settings.html 21 KB

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