settings.html 19 KB

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