index.html 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. {{ template "page/head_start" .}}
  2. <style>
  3. @media (min-width: 769px) {
  4. .ant-layout-content {
  5. margin: 24px 16px;
  6. }
  7. }
  8. .ant-card-dark h2 {
  9. color: var(--dark-color-text-primary);
  10. }
  11. .ant-backup-list-item {
  12. gap: 10px;
  13. }
  14. .ant-version-list-item {
  15. --padding: 12px;
  16. padding: var(--padding) !important;
  17. gap: var(--padding);
  18. }
  19. .dark .ant-version-list-item svg{
  20. color: var(--dark-color-text-primary);
  21. }
  22. .dark .ant-backup-list-item svg,
  23. .dark .ant-badge-status-text,
  24. .dark .ant-card-extra {
  25. color: var(--dark-color-text-primary);
  26. }
  27. .dark .ant-card-actions>li {
  28. color: rgba(255, 255, 255, 0.55);
  29. }
  30. .dark .ant-radio-inner {
  31. background-color: var(--dark-color-surface-100);
  32. border-color: var(--dark-color-surface-600);
  33. }
  34. .dark .ant-radio-checked .ant-radio-inner {
  35. border-color: var(--color-primary-100);
  36. }
  37. .dark .ant-backup-list,
  38. .dark .ant-version-list,
  39. .dark .ant-card-actions,
  40. .dark .ant-card-actions>li:not(:last-child) {
  41. border-color: var(--dark-color-stroke);
  42. }
  43. .ant-card-actions {
  44. background: transparent;
  45. }
  46. .ip-hidden {
  47. -webkit-user-select: none;
  48. -moz-user-select: none;
  49. user-select: none;
  50. filter: blur(10px);
  51. }
  52. .running-animation .ant-badge-status-dot {
  53. animation: runningAnimation 1.2s linear infinite;
  54. }
  55. .running-animation .ant-badge-status-processing:after {
  56. border-color: var(--color-primary-100);
  57. }
  58. @keyframes runningAnimation {
  59. 0%,
  60. 50%,
  61. 100% {
  62. transform: scale(1);
  63. opacity: 1;
  64. }
  65. 10% {
  66. transform: scale(1.5);
  67. opacity: .2;
  68. }
  69. }
  70. </style>
  71. {{ template "page/head_end" .}}
  72. {{ template "page/body_start" .}}
  73. <a-layout id="app" v-cloak :class="themeSwitcher.currentTheme">
  74. <a-sidebar></a-sidebar>
  75. <a-layout id="content-layout">
  76. <a-layout-content>
  77. <a-spin :spinning="loadingStates.spinning" :delay="200" :tip="loadingTip">
  78. <transition name="list" appear>
  79. <a-alert type="error" v-if="showAlert && loadingStates.fetched" :style="{ marginBottom: '10px' }"
  80. message='{{ i18n "secAlertTitle" }}'
  81. color="red"
  82. description='{{ i18n "secAlertSsl" }}'
  83. show-icon closable>
  84. </a-alert>
  85. </transition>
  86. <transition name="list" appear>
  87. <template>
  88. <a-row v-if="!loadingStates.fetched">
  89. <a-card :style="{ textAlign: 'center', padding: '30px 0', marginTop: '10px', background: 'transparent', border: 'none' }">
  90. <a-spin tip='{{ i18n "loading" }}'></a-spin>
  91. </a-card>
  92. </a-row>
  93. <a-row :gutter="[isMobile ? 8 : 16, isMobile ? 0 : 12]" v-else>
  94. <a-col>
  95. <a-card hoverable>
  96. <a-row :gutter="[0, isMobile ? 16 : 0]">
  97. <a-col :sm="24" :md="12">
  98. <a-row>
  99. <a-col :span="12" :style="{ textAlign: 'center' }">
  100. <a-progress type="dashboard" status="normal"
  101. :stroke-color="status.cpu.color"
  102. :percent="status.cpu.percent"></a-progress>
  103. <div>
  104. <b>{{ i18n "pages.index.cpu" }}:</b> [[ CPUFormatter.cpuCoreFormat(status.cpuCores) ]]
  105. <a-tooltip>
  106. <a-icon type="area-chart"></a-icon>
  107. <template slot="title">
  108. <div><b>{{ i18n "pages.index.logicalProcessors" }}:</b> [[ (status.logicalPro) ]]</div>
  109. <div><b>{{ i18n "pages.index.frequency" }}:</b> [[ CPUFormatter.cpuSpeedFormat(status.cpuSpeedMhz) ]]</div>
  110. </template>
  111. </a-tooltip>
  112. </div>
  113. </a-col>
  114. <a-col :span="12" :style="{ textAlign: 'center' }">
  115. <a-progress type="dashboard" status="normal"
  116. :stroke-color="status.mem.color"
  117. :percent="status.mem.percent"></a-progress>
  118. <div>
  119. <b>{{ i18n "pages.index.memory"}}:</b> [[ SizeFormatter.sizeFormat(status.mem.current) ]] / [[ SizeFormatter.sizeFormat(status.mem.total) ]]
  120. </div>
  121. </a-col>
  122. </a-row>
  123. </a-col>
  124. <a-col :sm="24" :md="12">
  125. <a-row>
  126. <a-col :span="12" :style="{ textAlign: 'center' }">
  127. <a-progress type="dashboard" status="normal"
  128. :stroke-color="status.swap.color"
  129. :percent="status.swap.percent"></a-progress>
  130. <div>
  131. <b>{{ i18n "pages.index.swap" }}:</b> [[ SizeFormatter.sizeFormat(status.swap.current) ]] / [[ SizeFormatter.sizeFormat(status.swap.total) ]]
  132. </div>
  133. </a-col>
  134. <a-col :span="12" :style="{ textAlign: 'center' }">
  135. <a-progress type="dashboard" status="normal"
  136. :stroke-color="status.disk.color"
  137. :percent="status.disk.percent"></a-progress>
  138. <div>
  139. <b>{{ i18n "pages.index.storage"}}:</b> [[ SizeFormatter.sizeFormat(status.disk.current) ]] / [[ SizeFormatter.sizeFormat(status.disk.total) ]]
  140. </div>
  141. </a-col>
  142. </a-row>
  143. </a-col>
  144. </a-row>
  145. </a-card>
  146. </a-col>
  147. <a-col :sm="24" :lg="12">
  148. <a-card hoverable>
  149. <template #title>
  150. <a-space direction="horizontal">
  151. <span>{{ i18n "pages.index.xrayStatus" }}</span>
  152. <a-tag v-if="isMobile && status.xray.version != 'Unknown'" color="green">
  153. v[[ status.xray.version ]]
  154. </a-tag>
  155. </a-space>
  156. </template>
  157. <template #extra>
  158. <template v-if="status.xray.state != 'error'">
  159. <a-badge status="processing" class="running-animation" :text="status.xray.stateMsg" :color="status.xray.color"/>
  160. </template>
  161. <template v-else>
  162. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  163. <span slot="title">
  164. <a-row type="flex" align="middle" justify="space-between">
  165. <a-col>
  166. <span>{{ i18n "pages.index.xrayErrorPopoverTitle" }}</span>
  167. </a-col>
  168. <a-col>
  169. <a-icon type="bars" :style="{ cursor: 'pointer', float: 'right' }" @click="openLogs()"></a-icon>
  170. </a-col>
  171. <a-col>
  172. <a-icon type="bars" :style="{ cursor: 'pointer', float: 'right' }" @click="openXrayLogs()"></a-icon>
  173. </a-col>
  174. </a-row>
  175. </span>
  176. <template slot="content">
  177. <span :style="{ maxWidth: '400px' }" v-for="line in status.xray.errorMsg.split('\n')">[[ line ]]</span>
  178. </template>
  179. <a-badge :text="status.xray.stateMsg" :color="status.xray.color"/>
  180. </a-popover>
  181. </template>
  182. </template>
  183. <template #actions>
  184. <a-space v-if="app.ipLimitEnable" direction="horizontal" @click="openXrayLogs()" :style="{ justifyContent: 'center' }">
  185. <a-icon type="bars"></a-icon>
  186. <span v-if="!isMobile">{{ i18n "pages.index.logs" }}</span>
  187. </a-space>
  188. <a-space direction="horizontal" @click="stopXrayService" :style="{ justifyContent: 'center' }">
  189. <a-icon type="poweroff"></a-icon>
  190. <span v-if="!isMobile">{{ i18n "pages.index.stopXray" }}</span>
  191. </a-space>
  192. <a-space direction="horizontal" @click="restartXrayService" :style="{ justifyContent: 'center' }">
  193. <a-icon type="reload"></a-icon>
  194. <span v-if="!isMobile">{{ i18n "pages.index.restartXray" }}</span>
  195. </a-space>
  196. <a-space direction="horizontal" @click="openSelectV2rayVersion" :style="{ justifyContent: 'center' }">
  197. <a-icon type="tool"></a-icon>
  198. <span v-if="!isMobile">
  199. [[ status.xray.version != 'Unknown' ? `v${status.xray.version}` : '{{ i18n "pages.index.xraySwitch" }}' ]]
  200. </span>
  201. </a-space>
  202. </template>
  203. </a-card>
  204. </a-col>
  205. <a-col :sm="24" :lg="12">
  206. <a-card title='{{ i18n "menu.link" }}' hoverable>
  207. <template #actions>
  208. <a-space direction="horizontal" @click="openLogs()" :style="{ justifyContent: 'center' }">
  209. <a-icon type="bars"></a-icon>
  210. <span v-if="!isMobile">{{ i18n "pages.index.logs" }}</span>
  211. </a-space>
  212. <a-space direction="horizontal" @click="openConfig" :style="{ justifyContent: 'center' }">
  213. <a-icon type="control"></a-icon>
  214. <span v-if="!isMobile">{{ i18n "pages.index.config" }}</span>
  215. </a-space>
  216. <a-space direction="horizontal" @click="openBackup" :style="{ justifyContent: 'center' }">
  217. <a-icon type="cloud-server"></a-icon>
  218. <span v-if="!isMobile">{{ i18n "pages.index.backup" }}</span>
  219. </a-space>
  220. </template>
  221. </a-card>
  222. </a-col>
  223. <a-col :sm="24" :lg="12">
  224. <a-card title='3X-UI' hoverable>
  225. <a rel="noopener" href="https://github.com/MHSanaei/3x-ui/releases" target="_blank">
  226. <a-tag color="green">
  227. <span>v{{ .cur_ver }}</span>
  228. </a-tag>
  229. </a>
  230. <a rel="noopener" href="https://t.me/XrayUI" target="_blank">
  231. <a-tag color="green">
  232. <span>@XrayUI</span>
  233. </a-tag>
  234. </a>
  235. <a rel="noopener" href="https://github.com/MHSanaei/3x-ui/wiki" target="_blank">
  236. <a-tag color="purple">
  237. <span>{{ i18n "pages.index.documentation" }}</span>
  238. </a-tag>
  239. </a>
  240. </a-card>
  241. </a-col>
  242. <a-col :sm="24" :lg="12">
  243. <a-card title='{{ i18n "pages.index.operationHours" }}' hoverable>
  244. <a-tag :color="status.xray.color">Xray: [[ TimeFormatter.formatSecond(status.appStats.uptime) ]]</a-tag>
  245. <a-tag color="green">OS: [[ TimeFormatter.formatSecond(status.uptime) ]]</a-tag>
  246. </a-card>
  247. </a-col>
  248. <a-col :sm="24" :lg="12">
  249. <a-card title='{{ i18n "pages.index.systemLoad" }}' hoverable>
  250. <a-tag color="green">
  251. <a-tooltip>
  252. [[ status.loads[0] ]] | [[ status.loads[1] ]] | [[ status.loads[2] ]]
  253. <template slot="title">
  254. {{ i18n "pages.index.systemLoadDesc" }}
  255. </template>
  256. </a-tooltip>
  257. </a-tag>
  258. </a-card>
  259. </a-col>
  260. <a-col :sm="24" :lg="12">
  261. <a-card title='{{ i18n "usage"}}' hoverable>
  262. <a-tag color="green"> {{ i18n "pages.index.memory" }}: [[ SizeFormatter.sizeFormat(status.appStats.mem) ]] </a-tag>
  263. <a-tag color="green"> {{ i18n "pages.index.threads" }}: [[ status.appStats.threads ]] </a-tag>
  264. </a-card>
  265. </a-col>
  266. <a-col :sm="24" :lg="12">
  267. <a-card title='{{ i18n "pages.index.overallSpeed" }}' hoverable>
  268. <a-row :gutter="isMobile ? [8,8] : 0">
  269. <a-col :span="12">
  270. <a-custom-statistic title='{{ i18n "pages.index.upload" }}' :value="SizeFormatter.sizeFormat(status.netIO.up)">
  271. <template #prefix>
  272. <a-icon type="arrow-up" />
  273. </template>
  274. <template #suffix>
  275. /s
  276. </template>
  277. </a-custom-statistic>
  278. </a-col>
  279. <a-col :span="12">
  280. <a-custom-statistic title='{{ i18n "pages.index.download" }}' :value="SizeFormatter.sizeFormat(status.netIO.down)">
  281. <template #prefix>
  282. <a-icon type="arrow-down" />
  283. </template>
  284. <template #suffix>
  285. /s
  286. </template>
  287. </a-custom-statistic>
  288. </a-col>
  289. </a-row>
  290. </a-card>
  291. </a-col>
  292. <a-col :sm="24" :lg="12">
  293. <a-card title='{{ i18n "pages.index.totalData" }}' hoverable>
  294. <a-row :gutter="isMobile ? [8,8] : 0">
  295. <a-col :span="12">
  296. <a-custom-statistic title='{{ i18n "pages.index.sent" }}' :value="SizeFormatter.sizeFormat(status.netTraffic.sent)">
  297. <template #prefix>
  298. <a-icon type="cloud-upload" />
  299. </template>
  300. </a-custom-statistic>
  301. </a-col>
  302. <a-col :span="12">
  303. <a-custom-statistic title='{{ i18n "pages.index.received" }}' :value="SizeFormatter.sizeFormat(status.netTraffic.recv)">
  304. <template #prefix>
  305. <a-icon type="cloud-download" />
  306. </template>
  307. </a-custom-statistic>
  308. </a-col>
  309. </a-row>
  310. </a-card>
  311. </a-col>
  312. <a-col :sm="24" :lg="12">
  313. <a-card title='{{ i18n "pages.index.ipAddresses" }}' hoverable>
  314. <template #extra>
  315. <a-tooltip :placement="isMobile ? 'topRight' : 'top'">
  316. <template #title>
  317. {{ i18n "pages.index.toggleIpVisibility" }}
  318. </template>
  319. <a-icon :type="showIp ? 'eye' : 'eye-invisible'" :style="{ fontSize: '1rem' }" @click="showIp = !showIp"></a-icon>
  320. </a-tooltip>
  321. </template>
  322. <a-row :class="showIp ? 'ip-visible' : 'ip-hidden'" :gutter="isMobile ? [8,8] : 0">
  323. <a-col :span="isMobile ? 24 : 12">
  324. <a-custom-statistic title="IPv4" :value="status.publicIP.ipv4">
  325. <template #prefix>
  326. <a-icon type="global" />
  327. </template>
  328. </a-custom-statistic>
  329. </a-col>
  330. <a-col :span="isMobile ? 24 : 12">
  331. <a-custom-statistic title="IPv6" :value="status.publicIP.ipv6">
  332. <template #prefix>
  333. <a-icon type="global" />
  334. </template>
  335. </a-custom-statistic>
  336. </a-col>
  337. </a-row>
  338. </a-card>
  339. </a-col>
  340. <a-col :sm="24" :lg="12">
  341. <a-card title='{{ i18n "pages.index.connectionCount" }}' hoverable>
  342. <a-row :gutter="isMobile ? [8,8] : 0">
  343. <a-col :span="12">
  344. <a-custom-statistic title="TCP" :value="status.tcpCount">
  345. <template #prefix>
  346. <a-icon type="swap" />
  347. </template>
  348. </a-custom-statistic>
  349. </a-col>
  350. <a-col :span="12">
  351. <a-custom-statistic title="UDP" :value="status.udpCount">
  352. <template #prefix>
  353. <a-icon type="swap" />
  354. </template>
  355. </a-custom-statistic>
  356. </a-col>
  357. </a-row>
  358. </a-card>
  359. </a-col>
  360. </a-row>
  361. </template>
  362. </transition>
  363. </a-spin>
  364. </a-layout-content>
  365. </a-layout>
  366. <a-modal id="version-modal" v-model="versionModal.visible" title='{{ i18n "pages.index.xraySwitch" }}' :closable="true"
  367. @ok="() => versionModal.visible = false" :class="themeSwitcher.currentTheme" footer="">
  368. <a-collapse default-active-key="1">
  369. <a-collapse-panel key="1" header='Xray'>
  370. <a-alert type="warning" :style="{ marginBottom: '12px', width: '100%' }" message='{{ i18n "pages.index.xraySwitchClickDesk" }}' show-icon></a-alert>
  371. <a-list class="ant-version-list" bordered :style="{ width: '100%' }">
  372. <a-list-item class="ant-version-list-item" v-for="version, index in versionModal.versions">
  373. <a-tag :color="index % 2 == 0 ? 'purple' : 'green'">[[ version ]]</a-tag>
  374. <a-radio :class="themeSwitcher.currentTheme" :checked="version === `v${status.xray.version}`" @click="switchV2rayVersion(version)"></a-radio>
  375. </a-list-item>
  376. </a-list>
  377. </a-collapse-panel>
  378. <a-collapse-panel key="2" header='Geofiles'>
  379. <a-list class="ant-version-list" bordered :style="{ width: '100%' }">
  380. <a-list-item class="ant-version-list-item" v-for="file, index in ['geosite.dat', 'geoip.dat', 'geosite_IR.dat', 'geoip_IR.dat', 'geosite_RU.dat', 'geoip_RU.dat']">
  381. <a-tag :color="index % 2 == 0 ? 'purple' : 'green'">[[ file ]]</a-tag>
  382. <a-icon type="reload" @click="updateGeofile(file)" :style="{ marginRight: '8px' }"/>
  383. </a-list-item>
  384. </a-list>
  385. <div style="margin-top: 5px; display: flex; justify-content: flex-end;">
  386. <a-button @click="updateGeofile('')">{{ i18n "pages.index.geofilesUpdateAll" }}</a-button>
  387. </div>
  388. </a-collapse-panel>
  389. </a-collapse>
  390. </a-modal>
  391. <a-modal id="log-modal" v-model="logModal.visible"
  392. :closable="true" @cancel="() => logModal.visible = false"
  393. :class="themeSwitcher.currentTheme"
  394. width="800px" footer="">
  395. <template slot="title">
  396. {{ i18n "pages.index.logs" }}
  397. <a-icon :spin="logModal.loading"
  398. type="sync"
  399. :style="{ verticalAlign: 'middle', marginLeft: '10px' }"
  400. :disabled="logModal.loading"
  401. @click="openLogs()">
  402. </a-icon>
  403. </template>
  404. <a-form layout="inline">
  405. <a-form-item :style="{ marginRight: '0.5rem' }">
  406. <a-input-group compact>
  407. <a-select size="small" v-model="logModal.rows" :style="{ width: '70px' }"
  408. @change="openLogs()" :dropdown-class-name="themeSwitcher.currentTheme">
  409. <a-select-option value="10">10</a-select-option>
  410. <a-select-option value="20">20</a-select-option>
  411. <a-select-option value="50">50</a-select-option>
  412. <a-select-option value="100">100</a-select-option>
  413. <a-select-option value="500">500</a-select-option>
  414. </a-select>
  415. <a-select size="small" v-model="logModal.level" :style="{ width: '95px' }"
  416. @change="openLogs()" :dropdown-class-name="themeSwitcher.currentTheme">
  417. <a-select-option value="debug">Debug</a-select-option>
  418. <a-select-option value="info">Info</a-select-option>
  419. <a-select-option value="notice">Notice</a-select-option>
  420. <a-select-option value="warning">Warning</a-select-option>
  421. <a-select-option value="err">Error</a-select-option>
  422. </a-select>
  423. </a-input-group>
  424. </a-form-item>
  425. <a-form-item>
  426. <a-checkbox v-model="logModal.syslog" @change="openLogs()">SysLog</a-checkbox>
  427. </a-form-item>
  428. <a-form-item :style="{ float: 'right' }">
  429. <a-button type="primary" icon="download" @click="FileManager.downloadTextFile(logModal.logs?.join('\n'), 'x-ui.log')"></a-button>
  430. </a-form-item>
  431. </a-form>
  432. <div class="ant-input" :style="{ height: 'auto', maxHeight: '500px', overflow: 'auto', marginTop: '0.5rem' }" v-html="logModal.formattedLogs"></div>
  433. </a-modal>
  434. <a-modal id="xraylog-modal"
  435. v-model="xraylogModal.visible"
  436. :closable="true" @cancel="() => xraylogModal.visible = false"
  437. :class="themeSwitcher.currentTheme"
  438. width="80vw"
  439. footer="">
  440. <template slot="title">
  441. {{ i18n "pages.index.logs" }}
  442. <a-icon :spin="xraylogModal.loading"
  443. type="sync"
  444. :style="{ verticalAlign: 'middle', marginLeft: '10px' }"
  445. :disabled="xraylogModal.loading"
  446. @click="openXrayLogs()">
  447. </a-icon>
  448. </template>
  449. <a-form layout="inline">
  450. <a-form-item :style="{ marginRight: '0.5rem' }">
  451. <a-input-group compact>
  452. <a-select size="small" v-model="xraylogModal.rows" :style="{ width: '70px' }"
  453. @change="openXrayLogs()" :dropdown-class-name="themeSwitcher.currentTheme">
  454. <a-select-option value="10">10</a-select-option>
  455. <a-select-option value="20">20</a-select-option>
  456. <a-select-option value="50">50</a-select-option>
  457. <a-select-option value="100">100</a-select-option>
  458. <a-select-option value="500">500</a-select-option>
  459. </a-select>
  460. </a-input-group>
  461. </a-form-item>
  462. <a-form-item label="Filter:">
  463. <a-input size="small" v-model="xraylogModal.filter" @keyup.enter="openXrayLogs()"></a-input>
  464. </a-form-item>
  465. <a-form-item>
  466. <a-checkbox v-model="xraylogModal.showDirect" @change="openXrayLogs()">Direct</a-checkbox>
  467. <a-checkbox v-model="xraylogModal.showBlocked" @change="openXrayLogs()">Blocked</a-checkbox>
  468. <a-checkbox v-model="xraylogModal.showProxy" @change="openXrayLogs()">Proxy</a-checkbox>
  469. </a-form-item>
  470. <a-form-item :style="{ float: 'right' }">
  471. <a-button type="primary" icon="download" @click="FileManager.downloadTextFile(xraylogModal.logs?.join('\n'), 'x-ui.log')"></a-button>
  472. </a-form-item>
  473. </a-form>
  474. <div class="ant-input" :style="{ height: 'auto', maxHeight: '500px', overflow: 'auto', marginTop: '0.5rem' }" v-html="xraylogModal.formattedLogs"></div>
  475. </a-modal>
  476. <a-modal id="backup-modal"
  477. v-model="backupModal.visible"
  478. title='{{ i18n "pages.index.backupTitle" }}'
  479. :closable="true"
  480. footer=""
  481. :class="themeSwitcher.currentTheme">
  482. <a-list class="ant-backup-list" bordered :style="{ width: '100%' }">
  483. <a-list-item class="ant-backup-list-item">
  484. <a-list-item-meta>
  485. <template #title>{{ i18n "pages.index.exportDatabase" }}</template>
  486. <template #description>{{ i18n "pages.index.exportDatabaseDesc" }}</template>
  487. </a-list-item-meta>
  488. <a-button @click="exportDatabase()" type="primary" icon="download"/>
  489. </a-list-item>
  490. <a-list-item class="ant-backup-list-item">
  491. <a-list-item-meta>
  492. <template #title>{{ i18n "pages.index.importDatabase" }}</template>
  493. <template #description>{{ i18n "pages.index.importDatabaseDesc" }}</template>
  494. </a-list-item-meta>
  495. <a-button @click="importDatabase()" type="primary" icon="upload" />
  496. </a-list-item>
  497. </a-list>
  498. </a-modal>
  499. </a-layout>
  500. {{template "page/body_scripts" .}}
  501. {{template "component/aSidebar" .}}
  502. {{template "component/aThemeSwitch" .}}
  503. {{template "component/aCustomStatistic" .}}
  504. {{template "modals/textModal"}}
  505. <script>
  506. class CurTotal {
  507. constructor(current, total) {
  508. this.current = current;
  509. this.total = total;
  510. }
  511. get percent() {
  512. if (this.total === 0) {
  513. return 0;
  514. }
  515. return NumberFormatter.toFixed(this.current / this.total * 100, 2);
  516. }
  517. get color() {
  518. const percent = this.percent;
  519. if (percent < 80) {
  520. return '#008771'; // Green
  521. } else if (percent < 90) {
  522. return "#f37b24"; // Orange
  523. } else {
  524. return "#cf3c3c"; // Red
  525. }
  526. }
  527. }
  528. class Status {
  529. constructor(data) {
  530. this.cpu = new CurTotal(0, 0);
  531. this.cpuCores = 0;
  532. this.logicalPro = 0;
  533. this.cpuSpeedMhz = 0;
  534. this.disk = new CurTotal(0, 0);
  535. this.loads = [0, 0, 0];
  536. this.mem = new CurTotal(0, 0);
  537. this.netIO = { up: 0, down: 0 };
  538. this.netTraffic = { sent: 0, recv: 0 };
  539. this.publicIP = { ipv4: 0, ipv6: 0 };
  540. this.swap = new CurTotal(0, 0);
  541. this.tcpCount = 0;
  542. this.udpCount = 0;
  543. this.uptime = 0;
  544. this.appUptime = 0;
  545. this.appStats = {threads: 0, mem: 0, uptime: 0};
  546. this.xray = { state: 'stop', stateMsg: "", errorMsg: "", version: "", color: "" };
  547. if (data == null) {
  548. return;
  549. }
  550. this.cpu = new CurTotal(data.cpu, 100);
  551. this.cpuCores = data.cpuCores;
  552. this.logicalPro = data.logicalPro;
  553. this.cpuSpeedMhz = data.cpuSpeedMhz;
  554. this.disk = new CurTotal(data.disk.current, data.disk.total);
  555. this.loads = data.loads.map(load => NumberFormatter.toFixed(load, 2));
  556. this.mem = new CurTotal(data.mem.current, data.mem.total);
  557. this.netIO = data.netIO;
  558. this.netTraffic = data.netTraffic;
  559. this.publicIP = data.publicIP;
  560. this.swap = new CurTotal(data.swap.current, data.swap.total);
  561. this.tcpCount = data.tcpCount;
  562. this.udpCount = data.udpCount;
  563. this.uptime = data.uptime;
  564. this.appUptime = data.appUptime;
  565. this.appStats = data.appStats;
  566. this.xray = data.xray;
  567. switch (this.xray.state) {
  568. case 'running':
  569. this.xray.color = "green";
  570. this.xray.stateMsg = '{{ i18n "pages.index.xrayStatusRunning" }}';
  571. break;
  572. case 'stop':
  573. this.xray.color = "orange";
  574. this.xray.stateMsg = '{{ i18n "pages.index.xrayStatusStop" }}';
  575. break;
  576. case 'error':
  577. this.xray.color = "red";
  578. this.xray.stateMsg ='{{ i18n "pages.index.xrayStatusError" }}';
  579. break;
  580. default:
  581. this.xray.color = "gray";
  582. this.xray.stateMsg = '{{ i18n "pages.index.xrayStatusUnknown" }}';
  583. break;
  584. }
  585. }
  586. }
  587. const versionModal = {
  588. visible: false,
  589. versions: [],
  590. show(versions) {
  591. this.visible = true;
  592. this.versions = versions;
  593. },
  594. hide() {
  595. this.visible = false;
  596. },
  597. };
  598. const logModal = {
  599. visible: false,
  600. logs: [],
  601. rows: 20,
  602. level: 'info',
  603. syslog: false,
  604. loading: false,
  605. show(logs) {
  606. this.visible = true;
  607. this.logs = logs;
  608. this.formattedLogs = this.logs?.length > 0 ? this.formatLogs(this.logs) : "No Record...";
  609. },
  610. formatLogs(logs) {
  611. let formattedLogs = '';
  612. const levels = ["DEBUG","INFO","NOTICE","WARNING","ERROR"];
  613. const levelColors = ["#3c89e8","#008771","#008771","#f37b24","#e04141","#bcbcbc"];
  614. logs.forEach((log, index) => {
  615. let [data, message] = log.split(" - ",2);
  616. const parts = data.split(" ")
  617. if(index>0) formattedLogs += '<br>';
  618. if (parts.length === 3) {
  619. const d = parts[0];
  620. const t = parts[1];
  621. const level = parts[2];
  622. const levelIndex = levels.indexOf(level,levels) || 5;
  623. //formattedLogs += `<span style="color: gray;">${index + 1}.</span>`;
  624. formattedLogs += `<span style="color: ${levelColors[0]};">${d} ${t}</span> `;
  625. formattedLogs += `<span style="color: ${levelColors[levelIndex]}">${level}</span>`;
  626. } else {
  627. const levelIndex = levels.indexOf(data,levels) || 5;
  628. formattedLogs += `<span style="color: ${levelColors[levelIndex]}">${data}</span>`;
  629. }
  630. if(message){
  631. if(message.startsWith("XRAY:"))
  632. message = "<b>XRAY: </b>" + message.substring(5);
  633. else
  634. message = "<b>X-UI: </b>" + message;
  635. }
  636. formattedLogs += message ? ' - ' + message : '';
  637. });
  638. return formattedLogs;
  639. },
  640. hide() {
  641. this.visible = false;
  642. },
  643. };
  644. const xraylogModal = {
  645. visible: false,
  646. logs: [],
  647. rows: 20,
  648. showDirect: true,
  649. showBlocked: true,
  650. showProxy: true,
  651. loading: false,
  652. show(logs) {
  653. this.visible = true;
  654. this.logs = logs;
  655. this.formattedLogs = this.logs?.length > 0 ? this.formatLogs(this.logs) : "No Record...";
  656. },
  657. formatLogs(logs) {
  658. let formattedLogs = '';
  659. logs.forEach((log, index) => {
  660. if(index > 0) formattedLogs += '<br>';
  661. const parts = log.split(' ');
  662. if(parts.length === 10) {
  663. const dateTime = `<b>${parts[0]} ${parts[1]}</b>`;
  664. const from = `<b>${parts[3]}</b>`;
  665. const to = `<b>${parts[5].replace(/^\/+/, "")}</b>`;
  666. let outboundColor = '';
  667. if (parts[9] === "b") {
  668. outboundColor = ' style="color: #e04141;"'; //red for blocked
  669. }
  670. else if (parts[9] === "p") {
  671. outboundColor = ' style="color: #3c89e8;"'; //blue for proxies
  672. }
  673. formattedLogs += `<span${outboundColor}>
  674. ${dateTime}
  675. ${parts[2]}
  676. ${from}
  677. ${parts[4]}
  678. ${to}
  679. ${parts.slice(6, 9).join(' ')}
  680. </span>`;
  681. } else {
  682. formattedLogs += `<span>${log}</span>`;
  683. }
  684. });
  685. return formattedLogs;
  686. },
  687. hide() {
  688. this.visible = false;
  689. },
  690. };
  691. const backupModal = {
  692. visible: false,
  693. show() {
  694. this.visible = true;
  695. },
  696. hide() {
  697. this.visible = false;
  698. },
  699. };
  700. const app = new Vue({
  701. delimiters: ['[[', ']]'],
  702. el: '#app',
  703. mixins: [MediaQueryMixin],
  704. data: {
  705. themeSwitcher,
  706. loadingStates: {
  707. fetched: false,
  708. spinning: false
  709. },
  710. status: new Status(),
  711. versionModal,
  712. logModal,
  713. xraylogModal,
  714. backupModal,
  715. loadingTip: '{{ i18n "loading"}}',
  716. showAlert: false,
  717. showIp: false,
  718. ipLimitEnable: false,
  719. },
  720. methods: {
  721. loading(spinning, tip = '{{ i18n "loading"}}') {
  722. this.loadingStates.spinning = spinning;
  723. this.loadingTip = tip;
  724. },
  725. async getStatus() {
  726. try {
  727. const msg = await HttpUtil.post('/server/status');
  728. if (msg.success) {
  729. if (!this.loadingStates.fetched) {
  730. this.loadingStates.fetched = true;
  731. }
  732. this.setStatus(msg.obj, true);
  733. }
  734. } catch (e) {
  735. console.error("Failed to get status:", e);
  736. }
  737. },
  738. setStatus(data) {
  739. this.status = new Status(data);
  740. },
  741. async openSelectV2rayVersion() {
  742. this.loading(true);
  743. const msg = await HttpUtil.post('server/getXrayVersion');
  744. this.loading(false);
  745. if (!msg.success) {
  746. return;
  747. }
  748. versionModal.show(msg.obj);
  749. },
  750. switchV2rayVersion(version) {
  751. this.$confirm({
  752. title: '{{ i18n "pages.index.xraySwitchVersionDialog"}}',
  753. content: '{{ i18n "pages.index.xraySwitchVersionDialogDesc"}}'.replace('#version#', version),
  754. okText: '{{ i18n "confirm"}}',
  755. class: themeSwitcher.currentTheme,
  756. cancelText: '{{ i18n "cancel"}}',
  757. onOk: async () => {
  758. versionModal.hide();
  759. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  760. await HttpUtil.post(`/server/installXray/${version}`);
  761. this.loading(false);
  762. },
  763. });
  764. },
  765. updateGeofile(fileName) {
  766. const isSingleFile = !!fileName;
  767. this.$confirm({
  768. title: '{{ i18n "pages.index.geofileUpdateDialog" }}',
  769. content: isSingleFile
  770. ? '{{ i18n "pages.index.geofileUpdateDialogDesc" }}'.replace("#filename#", fileName)
  771. : '{{ i18n "pages.index.geofilesUpdateDialogDesc" }}',
  772. okText: '{{ i18n "confirm"}}',
  773. class: themeSwitcher.currentTheme,
  774. cancelText: '{{ i18n "cancel"}}',
  775. onOk: async () => {
  776. versionModal.hide();
  777. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  778. const url = isSingleFile
  779. ? `/server/updateGeofile/${fileName}`
  780. : `/server/updateGeofile`;
  781. await HttpUtil.post(url);
  782. this.loading(false);
  783. },
  784. });
  785. },
  786. async stopXrayService() {
  787. this.loading(true);
  788. const msg = await HttpUtil.post('server/stopXrayService');
  789. this.loading(false);
  790. if (!msg.success) {
  791. return;
  792. }
  793. },
  794. async restartXrayService() {
  795. this.loading(true);
  796. const msg = await HttpUtil.post('server/restartXrayService');
  797. this.loading(false);
  798. if (!msg.success) {
  799. return;
  800. }
  801. },
  802. async openLogs(){
  803. logModal.loading = true;
  804. const msg = await HttpUtil.post('server/logs/'+logModal.rows,{level: logModal.level, syslog: logModal.syslog});
  805. if (!msg.success) {
  806. return;
  807. }
  808. logModal.show(msg.obj);
  809. await PromiseUtil.sleep(500);
  810. logModal.loading = false;
  811. },
  812. async openXrayLogs(){
  813. xraylogModal.loading = true;
  814. const msg = await HttpUtil.post('server/xraylogs/'+xraylogModal.rows,{filter: xraylogModal.filter, showDirect: xraylogModal.showDirect, showBlocked: xraylogModal.showBlocked, showProxy: xraylogModal.showProxy});
  815. if (!msg.success) {
  816. return;
  817. }
  818. xraylogModal.show(msg.obj);
  819. await PromiseUtil.sleep(500);
  820. xraylogModal.loading = false;
  821. },
  822. async openConfig() {
  823. this.loading(true);
  824. const msg = await HttpUtil.post('server/getConfigJson');
  825. this.loading(false);
  826. if (!msg.success) {
  827. return;
  828. }
  829. txtModal.show('config.json', JSON.stringify(msg.obj, null, 2), 'config.json');
  830. },
  831. openBackup() {
  832. backupModal.show();
  833. },
  834. exportDatabase() {
  835. window.location = basePath + 'server/getDb';
  836. },
  837. importDatabase() {
  838. const fileInput = document.createElement('input');
  839. fileInput.type = 'file';
  840. fileInput.accept = '.db';
  841. fileInput.addEventListener('change', async (event) => {
  842. const dbFile = event.target.files[0];
  843. if (dbFile) {
  844. const formData = new FormData();
  845. formData.append('db', dbFile);
  846. backupModal.hide();
  847. this.loading(true);
  848. const uploadMsg = await HttpUtil.post('server/importDB', formData, {
  849. headers: {
  850. 'Content-Type': 'multipart/form-data',
  851. }
  852. });
  853. this.loading(false);
  854. if (!uploadMsg.success) {
  855. return;
  856. }
  857. this.loading(true);
  858. const restartMsg = await HttpUtil.post("/panel/setting/restartPanel");
  859. this.loading(false);
  860. if (restartMsg.success) {
  861. this.loading(true);
  862. await PromiseUtil.sleep(5000);
  863. location.reload();
  864. }
  865. }
  866. });
  867. fileInput.click();
  868. },
  869. },
  870. async mounted() {
  871. if (window.location.protocol !== "https:") {
  872. this.showAlert = true;
  873. }
  874. const msg = await HttpUtil.post('/panel/setting/defaultSettings');
  875. if (msg.success) {
  876. this.ipLimitEnable = msg.obj.ipLimitEnable;
  877. }
  878. while (true) {
  879. try {
  880. await this.getStatus();
  881. } catch (e) {
  882. console.error(e);
  883. }
  884. await PromiseUtil.sleep(2000);
  885. }
  886. },
  887. });
  888. </script>
  889. {{ template "page/body_end" .}}