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
package/src/cli/index.js
CHANGED
|
@@ -1,128 +1,259 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* cli/index.js — entry point and bootstrap.
|
|
4
|
+
*
|
|
5
|
+
* This file deliberately has NO static import that reaches core/db.js.
|
|
6
|
+
* ESM evaluates every static import before any module body runs, so the data
|
|
7
|
+
* directory has to be decided here, before the database module is loaded.
|
|
8
|
+
* Everything else is pulled in with a dynamic import() once the environment
|
|
9
|
+
* is set up.
|
|
10
|
+
*
|
|
11
|
+
* Flags are parsed by hand: util.parseArgs is not available on Node 18.0,
|
|
12
|
+
* which is this project's documented minimum.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import path from 'path';
|
|
16
|
+
import { fileURLToPath } from 'url';
|
|
2
17
|
import { createRequire } from 'module';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import ora from 'ora';
|
|
5
|
-
import inquirer from 'inquirer';
|
|
6
|
-
import { runDetection, showSystemStatus, formatStatusLine } from '../core/detector.js';
|
|
7
|
-
|
|
8
|
-
import nodejsMenu from './menus/nodejs.js';
|
|
9
|
-
import nginxMenu from './menus/nginx.js';
|
|
10
|
-
import sslMenu from './menus/ssl.js';
|
|
11
|
-
import domainsMenu from './menus/domains.js';
|
|
12
|
-
import dashboardMenu from './menus/dashboard.js';
|
|
13
|
-
import settingsMenu from './menus/settings.js';
|
|
14
|
-
import updateMenu from './menus/update.js';
|
|
15
18
|
|
|
16
19
|
const require = createRequire(import.meta.url);
|
|
17
20
|
const { version } = require('../../package.json');
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
23
|
+
const PROJECT_ROOT = path.resolve(__dirname, '..', '..');
|
|
24
|
+
const DEV_DATA_DIR = path.join(PROJECT_ROOT, '.dev-data');
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
// Must match DATA_DIR_ENV and DEV_MODE_ENV in core/platform.js. Hardcoded
|
|
27
|
+
// rather than imported because importing platform.js here is fine, but keeping
|
|
28
|
+
// this file free of project imports makes the ordering guarantee obvious at a
|
|
29
|
+
// glance.
|
|
30
|
+
const DATA_DIR_ENV = 'EASY_DEVOPS_DATA_DIR';
|
|
31
|
+
const DEV_MODE_ENV = 'EZ_DEV';
|
|
32
|
+
|
|
33
|
+
// Read by dashboard/server.js, not by core/. Set here because the flag is a
|
|
34
|
+
// one-run override of the dashboardUi setting and the server must know about
|
|
35
|
+
// it before it mounts its routes.
|
|
36
|
+
//
|
|
37
|
+
// The React UI is now the default, so the override runs the other way:
|
|
38
|
+
// --classic-ui asks for the old EJS page. --new-ui is kept as an accepted
|
|
39
|
+
// no-op so an existing habit or script does not start failing.
|
|
40
|
+
const CLASSIC_UI_ENV = 'EASY_DEVOPS_CLASSIC_UI';
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Parses argv into flags and positional arguments.
|
|
44
|
+
* Recognises `--flag` and the short aliases `-h` / `-v`.
|
|
45
|
+
*
|
|
46
|
+
* Every positional is kept, not just the first: `ezz service install` needs
|
|
47
|
+
* both the command and its subcommand.
|
|
48
|
+
*
|
|
49
|
+
* @param {string[]} argv Arguments after node and the script path
|
|
50
|
+
* @returns {{ flags: Set<string>, command: string|null, args: string[], unknown: string[] }}
|
|
51
|
+
*/
|
|
52
|
+
function parseArgs(argv) {
|
|
53
|
+
const known = new Set([
|
|
54
|
+
'dash', 'dev', 'classic-ui', 'new-ui', 'help', 'version',
|
|
55
|
+
// Command options. Kept in the same set because the parser runs before
|
|
56
|
+
// any command module is loaded, and an unknown flag must still be
|
|
57
|
+
// refused rather than silently ignored.
|
|
58
|
+
'purge', 'yes',
|
|
59
|
+
]);
|
|
60
|
+
// Options that take a value, so `--days 30` does not leave `30` looking
|
|
61
|
+
// like a positional argument.
|
|
62
|
+
const valued = new Set(['days']);
|
|
63
|
+
const flags = new Set();
|
|
64
|
+
const unknown = [];
|
|
65
|
+
const positionals = [];
|
|
66
|
+
|
|
67
|
+
const options = {};
|
|
68
|
+
let expecting = null;
|
|
69
|
+
|
|
70
|
+
for (const arg of argv) {
|
|
71
|
+
if (expecting) {
|
|
72
|
+
options[expecting] = arg;
|
|
73
|
+
expecting = null;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (arg === '-h') { flags.add('help'); continue; }
|
|
78
|
+
if (arg === '-v') { flags.add('version'); continue; }
|
|
26
79
|
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
80
|
+
if (arg.startsWith('--')) {
|
|
81
|
+
const body = arg.slice(2);
|
|
82
|
+
const eq = body.indexOf('=');
|
|
83
|
+
const name = eq === -1 ? body : body.slice(0, eq);
|
|
30
84
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
85
|
+
if (valued.has(name)) {
|
|
86
|
+
if (eq === -1) expecting = name;
|
|
87
|
+
else options[name] = body.slice(eq + 1);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (known.has(name)) flags.add(name);
|
|
92
|
+
else unknown.push(arg);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
positionals.push(arg);
|
|
36
97
|
}
|
|
98
|
+
|
|
99
|
+
if (expecting) unknown.push(`--${expecting} (missing its value)`);
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
flags,
|
|
103
|
+
options,
|
|
104
|
+
command: positionals[0] ?? null,
|
|
105
|
+
args: positionals.slice(1),
|
|
106
|
+
unknown,
|
|
107
|
+
};
|
|
37
108
|
}
|
|
38
109
|
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
110
|
+
function printHelp() {
|
|
111
|
+
process.stdout.write(`
|
|
112
|
+
Easy DevOps v${version}
|
|
113
|
+
|
|
114
|
+
Usage:
|
|
115
|
+
easy-devops [command] [options]
|
|
116
|
+
ezz [command] [options] (short alias)
|
|
117
|
+
|
|
118
|
+
Commands:
|
|
119
|
+
(none) Start the interactive CLI menu
|
|
120
|
+
system-info Print detected system info and exit
|
|
121
|
+
daemon Run the background worker in the foreground: monitoring,
|
|
122
|
+
notifications and the Hub agent. No web port is opened.
|
|
123
|
+
Normally started by the installed service, not by hand.
|
|
124
|
+
service <action> Install and manage the native background service.
|
|
125
|
+
Actions: install, uninstall, status, start, stop,
|
|
126
|
+
restart, logs, repair
|
|
127
|
+
runtime <action> The Node runtime the service is pinned to.
|
|
128
|
+
Actions: status, update
|
|
129
|
+
update Update Easy DevOps itself, then restart the service.
|
|
130
|
+
cleanup List reclaimable files (runtime backups, old logs, stale
|
|
131
|
+
locks, nginx .bak files) and remove the ones you choose.
|
|
132
|
+
uninstall Remove Easy DevOps. Needs --purge to do anything.
|
|
133
|
+
dashboard <action>
|
|
134
|
+
Actions: setup-code (issue a new first-run setup code)
|
|
135
|
+
|
|
136
|
+
Options:
|
|
137
|
+
--dash Start the web dashboard in the foreground and print its
|
|
138
|
+
URL. Press Ctrl+C to stop it cleanly.
|
|
139
|
+
--dev Use an isolated data directory (.dev-data in the project)
|
|
140
|
+
instead of the real one, so development never touches your
|
|
141
|
+
installed configuration. Combines with --dash.
|
|
142
|
+
--classic-ui Serve the old EJS dashboard instead of the React one, for
|
|
143
|
+
one run. A temporary fallback; overrides the dashboardUi
|
|
144
|
+
setting.
|
|
145
|
+
--purge With "uninstall": remove the service, the pinned runtime
|
|
146
|
+
and the data directory, after exporting a backup. nginx,
|
|
147
|
+
your sites and your certificates are kept.
|
|
148
|
+
--days N With "cleanup": treat logs older than N days as
|
|
149
|
+
reclaimable (default 14).
|
|
150
|
+
--yes Answer the confirmations yes. For scripts;
|
|
151
|
+
"uninstall --purge" still prints what it will do.
|
|
152
|
+
-h, --help Show this help
|
|
153
|
+
-v, --version Show the version
|
|
154
|
+
|
|
155
|
+
Examples:
|
|
156
|
+
ezz Interactive menu
|
|
157
|
+
ezz --dash Run the dashboard in this terminal
|
|
158
|
+
ezz --dash --classic-ui Run the dashboard with the old EJS UI
|
|
159
|
+
ezz --dev --dash Run the dashboard against .dev-data
|
|
160
|
+
ezz service install Install the background service
|
|
161
|
+
ezz service status Show whether the service runs and starts on boot
|
|
162
|
+
ezz service stop Stop it until the next logon/boot (temporary)
|
|
163
|
+
ezz service start Start it again now
|
|
164
|
+
ezz daemon Run the background worker here (debugging)
|
|
165
|
+
ezz runtime status Show the pinned Node and the available LTS versions
|
|
166
|
+
ezz runtime update Move the service to a newer Node, with rollback
|
|
167
|
+
ezz update Update Easy DevOps and restart the service
|
|
168
|
+
ezz cleanup Show what can be reclaimed (nothing is deleted)
|
|
169
|
+
ezz dashboard setup-code Issue a new first-run setup code
|
|
170
|
+
npm run dev Interactive menu against .dev-data
|
|
171
|
+
|
|
172
|
+
`);
|
|
68
173
|
}
|
|
69
174
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
'📦 Node.js Manager',
|
|
77
|
-
'🌐 Nginx Manager',
|
|
78
|
-
'🔒 SSL Manager',
|
|
79
|
-
'🔗 Domain Manager',
|
|
80
|
-
'🎛️ Open Dashboard',
|
|
81
|
-
'⚙️ Settings',
|
|
82
|
-
'🔄 Check for Updates',
|
|
83
|
-
'✖ Exit',
|
|
84
|
-
],
|
|
85
|
-
}]);
|
|
86
|
-
return answers.choice;
|
|
175
|
+
const { flags, options, command, args, unknown } = parseArgs(process.argv.slice(2));
|
|
176
|
+
|
|
177
|
+
if (unknown.length > 0) {
|
|
178
|
+
process.stderr.write(`Unknown option: ${unknown.join(', ')}\n`);
|
|
179
|
+
process.stderr.write('Run `easy-devops --help` to see the available options.\n');
|
|
180
|
+
process.exit(1);
|
|
87
181
|
}
|
|
88
182
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
case '🌐 Nginx Manager': await nginxMenu(); break;
|
|
93
|
-
case '🔒 SSL Manager': await sslMenu(); break;
|
|
94
|
-
case '🔗 Domain Manager': await domainsMenu(); break;
|
|
95
|
-
case '🎛️ Open Dashboard': await dashboardMenu(); break;
|
|
96
|
-
case '⚙️ Settings': await settingsMenu(); break;
|
|
97
|
-
case '🔄 Check for Updates': await updateMenu(); break;
|
|
98
|
-
case '✖ Exit': process.exit(0);
|
|
99
|
-
}
|
|
183
|
+
if (flags.has('help')) {
|
|
184
|
+
printHelp();
|
|
185
|
+
process.exit(0);
|
|
100
186
|
}
|
|
101
187
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
spinner.stop();
|
|
107
|
-
|
|
108
|
-
try {
|
|
109
|
-
renderBanner();
|
|
110
|
-
console.log(' ' + formatStatusLine());
|
|
111
|
-
console.log();
|
|
112
|
-
} catch {
|
|
113
|
-
console.log(`\n=== Easy DevOps v${version} ===\n`);
|
|
114
|
-
}
|
|
188
|
+
if (flags.has('version')) {
|
|
189
|
+
process.stdout.write(`${version}\n`);
|
|
190
|
+
process.exit(0);
|
|
191
|
+
}
|
|
115
192
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
193
|
+
// ─── Dev data mode ────────────────────────────────────────────────────────────
|
|
194
|
+
// Set before any dynamic import below, so core/db.js — and any child process
|
|
195
|
+
// that inherits this environment, such as the detached dashboard — resolves
|
|
196
|
+
// the isolated directory. An explicit EASY_DEVOPS_DATA_DIR always wins.
|
|
197
|
+
//
|
|
198
|
+
// EZ_DEV is set alongside it, and is what actually marks the run as
|
|
199
|
+
// development. The data directory alone must never imply dev mode: every
|
|
200
|
+
// installed service passes EASY_DEVOPS_DATA_DIR so the service and the CLI
|
|
201
|
+
// agree on one location, and treating that as dev issued staging certificates
|
|
202
|
+
// on real domains. See isDevDataDir() in core/platform.js.
|
|
203
|
+
if (flags.has('dev')) {
|
|
204
|
+
process.env[DEV_MODE_ENV] = '1';
|
|
205
|
+
if (!process.env[DATA_DIR_ENV]?.trim()) {
|
|
206
|
+
process.env[DATA_DIR_ENV] = DEV_DATA_DIR;
|
|
125
207
|
}
|
|
126
208
|
}
|
|
127
209
|
|
|
128
|
-
|
|
210
|
+
// Same ordering reason as the data directory: dashboard/server.js is only
|
|
211
|
+
// imported below, so the flag is in the environment before it can be read.
|
|
212
|
+
if (flags.has('classic-ui')) {
|
|
213
|
+
process.env[CLASSIC_UI_ENV] = '1';
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Accepted and ignored: the new UI is what you get anyway.
|
|
217
|
+
if (flags.has('new-ui') && !flags.has('classic-ui')) {
|
|
218
|
+
process.stdout.write('Note: --new-ui is the default now; the flag is no longer needed.\n');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// ─── Dispatch ─────────────────────────────────────────────────────────────────
|
|
222
|
+
|
|
223
|
+
if (flags.has('dash')) {
|
|
224
|
+
const { runDashboard } = await import('./dash.js');
|
|
225
|
+
await runDashboard();
|
|
226
|
+
} else if (command === 'system-info') {
|
|
227
|
+
const { systemInfo } = await import('./menu.js');
|
|
228
|
+
await systemInfo();
|
|
229
|
+
process.exit(0);
|
|
230
|
+
} else if (command === 'daemon') {
|
|
231
|
+
// Runs in the foreground and never returns: the service managers that start
|
|
232
|
+
// it (WinSW, systemd, the Startup supervisor) all expect a process they can
|
|
233
|
+
// watch, and one that forks into the background looks to them like a crash.
|
|
234
|
+
const { runDaemon } = await import('../core/daemon/run.js');
|
|
235
|
+
process.exit(await runDaemon());
|
|
236
|
+
} else if (command === 'service') {
|
|
237
|
+
const { serviceCommand } = await import('./menus/service.js');
|
|
238
|
+
process.exit(await serviceCommand(args[0] ?? 'status'));
|
|
239
|
+
} else if (command === 'runtime') {
|
|
240
|
+
const { runtimeCommand } = await import('./menus/runtime.js');
|
|
241
|
+
process.exit(await runtimeCommand(args[0] ?? 'status', { yes: flags.has('yes') }));
|
|
242
|
+
} else if (command === 'update') {
|
|
243
|
+
const { updateCommand } = await import('./menus/update.js');
|
|
244
|
+
process.exit(await updateCommand({ yes: flags.has('yes') }));
|
|
245
|
+
} else if (command === 'cleanup') {
|
|
246
|
+
const { cleanupCommand } = await import('./menus/cleanup.js');
|
|
247
|
+
process.exit(await cleanupCommand({ days: options.days, yes: flags.has('yes') }));
|
|
248
|
+
} else if (command === 'uninstall') {
|
|
249
|
+
const { uninstallCommand } = await import('./menus/uninstall.js');
|
|
250
|
+
process.exit(await uninstallCommand({ purge: flags.has('purge'), yes: flags.has('yes') }));
|
|
251
|
+
} else if (command === 'dashboard') {
|
|
252
|
+
const { dashboardCommand } = await import('./menus/dashboard.js');
|
|
253
|
+
process.exit(await dashboardCommand(args[0] ?? 'setup-code'));
|
|
254
|
+
} else {
|
|
255
|
+
// Interactive menu: Ctrl+C simply quits.
|
|
256
|
+
process.on('SIGINT', () => process.exit(0));
|
|
257
|
+
const { run } = await import('./menu.js');
|
|
258
|
+
await run();
|
|
259
|
+
}
|
|
@@ -17,8 +17,10 @@ import fs from 'fs/promises';
|
|
|
17
17
|
import Table from 'cli-table3';
|
|
18
18
|
import { run } from '../../core/shell.js';
|
|
19
19
|
import { loadConfig } from '../../core/config.js';
|
|
20
|
-
import { getDomains, saveDomains, findDomain, createDomain, DOMAIN_DEFAULTS } from '../../
|
|
21
|
-
import {
|
|
20
|
+
import { getDomains, saveDomains, findDomain, createDomain, DOMAIN_DEFAULTS } from '../../core/domains-db.js';
|
|
21
|
+
import { getDefaultCertPaths } from '../../core/nginx-conf-generator.js';
|
|
22
|
+
import { writeConfWithTest, findBackslashCertPaths } from '../../core/nginx-apply.js';
|
|
23
|
+
import { prepareDomainForHttpChallenge, describeIssuance } from '../../core/ssl-issuer.js';
|
|
22
24
|
import { issueCert } from './ssl-manager.js';
|
|
23
25
|
import { isWindows, nginxTestCmd, nginxReloadCmd, combineOutput, isNginxTestOk } from '../../core/platform.js';
|
|
24
26
|
|
|
@@ -69,6 +71,19 @@ async function listDomainsAction() {
|
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
console.log('\n' + table.toString() + '\n');
|
|
74
|
+
|
|
75
|
+
// Report-only: existing configs are never rewritten automatically.
|
|
76
|
+
if (isWindows) {
|
|
77
|
+
const affected = findBackslashCertPaths(domains);
|
|
78
|
+
if (affected.length > 0) {
|
|
79
|
+
console.log(chalk.yellow(' ⚠ These domains still have backslash certificate paths:'));
|
|
80
|
+
for (const d of affected) console.log(chalk.gray(` ${d.name} ${d.certPath}`));
|
|
81
|
+
console.log(chalk.gray(
|
|
82
|
+
' nginx can read \\n and \\t in those paths as escape sequences.\n' +
|
|
83
|
+
' Edit and save a domain to regenerate it with forward slashes.\n'
|
|
84
|
+
));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
72
87
|
}
|
|
73
88
|
|
|
74
89
|
// ─── Add Domain ───────────────────────────────────────────────────────
|
|
@@ -127,14 +142,12 @@ async function addDomainAction() {
|
|
|
127
142
|
let ssl = { ...DOMAIN_DEFAULTS.ssl, enabled: sslAnswers.enabled };
|
|
128
143
|
|
|
129
144
|
if (ssl.enabled) {
|
|
130
|
-
const {
|
|
145
|
+
const { sslDir } = loadConfig();
|
|
131
146
|
const platform = isWindows ? 'win32' : 'linux';
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
? `C:\\easy-devops\\ssl\\${basic.name}\\privkey.pem`
|
|
137
|
-
: `${sslDir}/${basic.name}/privkey.pem`;
|
|
147
|
+
// Shared helper: honours sslDir and always suggests forward slashes, which
|
|
148
|
+
// is the form nginx needs on Windows.
|
|
149
|
+
const { certPath: defaultCertPath, keyPath: defaultKeyPath } =
|
|
150
|
+
getDefaultCertPaths(basic.name, platform, sslDir);
|
|
138
151
|
|
|
139
152
|
const sslDetails = await inquirer.prompt([
|
|
140
153
|
{ type: 'input', name: 'certPath', message: 'SSL cert path:', default: defaultCertPath },
|
|
@@ -191,6 +204,32 @@ async function addDomainAction() {
|
|
|
191
204
|
|
|
192
205
|
if (certAction === 'Create certificate now') {
|
|
193
206
|
const spinner = ora(`Creating certificate for ${basic.name}…`).start();
|
|
207
|
+
// Flow 2: nginx must be able to answer the challenge before we ask
|
|
208
|
+
// Let's Encrypt for anything. For a brand-new domain that means
|
|
209
|
+
// writing an HTTP-only config first (there is no certificate yet, so a
|
|
210
|
+
// 443 block would fail nginx -t), testing it and reloading.
|
|
211
|
+
if (!basic.wildcard) {
|
|
212
|
+
const prep = await prepareDomainForHttpChallenge({
|
|
213
|
+
name: basic.name,
|
|
214
|
+
port: basic.port,
|
|
215
|
+
backendHost: basic.backendHost,
|
|
216
|
+
upstreamType: basic.upstreamType,
|
|
217
|
+
www: basic.www,
|
|
218
|
+
wildcard: basic.wildcard,
|
|
219
|
+
ssl: { ...ssl, enabled: false },
|
|
220
|
+
});
|
|
221
|
+
if (prep.regenerated) {
|
|
222
|
+
spinner.stop();
|
|
223
|
+
console.log(chalk.gray(` ${prep.reason}`));
|
|
224
|
+
spinner.start(`Creating certificate for ${basic.name}...`);
|
|
225
|
+
}
|
|
226
|
+
if (!prep.ok) {
|
|
227
|
+
spinner.fail('Could not prepare nginx for the challenge');
|
|
228
|
+
console.log(chalk.yellow(` ${prep.error}`));
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
194
233
|
const result = await issueCert(basic.name, { www: basic.www, wildcard: basic.wildcard, validationMethod: basic.wildcard ? 'dns' : 'http' });
|
|
195
234
|
spinner.stop();
|
|
196
235
|
|
|
@@ -287,27 +326,16 @@ async function addDomainAction() {
|
|
|
287
326
|
advanced,
|
|
288
327
|
});
|
|
289
328
|
|
|
290
|
-
// Generate conf and test
|
|
329
|
+
// Generate conf and test through the shared core apply (same code path the
|
|
330
|
+
// dashboard and the Hub use, including the Windows cert-path retry).
|
|
291
331
|
const spinner = ora('Generating nginx config...').start();
|
|
292
|
-
const { nginxDir } = loadConfig();
|
|
293
332
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
} catch (err) {
|
|
297
|
-
spinner.fail('Failed to generate config');
|
|
298
|
-
console.log(chalk.red(err.message));
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
spinner.text = 'Testing config...';
|
|
303
|
-
const testCmd = isWindows ? nginxTestCmd(nginxDir) : 'nginx -t';
|
|
304
|
-
const testResult = await run(testCmd, { cwd: nginxDir });
|
|
333
|
+
spinner.text = 'Writing and testing config...';
|
|
334
|
+
const applied = await writeConfWithTest(domain);
|
|
305
335
|
|
|
306
|
-
if (!
|
|
336
|
+
if (!applied.ok) {
|
|
307
337
|
spinner.fail('Config test failed');
|
|
308
|
-
console.log(chalk.red('\n' +
|
|
309
|
-
// Clean up failed config
|
|
310
|
-
try { await import('fs/promises').then(fs => fs.unlink(domain.configFile)); } catch { /* ignore */ }
|
|
338
|
+
console.log(chalk.red('\n' + applied.error));
|
|
311
339
|
return;
|
|
312
340
|
}
|
|
313
341
|
|
|
@@ -365,24 +393,16 @@ async function editDomainAction() {
|
|
|
365
393
|
domain.www = updates.www;
|
|
366
394
|
domain.ssl.enabled = updates.sslEnabled;
|
|
367
395
|
|
|
368
|
-
// Regenerate config
|
|
396
|
+
// Regenerate config through the shared core apply. On failure the previous
|
|
397
|
+
// config content is restored exactly, so a bad edit cannot leave a broken file.
|
|
369
398
|
const spinner = ora('Regenerating config...').start();
|
|
370
|
-
const { nginxDir } = loadConfig();
|
|
371
399
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
} catch (err) {
|
|
375
|
-
spinner.fail('Failed to generate config');
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
spinner.text = 'Testing config...';
|
|
380
|
-
const testCmd = isWindows ? nginxTestCmd(nginxDir) : 'nginx -t';
|
|
381
|
-
const testResult = await run(testCmd, { cwd: nginxDir });
|
|
400
|
+
spinner.text = 'Writing and testing config...';
|
|
401
|
+
const applied = await writeConfWithTest(domain);
|
|
382
402
|
|
|
383
|
-
if (!
|
|
403
|
+
if (!applied.ok) {
|
|
384
404
|
spinner.fail('Config test failed');
|
|
385
|
-
console.log(chalk.red('\n' +
|
|
405
|
+
console.log(chalk.red('\n' + applied.error));
|
|
386
406
|
return;
|
|
387
407
|
}
|
|
388
408
|
|