index.html 29 KB

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