index.html 32 KB

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