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

Basic wizard

This commit is contained in:
Ycarus 2018-03-23 20:23:27 +01:00
parent 29246dab11
commit 0d235bac48
3 changed files with 136 additions and 0 deletions

View file

@ -0,0 +1,14 @@
#
# Copyright (C) 2018 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
#
#
include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI Support for OpenMPTCProuter
PKG_LICENSE:=Apache-2.0
include ../luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature

View file

@ -0,0 +1,51 @@
local ucic = uci.cursor()
module("luci.controller.openmptcprouter", package.seeall)
function index()
-- entry({"admin", "openmptcprouter"}, firstchild(), _("OpenMPTCProuter"), 19).index = true
-- entry({"admin", "openmptcprouter", "wizard"}, template("openmptcprouter/wizard"), _("Wizard"), 1).leaf = true
-- entry({"admin", "openmptcprouter", "wizard_add"}, post("wizard_add")).leaf = true
entry({"admin", "system", "openmptcprouter"}, template("openmptcprouter/wizard"), _("Settings Wizard"), 1)
entry({"admin", "system", "openmptcprouter", "wizard_add"}, post("wizard_add"))
end
function wizard_add()
local server_ip = luci.http.formvalue("server_ip")
local shadowsocks_key = luci.http.formvalue("shadowsocks_key")
local glorytun_key = luci.http.formvalue("glorytun_key")
if shadowsocks_key ~= "" then
ucic:set("shadowsocks-libev","sss0","server",server_ip)
ucic:set("shadowsocks-libev","sss0","key",shadowsocks_key)
ucic:set("shadowsocks-libev","sss0","method","aes-256-cfb")
ucic:set("shadowsocks-libev","sss0","server_port","65101")
ucic:set("shadowsocks-libev","sss0","disabled",0)
ucic:save("shadowsocks-libev")
ucic:commit("shadowsocks-libev")
end
if glorytun_key ~= "" then
ucic:set("glorytun","vpn","host",server_ip)
ucic:set("glorytun","vpn","port","65001")
ucic:set("glorytun","vpn","key",glorytun_key)
ucic:set("glorytun","vpn","enable",1)
ucic:set("glorytun","vpn","mptcp",1)
ucic:set("glorytun","vpn","chacha20",1)
ucic:set("glorytun","vpn","proto","tcp")
ucic:save("glorytun")
ucic:commit("glorytun")
end
local interfaces = luci.http.formvaluetable("intf")
for intf, _ in pairs(interfaces) do
local ipaddr = luci.http.formvalue("cbid.network.%s.ipaddr" % intf)
local netmask = luci.http.formvalue("cbid.network.%s.netmask" % intf)
local gateway = luci.http.formvalue("cbid.network.%s.gateway" % intf)
ucic:set("network",intf,"ipaddr",ipaddr)
ucic:set("network",intf,"netmask",netmask)
ucic:set("network",intf,"gateway",gateway)
end
ucic:save("network")
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/network/network"))
end

View file

@ -0,0 +1,71 @@
<%+header%>
<%
local uci = require("luci.model.uci").cursor()
local net = require "luci.model.network".init()
local ifaces = net:get_interfaces()
%>
<% 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')%>">
<div id="server" class="server">
<h1><%:Server settings%></h1>
<div class="cbi-value">
<label class="cbi-value-title"><%:Server IP%></label>
<div class="cbi-value-field">
<input type="text" name="server_ip" placeholder="Server IP" class="cbi-input-text" value="<%=uci:get("shadowsocks-libev","sss0","server")%>" data-type="ip4addr">
</div>
</div>
<div class="cbi-value">
<label class="cbi-value-title"><%:ShadowSocks key%></label>
<div class="cbi-value-field">
<input type="text" name="shadowsocks_key" placeholder="ShadowSocks key" class="cbi-input-text" value="<%=uci:get("shadowsocks-libev","sss0","key")%>" data-type="base64">
</div>
</div>
<div class="cbi-value">
<label class="cbi-value-title"><%:Glorytun key%></label>
<div class="cbi-value-field">
<input type="text" name="glorytun_key" placeholder="Glorytun key" class="cbi-input-text" value="<%=uci:get("glorytun","vpn","key")%>">
</div>
</div>
</div>
<div id="interfaces" class="interfaces">
<h1><%:Interfaces settings%></h1>
<%
for _, iface in ipairs(ifaces) do
--if not (iface == "lo" or iface:match("^tun.*")) then
local ifname = iface:name()
if (ifname:match("^wan.*")) then
%>
<h2><%=ifname%></h2>
<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">
</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")%>" 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">
</div>
</div>
<%
end
end
%>
</div>
<div class="cbi-page-actions">
<input type="hidden" name="token" value="<%=token%>" />
<button class="btn" type="submit">Submit</button>
</div>
</form>
<%+footer%>