settings.html 24 KB

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