mirror of
https://github.com/getnamingo/registry.git
synced 2025-08-05 17:18:04 +02:00
Added Monolog for automation scripts
This commit is contained in:
parent
e609b3f84d
commit
9d5078270a
13 changed files with 203 additions and 121 deletions
|
@ -5,12 +5,15 @@ 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/auto_approve_transfer.log';
|
||||
$log = setupLogger($logFilePath, 'Auto_Approve_Transfer');
|
||||
$log->info('job started.');
|
||||
|
||||
try {
|
||||
$dbh = new PDO($dsn, $c['db_username'], $c['db_password']);
|
||||
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
} catch (PDOException $e) {
|
||||
die("Connection failed: " . $e->getMessage());
|
||||
$log->error('DB Connection failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
$query_domain = "SELECT id, name, registrant, crdate, exdate, `update`, clid, crid, upid, trdate, trstatus, reid, redate, acid, acdate, transfer_exdate FROM domain WHERE CURRENT_TIMESTAMP > acdate AND trstatus = 'pending'";
|
||||
|
@ -47,8 +50,7 @@ while ($row = $stmt_domain->fetch(PDO::FETCH_ASSOC)) {
|
|||
[$price] = $dbh->query("SELECT m$date_add FROM domain_price WHERE tldid = '$tld_id' AND command = 'transfer' LIMIT 1")->fetch(PDO::FETCH_NUM);
|
||||
|
||||
if (($registrar_balance + $creditLimit) < $price) {
|
||||
$echo = 'The registrar who took over this domain has no money to pay the renewal period that resulted from the transfer request';
|
||||
shell_exec("echo '$name - $echo' >> /var/log/epp/domain_auto_approve_transfer.log");
|
||||
$log->notice($name . ': The registrar who took over this domain has no money to pay the renewal period that resulted from the transfer request');
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -62,9 +64,7 @@ while ($row = $stmt_domain->fetch(PDO::FETCH_ASSOC)) {
|
|||
$stmt_update_host->execute();
|
||||
|
||||
if ($stmt_update->errorCode() != "00000") {
|
||||
$err = 'UPDATE failed: ' . implode(", ", $stmt_update->errorInfo());
|
||||
$echo = "The transfer was not successful, something is wrong | $err";
|
||||
shell_exec("echo '$name - $echo' >> /var/log/epp/domain_auto_approve_transfer.log");
|
||||
$log->error($name . ': The domain transfer was not successful, something is wrong | DB Update failed:' . implode(", ", $stmt_update->errorInfo()));
|
||||
continue;
|
||||
} else {
|
||||
$dbh->exec("UPDATE registrar SET accountBalance = (accountBalance - $price) WHERE id = '$reid'");
|
||||
|
@ -98,9 +98,7 @@ while ($contact_data = $stmt_contact->fetch(PDO::FETCH_ASSOC)) {
|
|||
$stmt_update_contact->execute([$reid, $contact_id]);
|
||||
|
||||
if ($stmt_update_contact->errorCode() != "00000") {
|
||||
$err = 'UPDATE failed: ' . implode(", ", $stmt_update_contact->errorInfo());
|
||||
$echo = "The transfer was not successful, something is wrong | $err";
|
||||
shell_exec("echo '$contact_id - $echo' >> /var/log/epp/contact_auto_approve_transfer.log");
|
||||
$log->error($contact_id . ': The contact transfer was not successful, something is wrong | DB Update failed:' . implode(", ", $stmt_update_contact->errorInfo()));
|
||||
continue;
|
||||
} else {
|
||||
$stmt_select_contact = $dbh->prepare("SELECT identifier, crid, crdate, upid, `update`, trdate, trstatus, reid, redate, acid, acdate FROM contact WHERE id = ? LIMIT 1");
|
||||
|
@ -112,3 +110,4 @@ while ($contact_data = $stmt_contact->fetch(PDO::FETCH_ASSOC)) {
|
|||
}
|
||||
}
|
||||
$stmt_contact = null;
|
||||
$log->info('job finished successfully.');
|
|
@ -5,12 +5,15 @@ 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/auto_clean_unused_contact_and_host.log';
|
||||
$log = setupLogger($logFilePath, 'Auto_Clean_Unused_Contact_And_Host');
|
||||
$log->info('job started.');
|
||||
|
||||
try {
|
||||
$dbh = new PDO($dsn, $c['db_username'], $c['db_password']);
|
||||
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
} catch (PDOException $e) {
|
||||
die("Connection failed: " . $e->getMessage());
|
||||
$log->error('DB Connection failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -53,11 +56,13 @@ try {
|
|||
$dbh->prepare("DELETE FROM contact_authInfo WHERE contact_id IN ($placeholders)")->execute($contact_ids);
|
||||
$dbh->prepare("DELETE FROM contact WHERE id IN ($placeholders)")->execute($contact_ids);
|
||||
}
|
||||
|
||||
$log->info('job finished successfully.');
|
||||
|
||||
} catch (PDOException $e) {
|
||||
// Handle database errors
|
||||
die("Database error: " . $e->getMessage());
|
||||
$log->error('Database error: ' . $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
// Handle other types of errors
|
||||
die("Error: " . $e->getMessage());
|
||||
$log->error('Error: ' . $e->getMessage());
|
||||
}
|
|
@ -5,12 +5,15 @@ 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/change_domain_status.log';
|
||||
$log = setupLogger($logFilePath, 'Change_Domain_Status');
|
||||
$log->info('job started.');
|
||||
|
||||
try {
|
||||
$dbh = new PDO($dsn, $c['db_username'], $c['db_password']);
|
||||
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
} catch (PDOException $e) {
|
||||
die("Connection failed: " . $e->getMessage());
|
||||
$log->error('DB Connection failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
// Auto-Renew Grace Period
|
||||
|
@ -59,8 +62,7 @@ if ($auto_renew) {
|
|||
$dbh->exec("INSERT INTO domain_status (domain_id, status) VALUES('$domain_id', 'pendingDelete')");
|
||||
}
|
||||
}
|
||||
$currentDateTime = new DateTime();
|
||||
echo $currentDateTime->format("Y-m-d H:i:s.v") . " - $domain_id\t|\t$name\t|\trgpStatus:autoRenewPeriod exdate:$exdate\n";
|
||||
$log->info($name . ' (ID ' . $domain_id . ') rgpStatus:autoRenewPeriod exdate: ' . $exdate);
|
||||
}
|
||||
} else {
|
||||
$grace_period = 30;
|
||||
|
@ -88,8 +90,7 @@ if ($auto_renew) {
|
|||
$dbh->exec("UPDATE domain SET rgpstatus = 'redemptionPeriod', delTime = DATE_ADD(exdate, INTERVAL $grace_period DAY) WHERE id = '$domain_id'");
|
||||
$dbh->exec("INSERT INTO domain_status (domain_id, status) VALUES('$domain_id', 'pendingDelete')");
|
||||
}
|
||||
$currentDateTime = new DateTime();
|
||||
echo $currentDateTime->format("Y-m-d H:i:s.v") . " - $domain_id\t|\t$name\t|\trgpStatus:redemptionPeriod exdate:$exdate\n";
|
||||
$log->info($name . ' (ID ' . $domain_id . ') rgpStatus:redemptionPeriod exdate: ' . $exdate);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,7 +112,7 @@ try {
|
|||
$dbh->exec($sql4);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
die("Error: " . $e->getMessage());
|
||||
$log->error('DB Error: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
// Pending Delete
|
||||
|
@ -139,8 +140,7 @@ while ($row = $sth_pendingdelete->fetch(PDO::FETCH_ASSOC)) {
|
|||
if ($set_pendingDelete) {
|
||||
$dbh->exec("UPDATE domain SET rgpstatus = 'pendingDelete' WHERE id = '$domain_id'");
|
||||
}
|
||||
$currentDateTime = new DateTime();
|
||||
echo $currentDateTime->format("Y-m-d H:i:s.v") . " - $domain_id\t|\t$name\t|\trgpStatus:pendingDelete exdate:$exdate\n";
|
||||
$log->info($name . ' (ID ' . $domain_id . ') rgpStatus:pendingDelete exdate: ' . $exdate);
|
||||
}
|
||||
|
||||
// Pending Restore
|
||||
|
@ -153,9 +153,8 @@ while ($row = $sth_pendingRestore->fetch(PDO::FETCH_ASSOC)) {
|
|||
$exdate = $row['exdate'];
|
||||
|
||||
$dbh->exec("UPDATE domain SET rgpstatus = 'redemptionPeriod' WHERE id = '$domain_id'");
|
||||
|
||||
$currentDateTime = new DateTime();
|
||||
echo $currentDateTime->format("Y-m-d H:i:s.v") . " - $domain_id\t|\t$name\t|\tback to redemptionPeriod from pendingRestore exdate:$exdate\n";
|
||||
|
||||
$log->info($name . ' (ID ' . $domain_id . ') back to redemptionPeriod from pendingRestore exdate: ' . $exdate);
|
||||
}
|
||||
|
||||
// Domain Deletion
|
||||
|
@ -203,7 +202,7 @@ while ($row = $sth_delete->fetch(PDO::FETCH_ASSOC)) {
|
|||
$sth->execute([$domain_id]);
|
||||
if ($sth->errorCode() !== '00000') {
|
||||
$errorInfo = $sth->errorInfo();
|
||||
echo 'Numele de domeniu nu a fost sters cred ca este vre-o legatura cu alte obiecte: ' . $errorInfo[2];
|
||||
$log->error($domain_id . '|' . $name . ' The domain name has not been deleted, there is a database issue: ' . $errorInfo[2]);
|
||||
} else {
|
||||
if (!$dbh->query("SELECT id FROM statistics WHERE date = CURDATE()")->fetchColumn()) {
|
||||
$dbh->exec("INSERT IGNORE INTO statistics (date) VALUES(CURDATE())");
|
||||
|
@ -211,6 +210,6 @@ while ($row = $sth_delete->fetch(PDO::FETCH_ASSOC)) {
|
|||
$dbh->exec("UPDATE statistics SET deleted_domains = deleted_domains + 1 WHERE date = CURDATE()");
|
||||
}
|
||||
}
|
||||
$currentDateTime = new DateTime();
|
||||
echo $currentDateTime->format("Y-m-d H:i:s.v") . " - $domain_id\t|\t$name\t|\tdomain:Deleted exdate:$exdate\n";
|
||||
}
|
||||
$log->info($name . ' (ID ' . $domain_id . ') domain:Deleted exdate: ' . $exdate);
|
||||
}
|
||||
$log->info('job finished successfully.');
|
9
automation/composer.json
Normal file
9
automation/composer.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"require": {
|
||||
"badcow/dns": "^4.2",
|
||||
"phpseclib/phpseclib": "^3.0",
|
||||
"phpbu/phpbu": "^6.0",
|
||||
"setbased/php-audit": "^1.9",
|
||||
"monolog/monolog": "^3.5"
|
||||
}
|
||||
}
|
|
@ -13,11 +13,14 @@ $options = [
|
|||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
];
|
||||
$logFilePath = '/var/log/namingo/escrow.log';
|
||||
$log = setupLogger($logFilePath, 'Escrow');
|
||||
$log->info('job started.');
|
||||
|
||||
try {
|
||||
$dbh = new PDO($dsn, $c['db_username'], $c['db_password'], $options);
|
||||
} catch (PDOException $e) {
|
||||
die("Connection failed: " . $e->getMessage());
|
||||
$log->error('DB Connection failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
$domainCount = fetchCount($dbh, 'domain');
|
||||
|
@ -327,7 +330,7 @@ foreach ($tlds as $tld) {
|
|||
$encryptedData = gnupg_encrypt($res, $fileData);
|
||||
|
||||
if (!$encryptedData) {
|
||||
die("Error encrypting data: " . gnupg_geterror($res));
|
||||
$log->error('Error encrypting data: ' . gnupg_geterror($res));
|
||||
}
|
||||
|
||||
// Save the encrypted data to a new file
|
||||
|
@ -436,7 +439,7 @@ foreach ($tlds as $tld) {
|
|||
|
||||
// Login with username and password
|
||||
if (!$sftp->login($c['escrow_sftp_username'], $c['escrow_sftp_password'])) {
|
||||
die('Login failed');
|
||||
$log->error('SFTP Login failed');
|
||||
}
|
||||
|
||||
// Define the remote directory where you want to upload the files
|
||||
|
@ -452,9 +455,9 @@ foreach ($tlds as $tld) {
|
|||
foreach ($filesToUpload as $filePath) {
|
||||
$remoteFile = $remoteDir . basename($filePath);
|
||||
if (!$sftp->put($remoteFile, $filePath, SFTP::SOURCE_LOCAL_FILE)) {
|
||||
echo "Failed to upload " . basename($filePath) . "\n";
|
||||
$log->error('Failed to upload ' . basename($filePath));
|
||||
} else {
|
||||
echo "Successfully uploaded " . basename($filePath) . "\n";
|
||||
$log->info('Successfully uploaded ' . basename($filePath));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -476,18 +479,19 @@ foreach ($tlds as $tld) {
|
|||
$response = curl_exec($ch);
|
||||
|
||||
if ($response === false) {
|
||||
die('Error occurred: ' . curl_error($ch));
|
||||
$log->error('Upload error occurred: ' . curl_error($ch));
|
||||
}
|
||||
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if ($httpCode >= 200 && $httpCode < 300) {
|
||||
echo "File uploaded successfully.\n";
|
||||
$log->info('Escrow deposit uploaded successfully');
|
||||
} else {
|
||||
echo "Failed to upload file. HTTP Status Code: " . $httpCode . "\n";
|
||||
$log->error('Failed to upload escrow deposit. HTTP Status Code: ' . $httpCode);
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
$log->info('job finished successfully.');
|
|
@ -1,5 +1,46 @@
|
|||
<?php
|
||||
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
use Monolog\Logger;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Handler\RotatingFileHandler;
|
||||
use Monolog\Formatter\LineFormatter;
|
||||
|
||||
/**
|
||||
* Sets up and returns a Logger instance.
|
||||
*
|
||||
* @param string $logFilePath Full path to the log file.
|
||||
* @param string $channelName Name of the log channel (optional).
|
||||
* @return Logger
|
||||
*/
|
||||
function setupLogger($logFilePath, $channelName = 'app') {
|
||||
// Create a log channel
|
||||
$log = new Logger($channelName);
|
||||
|
||||
// Set up the console handler
|
||||
$consoleHandler = new StreamHandler('php://stdout', Logger::DEBUG);
|
||||
$consoleFormatter = new LineFormatter(
|
||||
"[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n",
|
||||
"Y-m-d H:i:s.u", // Date format
|
||||
true, // Allow inline line breaks
|
||||
true // Ignore empty context and extra
|
||||
);
|
||||
$consoleHandler->setFormatter($consoleFormatter);
|
||||
$log->pushHandler($consoleHandler);
|
||||
|
||||
// Set up the file handler
|
||||
$fileHandler = new RotatingFileHandler($logFilePath, 0, Logger::DEBUG);
|
||||
$fileFormatter = new LineFormatter(
|
||||
"[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n",
|
||||
"Y-m-d H:i:s.u" // Date format
|
||||
);
|
||||
$fileHandler->setFormatter($fileFormatter);
|
||||
$log->pushHandler($fileHandler);
|
||||
|
||||
return $log;
|
||||
}
|
||||
|
||||
function fetchCount($pdo, $tableName) {
|
||||
$stmt = $pdo->prepare("SELECT count(id) AS count FROM {$tableName};");
|
||||
$stmt->execute();
|
||||
|
|
|
@ -9,11 +9,14 @@ $options = [
|
|||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
];
|
||||
$logFilePath = '/var/log/namingo/reporting.log';
|
||||
$log = setupLogger($logFilePath, 'ICANN_Reporting');
|
||||
$log->info('job started.');
|
||||
|
||||
try {
|
||||
$dbh = new PDO($dsn, $c['db_username'], $c['db_password'], $options);
|
||||
} catch (PDOException $e) {
|
||||
die("Connection failed: " . $e->getMessage());
|
||||
$log->error('DB Connection failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
// Fetch all TLDs
|
||||
|
@ -180,11 +183,12 @@ foreach ($tlds as $tld) {
|
|||
$transactionUploadUrl = 'https://ry-api.icann.org/report/registrar-transactions/' . $tld_save . '/' . $previousMonth;
|
||||
|
||||
// Perform the upload
|
||||
//uploadFile($activityUploadUrl, $activityFile, $c['reporting_username'], $c['reporting_password']);
|
||||
//uploadFile($transactionUploadUrl, $transactionFile, $c['reporting_username'], $c['reporting_password']);
|
||||
//uploadFile($activityUploadUrl, $activityFile, $c['reporting_username'], $c['reporting_password'], $log);
|
||||
//uploadFile($transactionUploadUrl, $transactionFile, $c['reporting_username'], $c['reporting_password'], $log);
|
||||
}
|
||||
|
||||
}
|
||||
$log->info('job finished successfully.');
|
||||
|
||||
// HELPER FUNCTIONS
|
||||
function getOperationalRegistrars($dbh) {
|
||||
|
@ -562,7 +566,7 @@ function getAttemptedAddsAllRegistrars($dbh) {
|
|||
}
|
||||
|
||||
// Upload function using cURL
|
||||
function uploadFile($url, $filePath, $username, $password) {
|
||||
function uploadFile($url, $filePath, $username, $password, $log) {
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
|
@ -574,7 +578,7 @@ function uploadFile($url, $filePath, $username, $password) {
|
|||
|
||||
$response = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
echo 'Error:' . curl_error($ch);
|
||||
$log->error('Report upload error: ' . curl_error($ch));
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
|
|
@ -5,12 +5,15 @@ 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/send_invoice.log';
|
||||
$log = setupLogger($logFilePath, 'Invoice_Generator');
|
||||
$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) {
|
||||
die("Connection failed: " . $e->getMessage());
|
||||
$log->error('DB Connection failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
$previous = date("Y-m", strtotime("first day of previous month"));
|
||||
|
@ -110,15 +113,14 @@ try {
|
|||
$response = curl_exec($curl);
|
||||
|
||||
if ($response === false) {
|
||||
throw new Exception(curl_error($curl), curl_errno($curl));
|
||||
$log->error('Curl error: ' . curl_error($curl) . curl_errno($curl));
|
||||
}
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
print_r($response);
|
||||
$log->info('job finished successfully.');
|
||||
}
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
// Handle any PDO exceptions here
|
||||
echo "Database error: " . $e->getMessage();
|
||||
$log->error('Database error: ' . $e->getMessage());
|
||||
}
|
|
@ -5,12 +5,15 @@ 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/statistics.log';
|
||||
$log = setupLogger($logFilePath, 'Statistics');
|
||||
$log->info('job started.');
|
||||
|
||||
try {
|
||||
$dbh = new PDO($dsn, $c['db_username'], $c['db_password']);
|
||||
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
} catch (PDOException $e) {
|
||||
die("Connection failed: " . $e->getMessage());
|
||||
$log->error('DB Connection failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -27,11 +30,10 @@ try {
|
|||
|
||||
// Update the statistics table with the total number of domains for the current date
|
||||
$dbh->exec("UPDATE statistics SET total_domains = '$total_domains' WHERE date = CURDATE()");
|
||||
|
||||
$log->info('job finished successfully.');
|
||||
|
||||
} catch (PDOException $e) {
|
||||
// Handle database errors
|
||||
die("Database error: " . $e->getMessage());
|
||||
$log->error('Database error: ' . $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
// Handle other types of errors
|
||||
die("Error: " . $e->getMessage());
|
||||
$log->error('Error: ' . $e->getMessage());
|
||||
}
|
|
@ -5,68 +5,79 @@ 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/urs.log';
|
||||
$log = setupLogger($logFilePath, 'URS_Robot');
|
||||
$log->info('job started.');
|
||||
|
||||
try {
|
||||
$dbh = new PDO($dsn, $c['db_username'], $c['db_password']);
|
||||
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
} catch (PDOException $e) {
|
||||
die("Connection failed: " . $e->getMessage());
|
||||
$log->error('DB Connection failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
// Connect to mailbox
|
||||
$inbox = imap_open($c['urs_imap_host'], $c['urs_imap_username'], $c['urs_imap_password']) or die('Cannot connect to mailbox: ' . imap_last_error());
|
||||
|
||||
// Search for emails from the two URS providers
|
||||
$emailsFromProviderA = imap_search($inbox, 'FROM "urs@adrforum.com" UNSEEN');
|
||||
$emailsFromProviderB = imap_search($inbox, 'FROM "urs@adndrc.org" UNSEEN');
|
||||
$emailsFromProviderC = imap_search($inbox, 'FROM "urs@mfsd.it" UNSEEN');
|
||||
|
||||
// Combine the arrays of email IDs
|
||||
$allEmails = array_merge($emailsFromProviderA, $emailsFromProviderB, $emailsFromProviderC);
|
||||
|
||||
foreach ($allEmails as $emailId) {
|
||||
$header = imap_headerinfo($inbox, $emailId);
|
||||
$from = $header->from[0]->mailbox . "@" . $header->from[0]->host;
|
||||
$subject = $header->subject;
|
||||
$date = date('Y-m-d H:i:s', strtotime($header->date)) . '.000';
|
||||
|
||||
// Determine the URS provider based on the email sender
|
||||
$providerAEmail = 'urs@adrforum.com';
|
||||
$providerBEmail = 'urs@adndrc.org';
|
||||
$providerCEmail = 'urs@mfsd.it';
|
||||
|
||||
// Determine the URS provider based on the email sender
|
||||
if ($from == $providerAEmail) {
|
||||
$ursProvider = 'FORUM';
|
||||
} elseif ($from == $providerBEmail) {
|
||||
$ursProvider = 'ADNDRC';
|
||||
} elseif ($from == $providerCEmail) {
|
||||
$ursProvider = 'MFSD';
|
||||
} else {
|
||||
$ursProvider = 'Unknown';
|
||||
try {
|
||||
$inbox = imap_open($c['urs_imap_host'], $c['urs_imap_username'], $c['urs_imap_password']);
|
||||
if (!$inbox) {
|
||||
throw new Exception('Cannot connect to mailbox: ' . imap_last_error());
|
||||
}
|
||||
// Search for emails from the two URS providers
|
||||
$emailsFromProviderA = imap_search($inbox, 'FROM "urs@adrforum.com" UNSEEN');
|
||||
$emailsFromProviderB = imap_search($inbox, 'FROM "urs@adndrc.org" UNSEEN');
|
||||
$emailsFromProviderC = imap_search($inbox, 'FROM "urs@mfsd.it" UNSEEN');
|
||||
|
||||
// Extract domain name or relevant info from the email (you'd need more specific code here based on the email content)
|
||||
$body = imap_fetchbody($inbox, $emailId, 1);
|
||||
$domainName = extractDomainNameFromEmail($body);
|
||||
// Combine the arrays of email IDs
|
||||
$allEmails = array_merge($emailsFromProviderA, $emailsFromProviderB, $emailsFromProviderC);
|
||||
|
||||
// Insert into the database
|
||||
$stmt = $dbh->prepare("SELECT name, clid FROM domain WHERE name = ?");
|
||||
$stmt->execute([$domainName]);
|
||||
$domain = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($domain) {
|
||||
$domainName = $domain['name'];
|
||||
$registrarId = $domain['clid'];
|
||||
foreach ($allEmails as $emailId) {
|
||||
$header = imap_headerinfo($inbox, $emailId);
|
||||
$from = $header->from[0]->mailbox . "@" . $header->from[0]->host;
|
||||
$subject = $header->subject;
|
||||
$date = date('Y-m-d H:i:s', strtotime($header->date)) . '.000';
|
||||
|
||||
// Determine the URS provider based on the email sender
|
||||
$providerAEmail = 'urs@adrforum.com';
|
||||
$providerBEmail = 'urs@adndrc.org';
|
||||
$providerCEmail = 'urs@mfsd.it';
|
||||
|
||||
// Determine the URS provider based on the email sender
|
||||
if ($from == $providerAEmail) {
|
||||
$ursProvider = 'FORUM';
|
||||
} elseif ($from == $providerBEmail) {
|
||||
$ursProvider = 'ADNDRC';
|
||||
} elseif ($from == $providerCEmail) {
|
||||
$ursProvider = 'MFSD';
|
||||
} else {
|
||||
$ursProvider = 'Unknown';
|
||||
}
|
||||
|
||||
// Extract domain name or relevant info from the email (you'd need more specific code here based on the email content)
|
||||
$body = imap_fetchbody($inbox, $emailId, 1);
|
||||
$domainName = extractDomainNameFromEmail($body);
|
||||
|
||||
// Insert into the database
|
||||
$stmt = $dbh->prepare("SELECT name, clid FROM domain WHERE name = ?");
|
||||
$stmt->execute([$domainName]);
|
||||
$domain = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
$stmt = $dbh->prepare("INSERT INTO support_tickets (user_id, category_id, subject, message, status, priority, evidence) VALUES (?, ?, ?, ?, ?, ?, ?)");
|
||||
$stmt->execute([$registrarId, 12, 'New URS case for '.$domainName, 'New URS case for '.$domainName.' submitted by '.$ursProvider.' on '.$date.' Please act accordingly', 'Open', 'High', $body]);
|
||||
} else {
|
||||
echo "Domain does not exists in registry.";
|
||||
if ($domain) {
|
||||
$domainName = $domain['name'];
|
||||
$registrarId = $domain['clid'];
|
||||
|
||||
$stmt = $dbh->prepare("INSERT INTO support_tickets (user_id, category_id, subject, message, status, priority, evidence) VALUES (?, ?, ?, ?, ?, ?, ?)");
|
||||
$stmt->execute([$registrarId, 12, 'New URS case for '.$domainName, 'New URS case for '.$domainName.' submitted by '.$ursProvider.' on '.$date.' Please act accordingly', 'Open', 'High', $body]);
|
||||
} else {
|
||||
$log->warning('Domain ' . $domainName . ' does not exists in registry');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
imap_close($inbox);
|
||||
imap_close($inbox);
|
||||
$log->info('job finished successfully.');
|
||||
} catch (Exception $e) {
|
||||
$log->error('IMAP connection error: ' . $e->getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
function extractDomainNameFromEmail($emailBody) {
|
||||
// This is just a basic example
|
||||
|
|
|
@ -12,12 +12,15 @@ $c = require_once 'config.php';
|
|||
require_once 'helpers.php';
|
||||
|
||||
$dsn = "{$c['db_type']}:host={$c['db_host']};dbname={$c['db_database']};port={$c['db_port']}";
|
||||
$logFilePath = '/var/log/namingo/write_zone_optimized.log';
|
||||
$log = setupLogger($logFilePath, 'Zone_Generator_Optimized');
|
||||
$log->info('job started.');
|
||||
|
||||
try {
|
||||
$db = new PDO($dsn, $c['db_username'], $c['db_password']);
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
} catch (PDOException $e) {
|
||||
die("Connection failed: " . $e->getMessage());
|
||||
$log->error('DB Connection failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
$timestamp = time();
|
||||
|
@ -131,42 +134,43 @@ while (list($id, $tld) = $sth->fetch(PDO::FETCH_NUM)) {
|
|||
}
|
||||
|
||||
file_put_contents("{$basePath}/{$cleanedTld}.zone", $completed_zone);
|
||||
$log->info('job finished successfully.');
|
||||
}
|
||||
|
||||
if ($c['dns_server'] == 'bind') {
|
||||
exec("rndc reload .{$cleanedTld}", $output, $return_var);
|
||||
if ($return_var != 0) {
|
||||
print "Failed to reload BIND. $return_var \n";
|
||||
$log->error('Failed to reload BIND. ' . $return_var);
|
||||
}
|
||||
|
||||
exec("rndc notify .{$cleanedTld}", $output, $return_var);
|
||||
if ($return_var != 0) {
|
||||
print "Failed to notify secondary servers. $return_var \n";
|
||||
$log->error('Failed to notify secondary servers. ' . $return_var);
|
||||
}
|
||||
} elseif ($c['dns_server'] == 'nsd') {
|
||||
exec("nsd-control reload", $output, $return_var);
|
||||
if ($return_var != 0) {
|
||||
print "Failed to reload NSD. $return_var \n";
|
||||
$log->error('Failed to reload NSD. ' . $return_var);
|
||||
}
|
||||
} elseif ($c['dns_server'] == 'knot') {
|
||||
exec("knotc reload", $output, $return_var);
|
||||
if ($return_var != 0) {
|
||||
print "Failed to reload Knot DNS. $return_var \n";
|
||||
$log->error('Failed to reload Knot DNS. ' . $return_var);
|
||||
}
|
||||
|
||||
exec("knotc zone-notify .{$cleanedTld}", $output, $return_var);
|
||||
if ($return_var != 0) {
|
||||
print "Failed to notify secondary servers. $return_var \n";
|
||||
$log->error('Failed to notify secondary servers. ' . $return_var);
|
||||
}
|
||||
} else {
|
||||
// Default
|
||||
exec("rndc reload .{$cleanedTld}", $output, $return_var);
|
||||
if ($return_var != 0) {
|
||||
print "Failed to reload BIND. $return_var \n";
|
||||
$log->error('Failed to reload BIND. ' . $return_var);
|
||||
}
|
||||
|
||||
exec("rndc notify .{$cleanedTld}", $output, $return_var);
|
||||
if ($return_var != 0) {
|
||||
print "Failed to notify secondary servers. $return_var \n";
|
||||
$log->error('Failed to notify secondary servers. ' . $return_var);
|
||||
}
|
||||
}
|
|
@ -12,12 +12,15 @@ $c = require_once 'config.php';
|
|||
require_once 'helpers.php';
|
||||
|
||||
$dsn = "{$c['db_type']}:host={$c['db_host']};dbname={$c['db_database']};port={$c['db_port']}";
|
||||
$logFilePath = '/var/log/namingo/write_zone.log';
|
||||
$log = setupLogger($logFilePath, 'Zone_Generator');
|
||||
$log->info('job started.');
|
||||
|
||||
try {
|
||||
$db = new PDO($dsn, $c['db_username'], $c['db_password']);
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
} catch (PDOException $e) {
|
||||
die("Connection failed: " . $e->getMessage());
|
||||
$log->error('DB Connection failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
$timestamp = time();
|
||||
|
@ -177,42 +180,43 @@ while (list($id, $tld) = $sth->fetch(PDO::FETCH_NUM)) {
|
|||
}
|
||||
|
||||
file_put_contents("{$basePath}/{$cleanedTld}.zone", $completed_zone);
|
||||
$log->info('job finished successfully.');
|
||||
}
|
||||
|
||||
if ($c['dns_server'] == 'bind') {
|
||||
exec("rndc reload .{$cleanedTld}", $output, $return_var);
|
||||
if ($return_var != 0) {
|
||||
print "Failed to reload BIND. $return_var \n";
|
||||
$log->error('Failed to reload BIND. ' . $return_var);
|
||||
}
|
||||
|
||||
exec("rndc notify .{$cleanedTld}", $output, $return_var);
|
||||
if ($return_var != 0) {
|
||||
print "Failed to notify secondary servers. $return_var \n";
|
||||
$log->error('Failed to notify secondary servers. ' . $return_var);
|
||||
}
|
||||
} elseif ($c['dns_server'] == 'nsd') {
|
||||
exec("nsd-control reload", $output, $return_var);
|
||||
if ($return_var != 0) {
|
||||
print "Failed to reload NSD. $return_var \n";
|
||||
$log->error('Failed to reload NSD. ' . $return_var);
|
||||
}
|
||||
} elseif ($c['dns_server'] == 'knot') {
|
||||
exec("knotc reload", $output, $return_var);
|
||||
if ($return_var != 0) {
|
||||
print "Failed to reload Knot DNS. $return_var \n";
|
||||
$log->error('Failed to reload Knot DNS. ' . $return_var);
|
||||
}
|
||||
|
||||
exec("knotc zone-notify .{$cleanedTld}", $output, $return_var);
|
||||
if ($return_var != 0) {
|
||||
print "Failed to notify secondary servers. $return_var \n";
|
||||
$log->error('Failed to notify secondary servers. ' . $return_var);
|
||||
}
|
||||
} else {
|
||||
// Default
|
||||
exec("rndc reload .{$cleanedTld}", $output, $return_var);
|
||||
if ($return_var != 0) {
|
||||
print "Failed to reload BIND. $return_var \n";
|
||||
$log->error('Failed to reload BIND. ' . $return_var);
|
||||
}
|
||||
|
||||
exec("rndc notify .{$cleanedTld}", $output, $return_var);
|
||||
if ($return_var != 0) {
|
||||
print "Failed to notify secondary servers. $return_var \n";
|
||||
$log->error('Failed to notify secondary servers. ' . $return_var);
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' -o caddy-stabl
|
|||
gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg caddy-stable.gpg.key
|
||||
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list
|
||||
apt update && apt upgrade
|
||||
apt install -y bzip2 caddy composer curl gettext git gnupg2 net-tools php8.2 php8.2-bcmath php8.2-cli php8.2-common php8.2-curl php8.2-fpm php8.2-gd php8.2-gmp php8.2-gnupg php8.2-intl php8.2-mbstring php8.2-opcache php8.2-readline php8.2-swoole php8.2-xml pv unzip wget whois
|
||||
apt install -y bzip2 caddy composer curl gettext git gnupg2 net-tools php8.2 php8.2-bcmath php8.2-cli php8.2-common php8.2-curl php8.2-fpm php8.2-gd php8.2-gmp php8.2-gnupg php8.2-imap php8.2-intl php8.2-mbstring php8.2-opcache php8.2-readline php8.2-swoole php8.2-xml pv unzip wget whois
|
||||
```
|
||||
|
||||
### Configure OPcache
|
||||
|
@ -206,12 +206,10 @@ Open the file in a text editor and carefully review and update all the values to
|
|||
|
||||
### Install Required Dependencies:
|
||||
|
||||
Navigate to the automation directory in your command line interface.
|
||||
|
||||
Execute the following command to install the necessary dependencies:
|
||||
Execute the following command from the ```automation``` directory to install the necessary dependencies:
|
||||
|
||||
```bash
|
||||
composer require badcow/dns phpseclib/phpseclib phpbu/phpbu setbased/php-audit
|
||||
composer install
|
||||
```
|
||||
|
||||
This command will install the essential packages for the automation scripts to function correctly.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue