settings.html 19 KB

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