diff --git a/public/admin.html b/public/admin.html index ccfcf89..7a4bb3c 100644 --- a/public/admin.html +++ b/public/admin.html @@ -12,6 +12,7 @@
DripRunner ADMIN
+
' + esc(d.error) + '
'; return; } + if (d.error) { try { localStorage.removeItem('dr.admin'); } catch (e) {} document.body.innerHTML = '' + esc(d.error) + '. Enter the key again.
'; return; } + $('stamp').textContent = 'updated ' + new Date().toLocaleTimeString('en-US', { timeZone: 'America/Chicago', hour: 'numeric', minute: '2-digit', second: '2-digit' }) + ' CT'; S = d; var p = d.pool; $('links').innerHTML = 'Tester page: ' + esc(d.curtain) + ' · POL $' + f4(d.usdPerPol) + ' (from the IAP contract)'; $('pool').innerHTML = stat('Available now', f4(p.available) + ' POL') + stat('In from refuels', f4(p.in)) + stat('Back from spends', f4(p.spends)) + stat('Out as drips', f4(p.out)) + stat('Seed float', f4(p.seed)) + stat('Granted today', f4(p.grantedToday) + ' / ' + f4(p.dailyCapPol)); @@ -37,5 +39,9 @@ $('settings').addEventListener('submit', function (e) { api('/api/admin/settings', body).then(function (r) { $('saveOut').textContent = r.ok ? 'Saved.' : (r.error || 'Failed'); load(); }); }); $('tick').addEventListener('click', function () { $('tickOut').textContent = 'running…'; api('/api/admin/faucet/tick', {}).then(function (r) { $('tickOut').textContent = JSON.stringify(r); load(); }); }); +$('refresh').addEventListener('click', function () { $('stamp').textContent = 'refreshing…'; load(); }); +$('auto').addEventListener('change', function () { try { localStorage.setItem('dr.admin.auto', this.checked ? '1' : '0'); } catch (e) {} }); +try { $('auto').checked = localStorage.getItem('dr.admin.auto') !== '0'; } catch (e) {} +setInterval(function () { if ($('auto').checked && !document.hidden && document.activeElement.tagName !== 'INPUT' && document.activeElement.tagName !== 'TEXTAREA') load(); }, 60000); load(); })(); diff --git a/server.js b/server.js index 2e5e285..4fd073e 100644 --- a/server.js +++ b/server.js @@ -144,7 +144,7 @@ const server = http.createServer(async (req, res) => { // ---- static + pages ---- if (p === '/' || p === '/index.html') { if (curtained(req, res, u)) return; return sendFile(res, path.join(PUBLIC_DIR, 'index.html')); } if (p === '/play') return sendFile(res, path.join(PUBLIC_DIR, 'play.html')); - if (p === '/admin') { if (!admin(req, u)) return page(res, 403, 'Admin', 'Key required.
'); return sendFile(res, path.join(PUBLIC_DIR, 'admin.html')); } + if (p === '/admin') return sendFile(res, path.join(PUBLIC_DIR, 'admin.html')); // the page asks for the key; every /api/admin call checks it if (p === '/spawn.js') return sendFile(res, path.join(__dirname, 'lib', 'spawn.js')); if (/^\/[a-z0-9._-]+\.(css|js|png|jpg|svg|ico|webp|mp4)$/i.test(p) && !p.includes('..')) return sendFile(res, path.join(PUBLIC_DIR, p.slice(1)));