index.html 14 KB

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