From ed744c45139b3155c8c86e7a07ad9e30eb993a78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=AC=E5=93=A5=E4=BE=83=E4=BE=83=E4=BE=83ygkkk?= <121604513+yonggekkk@users.noreply.github.com> Date: Wed, 26 Feb 2025 09:07:50 +0800 Subject: [PATCH] Update app.js --- app.js | 60 ++++++++++++++++++---------------------------------------- 1 file changed, 18 insertions(+), 42 deletions(-) diff --git a/app.js b/app.js index 106d7b2..2a1d9b7 100644 --- a/app.js +++ b/app.js @@ -1,7 +1,6 @@ require('dotenv').config(); const express = require("express"); const { exec } = require('child_process'); -const { spawn } = require('child_process'); const app = express(); app.use(express.json()); const commandToRun = "cd ~ && bash serv00keep.sh"; @@ -37,50 +36,27 @@ app.get("/re", (req, res) => { }); }); +const changeportCommands = "cd ~ && bash webport.sh"; +function runportCommand() { +exec(changeportCommands, { maxBuffer: 1024 * 1024 * 10 }, (err, stdout, stderr) => { + console.log('stdout:', stdout); + console.error('stderr:', stderr); + if (err) { + console.error('Execution error:', err); + return res.status(500).send(`错误:${stderr || stdout}`); + } + if (stderr) { + console.error('stderr output:', stderr); + return res.status(500).send(`stderr: ${stderr}`); + } + res.type('text').send(stdout); + }); +} app.get("/rp", (req, res) => { - const changeportCommands = "bash"; - const args = ["webport.sh"]; - - const child = spawn(changeportCommands, args, { cwd: process.env.HOME }); - - let stdoutData = ''; - let stderrData = ''; - - // 处理标准输出 - child.stdout.on('data', (data) => { - stdoutData += data.toString(); // 累加输出 - console.log(data.toString()); // 输出到控制台,或者可以根据需要修改 - }); - - // 处理标准错误输出 - child.stderr.on('data', (data) => { - stderrData += data.toString(); // 累加错误信息 - console.error(data.toString()); // 输出错误 - }); - - // 处理结束 - child.on('close', (code) => { - if (code !== 0) { - console.error(`子进程退出,错误代码:${code}`); - return res.status(500).send(`错误:${stderrData || stdoutData}`); - } - - // 如果有stderr信息 - if (stderrData) { - return res.status(500).send(`stderr: ${stderrData}`); - } - - // 返回输出 - res.type('text').send(stdoutData); - }); - - child.on('error', (err) => { - console.error('子进程启动失败:', err); - res.status(500).send(`执行错误: ${err.message}`); - }); + runportCommand(); + res.type("html").send("
重置节点端口完成!请把后缀改为/list/你的uuid 查看更新端口后的节点及订阅信息
"); }); - app.get("/list/key", (req, res) => { const listCommands = ` USERNAME=$(whoami | tr '[:upper:]' '[:lower:]')