From 1e4d24bdaa88ba9a6ff692d8d06e7a33bd57f02c Mon Sep 17 00:00:00 2001 From: Ycarus Date: Fri, 20 Apr 2018 14:56:19 +0200 Subject: [PATCH] Interfaces can be added from wizard --- .../luasrc/controller/openmptcprouter.lua | 44 +++++++++++++- .../luasrc/view/openmptcprouter/wizard.htm | 60 +++++++++++-------- 2 files changed, 78 insertions(+), 26 deletions(-) diff --git a/luci-app-openmptcprouter/luasrc/controller/openmptcprouter.lua b/luci-app-openmptcprouter/luasrc/controller/openmptcprouter.lua index 427bf4144..9d96e441c 100644 --- a/luci-app-openmptcprouter/luasrc/controller/openmptcprouter.lua +++ b/luci-app-openmptcprouter/luasrc/controller/openmptcprouter.lua @@ -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 diff --git a/luci-app-openmptcprouter/luasrc/view/openmptcprouter/wizard.htm b/luci-app-openmptcprouter/luasrc/view/openmptcprouter/wizard.htm index cf841b7ba..9fd371ace 100644 --- a/luci-app-openmptcprouter/luasrc/view/openmptcprouter/wizard.htm +++ b/luci-app-openmptcprouter/luasrc/view/openmptcprouter/wizard.htm @@ -5,6 +5,7 @@ local net = require "luci.model.network".init() local ifaces = net:get_interfaces() %> + <% if stderr and #stderr > 0 then %>
<%=pcdata(stderr)%>
<% end %>
@@ -41,40 +42,49 @@ local ifname = iface:name() if (ifname:match("^wan.*")) then %> +
+ +

<%=ifname%>

- -
- -
- " data-type="ip4addr"> -
-
- help - <%:Set an IP in the same network as the modem%> +
+ +
+ +
+ " data-type="ip4addr"> +
+
+ help + <%:Set an IP in the same network as the modem%> +
-
-
- -
- " data-type="ip4addr"> -
-
-
- -
- " data-type="ip4addr"> -
-
- help - <%:Set here IP of the modem%> +
+ +
+ " data-type="ip4addr">
-
+
+ +
+ " data-type="ip4addr"> +
+
+ help + <%:Set here IP of the modem%> +
+
+
+ <% end end %> + +
+ +