1
0

index.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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. x-ui: <a href="https://github.com/MHSanaei/3x-ui/releases" target="_blank"><a-tag color="green">3x-ui 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">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. <table style="margin: 0px; width: 100%; background-color: black; color: hsla(0,0%,100%,.65);">
  201. <tr v-for="log , index in logModal.logs">
  202. <td style="vertical-align: top;">[[ index ]]</td><td>[[ log ]]</td>
  203. </tr>
  204. </table>
  205. </a-modal>
  206. </a-layout>
  207. {{template "js" .}}
  208. <script>
  209. const State = {
  210. Running: "running",
  211. Stop: "stop",
  212. Error: "error",
  213. }
  214. Object.freeze(State);
  215. class CurTotal {
  216. constructor(current, total) {
  217. this.current = current;
  218. this.total = total;
  219. }
  220. get percent() {
  221. if (this.total === 0) {
  222. return 0;
  223. }
  224. return toFixed(this.current / this.total * 100, 2);
  225. }
  226. get color() {
  227. const percent = this.percent;
  228. if (percent < 80) {
  229. return '#67C23A';
  230. } else if (percent < 90) {
  231. return '#E6A23C';
  232. } else {
  233. return '#F56C6C';
  234. }
  235. }
  236. }
  237. class Status {
  238. constructor(data) {
  239. this.cpu = new CurTotal(0, 0);
  240. this.disk = new CurTotal(0, 0);
  241. this.loads = [0, 0, 0];
  242. this.mem = new CurTotal(0, 0);
  243. this.netIO = {up: 0, down: 0};
  244. this.netTraffic = {sent: 0, recv: 0};
  245. this.swap = new CurTotal(0, 0);
  246. this.tcpCount = 0;
  247. this.udpCount = 0;
  248. this.uptime = 0;
  249. this.xray = {state: State.Stop, errorMsg: "", version: "", color: ""};
  250. if (data == null) {
  251. return;
  252. }
  253. this.cpu = new CurTotal(data.cpu, 100);
  254. this.disk = new CurTotal(data.disk.current, data.disk.total);
  255. this.loads = data.loads.map(load => toFixed(load, 2));
  256. this.mem = new CurTotal(data.mem.current, data.mem.total);
  257. this.netIO = data.netIO;
  258. this.netTraffic = data.netTraffic;
  259. this.swap = new CurTotal(data.swap.current, data.swap.total);
  260. this.tcpCount = data.tcpCount;
  261. this.udpCount = data.udpCount;
  262. this.uptime = data.uptime;
  263. this.xray = data.xray;
  264. switch (this.xray.state) {
  265. case State.Running:
  266. this.xray.color = "green";
  267. break;
  268. case State.Stop:
  269. this.xray.color = "orange";
  270. break;
  271. case State.Error:
  272. this.xray.color = "red";
  273. break;
  274. default:
  275. this.xray.color = "gray";
  276. }
  277. }
  278. }
  279. const versionModal = {
  280. visible: false,
  281. versions: [],
  282. show(versions) {
  283. this.visible = true;
  284. this.versions = versions;
  285. },
  286. hide() {
  287. this.visible = false;
  288. },
  289. };
  290. const logModal = {
  291. visible: false,
  292. logs: '',
  293. show(logs) {
  294. this.visible = true;
  295. this.logs = logs;
  296. },
  297. hide() {
  298. this.visible = false;
  299. },
  300. };
  301. const app = new Vue({
  302. delimiters: ['[[', ']]'],
  303. el: '#app',
  304. data: {
  305. siderDrawer,
  306. status: new Status(),
  307. versionModal,
  308. logModal,
  309. spinning: false,
  310. loadingTip: '{{ i18n "loading"}}',
  311. },
  312. methods: {
  313. loading(spinning, tip = '{{ i18n "loading"}}') {
  314. this.spinning = spinning;
  315. this.loadingTip = tip;
  316. },
  317. async getStatus() {
  318. const msg = await HttpUtil.post('/server/status');
  319. if (msg.success) {
  320. this.setStatus(msg.obj);
  321. }
  322. },
  323. setStatus(data) {
  324. this.status = new Status(data);
  325. },
  326. async openSelectV2rayVersion() {
  327. this.loading(true);
  328. const msg = await HttpUtil.post('server/getXrayVersion');
  329. this.loading(false);
  330. if (!msg.success) {
  331. return;
  332. }
  333. versionModal.show(msg.obj);
  334. },
  335. switchV2rayVersion(version) {
  336. this.$confirm({
  337. title: '{{ i18n "pages.index.xraySwitchVersionDialog"}}',
  338. content: '{{ i18n "pages.index.xraySwitchVersionDialogDesc"}}' + ` ${version}?`,
  339. okText: '{{ i18n "confirm"}}',
  340. class: siderDrawer.isDarkTheme ? darkClass : '',
  341. cancelText: '{{ i18n "cancel"}}',
  342. onOk: async () => {
  343. versionModal.hide();
  344. this.loading(true, '{{ i18n "pages.index.dontRefreshh"}}');
  345. await HttpUtil.post(`/server/installXray/${version}`);
  346. this.loading(false);
  347. },
  348. });
  349. },
  350. //here add stop xray function
  351. async stopXrayService() {
  352. this.loading(true);
  353. const msg = await HttpUtil.post('server/stopXrayService');
  354. this.loading(false);
  355. if (!msg.success) {
  356. return;
  357. }
  358. },
  359. //here add restart xray function
  360. async restartXrayService() {
  361. this.loading(true);
  362. const msg = await HttpUtil.post('server/restartXrayService');
  363. this.loading(false);
  364. if (!msg.success) {
  365. return;
  366. }
  367. },
  368. async openLogs(){
  369. this.loading(true);
  370. const msg = await HttpUtil.post('server/logs');
  371. this.loading(false);
  372. if (!msg.success) {
  373. return;
  374. }
  375. logModal.show(msg.obj);
  376. }
  377. },
  378. async mounted() {
  379. while (true) {
  380. try {
  381. await this.getStatus();
  382. } catch (e) {
  383. console.error(e);
  384. }
  385. await PromiseUtil.sleep(2000);
  386. }
  387. },
  388. });
  389. </script>
  390. </body>
  391. </html>