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(); } private 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); } 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; } 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; } }