index.html 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645
  1. {{ template "page/head_start" .}}
  2. {{ template "page/head_end" .}}
  3. {{ template "page/body_start" .}}
  4. <style>
  5. body.dark .custom-geo-section code.custom-geo-ext-code {
  6. color: var(--dark-color-text-primary, rgba(255, 255, 255, 0.85));
  7. background: var(--dark-color-surface-200, #222d42);
  8. border: 1px solid var(--dark-color-stroke, #2c3950);
  9. padding: 2px 6px;
  10. border-radius: 3px;
  11. }
  12. html[data-theme="ultra-dark"] body.dark .custom-geo-section code.custom-geo-ext-code {
  13. color: var(--dark-color-text-primary, rgba(255, 255, 255, 0.88));
  14. background: var(--dark-color-surface-700, #111929);
  15. border-color: var(--dark-color-stroke, #2c3950);
  16. }
  17. </style>
  18. <a-layout id="app" v-cloak :class="themeSwitcher.currentTheme + ' index-page'">
  19. <a-sidebar></a-sidebar>
  20. <a-layout id="content-layout">
  21. <a-layout-content>
  22. <a-spin :spinning="loadingStates.spinning" :delay="200" :tip="loadingTip" size="large">
  23. <transition name="list" appear>
  24. <a-alert type="error" v-if="showAlert && loadingStates.fetched" class="mb-10"
  25. message='{{ i18n "secAlertTitle" }}' color="red" description='{{ i18n "secAlertSsl" }}' show-icon closable>
  26. </a-alert>
  27. </transition>
  28. <transition name="list" appear>
  29. <template>
  30. <a-row v-if="!loadingStates.fetched">
  31. <div :style="{ minHeight: 'calc(100vh - 120px)' }"></div>
  32. </a-row>
  33. <a-row :gutter="[isMobile ? 8 : 16, isMobile ? 0 : 12]" v-else>
  34. <a-col>
  35. <a-card hoverable>
  36. <a-row :gutter="[0, isMobile ? 16 : 0]">
  37. <a-col :sm="24" :md="12">
  38. <a-row>
  39. <a-col :span="12" class="text-center">
  40. <a-progress type="dashboard" status="normal" :stroke-color="status.cpu.color"
  41. :percent="status.cpu.percent"></a-progress>
  42. <div>
  43. <b>{{ i18n "pages.index.cpu" }}:</b> [[ CPUFormatter.cpuCoreFormat(status.cpuCores) ]]
  44. <a-tooltip>
  45. <a-icon type="area-chart"></a-icon>
  46. <template slot="title">
  47. <div><b>{{ i18n "pages.index.logicalProcessors" }}:</b> [[ (status.logicalPro) ]]</div>
  48. <div><b>{{ i18n "pages.index.frequency" }}:</b> [[
  49. CPUFormatter.cpuSpeedFormat(status.cpuSpeedMhz) ]]</div>
  50. </template>
  51. </a-tooltip>
  52. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  53. <a-button size="small" shape="circle" class="ml-8" @click="openCpuHistory()">
  54. <a-icon type="history" />
  55. </a-button>
  56. </a-tooltip>
  57. </div>
  58. </a-col>
  59. <a-col :span="12" class="text-center">
  60. <a-progress type="dashboard" status="normal" :stroke-color="status.mem.color"
  61. :percent="status.mem.percent"></a-progress>
  62. <div>
  63. <b>{{ i18n "pages.index.memory"}}:</b> [[ SizeFormatter.sizeFormat(status.mem.current) ]] /
  64. [[ SizeFormatter.sizeFormat(status.mem.total) ]]
  65. </div>
  66. </a-col>
  67. </a-row>
  68. </a-col>
  69. <a-col :sm="24" :md="12">
  70. <a-row>
  71. <a-col :span="12" class="text-center">
  72. <a-progress type="dashboard" status="normal" :stroke-color="status.swap.color"
  73. :percent="status.swap.percent"></a-progress>
  74. <div>
  75. <b>{{ i18n "pages.index.swap" }}:</b> [[ SizeFormatter.sizeFormat(status.swap.current) ]] /
  76. [[ SizeFormatter.sizeFormat(status.swap.total) ]]
  77. </div>
  78. </a-col>
  79. <a-col :span="12" class="text-center">
  80. <a-progress type="dashboard" status="normal" :stroke-color="status.disk.color"
  81. :percent="status.disk.percent"></a-progress>
  82. <div>
  83. <b>{{ i18n "pages.index.storage"}}:</b> [[ SizeFormatter.sizeFormat(status.disk.current) ]]
  84. / [[ SizeFormatter.sizeFormat(status.disk.total) ]]
  85. </div>
  86. </a-col>
  87. </a-row>
  88. </a-col>
  89. </a-row>
  90. </a-card>
  91. </a-col>
  92. <a-col :sm="24" :lg="12">
  93. <a-card hoverable>
  94. <template #title>
  95. <a-space direction="horizontal">
  96. <span>{{ i18n "pages.index.xrayStatus" }}</span>
  97. <a-tag v-if="isMobile && status.xray.version != 'Unknown'" color="green">
  98. v[[ status.xray.version ]]
  99. </a-tag>
  100. </a-space>
  101. </template>
  102. <template #extra>
  103. <template v-if="status.xray.state != 'error'">
  104. <a-badge status="processing"
  105. :class="({ green: 'xray-running-animation', orange: 'xray-stop-animation' }[status.xray.color]) || 'xray-processing-animation'"
  106. :text="status.xray.stateMsg" :color="status.xray.color" />
  107. </template>
  108. <template v-else>
  109. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  110. <span slot="title">
  111. <a-row type="flex" align="middle" justify="space-between">
  112. <a-col>
  113. <span>{{ i18n "pages.index.xrayErrorPopoverTitle" }}</span>
  114. </a-col>
  115. <a-col>
  116. <a-icon type="bars" class="cursor-pointer float-right" @click="openLogs()"></a-icon>
  117. </a-col>
  118. </a-row>
  119. </span>
  120. <template slot="content">
  121. <span class="max-w-400" v-for="line in (status.xray.errorMsg || '').split('\n')">[[ line
  122. ]]</span>
  123. </template>
  124. <a-badge :text="status.xray.stateMsg" :color="status.xray.color"
  125. :class="status.xray.color === 'red' ? 'xray-error-animation' : ''" />
  126. </a-popover>
  127. </template>
  128. </template>
  129. <template #actions>
  130. <a-space v-if="ipLimitEnable" direction="horizontal" @click="openXrayLogs()" class="jc-center">
  131. <a-icon type="bars"></a-icon>
  132. <span v-if="!isMobile">{{ i18n "pages.index.logs" }}</span>
  133. </a-space>
  134. <a-space direction="horizontal" @click="stopXrayService" class="jc-center">
  135. <a-icon type="poweroff"></a-icon>
  136. <span v-if="!isMobile">{{ i18n "pages.index.stopXray" }}</span>
  137. </a-space>
  138. <a-space direction="horizontal" @click="restartXrayService" class="jc-center">
  139. <a-icon type="reload"></a-icon>
  140. <span v-if="!isMobile">{{ i18n "pages.index.restartXray" }}</span>
  141. </a-space>
  142. <a-space direction="horizontal" @click="openSelectV2rayVersion()" class="jc-center">
  143. <a-icon type="tool"></a-icon>
  144. <span v-if="!isMobile">
  145. [[ status.xray.version != 'Unknown' ? `v${status.xray.version}` : '{{ i18n
  146. "pages.index.xraySwitch" }}' ]]
  147. </span>
  148. </a-space>
  149. </template>
  150. </a-card>
  151. </a-col>
  152. <a-col :sm="24" :lg="12">
  153. <a-card title='{{ i18n "menu.link" }}' hoverable>
  154. <template #actions>
  155. <a-space direction="horizontal" @click="openLogs()" class="jc-center">
  156. <a-icon type="bars"></a-icon>
  157. <span v-if="!isMobile">{{ i18n "pages.index.logs" }}</span>
  158. </a-space>
  159. <a-space direction="horizontal" @click="openConfig" class="jc-center">
  160. <a-icon type="control"></a-icon>
  161. <span v-if="!isMobile">{{ i18n "pages.index.config" }}</span>
  162. </a-space>
  163. <a-space direction="horizontal" @click="openBackup" class="jc-center">
  164. <a-icon type="cloud-server"></a-icon>
  165. <span v-if="!isMobile">{{ i18n "pages.index.backup" }}</span>
  166. </a-space>
  167. </template>
  168. </a-card>
  169. </a-col>
  170. <a-col :sm="24" :lg="12">
  171. <a-card title='3X-UI' hoverable>
  172. <template v-if="panelUpdateModal.info.updateAvailable" #extra>
  173. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme"
  174. :title='`{{ i18n "pages.index.updatePanel" }}: ${panelUpdateModal.info.latestVersion}`'>
  175. <a-tag color="orange" style="cursor:pointer;margin:0" @click="openPanelUpdate">
  176. <a-icon type="cloud-download"></a-icon>[[ panelUpdateModal.info.latestVersion ]]
  177. <span v-if="!isMobile">{{ i18n "pages.index.updatePanel" }}</span>
  178. </a-tag>
  179. </a-tooltip>
  180. </template>
  181. <a rel="noopener" href="https://github.com/MHSanaei/3x-ui/releases" target="_blank">
  182. <a-tag color="green">
  183. <span>v{{ .cur_ver }}</span>
  184. </a-tag>
  185. </a>
  186. <a rel="noopener" href="https://t.me/XrayUI" target="_blank">
  187. <a-tag color="green">
  188. <span>@XrayUI</span>
  189. </a-tag>
  190. </a>
  191. <a rel="noopener" href="https://github.com/MHSanaei/3x-ui/wiki" target="_blank">
  192. <a-tag color="purple">
  193. <span>{{ i18n "pages.index.documentation" }}</span>
  194. </a-tag>
  195. </a>
  196. </a-card>
  197. </a-col>
  198. <a-col :sm="24" :lg="12">
  199. <a-card title='{{ i18n "pages.index.operationHours" }}' hoverable>
  200. <a-tag :color="status.xray.color">Xray: [[ TimeFormatter.formatSecond(status.appStats.uptime)
  201. ]]</a-tag>
  202. <a-tag color="green">OS: [[ TimeFormatter.formatSecond(status.uptime) ]]</a-tag>
  203. </a-card>
  204. </a-col>
  205. <a-col :sm="24" :lg="12">
  206. <a-card title='{{ i18n "pages.index.systemLoad" }}' hoverable>
  207. <a-tag color="green">
  208. <a-tooltip>
  209. [[ status.loads[0] ]] | [[ status.loads[1] ]] | [[ status.loads[2] ]]
  210. <template slot="title">
  211. {{ i18n "pages.index.systemLoadDesc" }}
  212. </template>
  213. </a-tooltip>
  214. </a-tag>
  215. </a-card>
  216. </a-col>
  217. <a-col :sm="24" :lg="12">
  218. <a-card title='{{ i18n "usage"}}' hoverable>
  219. <a-tag color="green"> {{ i18n "pages.index.memory" }}: [[
  220. SizeFormatter.sizeFormat(status.appStats.mem) ]] </a-tag>
  221. <a-tag color="green"> {{ i18n "pages.index.threads" }}: [[ status.appStats.threads ]] </a-tag>
  222. </a-card>
  223. </a-col>
  224. <a-col :sm="24" :lg="12">
  225. <a-card title='{{ i18n "pages.index.overallSpeed" }}' hoverable>
  226. <a-row :gutter="isMobile ? [8,8] : 0">
  227. <a-col :span="12">
  228. <a-custom-statistic title='{{ i18n "pages.index.upload" }}'
  229. :value="SizeFormatter.sizeFormat(status.netIO.up)">
  230. <template #prefix>
  231. <a-icon type="arrow-up" />
  232. </template>
  233. <template #suffix>
  234. /s
  235. </template>
  236. </a-custom-statistic>
  237. </a-col>
  238. <a-col :span="12">
  239. <a-custom-statistic title='{{ i18n "pages.index.download" }}'
  240. :value="SizeFormatter.sizeFormat(status.netIO.down)">
  241. <template #prefix>
  242. <a-icon type="arrow-down" />
  243. </template>
  244. <template #suffix>
  245. /s
  246. </template>
  247. </a-custom-statistic>
  248. </a-col>
  249. </a-row>
  250. </a-card>
  251. </a-col>
  252. <a-col :sm="24" :lg="12">
  253. <a-card title='{{ i18n "pages.index.totalData" }}' hoverable>
  254. <a-row :gutter="isMobile ? [8,8] : 0">
  255. <a-col :span="12">
  256. <a-custom-statistic title='{{ i18n "pages.index.sent" }}'
  257. :value="SizeFormatter.sizeFormat(status.netTraffic.sent)">
  258. <template #prefix>
  259. <a-icon type="cloud-upload" />
  260. </template>
  261. </a-custom-statistic>
  262. </a-col>
  263. <a-col :span="12">
  264. <a-custom-statistic title='{{ i18n "pages.index.received" }}'
  265. :value="SizeFormatter.sizeFormat(status.netTraffic.recv)">
  266. <template #prefix>
  267. <a-icon type="cloud-download" />
  268. </template>
  269. </a-custom-statistic>
  270. </a-col>
  271. </a-row>
  272. </a-card>
  273. </a-col>
  274. <a-col :sm="24" :lg="12">
  275. <a-card title='{{ i18n "pages.index.ipAddresses" }}' hoverable>
  276. <template #extra>
  277. <a-tooltip :placement="isMobile ? 'topRight' : 'top'">
  278. <template #title>
  279. {{ i18n "pages.index.toggleIpVisibility" }}
  280. </template>
  281. <a-icon :type="showIp ? 'eye' : 'eye-invisible'" class="fs-1rem"
  282. @click="showIp = !showIp"></a-icon>
  283. </a-tooltip>
  284. </template>
  285. <a-row :class="showIp ? 'ip-visible' : 'ip-hidden'" :gutter="isMobile ? [8,8] : 0">
  286. <a-col :span="isMobile ? 24 : 12">
  287. <a-custom-statistic title="IPv4" :value="status.publicIP.ipv4">
  288. <template #prefix>
  289. <a-icon type="global" />
  290. </template>
  291. </a-custom-statistic>
  292. </a-col>
  293. <a-col :span="isMobile ? 24 : 12">
  294. <a-custom-statistic title="IPv6" :value="status.publicIP.ipv6">
  295. <template #prefix>
  296. <a-icon type="global" />
  297. </template>
  298. </a-custom-statistic>
  299. </a-col>
  300. </a-row>
  301. </a-card>
  302. </a-col>
  303. <a-col :sm="24" :lg="12">
  304. <a-card title='{{ i18n "pages.index.connectionCount" }}' hoverable>
  305. <a-row :gutter="isMobile ? [8,8] : 0">
  306. <a-col :span="12">
  307. <a-custom-statistic title="TCP" :value="status.tcpCount">
  308. <template #prefix>
  309. <a-icon type="swap" />
  310. </template>
  311. </a-custom-statistic>
  312. </a-col>
  313. <a-col :span="12">
  314. <a-custom-statistic title="UDP" :value="status.udpCount">
  315. <template #prefix>
  316. <a-icon type="swap" />
  317. </template>
  318. </a-custom-statistic>
  319. </a-col>
  320. </a-row>
  321. </a-card>
  322. </a-col>
  323. </a-row>
  324. </template>
  325. </transition>
  326. </a-spin>
  327. </a-layout-content>
  328. </a-layout>
  329. <a-modal id="panel-update-modal" v-model="panelUpdateModal.visible" title='{{ i18n "pages.index.updatePanel" }}'
  330. :closable="true" @ok="() => panelUpdateModal.visible = false" :class="themeSwitcher.currentTheme" footer="">
  331. <a-alert type="warning" class="mb-12 w-100" message='{{ i18n "pages.index.panelUpdateDesc" }}' show-icon></a-alert>
  332. <a-list class="ant-version-list w-100" bordered>
  333. <a-list-item class="ant-version-list-item">
  334. <span>{{ i18n "pages.index.currentPanelVersion" }}</span>
  335. <a-tag color="green">v[[ panelUpdateModal.info.currentVersion || '{{ .cur_ver }}' ]]</a-tag>
  336. </a-list-item>
  337. <a-list-item class="ant-version-list-item" v-if="panelUpdateModal.info.updateAvailable">
  338. <span>{{ i18n "pages.index.latestPanelVersion" }}</span>
  339. <a-tag color="purple">
  340. [[ panelUpdateModal.info.latestVersion || '-' ]]
  341. </a-tag>
  342. </a-list-item>
  343. <a-list-item class="ant-version-list-item" v-else>
  344. <span>{{ i18n "pages.index.panelUpToDate" }}</span>
  345. <a-tag color="green">{{ i18n "pages.index.upToDate" }}</a-tag>
  346. </a-list-item>
  347. </a-list>
  348. <div class="mt-5 d-flex justify-end">
  349. <a-button type="primary" icon="cloud-download" :disabled="!panelUpdateModal.info.updateAvailable"
  350. @click="updatePanel">
  351. {{ i18n "pages.index.updatePanel" }}
  352. </a-button>
  353. </div>
  354. </a-modal>
  355. <a-modal id="version-modal" v-model="versionModal.visible" title='{{ i18n "pages.index.xrayUpdates" }}'
  356. :closable="true" @ok="() => versionModal.visible = false" :class="themeSwitcher.currentTheme" footer="">
  357. <a-collapse accordion :active-key="versionModal.activeKey" @change="key => versionModal.activeKey = key">
  358. <a-collapse-panel key="1" header='Xray'>
  359. <a-alert type="warning" class="mb-12 w-100" message='{{ i18n "pages.index.xraySwitchClickDesk" }}'
  360. show-icon></a-alert>
  361. <a-list class="ant-version-list w-100" bordered>
  362. <a-list-item class="ant-version-list-item" v-for="version, index in versionModal.versions">
  363. <a-tag :color="index % 2 == 0 ? 'purple' : 'green'">[[ version ]]</a-tag>
  364. <a-radio :class="themeSwitcher.currentTheme" :checked="version === `v${status.xray.version}`"
  365. @click="switchV2rayVersion(version)"></a-radio>
  366. </a-list-item>
  367. </a-list>
  368. </a-collapse-panel>
  369. <a-collapse-panel key="2" header='Geofiles'>
  370. <a-list class="ant-version-list w-100" bordered>
  371. <a-list-item class="ant-version-list-item"
  372. v-for="file, index in ['geosite.dat', 'geoip.dat', 'geosite_IR.dat', 'geoip_IR.dat', 'geosite_RU.dat', 'geoip_RU.dat']">
  373. <a-tag :color="index % 2 == 0 ? 'purple' : 'green'">[[ file ]]</a-tag>
  374. <a-icon type="reload" @click="updateGeofile(file)" class="mr-8" />
  375. </a-list-item>
  376. </a-list>
  377. <div class="mt-5 d-flex justify-end"><a-button @click="updateGeofile('')">{{ i18n
  378. "pages.index.geofilesUpdateAll" }}</a-button></div>
  379. </a-collapse-panel>
  380. <a-collapse-panel key="3" header='{{ i18n "pages.index.customGeoTitle" }}'>
  381. <div class="custom-geo-section">
  382. <a-alert type="info" show-icon class="mb-10"
  383. message='{{ i18n "pages.index.customGeoRoutingHint" }}'></a-alert>
  384. <div class="mb-10">
  385. <a-button type="primary" icon="plus" @click="openCustomGeoModal(null)" :loading="customGeoLoading">
  386. {{ i18n "pages.index.customGeoAdd" }}
  387. </a-button>
  388. <a-button class="ml-8" icon="reload" @click="updateAllCustomGeo" :loading="customGeoUpdatingAll">{{ i18n
  389. "pages.index.geofilesUpdateAll" }}</a-button>
  390. </div>
  391. <a-table :columns="customGeoColumns" :data-source="customGeoList" :pagination="false" :row-key="r => r.id"
  392. :loading="customGeoLoading" size="small" :scroll="{ x: 520 }">
  393. <template slot="extDat" slot-scope="text, record">
  394. <code class="custom-geo-ext-code">[[ customGeoExtDisplay(record) ]]</code>
  395. </template>
  396. <template slot="lastUpdatedAt" slot-scope="text, record">
  397. <span v-if="record.lastUpdatedAt">[[ customGeoFormatTime(record.lastUpdatedAt) ]]</span>
  398. <span v-else>—</span>
  399. </template>
  400. <template slot="action" slot-scope="text, record">
  401. <a-space size="small">
  402. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  403. <template slot="title">{{ i18n "pages.index.customGeoEdit" }}</template>
  404. <a-button type="link" size="small" icon="edit" @click="openCustomGeoModal(record)"></a-button>
  405. </a-tooltip>
  406. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  407. <template slot="title">{{ i18n "pages.index.customGeoDownload" }}</template>
  408. <a-button type="link" size="small" icon="reload" @click="downloadCustomGeo(record.id)"
  409. :loading="customGeoActionId === record.id"></a-button>
  410. </a-tooltip>
  411. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  412. <template slot="title">{{ i18n "pages.index.customGeoDelete" }}</template>
  413. <a-button type="link" size="small" icon="delete" @click="confirmDeleteCustomGeo(record)"></a-button>
  414. </a-tooltip>
  415. </a-space>
  416. </template>
  417. </a-table>
  418. </div>
  419. </a-collapse-panel>
  420. </a-collapse>
  421. </a-modal>
  422. <a-modal v-model="customGeoModal.visible"
  423. :title="customGeoModal.editId ? '{{ i18n "pages.index.customGeoModalEdit" }}' : '{{ i18n "pages.index.customGeoModalAdd" }}'"
  424. :confirm-loading="customGeoModal.saving" @ok="submitCustomGeo"
  425. :ok-text="'{{ i18n "pages.index.customGeoModalSave" }}'" :cancel-text="'{{ i18n "close" }}'"
  426. :class="themeSwitcher.currentTheme">
  427. <a-form layout="vertical">
  428. <a-form-item label='{{ i18n "pages.index.customGeoType" }}'>
  429. <a-select v-model="customGeoModal.form.type" :disabled="!!customGeoModal.editId"
  430. :dropdown-class-name="themeSwitcher.currentTheme">
  431. <a-select-option value="geosite">geosite</a-select-option>
  432. <a-select-option value="geoip">geoip</a-select-option>
  433. </a-select>
  434. </a-form-item>
  435. <a-form-item label='{{ i18n "pages.index.customGeoAlias" }}'>
  436. <a-input v-model.trim="customGeoModal.form.alias" :disabled="!!customGeoModal.editId"
  437. placeholder='{{ i18n "pages.index.customGeoAliasPlaceholder" }}'></a-input>
  438. </a-form-item>
  439. <a-form-item label='{{ i18n "pages.index.customGeoUrl" }}'>
  440. <a-input v-model.trim="customGeoModal.form.url" placeholder="https://"></a-input>
  441. </a-form-item>
  442. </a-form>
  443. </a-modal>
  444. <a-modal id="log-modal" v-model="logModal.visible" :closable="true" @cancel="() => logModal.visible = false"
  445. :class="themeSwitcher.currentTheme" width="800px" footer="">
  446. <template slot="title">
  447. {{ i18n "pages.index.logs" }}
  448. <a-icon :spin="logModal.loading" type="sync" class="va-middle ml-10" :disabled="logModal.loading"
  449. @click="openLogs()">
  450. </a-icon>
  451. </template>
  452. <a-form layout="inline">
  453. <a-form-item class="mr-05">
  454. <a-input-group compact>
  455. <a-select size="small" v-model="logModal.rows" :style="{ width: '70px' }" @change="openLogs()"
  456. :dropdown-class-name="themeSwitcher.currentTheme">
  457. <a-select-option value="10">10</a-select-option>
  458. <a-select-option value="20">20</a-select-option>
  459. <a-select-option value="50">50</a-select-option>
  460. <a-select-option value="100">100</a-select-option>
  461. <a-select-option value="500">500</a-select-option>
  462. </a-select>
  463. <a-select size="small" v-model="logModal.level" :style="{ width: '95px' }" @change="openLogs()"
  464. :dropdown-class-name="themeSwitcher.currentTheme">
  465. <a-select-option value="debug">Debug</a-select-option>
  466. <a-select-option value="info">Info</a-select-option>
  467. <a-select-option value="notice">Notice</a-select-option>
  468. <a-select-option value="warning">Warning</a-select-option>
  469. <a-select-option value="err">Error</a-select-option>
  470. </a-select>
  471. </a-input-group>
  472. </a-form-item>
  473. <a-form-item>
  474. <a-checkbox v-model="logModal.syslog" @change="openLogs()">SysLog</a-checkbox>
  475. </a-form-item>
  476. <a-form-item style="float: right;">
  477. <a-button type="primary" icon="download"
  478. @click="FileManager.downloadTextFile(logModal.logs?.join('\n'), 'x-ui.log')"></a-button>
  479. </a-form-item>
  480. </a-form>
  481. <div class="ant-input log-container" v-html="logModal.formattedLogs"></div>
  482. </a-modal>
  483. <a-modal id="xraylog-modal" v-model="xraylogModal.visible" :closable="true"
  484. @cancel="() => xraylogModal.visible = false" :class="themeSwitcher.currentTheme" width="80vw" footer="">
  485. <template slot="title">
  486. {{ i18n "pages.index.logs" }}
  487. <a-icon :spin="xraylogModal.loading" type="sync" class="va-middle ml-10" :disabled="xraylogModal.loading"
  488. @click="openXrayLogs()">
  489. </a-icon>
  490. </template>
  491. <a-form layout="inline">
  492. <a-form-item class="mr-05">
  493. <a-input-group compact>
  494. <a-select size="small" v-model="xraylogModal.rows" :style="{ width: '70px' }" @change="openXrayLogs()"
  495. :dropdown-class-name="themeSwitcher.currentTheme">
  496. <a-select-option value="10">10</a-select-option>
  497. <a-select-option value="20">20</a-select-option>
  498. <a-select-option value="50">50</a-select-option>
  499. <a-select-option value="100">100</a-select-option>
  500. <a-select-option value="500">500</a-select-option>
  501. </a-select>
  502. </a-input-group>
  503. </a-form-item>
  504. <a-form-item label="Filter:">
  505. <a-input size="small" v-model="xraylogModal.filter" @keyup.enter="openXrayLogs()"></a-input>
  506. </a-form-item>
  507. <a-form-item>
  508. <a-checkbox v-model="xraylogModal.showDirect" @change="openXrayLogs()">Direct</a-checkbox>
  509. <a-checkbox v-model="xraylogModal.showBlocked" @change="openXrayLogs()">Blocked</a-checkbox>
  510. <a-checkbox v-model="xraylogModal.showProxy" @change="openXrayLogs()">Proxy</a-checkbox>
  511. </a-form-item>
  512. <a-form-item style="float: right;">
  513. <a-button type="primary" icon="download" @click="downloadXrayLogs"></a-button>
  514. </a-form-item>
  515. </a-form>
  516. <div class="ant-input log-container" v-html="xraylogModal.formattedLogs"></div>
  517. </a-modal>
  518. <a-modal id="backup-modal" v-model="backupModal.visible" title='{{ i18n "pages.index.backupTitle" }}' :closable="true"
  519. footer="" :class="themeSwitcher.currentTheme">
  520. <a-list class="ant-backup-list w-100" bordered>
  521. <a-list-item class="ant-backup-list-item">
  522. <a-list-item-meta>
  523. <template #title>{{ i18n "pages.index.exportDatabase" }}</template>
  524. <template #description>{{ i18n "pages.index.exportDatabaseDesc" }}</template>
  525. </a-list-item-meta>
  526. <a-button @click="exportDatabase()" type="primary" icon="download" />
  527. </a-list-item>
  528. <a-list-item class="ant-backup-list-item">
  529. <a-list-item-meta>
  530. <template #title>{{ i18n "pages.index.importDatabase" }}</template>
  531. <template #description>{{ i18n "pages.index.importDatabaseDesc" }}</template>
  532. </a-list-item-meta>
  533. <a-button @click="importDatabase()" type="primary" icon="upload" />
  534. </a-list-item>
  535. </a-list>
  536. </a-modal>
  537. <!-- CPU History Modal -->
  538. <a-modal id="cpu-history-modal" v-model="cpuHistoryModal.visible" :closable="true"
  539. @cancel="() => cpuHistoryModal.visible = false" :class="themeSwitcher.currentTheme" width="900px" footer="">
  540. <template slot="title">
  541. CPU History
  542. <a-select size="small" v-model="cpuHistoryModal.bucket" class="ml-10" style="width: 80px"
  543. @change="fetchCpuHistoryBucket">
  544. <a-select-option :value="2">2m</a-select-option>
  545. <a-select-option :value="30">30m</a-select-option>
  546. <a-select-option :value="60">1h</a-select-option>
  547. <a-select-option :value="120">2h</a-select-option>
  548. <a-select-option :value="180">3h</a-select-option>
  549. <a-select-option :value="300">5h</a-select-option>
  550. </a-select>
  551. </template>
  552. <div style="padding:16px">
  553. <sparkline :data="cpuHistoryLong" :labels="cpuHistoryLabels" :vb-width="840" :height="220"
  554. :stroke="status.cpu.color" :stroke-width="2.2" :show-grid="true" :show-axes="true" :tick-count-x="5"
  555. :max-points="cpuHistoryLong.length" :fill-opacity="0.18" :marker-radius="3.2" :show-tooltip="true" />
  556. <div style="margin-top:4px;font-size:11px;opacity:0.65">Timeframe: [[ cpuHistoryModal.bucket ]] sec per point
  557. (total [[ cpuHistoryLong.length ]] points)</div>
  558. </div>
  559. </a-modal>
  560. </a-layout>
  561. {{template "page/body_scripts" .}}
  562. {{template "component/aSidebar" .}}
  563. {{template "component/aThemeSwitch" .}}
  564. {{template "component/aCustomStatistic" .}}
  565. {{template "modals/textModal" .}}
  566. <script>
  567. // Tiny Sparkline component using an inline SVG polyline
  568. Vue.component('sparkline', {
  569. props: {
  570. data: {
  571. type: Array,
  572. required: true
  573. },
  574. // viewBox width for drawing space; SVG width will be 100% of container
  575. vbWidth: {
  576. type: Number,
  577. default: 320
  578. },
  579. height: {
  580. type: Number,
  581. default: 80
  582. },
  583. stroke: {
  584. type: String,
  585. default: '#008771'
  586. },
  587. strokeWidth: {
  588. type: Number,
  589. default: 2
  590. },
  591. maxPoints: {
  592. type: Number,
  593. default: 120
  594. },
  595. showGrid: {
  596. type: Boolean,
  597. default: true
  598. },
  599. gridColor: {
  600. type: String,
  601. default: 'rgba(0,0,0,0.1)'
  602. },
  603. fillOpacity: {
  604. type: Number,
  605. default: 0.15
  606. },
  607. showMarker: {
  608. type: Boolean,
  609. default: true
  610. },
  611. markerRadius: {
  612. type: Number,
  613. default: 2.8
  614. },
  615. // New opts for axes/labels/tooltip
  616. labels: {
  617. type: Array,
  618. default: () => []
  619. }, // same length as data for x labels (e.g., timestamps)
  620. showAxes: {
  621. type: Boolean,
  622. default: false
  623. },
  624. yTickStep: {
  625. type: Number,
  626. default: 25
  627. }, // percent ticks
  628. tickCountX: {
  629. type: Number,
  630. default: 4
  631. },
  632. paddingLeft: {
  633. type: Number,
  634. default: 32
  635. },
  636. paddingRight: {
  637. type: Number,
  638. default: 6
  639. },
  640. paddingTop: {
  641. type: Number,
  642. default: 6
  643. },
  644. paddingBottom: {
  645. type: Number,
  646. default: 20
  647. },
  648. showTooltip: {
  649. type: Boolean,
  650. default: false
  651. },
  652. },
  653. data() {
  654. return {
  655. hoverIdx: -1,
  656. }
  657. },
  658. computed: {
  659. viewBoxAttr() {
  660. return '0 0 ' + this.vbWidth + ' ' + this.height
  661. },
  662. drawWidth() {
  663. return Math.max(1, this.vbWidth - this.paddingLeft - this.paddingRight)
  664. },
  665. drawHeight() {
  666. return Math.max(1, this.height - this.paddingTop - this.paddingBottom)
  667. },
  668. nPoints() {
  669. return Math.min(this.data.length, this.maxPoints)
  670. },
  671. dataSlice() {
  672. const n = this.nPoints
  673. if (n === 0) return []
  674. return this.data.slice(this.data.length - n)
  675. },
  676. labelsSlice() {
  677. const n = this.nPoints
  678. if (!this.labels || this.labels.length === 0 || n === 0) return []
  679. const start = Math.max(0, this.labels.length - n)
  680. return this.labels.slice(start)
  681. },
  682. pointsArr() {
  683. const n = this.nPoints
  684. if (n === 0) return []
  685. const slice = this.dataSlice
  686. const max = 100
  687. const w = this.drawWidth
  688. const h = this.drawHeight
  689. const dx = n > 1 ? w / (n - 1) : 0
  690. return slice.map((v, i) => {
  691. const x = Math.round(this.paddingLeft + i * dx)
  692. const y = Math.round(this.paddingTop + (h - (Math.max(0, Math.min(100, v)) / max) * h))
  693. return [x, y]
  694. })
  695. },
  696. points() {
  697. return this.pointsArr.map(p => `${p[0]},${p[1]}`).join(' ')
  698. },
  699. areaPath() {
  700. if (this.pointsArr.length === 0) return ''
  701. const first = this.pointsArr[0]
  702. const last = this.pointsArr[this.pointsArr.length - 1]
  703. const line = this.points
  704. // Close to bottom to create an area fill
  705. return `M ${first[0]},${this.paddingTop + this.drawHeight} L ${line.replace(/ /g, ' L ')} L ${last[0]},${this.paddingTop + this.drawHeight} Z`
  706. },
  707. gridLines() {
  708. if (!this.showGrid) return []
  709. const h = this.drawHeight
  710. const w = this.drawWidth
  711. // draw at 25%, 50%, 75%
  712. return [0, 0.25, 0.5, 0.75, 1]
  713. .map(r => Math.round(this.paddingTop + h * r))
  714. .map(y => ({
  715. x1: this.paddingLeft,
  716. y1: y,
  717. x2: this.paddingLeft + w,
  718. y2: y
  719. }))
  720. },
  721. lastPoint() {
  722. if (this.pointsArr.length === 0) return null
  723. return this.pointsArr[this.pointsArr.length - 1]
  724. },
  725. yTicks() {
  726. if (!this.showAxes) return []
  727. const step = Math.max(1, this.yTickStep)
  728. const ticks = []
  729. for (let p = 0; p <= 100; p += step) {
  730. const y = Math.round(this.paddingTop + (this.drawHeight - (p / 100) * this.drawHeight))
  731. ticks.push({
  732. y,
  733. label: `${p}%`
  734. })
  735. }
  736. return ticks
  737. },
  738. xTicks() {
  739. if (!this.showAxes) return []
  740. const labels = this.labelsSlice
  741. const n = this.nPoints
  742. const m = Math.max(2, this.tickCountX)
  743. const ticks = []
  744. if (n === 0) return ticks
  745. const w = this.drawWidth
  746. const dx = n > 1 ? w / (n - 1) : 0
  747. const positions = []
  748. for (let i = 0; i < m; i++) {
  749. const idx = Math.round((i * (n - 1)) / (m - 1))
  750. positions.push(idx)
  751. }
  752. positions.forEach(idx => {
  753. const label = labels[idx] != null ? String(labels[idx]) : String(idx)
  754. const x = Math.round(this.paddingLeft + idx * dx)
  755. ticks.push({
  756. x,
  757. label
  758. })
  759. })
  760. return ticks
  761. },
  762. },
  763. methods: {
  764. onMouseMove(evt) {
  765. if (!this.showTooltip || this.pointsArr.length === 0) return
  766. const rect = evt.currentTarget.getBoundingClientRect()
  767. const px = evt.clientX - rect.left
  768. // translate to viewBox space
  769. const x = (px / rect.width) * this.vbWidth
  770. const n = this.nPoints
  771. const dx = n > 1 ? this.drawWidth / (n - 1) : 0
  772. const idx = Math.max(0, Math.min(n - 1, Math.round((x - this.paddingLeft) / (dx || 1))))
  773. this.hoverIdx = idx
  774. },
  775. onMouseLeave() {
  776. this.hoverIdx = -1
  777. },
  778. fmtHoverText() {
  779. const labels = this.labelsSlice
  780. const idx = this.hoverIdx
  781. if (idx < 0 || idx >= this.dataSlice.length) return ''
  782. const raw = Math.max(0, Math.min(100, Number(this.dataSlice[idx] || 0)))
  783. const val = Number.isFinite(raw) ? raw.toFixed(2) : raw
  784. const lab = labels[idx] != null ? labels[idx] : ''
  785. return `${val}%${lab ? ' • ' + lab : ''}`
  786. },
  787. },
  788. template: `
  789. <svg width="100%" :height="height" :viewBox="viewBoxAttr" preserveAspectRatio="none" class="idx-cpu-history-svg"
  790. @mousemove="onMouseMove" @mouseleave="onMouseLeave">
  791. <defs>
  792. <linearGradient id="spkGrad" x1="0" y1="0" x2="0" y2="1">
  793. <stop offset="0%" :stop-color="stroke" :stop-opacity="fillOpacity"/>
  794. <stop offset="100%" :stop-color="stroke" stop-opacity="0"/>
  795. </linearGradient>
  796. </defs>
  797. <g v-if="showGrid">
  798. <line v-for="(g,i) in gridLines" :key="i" :x1="g.x1" :y1="g.y1" :x2="g.x2" :y2="g.y2" :stroke="gridColor" stroke-width="1" class="cpu-grid-line" />
  799. </g>
  800. <g v-if="showAxes">
  801. <!-- Y ticks/labels -->
  802. <g v-for="(t,i) in yTicks" :key="'y'+i">
  803. <text class="cpu-grid-y-text" :x="Math.max(0, paddingLeft - 4)" :y="t.y + 4" text-anchor="end" font-size="10" fill="rgba(0,0,0,0.3)" v-text="t.label"></text>
  804. </g>
  805. <!-- X ticks/labels -->
  806. <g v-for="(t,i) in xTicks" :key="'x'+i">
  807. <text class="cpu-grid-x-text" :x="t.x" :y="paddingTop + drawHeight + 22" text-anchor="middle" font-size="10" fill="rgba(0,0,0,0.3)" v-text="t.label"></text>
  808. </g>
  809. </g>
  810. <path v-if="areaPath" :d="areaPath" fill="url(#spkGrad)" stroke="none" />
  811. <polyline :points="points" fill="none" :stroke="stroke" :stroke-width="strokeWidth" stroke-linecap="round" stroke-linejoin="round"/>
  812. <circle v-if="showMarker && lastPoint" :cx="lastPoint[0]" :cy="lastPoint[1]" :r="markerRadius" :fill="stroke" />
  813. <!-- Hover marker/tooltip -->
  814. <g v-if="showTooltip && hoverIdx >= 0">
  815. <line class="cpu-grid-h-line" :x1="pointsArr[hoverIdx][0]" :x2="pointsArr[hoverIdx][0]" :y1="paddingTop" :y2="paddingTop + drawHeight" stroke="rgba(0,0,0,0.2)" stroke-width="1" />
  816. <circle :cx="pointsArr[hoverIdx][0]" :cy="pointsArr[hoverIdx][1]" r="3.5" :fill="stroke" />
  817. <text class="cpu-grid-text" :x="pointsArr[hoverIdx][0]" :y="paddingTop + 12" text-anchor="middle" font-size="11" fill="rgba(0,0,0,0.8)" v-text="fmtHoverText()"></text>
  818. </g>
  819. </svg>
  820. `,
  821. })
  822. class CurTotal {
  823. constructor(current, total) {
  824. this.current = current;
  825. this.total = total;
  826. }
  827. get percent() {
  828. if (this.total === 0) {
  829. return 0;
  830. }
  831. return NumberFormatter.toFixed(this.current / this.total * 100, 2);
  832. }
  833. get color() {
  834. const percent = this.percent;
  835. if (percent < 80) {
  836. return '#008771'; // Green
  837. } else if (percent < 90) {
  838. return "#f37b24"; // Orange
  839. } else {
  840. return "#cf3c3c"; // Red
  841. }
  842. }
  843. }
  844. class Status {
  845. constructor(data) {
  846. this.cpu = new CurTotal(0, 0);
  847. this.cpuCores = 0;
  848. this.logicalPro = 0;
  849. this.cpuSpeedMhz = 0;
  850. this.disk = new CurTotal(0, 0);
  851. this.loads = [0, 0, 0];
  852. this.mem = new CurTotal(0, 0);
  853. this.netIO = {
  854. up: 0,
  855. down: 0
  856. };
  857. this.netTraffic = {
  858. sent: 0,
  859. recv: 0
  860. };
  861. this.publicIP = {
  862. ipv4: 0,
  863. ipv6: 0
  864. };
  865. this.swap = new CurTotal(0, 0);
  866. this.tcpCount = 0;
  867. this.udpCount = 0;
  868. this.uptime = 0;
  869. this.appUptime = 0;
  870. this.appStats = {
  871. threads: 0,
  872. mem: 0,
  873. uptime: 0
  874. };
  875. this.xray = {
  876. state: 'stop',
  877. stateMsg: "",
  878. errorMsg: "",
  879. version: "",
  880. color: ""
  881. };
  882. if (data == null) {
  883. return;
  884. }
  885. this.cpu = new CurTotal(data.cpu, 100);
  886. this.cpuCores = data.cpuCores;
  887. this.logicalPro = data.logicalPro;
  888. this.cpuSpeedMhz = data.cpuSpeedMhz;
  889. this.disk = new CurTotal(data.disk.current, data.disk.total);
  890. this.loads = data.loads.map(load => NumberFormatter.toFixed(load, 2));
  891. this.mem = new CurTotal(data.mem.current, data.mem.total);
  892. this.netIO = data.netIO;
  893. this.netTraffic = data.netTraffic;
  894. this.publicIP = data.publicIP;
  895. this.swap = new CurTotal(data.swap.current, data.swap.total);
  896. this.tcpCount = data.tcpCount;
  897. this.udpCount = data.udpCount;
  898. this.uptime = data.uptime;
  899. this.appUptime = data.appUptime;
  900. this.appStats = data.appStats;
  901. this.xray = data.xray;
  902. switch (this.xray.state) {
  903. case 'running':
  904. this.xray.color = "green";
  905. this.xray.stateMsg = '{{ i18n "pages.index.xrayStatusRunning" }}';
  906. break;
  907. case 'stop':
  908. this.xray.color = "orange";
  909. this.xray.stateMsg = '{{ i18n "pages.index.xrayStatusStop" }}';
  910. break;
  911. case 'error':
  912. this.xray.color = "red";
  913. this.xray.stateMsg = '{{ i18n "pages.index.xrayStatusError" }}';
  914. break;
  915. default:
  916. this.xray.color = "gray";
  917. this.xray.stateMsg = '{{ i18n "pages.index.xrayStatusUnknown" }}';
  918. break;
  919. }
  920. }
  921. }
  922. const versionModal = {
  923. visible: false,
  924. activeKey: '1',
  925. versions: [],
  926. show(versions, activeKey = '1') {
  927. this.visible = true;
  928. this.activeKey = activeKey;
  929. this.versions = versions;
  930. },
  931. hide() {
  932. this.visible = false;
  933. },
  934. };
  935. const panelUpdateModal = {
  936. visible: false,
  937. info: {
  938. currentVersion: '{{ .cur_ver }}',
  939. latestVersion: '',
  940. updateAvailable: false,
  941. },
  942. show(info) {
  943. this.visible = true;
  944. if (info) {
  945. this.info = info;
  946. }
  947. },
  948. hide() {
  949. this.visible = false;
  950. },
  951. };
  952. const escapeHtml = (value) => {
  953. if (value === null || value === undefined) {
  954. return '';
  955. }
  956. return String(value)
  957. .replace(/&/g, '&amp;')
  958. .replace(/</g, '&lt;')
  959. .replace(/>/g, '&gt;')
  960. .replace(/"/g, '&quot;')
  961. .replace(/'/g, '&#39;');
  962. };
  963. const logModal = {
  964. visible: false,
  965. logs: [],
  966. rows: 20,
  967. level: 'info',
  968. syslog: false,
  969. loading: false,
  970. show(logs) {
  971. this.visible = true;
  972. this.logs = logs;
  973. this.formattedLogs = this.logs?.length > 0 ? this.formatLogs(this.logs) : "No Record...";
  974. },
  975. formatLogs(logs) {
  976. let formattedLogs = '';
  977. const levels = ["DEBUG", "INFO", "NOTICE", "WARNING", "ERROR"];
  978. const levelColors = ["#3c89e8", "#008771", "#008771", "#f37b24", "#e04141", "#bcbcbc"];
  979. logs.forEach((log, index) => {
  980. let [data, message] = log.split(" - ", 2);
  981. const parts = data.split(" ")
  982. if (index > 0) formattedLogs += '<br>';
  983. if (parts.length === 3) {
  984. const d = escapeHtml(parts[0]);
  985. const t = escapeHtml(parts[1]);
  986. const levelRaw = parts[2];
  987. const level = escapeHtml(levelRaw);
  988. const idx = levels.indexOf(levelRaw);
  989. const levelIndex = idx >= 0 ? idx : 5;
  990. //formattedLogs += `<span style="color: gray;">${index + 1}.</span>`;
  991. formattedLogs += `<span style="color: ${levelColors[0]};">${d} ${t}</span> `;
  992. formattedLogs += `<span style="color: ${levelColors[levelIndex]}">${level}</span>`;
  993. } else {
  994. const idx = levels.indexOf(data);
  995. const levelIndex = idx >= 0 ? idx : 5;
  996. formattedLogs += `<span style="color: ${levelColors[levelIndex]}">${escapeHtml(data)}</span>`;
  997. }
  998. if (message) {
  999. if (message.startsWith("XRAY:")) {
  1000. message = "<b>XRAY: </b>" + escapeHtml(message.substring(5));
  1001. } else {
  1002. message = "<b>X-UI: </b>" + escapeHtml(message);
  1003. }
  1004. }
  1005. formattedLogs += message ? ' - ' + message : '';
  1006. });
  1007. return formattedLogs;
  1008. },
  1009. hide() {
  1010. this.visible = false;
  1011. },
  1012. };
  1013. const xraylogModal = {
  1014. visible: false,
  1015. logs: [],
  1016. rows: 20,
  1017. showDirect: true,
  1018. showBlocked: true,
  1019. showProxy: true,
  1020. loading: false,
  1021. show(logs) {
  1022. this.visible = true;
  1023. this.logs = logs;
  1024. this.formattedLogs = this.logs?.length > 0 ? this.formatLogs(this.logs) : "No Record...";
  1025. },
  1026. formatLogs(logs) {
  1027. let formattedLogs = `
  1028. <style>
  1029. table {
  1030. border-collapse: collapse;
  1031. width: auto;
  1032. }
  1033. table td, table th {
  1034. padding: 2px 15px;
  1035. }
  1036. </style>
  1037. <table>
  1038. <tr>
  1039. <th>Date</th>
  1040. <th>From</th>
  1041. <th>To</th>
  1042. <th>Inbound</th>
  1043. <th>Outbound</th>
  1044. <th>Email</th>
  1045. </tr>
  1046. `;
  1047. logs.reverse().forEach((log, index) => {
  1048. let outboundColor = '';
  1049. if (log.Event === 1) {
  1050. outboundColor = ' style="color: #e04141;"'; //red for blocked
  1051. } else if (log.Event === 2) {
  1052. outboundColor = ' style="color: #3c89e8;"'; //blue for proxies
  1053. }
  1054. let text = ``;
  1055. if (log.Email !== "") {
  1056. text = `<td>${escapeHtml(log.Email)}</td>`;
  1057. }
  1058. formattedLogs += `
  1059. <tr ${outboundColor}>
  1060. <td><b>${escapeHtml(IntlUtil.formatDate(log.DateTime))}</b></td>
  1061. <td>${escapeHtml(log.FromAddress)}</td>
  1062. <td>${escapeHtml(log.ToAddress)}</td>
  1063. <td>${escapeHtml(log.Inbound)}</td>
  1064. <td>${escapeHtml(log.Outbound)}</td>
  1065. ${text}
  1066. </tr>
  1067. `;
  1068. });
  1069. return formattedLogs += "</table>";
  1070. },
  1071. hide() {
  1072. this.visible = false;
  1073. },
  1074. };
  1075. const backupModal = {
  1076. visible: false,
  1077. show() {
  1078. this.visible = true;
  1079. },
  1080. hide() {
  1081. this.visible = false;
  1082. },
  1083. };
  1084. const customGeoColumns = [{
  1085. title: '{{ i18n "pages.index.customGeoExtColumn" }}',
  1086. key: 'extDat',
  1087. scopedSlots: {
  1088. customRender: 'extDat'
  1089. },
  1090. ellipsis: true
  1091. },
  1092. {
  1093. title: '{{ i18n "pages.index.customGeoLastUpdated" }}',
  1094. key: 'lastUpdatedAt',
  1095. scopedSlots: {
  1096. customRender: 'lastUpdatedAt'
  1097. },
  1098. width: 160
  1099. },
  1100. {
  1101. title: '{{ i18n "pages.index.customGeoActions" }}',
  1102. key: 'action',
  1103. scopedSlots: {
  1104. customRender: 'action'
  1105. },
  1106. width: 120,
  1107. fixed: 'right'
  1108. },
  1109. ];
  1110. const app = new Vue({
  1111. delimiters: ['[[', ']]'],
  1112. el: '#app',
  1113. mixins: [MediaQueryMixin],
  1114. data: {
  1115. themeSwitcher,
  1116. loadingStates: {
  1117. fetched: false,
  1118. spinning: false
  1119. },
  1120. status: new Status(),
  1121. cpuHistory: [], // small live widget history
  1122. cpuHistoryLong: [], // aggregated points from backend
  1123. cpuHistoryLabels: [],
  1124. cpuHistoryModal: {
  1125. visible: false,
  1126. bucket: 2
  1127. },
  1128. versionModal,
  1129. panelUpdateModal,
  1130. logModal,
  1131. xraylogModal,
  1132. backupModal,
  1133. loadingTip: '{{ i18n "loading"}}',
  1134. showAlert: false,
  1135. showIp: false,
  1136. ipLimitEnable: false,
  1137. customGeoColumns,
  1138. customGeoList: [],
  1139. customGeoLoading: false,
  1140. customGeoUpdatingAll: false,
  1141. customGeoActionId: null,
  1142. customGeoModal: {
  1143. visible: false,
  1144. editId: null,
  1145. saving: false,
  1146. form: {
  1147. type: 'geosite',
  1148. alias: '',
  1149. url: '',
  1150. },
  1151. },
  1152. customGeoValidation: {
  1153. alias: '{{ i18n "pages.index.customGeoValidationAlias" }}',
  1154. url: '{{ i18n "pages.index.customGeoValidationUrl" }}',
  1155. },
  1156. },
  1157. methods: {
  1158. loading(spinning, tip = '{{ i18n "loading"}}') {
  1159. this.loadingStates.spinning = spinning;
  1160. this.loadingTip = tip;
  1161. },
  1162. async getStatus() {
  1163. try {
  1164. const msg = await HttpUtil.get('/panel/api/server/status');
  1165. if (msg.success) {
  1166. if (!this.loadingStates.fetched) {
  1167. this.loadingStates.fetched = true;
  1168. }
  1169. this.setStatus(msg.obj, true);
  1170. }
  1171. } catch (e) {
  1172. console.error("Failed to get status:", e);
  1173. }
  1174. },
  1175. setStatus(data) {
  1176. this.status = new Status(data);
  1177. // Push CPU percent into history (clamped 0..100)
  1178. const v = Math.max(0, Math.min(100, Number(data?.cpu ?? 0)))
  1179. this.cpuHistory.push(v)
  1180. const maxPoints = this.isMobile ? 60 : 120
  1181. if (this.cpuHistory.length > maxPoints) {
  1182. this.cpuHistory.splice(0, this.cpuHistory.length - maxPoints)
  1183. }
  1184. // If modal open, refresh current bucketed data
  1185. if (this.cpuHistoryModal.visible) {
  1186. this.fetchCpuHistoryBucket()
  1187. }
  1188. },
  1189. openCpuHistory() {
  1190. this.cpuHistoryModal.visible = true
  1191. this.fetchCpuHistoryBucket()
  1192. },
  1193. async fetchCpuHistoryBucket() {
  1194. const bucket = this.cpuHistoryModal.bucket || 2
  1195. try {
  1196. const msg = await HttpUtil.get(`/panel/api/server/cpuHistory/${bucket}`)
  1197. if (msg.success && Array.isArray(msg.obj)) {
  1198. const vals = []
  1199. const labels = []
  1200. for (const p of msg.obj) {
  1201. const d = new Date(p.t * 1000)
  1202. const hh = String(d.getHours()).padStart(2, '0')
  1203. const mm = String(d.getMinutes()).padStart(2, '0')
  1204. const ss = String(d.getSeconds()).padStart(2, '0')
  1205. labels.push(bucket >= 60 ? `${hh}:${mm}` : `${hh}:${mm}:${ss}`)
  1206. vals.push(Math.max(0, Math.min(100, p.cpu)))
  1207. }
  1208. this.cpuHistoryLabels = labels
  1209. this.cpuHistoryLong = vals
  1210. }
  1211. } catch (e) {
  1212. console.error('Failed to fetch bucketed cpu history', e)
  1213. }
  1214. },
  1215. async openSelectV2rayVersion(activeKey = '1') {
  1216. this.loading(true);
  1217. const msg = await HttpUtil.get('/panel/api/server/getXrayVersion');
  1218. this.loading(false);
  1219. if (!msg.success) {
  1220. return;
  1221. }
  1222. versionModal.show(msg.obj, activeKey);
  1223. this.loadCustomGeo();
  1224. },
  1225. async openPanelUpdate() {
  1226. this.loading(true);
  1227. const msg = await HttpUtil.get('/panel/api/server/getPanelUpdateInfo');
  1228. this.loading(false);
  1229. if (!msg.success) {
  1230. return;
  1231. }
  1232. panelUpdateModal.show(msg.obj);
  1233. },
  1234. customGeoFormatTime(ts) {
  1235. if (!ts) return '';
  1236. return typeof moment !== 'undefined' ? moment(ts * 1000).format('YYYY-MM-DD HH:mm') : String(ts);
  1237. },
  1238. customGeoExtDisplay(record) {
  1239. const fn = record.type === 'geoip' ?
  1240. `geoip_${record.alias}.dat` :
  1241. `geosite_${record.alias}.dat`;
  1242. return `ext:${fn}:tag`;
  1243. },
  1244. async loadCustomGeo() {
  1245. this.customGeoLoading = true;
  1246. try {
  1247. const msg = await HttpUtil.get('/panel/api/custom-geo/list');
  1248. if (msg.success && Array.isArray(msg.obj)) {
  1249. this.customGeoList = msg.obj;
  1250. }
  1251. } finally {
  1252. this.customGeoLoading = false;
  1253. }
  1254. },
  1255. openCustomGeoModal(record) {
  1256. if (record) {
  1257. this.customGeoModal.editId = record.id;
  1258. this.customGeoModal.form = {
  1259. type: record.type,
  1260. alias: record.alias,
  1261. url: record.url,
  1262. };
  1263. } else {
  1264. this.customGeoModal.editId = null;
  1265. this.customGeoModal.form = {
  1266. type: 'geosite',
  1267. alias: '',
  1268. url: '',
  1269. };
  1270. }
  1271. this.customGeoModal.visible = true;
  1272. },
  1273. validateCustomGeoForm() {
  1274. const f = this.customGeoModal.form;
  1275. const re = /^[a-z0-9_-]+$/;
  1276. if (!re.test(f.alias || '')) {
  1277. this.$message.error(this.customGeoValidation.alias);
  1278. return false;
  1279. }
  1280. const u = (f.url || '').trim();
  1281. if (!/^https?:\/\//i.test(u)) {
  1282. this.$message.error(this.customGeoValidation.url);
  1283. return false;
  1284. }
  1285. try {
  1286. const parsed = new URL(u);
  1287. if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
  1288. this.$message.error(this.customGeoValidation.url);
  1289. return false;
  1290. }
  1291. } catch (e) {
  1292. this.$message.error(this.customGeoValidation.url);
  1293. return false;
  1294. }
  1295. return true;
  1296. },
  1297. async submitCustomGeo() {
  1298. if (!this.validateCustomGeoForm()) {
  1299. return;
  1300. }
  1301. const f = this.customGeoModal.form;
  1302. this.customGeoModal.saving = true;
  1303. try {
  1304. let msg;
  1305. if (this.customGeoModal.editId) {
  1306. msg = await HttpUtil.post(`/panel/api/custom-geo/update/${this.customGeoModal.editId}`, f);
  1307. } else {
  1308. msg = await HttpUtil.post('/panel/api/custom-geo/add', f);
  1309. }
  1310. if (msg && msg.success) {
  1311. this.customGeoModal.visible = false;
  1312. await this.loadCustomGeo();
  1313. }
  1314. } finally {
  1315. this.customGeoModal.saving = false;
  1316. }
  1317. },
  1318. confirmDeleteCustomGeo(record) {
  1319. this.$confirm({
  1320. title: '{{ i18n "pages.index.customGeoDelete" }}',
  1321. content: '{{ i18n "pages.index.customGeoDeleteConfirm" }}',
  1322. okText: '{{ i18n "confirm"}}',
  1323. cancelText: '{{ i18n "cancel"}}',
  1324. class: themeSwitcher.currentTheme,
  1325. onOk: async () => {
  1326. const msg = await HttpUtil.post(`/panel/api/custom-geo/delete/${record.id}`);
  1327. if (msg.success) {
  1328. await this.loadCustomGeo();
  1329. }
  1330. },
  1331. });
  1332. },
  1333. async downloadCustomGeo(id) {
  1334. this.customGeoActionId = id;
  1335. try {
  1336. const msg = await HttpUtil.post(`/panel/api/custom-geo/download/${id}`);
  1337. if (msg.success) {
  1338. await this.loadCustomGeo();
  1339. }
  1340. } finally {
  1341. this.customGeoActionId = null;
  1342. }
  1343. },
  1344. async updateAllCustomGeo() {
  1345. this.customGeoUpdatingAll = true;
  1346. try {
  1347. const msg = await HttpUtil.post('/panel/api/custom-geo/update-all');
  1348. if (msg.success || (msg.obj && Array.isArray(msg.obj.succeeded) && msg.obj.succeeded.length > 0)) {
  1349. await this.loadCustomGeo();
  1350. }
  1351. } finally {
  1352. this.customGeoUpdatingAll = false;
  1353. }
  1354. },
  1355. switchV2rayVersion(version) {
  1356. this.$confirm({
  1357. title: '{{ i18n "pages.index.xraySwitchVersionDialog"}}',
  1358. content: '{{ i18n "pages.index.xraySwitchVersionDialogDesc"}}'.replace('#version#', version),
  1359. okText: '{{ i18n "confirm"}}',
  1360. class: themeSwitcher.currentTheme,
  1361. cancelText: '{{ i18n "cancel"}}',
  1362. onOk: async () => {
  1363. versionModal.hide();
  1364. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  1365. await HttpUtil.post(`/panel/api/server/installXray/${version}`);
  1366. this.loading(false);
  1367. },
  1368. });
  1369. },
  1370. updatePanel() {
  1371. this.$confirm({
  1372. title: '{{ i18n "pages.index.panelUpdateDialog" }}',
  1373. content: '{{ i18n "pages.index.panelUpdateDialogDesc" }}'
  1374. .replace('#version#', panelUpdateModal.info.latestVersion || ''),
  1375. okText: '{{ i18n "confirm"}}',
  1376. class: themeSwitcher.currentTheme,
  1377. cancelText: '{{ i18n "cancel"}}',
  1378. onOk: async () => {
  1379. panelUpdateModal.hide();
  1380. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  1381. const msg = await HttpUtil.post('/panel/api/server/updatePanel');
  1382. if (!msg.success) {
  1383. this.loading(false);
  1384. return;
  1385. }
  1386. await PromiseUtil.sleep(15000);
  1387. window.location.reload();
  1388. },
  1389. });
  1390. },
  1391. updateGeofile(fileName) {
  1392. const isSingleFile = !!fileName;
  1393. this.$confirm({
  1394. title: '{{ i18n "pages.index.geofileUpdateDialog" }}',
  1395. content: isSingleFile ?
  1396. '{{ i18n "pages.index.geofileUpdateDialogDesc" }}'.replace("#filename#", fileName) :
  1397. '{{ i18n "pages.index.geofilesUpdateDialogDesc" }}',
  1398. okText: '{{ i18n "confirm"}}',
  1399. class: themeSwitcher.currentTheme,
  1400. cancelText: '{{ i18n "cancel"}}',
  1401. onOk: async () => {
  1402. versionModal.hide();
  1403. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  1404. const url = isSingleFile ?
  1405. `/panel/api/server/updateGeofile/${fileName}` :
  1406. `/panel/api/server/updateGeofile`;
  1407. await HttpUtil.post(url);
  1408. this.loading(false);
  1409. },
  1410. });
  1411. },
  1412. async stopXrayService() {
  1413. this.loading(true);
  1414. const msg = await HttpUtil.post('/panel/api/server/stopXrayService');
  1415. this.loading(false);
  1416. if (!msg.success) {
  1417. return;
  1418. }
  1419. },
  1420. async restartXrayService() {
  1421. this.loading(true);
  1422. const msg = await HttpUtil.post('/panel/api/server/restartXrayService');
  1423. this.loading(false);
  1424. if (!msg.success) {
  1425. return;
  1426. }
  1427. },
  1428. async openLogs() {
  1429. logModal.loading = true;
  1430. const msg = await HttpUtil.post('/panel/api/server/logs/' + logModal.rows, {
  1431. level: logModal.level,
  1432. syslog: logModal.syslog
  1433. });
  1434. if (!msg.success) {
  1435. return;
  1436. }
  1437. logModal.show(msg.obj);
  1438. await PromiseUtil.sleep(500);
  1439. logModal.loading = false;
  1440. },
  1441. async openXrayLogs() {
  1442. xraylogModal.loading = true;
  1443. const msg = await HttpUtil.post('/panel/api/server/xraylogs/' + xraylogModal.rows, {
  1444. filter: xraylogModal.filter,
  1445. showDirect: xraylogModal.showDirect,
  1446. showBlocked: xraylogModal.showBlocked,
  1447. showProxy: xraylogModal.showProxy
  1448. });
  1449. if (!msg.success) {
  1450. return;
  1451. }
  1452. xraylogModal.show(msg.obj);
  1453. await PromiseUtil.sleep(500);
  1454. xraylogModal.loading = false;
  1455. },
  1456. downloadXrayLogs() {
  1457. if (!Array.isArray(this.xraylogModal.logs) || this.xraylogModal.logs.length === 0) {
  1458. FileManager.downloadTextFile('', 'x-ui.log');
  1459. return;
  1460. }
  1461. const lines = this.xraylogModal.logs.map(l => {
  1462. try {
  1463. const dt = l.DateTime ? new Date(l.DateTime) : null;
  1464. const dateStr = dt && !isNaN(dt.getTime()) ? dt.toISOString() : '';
  1465. const eventMap = {
  1466. 0: 'DIRECT',
  1467. 1: 'BLOCKED',
  1468. 2: 'PROXY'
  1469. };
  1470. const eventText = eventMap[l.Event] || String(l.Event ?? '');
  1471. const emailPart = l.Email ? ` Email=${l.Email}` : '';
  1472. return `${dateStr} FROM=${l.FromAddress || ''} TO=${l.ToAddress || ''} INBOUND=${l.Inbound || ''} OUTBOUND=${l.Outbound || ''}${emailPart} EVENT=${eventText}`
  1473. .trim();
  1474. } catch (e) {
  1475. return JSON.stringify(l);
  1476. }
  1477. }).join('\n');
  1478. FileManager.downloadTextFile(lines, 'x-ui.log');
  1479. },
  1480. async openConfig() {
  1481. this.loading(true);
  1482. const msg = await HttpUtil.get('/panel/api/server/getConfigJson');
  1483. this.loading(false);
  1484. if (!msg.success) {
  1485. return;
  1486. }
  1487. txtModal.show('config.json', JSON.stringify(msg.obj, null, 2), 'config.json');
  1488. },
  1489. openBackup() {
  1490. backupModal.show();
  1491. },
  1492. exportDatabase() {
  1493. window.location = basePath + 'panel/api/server/getDb';
  1494. },
  1495. importDatabase() {
  1496. const fileInput = document.createElement('input');
  1497. fileInput.type = 'file';
  1498. fileInput.accept = '.db';
  1499. fileInput.addEventListener('change', async (event) => {
  1500. const dbFile = event.target.files[0];
  1501. if (dbFile) {
  1502. const formData = new FormData();
  1503. formData.append('db', dbFile);
  1504. backupModal.hide();
  1505. this.loading(true);
  1506. const uploadMsg = await HttpUtil.post('/panel/api/server/importDB', formData, {
  1507. headers: {
  1508. 'Content-Type': 'multipart/form-data',
  1509. }
  1510. });
  1511. this.loading(false);
  1512. if (!uploadMsg.success) {
  1513. return;
  1514. }
  1515. this.loading(true);
  1516. const restartMsg = await HttpUtil.post("/panel/setting/restartPanel");
  1517. this.loading(false);
  1518. if (restartMsg.success) {
  1519. this.loading(true);
  1520. await PromiseUtil.sleep(5000);
  1521. location.reload();
  1522. }
  1523. }
  1524. });
  1525. fileInput.click();
  1526. },
  1527. startPolling() {
  1528. // Fallback polling mechanism
  1529. const pollInterval = setInterval(async () => {
  1530. if (window.wsClient && window.wsClient.isConnected) {
  1531. clearInterval(pollInterval);
  1532. return;
  1533. }
  1534. try {
  1535. await this.getStatus();
  1536. } catch (e) {
  1537. console.error(e);
  1538. }
  1539. }, 2000);
  1540. },
  1541. },
  1542. async mounted() {
  1543. if (window.location.protocol !== "https:") {
  1544. this.showAlert = true;
  1545. }
  1546. const msg = await HttpUtil.post('/panel/setting/defaultSettings');
  1547. if (msg.success) {
  1548. this.ipLimitEnable = msg.obj.ipLimitEnable;
  1549. }
  1550. // Initial status fetch
  1551. await this.getStatus();
  1552. // Silently check for panel updates so the indicator shows on load
  1553. HttpUtil.get('/panel/api/server/getPanelUpdateInfo').then(msg => {
  1554. if (msg && msg.success && msg.obj) {
  1555. panelUpdateModal.info = msg.obj;
  1556. }
  1557. });
  1558. // Setup WebSocket for real-time updates
  1559. if (window.wsClient) {
  1560. window.wsClient.connect();
  1561. // Listen for status updates
  1562. window.wsClient.on('status', (payload) => {
  1563. this.setStatus(payload);
  1564. });
  1565. // Listen for Xray state changes
  1566. window.wsClient.on('xray_state', (payload) => {
  1567. if (this.status && this.status.xray) {
  1568. this.status.xray.state = payload.state;
  1569. this.status.xray.errorMsg = payload.errorMsg || '';
  1570. switch (payload.state) {
  1571. case 'running':
  1572. this.status.xray.color = "green";
  1573. this.status.xray.stateMsg = '{{ i18n "pages.index.xrayStatusRunning" }}';
  1574. break;
  1575. case 'stop':
  1576. this.status.xray.color = "orange";
  1577. this.status.xray.stateMsg = '{{ i18n "pages.index.xrayStatusStop" }}';
  1578. break;
  1579. case 'error':
  1580. this.status.xray.color = "red";
  1581. this.status.xray.stateMsg = '{{ i18n "pages.index.xrayStatusError" }}';
  1582. break;
  1583. }
  1584. }
  1585. });
  1586. // Notifications disabled - white notifications are not needed
  1587. // Fallback to polling if WebSocket fails
  1588. window.wsClient.on('error', () => {
  1589. console.warn('WebSocket connection failed, falling back to polling');
  1590. this.startPolling();
  1591. });
  1592. window.wsClient.on('disconnected', () => {
  1593. if (window.wsClient.reconnectAttempts >= window.wsClient.maxReconnectAttempts) {
  1594. console.warn('WebSocket reconnection failed, falling back to polling');
  1595. this.startPolling();
  1596. }
  1597. });
  1598. } else {
  1599. // Fallback to polling if WebSocket is not available
  1600. this.startPolling();
  1601. }
  1602. },
  1603. });
  1604. </script>
  1605. {{ template "page/body_end" .}}