mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
Choose interface used for each domains, ips, networks or protocols that bypass OMR
This commit is contained in:
parent
d1d69d8043
commit
4171d8e07a
7 changed files with 296 additions and 196 deletions
|
@ -4,48 +4,6 @@ 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"))
|
||||
--entry({"admin", "services", "omr-bypass", "index"}, template("omr-bypass/bypass"))
|
||||
entry({"admin", "services", "omr-bypass", "index"}, cbi("omr-bypass"))
|
||||
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.ipmask(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 dpi ~= "" then
|
||||
if (type(dpi) ~= "table") then
|
||||
dpi = {dpi}
|
||||
end
|
||||
ucic:set_list("omr-bypass","dpi","proto",dpi)
|
||||
else
|
||||
ucic:delete("omr-bypass","dpi","proto")
|
||||
end
|
||||
|
||||
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_all")
|
||||
ucic:save("dhcp")
|
||||
ucic:commit("dhcp")
|
||||
luci.sys.exec("/etc/init.d/dnsmasq reload")
|
||||
luci.sys.exec("/etc/init.d/omr-bypass restart")
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin/services/omr-bypass"))
|
||||
return
|
||||
end
|
72
luci-app-omr-bypass/luasrc/model/cbi/omr-bypass.lua
Normal file
72
luci-app-omr-bypass/luasrc/model/cbi/omr-bypass.lua
Normal file
|
@ -0,0 +1,72 @@
|
|||
-- Copyright 2018 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
|
||||
-- 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() }
|
||||
|
||||
m = Map("omr-bypass", translate("Bypass"))
|
||||
|
||||
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
|
||||
|
||||
s = m:section(TypedSection, "ip", translate("IPs and Networks"))
|
||||
s.addremove = true
|
||||
s.anonymous = true
|
||||
s.template = "cbi/tblsection"
|
||||
|
||||
ip = s:option(Value, "ips", translate("IP"))
|
||||
ip.datatype = "ipaddr"
|
||||
ip.rmempty = true
|
||||
ip.optional = false
|
||||
|
||||
ifi = s:option(Value, "interface", translate("Interface"))
|
||||
ifi.rmempty = true
|
||||
|
||||
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
|
||||
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))
|
||||
end
|
||||
|
||||
ifp = s:option(ListValue, "interface", translate("Interface"))
|
||||
ifp.rmempty = true
|
||||
|
||||
ifd.default = "all"
|
||||
ifi.default = "all"
|
||||
ifp.default = "all"
|
||||
ifd:value("all",translate("Master interface"))
|
||||
ifi:value("all",translate("Master interface"))
|
||||
ifp:value("all",translate("Master interface"))
|
||||
for _, iface in ipairs(ifaces) do
|
||||
ifd:value(iface:name(),"%s" % iface:name())
|
||||
ifi:value(iface:name(),"%s" % iface:name())
|
||||
ifp:value(iface:name(),"%s" % iface:name())
|
||||
end
|
||||
|
||||
return m
|
|
@ -1,6 +1,6 @@
|
|||
<%+header%>
|
||||
|
||||
<script type="text/javascript" src="<%=resource%>/cbi.js" data-strings="{"path":{"resource":"\/luci-static\/resources","browser":"\/cgi-bin\/luci\/admin\/filebrowser"}}"></script>
|
||||
<script type="text/javascript" src="<%=resource%>/cbi.js?v=git-18.274.67584-38176e6" data-strings="{"path":{"resource":"\/luci-static\/resources","browser":"\/cgi-bin\/luci\/admin\/filebrowser"}}"></script>
|
||||
|
||||
<%
|
||||
local uci = require("luci.model.uci").cursor()
|
||||
|
@ -17,114 +17,82 @@
|
|||
<form class="inline" method="post" action="<%=url('admin/services/omr-bypass/add')%>">
|
||||
<div class="cbi-map">
|
||||
<h2 name="content"><%:Bypass%></h2>
|
||||
<fieldset class="cbi-section" id="hosts">
|
||||
<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"><%: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
|
||||
j = j+1
|
||||
for hst in string.gmatch(host,"([^/]*)/") do
|
||||
if hst ~= "" then
|
||||
%>
|
||||
<input class="cbi-input-text" value="<%=hst%>" data-update="change" type="text" id="cbid.omr-bypass.hosts.<%=j%>" name="cbid.omr-bypass.hosts" placeholder="google.com" />
|
||||
<br />
|
||||
<%
|
||||
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 />
|
||||
</div>
|
||||
<div class="cbi-value-description">
|
||||
<%:You need to use OpenMPTCProuter as DNS server when you want to bypass a domain%>
|
||||
</div>
|
||||
<%
|
||||
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 />
|
||||
</div>
|
||||
<div class="cbi-value-description">
|
||||
<%:You need to use OpenMPTCProuter as DNS server when you want to bypass a domain%>
|
||||
</div>
|
||||
<%
|
||||
end
|
||||
%>
|
||||
<div class="cbi-section cbi-tblsection" id="cbi-omr-bypass-domains">
|
||||
<h3><%:Domains, ips or networks%></h3>
|
||||
<div class="cbi-section-descr"></div>
|
||||
<div class="table cbi-section-table">
|
||||
<div class="tr cbi-section-table-titles-anonymous">
|
||||
<div class="th cbi-section-table-cell" data-type="value"><%:Domain, IP or network%></div>
|
||||
<div class="th cbi-section-table-cell" data-type="value"><%:Output interface%></div>
|
||||
<div class="th cbi-section-table-cell cbi-section-actions"></div>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset class="cbi-section" id="dpi">
|
||||
<div class="cbi-section-descr"><%:Set protocols you want to bypass.%></div>
|
||||
<div class="cbi-value cbi-value-last" id="cbi-omr-tracker-dpi" data-depends="[]" data-index="<%=table.getn(dpi)%>">
|
||||
<label class="cbi-value-title" for="cbid.omr-tracker.dpi"><%:Protocol%></label>
|
||||
<div class="cbi-value-field">
|
||||
<%
|
||||
local allprt=""""
|
||||
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
|
||||
<div class="tr cbi-section-table-row" id="cbi-omr-bypass-cfg">
|
||||
<div class="td cbi-value-field" data-name="name" data-type="value" data-title="Domain">
|
||||
<div id="cbi-omr-bypass-cfg-domain" data-index="" data-depends="[]">
|
||||
<input data-update="change" id="cbid.omr.bypass.cfg.domain"" name="cbid.omr.bypass.cfg.domain" type="text" class="cbi-input-text" value="" data-optional="true" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="td cbi-value-field" data-name="interface" data-type="value" data-title="<%:Interface%>">
|
||||
<select class="cbi-input-select" data-update="change" id="cbid.omr.bypass.cfg.interface" name="cbid.omr.bypass.cfg.interface" size="1">
|
||||
<option id="cbid.omr.bypass.cfg.interface-all" value="all" data-index="1" data-depends="[]"><%:All%></option>
|
||||
<%
|
||||
for _, iface in ipairs(ifaces) do
|
||||
if not (iface == "lo" or iface:match("^ifb.*")) then
|
||||
%>
|
||||
<option value="<%=iface%>"><%=iface%></option>
|
||||
<%
|
||||
end
|
||||
table.sort(protos)
|
||||
for _,b in ipairs(protos) do
|
||||
allprt=allprt .. ","" .. b .. """
|
||||
end
|
||||
%>
|
||||
|
||||
|
||||
<div data-prefix="cbid.omr-bypass.dpi" data-browser-path="" data-dynlist="[[<%=allprt%>],[<%=allprt%>],null,false]">
|
||||
<%
|
||||
local k = 1
|
||||
for _ , proto in pairs(dpi) do
|
||||
k = k+1
|
||||
%>
|
||||
<input class="cbi-input-text" id="cbid.omr-bypass.dpi.<%=k%>" name="cbid.omr-bypass.dpi" data-update="change" value="<%=proto%>" /><br />
|
||||
<%
|
||||
end
|
||||
if k == 1 then
|
||||
%>
|
||||
<input class="cbi-input-text" id="cbid.omr-bypass.dpi.<%=k%>" name="cbid.omr-bypass.dpi" data-update="change" /><br />
|
||||
<%
|
||||
end
|
||||
%>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<div class="cbi-section-descr"><%:Set interface you want to use for bypassed traffic.%></div>
|
||||
<div class="cbi-value">
|
||||
<label class="cbi-value-title">Interface</label>
|
||||
<div class="cbi-value-field">
|
||||
<select class="cbi-input-select" name="cbid.omr-bypass.interface" size="1">
|
||||
<option value="" <% if iface == bypassif then %>selected="selected"<% end %>><%=iface%></option>
|
||||
<%
|
||||
for _, iface in ipairs(ifaces) do
|
||||
if not (iface == "lo" or iface:match("^ifb.*")) then
|
||||
%>
|
||||
<option value="<%=iface%>" <% if iface == bypassif then %>selected="selected"<% end %>><%=iface%></option>
|
||||
<%
|
||||
end
|
||||
end
|
||||
%>
|
||||
</select>
|
||||
<br />
|
||||
<div class="cbi-value-description">
|
||||
<%:If empty, multipath master interface is used if up else any other up interface.%>
|
||||
end
|
||||
%>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="cbi-section-create cbi-tblsection-create">
|
||||
<input class="cbi-button cbi-button-add" type="submit" value="Add" name="cbi.cts.omr.bypass.domains" title="<%:Add%>" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="cbi-section cbi-tblsection" id="cbi-omr-bypass-proto">
|
||||
<h3><%:Protocols%></h3>
|
||||
<div class="cbi-section-descr"></div>
|
||||
<div class="table cbi-section-table">
|
||||
<div class="tr cbi-section-table-titles-anonymous">
|
||||
<div class="th cbi-section-table-cell" data-type="value"><%:Protocols%></div>
|
||||
<div class="th cbi-section-table-cell" data-type="value"><%:Output interface%></div>
|
||||
<div class="th cbi-section-table-cell cbi-section-actions"></div>
|
||||
</div>
|
||||
<div class="tr cbi-section-table-row" id="cbi-omr-bypass-cfg">
|
||||
<div class="td cbi-value-field" data-name="name" data-type="value" data-title="Domain">
|
||||
<%
|
||||
local allprt=""""
|
||||
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
|
||||
allprt=allprt .. ","" .. b .. """
|
||||
end
|
||||
%>
|
||||
<div data-prefix="cbid.omr.bypass.cfg.proto" data-browser-path="" data-dynlist="[[<%=allprt%>],[<%=allprt%>],null,false]">
|
||||
<div id="cbi-omr-bypass-cfg-proto" data-index="" data-depends="[]">
|
||||
<input data-update="change" id="cbid.omr.bypass.cfg.proto" name="cbid.omr.bypass.cfg.proto" type="text" class="cbi-input-text" value="" data-optional="true" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="td cbi-value-field" data-name="interface" data-type="value" data-title="<%:Interface%>">
|
||||
<select class="cbi-input-select" data-update="change" id="cbid.omr.bypass.cfg.interface" name="cbid.omr.bypass.cfg.interface" size="1">
|
||||
<option id="cbid.omr.bypass.cfg.interface-all" value="all" data-index="1" data-depends="[]"><%:All%></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cbi-section-create cbi-tblsection-create">
|
||||
<input class="cbi-button cbi-button-add" type="submit" value="Add" name="cbi.cts.omr.bypass.domains" title="<%:Add%>" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cbi-page-actions">
|
||||
<input type="hidden" name="token" value="<%=token%>" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue