mirror of
https://github.com/itflow-org/itflow
synced 2026-11-30 08:09:00 +00:00
Domains makeover: rebuilt domains list with expiry pills (red expired, amber close, blue close but auto-renewing), registrar and hosts shown once per vendor with their roles, SPF/DMARC/DKIM email pills, filters for Starred, Expiring in 45 days, Expired, No auto-renew and Email gaps with counts, registrar-or-host and tag filters, search across notes, hosts and tag names, safe column sorting, open straight to a domain with ?open=ID; new domain quick look with expiry, auto-renew, registration date and status, who registers it and hosts DNS, website and email, A/NS/MX records to copy, plain-language email checks (SPF strictness and duplicates, DMARC policy, DKIM at common selectors), certificates, services, the registrar and host logins, notes, TXT records, raw WHOIS and history; tabbed add/edit form that tidies pasted addresses to the domain, checks the name as it is typed (saved as, subdomain, already on the client), auto-renew switch, star, tags, client and our own vendors as registrar and hosts, Registrar does it all; add several domains at once from a pasted list; bulk look up now, set registrar or host, tags, star and unstar; domain tags (tag type 7) with a starter pack; refresher looks up a batch of up to 50 a run, never-checked, stale and soon-to-expire first; expiry alerts skip archived domains and clients, mention auto-renew and open the domain; vendor Domains tab opens the quick look and adds a domain with that vendor as registrar, our vendors get a Client domains tab; service quick look, overview renewals and search open the domain; client portal shows days to expiry and auto-renew; more export columns and filters; demo data with auto-renew, varied DMARC and DKIM, WHOIS lines and campaign domains near expiry. Fixes lookups, edits, the refresher and API updates wiping expiry dates and records when a lookup came back empty, edits logged without a client and dropping a past expiry date, every edit running slow lookups, expiry alerts for archived domains, deleted domains left on services and certificates, bulk archive needing delete rights and list actions limited to admins, registrar and host pickers accepting another client's vendors and dropping our own on save, services linking other clients' domains, a new client's website domain not added when its expiry could not be found, the WHOIS summary cut at 254 characters, and API names, vendors and duplicates not checked. Adds functions/domain.php helpers, domain quick look and shared form, domain_check lookup; removes domain_model.php. DB 2.8.3
This commit is contained in:
32
admin/database_updates/2.8.3.php
Normal file
32
admin/database_updates/2.8.3.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - Database update to version 2.8.3 (from 2.8.2)
|
||||
* Included by admin/database_updates.php - do not access directly
|
||||
*/
|
||||
|
||||
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
|
||||
|
||||
// Domain tags (tag type 7) - Primary, Parked, Client-owned, Managed DNS and so on
|
||||
mysqli_query($mysqli, "CREATE TABLE IF NOT EXISTS `domain_tags` (
|
||||
`domain_id` int(11) NOT NULL,
|
||||
`tag_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`domain_id`, `tag_id`),
|
||||
KEY `tag_id` (`tag_id`),
|
||||
CONSTRAINT `domain_tags_ibfk_1` FOREIGN KEY (`domain_id`) REFERENCES `domains` (`domain_id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `domain_tags_ibfk_2` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`tag_id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci");
|
||||
|
||||
// Whether it renews by itself at the registrar, its DMARC record and the
|
||||
// DKIM selectors found, and when the lookups last came back with something
|
||||
mysqli_query($mysqli, "ALTER TABLE `domains`
|
||||
ADD COLUMN `domain_auto_renew` tinyint(1) NOT NULL DEFAULT 0 AFTER `domain_expire`,
|
||||
ADD COLUMN `domain_dmarc` text DEFAULT NULL AFTER `domain_txt`,
|
||||
ADD COLUMN `domain_dkim` varchar(255) DEFAULT NULL AFTER `domain_dmarc`,
|
||||
ADD COLUMN `domain_refreshed_at` datetime DEFAULT NULL AFTER `domain_accessed_at`
|
||||
");
|
||||
|
||||
// Domains deleted before deletes cleared their references left services and
|
||||
// certificates pointing at an id that no longer exists
|
||||
mysqli_query($mysqli, "DELETE `service_domains` FROM `service_domains` LEFT JOIN `domains` ON `domains`.`domain_id` = `service_domains`.`domain_id` WHERE `domains`.`domain_id` IS NULL");
|
||||
mysqli_query($mysqli, "UPDATE `certificates` LEFT JOIN `domains` ON `domain_id` = `certificate_domain_id` SET `certificate_domain_id` = 0 WHERE `certificate_domain_id` > 0 AND `domain_id` IS NULL");
|
||||
@@ -19,6 +19,8 @@ if (isset($_GET['type'])) {
|
||||
$type_display = "Asset";
|
||||
} elseif ($type === 6) {
|
||||
$type_display = "Vendor";
|
||||
} elseif ($type === 7) {
|
||||
$type_display = "Domain";
|
||||
}
|
||||
}
|
||||
ob_start();
|
||||
|
||||
@@ -24,6 +24,8 @@ if ($tag_type == 1) {
|
||||
$tag_type_display = "Asset";
|
||||
} elseif ($tag_type == 6) {
|
||||
$tag_type_display = "Vendor";
|
||||
} elseif ($tag_type == 7) {
|
||||
$tag_type_display = "Domain";
|
||||
} else {
|
||||
$tag_type_display = "Unknown";
|
||||
}
|
||||
|
||||
@@ -1283,28 +1283,63 @@ function demoBuildClient($mysqli, $profile, $index, $context, &$counts) {
|
||||
demoBuildNetworkIps($mysqli, $profile, $assets, $network_ids, $counts);
|
||||
demoBuildPatchPanel($mysqli, $profile, $assets, $network_ids, $months, $counts);
|
||||
|
||||
// Domain, DNS and the certificate on it
|
||||
// Domain, DNS and the certificate on it. Half renew by themselves; the
|
||||
// email records vary so the Email checks have something to say - DMARC
|
||||
// enforced, monitoring only, or missing
|
||||
$domain_auto_renew = $index % 2;
|
||||
$domain_m365 = strpos($profile['mail_servers'], 'google') === false;
|
||||
$domain_id = starterInsert($mysqli, 'domains', [
|
||||
'domain_name' => $profile['domain'],
|
||||
'domain_description' => 'Primary domain - website and email',
|
||||
'domain_expire' => demoDate(-1 * (60 + ($index * 21))),
|
||||
'domain_auto_renew' => $domain_auto_renew,
|
||||
'domain_ip' => '203.0.113.' . (10 + $index),
|
||||
'domain_name_servers' => 'ns1.' . $profile['dns_host'] . ', ns2.' . $profile['dns_host'],
|
||||
'domain_raw_whois' => 'Registrar: Harbour Registrar Services. Status: clientTransferProhibited. Registrant: ' . $profile['name'] . '.',
|
||||
'domain_mail_servers' => $profile['mail_servers'],
|
||||
'domain_name_servers' => 'ns1.' . $profile['dns_host'] . "\nns2." . $profile['dns_host'],
|
||||
'domain_raw_whois' => "Registrar: Harbour Registrar Services\nRegistered: " . demoDate(365 * (6 + $index % 9) + $index * 11) . "\nExpires: " . demoDate(-1 * (60 + ($index * 21))) . "\nStatus: client transfer prohibited\nNameservers: ns1." . $profile['dns_host'] . ', ns2.' . $profile['dns_host'],
|
||||
'domain_mail_servers' => '0 ' . $profile['mail_servers'],
|
||||
'domain_dmarc' => [0 => 'v=DMARC1; p=reject; rua=mailto:dmarc@' . $profile['domain'], 1 => 'v=DMARC1; p=none; rua=mailto:dmarc@' . $profile['domain'], 2 => ''][$index % 3],
|
||||
'domain_dkim' => $index % 4 === 3 ? '' : ($domain_m365 ? "selector1\nselector2" : 'google'),
|
||||
'domain_refreshed_at' => demoDateTime(1 + $index % 6, 4, 0),
|
||||
// These three are vendor IDs, not names - who hosts the site, who runs
|
||||
// DNS, and who the mail lands with
|
||||
'domain_webhost' => intval($profile['build'] === 1 ? ($context['org_vendors']['Nextcloud Hosting Partner'] ?? 0) : $primary_vendor_id),
|
||||
'domain_dnshost' => intval($primary_vendor_id),
|
||||
'domain_mailhost' => intval($context['org_vendors']['Cascade Cloud Licensing'] ?? 0),
|
||||
'domain_txt' => 'v=spf1 include:' . $profile['dns_host'] . ' -all',
|
||||
'domain_notes' => 'Registrar login is held in the credential vault. Renewal is set to manual so it cannot lapse without a ticket.',
|
||||
'domain_txt' => 'v=spf1 include:' . $profile['dns_host'] . ' -all' . ($domain_m365 ? "\nMS=ms" . substr(demoSerial($profile['domain'], 8), 0, 8) : "\ngoogle-site-verification=" . strtolower(demoSerial($profile['domain'], 20))),
|
||||
'domain_notes' => 'Registrar login is held in the credential vault. ' . ($domain_auto_renew ? 'Auto-renew is on and charged to the card on file - check it before the card expires.' : 'Renewal is set to manual so it cannot lapse without a ticket.'),
|
||||
'domain_registrar' => $primary_vendor_id,
|
||||
'domain_client_id' => $client_id,
|
||||
'domain_created_at' => demoMonthDateTime($months, 7, 9, 45),
|
||||
'domain_accessed_at' => demoDateTime($index % 13, 15, 5),
|
||||
]);
|
||||
|
||||
demoAttachTags($mysqli, 'domain_tags', 'domain_id', 'tag_id', $domain_id, 7, ['Primary', 'Managed DNS']);
|
||||
|
||||
// Every third client also keeps a campaign domain nobody remembers - parked,
|
||||
// no mail, and close to lapsing or already lapsed
|
||||
if ($index % 3 === 0) {
|
||||
$campaign_days = $index % 2 ? -12 : 20;
|
||||
$campaign_domain_id = starterInsert($mysqli, 'domains', [
|
||||
'domain_name' => 'get' . $profile['domain'],
|
||||
'domain_description' => 'Old campaign domain - forwards to the main site',
|
||||
'domain_expire' => demoDate(-1 * $campaign_days),
|
||||
'domain_auto_renew' => 0,
|
||||
'domain_ip' => '203.0.113.' . (10 + $index),
|
||||
'domain_name_servers' => 'ns1.' . $profile['dns_host'] . "\nns2." . $profile['dns_host'],
|
||||
'domain_txt' => 'v=spf1 -all',
|
||||
'domain_dmarc' => 'v=DMARC1; p=reject',
|
||||
'domain_raw_whois' => "Registrar: Harbour Registrar Services\nRegistered: " . demoDate(365 * 3 + $index) . "\nStatus: client transfer prohibited",
|
||||
'domain_notes' => 'Ask the client whether to keep it before it renews.',
|
||||
'domain_registrar' => $primary_vendor_id,
|
||||
'domain_dnshost' => intval($primary_vendor_id),
|
||||
'domain_client_id' => $client_id,
|
||||
'domain_created_at' => demoMonthDateTime($months, 7, 10, 5),
|
||||
'domain_refreshed_at' => demoDateTime(2 + $index % 5, 4, 0),
|
||||
]);
|
||||
demoAttachTags($mysqli, 'domain_tags', 'domain_id', 'tag_id', $campaign_domain_id, 7, ['Parked', 'Marketing']);
|
||||
$counts['documentation']++;
|
||||
}
|
||||
|
||||
$certificate_id = starterInsert($mysqli, 'certificates', [
|
||||
'certificate_name' => 'www.' . $profile['domain'],
|
||||
'certificate_description' => $profile['cert_issuer'] === "Let's Encrypt" ? 'Public website certificate, renewed automatically by the reverse proxy' : 'Public website certificate, renewed manually at expiry',
|
||||
|
||||
@@ -30,7 +30,7 @@ function starterContentPacks() {
|
||||
'tags' => [
|
||||
'label' => 'Tags',
|
||||
'icon' => 'fa-tags',
|
||||
'description' => 'Client, location, contact, credential, asset and vendor tags.',
|
||||
'description' => 'Client, location, contact, credential, asset, vendor and domain tags.',
|
||||
],
|
||||
'ticket_templates' => [
|
||||
'label' => 'Ticket Templates',
|
||||
@@ -675,6 +675,14 @@ function starterContentTags() {
|
||||
[6, 'Hosting', '#17a2b8', 'globe'],
|
||||
[6, 'Professional Services', '#343a40', 'briefcase'],
|
||||
[6, 'Authorised Contacts Only', '#d81b60', 'user-lock'],
|
||||
|
||||
// Domain
|
||||
[7, 'Primary', '#007bff', 'star'],
|
||||
[7, 'Client-owned', '#6f42c1', 'user-tie'],
|
||||
[7, 'Managed DNS', '#20c997', 'sitemap'],
|
||||
[7, 'Parked', '#adb5bd', 'parking'],
|
||||
[7, 'Marketing', '#fd7e14', 'bullhorn'],
|
||||
[7, 'Do Not Renew', '#dc3545', 'ban'],
|
||||
];
|
||||
|
||||
return $tags;
|
||||
|
||||
@@ -20,6 +20,7 @@ $tag_types = [
|
||||
4 => ['label' => 'Credential', 'icon' => 'fa-key'],
|
||||
5 => ['label' => 'Asset', 'icon' => 'fa-desktop'],
|
||||
6 => ['label' => 'Vendor', 'icon' => 'fa-building'],
|
||||
7 => ['label' => 'Domain', 'icon' => 'fa-globe'],
|
||||
];
|
||||
|
||||
// Label for the selected type
|
||||
|
||||
@@ -1780,24 +1780,63 @@ if (isset($_GET['ai_ticket_summary'])) {
|
||||
}
|
||||
|
||||
// Stops people trying to use sub-domains in the domains tracker
|
||||
if (isset($_GET['apex_domain_check'])) {
|
||||
/*
|
||||
* The domain name in a New / Edit Domain form, checked as it is typed: what it
|
||||
* is saved as, whether DNS answers for it, whether it looks like a subdomain
|
||||
* of one that does, and whether the client has it already.
|
||||
*/
|
||||
if (isset($_GET['domain_check'])) {
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$domain = escapeSql($_GET['domain']);
|
||||
$input = (string) ($_GET['domain'] ?? '');
|
||||
$name = domainNormalizeName($input);
|
||||
$check_client_id = intval($_GET['client_id'] ?? 0);
|
||||
$check_domain_id = intval($_GET['domain_id'] ?? 0);
|
||||
$response = ['state' => '', 'message' => '', 'name' => $name];
|
||||
|
||||
$response['message'] = ""; // default
|
||||
if (trim($input) === '') {
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
if ($name === '') {
|
||||
echo json_encode(['state' => 'bad', 'message' => "That isn't a domain name - something like example.com.", 'name' => '']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (strlen($domain) >= 4) {
|
||||
$saved_as = strcasecmp(trim($input), $name) !== 0 ? "Saved as $name. " : '';
|
||||
|
||||
// SOA record check
|
||||
// This isn't 100%, as sub-domains can have their own SOA but will capture 99%
|
||||
if (!checkdnsrr($domain, 'SOA')) {
|
||||
$response['message'] = "<i class='fas fa-fw fa-exclamation-triangle me-2'></i> Domain name is invalid.";
|
||||
// Already on this client?
|
||||
if ($check_client_id) {
|
||||
$client_id = $check_client_id;
|
||||
enforceClientAccess();
|
||||
$name_sql = escapeSql($name);
|
||||
if (mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM domains WHERE domain_name = '$name_sql' AND domain_client_id = $check_client_id AND domain_id <> $check_domain_id LIMIT 1"))) {
|
||||
echo json_encode(['state' => 'bad', 'message' => $saved_as . "$name is already on this client.", 'name' => $name]);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (@checkdnsrr($name, 'SOA')) {
|
||||
$response = ['state' => 'ok', 'message' => $saved_as . 'Found in DNS - its records and expiry are looked up when it is saved.', 'name' => $name];
|
||||
} else {
|
||||
// Nothing for the name itself - is it a subdomain of one that does answer?
|
||||
$parts = explode('.', $name);
|
||||
$parent = '';
|
||||
while (count($parts) > 2) {
|
||||
array_shift($parts);
|
||||
$candidate = implode('.', $parts);
|
||||
if (@checkdnsrr($candidate, 'SOA')) {
|
||||
$parent = $candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$response = $parent
|
||||
? ['state' => 'warn', 'message' => $saved_as . "That looks like a subdomain of $parent - add $parent instead, unless it is registered on its own.", 'name' => $name]
|
||||
: ['state' => 'warn', 'message' => $saved_as . "Nothing answers for it in DNS yet - check the spelling. It can still be saved.", 'name' => $name];
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Get internal users/techs
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Domains - one client's, or every domain the agent can see from All Client
|
||||
* Docs. Starred first. Each row has when it expires (and whether it renews
|
||||
* by itself), who registers it and who hosts DNS, the website and email, and
|
||||
* how its email is protected (SPF, DMARC, DKIM). The pills along the top
|
||||
* count and filter the ones to act on: expiring soon, expired, email gaps.
|
||||
*/
|
||||
|
||||
// Default Column Sortby Filter
|
||||
$sort = "domain_name";
|
||||
$order = "ASC";
|
||||
@@ -9,100 +17,145 @@ if (isset($_GET['client_id'])) {
|
||||
require_once "includes/inc_all_client.php";
|
||||
$client_query = "AND domain_client_id = $client_id";
|
||||
$client_url = "client_id=$client_id&";
|
||||
// Overide Filter Header Archived
|
||||
if (isset($_GET['archived']) && $_GET['archived'] == 1) {
|
||||
$archived = 1;
|
||||
$archive_query = "domain_archived_at IS NOT NULL";
|
||||
} else {
|
||||
$archived = 0;
|
||||
$archive_query = "domain_archived_at IS NULL";
|
||||
}
|
||||
$archived = isset($_GET['archived']) && $_GET['archived'] == 1 ? 1 : 0;
|
||||
$archive_query = $archived ? "domain_archived_at IS NOT NULL" : "domain_archived_at IS NULL";
|
||||
} else {
|
||||
require_once "includes/inc_client_overview_all.php";
|
||||
$client_query = '';
|
||||
$client_url = '';
|
||||
// Overide Filter Header Archived
|
||||
if (isset($_GET['archived']) && $_GET['archived'] == 1) {
|
||||
$archived = 1;
|
||||
$archive_query = "(client_archived_at IS NOT NULL OR domain_archived_at IS NOT NULL)";
|
||||
} else {
|
||||
$archived = 0;
|
||||
$archive_query = "(client_archived_at IS NULL AND domain_archived_at IS NULL)";
|
||||
}
|
||||
$archived = isset($_GET['archived']) && $_GET['archived'] == 1 ? 1 : 0;
|
||||
$archive_query = $archived ? "(client_archived_at IS NOT NULL OR domain_archived_at IS NOT NULL)" : "(client_archived_at IS NULL AND domain_archived_at IS NULL)";
|
||||
}
|
||||
|
||||
// Perms
|
||||
enforceUserPermission('module_support');
|
||||
|
||||
// Expiring In Filter
|
||||
if (isset($_GET['expire_days']) && !empty($_GET['expire_days'])) {
|
||||
if ($_GET['expire_days'] == "expired") {
|
||||
$expire_days = "expired";
|
||||
$expire_query = "AND (domain_expire IS NOT NULL AND domain_expire != '0000-00-00' AND domain_expire < CURDATE())";
|
||||
} else {
|
||||
$expire_days = intval($_GET['expire_days']);
|
||||
$expire_query = "AND (domain_expire IS NOT NULL AND domain_expire != '0000-00-00' AND domain_expire BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL $expire_days DAY))";
|
||||
}
|
||||
$can_edit = domainCan(2);
|
||||
$can_delete = domainCan(3) && !empty($config_destructive_deletes_enable);
|
||||
|
||||
// Client Filter (all clients)
|
||||
$client = '';
|
||||
if (!$client_url && !empty($_GET['client'])) {
|
||||
$client = intval($_GET['client']);
|
||||
$client_query = "AND domain_client_id = $client";
|
||||
}
|
||||
|
||||
// Vendor Filter - the registrar or any of the hosts
|
||||
$vendor_filter = intval($_GET['vendor'] ?? 0);
|
||||
$vendor_query = $vendor_filter ? "AND $vendor_filter IN (domain_registrar, domain_dnshost, domain_webhost, domain_mailhost)" : '';
|
||||
|
||||
// Tags Filter - a domain with any of them
|
||||
if (isset($_GET['tags']) && is_array($_GET['tags']) && !empty($_GET['tags'])) {
|
||||
$tag_filter = implode(",", array_map('intval', $_GET['tags']));
|
||||
$tag_query = "AND domains.domain_id IN (SELECT domain_id FROM domain_tags WHERE tag_id IN ($tag_filter))";
|
||||
} else {
|
||||
// Default - any
|
||||
$expire_days = '';
|
||||
$expire_query = '';
|
||||
$tag_filter = 0;
|
||||
$tag_query = '';
|
||||
}
|
||||
|
||||
if (!$client_url) {
|
||||
// Client Filter
|
||||
if (isset($_GET['client']) & !empty($_GET['client'])) {
|
||||
$client_query = 'AND (domain_client_id = ' . intval($_GET['client']) . ')';
|
||||
$client = intval($_GET['client']);
|
||||
} else {
|
||||
// Default - any
|
||||
$client_query = '';
|
||||
$client = '';
|
||||
}
|
||||
// Which ones - the pills along the top. The old "Expiring in" filter
|
||||
// (?expire_days=30 from the dashboard and the expiry notifications) still works.
|
||||
$soon_days = DOMAIN_SOON_DAYS;
|
||||
$shows = [
|
||||
'' => ['label' => 'All', 'where' => ''],
|
||||
'starred' => ['label' => 'Starred', 'icon' => 'fa-star', 'where' => 'domains.domain_favorite = 1'],
|
||||
'soon' => ['label' => "Expiring in $soon_days days", 'icon' => 'fa-hourglass-half', 'where' => "domains.domain_expire BETWEEN CURDATE() AND CURDATE() + INTERVAL $soon_days DAY"],
|
||||
'expired' => ['label' => 'Expired', 'icon' => 'fa-calendar-times', 'where' => 'domains.domain_expire < CURDATE()'],
|
||||
'noauto' => ['label' => 'No auto-renew', 'icon' => 'fa-hand-paper', 'where' => 'domains.domain_auto_renew = 0'],
|
||||
'mail' => ['label' => 'Email gaps', 'icon' => 'fa-envelope-open-text', 'where' => domainMailGapSql()],
|
||||
];
|
||||
$show = isset($shows[$_GET['show'] ?? '']) ? ($_GET['show'] ?? '') : '';
|
||||
$show_query = $shows[$show]['where'] ? 'AND ' . $shows[$show]['where'] : '';
|
||||
|
||||
$expire_days = $_GET['expire_days'] ?? '';
|
||||
$expire_query = '';
|
||||
if ($expire_days === 'expired') {
|
||||
$expire_query = 'AND domains.domain_expire < CURDATE()';
|
||||
} elseif (intval($expire_days) > 0) {
|
||||
$expire_query = 'AND domains.domain_expire BETWEEN CURDATE() AND CURDATE() + INTERVAL ' . intval($expire_days) . ' DAY';
|
||||
}
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS domains.*, clients.*,
|
||||
registrar.vendor_id AS registrar_id,
|
||||
registrar.vendor_name AS registrar_name,
|
||||
dnshost.vendor_id AS dnshost_id,
|
||||
dnshost.vendor_name AS dnshost_name,
|
||||
mailhost.vendor_id AS mailhost_id,
|
||||
mailhost.vendor_name AS mailhost_name,
|
||||
webhost.vendor_id AS webhost_id,
|
||||
webhost.vendor_name AS webhost_name
|
||||
FROM domains
|
||||
LEFT JOIN clients ON client_id = domain_client_id
|
||||
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 (domains.domain_name LIKE '%$q%' OR domains.domain_description LIKE '%$q%' OR registrar.vendor_name LIKE '%$q%' OR dnshost.vendor_name LIKE '%$q%' OR mailhost.vendor_name LIKE '%$q%' OR webhost.vendor_name LIKE '%$q%' OR client_name LIKE '%$q%')
|
||||
AND $archive_query
|
||||
" . clientScopeSql('domain_client_id') . "
|
||||
$client_query
|
||||
$expire_query
|
||||
ORDER BY $sort $order LIMIT $record_from, $record_to");
|
||||
// Only these sort - filter_header.php will hand through any lowercase word, and
|
||||
// an unknown column takes the page down with a mysqli exception
|
||||
$sortable_columns = ['domain_name' => 'domains.domain_name', 'domain_expire' => 'domains.domain_expire', 'registrar_name' => 'registrar.vendor_name',
|
||||
'client_name' => 'client_name', 'domain_created_at' => 'domains.domain_created_at', 'domain_refreshed_at' => 'domains.domain_refreshed_at'];
|
||||
if (!isset($sortable_columns[$sort])) {
|
||||
$sort = 'domain_name';
|
||||
}
|
||||
// Domains without an expiry go last whichever way the expiry is sorted
|
||||
$sort_sql = ($sort === 'domain_expire' ? 'domains.domain_expire IS NULL, ' : '') . $sortable_columns[$sort] . " $order";
|
||||
|
||||
[$domain_columns, $domain_joins] = domainSelectSql();
|
||||
$search_query = "AND (domains.domain_name LIKE '%$q%' OR domains.domain_description LIKE '%$q%' OR domains.domain_notes LIKE '%$q%'
|
||||
OR registrar.vendor_name LIKE '%$q%' OR dnshost.vendor_name LIKE '%$q%' OR mailhost.vendor_name LIKE '%$q%' OR webhost.vendor_name LIKE '%$q%' OR client_name LIKE '%$q%'
|
||||
OR domains.domain_id IN (SELECT domain_id FROM domain_tags JOIN tags USING (tag_id) WHERE tag_name LIKE '%$q%'))";
|
||||
$scope_query = clientScopeSql('domain_client_id');
|
||||
$filters = "$archive_query $tag_query $vendor_query $search_query $expire_query $scope_query $client_query";
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS $domain_columns
|
||||
FROM domains $domain_joins
|
||||
WHERE $filters $show_query
|
||||
ORDER BY domains.domain_favorite DESC, $sort_sql, domains.domain_name ASC LIMIT $record_from, $record_to");
|
||||
|
||||
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
|
||||
$domains = [];
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$domains[intval($row['domain_id'])] = $row;
|
||||
}
|
||||
$domains_tags = tagsForRecords('domain', array_keys($domains));
|
||||
|
||||
// How many of each, for the pills - everything in scope, before the pill itself
|
||||
$count_sql = [];
|
||||
foreach ($shows as $key => $s) {
|
||||
$count_sql[] = $key === '' ? 'COUNT(*)' : "COALESCE(SUM({$s['where']}), 0)";
|
||||
}
|
||||
$row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT " . implode(', ', $count_sql) . " FROM domains $domain_joins WHERE $filters"));
|
||||
$counts = [];
|
||||
foreach (array_keys($shows) as $i => $key) {
|
||||
$counts[$key] = intval($row[$i]);
|
||||
}
|
||||
|
||||
$filter_url = function ($changes) {
|
||||
$params = array_merge($_GET, $changes);
|
||||
unset($params['page']);
|
||||
return '?' . http_build_query(array_filter($params, function ($v) { return $v !== '' && $v !== null; }));
|
||||
};
|
||||
|
||||
// Vendors for the filter - the ones registering or hosting a domain in this scope
|
||||
$sql_vendors_filter = mysqli_query($mysqli, "SELECT DISTINCT vendor_id, vendor_name, vendor_description, vendor_client_id FROM vendors
|
||||
JOIN domains ON vendor_id IN (domain_registrar, domain_dnshost, domain_webhost, domain_mailhost)
|
||||
LEFT JOIN clients ON client_id = domain_client_id
|
||||
WHERE $archive_query $scope_query $client_query
|
||||
ORDER BY vendor_name ASC");
|
||||
|
||||
// Vendors the bulk "set registrar or host" offers - the client's and ours, or only ours across clients
|
||||
$bulk_vendor_options = $can_edit ? domainVendorChoices($client_url ? $client_id : 0) : [];
|
||||
|
||||
?>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header bg-dark py-2">
|
||||
<h3 class="card-title mt-2"><i class="fa fa-fw fa-globe me-2"></i>Domains</h3>
|
||||
<div class="card-tools">
|
||||
<?php if ($can_edit || $num_rows[0]) { ?>
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary ajax-modal" data-modal-url="modals/domain/domain_add.php?<?= $client_url ?>"><i class="fas fa-plus me-2"></i>New Domain</button>
|
||||
<?php if ($can_edit) { ?>
|
||||
<button type="button" class="btn btn-primary ajax-modal" data-modal-size="lg" data-modal-url="modals/domain/domain_add.php?<?= $client_url ?>">
|
||||
<i class="fas fa-plus me-2"></i>New Domain
|
||||
</button>
|
||||
<?php } ?>
|
||||
<?php if ($num_rows[0] > 0) { ?>
|
||||
<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown"></button>
|
||||
<div class="dropdown-menu">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle <?= $can_edit ? 'dropdown-toggle-split' : '' ?>" data-bs-toggle="dropdown"><?= $can_edit ? '' : '<i class="fas fa-ellipsis-h"></i>' ?></button>
|
||||
<div class="dropdown-menu dropdown-menu-end">
|
||||
<a class="dropdown-item text-dark ajax-modal" href="#"
|
||||
data-modal-url="<?= buildExportModalUrl('modals/domain/domain_export.php', ['client_id', 'client', 'expire_days', 'archived', 'q']) ?>">
|
||||
data-modal-url="<?= buildExportModalUrl('modals/domain/domain_export.php', ['client_id', 'client', 'expire_days', 'archived', 'q', 'tags', 'vendor']) ?>">
|
||||
<i class="fa fa-fw fa-download me-2"></i>Export
|
||||
</a>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -112,275 +165,262 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
<input type="hidden" name="client_id" value="<?= $client_id ?>">
|
||||
<?php } ?>
|
||||
<input type="hidden" name="archived" value="<?= $archived ?>">
|
||||
<input type="hidden" name="show" value="<?= escapeHtml($show) ?>">
|
||||
<div class="row g-2 align-items-center">
|
||||
<div class="col-md-4">
|
||||
<div class="col-lg-3 col-md-6">
|
||||
<div class="input-group">
|
||||
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) { echo stripslashes(escapeHtml($q)); } ?>" placeholder="Search Domains">
|
||||
<button class="btn btn-dark" title="Search"><i class="fa fa-search"></i></button>
|
||||
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) { echo stripslashes(escapeHtml($q)); } ?>" placeholder="Search domain, registrar, host, notes...">
|
||||
<button class="btn btn-dark" title="Search"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-3 col-md-6">
|
||||
<select onchange="this.form.submit()" class="form-select select2" name="tags[]" data-placeholder="- Tags -" multiple>
|
||||
<?php
|
||||
// Tags in use on domains in this scope, plus any already picked
|
||||
$sql_tags_filter = mysqli_query($mysqli, "
|
||||
SELECT tag_id, tag_name, tag_color, tag_icon FROM tags
|
||||
WHERE tag_type = 7
|
||||
AND (
|
||||
EXISTS (SELECT 1 FROM domain_tags JOIN domains ON domains.domain_id = domain_tags.domain_id
|
||||
WHERE domain_tags.tag_id = tags.tag_id " . clientScopeSql('domain_client_id') . " $client_query)
|
||||
OR tag_id IN ($tag_filter)
|
||||
)
|
||||
ORDER BY tag_name ASC
|
||||
");
|
||||
while ($row = mysqli_fetch_assoc($sql_tags_filter)) {
|
||||
$tag_id = intval($row['tag_id']); ?>
|
||||
<option value="<?= $tag_id ?>" <?php if (isset($_GET['tags']) && is_array($_GET['tags']) && in_array($tag_id, $_GET['tags'])) { echo 'selected'; } ?><?= selectOptionColor($row['tag_color'] ?? '', $row['tag_icon'] ?? '') ?>><?= escapeHtml($row['tag_name']) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="<?= $client_url ? 'col-lg-4' : 'col-lg-2' ?> col-md-6">
|
||||
<select class="form-select select2" name="vendor" onchange="this.form.submit()">
|
||||
<option value="">- Any registrar or host -</option>
|
||||
<?php while ($row = mysqli_fetch_assoc($sql_vendors_filter)) {
|
||||
$vendor_id = intval($row['vendor_id']); ?>
|
||||
<option <?= $vendor_filter === $vendor_id ? 'selected' : '' ?> value="<?= $vendor_id ?>"<?= selectOptionVendor($row['vendor_name'], intval($row['vendor_client_id']) === 0 ? 'Ours' : $row['vendor_description']) ?>><?= escapeHtml($row['vendor_name']) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<?php if (!$client_url) { ?>
|
||||
<div class="col-md-2">
|
||||
<div class="input-group">
|
||||
<select class="form-select select2" name="client" onchange="this.form.submit()">
|
||||
<option value="" <?php if ($client == "") { echo "selected"; } ?>>- All Clients -</option>
|
||||
|
||||
<?php
|
||||
<div class="col-lg-2 col-md-6">
|
||||
<select class="form-select select2" name="client" onchange="this.form.submit()">
|
||||
<option value="" <?php if ($client == "") { echo "selected"; } ?>>- All Clients -</option>
|
||||
<?php
|
||||
$sql_clients_filter = mysqli_query($mysqli, "
|
||||
SELECT DISTINCT client_id, client_name, client_abbreviation
|
||||
FROM clients
|
||||
JOIN domains ON domain_client_id = client_id
|
||||
WHERE $archive_query
|
||||
" . clientScopeSql('clients.client_id') . "
|
||||
ORDER BY client_name ASC
|
||||
");
|
||||
while ($row = mysqli_fetch_assoc($sql_clients_filter)) {
|
||||
$client_id = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']);
|
||||
?>
|
||||
<option <?php if ($client == $client_id) { echo "selected"; } ?> value="<?= $client_id ?>"<?= selectOptionClient($row['client_id'], $row['client_name'], $row['client_abbreviation'] ?? '') ?>><?= $client_name ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
SELECT DISTINCT client_id, client_name, client_abbreviation
|
||||
FROM clients
|
||||
JOIN domains ON domain_client_id = client_id
|
||||
WHERE $archive_query
|
||||
" . clientScopeSql('clients.client_id') . "
|
||||
ORDER BY client_name ASC
|
||||
");
|
||||
while ($row = mysqli_fetch_assoc($sql_clients_filter)) {
|
||||
$client_id_filter = intval($row['client_id']); ?>
|
||||
<option <?php if ($client == $client_id_filter) { echo "selected"; } ?> value="<?= $client_id_filter ?>"<?= selectOptionClient($row['client_id'], $row['client_name'], $row['client_abbreviation'] ?? '') ?>><?= escapeHtml($row['client_name']) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="col-md-2">
|
||||
<div class="input-group">
|
||||
<select class="form-select select2" name="expire_days" onchange="this.form.submit()">
|
||||
<option value="" <?php if ($expire_days == "") { echo "selected"; } ?>>- Expiring In -</option>
|
||||
<option value="expired" <?php if ($expire_days === "expired") { echo "selected"; } ?>>Expired</option>
|
||||
<option value="7" <?php if ($expire_days === 7) { echo "selected"; } ?>>7 Days</option>
|
||||
<option value="30" <?php if ($expire_days === 30) { echo "selected"; } ?>>30 Days</option>
|
||||
<option value="45" <?php if ($expire_days === 45) { echo "selected"; } ?>>45 Days</option>
|
||||
<option value="60" <?php if ($expire_days === 60) { echo "selected"; } ?>>60 Days</option>
|
||||
<option value="90" <?php if ($expire_days === 90) { echo "selected"; } ?>>90 Days</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($client_url) { // filler ?>
|
||||
<div class="col-md-2"></div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="col-md-4">
|
||||
<div class="btn-group float-end">
|
||||
<a href="?<?= $client_url ?>archived=<?php if($archived == 1){ echo 0; } else { echo 1; } ?>"
|
||||
class="btn btn-<?php if($archived == 1){ echo"primary"; } else { echo "default"; } ?>">
|
||||
<i class="fa fa-fw fa-archive me-2"></i>Archived
|
||||
<div class="col-lg-2 col-md-6">
|
||||
<div class="d-flex justify-content-end gap-2">
|
||||
<a href="<?= escapeHtml($filter_url(['archived' => $archived ? '' : 1])) ?>"
|
||||
class="btn <?= $archived ? 'btn-dark' : 'btn-outline-dark' ?>" title="<?= $archived ? 'Back to active domains' : 'Show archived domains' ?>">
|
||||
<i class="fa fa-fw fa-archive"></i><span class="d-lg-none ms-2">Archived</span>
|
||||
</a>
|
||||
<div class="dropdown ms-2" id="bulkActionButton" hidden>
|
||||
<?php if ($can_edit) { ?>
|
||||
<div class="dropdown" id="bulkActionButton" hidden>
|
||||
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">
|
||||
<i class="fas fa-fw fa-layer-group me-2"></i>Bulk Action (<span id="selectedCount">0</span>)
|
||||
</button>
|
||||
<div class="dropdown-menu">
|
||||
<div class="dropdown-menu dropdown-menu-end">
|
||||
<?php if (!$archived) { ?>
|
||||
<button class="dropdown-item" type="submit" form="bulkActions" name="bulk_refresh_domains">
|
||||
<i class="fas fa-fw fa-sync-alt me-2"></i>Look up now
|
||||
</button>
|
||||
<a class="dropdown-item" href="#" data-bs-toggle="modal" data-bs-target="#domainBulkVendorModal">
|
||||
<i class="fas fa-fw fa-building me-2"></i>Set registrar or host
|
||||
</a>
|
||||
<?php } ?>
|
||||
<a class="dropdown-item" href="#" data-tag-picker data-tag-entity="domain" data-tag-bulk data-csrf="<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-tags me-2"></i>Tags
|
||||
</a>
|
||||
<button class="dropdown-item" type="submit" form="bulkActions" name="bulk_favorite_domains">
|
||||
<i class="fas fa-fw fa-star text-warning me-2"></i>Star
|
||||
</button>
|
||||
<button class="dropdown-item" type="submit" form="bulkActions" name="bulk_unfavorite_domains">
|
||||
<i class="far fa-fw fa-star me-2"></i>Unstar
|
||||
</button>
|
||||
<div class="dropdown-divider"></div>
|
||||
<?php if ($archived) { ?>
|
||||
<button class="dropdown-item text-info"
|
||||
type="submit" form="bulkActions" name="bulk_restore_domains">
|
||||
<i class="fas fa-fw fa-redo me-2"></i>Restore
|
||||
</button>
|
||||
<div class="dropdown-divider"></div>
|
||||
<button class="dropdown-item text-danger text-bold"
|
||||
type="submit" form="bulkActions" name="bulk_delete_domains">
|
||||
<i class="fas fa-fw fa-trash me-2"></i>Delete
|
||||
</button>
|
||||
<button class="dropdown-item text-info" type="submit" form="bulkActions" name="bulk_restore_domains">
|
||||
<i class="fas fa-fw fa-redo me-2"></i>Restore
|
||||
</button>
|
||||
<?php if ($can_delete) { ?>
|
||||
<button class="dropdown-item text-danger text-bold confirm-link" type="submit" form="bulkActions" name="bulk_delete_domains"
|
||||
data-confirm-text="The domains go for good, with their history. Services and certificates stop pointing at them.">
|
||||
<i class="fas fa-fw fa-trash me-2"></i>Delete
|
||||
</button>
|
||||
<?php } ?>
|
||||
<?php } else { ?>
|
||||
<button class="dropdown-item"
|
||||
type="submit" form="bulkActions" name="bulk_refresh_domains">
|
||||
<i class="fas fa-fw fa-sync-alt me-2"></i>Refresh Records
|
||||
</button>
|
||||
<div class="dropdown-divider"></div>
|
||||
<button class="dropdown-item text-danger confirm-link"
|
||||
type="submit" form="bulkActions" name="bulk_archive_domains">
|
||||
<i class="fas fa-fw fa-archive me-2"></i>Archive
|
||||
</button>
|
||||
<button class="dropdown-item text-danger confirm-link" type="submit" form="bulkActions" name="bulk_archive_domains">
|
||||
<i class="fas fa-fw fa-archive me-2"></i>Archive
|
||||
</button>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
|
||||
<form id="bulkActions" action="post.php" method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<?php if ($client_url) { ?>
|
||||
<input type="hidden" name="client_id" value="<?= $client_id ?>">
|
||||
<!-- Which ones - counted over what the filters above leave -->
|
||||
<nav class="nav nav-pills itflow-asset-tabs mt-2 flex-nowrap overflow-auto">
|
||||
<?php foreach ($shows as $key => $s) {
|
||||
$alarm = $counts[$key] && in_array($key, ['soon', 'expired', 'mail'], true); ?>
|
||||
<a class="nav-link text-nowrap <?= $show === $key ? 'active' : '' ?>" href="<?= escapeHtml($filter_url(['show' => $key, 'expire_days' => ''])) ?>">
|
||||
<?php if (!empty($s['icon'])) { ?><i class="fas fa-fw <?= $s['icon'] ?> me-1"></i><?php } ?><?= $s['label'] ?>
|
||||
<span class="badge rounded-pill ms-1 <?= $alarm ? ($key === 'expired' ? 'text-bg-danger' : 'text-bg-warning') : '' ?>"><?= $counts[$key] ?></span>
|
||||
</a>
|
||||
<?php } ?>
|
||||
<table class="table table-striped table-borderless table-hover mb-0">
|
||||
<thead class="text-dark <?php if ($num_rows[0] == 0) { echo "d-none"; } ?> text-nowrap">
|
||||
</nav>
|
||||
<?php if ($expire_query) { ?>
|
||||
<div class="small text-body-secondary mt-2">
|
||||
<i class="fas fa-filter me-1"></i><?= $expire_days === 'expired' ? 'Expired' : 'Expiring in ' . intval($expire_days) . ' days' ?>
|
||||
<a class="ms-2" href="<?= escapeHtml($filter_url(['expire_days' => ''])) ?>">Clear</a>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<form id="bulkActions" action="post.php" method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle mb-0 itflow-asset-table">
|
||||
<thead class="<?php if (!$num_rows[0]) { echo "d-none"; } ?> text-nowrap table-light">
|
||||
<tr>
|
||||
<td class="checkbox-column border-end">
|
||||
<?php if ($can_edit) { ?>
|
||||
<th class="checkbox-column border-end">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" id="selectAllCheckbox" type="checkbox" onclick="checkAll(this)">
|
||||
<input class="form-check-input" id="selectAllCheckbox" type="checkbox" onclick="checkAll(this)" title="Select all on this page">
|
||||
</div>
|
||||
</td>
|
||||
</th>
|
||||
<?php } ?>
|
||||
<th>
|
||||
<a class="text-secondary" href="?<?= $url_query_strings_sort ?>&sort=domain_name&order=<?= $disp ?>">
|
||||
<a class="text-reset text-decoration-none" href="?<?= $url_query_strings_sort ?>&sort=domain_name&order=<?= $disp ?>">
|
||||
Domain <?php if ($sort == 'domain_name') { echo $order_icon; } ?>
|
||||
</a>
|
||||
</th>
|
||||
<th>
|
||||
<a class="text-secondary" href="?<?= $url_query_strings_sort ?>&sort=registrar_name&order=<?= $disp ?>">
|
||||
Registrar <?php if ($sort == 'registrar_name') { echo $order_icon; } ?>
|
||||
</a>
|
||||
</th>
|
||||
<th>
|
||||
<a class="text-secondary" href="?<?= $url_query_strings_sort ?>&sort=webhost_name&order=<?= $disp ?>">
|
||||
Web Host <?php if ($sort == 'webhost_name') { echo $order_icon; } ?>
|
||||
</a>
|
||||
</th>
|
||||
<th>
|
||||
<a class="text-secondary" href="?<?= $url_query_strings_sort ?>&sort=dnshost_name&order=<?= $disp ?>">
|
||||
DNS Host <?php if ($sort == 'dnshost_name') { echo $order_icon; } ?>
|
||||
</a>
|
||||
</th>
|
||||
<th>
|
||||
<a class="text-secondary" href="?<?= $url_query_strings_sort ?>&sort=mailhost_name&order=<?= $disp ?>">
|
||||
Mail Host <?php if ($sort == 'mailhost_name') { echo $order_icon; } ?>
|
||||
</a>
|
||||
</th>
|
||||
<th>
|
||||
<a class="text-secondary" href="?<?= $url_query_strings_sort ?>&sort=domain_expire&order=<?= $disp ?>">
|
||||
<a class="text-reset text-decoration-none" href="?<?= $url_query_strings_sort ?>&sort=domain_expire&order=<?= $disp ?>">
|
||||
Expires <?php if ($sort == 'domain_expire') { echo $order_icon; } ?>
|
||||
</a>
|
||||
</th>
|
||||
<th>
|
||||
<a class="text-reset text-decoration-none" href="?<?= $url_query_strings_sort ?>&sort=registrar_name&order=<?= $disp ?>">
|
||||
Registrar and hosts <?php if ($sort == 'registrar_name') { echo $order_icon; } ?>
|
||||
</a>
|
||||
</th>
|
||||
<th>Email</th>
|
||||
<?php if (!$client_url) { ?>
|
||||
<th>
|
||||
<a class="text-dark" href="?<?= $url_query_strings_sort ?>&sort=client_name&order=<?= $disp ?>">
|
||||
<a class="text-reset text-decoration-none" href="?<?= $url_query_strings_sort ?>&sort=client_name&order=<?= $disp ?>">
|
||||
Client <?php if ($sort == 'client_name') { echo $order_icon; } ?>
|
||||
</a>
|
||||
</th>
|
||||
<?php } ?>
|
||||
<th class="text-center">Action</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$domain_id = intval($row['domain_id']);
|
||||
foreach ($domains as $domain_id => $row) {
|
||||
$row_client_id = intval($row['domain_client_id']);
|
||||
$domain_name = escapeHtml($row['domain_name']);
|
||||
$domain_description = escapeHtml($row['domain_description']);
|
||||
$domain_expire = escapeHtml($row['domain_expire']);
|
||||
$domain_expire_ago = timeAgo($domain_expire);
|
||||
// Convert the expiry date to a timestamp
|
||||
$domain_expire_timestamp = strtotime($row['domain_expire'] ?? '');
|
||||
$current_timestamp = time(); // Get current timestamp
|
||||
|
||||
// Calculate the difference in days
|
||||
$days_until_expiry = ($domain_expire_timestamp - $current_timestamp) / (60 * 60 * 24);
|
||||
|
||||
// Determine the class based on the number of days until expiry
|
||||
if ($days_until_expiry <= 0) {
|
||||
$tr_class = "table-secondary";
|
||||
} elseif ($days_until_expiry <= 14) {
|
||||
$tr_class = "table-danger";
|
||||
} elseif ($days_until_expiry <= 90) {
|
||||
$tr_class = "table-warning";
|
||||
} else {
|
||||
$tr_class = '';
|
||||
}
|
||||
$domain_registrar_id = intval($row['registrar_id']);
|
||||
$domain_webhost_id = intval($row['webhost_id']);
|
||||
$domain_dnshost_id = intval($row['dnshost_id']);
|
||||
$domain_mailhost_id = intval($row['mailhost_id']);
|
||||
$domain_registrar_name = escapeHtml($row['registrar_name']);
|
||||
$domain_webhost_name = escapeHtml($row['webhost_name']);
|
||||
$domain_dnshost_name = escapeHtml($row['dnshost_name']);
|
||||
$domain_mailhost_name = escapeHtml($row['mailhost_name']);
|
||||
$domain_created_at = escapeHtml($row['domain_created_at']);
|
||||
$domain_favorite = intval($row['domain_favorite']);
|
||||
$domain_archived_at = escapeHtml($row['domain_archived_at']);
|
||||
$client_id = intval($row['domain_client_id']);
|
||||
$client_name = escapeHtml($row['client_name']);
|
||||
// Add - if empty on the table
|
||||
$domain_registrar_name_display = $domain_registrar_name ? "
|
||||
<a class='ajax-modal' href='#' data-modal-size='lg' data-modal-url='modals/vendor/vendor.php?id=$domain_registrar_id'>
|
||||
$domain_registrar_name
|
||||
</a>" : "-";
|
||||
$domain_webhost_name_display = $domain_webhost_name ? "
|
||||
<a class='ajax-modal' href='#' data-modal-size='lg' data-modal-url='modals/vendor/vendor.php?id=$domain_webhost_id'>
|
||||
$domain_webhost_name
|
||||
</a>" : "-";
|
||||
$domain_dnshost_name_display = $domain_dnshost_name ? "
|
||||
<a class='ajax-modal' href='#' data-modal-size='lg' data-modal-url='modals/vendor/vendor.php?id=$domain_dnshost_id'>
|
||||
$domain_dnshost_name
|
||||
</a>" : "-";
|
||||
$domain_mailhost_name_display = $domain_mailhost_name ? "
|
||||
<a class='ajax-modal' href='#' data-modal-size='lg' data-modal-url='modals/vendor/vendor.php?id=$domain_mailhost_id'>
|
||||
$domain_mailhost_name
|
||||
</a>" : "-";
|
||||
$domain_tags = $domains_tags[$domain_id] ?? [];
|
||||
$expiry = domainExpiry($row['domain_expire'], $row['domain_auto_renew']);
|
||||
$quick_url = "modals/domain/domain.php?id=$domain_id";
|
||||
|
||||
?>
|
||||
<tr class="<?= $tr_class ?>">
|
||||
<tr>
|
||||
<?php if ($can_edit) { ?>
|
||||
<td class="checkbox-column bg-light border-end">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input bulk-select" type="checkbox" name="domain_ids[]" value="<?= $domain_id ?>">
|
||||
<input class="form-check-input bulk-select" type="checkbox" name="domain_ids[]" value="<?= $domain_id ?>" aria-label="Select <?= $domain_name ?>">
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<a class="text-dark ajax-modal" href="#"
|
||||
data-modal-size="lg"
|
||||
data-modal-url="modals/domain/domain_edit.php?<?= $client_url ?>&id=<?= $domain_id ?>">
|
||||
<div class="d-flex">
|
||||
<i class="fa fa-fw fa-2x fa-globe me-3"></i>
|
||||
<div class="flex-grow-1">
|
||||
<div><?= $domain_name ?></div>
|
||||
<div><small class="text-secondary"><?= $domain_description ?></small></div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<td class="itflow-asset-name-cell">
|
||||
<div class="d-flex align-items-center gap-3">
|
||||
<?= domainTile() ?>
|
||||
<div class="min-w-0">
|
||||
<a class="fw-semibold text-body ajax-modal" href="#" data-modal-size="lg" data-modal-url="<?= $quick_url ?>"><?= $domain_name ?></a>
|
||||
<?php if ($domain_favorite) { ?><i class="fas fa-star text-warning small ms-1" title="Starred"></i><?php } ?>
|
||||
<?php if ($domain_archived_at) { ?><span class="badge rounded-pill text-bg-secondary fw-normal ms-1">Archived</span><?php } ?>
|
||||
<?php if ($domain_description) { ?>
|
||||
<div class="small text-body-secondary text-truncate itflow-asset-desc" title="<?= $domain_description ?>"><?= $domain_description ?></div>
|
||||
<?php } ?>
|
||||
<?php if ($domain_tags || $can_edit) { ?>
|
||||
<div class="mt-1"><?= tagPills('domain', $domain_id, $domain_tags, "domains.php?$client_url", $can_edit) ?></div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</td>
|
||||
<td><?= $domain_registrar_name_display ?></td>
|
||||
<td><?= $domain_webhost_name_display ?></td>
|
||||
<td><?= $domain_dnshost_name_display ?></td>
|
||||
<td><?= $domain_mailhost_name_display ?></td>
|
||||
<td>
|
||||
<div><?= $domain_expire ?: '-' ?></div>
|
||||
<?php if (!empty($domain_expire)) { ?>
|
||||
<div><small><?= $domain_expire_ago ?></small></div>
|
||||
<td class="text-nowrap">
|
||||
<?= domainExpiryPill($expiry) ?>
|
||||
<?php if ($expiry) { ?>
|
||||
<div class="small text-body-secondary mt-1"><?= escapeHtml($expiry['date']) ?></div>
|
||||
<?php } ?>
|
||||
</td>
|
||||
<td class="small itflow-domain-who">
|
||||
<?php $who = domainVendorsHtml($row); ?>
|
||||
<?= $who ? '<div class="d-flex flex-column gap-1">' . $who . '</div>' : '<span class="text-body-secondary">-</span>' ?>
|
||||
</td>
|
||||
<td class="itflow-domain-mail"><?= domainMailPillsHtml(array_diff_key(domainMailChecks($row), ['mx' => 1])) ?></td>
|
||||
<?php if (!$client_url) { ?>
|
||||
<td><a href="domains.php?client_id=<?= $client_id ?>"><?= $client_name ?></a></td>
|
||||
<td><a href="domains.php?client_id=<?= $row_client_id ?>"><?= escapeHtml($row['client_name']) ?></a></td>
|
||||
<?php } ?>
|
||||
<td>
|
||||
<div class="dropdown dropstart text-center">
|
||||
<button class="btn btn-secondary btn-sm" title="More actions" type="button" data-bs-toggle="dropdown">
|
||||
<i class="fas fa-ellipsis-h"></i>
|
||||
</button>
|
||||
<td class="text-end">
|
||||
<div class="dropdown dropstart">
|
||||
<button class="btn btn-sm btn-light" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-fw fa-ellipsis-v"></i></button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item ajax-modal" href="#"
|
||||
data-modal-size="lg"
|
||||
data-modal-url="modals/domain/domain_edit.php?<?= $client_url ?>&id=<?= $domain_id ?>">
|
||||
<i class="fas fa-fw fa-edit me-2"></i>Edit
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-size="lg" data-modal-url="<?= $quick_url ?>">
|
||||
<i class="fas fa-fw fa-eye text-secondary me-2"></i>Quick look
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item" href="post.php?refresh_domain=<?= $domain_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-sync-alt me-2"></i>Refresh Records
|
||||
<a class="dropdown-item" href="https://<?= $domain_name ?>" target="_blank" rel="noopener noreferrer">
|
||||
<i class="fas fa-fw fa-external-link-alt text-secondary me-2"></i>Open the website
|
||||
</a>
|
||||
<?php if ($session_user_role == 3) { ?>
|
||||
<?php if ($can_edit && !$domain_archived_at) { ?>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/domain/domain_edit.php?id=<?= $domain_id ?>">
|
||||
<i class="fas fa-fw fa-edit text-secondary me-2"></i>Edit
|
||||
</a>
|
||||
<a class="dropdown-item" href="post.php?refresh_domain=<?= $domain_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-sync-alt text-secondary me-2"></i>Look up now
|
||||
</a>
|
||||
<a class="dropdown-item" href="post.php?<?= $domain_favorite ? 'unfavorite_domain' : 'favorite_domain' ?>=<?= $domain_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="<?= $domain_favorite ? 'far' : 'fas' ?> fa-fw fa-star text-secondary me-2"></i><?= $domain_favorite ? 'Unstar' : 'Star' ?>
|
||||
</a>
|
||||
<?php } ?>
|
||||
<?php if ($can_edit) { ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<?php if ($domain_archived_at) { ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-info confirm-link" href="post.php?restore_domain=<?= $domain_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-redo me-2"></i>Restore
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_domain=<?= $domain_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-trash me-2"></i>Delete
|
||||
</a>
|
||||
<a class="dropdown-item" href="post.php?restore_domain=<?= $domain_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-redo text-secondary me-2"></i>Restore
|
||||
</a>
|
||||
<?php if ($can_delete) { ?>
|
||||
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_domain=<?= $domain_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>"
|
||||
data-confirm-text="<?= $domain_name ?> goes for good, with its history. Services and certificates stop pointing at it.">
|
||||
<i class="fas fa-fw fa-trash me-2"></i>Delete
|
||||
</a>
|
||||
<?php } ?>
|
||||
<?php } else { ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-danger confirm-link" href="post.php?archive_domain=<?= $domain_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-archive me-2"></i>Archive
|
||||
</a>
|
||||
<a class="dropdown-item text-danger confirm-link" href="post.php?archive_domain=<?= $domain_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-archive me-2"></i>Archive
|
||||
</a>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
@@ -388,18 +428,72 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<?php } ?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<?php if (!$num_rows[0]) { ?>
|
||||
<div class="itflow-asset-empty">
|
||||
<i class="fas fa-globe fa-2x mb-2 opacity-50"></i>
|
||||
<div><?= $q || $tag_query || $show || $vendor_query || $expire_query ? 'No domains match.' : 'No domains yet.' ?></div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php require_once "../includes/filter_footer.php"; ?>
|
||||
</div>
|
||||
|
||||
<?php if ($can_edit && !$archived) { ?>
|
||||
<!-- Bulk: who registers or hosts the domains picked -->
|
||||
<div class="modal fade" id="domainBulkVendorModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fas fa-fw fa-building me-2"></i>Set registrar or host</h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<label class="form-label">What they do</label>
|
||||
<div class="btn-group w-100 mb-3" role="group">
|
||||
<?php foreach (DOMAIN_ROLES as $role => $info) { ?>
|
||||
<input type="radio" class="btn-check" form="bulkActions" name="role" value="<?= $role ?>" id="domainBulkRole<?= $role ?>" <?= $role === 'registrar' ? 'checked' : '' ?>>
|
||||
<label class="btn btn-outline-secondary" for="domainBulkRole<?= $role ?>"><i class="fas <?= $info['icon'] ?> me-1"></i><?= $info['label'] ?></label>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<label class="form-label">Vendor</label>
|
||||
<select class="form-select select2" form="bulkActions" name="vendor_id">
|
||||
<option value="0">- Nobody -</option>
|
||||
<?php foreach ($bulk_vendor_options as $vendor) { ?>
|
||||
<option value="<?= intval($vendor['vendor_id']) ?>"<?= selectOptionVendor($vendor['vendor_name'], intval($vendor['vendor_client_id']) === 0 ? 'Ours' : $vendor['vendor_description']) ?>><?= escapeHtml($vendor['vendor_name']) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
<div class="form-text"><?= $client_url ? "The client's vendors, and ours." : 'Across clients only our own vendors can be set - open a client to use theirs.' ?></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" form="bulkActions" name="bulk_set_domain_vendor" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Set it</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if (!empty($_GET['open'])) { ?>
|
||||
<script>
|
||||
// Opened from search or the overview - straight to that domain's quick look
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var open = document.createElement('a');
|
||||
open.className = 'ajax-modal';
|
||||
open.href = '#';
|
||||
open.dataset.modalSize = 'lg';
|
||||
open.dataset.modalUrl = 'modals/domain/domain.php?id=<?= intval($_GET['open']) ?>';
|
||||
document.body.appendChild(open);
|
||||
open.click();
|
||||
open.remove();
|
||||
});
|
||||
</script>
|
||||
<?php } ?>
|
||||
|
||||
<script src="../js/bulk_actions.js"></script>
|
||||
|
||||
<?php require_once "../includes/footer.php";
|
||||
|
||||
230
agent/modals/domain/domain.php
Normal file
230
agent/modals/domain/domain.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Domain quick look - opened from the domains list, vendors, services, the
|
||||
* client overview and search. When it expires and whether it renews by
|
||||
* itself, who registers it and who hosts DNS, the website and email, its
|
||||
* records (each to copy), the email checks clients get asked about (SPF,
|
||||
* DMARC, DKIM), its certificates and services, the registrar and DNS logins,
|
||||
* notes, the raw WHOIS and its history. Changing it takes edit rights.
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceUserPermission('module_support');
|
||||
|
||||
$domain_id = intval($_GET['id'] ?? 0);
|
||||
$domain = domainRow($domain_id);
|
||||
if (!$domain) {
|
||||
echo json_encode(['error' => 'That domain no longer exists.']);
|
||||
exit;
|
||||
}
|
||||
$client_id = intval($domain['domain_client_id']);
|
||||
enforceClientAccess();
|
||||
|
||||
// When it was last looked at - kept off the updated date, which the refresher uses
|
||||
mysqli_query($mysqli, "UPDATE domains SET domain_accessed_at = NOW(), domain_updated_at = domain_updated_at WHERE domain_id = $domain_id");
|
||||
|
||||
$domain_name = escapeHtml($domain['domain_name']);
|
||||
$domain_archived = !empty($domain['domain_archived_at']);
|
||||
$can_edit = domainCan(2) && !$domain_archived;
|
||||
$expiry = domainExpiry($domain['domain_expire'], $domain['domain_auto_renew']);
|
||||
$facts = domainRegistrationFacts($domain['domain_raw_whois']);
|
||||
$mail_checks = domainMailChecks($domain);
|
||||
$certificates = domainCertificates($domain);
|
||||
$services = domainServices($domain_id);
|
||||
$logins = domainLogins($domain);
|
||||
$history = domainHistory($domain_id, 15);
|
||||
$tags = tagsForRecord('domain', $domain_id);
|
||||
$txt_records = array_values(array_filter(array_map('trim', preg_split('/\r?\n/', (string) $domain['domain_txt'])), 'strlen'));
|
||||
|
||||
// One record line with its copy button
|
||||
$record = function ($value) {
|
||||
$value = trim((string) $value);
|
||||
return '<div class="d-flex align-items-center min-w-0"><span class="font-monospace small text-truncate" title="' . escapeHtml($value) . '">' . escapeHtml($value) . '</span>'
|
||||
. '<button type="button" class="itflow-copy clipboardjs" title="Copy" data-clipboard-text="' . escapeHtml($value) . '"><i class="far fa-copy"></i></button></div>';
|
||||
};
|
||||
$records = function ($text) use ($record) {
|
||||
$lines = domainLines($text);
|
||||
return $lines ? implode('', array_map($record, $lines)) : '<span class="text-body-secondary">None</span>';
|
||||
};
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark" data-bs-theme="dark">
|
||||
<div class="d-flex align-items-center gap-3 min-w-0">
|
||||
<?= domainTile() ?>
|
||||
<div class="min-w-0">
|
||||
<h5 class="modal-title d-flex flex-wrap align-items-center column-gap-2 row-gap-1">
|
||||
<span class="fw-semibold text-break"><?= $domain_name ?></span>
|
||||
<?php if (intval($domain['domain_favorite'])) { ?><i class="fas fa-star text-warning small" title="Starred"></i><?php } ?>
|
||||
<?php if ($domain_archived) { ?><span class="badge rounded-pill text-bg-secondary fw-normal fs-6">Archived</span><?php } ?>
|
||||
</h5>
|
||||
<div class="small text-body-secondary d-flex flex-wrap column-gap-3 mt-1">
|
||||
<span><?= escapeHtml($domain['client_name']) ?></span>
|
||||
<?php if ($domain['domain_description']) { ?><span><?= escapeHtml($domain['domain_description']) ?></span><?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="d-flex flex-wrap align-items-center gap-2 mb-3 small text-body-secondary">
|
||||
<?= domainExpiryPill($expiry, true) ?>
|
||||
<?php if (intval($domain['domain_auto_renew'])) { ?>
|
||||
<span class="badge rounded-pill bg-info-subtle text-info-emphasis border border-info-subtle fw-normal"><i class="fas fa-sync-alt me-1"></i>Auto-renews</span>
|
||||
<?php } ?>
|
||||
<a href="https://<?= $domain_name ?>" target="_blank" rel="noopener noreferrer"><i class="fas fa-external-link-alt me-1"></i>Open the website</a>
|
||||
<span title="<?= escapeHtml($domain['domain_refreshed_at'] ?? '') ?>"><i class="fas fa-search me-1"></i><?= $domain['domain_refreshed_at'] ? 'Looked up ' . timeAgo($domain['domain_refreshed_at']) : 'Not looked up yet' ?></span>
|
||||
<?php if ($tags) { ?><span><?= tagPills('domain', $domain_id, $tags, "domains.php?client_id=$client_id&", false) ?></span><?php } ?>
|
||||
</div>
|
||||
|
||||
<div class="row g-4">
|
||||
<div class="col-md-6">
|
||||
<div class="small text-body-secondary fw-semibold text-uppercase mb-2">Registration</div>
|
||||
<dl class="itflow-asset-dl itflow-domain-dl mb-3">
|
||||
<dt>Expires</dt>
|
||||
<dd><?= $expiry ? escapeHtml($expiry['date']) : '<span class="text-body-secondary">Unknown</span>' ?></dd>
|
||||
<dt>Auto-renew</dt>
|
||||
<dd><?= intval($domain['domain_auto_renew']) ? 'Yes' : 'No' ?></dd>
|
||||
<?php if (!empty($facts['registered'])) { ?>
|
||||
<dt>Registered</dt>
|
||||
<dd><?= escapeHtml($facts['registered']) ?> <span class="small text-body-secondary">(<?= timeAgo($facts['registered']) ?>)</span></dd>
|
||||
<?php } ?>
|
||||
<?php if (!empty($facts['registrar'])) { ?>
|
||||
<dt>Registry says</dt>
|
||||
<dd class="text-break"><?= escapeHtml($facts['registrar']) ?></dd>
|
||||
<?php } ?>
|
||||
<?php if (!empty($facts['status'])) { ?>
|
||||
<dt>Status</dt>
|
||||
<dd class="small text-break"><?= escapeHtml($facts['status']) ?></dd>
|
||||
<?php } ?>
|
||||
</dl>
|
||||
|
||||
<div class="small text-body-secondary fw-semibold text-uppercase mb-2">Who</div>
|
||||
<?php if (domainVendors($domain)) { ?>
|
||||
<div class="d-flex flex-column gap-2 mb-3"><?= domainVendorsHtml($domain) ?></div>
|
||||
<?php } else { ?>
|
||||
<p class="small text-body-secondary mb-3">No registrar or hosts set<?= $can_edit ? ' - Edit to add them' : '' ?>.</p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="small text-body-secondary fw-semibold text-uppercase mb-2">DNS</div>
|
||||
<dl class="itflow-asset-dl itflow-domain-dl mb-3">
|
||||
<dt>A</dt>
|
||||
<dd class="min-w-0"><?= $records($domain['domain_ip']) ?></dd>
|
||||
<dt>Name servers</dt>
|
||||
<dd class="min-w-0"><?= $records($domain['domain_name_servers']) ?></dd>
|
||||
<dt>MX</dt>
|
||||
<dd class="min-w-0"><?= $records($domain['domain_mail_servers']) ?></dd>
|
||||
</dl>
|
||||
|
||||
<div class="small text-body-secondary fw-semibold text-uppercase mb-2">Email</div>
|
||||
<div class="mb-2"><?= domainMailPillsHtml($mail_checks) ?></div>
|
||||
<ul class="list-unstyled small mb-0 itflow-domain-checks">
|
||||
<?php foreach ($mail_checks as $check) { ?>
|
||||
<li class="text-break"><?= escapeHtml($check['text']) ?></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($certificates) { ?>
|
||||
<div class="small text-body-secondary fw-semibold text-uppercase mt-3 mb-1">Certificates</div>
|
||||
<ul class="list-unstyled mb-0 itflow-links">
|
||||
<?php foreach ($certificates as $certificate) { ?>
|
||||
<li class="itflow-link-row">
|
||||
<span class="itflow-link-icon" aria-hidden="true"><i class="fas fa-fw fa-lock"></i></span>
|
||||
<div class="min-w-0 flex-grow-1">
|
||||
<div class="d-flex"><a class="ajax-modal text-truncate" href="#" data-modal-url="modals/certificate/certificate_edit.php?id=<?= intval($certificate['certificate_id']) ?>"><?= escapeHtml($certificate['certificate_domain'] ?: $certificate['certificate_name']) ?></a></div>
|
||||
<div class="small text-body-secondary text-truncate"><?= escapeHtml($certificate['certificate_issued_by'] ?: 'Issuer unknown') ?></div>
|
||||
</div>
|
||||
<?= softwareRenewalPill(softwareRenewal($certificate['certificate_expire']), true) ?>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($services) { ?>
|
||||
<div class="small text-body-secondary fw-semibold text-uppercase mt-3 mb-1">Services that use it</div>
|
||||
<ul class="list-unstyled mb-0 itflow-links">
|
||||
<?php foreach ($services as $service) { ?>
|
||||
<li class="itflow-link-row">
|
||||
<span class="itflow-link-icon" aria-hidden="true"><i class="fas fa-fw fa-stream"></i></span>
|
||||
<div class="min-w-0 flex-grow-1">
|
||||
<div class="d-flex"><a class="ajax-modal text-truncate" href="#" data-modal-size="lg" data-modal-url="modals/service/service.php?id=<?= intval($service['service_id']) ?>"><?= escapeHtml($service['service_name']) ?></a></div>
|
||||
<div class="small text-body-secondary"><?= escapeHtml($service['service_importance']) ?> importance</div>
|
||||
</div>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($logins) { ?>
|
||||
<div class="small text-body-secondary fw-semibold text-uppercase mt-3 mb-1">Logins for the registrar and hosts</div>
|
||||
<?= credentialListHtml($logins) ?>
|
||||
<?php } ?>
|
||||
|
||||
<?php if (trim((string) $domain['domain_notes']) !== '') { ?>
|
||||
<div class="small text-body-secondary fw-semibold text-uppercase mt-3 mb-1">Notes</div>
|
||||
<div class="itflow-credential-note small"><?= nl2br(escapeHtml($domain['domain_notes'])) ?></div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($txt_records) { ?>
|
||||
<details class="mt-3">
|
||||
<summary class="small text-body-secondary fw-semibold text-uppercase">TXT records (<?= count($txt_records) ?>)</summary>
|
||||
<div class="mt-2"><?= implode('', array_map($record, $txt_records)) ?></div>
|
||||
<?php if (trim((string) $domain['domain_dmarc']) !== '') { ?>
|
||||
<div class="small text-body-secondary mt-2">_dmarc</div>
|
||||
<?= $record($domain['domain_dmarc']) ?>
|
||||
<?php } ?>
|
||||
</details>
|
||||
<?php } ?>
|
||||
|
||||
<?php if (trim((string) $domain['domain_raw_whois']) !== '') { ?>
|
||||
<details class="mt-3">
|
||||
<summary class="small text-body-secondary fw-semibold text-uppercase">WHOIS</summary>
|
||||
<pre class="itflow-credential-note small mt-2 mb-0"><?= escapeHtml($domain['domain_raw_whois']) ?></pre>
|
||||
</details>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($history) { ?>
|
||||
<details class="mt-3">
|
||||
<summary class="small text-body-secondary fw-semibold text-uppercase">History</summary>
|
||||
<ul class="list-unstyled small mt-2 mb-0">
|
||||
<?php foreach ($history as $entry) {
|
||||
$old = trim((string) $entry['domain_history_old_value']);
|
||||
$new = trim((string) $entry['domain_history_new_value']); ?>
|
||||
<li class="d-flex gap-2 py-1 border-bottom">
|
||||
<span class="flex-grow-1 min-w-0 text-break">
|
||||
<strong><?= escapeHtml($entry['label']) ?></strong>
|
||||
<?php if (mb_strlen($old) <= 60 && mb_strlen($new) <= 60 && strpos($old . $new, "\n") === false) { ?>
|
||||
<?= $old === '' ? 'set to' : '<span class="text-body-secondary">' . escapeHtml($old) . '</span> →' ?> <?= $new === '' ? '<span class="text-body-secondary">cleared</span>' : escapeHtml($new) ?>
|
||||
<?php } else { ?>
|
||||
changed
|
||||
<?php } ?>
|
||||
</span>
|
||||
<span class="text-body-secondary text-nowrap" title="<?= escapeHtml($entry['domain_history_modified_at']) ?>"><?= timeAgo($entry['domain_history_modified_at']) ?></span>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</details>
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<?php if ($can_edit) { ?>
|
||||
<a class="btn btn-outline-secondary me-auto" href="post.php?refresh_domain=<?= $domain_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>"><i class="fas fa-sync-alt me-2"></i>Look up now</a>
|
||||
<button type="button" class="btn btn-primary text-bold ajax-modal" data-modal-size="lg" data-modal-url="modals/domain/domain_edit.php?id=<?= $domain_id ?>"><i class="fas fa-edit me-2"></i>Edit</button>
|
||||
<?php } ?>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Close</button>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
@@ -1,8 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* New domain - for the client it was opened from, or pick the client here.
|
||||
* One domain, or several pasted at once. Each is looked up as it is saved:
|
||||
* its records, its registration and expiry, and the certificate on its
|
||||
* website. Opened from a vendor's page (?vendor_id=) that vendor starts as
|
||||
* the registrar.
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$client_id = intval($_GET['client_id'] ?? 0);
|
||||
if ($client_id) {
|
||||
enforceClientAccess();
|
||||
}
|
||||
|
||||
$domain_form_mode = 'add';
|
||||
$domain_id = 0;
|
||||
$domain_name = $domain_description = $domain_expire = $domain_notes = '';
|
||||
$domain_favorite = $domain_auto_renew = 0;
|
||||
$domain_tag_ids = [];
|
||||
$domain_vendor_ids = array_fill_keys(array_keys(DOMAIN_ROLES), 0);
|
||||
if ($client_id) {
|
||||
$domain_vendor_ids['registrar'] = domainVendorId($_GET['vendor_id'] ?? 0, $client_id);
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
@@ -13,190 +36,18 @@ ob_start();
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<?php if ($client_id) { ?>
|
||||
<input type="hidden" name="client_id" value="<?= $client_id ?>">
|
||||
<?php } ?>
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<ul class="nav nav-pills nav-justified mb-3">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" data-bs-toggle="pill" href="#pills-details">Details</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-bs-toggle="pill" href="#pills-notes">Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="tab-content">
|
||||
|
||||
<div class="tab-pane fade show active" id="pills-details">
|
||||
|
||||
<?php if ($client_id) { ?>
|
||||
<input type="hidden" name="client_id" value="<?= $client_id ?>">
|
||||
<?php } else { ?>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Client <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
|
||||
<select class="form-select select2" name="client_id" required>
|
||||
<option value="">- Select Client -</option>
|
||||
<?php
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT client_id, client_name, client_abbreviation FROM clients WHERE client_archived_at IS NULL " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']); ?>
|
||||
<option <?php if ($client_id == $client_id_select) { echo "selected"; } ?> value="<?= $client_id_select ?>"<?= selectOptionClient($row['client_id'], $row['client_name'], $row['client_abbreviation'] ?? '') ?>><?= $client_name ?></option>
|
||||
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Domain Name <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-globe"></i></span>
|
||||
<input type="text" class="form-control" name="name" id="domain_name" placeholder="example.com" maxlength="200" required autofocus onfocusout="checkApexDomain()">
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<span class="text-info" id="domain_check_info"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Description</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-align-left"></i></span>
|
||||
<input type="text" class="form-control" name="description" placeholder="Short Description">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($client_id) { ?>
|
||||
<div class="mb-3">
|
||||
<label>Registrar</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-server"></i></span>
|
||||
<select class="form-select select2" name="registrar">
|
||||
<option value="">- Vendor -</option>
|
||||
<?php
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT vendor_id, vendor_name, vendor_description FROM vendors WHERE vendor_archived_at IS NULL AND vendor_client_id = $client_id ORDER BY vendor_favorite DESC, vendor_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$vendor_id = intval($row['vendor_id']);
|
||||
$vendor_name = escapeHtml($row['vendor_name']);
|
||||
?>
|
||||
<option value="<?= $vendor_id ?>"<?= selectOptionVendor($row['vendor_name'], $row['vendor_description']) ?>><?= $vendor_name ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Webhost</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-server"></i></span>
|
||||
<select class="form-select select2" name="webhost">
|
||||
<option value="">- Vendor -</option>
|
||||
<?php
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT vendor_id, vendor_name, vendor_description FROM vendors WHERE vendor_archived_at IS NULL AND vendor_client_id = $client_id ORDER BY vendor_favorite DESC, vendor_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$vendor_id = intval($row['vendor_id']);
|
||||
$vendor_name = escapeHtml($row['vendor_name']);
|
||||
?>
|
||||
<option value="<?= $vendor_id ?>"<?= selectOptionVendor($row['vendor_name'], $row['vendor_description']) ?>><?= $vendor_name ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>DNS Host</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-server"></i></span>
|
||||
<select class="form-select select2" name="dnshost">
|
||||
<option value="">- Vendor -</option>
|
||||
<?php
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT vendor_id, vendor_name, vendor_description FROM vendors WHERE vendor_archived_at IS NULL AND vendor_client_id = $client_id ORDER BY vendor_favorite DESC, vendor_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$vendor_id = intval($row['vendor_id']);
|
||||
$vendor_name = escapeHtml($row['vendor_name']);
|
||||
?>
|
||||
<option value="<?= $vendor_id ?>"<?= selectOptionVendor($row['vendor_name'], $row['vendor_description']) ?>><?= $vendor_name ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Mail Host</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-envelope"></i></span>
|
||||
<select class="form-select select2" name="mailhost">
|
||||
<option value="">- Vendor -</option>
|
||||
<?php
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT vendor_id, vendor_name, vendor_description FROM vendors WHERE vendor_archived_at IS NULL AND vendor_client_id = $client_id ORDER BY vendor_favorite DESC, vendor_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$vendor_id = intval($row['vendor_id']);
|
||||
$vendor_name = escapeHtml($row['vendor_name']);
|
||||
?>
|
||||
<option value="<?= $vendor_id ?>"<?= selectOptionVendor($row['vendor_name'], $row['vendor_description']) ?>><?= $vendor_name ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Expire Date</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-calendar-times"></i></span>
|
||||
<input type="date" class="form-control" name="expire" max="2999-12-31">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="tab-pane fade" id="pills-notes">
|
||||
<div class="mb-3">
|
||||
<textarea class="form-control" rows="12" placeholder="Enter some notes" name="notes"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<?php require 'domain_form.php'; ?>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="add_domain" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Create</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
// Checks domains aren't sub-domains (99%)
|
||||
function checkApexDomain() {
|
||||
var domain = document.getElementById("domain_name").value;
|
||||
//Send a GET request to ajax.php as ajax.php?apex_domain_check=true&domain=domain
|
||||
itflowGet(
|
||||
"ajax.php",
|
||||
{apex_domain_check: 'true', domain: domain},
|
||||
function(data) {
|
||||
//If we get a response from ajax.php, parse it as JSON
|
||||
const domain_check_data = JSON.parse(data);
|
||||
document.getElementById("domain_check_info").innerHTML = domain_check_data.message;
|
||||
}
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
<?php
|
||||
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
|
||||
@@ -1,263 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Edit a domain - its name, what it is for, the star, the expiry and
|
||||
* auto-renew, the registrar and hosts, tags and notes. Saving doesn't look
|
||||
* the domain up again unless its name changed; Look up now does that.
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$domain_id = intval($_GET['id']);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT domain_archived_at, domain_client_id, domain_created_at, domain_description,
|
||||
domain_dnshost, domain_expire, domain_ip, domain_mail_servers, domain_mailhost,
|
||||
domain_name, domain_name_servers, domain_notes, domain_raw_whois, domain_registrar,
|
||||
domain_txt, domain_webhost FROM domains WHERE domain_id = $domain_id LIMIT 1");
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$domain_name = escapeHtml($row['domain_name']);
|
||||
$domain_description = escapeHtml($row['domain_description']);
|
||||
$domain_expire = escapeHtml($row['domain_expire']);
|
||||
$domain_registrar = intval($row['domain_registrar']);
|
||||
$domain_webhost = intval($row['domain_webhost']);
|
||||
$domain_dnshost = intval($row['domain_dnshost']);
|
||||
$domain_mailhost = intval($row['domain_mailhost']);
|
||||
$domain_ip = escapeHtml($row['domain_ip']);
|
||||
$domain_name_servers = escapeHtml($row['domain_name_servers']);
|
||||
$domain_mail_servers = escapeHtml($row['domain_mail_servers']);
|
||||
$domain_txt = escapeHtml($row['domain_txt']);
|
||||
$domain_raw_whois = escapeHtml($row['domain_raw_whois']);
|
||||
$domain_notes = escapeHtml($row['domain_notes']);
|
||||
$domain_created_at = escapeHtml($row['domain_created_at']);
|
||||
$domain_archived_at = escapeHtml($row['domain_archived_at']);
|
||||
$client_id = intval($row['domain_client_id']);
|
||||
|
||||
$history_sql = mysqli_query($mysqli, "SELECT domain_history_column, domain_history_modified_at, domain_history_new_value,
|
||||
domain_history_old_value FROM domain_history WHERE domain_history_domain_id = $domain_id");
|
||||
|
||||
$domain_id = intval($_GET['id'] ?? 0);
|
||||
$domain = domainRow($domain_id);
|
||||
if (!$domain) {
|
||||
echo json_encode(['error' => 'That domain no longer exists.']);
|
||||
exit;
|
||||
}
|
||||
$client_id = intval($domain['domain_client_id']);
|
||||
enforceClientAccess();
|
||||
|
||||
$domain_form_mode = 'edit';
|
||||
$domain_name = escapeHtml($domain['domain_name']);
|
||||
$domain_description = escapeHtml($domain['domain_description']);
|
||||
$domain_expire = escapeHtml($domain['domain_expire']);
|
||||
$domain_notes = escapeHtml($domain['domain_notes']);
|
||||
$domain_favorite = intval($domain['domain_favorite']);
|
||||
$domain_auto_renew = intval($domain['domain_auto_renew']);
|
||||
$domain_tag_ids = array_map('intval', array_column(tagsForRecord('domain', $domain_id), 'tag_id'));
|
||||
$domain_vendor_ids = [];
|
||||
foreach (DOMAIN_ROLES as $role => $info) {
|
||||
$domain_vendor_ids[$role] = intval($domain[$info['column']]);
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-globe me-2"></i>Editing domain: <span class="text-bold"><?= $domain_name ?></span></h5>
|
||||
<h5 class="modal-title text-truncate"><i class="fa fa-fw fa-globe me-2"></i>Editing domain: <strong><?= $domain_name ?></strong></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="domain_id" value="<?= $domain_id ?>">
|
||||
<input type="hidden" name="client_id" value="<?= $client_id ?>">
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<ul class="nav nav-pills nav-justified mb-3">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" data-bs-toggle="pill" href="#pills-overview<?= $domain_id ?>">Overview</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-bs-toggle="pill" href="#pills-records<?= $domain_id ?>">Records</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-bs-toggle="pill" href="#pillsEditNotes<?= $domain_id ?>">Notes</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-bs-toggle="pill" href="#pillsEditHistory<?= $domain_id ?>">History</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="tab-content" <?php if (lookupUserPermission('module_support') <= 1) { echo 'inert'; } ?>>
|
||||
|
||||
<div class="tab-pane fade show active" id="pills-overview<?= $domain_id ?>">
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Domain Name <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-globe"></i></span>
|
||||
<input type="text" class="form-control" name="name" placeholder="Domain name example.com" maxlength="200" value="<?= $domain_name ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Description</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-align-left"></i></span>
|
||||
<input type="text" class="form-control" name="description" placeholder="Short Description" value="<?= $domain_description ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Domain Registrar</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-server"></i></span>
|
||||
<select class="form-select select2" name="registrar">
|
||||
<option value="">- Select Vendor -</option>
|
||||
<?php
|
||||
$vendor_sql = mysqli_query($mysqli, "SELECT vendor_id, vendor_name, vendor_description FROM vendors WHERE vendor_client_id = $client_id AND vendor_archived_at IS NULL ORDER BY vendor_favorite DESC, vendor_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($vendor_sql)) {
|
||||
$vendor_id = $row['vendor_id'];
|
||||
$vendor_name = escapeHtml($row['vendor_name']);
|
||||
?>
|
||||
<option <?php if ($domain_registrar == $vendor_id) { echo "selected"; } ?> value="<?= $vendor_id ?>"<?= selectOptionVendor($row['vendor_name'], $row['vendor_description']) ?>><?= $vendor_name ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Webhost</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-server"></i></span>
|
||||
<select class="form-select select2" name="webhost">
|
||||
<option value="">- Select Vendor -</option>
|
||||
<?php
|
||||
$vendor_sql = mysqli_query($mysqli, "SELECT vendor_id, vendor_name, vendor_description FROM vendors WHERE vendor_client_id = $client_id AND vendor_archived_at IS NULL ORDER BY vendor_favorite DESC, vendor_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($vendor_sql)) {
|
||||
$vendor_id = $row['vendor_id'];
|
||||
$vendor_name = escapeHtml($row['vendor_name']);
|
||||
?>
|
||||
<option <?php if ($domain_webhost == $vendor_id) { echo "selected"; } ?> value="<?= $vendor_id ?>"<?= selectOptionVendor($row['vendor_name'], $row['vendor_description']) ?>><?= $vendor_name ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>DNS Host</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-server"></i></span>
|
||||
<select class="form-select select2" name="dnshost">
|
||||
<option value="">- Select Vendor -</option>
|
||||
<?php
|
||||
$vendor_sql = mysqli_query($mysqli, "SELECT vendor_id, vendor_name, vendor_description FROM vendors WHERE vendor_client_id = $client_id AND vendor_archived_at IS NULL ORDER BY vendor_favorite DESC, vendor_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($vendor_sql)) {
|
||||
$vendor_id = $row['vendor_id'];
|
||||
$vendor_name = escapeHtml($row['vendor_name']);
|
||||
?>
|
||||
<option <?php if ($domain_dnshost == $vendor_id) { echo "selected"; } ?> value="<?= $vendor_id ?>"<?= selectOptionVendor($row['vendor_name'], $row['vendor_description']) ?>><?= $vendor_name ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Mail Host</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-envelope"></i></span>
|
||||
<select class="form-select select2" name="mailhost">
|
||||
<option value="">- Select Vendor -</option>
|
||||
<?php
|
||||
$vendor_sql = mysqli_query($mysqli, "SELECT vendor_id, vendor_name, vendor_description FROM vendors WHERE vendor_client_id = $client_id AND vendor_archived_at IS NULL ORDER BY vendor_favorite DESC, vendor_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($vendor_sql)) {
|
||||
$vendor_id = $row['vendor_id'];
|
||||
$vendor_name = escapeHtml($row['vendor_name']);
|
||||
?>
|
||||
<option <?php if ($domain_mailhost == $vendor_id) { echo "selected"; } ?> value="<?= $vendor_id ?>"<?= selectOptionVendor($row['vendor_name'], $row['vendor_description']) ?>><?= $vendor_name ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Expire Date</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-calendar-times"></i></span>
|
||||
<input type="date" class="form-control" name="expire" max="2999-12-31" value="<?= $domain_expire ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="tab-pane fade" id="pills-records<?= $domain_id ?>">
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Domain IP(s)</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-project-diagram"></i></span>
|
||||
<textarea class="form-control" rows="1" name="domain_ip" disabled><?= $domain_ip ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Name Servers</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-crown"></i></span>
|
||||
<textarea class="form-control" rows="1" name="name_servers" disabled><?= $domain_name_servers ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>MX Records</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-mail-bulk"></i></span>
|
||||
<textarea class="form-control" rows="1" name="mail_servers" disabled><?= $domain_mail_servers ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>TXT Records</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-check-double"></i></span>
|
||||
<textarea class="form-control" rows="1" name="txt_records" disabled><?= $domain_txt ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Raw WHOIS</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-search-plus"></i></span>
|
||||
<textarea class="form-control" rows="6" name="raw_whois" disabled><?= $domain_raw_whois ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="tab-pane fade" id="pillsEditNotes<?= $domain_id ?>">
|
||||
<div class="mb-3">
|
||||
<textarea class="form-control" name="notes" rows="12" placeholder="Enter some notes"><?= $domain_notes ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tab-pane fade" id="pillsEditHistory<?= $domain_id ?>">
|
||||
<div class="table-responsive">
|
||||
<table class='table table-sm table-striped border table-hover'>
|
||||
<thead class='table-dark'>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Field</th>
|
||||
<th>Before</th>
|
||||
<th>After</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
while ($row = mysqli_fetch_assoc($history_sql)) {
|
||||
$domain_modified_at = escapeHtml($row['domain_history_modified_at']);
|
||||
$domain_field = escapeHtml($row['domain_history_column']);
|
||||
$domain_before_value = escapeHtml($row['domain_history_old_value']);
|
||||
$domain_after_value = escapeHtml($row['domain_history_new_value']);
|
||||
?>
|
||||
<tr>
|
||||
<td><?= $domain_modified_at ?></td>
|
||||
<td><?= $domain_field ?></td>
|
||||
<td><?= $domain_before_value ?></td>
|
||||
<td><?= $domain_after_value ?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<?php require 'domain_form.php'; ?>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="edit_domain" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Save</button>
|
||||
|
||||
@@ -23,6 +23,10 @@ $expire_filter = $_GET['expire_days'] ?? '';
|
||||
// Archived Filter
|
||||
$archived_filter = (isset($_GET['archived']) && $_GET['archived'] == 1) ? 1 : 0;
|
||||
|
||||
// Tags and Vendor Filters
|
||||
$tags_filter = array_map('intval', (array) ($_GET['tags'] ?? []));
|
||||
$vendor_filter = intval($_GET['vendor'] ?? 0);
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
@@ -46,7 +50,7 @@ ob_start();
|
||||
<label>Search</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-search"></i></span>
|
||||
<input type="text" class="form-control" name="q" value="<?= stripslashes(escapeHtml($q_filter)) ?>" placeholder="Domain, registrar, web host">
|
||||
<input type="text" class="form-control" name="q" value="<?= stripslashes(escapeHtml($q_filter)) ?>" placeholder="Domain, registrar, host, notes, tag">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -86,6 +90,26 @@ ob_start();
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Tags</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-tags"></i></span>
|
||||
<select class="form-select select2" name="tags[]" data-placeholder="- Any -" multiple>
|
||||
<?php
|
||||
$sql_tags_filter = mysqli_query($mysqli, "SELECT tag_id, tag_name, tag_color, tag_icon FROM tags WHERE tag_type = 7 ORDER BY tag_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql_tags_filter)) {
|
||||
$filter_tag_id = intval($row['tag_id']); ?>
|
||||
<option value="<?= $filter_tag_id ?>" <?= in_array($filter_tag_id, $tags_filter, true) ? 'selected' : '' ?><?= selectOptionColor($row['tag_color'] ?? '', $row['tag_icon'] ?? '') ?>><?= escapeHtml($row['tag_name']) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($vendor_filter) { ?>
|
||||
<input type="hidden" name="vendor" value="<?= $vendor_filter ?>">
|
||||
<p class="small text-body-secondary"><i class="fas fa-building me-1"></i>Only domains registered or hosted with <strong><?= escapeHtml(getFieldById('vendors', $vendor_filter, 'vendor_name')) ?></strong></p>
|
||||
<?php } ?>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Archived</label>
|
||||
<div class="input-group">
|
||||
|
||||
298
agent/modals/domain/domain_form.php
Normal file
298
agent/modals/domain/domain_form.php
Normal file
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
/*
|
||||
* Domain form fields - shared by domain_add.php and domain_edit.php, which
|
||||
* set $domain_form_mode ('add' | 'edit'), $client_id (0 = pick the client
|
||||
* here), $domain_id and the $domain_* values (escaped; empty for a new one),
|
||||
* $domain_tag_ids and $domain_vendor_ids (role => vendor id) before
|
||||
* including this. Posts what domainFormSet() (functions/domain.php) reads.
|
||||
*
|
||||
* Tabs: Domain (the name, checked as it is typed - or several pasted at once
|
||||
* when adding - what it is for, the star, the expiry and auto-renew), Who
|
||||
* (the registrar and who hosts DNS, the website and email), Details (tags)
|
||||
* and Notes. The records themselves are looked up, never typed, and show in
|
||||
* the domain's quick look.
|
||||
*
|
||||
* Should not be accessed directly.
|
||||
*/
|
||||
|
||||
isset($mysqli) || die("Direct file access is not allowed");
|
||||
|
||||
$client_options = $vendor_options = [];
|
||||
if ($client_id) {
|
||||
$vendor_options = domainVendorChoices($client_id, array_values($domain_vendor_ids));
|
||||
$client_name_for_vendors = getFieldById('clients', $client_id, 'client_name');
|
||||
} else {
|
||||
$sql = mysqli_query($mysqli, "SELECT client_id, client_name, client_abbreviation FROM clients WHERE client_archived_at IS NULL " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$client_options[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
$sql_tags_select = mysqli_query($mysqli, "SELECT tag_id, tag_name, tag_color, tag_icon FROM tags WHERE tag_type = 7 ORDER BY tag_name ASC");
|
||||
|
||||
$form_id = 'domainForm' . ($domain_form_mode === 'edit' ? $domain_id : 'New');
|
||||
|
||||
?>
|
||||
|
||||
<ul class="nav nav-pills nav-fill flex-nowrap overflow-auto mb-3 itflow-asset-form-tabs" role="tablist">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" data-bs-toggle="pill" href="#<?= $form_id ?>Domain"><i class="fas fa-fw fa-globe me-2 d-none d-lg-inline"></i>Domain</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-bs-toggle="pill" href="#<?= $form_id ?>Who"><i class="fas fa-fw fa-building me-2 d-none d-lg-inline"></i>Who</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-bs-toggle="pill" href="#<?= $form_id ?>Details"><i class="fas fa-fw fa-tags me-2 d-none d-lg-inline"></i>Details</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-bs-toggle="pill" href="#<?= $form_id ?>Notes"><i class="fas fa-fw fa-sticky-note me-2 d-none d-lg-inline"></i>Notes</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-content" id="<?= $form_id ?>">
|
||||
|
||||
<!-- The domain -->
|
||||
<div class="tab-pane fade show active" id="<?= $form_id ?>Domain">
|
||||
<div class="row g-3">
|
||||
<?php if (!$client_id) { ?>
|
||||
<div class="col-12">
|
||||
<label class="form-label">Client <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
|
||||
<select class="form-select select2" name="client_id" required data-domain-client>
|
||||
<option value="">- Select Client -</option>
|
||||
<?php foreach ($client_options as $client_option) { ?>
|
||||
<option value="<?= intval($client_option['client_id']) ?>"<?= selectOptionClient($client_option['client_id'], $client_option['client_name'], $client_option['client_abbreviation'] ?? '') ?>><?= escapeHtml($client_option['client_name']) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-text">Set the registrar and hosts from the domain once it's saved.</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if ($domain_form_mode === 'add') { ?>
|
||||
<div class="col-12">
|
||||
<div class="btn-group btn-group-sm" role="group" aria-label="How many">
|
||||
<input type="radio" class="btn-check" name="domain_how_many" id="<?= $form_id ?>One" value="one" checked data-domain-mode>
|
||||
<label class="btn btn-outline-secondary" for="<?= $form_id ?>One"><i class="fas fa-globe me-1"></i>One domain</label>
|
||||
<input type="radio" class="btn-check" name="domain_how_many" id="<?= $form_id ?>Several" value="several" data-domain-mode>
|
||||
<label class="btn btn-outline-secondary" for="<?= $form_id ?>Several"><i class="fas fa-list me-1"></i>Several at once</label>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="col-md-8" data-domain-one>
|
||||
<label class="form-label">Domain name <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-globe"></i></span>
|
||||
<input type="text" class="form-control" name="name" placeholder="example.com" maxlength="200" value="<?= $domain_name ?>" required
|
||||
autocomplete="off" spellcheck="false" data-domain-name <?= $domain_form_mode === 'edit' ? '' : 'autofocus' ?>>
|
||||
</div>
|
||||
<div class="form-text" data-domain-check>Paste a web address if that is easier - it is tidied to the domain.</div>
|
||||
</div>
|
||||
<div class="col-md-4 d-flex align-items-end" data-domain-one>
|
||||
<div class="form-check form-switch mb-2">
|
||||
<input type="checkbox" class="form-check-input" name="favorite" value="1" id="<?= $form_id ?>Favorite" <?= $domain_favorite ? 'checked' : '' ?>>
|
||||
<label class="form-check-label" for="<?= $form_id ?>Favorite"><i class="fas fa-star text-warning me-1"></i>Starred</label>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($domain_form_mode === 'add') { ?>
|
||||
<div class="col-12 d-none" data-domain-several>
|
||||
<label class="form-label">Domain names <strong class="text-danger">*</strong></label>
|
||||
<textarea class="form-control font-monospace" name="names" rows="8" placeholder="example.com example.net shop.example.org" disabled data-domain-names></textarea>
|
||||
<div class="form-text">One per line - or separated by spaces or commas. Each is looked up as it is added; ones already on the client are skipped. The registrar, hosts, auto-renew and tags you set here go on all of them.</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="col-12" data-domain-one>
|
||||
<label class="form-label">Description</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-align-left"></i></span>
|
||||
<input type="text" class="form-control" name="description" placeholder="Primary domain - website and email" maxlength="500" value="<?= $domain_description ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6" data-domain-one>
|
||||
<label class="form-label">Expires</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-calendar-times"></i></span>
|
||||
<input type="date" class="form-control" name="expire" max="2999-12-31" value="<?= $domain_expire ?>">
|
||||
</div>
|
||||
<div class="form-text">Leave it empty - it is looked up from the registry. Set it by hand for registries that don't publish it.</div>
|
||||
</div>
|
||||
<div class="col-md-6 d-flex align-items-center">
|
||||
<div class="form-check form-switch mt-md-3">
|
||||
<input type="checkbox" class="form-check-input" name="auto_renew" value="1" id="<?= $form_id ?>AutoRenew" <?= $domain_auto_renew ? 'checked' : '' ?>>
|
||||
<label class="form-check-label" for="<?= $form_id ?>AutoRenew"><i class="fas fa-sync-alt text-info me-1"></i>Auto-renews at the registrar</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Who registers and hosts it -->
|
||||
<div class="tab-pane fade" id="<?= $form_id ?>Who">
|
||||
<?php if ($client_id) { ?>
|
||||
<div class="row g-3">
|
||||
<?php foreach (DOMAIN_ROLES as $role => $info) {
|
||||
$picked = intval($domain_vendor_ids[$role] ?? 0); ?>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label"><?= $role === 'registrar' ? 'Registrar' : $info['label'] . ' host' ?></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw <?= $info['icon'] ?>"></i></span>
|
||||
<select class="form-select select2" name="<?= $role ?>" data-domain-vendor="<?= $role ?>">
|
||||
<option value="0">- Nobody -</option>
|
||||
<?php foreach ([1, 0] as $theirs) {
|
||||
$group = array_filter($vendor_options, function ($vendor) use ($theirs) { return (intval($vendor['vendor_client_id']) !== 0) === (bool) $theirs; });
|
||||
if (!$group) {
|
||||
continue;
|
||||
} ?>
|
||||
<optgroup label="<?= $theirs ? escapeHtml($client_name_for_vendors) . "'s vendors" : 'Ours' ?>">
|
||||
<?php foreach ($group as $vendor) {
|
||||
$vendor_id = intval($vendor['vendor_id']); ?>
|
||||
<option value="<?= $vendor_id ?>" <?= $picked === $vendor_id ? 'selected' : '' ?><?= selectOptionVendor($vendor['vendor_name'], $vendor['vendor_description']) ?>><?= escapeHtml($vendor['vendor_name']) ?></option>
|
||||
<?php } ?>
|
||||
</optgroup>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="col-12 d-flex flex-wrap align-items-center gap-3">
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" data-domain-same><i class="fas fa-clone me-2"></i>Registrar does it all</button>
|
||||
<span class="form-text mt-0">Someone missing? Add them as a vendor - the client's own, or one of ours if we host it.</span>
|
||||
</div>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<div class="itflow-asset-empty">Pick the client first - the registrar and hosts are their vendors, or ours.</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<!-- Tags -->
|
||||
<div class="tab-pane fade" id="<?= $form_id ?>Details">
|
||||
<label class="form-label">Tags</label>
|
||||
<input type="hidden" name="tags_form" value="1">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-tags"></i></span>
|
||||
<select class="form-select select2" name="tags[]" data-placeholder="Primary, Parked, Client-owned, Managed DNS" multiple>
|
||||
<?php while ($row = mysqli_fetch_assoc($sql_tags_select)) {
|
||||
$tag_id_select = intval($row['tag_id']); ?>
|
||||
<option value="<?= $tag_id_select ?>" <?= in_array($tag_id_select, $domain_tag_ids, true) ? 'selected' : '' ?><?= selectOptionColor($row['tag_color'] ?? '', $row['tag_icon'] ?? '') ?>><?= escapeHtml($row['tag_name']) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
<?php if (!empty($session_is_admin)) { ?>
|
||||
<button class="btn btn-secondary ajax-modal" title="New tag" type="button" data-modal-url="../admin/modals/tag/tag_add.php?type=7">
|
||||
<i class="fas fa-plus"></i>
|
||||
</button>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php if ($domain_form_mode === 'edit') { ?>
|
||||
<p class="text-body-secondary small text-end mt-3 mb-0">Domain ID <span class="font-monospace"><?= $domain_id ?></span></p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<!-- Notes -->
|
||||
<div class="tab-pane fade" id="<?= $form_id ?>Notes">
|
||||
<label class="form-label">Notes</label>
|
||||
<textarea class="form-control" rows="10" name="notes" placeholder="Who owns the registrar account, how renewal is paid, transfer locks, anything to know before touching DNS"><?= $domain_notes ?></textarea>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
itflowReady(function () {
|
||||
var form = document.getElementById(<?= json_encode($form_id) ?>).closest('form');
|
||||
if (form.dataset.domainFormWired) {
|
||||
return;
|
||||
}
|
||||
form.dataset.domainFormWired = '1';
|
||||
|
||||
// A required field on a tab that isn't showing: show that tab and point at it
|
||||
var reported = false;
|
||||
form.addEventListener('invalid', function (e) {
|
||||
var pane = e.target.closest('.tab-pane');
|
||||
var tab = pane && form.querySelector('[data-bs-toggle="pill"][href="#' + pane.id + '"]');
|
||||
if (!tab || pane.classList.contains('active') || reported) {
|
||||
return;
|
||||
}
|
||||
reported = true;
|
||||
tab.addEventListener('shown.bs.tab', function () {
|
||||
reported = false;
|
||||
e.target.reportValidity();
|
||||
}, { once: true });
|
||||
bootstrap.Tab.getOrCreateInstance(tab).show();
|
||||
}, true);
|
||||
|
||||
// One domain, or several pasted at once - only the one in use posts and is required
|
||||
var nameInput = form.querySelector('[data-domain-name]');
|
||||
var namesInput = form.querySelector('[data-domain-names]');
|
||||
form.querySelectorAll('[data-domain-mode]').forEach(function (radio) {
|
||||
radio.addEventListener('change', function () {
|
||||
var several = radio.value === 'several' && radio.checked;
|
||||
// A class, not [hidden] - d-flex on some of them would win over it
|
||||
form.querySelectorAll('[data-domain-one]').forEach(function (el) { el.classList.toggle('d-none', several); });
|
||||
form.querySelectorAll('[data-domain-several]').forEach(function (el) { el.classList.toggle('d-none', !several); });
|
||||
nameInput.disabled = several;
|
||||
nameInput.required = !several;
|
||||
namesInput.disabled = !several;
|
||||
namesInput.required = several;
|
||||
(several ? namesInput : nameInput).focus();
|
||||
});
|
||||
});
|
||||
|
||||
// The name, checked as it is typed: what it is saved as, whether it answers,
|
||||
// whether it is a subdomain, whether the client has it already
|
||||
var check = form.querySelector('[data-domain-check]');
|
||||
var checkDefault = check.textContent;
|
||||
var clientSelect = form.querySelector('[data-domain-client]');
|
||||
var clientInput = form.querySelector('input[name="client_id"]');
|
||||
var timer = null;
|
||||
var last = '';
|
||||
function runCheck() {
|
||||
var value = nameInput.value.trim();
|
||||
var client = clientSelect ? clientSelect.value : (clientInput ? clientInput.value : '');
|
||||
var key = value + '|' + client;
|
||||
if (key === last) {
|
||||
return;
|
||||
}
|
||||
last = key;
|
||||
check.classList.remove('text-danger', 'text-warning', 'text-success');
|
||||
if (!value) {
|
||||
check.textContent = checkDefault;
|
||||
return;
|
||||
}
|
||||
itflowGet('ajax.php', { domain_check: 'true', domain: value, client_id: client, domain_id: <?= intval($domain_id) ?> }, function (data) {
|
||||
var result = {};
|
||||
try { result = JSON.parse(data); } catch (e) {}
|
||||
if (!result.message) {
|
||||
check.textContent = checkDefault;
|
||||
return;
|
||||
}
|
||||
check.classList.add({ ok: 'text-success', warn: 'text-warning', bad: 'text-danger' }[result.state] || '');
|
||||
check.textContent = result.message;
|
||||
});
|
||||
}
|
||||
nameInput.addEventListener('input', function () {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(runCheck, 600);
|
||||
});
|
||||
nameInput.addEventListener('blur', runCheck);
|
||||
if (clientSelect) {
|
||||
clientSelect.addEventListener('change', function () { last = ''; runCheck(); });
|
||||
}
|
||||
|
||||
// The registrar does it all - DNS, the website and email with them too
|
||||
var same = form.querySelector('[data-domain-same]');
|
||||
if (same) {
|
||||
same.addEventListener('click', function () {
|
||||
var registrar = form.querySelector('[data-domain-vendor="registrar"]');
|
||||
form.querySelectorAll('[data-domain-vendor]').forEach(function (select) {
|
||||
if (select === registrar) {
|
||||
return;
|
||||
}
|
||||
if (select.itflowSelect) {
|
||||
select.itflowSelect.setValue(registrar.value);
|
||||
} else {
|
||||
select.value = registrar.value;
|
||||
}
|
||||
select.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@@ -54,9 +54,10 @@ $service_credentials = lookupUserPermission('module_credential') >= 1
|
||||
// Associated Domains
|
||||
$sql_domains = mysqli_query(
|
||||
$mysqli,
|
||||
"SELECT domain_name FROM service_domains
|
||||
LEFT JOIN domains ON service_domains.domain_id = domains.domain_id
|
||||
WHERE service_id = $service_id"
|
||||
"SELECT domains.domain_id, domain_name, domain_expire, domain_auto_renew, domain_archived_at FROM service_domains
|
||||
JOIN domains ON service_domains.domain_id = domains.domain_id
|
||||
WHERE service_id = $service_id
|
||||
ORDER BY domain_name"
|
||||
);
|
||||
|
||||
// Associated Certificates
|
||||
@@ -179,13 +180,12 @@ ob_start();
|
||||
<!-- Domains -->
|
||||
<?php
|
||||
if (mysqli_num_rows($sql_domains) > 0) {
|
||||
echo "<h5><i class='fas fa-fw fa-globe me-2'></i>Domains</h5><ul>";
|
||||
echo "<h5><i class='fas fa-fw fa-globe me-2'></i>Domains</h5><ul class='list-unstyled ms-1'>";
|
||||
mysqli_data_seek($sql_domains, 0);
|
||||
while ($row = mysqli_fetch_assoc($sql_domains)) {
|
||||
if (!empty($row['domain_name'])) {
|
||||
$domain_name = escapeHtml($row['domain_name']);
|
||||
echo "<li><a href='domains.php?client_id=$client_id&q=$domain_name'>$domain_name</a></li>";
|
||||
}
|
||||
// Each opens its quick look, with when it expires
|
||||
echo '<li class="mb-1 d-flex align-items-center gap-2">' . domainLink($row['domain_id'], $row['domain_name'], ['archived' => !empty($row['domain_archived_at'])])
|
||||
. domainExpiryPill(domainExpiry($row['domain_expire'], $row['domain_auto_renew']), true) . '</li>';
|
||||
}
|
||||
echo "</ul>";
|
||||
}
|
||||
|
||||
@@ -80,34 +80,17 @@ if (isset($_POST['add_client'])) {
|
||||
}
|
||||
}
|
||||
|
||||
// Create domain and SSL certificate
|
||||
if (!empty($website) && filter_var($website, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)) {
|
||||
$expire = getDomainExpirationDate($website);
|
||||
$records = getDnsRecords($website);
|
||||
$a = escapeSql($records['a']);
|
||||
$ns = escapeSql($records['ns']);
|
||||
$mx = escapeSql($records['mx']);
|
||||
$whois = escapeSql($records['whois']);
|
||||
|
||||
try {
|
||||
mysqli_query($mysqli, "INSERT INTO domains SET domain_name = '$website', domain_registrar = 0, domain_webhost = 0, domain_expire = '$expire', domain_ip = '$a', domain_name_servers = '$ns', domain_mail_servers = '$mx', domain_raw_whois = '$whois', domain_client_id = $client_id");
|
||||
$extended_log_description .= ", domain $website added";
|
||||
} catch (Exception $e) {
|
||||
$extended_log_description .= ", domain not added";
|
||||
logApp("Client", "warning", "Failed to add domain $website during client creation");
|
||||
}
|
||||
|
||||
// Create domain and SSL certificate - the website's domain, tidied, looked up
|
||||
// like any other; one whose lookup finds nothing is still added, without records
|
||||
$website_domain = domainNormalizeName($website);
|
||||
if ($website_domain !== '') {
|
||||
$website_domain_sql = escapeSql($website_domain);
|
||||
mysqli_query($mysqli, "INSERT INTO domains SET domain_name = '$website_domain_sql', domain_description = 'Website', domain_client_id = $client_id");
|
||||
$domain_id = mysqli_insert_id($mysqli);
|
||||
$certificate = getSslCertificate($website);
|
||||
$extended_log_description .= ", domain $website_domain_sql added";
|
||||
|
||||
if ($certificate['success'] == "TRUE") {
|
||||
$expire = escapeSql($certificate['expire']);
|
||||
$issued_by = escapeSql($certificate['issued_by']);
|
||||
$public_key = escapeSql($certificate['public_key']);
|
||||
|
||||
mysqli_query($mysqli, "INSERT INTO certificates SET certificate_name = '$website', certificate_domain = '$website', certificate_issued_by = '$issued_by', certificate_expire = '$expire', certificate_public_key = '$public_key', certificate_domain_id = $domain_id, certificate_client_id = $client_id");
|
||||
|
||||
$extended_log_description .= ", SSL certificate $website added";
|
||||
if (domainApplyLookup($domain_id, domainLookup($website_domain)) && domainAddCertificate($domain_id, $website_domain, $client_id)) {
|
||||
$extended_log_description .= ", SSL certificate $website_domain_sql added";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,63 +2,153 @@
|
||||
|
||||
/*
|
||||
* ITFlow - GET/POST request handler for client domains
|
||||
*
|
||||
* Every handler checks the support module and the domain's own client; the
|
||||
* registrar and hosts a form names must be the client's vendors or ours.
|
||||
* Lookups (DNS, registration data, expiry) go through domainLookup() in
|
||||
* functions/domain.php, and a lookup that finds nothing changes nothing -
|
||||
* a network blip must not wipe a domain's records or its expiry date.
|
||||
*/
|
||||
|
||||
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
|
||||
|
||||
/** The domain a request names, after the module and client checks - or back with an error if it is gone. */
|
||||
function domainForRequest($domain_id, $level) {
|
||||
global $client_id;
|
||||
enforceUserPermission('module_support', $level);
|
||||
$row = domainRow($domain_id);
|
||||
if (!$row) {
|
||||
flashAlert('That domain no longer exists.', 'error');
|
||||
redirect();
|
||||
}
|
||||
$client_id = intval($row['domain_client_id']);
|
||||
enforceClientAccess();
|
||||
return $row;
|
||||
}
|
||||
|
||||
/** The domains a bulk action names that this agent may act on - [id => row]. */
|
||||
function domainsForBulk($level) {
|
||||
global $client_id;
|
||||
enforceUserPermission('module_support', $level);
|
||||
$rows = [];
|
||||
foreach (array_unique(array_map('intval', (array) ($_POST['domain_ids'] ?? []))) as $domain_id) {
|
||||
$row = domainRow($domain_id);
|
||||
if (!$row) {
|
||||
continue;
|
||||
}
|
||||
$client_id = intval($row['domain_client_id']);
|
||||
enforceClientAccess();
|
||||
$rows[$domain_id] = $row;
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/** Look a domain up and save what came back, with its history. True when something answered. */
|
||||
function domainRefresh($row) {
|
||||
$domain_id = intval($row['domain_id']);
|
||||
$lookup = domainLookup($row['domain_name']);
|
||||
if (!$lookup) {
|
||||
return false;
|
||||
}
|
||||
$before = domainHistorySnapshot($domain_id);
|
||||
domainApplyLookup($domain_id, $lookup);
|
||||
domainWriteHistory($domain_id, $before, domainHistorySnapshot($domain_id));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isset($_POST['add_domain'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
require_once 'domain_model.php';
|
||||
$extended_log_description = '';
|
||||
$client_id = intval($_POST['client_id']);
|
||||
$client_id = intval($_POST['client_id'] ?? 0);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// Set/check/lookup expiry date
|
||||
if (strtotime($expire)) {
|
||||
$expire = "'" . $expire . "'";
|
||||
if (!$client_id || !getFieldById('clients', $client_id, 'client_name')) {
|
||||
flashAlert('Pick the client this domain is for.', 'error');
|
||||
redirect();
|
||||
}
|
||||
else {
|
||||
$expire = getDomainExpirationDate($name);
|
||||
if (strtotime($expire)) {
|
||||
$expire = "'" . $expire . "'";
|
||||
} else {
|
||||
$expire = 'NULL';
|
||||
|
||||
// Several at once - a pasted list, one per line (or separated by spaces or commas)
|
||||
$names_input = trim((string) ($_POST['names'] ?? ''));
|
||||
if ($names_input !== '') {
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
$added = [];
|
||||
$skipped_invalid = $skipped_existing = 0;
|
||||
foreach (array_unique(array_filter(preg_split('/[\s,;]+/', $names_input), 'strlen')) as $input) {
|
||||
$post = $_POST;
|
||||
$post['name'] = $input;
|
||||
$post['expire'] = '';
|
||||
$form = domainFormSet($post, $client_id, 0, $error);
|
||||
if ($form === null) {
|
||||
if (domainNormalizeName($input) === '') {
|
||||
$skipped_invalid++;
|
||||
} else {
|
||||
$skipped_existing++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (isset($added[$form['name']])) {
|
||||
continue;
|
||||
}
|
||||
mysqli_query($mysqli, "INSERT INTO domains SET {$form['set']}, domain_client_id = $client_id");
|
||||
$domain_id = mysqli_insert_id($mysqli);
|
||||
domainSetTags($domain_id, $_POST['tags'] ?? []);
|
||||
$added[$form['name']] = $domain_id;
|
||||
logAudit("Domain", "Create", "$session_name created domain " . escapeSql($form['name']), $client_id, $domain_id);
|
||||
}
|
||||
|
||||
// Look up what there is time for now; the refresher takes the rest first on its next run
|
||||
$looked_up = 0;
|
||||
$started = time();
|
||||
foreach ($added as $name => $domain_id) {
|
||||
if (time() - $started > 20) {
|
||||
break;
|
||||
}
|
||||
if (domainApplyLookup($domain_id, domainLookup($name))) {
|
||||
$looked_up++;
|
||||
}
|
||||
}
|
||||
|
||||
$count = count($added);
|
||||
$message = "<strong>$count</strong> domain" . ($count === 1 ? '' : 's') . " added";
|
||||
if ($count) {
|
||||
$message .= $looked_up === $count ? ' and looked up' : ", <strong>$looked_up</strong> looked up now - the rest are checked on the refresher's next run";
|
||||
}
|
||||
if ($skipped_existing) {
|
||||
$message .= ", <strong>$skipped_existing</strong> already on this client";
|
||||
}
|
||||
if ($skipped_invalid) {
|
||||
$message .= ", <strong>$skipped_invalid</strong> not domain names";
|
||||
}
|
||||
logAudit("Domain", "Bulk Create", "$session_name added $count domain(s)", $client_id);
|
||||
flashAlert($message, $count ? 'success' : 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
// NS, MX, A and WHOIS records/data
|
||||
$records = getDnsRecords($name);
|
||||
$a = escapeSql($records['a']);
|
||||
$ns = escapeSql($records['ns']);
|
||||
$mx = escapeSql($records['mx']);
|
||||
$txt = escapeSql($records['txt']);
|
||||
$whois = escapeSql($records['whois']);
|
||||
$form = domainFormSet($_POST, $client_id, 0, $error);
|
||||
if ($form === null) {
|
||||
flashAlert($error, 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
// Add domain record
|
||||
mysqli_query($mysqli,"INSERT INTO domains SET domain_name = '$name', domain_description = '$description', domain_registrar = $registrar, domain_webhost = $webhost, domain_dnshost = $dnshost, domain_mailhost = $mailhost, 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)
|
||||
mysqli_query($mysqli, "INSERT INTO domains SET {$form['set']}, domain_client_id = $client_id");
|
||||
$domain_id = mysqli_insert_id($mysqli);
|
||||
|
||||
// Get SSL cert for domain (if exists)
|
||||
$certificate = getSslCertificate($name);
|
||||
if ($certificate['success'] == "TRUE") {
|
||||
$expire = escapeSql($certificate['expire']);
|
||||
$issued_by = escapeSql($certificate['issued_by']);
|
||||
$public_key = escapeSql($certificate['public_key']);
|
||||
domainSetTags($domain_id, $_POST['tags'] ?? []);
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO certificates SET certificate_name = '$name', certificate_domain = '$name', certificate_issued_by = '$issued_by', certificate_expire = '$expire', certificate_public_key = '$public_key', certificate_domain_id = $domain_id, certificate_client_id = $client_id");
|
||||
$extended_log_description = ', with associated SSL cert';
|
||||
}
|
||||
// Its records, registration and expiry - and the certificate on its website
|
||||
$found = domainApplyLookup($domain_id, domainLookup($form['name']));
|
||||
$with_certificate = $found && domainAddCertificate($domain_id, $form['name'], $client_id);
|
||||
|
||||
logAudit("Domain", "Create", "$session_name created domain $name$extended_log_description", $client_id, $domain_id);
|
||||
$name = $form['name'];
|
||||
logAudit("Domain", "Create", "$session_name created domain " . escapeSql($name) . ($with_certificate ? ', with its SSL certificate' : ''), $client_id, $domain_id);
|
||||
|
||||
flashAlert("Domain <strong>$name</strong> created");
|
||||
flashAlert("Domain <strong>$name</strong> created" . ($found ? ($with_certificate ? ', with its SSL certificate' : '') : ' - nothing answered for it in DNS, so check the name'), $found ? 'success' : 'warning');
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -68,89 +158,35 @@ if (isset($_POST['edit_domain'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
$row = domainForRequest($_POST['domain_id'] ?? 0, 2);
|
||||
$domain_id = intval($row['domain_id']);
|
||||
|
||||
require_once 'domain_model.php';
|
||||
|
||||
$domain_id = intval($_POST['domain_id']);
|
||||
|
||||
$client_id = intval(getFieldById('domains', $domain_id, 'domain_client_id'));
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// 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';
|
||||
}
|
||||
$form = domainFormSet($_POST, $client_id, $domain_id, $error);
|
||||
if ($form === null) {
|
||||
flashAlert($error, 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
$client_id = intval($_POST['client_id']);
|
||||
$before = domainHistorySnapshot($domain_id);
|
||||
|
||||
// Update NS, MX, A and WHOIS records/data
|
||||
$records = getDnsRecords($name);
|
||||
$a = escapeSql($records['a']);
|
||||
$ns = escapeSql($records['ns']);
|
||||
$mx = escapeSql($records['mx']);
|
||||
$txt = escapeSql($records['txt']);
|
||||
$whois = escapeSql($records['whois']);
|
||||
mysqli_query($mysqli, "UPDATE domains SET {$form['set']} WHERE domain_id = $domain_id");
|
||||
|
||||
// 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 domain
|
||||
mysqli_query($mysqli,"UPDATE domains SET domain_name = '$name', domain_description = '$description', domain_registrar = $registrar, domain_webhost = $webhost, domain_dnshost = $dnshost, domain_mailhost = $mailhost, 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");
|
||||
|
||||
// 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 = escapeSql($column);
|
||||
$old_value = escapeSql($old_value);
|
||||
$new_value = escapeSql($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");
|
||||
}
|
||||
// Only a form that showed the tags changes them
|
||||
if (isset($_POST['tags_form'])) {
|
||||
domainSetTags($domain_id, $_POST['tags'] ?? []);
|
||||
}
|
||||
|
||||
logAudit("Domain", "Edit", "$session_name edited domain $name", $client_id, $domain_id);
|
||||
// A new name is a new domain to look up; otherwise saving stays quick
|
||||
if ($form['name'] !== $row['domain_name']) {
|
||||
domainApplyLookup($domain_id, domainLookup($form['name']));
|
||||
}
|
||||
|
||||
flashAlert("Domain <strong>$name</strong> edited");
|
||||
domainWriteHistory($domain_id, $before, domainHistorySnapshot($domain_id));
|
||||
|
||||
$name = $form['name'];
|
||||
logAudit("Domain", "Edit", "$session_name edited domain " . escapeSql($name), $client_id, $domain_id);
|
||||
|
||||
flashAlert("Domain <strong>$name</strong> updated");
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -160,39 +196,34 @@ if (isset($_GET['refresh_domain'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
$row = domainForRequest($_GET['refresh_domain'], 2);
|
||||
$domain_id = intval($row['domain_id']);
|
||||
$name = $row['domain_name'];
|
||||
|
||||
$domain_id = intval($_GET['refresh_domain']);
|
||||
|
||||
// Get Name and Client ID for logging and alert message
|
||||
$sql = mysqli_query($mysqli,"SELECT domain_name, domain_client_id FROM domains WHERE domain_id = $domain_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$domain_name = escapeSql($row['domain_name']);
|
||||
$client_id = intval($row['domain_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// Lookup expiry date
|
||||
$expire = getDomainExpirationDate($domain_name);
|
||||
if (strtotime($expire)) {
|
||||
$expire = "'" . $expire . "'";
|
||||
} else {
|
||||
$expire = 'NULL';
|
||||
if (!domainRefresh($row)) {
|
||||
flashAlert("Nothing answered for <strong>$name</strong> in DNS - nothing was changed. Check the name, or whether it has lapsed.", 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
// NS, MX, A and WHOIS records/data
|
||||
$records = getDnsRecords($domain_name);
|
||||
$a = escapeSql($records['a']);
|
||||
$ns = escapeSql($records['ns']);
|
||||
$mx = escapeSql($records['mx']);
|
||||
$txt = escapeSql($records['txt']);
|
||||
$whois = escapeSql($records['whois']);
|
||||
logAudit("Domain", "Refresh", "$session_name looked up domain " . escapeSql($name), $client_id, $domain_id);
|
||||
|
||||
mysqli_query($mysqli,"UPDATE domains SET 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");
|
||||
flashAlert("Looked up <strong>$name</strong>");
|
||||
|
||||
logAudit("Domain", "Refresh", "$session_name refreshed records for domain $domain_name", $client_id, $domain_id);
|
||||
redirect();
|
||||
|
||||
flashAlert("Refreshed records for <strong>$domain_name</strong>");
|
||||
}
|
||||
|
||||
if (isset($_GET['favorite_domain']) || isset($_GET['unfavorite_domain'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$favorite = isset($_GET['favorite_domain']) ? 1 : 0;
|
||||
$row = domainForRequest($favorite ? $_GET['favorite_domain'] : $_GET['unfavorite_domain'], 2);
|
||||
$domain_id = intval($row['domain_id']);
|
||||
|
||||
mysqli_query($mysqli, "UPDATE domains SET domain_favorite = $favorite WHERE domain_id = $domain_id");
|
||||
|
||||
logAudit("Domain", "Edit", "$session_name " . ($favorite ? 'starred' : 'unstarred') . " domain " . escapeSql($row['domain_name']), $client_id, $domain_id);
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -202,49 +233,31 @@ if (isset($_GET['archive_domain'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
$row = domainForRequest($_GET['archive_domain'], 2);
|
||||
$domain_id = intval($row['domain_id']);
|
||||
|
||||
$domain_id = intval($_GET['archive_domain']);
|
||||
mysqli_query($mysqli, "UPDATE domains SET domain_archived_at = NOW() WHERE domain_id = $domain_id");
|
||||
|
||||
//Get domain Name
|
||||
$sql = mysqli_query($mysqli,"SELECT domain_client_id, domain_name FROM domains WHERE domain_id = $domain_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$domain_name = escapeSql($row['domain_name']);
|
||||
$client_id = intval($row['domain_client_id']);
|
||||
logAudit("Domain", "Archive", "$session_name archived domain " . escapeSql($row['domain_name']), $client_id, $domain_id);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
mysqli_query($mysqli,"UPDATE domains SET domain_archived_at = NOW() WHERE domain_id = $domain_id");
|
||||
|
||||
logAudit("Domain", "Archive", "$session_name archived domain $domain_name", $client_id, $domain_id);
|
||||
|
||||
flashAlert("Domain <strong>$domain_name archived", 'error');
|
||||
flashAlert("Domain <strong>{$row['domain_name']}</strong> archived", 'error');
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if(isset($_GET['restore_domain'])){
|
||||
if (isset($_GET['restore_domain'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
$row = domainForRequest($_GET['restore_domain'], 2);
|
||||
$domain_id = intval($row['domain_id']);
|
||||
|
||||
$domain_id = intval($_GET['restore_domain']);
|
||||
mysqli_query($mysqli, "UPDATE domains SET domain_archived_at = NULL WHERE domain_id = $domain_id");
|
||||
|
||||
// Get Name and Client ID for logging and alert message
|
||||
$sql = mysqli_query($mysqli,"SELECT domain_name, domain_client_id FROM domains WHERE domain_id = $domain_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$domain_name = escapeSql($row['domain_name']);
|
||||
$client_id = intval($row['domain_client_id']);
|
||||
logAudit("Domain", "Restore", "$session_name restored domain " . escapeSql($row['domain_name']), $client_id, $domain_id);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
mysqli_query($mysqli,"UPDATE domains SET domain_archived_at = NULL WHERE domain_id = $domain_id");
|
||||
|
||||
logAudit("Domain", "Restore", "$session_name restored domain $domain_name", $client_id, $domain_id);
|
||||
|
||||
flashAlert("Domain <strong>$domain_name</strong> restored");
|
||||
flashAlert("Domain <strong>{$row['domain_name']}</strong> restored");
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -254,141 +267,65 @@ if (isset($_GET['delete_domain'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 3);
|
||||
$row = domainForRequest($_GET['delete_domain'], 3);
|
||||
|
||||
$domain_id = intval($_GET['delete_domain']);
|
||||
domainDeleteForGood($row['domain_id']);
|
||||
|
||||
// Get Domain Name and Client ID for logging and alert message
|
||||
$sql = mysqli_query($mysqli,"SELECT domain_name, domain_client_id FROM domains WHERE domain_id = $domain_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$domain_name = escapeSql($row['domain_name']);
|
||||
$client_id = intval($row['domain_client_id']);
|
||||
logAudit("Domain", "Delete", "$session_name deleted domain " . escapeSql($row['domain_name']), $client_id);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM domains WHERE domain_id = $domain_id");
|
||||
|
||||
logAudit("Domain", "Delete", "$session_name deleted domain $domain_name", $client_id);
|
||||
|
||||
flashAlert("Domain <strong>$domain_name</strong> deleted", 'error');
|
||||
flashAlert("Domain <strong>{$row['domain_name']}</strong> deleted", 'error');
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['bulk_archive_domains'])) {
|
||||
if (isset($_POST['bulk_favorite_domains']) || isset($_POST['bulk_unfavorite_domains'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 3);
|
||||
|
||||
if (isset($_POST['domain_ids'])) {
|
||||
|
||||
// Get Selected Count
|
||||
$count = count($_POST['domain_ids']);
|
||||
|
||||
// Cycle through array and archive each record
|
||||
foreach ($_POST['domain_ids'] as $domain_id) {
|
||||
|
||||
$domain_id = intval($domain_id);
|
||||
|
||||
// Get Name and Client ID for logging and alert message
|
||||
$sql = mysqli_query($mysqli,"SELECT domain_name, domain_client_id FROM domains WHERE domain_id = $domain_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$domain_name = escapeSql($row['domain_name']);
|
||||
$client_id = intval($row['domain_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
mysqli_query($mysqli,"UPDATE domains SET domain_archived_at = NOW() WHERE domain_id = $domain_id");
|
||||
|
||||
logAudit("Domain", "Archive", "$session_name archived domain $domain_name", $client_id, $domain_id);
|
||||
}
|
||||
|
||||
logAudit("Domain", "Bulk Archive", "$session_name archived $count domain(s)", $client_id);
|
||||
|
||||
flashAlert("Archived <strong>$count</strong> domain(s)", 'error');
|
||||
|
||||
$favorite = isset($_POST['bulk_favorite_domains']) ? 1 : 0;
|
||||
$count = 0;
|
||||
foreach (domainsForBulk(2) as $domain_id => $row) {
|
||||
mysqli_query($mysqli, "UPDATE domains SET domain_favorite = $favorite WHERE domain_id = $domain_id");
|
||||
logAudit("Domain", "Edit", "$session_name " . ($favorite ? 'starred' : 'unstarred') . " domain " . escapeSql($row['domain_name']), intval($row['domain_client_id']), $domain_id);
|
||||
$count++;
|
||||
}
|
||||
|
||||
flashAlert(($favorite ? 'Starred' : 'Unstarred') . " <strong>$count</strong> domain" . ($count === 1 ? '' : 's'));
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['bulk_restore_domains'])) {
|
||||
// Who registers or hosts them - one vendor into one role for several domains at once
|
||||
if (isset($_POST['bulk_set_domain_vendor'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
if (isset($_POST['domain_ids'])) {
|
||||
|
||||
// Get Selected Count
|
||||
$count = count($_POST['domain_ids']);
|
||||
|
||||
// Cycle through array and restore
|
||||
foreach ($_POST['domain_ids'] as $domain_id) {
|
||||
|
||||
$domain_id = intval($domain_id);
|
||||
|
||||
// Get Name and Client ID for logging and alert message
|
||||
$sql = mysqli_query($mysqli,"SELECT domain_name, domain_client_id FROM domains WHERE domain_id = $domain_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$domain_name = escapeSql($row['domain_name']);
|
||||
$client_id = intval($row['domain_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
mysqli_query($mysqli,"UPDATE domains SET domain_archived_at = NULL WHERE domain_id = $domain_id");
|
||||
|
||||
logAudit("Domain", "Restore", "$session_name restored domain $domain_name", $client_id, $domain_id);
|
||||
$role = $_POST['role'] ?? '';
|
||||
if (!isset(DOMAIN_ROLES[$role])) {
|
||||
flashAlert('Pick what the vendor does for them.', 'error');
|
||||
redirect();
|
||||
}
|
||||
$column = DOMAIN_ROLES[$role]['column'];
|
||||
$vendor_input = intval($_POST['vendor_id'] ?? 0);
|
||||
|
||||
$count = $skipped = 0;
|
||||
foreach (domainsForBulk(2) as $domain_id => $row) {
|
||||
$vendor_id = domainVendorId($vendor_input, $row['domain_client_id']);
|
||||
if ($vendor_input && !$vendor_id) {
|
||||
// That vendor is another client's
|
||||
$skipped++;
|
||||
continue;
|
||||
}
|
||||
|
||||
logAudit("Domain", "Bulk Restore", "$session_name restored $count domain(s)", $client_id);
|
||||
|
||||
flashAlert("Restored <strong>$count</strong> domain(s)");
|
||||
|
||||
$before = domainHistorySnapshot($domain_id);
|
||||
mysqli_query($mysqli, "UPDATE domains SET $column = $vendor_id WHERE domain_id = $domain_id");
|
||||
domainWriteHistory($domain_id, $before, domainHistorySnapshot($domain_id));
|
||||
logAudit("Domain", "Edit", "$session_name set the " . strtolower(DOMAIN_ROLES[$role]['label']) . " vendor on domain " . escapeSql($row['domain_name']), intval($row['domain_client_id']), $domain_id);
|
||||
$count++;
|
||||
}
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['bulk_delete_domains'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 3);
|
||||
|
||||
if (isset($_POST['domain_ids'])) {
|
||||
|
||||
// Get Selected Count
|
||||
$count = count($_POST['domain_ids']);
|
||||
|
||||
// Cycle through array and delete each domain
|
||||
foreach ($_POST['domain_ids'] as $domain_id) {
|
||||
|
||||
$domain_id = intval($domain_id);
|
||||
|
||||
// Get Name and Client ID for logging and alert message
|
||||
$sql = mysqli_query($mysqli,"SELECT domain_name, domain_client_id FROM domains WHERE domain_id = $domain_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$domain_name = escapeSql($row['domain_name']);
|
||||
$client_id = intval($row['domain_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
mysqli_query($mysqli, "DELETE FROM domains WHERE domain_id = $domain_id AND domain_client_id = $client_id");
|
||||
|
||||
logAudit("Domain", "Delete", "$session_name deleted domain $domain_name", $client_id);
|
||||
}
|
||||
|
||||
logAudit("Domain", "Bulk Delete", "$session_name deleted $count domain(s)", $client_id);
|
||||
|
||||
flashAlert("Deleted <strong>$count</strong> domain(s)", 'error');
|
||||
|
||||
}
|
||||
flashAlert("Set the " . strtolower(DOMAIN_ROLES[$role]['label']) . ($role === 'registrar' ? '' : ' host') . " on <strong>$count</strong> domain" . ($count === 1 ? '' : 's') . ($skipped ? ", <strong>$skipped</strong> skipped - that vendor is another client's" : ''));
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -398,59 +335,74 @@ if (isset($_POST['bulk_refresh_domains'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
// Lookups are slow - don't time out mid-batch
|
||||
set_time_limit(0);
|
||||
|
||||
if (isset($_POST['domain_ids'])) {
|
||||
|
||||
// WHOIS lookups are slow - don't time out mid-batch
|
||||
set_time_limit(0);
|
||||
|
||||
// Get Selected Count
|
||||
$count = count($_POST['domain_ids']);
|
||||
|
||||
// Cycle through array and refresh each record
|
||||
foreach ($_POST['domain_ids'] as $domain_id) {
|
||||
|
||||
$domain_id = intval($domain_id);
|
||||
|
||||
// Get Name and Client ID for logging and alert message
|
||||
$sql = mysqli_query($mysqli,"SELECT domain_name, domain_client_id FROM domains WHERE domain_id = $domain_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$domain_name = escapeSql($row['domain_name']);
|
||||
$client_id = intval($row['domain_client_id']);
|
||||
|
||||
enforceClientAccess();
|
||||
|
||||
// Lookup expiry date
|
||||
$expire = getDomainExpirationDate($domain_name);
|
||||
if (strtotime($expire)) {
|
||||
$expire = "'" . $expire . "'";
|
||||
} else {
|
||||
$expire = 'NULL';
|
||||
}
|
||||
|
||||
// NS, MX, A and WHOIS records/data
|
||||
$records = getDnsRecords($domain_name);
|
||||
$a = escapeSql($records['a']);
|
||||
$ns = escapeSql($records['ns']);
|
||||
$mx = escapeSql($records['mx']);
|
||||
$txt = escapeSql($records['txt']);
|
||||
$whois = escapeSql($records['whois']);
|
||||
|
||||
mysqli_query($mysqli,"UPDATE domains SET 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");
|
||||
|
||||
logAudit("Domain", "Refresh", "$session_name refreshed records for domain $domain_name", $client_id, $domain_id);
|
||||
|
||||
// Be gentle on WHOIS servers
|
||||
sleep(1);
|
||||
$count = $found = 0;
|
||||
foreach (domainsForBulk(2) as $domain_id => $row) {
|
||||
$count++;
|
||||
if (domainRefresh($row)) {
|
||||
$found++;
|
||||
logAudit("Domain", "Refresh", "$session_name looked up domain " . escapeSql($row['domain_name']), intval($row['domain_client_id']), $domain_id);
|
||||
}
|
||||
|
||||
logAudit("Domain", "Bulk Refresh", "$session_name refreshed records for $count domain(s)", $client_id);
|
||||
|
||||
flashAlert("Refreshed records for <strong>$count</strong> domain(s)");
|
||||
|
||||
// Be gentle on the registries
|
||||
usleep(500000);
|
||||
}
|
||||
|
||||
$missed = $count - $found;
|
||||
flashAlert("Looked up <strong>$found</strong> domain" . ($found === 1 ? '' : 's') . ($missed ? ", nothing answered for <strong>$missed</strong> - left as they were" : ''), $missed ? 'warning' : 'success');
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['bulk_archive_domains'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$count = 0;
|
||||
foreach (domainsForBulk(2) as $domain_id => $row) {
|
||||
mysqli_query($mysqli, "UPDATE domains SET domain_archived_at = NOW() WHERE domain_id = $domain_id");
|
||||
logAudit("Domain", "Archive", "$session_name archived domain " . escapeSql($row['domain_name']), intval($row['domain_client_id']), $domain_id);
|
||||
$count++;
|
||||
}
|
||||
|
||||
flashAlert("Archived <strong>$count</strong> domain" . ($count === 1 ? '' : 's'), 'error');
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['bulk_restore_domains'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$count = 0;
|
||||
foreach (domainsForBulk(2) as $domain_id => $row) {
|
||||
mysqli_query($mysqli, "UPDATE domains SET domain_archived_at = NULL WHERE domain_id = $domain_id");
|
||||
logAudit("Domain", "Restore", "$session_name restored domain " . escapeSql($row['domain_name']), intval($row['domain_client_id']), $domain_id);
|
||||
$count++;
|
||||
}
|
||||
|
||||
flashAlert("Restored <strong>$count</strong> domain" . ($count === 1 ? '' : 's'));
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['bulk_delete_domains'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$count = 0;
|
||||
foreach (domainsForBulk(3) as $domain_id => $row) {
|
||||
domainDeleteForGood($domain_id);
|
||||
logAudit("Domain", "Delete", "$session_name deleted domain " . escapeSql($row['domain_name']), intval($row['domain_client_id']));
|
||||
$count++;
|
||||
}
|
||||
|
||||
flashAlert("Deleted <strong>$count</strong> domain" . ($count === 1 ? '' : 's'), 'error');
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
@@ -499,18 +451,31 @@ if (isExportRequest('export_domains')) {
|
||||
}
|
||||
|
||||
// Expiring In Filter
|
||||
$expire_query = '';
|
||||
if (!empty($_POST['expire_days'])) {
|
||||
if ($_POST['expire_days'] == "expired") {
|
||||
$expire_query = "AND (domain_expire IS NOT NULL AND domain_expire != '0000-00-00' AND domain_expire < CURDATE())";
|
||||
$expire_query = "AND (domain_expire IS NOT NULL AND domain_expire < CURDATE())";
|
||||
$filter_summary['Expiry'] = 'Expired';
|
||||
} else {
|
||||
$expire_days = intval($_POST['expire_days']);
|
||||
$expire_query = "AND (domain_expire IS NOT NULL AND domain_expire != '0000-00-00' AND domain_expire BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL $expire_days DAY))";
|
||||
$expire_query = "AND (domain_expire IS NOT NULL AND domain_expire BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL $expire_days DAY))";
|
||||
$filter_summary['Expiry'] = "Expiring within $expire_days days";
|
||||
}
|
||||
} else {
|
||||
// Default - any
|
||||
$expire_query = '';
|
||||
}
|
||||
|
||||
// Tags Filter - a domain with any of them
|
||||
$tag_query = '';
|
||||
if (isset($_POST['tags']) && is_array($_POST['tags']) && !empty($_POST['tags'])) {
|
||||
$tag_filter = implode(",", array_map('intval', $_POST['tags']));
|
||||
$tag_query = "AND domains.domain_id IN (SELECT domain_id FROM domain_tags WHERE tag_id IN ($tag_filter))";
|
||||
}
|
||||
|
||||
// Vendor Filter - registrar or any host
|
||||
$vendor_query = '';
|
||||
if (!empty($_POST['vendor'])) {
|
||||
$vendor_filter = intval($_POST['vendor']);
|
||||
$vendor_query = "AND $vendor_filter IN (domain_registrar, domain_dnshost, domain_webhost, domain_mailhost)";
|
||||
$filter_summary['Vendor'] = getFieldById('vendors', $vendor_filter, 'vendor_name');
|
||||
}
|
||||
|
||||
// Search Filter
|
||||
@@ -519,21 +484,25 @@ if (isExportRequest('export_domains')) {
|
||||
$filter_summary['Search'] = $_POST['q'];
|
||||
}
|
||||
|
||||
[$domain_columns, $domain_joins] = domainSelectSql();
|
||||
$sql = mysqli_query(
|
||||
$mysqli,
|
||||
"SELECT domains.*, clients.*,
|
||||
registrar.vendor_name AS domain_registrar_name,
|
||||
webhost.vendor_name AS domain_webhost_name
|
||||
FROM domains
|
||||
LEFT JOIN clients ON client_id = domain_client_id
|
||||
LEFT JOIN vendors AS registrar ON domains.domain_registrar = registrar.vendor_id
|
||||
LEFT JOIN vendors AS webhost ON domains.domain_webhost = webhost.vendor_id
|
||||
WHERE (domains.domain_name LIKE '%$q%' OR domains.domain_description LIKE '%$q%' OR registrar.vendor_name LIKE '%$q%' OR webhost.vendor_name LIKE '%$q%' OR client_name LIKE '%$q%')
|
||||
"SELECT $domain_columns,
|
||||
registrar.vendor_name AS domain_registrar_name, webhost.vendor_name AS domain_webhost_name,
|
||||
dnshost.vendor_name AS domain_dnshost_name, mailhost.vendor_name AS domain_mailhost_name,
|
||||
IF(domain_auto_renew = 1, 'Yes', 'No') AS domain_auto_renew_label,
|
||||
(SELECT GROUP_CONCAT(tag_name ORDER BY tag_name SEPARATOR ', ') FROM domain_tags dt JOIN tags t ON t.tag_id = dt.tag_id WHERE dt.domain_id = domains.domain_id) AS domain_tags
|
||||
FROM domains $domain_joins
|
||||
WHERE (domains.domain_name LIKE '%$q%' OR domains.domain_description LIKE '%$q%' OR domains.domain_notes LIKE '%$q%'
|
||||
OR registrar.vendor_name LIKE '%$q%' OR dnshost.vendor_name LIKE '%$q%' OR webhost.vendor_name LIKE '%$q%' OR mailhost.vendor_name LIKE '%$q%' OR client_name LIKE '%$q%'
|
||||
OR domains.domain_id IN (SELECT domain_id FROM domain_tags JOIN tags USING (tag_id) WHERE tag_name LIKE '%$q%'))
|
||||
AND $archive_query
|
||||
" . clientScopeSql('domain_client_id') . "
|
||||
$client_query
|
||||
$expire_query
|
||||
ORDER BY domains.domain_name ASC"
|
||||
$tag_query
|
||||
$vendor_query
|
||||
ORDER BY client_name ASC, domains.domain_name ASC"
|
||||
);
|
||||
|
||||
$num_rows = mysqli_num_rows($sql);
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
|
||||
|
||||
$name = preg_replace("(^https?://)", "", escapeSql($_POST['name']));
|
||||
$description = escapeSql($_POST['description']);
|
||||
$registrar = intval($_POST['registrar'] ?? 0);
|
||||
$dnshost = intval($_POST['dnshost'] ?? 0);
|
||||
$webhost = intval($_POST['webhost'] ?? 0);
|
||||
$mailhost = intval($_POST['mailhost'] ?? 0);
|
||||
$expire = escapeSql($_POST['expire']);
|
||||
$notes = escapeSql($_POST['notes']);
|
||||
@@ -68,7 +68,8 @@ if (isset($_POST['add_service'])) {
|
||||
if (isset($_POST['domains'])) {
|
||||
foreach($_POST['domains'] as $domain_id) {
|
||||
$domain_id = intval($domain_id);
|
||||
mysqli_query($mysqli, "INSERT INTO service_domains SET service_id = $service_id, domain_id = $domain_id");
|
||||
// Only the client's own domains
|
||||
mysqli_query($mysqli, "INSERT INTO service_domains (service_id, domain_id) SELECT $service_id, domain_id FROM domains WHERE domain_id = $domain_id AND domain_client_id = $client_id");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +158,8 @@ if (isset($_POST['edit_service'])) {
|
||||
if (isset($_POST['domains'])) {
|
||||
foreach($_POST['domains'] as $domain_id) {
|
||||
$domain_id = intval($domain_id);
|
||||
mysqli_query($mysqli, "INSERT INTO service_domains SET service_id = $service_id, domain_id = $domain_id");
|
||||
// Only the client's own domains
|
||||
mysqli_query($mysqli, "INSERT INTO service_domains (service_id, domain_id) SELECT $service_id, domain_id FROM domains WHERE domain_id = $domain_id AND domain_client_id = $client_id");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,14 +110,6 @@ if (!$vendor || (isset($_GET['client_id']) && $vendor_client_id !== intval($clie
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$assets[] = $row;
|
||||
}
|
||||
$sql = mysqli_query($mysqli, "SELECT domain_id, domain_name, domain_description, domain_expire, domain_registrar, domain_webhost, domain_dnshost, domain_mailhost
|
||||
FROM domains
|
||||
WHERE domain_client_id = $client_id AND domain_archived_at IS NULL
|
||||
AND $vendor_id IN (domain_registrar, domain_webhost, domain_dnshost, domain_mailhost)
|
||||
ORDER BY domain_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$domains[] = $row;
|
||||
}
|
||||
$sql = mysqli_query($mysqli, "SELECT services.service_id, service_name, service_description, service_category, service_importance
|
||||
FROM service_vendors JOIN services ON services.service_id = service_vendors.service_id
|
||||
WHERE service_vendors.vendor_id = $vendor_id AND service_client_id = $client_id
|
||||
@@ -128,6 +120,19 @@ if (!$vendor || (isset($_GET['client_id']) && $vendor_client_id !== intval($clie
|
||||
$documents = linkedRecords('vendor', $vendor_id, 'document');
|
||||
$files = linkedRecords('vendor', $vendor_id, 'file');
|
||||
}
|
||||
|
||||
// Domains they register or host - the client's, or for one of ours (DNS or
|
||||
// mail we run for clients), every client's that the agent can see
|
||||
$sql = mysqli_query($mysqli, "SELECT domain_id, domain_name, domain_description, domain_expire, domain_auto_renew, domain_registrar, domain_webhost, domain_dnshost, domain_mailhost,
|
||||
domain_client_id, client_name
|
||||
FROM domains
|
||||
LEFT JOIN clients ON client_id = domain_client_id
|
||||
WHERE domain_archived_at IS NULL AND $vendor_id IN (domain_registrar, domain_webhost, domain_dnshost, domain_mailhost)
|
||||
" . ($is_ours ? "AND client_archived_at IS NULL " . clientScopeSql('domain_client_id') : "AND domain_client_id = $client_id") . "
|
||||
ORDER BY client_name ASC, domain_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$domains[] = $row;
|
||||
}
|
||||
}
|
||||
if ($can_credentials && !$is_ours) {
|
||||
// The whole credential, so the password and 2FA code are right there to use
|
||||
@@ -168,8 +173,12 @@ if (!$vendor || (isset($_GET['client_id']) && $vendor_client_id !== intval($clie
|
||||
'expenses' => ['label' => 'Expenses', 'icon' => 'fa-receipt', 'count' => $spend ? $spend['count'] : 0],
|
||||
'recurring' => ['label' => 'Recurring', 'icon' => 'fa-redo-alt', 'count' => count($recurring)],
|
||||
'cases' => ['label' => 'Cases', 'icon' => 'fa-life-ring', 'count' => $case_count, 'badge' => $case_open_count],
|
||||
'domains' => ['label' => 'Client domains', 'icon' => 'fa-globe', 'count' => count($domains)],
|
||||
'history' => ['label' => 'History', 'icon' => 'fa-history', 'count' => count($history)],
|
||||
];
|
||||
if (!$domains) {
|
||||
unset($vendor_tabs['domains']);
|
||||
}
|
||||
if (!$can_financial) {
|
||||
unset($vendor_tabs['expenses'], $vendor_tabs['recurring']);
|
||||
}
|
||||
@@ -557,12 +566,17 @@ if (!$vendor || (isset($_GET['client_id']) && $vendor_client_id !== intval($clie
|
||||
<!-- Domains they register or host -->
|
||||
<div class="tab-pane fade" id="vendor-pane-domains" role="tabpanel">
|
||||
<div class="itflow-asset-pane-bar">
|
||||
<span class="text-body-secondary small">Domains they register or host, and for what.</span>
|
||||
<span class="text-body-secondary small"><?= $is_ours ? "Clients' domains we register or host with them, and for what." : 'Domains they register or host, and for what.' ?></span>
|
||||
<?php if (!$is_ours && $can_support_edit && !$vendor_archived_at) { ?>
|
||||
<button type="button" class="btn btn-sm btn-primary ajax-modal" data-modal-size="lg" data-modal-url="modals/domain/domain_add.php?client_id=<?= $client_id ?>&vendor_id=<?= $vendor_id ?>">
|
||||
<i class="fas fa-plus me-2"></i>New Domain
|
||||
</button>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php if ($domains) { ?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle mb-0">
|
||||
<thead class="text-nowrap table-light"><tr><th>Domain</th><th>They are</th><th>Expires</th></tr></thead>
|
||||
<thead class="text-nowrap table-light"><tr><th>Domain</th><th>They are</th><th>Expires</th><?= $is_ours ? '<th>Client</th>' : '' ?></tr></thead>
|
||||
<tbody>
|
||||
<?php foreach ($domains as $domain) {
|
||||
$roles = [];
|
||||
@@ -571,14 +585,22 @@ if (!$vendor || (isset($_GET['client_id']) && $vendor_client_id !== intval($clie
|
||||
$roles[] = $role;
|
||||
}
|
||||
}
|
||||
$expiry = softwareRenewal($domain['domain_expire']); ?>
|
||||
$expiry = domainExpiry($domain['domain_expire'], $domain['domain_auto_renew']); ?>
|
||||
<tr>
|
||||
<td>
|
||||
<a class="fw-semibold ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/domain/domain_edit.php?client_id=<?= $client_id ?>&id=<?= intval($domain['domain_id']) ?>"><?= escapeHtml($domain['domain_name']) ?></a>
|
||||
<?php if ($domain['domain_description']) { ?><div class="small text-body-secondary"><?= escapeHtml($domain['domain_description']) ?></div><?php } ?>
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<?= domainTile('sm') ?>
|
||||
<div class="min-w-0">
|
||||
<a class="fw-semibold ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/domain/domain.php?id=<?= intval($domain['domain_id']) ?>"><?= escapeHtml($domain['domain_name']) ?></a>
|
||||
<?php if ($domain['domain_description']) { ?><div class="small text-body-secondary"><?= escapeHtml($domain['domain_description']) ?></div><?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td><?php foreach ($roles as $role) { ?><span class="badge rounded-pill bg-secondary-subtle text-secondary-emphasis fw-normal me-1"><?= $role ?></span><?php } ?></td>
|
||||
<td class="text-nowrap"><?= $expiry ? softwareRenewalPill($expiry) : '<span class="text-body-secondary">-</span>' ?></td>
|
||||
<td class="text-nowrap"><?= domainExpiryPill($expiry, true) ?></td>
|
||||
<?php if ($is_ours) { ?>
|
||||
<td><a href="domains.php?client_id=<?= intval($domain['domain_client_id']) ?>&vendor=<?= $vendor_id ?>"><?= escapeHtml($domain['client_name']) ?></a></td>
|
||||
<?php } ?>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
|
||||
@@ -7,28 +7,17 @@ require_once 'domain_model.php';
|
||||
|
||||
$insert_id = false;
|
||||
|
||||
if (!empty($name) && !empty($client_id)) {
|
||||
// Use the supplied expiry when valid, otherwise look it up from WHOIS.
|
||||
if (strtotime($expire)) {
|
||||
$expire = "'$expire'";
|
||||
} else {
|
||||
$expire = getDomainExpirationDate($name);
|
||||
$expire = strtotime($expire) ? "'$expire'" : 'NULL';
|
||||
}
|
||||
if (!empty($name) && !empty($client_id) && !mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM domains WHERE domain_name = '$name' AND domain_client_id = $client_id LIMIT 1"))) {
|
||||
$expire_sql = $expire !== '' ? "'$expire'" : 'NULL';
|
||||
|
||||
// Populate DNS and WHOIS data from the domain rather than accepting it from the API.
|
||||
$records = getDnsRecords($name);
|
||||
$ip = escapeSql($records['a']);
|
||||
$name_servers = escapeSql($records['ns']);
|
||||
$mail_servers = escapeSql($records['mx']);
|
||||
$txt = escapeSql($records['txt']);
|
||||
$raw_whois = escapeSql($records['whois']);
|
||||
|
||||
$insert_sql = mysqli_query($mysqli, "INSERT INTO domains SET domain_name = '$name', domain_description = '$description', domain_expire = $expire, domain_ip = '$ip', domain_name_servers = '$name_servers', domain_mail_servers = '$mail_servers', domain_txt = '$txt', domain_raw_whois = '$raw_whois', domain_notes = '$notes', domain_registrar = $registrar, domain_webhost = $webhost, domain_dnshost = $dnshost, domain_mailhost = $mailhost, domain_client_id = $client_id");
|
||||
$insert_sql = mysqli_query($mysqli, "INSERT INTO domains SET domain_name = '$name', domain_description = '$description', domain_expire = $expire_sql, domain_auto_renew = $auto_renew, domain_notes = '$notes', domain_registrar = $registrar, domain_webhost = $webhost, domain_dnshost = $dnshost, domain_mailhost = $mailhost, domain_client_id = $client_id");
|
||||
|
||||
if ($insert_sql) {
|
||||
$insert_id = mysqli_insert_id($mysqli);
|
||||
|
||||
// DNS, registration and the expiry come from the domain itself rather than the request
|
||||
domainApplyLookup($insert_id, domainLookup($name));
|
||||
|
||||
logAudit("Domain", "Create", "$name via API ($api_key_name)", $client_id, $insert_id);
|
||||
logAudit("API", "Success", "Created domain $name via API ($api_key_name)", $client_id);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
// Variable assignment from POST (or: blank/from DB is updating)
|
||||
|
||||
if (isset($_POST['domain_name'])) {
|
||||
$name = preg_replace("(^https?://)", "", escapeSql($_POST['domain_name']));
|
||||
// Tidied the way the app keeps it - lowercase, no scheme, path or leading www.
|
||||
$name = escapeSql(domainNormalizeName($_POST['domain_name']));
|
||||
} elseif (isset($domain_row) && isset($domain_row['domain_name'])) {
|
||||
$name = mysqli_real_escape_string($mysqli, $domain_row['domain_name']);
|
||||
} else {
|
||||
@@ -64,4 +65,23 @@ if (isset($_POST['domain_mailhost'])) {
|
||||
$mailhost = $domain_row['domain_mailhost'];
|
||||
} else {
|
||||
$mailhost = 0;
|
||||
}
|
||||
|
||||
if (isset($_POST['domain_auto_renew'])) {
|
||||
$auto_renew = intval($_POST['domain_auto_renew']) ? 1 : 0;
|
||||
} elseif (isset($domain_row) && isset($domain_row['domain_auto_renew'])) {
|
||||
$auto_renew = intval($domain_row['domain_auto_renew']);
|
||||
} else {
|
||||
$auto_renew = 0;
|
||||
}
|
||||
|
||||
// The registrar and hosts must be the client's vendors or ours
|
||||
$registrar = domainVendorId($registrar, $client_id);
|
||||
$webhost = domainVendorId($webhost, $client_id);
|
||||
$dnshost = domainVendorId($dnshost, $client_id);
|
||||
$mailhost = domainVendorId($mailhost, $client_id);
|
||||
|
||||
// An expiry that is not a date is no expiry
|
||||
if ($expire !== '' && !DateTime::createFromFormat('!Y-m-d', $expire)) {
|
||||
$expire = '';
|
||||
}
|
||||
@@ -23,69 +23,27 @@ if (!empty($domain_id)) {
|
||||
LIMIT 1
|
||||
"));
|
||||
|
||||
$original_domain_info = $domain_row;
|
||||
|
||||
require_once 'domain_model.php';
|
||||
|
||||
// Use the supplied expiry when valid, otherwise look it up from WHOIS.
|
||||
if (strtotime($expire)) {
|
||||
$expire = "'$expire'";
|
||||
} else {
|
||||
$expire = getDomainExpirationDate($name);
|
||||
$expire = strtotime($expire) ? "'$expire'" : 'NULL';
|
||||
}
|
||||
$expire_sql = $expire !== '' ? "'$expire'" : 'NULL';
|
||||
$duplicate = $domain_row && mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM domains WHERE domain_name = '$name' AND domain_client_id = $client_id AND domain_id <> $domain_id LIMIT 1"));
|
||||
|
||||
// Populate DNS and WHOIS data from the domain rather than accepting it from the API.
|
||||
$records = getDnsRecords($name);
|
||||
$ip = escapeSql($records['a']);
|
||||
$name_servers = escapeSql($records['ns']);
|
||||
$mail_servers = escapeSql($records['mx']);
|
||||
$txt = escapeSql($records['txt']);
|
||||
$raw_whois = escapeSql($records['whois']);
|
||||
if ($domain_row && $name !== '' && !$duplicate) {
|
||||
$before = domainHistorySnapshot($domain_id);
|
||||
|
||||
$update_sql = mysqli_query($mysqli, "UPDATE domains SET domain_name = '$name', domain_description = '$description', domain_expire = $expire, domain_ip = '$ip', domain_name_servers = '$name_servers', domain_mail_servers = '$mail_servers', domain_txt = '$txt', domain_raw_whois = '$raw_whois', domain_notes = '$notes', domain_registrar = $registrar, domain_webhost = $webhost, domain_dnshost = $dnshost, domain_mailhost = $mailhost WHERE domain_id = $domain_id AND domain_client_id = $client_id AND domain_archived_at IS NULL LIMIT 1");
|
||||
$update_sql = mysqli_query($mysqli, "UPDATE domains SET domain_name = '$name', domain_description = '$description', domain_expire = $expire_sql, domain_auto_renew = $auto_renew, domain_notes = '$notes', domain_registrar = $registrar, domain_webhost = $webhost, domain_dnshost = $dnshost, domain_mailhost = $mailhost WHERE domain_id = $domain_id AND domain_client_id = $client_id AND domain_archived_at IS NULL LIMIT 1");
|
||||
|
||||
if ($update_sql && $domain_row) {
|
||||
// Capture the update result before any history or audit queries run.
|
||||
$update_count = mysqli_affected_rows($mysqli);
|
||||
if ($update_sql) {
|
||||
// Capture the update result before any history or audit queries run.
|
||||
$update_count = mysqli_affected_rows($mysqli);
|
||||
|
||||
$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 AND domain_client_id = $client_id
|
||||
LIMIT 1
|
||||
"));
|
||||
// DNS and registration come from the domain itself; a lookup that finds nothing keeps what was there
|
||||
domainApplyLookup($domain_id, domainLookup($name));
|
||||
domainWriteHistory($domain_id, $before, domainHistorySnapshot($domain_id));
|
||||
|
||||
$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 = escapeSql($column);
|
||||
$old_value = escapeSql($old_value);
|
||||
$new_value = escapeSql($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");
|
||||
}
|
||||
logAudit("Domain", "Edit", "$name via API ($api_key_name)", $client_id, $domain_id);
|
||||
logAudit("API", "Success", "Updated domain $name via API ($api_key_name)", $client_id);
|
||||
}
|
||||
|
||||
logAudit("Domain", "Edit", "$name via API ($api_key_name)", $client_id, $domain_id);
|
||||
logAudit("API", "Success", "Updated domain $name via API ($api_key_name)", $client_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ require_once "includes/inc_all.php";
|
||||
|
||||
enforceContactCan('itdoc');
|
||||
|
||||
$domains_sql = mysqli_query($mysqli, "SELECT domain_id, domain_name, domain_expire FROM domains WHERE domain_client_id = $session_client_id AND domain_archived_at IS NULL ORDER BY domain_expire ASC");
|
||||
$domains_sql = mysqli_query($mysqli, "SELECT domain_id, domain_name, domain_expire, domain_auto_renew FROM domains WHERE domain_client_id = $session_client_id AND domain_archived_at IS NULL ORDER BY domain_expire IS NULL, domain_expire ASC");
|
||||
?>
|
||||
|
||||
<h3>Domains</h3>
|
||||
@@ -26,6 +26,7 @@ $domains_sql = mysqli_query($mysqli, "SELECT domain_id, domain_name, domain_expi
|
||||
<tr>
|
||||
<th>Domain Name</th>
|
||||
<th>Expiry</th>
|
||||
<th>Renews automatically</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -34,12 +35,19 @@ $domains_sql = mysqli_query($mysqli, "SELECT domain_id, domain_name, domain_expi
|
||||
while ($row = mysqli_fetch_assoc($domains_sql)) {
|
||||
$domain_name = escapeHtml($row['domain_name']);
|
||||
$domain_expire = escapeHtml($row['domain_expire']);
|
||||
$expiry = domainExpiry($row['domain_expire'], $row['domain_auto_renew']);
|
||||
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<td><?= $domain_name ?></td>
|
||||
<td><?= $domain_expire ?></td>
|
||||
<td>
|
||||
<?= $domain_expire ?: '-' ?>
|
||||
<?php if ($expiry && $expiry['state'] !== 'active') { ?>
|
||||
<span class="badge text-bg-<?= $expiry['state'] === 'expired' ? 'danger' : ($expiry['auto'] ? 'info' : 'warning') ?> ms-1"><?= escapeHtml($expiry['text']) ?></span>
|
||||
<?php } ?>
|
||||
</td>
|
||||
<td><?= intval($row['domain_auto_renew']) ? 'Yes' : 'No' ?></td>
|
||||
</tr>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
@@ -37,86 +37,46 @@ if ($config_enable_cron == 0) {
|
||||
* ###############################################################################################################
|
||||
*/
|
||||
|
||||
// REFRESH DOMAIN WHOIS DATA (1 a day/run)
|
||||
// Get the oldest updated domain (MariaDB shows NULLs first when ordering by default)
|
||||
$row = mysqli_fetch_assoc(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"));
|
||||
// A batch a run - as many as fit in a few minutes, up to 50. Due are the ones
|
||||
// never looked up, not looked up in a week, or expiring within 60 days and not
|
||||
// looked up today. Least recently tried first: a domain that answers nothing is
|
||||
// touched anyway, so it goes to the back rather than taking a slot every run.
|
||||
// A lookup that finds nothing changes nothing (domainApplyLookup()).
|
||||
$started = time();
|
||||
$checked = $found = 0;
|
||||
$sql = mysqli_query($mysqli, "SELECT domain_id, domain_name FROM domains
|
||||
LEFT JOIN clients ON client_id = domain_client_id
|
||||
WHERE domain_archived_at IS NULL AND client_archived_at IS NULL
|
||||
AND (domain_refreshed_at IS NULL OR domain_refreshed_at < NOW() - INTERVAL 7 DAY
|
||||
OR (domain_expire IS NOT NULL AND domain_expire <= CURDATE() + INTERVAL 60 DAY AND domain_refreshed_at < NOW() - INTERVAL 1 DAY))
|
||||
ORDER BY domain_updated_at ASC
|
||||
LIMIT 50");
|
||||
|
||||
if ($row) {
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
|
||||
if (time() - $started > 240) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Get current data in database
|
||||
$domain_id = intval($row['domain_id']);
|
||||
$domain_name = escapeSql($row['domain_name']);
|
||||
$current_expire = escapeSql($row['domain_expire']);
|
||||
$checked++;
|
||||
|
||||
// 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 = getDnsRecords($domain_name);
|
||||
$a = escapeSql($records['a']);
|
||||
$ns = escapeSql($records['ns']);
|
||||
$mx = escapeSql($records['mx']);
|
||||
$txt = escapeSql($records['txt']);
|
||||
$whois = escapeSql($records['whois']);
|
||||
|
||||
// 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 . "'";
|
||||
$before = domainHistorySnapshot($domain_id);
|
||||
if (domainApplyLookup($domain_id, domainLookup($row['domain_name']))) {
|
||||
domainWriteHistory($domain_id, $before, domainHistorySnapshot($domain_id));
|
||||
$found++;
|
||||
echo "Updated {$row['domain_name']}.\n";
|
||||
} else {
|
||||
// Neither are valid, setting expiry to NULL
|
||||
$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 = escapeSql($column);
|
||||
$old_value = escapeSql($old_value);
|
||||
$new_value = escapeSql($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");
|
||||
}
|
||||
echo "Nothing answered for {$row['domain_name']} - left as it was.\n";
|
||||
}
|
||||
|
||||
// Be gentle on the registries
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
if ($checked) {
|
||||
logApp("Cron-Domain-Refresher", "info", "Looked up $checked domain(s), $found answered.");
|
||||
}
|
||||
|
||||
@@ -231,9 +231,10 @@ if ($config_enable_alert_domain_expire == 1) {
|
||||
//Get Domains Expiring
|
||||
$sql = mysqli_query(
|
||||
$mysqli,
|
||||
"SELECT client_id, client_name, domain_expire, domain_id, domain_name FROM domains
|
||||
"SELECT client_id, client_name, domain_expire, domain_auto_renew, domain_id, domain_name FROM domains
|
||||
LEFT JOIN clients ON domain_client_id = client_id
|
||||
WHERE domain_expire IS NOT NULL AND domain_expire = CURDATE() + INTERVAL $day DAY"
|
||||
WHERE domain_expire IS NOT NULL AND domain_expire = CURDATE() + INTERVAL $day DAY
|
||||
AND domain_archived_at IS NULL AND client_archived_at IS NULL"
|
||||
);
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
@@ -243,7 +244,9 @@ if ($config_enable_alert_domain_expire == 1) {
|
||||
$client_id = intval($row['client_id']);
|
||||
$client_name = escapeSql($row['client_name']);
|
||||
|
||||
appNotify("Domain Expiring", "Domain $domain_name for $client_name will expire in $day Days on $domain_expire", "/agent/domains.php?client_id=$client_id", $client_id);
|
||||
// Auto-renew still fails on an expired card, so it is said rather than skipped
|
||||
$domain_renewal = intval($row['domain_auto_renew']) ? ' - set to auto-renew, check it goes through' : '';
|
||||
appNotify("Domain Expiring", "Domain $domain_name for $client_name will expire in $day Days on $domain_expire$domain_renewal", "/agent/domains.php?client_id=$client_id&open=$domain_id", $client_id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -4686,3 +4686,23 @@ img.itflow-contact-avatar {
|
||||
min-width: 12rem;
|
||||
max-width: 22rem;
|
||||
}
|
||||
|
||||
/* Domains - agent/domains.php and agent/modals/domain/ (functions/domain.php).
|
||||
Records are monospace, one per line with a copy button; the registrar and
|
||||
hosts column keeps to one width. */
|
||||
.itflow-domain-dl dt {
|
||||
white-space: nowrap;
|
||||
}
|
||||
.itflow-domain-dl dd {
|
||||
min-height: 1.5rem;
|
||||
min-width: 0;
|
||||
}
|
||||
.itflow-domain-who {
|
||||
max-width: 18rem;
|
||||
}
|
||||
.itflow-domain-checks li + li {
|
||||
margin-top: .25rem;
|
||||
}
|
||||
.itflow-domain-mail > .d-inline-flex {
|
||||
flex-wrap: nowrap !important;
|
||||
}
|
||||
|
||||
21
db.sql
21
db.sql
@@ -1227,6 +1227,23 @@ CREATE TABLE `domain_history` (
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `domain_tags`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `domain_tags`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `domain_tags` (
|
||||
`domain_id` int(11) NOT NULL,
|
||||
`tag_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`domain_id`,`tag_id`),
|
||||
KEY `tag_id` (`tag_id`),
|
||||
CONSTRAINT `domain_tags_ibfk_1` FOREIGN KEY (`domain_id`) REFERENCES `domains` (`domain_id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `domain_tags_ibfk_2` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`tag_id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `domains`
|
||||
--
|
||||
@@ -1239,10 +1256,13 @@ CREATE TABLE `domains` (
|
||||
`domain_name` varchar(200) NOT NULL,
|
||||
`domain_description` text DEFAULT NULL,
|
||||
`domain_expire` date DEFAULT NULL,
|
||||
`domain_auto_renew` tinyint(1) NOT NULL DEFAULT 0,
|
||||
`domain_ip` varchar(255) DEFAULT NULL,
|
||||
`domain_name_servers` varchar(255) DEFAULT NULL,
|
||||
`domain_mail_servers` varchar(255) DEFAULT NULL,
|
||||
`domain_txt` text DEFAULT NULL,
|
||||
`domain_dmarc` text DEFAULT NULL,
|
||||
`domain_dkim` varchar(255) DEFAULT NULL,
|
||||
`domain_raw_whois` text DEFAULT NULL,
|
||||
`domain_notes` text DEFAULT NULL,
|
||||
`domain_favorite` tinyint(1) NOT NULL DEFAULT 0,
|
||||
@@ -1250,6 +1270,7 @@ CREATE TABLE `domains` (
|
||||
`domain_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(),
|
||||
`domain_archived_at` datetime DEFAULT NULL,
|
||||
`domain_accessed_at` datetime DEFAULT NULL,
|
||||
`domain_refreshed_at` datetime DEFAULT NULL,
|
||||
`domain_registrar` int(11) NOT NULL DEFAULT 0,
|
||||
`domain_webhost` int(11) NOT NULL DEFAULT 0,
|
||||
`domain_dnshost` int(11) NOT NULL DEFAULT 0,
|
||||
|
||||
@@ -283,7 +283,7 @@ function clientOverviewRenewals($client_id, $days = 45) {
|
||||
$sources = [
|
||||
['domain', 'globe', "SELECT domain_id AS id, domain_name AS name, domain_expire AS d FROM domains
|
||||
WHERE domain_client_id = $client_id AND domain_archived_at IS NULL AND domain_expire IS NOT NULL AND domain_expire <= $window",
|
||||
'Domain', "/agent/domains.php?client_id=$client_id&q="],
|
||||
'Domain', "/agent/domains.php?client_id=$client_id&open="],
|
||||
['certificate', 'lock', "SELECT certificate_id AS id, certificate_name AS name, certificate_expire AS d FROM certificates
|
||||
WHERE certificate_client_id = $client_id AND certificate_archived_at IS NULL AND certificate_expire IS NOT NULL AND certificate_expire <= $window",
|
||||
'Certificate', "/agent/certificates.php?client_id=$client_id&q="],
|
||||
@@ -308,7 +308,7 @@ function clientOverviewRenewals($client_id, $days = 45) {
|
||||
'kind' => $kind, 'icon' => $icon, 'label' => $label,
|
||||
'name' => $row['name'], 'date' => $row['d'],
|
||||
'days' => (int) $today->diff($date)->format('%r%a'),
|
||||
'url' => in_array($kind, ['warranty', 'retire', 'software'], true) ? $url . intval($row['id']) : $url . rawurlencode($row['name']),
|
||||
'url' => in_array($kind, ['domain', 'warranty', 'retire', 'software'], true) ? $url . intval($row['id']) : $url . rawurlencode($row['name']),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,6 +296,8 @@ function getDnsRecords($name) {
|
||||
'ns' => '',
|
||||
'mx' => '',
|
||||
'txt' => '',
|
||||
'dmarc' => '',
|
||||
'dkim' => '',
|
||||
'whois' => '',
|
||||
'expire' => ''
|
||||
);
|
||||
@@ -343,10 +345,33 @@ function getDnsRecords($name) {
|
||||
$records['txt'] = implode("\n", $txt_records);
|
||||
}
|
||||
|
||||
// DMARC - the policy record at _dmarc
|
||||
$dmarc = @dns_get_record("_dmarc.$domain", DNS_TXT);
|
||||
if (is_array($dmarc)) {
|
||||
foreach ($dmarc as $record) {
|
||||
if (isset($record['txt']) && stripos($record['txt'], 'v=DMARC1') === 0) {
|
||||
$records['dmarc'] = $record['txt'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DKIM - there is no list of a domain's selectors, so look at the ones the
|
||||
// big senders use (Microsoft 365, Google Workspace, Mailchimp and the usual defaults)
|
||||
$selectors = array();
|
||||
foreach (DOMAIN_DKIM_SELECTORS as $selector) {
|
||||
$dkim = @dns_get_record("$selector._domainkey.$domain", DNS_TXT);
|
||||
$cname = $dkim ? array() : @dns_get_record("$selector._domainkey.$domain", DNS_CNAME);
|
||||
if (!empty($dkim) || !empty($cname)) {
|
||||
$selectors[] = $selector;
|
||||
}
|
||||
}
|
||||
$records['dkim'] = implode("\n", $selectors);
|
||||
|
||||
// Registration data - RDAP first, legacy whois only if the TLD has no RDAP
|
||||
$rdap = getDomainRdap($domain);
|
||||
if ($rdap !== null) {
|
||||
$records['whois'] = substr(getRdapSummary($rdap), 0, 254);
|
||||
$records['whois'] = substr(getRdapSummary($rdap), 0, 4000);
|
||||
|
||||
$expires = getRdapEventDate($rdap, 'expiration');
|
||||
if (!empty($expires)) {
|
||||
@@ -363,7 +388,7 @@ function getDnsRecords($name) {
|
||||
$lines = array_map(function ($line) {
|
||||
return preg_replace('/ +/', ' ', rtrim($line));
|
||||
}, $lines);
|
||||
$records['whois'] = substr(trim(strip_tags(implode("\n", $lines))), 0, 254);
|
||||
$records['whois'] = substr(trim(strip_tags(implode("\n", $lines))), 0, 4000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,3 +492,508 @@ function getDomainExpirationDate($domain) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Domains in the app - what the list, the quick look, the forms
|
||||
// and the refresher share
|
||||
// ============================================================
|
||||
|
||||
/** Expiring within this many days is "soon" - the same 45 days the first expiry alert goes out at. */
|
||||
const DOMAIN_SOON_DAYS = 45;
|
||||
|
||||
/** DKIM selectors looked for - Microsoft 365 (selector1, selector2), Google Workspace, the usual defaults and Mailchimp. */
|
||||
const DOMAIN_DKIM_SELECTORS = ['selector1', 'selector2', 'google', 'default', 'k1', 's1'];
|
||||
|
||||
/** Who does what for a domain: each role, its column and how it is shown. */
|
||||
const DOMAIN_ROLES = [
|
||||
'registrar' => ['column' => 'domain_registrar', 'label' => 'Registrar', 'icon' => 'fa-id-card'],
|
||||
'dnshost' => ['column' => 'domain_dnshost', 'label' => 'DNS', 'icon' => 'fa-sitemap'],
|
||||
'webhost' => ['column' => 'domain_webhost', 'label' => 'Website', 'icon' => 'fa-server'],
|
||||
'mailhost' => ['column' => 'domain_mailhost', 'label' => 'Email', 'icon' => 'fa-envelope'],
|
||||
];
|
||||
|
||||
/** What each tracked column is called in a domain's history. */
|
||||
const DOMAIN_HISTORY_LABELS = [
|
||||
'domain_name' => 'Name', 'domain_description' => 'Description', 'domain_expire' => 'Expiry', 'domain_auto_renew' => 'Auto-renew',
|
||||
'registrar_name' => 'Registrar', 'dnshost_name' => 'DNS host', 'webhost_name' => 'Web host', 'mailhost_name' => 'Mail host',
|
||||
'domain_ip' => 'A records', 'domain_name_servers' => 'Name servers', 'domain_mail_servers' => 'MX records', 'domain_txt' => 'TXT records',
|
||||
'domain_dmarc' => 'DMARC', 'domain_dkim' => 'DKIM', 'domain_raw_whois' => 'WHOIS', 'domain_notes' => 'Notes',
|
||||
];
|
||||
|
||||
/** May this agent do this with domains? 1 is to see them, 2 to change them, 3 to delete them. */
|
||||
function domainCan($level) {
|
||||
return lookupUserPermission('module_support') >= $level;
|
||||
}
|
||||
|
||||
/** The columns and joins for a domain with its client and the vendor behind each role (registrar_name, dnshost_name...). */
|
||||
function domainSelectSql() {
|
||||
$columns = 'domains.*, client_name';
|
||||
$joins = 'LEFT JOIN clients ON client_id = domain_client_id';
|
||||
foreach (DOMAIN_ROLES as $role => $info) {
|
||||
$columns .= ", $role.vendor_name AS {$role}_name, $role.vendor_client_id AS {$role}_client_id, $role.vendor_archived_at AS {$role}_archived_at";
|
||||
$joins .= " LEFT JOIN vendors AS $role ON $role.vendor_id = domains.{$info['column']}";
|
||||
}
|
||||
return [$columns, $joins];
|
||||
}
|
||||
|
||||
/** One domain by id with its client and vendors - raw, or null. */
|
||||
function domainRow($domain_id) {
|
||||
global $mysqli;
|
||||
$domain_id = intval($domain_id);
|
||||
if (!$domain_id) {
|
||||
return null;
|
||||
}
|
||||
[$columns, $joins] = domainSelectSql();
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT $columns FROM domains $joins WHERE domain_id = $domain_id LIMIT 1"));
|
||||
return $row ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A domain name as it is kept - lowercase, without a scheme, a path, a port,
|
||||
* a leading www. or a trailing dot, and international names in their ASCII
|
||||
* form - from whatever was pasted ("https://www.Example.com/contact"). '' when
|
||||
* it is not a domain name.
|
||||
*/
|
||||
function domainNormalizeName($input) {
|
||||
$name = strtolower(trim(html_entity_decode((string) $input, ENT_QUOTES, 'UTF-8')));
|
||||
$name = preg_replace('#^[a-z][a-z0-9+.\-]*://#', '', $name);
|
||||
$name = preg_replace('#^[^@/]*@#', '', $name);
|
||||
$name = preg_split('#[/?\#\s]#', $name)[0];
|
||||
$name = preg_replace('#:\d+$#', '', $name);
|
||||
$name = trim($name, '.');
|
||||
$name = preg_replace('#^www\.#', '', $name);
|
||||
if ($name !== '' && preg_match('/[^\x20-\x7e]/', $name) && function_exists('idn_to_ascii')) {
|
||||
$ascii = idn_to_ascii($name, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46);
|
||||
$name = $ascii ?: $name;
|
||||
}
|
||||
if ($name === '' || strlen($name) > 200 || strpos($name, '.') === false
|
||||
|| !filter_var($name, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)
|
||||
|| !preg_match('/\.[a-z][a-z0-9\-]*[a-z0-9]$|\.xn--[a-z0-9\-]+$/', $name)) {
|
||||
return '';
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
/** A vendor id a domain may use - one of the client's own, or one of ours (the MSP hosting DNS or mail) - else 0. */
|
||||
function domainVendorId($vendor_id, $client_id) {
|
||||
global $mysqli;
|
||||
$vendor_id = intval($vendor_id);
|
||||
$client_id = intval($client_id);
|
||||
if (!$vendor_id) {
|
||||
return 0;
|
||||
}
|
||||
$row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT vendor_id FROM vendors WHERE vendor_id = $vendor_id AND vendor_client_id IN ($client_id, 0) LIMIT 1"));
|
||||
return $row ? intval($row[0]) : 0;
|
||||
}
|
||||
|
||||
/** The vendors a domain's pickers offer - the client's, then ours - plus any already picked, archived or not. */
|
||||
function domainVendorChoices($client_id, array $keep_ids = []) {
|
||||
global $mysqli;
|
||||
$client_id = intval($client_id);
|
||||
$keep = implode(',', array_filter(array_map('intval', $keep_ids))) ?: '0';
|
||||
$sql = mysqli_query($mysqli, "SELECT vendor_id, vendor_name, vendor_description, vendor_client_id FROM vendors
|
||||
WHERE (vendor_client_id IN ($client_id, 0) AND vendor_archived_at IS NULL) OR vendor_id IN ($keep)
|
||||
ORDER BY vendor_client_id = 0, vendor_favorite DESC, vendor_name ASC");
|
||||
$rows = [];
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* The fields a New / Edit form posts, as a SQL SET list, with the tidied name.
|
||||
* Null with $error set when it cannot be saved: not a domain name, already on
|
||||
* this client, or an expiry that is not a date. The vendors must be the
|
||||
* client's or ours.
|
||||
*/
|
||||
function domainFormSet($post, $client_id, $domain_id = 0, &$error = '') {
|
||||
global $mysqli;
|
||||
$error = '';
|
||||
$client_id = intval($client_id);
|
||||
$domain_id = intval($domain_id);
|
||||
$name = domainNormalizeName($post['name'] ?? '');
|
||||
if ($name === '') {
|
||||
$error = "That isn't a domain name - something like example.com.";
|
||||
return null;
|
||||
}
|
||||
$name_sql = escapeSql($name);
|
||||
if (mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM domains WHERE domain_name = '$name_sql' AND domain_client_id = $client_id AND domain_id <> $domain_id LIMIT 1"))) {
|
||||
$error = "$name is already on this client.";
|
||||
return null;
|
||||
}
|
||||
$expire = trim((string) ($post['expire'] ?? ''));
|
||||
if ($expire !== '') {
|
||||
$date = DateTime::createFromFormat('!Y-m-d', $expire);
|
||||
if (!$date || $date->format('Y-m-d') !== $expire) {
|
||||
$error = 'The expiry date is not a date.';
|
||||
return null;
|
||||
}
|
||||
}
|
||||
$fields = [
|
||||
'domain_name' => "'$name_sql'",
|
||||
'domain_description' => "'" . escapeSql(mb_substr(trim((string) ($post['description'] ?? '')), 0, 500)) . "'",
|
||||
'domain_expire' => $expire === '' ? 'NULL' : "'$expire'",
|
||||
'domain_auto_renew' => intval($post['auto_renew'] ?? 0) ? 1 : 0,
|
||||
'domain_favorite' => intval($post['favorite'] ?? 0) ? 1 : 0,
|
||||
'domain_notes' => "'" . escapeSql(trim((string) ($post['notes'] ?? ''))) . "'",
|
||||
];
|
||||
foreach (DOMAIN_ROLES as $role => $info) {
|
||||
$fields[$info['column']] = domainVendorId($post[$role] ?? 0, $client_id);
|
||||
}
|
||||
$set = [];
|
||||
foreach ($fields as $column => $value) {
|
||||
$set[] = "$column = $value";
|
||||
}
|
||||
return ['set' => implode(', ', $set), 'name' => $name, 'expire' => $expire];
|
||||
}
|
||||
|
||||
/** Replace a domain's tags with these - domain tags (type 7) only. */
|
||||
function domainSetTags($domain_id, $tag_ids) {
|
||||
global $mysqli;
|
||||
$domain_id = intval($domain_id);
|
||||
mysqli_query($mysqli, "DELETE FROM domain_tags WHERE domain_id = $domain_id");
|
||||
$tag_ids = array_values(array_unique(array_filter(array_map('intval', (array) $tag_ids))));
|
||||
if (!$tag_ids) {
|
||||
return;
|
||||
}
|
||||
mysqli_query($mysqli, "INSERT IGNORE INTO domain_tags (domain_id, tag_id)
|
||||
SELECT $domain_id, tag_id FROM tags WHERE tag_type = 7 AND tag_id IN (" . implode(',', $tag_ids) . ")");
|
||||
}
|
||||
|
||||
/**
|
||||
* Look a domain up - DNS (A, NS, MX, TXT, DMARC, DKIM), registration data
|
||||
* and the expiry date. Null when nothing answers for it (a typo, a lapsed
|
||||
* domain, or no network), so callers keep what they had rather than wiping it.
|
||||
*/
|
||||
function domainLookup($name) {
|
||||
$name = domainNormalizeName($name);
|
||||
if ($name === '' || !@checkdnsrr($name, 'SOA')) {
|
||||
return null;
|
||||
}
|
||||
$records = getDnsRecords($name);
|
||||
$expire = getDomainExpirationDate($name);
|
||||
$records['expire'] = $expire ?: (string) $records['expire'];
|
||||
return $records;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save what a lookup found. The expiry is the registry's when it gave one,
|
||||
* otherwise the date already there stays (some registries don't publish it);
|
||||
* the WHOIS summary stays when this lookup got none. False when there was
|
||||
* nothing to save.
|
||||
*/
|
||||
function domainApplyLookup($domain_id, $lookup) {
|
||||
global $mysqli;
|
||||
$domain_id = intval($domain_id);
|
||||
if (!$lookup || !$domain_id) {
|
||||
return false;
|
||||
}
|
||||
$set = [
|
||||
"domain_ip = '" . escapeSql($lookup['a']) . "'",
|
||||
"domain_name_servers = '" . escapeSql(mb_substr($lookup['ns'], 0, 255)) . "'",
|
||||
"domain_mail_servers = '" . escapeSql(mb_substr($lookup['mx'], 0, 255)) . "'",
|
||||
"domain_txt = '" . escapeSql($lookup['txt']) . "'",
|
||||
"domain_dmarc = '" . escapeSql($lookup['dmarc'] ?? '') . "'",
|
||||
"domain_dkim = '" . escapeSql(mb_substr($lookup['dkim'] ?? '', 0, 255)) . "'",
|
||||
'domain_refreshed_at = NOW()',
|
||||
];
|
||||
if (trim((string) $lookup['whois']) !== '') {
|
||||
$set[] = "domain_raw_whois = '" . escapeSql($lookup['whois']) . "'";
|
||||
}
|
||||
if (!empty($lookup['expire']) && strtotime($lookup['expire'])) {
|
||||
$set[] = "domain_expire = '" . escapeSql($lookup['expire']) . "'";
|
||||
}
|
||||
mysqli_query($mysqli, "UPDATE domains SET " . implode(', ', $set) . " WHERE domain_id = $domain_id");
|
||||
return true;
|
||||
}
|
||||
|
||||
/** What a domain's history tracks, as it stands now - compared before and after a change by domainWriteHistory(). */
|
||||
function domainHistorySnapshot($domain_id) {
|
||||
$row = domainRow($domain_id);
|
||||
if (!$row) {
|
||||
return [];
|
||||
}
|
||||
$snapshot = [];
|
||||
foreach (array_keys(DOMAIN_HISTORY_LABELS) as $column) {
|
||||
$snapshot[$column] = (string) ($row[$column] ?? '');
|
||||
}
|
||||
return $snapshot;
|
||||
}
|
||||
|
||||
/** Record what changed between two snapshots in the domain's history. */
|
||||
function domainWriteHistory($domain_id, array $before, array $after) {
|
||||
global $mysqli;
|
||||
$domain_id = intval($domain_id);
|
||||
foreach ($after as $column => $new_value) {
|
||||
$old_value = $before[$column] ?? '';
|
||||
if ((string) $old_value === (string) $new_value) {
|
||||
continue;
|
||||
}
|
||||
mysqli_query($mysqli, "INSERT INTO domain_history SET domain_history_column = '" . escapeSql($column) . "',
|
||||
domain_history_old_value = '" . escapeSql($old_value) . "', domain_history_new_value = '" . escapeSql($new_value) . "',
|
||||
domain_history_domain_id = $domain_id");
|
||||
}
|
||||
}
|
||||
|
||||
/** A domain's history, newest first - each change with its label. */
|
||||
function domainHistory($domain_id, $limit = 25) {
|
||||
global $mysqli;
|
||||
$domain_id = intval($domain_id);
|
||||
$limit = max(1, intval($limit));
|
||||
$sql = mysqli_query($mysqli, "SELECT domain_history_column, domain_history_old_value, domain_history_new_value, domain_history_modified_at
|
||||
FROM domain_history WHERE domain_history_domain_id = $domain_id
|
||||
ORDER BY domain_history_modified_at DESC, domain_history_id DESC LIMIT $limit");
|
||||
$rows = [];
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$row['label'] = DOMAIN_HISTORY_LABELS[$row['domain_history_column']] ?? ucfirst(str_replace('_', ' ', preg_replace('/^domain_/', '', $row['domain_history_column'])));
|
||||
$rows[] = $row;
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* When it expires: 'expired', 'soon' (within 45 days) or 'active', with a
|
||||
* tone, a line to show and a short form for the list. A domain set to
|
||||
* auto-renew is blue rather than amber when it is close. Null without a date.
|
||||
*/
|
||||
function domainExpiry($expire, $auto_renew = 0) {
|
||||
$renewal = softwareRenewal($expire, DOMAIN_SOON_DAYS);
|
||||
if (!$renewal) {
|
||||
return null;
|
||||
}
|
||||
$days = $renewal['days'];
|
||||
$auto = intval($auto_renew) === 1;
|
||||
if ($renewal['state'] === 'expired') {
|
||||
$renewal['short'] = 'Expired';
|
||||
} elseif ($renewal['state'] === 'soon') {
|
||||
$when = $days === 0 ? 'today' : ($days === 1 ? 'tomorrow' : "in $days days");
|
||||
$renewal['text'] = ($auto ? 'Auto-renews ' : 'Expires ') . $when;
|
||||
$renewal['short'] = $days === 0 ? 'Today' : ($days === 1 ? 'Tomorrow' : "$days days");
|
||||
$renewal['tone'] = $auto ? 'info' : ($days <= 7 ? 'danger' : 'warning');
|
||||
} else {
|
||||
$renewal['text'] = ($auto ? 'Auto-renews ' : 'Expires ') . timeAgo($renewal['date']);
|
||||
$renewal['short'] = timeAgo($renewal['date']);
|
||||
}
|
||||
$renewal['auto'] = $auto;
|
||||
return $renewal;
|
||||
}
|
||||
|
||||
/** The expiry as a soft pill - red expired, amber soon, blue soon but auto-renewing, otherwise green. */
|
||||
function domainExpiryPill($expiry, $use_text = false) {
|
||||
if (!$expiry) {
|
||||
return '<span class="badge rounded-pill bg-secondary-subtle text-secondary-emphasis border border-secondary-subtle fw-normal" title="No expiry date - look it up or set it">'
|
||||
. '<i class="fas fa-question me-1"></i>Unknown</span>';
|
||||
}
|
||||
$tone = $expiry['tone'];
|
||||
$icon = $expiry['state'] === 'expired' ? 'fa-calendar-times' : ($expiry['auto'] ? 'fa-sync-alt' : ($expiry['state'] === 'soon' ? 'fa-hourglass-half' : 'fa-calendar-check'));
|
||||
return '<span class="badge rounded-pill bg-' . $tone . '-subtle text-' . $tone . '-emphasis border border-' . $tone . '-subtle fw-normal" title="' . escapeHtml($expiry['date'] . ($expiry['auto'] ? ' - set to auto-renew' : '')) . '">'
|
||||
. '<i class="fas ' . $icon . ' me-1"></i>' . escapeHtml($use_text ? $expiry['text'] : $expiry['short']) . '</span>';
|
||||
}
|
||||
|
||||
/** A domain's tile - a globe, in the same rounded square as the other tiles. $size 'xs' | 'sm' | '' | 'lg'. */
|
||||
function domainTile($size = '') {
|
||||
$size_class = in_array($size, ['xs', 'sm', 'lg'], true) ? " itflow-asset-icon-$size" . ($size === 'xs' ? ' itflow-vendor-tile-xs' : '') : '';
|
||||
return '<span class="itflow-asset-icon' . $size_class . ' itflow-asset-tone-network" aria-hidden="true"><i class="fas fa-fw fa-globe"></i></span>';
|
||||
}
|
||||
|
||||
/** A domain wherever a page mentions one: its tile and its name, opening its quick look. 'archived' strikes it through. */
|
||||
function domainLink($domain_id, $name, $options = []) {
|
||||
$domain_id = intval($domain_id);
|
||||
$label = escapeHtml(html_entity_decode((string) $name, ENT_QUOTES, 'UTF-8'));
|
||||
$archived = !empty($options['archived']);
|
||||
$class = trim('text-truncate ' . ($options['class'] ?? '') . ($archived ? ' text-decoration-line-through text-body-secondary' : ''));
|
||||
return '<span class="itflow-contact-ref">' . domainTile('xs')
|
||||
. "<a class=\"ajax-modal $class\" href=\"#\" data-modal-size=\"lg\" data-modal-url=\"modals/domain/domain.php?id=$domain_id\">$label</a></span>";
|
||||
}
|
||||
|
||||
/** Record lines kept one per line (or comma-separated in older data) as a list. */
|
||||
function domainLines($text) {
|
||||
return array_values(array_filter(array_map('trim', preg_split('/[\r\n,]+/', (string) $text)), 'strlen'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Who does what - each vendor with the roles it holds for this domain, so a
|
||||
* registrar that also runs DNS and the website shows once: [vendor_id =>
|
||||
* ['name', 'client_id', 'archived', 'roles' => [labels]]].
|
||||
*/
|
||||
function domainVendors($row) {
|
||||
$vendors = [];
|
||||
foreach (DOMAIN_ROLES as $role => $info) {
|
||||
$vendor_id = intval($row[$info['column']] ?? 0);
|
||||
if (!$vendor_id || ($row["{$role}_name"] ?? null) === null) {
|
||||
continue;
|
||||
}
|
||||
if (!isset($vendors[$vendor_id])) {
|
||||
$vendors[$vendor_id] = ['name' => $row["{$role}_name"], 'client_id' => intval($row["{$role}_client_id"]), 'archived' => !empty($row["{$role}_archived_at"]), 'roles' => []];
|
||||
}
|
||||
$vendors[$vendor_id]['roles'][] = $info['label'];
|
||||
}
|
||||
return $vendors;
|
||||
}
|
||||
|
||||
/** The vendors as small links, each with the roles it holds. */
|
||||
function domainVendorsHtml($row) {
|
||||
$html = '';
|
||||
foreach (domainVendors($row) as $vendor_id => $vendor) {
|
||||
$html .= '<div class="d-flex align-items-center gap-2 min-w-0">' . vendorLink($vendor_id, $vendor['name'], ['archived' => $vendor['archived']])
|
||||
. '<span class="small text-body-secondary text-nowrap">' . escapeHtml(implode(' · ', $vendor['roles'])) . '</span></div>';
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* The email checks MSPs get asked about - is there mail (MX), SPF and how
|
||||
* strict it is, the DMARC policy, DKIM at the common selectors. Each is
|
||||
* [label, state ok|warn|bad|off|unknown, text]. DMARC and DKIM are unknown
|
||||
* until the domain has been looked up since those checks existed.
|
||||
*/
|
||||
function domainMailChecks($row) {
|
||||
$looked_up = !empty($row['domain_refreshed_at']);
|
||||
$has_mail = domainLines($row['domain_mail_servers'] ?? '') !== [];
|
||||
$spf = array_values(array_filter(domainLines(str_replace(',', ' ', (string) ($row['domain_txt'] ?? ''))), function ($line) {
|
||||
return stripos(trim($line, '"'), 'v=spf1') === 0;
|
||||
}));
|
||||
$checks = [];
|
||||
|
||||
$checks['mx'] = $has_mail
|
||||
? ['label' => 'MX', 'state' => 'ok', 'text' => 'Takes mail at ' . implode(', ', array_map(function ($mx) { return preg_replace('/^\d+\s+/', '', $mx); }, array_slice(domainLines($row['domain_mail_servers']), 0, 2)))]
|
||||
: ['label' => 'MX', 'state' => 'off', 'text' => 'No mail servers - it takes no email'];
|
||||
|
||||
if (count($spf) > 1) {
|
||||
$checks['spf'] = ['label' => 'SPF', 'state' => 'bad', 'text' => count($spf) . ' SPF records - receivers treat that as no SPF at all. Merge them into one.'];
|
||||
} elseif (!$spf) {
|
||||
$checks['spf'] = ['label' => 'SPF', 'state' => $has_mail ? 'bad' : 'warn', 'text' => $has_mail ? 'No SPF record - anyone can send as this domain' : 'No SPF record - add "v=spf1 -all" so nobody can send as it'];
|
||||
} else {
|
||||
$record = trim($spf[0], '"');
|
||||
if (preg_match('/[\-~]all\b/i', $record) || stripos($record, 'redirect=') !== false) {
|
||||
$checks['spf'] = ['label' => 'SPF', 'state' => 'ok', 'text' => (stripos($record, '-all') !== false ? 'SPF, hard fail (-all)' : (stripos($record, '~all') !== false ? 'SPF, soft fail (~all)' : 'SPF, redirected')) . ': ' . $record];
|
||||
} else {
|
||||
$checks['spf'] = ['label' => 'SPF', 'state' => 'warn', 'text' => 'SPF that lets anyone through (no -all or ~all): ' . $record];
|
||||
}
|
||||
}
|
||||
|
||||
$dmarc = trim((string) ($row['domain_dmarc'] ?? ''));
|
||||
if (!$looked_up && $dmarc === '') {
|
||||
$checks['dmarc'] = ['label' => 'DMARC', 'state' => 'unknown', 'text' => 'Not checked yet - look the domain up'];
|
||||
} elseif ($dmarc === '') {
|
||||
$checks['dmarc'] = ['label' => 'DMARC', 'state' => $has_mail ? 'bad' : 'warn', 'text' => 'No DMARC record'];
|
||||
} else {
|
||||
$policy = preg_match('/\bp\s*=\s*(none|quarantine|reject)/i', $dmarc, $match) ? strtolower($match[1]) : 'none';
|
||||
$checks['dmarc'] = $policy === 'none'
|
||||
? ['label' => 'DMARC', 'state' => 'warn', 'text' => 'DMARC p=none - reports only, spoofed mail still delivered: ' . $dmarc]
|
||||
: ['label' => 'DMARC', 'state' => 'ok', 'text' => "DMARC p=$policy: $dmarc"];
|
||||
}
|
||||
|
||||
$dkim = domainLines($row['domain_dkim'] ?? '');
|
||||
if (!$looked_up && !$dkim) {
|
||||
$checks['dkim'] = ['label' => 'DKIM', 'state' => 'unknown', 'text' => 'Not checked yet - look the domain up'];
|
||||
} elseif ($dkim) {
|
||||
$checks['dkim'] = ['label' => 'DKIM', 'state' => 'ok', 'text' => 'DKIM at ' . implode(', ', $dkim)];
|
||||
} else {
|
||||
$checks['dkim'] = ['label' => 'DKIM', 'state' => $has_mail ? 'warn' : 'off', 'text' => 'No DKIM at the usual selectors (' . implode(', ', DOMAIN_DKIM_SELECTORS) . ') - it may use another'];
|
||||
}
|
||||
return $checks;
|
||||
}
|
||||
|
||||
/** The email checks as small pills - green, amber, red, grey. */
|
||||
function domainMailPillsHtml(array $checks) {
|
||||
$tones = ['ok' => 'success', 'warn' => 'warning', 'bad' => 'danger', 'off' => 'secondary', 'unknown' => 'secondary'];
|
||||
$icons = ['ok' => 'fa-check', 'warn' => 'fa-exclamation', 'bad' => 'fa-times', 'off' => 'fa-minus', 'unknown' => 'fa-question'];
|
||||
$html = '';
|
||||
foreach ($checks as $check) {
|
||||
$tone = $tones[$check['state']];
|
||||
$html .= '<span class="badge rounded-pill bg-' . $tone . '-subtle text-' . $tone . '-emphasis border border-' . $tone . '-subtle fw-normal" title="' . escapeHtml($check['text']) . '">'
|
||||
. '<i class="fas ' . $icons[$check['state']] . ' me-1"></i>' . escapeHtml($check['label']) . '</span>';
|
||||
}
|
||||
return '<span class="d-inline-flex flex-wrap gap-1">' . $html . '</span>';
|
||||
}
|
||||
|
||||
/** The SQL for "takes mail but SPF is missing or DMARC is missing or only p=none" - the Email gaps filter. */
|
||||
function domainMailGapSql($alias = 'domains') {
|
||||
return "(COALESCE($alias.domain_mail_servers, '') <> '' AND (COALESCE($alias.domain_txt, '') NOT LIKE '%v=spf1%'
|
||||
OR ($alias.domain_refreshed_at IS NOT NULL AND (COALESCE($alias.domain_dmarc, '') = '' OR $alias.domain_dmarc LIKE '%p=none%'))))";
|
||||
}
|
||||
|
||||
/** The registration facts in the WHOIS summary - registrar, registered, status - when it has them one per line. */
|
||||
function domainRegistrationFacts($whois) {
|
||||
$facts = [];
|
||||
foreach (['registrar' => 'Registrar', 'registered' => 'Registered', 'status' => 'Status'] as $key => $label) {
|
||||
if (preg_match('/^' . $label . ':\s*(.+)$/mi', (string) $whois, $match) && strpos((string) $whois, "\n") !== false) {
|
||||
$facts[$key] = trim($match[1]);
|
||||
}
|
||||
}
|
||||
return $facts;
|
||||
}
|
||||
|
||||
/** The certificates for a domain - linked to it, or for it or one of its subdomains on the same client. */
|
||||
function domainCertificates($row) {
|
||||
global $mysqli;
|
||||
$domain_id = intval($row['domain_id']);
|
||||
$client_id = intval($row['domain_client_id']);
|
||||
$name = escapeSql($row['domain_name']);
|
||||
$name_like = escapeSql(str_replace(['\\', '%', '_'], ['\\\\', '\%', '\_'], $row['domain_name']));
|
||||
$sql = mysqli_query($mysqli, "SELECT certificate_id, certificate_name, certificate_domain, certificate_issued_by, certificate_expire FROM certificates
|
||||
WHERE certificate_archived_at IS NULL AND certificate_client_id = $client_id
|
||||
AND (certificate_domain_id = $domain_id OR certificate_domain = '$name' OR certificate_domain LIKE '%.$name_like')
|
||||
ORDER BY certificate_expire IS NULL, certificate_expire ASC");
|
||||
$rows = [];
|
||||
while ($cert = mysqli_fetch_assoc($sql)) {
|
||||
$rows[] = $cert;
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/** The services that use a domain. */
|
||||
function domainServices($domain_id) {
|
||||
global $mysqli;
|
||||
$domain_id = intval($domain_id);
|
||||
$sql = mysqli_query($mysqli, "SELECT services.service_id, service_name, service_importance FROM service_domains
|
||||
JOIN services ON services.service_id = service_domains.service_id WHERE service_domains.domain_id = $domain_id ORDER BY service_name");
|
||||
$rows = [];
|
||||
while ($service = mysqli_fetch_assoc($sql)) {
|
||||
$rows[] = $service;
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/** The client's logins for the domain's registrar and hosts - linked to those vendors - for those who may see credentials. */
|
||||
function domainLogins($row) {
|
||||
$vendor_ids = array_keys(domainVendors($row));
|
||||
if (!$vendor_ids || lookupUserPermission('module_credential') < 1) {
|
||||
return [];
|
||||
}
|
||||
$client_id = intval($row['domain_client_id']);
|
||||
return credentialRows("credential_client_id = $client_id AND credential_id IN (SELECT credential_id FROM vendor_credentials WHERE vendor_id IN (" . implode(',', array_map('intval', $vendor_ids)) . "))");
|
||||
}
|
||||
|
||||
/** Deleting a domain for good - services stop listing it and certificates stop pointing at it. History and tags cascade. */
|
||||
function domainDeleteForGood($domain_id) {
|
||||
global $mysqli;
|
||||
$domain_id = intval($domain_id);
|
||||
mysqli_query($mysqli, "DELETE FROM service_domains WHERE domain_id = $domain_id");
|
||||
mysqli_query($mysqli, "UPDATE certificates SET certificate_domain_id = 0 WHERE certificate_domain_id = $domain_id");
|
||||
mysqli_query($mysqli, "DELETE FROM domains WHERE domain_id = $domain_id");
|
||||
}
|
||||
|
||||
/**
|
||||
* Bring an SSL certificate for a new domain in, when its website has one and
|
||||
* the client has none for that name yet. True when one was added.
|
||||
*/
|
||||
function domainAddCertificate($domain_id, $name, $client_id) {
|
||||
global $mysqli;
|
||||
$domain_id = intval($domain_id);
|
||||
$client_id = intval($client_id);
|
||||
$name_sql = escapeSql($name);
|
||||
if (mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM certificates WHERE certificate_client_id = $client_id AND certificate_domain IN ('$name_sql', 'www.$name_sql') LIMIT 1"))) {
|
||||
return false;
|
||||
}
|
||||
$certificate = getSslCertificate($name);
|
||||
if (empty($certificate['success'])) {
|
||||
return false;
|
||||
}
|
||||
mysqli_query($mysqli, "INSERT INTO certificates SET certificate_name = '$name_sql', certificate_domain = '$name_sql',
|
||||
certificate_issued_by = '" . escapeSql($certificate['issued_by']) . "', certificate_expire = '" . escapeSql($certificate['expire']) . "',
|
||||
certificate_public_key = '" . escapeSql($certificate['public_key']) . "', certificate_domain_id = $domain_id, certificate_client_id = $client_id");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -187,6 +187,15 @@ function getExportColumns($export_type) {
|
||||
'domain_registrar' => ['label' => 'Registrar', 'field' => 'domain_registrar_name'],
|
||||
'domain_webhost' => ['label' => 'Web Host', 'field' => 'domain_webhost_name'],
|
||||
'domain_expire' => ['label' => 'Expiration Date'],
|
||||
'domain_dnshost' => ['label' => 'DNS Host', 'field' => 'domain_dnshost_name', 'default' => false],
|
||||
'domain_mailhost' => ['label' => 'Mail Host', 'field' => 'domain_mailhost_name', 'default' => false],
|
||||
'domain_auto_renew' => ['label' => 'Auto-renew', 'field' => 'domain_auto_renew_label', 'default' => false],
|
||||
'domain_name_servers' => ['label' => 'Name Servers', 'weight' => 2, 'default' => false],
|
||||
'domain_mail_servers' => ['label' => 'MX Records', 'weight' => 2, 'default' => false],
|
||||
'domain_dmarc' => ['label' => 'DMARC', 'weight' => 2, 'default' => false],
|
||||
'domain_tags' => ['label' => 'Tags', 'weight' => 2, 'default' => false],
|
||||
'domain_notes' => ['label' => 'Notes', 'weight' => 3, 'default' => false],
|
||||
'client_name' => ['label' => 'Client', 'weight' => 2, 'default' => false],
|
||||
],
|
||||
|
||||
// Defaults match what this export has always emitted, secrets included.
|
||||
|
||||
@@ -287,18 +287,19 @@ function globalSearchGroups($terms, $deep) {
|
||||
|
||||
$groups[] = [
|
||||
'key' => 'domains', 'label' => 'Domains', 'icon' => 'globe', 'module' => 'module_support',
|
||||
'select' => 'domain_id, domain_name, domain_expire, domain_client_id, client_name',
|
||||
'select' => 'domain_id, domain_name, domain_description, domain_expire, domain_auto_renew, domain_client_id, client_name',
|
||||
'from' => 'domains LEFT JOIN clients ON domain_client_id = client_id',
|
||||
'where' => "domain_archived_at IS NULL AND domain_name LIKE '%$like%'",
|
||||
'where' => "domain_archived_at IS NULL AND (domain_name LIKE '%$like%' OR domain_description LIKE '%$like%')",
|
||||
'scope' => 'domain_client_id',
|
||||
'order' => "(domain_name = '$eq') DESC, (domain_name LIKE '$like%') DESC, domain_name",
|
||||
'list_url' => '/agent/domains.php?' . http_build_query(['q' => $q]),
|
||||
'item' => function ($row) {
|
||||
return [
|
||||
'title' => $row['domain_name'],
|
||||
'subtitle' => $row['domain_expire'] ? 'Expires ' . $row['domain_expire'] : '',
|
||||
'subtitle' => implode(' · ', array_filter([($expiry = domainExpiry($row['domain_expire'], $row['domain_auto_renew'])) ? $expiry['text'] : '', $row['domain_description']])),
|
||||
'context' => $row['client_name'],
|
||||
'url' => globalSearchClientUrl('domains.php', $row['domain_client_id'], ['q' => $row['domain_name']]),
|
||||
// Straight to its quick look on the client's domains page
|
||||
'url' => globalSearchClientUrl('domains.php', $row['domain_client_id'], ['open' => intval($row['domain_id'])]),
|
||||
];
|
||||
},
|
||||
];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Tags on clients, locations, contacts, credentials, assets and vendors.
|
||||
* Tags on clients, locations, contacts, credentials, assets, vendors and domains.
|
||||
*
|
||||
* Every list and detail page draws a record's tags with tagPills(): coloured
|
||||
* pills that open the list filtered to that tag, then a "+" pill that opens
|
||||
@@ -10,7 +10,7 @@
|
||||
* returns, so the page never reloads and nothing goes through a modal.
|
||||
*/
|
||||
|
||||
/* What differs between the six kinds of tagged record. */
|
||||
/* What differs between the seven kinds of tagged record. */
|
||||
function tagEntity($entity) {
|
||||
$entities = [
|
||||
'client' => [
|
||||
@@ -50,6 +50,12 @@ function tagEntity($entity) {
|
||||
'table' => 'vendors', 'id' => 'vendor_id', 'client' => 'vendor_client_id', 'name' => 'vendor_name',
|
||||
'log' => 'Vendor', 'list' => 'vendors.php'
|
||||
],
|
||||
'domain' => [
|
||||
'type' => 7, 'label' => 'domain', 'module' => 'module_support',
|
||||
'link_table' => 'domain_tags', 'link_record' => 'domain_id', 'link_tag' => 'tag_id',
|
||||
'table' => 'domains', 'id' => 'domain_id', 'client' => 'domain_client_id', 'name' => 'domain_name',
|
||||
'log' => 'Domain', 'list' => 'domains.php'
|
||||
],
|
||||
];
|
||||
|
||||
return $entities[$entity] ?? null;
|
||||
|
||||
@@ -71,7 +71,7 @@ function cronJobRegistry(): array
|
||||
'name' => 'domain_refresher',
|
||||
'label' => 'Domain Refresher',
|
||||
'script' => 'domain_refresher.php',
|
||||
'description' => 'Refreshes WHOIS and DNS for the domain that was checked longest ago. One domain per run.',
|
||||
'description' => 'Looks up DNS, registration and expiry for domains that are due - never looked up, not in a week, or expiring within 60 days. Up to 50 a run.',
|
||||
'schedule' => 'Daily',
|
||||
'daily_at' => '04:00',
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user