settings.html 20 KB

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