setFormatter($consoleFormatter); $log->pushHandler($consoleHandler); // File handler - Rotates daily, keeps logs for 14 days $fileHandler = new RotatingFileHandler($logFilePath, 14, Logger::DEBUG); $fileFormatter = new LineFormatter( "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n", "Y-m-d H:i:s.u" ); $fileHandler->setFormatter($fileFormatter); $log->pushHandler($fileHandler); // Email Handler (For CRITICAL, ALERT, EMERGENCY) if (!empty($config['mailer_smtp_host'])) { // Create a PHPMailer instance $mail = new PHPMailer(true); try { $mail->isSMTP(); $mail->Host = $config['mailer_smtp_host']; $mail->SMTPAuth = true; $mail->Username = $config['mailer_smtp_username']; $mail->Password = $config['mailer_smtp_password']; $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $mail->Port = $config['mailer_smtp_port']; $mail->setFrom($config['mailer_from'], 'Registry System'); $mail->addAddress($config['admin_email']); // Attach PHPMailer to Monolog $mailerHandler = new PHPMailerHandler($mail); $mailerHandler->setFormatter(new HtmlFormatter); $filteredMailHandler = new FilterHandler($mailerHandler, Logger::ALERT, Logger::EMERGENCY); $safeMailHandler = new WhatFailureGroupHandler([$filteredMailHandler]); $log->pushHandler($safeMailHandler); } catch (Exception $e) { error_log("Failed to initialize PHPMailer: " . $e->getMessage()); } } return $log; } function isIpWhitelisted($ip, $pdo) { $stmt = $pdo->prepare("SELECT COUNT(*) FROM registrar_whitelist WHERE addr = :ip"); $stmt->execute(['ip' => $ip]); $count = $stmt->fetchColumn(); return $count > 0; } // Function to update the permitted IPs from the database function updatePermittedIPs($pool, $permittedIPsTable) { $pdo = $pool->get(); $query = "SELECT addr FROM registrar_whitelist"; $stmt = $pdo->query($query); $permittedIPs = $stmt->fetchAll(PDO::FETCH_COLUMN, 0); $pool->put($pdo); // Manually clear the table by removing each entry foreach ($permittedIPsTable as $key => $value) { $permittedIPsTable->del($key); } // Insert new values foreach ($permittedIPs as $ip) { $permittedIPsTable->set($ip, ['addr' => $ip]); } }