index.html 29 KB

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