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. }
  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. {{ i18n "pages.index.operationHours" }}:
  109. Xray:
  110. <a-tag color="green">[[ formatSecond(status.appStats.uptime) ]]</a-tag>
  111. OS:
  112. <a-tag color="green">[[ formatSecond(status.uptime) ]]</a-tag>
  113. </a-card>
  114. </a-col>
  115. <a-col :sm="24" :md="12">
  116. <a-card hoverable :class="themeSwitcher.darkCardClass">
  117. {{ i18n "pages.index.systemLoad" }}: [[ status.loads[0] ]] | [[ status.loads[1] ]] | [[ status.loads[2] ]]
  118. <a-tooltip>
  119. <template slot="title">
  120. {{ i18n "pages.index.systemLoadDesc" }}
  121. </template>
  122. <a-icon type="question-circle" theme="filled"></a-icon>
  123. </a-tooltip>
  124. </a-card>
  125. </a-col>
  126. <a-col :sm="24" :md="12">
  127. <a-card hoverable :class="themeSwitcher.darkCardClass">
  128. {{ i18n "usage"}}:
  129. Memory [[ sizeFormat(status.appStats.mem) ]] -
  130. Threads [[ status.appStats.threads ]]
  131. </a-tooltip>
  132. </a-card>
  133. </a-col>
  134. <a-col :sm="24" :md="12">
  135. <a-card hoverable :class="themeSwitcher.darkCardClass">
  136. <a-row>
  137. <a-col :span="12">
  138. IPv4:
  139. <a-tooltip>
  140. <template slot="title">
  141. [[ status.publicIP.ipv4 ]]
  142. </template>
  143. <a-icon type="question-circle" theme="filled"></a-icon>
  144. </a-tooltip>
  145. </a-col>
  146. <a-col :span="12">
  147. IPv6:
  148. <a-tooltip>
  149. <template slot="title">
  150. [[ status.publicIP.ipv6 ]]
  151. </template>
  152. <a-icon type="question-circle" theme="filled"></a-icon>
  153. </a-tooltip>
  154. </a-col>
  155. </a-row>
  156. </a-card>
  157. </a-col>
  158. <a-col :sm="24" :md="12">
  159. <a-card hoverable :class="themeSwitcher.darkCardClass">
  160. <a-row>
  161. <a-col :span="12">
  162. TCP: [[ status.tcpCount ]]
  163. <a-tooltip>
  164. <template slot="title">
  165. {{ i18n "pages.index.connectionTcpCountDesc" }}
  166. </template>
  167. <a-icon type="question-circle" theme="filled"></a-icon>
  168. </a-tooltip>
  169. </a-col>
  170. <a-col :span="12">
  171. UDP: [[ status.udpCount ]]
  172. <a-tooltip>
  173. <template slot="title">
  174. {{ i18n "pages.index.connectionUdpCountDesc" }}
  175. </template>
  176. <a-icon type="question-circle" theme="filled"></a-icon>
  177. </a-tooltip>
  178. </a-col>
  179. </a-row>
  180. </a-card>
  181. </a-col>
  182. <a-col :sm="24" :md="12">
  183. <a-card hoverable :class="themeSwitcher.darkCardClass">
  184. <a-row>
  185. <a-col :span="12">
  186. <a-icon type="arrow-up"></a-icon>
  187. [[ sizeFormat(status.netIO.up) ]]/S
  188. <a-tooltip>
  189. <template slot="title">
  190. {{ i18n "pages.index.upSpeed" }}
  191. </template>
  192. <a-icon type="question-circle" theme="filled"></a-icon>
  193. </a-tooltip>
  194. </a-col>
  195. <a-col :span="12">
  196. <a-icon type="arrow-down"></a-icon>
  197. [[ sizeFormat(status.netIO.down) ]]/S
  198. <a-tooltip>
  199. <template slot="title">
  200. {{ i18n "pages.index.downSpeed" }}
  201. </template>
  202. <a-icon type="question-circle" theme="filled"></a-icon>
  203. </a-tooltip>
  204. </a-col>
  205. </a-row>
  206. </a-card>
  207. </a-col>
  208. <a-col :sm="24" :md="12">
  209. <a-card hoverable :class="themeSwitcher.darkCardClass">
  210. <a-row>
  211. <a-col :span="12">
  212. <a-icon type="cloud-upload"></a-icon>
  213. [[ sizeFormat(status.netTraffic.sent) ]]
  214. <a-tooltip>
  215. <template slot="title">
  216. {{ i18n "pages.index.totalSent" }}
  217. </template>
  218. <a-icon type="question-circle" theme="filled"></a-icon>
  219. </a-tooltip>
  220. </a-col>
  221. <a-col :span="12">
  222. <a-icon type="cloud-download"></a-icon>
  223. [[ sizeFormat(status.netTraffic.recv) ]]
  224. <a-tooltip>
  225. <template slot="title">
  226. {{ i18n "pages.index.totalReceive" }}
  227. </template>
  228. <a-icon type="question-circle" theme="filled"></a-icon>
  229. </a-tooltip>
  230. </a-col>
  231. </a-row>
  232. </a-card>
  233. </a-col>
  234. </a-row>
  235. </transition>
  236. </a-layout-content>
  237. </a-layout>
  238. <a-modal id="version-modal" v-model="versionModal.visible" title='{{ i18n "pages.index.xraySwitch" }}'
  239. :closable="true" @ok="() => versionModal.visible = false"
  240. :class="themeSwitcher.darkCardClass"
  241. footer="">
  242. <h2>{{ i18n "pages.index.xraySwitchClick"}}</h2>
  243. <h2>{{ i18n "pages.index.xraySwitchClickDesk"}}</h2>
  244. <template v-for="version, index in versionModal.versions">
  245. <a-tag :color="index % 2 == 0 ? 'blue' : 'green'"
  246. style="margin: 10px" @click="switchV2rayVersion(version)">
  247. [[ version ]]
  248. </a-tag>
  249. </template>
  250. </a-modal>
  251. <a-modal id="log-modal" v-model="logModal.visible" title="X-UI logs"
  252. :closable="true" @ok="() => logModal.visible = false" @cancel="() => logModal.visible = false"
  253. :class="themeSwitcher.darkCardClass"
  254. width="800px"
  255. footer="">
  256. <a-form layout="inline">
  257. <a-form-item label="Count">
  258. <a-select v-model="logModal.rows"
  259. style="width: 80px"
  260. @change="openLogs()"
  261. :dropdown-class-name="themeSwitcher.darkCardClass">
  262. <a-select-option value="10">10</a-select-option>
  263. <a-select-option value="20">20</a-select-option>
  264. <a-select-option value="50">50</a-select-option>
  265. <a-select-option value="100">100</a-select-option>
  266. </a-select>
  267. </a-form-item>
  268. <a-form-item label="Log Level">
  269. <a-select v-model="logModal.level"
  270. style="width: 120px"
  271. @change="openLogs()"
  272. :dropdown-class-name="themeSwitcher.darkCardClass">
  273. <a-select-option value="debug">Debug</a-select-option>
  274. <a-select-option value="info">Info</a-select-option>
  275. <a-select-option value="notice">Notice</a-select-option>
  276. <a-select-option value="warning">Warning</a-select-option>
  277. <a-select-option value="err">Error</a-select-option>
  278. </a-select>
  279. </a-form-item>
  280. <a-form-item label="SysLog">
  281. <a-checkbox v-model="logModal.syslog" @change="openLogs()"></a-checkbox>
  282. </a-form-item>
  283. <a-form-item>
  284. <button class="ant-btn ant-btn-primary" @click="openLogs()"><a-icon type="sync"></a-icon> Reload</button>
  285. </a-form-item>
  286. <a-form-item>
  287. <a-button type="primary" style="margin-bottom: 10px;"
  288. :href="'data:application/text;charset=utf-8,' + encodeURIComponent(logModal.logs)" download="x-ui.log">
  289. {{ i18n "download" }} x-ui.log
  290. </a-button>
  291. </a-form-item>
  292. </a-form>
  293. <a-input type="textarea" v-model="logModal.logs" disabled="true"
  294. :autosize="{ minRows: 10, maxRows: 22}"></a-input>
  295. </a-modal>
  296. <a-modal id="backup-modal" v-model="backupModal.visible" :title="backupModal.title"
  297. :closable="true" :class="themeSwitcher.darkCardClass"
  298. @ok="() => backupModal.hide()" @cancel="() => backupModal.hide()">
  299. <p style="color: inherit; font-size: 16px; padding: 4px 2px;">
  300. <a-icon type="warning" style="color: inherit; font-size: 20px;"></a-icon>
  301. [[ backupModal.description ]]
  302. </p>
  303. <a-space direction="horizontal" style="text-align: center" style="margin-bottom: 10px;">
  304. <a-button type="primary" @click="exportDatabase()">
  305. [[ backupModal.exportText ]]
  306. </a-button>
  307. <a-button type="primary" @click="importDatabase()">
  308. [[ backupModal.importText ]]
  309. </a-button>
  310. </a-space>
  311. </a-modal>
  312. </a-layout>
  313. {{template "js" .}}
  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 '#67C23A';
  338. } else if (percent < 90) {
  339. return '#E6A23C';
  340. } else {
  341. return '#F56C6C';
  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.darkCardClass,
  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>