easy-devops 0.2.6 โ 1.0.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 +87 -44
- package/cli/index.js +27 -5
- package/cli/managers/domain-manager.js +204 -34
- package/cli/managers/nginx-manager.js +60 -20
- package/cli/managers/ssl-manager.js +441 -579
- package/cli/menus/settings.js +27 -8
- package/core/config.js +5 -2
- package/core/detector.js +50 -87
- package/core/nginx-conf-generator.js +100 -63
- package/core/platform.js +61 -0
- package/core/shell.js +2 -2
- package/core/validators.js +96 -0
- package/dashboard/lib/cert-reader.js +5 -5
- package/dashboard/lib/nginx-service.js +47 -77
- package/dashboard/public/img/icon.png +0 -0
- package/dashboard/public/img/icon_b.png +0 -0
- package/dashboard/public/js/app.js +257 -20
- package/dashboard/routes/domains.js +110 -72
- package/dashboard/routes/settings.js +19 -11
- package/dashboard/routes/ssl.js +235 -59
- package/dashboard/views/index.ejs +481 -260
- package/dashboard/views/partials/domain-form.ejs +332 -228
- package/dashboard/views/partials/domains-panel.ejs +100 -62
- package/dashboard/views/partials/login.ejs +157 -40
- package/dashboard/views/partials/nginx-panel.ejs +126 -84
- package/dashboard/views/partials/overview.ejs +124 -49
- package/dashboard/views/partials/settings-panel.ejs +66 -35
- package/dashboard/views/partials/sidebar.ejs +84 -33
- package/dashboard/views/partials/ssl-panel.ejs +174 -51
- package/install.sh +8 -9
- package/lib/installer/nvm-bootstrap.sh +8 -8
- package/lib/installer/picker.sh +32 -15
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="dashboard/public/img/icon.png" alt="Easy DevOps" width="100" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
1
5
|
# Easy DevOps
|
|
2
6
|
|
|
3
7
|
[](https://badge.fury.io/js/easy-devops)
|
|
@@ -6,23 +10,25 @@
|
|
|
6
10
|
|
|
7
11
|
A unified DevOps management tool with interactive CLI and web dashboard for managing **Nginx**, **SSL certificates**, and **Node.js** on Linux and Windows servers.
|
|
8
12
|
|
|
13
|
+
No external ACME binaries required โ SSL certificates are issued via [`acme-client`](https://www.npmjs.com/package/acme-client) (pure Node.js, Let's Encrypt).
|
|
14
|
+
|
|
9
15
|
## Features
|
|
10
16
|
|
|
11
17
|
- **๐ฅ๏ธ Interactive CLI** โ Arrow-key menus with real-time status indicators
|
|
12
|
-
- **๐ Web Dashboard** โ Modern Vue 3 interface with dark/light themes
|
|
13
|
-
- **๐ Nginx Management** โ Start/stop/reload, config editor, error logs
|
|
14
|
-
- **๐ SSL Certificate Management** โ Let's Encrypt via
|
|
15
|
-
- **๐ Domain Management** โ Reverse proxy
|
|
16
|
-
- **๐ฆ Node.js Manager** โ Version switching via nvm, global package management
|
|
18
|
+
- **๐ Web Dashboard** โ Modern Vue 3 interface with dark/light themes (`#161616` / `#d64a29` palette)
|
|
19
|
+
- **๐ Nginx Management** โ Start/stop/reload, config editor, error logs, install
|
|
20
|
+
- **๐ SSL Certificate Management** โ Let's Encrypt via `acme-client` (no certbot), HTTP-01 and DNS-01 challenges, wildcard certs, expiry tracking
|
|
21
|
+
- **๐ Domain Management** โ Reverse proxy configs with SSL, external URL backends, enable/disable, wildcard domains, WebSocket, gzip, rate limiting
|
|
22
|
+
- **๐ฆ Node.js Manager** โ Version switching via nvm / nvm-windows, global package management
|
|
17
23
|
- **๐ Real-time Updates** โ Socket.io powered status updates in dashboard
|
|
18
24
|
- **๐ฟ SQLite Storage** โ Persistent configuration via `good.db`
|
|
19
25
|
|
|
20
26
|
## Requirements
|
|
21
27
|
|
|
22
28
|
- **Node.js 18+** (with npm)
|
|
23
|
-
- **Linux** (Debian/Ubuntu) or **Windows**
|
|
24
|
-
- โ ๏ธ **Windows users: PowerShell must be run as Administrator** (required for
|
|
25
|
-
- Optional: Nginx,
|
|
29
|
+
- **Linux** (Debian/Ubuntu/etc.) or **Windows**
|
|
30
|
+
- โ ๏ธ **Windows users: PowerShell must be run as Administrator** (required for managing services and SSL certificates)
|
|
31
|
+
- Optional: Nginx, nvm (installed separately or via the tool)
|
|
26
32
|
|
|
27
33
|
## Installation
|
|
28
34
|
|
|
@@ -98,11 +104,14 @@ npx easy-devops
|
|
|
98
104
|
### CLI Overview
|
|
99
105
|
|
|
100
106
|
```
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
107
|
+
โโโโโโโโโโโโโโโโ Easy DevOps v1.0.0
|
|
108
|
+
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ
|
|
109
|
+
โโโโโโ โโโโ CLI & Web Dashboard
|
|
110
|
+
โโโโโโ โโโโ Nginx ยท SSL ยท Domains ยท Node.js
|
|
111
|
+
โโโโโโโโ โโโโโโโ
|
|
112
|
+
โโโโโโโโ โโโโโโโ
|
|
104
113
|
|
|
105
|
-
nginx: โ
v1.26.2 |
|
|
114
|
+
nginx: โ
v1.26.2 | ACME: acme-client | node: v22.21.1
|
|
106
115
|
|
|
107
116
|
? Select an option:
|
|
108
117
|
๐ฆ Node.js Manager
|
|
@@ -111,6 +120,7 @@ nginx: โ
v1.26.2 | certbot: โ
v2.9.0 | node: v22.21.1
|
|
|
111
120
|
๐ Domain Manager
|
|
112
121
|
๐๏ธ Open Dashboard
|
|
113
122
|
โ๏ธ Settings
|
|
123
|
+
๐ Check for Updates
|
|
114
124
|
โ Exit
|
|
115
125
|
```
|
|
116
126
|
|
|
@@ -150,13 +160,16 @@ Manage Nginx reverse proxy configurations from CLI or dashboard.
|
|
|
150
160
|
|
|
151
161
|
| Option | Description |
|
|
152
162
|
|--------|-------------|
|
|
153
|
-
| List Domains | Show all configured domains in a table |
|
|
163
|
+
| List Domains | Show all configured domains in a table (with status) |
|
|
154
164
|
| Add Domain | Interactive prompts for domain configuration |
|
|
155
165
|
| Edit Domain | Modify existing domain settings |
|
|
156
|
-
|
|
|
166
|
+
| Enable / Disable Domain | Toggle domain on/off without deleting config |
|
|
167
|
+
| Delete Domain | Remove domain (with option to also delete SSL files) |
|
|
157
168
|
|
|
158
169
|
**Domain Configuration Options:**
|
|
159
|
-
-
|
|
170
|
+
- Backend: local host:port (`127.0.0.1:3000`) or full external URL (`https://app.vercel.app`)
|
|
171
|
+
- Wildcard domain (`*.example.com`) โ auto-enforces DNS-01 SSL validation
|
|
172
|
+
- SSL/HTTPS with certificate management
|
|
160
173
|
- WebSocket support (`ws` upstream type)
|
|
161
174
|
- Gzip compression
|
|
162
175
|
- Rate limiting (requests/second + burst)
|
|
@@ -168,7 +181,7 @@ Manage Nginx reverse proxy configurations from CLI or dashboard.
|
|
|
168
181
|
|
|
169
182
|
### SSL Manager
|
|
170
183
|
|
|
171
|
-
|
|
184
|
+
Issue and renew Let's Encrypt SSL certificates via `acme-client` โ no certbot or external binaries required.
|
|
172
185
|
|
|
173
186
|
| Status | Meaning |
|
|
174
187
|
|--------|---------|
|
|
@@ -176,21 +189,28 @@ Manage Let's Encrypt SSL certificates using Certbot.
|
|
|
176
189
|
| โ ๏ธ yellow | Expiring soon (10โ30 days) |
|
|
177
190
|
| โ red | Critical (< 10 days) |
|
|
178
191
|
|
|
179
|
-
|
|
192
|
+
#### Challenge Methods
|
|
180
193
|
|
|
181
|
-
|
|
194
|
+
| Method | How it works |
|
|
195
|
+
|--------|-------------|
|
|
196
|
+
| **HTTP-01** | Easy DevOps stops nginx, binds port 80, serves the ACME token, then restarts nginx |
|
|
197
|
+
| **DNS-01** | You add a `_acme-challenge` TXT record to your DNS; Easy DevOps waits for confirmation |
|
|
182
198
|
|
|
183
|
-
|
|
199
|
+
> **Wildcard certificates** (`*.example.com`) require DNS-01 โ HTTP-01 is automatically disabled for wildcard domains.
|
|
184
200
|
|
|
185
|
-
|
|
201
|
+
#### Certificate Storage
|
|
186
202
|
|
|
187
|
-
|
|
203
|
+
Certificates are stored under `sslDir` (configured in Settings):
|
|
188
204
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
205
|
+
```
|
|
206
|
+
{sslDir}/{domain}/fullchain.pem
|
|
207
|
+
{sslDir}/{domain}/privkey.pem
|
|
208
|
+
{sslDir}/.account/account.key โ ACME account key, reused across all issuances
|
|
209
|
+
```
|
|
192
210
|
|
|
193
|
-
|
|
211
|
+
Default paths:
|
|
212
|
+
- Linux: `/etc/easy-devops/ssl/`
|
|
213
|
+
- Windows: `C:\easy-devops\ssl\`
|
|
194
214
|
|
|
195
215
|
---
|
|
196
216
|
|
|
@@ -239,8 +259,12 @@ The dashboard exposes RESTful API endpoints:
|
|
|
239
259
|
| `/api/nginx/configs` | GET | List config files |
|
|
240
260
|
| `/api/nginx/config/:file` | GET/POST | Read/write config file |
|
|
241
261
|
| `/api/domains` | GET/POST | List/create domains |
|
|
242
|
-
| `/api/domains/:name` |
|
|
262
|
+
| `/api/domains/:name` | PUT/DELETE | Update/delete domain |
|
|
263
|
+
| `/api/domains/:name/toggle` | PUT | Enable or disable domain |
|
|
264
|
+
| `/api/domains/:name/reload` | POST | Reload nginx for domain |
|
|
243
265
|
| `/api/ssl` | GET | List certificates |
|
|
266
|
+
| `/api/ssl/create` | POST | Issue new certificate |
|
|
267
|
+
| `/api/ssl/create-confirm` | POST | Confirm DNS challenge |
|
|
244
268
|
| `/api/ssl/renew/:domain` | POST | Renew certificate |
|
|
245
269
|
| `/api/settings` | GET/POST | Dashboard settings |
|
|
246
270
|
|
|
@@ -252,10 +276,20 @@ All configuration is stored in `data/easy-devops.sqlite`:
|
|
|
252
276
|
|
|
253
277
|
| Key | Contents |
|
|
254
278
|
|-----|----------|
|
|
255
|
-
| `config` | Dashboard port, password,
|
|
256
|
-
| `system-detection` | Cached system info (OS, Node, nginx
|
|
279
|
+
| `config` | Dashboard port, password, `nginxDir`, `sslDir`, `acmeEmail` |
|
|
280
|
+
| `system-detection` | Cached system info (OS, Node, nginx) |
|
|
257
281
|
| `domains` | Array of domain configurations |
|
|
258
282
|
|
|
283
|
+
**Config fields:**
|
|
284
|
+
|
|
285
|
+
| Field | Default (Linux) | Default (Windows) | Description |
|
|
286
|
+
|-------|-----------------|-------------------|-------------|
|
|
287
|
+
| `dashboardPort` | `3000` | `3000` | Dashboard HTTP port |
|
|
288
|
+
| `dashboardPassword` | `admin` | `admin` | Dashboard login password |
|
|
289
|
+
| `nginxDir` | `/etc/nginx` | `C:\nginx` | Nginx installation directory |
|
|
290
|
+
| `sslDir` | `/etc/easy-devops/ssl` | `C:\easy-devops\ssl` | SSL certificate storage root |
|
|
291
|
+
| `acmeEmail` | _(empty)_ | _(empty)_ | Email for Let's Encrypt account (**required** for cert issuance) |
|
|
292
|
+
|
|
259
293
|
---
|
|
260
294
|
|
|
261
295
|
## Project Structure
|
|
@@ -264,27 +298,28 @@ All configuration is stored in `data/easy-devops.sqlite`:
|
|
|
264
298
|
easy-devops/
|
|
265
299
|
โโโ cli/
|
|
266
300
|
โ โโโ index.js # CLI entry point
|
|
267
|
-
โ โโโ managers/ #
|
|
268
|
-
โ โโโ menus/ #
|
|
301
|
+
โ โโโ managers/ # Domain, Nginx, SSL, Node.js logic
|
|
302
|
+
โ โโโ menus/ # Thin menu dispatcher wrappers
|
|
269
303
|
โโโ core/
|
|
270
|
-
โ โโโ config.js # Configuration
|
|
271
|
-
โ โโโ db.js # SQLite
|
|
304
|
+
โ โโโ config.js # Configuration load/save
|
|
305
|
+
โ โโโ db.js # SQLite helpers (good.db)
|
|
272
306
|
โ โโโ detector.js # System environment detection
|
|
307
|
+
โ โโโ nginx-conf-generator.js # Nginx conf builder (shared)
|
|
308
|
+
โ โโโ platform.js # isWindows, nginx cmd helpers, combineOutput
|
|
273
309
|
โ โโโ shell.js # Cross-platform shell executor
|
|
274
|
-
โ โโโ
|
|
310
|
+
โ โโโ validators.js # Shared input validation helpers
|
|
275
311
|
โโโ dashboard/
|
|
276
312
|
โ โโโ server.js # Express + Socket.io server
|
|
277
|
-
โ โโโ routes/ #
|
|
278
|
-
โ โโโ lib/ #
|
|
279
|
-
โ โโโ views/ # EJS templates
|
|
280
|
-
โ โโโ public/ # Static assets (Vue app)
|
|
313
|
+
โ โโโ routes/ # auth, domains, nginx, settings, ssl
|
|
314
|
+
โ โโโ lib/ # cert-reader, domains-db, nginx-service
|
|
315
|
+
โ โโโ views/ # EJS templates + partials
|
|
316
|
+
โ โโโ public/ # Static assets (Vue 3 app)
|
|
281
317
|
โโโ data/
|
|
282
318
|
โ โโโ easy-devops.sqlite
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
โโโ winget-install.ps1 # Windows Package Manager installer
|
|
319
|
+
โโโ lib/
|
|
320
|
+
โ โโโ installer/ # Bash helper modules for install.sh
|
|
321
|
+
โโโ install.sh # Linux/macOS bootstrap installer
|
|
322
|
+
โโโ install.ps1 # Windows PowerShell installer
|
|
288
323
|
```
|
|
289
324
|
|
|
290
325
|
---
|
|
@@ -296,9 +331,11 @@ easy-devops/
|
|
|
296
331
|
| CLI Interface | โ
| โ
|
|
|
297
332
|
| Web Dashboard | โ
| โ
|
|
|
298
333
|
| Nginx Management | โ
| โ
|
|
|
299
|
-
| SSL (
|
|
334
|
+
| SSL โ HTTP-01 (acme-client) | โ
| โ
|
|
|
335
|
+
| SSL โ DNS-01 (acme-client) | โ
| โ
|
|
|
336
|
+
| Wildcard Certificates | โ
| โ
|
|
|
300
337
|
| Node.js (nvm) | โ
| โ
(nvm-windows) |
|
|
301
|
-
|
|
|
338
|
+
| Nginx service control | systemctl | nginx.exe direct |
|
|
302
339
|
|
|
303
340
|
---
|
|
304
341
|
|
|
@@ -334,6 +371,12 @@ Contributions are welcome! Please feel free to submit a Pull Request.
|
|
|
334
371
|
|
|
335
372
|
---
|
|
336
373
|
|
|
374
|
+
## Changelog
|
|
375
|
+
|
|
376
|
+
See [CHANGELOG.md](./CHANGELOG.md) for a full history of changes.
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
337
380
|
## License
|
|
338
381
|
|
|
339
382
|
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
package/cli/index.js
CHANGED
|
@@ -25,11 +25,33 @@ if (process.argv[2] === 'system-info') {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
function renderBanner() {
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
const c = chalk.hex('#d64a29');
|
|
29
|
+
const dim = chalk.hex('#d64a29').dim;
|
|
30
|
+
|
|
31
|
+
// Compact "EZ" logo โ 6 lines, ~20 chars wide, fits any 80-col terminal
|
|
32
|
+
const logo = [
|
|
33
|
+
'โโโโโโโโโโโโโโโโ',
|
|
34
|
+
'โโโโโโโโโโโโโโโโ',
|
|
35
|
+
'โโโโโโ โโโโ',
|
|
36
|
+
'โโโโโโ โโโโ ',
|
|
37
|
+
'โโโโโโโโ โโโโโโโ',
|
|
38
|
+
'โโโโโโโโ โโโโโโโ',
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
const gap = ' ';
|
|
42
|
+
const info = [
|
|
43
|
+
chalk.bold.white('Easy DevOps') + ' ' + chalk.hex('#d64a29')(`v${version}`),
|
|
44
|
+
dim('โโโโโโโโโโโโโโโโโโโโโ'),
|
|
45
|
+
chalk.hex('#888888')('CLI & Web Dashboard'),
|
|
46
|
+
chalk.hex('#888888')('Nginx ยท SSL ยท Domains ยท Node.js'),
|
|
47
|
+
'',
|
|
48
|
+
'',
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
console.log();
|
|
52
|
+
logo.forEach((line, i) => {
|
|
53
|
+
console.log(' ' + c(line) + gap + (info[i] ?? ''));
|
|
54
|
+
});
|
|
33
55
|
console.log();
|
|
34
56
|
}
|
|
35
57
|
|
|
@@ -13,33 +13,14 @@
|
|
|
13
13
|
import chalk from 'chalk';
|
|
14
14
|
import inquirer from 'inquirer';
|
|
15
15
|
import ora from 'ora';
|
|
16
|
+
import fs from 'fs/promises';
|
|
16
17
|
import Table from 'cli-table3';
|
|
17
18
|
import { run } from '../../core/shell.js';
|
|
18
19
|
import { loadConfig } from '../../core/config.js';
|
|
19
20
|
import { getDomains, saveDomains, findDomain, createDomain, DOMAIN_DEFAULTS } from '../../dashboard/lib/domains-db.js';
|
|
20
21
|
import { generateConf, buildConf } from '../../core/nginx-conf-generator.js';
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// โโโ Helper functions โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
25
|
-
|
|
26
|
-
function getNginxExe(nginxDir) {
|
|
27
|
-
return isWindows ? `${nginxDir}\\nginx.exe` : 'nginx';
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function nginxTestCmd(nginxDir) {
|
|
31
|
-
const exe = getNginxExe(nginxDir);
|
|
32
|
-
return isWindows ? `& "${exe}" -t` : 'nginx -t';
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function nginxReloadCmd(nginxDir) {
|
|
36
|
-
const exe = getNginxExe(nginxDir);
|
|
37
|
-
return isWindows ? `& "${exe}" -s reload` : 'nginx -s reload';
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function combineOutput(result) {
|
|
41
|
-
return [result.stdout, result.stderr].filter(Boolean).join('\n').trim();
|
|
42
|
-
}
|
|
22
|
+
import { issueCert } from './ssl-manager.js';
|
|
23
|
+
import { isWindows, nginxTestCmd, nginxReloadCmd, combineOutput } from '../../core/platform.js';
|
|
43
24
|
|
|
44
25
|
// โโโ List Domains โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
45
26
|
|
|
@@ -54,13 +35,14 @@ async function listDomainsAction() {
|
|
|
54
35
|
const table = new Table({
|
|
55
36
|
head: [
|
|
56
37
|
chalk.cyan('Domain'),
|
|
57
|
-
chalk.cyan('
|
|
38
|
+
chalk.cyan('Backend'),
|
|
58
39
|
chalk.cyan('Type'),
|
|
59
40
|
chalk.cyan('SSL'),
|
|
41
|
+
chalk.cyan('Status'),
|
|
60
42
|
chalk.cyan('Cert'),
|
|
61
43
|
],
|
|
62
44
|
style: { head: [], border: ['gray'] },
|
|
63
|
-
colWidths: [
|
|
45
|
+
colWidths: [28, 20, 8, 8, 10, 8],
|
|
64
46
|
});
|
|
65
47
|
|
|
66
48
|
for (const d of domains) {
|
|
@@ -70,11 +52,18 @@ async function listDomainsAction() {
|
|
|
70
52
|
? (d.daysLeft > 30 ? chalk.green(`${d.daysLeft}d`) : chalk.yellow(`${d.daysLeft}d`))
|
|
71
53
|
: chalk.gray('โ');
|
|
72
54
|
|
|
55
|
+
const backend = /^https?:\/\//i.test(d.backendHost || '')
|
|
56
|
+
? d.backendHost.replace(/^https?:\/\//, '')
|
|
57
|
+
: `${d.backendHost || '127.0.0.1'}:${d.port}`;
|
|
58
|
+
const status = d.enabled === false
|
|
59
|
+
? chalk.gray('DISABLED')
|
|
60
|
+
: (d.wildcard ? chalk.blue('WILDCARD') : chalk.green('active'));
|
|
73
61
|
table.push([
|
|
74
62
|
d.name,
|
|
75
|
-
|
|
63
|
+
backend,
|
|
76
64
|
type,
|
|
77
65
|
sslStatus,
|
|
66
|
+
status,
|
|
78
67
|
certDays,
|
|
79
68
|
]);
|
|
80
69
|
}
|
|
@@ -89,14 +78,39 @@ async function addDomainAction() {
|
|
|
89
78
|
|
|
90
79
|
// Section 1: Basic
|
|
91
80
|
const basic = await inquirer.prompt([
|
|
92
|
-
{ type: '
|
|
93
|
-
{
|
|
94
|
-
|
|
81
|
+
{ type: 'confirm', name: 'wildcard', message: 'Wildcard domain (*.example.com)?', default: false },
|
|
82
|
+
{
|
|
83
|
+
type: 'input', name: 'name',
|
|
84
|
+
message: (ans) => ans.wildcard
|
|
85
|
+
? 'Domain name (without *. prefix โ it will be added automatically):'
|
|
86
|
+
: 'Domain name:',
|
|
87
|
+
validate: (v) => {
|
|
88
|
+
const bare = v.trim().startsWith('*.') ? v.trim().slice(2) : v.trim();
|
|
89
|
+
if (!bare) return 'Required';
|
|
90
|
+
const labelPattern = /^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$/;
|
|
91
|
+
const labels = bare.split('.');
|
|
92
|
+
if (labels.length < 2) return 'Must have at least two labels (e.g. example.com)';
|
|
93
|
+
for (const label of labels) {
|
|
94
|
+
if (!label || !labelPattern.test(label)) return 'Invalid domain name format';
|
|
95
|
+
}
|
|
96
|
+
return true;
|
|
97
|
+
},
|
|
98
|
+
filter: (v) => v.trim().startsWith('*.') ? v.trim().slice(2) : v.trim(),
|
|
99
|
+
},
|
|
100
|
+
{ type: 'input', name: 'backendHost', message: 'Backend host or full URL:', default: '127.0.0.1' },
|
|
101
|
+
{
|
|
102
|
+
type: 'number', name: 'port', message: 'Backend port (ignored for full URLs):', default: 3000,
|
|
103
|
+
validate: (v) => (v >= 1 && v <= 65535) ? true : 'Port must be 1-65535',
|
|
104
|
+
when: (ans) => !/^https?:\/\//i.test(ans.backendHost),
|
|
105
|
+
},
|
|
95
106
|
{
|
|
96
107
|
type: 'list', name: 'upstreamType', message: 'Upstream type:', default: 'http',
|
|
97
108
|
choices: ['http', 'https', 'ws'],
|
|
98
109
|
},
|
|
99
|
-
{
|
|
110
|
+
{
|
|
111
|
+
type: 'confirm', name: 'www', message: 'Include www subdomain?', default: false,
|
|
112
|
+
when: (ans) => !ans.wildcard,
|
|
113
|
+
},
|
|
100
114
|
]);
|
|
101
115
|
|
|
102
116
|
// Check for duplicate
|
|
@@ -113,14 +127,14 @@ async function addDomainAction() {
|
|
|
113
127
|
let ssl = { ...DOMAIN_DEFAULTS.ssl, enabled: sslAnswers.enabled };
|
|
114
128
|
|
|
115
129
|
if (ssl.enabled) {
|
|
116
|
-
const { nginxDir,
|
|
130
|
+
const { nginxDir, sslDir } = loadConfig();
|
|
117
131
|
const platform = isWindows ? 'win32' : 'linux';
|
|
118
132
|
const defaultCertPath = platform === 'win32'
|
|
119
|
-
? `C:\\
|
|
120
|
-
: `${
|
|
133
|
+
? `C:\\easy-devops\\ssl\\${basic.name}\\fullchain.pem`
|
|
134
|
+
: `${sslDir}/${basic.name}/fullchain.pem`;
|
|
121
135
|
const defaultKeyPath = platform === 'win32'
|
|
122
|
-
? `C:\\
|
|
123
|
-
: `${
|
|
136
|
+
? `C:\\easy-devops\\ssl\\${basic.name}\\privkey.pem`
|
|
137
|
+
: `${sslDir}/${basic.name}/privkey.pem`;
|
|
124
138
|
|
|
125
139
|
const sslDetails = await inquirer.prompt([
|
|
126
140
|
{ type: 'input', name: 'certPath', message: 'SSL cert path:', default: defaultCertPath },
|
|
@@ -139,6 +153,66 @@ async function addDomainAction() {
|
|
|
139
153
|
ssl = { ...ssl, ...sslDetails };
|
|
140
154
|
}
|
|
141
155
|
|
|
156
|
+
// Cert existence check (FR-001, FR-002)
|
|
157
|
+
if (ssl.enabled) {
|
|
158
|
+
let certExists = false;
|
|
159
|
+
try {
|
|
160
|
+
await fs.access(ssl.certPath, fs.constants.F_OK);
|
|
161
|
+
certExists = true;
|
|
162
|
+
} catch {
|
|
163
|
+
certExists = false;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (!certExists) {
|
|
167
|
+
console.log(chalk.yellow(`\n โ Certificate not found at: ${ssl.certPath}`));
|
|
168
|
+
|
|
169
|
+
let certAction;
|
|
170
|
+
try {
|
|
171
|
+
({ certAction } = await inquirer.prompt([{
|
|
172
|
+
type: 'list',
|
|
173
|
+
name: 'certAction',
|
|
174
|
+
message: 'What would you like to do?',
|
|
175
|
+
choices: ['Create certificate now', 'Disable SSL', 'Cancel'],
|
|
176
|
+
}]));
|
|
177
|
+
} catch (err) {
|
|
178
|
+
if (err.name === 'ExitPromptError') return;
|
|
179
|
+
throw err;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (certAction === 'Cancel') {
|
|
183
|
+
console.log(chalk.gray('\n Cancelled.\n'));
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (certAction === 'Disable SSL') {
|
|
188
|
+
ssl.enabled = false;
|
|
189
|
+
console.log(chalk.gray(' SSL disabled. Domain will be saved as HTTP-only.\n'));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (certAction === 'Create certificate now') {
|
|
193
|
+
const spinner = ora(`Creating certificate for ${basic.name}โฆ`).start();
|
|
194
|
+
const result = await issueCert(basic.name, { www: basic.www, wildcard: basic.wildcard, validationMethod: basic.wildcard ? 'dns' : 'http' });
|
|
195
|
+
spinner.stop();
|
|
196
|
+
|
|
197
|
+
if (result.success) {
|
|
198
|
+
console.log(chalk.green('\n โ Certificate created successfully'));
|
|
199
|
+
console.log(chalk.gray(` Cert: ${result.certPath}`));
|
|
200
|
+
console.log(chalk.gray(` Key: ${result.keyPath}\n`));
|
|
201
|
+
ssl.certPath = result.certPath;
|
|
202
|
+
ssl.keyPath = result.keyPath;
|
|
203
|
+
} else {
|
|
204
|
+
const e = result.error;
|
|
205
|
+
console.log(chalk.red('\n โ Certificate creation failed โ domain was not saved'));
|
|
206
|
+
console.log(chalk.yellow(` Step: ${e.step}`));
|
|
207
|
+
console.log(chalk.yellow(` Cause: ${e.cause}`));
|
|
208
|
+
console.log(chalk.yellow(` Consequence: ${e.consequence}`));
|
|
209
|
+
console.log(chalk.gray(` nginx running: ${e.nginxRunning ? 'yes' : 'no'}\n`));
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
142
216
|
// Section 3: Proxy Behavior
|
|
143
217
|
const proxy = await inquirer.prompt([
|
|
144
218
|
{ type: 'input', name: 'maxBodySize', message: 'Max body size:', default: '10m' },
|
|
@@ -206,6 +280,7 @@ async function addDomainAction() {
|
|
|
206
280
|
backendHost: basic.backendHost,
|
|
207
281
|
upstreamType: basic.upstreamType,
|
|
208
282
|
www: basic.www,
|
|
283
|
+
wildcard: basic.wildcard,
|
|
209
284
|
ssl,
|
|
210
285
|
performance,
|
|
211
286
|
security,
|
|
@@ -394,6 +469,97 @@ async function reloadNginxAfterChange() {
|
|
|
394
469
|
return true;
|
|
395
470
|
}
|
|
396
471
|
|
|
472
|
+
// โโโ Toggle Domain (Enable/Disable) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
473
|
+
|
|
474
|
+
async function toggleDomainAction() {
|
|
475
|
+
const domains = getDomains();
|
|
476
|
+
|
|
477
|
+
if (domains.length === 0) {
|
|
478
|
+
console.log(chalk.yellow('\n No domains configured.\n'));
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
const { selectedName } = await inquirer.prompt([{
|
|
483
|
+
type: 'list',
|
|
484
|
+
name: 'selectedName',
|
|
485
|
+
message: 'Select domain to enable/disable:',
|
|
486
|
+
choices: domains.map(d => {
|
|
487
|
+
const status = d.enabled === false ? chalk.gray('[DISABLED]') : chalk.green('[active]');
|
|
488
|
+
return { name: `${d.name} ${status}`, value: d.name };
|
|
489
|
+
}),
|
|
490
|
+
}]);
|
|
491
|
+
|
|
492
|
+
const domain = findDomain(selectedName);
|
|
493
|
+
if (!domain) return;
|
|
494
|
+
|
|
495
|
+
const isEnabled = domain.enabled !== false;
|
|
496
|
+
const action = isEnabled ? 'disable' : 'enable';
|
|
497
|
+
|
|
498
|
+
const { confirmed } = await inquirer.prompt([{
|
|
499
|
+
type: 'confirm',
|
|
500
|
+
name: 'confirmed',
|
|
501
|
+
message: `${action.charAt(0).toUpperCase() + action.slice(1)} "${selectedName}"?`,
|
|
502
|
+
default: false,
|
|
503
|
+
}]);
|
|
504
|
+
|
|
505
|
+
if (!confirmed) {
|
|
506
|
+
console.log(chalk.gray('\n Cancelled.\n'));
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
const { nginxDir } = loadConfig();
|
|
511
|
+
const confPath = domain.configFile;
|
|
512
|
+
|
|
513
|
+
if (!confPath) {
|
|
514
|
+
console.log(chalk.red('\n No config file path stored for this domain.\n'));
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
const basePath = confPath.replace(/\.disabled$/, '');
|
|
519
|
+
const enabledPath = basePath;
|
|
520
|
+
const disabledPath = `${basePath}.disabled`;
|
|
521
|
+
const spinner = ora(`${action.charAt(0).toUpperCase() + action.slice(1)}ing domain...`).start();
|
|
522
|
+
|
|
523
|
+
try {
|
|
524
|
+
if (isEnabled) {
|
|
525
|
+
await fs.rename(enabledPath, disabledPath);
|
|
526
|
+
} else {
|
|
527
|
+
await fs.rename(disabledPath, enabledPath);
|
|
528
|
+
// Test config before reload
|
|
529
|
+
const testResult = await run(nginxTestCmd(nginxDir), { cwd: nginxDir });
|
|
530
|
+
if (!testResult.success) {
|
|
531
|
+
await fs.rename(enabledPath, disabledPath).catch(() => {});
|
|
532
|
+
spinner.fail('Config test failed โ rolled back');
|
|
533
|
+
console.log(chalk.red('\n' + combineOutput(testResult)));
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// Update DB
|
|
539
|
+
const allDomains = getDomains();
|
|
540
|
+
const idx = allDomains.findIndex(d => d.name === selectedName);
|
|
541
|
+
allDomains[idx] = {
|
|
542
|
+
...domain,
|
|
543
|
+
enabled: !isEnabled,
|
|
544
|
+
configFile: isEnabled ? disabledPath : enabledPath,
|
|
545
|
+
updatedAt: new Date().toISOString(),
|
|
546
|
+
};
|
|
547
|
+
saveDomains(allDomains);
|
|
548
|
+
|
|
549
|
+
// Reload nginx
|
|
550
|
+
const reloadResult = await run(nginxReloadCmd(nginxDir), { cwd: nginxDir });
|
|
551
|
+
if (!reloadResult.success) {
|
|
552
|
+
spinner.warn(`Domain ${action}d but nginx reload failed`);
|
|
553
|
+
console.log(chalk.yellow('\n' + combineOutput(reloadResult)));
|
|
554
|
+
} else {
|
|
555
|
+
spinner.succeed(`Domain "${selectedName}" ${action}d`);
|
|
556
|
+
}
|
|
557
|
+
} catch (err) {
|
|
558
|
+
spinner.fail(`Failed to ${action} domain`);
|
|
559
|
+
console.log(chalk.red(err.message));
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
397
563
|
// โโโ Main Menu (T026, T029-T033) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
398
564
|
|
|
399
565
|
export async function showDomainManager() {
|
|
@@ -409,6 +575,7 @@ export async function showDomainManager() {
|
|
|
409
575
|
'List Domains',
|
|
410
576
|
'Add Domain',
|
|
411
577
|
'Edit Domain',
|
|
578
|
+
'Enable / Disable Domain',
|
|
412
579
|
'Delete Domain',
|
|
413
580
|
new inquirer.Separator(),
|
|
414
581
|
'โ Back',
|
|
@@ -437,6 +604,9 @@ export async function showDomainManager() {
|
|
|
437
604
|
case 'Edit Domain':
|
|
438
605
|
await editDomainAction();
|
|
439
606
|
break;
|
|
607
|
+
case 'Enable / Disable Domain':
|
|
608
|
+
await toggleDomainAction();
|
|
609
|
+
break;
|
|
440
610
|
case 'Delete Domain':
|
|
441
611
|
await deleteDomainAction();
|
|
442
612
|
break;
|