index.html 30 KB

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