endpoints.ts 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  1. export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'WS';
  2. export type ParamLocation =
  3. | 'path'
  4. | 'query'
  5. | 'header'
  6. | 'body'
  7. | 'body (form)'
  8. | 'body (json)'
  9. | 'body (multipart)';
  10. export type ParamType =
  11. | 'string'
  12. | 'integer'
  13. | 'integer[]'
  14. | 'number'
  15. | 'boolean'
  16. | 'object'
  17. | 'object[]'
  18. | 'array'
  19. | 'file';
  20. export interface EndpointParam {
  21. name: string;
  22. in: ParamLocation;
  23. type: ParamType;
  24. desc?: string;
  25. optional?: boolean;
  26. defaultValue?: string | number | boolean;
  27. }
  28. export interface Endpoint {
  29. method: HttpMethod;
  30. path: string;
  31. summary: string;
  32. description?: string;
  33. deprecated?: boolean;
  34. params?: EndpointParam[];
  35. body?: string;
  36. response?: string;
  37. errorResponse?: string;
  38. errorStatus?: number;
  39. }
  40. export interface SubscriptionHeader {
  41. name: string;
  42. desc: string;
  43. }
  44. export interface Section {
  45. id: string;
  46. title: string;
  47. description?: string;
  48. subHeader?: SubscriptionHeader[];
  49. endpoints: Endpoint[];
  50. }
  51. export const sections: readonly Section[] = [
  52. {
  53. id: 'authentication',
  54. title: 'Authentication',
  55. description:
  56. '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/*.',
  57. endpoints: [
  58. {
  59. method: 'POST',
  60. path: '/login',
  61. summary: 'Authenticate with username + password and receive a session cookie. Required before any cookie-based API call.',
  62. params: [
  63. { name: 'username', in: 'body', type: 'string', desc: 'Panel admin username.' },
  64. { name: 'password', in: 'body', type: 'string', desc: 'Panel admin password.' },
  65. { name: 'twoFactorCode', in: 'body', type: 'string', desc: 'OTP code when 2FA is enabled. Omit otherwise.' },
  66. ],
  67. body: '{\n "username": "admin",\n "password": "admin",\n "twoFactorCode": "123456"\n}',
  68. response:
  69. '{\n "success": true,\n "msg": "Logged in successfully"\n}',
  70. errorResponse:
  71. '{\n "success": false,\n "msg": "Wrong username or password"\n}',
  72. },
  73. {
  74. method: 'POST',
  75. path: '/logout',
  76. summary: 'Clear the session cookie. Requires the CSRF header for browser sessions.',
  77. response: '{\n "success": true\n}',
  78. },
  79. {
  80. method: 'GET',
  81. path: '/csrf-token',
  82. 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.',
  83. response:
  84. '{\n "success": true,\n "obj": "csrf-token-string"\n}',
  85. },
  86. {
  87. method: 'POST',
  88. path: '/getTwoFactorEnable',
  89. summary: 'Returns whether 2FA is enabled on the panel — used by the login page to decide whether to show the OTP field.',
  90. response: '{\n "success": true,\n "obj": false\n}',
  91. },
  92. ],
  93. },
  94. {
  95. id: 'inbounds',
  96. title: 'Inbounds',
  97. description:
  98. '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.',
  99. endpoints: [
  100. {
  101. method: 'GET',
  102. path: '/panel/api/inbounds/list',
  103. summary: 'List every inbound owned by the authenticated user, including each inbound’s clientStats traffic counters. settings, streamSettings, and sniffing are returned as nested JSON objects (no escaped strings); legacy callers that send them back as JSON-encoded strings are still accepted on write.',
  104. response:
  105. '{\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": {\n "clients": [],\n "decryption": "none"\n },\n "streamSettings": {\n "network": "tcp",\n "security": "reality",\n "realitySettings": { "show": false, "dest": "..." }\n },\n "tag": "inbound-443",\n "sniffing": {\n "enabled": true,\n "destOverride": ["http", "tls"]\n },\n "clientStats": []\n }\n ]\n}',
  106. },
  107. {
  108. method: 'GET',
  109. path: '/panel/api/inbounds/list/slim',
  110. summary: 'Same shape as /list but with settings.clients[] stripped down to {email, enable, comment} and ClientStats not enriched with UUID/SubId. Use this for list pages; fetch /get/:id when you need the full per-client payload (uuid, password, flow, ...).',
  111. response:
  112. '{\n "success": true,\n "obj": [\n {\n "id": 1,\n "userId": 1,\n "remark": "VLESS-443",\n "settings": {\n "clients": [\n { "email": "alice", "enable": true }\n ],\n "decryption": "none"\n },\n "clientStats": []\n }\n ]\n}',
  113. },
  114. {
  115. method: 'GET',
  116. path: '/panel/api/inbounds/options',
  117. summary: 'Lightweight picker projection of the authenticated user’s inbounds. Returns only id, remark, protocol, port, and a server-computed tlsFlowCapable flag (true for VLESS / port-fallback on TCP with tls or reality). Use this for dropdowns and attach pickers — it skips settings, streamSettings, and clientStats so the payload stays small even on panels with thousands of clients.',
  118. response:
  119. '{\n "success": true,\n "obj": [\n {\n "id": 1,\n "remark": "VLESS-443",\n "protocol": "vless",\n "port": 443,\n "tlsFlowCapable": true\n }\n ]\n}',
  120. },
  121. {
  122. method: 'GET',
  123. path: '/panel/api/inbounds/get/:id',
  124. summary: 'Fetch a single inbound by numeric ID.',
  125. params: [
  126. { name: 'id', in: 'path', type: 'number', desc: 'Inbound ID.' },
  127. ],
  128. },
  129. {
  130. method: 'POST',
  131. path: '/panel/api/inbounds/add',
  132. summary: 'Create a new inbound. Send the full inbound payload (protocol, port, settings, streamSettings, sniffing, remark, expiryTime, total, enable). settings, streamSettings, and sniffing may be sent as nested JSON objects (preferred) or as JSON-encoded strings (legacy).',
  133. body:
  134. '{\n "enable": true,\n "remark": "VLESS-443",\n "listen": "",\n "port": 443,\n "protocol": "vless",\n "expiryTime": 0,\n "total": 0,\n "settings": {\n "clients": [{ "id": "...", "email": "user1" }],\n "decryption": "none",\n "fallbacks": []\n },\n "streamSettings": {\n "network": "tcp",\n "security": "reality",\n "realitySettings": { "show": false, "dest": "..." }\n },\n "sniffing": {\n "enabled": true,\n "destOverride": ["http", "tls"]\n }\n}',
  135. errorResponse:
  136. '{\n "success": false,\n "msg": "Port 443 is already in use"\n}',
  137. },
  138. {
  139. method: 'POST',
  140. path: '/panel/api/inbounds/del/:id',
  141. summary: 'Delete an inbound by ID. Also removes its associated client stats rows.',
  142. params: [
  143. { name: 'id', in: 'path', type: 'number', desc: 'Inbound ID.' },
  144. ],
  145. },
  146. {
  147. method: 'POST',
  148. path: '/panel/api/inbounds/update/:id',
  149. summary: 'Replace an inbound’s configuration. Body shape mirrors /add. Heavy on inbounds with thousands of clients — prefer /setEnable for enable-only flips.',
  150. params: [
  151. { name: 'id', in: 'path', type: 'number', desc: 'Inbound ID.' },
  152. ],
  153. },
  154. {
  155. method: 'POST',
  156. path: '/panel/api/inbounds/setEnable/:id',
  157. summary: 'Toggle only the enable flag without serialising the whole settings JSON. Recommended for UI switches on large inbounds.',
  158. params: [
  159. { name: 'id', in: 'path', type: 'number', desc: 'Inbound ID.' },
  160. ],
  161. body: '{\n "enable": false\n}',
  162. },
  163. {
  164. method: 'POST',
  165. path: '/panel/api/inbounds/:id/resetTraffic',
  166. summary: 'Zero out upload + download counters for a single inbound. Does not touch per-client counters.',
  167. params: [
  168. { name: 'id', in: 'path', type: 'number', desc: 'Inbound ID.' },
  169. ],
  170. },
  171. {
  172. method: 'POST',
  173. path: '/panel/api/inbounds/resetAllTraffics',
  174. summary: 'Reset upload + download counters on every inbound. Destructive — accounting history is lost.',
  175. },
  176. {
  177. method: 'POST',
  178. path: '/panel/api/inbounds/import',
  179. 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.',
  180. params: [
  181. { name: 'data', in: 'body (form)', type: 'string', desc: 'JSON-encoded inbound payload.' },
  182. ],
  183. },
  184. {
  185. method: 'GET',
  186. path: '/panel/api/inbounds/:id/fallbacks',
  187. summary: 'List the fallback rules attached to a master VLESS/Trojan TCP-TLS inbound. Each rule links one child inbound (the dest) to optional SNI/ALPN/path/xver match criteria.',
  188. params: [
  189. { name: 'id', in: 'path', type: 'number', desc: 'Master inbound ID.' },
  190. ],
  191. response:
  192. '{\n "success": true,\n "obj": [\n {\n "id": 1,\n "masterId": 10,\n "childId": 11,\n "name": "",\n "alpn": "",\n "path": "/vlws",\n "xver": 2,\n "sortOrder": 0\n }\n ]\n}',
  193. },
  194. {
  195. method: 'POST',
  196. path: '/panel/api/inbounds/:id/fallbacks',
  197. summary: 'Replace the entire fallback list for a master inbound. Body is JSON. Triggers an Xray restart.',
  198. params: [
  199. { name: 'id', in: 'path', type: 'number', desc: 'Master inbound ID.' },
  200. { name: 'fallbacks', in: 'body (json)', type: 'object[]', desc: 'Array of {childId, name, alpn, path, xver, sortOrder} entries.' },
  201. ],
  202. body: '{\n "fallbacks": [\n { "childId": 11, "path": "/vlws", "xver": 2 },\n { "childId": 12, "alpn": "h2" }\n ]\n}',
  203. response: '{\n "success": true,\n "msg": "Inbound updated"\n}',
  204. },
  205. ],
  206. },
  207. {
  208. id: 'server',
  209. title: 'Server',
  210. description:
  211. 'System status, log retrieval, certificate generators, Xray binary management, and backup/restore. All under /panel/api/server.',
  212. endpoints: [
  213. {
  214. method: 'GET',
  215. path: '/panel/api/server/status',
  216. 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.',
  217. 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}',
  218. },
  219. {
  220. method: 'GET',
  221. path: '/panel/api/server/cpuHistory/:bucket',
  222. summary: 'Legacy: aggregated CPU history. Use /history/cpu/:bucket instead — same data with a uniform {t, v} shape.',
  223. params: [
  224. { name: 'bucket', in: 'path', type: 'number', desc: 'Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.' },
  225. ],
  226. },
  227. {
  228. method: 'GET',
  229. path: '/panel/api/server/history/:metric/:bucket',
  230. summary: 'Aggregated time-series for one metric. Returns an array of {t, v} samples covering the last ~6 hours.',
  231. params: [
  232. { name: 'metric', in: 'path', type: 'string', desc: 'cpu | mem | netUp | netDown | online | load1 | load5 | load15.' },
  233. { name: 'bucket', in: 'path', type: 'number', desc: 'Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.' },
  234. ],
  235. response: '{\n "success": true,\n "obj": [\n { "t": 1700000000, "v": 12.5 },\n { "t": 1700000002, "v": 13.1 }\n ]\n}',
  236. },
  237. {
  238. method: 'GET',
  239. path: '/panel/api/server/xrayMetricsState',
  240. 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.',
  241. },
  242. {
  243. method: 'GET',
  244. path: '/panel/api/server/xrayMetricsHistory/:metric/:bucket',
  245. summary: 'Time-series history for one Xray runtime metric over the last ~6 hours. Same {t, v} shape as /history/:metric/:bucket.',
  246. params: [
  247. { name: 'metric', in: 'path', type: 'string', desc: 'xrAlloc | xrSys | xrHeapObjects | xrNumGC | xrPauseNs.' },
  248. { name: 'bucket', in: 'path', type: 'number', desc: 'Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.' },
  249. ],
  250. },
  251. {
  252. method: 'GET',
  253. path: '/panel/api/server/xrayObservatory',
  254. 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.',
  255. },
  256. {
  257. method: 'GET',
  258. path: '/panel/api/server/xrayObservatoryHistory/:tag/:bucket',
  259. summary: 'Time-series of observatory probe results for one outbound tag. Same {t, v} shape as the other history endpoints.',
  260. params: [
  261. { name: 'tag', in: 'path', type: 'string', desc: 'Outbound tag from the observatory config.' },
  262. { name: 'bucket', in: 'path', type: 'number', desc: 'Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.' },
  263. ],
  264. },
  265. {
  266. method: 'GET',
  267. path: '/panel/api/server/getXrayVersion',
  268. summary: 'List Xray binary versions available for install on this host.',
  269. response: '{\n "success": true,\n "obj": ["v25.10.31", "v25.9.15", "v25.8.1"]\n}',
  270. },
  271. {
  272. method: 'GET',
  273. path: '/panel/api/server/getPanelUpdateInfo',
  274. summary: 'Check whether a newer 3x-ui release is available on GitHub.',
  275. },
  276. {
  277. method: 'GET',
  278. path: '/panel/api/server/getConfigJson',
  279. summary: 'Return the assembled Xray config that\u2019s currently running on this host.',
  280. response: '{\n "success": true,\n "obj": {\n "log": { "loglevel": "warning" },\n "inbounds": [...],\n "outbounds": [...],\n "routing": { "rules": [...] }\n }\n}',
  281. },
  282. {
  283. method: 'GET',
  284. path: '/panel/api/server/getDb',
  285. summary: 'Stream the SQLite database file as an attachment. Use as a manual backup.',
  286. },
  287. {
  288. method: 'GET',
  289. path: '/panel/api/server/getNewUUID',
  290. summary: 'Generate a fresh UUID v4. Convenience helper for client IDs.',
  291. response: '{\n "success": true,\n "obj": "550e8400-e29b-41d4-a716-446655440000"\n}',
  292. },
  293. {
  294. method: 'GET',
  295. path: '/panel/api/server/getNewX25519Cert',
  296. summary: 'Generate a new X25519 keypair for Reality.',
  297. response: '{\n "success": true,\n "obj": {\n "privateKey": "uN9qLfV3zH8w...",\n "publicKey": "5v8xPqR2sM7k..."\n }\n}',
  298. },
  299. {
  300. method: 'GET',
  301. path: '/panel/api/server/getNewmldsa65',
  302. summary: 'Generate a new ML-DSA-65 keypair (post-quantum signature). Returns {privateKey, publicKey, seed}.',
  303. response: '{\n "success": true,\n "obj": {\n "privateKey": "mdsa65priv...",\n "publicKey": "mdsa65pub...",\n "seed": "random-seed..."\n }\n}',
  304. },
  305. {
  306. method: 'GET',
  307. path: '/panel/api/server/getNewmlkem768',
  308. summary: 'Generate a new ML-KEM-768 keypair (post-quantum KEM). Returns {clientKey, serverKey}.',
  309. response: '{\n "success": true,\n "obj": {\n "clientKey": "mlkem768-client...",\n "serverKey": "mlkem768-server..."\n }\n}',
  310. },
  311. {
  312. method: 'GET',
  313. path: '/panel/api/server/getNewVlessEnc',
  314. summary: 'Generate VLESS encryption auth options. Returns an auths array each with id, label, encryption, and decryption fields.',
  315. response: '{\n "success": true,\n "obj": {\n "auths": [\n { "id": 0, "label": "Auth #0", "encryption": "aes-256-gcm", "decryption": "" }\n ]\n }\n}',
  316. },
  317. {
  318. method: 'POST',
  319. path: '/panel/api/server/stopXrayService',
  320. summary: 'Stop the Xray binary. All proxies go offline immediately.',
  321. errorResponse:
  322. '{\n "success": false,\n "msg": "Xray is not running"\n}',
  323. },
  324. {
  325. method: 'POST',
  326. path: '/panel/api/server/restartXrayService',
  327. summary: 'Reload Xray with the current config. Typically required after structural inbound or routing changes.',
  328. errorResponse:
  329. '{\n "success": false,\n "msg": "Xray config is invalid: ..."\n}',
  330. },
  331. {
  332. method: 'POST',
  333. path: '/panel/api/server/installXray/:version',
  334. summary: 'Download and install the specified Xray version. Pass "latest" for the newest release.',
  335. params: [
  336. { name: 'version', in: 'path', type: 'string', desc: 'Xray tag (e.g. v25.10.31) or "latest".' },
  337. ],
  338. },
  339. {
  340. method: 'POST',
  341. path: '/panel/api/server/updatePanel',
  342. summary: 'Self-update the panel to the latest version. The server restarts on success.',
  343. },
  344. {
  345. method: 'POST',
  346. path: '/panel/api/server/updateGeofile',
  347. summary: 'Refresh the default GeoIP / GeoSite data files. Body can include a fileName, or use the /:fileName variant.',
  348. params: [
  349. { name: 'fileName', in: 'body (form)', type: 'string', desc: 'Filename to update (e.g. geoip.dat, geosite.dat). Omit to update all defaults.' },
  350. ],
  351. body: 'fileName=geoip.dat',
  352. },
  353. {
  354. method: 'POST',
  355. path: '/panel/api/server/updateGeofile/:fileName',
  356. summary: 'Refresh a single Geo file by filename (e.g. geoip.dat, geosite.dat).',
  357. params: [
  358. { name: 'fileName', in: 'path', type: 'string', desc: 'Filename of the data file to refresh.' },
  359. ],
  360. },
  361. {
  362. method: 'POST',
  363. path: '/panel/api/server/logs/:count',
  364. summary: 'Return the last N lines of the panel\u2019s own log.',
  365. params: [
  366. { name: 'count', in: 'path', type: 'number', desc: 'Number of trailing log lines.' },
  367. ],
  368. body: '{\n "level": "info",\n "syslog": false\n}',
  369. 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}',
  370. },
  371. {
  372. method: 'POST',
  373. path: '/panel/api/server/xraylogs/:count',
  374. summary: 'Return the last N lines of the Xray process log.',
  375. params: [
  376. { name: 'count', in: 'path', type: 'number', desc: 'Number of trailing log lines.' },
  377. { name: 'filter', in: 'body (form)', type: 'string', desc: 'Keyword filter — only lines containing this string.' },
  378. { name: 'showDirect', in: 'body (form)', type: 'string', desc: '"true" to include direct (freedom) traffic lines.' },
  379. { name: 'showBlocked', in: 'body (form)', type: 'string', desc: '"true" to include blocked (blackhole) traffic lines.' },
  380. { name: 'showProxy', in: 'body (form)', type: 'string', desc: '"true" to include proxy traffic lines.' },
  381. ],
  382. body: 'filter=error&showDirect=false&showBlocked=true&showProxy=true',
  383. 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}',
  384. },
  385. {
  386. method: 'POST',
  387. path: '/panel/api/server/importDB',
  388. summary: 'Restore the panel DB from an uploaded SQLite file (multipart form, field name "db"). The panel restarts after restore. Destructive.',
  389. params: [
  390. { name: 'db', in: 'body (multipart)', type: 'file', desc: 'SQLite database file to upload.' },
  391. ],
  392. },
  393. {
  394. method: 'POST',
  395. path: '/panel/api/server/getNewEchCert',
  396. summary: 'Generate a new ECH (Encrypted Client Hello) keypair and config list for the given SNI.',
  397. params: [
  398. { name: 'sni', in: 'body (form)', type: 'string', desc: 'Server Name Indication to generate the ECH config for.' },
  399. ],
  400. body: 'sni=example.com',
  401. response: '{\n "success": true,\n "obj": {\n "echKeySet": "...",\n "echServerKeys": [...],\n "echConfigList": "..."\n }\n}',
  402. },
  403. ],
  404. },
  405. {
  406. id: 'clients',
  407. title: 'Clients',
  408. description:
  409. 'Manage clients as first-class entities that can be attached to one or more inbounds. A single client row drives the settings.clients entry in every inbound it belongs to. Endpoints live under /panel/api/clients.',
  410. endpoints: [
  411. {
  412. method: 'GET',
  413. path: '/panel/api/clients/list',
  414. summary: 'List every client with its attached inbound IDs and traffic record. The reverse field, if set, is returned as a nested JSON object (legacy JSON-encoded-string form is still accepted on write).',
  415. response:
  416. '{\n "success": true,\n "obj": [\n {\n "id": 1,\n "email": "[email protected]",\n "subId": "abcd1234",\n "uuid": "...",\n "totalGB": 53687091200,\n "expiryTime": 1735689600000,\n "enable": true,\n "reverse": null,\n "inboundIds": [3, 5],\n "traffic": { "up": 1024, "down": 4096, "enable": true }\n }\n ]\n}',
  417. },
  418. {
  419. method: 'GET',
  420. path: '/panel/api/clients/list/paged',
  421. summary: 'Filter, sort, and paginate clients on the server. Each item is a slim row (no uuid/password/auth/flow/security/reverse/tgId) so the clients page can ship 25-ish rows in a few KB instead of the full table. The response also includes a summary computed across the full DB row set so dashboard counters stay stable as the user paginates or filters. Page size capped at 200; fetch /get/:email to obtain the full per-client payload for an edit/info modal.',
  422. params: [
  423. { name: 'page', in: 'query', type: 'number', desc: '1-indexed page number. Defaults to 1.' },
  424. { name: 'pageSize', in: 'query', type: 'number', desc: 'Rows per page. Defaults to 25, capped at 200.' },
  425. { name: 'search', in: 'query', type: 'string', desc: 'Case-insensitive substring match on email / subId / comment.' },
  426. { name: 'filter', in: 'query', type: 'string', desc: 'Status bucket: online | active | deactive | depleted | expiring.' },
  427. { name: 'protocol', in: 'query', type: 'string', desc: 'Match clients attached to at least one inbound of this protocol (vless, vmess, trojan, shadowsocks, ...).' },
  428. { name: 'sort', in: 'query', type: 'string', desc: 'Sort key: enable | email | inboundIds | traffic | remaining | expiryTime.' },
  429. { name: 'order', in: 'query', type: 'string', desc: 'ascend or descend.' },
  430. ],
  431. response:
  432. '{\n "success": true,\n "obj": {\n "items": [\n {\n "email": "[email protected]",\n "subId": "abcd1234",\n "enable": true,\n "totalGB": 53687091200,\n "expiryTime": 1735689600000,\n "limitIp": 0,\n "reset": 0,\n "inboundIds": [3, 5],\n "traffic": { "up": 1024, "down": 4096, "enable": true },\n "createdAt": 1735000000000,\n "updatedAt": 1735100000000\n }\n ],\n "total": 2000,\n "filtered": 47,\n "page": 1,\n "pageSize": 25,\n "summary": {\n "total": 2000,\n "active": 1850,\n "online": ["[email protected]"],\n "depleted": [],\n "expiring": [],\n "deactive": []\n }\n }\n}',
  433. },
  434. {
  435. method: 'GET',
  436. path: '/panel/api/clients/get/:email',
  437. summary: 'Fetch one client by email, including the inbound IDs it is attached to.',
  438. params: [
  439. { name: 'email', in: 'path', type: 'string', desc: 'Client email (unique identifier).' },
  440. ],
  441. response:
  442. '{\n "success": true,\n "obj": {\n "client": { "id": 1, "email": "[email protected]", ... },\n "inboundIds": [3, 5]\n }\n}',
  443. },
  444. {
  445. method: 'POST',
  446. path: '/panel/api/clients/add',
  447. summary: 'Create a new client and attach it to one or more inbounds in a single call. Body is JSON. Per-protocol secrets (UUID for VLESS/VMess, password for Trojan/Shadowsocks, auth for Hysteria) are generated server-side when omitted, so callers can send only the universal fields.',
  448. params: [
  449. { name: 'client', in: 'body (json)', type: 'object', desc: 'Client fields: email, subId, id (uuid), password, auth, flow, totalGB, expiryTime, limitIp, tgId (numeric Telegram user ID, 0 = none), comment, enable.' },
  450. { name: 'inboundIds', in: 'body (json)', type: 'integer[]', desc: 'Inbound IDs to attach the client to. At least one required.' },
  451. ],
  452. body: '{\n "client": {\n "email": "[email protected]",\n "totalGB": 53687091200,\n "expiryTime": 1735689600000,\n "tgId": 0,\n "limitIp": 0,\n "enable": true\n },\n "inboundIds": [3, 5]\n}',
  453. response: '{\n "success": true,\n "msg": "Client added"\n}',
  454. },
  455. {
  456. method: 'POST',
  457. path: '/panel/api/clients/update/:email',
  458. summary: 'Update an existing client by email. Changes propagate to every attached inbound. Body is the JSON client payload — supply the full set of fields you want to keep (the server replaces the row, it does not patch).',
  459. params: [
  460. { name: 'email', in: 'path', type: 'string', desc: 'Current client email (unique identifier).' },
  461. ],
  462. body: '{\n "email": "[email protected]",\n "totalGB": 107374182400,\n "expiryTime": 1767225600000,\n "tgId": 123456789,\n "enable": true\n}',
  463. response: '{\n "success": true,\n "msg": "Client updated"\n}',
  464. },
  465. {
  466. method: 'POST',
  467. path: '/panel/api/clients/del/:email',
  468. summary: 'Delete a client by email. Removes it from every attached inbound and drops its traffic record unless keepTraffic=1 is passed.',
  469. params: [
  470. { name: 'email', in: 'path', type: 'string', desc: 'Client email (unique identifier).' },
  471. { name: 'keepTraffic', in: 'query', type: 'integer', desc: 'Pass 1 to retain the xray_client_traffic row after deletion.' },
  472. ],
  473. response: '{\n "success": true,\n "msg": "Client deleted"\n}',
  474. },
  475. {
  476. method: 'POST',
  477. path: '/panel/api/clients/:email/attach',
  478. summary: 'Attach an existing client to one or more additional inbounds. Body is JSON.',
  479. params: [
  480. { name: 'email', in: 'path', type: 'string', desc: 'Client email (unique identifier).' },
  481. { name: 'inboundIds', in: 'body (json)', type: 'integer[]', desc: 'Inbound IDs to attach.' },
  482. ],
  483. body: '{\n "inboundIds": [7, 9]\n}',
  484. response: '{\n "success": true\n}',
  485. },
  486. {
  487. method: 'POST',
  488. path: '/panel/api/clients/:email/detach',
  489. summary: 'Detach a client from one or more inbounds without deleting the client.',
  490. params: [
  491. { name: 'email', in: 'path', type: 'string', desc: 'Client email (unique identifier).' },
  492. { name: 'inboundIds', in: 'body (json)', type: 'integer[]', desc: 'Inbound IDs to detach.' },
  493. ],
  494. body: '{\n "inboundIds": [5]\n}',
  495. response: '{\n "success": true\n}',
  496. },
  497. {
  498. method: 'POST',
  499. path: '/panel/api/clients/resetAllTraffics',
  500. summary: 'Reset the up/down counters for every client globally. Quotas and expiry are not affected. Triggers an Xray restart if any counter actually moved.',
  501. response: '{\n "success": true\n}',
  502. },
  503. {
  504. method: 'POST',
  505. path: '/panel/api/clients/delDepleted',
  506. summary: 'Delete every client whose traffic quota is exhausted (used >= total, when reset is disabled) or whose expiry has passed. Returns the deleted count and triggers an Xray restart when any client was on a running inbound.',
  507. response: '{\n "success": true,\n "obj": {\n "deleted": 0\n }\n}',
  508. },
  509. {
  510. method: 'POST',
  511. path: '/panel/api/clients/bulkAdjust',
  512. summary: 'Shift expiry and/or traffic quota for many clients in one call. addDays/addBytes may be negative. Clients with unlimited expiry (expiryTime=0) or unlimited traffic (totalGB=0) are skipped for the corresponding field — bulk extend never converts unlimited to limited. Returns the adjusted count and per-email skip reasons.',
  513. body: '{\n "emails": ["alice", "bob"],\n "addDays": 30,\n "addBytes": 53687091200\n}',
  514. response: '{\n "success": true,\n "obj": {\n "adjusted": 2,\n "skipped": [\n { "email": "carol", "reason": "unlimited expiry" }\n ]\n }\n}',
  515. },
  516. {
  517. method: 'POST',
  518. path: '/panel/api/clients/bulkDel',
  519. summary: 'Delete many clients in one call. The server processes the list sequentially so each delete sees the committed state of the previous one — avoids the race the per-email fan-out had on the panel side. Pass keepTraffic=true to retain the xray_client_traffic rows after deletion.',
  520. body: '{\n "emails": ["alice", "bob"],\n "keepTraffic": false\n}',
  521. response: '{\n "success": true,\n "obj": {\n "deleted": 2,\n "skipped": [\n { "email": "carol", "reason": "client not found" }\n ]\n }\n}',
  522. },
  523. {
  524. method: 'POST',
  525. path: '/panel/api/clients/bulkCreate',
  526. summary: 'Create many clients in one call. Body is a JSON array of {client, inboundIds} payloads — the same shape /add accepts. Items are processed sequentially; per-email skip reasons are returned for items that fail (e.g., duplicate email). Triggers a single Xray restart at the end if any inbound was running.',
  527. body: '[\n {\n "client": {\n "email": "[email protected]",\n "totalGB": 53687091200,\n "expiryTime": 0,\n "enable": true\n },\n "inboundIds": [7]\n },\n {\n "client": {\n "email": "[email protected]",\n "totalGB": 53687091200,\n "expiryTime": 0,\n "enable": true\n },\n "inboundIds": [7, 9]\n }\n]',
  528. response: '{\n "success": true,\n "obj": {\n "created": 2,\n "skipped": [\n { "email": "[email protected]", "reason": "email already in use" }\n ]\n }\n}',
  529. },
  530. {
  531. method: 'POST',
  532. path: '/panel/api/clients/resetTraffic/:email',
  533. summary: 'Zero out a single client’s up/down counters. Re-enables the client across every attached inbound and pushes the change to Xray (or the remote node) so depleted users can connect again immediately.',
  534. params: [
  535. { name: 'email', in: 'path', type: 'string', desc: 'Client email.' },
  536. ],
  537. },
  538. {
  539. method: 'POST',
  540. path: '/panel/api/clients/updateTraffic/:email',
  541. summary: 'Manually adjust a client’s upload + download counters. Useful for migrations from external accounting systems.',
  542. params: [
  543. { name: 'email', in: 'path', type: 'string', desc: 'Client email.' },
  544. ],
  545. body: '{\n "upload": 1073741824,\n "download": 5368709120\n}',
  546. },
  547. {
  548. method: 'POST',
  549. path: '/panel/api/clients/ips/:email',
  550. summary: 'List source IPs that have connected with the given client’s credentials. Returns an array of "ip (timestamp)" strings.',
  551. params: [
  552. { name: 'email', in: 'path', type: 'string', desc: 'Client email.' },
  553. ],
  554. },
  555. {
  556. method: 'POST',
  557. path: '/panel/api/clients/clearIps/:email',
  558. summary: 'Reset the recorded IP list for a client.',
  559. params: [
  560. { name: 'email', in: 'path', type: 'string', desc: 'Client email.' },
  561. ],
  562. },
  563. {
  564. method: 'POST',
  565. path: '/panel/api/clients/onlines',
  566. summary: 'List the emails of currently connected clients (last seen within the heartbeat window).',
  567. response: '{\n "success": true,\n "obj": ["user1", "user2"]\n}',
  568. },
  569. {
  570. method: 'POST',
  571. path: '/panel/api/clients/lastOnline',
  572. summary: 'Map of client email → last-seen unix timestamp.',
  573. response: '{\n "success": true,\n "obj": {\n "user1": 1700000000,\n "user2": 1699999000\n }\n}',
  574. },
  575. {
  576. method: 'GET',
  577. path: '/panel/api/clients/traffic/:email',
  578. summary: 'Traffic counters for a client identified by email.',
  579. params: [
  580. { name: 'email', in: 'path', type: 'string', desc: 'Client email (unique across the panel).' },
  581. ],
  582. response: '{\n "success": true,\n "obj": {\n "email": "user1",\n "up": 1048576,\n "down": 2097152,\n "total": 10737418240,\n "expiryTime": 1735689600000\n }\n}',
  583. },
  584. {
  585. method: 'GET',
  586. path: '/panel/api/clients/subLinks/:subId',
  587. summary:
  588. '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.',
  589. params: [
  590. { name: 'subId', in: 'path', type: 'string', desc: "Subscription ID, taken from the client's subId field." },
  591. ],
  592. response:
  593. '{\n "success": true,\n "obj": [\n "vless://uuid@host:443?security=reality&...#user1",\n "vmess://eyJ2IjoyLC..."\n ]\n}',
  594. },
  595. {
  596. method: 'GET',
  597. path: '/panel/api/clients/links/:email',
  598. summary:
  599. "Return every URL for one client across all attached inbounds — the same strings the Copy URL button copies in the panel UI. Supported protocols: vmess, vless, trojan, shadowsocks, hysteria. If streamSettings.externalProxy is set, returns one URL per external proxy. Protocols without a URL form (socks, http, mixed, wireguard, dokodemo, tunnel) contribute nothing.",
  600. params: [
  601. { name: 'email', in: 'path', type: 'string', desc: 'Client email (unique identifier).' },
  602. ],
  603. response:
  604. '{\n "success": true,\n "obj": [\n "vless://uuid@host:443?...#user1"\n ]\n}',
  605. },
  606. ],
  607. },
  608. {
  609. id: 'nodes',
  610. title: 'Nodes',
  611. description:
  612. 'Manage remote 3x-ui panels acting as nodes for a central panel. All endpoints under /panel/api/nodes.',
  613. endpoints: [
  614. {
  615. method: 'GET',
  616. path: '/panel/api/nodes/list',
  617. summary: 'List every configured node with its connection details, health, and last heartbeat patch.',
  618. response: '{\n "success": true,\n "obj": [\n {\n "id": 1,\n "name": "de-fra-1",\n "remark": "",\n "scheme": "https",\n "address": "node1.example.com",\n "port": 2053,\n "basePath": "/",\n "apiToken": "abcdef...",\n "enable": true,\n "allowPrivateAddress": false,\n "status": "online",\n "lastHeartbeat": 1700000000,\n "latencyMs": 42,\n "xrayVersion": "25.x.x",\n "panelVersion": "v3.x.x",\n "cpuPct": 23.5,\n "memPct": 45.1,\n "uptimeSecs": 86400,\n "lastError": "",\n "inboundCount": 5,\n "clientCount": 27,\n "onlineCount": 3,\n "depletedCount": 1,\n "createdAt": 1700000000,\n "updatedAt": 1700000000\n }\n ]\n}',
  619. },
  620. {
  621. method: 'GET',
  622. path: '/panel/api/nodes/get/:id',
  623. summary: 'Fetch a single node by ID.',
  624. params: [
  625. { name: 'id', in: 'path', type: 'number', desc: 'Node ID.' },
  626. ],
  627. },
  628. {
  629. method: 'POST',
  630. path: '/panel/api/nodes/add',
  631. summary: 'Register a new remote node. Provide its URL, apiToken, and optional remark / allowPrivateAddress flag.',
  632. body:
  633. '{\n "name": "de-fra-1",\n "remark": "",\n "scheme": "https",\n "address": "node1.example.com",\n "port": 2053,\n "basePath": "/",\n "apiToken": "abcdef...",\n "enable": true,\n "allowPrivateAddress": false\n}',
  634. },
  635. {
  636. method: 'POST',
  637. path: '/panel/api/nodes/update/:id',
  638. summary: 'Replace a node\u2019s connection details. Same body shape as /add.',
  639. params: [
  640. { name: 'id', in: 'path', type: 'number', desc: 'Node ID.' },
  641. ],
  642. body: '{\n "name": "de-fra-1",\n "remark": "",\n "scheme": "https",\n "address": "node1.example.com",\n "port": 2053,\n "basePath": "/",\n "apiToken": "abcdef...",\n "enable": true,\n "allowPrivateAddress": false\n}',
  643. },
  644. {
  645. method: 'POST',
  646. path: '/panel/api/nodes/del/:id',
  647. summary: 'Delete a node. Inbounds bound to it are not auto-migrated.',
  648. params: [
  649. { name: 'id', in: 'path', type: 'number', desc: 'Node ID.' },
  650. ],
  651. },
  652. {
  653. method: 'POST',
  654. path: '/panel/api/nodes/setEnable/:id',
  655. summary: 'Pause or resume traffic sync with this node.',
  656. params: [
  657. { name: 'id', in: 'path', type: 'number', desc: 'Node ID.' },
  658. ],
  659. body: '{\n "enable": true\n}',
  660. },
  661. {
  662. method: 'POST',
  663. path: '/panel/api/nodes/test',
  664. summary: 'Probe a node without saving it. Uses the body as connection details and returns the same heartbeat snapshot a registered node would have.',
  665. body: '{\n "scheme": "https",\n "address": "node1.example.com",\n "port": 2053,\n "basePath": "/",\n "apiToken": "abcdef..."\n}',
  666. response: '{\n "success": true,\n "obj": {\n "status": "online",\n "latencyMs": 42,\n "xrayVersion": "25.x.x",\n "panelVersion": "v3.x.x",\n "cpuPct": 12.5,\n "memPct": 45.2,\n "uptimeSecs": 86400,\n "error": ""\n }\n}',
  667. },
  668. {
  669. method: 'POST',
  670. path: '/panel/api/nodes/probe/:id',
  671. summary: 'Probe an existing node, updating its cached health state.',
  672. params: [
  673. { name: 'id', in: 'path', type: 'number', desc: 'Node ID.' },
  674. ],
  675. },
  676. {
  677. method: 'GET',
  678. path: '/panel/api/nodes/history/:id/:metric/:bucket',
  679. summary: 'Aggregated metric history for a node — same shape as /server/history, scoped to one node.',
  680. params: [
  681. { name: 'id', in: 'path', type: 'number', desc: 'Node ID.' },
  682. { name: 'metric', in: 'path', type: 'string', desc: 'cpu | mem.' },
  683. { name: 'bucket', in: 'path', type: 'number', desc: 'Bucket size in seconds. Allowed: 2, 30, 60, 120, 180, 300.' },
  684. ],
  685. },
  686. ],
  687. },
  688. {
  689. id: 'custom-geo',
  690. title: 'Custom Geo',
  691. description:
  692. 'Manage user-supplied GeoIP / GeoSite source files. All endpoints under /panel/api/custom-geo.',
  693. endpoints: [
  694. {
  695. method: 'GET',
  696. path: '/panel/api/custom-geo/list',
  697. summary: 'List configured custom geo sources with their type, alias, URL, status, and last-download timestamp.',
  698. },
  699. {
  700. method: 'GET',
  701. path: '/panel/api/custom-geo/aliases',
  702. summary: 'List geo aliases currently usable in routing rules — both built-in defaults and the user-configured ones.',
  703. },
  704. {
  705. method: 'POST',
  706. path: '/panel/api/custom-geo/add',
  707. summary: 'Register a custom geo source. Alias is auto-normalised; URL must point to a .dat / .json blob.',
  708. body:
  709. '{\n "type": "geoip",\n "alias": "myips",\n "url": "https://example.com/geo/my.dat"\n}',
  710. },
  711. {
  712. method: 'POST',
  713. path: '/panel/api/custom-geo/update/:id',
  714. summary: 'Replace a custom geo source. Same body shape as /add.',
  715. params: [
  716. { name: 'id', in: 'path', type: 'number', desc: 'Custom geo source ID.' },
  717. ],
  718. },
  719. {
  720. method: 'POST',
  721. path: '/panel/api/custom-geo/delete/:id',
  722. summary: 'Remove a custom geo source and its cached file.',
  723. params: [
  724. { name: 'id', in: 'path', type: 'number', desc: 'Custom geo source ID.' },
  725. ],
  726. },
  727. {
  728. method: 'POST',
  729. path: '/panel/api/custom-geo/download/:id',
  730. summary: 'Re-download one custom geo source on demand.',
  731. params: [
  732. { name: 'id', in: 'path', type: 'number', desc: 'Custom geo source ID.' },
  733. ],
  734. },
  735. {
  736. method: 'POST',
  737. path: '/panel/api/custom-geo/update-all',
  738. summary: 'Re-download every configured custom geo source. Errors are reported per-source in the response.',
  739. },
  740. ],
  741. },
  742. {
  743. id: 'backup',
  744. title: 'Backup',
  745. description: 'Operations that interact with the configured Telegram bot.',
  746. endpoints: [
  747. {
  748. method: 'POST',
  749. path: '/panel/api/backuptotgbot',
  750. summary: 'Send a fresh DB backup to every Telegram chat configured as an admin recipient. No body, no params.',
  751. },
  752. ],
  753. },
  754. {
  755. id: 'settings',
  756. title: 'Settings',
  757. description:
  758. 'Panel configuration and user credentials. All endpoints live under /panel/setting and require a logged-in session or Bearer token.',
  759. endpoints: [
  760. {
  761. method: 'POST',
  762. path: '/panel/setting/all',
  763. summary: 'Return every panel setting: web server, Telegram bot, subscription, security, LDAP. The full JSON blob that the Settings page edits.',
  764. 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}',
  765. },
  766. {
  767. method: 'POST',
  768. path: '/panel/setting/defaultSettings',
  769. summary: 'Return the computed default settings based on the request host. Useful to preview what a fresh install would use.',
  770. },
  771. {
  772. method: 'POST',
  773. path: '/panel/setting/update',
  774. 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.',
  775. body: '{\n "webPort": 2053,\n "webBasePath": "/",\n "subPort": 10882,\n "subPath": "/sub/",\n "tgBotEnable": false,\n ...\n}',
  776. },
  777. {
  778. method: 'POST',
  779. path: '/panel/setting/updateUser',
  780. summary: 'Change the panel admin username and password. Requires the current credentials for verification. The session is refreshed with the new values on success.',
  781. params: [
  782. { name: 'oldUsername', in: 'body', type: 'string', desc: 'Current admin username.' },
  783. { name: 'oldPassword', in: 'body', type: 'string', desc: 'Current admin password.' },
  784. { name: 'newUsername', in: 'body', type: 'string', desc: 'Desired new username.' },
  785. { name: 'newPassword', in: 'body', type: 'string', desc: 'Desired new password.' },
  786. ],
  787. body: '{\n "oldUsername": "admin",\n "oldPassword": "admin",\n "newUsername": "newadmin",\n "newPassword": "newpass"\n}',
  788. },
  789. {
  790. method: 'POST',
  791. path: '/panel/setting/restartPanel',
  792. 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.',
  793. },
  794. {
  795. method: 'GET',
  796. path: '/panel/setting/getDefaultJsonConfig',
  797. summary: 'Return the built-in default Xray JSON config template that ships with this panel version.',
  798. },
  799. ],
  800. },
  801. {
  802. id: 'api-tokens',
  803. title: 'API Tokens',
  804. description:
  805. 'Manage Bearer tokens used for programmatic auth (bots, central panels acting on this node, CI). Each token has a unique name and an enabled flag — disable to revoke without deleting, delete to revoke permanently. Tokens are stored plaintext so the SPA can show them on demand. Send one as <code>Authorization: Bearer &lt;token&gt;</code> on any /panel/api/* request.',
  806. endpoints: [
  807. {
  808. method: 'GET',
  809. path: '/panel/setting/apiTokens',
  810. summary: 'List every API token, enabled or not.',
  811. response: '{\n "success": true,\n "obj": [\n {\n "id": 1,\n "name": "default",\n "token": "abcdef-12345-...",\n "enabled": true,\n "createdAt": 1736000000\n }\n ]\n}',
  812. },
  813. {
  814. method: 'POST',
  815. path: '/panel/setting/apiTokens/create',
  816. summary: 'Mint a new API token. Name must be unique and 1-64 characters; the token string is server-generated.',
  817. params: [
  818. { name: 'name', in: 'body', type: 'string', desc: 'Human-readable label, e.g. "central-panel-a".' },
  819. ],
  820. body: '{\n "name": "central-panel-a"\n}',
  821. response: '{\n "success": true,\n "obj": {\n "id": 2,\n "name": "central-panel-a",\n "token": "new-token-string",\n "enabled": true,\n "createdAt": 1736000000\n }\n}',
  822. errorResponse: '{\n "success": false,\n "msg": "a token with that name already exists"\n}',
  823. },
  824. {
  825. method: 'POST',
  826. path: '/panel/setting/apiTokens/delete/:id',
  827. summary: 'Permanently delete a token. Any caller using it stops authenticating immediately.',
  828. params: [
  829. { name: 'id', in: 'path', type: 'number', desc: 'Token row ID.' },
  830. ],
  831. response: '{\n "success": true\n}',
  832. },
  833. {
  834. method: 'POST',
  835. path: '/panel/setting/apiTokens/setEnabled/:id',
  836. summary: 'Toggle a token enabled/disabled without deleting it. Disabled tokens are rejected by checkAPIAuth on the next request.',
  837. params: [
  838. { name: 'id', in: 'path', type: 'number', desc: 'Token row ID.' },
  839. { name: 'enabled', in: 'body', type: 'boolean', desc: 'New enabled state.' },
  840. ],
  841. body: '{\n "enabled": false\n}',
  842. response: '{\n "success": true\n}',
  843. },
  844. ],
  845. },
  846. {
  847. id: 'xray-settings',
  848. title: 'Xray Settings',
  849. description:
  850. 'Xray configuration template, outbound management, Warp/Nord integration, and config testing. All endpoints under /panel/xray.',
  851. endpoints: [
  852. {
  853. method: 'POST',
  854. path: '/panel/xray/',
  855. summary: 'Return the Xray config template (JSON string), available inbound tags, client reverse tags, and the configured outbound test URL in one response.',
  856. 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}',
  857. },
  858. {
  859. method: 'GET',
  860. path: '/panel/xray/getDefaultJsonConfig',
  861. summary: 'Return the built-in default Xray config shipped with the panel (identical to /panel/setting/getDefaultJsonConfig).',
  862. },
  863. {
  864. method: 'GET',
  865. path: '/panel/xray/getOutboundsTraffic',
  866. summary: 'Return traffic statistics for every outbound. Each outbound shows up/down/total counters.',
  867. },
  868. {
  869. method: 'GET',
  870. path: '/panel/xray/getXrayResult',
  871. summary: 'Return the most recent Xray process stdout/stderr output. Useful to check for startup errors or runtime warnings.',
  872. },
  873. {
  874. method: 'POST',
  875. path: '/panel/xray/update',
  876. summary: 'Save the Xray JSON config template and optionally the outbound test URL. Both are sent as form fields.',
  877. params: [
  878. { name: 'xraySetting', in: 'body (form)', type: 'string', desc: 'Full Xray JSON config template.' },
  879. { name: 'outboundTestUrl', in: 'body (form)', type: 'string', desc: 'URL used for outbound reachability tests. Defaults to https://www.google.com/generate_204.' },
  880. ],
  881. },
  882. {
  883. method: 'POST',
  884. path: '/panel/xray/warp/:action',
  885. summary: 'Manage Cloudflare Warp integration. The action parameter selects the operation.',
  886. params: [
  887. { 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).' },
  888. { name: 'privateKey', in: 'body (form)', type: 'string', desc: 'Required when action=reg.' },
  889. { name: 'publicKey', in: 'body (form)', type: 'string', desc: 'Required when action=reg.' },
  890. { name: 'license', in: 'body (form)', type: 'string', desc: 'Required when action=license.' },
  891. ],
  892. },
  893. {
  894. method: 'POST',
  895. path: '/panel/xray/nord/:action',
  896. summary: 'Manage NordVPN integration. The action parameter selects the operation.',
  897. params: [
  898. { 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.' },
  899. { name: 'countryId', in: 'body (form)', type: 'string', desc: 'Required when action=servers.' },
  900. { name: 'token', in: 'body (form)', type: 'string', desc: 'Required when action=reg.' },
  901. { name: 'key', in: 'body (form)', type: 'string', desc: 'Required when action=setKey.' },
  902. ],
  903. },
  904. {
  905. method: 'POST',
  906. path: '/panel/xray/resetOutboundsTraffic',
  907. summary: 'Reset traffic counters for a specific outbound by tag.',
  908. params: [
  909. { name: 'tag', in: 'body (form)', type: 'string', desc: 'Outbound tag to reset (e.g. "proxy", "direct").' },
  910. ],
  911. body: 'tag=proxy',
  912. },
  913. {
  914. method: 'POST',
  915. path: '/panel/xray/testOutbound',
  916. summary: 'Test an outbound configuration. Sends the outbound JSON (required), optionally all outbounds (to resolve sockopt.dialerProxy dependencies), and a mode flag.',
  917. params: [
  918. { name: 'outbound', in: 'body (form)', type: 'string', desc: 'JSON-encoded single outbound to test (required).' },
  919. { name: 'allOutbounds', in: 'body (form)', type: 'string', desc: 'JSON array of all outbounds — used to resolve dialerProxy chains.' },
  920. { 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.' },
  921. ],
  922. body: 'outbound={"protocol":"freedom","settings":{}}&mode=tcp',
  923. },
  924. ],
  925. },
  926. {
  927. id: 'subscription',
  928. title: 'Subscription Server',
  929. description:
  930. '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.',
  931. subHeader: [
  932. { name: 'Subscription-Userinfo', desc: 'Traffic and expiry: <code>upload=N; download=N; total=N; expire=TS</code>' },
  933. { name: 'Profile-Title', desc: 'Base64-encoded subscription display name' },
  934. { name: 'Profile-Web-Page-Url', desc: 'Link to the subscription info page' },
  935. { name: 'Support-Url', desc: 'Support contact URL configured in settings' },
  936. { name: 'Profile-Update-Interval', desc: 'Suggested polling interval in minutes (e.g. <code>10</code>)' },
  937. { name: 'Announce', desc: 'Base64-encoded announcement string' },
  938. { name: 'Routing-Enable', desc: '<code>true</code> or <code>false</code> — whether routing rules are included' },
  939. { name: 'Routing', desc: 'Global routing rules for client apps that support them (e.g. Happ)' },
  940. ],
  941. endpoints: [
  942. {
  943. method: 'GET',
  944. path: '/{subPath}:subid',
  945. 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.',
  946. params: [
  947. { name: 'subid', in: 'path', type: 'string', desc: 'Client subscription ID.' },
  948. ],
  949. },
  950. {
  951. method: 'GET',
  952. path: '/{jsonPath}:subid',
  953. 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.',
  954. params: [
  955. { name: 'subid', in: 'path', type: 'string', desc: 'Client subscription ID.' },
  956. ],
  957. },
  958. {
  959. method: 'GET',
  960. path: '/{clashPath}:subid',
  961. summary: 'Return subscription as a Clash/Mihomo-compatible YAML config. Only when Clash subscription is enabled in settings. Default path: /clash/:subid.',
  962. params: [
  963. { name: 'subid', in: 'path', type: 'string', desc: 'Client subscription ID.' },
  964. ],
  965. },
  966. ],
  967. },
  968. {
  969. id: 'websocket',
  970. title: 'WebSocket',
  971. description:
  972. '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.',
  973. endpoints: [
  974. {
  975. method: 'GET',
  976. path: '/ws',
  977. 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.',
  978. },
  979. {
  980. method: 'WS',
  981. path: '→ type: status',
  982. 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>.',
  983. response: '{\n "type": "status",\n "data": { "cpu": 12.5, "mem": { "current": 2147483648, "total": 8589934592 }, "xray": { "state": "running" } }\n}',
  984. },
  985. {
  986. method: 'WS',
  987. path: '→ type: xrayState',
  988. summary: 'Xray process state change. Fired when Xray starts, stops, or encounters an error.',
  989. response: '{\n "type": "xrayState",\n "data": "running"\n}',
  990. },
  991. {
  992. method: 'WS',
  993. path: '→ type: notification',
  994. summary: 'In-panel toast notification. Fired on Xray stop/restart, DB import, panel restart, etc.',
  995. response: '{\n "type": "notification",\n "title": "Xray service restarted",\n "body": "Xray has been restarted successfully",\n "severity": "success"\n}',
  996. },
  997. {
  998. method: 'WS',
  999. path: '→ type: invalidate',
  1000. summary: 'Instructs the UI to re-fetch a resource. Fired when another admin session modifies data (e.g. toggling inbound enable).',
  1001. response: '{\n "type": "invalidate",\n "resource": "inbounds"\n}',
  1002. },
  1003. ],
  1004. },
  1005. ];