index.html 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. {{template "head" .}}
  4. <style>
  5. @media (min-width: 769px) {
  6. .ant-layout-content {
  7. margin: 24px 16px;
  8. }
  9. .ant-card-hoverable {
  10. margin-inline: 0.3rem;
  11. }
  12. .ant-alert-error {
  13. margin-inline: 0.3rem;
  14. }
  15. }
  16. .ant-col-sm-24 {
  17. margin-top: 10px;
  18. }
  19. .ant-card-dark h2 {
  20. color: var(--dark-color-text-primary);
  21. }
  22. .ant-backup-list-item {
  23. gap: 10px;
  24. }
  25. .ant-version-list-item {
  26. --padding: 12px;
  27. padding: var(--padding) !important;
  28. gap: var(--padding);
  29. }
  30. .dark .ant-version-list-item svg{
  31. color: var(--dark-color-text-primary);
  32. }
  33. .dark .ant-backup-list-item svg,
  34. .dark .ant-badge-status-text,
  35. .dark .ant-card-extra {
  36. color: var(--dark-color-text-primary);
  37. }
  38. .dark .ant-card-actions>li {
  39. color: rgba(255, 255, 255, 0.55);
  40. }
  41. .dark .ant-radio-inner {
  42. background-color: var(--dark-color-surface-100);
  43. border-color: var(--dark-color-surface-600);
  44. }
  45. .dark .ant-radio-checked .ant-radio-inner {
  46. border-color: var(--color-primary-100);
  47. }
  48. .dark .ant-backup-list,
  49. .dark .ant-version-list,
  50. .dark .ant-card-actions,
  51. .dark .ant-card-actions>li:not(:last-child) {
  52. border-color: var(--dark-color-stroke);
  53. }
  54. .ant-card-actions {
  55. background: transparent;
  56. }
  57. .ip-hidden {
  58. -webkit-user-select: none;
  59. -moz-user-select: none;
  60. user-select: none;
  61. filter: blur(10px);
  62. }
  63. .running-animation .ant-badge-status-dot {
  64. animation: runningAnimation 1.2s linear infinite;
  65. }
  66. .running-animation .ant-badge-status-processing:after {
  67. border-color: var(--color-primary-100);
  68. }
  69. @keyframes runningAnimation {
  70. 0%,
  71. 50%,
  72. 100% {
  73. transform: scale(1);
  74. opacity: 1;
  75. }
  76. 10% {
  77. transform: scale(1.5);
  78. opacity: .2;
  79. }
  80. }
  81. </style>
  82. <body>
  83. <a-layout id="app" v-cloak :class="themeSwitcher.currentTheme">
  84. <a-sidebar></a-sidebar>
  85. <a-layout id="content-layout">
  86. <a-layout-content>
  87. <a-spin :spinning="spinning" :delay="200" :tip="loadingTip">
  88. <transition name="list" appear>
  89. <a-alert type="error" v-if="showAlert" :style="{ marginBottom: '10px' }"
  90. message='{{ i18n "secAlertTitle" }}'
  91. color="red"
  92. description='{{ i18n "secAlertSsl" }}'
  93. show-icon closable>
  94. </a-alert>
  95. </transition>
  96. <transition name="list" appear>
  97. <template>
  98. <a-row v-if="!status.isLoaded">
  99. <a-card :style="{ textAlign: 'center', padding: '30px 0', marginTop: '10px', background: 'transparent', border: 'none' }">
  100. <a-spin tip='{{ i18n "loading" }}'></a-spin>
  101. </a-card>
  102. </a-row>
  103. <a-row v-else>
  104. <a-row>
  105. <a-card hoverable>
  106. <a-row>
  107. <a-col :sm="24" :md="12">
  108. <a-row>
  109. <a-col :span="12" :style="{ textAlign: 'center' }">
  110. <a-progress type="dashboard" status="normal"
  111. :stroke-color="status.cpu.color"
  112. :percent="status.cpu.percent"></a-progress>
  113. <div>
  114. <b>{{ i18n "pages.index.cpu" }}:</b> [[ CPUFormatter.cpuCoreFormat(status.cpuCores) ]]
  115. <a-tooltip>
  116. <a-icon type="area-chart"></a-icon>
  117. <template slot="title">
  118. <div><b>{{ i18n "pages.index.logicalProcessors" }}:</b> [[ (status.logicalPro) ]]</div>
  119. <div><b>{{ i18n "pages.index.frequency" }}:</b> [[ CPUFormatter.cpuSpeedFormat(status.cpuSpeedMhz) ]]</div>
  120. </template>
  121. </a-tooltip>
  122. </div>
  123. </a-col>
  124. <a-col :span="12" :style="{ textAlign: 'center' }">
  125. <a-progress type="dashboard" status="normal"
  126. :stroke-color="status.mem.color"
  127. :percent="status.mem.percent"></a-progress>
  128. <div>
  129. <b>{{ i18n "pages.index.memory"}}:</b> [[ SizeFormatter.sizeFormat(status.mem.current) ]] / [[ SizeFormatter.sizeFormat(status.mem.total) ]]
  130. </div>
  131. </a-col>
  132. </a-row>
  133. </a-col>
  134. <a-col :sm="24" :md="12">
  135. <a-row>
  136. <a-col :span="12" :style="{ textAlign: 'center' }">
  137. <a-progress type="dashboard" status="normal"
  138. :stroke-color="status.swap.color"
  139. :percent="status.swap.percent"></a-progress>
  140. <div>
  141. <b>{{ i18n "pages.index.swap" }}:</b> [[ SizeFormatter.sizeFormat(status.swap.current) ]] / [[ SizeFormatter.sizeFormat(status.swap.total) ]]
  142. </div>
  143. </a-col>
  144. <a-col :span="12" :style="{ textAlign: 'center' }">
  145. <a-progress type="dashboard" status="normal"
  146. :stroke-color="status.disk.color"
  147. :percent="status.disk.percent"></a-progress>
  148. <div>
  149. <b>{{ i18n "pages.index.storage"}}:</b> [[ SizeFormatter.sizeFormat(status.disk.current) ]] / [[ SizeFormatter.sizeFormat(status.disk.total) ]]
  150. </div>
  151. </a-col>
  152. </a-row>
  153. </a-col>
  154. </a-row>
  155. </a-card>
  156. </a-row>
  157. <a-col :sm="24" :lg="12">
  158. <a-card hoverable>
  159. <template #title>
  160. <a-space direction="horizontal">
  161. <span>{{ i18n "pages.index.xrayStatus" }}</span>
  162. <a-tag v-if="isMobile && status.xray.version != 'Unknown'" color="green">
  163. v[[ status.xray.version ]]
  164. </a-tag>
  165. </a-space>
  166. </template>
  167. <template #extra>
  168. <template v-if="status.xray.state != 'error'">
  169. <a-badge status="processing" class="running-animation" :text="status.xray.stateMsg" :color="status.xray.color"/>
  170. </template>
  171. <template v-else>
  172. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  173. <span slot="title">
  174. <a-row type="flex" align="middle" justify="space-between">
  175. <a-col>
  176. <span>{{ i18n "pages.index.xrayErrorPopoverTitle" }}</span>
  177. </a-col>
  178. <a-col>
  179. <a-icon type="bars" :style="{ cursor: 'pointer', float: 'right' }" @click="openLogs()"></a-tag>
  180. </a-col>
  181. </a-row>
  182. </span>
  183. <template slot="content">
  184. <span :style="{ maxWidth: '400px' }" v-for="line in status.xray.errorMsg.split('\n')">[[ line ]]</span>
  185. </template>
  186. <a-badge :text="status.xray.stateMsg" :color="status.xray.color"/>
  187. </a-popover>
  188. </template>
  189. </template>
  190. <template #actions>
  191. <a-space direction="horizontal" @click="stopXrayService" :style="{ justifyContent: 'center' }">
  192. <a-icon type="poweroff"></a-icon>
  193. <span v-if="!isMobile">{{ i18n "pages.index.stopXray" }}</span>
  194. </a-space>
  195. <a-space direction="horizontal" @click="restartXrayService" :style="{ justifyContent: 'center' }">
  196. <a-icon type="reload"></a-icon>
  197. <span v-if="!isMobile">{{ i18n "pages.index.restartXray" }}</span>
  198. </a-space>
  199. <a-space direction="horizontal" @click="openSelectV2rayVersion" :style="{ justifyContent: 'center' }">
  200. <a-icon type="tool"></a-icon>
  201. <span v-if="!isMobile">
  202. [[ status.xray.version != 'Unknown' ? `v${status.xray.version}` : '{{ i18n "pages.index.xraySwitch" }}' ]]
  203. </span>
  204. </a-space>
  205. </template>
  206. </a-card>
  207. </a-col>
  208. <a-col :sm="24" :lg="12">
  209. <a-card title='{{ i18n "menu.link" }}' hoverable>
  210. <template #actions>
  211. <a-space direction="horizontal" @click="openLogs()" :style="{ justifyContent: 'center' }">
  212. <a-icon type="bars"></a-icon>
  213. <span v-if="!isMobile">{{ i18n "pages.index.logs" }}</span>
  214. </a-space>
  215. <a-space direction="horizontal" @click="openConfig" :style="{ justifyContent: 'center' }">
  216. <a-icon type="control"></a-icon>
  217. <span v-if="!isMobile">{{ i18n "pages.index.config" }}</span>
  218. </a-space>
  219. <a-space direction="horizontal" @click="openBackup" :style="{ justifyContent: 'center' }">
  220. <a-icon type="cloud-server"></a-icon>
  221. <span v-if="!isMobile">{{ i18n "pages.index.backup" }}</span>
  222. </a-space>
  223. </template>
  224. </a-card>
  225. </a-col>
  226. <a-col :sm="24" :lg="12">
  227. <a-card title='3X-UI' hoverable>
  228. <a rel="noopener" href="https://github.com/MHSanaei/3x-ui/releases" target="_blank">
  229. <a-tag color="green">
  230. <span>v{{ .cur_ver }}</span>
  231. </a-tag>
  232. </a>
  233. <a rel="noopener" href="https://t.me/XrayUI" target="_blank">
  234. <a-tag color="green">
  235. <span>@XrayUI</span>
  236. </a-tag>
  237. </a>
  238. <a rel="noopener" href="https://github.com/MHSanaei/3x-ui/wiki" target="_blank">
  239. <a-tag>
  240. <span>{{ i18n "pages.index.documentation" }}</span>
  241. </a-tag>
  242. </a>
  243. </a-card>
  244. </a-col>
  245. <a-col :sm="24" :lg="12">
  246. <a-card title='{{ i18n "pages.index.operationHours" }}' hoverable>
  247. <a-tag :color="status.xray.color">Xray: [[ TimeFormatter.formatSecond(status.appStats.uptime) ]]</a-tag>
  248. <a-tag color="green">OS: [[ TimeFormatter.formatSecond(status.uptime) ]]</a-tag>
  249. </a-card>
  250. </a-col>
  251. <a-col :sm="24" :lg="12">
  252. <a-card title='{{ i18n "pages.index.systemLoad" }}' hoverable>
  253. <a-tag color="green">
  254. <a-tooltip>
  255. [[ status.loads[0] ]] | [[ status.loads[1] ]] | [[ status.loads[2] ]]
  256. <template slot="title">
  257. {{ i18n "pages.index.systemLoadDesc" }}
  258. </template>
  259. </a-tooltip>
  260. </a-tag>
  261. </a-card>
  262. </a-col>
  263. <a-col :sm="24" :lg="12">
  264. <a-card title='{{ i18n "usage"}}' hoverable>
  265. <a-tag color="green"> {{ i18n "pages.index.memory" }}: [[ SizeFormatter.sizeFormat(status.appStats.mem) ]] </a-tag>
  266. <a-tag color="green"> {{ i18n "pages.index.threads" }}: [[ status.appStats.threads ]] </a-tag>
  267. </a-card>
  268. </a-col>
  269. <a-col :sm="24" :lg="12">
  270. <a-card title='{{ i18n "pages.index.overallSpeed" }}' hoverable>
  271. <a-row :gutter="isMobile ? [8,8] : 0">
  272. <a-col :span="12">
  273. <a-custom-statistic title='{{ i18n "pages.index.upload" }}' :value="SizeFormatter.sizeFormat(status.netIO.up)">
  274. <template #prefix>
  275. <a-icon type="arrow-up" />
  276. </template>
  277. <template #suffix>
  278. /s
  279. </template>
  280. </a-custom-statistic>
  281. </a-col>
  282. <a-col :span="12">
  283. <a-custom-statistic title='{{ i18n "pages.index.download" }}' :value="SizeFormatter.sizeFormat(status.netIO.down)">
  284. <template #prefix>
  285. <a-icon type="arrow-down" />
  286. </template>
  287. <template #suffix>
  288. /s
  289. </template>
  290. </a-custom-statistic>
  291. </a-col>
  292. </a-row>
  293. </a-card>
  294. </a-col>
  295. <a-col :sm="24" :lg="12">
  296. <a-card title='{{ i18n "pages.index.totalData" }}' hoverable>
  297. <a-row :gutter="isMobile ? [8,8] : 0">
  298. <a-col :span="12">
  299. <a-custom-statistic title='{{ i18n "pages.index.sent" }}' :value="SizeFormatter.sizeFormat(status.netTraffic.sent)">
  300. <template #prefix>
  301. <a-icon type="cloud-upload" />
  302. </template>
  303. </a-custom-statistic>
  304. </a-col>
  305. <a-col :span="12">
  306. <a-custom-statistic title='{{ i18n "pages.index.received" }}' :value="SizeFormatter.sizeFormat(status.netTraffic.recv)">
  307. <template #prefix>
  308. <a-icon type="cloud-download" />
  309. </template>
  310. </a-custom-statistic>
  311. </a-col>
  312. </a-row>
  313. </a-card>
  314. </a-col>
  315. <a-col :sm="24" :lg="12">
  316. <a-card title='{{ i18n "pages.index.ipAddresses" }}' hoverable>
  317. <template #extra>
  318. <a-tooltip :placement="isMobile ? 'topRight' : 'top'">
  319. <template #title>
  320. {{ i18n "pages.index.toggleIpVisibility" }}
  321. </template>
  322. <a-icon :type="showIp ? 'eye' : 'eye-invisible'" :style="{ fontSize: '1rem' }" @click="showIp = !showIp"></a-icon>
  323. </a-tooltip>
  324. </template>
  325. <a-row :class="showIp ? 'ip-visible' : 'ip-hidden'" :gutter="isMobile ? [8,8] : 0">
  326. <a-col :span="isMobile ? 24 : 12">
  327. <a-custom-statistic title="IPv4" :value="status.publicIP.ipv4">
  328. <template #prefix>
  329. <a-icon type="global" />
  330. </template>
  331. </a-custom-statistic>
  332. </a-col>
  333. <a-col :span="isMobile ? 24 : 12">
  334. <a-custom-statistic title="IPv6" :value="status.publicIP.ipv6">
  335. <template #prefix>
  336. <a-icon type="global" />
  337. </template>
  338. </a-custom-statistic>
  339. </a-col>
  340. </a-row>
  341. </a-card>
  342. </a-col>
  343. <a-col :sm="24" :lg="12">
  344. <a-card title='{{ i18n "pages.index.connectionCount" }}' hoverable>
  345. <a-row :gutter="isMobile ? [8,8] : 0">
  346. <a-col :span="12">
  347. <a-custom-statistic title="TCP" :value="status.tcpCount">
  348. <template #prefix>
  349. <a-icon type="swap" />
  350. </template>
  351. </a-custom-statistic>
  352. </a-col>
  353. <a-col :span="12">
  354. <a-custom-statistic title="UDP" :value="status.udpCount">
  355. <template #prefix>
  356. <a-icon type="swap" />
  357. </template>
  358. </a-custom-statistic>
  359. </a-col>
  360. </a-row>
  361. </a-card>
  362. </a-col>
  363. </a-row>
  364. </template>
  365. </transition>
  366. </a-spin>
  367. </a-layout-content>
  368. </a-layout>
  369. <a-modal id="version-modal" v-model="versionModal.visible" title='{{ i18n "pages.index.xraySwitch" }}' :closable="true"
  370. @ok="() => versionModal.visible = false" :class="themeSwitcher.currentTheme" footer="">
  371. <a-collapse default-active-key="1">
  372. <a-collapse-panel key="1" header='Xray'>
  373. <a-alert type="warning" :style="{ marginBottom: '12px', width: '100%' }" message='{{ i18n "pages.index.xraySwitchClickDesk" }}' show-icon></a-alert>
  374. <a-list class="ant-version-list" bordered :style="{ width: '100%' }">
  375. <a-list-item class="ant-version-list-item" v-for="version, index in versionModal.versions">
  376. <a-tag :color="index % 2 == 0 ? 'purple' : 'green'">[[ version ]]</a-tag>
  377. <a-radio :class="themeSwitcher.currentTheme" :checked="version === `v${status.xray.version}`" @click="switchV2rayVersion(version)"></a-radio>
  378. </a-list-item>
  379. </a-list>
  380. </a-collapse-panel>
  381. <a-collapse-panel key="2" header='Geofiles'>
  382. <a-list class="ant-version-list" bordered :style="{ width: '100%' }">
  383. <a-list-item class="ant-version-list-item" v-for="file, index in ['geosite.dat', 'geoip.dat', 'geosite_IR.dat', 'geoip_IR.dat', 'geosite_RU.dat', 'geoip_RU.dat']">
  384. <a-tag :color="index % 2 == 0 ? 'purple' : 'green'">[[ file ]]</a-tag>
  385. <a-icon type="reload" @click="updateGeofile(file)" :style="{ marginRight: '8px' }"/>
  386. </a-list-item>
  387. </a-list>
  388. </a-collapse-panel>
  389. </a-collapse>
  390. </a-modal>
  391. <a-modal id="log-modal" v-model="logModal.visible"
  392. :closable="true" @cancel="() => logModal.visible = false"
  393. :class="themeSwitcher.currentTheme"
  394. width="800px" footer="">
  395. <template slot="title">
  396. {{ i18n "pages.index.logs" }}
  397. <a-icon :spin="logModal.loading"
  398. type="sync"
  399. :style="{ verticalAlign: 'middle', marginLeft: '10px' }"
  400. :disabled="logModal.loading"
  401. @click="openLogs()">
  402. </a-icon>
  403. </template>
  404. <a-form layout="inline">
  405. <a-form-item :style="{ marginRight: '0.5rem' }">
  406. <a-input-group compact>
  407. <a-select size="small" v-model="logModal.rows" :style="{ width: '70px' }"
  408. @change="openLogs()" :dropdown-class-name="themeSwitcher.currentTheme">
  409. <a-select-option value="10">10</a-select-option>
  410. <a-select-option value="20">20</a-select-option>
  411. <a-select-option value="50">50</a-select-option>
  412. <a-select-option value="100">100</a-select-option>
  413. <a-select-option value="500">500</a-select-option>
  414. </a-select>
  415. <a-select size="small" v-model="logModal.level" :style="{ width: '95px' }"
  416. @change="openLogs()" :dropdown-class-name="themeSwitcher.currentTheme">
  417. <a-select-option value="debug">Debug</a-select-option>
  418. <a-select-option value="info">Info</a-select-option>
  419. <a-select-option value="notice">Notice</a-select-option>
  420. <a-select-option value="warning">Warning</a-select-option>
  421. <a-select-option value="err">Error</a-select-option>
  422. </a-select>
  423. </a-input-group>
  424. </a-form-item>
  425. <a-form-item>
  426. <a-checkbox v-model="logModal.syslog" @change="openLogs()">SysLog</a-checkbox>
  427. </a-form-item>
  428. <a-form-item :style="{ float: 'right' }">
  429. <a-button type="primary" icon="download" @click="FileManager.downloadTextFile(logModal.logs?.join('\n'), 'x-ui.log')"></a-button>
  430. </a-form-item>
  431. </a-form>
  432. <div class="ant-input" :style="{ height: 'auto', maxHeight: '500px', overflow: 'auto', marginTop: '0.5rem' }" v-html="logModal.formattedLogs"></div>
  433. </a-modal>
  434. <a-modal id="backup-modal"
  435. v-model="backupModal.visible"
  436. title='{{ i18n "pages.index.backupTitle" }}'
  437. :closable="true"
  438. footer=""
  439. :class="themeSwitcher.currentTheme">
  440. <a-list class="ant-backup-list" bordered :style="{ width: '100%' }">
  441. <a-list-item class="ant-backup-list-item">
  442. <a-list-item-meta>
  443. <template #title>{{ i18n "pages.index.exportDatabase" }}</template>
  444. <template #description>{{ i18n "pages.index.exportDatabaseDesc" }}</template>
  445. </a-list-item-meta>
  446. <a-button @click="exportDatabase()" type="primary" icon="download"/>
  447. </a-list-item>
  448. <a-list-item class="ant-backup-list-item">
  449. <a-list-item-meta>
  450. <template #title>{{ i18n "pages.index.importDatabase" }}</template>
  451. <template #description>{{ i18n "pages.index.importDatabaseDesc" }}</template>
  452. </a-list-item-meta>
  453. <a-button @click="importDatabase()" type="primary" icon="upload" />
  454. </a-list-item>
  455. </a-list>
  456. </a-modal>
  457. </a-layout>
  458. {{template "js" .}}
  459. {{template "component/aSidebar" .}}
  460. {{template "component/aThemeSwitch" .}}
  461. {{template "component/aCustomStatistic" .}}
  462. {{template "modals/textModal"}}
  463. <script>
  464. class CurTotal {
  465. constructor(current, total) {
  466. this.current = current;
  467. this.total = total;
  468. }
  469. get percent() {
  470. if (this.total === 0) {
  471. return 0;
  472. }
  473. return NumberFormatter.toFixed(this.current / this.total * 100, 2);
  474. }
  475. get color() {
  476. const percent = this.percent;
  477. if (percent < 80) {
  478. return '#008771'; // Green
  479. } else if (percent < 90) {
  480. return "#f37b24"; // Orange
  481. } else {
  482. return "#cf3c3c"; // Red
  483. }
  484. }
  485. }
  486. class Status {
  487. constructor(data, isLoaded = false) {
  488. this.cpu = new CurTotal(0, 0);
  489. this.cpuCores = 0;
  490. this.logicalPro = 0;
  491. this.cpuSpeedMhz = 0;
  492. this.disk = new CurTotal(0, 0);
  493. this.loads = [0, 0, 0];
  494. this.mem = new CurTotal(0, 0);
  495. this.netIO = { up: 0, down: 0 };
  496. this.netTraffic = { sent: 0, recv: 0 };
  497. this.publicIP = { ipv4: 0, ipv6: 0 };
  498. this.swap = new CurTotal(0, 0);
  499. this.tcpCount = 0;
  500. this.udpCount = 0;
  501. this.uptime = 0;
  502. this.appUptime = 0;
  503. this.appStats = {threads: 0, mem: 0, uptime: 0};
  504. this.xray = { state: 'stop', stateMsg: "", errorMsg: "", version: "", color: "" };
  505. if (data == null) {
  506. return;
  507. }
  508. this.isLoaded = isLoaded;
  509. this.cpu = new CurTotal(data.cpu, 100);
  510. this.cpuCores = data.cpuCores;
  511. this.logicalPro = data.logicalPro;
  512. this.cpuSpeedMhz = data.cpuSpeedMhz;
  513. this.disk = new CurTotal(data.disk.current, data.disk.total);
  514. this.loads = data.loads.map(load => NumberFormatter.toFixed(load, 2));
  515. this.mem = new CurTotal(data.mem.current, data.mem.total);
  516. this.netIO = data.netIO;
  517. this.netTraffic = data.netTraffic;
  518. this.publicIP = data.publicIP;
  519. this.swap = new CurTotal(data.swap.current, data.swap.total);
  520. this.tcpCount = data.tcpCount;
  521. this.udpCount = data.udpCount;
  522. this.uptime = data.uptime;
  523. this.appUptime = data.appUptime;
  524. this.appStats = data.appStats;
  525. this.xray = data.xray;
  526. switch (this.xray.state) {
  527. case 'running':
  528. this.xray.color = "green";
  529. this.xray.stateMsg = '{{ i18n "pages.index.xrayStatusRunning" }}';
  530. break;
  531. case 'stop':
  532. this.xray.color = "orange";
  533. this.xray.stateMsg = '{{ i18n "pages.index.xrayStatusStop" }}';
  534. break;
  535. case 'error':
  536. this.xray.color = "red";
  537. this.xray.stateMsg ='{{ i18n "pages.index.xrayStatusError" }}';
  538. break;
  539. default:
  540. this.xray.color = "gray";
  541. this.xray.stateMsg = '{{ i18n "pages.index.xrayStatusUnknown" }}';
  542. break;
  543. }
  544. }
  545. }
  546. const versionModal = {
  547. visible: false,
  548. versions: [],
  549. show(versions) {
  550. this.visible = true;
  551. this.versions = versions;
  552. },
  553. hide() {
  554. this.visible = false;
  555. },
  556. };
  557. const logModal = {
  558. visible: false,
  559. logs: [],
  560. rows: 20,
  561. level: 'info',
  562. syslog: false,
  563. loading: false,
  564. show(logs) {
  565. this.visible = true;
  566. this.logs = logs;
  567. this.formattedLogs = this.logs?.length > 0 ? this.formatLogs(this.logs) : "No Record...";
  568. },
  569. formatLogs(logs) {
  570. let formattedLogs = '';
  571. const levels = ["DEBUG","INFO","NOTICE","WARNING","ERROR"];
  572. const levelColors = ["#3c89e8","#008771","#008771","#f37b24","#e04141","#bcbcbc"];
  573. logs.forEach((log, index) => {
  574. let [data, message] = log.split(" - ",2);
  575. const parts = data.split(" ")
  576. if(index>0) formattedLogs += '<br>';
  577. if (parts.length === 3) {
  578. const d = parts[0];
  579. const t = parts[1];
  580. const level = parts[2];
  581. const levelIndex = levels.indexOf(level,levels) || 5;
  582. //formattedLogs += `<span style="color: gray;">${index + 1}.</span>`;
  583. formattedLogs += `<span style="color: ${levelColors[0]};">${d} ${t}</span> `;
  584. formattedLogs += `<span style="color: ${levelColors[levelIndex]}">${level}</span>`;
  585. } else {
  586. const levelIndex = levels.indexOf(data,levels) || 5;
  587. formattedLogs += `<span style="color: ${levelColors[levelIndex]}">${data}</span>`;
  588. }
  589. if(message){
  590. if(message.startsWith("XRAY:"))
  591. message = "<b>XRAY: </b>" + message.substring(5);
  592. else
  593. message = "<b>X-UI: </b>" + message;
  594. }
  595. formattedLogs += message ? ' - ' + message : '';
  596. });
  597. return formattedLogs;
  598. },
  599. hide() {
  600. this.visible = false;
  601. },
  602. };
  603. const backupModal = {
  604. visible: false,
  605. show() {
  606. this.visible = true;
  607. },
  608. hide() {
  609. this.visible = false;
  610. },
  611. };
  612. const app = new Vue({
  613. delimiters: ['[[', ']]'],
  614. el: '#app',
  615. mixins: [MediaQueryMixin],
  616. data: {
  617. themeSwitcher,
  618. status: new Status(),
  619. versionModal,
  620. logModal,
  621. backupModal,
  622. spinning: false,
  623. loadingTip: '{{ i18n "loading"}}',
  624. showAlert: false,
  625. showIp: false
  626. },
  627. methods: {
  628. loading(spinning, tip = '{{ i18n "loading"}}') {
  629. this.spinning = spinning;
  630. this.loadingTip = tip;
  631. },
  632. async getStatus() {
  633. try {
  634. const msg = await HttpUtil.post('/server/status');
  635. if (msg.success) {
  636. this.setStatus(msg.obj, true);
  637. }
  638. } catch (e) {
  639. console.error("Failed to get status:", e);
  640. }
  641. },
  642. setStatus(data, isLoaded = false) {
  643. this.status = new Status(data, isLoaded);
  644. },
  645. async openSelectV2rayVersion() {
  646. this.loading(true);
  647. const msg = await HttpUtil.post('server/getXrayVersion');
  648. this.loading(false);
  649. if (!msg.success) {
  650. return;
  651. }
  652. versionModal.show(msg.obj);
  653. },
  654. switchV2rayVersion(version) {
  655. this.$confirm({
  656. title: '{{ i18n "pages.index.xraySwitchVersionDialog"}}',
  657. content: '{{ i18n "pages.index.xraySwitchVersionDialogDesc"}}'.replace('#version#', version),
  658. okText: '{{ i18n "confirm"}}',
  659. class: themeSwitcher.currentTheme,
  660. cancelText: '{{ i18n "cancel"}}',
  661. onOk: async () => {
  662. versionModal.hide();
  663. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  664. await HttpUtil.post(`/server/installXray/${version}`);
  665. this.loading(false);
  666. },
  667. });
  668. },
  669. updateGeofile(fileName) {
  670. this.$confirm({
  671. title: '{{ i18n "pages.index.geofileUpdateDialog" }}',
  672. content: '{{ i18n "pages.index.geofileUpdateDialogDesc" }}'.replace("#filename#", fileName),
  673. okText: '{{ i18n "confirm"}}',
  674. class: themeSwitcher.currentTheme,
  675. cancelText: '{{ i18n "cancel"}}',
  676. onOk: async () => {
  677. versionModal.hide();
  678. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  679. await HttpUtil.post(`/server/updateGeofile/${fileName}`);
  680. this.loading(false);
  681. },
  682. });
  683. },
  684. async stopXrayService() {
  685. this.loading(true);
  686. const msg = await HttpUtil.post('server/stopXrayService');
  687. this.loading(false);
  688. if (!msg.success) {
  689. return;
  690. }
  691. },
  692. async restartXrayService() {
  693. this.loading(true);
  694. const msg = await HttpUtil.post('server/restartXrayService');
  695. this.loading(false);
  696. if (!msg.success) {
  697. return;
  698. }
  699. },
  700. async openLogs(){
  701. logModal.loading = true;
  702. const msg = await HttpUtil.post('server/logs/'+logModal.rows,{level: logModal.level, syslog: logModal.syslog});
  703. if (!msg.success) {
  704. return;
  705. }
  706. logModal.show(msg.obj);
  707. await PromiseUtil.sleep(500);
  708. logModal.loading = false;
  709. },
  710. async openConfig() {
  711. this.loading(true);
  712. const msg = await HttpUtil.post('server/getConfigJson');
  713. this.loading(false);
  714. if (!msg.success) {
  715. return;
  716. }
  717. txtModal.show('config.json', JSON.stringify(msg.obj, null, 2), 'config.json');
  718. },
  719. openBackup() {
  720. backupModal.show();
  721. },
  722. exportDatabase() {
  723. window.location = basePath + 'server/getDb';
  724. },
  725. importDatabase() {
  726. const fileInput = document.createElement('input');
  727. fileInput.type = 'file';
  728. fileInput.accept = '.db';
  729. fileInput.addEventListener('change', async (event) => {
  730. const dbFile = event.target.files[0];
  731. if (dbFile) {
  732. const formData = new FormData();
  733. formData.append('db', dbFile);
  734. backupModal.hide();
  735. this.loading(true);
  736. const uploadMsg = await HttpUtil.post('server/importDB', formData, {
  737. headers: {
  738. 'Content-Type': 'multipart/form-data',
  739. }
  740. });
  741. this.loading(false);
  742. if (!uploadMsg.success) {
  743. return;
  744. }
  745. this.loading(true);
  746. const restartMsg = await HttpUtil.post("/panel/setting/restartPanel");
  747. this.loading(false);
  748. if (restartMsg.success) {
  749. this.loading(true);
  750. await PromiseUtil.sleep(5000);
  751. location.reload();
  752. }
  753. }
  754. });
  755. fileInput.click();
  756. },
  757. },
  758. async mounted() {
  759. if (window.location.protocol !== "https:") {
  760. this.showAlert = true;
  761. }
  762. while (true) {
  763. try {
  764. await this.getStatus();
  765. } catch (e) {
  766. console.error(e);
  767. }
  768. await PromiseUtil.sleep(2000);
  769. }
  770. },
  771. });
  772. </script>
  773. </body>
  774. </html>