index.html 29 KB

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