Author Topic: GDS3710: capture picture with HTTP API  (Read 687 times)

MrNeondal

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: GDS3710: capture picture with HTTP API
« Reply #15 on: October 06, 2017, 11:45:31 AM »
Hi all,

So I finally got the Snapshot to work.

So I did the authentication procedure and then I sent the following URL:

https://GDS_IP/snapshot/view0.jpg

I did have to put ">> directory/pic.jpg" at the end of my request to save the picture in my directory.

Since this worked, I believe that we could also get the image from the other streams as specified in other product documentations by using view0, view4, and view8.

The auth process and this command is all sent via CURL in a shell script.

Make sure to use the cookies that you get form the auth process.

Thank you all so much for the help.

Hi MrNeondal,

good job :-)
Can you send me the curl script for authentication?

++
Andy

Hi ak0815,
Sure thing, and I did do this on Ubuntu 16.04 in case you wanted that information too.

_____________
#!/bin/bash

##Authentication Login
return="$(curl -k -H 'Content-Type: text/xml' -D 'cookies.txt' 'https://GDS_IP/goform/login?cmd=login&user=GDS_USERNAME&type=1')"

##Get ChallengeCode
substring1=${return##*<ChallengeCode>}
final=${substring1%%</ChallengeCode>*}

##Calculate md5 checksum
mdstr="$(echo -n $final:GDS3710lZpRsFzCbM:GDS_PASSWORD | md5sum | tr -d '/n')"

M="$(echo $mdstr | cut -d' ' -f1 | tr -d '/n')"

curl -k -H "Content-Type: text/xml" -D "cookies.txt" "https://GDS_IP/goform/login?cmd=login&user=GDS_USERNAME&authcode=$M&type=1"

##Request to take snapshot
curl -k -H "Content-Type: image/jpeg" --cookie "cookies.txt" "https://GDS_IP/snapshot/view0.jpg" >> gds_snap.jpg

___________________________________________________________________

Insert your GDS3710 IP, USERNAME, and PASSWORD

This has worked for me every time so if something goes wrong then I would suggest that you try each command separately.
Make sure you also have the curl and md5sum packages installed on your linux machine.

If you have anymore questions  I will try to monitor this and answer.


Thank you all again for your help with this.

AllUp

  • Beta Club Members
  • Sr. Member
  • *
  • Posts: 439
    • View Profile
Re: GDS3710: capture picture with HTTP API
« Reply #16 on: October 07, 2017, 12:20:28 PM »
Thank you for sharing this.  :)

ak0815

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: GDS3710: capture picture with HTTP API
« Reply #17 on: October 09, 2017, 12:05:12 AM »
Thanks :-)

gum2002

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: GDS3710: capture picture with HTTP API
« Reply #18 on: October 12, 2017, 09:00:55 AM »
Hi all,
thanks for your script MrNeondal.
Without your hplp I wouldn't be so far in solution. I'am not experienced in linux shell programming, but the script works until this line:

"curl -k -H "Content-Type: text/xml" -D "cookies.txt" "https://GDS_IP/goform/login?cmd=login&user=GDS_USERNAME&authcode=$M&type=1""

The fault  I get, is because of the password, it is not correct.
I tried the script step by step and I think it is because of the md5 hash. If I take the md5 hash direct in the terminal and not from the script, I get another solution, which works in the line above. Could it be, that my system calculates it wrong because of another shell terminal or something like that?
I use linux mint 17.3 Cinnamon.
Thanks for your help in advance,

gum2002

AllUp

  • Beta Club Members
  • Sr. Member
  • *
  • Posts: 439
    • View Profile
Re: GDS3710: capture picture with HTTP API
« Reply #19 on: October 13, 2017, 08:47:16 AM »
You did adjust GDS_USERNAME?

MrNeondal

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: GDS3710: capture picture with HTTP API
« Reply #20 on: October 13, 2017, 12:16:17 PM »
Hi gum2002,

Like @AllUp said, did you change the GDS_USERNAME and IP,etc. with your own GDS3170 parameters?

Also I am not 100% sure about Cinnamon, since I have been using Ubuntu since I can remember, but it could be possible that the md5 could be outputting something different.

Remember a simple space or any other character will change the md5.

I believe you shouldn't have a problem since most linux systems should be able to run the same or similar commands with the same outputs(I am not a linux expert though, so don't take my word for it).

Also do some googling.

I am no pro at shell programming either and most of these commands I merely googled to find a working answer.

Let me know the results and if you are still having problems.

Sorry I couldn't be of more help.

Mr. Neondal

gum2002

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: GDS3710: capture picture with HTTP API
« Reply #21 on: October 22, 2017, 04:34:28 AM »
I got it. The fault was the control character CR! Because of 1 character more, the md5 hash was totally different.
Thanks to all!

avigoureux

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: GDS3710: capture picture with HTTP API
« Reply #22 on: November 06, 2017, 06:48:31 AM »
Same code in PHP with direct return of the image to the browser (can also be saved to a file) :
Code: [Select]
<?php
function getHtml($url$post null) {
    
$ch curl_init();
    
//curl_setopt($ch, CURLOPT_VERBOSE, true);
    
curl_setopt($chCURLOPT_URL$url);
    
curl_setopt($chCURLOPT_RETURNTRANSFER1);
    
curl_setopt($chCURLOPT_FOLLOWLOCATION1);
    
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
    
curl_setopt($chCURLOPT_SSL_VERIFYHOST0);
    
curl_setopt($chCURLOPT_COOKIEJAR'/tmp/cookie.txt');
   
curl_setopt($chCURLOPT_COOKIEFILE'/tmp/cookie.txt');
    
$result curl_exec($ch);
    
curl_close($ch);
    return 
$result;
}

$doorphone_ip "GDS3710 IP";
$doorphone_username "USERNAME";
$doorphone_password "PASSWORD";

$token_url "https://".$doorphone_ip."/goform/login?cmd=login&user=".$doorphone_username."&type=1";
$snapshot_url "https://".$doorphone_ip."/snapshot/view0.jpg";

$result getHtml($token_url);
try {
  
$xml_result = new SimpleXMLElement($result);
} catch (
Exception $e) {
  echo 
"bad xml";
}
$challenge_code $xml_result->ChallengeCode;
$authcode $challenge_code.":GDS3710lZpRsFzCbM:".$doorphone_password;
$authcode_md5 md5($authcode);

$auth_url "https://".$doorphone_ip."/goform/login?cmd=login&user=".$doorphone_username."&authcode=".$authcode_md5."&type=1";
$result getHtml($auth_url);
$out getHtml($snapshot_url);

$img imagecreatefromstring($out);
header('Content-type: image/jpeg');
imagejpeg($img);

exit();
?>