index.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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. {{ i18n "pages.index.xrayStatus" }}:
  78. <a-tag :color="status.xray.color">[[ status.xray.state ]]</a-tag>
  79. <a-tooltip v-if="status.xray.state === State.Error">
  80. <template slot="title">
  81. <p v-for="line in status.xray.errorMsg.split('\n')">[[ line ]]</p>
  82. </template>
  83. <a-icon type="question-circle" theme="filled"></a-icon>
  84. </a-tooltip>
  85. <a-tag color="green" style="cursor: pointer;" @click="openSelectV2rayVersion">[[ status.xray.version ]]</a-tag>
  86. <a-tag color="blue" style="cursor: pointer;" @click="stopXrayService">{{ i18n "pages.index.stopXray" }}</a-tag>
  87. <a-tag color="blue" style="cursor: pointer;" @click="restartXrayService">{{ i18n "pages.index.restartXray" }}</a-tag>
  88. <a-tag color="blue" style="cursor: pointer;" @click="openSelectV2rayVersion">{{ i18n "pages.index.xraySwitch" }}</a-tag>
  89. </a-card>
  90. </a-col>
  91. <a-col :sm="24" :md="12">
  92. <a-card hoverable :class="siderDrawer.isDarkTheme ? darkClass : ''">
  93. {{ i18n "pages.index.operationHours" }}:
  94. <a-tag color="green">[[ formatSecond(status.uptime) ]]</a-tag>
  95. <a-tooltip>
  96. <template slot="title">
  97. {{ i18n "pages.index.operationHoursDesc" }}
  98. </template>
  99. <a-icon type="question-circle" theme="filled"></a-icon>
  100. </a-tooltip>
  101. </a-card>
  102. </a-col>
  103. <a-col :sm="24" :md="12">
  104. <a-card hoverable :class="siderDrawer.isDarkTheme ? darkClass : ''">
  105. {{ i18n "pages.index.systemLoad" }}: [[ status.loads[0] ]] | [[ status.loads[1] ]] | [[ status.loads[2] ]]
  106. </a-card>
  107. </a-col>
  108. <a-col :sm="24" :md="12">
  109. <a-card hoverable :class="siderDrawer.isDarkTheme ? darkClass : ''">
  110. TCP / UDP {{ i18n "pages.index.connectionCount" }}: [[ status.tcpCount ]] / [[ status.udpCount ]]
  111. <a-tooltip>
  112. <template slot="title">
  113. {{ i18n "pages.index.connectionCountDesc" }}
  114. </template>
  115. <a-icon type="question-circle" theme="filled"></a-icon>
  116. </a-tooltip>
  117. </a-card>
  118. </a-col>
  119. <a-col :sm="24" :md="12">
  120. <a-card hoverable :class="siderDrawer.isDarkTheme ? darkClass : ''">
  121. <a-row>
  122. <a-col :span="12">
  123. <a-icon type="arrow-up"></a-icon>
  124. [[ sizeFormat(status.netIO.up) ]] / S
  125. <a-tooltip>
  126. <template slot="title">
  127. {{ i18n "pages.index.upSpeed" }}
  128. </template>
  129. <a-icon type="question-circle" theme="filled"></a-icon>
  130. </a-tooltip>
  131. </a-col>
  132. <a-col :span="12">
  133. <a-icon type="arrow-down"></a-icon>
  134. [[ sizeFormat(status.netIO.down) ]] / S
  135. <a-tooltip>
  136. <template slot="title">
  137. {{ i18n "pages.index.downSpeed" }}
  138. </template>
  139. <a-icon type="question-circle" theme="filled"></a-icon>
  140. </a-tooltip>
  141. </a-col>
  142. </a-row>
  143. </a-card>
  144. </a-col>
  145. <a-col :sm="24" :md="12">
  146. <a-card hoverable :class="siderDrawer.isDarkTheme ? darkClass : ''">
  147. <a-row>
  148. <a-col :span="12">
  149. <a-icon type="cloud-upload"></a-icon>
  150. [[ sizeFormat(status.netTraffic.sent) ]]
  151. <a-tooltip>
  152. <template slot="title">
  153. {{ i18n "pages.index.totalSent" }}
  154. </template>
  155. <a-icon type="question-circle" theme="filled"></a-icon>
  156. </a-tooltip>
  157. </a-col>
  158. <a-col :span="12">
  159. <a-icon type="cloud-download"></a-icon>
  160. [[ sizeFormat(status.netTraffic.recv) ]]
  161. <a-tooltip>
  162. <template slot="title">
  163. {{ i18n "pages.index.totalReceive" }}
  164. </template>
  165. <a-icon type="question-circle" theme="filled"></a-icon>
  166. </a-tooltip>
  167. </a-col>
  168. </a-row>
  169. </a-card>
  170. </a-col>
  171. <a-col :sm="24" :md="12">
  172. <a-card hoverable :class="siderDrawer.isDarkTheme ? darkClass : ''">
  173. 3x-ui: <a href="https://github.com/MHSanaei/3x-ui/releases" target="_blank"><a-tag color="green">v{{ .cur_ver }}</a-tag></a>
  174. <a href="https://t.me/panel3xui" target="_blank"><a-tag color="green">Telegram</a-tag></a>
  175. <a-tag color="blue" style="cursor: pointer;" @click="openLogs(20)">Log Reports</a-tag>
  176. </a-card>
  177. </a-col>
  178. </a-row>
  179. </transition>
  180. </a-layout-content>
  181. </a-layout>
  182. <a-modal id="version-modal" v-model="versionModal.visible" title='{{ i18n "pages.index.xraySwitch" }}'
  183. :closable="true" @ok="() => versionModal.visible = false"
  184. :class="siderDrawer.isDarkTheme ? darkClass : ''"
  185. footer="">
  186. <h2>{{ i18n "pages.index.xraySwitchClick"}}</h2>
  187. <h2>{{ i18n "pages.index.xraySwitchClickDesk"}}</h2>
  188. <template v-for="version, index in versionModal.versions">
  189. <a-tag :color="index % 2 == 0 ? 'blue' : 'green'"
  190. style="margin: 10px" @click="switchV2rayVersion(version)">
  191. [[ version ]]
  192. </a-tag>
  193. </template>
  194. </a-modal>
  195. <a-modal id="log-modal" v-model="logModal.visible" title="X-UI logs"
  196. :closable="true" @ok="() => logModal.visible = false" @cancel="() => logModal.visible = false"
  197. :class="siderDrawer.isDarkTheme ? darkClass : ''"
  198. width="800px"
  199. footer="">
  200. <a-form layout="inline">
  201. <a-form-item label="Count">
  202. <a-select v-model="logModal.rows"
  203. style="width: 80px"
  204. @change="openLogs(logModal.rows)"
  205. :dropdown-class-name="siderDrawer.isDarkTheme ? 'ant-card-dark' : ''">
  206. <a-select-option value="10">10</a-select-option>
  207. <a-select-option value="20">20</a-select-option>
  208. <a-select-option value="50">50</a-select-option>
  209. <a-select-option value="100">100</a-select-option>
  210. </a-select>
  211. </a-form-item>
  212. <a-form-item>
  213. <button class="ant-btn ant-btn-primary" @click="openLogs(logModal.rows)"><a-icon type="sync"></a-icon> Reload</button>
  214. </a-form-item>
  215. <a-form-item>
  216. <a-button type="primary" style="margin-bottom: 10px;"
  217. :href="'data:application/text;charset=utf-8,' + encodeURIComponent(logModal.logs)" download="x-ui.log">
  218. {{ i18n "download" }} x-ui.log
  219. </a-button>
  220. </a-form-item>
  221. </a-form>
  222. <a-input type="textarea" v-model="logModal.logs" disabled="true"
  223. :autosize="{ minRows: 10, maxRows: 22}"></a-input>
  224. </a-modal>
  225. </a-layout>
  226. {{template "js" .}}
  227. <script>
  228. const State = {
  229. Running: "running",
  230. Stop: "stop",
  231. Error: "error",
  232. }
  233. Object.freeze(State);
  234. class CurTotal {
  235. constructor(current, total) {
  236. this.current = current;
  237. this.total = total;
  238. }
  239. get percent() {
  240. if (this.total === 0) {
  241. return 0;
  242. }
  243. return toFixed(this.current / this.total * 100, 2);
  244. }
  245. get color() {
  246. const percent = this.percent;
  247. if (percent < 80) {
  248. return '#67C23A';
  249. } else if (percent < 90) {
  250. return '#E6A23C';
  251. } else {
  252. return '#F56C6C';
  253. }
  254. }
  255. }
  256. class Status {
  257. constructor(data) {
  258. this.cpu = new CurTotal(0, 0);
  259. this.disk = new CurTotal(0, 0);
  260. this.loads = [0, 0, 0];
  261. this.mem = new CurTotal(0, 0);
  262. this.netIO = {up: 0, down: 0};
  263. this.netTraffic = {sent: 0, recv: 0};
  264. this.swap = new CurTotal(0, 0);
  265. this.tcpCount = 0;
  266. this.udpCount = 0;
  267. this.uptime = 0;
  268. this.xray = {state: State.Stop, errorMsg: "", version: "", color: ""};
  269. if (data == null) {
  270. return;
  271. }
  272. this.cpu = new CurTotal(data.cpu, 100);
  273. this.disk = new CurTotal(data.disk.current, data.disk.total);
  274. this.loads = data.loads.map(load => toFixed(load, 2));
  275. this.mem = new CurTotal(data.mem.current, data.mem.total);
  276. this.netIO = data.netIO;
  277. this.netTraffic = data.netTraffic;
  278. this.swap = new CurTotal(data.swap.current, data.swap.total);
  279. this.tcpCount = data.tcpCount;
  280. this.udpCount = data.udpCount;
  281. this.uptime = data.uptime;
  282. this.xray = data.xray;
  283. switch (this.xray.state) {
  284. case State.Running:
  285. this.xray.color = "green";
  286. break;
  287. case State.Stop:
  288. this.xray.color = "orange";
  289. break;
  290. case State.Error:
  291. this.xray.color = "red";
  292. break;
  293. default:
  294. this.xray.color = "gray";
  295. }
  296. }
  297. }
  298. const versionModal = {
  299. visible: false,
  300. versions: [],
  301. show(versions) {
  302. this.visible = true;
  303. this.versions = versions;
  304. },
  305. hide() {
  306. this.visible = false;
  307. },
  308. };
  309. const logModal = {
  310. visible: false,
  311. logs: '',
  312. rows: 20,
  313. show(logs, rows) {
  314. this.visible = true;
  315. this.rows = rows;
  316. this.logs = logs.join("\n");
  317. },
  318. hide() {
  319. this.visible = false;
  320. },
  321. };
  322. const app = new Vue({
  323. delimiters: ['[[', ']]'],
  324. el: '#app',
  325. data: {
  326. siderDrawer,
  327. status: new Status(),
  328. versionModal,
  329. logModal,
  330. spinning: false,
  331. loadingTip: '{{ i18n "loading"}}',
  332. },
  333. methods: {
  334. loading(spinning, tip = '{{ i18n "loading"}}') {
  335. this.spinning = spinning;
  336. this.loadingTip = tip;
  337. },
  338. async getStatus() {
  339. const msg = await HttpUtil.post('/server/status');
  340. if (msg.success) {
  341. this.setStatus(msg.obj);
  342. }
  343. },
  344. setStatus(data) {
  345. this.status = new Status(data);
  346. },
  347. async openSelectV2rayVersion() {
  348. this.loading(true);
  349. const msg = await HttpUtil.post('server/getXrayVersion');
  350. this.loading(false);
  351. if (!msg.success) {
  352. return;
  353. }
  354. versionModal.show(msg.obj);
  355. },
  356. switchV2rayVersion(version) {
  357. this.$confirm({
  358. title: '{{ i18n "pages.index.xraySwitchVersionDialog"}}',
  359. content: '{{ i18n "pages.index.xraySwitchVersionDialogDesc"}}' + ` ${version}?`,
  360. okText: '{{ i18n "confirm"}}',
  361. class: siderDrawer.isDarkTheme ? darkClass : '',
  362. cancelText: '{{ i18n "cancel"}}',
  363. onOk: async () => {
  364. versionModal.hide();
  365. this.loading(true, '{{ i18n "pages.index.dontRefreshh"}}');
  366. await HttpUtil.post(`/server/installXray/${version}`);
  367. this.loading(false);
  368. },
  369. });
  370. },
  371. //here add stop xray function
  372. async stopXrayService() {
  373. this.loading(true);
  374. const msg = await HttpUtil.post('server/stopXrayService');
  375. this.loading(false);
  376. if (!msg.success) {
  377. return;
  378. }
  379. },
  380. //here add restart xray function
  381. async restartXrayService() {
  382. this.loading(true);
  383. const msg = await HttpUtil.post('server/restartXrayService');
  384. this.loading(false);
  385. if (!msg.success) {
  386. return;
  387. }
  388. },
  389. async openLogs(rows){
  390. this.loading(true);
  391. const msg = await HttpUtil.post('server/logs/'+rows);
  392. this.loading(false);
  393. if (!msg.success) {
  394. return;
  395. }
  396. logModal.show(msg.obj,rows);
  397. }
  398. },
  399. async mounted() {
  400. while (true) {
  401. try {
  402. await this.getStatus();
  403. } catch (e) {
  404. console.error(e);
  405. }
  406. await PromiseUtil.sleep(2000);
  407. }
  408. },
  409. });
  410. </script>
  411. </body>
  412. </html>