setting.html 44 KB

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