Added notification system, only transfers for now

This commit is contained in:
Pinga 2025-03-13 11:30:37 +02:00
parent e22e670cb8
commit 9f6d9e2be3
5 changed files with 162 additions and 17 deletions

View file

@ -49,22 +49,16 @@ try {
$label = $matches[1]; $label = $matches[1];
$domain_extension = $matches[2]; $domain_extension = $matches[2];
$tld_id = null; $stmt_tld = $dbh->prepare("SELECT id FROM domain_tld WHERE UPPER(tld) = :tld LIMIT 1");
$stmt_tld = $dbh->prepare("SELECT id, tld FROM domain_tld"); $stmt_tld->execute([':tld' => '.' . strtoupper($domain_extension)]);
$stmt_tld->execute(); $tld_id = $stmt_tld->fetchColumn();
while ($tld_row = $stmt_tld->fetch(PDO::FETCH_ASSOC)) {
if ('.' . strtoupper($domain_extension) === strtoupper($tld_row['tld'])) {
$tld_id = $tld_row['id'];
break;
}
}
$returnValue = getDomainPrice($dbh, $name, $tld_id, $date_add, 'transfer', $reid, $currency); $returnValue = getDomainPrice($dbh, $name, $tld_id, $date_add, 'transfer', $reid, $currency);
$price = $returnValue['price']; $price = $returnValue['price'];
if (($registrar_balance + $creditLimit) < $price) { if (($registrar_balance + $creditLimit) < $price) {
$log->notice($name . ': The registrar who took over this domain has no money to pay the renewal period that resulted from the transfer request'); $log->notice($name . ': The registrar who took over this domain has no money to pay the renewal period that resulted from the transfer request');
$log->error("Registrar $reid failed to process transfer for domain $name: Insufficient funds (Balance: $registrar_balance, Credit Limit: $creditLimit, Required: $price).");
continue; continue;
} }
} }
@ -167,6 +161,18 @@ try {
$stmt_update_auth = $dbh->prepare("UPDATE domain_authInfo SET authinfo = '$new_authinfo' WHERE domain_id = '$domain_id'"); $stmt_update_auth = $dbh->prepare("UPDATE domain_authInfo SET authinfo = '$new_authinfo' WHERE domain_id = '$domain_id'");
$stmt_update_auth->execute(); $stmt_update_auth->execute();
// Remove "pendingTransfer" status
$stmt_remove_pending = $dbh->prepare("DELETE FROM domain_status WHERE domain_id = :domain_id AND status = 'pendingTransfer'");
$stmt_remove_pending->execute([
':domain_id' => $domain_id
]);
// Insert "ok" status
$stmt_insert_ok = $dbh->prepare("INSERT INTO domain_status (domain_id, status) VALUES (:domain_id, 'ok')");
$stmt_insert_ok->execute([
':domain_id' => $domain_id
]);
if (!$minimum_data) { if (!$minimum_data) {
foreach ($contactMap as $contact) { foreach ($contactMap as $contact) {
// Construct the SQL update query // Construct the SQL update query
@ -191,6 +197,7 @@ try {
if ($stmt_update->errorCode() != "00000") { if ($stmt_update->errorCode() != "00000") {
$log->error($name . ': The domain transfer was not successful, something is wrong | DB Update failed:' . implode(", ", $stmt_update->errorInfo())); $log->error($name . ': The domain transfer was not successful, something is wrong | DB Update failed:' . implode(", ", $stmt_update->errorInfo()));
$log->error("Registrar $reid failed to process transfer for domain $name: Database update failed.");
continue; continue;
} else { } else {
$dbh->exec("UPDATE registrar SET accountBalance = (accountBalance - $price) WHERE id = '$reid'"); $dbh->exec("UPDATE registrar SET accountBalance = (accountBalance - $price) WHERE id = '$reid'");
@ -207,6 +214,23 @@ try {
$stmt_auto_approve_transfer = $dbh->prepare("INSERT INTO domain_auto_approve_transfer (name,registrant,crdate,exdate,lastupdate,clid,crid,upid,trdate,trstatus,reid,redate,acid,acdate,transfer_exdate) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); $stmt_auto_approve_transfer = $dbh->prepare("INSERT INTO domain_auto_approve_transfer (name,registrant,crdate,exdate,lastupdate,clid,crid,upid,trdate,trstatus,reid,redate,acid,acdate,transfer_exdate) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$stmt_auto_approve_transfer->execute(array_values($domain_data)); $stmt_auto_approve_transfer->execute(array_values($domain_data));
$stmt_log = $dbh->prepare("INSERT INTO error_log (channel, level, level_name, message, context, extra) VALUES (?, ?, ?, ?, ?, ?)");
$stmt_log->execute([
'auto_transfer',
250,
'NOTICE',
"Domain transfer auto-approved: $name (New registrant: $newRegistrantId, Registrar: $reid)",
json_encode(['domain_id' => $domain_id, 'new_registrant' => $newRegistrantId, 'registrar' => $reid]),
json_encode([
'received_on' => date('Y-m-d H:i:s'),
'read_on' => null,
'is_read' => false,
'message_type' => 'auto_transfer_approval'
])
]);
$log->notice("Domain transfer processed: $name (New registrant: $newRegistrantId, Registrar: $reid, New Expiry: $to)");
} }
} }
@ -225,6 +249,7 @@ try {
if ($stmt_update_contact->errorCode() != "00000") { if ($stmt_update_contact->errorCode() != "00000") {
$log->error($contact_id . ': The contact transfer was not successful, something is wrong | DB Update failed:' . implode(", ", $stmt_update_contact->errorInfo())); $log->error($contact_id . ': The contact transfer was not successful, something is wrong | DB Update failed:' . implode(", ", $stmt_update_contact->errorInfo()));
$log->error("Registrar $reid failed to process contact transfer for contact ID $contact_id");
continue; continue;
} else { } else {
$stmt_select_contact = $dbh->prepare("SELECT identifier, crid, crdate, upid, lastupdate, trdate, trstatus, reid, redate, acid, acdate FROM contact WHERE id = ? LIMIT 1"); $stmt_select_contact = $dbh->prepare("SELECT identifier, crid, crdate, upid, lastupdate, trdate, trstatus, reid, redate, acid, acdate FROM contact WHERE id = ? LIMIT 1");
@ -241,10 +266,13 @@ try {
} catch (Exception $e) { } catch (Exception $e) {
$dbh->rollBack(); $dbh->rollBack();
$log->error('Database error: ' . $e->getMessage()); $log->error('Database error: ' . $e->getMessage());
$log->error("Registrar $reid failed to process transfer for domain $name due to unexpected exception: " . $e->getMessage());
} catch (PDOException $e) { } catch (PDOException $e) {
$dbh->rollBack(); $dbh->rollBack();
$log->error('Database error: ' . $e->getMessage()); $log->error('Database error: ' . $e->getMessage());
$log->error("Registrar $reid failed to process transfer for domain $name due to unexpected exception: " . $e->getMessage());
} catch (Throwable $e) { } catch (Throwable $e) {
$dbh->rollBack(); $dbh->rollBack();
$log->error('Error: ' . $e->getMessage()); $log->error('Error: ' . $e->getMessage());
$log->error("Registrar $reid failed to process transfer for domain $name due to unexpected exception: " . $e->getMessage());
} }

View file

@ -3009,6 +3009,28 @@ class DomainsController extends Controller
'UPDATE statistics SET transfered_domains = transfered_domains + 1 WHERE date = CURDATE()' 'UPDATE statistics SET transfered_domains = transfered_domains + 1 WHERE date = CURDATE()'
); );
$stmt_log = $db->exec(
'INSERT INTO error_log (channel, level, level_name, message, context, extra) VALUES (?, ?, ?, ?, ?, ?)',
[
'manual_transfer',
250,
'NOTICE',
"Manual domain transfer approved: $domainName (New registrant: $newRegistrantId, Registrar: $reid)",
json_encode([
'domain_id' => $domain_id,
'new_registrant' => $newRegistrantId,
'registrar' => $reid,
'performed_by' => $clid
]),
json_encode([
'received_on' => date('Y-m-d H:i:s'),
'read_on' => null,
'is_read' => false,
'message_type' => 'manual_transfer_approval'
])
]
);
$db->commit(); $db->commit();
} catch (Exception $e) { } catch (Exception $e) {
$db->rollBack(); $db->rollBack();
@ -3104,6 +3126,28 @@ class DomainsController extends Controller
] ]
); );
$db->exec(
'INSERT INTO error_log (channel, level, level_name, message, context, extra) VALUES (?, ?, ?, ?, ?, ?)',
[
'manual_transfer_reject',
250, // NOTICE level
'NOTICE',
"Manual domain transfer rejected: $domainName (Losing Registrar: $clid)",
json_encode([
'domain_id' => $domain_id,
'losing_registrar' => $clid,
'status' => 'clientRejected',
'performed_by' => $clid
]),
json_encode([
'received_on' => date('Y-m-d H:i:s'),
'read_on' => null,
'is_read' => false,
'message_type' => 'manual_transfer_rejection'
])
]
);
$this->container->get('flash')->addMessage('success', 'Transfer for ' . $domainName . ' has been rejected successfully'); $this->container->get('flash')->addMessage('success', 'Transfer for ' . $domainName . ' has been rejected successfully');
return $response->withHeader('Location', '/transfers')->withStatus(302); return $response->withHeader('Location', '/transfers')->withStatus(302);
} else { } else {
@ -3192,6 +3236,28 @@ class DomainsController extends Controller
] ]
); );
$db->exec(
'INSERT INTO error_log (channel, level, level_name, message, context, extra) VALUES (?, ?, ?, ?, ?, ?)',
[
'manual_transfer_cancel',
250, // NOTICE level
'NOTICE',
"Manual domain transfer canceled: $domainName (Applicant: $clid)",
json_encode([
'domain_id' => $domain_id,
'applicant' => $clid,
'status' => 'clientCancelled',
'performed_by' => $clid
]),
json_encode([
'received_on' => date('Y-m-d H:i:s'),
'read_on' => null,
'is_read' => false,
'message_type' => 'manual_transfer_cancellation'
])
]
);
$this->container->get('flash')->addMessage('success', 'Transfer for ' . $domainName . ' has been cancelled successfully'); $this->container->get('flash')->addMessage('success', 'Transfer for ' . $domainName . ' has been cancelled successfully');
return $response->withHeader('Location', '/transfers')->withStatus(302); return $response->withHeader('Location', '/transfers')->withStatus(302);
} else { } else {

View file

@ -23,14 +23,14 @@
responsiveLayoutCollapseStartOpen:false, responsiveLayoutCollapseStartOpen:false,
resizableColumns:false, resizableColumns:false,
initialSort:[ initialSort:[
{column:"created_at", dir:"desc"}, // sorting by the "created_at" field in descending order {column:"created_at", dir:"desc"},
], ],
placeholder: "{{ __('No Data') }}", placeholder: "{{ __('No Data') }}",
columns:[ columns:[
{formatter:"responsiveCollapse", width:30, minWidth:30, hozAlign:"center", resizable:false, headerSort:false, responsive:0}, {formatter:"responsiveCollapse", width:30, minWidth:30, hozAlign:"center", resizable:false, headerSort:false, responsive:0},
{title:"{{ __('Channel') }}", field:"channel", minWidth:180, resizable:false, headerSort:true, responsive:0}, {title:"{{ __('Channel') }}", field:"channel", minWidth:190, width:200, resizable:false, headerSort:true, responsive:0},
{title:"{{ __('Level') }}", field:"level_name", resizable:false, minWidth:150, headerSort:true, responsive:0}, {title:"{{ __('Level') }}", field:"level_name", resizable:false, minWidth:90, width:135, headerSort:true, responsive:0},
{title:"{{ __('Log') }}", field:"message", resizable:false, minWidth:550, headerSort:true, responsive:2}, {title:"{{ __('Log') }}", field:"message", resizable:false, minWidth:550, width:650, headerSort:true, responsive:2},
{title:"{{ __('Date') }}", field:"created_at", resizable:false, minWidth:250, headerSort:true, responsive:2}, {title:"{{ __('Date') }}", field:"created_at", resizable:false, minWidth:250, headerSort:true, responsive:2},
] ]
}); });

