Skip to content

Commit 7c7527a

Browse files
committed
Improve UI
1 parent 8b34b67 commit 7c7527a

File tree

4 files changed

+90
-47
lines changed

4 files changed

+90
-47
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ deploy:
3535
skip_cleanup: true
3636
file_glob: true
3737
file: $TRAVIS_BUILD_DIR/$PACKAGE*.ipk
38-
# on:
39-
# tags: true
38+
on:
39+
tags: true

src/add_ovpn_user.sh

-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ uci set "$TAG.$ID.pass=$PASS"
1717
uci set "$TAG.$ID.login=$USER"
1818
uci set "$TAG.$ID.enabled=1"
1919
uci commit "$TAG"
20-
chmod 644 /etc/config/ovpnauth

src/ovpnauth-mod.lua

+87-44
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
local sys = require "luci.sys"
55
require("luci.template")
66
local io = require("io")
7+
local util = require("luci.util")
8+
local class = util.class
79

810
m = Map("ovpnauth", translate("OpenVPN Server"))
11+
m:chain("openvpn")
12+
m:chain("network")
913

10-
s = m:section(TypedSection, "settings", "Server Configuration")
14+
-- OpenVPN Client settings
15+
16+
s = m:section(TypedSection, "settings", "Client Configuration")
1117
s.anonymous = true
1218

1319
s:option(Value, "external_ip", translate("WAN IP or DNS name"))
14-
s:option(Value, "external_port", translate("Server port"))
15-
pr = s:option(ListValue, "proto", translate("Protocol"))
16-
pr:value("tcp", "TCP")
17-
pr:value("udp", "UDP")
18-
s:option(Flag, "enabled", translate("Enabled"))
19-
2020
local d = Template("ovpnauth")
2121
s:append(d)
2222
function d.parse()
@@ -37,8 +37,8 @@ function d.parse()
3737
luci.http.write("persist-key\n")
3838
luci.http.write("persist-tun\n")
3939
local ext_ip = Map.formvalue(m, "cbid.ovpnauth.settings.external_ip")
40-
local ext_port = Map.formvalue(m, "cbid.ovpnauth.settings.external_port")
41-
local ext_proto = Map.formvalue(m, "cbid.ovpnauth.settings.proto")
40+
local ext_port = Map.formvalue(m, "cbid.openvpn.openvpn_server.port")
41+
local ext_proto = Map.formvalue(m, "cbid.openvpn.openvpn_server.proto")
4242
luci.http.write("remote " .. ext_ip .. " " .. ext_port .. " " .. ext_proto .. "\n")
4343
luci.http.write("resolv-retry infinite\n")
4444
luci.http.write("script-security 2\n")
@@ -69,6 +69,8 @@ function d.parse()
6969
end
7070
end
7171

72+
-- OpenVPN Users list
73+
7274
s = m:section(TypedSection, "user", translate("User accounts")
7375
, translate("Please add users who can connect to the VPN server."))
7476
s.anonymous = true
@@ -97,46 +99,87 @@ end
9799
ro = s:option(Flag, "enabled", translate("Enabled"))
98100
ro.rmempty = false
99101

