index.html 33 KB

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