Advertisement
Bizziebis

Synology GetSnapshot PHP

Jun 6th, 2015
1,660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.60 KB | None | 0 0
  1. <?
  2. // Configuration
  3. $user = "username";  // Synology username with rights to Surveillance station
  4. $pass = "password";  // Password of the user entered above
  5. $ip = "10.0.0.250";  // IP-Adress of your Synology-NAS
  6. $port = "5000";  // default port of Surveillance Station
  7. $http = "http"; // Change to https if you use a secure connection
  8. $cameraID = "3";  // ID of the camera for taking snapshots
  9. $cameraStream = $_GET["stream"];
  10. // You can change the stream by adding ?stream=0/1/2 to the url. For example: www.yourdomain.com/snapshot.php?stream=2
  11. // 0: Live stream | 1: Recording stream | 2: Mobile stream
  12. // Default value is stream 0
  13. if ($cameraStream == NULL) {
  14.     $cameraStream = "0";
  15.     }
  16.  
  17. // Authenticate with Synology Surveillance Station WebAPI and get our SID
  18. $json = file_get_contents($http.'://'.$ip.':'.$port.'/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=3&account='.$user.'&passwd='.$pass.'&session=SurveillanceStation&format=sid');
  19. $obj = json_decode($json, true);
  20. @$sid = $obj["data"]["sid"];
  21.  
  22. // Setting the correct header so the PHP file will be recognised as a JPEG file
  23. header('Content-Type: image/jpeg');
  24. // Read the contents of the snapshot and output it directly without putting it in memory first
  25. readfile($http.'://'.$ip.':'.$port.'/webapi/entry.cgi?camStm='.$cameraStream.'&version=3&cameraId='.$cameraID.'&api=SYNO.SurveillanceStation.Camera&preview=false&method=GetSnapshot&_sid='.$sid);
  26. // Log out from Surveillance Station
  27. file_get_contents($http.'://'.$ip.':'.$port.'/webapi/auth.cgi?api=SYNO.API.Auth&method=Logout&version=3&session=SurveillanceStation&_sid='.$sid);
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement