get('/api/v1/cablemodem/node', function (Application $app, Request $request) { $ch = new Checks(); $codeResponse = 400; try { $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration()); $apiInstance = new NodeApi( new Client(), $config ); try { $id = $ch->integer($request, "id"); $apiInstance->setDisabledTenancy(true); $result = $apiInstance->getById($id); $apiInstance->setDisabledTenancy(false); if ($result) { $content = $result->__toString(); $content = (new CurlOptions())->clearNull($content); $codeResponse = 200; } else { $content = "No se encontro el id = " . $id; } } catch (Throwable $e) { $content = $e->getCode() . " - " . $e->getMessage(); } } catch (Throwable $t) { $content = $t->getCode() . " - " . $t->getMessage(); } return Utils::returnJSON($content, $codeResponse); }); } public function getNodes(Application $app) { $app->get('/api/v1/cablemodem/nodes', function (Application $app, Request $request) { $ch = new Checks(); $codeResponse = 400; try { $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration()); $apiInstance = new NodeApi( new Client(), $config ); try { $page = $ch->integer($request, "page", false); $limit = $ch->integer($request, "limit", false); $id = $ch->integer($request, "id", false); $name = $ch->string($request, "name", false); $parent = $ch->integer($request, "parent", false); $tenancyId = $ch->integer($request, "tenancyId", false); $qb_criteria = $ch->integer($request, "qb-criteria", false, null); $content = "["; $result = $apiInstance->getList($id, $parent, $name, $tenancyId, $qb_criteria, $limit, $page); foreach ($result as $v) { // se eliminan los null $content .= $v->__toString() . ","; } if (strlen($content) > 1) { $content = substr($content, 0, strlen($content) - 1); } $content .= "]"; $content = (new CurlOptions())->clearNull($content); $codeResponse = 200; } catch (Throwable $e) { $content = $e->getCode() . " - " . $e->getMessage(); } } catch (Throwable $t) { $content = $t->getCode() . " - " . $t->getMessage(); } return Utils::returnJSON($content, $codeResponse); }); } public function getModelId(Application $app) { $app->get('/api/v1/cablemodem/model', function (Application $app, Request $request) { $ch = new Checks(); $codeResponse = 400; try { $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration()); $apiInstance = new CablemodemModelApi( new Client(), $config ); try { $id = $ch->integer($request, "id"); $result = $apiInstance->getById($id); if ($result) { $content = $result->__toString(); $content = (new CurlOptions())->clearNull($content); $codeResponse = 200; } else { $content = "No se encontro el id = " . $id; } } catch (Throwable $e) { $content = $e->getCode() . " - " . $e->getMessage(); } } catch (Throwable $t) { $content = $t->getCode() . " - " . $t->getMessage(); } return Utils::returnJSON($content, $codeResponse); }); } public function getModels(Application $app) { $app->get('/api/v1/cablemodem/models', function (Application $app, Request $request) { $ch = new Checks(); $codeResponse = 400; try { $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration()); $apiInstance = new CablemodemModelApi( new Client(), $config ); try { $page = $ch->integer($request, "page", false); $limit = $ch->integer($request, "limit", false); $id = $ch->integer($request, "id", false); $name = $ch->string($request, "name", false); $qb_criteria = $ch->integer($request, "qb-criteria", false, null); $content = "["; $result = $apiInstance->getList($id, $name, $qb_criteria, $limit, $page); foreach ($result as $v) { // se eliminan los null $content .= $v->__toString() . ","; } if (strlen($content) > 1) { $content = substr($content, 0, strlen($content) - 1); } $content .= "]"; $content = (new CurlOptions())->clearNull($content); $codeResponse = 200; } catch (Throwable $e) { $content = $e->getCode() . " - " . $e->getMessage(); } } catch (Throwable $t) { $content = $t->getCode() . " - " . $t->getMessage(); } return Utils::returnJSON($content, $codeResponse); }); } public function getProfileId(Application $app) { $app->get('/api/v1/cablemodem/profile', function (Application $app, Request $request) { $ch = new Checks(); $codeResponse = 400; try { $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration()); $apiInstance = new ProfileApi( new Client(), $config ); try { $id = $ch->integer($request, "id"); $apiInstance->setDisabledTenancy(true); $result = $apiInstance->getById($id); $apiInstance->setDisabledTenancy(false); if ($result) { $content = $result->__toString(); $content = (new CurlOptions())->clearNull($content); $codeResponse = 200; } else { $content = "No se encontro el id = " . $id; } } catch (Throwable $e) { $content = $e->getCode() . " - " . $e->getMessage(); } } catch (Throwable $t) { $content = $t->getCode() . " - " . $t->getMessage(); } return Utils::returnJSON($content, $codeResponse); }); } public function getProfiles(Application $app) { $app->get('/api/v1/cablemodem/profiles', function (Application $app, Request $request) { $ch = new Checks(); $codeResponse = 400; try { $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration()); $apiInstance = new ProfileApi( new Client(), $config ); try { $page = $ch->integer($request, "page", false); $limit = $ch->integer($request, "limit", false); $id = $ch->integer($request, "id", false); $name = $ch->string($request, "name", false); $downstream = $ch->integer($request, "downstream", false); $upstream = $ch->integer($request, "upstream", false); $upload = $ch->integer($request, "upload", false); $download = $ch->integer($request, "download", false); $maxcpe = $ch->integer($request, "maxcpe", false); $tenancyId = $ch->integer($request, "tenancyId", false); $qb_criteria = $ch->integer($request, "qb-criteria", false, null); $content = "["; $result = $apiInstance->getList($id, $name, $downstream, $upstream, $upload, $download, $maxcpe, $tenancyId, $qb_criteria, $limit, $page); foreach ($result as $v) { // se eliminan los null $content .= $v->__toString() . ","; } if (strlen($content) > 1) { $content = substr($content, 0, strlen($content) - 1); } $content .= "]"; $content = (new CurlOptions())->clearNull($content); $codeResponse = 200; } catch (Throwable $e) { $content = $e->getCode() . " - " . $e->getMessage(); } } catch (Throwable $t) { $content = $t->getCode() . " - " . $t->getMessage(); } return Utils::returnJSON($content, $codeResponse); }); } public function getCablemodemId(Application $app) { $app->get('/api/v1/cablemodem/cablemodem', function (Application $app, Request $request) { $ch = new Checks(); $codeResponse = 400; try { $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration()); $apiInstance = new CablemodemApi( new Client(), $config ); try { $id = $ch->integer($request, "id"); $apiInstance->setDisabledTenancy(true); $result = $apiInstance->getById($id); $apiInstance->setDisabledTenancy(false); if ($result) { $content = $result->__toString(); $content = (new CurlOptions())->clearNull($content); $codeResponse = 200; } else { $content = "No se encontro el id = " . $id; } } catch (Throwable $e) { $content = $e->getCode() . " - " . $e->getMessage(); } } catch (Throwable $t) { $content = $t->getCode() . " - " . $t->getMessage(); } return Utils::returnJSON($content, $codeResponse); }); } public function getCablemodems(Application $app) { $app->get('/api/v1/cablemodem/cablemodems', function (Application $app, Request $request) { $ch = new Checks(); $codeResponse = 400; try { $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration()); $apiInstance = new CablemodemApi( new Client(), $config ); try { $page = $ch->integer($request, "page", false); $limit = $ch->integer($request, "limit", false); $id = $ch->integer($request, "id", false); $clientId = $ch->string($request, "clientId", false); $mac = $ch->integer($request, "mac", false); $node = $ch->string($request, "node", false); $profile = $ch->string($request, "profiel", false); $model = $ch->string($request, "model", false); $tenancyId = $ch->integer($request, "tenancyId", false); $qb_criteria = $ch->integer($request, "qb-criteria", false, null); $content = "["; $result = $apiInstance->getList($id, $clientId, $mac, $node, $profile, $model, $tenancyId, $qb_criteria, $limit, $page); foreach ($result as $v) { // se eliminan los null $content .= $v->__toString() . ","; } if (strlen($content) > 1) { $content = substr($content, 0, strlen($content) - 1); } $content .= "]"; $content = (new CurlOptions())->clearNull($content); $codeResponse = 200; } catch (Throwable $e) { $content = $e->getCode() . " - " . $e->getMessage(); } } catch (Throwable $t) { $content = $t->getCode() . " - " . $t->getMessage(); } return Utils::returnJSON($content, $codeResponse); }); } public function postCablemodem(Application $app) { $app->post('/api/v1/cablemodem/cablemodem', function (Application $app, Request $request) { $codeResponse = 400; try { $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration()); $configBase = $this->setUserPasswordConfig($request, ConfigurationBase::getDefaultConfiguration()); $apiInstance = new CablemodemApi( new Client(), $config ); $data = json_decode(file_get_contents('php://input'), true); $utils = new Utils(); $instance = $utils->loadData(new CablemodemCRUD(), $data); $errors = $instance->listInvalidProperties(); if (is_null($instance->getMac()) || trim($instance->getMac()) == "") { $content = "Debe cargar la mac del cablemodem."; } elseif (preg_match('/([a-fA-F0-9]{2}[:|\-]?){6}/', trim($instance->getMac())) == 0) { $content = "La mac es incorrecta."; } elseif (is_null($instance->getProfile()) || !is_numeric($instance->getProfile()) || $instance->getProfile() <= 0) { $content = "Debe cargar el perfil del cablemodem."; } elseif (count($errors) === 0) { // chequeo la tenencia $apiValidationBase = new ValidationApiBase( new Client(), $configBase ); $apiValidationCablemodem = new ValidationApi( new Client(), $config ); $content = null; // verifico si existe la tenencia if ($apiValidationBase->validTenancy($instance->getTenancyId())) { if (!is_null($instance->getClientId()) && $instance->getClientId() > 0) { // chequeo el cliente exista if (!$apiValidationBase->validClient($instance->getClientId())) { $content = "El id del cliente no existe."; } } if (is_null($content)) { // mostrar error de que la mac ya existe $result = $apiValidationCablemodem->existsCablemodem($instance->getMac(), $instance->getTenancyId()); $name = ""; if ($result) { $name = $result->getId() . " - " . $result->getMac(); } if ($name == "") { if (!is_null($instance->getNode())) { if (!$apiValidationCablemodem->validNode($instance->getNode())) { $content = "El id de nodo no existe."; } } if (is_null($content)) { if (!is_null($instance->getProfile())) { if (!$apiValidationCablemodem->validProfile($instance->getProfile())) { $content = "El id del profile no existe."; } } if (is_null($content)) { if (!is_null($instance->getModel())) { if (!$apiValidationCablemodem->validCablemodemModel($instance->getModel())) { $content = "El id del modelo no existe."; } } if (is_null($content)) { $apiInstance->create($instance); // busco el id del cliente, buscandolo por mac $result = $apiValidationCablemodem->existsCablemodem($instance->getMac(), $instance->getTenancyId()); if ($result) { $content = $result->__toString(); $codeResponse = 200; } else { $content = "No se pudo obtener el cablemodem cargado. Verifique por sistema si la carga se realizo correctamente."; } } } } } else { $codeResponse = 409; $content = "La MAC ya existe y pertenece al cablemodem " . $name . "."; } } } else { $content = "El id de tenencia es incorrecto."; } } else { $content = json_encode($errors); } } catch (Throwable $t) { $content = $t->getCode() . " - " . $t->getMessage(); } return Utils::returnJSON($content, $codeResponse); }); } public function putCablemodem(Application $app) { $app->put('/api/v1/cablemodem/cablemodem', function (Application $app, Request $request) { $codeResponse = 400; try { $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration()); $configBase = $this->setUserPasswordConfig($request, ConfigurationBase::getDefaultConfiguration()); $apiInstance = new CablemodemApi( new Client(), $config ); $data = json_decode(file_get_contents('php://input'), true); $utils = new Utils(); $instance = $utils->loadData(new CablemodemCRUD(), $data); $errors = $instance->listInvalidProperties(); if (is_null($instance->getMac()) || trim($instance->getMac()) == "") { $content = "Debe cargar la mac del cablemodem."; } elseif (is_null($instance->getProfile()) || !is_numeric($instance->getProfile()) || $instance->getProfile() <= 0) { $content = "Debe cargar el perfil del cablemodem."; } elseif (count($errors) === 0) { // chequeo la tenencia $apiValidationBase = new ValidationApiBase( new Client(), $configBase ); $apiValidationCablemodem = new ValidationApi( new Client(), $config ); $content = null; // verifico si existe la tenencia if ($apiValidationBase->validTenancy($instance->getTenancyId())) { if (!is_null($instance->getClientId()) && $instance->getClientId() > 0) { // chequeo el cliente exista if (!$apiValidationBase->validClient($instance->getClientId())) { $content = "El id del cliente no existe."; } } if (is_null($content)) { // mostrar error de que la mac ya existe $result = $apiValidationCablemodem->existsCablemodem($instance->getMac(), $instance->getTenancyId()); $name = ""; if ($result && $result->getId() != $instance->getId()) { $name = $result->getId() . " - " . $result->getMac(); } if ($name == "") { if (!is_null($instance->getNode())) { if (!$apiValidationCablemodem->validNode($instance->getNode())) { $content = "El id de nodo no existe."; } } if (is_null($content)) { if (!is_null($instance->getProfile())) { if (!$apiValidationCablemodem->validProfile($instance->getProfile())) { $content = "El id del profile no existe."; } } if (is_null($content)) { if (!is_null($instance->getModel())) { if (!$apiValidationCablemodem->validCablemodemModel($instance->getModel())) { $content = "El id del modelo no existe."; } } if (is_null($content)) { $apiInstance->update($instance->getId(), $instance); // busco el id del cliente, buscandolo por externalid $apiInstance->setDisabledTenancy(true); $result = $apiInstance->getById($instance->getId()); $apiInstance->setDisabledTenancy(false); if ($result) { $content = $result->__toString(); $codeResponse = 200; } else { $content = "No se pudo obtener el cablemodem cargado. Verifique por sistema si la carga se realizo correctamente."; } } } } } else { $codeResponse = 409; $content = "La MAC ya existe y pertenece al cablemodem " . $name . "."; } } } else { $content = "El id de tenencia es incorrecto."; } } else { $content = json_encode($errors); } } catch (Throwable $t) { $content = $t->getCode() . " - " . $t->getMessage(); } return Utils::returnJSON($content, $codeResponse); }); } public function deleteCablemodem(Application $app) { $app->delete('/api/v1/cablemodem/cablemodem', function (Application $app, Request $request) { $codeResponse = 400; try { $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration()); $apiInstance = new CablemodemApi( new Client(), $config ); $ch = new Checks(); $id = $ch->integer($request, "id", true); $apiInstance->setDisabledTenancy(true); $result = $apiInstance->getById($id); $apiInstance->setDisabledTenancy(false); if (!is_null($result)) { $apiInstance->delete($id); $content = $result->__toString(); $codeResponse = 200; } else { $content = "No se encontro el id = " . $id; } } catch (Throwable $t) { $content = $t->getCode() . " - " . $t->getMessage(); } return Utils::returnJSON($content, $codeResponse); }); } public function getCablemodemActive(Application $app) { $app->get('/api/v1/cablemodem/cablemodem/active', function (Application $app, Request $request) { $codeResponse = 400; try { $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration()); $apiInstance = new CablemodemApi( new Client(), $config ); $ch = new Checks(); $id = $ch->integer($request, "id", true); $workflow = "administrative_state"; $transition = "suspend_to_active"; $apiInstance->setDisabledTenancy(true); $result = $apiInstance->getById($id); $apiInstance->setDisabledTenancy(false); if (!is_null($result)) { $apiInstance->apply($id, $workflow, $transition); $apiInstance->setDisabledTenancy(true); $result = $apiInstance->getById($id); $apiInstance->setDisabledTenancy(false); if ($result) { $content = $result->__toString(); $codeResponse = 200; } else { $content = "No se pudo obtener el acceso cargado. Verifique por sistema si la carga se realizo correctamente."; } } else { $content = "No se encontro el cablemodem de id = " . $id; } } catch (Throwable $t) { $content = $t->getCode() . " - " . $t->getMessage(); } return Utils::returnJSON($content, $codeResponse); }); } public function getCablemodemDisable(Application $app) { $app->get('/api/v1/cablemodem/cablemodem/disable', function (Application $app, Request $request) { $codeResponse = 400; try { $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration()); $apiInstance = new CablemodemApi( new Client(), $config ); $ch = new Checks(); $id = $ch->integer($request, "id", true); $workflow = "administrative_state"; $transition = "active_to_suspend"; $apiInstance->setDisabledTenancy(true); $result = $apiInstance->getById($id); $apiInstance->setDisabledTenancy(false); if (!is_null($result)) { $apiInstance->apply($id, $workflow, $transition); $apiInstance->setDisabledTenancy(true); $result = $apiInstance->getById($id); $apiInstance->setDisabledTenancy(false); if ($result) { $content = $result->__toString(); $codeResponse = 200; } else { $content = "No se pudo obtener el acceso cargado. Verifique por sistema si la carga se realizo correctamente."; } } else { $content = "No se encontro el cablemodem de id = " . $id; } } catch (Throwable $t) { $content = $t->getCode() . " - " . $t->getMessage(); } return Utils::returnJSON($content, $codeResponse); }); } public function getCablemodemSupply(Application $app) { $app->get('/api/v1/cablemodem/cablemodem/supply', function (Application $app, Request $request) { $codeResponse = 400; try { $config = $this->setUserPasswordConfig($request, Configuration::getDefaultConfiguration()); $apiInstance = new CablemodemApi( new Client(), $config ); $ch = new Checks(); $mac = $ch->string($request, "mac", true); $activationCode = $ch->string($request, "activationCode", true); $apiInstance->setDisabledTenancy(true); $result = $apiInstance->getList(null, null, $mac); $apiInstance->setDisabledTenancy(false); $util = new \Utils(); $result = $util->valueExistsLower($mac, $result, "getMac"); if (!is_null($result)) { $instance = new CablemodemCRUD(); $instance->setId($result->getId()); $instance->setActivationCode($activationCode); $apiInstance->update($result->getId(), $instance); $apiInstance->setDisabledTenancy(true); $result = $apiInstance->getById($result->getId()); $apiInstance->setDisabledTenancy(false); if ($result) { $content = $result->__toString(); $codeResponse = 200; } else { $content = "No se pudo obtener el acceso cargado. Verifique por sistema si la carga se realizo correctamente."; } } else { $content = "No se encontro el cablemodem de mac = " . $mac; } } catch (Throwable $t) { $content = $t->getCode() . " - " . $t->getMessage(); } return Utils::returnJSON($content, $codeResponse); }); } }