Domain expiration dates

- Update logic in post when adding/editing a domain to better account for null values
- Update logic in cron domain refresher to account for null values
- Prevent cron domain refresher getting stuck on a single domain
- Exclude domains with no expiration date from the cron nightly renewal alerts
This commit is contained in:
Marcus Hill
2024-02-22 21:51:12 +00:00
parent 4fddeb88b7
commit 66dc7e799b
3 changed files with 47 additions and 24 deletions

View File

@@ -41,12 +41,20 @@ if ( $argv[1] !== $config_cron_key ) {
// END ERROR
// REFRESH DOMAIN WHOIS DATA (1 a day)
// Get the oldest updated domain (MariaDB shows NULLs first when ordering by default)
$row = mysqli_fetch_array(mysqli_query($mysqli, "SELECT domain_id, domain_name FROM `domains` ORDER BY domain_updated_at LIMIT 1"));
$row = mysqli_fetch_array(mysqli_query($mysqli, "SELECT domain_id, domain_name, domain_expire FROM `domains` ORDER BY domain_updated_at LIMIT 1"));
if ($row) {
// Get current data in database
$domain_id = intval($row['domain_id']);
$domain_name = sanitizeInput($row['domain_name']);
$current_expire = sanitizeInput($row['domain_expire']);
echo "Renewing $domain_name";
// Touch the record we're refreshing to ensure we don't loop
mysqli_query($mysqli, "UPDATE domains SET domain_updated_at = NOW() WHERE domain_id = $domain_id");
// Lookup fresh info
$expire = getDomainExpirationDate($domain_name);
$records = getDomainRecords($domain_name);
$a = sanitizeInput($records['a']);
@@ -55,16 +63,18 @@ if ($row) {
$txt = sanitizeInput($records['txt']);
$whois = sanitizeInput($records['whois']);
if (
$expire === 'NULL'
&& $row['domain_expire'] !== null
&& (new DateTime($row['domain_expire'])) >= (new DateTime())
) {
$expire = $row['domain_expire'];
// Handle expiry date
if (strtotime($expire)) {
$expire = "'" . $expire . "'"; // Valid
} elseif (!strtotime($expire) && strtotime($current_expire)) {
// New expiry date is invalid, but old one is OK - reverting back
$expire = "'" . $current_expire . "'";
} else {
// Neither are valid, setting expiry to NULL
$expire = 'NULL';
}
// Update the domain
mysqli_query($mysqli, "UPDATE domains SET domain_name = '$domain_name', domain_expire = '$expire', domain_ip = '$a', domain_name_servers = '$ns', domain_mail_servers = '$mx', domain_txt = '$txt', domain_raw_whois = '$whois' WHERE domain_id = $domain_id");
}
// TODO: Re-add the cert refresher
// Update the domain
mysqli_query($mysqli, "UPDATE domains SET domain_name = '$domain_name', domain_expire = $expire, domain_ip = '$a', domain_name_servers = '$ns', domain_mail_servers = '$mx', domain_txt = '$txt', domain_raw_whois = '$whois' WHERE domain_id = $domain_id");
}