mirror of
https://github.com/getnamingo/registry.git
synced 2025-05-17 10:06:59 +02:00
Added ability to send emails on errors (change required)
Add MAIL_TO_ADDRESS in .env and make sure iana_email is configured.
This commit is contained in:
parent
2adce55a07
commit
4658913847
8 changed files with 14 additions and 211 deletions
12
automation/archive-logs.php
Normal file
12
automation/archive-logs.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
$c = require_once 'config.php';
|
||||
require_once 'helpers.php';
|
||||
|
||||
$logFilePath = '/var/log/namingo/archive-logs.log';
|
||||
$log = setupLogger($logFilePath, 'ARCHIVE_LOGS');
|
||||
$log->info('job started.');
|
||||
|
||||
archiveOldLogs($logFilePath);
|
||||
|
||||
$log->info('job finished successfully.');
|
|
@ -57,6 +57,8 @@ $scheduler->php('/opt/registry/automation/domain-lifecycle-manager.php')->at('*/
|
|||
$scheduler->php('/opt/registry/automation/auto-approve-transfer.php')->at('*/30 * * * *');
|
||||
$scheduler->php('/opt/registry/automation/auto-clean-unused-contact-and-host.php')->at('5 0 * * *');
|
||||
|
||||
$scheduler->php('/opt/registry/automation/archive-logs.php')->at('0 1 1 * *');
|
||||
|
||||
// Conditional Cron Jobs
|
||||
if ($cronJobConfig['accounting']) {
|
||||
$scheduler->php('/opt/registry/automation/send-invoice.php')->at('1 0 1 * *');
|
||||
|
|
|
@ -54,15 +54,6 @@ function setupLogger($logFilePath, $channelName = 'app') {
|
|||
$fileHandler->setFormatter($fileFormatter);
|
||||
$log->pushHandler($fileHandler);
|
||||
|
||||
// Archive logs older than 14 days
|
||||
archiveOldLogs($logFilePath);
|
||||
|
||||
// Pushover Handler (For CRITICAL, ALERT, EMERGENCY)
|
||||
if (!empty($config['pushover_key'])) {
|
||||
$pushoverHandler = new PushoverHandler($config['pushover_key'], Logger::ALERT);
|
||||
$log->pushHandler($pushoverHandler);
|
||||
}
|
||||
|
||||
// Email Handler (For CRITICAL, ALERT, EMERGENCY)
|
||||
if (!empty($config['mailer_smtp_host'])) {
|
||||
// Create a PHPMailer instance
|
||||
|
|
|
@ -69,16 +69,6 @@ class Logger extends \Monolog\Logger
|
|||
$fileHandler->setFormatter($fileFormatter);
|
||||
$this->pushHandler($fileHandler);
|
||||
|
||||
// Pushover Alerts (For CRITICAL, ALERT, EMERGENCY)
|
||||
if (!empty($_ENV['PUSHOVER_KEY'])) {
|
||||
try {
|
||||
$pushoverHandler = new PushoverHandler($_ENV['PUSHOVER_KEY'], \Monolog\Logger::ALERT);
|
||||
$this->pushHandler($pushoverHandler);
|
||||
} catch (\Exception $e) {
|
||||
error_log("PushoverHandler failed: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Email Alerts (For CRITICAL, ALERT, EMERGENCY)
|
||||
if (!empty($_ENV['MAIL_HOST'])) {
|
||||
try {
|
||||
|
|
|
@ -46,15 +46,6 @@ function setupLogger($logFilePath, $channelName = 'app') {
|
|||
$fileHandler->setFormatter($fileFormatter);
|
||||
$log->pushHandler($fileHandler);
|
||||
|
||||
// Archive logs older than 14 days
|
||||
archiveOldLogs($logFilePath);
|
||||
|
||||
// Pushover Handler (For CRITICAL, ALERT, EMERGENCY)
|
||||
if (!empty($config['pushover_key'])) {
|
||||
$pushoverHandler = new PushoverHandler($config['pushover_key'], Logger::ALERT);
|
||||
$log->pushHandler($pushoverHandler);
|
||||
}
|
||||
|
||||
// Email Handler (For CRITICAL, ALERT, EMERGENCY)
|
||||
if (!empty($config['mailer_smtp_host'])) {
|
||||
// Create a PHPMailer instance
|
||||
|
@ -85,45 +76,6 @@ function setupLogger($logFilePath, $channelName = 'app') {
|
|||
return $log;
|
||||
}
|
||||
|
||||
function archiveOldLogs($logFilePath) {
|
||||
$logDir = dirname($logFilePath);
|
||||
$backupDir = '/opt/backup';
|
||||
$lockFile = $backupDir . '/log_archive.lock';
|
||||
|
||||
// Prevent multiple processes from running archive at the same time
|
||||
if (file_exists($lockFile)) {
|
||||
return; // Another process is already archiving
|
||||
}
|
||||
touch($lockFile); // Create lock file
|
||||
|
||||
if (!is_dir($backupDir)) {
|
||||
mkdir($backupDir, 0755, true);
|
||||
}
|
||||
|
||||
$logFiles = glob($logDir . '/*.log'); // Get all log files
|
||||
$thresholdDate = strtotime('-14 days'); // Logs older than 14 days
|
||||
|
||||
foreach ($logFiles as $file) {
|
||||
if (filemtime($file) < $thresholdDate) {
|
||||
$filename = basename($file);
|
||||
$monthYear = date('F-Y', filemtime($file));
|
||||
$zipPath = $backupDir . "/logs-{$monthYear}.zip";
|
||||
|
||||
// Open or create ZIP archive
|
||||
$zip = new ZipArchive();
|
||||
if ($zip->open($zipPath, ZipArchive::CREATE) === true) {
|
||||
if (!$zip->locateName($filename)) { // Prevent duplicate addition
|
||||
$zip->addFile($file, $filename);
|
||||
unlink($file); // Delete original log after archiving
|
||||
}
|
||||
$zip->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unlink($lockFile); // Remove lock when done
|
||||
}
|
||||
|
||||
function isIpWhitelisted($ip, $pdo) {
|
||||
$stmt = $pdo->prepare("SELECT COUNT(*) FROM registrar_whitelist WHERE addr = ?");
|
||||
$stmt->execute([$ip]);
|
||||
|
|
|
@ -57,15 +57,6 @@ function setupLogger($logFilePath, $channelName = 'app') {
|
|||
$fileHandler->setFormatter($fileFormatter);
|
||||
$log->pushHandler($fileHandler);
|
||||
|
||||
// Archive logs older than 14 days
|
||||
archiveOldLogs($logFilePath);
|
||||
|
||||
// Pushover Handler (For CRITICAL, ALERT, EMERGENCY)
|
||||
if (!empty($config['pushover_key'])) {
|
||||
$pushoverHandler = new PushoverHandler($config['pushover_key'], Logger::ALERT);
|
||||
$log->pushHandler($pushoverHandler);
|
||||
}
|
||||
|
||||
// Email Handler (For CRITICAL, ALERT, EMERGENCY)
|
||||
if (!empty($config['mailer_smtp_host'])) {
|
||||
// Create a PHPMailer instance
|
||||
|
@ -96,45 +87,6 @@ function setupLogger($logFilePath, $channelName = 'app') {
|
|||
return $log;
|
||||
}
|
||||
|
||||
function archiveOldLogs($logFilePath) {
|
||||
$logDir = dirname($logFilePath);
|
||||
$backupDir = '/opt/backup';
|
||||
$lockFile = $backupDir . '/log_archive.lock';
|
||||
|
||||
// Prevent multiple processes from running archive at the same time
|
||||
if (file_exists($lockFile)) {
|
||||
return; // Another process is already archiving
|
||||
}
|
||||
touch($lockFile); // Create lock file
|
||||
|
||||
if (!is_dir($backupDir)) {
|
||||
mkdir($backupDir, 0755, true);
|
||||
}
|
||||
|
||||
$logFiles = glob($logDir . '/*.log'); // Get all log files
|
||||
$thresholdDate = strtotime('-14 days'); // Logs older than 14 days
|
||||
|
||||
foreach ($logFiles as $file) {
|
||||
if (filemtime($file) < $thresholdDate) {
|
||||
$filename = basename($file);
|
||||
$monthYear = date('F-Y', filemtime($file));
|
||||
$zipPath = $backupDir . "/logs-{$monthYear}.zip";
|
||||
|
||||
// Open or create ZIP archive
|
||||
$zip = new ZipArchive();
|
||||
if ($zip->open($zipPath, ZipArchive::CREATE) === true) {
|
||||
if (!$zip->locateName($filename)) { // Prevent duplicate addition
|
||||
$zip->addFile($file, $filename);
|
||||
unlink($file); // Delete original log after archiving
|
||||
}
|
||||
$zip->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unlink($lockFile); // Remove lock when done
|
||||
}
|
||||
|
||||
function checkLogin($db, $clID, $pw) {
|
||||
$stmt = $db->prepare("SELECT pw FROM registrar WHERE clid = :username");
|
||||
$stmt->execute(['username' => $clID]);
|
||||
|
|
|
@ -46,15 +46,6 @@ function setupLogger($logFilePath, $channelName = 'app') {
|
|||
$fileHandler->setFormatter($fileFormatter);
|
||||
$log->pushHandler($fileHandler);
|
||||
|
||||
// Archive logs older than 14 days
|
||||
archiveOldLogs($logFilePath);
|
||||
|
||||
// Pushover Handler (For CRITICAL, ALERT, EMERGENCY)
|
||||
if (!empty($config['pushover_key'])) {
|
||||
$pushoverHandler = new PushoverHandler($config['pushover_key'], Logger::ALERT);
|
||||
$log->pushHandler($pushoverHandler);
|
||||
}
|
||||
|
||||
// Email Handler (For CRITICAL, ALERT, EMERGENCY)
|
||||
if (!empty($config['mailer_smtp_host'])) {
|
||||
// Create a PHPMailer instance
|
||||
|
@ -85,45 +76,6 @@ function setupLogger($logFilePath, $channelName = 'app') {
|
|||
return $log;
|
||||
}
|
||||
|
||||
function archiveOldLogs($logFilePath) {
|
||||
$logDir = dirname($logFilePath);
|
||||
$backupDir = '/opt/backup';
|
||||
$lockFile = $backupDir . '/log_archive.lock';
|
||||
|
||||
// Prevent multiple processes from running archive at the same time
|
||||
if (file_exists($lockFile)) {
|
||||
return; // Another process is already archiving
|
||||
}
|
||||
touch($lockFile); // Create lock file
|
||||
|
||||
if (!is_dir($backupDir)) {
|
||||
mkdir($backupDir, 0755, true);
|
||||
}
|
||||
|
||||
$logFiles = glob($logDir . '/*.log'); // Get all log files
|
||||
$thresholdDate = strtotime('-14 days'); // Logs older than 14 days
|
||||
|
||||
foreach ($logFiles as $file) {
|
||||
if (filemtime($file) < $thresholdDate) {
|
||||
$filename = basename($file);
|
||||
$monthYear = date('F-Y', filemtime($file));
|
||||
$zipPath = $backupDir . "/logs-{$monthYear}.zip";
|
||||
|
||||
// Open or create ZIP archive
|
||||
$zip = new ZipArchive();
|
||||
if ($zip->open($zipPath, ZipArchive::CREATE) === true) {
|
||||
if (!$zip->locateName($filename)) { // Prevent duplicate addition
|
||||
$zip->addFile($file, $filename);
|
||||
unlink($file); // Delete original log after archiving
|
||||
}
|
||||
$zip->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unlink($lockFile); // Remove lock when done
|
||||
}
|
||||
|
||||
function mapContactToVCard($contactDetails, $role, $c) {
|
||||
// Determine which type of disclosure to use
|
||||
$disclose_name = ($contactDetails['type'] == 'loc') ? $contactDetails['disclose_name_loc'] : $contactDetails['disclose_name_int'];
|
||||
|
|
|
@ -46,15 +46,6 @@ function setupLogger($logFilePath, $channelName = 'app') {
|
|||
$fileHandler->setFormatter($fileFormatter);
|
||||
$log->pushHandler($fileHandler);
|
||||
|
||||
// Archive logs older than 14 days
|
||||
archiveOldLogs($logFilePath);
|
||||
|
||||
// Pushover Handler (For CRITICAL, ALERT, EMERGENCY)
|
||||
if (!empty($config['pushover_key'])) {
|
||||
$pushoverHandler = new PushoverHandler($config['pushover_key'], Logger::ALERT);
|
||||
$log->pushHandler($pushoverHandler);
|
||||
}
|
||||
|
||||
// Email Handler (For CRITICAL, ALERT, EMERGENCY)
|
||||
if (!empty($config['mailer_smtp_host'])) {
|
||||
// Create a PHPMailer instance
|
||||
|
@ -85,45 +76,6 @@ function setupLogger($logFilePath, $channelName = 'app') {
|
|||
return $log;
|
||||
}
|
||||
|
||||
function archiveOldLogs($logFilePath) {
|
||||
$logDir = dirname($logFilePath);
|
||||
$backupDir = '/opt/backup';
|
||||
$lockFile = $backupDir . '/log_archive.lock';
|
||||
|
||||
// Prevent multiple processes from running archive at the same time
|
||||
if (file_exists($lockFile)) {
|
||||
return; // Another process is already archiving
|
||||
}
|
||||
touch($lockFile); // Create lock file
|
||||
|
||||
if (!is_dir($backupDir)) {
|
||||
mkdir($backupDir, 0755, true);
|
||||
}
|
||||
|
||||
$logFiles = glob($logDir . '/*.log'); // Get all log files
|
||||
$thresholdDate = strtotime('-14 days'); // Logs older than 14 days
|
||||
|
||||
foreach ($logFiles as $file) {
|
||||
if (filemtime($file) < $thresholdDate) {
|
||||
$filename = basename($file);
|
||||
$monthYear = date('F-Y', filemtime($file));
|
||||
$zipPath = $backupDir . "/logs-{$monthYear}.zip";
|
||||
|
||||
// Open or create ZIP archive
|
||||
$zip = new ZipArchive();
|
||||
if ($zip->open($zipPath, ZipArchive::CREATE) === true) {
|
||||
if (!$zip->locateName($filename)) { // Prevent duplicate addition
|
||||
$zip->addFile($file, $filename);
|
||||
unlink($file); // Delete original log after archiving
|
||||
}
|
||||
$zip->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unlink($lockFile); // Remove lock when done
|
||||
}
|
||||
|
||||
function parseQuery($data) {
|
||||
$data = trim($data);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue