index.html 26 KB

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