1
0

index.html 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629
  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 logModal = {
  953. visible: false,
  954. logs: [],
  955. rows: 20,
  956. level: 'info',
  957. syslog: false,
  958. loading: false,
  959. show(logs) {
  960. this.visible = true;
  961. this.logs = logs;
  962. this.formattedLogs = this.logs?.length > 0 ? this.formatLogs(this.logs) : "No Record...";
  963. },
  964. formatLogs(logs) {
  965. let formattedLogs = '';
  966. const levels = ["DEBUG", "INFO", "NOTICE", "WARNING", "ERROR"];
  967. const levelColors = ["#3c89e8", "#008771", "#008771", "#f37b24", "#e04141", "#bcbcbc"];
  968. logs.forEach((log, index) => {
  969. let [data, message] = log.split(" - ", 2);
  970. const parts = data.split(" ")
  971. if (index > 0) formattedLogs += '<br>';
  972. if (parts.length === 3) {
  973. const d = parts[0];
  974. const t = parts[1];
  975. const level = parts[2];
  976. const levelIndex = levels.indexOf(level, levels) || 5;
  977. //formattedLogs += `<span style="color: gray;">${index + 1}.</span>`;
  978. formattedLogs += `<span style="color: ${levelColors[0]};">${d} ${t}</span> `;
  979. formattedLogs += `<span style="color: ${levelColors[levelIndex]}">${level}</span>`;
  980. } else {
  981. const levelIndex = levels.indexOf(data, levels) || 5;
  982. formattedLogs += `<span style="color: ${levelColors[levelIndex]}">${data}</span>`;
  983. }
  984. if (message) {
  985. if (message.startsWith("XRAY:"))
  986. message = "<b>XRAY: </b>" + message.substring(5);
  987. else
  988. message = "<b>X-UI: </b>" + message;
  989. }
  990. formattedLogs += message ? ' - ' + message : '';
  991. });
  992. return formattedLogs;
  993. },
  994. hide() {
  995. this.visible = false;
  996. },
  997. };
  998. const xraylogModal = {
  999. visible: false,
  1000. logs: [],
  1001. rows: 20,
  1002. showDirect: true,
  1003. showBlocked: true,
  1004. showProxy: true,
  1005. loading: false,
  1006. show(logs) {
  1007. this.visible = true;
  1008. this.logs = logs;
  1009. this.formattedLogs = this.logs?.length > 0 ? this.formatLogs(this.logs) : "No Record...";
  1010. },
  1011. formatLogs(logs) {
  1012. let formattedLogs = `
  1013. <style>
  1014. table {
  1015. border-collapse: collapse;
  1016. width: auto;
  1017. }
  1018. table td, table th {
  1019. padding: 2px 15px;
  1020. }
  1021. </style>
  1022. <table>
  1023. <tr>
  1024. <th>Date</th>
  1025. <th>From</th>
  1026. <th>To</th>
  1027. <th>Inbound</th>
  1028. <th>Outbound</th>
  1029. <th>Email</th>
  1030. </tr>
  1031. `;
  1032. logs.reverse().forEach((log, index) => {
  1033. let outboundColor = '';
  1034. if (log.Event === 1) {
  1035. outboundColor = ' style="color: #e04141;"'; //red for blocked
  1036. } else if (log.Event === 2) {
  1037. outboundColor = ' style="color: #3c89e8;"'; //blue for proxies
  1038. }
  1039. let text = ``;
  1040. if (log.Email !== "") {
  1041. text = `<td>${log.Email}</td>`;
  1042. }
  1043. formattedLogs += `
  1044. <tr ${outboundColor}>
  1045. <td><b>${IntlUtil.formatDate(log.DateTime)}</b></td>
  1046. <td>${log.FromAddress}</td>
  1047. <td>${log.ToAddress}</td>
  1048. <td>${log.Inbound}</td>
  1049. <td>${log.Outbound}</td>
  1050. ${text}
  1051. </tr>
  1052. `;
  1053. });
  1054. return formattedLogs += "</table>";
  1055. },
  1056. hide() {
  1057. this.visible = false;
  1058. },
  1059. };
  1060. const backupModal = {
  1061. visible: false,
  1062. show() {
  1063. this.visible = true;
  1064. },
  1065. hide() {
  1066. this.visible = false;
  1067. },
  1068. };
  1069. const customGeoColumns = [{
  1070. title: '{{ i18n "pages.index.customGeoExtColumn" }}',
  1071. key: 'extDat',
  1072. scopedSlots: {
  1073. customRender: 'extDat'
  1074. },
  1075. ellipsis: true
  1076. },
  1077. {
  1078. title: '{{ i18n "pages.index.customGeoLastUpdated" }}',
  1079. key: 'lastUpdatedAt',
  1080. scopedSlots: {
  1081. customRender: 'lastUpdatedAt'
  1082. },
  1083. width: 160
  1084. },
  1085. {
  1086. title: '{{ i18n "pages.index.customGeoActions" }}',
  1087. key: 'action',
  1088. scopedSlots: {
  1089. customRender: 'action'
  1090. },
  1091. width: 120,
  1092. fixed: 'right'
  1093. },
  1094. ];
  1095. const app = new Vue({
  1096. delimiters: ['[[', ']]'],
  1097. el: '#app',
  1098. mixins: [MediaQueryMixin],
  1099. data: {
  1100. themeSwitcher,
  1101. loadingStates: {
  1102. fetched: false,
  1103. spinning: false
  1104. },
  1105. status: new Status(),
  1106. cpuHistory: [], // small live widget history
  1107. cpuHistoryLong: [], // aggregated points from backend
  1108. cpuHistoryLabels: [],
  1109. cpuHistoryModal: {
  1110. visible: false,
  1111. bucket: 2
  1112. },
  1113. versionModal,
  1114. panelUpdateModal,
  1115. logModal,
  1116. xraylogModal,
  1117. backupModal,
  1118. loadingTip: '{{ i18n "loading"}}',
  1119. showAlert: false,
  1120. showIp: false,
  1121. ipLimitEnable: false,
  1122. customGeoColumns,
  1123. customGeoList: [],
  1124. customGeoLoading: false,
  1125. customGeoUpdatingAll: false,
  1126. customGeoActionId: null,
  1127. customGeoModal: {
  1128. visible: false,
  1129. editId: null,
  1130. saving: false,
  1131. form: {
  1132. type: 'geosite',
  1133. alias: '',
  1134. url: '',
  1135. },
  1136. },
  1137. customGeoValidation: {
  1138. alias: '{{ i18n "pages.index.customGeoValidationAlias" }}',
  1139. url: '{{ i18n "pages.index.customGeoValidationUrl" }}',
  1140. },
  1141. },
  1142. methods: {
  1143. loading(spinning, tip = '{{ i18n "loading"}}') {
  1144. this.loadingStates.spinning = spinning;
  1145. this.loadingTip = tip;
  1146. },
  1147. async getStatus() {
  1148. try {
  1149. const msg = await HttpUtil.get('/panel/api/server/status');
  1150. if (msg.success) {
  1151. if (!this.loadingStates.fetched) {
  1152. this.loadingStates.fetched = true;
  1153. }
  1154. this.setStatus(msg.obj, true);
  1155. }
  1156. } catch (e) {
  1157. console.error("Failed to get status:", e);
  1158. }
  1159. },
  1160. setStatus(data) {
  1161. this.status = new Status(data);
  1162. // Push CPU percent into history (clamped 0..100)
  1163. const v = Math.max(0, Math.min(100, Number(data?.cpu ?? 0)))
  1164. this.cpuHistory.push(v)
  1165. const maxPoints = this.isMobile ? 60 : 120
  1166. if (this.cpuHistory.length > maxPoints) {
  1167. this.cpuHistory.splice(0, this.cpuHistory.length - maxPoints)
  1168. }
  1169. // If modal open, refresh current bucketed data
  1170. if (this.cpuHistoryModal.visible) {
  1171. this.fetchCpuHistoryBucket()
  1172. }
  1173. },
  1174. openCpuHistory() {
  1175. this.cpuHistoryModal.visible = true
  1176. this.fetchCpuHistoryBucket()
  1177. },
  1178. async fetchCpuHistoryBucket() {
  1179. const bucket = this.cpuHistoryModal.bucket || 2
  1180. try {
  1181. const msg = await HttpUtil.get(`/panel/api/server/cpuHistory/${bucket}`)
  1182. if (msg.success && Array.isArray(msg.obj)) {
  1183. const vals = []
  1184. const labels = []
  1185. for (const p of msg.obj) {
  1186. const d = new Date(p.t * 1000)
  1187. const hh = String(d.getHours()).padStart(2, '0')
  1188. const mm = String(d.getMinutes()).padStart(2, '0')
  1189. const ss = String(d.getSeconds()).padStart(2, '0')
  1190. labels.push(bucket >= 60 ? `${hh}:${mm}` : `${hh}:${mm}:${ss}`)
  1191. vals.push(Math.max(0, Math.min(100, p.cpu)))
  1192. }
  1193. this.cpuHistoryLabels = labels
  1194. this.cpuHistoryLong = vals
  1195. }
  1196. } catch (e) {
  1197. console.error('Failed to fetch bucketed cpu history', e)
  1198. }
  1199. },
  1200. async openSelectV2rayVersion(activeKey = '1') {
  1201. this.loading(true);
  1202. const msg = await HttpUtil.get('/panel/api/server/getXrayVersion');
  1203. this.loading(false);
  1204. if (!msg.success) {
  1205. return;
  1206. }
  1207. versionModal.show(msg.obj, activeKey);
  1208. this.loadCustomGeo();
  1209. },
  1210. async openPanelUpdate() {
  1211. this.loading(true);
  1212. const msg = await HttpUtil.get('/panel/api/server/getPanelUpdateInfo');
  1213. this.loading(false);
  1214. if (!msg.success) {
  1215. return;
  1216. }
  1217. panelUpdateModal.show(msg.obj);
  1218. },
  1219. customGeoFormatTime(ts) {
  1220. if (!ts) return '';
  1221. return typeof moment !== 'undefined' ? moment(ts * 1000).format('YYYY-MM-DD HH:mm') : String(ts);
  1222. },
  1223. customGeoExtDisplay(record) {
  1224. const fn = record.type === 'geoip' ?
  1225. `geoip_${record.alias}.dat` :
  1226. `geosite_${record.alias}.dat`;
  1227. return `ext:${fn}:tag`;
  1228. },
  1229. async loadCustomGeo() {
  1230. this.customGeoLoading = true;
  1231. try {
  1232. const msg = await HttpUtil.get('/panel/api/custom-geo/list');
  1233. if (msg.success && Array.isArray(msg.obj)) {
  1234. this.customGeoList = msg.obj;
  1235. }
  1236. } finally {
  1237. this.customGeoLoading = false;
  1238. }
  1239. },
  1240. openCustomGeoModal(record) {
  1241. if (record) {
  1242. this.customGeoModal.editId = record.id;
  1243. this.customGeoModal.form = {
  1244. type: record.type,
  1245. alias: record.alias,
  1246. url: record.url,
  1247. };
  1248. } else {
  1249. this.customGeoModal.editId = null;
  1250. this.customGeoModal.form = {
  1251. type: 'geosite',
  1252. alias: '',
  1253. url: '',
  1254. };
  1255. }
  1256. this.customGeoModal.visible = true;
  1257. },
  1258. validateCustomGeoForm() {
  1259. const f = this.customGeoModal.form;
  1260. const re = /^[a-z0-9_-]+$/;
  1261. if (!re.test(f.alias || '')) {
  1262. this.$message.error(this.customGeoValidation.alias);
  1263. return false;
  1264. }
  1265. const u = (f.url || '').trim();
  1266. if (!/^https?:\/\//i.test(u)) {
  1267. this.$message.error(this.customGeoValidation.url);
  1268. return false;
  1269. }
  1270. try {
  1271. const parsed = new URL(u);
  1272. if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
  1273. this.$message.error(this.customGeoValidation.url);
  1274. return false;
  1275. }
  1276. } catch (e) {
  1277. this.$message.error(this.customGeoValidation.url);
  1278. return false;
  1279. }
  1280. return true;
  1281. },
  1282. async submitCustomGeo() {
  1283. if (!this.validateCustomGeoForm()) {
  1284. return;
  1285. }
  1286. const f = this.customGeoModal.form;
  1287. this.customGeoModal.saving = true;
  1288. try {
  1289. let msg;
  1290. if (this.customGeoModal.editId) {
  1291. msg = await HttpUtil.post(`/panel/api/custom-geo/update/${this.customGeoModal.editId}`, f);
  1292. } else {
  1293. msg = await HttpUtil.post('/panel/api/custom-geo/add', f);
  1294. }
  1295. if (msg && msg.success) {
  1296. this.customGeoModal.visible = false;
  1297. await this.loadCustomGeo();
  1298. }
  1299. } finally {
  1300. this.customGeoModal.saving = false;
  1301. }
  1302. },
  1303. confirmDeleteCustomGeo(record) {
  1304. this.$confirm({
  1305. title: '{{ i18n "pages.index.customGeoDelete" }}',
  1306. content: '{{ i18n "pages.index.customGeoDeleteConfirm" }}',
  1307. okText: '{{ i18n "confirm"}}',
  1308. cancelText: '{{ i18n "cancel"}}',
  1309. class: themeSwitcher.currentTheme,
  1310. onOk: async () => {
  1311. const msg = await HttpUtil.post(`/panel/api/custom-geo/delete/${record.id}`);
  1312. if (msg.success) {
  1313. await this.loadCustomGeo();
  1314. }
  1315. },
  1316. });
  1317. },
  1318. async downloadCustomGeo(id) {
  1319. this.customGeoActionId = id;
  1320. try {
  1321. const msg = await HttpUtil.post(`/panel/api/custom-geo/download/${id}`);
  1322. if (msg.success) {
  1323. await this.loadCustomGeo();
  1324. }
  1325. } finally {
  1326. this.customGeoActionId = null;
  1327. }
  1328. },
  1329. async updateAllCustomGeo() {
  1330. this.customGeoUpdatingAll = true;
  1331. try {
  1332. const msg = await HttpUtil.post('/panel/api/custom-geo/update-all');
  1333. if (msg.success || (msg.obj && Array.isArray(msg.obj.succeeded) && msg.obj.succeeded.length > 0)) {
  1334. await this.loadCustomGeo();
  1335. }
  1336. } finally {
  1337. this.customGeoUpdatingAll = false;
  1338. }
  1339. },
  1340. switchV2rayVersion(version) {
  1341. this.$confirm({
  1342. title: '{{ i18n "pages.index.xraySwitchVersionDialog"}}',
  1343. content: '{{ i18n "pages.index.xraySwitchVersionDialogDesc"}}'.replace('#version#', version),
  1344. okText: '{{ i18n "confirm"}}',
  1345. class: themeSwitcher.currentTheme,
  1346. cancelText: '{{ i18n "cancel"}}',
  1347. onOk: async () => {
  1348. versionModal.hide();
  1349. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  1350. await HttpUtil.post(`/panel/api/server/installXray/${version}`);
  1351. this.loading(false);
  1352. },
  1353. });
  1354. },
  1355. updatePanel() {
  1356. this.$confirm({
  1357. title: '{{ i18n "pages.index.panelUpdateDialog" }}',
  1358. content: '{{ i18n "pages.index.panelUpdateDialogDesc" }}'
  1359. .replace('#version#', panelUpdateModal.info.latestVersion || ''),
  1360. okText: '{{ i18n "confirm"}}',
  1361. class: themeSwitcher.currentTheme,
  1362. cancelText: '{{ i18n "cancel"}}',
  1363. onOk: async () => {
  1364. panelUpdateModal.hide();
  1365. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  1366. const msg = await HttpUtil.post('/panel/api/server/updatePanel');
  1367. if (!msg.success) {
  1368. this.loading(false);
  1369. return;
  1370. }
  1371. await PromiseUtil.sleep(15000);
  1372. window.location.reload();
  1373. },
  1374. });
  1375. },
  1376. updateGeofile(fileName) {
  1377. const isSingleFile = !!fileName;
  1378. this.$confirm({
  1379. title: '{{ i18n "pages.index.geofileUpdateDialog" }}',
  1380. content: isSingleFile ?
  1381. '{{ i18n "pages.index.geofileUpdateDialogDesc" }}'.replace("#filename#", fileName) :
  1382. '{{ i18n "pages.index.geofilesUpdateDialogDesc" }}',
  1383. okText: '{{ i18n "confirm"}}',
  1384. class: themeSwitcher.currentTheme,
  1385. cancelText: '{{ i18n "cancel"}}',
  1386. onOk: async () => {
  1387. versionModal.hide();
  1388. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  1389. const url = isSingleFile ?
  1390. `/panel/api/server/updateGeofile/${fileName}` :
  1391. `/panel/api/server/updateGeofile`;
  1392. await HttpUtil.post(url);
  1393. this.loading(false);
  1394. },
  1395. });
  1396. },
  1397. async stopXrayService() {
  1398. this.loading(true);
  1399. const msg = await HttpUtil.post('/panel/api/server/stopXrayService');
  1400. this.loading(false);
  1401. if (!msg.success) {
  1402. return;
  1403. }
  1404. },
  1405. async restartXrayService() {
  1406. this.loading(true);
  1407. const msg = await HttpUtil.post('/panel/api/server/restartXrayService');
  1408. this.loading(false);
  1409. if (!msg.success) {
  1410. return;
  1411. }
  1412. },
  1413. async openLogs() {
  1414. logModal.loading = true;
  1415. const msg = await HttpUtil.post('/panel/api/server/logs/' + logModal.rows, {
  1416. level: logModal.level,
  1417. syslog: logModal.syslog
  1418. });
  1419. if (!msg.success) {
  1420. return;
  1421. }
  1422. logModal.show(msg.obj);
  1423. await PromiseUtil.sleep(500);
  1424. logModal.loading = false;
  1425. },
  1426. async openXrayLogs() {
  1427. xraylogModal.loading = true;
  1428. const msg = await HttpUtil.post('/panel/api/server/xraylogs/' + xraylogModal.rows, {
  1429. filter: xraylogModal.filter,
  1430. showDirect: xraylogModal.showDirect,
  1431. showBlocked: xraylogModal.showBlocked,
  1432. showProxy: xraylogModal.showProxy
  1433. });
  1434. if (!msg.success) {
  1435. return;
  1436. }
  1437. xraylogModal.show(msg.obj);
  1438. await PromiseUtil.sleep(500);
  1439. xraylogModal.loading = false;
  1440. },
  1441. downloadXrayLogs() {
  1442. if (!Array.isArray(this.xraylogModal.logs) || this.xraylogModal.logs.length === 0) {
  1443. FileManager.downloadTextFile('', 'x-ui.log');
  1444. return;
  1445. }
  1446. const lines = this.xraylogModal.logs.map(l => {
  1447. try {
  1448. const dt = l.DateTime ? new Date(l.DateTime) : null;
  1449. const dateStr = dt && !isNaN(dt.getTime()) ? dt.toISOString() : '';
  1450. const eventMap = {
  1451. 0: 'DIRECT',
  1452. 1: 'BLOCKED',
  1453. 2: 'PROXY'
  1454. };
  1455. const eventText = eventMap[l.Event] || String(l.Event ?? '');
  1456. const emailPart = l.Email ? ` Email=${l.Email}` : '';
  1457. return `${dateStr} FROM=${l.FromAddress || ''} TO=${l.ToAddress || ''} INBOUND=${l.Inbound || ''} OUTBOUND=${l.Outbound || ''}${emailPart} EVENT=${eventText}`
  1458. .trim();
  1459. } catch (e) {
  1460. return JSON.stringify(l);
  1461. }
  1462. }).join('\n');
  1463. FileManager.downloadTextFile(lines, 'x-ui.log');
  1464. },
  1465. async openConfig() {
  1466. this.loading(true);
  1467. const msg = await HttpUtil.get('/panel/api/server/getConfigJson');
  1468. this.loading(false);
  1469. if (!msg.success) {
  1470. return;
  1471. }
  1472. txtModal.show('config.json', JSON.stringify(msg.obj, null, 2), 'config.json');
  1473. },
  1474. openBackup() {
  1475. backupModal.show();
  1476. },
  1477. exportDatabase() {
  1478. window.location = basePath + 'panel/api/server/getDb';
  1479. },
  1480. importDatabase() {
  1481. const fileInput = document.createElement('input');
  1482. fileInput.type = 'file';
  1483. fileInput.accept = '.db';
  1484. fileInput.addEventListener('change', async (event) => {
  1485. const dbFile = event.target.files[0];
  1486. if (dbFile) {
  1487. const formData = new FormData();
  1488. formData.append('db', dbFile);
  1489. backupModal.hide();
  1490. this.loading(true);
  1491. const uploadMsg = await HttpUtil.post('/panel/api/server/importDB', formData, {
  1492. headers: {
  1493. 'Content-Type': 'multipart/form-data',
  1494. }
  1495. });
  1496. this.loading(false);
  1497. if (!uploadMsg.success) {
  1498. return;
  1499. }
  1500. this.loading(true);
  1501. const restartMsg = await HttpUtil.post("/panel/setting/restartPanel");
  1502. this.loading(false);
  1503. if (restartMsg.success) {
  1504. this.loading(true);
  1505. await PromiseUtil.sleep(5000);
  1506. location.reload();
  1507. }
  1508. }
  1509. });
  1510. fileInput.click();
  1511. },
  1512. startPolling() {
  1513. // Fallback polling mechanism
  1514. const pollInterval = setInterval(async () => {
  1515. if (window.wsClient && window.wsClient.isConnected) {
  1516. clearInterval(pollInterval);
  1517. return;
  1518. }
  1519. try {
  1520. await this.getStatus();
  1521. } catch (e) {
  1522. console.error(e);
  1523. }
  1524. }, 2000);
  1525. },
  1526. },
  1527. async mounted() {
  1528. if (window.location.protocol !== "https:") {
  1529. this.showAlert = true;
  1530. }
  1531. const msg = await HttpUtil.post('/panel/setting/defaultSettings');
  1532. if (msg.success) {
  1533. this.ipLimitEnable = msg.obj.ipLimitEnable;
  1534. }
  1535. // Initial status fetch
  1536. await this.getStatus();
  1537. // Silently check for panel updates so the indicator shows on load
  1538. HttpUtil.get('/panel/api/server/getPanelUpdateInfo').then(msg => {
  1539. if (msg && msg.success && msg.obj) {
  1540. panelUpdateModal.info = msg.obj;
  1541. }
  1542. });
  1543. // Setup WebSocket for real-time updates
  1544. if (window.wsClient) {
  1545. window.wsClient.connect();
  1546. // Listen for status updates
  1547. window.wsClient.on('status', (payload) => {
  1548. this.setStatus(payload);
  1549. });
  1550. // Listen for Xray state changes
  1551. window.wsClient.on('xray_state', (payload) => {
  1552. if (this.status && this.status.xray) {
  1553. this.status.xray.state = payload.state;
  1554. this.status.xray.errorMsg = payload.errorMsg || '';
  1555. switch (payload.state) {
  1556. case 'running':
  1557. this.status.xray.color = "green";
  1558. this.status.xray.stateMsg = '{{ i18n "pages.index.xrayStatusRunning" }}';
  1559. break;
  1560. case 'stop':
  1561. this.status.xray.color = "orange";
  1562. this.status.xray.stateMsg = '{{ i18n "pages.index.xrayStatusStop" }}';
  1563. break;
  1564. case 'error':
  1565. this.status.xray.color = "red";
  1566. this.status.xray.stateMsg = '{{ i18n "pages.index.xrayStatusError" }}';
  1567. break;
  1568. }
  1569. }
  1570. });
  1571. // Notifications disabled - white notifications are not needed
  1572. // Fallback to polling if WebSocket fails
  1573. window.wsClient.on('error', () => {
  1574. console.warn('WebSocket connection failed, falling back to polling');
  1575. this.startPolling();
  1576. });
  1577. window.wsClient.on('disconnected', () => {
  1578. if (window.wsClient.reconnectAttempts >= window.wsClient.maxReconnectAttempts) {
  1579. console.warn('WebSocket reconnection failed, falling back to polling');
  1580. this.startPolling();
  1581. }
  1582. });
  1583. } else {
  1584. // Fallback to polling if WebSocket is not available
  1585. this.startPolling();
  1586. }
  1587. },
  1588. });
  1589. </script>
  1590. {{ template "page/body_end" .}}