fetchOne("SELECT `value` FROM settings WHERE `key` = ?", [$key]); return $row['value'] ?? ''; } private static function send(string $to, string $subject, string $html): bool { $apiKey = self::getSetting('cybermail_api_key'); $fromEmail = self::getSetting('notify_from_email') ?: 'noreply@novacpx.local'; $fromName = self::getSetting('notify_from_name') ?: 'NovaCPX Panel'; if (!$apiKey || !$to) return false; $payload = json_encode([ 'from' => $fromEmail, 'to' => $to, 'subject' => $subject, 'html' => $html, 'text' => strip_tags(str_replace(['
', '
', '
'], "\n", $html)), ]); $ch = curl_init('https://platform.cyberpersons.com/email/v1/send'); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $payload, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . $apiKey, 'Content-Type: application/json', ], CURLOPT_TIMEOUT => 10, CURLOPT_SSL_VERIFYPEER => true, ]); $body = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return $code === 202; } private static function adminEmail(): string { return self::getSetting('notify_admin_email'); } private static function notificationsEnabled(): bool { return self::getSetting('notifications_enabled') !== '0'; } // ── Triggers ────────────────────────────────────────────────────────────── public static function accountCreated(array $account, string $password): void { if (!self::notificationsEnabled()) return; $user = $account['username']; $domain = $account['domain']; $email = $account['email'] ?? ''; $panel = 'https://' . ($_SERVER['HTTP_HOST'] ?? 'your-panel'); // Notify the new user if ($email) { self::send($email, "Welcome to NovaCPX — your account is ready", "

Welcome, {$user}!

Your hosting account has been created.

Domain:{$domain}
Username:{$user}
Password:{$password}
Panel:{$panel}

Please change your password after first login.

" ); } // Notify admin $adminEmail = self::adminEmail(); if ($adminEmail) { self::send($adminEmail, "NovaCPX: New account created — {$domain}", "

A new hosting account was created:

Domain:{$domain}
Username:{$user}
Email:{$email}
" ); } } public static function accountSuspended(array $account, string $reason = ''): void { if (!self::notificationsEnabled()) return; $user = $account['username'] ?? 'unknown'; $domain = $account['domain'] ?? 'unknown'; $email = $account['email'] ?? ''; $why = $reason ?: 'No reason provided'; // Notify account holder if ($email) { self::send($email, "Your hosting account has been suspended", "

Account Suspended

Your hosting account {$domain} has been suspended.

Reason: {$why}

Please contact support to resolve this issue.

" ); } // Notify admin $adminEmail = self::adminEmail(); if ($adminEmail) { self::send($adminEmail, "NovaCPX: Account suspended — {$domain}", "

Account {$domain} (user: {$user}) was suspended.

Reason: {$why}

" ); } } public static function diskQuotaWarning(array $account, int $usedMb, int $limitMb): void { if (!self::notificationsEnabled()) return; $pct = $limitMb > 0 ? round($usedMb / $limitMb * 100) : 0; $domain = $account['domain'] ?? 'unknown'; $email = $account['email'] ?? ''; if ($email) { self::send($email, "Disk quota warning — {$domain} is at {$pct}%", "

Disk Quota Warning

Your hosting account {$domain} has used {$pct}% of its disk quota.

Usage: {$usedMb} MB of {$limitMb} MB

Please free up space or contact support to upgrade your plan.

" ); } $adminEmail = self::adminEmail(); if ($adminEmail) { self::send($adminEmail, "NovaCPX: Disk quota warning — {$domain} at {$pct}%", "

Account {$domain} is at {$pct}% disk usage ({$usedMb} MB / {$limitMb} MB).

" ); } } public static function sslExpiring(string $domain, string $email, int $daysLeft): void { if (!self::notificationsEnabled()) return; if ($email) { self::send($email, "SSL certificate expiring in {$daysLeft} days — {$domain}", "

SSL Certificate Expiry Notice

The SSL certificate for {$domain} will expire in {$daysLeft} days.

Please renew your certificate to avoid service interruption.

" ); } $adminEmail = self::adminEmail(); if ($adminEmail) { self::send($adminEmail, "NovaCPX: SSL expiring in {$daysLeft} days — {$domain}", "

SSL for {$domain} expires in {$daysLeft} days. Account email: {$email}

" ); } } }