index.html 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  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. }
  13. .ant-col-sm-24 {
  14. margin-top: 10px;
  15. }
  16. .ant-card-dark h2 {
  17. color: hsla(0, 0%, 100%, .65);
  18. }
  19. </style>
  20. <body>
  21. <a-layout id="app" v-cloak :class="themeSwitcher.currentTheme">
  22. {{ template "commonSider" . }}
  23. <a-layout id="content-layout">
  24. <a-layout-content>
  25. <a-spin :spinning="spinning" :delay="200" :tip="loadingTip"/>
  26. <transition name="list" appear>
  27. <a-row>
  28. <a-card hoverable>
  29. <a-row>
  30. <a-col :sm="24" :md="12">
  31. <a-row>
  32. <a-col :span="12" style="text-align: center">
  33. <a-progress type="dashboard" status="normal"
  34. :stroke-color="status.cpu.color"
  35. :percent="status.cpu.percent"></a-progress>
  36. <div>CPU: [[ cpuCoreFormat(status.cpuCores) ]]</div>
  37. <div>Speed: [[ cpuSpeedFormat(status.cpuSpeedMhz) ]]</div>
  38. </a-col>
  39. <a-col :span="12" style="text-align: center">
  40. <a-progress type="dashboard" status="normal"
  41. :stroke-color="status.mem.color"
  42. :percent="status.mem.percent"></a-progress>
  43. <div>
  44. {{ i18n "pages.index.memory"}}: [[ sizeFormat(status.mem.current) ]] / [[ sizeFormat(status.mem.total) ]]
  45. </div>
  46. </a-col>
  47. </a-row>
  48. </a-col>
  49. <a-col :sm="24" :md="12">
  50. <a-row>
  51. <a-col :span="12" style="text-align: center">
  52. <a-progress type="dashboard" status="normal"
  53. :stroke-color="status.swap.color"
  54. :percent="status.swap.percent"></a-progress>
  55. <div>
  56. Swap: [[ sizeFormat(status.swap.current) ]] / [[ sizeFormat(status.swap.total) ]]
  57. </div>
  58. </a-col>
  59. <a-col :span="12" style="text-align: center">
  60. <a-progress type="dashboard" status="normal"
  61. :stroke-color="status.disk.color"
  62. :percent="status.disk.percent"></a-progress>
  63. <div>
  64. {{ i18n "pages.index.hard"}}: [[ sizeFormat(status.disk.current) ]] / [[ sizeFormat(status.disk.total) ]]
  65. </div>
  66. </a-col>
  67. </a-row>
  68. </a-col>
  69. </a-row>
  70. </a-card>
  71. </a-row>
  72. </transition>
  73. <transition name="list" appear>
  74. <a-row>
  75. <a-col :sm="24" :md="12">
  76. <a-card hoverable>
  77. 3X-UI <a href="https://github.com/MHSanaei/3x-ui/releases" target="_blank"><a-tag color="green">v{{ .cur_ver }}</a-tag></a>
  78. Xray <a-tag color="green" style="cursor: pointer;" @click="openSelectV2rayVersion">v[[ status.xray.version ]]</a-tag>
  79. <a href="https://t.me/panel3xui" target="_blank"><a-tag color="green">@panel3xui</a-tag></a>
  80. </a-card>
  81. </a-col>
  82. <a-col :sm="24" :md="12">
  83. <a-card hoverable>
  84. {{ i18n "menu.link" }}:
  85. <a-tag color="purple" style="cursor: pointer;" @click="openLogs()">{{ i18n "pages.index.logs" }}</a-tag>
  86. <a-tag color="purple" style="cursor: pointer;" @click="openConfig">{{ i18n "pages.index.config" }}</a-tag>
  87. <a-tag color="purple" style="cursor: pointer;" @click="openBackup">{{ i18n "pages.index.backup" }}</a-tag>
  88. </a-card>
  89. </a-col>
  90. <a-col :sm="24" :md="12">
  91. <a-card hoverable>
  92. {{ i18n "pages.index.xrayStatus" }}:
  93. <a-tag :color="status.xray.color">[[ status.xray.state.toUpperCase() ]]</a-tag>
  94. <a-popover v-if="status.xray.state === State.Error"
  95. :overlay-class-name="themeSwitcher.currentTheme">
  96. <span slot="title" style="font-size: 12pt">An error occurred while running Xray
  97. <a-tag color="purple" style="cursor: pointer; float: right;" @click="openLogs()">{{ i18n "pages.index.logs" }}</a-tag>
  98. </span>
  99. <template slot="content">
  100. <p style="max-width: 400px" v-for="line in status.xray.errorMsg.split('\n')">[[ line ]]</p>
  101. </template>
  102. <a-icon type="question-circle"></a-icon>
  103. </a-popover>
  104. <a-tag color="purple" style="cursor: pointer;" @click="stopXrayService">{{ i18n "pages.index.stopXray" }}</a-tag>
  105. <a-tag color="purple" style="cursor: pointer;" @click="restartXrayService">{{ i18n "pages.index.restartXray" }}</a-tag>
  106. <a-tag color="purple" style="cursor: pointer;" @click="openSelectV2rayVersion">{{ i18n "pages.index.xraySwitch" }}</a-tag>
  107. </a-card>
  108. </a-col>
  109. <a-col :sm="24" :md="12">
  110. <a-card hoverable>
  111. {{ i18n "pages.index.operationHours" }}:
  112. Xray
  113. <a-tag color="green">[[ formatSecond(status.appStats.uptime) ]]</a-tag>
  114. OS
  115. <a-tag color="green">[[ formatSecond(status.uptime) ]]</a-tag>
  116. </a-card>
  117. </a-col>
  118. <a-col :sm="24" :md="12">
  119. <a-card hoverable>
  120. {{ i18n "pages.index.systemLoad" }}: [[ status.loads[0] ]] | [[ status.loads[1] ]] | [[ status.loads[2] ]]
  121. <a-tooltip>
  122. <template slot="title">
  123. {{ i18n "pages.index.systemLoadDesc" }}
  124. </template>
  125. <a-icon type="question-circle"></a-icon>
  126. </a-tooltip>
  127. </a-card>
  128. </a-col>
  129. <a-col :sm="24" :md="12">
  130. <a-card hoverable>
  131. {{ i18n "usage"}}:
  132. RAM [[ sizeFormat(status.appStats.mem) ]] -
  133. Threads [[ status.appStats.threads ]]
  134. </a-tooltip>
  135. </a-card>
  136. </a-col>
  137. <a-col :sm="24" :md="12">
  138. <a-card hoverable>
  139. <a-row>
  140. <a-col :span="12">
  141. IPv4:
  142. <a-tooltip>
  143. <template slot="title">
  144. [[ status.publicIP.ipv4 ]]
  145. </template>
  146. <a-icon type="question-circle"></a-icon>
  147. </a-tooltip>
  148. </a-col>
  149. <a-col :span="12">
  150. IPv6:
  151. <a-tooltip>
  152. <template slot="title">
  153. [[ status.publicIP.ipv6 ]]
  154. </template>
  155. <a-icon type="question-circle"></a-icon>
  156. </a-tooltip>
  157. </a-col>
  158. </a-row>
  159. </a-card>
  160. </a-col>
  161. <a-col :sm="24" :md="12">
  162. <a-card hoverable>
  163. <a-row>
  164. <a-col :span="12">
  165. TCP: [[ status.tcpCount ]]
  166. <a-tooltip>
  167. <template slot="title">
  168. {{ i18n "pages.index.connectionTcpCountDesc" }}
  169. </template>
  170. <a-icon type="question-circle"></a-icon>
  171. </a-tooltip>
  172. </a-col>
  173. <a-col :span="12">
  174. UDP: [[ status.udpCount ]]
  175. <a-tooltip>
  176. <template slot="title">
  177. {{ i18n "pages.index.connectionUdpCountDesc" }}
  178. </template>
  179. <a-icon type="question-circle"></a-icon>
  180. </a-tooltip>
  181. </a-col>
  182. </a-row>
  183. </a-card>
  184. </a-col>
  185. <a-col :sm="24" :md="12">
  186. <a-card hoverable>
  187. <a-row>
  188. <a-col :span="12">
  189. <a-icon type="arrow-up"></a-icon>
  190. [[ sizeFormat(status.netIO.up) ]]/s
  191. <a-tooltip>
  192. <template slot="title">
  193. {{ i18n "pages.index.upSpeed" }}
  194. </template>
  195. <a-icon type="question-circle"></a-icon>
  196. </a-tooltip>
  197. </a-col>
  198. <a-col :span="12">
  199. <a-icon type="arrow-down"></a-icon>
  200. [[ sizeFormat(status.netIO.down) ]]/s
  201. <a-tooltip>
  202. <template slot="title">
  203. {{ i18n "pages.index.downSpeed" }}
  204. </template>
  205. <a-icon type="question-circle"></a-icon>
  206. </a-tooltip>
  207. </a-col>
  208. </a-row>
  209. </a-card>
  210. </a-col>
  211. <a-col :sm="24" :md="12">
  212. <a-card hoverable>
  213. <a-row>
  214. <a-col :span="12">
  215. <a-icon type="cloud-upload"></a-icon>
  216. [[ sizeFormat(status.netTraffic.sent) ]]
  217. <a-tooltip>
  218. <template slot="title">
  219. {{ i18n "pages.index.totalSent" }}
  220. </template>
  221. <a-icon type="question-circle"></a-icon>
  222. </a-tooltip>
  223. </a-col>
  224. <a-col :span="12">
  225. <a-icon type="cloud-download"></a-icon>
  226. [[ sizeFormat(status.netTraffic.recv) ]]
  227. <a-tooltip>
  228. <template slot="title">
  229. {{ i18n "pages.index.totalReceive" }}
  230. </template>
  231. <a-icon type="question-circle"></a-icon>
  232. </a-tooltip>
  233. </a-col>
  234. </a-row>
  235. </a-card>
  236. </a-col>
  237. </a-row>
  238. </transition>
  239. </a-layout-content>
  240. </a-layout>
  241. <a-modal id="version-modal" v-model="versionModal.visible" title='{{ i18n "pages.index.xraySwitch" }}'
  242. :closable="true" @ok="() => versionModal.visible = false"
  243. :class="themeSwitcher.currentTheme"
  244. footer="">
  245. <a-alert type="warning" style="margin-bottom: 12px; width: fit-content"
  246. message='{{ i18n "pages.index.xraySwitchClickDesk" }}'
  247. show-icon
  248. ></a-alert>
  249. <template v-for="version, index in versionModal.versions">
  250. <a-tag :color="index % 2 == 0 ? 'purple' : 'green'"
  251. style="margin: 10px" @click="switchV2rayVersion(version)">
  252. [[ version ]]
  253. </a-tag>
  254. </template>
  255. </a-modal>
  256. <a-modal id="log-modal" v-model="logModal.visible" title="Logs"
  257. :closable="true" @ok="() => logModal.visible = false" @cancel="() => logModal.visible = false"
  258. :class="themeSwitcher.currentTheme"
  259. width="800px"
  260. footer="">
  261. <a-form layout="inline">
  262. <a-form-item label="Count">
  263. <a-select v-model="logModal.rows"
  264. style="width: 80px"
  265. @change="openLogs()"
  266. :dropdown-class-name="themeSwitcher.currentTheme">
  267. <a-select-option value="10">10</a-select-option>
  268. <a-select-option value="20">20</a-select-option>
  269. <a-select-option value="50">50</a-select-option>
  270. <a-select-option value="100">100</a-select-option>
  271. </a-select>
  272. </a-form-item>
  273. <a-form-item label="Log Level">
  274. <a-select v-model="logModal.level"
  275. style="width: 120px"
  276. @change="openLogs()"
  277. :dropdown-class-name="themeSwitcher.currentTheme">
  278. <a-select-option value="debug">Debug</a-select-option>
  279. <a-select-option value="info">Info</a-select-option>
  280. <a-select-option value="notice">Notice</a-select-option>
  281. <a-select-option value="warning">Warning</a-select-option>
  282. <a-select-option value="err">Error</a-select-option>
  283. </a-select>
  284. </a-form-item>
  285. <a-form-item label="SysLog">
  286. <a-checkbox v-model="logModal.syslog" @change="openLogs()"></a-checkbox>
  287. </a-form-item>
  288. <a-form-item>
  289. <a-button class="ant-btn ant-btn-primary" :loading="logModal.loading" @click="openLogs()"><a-icon :spin="logModal.loading" type="sync"></a-icon> Reload</a-button>
  290. </a-form-item>
  291. <a-form-item>
  292. <a-button type="primary" style="margin-bottom: 10px;"
  293. :href="'data:application/text;charset=utf-8,' + encodeURIComponent(logModal.logs)" download="x-ui.log">
  294. {{ i18n "download" }} x-ui.log
  295. </a-button>
  296. </a-form-item>
  297. </a-form>
  298. <div class="ant-input" style="height: auto; max-height: 500px; overflow: auto;" v-html="logModal.logs"></div>
  299. </a-modal>
  300. <a-modal id="backup-modal" v-model="backupModal.visible" :title="backupModal.title"
  301. :closable="true" :class="themeSwitcher.currentTheme"
  302. @ok="() => backupModal.hide()" @cancel="() => backupModal.hide()">
  303. <a-alert type="warning" style="margin-bottom: 10px; width: fit-content"
  304. :message="backupModal.description"
  305. show-icon
  306. ></a-alert>
  307. <a-space direction="horizontal" style="text-align: center" style="margin-bottom: 10px;">
  308. <a-button type="primary" @click="exportDatabase()">
  309. [[ backupModal.exportText ]]
  310. </a-button>
  311. <a-button type="primary" @click="importDatabase()">
  312. [[ backupModal.importText ]]
  313. </a-button>
  314. </a-space>
  315. </a-modal>
  316. </a-layout>
  317. {{template "js" .}}
  318. <script src="{{ .base_path }}assets/clipboard/clipboard.min.js"></script>
  319. {{template "component/themeSwitcher" .}}
  320. {{template "textModal"}}
  321. <script>
  322. const State = {
  323. Running: "running",
  324. Stop: "stop",
  325. Error: "error",
  326. }
  327. Object.freeze(State);
  328. class CurTotal {
  329. constructor(current, total) {
  330. this.current = current;
  331. this.total = total;
  332. }
  333. get percent() {
  334. if (this.total === 0) {
  335. return 0;
  336. }
  337. return toFixed(this.current / this.total * 100, 2);
  338. }
  339. get color() {
  340. const percent = this.percent;
  341. if (percent < 80) {
  342. return '#008771'; // Green
  343. } else if (percent < 90) {
  344. return "#f37b24"; // Orange
  345. } else {
  346. return "#cf3c3c"; // Red
  347. }
  348. }
  349. }
  350. class Status {
  351. constructor(data) {
  352. this.cpu = new CurTotal(0, 0);
  353. this.cpuCores = 0;
  354. this.cpuSpeedMhz = 0;
  355. this.disk = new CurTotal(0, 0);
  356. this.loads = [0, 0, 0];
  357. this.mem = new CurTotal(0, 0);
  358. this.netIO = { up: 0, down: 0 };
  359. this.netTraffic = { sent: 0, recv: 0 };
  360. this.publicIP = { ipv4: 0, ipv6: 0 };
  361. this.swap = new CurTotal(0, 0);
  362. this.tcpCount = 0;
  363. this.udpCount = 0;
  364. this.uptime = 0;
  365. this.appUptime = 0;
  366. this.appStats = {threads: 0, mem: 0, uptime: 0};
  367. this.xray = { state: State.Stop, errorMsg: "", version: "", color: "" };
  368. if (data == null) {
  369. return;
  370. }
  371. this.cpu = new CurTotal(data.cpu, 100);
  372. this.cpuCores = data.cpuCores;
  373. this.cpuSpeedMhz = data.cpuSpeedMhz;
  374. this.disk = new CurTotal(data.disk.current, data.disk.total);
  375. this.loads = data.loads.map(load => toFixed(load, 2));
  376. this.mem = new CurTotal(data.mem.current, data.mem.total);
  377. this.netIO = data.netIO;
  378. this.netTraffic = data.netTraffic;
  379. this.publicIP = data.publicIP;
  380. this.swap = new CurTotal(data.swap.current, data.swap.total);
  381. this.tcpCount = data.tcpCount;
  382. this.udpCount = data.udpCount;
  383. this.uptime = data.uptime;
  384. this.appUptime = data.appUptime;
  385. this.appStats = data.appStats;
  386. this.xray = data.xray;
  387. switch (this.xray.state) {
  388. case State.Running:
  389. this.xray.color = "green";
  390. break;
  391. case State.Stop:
  392. this.xray.color = "orange";
  393. break;
  394. case State.Error:
  395. this.xray.color = "red";
  396. break;
  397. default:
  398. this.xray.color = "gray";
  399. }
  400. }
  401. }
  402. const versionModal = {
  403. visible: false,
  404. versions: [],
  405. show(versions) {
  406. this.visible = true;
  407. this.versions = versions;
  408. },
  409. hide() {
  410. this.visible = false;
  411. },
  412. };
  413. const logModal = {
  414. visible: false,
  415. logs: '',
  416. rows: 20,
  417. level: 'info',
  418. syslog: false,
  419. loading: false,
  420. show(logs) {
  421. this.visible = true;
  422. this.logs = logs? this.formatLogs(logs) : "No Record...";
  423. },
  424. formatLogs(logs) {
  425. let formattedLogs = '';
  426. const levels = ["DEBUG","INFO","NOTICE","WARNING","ERROR"];
  427. const levelColors = ["#3c89e8","#008771","#008771","#f37b24","#e04141","#bcbcbc"];
  428. logs.forEach((log, index) => {
  429. let [data, message] = log.split(" - ",2);
  430. const parts = data.split(" ")
  431. if(index>0) formattedLogs += '<br>';
  432. if (parts.length === 3) {
  433. const d = parts[0];
  434. const t = parts[1];
  435. const level = parts[2];
  436. const levelIndex = levels.indexOf(level,levels) || 5;
  437. //formattedLogs += `<span style="color: gray;">${index + 1}.</span>`;
  438. formattedLogs += `<span style="color: ${levelColors[0]};">${d} ${t}</span> `;
  439. formattedLogs += `<span style="color: ${levelColors[levelIndex]}">${level}</span>`;
  440. } else {
  441. const levelIndex = levels.indexOf(data,levels) || 5;
  442. formattedLogs += `<span style="color: ${levelColors[levelIndex]}">${data}</span>`;
  443. }
  444. if(message){
  445. if(message.startsWith("XRAY:"))
  446. message = "<b>XRAY: </b>" + message.substring(5);
  447. else
  448. message = "<b>X-UI: </b>" + message;
  449. }
  450. formattedLogs += message ? ' - ' + message : '';
  451. });
  452. return formattedLogs;
  453. },
  454. hide() {
  455. this.visible = false;
  456. },
  457. };
  458. const backupModal = {
  459. visible: false,
  460. title: '',
  461. description: '',
  462. exportText: '',
  463. importText: '',
  464. show({
  465. title = '{{ i18n "pages.index.backupTitle" }}',
  466. description = '{{ i18n "pages.index.backupDescription" }}',
  467. exportText = '{{ i18n "pages.index.exportDatabase" }}',
  468. importText = '{{ i18n "pages.index.importDatabase" }}',
  469. }) {
  470. this.title = title;
  471. this.description = description;
  472. this.exportText = exportText;
  473. this.importText = importText;
  474. this.visible = true;
  475. },
  476. hide() {
  477. this.visible = false;
  478. },
  479. };
  480. const app = new Vue({
  481. delimiters: ['[[', ']]'],
  482. el: '#app',
  483. data: {
  484. siderDrawer,
  485. themeSwitcher,
  486. status: new Status(),
  487. versionModal,
  488. logModal,
  489. backupModal,
  490. spinning: false,
  491. loadingTip: '{{ i18n "loading"}}',
  492. },
  493. methods: {
  494. loading(spinning, tip = '{{ i18n "loading"}}') {
  495. this.spinning = spinning;
  496. this.loadingTip = tip;
  497. },
  498. async getStatus() {
  499. try {
  500. const msg = await HttpUtil.post('/server/status');
  501. if (msg.success) {
  502. this.setStatus(msg.obj);
  503. }
  504. } catch (e) {
  505. console.error("Failed to get status:", e);
  506. }
  507. },
  508. setStatus(data) {
  509. this.status = new Status(data);
  510. },
  511. async openSelectV2rayVersion() {
  512. this.loading(true);
  513. const msg = await HttpUtil.post('server/getXrayVersion');
  514. this.loading(false);
  515. if (!msg.success) {
  516. return;
  517. }
  518. versionModal.show(msg.obj);
  519. },
  520. switchV2rayVersion(version) {
  521. this.$confirm({
  522. title: '{{ i18n "pages.index.xraySwitchVersionDialog"}}',
  523. content: '{{ i18n "pages.index.xraySwitchVersionDialogDesc"}}' + ` ${version}?`,
  524. okText: '{{ i18n "confirm"}}',
  525. class: themeSwitcher.currentTheme,
  526. cancelText: '{{ i18n "cancel"}}',
  527. onOk: async () => {
  528. versionModal.hide();
  529. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  530. await HttpUtil.post(`/server/installXray/${version}`);
  531. this.loading(false);
  532. },
  533. });
  534. },
  535. async stopXrayService() {
  536. this.loading(true);
  537. const msg = await HttpUtil.post('server/stopXrayService');
  538. this.loading(false);
  539. if (!msg.success) {
  540. return;
  541. }
  542. },
  543. async restartXrayService() {
  544. this.loading(true);
  545. const msg = await HttpUtil.post('server/restartXrayService');
  546. this.loading(false);
  547. if (!msg.success) {
  548. return;
  549. }
  550. },
  551. async openLogs(){
  552. logModal.loading = true;
  553. const msg = await HttpUtil.post('server/logs/'+logModal.rows,{level: logModal.level, syslog: logModal.syslog});
  554. if (!msg.success) {
  555. return;
  556. }
  557. logModal.show(msg.obj);
  558. await PromiseUtil.sleep(500);
  559. logModal.loading = false;
  560. },
  561. async openConfig() {
  562. this.loading(true);
  563. const msg = await HttpUtil.post('server/getConfigJson');
  564. this.loading(false);
  565. if (!msg.success) {
  566. return;
  567. }
  568. txtModal.show('config.json', JSON.stringify(msg.obj, null, 2), 'config.json');
  569. },
  570. openBackup() {
  571. backupModal.show({
  572. title: '{{ i18n "pages.index.backupTitle" }}',
  573. description: '{{ i18n "pages.index.backupDescription" }}',
  574. exportText: '{{ i18n "pages.index.exportDatabase" }}',
  575. importText: '{{ i18n "pages.index.importDatabase" }}',
  576. });
  577. },
  578. exportDatabase() {
  579. window.location = basePath + 'server/getDb';
  580. },
  581. importDatabase() {
  582. const fileInput = document.createElement('input');
  583. fileInput.type = 'file';
  584. fileInput.accept = '.db';
  585. fileInput.addEventListener('change', async (event) => {
  586. const dbFile = event.target.files[0];
  587. if (dbFile) {
  588. const formData = new FormData();
  589. formData.append('db', dbFile);
  590. backupModal.hide();
  591. this.loading(true);
  592. const uploadMsg = await HttpUtil.post('server/importDB', formData, {
  593. headers: {
  594. 'Content-Type': 'multipart/form-data',
  595. }
  596. });
  597. this.loading(false);
  598. if (!uploadMsg.success) {
  599. return;
  600. }
  601. this.loading(true);
  602. const restartMsg = await HttpUtil.post("/panel/setting/restartPanel");
  603. this.loading(false);
  604. if (restartMsg.success) {
  605. this.loading(true);
  606. await PromiseUtil.sleep(5000);
  607. location.reload();
  608. }
  609. }
  610. });
  611. fileInput.click();
  612. },
  613. },
  614. async mounted() {
  615. let retries = 0;
  616. while (retries < 5) {
  617. try {
  618. await this.getStatus();
  619. retries = 0;
  620. } catch (e) {
  621. console.error("Error occurred while fetching status:", e);
  622. retries++;
  623. }
  624. await PromiseUtil.sleep(2000);
  625. }
  626. },
  627. });
  628. </script>
  629. </body>
  630. </html>