WIP 2025-07-31 Citycom OAN Api WIP
This commit is contained in:
@@ -74,7 +74,6 @@ class Citycom_OanApiClient {
|
||||
}
|
||||
|
||||
$url = $this->baseurl.CITYCOM_OAN_API_EP_GET_PRODUCTS;
|
||||
echo "$url\n";
|
||||
|
||||
$url = $this->baseurl.CITYCOM_OAN_API_EP_GET_PRODUCTS;
|
||||
|
||||
@@ -107,7 +106,6 @@ class Citycom_OanApiClient {
|
||||
}
|
||||
|
||||
$url = $this->baseurl.CITYCOM_OAN_API_EP_CREATE_PRODUCT;
|
||||
echo "$url\n";
|
||||
|
||||
$ctx_options = [
|
||||
"http" => [
|
||||
@@ -136,7 +134,6 @@ class Citycom_OanApiClient {
|
||||
}
|
||||
|
||||
$url = str_replace("{product_id}", $product_id, $this->baseurl.CITYCOM_OAN_API_EP_UPDATE_PRODUCT);
|
||||
echo $url;
|
||||
|
||||
}
|
||||
|
||||
@@ -149,7 +146,6 @@ class Citycom_OanApiClient {
|
||||
}
|
||||
|
||||
$url = str_replace("{product_id}", $product_id, $this->baseurl.CITYCOM_OAN_API_EP_DELETE_PRODUCT);
|
||||
echo "$url\n";
|
||||
|
||||
}
|
||||
|
||||
@@ -163,7 +159,6 @@ class Citycom_OanApiClient {
|
||||
}
|
||||
|
||||
$url = $this->baseurl.CITYCOM_OAN_API_EP_GET_SERVICES;
|
||||
echo "$url\n";
|
||||
|
||||
$ctx_options = [
|
||||
"http" => [
|
||||
@@ -181,7 +176,7 @@ class Citycom_OanApiClient {
|
||||
|
||||
}
|
||||
|
||||
public function createService($home_id, $data) {
|
||||
public function createService($data) {
|
||||
if(!$this->token) {
|
||||
$this->getAuthToken();
|
||||
if(!$this->token) {
|
||||
@@ -189,8 +184,11 @@ class Citycom_OanApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
if(!array_key_exists("billing_date", $data) || !$data["billing_date"]) {
|
||||
$data["billing_date"] = date("Y-m-d");
|
||||
}
|
||||
|
||||
$url = $this->baseurl.CITYCOM_OAN_API_EP_CREATE_SERVICES;
|
||||
echo "$url\n";
|
||||
|
||||
$ctx_options = [
|
||||
"http" => [
|
||||
@@ -217,7 +215,6 @@ class Citycom_OanApiClient {
|
||||
}
|
||||
|
||||
$url = str_replace("{service_id}", $service_id, $this->baseurl.CITYCOM_OAN_API_EP_UPDATE_SERVICES);
|
||||
echo $url;
|
||||
|
||||
}
|
||||
|
||||
@@ -230,7 +227,6 @@ class Citycom_OanApiClient {
|
||||
}
|
||||
|
||||
$url = str_replace("{service_id}", $service_id, $this->baseurl.CITYCOM_OAN_API_EP_CANCEL_SERVICES);
|
||||
echo "$url\n";
|
||||
|
||||
}
|
||||
|
||||
@@ -264,8 +260,6 @@ class Citycom_OanApiClient {
|
||||
|
||||
$types = $resp->data;
|
||||
|
||||
var_dump($types);exit;
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ class Citycom_OanApiHelper {
|
||||
|
||||
public function __construct(Citycom_OanApiClient $apiClient) {
|
||||
$this->api = $apiClient;
|
||||
$this->log = mfLoghandler::singleton();
|
||||
}
|
||||
|
||||
public function findOrCreateProduct($specs = []) {
|
||||
@@ -54,6 +55,22 @@ class Citycom_OanApiHelper {
|
||||
return $product_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates services in Citycom API
|
||||
*
|
||||
* $data = [
|
||||
* "up" = 300,
|
||||
* "down" = 300,
|
||||
* "execution_date" = [Y-m-d | false],
|
||||
* "services" = CITYCOM_OAN_API_SERVICES_FOR_ORDER,
|
||||
* "product_name" = "thetool-test OAN 300/300"
|
||||
* ]
|
||||
*
|
||||
* @param $preorder Preorder
|
||||
* @param $sublocation_id integer
|
||||
* @param $data Array
|
||||
* @return boolean
|
||||
*/
|
||||
public function orderServices($preorder, $sublocation_id, $data) {
|
||||
if(!is_numeric($sublocation_id) || !$sublocation_id) {
|
||||
return false;
|
||||
@@ -63,7 +80,7 @@ class Citycom_OanApiHelper {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!array_key_exists("services", $data) || is_array($data["services"]) || !count($data["services"])) {
|
||||
if(!array_key_exists("services", $data) || !is_array($data["services"]) || !count($data["services"])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -71,7 +88,7 @@ class Citycom_OanApiHelper {
|
||||
$down = $data["down"];
|
||||
$product_name = $data["product_name"];
|
||||
$execution_date = $data["execution_date"];
|
||||
$services = $data["services"];
|
||||
$want_services = $data["services"];
|
||||
|
||||
if(!$execution_date) {
|
||||
$execution_date = date("Y-m-d");
|
||||
@@ -79,33 +96,98 @@ class Citycom_OanApiHelper {
|
||||
|
||||
|
||||
$product_data = [
|
||||
"bb_up" => $up,
|
||||
"bb_down" => $down,
|
||||
"up" => $up,
|
||||
"down" => $down,
|
||||
"name" => $product_name
|
||||
];
|
||||
|
||||
// find or craete product
|
||||
$product_id = $this->findOrCreateProduct($product_data);
|
||||
if(!$product_id) {
|
||||
$this->log->debug(__METHOD__.": no citycom product for query ".print_r($product_data, true));
|
||||
$this->log->error(__METHOD__.": no citycom product found for ".print_r($product_data, true));
|
||||
return false;
|
||||
}
|
||||
|
||||
// order all services and save ctags
|
||||
$cc_service_types = $this->api->getServices();
|
||||
$cc_service_types = $this->api->getServiceTypes();
|
||||
|
||||
$new_services = [];
|
||||
|
||||
$ctags = $preorder->getNextFreeCtags();
|
||||
|
||||
if(!$ctags) {
|
||||
$this->log->error(__METHOD__.": No New Free Ctags (Preorder ".$preorder->id.")");
|
||||
}
|
||||
|
||||
if(count($ctags) < count($want_services)) {
|
||||
$this->log->error(__METHOD__.": Not enough New Free CTags for Preorder ".$preorder->id);
|
||||
}
|
||||
|
||||
$preorder_ctag_data = [
|
||||
"preorder_id" => $preorder->id,
|
||||
"network" => "citycom-oan-api",
|
||||
"stag" => $preorder->adb_hausnummer->vlan_stag,
|
||||
];
|
||||
|
||||
$service_count = 0;
|
||||
foreach($cc_service_types as $stype) {
|
||||
// was this service type requested
|
||||
if(!in_array($stype->name, $want_services)) continue;
|
||||
|
||||
$ctag = $ctags[$service_count];
|
||||
$ctag_service_type = array_flip(CITYCOM_OAN_API_SERVICES_FOR_ORDER)[$stype->name];
|
||||
if(!$ctag_service_type) {
|
||||
$this->log->error(__METHOD__.": Cannot create Service ".$stype->name." for preorder ".$preorder->id." because no ctag service type defined");
|
||||
}
|
||||
|
||||
$service_data = [
|
||||
"sublocation" => $sublocation_id,
|
||||
"service_type" => $stype->id,
|
||||
"product" => $product_id,
|
||||
"billing_date" => $execution_date,
|
||||
"ctag"
|
||||
"ctag" => $ctag,
|
||||
];
|
||||
$new_service = $this->api->createService($sublocation_id, $service_data);
|
||||
|
||||
$this->log->info(__METHOD__.": Creating Service ".$stype->name." on sublocation $sublocation_id with product_id $product_id and ctag $ctag");
|
||||
//continue;
|
||||
|
||||
// register new Service with Citycom
|
||||
/*$new_service = $this->api->createService($service_data);
|
||||
if(!$new_service) {
|
||||
return false;
|
||||
}*/
|
||||
|
||||
$service_return = [
|
||||
"ont" => [
|
||||
"serial" => "ONT123456",
|
||||
"fsan" => "FSAN7890",
|
||||
],
|
||||
];
|
||||
|
||||
// save ctag
|
||||
$ctag_data = $preorder_ctag_data;
|
||||
$ctag_data["ctag"] = $ctag;
|
||||
$ctag_data["service_type"] = $ctag_service_type;
|
||||
$pct = PreorderCtag::create($ctag_data);
|
||||
|
||||
$service_count++;
|
||||
|
||||
if(!$pct->save()) {
|
||||
$this->log->error(__METHOD__.": Error saving PreorderCtag (Preorder ".$preorder->id.")");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$pct->configureNetwork();
|
||||
} catch(Exception $e) {
|
||||
$this->log->error(__METHOD__.": Error configuring network equipment (Preorder ".$preorder->id.")");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ class mfRouteros {
|
||||
private $password;
|
||||
private $ros = false;
|
||||
|
||||
public function __construct($hostname, $username, $password, $port = 8729, $use_ssl = true) {
|
||||
public function __construct($hostname, $username, $password, $port = 8729, $use_ssl = "auto") {
|
||||
$this->hostname = $hostname;
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
@@ -25,7 +25,9 @@ class mfRouteros {
|
||||
|
||||
private function _connect() {
|
||||
$crypto = NetworkStream::CRYPTO_OFF;
|
||||
if($this->use_ssl) {
|
||||
if($this->use_ssl === true) {
|
||||
$crypto = NetworkStream::CRYPTO_TLS;
|
||||
} elseif($this->use_ssl == "auto" && $this->port == 8729) {
|
||||
$crypto = NetworkStream::CRYPTO_TLS;
|
||||
}
|
||||
|
||||
@@ -104,6 +106,60 @@ class mfRouteros {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function add($table, $set = []) {
|
||||
if(!$this->ros) $this->_connect();
|
||||
|
||||
if(substr($table, 0, 1) != '/') {
|
||||
$table = "/".$table;
|
||||
}
|
||||
|
||||
$req = new RouterOS\Request("$table add");
|
||||
|
||||
if(count($set)) {
|
||||
foreach($set as $name => $value) {
|
||||
$req->setArgument($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$resp = $this->ros->sendSync($req);
|
||||
|
||||
if($resp->getType() !== RouterOS\Response::TYPE_FINAL) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function remove($table, $filter = []) {
|
||||
if(!$filter) {
|
||||
// no filter would remove every entry in table -> disallowed
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$this->ros) $this->_connect();
|
||||
$util = new RouterOS\Util($this->ros);
|
||||
|
||||
if(substr($table, 0, 1) != '/') {
|
||||
$table = "/".$table;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$query = false;
|
||||
if(count($filter)) {
|
||||
foreach($filter as $name => $value) {
|
||||
if(!$query) {
|
||||
$query = RouterOS\Query::where($name, $value);
|
||||
} else {
|
||||
$query->andWhere($name, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$util->setMenu($table);
|
||||
$util->remove($query);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* accessors */
|
||||
public function hostname($hostname=false) {
|
||||
|
||||
Reference in New Issue
Block a user