index.html 33 KB

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