1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-13 19:11:51 +00:00
openmptcprouter-feeds/luci-app-omr-bypass/luasrc/controller/omr-bypass.lua
2018-06-29 18:26:44 +02:00

47 lines
No EOL
1.5 KiB
Lua

local ucic = luci.model.uci.cursor()
local dt = require "luci.cbi.datatypes"
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
local domains_ipset = ""
local ip_ipset = {}
for _, k in pairs(hosts) do
if k ~= "" then
if dt.ipaddr(k) then
table.insert(ip_ipset, k)
else
domains_ipset = domains_ipset .. '/' .. k
end
end
end
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}
end
ucic:set_list("omr-bypass","dpi","proto",dpi)
local interface = luci.http.formvalue("cbid.omr-bypass.interface") or ""
ucic:set("omr-bypass","defaults","ifname",interface)
ucic:save("omr-bypass")
ucic:commit("omr-bypass")
ucic:set_list("dhcp",ucic:get_first("dhcp","dnsmasq"),"ipset",domains_ipset .. "/ss_rules_dst_bypass")
ucic:save("dhcp")
ucic:commit("dhcp")
--luci.sys.exec("/etc/init.d/dnsmasq restart")
luci.sys.exec("/etc/init.d/omr-bypass restart")
luci.http.redirect(luci.dispatcher.build_url("admin/services/omr-bypass"))
return
end