easy-devops 1.2.0 → 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.
Files changed (132) hide show
  1. package/README.md +97 -6
  2. package/dist/ui/assets/index-B6zdwEnG.css +1 -0
  3. package/dist/ui/assets/index-Cy0oNmul.js +442 -0
  4. package/dist/ui/assets/socket-DwLPrgsr.js +1 -0
  5. package/dist/ui/assets/socket-K5ttLD2q.js +65 -0
  6. package/dist/ui/brand/apple-touch-icon.png +0 -0
  7. package/dist/ui/brand/favicon-16.png +0 -0
  8. package/dist/ui/brand/favicon-32.png +0 -0
  9. package/dist/ui/brand/favicon-light-16.png +0 -0
  10. package/dist/ui/brand/favicon-light-32.png +0 -0
  11. package/dist/ui/brand/favicon.ico +0 -0
  12. package/dist/ui/brand/icon-192.png +0 -0
  13. package/dist/ui/brand/icon-48.png +0 -0
  14. package/dist/ui/brand/icon-512.png +0 -0
  15. package/dist/ui/brand/icon-64-light.png +0 -0
  16. package/dist/ui/brand/icon-64.png +0 -0
  17. package/dist/ui/brand/logo-dark.png +0 -0
  18. package/dist/ui/brand/logo-light.png +0 -0
  19. package/dist/ui/brand/mark-dark.png +0 -0
  20. package/dist/ui/brand/mark-light.png +0 -0
  21. package/dist/ui/index.html +71 -0
  22. package/install.ps1 +188 -1
  23. package/install.sh +254 -29
  24. package/package.json +17 -5
  25. package/src/cli/dash.js +110 -0
  26. package/src/cli/index.js +237 -106
  27. package/src/cli/managers/domain-manager.js +60 -40
  28. package/src/cli/managers/ssl-manager.js +47 -330
  29. package/src/cli/menu.js +156 -0
  30. package/src/cli/menus/cleanup.js +205 -0
  31. package/src/cli/menus/dashboard.js +93 -2
  32. package/src/cli/menus/runtime.js +236 -0
  33. package/src/cli/menus/service.js +764 -0
  34. package/src/cli/menus/settings.js +176 -8
  35. package/src/cli/menus/uninstall.js +167 -0
  36. package/src/cli/menus/update.js +221 -65
  37. package/src/core/acme-challenge.js +273 -0
  38. package/src/core/cert-operations.js +189 -0
  39. package/src/{dashboard/lib → core}/cert-reader.js +2 -2
  40. package/src/core/cert-renewal.js +494 -0
  41. package/src/core/channels/discord.js +77 -0
  42. package/src/core/channels/telegram.js +120 -0
  43. package/src/core/cleanup.js +600 -0
  44. package/src/core/config.js +169 -2
  45. package/src/core/daemon/ipc.js +292 -0
  46. package/src/core/daemon/lock.js +294 -0
  47. package/src/core/daemon/run.js +241 -0
  48. package/src/core/daemon/stopRequest.js +162 -0
  49. package/src/core/db.js +44 -8
  50. package/src/core/deploy/apps.js +491 -0
  51. package/src/core/deploy/domainLink.js +200 -0
  52. package/src/core/deploy/engine.js +973 -0
  53. package/src/core/deploy/ezfile.js +361 -0
  54. package/src/core/deploy/github.js +239 -0
  55. package/src/core/deploy/githubApi.js +261 -0
  56. package/src/core/deploy/hookServer.js +325 -0
  57. package/src/core/deploy/hubCommands.js +267 -0
  58. package/src/core/deploy/launcher.js +57 -0
  59. package/src/core/deploy/status.js +91 -0
  60. package/src/core/deploy/store.js +398 -0
  61. package/src/core/domainNotifier.js +364 -0
  62. package/src/core/domains-db.js +234 -0
  63. package/src/core/events.js +222 -0
  64. package/src/core/hub/agent.js +842 -0
  65. package/src/core/hubLink.js +306 -0
  66. package/src/core/hubPermissions.js +430 -0
  67. package/src/core/installSource.js +162 -0
  68. package/src/core/jobs/bus.js +120 -0
  69. package/src/core/jobs/index.js +371 -0
  70. package/src/core/jobs/monitors.js +368 -0
  71. package/src/core/jobs/owner.js +217 -0
  72. package/src/core/jobs/revisionWatcher.js +106 -0
  73. package/src/core/nginx-apply.js +213 -0
  74. package/src/core/nginx-conf-generator.js +253 -17
  75. package/src/{dashboard/lib → core}/nginx-service.js +18 -9
  76. package/src/core/notifications/claim.js +214 -0
  77. package/src/core/notifications/dispatch.js +154 -0
  78. package/src/core/notifier.js +103 -0
  79. package/src/core/passwords.js +172 -0
  80. package/src/core/permissions.js +8 -4
  81. package/src/core/platform.js +709 -2
  82. package/src/core/probeCache.js +258 -0
  83. package/src/core/purge.js +372 -0
  84. package/src/core/runner.js +488 -0
  85. package/src/core/service/acl.js +226 -0
  86. package/src/core/service/dataDir.js +345 -0
  87. package/src/core/service/index.js +1128 -0
  88. package/src/core/service/legacy.js +218 -0
  89. package/src/core/service/runtime.js +446 -0
  90. package/src/core/service/runtimeUpdate.js +800 -0
  91. package/src/core/service/systemd.js +458 -0
  92. package/src/core/service/windowsPersonal.js +530 -0
  93. package/src/core/service/windowsService.js +576 -0
  94. package/src/core/service/winsw.js +260 -0
  95. package/src/core/setupCode.js +331 -0
  96. package/src/core/shell.js +128 -13
  97. package/src/core/ssl-issuer.js +627 -0
  98. package/src/core/updater.js +295 -0
  99. package/src/core/validators.js +99 -0
  100. package/src/dashboard/controllers/authController.js +316 -0
  101. package/src/dashboard/controllers/deploymentsController.js +479 -0
  102. package/src/dashboard/controllers/domainsController.js +403 -0
  103. package/src/dashboard/controllers/hubController.js +135 -0
  104. package/src/dashboard/controllers/nginxController.js +146 -0
  105. package/src/dashboard/controllers/processesController.js +368 -0
  106. package/src/dashboard/controllers/settingsController.js +503 -0
  107. package/src/dashboard/controllers/sslController.js +452 -0
  108. package/src/dashboard/lib/daemonBridge.js +163 -0
  109. package/src/dashboard/lib/localRequest.js +235 -0
  110. package/src/dashboard/lib/loginRateLimit.js +119 -0
  111. package/src/dashboard/lib/requireAuth.js +80 -0
  112. package/src/dashboard/public/img/icon.png +0 -0
  113. package/src/dashboard/public/img/icon_b.png +0 -0
  114. package/src/dashboard/public/js/app.js +595 -19
  115. package/src/dashboard/routes/auth.js +14 -33
  116. package/src/dashboard/routes/deployments.js +46 -0
  117. package/src/dashboard/routes/domains.js +20 -363
  118. package/src/dashboard/routes/hub.js +22 -0
  119. package/src/dashboard/routes/nginx.js +22 -146
  120. package/src/dashboard/routes/processes.js +29 -0
  121. package/src/dashboard/routes/settings.js +25 -232
  122. package/src/dashboard/routes/ssl.js +18 -276
  123. package/src/dashboard/server.js +279 -165
  124. package/src/dashboard/socketManager.js +246 -0
  125. package/src/dashboard/views/index.ejs +1 -0
  126. package/src/dashboard/views/partials/domain-form.ejs +64 -1
  127. package/src/dashboard/views/partials/login.ejs +69 -8
  128. package/src/dashboard/views/partials/processes-panel.ejs +261 -0
  129. package/src/dashboard/views/partials/settings-panel.ejs +549 -118
  130. package/src/dashboard/views/partials/sidebar.ejs +3 -1
  131. package/src/dashboard/lib/domains-db.js +0 -51
  132. /package/src/{dashboard/routes → core/channels}/.gitkeep +0 -0
