Further updates on automation

This commit is contained in:
Pinga 2023-12-01 11:17:04 +02:00
parent db75518533
commit 28c68a4e57
7 changed files with 918 additions and 882 deletions

View file

@ -16,11 +16,12 @@ try {
$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'";
$stmt_domain = $dbh->prepare($query_domain);
$stmt_domain->execute();
try {
$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'";
$stmt_domain = $dbh->prepare($query_domain);
$stmt_domain->execute();
while ($row = $stmt_domain->fetch(PDO::FETCH_ASSOC)) {
while ($row = $stmt_domain->fetch(PDO::FETCH_ASSOC)) {
// Extracting data from the result set
extract($row);
@ -83,13 +84,13 @@ while ($row = $stmt_domain->fetch(PDO::FETCH_ASSOC)) {
$stmt_auto_approve_transfer->execute(array_values($domain_data));
}
}
$stmt_domain = null;
}
$stmt_domain = null;
$stmt_contact = $dbh->prepare("SELECT id, crid, crdate, upid, `update`, trdate, trstatus, reid, redate, acid, acdate FROM contact WHERE CURRENT_TIMESTAMP > acdate AND trstatus = 'pending'");
$stmt_contact->execute();
$stmt_contact = $dbh->prepare("SELECT id, crid, crdate, upid, `update`, trdate, trstatus, reid, redate, acid, acdate FROM contact WHERE CURRENT_TIMESTAMP > acdate AND trstatus = 'pending'");
$stmt_contact->execute();
while ($contact_data = $stmt_contact->fetch(PDO::FETCH_ASSOC)) {
while ($contact_data = $stmt_contact->fetch(PDO::FETCH_ASSOC)) {
$contact_id = $contact_data['id'];
$reid = $contact_data['reid'];
@ -108,6 +109,11 @@ while ($contact_data = $stmt_contact->fetch(PDO::FETCH_ASSOC)) {
$stmt_auto_approve_transfer = $dbh->prepare("INSERT INTO contact_auto_approve_transfer (identifier, crid, crdate, upid, `update`, trdate, trstatus, reid, redate, acid, acdate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt_auto_approve_transfer->execute(array_values($contact_selected_data));
}
}
$stmt_contact = null;
$log->info('job finished successfully.');
} catch (PDOException $e) {
$log->error('Database error: ' . $e->getMessage());
} catch (Throwable $e) {
$log->error('Error: ' . $e->getMessage());
}
$stmt_contact = null;
$log->info('job finished successfully.');

View file

@ -60,9 +60,7 @@ try {
$log->info('job finished successfully.');
} catch (PDOException $e) {
// Handle database errors
$log->error('Database error: ' . $e->getMessage());
} catch (Exception $e) {
// Handle other types of errors
} catch (Throwable $e) {
$log->error('Error: ' . $e->getMessage());
}

View file

@ -16,10 +16,11 @@ try {
$log->error('DB Connection failed: ' . $e->getMessage());
}
// Auto-Renew Grace Period
$auto_renew = 0;
try {
// Auto-Renew Grace Period
$auto_renew = 0;
if ($auto_renew) {
if ($auto_renew) {
$sth_autorenewperiod = $dbh->prepare("SELECT id, name, tldid, exdate, clid FROM domain WHERE CURRENT_TIMESTAMP > exdate AND rgpstatus IS NULL");
$sth_autorenewperiod->execute();
while ($row = $sth_autorenewperiod->fetch(PDO::FETCH_ASSOC)) {
@ -64,7 +65,7 @@ if ($auto_renew) {
}
$log->info($name . ' (ID ' . $domain_id . ') rgpStatus:autoRenewPeriod exdate: ' . $exdate);
}
} else {
} else {
$grace_period = 30;
$sth_graceperiod = $dbh->prepare("SELECT id, name, exdate FROM domain WHERE CURRENT_TIMESTAMP > DATE_ADD(exdate, INTERVAL $grace_period DAY) AND rgpstatus IS NULL");
$sth_graceperiod->execute();
@ -92,9 +93,9 @@ if ($auto_renew) {
}
$log->info($name . ' (ID ' . $domain_id . ') rgpStatus:redemptionPeriod exdate: ' . $exdate);
}
}
}
try {
try {
// clean autoRenewPeriod after 45 days
$sql1 = "UPDATE domain SET rgpstatus = NULL WHERE CURRENT_TIMESTAMP > DATE_ADD(exdate, INTERVAL 45 DAY) AND rgpstatus = 'autoRenewPeriod'";
$dbh->exec($sql1);
@ -111,16 +112,16 @@ try {
$sql4 = "UPDATE domain SET rgpstatus = NULL WHERE CURRENT_TIMESTAMP > DATE_ADD(trdate, INTERVAL 5 DAY) AND rgpstatus = 'transferPeriod'";
$dbh->exec($sql4);
} catch (PDOException $e) {
} catch (PDOException $e) {
$log->error('DB Error: ' . $e->getMessage());
}
}
// Pending Delete
// The current value of the redemptionPeriod is 30 calendar days.
$sth_pendingdelete = $dbh->prepare("SELECT id, name, exdate FROM domain WHERE CURRENT_TIMESTAMP > DATE_ADD(delTime, INTERVAL 30 DAY) AND rgpstatus = 'redemptionPeriod'");
$sth_pendingdelete->execute();
// Pending Delete
// The current value of the redemptionPeriod is 30 calendar days.
$sth_pendingdelete = $dbh->prepare("SELECT id, name, exdate FROM domain WHERE CURRENT_TIMESTAMP > DATE_ADD(delTime, INTERVAL 30 DAY) AND rgpstatus = 'redemptionPeriod'");
$sth_pendingdelete->execute();
while ($row = $sth_pendingdelete->fetch(PDO::FETCH_ASSOC)) {
while ($row = $sth_pendingdelete->fetch(PDO::FETCH_ASSOC)) {
$domain_id = $row['id'];
$name = $row['name'];
$exdate = $row['exdate'];
@ -141,13 +142,13 @@ while ($row = $sth_pendingdelete->fetch(PDO::FETCH_ASSOC)) {
$dbh->exec("UPDATE domain SET rgpstatus = 'pendingDelete' WHERE id = '$domain_id'");
}
$log->info($name . ' (ID ' . $domain_id . ') rgpStatus:pendingDelete exdate: ' . $exdate);
}
}
// Pending Restore
$sth_pendingRestore = $dbh->prepare("SELECT id, name, exdate FROM domain WHERE rgpstatus = 'pendingRestore' AND (CURRENT_TIMESTAMP > DATE_ADD(resTime, INTERVAL 7 DAY))");
$sth_pendingRestore->execute();
// Pending Restore
$sth_pendingRestore = $dbh->prepare("SELECT id, name, exdate FROM domain WHERE rgpstatus = 'pendingRestore' AND (CURRENT_TIMESTAMP > DATE_ADD(resTime, INTERVAL 7 DAY))");
$sth_pendingRestore->execute();
while ($row = $sth_pendingRestore->fetch(PDO::FETCH_ASSOC)) {
while ($row = $sth_pendingRestore->fetch(PDO::FETCH_ASSOC)) {
$domain_id = $row['id'];
$name = $row['name'];
$exdate = $row['exdate'];
@ -155,13 +156,13 @@ while ($row = $sth_pendingRestore->fetch(PDO::FETCH_ASSOC)) {
$dbh->exec("UPDATE domain SET rgpstatus = 'redemptionPeriod' WHERE id = '$domain_id'");
$log->info($name . ' (ID ' . $domain_id . ') back to redemptionPeriod from pendingRestore exdate: ' . $exdate);
}
}
// Domain Deletion
$sth_delete = $dbh->prepare("SELECT id, name, exdate FROM domain WHERE CURRENT_TIMESTAMP > DATE_ADD(delTime, INTERVAL 35 DAY) AND rgpstatus = 'pendingDelete'");
$sth_delete->execute();
// Domain Deletion
$sth_delete = $dbh->prepare("SELECT id, name, exdate FROM domain WHERE CURRENT_TIMESTAMP > DATE_ADD(delTime, INTERVAL 35 DAY) AND rgpstatus = 'pendingDelete'");
$sth_delete->execute();
while ($row = $sth_delete->fetch(PDO::FETCH_ASSOC)) {
while ($row = $sth_delete->fetch(PDO::FETCH_ASSOC)) {
$domain_id = $row['id'];
$name = $row['name'];
$exdate = $row['exdate'];
@ -211,5 +212,10 @@ while ($row = $sth_delete->fetch(PDO::FETCH_ASSOC)) {
}
}
$log->info($name . ' (ID ' . $domain_id . ') domain:Deleted exdate: ' . $exdate);
}
$log->info('job finished successfully.');
} catch (PDOException $e) {
$log->error('Database error: ' . $e->getMessage());
} catch (Throwable $e) {
$log->error('Error: ' . $e->getMessage());
}
$log->info('job finished successfully.');

View file

@ -23,27 +23,28 @@ try {
$log->error('DB Connection failed: ' . $e->getMessage());
}
$domainCount = fetchCount($dbh, 'domain');
$hostCount = fetchCount($dbh, 'host');
$contactCount = fetchCount($dbh, 'contact');
$registrarCount = fetchCount($dbh, 'registrar');
try {
$domainCount = fetchCount($dbh, 'domain');
$hostCount = fetchCount($dbh, 'host');
$contactCount = fetchCount($dbh, 'contact');
$registrarCount = fetchCount($dbh, 'registrar');
// Fetching TLDs
$stmt = $dbh->query("SELECT id,tld FROM domain_tld;");
$tlds = $stmt->fetchAll();
// Fetching TLDs
$stmt = $dbh->query("SELECT id,tld FROM domain_tld;");
$tlds = $stmt->fetchAll();
// Fetching details from rde_escrow_deposits table
$stmt = $dbh->prepare("SELECT deposit_id, revision FROM rde_escrow_deposits;");
$stmt->execute();
$deposit_id = $stmt->fetch();
// Fetching details from rde_escrow_deposits table
$stmt = $dbh->prepare("SELECT deposit_id, revision FROM rde_escrow_deposits;");
$stmt->execute();
$deposit_id = $stmt->fetch();
// Determine the next revision number
$nextRevisionNumber = is_null($deposit_id['deposit_id']) ? 1 : ($deposit_id['revision'] + 1);
// Determine the next revision number
$nextRevisionNumber = is_null($deposit_id['deposit_id']) ? 1 : ($deposit_id['revision'] + 1);
// Format the revision number (001, 002, 003, ..., 010, ...)
$finalDepositId = str_pad($nextRevisionNumber, 3, '0', STR_PAD_LEFT);
// Format the revision number (001, 002, 003, ..., 010, ...)
$finalDepositId = str_pad($nextRevisionNumber, 3, '0', STR_PAD_LEFT);
foreach ($tlds as $tld) {
foreach ($tlds as $tld) {
$tldname = strtoupper(ltrim($tld['tld'], '.'));
// Skip subdomains
@ -493,5 +494,10 @@ foreach ($tlds as $tld) {
}
}
$log->info('job finished successfully.');
} catch (PDOException $e) {
$log->error('Database error: ' . $e->getMessage());
} catch (Throwable $e) {
$log->error('Error: ' . $e->getMessage());
}
$log->info('job finished successfully.');

View file

@ -19,11 +19,12 @@ try {
$log->error('DB Connection failed: ' . $e->getMessage());
}
// Fetch all TLDs
$query = "SELECT tld FROM domain_tld";
$tlds = $dbh->query($query)->fetchAll(PDO::FETCH_COLUMN);
try {
// Fetch all TLDs
$query = "SELECT tld FROM domain_tld";
$tlds = $dbh->query($query)->fetchAll(PDO::FETCH_COLUMN);
foreach ($tlds as $tld) {
foreach ($tlds as $tld) {
// Skip TLDs with a dot inside, apart from the beginning
if (strpos(substr($tld, 1), '.') !== false) {
continue; // Skip this iteration if an additional dot is found
@ -183,12 +184,17 @@ 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'], $log);
//uploadFile($transactionUploadUrl, $transactionFile, $c['reporting_username'], $c['reporting_password'], $log);
uploadFile($activityUploadUrl, $activityFile, $c['reporting_username'], $c['reporting_password']);
uploadFile($transactionUploadUrl, $transactionFile, $c['reporting_username'], $c['reporting_password']);
}
}
$log->info('job finished successfully.');
} catch (PDOException $e) {
$log->error('DB Connection failed: ' . $e->getMessage());
} catch (Throwable $e) {
$log->error('Error: ' . $e->getMessage());
}
$log->info('job finished successfully.');
// HELPER FUNCTIONS
function getOperationalRegistrars($dbh) {
@ -202,12 +208,25 @@ function getRegistrars($dbh) {
}
function writeCSV($filename, $data) {
if (!is_array($data) || empty($data)) {
throw new Exception("Data for CSV writing must be a non-empty array.");
}
$file = fopen($filename, 'w');
if ($file === false) {
throw new Exception("Unable to open file '{$filename}' for writing.");
}
fputcsv($file, array_keys($data[0]));
foreach ($data as $row) {
fputcsv($file, $row);
if (false === fputcsv($file, $row)) {
throw new Exception("Failed to write data to CSV file.");
}
}
if (false === fclose($file)) {
throw new Exception("Unable to close the file '{$filename}'.");
}
fclose($file);
}
function getZfaPasswords($dbh) {
@ -566,7 +585,7 @@ function getAttemptedAddsAllRegistrars($dbh) {
}
// Upload function using cURL
function uploadFile($url, $filePath, $username, $password, $log) {
function uploadFile($url, $filePath, $username, $password) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
@ -578,7 +597,7 @@ function uploadFile($url, $filePath, $username, $password, $log) {
$response = curl_exec($ch);
if (curl_errno($ch)) {
$log->error('Report upload error: ' . curl_error($ch));
throw new Exception('Report upload error: ' . curl_error($ch));
}
curl_close($ch);

View file

@ -34,6 +34,6 @@ try {
} catch (PDOException $e) {
$log->error('Database error: ' . $e->getMessage());
} catch (Exception $e) {
} catch (Throwable $e) {
$log->error('Error: ' . $e->getMessage());
}

View file

@ -76,7 +76,8 @@ try {
$log->info('job finished successfully.');
} catch (Exception $e) {
$log->error('IMAP connection error: ' . $e->getMessage());
return;
} catch (Throwable $e) {
$log->error('Error: ' . $e->getMessage());
}
function extractDomainNameFromEmail($emailBody) {