proxyhost = $proxyHost; } public function getProxyHost() { return $this->proxyhost; } public function setProxyPort($proxyPort) { $this->proxyport = $proxyPort; } public function getProxyPort() { return $this->proxyport; } public function setProxyUsername($proxyUsername) { $this->proxyusername = $proxyUsername; } public function getProxyUsername() { return $this->proxyusername; } public function setProxyPassword($proxyPassword) { $this->proxypassword = $proxyPassword; } public function getProxyPassword() { return $this->proxypassword; } public function setUsername($username) { $this->username = $username; } public function getUsername() { return $this->username; } public function setPassword($password) { $this->password = $password; } public function getPassword() { return $this->password; } public function getDeviceUri() { return $this->mediauri; } public function setDeviceUri($deviceUri) { $this->mediauri=$deviceUrl; } public function getIPAddress($ipAddress) { return $this->ipAddress; } public function setIPAddress($ipAddress) { $this->ipaddress=$ipAddress; } public function getSources() { return $this->sources; } public function getMediaUri() { return $this->mediauri; } public function getPTZUri() { return $this->ptzuri; } public function getBaseUrl() { return $this->baseuri; } public function getSupportedVersion() { return $this->onvifversion; } public function getCapabilities() { return $this->capabilities; } public function setBreakOnError($intransingent) { $this->intransingent=$intransingent; } public function getLastResponse() { return $this->lastresponse; } public function setDiscoveryTimeout($discoverytimeout) { $this->discoverytimeout = $discoverytimeout; } public function setDiscoveryBindIp($discoverybindip) { $this->discoverybindip = $discoverybindip; } public function setDiscoveryMcastIp($discoverymcastip) { $this->discoverymcastip = $discoverymcastip; } public function setDiscoveryMcastPort($discoverymcastport) { $this->discoverymcastport = $discoverymcastport; } public function setDiscoveryHideDuplicates($discoveryhideduplicates) { $this->discoveryhideduplicates = $discoveryhideduplicates; } public function getSnapshotUri() { return $this->snapshoturi; } public function setDigestMethod( $DM ){ $this->digestMethod = $DM; } public function getDigestMethod(){ return $this->digestMethod; } /* Constructor & Destructor */ public function __construct() { // nothing to do } public function __destruct() { // nothing to do } /* WS-Discovery */ public function discover(){ $result = array(); $timeout = time() + $this->discoverytimeout; $post_string = 'uuid:84ede3de-7dec-11d0-c360-f01234567890urn:schemas-xmlsoap-org:ws:2005:04:discoveryhttp://schemas.xmlsoap.org/ws/2005/04/discovery/Probedn:NetworkVideoTransmitter'; try { if(FALSE == ($sock = @socket_create(AF_INET, SOCK_DGRAM, SOL_UDP))){ echo('Create socket error: ['.socket_last_error().'] '.socket_strerror(socket_last_error())); } //if(FALSE == @socket_bind($sock, $this->discoverybindip, rand(20000, 40000))){ // echo('Bind socket error: ['.socket_last_error().'] '.socket_strerror(socket_last_error())); //} //socket_set_option($sock, IPPROTO_IP, MCAST_JOIN_GROUP, array('group' => $this->discoverymcastip)); socket_sendto($sock, $post_string, strlen($post_string), 0, $this->discoverymcastip, $this->discoverymcastport); socket_set_nonblock($sock); while(time() < $timeout){ if( FALSE !== @socket_recvfrom($sock, $response, 9999, 0, $from, $this->discoverymcastport)){ if( $response != NULL && $response != $post_string ){ $response = $this->_xml2array($response); if(!$this->isFault($response)){ $response['Envelope']['Body']['ProbeMatches']['ProbeMatch']['IPAddr'] = $from; if($this->discoveryhideduplicates){ $result[$from] = $response['Envelope']['Body']['ProbeMatches']['ProbeMatch']; }else{ $result[] = $response['Envelope']['Body']['ProbeMatches']['ProbeMatch']; } } } } } socket_close($sock); } catch (Exception $e) {} sort($result); return $result; } /* Public functions (basic initialization method and other collaterals) */ public function initialize() { $this->mediauri='http://'.$this->ipaddress.'/onvif/device_service'; try { $datetime=$this->core_GetSystemDateAndTime(); $timestamp=mktime($datetime['Time']['Hour'], $datetime['Time']['Minute'], $datetime['Time']['Second'], $datetime['Date']['Month'], $datetime['Date']['Day'], $datetime['Date']['Year']); $this->deltatime = time()-$timestamp;//-5; } catch( Exception $e ) { } $this->capabilities=$this->core_GetCapabilities(); echo "\n\n\n\nGet Cap\n\n\n"; $onvifVersion=$this->_getOnvifVersion($this->capabilities); $this->mediauri=$onvifVersion['media']; $this->deviceuri=$onvifVersion['device']; $this->ptzuri=$onvifVersion['ptz']; preg_match("/^http(.*)onvif\//",$this->mediauri,$matches); $this->baseuri=$matches[0]; $this->onvifversion=array('major'=>$onvifVersion['major'],'minor'=>$onvifVersion['minor']); $this->videosources=$this->media_GetVideoSources(); $this->profiles=$this->media_GetProfiles(); $this->sources=$this->_getActiveSources($this->videosources,$this->profiles); } public function isFault($response) { // Useful to check if response contains a fault if( is_array( $response ) ){ if( array_key_exists('Fault', $response ) ) return true; if( array_key_exists('Envelope', $response ) ) if( is_array( $response['Envelope'] ) ) if( array_key_exists('Body', $response['Envelope'] ) ) if( is_array( $response['Envelope']['Body'] ) ) if( array_key_exists('Fault', $response['Envelope']['Body'] ) ) return true; }; return false; } /* Public wrappers for a subset of ONVIF primitives */ public function core_GetSystemDateAndTime() { $post_string=''; if( $this->isFault($response=$this->_send_request($this->mediauri,$post_string)) ){ if ($this->intransingent) throw new Exception('GetSystemDateAndTime: Communication error'); } else { return $response['Envelope']['Body']['GetSystemDateAndTimeResponse']['SystemDateAndTime']['UTCDateTime']; } } public function core_GetCapabilities() { $REQ=$this->_makeToken(); $post_string='%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%All'; $post_string=str_replace(array("%%USERNAME%%", "%%PASSWORD%%", "%%NONCE%%", "%%CREATED%%"), array($REQ['USERNAME'], $REQ['PASSDIGEST'], $REQ['NONCE'], $REQ['TIMESTAMP']), $post_string); if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) { if ($this->intransingent) throw new Exception('GetCapabilities: Communication error'); } else return $response['Envelope']['Body']['GetCapabilitiesResponse']['Capabilities']; } public function media_GetVideoSources() { $REQ=$this->_makeToken(); $post_string='%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%'; $post_string=str_replace(array("%%USERNAME%%", "%%PASSWORD%%", "%%NONCE%%", "%%CREATED%%"), array($REQ['USERNAME'], $REQ['PASSDIGEST'], $REQ['NONCE'], $REQ['TIMESTAMP']), $post_string); //echo "POST STRING:" . $post_string . "\n\n"; if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) { if ($this->intransingent) throw new Exception('GetVideoSources: Communication error'); } else // var_dump( $response ); return $response['Envelope']['Body']['GetVideoSourcesResponse']['VideoSources']; } public function media_GetProfiles() { $REQ=$this->_makeToken(); $post_string='%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%'; $post_string=str_replace(array("%%USERNAME%%", "%%PASSWORD%%", "%%NONCE%%", "%%CREATED%%"), array($REQ['USERNAME'], $REQ['PASSDIGEST'], $REQ['NONCE'], $REQ['TIMESTAMP']), $post_string); if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) { if ($this->intransingent) throw new Exception('GetProfiles: Communication error'); } else return $response['Envelope']['Body']['GetProfilesResponse']['Profiles']; } public function media_GetServices() { $REQ=$this->_makeToken(); $post_string='%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%false'; $post_string=str_replace(array("%%USERNAME%%", "%%PASSWORD%%", "%%NONCE%%", "%%CREATED%%"), array($REQ['USERNAME'], $REQ['PASSDIGEST'], $REQ['NONCE'], $REQ['TIMESTAMP']), $post_string); if ($this->isFault($this->_send_request($this->mediauri,$post_string))) { if ($this->intransingent) throw new Exception('GetServices: Communication error'); } } public function core_GetDeviceInformation() { $REQ=$this->_makeToken(); $post_string='%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%'; $post_string=str_replace(array("%%USERNAME%%", "%%PASSWORD%%", "%%NONCE%%", "%%CREATED%%"), array($REQ['USERNAME'], $REQ['PASSDIGEST'], $REQ['NONCE'], $REQ['TIMESTAMP']), $post_string); if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) { if ($this->intransingent) throw new Exception('GetDeviceInformation: Communication error'); } else return $response['Envelope']['Body']['GetDeviceInformationResponse']; } public function media_GetStreamUri($profileToken,$stream="RTP-Unicast",$protocol="RTSP") { $REQ=$this->_makeToken(); $post_string='%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%%%STREAM%%%%PROTOCOL%%%%PROFILETOKEN%%'; $post_string=str_replace( array("%%USERNAME%%", "%%PASSWORD%%", "%%NONCE%%", "%%CREATED%%", "%%PROFILETOKEN%%", "%%STREAM%%", "%%PROTOCOL%%"), array($REQ['USERNAME'], $REQ['PASSDIGEST'], $REQ['NONCE'], $REQ['TIMESTAMP'], $profileToken, $stream, $protocol), $post_string ); if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) { if ($this->intransingent) throw new Exception('GetStreamUri: Communication error'); } else return $response['Envelope']['Body']['GetStreamUriResponse']['MediaUri']['Uri']; } public function media_GetSnapshotUri($profileToken) { $REQ=$this->_makeToken(); $post_string='%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%%%PROFILETOKEN%%'; $post_string=str_replace(array("%%USERNAME%%", "%%PASSWORD%%", "%%NONCE%%", "%%CREATED%%", "%%PROFILETOKEN%%"), array($REQ['USERNAME'], $REQ['PASSDIGEST'], $REQ['NONCE'], $REQ['TIMESTAMP'], $profileToken), $post_string); if ($this->isFault($response=$this->_send_request($this->mediauri,$post_string))) { if ($this->intransingent) throw new Exception('GetSnapshotUri: Communication error'); var_dump($response); } else return $response['Envelope']['Body']['GetSnapshotUriResponse']['MediaUri']['Uri']; } public function ptz_GetPresets($profileToken) { if ($this->ptzuri=='') return array(); $REQ=$this->_makeToken(); $post_string='%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%%%PROFILETOKEN%%'; $post_string=str_replace(array("%%USERNAME%%", "%%PASSWORD%%", "%%NONCE%%", "%%CREATED%%", "%%PROFILETOKEN%%"), array($REQ['USERNAME'], $REQ['PASSDIGEST'], $REQ['NONCE'], $REQ['TIMESTAMP'], $profileToken), $post_string); if ($this->isFault($response=$this->_send_request($this->ptzuri,$post_string))) { if ($this->intransingent) throw new Exception('GetPresets: Communication error'); } else { $getpresetsresponse=$response['Envelope']['Body']['GetPresetsResponse']['Preset']; $presets=array(); foreach ($getpresetsresponse as $preset) { $presets[]=array('Token'=>$preset['@attributes']['token'], 'Name'=>$preset['Name'], 'PTZPosition'=>$preset['PTZPosition']); } return $presets; } } public function ptz_GetNode($ptzNodeToken) { if ($this->ptzuri=='') return array(); $REQ=$this->_makeToken(); $post_string='%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%%%NODETOKEN%%'; $post_string=str_replace(array("%%USERNAME%%", "%%PASSWORD%%", "%%NONCE%%", "%%CREATED%%", "%%NODETOKEN%%"), array($REQ['USERNAME'], $REQ['PASSDIGEST'], $REQ['NONCE'], $REQ['TIMESTAMP'], $ptzNodeToken), $post_string); if ($this->isFault($response=$this->_send_request($this->ptzuri,$post_string))) { if ($this->intransingent) throw new Exception('GetNode: Communication error'); } else return $response['Envelope']['Body']['GetNodeResponse']; } public function ptz_GotoPreset($profileToken,$presetToken,$speed_pantilt_x,$speed_pantilt_y,$speed_zoom_x) { if ($this->ptzuri=='') return array(); $REQ=$this->_makeToken(); $post_string='%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%%%PROFILETOKEN%%%%PRESETTOKEN%%'; $post_string=str_replace(array("%%USERNAME%%", "%%PASSWORD%%", "%%NONCE%%", "%%CREATED%%", "%%PROFILETOKEN%%", "%%PRESETTOKEN%%", "%%SPEEDPANTILTX%%", "%%SPEEDPANTILTY%%", "%%SPEEDZOOMX%%"), array($REQ['USERNAME'], $REQ['PASSDIGEST'], $REQ['NONCE'], $REQ['TIMESTAMP'], $profileToken, $presetToken, $speed_pantilt_x, $speed_pantilt_y, $speed_zoom_x), $post_string); if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) { if ($this->intransingent) throw new Exception('GotoPreset: Communication error'); } } public function ptz_RemovePreset($profileToken,$presetToken) { if ($this->ptzuri=='') return array(); $REQ=$this->_makeToken(); $post_string='%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%%%PROFILETOKEN%%%%PRESETTOKEN%%'; $post_string=str_replace(array("%%USERNAME%%", "%%PASSWORD%%", "%%NONCE%%", "%%CREATED%%", "%%PROFILETOKEN%%", "%%PRESETTOKEN%%"), array($REQ['USERNAME'], $REQ['PASSDIGEST'], $REQ['NONCE'], $REQ['TIMESTAMP'], $profileToken, $presetToken), $post_string); if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) { if ($this->intransingent) throw new Exception('RemovePreset: Communication error'); } } public function ptz_SetPreset($profileToken,$presetName) { if ($this->ptzuri=='') return array(); $REQ=$this->_makeToken(); $post_string='%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%%%PROFILETOKEN%%%%PRESETNAME%%'; $post_string=str_replace(array("%%USERNAME%%", "%%PASSWORD%%", "%%NONCE%%", "%%CREATED%%", "%%PROFILETOKEN%%", "%%PRESETNAME%%"), array($REQ['USERNAME'], $REQ['PASSDIGEST'], $REQ['NONCE'], $REQ['TIMESTAMP'], $profileToken, $presetName), $post_string); if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) { if ($this->intransingent) throw new Exception('SetPreset: Communication error'); } } public function ptz_RelativeMove($profileToken,$translation_pantilt_x,$translation_pantilt_y,$speed_pantilt_x,$speed_pantilt_y) { if ($this->ptzuri=='') return array(); $REQ=$this->_makeToken(); $post_string='%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%%%PROFILETOKEN%%'; $post_string=str_replace(array("%%USERNAME%%", "%%PASSWORD%%", "%%NONCE%%", "%%CREATED%%", "%%PROFILETOKEN%%", "%%TRANSLATIONPANTILTX%%", "%%TRANSLATIONPANTILTY%%", "%%SPEEDPANTILTX%%", "%%SPEEDPANTILTY%%"), array($REQ['USERNAME'], $REQ['PASSDIGEST'], $REQ['NONCE'], $REQ['TIMESTAMP'], $profileToken, $translation_pantilt_x, $translation_pantilt_y, $speed_pantilt_x, $speed_pantilt_y), $post_string); if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) { if ($this->intransingent) throw new Exception('RelativeMove: Communication error'); } } public function ptz_RelativeMoveZoom($profileToken,$zoom,$speedZoom) { if ($this->ptzuri=='') return array(); $REQ=$this->_makeToken(); $post_string='%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%%%PROFILETOKEN%%'; $post_string=str_replace(array("%%USERNAME%%", "%%PASSWORD%%", "%%NONCE%%", "%%CREATED%%", "%%PROFILETOKEN%%", "%%SPEEDZOOM%%", "%%ZOOM%%"), array($REQ['USERNAME'], $REQ['PASSDIGEST'], $REQ['NONCE'], $REQ['TIMESTAMP'], $profileToken, $speedZoom, $zoom), $post_string); if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) { if ($this->intransingent) throw new Exception('RelativeMoveZoom: Communication error'); } } public function ptz_GetStatus( $profileToken ){ $REQ=$this->_makeToken(); $post_string='%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%%%PROFILETOKEN%%'; $post_string=str_replace(array("%%USERNAME%%", "%%PASSWORD%%", "%%NONCE%%", "%%CREATED%%", "%%PROFILETOKEN%%"), array($REQ['USERNAME'], $REQ['PASSDIGEST'], $REQ['NONCE'], $REQ['TIMESTAMP'], $profileToken), $post_string); if ($this->isFault($response = $this->_send_request($this->ptzuri,$post_string))) { if ($this->intransingent) throw new Exception('ptz Get Status: Communication error'); } else { var_dump( $response ); $cpos=$response['Envelope']['Body']['GetStatusResponse']['PTZStatus']['Position']; return $cpos; }; } public function ptz_AbsoluteMove($profileToken,$position_pantilt_x,$position_pantilt_y,$zoom, $PSpeed=1.0, $TSpeed=1.0, $ZSpeed=1.0 ) { if ($this->ptzuri=='') return array(); $REQ=$this->_makeToken(); $post_string='%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%%%PROFILETOKEN%%'; $post_string=str_replace(array("%%USERNAME%%", "%%PASSWORD%%", "%%NONCE%%", "%%CREATED%%", "%%PROFILETOKEN%%", "%%POSITIONPANTILTX%%", "%%POSITIONPANTILTY%%", "%%ZOOM%%", "%%SPEEDPANTILTX%%", "%%SPEEDPANTILTY%%", "%%SPEEDZOOMX%%"), array($REQ['USERNAME'], $REQ['PASSDIGEST'], $REQ['NONCE'], $REQ['TIMESTAMP'], $profileToken, $position_pantilt_x, $position_pantilt_y, $zoom, $PSpeed, $TSpeed, $ZSpeed), $post_string); if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) { if ($this->intransingent) throw new Exception('AbsoluteMove: Communication error'); } } public function ptz_ContinuousMove($profileToken,$velocity_pantilt_x,$velocity_pantilt_y) { if ($this->ptzuri=='') return array(); $REQ=$this->_makeToken(); $post_string='%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%%%PROFILETOKEN%%'; $post_string=str_replace(array("%%USERNAME%%", "%%PASSWORD%%", "%%NONCE%%", "%%CREATED%%", "%%PROFILETOKEN%%", "%%VELOCITYPANTILTX%%", "%%VELOCITYPANTILTY%%"), array($REQ['USERNAME'], $REQ['PASSDIGEST'], $REQ['NONCE'], $REQ['TIMESTAMP'], $profileToken, $velocity_pantilt_x, $velocity_pantilt_y), $post_string); if ( $this->isFault($this->_send_request($this->ptzuri,$post_string))) { if( $this->intransingent ) throw new Exception('ContinuousMove: Communication error'); } } public function ptz_ContinuousMoveZoom($profileToken,$zoom) { if ($this->ptzuri=='') return array(); $REQ=$this->_makeToken(); $post_string='%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%%%PROFILETOKEN%%'; $post_string=str_replace(array("%%USERNAME%%", "%%PASSWORD%%", "%%NONCE%%", "%%CREATED%%", "%%PROFILETOKEN%%", "%%ZOOM%%"), array($REQ['USERNAME'], $REQ['PASSDIGEST'], $REQ['NONCE'], $REQ['TIMESTAMP'], $profileToken, $zoom), $post_string); if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) { if ($this->intransingent) throw new Exception('ContinuousMoveZoom: Communication error'); } } public function ptz_Stop($profileToken,$pantilt,$zoom) { if ($this->ptzuri=='') return array(); $REQ=$this->_makeToken(); $post_string='%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%%%PROFILETOKEN%%%%PANTILT%%%%ZOOM%%'; $post_string=str_replace(array("%%USERNAME%%", "%%PASSWORD%%", "%%NONCE%%", "%%CREATED%%", "%%PROFILETOKEN%%", "%%PANTILT%%", "%%ZOOM%%"), array($REQ['USERNAME'], $REQ['PASSDIGEST'], $REQ['NONCE'], $REQ['TIMESTAMP'], $profileToken, $pantilt, $zoom), $post_string); if ($this->isFault($this->_send_request($this->ptzuri,$post_string))) { if ($this->intransingent) throw new Exception('Stop: Communication error'); } } /* Internal functions */ protected function _makeToken() { $timestamp=time()-$this->deltatime; return $this->_passwordDigest($this->username,$this->password,date('Y-m-d\TH:i:s.000\Z',$timestamp)); } protected function _getOnvifVersion($capabilities) { $version=array(); if (isset($capabilities['Device']['System']['SupportedVersions']['Major'])) { // NVT supports a specific onvif version $version['major']=$capabilities['Device']['System']['SupportedVersions']['Major']; $version['minor']=$capabilities['Device']['System']['SupportedVersions']['Minor']; } else { // NVT supports more onvif versions $currentma=0; $currentmi=0; foreach ($capabilities['Device']['System']['SupportedVersions'] as $cver) { if ($cver['Major']>$currentma) { $currentma=$cver['Major'];$currentmi=$cver['Minor']; } } $version['major']=$currentma; $version['minor']=$currentmi; } $version['media']=$capabilities['Media']['XAddr']; $version['device']=$capabilities['Device']['XAddr']; $version['event']=$capabilities['Events']['XAddr']; if (isset($capabilities['PTZ']['XAddr'])) $version['ptz']=$capabilities['PTZ']['XAddr']; else $version['ptz']=''; return $version; } protected function _getActiveSources($videoSources,$profiles) { $sources=array(); if (isset($videoSources['@attributes'])) { // NVT is a camera $sources[0]['sourcetoken']=$videoSources['@attributes']['token']; $this->_getProfileData($sources,0,$profiles); } else { // NVT is an encoder for ($i=0;$i_getProfileData($sources,$i,$profiles); } } // for } return $sources; } protected function _getProfileData(&$sources,$i,$profiles) { $inprofile=0; for ($y=0; $y < count($profiles); $y++) { if ($profiles[$y]['VideoSourceConfiguration']['SourceToken']==$sources[$i]['sourcetoken']) { $sources[$i][$inprofile]['profilename']=$profiles[$y]['Name']; $sources[$i][$inprofile]['profiletoken']=$profiles[$y]['@attributes']['token']; if ( isset($profiles[$y]['VideoEncoderConfiguration'])) { $sources[$i][$inprofile]['encoding']=$profiles[$y]['VideoEncoderConfiguration']['Encoding']; $sources[$i][$inprofile]['width']=$profiles[$y]['VideoEncoderConfiguration']['Resolution']['Width']; $sources[$i][$inprofile]['height']=$profiles[$y]['VideoEncoderConfiguration']['Resolution']['Height']; $sources[$i][$inprofile]['fps']=$profiles[$y]['VideoEncoderConfiguration']['RateControl']['FrameRateLimit']; $sources[$i][$inprofile]['bitrate']=$profiles[$y]['VideoEncoderConfiguration']['RateControl']['BitrateLimit']; } if ( isset($profiles[$y]['PTZConfiguration'])) { $sources[$i][$inprofile]['ptz']['name']=$profiles[$y]['PTZConfiguration']['Name']; $sources[$i][$inprofile]['ptz']['nodetoken']=$profiles[$y]['PTZConfiguration']['NodeToken']; } $inprofile++; } } } protected function _xml2array($response) { $sxe = new SimpleXMLElement($response); $dom_sxe = dom_import_simplexml($sxe); $dom = new DOMDocument('1.0'); $dom_sxe = $dom->importNode($dom_sxe, true); $dom_sxe = $dom->appendChild($dom_sxe); $element = $dom->childNodes->item(0); foreach ($sxe->getDocNamespaces() as $name => $uri) { $element->removeAttributeNS($uri, $name); } $xmldata=$dom->saveXML(); $xmldata=substr($xmldata,strpos($xmldata,"")); $xmldata=substr($xmldata,0,strpos($xmldata,"")+strlen("")); $xml=simplexml_load_string($xmldata); $data=json_decode(json_encode((array)$xml),1); $data=array($xml->getName()=>$data); return $data; } protected function _passwordDigest( $username, $password, $timestamp = "default", $nonce = "default", $realm='', $cnonce='' ) { if ($timestamp=='default') $timestamp=date('Y-m-d\TH:i:s.000\Z'); if ($nonce=='default') $nonce=mt_rand(); $REQ=array(); switch( $this->digestMethod ){ case 'SHA-256': $H1 = pack('H*', sha1(pack('H*', $nonce) . pack('a*',$timestamp) . pack('a*',$password))); break; case 'SHA-256-sess': case 'SHA-512-256': case 'SHA-512-256-sess': case 'MD5': $H1 = pack('H*', md5( pack('a*', $username) . pack('a*', $realm) . pack('a*', $password) ) ); //$H2 = break; case 'MD5-sess': $H1 = pack('H*', md5( pack('H*', md5( pack('a*', $username) . pack('a*', $realm) . pack('a*', $password) ) ) . pack('H*', $nonce).pack('H*', $cnonce ) ) ); break; default: $passdigest=base64_encode(sha1($nonce.$timestamp.$password,true)); // alternative }; $REQ['USERNAME']=$username; $REQ['PASSDIGEST']=base64_encode( $H1 );//$passdigest ); $REQ['NONCE']=base64_encode(pack('H*', $nonce)); //$REQ['NONCE']=base64_encode($nonce); // alternative //$REQ['NONCE']=base64_encode(pack('H*', $nonce)); $REQ['TIMESTAMP']=$timestamp; return $REQ; } protected function _send_request($url,$post_string) { $soap_do = curl_init(); curl_setopt($soap_do, CURLOPT_URL, $url ); if ($this->proxyhost!='' && $this->proxyport!='') { curl_setopt($soap_do, CURLOPT_PROXY, $this->proxyhost); curl_setopt($soap_do, CURLOPT_PROXYPORT, $this->proxyport); if ($this->proxyusername!='' && $this->proxypassword!='') curl_setopt($soap_do, CURLOPT_PROXYUSERPWD, $this->proxyusername.':'.$this->proxypassword); } curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 2 ); curl_setopt($soap_do, CURLOPT_TIMEOUT, 2 ); curl_setopt($soap_do, CURLOPT_HEADER, true ); curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true ); curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false); //curl_setopt($soap_do, CURLOPT_VERBOSE, true); //curl_setopt($soap_do, CURLOPT_DEBUG, true); curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($soap_do, CURLOPT_POST, true ); curl_setopt($soap_do, CURLOPT_POSTFIELDS, $post_string); curl_setopt($soap_do, CURLOPT_HTTPHEADER, array('Expect:', 'Content-Type: application/soap+xml; charset=utf-8', 'Content-Length: '.strlen($post_string) )); curl_setopt($soap_do, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); curl_setopt($soap_do, CURLOPT_USERPWD, $this->username . ":" . $this->password ); // HTTP authentication if ( ($result = curl_exec($soap_do)) === false) { $err = curl_error($soap_do); $this->lastresponse=array("Fault"=>$err); } else { $headerSize = curl_getinfo( $soap_do, CURLINFO_HEADER_SIZE ); $headerStr = substr( $result , 0 , $headerSize ); $bodyStr = substr( $result , $headerSize ); echo "QU: {$url}\n"; echo "\n------------------\n"; var_dump( $post_string ); echo "\n~~~~~~~~~~~~~~~~~~\n"; var_dump( $headerStr ); echo "\n~~~~~~~~~~~~~~~~~~\n"; var_dump( $bodyStr ); echo "\n~~~~~~~~~~~~~~~~~~\n"; $headersTmpArray = explode( "\r\n" , $headerStr ); $R_CONT = 'text/html'; $R_CODE = 0; foreach( $headersTmpArray as $H ){ $CL = trim( $H ); if( $CL!= '' ){ $SS = explode( ' ', $CL ); $Biba = explode( ':', $CL ); if( $SS[0] == 'HTTP/1.1' ){ $R_CODE = intval( $SS[1] ); $R_REASON = $SS[2]; } else { switch( $Biba[0] ){ case 'WWW-Authenticate':{ $AA = str_ireplace( ',','', trim( $Biba[1] )); $AA = str_ireplace( '"','', $AA ); $BB = explode( ' ', $AA ); if( $BB[0] == 'Digest' ){ $this->useDigest = true; foreach( $BB as $B ){ $PO = explode( '=', $B ); switch( $PO[0] ){ case 'qop': $this->qop=$PO[1]; break; case 'realm': $this->auth_realm=$PO[1]; break; case 'algorithm': $this->digestMethod=$PO[1]; break; case 'nonce':{ $this->auth_nonce = substr( $B, 6 );//base64_decode( substr( $B, 6 ) ); break; }; }; }; }; break; }; case 'Authentication-Info':{ break; }; case 'Content-Type':{ $R_CONT = str_ireplace( ';', '', $SS[1] ); }; }; }; }; }; if( $R_CODE == 200 ){ if( $R_CONT != 'text/html' ){ $this->lastresponse=$this->_xml2array( $bodyStr ); } else { $this->lastresponse=array("Fault"=>"Content is TEXT/HTML!"); }; } else { $err = 'Code: '.$R_CODE.' '.$R_REASON; $this->lastresponse=array("Fault"=>$err); }; }; return $this->lastresponse; } } // end class ?>