2018-05-09 14:08:52 +00:00
|
|
|
local ucic = luci.model.uci.cursor()
|
2018-05-15 15:20:49 +00:00
|
|
|
local dt = require "luci.cbi.datatypes"
|
2018-04-07 20:13:33 +00:00
|
|
|
module("luci.controller.omr-bypass", package.seeall)
|
|
|
|
|
|
|
|
function index()
|
|
|
|
entry({"admin", "services", "omr-bypass"}, alias("admin", "services", "omr-bypass", "index"), _("OMR-Bypass"))
|
|
|
|
entry({"admin", "services", "omr-bypass", "index"}, template("omr-bypass/bypass"))
|
|
|
|
entry({"admin", "services", "omr-bypass", "add"}, post("bypass_add"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function bypass_add()
|
|
|
|
local hosts = luci.http.formvalue("cbid.omr-bypass.hosts")
|
|
|
|
if (type(hosts) ~= "table") then
|
|
|
|
hosts = {hosts}
|
|
|
|
end
|
2018-05-15 15:20:49 +00:00
|
|
|
local domains_ipset = ""
|
|
|
|
local ip_ipset = {}
|
2018-04-07 20:13:33 +00:00
|
|
|
for _, k in pairs(hosts) do
|
|
|
|
if k ~= "" then
|
2018-05-15 15:20:49 +00:00
|
|
|
if dt.ipaddr(k) then
|
|
|
|
table.insert(ip_ipset, k)
|
|
|
|
else
|
|
|
|
domains_ipset = domains_ipset .. '/' .. k
|
|
|
|
end
|
2018-04-07 20:13:33 +00:00
|
|
|
end
|
|
|
|
end
|
2018-06-22 08:50:17 +00:00
|
|
|
ucic:set_list("omr-bypass","ips","ip",ip_ipset)
|
|
|
|
|
|
|
|
local dpi = luci.http.formvalue("cbid.omr-bypass.dpi")
|
|
|
|
if (type(dpi) ~= "table") then
|
|
|
|
dpi = {dpi}
|
2018-05-15 15:20:49 +00:00
|
|
|
end
|
2018-06-22 08:50:17 +00:00
|
|
|
ucic:set_list("omr-bypass","dpi","proto",dpi)
|
2018-06-29 16:26:44 +00:00
|
|
|
|
|
|
|
local interface = luci.http.formvalue("cbid.omr-bypass.interface") or ""
|
|
|
|
ucic:set("omr-bypass","defaults","ifname",interface)
|
2018-06-22 08:50:17 +00:00
|
|
|
|
2018-05-15 15:20:49 +00:00
|
|
|
ucic:save("omr-bypass")
|
|
|
|
ucic:commit("omr-bypass")
|
|
|
|
ucic:set_list("dhcp",ucic:get_first("dhcp","dnsmasq"),"ipset",domains_ipset .. "/ss_rules_dst_bypass")
|
2018-04-07 20:13:33 +00:00
|
|
|
ucic:save("dhcp")
|
|
|
|
ucic:commit("dhcp")
|
2018-05-15 15:20:49 +00:00
|
|
|
--luci.sys.exec("/etc/init.d/dnsmasq restart")
|
2018-06-22 08:50:17 +00:00
|
|
|
luci.sys.exec("/etc/init.d/omr-bypass restart")
|
2018-04-07 20:13:33 +00:00
|
|
|
luci.http.redirect(luci.dispatcher.build_url("admin/services/omr-bypass"))
|
|
|
|
return
|
|
|
|
end
|