Notification system improvement

Also only registry can now approve and reject applications
This commit is contained in:
Pinga 2025-03-14 17:27:39 +02:00
parent edc2bdab04
commit f942607363
5 changed files with 105 additions and 19 deletions

View file

@ -467,8 +467,8 @@ class ApplicationsController extends Controller
'error_log', 'error_log',
[ [
'channel' => 'control_panel', 'channel' => 'control_panel',
'level' => 3, 'level' => 300,
'level_name' => 'warning', 'level_name' => 'WARNING',
'message' => "Application: $domainName; hostName: $nameserver - is duplicated", 'message' => "Application: $domainName; hostName: $nameserver - is duplicated",
'context' => json_encode([ 'context' => json_encode([
'registrar_id' => $clid, 'registrar_id' => $clid,
@ -589,6 +589,25 @@ class ApplicationsController extends Controller
} }
} }
$db->insert('error_log', [
'channel' => 'applications',
'level' => 250,
'level_name' => 'NOTICE',
'message' => "User {$_SESSION['auth_user_id']} from registrar {$clid} created a domain application: {$domainName}",
'context' => json_encode([
'domain_name' => $domainName,
'user_id' => $_SESSION['auth_user_id'],
'registrar' => $clid,
'status' => 'pending'
]),
'extra' => json_encode([
'received_on' => date('Y-m-d H:i:s'),
'read_on' => null,
'is_read' => false,
'message_type' => 'application_creation'
])
]);
$db->commit(); $db->commit();
} catch (Exception $e) { } catch (Exception $e) {
$db->rollBack(); $db->rollBack();
@ -1037,6 +1056,11 @@ class ApplicationsController extends Controller
public function approveApplication(Request $request, Response $response, $args) public function approveApplication(Request $request, Response $response, $args)
{ {
if ($_SESSION["auth_roles"] != 0) {
$this->container->get('flash')->addMessage('error', 'Only registry administrators can perform this action.');
return $response->withHeader('Location', '/applications')->withStatus(302);
}
// if ($request->getMethod() === 'POST') { // if ($request->getMethod() === 'POST') {
$db = $this->container->get('db'); $db = $this->container->get('db');
// Get the current URI // Get the current URI
@ -1249,6 +1273,25 @@ class ApplicationsController extends Controller
[$domain_id] [$domain_id]
); );
$db->insert('error_log', [
'channel' => 'applications',
'level' => 250,
'level_name' => 'NOTICE',
'message' => "User {$_SESSION['auth_user_id']} from registrar {$clid} approved the domain application: {$domainName}",
'context' => json_encode([
'domain_name' => $domainName,
'user_id' => $_SESSION['auth_user_id'],
'registrar' => $clid,
'status' => 'approved'
]),
'extra' => json_encode([
'received_on' => date('Y-m-d H:i:s'),
'read_on' => null,
'is_read' => false,
'message_type' => 'application_approval'
])
]);
$this->container->get('flash')->addMessage('success', 'Domain ' . $domainName . ' has been created successfully on ' . $crdate); $this->container->get('flash')->addMessage('success', 'Domain ' . $domainName . ' has been created successfully on ' . $crdate);
return $response->withHeader('Location', '/domains')->withStatus(302); return $response->withHeader('Location', '/domains')->withStatus(302);
} catch (Exception $e) { } catch (Exception $e) {
@ -1271,6 +1314,11 @@ class ApplicationsController extends Controller
public function rejectApplication(Request $request, Response $response, $args) public function rejectApplication(Request $request, Response $response, $args)
{ {
if ($_SESSION["auth_roles"] != 0) {
$this->container->get('flash')->addMessage('error', 'Only registry administrators can perform this action.');
return $response->withHeader('Location', '/applications')->withStatus(302);
}
// if ($request->getMethod() === 'POST') { // if ($request->getMethod() === 'POST') {
$db = $this->container->get('db'); $db = $this->container->get('db');
// Get the current URI // Get the current URI
@ -1323,6 +1371,25 @@ class ApplicationsController extends Controller
] ]
); );
$db->insert('error_log', [
'channel' => 'applications',
'level' => 250,
'level_name' => 'NOTICE',
'message' => "User {$_SESSION['auth_user_id']} from registrar {$clid} rejected the domain application: {$domainName}",
'context' => json_encode([
'domain_name' => $domainName,
'user_id' => $_SESSION['auth_user_id'],
'registrar' => $clid,
'status' => 'rejected'
]),
'extra' => json_encode([
'received_on' => date('Y-m-d H:i:s'),
'read_on' => null,
'is_read' => false,
'message_type' => 'application_rejection'
])
]);
$db->commit(); $db->commit();
} catch (Exception $e) { } catch (Exception $e) {
$db->rollBack(); $db->rollBack();
@ -1418,6 +1485,25 @@ class ApplicationsController extends Controller
] ]
); );
$db->insert('error_log', [
'channel' => 'applications',
'level' => 250, // NOTICE level
'level_name' => 'NOTICE',
'message' => "User {$_SESSION['auth_user_id']} from registrar {$clid} deleted the domain application: {$domainName}",
'context' => json_encode([
'domain_name' => $domainName,
'user_id' => $_SESSION['auth_user_id'],
'registrar' => $clid,
'status' => 'deleted'
]),
'extra' => json_encode([
'received_on' => date('Y-m-d H:i:s'),
'read_on' => null,
'is_read' => false,
'message_type' => 'application_deletion'
])
]);
$db->commit(); $db->commit();
} catch (Exception $e) { } catch (Exception $e) {
$db->rollBack(); $db->rollBack();

View file

@ -749,8 +749,8 @@ class DomainsController extends Controller
'error_log', 'error_log',
[ [
'channel' => 'control_panel', 'channel' => 'control_panel',
'level' => 3, 'level' => 300,
'level_name' => 'warning', 'level_name' => 'WARNING',
'message' => "Domain: $domainName; hostName: $nameserver - is duplicated", 'message' => "Domain: $domainName; hostName: $nameserver - is duplicated",
'context' => json_encode([ 'context' => json_encode([
'registrar_id' => $clid, 'registrar_id' => $clid,
@ -3129,7 +3129,7 @@ class DomainsController extends Controller
$db->exec( $db->exec(
'INSERT INTO error_log (channel, level, level_name, message, context, extra) VALUES (?, ?, ?, ?, ?, ?)', 'INSERT INTO error_log (channel, level, level_name, message, context, extra) VALUES (?, ?, ?, ?, ?, ?)',
[ [
'manual_transfer_reject', 'manual_transfer',
250, // NOTICE level 250, // NOTICE level
'NOTICE', 'NOTICE',
"Manual domain transfer rejected: $domainName (Losing Registrar: $clid)", "Manual domain transfer rejected: $domainName (Losing Registrar: $clid)",
@ -3239,7 +3239,7 @@ class DomainsController extends Controller
$db->exec( $db->exec(
'INSERT INTO error_log (channel, level, level_name, message, context, extra) VALUES (?, ?, ?, ?, ?, ?)', 'INSERT INTO error_log (channel, level, level_name, message, context, extra) VALUES (?, ?, ?, ?, ?, ?)',
[ [
'manual_transfer_cancel', 'manual_transfer',
250, // NOTICE level 250, // NOTICE level
'NOTICE', 'NOTICE',
"Manual domain transfer canceled: $domainName (Applicant: $clid)", "Manual domain transfer canceled: $domainName (Applicant: $clid)",

View file

@ -1367,7 +1367,7 @@ function processDomainCreate($conn, $db, $xml, $clid, $database_type, $trans, $m
} else { } else {
$errorLogStmt = $db->prepare("INSERT INTO error_log $errorLogStmt = $db->prepare("INSERT INTO error_log
(channel, level, level_name, message, context, extra, created_at) (channel, level, level_name, message, context, extra, created_at)
VALUES ('epp', 3, 'warning', :log, :context, '{}', CURRENT_TIMESTAMP)"); VALUES ('epp', 300, 'WARNING', :log, :context, '{}', CURRENT_TIMESTAMP)");
$errorLogStmt->execute([ $errorLogStmt->execute([
':log' => "Domain: $domainName; hostObj: $hostObj - is duplicated", ':log' => "Domain: $domainName; hostObj: $hostObj - is duplicated",
':context' => json_encode(['registrar_id' => $clid, 'domain' => $domainName, 'host' => $hostObj]) ':context' => json_encode(['registrar_id' => $clid, 'domain' => $domainName, 'host' => $hostObj])
@ -1437,7 +1437,7 @@ function processDomainCreate($conn, $db, $xml, $clid, $database_type, $trans, $m
// Log duplicate mapping error // Log duplicate mapping error
$stmt = $db->prepare("INSERT INTO error_log $stmt = $db->prepare("INSERT INTO error_log
(channel, level, level_name, message, context, extra, created_at) (channel, level, level_name, message, context, extra, created_at)
VALUES ('epp', 3, 'warning', ?, ?, '{}', CURRENT_TIMESTAMP)"); VALUES ('epp', 300, 'WARNING', ?, ?, '{}', CURRENT_TIMESTAMP)");
$stmt->execute([ $stmt->execute([
"Domain: $domainName; hostName: $hostName - duplicate mapping", "Domain: $domainName; hostName: $hostName - duplicate mapping",
json_encode(['registrar_id' => $clid, 'domain' => $domainName, 'host' => $hostName]) json_encode(['registrar_id' => $clid, 'domain' => $domainName, 'host' => $hostName])
@ -1736,7 +1736,7 @@ function processDomainCreate($conn, $db, $xml, $clid, $database_type, $trans, $m
} else { } else {
$errorLogStmt = $db->prepare("INSERT INTO error_log $errorLogStmt = $db->prepare("INSERT INTO error_log
(channel, level, level_name, message, context, extra, created_at) (channel, level, level_name, message, context, extra, created_at)
VALUES ('epp', 3, 'warning', :log, :context, '{}', CURRENT_TIMESTAMP)"); VALUES ('epp', 300, 'WARNING', :log, :context, '{}', CURRENT_TIMESTAMP)");
$errorLogStmt->execute([ $errorLogStmt->execute([
':log' => "Domain: $domainName; hostObj: $hostObj - is duplicated", ':log' => "Domain: $domainName; hostObj: $hostObj - is duplicated",
':context' => json_encode(['registrar_id' => $clid, 'domain' => $domainName, 'host' => $hostObj]) ':context' => json_encode(['registrar_id' => $clid, 'domain' => $domainName, 'host' => $hostObj])
@ -1806,7 +1806,7 @@ function processDomainCreate($conn, $db, $xml, $clid, $database_type, $trans, $m
// Log duplicate mapping error // Log duplicate mapping error
$stmt = $db->prepare("INSERT INTO error_log $stmt = $db->prepare("INSERT INTO error_log
(channel, level, level_name, message, context, extra, created_at) (channel, level, level_name, message, context, extra, created_at)
VALUES ('epp', 3, 'warning', ?, ?, '{}', CURRENT_TIMESTAMP)"); VALUES ('epp', 300, 'WARNING', ?, ?, '{}', CURRENT_TIMESTAMP)");
$stmt->execute([ $stmt->execute([
"Domain: $domainName; hostName: $hostName - duplicate mapping", "Domain: $domainName; hostName: $hostName - duplicate mapping",
json_encode(['registrar_id' => $clid, 'domain' => $domainName, 'host' => $hostName]) json_encode(['registrar_id' => $clid, 'domain' => $domainName, 'host' => $hostName])

View file

@ -578,7 +578,7 @@ function processDomainTransfer($conn, $db, $xml, $clid, $database_type, $trans)
$stmt_log = $db->prepare("INSERT INTO error_log (channel, level, level_name, message, context, extra) VALUES (?, ?, ?, ?, ?, ?)"); $stmt_log = $db->prepare("INSERT INTO error_log (channel, level, level_name, message, context, extra) VALUES (?, ?, ?, ?, ?, ?)");
$stmt_log->execute([ $stmt_log->execute([
'domain_transfer', 'manual_transfer',
250, 250,
'NOTICE', 'NOTICE',
"Domain transfer manually approved: $domainName (New registrant: $newRegistrantId, Registrar: $reid)", "Domain transfer manually approved: $domainName (New registrant: $newRegistrantId, Registrar: $reid)",
@ -730,7 +730,7 @@ function processDomainTransfer($conn, $db, $xml, $clid, $database_type, $trans)
$stmt_log = $db->prepare("INSERT INTO error_log (channel, level, level_name, message, context, extra) VALUES (?, ?, ?, ?, ?, ?)"); $stmt_log = $db->prepare("INSERT INTO error_log (channel, level, level_name, message, context, extra) VALUES (?, ?, ?, ?, ?, ?)");
$stmt_log->execute([ $stmt_log->execute([
'domain_transfer', 'manual_transfer',
250, 250,
'NOTICE', 'NOTICE',
"Domain transfer manually canceled: $domainName (Registrar: $reid)", "Domain transfer manually canceled: $domainName (Registrar: $reid)",
@ -879,7 +879,7 @@ function processDomainTransfer($conn, $db, $xml, $clid, $database_type, $trans)
$stmt_log = $db->prepare("INSERT INTO error_log (channel, level, level_name, message, context, extra) VALUES (?, ?, ?, ?, ?, ?)"); $stmt_log = $db->prepare("INSERT INTO error_log (channel, level, level_name, message, context, extra) VALUES (?, ?, ?, ?, ?, ?)");
$stmt_log->execute([ $stmt_log->execute([
'domain_transfer', 'manual_transfer',
250, 250,
'NOTICE', 'NOTICE',
"Domain transfer manually rejected: $domainName (Registrar: $reid)", "Domain transfer manually rejected: $domainName (Registrar: $reid)",

View file

@ -1537,7 +1537,7 @@ function processDomainUpdate($conn, $db, $xml, $clid, $database_type, $trans) {
]); ]);
$stmt = $db->prepare("INSERT INTO error_log $stmt = $db->prepare("INSERT INTO error_log
(channel, level, level_name, message, context, extra, created_at) (channel, level, level_name, message, context, extra, created_at)
VALUES ('epp', 3, 'warning', ?, ?, '{}', CURRENT_TIMESTAMP)"); VALUES ('epp', 300, 'WARNING', ?, ?, '{}', CURRENT_TIMESTAMP)");
$stmt->execute([$logMessage, $contextData]); $stmt->execute([$logMessage, $contextData]);
} }
} else { } else {