package/src/core/shell.js CHANGED
@@ -6,17 +6,22 @@
6
6
  * All modules must use this utility instead of calling child_process APIs directly.
7
7
  *
8
8
  * Exported functions:
9
- * - getShell() — Returns OS-resolved shell descriptor { shell, flag }
10
- * - run(cmd, options) — Executes a command and captures output; never throws
11
- * - runLive(cmd, options) — Executes a command, streaming output to the terminal; never throws
12
- * - runInteractive(cmd, options) — Executes a command with full stdio inheritance (Linux only); never throws
9
+ * - getShell() — Returns OS-resolved shell descriptor { shell, flag }
10
+ * - run(cmd, options) — Executes a command and captures output; never throws
11
+ * - runLive(cmd, options) — Executes a command, streaming output to the terminal; never throws
12
+ * - runInteractive(cmd, options) — Executes a command with full stdio inheritance, for commands that prompt; never throws
13
+ * - runWithStdin(cmd, argsArray, stdinData) — Spawns a process with stdin piping; never throws
14
+ * - runCommandLine(cmd, options) — Runs a command line a USER wrote, in the platform's default shell; never throws
13
15
  *
14
16
  * CommandResult shape (returned by run()):
15
- * { success: boolean, stdout: string, stderr: string, exitCode: number|null, command: string }
17
+ * { success: boolean, stdout: string, stderr: string, exitCode: number|null, command: string }
16
18
  *
