1
0

index.html 29 KB

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