index.html 26 KB

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