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

Change in luci-app-openmptcprouter to use device setting

This commit is contained in:
Ycarus (Yannick Chabanois) 2021-06-25 19:42:03 +02:00
parent 04b15901fa
commit 72f5756eb5
4 changed files with 58 additions and 23 deletions

View file

@ -26,7 +26,11 @@ end
function interface_from_device(dev) function interface_from_device(dev)
for _, iface in ipairs(net:get_networks()) do for _, iface in ipairs(net:get_networks()) do
local ifacen = iface:name() local ifacen = iface:name()
local ifacename = ucic:get("network",ifacen,"ifname") local ifacename = ""
ifacename = ucic:get("network",ifacen,"device")
if ifacename == "" then
ifacename = ucic:get("network",ifacen,"ifname")
end
if ifacename == dev then if ifacename == dev then
return ifacen return ifacen
end end
@ -113,7 +117,10 @@ function wizard_add()
end) end)
local defif = "eth0" local defif = "eth0"
if add_interface_ifname == "" then if add_interface_ifname == "" then
local defif1 = ucic:get("network","wan1_dev","ifname") or "" local defif1 = ucic:get("network","wan1_dev","device") or ""
if defif1 == "" then
defif1 = ucic:get("network","wan1_dev","ifname") or ""
end
if defif1 ~= "" then if defif1 ~= "" then
defif = defif1 defif = defif1
end end
@ -126,17 +133,29 @@ function wizard_add()
if ointf ~= "" then if ointf ~= "" then
if ucic:get("network",ointf,"type") == "" then if ucic:get("network",ointf,"type") == "" then
ucic:set("network",ointf,"type","macvlan") ucic:set("network",ointf,"type","macvlan")
ucic:set("network",ointf,"device",ointf)
ucic:set("network",ointf .. "_dev","device")
ucic:set("network",ointf .. "_dev","type","macvlan")
ucic:set("network",ointf .. "_dev","mode","vepa")
ucic:set("network",ointf .. "_dev","ifname",defif)
ucic:set("network",ointf .. "_dev","name",ointf)
end end
wanif = "wan" .. i wanif = "wan" .. i
end end
ucic:set("network","wan" .. i,"interface") ucic:set("network","wan" .. i,"interface")
ucic:set("network","wan" .. i,"ifname",defif) ucic:set("network","wan" .. i,"device",defif)
ucic:set("network","wan" .. i,"proto","static") ucic:set("network","wan" .. i,"proto","static")
ucic:set("openmptcprouter","wan" .. i,"interface") ucic:set("openmptcprouter","wan" .. i,"interface")
if ointf ~= "" then if ointf ~= "" then
ucic:set("network","wan" .. i,"type","macvlan") ucic:set("network","wan" .. i,"type","macvlan")
ucic:set("network","wan" .. i,"device","wan" .. i)
ucic:set("network","wan" .. i,"masterintf",defif) ucic:set("network","wan" .. i,"masterintf",defif)
ucic:set("network","wan" .. i .. "_dev","device")
ucic:set("network","wan" .. i .. "_dev","type","macvlan")
ucic:set("network","wan" .. i .. "_dev","mode","vepa")
ucic:set("network","wan" .. i .. "_dev","ifname",defif)
ucic:set("network","wan" .. i .. "_dev","name","wan" .. i)
end end
ucic:set("network","wan" .. i,"ip4table","wan") ucic:set("network","wan" .. i,"ip4table","wan")
if multipath_master then if multipath_master then
@ -197,7 +216,10 @@ function wizard_add()
local delete_intf = luci.http.formvaluetable("delete") or "" local delete_intf = luci.http.formvaluetable("delete") or ""
if delete_intf ~= "" then if delete_intf ~= "" then
for intf, _ in pairs(delete_intf) do for intf, _ in pairs(delete_intf) do
local defif = ucic:get("network",intf,"ifname") local defif = ucic:get("network",intf,"ifname") or ""
if defif == "" then
defif = ucic:get("network",intf,"ifname")
end
ucic:delete("network",intf) ucic:delete("network",intf)
if ucic:get("network",intf .. "_dev") ~= "" then if ucic:get("network",intf .. "_dev") ~= "" then
ucic:delete("network",intf .. "_dev") ucic:delete("network",intf .. "_dev")
@ -262,9 +284,14 @@ function wizard_add()
end end
if typeintf == "macvlan" and masterintf ~= "" then if typeintf == "macvlan" and masterintf ~= "" then
ucic:set("network",intf,"type","macvlan") ucic:set("network",intf,"type","macvlan")
ucic:set("network",intf .. "_dev","device")
ucic:set("network",intf .. "_dev","type","macvlan")
ucic:set("network",intf .. "_dev","ifname",masterinf)
ucic:set("network",intf .. "_dev","mode","vepa")
ucic:set("network",intf .. "_dev","name",intf)
ucic:set("network",intf,"masterintf",masterintf) ucic:set("network",intf,"masterintf",masterintf)
elseif typeintf == "" and ifname ~= "" and (proto == "static" or proto == "dhcp" or proto == "dhcpv6") then elseif typeintf == "" and ifname ~= "" and (proto == "static" or proto == "dhcp" or proto == "dhcpv6") then
ucic:set("network",intf,"ifname",ifname) ucic:set("network",intf,"device",ifname)
elseif typeintf == "" and device ~= "" and proto == "ncm" then elseif typeintf == "" and device ~= "" and proto == "ncm" then
ucic:set("network",intf,"device",device_ncm) ucic:set("network",intf,"device",device_ncm)
elseif typeintf == "" and device ~= "" and proto == "qmi" then elseif typeintf == "" and device ~= "" and proto == "qmi" then
@ -342,7 +369,10 @@ function wizard_add()
if not ucic:get("sqm",intf) ~= "" then if not ucic:get("sqm",intf) ~= "" then
local defif = get_device(intf) local defif = get_device(intf)
if defif == "" then if defif == "" then
defif = ucic:get("network",intf,"ifname") or "" defif = ucic:get("network",intf,"device") or ""
if defif == "" then
defif = ucic:get("network",intf,"ifname") or ""
end
end end
ucic:set("sqm",intf,"queue") ucic:set("sqm",intf,"queue")
ucic:set("sqm",intf,"interface",defif) ucic:set("sqm",intf,"interface",defif)
@ -442,7 +472,7 @@ function wizard_add()
ucic:set("network","omrvpn","proto","bonding") ucic:set("network","omrvpn","proto","bonding")
end end
if vpn_intf ~= "" then if vpn_intf ~= "" then
ucic:set("network","omrvpn","ifname",vpn_intf) ucic:set("network","omrvpn","device",vpn_intf)
ucic:set("sqm","omrvpn","interface",vpn_intf) ucic:set("sqm","omrvpn","interface",vpn_intf)
ucic:save("network") ucic:save("network")
ucic:commit("network") ucic:commit("network")
@ -894,7 +924,7 @@ function wizard_add()
-- Restart all -- Restart all
menuentry = ucic:get("openmptcprouter","settings","menu") or "openmptcprouter" menuentry = ucic:get("openmptcprouter","settings","menu") or "openmptcprouter"
if gostatus == true then if gostatus == true then
luci.sys.call("/etc/init.d/macvlan restart >/dev/null 2>/dev/null") --luci.sys.call("/etc/init.d/macvlan restart >/dev/null 2>/dev/null")
luci.sys.call("(env -i /bin/ubus call network reload) >/dev/null 2>/dev/null") luci.sys.call("(env -i /bin/ubus call network reload) >/dev/null 2>/dev/null")
luci.sys.call("ip addr flush dev tun0 >/dev/null 2>/dev/null") luci.sys.call("ip addr flush dev tun0 >/dev/null 2>/dev/null")
luci.sys.call("/etc/init.d/omr-tracker stop >/dev/null 2>/dev/null") luci.sys.call("/etc/init.d/omr-tracker stop >/dev/null 2>/dev/null")

