Compare commits
	
		
			12 Commits
		
	
	
		
			3f3d19bc6d
			...
			master
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 3f67dc2b2c | |||
| 10a7bcbd2c | |||
| 1730cb41a3 | |||
| 24f1f88a45 | |||
| 319afb24ec | |||
| d13b80611c | |||
| b03396a467 | |||
| 5142e6f245 | |||
|  | 30236e4359 | ||
|  | 1ac6b88e75 | ||
| 01cccc21c1 | |||
|  | d5798eacdb | 
| @@ -1,11 +1,10 @@ | |||||||
| const { randomUUID } = require("crypto"); | const {randomUUID} = require("crypto"); | ||||||
| const ins = require("../../utils/http"); | const ins = require("../../utils/http"); | ||||||
| const dayjs = require("dayjs"); | const dayjs = require("dayjs"); | ||||||
| const getCookie = require("../../auth/3xuiLogin"); | const getCookie = require("../../auth/3xuiLogin"); | ||||||
| const { log } = require("console"); |  | ||||||
|  |  | ||||||
| module.exports = async (ctx) => { | module.exports = async (ctx) => { | ||||||
|   let { id = 4, limitIp, expiryTime = 0, enable = !0, totalGB = 1, subId = "2rv0gb458kbfl532" } = ctx.request.body; |   let {id = 4, limitIp, expiryTime = 0, enable = !0, totalGB = 1, subId = "2rv0gb458kbfl532", email, uuid} = ctx.request.body; | ||||||
|   if (!ctx.state.cookie) { |   if (!ctx.state.cookie) { | ||||||
|     ctx.state.cookie = await getCookie(); |     ctx.state.cookie = await getCookie(); | ||||||
|     ins.interceptors.request.use((config) => { |     ins.interceptors.request.use((config) => { | ||||||
| @@ -14,31 +13,37 @@ module.exports = async (ctx) => { | |||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
|   const inbound = await ins.get(`/panel/api/inbounds/get/${id}`); |   const inbound = await ins.get(`/panel/api/inbounds/get/${id}`); | ||||||
|   if (!inbound?.success) return (ctx.body = { code: "1", msg: "获取节点失败" }); |   if (!inbound?.success) return (ctx.body = { code: "1", msg: `获取节点失败:${inbound}` }); | ||||||
|   const uuid = randomUUID(), |   uuid = uuid || randomUUID(); | ||||||
|     email = uuid.split("-")[0]; |   email = email || uuid.split("-")[0]; | ||||||
|   if (expiryTime > 0) { |   if (expiryTime != 0) { | ||||||
|     expiryTime = dayjs(expiryTime, "YYYY-MM-DD HH:mm:ss").valueOf(); |     expiryTime = dayjs(expiryTime, "YYYY-MM-DD HH:mm:ss").valueOf(); | ||||||
|   } |   } | ||||||
|   totalGB = totalGB * 1024 * 1024 * 1024; |   totalGB = totalGB * 1024 * 1024 * 1024; | ||||||
|   const settings = { clients: [{ id: uuid, flow: "", email, limitIp, enable, tgId: "", subId, reset: 0, totalGB, expiryTime }] }; |   const settings = {clients: [{id: uuid, flow: "", email, limitIp, enable, tgId: "", subId, reset: 0, totalGB, expiryTime}]}; | ||||||
|   const result = await ins.post("/panel/api/inbounds/addClient", { id, settings: JSON.stringify(settings) }); |   const result = await ins.post("/panel/api/inbounds/addClient", {id, settings: JSON.stringify(settings)}); | ||||||
|   if (result?.success) { |   if (result?.success) { | ||||||
|     const { remark, port, protocol, streamSettings = "{}" } = inbound.obj || {}; |     const {remark, port, protocol, streamSettings = "{}"} = inbound.obj || {}; | ||||||
|     const { |     const setting = JSON.parse(streamSettings || "{}"), {network = "ws", security = "none"} = setting; | ||||||
|       network = "ws", |     if (network === "ws") { | ||||||
|       security = "none", |       const {wsSettings: {host, path}} = setting | ||||||
|       wsSettings: { host, path }, |  | ||||||
|     } = JSON.parse(streamSettings); |  | ||||||
|       ctx.body = { |       ctx.body = { | ||||||
|       code: "0", |         code: "0", message: "success", | ||||||
|         data: `${protocol}://${uuid}@vless.jjcp52.com:${port}?type=${network}&path=${path}&host=${host}&security=${security}#${remark}-${email}`, |         data: `${protocol}://${uuid}@vless.jjcp52.com:${port}?type=${network}&path=${path}&host=${host}&security=${security}#${remark}-${email}`, | ||||||
|       message: "success", |  | ||||||
|       }; |       }; | ||||||
|  |     } else if (network === "tcp") { | ||||||
|  |       // 生成的链接格式 vless://842f52b6-4945-46c8-89ed-165bf51123fc@206.237.11.232:34261?type=tcp&security=reality&pbk=3-yeUp9rz5KacCLJqaLt_rHUY_6EKw6tveLpVB2hxQI&fp=random&sni=yahoo.com&sid=0f7f86d03b646595&spx=%2F#temu-reality-kubbo | ||||||
|  |       const {serverNames: [sni], shortIds: [sid], settings: {publicKey, fingerprint, spiderX}} = (setting.realitySettings || {}) | ||||||
|  |       ctx.body = { | ||||||
|  |         code: "0", message: "success", | ||||||
|  |         data: `${protocol}://${uuid}@vless.jjcp52.com:${port}?type=${network}&security=${security}&pbk=${publicKey}&fp=${fingerprint}&sni=${sni}&sid=${sid}&spx=${spiderX}#${remark}-${email}`, | ||||||
|  |       }; | ||||||
|  |     } | ||||||
|  |  | ||||||
|   } else { |   } else { | ||||||
|     ctx.body = { |     ctx.body = { | ||||||
|       code: 1, |       code: 1, | ||||||
|       message: "添加失败", |       message: "添加失败:" + result?.msg || "未知原因", | ||||||
|       data: ctx.request.body, |       data: ctx.request.body, | ||||||
|     }; |     }; | ||||||
|   } |   } | ||||||
|   | |||||||
							
								
								
									
										19
									
								
								api/client/status.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								api/client/status.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | |||||||
|  | const getCookie = require("../../auth/3xuiLogin"); | ||||||
|  | const instance = require("../../utils/http"); | ||||||
|  |  | ||||||
|  | module.exports = async (ctx) => { | ||||||
|  |   let { id } = ctx.request.query; | ||||||
|  |   if (!ctx.state.cookie) { | ||||||
|  |     ctx.state.cookie = await getCookie(); | ||||||
|  |     instance.interceptors.request.use((config) => { | ||||||
|  |       config.headers.Cookie = ctx.state.cookie; | ||||||
|  |       return config; | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  |   const status = await instance.get(`/panel/api/inbounds/getClientTrafficsById/${id}`); | ||||||
|  |   ctx.body = { | ||||||
|  |     code: 0, | ||||||
|  |     data: status.obj?.[0] || {}, | ||||||
|  |     msg: "success", | ||||||
|  |   }; | ||||||
|  | }; | ||||||
| @@ -1,3 +1,4 @@ | |||||||
| module.exports = (token) => { | module.exports = (token) => { | ||||||
|   return { token, username: token }; |   const AUTH_TOKEN = process.env.AUTH_TOKEN || "pJENcyWA0eg47CsyBaztb2zCyx77D294"; | ||||||
|  |   return token === AUTH_TOKEN ? { token, username: "lsw" } : null; | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -1,11 +1,11 @@ | |||||||
| { | { | ||||||
|   "name": "vless-api", |   "name": "vless-api", | ||||||
|   "version": "1.0.0", |   "version": "1.0.0", | ||||||
|   "description": "", |   "main": "index.js", | ||||||
|   "main": "app.js", |  | ||||||
|   "scripts": { |   "scripts": { | ||||||
|     "start": "node app.js", |     "start": "node index.js", | ||||||
|     "dev": "nodemon app.js" |     "dev": "nodemon index.js", | ||||||
|  |     "build": "pkg index.js --targets=node18-win-x64,node18-linux-x64 --output=dist/" | ||||||
|   }, |   }, | ||||||
|   "author": "kubbo", |   "author": "kubbo", | ||||||
|   "license": "ISC", |   "license": "ISC", | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user