mirror of
https://github.com/getnamingo/registry.git
synced 2025-05-10 16:58:34 +02:00
75 lines
No EOL
2.8 KiB
PHP
75 lines
No EOL
2.8 KiB
PHP
<?php
|
|
|
|
$c = require_once 'config.php';
|
|
require_once 'helpers.php';
|
|
|
|
// Connect to the database
|
|
$dsn = "{$c['db_type']}:host={$c['db_host']};dbname={$c['db_database']};port={$c['db_port']}";
|
|
|
|
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());
|
|
}
|
|
|
|
// 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';
|
|
}
|
|
|
|
// 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);
|
|
|
|
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);
|
|
|
|
function extractDomainNameFromEmail($emailBody) {
|
|
// This is just a basic example
|
|
preg_match("/domain: (.*?) /i", $emailBody, $matches);
|
|
return $matches[1] ?? '';
|
|
} |