settings.html 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. {{template "head" .}}
  4. <style>
  5. @media (min-width: 769px) {
  6. .ant-layout-content {
  7. margin: 24px 16px;
  8. }
  9. }
  10. .ant-col-sm-24 {
  11. margin-top: 10px;
  12. }
  13. .ant-tabs-bar {
  14. margin: 0;
  15. }
  16. .ant-list-item {
  17. display: block;
  18. }
  19. :not(.ant-card-dark)>.ant-tabs-top-bar {
  20. background: white;
  21. }
  22. </style>
  23. <body>
  24. <a-layout id="app" v-cloak>
  25. {{ template "commonSider" . }}
  26. <a-layout id="content-layout" :style="siderDrawer.isDarkTheme ? bgDarkStyle : ''">
  27. <a-layout-content>
  28. <a-spin :spinning="spinning" :delay="500" tip="loading">
  29. <a-space direction="vertical">
  30. <a-space direction="horizontal">
  31. <a-button type="primary" :disabled="saveBtnDisable" @click="updateAllSetting">{{ i18n "pages.settings.save" }}</a-button>
  32. <a-button type="danger" :disabled="!saveBtnDisable" @click="restartPanel">{{ i18n "pages.settings.restartPanel" }}</a-button>
  33. </a-space>
  34. <a-tabs default-active-key="1" :class="siderDrawer.isDarkTheme ? darkClass : ''" >
  35. <a-tab-pane key="1" tab='{{ i18n "pages.settings.panelSettings"}}'>
  36. <a-list item-layout="horizontal" :style="siderDrawer.isDarkTheme ? 'color: hsla(0,0%,100%,.65);': 'background: white;'">
  37. <setting-list-item type="text" title='{{ i18n "pages.settings.panelListeningIP"}}' desc='{{ i18n "pages.settings.panelListeningIPDesc"}}' v-model="allSetting.webListen"></setting-list-item>
  38. <setting-list-item type="number" title='{{ i18n "pages.settings.panelPort"}}' desc='{{ i18n "pages.settings.panelPortDesc"}}' v-model="allSetting.webPort" :min="0"></setting-list-item>
  39. <setting-list-item type="text" title='{{ i18n "pages.settings.publicKeyPath"}}' desc='{{ i18n "pages.settings.publicKeyPathDesc"}}' v-model="allSetting.webCertFile"></setting-list-item>
  40. <setting-list-item type="text" title='{{ i18n "pages.settings.privateKeyPath"}}' desc='{{ i18n "pages.settings.privateKeyPathDesc"}}' v-model="allSetting.webKeyFile"></setting-list-item>
  41. <setting-list-item type="text" title='{{ i18n "pages.settings.panelUrlPath"}}' desc='{{ i18n "pages.settings.panelUrlPathDesc"}}' v-model="allSetting.webBasePath"></setting-list-item>
  42. <setting-list-item type="number" title='{{ i18n "pages.settings.sessionMaxAge" }}' desc='{{ i18n "pages.settings.sessionMaxAgeDesc" }}' v-model="allSetting.sessionMaxAge" :min="0"></setting-list-item>
  43. <setting-list-item type="number" title='{{ i18n "pages.settings.expireTimeDiff" }}' desc='{{ i18n "pages.settings.expireTimeDiffDesc" }}' v-model="allSetting.expireDiff" :min="0"></setting-list-item>
  44. <setting-list-item type="number" title='{{ i18n "pages.settings.trafficDiff" }}' desc='{{ i18n "pages.settings.trafficDiffDesc" }}' v-model="allSetting.trafficDiff" :min="0"></setting-list-item>
  45. <setting-list-item type="text" title='{{ i18n "pages.settings.timeZone"}}' desc='{{ i18n "pages.settings.timeZoneDesc"}}' v-model="allSetting.timeLocation"></setting-list-item>
  46. <a-list-item>
  47. <a-row style="padding: 20px">
  48. <a-col :lg="24" :xl="12">
  49. <a-list-item-meta title="Language" />
  50. </a-col>
  51. <a-col :lg="24" :xl="12">
  52. <template>
  53. <a-select
  54. ref="selectLang"
  55. v-model="lang"
  56. @change="setLang(lang)"
  57. :dropdown-class-name="siderDrawer.isDarkTheme ? 'ant-card-dark' : ''"
  58. style="width: 100%"
  59. >
  60. <a-select-option :value="l.value" :label="l.value" v-for="l in supportLangs">
  61. <span role="img" aria-label="l.name" v-text="l.icon"></span>&nbsp;&nbsp;<span v-text="l.name"></span>
  62. </a-select-option>
  63. </a-select>
  64. </template>
  65. </a-col>
  66. </a-row>
  67. </a-list-item>
  68. </a-list>
  69. </a-tab-pane>
  70. <a-tab-pane key="2" tab='{{ i18n "pages.settings.securitySettings"}}' style="padding: 20px;">
  71. <a-tabs default-active-key="sec-1" :class="siderDrawer.isDarkTheme ? darkClass : ''">
  72. <a-tab-pane key="sec-1" tab='{{ i18n "pages.settings.security.admin"}}'>
  73. <a-form :style="siderDrawer.isDarkTheme ? 'color: hsla(0,0%,100%,.65); padding: 20px;': 'background: white; padding: 20px;'">
  74. <a-form-item label='{{ i18n "pages.settings.oldUsername"}}'>
  75. <a-input v-model="user.oldUsername" style="max-width: 300px"></a-input>
  76. </a-form-item>
  77. <a-form-item label='{{ i18n "pages.settings.currentPassword"}}'>
  78. <a-input type="password" v-model="user.oldPassword" style="max-width: 300px"></a-input>
  79. </a-form-item>
  80. <a-form-item label='{{ i18n "pages.settings.newUsername"}}'>
  81. <a-input v-model="user.newUsername" style="max-width: 300px"></a-input>
  82. </a-form-item>
  83. <a-form-item label='{{ i18n "pages.settings.newPassword"}}'>
  84. <a-input type="password" v-model="user.newPassword" style="max-width: 300px"></a-input>
  85. </a-form-item>
  86. <a-form-item>
  87. <a-button type="primary" @click="updateUser">{{ i18n "confirm" }}</a-button>
  88. </a-form-item>
  89. </a-form>
  90. </a-tab-pane>
  91. <a-tab-pane key="sec-2" tab='{{ i18n "pages.settings.security.secret"}}'>
  92. <a-form :style="siderDrawer.isDarkTheme ? 'color: hsla(0,0%,100%,.65); padding: 20px;': 'background: white; padding: 20px;'">
  93. <a-list-item style="padding: 20px">
  94. <a-row>
  95. <a-col :lg="24" :xl="12">
  96. <a-list-item-meta title='{{ i18n "pages.settings.security.loginSecurity" }}' description='{{ i18n "pages.settings.security.loginSecurityDesc" }}'/>
  97. </a-col>
  98. <a-col :lg="24" :xl="12">
  99. <template>
  100. <a-switch @change="toggleToken(allSetting.secretEnable)" v-model="allSetting.secretEnable"></a-switch>
  101. </template>
  102. </a-col>
  103. </a-row>
  104. </a-list-item>
  105. <a-list-item style="padding: 20px">
  106. <a-row>
  107. <a-col :lg="24" :xl="12">
  108. <a-list-item-meta title='{{ i18n "pages.settings.security.secretToken" }}' description='{{ i18n "pages.settings.security.secretTokenDesc" }}'/>
  109. </a-col>
  110. <a-col :lg="24" :xl="12">
  111. <svg
  112. @click="getNewSecret"
  113. xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="anticon anticon-question-circle" viewBox="0 0 16 16"> <path d="M11.534 7h3.932a.25.25 0 0 1 .192.41l-1.966 2.36a.25.25 0 0 1-.384 0l-1.966-2.36a.25.25 0 0 1 .192-.41zm-11 2h3.932a.25.25 0 0 0 .192-.41L2.692 6.23a.25.25 0 0 0-.384 0L.342 8.59A.25.25 0 0 0 .534 9z"/> <path fill-rule="evenodd" d="M8 3c-1.552 0-2.94.707-3.857 1.818a.5.5 0 1 1-.771-.636A6.002 6.002 0 0 1 13.917 7H12.9A5.002 5.002 0 0 0 8 3zM3.1 9a5.002 5.002 0 0 0 8.757 2.182.5.5 0 1 1 .771.636A6.002 6.002 0 0 1 2.083 9H3.1z"/>
  114. </svg>
  115. <template>
  116. <a-textarea type="text" id='token' :disabled="!allSetting.secretEnable" v-model="user.loginSecret"></a-textarea>
  117. </template>
  118. </a-col>
  119. </a-row>
  120. </a-list-item>
  121. <a-button type="primary" @click="updateSecret">{{ i18n "confirm" }}</a-button>
  122. </a-form>
  123. </a-tab-pane>
  124. </a-tabs>
  125. </a-tab-pane>
  126. <a-tab-pane key="3" tab='{{ i18n "pages.settings.xrayConfiguration"}}'>
  127. <a-list item-layout="horizontal" :style="siderDrawer.isDarkTheme ? 'color: hsla(0,0%,100%,.65);': 'background: white;'">
  128. <a-divider style="padding: 20px;">{{ i18n "pages.settings.actions"}}</a-divider>
  129. <a-space direction="horizontal" style="padding: 0px 20px">
  130. <a-button type="primary" @click="resetXrayConfigToDefault">{{ i18n "pages.settings.resetDefaultConfig" }}</a-button>
  131. </a-space>
  132. <a-divider style="padding: 20px;">{{ i18n "pages.settings.templates.title"}} </a-divider>
  133. <a-tabs default-active-key="tpl-1" :class="siderDrawer.isDarkTheme ? darkClass : ''" style="padding: 20px 20px;">
  134. <a-tab-pane key="tpl-1" tab='{{ i18n "pages.settings.templates.basicTemplate"}}' style="padding-top: 20px;">
  135. <a-collapse>
  136. <a-collapse-panel header='{{ i18n "pages.settings.templates.generalConfigs"}}'>
  137. <a-row :xs="24" :sm="24" :lg="12">
  138. <h2 style="color: inherit; font-weight: bold; font-size: 18px; padding: 10px 20px; border-bottom: 2px solid;">
  139. <a-icon type="warning" style="color: inherit; font-size: 24px;"></a-icon>
  140. {{ i18n "pages.settings.templates.generalConfigsDesc" }}
  141. </h2>
  142. </a-row>
  143. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigTorrent"}}' desc='{{ i18n "pages.settings.templates.xrayConfigTorrentDesc"}}' v-model="torrentSettings"></setting-list-item>
  144. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigPrivateIp"}}' desc='{{ i18n "pages.settings.templates.xrayConfigPrivateIpDesc"}}' v-model="privateIpSettings"></setting-list-item>
  145. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigAds"}}' desc='{{ i18n "pages.settings.templates.xrayConfigAdsDesc"}}' v-model="AdsSettings"></setting-list-item>
  146. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigPorn"}}' desc='{{ i18n "pages.settings.templates.xrayConfigPornDesc"}}' v-model="PornSettings"></setting-list-item>
  147. </a-collapse-panel>
  148. <a-collapse-panel header='{{ i18n "pages.settings.templates.countryConfigs"}}'>
  149. <a-row :xs="24" :sm="24" :lg="12">
  150. <h2 style="color: inherit; font-weight: bold; font-size: 18px; padding: 10px 20px; border-bottom: 2px solid;">
  151. <a-icon type="warning" style="color: inherit; font-size: 24px;"></a-icon>
  152. {{ i18n "pages.settings.templates.countryConfigsDesc" }}
  153. </h2>
  154. </a-row>
  155. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigIRIp"}}' desc='{{ i18n "pages.settings.templates.xrayConfigIRIpDesc"}}' v-model="IRIpSettings"></setting-list-item>
  156. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigIRDomain"}}' desc='{{ i18n "pages.settings.templates.xrayConfigIRDomainDesc"}}' v-model="IRDomainSettings"></setting-list-item>
  157. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigChinaIp"}}' desc='{{ i18n "pages.settings.templates.xrayConfigChinaIpDesc"}}' v-model="ChinaIpSettings"></setting-list-item>
  158. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigChinaDomain"}}' desc='{{ i18n "pages.settings.templates.xrayConfigChinaDomainDesc"}}' v-model="ChinaDomainSettings"></setting-list-item>
  159. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigRussiaIp"}}' desc='{{ i18n "pages.settings.templates.xrayConfigRussiaIpDesc"}}' v-model="RussiaIpSettings"></setting-list-item>
  160. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigRussiaDomain"}}' desc='{{ i18n "pages.settings.templates.xrayConfigRussiaDomainDesc"}}' v-model="RussiaDomainSettings"></setting-list-item>
  161. </a-collapse-panel>
  162. <a-collapse-panel header='{{ i18n "pages.settings.templates.ipv4Configs"}}'>
  163. <a-row :xs="24" :sm="24" :lg="12">
  164. <h2 style="color: inherit; font-weight: bold; font-size: 18px; padding: 10px 20px; border-bottom: 2px solid;">
  165. <a-icon type="warning" style="color: inherit; font-size: 24px;"></a-icon>
  166. {{ i18n "pages.settings.templates.ipv4ConfigsDesc" }}
  167. </h2>
  168. </a-row>
  169. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigGoogleIPv4"}}' desc='{{ i18n "pages.settings.templates.xrayConfigGoogleIPv4Desc"}}' v-model="GoogleIPv4Settings"></setting-list-item>
  170. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigNetflixIPv4"}}' desc='{{ i18n "pages.settings.templates.xrayConfigNetflixIPv4Desc"}}' v-model="NetflixIPv4Settings"></setting-list-item>
  171. </a-collapse-panel>
  172. <a-collapse-panel header='{{ i18n "pages.settings.templates.warpConfigs"}}'>
  173. <a-row :xs="24" :sm="24" :lg="12">
  174. <h2 style="color: inherit; font-weight: bold; font-size: 18px; padding: 10px 20px; border-bottom: 2px solid;">
  175. <a-icon type="warning" style="color: inherit; font-size: 24px;"></a-icon>
  176. {{ i18n "pages.settings.templates.warpConfigsDesc" }}
  177. </h2>
  178. </a-row>
  179. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigGoogleWARP"}}' desc='{{ i18n "pages.settings.templates.xrayConfigGoogleWARPDesc"}}' v-model="GoogleWARPSettings"></setting-list-item>
  180. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigOpenAIWARP"}}' desc='{{ i18n "pages.settings.templates.xrayConfigOpenAIWARPDesc"}}' v-model="OpenAIWARPSettings"></setting-list-item>
  181. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigNetflixWARP"}}' desc='{{ i18n "pages.settings.templates.xrayConfigNetflixWARPDesc"}}' v-model="NetflixWARPSettings"></setting-list-item>
  182. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigSpotifyWARP"}}' desc='{{ i18n "pages.settings.templates.xrayConfigSpotifyWARPDesc"}}' v-model="SpotifyWARPSettings"></setting-list-item>
  183. </a-collapse-panel>
  184. </a-collapse>
  185. </a-tab-pane>
  186. <a-tab-pane key="tpl-2" tab='{{ i18n "pages.settings.templates.advancedTemplate"}}' style="padding-top: 20px;">
  187. <a-collapse>
  188. <a-collapse-panel header='{{ i18n "pages.settings.templates.xrayConfigInbounds"}}'>
  189. <setting-list-item type="textarea" title='{{ i18n "pages.settings.templates.xrayConfigInbounds"}}' desc='{{ i18n "pages.settings.templates.xrayConfigInboundsDesc"}}' v-model="inboundSettings"></setting-list-item>
  190. </a-collapse-panel>
  191. <a-collapse-panel header='{{ i18n "pages.settings.templates.xrayConfigOutbounds"}}'>
  192. <setting-list-item type="textarea" title='{{ i18n "pages.settings.templates.xrayConfigOutbounds"}}' desc='{{ i18n "pages.settings.templates.xrayConfigOutboundsDesc"}}' v-model="outboundSettings"></setting-list-item>
  193. </a-collapse-panel>
  194. <a-collapse-panel header='{{ i18n "pages.settings.templates.xrayConfigRoutings"}}'>
  195. <setting-list-item type="textarea" title='{{ i18n "pages.settings.templates.xrayConfigRoutings"}}' desc='{{ i18n "pages.settings.templates.xrayConfigRoutingsDesc"}}' v-model="routingRuleSettings"></setting-list-item>
  196. </a-collapse-panel>
  197. </a-collapse>
  198. </a-tab-pane>
  199. <a-tab-pane key="tpl-3" tab='{{ i18n "pages.settings.templates.completeTemplate"}}' style="padding-top: 20px;">
  200. <setting-list-item type="textarea" title='{{ i18n "pages.settings.templates.xrayConfigTemplate"}}' desc='{{ i18n "pages.settings.templates.xrayConfigTemplateDesc"}}' v-model="allSetting.xrayTemplateConfig"></setting-list-item>
  201. </a-tab-pane>
  202. </a-tabs>
  203. </a-list>
  204. </a-tab-pane>
  205. <a-tab-pane key="4" tab='{{ i18n "pages.settings.TGBotSettings"}}'>
  206. <a-list item-layout="horizontal" :style="siderDrawer.isDarkTheme ? 'color: hsla(0,0%,100%,.65);': 'background: white;'">
  207. <setting-list-item type="switch" title='{{ i18n "pages.settings.telegramBotEnable" }}' desc='{{ i18n "pages.settings.telegramBotEnableDesc" }}' v-model="allSetting.tgBotEnable"></setting-list-item>
  208. <setting-list-item type="text" title='{{ i18n "pages.settings.telegramToken"}}' desc='{{ i18n "pages.settings.telegramTokenDesc"}}' v-model="allSetting.tgBotToken"></setting-list-item>
  209. <setting-list-item type="text" title='{{ i18n "pages.settings.telegramChatId"}}' desc='{{ i18n "pages.settings.telegramChatIdDesc"}}' v-model="allSetting.tgBotChatId"></setting-list-item>
  210. <setting-list-item type="text" title='{{ i18n "pages.settings.telegramNotifyTime"}}' desc='{{ i18n "pages.settings.telegramNotifyTimeDesc"}}' v-model="allSetting.tgRunTime"></setting-list-item>
  211. <setting-list-item type="switch" title='{{ i18n "pages.settings.tgNotifyBackup" }}' desc='{{ i18n "pages.settings.tgNotifyBackupDesc" }}' v-model="allSetting.tgBotBackup"></setting-list-item>
  212. <setting-list-item type="number" title='{{ i18n "pages.settings.tgNotifyCpu" }}' desc='{{ i18n "pages.settings.tgNotifyCpuDesc" }}' v-model="allSetting.tgCpu" :min="0" :max="100"></setting-list-item>
  213. </a-list>
  214. </a-tab-pane>
  215. </a-tabs>
  216. </a-space>
  217. </a-spin>
  218. </a-layout-content>
  219. </a-layout>
  220. </a-layout>
  221. {{template "js" .}}
  222. {{template "component/setting"}}
  223. <script>
  224. const app = new Vue({
  225. delimiters: ['[[', ']]'],
  226. el: '#app',
  227. data: {
  228. siderDrawer,
  229. spinning: false,
  230. oldAllSetting: new AllSetting(),
  231. allSetting: new AllSetting(),
  232. saveBtnDisable: true,
  233. user: new User(),
  234. lang: getLang(),
  235. ipv4Settings: {
  236. tag: "IPv4",
  237. protocol: "freedom",
  238. settings: {
  239. domainStrategy: "UseIPv4"
  240. }
  241. },
  242. warpSettings: {
  243. tag: "WARP",
  244. protocol: "socks",
  245. settings: {
  246. servers: [
  247. {
  248. address: "127.0.0.1",
  249. port: 40000
  250. }
  251. ]
  252. }
  253. },
  254. settingsData: {
  255. protocols: {
  256. bittorrent: ["bittorrent"],
  257. },
  258. ips: {
  259. local: ["geoip:private"],
  260. google: ["geoip:google"],
  261. cn: ["geoip:cn"],
  262. ir: ["geoip:ir"],
  263. ru: ["geoip:ru"],
  264. },
  265. domains: {
  266. ads: [
  267. "geosite:category-ads-all",
  268. "geosite:category-ads",
  269. "geosite:google-ads",
  270. "geosite:spotify-ads"
  271. ],
  272. porn: ["geosite:category-porn"],
  273. openai: ["geosite:openai"],
  274. google: ["geosite:google"],
  275. spotify: ["geosite:spotify"],
  276. netflix: ["geosite:netflix"],
  277. cn: [
  278. "geosite:cn",
  279. "regexp:.*\\.cn$"
  280. ],
  281. ru: [
  282. "geosite:category-gov-ru",
  283. "regexp:.*\\.ru$"
  284. ],
  285. ir: [
  286. "regexp:.*\\.ir$",
  287. "ext:iran.dat:ir",
  288. "ext:iran.dat:other",
  289. "ext:iran.dat:ads",
  290. "geosite:category-ir"
  291. ]
  292. },
  293. }
  294. },
  295. methods: {
  296. loading(spinning = true, obj) {
  297. if (obj == null) this.spinning = spinning;
  298. },
  299. async getAllSetting() {
  300. this.loading(true);
  301. const msg = await HttpUtil.post("/xui/setting/all");
  302. this.loading(false);
  303. if (msg.success) {
  304. this.oldAllSetting = new AllSetting(msg.obj);
  305. this.allSetting = new AllSetting(msg.obj);
  306. this.saveBtnDisable = true;
  307. }
  308. await this.getUserSecret();
  309. },
  310. async updateAllSetting() {
  311. this.loading(true);
  312. const msg = await HttpUtil.post("/xui/setting/update", this.allSetting);
  313. this.loading(false);
  314. if (msg.success) {
  315. await this.getAllSetting();
  316. }
  317. },
  318. async updateUser() {
  319. this.loading(true);
  320. const msg = await HttpUtil.post("/xui/setting/updateUser", this.user);
  321. this.loading(false);
  322. if (msg.success) {
  323. this.user = {};
  324. window.location.replace("/logout")
  325. }
  326. },
  327. async restartPanel() {
  328. await new Promise(resolve => {
  329. this.$confirm({
  330. title: '{{ i18n "pages.settings.restartPanel" }}',
  331. content: '{{ i18n "pages.settings.restartPanelDesc" }}',
  332. okText: '{{ i18n "sure" }}',
  333. cancelText: '{{ i18n "cancel" }}',
  334. onOk: () => resolve(),
  335. });
  336. });
  337. this.loading(true);
  338. const msg = await HttpUtil.post("/xui/setting/restartPanel");
  339. this.loading(false);
  340. if (msg.success) {
  341. this.loading(true);
  342. await PromiseUtil.sleep(5000);
  343. location.reload();
  344. }
  345. },
  346. async getUserSecret() {
  347. const user_msg = await HttpUtil.post("/xui/setting/getUserSecret", this.user);
  348. if (user_msg.success) {
  349. this.user = user_msg.obj;
  350. }
  351. this.loading(false);
  352. },
  353. async updateSecret() {
  354. this.loading(true);
  355. const msg = await HttpUtil.post("/xui/setting/updateUserSecret", this.user);
  356. if (msg.success) {
  357. this.user = msg.obj;
  358. window.location.replace("/logout")
  359. }
  360. this.loading(false);
  361. await this.updateAllSetting();
  362. },
  363. async getNewSecret() {
  364. this.loading(true);
  365. await PromiseUtil.sleep(1000);
  366. var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  367. var string = "";
  368. var len = 64;
  369. for (var ii = 0; ii < len; ii++) {
  370. string += chars[Math.floor(Math.random() * chars.length)];
  371. }
  372. this.user.loginSecret = string;
  373. document.getElementById("token").value = this.user.loginSecret;
  374. this.loading(false);
  375. },
  376. async toggleToken(value) {
  377. if (value) this.getNewSecret();
  378. else this.user.loginSecret = "";
  379. },
  380. async resetXrayConfigToDefault() {
  381. this.loading(true);
  382. const msg = await HttpUtil.get("/xui/setting/getDefaultJsonConfig");
  383. this.loading(false);
  384. if (msg.success) {
  385. this.templateSettings = JSON.parse(JSON.stringify(msg.obj, null, 2));
  386. this.saveBtnDisable = true;
  387. }
  388. },
  389. checkRequiredOutbounds() {
  390. const newTemplateSettings = this.templateSettings;
  391. const haveIPv4Outbounds = newTemplateSettings.outbounds.some((o) => o?.tag === "IPv4");
  392. const haveIPv4Rules = newTemplateSettings.routing.rules.some((r) => r?.outboundTag === "IPv4");
  393. const haveWARPOutbounds = newTemplateSettings.outbounds.some((o) => o?.tag === "WARP");
  394. const haveWARPRules = newTemplateSettings.routing.rules.some((r) => r?.outboundTag === "WARP");
  395. if (haveWARPRules && !haveWARPOutbounds) {
  396. newTemplateSettings.outbounds.push(this.warpSettings);
  397. }
  398. if (haveIPv4Rules && !haveIPv4Outbounds) {
  399. newTemplateSettings.outbounds.push(this.ipv4Settings);
  400. }
  401. this.templateSettings = newTemplateSettings;
  402. },
  403. templateRuleGetter(routeSettings) {
  404. const { data, property, outboundTag } = routeSettings;
  405. let result = false;
  406. if (this.templateSettings != null) {
  407. this.templateSettings.routing.rules.forEach(
  408. (routingRule) => {
  409. if (
  410. routingRule.hasOwnProperty(property) &&
  411. routingRule.hasOwnProperty("outboundTag") &&
  412. routingRule.outboundTag === outboundTag
  413. ) {
  414. if (data.includes(routingRule[property][0])) {
  415. result = true;
  416. }
  417. }
  418. }
  419. );
  420. }
  421. return result;
  422. },
  423. templateRuleSetter(routeSettings) {
  424. const { newValue, data, property, outboundTag } = routeSettings;
  425. const oldTemplateSettings = this.templateSettings;
  426. const newTemplateSettings = oldTemplateSettings;
  427. if (newValue) {
  428. const propertyRule = {
  429. type: "field",
  430. outboundTag,
  431. [property]: data
  432. };
  433. newTemplateSettings.routing.rules.push(propertyRule);
  434. }
  435. else {
  436. const newRules = [];
  437. newTemplateSettings.routing.rules.forEach(
  438. (routingRule) => {
  439. if (
  440. routingRule.hasOwnProperty(property) &&
  441. routingRule.hasOwnProperty("outboundTag") &&
  442. routingRule.outboundTag === outboundTag
  443. ) {
  444. if (data.includes(routingRule[property][0])) {
  445. return;
  446. }
  447. }
  448. newRules.push(routingRule);
  449. }
  450. );
  451. newTemplateSettings.routing.rules = newRules;
  452. }
  453. this.templateSettings = newTemplateSettings;
  454. this.checkRequiredOutbounds();
  455. }
  456. },
  457. async mounted() {
  458. await this.getAllSetting();
  459. while (true) {
  460. await PromiseUtil.sleep(1000);
  461. this.saveBtnDisable = this.oldAllSetting.equals(this.allSetting);
  462. }
  463. },
  464. computed: {
  465. templateSettings: {
  466. get: function () { return this.allSetting.xrayTemplateConfig ? JSON.parse(this.allSetting.xrayTemplateConfig) : null; },
  467. set: function (newValue) { this.allSetting.xrayTemplateConfig = JSON.stringify(newValue, null, 2) },
  468. },
  469. inboundSettings: {
  470. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.inbounds, null, 2) : null; },
  471. set: function (newValue) {
  472. newTemplateSettings = this.templateSettings;
  473. newTemplateSettings.inbounds = JSON.parse(newValue)
  474. this.templateSettings = newTemplateSettings
  475. },
  476. },
  477. outboundSettings: {
  478. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.outbounds, null, 2) : null; },
  479. set: function (newValue) {
  480. newTemplateSettings = this.templateSettings;
  481. newTemplateSettings.outbounds = JSON.parse(newValue)
  482. this.templateSettings = newTemplateSettings
  483. },
  484. },
  485. routingRuleSettings: {
  486. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.routing.rules, null, 2) : null; },
  487. set: function (newValue) {
  488. newTemplateSettings = this.templateSettings;
  489. newTemplateSettings.routing.rules = JSON.parse(newValue)
  490. this.templateSettings = newTemplateSettings
  491. },
  492. },
  493. torrentSettings: {
  494. get: function () {
  495. return this.templateRuleGetter({
  496. outboundTag: "blocked",
  497. property: "protocol",
  498. data: this.settingsData.protocols.bittorrent
  499. });
  500. },
  501. set: function (newValue) {
  502. this.templateRuleSetter({
  503. newValue,
  504. outboundTag: "blocked",
  505. property: "protocol",
  506. data: this.settingsData.protocols.bittorrent
  507. });
  508. },
  509. },
  510. privateIpSettings: {
  511. get: function () {
  512. return this.templateRuleGetter({
  513. outboundTag: "blocked",
  514. property: "ip",
  515. data: this.settingsData.ips.local
  516. });
  517. },
  518. set: function (newValue) {
  519. this.templateRuleSetter({
  520. newValue,
  521. outboundTag: "blocked",
  522. property: "ip",
  523. data: this.settingsData.ips.local
  524. });
  525. },
  526. },
  527. AdsSettings: {
  528. get: function () {
  529. return this.templateRuleGetter({
  530. outboundTag: "blocked",
  531. property: "domain",
  532. data: this.settingsData.domains.ads
  533. });
  534. },
  535. set: function (newValue) {
  536. this.templateRuleSetter({
  537. newValue,
  538. outboundTag: "blocked",
  539. property: "domain",
  540. data: this.settingsData.domains.ads
  541. });
  542. },
  543. },
  544. PornSettings: {
  545. get: function () {
  546. return this.templateRuleGetter({
  547. outboundTag: "blocked",
  548. property: "domain",
  549. data: this.settingsData.domains.porn
  550. });
  551. },
  552. set: function (newValue) {
  553. this.templateRuleSetter({
  554. newValue,
  555. outboundTag: "blocked",
  556. property: "domain",
  557. data: this.settingsData.domains.porn
  558. });
  559. },
  560. },
  561. GoogleIPv4Settings: {
  562. get: function () {
  563. return this.templateRuleGetter({
  564. outboundTag: "IPv4",
  565. property: "domain",
  566. data: this.settingsData.domains.google
  567. });
  568. },
  569. set: function (newValue) {
  570. this.templateRuleSetter({
  571. newValue,
  572. outboundTag: "IPv4",
  573. property: "domain",
  574. data: this.settingsData.domains.google
  575. });
  576. },
  577. },
  578. NetflixIPv4Settings: {
  579. get: function () {
  580. return this.templateRuleGetter({
  581. outboundTag: "IPv4",
  582. property: "domain",
  583. data: this.settingsData.domains.netflix
  584. });
  585. },
  586. set: function (newValue) {
  587. this.templateRuleSetter({
  588. newValue,
  589. outboundTag: "IPv4",
  590. property: "domain",
  591. data: this.settingsData.domains.netflix
  592. });
  593. },
  594. },
  595. IRIpSettings: {
  596. get: function () {
  597. return this.templateRuleGetter({
  598. outboundTag: "blocked",
  599. property: "ip",
  600. data: this.settingsData.ips.ir
  601. });
  602. },
  603. set: function (newValue) {
  604. this.templateRuleSetter({
  605. newValue,
  606. outboundTag: "blocked",
  607. property: "ip",
  608. data: this.settingsData.ips.ir
  609. });
  610. },
  611. },
  612. IRDomainSettings: {
  613. get: function () {
  614. return this.templateRuleGetter({
  615. outboundTag: "blocked",
  616. property: "domain",
  617. data: this.settingsData.domains.ir
  618. });
  619. },
  620. set: function (newValue) {
  621. this.templateRuleSetter({
  622. newValue,
  623. outboundTag: "blocked",
  624. property: "domain",
  625. data: this.settingsData.domains.ir
  626. });
  627. },
  628. },
  629. ChinaIpSettings: {
  630. get: function () {
  631. return this.templateRuleGetter({
  632. outboundTag: "blocked",
  633. property: "ip",
  634. data: this.settingsData.ips.cn
  635. });
  636. },
  637. set: function (newValue) {
  638. this.templateRuleSetter({
  639. newValue,
  640. outboundTag: "blocked",
  641. property: "ip",
  642. data: this.settingsData.ips.cn
  643. });
  644. },
  645. },
  646. ChinaDomainSettings: {
  647. get: function () {
  648. return this.templateRuleGetter({
  649. outboundTag: "blocked",
  650. property: "domain",
  651. data: this.settingsData.domains.cn
  652. });
  653. },
  654. set: function (newValue) {
  655. this.templateRuleSetter({
  656. newValue,
  657. outboundTag: "blocked",
  658. property: "domain",
  659. data: this.settingsData.domains.cn
  660. });
  661. },
  662. },
  663. RussiaIpSettings: {
  664. get: function () {
  665. return this.templateRuleGetter({
  666. outboundTag: "blocked",
  667. property: "ip",
  668. data: this.settingsData.ips.ru
  669. });
  670. },
  671. set: function (newValue) {
  672. this.templateRuleSetter({
  673. newValue,
  674. outboundTag: "blocked",
  675. property: "ip",
  676. data: this.settingsData.ips.ru
  677. });
  678. },
  679. },
  680. RussiaDomainSettings: {
  681. get: function () {
  682. return this.templateRuleGetter({
  683. outboundTag: "blocked",
  684. property: "domain",
  685. data: this.settingsData.domains.ru
  686. });
  687. },
  688. set: function (newValue) {
  689. this.templateRuleSetter({
  690. newValue,
  691. outboundTag: "blocked",
  692. property: "domain",
  693. data: this.settingsData.domains.ru
  694. });
  695. },
  696. },
  697. GoogleWARPSettings: {
  698. get: function () {
  699. return this.templateRuleGetter({
  700. outboundTag: "WARP",
  701. property: "domain",
  702. data: this.settingsData.domains.google
  703. });
  704. },
  705. set: function (newValue) {
  706. this.templateRuleSetter({
  707. newValue,
  708. outboundTag: "WARP",
  709. property: "domain",
  710. data: this.settingsData.domains.google
  711. });
  712. },
  713. },
  714. OpenAIWARPSettings: {
  715. get: function () {
  716. return this.templateRuleGetter({
  717. outboundTag: "WARP",
  718. property: "domain",
  719. data: this.settingsData.domains.openai
  720. });
  721. },
  722. set: function (newValue) {
  723. this.templateRuleSetter({
  724. newValue,
  725. outboundTag: "WARP",
  726. property: "domain",
  727. data: this.settingsData.domains.openai
  728. });
  729. },
  730. },
  731. NetflixWARPSettings: {
  732. get: function () {
  733. return this.templateRuleGetter({
  734. outboundTag: "WARP",
  735. property: "domain",
  736. data: this.settingsData.domains.netflix
  737. });
  738. },
  739. set: function (newValue) {
  740. this.templateRuleSetter({
  741. newValue,
  742. outboundTag: "WARP",
  743. property: "domain",
  744. data: this.settingsData.domains.netflix
  745. });
  746. },
  747. },
  748. SpotifyWARPSettings: {
  749. get: function () {
  750. return this.templateRuleGetter({
  751. outboundTag: "WARP",
  752. property: "domain",
  753. data: this.settingsData.domains.spotify
  754. });
  755. },
  756. set: function (newValue) {
  757. this.templateRuleSetter({
  758. newValue,
  759. outboundTag: "WARP",
  760. property: "domain",
  761. data: this.settingsData.domains.spotify
  762. });
  763. },
  764. },
  765. }
  766. });
  767. </script>
  768. </body>
  769. </html>