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.

743 lines
49 KiB

6 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. public function setProxyHost($proxyHost) { $this->proxyhost = $proxyHost; }
  29. public function getProxyHost() { return $this->proxyhost; }
  30. public function setProxyPort($proxyPort) { $this->proxyport = $proxyPort; }
  31. public function getProxyPort() { return $this->proxyport; }
  32. public function setProxyUsername($proxyUsername) { $this->proxyusername = $proxyUsername; }
  33. public function getProxyUsername() { return $this->proxyusername; }
  34. public function setProxyPassword($proxyPassword) { $this->proxypassword = $proxyPassword; }
  35. public function getProxyPassword() { return $this->proxypassword; }
  36. public function setUsername($username) { $this->username = $username; }
  37. public function getUsername() { return $this->username; }
  38. public function setPassword($password) { $this->password = $password; }
  39. public function getPassword() { return $this->password; }
  40. public function getDeviceUri() { return $this->mediauri; }
  41. public function setDeviceUri($deviceUri) { $this->mediauri=$deviceUrl; }
  42. public function getIPAddress($ipAddress) { return $this->ipAddress; }
  43. public function setIPAddress($ipAddress) { $this->ipaddress=$ipAddress; }
  44. public function getSources() { return $this->sources; }
  45. public function getMediaUri() { return $this->mediauri; }
  46. public function getPTZUri() { return $this->ptzuri; }
  47. public function getBaseUrl() { return $this->baseuri; }
  48. public function getSupportedVersion() { return $this->onvifversion; }
  49. public function getCapabilities() { return $this->capabilities; }
  50. public function setBreakOnError($intransingent) { $this->intransingent=$intransingent; }
  51. public function getLastResponse() { return $this->lastresponse; }
  52. public function setDiscoveryTimeout($discoverytimeout) { $this->discoverytimeout = $discoverytimeout; }
  53. public function setDiscoveryBindIp($discoverybindip) { $this->discoverybindip = $discoverybindip; }
  54. public function setDiscoveryMcastIp($discoverymcastip) { $this->discoverymcastip = $discoverymcastip; }
  55. public function setDiscoveryMcastPort($discoverymcastport) { $this->discoverymcastport = $discoverymcastport; }
  56. public function setDiscoveryHideDuplicates($discoveryhideduplicates) { $this->discoveryhideduplicates = $discoveryhideduplicates; }
  57. public function getSnapshotUri() { return $this->snapshoturi; }
  58. /*
  59. Constructor & Destructor
  60. */
  61. public function __construct()
  62. {
  63. // nothing to do
  64. }
  65. public function __destruct()
  66. {
  67. // nothing to do
  68. }
  69. /*
  70. WS-Discovery
  71. */
  72. public function discover(){
  73. $result = array();
  74. $timeout = time() + $this->discoverytimeout;
  75. $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>';
  76. try {
  77. if(FALSE == ($sock = @socket_create(AF_INET, SOCK_DGRAM, SOL_UDP))){
  78. echo('Create socket error: ['.socket_last_error().'] '.socket_strerror(socket_last_error()));
  79. }
  80. if(FALSE == @socket_bind($sock, $this->discoverybindip, rand(20000, 40000))){
  81. echo('Bind socket error: ['.socket_last_error().'] '.socket_strerror(socket_last_error()));
  82. }
  83. socket_set_option($sock, IPPROTO_IP, MCAST_JOIN_GROUP, array('group' => $this->discoverymcastip));
  84. socket_sendto($sock, $post_string, strlen($post_string), 0, $this->discoverymcastip, $this->discoverymcastport);
  85. socket_set_nonblock($sock);
  86. while(time() < $timeout){
  87. if(FALSE !== @socket_recvfrom($sock, $response, 9999, 0, $from, $this->discoverymcastport)){
  88. if($response != NULL && $response != $post_string){
  89. $response = $this->_xml2array($response);
  90. if(!$this->isFault($response)){
  91. $response['Envelope']['Body']['ProbeMatches']['ProbeMatch']['IPAddr'] = $from;
  92. if($this->discoveryhideduplicates){
  93. $result[$from] = $response['Envelope']['Body']['ProbeMatches']['ProbeMatch'];
  94. }else{
  95. $result[] = $response['Envelope']['Body']['ProbeMatches']['ProbeMatch'];
  96. }
  97. }
  98. }
  99. }
  100. }
  101. socket_close($sock);
  102. } catch (Exception $e) {}
  103. sort($result);
  104. return $result;
  105. }
  106. /*
  107. Public functions (basic initialization method and other collaterals)
  108. */
  109. public function initialize() {
  110. $this->mediauri='http://'.$this->ipaddress.'/onvif/device_service';
  111. try {
  112. $datetime=$this->core_GetSystemDateAndTime();
  113. $timestamp=mktime($datetime['Time']['Hour'], $datetime['Time']['Minute'], $datetime['Time']['Second'],
  114. $datetime['Date']['Month'], $datetime['Date']['Day'], $datetime['Date']['Year']);
  115. $this->deltatime=time()-$timestamp-5;
  116. } catch (Exception $e) {}
  117. $this->capabilities=$this->core_GetCapabilities();
  118. $onvifVersion=$this->_getOnvifVersion($this->capabilities);
  119. $this->mediauri=$onvifVersion['media'];
  120. $this->deviceuri=$onvifVersion['device'];
  121. $this->ptzuri=$onvifVersion['ptz'];
  122. preg_match("/^http(.*)onvif\//",$this->mediauri,$matches);
  123. $this->baseuri=$matches[0];
  124. $this->onvifversion=array('major'=>$onvifVersion['major'],'minor'=>$onvifVersion['minor']);
  125. $this->videosources=$this->media_GetVideoSources();
  126. $this->profiles=$this->media_GetProfiles();
  127. $this->sources=$this->_getActiveSources($this->videosources,$this->profiles);
  128. }
  129. public function isFault($response) { // Useful to check if response contains a fault
  130. if( is_array( $response ) ){
  131. if( array_key_exists('Fault', $response ) ) return true;
  132. if( array_key_exists('Envelope', $response ) )
  133. if( is_array( $response['Envelope'] ) )
  134. if( array_key_exists('Body', $response['Envelope'] ) )
  135. if( is_array( $response['Envelope']['Body'] ) )
  136. if( array_key_exists('Fault', $response['Envelope']['Body'] ) ) return true;
  137. };
  138. return false;
  139. }
  140. /*
  141. Public wrappers for a subset of ONVIF primitives
  142. */
  143. public function core_GetSystemDateAndTime() {
  144. $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>';
  145. if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) {
  146. if ($this->intransingent) throw new Exception('GetSystemDateAndTime: Communication error');
  147. } else {
  148. return $response['Envelope']['Body']['GetSystemDateAndTimeResponse']['SystemDateAndTime']['UTCDateTime'];
  149. }
  150. }
  151. public function core_GetCapabilities() {
  152. $REQ=$this->_makeToken();
  153. $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>';
  154. $post_string=str_replace(array("%%USERNAME%%",
  155. "%%PASSWORD%%",
  156. "%%NONCE%%",
  157. "%%CREATED%%"),
  158. array($REQ['USERNAME'],
  159. $REQ['PASSDIGEST'],
  160. $REQ['NONCE'],
  161. $REQ['TIMESTAMP']),
  162. $post_string);
  163. if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) {
  164. if ($this->intransingent) throw new Exception('GetCapabilities: Communication error');
  165. }
  166. else
  167. return $response['Envelope']['Body']['GetCapabilitiesResponse']['Capabilities'];
  168. }
  169. public function media_GetVideoSources() {
  170. $REQ=$this->_makeToken();
  171. $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>';
  172. $post_string=str_replace(array("%%USERNAME%%",
  173. "%%PASSWORD%%",
  174. "%%NONCE%%",
  175. "%%CREATED%%"),
  176. array($REQ['USERNAME'],
  177. $REQ['PASSDIGEST'],
  178. $REQ['NONCE'],
  179. $REQ['TIMESTAMP']),
  180. $post_string);
  181. //echo "POST STRING:" . $post_string . "\n\n";
  182. if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) {
  183. if ($this->intransingent) throw new Exception('GetVideoSources: Communication error');
  184. }
  185. else
  186. // var_dump( $response );
  187. return $response['Envelope']['Body']['GetVideoSourcesResponse']['VideoSources'];
  188. }
  189. public function media_GetProfiles() {
  190. $REQ=$this->_makeToken();
  191. $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>';
  192. $post_string=str_replace(array("%%USERNAME%%",
  193. "%%PASSWORD%%",
  194. "%%NONCE%%",
  195. "%%CREATED%%"),
  196. array($REQ['USERNAME'],
  197. $REQ['PASSDIGEST'],
  198. $REQ['NONCE'],
  199. $REQ['TIMESTAMP']),
  200. $post_string);
  201. if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) {
  202. if ($this->intransingent) throw new Exception('GetProfiles: Communication error');
  203. }
  204. else
  205. return $response['Envelope']['Body']['GetProfilesResponse']['Profiles'];
  206. }
  207. public function media_GetServices() {
  208. $REQ=$this->_makeToken();
  209. $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>';
  210. $post_string=str_replace(array("%%USERNAME%%",
  211. "%%PASSWORD%%",
  212. "%%NONCE%%",
  213. "%%CREATED%%"),
  214. array($REQ['USERNAME'],
  215. $REQ['PASSDIGEST'],
  216. $REQ['NONCE'],
  217. $REQ['TIMESTAMP']),
  218. $post_string);
  219. if ($this->isFault($this->_send_request($this->mediauri,$post_string))) {
  220. if ($this->intransingent) throw new Exception('GetServices: Communication error');
  221. }
  222. }
  223. public function core_GetDeviceInformation() {
  224. $REQ=$this->_makeToken();
  225. $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>';
  226. $post_string=str_replace(array("%%USERNAME%%",
  227. "%%PASSWORD%%",
  228. "%%NONCE%%",
  229. "%%CREATED%%"),
  230. array($REQ['USERNAME'],
  231. $REQ['PASSDIGEST'],
  232. $REQ['NONCE'],
  233. $REQ['TIMESTAMP']),
  234. $post_string);
  235. if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) {
  236. if ($this->intransingent) throw new Exception('GetDeviceInformation: Communication error');
  237. }
  238. else
  239. return $response['Envelope']['Body']['GetDeviceInformationResponse'];
  240. }
  241. public function media_GetStreamUri($profileToken,$stream="RTP-Unicast",$protocol="RTSP") {
  242. $REQ=$this->_makeToken();
  243. $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>';
  244. $post_string=str_replace(
  245. array("%%USERNAME%%",
  246. "%%PASSWORD%%",
  247. "%%NONCE%%",
  248. "%%CREATED%%",
  249. "%%PROFILETOKEN%%",
  250. "%%STREAM%%",
  251. "%%PROTOCOL%%"),
  252. array($REQ['USERNAME'],
  253. $REQ['PASSDIGEST'],
  254. $REQ['NONCE'],
  255. $REQ['TIMESTAMP'],
  256. $profileToken,
  257. $stream,
  258. $protocol),
  259. $post_string
  260. );
  261. if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) {
  262. if ($this->intransingent) throw new Exception('GetStreamUri: Communication error');
  263. }
  264. else
  265. return $response['Envelope']['Body']['GetStreamUriResponse']['MediaUri']['Uri'];
  266. }
  267. public function media_GetSnapshotUri($profileToken) {
  268. $REQ=$this->_makeToken();
  269. $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>';
  270. $post_string=str_replace(array("%%USERNAME%%",
  271. "%%PASSWORD%%",
  272. "%%NONCE%%",
  273. "%%CREATED%%",
  274. "%%PROFILETOKEN%%"),
  275. array($REQ['USERNAME'],
  276. $REQ['PASSDIGEST'],
  277. $REQ['NONCE'],
  278. $REQ['TIMESTAMP'],
  279. $profileToken),
  280. $post_string);
  281. if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) {
  282. if ($this->intransingent) throw new Exception('GetSnapshotUri: Communication error');
  283. var_dump($response);
  284. }
  285. else
  286. return $response['Envelope']['Body']['GetSnapshotUriResponse']['MediaUri']['Uri'];
  287. }
  288. public function ptz_GetPresets($profileToken) {
  289. if ($this->ptzuri=='') return array();
  290. $REQ=$this->_makeToken();
  291. $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>';
  292. $post_string=str_replace(array("%%USERNAME%%",
  293. "%%PASSWORD%%",
  294. "%%NONCE%%",
  295. "%%CREATED%%",
  296. "%%PROFILETOKEN%%"),
  297. array($REQ['USERNAME'],
  298. $REQ['PASSDIGEST'],
  299. $REQ['NONCE'],
  300. $REQ['TIMESTAMP'],
  301. $profileToken),
  302. $post_string);
  303. if ($this->isFault($response=$this->_send_request($this->ptzuri,$post_string))) {
  304. if ($this->intransingent) throw new Exception('GetPresets: Communication error');
  305. }
  306. else {
  307. $getpresetsresponse=$response['Envelope']['Body']['GetPresetsResponse']['Preset'];
  308. $presets=array();
  309. foreach ($getpresetsresponse as $preset) {
  310. $presets[]=array('Token'=>$preset['@attributes']['token'],
  311. 'Name'=>$preset['Name'],
  312. 'PTZPosition'=>$preset['PTZPosition']);
  313. }
  314. return $presets;
  315. }
  316. }
  317. public function ptz_GetNode($ptzNodeToken) {
  318. if ($this->ptzuri=='') return array();
  319. $REQ=$this->_makeToken();
  320. $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>';
  321. $post_string=str_replace(array("%%USERNAME%%",
  322. "%%PASSWORD%%",
  323. "%%NONCE%%",
  324. "%%CREATED%%",
  325. "%%NODETOKEN%%"),
  326. array($REQ['USERNAME'],
  327. $REQ['PASSDIGEST'],
  328. $REQ['NONCE'],
  329. $REQ['TIMESTAMP'],
  330. $ptzNodeToken),
  331. $post_string);
  332. if ($this->isFault($response=$this->_send_request($this->ptzuri,$post_string))) {
  333. if ($this->intransingent) throw new Exception('GetNode: Communication error');
  334. }
  335. else
  336. return $response['Envelope']['Body']['GetNodeResponse'];
  337. }
  338. public function ptz_GotoPreset($profileToken,$presetToken,$speed_pantilt_x,$speed_pantilt_y,$speed_zoom_x) {
  339. if ($this->ptzuri=='') return array();
  340. $REQ=$this->_makeToken();
  341. $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>';
  342. $post_string=str_replace(array("%%USERNAME%%",
  343. "%%PASSWORD%%",
  344. "%%NONCE%%",
  345. "%%CREATED%%",
  346. "%%PROFILETOKEN%%",
  347. "%%PRESETTOKEN%%",
  348. "%%SPEEDPANTILTX%%",
  349. "%%SPEEDPANTILTY%%",
  350. "%%SPEEDZOOMX%%"),
  351. array($REQ['USERNAME'],
  352. $REQ['PASSDIGEST'],
  353. $REQ['NONCE'],
  354. $REQ['TIMESTAMP'],
  355. $profileToken,
  356. $presetToken,
  357. $speed_pantilt_x,
  358. $speed_pantilt_y,
  359. $speed_zoom_x),
  360. $post_string);
  361. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  362. if ($this->intransingent) throw new Exception('GotoPreset: Communication error');
  363. }
  364. }
  365. public function ptz_RemovePreset($profileToken,$presetToken) {
  366. if ($this->ptzuri=='') return array();
  367. $REQ=$this->_makeToken();
  368. $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>';
  369. $post_string=str_replace(array("%%USERNAME%%",
  370. "%%PASSWORD%%",
  371. "%%NONCE%%",
  372. "%%CREATED%%",
  373. "%%PROFILETOKEN%%",
  374. "%%PRESETTOKEN%%"),
  375. array($REQ['USERNAME'],
  376. $REQ['PASSDIGEST'],
  377. $REQ['NONCE'],
  378. $REQ['TIMESTAMP'],
  379. $profileToken,
  380. $presetToken),
  381. $post_string);
  382. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  383. if ($this->intransingent) throw new Exception('RemovePreset: Communication error');
  384. }
  385. }
  386. public function ptz_SetPreset($profileToken,$presetName) {
  387. if ($this->ptzuri=='') return array();
  388. $REQ=$this->_makeToken();
  389. $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>';
  390. $post_string=str_replace(array("%%USERNAME%%",
  391. "%%PASSWORD%%",
  392. "%%NONCE%%",
  393. "%%CREATED%%",
  394. "%%PROFILETOKEN%%",
  395. "%%PRESETNAME%%"),
  396. array($REQ['USERNAME'],
  397. $REQ['PASSDIGEST'],
  398. $REQ['NONCE'],
  399. $REQ['TIMESTAMP'],
  400. $profileToken,
  401. $presetName),
  402. $post_string);
  403. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  404. if ($this->intransingent) throw new Exception('SetPreset: Communication error');
  405. }
  406. }
  407. public function ptz_RelativeMove($profileToken,$translation_pantilt_x,$translation_pantilt_y,$speed_pantilt_x,$speed_pantilt_y) {
  408. if ($this->ptzuri=='') return array();
  409. $REQ=$this->_makeToken();
  410. $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>';
  411. $post_string=str_replace(array("%%USERNAME%%",
  412. "%%PASSWORD%%",
  413. "%%NONCE%%",
  414. "%%CREATED%%",
  415. "%%PROFILETOKEN%%",
  416. "%%TRANSLATIONPANTILTX%%",
  417. "%%TRANSLATIONPANTILTY%%",
  418. "%%SPEEDPANTILTX%%",
  419. "%%SPEEDPANTILTY%%"),
  420. array($REQ['USERNAME'],
  421. $REQ['PASSDIGEST'],
  422. $REQ['NONCE'],
  423. $REQ['TIMESTAMP'],
  424. $profileToken,
  425. $translation_pantilt_x,
  426. $translation_pantilt_y,
  427. $speed_pantilt_x,
  428. $speed_pantilt_y),
  429. $post_string);
  430. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  431. if ($this->intransingent) throw new Exception('RelativeMove: Communication error');
  432. }
  433. }
  434. public function ptz_RelativeMoveZoom($profileToken,$zoom,$speedZoom) {
  435. if ($this->ptzuri=='') return array();
  436. $REQ=$this->_makeToken();
  437. $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>';
  438. $post_string=str_replace(array("%%USERNAME%%",
  439. "%%PASSWORD%%",
  440. "%%NONCE%%",
  441. "%%CREATED%%",
  442. "%%PROFILETOKEN%%",
  443. "%%SPEEDZOOM%%",
  444. "%%ZOOM%%"),
  445. array($REQ['USERNAME'],
  446. $REQ['PASSDIGEST'],
  447. $REQ['NONCE'],
  448. $REQ['TIMESTAMP'],
  449. $profileToken,
  450. $speedZoom,
  451. $zoom),
  452. $post_string);
  453. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  454. if ($this->intransingent) throw new Exception('RelativeMoveZoom: Communication error');
  455. }
  456. }
  457. public function ptz_GetStatus( $profileToken ){
  458. $REQ=$this->_makeToken();
  459. $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>';
  460. $post_string=str_replace(array("%%USERNAME%%",
  461. "%%PASSWORD%%",
  462. "%%NONCE%%",
  463. "%%CREATED%%",
  464. "%%PROFILETOKEN%%"),
  465. array($REQ['USERNAME'],
  466. $REQ['PASSDIGEST'],
  467. $REQ['NONCE'],
  468. $REQ['TIMESTAMP'],
  469. $profileToken),
  470. $post_string);
  471. if ($this->isFault($response = $this->_send_request($this->ptzuri,$post_string))) {
  472. if ($this->intransingent) throw new Exception('ptz Get Status: Communication error');
  473. } else {
  474. var_dump( $response );
  475. $cpos=$response['Envelope']['Body']['GetStatusResponse']['PTZStatus']['Position'];
  476. return $cpos;
  477. };
  478. }
  479. public function ptz_AbsoluteMove($profileToken,$position_pantilt_x,$position_pantilt_y,$zoom, $PSpeed=1.0, $TSpeed=1.0, $ZSpeed=1.0 ) {
  480. if ($this->ptzuri=='') return array();
  481. $REQ=$this->_makeToken();
  482. $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>';
  483. $post_string=str_replace(array("%%USERNAME%%",
  484. "%%PASSWORD%%",
  485. "%%NONCE%%",
  486. "%%CREATED%%",
  487. "%%PROFILETOKEN%%",
  488. "%%POSITIONPANTILTX%%",
  489. "%%POSITIONPANTILTY%%",
  490. "%%ZOOM%%",
  491. "%%SPEEDPANTILTX%%",
  492. "%%SPEEDPANTILTY%%",
  493. "%%SPEEDZOOMX%%"),
  494. array($REQ['USERNAME'],
  495. $REQ['PASSDIGEST'],
  496. $REQ['NONCE'],
  497. $REQ['TIMESTAMP'],
  498. $profileToken,
  499. $position_pantilt_x,
  500. $position_pantilt_y,
  501. $zoom,
  502. $PSpeed,
  503. $TSpeed,
  504. $ZSpeed),
  505. $post_string);
  506. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  507. if ($this->intransingent) throw new Exception('AbsoluteMove: Communication error');
  508. }
  509. }
  510. public function ptz_ContinuousMove($profileToken,$velocity_pantilt_x,$velocity_pantilt_y) {
  511. if ($this->ptzuri=='') return array();
  512. $REQ=$this->_makeToken();
  513. $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>';
  514. $post_string=str_replace(array("%%USERNAME%%",
  515. "%%PASSWORD%%",
  516. "%%NONCE%%",
  517. "%%CREATED%%",
  518. "%%PROFILETOKEN%%",
  519. "%%VELOCITYPANTILTX%%",
  520. "%%VELOCITYPANTILTY%%"),
  521. array($REQ['USERNAME'],
  522. $REQ['PASSDIGEST'],
  523. $REQ['NONCE'],
  524. $REQ['TIMESTAMP'],
  525. $profileToken,
  526. $velocity_pantilt_x,
  527. $velocity_pantilt_y),
  528. $post_string);
  529. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  530. if ($this->intransingent) throw new Exception('ContinuousMove: Communication error');
  531. }
  532. }
  533. public function ptz_ContinuousMoveZoom($profileToken,$zoom) {
  534. if ($this->ptzuri=='') return array();
  535. $REQ=$this->_makeToken();
  536. $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>';
  537. $post_string=str_replace(array("%%USERNAME%%",
  538. "%%PASSWORD%%",
  539. "%%NONCE%%",
  540. "%%CREATED%%",
  541. "%%PROFILETOKEN%%",
  542. "%%ZOOM%%"),
  543. array($REQ['USERNAME'],
  544. $REQ['PASSDIGEST'],
  545. $REQ['NONCE'],
  546. $REQ['TIMESTAMP'],
  547. $profileToken,
  548. $zoom),
  549. $post_string);
  550. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  551. if ($this->intransingent) throw new Exception('ContinuousMoveZoom: Communication error');
  552. }
  553. }
  554. public function ptz_Stop($profileToken,$pantilt,$zoom) {
  555. if ($this->ptzuri=='') return array();
  556. $REQ=$this->_makeToken();
  557. $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>';
  558. $post_string=str_replace(array("%%USERNAME%%",
  559. "%%PASSWORD%%",
  560. "%%NONCE%%",
  561. "%%CREATED%%",
  562. "%%PROFILETOKEN%%",
  563. "%%PANTILT%%",
  564. "%%ZOOM%%"),
  565. array($REQ['USERNAME'],
  566. $REQ['PASSDIGEST'],
  567. $REQ['NONCE'],
  568. $REQ['TIMESTAMP'],
  569. $profileToken,
  570. $pantilt,
  571. $zoom),
  572. $post_string);
  573. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  574. if ($this->intransingent) throw new Exception('Stop: Communication error');
  575. }
  576. }
  577. /*
  578. Internal functions
  579. */
  580. protected function _makeToken() {
  581. $timestamp=time()-$this->deltatime;
  582. return $this->_passwordDigest($this->username,$this->password,date('Y-m-d\TH:i:s.000\Z',$timestamp));
  583. }
  584. protected function _getOnvifVersion($capabilities) {
  585. $version=array();
  586. if (isset($capabilities['Device']['System']['SupportedVersions']['Major'])) {
  587. // NVT supports a specific onvif version
  588. $version['major']=$capabilities['Device']['System']['SupportedVersions']['Major'];
  589. $version['minor']=$capabilities['Device']['System']['SupportedVersions']['Minor'];
  590. } else {
  591. // NVT supports more onvif versions
  592. $currentma=0;
  593. $currentmi=0;
  594. foreach ($capabilities['Device']['System']['SupportedVersions'] as $cver) {
  595. if ($cver['Major']>$currentma) { $currentma=$cver['Major'];$currentmi=$cver['Minor']; }
  596. }
  597. $version['major']=$currentma;
  598. $version['minor']=$currentmi;
  599. }
  600. $version['media']=$capabilities['Media']['XAddr'];
  601. $version['device']=$capabilities['Device']['XAddr'];
  602. $version['event']=$capabilities['Events']['XAddr'];
  603. if (isset($capabilities['PTZ']['XAddr'])) $version['ptz']=$capabilities['PTZ']['XAddr']; else $version['ptz']='';
  604. return $version;
  605. }
  606. protected function _getActiveSources($videoSources,$profiles) {
  607. $sources=array();
  608. if (isset($videoSources['@attributes'])) {
  609. // NVT is a camera
  610. $sources[0]['sourcetoken']=$videoSources['@attributes']['token'];
  611. $this->_getProfileData($sources,0,$profiles);
  612. }
  613. else {
  614. // NVT is an encoder
  615. for ($i=0;$i<count($videoSources);$i++) {
  616. if (strtolower($videoSources[$i]['@attributes']['SignalActive'])=='true') {
  617. $sources[$i]['sourcetoken']=$videoSources[$i]['@attributes']['token'];
  618. $this->_getProfileData($sources,$i,$profiles);
  619. }
  620. } // for
  621. }
  622. return $sources;
  623. }
  624. protected function _getProfileData(&$sources,$i,$profiles) {
  625. $inprofile=0;
  626. for ($y=0; $y < count($profiles); $y++) {
  627. if ($profiles[$y]['VideoSourceConfiguration']['SourceToken']==$sources[$i]['sourcetoken']) {
  628. $sources[$i][$inprofile]['profilename']=$profiles[$y]['Name'];
  629. $sources[$i][$inprofile]['profiletoken']=$profiles[$y]['@attributes']['token'];
  630. if ( isset($profiles[$y]['VideoEncoderConfiguration'])) {
  631. $sources[$i][$inprofile]['encoding']=$profiles[$y]['VideoEncoderConfiguration']['Encoding'];
  632. $sources[$i][$inprofile]['width']=$profiles[$y]['VideoEncoderConfiguration']['Resolution']['Width'];
  633. $sources[$i][$inprofile]['height']=$profiles[$y]['VideoEncoderConfiguration']['Resolution']['Height'];
  634. $sources[$i][$inprofile]['fps']=$profiles[$y]['VideoEncoderConfiguration']['RateControl']['FrameRateLimit'];
  635. $sources[$i][$inprofile]['bitrate']=$profiles[$y]['VideoEncoderConfiguration']['RateControl']['BitrateLimit'];
  636. }
  637. if ( isset($profiles[$y]['PTZConfiguration'])) {
  638. $sources[$i][$inprofile]['ptz']['name']=$profiles[$y]['PTZConfiguration']['Name'];
  639. $sources[$i][$inprofile]['ptz']['nodetoken']=$profiles[$y]['PTZConfiguration']['NodeToken'];
  640. }
  641. $inprofile++;
  642. }
  643. }
  644. }
  645. protected function _xml2array($response) {
  646. $sxe = new SimpleXMLElement($response);
  647. $dom_sxe = dom_import_simplexml($sxe);
  648. $dom = new DOMDocument('1.0');
  649. $dom_sxe = $dom->importNode($dom_sxe, true);
  650. $dom_sxe = $dom->appendChild($dom_sxe);
  651. $element = $dom->childNodes->item(0);
  652. foreach ($sxe->getDocNamespaces() as $name => $uri) {
  653. $element->removeAttributeNS($uri, $name);
  654. }
  655. $xmldata=$dom->saveXML();
  656. $xmldata=substr($xmldata,strpos($xmldata,"<Envelope>"));
  657. $xmldata=substr($xmldata,0,strpos($xmldata,"</Envelope>")+strlen("</Envelope>"));
  658. $xml=simplexml_load_string($xmldata);
  659. $data=json_decode(json_encode((array)$xml),1);
  660. $data=array($xml->getName()=>$data);
  661. return $data;
  662. }
  663. protected function _passwordDigest( $username, $password, $timestamp = "default", $nonce = "default" ) {
  664. if ($timestamp=='default') $timestamp=date('Y-m-d\TH:i:s.000\Z');
  665. if ($nonce=='default') $nonce=mt_rand();
  666. $REQ=array();
  667. $passdigest = base64_encode(pack('H*', sha1(pack('H*', $nonce) . pack('a*',$timestamp).pack('a*',$password))));
  668. //$passdigest=base64_encode(sha1($nonce.$timestamp.$password,true)); // alternative
  669. $REQ['USERNAME']=$username;
  670. $REQ['PASSDIGEST']=$passdigest;
  671. $REQ['NONCE']=base64_encode(pack('H*', $nonce));
  672. //$REQ['NONCE']=base64_encode($nonce); // alternative
  673. $REQ['TIMESTAMP']=$timestamp;
  674. return $REQ;
  675. }
  676. protected function _send_request($url,$post_string) {
  677. $soap_do = curl_init();
  678. curl_setopt($soap_do, CURLOPT_URL, $url );
  679. if ($this->proxyhost!='' && $this->proxyport!='') {
  680. curl_setopt($soap_do, CURLOPT_PROXY, $this->proxyhost);
  681. curl_setopt($soap_do, CURLOPT_PROXYPORT, $this->proxyport);
  682. if ($this->proxyusername!='' && $this->proxypassword!='')
  683. curl_setopt($soap_do, CURLOPT_PROXYUSERPWD, $this->proxyusername.':'.$this->proxypassword);
  684. }
  685. curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
  686. curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
  687. curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
  688. curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
  689. curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
  690. curl_setopt($soap_do, CURLOPT_POST, true );
  691. curl_setopt($soap_do, CURLOPT_POSTFIELDS, $post_string);
  692. curl_setopt($soap_do, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($post_string) ));
  693. curl_setopt($soap_do, CURLOPT_USERPWD, $this->username . ":" . $this->password); // HTTP authentication
  694. if ( ($result = curl_exec($soap_do)) === false) {
  695. $err = curl_error($soap_do);
  696. $this->lastresponse=array("Fault"=>$err);
  697. } else {
  698. //var_dump( $result );
  699. $this->lastresponse=$this->_xml2array($result);
  700. }
  701. return $this->lastresponse;
  702. }
  703. } // end class
  704. ?>