Saturday, November 24, 2012

Enable / disable cameras on Diskstation from Shell

I finally managed to enable / disable the cameras connected to my Synology DiskStation 413j running DSM 4.1 from a shell script!

The problem with existing scripts I found in forums was, that Synology improved the logon procedure, adding encryption of passwords (using "encryption.cgi") which makes it harder to log in using simple "wget" calls.

The client requests a key from encryption.cgi which is being used inside JavaScript to encrypt the password and send a hash to the server. Cleartext passwords no longer work (at least I couldn't get them to work anymore):

I used WebScarab proxy to monitor the connection between my browser and the DiskStation. This is what the call to encryption.cgi returns:


And this is what the following call to login.cgi looks like:



So it would be necessary to get the JavaScript code that encrypts the password, see what it does and try to use or reimplement this somehow. Too complicated.

However, Synology introduced a nice CGI API that is really straightforward and well documented and allows you to logon using clear text passwords (over SSL encrypted connection if needed) - but lacks the feature to enable / disable the cameras! :-(

Finally, combining a logon call to the new API, saving the cookie, then calling the main page ("index.cgi") and then setting the cameras turned out to work, so this is what works at least for me:

 Turning cameras ON:

wget --keep-session-cookies --save-cookies syno-cookies.txt -O- "http://DISKSTATION:9900/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=1&account=admin&passwd=PASSWORD"

wget --load-cookies syno-cookies.txt -O- "http://
DISKSTATION:9900/webman/3rdparty/SurveillanceStation/cgi/index.cgi"

wget --load-cookies syno-cookies.txt -O-  "http://DISKSTATION:9900/webman/3rdparty/SurveillanceStation/cgi/camera.cgi?_dc=1353771235677&action=cameraEnable&UserId=1024&idList=1"

wget wget --load-cookies syno-cookies.txt -O- "http://
DISKSTATION:9900/webman/3rdparty/SurveillanceStation/cgi/camera.cgi?_dc=1353771235677&action=cameraEnable&UserId=1024&idList=2"

Turning cameras OFF:

wget --keep-session-cookies --save-cookies syno-cookies.txt -O- "http://DISKSTATION:9900/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=1&account=admin&passwd=PASSWORD"

wget --load-cookies syno-cookies.txt -O- "http://
DISKSTATION:9900/webman/3rdparty/SurveillanceStation/cgi/index.cgi"

wget --load-cookies syno-cookies.txt -O-  "http://DISKSTATION:9900/webman/3rdparty/SurveillanceStation/cgi/camera.cgi?_dc=1353771235677&action=cameraDisable&UserId=1024&idList=1"

wget wget --load-cookies syno-cookies.txt -O- "http://
DISKSTATION:9900/webman/3rdparty/SurveillanceStation/cgi/camera.cgi?_dc=1353771235677&action=cameraDisable&UserId=1024&idList=2"

2 comments:

  1. It works . Tnx a lot :)

    ReplyDelete
  2. Amazing, it works perfectly !! That's great, thanks for saving me a long time analyzing htpp discussions using Fiddler ! Thank you soooo much :-) !!

    ReplyDelete