Improvements on the URS script

This commit is contained in:
Pinga 2023-11-13 14:54:18 +02:00
parent 647a1ae659
commit 9b183ddf5d
4 changed files with 43 additions and 16 deletions

View file

@ -31,4 +31,9 @@ return [
// Zone Writer Configuration // Zone Writer Configuration
'dns_server' => 'bind', 'dns_server' => 'bind',
// URS Configuration
'urs_imap_host' => '{your_imap_server:993/imap/ssl}INBOX',
'urs_imap_username' => 'your_username',
'urs_imap_password' => 'your_password',
]; ];

View file

@ -13,19 +13,16 @@ try {
die("Connection failed: " . $e->getMessage()); die("Connection failed: " . $e->getMessage());
} }
$hostname = '{your_imap_server:993/imap/ssl}INBOX';
$username = 'your_email@example.com';
$password = 'your_password';
// Connect to mailbox // Connect to mailbox
$inbox = imap_open($hostname, $username, $password) or die('Cannot connect to mailbox: ' . imap_last_error()); $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 // Search for emails from the two URS providers
$emailsFromProviderA = imap_search($inbox, 'FROM "providerA@example.com" UNSEEN'); $emailsFromProviderA = imap_search($inbox, 'FROM "urs@adrforum.com" UNSEEN');
$emailsFromProviderB = imap_search($inbox, 'FROM "providerB@example.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 // Combine the arrays of email IDs
$allEmails = array_merge($emailsFromProviderA, $emailsFromProviderB); $allEmails = array_merge($emailsFromProviderA, $emailsFromProviderB, $emailsFromProviderC);
foreach ($allEmails as $emailId) { foreach ($allEmails as $emailId) {
$header = imap_headerinfo($inbox, $emailId); $header = imap_headerinfo($inbox, $emailId);
@ -34,21 +31,44 @@ foreach ($allEmails as $emailId) {
$date = date('Y-m-d H:i:s', strtotime($header->date)) . '.000'; $date = date('Y-m-d H:i:s', strtotime($header->date)) . '.000';
// Determine the URS provider based on the email sender // Determine the URS provider based on the email sender
$ursProvider = ($from == 'providerA@example.com') ? 'URSPA' : 'URSPB'; $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) // 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); $body = imap_fetchbody($inbox, $emailId, 1);
$domainName = extractDomainNameFromEmail($body); // You'd have to define this function $domainName = extractDomainNameFromEmail($body);
// Insert into the database // Insert into the database
$stmt = $dbh->prepare("INSERT INTO urs_actions (domain_name, urs_provider, action_date, status) VALUES (?, ?, ?, ?)"); $stmt = $dbh->prepare("SELECT name, clid FROM domain WHERE name = ?");
$stmt->execute([$domainName, $ursProvider, $date, 'Suspended']); $stmt->execute([$domainName]);
$domain = $stmt->fetch(PDO::FETCH_ASSOC);
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 {
echo "Domain does not exists in registry.";
}
} }
imap_close($inbox); imap_close($inbox);
function extractDomainNameFromEmail($emailBody) { function extractDomainNameFromEmail($emailBody) {
// Placeholder function; you'd extract the domain name based on the email format/content
// This is just a basic example // This is just a basic example
preg_match("/domain: (.*?) /i", $emailBody, $matches); preg_match("/domain: (.*?) /i", $emailBody, $matches);
return $matches[1] ?? ''; return $matches[1] ?? '';

View file

@ -661,7 +661,8 @@ INSERT INTO `registry`.`ticket_categories` (name, description) VALUES
('Abuse Notifications', 'Reports of domain abusive practices as per ICANN guidelines'), ('Abuse Notifications', 'Reports of domain abusive practices as per ICANN guidelines'),
('General Inquiry', 'General questions or feedback about services, platform or any non-specific topic'), ('General Inquiry', 'General questions or feedback about services, platform or any non-specific topic'),
('Registrar Application', 'Queries or issues related to new registrar applications or onboarding'), ('Registrar Application', 'Queries or issues related to new registrar applications or onboarding'),
('RDAP Updates', 'Issues or queries related to the Registration Data Access Protocol (RDAP) updates'); ('RDAP Updates', 'Issues or queries related to the Registration Data Access Protocol (RDAP) updates'),
('URS Cases', 'Reports of URS cases');
INSERT INTO `registry`.`settings` (`name`, `value`) VALUES INSERT INTO `registry`.`settings` (`name`, `value`) VALUES
('dns-tcp-queries-received', '0'), ('dns-tcp-queries-received', '0'),

View file

@ -641,7 +641,8 @@ INSERT INTO registry.ticket_categories (name, description) VALUES
('Abuse Notifications', 'Reports of domain abusive practices as per ICANN guidelines'), ('Abuse Notifications', 'Reports of domain abusive practices as per ICANN guidelines'),
('General Inquiry', 'General questions or feedback about services, platform or any non-specific topic'), ('General Inquiry', 'General questions or feedback about services, platform or any non-specific topic'),
('Registrar Application', 'Queries or issues related to new registrar applications or onboarding'), ('Registrar Application', 'Queries or issues related to new registrar applications or onboarding'),
('RDAP Updates', 'Issues or queries related to the Registration Data Access Protocol (RDAP) updates'); ('RDAP Updates', 'Issues or queries related to the Registration Data Access Protocol (RDAP) updates'),
('URS Cases', 'Reports of URS cases');
INSERT INTO registry.settings (name, value) VALUES INSERT INTO registry.settings (name, value) VALUES
('dns-tcp-queries-received', '0'), ('dns-tcp-queries-received', '0'),