index.html 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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>CPU: [[ cpuCoreFormat(status.cpuCores) ]]</div>
  35. <div>Speed: [[ cpuSpeedFormat(status.cpuSpeedMhz) ]]</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: <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. <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(logModal.rows, logModal.logLevel)">{{ 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, logModal.logLevel)"
  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 label="Log Level">
  260. <a-select v-model="logModal.logLevel"
  261. style="width: 120px"
  262. @change="openLogs(logModal.rows, logModal.logLevel)"
  263. :dropdown-class-name="themeSwitcher.darkCardClass">
  264. <a-select-option value="debug">Debug</a-select-option>
  265. <a-select-option value="info">Info</a-select-option>
  266. <a-select-option value="notice">Notice</a-select-option>
  267. <a-select-option value="warning">Warning</a-select-option>
  268. <a-select-option value="err">Error</a-select-option>
  269. </a-select>
  270. </a-form-item>
  271. <a-form-item>
  272. <button class="ant-btn ant-btn-primary" @click="openLogs(logModal.rows, logModal.logLevel)"><a-icon type="sync"></a-icon> Reload</button>
  273. </a-form-item>
  274. <a-form-item>
  275. <a-button type="primary" style="margin-bottom: 10px;"
  276. :href="'data:application/text;charset=utf-8,' + encodeURIComponent(logModal.logs)" download="x-ui.log">
  277. {{ i18n "download" }} x-ui.log
  278. </a-button>
  279. </a-form-item>
  280. </a-form>
  281. <a-input type="textarea" v-model="logModal.logs" disabled="true"
  282. :autosize="{ minRows: 10, maxRows: 22}"></a-input>
  283. </a-modal>
  284. <a-modal id="backup-modal" v-model="backupModal.visible" :title="backupModal.title"
  285. :closable="true" :class="themeSwitcher.darkCardClass"
  286. @ok="() => backupModal.hide()" @cancel="() => backupModal.hide()">
  287. <p style="color: inherit; font-size: 16px; padding: 4px 2px;">
  288. <a-icon type="warning" style="color: inherit; font-size: 20px;"></a-icon>
  289. [[ backupModal.description ]]
  290. </p>
  291. <a-space direction="horizontal" style="text-align: center" style="margin-bottom: 10px;">
  292. <a-button type="primary" @click="exportDatabase()">
  293. [[ backupModal.exportText ]]
  294. </a-button>
  295. <a-button type="primary" @click="importDatabase()">
  296. [[ backupModal.importText ]]
  297. </a-button>
  298. </a-space>
  299. </a-modal>
  300. </a-layout>
  301. {{template "js" .}}
  302. {{template "component/themeSwitcher" .}}
  303. {{template "textModal"}}
  304. <script>
  305. const State = {
  306. Running: "running",
  307. Stop: "stop",
  308. Error: "error",
  309. }
  310. Object.freeze(State);
  311. class CurTotal {
  312. constructor(current, total) {
  313. this.current = current;
  314. this.total = total;
  315. }
  316. get percent() {
  317. if (this.total === 0) {
  318. return 0;
  319. }
  320. return toFixed(this.current / this.total * 100, 2);
  321. }
  322. get color() {
  323. const percent = this.percent;
  324. if (percent < 80) {
  325. return '#67C23A';
  326. } else if (percent < 90) {
  327. return '#E6A23C';
  328. } else {
  329. return '#F56C6C';
  330. }
  331. }
  332. }
  333. class Status {
  334. constructor(data) {
  335. this.cpu = new CurTotal(0, 0);
  336. this.cpuCores = 0;
  337. this.cpuSpeedMhz = 0;
  338. this.disk = new CurTotal(0, 0);
  339. this.loads = [0, 0, 0];
  340. this.mem = new CurTotal(0, 0);
  341. this.netIO = { up: 0, down: 0 };
  342. this.netTraffic = { sent: 0, recv: 0 };
  343. this.publicIP = { ipv4: 0, ipv6: 0 };
  344. this.swap = new CurTotal(0, 0);
  345. this.tcpCount = 0;
  346. this.udpCount = 0;
  347. this.uptime = 0;
  348. this.xray = { state: State.Stop, errorMsg: "", version: "", color: "" };
  349. if (data == null) {
  350. return;
  351. }
  352. this.cpu = new CurTotal(data.cpu, 100);
  353. this.cpuCores = data.cpuCores;
  354. this.cpuSpeedMhz = data.cpuSpeedMhz;
  355. this.disk = new CurTotal(data.disk.current, data.disk.total);
  356. this.loads = data.loads.map(load => toFixed(load, 2));
  357. this.mem = new CurTotal(data.mem.current, data.mem.total);
  358. this.netIO = data.netIO;
  359. this.netTraffic = data.netTraffic;
  360. this.publicIP = data.publicIP;
  361. this.swap = new CurTotal(data.swap.current, data.swap.total);
  362. this.tcpCount = data.tcpCount;
  363. this.udpCount = data.udpCount;
  364. this.uptime = data.uptime;
  365. this.xray = data.xray;
  366. switch (this.xray.state) {
  367. case State.Running:
  368. this.xray.color = "green";
  369. break;
  370. case State.Stop:
  371. this.xray.color = "orange";
  372. break;
  373. case State.Error:
  374. this.xray.color = "red";
  375. break;
  376. default:
  377. this.xray.color = "gray";
  378. }
  379. }
  380. }
  381. const versionModal = {
  382. visible: false,
  383. versions: [],
  384. show(versions) {
  385. this.visible = true;
  386. this.versions = versions;
  387. },
  388. hide() {
  389. this.visible = false;
  390. },
  391. };
  392. const logModal = {
  393. visible: false,
  394. logs: '',
  395. rows: 20,
  396. logLevel: 'info',
  397. show(logs, rows) {
  398. this.visible = true;
  399. this.rows = rows;
  400. this.logs = logs.join("\n");
  401. },
  402. hide() {
  403. this.visible = false;
  404. },
  405. };
  406. const backupModal = {
  407. visible: false,
  408. title: '',
  409. description: '',
  410. exportText: '',
  411. importText: '',
  412. show({
  413. title = '{{ i18n "pages.index.backupTitle" }}',
  414. description = '{{ i18n "pages.index.backupDescription" }}',
  415. exportText = '{{ i18n "pages.index.exportDatabase" }}',
  416. importText = '{{ i18n "pages.index.importDatabase" }}',
  417. }) {
  418. this.title = title;
  419. this.description = description;
  420. this.exportText = exportText;
  421. this.importText = importText;
  422. this.visible = true;
  423. },
  424. hide() {
  425. this.visible = false;
  426. },
  427. };
  428. const app = new Vue({
  429. delimiters: ['[[', ']]'],
  430. el: '#app',
  431. data: {
  432. siderDrawer,
  433. themeSwitcher,
  434. status: new Status(),
  435. versionModal,
  436. logModal,
  437. backupModal,
  438. spinning: false,
  439. loadingTip: '{{ i18n "loading"}}',
  440. },
  441. methods: {
  442. loading(spinning, tip = '{{ i18n "loading"}}') {
  443. this.spinning = spinning;
  444. this.loadingTip = tip;
  445. },
  446. async getStatus() {
  447. try {
  448. const msg = await HttpUtil.post('/server/status');
  449. if (msg.success) {
  450. this.setStatus(msg.obj);
  451. }
  452. } catch (e) {
  453. console.error("Failed to get status:", e);
  454. }
  455. },
  456. setStatus(data) {
  457. this.status = new Status(data);
  458. },
  459. async openSelectV2rayVersion() {
  460. this.loading(true);
  461. const msg = await HttpUtil.post('server/getXrayVersion');
  462. this.loading(false);
  463. if (!msg.success) {
  464. return;
  465. }
  466. versionModal.show(msg.obj);
  467. },
  468. switchV2rayVersion(version) {
  469. this.$confirm({
  470. title: '{{ i18n "pages.index.xraySwitchVersionDialog"}}',
  471. content: '{{ i18n "pages.index.xraySwitchVersionDialogDesc"}}' + ` ${version}?`,
  472. okText: '{{ i18n "confirm"}}',
  473. class: themeSwitcher.darkCardClass,
  474. cancelText: '{{ i18n "cancel"}}',
  475. onOk: async () => {
  476. versionModal.hide();
  477. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  478. await HttpUtil.post(`/server/installXray/${version}`);
  479. this.loading(false);
  480. },
  481. });
  482. },
  483. async stopXrayService() {
  484. this.loading(true);
  485. const msg = await HttpUtil.post('server/stopXrayService');
  486. this.loading(false);
  487. if (!msg.success) {
  488. return;
  489. }
  490. },
  491. async restartXrayService() {
  492. this.loading(true);
  493. const msg = await HttpUtil.post('server/restartXrayService');
  494. this.loading(false);
  495. if (!msg.success) {
  496. return;
  497. }
  498. },
  499. async openLogs(rows, logLevel) {
  500. this.loading(true);
  501. const msg = await HttpUtil.post('server/logs/' + rows, { logLevel: `${logLevel}` });
  502. this.loading(false);
  503. if (!msg.success) {
  504. return;
  505. }
  506. logModal.show(msg.obj, rows);
  507. },
  508. async openConfig() {
  509. this.loading(true);
  510. const msg = await HttpUtil.post('server/getConfigJson');
  511. this.loading(false);
  512. if (!msg.success) {
  513. return;
  514. }
  515. txtModal.show('config.json', JSON.stringify(msg.obj, null, 2), 'config.json');
  516. },
  517. openBackup() {
  518. backupModal.show({
  519. title: '{{ i18n "pages.index.backupTitle" }}',
  520. description: '{{ i18n "pages.index.backupDescription" }}',
  521. exportText: '{{ i18n "pages.index.exportDatabase" }}',
  522. importText: '{{ i18n "pages.index.importDatabase" }}',
  523. });
  524. },
  525. exportDatabase() {
  526. window.location = basePath + 'server/getDb';
  527. },
  528. importDatabase() {
  529. const fileInput = document.createElement('input');
  530. fileInput.type = 'file';
  531. fileInput.accept = '.db';
  532. fileInput.addEventListener('change', async (event) => {
  533. const dbFile = event.target.files[0];
  534. if (dbFile) {
  535. const formData = new FormData();
  536. formData.append('db', dbFile);
  537. backupModal.hide();
  538. this.loading(true);
  539. const uploadMsg = await HttpUtil.post('server/importDB', formData, {
  540. headers: {
  541. 'Content-Type': 'multipart/form-data',
  542. }
  543. });
  544. this.loading(false);
  545. if (!uploadMsg.success) {
  546. return;
  547. }
  548. this.loading(true);
  549. const restartMsg = await HttpUtil.post("/panel/setting/restartPanel");
  550. this.loading(false);
  551. if (restartMsg.success) {
  552. this.loading(true);
  553. await PromiseUtil.sleep(5000);
  554. location.reload();
  555. }
  556. }
  557. });
  558. fileInput.click();
  559. },
  560. },
  561. async mounted() {
  562. let retries = 0;
  563. while (retries < 5) {
  564. try {
  565. await this.getStatus();
  566. retries = 0;
  567. } catch (e) {
  568. console.error("Error occurred while fetching status:", e);
  569. retries++;
  570. }
  571. await PromiseUtil.sleep(2000);
  572. }
  573. },
  574. });
  575. </script>
  576. </body>
  577. </html>