easy-devops 1.2.1 → 1.3.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 +97 -6
- package/dist/ui/assets/index-B6zdwEnG.css +1 -0
- package/dist/ui/assets/index-Cy0oNmul.js +442 -0
- package/dist/ui/assets/socket-DwLPrgsr.js +1 -0
- package/dist/ui/assets/socket-K5ttLD2q.js +65 -0
- package/dist/ui/brand/apple-touch-icon.png +0 -0
- package/dist/ui/brand/favicon-16.png +0 -0
- package/dist/ui/brand/favicon-32.png +0 -0
- package/dist/ui/brand/favicon-light-16.png +0 -0
- package/dist/ui/brand/favicon-light-32.png +0 -0
- package/dist/ui/brand/favicon.ico +0 -0
- package/dist/ui/brand/icon-192.png +0 -0
- package/dist/ui/brand/icon-48.png +0 -0
- package/dist/ui/brand/icon-512.png +0 -0
- package/dist/ui/brand/icon-64-light.png +0 -0
- package/dist/ui/brand/icon-64.png +0 -0
- package/dist/ui/brand/logo-dark.png +0 -0
- package/dist/ui/brand/logo-light.png +0 -0
- package/dist/ui/brand/mark-dark.png +0 -0
- package/dist/ui/brand/mark-light.png +0 -0
- package/dist/ui/index.html +71 -0
- package/install.ps1 +188 -1
- package/install.sh +254 -29
- package/package.json +15 -4
- package/src/cli/dash.js +110 -0
- package/src/cli/index.js +237 -106
- package/src/cli/managers/domain-manager.js +60 -40
- package/src/cli/managers/ssl-manager.js +47 -330
- package/src/cli/menu.js +156 -0
- package/src/cli/menus/cleanup.js +205 -0
- package/src/cli/menus/dashboard.js +92 -1
- package/src/cli/menus/runtime.js +236 -0
- package/src/cli/menus/service.js +764 -0
- package/src/cli/menus/settings.js +176 -8
- package/src/cli/menus/uninstall.js +167 -0
- package/src/cli/menus/update.js +221 -65
- package/src/core/acme-challenge.js +273 -0
- package/src/core/cert-operations.js +189 -0
- package/src/{dashboard/lib → core}/cert-reader.js +2 -2
- package/src/core/cert-renewal.js +494 -0
- package/src/core/cleanup.js +600 -0
- package/src/core/config.js +169 -2
- package/src/core/daemon/ipc.js +292 -0
- package/src/core/daemon/lock.js +294 -0
- package/src/core/daemon/run.js +241 -0
- package/src/core/daemon/stopRequest.js +162 -0
- package/src/core/db.js +37 -8
- package/src/core/deploy/apps.js +491 -0
- package/src/core/deploy/domainLink.js +200 -0
- package/src/core/deploy/engine.js +973 -0
- package/src/core/deploy/ezfile.js +361 -0
- package/src/core/deploy/github.js +239 -0
- package/src/core/deploy/githubApi.js +261 -0
- package/src/core/deploy/hookServer.js +325 -0
- package/src/core/deploy/hubCommands.js +267 -0
- package/src/core/deploy/launcher.js +57 -0
- package/src/core/deploy/status.js +91 -0
- package/src/core/deploy/store.js +398 -0
- package/src/core/domainNotifier.js +94 -28
- package/src/core/domains-db.js +234 -0
- package/src/core/events.js +94 -2
- package/src/core/hub/agent.js +842 -0
- package/src/core/hubLink.js +306 -0
- package/src/core/hubPermissions.js +430 -0
- package/src/core/installSource.js +162 -0
- package/src/core/jobs/bus.js +120 -0
- package/src/core/jobs/index.js +371 -0
- package/src/core/jobs/monitors.js +368 -0
- package/src/core/jobs/owner.js +217 -0
- package/src/core/jobs/revisionWatcher.js +106 -0
- package/src/core/nginx-apply.js +213 -0
- package/src/core/nginx-conf-generator.js +253 -17
- package/src/{dashboard/lib → core}/nginx-service.js +18 -9
- package/src/core/notifications/claim.js +214 -0
- package/src/core/notifications/dispatch.js +154 -0
- package/src/core/notifier.js +31 -1
- package/src/core/passwords.js +172 -0
- package/src/core/permissions.js +8 -4
- package/src/core/platform.js +709 -2
- package/src/core/probeCache.js +258 -0
- package/src/core/purge.js +372 -0
- package/src/core/runner.js +488 -0
- package/src/core/service/acl.js +226 -0
- package/src/core/service/dataDir.js +345 -0
- package/src/core/service/index.js +1128 -0
- package/src/core/service/legacy.js +218 -0
- package/src/core/service/runtime.js +446 -0
- package/src/core/service/runtimeUpdate.js +800 -0
- package/src/core/service/systemd.js +458 -0
- package/src/core/service/windowsPersonal.js +530 -0
- package/src/core/service/windowsService.js +576 -0
- package/src/core/service/winsw.js +260 -0
- package/src/core/setupCode.js +331 -0
- package/src/core/shell.js +70 -7
- package/src/core/ssl-issuer.js +627 -0
- package/src/core/updater.js +295 -0
- package/src/core/validators.js +99 -0
- package/src/dashboard/controllers/authController.js +302 -15
- package/src/dashboard/controllers/deploymentsController.js +479 -0
- package/src/dashboard/controllers/domainsController.js +39 -52
- package/src/dashboard/controllers/hubController.js +135 -0
- package/src/dashboard/controllers/nginxController.js +21 -3
- package/src/dashboard/controllers/processesController.js +368 -0
- package/src/dashboard/controllers/settingsController.js +180 -12
- package/src/dashboard/controllers/sslController.js +171 -10
- package/src/dashboard/lib/daemonBridge.js +163 -0
- package/src/dashboard/lib/localRequest.js +235 -0
- package/src/dashboard/lib/loginRateLimit.js +119 -0
- package/src/dashboard/lib/requireAuth.js +80 -0
- package/src/dashboard/public/js/app.js +489 -19
- package/src/dashboard/routes/auth.js +10 -10
- package/src/dashboard/routes/deployments.js +46 -0
- package/src/dashboard/routes/domains.js +9 -0
- package/src/dashboard/routes/hub.js +22 -0
- package/src/dashboard/routes/nginx.js +9 -0
- package/src/dashboard/routes/processes.js +29 -0
- package/src/dashboard/routes/settings.js +9 -0
- package/src/dashboard/routes/ssl.js +9 -0
- package/src/dashboard/server.js +288 -21
- package/src/dashboard/socketManager.js +171 -207
- package/src/dashboard/views/index.ejs +1 -0
- package/src/dashboard/views/partials/login.ejs +68 -7
- package/src/dashboard/views/partials/processes-panel.ejs +261 -0
- package/src/dashboard/views/partials/settings-panel.ejs +287 -0
- package/src/dashboard/views/partials/sidebar.ejs +2 -0
- package/src/dashboard/lib/domains-db.js +0 -51
|
@@ -1,203 +1,151 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* dashboard/socketManager.js
|
|
3
|
+
*
|
|
4
|
+
* The browser-facing Socket.io layer. It no longer DOES any monitoring.
|
|
5
|
+
*
|
|
6
|
+
* It used to: nginx polling, domain health probes, certificate checks and the
|
|
7
|
+
* notification decisions all lived here, driven by intervals that only ran
|
|
8
|
+
* while a browser was connected. That is why none of it worked without an open
|
|
9
|
+
* dashboard, and why it could not move into a service.
|
|
10
|
+
*
|
|
11
|
+
* All of it now lives in core/jobs/, runs in whichever process owns the jobs,
|
|
12
|
+
* and arrives here as events on core/jobs/bus.js — published either by the
|
|
13
|
+
* monitors in this process, or by the daemon over IPC and republished onto the
|
|
14
|
+
* bus by dashboard/lib/daemonBridge.js. This module's whole job is to forward
|
|
15
|
+
* them to connected browsers unchanged, which is why the bus uses the names
|
|
16
|
+
* and payloads from docs/api-contract.md.
|
|
17
|
+
*
|
|
18
|
+
* What is still genuinely socket work and stays here: the session and
|
|
19
|
+
* local-request guards on the handshake, and the live log tails — a tail exists
|
|
20
|
+
* only for a client that is watching it, and dies with that client.
|
|
21
|
+
*/
|
|
22
|
+
|
|
2
23
|
import { spawn } from 'child_process';
|
|
3
|
-
import path from 'path';
|
|
4
24
|
import { Server as SocketIO } from 'socket.io';
|
|
5
25
|
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
26
|
+
import { socketRequireAuth } from './lib/requireAuth.js';
|
|
27
|
+
import { socketRequireLocalRequest } from './lib/localRequest.js';
|
|
8
28
|
import { loadConfig } from '../core/config.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
createNginxDownEvent,
|
|
12
|
-
createNginxRecoveredEvent,
|
|
13
|
-
createDomainDownEvent,
|
|
14
|
-
createDomainRecoveredEvent,
|
|
15
|
-
} from '../core/events.js';
|
|
16
|
-
import { sendNotification } from '../core/notifier.js';
|
|
17
|
-
import {
|
|
18
|
-
getEffectiveChannelIds,
|
|
19
|
-
getAllDomainChannelIds,
|
|
20
|
-
shouldSendNotification,
|
|
21
|
-
} from '../core/domainNotifier.js';
|
|
29
|
+
import { nginxLogPath } from '../core/platform.js';
|
|
30
|
+
import { publish, subscribeAll } from '../core/jobs/bus.js';
|
|
22
31
|
|
|
23
32
|
let connectedClients = 0;
|
|
24
33
|
const activeTails = new Map();
|
|
25
34
|
|
|
35
|
+
let ioServer = null;
|
|
36
|
+
let unsubscribeBus = null;
|
|
37
|
+
|
|
26
38
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
39
|
+
* The most recent payload for each replayable event.
|
|
40
|
+
*
|
|
41
|
+
* A newly opened tab has to show something immediately. The monitors publish
|
|
42
|
+
* on their own schedule — domain health every 60 seconds — so without this a
|
|
43
|
+
* tab opened just after a poll would sit empty until the next one. Previously
|
|
44
|
+
* the fix was to run a fresh poll per connection; that does not work when the
|
|
45
|
+
* polling happens in another process, and it meant every opened tab triggered
|
|
46
|
+
* real work.
|
|
47
|
+
*
|
|
48
|
+
* `service:changed` is cached for the same reason, and matters more: a tab
|
|
49
|
+
* that opens while the daemon is already running must render the banner right
|
|
50
|
+
* away rather than waiting for the next hand-over to tell it anything.
|
|
51
|
+
*
|
|
52
|
+
* Only the state-like events are cached. `notification:new` is not: it is a
|
|
53
|
+
* discrete thing that happened, and replaying old notifications into each new
|
|
54
|
+
* tab would announce outages that are long over.
|
|
29
55
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const status = await getStatus();
|
|
33
|
-
target.emit('nginx:status', status);
|
|
34
|
-
|
|
35
|
-
const currentStatus = status.running ? 'up' : 'down';
|
|
36
|
-
const decision = shouldSendNotification(null, 'nginx_down', currentStatus);
|
|
37
|
-
|
|
38
|
-
if (decision.shouldNotify) {
|
|
39
|
-
let event;
|
|
40
|
-
if (decision.reason === 'recovery') {
|
|
41
|
-
event = createNginxRecoveredEvent();
|
|
42
|
-
} else {
|
|
43
|
-
event = createNginxDownEvent();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
console.log(`[socketManager] Sending nginx notification: ${decision.reason}`);
|
|
47
|
-
target.emit('notification:new', event);
|
|
48
|
-
|
|
49
|
-
// External channel routing (fire-and-forget, isolated)
|
|
50
|
-
try {
|
|
51
|
-
const channels = getAllDomainChannelIds('nginx_down');
|
|
52
|
-
await sendNotification(event, channels);
|
|
53
|
-
} catch (err) {
|
|
54
|
-
console.error('[socketManager] sendNotification failed:', err.message);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
} catch (err) {
|
|
58
|
-
target.emit('nginx:status', { running: false, version: null, pid: null, error: err.message });
|
|
59
|
-
}
|
|
60
|
-
}
|
|
56
|
+
const REPLAYABLE = ['nginx:status', 'domain:health', 'service:changed'];
|
|
57
|
+
const lastKnown = new Map();
|
|
61
58
|
|
|
62
59
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
60
|
+
* Initialize the Socket.IO server.
|
|
61
|
+
*
|
|
62
|
+
* @param {import('http').Server} httpServer
|
|
63
|
+
* @param {Function} sessionMiddleware Shared with Express so sockets see the same session
|
|
64
|
+
* @param {Function} getBinding Returns the current { port, bindAddress }
|
|
65
|
+
* @returns {import('socket.io').Server}
|
|
67
66
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
await sendNotification(event, channels);
|
|
87
|
-
} catch (err) {
|
|
88
|
-
console.error('[socketManager] sendNotification failed:', err.message);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
} catch {
|
|
93
|
-
/* non-fatal */
|
|
67
|
+
function initSocket(httpServer, sessionMiddleware, getBinding) {
|
|
68
|
+
const io = new SocketIO(httpServer);
|
|
69
|
+
ioServer = io;
|
|
70
|
+
|
|
71
|
+
// The socket stream is not a lesser surface than the REST API: it carries
|
|
72
|
+
// nginx status, domain health and live log tails. It gets the same session
|
|
73
|
+
// check.
|
|
74
|
+
//
|
|
75
|
+
// `io.engine.use` runs the express-session middleware on the handshake
|
|
76
|
+
// request, which is what puts `socket.request.session` in place for
|
|
77
|
+
// socketRequireAuth to read. Without the middleware there is no session
|
|
78
|
+
// object at all, and the guard then refuses every connection — which is the
|
|
79
|
+
// correct direction to fail, but would break the dashboard, so it is worth
|
|
80
|
+
// noticing rather than shipping.
|
|
81
|
+
if (typeof sessionMiddleware === 'function') {
|
|
82
|
+
io.engine.use(sessionMiddleware);
|
|
83
|
+
} else {
|
|
84
|
+
console.error('[socketManager] no session middleware supplied — refusing all socket connections');
|
|
94
85
|
}
|
|
95
|
-
}
|
|
96
86
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
req.end();
|
|
87
|
+
// Host / Origin / X-EZ-Request, before the session check — the handshake is
|
|
88
|
+
// as reachable from a hostile page as any POST is, and a socket has no
|
|
89
|
+
// "safe method", so the custom header is required unconditionally.
|
|
90
|
+
//
|
|
91
|
+
// This is why the browser client must NOT force transports: ['websocket']:
|
|
92
|
+
// browsers cannot set headers on a WebSocket upgrade. socket.io's default
|
|
93
|
+
// starts with HTTP polling, where extraHeaders does apply, and the
|
|
94
|
+
// handshake is authenticated there before any upgrade happens.
|
|
95
|
+
if (typeof getBinding === 'function') {
|
|
96
|
+
io.use(socketRequireLocalRequest(getBinding));
|
|
97
|
+
} else {
|
|
98
|
+
console.error('[socketManager] no binding supplied — refusing all socket connections');
|
|
99
|
+
io.use((socket, next) => next(new Error('FORBIDDEN')));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
io.use(socketRequireAuth);
|
|
103
|
+
|
|
104
|
+
// One subscription for the whole server, not one per client: these events are
|
|
105
|
+
// broadcasts, and subscribing per socket would deliver each one as many times
|
|
106
|
+
// as there are tabs open.
|
|
107
|
+
unsubscribeBus = subscribeAll((event, payload) => {
|
|
108
|
+
if (REPLAYABLE.includes(event)) lastKnown.set(event, payload);
|
|
109
|
+
if (connectedClients > 0) io.emit(event, payload);
|
|
121
110
|
});
|
|
122
|
-
}
|
|
123
111
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
try {
|
|
132
|
-
const domains = dbGet('domains') || [];
|
|
133
|
-
const results = await Promise.all(
|
|
134
|
-
domains.map(async (d) => {
|
|
135
|
-
const host = d.backendHost || '127.0.0.1';
|
|
136
|
-
const port = d.port || 80;
|
|
137
|
-
|
|
138
|
-
// Skip external URL backends
|
|
139
|
-
if (typeof host === 'string' && host.startsWith('http')) return { name: d.name, up: null };
|
|
140
|
-
|
|
141
|
-
const { up } = await checkDomainHealth(host, port);
|
|
142
|
-
return { name: d.name, up, port, host };
|
|
143
|
-
})
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
target.emit('domain:health', results);
|
|
147
|
-
|
|
148
|
-
// Process state transitions for each domain
|
|
149
|
-
for (const result of results) {
|
|
150
|
-
if (result.up === null) continue; // Skip external URL backends
|
|
151
|
-
|
|
152
|
-
const currentStatus = result.up ? 'up' : 'down';
|
|
153
|
-
const decision = shouldSendNotification(result.name, 'domain_health', currentStatus);
|
|
154
|
-
|
|
155
|
-
if (decision.shouldNotify) {
|
|
156
|
-
let event;
|
|
157
|
-
if (decision.reason === 'recovery') {
|
|
158
|
-
event = createDomainRecoveredEvent(result.name, result.port);
|
|
159
|
-
} else {
|
|
160
|
-
event = createDomainDownEvent(result.name, result.port);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
console.log(`[socketManager] Sending domain health notification for ${result.name}: ${decision.reason}`);
|
|
164
|
-
target.emit('notification:new', event);
|
|
165
|
-
|
|
166
|
-
try {
|
|
167
|
-
const channelIds = getEffectiveChannelIds(result.name, 'domain_health');
|
|
168
|
-
await sendNotification(event, channelIds);
|
|
169
|
-
} catch (err) {
|
|
170
|
-
console.error('[socketManager] domain health sendNotification failed:', err.message);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
112
|
+
io.on('connection', (socket) => {
|
|
113
|
+
connectedClients++;
|
|
114
|
+
|
|
115
|
+
// Whatever we last heard, so the UI renders immediately instead of waiting
|
|
116
|
+
// for the next poll in whichever process owns the jobs.
|
|
117
|
+
for (const event of REPLAYABLE) {
|
|
118
|
+
if (lastKnown.has(event)) socket.emit(event, lastKnown.get(event));
|
|
173
119
|
}
|
|
174
|
-
} catch (err) {
|
|
175
|
-
console.error('[socketManager] emitDomainHealth error:', err.message);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
120
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
*/
|
|
182
|
-
function getLogPath(logFile) {
|
|
183
|
-
const { nginxDir } = loadConfig();
|
|
184
|
-
const file = logFile === 'access' ? 'access.log' : 'error.log';
|
|
121
|
+
socket.on('logs:subscribe', ({ logFile } = {}) => startTail(socket, logFile || 'error'));
|
|
122
|
+
socket.on('logs:unsubscribe', () => stopTail(socket.id));
|
|
185
123
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
124
|
+
socket.on('disconnect', () => {
|
|
125
|
+
connectedClients--;
|
|
126
|
+
stopTail(socket.id);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
return io;
|
|
191
131
|
}
|
|
192
132
|
|
|
133
|
+
// ─── Live log tails ───────────────────────────────────────────────────────────
|
|
134
|
+
|
|
193
135
|
/**
|
|
194
|
-
*
|
|
136
|
+
* Starts tailing a log file for one socket.
|
|
137
|
+
*
|
|
138
|
+
* `-n 50` / `-Tail 50` is what satisfies the contract's promise that a
|
|
139
|
+
* subscribe replays the last 50 lines before streaming: the tail command does
|
|
140
|
+
* both in one call, so there is no window between the replay and the live
|
|
141
|
+
* stream in which a line could be missed.
|
|
195
142
|
*/
|
|
196
143
|
function startTail(socket, logFile) {
|
|
197
|
-
// Kill any existing tail for this socket
|
|
198
144
|
stopTail(socket.id);
|
|
199
145
|
|
|
200
|
-
const
|
|
146
|
+
const { nginxDir } = loadConfig();
|
|
147
|
+
const logPath = nginxLogPath(nginxDir, logFile === 'access' ? 'access' : 'error');
|
|
148
|
+
|
|
201
149
|
const args = process.platform === 'win32'
|
|
202
150
|
? ['Get-Content', '-Path', logPath, '-Wait', '-Tail', '50']
|
|
203
151
|
: ['-n', '50', '-f', logPath];
|
|
@@ -212,7 +160,7 @@ function startTail(socket, logFile) {
|
|
|
212
160
|
child.stdout.on('data', (chunk) => {
|
|
213
161
|
buf += chunk.toString();
|
|
214
162
|
const lines = buf.split('\n');
|
|
215
|
-
buf = lines.pop(); // keep incomplete line in buffer
|
|
163
|
+
buf = lines.pop(); // keep the incomplete line in the buffer
|
|
216
164
|
for (const line of lines) {
|
|
217
165
|
if (line.trim()) socket.emit('logs:line', { line: line.trim(), logFile });
|
|
218
166
|
}
|
|
@@ -226,9 +174,7 @@ function startTail(socket, logFile) {
|
|
|
226
174
|
activeTails.set(socket.id, { process: child, logFile });
|
|
227
175
|
}
|
|
228
176
|
|
|
229
|
-
/**
|
|
230
|
-
* Stop tailing a log file for a socket.
|
|
231
|
-
*/
|
|
177
|
+
/** Stops the tail belonging to one socket. */
|
|
232
178
|
function stopTail(socketId) {
|
|
233
179
|
const entry = activeTails.get(socketId);
|
|
234
180
|
if (entry) {
|
|
@@ -239,44 +185,62 @@ function stopTail(socketId) {
|
|
|
239
185
|
}
|
|
240
186
|
}
|
|
241
187
|
|
|
188
|
+
// ─── Outbound helper ──────────────────────────────────────────────────────────
|
|
189
|
+
|
|
242
190
|
/**
|
|
243
|
-
*
|
|
191
|
+
* Tells every open dashboard tab that a section changed, so the UI can refresh
|
|
192
|
+
* just that part instead of reloading the page.
|
|
193
|
+
*
|
|
194
|
+
* Used when a change did NOT originate in this browser — most importantly when
|
|
195
|
+
* the Hub applies a command through core/hub/agent.js, or when another process
|
|
196
|
+
* moves the revision counter.
|
|
197
|
+
*
|
|
198
|
+
* It publishes to the job bus rather than emitting at the socket server
|
|
199
|
+
* directly, so the same call works in the daemon, which has no socket server,
|
|
200
|
+
* and still reaches browsers through IPC. Safe to call before initSocket().
|
|
201
|
+
*
|
|
202
|
+
* @param {'domains'|'ssl'|'nginx'|'settings'} section
|
|
203
|
+
* @param {Object} [detail] Optional extra context for the client
|
|
244
204
|
*/
|
|
245
|
-
function
|
|
246
|
-
|
|
205
|
+
function emitLocalChange(section, detail = {}) {
|
|
206
|
+
publish('local:changed', { section, source: 'hub', at: Date.now(), ...detail });
|
|
207
|
+
}
|
|
247
208
|
|
|
248
|
-
|
|
249
|
-
|
|
209
|
+
/**
|
|
210
|
+
* Stops everything initSocket() started: the bus subscription, every active
|
|
211
|
+
* log tail (each is a spawned child process), and the Socket.io server itself.
|
|
212
|
+
* Safe to call more than once.
|
|
213
|
+
*
|
|
214
|
+
* It does NOT stop the background jobs — server.js owns those, because their
|
|
215
|
+
* lifetime is the process's, not the socket server's.
|
|
216
|
+
*
|
|
217
|
+
* @returns {Promise<void>} Resolves once the Socket.io server has closed
|
|
218
|
+
*/
|
|
219
|
+
async function stopSocket() {
|
|
220
|
+
if (unsubscribeBus) {
|
|
221
|
+
unsubscribeBus();
|
|
222
|
+
unsubscribeBus = null;
|
|
223
|
+
}
|
|
250
224
|
|
|
251
|
-
|
|
252
|
-
|
|
225
|
+
// Kill the tail/Get-Content children; stopTail() removes each map entry.
|
|
226
|
+
for (const socketId of [...activeTails.keys()]) stopTail(socketId);
|
|
253
227
|
|
|
254
|
-
|
|
255
|
-
|
|
228
|
+
connectedClients = 0;
|
|
229
|
+
lastKnown.clear();
|
|
256
230
|
|
|
257
|
-
|
|
258
|
-
|
|
231
|
+
const io = ioServer;
|
|
232
|
+
ioServer = null;
|
|
233
|
+
if (!io) return;
|
|
259
234
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
235
|
+
await new Promise((resolve) => {
|
|
236
|
+
// close() disconnects clients and stops accepting new ones. It is given a
|
|
237
|
+
// short grace period so a wedged client cannot block shutdown.
|
|
238
|
+
const done = setTimeout(resolve, 2000);
|
|
239
|
+
io.close(() => {
|
|
240
|
+
clearTimeout(done);
|
|
241
|
+
resolve();
|
|
263
242
|
});
|
|
264
243
|
});
|
|
265
|
-
|
|
266
|
-
// Poll domain health every 60 seconds
|
|
267
|
-
setInterval(() => {
|
|
268
|
-
if (connectedClients > 0) emitDomainHealth(io);
|
|
269
|
-
}, 60_000);
|
|
270
|
-
|
|
271
|
-
// Broadcast nginx status to all clients every 5 seconds
|
|
272
|
-
setInterval(() => {
|
|
273
|
-
if (connectedClients > 0) emitNginxStatus(io);
|
|
274
|
-
}, 5000);
|
|
275
|
-
|
|
276
|
-
// Check cert expiry every 12 hours
|
|
277
|
-
setInterval(() => {
|
|
278
|
-
if (connectedClients > 0) emitCertNotifications(io);
|
|
279
|
-
}, 12 * 60 * 60 * 1000);
|
|
280
244
|
}
|
|
281
245
|
|
|
282
|
-
export { initSocket };
|
|
246
|
+
export { initSocket, stopSocket, emitLocalChange };
|
|
@@ -689,6 +689,7 @@ class="theme-accent-circle"
|
|
|
689
689
|
<%- include('partials/ssl-panel.ejs') %>
|
|
690
690
|
<%- include('partials/domains-panel.ejs') %>
|
|
691
691
|
<%- include('partials/settings-panel.ejs') %>
|
|
692
|
+
<%- include('partials/processes-panel.ejs') %>
|
|
692
693
|
<%- include('partials/logs-panel.ejs') %>
|
|
693
694
|
</div>
|
|
694
695
|
</transition>
|
|
@@ -95,7 +95,34 @@
|
|
|
95
95
|
|
|
96
96
|
<!-- Login Card -->
|
|
97
97
|
<div class="login-card w-full text-left" style="animation: card-enter 500ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;">
|
|
98
|
-
|
|
98
|
+
<!--
|
|
99
|
+
First run: no password exists yet, so the only thing on offer is
|
|
100
|
+
setting one. There is deliberately no way to skip this — an empty
|
|
101
|
+
password used to be a valid login.
|
|
102
|
+
-->
|
|
103
|
+
<template v-if="login.needsSetup">
|
|
104
|
+
<p style="
|
|
105
|
+
font-size: 13px; color: var(--color-muted);
|
|
106
|
+
margin-top: 0; margin-bottom: 20px; font-weight: 500; line-height: 1.6;
|
|
107
|
+
">
|
|
108
|
+
No dashboard password is set yet. Choose one to protect this dashboard —
|
|
109
|
+
at least {{ login.minLength }} characters.
|
|
110
|
+
</p>
|
|
111
|
+
|
|
112
|
+
<div class="mb-4">
|
|
113
|
+
<label class="login-label">New password</label>
|
|
114
|
+
<input v-model="login.password" type="password" class="login-input"
|
|
115
|
+
:placeholder="'At least ' + login.minLength + ' characters'" @keyup.enter="doSetup" />
|
|
116
|
+
</div>
|
|
117
|
+
|
|
118
|
+
<div class="mb-6">
|
|
119
|
+
<label class="login-label">Confirm password</label>
|
|
120
|
+
<input v-model="login.confirm" type="password" class="login-input"
|
|
121
|
+
placeholder="Repeat the password" @keyup.enter="doSetup" />
|
|
122
|
+
</div>
|
|
123
|
+
</template>
|
|
124
|
+
|
|
125
|
+
<div v-else class="mb-6">
|
|
99
126
|
<label class="login-label">Password</label>
|
|
100
127
|
<input v-model="login.password" type="password" class="login-input" placeholder="Enter dashboard password" @keyup.enter="doLogin" />
|
|
101
128
|
</div>
|
|
@@ -113,18 +140,52 @@
|
|
|
113
140
|
{{ login.error }}
|
|
114
141
|
</div>
|
|
115
142
|
|
|
116
|
-
<button @click="
|
|
143
|
+
<button v-if="login.needsSetup" @click="doSetup" :disabled="login.loading" class="login-btn gap-2">
|
|
117
144
|
<svg v-if="login.loading" class="w-4 h-4 animate-spin inline-block -ml-1" fill="none" viewBox="0 0 24 24">
|
|
118
145
|
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
|
119
146
|
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"></path>
|
|
120
147
|
</svg>
|
|
121
|
-
{{ login.loading ? '
|
|
148
|
+
{{ login.loading ? 'Saving...' : 'Set a password' }}
|
|
122
149
|
</button>
|
|
123
150
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
151
|
+
<!--
|
|
152
|
+
Shown only when the server says so: the dashboard must listen on this
|
|
153
|
+
machine only AND this page must have been opened from this machine.
|
|
154
|
+
Anywhere else the option does not appear at all.
|
|
155
|
+
-->
|
|
156
|
+
<template v-if="login.needsSetup && login.canUseNoPassword">
|
|
157
|
+
<div style="
|
|
158
|
+
display: flex; align-items: center; gap: 12px;
|
|
159
|
+
margin: 20px 0 16px; color: var(--color-muted);
|
|
160
|
+
font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700;
|
|
161
|
+
">
|
|
162
|
+
<span style="flex: 1; height: 1px; background: var(--color-border);"></span>
|
|
163
|
+
or
|
|
164
|
+
<span style="flex: 1; height: 1px; background: var(--color-border);"></span>
|
|
165
|
+
</div>
|
|
166
|
+
|
|
167
|
+
<button @click="doSetupNoPassword" :disabled="login.loading"
|
|
168
|
+
class="login-btn gap-2"
|
|
169
|
+
style="background: transparent; border: 1px solid var(--color-border); color: var(--color-foreground);">
|
|
170
|
+
No password (this machine only)
|
|
171
|
+
</button>
|
|
172
|
+
|
|
173
|
+
<p style="
|
|
174
|
+
text-align: center; font-size: 11px; color: var(--color-muted);
|
|
175
|
+
margin-top: 12px; margin-bottom: 0; font-weight: 500; line-height: 1.6;
|
|
176
|
+
">
|
|
177
|
+
The dashboard stays reachable from this computer only. You can set a
|
|
178
|
+
password later in Settings.
|
|
179
|
+
</p>
|
|
180
|
+
</template>
|
|
181
|
+
|
|
182
|
+
<button v-else @click="doLogin" :disabled="login.loading" class="login-btn gap-2">
|
|
183
|
+
<svg v-if="login.loading" class="w-4 h-4 animate-spin inline-block -ml-1" fill="none" viewBox="0 0 24 24">
|
|
184
|
+
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
|
185
|
+
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"></path>
|
|
186
|
+
</svg>
|
|
187
|
+
{{ login.loading ? 'Signing in...' : 'Sign In' }}
|
|
188
|
+
</button>
|
|
128
189
|
</div>
|
|
129
190
|
|
|
130
191
|
<!-- Bottom Theme Controls (Pill) -->
|