index.html 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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. {{template "component/themeSwitcher" .}}
  314. {{template "textModal"}}
  315. <script>
  316. const State = {
  317. Running: "running",
  318. Stop: "stop",
  319. Error: "error",
  320. }
  321. Object.freeze(State);
  322. class CurTotal {
  323. constructor(current, total) {
  324. this.current = current;
  325. this.total = total;
  326. }
  327. get percent() {
  328. if (this.total === 0) {
  329. return 0;
  330. }
  331. return toFixed(this.current / this.total * 100, 2);
  332. }
  333. get color() {
  334. const percent = this.percent;
  335. if (percent < 80) {
  336. return '#0a7557';
  337. } else if (percent < 90) {
  338. return '#ffa031';
  339. } else {
  340. return '#e04141';
  341. }
  342. }
  343. }
  344. class Status {
  345. constructor(data) {
  346. this.cpu = new CurTotal(0, 0);
  347. this.cpuCores = 0;
  348. this.cpuSpeedMhz = 0;
  349. this.disk = new CurTotal(0, 0);
  350. this.loads = [0, 0, 0];
  351. this.mem = new CurTotal(0, 0);
  352. this.netIO = { up: 0, down: 0 };
  353. this.netTraffic = { sent: 0, recv: 0 };
  354. this.publicIP = { ipv4: 0, ipv6: 0 };
  355. this.swap = new CurTotal(0, 0);
  356. this.tcpCount = 0;
  357. this.udpCount = 0;
  358. this.uptime = 0;
  359. this.appUptime = 0;
  360. this.appStats = {threads: 0, mem: 0, uptime: 0};
  361. this.xray = { state: State.Stop, errorMsg: "", version: "", color: "" };
  362. if (data == null) {
  363. return;
  364. }
  365. this.cpu = new CurTotal(data.cpu, 100);
  366. this.cpuCores = data.cpuCores;
  367. this.cpuSpeedMhz = data.cpuSpeedMhz;
  368. this.disk = new CurTotal(data.disk.current, data.disk.total);
  369. this.loads = data.loads.map(load => toFixed(load, 2));
  370. this.mem = new CurTotal(data.mem.current, data.mem.total);
  371. this.netIO = data.netIO;
  372. this.netTraffic = data.netTraffic;
  373. this.publicIP = data.publicIP;
  374. this.swap = new CurTotal(data.swap.current, data.swap.total);
  375. this.tcpCount = data.tcpCount;
  376. this.udpCount = data.udpCount;
  377. this.uptime = data.uptime;
  378. this.appUptime = data.appUptime;
  379. this.appStats = data.appStats;
  380. this.xray = data.xray;
  381. switch (this.xray.state) {
  382. case State.Running:
  383. this.xray.color = "green";
  384. break;
  385. case State.Stop:
  386. this.xray.color = "orange";
  387. break;
  388. case State.Error:
  389. this.xray.color = "red";
  390. break;
  391. default:
  392. this.xray.color = "gray";
  393. }
  394. }
  395. }
  396. const versionModal = {
  397. visible: false,
  398. versions: [],
  399. show(versions) {
  400. this.visible = true;
  401. this.versions = versions;
  402. },
  403. hide() {
  404. this.visible = false;
  405. },
  406. };
  407. const logModal = {
  408. visible: false,
  409. logs: '',
  410. rows: 20,
  411. level: 'info',
  412. syslog: false,
  413. show(logs) {
  414. this.visible = true;
  415. this.logs = logs? logs.join("\n"): "No Record...";
  416. },
  417. hide() {
  418. this.visible = false;
  419. },
  420. };
  421. const backupModal = {
  422. visible: false,
  423. title: '',
  424. description: '',
  425. exportText: '',
  426. importText: '',
  427. show({
  428. title = '{{ i18n "pages.index.backupTitle" }}',
  429. description = '{{ i18n "pages.index.backupDescription" }}',
  430. exportText = '{{ i18n "pages.index.exportDatabase" }}',
  431. importText = '{{ i18n "pages.index.importDatabase" }}',
  432. }) {
  433. this.title = title;
  434. this.description = description;
  435. this.exportText = exportText;
  436. this.importText = importText;
  437. this.visible = true;
  438. },
  439. hide() {
  440. this.visible = false;
  441. },
  442. };
  443. const app = new Vue({
  444. delimiters: ['[[', ']]'],
  445. el: '#app',
  446. data: {
  447. siderDrawer,
  448. themeSwitcher,
  449. status: new Status(),
  450. versionModal,
  451. logModal,
  452. backupModal,
  453. spinning: false,
  454. loadingTip: '{{ i18n "loading"}}',
  455. },
  456. methods: {
  457. loading(spinning, tip = '{{ i18n "loading"}}') {
  458. this.spinning = spinning;
  459. this.loadingTip = tip;
  460. },
  461. async getStatus() {
  462. try {
  463. const msg = await HttpUtil.post('/server/status');
  464. if (msg.success) {
  465. this.setStatus(msg.obj);
  466. }
  467. } catch (e) {
  468. console.error("Failed to get status:", e);
  469. }
  470. },
  471. setStatus(data) {
  472. this.status = new Status(data);
  473. },
  474. async openSelectV2rayVersion() {
  475. this.loading(true);
  476. const msg = await HttpUtil.post('server/getXrayVersion');
  477. this.loading(false);
  478. if (!msg.success) {
  479. return;
  480. }
  481. versionModal.show(msg.obj);
  482. },
  483. switchV2rayVersion(version) {
  484. this.$confirm({
  485. title: '{{ i18n "pages.index.xraySwitchVersionDialog"}}',
  486. content: '{{ i18n "pages.index.xraySwitchVersionDialogDesc"}}' + ` ${version}?`,
  487. okText: '{{ i18n "confirm"}}',
  488. class: themeSwitcher.currentTheme,
  489. cancelText: '{{ i18n "cancel"}}',
  490. onOk: async () => {
  491. versionModal.hide();
  492. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  493. await HttpUtil.post(`/server/installXray/${version}`);
  494. this.loading(false);
  495. },
  496. });
  497. },
  498. async stopXrayService() {
  499. this.loading(true);
  500. const msg = await HttpUtil.post('server/stopXrayService');
  501. this.loading(false);
  502. if (!msg.success) {
  503. return;
  504. }
  505. },
  506. async restartXrayService() {
  507. this.loading(true);
  508. const msg = await HttpUtil.post('server/restartXrayService');
  509. this.loading(false);
  510. if (!msg.success) {
  511. return;
  512. }
  513. },
  514. async openLogs(){
  515. this.loading(true);
  516. const msg = await HttpUtil.post('server/logs/'+logModal.rows,{level: logModal.level, syslog: logModal.syslog});
  517. this.loading(false);
  518. if (!msg.success) {
  519. return;
  520. }
  521. logModal.show(msg.obj);
  522. },
  523. async openConfig() {
  524. this.loading(true);
  525. const msg = await HttpUtil.post('server/getConfigJson');
  526. this.loading(false);
  527. if (!msg.success) {
  528. return;
  529. }
  530. txtModal.show('config.json', JSON.stringify(msg.obj, null, 2), 'config.json');
  531. },
  532. openBackup() {
  533. backupModal.show({
  534. title: '{{ i18n "pages.index.backupTitle" }}',
  535. description: '{{ i18n "pages.index.backupDescription" }}',
  536. exportText: '{{ i18n "pages.index.exportDatabase" }}',
  537. importText: '{{ i18n "pages.index.importDatabase" }}',
  538. });
  539. },
  540. exportDatabase() {
  541. window.location = basePath + 'server/getDb';
  542. },
  543. importDatabase() {
  544. const fileInput = document.createElement('input');
  545. fileInput.type = 'file';
  546. fileInput.accept = '.db';
  547. fileInput.addEventListener('change', async (event) => {
  548. const dbFile = event.target.files[0];
  549. if (dbFile) {
  550. const formData = new FormData();
  551. formData.append('db', dbFile);
  552. backupModal.hide();
  553. this.loading(true);
  554. const uploadMsg = await HttpUtil.post('server/importDB', formData, {
  555. headers: {
  556. 'Content-Type': 'multipart/form-data',
  557. }
  558. });
  559. this.loading(false);
  560. if (!uploadMsg.success) {
  561. return;
  562. }
  563. this.loading(true);
  564. const restartMsg = await HttpUtil.post("/panel/setting/restartPanel");
  565. this.loading(false);
  566. if (restartMsg.success) {
  567. this.loading(true);
  568. await PromiseUtil.sleep(5000);
  569. location.reload();
  570. }
  571. }
  572. });
  573. fileInput.click();
  574. },
  575. },
  576. async mounted() {
  577. let retries = 0;
  578. while (retries < 5) {
  579. try {
  580. await this.getStatus();
  581. retries = 0;
  582. } catch (e) {
  583. console.error("Error occurred while fetching status:", e);
  584. retries++;
  585. }
  586. await PromiseUtil.sleep(2000);
  587. }
  588. },
  589. });
  590. </script>
  591. </body>
  592. </html>