2020-03-21 12:56:29 +00:00
'use strict' ;
'require rpc' ;
'require form' ;
'require fs' ;
'require uci' ;
'require tools.widgets as widgets' ;
var callHostHints ;
return L . view . extend ( {
callHostHints : rpc . declare ( {
object : 'luci-rpc' ,
method : 'getHostHints' ,
expect : { '' : { } }
} ) ,
load : function ( ) {
2023-05-25 11:09:49 +00:00
return Promise . all ( [
L . resolveDefault ( fs . stat ( '/proc/net/xt_ndpi/proto' ) , null ) ,
this . callHostHints ( )
] ) ;
2020-03-21 12:56:29 +00:00
} ,
2023-05-25 11:09:49 +00:00
render : function ( testhosts ) {
var m , s , o , hosts ;
hosts = testhosts [ 1 ] ;
2020-03-21 12:56:29 +00:00
2020-06-09 15:05:49 +00:00
m = new form . Map ( 'omr-bypass' , _ ( 'OMR-Bypass' ) , _ ( 'OpenMPTCProuter IP must be used as DNS.' ) ) ;
2020-03-21 12:56:29 +00:00
2023-05-07 06:53:12 +00:00
/ *
s = m . section ( form . TypedSection , 'global' , _ ( 'Global settings' ) ) ;
s . addremove = false ;
s . anonymous = true ;
o = s . option ( form . Flag , 'noipv6' , _ ( 'Disable IPv6 AAAA DNS results for bypassed domains' ) ) ;
o . default = o . disabled ;
o . optional = true ;
* /
2020-03-21 12:56:29 +00:00
s = m . section ( form . GridSection , 'domains' , _ ( 'Domains' ) ) ;
s . addremove = true ;
s . anonymous = true ;
2020-07-31 07:59:50 +00:00
s . nodescriptions = true ;
2020-03-21 12:56:29 +00:00
2020-09-23 07:49:55 +00:00
o = s . option ( form . Flag , 'enabled' , _ ( 'Enabled' ) ) ;
o . default = o . enabled ;
2020-05-01 09:07:25 +00:00
o = s . option ( form . Value , 'name' , _ ( 'Domain' ) ) ;
2020-03-21 12:56:29 +00:00
o . rmempty = false ;
2023-12-30 07:50:57 +00:00
o = s . option ( form . Flag , 'vpn' , _ ( 'VPN on server' ) , _ ( 'Bypass using VPN configured on server.' ) ) ;
2020-06-26 12:53:15 +00:00
o = s . option ( widgets . DeviceSelect , 'interface' , _ ( 'Interface' ) , _ ( 'When none selected, MPTCP master interface is used.' ) ) ;
2020-05-01 09:07:25 +00:00
o . noaliases = true ;
o . noinactive = true ;
o . nocreate = true ;
2023-12-30 07:50:57 +00:00
o . depends ( 'vpn' , '0' ) ;
2020-03-21 12:56:29 +00:00
o = s . option ( form . Value , 'note' , _ ( 'Note' ) ) ;
o . rmempty = true ;
2023-05-07 06:53:12 +00:00
o = s . option ( form . ListValue , 'family' , _ ( 'Restrict to address family' ) ) ;
o . value ( 'ipv4ipv6' , _ ( 'IPv4 and IPv6' ) ) ;
o . value ( 'ipv4' , _ ( 'IPv4 only' ) ) ;
2023-09-29 12:41:43 +00:00
o . value ( 'ipv6' , _ ( 'IPv6 only' ) ) ;
2023-05-07 06:53:12 +00:00
o . default = 'ipv4ipv6' ;
o . modalonly = true
o = s . option ( form . Flag , 'noipv6' , _ ( 'Disable AAAA IPv6 DNS' ) ) ;
o . default = o . enabled ;
o . modalonly = true
2020-03-21 12:56:29 +00:00
s = m . section ( form . GridSection , 'ips' , _ ( 'IPs and Networks' ) ) ;
s . addremove = true ;
s . anonymous = true ;
2020-07-31 07:59:50 +00:00
s . nodescriptions = true ;
2020-03-21 12:56:29 +00:00
2020-09-23 07:49:55 +00:00
o = s . option ( form . Flag , 'enabled' , _ ( 'Enabled' ) ) ;
o . default = o . enabled ;
2020-03-21 12:56:29 +00:00
o = s . option ( form . Value , 'ip' , _ ( 'IP' ) ) ;
o . rmempty = false ;
2023-12-30 07:50:57 +00:00
o = s . option ( form . Flag , 'vpn' , _ ( 'VPN on server' ) , _ ( 'Bypass using VPN configured on server.' ) ) ;
2020-05-01 09:07:25 +00:00
o = s . option ( widgets . DeviceSelect , 'interface' , _ ( 'Interface' ) , _ ( 'When none selected, MPTCP master interface is used.' ) ) ;
o . noaliases = true ;
o . noinactive = true ;
o . nocreate = true ;
2023-12-30 07:50:57 +00:00
o . depends ( 'vpn' , '0' ) ;
2020-03-21 12:56:29 +00:00
o = s . option ( form . Value , 'note' , _ ( 'Note' ) ) ;
o . rmempty = true ;
2020-04-05 18:27:59 +00:00
s = m . section ( form . GridSection , 'dest_port' , _ ( 'Ports destination' ) ) ;
2020-03-21 12:56:29 +00:00
s . addremove = true ;
s . anonymous = true ;
2020-07-31 07:59:50 +00:00
s . nodescriptions = true ;
2020-03-21 12:56:29 +00:00
2020-09-23 07:49:55 +00:00
o = s . option ( form . Flag , 'enabled' , _ ( 'Enabled' ) ) ;
o . default = o . enabled ;
2020-03-21 12:56:29 +00:00
o = s . option ( form . Value , 'dport' , _ ( 'port' ) ) ;
o . rmempty = false ;
2020-05-02 16:24:57 +00:00
o = s . option ( form . ListValue , 'proto' , _ ( 'protocol' ) ) ;
2020-03-21 12:56:29 +00:00
o . default = 'tcp' ;
o . rmempty = false ;
o . value ( 'tcp' ) ;
o . value ( 'udp' ) ;
2020-05-02 16:24:57 +00:00
o . value ( 'icmp' ) ;
2020-03-21 12:56:29 +00:00
2020-06-26 12:53:15 +00:00
o = s . option ( widgets . DeviceSelect , 'interface' , _ ( 'Interface' ) , _ ( 'When none selected, MPTCP master interface is used.' ) ) ;
2020-05-13 19:46:35 +00:00
o . noaliases = true ;
o . noinactive = true ;
o . nocreate = true ;
o = s . option ( form . Value , 'note' , _ ( 'Note' ) ) ;
o . rmempty = true ;
s = m . section ( form . GridSection , 'src_port' , _ ( 'Ports source' ) ) ;
s . addremove = true ;
s . anonymous = true ;
2020-07-31 07:59:50 +00:00
s . nodescriptions = true ;
2020-05-13 19:46:35 +00:00
2020-09-23 07:49:55 +00:00
o = s . option ( form . Flag , 'enabled' , _ ( 'Enabled' ) ) ;
o . default = o . enabled ;
2020-05-13 19:46:35 +00:00
o = s . option ( form . Value , 'sport' , _ ( 'port' ) ) ;
o . rmempty = false ;
o = s . option ( form . ListValue , 'proto' , _ ( 'protocol' ) ) ;
o . default = 'tcp' ;
o . rmempty = false ;
o . value ( 'tcp' ) ;
o . value ( 'udp' ) ;
o . value ( 'icmp' ) ;
2020-06-26 12:53:15 +00:00
o = s . option ( widgets . DeviceSelect , 'interface' , _ ( 'Interface' ) , _ ( 'When none selected, MPTCP master interface is used.' ) ) ;
2020-05-01 09:07:25 +00:00
o . noaliases = true ;
o . noinactive = true ;
o . nocreate = true ;
2020-03-21 12:56:29 +00:00
o = s . option ( form . Value , 'note' , _ ( 'Note' ) ) ;
o . rmempty = true ;
2020-04-05 18:27:59 +00:00
s = m . section ( form . GridSection , 'macs' , _ ( 'MAC-Address' ) ) ;
2020-03-21 12:56:29 +00:00
s . addremove = true ;
s . anonymous = true ;
2020-07-31 07:59:50 +00:00
s . nodescriptions = true ;
2020-03-21 12:56:29 +00:00
2020-09-23 07:49:55 +00:00
o = s . option ( form . Flag , 'enabled' , _ ( 'Enabled' ) ) ;
o . default = o . enabled ;
2020-03-21 12:56:29 +00:00
o = s . option ( form . Value , 'mac' , _ ( 'source MAC-Address' ) ) ;
o . datatype = 'list(unique(macaddr))' ;
o . rmempty = false ;
Object . keys ( hosts ) . forEach ( function ( mac ) {
var hint = hosts [ mac ] . name || hosts [ mac ] . ipv4 ;
o . value ( mac , hint ? '%s (%s)' . format ( mac , hint ) : mac ) ;
} ) ;
2020-06-26 12:53:15 +00:00
o = s . option ( widgets . DeviceSelect , 'interface' , _ ( 'Interface' ) , _ ( 'When none selected, MPTCP master interface is used.' ) ) ;
2020-05-01 09:07:25 +00:00
o . noaliases = true ;
o . noinactive = true ;
o . nocreate = true ;
2020-03-21 12:56:29 +00:00
o = s . option ( form . Value , 'note' , _ ( 'Note' ) ) ;
o . rmempty = true ;
s = m . section ( form . GridSection , 'lan_ip' , _ ( 'Source lan IP address or network' ) ) ;
s . addremove = true ;
s . anonymous = true ;
2020-07-31 07:59:50 +00:00
s . nodescriptions = true ;
2020-03-21 12:56:29 +00:00
2020-09-23 07:49:55 +00:00
o = s . option ( form . Flag , 'enabled' , _ ( 'Enabled' ) ) ;
o . default = o . enabled ;
2020-03-21 12:56:29 +00:00
o = s . option ( form . Value , 'ip' , _ ( 'IP Address' ) ) ;
o . datatype = 'or(ip4addr,ip6addr)' ;
o . rmempty = false ;
Object . keys ( hosts ) . forEach ( function ( mac ) {
if ( hosts [ mac ] . ipv4 ) {
var hint = hosts [ mac ] . name ;
o . value ( hosts [ mac ] . ipv4 , hint ? '%s (%s)' . format ( hosts [ mac ] . ipv4 , hint ) : hosts [ mac ] . ipv4 ) ;
}
} ) ;
2020-06-26 12:53:15 +00:00
o = s . option ( widgets . DeviceSelect , 'interface' , _ ( 'Interface' ) , _ ( 'When none selected, MPTCP master interface is used.' ) ) ;
2020-05-01 09:07:25 +00:00
o . noaliases = true ;
o . noinactive = true ;
o . nocreate = true ;
2020-03-21 12:56:29 +00:00
o = s . option ( form . Value , 'note' , _ ( 'Note' ) ) ;
o . rmempty = true ;
s = m . section ( form . GridSection , 'asns' , _ ( 'ASN' ) ) ;
s . addremove = true ;
s . anonymous = true ;
2020-08-15 06:58:19 +00:00
s . nodescriptions = true ;
2020-03-21 12:56:29 +00:00
2020-09-23 07:49:55 +00:00
o = s . option ( form . Flag , 'enabled' , _ ( 'Enabled' ) ) ;
o . default = o . enabled ;
2020-03-21 12:56:29 +00:00
o = s . option ( form . Value , 'asn' , _ ( 'ASN' ) ) ;
o . rmempty = false ;
2023-12-30 07:50:57 +00:00
o = s . option ( form . Flag , 'vpn' , _ ( 'VPN on server' ) , _ ( 'Bypass using VPN configured on server.' ) ) ;
2020-06-26 12:53:15 +00:00
o = s . option ( widgets . DeviceSelect , 'interface' , _ ( 'Interface' ) , _ ( 'When none selected, MPTCP master interface is used.' ) ) ;
2020-05-01 09:07:25 +00:00
o . noaliases = true ;
o . noinactive = true ;
o . nocreate = true ;
2023-12-30 07:50:57 +00:00
o . depends ( 'vpn' , '0' ) ;
2020-03-21 12:56:29 +00:00
o = s . option ( form . Value , 'note' , _ ( 'Note' ) ) ;
o . rmempty = true ;
s = m . section ( form . GridSection , 'dpis' , _ ( 'Protocols and services' ) ) ;
s . addremove = true ;
s . anonymous = true ;
2020-07-31 07:59:50 +00:00
s . nodescriptions = true ;
2020-03-21 12:56:29 +00:00
2020-09-23 07:49:55 +00:00
o = s . option ( form . Flag , 'enabled' , _ ( 'Enabled' ) ) ;
o . default = o . enabled ;
2022-02-17 12:21:36 +00:00
o = s . option ( form . ListValue , 'proto' , _ ( 'Protocol/Service' ) ) ;
2020-03-21 12:56:29 +00:00
o . rmempty = false ;
o . load = function ( section _id ) {
return Promise . all ( [
2023-05-25 11:09:49 +00:00
L . resolveDefault ( fs . read _direct ( '/proc/net/xt_ndpi/proto' ) , '' ) ,
L . resolveDefault ( fs . read _direct ( '/proc/net/xt_ndpi/host_proto' ) , '' ) ,
fs . read _direct ( '/usr/share/omr-bypass/omr-bypass-proto.lst' )
2020-08-03 17:06:14 +00:00
] ) . then ( L . bind ( function ( filesi ) {
var proto = filesi [ 0 ] . split ( /\n/ ) ,
host = filesi [ 1 ] . split ( /\n/ ) ,
2023-05-25 11:09:49 +00:00
protofile = filesi [ 2 ] . split ( /\n/ ) ,
2020-03-21 12:56:29 +00:00
name = [ ] ;
2023-05-25 11:09:49 +00:00
if ( proto . length > 2 ) {
for ( var i = 0 ; i < proto . length ; i ++ ) {
var m = proto [ i ] . split ( /\s+/ ) ;
if ( m && m [ 0 ] != "#id" && m [ 1 ] != "disabled" )
name . push ( m [ 2 ] ) ;
}
2020-03-21 12:56:29 +00:00
}
2023-05-25 11:09:49 +00:00
if ( host . length > 2 ) {
for ( var i = 0 ; i < host . length ; i ++ ) {
var m = host [ i ] . split ( /:/ ) ;
if ( m && m [ 0 ] != "#Proto" )
name . push ( m [ 0 ] . toLowerCase ( ) ) ;
}
}
if ( proto . length == 1 && host . length == 1 ) {
for ( var i = 0 ; i < protofile . length ; i ++ ) {
var m = protofile [ i ] ;
name . push ( m ) ;
}
2020-03-21 12:56:29 +00:00
}
2020-08-03 17:10:12 +00:00
name = Array . from ( new Set ( name ) ) . sort ( function ( a , b ) { return a . toLowerCase ( ) . localeCompare ( b . toLowerCase ( ) ) } ) . reduce ( function ( a , b ) { if ( a . slice ( - 1 ) [ 0 ] !== b ) a . push ( b ) ; return a ; } , [ ] ) ;
2020-03-21 12:56:29 +00:00
for ( var i = 0 ; i < name . length ; i ++ ) {
this . value ( name [ i ] ) ;
}
return this . super ( 'load' , [ section _id ] ) ;
} , this ) ) ;
} ;
2023-12-30 07:50:57 +00:00
o = s . option ( form . Flag , 'vpn' , _ ( 'VPN on server' ) , _ ( 'Bypass using VPN configured on server.' ) ) ;
2020-10-07 09:17:26 +00:00
o = s . option ( widgets . DeviceSelect , 'interface' , _ ( 'Interface' ) , _ ( 'When none selected, MPTCP master interface is used (or an other interface if master is down).' ) ) ;
2020-05-01 09:07:25 +00:00
o . noaliases = true ;
o . noinactive = true ;
o . nocreate = true ;
2023-12-30 07:50:57 +00:00
o . depends ( 'vpn' , '0' ) ;
2020-03-21 12:56:29 +00:00
o = s . option ( form . Value , 'note' , _ ( 'Note' ) ) ;
o . rmempty = true ;
2023-05-07 06:53:12 +00:00
o = s . option ( form . ListValue , 'family' , _ ( 'Restrict to address family' ) ) ;
o . value ( 'ipv4ipv6' , _ ( 'IPv4 and IPv6' ) ) ;
o . value ( 'ipv4' , _ ( 'IPv4 only' ) ) ;
o . value ( 'ipv4' , _ ( 'IPv6 only' ) ) ;
o . default = 'ipv4ipv6' ;
o . modalonly = true
o = s . option ( form . Flag , 'noipv6' , _ ( 'Disable AAAA IPv6 DNS' ) ) ;
o . default = o . enabled ;
o . modalonly = true
2023-05-25 11:09:49 +00:00
if ( testhosts [ 0 ] ) {
o = s . option ( form . Flag , 'ndpi' , _ ( 'Enable ndpi' ) ) ;
o . default = o . enabled ;
o . modalonly = true
2023-12-30 07:50:57 +00:00
o . depends ( 'vpn' , '0' ) ;
2023-05-25 11:09:49 +00:00
}
2023-05-07 06:53:12 +00:00
2020-03-21 12:56:29 +00:00
return m . render ( ) ;
}
} ) ;