settings.html 44 KB

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