diff --git a/htdocs/luci-static/resources/view/homeproxy/client.js b/htdocs/luci-static/resources/view/homeproxy/client.js index 73ec4060..88c225f6 100644 --- a/htdocs/luci-static/resources/view/homeproxy/client.js +++ b/htdocs/luci-static/resources/view/homeproxy/client.js @@ -156,7 +156,7 @@ return view.extend({ o.rmempty = false; o = s.taboption('routing', form.Value, 'dns_server', _('DNS server'), - _('You can only have one server set. It MUST support TCP query.')); + _('It MUST support TCP query.')); o.value('wan', _('Use DNS server from WAN')); o.value('1.1.1.1', _('CloudFlare Public DNS (1.1.1.1)')); o.value('208.67.222.222', _('Cisco Public DNS (208.67.222.222)')); @@ -182,27 +182,37 @@ return view.extend({ } if (features.hp_has_chinadns_ng) { - o = s.taboption('routing', form.Value, 'china_dns_server', _('China DNS server'), - _('You can only have two servers set at maximum.')); - o.value('', _('Disable')); + o = s.taboption('routing', form.DynamicList, 'china_dns_server', _('China DNS server')); o.value('wan', _('Use DNS server from WAN')); - o.value('wan_114', _('Use DNS server from WAN + 114DNS')); o.value('223.5.5.5', _('Aliyun Public DNS (223.5.5.5)')); o.value('210.2.4.8', _('CNNIC Public DNS (210.2.4.8)')); o.value('119.29.29.29', _('Tencent Public DNS (119.29.29.29)')); o.value('114.114.114.114', _('Xinfeng Public DNS (114.114.114.114)')); o.depends('routing_mode', 'bypass_mainland_china'); - o.validate = function(section_id, value) { - if (section_id && value && !['wan', 'wan_114'].includes(value)) { - var dns_servers = value.split(','); - var ipv6_support = this.map.lookupOption('ipv6_support', section_id)[0].formvalue(section_id); + o.validate = function(section_id) { + if (section_id) { + var value = this.map.lookupOption('china_dns_server', section_id)[0].formvalue(section_id); + if (value.length < 1) + return true; - if (dns_servers.length > 2) + if (!features.hp_has_chinadns_ng_v2 && value.length > 2) return _('You can only have two servers set at maximum.'); - for (var i of dns_servers) - if (!stubValidator.apply((ipv6_support === '1') ? 'ipaddr' : 'ip4addr', i)) - return _('Expecting: %s').format(_('valid IP address')); + for (var dns of value) { + var ipv6_support = this.map.lookupOption('ipv6_support', section_id)[0].formvalue(section_id); + if (dns === 'wan') { + continue; + } else { + var err = _('Expecting: %s').format(_('valid address#port')); + dns = dns.split('#'); + if (dns.length > 2) + return err; + if (!stubValidator.apply((ipv6_support === '1') ? 'ipaddr' : 'ip4addr', dns[0])) + return err; + if (dns[1] && !stubValidator.apply('port', dns[1])) + return err; + } + } } return true; diff --git a/root/etc/init.d/homeproxy b/root/etc/init.d/homeproxy index 6322392c..9ff242cf 100755 --- a/root/etc/init.d/homeproxy +++ b/root/etc/init.d/homeproxy @@ -180,10 +180,8 @@ start_service() { # chinadns-ng if [ -n "$china_dns_server" ]; then local wandns="$(ifstatus wan | jsonfilter -e '@["dns-server"][0]' || echo "119.29.29.29")" - case "$china_dns_server" in - "wan") china_dns_server="$wandns" ;; - "wan_114") china_dns_server="$wandns,114.114.114.114" ;; - esac + china_dns_server="${china_dns_server/wan/$wandns}" + china_dns_server="${china_dns_server// /,}" for i in $(seq 1 "$(grep -c "processor" "/proc/cpuinfo")"); do procd_open_instance "chinadns-ng-$i" @@ -199,6 +197,11 @@ start_service() { [ "$ipv6_support" -eq "1" ] || procd_append_param command --no-ipv6=tC procd_append_param command --reuse-port + if chinadns-ng --version | grep -q "target:"; then + procd_append_param command --cache 10000 + procd_append_param command --cache-stale 3600 + fi + if [ -x "/sbin/ujail" ]; then procd_add_jail "chinadns-ng" log procd_add_jail_mount "$HP_DIR/resources/china_list.txt" diff --git a/root/etc/uci-defaults/luci-homeproxy-migration b/root/etc/uci-defaults/luci-homeproxy-migration new file mode 100644 index 00000000..a31c62f7 --- /dev/null +++ b/root/etc/uci-defaults/luci-homeproxy-migration @@ -0,0 +1,15 @@ +#!/bin/sh + +china_dns_server="$(uci -q get "homeproxy.config.china_dns_server")" +if [ "$china_dns_server" = "wan_114" ]; then + uci -q delete homeproxy.config.china_dns_server + uci -q add_list "homeproxy.config.china_dns_server"="wan" + uci -q add_list "homeproxy.config.china_dns_server"="114.114.114.114" +elif echo "$china_dns_server" | grep -q ","; then + uci -q delete homeproxy.config.china_dns_server + for dns in ${china_dns_server//,/ }; do + uci -q add_list "homeproxy.config.china_dns_server"="$dns" + done +fi + +exit 0 diff --git a/root/usr/share/rpcd/ucode/luci.homeproxy b/root/usr/share/rpcd/ucode/luci.homeproxy index f31b1ca3..34754c52 100755 --- a/root/usr/share/rpcd/ucode/luci.homeproxy +++ b/root/usr/share/rpcd/ucode/luci.homeproxy @@ -173,6 +173,8 @@ const methods = { } features.hp_has_chinadns_ng = access('/usr/bin/chinadns-ng'); + if (features.hp_has_chinadns_ng) + features.hp_has_chinadns_ng_v2 = (system('/usr/bin/chinadns-ng --version | grep -q "target:"') === 0); features.hp_has_ip_full = access('/usr/libexec/ip-full'); features.hp_has_tcp_brutal = hasKernelModule('brutal.ko'); features.hp_has_tproxy = hasKernelModule('nft_tproxy.ko') || access('/etc/modules.d/nft-tproxy');