settings.html 24 KB

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