xray-api.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import axios from "axios"
  2. import qs from "qs"
  3. import fs from "fs"
  4. import path from "path"
  5. import { v4 as uuidv4 } from "uuid"
  6. import randomstring from "randomstring"
  7. process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
  8. // const api = axios.create({
  9. // baseURL: "https://scouting0419.mesgity.top:2053/LQvb0quvC2",
  10. // withCredentials: true
  11. // })
  12. // const username = "r962TFfc"
  13. // const password = "hh6a5zSW"
  14. const api = axios.create({
  15. baseURL: "https://endearing.kxmd.xyz:2053/Ujdlw09vra",
  16. withCredentials: true
  17. })
  18. const username = "WtaLZG12"
  19. const password = "woPsrTlu"
  20. async function login() {
  21. const { data, headers } = await api.post(
  22. "login",
  23. qs.stringify({
  24. username,
  25. password
  26. })
  27. )
  28. api.defaults.headers.Cookie = headers["set-cookie"]
  29. }
  30. async function status() {
  31. const { data } = await api.post("server/status")
  32. console.log(data)
  33. }
  34. async function update() {
  35. const { data } = await api.post(
  36. "panel/xray/update",
  37. qs.stringify({
  38. xraySetting: fs.readFileSync(
  39. path.resolve("dist", "xray_edited.json")
  40. )
  41. })
  42. )
  43. console.log(data)
  44. if (!data.success) {
  45. throw new Error(data.message)
  46. }
  47. }
  48. async function restartXray() {
  49. const { data } = await api.post("server/restartXrayService")
  50. console.log(data)
  51. }
  52. async function add(name, users) {
  53. const shortId = randomstring.generate({
  54. length: 8,
  55. charset: "hex"
  56. })
  57. const publicKey = "6jZhBr6PvJDFaU8o0WMeJBzLlwmr-D3hScvT8iM7qW0"
  58. const privateKey = "yGN50gBt8fnx4GLyEnpD1GTjXel5rII7nSVcclC1QzQ"
  59. const port = Math.floor(Math.random() * 3000) + 20000
  60. const clients = users.map(user => {
  61. return {
  62. id: uuidv4(),
  63. flow: "",
  64. email: user,
  65. limitIp: 0,
  66. totalGB: 0,
  67. expiryTime: 0,
  68. enable: true,
  69. tgId: "",
  70. subId: randomstring.generate(16),
  71. reset: 0
  72. }
  73. })
  74. const { data } = await api.post(
  75. "panel/inbound/add",
  76. qs.stringify({
  77. up: 0,
  78. down: 0,
  79. total: 0,
  80. remark: name,
  81. enable: true,
  82. expiryTime: 0,
  83. listen: "",
  84. port,
  85. protocol: "vless",
  86. settings: JSON.stringify({
  87. clients,
  88. decryption: "none",
  89. fallbacks: []
  90. }),
  91. streamSettings: JSON.stringify({
  92. network: "tcp",
  93. security: "reality",
  94. externalProxy: [],
  95. realitySettings: {
  96. show: false,
  97. xver: 0,
  98. dest: "yahoo.com:443",
  99. serverNames: ["yahoo.com", "www.yahoo.com"],
  100. privateKey,
  101. minClient: "",
  102. maxClient: "",
  103. maxTimediff: 0,
  104. shortIds: [shortId],
  105. settings: {
  106. publicKey,
  107. fingerprint: "firefox",
  108. serverName: "",
  109. spiderX: "/"
  110. }
  111. },
  112. tcpSettings: {
  113. acceptProxyProtocol: false,
  114. header: {
  115. type: "none"
  116. }
  117. }
  118. }),
  119. sniffing: JSON.stringify({
  120. enabled: true,
  121. destOverride: ["http", "tls", "quic", "fakedns"],
  122. metadataOnly: false,
  123. routeOnly: false
  124. })
  125. })
  126. )
  127. console.log(data)
  128. if (!data.success) {
  129. throw new Error(data.msg)
  130. }
  131. const server = new URL(api.defaults.baseURL).hostname
  132. return clients.map(client => {
  133. return {
  134. name: client.email,
  135. config: `{name: ${client.email}, server: ${server}, port: ${port}, reality-opts: {public-key: ${publicKey}, short-id: ${shortId}}, client-fingerprint: chrome, type: vless, uuid: ${client.id}, tls: true, tfo: false, skip-cert-verify: false, servername: yahoo.com, network: tcp}`
  136. }
  137. })
  138. }
  139. async function del(id) {
  140. const { data } = await api.post(`panel/inbound/del/${id}`)
  141. console.log(data)
  142. }
  143. await login()
  144. export { login, status, update, restartXray, add, del }