1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00

Add bypass IPs and network support

This commit is contained in:
Ycarus 2018-05-15 17:20:49 +02:00
parent 1bdb327224
commit 602aa8a127
7 changed files with 83 additions and 16 deletions

View file

@ -1,4 +1,5 @@
local ucic = luci.model.uci.cursor()
local dt = require "luci.cbi.datatypes"
module("luci.controller.omr-bypass", package.seeall)
function index()
@ -12,16 +13,29 @@ function bypass_add()
if (type(hosts) ~= "table") then
hosts = {hosts}
end
local ipset = ""
local domains_ipset = ""
local ip_ipset = {}
for _, k in pairs(hosts) do
if k ~= "" then
ipset = ipset .. '/' .. k
if dt.ipaddr(k) then
table.insert(ip_ipset, k)
else
domains_ipset = domains_ipset .. '/' .. k
end
end
end
ucic:set_list("dhcp",ucic:get_first("dhcp","dnsmasq"),"ipset",ipset .. "/ss_rules_dst_bypass")
ucic:delete("omr-bypass","ips","ip")
if table.getn(ip_ipset) > 0 then
for _, i in pairs(ip_ipset) do
ucic:set_list("omr-bypass","ips","ip",ip_ipset)
end
end
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/dnsmasq restart")
luci.http.redirect(luci.dispatcher.build_url("admin/services/omr-bypass"))
return
end

View file

@ -5,6 +5,7 @@
<%
local uci = require("luci.model.uci").cursor()
local hosts = uci:get_list("dhcp", uci:get_first("dhcp","dnsmasq"), "ipset")
local ips = uci:get_list("omr-bypass", "ips", "ip")
%>
<% if stderr and #stderr > 0 then %><pre class="error"><%=pcdata(stderr)%></pre><% end %>
@ -12,15 +13,14 @@
<div class="cbi-map">
<h2 name="content"><%:Bypass%></h2>
<fieldset class="cbi-section" id="hosts">
<div class="cbi-section-descr"><%:Set domains name you want to bypass.%></div>
<div class="cbi-section-descr"><%:Set domains name, ips or networks you want to bypass.%></div>
<div class="cbi-value cbi-value-last" id="cbi-omr-tracker-hosts" data-depends="[]" data-index="<%=table.getn(hosts)%>">
<label class="cbi-value-title" for="cbid.omr-tracker.hosts"><%:Domains%></label>
<label class="cbi-value-title" for="cbid.omr-tracker.hosts"><%:Domain, IP or network%></label>
<div class="cbi-value-field">
<div data-prefix="cbid.omr-bypass.hosts" data-browser-path="" data-dynlist="[[],[],null,false]" data-placeholder="google.com">
<%
local j = 1
for _ , host in pairs(hosts) do
%><%=host%><%
j = j+1
for hst in string.gmatch(host,"([^/]*)/") do
if hst ~= "" then
@ -30,6 +30,12 @@
end
end
end
for _ , ip in pairs(ips) do
j = j+1
%>
<input class="cbi-input-text" value="<%=ip%>" data-update="change" type="text" id="cbid.omr-bypass.hosts.<%=j%>" name="cbid.omr-bypass.hosts" placeholder="google.com" /><br />
<%
end
if j == 1 then
%>
<input class="cbi-input-text" value="" data-update="change" type="text" id="cbid.omr-bypass.hosts.1" name="cbid.omr-bypass.hosts" placeholder="google.com" /><br />