diff --git a/automation/crontab.example b/automation/crontab.example index 758b21a..dd6cde7 100644 --- a/automation/crontab.example +++ b/automation/crontab.example @@ -33,6 +33,12 @@ # run escrow.php every day 5 0 * * * root /usr/bin/php8.2 /opt/registry/automation/escrow.php +# run rdap-urls.php every day +50 1 * * * root /usr/bin/php8.2 /opt/registry/automation/rdap-urls.php + +# run file_cache.php every day +0 2 * * * root /usr/bin/php8.2 /var/www/cp/bin/file_cache.php + # run reporting.php every 1st day 1 0 1 * * root /usr/bin/php8.2 /opt/registry/automation/reporting.php diff --git a/automation/rdap-urls.php b/automation/rdap-urls.php new file mode 100644 index 0000000..1336fef --- /dev/null +++ b/automation/rdap-urls.php @@ -0,0 +1,65 @@ +info('job started.'); + +try { + $dbh = new PDO($dsn, $c['db_username'], $c['db_password']); + $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +} catch (PDOException $e) { + $log->error('DB Connection failed: ' . $e->getMessage()); +} + +// URL to the IANA file +$csv_url = 'https://www.iana.org/assignments/registrar-ids/registrar-ids-1.csv'; + +// Download IANA file +$ch = curl_init(); +curl_setopt($ch, CURLOPT_URL, $csv_url); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); +curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); +$userAgent = 'Namingo Registry/0.5 (+https://namingo.org)'; +curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); +$csv_data = curl_exec($ch); +if (curl_errno($ch)) { + $error_msg = curl_error($ch); +} +curl_close($ch); + +if ($csv_data === false) { + $log->error("Error downloading CSV file: " . $error_msg); +} + +// Parse CSV data +$rows = array_map("str_getcsv", explode("\n", $csv_data)); +$header = array_shift($rows); // Remove header + +foreach ($rows as $row) { + if (count($row) < 4 || empty($row[3])) { + // Skip rows with missing RDAP Base URL + continue; + } + + // Prepare SQL statement + $stmt = $dbh->prepare("UPDATE registrar SET rdap_server = :rdap_server WHERE iana_id = :iana_id"); + + // Bind parameters + $stmt->bindParam(':rdap_server', $row[3], PDO::PARAM_STR); + $stmt->bindParam(':iana_id', $row[0], PDO::PARAM_INT); + + // Execute and check for errors + try { + $stmt->execute(); + } catch (\PDOException $e) { + $log->error("Error updating ID {$row[0]}: " . $e->getMessage()); + } catch (Throwable $e) { + $log->error('Error: ' . $e->getMessage()); + } +} + +$log->info('job finished successfully.'); \ No newline at end of file diff --git a/rdap/start_rdap.php b/rdap/start_rdap.php index d4fac32..119885d 100644 --- a/rdap/start_rdap.php +++ b/rdap/start_rdap.php @@ -539,7 +539,7 @@ function handleDomainQuery($request, $response, $pdo, $domainName, $c, $log) { 'type' => 'application/rdap+json', ], [ - 'href' => 'https://' . $registrarDetails['rdap_server'] . '/domain/' . $domain, + 'href' => $registrarDetails['rdap_server'] . 'domain/' . $domain, 'rel' => 'related', 'type' => 'application/rdap+json', ] @@ -1771,7 +1771,7 @@ function handleDomainSearchQuery($request, $response, $pdo, $searchPattern, $c, 'type' => 'application/rdap+json', ], [ - 'href' => 'https://' . $registrarDetails['rdap_server'] . '/domain/' . $domain, + 'href' => $registrarDetails['rdap_server'] . 'domain/' . $domain, 'rel' => 'related', 'type' => 'application/rdap+json', ]