index.html 29 KB

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