settings.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  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"
  82. :style="{ paddingTop: '20px' }">
  83. <template #tab>
  84. <a-icon type="code"></a-icon>
  85. <span>{{ i18n "pages.settings.subSettings" }} (Formats)</span>
  86. </template>
  87. {{ template "settings/panel/subscription/json" . }}
  88. </a-tab-pane>
  89. </a-tabs>
  90. </a-col>
  91. </a-row>
  92. </template>
  93. </transition>
  94. </a-spin>
  95. </a-layout-content>
  96. </a-layout>
  97. </a-layout>
  98. {{template "page/body_scripts" .}}
  99. <script src="{{ .base_path }}assets/qrcode/qrious2.min.js?{{ .cur_ver }}"></script>
  100. <script src="{{ .base_path }}assets/otpauth/otpauth.umd.min.js?{{ .cur_ver }}"></script>
  101. <script src="{{ .base_path }}assets/js/model/setting.js?{{ .cur_ver }}"></script>
  102. {{template "component/aSidebar" .}}
  103. {{template "component/aThemeSwitch" .}}
  104. {{template "component/aSettingListItem" .}}
  105. {{template "modals/twoFactorModal"}}
  106. <script>
  107. const app = new Vue({
  108. delimiters: ['[[', ']]'],
  109. mixins: [MediaQueryMixin],
  110. el: '#app',
  111. data: {
  112. themeSwitcher,
  113. loadingStates: {
  114. fetched: false,
  115. spinning: false
  116. },
  117. oldAllSetting: new AllSetting(),
  118. allSetting: new AllSetting(),
  119. saveBtnDisable: true,
  120. entryHost: null,
  121. entryPort: null,
  122. entryProtocol: null,
  123. entryIsIP: false,
  124. user: {},
  125. lang: LanguageManager.getLanguage(),
  126. inboundOptions: [],
  127. remarkModels: {
  128. i: 'Inbound',
  129. e: 'Email',
  130. o: 'Other'
  131. },
  132. remarkSeparators: [' ', '-', '_', '@', ':', '~', '|', ',', '.', '/'],
  133. datepickerList: [{
  134. name: 'Gregorian (Standard)',
  135. value: 'gregorian'
  136. }, {
  137. name: 'Jalalian (شمسی)',
  138. value: 'jalalian'
  139. }],
  140. remarkSample: '',
  141. defaultFragment: {
  142. packets: "tlshello",
  143. length: "100-200",
  144. interval: "10-20",
  145. maxSplit: "300-400"
  146. },
  147. defaultNoises: [{
  148. type: "rand",
  149. packet: "10-20",
  150. delay: "10-16",
  151. applyTo: "ip"
  152. }],
  153. defaultMux: {
  154. enabled: true,
  155. concurrency: 8,
  156. xudpConcurrency: 16,
  157. xudpProxyUDP443: "reject"
  158. },
  159. defaultRules: [{
  160. type: "field",
  161. outboundTag: "direct",
  162. domain: [
  163. "geosite:category-ir"
  164. ]
  165. },
  166. {
  167. type: "field",
  168. outboundTag: "direct",
  169. ip: [
  170. "geoip:private",
  171. "geoip:ir"
  172. ]
  173. },
  174. ],
  175. directIPsOptions: [{
  176. label: 'Private IP',
  177. value: 'geoip:private'
  178. },
  179. {
  180. label: '🇮🇷 Iran',
  181. value: 'geoip:ir'
  182. },
  183. {
  184. label: '🇨🇳 China',
  185. value: 'geoip:cn'
  186. },
  187. {
  188. label: '🇷🇺 Russia',
  189. value: 'geoip:ru'
  190. },
  191. {
  192. label: '🇻🇳 Vietnam',
  193. value: 'geoip:vn'
  194. },
  195. {
  196. label: '🇪🇸 Spain',
  197. value: 'geoip:es'
  198. },
  199. {
  200. label: '🇮🇩 Indonesia',
  201. value: 'geoip:id'
  202. },
  203. {
  204. label: '🇺🇦 Ukraine',
  205. value: 'geoip:ua'
  206. },
  207. {
  208. label: '🇹🇷 Türkiye',
  209. value: 'geoip:tr'
  210. },
  211. {
  212. label: '🇧🇷 Brazil',
  213. value: 'geoip:br'
  214. },
  215. ],
  216. diretDomainsOptions: [{
  217. label: 'Private DNS',
  218. value: 'geosite:private'
  219. },
  220. {
  221. label: '🇮🇷 Iran',
  222. value: 'geosite:category-ir'
  223. },
  224. {
  225. label: '🇨🇳 China',
  226. value: 'geosite:cn'
  227. },
  228. {
  229. label: '🇷🇺 Russia',
  230. value: 'geosite:category-ru'
  231. },
  232. {
  233. label: 'Apple',
  234. value: 'geosite:apple'
  235. },
  236. {
  237. label: 'Meta',
  238. value: 'geosite:meta'
  239. },
  240. {
  241. label: 'Google',
  242. value: 'geosite:google'
  243. },
  244. ],
  245. get remarkModel() {
  246. rm = this.allSetting.remarkModel;
  247. return rm.length > 1 ? rm.substring(1).split('') : [];
  248. },
  249. set remarkModel(value) {
  250. rs = this.allSetting.remarkModel[0];
  251. this.allSetting.remarkModel = rs + value.join('');
  252. this.changeRemarkSample();
  253. },
  254. get remarkSeparator() {
  255. return this.allSetting.remarkModel.length > 1 ? this.allSetting.remarkModel.charAt(0) : '-';
  256. },
  257. set remarkSeparator(value) {
  258. this.allSetting.remarkModel = value + this.allSetting.remarkModel.substring(1);
  259. this.changeRemarkSample();
  260. },
  261. get datepicker() {
  262. return this.allSetting.datepicker ? this.allSetting.datepicker : 'gregorian';
  263. },
  264. set datepicker(value) {
  265. this.allSetting.datepicker = value;
  266. },
  267. changeRemarkSample() {
  268. sample = []
  269. this.remarkModel.forEach(r => sample.push(this.remarkModels[r]));
  270. this.remarkSample = sample.length == 0 ? '' : sample.join(this.remarkSeparator);
  271. }
  272. },
  273. methods: {
  274. loading(spinning = true) {
  275. this.loadingStates.spinning = spinning;
  276. },
  277. _isIp(h) {
  278. if (typeof h !== "string") return false;
  279. // IPv4: four dot-separated octets 0-255
  280. const v4 = h.split(".");
  281. if (
  282. v4.length === 4 &&
  283. v4.every(p => /^\d{1,3}$/.test(p) && Number(p) <= 255)
  284. ) return true;
  285. // IPv6: hex groups, optional single :: compression
  286. if (!h.includes(":") || h.includes(":::")) return false;
  287. const parts = h.split("::");
  288. if (parts.length > 2) return false;
  289. const splitGroups = s => (s ? s.split(":").filter(Boolean) : []);
  290. const head = splitGroups(parts[0]);
  291. const tail = splitGroups(parts[1]);
  292. const validGroup = seg => /^[0-9a-fA-F]{1,4}$/.test(seg);
  293. if (![...head, ...tail].every(validGroup)) return false;
  294. const groups = head.length + tail.length;
  295. return parts.length === 2 ? groups < 8 : groups === 8;
  296. },
  297. async getAllSetting() {
  298. const msg = await HttpUtil.post("/panel/setting/all");
  299. if (msg.success) {
  300. if (!this.loadingStates.fetched) {
  301. this.loadingStates.fetched = true
  302. }
  303. this.oldAllSetting = new AllSetting(msg.obj);
  304. this.allSetting = new AllSetting(msg.obj);
  305. app.changeRemarkSample();
  306. this.saveBtnDisable = true;
  307. }
  308. },
  309. async loadInboundTags() {
  310. const msg = await HttpUtil.get("/panel/api/inbounds/list");
  311. if (msg && msg.success && Array.isArray(msg.obj)) {
  312. this.inboundOptions = msg.obj.map(ib => ({
  313. label: `${ib.tag} (${ib.protocol}@${ib.port})`,
  314. value: ib.tag,
  315. }));
  316. } else {
  317. this.inboundOptions = [];
  318. }
  319. },
  320. async updateAllSetting() {
  321. this.loading(true);
  322. const msg = await HttpUtil.post("/panel/setting/update", this.allSetting);
  323. this.loading(false);
  324. if (msg.success) {
  325. await this.getAllSetting();
  326. }
  327. },
  328. async updateUser() {
  329. const sendUpdateUserRequest = async () => {
  330. this.loading(true);
  331. const msg = await HttpUtil.post("/panel/setting/updateUser", this.user);
  332. this.loading(false);
  333. if (msg.success) {
  334. this.user = {};
  335. window.location.replace(basePath + "logout");
  336. }
  337. }
  338. if (this.allSetting.twoFactorEnable) {
  339. twoFactorModal.show({
  340. title: '{{ i18n "pages.settings.security.twoFactorModalChangeCredentialsTitle" }}',
  341. description: '{{ i18n "pages.settings.security.twoFactorModalChangeCredentialsStep" }}',
  342. token: this.allSetting.twoFactorToken,
  343. type: 'confirm',
  344. confirm: (success) => {
  345. if (success) {
  346. sendUpdateUserRequest();
  347. }
  348. }
  349. })
  350. } else {
  351. sendUpdateUserRequest();
  352. }
  353. },
  354. async restartPanel() {
  355. await new Promise(resolve => {
  356. this.$confirm({
  357. title: '{{ i18n "pages.settings.restartPanel" }}',
  358. content: '{{ i18n "pages.settings.restartPanelDesc" }}',
  359. class: themeSwitcher.currentTheme,
  360. okText: '{{ i18n "sure" }}',
  361. cancelText: '{{ i18n "cancel" }}',
  362. onOk: () => resolve(),
  363. });
  364. });
  365. this.loading(true);
  366. const msg = await HttpUtil.post("/panel/setting/restartPanel");
  367. this.loading(false);
  368. if (!msg.success) return;
  369. this.loading(true);
  370. await PromiseUtil.sleep(5000);
  371. const {
  372. webDomain,
  373. webPort,
  374. webBasePath,
  375. webCertFile,
  376. webKeyFile
  377. } = this.allSetting;
  378. const newProtocol = (webCertFile || webKeyFile) ? "https:" : "http:";
  379. let base = webBasePath ? webBasePath.replace(/^\//, "") : "";
  380. if (base && !base.endsWith("/")) base += "/";
  381. if (!this.entryIsIP) {
  382. const url = new URL(window.location.href);
  383. url.pathname = `/${base}panel/settings`;
  384. url.protocol = newProtocol;
  385. window.location.replace(url.toString());
  386. return;
  387. }
  388. let finalHost = this.entryHost;
  389. let finalPort = this.entryPort || "";
  390. if (webDomain && this._isIp(webDomain)) {
  391. finalHost = webDomain;
  392. }
  393. if (webPort && Number(webPort) !== Number(this.entryPort)) {
  394. finalPort = String(webPort);
  395. }
  396. const url = new URL(`${newProtocol}//${finalHost}`);
  397. if (finalPort) url.port = finalPort;
  398. url.pathname = `/${base}panel/settings`;
  399. window.location.replace(url.toString());
  400. },
  401. toggleTwoFactor(newValue) {
  402. if (newValue) {
  403. const newTwoFactorToken = RandomUtil.randomBase32String()
  404. twoFactorModal.show({
  405. title: '{{ i18n "pages.settings.security.twoFactorModalSetTitle" }}',
  406. token: newTwoFactorToken,
  407. type: 'set',
  408. confirm: (success) => {
  409. if (success) {
  410. Vue.prototype.$message['success'](
  411. '{{ i18n "pages.settings.security.twoFactorModalSetSuccess" }}')
  412. this.allSetting.twoFactorToken = newTwoFactorToken
  413. }
  414. this.allSetting.twoFactorEnable = success
  415. }
  416. })
  417. } else {
  418. twoFactorModal.show({
  419. title: '{{ i18n "pages.settings.security.twoFactorModalDeleteTitle" }}',
  420. description: '{{ i18n "pages.settings.security.twoFactorModalRemoveStep" }}',
  421. token: this.allSetting.twoFactorToken,
  422. type: 'confirm',
  423. confirm: (success) => {
  424. if (success) {
  425. Vue.prototype.$message['success'](
  426. '{{ i18n "pages.settings.security.twoFactorModalDeleteSuccess" }}')
  427. this.allSetting.twoFactorEnable = false
  428. this.allSetting.twoFactorToken = ""
  429. }
  430. }
  431. })
  432. }
  433. },
  434. addNoise() {
  435. const newNoise = {
  436. type: "rand",
  437. packet: "10-20",
  438. delay: "10-16",
  439. applyTo: "ip"
  440. };
  441. this.noisesArray = [...this.noisesArray, newNoise];
  442. },
  443. removeNoise(index) {
  444. const newNoises = [...this.noisesArray];
  445. newNoises.splice(index, 1);
  446. this.noisesArray = newNoises;
  447. },
  448. updateNoiseType(index, value) {
  449. const updatedNoises = [...this.noisesArray];
  450. updatedNoises[index] = {
  451. ...updatedNoises[index],
  452. type: value
  453. };
  454. this.noisesArray = updatedNoises;
  455. },
  456. updateNoisePacket(index, value) {
  457. const updatedNoises = [...this.noisesArray];
  458. updatedNoises[index] = {
  459. ...updatedNoises[index],
  460. packet: value
  461. };
  462. this.noisesArray = updatedNoises;
  463. },
  464. updateNoiseDelay(index, value) {
  465. const updatedNoises = [...this.noisesArray];
  466. updatedNoises[index] = {
  467. ...updatedNoises[index],
  468. delay: value
  469. };
  470. this.noisesArray = updatedNoises;
  471. },
  472. updateNoiseApplyTo(index, value) {
  473. const updatedNoises = [...this.noisesArray];
  474. updatedNoises[index] = {
  475. ...updatedNoises[index],
  476. applyTo: value
  477. };
  478. this.noisesArray = updatedNoises;
  479. },
  480. },
  481. computed: {
  482. ldapInboundTagList: {
  483. get: function() {
  484. const csv = this.allSetting.ldapInboundTags || "";
  485. return csv.length ? csv.split(',').map(s => s.trim()).filter(Boolean) : [];
  486. },
  487. set: function(list) {
  488. this.allSetting.ldapInboundTags = Array.isArray(list) ? list.join(',') : '';
  489. }
  490. },
  491. fragment: {
  492. get: function() {
  493. return this.allSetting?.subJsonFragment != "";
  494. },
  495. set: function(v) {
  496. this.allSetting.subJsonFragment = v ? JSON.stringify(this.defaultFragment) : "";
  497. }
  498. },
  499. fragmentPackets: {
  500. get: function() {
  501. return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).packets : "";
  502. },
  503. set: function(v) {
  504. if (v != "") {
  505. newFragment = JSON.parse(this.allSetting.subJsonFragment);
  506. newFragment.packets = v;
  507. this.allSetting.subJsonFragment = JSON.stringify(newFragment);
  508. }
  509. }
  510. },
  511. fragmentLength: {
  512. get: function() {
  513. return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).length : "";
  514. },
  515. set: function(v) {
  516. if (v != "") {
  517. newFragment = JSON.parse(this.allSetting.subJsonFragment);
  518. newFragment.length = v;
  519. this.allSetting.subJsonFragment = JSON.stringify(newFragment);
  520. }
  521. }
  522. },
  523. fragmentInterval: {
  524. get: function() {
  525. return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).interval : "";
  526. },
  527. set: function(v) {
  528. if (v != "") {
  529. newFragment = JSON.parse(this.allSetting.subJsonFragment);
  530. newFragment.interval = v;
  531. this.allSetting.subJsonFragment = JSON.stringify(newFragment);
  532. }
  533. }
  534. },
  535. fragmentMaxSplit: {
  536. get: function() {
  537. return this.fragment ? JSON.parse(this.allSetting.subJsonFragment).maxSplit : "";
  538. },
  539. set: function(v) {
  540. if (v != "") {
  541. newFragment = JSON.parse(this.allSetting.subJsonFragment);
  542. newFragment.maxSplit = v;
  543. this.allSetting.subJsonFragment = JSON.stringify(newFragment);
  544. }
  545. }
  546. },
  547. noises: {
  548. get() {
  549. return this.allSetting?.subJsonNoises != "";
  550. },
  551. set(v) {
  552. if (v) {
  553. this.allSetting.subJsonNoises = JSON.stringify(this.defaultNoises);
  554. } else {
  555. this.allSetting.subJsonNoises = "";
  556. }
  557. }
  558. },
  559. noisesArray: {
  560. get() {
  561. return this.noises ? JSON.parse(this.allSetting.subJsonNoises) : [];
  562. },
  563. set(value) {
  564. if (this.noises) {
  565. this.allSetting.subJsonNoises = JSON.stringify(value);
  566. }
  567. }
  568. },
  569. enableMux: {
  570. get: function() {
  571. return this.allSetting?.subJsonMux != "";
  572. },
  573. set: function(v) {
  574. this.allSetting.subJsonMux = v ? JSON.stringify(this.defaultMux) : "";
  575. }
  576. },
  577. muxConcurrency: {
  578. get: function() {
  579. return this.enableMux ? JSON.parse(this.allSetting.subJsonMux).concurrency : -1;
  580. },
  581. set: function(v) {
  582. newMux = JSON.parse(this.allSetting.subJsonMux);
  583. newMux.concurrency = v;
  584. this.allSetting.subJsonMux = JSON.stringify(newMux);
  585. }
  586. },
  587. muxXudpConcurrency: {
  588. get: function() {
  589. return this.enableMux ? JSON.parse(this.allSetting.subJsonMux).xudpConcurrency : -1;
  590. },
  591. set: function(v) {
  592. newMux = JSON.parse(this.allSetting.subJsonMux);
  593. newMux.xudpConcurrency = v;
  594. this.allSetting.subJsonMux = JSON.stringify(newMux);
  595. }
  596. },
  597. muxXudpProxyUDP443: {
  598. get: function() {
  599. return this.enableMux ? JSON.parse(this.allSetting.subJsonMux).xudpProxyUDP443 : "reject";
  600. },
  601. set: function(v) {
  602. newMux = JSON.parse(this.allSetting.subJsonMux);
  603. newMux.xudpProxyUDP443 = v;
  604. this.allSetting.subJsonMux = JSON.stringify(newMux);
  605. }
  606. },
  607. enableDirect: {
  608. get: function() {
  609. return this.allSetting?.subJsonRules != "";
  610. },
  611. set: function(v) {
  612. this.allSetting.subJsonRules = v ? JSON.stringify(this.defaultRules) : "";
  613. }
  614. },
  615. directIPs: {
  616. get: function() {
  617. if (!this.enableDirect) return [];
  618. const rules = JSON.parse(this.allSetting.subJsonRules);
  619. if (!Array.isArray(rules)) return [];
  620. const ipRule = rules.find(r => r.ip);
  621. return ipRule?.ip ?? [];
  622. },
  623. set: function(v) {
  624. let rules = JSON.parse(this.allSetting.subJsonRules);
  625. if (!Array.isArray(rules)) return;
  626. if (v.length == 0) {
  627. rules = rules.filter(r => !r.ip);
  628. } else {
  629. let ruleIndex = rules.findIndex(r => r.ip);
  630. if (ruleIndex == -1) ruleIndex = rules.push(this.defaultRules[1]) - 1;
  631. rules[ruleIndex].ip = [];
  632. v.forEach(d => {
  633. rules[ruleIndex].ip.push(d);
  634. });
  635. }
  636. this.allSetting.subJsonRules = JSON.stringify(rules);
  637. }
  638. },
  639. directDomains: {
  640. get: function() {
  641. if (!this.enableDirect) return [];
  642. const rules = JSON.parse(this.allSetting.subJsonRules);
  643. if (!Array.isArray(rules)) return [];
  644. const domainRule = rules.find(r => r.domain);
  645. return domainRule?.domain ?? [];
  646. },
  647. set: function(v) {
  648. let rules = JSON.parse(this.allSetting.subJsonRules);
  649. if (!Array.isArray(rules)) return;
  650. if (v.length == 0) {
  651. rules = rules.filter(r => !r.domain);
  652. } else {
  653. let ruleIndex = rules.findIndex(r => r.domain);
  654. if (ruleIndex == -1) ruleIndex = rules.push(this.defaultRules[0]) - 1;
  655. rules[ruleIndex].domain = v;
  656. }
  657. this.allSetting.subJsonRules = JSON.stringify(rules);
  658. }
  659. },
  660. confAlerts: {
  661. get: function() {
  662. if (!this.allSetting) return [];
  663. var alerts = []
  664. if (window.location.protocol !== "https:") alerts.push('{{ i18n "secAlertSSL" }}');
  665. if (this.allSetting.webPort === 2053) alerts.push('{{ i18n "secAlertPanelPort" }}');
  666. panelPath = window.location.pathname.split('/').length < 4
  667. if (panelPath && this.allSetting.webBasePath == '/') alerts.push('{{ i18n "secAlertPanelURI" }}');
  668. if (this.allSetting.subEnable) {
  669. subPath = this.allSetting.subURI.length > 0 ? new URL(this.allSetting.subURI).pathname : this
  670. .allSetting.subPath;
  671. if (subPath == '/sub/') alerts.push('{{ i18n "secAlertSubURI" }}');
  672. }
  673. if (this.allSetting.subJsonEnable) {
  674. subJsonPath = this.allSetting.subJsonURI.length > 0 ? new URL(this.allSetting.subJsonURI).pathname :
  675. this.allSetting.subJsonPath;
  676. if (subJsonPath == '/json/') alerts.push('{{ i18n "secAlertSubJsonURI" }}');
  677. }
  678. return alerts
  679. }
  680. }
  681. },
  682. async mounted() {
  683. this.entryHost = window.location.hostname;
  684. this.entryPort = window.location.port;
  685. this.entryProtocol = window.location.protocol;
  686. this.entryIsIP = this._isIp(this.entryHost);
  687. await this.getAllSetting();
  688. await this.loadInboundTags();
  689. while (true) {
  690. await PromiseUtil.sleep(1000);
  691. this.saveBtnDisable = this.oldAllSetting.equals(this.allSetting);
  692. }
  693. }
  694. });
  695. </script>
  696. {{ template "page/body_end" .}}