mirror of
https://github.com/getnamingo/registry.git
synced 2025-07-14 14:55:06 +02:00
LORDN script improvement
This commit is contained in:
parent
c681d32977
commit
d3b3ebb6ed
2 changed files with 60 additions and 27 deletions
|
@ -15,44 +15,58 @@ $log = setupLogger($logFilePath, 'Lordn');
|
||||||
$log->info('job started.');
|
$log->info('job started.');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$dbh = new PDO($dsn, $c['db_username'], $c['db_password'], $options);
|
$pdo = new PDO($dsn, $c['db_username'], $c['db_password'], $options);
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
$log->error('DB Connection failed: ' . $e->getMessage());
|
$log->error('DB Connection failed: ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetching TLDs
|
// Fetching TLDs
|
||||||
$stmt = $dbh->query("SELECT id, tld FROM domain_tld;");
|
$stmt = $pdo->query("SELECT id, tld FROM domain_tld;");
|
||||||
$tlds = $stmt->fetchAll();
|
$tlds = $stmt->fetchAll();
|
||||||
|
|
||||||
foreach ($tlds as $tld) {
|
foreach ($tlds as $tld) {
|
||||||
$stmt = $dbh->prepare("SELECT phase_type, phase_description FROM launch_phases WHERE tld_id = ?");
|
try {
|
||||||
$stmt->execute([$tld['id']]);
|
$stmt = $pdo->prepare("SELECT phase_type, phase_description FROM launch_phases WHERE tld_id = ?");
|
||||||
$launchPhase = $stmt->fetch();
|
$stmt->execute([$tld['id']]);
|
||||||
|
$launchPhase = $stmt->fetch();
|
||||||
|
|
||||||
if ($launchPhase) {
|
if ($launchPhase) {
|
||||||
if ($launchPhase['phase_type'] == 'sunrise') {
|
if ($launchPhase['phase_type'] == 'sunrise') {
|
||||||
// Generate Sunrise LORDN file
|
// Generate Sunrise LORDN file
|
||||||
generateSunriseLordn($dbh, $tld, $c['lordn_user'], $c['lordn_pass']);
|
generateSunriseLordn($pdo, $tld, $c['lordn_user'], $c['lordn_pass'], $log);
|
||||||
} elseif ($launchPhase['phase_type'] == 'claims' || strpos($launchPhase['phase_description'], 'claims') !== false) {
|
} elseif ($launchPhase['phase_type'] == 'claims' || strpos($launchPhase['phase_description'], 'claims') !== false) {
|
||||||
// Generate Claims LORDN file
|
// Generate Claims LORDN file
|
||||||
generateClaimsLordn($dbh, $tld, $c['lordn_user'], $c['lordn_pass']);
|
generateClaimsLordn($pdo, $tld, $c['lordn_user'], $c['lordn_pass'], $log);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$log->info("No launch phase found for TLD {$tld['tld']}.");
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
$log->error("Error processing TLD {$tld['tld']}: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
$log->info('job finished successfully.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateSunriseLordn($dbh, $tld, $username, $password) {
|
$log->info('job finished successfully.');
|
||||||
|
|
||||||
|
function generateSunriseLordn($pdo, $tld, $username, $password, $log) {
|
||||||
$dateStamp = date('Ymd');
|
$dateStamp = date('Ymd');
|
||||||
$tldName = ltrim($tld['tld'], '.'); // Remove leading dot
|
$tldName = ltrim($tld['tld'], '.'); // Remove leading dot
|
||||||
$fileName = "sunrise_lordn_{$tldName}_{$dateStamp}.csv";
|
$fileName = "sunrise_lordn_{$tldName}_{$dateStamp}.csv";
|
||||||
$file = fopen($fileName, 'w');
|
$file = fopen($fileName, 'w');
|
||||||
|
|
||||||
|
if (!$file) {
|
||||||
|
$log->error("Unable to open file {$fileName} for writing.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch data from your database
|
// Fetch data from your database
|
||||||
$stmt = $dbh->prepare("SELECT id, name, smd, clid, crdate FROM application WHERE tldid = ?");
|
$stmt = $pdo->prepare("SELECT id, name, smd, clid, crdate FROM application WHERE tldid = ?");
|
||||||
$stmt->execute([$tld['id']]);
|
$stmt->execute([$tld['id']]);
|
||||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
$log->info("Creating LORDN file {$fileName} with " . count($rows) . " entries.");
|
||||||
|
|
||||||
// First row: version, creation datetime, number of lines
|
// First row: version, creation datetime, number of lines
|
||||||
fputcsv($file, [1, gmdate('Y-m-d\TH:i:s\Z'), count($rows)]);
|
fputcsv($file, [1, gmdate('Y-m-d\TH:i:s\Z'), count($rows)]);
|
||||||
|
|
||||||
|
@ -68,20 +82,33 @@ function generateSunriseLordn($dbh, $tld, $username, $password) {
|
||||||
|
|
||||||
// Upload the file
|
// Upload the file
|
||||||
$uploadUrl = "https://<tmdb-domain-name>/LORDN/{$tldName}/sunrise";
|
$uploadUrl = "https://<tmdb-domain-name>/LORDN/{$tldName}/sunrise";
|
||||||
uploadFile($fileName, $uploadUrl, $username, $password);
|
$result = uploadFile($fileName, $uploadUrl, $username, $password, $log);
|
||||||
|
|
||||||
|
if ($result['transactionId']) {
|
||||||
|
$log->info("LORDN upload successful for {$tld['tld']} ({$fileName}). Transaction ID: {$result['transactionId']}");
|
||||||
|
} else {
|
||||||
|
$log->warning("LORDN upload for {$tld['tld']} ({$fileName}) did not return a transaction ID.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateClaimsLordn($dbh, $tld, $username, $password) {
|
function generateClaimsLordn($pdo, $tld, $username, $password, $log) {
|
||||||
$dateStamp = date('Ymd');
|
$dateStamp = date('Ymd');
|
||||||
$tldName = ltrim($tld['tld'], '.'); // Remove leading dot
|
$tldName = ltrim($tld['tld'], '.'); // Remove leading dot
|
||||||
$fileName = "claims_lordn_{$tldName}_{$dateStamp}.csv";
|
$fileName = "claims_lordn_{$tldName}_{$dateStamp}.csv";
|
||||||
$file = fopen($fileName, 'w');
|
$file = fopen($fileName, 'w');
|
||||||
|
|
||||||
|
if (!$file) {
|
||||||
|
$log->error("Unable to open file {$fileName} for writing.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch data from your database
|
// Fetch data from your database
|
||||||
$stmt = $dbh->prepare("SELECT id, name, notice_id, clid, crdate, ack_datetime FROM domain WHERE tldid = ?");
|
$stmt = $pdo->prepare("SELECT id, name, notice_id, clid, crdate, ack_datetime FROM domain WHERE tldid = ?");
|
||||||
$stmt->execute([$tld['id']]);
|
$stmt->execute([$tld['id']]);
|
||||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
$log->info("Creating LORDN file {$fileName} with " . count($rows) . " entries.");
|
||||||
|
|
||||||
// First row: version, creation datetime, number of lines
|
// First row: version, creation datetime, number of lines
|
||||||
fputcsv($file, [1, gmdate('Y-m-d\TH:i:s\Z'), count($rows)]);
|
fputcsv($file, [1, gmdate('Y-m-d\TH:i:s\Z'), count($rows)]);
|
||||||
|
|
||||||
|
@ -99,10 +126,16 @@ function generateClaimsLordn($dbh, $tld, $username, $password) {
|
||||||
|
|
||||||
// Upload the file
|
// Upload the file
|
||||||
$uploadUrl = "https://<tmdb-domain-name>/LORDN/{$tldName}/claims";
|
$uploadUrl = "https://<tmdb-domain-name>/LORDN/{$tldName}/claims";
|
||||||
uploadFile($fileName, $uploadUrl, $username, $password);
|
$result = uploadFile($fileName, $uploadUrl, $username, $password, $log);
|
||||||
|
|
||||||
|
if ($result['transactionId']) {
|
||||||
|
$log->info("LORDN upload successful for {$tld['tld']} ({$fileName}). Transaction ID: {$result['transactionId']}");
|
||||||
|
} else {
|
||||||
|
$log->warning("LORDN upload for {$tld['tld']} ({$fileName}) did not return a transaction ID.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function uploadFile($filePath, $uploadUrl, $username, $password) {
|
function uploadFile($filePath, $uploadUrl, $username, $password, $log) {
|
||||||
$curl = curl_init();
|
$curl = curl_init();
|
||||||
$fileData = file_get_contents($filePath);
|
$fileData = file_get_contents($filePath);
|
||||||
|
|
||||||
|
@ -133,19 +166,19 @@ function uploadFile($filePath, $uploadUrl, $username, $password) {
|
||||||
}
|
}
|
||||||
} elseif ($httpCode === 400) {
|
} elseif ($httpCode === 400) {
|
||||||
// Syntax of the LORDN file is incorrect
|
// Syntax of the LORDN file is incorrect
|
||||||
echo "Error 400: Incorrect syntax - " . $body;
|
$log->error("Error 400: Incorrect syntax - " . $body);
|
||||||
} elseif ($httpCode === 401) {
|
} elseif ($httpCode === 401) {
|
||||||
// Unauthorized
|
// Unauthorized
|
||||||
echo "Error 401: Unauthorized";
|
$log->error("Error 401: Unauthorized");
|
||||||
} elseif ($httpCode === 404) {
|
} elseif ($httpCode === 404) {
|
||||||
// Not found, typically outside of a QLP Period
|
// Not found, typically outside of a QLP Period
|
||||||
echo "Error 404: Not Found";
|
$log->error("Error 404: Not Found");
|
||||||
} elseif ($httpCode === 500) {
|
} elseif ($httpCode === 500) {
|
||||||
// Server error
|
// Server error
|
||||||
echo "Error 500: Server error";
|
$log->error("Error 500: Server error");
|
||||||
} else {
|
} else {
|
||||||
// Other errors
|
// Other errors
|
||||||
echo "Error: HTTP status code " . $httpCode;
|
$log->error("Error: HTTP status code " . $httpCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_close($curl);
|
curl_close($curl);
|
||||||
|
|
|
@ -23,7 +23,7 @@ $ch = curl_init();
|
||||||
curl_setopt($ch, CURLOPT_URL, $csv_url);
|
curl_setopt($ch, CURLOPT_URL, $csv_url);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
||||||
$userAgent = 'Namingo Registry/0.5 (+https://namingo.org)';
|
$userAgent = 'Namingo Registry/1.0 (+https://namingo.org)';
|
||||||
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
|
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
|
||||||
$csv_data = curl_exec($ch);
|
$csv_data = curl_exec($ch);
|
||||||
if (curl_errno($ch)) {
|
if (curl_errno($ch)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue