Advertisement
Guest User

Untitled

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