diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f01e2a5 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "apc.stylesheet": { ".anysphere-markdown-container-root": "font-size: 16px; line-height: 1.4;" } +} \ No newline at end of file diff --git a/README.md b/README.md index 3bbaabb..7105396 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,16 @@ # 安装 > **注意:** 记得把命令中的 `yourdomain` 改为你真实的域名 + ```bash curl -Ls https://raw.githubusercontent.com/frankiejun/node-ws/refs/heads/main/setup.sh > setup.sh && chmod +x setup.sh && ./setup.sh yourdomain ``` +> 目前只能手动上传 index.js,package.json 然后面板启动! + + + + # Node-ws说明 diff --git a/index.js b/index.js index bfc623c..296df97 100644 --- a/index.js +++ b/index.js @@ -6,15 +6,14 @@ const net = require('net'); const { Buffer } = require('buffer'); const { exec, execSync } = require('child_process'); const { WebSocket, createWebSocketStream } = require('ws'); -const UUID = process.env.UUID || 'de04add9-5c68-6bab-950c-08cd5320df33'; // 运行哪吒v1,在不同的平台需要改UUID,否则会被覆盖 +const UUID = process.env.UUID || '#UUID#'; // 运行哪吒v1,在不同的平台需要改UUID,否则会被覆盖 const NEZHA_SERVER = process.env.NEZHA_SERVER || ''; // 哪吒v1填写形式:nz.abc.com:8008 哪吒v0填写形式:nz.abc.com const NEZHA_PORT = process.env.NEZHA_PORT || ''; // 哪吒v1没有此变量,v0的agent端口为{443,8443,2096,2087,2083,2053}其中之一时开启tls const NEZHA_KEY = process.env.NEZHA_KEY || ''; // v1的NZ_CLIENT_SECRET或v0的agent端口 -const DOMAIN = process.env.DOMAIN || '1234.abc.com'; // 填写项目域名或已反代的域名,不带前缀,建议填已反代的域名 +const DOMAIN = process.env.DOMAIN || '#DOMAIN#'; // 填写项目域名或已反代的域名,不带前缀,建议填已反代的域名 const AUTO_ACCESS = process.env.AUTO_ACCESS || true; // 是否开启自动访问保活,false为关闭,true为开启,需同时填写DOMAIN变量 -const SUB_PATH = process.env.SUB_PATH || 'sub'; // 获取节点的订阅路径 const NAME = process.env.NAME || 'Vls'; // 节点名称 -const PORT = process.env.PORT || 3000; // http和ws服务端口 +const PORT = process.env.PORT || #PORT#; // http和ws服务端口 const metaInfo = execSync( 'curl -s https://speed.cloudflare.com/meta | awk -F\\" \'{print $26"-"$18}\' | sed -e \'s/ /_/g\'', @@ -25,10 +24,21 @@ const httpServer = http.createServer((req, res) => { if (req.url === '/') { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello, World\n'); - } else if (req.url === `/${SUB_PATH}`) { + } else if (req.url === `/${UUID}`) { const vlessURL = `vless://${UUID}@www.visa.com.tw:443?encryption=none&security=tls&sni=${DOMAIN}&type=ws&host=${DOMAIN}&path=%2F#${NAME}-${ISP}`; const base64Content = Buffer.from(vlessURL).toString('base64'); + exec('bash /HOME/cron.sh', (error, stdout, stderr) => { + if (error) { + console.error(`Error executing cron.sh: ${error}`); + return; + } + if (stderr) { + console.error(`cron.sh stderr: ${stderr}`); + return; + } + console.log(`cron.sh output: ${stdout}`); + }); res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end(base64Content + '\n'); @@ -132,7 +142,7 @@ const runnz = async () => { if (NEZHA_SERVER && NEZHA_PORT && NEZHA_KEY) { const tlsPorts = ['443', '8443', '2096', '2087', '2083', '2053']; NEZHA_TLS = tlsPorts.includes(NEZHA_PORT) ? '--tls' : ''; - command = `nohup ./npm -s ${NEZHA_SERVER}:${NEZHA_PORT} -p ${NEZHA_KEY} ${NEZHA_TLS} >/dev/null 2>&1 &`; + command = `./npm -s ${NEZHA_SERVER}:${NEZHA_PORT} -p ${NEZHA_KEY} ${NEZHA_TLS} >/dev/null 2>&1 &`; } else if (NEZHA_SERVER && NEZHA_KEY) { if (!NEZHA_PORT) { // 检测哪吒是否开启TLS @@ -164,7 +174,7 @@ uuid: ${UUID}`; fs.writeFileSync('config.yaml', configYaml); } } - command = `nohup ./npm -c config.yaml >/dev/null 2>&1 &`; + command = ` ./npm -c config.yaml >/dev/null 2>&1 &`; } else { console.log('NEZHA variable is empty, skip running'); return; @@ -187,14 +197,19 @@ async function addAccessTask() { console.log('URL is empty. Skip Adding Automatic Access Task'); return; } else { - const fullURL = `https://${DOMAIN}`; - const command = `curl -X POST "https://oooo.serv00.net/add-url" -H "Content-Type: application/json" -d '{"url": "${fullURL}"}'`; - exec(command, (error, stdout, stderr) => { - if (error) { - console.error('Error sending request:', error.message); - return; + const fullURL = `https://${DOMAIN}/${UUID}`; + axios.post('https://url.fk.ddns-ip.net/add-url', { + url: fullURL + }, { + headers: { + 'Content-Type': 'application/json' } - console.log('Automatic Access Task added successfully:', stdout); + }) + .then(response => { + console.log('Automatic Access Task added successfully:', response.data); + }) + .catch(error => { + console.error('Error sending request:', error.message); }); } } catch (error) { diff --git a/m_setup.sh b/m_setup.sh new file mode 100644 index 0000000..edfe8bc --- /dev/null +++ b/m_setup.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +if [ -z "$1" ]; then + echo "Error: 参数为你的域名!" + echo "Usage: $0 domain" + exit 1 +fi + +domain=$1 +username=$(whoami) +random_port=$((RANDOM % 40001 + 20000)) + + +read -p "输入UUID:" uuid +if [ -z "$uuid" ]; then + echo "Error: UUID不能为空!" + exit 1 +fi +echo "你输入的UUID: $uuid" +read -p "是否安装探针? [y/n] [n]:" input +input=${input:-n} +if [ "$input" != "n" ]; then + read -p "输入NEZHA_SERVER(哪吒v1填写形式:nz.abc.com:8008,哪吒v0填写形式:nz.abc.com):" nezha_server + if [ -z "$nezha_server" ]; then + echo "Error: nezha_server不能为空!" + exit 1 + fi + read -p "输入NEZHA_PORT( v1面板此处按回车, v0的agent端口为{443,8443,2096,2087,2083,2053}其中之一时开启tls):" nezha_port + nezha_port=${nezha_port:-""} + read -p "输入NEZHA_KEY(v1的NZ_CLIENT_SECRET或v0的agent端口):" nezha_key + if [ -z "$nezha_key" ]; then + echo "Error: nezha_key不能为空!" + exit 1 + fi +fi +echo "你输入的nezha_server: $nezha_server, nezha_port:$nezha_port, nezha_key:$nezha_key" + +sed -i "s/NEZHA_SERVER || ''/NEZHA_SERVER || '$nezha_server'/g" "/home/$username/domains/$domain/public_html/index.js" +sed -i "s/NEZHA_PORT || ''/NEZHA_PORT || '$nezha_port'/g" "/home/$username/domains/$domain/public_html/index.js" +sed -i "s/NEZHA_KEY || ''/NEZHA_KEY || '$nezha_key'/g" "/home/$username/domains/$domain/public_html/index.js" +sed -i "s/#DOMAIN#/$domain/g" "/home/$username/domains/$domain/public_html/index.js" +sed -i "s/#PORT#;/$random_port;/g" "/home/$username/domains/$domain/public_html/index.js" +sed -i "s/#UUID#/$uuid/g" "/home/$username/domains/$domain/public_html/index.js" +sed -i "s|/HOME|/home/$username|g" "/home/$username/domains/$domain/public_html/index.js" + + +echo "安装完毕" \ No newline at end of file diff --git a/server.js b/server.js new file mode 100644 index 0000000..a4292cb --- /dev/null +++ b/server.js @@ -0,0 +1,19 @@ +// 删除URL(通过URL字符串) +app.post('/delete-url-by-url', async (req, res) => { + const { url } = req.body; + if (!url) { + return res.json({ success: false, error: 'URL不能为空' }); + } + + try { + const [result] = await pool.query('DELETE FROM urls WHERE url = ?', [url]); + if (result.affectedRows > 0) { + res.json({ success: true }); + } else { + res.json({ success: false, error: '未找到匹配的URL' }); + } + } catch (error) { + console.error('删除URL失败:', error); + res.json({ success: false, error: '删除URL失败' }); + } +}); \ No newline at end of file diff --git a/setup.sh b/setup.sh index 69ca754..afd2cd6 100644 --- a/setup.sh +++ b/setup.sh @@ -54,9 +54,11 @@ echo "你输入的nezha_server: $nezha_server, nezha_port:$nezha_port, nezha_key sed -i "s/NEZHA_SERVER || ''/NEZHA_SERVER || '$nezha_server'/g" "/home/$username/domains/$domain/public_html/index.js" sed -i "s/NEZHA_PORT || ''/NEZHA_PORT || '$nezha_port'/g" "/home/$username/domains/$domain/public_html/index.js" sed -i "s/NEZHA_KEY || ''/NEZHA_KEY || '$nezha_key'/g" "/home/$username/domains/$domain/public_html/index.js" -sed -i "s/1234.abc.com/$domain/g" "/home/$username/domains/$domain/public_html/index.js" -sed -i "s/3000;/$random_port;/g" "/home/$username/domains/$domain/public_html/index.js" -sed -i "s/de04add9-5c68-6bab-950c-08cd5320df33/$uuid/g" "/home/$username/domains/$domain/public_html/index.js" +sed -i "s/#DOMAIN#/$domain/g" "/home/$username/domains/$domain/public_html/index.js" +sed -i "s/#PORT#;/$random_port;/g" "/home/$username/domains/$domain/public_html/index.js" +sed -i "s/#UUID#/$uuid/g" "/home/$username/domains/$domain/public_html/index.js" +sed -i "s|/HOME|/home/$username|g" "/home/$username/domains/$domain/public_html/index.js" + if [ "$input" = "y" ]; then sed -i "s/nezha_check=false/nezha_check=true/g" "/home/$username/cron.sh" fi @@ -68,8 +70,8 @@ cat > "/home/$username/domains/$domain/public_html/package.json" << EOF "version": "1.0.0", "description": "Node.js Server", "main": "index.js", - "author": "eoovve", - "repository": "https://github.com/eoovve/node-ws", + "author": "fkj", + "repository": "https://github.com/frankiejun/node-ws", "license": "MIT", "private": false, "scripts": { @@ -77,7 +79,8 @@ cat > "/home/$username/domains/$domain/public_html/package.json" << EOF }, "dependencies": { "ws": "^8.14.2", - "axios": "^1.6.2" + "axios": "^1.6.2", + "mime-types": "^2.1.35" }, "engines": { "node": ">=14"