index.html 27 KB

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