1
0

index.html 57 KB

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