mirror of
https://github.com/getnamingo/registry.git
synced 2025-08-03 08:11:49 +02:00
Added registrar maintenance cron; tmch cleanup
This commit is contained in:
parent
a3b16e4ab9
commit
384204f41b
3 changed files with 98 additions and 0 deletions
|
@ -15,6 +15,9 @@
|
|||
# run auto-approve-transfer.php every hour
|
||||
45 * * * * root /usr/bin/php8.2 /opt/registry/automation/auto-approve-transfer.php
|
||||
|
||||
# run registrar.php every hour
|
||||
35 * * * * root /usr/bin/php8.2 /opt/registry/automation/registrar.php
|
||||
|
||||
# run abusemonitor.php every hour
|
||||
30 * * * * root /usr/bin/php8.2 /opt/registry/automation/abusemonitor.php
|
||||
|
||||
|
|
94
automation/registrar.php
Normal file
94
automation/registrar.php
Normal file
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
$c = require_once 'config.php';
|
||||
require_once 'helpers.php';
|
||||
|
||||
// Connect to the database
|
||||
$dsn = "{$c['db_type']}:host={$c['db_host']};dbname={$c['db_database']};port={$c['db_port']}";
|
||||
$logFilePath = '/var/log/namingo/registrar.log';
|
||||
$log = setupLogger($logFilePath, 'Registrar_Maintenance');
|
||||
$log->info('job started.');
|
||||
|
||||
try {
|
||||
$pdo = new PDO($dsn, $c['db_username'], $c['db_password']);
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
} catch (PDOException $e) {
|
||||
$log->error('DB Connection failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
// Define the query
|
||||
$sql = "SELECT id, clid, accountBalance, creditThreshold, creditLimit FROM registrar";
|
||||
|
||||
try {
|
||||
$stmt = $pdo->query($sql);
|
||||
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
if ($row['accountBalance'] < $row['creditThreshold']) {
|
||||
// Case 1: accountBalance is less than creditThreshold
|
||||
sendEmail($row, 'low_balance');
|
||||
} elseif ($row['accountBalance'] == 0) {
|
||||
// Case 2: accountBalance is 0
|
||||
sendEmail($row, 'zero_balance');
|
||||
} elseif (($row['accountBalance'] + $row['creditLimit']) < 0) {
|
||||
// Case 3: accountBalance + creditLimit is less than 0
|
||||
sendEmail($row, 'over_limit');
|
||||
}
|
||||
}
|
||||
|
||||
$log->info('job finished successfully.');
|
||||
} catch (PDOException $e) {
|
||||
$log->error('Database error: ' . $e->getMessage());
|
||||
} catch (Throwable $e) {
|
||||
$log->error('Error: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
// Function to send email
|
||||
function sendEmail($data, $case) {
|
||||
// Implement the actual email sending logic here
|
||||
switch ($case) {
|
||||
case 'low_balance':
|
||||
$message = "Low balance alert for registrar: " . $data['clid'];
|
||||
break;
|
||||
case 'zero_balance':
|
||||
$message = "Zero balance alert for registrar: " . $data['clid'];
|
||||
break;
|
||||
case 'over_limit':
|
||||
$message = "Over limit alert for registrar: " . $data['clid'];
|
||||
break;
|
||||
default:
|
||||
$message = "Alert for registrar: " . $data['clid'];
|
||||
}
|
||||
|
||||
// Prepare the data array for the cURL request
|
||||
$data = [
|
||||
'type' => 'sendmail',
|
||||
'subject' => $subject,
|
||||
'body' => $body,
|
||||
'toEmail' => $row['billing_email'],
|
||||
];
|
||||
|
||||
$url = 'http://127.0.0.1:8250';
|
||||
|
||||
$options = [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_CUSTOMREQUEST => 'POST',
|
||||
CURLOPT_POSTFIELDS => json_encode($data),
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Content-Type: application/json',
|
||||
'Content-Length: ' . strlen(json_encode($data))
|
||||
],
|
||||
];
|
||||
|
||||
$curl = curl_init($url);
|
||||
curl_setopt_array($curl, $options);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
if ($response === false) {
|
||||
throw new Exception(curl_error($curl), curl_errno($curl));
|
||||
}
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
$log->info('sending email to ' . $data['clid']);
|
||||
}
|
|
@ -73,6 +73,7 @@ try {
|
|||
insertTmchData($dbh, $filePath);
|
||||
}
|
||||
}
|
||||
unlink($filePath);
|
||||
$log->info('job finished successfully.');
|
||||
} catch (PDOException $e) {
|
||||
$log->error('Database error: ' . $e->getMessage());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue