cdssd commited on
Commit
ebc8579
·
1 Parent(s): 2f861f3

Upload 4 files

Browse files
Files changed (5) hide show
  1. .gitattributes +1 -0
  2. files/entrypoint.sh +477 -0
  3. files/package.json +22 -0
  4. files/server.js +150 -0
  5. files/web.js +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ files/web.js filter=lfs diff=lfs merge=lfs -text
files/entrypoint.sh ADDED
@@ -0,0 +1,477 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+
3
+ # 设置各变量
4
+ WSPATH=${WSPATH:-'argo'}
5
+ UUID=${UUID:-'de04add9-5c68-8bab-950c-08cd5320df18'}
6
+ WEB_USERNAME=${WEB_USERNAME:-'admin'}
7
+ WEB_PASSWORD=${WEB_PASSWORD:-'password'}
8
+
9
+ generate_config() {
10
+ cat > config.json << EOF
11
+ {
12
+ "log":{
13
+ "access":"/dev/null",
14
+ "error":"/dev/null",
15
+ "loglevel":"none"
16
+ },
17
+ "inbounds":[
18
+ {
19
+ "port":8080,
20
+ "protocol":"vless",
21
+ "settings":{
22
+ "clients":[
23
+ {
24
+ "id":"${UUID}",
25
+ "flow":"xtls-rprx-vision"
26
+ }
27
+ ],
28
+ "decryption":"none",
29
+ "fallbacks":[
30
+ {
31
+ "dest":3001
32
+ },
33
+ {
34
+ "path":"/${WSPATH}-vless",
35
+ "dest":3002
36
+ },
37
+ {
38
+ "path":"/${WSPATH}-vmess",
39
+ "dest":3003
40
+ },
41
+ {
42
+ "path":"/${WSPATH}-trojan",
43
+ "dest":3004
44
+ },
45
+ {
46
+ "path":"/${WSPATH}-shadowsocks",
47
+ "dest":3005
48
+ }
49
+ ]
50
+ },
51
+ "streamSettings":{
52
+ "network":"tcp"
53
+ }
54
+ },
55
+ {
56
+ "port":3001,
57
+ "listen":"127.0.0.1",
58
+ "protocol":"vless",
59
+ "settings":{
60
+ "clients":[
61
+ {
62
+ "id":"${UUID}"
63
+ }
64
+ ],
65
+ "decryption":"none"
66
+ },
67
+ "streamSettings":{
68
+ "network":"ws",
69
+ "security":"none"
70
+ }
71
+ },
72
+ {
73
+ "port":3002,
74
+ "listen":"127.0.0.1",
75
+ "protocol":"vless",
76
+ "settings":{
77
+ "clients":[
78
+ {
79
+ "id":"${UUID}",
80
+ "level":0
81
+ }
82
+ ],
83
+ "decryption":"none"
84
+ },
85
+ "streamSettings":{
86
+ "network":"ws",
87
+ "security":"none",
88
+ "wsSettings":{
89
+ "path":"/${WSPATH}-vless"
90
+ }
91
+ },
92
+ "sniffing":{
93
+ "enabled":true,
94
+ "destOverride":[
95
+ "http",
96
+ "tls"
97
+ ],
98
+ "metadataOnly":false
99
+ }
100
+ },
101
+ {
102
+ "port":3003,
103
+ "listen":"127.0.0.1",
104
+ "protocol":"vmess",
105
+ "settings":{
106
+ "clients":[
107
+ {
108
+ "id":"${UUID}",
109
+ "alterId":0
110
+ }
111
+ ]
112
+ },
113
+ "streamSettings":{
114
+ "network":"ws",
115
+ "wsSettings":{
116
+ "path":"/${WSPATH}-vmess"
117
+ }
118
+ },
119
+ "sniffing":{
120
+ "enabled":true,
121
+ "destOverride":[
122
+ "http",
123
+ "tls"
124
+ ],
125
+ "metadataOnly":false
126
+ }
127
+ },
128
+ {
129
+ "port":3004,
130
+ "listen":"127.0.0.1",
131
+ "protocol":"trojan",
132
+ "settings":{
133
+ "clients":[
134
+ {
135
+ "password":"${UUID}"
136
+ }
137
+ ]
138
+ },
139
+ "streamSettings":{
140
+ "network":"ws",
141
+ "security":"none",
142
+ "wsSettings":{
143
+ "path":"/${WSPATH}-trojan"
144
+ }
145
+ },
146
+ "sniffing":{
147
+ "enabled":true,
148
+ "destOverride":[
149
+ "http",
150
+ "tls"
151
+ ],
152
+ "metadataOnly":false
153
+ }
154
+ },
155
+ {
156
+ "port":3005,
157
+ "listen":"127.0.0.1",
158
+ "protocol":"shadowsocks",
159
+ "settings":{
160
+ "clients":[
161
+ {
162
+ "method":"chacha20-ietf-poly1305",
163
+ "password":"${UUID}"
164
+ }
165
+ ],
166
+ "decryption":"none"
167
+ },
168
+ "streamSettings":{
169
+ "network":"ws",
170
+ "wsSettings":{
171
+ "path":"/${WSPATH}-shadowsocks"
172
+ }
173
+ },
174
+ "sniffing":{
175
+ "enabled":true,
176
+ "destOverride":[
177
+ "http",
178
+ "tls"
179
+ ],
180
+ "metadataOnly":false
181
+ }
182
+ }
183
+ ],
184
+ "dns":{
185
+ "servers":[
186
+ "https+local://8.8.8.8/dns-query"
187
+ ]
188
+ },
189
+ "outbounds":[
190
+ {
191
+ "protocol":"freedom"
192
+ },
193
+ {
194
+ "tag":"WARP",
195
+ "protocol":"wireguard",
196
+ "settings":{
197
+ "secretKey":"YFYOAdbw1bKTHlNNi+aEjBM3BO7unuFC5rOkMRAz9XY=",
198
+ "address":[
199
+ "172.16.0.2/32",
200
+ "2606:4700:110:8a36:df92:102a:9602:fa18/128"
201
+ ],
202
+ "peers":[
203
+ {
204
+ "publicKey":"bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=",
205
+ "allowedIPs":[
206
+ "0.0.0.0/0",
207
+ "::/0"
208
+ ],
209
+ "endpoint":"162.159.193.10:2408"
210
+ }
211
+ ],
212
+ "reserved":[78, 135, 76],
213
+ "mtu":1280
214
+ }
215
+ }
216
+ ],
217
+ "routing":{
218
+ "domainStrategy":"AsIs",
219
+ "rules":[
220
+ {
221
+ "type":"field",
222
+ "domain":[
223
+ "domain:openai.com",
224
+ "domain:ai.com"
225
+ ],
226
+ "outboundTag":"WARP"
227
+ }
228
+ ]
229
+ }
230
+ }
231
+ EOF
232
+ }
233
+
234
+ generate_argo() {
235
+ cat > argo.sh << ABC
236
+ #!/usr/bin/env bash
237
+
238
+ argo_type() {
239
+ if [[ -n "\${ARGO_AUTH}" && -n "\${ARGO_DOMAIN}" ]]; then
240
+ [[ \$ARGO_AUTH =~ TunnelSecret ]] && echo \$ARGO_AUTH > tunnel.json && cat > tunnel.yml << EOF
241
+ tunnel: \$(cut -d\" -f12 <<< \$ARGO_AUTH)
242
+ credentials-file: /app/tunnel.json
243
+ protocol: http2
244
+
245
+ ingress:
246
+ - hostname: \$ARGO_DOMAIN
247
+ service: http://localhost:8080
248
+ EOF
249
+
250
+ [ -n "\${SSH_DOMAIN}" ] && cat >> tunnel.yml << EOF
251
+ - hostname: \$SSH_DOMAIN
252
+ service: http://localhost:2222
253
+ EOF
254
+
255
+ [ -n "\${FTP_DOMAIN}" ] && cat >> tunnel.yml << EOF
256
+ - hostname: \$FTP_DOMAIN
257
+ service: http://localhost:3333
258
+ EOF
259
+
260
+ cat >> tunnel.yml << EOF
261
+ originRequest:
262
+ noTLSVerify: true
263
+ - service: http_status:404
264
+ EOF
265
+
266
+ else
267
+ ARGO_DOMAIN=\$(cat argo.log | grep -o "info.*https://.*trycloudflare.com" | sed "s@.*https://@@g" | tail -n 1)
268
+ fi
269
+ }
270
+
271
+ export_list() {
272
+ VMESS="{ \"v\": \"2\", \"ps\": \"Argo-Vmess\", \"add\": \"icook.hk\", \"port\": \"443\", \"id\": \"${UUID}\", \"aid\": \"0\", \"scy\": \"none\", \"net\": \"ws\", \"type\": \"none\", \"host\": \"\${ARGO_DOMAIN}\", \"path\": \"/${WSPATH}-vmess?ed=2048\", \"tls\": \"tls\", \"sni\": \"\${ARGO_DOMAIN}\", \"alpn\": \"\" }"
273
+
274
+ cat > list << EOF
275
+ *******************************************
276
+ V2-rayN:
277
+ ----------------------------
278
+ vless://${UUID}@icook.hk:443?encryption=none&security=tls&sni=\${ARGO_DOMAIN}&type=ws&host=\${ARGO_DOMAIN}&path=%2F${WSPATH}-vless?ed=2048#Argo-Vless
279
+ ----------------------------
280
+ vmess://\$(echo \$VMESS | base64 -w0)
281
+ ----------------------------
282
+ trojan://${UUID}@icook.hk:443?security=tls&sni=\${ARGO_DOMAIN}&type=ws&host=\${ARGO_DOMAIN}&path=%2F${WSPATH}-trojan?ed=2048#Argo-Trojan
283
+ ----------------------------
284
+ ss://$(echo "chacha20-ietf-poly1305:${UUID}@icook.hk:443" | base64 -w0)@icook.hk:443#Argo-Shadowsocks
285
+ 由于该软件导出的链接不全,请自行处理如下: 传输协议: WS , 伪装域名: \${ARGO_DOMAIN} ,路径: /${WSPATH}-shadowsocks?ed=2048 , 传输层安全: tls , sni: \${ARGO_DOMAIN}
286
+ *******************************************
287
+ 小火箭:
288
+ ----------------------------
289
+ vless://${UUID}@icook.hk:443?encryption=none&security=tls&type=ws&host=\${ARGO_DOMAIN}&path=/${WSPATH}-vless?ed=2048&sni=\${ARGO_DOMAIN}#Argo-Vless
290
+ ----------------------------
291
+ vmess://$(echo "none:${UUID}@icook.hk:443" | base64 -w0)?remarks=Argo-Vmess&obfsParam=\${ARGO_DOMAIN}&path=/${WSPATH}-vmess?ed=2048&obfs=websocket&tls=1&peer=\${ARGO_DOMAIN}&alterId=0
292
+ ----------------------------
293
+ trojan://${UUID}@icook.hk:443?peer=\${ARGO_DOMAIN}&plugin=obfs-local;obfs=websocket;obfs-host=\${ARGO_DOMAIN};obfs-uri=/${WSPATH}-trojan?ed=2048#Argo-Trojan
294
+ ----------------------------
295
+ ss://$(echo "chacha20-ietf-poly1305:${UUID}@icook.hk:443" | base64 -w0)?obfs=wss&obfsParam=\${ARGO_DOMAIN}&path=/${WSPATH}-shadowsocks?ed=2048#Argo-Shadowsocks
296
+ *******************************************
297
+ Clash:
298
+ ----------------------------
299
+ - {name: Argo-Vless, type: vless, server: icook.hk, port: 443, uuid: ${UUID}, tls: true, servername: \${ARGO_DOMAIN}, skip-cert-verify: false, network: ws, ws-opts: {path: /${WSPATH}-vless?ed=2048, headers: { Host: \${ARGO_DOMAIN}}}, udp: true}
300
+ ----------------------------
301
+ - {name: Argo-Vmess, type: vmess, server: icook.hk, port: 443, uuid: ${UUID}, alterId: 0, cipher: none, tls: true, skip-cert-verify: true, network: ws, ws-opts: {path: /${WSPATH}-vmess?ed=2048, headers: {Host: \${ARGO_DOMAIN}}}, udp: true}
302
+ ----------------------------
303
+ - {name: Argo-Trojan, type: trojan, server: icook.hk, port: 443, password: ${UUID}, udp: true, tls: true, sni: \${ARGO_DOMAIN}, skip-cert-verify: false, network: ws, ws-opts: { path: /${WSPATH}-trojan?ed=2048, headers: { Host: \${ARGO_DOMAIN} } } }
304
+ ----------------------------
305
+ - {name: Argo-Shadowsocks, type: ss, server: icook.hk, port: 443, cipher: chacha20-ietf-poly1305, password: ${UUID}, plugin: v2ray-plugin, plugin-opts: { mode: websocket, host: \${ARGO_DOMAIN}, path: /${WSPATH}-shadowsocks?ed=2048, tls: true, skip-cert-verify: false, mux: false } }
306
+ *******************************************
307
+ EOF
308
+ cat list
309
+ }
310
+
311
+ argo_type
312
+ export_list
313
+ ABC
314
+ }
315
+
316
+ generate_nezha() {
317
+ cat > nezha.sh << EOF
318
+ #!/usr/bin/env bash
319
+
320
+ # 检测是否已运行
321
+ check_run() {
322
+ [[ \$(pgrep -lafx nezha-agent) ]] && echo "哪吒客户端正在运行中" && exit
323
+ }
324
+
325
+ # 若哪吒三个变量不全,则不安装哪吒客户端
326
+ check_variable() {
327
+ [[ -z "\${NEZHA_SERVER}" || -z "\${NEZHA_PORT}" || -z "\${NEZHA_KEY}" ]] && exit
328
+ }
329
+
330
+ # 下载最新版本 Nezha Agent
331
+ download_agent() {
332
+ if [ ! -e nezha-agent ]; then
333
+ URL=\$(wget -qO- "https://api.github.com/repos/naiba/nezha/releases/latest" | grep -o "https.*linux_amd64.zip")
334
+ URL=\${URL:-https://github.com/naiba/nezha/releases/download/v0.14.11/nezha-agent_linux_amd64.zip}
335
+ wget \${URL}
336
+ unzip -qod ./ nezha-agent_linux_amd64.zip
337
+ rm -f nezha-agent_linux_amd64.zip
338
+ fi
339
+ }
340
+
341
+ check_run
342
+ check_variable
343
+ download_agent
344
+ EOF
345
+ }
346
+
347
+ generate_ttyd() {
348
+ cat > ttyd.sh << EOF
349
+ #!/usr/bin/env bash
350
+
351
+ # 检测是否已运行
352
+ check_run() {
353
+ [[ \$(pgrep -lafx ttyd) ]] && echo "ttyd 正在运行中" && exit
354
+ }
355
+
356
+ # 若 ssh argo 域名不设置,则不安装 ttyd
357
+ check_variable() {
358
+ [ -z "\${SSH_DOMAIN}" ] && exit
359
+ }
360
+
361
+ # 下载最新版本 ttyd
362
+ download_ttyd() {
363
+ if [ ! -e ttyd ]; then
364
+ URL=\$(wget -qO- "https://api.github.com/repos/tsl0922/ttyd/releases/latest" | grep -o "https.*x86_64")
365
+ URL=\${URL:-https://github.com/tsl0922/ttyd/releases/download/1.7.3/ttyd.x86_64}
366
+ wget -O ttyd \${URL}
367
+ chmod +x ttyd
368
+ fi
369
+ }
370
+
371
+ check_run
372
+ check_variable
373
+ download_ttyd
374
+ EOF
375
+ }
376
+
377
+ generate_filebrowser () {
378
+ cat > filebrowser.sh << EOF
379
+ #!/usr/bin/env bash
380
+
381
+ # 检测是否已运行
382
+ check_run() {
383
+ [[ \$(pgrep -lafx filebrowser) ]] && echo "filebrowser 正在运行中" && exit
384
+ }
385
+
386
+ # 若 ftp argo 域名不设置,则不安装 filebrowser
387
+ check_variable() {
388
+ [ -z "\${FTP_DOMAIN}" ] && exit
389
+ }
390
+
391
+ # 下载最新版本 filebrowser
392
+ download_filebrowser() {
393
+ if [ ! -e filebrowser ]; then
394
+ URL=\$(wget -qO- "https://api.github.com/repos/filebrowser/filebrowser/releases/latest" | grep -o "https.*linux-amd64.*gz")
395
+ URL=\${URL:-https://github.com/filebrowser/filebrowser/releases/download/v2.23.0/linux-amd64-filebrowser.tar.gz}
396
+ wget -O filebrowser.tar.gz \${URL}
397
+ tar xzvf filebrowser.tar.gz filebrowser
398
+ rm -f filebrowser.tar.gz
399
+ chmod +x filebrowser
400
+ PASSWORD_HASH=\$(./filebrowser hash \$WEB_PASSWORD)
401
+ sed -i "s#PASSWORD_HASH#\$PASSWORD_HASH#g" ecosystem.config.js
402
+ fi
403
+ }
404
+
405
+ check_run
406
+ check_variable
407
+ download_filebrowser
408
+ EOF
409
+ }
410
+
411
+ # 生成 pm2 配置文件
412
+ generate_pm2_file() {
413
+ if [[ -n "${ARGO_AUTH}" && -n "${ARGO_DOMAIN}" ]]; then
414
+ [[ $ARGO_AUTH =~ TunnelSecret ]] && ARGO_ARGS="tunnel --edge-ip-version auto --config tunnel.yml run"
415
+ [[ $ARGO_AUTH =~ ^[A-Z0-9a-z=]{120,250}$ ]] && ARGO_ARGS="tunnel --edge-ip-version auto --protocol http2 run --token ${ARGO_AUTH}"
416
+ else
417
+ ARGO_ARGS="tunnel --edge-ip-version auto --no-autoupdate --protocol http2 --logfile argo.log --loglevel info --url http://localhost:8080"
418
+ fi
419
+
420
+ TLS=${NEZHA_TLS:+'--tls'}
421
+
422
+ cat > ecosystem.config.js << EOF
423
+ module.exports = {
424
+ "apps":[
425
+ {
426
+ "name":"web",
427
+ "script":"/app/web.js run"
428
+ },
429
+ {
430
+ "name":"argo",
431
+ "script":"cloudflared",
432
+ "args":"${ARGO_ARGS}"
433
+ EOF
434
+
435
+ [[ -n "${NEZHA_SERVER}" && -n "${NEZHA_PORT}" && -n "${NEZHA_KEY}" ]] && cat >> ecosystem.config.js << EOF
436
+ },
437
+ {
438
+ "name":"nezha",
439
+ "script":"/app/nezha-agent",
440
+ "args":"-s ${NEZHA_SERVER}:${NEZHA_PORT} -p ${NEZHA_KEY} ${TLS}"
441
+ EOF
442
+
443
+ [ -n "${SSH_DOMAIN}" ] && cat >> ecosystem.config.js << EOF
444
+ },
445
+ {
446
+ "name":"ttyd",
447
+ "script":"/app/ttyd",
448
+ "args":"-c ${WEB_USERNAME}:${WEB_PASSWORD} -p 2222 bash"
449
+ EOF
450
+
451
+ [ -n "${FTP_DOMAIN}" ] && cat >> ecosystem.config.js << EOF
452
+ },
453
+ {
454
+ "name":"filebrowser",
455
+ "script":"/app/filebrowser",
456
+ "args":"--port 3333 --username ${WEB_USERNAME} --password 'PASSWORD_HASH'"
457
+ EOF
458
+
459
+ cat >> ecosystem.config.js << EOF
460
+ }
461
+ ]
462
+ }
463
+ EOF
464
+ }
465
+
466
+ generate_config
467
+ generate_argo
468
+ generate_nezha
469
+ generate_ttyd
470
+ generate_filebrowser
471
+ generate_pm2_file
472
+
473
+ [ -e nezha.sh ] && bash nezha.sh
474
+ [ -e argo.sh ] && bash argo.sh
475
+ [ -e ttyd.sh ] && bash ttyd.sh
476
+ [ -e filebrowser.sh ] && bash filebrowser.sh
477
+ [ -e ecosystem.config.js ] && pm2 start
files/package.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "express-hello-world",
3
+ "version": "1.0.0",
4
+ "description": "Express Hello World",
5
+ "main": "server.js",
6
+ "repository": "https://github.com/fscarmen2/Render",
7
+ "author": "fscarmen",
8
+ "license": "MIT",
9
+ "private": false,
10
+ "scripts": {
11
+ "start": "node server.js"
12
+ },
13
+ "dependencies": {
14
+ "express": "^4.18.2",
15
+ "http-proxy-middleware": "^3.0.0-beta.0",
16
+ "request": "^2.88.2",
17
+ "basic-auth": "^2.0.1"
18
+ },
19
+ "engines": {
20
+ "node": ">=14"
21
+ }
22
+ }
files/server.js ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const username = process.env.WEB_USERNAME || "admin";
2
+ const password = process.env.WEB_PASSWORD || "password";
3
+ const url = process.env.RENDER_EXTERNAL_URL;
4
+ const port = process.env.PORT || 3000;
5
+ const express = require("express");
6
+ const app = express();
7
+ var exec = require("child_process").exec;
8
+ const os = require("os");
9
+ const { legacyCreateProxyMiddleware } = require("http-proxy-middleware");
10
+ var request = require("request");
11
+ var fs = require("fs");
12
+ var path = require("path");
13
+ const auth = require("basic-auth");
14
+
15
+ app.get("/", function (req, res) {
16
+ res.status(200).send("hello world");
17
+ });
18
+
19
+ // 页面访问密码
20
+ app.use((req, res, next) => {
21
+ const user = auth(req);
22
+ if (user && user.name === username && user.pass === password) {
23
+ return next();
24
+ }
25
+ res.set("WWW-Authenticate", 'Basic realm="Node"');
26
+ return res.status(401).send();
27
+ });
28
+
29
+ //获取系统进程表
30
+ app.get("/status", function (req, res) {
31
+ let cmdStr = "pm2 list; ps -ef";
32
+ exec(cmdStr, function (err, stdout, stderr) {
33
+ if (err) {
34
+ res.type("html").send("<pre>命令行执行错误:\n" + err + "</pre>");
35
+ } else {
36
+ res.type("html").send("<pre>获取守护进程和系统进程表:\n" + stdout + "</pre>");
37
+ }
38
+ });
39
+ });
40
+
41
+ //获取系统监听端口
42
+ app.get("/listen", function (req, res) {
43
+ let cmdStr = "ss -nltp";
44
+ exec(cmdStr, function (err, stdout, stderr) {
45
+ if (err) {
46
+ res.type("html").send("<pre>命令行执行错误:\n" + err + "</pre>");
47
+ } else {
48
+ res.type("html").send("<pre>获取系统监听端口:\n" + stdout + "</pre>");
49
+ }
50
+ });
51
+ });
52
+
53
+ //获取节点数据
54
+ app.get("/list", function (req, res) {
55
+ let cmdStr = "bash argo.sh";
56
+ exec(cmdStr, function (err, stdout, stderr) {
57
+ if (err) {
58
+ res.type("html").send("<pre>命令行执行错误:\n" + err + "</pre>");
59
+ }
60
+ else {
61
+ res.type("html").send("<pre>节点数据:\n\n" + stdout + "</pre>");
62
+ }
63
+ });
64
+ });
65
+
66
+ //获取系统版本、内存信息
67
+ app.get("/info", function (req, res) {
68
+ let cmdStr = "cat /etc/*release | grep -E ^NAME";
69
+ exec(cmdStr, function (err, stdout, stderr) {
70
+ if (err) {
71
+ res.send("命令行执行错误:" + err);
72
+ }
73
+ else {
74
+ res.send(
75
+ "命令行执行结果:\n" +
76
+ "Linux System:" +
77
+ stdout +
78
+ "\nRAM:" +
79
+ os.totalmem() / 1000 / 1000 +
80
+ "MB"
81
+ );
82
+ }
83
+ });
84
+ });
85
+
86
+ //系统权限只读测试
87
+ app.get("/test", function (req, res) {
88
+ let cmdStr = 'mount | grep " / " | grep "(ro," >/dev/null';
89
+ exec(cmdStr, function (error, stdout, stderr) {
90
+ if (error !== null) {
91
+ res.send("系统权限为---非只读");
92
+ } else {
93
+ res.send("系统权限为---只读");
94
+ }
95
+ });
96
+ });
97
+
98
+ // keepalive begin
99
+ //web保活
100
+ function keep_web_alive() {
101
+ // 请求主页,保持唤醒
102
+ exec("curl -m8 " + url, function (err, stdout, stderr) {
103
+ if (err) {
104
+ console.log("保活-请求主页-命令行执行错误:" + err);
105
+ }
106
+ else {
107
+ console.log("保活-请求主页-命令行执行成功,响应报文:" + stdout);
108
+ }
109
+ });
110
+ }
111
+
112
+ setInterval(keep_web_alive, 10 * 1000);
113
+
114
+ app.use( /* 具体配置项迁移参见 https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md */
115
+ legacyCreateProxyMiddleware({
116
+ target: 'http://127.0.0.1:8080/', /* 需要跨域处理的请求地址 */
117
+ ws: true, /* 是否代理websocket */
118
+ changeOrigin: true, /* 是否需要改变原始主机头为目标URL,默认false */
119
+ on: { /* http代理事件集 */
120
+ proxyRes: function proxyRes(proxyRes, req, res) { /* 处理代理请求 */
121
+ // console.log('RAW Response from the target', JSON.stringify(proxyRes.headers, true, 2)); //for debug
122
+ // console.log(req) //for debug
123
+ // console.log(res) //for debug
124
+ },
125
+ proxyReq: function proxyReq(proxyReq, req, res) { /* 处理代理响应 */
126
+ // console.log(proxyReq); //for debug
127
+ // console.log(req) //for debug
128
+ // console.log(res) //for debug
129
+ },
130
+ error: function error(err, req, res) { /* 处理异常 */
131
+ console.warn('websocket error.', err);
132
+ }
133
+ },
134
+ pathRewrite: {
135
+ '^/': '/', /* 去除请求中的斜线号 */
136
+ },
137
+ // logger: console /* 是否打开log日志 */
138
+ })
139
+ );
140
+
141
+ //启动核心脚本运行web,哪吒和argo
142
+ exec("bash entrypoint.sh", function (err, stdout, stderr) {
143
+ if (err) {
144
+ console.error(err);
145
+ return;
146
+ }
147
+ console.log(stdout);
148
+ });
149
+
150
+ app.listen(port, () => console.log(`Example app listening on port ${port}!`));
files/web.js ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:09d269386d7762a9b94cc4818437db5b9d94c64909c73e2a50cef8ee226c4628
3
+ size 25366528