index.html 61 KB

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