1
0

settings.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. {{ template "page/head_start" .}}
  2. {{ template "page/head_end" .}}
  3. {{ template "page/body_start" .}}
  4. <a-layout id="app" v-cloak :class="themeSwitcher.currentTheme + ' settings-page'">
  5. <a-sidebar></a-sidebar>
  6. <a-layout id="content-layout">
  7. <a-layout-content>
  8. <a-spin :spinning="loadingStates.spinning" :delay="500" tip='{{ i18n "loading"}}'>
  9. <transition name="list" appear>
  10. <a-alert type="error" v-if="confAlerts.length>0 && loadingStates.fetched" :style="{ marginBottom: '10px' }"
  11. message='{{ i18n "secAlertTitle" }}'
  12. color="red"
  13. show-icon closable>
  14. <template slot="description">
  15. <b>{{ i18n "secAlertConf" }}</b>
  16. <ul><li v-for="a in confAlerts">[[ a ]]</li></ul>
  17. </template>
  18. </a-alert>
  19. </transition>
  20. <transition name="list" appear>
  21. <template>
  22. <a-row v-if="!loadingStates.fetched">
  23. <a-card :style="{ textAlign: 'center', padding: '30px 0', marginTop: '10px', background: 'transparent', border: 'none' }">
  24. <a-spin tip='{{ i18n "loading" }}'></a-spin>
  25. </a-card>
  26. </a-row>
  27. <a-row :gutter="[isMobile ? 8 : 16, isMobile ? 0 : 12]" v-else>
  28. <a-col>
  29. <a-card hoverable>
  30. <a-row :style="{ display: 'flex', flexWrap: 'wrap', alignItems: 'center' }">
  31. <a-col :xs="24" :sm="10" :style="{ padding: '4px' }">
  32. <a-space direction="horizontal">
  33. <a-button type="primary" :disabled="saveBtnDisable" @click="updateAllSetting">{{ i18n "pages.settings.save" }}</a-button>
  34. <a-button type="danger" :disabled="!saveBtnDisable" @click="restartPanel">{{ i18n "pages.settings.restartPanel" }}</a-button>
  35. </a-space>
  36. </a-col>
  37. <a-col :xs="24" :sm="14">
  38. <template>
  39. <div>
  40. <a-back-top :target="() => document.getElementById('content-layout')" visibility-height="200"></a-back-top>
  41. <a-alert type="warning" :style="{ float: 'right', width: 'fit-content' }"
  42. message='{{ i18n "pages.settings.infoDesc" }}'
  43. show-icon>
  44. </a-alert>
  45. </div>
  46. </template>
  47. </a-col>
  48. </a-row>
  49. </a-card>
  50. </a-col>
  51. <a-col>
  52. <a-tabs default-active-key="1">
  53. <a-tab-pane key="1" :style="{ paddingTop: '20px' }">
  54. <template #tab>
  55. <a-icon type="setting"></a-icon>
  56. <span>{{ i18n "pages.settings.panelSettings" }}</span>
  57. </template>
  58. {{ template "settings/panel/general" . }}
  59. </a-tab-pane>
  60. <a-tab-pane key="2" :style="{ paddingTop: '20px' }">
  61. <template #tab>
  62. <a-icon type="safety"></a-icon>
  63. <span>{{ i18n "pages.settings.securitySettings" }}</span>
  64. </template>
  65. {{ template "settings/panel/security" . }}
  66. </a-tab-pane>
  67. <a-tab-pane key="3" :style="{ paddingTop: '20px' }">
  68. <template #tab>
  69. <a-icon type="message"></a-icon>
  70. <span>{{ i18n "pages.settings.TGBotSettings" }}</span>
  71. </template>
  72. {{ template "settings/panel/telegram" . }}
  73. </a-tab-pane>
  74. <a-tab-pane key="4" :style="{ paddingTop: '20px' }">
  75. <template #tab>
  76. <a-icon type="cloud-server"></a-icon>
  77. <span>{{ i18n "pages.settings.subSettings" }}</span>
  78. </template>
  79. {{ template "settings/panel/subscription/general" . }}
  80. </a-tab-pane>
  81. <a-tab-pane key="5" v-if="allSetting.subEnable" :style="{ paddingTop: '20px' }">
  82. <template #tab>
  83. <a-icon type="code"></a-icon>
  84. <span>{{ i18n "pages.settings.subSettings" }} (JSON)</span>
  85. </template>
  86. {{ template "settings/panel/subscription/json" . }}
  87. </a-tab-pane>
  88. </a-tabs>
  89. </a-col>
  90. </a-row>
  91. </template>
  92. </transition>
  93. </a-spin>
  94. </a-layout-content>
  95. </a-layout>
  96. </a-layout>
  97. {{template "page/body_scripts" .}}
  98. <script src="{{ .base_path }}assets/qrcode/qrious2.min.js?{{ .cur_ver }}"></script>
  99. <script src="{{ .base_path }}assets/otpauth/otpauth.umd.min.js?{{ .cur_ver }}"></script>
  100. <script src="{{ .base_path }}assets/js/model/setting.js?{{ .cur_ver }}"></script>
  101. {{template "component/aSidebar" .}}
  102. {{template "component/aThemeSwitch" .}}
  103. {{template "component/aSettingListItem" .}}
  104. {{template "modals/twoFactorModal"}}
  105. <script>
  106. const app = new Vue({
  107. delimiters: ['[[', ']]'],
  108. mixins: [MediaQueryMixin],
  109. el: '#app',
  110. data: {
  111. themeSwitcher,
  112. loadingStates: {
  113. fetched: false,
  114. spinning: false
  115. },
  116. oldAllSetting: new AllSetting(),
  117. allSetting: new AllSetting(),
  118. saveBtnDisable: true,
  119. user: {},
  120. lang: LanguageManager.getLanguage(),
  121. remarkModels: { i: 'Inbound', e: 'Email', o: 'Other' },
  122. remarkSeparators: [' ', '-', '_', '@', ':', '~', '|', ',', '.', '/'],
  123. datepickerList: [{ name: 'Gregorian (Standard)', value: 'gregorian' }, { name: 'Jalalian (شمسی)', value: 'jalalian' }],
  124. remarkSample: '',
  125. defaultFragment: {
  126. tag: "fragment",
  127. protocol: "freedom",
  128. settings: {
  129. domainStrategy: "AsIs",
  130. fragment: {
  131. packets: "tlshello",
  132. length: "100-200",
  133. interval: "10-20"
  134. }
  135. },
  136. streamSettings: {
  137. sockopt: {
  138. tcpKeepAliveIdle: 100,
  139. tcpMptcp: true,
  140. penetrate: true
  141. }
  142. }
  143. },
  144. defaultNoises: {
  145. tag: "noises",
  146. protocol: "freedom",
  147. settings: {
  148. domainStrategy: "AsIs",
  149. noises: [
  150. { type: "rand", packet: "10-20", delay: "10-16", applyTo: "ip" },
  151. ],
  152. },
  153. },
  154. defaultMux: {
  155. enabled: true,
  156. concurrency: 8,
  157. xudpConcurrency: 16,
  158. xudpProxyUDP443: "reject"
  159. },
  160. defaultRules: [
  161. {
  162. type: "field",
  163. outboundTag: "direct",
  164. domain: [
  165. "geosite:category-ir"
  166. ]
  167. },
  168. {
  169. type: "field",
  170. outboundTag: "direct",
  171. ip: [
  172. "geoip:private",
  173. "geoip:ir"
  174. ]
  175. },
  176. ],
  177. directIPsOptions: [
  178. { label: 'Private IP', value: 'geoip:private' },
  179. { label: '🇮🇷 Iran', value: 'geoip:ir' },
  180. { label: '🇨🇳 China', value: 'geoip:cn' },
  181. { label: '🇷🇺 Russia', value: 'geoip:ru' },
  182. { label: '🇻🇳 Vietnam', value: 'geoip:vn' },
  183. { label: '🇪🇸 Spain', value: 'geoip:es' },
  184. { label: '🇮🇩 Indonesia', value: 'geoip:id' },
  185. { label: '🇺🇦 Ukraine', value: 'geoip:ua' },
  186. { label: '🇹🇷 Türkiye', value: 'geoip:tr' },
  187. { label: '🇧🇷 Brazil', value: 'geoip:br' },
  188. ],
  189. diretDomainsOptions: [
  190. { label: 'Private DNS', value: 'geosite:private' },
  191. { label: '🇮🇷 Iran', value: 'geosite:category-ir' },
  192. { label: '🇨🇳 China', value: 'geosite:cn' },
  193. { label: '🇷🇺 Russia', value: 'geosite:category-ru' },
  194. { label: 'Apple', value: 'geosite:apple' },
  195. { label: 'Meta', value: 'geosite:meta' },
  196. { label: 'Google', value: 'geosite:google' },
  197. ],
  198. get remarkModel() {
  199. rm = this.allSetting.remarkModel;
  200. return rm.length > 1 ? rm.substring(1).split('') : [];
  201. },
  202. set remarkModel(value) {
  203. rs = this.allSetting.remarkModel[0];
  204. this.allSetting.remarkModel = rs + value.join('');
  205. this.changeRemarkSample();
  206. },
  207. get remarkSeparator() {
  208. return this.allSetting.remarkModel.length > 1 ? this.allSetting.remarkModel.charAt(0) : '-';
  209. },
  210. set remarkSeparator(value) {
  211. this.allSetting.remarkModel = value + this.allSetting.remarkModel.substring(1);
  212. this.changeRemarkSample();
  213. },
  214. get datepicker() {
  215. return this.allSetting.datepicker ? this.allSetting.datepicker : 'gregorian';
  216. },
  217. set datepicker(value) {
  218. this.allSetting.datepicker = value;
  219. },
  220. changeRemarkSample() {
  221. sample = []
  222. this.remarkModel.forEach(r => sample.push(this.remarkModels[r]));
  223. this.remarkSample = sample.length == 0 ? '' : sample.join(this.remarkSeparator);
  224. }
  225. },
  226. methods: {
  227. loading(spinning = true) {
  228. this.loadingStates.spinning = spinning;
  229. },
  230. async getAllSetting() {
  231. const msg = await HttpUtil.post("/panel/setting/all");
  232. if (msg.success) {
  233. if (!this.loadingStates.fetched) {
  234. this.loadingStates.fetched = true
  235. }
  236. this.oldAllSetting = new AllSetting(msg.obj);
  237. this.allSetting = new AllSetting(msg.obj);
  238. app.changeRemarkSample();
  239. this.saveBtnDisable = true;
  240. }
  241. },
  242. async updateAllSetting() {
  243. this.loading(true);
  244. const msg = await HttpUtil.post("/panel/setting/update", this.allSetting);
  245. this.loading(false);
  246. if (msg.success) {
  247. await this.getAllSetting();
  248. }
  249. },
  250. async updateUser() {
  251. const sendUpdateUserRequest = async () => {
  252. this.loading(true);
  253. const msg = await HttpUtil.post("/panel/setting/updateUser", this.user);
  254. this.loading(false);
  255. if (msg.success) {
  256. this.user = {};
  257. window.location.replace(basePath + "logout");
  258. }
  259. }
  260. if (this.allSetting.twoFactorEnable) {
  261. twoFactorModal.show({
  262. title: '{{ i18n "pages.settings.security.twoFactorModalChangeCredentialsTitle" }}',
  263. description: '{{ i18n "pages.settings.security.twoFactorModalChangeCredentialsStep" }}',
  264. token: this.allSetting.twoFactorToken,
  265. type: 'confirm',
  266. confirm: (success) => {
  267. if (success) {
  268. sendUpdateUserRequest();
  269. }
  270. }
  271. })
  272. } else {
  273. sendUpdateUserRequest();
  274. }
  275. },
  276. async restartPanel() {
  277. await new Promise(resolve => {
  278. this.$confirm({
  279. title: '{{ i18n "pages.settings.restartPanel" }}',
  280. content: '{{ i18n "pages.settings.restartPanelDesc" }}',
  281. class: themeSwitcher.currentTheme,
  282. okText: '{{ i18n "sure" }}',
  283. cancelText: '{{ i18n "cancel" }}',
  284. onOk: () => resolve(),
  285. });
  286. });
  287. this.loading(true);
  288. const msg = await HttpUtil.post("/panel/setting/restartPanel");
  289. this.loading(false);
  290. if (msg.success) {
  291. this.loading(true);
  292. await PromiseUtil.sleep(5000);
  293. var { webCertFile, webKeyFile, webDomain: host, webPort: port, webBasePath: base } = this.allSetting;
  294. if (host == this.oldAllSetting.webDomain) host = null;
  295. if (port == this.oldAllSetting.webPort) port = null;
  296. const isTLS = webCertFile !== "" || webKeyFile !== "";
  297. const url = URLBuilder.buildURL({ host, port, isTLS, base, path: "panel/settings" });
  298. window.location.replace(url);
  299. }
  300. },
  301. toggleTwoFactor(newValue) {
  302. if (newValue) {
  303. const newTwoFactorToken = RandomUtil.randomBase32String()
  304. twoFactorModal.show({
  305. title: '{{ i18n "pages.settings.security.twoFactorModalSetTitle" }}',
  306. token: newTwoFactorToken,
  307. type: 'set',
  308. confirm: (success) => {
  309. if (success) {
  310. Vue.prototype.$message['success']('{{ i18n "pages.settings.security.twoFactorModalSetSuccess" }}')
  311. this.allSetting.twoFactorToken = newTwoFactorToken
  312. }
  313. this.allSetting.twoFactorEnable = success
  314. }
  315. })
  316. } else {
  317. twoFactorModal.show({
  318. title: '{{ i18n "pages.settings.security.twoFactorModalDeleteTitle" }}',
  319. description: '{{ i18n "pages.settings.security.twoFactorModalRemoveStep" }}',
  320. token: this.allSetting.twoFactorToken,
  321. type: 'confirm',
  322. confirm: (success) => {
  323. if (success) {
  324. Vue.prototype.$message['success']('{{ i18n "pages.settings.security.twoFactorModalDeleteSuccess" }}')
  325. this.allSetting.twoFactorEnable = false
  326. this.allSetting.twoFactorToken = ""
  327. }
  328. }
  329. })
  330. }
  331. },
  332. addNoise() {
  333. const newNoise = { type: "rand", packet: "10-20", delay: "10-16", applyTo: "ip" };
  334. this.noisesArray = [...this.noisesArray, newNoise];
  335. },
  336. removeNoise(index) {
  337. const newNoises = [...this.noisesArray];
  338. newNoises.splice(index, 1);
  339. this.noisesArray = newNoises;
  340. },
  341. updateNoiseType(index, value) {
  342. const updatedNoises = [...this.noisesArray];
  343. updatedNoises[index] = { ...updatedNoises[index], type: value };
  344. this.noisesArray = updatedNoises;
  345. },
  346. updateNoisePacket(index, value) {
  347. const updatedNoises = [...this.noisesArray];
  348. updatedNoises[index] = { ...updatedNoises[index], packet: value };
  349. this.noisesArray = updatedNoises;
  350. },
  351. updateNoiseDelay(index, value) {
  352. const updatedNoises = [...this.noisesArray];
  353. updatedNoises[index] = { ...updatedNoises[index], delay: value };
  354. this.noisesArray = updatedNoises;
  355. },
  356. updateNoiseApplyTo(index, value) {
  357. const updatedNoises = [...this.noisesArray];
  358. updatedNoises[index] = { ...updatedNoises[index], applyTo: value };
  359. this.noisesArray = updatedNoises;
  360. },
  361. },
  362. computed: {
  363. fragment: {
  364. get: function () { return this.allSetting?.subJsonFragment != ""; },
  365. set: function (v) {
  366. this.allSetting.subJsonFragment = v ? JSON.stringify(this.defaultFragment) : "";
  367. }
  368. },
  369. fragmentPackets: {
  370. get: function () { return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).settings.fragment.packets : ""; },
  371. set: function (v) {
  372. if (v != "") {
  373. newFragment = JSON.parse(this.allSetting.subJsonFragment);
  374. newFragment.settings.fragment.packets = v;
  375. this.allSetting.subJsonFragment = JSON.stringify(newFragment);
  376. }
  377. }
  378. },
  379. fragmentLength: {
  380. get: function () { return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).settings.fragment.length : ""; },
  381. set: function (v) {
  382. if (v != "") {
  383. newFragment = JSON.parse(this.allSetting.subJsonFragment);
  384. newFragment.settings.fragment.length = v;
  385. this.allSetting.subJsonFragment = JSON.stringify(newFragment);
  386. }
  387. }
  388. },
  389. fragmentInterval: {
  390. get: function () { return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).settings.fragment.interval : ""; },
  391. set: function (v) {
  392. if (v != "") {
  393. newFragment = JSON.parse(this.allSetting.subJsonFragment);
  394. newFragment.settings.fragment.interval = v;
  395. this.allSetting.subJsonFragment = JSON.stringify(newFragment);
  396. }
  397. }
  398. },
  399. noises: {
  400. get() {
  401. return this.allSetting?.subJsonNoises != "";
  402. },
  403. set(v) {
  404. if (v) {
  405. this.allSetting.subJsonNoises = JSON.stringify(this.defaultNoises);
  406. } else {
  407. this.allSetting.subJsonNoises = "";
  408. }
  409. }
  410. },
  411. noisesArray: {
  412. get() {
  413. return this.noises ? JSON.parse(this.allSetting.subJsonNoises).settings.noises : [];
  414. },
  415. set(value) {
  416. if (this.noises) {
  417. const newNoises = JSON.parse(this.allSetting.subJsonNoises);
  418. newNoises.settings.noises = value;
  419. this.allSetting.subJsonNoises = JSON.stringify(newNoises);
  420. }
  421. }
  422. },
  423. enableMux: {
  424. get: function () { return this.allSetting?.subJsonMux != ""; },
  425. set: function (v) {
  426. this.allSetting.subJsonMux = v ? JSON.stringify(this.defaultMux) : "";
  427. }
  428. },
  429. muxConcurrency: {
  430. get: function () { return this.enableMux ? JSON.parse(this.allSetting.subJsonMux).concurrency : -1; },
  431. set: function (v) {
  432. newMux = JSON.parse(this.allSetting.subJsonMux);
  433. newMux.concurrency = v;
  434. this.allSetting.subJsonMux = JSON.stringify(newMux);
  435. }
  436. },
  437. muxXudpConcurrency: {
  438. get: function () { return this.enableMux ? JSON.parse(this.allSetting.subJsonMux).xudpConcurrency : -1; },
  439. set: function (v) {
  440. newMux = JSON.parse(this.allSetting.subJsonMux);
  441. newMux.xudpConcurrency = v;
  442. this.allSetting.subJsonMux = JSON.stringify(newMux);
  443. }
  444. },
  445. muxXudpProxyUDP443: {
  446. get: function () { return this.enableMux ? JSON.parse(this.allSetting.subJsonMux).xudpProxyUDP443 : "reject"; },
  447. set: function (v) {
  448. newMux = JSON.parse(this.allSetting.subJsonMux);
  449. newMux.xudpProxyUDP443 = v;
  450. this.allSetting.subJsonMux = JSON.stringify(newMux);
  451. }
  452. },
  453. enableDirect: {
  454. get: function () { return this.allSetting?.subJsonRules != ""; },
  455. set: function (v) {
  456. this.allSetting.subJsonRules = v ? JSON.stringify(this.defaultRules) : "";
  457. }
  458. },
  459. directIPs: {
  460. get: function () {
  461. if (!this.enableDirect) return [];
  462. const rules = JSON.parse(this.allSetting.subJsonRules);
  463. if (!Array.isArray(rules)) return [];
  464. const ipRule = rules.find(r => r.ip);
  465. return ipRule?.ip ?? [];
  466. },
  467. set: function (v) {
  468. let rules = JSON.parse(this.allSetting.subJsonRules);
  469. if (!Array.isArray(rules)) return;
  470. if (v.length == 0) {
  471. rules = rules.filter(r => !r.ip);
  472. } else {
  473. let ruleIndex = rules.findIndex(r => r.ip);
  474. if (ruleIndex == -1) ruleIndex = rules.push(this.defaultRules[1]) - 1;
  475. rules[ruleIndex].ip = [];
  476. v.forEach(d => {
  477. rules[ruleIndex].ip.push(d);
  478. });
  479. }
  480. this.allSetting.subJsonRules = JSON.stringify(rules);
  481. }
  482. },
  483. directDomains: {
  484. get: function () {
  485. if (!this.enableDirect) return [];
  486. const rules = JSON.parse(this.allSetting.subJsonRules);
  487. if (!Array.isArray(rules)) return [];
  488. const domainRule = rules.find(r => r.domain);
  489. return domainRule?.domain ?? [];
  490. },
  491. set: function (v) {
  492. let rules = JSON.parse(this.allSetting.subJsonRules);
  493. if (!Array.isArray(rules)) return;
  494. if (v.length == 0) {
  495. rules = rules.filter(r => !r.domain);
  496. } else {
  497. let ruleIndex = rules.findIndex(r => r.domain);
  498. if (ruleIndex == -1) ruleIndex = rules.push(this.defaultRules[0]) - 1;
  499. rules[ruleIndex].domain = v;
  500. }
  501. this.allSetting.subJsonRules = JSON.stringify(rules);
  502. }
  503. },
  504. confAlerts: {
  505. get: function () {
  506. if (!this.allSetting) return [];
  507. var alerts = []
  508. if (window.location.protocol !== "https:") alerts.push('{{ i18n "secAlertSSL" }}');
  509. if (this.allSetting.webPort === 2053) alerts.push('{{ i18n "secAlertPanelPort" }}');
  510. panelPath = window.location.pathname.split('/').length < 4
  511. if (panelPath && this.allSetting.webBasePath == '/') alerts.push('{{ i18n "secAlertPanelURI" }}');
  512. if (this.allSetting.subEnable) {
  513. subPath = this.allSetting.subURI.length > 0 ? new URL(this.allSetting.subURI).pathname : this.allSetting.subPath;
  514. if (subPath == '/sub/') alerts.push('{{ i18n "secAlertSubURI" }}');
  515. subJsonPath = this.allSetting.subJsonURI.length > 0 ? new URL(this.allSetting.subJsonURI).pathname : this.allSetting.subJsonPath;
  516. if (subJsonPath == '/json/') alerts.push('{{ i18n "secAlertSubJsonURI" }}');
  517. }
  518. return alerts
  519. }
  520. }
  521. },
  522. async mounted() {
  523. await this.getAllSetting();
  524. while (true) {
  525. await PromiseUtil.sleep(1000);
  526. this.saveBtnDisable = this.oldAllSetting.equals(this.allSetting);
  527. }
  528. }
  529. });
  530. </script>
  531. {{ template "page/body_end" .}}