index.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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)">Log Reports</a-tag>
  113. <a-tag color="blue" style="cursor: pointer;" @click="openConfig">Config</a-tag>
  114. <a-tag color="blue" style="cursor: pointer;" @click="getBackup">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-layout>
  233. {{template "js" .}}
  234. {{template "textModal"}}
  235. <script>
  236. const State = {
  237. Running: "running",
  238. Stop: "stop",
  239. Error: "error",
  240. }
  241. Object.freeze(State);
  242. class CurTotal {
  243. constructor(current, total) {
  244. this.current = current;
  245. this.total = total;
  246. }
  247. get percent() {
  248. if (this.total === 0) {
  249. return 0;
  250. }
  251. return toFixed(this.current / this.total * 100, 2);
  252. }
  253. get color() {
  254. const percent = this.percent;
  255. if (percent < 80) {
  256. return '#67C23A';
  257. } else if (percent < 90) {
  258. return '#E6A23C';
  259. } else {
  260. return '#F56C6C';
  261. }
  262. }
  263. }
  264. class Status {
  265. constructor(data) {
  266. this.cpu = new CurTotal(0, 0);
  267. this.disk = new CurTotal(0, 0);
  268. this.loads = [0, 0, 0];
  269. this.mem = new CurTotal(0, 0);
  270. this.netIO = {up: 0, down: 0};
  271. this.netTraffic = {sent: 0, recv: 0};
  272. this.swap = new CurTotal(0, 0);
  273. this.tcpCount = 0;
  274. this.udpCount = 0;
  275. this.uptime = 0;
  276. this.xray = {state: State.Stop, errorMsg: "", version: "", color: ""};
  277. if (data == null) {
  278. return;
  279. }
  280. this.cpu = new CurTotal(data.cpu, 100);
  281. this.disk = new CurTotal(data.disk.current, data.disk.total);
  282. this.loads = data.loads.map(load => toFixed(load, 2));
  283. this.mem = new CurTotal(data.mem.current, data.mem.total);
  284. this.netIO = data.netIO;
  285. this.netTraffic = data.netTraffic;
  286. this.swap = new CurTotal(data.swap.current, data.swap.total);
  287. this.tcpCount = data.tcpCount;
  288. this.udpCount = data.udpCount;
  289. this.uptime = data.uptime;
  290. this.xray = data.xray;
  291. switch (this.xray.state) {
  292. case State.Running:
  293. this.xray.color = "green";
  294. break;
  295. case State.Stop:
  296. this.xray.color = "orange";
  297. break;
  298. case State.Error:
  299. this.xray.color = "red";
  300. break;
  301. default:
  302. this.xray.color = "gray";
  303. }
  304. }
  305. }
  306. const versionModal = {
  307. visible: false,
  308. versions: [],
  309. show(versions) {
  310. this.visible = true;
  311. this.versions = versions;
  312. },
  313. hide() {
  314. this.visible = false;
  315. },
  316. };
  317. const logModal = {
  318. visible: false,
  319. logs: '',
  320. rows: 20,
  321. show(logs, rows) {
  322. this.visible = true;
  323. this.rows = rows;
  324. this.logs = logs.join("\n");
  325. },
  326. hide() {
  327. this.visible = false;
  328. },
  329. };
  330. const app = new Vue({
  331. delimiters: ['[[', ']]'],
  332. el: '#app',
  333. data: {
  334. siderDrawer,
  335. status: new Status(),
  336. versionModal,
  337. logModal,
  338. spinning: false,
  339. loadingTip: '{{ i18n "loading"}}',
  340. },
  341. methods: {
  342. loading(spinning, tip = '{{ i18n "loading"}}') {
  343. this.spinning = spinning;
  344. this.loadingTip = tip;
  345. },
  346. async getStatus() {
  347. const msg = await HttpUtil.post('/server/status');
  348. if (msg.success) {
  349. this.setStatus(msg.obj);
  350. }
  351. },
  352. setStatus(data) {
  353. this.status = new Status(data);
  354. },
  355. async openSelectV2rayVersion() {
  356. this.loading(true);
  357. const msg = await HttpUtil.post('server/getXrayVersion');
  358. this.loading(false);
  359. if (!msg.success) {
  360. return;
  361. }
  362. versionModal.show(msg.obj);
  363. },
  364. switchV2rayVersion(version) {
  365. this.$confirm({
  366. title: '{{ i18n "pages.index.xraySwitchVersionDialog"}}',
  367. content: '{{ i18n "pages.index.xraySwitchVersionDialogDesc"}}' + ` ${version}?`,
  368. okText: '{{ i18n "confirm"}}',
  369. class: siderDrawer.isDarkTheme ? darkClass : '',
  370. cancelText: '{{ i18n "cancel"}}',
  371. onOk: async () => {
  372. versionModal.hide();
  373. this.loading(true, '{{ i18n "pages.index.dontRefreshh"}}');
  374. await HttpUtil.post(`/server/installXray/${version}`);
  375. this.loading(false);
  376. },
  377. });
  378. },
  379. //here add stop xray function
  380. async stopXrayService() {
  381. this.loading(true);
  382. const msg = await HttpUtil.post('server/stopXrayService');
  383. this.loading(false);
  384. if (!msg.success) {
  385. return;
  386. }
  387. },
  388. //here add restart xray function
  389. async restartXrayService() {
  390. this.loading(true);
  391. const msg = await HttpUtil.post('server/restartXrayService');
  392. this.loading(false);
  393. if (!msg.success) {
  394. return;
  395. }
  396. },
  397. async openLogs(rows){
  398. this.loading(true);
  399. const msg = await HttpUtil.post('server/logs/'+rows);
  400. this.loading(false);
  401. if (!msg.success) {
  402. return;
  403. }
  404. logModal.show(msg.obj,rows);
  405. },
  406. async openConfig(){
  407. this.loading(true);
  408. const msg = await HttpUtil.post('server/getConfigJson');
  409. this.loading(false);
  410. if (!msg.success) {
  411. return;
  412. }
  413. txtModal.show('config.json',JSON.stringify(msg.obj, null, 2),'config.json');
  414. },
  415. getBackup(){
  416. window.location = basePath + 'server/getDb';
  417. }
  418. },
  419. async mounted() {
  420. while (true) {
  421. try {
  422. await this.getStatus();
  423. } catch (e) {
  424. console.error(e);
  425. }
  426. await PromiseUtil.sleep(2000);
  427. }
  428. },
  429. });
  430. </script>
  431. </body>
  432. </html>