index.html 36 KB

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