2019-01-26 12:50:03 +00:00
-- Copyright 2018-2019 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
2018-10-05 15:13:38 +00:00
-- Licensed to the public under the Apache License 2.0.
local ipc = require " luci.ip "
local sys = require " luci.sys "
local net = require " luci.model.network " . init ( )
local ifaces = net : get_interfaces ( ) or { net : get_interface ( ) }
2018-10-15 13:11:04 +00:00
m = Map ( " omr-bypass " , translate ( " Bypass " ) , translate ( " Here you can bypass ShadowSocks and VPN. If you set Interface to Default this use any working interface. " ) )
2018-10-05 15:13:38 +00:00
s = m : section ( TypedSection , " domains " , translate ( " Domains " ) )
s.addremove = true
s.anonymous = true
s.template = " cbi/tblsection "
hn = s : option ( Value , " name " , translate ( " Domain " ) )
hn.datatype = " hostname "
hn.optional = false
hn.rmempty = true
ifd = s : option ( Value , " interface " , translate ( " Interface " ) )
ifd.rmempty = true
2018-11-02 19:19:50 +00:00
s = m : section ( TypedSection , " ips " , translate ( " IPs and Networks " ) )
2018-10-05 15:13:38 +00:00
s.addremove = true
s.anonymous = true
s.template = " cbi/tblsection "
2018-11-02 19:19:50 +00:00
ip = s : option ( Value , " ip " , translate ( " IP " ) )
2018-10-05 15:13:38 +00:00
ip.datatype = " ipaddr "
ip.rmempty = true
ip.optional = false
ifi = s : option ( Value , " interface " , translate ( " Interface " ) )
ifi.rmempty = true
2018-11-02 19:19:50 +00:00
s = m : section ( TypedSection , " macs " , translate ( " <abbr title= \" Media Access Control \" >MAC</abbr>-Address " ) )
s.addremove = true
s.anonymous = true
s.template = " cbi/tblsection "
2018-11-15 14:35:02 +00:00
mac = s : option ( Value , " mac " , translate ( " Source MAC-Address " ) )
2018-11-02 19:19:50 +00:00
mac.datatype = " list(macaddr) "
mac.rmempty = true
mac.optional = false
sys.net . host_hints ( function ( m , v4 , v6 , name )
if m then
mac : value ( m , " %s (%s) " % { m , name or v4 or v6 } )
end
end )
ifm = s : option ( Value , " interface " , translate ( " Interface " ) )
ifm.rmempty = true
2019-03-11 18:36:14 +00:00
s = m : section ( TypedSection , " lan_ip " , translate ( " Source lan IP address or network " ) )
2018-11-15 14:35:02 +00:00
s.addremove = true
s.anonymous = true
s.template = " cbi/tblsection "
ip = s : option ( Value , " ip " , translate ( " IP Address " ) )
ip.datatype = " ipaddr "
ip.rmempty = true
ip.optional = false
2018-11-30 18:52:09 +00:00
ifl = s : option ( Value , " interface " , translate ( " Interface " ) )
ifl.rmempty = true
2018-11-15 14:35:02 +00:00
2019-01-06 07:43:07 +00:00
s = m : section ( TypedSection , " asns " , translate ( " <abbr tittle= \" Autonomous System Number \" >ASN</abbr> " ) )
2019-01-03 19:41:43 +00:00
s.addremove = true
s.anonymous = true
s.template = " cbi/tblsection "
asn = s : option ( Value , " asn " , translate ( " ASN " ) )
asn.rmempty = true
asn.optional = false
ifa = s : option ( Value , " interface " , translate ( " Interface " ) )
ifa.rmempty = true
2018-10-05 15:13:38 +00:00
s = m : section ( TypedSection , " dpis " , translate ( " Protocols " ) )
s.addremove = true
s.anonymous = true
s.template = " cbi/tblsection "
dpi = s : option ( Value , " proto " , translate ( " Protocol " ) )
dpi.rmempty = true
dpi.optional = false
2019-01-26 12:50:03 +00:00
local xt_ndpi_available = nixio.fs . access ( " /proc/net/xt_ndpi/proto " )
if xt_ndpi_available then
local protos = { }
for l in io.lines ( " /proc/net/xt_ndpi/proto " ) do
local a , b , c , d = l : match ( ' (%w+) (%w+) ' )
if b ~= " 2 " and not string.match ( b , " custom " ) then
table.insert ( protos , b )
end
end
table.sort ( protos )
for _ , b in ipairs ( protos ) do
dpi : value ( b , " %s " % tostring ( b ) )
2018-10-05 15:13:38 +00:00
end
end
ifp = s : option ( ListValue , " interface " , translate ( " Interface " ) )
ifp.rmempty = true
ifd.default = " all "
ifi.default = " all "
ifp.default = " all "
2018-11-02 19:19:50 +00:00
ifm.default = " all "
2018-11-30 18:52:09 +00:00
ifl.default = " all "
2019-01-03 19:41:43 +00:00
ifa.default = " all "
2018-10-15 13:11:04 +00:00
ifd : value ( " all " , translate ( " Default " ) )
ifi : value ( " all " , translate ( " Default " ) )
ifp : value ( " all " , translate ( " Default " ) )
2018-11-02 19:19:50 +00:00
ifm : value ( " all " , translate ( " Default " ) )
2018-11-30 18:52:09 +00:00
ifl : value ( " all " , translate ( " Default " ) )
2019-01-03 19:41:43 +00:00
ifa : value ( " all " , translate ( " Default " ) )
2018-10-05 15:13:38 +00:00
for _ , iface in ipairs ( ifaces ) do
2018-10-15 13:11:04 +00:00
if iface : is_up ( ) then
ifd : value ( iface : name ( ) , " %s " % iface : name ( ) )
ifi : value ( iface : name ( ) , " %s " % iface : name ( ) )
ifp : value ( iface : name ( ) , " %s " % iface : name ( ) )
2018-11-02 19:19:50 +00:00
ifm : value ( iface : name ( ) , " %s " % iface : name ( ) )
2019-01-03 19:41:43 +00:00
ifl : value ( iface : name ( ) , " %s " % iface : name ( ) )
ifa : value ( iface : name ( ) , " %s " % iface : name ( ) )
2018-10-15 13:11:04 +00:00
end
2018-10-05 15:13:38 +00:00
end
return m