index.html 17 KB

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