1
0

index.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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" @click="openSelectV2rayVersion">[[ status.xray.version ]]</a-tag>
  86. <a-tag color="blue" @click="stopXrayService">{{ i18n "pages.index.stopXray" }}</a-tag>
  87. <a-tag color="blue" @click="restartXrayService">{{ i18n "pages.index.restartXray" }}</a-tag>
  88. <a-tag color="blue" @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="#87d068">[[ 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-row>
  172. </transition>
  173. </a-layout-content>
  174. </a-layout>
  175. <a-modal id="version-modal" v-model="versionModal.visible" title='{{ i18n "pages.index.xraySwitch" }}'
  176. :closable="true" @ok="() => versionModal.visible = false"
  177. :class="siderDrawer.isDarkTheme ? darkClass : ''"
  178. ok-text='{{ i18n "confirm" }}' cancel-text='{{ i18n "cancel"}}'>
  179. <h2>{{ i18n "pages.index.xraySwitchClick"}}</h2>
  180. <h2>{{ i18n "pages.index.xraySwitchClickDesk"}}</h2>
  181. <template v-for="version, index in versionModal.versions">
  182. <a-tag :color="index % 2 == 0 ? 'blue' : 'green'"
  183. style="margin: 10px" @click="switchV2rayVersion(version)">
  184. [[ version ]]
  185. </a-tag>
  186. </template>
  187. </a-modal>
  188. </a-layout>
  189. {{template "js" .}}
  190. <script>
  191. const State = {
  192. Running: "running",
  193. Stop: "stop",
  194. Error: "error",
  195. }
  196. Object.freeze(State);
  197. class CurTotal {
  198. constructor(current, total) {
  199. this.current = current;
  200. this.total = total;
  201. }
  202. get percent() {
  203. if (this.total === 0) {
  204. return 0;
  205. }
  206. return toFixed(this.current / this.total * 100, 2);
  207. }
  208. get color() {
  209. const percent = this.percent;
  210. if (percent < 80) {
  211. return '#67C23A';
  212. } else if (percent < 90) {
  213. return '#E6A23C';
  214. } else {
  215. return '#F56C6C';
  216. }
  217. }
  218. }
  219. class Status {
  220. constructor(data) {
  221. this.cpu = new CurTotal(0, 0);
  222. this.disk = new CurTotal(0, 0);
  223. this.loads = [0, 0, 0];
  224. this.mem = new CurTotal(0, 0);
  225. this.netIO = {up: 0, down: 0};
  226. this.netTraffic = {sent: 0, recv: 0};
  227. this.swap = new CurTotal(0, 0);
  228. this.tcpCount = 0;
  229. this.udpCount = 0;
  230. this.uptime = 0;
  231. this.xray = {state: State.Stop, errorMsg: "", version: "", color: ""};
  232. if (data == null) {
  233. return;
  234. }
  235. this.cpu = new CurTotal(data.cpu, 100);
  236. this.disk = new CurTotal(data.disk.current, data.disk.total);
  237. this.loads = data.loads.map(load => toFixed(load, 2));
  238. this.mem = new CurTotal(data.mem.current, data.mem.total);
  239. this.netIO = data.netIO;
  240. this.netTraffic = data.netTraffic;
  241. this.swap = new CurTotal(data.swap.current, data.swap.total);
  242. this.tcpCount = data.tcpCount;
  243. this.udpCount = data.udpCount;
  244. this.uptime = data.uptime;
  245. this.xray = data.xray;
  246. switch (this.xray.state) {
  247. case State.Running:
  248. this.xray.color = "green";
  249. break;
  250. case State.Stop:
  251. this.xray.color = "orange";
  252. break;
  253. case State.Error:
  254. this.xray.color = "red";
  255. break;
  256. default:
  257. this.xray.color = "gray";
  258. }
  259. }
  260. }
  261. const versionModal = {
  262. visible: false,
  263. versions: [],
  264. show(versions) {
  265. this.visible = true;
  266. this.versions = versions;
  267. },
  268. hide() {
  269. this.visible = false;
  270. },
  271. };
  272. const app = new Vue({
  273. delimiters: ['[[', ']]'],
  274. el: '#app',
  275. data: {
  276. siderDrawer,
  277. status: new Status(),
  278. versionModal,
  279. spinning: false,
  280. loadingTip: '{{ i18n "loading"}}',
  281. },
  282. methods: {
  283. loading(spinning, tip = '{{ i18n "loading"}}') {
  284. this.spinning = spinning;
  285. this.loadingTip = tip;
  286. },
  287. async getStatus() {
  288. const msg = await HttpUtil.post('/server/status');
  289. if (msg.success) {
  290. this.setStatus(msg.obj);
  291. }
  292. },
  293. setStatus(data) {
  294. this.status = new Status(data);
  295. },
  296. async openSelectV2rayVersion() {
  297. this.loading(true);
  298. const msg = await HttpUtil.post('server/getXrayVersion');
  299. this.loading(false);
  300. if (!msg.success) {
  301. return;
  302. }
  303. versionModal.show(msg.obj);
  304. },
  305. switchV2rayVersion(version) {
  306. this.$confirm({
  307. title: '{{ i18n "pages.index.xraySwitchVersionDialog"}}',
  308. content: '{{ i18n "pages.index.xraySwitchVersionDialogDesc"}}' + ` ${version}?`,
  309. okText: '{{ i18n "confirm"}}',
  310. class: siderDrawer.isDarkTheme ? darkClass : '',
  311. cancelText: '{{ i18n "cancel"}}',
  312. onOk: async () => {
  313. versionModal.hide();
  314. this.loading(true, '{{ i18n "pages.index.dontRefreshh"}}');
  315. await HttpUtil.post(`/server/installXray/${version}`);
  316. this.loading(false);
  317. },
  318. });
  319. },
  320. //here add stop xray function
  321. async stopXrayService() {
  322. this.loading(true);
  323. const msg = await HttpUtil.post('server/stopXrayService');
  324. this.loading(false);
  325. if (!msg.success) {
  326. return;
  327. }
  328. },
  329. //here add restart xray function
  330. async restartXrayService() {
  331. this.loading(true);
  332. const msg = await HttpUtil.post('server/restartXrayService');
  333. this.loading(false);
  334. if (!msg.success) {
  335. return;
  336. }
  337. },
  338. },
  339. async mounted() {
  340. while (true) {
  341. try {
  342. await this.getStatus();
  343. } catch (e) {
  344. console.error(e);
  345. }
  346. await PromiseUtil.sleep(2000);
  347. }
  348. },
  349. });
  350. </script>
  351. </body>
  352. </html>