Advertisement
Guest User

Untitled

a guest
Jul 8th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. Here is some code to get around this.
  2.  
  3. PHP:
  4. [code]
  5. $url = "http://192.168.1.$camera/cgi-bin/snapshot.cgi";
  6.  
  7. $options = array(
  8. CURLOPT_URL => $url,
  9. CURLOPT_HEADER => true,
  10. CURLOPT_VERBOSE => true,
  11. CURLOPT_RETURNTRANSFER => true,
  12. CURLOPT_FOLLOWLOCATION => true,
  13. CURLOPT_SSL_VERIFYPEER => false, // for https
  14. CURLOPT_USERPWD => $username . ":" . $password,
  15. CURLOPT_HTTPAUTH => CURLAUTH_DIGEST
  16. );
  17.  
  18. $ch = curl_init();
  19.  
  20. curl_setopt_array( $ch, $options );
  21.  
  22. try {
  23. $raw = curl_exec( $ch );
  24.  
  25. // validate CURL status
  26. if(curl_errno($ch))
  27. throw new Exception(curl_error($ch), 500);
  28.  
  29. // validate HTTP status code (user/password credential issues)
  30. $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  31. if ($status_code != 200)
  32. throw new Exception("Response with Status Code [" . $status_code . "].", 500);
  33.  
  34. } catch(Exception $ex) {
  35. if ($ch != null) curl_close($ch);
  36. throw new Exception($ex);
  37. }
  38.  
  39. if ($ch != null) curl_close($ch);
  40.  
  41. $start = strpos($raw,"\xff");
  42. $end = strpos($raw,$boundary,$start)-1;
  43. $frame = substr("$raw",$start,$end - $start);
  44.  
  45. header("Content-type: image/jpeg");
  46. echo $frame;
  47. [/code]
  48.  
  49. Javascript -- cache the http credentials in the background so the browser doesn't ask for them:
  50. [code]function cacheHttpCameraCredentials(sender='default') {
  51. // Cache http user/pass for cameras
  52. $.ajax({
  53. type: 'GET',
  54. url: 'http://192.168.1.123/cgi-bin/snapshot.cgi',
  55. username: 'admin',
  56. password: 'admin',
  57. success : function(data) {
  58. //Success block
  59. console.log('Cached webserver camera credentials: ' + sender);
  60. },
  61. error: function (xhr,ajaxOptions,throwError){
  62. //Error block
  63. console.log('Error caching camera credentials: ' + sender);
  64. },
  65. });
  66. }[/code]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement