4
4
local sys = require " luci.sys"
5
5
require (" luci.template" )
6
6
local io = require (" io" )
7
+ local util = require (" luci.util" )
8
+ local class = util .class
7
9
8
10
m = Map (" ovpnauth" , translate (" OpenVPN Server" ))
11
+ m :chain (" openvpn" )
12
+ m :chain (" network" )
9
13
10
- s = m :section (TypedSection , " settings" , " Server Configuration" )
14
+ -- OpenVPN Client settings
15
+
16
+ s = m :section (TypedSection , " settings" , " Client Configuration" )
11
17
s .anonymous = true
12
18
13
19
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
-
20
20
local d = Template (" ovpnauth" )
21
21
s :append (d )
22
22
function d .parse ()
@@ -37,8 +37,8 @@ function d.parse()
37
37
luci .http .write (" persist-key\n " )
38
38
luci .http .write (" persist-tun\n " )
39
39
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" )
42
42
luci .http .write (" remote " .. ext_ip .. " " .. ext_port .. " " .. ext_proto .. " \n " )
43
43
luci .http .write (" resolv-retry infinite\n " )
44
44
luci .http .write (" script-security 2\n " )
@@ -69,6 +69,8 @@ function d.parse()
69
69
end
70
70
end
71
71
72
+ -- OpenVPN Users list
73
+
72
74
s = m :section (TypedSection , " user" , translate (" User accounts" )
73
75
, translate (" Please add users who can connect to the VPN server." ))
74
76
s .anonymous = true
97
99
ro = s :option (Flag , " enabled" , translate (" Enabled" ))
98
100
ro .rmempty = false
99
101
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 )
102
174
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
+
130
178
local section = self .uci :section (" network" , " interface" , " ovpn" )
131
179
self .uci :set (" network" , section , " auto" , " 1" )
132
180
self .uci :set (" network" , section , " ifname" , " tun0" )
133
181
self .uci :set (" network" , section , " proto" , " none" )
134
182
self .uci :set (" network" , section , " auto" , " 1" )
135
183
end
136
184
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
0 commit comments