index.html 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  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. </a-collapse-panel>
  386. </a-collapse>
  387. </a-modal>
  388. <a-modal id="log-modal" v-model="logModal.visible"
  389. :closable="true" @cancel="() => logModal.visible = false"
  390. :class="themeSwitcher.currentTheme"
  391. width="800px" footer="">
  392. <template slot="title">
  393. {{ i18n "pages.index.logs" }}
  394. <a-icon :spin="logModal.loading"
  395. type="sync"
  396. :style="{ verticalAlign: 'middle', marginLeft: '10px' }"
  397. :disabled="logModal.loading"
  398. @click="openLogs()">
  399. </a-icon>
  400. </template>
  401. <a-form layout="inline">
  402. <a-form-item :style="{ marginRight: '0.5rem' }">
  403. <a-input-group compact>
  404. <a-select size="small" v-model="logModal.rows" :style="{ width: '70px' }"
  405. @change="openLogs()" :dropdown-class-name="themeSwitcher.currentTheme">
  406. <a-select-option value="10">10</a-select-option>
  407. <a-select-option value="20">20</a-select-option>
  408. <a-select-option value="50">50</a-select-option>
  409. <a-select-option value="100">100</a-select-option>
  410. <a-select-option value="500">500</a-select-option>
  411. </a-select>
  412. <a-select size="small" v-model="logModal.level" :style="{ width: '95px' }"
  413. @change="openLogs()" :dropdown-class-name="themeSwitcher.currentTheme">
  414. <a-select-option value="debug">Debug</a-select-option>
  415. <a-select-option value="info">Info</a-select-option>
  416. <a-select-option value="notice">Notice</a-select-option>
  417. <a-select-option value="warning">Warning</a-select-option>
  418. <a-select-option value="err">Error</a-select-option>
  419. </a-select>
  420. </a-input-group>
  421. </a-form-item>
  422. <a-form-item>
  423. <a-checkbox v-model="logModal.syslog" @change="openLogs()">SysLog</a-checkbox>
  424. </a-form-item>
  425. <a-form-item :style="{ float: 'right' }">
  426. <a-button type="primary" icon="download" @click="FileManager.downloadTextFile(logModal.logs?.join('\n'), 'x-ui.log')"></a-button>
  427. </a-form-item>
  428. </a-form>
  429. <div class="ant-input" :style="{ height: 'auto', maxHeight: '500px', overflow: 'auto', marginTop: '0.5rem' }" v-html="logModal.formattedLogs"></div>
  430. </a-modal>
  431. <a-modal id="xraylog-modal"
  432. v-model="xraylogModal.visible"
  433. :closable="true" @cancel="() => xraylogModal.visible = false"
  434. :class="themeSwitcher.currentTheme"
  435. width="80vw"
  436. footer="">
  437. <template slot="title">
  438. {{ i18n "pages.index.logs" }}
  439. <a-icon :spin="xraylogModal.loading"
  440. type="sync"
  441. :style="{ verticalAlign: 'middle', marginLeft: '10px' }"
  442. :disabled="xraylogModal.loading"
  443. @click="openXrayLogs()">
  444. </a-icon>
  445. </template>
  446. <a-form layout="inline">
  447. <a-form-item :style="{ marginRight: '0.5rem' }">
  448. <a-input-group compact>
  449. <a-select size="small" v-model="xraylogModal.rows" :style="{ width: '70px' }"
  450. @change="openXrayLogs()" :dropdown-class-name="themeSwitcher.currentTheme">
  451. <a-select-option value="10">10</a-select-option>
  452. <a-select-option value="20">20</a-select-option>
  453. <a-select-option value="50">50</a-select-option>
  454. <a-select-option value="100">100</a-select-option>
  455. <a-select-option value="500">500</a-select-option>
  456. </a-select>
  457. </a-input-group>
  458. </a-form-item>
  459. <a-form-item :style="{ float: 'right' }">
  460. <a-button type="primary" icon="download" @click="FileManager.downloadTextFile(xraylogModal.logs?.join('\n'), 'x-ui.log')"></a-button>
  461. </a-form-item>
  462. </a-form>
  463. <div class="ant-input" :style="{ height: 'auto', maxHeight: '500px', overflow: 'auto', marginTop: '0.5rem' }" v-html="xraylogModal.formattedLogs"></div>
  464. </a-modal>
  465. <a-modal id="backup-modal"
  466. v-model="backupModal.visible"
  467. title='{{ i18n "pages.index.backupTitle" }}'
  468. :closable="true"
  469. footer=""
  470. :class="themeSwitcher.currentTheme">
  471. <a-list class="ant-backup-list" bordered :style="{ width: '100%' }">
  472. <a-list-item class="ant-backup-list-item">
  473. <a-list-item-meta>
  474. <template #title>{{ i18n "pages.index.exportDatabase" }}</template>
  475. <template #description>{{ i18n "pages.index.exportDatabaseDesc" }}</template>
  476. </a-list-item-meta>
  477. <a-button @click="exportDatabase()" type="primary" icon="download"/>
  478. </a-list-item>
  479. <a-list-item class="ant-backup-list-item">
  480. <a-list-item-meta>
  481. <template #title>{{ i18n "pages.index.importDatabase" }}</template>
  482. <template #description>{{ i18n "pages.index.importDatabaseDesc" }}</template>
  483. </a-list-item-meta>
  484. <a-button @click="importDatabase()" type="primary" icon="upload" />
  485. </a-list-item>
  486. </a-list>
  487. </a-modal>
  488. </a-layout>
  489. {{template "page/body_scripts" .}}
  490. {{template "component/aSidebar" .}}
  491. {{template "component/aThemeSwitch" .}}
  492. {{template "component/aCustomStatistic" .}}
  493. {{template "modals/textModal"}}
  494. <script>
  495. class CurTotal {
  496. constructor(current, total) {
  497. this.current = current;
  498. this.total = total;
  499. }
  500. get percent() {
  501. if (this.total === 0) {
  502. return 0;
  503. }
  504. return NumberFormatter.toFixed(this.current / this.total * 100, 2);
  505. }
  506. get color() {
  507. const percent = this.percent;
  508. if (percent < 80) {
  509. return '#008771'; // Green
  510. } else if (percent < 90) {
  511. return "#f37b24"; // Orange
  512. } else {
  513. return "#cf3c3c"; // Red
  514. }
  515. }
  516. }
  517. class Status {
  518. constructor(data) {
  519. this.cpu = new CurTotal(0, 0);
  520. this.cpuCores = 0;
  521. this.logicalPro = 0;
  522. this.cpuSpeedMhz = 0;
  523. this.disk = new CurTotal(0, 0);
  524. this.loads = [0, 0, 0];
  525. this.mem = new CurTotal(0, 0);
  526. this.netIO = { up: 0, down: 0 };
  527. this.netTraffic = { sent: 0, recv: 0 };
  528. this.publicIP = { ipv4: 0, ipv6: 0 };
  529. this.swap = new CurTotal(0, 0);
  530. this.tcpCount = 0;
  531. this.udpCount = 0;
  532. this.uptime = 0;
  533. this.appUptime = 0;
  534. this.appStats = {threads: 0, mem: 0, uptime: 0};
  535. this.xray = { state: 'stop', stateMsg: "", errorMsg: "", version: "", color: "" };
  536. if (data == null) {
  537. return;
  538. }
  539. this.cpu = new CurTotal(data.cpu, 100);
  540. this.cpuCores = data.cpuCores;
  541. this.logicalPro = data.logicalPro;
  542. this.cpuSpeedMhz = data.cpuSpeedMhz;
  543. this.disk = new CurTotal(data.disk.current, data.disk.total);
  544. this.loads = data.loads.map(load => NumberFormatter.toFixed(load, 2));
  545. this.mem = new CurTotal(data.mem.current, data.mem.total);
  546. this.netIO = data.netIO;
  547. this.netTraffic = data.netTraffic;
  548. this.publicIP = data.publicIP;
  549. this.swap = new CurTotal(data.swap.current, data.swap.total);
  550. this.tcpCount = data.tcpCount;
  551. this.udpCount = data.udpCount;
  552. this.uptime = data.uptime;
  553. this.appUptime = data.appUptime;
  554. this.appStats = data.appStats;
  555. this.xray = data.xray;
  556. switch (this.xray.state) {
  557. case 'running':
  558. this.xray.color = "green";
  559. this.xray.stateMsg = '{{ i18n "pages.index.xrayStatusRunning" }}';
  560. break;
  561. case 'stop':
  562. this.xray.color = "orange";
  563. this.xray.stateMsg = '{{ i18n "pages.index.xrayStatusStop" }}';
  564. break;
  565. case 'error':
  566. this.xray.color = "red";
  567. this.xray.stateMsg ='{{ i18n "pages.index.xrayStatusError" }}';
  568. break;
  569. default:
  570. this.xray.color = "gray";
  571. this.xray.stateMsg = '{{ i18n "pages.index.xrayStatusUnknown" }}';
  572. break;
  573. }
  574. }
  575. }
  576. const versionModal = {
  577. visible: false,
  578. versions: [],
  579. show(versions) {
  580. this.visible = true;
  581. this.versions = versions;
  582. },
  583. hide() {
  584. this.visible = false;
  585. },
  586. };
  587. const logModal = {
  588. visible: false,
  589. logs: [],
  590. rows: 20,
  591. level: 'info',
  592. syslog: false,
  593. loading: false,
  594. show(logs) {
  595. this.visible = true;
  596. this.logs = logs;
  597. this.formattedLogs = this.logs?.length > 0 ? this.formatLogs(this.logs) : "No Record...";
  598. },
  599. formatLogs(logs) {
  600. let formattedLogs = '';
  601. const levels = ["DEBUG","INFO","NOTICE","WARNING","ERROR"];
  602. const levelColors = ["#3c89e8","#008771","#008771","#f37b24","#e04141","#bcbcbc"];
  603. logs.forEach((log, index) => {
  604. let [data, message] = log.split(" - ",2);
  605. const parts = data.split(" ")
  606. if(index>0) formattedLogs += '<br>';
  607. if (parts.length === 3) {
  608. const d = parts[0];
  609. const t = parts[1];
  610. const level = parts[2];
  611. const levelIndex = levels.indexOf(level,levels) || 5;
  612. //formattedLogs += `<span style="color: gray;">${index + 1}.</span>`;
  613. formattedLogs += `<span style="color: ${levelColors[0]};">${d} ${t}</span> `;
  614. formattedLogs += `<span style="color: ${levelColors[levelIndex]}">${level}</span>`;
  615. } else {
  616. const levelIndex = levels.indexOf(data,levels) || 5;
  617. formattedLogs += `<span style="color: ${levelColors[levelIndex]}">${data}</span>`;
  618. }
  619. if(message){
  620. if(message.startsWith("XRAY:"))
  621. message = "<b>XRAY: </b>" + message.substring(5);
  622. else
  623. message = "<b>X-UI: </b>" + message;
  624. }
  625. formattedLogs += message ? ' - ' + message : '';
  626. });
  627. return formattedLogs;
  628. },
  629. hide() {
  630. this.visible = false;
  631. },
  632. };
  633. const xraylogModal = {
  634. visible: false,
  635. logs: [],
  636. rows: 20,
  637. loading: false,
  638. show(logs) {
  639. this.visible = true;
  640. this.logs = logs;
  641. this.formattedLogs = this.logs?.length > 0 ? this.formatLogs(this.logs) : "No Record...";
  642. },
  643. formatLogs(logs) {
  644. let formattedLogs = '';
  645. logs.forEach((log, index) => {
  646. if(index > 0) formattedLogs += '<br>';
  647. const parts = log.split(' ');
  648. if(parts.length === 9) {
  649. const dateTime = `<b>${parts[0]} ${parts[1]}</b>`;
  650. const from = `<b>${parts[3]}</b>`;
  651. const to = `<b>${parts[5].replace(/^\/+/, "")}</b>`;
  652. let outboundColor = '';
  653. if (parts[8].startsWith('blocked')) {
  654. outboundColor = ' style="color: #e04141;"';
  655. }
  656. else if (!parts[8].startsWith('direct')) {
  657. outboundColor = ' style="color: #3c89e8;"';
  658. }
  659. formattedLogs += `<span${outboundColor}>
  660. ${dateTime}
  661. ${parts[2]}
  662. ${from}
  663. ${parts[4]}
  664. ${to}
  665. ${parts.slice(6).join(' ')}
  666. </span>`;
  667. } else {
  668. formattedLogs += `<span>${parts.join(' ')}</span>`;
  669. }
  670. });
  671. return formattedLogs;
  672. },
  673. hide() {
  674. this.visible = false;
  675. },
  676. };
  677. const backupModal = {
  678. visible: false,
  679. show() {
  680. this.visible = true;
  681. },
  682. hide() {
  683. this.visible = false;
  684. },
  685. };
  686. const app = new Vue({
  687. delimiters: ['[[', ']]'],
  688. el: '#app',
  689. mixins: [MediaQueryMixin],
  690. data: {
  691. themeSwitcher,
  692. loadingStates: {
  693. fetched: false,
  694. spinning: false
  695. },
  696. status: new Status(),
  697. versionModal,
  698. logModal,
  699. xraylogModal,
  700. backupModal,
  701. loadingTip: '{{ i18n "loading"}}',
  702. showAlert: false,
  703. showIp: false,
  704. ipLimitEnable: false,
  705. },
  706. methods: {
  707. loading(spinning, tip = '{{ i18n "loading"}}') {
  708. this.loadingStates.spinning = spinning;
  709. this.loadingTip = tip;
  710. },
  711. async getStatus() {
  712. try {
  713. const msg = await HttpUtil.post('/server/status');
  714. if (msg.success) {
  715. if (!this.loadingStates.fetched) {
  716. this.loadingStates.fetched = true;
  717. }
  718. this.setStatus(msg.obj, true);
  719. }
  720. } catch (e) {
  721. console.error("Failed to get status:", e);
  722. }
  723. },
  724. setStatus(data) {
  725. this.status = new Status(data);
  726. },
  727. async openSelectV2rayVersion() {
  728. this.loading(true);
  729. const msg = await HttpUtil.post('server/getXrayVersion');
  730. this.loading(false);
  731. if (!msg.success) {
  732. return;
  733. }
  734. versionModal.show(msg.obj);
  735. },
  736. switchV2rayVersion(version) {
  737. this.$confirm({
  738. title: '{{ i18n "pages.index.xraySwitchVersionDialog"}}',
  739. content: '{{ i18n "pages.index.xraySwitchVersionDialogDesc"}}'.replace('#version#', version),
  740. okText: '{{ i18n "confirm"}}',
  741. class: themeSwitcher.currentTheme,
  742. cancelText: '{{ i18n "cancel"}}',
  743. onOk: async () => {
  744. versionModal.hide();
  745. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  746. await HttpUtil.post(`/server/installXray/${version}`);
  747. this.loading(false);
  748. },
  749. });
  750. },
  751. updateGeofile(fileName) {
  752. this.$confirm({
  753. title: '{{ i18n "pages.index.geofileUpdateDialog" }}',
  754. content: '{{ i18n "pages.index.geofileUpdateDialogDesc" }}'.replace("#filename#", fileName),
  755. okText: '{{ i18n "confirm"}}',
  756. class: themeSwitcher.currentTheme,
  757. cancelText: '{{ i18n "cancel"}}',
  758. onOk: async () => {
  759. versionModal.hide();
  760. this.loading(true, '{{ i18n "pages.index.dontRefresh"}}');
  761. await HttpUtil.post(`/server/updateGeofile/${fileName}`);
  762. this.loading(false);
  763. },
  764. });
  765. },
  766. async stopXrayService() {
  767. this.loading(true);
  768. const msg = await HttpUtil.post('server/stopXrayService');
  769. this.loading(false);
  770. if (!msg.success) {
  771. return;
  772. }
  773. },
  774. async restartXrayService() {
  775. this.loading(true);
  776. const msg = await HttpUtil.post('server/restartXrayService');
  777. this.loading(false);
  778. if (!msg.success) {
  779. return;
  780. }
  781. },
  782. async openLogs(){
  783. logModal.loading = true;
  784. const msg = await HttpUtil.post('server/logs/'+logModal.rows,{level: logModal.level, syslog: logModal.syslog});
  785. if (!msg.success) {
  786. return;
  787. }
  788. logModal.show(msg.obj);
  789. await PromiseUtil.sleep(500);
  790. logModal.loading = false;
  791. },
  792. async openXrayLogs(){
  793. xraylogModal.loading = true;
  794. const msg = await HttpUtil.post('server/xraylogs/'+xraylogModal.rows);
  795. if (!msg.success) {
  796. return;
  797. }
  798. xraylogModal.show(msg.obj);
  799. await PromiseUtil.sleep(500);
  800. xraylogModal.loading = false;
  801. },
  802. async openConfig() {
  803. this.loading(true);
  804. const msg = await HttpUtil.post('server/getConfigJson');
  805. this.loading(false);
  806. if (!msg.success) {
  807. return;
  808. }
  809. txtModal.show('config.json', JSON.stringify(msg.obj, null, 2), 'config.json');
  810. },
  811. openBackup() {
  812. backupModal.show();
  813. },
  814. exportDatabase() {
  815. window.location = basePath + 'server/getDb';
  816. },
  817. importDatabase() {
  818. const fileInput = document.createElement('input');
  819. fileInput.type = 'file';
  820. fileInput.accept = '.db';
  821. fileInput.addEventListener('change', async (event) => {
  822. const dbFile = event.target.files[0];
  823. if (dbFile) {
  824. const formData = new FormData();
  825. formData.append('db', dbFile);
  826. backupModal.hide();
  827. this.loading(true);
  828. const uploadMsg = await HttpUtil.post('server/importDB', formData, {
  829. headers: {
  830. 'Content-Type': 'multipart/form-data',
  831. }
  832. });
  833. this.loading(false);
  834. if (!uploadMsg.success) {
  835. return;
  836. }
  837. this.loading(true);
  838. const restartMsg = await HttpUtil.post("/panel/setting/restartPanel");
  839. this.loading(false);
  840. if (restartMsg.success) {
  841. this.loading(true);
  842. await PromiseUtil.sleep(5000);
  843. location.reload();
  844. }
  845. }
  846. });
  847. fileInput.click();
  848. },
  849. },
  850. async mounted() {
  851. if (window.location.protocol !== "https:") {
  852. this.showAlert = true;
  853. }
  854. const msg = await HttpUtil.post('/panel/setting/defaultSettings');
  855. if (msg.success) {
  856. this.ipLimitEnable = msg.obj.ipLimitEnable;
  857. }
  858. while (true) {
  859. try {
  860. await this.getStatus();
  861. } catch (e) {
  862. console.error(e);
  863. }
  864. await PromiseUtil.sleep(2000);
  865. }
  866. },
  867. });
  868. </script>
  869. {{ template "page/body_end" .}}