update 2023-07-12 23:36:14

This commit is contained in:
github-actions[bot] 2023-07-12 23:36:14 +08:00
parent 8b04762e7e
commit e4a47c9943
8 changed files with 95 additions and 49 deletions

View File

@ -17,7 +17,6 @@ endef
define Package/$(PKG_NAME)/postinst
#!/bin/sh
[ ! -f /etc/openwrt_release ] && exit 0
[ -n "${IPKG_INSTROOT}" ] || {
sysctl -p /etc/sysctl.d/20-mosdns-buffer-increase.conf
exit 0

View File

@ -20,8 +20,6 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
[ ! -f /etc/openwrt_release ] && exit 0
START=99
USE_PROCD=1

View File

@ -60,6 +60,7 @@ define Package/$(PKG_NAME)/install
$(INSTALL_DATA) ./root/usr/share/rpcd/acl.d/luci-app-xray.json $(1)/usr/share/rpcd/acl.d/luci-app-xray.json
$(INSTALL_DIR) $(1)/usr/share/xray
$(INSTALL_DATA) ./root/usr/share/xray/include.nft $(1)/usr/share/xray/include.nft
$(INSTALL_BIN) ./root/usr/share/xray/dnsmasq_include.ut $(1)/usr/share/xray/dnsmasq_include.ut
$(INSTALL_BIN) ./root/usr/share/xray/firewall_include.ut $(1)/usr/share/xray/firewall_include.ut
$(INSTALL_BIN) ./root/usr/share/xray/gen_config.uc $(1)/usr/share/xray/gen_config.uc
endef

View File

@ -109,17 +109,7 @@ gen_config_file() {
}
setup_dnsmasq() {
local dns_port=$(uci_get_by_type general dns_port)
local dns_count=$(uci_get_by_type general dns_count 0)
echo "# Generated dnsmasq configurations by luci-app-xray" > /tmp/dnsmasq.d/xray.conf
echo "strict-order" >> /tmp/dnsmasq.d/xray.conf
echo "server=/#/127.0.0.1#${dns_port}" >> /tmp/dnsmasq.d/xray.conf
local cur_port
for cur_port in $(seq ${dns_port} $(expr ${dns_port} + ${dns_count})); do
echo "server=127.0.0.1#${cur_port}" >> /tmp/dnsmasq.d/xray.conf
done
utpl /usr/share/xray/dnsmasq_include.ut > /tmp/dnsmasq.d/xray.conf
logger -st xray[$$] -p4 $(cat /tmp/dnsmasq.d/xray.conf)
/etc/init.d/dnsmasq restart > /dev/null 2>&1
}

View File

@ -0,0 +1,30 @@
#!/usr/bin/utpl
{%
"use strict";
import { cursor } from "uci";
const config = function () {
const uci = cursor();
uci.load("xray_fw4");
return uci.get_all("xray_fw4");
}();
const general = config[filter(keys(config), k => config[k][".type"] == "general")[0]];
const dns_port = int(general["dns_port"]);
const dns_count = int(general["dns_count"] || 0);
const manual_tproxy = filter(keys(config), k => config[k][".type"] == "manual_tproxy") || [];
%}
# Generated dnsmasq configurations by luci-app-xray
strict-order
server=/#/127.0.0.1#{{ general.dns_port }}
{% for (let i = dns_port; i <= dns_port + dns_count; i++): %}
server=127.0.0.1#{{ i }}
{% endfor %}
{% for (let i in manual_tproxy): %}
{% if (config[i]["rebind_domain_ok"] == "1"): %}
{% for (let j in config[i]["domain_names"]): %}
rebind-domain-ok={{ j }}
{% endfor %}
{% endif %}
{% endfor %}
{% if (general["blocked_as_nxdomain"] == "1"): %}
bogus-nxdomain=127.127.127.127
{% endif %}

View File

@ -1,10 +1,13 @@
#!/usr/bin/utpl
{%
const uci = require("uci");
const fs = require("fs");
const cursor = uci.cursor();
cursor.load("xray_fw4");
const config = cursor.get_all("xray_fw4");
"use strict";
import { cursor } from "uci";
import { stat } from "fs";
const config = function () {
const uci = cursor();
uci.load("xray_fw4");
return uci.get_all("xray_fw4");
}();
const general = config[filter(keys(config), k => config[k][".type"] == "general")[0]];
const tp_spec_src_fw = uniq(map(filter(keys(config), k => config[k][".type"] == "lan_hosts" && config[k].bypassed == "0"), k => config[k].macaddr) || []);
const tp_spec_src_bp = uniq(map(filter(keys(config), k => config[k][".type"] == "lan_hosts" && config[k].bypassed == "1"), k => config[k].macaddr) || []);
@ -16,7 +19,7 @@
push(wan_fw_ips_no_dns, split(general.secure_dns, ":")[0]);
const wan_bp_ips = uniq(wan_bp_ips_no_dns);
const wan_fw_ips = uniq(wan_fw_ips_no_dns);
const ignore_tp_spec_def_gw = fs.stat("/usr/share/xray/ignore_tp_spec_def_gw");
const ignore_tp_spec_def_gw = stat("/usr/share/xray/ignore_tp_spec_def_gw");
const transparent_default_port_policy = general.transparent_default_port_policy || "forwarded";
const wan_fw_tcp_ports = general.wan_fw_tcp_ports || [];
const wan_fw_udp_ports = general.wan_fw_udp_ports || [];

View File

@ -1,15 +1,23 @@
#!/usr/bin/ucode
const uci = require("uci");
const fs = require("fs");
const cursor = uci.cursor();
cursor.load("xray_fw4");
const config = cursor.get_all("xray_fw4");
const share_dir = fs.lsdir("/usr/share/xray");
"use strict";
import { cursor } from "uci";
import { lsdir } from "fs";
const config = function () {
const uci = cursor();
uci.load("xray_fw4");
return uci.get_all("xray_fw4");
}();
const proxy = config[filter(keys(config), k => config[k][".type"] == "general")[0]];
const bridge = filter(keys(config), k => config[k][".type"] == "bridge") || [];
const fallback = filter(keys(config), k => config[k][".type"] == "fallback") || [];
const manual_tproxy = filter(keys(config), k => config[k][".type"] == "manual_tproxy") || [];
const tcp_server = config[proxy["main_server"]];
const udp_server = config[proxy["tproxy_udp_server"]];
const share_dir = lsdir("/usr/share/xray");
const geoip_existence = index(share_dir, "geoip.dat") > 0;
const geosite_existence = index(share_dir, "geosite.dat") > 0;
@ -363,7 +371,7 @@ function override_custom_config_recursive(x, y) {
if (type(x) != "object" || type(y) != "object") {
return y;
}
for (k in y) {
for (let k in y) {
x[k] = override_custom_config_recursive(x[k], y[k])
}
return x;
@ -387,8 +395,8 @@ function server_outbound_recursive(t, server, tag) {
const custom_config_outbound_string = server["custom_config"];
if (custom_config_outbound_string != null && custom_config_outbound_string != "") {
let custom_config_outbound = json(custom_config_outbound_string);
for (k in custom_config_outbound) {
const custom_config_outbound = json(custom_config_outbound_string);
for (let k in custom_config_outbound) {
if (k == "tag") {
continue;
}
@ -479,7 +487,7 @@ function socks_inbound() {
function fallbacks() {
let f = [];
for (key in filter(keys(config), k => config[k][".type"] == "fallback")) {
for (let key in fallback) {
const s = config[key];
if (s["dest"] != null) {
push(f, {
@ -594,7 +602,7 @@ function https_inbound() {
if (proxy["web_server_protocol"] == "trojan") {
return https_trojan_inbound()
}
return nil
return null;
}
function dns_server_inbounds() {
@ -695,13 +703,19 @@ function dns_conf() {
});
}
let hosts = null;
let hosts = {};
if (length(blocked_domain_rules()) > 0) {
hosts = {};
for (rule in (blocked_domain_rules())) {
for (let rule in (blocked_domain_rules())) {
hosts[rule] = ["127.127.127.127", "100::6c62:636f:656b:2164"] // blocked!
}
}
for (let key in manual_tproxy) {
if (config[key].domain_names != null) {
for (let d in config[key].domain_names) {
hosts[d] = [config[key].source_addr];
}
}
}
return {
hosts: hosts,
@ -773,13 +787,13 @@ function inbounds() {
function manual_tproxy_outbounds() {
let result = [];
let i = 0;
for (key in filter(keys(config), k => config[k][".type"] == "manual_tproxy")) {
for (let key in manual_tproxy) {
const v = config[key];
i = i + 1;
let tcp_tag = "direct";
let udp_tag = "direct";
if (v["force_forward"] == "1") {
if (v["force_forward_server_tcp"] != nil) {
if (v["force_forward_server_tcp"] != null) {
if (v["force_forward_server_tcp"] == proxy["main_server"]) {
tcp_tag = "tcp_outbound"
} else {
@ -790,7 +804,7 @@ function manual_tproxy_outbounds() {
} else {
tcp_tag = "tcp_outbound"
}
if (v["force_forward_server_udp"] != nil) {
if (v["force_forward_server_udp"] != null) {
if (v["force_forward_server_udp"] == proxy["tproxy_udp_server"]) {
udp_tag = "udp_outbound"
} else {
@ -832,7 +846,7 @@ function manual_tproxy_outbounds() {
function manual_tproxy_rules() {
let result = [];
let i = 0;
for (key in filter(keys(config), k => config[k][".type"] == "manual_tproxy")) {
for (let key in manual_tproxy) {
const v = config[key];
i = i + 1;
splice(result, 0, 0, {
@ -856,7 +870,7 @@ function manual_tproxy_rules() {
function bridges() {
let result = [];
let i = 0;
for (key in filter(keys(config), k => config[k][".type"] == "bridge")) {
for (let key in bridge) {
const v = config[key];
i = i + 1;
push(result, {
@ -870,11 +884,11 @@ function bridges() {
function bridge_outbounds() {
let result = [];
let i = 0;
for (key in filter(keys(config), k => config[k][".type"] == "bridge")) {
for (let key in bridge) {
const v = config[key];
i = i + 1;
const bridge_server = config[v["upstream"]];
for (f in server_outbound(bridge_server, sprintf("bridge_upstream_outbound_%d", i))) {
for (let f in server_outbound(bridge_server, sprintf("bridge_upstream_outbound_%d", i))) {
splice(result, 0, 0, f);
}
splice(result, 0, 0, {
@ -890,7 +904,7 @@ function bridge_outbounds() {
function bridge_rules() {
let result = [];
for (key in filter(keys(config), k => config[k][".type"] == "bridge")) {
for (let key in bridge) {
const v = config[key];
i = i + 1;
push(result, {
@ -924,13 +938,15 @@ function rules() {
type: "field",
inboundTag: dns_server_tags(),
outboundTag: "dns_server_outbound"
},
{
}
];
if (proxy["xray_api"] == '1') {
push(result, {
type: "field",
inboundTag: ["api"],
outboundTag: "api"
}
];
});
}
if (proxy["metrics_server_enable"] == "1") {
splice(result, 0, 0, {
type: "field",

View File

@ -1,10 +1,10 @@
'use strict';
'require view';
'require uci';
'require form';
'require fs';
'require network';
'require tools.widgets as widgets';
'require uci';
'require view';
const variant = "xray_fw4";
@ -304,7 +304,7 @@ return view.extend({
o = s.taboption('general', form.Flag, 'route_only', _('Route Only'), _('Use sniffed domain for routing only but still access through IP. Reduces unnecessary DNS requests. See <a href="https://github.com/XTLS/Xray-core/commit/a3023e43ef55d4498b1afbc9a7fe7b385138bb1a">here</a> for help.'))
o.depends({ "transparent_proxy_enable": "1", "tproxy_sniffing": "1" })
o = s.taboption('general', form.Flag, 'direct_bittorrent', _('Bittorrent Direct'), _("If enabled, all bittorrent request won't be forwarded through Xray."))
o = s.taboption('general', form.Flag, 'direct_bittorrent', _('Bittorrent Direct'), _("If enabled, no bittorrent request will be forwarded through Xray."))
o.depends({ "transparent_proxy_enable": "1", "tproxy_sniffing": "1" })
o = s.taboption('general', form.SectionValue, "xray_servers", form.GridSection, 'servers', _('Xray Servers'), _("Servers are referenced by index (order in the following list). Deleting servers may result in changes of upstream servers actually used by proxy and bridge."))
@ -690,6 +690,9 @@ return view.extend({
}
o.rmempty = true
o = s.taboption('dns', form.Flag, 'blocked_as_nxdomain', _('Use NXDOMAIN for blocked'), _('Return <code>NXDOMAIN</code> as response for blocked domain rules. If not selected, a loopback address will be returned.'))
o.modalonly = true
o = s.taboption('dns', form.Value, 'dns_port', _('Xray DNS Server Port'), _("Do not use port 53 (dnsmasq), port 5353 (mDNS) or other common ports"))
o.datatype = 'port'
o.default = 5300
@ -794,6 +797,12 @@ return view.extend({
o.default = "UseIP"
o.modalonly = true
o = ss.option(form.DynamicList, "domain_names", _("Domain names to associate"))
o.rmempty = true
o = ss.option(form.Flag, 'rebind_domain_ok', _('Exempt rebind protection'), _('Avoid dnsmasq filtering RFC1918 IP addresses (and some TESTNET addresses as well) from result.'))
o.modalonly = true
o = ss.option(form.Flag, 'force_forward', _('Force Forward'), _('This destination must be forwarded through an outbound server.'))
o.modalonly = true