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

Interfaces can be added from wizard

This commit is contained in:
Ycarus 2018-04-20 14:56:19 +02:00
parent 531851d3c2
commit 1e4d24bdaa
2 changed files with 78 additions and 26 deletions

View file

@ -18,6 +18,44 @@ function index()
end
function wizard_add()
local add_interface = luci.http.formvalue("add_interface") or ""
local gostatus = true
if add_interface ~= "" then
local i = 1
ucic:foreach("network", "interface", function(s)
local sectionname = s[".name"]
if sectionname:match("^wan(%d+)$") then
i = i + 1
end
end)
local defif = ucic:get("network","wan1","ifname") or "eth0"
ucic:set("network","wan" .. i,"interface")
ucic:set("network","wan" .. i,"ifname",defif)
ucic:set("network","wan" .. i,"proto","static")
ucic:set("network","wan" .. i,"type","macvlan")
ucic:set("network","wan" .. i,"ip4table","wan")
ucic:set("network","wan" .. i,"multipath","on")
ucic:set("network","wan" .. i,"defaultroute","0")
ucic:save("network")
ucic:commit("network")
-- Dirty way to add new interface to firewall...
luci.sys.call("uci -q add_list firewall.@zone[1].network=wan" .. i)
luci.sys.call("/etc/init.d/macvlan restart >/dev/null 2>/dev/null")
gostatus = false
end
local delete_intf = luci.http.formvaluetable("delete")
if delete_intf ~= "" then
for intf, _ in pairs(delete_intf) do
ucic:delete("network",intf)
ucic:delete("network",intf .. "_dev")
ucic:save("network")
ucic:commit("network")
end
gostatus = false
end
local server_ip = luci.http.formvalue("server_ip")
-- Set ShadowSocks settings
@ -60,7 +98,11 @@ function wizard_add()
ucic:commit("network")
luci.sys.call("(env -i /bin/ubus call network reload) >/dev/null 2>/dev/null")
luci.sys.call("/etc/init.d/glorytun restart >/dev/null 2>/dev/null")
luci.http.redirect(luci.dispatcher.build_url("admin/system/openmptcprouter/status"))
if gostatus then
luci.http.redirect(luci.dispatcher.build_url("admin/system/openmptcprouter/status"))
else
luci.http.redirect(luci.dispatcher.build_url("admin/system/openmptcprouter/wizard"))
end
return
end

View file

@ -5,6 +5,7 @@
local net = require "luci.model.network".init()
local ifaces = net:get_interfaces()
%>
<script type="text/javascript" src="<%=resource%>/cbi.js"></script>
<% if stderr and #stderr > 0 then %><pre class="error"><%=pcdata(stderr)%></pre><% end %>
<form class="inline" method="post" action="<%=url('admin/system/openmptcprouter/wizard_add')%>">
@ -41,40 +42,49 @@
local ifname = iface:name()
if (ifname:match("^wan.*")) then
%>
<div class="cbi-section-remove right">
<input type="submit" name="delete.<%=ifname%>" value="<%:Delete%>" class="cbi-button" />
</div>
<h3><%=ifname%></h3>
<input type="hidden" name="intf.<%=ifname%>" value="<%=ifname%>" />
<div class="cbi-value">
<label class="cbi-value-title"><%:IPv4 address%></label>
<div class="cbi-value-field">
<input type="text" name="cbid.network.<%=ifname%>.ipaddr" class="cbi-input-text" value="<%=uci:get("network",ifname,"ipaddr")%>" data-type="ip4addr">
<br />
<div class="cbi-value-description">
<span class="cbi-value-helpicon"><img src="/luci-static/resources/cbi/help.gif" alt="help" /></span>
<%:Set an IP in the same network as the modem%>
<fieldset class="cbi-section-node" id="cbi-openmptcprouter-<%=ifname%>">
<input type="hidden" name="intf.<%=ifname%>" value="<%=ifname%>" />
<div class="cbi-value">
<label class="cbi-value-title"><%:IPv4 address%></label>
<div class="cbi-value-field">
<input type="text" name="cbid.network.<%=ifname%>.ipaddr" class="cbi-input-text" value="<%=uci:get("network",ifname,"ipaddr")%>" data-type="ip4addr">
<br />
<div class="cbi-value-description">
<span class="cbi-value-helpicon"><img src="/luci-static/resources/cbi/help.gif" alt="help" /></span>
<%:Set an IP in the same network as the modem%>
</div>
</div>
</div>
</div>
<div class="cbi-value">
<label class="cbi-value-title"><%:IPv4 netmask%></label>
<div class="cbi-value-field">
<input type="text" name="cbid.network.<%=ifname%>.netmask" class="cbi-input-text" value="<%=uci:get("network",ifname,"netmask") or "255.255.255.0"%>" data-type="ip4addr">
</div>
</div>
<div class="cbi-value">
<label class="cbi-value-title"><%:IPv4 gateway%></label>
<div class="cbi-value-field">
<input type="text" name="cbid.network.<%=ifname%>.gateway" class="cbi-input-text" value="<%=uci:get("network",ifname,"gateway")%>" data-type="ip4addr">
<br />
<div class="cbi-value-description">
<span class="cbi-value-helpicon"><img src="/luci-static/resources/cbi/help.gif" alt="help" /></span>
<%:Set here IP of the modem%>
<div class="cbi-value">
<label class="cbi-value-title"><%:IPv4 netmask%></label>
<div class="cbi-value-field">
<input type="text" name="cbid.network.<%=ifname%>.netmask" class="cbi-input-text" value="<%=uci:get("network",ifname,"netmask") or "255.255.255.0"%>" data-type="ip4addr">
</div>
</div>
</div>
<div class="cbi-value">
<label class="cbi-value-title"><%:IPv4 gateway%></label>
<div class="cbi-value-field">
<input type="text" name="cbid.network.<%=ifname%>.gateway" class="cbi-input-text" value="<%=uci:get("network",ifname,"gateway")%>" data-type="ip4addr">
<br />
<div class="cbi-value-description">
<span class="cbi-value-helpicon"><img src="/luci-static/resources/cbi/help.gif" alt="help" /></span>
<%:Set here IP of the modem%>
</div>
</div>
</div>
</fieldset>
<%
end
end
%>
<div class="cbi-section-create">
<input class="cbi-button cbi-button-add" type="submit" name="add_interface" value="<%:Add an interface%>" title="<%:Add an interface%>" />
</div>
</fieldset>
</div>
<div class="cbi-page-actions">