@@ -9,6 +9,10 @@ if not arg[1] or not m:get(arg[1]) then
99 luci .http .redirect (m .redirect )
1010end
1111
12+ if api .is_js_luci () then
13+ m :append (Template (appname .. " /cbi/nodes_listvalue_com" ))
14+ end
15+
1216local fs = api .fs
1317local sys = api .sys
1418local has_singbox = api .finded_com (" sing-box" )
@@ -22,11 +26,17 @@ local port_validate = function(self, value, t)
2226end
2327
2428local nodes_table = {}
25- local shunt_list = {}
26- for k , e in ipairs (api .get_valid_nodes ()) do
29+ for _ , e in ipairs (api .get_valid_nodes ()) do
2730 nodes_table [# nodes_table + 1 ] = e
2831end
2932
33+ local normal_list = {}
34+ for _ , v in pairs (nodes_table ) do
35+ if v .node_type == " normal" then
36+ normal_list [# normal_list + 1 ] = v
37+ end
38+ end
39+
3040local dynamicList_write = function (self , section , value )
3141 local t = {}
3242 local t2 = {}
@@ -188,6 +198,10 @@ o:depends({ _hide_node_option = "1", ['!reverse'] = true })
188198o = s :option (ListValue , " tcp_node" , " <a style='color: red'>" .. translate (" TCP Node" ) .. " </a>" )
189199o .default = " "
190200o :depends ({ _hide_node_option = false , use_global_config = false })
201+ if api .is_js_luci () then
202+ o .template = appname .. " /cbi/nodes_listvalue"
203+ end
204+ o .group = {}
191205
192206o = s :option (DummyValue , " _tcp_node_bool" , " " )
193207o .template = " passwall/cbi/hidevalue"
@@ -199,14 +213,10 @@ o.default = ""
199213o :value (" " , translate (" Close" ))
200214o :value (" tcp" , translate (" Same as the tcp node" ))
201215o :depends ({ _tcp_node_bool = " 1" })
202-
203- for k , v in pairs (nodes_table ) do
204- s .fields [" tcp_node" ]:value (v .id , v [" remark" ])
205- s .fields [" udp_node" ]:value (v .id , v [" remark" ])
206- if v .protocol and v .protocol == " _shunt" then
207- shunt_list [# shunt_list + 1 ] = v
208- end
216+ if api .is_js_luci () then
217+ o .template = appname .. " /cbi/nodes_listvalue"
209218end
219+ o .group = {" " ," " }
210220
211221o = s :option (DummyValue , " _udp_node_bool" , " " )
212222o .template = " passwall/cbi/hidevalue"
@@ -260,6 +270,8 @@ o.cfgvalue = function(t, n)
260270 return string.format (' <font color="red">%s</font>' ,
261271 translate (" The port settings support single ports and ranges.<br>Separate multiple ports with commas (,).<br>Example: 21,80,443,1000:2000." ))
262272end
273+ o :depends ({ use_global_config = true })
274+ o :depends ({ _tcp_node_bool = " 1" })
263275
264276o = s :option (Flag , " use_direct_list" , translatef (" Use %s" , translate (" Direct List" )))
265277o .default = " 1"
@@ -333,15 +345,25 @@ o.remove = function(self, section)
333345 if id_val == " " then
334346 return m :del (section , self .option )
335347 end
336- for k , v in pairs (shunt_list ) do
348+ for _ , v in pairs (nodes_table ) do
337349 if v .id == id_val then
338350 local new_val = (v .type == " Xray" ) and " xray" or " sing-box"
339- return m :set (section , self .option , new_val )
351+ m :set (section , self .option , new_val )
352+
353+ local dns_field = s .fields [v .type == " Xray" and " xray_dns_mode" or " singbox_dns_mode" ]
354+ local v2ray_dns_mode = dns_field and dns_field :formvalue (section )
355+ if v2ray_dns_mode then
356+ m :set (section , " v2ray_dns_mode" , v2ray_dns_mode )
357+ end
358+
359+ break
340360 end
341361 end
342362end
343363
344364o = s :option (ListValue , " xray_dns_mode" , translate (" Request protocol" ))
365+ o .default = " tcp"
366+ o :value (" udp" , " UDP" )
345367o :value (" tcp" , " TCP" )
346368o :value (" tcp+doh" , " TCP + DoH (" .. translate (" A/AAAA type" ) .. " )" )
347369o :depends (" dns_mode" , " xray" )
@@ -355,6 +377,8 @@ o.write = function(self, section, value)
355377end
356378
357379o = s :option (ListValue , " singbox_dns_mode" , translate (" Request protocol" ))
380+ o .default = " tcp"
381+ o :value (" udp" , " UDP" )
358382o :value (" tcp" , " TCP" )
359383o :value (" doh" , " DoH" )
360384o :depends (" dns_mode" , " sing-box" )
@@ -379,53 +403,53 @@ o:value("149.112.112.112", "149.112.112.112 (Quad9-Recommended)")
379403o :value (" 208.67.220.220" , " 208.67.220.220 (OpenDNS)" )
380404o :value (" 208.67.222.222" , " 208.67.222.222 (OpenDNS)" )
381405o :depends ({dns_mode = " dns2socks" })
406+ o :depends ({xray_dns_mode = " udp" })
382407o :depends ({xray_dns_mode = " tcp" })
383408o :depends ({xray_dns_mode = " tcp+doh" })
409+ o :depends ({singbox_dns_mode = " udp" })
384410o :depends ({singbox_dns_mode = " tcp" })
385411
386- if has_singbox or has_xray then
387- o = s :option (Value , " remote_dns_doh" , translate (" Remote DNS DoH" ))
388- o :value (" https://1.1.1.1/dns-query" , " CloudFlare" )
389- o :value (" https://1.1.1.2/dns-query" , " CloudFlare-Security" )
390- o :value (" https://8.8.4.4/dns-query" , " Google 8844" )
391- o :value (" https://8.8.8.8/dns-query" , " Google 8888" )
392- o :value (" https://9.9.9.9/dns-query" , " Quad9-Recommended 9.9.9.9" )
393- o :value (" https://149.112.112.112/dns-query" , " Quad9-Recommended 149.112.112.112" )
394- o :value (" https://208.67.222.222/dns-query" , " OpenDNS" )
395- o :value (" https://dns.adguard.com/dns-query,176.103.130.130" , " AdGuard" )
396- o :value (" https://doh.libredns.gr/dns-query,116.202.176.26" , " LibreDNS" )
397- o :value (" https://doh.libredns.gr/ads,116.202.176.26" , " LibreDNS (No Ads)" )
398- o .default = " https://1.1.1.1/dns-query"
399- o .validate = function (self , value , t )
400- if value ~= " " then
401- value = api .trim (value )
402- local flag = 0
403- local util = require " luci.util"
404- local val = util .split (value , " ," )
405- local url = val [1 ]
406- val [1 ] = nil
407- for i = 1 , # val do
408- local v = val [i ]
409- if v then
410- if not api .datatypes .ipmask4 (v ) then
411- flag = 1
412- end
412+ o = s :option (Value , " remote_dns_doh" , translate (" Remote DNS DoH" ))
413+ o :value (" https://1.1.1.1/dns-query" , " 1.1.1.1 (CloudFlare)" )
414+ o :value (" https://1.1.1.2/dns-query" , " 1.1.1.2 (CloudFlare-Security)" )
415+ o :value (" https://8.8.4.4/dns-query" , " 8.8.4.4 (Google)" )
416+ o :value (" https://8.8.8.8/dns-query" , " 8.8.8.8 (Google)" )
417+ o :value (" https://9.9.9.9/dns-query" , " 9.9.9.9 (Quad9)" )
418+ o :value (" https://149.112.112.112/dns-query" , " 149.112.112.112 (Quad9)" )
419+ o :value (" https://208.67.222.222/dns-query" , " 208.67.222.222 (OpenDNS)" )
420+ o :value (" https://dns.adguard.com/dns-query,94.140.14.14" , " 94.140.14.14 (AdGuard)" )
421+ o :value (" https://doh.libredns.gr/dns-query,116.202.176.26" , " 116.202.176.26 (LibreDNS)" )
422+ o :value (" https://doh.libredns.gr/ads,116.202.176.26" , " 116.202.176.26 (LibreDNS-NoAds)" )
423+ o .default = " https://1.1.1.1/dns-query"
424+ o .validate = function (self , value , t )
425+ if value ~= " " then
426+ value = api .trim (value )
427+ local flag = 0
428+ local util = require " luci.util"
429+ local val = util .split (value , " ," )
430+ local url = val [1 ]
431+ val [1 ] = nil
432+ for i = 1 , # val do
433+ local v = val [i ]
434+ if v then
435+ if not api .datatypes .ipmask4 (v ) then
436+ flag = 1
413437 end
414438 end
415- if flag == 0 then
416- return value
417- end
418439 end
419- return nil , translate (" DoH request address" ) .. " " .. translate (" Format must be:" ) .. " URL,IP"
440+ if flag == 0 then
441+ return value
442+ end
420443 end
421- o :depends ({xray_dns_mode = " tcp+doh" })
422- o :depends ({singbox_dns_mode = " doh" })
423-
424- o = s :option (Value , " remote_dns_client_ip" , translate (" EDNS Client Subnet" ))
425- o .datatype = " ipaddr"
426- o :depends ({dns_mode = " sing-box" })
427- o :depends ({dns_mode = " xray" })
444+ return nil , translate (" DoH request address" ) .. " " .. translate (" Format must be:" ) .. " URL,IP"
428445end
446+ o :depends ({xray_dns_mode = " tcp+doh" })
447+ o :depends ({singbox_dns_mode = " doh" })
448+
449+ o = s :option (Value , " remote_dns_client_ip" , translate (" EDNS Client Subnet" ))
450+ o .datatype = " ipaddr"
451+ o :depends ({dns_mode = " sing-box" })
452+ o :depends ({dns_mode = " xray" })
429453
430454o = s :option (ListValue , " chinadns_ng_default_tag" , translate (" Default DNS" ))
431455o .default = " none"
@@ -452,20 +476,40 @@ o:value("direct", translate("Direct DNS"))
452476o .description = desc .. " </ul>"
453477o :depends ({dns_shunt = " dnsmasq" , tcp_proxy_mode = " proxy" , chn_list = " direct" })
454478
479+ local tcp = s .fields [" tcp_node" ]
480+ local udp = s .fields [" udp_node" ]
455481for k , v in pairs (nodes_table ) do
456- if v .protocol ~= " _shunt" then
457- s .fields [" dns_mode" ]:depends ({ _tcp_node_bool = " 1" , tcp_node = v .id })
458- end
459- end
460- for k , v in pairs (shunt_list ) do
461- if v .type == " Xray" and has_xray then
462- s .fields [" xray_dns_mode" ]:depends ({ _tcp_node_bool = " 1" , tcp_node = v .id })
463- end
464- if v .type == " sing-box" and has_singbox then
465- s .fields [" singbox_dns_mode" ]:depends ({ _tcp_node_bool = " 1" , tcp_node = v .id })
482+ if # normal_list == 0 then
483+ s .fields [" dns_mode" ]:depends ({ _tcp_node_bool = " 1" })
484+ break
466485 end
467- if has_xray or has_singbox then
468- s .fields [" remote_dns_client_ip" ]:depends ({ tcp_node = v .id })
486+ if v .protocol == " _shunt" then
487+ if v .type == " Xray" and has_xray then
488+ tcp :value (v .id , v [" remark" ])
489+ tcp .group [# tcp .group + 1 ] = (v .group and v .group ~= " " ) and v .group or translate (" default" )
490+ udp :value (v .id , v [" remark" ])
491+ udp .group [# udp .group + 1 ] = (v .group and v .group ~= " " ) and v .group or translate (" default" )
492+
493+ s .fields [" xray_dns_mode" ]:depends ({ _tcp_node_bool = " 1" , tcp_node = v .id })
494+ end
495+ if v .type == " sing-box" and has_singbox then
496+ tcp :value (v .id , v [" remark" ])
497+ tcp .group [# tcp .group + 1 ] = (v .group and v .group ~= " " ) and v .group or translate (" default" )
498+ udp :value (v .id , v [" remark" ])
499+ udp .group [# udp .group + 1 ] = (v .group and v .group ~= " " ) and v .group or translate (" default" )
500+
501+ s .fields [" singbox_dns_mode" ]:depends ({ _tcp_node_bool = " 1" , tcp_node = v .id })
502+ end
503+ if has_xray or has_singbox then
504+ s .fields [" remote_dns_client_ip" ]:depends ({ tcp_node = v .id })
505+ end
506+ else
507+ tcp :value (v .id , v [" remark" ])
508+ tcp .group [# tcp .group + 1 ] = (v .group and v .group ~= " " ) and v .group or translate (" default" )
509+ udp :value (v .id , v [" remark" ])
510+ udp .group [# udp .group + 1 ] = (v .group and v .group ~= " " ) and v .group or translate (" default" )
511+
512+ s .fields [" dns_mode" ]:depends ({ _tcp_node_bool = " 1" , tcp_node = v .id })
469513 end
470514end
471515
0 commit comments