From d209a5b13d9c21115ec1e48369790f697493ef32 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Fri, 12 Dec 2025 12:10:26 +0100 Subject: [PATCH] WIP Citycom ONT Status 2025-12-11 --- .../Modules/Operationaldata/SnoppCitycom.php | 59 +++++++++ .../Api/v1/OperationaldataApicontroller.php | 3 +- lib/Citycom/OanApiClient.php | 116 ++++++++++++++++++ 3 files changed, 177 insertions(+), 1 deletion(-) diff --git a/application/Api/v1/Modules/Operationaldata/SnoppCitycom.php b/application/Api/v1/Modules/Operationaldata/SnoppCitycom.php index 0420f7e42..75bdbade4 100644 --- a/application/Api/v1/Modules/Operationaldata/SnoppCitycom.php +++ b/application/Api/v1/Modules/Operationaldata/SnoppCitycom.php @@ -17,6 +17,65 @@ class SnoppCitycom extends Modules\ApiControllerModule } + public function getOntStatus($req_id) { + if(!$req_id) { + return \mfResponse::BadRequest(["message" => "id missing"]); + } + + $wohneinheit = false; + if(is_numeric($req_id)) { + $id = $req_id; + $wohneinheit = new \ADBWohneinheit($id); + } + if(!$wohneinheit || !$wohneinheit->id) { + $oaid = $req_id; + $wohneinheit = \ADBWohneinheitModel::getFirst(["oaid" => $oaid]); + if (!$wohneinheit) { + return \mfResponse::NotFound(["message" => "Home not found"]); + } + } + + $cc = new \Citycom_OanApiClient(CITYCOM_OAN_API_USER, CITYCOM_OAN_API_PASS); + $data = $cc->getOntStatus($wohneinheit->oaid); + + $status = []; + $status["online"] = ($data->{"oper-status"} == "present" && $data->status == "Confirmed") ? 1 : 0; + $status["uptime"] = ($data->up_time) ? (date('U') - $data->up_time) : null; + $status["downtime"] = null; + $status["rx"] = $data->{"opt-signal-level"}; + $status["tx"] = $data->tx_opt_level_dbm; + $status["distance"] = null; + + + return \mfResponse::Ok(["status" => $status]); + } + + public function getOntTelemetry($req_id) { + if(!$req_id) { + return \mfResponse::BadRequest(["message" => "id missing"]); + } + + $wohneinheit = false; + if(is_numeric($req_id)) { + $id = $req_id; + $wohneinheit = new \ADBWohneinheit($id); + } + if(!$wohneinheit || !$wohneinheit->id) { + $oaid = $req_id; + $wohneinheit = \ADBWohneinheitModel::getFirst(["oaid" => $oaid]); + if (!$wohneinheit) { + return \mfResponse::NotFound(["message" => "Home not found"]); + } + } + + $cc = new \Citycom_OanApiClient(CITYCOM_OAN_API_USER, CITYCOM_OAN_API_PASS); + $data = $cc->getOntStatusDetail($wohneinheit->oaid); + + print_r($data);exit; + + return \mfResponse::Ok(["status" => $status]); + } + public function orderService($req_id) { if(!$req_id) { return \mfResponse::BadRequest(["message" => "id missing"]); diff --git a/application/Api/v1/OperationaldataApicontroller.php b/application/Api/v1/OperationaldataApicontroller.php index da17d35dc..c0f70186b 100644 --- a/application/Api/v1/OperationaldataApicontroller.php +++ b/application/Api/v1/OperationaldataApicontroller.php @@ -50,8 +50,9 @@ class OperationaldataApicontroller extends mfBaseApicontroller $this->addRoute("/operationaldata/home/:id/connected", [$modules["Snopp"], "setPreorderConnected"], "POST"); $this->addRoute("/operationaldata/home/:id/active", [$modules["Snopp"], "setPreorderActive"], "POST"); - //$this->addRoute("/operationaldata/preorder/:id/orderServiceTest", [$modules["SnoppCitycom"], "orderServiceTest"], "POST"); $this->addRoute("/operationaldata/preorder/:id/orderService", [$modules["SnoppCitycom"], "orderService"], "POST"); + $this->addRoute("/operationaldata/preorder/:id/ontStatus", [$modules["SnoppCitycom"], "getOntStatus"], "GET"); + $this->addRoute("/operationaldata/preorder/:id/ontTelemetry", [$modules["SnoppCitycom"], "getOntTelemetry"], "GET"); } diff --git a/lib/Citycom/OanApiClient.php b/lib/Citycom/OanApiClient.php index 24cac04c8..c5f61c546 100644 --- a/lib/Citycom/OanApiClient.php +++ b/lib/Citycom/OanApiClient.php @@ -266,6 +266,122 @@ class Citycom_OanApiClient { return $types; } + public function getOntStatus($oan_id) { + if(!$this->token) { + $this->getAuthToken(); + if(!$this->token) { + return false; + } + } + + $url = $this->baseurl.CITYCOM_OAN_API_EP_GET_ONT_STATUS; + $url = str_replace("{oan_id}", $oan_id, $url); + $ctx_options = [ + "http" => [ + "ignore_errors" => true, + "method" => "GET", + "header" => [ + "Accept: application/json", + "Authorization: Bearer ".$this->token, + ], + ] + ]; + + $ctx = stream_context_create($ctx_options); + $output = file_get_contents($url, false, $ctx); + + $resp = json_decode($output); + if(!is_object($resp)) { + return false; + } + if(!property_exists($resp, "success") || !$resp->success || !property_exists($resp, "data")) { + return false; + } + + return $resp->data; + } + + public function getOntPortStatus($oan_id) { + if(!$this->token) { + $this->getAuthToken(); + if(!$this->token) { + return false; + } + } + + $url = $this->baseurl.CITYCOM_OAN_API_EP_GET_ONT_PORTSTATUS; + $url = str_replace("{oan_id}", $oan_id, $url); + $ctx_options = [ + "http" => [ + "ignore_errors" => true, + "method" => "GET", + "header" => [ + "Accept: application/json", + "Authorization: Bearer ".$this->token, + ], + ] + ]; + + $ctx = stream_context_create($ctx_options); + $output = file_get_contents($url, false, $ctx); + + $resp = json_decode($output); + if(!is_object($resp)) { + return false; + } + if(!property_exists($resp, "success") || !$resp->success || !property_exists($resp, "data")) { + return false; + } + + return $resp->data; + } + + public function getOntMacAddresses($oan_id) { + if(!$this->token) { + $this->getAuthToken(); + if(!$this->token) { + return false; + } + } + + $url = $this->baseurl.CITYCOM_OAN_API_EP_GET_ONT_MACADDRESSES; + $url = str_replace("{oan_id}", $oan_id, $url); + $ctx_options = [ + "http" => [ + "ignore_errors" => true, + "method" => "GET", + "header" => [ + "Accept: application/json", + "Authorization: Bearer ".$this->token, + ], + ] + ]; + + $ctx = stream_context_create($ctx_options); + $output = file_get_contents($url, false, $ctx); + + $resp = json_decode($output); + if(!is_object($resp)) { + return false; + } + if(!property_exists($resp, "success") || !$resp->success || !property_exists($resp, "data")) { + return false; + } + return $resp->data; + } + + public function getOntStatusDetail($oan_id) { + $ont_status = $this->getOntStatus($oan_id); + $ont_port_status = $this->getOntPortStatus($oan_id); + $ont_mac_addresses = $this->getOntMacAddresses($oan_id); + + return [ + $ont_status, + $ont_port_status, + $ont_mac_addresses + ]; + } + private function getAuthToken() { $token = new mfConfig("adb.import.citycom.auth.token"); if($token && $token->value()) {