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.

711 lines
47 KiB

7 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. }
  148. else
  149. return $response['Envelope']['Body']['GetSystemDateAndTimeResponse']['SystemDateAndTime']['UTCDateTime'];
  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. if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) {
  182. if ($this->intransingent) throw new Exception('GetVideoSources: Communication error');
  183. }
  184. else
  185. return $response['Envelope']['Body']['GetVideoSourcesResponse']['VideoSources'];
  186. }
  187. public function media_GetProfiles() {
  188. $REQ=$this->_makeToken();
  189. $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>';
  190. $post_string=str_replace(array("%%USERNAME%%",
  191. "%%PASSWORD%%",
  192. "%%NONCE%%",
  193. "%%CREATED%%"),
  194. array($REQ['USERNAME'],
  195. $REQ['PASSDIGEST'],
  196. $REQ['NONCE'],
  197. $REQ['TIMESTAMP']),
  198. $post_string);
  199. if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) {
  200. if ($this->intransingent) throw new Exception('GetProfiles: Communication error');
  201. }
  202. else
  203. return $response['Envelope']['Body']['GetProfilesResponse']['Profiles'];
  204. }
  205. public function media_GetServices() {
  206. $REQ=$this->_makeToken();
  207. $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>';
  208. $post_string=str_replace(array("%%USERNAME%%",
  209. "%%PASSWORD%%",
  210. "%%NONCE%%",
  211. "%%CREATED%%"),
  212. array($REQ['USERNAME'],
  213. $REQ['PASSDIGEST'],
  214. $REQ['NONCE'],
  215. $REQ['TIMESTAMP']),
  216. $post_string);
  217. if ($this->isFault($this->_send_request($this->mediauri,$post_string))) {
  218. if ($this->intransingent) throw new Exception('GetServices: Communication error');
  219. }
  220. }
  221. public function core_GetDeviceInformation() {
  222. $REQ=$this->_makeToken();
  223. $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>';
  224. $post_string=str_replace(array("%%USERNAME%%",
  225. "%%PASSWORD%%",
  226. "%%NONCE%%",
  227. "%%CREATED%%"),
  228. array($REQ['USERNAME'],
  229. $REQ['PASSDIGEST'],
  230. $REQ['NONCE'],
  231. $REQ['TIMESTAMP']),
  232. $post_string);
  233. if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) {
  234. if ($this->intransingent) throw new Exception('GetDeviceInformation: Communication error');
  235. }
  236. else
  237. return $response['Envelope']['Body']['GetDeviceInformationResponse'];
  238. }
  239. public function media_GetStreamUri($profileToken,$stream="RTP-Unicast",$protocol="RTSP") {
  240. $REQ=$this->_makeToken();
  241. $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>';
  242. $post_string=str_replace(
  243. array("%%USERNAME%%",
  244. "%%PASSWORD%%",
  245. "%%NONCE%%",
  246. "%%CREATED%%",
  247. "%%PROFILETOKEN%%",
  248. "%%STREAM%%",
  249. "%%PROTOCOL%%"),
  250. array($REQ['USERNAME'],
  251. $REQ['PASSDIGEST'],
  252. $REQ['NONCE'],
  253. $REQ['TIMESTAMP'],
  254. $profileToken,
  255. $stream,
  256. $protocol),
  257. $post_string
  258. );
  259. if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) {
  260. if ($this->intransingent) throw new Exception('GetStreamUri: Communication error');
  261. }
  262. else
  263. return $response['Envelope']['Body']['GetStreamUriResponse']['MediaUri']['Uri'];
  264. }
  265. public function media_GetSnapshotUri($profileToken) {
  266. $REQ=$this->_makeToken();
  267. $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>';
  268. $post_string=str_replace(array("%%USERNAME%%",
  269. "%%PASSWORD%%",
  270. "%%NONCE%%",
  271. "%%CREATED%%",
  272. "%%PROFILETOKEN%%"),
  273. array($REQ['USERNAME'],
  274. $REQ['PASSDIGEST'],
  275. $REQ['NONCE'],
  276. $REQ['TIMESTAMP'],
  277. $profileToken),
  278. $post_string);
  279. if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) {
  280. if ($this->intransingent) throw new Exception('GetSnapshotUri: Communication error');
  281. var_dump($response);
  282. }
  283. else
  284. return $response['Envelope']['Body']['GetSnapshotUriResponse']['MediaUri']['Uri'];
  285. }
  286. public function ptz_GetPresets($profileToken) {
  287. if ($this->ptzuri=='') return array();
  288. $REQ=$this->_makeToken();
  289. $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>';
  290. $post_string=str_replace(array("%%USERNAME%%",
  291. "%%PASSWORD%%",
  292. "%%NONCE%%",
  293. "%%CREATED%%",
  294. "%%PROFILETOKEN%%"),
  295. array($REQ['USERNAME'],
  296. $REQ['PASSDIGEST'],
  297. $REQ['NONCE'],
  298. $REQ['TIMESTAMP'],
  299. $profileToken),
  300. $post_string);
  301. if ($this->isFault($response=$this->_send_request($this->ptzuri,$post_string))) {
  302. if ($this->intransingent) throw new Exception('GetPresets: Communication error');
  303. }
  304. else {
  305. $getpresetsresponse=$response['Envelope']['Body']['GetPresetsResponse']['Preset'];
  306. $presets=array();
  307. foreach ($getpresetsresponse as $preset) {
  308. $presets[]=array('Token'=>$preset['@attributes']['token'],
  309. 'Name'=>$preset['Name'],
  310. 'PTZPosition'=>$preset['PTZPosition']);
  311. }
  312. return $presets;
  313. }
  314. }
  315. public function ptz_GetNode($ptzNodeToken) {
  316. if ($this->ptzuri=='') return array();
  317. $REQ=$this->_makeToken();
  318. $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>';
  319. $post_string=str_replace(array("%%USERNAME%%",
  320. "%%PASSWORD%%",
  321. "%%NONCE%%",
  322. "%%CREATED%%",
  323. "%%NODETOKEN%%"),
  324. array($REQ['USERNAME'],
  325. $REQ['PASSDIGEST'],
  326. $REQ['NONCE'],
  327. $REQ['TIMESTAMP'],
  328. $ptzNodeToken),
  329. $post_string);
  330. if ($this->isFault($response=$this->_send_request($this->ptzuri,$post_string))) {
  331. if ($this->intransingent) throw new Exception('GetNode: Communication error');
  332. }
  333. else
  334. return $response['Envelope']['Body']['GetNodeResponse'];
  335. }
  336. public function ptz_GotoPreset($profileToken,$presetToken,$speed_pantilt_x,$speed_pantilt_y,$speed_zoom_x) {
  337. if ($this->ptzuri=='') return array();
  338. $REQ=$this->_makeToken();
  339. $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>';
  340. $post_string=str_replace(array("%%USERNAME%%",
  341. "%%PASSWORD%%",
  342. "%%NONCE%%",
  343. "%%CREATED%%",
  344. "%%PROFILETOKEN%%",
  345. "%%PRESETTOKEN%%",
  346. "%%SPEEDPANTILTX%%",
  347. "%%SPEEDPANTILTY%%",
  348. "%%SPEEDZOOMX%%"),
  349. array($REQ['USERNAME'],
  350. $REQ['PASSDIGEST'],
  351. $REQ['NONCE'],
  352. $REQ['TIMESTAMP'],
  353. $profileToken,
  354. $presetToken,
  355. $speed_pantilt_x,
  356. $speed_pantilt_y,
  357. $speed_zoom_x),
  358. $post_string);
  359. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  360. if ($this->intransingent) throw new Exception('GotoPreset: Communication error');
  361. }
  362. }
  363. public function ptz_RemovePreset($profileToken,$presetToken) {
  364. if ($this->ptzuri=='') return array();
  365. $REQ=$this->_makeToken();
  366. $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>';
  367. $post_string=str_replace(array("%%USERNAME%%",
  368. "%%PASSWORD%%",
  369. "%%NONCE%%",
  370. "%%CREATED%%",
  371. "%%PROFILETOKEN%%",
  372. "%%PRESETTOKEN%%"),
  373. array($REQ['USERNAME'],
  374. $REQ['PASSDIGEST'],
  375. $REQ['NONCE'],
  376. $REQ['TIMESTAMP'],
  377. $profileToken,
  378. $presetToken),
  379. $post_string);
  380. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  381. if ($this->intransingent) throw new Exception('RemovePreset: Communication error');
  382. }
  383. }
  384. public function ptz_SetPreset($profileToken,$presetName) {
  385. if ($this->ptzuri=='') return array();
  386. $REQ=$this->_makeToken();
  387. $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>';
  388. $post_string=str_replace(array("%%USERNAME%%",
  389. "%%PASSWORD%%",
  390. "%%NONCE%%",
  391. "%%CREATED%%",
  392. "%%PROFILETOKEN%%",
  393. "%%PRESETNAME%%"),
  394. array($REQ['USERNAME'],
  395. $REQ['PASSDIGEST'],
  396. $REQ['NONCE'],
  397. $REQ['TIMESTAMP'],
  398. $profileToken,
  399. $presetName),
  400. $post_string);
  401. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  402. if ($this->intransingent) throw new Exception('SetPreset: Communication error');
  403. }
  404. }
  405. public function ptz_RelativeMove($profileToken,$translation_pantilt_x,$translation_pantilt_y,$speed_pantilt_x,$speed_pantilt_y) {
  406. if ($this->ptzuri=='') return array();
  407. $REQ=$this->_makeToken();
  408. $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>';
  409. $post_string=str_replace(array("%%USERNAME%%",
  410. "%%PASSWORD%%",
  411. "%%NONCE%%",
  412. "%%CREATED%%",
  413. "%%PROFILETOKEN%%",
  414. "%%TRANSLATIONPANTILTX%%",
  415. "%%TRANSLATIONPANTILTY%%",
  416. "%%SPEEDPANTILTX%%",
  417. "%%SPEEDPANTILTY%%"),
  418. array($REQ['USERNAME'],
  419. $REQ['PASSDIGEST'],
  420. $REQ['NONCE'],
  421. $REQ['TIMESTAMP'],
  422. $profileToken,
  423. $translation_pantilt_x,
  424. $translation_pantilt_y,
  425. $speed_pantilt_x,
  426. $speed_pantilt_y),
  427. $post_string);
  428. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  429. if ($this->intransingent) throw new Exception('RelativeMove: Communication error');
  430. }
  431. }
  432. public function ptz_RelativeMoveZoom($profileToken,$zoom,$speedZoom) {
  433. if ($this->ptzuri=='') return array();
  434. $REQ=$this->_makeToken();
  435. $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>';
  436. $post_string=str_replace(array("%%USERNAME%%",
  437. "%%PASSWORD%%",
  438. "%%NONCE%%",
  439. "%%CREATED%%",
  440. "%%PROFILETOKEN%%",
  441. "%%SPEEDZOOM%%",
  442. "%%ZOOM%%"),
  443. array($REQ['USERNAME'],
  444. $REQ['PASSDIGEST'],
  445. $REQ['NONCE'],
  446. $REQ['TIMESTAMP'],
  447. $profileToken,
  448. $speedZoom,
  449. $zoom),
  450. $post_string);
  451. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  452. if ($this->intransingent) throw new Exception('RelativeMoveZoom: Communication error');
  453. }
  454. }
  455. public function ptz_AbsoluteMove($profileToken,$position_pantilt_x,$position_pantilt_y,$zoom) {
  456. if ($this->ptzuri=='') return array();
  457. $REQ=$this->_makeToken();
  458. $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></AbsoluteMove></s:Body></s:Envelope>';
  459. $post_string=str_replace(array("%%USERNAME%%",
  460. "%%PASSWORD%%",
  461. "%%NONCE%%",
  462. "%%CREATED%%",
  463. "%%PROFILETOKEN%%",
  464. "%%POSITIONPANTILTX%%",
  465. "%%POSITIONPANTILTY%%",
  466. "%%ZOOM%%"),
  467. array($REQ['USERNAME'],
  468. $REQ['PASSDIGEST'],
  469. $REQ['NONCE'],
  470. $REQ['TIMESTAMP'],
  471. $profileToken,
  472. $position_pantilt_x,
  473. $position_pantilt_y,
  474. $zoom),
  475. $post_string);
  476. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  477. if ($this->intransingent) throw new Exception('AbsoluteMove: Communication error');
  478. }
  479. }
  480. public function ptz_ContinuousMove($profileToken,$velocity_pantilt_x,$velocity_pantilt_y) {
  481. if ($this->ptzuri=='') return array();
  482. $REQ=$this->_makeToken();
  483. $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>';
  484. $post_string=str_replace(array("%%USERNAME%%",
  485. "%%PASSWORD%%",
  486. "%%NONCE%%",
  487. "%%CREATED%%",
  488. "%%PROFILETOKEN%%",
  489. "%%VELOCITYPANTILTX%%",
  490. "%%VELOCITYPANTILTY%%"),
  491. array($REQ['USERNAME'],
  492. $REQ['PASSDIGEST'],
  493. $REQ['NONCE'],
  494. $REQ['TIMESTAMP'],
  495. $profileToken,
  496. $velocity_pantilt_x,
  497. $velocity_pantilt_y),
  498. $post_string);
  499. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  500. if ($this->intransingent) throw new Exception('ContinuousMove: Communication error');
  501. }
  502. }
  503. public function ptz_ContinuousMoveZoom($profileToken,$zoom) {
  504. if ($this->ptzuri=='') return array();
  505. $REQ=$this->_makeToken();
  506. $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>';
  507. $post_string=str_replace(array("%%USERNAME%%",
  508. "%%PASSWORD%%",
  509. "%%NONCE%%",
  510. "%%CREATED%%",
  511. "%%PROFILETOKEN%%",
  512. "%%ZOOM%%"),
  513. array($REQ['USERNAME'],
  514. $REQ['PASSDIGEST'],
  515. $REQ['NONCE'],
  516. $REQ['TIMESTAMP'],
  517. $profileToken,
  518. $zoom),
  519. $post_string);
  520. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  521. if ($this->intransingent) throw new Exception('ContinuousMoveZoom: Communication error');
  522. }
  523. }
  524. public function ptz_Stop($profileToken,$pantilt,$zoom) {
  525. if ($this->ptzuri=='') return array();
  526. $REQ=$this->_makeToken();
  527. $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>';
  528. $post_string=str_replace(array("%%USERNAME%%",
  529. "%%PASSWORD%%",
  530. "%%NONCE%%",
  531. "%%CREATED%%",
  532. "%%PROFILETOKEN%%",
  533. "%%PANTILT%%",
  534. "%%ZOOM%%"),
  535. array($REQ['USERNAME'],
  536. $REQ['PASSDIGEST'],
  537. $REQ['NONCE'],
  538. $REQ['TIMESTAMP'],
  539. $profileToken,
  540. $pantilt,
  541. $zoom),
  542. $post_string);
  543. if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) {
  544. if ($this->intransingent) throw new Exception('Stop: Communication error');
  545. }
  546. }
  547. /*
  548. Internal functions
  549. */
  550. protected function _makeToken() {
  551. $timestamp=time()-$this->deltatime;
  552. return $this->_passwordDigest($this->username,$this->password,date('Y-m-d\TH:i:s.000\Z',$timestamp));
  553. }
  554. protected function _getOnvifVersion($capabilities) {
  555. $version=array();
  556. if (isset($capabilities['Device']['System']['SupportedVersions']['Major'])) {
  557. // NVT supports a specific onvif version
  558. $version['major']=$capabilities['Device']['System']['SupportedVersions']['Major'];
  559. $version['minor']=$capabilities['Device']['System']['SupportedVersions']['Minor'];
  560. } else {
  561. // NVT supports more onvif versions
  562. $currentma=0;
  563. $currentmi=0;
  564. foreach ($capabilities['Device']['System']['SupportedVersions'] as $cver) {
  565. if ($cver['Major']>$currentma) { $currentma=$cver['Major'];$currentmi=$cver['Minor']; }
  566. }
  567. $version['major']=$currentma;
  568. $version['minor']=$currentmi;
  569. }
  570. $version['media']=$capabilities['Media']['XAddr'];
  571. $version['device']=$capabilities['Device']['XAddr'];
  572. $version['event']=$capabilities['Events']['XAddr'];
  573. if (isset($capabilities['PTZ']['XAddr'])) $version['ptz']=$capabilities['PTZ']['XAddr']; else $version['ptz']='';
  574. return $version;
  575. }
  576. protected function _getActiveSources($videoSources,$profiles) {
  577. $sources=array();
  578. if (isset($videoSources['@attributes'])) {
  579. // NVT is a camera
  580. $sources[0]['sourcetoken']=$videoSources['@attributes']['token'];
  581. $this->_getProfileData($sources,0,$profiles);
  582. }
  583. else {
  584. // NVT is an encoder
  585. for ($i=0;$i<count($videoSources);$i++) {
  586. if (strtolower($videoSources[$i]['@attributes']['SignalActive'])=='true') {
  587. $sources[$i]['sourcetoken']=$videoSources[$i]['@attributes']['token'];
  588. $this->_getProfileData($sources,$i,$profiles);
  589. }
  590. } // for
  591. }
  592. return $sources;
  593. }
  594. protected function _getProfileData(&$sources,$i,$profiles) {
  595. $inprofile=0;
  596. for ($y=0; $y < count($profiles); $y++) {
  597. if ($profiles[$y]['VideoSourceConfiguration']['SourceToken']==$sources[$i]['sourcetoken']) {
  598. $sources[$i][$inprofile]['profilename']=$profiles[$y]['Name'];
  599. $sources[$i][$inprofile]['profiletoken']=$profiles[$y]['@attributes']['token'];
  600. if ( isset($profiles[$y]['VideoEncoderConfiguration'])) {
  601. $sources[$i][$inprofile]['encoding']=$profiles[$y]['VideoEncoderConfiguration']['Encoding'];
  602. $sources[$i][$inprofile]['width']=$profiles[$y]['VideoEncoderConfiguration']['Resolution']['Width'];
  603. $sources[$i][$inprofile]['height']=$profiles[$y]['VideoEncoderConfiguration']['Resolution']['Height'];
  604. $sources[$i][$inprofile]['fps']=$profiles[$y]['VideoEncoderConfiguration']['RateControl']['FrameRateLimit'];
  605. $sources[$i][$inprofile]['bitrate']=$profiles[$y]['VideoEncoderConfiguration']['RateControl']['BitrateLimit'];
  606. }
  607. if ( isset($profiles[$y]['PTZConfiguration'])) {
  608. $sources[$i][$inprofile]['ptz']['name']=$profiles[$y]['PTZConfiguration']['Name'];
  609. $sources[$i][$inprofile]['ptz']['nodetoken']=$profiles[$y]['PTZConfiguration']['NodeToken'];
  610. }
  611. $inprofile++;
  612. }
  613. }
  614. }
  615. protected function _xml2array($response) {
  616. $sxe = new SimpleXMLElement($response);
  617. $dom_sxe = dom_import_simplexml($sxe);
  618. $dom = new DOMDocument('1.0');
  619. $dom_sxe = $dom->importNode($dom_sxe, true);
  620. $dom_sxe = $dom->appendChild($dom_sxe);
  621. $element = $dom->childNodes->item(0);
  622. foreach ($sxe->getDocNamespaces() as $name => $uri) {
  623. $element->removeAttributeNS($uri, $name);
  624. }
  625. $xmldata=$dom->saveXML();
  626. $xmldata=substr($xmldata,strpos($xmldata,"<Envelope>"));
  627. $xmldata=substr($xmldata,0,strpos($xmldata,"</Envelope>")+strlen("</Envelope>"));
  628. $xml=simplexml_load_string($xmldata);
  629. $data=json_decode(json_encode((array)$xml),1);
  630. $data=array($xml->getName()=>$data);
  631. return $data;
  632. }
  633. protected function _passwordDigest( $username, $password, $timestamp = "default", $nonce = "default" ) {
  634. if ($timestamp=='default') $timestamp=date('Y-m-d\TH:i:s.000\Z');
  635. if ($nonce=='default') $nonce=mt_rand();
  636. $REQ=array();
  637. $passdigest = base64_encode(pack('H*', sha1(pack('H*', $nonce) . pack('a*',$timestamp).pack('a*',$password))));
  638. //$passdigest=base64_encode(sha1($nonce.$timestamp.$password,true)); // alternative
  639. $REQ['USERNAME']=$username;
  640. $REQ['PASSDIGEST']=$passdigest;
  641. $REQ['NONCE']=base64_encode(pack('H*', $nonce));
  642. //$REQ['NONCE']=base64_encode($nonce); // alternative
  643. $REQ['TIMESTAMP']=$timestamp;
  644. return $REQ;
  645. }
  646. protected function _send_request($url,$post_string) {
  647. $soap_do = curl_init();
  648. curl_setopt($soap_do, CURLOPT_URL, $url );
  649. if ($this->proxyhost!='' && $this->proxyport!='') {
  650. curl_setopt($soap_do, CURLOPT_PROXY, $this->proxyhost);
  651. curl_setopt($soap_do, CURLOPT_PROXYPORT, $this->proxyport);
  652. if ($this->proxyusername!='' && $this->proxypassword!='')
  653. curl_setopt($soap_do, CURLOPT_PROXYUSERPWD, $this->proxyusername.':'.$this->proxypassword);
  654. }
  655. curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
  656. curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
  657. curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
  658. curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
  659. curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
  660. curl_setopt($soap_do, CURLOPT_POST, true );
  661. curl_setopt($soap_do, CURLOPT_POSTFIELDS, $post_string);
  662. curl_setopt($soap_do, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($post_string) ));
  663. //curl_setopt($soap_do, CURLOPT_USERPWD, $user . ":" . $password); // HTTP authentication
  664. if ( ($result = curl_exec($soap_do)) === false) {
  665. $err = curl_error($soap_do);
  666. $this->lastresponse=array("Fault"=>$err);
  667. } else {
  668. $this->lastresponse=$this->_xml2array($result);
  669. }
  670. return $this->lastresponse;
  671. }
  672. } // end class
  673. ?>