View file

@ -473,7 +473,7 @@
if not (ifacea == "lo" or ifacea == "6in4-omr6in4" or ifacea == "mlvpn0" or ifacea:match("^ifb.*") or ifacea:match("^sit.*") or ifacea:match("^gre.*") or ifacea:match("^ip6.*") or ifacea:match("^teql.*") or ifacea:match("^erspan.*") or ifacea:match("^tun.*") or ifacea:match("^bond.*")) and device_notvirtual(ifacea) then if not (ifacea == "lo" or ifacea == "6in4-omr6in4" or ifacea == "mlvpn0" or ifacea:match("^ifb.*") or ifacea:match("^sit.*") or ifacea:match("^gre.*") or ifacea:match("^ip6.*") or ifacea:match("^teql.*") or ifacea:match("^erspan.*") or ifacea:match("^tun.*") or ifacea:match("^bond.*")) and device_notvirtual(ifacea) then
if uci:get("network",ifname,"proto") ~= "macvlan" then if uci:get("network",ifname,"proto") ~= "macvlan" then
%> %>
<option value="<%=ifacea%>"<% if uci:get("network",ifname,"ifname") == ifacea then iffind = 1 %> selected="selected"<% end %>><%=ifacea%></option> <option value="<%=ifacea%>"<% if uci:get("network",ifname,"device") == ifacea then iffind = 1 %> selected="selected"<% end %>><%=ifacea%></option>
<% <%
else else
%> %>
@ -483,9 +483,9 @@
end end
end end
if uci:get("network",ifname,"proto") ~= "macvlan" then if uci:get("network",ifname,"proto") ~= "macvlan" then
if iffind == 0 and uci:get("network",ifname,"ifname") ~= nil then if iffind == 0 and uci:get("network",ifname,"device") ~= nil then
%> %>
<option value="<%=uci:get("network",ifname,"ifname")%>" selected="selected"><%=uci:get("network",ifname,"ifname")%></option> <option value="<%=uci:get("network",ifname,"device")%>" selected="selected"><%=uci:get("network",ifname,"device")%></option>
<% <%
end end
else else
@ -616,7 +616,7 @@
<select class="cbi-input-select" data-update="change" id="cbid.network.<%=ifname%>.intf" name="cbid.network.<%=ifname%>.intf" size="1"> <select class="cbi-input-select" data-update="change" id="cbid.network.<%=ifname%>.intf" name="cbid.network.<%=ifname%>.intf" size="1">
<% <%
iffind=0 iffind=0
uciifname=uci:get("network",ifname,"ifname") uciifname=uci:get("network",ifname,"device")
if uciifname ~= nil then if uciifname ~= nil then
if uciifname:match("/") then if uciifname:match("/") then
realifname=uciifname realifname=uciifname

