index.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  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="siderDrawer.isDarkTheme ? bgDarkStyle : ''">
  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="siderDrawer.isDarkTheme ? darkClass : ''">
  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="siderDrawer.isDarkTheme ? darkClass : ''"
  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="siderDrawer.isDarkTheme ? darkClass : ''"
  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="siderDrawer.isDarkTheme ? darkClass : ''"
  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="siderDrawer.isDarkTheme ? darkClass : ''"
  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="siderDrawer.isDarkTheme ? darkClass : ''">
  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="siderDrawer.isDarkTheme ? darkClass : ''">
  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="siderDrawer.isDarkTheme ? darkClass : ''">
  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="siderDrawer.isDarkTheme ? darkClass : ''">
  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="siderDrawer.isDarkTheme ? darkClass : ''">
  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="siderDrawer.isDarkTheme ? darkClass : ''">
  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="siderDrawer.isDarkTheme ? darkClass : ''">
  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="siderDrawer.isDarkTheme ? darkClass : ''">
  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="siderDrawer.isDarkTheme ? darkClass : ''"
  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="siderDrawer.isDarkTheme ? darkClass : ''"
  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="siderDrawer.isDarkTheme ? 'ant-card-dark' : ''">
  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="siderDrawer.isDarkTheme ? darkClass : ''"
  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 "textModal"}}
  251. <script>
  252. const State = {
  253. Running: "running",
  254. Stop: "stop",
  255. Error: "error",
  256. }
  257. Object.freeze(State);
  258. class CurTotal {
  259. constructor(current, total) {
  260. this.current = current;
  261. this.total = total;
  262. }
  263. get percent() {
  264. if (this.total === 0) {
  265. return 0;
  266. }
  267. return toFixed(this.current / this.total * 100, 2);
  268. }
  269. get color() {
  270. const percent = this.percent;
  271. if (percent < 80) {
  272. return '#67C23A';
  273. } else if (percent < 90) {
  274. return '#E6A23C';
  275. } else {
  276. return '#F56C6C';
  277. }
  278. }
  279. }
  280. class Status {
  281. constructor(data) {
  282. this.cpu = new CurTotal(0, 0);
  283. this.disk = new CurTotal(0, 0);
  284. this.loads = [0, 0, 0];
  285. this.mem = new CurTotal(0, 0);
  286. this.netIO = {up: 0, down: 0};
  287. this.netTraffic = {sent: 0, recv: 0};
  288. this.swap = new CurTotal(0, 0);
  289. this.tcpCount = 0;
  290. this.udpCount = 0;
  291. this.uptime = 0;
  292. this.xray = {state: State.Stop, errorMsg: "", version: "", color: ""};
  293. if (data == null) {
  294. return;
  295. }
  296. this.cpu = new CurTotal(data.cpu, 100);
  297. this.disk = new CurTotal(data.disk.current, data.disk.total);
  298. this.loads = data.loads.map(load => toFixed(load, 2));
  299. this.mem = new CurTotal(data.mem.current, data.mem.total);
  300. this.netIO = data.netIO;
  301. this.netTraffic = data.netTraffic;
  302. this.swap = new CurTotal(data.swap.current, data.swap.total);
  303. this.tcpCount = data.tcpCount;
  304. this.udpCount = data.udpCount;
  305. this.uptime = data.uptime;
  306. this.xray = data.xray;
  307. switch (this.xray.state) {
  308. case State.Running:
  309. this.xray.color = "green";
  310. break;
  311. case State.Stop:
  312. this.xray.color = "orange";
  313. break;
  314. case State.Error:
  315. this.xray.color = "red";
  316. break;
  317. default:
  318. this.xray.color = "gray";
  319. }
  320. }
  321. }
  322. const versionModal = {
  323. visible: false,
  324. versions: [],
  325. show(versions) {
  326. this.visible = true;
  327. this.versions = versions;
  328. },
  329. hide() {
  330. this.visible = false;
  331. },
  332. };
  333. const logModal = {
  334. visible: false,
  335. logs: '',
  336. rows: 20,
  337. show(logs, rows) {
  338. this.visible = true;
  339. this.rows = rows;
  340. this.logs = logs.join("\n");
  341. },
  342. hide() {
  343. this.visible = false;
  344. },
  345. };
  346. const backupModal = {
  347. visible: false,
  348. title: '',
  349. description: '',
  350. exportText: '',
  351. importText: '',
  352. show({
  353. title = '{{ i18n "pages.index.backupTitle" }}',
  354. description = '{{ i18n "pages.index.backupDescription" }}',
  355. exportText = '{{ i18n "pages.index.exportDatabase" }}',
  356. importText = '{{ i18n "pages.index.importDatabase" }}',
  357. }) {
  358. this.title = title;
  359. this.description = description;
  360. this.exportText = exportText;
  361. this.importText = importText;
  362. this.visible = true;
  363. },
  364. hide() {
  365. this.visible = false;
  366. },
  367. };
  368. const app = new Vue({
  369. delimiters: ['[[', ']]'],
  370. el: '#app',
  371. data: {
  372. siderDrawer,
  373. status: new Status(),
  374. versionModal,
  375. logModal,
  376. backupModal,
  377. spinning: false,
  378. loadingTip: '{{ i18n "loading"}}',
  379. },
  380. methods: {
  381. loading(spinning, tip = '{{ i18n "loading"}}') {
  382. this.spinning = spinning;
  383. this.loadingTip = tip;
  384. },
  385. async getStatus() {
  386. const msg = await HttpUtil.post('/server/status');
  387. if (msg.success) {
  388. this.setStatus(msg.obj);
  389. }
  390. },
  391. setStatus(data) {
  392. this.status = new Status(data);
  393. },
  394. async openSelectV2rayVersion() {
  395. this.loading(true);
  396. const msg = await HttpUtil.post('server/getXrayVersion');
  397. this.loading(false);
  398. if (!msg.success) {
  399. return;
  400. }
  401. versionModal.show(msg.obj);
  402. },
  403. switchV2rayVersion(version) {
  404. this.$confirm({
  405. title: '{{ i18n "pages.index.xraySwitchVersionDialog"}}',
  406. content: '{{ i18n "pages.index.xraySwitchVersionDialogDesc"}}' + ` ${version}?`,
  407. okText: '{{ i18n "confirm"}}',
  408. class: siderDrawer.isDarkTheme ? darkClass : '',
  409. cancelText: '{{ i18n "cancel"}}',
  410. onOk: async () => {
  411. versionModal.hide();
  412. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  413. await HttpUtil.post(`/server/installXray/${version}`);
  414. this.loading(false);
  415. },
  416. });
  417. },
  418. async stopXrayService() {
  419. this.loading(true);
  420. const msg = await HttpUtil.post('server/stopXrayService');
  421. this.loading(false);
  422. if (!msg.success) {
  423. return;
  424. }
  425. },
  426. async restartXrayService() {
  427. this.loading(true);
  428. const msg = await HttpUtil.post('server/restartXrayService');
  429. this.loading(false);
  430. if (!msg.success) {
  431. return;
  432. }
  433. },
  434. async openLogs(rows){
  435. this.loading(true);
  436. const msg = await HttpUtil.post('server/logs/'+rows);
  437. this.loading(false);
  438. if (!msg.success) {
  439. return;
  440. }
  441. logModal.show(msg.obj, rows);
  442. },
  443. async openConfig() {
  444. this.loading(true);
  445. const msg = await HttpUtil.post('server/getConfigJson');
  446. this.loading(false);
  447. if (!msg.success) {
  448. return;
  449. }
  450. txtModal.show('config.json', JSON.stringify(msg.obj, null, 2), 'config.json');
  451. },
  452. openBackup() {
  453. backupModal.show({
  454. title: '{{ i18n "pages.index.backupTitle" }}',
  455. description: '{{ i18n "pages.index.backupDescription" }}',
  456. exportText: '{{ i18n "pages.index.exportDatabase" }}',
  457. importText: '{{ i18n "pages.index.importDatabase" }}',
  458. });
  459. },
  460. exportDatabase() {
  461. window.location = basePath + 'server/getDb';
  462. },
  463. importDatabase() {
  464. const fileInput = document.createElement('input');
  465. fileInput.type = 'file';
  466. fileInput.accept = '.db';
  467. fileInput.addEventListener('change', async (event) => {
  468. const dbFile = event.target.files[0];
  469. if (dbFile) {
  470. const formData = new FormData();
  471. formData.append('db', dbFile);
  472. backupModal.hide();
  473. this.loading(true);
  474. const uploadMsg = await HttpUtil.post('server/importDB', formData, {
  475. headers: {
  476. 'Content-Type': 'multipart/form-data',
  477. }
  478. });
  479. this.loading(false);
  480. if (!uploadMsg.success) {
  481. return;
  482. }
  483. this.loading(true);
  484. const restartMsg = await HttpUtil.post("/xui/setting/restartPanel");
  485. this.loading(false);
  486. if (restartMsg.success) {
  487. this.loading(true);
  488. await PromiseUtil.sleep(5000);
  489. location.reload();
  490. }
  491. }
  492. });
  493. fileInput.click();
  494. },
  495. },
  496. async mounted() {
  497. while (true) {
  498. try {
  499. await this.getStatus();
  500. } catch (e) {
  501. console.error(e);
  502. }
  503. await PromiseUtil.sleep(2000);
  504. }
  505. },
  506. });
  507. </script>
  508. </body>
  509. </html>