index.html 23 KB

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