diff --git a/public_html/index.html b/public_html/index.html index dce28c1..cdc8553 100644 --- a/public_html/index.html +++ b/public_html/index.html @@ -793,9 +793,7 @@ body::after{
-
-
-
+ @@ -828,6 +826,35 @@ body::after{ + +
@@ -1487,7 +1514,7 @@ function switchTab(name) { if (name === 'news') loadNews(); if (name === 'agents') loadAgents(); if (name === 'alerts') loadAlerts(); - if (name === 'sites') loadSites(); + if (name === 'sites') { openSitesModal(); return; } } // ── CHAT ────────────────────────────────────────────────────────────── @@ -1899,129 +1926,106 @@ document.addEventListener('click', function(e) { }); + + // ── SITES MANAGER ──────────────────────────────────────────────────── let sitesData = {}; +function openSitesModal() { + document.getElementById('sitesModal').style.display = 'flex'; + loadSites(); +} +function closeSitesModal() { + document.getElementById('sitesModal').style.display = 'none'; +} +// Close on backdrop click +document.getElementById('sitesModal').addEventListener('click', function(e) { + if (e.target === this) closeSitesModal(); +}); + async function loadSites() { - const el = document.getElementById('sites-content'); - el.innerHTML = '
'; + document.getElementById('sites-grid').innerHTML = '
LOADING SITE SETTINGS...
'; const res = await api('sites'); - if (!res.success) { el.innerHTML = '
FAILED TO LOAD SITE SETTINGS
'; return; } + if (!res.success) { + document.getElementById('sites-grid').innerHTML = '
FAILED TO LOAD SETTINGS
'; + return; + } sitesData = res.sites; - renderSites(); + // Pre-fill global key from first site + const firstKey = Object.values(res.sites)[0]?.api_key || ''; + document.getElementById('global-api-key').value = firstKey; + renderSiteCards(); } -function renderSites() { - const el = document.getElementById('sites-content'); - const sites = sitesData; - - // Get the shared API key from first site - const firstSite = Object.values(sites)[0] || {}; - const apiKey = firstSite.api_key || ''; - - let html = ` -
SITES MANAGER
- - -
-
▸ CYBERMAIL API KEY — ALL SITES
-
- - -
-
-
`; - - // Per-site cards - for (const [id, s] of Object.entries(sites)) { +function renderSiteCards() { + const grid = document.getElementById('sites-grid'); + let html = ''; + for (const [id, s] of Object.entries(sitesData)) { html += ` -
-
-
-
${s.name.toUpperCase()}
-
${s.url}
-
+
+
+
${s.name.toUpperCase()}
+
${s.url}
-
-
-
FROM EMAIL
- -
-
-
FROM NAME
- -
-
-
ADMIN NOTIFICATION EMAIL
- -
+
+
FROM EMAIL
+
-
+
+
FROM NAME
+ +
+
+
ADMIN NOTIFICATION EMAIL
+ +
+
- +
`; } - - el.innerHTML = html; + grid.innerHTML = html; } async function pushApiKey() { const key = document.getElementById('global-api-key').value.trim(); const status = document.getElementById('push-status'); - if (!key) { status.textContent = '✗ API key required'; status.style.color = '#f44'; return; } - status.textContent = 'PUSHING...'; - status.style.color = 'var(--text-dim)'; + if (!key) { status.style.color='#f44'; status.textContent='✗ API KEY REQUIRED'; return; } + status.style.color='var(--text-dim)'; status.textContent='PUSHING TO ALL SITES...'; const res = await api('sites', 'POST', {action:'push_key', api_key:key}); if (res.success) { const ok = Object.values(res.results).filter(Boolean).length; const total = Object.keys(res.results).length; status.style.color = ok === total ? 'var(--cyan)' : '#fa0'; status.textContent = `✓ PUSHED TO ${ok}/${total} SITES`; - // Update local cache for (const id of Object.keys(sitesData)) sitesData[id].api_key = key; } else { - status.style.color = '#f44'; - status.textContent = '✗ ' + (res.error || 'FAILED'); + status.style.color='#f44'; status.textContent='✗ ' + (res.error || 'FAILED'); } } async function saveSite(id) { const status = document.getElementById(id + '-status'); - status.textContent = 'SAVING...'; - status.style.color = 'var(--text-dim)'; - const payload = { + status.style.color='var(--text-dim)'; status.textContent='SAVING...'; + const res = await api('sites', 'POST', { action: 'save', site: id, - from_email: document.getElementById(id + '-from_email').value.trim(), - from_name: document.getElementById(id + '-from_name').value.trim(), - admin_email: document.getElementById(id + '-admin_email').value.trim(), - }; - const res = await api('sites', 'POST', payload); + from_email: document.getElementById(id+'-from_email').value.trim(), + from_name: document.getElementById(id+'-from_name').value.trim(), + admin_email: document.getElementById(id+'-admin_email').value.trim(), + }); if (res.success) { - status.style.color = 'var(--cyan)'; - status.textContent = '✓ SAVED'; - setTimeout(() => { status.textContent = ''; }, 3000); - // Update local cache - if (sitesData[id]) { - sitesData[id].from_email = payload.from_email; - sitesData[id].from_name = payload.from_name; - sitesData[id].admin_email = payload.admin_email; - } + status.style.color='var(--cyan)'; status.textContent='✓ SAVED'; + setTimeout(() => { status.textContent=''; }, 3000); } else { - status.style.color = '#f44'; - status.textContent = '✗ ' + (res.error || 'FAILED'); + status.style.color='#f44'; status.textContent='✗ ' + (res.error || 'FAILED'); } }