Skip to content

Commit

Permalink
Merge pull request #888 from wrongecho/dns-expiry-null-fix
Browse files Browse the repository at this point in the history
Domain expiration dates
  • Loading branch information
johnnyq authored Feb 23, 2024
2 parents 31184f0 + dae51c9 commit 603d677
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
$mysqli,
"SELECT * FROM domains
LEFT JOIN clients ON domain_client_id = client_id
WHERE domain_expire = CURDATE() + INTERVAL $day DAY"
WHERE domain_expire IS NOT NULL AND domain_expire = CURDATE() + INTERVAL $day DAY"
);

while ($row = mysqli_fetch_array($sql)) {
Expand Down
29 changes: 19 additions & 10 deletions cron_domain_refresher.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,19 @@
// 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']);

// 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']);
Expand All @@ -55,16 +62,18 @@
$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");
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
35 changes: 24 additions & 11 deletions post/domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
$expire = sanitizeInput($_POST['expire']);
$notes = sanitizeInput($_POST['notes']);

if (empty($expire)) {
$expire = "NULL";
} else {
// Set/check/lookup expiry date
if (strtotime($expire)) {
$expire = "'" . $expire . "'";
}

// Get domain expiry date - if not specified
if ($expire == 'NULL') {
else {
$expire = getDomainExpirationDate($name);
$expire = "'" . $expire . "'";
if (strtotime($expire)) {
$expire = "'" . $expire . "'";
} else {
$expire = 'NULL';
}
}

// NS, MX, A and WHOIS records/data
Expand All @@ -39,7 +40,6 @@
// Add domain record
mysqli_query($mysqli,"INSERT INTO domains SET domain_name = '$name', domain_registrar = $registrar, domain_webhost = $webhost, domain_expire = $expire, domain_ip = '$a', domain_name_servers = '$ns', domain_mail_servers = '$mx', domain_txt = '$txt', domain_raw_whois = '$whois', domain_notes = '$notes', domain_client_id = $client_id");


// Get inserted ID (for linking certificate, if exists)
$domain_id = mysqli_insert_id($mysqli);

Expand Down Expand Up @@ -74,9 +74,22 @@
$expire = sanitizeInput($_POST['expire']);
$notes = sanitizeInput($_POST['notes']);

if (empty($expire) || (new DateTime($expire)) < (new DateTime())) {
// Update domain expiry date
// if (empty($expire) || (new DateTime($expire)) < (new DateTime())) {
// // Update domain expiry date
// $expire = getDomainExpirationDate($name);
// }

// Set/check/lookup expiry date
if (strtotime($expire) && (new DateTime($expire)) > (new DateTime())) {
$expire = "'" . $expire . "'";
}
else {
$expire = getDomainExpirationDate($name);
if (strtotime($expire)) {
$expire = "'" . $expire . "'";
} else {
$expire = 'NULL';
}
}

$client_id = intval($_POST['client_id']);
Expand All @@ -89,7 +102,7 @@
$txt = sanitizeInput($records['txt']);
$whois = sanitizeInput($records['whois']);

mysqli_query($mysqli,"UPDATE domains SET domain_name = '$name', domain_registrar = $registrar, domain_webhost = $webhost, domain_expire = '$expire', domain_ip = '$a', domain_name_servers = '$ns', domain_mail_servers = '$mx', domain_txt = '$txt', domain_raw_whois = '$whois', domain_notes = '$notes' WHERE domain_id = $domain_id");
mysqli_query($mysqli,"UPDATE domains SET domain_name = '$name', domain_registrar = $registrar, domain_webhost = $webhost, domain_expire = $expire, domain_ip = '$a', domain_name_servers = '$ns', domain_mail_servers = '$mx', domain_txt = '$txt', domain_raw_whois = '$whois', domain_notes = '$notes' WHERE domain_id = $domain_id");

//Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Domain', log_action = 'Modify', log_description = '$session_name modified domain $name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $domain_id");
Expand Down

0 comments on commit 603d677

Please sign in to comment.