settings.html 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  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="themeSwitcher.bgStyle">
  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 style="margin:1rem 0.5rem;" default-active-key="1" :class="themeSwitcher.darkCardClass" >
  35. <a-tab-pane key="1" tab='{{ i18n "pages.settings.panelSettings"}}'>
  36. <a-list item-layout="horizontal" :style="themeSwitcher.textStyle">
  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="themeSwitcher.darkCardClass"
  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 class="ant-card-dark-securitybox-nohover" default-active-key="sec-1" :class="themeSwitcher.darkCardClass">
  72. <a-tab-pane key="sec-1" tab='{{ i18n "pages.settings.security.admin"}}'>
  73. <a-form :style="'padding: 20px;' + themeSwitcher.textStyle">
  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. <password-input v-model="user.oldPassword" style="max-width: 300px"></password-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. <password-input v-model="user.newPassword" style="max-width: 300px"></password-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="'padding: 20px;' + themeSwitcher.textStyle">
  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="themeSwitcher.textStyle">
  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 class="ant-card-dark-box-nohover" default-active-key="tpl-1" :class="themeSwitcher.darkCardClass" 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. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigSpeedtest"}}' desc='{{ i18n "pages.settings.templates.xrayConfigSpeedtestDesc"}}' v-model="SpeedTestSettings"></setting-list-item>
  148. </a-collapse-panel>
  149. <a-collapse-panel header='{{ i18n "pages.settings.templates.countryConfigs"}}'>
  150. <a-row :xs="24" :sm="24" :lg="12">
  151. <h2 style="color: inherit; font-weight: bold; font-size: 18px; padding: 10px 20px; border-bottom: 2px solid;">
  152. <a-icon type="warning" style="color: inherit; font-size: 24px;"></a-icon>
  153. {{ i18n "pages.settings.templates.countryConfigsDesc" }}
  154. </h2>
  155. </a-row>
  156. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigIRIp"}}' desc='{{ i18n "pages.settings.templates.xrayConfigIRIpDesc"}}' v-model="IRIpSettings"></setting-list-item>
  157. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigIRDomain"}}' desc='{{ i18n "pages.settings.templates.xrayConfigIRDomainDesc"}}' v-model="IRDomainSettings"></setting-list-item>
  158. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigChinaIp"}}' desc='{{ i18n "pages.settings.templates.xrayConfigChinaIpDesc"}}' v-model="ChinaIpSettings"></setting-list-item>
  159. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigChinaDomain"}}' desc='{{ i18n "pages.settings.templates.xrayConfigChinaDomainDesc"}}' v-model="ChinaDomainSettings"></setting-list-item>
  160. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigRussiaIp"}}' desc='{{ i18n "pages.settings.templates.xrayConfigRussiaIpDesc"}}' v-model="RussiaIpSettings"></setting-list-item>
  161. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigRussiaDomain"}}' desc='{{ i18n "pages.settings.templates.xrayConfigRussiaDomainDesc"}}' v-model="RussiaDomainSettings"></setting-list-item>
  162. </a-collapse-panel>
  163. <a-collapse-panel header='{{ i18n "pages.settings.templates.ipv4Configs"}}'>
  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.settings.templates.ipv4ConfigsDesc" }}
  168. </h2>
  169. </a-row>
  170. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigGoogleIPv4"}}' desc='{{ i18n "pages.settings.templates.xrayConfigGoogleIPv4Desc"}}' v-model="GoogleIPv4Settings"></setting-list-item>
  171. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigNetflixIPv4"}}' desc='{{ i18n "pages.settings.templates.xrayConfigNetflixIPv4Desc"}}' v-model="NetflixIPv4Settings"></setting-list-item>
  172. </a-collapse-panel>
  173. <a-collapse-panel header='{{ i18n "pages.settings.templates.warpConfigs"}}'>
  174. <a-row :xs="24" :sm="24" :lg="12">
  175. <h2 style="color: inherit; font-weight: bold; font-size: 18px; padding: 10px 20px; border-bottom: 2px solid;">
  176. <a-icon type="warning" style="color: inherit; font-size: 24px;"></a-icon>
  177. {{ i18n "pages.settings.templates.warpConfigsDesc" }}
  178. </h2>
  179. </a-row>
  180. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigGoogleWARP"}}' desc='{{ i18n "pages.settings.templates.xrayConfigGoogleWARPDesc"}}' v-model="GoogleWARPSettings"></setting-list-item>
  181. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigOpenAIWARP"}}' desc='{{ i18n "pages.settings.templates.xrayConfigOpenAIWARPDesc"}}' v-model="OpenAIWARPSettings"></setting-list-item>
  182. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigNetflixWARP"}}' desc='{{ i18n "pages.settings.templates.xrayConfigNetflixWARPDesc"}}' v-model="NetflixWARPSettings"></setting-list-item>
  183. <setting-list-item type="switch" title='{{ i18n "pages.settings.templates.xrayConfigSpotifyWARP"}}' desc='{{ i18n "pages.settings.templates.xrayConfigSpotifyWARPDesc"}}' v-model="SpotifyWARPSettings"></setting-list-item>
  184. </a-collapse-panel>
  185. </a-collapse>
  186. </a-tab-pane>
  187. <a-tab-pane key="tpl-2" tab='{{ i18n "pages.settings.templates.advancedTemplate"}}' style="padding-top: 20px;">
  188. <a-collapse>
  189. <a-collapse-panel header='{{ i18n "pages.settings.templates.xrayConfigInbounds"}}'>
  190. <setting-list-item type="textarea" title='{{ i18n "pages.settings.templates.xrayConfigInbounds"}}' desc='{{ i18n "pages.settings.templates.xrayConfigInboundsDesc"}}' v-model="inboundSettings"></setting-list-item>
  191. </a-collapse-panel>
  192. <a-collapse-panel header='{{ i18n "pages.settings.templates.xrayConfigOutbounds"}}'>
  193. <setting-list-item type="textarea" title='{{ i18n "pages.settings.templates.xrayConfigOutbounds"}}' desc='{{ i18n "pages.settings.templates.xrayConfigOutboundsDesc"}}' v-model="outboundSettings"></setting-list-item>
  194. </a-collapse-panel>
  195. <a-collapse-panel header='{{ i18n "pages.settings.templates.xrayConfigRoutings"}}'>
  196. <setting-list-item type="textarea" title='{{ i18n "pages.settings.templates.xrayConfigRoutings"}}' desc='{{ i18n "pages.settings.templates.xrayConfigRoutingsDesc"}}' v-model="routingRuleSettings"></setting-list-item>
  197. </a-collapse-panel>
  198. </a-collapse>
  199. </a-tab-pane>
  200. <a-tab-pane key="tpl-3" tab='{{ i18n "pages.settings.templates.completeTemplate"}}' style="padding-top: 20px;">
  201. <setting-list-item type="textarea" title='{{ i18n "pages.settings.templates.xrayConfigTemplate"}}' desc='{{ i18n "pages.settings.templates.xrayConfigTemplateDesc"}}' v-model="allSetting.xrayTemplateConfig"></setting-list-item>
  202. </a-tab-pane>
  203. </a-tabs>
  204. </a-list>
  205. </a-tab-pane>
  206. <a-tab-pane key="4" tab='{{ i18n "pages.settings.TGBotSettings"}}'>
  207. <a-list item-layout="horizontal" :style="themeSwitcher.textStyle">
  208. <setting-list-item type="switch" title='{{ i18n "pages.settings.telegramBotEnable" }}' desc='{{ i18n "pages.settings.telegramBotEnableDesc" }}' v-model="allSetting.tgBotEnable"></setting-list-item>
  209. <setting-list-item type="text" title='{{ i18n "pages.settings.telegramToken"}}' desc='{{ i18n "pages.settings.telegramTokenDesc"}}' v-model="allSetting.tgBotToken"></setting-list-item>
  210. <setting-list-item type="text" title='{{ i18n "pages.settings.telegramChatId"}}' desc='{{ i18n "pages.settings.telegramChatIdDesc"}}' v-model="allSetting.tgBotChatId"></setting-list-item>
  211. <setting-list-item type="text" title='{{ i18n "pages.settings.telegramNotifyTime"}}' desc='{{ i18n "pages.settings.telegramNotifyTimeDesc"}}' v-model="allSetting.tgRunTime"></setting-list-item>
  212. <setting-list-item type="switch" title='{{ i18n "pages.settings.tgNotifyBackup" }}' desc='{{ i18n "pages.settings.tgNotifyBackupDesc" }}' v-model="allSetting.tgBotBackup"></setting-list-item>
  213. <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>
  214. </a-list>
  215. </a-tab-pane>
  216. </a-tabs>
  217. </a-space>
  218. </a-spin>
  219. </a-layout-content>
  220. </a-layout>
  221. </a-layout>
  222. {{template "js" .}}
  223. {{template "component/themeSwitcher" .}}
  224. {{template "component/password" .}}
  225. {{template "component/setting"}}
  226. <script>
  227. const app = new Vue({
  228. delimiters: ['[[', ']]'],
  229. el: '#app',
  230. data: {
  231. siderDrawer,
  232. themeSwitcher,
  233. spinning: false,
  234. oldAllSetting: new AllSetting(),
  235. allSetting: new AllSetting(),
  236. saveBtnDisable: true,
  237. user: new User(),
  238. lang: getLang(),
  239. ipv4Settings: {
  240. tag: "IPv4",
  241. protocol: "freedom",
  242. settings: {
  243. domainStrategy: "UseIPv4"
  244. }
  245. },
  246. warpSettings: {
  247. tag: "WARP",
  248. protocol: "socks",
  249. settings: {
  250. servers: [
  251. {
  252. address: "127.0.0.1",
  253. port: 40000
  254. }
  255. ]
  256. }
  257. },
  258. settingsData: {
  259. protocols: {
  260. bittorrent: ["bittorrent"],
  261. },
  262. ips: {
  263. local: ["geoip:private"],
  264. google: ["geoip:google"],
  265. cn: ["geoip:cn"],
  266. ir: ["geoip:ir"],
  267. ru: ["geoip:ru"],
  268. },
  269. domains: {
  270. ads: [
  271. "geosite:category-ads-all",
  272. "geosite:category-ads",
  273. "geosite:google-ads",
  274. "geosite:spotify-ads"
  275. ],
  276. porn: ["geosite:category-porn"],
  277. speedtest: ["geosite:speedtest"],
  278. openai: ["geosite:openai"],
  279. google: ["geosite:google"],
  280. spotify: ["geosite:spotify"],
  281. netflix: ["geosite:netflix"],
  282. cn: [
  283. "geosite:cn",
  284. "regexp:.*\\.cn$"
  285. ],
  286. ru: [
  287. "geosite:category-gov-ru",
  288. "regexp:.*\\.ru$"
  289. ],
  290. ir: [
  291. "regexp:.*\\.ir$",
  292. "ext:iran.dat:ir",
  293. "ext:iran.dat:other",
  294. "ext:iran.dat:ads",
  295. "geosite:category-ir"
  296. ]
  297. },
  298. }
  299. },
  300. methods: {
  301. loading(spinning = true, obj) {
  302. if (obj == null) this.spinning = spinning;
  303. },
  304. async getAllSetting() {
  305. this.loading(true);
  306. const msg = await HttpUtil.post("/panel/setting/all");
  307. this.loading(false);
  308. if (msg.success) {
  309. this.oldAllSetting = new AllSetting(msg.obj);
  310. this.allSetting = new AllSetting(msg.obj);
  311. this.saveBtnDisable = true;
  312. }
  313. await this.getUserSecret();
  314. },
  315. async updateAllSetting() {
  316. this.loading(true);
  317. const msg = await HttpUtil.post("/panel/setting/update", this.allSetting);
  318. this.loading(false);
  319. if (msg.success) {
  320. await this.getAllSetting();
  321. }
  322. },
  323. async updateUser() {
  324. this.loading(true);
  325. const msg = await HttpUtil.post("/panel/setting/updateUser", this.user);
  326. this.loading(false);
  327. if (msg.success) {
  328. this.user = {};
  329. window.location.replace(basePath + "logout")
  330. }
  331. },
  332. async restartPanel() {
  333. await new Promise(resolve => {
  334. this.$confirm({
  335. title: '{{ i18n "pages.settings.restartPanel" }}',
  336. content: '{{ i18n "pages.settings.restartPanelDesc" }}',
  337. okText: '{{ i18n "sure" }}',
  338. cancelText: '{{ i18n "cancel" }}',
  339. onOk: () => resolve(),
  340. });
  341. });
  342. this.loading(true);
  343. const msg = await HttpUtil.post("/panel/setting/restartPanel");
  344. this.loading(false);
  345. if (msg.success) {
  346. this.loading(true);
  347. await PromiseUtil.sleep(5000);
  348. location.reload();
  349. }
  350. },
  351. async getUserSecret() {
  352. const user_msg = await HttpUtil.post("/panel/setting/getUserSecret", this.user);
  353. if (user_msg.success) {
  354. this.user = user_msg.obj;
  355. }
  356. this.loading(false);
  357. },
  358. async updateSecret() {
  359. this.loading(true);
  360. const msg = await HttpUtil.post("/panel/setting/updateUserSecret", this.user);
  361. if (msg.success) {
  362. this.user = msg.obj;
  363. window.location.replace(basePath + "logout")
  364. }
  365. this.loading(false);
  366. await this.updateAllSetting();
  367. },
  368. async getNewSecret() {
  369. this.loading(true);
  370. await PromiseUtil.sleep(1000);
  371. var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  372. var string = "";
  373. var len = 64;
  374. for (var ii = 0; ii < len; ii++) {
  375. string += chars[Math.floor(Math.random() * chars.length)];
  376. }
  377. this.user.loginSecret = string;
  378. document.getElementById("token").value = this.user.loginSecret;
  379. this.loading(false);
  380. },
  381. async toggleToken(value) {
  382. if (value) this.getNewSecret();
  383. else this.user.loginSecret = "";
  384. },
  385. async resetXrayConfigToDefault() {
  386. this.loading(true);
  387. const msg = await HttpUtil.get("/panel/setting/getDefaultJsonConfig");
  388. this.loading(false);
  389. if (msg.success) {
  390. this.templateSettings = JSON.parse(JSON.stringify(msg.obj, null, 2));
  391. this.saveBtnDisable = true;
  392. }
  393. },
  394. checkRequiredOutbounds() {
  395. const newTemplateSettings = this.templateSettings;
  396. const haveIPv4Outbounds = newTemplateSettings.outbounds.some((o) => o?.tag === "IPv4");
  397. const haveIPv4Rules = newTemplateSettings.routing.rules.some((r) => r?.outboundTag === "IPv4");
  398. const haveWARPOutbounds = newTemplateSettings.outbounds.some((o) => o?.tag === "WARP");
  399. const haveWARPRules = newTemplateSettings.routing.rules.some((r) => r?.outboundTag === "WARP");
  400. if (haveWARPRules && !haveWARPOutbounds) {
  401. newTemplateSettings.outbounds.push(this.warpSettings);
  402. }
  403. if (haveIPv4Rules && !haveIPv4Outbounds) {
  404. newTemplateSettings.outbounds.push(this.ipv4Settings);
  405. }
  406. this.templateSettings = newTemplateSettings;
  407. },
  408. templateRuleGetter(routeSettings) {
  409. const { data, property, outboundTag } = routeSettings;
  410. let result = false;
  411. if (this.templateSettings != null) {
  412. this.templateSettings.routing.rules.forEach(
  413. (routingRule) => {
  414. if (
  415. routingRule.hasOwnProperty(property) &&
  416. routingRule.hasOwnProperty("outboundTag") &&
  417. routingRule.outboundTag === outboundTag
  418. ) {
  419. if (data.includes(routingRule[property][0])) {
  420. result = true;
  421. }
  422. }
  423. }
  424. );
  425. }
  426. return result;
  427. },
  428. templateRuleSetter(routeSettings) {
  429. const { newValue, data, property, outboundTag } = routeSettings;
  430. const oldTemplateSettings = this.templateSettings;
  431. const newTemplateSettings = oldTemplateSettings;
  432. if (newValue) {
  433. const propertyRule = {
  434. type: "field",
  435. outboundTag,
  436. [property]: data
  437. };
  438. newTemplateSettings.routing.rules.push(propertyRule);
  439. }
  440. else {
  441. const newRules = [];
  442. newTemplateSettings.routing.rules.forEach(
  443. (routingRule) => {
  444. if (
  445. routingRule.hasOwnProperty(property) &&
  446. routingRule.hasOwnProperty("outboundTag") &&
  447. routingRule.outboundTag === outboundTag
  448. ) {
  449. if (data.includes(routingRule[property][0])) {
  450. return;
  451. }
  452. }
  453. newRules.push(routingRule);
  454. }
  455. );
  456. newTemplateSettings.routing.rules = newRules;
  457. }
  458. this.templateSettings = newTemplateSettings;
  459. this.checkRequiredOutbounds();
  460. }
  461. },
  462. async mounted() {
  463. await this.getAllSetting();
  464. while (true) {
  465. await PromiseUtil.sleep(1000);
  466. this.saveBtnDisable = this.oldAllSetting.equals(this.allSetting);
  467. }
  468. },
  469. computed: {
  470. templateSettings: {
  471. get: function () { return this.allSetting.xrayTemplateConfig ? JSON.parse(this.allSetting.xrayTemplateConfig) : null; },
  472. set: function (newValue) { this.allSetting.xrayTemplateConfig = JSON.stringify(newValue, null, 2) },
  473. },
  474. inboundSettings: {
  475. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.inbounds, null, 2) : null; },
  476. set: function (newValue) {
  477. newTemplateSettings = this.templateSettings;
  478. newTemplateSettings.inbounds = JSON.parse(newValue)
  479. this.templateSettings = newTemplateSettings
  480. },
  481. },
  482. outboundSettings: {
  483. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.outbounds, null, 2) : null; },
  484. set: function (newValue) {
  485. newTemplateSettings = this.templateSettings;
  486. newTemplateSettings.outbounds = JSON.parse(newValue)
  487. this.templateSettings = newTemplateSettings
  488. },
  489. },
  490. routingRuleSettings: {
  491. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.routing.rules, null, 2) : null; },
  492. set: function (newValue) {
  493. newTemplateSettings = this.templateSettings;
  494. newTemplateSettings.routing.rules = JSON.parse(newValue)
  495. this.templateSettings = newTemplateSettings
  496. },
  497. },
  498. torrentSettings: {
  499. get: function () {
  500. return this.templateRuleGetter({
  501. outboundTag: "blocked",
  502. property: "protocol",
  503. data: this.settingsData.protocols.bittorrent
  504. });
  505. },
  506. set: function (newValue) {
  507. this.templateRuleSetter({
  508. newValue,
  509. outboundTag: "blocked",
  510. property: "protocol",
  511. data: this.settingsData.protocols.bittorrent
  512. });
  513. },
  514. },
  515. privateIpSettings: {
  516. get: function () {
  517. return this.templateRuleGetter({
  518. outboundTag: "blocked",
  519. property: "ip",
  520. data: this.settingsData.ips.local
  521. });
  522. },
  523. set: function (newValue) {
  524. this.templateRuleSetter({
  525. newValue,
  526. outboundTag: "blocked",
  527. property: "ip",
  528. data: this.settingsData.ips.local
  529. });
  530. },
  531. },
  532. AdsSettings: {
  533. get: function () {
  534. return this.templateRuleGetter({
  535. outboundTag: "blocked",
  536. property: "domain",
  537. data: this.settingsData.domains.ads
  538. });
  539. },
  540. set: function (newValue) {
  541. this.templateRuleSetter({
  542. newValue,
  543. outboundTag: "blocked",
  544. property: "domain",
  545. data: this.settingsData.domains.ads
  546. });
  547. },
  548. },
  549. PornSettings: {
  550. get: function () {
  551. return this.templateRuleGetter({
  552. outboundTag: "blocked",
  553. property: "domain",
  554. data: this.settingsData.domains.porn
  555. });
  556. },
  557. set: function (newValue) {
  558. this.templateRuleSetter({
  559. newValue,
  560. outboundTag: "blocked",
  561. property: "domain",
  562. data: this.settingsData.domains.porn
  563. });
  564. },
  565. },
  566. SpeedTestSettings: {
  567. get: function () {
  568. return this.templateRuleGetter({
  569. outboundTag: "blocked",
  570. property: "domain",
  571. data: this.settingsData.domains.speedtest
  572. });
  573. },
  574. set: function (newValue) {
  575. this.templateRuleSetter({
  576. newValue,
  577. outboundTag: "blocked",
  578. property: "domain",
  579. data: this.settingsData.domains.speedtest
  580. });
  581. },
  582. },
  583. GoogleIPv4Settings: {
  584. get: function () {
  585. return this.templateRuleGetter({
  586. outboundTag: "IPv4",
  587. property: "domain",
  588. data: this.settingsData.domains.google
  589. });
  590. },
  591. set: function (newValue) {
  592. this.templateRuleSetter({
  593. newValue,
  594. outboundTag: "IPv4",
  595. property: "domain",
  596. data: this.settingsData.domains.google
  597. });
  598. },
  599. },
  600. NetflixIPv4Settings: {
  601. get: function () {
  602. return this.templateRuleGetter({
  603. outboundTag: "IPv4",
  604. property: "domain",
  605. data: this.settingsData.domains.netflix
  606. });
  607. },
  608. set: function (newValue) {
  609. this.templateRuleSetter({
  610. newValue,
  611. outboundTag: "IPv4",
  612. property: "domain",
  613. data: this.settingsData.domains.netflix
  614. });
  615. },
  616. },
  617. IRIpSettings: {
  618. get: function () {
  619. return this.templateRuleGetter({
  620. outboundTag: "blocked",
  621. property: "ip",
  622. data: this.settingsData.ips.ir
  623. });
  624. },
  625. set: function (newValue) {
  626. this.templateRuleSetter({
  627. newValue,
  628. outboundTag: "blocked",
  629. property: "ip",
  630. data: this.settingsData.ips.ir
  631. });
  632. },
  633. },
  634. IRDomainSettings: {
  635. get: function () {
  636. return this.templateRuleGetter({
  637. outboundTag: "blocked",
  638. property: "domain",
  639. data: this.settingsData.domains.ir
  640. });
  641. },
  642. set: function (newValue) {
  643. this.templateRuleSetter({
  644. newValue,
  645. outboundTag: "blocked",
  646. property: "domain",
  647. data: this.settingsData.domains.ir
  648. });
  649. },
  650. },
  651. ChinaIpSettings: {
  652. get: function () {
  653. return this.templateRuleGetter({
  654. outboundTag: "blocked",
  655. property: "ip",
  656. data: this.settingsData.ips.cn
  657. });
  658. },
  659. set: function (newValue) {
  660. this.templateRuleSetter({
  661. newValue,
  662. outboundTag: "blocked",
  663. property: "ip",
  664. data: this.settingsData.ips.cn
  665. });
  666. },
  667. },
  668. ChinaDomainSettings: {
  669. get: function () {
  670. return this.templateRuleGetter({
  671. outboundTag: "blocked",
  672. property: "domain",
  673. data: this.settingsData.domains.cn
  674. });
  675. },
  676. set: function (newValue) {
  677. this.templateRuleSetter({
  678. newValue,
  679. outboundTag: "blocked",
  680. property: "domain",
  681. data: this.settingsData.domains.cn
  682. });
  683. },
  684. },
  685. RussiaIpSettings: {
  686. get: function () {
  687. return this.templateRuleGetter({
  688. outboundTag: "blocked",
  689. property: "ip",
  690. data: this.settingsData.ips.ru
  691. });
  692. },
  693. set: function (newValue) {
  694. this.templateRuleSetter({
  695. newValue,
  696. outboundTag: "blocked",
  697. property: "ip",
  698. data: this.settingsData.ips.ru
  699. });
  700. },
  701. },
  702. RussiaDomainSettings: {
  703. get: function () {
  704. return this.templateRuleGetter({
  705. outboundTag: "blocked",
  706. property: "domain",
  707. data: this.settingsData.domains.ru
  708. });
  709. },
  710. set: function (newValue) {
  711. this.templateRuleSetter({
  712. newValue,
  713. outboundTag: "blocked",
  714. property: "domain",
  715. data: this.settingsData.domains.ru
  716. });
  717. },
  718. },
  719. GoogleWARPSettings: {
  720. get: function () {
  721. return this.templateRuleGetter({
  722. outboundTag: "WARP",
  723. property: "domain",
  724. data: this.settingsData.domains.google
  725. });
  726. },
  727. set: function (newValue) {
  728. this.templateRuleSetter({
  729. newValue,
  730. outboundTag: "WARP",
  731. property: "domain",
  732. data: this.settingsData.domains.google
  733. });
  734. },
  735. },
  736. OpenAIWARPSettings: {
  737. get: function () {
  738. return this.templateRuleGetter({
  739. outboundTag: "WARP",
  740. property: "domain",
  741. data: this.settingsData.domains.openai
  742. });
  743. },
  744. set: function (newValue) {
  745. this.templateRuleSetter({
  746. newValue,
  747. outboundTag: "WARP",
  748. property: "domain",
  749. data: this.settingsData.domains.openai
  750. });
  751. },
  752. },
  753. NetflixWARPSettings: {
  754. get: function () {
  755. return this.templateRuleGetter({
  756. outboundTag: "WARP",
  757. property: "domain",
  758. data: this.settingsData.domains.netflix
  759. });
  760. },
  761. set: function (newValue) {
  762. this.templateRuleSetter({
  763. newValue,
  764. outboundTag: "WARP",
  765. property: "domain",
  766. data: this.settingsData.domains.netflix
  767. });
  768. },
  769. },
  770. SpotifyWARPSettings: {
  771. get: function () {
  772. return this.templateRuleGetter({
  773. outboundTag: "WARP",
  774. property: "domain",
  775. data: this.settingsData.domains.spotify
  776. });
  777. },
  778. set: function (newValue) {
  779. this.templateRuleSetter({
  780. newValue,
  781. outboundTag: "WARP",
  782. property: "domain",
  783. data: this.settingsData.domains.spotify
  784. });
  785. },
  786. },
  787. }
  788. });
  789. </script>
  790. </body>
  791. </html>