settings.html 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  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. themeSwitcher,
  232. spinning: false,
  233. oldAllSetting: new AllSetting(),
  234. allSetting: new AllSetting(),
  235. saveBtnDisable: true,
  236. user: new User(),
  237. lang: getLang(),
  238. ipv4Settings: {
  239. tag: "IPv4",
  240. protocol: "freedom",
  241. settings: {
  242. domainStrategy: "UseIPv4"
  243. }
  244. },
  245. warpSettings: {
  246. tag: "WARP",
  247. protocol: "socks",
  248. settings: {
  249. servers: [
  250. {
  251. address: "127.0.0.1",
  252. port: 40000
  253. }
  254. ]
  255. }
  256. },
  257. settingsData: {
  258. protocols: {
  259. bittorrent: ["bittorrent"],
  260. },
  261. ips: {
  262. local: ["geoip:private"],
  263. google: ["geoip:google"],
  264. cn: ["geoip:cn"],
  265. ir: ["geoip:ir"],
  266. ru: ["geoip:ru"],
  267. },
  268. domains: {
  269. ads: [
  270. "geosite:category-ads-all",
  271. "geosite:category-ads",
  272. "geosite:google-ads",
  273. "geosite:spotify-ads"
  274. ],
  275. porn: ["geosite:category-porn"],
  276. speedtest: ["geosite:speedtest"],
  277. openai: ["geosite:openai"],
  278. google: ["geosite:google"],
  279. spotify: ["geosite:spotify"],
  280. netflix: ["geosite:netflix"],
  281. cn: [
  282. "geosite:cn",
  283. "regexp:.*\\.cn$"
  284. ],
  285. ru: [
  286. "geosite:category-gov-ru",
  287. "regexp:.*\\.ru$"
  288. ],
  289. ir: [
  290. "regexp:.*\\.ir$",
  291. "ext:iran.dat:ir",
  292. "ext:iran.dat:other",
  293. "ext:iran.dat:ads",
  294. "geosite:category-ir"
  295. ]
  296. },
  297. }
  298. },
  299. methods: {
  300. loading(spinning = true, obj) {
  301. if (obj == null) this.spinning = spinning;
  302. },
  303. async getAllSetting() {
  304. this.loading(true);
  305. const msg = await HttpUtil.post("/panel/setting/all");
  306. this.loading(false);
  307. if (msg.success) {
  308. this.oldAllSetting = new AllSetting(msg.obj);
  309. this.allSetting = new AllSetting(msg.obj);
  310. this.saveBtnDisable = true;
  311. }
  312. await this.getUserSecret();
  313. },
  314. async updateAllSetting() {
  315. this.loading(true);
  316. const msg = await HttpUtil.post("/panel/setting/update", this.allSetting);
  317. this.loading(false);
  318. if (msg.success) {
  319. await this.getAllSetting();
  320. }
  321. },
  322. async updateUser() {
  323. this.loading(true);
  324. const msg = await HttpUtil.post("/panel/setting/updateUser", this.user);
  325. this.loading(false);
  326. if (msg.success) {
  327. this.user = {};
  328. window.location.replace(basePath + "logout")
  329. }
  330. },
  331. async restartPanel() {
  332. await new Promise(resolve => {
  333. this.$confirm({
  334. title: '{{ i18n "pages.settings.restartPanel" }}',
  335. content: '{{ i18n "pages.settings.restartPanelDesc" }}',
  336. okText: '{{ i18n "sure" }}',
  337. cancelText: '{{ i18n "cancel" }}',
  338. onOk: () => resolve(),
  339. });
  340. });
  341. this.loading(true);
  342. const msg = await HttpUtil.post("/panel/setting/restartPanel");
  343. this.loading(false);
  344. if (msg.success) {
  345. this.loading(true);
  346. await PromiseUtil.sleep(5000);
  347. location.reload();
  348. }
  349. },
  350. async getUserSecret() {
  351. const user_msg = await HttpUtil.post("/panel/setting/getUserSecret", this.user);
  352. if (user_msg.success) {
  353. this.user = user_msg.obj;
  354. }
  355. this.loading(false);
  356. },
  357. async updateSecret() {
  358. this.loading(true);
  359. const msg = await HttpUtil.post("/panel/setting/updateUserSecret", this.user);
  360. if (msg.success) {
  361. this.user = msg.obj;
  362. window.location.replace(basePath + "logout")
  363. }
  364. this.loading(false);
  365. await this.updateAllSetting();
  366. },
  367. async getNewSecret() {
  368. this.loading(true);
  369. await PromiseUtil.sleep(1000);
  370. var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  371. var string = "";
  372. var len = 64;
  373. for (var ii = 0; ii < len; ii++) {
  374. string += chars[Math.floor(Math.random() * chars.length)];
  375. }
  376. this.user.loginSecret = string;
  377. document.getElementById("token").value = this.user.loginSecret;
  378. this.loading(false);
  379. },
  380. async toggleToken(value) {
  381. if (value) this.getNewSecret();
  382. else this.user.loginSecret = "";
  383. },
  384. async resetXrayConfigToDefault() {
  385. this.loading(true);
  386. const msg = await HttpUtil.get("/panel/setting/getDefaultJsonConfig");
  387. this.loading(false);
  388. if (msg.success) {
  389. this.templateSettings = JSON.parse(JSON.stringify(msg.obj, null, 2));
  390. this.saveBtnDisable = true;
  391. }
  392. },
  393. checkRequiredOutbounds() {
  394. const newTemplateSettings = this.templateSettings;
  395. const haveIPv4Outbounds = newTemplateSettings.outbounds.some((o) => o?.tag === "IPv4");
  396. const haveIPv4Rules = newTemplateSettings.routing.rules.some((r) => r?.outboundTag === "IPv4");
  397. const haveWARPOutbounds = newTemplateSettings.outbounds.some((o) => o?.tag === "WARP");
  398. const haveWARPRules = newTemplateSettings.routing.rules.some((r) => r?.outboundTag === "WARP");
  399. if (haveWARPRules && !haveWARPOutbounds) {
  400. newTemplateSettings.outbounds.push(this.warpSettings);
  401. }
  402. if (haveIPv4Rules && !haveIPv4Outbounds) {
  403. newTemplateSettings.outbounds.push(this.ipv4Settings);
  404. }
  405. this.templateSettings = newTemplateSettings;
  406. },
  407. templateRuleGetter(routeSettings) {
  408. const { data, property, outboundTag } = routeSettings;
  409. let result = false;
  410. if (this.templateSettings != null) {
  411. this.templateSettings.routing.rules.forEach(
  412. (routingRule) => {
  413. if (
  414. routingRule.hasOwnProperty(property) &&
  415. routingRule.hasOwnProperty("outboundTag") &&
  416. routingRule.outboundTag === outboundTag
  417. ) {
  418. if (data.includes(routingRule[property][0])) {
  419. result = true;
  420. }
  421. }
  422. }
  423. );
  424. }
  425. return result;
  426. },
  427. templateRuleSetter(routeSettings) {
  428. const { newValue, data, property, outboundTag } = routeSettings;
  429. const oldTemplateSettings = this.templateSettings;
  430. const newTemplateSettings = oldTemplateSettings;
  431. if (newValue) {
  432. const propertyRule = {
  433. type: "field",
  434. outboundTag,
  435. [property]: data
  436. };
  437. newTemplateSettings.routing.rules.push(propertyRule);
  438. }
  439. else {
  440. const newRules = [];
  441. newTemplateSettings.routing.rules.forEach(
  442. (routingRule) => {
  443. if (
  444. routingRule.hasOwnProperty(property) &&
  445. routingRule.hasOwnProperty("outboundTag") &&
  446. routingRule.outboundTag === outboundTag
  447. ) {
  448. if (data.includes(routingRule[property][0])) {
  449. return;
  450. }
  451. }
  452. newRules.push(routingRule);
  453. }
  454. );
  455. newTemplateSettings.routing.rules = newRules;
  456. }
  457. this.templateSettings = newTemplateSettings;
  458. this.checkRequiredOutbounds();
  459. }
  460. },
  461. async mounted() {
  462. await this.getAllSetting();
  463. while (true) {
  464. await PromiseUtil.sleep(1000);
  465. this.saveBtnDisable = this.oldAllSetting.equals(this.allSetting);
  466. }
  467. },
  468. computed: {
  469. templateSettings: {
  470. get: function () { return this.allSetting.xrayTemplateConfig ? JSON.parse(this.allSetting.xrayTemplateConfig) : null; },
  471. set: function (newValue) { this.allSetting.xrayTemplateConfig = JSON.stringify(newValue, null, 2) },
  472. },
  473. inboundSettings: {
  474. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.inbounds, null, 2) : null; },
  475. set: function (newValue) {
  476. newTemplateSettings = this.templateSettings;
  477. newTemplateSettings.inbounds = JSON.parse(newValue)
  478. this.templateSettings = newTemplateSettings
  479. },
  480. },
  481. outboundSettings: {
  482. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.outbounds, null, 2) : null; },
  483. set: function (newValue) {
  484. newTemplateSettings = this.templateSettings;
  485. newTemplateSettings.outbounds = JSON.parse(newValue)
  486. this.templateSettings = newTemplateSettings
  487. },
  488. },
  489. routingRuleSettings: {
  490. get: function () { return this.templateSettings ? JSON.stringify(this.templateSettings.routing.rules, null, 2) : null; },
  491. set: function (newValue) {
  492. newTemplateSettings = this.templateSettings;
  493. newTemplateSettings.routing.rules = JSON.parse(newValue)
  494. this.templateSettings = newTemplateSettings
  495. },
  496. },
  497. torrentSettings: {
  498. get: function () {
  499. return this.templateRuleGetter({
  500. outboundTag: "blocked",
  501. property: "protocol",
  502. data: this.settingsData.protocols.bittorrent
  503. });
  504. },
  505. set: function (newValue) {
  506. this.templateRuleSetter({
  507. newValue,
  508. outboundTag: "blocked",
  509. property: "protocol",
  510. data: this.settingsData.protocols.bittorrent
  511. });
  512. },
  513. },
  514. privateIpSettings: {
  515. get: function () {
  516. return this.templateRuleGetter({
  517. outboundTag: "blocked",
  518. property: "ip",
  519. data: this.settingsData.ips.local
  520. });
  521. },
  522. set: function (newValue) {
  523. this.templateRuleSetter({
  524. newValue,
  525. outboundTag: "blocked",
  526. property: "ip",
  527. data: this.settingsData.ips.local
  528. });
  529. },
  530. },
  531. AdsSettings: {
  532. get: function () {
  533. return this.templateRuleGetter({
  534. outboundTag: "blocked",
  535. property: "domain",
  536. data: this.settingsData.domains.ads
  537. });
  538. },
  539. set: function (newValue) {
  540. this.templateRuleSetter({
  541. newValue,
  542. outboundTag: "blocked",
  543. property: "domain",
  544. data: this.settingsData.domains.ads
  545. });
  546. },
  547. },
  548. PornSettings: {
  549. get: function () {
  550. return this.templateRuleGetter({
  551. outboundTag: "blocked",
  552. property: "domain",
  553. data: this.settingsData.domains.porn
  554. });
  555. },
  556. set: function (newValue) {
  557. this.templateRuleSetter({
  558. newValue,
  559. outboundTag: "blocked",
  560. property: "domain",
  561. data: this.settingsData.domains.porn
  562. });
  563. },
  564. },
  565. SpeedTestSettings: {
  566. get: function () {
  567. return this.templateRuleGetter({
  568. outboundTag: "blocked",
  569. property: "domain",
  570. data: this.settingsData.domains.speedtest
  571. });
  572. },
  573. set: function (newValue) {
  574. this.templateRuleSetter({
  575. newValue,
  576. outboundTag: "blocked",
  577. property: "domain",
  578. data: this.settingsData.domains.speedtest
  579. });
  580. },
  581. },
  582. GoogleIPv4Settings: {
  583. get: function () {
  584. return this.templateRuleGetter({
  585. outboundTag: "IPv4",
  586. property: "domain",
  587. data: this.settingsData.domains.google
  588. });
  589. },
  590. set: function (newValue) {
  591. this.templateRuleSetter({
  592. newValue,
  593. outboundTag: "IPv4",
  594. property: "domain",
  595. data: this.settingsData.domains.google
  596. });
  597. },
  598. },
  599. NetflixIPv4Settings: {
  600. get: function () {
  601. return this.templateRuleGetter({
  602. outboundTag: "IPv4",
  603. property: "domain",
  604. data: this.settingsData.domains.netflix
  605. });
  606. },
  607. set: function (newValue) {
  608. this.templateRuleSetter({
  609. newValue,
  610. outboundTag: "IPv4",
  611. property: "domain",
  612. data: this.settingsData.domains.netflix
  613. });
  614. },
  615. },
  616. IRIpSettings: {
  617. get: function () {
  618. return this.templateRuleGetter({
  619. outboundTag: "blocked",
  620. property: "ip",
  621. data: this.settingsData.ips.ir
  622. });
  623. },
  624. set: function (newValue) {
  625. this.templateRuleSetter({
  626. newValue,
  627. outboundTag: "blocked",
  628. property: "ip",
  629. data: this.settingsData.ips.ir
  630. });
  631. },
  632. },
  633. IRDomainSettings: {
  634. get: function () {
  635. return this.templateRuleGetter({
  636. outboundTag: "blocked",
  637. property: "domain",
  638. data: this.settingsData.domains.ir
  639. });
  640. },
  641. set: function (newValue) {
  642. this.templateRuleSetter({
  643. newValue,
  644. outboundTag: "blocked",
  645. property: "domain",
  646. data: this.settingsData.domains.ir
  647. });
  648. },
  649. },
  650. ChinaIpSettings: {
  651. get: function () {
  652. return this.templateRuleGetter({
  653. outboundTag: "blocked",
  654. property: "ip",
  655. data: this.settingsData.ips.cn
  656. });
  657. },
  658. set: function (newValue) {
  659. this.templateRuleSetter({
  660. newValue,
  661. outboundTag: "blocked",
  662. property: "ip",
  663. data: this.settingsData.ips.cn
  664. });
  665. },
  666. },
  667. ChinaDomainSettings: {
  668. get: function () {
  669. return this.templateRuleGetter({
  670. outboundTag: "blocked",
  671. property: "domain",
  672. data: this.settingsData.domains.cn
  673. });
  674. },
  675. set: function (newValue) {
  676. this.templateRuleSetter({
  677. newValue,
  678. outboundTag: "blocked",
  679. property: "domain",
  680. data: this.settingsData.domains.cn
  681. });
  682. },
  683. },
  684. RussiaIpSettings: {
  685. get: function () {
  686. return this.templateRuleGetter({
  687. outboundTag: "blocked",
  688. property: "ip",
  689. data: this.settingsData.ips.ru
  690. });
  691. },
  692. set: function (newValue) {
  693. this.templateRuleSetter({
  694. newValue,
  695. outboundTag: "blocked",
  696. property: "ip",
  697. data: this.settingsData.ips.ru
  698. });
  699. },
  700. },
  701. RussiaDomainSettings: {
  702. get: function () {
  703. return this.templateRuleGetter({
  704. outboundTag: "blocked",
  705. property: "domain",
  706. data: this.settingsData.domains.ru
  707. });
  708. },
  709. set: function (newValue) {
  710. this.templateRuleSetter({
  711. newValue,
  712. outboundTag: "blocked",
  713. property: "domain",
  714. data: this.settingsData.domains.ru
  715. });
  716. },
  717. },
  718. GoogleWARPSettings: {
  719. get: function () {
  720. return this.templateRuleGetter({
  721. outboundTag: "WARP",
  722. property: "domain",
  723. data: this.settingsData.domains.google
  724. });
  725. },
  726. set: function (newValue) {
  727. this.templateRuleSetter({
  728. newValue,
  729. outboundTag: "WARP",
  730. property: "domain",
  731. data: this.settingsData.domains.google
  732. });
  733. },
  734. },
  735. OpenAIWARPSettings: {
  736. get: function () {
  737. return this.templateRuleGetter({
  738. outboundTag: "WARP",
  739. property: "domain",
  740. data: this.settingsData.domains.openai
  741. });
  742. },
  743. set: function (newValue) {
  744. this.templateRuleSetter({
  745. newValue,
  746. outboundTag: "WARP",
  747. property: "domain",
  748. data: this.settingsData.domains.openai
  749. });
  750. },
  751. },
  752. NetflixWARPSettings: {
  753. get: function () {
  754. return this.templateRuleGetter({
  755. outboundTag: "WARP",
  756. property: "domain",
  757. data: this.settingsData.domains.netflix
  758. });
  759. },
  760. set: function (newValue) {
  761. this.templateRuleSetter({
  762. newValue,
  763. outboundTag: "WARP",
  764. property: "domain",
  765. data: this.settingsData.domains.netflix
  766. });
  767. },
  768. },
  769. SpotifyWARPSettings: {
  770. get: function () {
  771. return this.templateRuleGetter({
  772. outboundTag: "WARP",
  773. property: "domain",
  774. data: this.settingsData.domains.spotify
  775. });
  776. },
  777. set: function (newValue) {
  778. this.templateRuleSetter({
  779. newValue,
  780. outboundTag: "WARP",
  781. property: "domain",
  782. data: this.settingsData.domains.spotify
  783. });
  784. },
  785. },
  786. }
  787. });
  788. </script>
  789. </body>
  790. </html>