mirror of
https://github.com/myronblair/novacpx
synced 2026-06-30 17:50:41 -05:00
e3b166803a
- 14 API endpoints: accounts, packages, domains, dns, email, databases, ftp, ssl, cron, php, files, stats, webmail, server_setup - 8 lib managers: AccountManager, VhostManager, DNSManager, EmailManager, DatabaseManager, PHPManager, FTPManager, SSLManager - Roundcube webmail on dedicated port 8883 (sequenced after 8880/8881/8882) - Custom NovaCPX SVG icon sprite (30+ unique icons), logo, mark, favicon - PORT_WEBMAIL=8883 wired into Core.php, install.sh, UFW, Fail2Ban, credentials file Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
63 lines
2.9 KiB
PHP
63 lines
2.9 KiB
PHP
<?php
|
|
$db = DB::getInstance();
|
|
$body = json_decode(file_get_contents('php://input'), true) ?? [];
|
|
require_once NOVACPX_LIB . '/SSLManager.php';
|
|
require_once NOVACPX_LIB . '/VhostManager.php';
|
|
|
|
$user = Auth::getInstance()->user();
|
|
$accountId = $user['role'] === 'user'
|
|
? (int)($db->fetchOne("SELECT id FROM accounts WHERE user_id = ?", [$user['uid']])['id'] ?? 0)
|
|
: (int)($body['account_id'] ?? $_GET['account_id'] ?? 0);
|
|
|
|
match ($action) {
|
|
'list' => (function() use ($db, $accountId) {
|
|
$rows = $db->fetchAll("SELECT id, domain, type, issued_at, expires_at, auto_renew, status FROM ssl_certs WHERE account_id = ? ORDER BY domain", [$accountId]);
|
|
foreach ($rows as &$r) {
|
|
$r['days_remaining'] = $r['expires_at'] ? (int)floor((strtotime($r['expires_at']) - time()) / 86400) : null;
|
|
}
|
|
Response::success($rows);
|
|
})(),
|
|
|
|
'issue' => (function() use ($body, $accountId) {
|
|
$domain = trim($body['domain'] ?? '');
|
|
$email = trim($body['email'] ?? '');
|
|
if (!$domain) Response::error("domain required");
|
|
if (!$accountId) Response::error("account_id required");
|
|
$result = SSLManager::issueLetsEncrypt($accountId, $domain, $email);
|
|
audit('ssl.issue', $domain);
|
|
Response::success($result, "SSL certificate issued for $domain");
|
|
})(),
|
|
|
|
'install-custom' => (function() use ($body, $accountId) {
|
|
$domain = trim($body['domain'] ?? '');
|
|
$cert = trim($body['cert'] ?? '');
|
|
$key = trim($body['key'] ?? '');
|
|
$chain = trim($body['chain'] ?? '');
|
|
if (!$domain || !$cert || !$key) Response::error("domain, cert, and key required");
|
|
$id = SSLManager::installCustom($accountId, $domain, $cert, $key, $chain);
|
|
audit('ssl.install-custom', $domain);
|
|
Response::success(['id' => $id], 'Custom certificate installed');
|
|
})(),
|
|
|
|
'renew' => (function() use ($db, $body, $accountId) {
|
|
$certId = (int)($body['cert_id'] ?? 0);
|
|
$cert = $db->fetchOne("SELECT * FROM ssl_certs WHERE id = ? AND account_id = ?", [$certId, $accountId]);
|
|
if (!$cert) Response::error("Certificate not found", 404);
|
|
$result = SSLManager::issueLetsEncrypt($accountId, $cert['domain']);
|
|
audit('ssl.renew', $cert['domain']);
|
|
Response::success($result, 'Certificate renewed');
|
|
})(),
|
|
|
|
'delete' => (function() use ($db, $body, $accountId) {
|
|
$certId = (int)($body['cert_id'] ?? 0);
|
|
$cert = $db->fetchOne("SELECT * FROM ssl_certs WHERE id = ? AND account_id = ?", [$certId, $accountId]);
|
|
if (!$cert) Response::error("Certificate not found", 404);
|
|
$db->execute("DELETE FROM ssl_certs WHERE id = ?", [$certId]);
|
|
$db->execute("UPDATE domains SET ssl_enabled = 0 WHERE domain = ?", [$cert['domain']]);
|
|
audit('ssl.delete', $cert['domain']);
|
|
Response::success(null, 'Certificate removed');
|
|
})(),
|
|
|
|
default => Response::error("Unknown ssl action: $action", 404),
|
|
};
|