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