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

662 lines
44 KiB

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