17
19
  * CommandOptions (accepted by run() and runLive()):
18
- * { timeout?: number, cwd?: string }
19
- * Defaults: timeout = 30 000 ms, cwd = process.cwd()
20
+ * { timeout?: number, cwd?: string }
21
+ * Defaults: timeout = 30 000 ms, cwd = process.cwd()
22
+ *
23
+ * run() additionally accepts `env` (merged over process.env) and `onData`
24
+ * (called with each chunk of output as it arrives).
20
25
  */
21
26
 
22
27
  import { spawn } from 'child_process';
@@ -55,23 +60,48 @@ export function getShell() {
55
60
  * @param {{ timeout?: number, cwd?: string }} [options]
56
61
  * @param {number} [options.timeout=30000] - Milliseconds before the process is killed.
57
62
  * @param {string} [options.cwd=process.cwd()] - Working directory for the child process.
63
+ * @param {Object} [options.env] - Extra environment variables, merged over process.env.
64
+ * @param {(chunk: string, stream: 'stdout'|'stderr') => void} [options.onData] - Receives output as it arrives.
58
65
  * @returns {Promise<{ success: boolean, stdout: string, stderr: string, exitCode: number|null, command: string }>}
59
66
  */
60
67
  export function run(cmd, options = {}) {
61
- const { timeout = 30000, cwd = process.cwd() } = options;
68
+ const { timeout = 30000, cwd = process.cwd(), env = null, onData = null } = options;
62
69
  const { shell, flag } = getShell();
63
70
 
71
+ return capture((spawnOptions) => spawn(shell, [flag, cmd], spawnOptions), { cmd, timeout, cwd, env, onData });
72
+ }
73
+
74
+ /**
75
+ * Shared body of run() and runCommandLine(): spawn, collect output, enforce
76
+ * the timeout, and always resolve with a CommandResult.
77
+ *
78
+ * @param {(spawnOptions: Object) => import('child_process').ChildProcess} spawnChild
79
+ * @param {{ cmd: string, timeout: number, cwd: string, env: Object|null, onData: Function|null }} opts
80
+ */
81
+ function capture(spawnChild, { cmd, timeout, cwd, env, onData }) {
64
82
  return new Promise((resolve) => {
65
83
  const ac = new AbortController();
66
84
  const timer = setTimeout(() => ac.abort(), timeout);
67
85
 
68
- const child = spawn(shell, [flag, cmd], { cwd, signal: ac.signal, encoding: 'utf8', windowsHide: true });
86
+ const child = spawnChild({
87
+ cwd,
88
+ signal: ac.signal,
89
+ encoding: 'utf8',
90
+ windowsHide: true,
91
+ ...(env ? { env: { ...process.env, ...env } } : {}),
92
+ });
69
93
 
70
94
  let stdoutBuf = '';
71
95
  let stderrBuf = '';
72
96
 
73
- child.stdout.on('data', (chunk) => { stdoutBuf += chunk; });
74
- child.stderr.on('data', (chunk) => { stderrBuf += chunk; });
97
+ // A listener that throws must not lose the command's result.
98
+ const tell = (chunk, stream) => {
99
+ if (!onData) return;
100
+ try { onData(stripAnsi(String(chunk)), stream); } catch { /* ignore */ }
101
+ };
102
+
103
+ child.stdout.on('data', (chunk) => { stdoutBuf += chunk; tell(chunk, 'stdout'); });
104
+ child.stderr.on('data', (chunk) => { stderrBuf += chunk; tell(chunk, 'stderr'); });
75
105
 
76
106
  child.on('close', (exitCode) => {
77
107
  clearTimeout(timer);
@@ -107,6 +137,35 @@ export function run(cmd, options = {}) {
107
137
  });
108
138
  }
109
139
 
140
+ // ─── runCommandLine ───────────────────────────────────────────────────────────
141
+
142
+ /**
143
+ * Runs a command line that a USER wrote — an `install`, `build` or hook command
144
+ * from a project's ez.json — in the platform's default shell.
145
+ *
146
+ * This is not run(): run() uses PowerShell on Windows, where `a && b` is a
147
+ * syntax error before PowerShell 7, and almost every build command anyone
148
+ * writes contains `&&`. `shell: true` gives `/bin/sh -c` on Linux and
149
+ * `cmd.exe /d /s /c` on Windows, which is the shell npm scripts themselves run
150
+ * in — so a command that works in `package.json` works here unchanged.
151
+ *
152
+ * Never throws. Same CommandResult as run(). On a timeout the shell is killed;
153
+ * a grandchild it started may outlive it, which is why the default is long
154
+ * rather than tight.
155
+ *
156
+ * @param {string} cmd - The command line, exactly as written.
157
+ * @param {Object} [options]
158
+ * @param {number} [options.timeout=900000] - Milliseconds before the shell is killed (15 minutes).
159
+ * @param {string} [options.cwd=process.cwd()]
160
+ * @param {Object} [options.env] - Extra environment variables, merged over process.env.
161
+ * @param {(chunk: string, stream: 'stdout'|'stderr') => void} [options.onData]
162
+ * @returns {Promise<{ success: boolean, stdout: string, stderr: string, exitCode: number|null, command: string }>}
163
+ */
164
+ export function runCommandLine(cmd, options = {}) {
165
+ const { timeout = 900000, cwd = process.cwd(), env = null, onData = null } = options;
166
+ return capture((spawnOptions) => spawn(cmd, [], { ...spawnOptions, shell: true }), { cmd, timeout, cwd, env, onData });
167
+ }
168
+
110
169
  // ─── runLive ──────────────────────────────────────────────────────────────────
111
170
 
112
171
  /**
@@ -155,8 +214,13 @@ export function runLive(cmd, options = {}) {
155
214
 
156
215
  /**
157
216
  * Executes a shell command with full stdio inheritance (stdin/stdout/stderr all
158
- * pass through to the terminal). Intended for Linux-only interactive commands
159
- * such as `sudo -v` that need to read a password from the user.
217
+ * pass through to the terminal), for commands that must prompt the user
218
+ * themselves — `sudo -v` on Linux, and `schtasks /RP *` on Windows, where
219
+ * Windows collects the account password so that Easy DevOps never handles it.
220
+ *
221
+ * The implementation is platform-agnostic; the caller is responsible for
222
+ * checking that a real terminal exists (`process.stdin.isTTY`), since there is
223
+ * nothing to prompt on in a dashboard request or a PM2-managed process.
160
224
  *
161
225
  * Never throws.
162
226
  *
@@ -185,3 +249,54 @@ export function runInteractive(cmd, options = {}) {
185
249
  });
186
250
  });
187
251
  }
252
+
253
+ // ─── runWithStdin ─────────────────────────────────────────────────────────────
254
+
255
+ /**
256
+ * Spawns a process directly (no shell wrapper) and pipes data to its stdin.
257
+ * Intended for commands like `sudo -S` that read input from stdin.
258
+ *
259
+ * Never throws. The returned Promise always resolves with a CommandResult.
260
+ *
261
+ * @param {string} cmd - The executable to spawn (e.g. 'sudo').
262
+ * @param {string[]} argsArray - Arguments passed directly to the executable.
263
+ * @param {string} [stdinData=''] - String to pipe to the process stdin.
264
+ * @returns {Promise<{ success: boolean, stdout: string, stderr: string, exitCode: number|null, command: string }>}
265
+ */
266
+ export function runWithStdin(cmd, argsArray, stdinData = '') {
267
+ return new Promise((resolve) => {
268
+ const child = spawn(cmd, argsArray, {
269
+ stdio: ['pipe', 'pipe', 'pipe'],
270
+ windowsHide: true,
271
+ });
272
+
273
+ let stdoutBuf = '';
274
+ let stderrBuf = '';
275
+
276
+ child.stdout.on('data', (chunk) => { stdoutBuf += chunk; });
277
+ child.stderr.on('data', (chunk) => { stderrBuf += chunk; });
278
+
279
+ child.stdin.write(stdinData);
280
+ child.stdin.end();
281
+
282
+ child.on('close', (exitCode) => {
283
+ resolve({
284
+ success: exitCode === 0,
285
+ stdout: stripAnsi(stdoutBuf).trim(),
286
+ stderr: stripAnsi(stderrBuf).trim(),
287
+ exitCode,
288
+ command: cmd,
289
+ });
290
+ });
291
+
292
+ child.on('error', (err) => {
293
+ resolve({
294
+ success: false,
295
+ stdout: '',
296
+ stderr: err.message,
297
+ exitCode: null,
298
+ command: cmd,
299
+ });
300
+ });
301
+ });
302
+ }