index.html 27 KB

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