settings.html 46 KB

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