index.html 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  1. {{ template "page/head_start" .}}
  2. {{ template "page/head_end" .}}
  3. {{ template "page/body_start" .}}
  4. <a-layout id="app" v-cloak :class="themeSwitcher.currentTheme + ' index-page'">
  5. <a-sidebar></a-sidebar>
  6. <a-layout id="content-layout">
  7. <a-layout-content>
  8. <a-spin :spinning="loadingStates.spinning" :delay="200" :tip="loadingTip">
  9. <transition name="list" appear>
  10. <a-alert type="error" v-if="showAlert && loadingStates.fetched" class="mb-10"
  11. message='{{ i18n "secAlertTitle" }}' color="red" description='{{ i18n "secAlertSsl" }}' show-icon closable>
  12. </a-alert>
  13. </transition>
  14. <transition name="list" appear>
  15. <template>
  16. <a-row v-if="!loadingStates.fetched">
  17. <a-card class="card-placeholder text-center">
  18. <a-spin tip='{{ i18n "loading" }}'></a-spin>
  19. </a-card>
  20. </a-row>
  21. <a-row :gutter="[isMobile ? 8 : 16, isMobile ? 0 : 12]" v-else>
  22. <a-col>
  23. <a-card hoverable>
  24. <a-row :gutter="[0, isMobile ? 16 : 0]">
  25. <a-col :sm="24" :md="12">
  26. <a-row>
  27. <a-col :span="12" class="text-center">
  28. <a-progress type="dashboard" status="normal" :stroke-color="status.cpu.color"
  29. :percent="status.cpu.percent"></a-progress>
  30. <div>
  31. <b>{{ i18n "pages.index.cpu" }}:</b> [[ CPUFormatter.cpuCoreFormat(status.cpuCores) ]]
  32. <a-tooltip>
  33. <a-icon type="area-chart"></a-icon>
  34. <template slot="title">
  35. <div><b>{{ i18n "pages.index.logicalProcessors" }}:</b> [[ (status.logicalPro) ]]</div>
  36. <div><b>{{ i18n "pages.index.frequency" }}:</b> [[
  37. CPUFormatter.cpuSpeedFormat(status.cpuSpeedMhz) ]]</div>
  38. </template>
  39. </a-tooltip>
  40. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  41. <a-button size="small" shape="circle" class="ml-8" @click="openCpuHistory()">
  42. <a-icon type="history" />
  43. </a-button>
  44. </a-tooltip>
  45. </div>
  46. </a-col>
  47. <a-col :span="12" class="text-center">
  48. <a-progress type="dashboard" status="normal" :stroke-color="status.mem.color"
  49. :percent="status.mem.percent"></a-progress>
  50. <div>
  51. <b>{{ i18n "pages.index.memory"}}:</b> [[ SizeFormatter.sizeFormat(status.mem.current) ]] /
  52. [[ SizeFormatter.sizeFormat(status.mem.total) ]]
  53. </div>
  54. </a-col>
  55. </a-row>
  56. </a-col>
  57. <a-col :sm="24" :md="12">
  58. <a-row>
  59. <a-col :span="12" class="text-center">
  60. <a-progress type="dashboard" status="normal" :stroke-color="status.swap.color"
  61. :percent="status.swap.percent"></a-progress>
  62. <div>
  63. <b>{{ i18n "pages.index.swap" }}:</b> [[ SizeFormatter.sizeFormat(status.swap.current) ]] /
  64. [[ SizeFormatter.sizeFormat(status.swap.total) ]]
  65. </div>
  66. </a-col>
  67. <a-col :span="12" class="text-center">
  68. <a-progress type="dashboard" status="normal" :stroke-color="status.disk.color"
  69. :percent="status.disk.percent"></a-progress>
  70. <div>
  71. <b>{{ i18n "pages.index.storage"}}:</b> [[ SizeFormatter.sizeFormat(status.disk.current) ]]
  72. / [[ SizeFormatter.sizeFormat(status.disk.total) ]]
  73. </div>
  74. </a-col>
  75. </a-row>
  76. </a-col>
  77. </a-row>
  78. </a-card>
  79. </a-col>
  80. <a-col :sm="24" :lg="12">
  81. <a-card hoverable>
  82. <template #title>
  83. <a-space direction="horizontal">
  84. <span>{{ i18n "pages.index.xrayStatus" }}</span>
  85. <a-tag v-if="isMobile && status.xray.version != 'Unknown'" color="green">
  86. v[[ status.xray.version ]]
  87. </a-tag>
  88. </a-space>
  89. </template>
  90. <template #extra>
  91. <template v-if="status.xray.state != 'error'">
  92. <a-badge status="processing"
  93. :class="({ green: 'xray-running-animation', orange: 'xray-stop-animation' }[status.xray.color]) || 'xray-processing-animation'"
  94. :text="status.xray.stateMsg" :color="status.xray.color" />
  95. </template>
  96. <template v-else>
  97. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  98. <span slot="title">
  99. <a-row type="flex" align="middle" justify="space-between">
  100. <a-col>
  101. <span>{{ i18n "pages.index.xrayErrorPopoverTitle" }}</span>
  102. </a-col>
  103. <a-col>
  104. <a-icon type="bars" class="cursor-pointer float-right" @click="openLogs()"></a-icon>
  105. </a-col>
  106. </a-row>
  107. </span>
  108. <template slot="content">
  109. <span class="max-w-400" v-for="line in status.xray.errorMsg.split('\n')">[[ line ]]</span>
  110. </template>
  111. <a-badge :text="status.xray.stateMsg" :color="status.xray.color"
  112. :class="status.xray.color === 'red' ? 'xray-error-animation' : ''" />
  113. </a-popover>
  114. </template>
  115. </template>
  116. <template #actions>
  117. <a-space v-if="app.ipLimitEnable" direction="horizontal" @click="openXrayLogs()" class="jc-center">
  118. <a-icon type="bars"></a-icon>
  119. <span v-if="!isMobile">{{ i18n "pages.index.logs" }}</span>
  120. </a-space>
  121. <a-space direction="horizontal" @click="stopXrayService" class="jc-center">
  122. <a-icon type="poweroff"></a-icon>
  123. <span v-if="!isMobile">{{ i18n "pages.index.stopXray" }}</span>
  124. </a-space>
  125. <a-space direction="horizontal" @click="restartXrayService" class="jc-center">
  126. <a-icon type="reload"></a-icon>
  127. <span v-if="!isMobile">{{ i18n "pages.index.restartXray" }}</span>
  128. </a-space>
  129. <a-space direction="horizontal" @click="openSelectV2rayVersion" class="jc-center">
  130. <a-icon type="tool"></a-icon>
  131. <span v-if="!isMobile">
  132. [[ status.xray.version != 'Unknown' ? `v${status.xray.version}` : '{{ i18n
  133. "pages.index.xraySwitch" }}' ]]
  134. </span>
  135. </a-space>
  136. </template>
  137. </a-card>
  138. </a-col>
  139. <a-col :sm="24" :lg="12">
  140. <a-card title='{{ i18n "menu.link" }}' hoverable>
  141. <template #actions>
  142. <a-space direction="horizontal" @click="openLogs()" class="jc-center">
  143. <a-icon type="bars"></a-icon>
  144. <span v-if="!isMobile">{{ i18n "pages.index.logs" }}</span>
  145. </a-space>
  146. <a-space direction="horizontal" @click="openConfig" class="jc-center">
  147. <a-icon type="control"></a-icon>
  148. <span v-if="!isMobile">{{ i18n "pages.index.config" }}</span>
  149. </a-space>
  150. <a-space direction="horizontal" @click="openBackup" class="jc-center">
  151. <a-icon type="cloud-server"></a-icon>
  152. <span v-if="!isMobile">{{ i18n "pages.index.backup" }}</span>
  153. </a-space>
  154. </template>
  155. </a-card>
  156. </a-col>
  157. <a-col :sm="24" :lg="12">
  158. <a-card title='3X-UI' hoverable>
  159. <a rel="noopener" href="https://github.com/MHSanaei/3x-ui/releases" target="_blank">
  160. <a-tag color="green">
  161. <span>v{{ .cur_ver }}</span>
  162. </a-tag>
  163. </a>
  164. <a rel="noopener" href="https://t.me/XrayUI" target="_blank">
  165. <a-tag color="green">
  166. <span>@XrayUI</span>
  167. </a-tag>
  168. </a>
  169. <a rel="noopener" href="https://github.com/MHSanaei/3x-ui/wiki" target="_blank">
  170. <a-tag color="purple">
  171. <span>{{ i18n "pages.index.documentation" }}</span>
  172. </a-tag>
  173. </a>
  174. </a-card>
  175. </a-col>
  176. <a-col :sm="24" :lg="12">
  177. <a-card title='{{ i18n "pages.index.operationHours" }}' hoverable>
  178. <a-tag :color="status.xray.color">Xray: [[ TimeFormatter.formatSecond(status.appStats.uptime)
  179. ]]</a-tag>
  180. <a-tag color="green">OS: [[ TimeFormatter.formatSecond(status.uptime) ]]</a-tag>
  181. </a-card>
  182. </a-col>
  183. <a-col :sm="24" :lg="12">
  184. <a-card title='{{ i18n "pages.index.systemLoad" }}' hoverable>
  185. <a-tag color="green">
  186. <a-tooltip>
  187. [[ status.loads[0] ]] | [[ status.loads[1] ]] | [[ status.loads[2] ]]
  188. <template slot="title">
  189. {{ i18n "pages.index.systemLoadDesc" }}
  190. </template>
  191. </a-tooltip>
  192. </a-tag>
  193. </a-card>
  194. </a-col>
  195. <a-col :sm="24" :lg="12">
  196. <a-card title='{{ i18n "usage"}}' hoverable>
  197. <a-tag color="green"> {{ i18n "pages.index.memory" }}: [[
  198. SizeFormatter.sizeFormat(status.appStats.mem) ]] </a-tag>
  199. <a-tag color="green"> {{ i18n "pages.index.threads" }}: [[ status.appStats.threads ]] </a-tag>
  200. </a-card>
  201. </a-col>
  202. <a-col :sm="24" :lg="12">
  203. <a-card title='{{ i18n "pages.index.overallSpeed" }}' hoverable>
  204. <a-row :gutter="isMobile ? [8,8] : 0">
  205. <a-col :span="12">
  206. <a-custom-statistic title='{{ i18n "pages.index.upload" }}'
  207. :value="SizeFormatter.sizeFormat(status.netIO.up)">
  208. <template #prefix>
  209. <a-icon type="arrow-up" />
  210. </template>
  211. <template #suffix>
  212. /s
  213. </template>
  214. </a-custom-statistic>
  215. </a-col>
  216. <a-col :span="12">
  217. <a-custom-statistic title='{{ i18n "pages.index.download" }}'
  218. :value="SizeFormatter.sizeFormat(status.netIO.down)">
  219. <template #prefix>
  220. <a-icon type="arrow-down" />
  221. </template>
  222. <template #suffix>
  223. /s
  224. </template>
  225. </a-custom-statistic>
  226. </a-col>
  227. </a-row>
  228. </a-card>
  229. </a-col>
  230. <a-col :sm="24" :lg="12">
  231. <a-card title='{{ i18n "pages.index.totalData" }}' hoverable>
  232. <a-row :gutter="isMobile ? [8,8] : 0">
  233. <a-col :span="12">
  234. <a-custom-statistic title='{{ i18n "pages.index.sent" }}'
  235. :value="SizeFormatter.sizeFormat(status.netTraffic.sent)">
  236. <template #prefix>
  237. <a-icon type="cloud-upload" />
  238. </template>
  239. </a-custom-statistic>
  240. </a-col>
  241. <a-col :span="12">
  242. <a-custom-statistic title='{{ i18n "pages.index.received" }}'
  243. :value="SizeFormatter.sizeFormat(status.netTraffic.recv)">
  244. <template #prefix>
  245. <a-icon type="cloud-download" />
  246. </template>
  247. </a-custom-statistic>
  248. </a-col>
  249. </a-row>
  250. </a-card>
  251. </a-col>
  252. <a-col :sm="24" :lg="12">
  253. <a-card title='{{ i18n "pages.index.ipAddresses" }}' hoverable>
  254. <template #extra>
  255. <a-tooltip :placement="isMobile ? 'topRight' : 'top'">
  256. <template #title>
  257. {{ i18n "pages.index.toggleIpVisibility" }}
  258. </template>
  259. <a-icon :type="showIp ? 'eye' : 'eye-invisible'" class="fs-1rem"
  260. @click="showIp = !showIp"></a-icon>
  261. </a-tooltip>
  262. </template>
  263. <a-row :class="showIp ? 'ip-visible' : 'ip-hidden'" :gutter="isMobile ? [8,8] : 0">
  264. <a-col :span="isMobile ? 24 : 12">
  265. <a-custom-statistic title="IPv4" :value="status.publicIP.ipv4">
  266. <template #prefix>
  267. <a-icon type="global" />
  268. </template>
  269. </a-custom-statistic>
  270. </a-col>
  271. <a-col :span="isMobile ? 24 : 12">
  272. <a-custom-statistic title="IPv6" :value="status.publicIP.ipv6">
  273. <template #prefix>
  274. <a-icon type="global" />
  275. </template>
  276. </a-custom-statistic>
  277. </a-col>
  278. </a-row>
  279. </a-card>
  280. </a-col>
  281. <a-col :sm="24" :lg="12">
  282. <a-card title='{{ i18n "pages.index.connectionCount" }}' hoverable>
  283. <a-row :gutter="isMobile ? [8,8] : 0">
  284. <a-col :span="12">
  285. <a-custom-statistic title="TCP" :value="status.tcpCount">
  286. <template #prefix>
  287. <a-icon type="swap" />
  288. </template>
  289. </a-custom-statistic>
  290. </a-col>
  291. <a-col :span="12">
  292. <a-custom-statistic title="UDP" :value="status.udpCount">
  293. <template #prefix>
  294. <a-icon type="swap" />
  295. </template>
  296. </a-custom-statistic>
  297. </a-col>
  298. </a-row>
  299. </a-card>
  300. </a-col>
  301. </a-row>
  302. </template>
  303. </transition>
  304. </a-spin>
  305. </a-layout-content>
  306. </a-layout>
  307. <a-modal id="version-modal" v-model="versionModal.visible" title='{{ i18n "pages.index.xraySwitch" }}'
  308. :closable="true" @ok="() => versionModal.visible = false" :class="themeSwitcher.currentTheme" footer="">
  309. <a-collapse default-active-key="1">
  310. <a-collapse-panel key="1" header='Xray'>
  311. <a-alert type="warning" class="mb-12 w-100" message='{{ i18n "pages.index.xraySwitchClickDesk" }}'
  312. show-icon></a-alert>
  313. <a-list class="ant-version-list w-100" bordered>
  314. <a-list-item class="ant-version-list-item" v-for="version, index in versionModal.versions">
  315. <a-tag :color="index % 2 == 0 ? 'purple' : 'green'">[[ version ]]</a-tag>
  316. <a-radio :class="themeSwitcher.currentTheme" :checked="version === `v${status.xray.version}`"
  317. @click="switchV2rayVersion(version)"></a-radio>
  318. </a-list-item>
  319. </a-list>
  320. </a-collapse-panel>
  321. <a-collapse-panel key="2" header='Geofiles'>
  322. <a-list class="ant-version-list w-100" bordered>
  323. <a-list-item class="ant-version-list-item"
  324. v-for="file, index in ['geosite.dat', 'geoip.dat', 'geosite_IR.dat', 'geoip_IR.dat', 'geosite_RU.dat', 'geoip_RU.dat']">
  325. <a-tag :color="index % 2 == 0 ? 'purple' : 'green'">[[ file ]]</a-tag>
  326. <a-icon type="reload" @click="updateGeofile(file)" class="mr-8" />
  327. </a-list-item>
  328. </a-list>
  329. <div class="mt-5 d-flex justify-end"><a-button @click="updateGeofile('')">{{ i18n
  330. "pages.index.geofilesUpdateAll" }}</a-button></div>
  331. </a-collapse-panel>
  332. </a-collapse>
  333. </a-modal>
  334. <a-modal id="log-modal" v-model="logModal.visible" :closable="true" @cancel="() => logModal.visible = false"
  335. :class="themeSwitcher.currentTheme" width="800px" footer="">
  336. <template slot="title">
  337. {{ i18n "pages.index.logs" }}
  338. <a-icon :spin="logModal.loading" type="sync" class="va-middle ml-10" :disabled="logModal.loading"
  339. @click="openLogs()">
  340. </a-icon>
  341. </template>
  342. <a-form layout="inline">
  343. <a-form-item class="mr-05">
  344. <a-input-group compact>
  345. <a-select size="small" v-model="logModal.rows" :style="{ width: '70px' }" @change="openLogs()"
  346. :dropdown-class-name="themeSwitcher.currentTheme">
  347. <a-select-option value="10">10</a-select-option>
  348. <a-select-option value="20">20</a-select-option>
  349. <a-select-option value="50">50</a-select-option>
  350. <a-select-option value="100">100</a-select-option>
  351. <a-select-option value="500">500</a-select-option>
  352. </a-select>
  353. <a-select size="small" v-model="logModal.level" :style="{ width: '95px' }" @change="openLogs()"
  354. :dropdown-class-name="themeSwitcher.currentTheme">
  355. <a-select-option value="debug">Debug</a-select-option>
  356. <a-select-option value="info">Info</a-select-option>
  357. <a-select-option value="notice">Notice</a-select-option>
  358. <a-select-option value="warning">Warning</a-select-option>
  359. <a-select-option value="err">Error</a-select-option>
  360. </a-select>
  361. </a-input-group>
  362. </a-form-item>
  363. <a-form-item>
  364. <a-checkbox v-model="logModal.syslog" @change="openLogs()">SysLog</a-checkbox>
  365. </a-form-item>
  366. <a-form-item style="float: right;">
  367. <a-button type="primary" icon="download" @click="FileManager.downloadTextFile(logModal.logs?.join('\n'), 'x-ui.log')"></a-button>
  368. </a-form-item>
  369. </a-form>
  370. <div class="ant-input log-container" v-html="logModal.formattedLogs"></div>
  371. </a-modal>
  372. <a-modal id="xraylog-modal" v-model="xraylogModal.visible" :closable="true"
  373. @cancel="() => xraylogModal.visible = false" :class="themeSwitcher.currentTheme" width="80vw" footer="">
  374. <template slot="title">
  375. {{ i18n "pages.index.logs" }}
  376. <a-icon :spin="xraylogModal.loading" type="sync" class="va-middle ml-10" :disabled="xraylogModal.loading"
  377. @click="openXrayLogs()">
  378. </a-icon>
  379. </template>
  380. <a-form layout="inline">
  381. <a-form-item class="mr-05">
  382. <a-input-group compact>
  383. <a-select size="small" v-model="xraylogModal.rows" :style="{ width: '70px' }" @change="openXrayLogs()"
  384. :dropdown-class-name="themeSwitcher.currentTheme">
  385. <a-select-option value="10">10</a-select-option>
  386. <a-select-option value="20">20</a-select-option>
  387. <a-select-option value="50">50</a-select-option>
  388. <a-select-option value="100">100</a-select-option>
  389. <a-select-option value="500">500</a-select-option>
  390. </a-select>
  391. </a-input-group>
  392. </a-form-item>
  393. <a-form-item label="Filter:">
  394. <a-input size="small" v-model="xraylogModal.filter" @keyup.enter="openXrayLogs()"></a-input>
  395. </a-form-item>
  396. <a-form-item>
  397. <a-checkbox v-model="xraylogModal.showDirect" @change="openXrayLogs()">Direct</a-checkbox>
  398. <a-checkbox v-model="xraylogModal.showBlocked" @change="openXrayLogs()">Blocked</a-checkbox>
  399. <a-checkbox v-model="xraylogModal.showProxy" @change="openXrayLogs()">Proxy</a-checkbox>
  400. </a-form-item>
  401. <a-form-item style="float: right;">
  402. <a-button type="primary" icon="download" @click="downloadXrayLogs"></a-button>
  403. </a-form-item>
  404. </a-form>
  405. <div class="ant-input log-container" v-html="xraylogModal.formattedLogs"></div>
  406. </a-modal>
  407. <a-modal id="backup-modal" v-model="backupModal.visible" title='{{ i18n "pages.index.backupTitle" }}' :closable="true"
  408. footer="" :class="themeSwitcher.currentTheme">
  409. <a-list class="ant-backup-list w-100" bordered>
  410. <a-list-item class="ant-backup-list-item">
  411. <a-list-item-meta>
  412. <template #title>{{ i18n "pages.index.exportDatabase" }}</template>
  413. <template #description>{{ i18n "pages.index.exportDatabaseDesc" }}</template>
  414. </a-list-item-meta>
  415. <a-button @click="exportDatabase()" type="primary" icon="download" />
  416. </a-list-item>
  417. <a-list-item class="ant-backup-list-item">
  418. <a-list-item-meta>
  419. <template #title>{{ i18n "pages.index.importDatabase" }}</template>
  420. <template #description>{{ i18n "pages.index.importDatabaseDesc" }}</template>
  421. </a-list-item-meta>
  422. <a-button @click="importDatabase()" type="primary" icon="upload" />
  423. </a-list-item>
  424. </a-list>
  425. </a-modal>
  426. <!-- CPU History Modal -->
  427. <a-modal id="cpu-history-modal" v-model="cpuHistoryModal.visible" :closable="true"
  428. @cancel="() => cpuHistoryModal.visible = false" :class="themeSwitcher.currentTheme" width="900px" footer="">
  429. <template slot="title">
  430. CPU History
  431. <a-select size="small" v-model="cpuHistoryModal.bucket" class="ml-10" style="width: 80px"
  432. @change="fetchCpuHistoryBucket">
  433. <a-select-option :value="2">2m</a-select-option>
  434. <a-select-option :value="30">30m</a-select-option>
  435. <a-select-option :value="60">1h</a-select-option>
  436. <a-select-option :value="120">2h</a-select-option>
  437. <a-select-option :value="180">3h</a-select-option>
  438. <a-select-option :value="300">5h</a-select-option>
  439. </a-select>
  440. </template>
  441. <div style="padding:16px">
  442. <sparkline :data="cpuHistoryLong" :labels="cpuHistoryLabels" :vb-width="840" :height="220"
  443. :stroke="status.cpu.color" :stroke-width="2.2" :show-grid="true" :show-axes="true" :tick-count-x="5"
  444. :max-points="cpuHistoryLong.length" :fill-opacity="0.18" :marker-radius="3.2" :show-tooltip="true" />
  445. <div style="margin-top:4px;font-size:11px;opacity:0.65">Timeframe: [[ cpuHistoryModal.bucket ]] sec per point (total [[ cpuHistoryLong.length ]] points)</div>
  446. </div>
  447. </a-modal>
  448. </a-layout>
  449. {{template "page/body_scripts" .}}
  450. {{template "component/aSidebar" .}}
  451. {{template "component/aThemeSwitch" .}}
  452. {{template "component/aCustomStatistic" .}}
  453. {{template "modals/textModal"}}
  454. <script>
  455. // Tiny Sparkline component using an inline SVG polyline
  456. Vue.component('sparkline', {
  457. props: {
  458. data: { type: Array, required: true },
  459. // viewBox width for drawing space; SVG width will be 100% of container
  460. vbWidth: { type: Number, default: 320 },
  461. height: { type: Number, default: 80 },
  462. stroke: { type: String, default: '#008771' },
  463. strokeWidth: { type: Number, default: 2 },
  464. maxPoints: { type: Number, default: 120 },
  465. showGrid: { type: Boolean, default: true },
  466. gridColor: { type: String, default: 'rgba(0,0,0,0.1)' },
  467. fillOpacity: { type: Number, default: 0.15 },
  468. showMarker: { type: Boolean, default: true },
  469. markerRadius: { type: Number, default: 2.8 },
  470. // New opts for axes/labels/tooltip
  471. labels: { type: Array, default: () => [] }, // same length as data for x labels (e.g., timestamps)
  472. showAxes: { type: Boolean, default: false },
  473. yTickStep: { type: Number, default: 25 }, // percent ticks
  474. tickCountX: { type: Number, default: 4 },
  475. paddingLeft: { type: Number, default: 32 },
  476. paddingRight: { type: Number, default: 6 },
  477. paddingTop: { type: Number, default: 6 },
  478. paddingBottom: { type: Number, default: 20 },
  479. showTooltip: { type: Boolean, default: false },
  480. },
  481. data() {
  482. return {
  483. hoverIdx: -1,
  484. }
  485. },
  486. computed: {
  487. viewBoxAttr() {
  488. return '0 0 ' + this.vbWidth + ' ' + this.height
  489. },
  490. drawWidth() {
  491. return Math.max(1, this.vbWidth - this.paddingLeft - this.paddingRight)
  492. },
  493. drawHeight() {
  494. return Math.max(1, this.height - this.paddingTop - this.paddingBottom)
  495. },
  496. nPoints() {
  497. return Math.min(this.data.length, this.maxPoints)
  498. },
  499. dataSlice() {
  500. const n = this.nPoints
  501. if (n === 0) return []
  502. return this.data.slice(this.data.length - n)
  503. },
  504. labelsSlice() {
  505. const n = this.nPoints
  506. if (!this.labels || this.labels.length === 0 || n === 0) return []
  507. const start = Math.max(0, this.labels.length - n)
  508. return this.labels.slice(start)
  509. },
  510. pointsArr() {
  511. const n = this.nPoints
  512. if (n === 0) return []
  513. const slice = this.dataSlice
  514. const max = 100
  515. const w = this.drawWidth
  516. const h = this.drawHeight
  517. const dx = n > 1 ? w / (n - 1) : 0
  518. return slice.map((v, i) => {
  519. const x = Math.round(this.paddingLeft + i * dx)
  520. const y = Math.round(this.paddingTop + (h - (Math.max(0, Math.min(100, v)) / max) * h))
  521. return [x, y]
  522. })
  523. },
  524. points() {
  525. return this.pointsArr.map(p => `${p[0]},${p[1]}`).join(' ')
  526. },
  527. areaPath() {
  528. if (this.pointsArr.length === 0) return ''
  529. const first = this.pointsArr[0]
  530. const last = this.pointsArr[this.pointsArr.length - 1]
  531. const line = this.points
  532. // Close to bottom to create an area fill
  533. return `M ${first[0]},${this.paddingTop + this.drawHeight} L ${line.replace(/ /g, ' L ')} L ${last[0]},${this.paddingTop + this.drawHeight} Z`
  534. },
  535. gridLines() {
  536. if (!this.showGrid) return []
  537. const h = this.drawHeight
  538. const w = this.drawWidth
  539. // draw at 25%, 50%, 75%
  540. return [0, 0.25, 0.5, 0.75, 1]
  541. .map(r => Math.round(this.paddingTop + h * r))
  542. .map(y => ({ x1: this.paddingLeft, y1: y, x2: this.paddingLeft + w, y2: y }))
  543. },
  544. lastPoint() {
  545. if (this.pointsArr.length === 0) return null
  546. return this.pointsArr[this.pointsArr.length - 1]
  547. },
  548. yTicks() {
  549. if (!this.showAxes) return []
  550. const step = Math.max(1, this.yTickStep)
  551. const ticks = []
  552. for (let p = 0; p <= 100; p += step) {
  553. const y = Math.round(this.paddingTop + (this.drawHeight - (p / 100) * this.drawHeight))
  554. ticks.push({ y, label: `${p}%` })
  555. }
  556. return ticks
  557. },
  558. xTicks() {
  559. if (!this.showAxes) return []
  560. const labels = this.labelsSlice
  561. const n = this.nPoints
  562. const m = Math.max(2, this.tickCountX)
  563. const ticks = []
  564. if (n === 0) return ticks
  565. const w = this.drawWidth
  566. const dx = n > 1 ? w / (n - 1) : 0
  567. const positions = []
  568. for (let i = 0; i < m; i++) {
  569. const idx = Math.round((i * (n - 1)) / (m - 1))
  570. positions.push(idx)
  571. }
  572. positions.forEach(idx => {
  573. const label = labels[idx] != null ? String(labels[idx]) : String(idx)
  574. const x = Math.round(this.paddingLeft + idx * dx)
  575. ticks.push({ x, label })
  576. })
  577. return ticks
  578. },
  579. },
  580. methods: {
  581. onMouseMove(evt) {
  582. if (!this.showTooltip || this.pointsArr.length === 0) return
  583. const rect = evt.currentTarget.getBoundingClientRect()
  584. const px = evt.clientX - rect.left
  585. // translate to viewBox space
  586. const x = (px / rect.width) * this.vbWidth
  587. const n = this.nPoints
  588. const dx = n > 1 ? this.drawWidth / (n - 1) : 0
  589. const idx = Math.max(0, Math.min(n - 1, Math.round((x - this.paddingLeft) / (dx || 1))))
  590. this.hoverIdx = idx
  591. },
  592. onMouseLeave() {
  593. this.hoverIdx = -1
  594. },
  595. fmtHoverText() {
  596. const labels = this.labelsSlice
  597. const idx = this.hoverIdx
  598. if (idx < 0 || idx >= this.dataSlice.length) return ''
  599. const raw = Math.max(0, Math.min(100, Number(this.dataSlice[idx] || 0)))
  600. const val = Number.isFinite(raw) ? raw.toFixed(2) : raw
  601. const lab = labels[idx] != null ? labels[idx] : ''
  602. return `${val}%${lab ? ' • ' + lab : ''}`
  603. },
  604. },
  605. template: `
  606. <svg width="100%" :height="height" :viewBox="viewBoxAttr" preserveAspectRatio="none" class="idx-cpu-history-svg"
  607. @mousemove="onMouseMove" @mouseleave="onMouseLeave">
  608. <defs>
  609. <linearGradient id="spkGrad" x1="0" y1="0" x2="0" y2="1">
  610. <stop offset="0%" :stop-color="stroke" :stop-opacity="fillOpacity"/>
  611. <stop offset="100%" :stop-color="stroke" stop-opacity="0"/>
  612. </linearGradient>
  613. </defs>
  614. <g v-if="showGrid">
  615. <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" />
  616. </g>
  617. <g v-if="showAxes">
  618. <!-- Y ticks/labels -->
  619. <g v-for="(t,i) in yTicks" :key="'y'+i">
  620. <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>
  621. </g>
  622. <!-- X ticks/labels -->
  623. <g v-for="(t,i) in xTicks" :key="'x'+i">
  624. <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>
  625. </g>
  626. </g>
  627. <path v-if="areaPath" :d="areaPath" fill="url(#spkGrad)" stroke="none" />
  628. <polyline :points="points" fill="none" :stroke="stroke" :stroke-width="strokeWidth" stroke-linecap="round" stroke-linejoin="round"/>
  629. <circle v-if="showMarker && lastPoint" :cx="lastPoint[0]" :cy="lastPoint[1]" :r="markerRadius" :fill="stroke" />
  630. <!-- Hover marker/tooltip -->
  631. <g v-if="showTooltip && hoverIdx >= 0">
  632. <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" />
  633. <circle :cx="pointsArr[hoverIdx][0]" :cy="pointsArr[hoverIdx][1]" r="3.5" :fill="stroke" />
  634. <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>
  635. </g>
  636. </svg>
  637. `,
  638. })
  639. class CurTotal {
  640. constructor(current, total) {
  641. this.current = current;
  642. this.total = total;
  643. }
  644. get percent() {
  645. if (this.total === 0) {
  646. return 0;
  647. }
  648. return NumberFormatter.toFixed(this.current / this.total * 100, 2);
  649. }
  650. get color() {
  651. const percent = this.percent;
  652. if (percent < 80) {
  653. return '#008771'; // Green
  654. } else if (percent < 90) {
  655. return "#f37b24"; // Orange
  656. } else {
  657. return "#cf3c3c"; // Red
  658. }
  659. }
  660. }
  661. class Status {
  662. constructor(data) {
  663. this.cpu = new CurTotal(0, 0);
  664. this.cpuCores = 0;
  665. this.logicalPro = 0;
  666. this.cpuSpeedMhz = 0;
  667. this.disk = new CurTotal(0, 0);
  668. this.loads = [0, 0, 0];
  669. this.mem = new CurTotal(0, 0);
  670. this.netIO = { up: 0, down: 0 };
  671. this.netTraffic = { sent: 0, recv: 0 };
  672. this.publicIP = { ipv4: 0, ipv6: 0 };
  673. this.swap = new CurTotal(0, 0);
  674. this.tcpCount = 0;
  675. this.udpCount = 0;
  676. this.uptime = 0;
  677. this.appUptime = 0;
  678. this.appStats = { threads: 0, mem: 0, uptime: 0 };
  679. this.xray = { state: 'stop', stateMsg: "", errorMsg: "", version: "", color: "" };
  680. if (data == null) {
  681. return;
  682. }
  683. this.cpu = new CurTotal(data.cpu, 100);
  684. this.cpuCores = data.cpuCores;
  685. this.logicalPro = data.logicalPro;
  686. this.cpuSpeedMhz = data.cpuSpeedMhz;
  687. this.disk = new CurTotal(data.disk.current, data.disk.total);
  688. this.loads = data.loads.map(load => NumberFormatter.toFixed(load, 2));
  689. this.mem = new CurTotal(data.mem.current, data.mem.total);
  690. this.netIO = data.netIO;
  691. this.netTraffic = data.netTraffic;
  692. this.publicIP = data.publicIP;
  693. this.swap = new CurTotal(data.swap.current, data.swap.total);
  694. this.tcpCount = data.tcpCount;
  695. this.udpCount = data.udpCount;
  696. this.uptime = data.uptime;
  697. this.appUptime = data.appUptime;
  698. this.appStats = data.appStats;
  699. this.xray = data.xray;
  700. switch (this.xray.state) {
  701. case 'running':
  702. this.xray.color = "green";
  703. this.xray.stateMsg = '{{ i18n "pages.index.xrayStatusRunning" }}';
  704. break;
  705. case 'stop':
  706. this.xray.color = "orange";
  707. this.xray.stateMsg = '{{ i18n "pages.index.xrayStatusStop" }}';
  708. break;
  709. case 'error':
  710. this.xray.color = "red";
  711. this.xray.stateMsg = '{{ i18n "pages.index.xrayStatusError" }}';
  712. break;
  713. default:
  714. this.xray.color = "gray";
  715. this.xray.stateMsg = '{{ i18n "pages.index.xrayStatusUnknown" }}';
  716. break;
  717. }
  718. }
  719. }
  720. const versionModal = {
  721. visible: false,
  722. versions: [],
  723. show(versions) {
  724. this.visible = true;
  725. this.versions = versions;
  726. },
  727. hide() {
  728. this.visible = false;
  729. },
  730. };
  731. const logModal = {
  732. visible: false,
  733. logs: [],
  734. rows: 20,
  735. level: 'info',
  736. syslog: false,
  737. loading: false,
  738. show(logs) {
  739. this.visible = true;
  740. this.logs = logs;
  741. this.formattedLogs = this.logs?.length > 0 ? this.formatLogs(this.logs) : "No Record...";
  742. },
  743. formatLogs(logs) {
  744. let formattedLogs = '';
  745. const levels = ["DEBUG", "INFO", "NOTICE", "WARNING", "ERROR"];
  746. const levelColors = ["#3c89e8", "#008771", "#008771", "#f37b24", "#e04141", "#bcbcbc"];
  747. logs.forEach((log, index) => {
  748. let [data, message] = log.split(" - ", 2);
  749. const parts = data.split(" ")
  750. if (index > 0) formattedLogs += '<br>';
  751. if (parts.length === 3) {
  752. const d = parts[0];
  753. const t = parts[1];
  754. const level = parts[2];
  755. const levelIndex = levels.indexOf(level, levels) || 5;
  756. //formattedLogs += `<span style="color: gray;">${index + 1}.</span>`;
  757. formattedLogs += `<span style="color: ${levelColors[0]};">${d} ${t}</span> `;
  758. formattedLogs += `<span style="color: ${levelColors[levelIndex]}">${level}</span>`;
  759. } else {
  760. const levelIndex = levels.indexOf(data, levels) || 5;
  761. formattedLogs += `<span style="color: ${levelColors[levelIndex]}">${data}</span>`;
  762. }
  763. if (message) {
  764. if (message.startsWith("XRAY:"))
  765. message = "<b>XRAY: </b>" + message.substring(5);
  766. else
  767. message = "<b>X-UI: </b>" + message;
  768. }
  769. formattedLogs += message ? ' - ' + message : '';
  770. });
  771. return formattedLogs;
  772. },
  773. hide() {
  774. this.visible = false;
  775. },
  776. };
  777. const xraylogModal = {
  778. visible: false,
  779. logs: [],
  780. rows: 20,
  781. showDirect: true,
  782. showBlocked: true,
  783. showProxy: true,
  784. loading: false,
  785. show(logs) {
  786. this.visible = true;
  787. this.logs = logs;
  788. this.formattedLogs = this.logs?.length > 0 ? this.formatLogs(this.logs) : "No Record...";
  789. },
  790. formatLogs(logs) {
  791. let formattedLogs = `
  792. <style>
  793. table {
  794. border-collapse: collapse;
  795. width: auto;
  796. }
  797. table td, table th {
  798. padding: 2px 15px;
  799. }
  800. </style>
  801. <table>
  802. <tr>
  803. <th>Date</th>
  804. <th>From</th>
  805. <th>To</th>
  806. <th>Inbound</th>
  807. <th>Outbound</th>
  808. <th>Email</th>
  809. </tr>
  810. `;
  811. logs.reverse().forEach((log, index) => {
  812. let outboundColor = '';
  813. if (log.Event === 1) {
  814. outboundColor = ' style="color: #e04141;"'; //red for blocked
  815. }
  816. else if (log.Event === 2) {
  817. outboundColor = ' style="color: #3c89e8;"'; //blue for proxies
  818. }
  819. let text = ``;
  820. if (log.Email !== "") {
  821. text = `<td>${log.Email}</td>`;
  822. }
  823. formattedLogs += `
  824. <tr ${outboundColor}>
  825. <td><b>${IntlUtil.formatDate(log.DateTime)}</b></td>
  826. <td>${log.FromAddress}</td>
  827. <td>${log.ToAddress}</td>
  828. <td>${log.Inbound}</td>
  829. <td>${log.Outbound}</td>
  830. ${text}
  831. </tr>
  832. `;
  833. });
  834. return formattedLogs += "</table>";
  835. },
  836. hide() {
  837. this.visible = false;
  838. },
  839. };
  840. const backupModal = {
  841. visible: false,
  842. show() {
  843. this.visible = true;
  844. },
  845. hide() {
  846. this.visible = false;
  847. },
  848. };
  849. const app = new Vue({
  850. delimiters: ['[[', ']]'],
  851. el: '#app',
  852. mixins: [MediaQueryMixin],
  853. data: {
  854. themeSwitcher,
  855. loadingStates: {
  856. fetched: false,
  857. spinning: false
  858. },
  859. status: new Status(),
  860. cpuHistory: [], // small live widget history
  861. cpuHistoryLong: [], // aggregated points from backend
  862. cpuHistoryLabels: [],
  863. cpuHistoryModal: { visible: false, bucket: 2 },
  864. versionModal,
  865. logModal,
  866. xraylogModal,
  867. backupModal,
  868. loadingTip: '{{ i18n "loading"}}',
  869. showAlert: false,
  870. showIp: false,
  871. ipLimitEnable: false,
  872. },
  873. methods: {
  874. loading(spinning, tip = '{{ i18n "loading"}}') {
  875. this.loadingStates.spinning = spinning;
  876. this.loadingTip = tip;
  877. },
  878. async getStatus() {
  879. try {
  880. const msg = await HttpUtil.get('/panel/api/server/status');
  881. if (msg.success) {
  882. if (!this.loadingStates.fetched) {
  883. this.loadingStates.fetched = true;
  884. }
  885. this.setStatus(msg.obj, true);
  886. }
  887. } catch (e) {
  888. console.error("Failed to get status:", e);
  889. }
  890. },
  891. setStatus(data) {
  892. this.status = new Status(data);
  893. // Push CPU percent into history (clamped 0..100)
  894. const v = Math.max(0, Math.min(100, Number(data?.cpu ?? 0)))
  895. this.cpuHistory.push(v)
  896. const maxPoints = this.isMobile ? 60 : 120
  897. if (this.cpuHistory.length > maxPoints) {
  898. this.cpuHistory.splice(0, this.cpuHistory.length - maxPoints)
  899. }
  900. // If modal open, refresh current bucketed data
  901. if (this.cpuHistoryModal.visible) {
  902. this.fetchCpuHistoryBucket()
  903. }
  904. },
  905. openCpuHistory() {
  906. this.cpuHistoryModal.visible = true
  907. this.fetchCpuHistoryBucket()
  908. },
  909. async fetchCpuHistoryBucket() {
  910. const bucket = this.cpuHistoryModal.bucket || 2
  911. try {
  912. const msg = await HttpUtil.get(`/panel/api/server/cpuHistory/${bucket}`)
  913. if (msg.success && Array.isArray(msg.obj)) {
  914. const vals = []
  915. const labels = []
  916. for (const p of msg.obj) {
  917. const d = new Date(p.t * 1000)
  918. const hh = String(d.getHours()).padStart(2,'0')
  919. const mm = String(d.getMinutes()).padStart(2,'0')
  920. const ss = String(d.getSeconds()).padStart(2,'0')
  921. labels.push(bucket>=60 ? `${hh}:${mm}` : `${hh}:${mm}:${ss}`)
  922. vals.push(Math.max(0, Math.min(100, p.cpu)))
  923. }
  924. this.cpuHistoryLabels = labels
  925. this.cpuHistoryLong = vals
  926. }
  927. } catch(e) {
  928. console.error('Failed to fetch bucketed cpu history', e)
  929. }
  930. },
  931. async openSelectV2rayVersion() {
  932. this.loading(true);
  933. const msg = await HttpUtil.get('/panel/api/server/getXrayVersion');
  934. this.loading(false);
  935. if (!msg.success) {
  936. return;
  937. }
  938. versionModal.show(msg.obj);
  939. },
  940. switchV2rayVersion(version) {
  941. this.$confirm({
  942. title: '{{ i18n "pages.index.xraySwitchVersionDialog"}}',
  943. content: '{{ i18n "pages.index.xraySwitchVersionDialogDesc"}}'.replace('#version#', version),
  944. okText: '{{ i18n "confirm"}}',
  945. class: themeSwitcher.currentTheme,
  946. cancelText: '{{ i18n "cancel"}}',
  947. onOk: async () => {
  948. versionModal.hide();
  949. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  950. await HttpUtil.post(`/panel/api/server/installXray/${version}`);
  951. this.loading(false);
  952. },
  953. });
  954. },
  955. updateGeofile(fileName) {
  956. const isSingleFile = !!fileName;
  957. this.$confirm({
  958. title: '{{ i18n "pages.index.geofileUpdateDialog" }}',
  959. content: isSingleFile
  960. ? '{{ i18n "pages.index.geofileUpdateDialogDesc" }}'.replace("#filename#", fileName)
  961. : '{{ i18n "pages.index.geofilesUpdateDialogDesc" }}',
  962. okText: '{{ i18n "confirm"}}',
  963. class: themeSwitcher.currentTheme,
  964. cancelText: '{{ i18n "cancel"}}',
  965. onOk: async () => {
  966. versionModal.hide();
  967. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  968. const url = isSingleFile
  969. ? `/panel/api/server/updateGeofile/${fileName}`
  970. : `/panel/api/server/updateGeofile`;
  971. await HttpUtil.post(url);
  972. this.loading(false);
  973. },
  974. });
  975. },
  976. async stopXrayService() {
  977. this.loading(true);
  978. const msg = await HttpUtil.post('/panel/api/server/stopXrayService');
  979. this.loading(false);
  980. if (!msg.success) {
  981. return;
  982. }
  983. },
  984. async restartXrayService() {
  985. this.loading(true);
  986. const msg = await HttpUtil.post('/panel/api/server/restartXrayService');
  987. this.loading(false);
  988. if (!msg.success) {
  989. return;
  990. }
  991. },
  992. async openLogs() {
  993. logModal.loading = true;
  994. const msg = await HttpUtil.post('/panel/api/server/logs/' + logModal.rows, { level: logModal.level, syslog: logModal.syslog });
  995. if (!msg.success) {
  996. return;
  997. }
  998. logModal.show(msg.obj);
  999. await PromiseUtil.sleep(500);
  1000. logModal.loading = false;
  1001. },
  1002. async openXrayLogs() {
  1003. xraylogModal.loading = true;
  1004. const msg = await HttpUtil.post('/panel/api/server/xraylogs/' + xraylogModal.rows, { filter: xraylogModal.filter, showDirect: xraylogModal.showDirect, showBlocked: xraylogModal.showBlocked, showProxy: xraylogModal.showProxy });
  1005. if (!msg.success) {
  1006. return;
  1007. }
  1008. xraylogModal.show(msg.obj);
  1009. await PromiseUtil.sleep(500);
  1010. xraylogModal.loading = false;
  1011. },
  1012. downloadXrayLogs() {
  1013. if (!Array.isArray(this.xraylogModal.logs) || this.xraylogModal.logs.length === 0) {
  1014. FileManager.downloadTextFile('', 'x-ui.log');
  1015. return;
  1016. }
  1017. const lines = this.xraylogModal.logs.map(l => {
  1018. try {
  1019. const dt = l.DateTime ? new Date(l.DateTime) : null;
  1020. const dateStr = dt && !isNaN(dt.getTime()) ? dt.toISOString() : '';
  1021. const eventMap = { 0: 'DIRECT', 1: 'BLOCKED', 2: 'PROXY' };
  1022. const eventText = eventMap[l.Event] || String(l.Event ?? '');
  1023. const emailPart = l.Email ? ` Email=${l.Email}` : '';
  1024. return `${dateStr} FROM=${l.FromAddress || ''} TO=${l.ToAddress || ''} INBOUND=${l.Inbound || ''} OUTBOUND=${l.Outbound || ''}${emailPart} EVENT=${eventText}`.trim();
  1025. } catch (e) {
  1026. return JSON.stringify(l);
  1027. }
  1028. }).join('\n');
  1029. FileManager.downloadTextFile(lines, 'x-ui.log');
  1030. },
  1031. async openConfig() {
  1032. this.loading(true);
  1033. const msg = await HttpUtil.get('/panel/api/server/getConfigJson');
  1034. this.loading(false);
  1035. if (!msg.success) {
  1036. return;
  1037. }
  1038. txtModal.show('config.json', JSON.stringify(msg.obj, null, 2), 'config.json');
  1039. },
  1040. openBackup() {
  1041. backupModal.show();
  1042. },
  1043. exportDatabase() {
  1044. window.location = basePath + 'panel/api/server/getDb';
  1045. },
  1046. importDatabase() {
  1047. const fileInput = document.createElement('input');
  1048. fileInput.type = 'file';
  1049. fileInput.accept = '.db';
  1050. fileInput.addEventListener('change', async (event) => {
  1051. const dbFile = event.target.files[0];
  1052. if (dbFile) {
  1053. const formData = new FormData();
  1054. formData.append('db', dbFile);
  1055. backupModal.hide();
  1056. this.loading(true);
  1057. const uploadMsg = await HttpUtil.post('/panel/api/server/importDB', formData, {
  1058. headers: {
  1059. 'Content-Type': 'multipart/form-data',
  1060. }
  1061. });
  1062. this.loading(false);
  1063. if (!uploadMsg.success) {
  1064. return;
  1065. }
  1066. this.loading(true);
  1067. const restartMsg = await HttpUtil.post("/panel/setting/restartPanel");
  1068. this.loading(false);
  1069. if (restartMsg.success) {
  1070. this.loading(true);
  1071. await PromiseUtil.sleep(5000);
  1072. location.reload();
  1073. }
  1074. }
  1075. });
  1076. fileInput.click();
  1077. },
  1078. startPolling() {
  1079. // Fallback polling mechanism
  1080. const pollInterval = setInterval(async () => {
  1081. if (window.wsClient && window.wsClient.isConnected) {
  1082. clearInterval(pollInterval);
  1083. return;
  1084. }
  1085. try {
  1086. await this.getStatus();
  1087. } catch (e) {
  1088. console.error(e);
  1089. }
  1090. }, 2000);
  1091. },
  1092. },
  1093. async mounted() {
  1094. if (window.location.protocol !== "https:") {
  1095. this.showAlert = true;
  1096. }
  1097. const msg = await HttpUtil.post('/panel/setting/defaultSettings');
  1098. if (msg.success) {
  1099. this.ipLimitEnable = msg.obj.ipLimitEnable;
  1100. }
  1101. // Initial status fetch
  1102. await this.getStatus();
  1103. // Setup WebSocket for real-time updates
  1104. if (window.wsClient) {
  1105. window.wsClient.connect();
  1106. // Listen for status updates
  1107. window.wsClient.on('status', (payload) => {
  1108. this.setStatus(payload);
  1109. });
  1110. // Listen for Xray state changes
  1111. window.wsClient.on('xray_state', (payload) => {
  1112. if (this.status && this.status.xray) {
  1113. this.status.xray.state = payload.state;
  1114. this.status.xray.errorMsg = payload.errorMsg || '';
  1115. switch (payload.state) {
  1116. case 'running':
  1117. this.status.xray.color = "green";
  1118. this.status.xray.stateMsg = '{{ i18n "pages.index.xrayStatusRunning" }}';
  1119. break;
  1120. case 'stop':
  1121. this.status.xray.color = "orange";
  1122. this.status.xray.stateMsg = '{{ i18n "pages.index.xrayStatusStop" }}';
  1123. break;
  1124. case 'error':
  1125. this.status.xray.color = "red";
  1126. this.status.xray.stateMsg = '{{ i18n "pages.index.xrayStatusError" }}';
  1127. break;
  1128. }
  1129. }
  1130. });
  1131. // Notifications disabled - white notifications are not needed
  1132. // Fallback to polling if WebSocket fails
  1133. window.wsClient.on('error', () => {
  1134. console.warn('WebSocket connection failed, falling back to polling');
  1135. this.startPolling();
  1136. });
  1137. window.wsClient.on('disconnected', () => {
  1138. if (window.wsClient.reconnectAttempts >= window.wsClient.maxReconnectAttempts) {
  1139. console.warn('WebSocket reconnection failed, falling back to polling');
  1140. this.startPolling();
  1141. }
  1142. });
  1143. } else {
  1144. // Fallback to polling if WebSocket is not available
  1145. this.startPolling();
  1146. }
  1147. },
  1148. });
  1149. </script>
  1150. {{ template "page/body_end" .}}