settings.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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/js/model/setting.js?{{ .cur_ver }}"></script>
  124. {{template "component/aSidebar" .}}
  125. {{template "component/aThemeSwitch" .}}
  126. {{template "component/aSettingListItem" .}}
  127. <script>
  128. const app = new Vue({
  129. delimiters: ['[[', ']]'],
  130. el: '#app',
  131. data: {
  132. themeSwitcher,
  133. spinning: false,
  134. changeSecret: false,
  135. oldAllSetting: new AllSetting(),
  136. allSetting: new AllSetting(),
  137. saveBtnDisable: true,
  138. user: {},
  139. lang: LanguageManager.getLanguage(),
  140. remarkModels: { i: 'Inbound', e: 'Email', o: 'Other' },
  141. remarkSeparators: [' ', '-', '_', '@', ':', '~', '|', ',', '.', '/'],
  142. datepickerList: [{ name: 'Gregorian (Standard)', value: 'gregorian' }, { name: 'Jalalian (شمسی)', value: 'jalalian' }],
  143. remarkSample: '',
  144. defaultFragment: {
  145. tag: "fragment",
  146. protocol: "freedom",
  147. settings: {
  148. domainStrategy: "AsIs",
  149. fragment: {
  150. packets: "tlshello",
  151. length: "100-200",
  152. interval: "10-20"
  153. }
  154. },
  155. streamSettings: {
  156. sockopt: {
  157. tcpKeepAliveIdle: 100,
  158. tcpMptcp: true,
  159. penetrate: true
  160. }
  161. }
  162. },
  163. defaultNoises: {
  164. tag: "noises",
  165. protocol: "freedom",
  166. settings: {
  167. domainStrategy: "AsIs",
  168. noises: [
  169. { type: "rand", packet: "10-20", delay: "10-16" },
  170. ],
  171. },
  172. },
  173. defaultMux: {
  174. enabled: true,
  175. concurrency: 8,
  176. xudpConcurrency: 16,
  177. xudpProxyUDP443: "reject"
  178. },
  179. defaultRules: [
  180. {
  181. type: "field",
  182. outboundTag: "direct",
  183. domain: [
  184. "geosite:category-ir"
  185. ]
  186. },
  187. {
  188. type: "field",
  189. outboundTag: "direct",
  190. ip: [
  191. "geoip:private",
  192. "geoip:ir"
  193. ]
  194. },
  195. ],
  196. directIPsOptions: [
  197. { label: 'Private IP', value: 'geoip:private' },
  198. { label: '🇮🇷 Iran', value: 'geoip:ir' },
  199. { label: '🇨🇳 China', value: 'geoip:cn' },
  200. { label: '🇷🇺 Russia', value: 'geoip:ru' },
  201. { label: '🇻🇳 Vietnam', value: 'geoip:vn' },
  202. { label: '🇪🇸 Spain', value: 'geoip:es' },
  203. { label: '🇮🇩 Indonesia', value: 'geoip:id' },
  204. { label: '🇺🇦 Ukraine', value: 'geoip:ua' },
  205. { label: '🇹🇷 Türkiye', value: 'geoip:tr' },
  206. { label: '🇧🇷 Brazil', value: 'geoip:br' },
  207. ],
  208. diretDomainsOptions: [
  209. { label: 'Private DNS', value: 'geosite:private' },
  210. { label: '🇮🇷 Iran', value: 'geosite:category-ir' },
  211. { label: '🇨🇳 China', value: 'geosite:cn' },
  212. { label: '🇷🇺 Russia', value: 'geosite:category-ru' },
  213. { label: 'Apple', value: 'geosite:apple' },
  214. { label: 'Meta', value: 'geosite:meta' },
  215. { label: 'Google', value: 'geosite:google' },
  216. ],
  217. get remarkModel() {
  218. rm = this.allSetting.remarkModel;
  219. return rm.length > 1 ? rm.substring(1).split('') : [];
  220. },
  221. set remarkModel(value) {
  222. rs = this.allSetting.remarkModel[0];
  223. this.allSetting.remarkModel = rs + value.join('');
  224. this.changeRemarkSample();
  225. },
  226. get remarkSeparator() {
  227. return this.allSetting.remarkModel.length > 1 ? this.allSetting.remarkModel.charAt(0) : '-';
  228. },
  229. set remarkSeparator(value) {
  230. this.allSetting.remarkModel = value + this.allSetting.remarkModel.substring(1);
  231. this.changeRemarkSample();
  232. },
  233. get datepicker() {
  234. return this.allSetting.datepicker ? this.allSetting.datepicker : 'gregorian';
  235. },
  236. set datepicker(value) {
  237. this.allSetting.datepicker = value;
  238. },
  239. changeRemarkSample() {
  240. sample = []
  241. this.remarkModel.forEach(r => sample.push(this.remarkModels[r]));
  242. this.remarkSample = sample.length == 0 ? '' : sample.join(this.remarkSeparator);
  243. }
  244. },
  245. methods: {
  246. loading(spinning = true) {
  247. this.spinning = spinning;
  248. },
  249. async getAllSetting() {
  250. this.loading(true);
  251. const msg = await HttpUtil.post("/panel/setting/all");
  252. this.loading(false);
  253. if (msg.success) {
  254. this.oldAllSetting = new AllSetting(msg.obj);
  255. this.allSetting = new AllSetting(msg.obj);
  256. app.changeRemarkSample();
  257. this.saveBtnDisable = true;
  258. }
  259. await this.fetchUserSecret();
  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. async fetchUserSecret() {
  304. this.loading(true);
  305. const userMessage = await HttpUtil.post("/panel/setting/getUserSecret", this.user);
  306. if (userMessage.success) {
  307. this.user = userMessage.obj;
  308. }
  309. this.loading(false);
  310. },
  311. async updateSecret() {
  312. this.loading(true);
  313. const msg = await HttpUtil.post("/panel/setting/updateUserSecret", this.user);
  314. if (msg && msg.obj) {
  315. this.user = msg.obj;
  316. }
  317. this.loading(false);
  318. await this.updateAllSetting();
  319. },
  320. generateRandomString(length) {
  321. var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  322. let randomString = "";
  323. for (let i = 0; i < length; i++) {
  324. randomString += chars[Math.floor(Math.random() * chars.length)];
  325. }
  326. return randomString;
  327. },
  328. async getNewSecret() {
  329. if (!this.changeSecret) {
  330. this.changeSecret = true;
  331. this.user.loginSecret = '';
  332. const newSecret = this.generateRandomString(64);
  333. await PromiseUtil.sleep(1000);
  334. this.user.loginSecret = newSecret;
  335. this.changeSecret = false;
  336. }
  337. },
  338. async toggleToken(value) {
  339. if (value) {
  340. await this.getNewSecret();
  341. } else {
  342. this.user.loginSecret = "";
  343. }
  344. },
  345. addNoise() {
  346. const newNoise = { type: "rand", packet: "10-20", delay: "10-16" };
  347. this.noisesArray = [...this.noisesArray, newNoise];
  348. },
  349. removeNoise(index) {
  350. const newNoises = [...this.noisesArray];
  351. newNoises.splice(index, 1);
  352. this.noisesArray = newNoises;
  353. },
  354. updateNoiseType(index, value) {
  355. const updatedNoises = [...this.noisesArray];
  356. updatedNoises[index] = { ...updatedNoises[index], type: value };
  357. this.noisesArray = updatedNoises;
  358. },
  359. updateNoisePacket(index, value) {
  360. const updatedNoises = [...this.noisesArray];
  361. updatedNoises[index] = { ...updatedNoises[index], packet: value };
  362. this.noisesArray = updatedNoises;
  363. },
  364. updateNoiseDelay(index, value) {
  365. const updatedNoises = [...this.noisesArray];
  366. updatedNoises[index] = { ...updatedNoises[index], delay: value };
  367. this.noisesArray = updatedNoises;
  368. },
  369. },
  370. computed: {
  371. fragment: {
  372. get: function () { return this.allSetting?.subJsonFragment != ""; },
  373. set: function (v) {
  374. this.allSetting.subJsonFragment = v ? JSON.stringify(this.defaultFragment) : "";
  375. }
  376. },
  377. fragmentPackets: {
  378. get: function () { return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).settings.fragment.packets : ""; },
  379. set: function (v) {
  380. if (v != "") {
  381. newFragment = JSON.parse(this.allSetting.subJsonFragment);
  382. newFragment.settings.fragment.packets = v;
  383. this.allSetting.subJsonFragment = JSON.stringify(newFragment);
  384. }
  385. }
  386. },
  387. fragmentLength: {
  388. get: function () { return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).settings.fragment.length : ""; },
  389. set: function (v) {
  390. if (v != "") {
  391. newFragment = JSON.parse(this.allSetting.subJsonFragment);
  392. newFragment.settings.fragment.length = v;
  393. this.allSetting.subJsonFragment = JSON.stringify(newFragment);
  394. }
  395. }
  396. },
  397. fragmentInterval: {
  398. get: function () { return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).settings.fragment.interval : ""; },
  399. set: function (v) {
  400. if (v != "") {
  401. newFragment = JSON.parse(this.allSetting.subJsonFragment);
  402. newFragment.settings.fragment.interval = v;
  403. this.allSetting.subJsonFragment = JSON.stringify(newFragment);
  404. }
  405. }
  406. },
  407. noises: {
  408. get() {
  409. return this.allSetting?.subJsonNoises != "";
  410. },
  411. set(v) {
  412. if (v) {
  413. this.allSetting.subJsonNoises = JSON.stringify(this.defaultNoises);
  414. } else {
  415. this.allSetting.subJsonNoises = "";
  416. }
  417. }
  418. },
  419. noisesArray: {
  420. get() {
  421. return this.noises ? JSON.parse(this.allSetting.subJsonNoises).settings.noises : [];
  422. },
  423. set(value) {
  424. if (this.noises) {
  425. const newNoises = JSON.parse(this.allSetting.subJsonNoises);
  426. newNoises.settings.noises = value;
  427. this.allSetting.subJsonNoises = JSON.stringify(newNoises);
  428. }
  429. }
  430. },
  431. enableMux: {
  432. get: function () { return this.allSetting?.subJsonMux != ""; },
  433. set: function (v) {
  434. this.allSetting.subJsonMux = v ? JSON.stringify(this.defaultMux) : "";
  435. }
  436. },
  437. muxConcurrency: {
  438. get: function () { return this.enableMux ? JSON.parse(this.allSetting.subJsonMux).concurrency : -1; },
  439. set: function (v) {
  440. newMux = JSON.parse(this.allSetting.subJsonMux);
  441. newMux.concurrency = v;
  442. this.allSetting.subJsonMux = JSON.stringify(newMux);
  443. }
  444. },
  445. muxXudpConcurrency: {
  446. get: function () { return this.enableMux ? JSON.parse(this.allSetting.subJsonMux).xudpConcurrency : -1; },
  447. set: function (v) {
  448. newMux = JSON.parse(this.allSetting.subJsonMux);
  449. newMux.xudpConcurrency = v;
  450. this.allSetting.subJsonMux = JSON.stringify(newMux);
  451. }
  452. },
  453. muxXudpProxyUDP443: {
  454. get: function () { return this.enableMux ? JSON.parse(this.allSetting.subJsonMux).xudpProxyUDP443 : "reject"; },
  455. set: function (v) {
  456. newMux = JSON.parse(this.allSetting.subJsonMux);
  457. newMux.xudpProxyUDP443 = v;
  458. this.allSetting.subJsonMux = JSON.stringify(newMux);
  459. }
  460. },
  461. enableDirect: {
  462. get: function () { return this.allSetting?.subJsonRules != ""; },
  463. set: function (v) {
  464. this.allSetting.subJsonRules = v ? JSON.stringify(this.defaultRules) : "";
  465. }
  466. },
  467. directIPs: {
  468. get: function () {
  469. if (!this.enableDirect) return [];
  470. const rules = JSON.parse(this.allSetting.subJsonRules);
  471. if (!Array.isArray(rules)) return [];
  472. const ipRule = rules.find(r => r.ip);
  473. return ipRule?.ip ?? [];
  474. },
  475. set: function (v) {
  476. let rules = JSON.parse(this.allSetting.subJsonRules);
  477. if (!Array.isArray(rules)) return;
  478. if (v.length == 0) {
  479. rules = rules.filter(r => !r.ip);
  480. } else {
  481. let ruleIndex = rules.findIndex(r => r.ip);
  482. if (ruleIndex == -1) ruleIndex = rules.push(this.defaultRules[1]) - 1;
  483. rules[ruleIndex].ip = [];
  484. v.forEach(d => {
  485. rules[ruleIndex].ip.push(d);
  486. });
  487. }
  488. this.allSetting.subJsonRules = JSON.stringify(rules);
  489. }
  490. },
  491. directDomains: {
  492. get: function () {
  493. if (!this.enableDirect) return [];
  494. const rules = JSON.parse(this.allSetting.subJsonRules);
  495. if (!Array.isArray(rules)) return [];
  496. const domainRule = rules.find(r => r.domain);
  497. return domainRule?.domain ?? [];
  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.domain);
  504. } else {
  505. let ruleIndex = rules.findIndex(r => r.domain);
  506. if (ruleIndex == -1) ruleIndex = rules.push(this.defaultRules[0]) - 1;
  507. rules[ruleIndex].domain = v;
  508. }
  509. this.allSetting.subJsonRules = JSON.stringify(rules);
  510. }
  511. },
  512. confAlerts: {
  513. get: function () {
  514. if (!this.allSetting) return [];
  515. var alerts = []
  516. if (window.location.protocol !== "https:") alerts.push('{{ i18n "secAlertSSL" }}');
  517. if (this.allSetting.webPort == 54321) alerts.push('{{ i18n "secAlertPanelPort" }}');
  518. panelPath = window.location.pathname.split('/').length < 4
  519. if (panelPath && this.allSetting.webBasePath == '/') alerts.push('{{ i18n "secAlertPanelURI" }}');
  520. if (this.allSetting.subEnable) {
  521. subPath = this.allSetting.subURI.length > 0 ? new URL(this.allSetting.subURI).pathname : this.allSetting.subPath;
  522. if (subPath == '/sub/') alerts.push('{{ i18n "secAlertSubURI" }}');
  523. subJsonPath = this.allSetting.subJsonURI.length > 0 ? new URL(this.allSetting.subJsonURI).pathname : this.allSetting.subJsonPath;
  524. if (subJsonPath == '/json/') alerts.push('{{ i18n "secAlertSubJsonURI" }}');
  525. }
  526. return alerts
  527. }
  528. }
  529. },
  530. async mounted() {
  531. await this.getAllSetting();
  532. while (true) {
  533. await PromiseUtil.sleep(1000);
  534. this.saveBtnDisable = this.oldAllSetting.equals(this.allSetting);
  535. }
  536. }
  537. });
  538. </script>
  539. </body>
  540. </html>