View file

@ -18,7 +18,8 @@ omr_intf_check() {
omr_intf_set() { omr_intf_set() {
local device local device
local ifname local ifname
config_get ifname "$1" ifname config_get ifname "$1" device
[ -z "$ifname" ] && config_get ifname "$1" ifname
config_get device "$1" device config_get device "$1" device
config_get type "$1" type config_get type "$1" type
@ -56,7 +57,8 @@ omr_set_settings() {
local ifname local ifname
local multipath local multipath
config_get multipath "$1" multipath config_get multipath "$1" multipath
config_get ifname "$1" ifname config_get ifname "$1" device
[ -z "$ifname" ] && config_get ifname "$1" ifname
config_get device "$1" device config_get device "$1" device
config_get proto "$1" proto config_get proto "$1" proto
config_get type "$1" type config_get type "$1" type

View file

@ -11,7 +11,7 @@ local jsonc = require "luci.jsonc"
function interface_from_device(dev) function interface_from_device(dev)
for _, iface in ipairs(net:get_networks()) do for _, iface in ipairs(net:get_networks()) do
local ifacen = iface:name() local ifacen = iface:name()
local ifacename = ucic:get("network",ifacen,"ifname") local ifacename = ucic:get("network",ifacen,"device")
if ifacename == dev then if ifacename == dev then
return ifacen return ifacen
end end
@ -72,7 +72,7 @@ function add_interface(add_interface_ifname)
end end
ucic:set("network","wan" .. i,"interface") ucic:set("network","wan" .. i,"interface")
ucic:set("network","wan" .. i,"ifname",defif) ucic:set("network","wan" .. i,"device",defif)
ucic:set("network","wan" .. i,"proto","static") ucic:set("network","wan" .. i,"proto","static")
if ointf ~= "" then if ointf ~= "" then
ucic:set("network","wan" .. i,"type","macvlan") ucic:set("network","wan" .. i,"type","macvlan")
@ -128,7 +128,7 @@ end
function remove_interface(intf) function remove_interface(intf)
-- Remove existing interface -- Remove existing interface
local defif = ucic:get("network",intf,"ifname") local defif = ucic:get("network",intf,"device")
ucic:delete("network",intf) ucic:delete("network",intf)
ucic:delete("network",intf .. "_dev") ucic:delete("network",intf .. "_dev")
ucic:save("network") ucic:save("network")
@ -170,7 +170,7 @@ function set_interface(intf,proto,ipaddr,netmask,gateway,sqmenabled,downloadspee
if not ucic:get("sqm",intf) ~= "" then if not ucic:get("sqm",intf) ~= "" then
local defif = get_device(intf) local defif = get_device(intf)
if defif == "" then if defif == "" then
defif = ucic:get("network",intf,"ifname") or "" defif = ucic:get("network",intf,"device") or ""
end end
ucic:set("sqm",intf,"queue") ucic:set("sqm",intf,"queue")
ucic:set("sqm",intf,"interface",defif) ucic:set("sqm",intf,"interface",defif)
@ -268,7 +268,7 @@ function default_vpn(default_vpn)
ucic:set("network","omrvpn","proto","dhcp") ucic:set("network","omrvpn","proto","dhcp")
end end
if vpn_intf ~= "" then if vpn_intf ~= "" then
ucic:set("network","omrvpn","ifname",vpn_intf) ucic:set("network","omrvpn","device",vpn_intf)
ucic:save("network") ucic:save("network")
ucic:commit("network") ucic:commit("network")
end end
@ -961,7 +961,10 @@ function interfaces_status()
if string.find(sys.exec("/usr/bin/pgrep '^(/usr/sbin/)?glorytun(-udp)?$'"), "%d+") or string.find(sys.exec("/usr/bin/pgrep '^(/usr/sbin/)?dsvpn?$'"), "%d+") or string.find(sys.exec("/usr/bin/pgrep '^(/usr/sbin/)?mlvpn?$'"), "%d+") or string.find(sys.exec("/usr/bin/pgrep '^(/usr/sbin/)?openvpn?$'"), "%d+") then if string.find(sys.exec("/usr/bin/pgrep '^(/usr/sbin/)?glorytun(-udp)?$'"), "%d+") or string.find(sys.exec("/usr/bin/pgrep '^(/usr/sbin/)?dsvpn?$'"), "%d+") or string.find(sys.exec("/usr/bin/pgrep '^(/usr/sbin/)?mlvpn?$'"), "%d+") or string.find(sys.exec("/usr/bin/pgrep '^(/usr/sbin/)?openvpn?$'"), "%d+") then
mArray.openmptcprouter["tun_service"] = true mArray.openmptcprouter["tun_service"] = true
mArray.openmptcprouter["tun_ip"] = get_ip("omrvpn") mArray.openmptcprouter["tun_ip"] = get_ip("omrvpn")
local tun_dev = uci:get("network","omrvpn","ifname") local tun_dev = uci:get("network","omrvpn","device")
if tun_dev == "" then
tun_dev = uci:get("network","omrvpn","ifname")
end
if tun_dev == "" then if tun_dev == "" then
tun_dev = get_device("omrvpn") tun_dev = get_device("omrvpn")
end end
@ -1139,14 +1142,14 @@ function interfaces_status()
local ifname = get_device(interface) local ifname = get_device(interface)
if ifname == "" or ifname == nil then if ifname == "" or ifname == nil then
ifname = section["ifname"] or "" ifname = section["device"] or ""
end end
--if ifname ~= nil and ifname:match("^tun.*") and interface:match("^ovpn.*") then --if ifname ~= nil and ifname:match("^tun.*") and interface:match("^ovpn.*") then
--ifname = get_device(interface:sub(5)) --ifname = get_device(interface:sub(5))
--end --end
duplicateif = false duplicateif = false
if ifname ~= "" and ifname ~= nil and not (section["ifname"] ~= nil and section["ifname"]:match("^@.*")) then if ifname ~= "" and ifname ~= nil and not (section["device"] ~= nil and section["device"]:match("^@.*")) then
if allintf[ifname] then if allintf[ifname] then
connectivity = "ERROR" connectivity = "ERROR"
duplicateif = true duplicateif = true
@ -1156,7 +1159,7 @@ function interfaces_status()
end end
duplicatemac = false duplicatemac = false
if mac ~= "" and mac ~= nil and not (section["ifname"] ~= nil and section["ifname"]:match("^@.*")) then if mac ~= "" and mac ~= nil and not (section["device"] ~= nil and section["device"]:match("^@.*")) then
if allmac[mac] then if allmac[mac] then
connectivity = "ERROR" connectivity = "ERROR"
duplicatemac = true duplicatemac = true