Add modal for configuring Chrome Extension ID and enhance CPE provisioning functionality

This commit is contained in:
Luca Haid
2025-11-17 08:36:25 +01:00
parent a0791b3b68
commit a09085ec5c
5 changed files with 190 additions and 10 deletions

View File

@@ -529,6 +529,7 @@ class CpeprovisioningController extends mfBaseController {
// Pass API URLs and initial data to the frontend
"CPE_PROV_API_GET_URL" => $this->getUrl("Cpeprovisioning", "apiGet"),
"CPE_PROV_API_SAVE_URL" => $this->getUrl("Cpeprovisioning", "apiSave"),
"CPE_PROV_API_TEST_ACS_VLAN_URL" => $this->getUrl("Cpeprovisioning", "getAcsVlan"),
"CPE_PROV_PRINT_PDF_URL" => $this->getUrl("Cpeprovisioning", "printPDF"),
"ORDER_URL" => $this->getUrl("Order"),
"NETWORKS" => NetworkModel::getAll(),
@@ -565,6 +566,58 @@ class CpeprovisioningController extends mfBaseController {
);
}
protected function getAcsVlanAction() {
$apiKey = $_SERVER['HTTP_X_API_KEY'] ?? null;
$isApiCall = defined('TT_CPE_PROV_ACS_API_KEY') && $apiKey && $apiKey === TT_CPE_PROV_ACS_API_KEY;
$isLoggedInUser = $this->me && $this->me->id;
if (!$isApiCall && !$isLoggedInUser) {
http_response_code(403);
self::returnJson(['success' => false, 'message' => 'Forbidden']);
return;
}
try {
$p = json_decode(file_get_contents('php://input'), true);
$mac = $p['mac'] ?? null;
if (empty($mac)) {
throw new Exception("MAC address is required.");
}
$cpe = CpeprovisioningModel::getFirst(['mac' => $mac]);
if (!$cpe || !$cpe->termination_id) {
throw new Exception("No active provisioning entry found for this MAC address.");
}
$term = new Termination($cpe->termination_id);
$product = $cpe->orderproduct;
if (!$term->id || !$product->id) {
throw new Exception("Could not load termination or product details.");
}
$attrs = $product->product->attributes;
$vlanPublicDefault = $term->getPop()->vlan_public ?? $attrs['vlan_default_public']->value ?? null;
$vlanNatDefault = $term->getPop()->vlan_nat ?? $attrs['vlan_default_nat']->value ?? null;
$vlanIpv6Default = $term->getPop()->vlan_ipv6 ?? $attrs['vlan_default_ipv6']->value ?? null;
// For the test, we just return the first available VLAN that would be assigned.
// The logic can be expanded if a specific type is requested.
$assignedVlan = $vlanPublicDefault ?? $vlanNatDefault ?? $vlanIpv6Default;
if ($assignedVlan) {
self::returnJson(['success' => true, 'vlan_id' => $assignedVlan]);
} else {
throw new Exception("No default VLAN could be determined for this product/POP combination.");
}
} catch (Exception $e) {
http_response_code(400);
self::returnJson(['success' => false, 'message' => $e->getMessage()]);
}
}
private function fixCpeData($data) {
if (!$data) return [];
$data->shipping = (bool)$data->shipping;