Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
5.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. require_once('../ajax_asm.php');
  3. require_once('../php/onvif/toto.php');
  4. if( $CUser->Data['id'] > 1 ){
  5. $Data = array();
  6. $Data['success'] = false;
  7. if( isset( $_POST['CID'] ) ){
  8. $ECID = intval( $_POST['CID'] );
  9. if( $ECID > 0 ){
  10. //Check if Camera Already has password and discovered sources!
  11. $QS = "SELECT * FROM media_streams WHERE source_id={$ECID}";
  12. $Result = $DATABASE->Query($QS,false);
  13. if( count( $Result ) > 0 ){
  14. foreach( $Result as $CD ){
  15. $cnode['id'] = $CD['id'];
  16. $cnode['name'] = $CD['name'];
  17. $cnode['size'] = $CD['img_width'].'x'.$CD['img_height'].'@'.$CD['fps'];
  18. $cnode['encode'] = $CD['compression_type'];
  19. $cnode['bitrate'] = $CD['bitrate'];
  20. $cnode['pic'] = $CD['picture_proto'] . '://' . $IP . ':' . $CD['picture_port'] . $CD['picture'];
  21. $Data['nodes'][] = $cnode;
  22. };
  23. $Data['success'] = true;
  24. echo json_encode( $Data );
  25. exit();
  26. };
  27. };
  28. $EUser = $DATABASE->escape( $_POST['GUG'] );
  29. $EPass = $DATABASE->escape( $_POST['GOG'] );
  30. $AUTH = intval( $_POST['GAT'] );
  31. $QS = "SELECT * FROM cameras WHERE id = {$ECID}";
  32. $Result = $DATABASE->Query( $QS, false );
  33. if( count($Result) ){
  34. $IP = $Result[0]['ip'];
  35. $onvif = new Ponvif();
  36. $onvif->setUsername( $EUser );
  37. $onvif->setPassword( $EPass );
  38. $onvif->setIPAddress( $IP );
  39. $onvif->setAuthMethod( $AUTH );
  40. try {
  41. $onvif->initialize();
  42. if ( !$onvif->isFault($devices=$onvif->getSources())){// die("Error getting sources");
  43. foreach( $devices[0] as $source ) if( is_array( $source ) ){
  44. //print_r( $source );
  45. $Ename = $DATABASE->escape( $source['profilename']);
  46. $Etoken = $DATABASE->escape( $source['profiletoken']);
  47. $Eencode = $DATABASE->escape( $source['encoding']);
  48. $Ewidth = intval($source['width']);
  49. $Eheight = intval($source['height']);
  50. $Efps = intval($source['fps']);
  51. $Ebitrate = intval($source['bitrate']);
  52. if( isset( $source['ptz'] ) ){
  53. $Eptz = $DATABASE->escape( $source['ptz']['nodetoken'] );
  54. } else {
  55. $Eptz='';
  56. };
  57. $mrl = $onvif->media_GetStreamUri($source['profiletoken']);
  58. $pic = $onvif->media_GetSnapshotUri($source['profiletoken']);
  59. $TPArr = explode(':',$mrl);
  60. $mrl_proto = $TPArr[0];
  61. $mrl_port = intval( $TPArr[2] );
  62. if( $mrl_port == 0 ) {
  63. switch( $mrl_proto ){
  64. case 'rtsp': $mrl_port = 554; break;
  65. case 'http': $mrl_port = 80; break;
  66. case 'https': $mrl_port = 443; break;
  67. };
  68. };
  69. $Emrl = $DATABASE->escape( $mrl );
  70. $Emrl = str_replace( $mrl_proto . '://' . $IP . ':' . $mrl_port, '', $Emrl );
  71. $Emrl = str_replace( $mrl_proto . '://' . $IP, '', $Emrl );
  72. $TPArr = explode(':',$pic );
  73. $pic_proto = $TPArr[0];
  74. $pic_port = intval( $TPArr[2] );
  75. if($pic_port == 0 ) $pic_port = 80;
  76. $Epic = $DATABASE->escape( $pic );
  77. $Epic = str_replace( $pic_proto . '://' . $IP . ':' . $pic_port, '', $Epic );
  78. $Epic = str_replace( $pic_proto . '://' . $IP , '', $Epic );
  79. $QS = "INSERT INTO `media_streams`(`source_id`,`source_type`,`valid`,`name`,`token`,`img_width`,`img_height`,`compression_type`,`bitrate`,`fps`,`mrl`,`mrl_proto`,`mrl_port`,`picture_proto`,`picture_port`,`picture`) VALUES({$ECID},'D',1,'{$Ename}','{$Etoken}',{$Ewidth},{$Eheight},'{$Eencode}',{$Ebitrate},{$Efps},'{$Emrl}','{$mrl_proto}','{$mrl_port}','{$pic_proto}','{$pic_port}','{$Epic}') ON CONFLICT(`source_id`,`token`) DO UPDATE SET `source_type`='D', `valid`=1, `mrl`='{$Emrl}', `mrl_proto`='{$mrl_proto}', `mrl_port`='{$mrl_port}', `picture_proto`='{$pic_proto}', `picture_port`='{$pic_port}', `picture`='{$Epic}'";
  80. $DATABASE->Query( $QS, false );
  81. };
  82. $QS = "UPDATE cameras SET access_login='$EUser', access_pass='$EPass', auth_mode={$AUTH}, ptz_token='{$Eptz}' WHERE id={$ECID}";
  83. $DATABASE->Query( $QS, false );
  84. } else {
  85. $Data['error'] = 'Provided Credentials are Wrong!';
  86. echo json_encode( $Data );
  87. exit();
  88. };
  89. } catch (Exception $e) {
  90. if( stripos( $e->getMessage(), 'GetCapabilities')!== false ){
  91. $Data['error'] = '<p align="center">Camera IP Address is Wrong!</p><p align="center">Please consider run network discovery.</p><p align="center">To refresh all aveable cameras addreses.</p>';
  92. } else {
  93. $Data['error'] = 'Provided Credentials are Wrong!';
  94. };
  95. //$Data['error'] = 'Caught exception: '.$e->getMessage();
  96. echo json_encode( $Data );
  97. exit();
  98. };
  99. };
  100. $QS = "SELECT * FROM media_streams WHERE source_id={$ECID}";
  101. $Result = $DATABASE->Query($QS,false);
  102. foreach( $Result as $CD ){
  103. $cnode['id'] = $CD['id'];
  104. $cnode['name'] = $CD['name'];
  105. $cnode['size'] = $CD['img_width'].'x'.$CD['img_height'].'@'.$CD['fps'];
  106. $cnode['encode'] = $CD['compression_type'];
  107. $cnode['bitrate'] = $CD['bitrate'];
  108. $Data['nodes'][] = $cnode;
  109. };
  110. $Data['success'] = true;
  111. };
  112. echo json_encode( $Data );
  113. } else {
  114. header('location: /');
  115. };
  116. ?>