View file

@ -80,6 +80,9 @@
responsiveLayout: "collapse", responsiveLayout: "collapse",
responsiveLayoutCollapseStartOpen:false, responsiveLayoutCollapseStartOpen:false,
resizableColumns:false, resizableColumns:false,
initialSort:[
{column:"redate", dir:"desc"},
],
placeholder: "{{ __('No Data') }}", placeholder: "{{ __('No Data') }}",
columns:[ columns:[
{formatter:"responsiveCollapse", width:30, minWidth:30, hozAlign:"center", resizable:false, headerSort:false, responsive:0}, {formatter:"responsiveCollapse", width:30, minWidth:30, hozAlign:"center", resizable:false, headerSort:false, responsive:0},

View file

@ -576,6 +576,22 @@ function processDomainTransfer($conn, $db, $xml, $clid, $database_type, $trans)
$stmt = $db->prepare("UPDATE domain SET exdate = DATE_ADD(exdate, INTERVAL ? MONTH), lastupdate = CURRENT_TIMESTAMP(3), clid = ?, upid = ?, registrant = ?, trdate = CURRENT_TIMESTAMP(3), trstatus = 'clientApproved', acdate = CURRENT_TIMESTAMP(3), transfer_exdate = NULL, rgpstatus = 'transferPeriod', transferPeriod = ? WHERE id = ?"); $stmt = $db->prepare("UPDATE domain SET exdate = DATE_ADD(exdate, INTERVAL ? MONTH), lastupdate = CURRENT_TIMESTAMP(3), clid = ?, upid = ?, registrant = ?, trdate = CURRENT_TIMESTAMP(3), trstatus = 'clientApproved', acdate = CURRENT_TIMESTAMP(3), transfer_exdate = NULL, rgpstatus = 'transferPeriod', transferPeriod = ? WHERE id = ?");
$stmt->execute([$date_add, $row["reid"], $clid, $newRegistrantId, $date_add, $domain_id]); $stmt->execute([$date_add, $row["reid"], $clid, $newRegistrantId, $date_add, $domain_id]);
$stmt_log = $db->prepare("INSERT INTO error_log (channel, level, level_name, message, context, extra) VALUES (?, ?, ?, ?, ?, ?)");
$stmt_log->execute([
'domain_transfer',
250,
'NOTICE',
"Domain transfer manually approved: $domainName (New registrant: $newRegistrantId, Registrar: $reid)",
json_encode(['domain_id' => $domain_id, 'new_registrant' => $newRegistrantId, 'registrar' => $reid]),
json_encode([
'received_on' => date('Y-m-d H:i:s'),
'read_on' => null,
'is_read' => false,
'message_type' => 'manual_transfer_approval',
'performed_by' => $clid
])
]);
$stmt = $db->prepare('SELECT status FROM domain_status WHERE domain_id = ? AND status = ? LIMIT 1'); $stmt = $db->prepare('SELECT status FROM domain_status WHERE domain_id = ? AND status = ? LIMIT 1');
$stmt->execute([$domain_id, 'pendingTransfer']); $stmt->execute([$domain_id, 'pendingTransfer']);
$existingStatus = $stmt->fetchColumn(); $existingStatus = $stmt->fetchColumn();
@ -712,6 +728,22 @@ function processDomainTransfer($conn, $db, $xml, $clid, $database_type, $trans)
$stmt = $db->prepare("UPDATE domain SET trstatus = 'clientCancelled' WHERE id = :domain_id"); $stmt = $db->prepare("UPDATE domain SET trstatus = 'clientCancelled' WHERE id = :domain_id");
$stmt->execute(['domain_id' => $domain_id]); $stmt->execute(['domain_id' => $domain_id]);
$stmt_log = $db->prepare("INSERT INTO error_log (channel, level, level_name, message, context, extra) VALUES (?, ?, ?, ?, ?, ?)");
$stmt_log->execute([
'domain_transfer',
250,
'NOTICE',
"Domain transfer manually canceled: $domainName (Registrar: $reid)",
json_encode(['domain_id' => $domain_id, 'registrar' => $reid]),
json_encode([
'received_on' => date('Y-m-d H:i:s'),
'read_on' => null,
'is_read' => false,
'message_type' => 'manual_transfer_cancellation',
'performed_by' => $clid
])
]);
$stmt = $db->prepare('SELECT status FROM domain_status WHERE domain_id = ? AND status = ? LIMIT 1'); $stmt = $db->prepare('SELECT status FROM domain_status WHERE domain_id = ? AND status = ? LIMIT 1');
$stmt->execute([$domain_id, 'pendingTransfer']); $stmt->execute([$domain_id, 'pendingTransfer']);
$existingStatus = $stmt->fetchColumn(); $existingStatus = $stmt->fetchColumn();
@ -845,6 +877,22 @@ function processDomainTransfer($conn, $db, $xml, $clid, $database_type, $trans)
$stmtUpdate = $db->prepare("UPDATE domain SET trstatus = 'clientRejected' WHERE id = :domain_id"); $stmtUpdate = $db->prepare("UPDATE domain SET trstatus = 'clientRejected' WHERE id = :domain_id");
$success = $stmtUpdate->execute(['domain_id' => $domain_id]); $success = $stmtUpdate->execute(['domain_id' => $domain_id]);
$stmt_log = $db->prepare("INSERT INTO error_log (channel, level, level_name, message, context, extra) VALUES (?, ?, ?, ?, ?, ?)");
$stmt_log->execute([
'domain_transfer',
250,
'NOTICE',
"Domain transfer manually rejected: $domainName (Registrar: $reid)",
json_encode(['domain_id' => $domain_id, 'registrar' => $reid]),
json_encode([
'received_on' => date('Y-m-d H:i:s'),
'read_on' => null,
'is_read' => false,
'message_type' => 'manual_transfer_rejection',
'performed_by' => $clid
])
]);
$stmt = $db->prepare('SELECT status FROM domain_status WHERE domain_id = ? AND status = ? LIMIT 1'); $stmt = $db->prepare('SELECT status FROM domain_status WHERE domain_id = ? AND status = ? LIMIT 1');
$stmt->execute([$domain_id, 'pendingTransfer']); $stmt->execute([$domain_id, 'pendingTransfer']);
$existingStatus = $stmt->fetchColumn(); $existingStatus = $stmt->fetchColumn();