- Split single-page into 3 pages: - index.php: product catalog with VM size cards - create.php: order form (name, domain, description) - requests.php: request history with pagination - Rewrite NetBox integration to create Virtual Machines (/virtualization/virtual-machines/) instead of DCIM devices - Add netbox_integration/netbox_api.php: NetBoxClient with createVirtualMachine(), findCluster(), findTag(), getList() - Generate new sleek product-card images (420x280) with aligned spec boxes (vcpus/ram/disk) - Add webshop CSS: product cards, nav links, hero section, order layout, responsive grid - Update redirects: send.php -> requests.php, cancel.php -> requests.php - Update E2E test for new page structure - Add .gitignore, deploy-local.sh, setup_database.sql to repo
62 lines
1.6 KiB
PHP
Executable File
62 lines
1.6 KiB
PHP
Executable File
<?php
|
|
// NetBox configuration
|
|
|
|
function loadNetBoxEnvValue($key, $default = '') {
|
|
$value = getenv($key);
|
|
if ($value !== false && $value !== '') {
|
|
return $value;
|
|
}
|
|
|
|
$envPath = dirname(__DIR__) . '/.env';
|
|
if (!is_readable($envPath)) {
|
|
return $default;
|
|
}
|
|
|
|
$lines = file($envPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
|
if ($lines === false) {
|
|
return $default;
|
|
}
|
|
|
|
foreach ($lines as $line) {
|
|
$line = trim($line);
|
|
if ($line === '' || str_starts_with($line, '#')) {
|
|
continue;
|
|
}
|
|
|
|
if (str_contains($line, '=')) {
|
|
[$name, $rawValue] = array_map('trim', explode('=', $line, 2));
|
|
if ($name === $key) {
|
|
return trim($rawValue, "\"'");
|
|
}
|
|
continue;
|
|
}
|
|
|
|
// Backward compatibility: the current local .env contains only the
|
|
// NetBox token value, without a NETBOX_API_TOKEN= prefix.
|
|
if ($key === 'NETBOX_API_TOKEN') {
|
|
return $line;
|
|
}
|
|
}
|
|
|
|
return $default;
|
|
}
|
|
|
|
$netboxConfig = [
|
|
'base_url' => loadNetBoxEnvValue('NETBOX_BASE_URL', 'http://192.168.1.144'),
|
|
'api_token' => loadNetBoxEnvValue('NETBOX_API_TOKEN'),
|
|
'verify_ssl' => false, // Set to true in production
|
|
];
|
|
|
|
// Function to get NetBox client
|
|
function getNetBoxClient() {
|
|
global $netboxConfig;
|
|
$token = $netboxConfig['api_token'];
|
|
$baseUrl = $netboxConfig['base_url'];
|
|
|
|
// Include the NetBox client class
|
|
require_once __DIR__ . '/netbox_api.php';
|
|
|
|
return new NetBoxClient($baseUrl, $token);
|
|
}
|
|
?>
|