diff --git a/README.md b/README.md index 51022cc8..ef6581fa 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,10 @@ Fork this repository and: * Wait until actions finish * Use `opkg -i *` to install both ipks from Releases. +## Changelog since 3.4.0 + +* 2024-02-18 chore: optimize code style; bump version + ## Changelog since 3.3.0 * 2024-01-19 chore: bump version diff --git a/core/Makefile b/core/Makefile index fa5cfe9d..0641f1a3 100644 --- a/core/Makefile +++ b/core/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-xray -PKG_VERSION:=3.3.1 +PKG_VERSION:=3.4.0 PKG_RELEASE:=1 PKG_LICENSE:=MPLv2 @@ -132,7 +132,6 @@ endif $(INSTALL_DIR) $(1)/usr/share/xray/feature $(INSTALL_DATA) ./root/usr/share/xray/feature/bridge.mjs $(1)/usr/share/xray/feature/bridge.mjs $(INSTALL_DATA) ./root/usr/share/xray/feature/dns.mjs $(1)/usr/share/xray/feature/dns.mjs - $(INSTALL_DATA) ./root/usr/share/xray/feature/extra_inbound.mjs $(1)/usr/share/xray/feature/extra_inbound.mjs $(INSTALL_DATA) ./root/usr/share/xray/feature/fake_dns.mjs $(1)/usr/share/xray/feature/fake_dns.mjs $(INSTALL_DATA) ./root/usr/share/xray/feature/inbound.mjs $(1)/usr/share/xray/feature/inbound.mjs $(INSTALL_DATA) ./root/usr/share/xray/feature/manual_tproxy.mjs $(1)/usr/share/xray/feature/manual_tproxy.mjs diff --git a/core/root/usr/share/xray/feature/dns.mjs b/core/root/usr/share/xray/feature/dns.mjs index 75966a51..7712faa9 100644 --- a/core/root/usr/share/xray/feature/dns.mjs +++ b/core/root/usr/share/xray/feature/dns.mjs @@ -75,31 +75,34 @@ export function dns_rules(proxy, tcp_hijack_inbound_tags, udp_hijack_inbound_tag for (let i = dns_port; i <= dns_port + dns_count; i++) { push(dns_server_tags, sprintf("dns_server_inbound:%d", i)); } - return [ + let result = [ { + type: "field", + inboundTag: dns_server_tags, + outboundTag: "dns_server_outbound" + }, + ]; + if (proxy.dns_tcp_hijack) { + push(result, { type: "field", port: "53", inboundTag: tcp_hijack_inbound_tags, outboundTag: "dns_tcp_hijack_outbound" - }, - { + }); + } + if (proxy.dns_udp_hijack) { + push(result, { type: "field", port: "53", inboundTag: udp_hijack_inbound_tags, outboundTag: "dns_udp_hijack_outbound" - }, - { - type: "field", - inboundTag: dns_server_tags, - outboundTag: "dns_server_outbound" - }, - ]; + }); + } + return result; }; export function dns_server_outbounds(proxy) { - return [ - direct_outbound("dns_tcp_hijack_outbound", proxy.dns_tcp_hijack || ""), - direct_outbound("dns_udp_hijack_outbound", proxy.dns_udp_hijack || ""), + let result = [ { protocol: "dns", settings: { @@ -113,6 +116,13 @@ export function dns_server_outbounds(proxy) { tag: "dns_server_outbound" } ]; + if (proxy.dns_tcp_hijack) { + push(result, direct_outbound("dns_tcp_hijack_outbound", proxy.dns_tcp_hijack)); + } + if (proxy.dns_udp_hijack) { + push(result, direct_outbound("dns_udp_hijack_outbound", proxy.dns_udp_hijack)); + } + return result; }; export function dns_conf(proxy, config, manual_tproxy, fakedns) { @@ -136,7 +146,7 @@ export function dns_conf(proxy, config, manual_tproxy, fakedns) { let servers = [ ...fake_dns_domains(fakedns), ...map(keys(domain_extra_options), function (k) { - const i = split_ipv4_host_port(domain_extra_options[k]); + let i = split_ipv4_host_port(domain_extra_options[k]); i["domains"] = [`domain:${k}`]; i["skipFallback"] = true; return i; diff --git a/core/root/usr/share/xray/feature/extra_inbound.mjs b/core/root/usr/share/xray/feature/extra_inbound.mjs deleted file mode 100644 index a0313889..00000000 --- a/core/root/usr/share/xray/feature/extra_inbound.mjs +++ /dev/null @@ -1,69 +0,0 @@ -"use strict"; - -import { dokodemo_inbound, http_inbound, socks_inbound } from "./inbound.mjs"; -import { balancer } from "./system.mjs"; - -export function extra_inbounds(proxy, extra_inbound) { - let result = []; - for (let v in extra_inbound) { - const tag = `extra_inbound:${v[".name"]}`; - if (v["inbound_type"] == "http") { - push(result, http_inbound(v["inbound_addr"] || "0.0.0.0", v["inbound_port"], tag, v["inbound_username"], v["inbound_password"])); - } else if (v["inbound_type"] == "socks5") { - push(result, socks_inbound(v["inbound_addr"] || "0.0.0.0", v["inbound_port"], tag, v["inbound_username"], v["inbound_password"])); - } else if (v["inbound_type"] == "tproxy_tcp") { - push(result, dokodemo_inbound(v["inbound_addr"] || "0.0.0.0", v["inbound_port"], tag, proxy["tproxy_sniffing"], proxy["route_only"], ["http", "tls"], "0", "tcp", "tproxy")); - } else if (v["inbound_type"] == "tproxy_udp") { - push(result, dokodemo_inbound(v["inbound_addr"] || "0.0.0.0", v["inbound_port"], tag, proxy["tproxy_sniffing"], proxy["route_only"], ["quic"], "0", "udp", "tproxy")); - } else { - die(`unknown inbound type ${v["inbound_type"]}`); - } - } - return result; -}; - -export function extra_inbound_rules(extra_inbound) { - let result = []; - for (let v in extra_inbound) { - if (v["specify_outbound"] == "1") { - push(result, { - type: "field", - inboundTag: [`extra_inbound:${v[".name"]}`], - balancerTag: `extra_inbound_outbound:${v[".name"]}` - }); - } - } - return result; -}; - -export function extra_inbound_balancers(extra_inbound) { - let result = []; - for (let e in extra_inbound) { - if (e["specify_outbound"] == "1") { - push(result, { - "tag": `extra_inbound_outbound:${e[".name"]}`, - "selector": balancer(e, "destination", `extra_inbound:${e[".name"]}`), - "strategy": { - "type": e["balancer_strategy"] || "random" - } - }); - } - } - return result; -}; - -export function extra_inbound_global_tcp(extra_inbound) { - return map(filter(extra_inbound, v => v["specify_outbound"] != "1" && v["inbound_type"] == "tproxy_tcp"), v => `extra_inbound_${v[".name"]}`); -}; - -export function extra_inbound_global_udp(extra_inbound) { - return map(filter(extra_inbound, v => v["specify_outbound"] != "1" && v["inbound_type"] == "tproxy_udp"), v => `extra_inbound_${v[".name"]}`); -}; - -export function extra_inbound_global_http(extra_inbound) { - return map(filter(extra_inbound, v => v["specify_outbound"] != "1" && v["inbound_type"] == "http"), v => `extra_inbound_${v[".name"]}`); -}; - -export function extra_inbound_global_socks5(extra_inbound) { - return map(filter(extra_inbound, v => v["specify_outbound"] != "1" && v["inbound_type"] == "socks5"), v => `extra_inbound_${v[".name"]}`); -}; diff --git a/core/root/usr/share/xray/feature/inbound.mjs b/core/root/usr/share/xray/feature/inbound.mjs index c38b2fb5..1729c975 100644 --- a/core/root/usr/share/xray/feature/inbound.mjs +++ b/core/root/usr/share/xray/feature/inbound.mjs @@ -2,6 +2,7 @@ import { https_trojan_inbound } from "../protocol/trojan.mjs"; import { https_vless_inbound } from "../protocol/vless.mjs"; +import { balancer } from "./system.mjs"; export function dokodemo_inbound(listen, port, tag, sniffing, sniffing_route_only, sniffing_dest_override, sniffing_metadata_only, network, tproxy, timeout) { let result = { @@ -87,3 +88,62 @@ export function https_inbound(proxy, config) { } return null; }; + +export function extra_inbounds(proxy, extra_inbound) { + let result = []; + for (let v in extra_inbound) { + const tag = `extra_inbound:${v[".name"]}`; + if (v["inbound_type"] == "http") { + push(result, http_inbound(v["inbound_addr"] || "0.0.0.0", v["inbound_port"], tag, v["inbound_username"], v["inbound_password"])); + } else if (v["inbound_type"] == "socks5") { + push(result, socks_inbound(v["inbound_addr"] || "0.0.0.0", v["inbound_port"], tag, v["inbound_username"], v["inbound_password"])); + } else if (v["inbound_type"] == "tproxy_tcp") { + push(result, dokodemo_inbound(v["inbound_addr"] || "0.0.0.0", v["inbound_port"], tag, proxy["tproxy_sniffing"], proxy["route_only"], ["http", "tls"], "0", "tcp", "tproxy")); + } else if (v["inbound_type"] == "tproxy_udp") { + push(result, dokodemo_inbound(v["inbound_addr"] || "0.0.0.0", v["inbound_port"], tag, proxy["tproxy_sniffing"], proxy["route_only"], ["quic"], "0", "udp", "tproxy")); + } else { + die(`unknown inbound type ${v["inbound_type"]}`); + } + } + return result; +}; + +export function extra_inbound_rules(extra_inbound) { + let result = []; + for (let v in extra_inbound) { + if (v["specify_outbound"] == "1") { + push(result, { + type: "field", + inboundTag: [`extra_inbound:${v[".name"]}`], + balancerTag: `extra_inbound_outbound:${v[".name"]}` + }); + } + } + return result; +}; + +export function extra_inbound_balancers(extra_inbound) { + let result = []; + for (let e in extra_inbound) { + if (e["specify_outbound"] == "1") { + push(result, { + "tag": `extra_inbound_outbound:${e[".name"]}`, + "selector": balancer(e, "destination", `extra_inbound:${e[".name"]}`), + "strategy": { + "type": e["balancer_strategy"] || "random" + } + }); + } + } + return result; +}; + +export function extra_inbound_global(extra_inbound) { + const global_tags = filter(extra_inbound, v => v["specify_outbound"] != "1"); + return { + "tproxy_tcp": map(filter(global_tags, v => v["inbound_type"] == "tproxy_tcp"), v => `extra_inbound_${v[".name"]}`), + "tproxy_udp": map(filter(global_tags, v => v["inbound_type"] == "tproxy_udp"), v => `extra_inbound_${v[".name"]}`), + "http": map(filter(global_tags, v => v["inbound_type"] == "http"), v => `extra_inbound_${v[".name"]}`), + "socks5": map(filter(global_tags, v => v["inbound_type"] == "socks5"), v => `extra_inbound_${v[".name"]}`), + }; +}; \ No newline at end of file diff --git a/core/root/usr/share/xray/gen_config.uc b/core/root/usr/share/xray/gen_config.uc index 4f1d144d..1c0605c1 100644 --- a/core/root/usr/share/xray/gen_config.uc +++ b/core/root/usr/share/xray/gen_config.uc @@ -5,9 +5,8 @@ import { access } from "fs"; import { load_config } from "./common/config.mjs"; import { bridge_outbounds, bridge_rules, bridges } from "./feature/bridge.mjs"; import { blocked_domain_rules, dns_conf, dns_rules, dns_server_inbounds, dns_server_outbounds, fast_domain_rules, secure_domain_rules } from "./feature/dns.mjs"; -import { extra_inbound_balancers, extra_inbound_global_http, extra_inbound_global_socks5, extra_inbound_global_tcp, extra_inbound_global_udp, extra_inbound_rules, extra_inbounds } from "./feature/extra_inbound.mjs"; import { fake_dns_balancers, fake_dns_conf, fake_dns_rules } from "./feature/fake_dns.mjs"; -import { dokodemo_inbound, http_inbound, https_inbound, socks_inbound } from "./feature/inbound.mjs"; +import { dokodemo_inbound, extra_inbound_balancers, extra_inbound_global, extra_inbound_rules, extra_inbounds, http_inbound, https_inbound, socks_inbound } from "./feature/inbound.mjs"; import { manual_tproxy_outbound_tags, manual_tproxy_outbounds, manual_tproxy_rules } from "./feature/manual_tproxy.mjs"; import { blackhole_outbound, direct_outbound, server_outbound } from "./feature/outbound.mjs"; import { api_conf, balancer, logging, metrics_conf, policy, system_route_rules } from "./feature/system.mjs"; @@ -108,10 +107,11 @@ function rules(proxy, bridge, manual_tproxy, extra_inbound, fakedns) { const tproxy_udp_inbound_v4_tags = ["tproxy_udp_inbound_v4"]; const tproxy_tcp_inbound_v6_tags = ["tproxy_tcp_inbound_v6"]; const tproxy_udp_inbound_v6_tags = ["tproxy_udp_inbound_v6"]; - const extra_inbound_global_tcp_tags = extra_inbound_global_tcp() || []; - const extra_inbound_global_udp_tags = extra_inbound_global_udp() || []; - const extra_inbound_global_http_tags = extra_inbound_global_http() || []; - const extra_inbound_global_socks5_tags = extra_inbound_global_socks5() || []; + const extra_inbound_global_tags = extra_inbound_global(); + const extra_inbound_global_tcp_tags = extra_inbound_global_tags["tproxy_tcp"] || []; + const extra_inbound_global_udp_tags = extra_inbound_global_tags["tproxy_udp"] || []; + const extra_inbound_global_http_tags = extra_inbound_global_tags["http"] || []; + const extra_inbound_global_socks5_tags = extra_inbound_global_tags["socks5"] || []; const built_in_tcp_inbounds = [...tproxy_tcp_inbound_v4_tags, ...extra_inbound_global_tcp_tags, ...extra_inbound_global_http_tags, ...extra_inbound_global_socks5_tags, "socks_inbound", "https_inbound", "http_inbound"]; const built_in_udp_inbounds = [...tproxy_udp_inbound_v4_tags, ...extra_inbound_global_udp_tags, "dns_conf_inbound"]; let result = [ diff --git a/status/Makefile b/status/Makefile index fba8ab4d..a41114bd 100644 --- a/status/Makefile +++ b/status/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-xray-status -PKG_VERSION:=3.3.1 +PKG_VERSION:=3.4.0 PKG_RELEASE:=1 PKG_LICENSE:=MPLv2