100-
function m.on_save(self)
101-
-- sys.call("/usr/bin/gen_openvpn_server_keys.sh")
102+
-- Hidden values class
103+
104+
HiddenValue = class(DummyValue)
105+
106+
function HiddenValue.__init__(self, ...)
107+
DummyValue.__init__(self, ...)
108+
end
109+
110+
function HiddenValue.render(self, s, scope)
111+
end
112+
113+
-- OpenVPN Server settings
114+
115+
m1 = Map("openvpn", translate("OpenVPN Server"))
116+
s1 = m1:section(NamedSection, "openvpn_server", "openvpn")
117+
118+
o = s1:option(Value, "port", translate("Server port"))
119+
o.default = 1194
120+
121+
o = s1:option(ListValue, "proto", translate("Protocol"))
122+
o:value("tcp", "TCP")
123+
o:value("udp", "UDP")
124+
o.default = "udp"
125+
126+
o = s1:option(Value,"server",translate("Addresses range"))
127+
o.default = "10.8.0.0 255.255.255.0"
128+
129+
o = s1:option(Flag, "enabled", translate("Enabled"))
130+
o.default = true
131+
132+
o = s1:option(DynamicList, "push", translate("Push options to peer"))
133+
o.default = {"redirect-gateway", "dhcp-option DNS 10.8.0.1"}
134+
135+
o = s1:option(Flag, "client_to_client", translate("Allow client-to-client traffic"))
136+
o.default = true
137+
138+
o = s1:option(ListValue, "verb", translate("Set output verbosity"))
139+
o:value("0", "No log")
140+
o:value("3", "Normal log")
141+
o:value("5", "Dump traffic")
142+
o:value("11", "Debug")
143+
144+
local params = {
145+
{"dev", "tun", translate("Type of used device")},
146+
{"ca", "/etc/openvpn/ca.crt", translate("Certificate authority")},
147+
{"cert", "/etc/openvpn/server.crt", translate("Local certificate")},
148+
{"key", "/etc/openvpn/server.key", translate("Local private key")},
149+
{"dh", "/etc/openvpn/dh1024.pem", translate("Diffie Hellman parameters")},
150+
{"ifconfig_pool_persist", "/tmp/ipp.txt", translate("Persist/unpersist ifconfig-pool")},
151+
{"remote_cert_tls", "client", translate("Require explicit key usage on certificate")},
152+
{"keepalive", "10 120", translate("Keepalive")},
153+
{"tls_auth", "/etc/openvpn/ta.key 0", translate("Additional authentication over TLS")},
154+
{"cipher", "BF-CBC", translate("Encryption cipher for packets")},
155+
{"compress", "lzo", translate("Copmression")},
156+
{"persist_key", "1", translate("Don't re-read key on restart")},
157+
{"persist_tun", "1", translate("Keep tun/tap device open on restart")},
158+
{"status", "/tmp/openvpn-status.log", translate("Write status to file every n seconds")},
159+
{"script_security", "2", translate("Policy level over usage of external programs an)d scripts")},
160+
{"auth_user_pass_verify", "/usr/bin/ovpnauth.sh via-file", translate("Script used to authenticate users")},
161+
{"username_as_common_name", "1", translate("Use username as common name")}
162+
}
163+
164+
for _, option in ipairs(params) do
165+
local o = s1:option(HiddenValue, option[1], option[3])
166+
o.default = option[2]
167+
end
168+
169+
function m1.on_after_commit(self)
170+
sys.call("/etc/init.d/openvpn reload")
171+
end
172+
173+
function m1.on_save(self)
102174
local section = self.uci:section("openvpn", "openvpn", "openvpn_server")
103-
self.uci:set("openvpn", section, "port", self:get("settings", "external_port"))
104-
self.uci:set("openvpn", section, "proto", self:get("settings", "proto"))
105-
self.uci:set("openvpn", section, "enabled", self:get("settings", "enabled"))
106-
self.uci:set("openvpn", section, "dev", "tun")
107-
self.uci:set("openvpn", section, "ca", "/etc/openvpn/ca.crt")
108-
self.uci:set("openvpn", section, "cert", "/etc/openvpn/server.crt")
109-
self.uci:set("openvpn", section, "key", "/etc/openvpn/server.key")
110-
self.uci:set("openvpn", section, "dh", "/etc/openvpn/dh1024.pem")
111-
self.uci:set("openvpn", section, "server", "10.8.0.0 255.255.255.0")
112-
self.uci:set("openvpn", section, "ifconfig_pool_persist", "/tmp/ipp.txt")
113-
self.uci:set("openvpn", section, "client_to_client", "1")
114-
self.uci:set("openvpn", section, "remote_cert_tls", "client")
115-
self.uci:set("openvpn", section, "verb", "3")
116-
self.uci:set_list("openvpn", section, "push", {"redirect-gateway", "dhcp-option DNS 10.8.0.1"})
117-
self.uci:set("openvpn", section, "keepalive", "10 120")
118-
self.uci:set("openvpn", section, "tls_auth", "/etc/openvpn/ta.key 0")
119-
self.uci:set("openvpn", section, "cipher", "BF-CBC")
120-
self.uci:set("openvpn", section, "compress", "lzo")
121-
self.uci:set("openvpn", section, "persist_key", "1")
122-
self.uci:set("openvpn", section, "persist_tun", "1")
123-
self.uci:set("openvpn", section, "user", "nobody")
124-
self.uci:set("openvpn", section, "group", "nogroup")
125-
self.uci:set("openvpn", section, "status", "/tmp/openvpn-status.log")
126-
self.uci:set("openvpn", section, "script_security", "2")
127-
self.uci:set("openvpn", section, "auth_user_pass_verify", "/usr/bin/ovpnauth.sh via-file")
128-
self.uci:set("openvpn", section, "username_as_common_name", "1")
129-
175+
self.uci:delete("openvpn", section, "user")
176+
self.uci:delete("openvpn", section, "group")
177+
130178
local section = self.uci:section("network", "interface", "ovpn")
131179
self.uci:set("network", section, "auto", "1")
132180
self.uci:set("network", section, "ifname", "tun0")
133181
self.uci:set("network", section, "proto", "none")
134182
self.uci:set("network", section, "auto", "1")
135183
end
136184

137-
function m.on_after_commit(self)
138-
sys.call("/etc/init.d/openvpn reload")
139-
sys.call("chmod 644 /etc/config/ovpnauth")
140-
end
141-
142-
return m
185+
return m,m1

src/ovpnauth.sh

+1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ auth_cb() {
3535
config_foreach auth_cb 'user'
3636

3737
logger -t "$TAG" "OpenVPN user $USERNAME authentication failed"
38+
sleep 3
3839
exit 1

0 commit comments

Comments
 (0)