Web UI for ARGUS server
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.

837 lines
52 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. class Ponvif {
  3. protected $ipaddress='';
  4. protected $username='';
  5. protected $password='';
  6. protected $mediauri='';
  7. protected $snapshoturi='';
  8. protected $deviceuri='';
  9. protected $ptzuri='';
  10. protected $baseuri='';
  11. protected $onvifversion=array();
  12. protected $deltatime=0;
  13. protected $capabilities=array();
  14. protected $videosources=array();
  15. protected $sources=array();
  16. protected $profiles=array();
  17. protected $proxyhost='';
  18. protected $proxyport='';
  19. protected $proxyusername='';
  20. protected $proxypassword='';
  21. protected $lastresponse='';
  22. protected $intransingent=true;
  23. protected $discoverytimeout=2;
  24. protected $discoverybindip='0.0.0.0';
  25. protected $discoverymcastip='239.255.255.250';
  26. protected $discoverymcastport=3702;
  27. protected $discoveryhideduplicates=true;
  28. protected $useDigest= false;
  29. protected $qop='auth';
  30. protected $auth_realm = '';
  31. protected $auth_nonce = '';
  32. protected $auth_cnonce = '';
  33. protected $auth_nc = 0;
  34. protected $digestMethod = 'SHA-256';
  35. public function setProxyHost($proxyHost) { $this->proxyhost = $proxyHost; }
  36. public function getProxyHost() { return $this->proxyhost; }
  37. public function setProxyPort($proxyPort) { $this->proxyport = $proxyPort; }
  38. public function getProxyPort() { return $this->proxyport; }
  39. public function setProxyUsername($proxyUsername) { $this->proxyusername = $proxyUsername; }
  40. public function getProxyUsername() { return $this->proxyusername; }
  41. public function setProxyPassword($proxyPassword) { $this->proxypassword = $proxyPassword; }
  42. public function getProxyPassword() { return $this->proxypassword; }
  43. public function setUsername($username) { $this->username = $username; }
  44. public function getUsername() { return $this->username; }
  45. public function setPassword($password) { $this->password = $password; }
  46. public function getPassword() { return $this->password; }
  47. public function getDeviceUri() { return $this->mediauri; }
  48. public function setDeviceUri($deviceUri) { $this->mediauri=$deviceUrl; }
  49. public function getIPAddress($ipAddress) { return $this->ipAddress; }
  50. public function setIPAddress($ipAddress) { $this->ipaddress=$ipAddress; }
  51. public function getSources() { return $this->sources; }
  52. public function getMediaUri() { return $this->mediauri; }
  53. public function getPTZUri() { return $this->ptzuri; }
  54. public function getBaseUrl() { return $this->baseuri; }
  55. public function getSupportedVersion() { return $this->onvifversion; }
  56. public function getCapabilities() { return $this->capabilities; }
  57. public function setBreakOnError($intransingent) { $this->intransingent=$intransingent; }
  58. public function getLastResponse() { return $this->lastresponse; }
  59. public function setDiscoveryTimeout($discoverytimeout) { $this->discoverytimeout = $discoverytimeout; }
  60. public function setDiscoveryBindIp($discoverybindip) { $this->discoverybindip = $discoverybindip; }
  61. public function setDiscoveryMcastIp($discoverymcastip) { $this->discoverymcastip = $discoverymcastip; }
  62. public function setDiscoveryMcastPort($discoverymcastport) { $this->discoverymcastport = $discoverymcastport; }
  63. public function setDiscoveryHideDuplicates($discoveryhideduplicates) { $this->discoveryhideduplicates = $discoveryhideduplicates; }
  64. public function getSnapshotUri() { return $this->snapshoturi; }
  65. public function setDigestMethod( $DM ){ $this->digestMethod = $DM; }
  66. public function getDigestMethod(){ return $this->digestMethod; }
  67. /*
  68. Constructor & Destructor
  69. */
  70. public function __construct()
  71. {
  72. // nothing to do
  73. }
  74. public function __destruct()
  75. {
  76. // nothing to do
  77. }
  78. /*
  79. WS-Discovery
  80. */
  81. public function discover(){
  82. $result = array();
  83. $timeout = time() + $this->discoverytimeout;
  84. $post_string = '<?xml version="1.0" encoding="UTF-8"?><e:Envelope xmlns:e="http://www.w3.org/2003/05/soap-envelope" xmlns:w="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:d="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:dn="http://www.onvif.org/ver10/network/wsdl"><e:Header><w:MessageID>uuid:84ede3de-7dec-11d0-c360-f01234567890</w:MessageID><w:To e:mustUnderstand="true">urn:schemas-xmlsoap-org:ws:2005:04:discovery</w:To><w:Action a:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe</w:Action></e:Header><e:Body><d:Probe><d:Types>dn:NetworkVideoTransmitter</d:Types></d:Probe></e:Body></e:Envelope>';
  85. try {
  86. if(FALSE == ($sock = @socket_create(AF_INET, SOCK_DGRAM, SOL_UDP))){
  87. echo('Create socket error: ['.socket_last_error().'] '.socket_strerror(socket_last_error()));
  88. }
  89. //if(FALSE == @socket_bind($sock, $this->discoverybindip, rand(20000, 40000))){
  90. // echo('Bind socket error: ['.socket_last_error().'] '.socket_strerror(socket_last_error()));
  91. //}
  92. //socket_set_option($sock, IPPROTO_IP, MCAST_JOIN_GROUP, array('group' => $this->discoverymcastip));
  93. socket_sendto($sock, $post_string, strlen($post_string), 0, $this->discoverymcastip, $this->discoverymcastport);
  94. socket_set_nonblock($sock);
  95. while(time() < $timeout){
  96. if( FALSE !== @socket_recvfrom($sock, $response, 9999, 0, $from, $this->discoverymcastport)){
  97. if( $response != NULL && $response != $post_string ){
  98. $response = $this->_xml2array($response);
  99. if(!$this->isFault($response)){
  100. $response['Envelope']['Body']['ProbeMatches']['ProbeMatch']['IPAddr'] = $from;
  101. if($this->discoveryhideduplicates){
  102. $result[$from] = $response['Envelope']['Body']['ProbeMatches']['ProbeMatch'];
  103. }else{
  104. $result[] = $response['Envelope']['Body']['ProbeMatches']['ProbeMatch'];
  105. }
  106. }
  107. }
  108. }
  109. }
  110. socket_close($sock);
  111. } catch (Exception $e) {}
  112. sort($result);
  113. return $result;
  114. }
  115. /*
  116. Public functions (basic initialization method and other collaterals)
  117. */
  118. public function initialize() {
  119. $this->mediauri='http://'.$this->ipaddress.'/onvif/device_service';
  120. try {
  121. $datetime=$this->core_GetSystemDateAndTime();
  122. $timestamp=mktime($datetime['Time']['Hour'], $datetime['Time']['Minute'], $datetime['Time']['Second'],
  123. $datetime['Date']['Month'], $datetime['Date']['Day'], $datetime['Date']['Year']);
  124. $this->deltatime = time()-$timestamp;//-5;
  125. } catch( Exception $e ) {
  126. }
  127. $this->capabilities=$this->core_GetCapabilities();
  128. echo "\n\n\n\nGet Cap\n\n\n";
  129. $onvifVersion=$this->_getOnvifVersion($this->capabilities);
  130. $this->mediauri=$onvifVersion['media'];
  131. $this->deviceuri=$onvifVersion['device'];
  132. $this->ptzuri=$onvifVersion['ptz'];
  133. preg_match("/^http(.*)onvif\//",$this->mediauri,$matches);
  134. $this->baseuri=$matches[0];
  135. $this->onvifversion=array('major'=>$onvifVersion['major'],'minor'=>$onvifVersion['minor']);
  136. $this->videosources=$this->media_GetVideoSources();
  137. $this->profiles=$this->media_GetProfiles();
  138. $this->sources=$this->_getActiveSources($this->videosources,$this->profiles);
  139. }
  140. public function isFault($response) { // Useful to check if response contains a fault
  141. if( is_array( $response ) ){
  142. if( array_key_exists('Fault', $response ) ) return true;
  143. if( array_key_exists('Envelope', $response ) )
  144. if( is_array( $response['Envelope'] ) )
  145. if( array_key_exists('Body', $response['Envelope'] ) )
  146. if( is_array( $response['Envelope']['Body'] ) )
  147. if( array_key_exists('Fault', $response['Envelope']['Body'] ) ) return true;
  148. };
  149. return false;
  150. }
  151. /*
  152. Public wrappers for a subset of ONVIF primitives
  153. */
  154. public function core_GetSystemDateAndTime() {
  155. $post_string='<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetSystemDateAndTime xmlns="http://www.onvif.org/ver10/device/wsdl"/></s:Body></s:Envelope>';
  156. if( $this->isFault($response=$this->_send_request($this->mediauri,$post_string)) ){
  157. if ($this->intransingent) throw new Exception('GetSystemDateAndTime: Communication error');
  158. } else {
  159. return $response['Envelope']['Body']['GetSystemDateAndTimeResponse']['SystemDateAndTime']['UTCDateTime'];
  160. }
  161. }
  162. public function core_GetCapabilities() {
  163. $REQ=$this->_makeToken();
  164. $post_string='<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>%%USERNAME%%</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%%PASSWORD%%</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%%NONCE%%</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%%CREATED%%</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetCapabilities xmlns="http://www.onvif.org/ver10/device/wsdl"><Category>All</Category></GetCapabilities></s:Body></s:Envelope>';
  165. $post_string=str_replace(array("%%USERNAME%%",
  166. "%%PASSWORD%%",
  167. "%%NONCE%%",
  168. "%%CREATED%%"),
  169. array($REQ['USERNAME'],
  170. $REQ['PASSDIGEST'],
  171. $REQ['NONCE'],
  172. $REQ['TIMESTAMP']),
  173. $post_string);
  174. if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) {
  175. if ($this->intransingent) throw new Exception('GetCapabilities: Communication error');
  176. }
  177. else
  178. return $response['Envelope']['Body']['GetCapabilitiesResponse']['Capabilities'];
  179. }
  180. public function media_GetVideoSources() {
  181. $REQ=$this->_makeToken();
  182. $post_string='<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>%%USERNAME%%</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%%PASSWORD%%</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%%NONCE%%</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%%CREATED%%</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetVideoSources xmlns="http://www.onvif.org/ver10/media/wsdl"/></s:Body></s:Envelope>';
  183. $post_string=str_replace(array("%%USERNAME%%",
  184. "%%PASSWORD%%",
  185. "%%NONCE%%",
  186. "%%CREATED%%"),
  187. array($REQ['USERNAME'],
  188. $REQ['PASSDIGEST'],
  189. $REQ['NONCE'],
  190. $REQ['TIMESTAMP']),
  191. $post_string);
  192. //echo "POST STRING:" . $post_string . "\n\n";
  193. if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) {
  194. if ($this->intransingent) throw new Exception('GetVideoSources: Communication error');
  195. }
  196. else
  197. // var_dump( $response );
  198. return $response['Envelope']['Body']['GetVideoSourcesResponse']['VideoSources'];
  199. }
  200. public function media_GetProfiles() {
  201. $REQ=$this->_makeToken();
  202. $post_string='<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>%%USERNAME%%</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%%PASSWORD%%</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%%NONCE%%</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%%CREATED%%</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetProfiles xmlns="http://www.onvif.org/ver10/media/wsdl"/></s:Body></s:Envelope>';
  203. $post_string=str_replace(array("%%USERNAME%%",
  204. "%%PASSWORD%%",
  205. "%%NONCE%%",
  206. "%%CREATED%%"),
  207. array($REQ['USERNAME'],
  208. $REQ['PASSDIGEST'],
  209. $REQ['NONCE'],
  210. $REQ['TIMESTAMP']),
  211. $post_string);
  212. if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) {
  213. if ($this->intransingent) throw new Exception('GetProfiles: Communication error');
  214. }
  215. else
  216. return $response['Envelope']['Body']['GetProfilesResponse']['Profiles'];
  217. }
  218. public function media_GetServices() {
  219. $REQ=$this->_makeToken();
  220. $post_string='<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>%%USERNAME%%</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%%PASSWORD%%</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%%NONCE%%</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%%CREATED%%</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetServices xmlns="http://www.onvif.org/ver10/device/wsdl"><IncludeCapability>false</IncludeCapability></GetServices></s:Body></s:Envelope>';
  221. $post_string=str_replace(array("%%USERNAME%%",
  222. "%%PASSWORD%%",
  223. "%%NONCE%%",
  224. "%%CREATED%%"),
  225. array($REQ['USERNAME'],
  226. $REQ['PASSDIGEST'],
  227. $REQ['NONCE'],
  228. $REQ['TIMESTAMP']),
  229. $post_string);
  230. if ($this->isFault($this->_send_request($this->mediauri,$post_string))) {
  231. if ($this->intransingent) throw new Exception('GetServices: Communication error');
  232. }
  233. }
  234. public function core_GetDeviceInformation() {
  235. $REQ=$this->_makeToken();
  236. $post_string='<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>%%USERNAME%%</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%%PASSWORD%%</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%%NONCE%%</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%%CREATED%%</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetDeviceInformation xmlns="http://www.onvif.org/ver10/device/wsdl"/></s:Body></s:Envelope>';
  237. $post_string=str_replace(array("%%USERNAME%%",
  238. "%%PASSWORD%%",
  239. "%%NONCE%%",
  240. "%%CREATED%%"),
  241. array($REQ['USERNAME'],
  242. $REQ['PASSDIGEST'],
  243. $REQ['NONCE'],
  244. $REQ['TIMESTAMP']),
  245. $post_string);
  246. if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) {
  247. if ($this->intransingent) throw new Exception('GetDeviceInformation: Communication error');
  248. }
  249. else
  250. return $response['Envelope']['Body']['GetDeviceInformationResponse'];
  251. }
  252. public function media_GetStreamUri($profileToken,$stream="RTP-Unicast",$protocol="RTSP") {
  253. $REQ=$this->_makeToken();
  254. $post_string='<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>%%USERNAME%%</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%%PASSWORD%%</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%%NONCE%%</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%%CREATED%%</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetStreamUri xmlns="http://www.onvif.org/ver10/media/wsdl"><StreamSetup><Stream xmlns="http://www.onvif.org/ver10/schema">%%STREAM%%</Stream><Transport xmlns="http://www.onvif.org/ver10/schema"><Protocol>%%PROTOCOL%%</Protocol></Transport></StreamSetup><ProfileToken>%%PROFILETOKEN%%</ProfileToken></GetStreamUri></s:Body></s:Envelope>';
  255. $post_string=str_replace(
  256. array("%%USERNAME%%",
  257. "%%PASSWORD%%",
  258. "%%NONCE%%",
  259. "%%CREATED%%",
  260. "%%PROFILETOKEN%%",
  261. "%%STREAM%%",
  262. "%%PROTOCOL%%"),
  263. array($REQ['USERNAME'],
  264. $REQ['PASSDIGEST'],
  265. $REQ['NONCE'],
  266. $REQ['TIMESTAMP'],
  267. $profileToken,
  268. $stream,
  269. $protocol),
  270. $post_string
  271. );
  272. if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) {
  273. if ($this->intransingent) throw new Exception('GetStreamUri: Communication error');
  274. }
  275. else
  276. return $response['Envelope']['Body']['GetStreamUriResponse']['MediaUri']['Uri'];
  277. }
  278. public function media_GetSnapshotUri($profileToken) {
  279. $REQ=$this->_makeToken();
  280. $post_string='<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>%%USERNAME%%</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%%PASSWORD%%</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%%NONCE%%</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%%CREATED%%</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetSnapshotUri xmlns="http://www.onvif.org/ver10/media/wsdl"><ProfileToken>%%PROFILETOKEN%%</ProfileToken></GetSnapshotUri></s:Body></s:Envelope>';
  281. $post_string=str_replace(array("%%USERNAME%%",
  282. "%%PASSWORD%%",
  283. "%%NONCE%%",
  284. "%%CREATED%%",
  285. "%%PROFILETOKEN%%"),
  286. array($REQ['USERNAME'],
  287. $REQ['PASSDIGEST'],
  288. $REQ['NONCE'],
  289. $REQ['TIMESTAMP'],
  290. $profileToken),
  291. $post_string);
  292. if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) {
  293. if ($this->intransingent) throw new Exception('GetSnapshotUri: Communication error');
  294. var_dump($response);
  295. }
  296. else
  297. return $response['Envelope']['Body']['GetSnapshotUriResponse']['MediaUri']['Uri'];
  298. }
  299. public function ptz_GetPresets($profileToken) {
  300. if ($this->ptzuri=='') return array();
  301. $REQ=$this->_makeToken();
  302. $post_string='<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>%%USERNAME%%</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%%PASSWORD%%</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%%NONCE%%</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%%CREATED%%</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetPresets xmlns="http://www.onvif.org/ver20/ptz/wsdl"><ProfileToken>%%PROFILETOKEN%%</ProfileToken></GetPresets></s:Body></s:Envelope>';
  303. $post_string=str_replace(array("%%USERNAME%%",
  304. "%%PASSWORD%%",
  305. "%%NONCE%%",
  306. "%%CREATED%%",
  307. "%%PROFILETOKEN%%"),
  308. array($REQ['USERNAME'],
  309. $REQ['PASSDIGEST'],
  310. $REQ['NONCE'],
  311. $REQ['TIMESTAMP'],
  312. $profileToken),
  313. $post_string);
  314. if ($this->isFault($response=$this->_send_request($this->ptzuri,$post_string))) {
  315. if ($this->intransingent) throw new Exception('GetPresets: Communication error');
  316. }
  317. else {
  318. $getpresetsresponse=$response['Envelope']['Body']['GetPresetsResponse']['Preset'];
  319. $presets=array();
  320. foreach ($getpresetsresponse as $preset) {
  321. $presets[]=array('Token'=>$preset['@attributes']['token'],
  322. 'Name'=>$preset['Name'],
  323. 'PTZPosition'=>$preset['PTZPosition']);
  324. }
  325. return $presets;
  326. }
  327. }
  328. public function ptz_GetNode($ptzNodeToken) {
  329. if ($this->ptzuri=='') return array();
  330. $REQ=$this->_makeToken();
  331. $post_string='<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>%%USERNAME%%</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%%PASSWORD%%</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%%NONCE%%</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%%CREATED%%</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetNode xmlns="http://www.onvif.org/ver20/ptz/wsdl"><NodeToken>%%NODETOKEN%%</NodeToken></GetNode></s:Body></s:Envelope>';
  332. $post_string=str_replace(array("%%USERNAME%%",
  333. "%%PASSWORD%%",
  334. "%%NONCE%%",
  335. "%%CREATED%%",
  336. "%%NODETOKEN%%"),
  337. array($REQ['USERNAME'],
  338. $REQ['PASSDIGEST'],
  339. $REQ['NONCE'],
  340. $REQ['TIMESTAMP'],
  341. $ptzNodeToken),
  342. $post_string);
  343. if ($this->isFault($response=$this->_send_request($this->ptzuri,$post_string))) {
  344. if ($this->intransingent) throw new Exception('GetNode: Communication error');
  345. }
  346. else
  347. return $response['Envelope']['Body']['GetNodeResponse'];
  348. }
  349. public function ptz_GotoPreset($profileToken,$presetToken,$speed_pantilt_x,$speed_pantilt_y,$speed_zoom_x) {
  350. if ($this->ptzuri=='') return array();
  351. $REQ=$this->_makeToken();
  352. $post_string='<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>%%USERNAME%%</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%%PASSWORD%%</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%%NONCE%%</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%%CREATED%%</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GotoPreset xmlns="http://www.onvif.org/ver20/ptz/wsdl"><ProfileToken>%%PROFILETOKEN%%</ProfileToken><PresetToken>%%PRESETTOKEN%%</PresetToken><Speed><PanTilt x="%%SPEEDPANTILTX%%" y="%%SPEEDPANTILTY%%" xmlns="http://www.onvif.org/ver10/schema"/><Zoom x="%%SPEEDZOOMX%%" xmlns="http://www.onvif.org/ver10/schema"/></Speed></GotoPreset></s:Body></s:Envelope>';
  353. $post_string=str_replace(array("%%USERNAME%%",
  354. "%%PASSWORD%%",
  355. "%%NONCE%%",
  356. "%%CREATED%%",
  357. "%%PROFILETOKEN%%",
  358. "%%PRESETTOKEN%%",
  359. "%%SPEEDPANTILTX%%",
  360. "%%SPEEDPANTILTY%%",
  361. "%%SPEEDZOOMX%%"),
  362. array($REQ['USERNAME'],
  363. $REQ['PASSDIGEST'],
  364. $REQ['NONCE'],
  365. $REQ['TIMESTAMP'],
  366. $profileToken,
  367. $presetToken,
  368. $speed_pantilt_x,
  369. $speed_pantilt_y,
  370. $speed_zoom_x),
  371. $post_string);
  372. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  373. if ($this->intransingent) throw new Exception('GotoPreset: Communication error');
  374. }
  375. }
  376. public function ptz_RemovePreset($profileToken,$presetToken) {
  377. if ($this->ptzuri=='') return array();
  378. $REQ=$this->_makeToken();
  379. $post_string='<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>%%USERNAME%%</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%%PASSWORD%%</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%%NONCE%%</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%%CREATED%%</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><RemovePreset xmlns="http://www.onvif.org/ver20/ptz/wsdl"><ProfileToken>%%PROFILETOKEN%%</ProfileToken><PresetToken>%%PRESETTOKEN%%</PresetToken></RemovePreset></s:Body></s:Envelope>';
  380. $post_string=str_replace(array("%%USERNAME%%",
  381. "%%PASSWORD%%",
  382. "%%NONCE%%",
  383. "%%CREATED%%",
  384. "%%PROFILETOKEN%%",
  385. "%%PRESETTOKEN%%"),
  386. array($REQ['USERNAME'],
  387. $REQ['PASSDIGEST'],
  388. $REQ['NONCE'],
  389. $REQ['TIMESTAMP'],
  390. $profileToken,
  391. $presetToken),
  392. $post_string);
  393. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  394. if ($this->intransingent) throw new Exception('RemovePreset: Communication error');
  395. }
  396. }
  397. public function ptz_SetPreset($profileToken,$presetName) {
  398. if ($this->ptzuri=='') return array();
  399. $REQ=$this->_makeToken();
  400. $post_string='<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>%%USERNAME%%</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%%PASSWORD%%</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%%NONCE%%</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%%CREATED%%</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SetPreset xmlns="http://www.onvif.org/ver20/ptz/wsdl"><ProfileToken>%%PROFILETOKEN%%</ProfileToken><PresetName>%%PRESETNAME%%</PresetName></SetPreset></s:Body></s:Envelope>';
  401. $post_string=str_replace(array("%%USERNAME%%",
  402. "%%PASSWORD%%",
  403. "%%NONCE%%",
  404. "%%CREATED%%",
  405. "%%PROFILETOKEN%%",
  406. "%%PRESETNAME%%"),
  407. array($REQ['USERNAME'],
  408. $REQ['PASSDIGEST'],
  409. $REQ['NONCE'],
  410. $REQ['TIMESTAMP'],
  411. $profileToken,
  412. $presetName),
  413. $post_string);
  414. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  415. if ($this->intransingent) throw new Exception('SetPreset: Communication error');
  416. }
  417. }
  418. public function ptz_RelativeMove($profileToken,$translation_pantilt_x,$translation_pantilt_y,$speed_pantilt_x,$speed_pantilt_y) {
  419. if ($this->ptzuri=='') return array();
  420. $REQ=$this->_makeToken();
  421. $post_string='<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>%%USERNAME%%</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%%PASSWORD%%</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%%NONCE%%</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%%CREATED%%</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><RelativeMove xmlns="http://www.onvif.org/ver20/ptz/wsdl"><ProfileToken>%%PROFILETOKEN%%</ProfileToken><Translation><PanTilt x="%%TRANSLATIONPANTILTX%%" y="%%TRANSLATIONPANTILTY%%" space="http://www.onvif.org/ver10/tptz/PanTiltSpaces/TranslationGenericSpace" xmlns="http://www.onvif.org/ver10/schema"/></Translation><Speed><PanTilt x="%%SPEEDPANTILTX%%" y="%%SPEEDPANTILTY%%" space="http://www.onvif.org/ver10/tptz/PanTiltSpaces/GenericSpeedSpace" xmlns="http://www.onvif.org/ver10/schema"/></Speed></RelativeMove></s:Body></s:Envelope>';
  422. $post_string=str_replace(array("%%USERNAME%%",
  423. "%%PASSWORD%%",
  424. "%%NONCE%%",
  425. "%%CREATED%%",
  426. "%%PROFILETOKEN%%",
  427. "%%TRANSLATIONPANTILTX%%",
  428. "%%TRANSLATIONPANTILTY%%",
  429. "%%SPEEDPANTILTX%%",
  430. "%%SPEEDPANTILTY%%"),
  431. array($REQ['USERNAME'],
  432. $REQ['PASSDIGEST'],
  433. $REQ['NONCE'],
  434. $REQ['TIMESTAMP'],
  435. $profileToken,
  436. $translation_pantilt_x,
  437. $translation_pantilt_y,
  438. $speed_pantilt_x,
  439. $speed_pantilt_y),
  440. $post_string);
  441. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  442. if ($this->intransingent) throw new Exception('RelativeMove: Communication error');
  443. }
  444. }
  445. public function ptz_RelativeMoveZoom($profileToken,$zoom,$speedZoom) {
  446. if ($this->ptzuri=='') return array();
  447. $REQ=$this->_makeToken();
  448. $post_string='<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>%%USERNAME%%</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%%PASSWORD%%</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%%NONCE%%</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%%CREATED%%</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><RelativeMove xmlns="http://www.onvif.org/ver20/ptz/wsdl"><ProfileToken>%%PROFILETOKEN%%</ProfileToken><Translation><Zoom x="%%ZOOM%%" space="http://www.onvif.org/ver10/tptz/ZoomSpaces/TranslationGenericSpace" xmlns="http://www.onvif.org/ver10/schema"/></Translation><Speed><Zoom x="%%SPEEDZOOM%%" space="http://www.onvif.org/ver10/tptz/ZoomSpaces/ZoomGenericSpeedSpace" xmlns="http://www.onvif.org/ver10/schema"/></Speed></RelativeMove></s:Body></s:Envelope>';
  449. $post_string=str_replace(array("%%USERNAME%%",
  450. "%%PASSWORD%%",
  451. "%%NONCE%%",
  452. "%%CREATED%%",
  453. "%%PROFILETOKEN%%",
  454. "%%SPEEDZOOM%%",
  455. "%%ZOOM%%"),
  456. array($REQ['USERNAME'],
  457. $REQ['PASSDIGEST'],
  458. $REQ['NONCE'],
  459. $REQ['TIMESTAMP'],
  460. $profileToken,
  461. $speedZoom,
  462. $zoom),
  463. $post_string);
  464. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  465. if ($this->intransingent) throw new Exception('RelativeMoveZoom: Communication error');
  466. }
  467. }
  468. public function ptz_GetStatus( $profileToken ){
  469. $REQ=$this->_makeToken();
  470. $post_string='<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>%%USERNAME%%</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%%PASSWORD%%</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%%NONCE%%</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%%CREATED%%</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetStatus xmlns="http://www.onvif.org/ver20/ptz/wsdl"><ProfileToken>%%PROFILETOKEN%%</ProfileToken></GetStatus></s:Body></s:Envelope>';
  471. $post_string=str_replace(array("%%USERNAME%%",
  472. "%%PASSWORD%%",
  473. "%%NONCE%%",
  474. "%%CREATED%%",
  475. "%%PROFILETOKEN%%"),
  476. array($REQ['USERNAME'],
  477. $REQ['PASSDIGEST'],
  478. $REQ['NONCE'],
  479. $REQ['TIMESTAMP'],
  480. $profileToken),
  481. $post_string);
  482. if ($this->isFault($response = $this->_send_request($this->ptzuri,$post_string))) {
  483. if ($this->intransingent) throw new Exception('ptz Get Status: Communication error');
  484. } else {
  485. var_dump( $response );
  486. $cpos=$response['Envelope']['Body']['GetStatusResponse']['PTZStatus']['Position'];
  487. return $cpos;
  488. };
  489. }
  490. public function ptz_AbsoluteMove($profileToken,$position_pantilt_x,$position_pantilt_y,$zoom, $PSpeed=1.0, $TSpeed=1.0, $ZSpeed=1.0 ) {
  491. if ($this->ptzuri=='') return array();
  492. $REQ=$this->_makeToken();
  493. $post_string='<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>%%USERNAME%%</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%%PASSWORD%%</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%%NONCE%%</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%%CREATED%%</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><AbsoluteMove xmlns="http://www.onvif.org/ver20/ptz/wsdl"><ProfileToken>%%PROFILETOKEN%%</ProfileToken><Position><PanTilt x="%%POSITIONPANTILTX%%" y="%%POSITIONPANTILTY%%" space="http://www.onvif.org/ver10/tptz/PanTiltSpaces/PositionGenericSpace" xmlns="http://www.onvif.org/ver10/schema"/><Zoom x="%%ZOOM%%" space="http://www.onvif.org/ver10/tptz/ZoomSpaces/PositionGenericSpace" xmlns="http://www.onvif.org/ver10/schema"/></Position><Speed><PanTilt x="%%SPEEDPANTILTX%%" y="%%SPEEDPANTILTY%%" xmlns="http://www.onvif.org/ver10/schema"/><Zoom x="%%SPEEDZOOMX%%" xmlns="http://www.onvif.org/ver10/schema"/></Speed></AbsoluteMove></s:Body></s:Envelope>';
  494. $post_string=str_replace(array("%%USERNAME%%",
  495. "%%PASSWORD%%",
  496. "%%NONCE%%",
  497. "%%CREATED%%",
  498. "%%PROFILETOKEN%%",
  499. "%%POSITIONPANTILTX%%",
  500. "%%POSITIONPANTILTY%%",
  501. "%%ZOOM%%",
  502. "%%SPEEDPANTILTX%%",
  503. "%%SPEEDPANTILTY%%",
  504. "%%SPEEDZOOMX%%"),
  505. array($REQ['USERNAME'],
  506. $REQ['PASSDIGEST'],
  507. $REQ['NONCE'],
  508. $REQ['TIMESTAMP'],
  509. $profileToken,
  510. $position_pantilt_x,
  511. $position_pantilt_y,
  512. $zoom,
  513. $PSpeed,
  514. $TSpeed,
  515. $ZSpeed),
  516. $post_string);
  517. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  518. if ($this->intransingent) throw new Exception('AbsoluteMove: Communication error');
  519. }
  520. }
  521. public function ptz_ContinuousMove($profileToken,$velocity_pantilt_x,$velocity_pantilt_y) {
  522. if ($this->ptzuri=='') return array();
  523. $REQ=$this->_makeToken();
  524. $post_string='<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>%%USERNAME%%</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%%PASSWORD%%</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%%NONCE%%</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%%CREATED%%</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><ContinuousMove xmlns="http://www.onvif.org/ver20/ptz/wsdl"><ProfileToken>%%PROFILETOKEN%%</ProfileToken><Velocity><PanTilt x="%%VELOCITYPANTILTX%%" y="%%VELOCITYPANTILTY%%" space="http://www.onvif.org/ver10/tptz/PanTiltSpaces/VelocityGenericSpace" xmlns="http://www.onvif.org/ver10/schema"/></Velocity></ContinuousMove></s:Body></s:Envelope>';
  525. $post_string=str_replace(array("%%USERNAME%%",
  526. "%%PASSWORD%%",
  527. "%%NONCE%%",
  528. "%%CREATED%%",
  529. "%%PROFILETOKEN%%",
  530. "%%VELOCITYPANTILTX%%",
  531. "%%VELOCITYPANTILTY%%"),
  532. array($REQ['USERNAME'],
  533. $REQ['PASSDIGEST'],
  534. $REQ['NONCE'],
  535. $REQ['TIMESTAMP'],
  536. $profileToken,
  537. $velocity_pantilt_x,
  538. $velocity_pantilt_y),
  539. $post_string);
  540. if ( $this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  541. if( $this->intransingent ) throw new Exception('ContinuousMove: Communication error');
  542. }
  543. }
  544. public function ptz_ContinuousMoveZoom($profileToken,$zoom) {
  545. if ($this->ptzuri=='') return array();
  546. $REQ=$this->_makeToken();
  547. $post_string='<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>%%USERNAME%%</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%%PASSWORD%%</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%%NONCE%%</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%%CREATED%%</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><ContinuousMove xmlns="http://www.onvif.org/ver20/ptz/wsdl"><ProfileToken>%%PROFILETOKEN%%</ProfileToken><Velocity><Zoom x="%%ZOOM%%" space="http://www.onvif.org/ver10/tptz/ZoomSpaces/VelocityGenericSpace" xmlns="http://www.onvif.org/ver10/schema"/></Velocity></ContinuousMove></s:Body></s:Envelope>';
  548. $post_string=str_replace(array("%%USERNAME%%",
  549. "%%PASSWORD%%",
  550. "%%NONCE%%",
  551. "%%CREATED%%",
  552. "%%PROFILETOKEN%%",
  553. "%%ZOOM%%"),
  554. array($REQ['USERNAME'],
  555. $REQ['PASSDIGEST'],
  556. $REQ['NONCE'],
  557. $REQ['TIMESTAMP'],
  558. $profileToken,
  559. $zoom),
  560. $post_string);
  561. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  562. if ($this->intransingent) throw new Exception('ContinuousMoveZoom: Communication error');
  563. }
  564. }
  565. public function ptz_Stop($profileToken,$pantilt,$zoom) {
  566. if ($this->ptzuri=='') return array();
  567. $REQ=$this->_makeToken();
  568. $post_string='<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>%%USERNAME%%</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%%PASSWORD%%</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%%NONCE%%</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%%CREATED%%</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Stop xmlns="http://www.onvif.org/ver20/ptz/wsdl"><ProfileToken>%%PROFILETOKEN%%</ProfileToken><PanTilt>%%PANTILT%%</PanTilt><Zoom>%%ZOOM%%</Zoom></Stop></s:Body></s:Envelope>';
  569. $post_string=str_replace(array("%%USERNAME%%",
  570. "%%PASSWORD%%",
  571. "%%NONCE%%",
  572. "%%CREATED%%",
  573. "%%PROFILETOKEN%%",
  574. "%%PANTILT%%",
  575. "%%ZOOM%%"),
  576. array($REQ['USERNAME'],
  577. $REQ['PASSDIGEST'],
  578. $REQ['NONCE'],
  579. $REQ['TIMESTAMP'],
  580. $profileToken,
  581. $pantilt,
  582. $zoom),
  583. $post_string);
  584. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  585. if ($this->intransingent) throw new Exception('Stop: Communication error');
  586. }
  587. }
  588. /*
  589. Internal functions
  590. */
  591. protected function _makeToken() {
  592. $timestamp=time()-$this->deltatime;
  593. return $this->_passwordDigest($this->username,$this->password,date('Y-m-d\TH:i:s.000\Z',$timestamp));
  594. }
  595. protected function _getOnvifVersion($capabilities) {
  596. $version=array();
  597. if (isset($capabilities['Device']['System']['SupportedVersions']['Major'])) {
  598. // NVT supports a specific onvif version
  599. $version['major']=$capabilities['Device']['System']['SupportedVersions']['Major'];
  600. $version['minor']=$capabilities['Device']['System']['SupportedVersions']['Minor'];
  601. } else {
  602. // NVT supports more onvif versions
  603. $currentma=0;
  604. $currentmi=0;
  605. foreach ($capabilities['Device']['System']['SupportedVersions'] as $cver) {
  606. if ($cver['Major']>$currentma) { $currentma=$cver['Major'];$currentmi=$cver['Minor']; }
  607. }
  608. $version['major']=$currentma;
  609. $version['minor']=$currentmi;
  610. }
  611. $version['media']=$capabilities['Media']['XAddr'];
  612. $version['device']=$capabilities['Device']['XAddr'];
  613. $version['event']=$capabilities['Events']['XAddr'];
  614. if (isset($capabilities['PTZ']['XAddr'])) $version['ptz']=$capabilities['PTZ']['XAddr']; else $version['ptz']='';
  615. return $version;
  616. }
  617. protected function _getActiveSources($videoSources,$profiles) {
  618. $sources=array();
  619. if (isset($videoSources['@attributes'])) {
  620. // NVT is a camera
  621. $sources[0]['sourcetoken']=$videoSources['@attributes']['token'];
  622. $this->_getProfileData($sources,0,$profiles);
  623. }
  624. else {
  625. // NVT is an encoder
  626. for ($i=0;$i<count($videoSources);$i++) {
  627. if (strtolower($videoSources[$i]['@attributes']['SignalActive'])=='true') {
  628. $sources[$i]['sourcetoken']=$videoSources[$i]['@attributes']['token'];
  629. $this->_getProfileData($sources,$i,$profiles);
  630. }
  631. } // for
  632. }
  633. return $sources;
  634. }
  635. protected function _getProfileData(&$sources,$i,$profiles) {
  636. $inprofile=0;
  637. for ($y=0; $y < count($profiles); $y++) {
  638. if ($profiles[$y]['VideoSourceConfiguration']['SourceToken']==$sources[$i]['sourcetoken']) {
  639. $sources[$i][$inprofile]['profilename']=$profiles[$y]['Name'];
  640. $sources[$i][$inprofile]['profiletoken']=$profiles[$y]['@attributes']['token'];
  641. if ( isset($profiles[$y]['VideoEncoderConfiguration'])) {
  642. $sources[$i][$inprofile]['encoding']=$profiles[$y]['VideoEncoderConfiguration']['Encoding'];
  643. $sources[$i][$inprofile]['width']=$profiles[$y]['VideoEncoderConfiguration']['Resolution']['Width'];
  644. $sources[$i][$inprofile]['height']=$profiles[$y]['VideoEncoderConfiguration']['Resolution']['Height'];
  645. $sources[$i][$inprofile]['fps']=$profiles[$y]['VideoEncoderConfiguration']['RateControl']['FrameRateLimit'];
  646. $sources[$i][$inprofile]['bitrate']=$profiles[$y]['VideoEncoderConfiguration']['RateControl']['BitrateLimit'];
  647. }
  648. if ( isset($profiles[$y]['PTZConfiguration'])) {
  649. $sources[$i][$inprofile]['ptz']['name']=$profiles[$y]['PTZConfiguration']['Name'];
  650. $sources[$i][$inprofile]['ptz']['nodetoken']=$profiles[$y]['PTZConfiguration']['NodeToken'];
  651. }
  652. $inprofile++;
  653. }
  654. }
  655. }
  656. protected function _xml2array($response) {
  657. $sxe = new SimpleXMLElement($response);
  658. $dom_sxe = dom_import_simplexml($sxe);
  659. $dom = new DOMDocument('1.0');
  660. $dom_sxe = $dom->importNode($dom_sxe, true);
  661. $dom_sxe = $dom->appendChild($dom_sxe);
  662. $element = $dom->childNodes->item(0);
  663. foreach ($sxe->getDocNamespaces() as $name => $uri) {
  664. $element->removeAttributeNS($uri, $name);
  665. }
  666. $xmldata=$dom->saveXML();
  667. $xmldata=substr($xmldata,strpos($xmldata,"<Envelope>"));
  668. $xmldata=substr($xmldata,0,strpos($xmldata,"</Envelope>")+strlen("</Envelope>"));
  669. $xml=simplexml_load_string($xmldata);
  670. $data=json_decode(json_encode((array)$xml),1);
  671. $data=array($xml->getName()=>$data);
  672. return $data;
  673. }
  674. protected function _passwordDigest( $username, $password, $timestamp = "default", $nonce = "default", $realm='', $cnonce='' ) {
  675. if ($timestamp=='default') $timestamp=date('Y-m-d\TH:i:s.000\Z');
  676. if ($nonce=='default') $nonce=mt_rand();
  677. $REQ=array();
  678. switch( $this->digestMethod ){
  679. case 'SHA-256':
  680. $H1 = pack('H*', sha1(pack('H*', $nonce) . pack('a*',$timestamp) . pack('a*',$password)));
  681. break;
  682. case 'SHA-256-sess':
  683. case 'SHA-512-256':
  684. case 'SHA-512-256-sess':
  685. case 'MD5':
  686. $H1 = pack('H*', md5( pack('a*', $username) . pack('a*', $realm) . pack('a*', $password) ) );
  687. //$H2 =
  688. break;
  689. case 'MD5-sess':
  690. $H1 = pack('H*', md5( pack('H*', md5( pack('a*', $username) . pack('a*', $realm) . pack('a*', $password) ) ) . pack('H*', $nonce).pack('H*', $cnonce ) ) );
  691. break;
  692. default:
  693. $passdigest=base64_encode(sha1($nonce.$timestamp.$password,true)); // alternative
  694. };
  695. $REQ['USERNAME']=$username;
  696. $REQ['PASSDIGEST']=base64_encode( $H1 );//$passdigest );
  697. $REQ['NONCE']=base64_encode(pack('H*', $nonce));
  698. //$REQ['NONCE']=base64_encode($nonce); // alternative
  699. //$REQ['NONCE']=base64_encode(pack('H*', $nonce));
  700. $REQ['TIMESTAMP']=$timestamp;
  701. return $REQ;
  702. }
  703. protected function _send_request($url,$post_string) {
  704. $soap_do = curl_init();
  705. curl_setopt($soap_do, CURLOPT_URL, $url );
  706. if ($this->proxyhost!='' && $this->proxyport!='') {
  707. curl_setopt($soap_do, CURLOPT_PROXY, $this->proxyhost);
  708. curl_setopt($soap_do, CURLOPT_PROXYPORT, $this->proxyport);
  709. if ($this->proxyusername!='' && $this->proxypassword!='')
  710. curl_setopt($soap_do, CURLOPT_PROXYUSERPWD, $this->proxyusername.':'.$this->proxypassword);
  711. }
  712. curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 2 );
  713. curl_setopt($soap_do, CURLOPT_TIMEOUT, 2 );
  714. curl_setopt($soap_do, CURLOPT_HEADER, true );
  715. curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
  716. curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
  717. //curl_setopt($soap_do, CURLOPT_VERBOSE, true);
  718. //curl_setopt($soap_do, CURLOPT_DEBUG, true);
  719. curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
  720. curl_setopt($soap_do, CURLOPT_POST, true );
  721. curl_setopt($soap_do, CURLOPT_POSTFIELDS, $post_string);
  722. curl_setopt($soap_do, CURLOPT_HTTPHEADER, array('Expect:', 'Content-Type: application/soap+xml; charset=utf-8', 'Content-Length: '.strlen($post_string) ));
  723. curl_setopt($soap_do, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
  724. curl_setopt($soap_do, CURLOPT_USERPWD, $this->username . ":" . $this->password ); // HTTP authentication
  725. if ( ($result = curl_exec($soap_do)) === false) {
  726. $err = curl_error($soap_do);
  727. $this->lastresponse=array("Fault"=>$err);
  728. } else {
  729. $headerSize = curl_getinfo( $soap_do, CURLINFO_HEADER_SIZE );
  730. $headerStr = substr( $result , 0 , $headerSize );
  731. $bodyStr = substr( $result , $headerSize );
  732. echo "QU: {$url}\n";
  733. echo "\n------------------\n";
  734. var_dump( $post_string );
  735. echo "\n~~~~~~~~~~~~~~~~~~\n";
  736. var_dump( $headerStr );
  737. echo "\n~~~~~~~~~~~~~~~~~~\n";
  738. var_dump( $bodyStr );
  739. echo "\n~~~~~~~~~~~~~~~~~~\n";
  740. $headersTmpArray = explode( "\r\n" , $headerStr );
  741. $R_CONT = 'text/html';
  742. $R_CODE = 0;
  743. foreach( $headersTmpArray as $H ){
  744. $CL = trim( $H );
  745. if( $CL!= '' ){
  746. $SS = explode( ' ', $CL );
  747. $Biba = explode( ':', $CL );
  748. if( $SS[0] == 'HTTP/1.1' ){
  749. $R_CODE = intval( $SS[1] );
  750. $R_REASON = $SS[2];
  751. } else {
  752. switch( $Biba[0] ){
  753. case 'WWW-Authenticate':{
  754. $AA = str_ireplace( ',','', trim( $Biba[1] ));
  755. $AA = str_ireplace( '"','', $AA );
  756. $BB = explode( ' ', $AA );
  757. if( $BB[0] == 'Digest' ){
  758. $this->useDigest = true;
  759. foreach( $BB as $B ){
  760. $PO = explode( '=', $B );
  761. switch( $PO[0] ){
  762. case 'qop': $this->qop=$PO[1]; break;
  763. case 'realm': $this->auth_realm=$PO[1]; break;
  764. case 'algorithm': $this->digestMethod=$PO[1]; break;
  765. case 'nonce':{
  766. $this->auth_nonce = substr( $B, 6 );//base64_decode( substr( $B, 6 ) );
  767. break;
  768. };
  769. };
  770. };
  771. };
  772. break;
  773. };
  774. case 'Authentication-Info':{
  775. break;
  776. };
  777. case 'Content-Type':{
  778. $R_CONT = str_ireplace( ';', '', $SS[1] );
  779. };
  780. };
  781. };
  782. };
  783. };
  784. if( $R_CODE == 200 ){
  785. if( $R_CONT != 'text/html' ){
  786. $this->lastresponse=$this->_xml2array( $bodyStr );
  787. } else {
  788. $this->lastresponse=array("Fault"=>"Content is TEXT/HTML!");
  789. };
  790. } else {
  791. $err = 'Code: '.$R_CODE.' '.$R_REASON;
  792. $this->lastresponse=array("Fault"=>$err);
  793. };
  794. };
  795. return $this->lastresponse;
  796. }
  797. } // end class
  798. ?>