Merge pull request #2307 from dibdot/ovpn
luci-app-openvpn: more changes & fixes
This commit is contained in:
commit
d5c59834c8
4 changed files with 88 additions and 16 deletions
|
@ -18,7 +18,7 @@ function ovpn_upload()
|
||||||
local util = require("luci.util")
|
local util = require("luci.util")
|
||||||
local uci = require("luci.model.uci").cursor()
|
local uci = require("luci.model.uci").cursor()
|
||||||
local upload = http.formvalue("ovpn_file")
|
local upload = http.formvalue("ovpn_file")
|
||||||
local name = string.gsub(util.shellquote(http.formvalue("instance_name2")), "'", "")
|
local name = http.formvalue("instance_name2")
|
||||||
local file = "/etc/openvpn/" ..name.. ".ovpn"
|
local file = "/etc/openvpn/" ..name.. ".ovpn"
|
||||||
|
|
||||||
if name and upload then
|
if name and upload then
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
-- Copyright 2008 Steven Barth <steven@midlink.org>
|
-- Copyright 2008 Steven Barth <steven@midlink.org>
|
||||||
-- Licensed to the public under the Apache License 2.0.
|
-- Licensed to the public under the Apache License 2.0.
|
||||||
|
|
||||||
require("luci.ip")
|
local fs = require("nixio.fs")
|
||||||
require("luci.model.uci")
|
|
||||||
|
|
||||||
|
|
||||||
local knownParams = {
|
local knownParams = {
|
||||||
--
|
--
|
||||||
|
@ -160,6 +158,10 @@ local knownParams = {
|
||||||
"script_security",
|
"script_security",
|
||||||
{ 0, 1, 2, 3 },
|
{ 0, 1, 2, 3 },
|
||||||
translate("Policy level over usage of external programs and scripts") },
|
translate("Policy level over usage of external programs and scripts") },
|
||||||
|
{ Value,
|
||||||
|
"config",
|
||||||
|
"/etc/openvpn/ovpn-file.ovpn",
|
||||||
|
translate("Local OVPN configuration file") },
|
||||||
} },
|
} },
|
||||||
|
|
||||||
{ "Networking", {
|
{ "Networking", {
|
||||||
|
@ -464,7 +466,7 @@ local knownParams = {
|
||||||
0,
|
0,
|
||||||
translate("Accept options pushed from server"),
|
translate("Accept options pushed from server"),
|
||||||
{ client="1" } },
|
{ client="1" } },
|
||||||
{ Value,
|
{ FileUpload,
|
||||||
"auth_user_pass",
|
"auth_user_pass",
|
||||||
"/etc/openvpn/userpass.txt",
|
"/etc/openvpn/userpass.txt",
|
||||||
translate("Authenticate using username/password"),
|
translate("Authenticate using username/password"),
|
||||||
|
@ -689,9 +691,9 @@ local knownParams = {
|
||||||
"tls_version_max",
|
"tls_version_max",
|
||||||
"1.2",
|
"1.2",
|
||||||
translate("The highest supported TLS version") },
|
translate("The highest supported TLS version") },
|
||||||
{ Value,
|
{ ListValue,
|
||||||
"key_direction",
|
"key_direction",
|
||||||
"1",
|
{ 0, 1 },
|
||||||
translate("The key direction for 'tls-auth' and 'secret' options") },
|
translate("The key direction for 'tls-auth' and 'secret' options") },
|
||||||
} }
|
} }
|
||||||
}
|
}
|
||||||
|
@ -703,6 +705,8 @@ local params = { }
|
||||||
local m = Map("openvpn")
|
local m = Map("openvpn")
|
||||||
local p = m:section( SimpleSection )
|
local p = m:section( SimpleSection )
|
||||||
|
|
||||||
|
m.apply_on_parse = true
|
||||||
|
|
||||||
p.template = "openvpn/pageswitch"
|
p.template = "openvpn/pageswitch"
|
||||||
p.mode = "advanced"
|
p.mode = "advanced"
|
||||||
p.instance = arg[1]
|
p.instance = arg[1]
|
||||||
|
@ -732,8 +736,42 @@ for _, option in ipairs(params) do
|
||||||
option[2], option[4]
|
option[2], option[4]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
o.optional = true
|
||||||
|
|
||||||
if option[1] == DummyValue then
|
if option[1] == DummyValue then
|
||||||
o.value = option[3]
|
o.value = option[3]
|
||||||
|
elseif option[1] == FileUpload then
|
||||||
|
|
||||||
|
function o.cfgvalue(self, section)
|
||||||
|
local cfg_val = AbstractValue.cfgvalue(self, section)
|
||||||
|
|
||||||
|
if cfg_val then
|
||||||
|
return cfg_val
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function o.formvalue(self, section)
|
||||||
|
local sel_val = AbstractValue.formvalue(self, section)
|
||||||
|
local txt_val = luci.http.formvalue("cbid."..self.map.config.."."..section.."."..self.option..".textbox")
|
||||||
|
|
||||||
|
if sel_val and sel_val ~= "" then
|
||||||
|
return sel_val
|
||||||
|
end
|
||||||
|
|
||||||
|
if txt_val and txt_val ~= "" then
|
||||||
|
return txt_val
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function o.remove(self, section)
|
||||||
|
local cfg_val = AbstractValue.cfgvalue(self, section)
|
||||||
|
local txt_val = luci.http.formvalue("cbid."..self.map.config.."."..section.."."..self.option..".textbox")
|
||||||
|
|
||||||
|
if cfg_val and fs.access(cfg_val) and txt_val == "" then
|
||||||
|
fs.unlink(cfg_val)
|
||||||
|
end
|
||||||
|
return AbstractValue.remove(self, section)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
if option[1] == DynamicList then
|
if option[1] == DynamicList then
|
||||||
function o.cfgvalue(...)
|
function o.cfgvalue(...)
|
||||||
|
@ -742,8 +780,6 @@ for _, option in ipairs(params) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
o.optional = true
|
|
||||||
|
|
||||||
if type(option[3]) == "table" then
|
if type(option[3]) == "table" then
|
||||||
if o.optional then o:value("", "-- remove --") end
|
if o.optional then o:value("", "-- remove --") end
|
||||||
for _, v in ipairs(option[3]) do
|
for _, v in ipairs(option[3]) do
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
-- Copyright 2008 Steven Barth <steven@midlink.org>
|
-- Copyright 2008 Steven Barth <steven@midlink.org>
|
||||||
-- Licensed to the public under the Apache License 2.0.
|
-- Licensed to the public under the Apache License 2.0.
|
||||||
|
|
||||||
require("luci.ip")
|
local fs = require("nixio.fs")
|
||||||
require("luci.model.uci")
|
|
||||||
|
|
||||||
local basicParams = {
|
local basicParams = {
|
||||||
--
|
--
|
||||||
-- Widget, Name, Default(s), Description
|
-- Widget, Name, Default(s), Description
|
||||||
--
|
--
|
||||||
|
|
||||||
{ ListValue, "verb", { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }, translate("Set output verbosity") },
|
{ ListValue, "verb", { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }, translate("Set output verbosity") },
|
||||||
{ Value, "nice",0, translate("Change process priority") },
|
{ Value, "nice",0, translate("Change process priority") },
|
||||||
{ Value,"port",1194, translate("TCP/UDP port # for both local and remote") },
|
{ Value,"port",1194, translate("TCP/UDP port # for both local and remote") },
|
||||||
|
@ -28,18 +26,22 @@ local basicParams = {
|
||||||
{ DynamicList,"remote","vpnserver.example.org", translate("Remote host name or ip address") },
|
{ DynamicList,"remote","vpnserver.example.org", translate("Remote host name or ip address") },
|
||||||
|
|
||||||
{ FileUpload,"secret","/etc/openvpn/secret.key", translate("Enable Static Key encryption mode (non-TLS)") },
|
{ FileUpload,"secret","/etc/openvpn/secret.key", translate("Enable Static Key encryption mode (non-TLS)") },
|
||||||
{ Value,"key_direction","1", translate("The key direction for 'tls-auth' and 'secret' options") },
|
{ ListValue,"key_direction", { 0, 1 }, translate("The key direction for 'tls-auth' and 'secret' options") },
|
||||||
{ FileUpload,"pkcs12","/etc/easy-rsa/keys/some-client.pk12", translate("PKCS#12 file containing keys") },
|
{ FileUpload,"pkcs12","/etc/easy-rsa/keys/some-client.pk12", translate("PKCS#12 file containing keys") },
|
||||||
{ FileUpload,"ca","/etc/easy-rsa/keys/ca.crt", translate("Certificate authority") },
|
{ FileUpload,"ca","/etc/easy-rsa/keys/ca.crt", translate("Certificate authority") },
|
||||||
{ FileUpload,"dh","/etc/easy-rsa/keys/dh1024.pem", translate("Diffie Hellman parameters") },
|
{ FileUpload,"dh","/etc/easy-rsa/keys/dh1024.pem", translate("Diffie Hellman parameters") },
|
||||||
{ FileUpload,"cert","/etc/easy-rsa/keys/some-client.crt", translate("Local certificate") },
|
{ FileUpload,"cert","/etc/easy-rsa/keys/some-client.crt", translate("Local certificate") },
|
||||||
{ FileUpload,"key","/etc/easy-rsa/keys/some-client.key", translate("Local private key") },
|
{ FileUpload,"key","/etc/easy-rsa/keys/some-client.key", translate("Local private key") },
|
||||||
|
{ Value,"config","/etc/openvpn/ovpn-file.ovpn", translate("Local OVPN configuration file") },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
local m = Map("openvpn")
|
local m = Map("openvpn")
|
||||||
local p = m:section( SimpleSection )
|
local p = m:section( SimpleSection )
|
||||||
|
|
||||||
|
m.apply_on_parse = true
|
||||||
|
|
||||||
|
|
||||||
p.template = "openvpn/pageswitch"
|
p.template = "openvpn/pageswitch"
|
||||||
p.mode = "basic"
|
p.mode = "basic"
|
||||||
p.instance = arg[1]
|
p.instance = arg[1]
|
||||||
|
@ -57,6 +59,38 @@ for _, option in ipairs(basicParams) do
|
||||||
|
|
||||||
if option[1] == DummyValue then
|
if option[1] == DummyValue then
|
||||||
o.value = option[3]
|
o.value = option[3]
|
||||||
|
elseif option[1] == FileUpload then
|
||||||
|
|
||||||
|
function o.cfgvalue(self, section)
|
||||||
|
local cfg_val = AbstractValue.cfgvalue(self, section)
|
||||||
|
|
||||||
|
if cfg_val then
|
||||||
|
return cfg_val
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function o.formvalue(self, section)
|
||||||
|
local sel_val = AbstractValue.formvalue(self, section)
|
||||||
|
local txt_val = luci.http.formvalue("cbid."..self.map.config.."."..section.."."..self.option..".textbox")
|
||||||
|
|
||||||
|
if sel_val and sel_val ~= "" then
|
||||||
|
return sel_val
|
||||||
|
end
|
||||||
|
|
||||||
|
if txt_val and txt_val ~= "" then
|
||||||
|
return txt_val
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function o.remove(self, section)
|
||||||
|
local cfg_val = AbstractValue.cfgvalue(self, section)
|
||||||
|
local txt_val = luci.http.formvalue("cbid."..self.map.config.."."..section.."."..self.option..".textbox")
|
||||||
|
|
||||||
|
if cfg_val and fs.access(cfg_val) and txt_val == "" then
|
||||||
|
fs.unlink(cfg_val)
|
||||||
|
end
|
||||||
|
return AbstractValue.remove(self, section)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
if option[1] == DynamicList then
|
if option[1] == DynamicList then
|
||||||
function o.cfgvalue(...)
|
function o.cfgvalue(...)
|
||||||
|
|
|
@ -14,8 +14,8 @@ s.template_addremove = "openvpn/cbi-select-input-add"
|
||||||
s.addremove = true
|
s.addremove = true
|
||||||
s.add_select_options = { }
|
s.add_select_options = { }
|
||||||
|
|
||||||
file_cfg = s:option(DummyValue, "config")
|
local cfg = s:option(DummyValue, "config")
|
||||||
function file_cfg.cfgvalue(self, section)
|
function cfg.cfgvalue(self, section)
|
||||||
local file_cfg = self.map:get(section, "config")
|
local file_cfg = self.map:get(section, "config")
|
||||||
if file_cfg then
|
if file_cfg then
|
||||||
s.extedit = luci.dispatcher.build_url("admin", "services", "openvpn", "file", "%s")
|
s.extedit = luci.dispatcher.build_url("admin", "services", "openvpn", "file", "%s")
|
||||||
|
@ -73,8 +73,10 @@ function s.create(self, name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
uci:save("openvpn")
|
uci:save("openvpn")
|
||||||
|
if extedit then
|
||||||
luci.http.redirect( self.extedit:format(name) )
|
luci.http.redirect( self.extedit:format(name) )
|
||||||
end
|
end
|
||||||
|
end
|
||||||
elseif #name > 0 then
|
elseif #name > 0 then
|
||||||
self.invalid_cts = true
|
self.invalid_cts = true
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue