Web UI for ARGUS server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

755 lines
50 KiB

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