easy-devops 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +4 -2
- package/src/cli/index.js +13 -1
- package/src/dashboard/public/js/app.js +126 -0
- package/src/dashboard/routes/auth.js +10 -1
- package/src/dashboard/routes/settings.js +43 -0
- package/src/dashboard/server.js +153 -3
- package/src/dashboard/views/index.ejs +52 -0
- package/src/dashboard/views/partials/domains-panel.ejs +4 -0
- package/src/dashboard/views/partials/logs-panel.ejs +67 -0
- package/src/dashboard/views/partials/settings-panel.ejs +32 -0
- package/src/dashboard/views/partials/sidebar.ejs +2 -0
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="src/dashboard/public/img/
|
|
2
|
+
<img src="src/dashboard/public/img/icon_b.png" alt="Easy DevOps" width="100" />
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
# Easy DevOps
|
|
@@ -110,7 +110,7 @@ npx easy-devops
|
|
|
110
110
|
### CLI Overview
|
|
111
111
|
|
|
112
112
|
```
|
|
113
|
-
███████╗███████╗ Easy DevOps v1.0
|
|
113
|
+
███████╗███████╗ Easy DevOps v1.1.0
|
|
114
114
|
██╔════╝╚════██╗ ─────────────────────
|
|
115
115
|
█████╗ ██╔╝ CLI & Web Dashboard
|
|
116
116
|
██╔══╝ ██╔╝ Nginx · SSL · Domains · Node.js
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easy-devops",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A unified DevOps management tool with CLI and web dashboard for managing Nginx, SSL certificates, and Node.js on Linux and Windows servers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"devops",
|
|
@@ -57,10 +57,12 @@
|
|
|
57
57
|
"cli-table3": "^0.6.5",
|
|
58
58
|
"ejs": "^5.0.1",
|
|
59
59
|
"express": "^5.2.1",
|
|
60
|
+
"express-rate-limit": "^8.3.2",
|
|
60
61
|
"express-session": "^1.17.3",
|
|
61
62
|
"good.db": "^2.4.6",
|
|
62
63
|
"inquirer": "^9.2.12",
|
|
63
64
|
"ora": "^7.0.1",
|
|
65
|
+
"session-file-store": "^1.5.0",
|
|
64
66
|
"socket.io": "^4.8.3"
|
|
65
67
|
}
|
|
66
|
-
}
|
|
68
|
+
}
|
package/src/cli/index.js
CHANGED
|
@@ -24,6 +24,18 @@ if (process.argv[2] === 'system-info') {
|
|
|
24
24
|
process.exit(0);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
// ─── Detection cache — only re-run if stale (>60s) ───────────────────────────
|
|
28
|
+
const DETECTION_TTL_MS = 60_000;
|
|
29
|
+
let lastDetectionAt = 0;
|
|
30
|
+
|
|
31
|
+
async function runDetectionIfStale() {
|
|
32
|
+
const now = Date.now();
|
|
33
|
+
if (now - lastDetectionAt >= DETECTION_TTL_MS) {
|
|
34
|
+
await runDetection();
|
|
35
|
+
lastDetectionAt = now;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
27
39
|
function renderBanner() {
|
|
28
40
|
const c = chalk.hex('#d64a29');
|
|
29
41
|
const dim = chalk.hex('#d64a29').dim;
|
|
@@ -90,7 +102,7 @@ async function dispatch(choice) {
|
|
|
90
102
|
async function main() {
|
|
91
103
|
while (true) {
|
|
92
104
|
const spinner = ora('Checking system…').start();
|
|
93
|
-
await
|
|
105
|
+
await runDetectionIfStale();
|
|
94
106
|
spinner.stop();
|
|
95
107
|
|
|
96
108
|
try {
|
|
@@ -55,6 +55,7 @@ createApp({
|
|
|
55
55
|
{ id: 'nginx', label: 'Nginx', icon: '🌐' },
|
|
56
56
|
{ id: 'ssl', label: 'SSL Certs', icon: '🔒' },
|
|
57
57
|
{ id: 'domains', label: 'Domains', icon: '🔗' },
|
|
58
|
+
{ id: 'logs', label: 'Logs', icon: '📋' },
|
|
58
59
|
{ id: 'settings', label: 'Settings', icon: '⚙️' },
|
|
59
60
|
],
|
|
60
61
|
|
|
@@ -78,6 +79,8 @@ createApp({
|
|
|
78
79
|
},
|
|
79
80
|
|
|
80
81
|
// T017-T019: Updated domains state
|
|
82
|
+
domainHealth: {}, // { [name]: true|false|null }
|
|
83
|
+
|
|
81
84
|
domains: {
|
|
82
85
|
list: [], loading: false, error: '',
|
|
83
86
|
showForm: false,
|
|
@@ -103,6 +106,13 @@ createApp({
|
|
|
103
106
|
advanced: false,
|
|
104
107
|
},
|
|
105
108
|
|
|
109
|
+
logs: {
|
|
110
|
+
lines: [],
|
|
111
|
+
activeLog: 'error', // 'error' | 'access'
|
|
112
|
+
paused: false,
|
|
113
|
+
socket: null,
|
|
114
|
+
},
|
|
115
|
+
|
|
106
116
|
settings: {
|
|
107
117
|
dashboardPort: '', nginxDir: '', sslDir: '', acmeEmail: '',
|
|
108
118
|
password: '', loading: false, msg: '', error: '',
|
|
@@ -112,6 +122,16 @@ createApp({
|
|
|
112
122
|
permissions: {
|
|
113
123
|
configured: false, loading: false, password: '', msg: '', error: '',
|
|
114
124
|
},
|
|
125
|
+
|
|
126
|
+
backup: {
|
|
127
|
+
restoring: false, msg: '', error: '',
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
notifications: {
|
|
131
|
+
items: [], // { id, type, severity, message, domain?, timestamp }
|
|
132
|
+
panelOpen: false,
|
|
133
|
+
unread: 0,
|
|
134
|
+
},
|
|
115
135
|
};
|
|
116
136
|
},
|
|
117
137
|
|
|
@@ -148,6 +168,15 @@ createApp({
|
|
|
148
168
|
localStorage.setItem('ed-sidebar', val);
|
|
149
169
|
},
|
|
150
170
|
|
|
171
|
+
'logs.lines'() {
|
|
172
|
+
if (!this.logs.paused) {
|
|
173
|
+
this.$nextTick(() => {
|
|
174
|
+
const el = document.getElementById('log-output');
|
|
175
|
+
if (el) el.scrollTop = el.scrollHeight;
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
|
|
151
180
|
// T019: Deep watch form for dirty tracking
|
|
152
181
|
'domains.form': {
|
|
153
182
|
handler() {
|
|
@@ -202,6 +231,21 @@ createApp({
|
|
|
202
231
|
socket.on('nginx:status', (status) => {
|
|
203
232
|
this.nginx.status = status;
|
|
204
233
|
});
|
|
234
|
+
socket.on('notification:new', (n) => {
|
|
235
|
+
this.addNotification(n);
|
|
236
|
+
});
|
|
237
|
+
socket.on('domain:health', (results) => {
|
|
238
|
+
const map = {};
|
|
239
|
+
for (const r of results) map[r.name] = r.up;
|
|
240
|
+
this.domainHealth = map;
|
|
241
|
+
});
|
|
242
|
+
socket.on('logs:line', ({ line, logFile }) => {
|
|
243
|
+
if (!this.logs.paused && logFile === this.logs.activeLog) {
|
|
244
|
+
this.logs.lines.push(line);
|
|
245
|
+
if (this.logs.lines.length > 500) this.logs.lines.shift();
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
this.logs.socket = socket;
|
|
205
249
|
},
|
|
206
250
|
|
|
207
251
|
methods: {
|
|
@@ -251,6 +295,7 @@ createApp({
|
|
|
251
295
|
},
|
|
252
296
|
|
|
253
297
|
async loadPage(p) {
|
|
298
|
+
if (this.page === 'logs' && p !== 'logs') this.unsubscribeLogs();
|
|
254
299
|
this.page = p;
|
|
255
300
|
if (p === 'overview') {
|
|
256
301
|
await Promise.all([this.loadNginxStatus(), this.loadSSL(), this.loadDomains()]);
|
|
@@ -258,6 +303,7 @@ createApp({
|
|
|
258
303
|
await Promise.all([this.loadNginxStatus(), this.loadNginxConfigs(), this.loadNginxLogs()]);
|
|
259
304
|
} else if (p === 'ssl') { await this.loadSSL(); }
|
|
260
305
|
else if (p === 'domains') { await this.loadDomains(); }
|
|
306
|
+
else if (p === 'logs') { this.subscribeToLogs(this.logs.activeLog); }
|
|
261
307
|
else if (p === 'settings') { await Promise.all([this.loadSettings(), this.loadPermissionsStatus()]); }
|
|
262
308
|
},
|
|
263
309
|
|
|
@@ -730,6 +776,86 @@ createApp({
|
|
|
730
776
|
}
|
|
731
777
|
},
|
|
732
778
|
|
|
779
|
+
// ── Logs ──────────────────────────────────────────────────────────────────
|
|
780
|
+
subscribeToLogs(logFile) {
|
|
781
|
+
if (!this.logs.socket) return;
|
|
782
|
+
this.logs.lines = [];
|
|
783
|
+
this.logs.activeLog = logFile;
|
|
784
|
+
this.logs.paused = false;
|
|
785
|
+
this.logs.socket.emit('logs:subscribe', { logFile });
|
|
786
|
+
},
|
|
787
|
+
switchLog(logFile) {
|
|
788
|
+
this.subscribeToLogs(logFile);
|
|
789
|
+
},
|
|
790
|
+
unsubscribeLogs() {
|
|
791
|
+
if (this.logs.socket) this.logs.socket.emit('logs:unsubscribe');
|
|
792
|
+
},
|
|
793
|
+
|
|
794
|
+
// ── Notifications ─────────────────────────────────────────────────────────
|
|
795
|
+
addNotification(n) {
|
|
796
|
+
// Deduplicate by id — replace if same id already exists
|
|
797
|
+
const idx = this.notifications.items.findIndex(i => i.id === n.id);
|
|
798
|
+
if (idx !== -1) {
|
|
799
|
+
this.notifications.items.splice(idx, 1, n);
|
|
800
|
+
} else {
|
|
801
|
+
this.notifications.items.unshift(n);
|
|
802
|
+
if (!this.notifications.panelOpen) this.notifications.unread++;
|
|
803
|
+
}
|
|
804
|
+
},
|
|
805
|
+
toggleNotificationsPanel() {
|
|
806
|
+
this.notifications.panelOpen = !this.notifications.panelOpen;
|
|
807
|
+
if (this.notifications.panelOpen) this.notifications.unread = 0;
|
|
808
|
+
},
|
|
809
|
+
clearNotifications() {
|
|
810
|
+
this.notifications.items = [];
|
|
811
|
+
this.notifications.unread = 0;
|
|
812
|
+
},
|
|
813
|
+
notifIcon(type) {
|
|
814
|
+
if (type === 'nginx_down') return '🔴';
|
|
815
|
+
if (type === 'cert_expiry') return '🔒';
|
|
816
|
+
if (type === 'domain_down') return '⚠️';
|
|
817
|
+
return '🔔';
|
|
818
|
+
},
|
|
819
|
+
|
|
820
|
+
// ── Backup & Restore ──────────────────────────────────────────────────────
|
|
821
|
+
exportBackup() {
|
|
822
|
+
window.location.href = '/api/settings/backup';
|
|
823
|
+
},
|
|
824
|
+
async importBackup(event) {
|
|
825
|
+
const file = event.target.files[0];
|
|
826
|
+
if (!file) return;
|
|
827
|
+
this.backup.msg = ''; this.backup.error = '';
|
|
828
|
+
let data;
|
|
829
|
+
try {
|
|
830
|
+
data = JSON.parse(await file.text());
|
|
831
|
+
} catch {
|
|
832
|
+
this.backup.error = 'Invalid file — could not parse JSON.';
|
|
833
|
+
event.target.value = '';
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
const { isConfirmed } = await Swal.fire({
|
|
837
|
+
title: 'Restore backup?',
|
|
838
|
+
text: 'This will overwrite your current configuration and domains list.',
|
|
839
|
+
icon: 'warning',
|
|
840
|
+
showCancelButton: true,
|
|
841
|
+
confirmButtonText: 'Restore',
|
|
842
|
+
cancelButtonText: 'Cancel',
|
|
843
|
+
...this.swalTheme,
|
|
844
|
+
});
|
|
845
|
+
event.target.value = '';
|
|
846
|
+
if (!isConfirmed) return;
|
|
847
|
+
this.backup.restoring = true;
|
|
848
|
+
const r = await this.api('POST', '/api/settings/restore', data);
|
|
849
|
+
this.backup.restoring = false;
|
|
850
|
+
if (r.ok) {
|
|
851
|
+
this.backup.msg = 'Restored successfully. Reload the page to see changes.';
|
|
852
|
+
await this.loadSettings();
|
|
853
|
+
await this.loadDomains();
|
|
854
|
+
} else {
|
|
855
|
+
this.backup.error = r.data?.error || 'Restore failed';
|
|
856
|
+
}
|
|
857
|
+
},
|
|
858
|
+
|
|
733
859
|
async saveSettings() {
|
|
734
860
|
this.settings.loading = true; this.settings.msg = ''; this.settings.error = '';
|
|
735
861
|
const payload = {
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
+
import rateLimit from 'express-rate-limit';
|
|
2
3
|
import { loadConfig } from '../../core/config.js';
|
|
3
4
|
|
|
4
5
|
const router = Router();
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
const loginLimiter = rateLimit({
|
|
8
|
+
windowMs: 15 * 60 * 1000, // 15 minutes
|
|
9
|
+
max: 10,
|
|
10
|
+
standardHeaders: true,
|
|
11
|
+
legacyHeaders: false,
|
|
12
|
+
message: { ok: false, error: 'Too many login attempts. Try again in 15 minutes.' },
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
router.post('/login', loginLimiter, (req, res) => {
|
|
7
16
|
const { password } = req.body;
|
|
8
17
|
const { dashboardPassword } = loadConfig();
|
|
9
18
|
if (password === dashboardPassword) {
|
|
@@ -7,6 +7,7 @@ import { loadConfig, saveConfig } from '../../core/config.js';
|
|
|
7
7
|
import { validatePort, validateEmail } from '../../core/validators.js';
|
|
8
8
|
import { run } from '../../core/shell.js';
|
|
9
9
|
import { checkPermissionsConfigured } from '../../core/permissions.js';
|
|
10
|
+
import { dbGet, dbSet } from '../../core/db.js';
|
|
10
11
|
|
|
11
12
|
// Run a bash command with sudo -S (password read from stdin — no terminal needed)
|
|
12
13
|
function runSudoS(bashCmd, password) {
|
|
@@ -191,4 +192,46 @@ router.post('/settings/permissions/setup', async (req, res) => {
|
|
|
191
192
|
res.json({ success: true });
|
|
192
193
|
});
|
|
193
194
|
|
|
195
|
+
// ─── GET /api/settings/backup ──────────────────────────────────────────────────
|
|
196
|
+
|
|
197
|
+
router.get('/settings/backup', (req, res) => {
|
|
198
|
+
try {
|
|
199
|
+
const config = loadConfig();
|
|
200
|
+
const domains = dbGet('domains') || [];
|
|
201
|
+
const { dashboardPassword: _pw, ...safeConfig } = config; // exclude password from export
|
|
202
|
+
const backup = {
|
|
203
|
+
version: 1,
|
|
204
|
+
exportedAt: new Date().toISOString(),
|
|
205
|
+
config: safeConfig,
|
|
206
|
+
domains,
|
|
207
|
+
};
|
|
208
|
+
res.setHeader('Content-Disposition', `attachment; filename="easy-devops-backup-${Date.now()}.json"`);
|
|
209
|
+
res.setHeader('Content-Type', 'application/json');
|
|
210
|
+
res.json(backup);
|
|
211
|
+
} catch (err) {
|
|
212
|
+
res.status(500).json({ error: 'Export failed' });
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// ─── POST /api/settings/restore ────────────────────────────────────────────────
|
|
217
|
+
|
|
218
|
+
router.post('/settings/restore', (req, res) => {
|
|
219
|
+
try {
|
|
220
|
+
const { config, domains } = req.body ?? {};
|
|
221
|
+
if (!config || typeof config !== 'object') {
|
|
222
|
+
return res.status(400).json({ error: 'Invalid backup: missing config' });
|
|
223
|
+
}
|
|
224
|
+
// Merge imported config with current (preserve password, merge rest)
|
|
225
|
+
const current = loadConfig();
|
|
226
|
+
const merged = { ...current, ...config, dashboardPassword: current.dashboardPassword };
|
|
227
|
+
saveConfig(merged);
|
|
228
|
+
if (Array.isArray(domains)) {
|
|
229
|
+
dbSet('domains', domains);
|
|
230
|
+
}
|
|
231
|
+
res.json({ success: true });
|
|
232
|
+
} catch (err) {
|
|
233
|
+
res.status(500).json({ error: 'Restore failed' });
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
|
|
194
237
|
export default router;
|
package/src/dashboard/server.js
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import { createServer } from 'http';
|
|
2
|
+
import http from 'http';
|
|
3
|
+
import { createRequire } from 'module';
|
|
4
|
+
import { spawn } from 'child_process';
|
|
2
5
|
import express from 'express';
|
|
3
6
|
import { fileURLToPath } from 'url';
|
|
4
7
|
import path from 'path';
|
|
8
|
+
import os from 'os';
|
|
9
|
+
import crypto from 'crypto';
|
|
5
10
|
import session from 'express-session';
|
|
6
11
|
import { Server as SocketIO } from 'socket.io';
|
|
7
12
|
import { loadConfig } from '../core/config.js';
|
|
13
|
+
import { dbGet, dbSet } from '../core/db.js';
|
|
8
14
|
import authRouter from './routes/auth.js';
|
|
9
15
|
import domainsRouter from './routes/domains.js';
|
|
10
16
|
import sslRouter from './routes/ssl.js';
|
|
11
17
|
import nginxRouter from './routes/nginx.js';
|
|
12
18
|
import settingsRouter from './routes/settings.js';
|
|
13
19
|
import { getStatus } from './lib/nginx-service.js';
|
|
20
|
+
import { listAllCerts } from './lib/cert-reader.js';
|
|
21
|
+
|
|
22
|
+
const require = createRequire(import.meta.url);
|
|
23
|
+
const FileStore = require('session-file-store')(session);
|
|
14
24
|
|
|
15
25
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
16
26
|
|
|
@@ -20,12 +30,25 @@ const app = express();
|
|
|
20
30
|
app.set('view engine', 'ejs');
|
|
21
31
|
app.set('views', path.join(__dirname, 'views'));
|
|
22
32
|
|
|
23
|
-
app.use(express.json());
|
|
33
|
+
app.use(express.json({ limit: '1mb' }));
|
|
34
|
+
|
|
35
|
+
// ─── Session secret — generated once, persisted in SQLite ────────────────────
|
|
36
|
+
let sessionSecret = dbGet('session_secret');
|
|
37
|
+
if (!sessionSecret) {
|
|
38
|
+
sessionSecret = crypto.randomBytes(32).toString('hex');
|
|
39
|
+
dbSet('session_secret', sessionSecret);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Sessions stored on disk so they survive restarts
|
|
43
|
+
const SESSION_DIR = process.platform === 'win32'
|
|
44
|
+
? path.join(process.env.APPDATA || os.homedir(), 'easy-devops', 'sessions')
|
|
45
|
+
: path.join(os.homedir(), '.config', 'easy-devops', 'sessions');
|
|
24
46
|
|
|
25
47
|
app.use(session({
|
|
26
|
-
secret:
|
|
48
|
+
secret: sessionSecret,
|
|
27
49
|
resave: false,
|
|
28
50
|
saveUninitialized: false,
|
|
51
|
+
store: new FileStore({ path: SESSION_DIR, retries: 1, logFn() {} }),
|
|
29
52
|
cookie: { httpOnly: true },
|
|
30
53
|
}));
|
|
31
54
|
|
|
@@ -52,22 +75,149 @@ async function emitNginxStatus(target) {
|
|
|
52
75
|
try {
|
|
53
76
|
const status = await getStatus();
|
|
54
77
|
target.emit('nginx:status', status);
|
|
78
|
+
// Emit notification if nginx is down
|
|
79
|
+
if (!status.running) {
|
|
80
|
+
target.emit('notification:new', {
|
|
81
|
+
id: 'nginx-down',
|
|
82
|
+
type: 'nginx_down',
|
|
83
|
+
severity: 'danger',
|
|
84
|
+
message: 'Nginx is not running',
|
|
85
|
+
timestamp: Date.now(),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
55
88
|
} catch (err) {
|
|
56
89
|
target.emit('nginx:status', { running: false, version: null, pid: null, error: err.message });
|
|
57
90
|
}
|
|
58
91
|
}
|
|
59
92
|
|
|
93
|
+
// ─── Cert expiry notifications ────────────────────────────────────────────────
|
|
94
|
+
async function emitCertNotifications(target) {
|
|
95
|
+
try {
|
|
96
|
+
const certs = await listAllCerts();
|
|
97
|
+
for (const cert of certs) {
|
|
98
|
+
if (cert.daysLeft !== null && cert.daysLeft < 30) {
|
|
99
|
+
const severity = cert.daysLeft < 10 ? 'danger' : 'warning';
|
|
100
|
+
target.emit('notification:new', {
|
|
101
|
+
id: `cert-expiry-${cert.domain}`,
|
|
102
|
+
type: 'cert_expiry',
|
|
103
|
+
severity,
|
|
104
|
+
message: `SSL cert for ${cert.domain} expires in ${cert.daysLeft} day${cert.daysLeft === 1 ? '' : 's'}`,
|
|
105
|
+
domain: cert.domain,
|
|
106
|
+
timestamp: Date.now(),
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
} catch { /* non-fatal */ }
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// ─── Domain health checks ─────────────────────────────────────────────────────
|
|
114
|
+
function checkDomainHealth(host, port) {
|
|
115
|
+
return new Promise((resolve) => {
|
|
116
|
+
const req = http.request({ host, port: Number(port), path: '/', method: 'HEAD', timeout: 5000 }, (res) => {
|
|
117
|
+
resolve({ up: true, status: res.statusCode });
|
|
118
|
+
res.resume();
|
|
119
|
+
});
|
|
120
|
+
req.on('timeout', () => { req.destroy(); resolve({ up: false }); });
|
|
121
|
+
req.on('error', () => resolve({ up: false }));
|
|
122
|
+
req.end();
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function emitDomainHealth(target) {
|
|
127
|
+
try {
|
|
128
|
+
const domains = dbGet('domains') || [];
|
|
129
|
+
const results = await Promise.all(
|
|
130
|
+
domains.map(async (d) => {
|
|
131
|
+
const host = d.backendHost || '127.0.0.1';
|
|
132
|
+
const port = d.port || 80;
|
|
133
|
+
// Skip external URL backends
|
|
134
|
+
if (typeof host === 'string' && host.startsWith('http')) return { name: d.name, up: null };
|
|
135
|
+
const { up } = await checkDomainHealth(host, port);
|
|
136
|
+
return { name: d.name, up };
|
|
137
|
+
})
|
|
138
|
+
);
|
|
139
|
+
target.emit('domain:health', results);
|
|
140
|
+
} catch { /* non-fatal */ }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// ─── Live log streaming ───────────────────────────────────────────────────────
|
|
144
|
+
const activeTails = new Map(); // socketId → { process, logFile }
|
|
145
|
+
|
|
146
|
+
function getLogPath(logFile) {
|
|
147
|
+
const { nginxDir } = loadConfig();
|
|
148
|
+
const file = logFile === 'access' ? 'access.log' : 'error.log';
|
|
149
|
+
// Linux standard path first, fall back to nginxDir/logs/
|
|
150
|
+
if (process.platform !== 'win32') {
|
|
151
|
+
return `/var/log/nginx/${file}`;
|
|
152
|
+
}
|
|
153
|
+
return path.join(nginxDir, 'logs', file);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function startTail(socket, logFile) {
|
|
157
|
+
// Kill any existing tail for this socket
|
|
158
|
+
stopTail(socket.id);
|
|
159
|
+
|
|
160
|
+
const logPath = getLogPath(logFile);
|
|
161
|
+
const args = process.platform === 'win32'
|
|
162
|
+
? ['Get-Content', '-Path', logPath, '-Wait', '-Tail', '50']
|
|
163
|
+
: ['-n', '50', '-f', logPath];
|
|
164
|
+
const cmd = process.platform === 'win32' ? 'powershell' : 'tail';
|
|
165
|
+
|
|
166
|
+
const child = spawn(cmd, args, { stdio: ['ignore', 'pipe', 'ignore'] });
|
|
167
|
+
let buf = '';
|
|
168
|
+
child.stdout.on('data', (chunk) => {
|
|
169
|
+
buf += chunk.toString();
|
|
170
|
+
const lines = buf.split('\n');
|
|
171
|
+
buf = lines.pop(); // keep incomplete line in buffer
|
|
172
|
+
for (const line of lines) {
|
|
173
|
+
if (line.trim()) socket.emit('logs:line', { line: line.trim(), logFile });
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
child.on('error', () => {});
|
|
177
|
+
child.on('close', () => { activeTails.delete(socket.id); });
|
|
178
|
+
activeTails.set(socket.id, { process: child, logFile });
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function stopTail(socketId) {
|
|
182
|
+
const entry = activeTails.get(socketId);
|
|
183
|
+
if (entry) {
|
|
184
|
+
try { entry.process.kill(); } catch {}
|
|
185
|
+
activeTails.delete(socketId);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
60
189
|
io.on('connection', (socket) => {
|
|
61
190
|
connectedClients++;
|
|
62
191
|
emitNginxStatus(socket);
|
|
63
|
-
socket
|
|
192
|
+
emitCertNotifications(socket);
|
|
193
|
+
|
|
194
|
+
socket.on('logs:subscribe', ({ logFile }) => startTail(socket, logFile || 'error'));
|
|
195
|
+
socket.on('logs:unsubscribe', () => stopTail(socket.id));
|
|
196
|
+
|
|
197
|
+
// Send initial domain health on connect
|
|
198
|
+
emitDomainHealth(socket);
|
|
199
|
+
|
|
200
|
+
socket.on('disconnect', () => {
|
|
201
|
+
connectedClients--;
|
|
202
|
+
stopTail(socket.id);
|
|
203
|
+
});
|
|
64
204
|
});
|
|
65
205
|
|
|
206
|
+
// Poll domain health every 60 seconds
|
|
207
|
+
setInterval(() => {
|
|
208
|
+
if (connectedClients > 0) emitDomainHealth(io);
|
|
209
|
+
}, 60_000);
|
|
210
|
+
|
|
66
211
|
// Broadcast nginx status to all clients every 5 seconds
|
|
67
212
|
setInterval(() => {
|
|
68
213
|
if (connectedClients > 0) emitNginxStatus(io);
|
|
69
214
|
}, 5000);
|
|
70
215
|
|
|
216
|
+
// Check cert expiry every 12 hours
|
|
217
|
+
setInterval(() => {
|
|
218
|
+
if (connectedClients > 0) emitCertNotifications(io);
|
|
219
|
+
}, 12 * 60 * 60 * 1000);
|
|
220
|
+
|
|
71
221
|
// ─── Start ────────────────────────────────────────────────────────────────────
|
|
72
222
|
|
|
73
223
|
const { dashboardPort } = loadConfig();
|
|
@@ -473,6 +473,11 @@ animation: shimmer 1.5s ease infinite;
|
|
|
473
473
|
.fade-enter-active, .fade-leave-active { transition: opacity 150ms ease; }
|
|
474
474
|
.fade-enter-from, .fade-leave-to { opacity: 0; }
|
|
475
475
|
|
|
476
|
+
.notif-panel-enter-active { transition: opacity 150ms ease, transform 150ms ease; }
|
|
477
|
+
.notif-panel-leave-active { transition: opacity 100ms ease, transform 100ms ease; }
|
|
478
|
+
.notif-panel-enter-from { opacity: 0; transform: translateY(-8px) scale(0.97); }
|
|
479
|
+
.notif-panel-leave-to { opacity: 0; transform: translateY(-4px) scale(0.98); }
|
|
480
|
+
|
|
476
481
|
/* Login Page Styles */
|
|
477
482
|
.login-card {
|
|
478
483
|
background: var(--color-surface);
|
|
@@ -618,6 +623,52 @@ class="theme-accent-circle"
|
|
|
618
623
|
</button>
|
|
619
624
|
</div>
|
|
620
625
|
|
|
626
|
+
<!-- Bell / Notifications -->
|
|
627
|
+
<div class="relative">
|
|
628
|
+
<button @click="toggleNotificationsPanel"
|
|
629
|
+
class="relative p-1.5 text-muted hover:text-foreground transition-colors rounded-lg"
|
|
630
|
+
:class="notifications.panelOpen ? 'text-foreground' : ''">
|
|
631
|
+
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
632
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"></path>
|
|
633
|
+
</svg>
|
|
634
|
+
<span v-if="notifications.unread > 0"
|
|
635
|
+
class="absolute -top-0.5 -right-0.5 min-w-[16px] h-4 px-1 rounded-full text-[10px] font-bold flex items-center justify-center text-white"
|
|
636
|
+
style="background: var(--color-primary)">
|
|
637
|
+
{{ notifications.unread > 9 ? '9+' : notifications.unread }}
|
|
638
|
+
</span>
|
|
639
|
+
</button>
|
|
640
|
+
|
|
641
|
+
<!-- Sliding panel -->
|
|
642
|
+
<transition name="notif-panel">
|
|
643
|
+
<div v-if="notifications.panelOpen"
|
|
644
|
+
v-click-outside="() => { notifications.panelOpen = false; }"
|
|
645
|
+
class="absolute right-0 top-10 w-80 rounded-2xl border border-border shadow-2xl z-50 overflow-hidden"
|
|
646
|
+
style="background: var(--color-surface)">
|
|
647
|
+
<div class="flex items-center justify-between px-4 py-3 border-b border-border">
|
|
648
|
+
<span class="text-sm font-bold">Notifications</span>
|
|
649
|
+
<button v-if="notifications.items.length" @click="clearNotifications"
|
|
650
|
+
class="text-xs text-muted hover:text-foreground transition-colors">Clear all</button>
|
|
651
|
+
</div>
|
|
652
|
+
<div class="max-h-72 overflow-y-auto">
|
|
653
|
+
<div v-if="!notifications.items.length" class="px-4 py-6 text-center text-sm text-muted">
|
|
654
|
+
All clear — no notifications
|
|
655
|
+
</div>
|
|
656
|
+
<div v-for="n in notifications.items" :key="n.id"
|
|
657
|
+
class="flex items-start gap-3 px-4 py-3 border-b border-border last:border-0 hover:bg-primary/[0.03] transition-colors">
|
|
658
|
+
<span class="text-base leading-none mt-0.5">{{ notifIcon(n.type) }}</span>
|
|
659
|
+
<div class="flex-1 min-w-0">
|
|
660
|
+
<p class="text-xs font-medium leading-snug"
|
|
661
|
+
:class="n.severity === 'danger' ? 'text-red-400' : 'text-yellow-400'">
|
|
662
|
+
{{ n.message }}
|
|
663
|
+
</p>
|
|
664
|
+
<p class="text-[10px] text-muted mt-0.5">{{ new Date(n.timestamp).toLocaleTimeString() }}</p>
|
|
665
|
+
</div>
|
|
666
|
+
</div>
|
|
667
|
+
</div>
|
|
668
|
+
</div>
|
|
669
|
+
</transition>
|
|
670
|
+
</div>
|
|
671
|
+
|
|
621
672
|
<div class="w-px h-6 border-l border-border mx-1"></div>
|
|
622
673
|
|
|
623
674
|
<!-- Theme Toggle -->
|
|
@@ -638,6 +689,7 @@ class="theme-accent-circle"
|
|
|
638
689
|
<%- include('partials/ssl-panel.ejs') %>
|
|
639
690
|
<%- include('partials/domains-panel.ejs') %>
|
|
640
691
|
<%- include('partials/settings-panel.ejs') %>
|
|
692
|
+
<%- include('partials/logs-panel.ejs') %>
|
|
641
693
|
</div>
|
|
642
694
|
</transition>
|
|
643
695
|
</div>
|
|
@@ -73,6 +73,10 @@
|
|
|
73
73
|
SSL: {{ d.daysLeft != null ? d.daysLeft + 'd' : 'Wait' }}
|
|
74
74
|
</span>
|
|
75
75
|
<span v-else class="badge badge-neutral">HTTP Only</span>
|
|
76
|
+
|
|
77
|
+
<!-- Backend Health Badge -->
|
|
78
|
+
<span v-if="domainHealth[d.name] === true" class="badge badge-success" title="Backend reachable">● Up</span>
|
|
79
|
+
<span v-else-if="domainHealth[d.name] === false" class="badge badge-danger" title="Backend unreachable">● Down</span>
|
|
76
80
|
</div>
|
|
77
81
|
|
|
78
82
|
<!-- Actions (appear on hover via .domain-actions in CSS) -->
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<!-- Logs Panel -->
|
|
2
|
+
<div v-if="page === 'logs'">
|
|
3
|
+
<div class="flex items-center justify-between mb-6">
|
|
4
|
+
<div>
|
|
5
|
+
<h2 class="text-xl font-bold text-foreground">Nginx Logs</h2>
|
|
6
|
+
<p class="text-sm text-muted mt-1">Live streaming — last 500 lines</p>
|
|
7
|
+
</div>
|
|
8
|
+
<div class="flex items-center gap-2">
|
|
9
|
+
<!-- Log file toggle -->
|
|
10
|
+
<div class="flex items-center gap-1 p-1 rounded-lg border border-border" style="background: var(--color-surface)">
|
|
11
|
+
<button @click="switchLog('error')"
|
|
12
|
+
class="px-3 py-1.5 text-xs font-semibold rounded-md transition-all"
|
|
13
|
+
:class="logs.activeLog === 'error' ? 'bg-primary text-white' : 'text-muted hover:text-foreground'">
|
|
14
|
+
Error
|
|
15
|
+
</button>
|
|
16
|
+
<button @click="switchLog('access')"
|
|
17
|
+
class="px-3 py-1.5 text-xs font-semibold rounded-md transition-all"
|
|
18
|
+
:class="logs.activeLog === 'access' ? 'bg-primary text-white' : 'text-muted hover:text-foreground'">
|
|
19
|
+
Access
|
|
20
|
+
</button>
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
<!-- Pause / Resume -->
|
|
24
|
+
<button @click="logs.paused = !logs.paused"
|
|
25
|
+
class="btn btn-secondary btn-sm flex items-center gap-1.5">
|
|
26
|
+
<svg v-if="!logs.paused" class="w-3.5 h-3.5" fill="currentColor" viewBox="0 0 24 24">
|
|
27
|
+
<path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/>
|
|
28
|
+
</svg>
|
|
29
|
+
<svg v-else class="w-3.5 h-3.5" fill="currentColor" viewBox="0 0 24 24">
|
|
30
|
+
<path d="M8 5v14l11-7z"/>
|
|
31
|
+
</svg>
|
|
32
|
+
{{ logs.paused ? 'Resume' : 'Pause' }}
|
|
33
|
+
</button>
|
|
34
|
+
|
|
35
|
+
<!-- Clear -->
|
|
36
|
+
<button @click="logs.lines = []" class="btn btn-secondary btn-sm">Clear</button>
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
|
|
40
|
+
<!-- Live indicator -->
|
|
41
|
+
<div class="flex items-center gap-2 mb-3">
|
|
42
|
+
<div class="w-2 h-2 rounded-full" :class="logs.paused ? 'bg-yellow-500' : 'bg-green-500 animate-pulse'"></div>
|
|
43
|
+
<span class="text-xs text-muted font-mono">
|
|
44
|
+
{{ logs.paused ? 'Paused' : 'Live' }} · {{ logs.activeLog }}.log · {{ logs.lines.length }} lines
|
|
45
|
+
</span>
|
|
46
|
+
</div>
|
|
47
|
+
|
|
48
|
+
<!-- Log output -->
|
|
49
|
+
<div class="rounded-xl border border-border overflow-hidden" style="background: #0d0d0d">
|
|
50
|
+
<div
|
|
51
|
+
id="log-output"
|
|
52
|
+
class="h-[calc(100vh-280px)] overflow-y-auto p-4 font-mono text-xs leading-relaxed"
|
|
53
|
+
style="color: #c8d3f5"
|
|
54
|
+
ref="logOutput">
|
|
55
|
+
<div v-if="!logs.lines.length" class="text-muted italic">
|
|
56
|
+
Waiting for log output…
|
|
57
|
+
</div>
|
|
58
|
+
<div v-for="(line, i) in logs.lines" :key="i"
|
|
59
|
+
class="whitespace-pre-wrap break-all py-0.5"
|
|
60
|
+
:class="{
|
|
61
|
+
'text-red-400': line.includes('[error]') || line.includes('[crit]') || line.includes('[emerg]'),
|
|
62
|
+
'text-yellow-400': line.includes('[warn]'),
|
|
63
|
+
'text-green-400': line.includes('200') || line.includes('304'),
|
|
64
|
+
}">{{ line }}</div>
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
@@ -66,6 +66,38 @@
|
|
|
66
66
|
</div>
|
|
67
67
|
</div>
|
|
68
68
|
|
|
69
|
+
<!-- Backup & Restore card -->
|
|
70
|
+
<div class="stat-card overflow-hidden relative mt-6">
|
|
71
|
+
<div class="absolute top-0 left-0 w-full h-1 bg-primary/40"></div>
|
|
72
|
+
<div class="p-6 border-b border-border/50 bg-black/5 dark:bg-white/5">
|
|
73
|
+
<h3 class="form-label !mb-0 font-bold">Backup & Restore</h3>
|
|
74
|
+
<p class="text-[11px] text-muted mt-1 font-bold tracking-wide uppercase opacity-70">Export or restore configuration and domains</p>
|
|
75
|
+
</div>
|
|
76
|
+
<div class="p-8 bg-background flex flex-col sm:flex-row gap-6">
|
|
77
|
+
<div class="flex-1">
|
|
78
|
+
<p class="text-sm text-muted mb-4">Export all settings and domains as a JSON file. Passwords are excluded from the export.</p>
|
|
79
|
+
<button @click="exportBackup" class="btn btn-secondary">
|
|
80
|
+
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"></path></svg>
|
|
81
|
+
Export Backup
|
|
82
|
+
</button>
|
|
83
|
+
</div>
|
|
84
|
+
<div class="w-px bg-border hidden sm:block"></div>
|
|
85
|
+
<div class="flex-1">
|
|
86
|
+
<p class="text-sm text-muted mb-4">Restore configuration from a previously exported backup file.</p>
|
|
87
|
+
<label class="btn btn-secondary cursor-pointer" :class="backup.restoring ? 'opacity-50 pointer-events-none' : ''">
|
|
88
|
+
<svg v-if="backup.restoring" class="w-4 h-4 animate-spin" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"></path></svg>
|
|
89
|
+
<svg v-else class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l4-4m0 0l4 4m-4-4v12"></path></svg>
|
|
90
|
+
{{ backup.restoring ? 'Restoring...' : 'Import Backup' }}
|
|
91
|
+
<input type="file" accept=".json" class="hidden" @change="importBackup" :disabled="backup.restoring" />
|
|
92
|
+
</label>
|
|
93
|
+
</div>
|
|
94
|
+
</div>
|
|
95
|
+
<div v-if="backup.msg || backup.error" class="px-8 pb-6">
|
|
96
|
+
<span v-if="backup.msg" class="text-green-500 text-[13px] font-bold px-3 py-1.5 rounded-[10px] bg-green-500/10 border border-green-500/20">{{ backup.msg }}</span>
|
|
97
|
+
<span v-if="backup.error" class="text-red-500 text-[13px] font-bold px-3 py-1.5 rounded-[10px] bg-red-500/10 border border-red-500/20">{{ backup.error }}</span>
|
|
98
|
+
</div>
|
|
99
|
+
</div>
|
|
100
|
+
|
|
69
101
|
<!-- Linux Permissions card (hidden on Windows) -->
|
|
70
102
|
<div v-if="settings.platform !== 'win32'" class="stat-card overflow-hidden relative mt-6">
|
|
71
103
|
<div class="absolute top-0 left-0 w-full h-1" :class="permissions.configured ? 'bg-green-500/40' : 'bg-yellow-500/40'"></div>
|
|
@@ -39,6 +39,8 @@
|
|
|
39
39
|
<svg v-if="item.id === 'ssl'" class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"></path></svg>
|
|
40
40
|
<!-- Domains -->
|
|
41
41
|
<svg v-if="item.id === 'domains'" class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"></path></svg>
|
|
42
|
+
<!-- Logs -->
|
|
43
|
+
<svg v-if="item.id === 'logs'" class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path></svg>
|
|
42
44
|
<!-- Settings -->
|
|
43
45
|
<svg v-if="item.id === 'settings'" class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"></path><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path></svg>
|
|
44
46
|
</div>
|