Rename package and rebuild opkg-feed
- Added luci-app-GO-wireguard (Luci app for Wireguard pulled from GoldenOrb)
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
require("luci.ip")
|
||||
require("luci.model.uci")
|
||||
|
||||
--luci.sys.call("/usr/lib/wireguard/keygen.sh " .. arg[1])
|
||||
|
||||
local m = Map("wireguard", translate("Wireguard Client"), translate("Set up a Wireguard Client"))
|
||||
|
||||
e = m:section(NamedSection, "settings", "")
|
||||
|
||||
m.on_init = function(self)
|
||||
--luci.sys.call("/usr/lib/wireguard/keygen.sh " .. arg[1])
|
||||
end
|
||||
|
||||
btn = e:option(Button, "_btn", translate(" "))
|
||||
btn.inputtitle = translate("Back to Main Page")
|
||||
btn.inputstyle = "apply"
|
||||
btn.redirect = luci.dispatcher.build_url(
|
||||
"admin", "vpn", "wireguard"
|
||||
)
|
||||
function btn.write(self, section, value)
|
||||
luci.http.redirect( self.redirect )
|
||||
end
|
||||
|
||||
|
||||
local s = m:section( NamedSection, arg[1], "wireguard", translate("Client") )
|
||||
|
||||
ip = s:option(Value, "addresses", translate("IP Addresses :"), translate("Comma separated list of IP Addresses that server will accept from this client"));
|
||||
ip.rmempty = true;
|
||||
ip.optional=false;
|
||||
ip.default="10.14.0.2/24";
|
||||
|
||||
port = s:option(Value, "port", translate("Listen Port :"), translate("Client Listen Port"));
|
||||
port.rmempty = true;
|
||||
port.optional=false;
|
||||
port.default="51820";
|
||||
|
||||
ul = s:option(ListValue, "udptunnel", translate("Enable UDP over TCP :"));
|
||||
ul:value("0", translate("No"))
|
||||
ul:value("1", translate("Yes"))
|
||||
ul.default=0
|
||||
|
||||
dns = s:option(Value, "dns", translate("DNS Servers :"), translate("Comma separated list of DNS Servers."));
|
||||
dns.rmempty = true;
|
||||
dns.optional=false;
|
||||
|
||||
mtu = s:option(Value, "mtu", translate("MTU :"), translate("Maximum MTU"));
|
||||
mtu.rmempty = true;
|
||||
mtu.optional=false;
|
||||
mtu.datatype = 'range(1280,1420)';
|
||||
mtu.default="1280";
|
||||
|
||||
pka = s:option(Value, "persistent_keepalive", translate("Persistent Keep Alive :"), translate("Seconds between keep alive messages"));
|
||||
pka.rmempty = true;
|
||||
pka.optional=false;
|
||||
pka.datatype = 'range(1,100)';
|
||||
pka.default="25";
|
||||
|
||||
pkey = s:option(Value, "privatekey", translate("Private Key :"), translate("Private Key supplied by the Server"));
|
||||
pkey.rmempty = true;
|
||||
pkey.optional=false;
|
||||
|
||||
il = s:option(ListValue, "wginter", translate("Interface to Use :"));
|
||||
il:value("0", translate("WG0"))
|
||||
il:value("1", translate("WG1"))
|
||||
il.default="0"
|
||||
|
||||
bl = s:option(ListValue, "auto", translate("Start on Boot :"));
|
||||
bl:value("0", translate("No"))
|
||||
bl:value("1", translate("Yes"))
|
||||
bl.default="0"
|
||||
|
||||
xbl = s:option(ListValue, "forward", translate("All Traffic Through Tunnel :"));
|
||||
xbl:value("0", translate("No"))
|
||||
xbl:value("1", translate("Yes"))
|
||||
xbl.default="1"
|
||||
|
||||
s = m:section( NamedSection, arg[1], "wireguard", translate("Server") )
|
||||
|
||||
name = s:option( Value, "name", translate("Server Name :"), translate("Optional Server name"))
|
||||
|
||||
pukey = s:option(Value, "publickey", translate("Public Key :"), translate("Public Key of the Server"));
|
||||
pukey.rmempty = true;
|
||||
pukey.optional=false;
|
||||
|
||||
prkey = s:option(Value, "presharedkey", translate("Presharedkey :"), translate("PreShared Key from the Server"));
|
||||
prkey.rmempty = true;
|
||||
prkey.optional=false;
|
||||
|
||||
host = s:option(Value, "endpoint_host", translate("Server Address :"), translate("URL or IP Address of Server"));
|
||||
host.rmempty = true;
|
||||
host.optional=false;
|
||||
host.default="";
|
||||
|
||||
sport = s:option(Value, "sport", translate("Listen Port :"), translate("Server Listen Port"));
|
||||
sport.rmempty = true;
|
||||
sport.optional=false;
|
||||
sport.default="51820";
|
||||
|
||||
sip = s:option(Value, "ips", translate("Allowed IP Addresses :"), translate("Comma separated list of IP Addresses that server will accept"));
|
||||
sip.rmempty = true;
|
||||
sip.optional=false;
|
||||
sip.default="10.14.0.0/24";
|
||||
|
||||
return m
|
||||
@@ -0,0 +1,130 @@
|
||||
require("luci.ip")
|
||||
require("luci.model.uci")
|
||||
|
||||
--luci.sys.call("/usr/lib/wireguard/keygen.sh " .. arg[1])
|
||||
|
||||
local m = Map("wireguard", translate("Wireguard Server"), translate("Set up a Wireguard Server"))
|
||||
|
||||
e = m:section(NamedSection, "settings", "")
|
||||
|
||||
m.on_init = function(self)
|
||||
luci.sys.call("/usr/lib/wireguard/keygen.sh " .. arg[1])
|
||||
end
|
||||
|
||||
m.on_after_save = function(self)
|
||||
luci.sys.call("/usr/lib/wireguard/keygen.sh " .. arg[1] .. "&")
|
||||
end
|
||||
|
||||
btn = e:option(Button, "_btn", translate(" "))
|
||||
btn.inputtitle = translate("Back to Main Page")
|
||||
btn.inputstyle = "apply"
|
||||
btn.redirect = luci.dispatcher.build_url(
|
||||
"admin", "vpn", "wireguard"
|
||||
)
|
||||
function btn.write(self, section, value)
|
||||
luci.http.redirect( self.redirect )
|
||||
end
|
||||
|
||||
|
||||
local s = m:section( NamedSection, arg[1], "wireguard", translate("Server") )
|
||||
|
||||
ip = s:option(Value, "addresses", translate("Internal IP Address :"));
|
||||
ip.rmempty = true;
|
||||
ip.optional=false;
|
||||
ip.default="10.14.0.1/32";
|
||||
ip.datatype = "ipaddr"
|
||||
|
||||
host = s:option(Value, "endpoint_host", translate("Server Address :"), translate("URL or IP Address of Server"));
|
||||
host.rmempty = true;
|
||||
host.optional=false;
|
||||
host.default="example.wireguard.org";
|
||||
|
||||
port = s:option(Value, "port", translate("Port :"), translate("Server Listen Port. Default is 51280"));
|
||||
port.rmempty = true;
|
||||
port.optional=false;
|
||||
port.default="51280";
|
||||
|
||||
ul = s:option(ListValue, "udptunnel", "Enable UDP over TCP :");
|
||||
ul:value("0", translate("No"))
|
||||
ul:value("1", translate("Yes"))
|
||||
ul.default=0
|
||||
|
||||
uport = s:option(Value, "udpport", translate("UDP over TCP Port :"), translate("Server Local TCP Port. Default is 54321"));
|
||||
uport.rmempty = true;
|
||||
uport.optional=false;
|
||||
uport.default="54321";
|
||||
uport:depends("udptunnel", "1")
|
||||
|
||||
pkey = s:option(DummyValue, "privatekey", translate("Private Key :"));
|
||||
pkey.optional=false;
|
||||
|
||||
pukey = s:option(DummyValue, "publickey", translate("Public Key :"), translate("Server Public key sent to Clients"));
|
||||
pukey.optional=false;
|
||||
|
||||
pl = s:option(ListValue, "usepre", "Use PreSharedKey :");
|
||||
pl:value("0", translate("No"))
|
||||
pl:value("1", translate("Yes"))
|
||||
pl.default=0
|
||||
|
||||
prkey = s:option(DummyValue, "presharedkey", translate("PreShared Key :"), translate("PreShared Key sent to Client"));
|
||||
prkey.optional=false;
|
||||
prkey:depends("usepre", "1")
|
||||
|
||||
bl = s:option(ListValue, "auto", translate("Start on Boot :"));
|
||||
bl:value("0", translate("No"))
|
||||
bl:value("1", translate("Yes"))
|
||||
bl.default="0"
|
||||
|
||||
xbl = s:option(ListValue, "forward", translate("All Traffic Through Tunnel :"));
|
||||
xbl:value("0", translate("No"))
|
||||
xbl:value("1", translate("Yes"))
|
||||
xbl.default="1"
|
||||
|
||||
|
||||
b3 = s:option(DummyValue, "blank", " ");
|
||||
|
||||
sx = s:option(Value, "_dmy1", translate(" "))
|
||||
sx.template = "wireguard/conf"
|
||||
|
||||
ss = m:section(TypedSection, "custom" .. arg[1], translate("Clients"), translate("Clients of this server"))
|
||||
ss.anonymous = true
|
||||
ss.addremove = true
|
||||
|
||||
name = ss:option(Value, "name", translate("Client Name"))
|
||||
name.optional=false;
|
||||
|
||||
cport = ss:option(Value, "endpoint_port", translate("Listen Port :"), translate("Port sent to Client. Default is 51280"));
|
||||
cport.rmempty = true;
|
||||
cport.optional=false;
|
||||
cport.default="";
|
||||
|
||||
aip = ss:option(Value, "address", translate("Assigned IP Address :"), translate("IP Address assigned to Client"));
|
||||
aip.rmempty = true;
|
||||
aip.optional=false;
|
||||
aip.default="10.14.0.2/32";
|
||||
|
||||
dns = ss:option(Value, "dns", translate("DNS Servers :"), translate("Comma separated list of DNS Servers sent to Client"));
|
||||
dns.rmempty = true;
|
||||
dns.optional=false;
|
||||
dns.default="";
|
||||
|
||||
mtu = ss:option(Value, "mtu", translate("MTU :"), translate("Maximum MTU"));
|
||||
mtu.rmempty = true;
|
||||
mtu.optional=false;
|
||||
mtu.datatype = 'range(1280,1420)';
|
||||
mtu.default="1280";
|
||||
|
||||
aip = ss:option(Value, "allowed_ips", translate("Allowed IP Address :"), translate("Comma separated list of IP Addresses allowed from Client"));
|
||||
aip.rmempty = true;
|
||||
aip.optional=false;
|
||||
aip.default="0.0.0.0/0,::/0";
|
||||
|
||||
pukey = ss:option(DummyValue, "publickey", translate("Public Key :"), translate("Client Public Key"));
|
||||
pukey.optional=false;
|
||||
|
||||
pikey = ss:option(DummyValue, "privatekey", translate("Private Key :"), translate("Private Key sent to Client"));
|
||||
pikey.optional=false;
|
||||
|
||||
b3 = ss:option(DummyValue, "blank", " ");
|
||||
|
||||
return m
|
||||
182
ipk-source/luci-app-go-wireguard/root/usr/lib/lua/luci/model/cbi/wireguard.lua
Executable file
182
ipk-source/luci-app-go-wireguard/root/usr/lib/lua/luci/model/cbi/wireguard.lua
Executable file
@@ -0,0 +1,182 @@
|
||||
local fs = require "nixio.fs"
|
||||
local sys = require "luci.sys"
|
||||
local uci = require "luci.model.uci".cursor()
|
||||
local testfullps = sys.exec("ps --help 2>&1 | grep BusyBox") --check which ps do we have
|
||||
local psstring = (string.len(testfullps)>0) and "ps w" or "ps axfw" --set command we use to get pid
|
||||
|
||||
local m = Map("wireguard", translate("Wireguard"), translate("Set up a Wireguard VPN Tunnel on your Router"))
|
||||
|
||||
local s = m:section( TypedSection, "wireguard", translate("Instances"), translate("Below is a list of configured Wireguard Instances and their current state") )
|
||||
s.template = "cbi/tblsection"
|
||||
s.template_addremove = "wireguard/cbi-select-input-add"
|
||||
s.addremove = true
|
||||
s.add_select_options = { }
|
||||
|
||||
local cfg = s:option(DummyValue, "config")
|
||||
function cfg.cfgvalue(self, section)
|
||||
local file_cfg = self.map:get(section, "client")
|
||||
if file_cfg == "1" then
|
||||
s.extedit = luci.dispatcher.build_url("admin", "vpn", "wireguard", "client", "%s")
|
||||
else
|
||||
s.extedit = luci.dispatcher.build_url("admin", "vpn", "wireguard", "server", "%s")
|
||||
end
|
||||
end
|
||||
|
||||
uci:load("wireguard_recipes")
|
||||
uci:foreach( "wireguard_recipes", "wireguard_recipe",
|
||||
function(section)
|
||||
s.add_select_options[section['.name']] =
|
||||
section['_description'] or section['.name']
|
||||
end
|
||||
)
|
||||
|
||||
function s.parse(self, section)
|
||||
local recipe = luci.http.formvalue(
|
||||
luci.cbi.CREATE_PREFIX .. self.config .. "." ..
|
||||
self.sectiontype .. ".select"
|
||||
)
|
||||
|
||||
if recipe and not s.add_select_options[recipe] then
|
||||
self.invalid_cts = true
|
||||
else
|
||||
TypedSection.parse( self, section )
|
||||
end
|
||||
end
|
||||
|
||||
function s.create(self, name)
|
||||
local recipe = luci.http.formvalue(
|
||||
luci.cbi.CREATE_PREFIX .. self.config .. "." ..
|
||||
self.sectiontype .. ".select"
|
||||
)
|
||||
local name = luci.http.formvalue(
|
||||
luci.cbi.CREATE_PREFIX .. self.config .. "." ..
|
||||
self.sectiontype .. ".text"
|
||||
)
|
||||
if #name > 3 and not name:match("[^a-zA-Z0-9_]") then
|
||||
local s = uci:section("wireguard", "wireguard", name)
|
||||
if s then
|
||||
local options = uci:get_all("wireguard_recipes", recipe)
|
||||
for k, v in pairs(options) do
|
||||
if k ~= "_role" and k ~= "_description" then
|
||||
if type(v) == "boolean" then
|
||||
v = v and "1" or "0"
|
||||
end
|
||||
uci:set("wireguard", name, k, v)
|
||||
end
|
||||
end
|
||||
uci:save("wireguard")
|
||||
uci:commit("wireguard")
|
||||
if extedit then
|
||||
luci.http.redirect( self.extedit:format(name) )
|
||||
end
|
||||
end
|
||||
elseif #name > 0 then
|
||||
self.invalid_cts = true
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
function s.remove(self, name)
|
||||
local cfg_file = "/etc/openvpn/" ..name.. ".conf"
|
||||
local auth_file = "/etc/openvpn/" ..name.. ".auth"
|
||||
if fs.access(cfg_file) then
|
||||
fs.unlink(cfg_file)
|
||||
end
|
||||
if fs.access(auth_file) then
|
||||
fs.unlink(auth_file)
|
||||
end
|
||||
uci:delete("wireguard", name)
|
||||
uci:save("wireguard")
|
||||
uci:commit("wireguard")
|
||||
end
|
||||
|
||||
local port = s:option( DummyValue, "client", translate("Type") )
|
||||
function port.cfgvalue(self, section)
|
||||
local val = AbstractValue.cfgvalue(self, section)
|
||||
if val == nil then
|
||||
val = 0
|
||||
end
|
||||
if val == "1" then
|
||||
return "Client"
|
||||
else
|
||||
return "Server"
|
||||
end
|
||||
end
|
||||
|
||||
local addr = s:option( DummyValue, "addresses", translate("IP Addresses") )
|
||||
function addr.cfgvalue(self, section)
|
||||
local val = AbstractValue.cfgvalue(self, section)
|
||||
return val or "----"
|
||||
end
|
||||
|
||||
local auto = s:option( DummyValue, "udptunnel", translate("UDP over TCP") )
|
||||
function auto.cfgvalue(self, section)
|
||||
local val = AbstractValue.cfgvalue(self, section)
|
||||
if val == nil then
|
||||
val = 0
|
||||
end
|
||||
if val == "1" then
|
||||
return "Yes"
|
||||
else
|
||||
return "No"
|
||||
end
|
||||
end
|
||||
|
||||
local auto = s:option( DummyValue, "auto", translate("Start on Boot") )
|
||||
function auto.cfgvalue(self, section)
|
||||
local val = AbstractValue.cfgvalue(self, section)
|
||||
if val == nil then
|
||||
val = 0
|
||||
end
|
||||
if val == "1" then
|
||||
return "Yes"
|
||||
else
|
||||
return "No"
|
||||
end
|
||||
end
|
||||
|
||||
local active = s:option( DummyValue, "active", translate("Started") )
|
||||
function active.cfgvalue(self, section)
|
||||
local val = AbstractValue.cfgvalue(self, section)
|
||||
if val == nil then
|
||||
val = 0
|
||||
end
|
||||
if val == "1" then
|
||||
return "Yes"
|
||||
else
|
||||
return "No"
|
||||
end
|
||||
end
|
||||
|
||||
local updown = s:option( Button, "_updown", translate("Start/Stop") )
|
||||
updown._state = false
|
||||
updown.redirect = luci.dispatcher.build_url(
|
||||
"admin", "vpn", "wireguard"
|
||||
)
|
||||
function updown.cbid(self, section)
|
||||
local file_cfg = self.map:get(section, "active")
|
||||
if file_cfg == "1" then
|
||||
pid = 1
|
||||
else
|
||||
pid = nil
|
||||
end
|
||||
self._state = pid ~= nil
|
||||
self.option = self._state and "stop" or "start"
|
||||
return AbstractValue.cbid(self, section)
|
||||
end
|
||||
function updown.cfgvalue(self, section)
|
||||
self.title = self._state and "stop" or "start"
|
||||
self.inputstyle = self._state and "reset" or "reload"
|
||||
end
|
||||
function updown.write(self, section, value)
|
||||
if self.option == "stop" then
|
||||
sys.call("/usr/lib/wireguard/stopvpn.sh %s" % section)
|
||||
else
|
||||
sys.call("/usr/lib/wireguard/startvpn.sh %s" % section)
|
||||
end
|
||||
luci.http.redirect( self.redirect )
|
||||
end
|
||||
|
||||
m:section(SimpleSection).template = "wireguard/wireguard"
|
||||
|
||||
return m
|
||||
Reference in New Issue
Block a user