index.html 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  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: <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 ]]</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">Error in running xray-core
  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. Memory [[ 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. <h2>{{ i18n "pages.index.xraySwitchClick"}}</h2>
  246. <h2>{{ i18n "pages.index.xraySwitchClickDesk"}}</h2>
  247. <template v-for="version, index in versionModal.versions">
  248. <a-tag :color="index % 2 == 0 ? 'purple' : 'green'"
  249. style="margin: 10px" @click="switchV2rayVersion(version)">
  250. [[ version ]]
  251. </a-tag>
  252. </template>
  253. </a-modal>
  254. <a-modal id="log-modal" v-model="logModal.visible" title="Logs"
  255. :closable="true" @ok="() => logModal.visible = false" @cancel="() => logModal.visible = false"
  256. :class="themeSwitcher.currentTheme"
  257. width="800px"
  258. footer="">
  259. <a-form layout="inline">
  260. <a-form-item label="Count">
  261. <a-select v-model="logModal.rows"
  262. style="width: 80px"
  263. @change="openLogs()"
  264. :dropdown-class-name="themeSwitcher.currentTheme">
  265. <a-select-option value="10">10</a-select-option>
  266. <a-select-option value="20">20</a-select-option>
  267. <a-select-option value="50">50</a-select-option>
  268. <a-select-option value="100">100</a-select-option>
  269. </a-select>
  270. </a-form-item>
  271. <a-form-item label="Log Level">
  272. <a-select v-model="logModal.level"
  273. style="width: 120px"
  274. @change="openLogs()"
  275. :dropdown-class-name="themeSwitcher.currentTheme">
  276. <a-select-option value="debug">Debug</a-select-option>
  277. <a-select-option value="info">Info</a-select-option>
  278. <a-select-option value="notice">Notice</a-select-option>
  279. <a-select-option value="warning">Warning</a-select-option>
  280. <a-select-option value="err">Error</a-select-option>
  281. </a-select>
  282. </a-form-item>
  283. <a-form-item label="SysLog">
  284. <a-checkbox v-model="logModal.syslog" @change="openLogs()"></a-checkbox>
  285. </a-form-item>
  286. <a-form-item>
  287. <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>
  288. </a-form-item>
  289. <a-form-item>
  290. <a-button type="primary" style="margin-bottom: 10px;"
  291. :href="'data:application/text;charset=utf-8,' + encodeURIComponent(logModal.logs)" download="x-ui.log">
  292. {{ i18n "download" }} x-ui.log
  293. </a-button>
  294. </a-form-item>
  295. </a-form>
  296. <div class="ant-input" style="height: auto; max-height: 500px; overflow: auto;" v-html="logModal.logs"></div>
  297. </a-modal>
  298. <a-modal id="backup-modal" v-model="backupModal.visible" :title="backupModal.title"
  299. :closable="true" :class="themeSwitcher.currentTheme"
  300. @ok="() => backupModal.hide()" @cancel="() => backupModal.hide()">
  301. <a-alert type="warning" style="margin-bottom: 10px; width: fit-content"
  302. :message="backupModal.description"
  303. show-icon
  304. ></a-alert>
  305. <a-space direction="horizontal" style="text-align: center" style="margin-bottom: 10px;">
  306. <a-button type="primary" @click="exportDatabase()">
  307. [[ backupModal.exportText ]]
  308. </a-button>
  309. <a-button type="primary" @click="importDatabase()">
  310. [[ backupModal.importText ]]
  311. </a-button>
  312. </a-space>
  313. </a-modal>
  314. </a-layout>
  315. {{template "js" .}}
  316. <script src="{{ .base_path }}assets/clipboard/clipboard.min.js"></script>
  317. {{template "component/themeSwitcher" .}}
  318. {{template "textModal"}}
  319. <script>
  320. const State = {
  321. Running: "running",
  322. Stop: "stop",
  323. Error: "error",
  324. }
  325. Object.freeze(State);
  326. class CurTotal {
  327. constructor(current, total) {
  328. this.current = current;
  329. this.total = total;
  330. }
  331. get percent() {
  332. if (this.total === 0) {
  333. return 0;
  334. }
  335. return toFixed(this.current / this.total * 100, 2);
  336. }
  337. get color() {
  338. const percent = this.percent;
  339. if (percent < 80) {
  340. return '#008771'; // Green
  341. } else if (percent < 90) {
  342. return "#f37b24"; // Orange
  343. } else {
  344. return "#cf3c3c"; // Red
  345. }
  346. }
  347. }
  348. class Status {
  349. constructor(data) {
  350. this.cpu = new CurTotal(0, 0);
  351. this.cpuCores = 0;
  352. this.cpuSpeedMhz = 0;
  353. this.disk = new CurTotal(0, 0);
  354. this.loads = [0, 0, 0];
  355. this.mem = new CurTotal(0, 0);
  356. this.netIO = { up: 0, down: 0 };
  357. this.netTraffic = { sent: 0, recv: 0 };
  358. this.publicIP = { ipv4: 0, ipv6: 0 };
  359. this.swap = new CurTotal(0, 0);
  360. this.tcpCount = 0;
  361. this.udpCount = 0;
  362. this.uptime = 0;
  363. this.appUptime = 0;
  364. this.appStats = {threads: 0, mem: 0, uptime: 0};
  365. this.xray = { state: State.Stop, errorMsg: "", version: "", color: "" };
  366. if (data == null) {
  367. return;
  368. }
  369. this.cpu = new CurTotal(data.cpu, 100);
  370. this.cpuCores = data.cpuCores;
  371. this.cpuSpeedMhz = data.cpuSpeedMhz;
  372. this.disk = new CurTotal(data.disk.current, data.disk.total);
  373. this.loads = data.loads.map(load => toFixed(load, 2));
  374. this.mem = new CurTotal(data.mem.current, data.mem.total);
  375. this.netIO = data.netIO;
  376. this.netTraffic = data.netTraffic;
  377. this.publicIP = data.publicIP;
  378. this.swap = new CurTotal(data.swap.current, data.swap.total);
  379. this.tcpCount = data.tcpCount;
  380. this.udpCount = data.udpCount;
  381. this.uptime = data.uptime;
  382. this.appUptime = data.appUptime;
  383. this.appStats = data.appStats;
  384. this.xray = data.xray;
  385. switch (this.xray.state) {
  386. case State.Running:
  387. this.xray.color = "green";
  388. break;
  389. case State.Stop:
  390. this.xray.color = "orange";
  391. break;
  392. case State.Error:
  393. this.xray.color = "red";
  394. break;
  395. default:
  396. this.xray.color = "gray";
  397. }
  398. }
  399. }
  400. const versionModal = {
  401. visible: false,
  402. versions: [],
  403. show(versions) {
  404. this.visible = true;
  405. this.versions = versions;
  406. },
  407. hide() {
  408. this.visible = false;
  409. },
  410. };
  411. const logModal = {
  412. visible: false,
  413. logs: '',
  414. rows: 20,
  415. level: 'info',
  416. syslog: false,
  417. loading: false,
  418. show(logs) {
  419. this.visible = true;
  420. this.logs = logs? this.formatLogs(logs) : "No Record...";
  421. },
  422. formatLogs(logs) {
  423. let formattedLogs = '';
  424. const levels = ["DEBUG","INFO","NOTICE","WARNING","ERROR"];
  425. const levelColors = ["#3c89e8","#008771","#008771","#f37b24","#e04141","#bcbcbc"];
  426. logs.forEach((log, index) => {
  427. let [data, message] = log.split(" - ",2);
  428. const parts = data.split(" ")
  429. if(index>0) formattedLogs += '<br>';
  430. if (parts.length === 3) {
  431. const d = parts[0];
  432. const t = parts[1];
  433. const level = parts[2];
  434. const levelIndex = levels.indexOf(level,levels) || 5;
  435. //formattedLogs += `<span style="color: gray;">${index + 1}.</span>`;
  436. formattedLogs += `<span style="color: ${levelColors[0]};">${d} ${t}</span> `;
  437. formattedLogs += `<span style="color: ${levelColors[levelIndex]}">${level}</span>`;
  438. } else {
  439. const levelIndex = levels.indexOf(data,levels) || 5;
  440. formattedLogs += `<span style="color: ${levelColors[levelIndex]}">${data}</span>`;
  441. }
  442. if(message){
  443. if(message.startsWith("XRAY:"))
  444. message = "<b>XRAY: </b>" + message.substring(5);
  445. else
  446. message = "<b>X-UI: </b>" + message;
  447. }
  448. formattedLogs += message ? ' - ' + message : '';
  449. });
  450. return formattedLogs;
  451. },
  452. hide() {
  453. this.visible = false;
  454. },
  455. };
  456. const backupModal = {
  457. visible: false,
  458. title: '',
  459. description: '',
  460. exportText: '',
  461. importText: '',
  462. show({
  463. title = '{{ i18n "pages.index.backupTitle" }}',
  464. description = '{{ i18n "pages.index.backupDescription" }}',
  465. exportText = '{{ i18n "pages.index.exportDatabase" }}',
  466. importText = '{{ i18n "pages.index.importDatabase" }}',
  467. }) {
  468. this.title = title;
  469. this.description = description;
  470. this.exportText = exportText;
  471. this.importText = importText;
  472. this.visible = true;
  473. },
  474. hide() {
  475. this.visible = false;
  476. },
  477. };
  478. const app = new Vue({
  479. delimiters: ['[[', ']]'],
  480. el: '#app',
  481. data: {
  482. siderDrawer,
  483. themeSwitcher,
  484. status: new Status(),
  485. versionModal,
  486. logModal,
  487. backupModal,
  488. spinning: false,
  489. loadingTip: '{{ i18n "loading"}}',
  490. },
  491. methods: {
  492. loading(spinning, tip = '{{ i18n "loading"}}') {
  493. this.spinning = spinning;
  494. this.loadingTip = tip;
  495. },
  496. async getStatus() {
  497. try {
  498. const msg = await HttpUtil.post('/server/status');
  499. if (msg.success) {
  500. this.setStatus(msg.obj);
  501. }
  502. } catch (e) {
  503. console.error("Failed to get status:", e);
  504. }
  505. },
  506. setStatus(data) {
  507. this.status = new Status(data);
  508. },
  509. async openSelectV2rayVersion() {
  510. this.loading(true);
  511. const msg = await HttpUtil.post('server/getXrayVersion');
  512. this.loading(false);
  513. if (!msg.success) {
  514. return;
  515. }
  516. versionModal.show(msg.obj);
  517. },
  518. switchV2rayVersion(version) {
  519. this.$confirm({
  520. title: '{{ i18n "pages.index.xraySwitchVersionDialog"}}',
  521. content: '{{ i18n "pages.index.xraySwitchVersionDialogDesc"}}' + ` ${version}?`,
  522. okText: '{{ i18n "confirm"}}',
  523. class: themeSwitcher.currentTheme,
  524. cancelText: '{{ i18n "cancel"}}',
  525. onOk: async () => {
  526. versionModal.hide();
  527. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  528. await HttpUtil.post(`/server/installXray/${version}`);
  529. this.loading(false);
  530. },
  531. });
  532. },
  533. async stopXrayService() {
  534. this.loading(true);
  535. const msg = await HttpUtil.post('server/stopXrayService');
  536. this.loading(false);
  537. if (!msg.success) {
  538. return;
  539. }
  540. },
  541. async restartXrayService() {
  542. this.loading(true);
  543. const msg = await HttpUtil.post('server/restartXrayService');
  544. this.loading(false);
  545. if (!msg.success) {
  546. return;
  547. }
  548. },
  549. async openLogs(){
  550. logModal.loading = true;
  551. const msg = await HttpUtil.post('server/logs/'+logModal.rows,{level: logModal.level, syslog: logModal.syslog});
  552. if (!msg.success) {
  553. return;
  554. }
  555. logModal.show(msg.obj);
  556. await PromiseUtil.sleep(500);
  557. logModal.loading = false;
  558. },
  559. async openConfig() {
  560. this.loading(true);
  561. const msg = await HttpUtil.post('server/getConfigJson');
  562. this.loading(false);
  563. if (!msg.success) {
  564. return;
  565. }
  566. txtModal.show('config.json', JSON.stringify(msg.obj, null, 2), 'config.json');
  567. },
  568. openBackup() {
  569. backupModal.show({
  570. title: '{{ i18n "pages.index.backupTitle" }}',
  571. description: '{{ i18n "pages.index.backupDescription" }}',
  572. exportText: '{{ i18n "pages.index.exportDatabase" }}',
  573. importText: '{{ i18n "pages.index.importDatabase" }}',
  574. });
  575. },
  576. exportDatabase() {
  577. window.location = basePath + 'server/getDb';
  578. },
  579. importDatabase() {
  580. const fileInput = document.createElement('input');
  581. fileInput.type = 'file';
  582. fileInput.accept = '.db';
  583. fileInput.addEventListener('change', async (event) => {
  584. const dbFile = event.target.files[0];
  585. if (dbFile) {
  586. const formData = new FormData();
  587. formData.append('db', dbFile);
  588. backupModal.hide();
  589. this.loading(true);
  590. const uploadMsg = await HttpUtil.post('server/importDB', formData, {
  591. headers: {
  592. 'Content-Type': 'multipart/form-data',
  593. }
  594. });
  595. this.loading(false);
  596. if (!uploadMsg.success) {
  597. return;
  598. }
  599. this.loading(true);
  600. const restartMsg = await HttpUtil.post("/panel/setting/restartPanel");
  601. this.loading(false);
  602. if (restartMsg.success) {
  603. this.loading(true);
  604. await PromiseUtil.sleep(5000);
  605. location.reload();
  606. }
  607. }
  608. });
  609. fileInput.click();
  610. },
  611. },
  612. async mounted() {
  613. let retries = 0;
  614. while (retries < 5) {
  615. try {
  616. await this.getStatus();
  617. retries = 0;
  618. } catch (e) {
  619. console.error("Error occurred while fetching status:", e);
  620. retries++;
  621. }
  622. await PromiseUtil.sleep(2000);
  623. }
  624. },
  625. });
  626. </script>
  627. </body>
  628. </html>