1
0

settings.html 19 KB

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