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

759 lines
50 KiB

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