serviceContainer = $serviceContainer; if($this->serviceContainer->getParameter("tr069_service")) { $this->user = $this->serviceContainer->getParameter("tr069_user"); $this->pass = $this->serviceContainer->getParameter("tr069_pass"); $this->host = $this->serviceContainer->getParameter("tr069_host"); $this->port = $this->serviceContainer->getParameter("tr069_port"); $this->url = "http://{$this->host}:{$this->port}"; } } private function get($url, $headers = array()) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($ch, CURLOPT_USERPWD, "{$this->user}:{$this->pass}"); $headers[] = "Accept: application/json"; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); if (curl_errno($ch)) {echo 'Error:' . curl_error($ch);} curl_close($ch); $data = json_decode($result,true); if(is_array($data)) return $data; return array(); } public function post($url, $data = array(), $headers = array()) { $ch = curl_init(); $data_string = json_encode($data); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_USERPWD, "{$this->user}:{$this->pass}"); $headers[] = "Content-Type: application/json"; $headers[] = "Content-Length: " . strlen($data_string); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); if (curl_errno($ch)) {echo 'Error:' . curl_error($ch);} curl_close($ch); $data = json_decode($result,true); if(is_array($data)) return $data; return array(); } public function getDevices($query = null) { $url = "{$this->url}/devices"; if($query && is_array($query)) { $url .= "?query=".json_encode($query); } return $this->get($url); } public function getDevice($id = null) { if(is_null($id)) return array(); $url = "{$this->url}/devices/{$id}"; return $this->get($url); } public function setWlan($id, $ssid, $password = null) { $url = "{$this->url}/devices/{$id}/tasks?connection_request"; $data = array(); $data['name'] = 'setParameterValues'; $data['parameterValues'] = array(); if($password) $data['parameterValues'][] = array('InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.PreSharedKey.1.PreSharedKey',$password,'xsd:string'); if($ssid) $data['parameterValues'][] = array('InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.SSID',$ssid,'xsd:string'); $return = $this->post($url, $data); return $return; } public function setCATV($id, $state = true) { $url = "{$this->url}/devices/{$id}/tasks?connection_request"; $data = array(); $data['name'] = 'setParameterValues'; $data['parameterValues'] = array(); $data['parameterValues'][] = array('InternetGatewayDevice.VS_AppCfg.VsCatvCfg.CatvPower',$state,'xsd:boolean'); $return = $this->post($url, $data); return $return; } public function setWbroadcast($id, $state = true) { $url = "{$this->url}/devices/{$id}/tasks?connection_request"; $data = array(); $data['name'] = 'setParameterValues'; $data['parameterValues'] = array(); $data['parameterValues'][] = array('InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.SSIDAdvertisementEnabled',$state,'xsd:boolean'); $return = $this->post($url, $data); return $return; } public function setWstatus($id, $state = true) { $url = "{$this->url}/devices/{$id}/tasks?connection_request"; $data = array(); $data['name'] = 'setParameterValues'; $data['parameterValues'] = array(); $data['parameterValues'][] = array('InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.Enable',$state,'xsd:boolean'); $return = $this->post($url, $data); return $return; } public function setParameter($id, $parameter, $value, $type) { $url = "{$this->url}/devices/{$id}/tasks?connection_request"; $data = array(); $data['name'] = 'setParameterValues'; $data['parameterValues'] = array(); $data['parameterValues'][] = array($parameter,$value,"xsd:$type"); $return = $this->post($url, $data); return $return; } public function getParameter($id, $parameter) { $query = json_encode(array('_id' => $id)); $url = "{$this->url}/devices?query={$query}&projection={$parameter}"; return $this->get($url); } public function getTR069Data($data) { $result = array(); $result['_id'] = $data['_id'] ?? null; $result['_deviceId'] = $data['_deviceId'] ?? null; $result['SSID'] = $data['InternetGatewayDevice']['LANDevice']['1']['WLANConfiguration']['1']['SSID'] ?? null; $result['keyPassphrase'] = $data['InternetGatewayDevice']['LANDevice']['1']['WLANConfiguration']['1']['KeyPassphrase'] ?? null; $result['SSIDAdvertisementEnabled'] = $data['InternetGatewayDevice']['LANDevice']['1']['WLANConfiguration']['1']['SSIDAdvertisementEnabled'] ?? null; $result['Status'] = $data['InternetGatewayDevice']['LANDevice']['1']['WLANConfiguration']['1']['Enable'] ?? null; //InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.PreSharedKey.1.PreSharedKey $result['preSharedKey'] = $data['InternetGatewayDevice']['LANDevice']['1']['WLANConfiguration']['1']['PreSharedKey']['1']['PreSharedKey'] ?? null; $result['CatvPower'] = $data['InternetGatewayDevice']['VS_AppCfg']['VsCatvCfg']['CatvPower'] ?? null; $result['ExternalIPAddress'] = $data['InternetGatewayDevice']['WANDevice']['1']['WANConnectionDevice']['1']['WANPPPConnection']['1']['ExternalIPAddress'] ?? null; return $result; } public function refreshObject($id, $object) { $url = "{$this->url}/devices/{$id}/tasks?connection_request"; $data = array(); $data['name'] = 'refreshObject'; $data['objectName'] = $object; $return = $this->post($url, $data); } }