index.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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. </style>
  14. <body>
  15. <a-layout id="app" v-cloak>
  16. {{ template "commonSider" . }}
  17. <a-layout id="content-layout" :style="siderDrawer.isDarkTheme ? bgDarkStyle : ''">
  18. <a-layout-content>
  19. <a-spin :spinning="spinning" :delay="200" :tip="loadingTip"/>
  20. <transition name="list" appear>
  21. <a-row>
  22. <a-card hoverable :class="siderDrawer.isDarkTheme ? darkClass : ''">
  23. <a-row>
  24. <a-col :sm="24" :md="12">
  25. <a-row>
  26. <a-col :span="12" style="text-align: center">
  27. <a-progress type="dashboard" status="normal"
  28. :stroke-color="status.cpu.color"
  29. :class="siderDrawer.isDarkTheme ? darkClass : ''"
  30. :percent="status.cpu.percent"></a-progress>
  31. <div>CPU</div>
  32. </a-col>
  33. <a-col :span="12" style="text-align: center">
  34. <a-progress type="dashboard" status="normal"
  35. :stroke-color="status.mem.color"
  36. :class="siderDrawer.isDarkTheme ? darkClass : ''"
  37. :percent="status.mem.percent"></a-progress>
  38. <div>
  39. {{ i18n "pages.index.memory"}}: [[ sizeFormat(status.mem.current) ]] / [[ sizeFormat(status.mem.total) ]]
  40. </div>
  41. </a-col>
  42. </a-row>
  43. </a-col>
  44. <a-col :sm="24" :md="12">
  45. <a-row>
  46. <a-col :span="12" style="text-align: center">
  47. <a-progress type="dashboard" status="normal"
  48. :stroke-color="status.swap.color"
  49. :class="siderDrawer.isDarkTheme ? darkClass : ''"
  50. :percent="status.swap.percent"></a-progress>
  51. <div>
  52. Swap: [[ sizeFormat(status.swap.current) ]] / [[ sizeFormat(status.swap.total) ]]
  53. </div>
  54. </a-col>
  55. <a-col :span="12" style="text-align: center">
  56. <a-progress type="dashboard" status="normal"
  57. :stroke-color="status.disk.color"
  58. :class="siderDrawer.isDarkTheme ? darkClass : ''"
  59. :percent="status.disk.percent"></a-progress>
  60. <div>
  61. {{ i18n "pages.index.hard"}}: [[ sizeFormat(status.disk.current) ]] / [[ sizeFormat(status.disk.total) ]]
  62. </div>
  63. </a-col>
  64. </a-row>
  65. </a-col>
  66. </a-row>
  67. </a-card>
  68. </a-row>
  69. </transition>
  70. <transition name="list" appear>
  71. <a-row>
  72. <a-col :sm="24" :md="12">
  73. <a-card hoverable :class="siderDrawer.isDarkTheme ? darkClass : ''">
  74. {{ i18n "pages.index.xrayStatus" }}:
  75. <a-tag :color="status.xray.color">[[ status.xray.state ]]</a-tag>
  76. <a-tooltip v-if="status.xray.state === State.Error">
  77. <template slot="title">
  78. <p v-for="line in status.xray.errorMsg.split('\n')">[[ line ]]</p>
  79. </template>
  80. <a-icon type="question-circle" theme="filled"></a-icon>
  81. </a-tooltip>
  82. <a-tag color="green" @click="openSelectV2rayVersion">[[ status.xray.version ]]</a-tag>
  83. <a-tag color="blue" @click="stopXrayService">{{ i18n "pages.index.stopXray" }}</a-tag>
  84. <a-tag color="blue" @click="restartXrayService">{{ i18n "pages.index.restartXray" }}</a-tag>
  85. <a-tag color="blue" @click="openSelectV2rayVersion">{{ i18n "pages.index.xraySwitch" }}</a-tag>
  86. </a-card>
  87. </a-col>
  88. <a-col :sm="24" :md="12">
  89. <a-card hoverable :class="siderDrawer.isDarkTheme ? darkClass : ''">
  90. {{ i18n "pages.index.operationHours" }}:
  91. <a-tag color="#87d068">[[ formatSecond(status.uptime) ]]</a-tag>
  92. <a-tooltip>
  93. <template slot="title">
  94. {{ i18n "pages.index.operationHoursDesc" }}
  95. </template>
  96. <a-icon type="question-circle" theme="filled"></a-icon>
  97. </a-tooltip>
  98. </a-card>
  99. </a-col>
  100. <a-col :sm="24" :md="12">
  101. <a-card hoverable :class="siderDrawer.isDarkTheme ? darkClass : ''">
  102. {{ i18n "pages.index.systemLoad" }}: [[ status.loads[0] ]] | [[ status.loads[1] ]] | [[ status.loads[2] ]]
  103. </a-card>
  104. </a-col>
  105. <a-col :sm="24" :md="12">
  106. <a-card hoverable :class="siderDrawer.isDarkTheme ? darkClass : ''">
  107. TCP / UDP {{ i18n "pages.index.connectionCount" }}: [[ status.tcpCount ]] / [[ status.udpCount ]]
  108. <a-tooltip>
  109. <template slot="title">
  110. {{ i18n "pages.index.connectionCountDesc" }}
  111. </template>
  112. <a-icon type="question-circle" theme="filled"></a-icon>
  113. </a-tooltip>
  114. </a-card>
  115. </a-col>
  116. <a-col :sm="24" :md="12">
  117. <a-card hoverable :class="siderDrawer.isDarkTheme ? darkClass : ''">
  118. <a-row>
  119. <a-col :span="12">
  120. <a-icon type="arrow-up"></a-icon>
  121. [[ sizeFormat(status.netIO.up) ]] / S
  122. <a-tooltip>
  123. <template slot="title">
  124. {{ i18n "pages.index.upSpeed" }}
  125. </template>
  126. <a-icon type="question-circle" theme="filled"></a-icon>
  127. </a-tooltip>
  128. </a-col>
  129. <a-col :span="12">
  130. <a-icon type="arrow-down"></a-icon>
  131. [[ sizeFormat(status.netIO.down) ]] / S
  132. <a-tooltip>
  133. <template slot="title">
  134. {{ i18n "pages.index.downSpeed" }}
  135. </template>
  136. <a-icon type="question-circle" theme="filled"></a-icon>
  137. </a-tooltip>
  138. </a-col>
  139. </a-row>
  140. </a-card>
  141. </a-col>
  142. <a-col :sm="24" :md="12">
  143. <a-card hoverable :class="siderDrawer.isDarkTheme ? darkClass : ''">
  144. <a-row>
  145. <a-col :span="12">
  146. <a-icon type="cloud-upload"></a-icon>
  147. [[ sizeFormat(status.netTraffic.sent) ]]
  148. <a-tooltip>
  149. <template slot="title">
  150. {{ i18n "pages.index.totalSent" }}
  151. </template>
  152. <a-icon type="question-circle" theme="filled"></a-icon>
  153. </a-tooltip>
  154. </a-col>
  155. <a-col :span="12">
  156. <a-icon type="cloud-download"></a-icon>
  157. [[ sizeFormat(status.netTraffic.recv) ]]
  158. <a-tooltip>
  159. <template slot="title">
  160. {{ i18n "pages.index.totalReceive" }}
  161. </template>
  162. <a-icon type="question-circle" theme="filled"></a-icon>
  163. </a-tooltip>
  164. </a-col>
  165. </a-row>
  166. </a-card>
  167. </a-col>
  168. </a-row>
  169. </transition>
  170. </a-layout-content>
  171. </a-layout>
  172. <a-modal id="version-modal" v-model="versionModal.visible" title='{{ i18n "pages.index.xraySwitch" }}'
  173. :closable="true" @ok="() => versionModal.visible = false"
  174. ok-text='{{ i18n "confirm" }}' cancel-text='{{ i18n "cancel"}}'>
  175. <h2>{{ i18n "pages.index.xraySwitchClick"}}</h2>
  176. <h2>{{ i18n "pages.index.xraySwitchClickDesk"}}</h2>
  177. <template v-for="version, index in versionModal.versions">
  178. <a-tag :color="index % 2 == 0 ? 'blue' : 'green'"
  179. style="margin: 10px" @click="switchV2rayVersion(version)">
  180. [[ version ]]
  181. </a-tag>
  182. </template>
  183. </a-modal>
  184. </a-layout>
  185. {{template "js" .}}
  186. <script>
  187. const State = {
  188. Running: "running",
  189. Stop: "stop",
  190. Error: "error",
  191. }
  192. Object.freeze(State);
  193. class CurTotal {
  194. constructor(current, total) {
  195. this.current = current;
  196. this.total = total;
  197. }
  198. get percent() {
  199. if (this.total === 0) {
  200. return 0;
  201. }
  202. return toFixed(this.current / this.total * 100, 2);
  203. }
  204. get color() {
  205. const percent = this.percent;
  206. if (percent < 80) {
  207. return '#67C23A';
  208. } else if (percent < 90) {
  209. return '#E6A23C';
  210. } else {
  211. return '#F56C6C';
  212. }
  213. }
  214. }
  215. class Status {
  216. constructor(data) {
  217. this.cpu = new CurTotal(0, 0);
  218. this.disk = new CurTotal(0, 0);
  219. this.loads = [0, 0, 0];
  220. this.mem = new CurTotal(0, 0);
  221. this.netIO = {up: 0, down: 0};
  222. this.netTraffic = {sent: 0, recv: 0};
  223. this.swap = new CurTotal(0, 0);
  224. this.tcpCount = 0;
  225. this.udpCount = 0;
  226. this.uptime = 0;
  227. this.xray = {state: State.Stop, errorMsg: "", version: "", color: ""};
  228. if (data == null) {
  229. return;
  230. }
  231. this.cpu = new CurTotal(data.cpu, 100);
  232. this.disk = new CurTotal(data.disk.current, data.disk.total);
  233. this.loads = data.loads.map(load => toFixed(load, 2));
  234. this.mem = new CurTotal(data.mem.current, data.mem.total);
  235. this.netIO = data.netIO;
  236. this.netTraffic = data.netTraffic;
  237. this.swap = new CurTotal(data.swap.current, data.swap.total);
  238. this.tcpCount = data.tcpCount;
  239. this.udpCount = data.udpCount;
  240. this.uptime = data.uptime;
  241. this.xray = data.xray;
  242. switch (this.xray.state) {
  243. case State.Running:
  244. this.xray.color = "green";
  245. break;
  246. case State.Stop:
  247. this.xray.color = "orange";
  248. break;
  249. case State.Error:
  250. this.xray.color = "red";
  251. break;
  252. default:
  253. this.xray.color = "gray";
  254. }
  255. }
  256. }
  257. const versionModal = {
  258. visible: false,
  259. versions: [],
  260. show(versions) {
  261. this.visible = true;
  262. this.versions = versions;
  263. },
  264. hide() {
  265. this.visible = false;
  266. },
  267. };
  268. const app = new Vue({
  269. delimiters: ['[[', ']]'],
  270. el: '#app',
  271. data: {
  272. siderDrawer,
  273. status: new Status(),
  274. versionModal,
  275. spinning: false,
  276. loadingTip: '{{ i18n "loading"}}',
  277. },
  278. methods: {
  279. loading(spinning, tip = '{{ i18n "loading"}}') {
  280. this.spinning = spinning;
  281. this.loadingTip = tip;
  282. },
  283. async getStatus() {
  284. const msg = await HttpUtil.post('/server/status');
  285. if (msg.success) {
  286. this.setStatus(msg.obj);
  287. }
  288. },
  289. setStatus(data) {
  290. this.status = new Status(data);
  291. },
  292. async openSelectV2rayVersion() {
  293. this.loading(true);
  294. const msg = await HttpUtil.post('server/getXrayVersion');
  295. this.loading(false);
  296. if (!msg.success) {
  297. return;
  298. }
  299. versionModal.show(msg.obj);
  300. },
  301. switchV2rayVersion(version) {
  302. this.$confirm({
  303. title: '{{ i18n "pages.index.xraySwitchVersionDialog"}}',
  304. content: '{{ i18n "pages.index.xraySwitchVersionDialogDesc"}}' + ` ${version}?`,
  305. okText: '{{ i18n "confirm"}}',
  306. cancelText: '{{ i18n "cancel"}}',
  307. onOk: async () => {
  308. versionModal.hide();
  309. this.loading(true, '{{ i18n "pages.index.dontRefreshh"}}');
  310. await HttpUtil.post(`/server/installXray/${version}`);
  311. this.loading(false);
  312. },
  313. });
  314. },
  315. //here add stop xray function
  316. async stopXrayService() {
  317. this.loading(true);
  318. const msg = await HttpUtil.post('server/stopXrayService');
  319. this.loading(false);
  320. if (!msg.success) {
  321. return;
  322. }
  323. },
  324. //here add restart xray function
  325. async restartXrayService() {
  326. this.loading(true);
  327. const msg = await HttpUtil.post('server/restartXrayService');
  328. this.loading(false);
  329. if (!msg.success) {
  330. return;
  331. }
  332. },
  333. },
  334. async mounted() {
  335. while (true) {
  336. try {
  337. await this.getStatus();
  338. } catch (e) {
  339. console.error(e);
  340. }
  341. await PromiseUtil.sleep(2000);
  342. }
  343. },
  344. });
  345. </script>
  346. </body>
  347. </html>