endpoints.js 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. export function safeInlineHtml(input) {
  2. if (!input) return '';
  3. const escape = (s) => s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  4. const open = '<code>';
  5. const close = '</code>';
  6. let out = '';
  7. let i = 0;
  8. while (i < input.length) {
  9. const oIdx = input.indexOf(open, i);
  10. if (oIdx === -1) {
  11. out += escape(input.slice(i));
  12. break;
  13. }
  14. out += escape(input.slice(i, oIdx));
  15. const cIdx = input.indexOf(close, oIdx + open.length);
  16. if (cIdx === -1) {
  17. out += escape(input.slice(oIdx));
  18. break;
  19. }
  20. out += '<code>' + escape(input.slice(oIdx + open.length, cIdx)) + '</code>';
  21. i = cIdx + close.length;
  22. }
  23. return out;
  24. }
  25. export const sections = [
  26. {
  27. id: 'auth',
  28. title: 'Authentication',
  29. description:
  30. 'Two authentication modes are supported. UI sessions use a cookie set by the login endpoint. Programmatic clients (bots, scripts, remote panels) authenticate with a Bearer token taken from Settings → Security → API Token. Both work for every endpoint under /panel/api/*.',
  31. endpoints: [
  32. {
  33. method: 'POST',
  34. path: '/login',
  35. summary: 'Authenticate with username + password and receive a session cookie. Required before any cookie-based API call.',
  36. params: [
  37. { name: 'username', in: 'body', type: 'string', desc: 'Panel admin username.' },
  38. { name: 'password', in: 'body', type: 'string', desc: 'Panel admin password.' },
  39. { name: 'twoFactorCode', in: 'body', type: 'string', desc: 'OTP code when 2FA is enabled. Omit otherwise.' },
  40. ],
  41. body: '{\n "username": "admin",\n "password": "admin",\n "twoFactorCode": "123456"\n}',
  42. response:
  43. '{\n "success": true,\n "msg": "Logged in successfully"\n}',
  44. errorResponse:
  45. '{\n "success": false,\n "msg": "Wrong username or password"\n}',
  46. },
  47. {
  48. method: 'POST',
  49. path: '/logout',
  50. summary: 'Clear the session cookie. Requires the CSRF header for browser sessions.',
  51. response: '{\n "success": true\n}',
  52. },
  53. {
  54. method: 'GET',
  55. path: '/csrf-token',
  56. summary: 'Mint a CSRF token for the current session. The SPA replays it in the X-CSRF-Token header on unsafe requests. Bearer-token callers can skip this — the middleware short-circuits CSRF for authenticated API requests.',
  57. response:
  58. '{\n "success": true,\n "obj": "csrf-token-string"\n}',
  59. },
  60. {
  61. method: 'POST',
  62. path: '/getTwoFactorEnable',
  63. summary: 'Returns whether 2FA is enabled on the panel — used by the login page to decide whether to show the OTP field.',
  64. response: '{\n "success": true,\n "obj": false\n}',
  65. },
  66. ],
  67. },
  68. {
  69. id: 'inbounds',
  70. title: 'Inbounds',
  71. description:
  72. 'Manage inbound configurations and their clients. All endpoints live under /panel/api/inbounds and require a logged-in session or Bearer token. Link-generating endpoints honour forwarded headers only when the request comes from a configured trusted proxy.',
  73. endpoints: [
  74. {
  75. method: 'GET',
  76. path: '/panel/api/inbounds/list',
  77. summary: 'List every inbound owned by the authenticated user, including each inbound’s clientStats traffic counters.',
  78. response:
  79. '{\n "success": true,\n "obj": [\n {\n "id": 1,\n "userId": 1,\n "up": 0,\n "down": 0,\n "total": 0,\n "remark": "VLESS-443",\n "enable": true,\n "expiryTime": 0,\n "listen": "",\n "port": 443,\n "protocol": "vless",\n "settings": "{\\"clients\\":[...]}",\n "streamSettings": "{...}",\n "tag": "inbound-443",\n "sniffing": "{...}",\n "clientStats": [...]\n }\n ]\n}',
  80. },
  81. {
  82. method: 'GET',
  83. path: '/panel/api/inbounds/get/:id',
  84. summary: 'Fetch a single inbound by numeric ID.',
  85. params: [
  86. { name: 'id', in: 'path', type: 'number', desc: 'Inbound ID.' },
  87. ],
  88. },
  89. {
  90. method: 'GET',
  91. path: '/panel/api/inbounds/getClientTraffics/:email',
  92. summary: 'Traffic counters for a client identified by email.',
  93. params: [
  94. { name: 'email', in: 'path', type: 'string', desc: 'Client email (unique across the panel).' },
  95. ],
  96. response: '{\n "success": true,\n "obj": {\n "email": "user1",\n "up": 1048576,\n "down": 2097152,\n "total": 10737418240,\n "expiryTime": 1735689600000\n }\n}',
  97. },
  98. {
  99. method: 'GET',
  100. path: '/panel/api/inbounds/getClientTrafficsById/:id',
  101. summary: 'Traffic counters for a client identified by its UUID/password.',
  102. params: [
  103. { name: 'id', in: 'path', type: 'string', desc: 'Client subId / UUID.' },
  104. ],
  105. response: '{\n "success": true,\n "obj": {\n "email": "user1",\n "up": 1048576,\n "down": 2097152,\n "total": 10737418240,\n "expiryTime": 1735689600000\n }\n}',
  106. },
  107. {
  108. method: 'POST',
  109. path: '/panel/api/inbounds/add',
  110. summary: 'Create a new inbound. Send the full inbound payload (protocol, port, settings JSON, streamSettings JSON, sniffing JSON, remark, expiryTime, total, enable).',
  111. body:
  112. '{\n "enable": true,\n "remark": "VLESS-443",\n "listen": "",\n "port": 443,\n "protocol": "vless",\n "expiryTime": 0,\n "total": 0,\n "settings": "{\\"clients\\":[{\\"id\\":\\"...\\",\\"email\\":\\"user1\\"}],\\"decryption\\":\\"none\\",\\"fallbacks\\":[]}",\n "streamSettings": "{\\"network\\":\\"tcp\\",\\"security\\":\\"reality\\",\\"realitySettings\\":{...}}",\n "sniffing": "{\\"enabled\\":true,\\"destOverride\\":[\\"http\\",\\"tls\\"]}"\n}',
  113. errorResponse:
  114. '{\n "success": false,\n "msg": "Port 443 is already in use"\n}',
  115. },
  116. {
  117. method: 'POST',
  118. path: '/panel/api/inbounds/del/:id',
  119. summary: 'Delete an inbound by ID. Also removes its associated client stats rows.',
  120. params: [
  121. { name: 'id', in: 'path', type: 'number', desc: 'Inbound ID.' },
  122. ],
  123. },
  124. {
  125. method: 'POST',
  126. path: '/panel/api/inbounds/update/:id',
  127. summary: 'Replace an inbound’s configuration. Body shape mirrors /add. Heavy on inbounds with thousands of clients — prefer /setEnable for enable-only flips.',
  128. params: [
  129. { name: 'id', in: 'path', type: 'number', desc: 'Inbound ID.' },
  130. ],
  131. },
  132. {
  133. method: 'POST',
  134. path: '/panel/api/inbounds/setEnable/:id',
  135. summary: 'Toggle only the enable flag without serialising the whole settings JSON. Recommended for UI switches on large inbounds.',
  136. params: [
  137. { name: 'id', in: 'path', type: 'number', desc: 'Inbound ID.' },
  138. ],
  139. body: '{\n "enable": false\n}',
  140. },
  141. {
  142. method: 'POST',
  143. path: '/panel/api/inbounds/clientIps/:email',
  144. summary: 'List source IPs that have connected with the given client’s credentials. Returns an array of "ip (timestamp)" strings.',
  145. params: [
  146. { name: 'email', in: 'path', type: 'string', desc: 'Client email.' },
  147. ],
  148. },
  149. {
  150. method: 'POST',
  151. path: '/panel/api/inbounds/clearClientIps/:email',
  152. summary: 'Reset the recorded IP list for a client.',
  153. params: [
  154. { name: 'email', in: 'path', type: 'string', desc: 'Client email.' },
  155. ],
  156. },
  157. {
  158. method: 'POST',
  159. path: '/panel/api/inbounds/addClient',
  160. summary: 'Add one or more clients to an existing inbound. The settings field is the JSON-encoded settings.clients array of the target inbound.',
  161. body:
  162. '{\n "id": 1,\n "settings": "{\\"clients\\":[{\\"id\\":\\"uuid-here\\",\\"email\\":\\"newuser\\",\\"limitIp\\":0,\\"totalGB\\":0,\\"expiryTime\\":0,\\"enable\\":true,\\"flow\\":\\"\\"}]}"\n}',
  163. },
  164. {
  165. method: 'POST',
  166. path: '/panel/api/inbounds/:id/copyClients',
  167. summary: 'Copy selected clients from one inbound into another. Useful for duplicating user lists across protocols.',
  168. params: [
  169. { name: 'id', in: 'path', type: 'number', desc: 'Target inbound ID.' },
  170. { name: 'sourceInboundId', in: 'body', type: 'number', desc: 'Inbound ID to read clients from.' },
  171. { name: 'clientEmails', in: 'body', type: 'string[]', desc: 'Emails of clients to copy. Empty means all clients.' },
  172. { name: 'flow', in: 'body', type: 'string', desc: 'Override the flow field on copied clients (e.g. "xtls-rprx-vision"). Empty to keep source flow.' },
  173. ],
  174. },
  175. {
  176. method: 'POST',
  177. path: '/panel/api/inbounds/:id/delClient/:clientId',
  178. summary: 'Delete a client by its UUID/password from a specific inbound.',
  179. params: [
  180. { name: 'id', in: 'path', type: 'number', desc: 'Inbound ID.' },
  181. { name: 'clientId', in: 'path', type: 'string', desc: 'Client UUID / password.' },
  182. ],
  183. },
  184. {
  185. method: 'POST',
  186. path: '/panel/api/inbounds/updateClient/:clientId',
  187. summary: 'Update a single client without rewriting the whole settings JSON. Send the target inbound payload with the new client values.',
  188. params: [
  189. { name: 'clientId', in: 'path', type: 'string', desc: 'Client UUID / password.' },
  190. ],
  191. body:
  192. '{\n "id": 1,\n "settings": "{\\"clients\\":[{\\"id\\":\\"uuid-here\\",\\"email\\":\\"user1\\",\\"limitIp\\":2,\\"totalGB\\":10737418240,\\"expiryTime\\":1735689600000,\\"enable\\":true}]}"\n}',
  193. },
  194. {
  195. method: 'POST',
  196. path: '/panel/api/inbounds/:id/resetTraffic',
  197. summary: 'Zero out upload + download counters for a single inbound. Does not touch per-client counters.',
  198. params: [
  199. { name: 'id', in: 'path', type: 'number', desc: 'Inbound ID.' },
  200. ],
  201. },
  202. {
  203. method: 'POST',
  204. path: '/panel/api/inbounds/:id/resetClientTraffic/:email',
  205. summary: 'Zero out upload + download counters for one client.',
  206. params: [
  207. { name: 'id', in: 'path', type: 'number', desc: 'Inbound ID.' },
  208. { name: 'email', in: 'path', type: 'string', desc: 'Client email.' },
  209. ],
  210. },
  211. {
  212. method: 'POST',
  213. path: '/panel/api/inbounds/resetAllTraffics',
  214. summary: 'Reset upload + download counters on every inbound. Destructive — accounting history is lost.',
  215. },
  216. {
  217. method: 'POST',
  218. path: '/panel/api/inbounds/resetAllClientTraffics/:id',
  219. summary: 'Reset traffic for every client in one inbound.',
  220. params: [
  221. { name: 'id', in: 'path', type: 'number', desc: 'Inbound ID.' },
  222. ],
  223. },
  224. {
  225. method: 'POST',
  226. path: '/panel/api/inbounds/delDepletedClients/:id',
  227. summary: 'Delete clients in this inbound whose traffic cap or expiry has elapsed. Pass id=-1 to sweep every inbound.',
  228. params: [
  229. { name: 'id', in: 'path', type: 'number', desc: 'Inbound ID, or -1 for all inbounds.' },
  230. ],
  231. },
  232. {
  233. method: 'POST',
  234. path: '/panel/api/inbounds/import',
  235. summary: 'Bulk-import an inbound from a JSON blob (e.g. one exported via the UI). The body uses form encoding with a single "data" field.',
  236. params: [
  237. { name: 'data', in: 'body (form)', type: 'string', desc: 'JSON-encoded inbound payload.' },
  238. ],
  239. },
  240. {
  241. method: 'POST',
  242. path: '/panel/api/inbounds/onlines',
  243. summary: 'List the emails of currently connected clients (last seen within the heartbeat window).',
  244. response: '{\n "success": true,\n "obj": ["user1", "user2"]\n}',
  245. },
  246. {
  247. method: 'POST',
  248. path: '/panel/api/inbounds/lastOnline',
  249. summary: 'Map of client email → last-seen unix timestamp.',
  250. response: '{\n "success": true,\n "obj": [\n { "email": "user1", "lastOnline": 1700000000 },\n { "email": "user2", "lastOnline": 1699999000 }\n ]\n}',
  251. },
  252. {
  253. method: 'GET',
  254. path: '/panel/api/inbounds/getSubLinks/:subId',
  255. summary:
  256. 'Return every protocol URL (vless://, vmess://, trojan://, ss://, hysteria://, hy2://) for clients matching the subscription ID. Same result set as /sub/<subId>, but as a JSON array — no base64. When an inbound has streamSettings.externalProxy set, one URL is emitted per external proxy. Empty array when the subId has no enabled clients.',
  257. params: [
  258. { name: 'subId', in: 'path', type: 'string', desc: "Subscription ID, taken from the client's subId field." },
  259. ],
  260. response:
  261. '{\n "success": true,\n "obj": [\n "vless://uuid@host:443?security=reality&...#user1",\n "vmess://eyJ2IjoyLC..."\n ]\n}',
  262. },
  263. {
  264. method: 'GET',
  265. path: '/panel/api/inbounds/getClientLinks/:id/:email',
  266. summary:
  267. "Return the URL(s) for one client on one inbound — the same string the Copy URL button copies in the panel UI. Supported protocols: vmess, vless, trojan, shadowsocks, hysteria, hysteria2. If streamSettings.externalProxy is set, returns one URL per external proxy. Protocols without a URL form (socks, http, mixed, wireguard, dokodemo, tunnel) return an empty array.",
  268. params: [
  269. { name: 'id', in: 'path', type: 'number', desc: 'Inbound ID.' },
  270. { name: 'email', in: 'path', type: 'string', desc: 'Client email.' },
  271. ],
  272. response:
  273. '{\n "success": true,\n "obj": [\n "vless://uuid@host:443?...#user1"\n ]\n}',
  274. },
  275. {
  276. method: 'POST',
  277. path: '/panel/api/inbounds/updateClientTraffic/:email',
  278. summary: 'Manually adjust a client’s upload + download counters. Useful for migrations from external accounting systems.',
  279. params: [
  280. { name: 'email', in: 'path', type: 'string', desc: 'Client email.' },
  281. ],
  282. body: '{\n "upload": 1073741824,\n "download": 5368709120\n}',
  283. },
  284. {
  285. method: 'POST',
  286. path: '/panel/api/inbounds/:id/delClientByEmail/:email',
  287. summary: 'Delete a client identified by email rather than UUID.',
  288. params: [
  289. { name: 'id', in: 'path', type: 'number', desc: 'Inbound ID.' },
  290. { name: 'email', in: 'path', type: 'string', desc: 'Client email.' },
  291. ],
  292. },
  293. ],
  294. },
  295. {
  296. id: 'server',
  297. title: 'Server',
  298. description:
  299. 'System status, log retrieval, certificate generators, Xray binary management, and backup/restore. All under /panel/api/server.',
  300. endpoints: [
  301. {
  302. method: 'GET',
  303. path: '/panel/api/server/status',
  304. summary: 'Real-time machine snapshot: CPU, memory, swap, disk, network IO, load averages, open connections, Xray state. Cached and refreshed every 2 seconds in the background.',
  305. response: '{\n "success": true,\n "obj": {\n "cpu": 12.5,\n "mem": { "current": 2147483648, "total": 8589934592 },\n "swap": { "current": 0, "total": 4294967296 },\n "disk": { "current": 53687091200, "total": 268435456000 },\n "netIO": { "up": 1073741824, "down": 2147483648 },\n "xray": { "state": "running", "version": "v25.10.31" },\n "tcpCount": 42,\n "load": { "load1": 0.5, "load5": 0.3, "load15": 0.2 }\n }\n}',
  306. },
  307. {
  308. method: 'GET',
  309. path: '/panel/api/server/cpuHistory/:bucket',
  310. summary: 'Legacy: aggregated CPU history. Use /history/cpu/:bucket instead — same data with a uniform {t, v} shape.',
  311. params: [
  312. { name: 'bucket', in: 'path', type: 'number', desc: 'Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.' },
  313. ],
  314. },
  315. {
  316. method: 'GET',
  317. path: '/panel/api/server/history/:metric/:bucket',
  318. summary: 'Aggregated time-series for one metric. Returns an array of {t, v} samples covering the last ~6 hours.',
  319. params: [
  320. { name: 'metric', in: 'path', type: 'string', desc: 'cpu | mem | netUp | netDown | online | load1 | load5 | load15.' },
  321. { name: 'bucket', in: 'path', type: 'number', desc: 'Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.' },
  322. ],
  323. response: '{\n "success": true,\n "obj": [\n { "t": 1700000000, "v": 12.5 },\n { "t": 1700000002, "v": 13.1 }\n ]\n}',
  324. },
  325. {
  326. method: 'GET',
  327. path: '/panel/api/server/xrayMetricsState',
  328. summary: 'Xray runtime metrics state — whether the xray config has a `metrics` block, which expvar keys are flowing, and the current snapshot values for each. Returns an empty state when metrics are not configured.',
  329. },
  330. {
  331. method: 'GET',
  332. path: '/panel/api/server/xrayMetricsHistory/:metric/:bucket',
  333. summary: 'Time-series history for one Xray runtime metric over the last ~6 hours. Same {t, v} shape as /history/:metric/:bucket.',
  334. params: [
  335. { name: 'metric', in: 'path', type: 'string', desc: 'xrAlloc | xrSys | xrHeapObjects | xrNumGC | xrPauseNs.' },
  336. { name: 'bucket', in: 'path', type: 'number', desc: 'Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.' },
  337. ],
  338. },
  339. {
  340. method: 'GET',
  341. path: '/panel/api/server/xrayObservatory',
  342. summary: 'Latest snapshot from the Xray observatory — per-outbound latency, health status, and last-probe time. Only populated when the Xray config has an observatory configured.',
  343. },
  344. {
  345. method: 'GET',
  346. path: '/panel/api/server/xrayObservatoryHistory/:tag/:bucket',
  347. summary: 'Time-series of observatory probe results for one outbound tag. Same {t, v} shape as the other history endpoints.',
  348. params: [
  349. { name: 'tag', in: 'path', type: 'string', desc: 'Outbound tag from the observatory config.' },
  350. { name: 'bucket', in: 'path', type: 'number', desc: 'Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.' },
  351. ],
  352. },
  353. {
  354. method: 'GET',
  355. path: '/panel/api/server/getXrayVersion',
  356. summary: 'List Xray binary versions available for install on this host.',
  357. response: '{\n "success": true,\n "obj": ["v25.10.31", "v25.9.15", "v25.8.1"]\n}',
  358. },
  359. {
  360. method: 'GET',
  361. path: '/panel/api/server/getPanelUpdateInfo',
  362. summary: 'Check whether a newer 3x-ui release is available on GitHub.',
  363. },
  364. {
  365. method: 'GET',
  366. path: '/panel/api/server/getConfigJson',
  367. summary: 'Return the assembled Xray config that\u2019s currently running on this host.',
  368. response: '{\n "success": true,\n "obj": {\n "log": { "loglevel": "warning" },\n "inbounds": [...],\n "outbounds": [...],\n "routing": { "rules": [...] }\n }\n}',
  369. },
  370. {
  371. method: 'GET',
  372. path: '/panel/api/server/getDb',
  373. summary: 'Stream the SQLite database file as an attachment. Use as a manual backup.',
  374. },
  375. {
  376. method: 'GET',
  377. path: '/panel/api/server/getNewUUID',
  378. summary: 'Generate a fresh UUID v4. Convenience helper for client IDs.',
  379. response: '{\n "success": true,\n "obj": "550e8400-e29b-41d4-a716-446655440000"\n}',
  380. },
  381. {
  382. method: 'GET',
  383. path: '/panel/api/server/getNewX25519Cert',
  384. summary: 'Generate a new X25519 keypair for Reality.',
  385. response: '{\n "success": true,\n "obj": {\n "privateKey": "uN9qLfV3zH8w...",\n "publicKey": "5v8xPqR2sM7k..."\n }\n}',
  386. },
  387. {
  388. method: 'GET',
  389. path: '/panel/api/server/getNewmldsa65',
  390. summary: 'Generate a new ML-DSA-65 keypair (post-quantum signature). Returns {privateKey, publicKey, seed}.',
  391. response: '{\n "success": true,\n "obj": {\n "privateKey": "mdsa65priv...",\n "publicKey": "mdsa65pub...",\n "seed": "random-seed..."\n }\n}',
  392. },
  393. {
  394. method: 'GET',
  395. path: '/panel/api/server/getNewmlkem768',
  396. summary: 'Generate a new ML-KEM-768 keypair (post-quantum KEM). Returns {clientKey, serverKey}.',
  397. response: '{\n "success": true,\n "obj": {\n "clientKey": "mlkem768-client...",\n "serverKey": "mlkem768-server..."\n }\n}',
  398. },
  399. {
  400. method: 'GET',
  401. path: '/panel/api/server/getNewVlessEnc',
  402. summary: 'Generate VLESS encryption auth options. Returns an auths array each with id, label, encryption, and decryption fields.',
  403. response: '{\n "success": true,\n "obj": {\n "auths": [\n { "id": 0, "label": "Auth #0", "encryption": "aes-256-gcm", "decryption": "" }\n ]\n }\n}',
  404. },
  405. {
  406. method: 'POST',
  407. path: '/panel/api/server/stopXrayService',
  408. summary: 'Stop the Xray binary. All proxies go offline immediately.',
  409. errorResponse:
  410. '{\n "success": false,\n "msg": "Xray is not running"\n}',
  411. },
  412. {
  413. method: 'POST',
  414. path: '/panel/api/server/restartXrayService',
  415. summary: 'Reload Xray with the current config. Typically required after structural inbound or routing changes.',
  416. errorResponse:
  417. '{\n "success": false,\n "msg": "Xray config is invalid: ..."\n}',
  418. },
  419. {
  420. method: 'POST',
  421. path: '/panel/api/server/installXray/:version',
  422. summary: 'Download and install the specified Xray version. Pass "latest" for the newest release.',
  423. params: [
  424. { name: 'version', in: 'path', type: 'string', desc: 'Xray tag (e.g. v25.10.31) or "latest".' },
  425. ],
  426. },
  427. {
  428. method: 'POST',
  429. path: '/panel/api/server/updatePanel',
  430. summary: 'Self-update the panel to the latest version. The server restarts on success.',
  431. },
  432. {
  433. method: 'POST',
  434. path: '/panel/api/server/updateGeofile',
  435. summary: 'Refresh the default GeoIP / GeoSite data files. Body can include a fileName, or use the /:fileName variant.',
  436. params: [
  437. { name: 'fileName', in: 'body (form)', type: 'string', desc: 'Filename to update (e.g. geoip.dat, geosite.dat). Omit to update all defaults.' },
  438. ],
  439. body: 'fileName=geoip.dat',
  440. },
  441. {
  442. method: 'POST',
  443. path: '/panel/api/server/updateGeofile/:fileName',
  444. summary: 'Refresh a single Geo file by filename (e.g. geoip.dat, geosite.dat).',
  445. params: [
  446. { name: 'fileName', in: 'path', type: 'string', desc: 'Filename of the data file to refresh.' },
  447. ],
  448. },
  449. {
  450. method: 'POST',
  451. path: '/panel/api/server/logs/:count',
  452. summary: 'Return the last N lines of the panel\u2019s own log.',
  453. params: [
  454. { name: 'count', in: 'path', type: 'number', desc: 'Number of trailing log lines.' },
  455. ],
  456. body: '{\n "level": "info",\n "syslog": false\n}',
  457. response: '{\n "success": true,\n "obj": "2025/01/01 12:00:00 [INFO] Server started\\n2025/01/01 12:00:01 [INFO] Xray is running"\n}',
  458. },
  459. {
  460. method: 'POST',
  461. path: '/panel/api/server/xraylogs/:count',
  462. summary: 'Return the last N lines of the Xray process log.',
  463. params: [
  464. { name: 'count', in: 'path', type: 'number', desc: 'Number of trailing log lines.' },
  465. { name: 'filter', in: 'body (form)', type: 'string', desc: 'Keyword filter — only lines containing this string.' },
  466. { name: 'showDirect', in: 'body (form)', type: 'string', desc: '"true" to include direct (freedom) traffic lines.' },
  467. { name: 'showBlocked', in: 'body (form)', type: 'string', desc: '"true" to include blocked (blackhole) traffic lines.' },
  468. { name: 'showProxy', in: 'body (form)', type: 'string', desc: '"true" to include proxy traffic lines.' },
  469. ],
  470. body: 'filter=error&showDirect=false&showBlocked=true&showProxy=true',
  471. response: '{\n "success": true,\n "obj": "2025/01/01 12:00:00 rejected vless proxy example.com reason: no valid user\\n2025/01/01 12:00:01 direct freedom ok"\n}',
  472. },
  473. {
  474. method: 'POST',
  475. path: '/panel/api/server/importDB',
  476. summary: 'Restore the panel DB from an uploaded SQLite file (multipart form, field name "db"). The panel restarts after restore. Destructive.',
  477. params: [
  478. { name: 'db', in: 'body (multipart)', type: 'file', desc: 'SQLite database file to upload.' },
  479. ],
  480. },
  481. {
  482. method: 'POST',
  483. path: '/panel/api/server/getNewEchCert',
  484. summary: 'Generate a new ECH (Encrypted Client Hello) keypair and config list for the given SNI.',
  485. params: [
  486. { name: 'sni', in: 'body (form)', type: 'string', desc: 'Server Name Indication to generate the ECH config for.' },
  487. ],
  488. body: 'sni=example.com',
  489. response: '{\n "success": true,\n "obj": {\n "echKeySet": "...",\n "echServerKeys": [...],\n "echConfigList": "..."\n }\n}',
  490. },
  491. ],
  492. },
  493. {
  494. id: 'nodes',
  495. title: 'Nodes',
  496. description:
  497. 'Manage remote 3x-ui panels acting as nodes for a central panel. All endpoints under /panel/api/nodes.',
  498. endpoints: [
  499. {
  500. method: 'GET',
  501. path: '/panel/api/nodes/list',
  502. summary: 'List every configured node with its connection details, health, and last heartbeat patch.',
  503. response: '{\n "success": true,\n "obj": [\n {\n "id": 1,\n "name": "de-fra-1",\n "scheme": "https",\n "host": "node1.example.com",\n "port": 2053,\n "status": "online",\n "cpu": 23.5,\n "mem": 45.1\n }\n ]\n}',
  504. },
  505. {
  506. method: 'GET',
  507. path: '/panel/api/nodes/get/:id',
  508. summary: 'Fetch a single node by ID.',
  509. params: [
  510. { name: 'id', in: 'path', type: 'number', desc: 'Node ID.' },
  511. ],
  512. },
  513. {
  514. method: 'POST',
  515. path: '/panel/api/nodes/add',
  516. summary: 'Register a new remote node. Provide its URL, apiToken, and optional label/notes.',
  517. body:
  518. '{\n "name": "de-fra-1",\n "scheme": "https",\n "host": "node1.example.com",\n "port": 2053,\n "basePath": "/",\n "apiToken": "abcdef..."\n}',
  519. },
  520. {
  521. method: 'POST',
  522. path: '/panel/api/nodes/update/:id',
  523. summary: 'Replace a node\u2019s connection details. Same body shape as /add.',
  524. params: [
  525. { name: 'id', in: 'path', type: 'number', desc: 'Node ID.' },
  526. ],
  527. body: '{\n "name": "de-fra-1",\n "scheme": "https",\n "host": "node1.example.com",\n "port": 2053,\n "basePath": "/",\n "apiToken": "abcdef..."\n}',
  528. },
  529. {
  530. method: 'POST',
  531. path: '/panel/api/nodes/del/:id',
  532. summary: 'Delete a node. Inbounds bound to it are not auto-migrated.',
  533. params: [
  534. { name: 'id', in: 'path', type: 'number', desc: 'Node ID.' },
  535. ],
  536. },
  537. {
  538. method: 'POST',
  539. path: '/panel/api/nodes/setEnable/:id',
  540. summary: 'Pause or resume traffic sync with this node.',
  541. params: [
  542. { name: 'id', in: 'path', type: 'number', desc: 'Node ID.' },
  543. ],
  544. body: '{\n "enable": true\n}',
  545. },
  546. {
  547. method: 'POST',
  548. path: '/panel/api/nodes/test',
  549. summary: 'Probe a node without saving it. Uses the body as connection details and returns whether the handshake succeeds.',
  550. body: '{\n "scheme": "https",\n "host": "node1.example.com",\n "port": 2053,\n "basePath": "/",\n "apiToken": "abcdef..."\n}',
  551. response: '{\n "success": true,\n "obj": {\n "status": "online",\n "cpu": 12.5,\n "mem": 45.2\n }\n}',
  552. },
  553. {
  554. method: 'POST',
  555. path: '/panel/api/nodes/probe/:id',
  556. summary: 'Probe an existing node, updating its cached health state.',
  557. params: [
  558. { name: 'id', in: 'path', type: 'number', desc: 'Node ID.' },
  559. ],
  560. },
  561. {
  562. method: 'GET',
  563. path: '/panel/api/nodes/history/:id/:metric/:bucket',
  564. summary: 'Aggregated metric history for a node — same shape as /server/history, scoped to one node.',
  565. params: [
  566. { name: 'id', in: 'path', type: 'number', desc: 'Node ID.' },
  567. { name: 'metric', in: 'path', type: 'string', desc: 'cpu | mem.' },
  568. { name: 'bucket', in: 'path', type: 'number', desc: 'Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.' },
  569. ],
  570. },
  571. ],
  572. },
  573. {
  574. id: 'customGeo',
  575. title: 'Custom Geo',
  576. description:
  577. 'Manage user-supplied GeoIP / GeoSite source files. All endpoints under /panel/api/custom-geo.',
  578. endpoints: [
  579. {
  580. method: 'GET',
  581. path: '/panel/api/custom-geo/list',
  582. summary: 'List configured custom geo sources with their type, alias, URL, status, and last-download timestamp.',
  583. },
  584. {
  585. method: 'GET',
  586. path: '/panel/api/custom-geo/aliases',
  587. summary: 'List geo aliases currently usable in routing rules — both built-in defaults and the user-configured ones.',
  588. },
  589. {
  590. method: 'POST',
  591. path: '/panel/api/custom-geo/add',
  592. summary: 'Register a custom geo source. Alias is auto-normalised; URL must point to a .dat / .json blob.',
  593. body:
  594. '{\n "type": "geoip",\n "alias": "myips",\n "url": "https://example.com/geo/my.dat"\n}',
  595. },
  596. {
  597. method: 'POST',
  598. path: '/panel/api/custom-geo/update/:id',
  599. summary: 'Replace a custom geo source. Same body shape as /add.',
  600. params: [
  601. { name: 'id', in: 'path', type: 'number', desc: 'Custom geo source ID.' },
  602. ],
  603. },
  604. {
  605. method: 'POST',
  606. path: '/panel/api/custom-geo/delete/:id',
  607. summary: 'Remove a custom geo source and its cached file.',
  608. params: [
  609. { name: 'id', in: 'path', type: 'number', desc: 'Custom geo source ID.' },
  610. ],
  611. },
  612. {
  613. method: 'POST',
  614. path: '/panel/api/custom-geo/download/:id',
  615. summary: 'Re-download one custom geo source on demand.',
  616. params: [
  617. { name: 'id', in: 'path', type: 'number', desc: 'Custom geo source ID.' },
  618. ],
  619. },
  620. {
  621. method: 'POST',
  622. path: '/panel/api/custom-geo/update-all',
  623. summary: 'Re-download every configured custom geo source. Errors are reported per-source in the response.',
  624. },
  625. ],
  626. },
  627. {
  628. id: 'backup',
  629. title: 'Backup',
  630. description: 'Operations that interact with the configured Telegram bot.',
  631. endpoints: [
  632. {
  633. method: 'POST',
  634. path: '/panel/api/backuptotgbot',
  635. summary: 'Send a fresh DB backup to every Telegram chat configured as an admin recipient. No body, no params.',
  636. },
  637. ],
  638. },
  639. {
  640. id: 'settings',
  641. title: 'Settings',
  642. description:
  643. 'Panel configuration, user credentials, and API token management. All endpoints live under /panel/setting and require a logged-in session or Bearer token.',
  644. endpoints: [
  645. {
  646. method: 'POST',
  647. path: '/panel/setting/all',
  648. summary: 'Return every panel setting: web server, Telegram bot, subscription, security, LDAP. The full JSON blob that the Settings page edits.',
  649. response: '{\n "success": true,\n "obj": {\n "webPort": 2053,\n "webCertFile": "",\n "webKeyFile": "",\n "webBasePath": "/",\n "subPort": 10882,\n "subPath": "/sub/",\n "tgBotEnable": false,\n "tgBotToken": "",\n ...\n }\n}',
  650. },
  651. {
  652. method: 'POST',
  653. path: '/panel/setting/defaultSettings',
  654. summary: 'Return the computed default settings based on the request host. Useful to preview what a fresh install would use.',
  655. },
  656. {
  657. method: 'POST',
  658. path: '/panel/setting/update',
  659. summary: 'Persist every setting at once. The body mirrors the shape returned by /all. Invalid values (bad ports, missing cert pairs, etc.) are rejected before write.',
  660. body: '{\n "webPort": 2053,\n "webBasePath": "/",\n "subPort": 10882,\n "subPath": "/sub/",\n "tgBotEnable": false,\n ...\n}',
  661. },
  662. {
  663. method: 'POST',
  664. path: '/panel/setting/updateUser',
  665. summary: 'Change the panel admin username and password. Requires the current credentials for verification. The session is refreshed with the new values on success.',
  666. params: [
  667. { name: 'oldUsername', in: 'body', type: 'string', desc: 'Current admin username.' },
  668. { name: 'oldPassword', in: 'body', type: 'string', desc: 'Current admin password.' },
  669. { name: 'newUsername', in: 'body', type: 'string', desc: 'Desired new username.' },
  670. { name: 'newPassword', in: 'body', type: 'string', desc: 'Desired new password.' },
  671. ],
  672. body: '{\n "oldUsername": "admin",\n "oldPassword": "admin",\n "newUsername": "newadmin",\n "newPassword": "newpass"\n}',
  673. },
  674. {
  675. method: 'POST',
  676. path: '/panel/setting/restartPanel',
  677. summary: 'Restart the entire 3x-ui process after a 3-second grace period. The connection drops immediately; the panel comes back online ~5-10 seconds later.',
  678. },
  679. {
  680. method: 'GET',
  681. path: '/panel/setting/getDefaultJsonConfig',
  682. summary: 'Return the built-in default Xray JSON config template that ships with this panel version.',
  683. },
  684. {
  685. method: 'GET',
  686. path: '/panel/setting/getApiToken',
  687. summary: 'Return the current API Bearer token. The token is auto-generated on first read so existing installs upgrade transparently.',
  688. response: '{\n "success": true,\n "obj": "abcdef-12345-..."\n}',
  689. },
  690. {
  691. method: 'POST',
  692. path: '/panel/setting/regenerateApiToken',
  693. summary: 'Rotate the API Bearer token. Any remote central panel that cached the old value will start failing heartbeats until updated with the new token.',
  694. response: '{\n "success": true,\n "obj": "new-token-string"\n}',
  695. },
  696. ],
  697. },
  698. {
  699. id: 'xraySettings',
  700. title: 'Xray Settings',
  701. description:
  702. 'Xray configuration template, outbound management, Warp/Nord integration, and config testing. All endpoints under /panel/xray.',
  703. endpoints: [
  704. {
  705. method: 'POST',
  706. path: '/panel/xray/',
  707. summary: 'Return the Xray config template (JSON string), available inbound tags, client reverse tags, and the configured outbound test URL in one response.',
  708. response: '{\n "success": true,\n "obj": {\n "xraySetting": "{...raw xray config...}",\n "inboundTags": "[\\"inbound-443\\"]",\n "clientReverseTags": "[]",\n "outboundTestUrl": "https://www.google.com/generate_204"\n }\n}',
  709. },
  710. {
  711. method: 'GET',
  712. path: '/panel/xray/getDefaultJsonConfig',
  713. summary: 'Return the built-in default Xray config shipped with the panel (identical to /panel/setting/getDefaultJsonConfig).',
  714. },
  715. {
  716. method: 'GET',
  717. path: '/panel/xray/getOutboundsTraffic',
  718. summary: 'Return traffic statistics for every outbound. Each outbound shows up/down/total counters.',
  719. },
  720. {
  721. method: 'GET',
  722. path: '/panel/xray/getXrayResult',
  723. summary: 'Return the most recent Xray process stdout/stderr output. Useful to check for startup errors or runtime warnings.',
  724. },
  725. {
  726. method: 'POST',
  727. path: '/panel/xray/update',
  728. summary: 'Save the Xray JSON config template and optionally the outbound test URL. Both are sent as form fields.',
  729. params: [
  730. { name: 'xraySetting', in: 'body (form)', type: 'string', desc: 'Full Xray JSON config template.' },
  731. { name: 'outboundTestUrl', in: 'body (form)', type: 'string', desc: 'URL used for outbound reachability tests. Defaults to https://www.google.com/generate_204.' },
  732. ],
  733. },
  734. {
  735. method: 'POST',
  736. path: '/panel/xray/warp/:action',
  737. summary: 'Manage Cloudflare Warp integration. The action parameter selects the operation.',
  738. params: [
  739. { name: 'action', in: 'path', type: 'string', desc: 'data — return Warp stats (quota, remaining). del — delete Warp data. config — return current Warp config. reg — register a new Warp endpoint (sends privateKey, publicKey). license — set a Warp+ license key (sends license).' },
  740. { name: 'privateKey', in: 'body (form)', type: 'string', desc: 'Required when action=reg.' },
  741. { name: 'publicKey', in: 'body (form)', type: 'string', desc: 'Required when action=reg.' },
  742. { name: 'license', in: 'body (form)', type: 'string', desc: 'Required when action=license.' },
  743. ],
  744. },
  745. {
  746. method: 'POST',
  747. path: '/panel/xray/nord/:action',
  748. summary: 'Manage NordVPN integration. The action parameter selects the operation.',
  749. params: [
  750. { name: 'action', in: 'path', type: 'string', desc: 'countries — list available countries. servers — list servers in a country (sends countryId). reg — get NordVPN credentials (sends token). setKey — store NordVPN API key (sends key). data — return current NordVPN connection data. del — delete NordVPN data.' },
  751. { name: 'countryId', in: 'body (form)', type: 'string', desc: 'Required when action=servers.' },
  752. { name: 'token', in: 'body (form)', type: 'string', desc: 'Required when action=reg.' },
  753. { name: 'key', in: 'body (form)', type: 'string', desc: 'Required when action=setKey.' },
  754. ],
  755. },
  756. {
  757. method: 'POST',
  758. path: '/panel/xray/resetOutboundsTraffic',
  759. summary: 'Reset traffic counters for a specific outbound by tag.',
  760. params: [
  761. { name: 'tag', in: 'body (form)', type: 'string', desc: 'Outbound tag to reset (e.g. "proxy", "direct").' },
  762. ],
  763. body: 'tag=proxy',
  764. },
  765. {
  766. method: 'POST',
  767. path: '/panel/xray/testOutbound',
  768. summary: 'Test an outbound configuration. Sends the outbound JSON (required), optionally all outbounds (to resolve sockopt.dialerProxy dependencies), and a mode flag.',
  769. params: [
  770. { name: 'outbound', in: 'body (form)', type: 'string', desc: 'JSON-encoded single outbound to test (required).' },
  771. { name: 'allOutbounds', in: 'body (form)', type: 'string', desc: 'JSON array of all outbounds — used to resolve dialerProxy chains.' },
  772. { name: 'mode', in: 'body (form)', type: 'string', desc: '"tcp" for a fast dial-only probe (parallel-safe). Default/empty uses a full HTTP probe through a temp xray instance.' },
  773. ],
  774. body: 'outbound={"protocol":"freedom","settings":{}}&mode=tcp',
  775. },
  776. ],
  777. },
  778. {
  779. id: 'subscription',
  780. title: 'Subscription Server',
  781. description:
  782. 'A separate HTTP/HTTPS server that serves proxy subscription links (standard, JSON, and Clash) to clients. The server listens on its own port (default 10882) and is configured in Settings → Subscription. Paths are configurable; defaults are shown below. All subscription endpoints set response headers for client apps to read traffic/expiry info.',
  783. subHeader: [
  784. { name: 'Subscription-Userinfo', desc: 'Traffic and expiry: <code>upload=N; download=N; total=N; expire=TS</code>' },
  785. { name: 'Profile-Title', desc: 'Base64-encoded subscription display name' },
  786. { name: 'Profile-Web-Page-Url', desc: 'Link to the subscription info page' },
  787. { name: 'Support-Url', desc: 'Support contact URL configured in settings' },
  788. { name: 'Profile-Update-Interval', desc: 'Suggested polling interval in minutes (e.g. <code>10</code>)' },
  789. { name: 'Announce', desc: 'Base64-encoded announcement string' },
  790. { name: 'Routing-Enable', desc: '<code>true</code> or <code>false</code> — whether routing rules are included' },
  791. { name: 'Routing', desc: 'Global routing rules for client apps that support them (e.g. Happ)' },
  792. ],
  793. endpoints: [
  794. {
  795. method: 'GET',
  796. path: '/{subPath}:subid',
  797. summary: 'Return base64-encoded subscription links for all enabled clients matching the subscription ID. When the request has an Accept: text/html header or ?html=1, renders a styled info page instead. Default path: /sub/:subid.',
  798. params: [
  799. { name: 'subid', in: 'path', type: 'string', desc: 'Client subscription ID.' },
  800. ],
  801. },
  802. {
  803. method: 'GET',
  804. path: '/{jsonPath}:subid',
  805. summary: 'Return subscription as a JSON array of proxy configs (one per enabled client). Only when JSON subscription is enabled in settings. Default path: /json/:subid.',
  806. params: [
  807. { name: 'subid', in: 'path', type: 'string', desc: 'Client subscription ID.' },
  808. ],
  809. },
  810. {
  811. method: 'GET',
  812. path: '/{clashPath}:subid',
  813. summary: 'Return subscription as a Clash/Mihomo-compatible YAML config. Only when Clash subscription is enabled in settings. Default path: /clash/:subid.',
  814. params: [
  815. { name: 'subid', in: 'path', type: 'string', desc: 'Client subscription ID.' },
  816. ],
  817. },
  818. ],
  819. },
  820. {
  821. id: 'websocket',
  822. title: 'WebSocket',
  823. description:
  824. 'Real-time status updates via WebSocket. Connect once at <code>ws://<panel>/ws</code> to receive a stream of JSON messages without polling. Requires an authenticated session cookie (Bearer token auth is not supported). Each message has a <code>type</code> field that identifies the payload shape.',
  825. endpoints: [
  826. {
  827. method: 'GET',
  828. path: '/ws',
  829. summary: 'Upgrade an HTTP connection to a WebSocket. Requires an authenticated session cookie (Bearer token auth is not supported here). Returns 101 Switching Protocols on success. The server then pushes JSON messages described below.',
  830. },
  831. {
  832. method: 'WS',
  833. path: '→ type: status',
  834. summary: 'Server health snapshot pushed every 2 seconds. Contains CPU, memory, swap, disk, network IO, load, and Xray state — same shape as <code>GET /panel/api/server/status</code>.',
  835. response: '{\n "type": "status",\n "data": { "cpu": 12.5, "mem": { "current": 2147483648, "total": 8589934592 }, "xray": { "state": "running" } }\n}',
  836. },
  837. {
  838. method: 'WS',
  839. path: '→ type: xrayState',
  840. summary: 'Xray process state change. Fired when Xray starts, stops, or encounters an error.',
  841. response: '{\n "type": "xrayState",\n "data": "running"\n}',
  842. },
  843. {
  844. method: 'WS',
  845. path: '→ type: notification',
  846. summary: 'In-panel toast notification. Fired on Xray stop/restart, DB import, panel restart, etc.',
  847. response: '{\n "type": "notification",\n "title": "Xray service restarted",\n "body": "Xray has been restarted successfully",\n "severity": "success"\n}',
  848. },
  849. {
  850. method: 'WS',
  851. path: '→ type: invalidate',
  852. summary: 'Instructs the UI to re-fetch a resource. Fired when another admin session modifies data (e.g. toggling inbound enable).',
  853. response: '{\n "type": "invalidate",\n "resource": "inbounds"\n}',
  854. },
  855. ],
  856. },
  857. ];
  858. export const methodColors = {
  859. GET: 'blue',
  860. POST: 'green',
  861. PUT: 'orange',
  862. PATCH: 'orange',
  863. DELETE: 'red',
  864. WS: 'purple',
  865. };