1
0

index.html 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  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 hoverable :style="{ textAlign: 'center', padding: '30px 0', marginTop: '10px', background: 'transparent' }">
  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"><a-tag color="green">v{{ .cur_ver }}</a-tag></a>
  229. <a rel="noopener" href="https://t.me/XrayUI" target="_blank"><a-tag color="green">@XrayUI</a-tag></a>
  230. </a-card>
  231. </a-col>
  232. <a-col :sm="24" :lg="12">
  233. <a-card title='{{ i18n "pages.index.operationHours" }}' hoverable>
  234. <a-tag :color="status.xray.color">Xray: [[ TimeFormatter.formatSecond(status.appStats.uptime) ]]</a-tag>
  235. <a-tag color="green">OS: [[ TimeFormatter.formatSecond(status.uptime) ]]</a-tag>
  236. </a-card>
  237. </a-col>
  238. <a-col :sm="24" :lg="12">
  239. <a-card title='{{ i18n "pages.index.systemLoad" }}' hoverable>
  240. <a-tag color="green">
  241. <a-tooltip>
  242. [[ status.loads[0] ]] | [[ status.loads[1] ]] | [[ status.loads[2] ]]
  243. <template slot="title">
  244. {{ i18n "pages.index.systemLoadDesc" }}
  245. </template>
  246. </a-tooltip>
  247. </a-tag>
  248. </a-card>
  249. </a-col>
  250. <a-col :sm="24" :lg="12">
  251. <a-card title='{{ i18n "usage"}}' hoverable>
  252. <a-tag color="green"> {{ i18n "pages.index.memory" }}: [[ SizeFormatter.sizeFormat(status.appStats.mem) ]] </a-tag>
  253. <a-tag color="green"> {{ i18n "pages.index.threads" }}: [[ status.appStats.threads ]] </a-tag>
  254. </a-card>
  255. </a-col>
  256. <a-col :sm="24" :lg="12">
  257. <a-card title='{{ i18n "pages.index.overallSpeed" }}' hoverable>
  258. <a-row :gutter="isMobile ? [8,8] : 0">
  259. <a-col :span="12">
  260. <a-custom-statistic title='{{ i18n "pages.index.upload" }}' :value="SizeFormatter.sizeFormat(status.netIO.up)">
  261. <template #prefix>
  262. <a-icon type="arrow-up" />
  263. </template>
  264. <template #suffix>
  265. /s
  266. </template>
  267. </a-custom-statistic>
  268. </a-col>
  269. <a-col :span="12">
  270. <a-custom-statistic title='{{ i18n "pages.index.download" }}' :value="SizeFormatter.sizeFormat(status.netIO.down)">
  271. <template #prefix>
  272. <a-icon type="arrow-down" />
  273. </template>
  274. <template #suffix>
  275. /s
  276. </template>
  277. </a-custom-statistic>
  278. </a-col>
  279. </a-row>
  280. </a-card>
  281. </a-col>
  282. <a-col :sm="24" :lg="12">
  283. <a-card title='{{ i18n "pages.index.totalData" }}' hoverable>
  284. <a-row :gutter="isMobile ? [8,8] : 0">
  285. <a-col :span="12">
  286. <a-custom-statistic title='{{ i18n "pages.index.sent" }}' :value="SizeFormatter.sizeFormat(status.netTraffic.sent)">
  287. <template #prefix>
  288. <a-icon type="cloud-upload" />
  289. </template>
  290. </a-custom-statistic>
  291. </a-col>
  292. <a-col :span="12">
  293. <a-custom-statistic title='{{ i18n "pages.index.received" }}' :value="SizeFormatter.sizeFormat(status.netTraffic.recv)">
  294. <template #prefix>
  295. <a-icon type="cloud-download" />
  296. </template>
  297. </a-custom-statistic>
  298. </a-col>
  299. </a-row>
  300. </a-card>
  301. </a-col>
  302. <a-col :sm="24" :lg="12">
  303. <a-card title='{{ i18n "pages.index.ipAddresses" }}' hoverable>
  304. <template #extra>
  305. <a-tooltip>
  306. <template #title>
  307. {{ i18n "pages.index.toggleIpVisibility" }}
  308. </template>
  309. <a-icon :type="showIp ? 'eye' : 'eye-invisible'" :style="{ fontSize: '1rem' }" @click="showIp = !showIp"></a-icon>
  310. </a-tooltip>
  311. </template>
  312. <a-row :class="showIp ? 'ip-visible' : 'ip-hidden'" :gutter="isMobile ? [8,8] : 0">
  313. <a-col :span="isMobile ? 24 : 12">
  314. <a-custom-statistic title="IPv4" :value="status.publicIP.ipv4">
  315. <template #prefix>
  316. <a-icon type="global" />
  317. </template>
  318. </a-custom-statistic>
  319. </a-col>
  320. <a-col :span="isMobile ? 24 : 12">
  321. <a-custom-statistic title="IPv6" :value="status.publicIP.ipv6">
  322. <template #prefix>
  323. <a-icon type="global" />
  324. </template>
  325. </a-custom-statistic>
  326. </a-col>
  327. </a-row>
  328. </a-card>
  329. </a-col>
  330. <a-col :sm="24" :lg="12">
  331. <a-card title='{{ i18n "pages.index.connectionCount" }}' hoverable>
  332. <a-row :gutter="isMobile ? [8,8] : 0">
  333. <a-col :span="12">
  334. <a-custom-statistic title="TCP" :value="status.tcpCount">
  335. <template #prefix>
  336. <a-icon type="swap" />
  337. </template>
  338. </a-custom-statistic>
  339. </a-col>
  340. <a-col :span="12">
  341. <a-custom-statistic title="UDP" :value="status.udpCount">
  342. <template #prefix>
  343. <a-icon type="swap" />
  344. </template>
  345. </a-custom-statistic>
  346. </a-col>
  347. </a-row>
  348. </a-card>
  349. </a-col>
  350. </a-row>
  351. </template>
  352. </transition>
  353. </a-spin>
  354. </a-layout-content>
  355. </a-layout>
  356. <a-modal id="version-modal" v-model="versionModal.visible" title='{{ i18n "pages.index.xraySwitch" }}' :closable="true"
  357. @ok="() => versionModal.visible = false" :class="themeSwitcher.currentTheme" footer="">
  358. <a-collapse default-active-key="1">
  359. <a-collapse-panel key="1" header='Xray'>
  360. <a-alert type="warning" :style="{ marginBottom: '12px', width: '100%' }" message='{{ i18n "pages.index.xraySwitchClickDesk" }}' show-icon></a-alert>
  361. <a-list class="ant-version-list" bordered :style="{ width: '100%' }">
  362. <a-list-item class="ant-version-list-item" v-for="version, index in versionModal.versions">
  363. <a-tag :color="index % 2 == 0 ? 'purple' : 'green'">[[ version ]]</a-tag>
  364. <a-radio :class="themeSwitcher.currentTheme" :checked="version === `v${status.xray.version}`" @click="switchV2rayVersion(version)"></a-radio>
  365. </a-list-item>
  366. </a-list>
  367. </a-collapse-panel>
  368. <a-collapse-panel key="2" header='Geofiles'>
  369. <a-list class="ant-version-list" bordered :style="{ width: '100%' }">
  370. <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']">
  371. <a-tag :color="index % 2 == 0 ? 'purple' : 'green'">[[ file ]]</a-tag>
  372. <a-icon type="reload" @click="updateGeofile(file)" :style="{ marginRight: '8px' }"/>
  373. </a-list-item>
  374. </a-list>
  375. </a-collapse-panel>
  376. </a-collapse>
  377. </a-modal>
  378. <a-modal id="log-modal" v-model="logModal.visible"
  379. :closable="true" @cancel="() => logModal.visible = false"
  380. :class="themeSwitcher.currentTheme"
  381. width="800px" footer="">
  382. <template slot="title">
  383. {{ i18n "pages.index.logs" }}
  384. <a-icon :spin="logModal.loading"
  385. type="sync"
  386. :style="{ verticalAlign: 'middle', marginLeft: '10px' }"
  387. :disabled="logModal.loading"
  388. @click="openLogs()">
  389. </a-icon>
  390. </template>
  391. <a-form layout="inline">
  392. <a-form-item :style="{ marginRight: '0.5rem' }">
  393. <a-input-group compact>
  394. <a-select size="small" v-model="logModal.rows" :style="{ width: '70px' }"
  395. @change="openLogs()" :dropdown-class-name="themeSwitcher.currentTheme">
  396. <a-select-option value="10">10</a-select-option>
  397. <a-select-option value="20">20</a-select-option>
  398. <a-select-option value="50">50</a-select-option>
  399. <a-select-option value="100">100</a-select-option>
  400. <a-select-option value="500">500</a-select-option>
  401. </a-select>
  402. <a-select size="small" v-model="logModal.level" :style="{ width: '95px' }"
  403. @change="openLogs()" :dropdown-class-name="themeSwitcher.currentTheme">
  404. <a-select-option value="debug">Debug</a-select-option>
  405. <a-select-option value="info">Info</a-select-option>
  406. <a-select-option value="notice">Notice</a-select-option>
  407. <a-select-option value="warning">Warning</a-select-option>
  408. <a-select-option value="err">Error</a-select-option>
  409. </a-select>
  410. </a-input-group>
  411. </a-form-item>
  412. <a-form-item>
  413. <a-checkbox v-model="logModal.syslog" @change="openLogs()">SysLog</a-checkbox>
  414. </a-form-item>
  415. <a-form-item :style="{ float: 'right' }">
  416. <a-button type="primary" icon="download" @click="FileManager.downloadTextFile(logModal.logs?.join('\n'), 'x-ui.log')"></a-button>
  417. </a-form-item>
  418. </a-form>
  419. <div class="ant-input" :style="{ height: 'auto', maxHeight: '500px', overflow: 'auto', marginTop: '0.5rem' }" v-html="logModal.formattedLogs"></div>
  420. </a-modal>
  421. <a-modal id="backup-modal"
  422. v-model="backupModal.visible"
  423. title='{{ i18n "pages.index.backupTitle" }}'
  424. :closable="true"
  425. footer=""
  426. :class="themeSwitcher.currentTheme">
  427. <a-list class="ant-backup-list" bordered :style="{ width: '100%' }">
  428. <a-list-item class="ant-backup-list-item">
  429. <a-list-item-meta>
  430. <template #title>{{ i18n "pages.index.exportDatabase" }}</template>
  431. <template #description>{{ i18n "pages.index.exportDatabaseDesc" }}</template>
  432. </a-list-item-meta>
  433. <a-button @click="exportDatabase()" type="primary" icon="download"/>
  434. </a-list-item>
  435. <a-list-item class="ant-backup-list-item">
  436. <a-list-item-meta>
  437. <template #title>{{ i18n "pages.index.importDatabase" }}</template>
  438. <template #description>{{ i18n "pages.index.importDatabaseDesc" }}</template>
  439. </a-list-item-meta>
  440. <a-button @click="importDatabase()" type="primary" icon="upload" />
  441. </a-list-item>
  442. </a-list>
  443. </a-modal>
  444. </a-layout>
  445. {{template "js" .}}
  446. {{template "component/aSidebar" .}}
  447. {{template "component/aThemeSwitch" .}}
  448. {{template "component/aCustomStatistic" .}}
  449. {{template "modals/textModal"}}
  450. <script>
  451. class CurTotal {
  452. constructor(current, total) {
  453. this.current = current;
  454. this.total = total;
  455. }
  456. get percent() {
  457. if (this.total === 0) {
  458. return 0;
  459. }
  460. return NumberFormatter.toFixed(this.current / this.total * 100, 2);
  461. }
  462. get color() {
  463. const percent = this.percent;
  464. if (percent < 80) {
  465. return '#008771'; // Green
  466. } else if (percent < 90) {
  467. return "#f37b24"; // Orange
  468. } else {
  469. return "#cf3c3c"; // Red
  470. }
  471. }
  472. }
  473. class Status {
  474. constructor(data, isLoaded = false) {
  475. this.cpu = new CurTotal(0, 0);
  476. this.cpuCores = 0;
  477. this.logicalPro = 0;
  478. this.cpuSpeedMhz = 0;
  479. this.disk = new CurTotal(0, 0);
  480. this.loads = [0, 0, 0];
  481. this.mem = new CurTotal(0, 0);
  482. this.netIO = { up: 0, down: 0 };
  483. this.netTraffic = { sent: 0, recv: 0 };
  484. this.publicIP = { ipv4: 0, ipv6: 0 };
  485. this.swap = new CurTotal(0, 0);
  486. this.tcpCount = 0;
  487. this.udpCount = 0;
  488. this.uptime = 0;
  489. this.appUptime = 0;
  490. this.appStats = {threads: 0, mem: 0, uptime: 0};
  491. this.xray = { state: 'stop', stateMsg: "", errorMsg: "", version: "", color: "" };
  492. if (data == null) {
  493. return;
  494. }
  495. this.isLoaded = isLoaded;
  496. this.cpu = new CurTotal(data.cpu, 100);
  497. this.cpuCores = data.cpuCores;
  498. this.logicalPro = data.logicalPro;
  499. this.cpuSpeedMhz = data.cpuSpeedMhz;
  500. this.disk = new CurTotal(data.disk.current, data.disk.total);
  501. this.loads = data.loads.map(load => NumberFormatter.toFixed(load, 2));
  502. this.mem = new CurTotal(data.mem.current, data.mem.total);
  503. this.netIO = data.netIO;
  504. this.netTraffic = data.netTraffic;
  505. this.publicIP = data.publicIP;
  506. this.swap = new CurTotal(data.swap.current, data.swap.total);
  507. this.tcpCount = data.tcpCount;
  508. this.udpCount = data.udpCount;
  509. this.uptime = data.uptime;
  510. this.appUptime = data.appUptime;
  511. this.appStats = data.appStats;
  512. this.xray = data.xray;
  513. switch (this.xray.state) {
  514. case 'running':
  515. this.xray.color = "green";
  516. this.xray.stateMsg = '{{ i18n "pages.index.xrayStatusRunning" }}';
  517. break;
  518. case 'stop':
  519. this.xray.color = "orange";
  520. this.xray.stateMsg = '{{ i18n "pages.index.xrayStatusStop" }}';
  521. break;
  522. case 'error':
  523. this.xray.color = "red";
  524. this.xray.stateMsg ='{{ i18n "pages.index.xrayStatusError" }}';
  525. break;
  526. default:
  527. this.xray.color = "gray";
  528. this.xray.stateMsg = '{{ i18n "pages.index.xrayStatusUnknown" }}';
  529. break;
  530. }
  531. }
  532. }
  533. const versionModal = {
  534. visible: false,
  535. versions: [],
  536. show(versions) {
  537. this.visible = true;
  538. this.versions = versions;
  539. },
  540. hide() {
  541. this.visible = false;
  542. },
  543. };
  544. const logModal = {
  545. visible: false,
  546. logs: [],
  547. rows: 20,
  548. level: 'info',
  549. syslog: false,
  550. loading: false,
  551. show(logs) {
  552. this.visible = true;
  553. this.logs = logs;
  554. this.formattedLogs = this.logs?.length > 0 ? this.formatLogs(this.logs) : "No Record...";
  555. },
  556. formatLogs(logs) {
  557. let formattedLogs = '';
  558. const levels = ["DEBUG","INFO","NOTICE","WARNING","ERROR"];
  559. const levelColors = ["#3c89e8","#008771","#008771","#f37b24","#e04141","#bcbcbc"];
  560. logs.forEach((log, index) => {
  561. let [data, message] = log.split(" - ",2);
  562. const parts = data.split(" ")
  563. if(index>0) formattedLogs += '<br>';
  564. if (parts.length === 3) {
  565. const d = parts[0];
  566. const t = parts[1];
  567. const level = parts[2];
  568. const levelIndex = levels.indexOf(level,levels) || 5;
  569. //formattedLogs += `<span style="color: gray;">${index + 1}.</span>`;
  570. formattedLogs += `<span style="color: ${levelColors[0]};">${d} ${t}</span> `;
  571. formattedLogs += `<span style="color: ${levelColors[levelIndex]}">${level}</span>`;
  572. } else {
  573. const levelIndex = levels.indexOf(data,levels) || 5;
  574. formattedLogs += `<span style="color: ${levelColors[levelIndex]}">${data}</span>`;
  575. }
  576. if(message){
  577. if(message.startsWith("XRAY:"))
  578. message = "<b>XRAY: </b>" + message.substring(5);
  579. else
  580. message = "<b>X-UI: </b>" + message;
  581. }
  582. formattedLogs += message ? ' - ' + message : '';
  583. });
  584. return formattedLogs;
  585. },
  586. hide() {
  587. this.visible = false;
  588. },
  589. };
  590. const backupModal = {
  591. visible: false,
  592. show() {
  593. this.visible = true;
  594. },
  595. hide() {
  596. this.visible = false;
  597. },
  598. };
  599. const app = new Vue({
  600. delimiters: ['[[', ']]'],
  601. el: '#app',
  602. mixins: [MediaQueryMixin],
  603. data: {
  604. themeSwitcher,
  605. status: new Status(),
  606. versionModal,
  607. logModal,
  608. backupModal,
  609. spinning: false,
  610. loadingTip: '{{ i18n "loading"}}',
  611. showAlert: false,
  612. showIp: false
  613. },
  614. methods: {
  615. loading(spinning, tip = '{{ i18n "loading"}}') {
  616. this.spinning = spinning;
  617. this.loadingTip = tip;
  618. },
  619. async getStatus() {
  620. try {
  621. const msg = await HttpUtil.post('/server/status');
  622. if (msg.success) {
  623. this.setStatus(msg.obj, true);
  624. }
  625. } catch (e) {
  626. console.error("Failed to get status:", e);
  627. }
  628. },
  629. setStatus(data, isLoaded = false) {
  630. this.status = new Status(data, isLoaded);
  631. },
  632. async openSelectV2rayVersion() {
  633. this.loading(true);
  634. const msg = await HttpUtil.post('server/getXrayVersion');
  635. this.loading(false);
  636. if (!msg.success) {
  637. return;
  638. }
  639. versionModal.show(msg.obj);
  640. },
  641. switchV2rayVersion(version) {
  642. this.$confirm({
  643. title: '{{ i18n "pages.index.xraySwitchVersionDialog"}}',
  644. content: '{{ i18n "pages.index.xraySwitchVersionDialogDesc"}}'.replace('#version#', version),
  645. okText: '{{ i18n "confirm"}}',
  646. class: themeSwitcher.currentTheme,
  647. cancelText: '{{ i18n "cancel"}}',
  648. onOk: async () => {
  649. versionModal.hide();
  650. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  651. await HttpUtil.post(`/server/installXray/${version}`);
  652. this.loading(false);
  653. },
  654. });
  655. },
  656. updateGeofile(fileName) {
  657. this.$confirm({
  658. title: '{{ i18n "pages.index.geofileUpdateDialog" }}',
  659. content: '{{ i18n "pages.index.geofileUpdateDialogDesc" }}'.replace("#filename#", fileName),
  660. okText: '{{ i18n "confirm"}}',
  661. class: themeSwitcher.currentTheme,
  662. cancelText: '{{ i18n "cancel"}}',
  663. onOk: async () => {
  664. versionModal.hide();
  665. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  666. await HttpUtil.post(`/server/updateGeofile/${fileName}`);
  667. this.loading(false);
  668. },
  669. });
  670. },
  671. async stopXrayService() {
  672. this.loading(true);
  673. const msg = await HttpUtil.post('server/stopXrayService');
  674. this.loading(false);
  675. if (!msg.success) {
  676. return;
  677. }
  678. },
  679. async restartXrayService() {
  680. this.loading(true);
  681. const msg = await HttpUtil.post('server/restartXrayService');
  682. this.loading(false);
  683. if (!msg.success) {
  684. return;
  685. }
  686. },
  687. async openLogs(){
  688. logModal.loading = true;
  689. const msg = await HttpUtil.post('server/logs/'+logModal.rows,{level: logModal.level, syslog: logModal.syslog});
  690. if (!msg.success) {
  691. return;
  692. }
  693. logModal.show(msg.obj);
  694. await PromiseUtil.sleep(500);
  695. logModal.loading = false;
  696. },
  697. async openConfig() {
  698. this.loading(true);
  699. const msg = await HttpUtil.post('server/getConfigJson');
  700. this.loading(false);
  701. if (!msg.success) {
  702. return;
  703. }
  704. txtModal.show('config.json', JSON.stringify(msg.obj, null, 2), 'config.json');
  705. },
  706. openBackup() {
  707. backupModal.show();
  708. },
  709. exportDatabase() {
  710. window.location = basePath + 'server/getDb';
  711. },
  712. importDatabase() {
  713. const fileInput = document.createElement('input');
  714. fileInput.type = 'file';
  715. fileInput.accept = '.db';
  716. fileInput.addEventListener('change', async (event) => {
  717. const dbFile = event.target.files[0];
  718. if (dbFile) {
  719. const formData = new FormData();
  720. formData.append('db', dbFile);
  721. backupModal.hide();
  722. this.loading(true);
  723. const uploadMsg = await HttpUtil.post('server/importDB', formData, {
  724. headers: {
  725. 'Content-Type': 'multipart/form-data',
  726. }
  727. });
  728. this.loading(false);
  729. if (!uploadMsg.success) {
  730. return;
  731. }
  732. this.loading(true);
  733. const restartMsg = await HttpUtil.post("/panel/setting/restartPanel");
  734. this.loading(false);
  735. if (restartMsg.success) {
  736. this.loading(true);
  737. await PromiseUtil.sleep(5000);
  738. location.reload();
  739. }
  740. }
  741. });
  742. fileInput.click();
  743. },
  744. },
  745. async mounted() {
  746. if (window.location.protocol !== "https:") {
  747. this.showAlert = true;
  748. }
  749. while (true) {
  750. try {
  751. await this.getStatus();
  752. } catch (e) {
  753. console.error(e);
  754. }
  755. await PromiseUtil.sleep(2000);
  756. }
  757. },
  758. });
  759. </script>
  760. </body>
  761. </html>