From ecd83b6b11f1016cba63d7b6ffe396293e56fa69 Mon Sep 17 00:00:00 2001 From: wrongecho Date: Fri, 17 Jan 2025 21:39:11 +0000 Subject: [PATCH] Add domain history to domain refresher --- functions.php | 34 +++++++++++----------- post/user/domain.php | 6 ---- scripts/cron_domain_refresher.php | 47 ++++++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 24 deletions(-) diff --git a/functions.php b/functions.php index 225e3128..1bcc9349 100644 --- a/functions.php +++ b/functions.php @@ -422,46 +422,46 @@ function getDomainRecords($name) $records['ns'] = trim(strip_tags(shell_exec("dig +short NS $domain"))); $records['mx'] = trim(strip_tags(shell_exec("dig +short MX $domain"))); $records['txt'] = trim(strip_tags(shell_exec("dig +short TXT $domain"))); - $records['whois'] = substr(trim(strip_tags(shell_exec("whois -H $domain | sed 's/ //g' | head -30"))), 0, 255); + $records['whois'] = substr(trim(strip_tags(shell_exec("whois -H $domain | head -30 | sed 's/ //g'"))), 0, 254); // Sort A records (if multiple records exist) if (!empty($records['a'])) { - $aRecords = explode("\n", $records['a']); - array_walk($aRecords, function(&$record) { + $a_records = explode("\n", $records['a']); + array_walk($a_records, function(&$record) { $record = trim($record); }); - sort($aRecords); - $records['a'] = implode("\n", $aRecords); + sort($a_records); + $records['a'] = implode("\n", $a_records); } // Sort NS records (if multiple records exist) if (!empty($records['ns'])) { - $nsRecords = explode("\n", $records['ns']); - array_walk($nsRecords, function(&$record) { + $ns_records = explode("\n", $records['ns']); + array_walk($ns_records, function(&$record) { $record = trim($record); }); - sort($nsRecords); - $records['ns'] = implode("\n", $nsRecords); + sort($ns_records); + $records['ns'] = implode("\n", $ns_records); } // Sort MX records (if multiple records exist) if (!empty($records['mx'])) { - $mxRecords = explode("\n", $records['mx']); - array_walk($mxRecords, function(&$record) { + $mx_records = explode("\n", $records['mx']); + array_walk($mx_records, function(&$record) { $record = trim($record); }); - sort($mxRecords); - $records['mx'] = implode("\n", $mxRecords); + sort($mx_records); + $records['mx'] = implode("\n", $mx_records); } // Sort TXT records (if multiple records exist) if (!empty($records['txt'])) { - $txtRecords = explode("\n", $records['txt']); - array_walk($txtRecords, function(&$record) { + $txt_records = explode("\n", $records['txt']); + array_walk($txt_records, function(&$record) { $record = trim($record); }); - sort($txtRecords); - $records['txt'] = implode("\n", $txtRecords); + sort($txt_records); + $records['txt'] = implode("\n", $txt_records); } return $records; diff --git a/post/user/domain.php b/post/user/domain.php index 38484e49..28807307 100644 --- a/post/user/domain.php +++ b/post/user/domain.php @@ -68,12 +68,6 @@ if (isset($_POST['edit_domain'])) { require_once 'domain_model.php'; $domain_id = intval($_POST['domain_id']); - -// 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 . "'"; diff --git a/scripts/cron_domain_refresher.php b/scripts/cron_domain_refresher.php index f08ddf05..441265eb 100644 --- a/scripts/cron_domain_refresher.php +++ b/scripts/cron_domain_refresher.php @@ -39,7 +39,7 @@ if ( $argv[1] !== $config_cron_key ) { // REFRESH DOMAIN WHOIS DATA (1 a day/run) // 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, domain_expire 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` WHERE domain_archived_at IS NULL ORDER BY domain_updated_at LIMIT 1")); if ($row) { @@ -71,7 +71,52 @@ if ($row) { $expire = 'NULL'; } + // Current domain info + $original_domain_info = mysqli_fetch_assoc(mysqli_query($mysqli," + SELECT + domains.*, + registrar.vendor_name AS registrar_name, + dnshost.vendor_name AS dnshost_name, + mailhost.vendor_name AS mailhost_name, + webhost.vendor_name AS webhost_name + FROM domains + LEFT JOIN vendors AS registrar ON domains.domain_registrar = registrar.vendor_id + LEFT JOIN vendors AS dnshost ON domains.domain_dnshost = dnshost.vendor_id + LEFT JOIN vendors AS mailhost ON domains.domain_mailhost = mailhost.vendor_id + LEFT JOIN vendors AS webhost ON domains.domain_webhost = webhost.vendor_id + WHERE domain_id = $domain_id + ")); // 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"); + echo "Updated $domain_name."; + + // Fetch updated info + $new_domain_info = mysqli_fetch_assoc(mysqli_query($mysqli," + SELECT + domains.*, + registrar.vendor_name AS registrar_name, + dnshost.vendor_name AS dnshost_name, + mailhost.vendor_name AS mailhost_name, + webhost.vendor_name AS webhost_name + FROM domains + LEFT JOIN vendors AS registrar ON domains.domain_registrar = registrar.vendor_id + LEFT JOIN vendors AS dnshost ON domains.domain_dnshost = dnshost.vendor_id + LEFT JOIN vendors AS mailhost ON domains.domain_mailhost = mailhost.vendor_id + LEFT JOIN vendors AS webhost ON domains.domain_webhost = webhost.vendor_id + WHERE domain_id = $domain_id + ")); + + // Compare/log changes + $ignored_columns = ["domain_updated_at", "domain_accessed_at", "domain_registrar", "domain_webhost", "domain_dnshost", "domain_mailhost"]; + foreach ($original_domain_info as $column => $old_value) { + $new_value = $new_domain_info[$column]; + if ($old_value != $new_value && !in_array($column, $ignored_columns)) { + $column = sanitizeInput($column); + $old_value = sanitizeInput($old_value); + $new_value = sanitizeInput($new_value); + mysqli_query($mysqli,"INSERT INTO domain_history SET domain_history_column = '$column', domain_history_old_value = '$old_value', domain_history_new_value = '$new_value', domain_history_domain_id = $domain_id"); + } + } + }