Advertisement
Guest User

Untitled

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