mirror of
https://github.com/myronblair/novacpx
synced 2026-06-30 17:50:41 -05:00
716d292e77
Each panel now has its own dedicated port and is fully self-contained: - Port 8880: User panel (end-user hosting dashboard) - Port 8881: Reseller panel (account/package management) - Port 8882: Admin panel (datacenter/server manager) Changes: - install.sh: PORT_USER/PORT_RESELLER/PORT_ADMIN constants; three separate nginx/Apache vhosts; UFW opens all three ports; Fail2Ban jail per port; credentials file shows all three URLs - config.ini: stores port_user/port_reseller/port_admin - Core.php: defines PORT_USER/RESELLER/ADMIN, detects CURRENT_PORTAL from SERVER_PORT so the API knows which tier is being accessed - Auth.php: portalUrl() maps role → correct port for cross-portal redirects - auth.php endpoint: returns portal_url on login so JS redirects to right port - index.php login: uses portal_url from API response (no hardcoded paths) - admin/index.php: inline login form (port 8882 is self-contained, no redirect) - user/index.php: inline login form (port 8880 self-contained) - reseller/index.php: new full reseller panel with inline login (port 8881); sidebar with accounts, packages, DNS, branding, bandwidth report sections Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
65 lines
2.5 KiB
PHP
65 lines
2.5 KiB
PHP
<?php
|
|
/**
|
|
* NovaCPX Core — constants, config loader, helpers
|
|
*/
|
|
|
|
define('NOVACPX_VERSION', trim(file_get_contents(NOVACPX_ROOT . '/VERSION') ?: '1.0.0'));
|
|
define('NOVACPX_CONFIG', '/etc/novacpx/config.ini');
|
|
|
|
// Load config
|
|
$_cfg = parse_ini_file(NOVACPX_CONFIG, true);
|
|
if (!$_cfg) {
|
|
http_response_code(503);
|
|
die(json_encode(['error' => 'NovaCPX not configured. Run the installer.']));
|
|
}
|
|
|
|
define('DB_HOST', $_cfg['database']['host'] ?? 'localhost');
|
|
define('DB_NAME', $_cfg['database']['name'] ?? 'novacpx');
|
|
define('DB_USER', $_cfg['database']['user'] ?? '');
|
|
define('DB_PASS', $_cfg['database']['pass'] ?? '');
|
|
define('SECRET_KEY', $_cfg['panel']['secret'] ?? '');
|
|
define('PANEL_VER', $_cfg['panel']['version'] ?? NOVACPX_VERSION);
|
|
define('PORT_USER', (int)($_cfg['panel']['port_user'] ?? 8880));
|
|
define('PORT_RESELLER', (int)($_cfg['panel']['port_reseller'] ?? 8881));
|
|
define('PORT_ADMIN', (int)($_cfg['panel']['port_admin'] ?? 8882));
|
|
define('WEB_SERVER', $_cfg['web']['server'] ?? 'apache');
|
|
define('PHP_DEFAULT', $_cfg['web']['php_default'] ?? '8.3');
|
|
|
|
// Detect which portal is being accessed by the request port
|
|
$requestPort = (int)($_SERVER['SERVER_PORT'] ?? 0);
|
|
define('CURRENT_PORTAL',
|
|
$requestPort === PORT_ADMIN ? 'admin' :
|
|
($requestPort === PORT_RESELLER ? 'reseller' : 'user')
|
|
);
|
|
|
|
function novacpx_log(string $level, string $msg, array $ctx = []): void {
|
|
$line = sprintf("[%s] [%s] %s %s\n",
|
|
date('Y-m-d H:i:s'), strtoupper($level), $msg,
|
|
$ctx ? json_encode($ctx) : ''
|
|
);
|
|
file_put_contents('/var/log/novacpx/panel.log', $line, FILE_APPEND | LOCK_EX);
|
|
}
|
|
|
|
function audit(string $action, string $resource = '', array $detail = []): void {
|
|
try {
|
|
$db = DB::getInstance();
|
|
$auth = Auth::getInstance();
|
|
$user = $auth->user();
|
|
$db->execute(
|
|
"INSERT INTO audit_log (user_id, username, action, resource, detail, ip_address, user_agent)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?)",
|
|
[
|
|
$user['id'] ?? null,
|
|
$user['username'] ?? 'system',
|
|
$action,
|
|
$resource,
|
|
json_encode($detail),
|
|
$_SERVER['REMOTE_ADDR'] ?? '',
|
|
$_SERVER['HTTP_USER_AGENT'] ?? '',
|
|
]
|
|
);
|
|
} catch (Throwable $e) {
|
|
novacpx_log('error', 'audit failed: ' . $e->getMessage());
|
|
}
|
|
}
|