diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9095c52 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +node_modules/ +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.env +.env.* +*.log diff --git a/index.js b/index.js index cb8a59c..97fb78c 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,8 @@ const express = require('express'); const https = require('https'); +const http = require('http'); const app = express(); +app.use(express.json()); const PORT = 3000; // ─── IP Helpers ─────────────────────────────────────────────────────────────── @@ -30,8 +32,9 @@ function getPublicIP() { // ─── Internet Monitor State ─────────────────────────────────────────────────── -const CHECK_INTERVAL_MS = 5000; -const CHECK_URL = 'https://www.google.com'; +let checkIntervalMs = 5000; +let checkUrl = 'https://www.google.com'; +let intervalId = null; let isOnline = true; let outageStart = null; @@ -41,7 +44,8 @@ let totalDowntimeMs = 0; function checkConnectivity() { return new Promise((resolve) => { - const req = https.get(CHECK_URL, { timeout: 4000 }, (res) => { + const mod = checkUrl.startsWith('https://') ? https : http; + const req = mod.get(checkUrl, { timeout: 4000 }, (res) => { res.resume(); resolve(true); }); @@ -75,7 +79,12 @@ function formatDuration(ms) { return `${sec}s`; } -setInterval(monitor, CHECK_INTERVAL_MS); +function restartMonitor() { + if (intervalId) clearInterval(intervalId); + intervalId = setInterval(monitor, checkIntervalMs); +} + +restartMonitor(); monitor(); // ─── Routes ─────────────────────────────────────────────────────────────────── @@ -249,6 +258,63 @@ app.get('/', async (req, res) => { } .export-menu a:hover { background: #243044; } .export-menu a + a { border-top: 1px solid #334155; } + + /* Settings */ + .settings-btn { + display: inline-flex; align-items: center; gap: 0.45rem; + background: #1e293b; border: 1px solid #334155; color: #e2e8f0; + padding: 0.4rem 1rem; border-radius: 8px; font-size: 0.85rem; + font-weight: 600; cursor: pointer; transition: background 0.15s; + } + .settings-btn:hover { background: #243044; } + .modal-overlay { + display: none; position: fixed; inset: 0; + background: rgba(0,0,0,.65); z-index: 200; + align-items: center; justify-content: center; + } + .modal-overlay.open { display: flex; } + .modal { + background: #1e293b; border: 1px solid #334155; + border-radius: 16px; padding: 1.75rem; + width: 100%; max-width: 420px; + box-shadow: 0 20px 60px rgba(0,0,0,.5); + } + .modal-title { font-size: 1rem; font-weight: 700; margin-bottom: 1.25rem; } + .form-group { margin-bottom: 1rem; } + .form-label { + display: block; font-size: 0.75rem; font-weight: 600; color: #94a3b8; + text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.4rem; + } + .form-input { + width: 100%; background: #0f172a; border: 1px solid #334155; + border-radius: 8px; padding: 0.55rem 0.75rem; + color: #e2e8f0; font-size: 0.9rem; outline: none; + transition: border-color 0.15s; + } + .form-input:focus { border-color: #6366f1; } + .form-hint { font-size: 0.72rem; color: #64748b; margin-top: 0.3rem; } + .modal-actions { display: flex; gap: 0.75rem; margin-top: 1.5rem; justify-content: flex-end; } + .btn-save { + background: #6366f1; color: white; border: none; + padding: 0.5rem 1.25rem; border-radius: 8px; + font-size: 0.85rem; font-weight: 600; cursor: pointer; + transition: background 0.15s; + } + .btn-save:hover { background: #4f46e5; } + .btn-cancel { + background: transparent; color: #94a3b8; border: 1px solid #334155; + padding: 0.5rem 1.25rem; border-radius: 8px; + font-size: 0.85rem; cursor: pointer; transition: background 0.15s; + } + .btn-cancel:hover { background: #243044; color: #e2e8f0; } + .toast { + position: fixed; bottom: 1.5rem; right: 1.5rem; + background: #14532d; color: #4ade80; border: 1px solid #166534; + padding: 0.65rem 1.25rem; border-radius: 10px; font-size: 0.85rem; + font-weight: 600; opacity: 0; transition: opacity 0.3s; z-index: 300; + pointer-events: none; + } + .toast.show { opacity: 1; }
@@ -259,6 +325,7 @@ app.get('/', async (req, res) => {