index.html 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  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. }
  10. .ant-col-sm-24 {
  11. margin-top: 10px;
  12. }
  13. .ant-card-dark h2 {
  14. color: hsla(0, 0%, 100%, .65);
  15. }
  16. </style>
  17. <body>
  18. <a-layout id="app" v-cloak>
  19. {{ template "commonSider" . }}
  20. <a-layout id="content-layout" :style="themeSwitcher.bgStyle">
  21. <a-layout-content>
  22. <a-spin :spinning="spinning" :delay="200" :tip="loadingTip"/>
  23. <transition name="list" appear>
  24. <a-row>
  25. <a-card hoverable :class="themeSwitcher.darkCardClass">
  26. <a-row>
  27. <a-col :sm="24" :md="12">
  28. <a-row>
  29. <a-col :span="12" style="text-align: center">
  30. <a-progress type="dashboard" status="normal"
  31. :stroke-color="status.cpu.color"
  32. :class="themeSwitcher.darkCardClass"
  33. :percent="status.cpu.percent"></a-progress>
  34. <div>Cores: [[ status.cpuCores ]]</div>
  35. <div>Logical Procs: [[ status.logicalProcessors ]]</div>
  36. </a-col>
  37. <a-col :span="12" style="text-align: center">
  38. <a-progress type="dashboard" status="normal"
  39. :stroke-color="status.mem.color"
  40. :class="themeSwitcher.darkCardClass"
  41. :percent="status.mem.percent"></a-progress>
  42. <div>
  43. {{ i18n "pages.index.memory"}}: [[ sizeFormat(status.mem.current) ]] / [[ sizeFormat(status.mem.total) ]]
  44. </div>
  45. </a-col>
  46. </a-row>
  47. </a-col>
  48. <a-col :sm="24" :md="12">
  49. <a-row>
  50. <a-col :span="12" style="text-align: center">
  51. <a-progress type="dashboard" status="normal"
  52. :stroke-color="status.swap.color"
  53. :class="themeSwitcher.darkCardClass"
  54. :percent="status.swap.percent"></a-progress>
  55. <div>
  56. Swap: [[ sizeFormat(status.swap.current) ]] / [[ sizeFormat(status.swap.total) ]]
  57. </div>
  58. </a-col>
  59. <a-col :span="12" style="text-align: center">
  60. <a-progress type="dashboard" status="normal"
  61. :stroke-color="status.disk.color"
  62. :class="themeSwitcher.darkCardClass"
  63. :percent="status.disk.percent"></a-progress>
  64. <div>
  65. {{ i18n "pages.index.hard"}}: [[ sizeFormat(status.disk.current) ]] / [[ sizeFormat(status.disk.total) ]]
  66. </div>
  67. </a-col>
  68. </a-row>
  69. </a-col>
  70. </a-row>
  71. </a-card>
  72. </a-row>
  73. </transition>
  74. <transition name="list" appear>
  75. <a-row>
  76. <a-col :sm="24" :md="12">
  77. <a-card hoverable :class="themeSwitcher.darkCardClass">
  78. 3x-ui: <a href="https://github.com/MHSanaei/3x-ui/releases" target="_blank"><a-tag color="green">v{{ .cur_ver }}</a-tag></a>
  79. Xray: <a-tag color="green" style="cursor: pointer;" @click="openSelectV2rayVersion">v[[ status.xray.version ]]</a-tag>
  80. Telegram: <a href="https://t.me/panel3xui" target="_blank"><a-tag color="green">@panel3xui</a-tag></a>
  81. </a-card>
  82. </a-col>
  83. <a-col :sm="24" :md="12">
  84. <a-card hoverable :class="themeSwitcher.darkCardClass">
  85. {{ i18n "menu.link" }}:
  86. <a-tag color="blue" style="cursor: pointer;" @click="openLogs(20)">{{ i18n "pages.index.logs" }}</a-tag>
  87. <a-tag color="blue" style="cursor: pointer;" @click="openConfig">{{ i18n "pages.index.config" }}</a-tag>
  88. <a-tag color="blue" style="cursor: pointer;" @click="openBackup">{{ i18n "pages.index.backup" }}</a-tag>
  89. </a-card>
  90. </a-col>
  91. <a-col :sm="24" :md="12">
  92. <a-card hoverable :class="themeSwitcher.darkCardClass">
  93. {{ i18n "pages.index.xrayStatus" }}:
  94. <a-tag :color="status.xray.color">[[ status.xray.state ]]</a-tag>
  95. <a-tooltip v-if="status.xray.state === State.Error">
  96. <template slot="title">
  97. <p v-for="line in status.xray.errorMsg.split('\n')">[[ line ]]</p>
  98. </template>
  99. <a-icon type="question-circle" theme="filled"></a-icon>
  100. </a-tooltip>
  101. <a-tag color="blue" style="cursor: pointer;" @click="stopXrayService">{{ i18n "pages.index.stopXray" }}</a-tag>
  102. <a-tag color="blue" style="cursor: pointer;" @click="restartXrayService">{{ i18n "pages.index.restartXray" }}</a-tag>
  103. <a-tag color="blue" style="cursor: pointer;" @click="openSelectV2rayVersion">{{ i18n "pages.index.xraySwitch" }}</a-tag>
  104. </a-card>
  105. </a-col>
  106. <a-col :sm="24" :md="12">
  107. <a-card hoverable :class="themeSwitcher.darkCardClass">
  108. <a-row>
  109. <a-col :span="12">
  110. {{ i18n "pages.index.systemLoad" }}: [[ status.loads[0] ]] | [[ status.loads[1] ]] | [[ status.loads[2] ]]
  111. <a-tooltip>
  112. <template slot="title">
  113. {{ i18n "pages.index.systemLoadDesc" }}
  114. </template>
  115. <a-icon type="question-circle" theme="filled"></a-icon>
  116. </a-tooltip>
  117. </a-col>
  118. <a-col :span="12">
  119. {{ i18n "pages.index.operationHours" }}:
  120. <a-tag color="green">[[ formatSecond(status.uptime) ]]</a-tag>
  121. </a-col>
  122. </a-row>
  123. </a-card>
  124. </a-col>
  125. <a-col :sm="24" :md="12">
  126. <a-card hoverable :class="themeSwitcher.darkCardClass">
  127. <a-row>
  128. <a-col :span="12">
  129. ipv4:
  130. <a-tooltip>
  131. <template slot="title">
  132. [[ status.publicIP.ipv4 ]]
  133. </template>
  134. <a-icon type="question-circle" theme="filled"></a-icon>
  135. </a-tooltip>
  136. </a-col>
  137. <a-col :span="12">
  138. ipv6:
  139. <a-tooltip>
  140. <template slot="title">
  141. [[ status.publicIP.ipv6 ]]
  142. </template>
  143. <a-icon type="question-circle" theme="filled"></a-icon>
  144. </a-tooltip>
  145. </a-col>
  146. </a-row>
  147. </a-card>
  148. </a-col>
  149. <a-col :sm="24" :md="12">
  150. <a-card hoverable :class="themeSwitcher.darkCardClass">
  151. <a-row>
  152. <a-col :span="12">
  153. TCP: [[ status.tcpCount ]]
  154. <a-tooltip>
  155. <template slot="title">
  156. {{ i18n "pages.index.connectionTcpCountDesc" }}
  157. </template>
  158. <a-icon type="question-circle" theme="filled"></a-icon>
  159. </a-tooltip>
  160. </a-col>
  161. <a-col :span="12">
  162. UDP: [[ status.udpCount ]]
  163. <a-tooltip>
  164. <template slot="title">
  165. {{ i18n "pages.index.connectionUdpCountDesc" }}
  166. </template>
  167. <a-icon type="question-circle" theme="filled"></a-icon>
  168. </a-tooltip>
  169. </a-col>
  170. </a-row>
  171. </a-card>
  172. </a-col>
  173. <a-col :sm="24" :md="12">
  174. <a-card hoverable :class="themeSwitcher.darkCardClass">
  175. <a-row>
  176. <a-col :span="12">
  177. <a-icon type="arrow-up"></a-icon>
  178. [[ sizeFormat(status.netIO.up) ]] / S
  179. <a-tooltip>
  180. <template slot="title">
  181. {{ i18n "pages.index.upSpeed" }}
  182. </template>
  183. <a-icon type="question-circle" theme="filled"></a-icon>
  184. </a-tooltip>
  185. </a-col>
  186. <a-col :span="12">
  187. <a-icon type="arrow-down"></a-icon>
  188. [[ sizeFormat(status.netIO.down) ]] / S
  189. <a-tooltip>
  190. <template slot="title">
  191. {{ i18n "pages.index.downSpeed" }}
  192. </template>
  193. <a-icon type="question-circle" theme="filled"></a-icon>
  194. </a-tooltip>
  195. </a-col>
  196. </a-row>
  197. </a-card>
  198. </a-col>
  199. <a-col :sm="24" :md="12">
  200. <a-card hoverable :class="themeSwitcher.darkCardClass">
  201. <a-row>
  202. <a-col :span="12">
  203. <a-icon type="cloud-upload"></a-icon>
  204. [[ sizeFormat(status.netTraffic.sent) ]]
  205. <a-tooltip>
  206. <template slot="title">
  207. {{ i18n "pages.index.totalSent" }}
  208. </template>
  209. <a-icon type="question-circle" theme="filled"></a-icon>
  210. </a-tooltip>
  211. </a-col>
  212. <a-col :span="12">
  213. <a-icon type="cloud-download"></a-icon>
  214. [[ sizeFormat(status.netTraffic.recv) ]]
  215. <a-tooltip>
  216. <template slot="title">
  217. {{ i18n "pages.index.totalReceive" }}
  218. </template>
  219. <a-icon type="question-circle" theme="filled"></a-icon>
  220. </a-tooltip>
  221. </a-col>
  222. </a-row>
  223. </a-card>
  224. </a-col>
  225. </a-row>
  226. </transition>
  227. </a-layout-content>
  228. </a-layout>
  229. <a-modal id="version-modal" v-model="versionModal.visible" title='{{ i18n "pages.index.xraySwitch" }}'
  230. :closable="true" @ok="() => versionModal.visible = false"
  231. :class="themeSwitcher.darkCardClass"
  232. footer="">
  233. <h2>{{ i18n "pages.index.xraySwitchClick"}}</h2>
  234. <h2>{{ i18n "pages.index.xraySwitchClickDesk"}}</h2>
  235. <template v-for="version, index in versionModal.versions">
  236. <a-tag :color="index % 2 == 0 ? 'blue' : 'green'"
  237. style="margin: 10px" @click="switchV2rayVersion(version)">
  238. [[ version ]]
  239. </a-tag>
  240. </template>
  241. </a-modal>
  242. <a-modal id="log-modal" v-model="logModal.visible" title="X-UI logs"
  243. :closable="true" @ok="() => logModal.visible = false" @cancel="() => logModal.visible = false"
  244. :class="themeSwitcher.darkCardClass"
  245. width="800px"
  246. footer="">
  247. <a-form layout="inline">
  248. <a-form-item label="Count">
  249. <a-select v-model="logModal.rows"
  250. style="width: 80px"
  251. @change="openLogs(logModal.rows)"
  252. :dropdown-class-name="themeSwitcher.darkCardClass">
  253. <a-select-option value="10">10</a-select-option>
  254. <a-select-option value="20">20</a-select-option>
  255. <a-select-option value="50">50</a-select-option>
  256. <a-select-option value="100">100</a-select-option>
  257. </a-select>
  258. </a-form-item>
  259. <a-form-item>
  260. <button class="ant-btn ant-btn-primary" @click="openLogs(logModal.rows)"><a-icon type="sync"></a-icon> Reload</button>
  261. </a-form-item>
  262. <a-form-item>
  263. <a-button type="primary" style="margin-bottom: 10px;"
  264. :href="'data:application/text;charset=utf-8,' + encodeURIComponent(logModal.logs)" download="x-ui.log">
  265. {{ i18n "download" }} x-ui.log
  266. </a-button>
  267. </a-form-item>
  268. </a-form>
  269. <a-input type="textarea" v-model="logModal.logs" disabled="true"
  270. :autosize="{ minRows: 10, maxRows: 22}"></a-input>
  271. </a-modal>
  272. <a-modal id="backup-modal" v-model="backupModal.visible" :title="backupModal.title"
  273. :closable="true" :class="themeSwitcher.darkCardClass"
  274. @ok="() => backupModal.hide()" @cancel="() => backupModal.hide()">
  275. <p style="color: inherit; font-size: 16px; padding: 4px 2px;">
  276. <a-icon type="warning" style="color: inherit; font-size: 20px;"></a-icon>
  277. [[ backupModal.description ]]
  278. </p>
  279. <a-space direction="horizontal" style="text-align: center" style="margin-bottom: 10px;">
  280. <a-button type="primary" @click="exportDatabase()">
  281. [[ backupModal.exportText ]]
  282. </a-button>
  283. <a-button type="primary" @click="importDatabase()">
  284. [[ backupModal.importText ]]
  285. </a-button>
  286. </a-space>
  287. </a-modal>
  288. </a-layout>
  289. {{template "js" .}}
  290. {{template "component/themeSwitcher" .}}
  291. {{template "textModal"}}
  292. <script>
  293. const State = {
  294. Running: "running",
  295. Stop: "stop",
  296. Error: "error",
  297. }
  298. Object.freeze(State);
  299. class CurTotal {
  300. constructor(current, total) {
  301. this.current = current;
  302. this.total = total;
  303. }
  304. get percent() {
  305. if (this.total === 0) {
  306. return 0;
  307. }
  308. return toFixed(this.current / this.total * 100, 2);
  309. }
  310. get color() {
  311. const percent = this.percent;
  312. if (percent < 80) {
  313. return '#67C23A';
  314. } else if (percent < 90) {
  315. return '#E6A23C';
  316. } else {
  317. return '#F56C6C';
  318. }
  319. }
  320. }
  321. class Status {
  322. constructor(data) {
  323. this.cpu = new CurTotal(0, 0);
  324. this.disk = new CurTotal(0, 0);
  325. this.loads = [0, 0, 0];
  326. this.mem = new CurTotal(0, 0);
  327. this.netIO = { up: 0, down: 0 };
  328. this.netTraffic = { sent: 0, recv: 0 };
  329. this.publicIP = { ipv4: 0, ipv6: 0 };
  330. this.swap = new CurTotal(0, 0);
  331. this.tcpCount = 0;
  332. this.udpCount = 0;
  333. this.cpuCores = 0;
  334. this.logicalProcessors = 0;
  335. this.uptime = 0;
  336. this.xray = { state: State.Stop, errorMsg: "", version: "", color: "" };
  337. if (data == null) {
  338. return;
  339. }
  340. this.cpu = new CurTotal(data.cpu, 100);
  341. this.disk = new CurTotal(data.disk.current, data.disk.total);
  342. this.loads = data.loads.map(load => toFixed(load, 2));
  343. this.mem = new CurTotal(data.mem.current, data.mem.total);
  344. this.netIO = data.netIO;
  345. this.netTraffic = data.netTraffic;
  346. this.publicIP = data.publicIP;
  347. this.swap = new CurTotal(data.swap.current, data.swap.total);
  348. this.tcpCount = data.tcpCount;
  349. this.udpCount = data.udpCount;
  350. this.cpuCores = data.cpuCores;
  351. this.logicalProcessors = data.logicalProcessors;
  352. this.uptime = data.uptime;
  353. this.xray = data.xray;
  354. switch (this.xray.state) {
  355. case State.Running:
  356. this.xray.color = "green";
  357. break;
  358. case State.Stop:
  359. this.xray.color = "orange";
  360. break;
  361. case State.Error:
  362. this.xray.color = "red";
  363. break;
  364. default:
  365. this.xray.color = "gray";
  366. }
  367. }
  368. }
  369. const versionModal = {
  370. visible: false,
  371. versions: [],
  372. show(versions) {
  373. this.visible = true;
  374. this.versions = versions;
  375. },
  376. hide() {
  377. this.visible = false;
  378. },
  379. };
  380. const logModal = {
  381. visible: false,
  382. logs: '',
  383. rows: 20,
  384. show(logs, rows) {
  385. this.visible = true;
  386. this.rows = rows;
  387. this.logs = logs.join("\n");
  388. },
  389. hide() {
  390. this.visible = false;
  391. },
  392. };
  393. const backupModal = {
  394. visible: false,
  395. title: '',
  396. description: '',
  397. exportText: '',
  398. importText: '',
  399. show({
  400. title = '{{ i18n "pages.index.backupTitle" }}',
  401. description = '{{ i18n "pages.index.backupDescription" }}',
  402. exportText = '{{ i18n "pages.index.exportDatabase" }}',
  403. importText = '{{ i18n "pages.index.importDatabase" }}',
  404. }) {
  405. this.title = title;
  406. this.description = description;
  407. this.exportText = exportText;
  408. this.importText = importText;
  409. this.visible = true;
  410. },
  411. hide() {
  412. this.visible = false;
  413. },
  414. };
  415. const app = new Vue({
  416. delimiters: ['[[', ']]'],
  417. el: '#app',
  418. data: {
  419. siderDrawer,
  420. themeSwitcher,
  421. status: new Status(),
  422. versionModal,
  423. logModal,
  424. backupModal,
  425. spinning: false,
  426. loadingTip: '{{ i18n "loading"}}',
  427. },
  428. methods: {
  429. loading(spinning, tip = '{{ i18n "loading"}}') {
  430. this.spinning = spinning;
  431. this.loadingTip = tip;
  432. },
  433. async getStatus() {
  434. const msg = await HttpUtil.post('/server/status');
  435. if (msg.success) {
  436. this.setStatus(msg.obj);
  437. }
  438. },
  439. setStatus(data) {
  440. this.status = new Status(data);
  441. },
  442. async openSelectV2rayVersion() {
  443. this.loading(true);
  444. const msg = await HttpUtil.post('server/getXrayVersion');
  445. this.loading(false);
  446. if (!msg.success) {
  447. return;
  448. }
  449. versionModal.show(msg.obj);
  450. },
  451. switchV2rayVersion(version) {
  452. this.$confirm({
  453. title: '{{ i18n "pages.index.xraySwitchVersionDialog"}}',
  454. content: '{{ i18n "pages.index.xraySwitchVersionDialogDesc"}}' + ` ${version}?`,
  455. okText: '{{ i18n "confirm"}}',
  456. class: themeSwitcher.darkCardClass,
  457. cancelText: '{{ i18n "cancel"}}',
  458. onOk: async () => {
  459. versionModal.hide();
  460. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  461. await HttpUtil.post(`/server/installXray/${version}`);
  462. this.loading(false);
  463. },
  464. });
  465. },
  466. async stopXrayService() {
  467. this.loading(true);
  468. const msg = await HttpUtil.post('server/stopXrayService');
  469. this.loading(false);
  470. if (!msg.success) {
  471. return;
  472. }
  473. },
  474. async restartXrayService() {
  475. this.loading(true);
  476. const msg = await HttpUtil.post('server/restartXrayService');
  477. this.loading(false);
  478. if (!msg.success) {
  479. return;
  480. }
  481. },
  482. async openLogs(rows) {
  483. this.loading(true);
  484. const msg = await HttpUtil.post('server/logs/' + rows);
  485. this.loading(false);
  486. if (!msg.success) {
  487. return;
  488. }
  489. logModal.show(msg.obj, rows);
  490. },
  491. async openConfig() {
  492. this.loading(true);
  493. const msg = await HttpUtil.post('server/getConfigJson');
  494. this.loading(false);
  495. if (!msg.success) {
  496. return;
  497. }
  498. txtModal.show('config.json', JSON.stringify(msg.obj, null, 2), 'config.json');
  499. },
  500. openBackup() {
  501. backupModal.show({
  502. title: '{{ i18n "pages.index.backupTitle" }}',
  503. description: '{{ i18n "pages.index.backupDescription" }}',
  504. exportText: '{{ i18n "pages.index.exportDatabase" }}',
  505. importText: '{{ i18n "pages.index.importDatabase" }}',
  506. });
  507. },
  508. exportDatabase() {
  509. window.location = basePath + 'server/getDb';
  510. },
  511. importDatabase() {
  512. const fileInput = document.createElement('input');
  513. fileInput.type = 'file';
  514. fileInput.accept = '.db';
  515. fileInput.addEventListener('change', async (event) => {
  516. const dbFile = event.target.files[0];
  517. if (dbFile) {
  518. const formData = new FormData();
  519. formData.append('db', dbFile);
  520. backupModal.hide();
  521. this.loading(true);
  522. const uploadMsg = await HttpUtil.post('server/importDB', formData, {
  523. headers: {
  524. 'Content-Type': 'multipart/form-data',
  525. }
  526. });
  527. this.loading(false);
  528. if (!uploadMsg.success) {
  529. return;
  530. }
  531. this.loading(true);
  532. const restartMsg = await HttpUtil.post("/panel/setting/restartPanel");
  533. this.loading(false);
  534. if (restartMsg.success) {
  535. this.loading(true);
  536. await PromiseUtil.sleep(5000);
  537. location.reload();
  538. }
  539. }
  540. });
  541. fileInput.click();
  542. },
  543. },
  544. async mounted() {
  545. while (true) {
  546. try {
  547. await this.getStatus();
  548. } catch (e) {
  549. console.error(e);
  550. }
  551. await PromiseUtil.sleep(2000);
  552. }
  553. },
  554. });
  555. </script>
  556. </body>
  557. </html>