easy-vps 0.1.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/bin/cli.js +180 -0
- package/client/assets/index-C4GZ_uMC.js +104 -0
- package/client/assets/index-Dq-W19hL.css +2 -0
- package/client/assets/poppins-devanagari-400-normal-CJDn6rn8.woff2 +0 -0
- package/client/assets/poppins-devanagari-400-normal-CqVvlrh5.woff +0 -0
- package/client/assets/poppins-latin-400-normal-BOb3E3N0.woff +0 -0
- package/client/assets/poppins-latin-400-normal-cpxAROuN.woff2 +0 -0
- package/client/assets/poppins-latin-ext-400-normal-DaBSavcJ.woff +0 -0
- package/client/assets/poppins-latin-ext-400-normal-by3JarPu.woff2 +0 -0
- package/client/favicon.svg +1 -0
- package/client/icons.svg +24 -0
- package/client/index.html +14 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +143 -0
- package/dist/routes/async-route.d.ts +3 -0
- package/dist/routes/async-route.js +9 -0
- package/dist/routes/auth.d.ts +5 -0
- package/dist/routes/auth.js +101 -0
- package/dist/routes/database.d.ts +2 -0
- package/dist/routes/database.js +192 -0
- package/dist/routes/deploy.d.ts +2 -0
- package/dist/routes/deploy.js +161 -0
- package/dist/routes/domain.d.ts +2 -0
- package/dist/routes/domain.js +54 -0
- package/dist/routes/firewall.d.ts +2 -0
- package/dist/routes/firewall.js +63 -0
- package/dist/routes/instances.d.ts +2 -0
- package/dist/routes/instances.js +77 -0
- package/dist/routes/logs.d.ts +2 -0
- package/dist/routes/logs.js +67 -0
- package/dist/routes/system.d.ts +2 -0
- package/dist/routes/system.js +83 -0
- package/dist/services/auth.d.ts +25 -0
- package/dist/services/auth.js +128 -0
- package/dist/services/backup-config.d.ts +16 -0
- package/dist/services/backup-config.js +51 -0
- package/dist/services/backup-scheduler.d.ts +2 -0
- package/dist/services/backup-scheduler.js +104 -0
- package/dist/services/daemon.d.ts +28 -0
- package/dist/services/daemon.js +180 -0
- package/dist/services/database.d.ts +60 -0
- package/dist/services/database.js +540 -0
- package/dist/services/deploy.d.ts +102 -0
- package/dist/services/deploy.js +540 -0
- package/dist/services/domain.d.ts +26 -0
- package/dist/services/domain.js +170 -0
- package/dist/services/firewall.d.ts +24 -0
- package/dist/services/firewall.js +64 -0
- package/dist/services/instances.d.ts +17 -0
- package/dist/services/instances.js +67 -0
- package/dist/services/logs.d.ts +8 -0
- package/dist/services/logs.js +61 -0
- package/dist/services/metrics-history.d.ts +13 -0
- package/dist/services/metrics-history.js +36 -0
- package/dist/services/packages.d.ts +22 -0
- package/dist/services/packages.js +124 -0
- package/dist/services/s3.d.ts +17 -0
- package/dist/services/s3.js +93 -0
- package/dist/services/ssh.d.ts +78 -0
- package/dist/services/ssh.js +309 -0
- package/dist/services/system.d.ts +74 -0
- package/dist/services/system.js +286 -0
- package/package.json +55 -0
- package/scripts/dev.js +88 -0
- package/scripts/postinstall.js +123 -0
- package/scripts/preuninstall.js +21 -0
- package/scripts/try-install.sh +65 -0
- package/scripts/ui.js +54 -0
package/bin/cli.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
const path = require('node:path')
|
|
5
|
+
const os = require('node:os')
|
|
6
|
+
|
|
7
|
+
const ROOT = path.resolve(__dirname, '..')
|
|
8
|
+
const DIST = path.join(ROOT, 'dist', 'index.js')
|
|
9
|
+
const DAEMON = path.join(ROOT, 'dist', 'services', 'daemon.js')
|
|
10
|
+
|
|
11
|
+
const COMMANDS = ['run', 'start', 'stop', 'restart', 'status', 'logs', 'uninstall']
|
|
12
|
+
|
|
13
|
+
function parseArgs(argv) {
|
|
14
|
+
const options = { command: null, port: undefined, host: undefined, help: false, version: false }
|
|
15
|
+
|
|
16
|
+
for (let i = 0; i < argv.length; i++) {
|
|
17
|
+
const arg = argv[i]
|
|
18
|
+
if (arg === '--help' || arg === '-h') options.help = true
|
|
19
|
+
else if (arg === '--version' || arg === '-v') options.version = true
|
|
20
|
+
else if (arg === '--port' || arg === '-p') options.port = Number(argv[++i])
|
|
21
|
+
else if (arg.startsWith('--port=')) options.port = Number(arg.slice(7))
|
|
22
|
+
else if (arg === '--host') options.host = argv[++i]
|
|
23
|
+
else if (arg.startsWith('--host=')) options.host = arg.slice(7)
|
|
24
|
+
else if (!options.command && COMMANDS.includes(arg)) options.command = arg
|
|
25
|
+
else {
|
|
26
|
+
console.error(`Unknown argument: ${arg}`)
|
|
27
|
+
process.exit(1)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return options
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function usage(defaultPort) {
|
|
35
|
+
return `easy-vps — VPS control panel
|
|
36
|
+
|
|
37
|
+
Usage:
|
|
38
|
+
easy-vps [command] [options]
|
|
39
|
+
|
|
40
|
+
Commands:
|
|
41
|
+
run Run the panel in the foreground (default)
|
|
42
|
+
start Start the panel in the background
|
|
43
|
+
stop Stop the background panel
|
|
44
|
+
restart Restart the background panel
|
|
45
|
+
status Show whether the panel is running
|
|
46
|
+
logs Print the path to the panel log
|
|
47
|
+
uninstall Stop the panel and remove its service
|
|
48
|
+
(run this before npm rm -g easy-vps)
|
|
49
|
+
|
|
50
|
+
Options:
|
|
51
|
+
-p, --port <port> Port to listen on (default: ${defaultPort}, env: EASY_VPS_PORT)
|
|
52
|
+
--host <host> Address to bind (default: 0.0.0.0, env: EASY_VPS_HOST)
|
|
53
|
+
-v, --version Print version
|
|
54
|
+
-h, --help Show this help
|
|
55
|
+
`
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Addresses the panel can be reached on, for the startup banner. */
|
|
59
|
+
function networkAddresses() {
|
|
60
|
+
const addresses = []
|
|
61
|
+
for (const list of Object.values(os.networkInterfaces())) {
|
|
62
|
+
for (const net of list || []) {
|
|
63
|
+
if (net.family === 'IPv4' && !net.internal) addresses.push(net.address)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return addresses
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function printUrls(port) {
|
|
70
|
+
console.log(` ➜ Local: http://localhost:${port}/`)
|
|
71
|
+
for (const address of networkAddresses()) {
|
|
72
|
+
console.log(` ➜ Network: http://${address}:${port}/`)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function exitOnListenError(error, port) {
|
|
77
|
+
if (error.code === 'EADDRINUSE') {
|
|
78
|
+
console.error(`Port ${port} is already in use. Pass --port to pick another.`)
|
|
79
|
+
} else if (error.code === 'EACCES') {
|
|
80
|
+
console.error(`Not allowed to bind port ${port}. Try a port above 1024, or run with sudo.`)
|
|
81
|
+
} else {
|
|
82
|
+
console.error(error.message)
|
|
83
|
+
}
|
|
84
|
+
process.exit(1)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function main() {
|
|
88
|
+
let app
|
|
89
|
+
let daemon
|
|
90
|
+
try {
|
|
91
|
+
app = require(DIST)
|
|
92
|
+
daemon = require(DAEMON)
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error('easy-vps is not built. Run `npm run build` in the package directory.')
|
|
95
|
+
console.error(error.message)
|
|
96
|
+
process.exit(1)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const options = parseArgs(process.argv.slice(2))
|
|
100
|
+
|
|
101
|
+
if (options.help) {
|
|
102
|
+
process.stdout.write(usage(app.DEFAULT_PORT))
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (options.version) {
|
|
107
|
+
console.log(app.version())
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const port = options.port || Number(process.env.EASY_VPS_PORT) || app.DEFAULT_PORT
|
|
112
|
+
const host = options.host || process.env.EASY_VPS_HOST || app.DEFAULT_HOST
|
|
113
|
+
|
|
114
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
115
|
+
console.error(`Invalid port: ${port}`)
|
|
116
|
+
process.exit(1)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
switch (options.command) {
|
|
120
|
+
case 'status': {
|
|
121
|
+
const state = await daemon.status()
|
|
122
|
+
console.log(state.running ? `easy-vps is running — ${state.detail}` : `easy-vps is ${state.detail}`)
|
|
123
|
+
if (state.running) printUrls(port)
|
|
124
|
+
process.exit(state.running ? 0 : 1)
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
case 'logs': {
|
|
129
|
+
console.log(daemon.mode() === 'systemd' ? 'journalctl -u easy-vps -f' : daemon.logPath())
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
case 'uninstall': {
|
|
134
|
+
await daemon.uninstall()
|
|
135
|
+
console.log('easy-vps service stopped and removed')
|
|
136
|
+
console.log('You can now run: npm rm -g easy-vps')
|
|
137
|
+
return
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
case 'stop': {
|
|
141
|
+
await daemon.stop()
|
|
142
|
+
console.log('easy-vps stopped')
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
case 'start':
|
|
147
|
+
case 'restart': {
|
|
148
|
+
const mode = await daemon.start({ port, host })
|
|
149
|
+
const state = await daemon.status()
|
|
150
|
+
if (!state.running) {
|
|
151
|
+
console.error(`easy-vps did not start — ${state.detail}`)
|
|
152
|
+
process.exit(1)
|
|
153
|
+
}
|
|
154
|
+
console.log(`easy-vps started (${mode})`)
|
|
155
|
+
printUrls(port)
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
default:
|
|
160
|
+
break
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
let server
|
|
164
|
+
try {
|
|
165
|
+
server = await app.startServer({ port, host })
|
|
166
|
+
} catch (error) {
|
|
167
|
+
exitOnListenError(error, port)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
console.log(`\n easy-vps v${app.version()}\n`)
|
|
171
|
+
printUrls(port)
|
|
172
|
+
|
|
173
|
+
const shutdown = () => {
|
|
174
|
+
server.close(() => process.exit(0))
|
|
175
|
+
}
|
|
176
|
+
process.on('SIGINT', shutdown)
|
|
177
|
+
process.on('SIGTERM', shutdown)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
main()
|