69 lines
2.3 KiB
JavaScript
69 lines
2.3 KiB
JavaScript
// Domains UI functions
|
|
function renderDnsConflicts() {
|
|
if (window.genericFilter) window.genericFilter('dns-conflicts');
|
|
}
|
|
|
|
function openAddModal() {
|
|
const modal = document.getElementById('addDomainModal');
|
|
if (modal) modal.showModal();
|
|
}
|
|
|
|
async function submitAddDomain() {
|
|
const domainEl = document.getElementById('modal-domain');
|
|
const hashEl = document.getElementById('modal-hash');
|
|
const sslEl = document.getElementById('modal-ssl');
|
|
if (!domainEl || !hashEl) return;
|
|
|
|
const domain = domainEl.value.trim();
|
|
const hash = hashEl.value.trim();
|
|
const ssl = sslEl ? sslEl.checked : false;
|
|
try {
|
|
const response = await fetch('/api/add-domain', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ domain, hash, ssl })
|
|
});
|
|
if (!response.ok) {
|
|
throw new Error(await response.text());
|
|
}
|
|
if (window.showNotification) window.showNotification('Domain added successfully');
|
|
const modal = document.getElementById('addDomainModal');
|
|
if (modal) modal.close();
|
|
domainEl.value = '';
|
|
hashEl.value = '';
|
|
if (sslEl) sslEl.checked = false;
|
|
if (window.genericFetch) window.genericFetch('domains', true);
|
|
} catch (err) {
|
|
console.error('Failed to add domain:', err);
|
|
if (window.showNotification) window.showNotification('Failed to add domain: ' + err.message, 'error');
|
|
}
|
|
}
|
|
|
|
function removeDomain(domain) {
|
|
if (window.showConfirm) {
|
|
window.showConfirm(`Remove ${domain}?`, async () => {
|
|
try {
|
|
const response = await fetch('/api/remove-domain', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ domain })
|
|
});
|
|
if (!response.ok) {
|
|
throw new Error(await response.text());
|
|
}
|
|
if (window.showNotification) window.showNotification('Domain removed successfully');
|
|
if (window.genericFetch) window.genericFetch('domains', true);
|
|
} catch (err) {
|
|
console.error('Failed to remove domain:', err);
|
|
if (window.showNotification) window.showNotification('Failed to remove domain: ' + err.message, 'error');
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
window.renderDnsConflicts = renderDnsConflicts;
|
|
window.openAddModal = openAddModal;
|
|
window.submitAddDomain = submitAddDomain;
|
|
window.removeDomain = removeDomain;
|
|
|