]>
Commit | Line | Data |
---|---|---|
6e13d0a5 | 1 | #!/usr/bin/perl |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
49abe7af | 5 | # Copyright (C) 2007-2014 IPFire Team <info@ipfire.org> # |
70df8302 MT |
6 | # # |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
54fd0535 | 21 | ### |
54fd0535 | 22 | ### |
6e13d0a5 MT |
23 | use CGI; |
24 | use CGI qw/:standard/; | |
25 | use Net::DNS; | |
ce9abb66 | 26 | use Net::Ping; |
54fd0535 | 27 | use Net::Telnet; |
6e13d0a5 MT |
28 | use File::Copy; |
29 | use File::Temp qw/ tempfile tempdir /; | |
30 | use strict; | |
31 | use Archive::Zip qw(:ERROR_CODES :CONSTANTS); | |
eff2dbf8 | 32 | use Sort::Naturally; |
6e13d0a5 | 33 | require '/var/ipfire/general-functions.pl'; |
6e13d0a5 MT |
34 | require "${General::swroot}/lang.pl"; |
35 | require "${General::swroot}/header.pl"; | |
36 | require "${General::swroot}/countries.pl"; | |
37 | ||
38 | # enable only the following on debugging purpose | |
8c877a82 AM |
39 | #use warnings; |
40 | #use CGI::Carp 'fatalsToBrowser'; | |
6e13d0a5 | 41 | #workaround to suppress a warning when a variable is used only once |
8c877a82 | 42 | my @dummy = ( ${Header::colourgreen}, ${Header::colourblue} ); |
6e13d0a5 MT |
43 | undef (@dummy); |
44 | ||
f2fdd0c1 CS |
45 | my %color = (); |
46 | my %mainsettings = (); | |
47 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
48 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
6e13d0a5 MT |
49 | |
50 | ### | |
51 | ### Initialize variables | |
52 | ### | |
e81be1e1 AM |
53 | my %ccdconfhash=(); |
54 | my %ccdroutehash=(); | |
55 | my %ccdroute2hash=(); | |
6e13d0a5 MT |
56 | my %netsettings=(); |
57 | my %cgiparams=(); | |
58 | my %vpnsettings=(); | |
59 | my %checked=(); | |
60 | my %confighash=(); | |
61 | my %cahash=(); | |
62 | my %selected=(); | |
63 | my $warnmessage = ''; | |
64 | my $errormessage = ''; | |
65 | my %settings=(); | |
54fd0535 | 66 | my $routes_push_file = ''; |
df9b48b7 AM |
67 | my $confighost="${General::swroot}/fwhosts/customhosts"; |
68 | my $configgrp="${General::swroot}/fwhosts/customgroups"; | |
69 | my $customnet="${General::swroot}/fwhosts/customnetworks"; | |
70 | my $name; | |
99bfa85c | 71 | my $col=""; |
6e13d0a5 MT |
72 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); |
73 | $cgiparams{'ENABLED'} = 'off'; | |
74 | $cgiparams{'ENABLED_BLUE'} = 'off'; | |
75 | $cgiparams{'ENABLED_ORANGE'} = 'off'; | |
76 | $cgiparams{'EDIT_ADVANCED'} = 'off'; | |
77 | $cgiparams{'NAT'} = 'off'; | |
78 | $cgiparams{'COMPRESSION'} = 'off'; | |
79 | $cgiparams{'ONLY_PROPOSED'} = 'off'; | |
80 | $cgiparams{'ACTION'} = ''; | |
81 | $cgiparams{'CA_NAME'} = ''; | |
4c962356 EK |
82 | $cgiparams{'DH_NAME'} = 'dh1024.pem'; |
83 | $cgiparams{'DHLENGHT'} = ''; | |
6e13d0a5 MT |
84 | $cgiparams{'DHCP_DOMAIN'} = ''; |
85 | $cgiparams{'DHCP_DNS'} = ''; | |
86 | $cgiparams{'DHCP_WINS'} = ''; | |
54fd0535 | 87 | $cgiparams{'ROUTES_PUSH'} = ''; |
6e13d0a5 | 88 | $cgiparams{'DCOMPLZO'} = 'off'; |
a79fa1d6 | 89 | $cgiparams{'MSSFIX'} = ''; |
8c877a82 | 90 | $cgiparams{'number'} = ''; |
2ee746be | 91 | $cgiparams{'PMTU_DISCOVERY'} = ''; |
4c962356 | 92 | $cgiparams{'DCIPHER'} = ''; |
49abe7af EK |
93 | $cgiparams{'DAUTH'} = ''; |
94 | $cgiparams{'TLSAUTH'} = ''; | |
95 | $cgiparams{'ENGINES'} = ''; | |
54fd0535 MT |
96 | $routes_push_file = "${General::swroot}/ovpn/routes_push"; |
97 | unless (-e $routes_push_file) { system("touch $routes_push_file"); } | |
8c877a82 AM |
98 | unless (-e "${General::swroot}/ovpn/ccd.conf") { system("touch ${General::swroot}/ovpn/ccd.conf"); } |
99 | unless (-e "${General::swroot}/ovpn/ccdroute") { system("touch ${General::swroot}/ovpn/ccdroute"); } | |
100 | unless (-e "${General::swroot}/ovpn/ccdroute2") { system("touch ${General::swroot}/ovpn/ccdroute2"); } | |
ce9abb66 | 101 | |
6e13d0a5 MT |
102 | &Header::getcgihash(\%cgiparams, {'wantfile' => 1, 'filevar' => 'FH'}); |
103 | ||
104 | # prepare openvpn config file | |
105 | ### | |
106 | ### Useful functions | |
107 | ### | |
c6c9630e MT |
108 | sub haveOrangeNet |
109 | { | |
13211b21 CS |
110 | if ($netsettings{'CONFIG_TYPE'} == 2) {return 1;} |
111 | if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;} | |
c6c9630e MT |
112 | return 0; |
113 | } | |
114 | ||
115 | sub haveBlueNet | |
116 | { | |
13211b21 | 117 | if ($netsettings{'CONFIG_TYPE'} == 3) {return 1;} |
c6c9630e | 118 | if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;} |
c6c9630e MT |
119 | return 0; |
120 | } | |
121 | ||
122 | sub sizeformat{ | |
123 | my $bytesize = shift; | |
124 | my $i = 0; | |
125 | ||
126 | while(abs($bytesize) >= 1024){ | |
127 | $bytesize=$bytesize/1024; | |
128 | $i++; | |
129 | last if($i==6); | |
130 | } | |
131 | ||
132 | my @units = ("Bytes","KB","MB","GB","TB","PB","EB"); | |
133 | my $newsize=(int($bytesize*100 +0.5))/100; | |
134 | return("$newsize $units[$i]"); | |
135 | } | |
136 | ||
c6c9630e MT |
137 | sub cleanssldatabase |
138 | { | |
139 | if (open(FILE, ">${General::swroot}/ovpn/certs/serial")) { | |
140 | print FILE "01"; | |
141 | close FILE; | |
142 | } | |
143 | if (open(FILE, ">${General::swroot}/ovpn/certs/index.txt")) { | |
144 | print FILE ""; | |
145 | close FILE; | |
146 | } | |
147 | unlink ("${General::swroot}/ovpn/certs/index.txt.old"); | |
148 | unlink ("${General::swroot}/ovpn/certs/serial.old"); | |
149 | unlink ("${General::swroot}/ovpn/certs/01.pem"); | |
150 | } | |
151 | ||
152 | sub newcleanssldatabase | |
153 | { | |
154 | if (! -s "${General::swroot}/ovpn/certs/serial" ) { | |
155 | open(FILE, ">${General::swroot}(ovpn/certs/serial"); | |
156 | print FILE "01"; | |
157 | close FILE; | |
158 | } | |
159 | if (! -s ">${General::swroot}/ovpn/certs/index.txt") { | |
160 | system ("touch ${General::swroot}/ovpn/certs/index.txt"); | |
161 | } | |
162 | unlink ("${General::swroot}/ovpn/certs/index.txt.old"); | |
163 | unlink ("${General::swroot}/ovpn/certs/serial.old"); | |
164 | } | |
165 | ||
166 | sub deletebackupcert | |
167 | { | |
168 | if (open(FILE, "${General::swroot}/ovpn/certs/serial.old")) { | |
169 | my $hexvalue = <FILE>; | |
170 | chomp $hexvalue; | |
171 | close FILE; | |
172 | unlink ("${General::swroot}/ovpn/certs/$hexvalue.pem"); | |
173 | } | |
174 | } | |
c6c9630e | 175 | sub checkportfw { |
6945e463 AM |
176 | my $DPORT = shift; |
177 | my $DPROT = shift; | |
178 | my %natconfig =(); | |
6d8eb5de | 179 | my $confignat = "${General::swroot}/firewall/config"; |
6945e463 AM |
180 | $DPROT= uc ($DPROT); |
181 | &General::readhasharray($confignat, \%natconfig); | |
182 | foreach my $key (sort keys %natconfig){ | |
6945e463 AM |
183 | my @portarray = split (/\|/,$natconfig{$key}[30]); |
184 | foreach my $value (@portarray){ | |
6945e463 AM |
185 | if ($value =~ /:/i){ |
186 | my ($a,$b) = split (":",$value); | |
187 | if ($DPROT eq $natconfig{$key}[12] && $DPORT gt $a && $DPORT lt $b){ | |
188 | $errormessage= "$Lang::tr{'source port in use'} $DPORT"; | |
189 | } | |
190 | }else{ | |
191 | if ($DPROT eq $natconfig{$key}[12] && $DPORT eq $value){ | |
192 | $errormessage= "$Lang::tr{'source port in use'} $DPORT"; | |
193 | } | |
194 | } | |
c6c9630e MT |
195 | } |
196 | } | |
6945e463 | 197 | return; |
c6c9630e MT |
198 | } |
199 | ||
200 | sub checkportoverlap | |
201 | { | |
202 | my $portrange1 = $_[0]; # New port range | |
203 | my $portrange2 = $_[1]; # existing port range | |
204 | my @tempr1 = split(/\:/,$portrange1); | |
205 | my @tempr2 = split(/\:/,$portrange2); | |
206 | ||
207 | unless (&checkportinc($tempr1[0], $portrange2)){ return 0;} | |
208 | unless (&checkportinc($tempr1[1], $portrange2)){ return 0;} | |
209 | ||
210 | unless (&checkportinc($tempr2[0], $portrange1)){ return 0;} | |
211 | unless (&checkportinc($tempr2[1], $portrange1)){ return 0;} | |
212 | ||
213 | return 1; # Everything checks out! | |
214 | } | |
215 | ||
216 | # Darren Critchley - we want to make sure that a port entry is not within an already existing range | |
217 | sub checkportinc | |
218 | { | |
219 | my $port1 = $_[0]; # Port | |
220 | my $portrange2 = $_[1]; # Port range | |
221 | my @tempr1 = split(/\:/,$portrange2); | |
222 | ||
223 | if ($port1 < $tempr1[0] || $port1 > $tempr1[1]) { | |
224 | return 1; | |
225 | } else { | |
226 | return 0; | |
227 | } | |
228 | } | |
c6c9630e | 229 | |
b2e75449 MT |
230 | # Darren Critchley - certain ports are reserved for IPFire |
231 | # TCP 67,68,81,222,444 | |
232 | # UDP 67,68 | |
233 | # Params passed in -> port, rangeyn, protocol | |
234 | sub disallowreserved | |
235 | { | |
236 | # port 67 and 68 same for tcp and udp, don't bother putting in an array | |
237 | my $msg = ""; | |
238 | my @tcp_reserved = (81,222,444); | |
239 | my $prt = $_[0]; # the port or range | |
240 | my $ryn = $_[1]; # tells us whether or not it is a port range | |
241 | my $prot = $_[2]; # protocol | |
242 | my $srcdst = $_[3]; # source or destination | |
243 | if ($ryn) { # disect port range | |
244 | if ($srcdst eq "src") { | |
245 | $msg = "$Lang::tr{'rsvd src port overlap'}"; | |
246 | } else { | |
247 | $msg = "$Lang::tr{'rsvd dst port overlap'}"; | |
248 | } | |
249 | my @tmprng = split(/\:/,$prt); | |
250 | unless (67 < $tmprng[0] || 67 > $tmprng[1]) { $errormessage="$msg 67"; return; } | |
251 | unless (68 < $tmprng[0] || 68 > $tmprng[1]) { $errormessage="$msg 68"; return; } | |
252 | if ($prot eq "tcp") { | |
253 | foreach my $prange (@tcp_reserved) { | |
254 | unless ($prange < $tmprng[0] || $prange > $tmprng[1]) { $errormessage="$msg $prange"; return; } | |
255 | } | |
256 | } | |
257 | } else { | |
258 | if ($srcdst eq "src") { | |
259 | $msg = "$Lang::tr{'reserved src port'}"; | |
260 | } else { | |
261 | $msg = "$Lang::tr{'reserved dst port'}"; | |
262 | } | |
263 | if ($prt == 67) { $errormessage="$msg 67"; return; } | |
264 | if ($prt == 68) { $errormessage="$msg 68"; return; } | |
265 | if ($prot eq "tcp") { | |
266 | foreach my $prange (@tcp_reserved) { | |
267 | if ($prange == $prt) { $errormessage="$msg $prange"; return; } | |
268 | } | |
269 | } | |
270 | } | |
271 | return; | |
272 | } | |
273 | ||
4c962356 | 274 | |
c6c9630e | 275 | sub writeserverconf { |
54fd0535 MT |
276 | my %sovpnsettings = (); |
277 | my @temp = (); | |
c6c9630e | 278 | &General::readhash("${General::swroot}/ovpn/settings", \%sovpnsettings); |
54fd0535 MT |
279 | &read_routepushfile; |
280 | ||
c6c9630e MT |
281 | open(CONF, ">${General::swroot}/ovpn/server.conf") or die "Unable to open ${General::swroot}/ovpn/server.conf: $!"; |
282 | flock CONF, 2; | |
283 | print CONF "#OpenVPN Server conf\n"; | |
284 | print CONF "\n"; | |
285 | print CONF "daemon openvpnserver\n"; | |
286 | print CONF "writepid /var/run/openvpn.pid\n"; | |
afabe9f7 | 287 | print CONF "#DAN prepare OpenVPN for listening on blue and orange\n"; |
c6c9630e MT |
288 | print CONF ";local $sovpnsettings{'VPN_IP'}\n"; |
289 | print CONF "dev $sovpnsettings{'DDEVICE'}\n"; | |
c6c9630e MT |
290 | print CONF "proto $sovpnsettings{'DPROTOCOL'}\n"; |
291 | print CONF "port $sovpnsettings{'DDEST_PORT'}\n"; | |
2b29c22e | 292 | print CONF "script-security 3 system\n"; |
07675dc3 | 293 | print CONF "ifconfig-pool-persist /var/ipfire/ovpn/ovpn-leases.db 3600\n"; |
6140e7e0 | 294 | print CONF "client-config-dir /var/ipfire/ovpn/ccd\n"; |
c6c9630e | 295 | print CONF "tls-server\n"; |
4c962356 EK |
296 | print CONF "ca ${General::swroot}/ovpn/ca/cacert.pem\n"; |
297 | print CONF "cert ${General::swroot}/ovpn/certs/servercert.pem\n"; | |
298 | print CONF "key ${General::swroot}/ovpn/certs/serverkey.pem\n"; | |
49abe7af | 299 | print CONF "dh ${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}\n"; |
c6c9630e MT |
300 | my @tempovpnsubnet = split("\/",$sovpnsettings{'DOVPN_SUBNET'}); |
301 | print CONF "server $tempovpnsubnet[0] $tempovpnsubnet[1]\n"; | |
8c877a82 | 302 | #print CONF "push \"route $netsettings{'GREEN_NETADDRESS'} $netsettings{'GREEN_NETMASK'}\"\n"; |
4c962356 | 303 | |
2ee746be SS |
304 | # Check if we are using mssfix, fragment or mtu-disc and set the corretct mtu of 1500. |
305 | # If we doesn't use one of them, we can use the configured mtu value. | |
306 | if ($sovpnsettings{'MSSFIX'} eq 'on') | |
307 | { print CONF "$sovpnsettings{'DDEVICE'}-mtu 1500\n"; } | |
308 | elsif ($sovpnsettings{'FRAGMENT'} ne '' && $sovpnsettings{'DPROTOCOL'} ne 'tcp') | |
309 | { print CONF "$sovpnsettings{'DDEVICE'}-mtu 1500\n"; } | |
1647059d | 310 | elsif (($sovpnsettings{'PMTU_DISCOVERY'} eq 'yes') || |
4c962356 EK |
311 | ($sovpnsettings{'PMTU_DISCOVERY'} eq 'maybe') || |
312 | ($sovpnsettings{'PMTU_DISCOVERY'} eq 'no' )) | |
2ee746be SS |
313 | { print CONF "$sovpnsettings{'DDEVICE'}-mtu 1500\n"; } |
314 | else | |
315 | { print CONF "$sovpnsettings{'DDEVICE'}-mtu $sovpnsettings{'DMTU'}\n"; } | |
316 | ||
54fd0535 | 317 | if ($vpnsettings{'ROUTES_PUSH'} ne '') { |
8c877a82 AM |
318 | @temp = split(/\n/,$vpnsettings{'ROUTES_PUSH'}); |
319 | foreach (@temp) | |
320 | { | |
321 | @tempovpnsubnet = split("\/",&General::ipcidr2msk($_)); | |
322 | print CONF "push \"route " . $tempovpnsubnet[0]. " " . $tempovpnsubnet[1] . "\"\n"; | |
323 | } | |
54fd0535 | 324 | } |
8c877a82 AM |
325 | # a.marx ccd |
326 | my %ccdconfhash=(); | |
327 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
328 | foreach my $key (keys %ccdconfhash) { | |
329 | my $a=$ccdconfhash{$key}[1]; | |
330 | my ($b,$c) = split (/\//, $a); | |
331 | print CONF "route $b ".&General::cidrtosub($c)."\n"; | |
332 | } | |
333 | my %ccdroutehash=(); | |
334 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
335 | foreach my $key (keys %ccdroutehash) { | |
336 | foreach my $i ( 1 .. $#{$ccdroutehash{$key}}){ | |
337 | my ($a,$b)=split (/\//,$ccdroutehash{$key}[$i]); | |
338 | print CONF "route $a $b\n"; | |
339 | } | |
340 | } | |
341 | # ccd end | |
54fd0535 | 342 | |
8c877a82 | 343 | if ($sovpnsettings{CLIENT2CLIENT} eq 'on') { |
c6c9630e MT |
344 | print CONF "client-to-client\n"; |
345 | } | |
1de5c945 | 346 | if ($sovpnsettings{MSSFIX} eq 'on') { |
4c962356 | 347 | print CONF "mssfix\n"; |
1de5c945 EK |
348 | } |
349 | if ($sovpnsettings{FRAGMENT} ne '' && $sovpnsettings{'DPROTOCOL'} ne 'tcp') { | |
4c962356 | 350 | print CONF "fragment $sovpnsettings{'FRAGMENT'}\n"; |
a79fa1d6 | 351 | } |
2ee746be | 352 | |
1647059d SS |
353 | # Check if a valid operating mode has been choosen and use it. |
354 | if (($sovpnsettings{'PMTU_DISCOVERY'} eq 'yes') || | |
355 | ($sovpnsettings{'PMTU_DISCOVERY'} eq 'maybe') || | |
356 | ($sovpnsettings{'PMTU_DISCOVERY'} eq 'no' )) { | |
357 | print CONF "mtu-disc $sovpnsettings{'PMTU_DISCOVERY'}\n"; | |
2ee746be SS |
358 | } |
359 | ||
c6c9630e MT |
360 | if ($sovpnsettings{KEEPALIVE_1} > 0 && $sovpnsettings{KEEPALIVE_2} > 0) { |
361 | print CONF "keepalive $sovpnsettings{'KEEPALIVE_1'} $sovpnsettings{'KEEPALIVE_2'}\n"; | |
362 | } | |
363 | print CONF "status-version 1\n"; | |
4e17adad | 364 | print CONF "status /var/log/ovpnserver.log 30\n"; |
c6c9630e | 365 | print CONF "cipher $sovpnsettings{DCIPHER}\n"; |
49abe7af EK |
366 | if ($sovpnsettings{'DAUTH'} eq '') { |
367 | print CONF ""; | |
368 | } else { | |
369 | print CONF "auth $sovpnsettings{'DAUTH'}\n"; | |
370 | } | |
371 | if ($sovpnsettings{'TLSAUTH'} eq 'on') { | |
372 | print CONF "tls-auth ${General::swroot}/ovpn/ca/ta.key 0\n"; | |
373 | } | |
374 | if ($sovpnsettings{ENGINES} eq 'disabled') { | |
375 | print CONF ""; | |
376 | } else { | |
377 | print CONF "engine $sovpnsettings{ENGINES}\n"; | |
378 | } | |
c6c9630e MT |
379 | if ($sovpnsettings{DCOMPLZO} eq 'on') { |
380 | print CONF "comp-lzo\n"; | |
381 | } | |
382 | if ($sovpnsettings{REDIRECT_GW_DEF1} eq 'on') { | |
383 | print CONF "push \"redirect-gateway def1\"\n"; | |
384 | } | |
385 | if ($sovpnsettings{DHCP_DOMAIN} ne '') { | |
386 | print CONF "push \"dhcp-option DOMAIN $sovpnsettings{DHCP_DOMAIN}\"\n"; | |
387 | } | |
388 | ||
389 | if ($sovpnsettings{DHCP_DNS} ne '') { | |
390 | print CONF "push \"dhcp-option DNS $sovpnsettings{DHCP_DNS}\"\n"; | |
391 | } | |
392 | ||
393 | if ($sovpnsettings{DHCP_WINS} ne '') { | |
394 | print CONF "push \"dhcp-option WINS $sovpnsettings{DHCP_WINS}\"\n"; | |
395 | } | |
396 | ||
397 | if ($sovpnsettings{DHCP_WINS} eq '') { | |
398 | print CONF "max-clients 100\n"; | |
a79fa1d6 | 399 | } |
c6c9630e MT |
400 | if ($sovpnsettings{DHCP_WINS} ne '') { |
401 | print CONF "max-clients $sovpnsettings{MAX_CLIENTS}\n"; | |
402 | } | |
1d0a260a | 403 | print CONF "tls-verify /usr/lib/openvpn/verify\n"; |
c6c9630e MT |
404 | print CONF "crl-verify /var/ipfire/ovpn/crls/cacrl.pem\n"; |
405 | print CONF "user nobody\n"; | |
406 | print CONF "group nobody\n"; | |
407 | print CONF "persist-key\n"; | |
408 | print CONF "persist-tun\n"; | |
409 | if ($sovpnsettings{LOG_VERB} ne '') { | |
410 | print CONF "verb $sovpnsettings{LOG_VERB}\n"; | |
411 | } else { | |
412 | print CONF "verb 3\n"; | |
413 | } | |
414 | print CONF "\n"; | |
415 | ||
416 | close(CONF); | |
417 | } | |
8c877a82 | 418 | |
c6c9630e | 419 | sub emptyserverlog{ |
4e17adad | 420 | if (open(FILE, ">/var/log/ovpnserver.log")) { |
c6c9630e MT |
421 | flock FILE, 2; |
422 | print FILE ""; | |
423 | close FILE; | |
424 | } | |
425 | ||
426 | } | |
427 | ||
8c877a82 AM |
428 | sub delccdnet |
429 | { | |
430 | my %ccdconfhash = (); | |
431 | my %ccdhash = (); | |
432 | my $ccdnetname=$_[0]; | |
433 | if (-f "${General::swroot}/ovpn/ovpnconfig"){ | |
434 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
435 | foreach my $key (keys %ccdhash) { | |
436 | if ($ccdhash{$key}[32] eq $ccdnetname) { | |
437 | $errormessage=$Lang::tr{'ccd err hostinnet'}; | |
438 | return; | |
439 | } | |
440 | } | |
441 | } | |
442 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
443 | foreach my $key (keys %ccdconfhash) { | |
444 | if ($ccdconfhash{$key}[0] eq $ccdnetname){ | |
445 | delete $ccdconfhash{$key}; | |
446 | } | |
447 | } | |
448 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
449 | ||
450 | &writeserverconf; | |
451 | return 0; | |
452 | } | |
453 | ||
454 | sub addccdnet | |
455 | { | |
456 | my %ccdconfhash=(); | |
457 | my @ccdconf=(); | |
458 | my $ccdname=$_[0]; | |
459 | my $ccdnet=$_[1]; | |
8c877a82 AM |
460 | my $subcidr; |
461 | my @ip2=(); | |
462 | my $checkup; | |
463 | my $ccdip; | |
464 | my $baseaddress; | |
290007b3 AM |
465 | |
466 | ||
467 | #check name | |
468 | if ($ccdname eq '') | |
469 | { | |
470 | $errormessage=$errormessage.$Lang::tr{'ccd err name'}."<br>"; | |
471 | return | |
472 | } | |
473 | ||
474 | if(!&General::validhostname($ccdname)) | |
475 | { | |
8c877a82 AM |
476 | $errormessage=$Lang::tr{'ccd err invalidname'}; |
477 | return; | |
478 | } | |
290007b3 AM |
479 | |
480 | ($ccdip,$subcidr) = split (/\//,$ccdnet); | |
481 | $subcidr=&General::iporsubtocidr($subcidr); | |
482 | #check subnet | |
483 | if ($subcidr > 30) | |
484 | { | |
8c877a82 AM |
485 | $errormessage=$Lang::tr{'ccd err invalidnet'}; |
486 | return; | |
487 | } | |
290007b3 AM |
488 | #check ip |
489 | if (!&General::validipandmask($ccdnet)){ | |
490 | $errormessage=$Lang::tr{'ccd err invalidnet'}; | |
491 | return; | |
8c877a82 | 492 | } |
290007b3 | 493 | |
e2429e8d | 494 | $errormessage=&General::checksubnets($ccdname,$ccdnet); |
290007b3 | 495 | |
8c877a82 AM |
496 | |
497 | if (!$errormessage) { | |
498 | my %ccdconfhash=(); | |
499 | $baseaddress=&General::getnetworkip($ccdip,$subcidr); | |
500 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
501 | my $key = &General::findhasharraykey (\%ccdconfhash); | |
502 | foreach my $i (0 .. 1) { $ccdconfhash{$key}[$i] = "";} | |
503 | $ccdconfhash{$key}[0] = $ccdname; | |
504 | $ccdconfhash{$key}[1] = $baseaddress."/".$subcidr; | |
505 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
506 | &writeserverconf; | |
507 | $cgiparams{'ccdname'}=''; | |
508 | $cgiparams{'ccdsubnet'}=''; | |
509 | return 1; | |
510 | } | |
511 | } | |
512 | ||
513 | sub modccdnet | |
514 | { | |
515 | ||
516 | my $newname=$_[0]; | |
517 | my $oldname=$_[1]; | |
518 | my %ccdconfhash=(); | |
519 | my %ccdhash=(); | |
520 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
521 | foreach my $key (keys %ccdconfhash) { | |
522 | if ($ccdconfhash{$key}[0] eq $oldname) { | |
523 | foreach my $key1 (keys %ccdconfhash) { | |
524 | if ($ccdconfhash{$key1}[0] eq $newname){ | |
525 | $errormessage=$errormessage.$Lang::tr{'ccd err netadrexist'}; | |
526 | return; | |
527 | }else{ | |
528 | $ccdconfhash{$key}[0]= $newname; | |
529 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
530 | last; | |
531 | } | |
532 | } | |
533 | } | |
534 | } | |
535 | ||
536 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
537 | foreach my $key (keys %ccdhash) { | |
538 | if ($ccdhash{$key}[32] eq $oldname) { | |
539 | $ccdhash{$key}[32]=$newname; | |
540 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
541 | last; | |
542 | } | |
543 | } | |
544 | ||
545 | return 0; | |
546 | } | |
547 | sub ccdmaxclients | |
548 | { | |
549 | my $ccdnetwork=$_[0]; | |
550 | my @octets=(); | |
551 | my @subnet=(); | |
552 | @octets=split("\/",$ccdnetwork); | |
553 | @subnet= split /\./, &General::cidrtosub($octets[1]); | |
554 | my ($a,$b,$c,$d,$e); | |
555 | $a=256-$subnet[0]; | |
556 | $b=256-$subnet[1]; | |
557 | $c=256-$subnet[2]; | |
558 | $d=256-$subnet[3]; | |
559 | $e=($a*$b*$c*$d)/4; | |
560 | return $e-1; | |
561 | } | |
562 | ||
563 | sub getccdadresses | |
564 | { | |
565 | my $ipin=$_[0]; | |
566 | my ($ip1,$ip2,$ip3,$ip4)=split /\./, $ipin; | |
567 | my $cidr=$_[1]; | |
568 | chomp($cidr); | |
569 | my $count=$_[2]; | |
570 | my $hasip=$_[3]; | |
571 | chomp($hasip); | |
572 | my @iprange=(); | |
573 | my %ccdhash=(); | |
574 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
b2e75449 | 575 | $iprange[0]=$ip1.".".$ip2.".".$ip3.".".2; |
ac87f371 | 576 | for (my $i=1;$i<=$count;$i++) { |
8c877a82 AM |
577 | my $tmpip=$iprange[$i-1]; |
578 | my $stepper=$i*4; | |
579 | $iprange[$i]= &General::getnextip($tmpip,4); | |
580 | } | |
581 | my $r=0; | |
582 | foreach my $key (keys %ccdhash) { | |
583 | $r=0; | |
584 | foreach my $tmp (@iprange){ | |
585 | my ($net,$sub) = split (/\//,$ccdhash{$key}[33]); | |
586 | if ($net eq $tmp) { | |
587 | if ( $hasip ne $ccdhash{$key}[33] ){ | |
588 | splice (@iprange,$r,1); | |
589 | } | |
590 | } | |
591 | $r++; | |
592 | } | |
593 | } | |
594 | return @iprange; | |
595 | } | |
596 | ||
597 | sub fillselectbox | |
598 | { | |
599 | my $boxname=$_[1]; | |
600 | my ($ccdip,$subcidr) = split("/",$_[0]); | |
601 | my $tz=$_[2]; | |
602 | my @allccdips=&getccdadresses($ccdip,$subcidr,&ccdmaxclients($ccdip."/".$subcidr),$tz); | |
603 | print"<select name='$boxname' STYLE='font-family : arial; font-size : 9pt; width:130px;' >"; | |
604 | foreach (@allccdips) { | |
605 | my $ip=$_."/30"; | |
606 | chomp($ip); | |
607 | print "<option value='$ip' "; | |
608 | if ( $ip eq $cgiparams{$boxname} ){ | |
609 | print"selected"; | |
610 | } | |
611 | print ">$ip</option>"; | |
612 | } | |
613 | print "</select>"; | |
614 | } | |
615 | ||
616 | sub hostsinnet | |
617 | { | |
618 | my $name=$_[0]; | |
619 | my %ccdhash=(); | |
620 | my $i=0; | |
621 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
622 | foreach my $key (keys %ccdhash) { | |
623 | if ($ccdhash{$key}[32] eq $name){ $i++;} | |
624 | } | |
625 | return $i; | |
626 | } | |
627 | ||
628 | sub check_routes_push | |
629 | { | |
630 | my $val=$_[0]; | |
631 | my ($ip,$cidr) = split (/\//, $val); | |
632 | ##check for existing routes in routes_push | |
633 | if (-e "${General::swroot}/ovpn/routes_push") { | |
634 | open(FILE,"${General::swroot}/ovpn/routes_push"); | |
635 | while (<FILE>) { | |
636 | $_=~s/\s*$//g; | |
637 | ||
638 | my ($ip2,$cidr2) = split (/\//,"$_"); | |
639 | my $val2=$ip2."/".&General::iporsubtodec($cidr2); | |
640 | ||
641 | if($val eq $val2){ | |
642 | return 0; | |
643 | } | |
644 | #subnetcheck | |
645 | if (&General::IpInSubnet ($ip,$ip2,&General::iporsubtodec($cidr2))){ | |
646 | return 0; | |
647 | } | |
648 | }; | |
649 | close(FILE); | |
650 | } | |
651 | return 1; | |
652 | } | |
653 | ||
654 | sub check_ccdroute | |
655 | { | |
656 | my %ccdroutehash=(); | |
657 | my $val=$_[0]; | |
658 | my ($ip,$cidr) = split (/\//, $val); | |
659 | #check for existing routes in ccdroute | |
660 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
661 | foreach my $key (keys %ccdroutehash) { | |
662 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { | |
663 | if (&General::iporsubtodec($val) eq $ccdroutehash{$key}[$i] && $ccdroutehash{$key}[0] ne $cgiparams{'NAME'}){ | |
664 | return 0; | |
665 | } | |
666 | my ($ip2,$cidr2) = split (/\//,$ccdroutehash{$key}[$i]); | |
667 | #subnetcheck | |
668 | if (&General::IpInSubnet ($ip,$ip2,$cidr2)&& $ccdroutehash{$key}[0] ne $cgiparams{'NAME'} ){ | |
669 | return 0; | |
670 | } | |
671 | } | |
672 | } | |
673 | return 1; | |
674 | } | |
675 | sub check_ccdconf | |
676 | { | |
677 | my %ccdconfhash=(); | |
678 | my $val=$_[0]; | |
679 | my ($ip,$cidr) = split (/\//, $val); | |
680 | #check for existing routes in ccdroute | |
681 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
682 | foreach my $key (keys %ccdconfhash) { | |
683 | if (&General::iporsubtocidr($val) eq $ccdconfhash{$key}[1]){ | |
684 | return 0; | |
685 | } | |
686 | my ($ip2,$cidr2) = split (/\//,$ccdconfhash{$key}[1]); | |
687 | #subnetcheck | |
688 | if (&General::IpInSubnet ($ip,$ip2,&General::cidrtosub($cidr2))){ | |
689 | return 0; | |
690 | } | |
691 | ||
692 | } | |
693 | return 1; | |
694 | } | |
695 | ||
7c1d9faf AH |
696 | ### |
697 | # m.a.d net2net | |
698 | ### | |
699 | ||
700 | sub validdotmask | |
701 | { | |
702 | my $ipdotmask = $_[0]; | |
703 | if (&General::validip($ipdotmask)) { return 0; } | |
704 | if (!($ipdotmask =~ /^(.*?)\/(.*?)$/)) { } | |
705 | my $mask = $2; | |
706 | if (($mask =~ /\./ )) { return 0; } | |
707 | return 1; | |
708 | } | |
54fd0535 MT |
709 | |
710 | # ------------------------------------------------------------------- | |
711 | ||
712 | sub write_routepushfile | |
713 | { | |
714 | open(FILE, ">$routes_push_file"); | |
715 | flock(FILE, 2); | |
716 | if ($vpnsettings{'ROUTES_PUSH'} ne '') { | |
717 | print FILE $vpnsettings{'ROUTES_PUSH'}; | |
718 | } | |
719 | close(FILE); | |
720 | } | |
721 | ||
722 | sub read_routepushfile | |
723 | { | |
724 | if (-e "$routes_push_file") { | |
725 | open(FILE,"$routes_push_file"); | |
726 | delete $vpnsettings{'ROUTES_PUSH'}; | |
727 | while (<FILE>) { $vpnsettings{'ROUTES_PUSH'} .= $_ }; | |
728 | close(FILE); | |
729 | $cgiparams{'ROUTES_PUSH'} = $vpnsettings{'ROUTES_PUSH'}; | |
8c877a82 | 730 | |
54fd0535 MT |
731 | } |
732 | } | |
7c1d9faf AH |
733 | |
734 | ||
c6c9630e MT |
735 | #hier die refresh page |
736 | if ( -e "${General::swroot}/ovpn/gencanow") { | |
737 | my $refresh = ''; | |
738 | $refresh = "<meta http-equiv='refresh' content='15;' />"; | |
739 | &Header::showhttpheaders(); | |
740 | &Header::openpage($Lang::tr{'OVPN'}, 1, $refresh); | |
741 | &Header::openbigbox('100%', 'center'); | |
742 | &Header::openbox('100%', 'left', "$Lang::tr{'generate root/host certificates'}:"); | |
743 | print "<tr>\n<td align='center'><img src='/images/clock.gif' alt='' /></td>\n"; | |
744 | print "<td colspan='2'><font color='red'>Please be patient this realy can take some time on older hardware...</font></td></tr>\n"; | |
745 | &Header::closebox(); | |
746 | &Header::closebigbox(); | |
747 | &Header::closepage(); | |
748 | exit (0); | |
749 | } | |
750 | ##hier die refresh page | |
751 | ||
6e13d0a5 MT |
752 | |
753 | ### | |
754 | ### OpenVPN Server Control | |
755 | ### | |
756 | if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'} || | |
757 | $cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'} || | |
758 | $cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}) { | |
6e13d0a5 MT |
759 | #start openvpn server |
760 | if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'}){ | |
c6c9630e | 761 | &emptyserverlog(); |
6e13d0a5 MT |
762 | system('/usr/local/bin/openvpnctrl', '-s'); |
763 | } | |
764 | #stop openvpn server | |
765 | if ($cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'}){ | |
6e13d0a5 | 766 | system('/usr/local/bin/openvpnctrl', '-k'); |
c6c9630e | 767 | &emptyserverlog(); |
6e13d0a5 MT |
768 | } |
769 | # #restart openvpn server | |
8c877a82 | 770 | # if ($cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}){ |
6e13d0a5 | 771 | #workarund, till SIGHUP also works when running as nobody |
8c877a82 AM |
772 | # system('/usr/local/bin/openvpnctrl', '-r'); |
773 | # &emptyserverlog(); | |
774 | # } | |
6e13d0a5 MT |
775 | } |
776 | ||
777 | ### | |
778 | ### Save Advanced options | |
779 | ### | |
780 | ||
781 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save-adv-options'}) { | |
782 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
783 | #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too, | |
784 | #DAN this value has to leave. | |
785 | #new settings for daemon | |
786 | $vpnsettings{'LOG_VERB'} = $cgiparams{'LOG_VERB'}; | |
787 | $vpnsettings{'KEEPALIVE_1'} = $cgiparams{'KEEPALIVE_1'}; | |
788 | $vpnsettings{'KEEPALIVE_2'} = $cgiparams{'KEEPALIVE_2'}; | |
789 | $vpnsettings{'MAX_CLIENTS'} = $cgiparams{'MAX_CLIENTS'}; | |
790 | $vpnsettings{'REDIRECT_GW_DEF1'} = $cgiparams{'REDIRECT_GW_DEF1'}; | |
791 | $vpnsettings{'CLIENT2CLIENT'} = $cgiparams{'CLIENT2CLIENT'}; | |
792 | $vpnsettings{'DHCP_DOMAIN'} = $cgiparams{'DHCP_DOMAIN'}; | |
793 | $vpnsettings{'DHCP_DNS'} = $cgiparams{'DHCP_DNS'}; | |
794 | $vpnsettings{'DHCP_WINS'} = $cgiparams{'DHCP_WINS'}; | |
54fd0535 | 795 | $vpnsettings{'ROUTES_PUSH'} = $cgiparams{'ROUTES_PUSH'}; |
2ee746be | 796 | $vpnsettings{'PMTU_DISCOVERY'} = $cgiparams{'PMTU_DISCOVERY'}; |
4c962356 | 797 | $vpnsettings{'DAUTH'} = $cgiparams{'DAUTH'}; |
49abe7af EK |
798 | $vpnsettings{'TLSAUTH'} = $cgiparams{'TLSAUTH'}; |
799 | $vpnsettings{'ENGINES'} = $cgiparams{'ENGINES'}; | |
54fd0535 | 800 | my @temp=(); |
6e13d0a5 | 801 | |
a79fa1d6 JPT |
802 | if ($cgiparams{'FRAGMENT'} eq '') { |
803 | delete $vpnsettings{'FRAGMENT'}; | |
804 | } else { | |
805 | if ($cgiparams{'FRAGMENT'} !~ /^[0-9]+$/) { | |
806 | $errormessage = "Incorrect value, please insert only numbers."; | |
807 | goto ADV_ERROR; | |
808 | } else { | |
809 | $vpnsettings{'FRAGMENT'} = $cgiparams{'FRAGMENT'}; | |
810 | } | |
811 | } | |
49abe7af | 812 | |
a79fa1d6 | 813 | if ($cgiparams{'MSSFIX'} ne 'on') { |
1de5c945 | 814 | delete $vpnsettings{'MSSFIX'}; |
a79fa1d6 JPT |
815 | } else { |
816 | $vpnsettings{'MSSFIX'} = $cgiparams{'MSSFIX'}; | |
817 | } | |
2ee746be | 818 | |
49abe7af EK |
819 | # Create ta.key for tls-auth if not presant |
820 | if ($cgiparams{'TLSAUTH'} eq 'on') { | |
821 | if ( ! -e "${General::swroot}/ovpn/ca/ta.key") { | |
822 | system('/usr/sbin/openvpn', '--genkey', '--secret', "${General::swroot}/ovpn/ca/ta.key") | |
823 | } | |
824 | } | |
825 | ||
1647059d SS |
826 | if (($cgiparams{'PMTU_DISCOVERY'} eq 'yes') || |
827 | ($cgiparams{'PMTU_DISCOVERY'} eq 'maybe') || | |
828 | ($cgiparams{'PMTU_DISCOVERY'} eq 'no' )) { | |
829 | ||
2ee746be SS |
830 | if (($cgiparams{'MSSFIX'} eq 'on') || ($cgiparams{'FRAGMENT'} ne '')) { |
831 | $errormessage = $Lang::tr{'ovpn mtu-disc with mssfix or fragment'}; | |
832 | goto ADV_ERROR; | |
833 | } | |
834 | } | |
835 | ||
6e13d0a5 | 836 | if ($cgiparams{'DHCP_DOMAIN'} ne ''){ |
81da1b01 | 837 | unless (&General::validdomainname($cgiparams{'DHCP_DOMAIN'}) || &General::validip($cgiparams{'DHCP_DOMAIN'})) { |
6e13d0a5 MT |
838 | $errormessage = $Lang::tr{'invalid input for dhcp domain'}; |
839 | goto ADV_ERROR; | |
840 | } | |
841 | } | |
842 | if ($cgiparams{'DHCP_DNS'} ne ''){ | |
843 | unless (&General::validfqdn($cgiparams{'DHCP_DNS'}) || &General::validip($cgiparams{'DHCP_DNS'})) { | |
844 | $errormessage = $Lang::tr{'invalid input for dhcp dns'}; | |
845 | goto ADV_ERROR; | |
846 | } | |
847 | } | |
848 | if ($cgiparams{'DHCP_WINS'} ne ''){ | |
849 | unless (&General::validfqdn($cgiparams{'DHCP_WINS'}) || &General::validip($cgiparams{'DHCP_WINS'})) { | |
850 | $errormessage = $Lang::tr{'invalid input for dhcp wins'}; | |
54fd0535 MT |
851 | goto ADV_ERROR; |
852 | } | |
853 | } | |
854 | if ($cgiparams{'ROUTES_PUSH'} ne ''){ | |
855 | @temp = split(/\n/,$cgiparams{'ROUTES_PUSH'}); | |
856 | undef $vpnsettings{'ROUTES_PUSH'}; | |
8c877a82 AM |
857 | |
858 | foreach my $tmpip (@temp) | |
54fd0535 MT |
859 | { |
860 | s/^\s+//g; s/\s+$//g; | |
8c877a82 AM |
861 | |
862 | if ($tmpip) | |
54fd0535 | 863 | { |
8c877a82 AM |
864 | $tmpip=~s/\s*$//g; |
865 | unless (&General::validipandmask($tmpip)) { | |
866 | $errormessage = "$tmpip ".$Lang::tr{'ovpn errmsg invalid ip or mask'}; | |
867 | goto ADV_ERROR; | |
54fd0535 | 868 | } |
8c877a82 AM |
869 | my ($ip, $cidr) = split("\/",&General::ipcidr2msk($tmpip)); |
870 | ||
54fd0535 MT |
871 | if ($ip eq $netsettings{'GREEN_NETADDRESS'} && $cidr eq $netsettings{'GREEN_NETMASK'}) { |
872 | $errormessage = $Lang::tr{'ovpn errmsg green already pushed'}; | |
8c877a82 AM |
873 | goto ADV_ERROR; |
874 | } | |
875 | # a.marx ccd | |
876 | my %ccdroutehash=(); | |
877 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
878 | foreach my $key (keys %ccdroutehash) { | |
879 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { | |
880 | if ( $ip."/".$cidr eq $ccdroutehash{$key}[$i] ){ | |
881 | $errormessage="Route $ip\/$cidr ".$Lang::tr{'ccd err inuse'}." $ccdroutehash{$key}[0]" ; | |
882 | goto ADV_ERROR; | |
883 | } | |
884 | my ($ip2,$cidr2) = split(/\//,$ccdroutehash{$key}[$i]); | |
885 | if (&General::IpInSubnet ($ip,$ip2,$cidr2)){ | |
886 | $errormessage="Route $ip\/$cidr ".$Lang::tr{'ccd err inuse'}." $ccdroutehash{$key}[0]" ; | |
887 | goto ADV_ERROR; | |
888 | } | |
889 | } | |
54fd0535 | 890 | } |
8c877a82 AM |
891 | |
892 | # ccd end | |
893 | ||
894 | $vpnsettings{'ROUTES_PUSH'} .= $tmpip."\n"; | |
54fd0535 | 895 | } |
8c877a82 AM |
896 | } |
897 | &write_routepushfile; | |
54fd0535 | 898 | undef $vpnsettings{'ROUTES_PUSH'}; |
8e148dc3 NP |
899 | } |
900 | else { | |
901 | undef $vpnsettings{'ROUTES_PUSH'}; | |
902 | &write_routepushfile; | |
6e13d0a5 | 903 | } |
6e13d0a5 MT |
904 | if ((length($cgiparams{'MAX_CLIENTS'}) == 0) || (($cgiparams{'MAX_CLIENTS'}) < 1 ) || (($cgiparams{'MAX_CLIENTS'}) > 255 )) { |
905 | $errormessage = $Lang::tr{'invalid input for max clients'}; | |
906 | goto ADV_ERROR; | |
907 | } | |
908 | if ($cgiparams{'KEEPALIVE_1'} ne '') { | |
909 | if ($cgiparams{'KEEPALIVE_1'} !~ /^[0-9]+$/) { | |
910 | $errormessage = $Lang::tr{'invalid input for keepalive 1'}; | |
911 | goto ADV_ERROR; | |
912 | } | |
913 | } | |
914 | if ($cgiparams{'KEEPALIVE_2'} ne ''){ | |
915 | if ($cgiparams{'KEEPALIVE_2'} !~ /^[0-9]+$/) { | |
916 | $errormessage = $Lang::tr{'invalid input for keepalive 2'}; | |
917 | goto ADV_ERROR; | |
918 | } | |
919 | } | |
920 | if ($cgiparams{'KEEPALIVE_2'} < ($cgiparams{'KEEPALIVE_1'} * 2)){ | |
921 | $errormessage = $Lang::tr{'invalid input for keepalive 1:2'}; | |
922 | goto ADV_ERROR; | |
923 | } | |
924 | ||
925 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
c6c9630e | 926 | &writeserverconf();#hier ok |
6e13d0a5 MT |
927 | } |
928 | ||
ce9abb66 | 929 | ### |
7c1d9faf | 930 | # m.a.d net2net |
ce9abb66 AH |
931 | ### |
932 | ||
933 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'server') | |
934 | { | |
c6c9630e | 935 | |
ce9abb66 AH |
936 | my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'}); |
937 | my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'}); | |
54fd0535 | 938 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; |
d96c89eb | 939 | my $tunmtu = ''; |
531f0835 AH |
940 | |
941 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} | |
942 | unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";} | |
ce9abb66 AH |
943 | |
944 | open(SERVERCONF, ">${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Unable to open ${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf: $!"; | |
945 | ||
946 | flock SERVERCONF, 2; | |
7c1d9faf | 947 | print SERVERCONF "# IPFire n2n Open VPN Server Config by ummeegge und m.a.d\n"; |
ce9abb66 | 948 | print SERVERCONF "\n"; |
b278daf3 | 949 | print SERVERCONF "# User Security\n"; |
ce9abb66 AH |
950 | print SERVERCONF "user nobody\n"; |
951 | print SERVERCONF "group nobody\n"; | |
952 | print SERVERCONF "persist-tun\n"; | |
953 | print SERVERCONF "persist-key\n"; | |
7c1d9faf | 954 | print SERVERCONF "script-security 2\n"; |
60f396d7 | 955 | print SERVERCONF "# IP/DNS for remote Server Gateway\n"; |
c125d8a2 SS |
956 | |
957 | if ($cgiparams{'REMOTE'} ne '') { | |
ce9abb66 | 958 | print SERVERCONF "remote $cgiparams{'REMOTE'}\n"; |
c125d8a2 SS |
959 | } |
960 | ||
b278daf3 | 961 | print SERVERCONF "float\n"; |
60f396d7 | 962 | print SERVERCONF "# IP adresses of the VPN Subnet\n"; |
ce9abb66 | 963 | print SERVERCONF "ifconfig $ovsubnet.1 $ovsubnet.2\n"; |
60f396d7 | 964 | print SERVERCONF "# Client Gateway Network\n"; |
54fd0535 | 965 | print SERVERCONF "route $remsubnet[0] $remsubnet[1]\n"; |
60f396d7 | 966 | print SERVERCONF "# tun Device\n"; |
ce9abb66 | 967 | print SERVERCONF "dev tun\n"; |
60f396d7 | 968 | print SERVERCONF "# Port and Protokol\n"; |
ce9abb66 | 969 | print SERVERCONF "port $cgiparams{'DEST_PORT'}\n"; |
60f396d7 AH |
970 | |
971 | if ($cgiparams{'PROTOCOL'} eq 'tcp') { | |
972 | print SERVERCONF "proto tcp-server\n"; | |
973 | print SERVERCONF "# Packet size\n"; | |
d96c89eb | 974 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}}; |
60f396d7 | 975 | print SERVERCONF "tun-mtu $tunmtu\n"; |
d96c89eb | 976 | } |
60f396d7 AH |
977 | |
978 | if ($cgiparams{'PROTOCOL'} eq 'udp') { | |
979 | print SERVERCONF "proto udp\n"; | |
980 | print SERVERCONF "# Paketsize\n"; | |
981 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1500'} else {$tunmtu = $cgiparams{'MTU'}}; | |
982 | print SERVERCONF "tun-mtu $tunmtu\n"; | |
54fd0535 MT |
983 | if ($cgiparams{'FRAGMENT'} ne '') {print SERVERCONF "fragment $cgiparams{'FRAGMENT'}\n";} |
984 | if ($cgiparams{'MSSFIX'} eq 'on') {print SERVERCONF "mssfix\n"; }; | |
d96c89eb | 985 | } |
1647059d SS |
986 | |
987 | # Check if a valid operating mode has been choosen and use it. | |
988 | if (($cgiparams{'PMTU_DISCOVERY'} eq 'yes') || | |
989 | ($cgiparams{'PMTU_DISCOVERY'} eq 'maybe') || | |
990 | ($cgiparams{'PMTU_DISCOVERY'} eq 'no' )) { | |
2ee746be SS |
991 | if(($cgiparams{'MSSFIX'} ne 'on') || ($cgiparams{'FRAGMENT'} eq '')) { |
992 | if($cgiparams{'MTU'} eq '1500') { | |
993 | print SERVERCONF "mtu-disc $cgiparams{'PMTU_DISCOVERY'}\n"; | |
994 | } | |
995 | } | |
996 | } | |
60f396d7 | 997 | print SERVERCONF "# Auth. Server\n"; |
ce9abb66 AH |
998 | print SERVERCONF "tls-server\n"; |
999 | print SERVERCONF "ca ${General::swroot}/ovpn/ca/cacert.pem\n"; | |
1000 | print SERVERCONF "cert ${General::swroot}/ovpn/certs/servercert.pem\n"; | |
1001 | print SERVERCONF "key ${General::swroot}/ovpn/certs/serverkey.pem\n"; | |
49abe7af | 1002 | print SERVERCONF "dh ${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}\n"; |
b278daf3 | 1003 | print SERVERCONF "# Cipher\n"; |
4c962356 | 1004 | print SERVERCONF "cipher $cgiparams{'DCIPHER'}\n"; |
49abe7af EK |
1005 | if ($cgiparams{'DAUTH'} eq '') { |
1006 | print SERVERCONF "auth SHA1\n"; | |
1007 | } else { | |
1008 | print SERVERCONF "# HMAC algorithm\n"; | |
1009 | print SERVERCONF "auth $cgiparams{'DAUTH'}\n"; | |
1010 | } | |
1011 | if ($cgiparams{'ENGINES'} eq 'disabled') { | |
1012 | print SERVERCONF ""; | |
1013 | } else { | |
1014 | print SERVERCONF "# Crypto engine\n"; | |
1015 | print SERVERCONF "engine $cgiparams{'ENGINES'}\n"; | |
1016 | } | |
ce9abb66 | 1017 | if ($cgiparams{'COMPLZO'} eq 'on') { |
60f396d7 | 1018 | print SERVERCONF "# Enable Compression\n"; |
ce9abb66 | 1019 | print SERVERCONF "comp-lzo\r\n"; |
b278daf3 | 1020 | } |
60f396d7 | 1021 | print SERVERCONF "# Debug Level\n"; |
ce9abb66 | 1022 | print SERVERCONF "verb 3\n"; |
b278daf3 | 1023 | print SERVERCONF "# Tunnel check\n"; |
ce9abb66 | 1024 | print SERVERCONF "keepalive 10 60\n"; |
60f396d7 | 1025 | print SERVERCONF "# Start as daemon\n"; |
ce9abb66 AH |
1026 | print SERVERCONF "daemon $cgiparams{'NAME'}n2n\n"; |
1027 | print SERVERCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n"; | |
60f396d7 | 1028 | print SERVERCONF "# Activate Management Interface and Port\n"; |
54fd0535 MT |
1029 | if ($cgiparams{'OVPN_MGMT'} eq '') {print SERVERCONF "management localhost $cgiparams{'DEST_PORT'}\n"} |
1030 | else {print SERVERCONF "management localhost $cgiparams{'OVPN_MGMT'}\n"}; | |
ce9abb66 AH |
1031 | close(SERVERCONF); |
1032 | ||
1033 | } | |
1034 | ||
1035 | ### | |
7c1d9faf | 1036 | # m.a.d net2net |
ce9abb66 | 1037 | ### |
7c1d9faf | 1038 | |
ce9abb66 AH |
1039 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'client') |
1040 | { | |
4c962356 | 1041 | |
ce9abb66 | 1042 | my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'}); |
54fd0535 | 1043 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; |
ce9abb66 | 1044 | my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'}); |
d96c89eb | 1045 | my $tunmtu = ''; |
54fd0535 | 1046 | |
531f0835 AH |
1047 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} |
1048 | unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";} | |
ce9abb66 AH |
1049 | |
1050 | open(CLIENTCONF, ">${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Unable to open ${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf: $!"; | |
1051 | ||
1052 | flock CLIENTCONF, 2; | |
7c1d9faf | 1053 | print CLIENTCONF "# IPFire rewritten n2n Open VPN Client Config by ummeegge und m.a.d\n"; |
ce9abb66 | 1054 | print CLIENTCONF "#\n"; |
b278daf3 | 1055 | print CLIENTCONF "# User Security\n"; |
ce9abb66 AH |
1056 | print CLIENTCONF "user nobody\n"; |
1057 | print CLIENTCONF "group nobody\n"; | |
1058 | print CLIENTCONF "persist-tun\n"; | |
1059 | print CLIENTCONF "persist-key\n"; | |
7c1d9faf | 1060 | print CLIENTCONF "script-security 2\n"; |
60f396d7 | 1061 | print CLIENTCONF "# IP/DNS for remote Server Gateway\n"; |
ce9abb66 | 1062 | print CLIENTCONF "remote $cgiparams{'REMOTE'}\n"; |
b278daf3 | 1063 | print CLIENTCONF "float\n"; |
60f396d7 | 1064 | print CLIENTCONF "# IP adresses of the VPN Subnet\n"; |
ce9abb66 | 1065 | print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n"; |
60f396d7 | 1066 | print CLIENTCONF "# Server Gateway Network\n"; |
54fd0535 | 1067 | print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n"; |
60f396d7 | 1068 | print CLIENTCONF "# tun Device\n"; |
ce9abb66 | 1069 | print CLIENTCONF "dev tun\n"; |
60f396d7 | 1070 | print CLIENTCONF "# Port and Protokol\n"; |
ce9abb66 | 1071 | print CLIENTCONF "port $cgiparams{'DEST_PORT'}\n"; |
60f396d7 AH |
1072 | |
1073 | if ($cgiparams{'PROTOCOL'} eq 'tcp') { | |
1074 | print CLIENTCONF "proto tcp-client\n"; | |
1075 | print CLIENTCONF "# Packet size\n"; | |
d96c89eb | 1076 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}}; |
60f396d7 | 1077 | print CLIENTCONF "tun-mtu $tunmtu\n"; |
d96c89eb | 1078 | } |
60f396d7 AH |
1079 | |
1080 | if ($cgiparams{'PROTOCOL'} eq 'udp') { | |
1081 | print CLIENTCONF "proto udp\n"; | |
1082 | print CLIENTCONF "# Paketsize\n"; | |
1083 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1500'} else {$tunmtu = $cgiparams{'MTU'}}; | |
1084 | print CLIENTCONF "tun-mtu $tunmtu\n"; | |
54fd0535 MT |
1085 | if ($cgiparams{'FRAGMENT'} ne '') {print CLIENTCONF "fragment $cgiparams{'FRAGMENT'}\n";} |
1086 | if ($cgiparams{'MSSFIX'} eq 'on') {print CLIENTCONF "mssfix\n"; }; | |
d96c89eb | 1087 | } |
1647059d SS |
1088 | |
1089 | # Check if a valid operating mode has been choosen and use it. | |
1090 | if (($cgiparams{'PMTU_DISCOVERY'} eq 'yes') || | |
1091 | ($cgiparams{'PMTU_DISCOVERY'} eq 'maybe') || | |
1092 | ($cgiparams{'PMTU_DISCOVERY'} eq 'no' )) { | |
2ee746be SS |
1093 | if(($cgiparams{'MSSFIX'} ne 'on') || ($cgiparams{'FRAGMENT'} eq '')) { |
1094 | if ($cgiparams{'MTU'} eq '1500') { | |
1095 | print CLIENTCONF "mtu-disc $cgiparams{'PMTU_DISCOVERY'}\n"; | |
1096 | } | |
1097 | } | |
1647059d SS |
1098 | } |
1099 | ||
54fd0535 | 1100 | print CLIENTCONF "ns-cert-type server\n"; |
ce9abb66 AH |
1101 | print CLIENTCONF "# Auth. Client\n"; |
1102 | print CLIENTCONF "tls-client\n"; | |
b278daf3 | 1103 | print CLIENTCONF "# Cipher\n"; |
4c962356 | 1104 | print CLIENTCONF "cipher $cgiparams{'DCIPHER'}\n"; |
ce9abb66 | 1105 | print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12\r\n"; |
49abe7af EK |
1106 | if ($cgiparams{'DAUTH'} eq '') { |
1107 | print CLIENTCONF "auth SHA1\n"; | |
1108 | } else { | |
1109 | print CLIENTCONF "# HMAC algorithm\n"; | |
1110 | print CLIENTCONF "auth $cgiparams{'DAUTH'}\n"; | |
1111 | } | |
1112 | if ($cgiparams{'ENGINES'} eq 'disabled') { | |
1113 | print CLIENTCONF ""; | |
1114 | } else { | |
1115 | print CLIENTCONF "# Crypto engine\n"; | |
1116 | print CLIENTCONF "engine $cgiparams{'ENGINES'}\n"; | |
1117 | } | |
ce9abb66 | 1118 | if ($cgiparams{'COMPLZO'} eq 'on') { |
60f396d7 | 1119 | print CLIENTCONF "# Enable Compression\n"; |
ce9abb66 | 1120 | print CLIENTCONF "comp-lzo\r\n"; |
4c962356 | 1121 | } |
ce9abb66 AH |
1122 | print CLIENTCONF "# Debug Level\n"; |
1123 | print CLIENTCONF "verb 3\n"; | |
b278daf3 | 1124 | print CLIENTCONF "# Tunnel check\n"; |
ce9abb66 | 1125 | print CLIENTCONF "keepalive 10 60\n"; |
60f396d7 | 1126 | print CLIENTCONF "# Start as daemon\n"; |
ce9abb66 AH |
1127 | print CLIENTCONF "daemon $cgiparams{'NAME'}n2n\n"; |
1128 | print CLIENTCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n"; | |
60f396d7 | 1129 | print CLIENTCONF "# Activate Management Interface and Port\n"; |
54fd0535 MT |
1130 | if ($cgiparams{'OVPN_MGMT'} eq '') {print CLIENTCONF "management localhost $cgiparams{'DEST_PORT'}\n"} |
1131 | else {print CLIENTCONF "management localhost $cgiparams{'OVPN_MGMT'}\n"}; | |
ce9abb66 | 1132 | close(CLIENTCONF); |
c6c9630e | 1133 | |
ce9abb66 AH |
1134 | } |
1135 | ||
6e13d0a5 MT |
1136 | ### |
1137 | ### Save main settings | |
1138 | ### | |
ce9abb66 AH |
1139 | |
1140 | ||
6e13d0a5 MT |
1141 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq '' && $cgiparams{'KEY'} eq '') { |
1142 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
6e13d0a5 MT |
1143 | #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too, |
1144 | #DAN this value has to leave. | |
1145 | if ($cgiparams{'ENABLED'} eq 'on'){ | |
1146 | unless (&General::validfqdn($cgiparams{'VPN_IP'}) || &General::validip($cgiparams{'VPN_IP'})) { | |
1147 | $errormessage = $Lang::tr{'invalid input for hostname'}; | |
c6c9630e | 1148 | goto SETTINGS_ERROR; |
6e13d0a5 MT |
1149 | } |
1150 | } | |
6e13d0a5 | 1151 | if ($errormessage) { goto SETTINGS_ERROR; } |
48cc0e12 | 1152 | |
6e13d0a5 | 1153 | if ($cgiparams{'ENABLED'} eq 'on'){ |
6945e463 | 1154 | &checkportfw($cgiparams{'DDEST_PORT'},$cgiparams{'DPROTOCOL'}); |
6e13d0a5 | 1155 | } |
6e13d0a5 MT |
1156 | if ($errormessage) { goto SETTINGS_ERROR; } |
1157 | ||
1158 | if (! &General::validipandmask($cgiparams{'DOVPN_SUBNET'})) { | |
c6c9630e | 1159 | $errormessage = $Lang::tr{'ovpn subnet is invalid'}; |
4c962356 | 1160 | goto SETTINGS_ERROR; |
c6c9630e MT |
1161 | } |
1162 | my @tmpovpnsubnet = split("\/",$cgiparams{'DOVPN_SUBNET'}); | |
1163 | ||
1164 | if (&General::IpInSubnet ( $netsettings{'RED_ADDRESS'}, | |
1165 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1166 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire RED Network $netsettings{'RED_ADDRESS'}"; | |
1167 | goto SETTINGS_ERROR; | |
1168 | } | |
1169 | ||
1170 | if (&General::IpInSubnet ( $netsettings{'GREEN_ADDRESS'}, | |
1171 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1172 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Green Network $netsettings{'GREEN_ADDRESS'}"; | |
1173 | goto SETTINGS_ERROR; | |
1174 | } | |
1175 | ||
1176 | if (&General::IpInSubnet ( $netsettings{'BLUE_ADDRESS'}, | |
1177 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1178 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Blue Network $netsettings{'BLUE_ADDRESS'}"; | |
1179 | goto SETTINGS_ERROR; | |
1180 | } | |
1181 | ||
1182 | if (&General::IpInSubnet ( $netsettings{'ORANGE_ADDRESS'}, | |
1183 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1184 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Orange Network $netsettings{'ORANGE_ADDRESS'}"; | |
1185 | goto SETTINGS_ERROR; | |
1186 | } | |
1187 | open(ALIASES, "${General::swroot}/ethernet/aliases") or die 'Unable to open aliases file.'; | |
1188 | while (<ALIASES>) | |
1189 | { | |
1190 | chomp($_); | |
1191 | my @tempalias = split(/\,/,$_); | |
1192 | if ($tempalias[1] eq 'on') { | |
1193 | if (&General::IpInSubnet ($tempalias[0] , | |
1194 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1195 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire alias entry $tempalias[0]"; | |
1196 | } | |
1197 | } | |
1198 | } | |
1199 | close(ALIASES); | |
6e13d0a5 | 1200 | if ($errormessage ne ''){ |
c6c9630e | 1201 | goto SETTINGS_ERROR; |
6e13d0a5 MT |
1202 | } |
1203 | if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) { | |
1204 | $errormessage = $Lang::tr{'invalid input'}; | |
1205 | goto SETTINGS_ERROR; | |
1206 | } | |
1207 | if ((length($cgiparams{'DMTU'})==0) || (($cgiparams{'DMTU'}) < 1000 )) { | |
1208 | $errormessage = $Lang::tr{'invalid mtu input'}; | |
1209 | goto SETTINGS_ERROR; | |
1210 | } | |
1211 | ||
1212 | unless (&General::validport($cgiparams{'DDEST_PORT'})) { | |
c6c9630e MT |
1213 | $errormessage = $Lang::tr{'invalid port'}; |
1214 | goto SETTINGS_ERROR; | |
6e13d0a5 | 1215 | } |
8c252e6a | 1216 | |
6e13d0a5 MT |
1217 | $vpnsettings{'ENABLED_BLUE'} = $cgiparams{'ENABLED_BLUE'}; |
1218 | $vpnsettings{'ENABLED_ORANGE'} =$cgiparams{'ENABLED_ORANGE'}; | |
1219 | $vpnsettings{'ENABLED'} = $cgiparams{'ENABLED'}; | |
1220 | $vpnsettings{'VPN_IP'} = $cgiparams{'VPN_IP'}; | |
1221 | #new settings for daemon | |
1222 | $vpnsettings{'DOVPN_SUBNET'} = $cgiparams{'DOVPN_SUBNET'}; | |
1223 | $vpnsettings{'DDEVICE'} = $cgiparams{'DDEVICE'}; | |
1224 | $vpnsettings{'DPROTOCOL'} = $cgiparams{'DPROTOCOL'}; | |
1225 | $vpnsettings{'DDEST_PORT'} = $cgiparams{'DDEST_PORT'}; | |
1226 | $vpnsettings{'DMTU'} = $cgiparams{'DMTU'}; | |
1227 | $vpnsettings{'DCOMPLZO'} = $cgiparams{'DCOMPLZO'}; | |
1228 | $vpnsettings{'DCIPHER'} = $cgiparams{'DCIPHER'}; | |
3ffee04b CS |
1229 | #wrtie enable |
1230 | ||
1231 | if ( $vpnsettings{'ENABLED_BLUE'} eq 'on' ) {system("touch ${General::swroot}/ovpn/enable_blue 2>/dev/null");}else{system("unlink ${General::swroot}/ovpn/enable_blue 2>/dev/null");} | |
1232 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' ) {system("touch ${General::swroot}/ovpn/enable_orange 2>/dev/null");}else{system("unlink ${General::swroot}/ovpn/enable_orange 2>/dev/null");} | |
1233 | if ( $vpnsettings{'ENABLED'} eq 'on' ) {system("touch ${General::swroot}/ovpn/enable 2>/dev/null");}else{system("unlink ${General::swroot}/ovpn/enable 2>/dev/null");} | |
6e13d0a5 MT |
1234 | #new settings for daemon |
1235 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
c6c9630e | 1236 | &writeserverconf();#hier ok |
6e13d0a5 MT |
1237 | SETTINGS_ERROR: |
1238 | ### | |
1239 | ### Reset all step 2 | |
1240 | ### | |
4c962356 | 1241 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove x509'} && $cgiparams{'AREUSURE'} eq 'yes') { |
6e13d0a5 MT |
1242 | my $file = ''; |
1243 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1244 | ||
1245 | foreach my $key (keys %confighash) { | |
c6c9630e MT |
1246 | if ($confighash{$key}[4] eq 'cert') { |
1247 | delete $confighash{$cgiparams{'$key'}}; | |
1248 | } | |
6e13d0a5 MT |
1249 | } |
1250 | while ($file = glob("${General::swroot}/ovpn/ca/*")) { | |
49abe7af | 1251 | unlink $file; |
6e13d0a5 MT |
1252 | } |
1253 | while ($file = glob("${General::swroot}/ovpn/certs/*")) { | |
49abe7af | 1254 | unlink $file; |
6e13d0a5 MT |
1255 | } |
1256 | while ($file = glob("${General::swroot}/ovpn/crls/*")) { | |
49abe7af | 1257 | unlink $file; |
6e13d0a5 | 1258 | } |
4c962356 | 1259 | &cleanssldatabase(); |
6e13d0a5 MT |
1260 | if (open(FILE, ">${General::swroot}/ovpn/caconfig")) { |
1261 | print FILE ""; | |
1262 | close FILE; | |
1263 | } | |
49abe7af EK |
1264 | if (open(FILE, ">${General::swroot}/ovpn/ccdroute")) { |
1265 | print FILE ""; | |
1266 | close FILE; | |
1267 | } | |
1268 | if (open(FILE, ">${General::swroot}/ovpn/ccdroute2")) { | |
1269 | print FILE ""; | |
1270 | close FILE; | |
1271 | } | |
1272 | while ($file = glob("${General::swroot}/ovpn/ccd/*")) { | |
1273 | unlink $file | |
1274 | } | |
1275 | if (open(FILE, ">${General::swroot}/ovpn/ovpn-leases.db")) { | |
1276 | print FILE ""; | |
1277 | close FILE; | |
1278 | } | |
1279 | if (open(FILE, ">${General::swroot}/ovpn/ovpnconfig")) { | |
1280 | print FILE ""; | |
1281 | close FILE; | |
1282 | } | |
1283 | while ($file = glob("${General::swroot}/ovpn/n2nconf/*")) { | |
1284 | system ("rm -rf $file"); | |
1285 | } | |
1286 | ||
c6c9630e | 1287 | #&writeserverconf(); |
6e13d0a5 MT |
1288 | ### |
1289 | ### Reset all step 1 | |
1290 | ### | |
4c962356 | 1291 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove x509'}) { |
6e13d0a5 | 1292 | &Header::showhttpheaders(); |
4c962356 EK |
1293 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
1294 | &Header::openbigbox('100%', 'left', '', ''); | |
1295 | &Header::openbox('100%', 'left', $Lang::tr{'are you sure'}); | |
1296 | print <<END; | |
1297 | <form method='post'> | |
1298 | <table width='100%'> | |
1299 | <tr> | |
1300 | <td align='center'> | |
1301 | <input type='hidden' name='AREUSURE' value='yes' /> | |
1302 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: | |
49abe7af | 1303 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: |
4c962356 EK |
1304 | $Lang::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}</td> |
1305 | </tr> | |
1306 | <tr> | |
1307 | <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' /> | |
1308 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td> | |
1309 | </tr> | |
1310 | </table> | |
1311 | </form> | |
6e13d0a5 MT |
1312 | END |
1313 | ; | |
1314 | &Header::closebox(); | |
1315 | &Header::closebigbox(); | |
1316 | &Header::closepage(); | |
1317 | exit (0); | |
1318 | ||
4c962356 EK |
1319 | ### |
1320 | ### Generate DH key step 2 | |
1321 | ### | |
1322 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate dh key'} && $cgiparams{'AREUSURE'} eq 'yes') { | |
49abe7af | 1323 | # Delete if old key exists |
4c962356 EK |
1324 | if (-f "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}") { |
1325 | unlink "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}"; | |
1326 | } | |
1327 | # Create Diffie Hellmann Parameter | |
1328 | system('/usr/bin/openssl', 'dhparam', '-rand', '/proc/interrupts:/proc/net/rt_cache', | |
1329 | '-out', "${General::swroot}/ovpn/ca/dh1024.pem", "$cgiparams{'DHLENGHT'}"); | |
1330 | if ($?) { | |
1331 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1332 | unlink ("${General::swroot}/ovpn/ca/dh1024.pem"); | |
1333 | } | |
1334 | ||
1335 | ### | |
1336 | ### Generate DH key step 1 | |
1337 | ### | |
1338 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate dh key'}) { | |
1339 | &Header::showhttpheaders(); | |
1340 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
1341 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
1342 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'gen dh'}:"); | |
1343 | print <<END; | |
1344 | <table width='100%'> | |
1345 | <tr> | |
1346 | <td width='15%'> </td> <td width='15%'></td> <td width='65%'></td> | |
49abe7af | 1347 | </tr> |
4c962356 EK |
1348 | <tr> |
1349 | <td class='base'>$Lang::tr{'ovpn dh'}:</td> | |
1350 | <td align='center'> | |
1351 | <form method='post'><input type='hidden' name='AREUSURE' value='yes' /> | |
1352 | <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' /> | |
1353 | <select name='DHLENGHT'> | |
1354 | <option value='1024' $selected{'DHLENGHT'}{'1024'}>1024 $Lang::tr{'bit'}</option> | |
1355 | <option value='2048' $selected{'DHLENGHT'}{'2048'}>2048 $Lang::tr{'bit'}</option> | |
1356 | <option value='3072' $selected{'DHLENGHT'}{'3072'}>3072 $Lang::tr{'bit'}</option> | |
1357 | <option value='4096' $selected{'DHLENGHT'}{'4096'}>4096 $Lang::tr{'bit'}</option> | |
1358 | </select> | |
1359 | </td> | |
1360 | </tr> | |
1361 | <tr><td colspan='4'><br></td></tr> | |
1362 | </table> | |
1363 | <table width='100%'> | |
1364 | <tr> | |
49abe7af | 1365 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}: </font></b>$Lang::tr{'dh key warn'} |
4c962356 | 1366 | </tr> |
49abe7af EK |
1367 | <tr> |
1368 | <td class='base'>$Lang::tr{'dh key warn1'}</td> | |
1369 | </tr> | |
1370 | <tr><td colspan='2'><br></td></tr> | |
4c962356 EK |
1371 | <tr> |
1372 | <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'generate dh key'}' /></td> | |
1373 | </form> | |
1374 | </tr> | |
1375 | </table> | |
1376 | ||
1377 | END | |
1378 | ; | |
1379 | &Header::closebox(); | |
1380 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1381 | &Header::closebigbox(); | |
1382 | &Header::closepage(); | |
1383 | exit (0); | |
1384 | ||
1385 | ### | |
1386 | ### Upload DH key | |
1387 | ### | |
1388 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload dh key'}) { | |
4c962356 EK |
1389 | if (ref ($cgiparams{'FH'}) ne 'Fh') { |
1390 | $errormessage = $Lang::tr{'there was no file upload'}; | |
1391 | goto UPLOADCA_ERROR; | |
1392 | } | |
49abe7af | 1393 | # Move uploaded dh key to a temporary file |
4c962356 EK |
1394 | (my $fh, my $filename) = tempfile( ); |
1395 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
1396 | $errormessage = $!; | |
49abe7af | 1397 | goto UPLOADCA_ERROR; |
4c962356 | 1398 | } |
49abe7af | 1399 | my $temp = `/usr/bin/openssl dhparam -text -in $filename`; |
4c962356 EK |
1400 | if ($temp !~ /DH Parameters: \((1024|2048|3072|4096) bit\)/) { |
1401 | $errormessage = $Lang::tr{'not a valid dh key'}; | |
1402 | unlink ($filename); | |
1403 | goto UPLOADCA_ERROR; | |
1404 | } else { | |
1405 | # Delete if old key exists | |
1406 | if (-f "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}") { | |
1407 | unlink "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}"; | |
1408 | } | |
1409 | move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}"); | |
49abe7af EK |
1410 | if ($? ne 0) { |
1411 | $errormessage = "$Lang::tr{'dh key move failed'}: $!"; | |
1412 | unlink ($filename); | |
1413 | goto UPLOADCA_ERROR; | |
1414 | } | |
4c962356 EK |
1415 | } |
1416 | ||
6e13d0a5 MT |
1417 | ### |
1418 | ### Upload CA Certificate | |
1419 | ### | |
1420 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload ca certificate'}) { | |
1421 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1422 | ||
1423 | if ($cgiparams{'CA_NAME'} !~ /^[a-zA-Z0-9]+$/) { | |
1424 | $errormessage = $Lang::tr{'name must only contain characters'}; | |
1425 | goto UPLOADCA_ERROR; | |
1426 | } | |
1427 | ||
1428 | if (length($cgiparams{'CA_NAME'}) >60) { | |
1429 | $errormessage = $Lang::tr{'name too long'}; | |
1430 | goto VPNCONF_ERROR; | |
1431 | } | |
1432 | ||
1433 | if ($cgiparams{'CA_NAME'} eq 'ca') { | |
1434 | $errormessage = $Lang::tr{'name is invalid'}; | |
4c962356 | 1435 | goto UPLOADCA_ERROR; |
6e13d0a5 MT |
1436 | } |
1437 | ||
1438 | # Check if there is no other entry with this name | |
1439 | foreach my $key (keys %cahash) { | |
c6c9630e MT |
1440 | if ($cahash{$key}[0] eq $cgiparams{'CA_NAME'}) { |
1441 | $errormessage = $Lang::tr{'a ca certificate with this name already exists'}; | |
1442 | goto UPLOADCA_ERROR; | |
1443 | } | |
6e13d0a5 MT |
1444 | } |
1445 | ||
1446 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
c6c9630e MT |
1447 | $errormessage = $Lang::tr{'there was no file upload'}; |
1448 | goto UPLOADCA_ERROR; | |
6e13d0a5 MT |
1449 | } |
1450 | # Move uploaded ca to a temporary file | |
1451 | (my $fh, my $filename) = tempfile( ); | |
1452 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
c6c9630e MT |
1453 | $errormessage = $!; |
1454 | goto UPLOADCA_ERROR; | |
6e13d0a5 MT |
1455 | } |
1456 | my $temp = `/usr/bin/openssl x509 -text -in $filename`; | |
c6c9630e MT |
1457 | if ($temp !~ /CA:TRUE/i) { |
1458 | $errormessage = $Lang::tr{'not a valid ca certificate'}; | |
1459 | unlink ($filename); | |
1460 | goto UPLOADCA_ERROR; | |
6e13d0a5 | 1461 | } else { |
c6c9630e MT |
1462 | move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem"); |
1463 | if ($? ne 0) { | |
1464 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1465 | unlink ($filename); | |
1466 | goto UPLOADCA_ERROR; | |
1467 | } | |
6e13d0a5 MT |
1468 | } |
1469 | ||
1470 | my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem`; | |
1471 | $casubject =~ /Subject: (.*)[\n]/; | |
1472 | $casubject = $1; | |
1473 | $casubject =~ s+/Email+, E+; | |
1474 | $casubject =~ s/ ST=/ S=/; | |
1475 | $casubject = &Header::cleanhtml($casubject); | |
1476 | ||
1477 | my $key = &General::findhasharraykey (\%cahash); | |
1478 | $cahash{$key}[0] = $cgiparams{'CA_NAME'}; | |
1479 | $cahash{$key}[1] = $casubject; | |
1480 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
c6c9630e MT |
1481 | # system('/usr/local/bin/ipsecctrl', 'R'); |
1482 | ||
6e13d0a5 MT |
1483 | UPLOADCA_ERROR: |
1484 | ||
1485 | ### | |
1486 | ### Display ca certificate | |
1487 | ### | |
1488 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show ca certificate'}) { | |
c6c9630e MT |
1489 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); |
1490 | ||
1491 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem") { | |
1492 | &Header::showhttpheaders(); | |
4c962356 | 1493 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
c6c9630e MT |
1494 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); |
1495 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ca certificate'}:"); | |
1496 | my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`; | |
1497 | $output = &Header::cleanhtml($output,"y"); | |
1498 | print "<pre>$output</pre>\n"; | |
1499 | &Header::closebox(); | |
1500 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1501 | &Header::closebigbox(); | |
1502 | &Header::closepage(); | |
1503 | exit(0); | |
1504 | } else { | |
1505 | $errormessage = $Lang::tr{'invalid key'}; | |
1506 | } | |
1507 | ||
6e13d0a5 MT |
1508 | ### |
1509 | ### Download ca certificate | |
1510 | ### | |
1511 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download ca certificate'}) { | |
1512 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1513 | ||
1514 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
1515 | print "Content-Type: application/octet-stream\r\n"; | |
1516 | print "Content-Disposition: filename=$cahash{$cgiparams{'KEY'}}[0]cert.pem\r\n\r\n"; | |
1517 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`; | |
1518 | exit(0); | |
1519 | } else { | |
1520 | $errormessage = $Lang::tr{'invalid key'}; | |
1521 | } | |
1522 | ||
1523 | ### | |
1524 | ### Remove ca certificate (step 2) | |
1525 | ### | |
1526 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'} && $cgiparams{'AREUSURE'} eq 'yes') { | |
1527 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1528 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1529 | ||
1530 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
1531 | foreach my $key (keys %confighash) { | |
1532 | my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem ${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem`; | |
1533 | if ($test =~ /: OK/) { | |
c6c9630e MT |
1534 | # Delete connection |
1535 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
1536 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
1537 | # system('/usr/local/bin/ipsecctrl', 'D', $key); | |
1538 | # } | |
6e13d0a5 MT |
1539 | unlink ("${General::swroot}/ovpn//certs/$confighash{$key}[1]cert.pem"); |
1540 | unlink ("${General::swroot}/ovpn/certs/$confighash{$key}[1].p12"); | |
1541 | delete $confighash{$key}; | |
1542 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 1543 | # &writeipsecfiles(); |
6e13d0a5 MT |
1544 | } |
1545 | } | |
1546 | unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
1547 | delete $cahash{$cgiparams{'KEY'}}; | |
1548 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
c6c9630e | 1549 | # system('/usr/local/bin/ipsecctrl', 'R'); |
6e13d0a5 MT |
1550 | } else { |
1551 | $errormessage = $Lang::tr{'invalid key'}; | |
1552 | } | |
1553 | ### | |
1554 | ### Remove ca certificate (step 1) | |
1555 | ### | |
1556 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'}) { | |
1557 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1558 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1559 | ||
1560 | my $assignedcerts = 0; | |
1561 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
1562 | foreach my $key (keys %confighash) { | |
1563 | my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem ${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem`; | |
1564 | if ($test =~ /: OK/) { | |
1565 | $assignedcerts++; | |
1566 | } | |
1567 | } | |
1568 | if ($assignedcerts) { | |
1569 | &Header::showhttpheaders(); | |
4c962356 | 1570 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
6e13d0a5 MT |
1571 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); |
1572 | &Header::openbox('100%', 'LEFT', $Lang::tr{'are you sure'}); | |
4c962356 | 1573 | print <<END; |
6e13d0a5 MT |
1574 | <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' /> |
1575 | <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' /> | |
1576 | <tr><td align='center'> | |
1577 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: $assignedcerts | |
1578 | $Lang::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'} | |
1579 | <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'remove ca certificate'}' /> | |
1580 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td></tr> | |
1581 | </form></table> | |
1582 | END | |
1583 | ; | |
1584 | &Header::closebox(); | |
1585 | &Header::closebigbox(); | |
1586 | &Header::closepage(); | |
1587 | exit (0); | |
1588 | } else { | |
1589 | unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
1590 | delete $cahash{$cgiparams{'KEY'}}; | |
1591 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1592 | # system('/usr/local/bin/ipsecctrl', 'R'); | |
1593 | } | |
1594 | } else { | |
1595 | $errormessage = $Lang::tr{'invalid key'}; | |
1596 | } | |
1597 | ||
1598 | ### | |
1599 | ### Display root certificate | |
1600 | ### | |
c6c9630e MT |
1601 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'} || |
1602 | $cgiparams{'ACTION'} eq $Lang::tr{'show host certificate'}) { | |
1603 | my $output; | |
1604 | &Header::showhttpheaders(); | |
4c962356 | 1605 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
c6c9630e MT |
1606 | &Header::openbigbox('100%', 'LEFT', '', ''); |
1607 | if ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'}) { | |
1608 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'root certificate'}:"); | |
1609 | $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem`; | |
1610 | } else { | |
1611 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'host certificate'}:"); | |
1612 | $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
1613 | } | |
1614 | $output = &Header::cleanhtml($output,"y"); | |
1615 | print "<pre>$output</pre>\n"; | |
1616 | &Header::closebox(); | |
1617 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1618 | &Header::closebigbox(); | |
1619 | &Header::closepage(); | |
1620 | exit(0); | |
1621 | ||
6e13d0a5 MT |
1622 | ### |
1623 | ### Download root certificate | |
1624 | ### | |
1625 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download root certificate'}) { | |
1626 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) { | |
1627 | print "Content-Type: application/octet-stream\r\n"; | |
1628 | print "Content-Disposition: filename=cacert.pem\r\n\r\n"; | |
1629 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/cacert.pem`; | |
1630 | exit(0); | |
1631 | } | |
1632 | ||
1633 | ### | |
1634 | ### Download host certificate | |
1635 | ### | |
1636 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download host certificate'}) { | |
1637 | if ( -f "${General::swroot}/ovpn/certs/servercert.pem" ) { | |
1638 | print "Content-Type: application/octet-stream\r\n"; | |
1639 | print "Content-Disposition: filename=servercert.pem\r\n\r\n"; | |
1640 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
1641 | exit(0); | |
1642 | } | |
1643 | ### | |
1644 | ### Form for generating a root certificate | |
1645 | ### | |
1646 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate root/host certificates'} || | |
1647 | $cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) { | |
1648 | ||
1649 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1650 | if (-f "${General::swroot}/ovpn/ca/cacert.pem") { | |
1651 | $errormessage = $Lang::tr{'valid root certificate already exists'}; | |
1652 | $cgiparams{'ACTION'} = ''; | |
1653 | goto ROOTCERT_ERROR; | |
1654 | } | |
1655 | ||
1656 | if (($cgiparams{'ROOTCERT_HOSTNAME'} eq '') && -e "${General::swroot}/red/active") { | |
1657 | if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) { | |
1658 | my $ipaddr = <IPADDR>; | |
1659 | close IPADDR; | |
1660 | chomp ($ipaddr); | |
1661 | $cgiparams{'ROOTCERT_HOSTNAME'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0]; | |
1662 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq '') { | |
1663 | $cgiparams{'ROOTCERT_HOSTNAME'} = $ipaddr; | |
1664 | } | |
1665 | } | |
1666 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) { | |
1667 | ||
1668 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
1669 | $errormessage = $Lang::tr{'there was no file upload'}; | |
1670 | goto ROOTCERT_ERROR; | |
1671 | } | |
1672 | ||
1673 | # Move uploaded certificate request to a temporary file | |
1674 | (my $fh, my $filename) = tempfile( ); | |
1675 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
1676 | $errormessage = $!; | |
1677 | goto ROOTCERT_ERROR; | |
1678 | } | |
1679 | ||
1680 | # Create a temporary dirctory | |
1681 | my $tempdir = tempdir( CLEANUP => 1 ); | |
1682 | ||
1683 | # Extract the CA certificate from the file | |
1684 | my $pid = open(OPENSSL, "|-"); | |
1685 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1686 | if ($pid) { # parent | |
1687 | if ($cgiparams{'P12_PASS'} ne '') { | |
1688 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1689 | } | |
1690 | close (OPENSSL); | |
1691 | if ($?) { | |
1692 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1693 | unlink ($filename); | |
1694 | goto ROOTCERT_ERROR; | |
1695 | } | |
1696 | } else { # child | |
1697 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-cacerts', '-nokeys', | |
1698 | '-in', $filename, | |
1699 | '-out', "$tempdir/cacert.pem")) { | |
1700 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1701 | unlink ($filename); | |
1702 | goto ROOTCERT_ERROR; | |
1703 | } | |
1704 | } | |
1705 | ||
1706 | # Extract the Host certificate from the file | |
1707 | $pid = open(OPENSSL, "|-"); | |
1708 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1709 | if ($pid) { # parent | |
1710 | if ($cgiparams{'P12_PASS'} ne '') { | |
1711 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1712 | } | |
1713 | close (OPENSSL); | |
1714 | if ($?) { | |
1715 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1716 | unlink ($filename); | |
1717 | goto ROOTCERT_ERROR; | |
1718 | } | |
1719 | } else { # child | |
1720 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-clcerts', '-nokeys', | |
1721 | '-in', $filename, | |
1722 | '-out', "$tempdir/hostcert.pem")) { | |
1723 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1724 | unlink ($filename); | |
1725 | goto ROOTCERT_ERROR; | |
1726 | } | |
1727 | } | |
1728 | ||
1729 | # Extract the Host key from the file | |
1730 | $pid = open(OPENSSL, "|-"); | |
1731 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1732 | if ($pid) { # parent | |
1733 | if ($cgiparams{'P12_PASS'} ne '') { | |
1734 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1735 | } | |
1736 | close (OPENSSL); | |
1737 | if ($?) { | |
1738 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1739 | unlink ($filename); | |
1740 | goto ROOTCERT_ERROR; | |
1741 | } | |
1742 | } else { # child | |
1743 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-nocerts', | |
1744 | '-nodes', | |
1745 | '-in', $filename, | |
1746 | '-out', "$tempdir/serverkey.pem")) { | |
1747 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1748 | unlink ($filename); | |
1749 | goto ROOTCERT_ERROR; | |
1750 | } | |
1751 | } | |
1752 | ||
1753 | move("$tempdir/cacert.pem", "${General::swroot}/ovpn/ca/cacert.pem"); | |
1754 | if ($? ne 0) { | |
1755 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1756 | unlink ($filename); | |
1757 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1758 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1759 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1760 | goto ROOTCERT_ERROR; | |
1761 | } | |
1762 | ||
1763 | move("$tempdir/hostcert.pem", "${General::swroot}/ovpn/certs/servercert.pem"); | |
1764 | if ($? ne 0) { | |
1765 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1766 | unlink ($filename); | |
1767 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1768 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1769 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1770 | goto ROOTCERT_ERROR; | |
1771 | } | |
1772 | ||
1773 | move("$tempdir/serverkey.pem", "${General::swroot}/ovpn/certs/serverkey.pem"); | |
1774 | if ($? ne 0) { | |
1775 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1776 | unlink ($filename); | |
1777 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1778 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1779 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1780 | goto ROOTCERT_ERROR; | |
1781 | } | |
1782 | ||
1783 | goto ROOTCERT_SUCCESS; | |
1784 | ||
1785 | } elsif ($cgiparams{'ROOTCERT_COUNTRY'} ne '') { | |
1786 | ||
1787 | # Validate input since the form was submitted | |
1788 | if ($cgiparams{'ROOTCERT_ORGANIZATION'} eq ''){ | |
1789 | $errormessage = $Lang::tr{'organization cant be empty'}; | |
1790 | goto ROOTCERT_ERROR; | |
1791 | } | |
1792 | if (length($cgiparams{'ROOTCERT_ORGANIZATION'}) >60) { | |
1793 | $errormessage = $Lang::tr{'organization too long'}; | |
1794 | goto ROOTCERT_ERROR; | |
1795 | } | |
1796 | if ($cgiparams{'ROOTCERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1797 | $errormessage = $Lang::tr{'invalid input for organization'}; | |
1798 | goto ROOTCERT_ERROR; | |
1799 | } | |
1800 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq ''){ | |
1801 | $errormessage = $Lang::tr{'hostname cant be empty'}; | |
1802 | goto ROOTCERT_ERROR; | |
1803 | } | |
1804 | unless (&General::validfqdn($cgiparams{'ROOTCERT_HOSTNAME'}) || &General::validip($cgiparams{'ROOTCERT_HOSTNAME'})) { | |
1805 | $errormessage = $Lang::tr{'invalid input for hostname'}; | |
1806 | goto ROOTCERT_ERROR; | |
1807 | } | |
1808 | if ($cgiparams{'ROOTCERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'ROOTCERT_EMAIL'}))) { | |
1809 | $errormessage = $Lang::tr{'invalid input for e-mail address'}; | |
1810 | goto ROOTCERT_ERROR; | |
1811 | } | |
1812 | if (length($cgiparams{'ROOTCERT_EMAIL'}) > 40) { | |
1813 | $errormessage = $Lang::tr{'e-mail address too long'}; | |
1814 | goto ROOTCERT_ERROR; | |
1815 | } | |
1816 | if ($cgiparams{'ROOTCERT_OU'} ne '' && $cgiparams{'ROOTCERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1817 | $errormessage = $Lang::tr{'invalid input for department'}; | |
1818 | goto ROOTCERT_ERROR; | |
1819 | } | |
1820 | if ($cgiparams{'ROOTCERT_CITY'} ne '' && $cgiparams{'ROOTCERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1821 | $errormessage = $Lang::tr{'invalid input for city'}; | |
1822 | goto ROOTCERT_ERROR; | |
1823 | } | |
1824 | if ($cgiparams{'ROOTCERT_STATE'} ne '' && $cgiparams{'ROOTCERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1825 | $errormessage = $Lang::tr{'invalid input for state or province'}; | |
1826 | goto ROOTCERT_ERROR; | |
1827 | } | |
1828 | if ($cgiparams{'ROOTCERT_COUNTRY'} !~ /^[A-Z]*$/) { | |
1829 | $errormessage = $Lang::tr{'invalid input for country'}; | |
1830 | goto ROOTCERT_ERROR; | |
1831 | } | |
1832 | ||
1833 | # Copy the cgisettings to vpnsettings and save the configfile | |
1834 | $vpnsettings{'ROOTCERT_ORGANIZATION'} = $cgiparams{'ROOTCERT_ORGANIZATION'}; | |
1835 | $vpnsettings{'ROOTCERT_HOSTNAME'} = $cgiparams{'ROOTCERT_HOSTNAME'}; | |
1836 | $vpnsettings{'ROOTCERT_EMAIL'} = $cgiparams{'ROOTCERT_EMAIL'}; | |
1837 | $vpnsettings{'ROOTCERT_OU'} = $cgiparams{'ROOTCERT_OU'}; | |
1838 | $vpnsettings{'ROOTCERT_CITY'} = $cgiparams{'ROOTCERT_CITY'}; | |
1839 | $vpnsettings{'ROOTCERT_STATE'} = $cgiparams{'ROOTCERT_STATE'}; | |
1840 | $vpnsettings{'ROOTCERT_COUNTRY'} = $cgiparams{'ROOTCERT_COUNTRY'}; | |
1841 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1842 | ||
1843 | # Replace empty strings with a . | |
1844 | (my $ou = $cgiparams{'ROOTCERT_OU'}) =~ s/^\s*$/\./; | |
1845 | (my $city = $cgiparams{'ROOTCERT_CITY'}) =~ s/^\s*$/\./; | |
1846 | (my $state = $cgiparams{'ROOTCERT_STATE'}) =~ s/^\s*$/\./; | |
1847 | ||
1848 | # refresh | |
c6c9630e | 1849 | #system ('/bin/touch', "${General::swroot}/ovpn/gencanow"); |
6e13d0a5 MT |
1850 | |
1851 | # Create the CA certificate | |
1852 | my $pid = open(OPENSSL, "|-"); | |
1853 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1854 | if ($pid) { # parent | |
1855 | print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n"; | |
1856 | print OPENSSL "$state\n"; | |
1857 | print OPENSSL "$city\n"; | |
1858 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n"; | |
1859 | print OPENSSL "$ou\n"; | |
1860 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'} CA\n"; | |
1861 | print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n"; | |
1862 | close (OPENSSL); | |
1863 | if ($?) { | |
1864 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1865 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1866 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1867 | goto ROOTCERT_ERROR; | |
1868 | } | |
1869 | } else { # child | |
1870 | unless (exec ('/usr/bin/openssl', 'req', '-x509', '-nodes', '-rand', '/proc/interrupts:/proc/net/rt_cache', | |
49abe7af | 1871 | '-days', '999999', '-newkey', 'rsa:4096', '-sha512', |
6e13d0a5 MT |
1872 | '-keyout', "${General::swroot}/ovpn/ca/cakey.pem", |
1873 | '-out', "${General::swroot}/ovpn/ca/cacert.pem", | |
1874 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) { | |
1875 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1876 | goto ROOTCERT_ERROR; | |
1877 | } | |
1878 | } | |
1879 | ||
1880 | # Create the Host certificate request | |
1881 | $pid = open(OPENSSL, "|-"); | |
1882 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1883 | if ($pid) { # parent | |
1884 | print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n"; | |
1885 | print OPENSSL "$state\n"; | |
1886 | print OPENSSL "$city\n"; | |
1887 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n"; | |
1888 | print OPENSSL "$ou\n"; | |
1889 | print OPENSSL "$cgiparams{'ROOTCERT_HOSTNAME'}\n"; | |
1890 | print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n"; | |
1891 | print OPENSSL ".\n"; | |
1892 | print OPENSSL ".\n"; | |
1893 | close (OPENSSL); | |
1894 | if ($?) { | |
1895 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1896 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1897 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1898 | goto ROOTCERT_ERROR; | |
1899 | } | |
1900 | } else { # child | |
1901 | unless (exec ('/usr/bin/openssl', 'req', '-nodes', '-rand', '/proc/interrupts:/proc/net/rt_cache', | |
4c962356 | 1902 | '-newkey', 'rsa:2048', |
6e13d0a5 MT |
1903 | '-keyout', "${General::swroot}/ovpn/certs/serverkey.pem", |
1904 | '-out', "${General::swroot}/ovpn/certs/serverreq.pem", | |
1905 | '-extensions', 'server', | |
1906 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" )) { | |
1907 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1908 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1909 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1910 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1911 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1912 | goto ROOTCERT_ERROR; | |
1913 | } | |
1914 | } | |
1915 | ||
1916 | # Sign the host certificate request | |
1917 | system('/usr/bin/openssl', 'ca', '-days', '999999', | |
1918 | '-batch', '-notext', | |
1919 | '-in', "${General::swroot}/ovpn/certs/serverreq.pem", | |
1920 | '-out', "${General::swroot}/ovpn/certs/servercert.pem", | |
1921 | '-extensions', 'server', | |
1922 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
1923 | if ($?) { | |
1924 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1925 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1926 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1927 | unlink ("${General::swroot}/ovpn/serverkey.pem"); | |
1928 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1929 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
c6c9630e | 1930 | &newcleanssldatabase(); |
6e13d0a5 MT |
1931 | goto ROOTCERT_ERROR; |
1932 | } else { | |
1933 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
c6c9630e | 1934 | &deletebackupcert(); |
6e13d0a5 MT |
1935 | } |
1936 | ||
1937 | # Create an empty CRL | |
1938 | system('/usr/bin/openssl', 'ca', '-gencrl', | |
1939 | '-out', "${General::swroot}/ovpn/crls/cacrl.pem", | |
1940 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" ); | |
1941 | if ($?) { | |
1942 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1943 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1944 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1945 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1946 | unlink ("${General::swroot}/ovpn/crls/cacrl.pem"); | |
c6c9630e | 1947 | &cleanssldatabase(); |
6e13d0a5 | 1948 | goto ROOTCERT_ERROR; |
c6c9630e MT |
1949 | # } else { |
1950 | # &cleanssldatabase(); | |
6e13d0a5 MT |
1951 | } |
1952 | # Create Diffie Hellmann Parameter | |
1953 | system('/usr/bin/openssl', 'dhparam', '-rand', '/proc/interrupts:/proc/net/rt_cache', | |
4c962356 | 1954 | '-out', "${General::swroot}/ovpn/ca/dh1024.pem", "$cgiparams{'DHLENGHT'}"); |
6e13d0a5 MT |
1955 | if ($?) { |
1956 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1957 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1958 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1959 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1960 | unlink ("${General::swroot}/ovpn/crls/cacrl.pem"); | |
1961 | unlink ("${General::swroot}/ovpn/ca/dh1024.pem"); | |
c6c9630e | 1962 | &cleanssldatabase(); |
6e13d0a5 | 1963 | goto ROOTCERT_ERROR; |
c6c9630e MT |
1964 | # } else { |
1965 | # &cleanssldatabase(); | |
6e13d0a5 MT |
1966 | } |
1967 | goto ROOTCERT_SUCCESS; | |
1968 | } | |
1969 | ROOTCERT_ERROR: | |
1970 | if ($cgiparams{'ACTION'} ne '') { | |
1971 | &Header::showhttpheaders(); | |
4c962356 | 1972 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
6e13d0a5 MT |
1973 | &Header::openbigbox('100%', 'LEFT', '', ''); |
1974 | if ($errormessage) { | |
1975 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
1976 | print "<class name='base'>$errormessage"; | |
1977 | print " </class>"; | |
1978 | &Header::closebox(); | |
1979 | } | |
1980 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'generate root/host certificates'}:"); | |
49abe7af | 1981 | print <<END; |
6e13d0a5 MT |
1982 | <form method='post' enctype='multipart/form-data'> |
1983 | <table width='100%' border='0' cellspacing='1' cellpadding='0'> | |
1984 | <tr><td width='30%' class='base'>$Lang::tr{'organization name'}:</td> | |
1985 | <td width='35%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value='$cgiparams{'ROOTCERT_ORGANIZATION'}' size='32' /></td> | |
1986 | <td width='35%' colspan='2'> </td></tr> | |
1987 | <tr><td class='base'>$Lang::tr{'ipfires hostname'}:</td> | |
1988 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value='$cgiparams{'ROOTCERT_HOSTNAME'}' size='32' /></td> | |
1989 | <td colspan='2'> </td></tr> | |
1990 | <tr><td class='base'>$Lang::tr{'your e-mail'}: <img src='/blob.gif' alt'*' /></td> | |
1991 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value='$cgiparams{'ROOTCERT_EMAIL'}' size='32' /></td> | |
1992 | <td colspan='2'> </td></tr> | |
1993 | <tr><td class='base'>$Lang::tr{'your department'}: <img src='/blob.gif' alt'*' /></td> | |
1994 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value='$cgiparams{'ROOTCERT_OU'}' size='32' /></td> | |
1995 | <td colspan='2'> </td></tr> | |
1996 | <tr><td class='base'>$Lang::tr{'city'}: <img src='/blob.gif' alt'*' /></td> | |
1997 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value='$cgiparams{'ROOTCERT_CITY'}' size='32' /></td> | |
1998 | <td colspan='2'> </td></tr> | |
1999 | <tr><td class='base'>$Lang::tr{'state or province'}: <img src='/blob.gif' alt'*' /></td> | |
2000 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value='$cgiparams{'ROOTCERT_STATE'}' size='32' /></td> | |
2001 | <td colspan='2'> </td></tr> | |
2002 | <tr><td class='base'>$Lang::tr{'country'}:</td> | |
2003 | <td class='base'><select name='ROOTCERT_COUNTRY'> | |
2004 | ||
2005 | END | |
2006 | ; | |
2007 | foreach my $country (sort keys %{Countries::countries}) { | |
2008 | print "<option value='$Countries::countries{$country}'"; | |
2009 | if ( $Countries::countries{$country} eq $cgiparams{'ROOTCERT_COUNTRY'} ) { | |
2010 | print " selected='selected'"; | |
2011 | } | |
2012 | print ">$country</option>"; | |
2013 | } | |
49abe7af | 2014 | print <<END; |
6e13d0a5 | 2015 | </select></td> |
4c962356 EK |
2016 | <tr><td class='base'>$Lang::tr{'ovpn dh'}:</td> |
2017 | <td class='base'><select name='DHLENGHT'> | |
2018 | <option value='1024' $selected{'DHLENGHT'}{'1024'}>1024 $Lang::tr{'bit'}</option> | |
2019 | <option value='2048' $selected{'DHLENGHT'}{'2048'}>2048 $Lang::tr{'bit'}</option> | |
2020 | <option value='3072' $selected{'DHLENGHT'}{'3072'}>3072 $Lang::tr{'bit'}</option> | |
2021 | <option value='4096' $selected{'DHLENGHT'}{'4096'}>4096 $Lang::tr{'bit'}</option> | |
2022 | </select> | |
2023 | </td> | |
2024 | </tr> | |
2025 | ||
6e13d0a5 MT |
2026 | <tr><td> </td> |
2027 | <td><input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' /></td> | |
2028 | <td> </td><td> </td></tr> | |
2029 | <tr><td class='base' colspan='4' align='left'> | |
2030 | <img src='/blob.gif' valign='top' alt='*' /> $Lang::tr{'this field may be blank'}</td></tr> | |
49abe7af EK |
2031 | <tr><td colspan='2'><br></td></tr> |
2032 | <table width='100%'> | |
2033 | <tr> | |
2034 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}: </font></b>$Lang::tr{'ovpn generating the root and host certificates'} | |
2035 | <td class='base'>$Lang::tr{'dh key warn'}</td> | |
4c962356 | 2036 | </tr> |
49abe7af EK |
2037 | <tr> |
2038 | <td class='base'>$Lang::tr{'dh key warn1'}</td> | |
4c962356 | 2039 | </tr> |
49abe7af EK |
2040 | <tr><td colspan='2'><br></td></tr> |
2041 | <tr> | |
2042 | </table> | |
4c962356 | 2043 | |
49abe7af | 2044 | <table width='100%'> |
4c962356 | 2045 | <tr><td colspan='4'><hr></td></tr> |
6e13d0a5 MT |
2046 | <tr><td class='base' nowrap='nowrap'>$Lang::tr{'upload p12 file'}:</td> |
2047 | <td nowrap='nowrap'><input type='file' name='FH' size='32'></td> | |
2048 | <td colspan='2'> </td></tr> | |
2049 | <tr><td class='base'>$Lang::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' ></td> | |
2050 | <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value='$cgiparams{'P12_PASS'}' size='32' /></td> | |
2051 | <td colspan='2'> </td></tr> | |
2052 | <tr><td> </td> | |
2053 | <td><input type='submit' name='ACTION' value='$Lang::tr{'upload p12 file'}' /></td> | |
2054 | <td colspan='2'> </td></tr> | |
2055 | <tr><td class='base' colspan='4' align='left'> | |
4c962356 EK |
2056 | <img src='/blob.gif' valign='top' al='*' > $Lang::tr{'this field may be blank'}</td> |
2057 | </tr> | |
6e13d0a5 MT |
2058 | </form></table> |
2059 | END | |
2060 | ; | |
2061 | &Header::closebox(); | |
4c962356 | 2062 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; |
6e13d0a5 MT |
2063 | &Header::closebigbox(); |
2064 | &Header::closepage(); | |
2065 | exit(0) | |
2066 | } | |
2067 | ||
2068 | ROOTCERT_SUCCESS: | |
2069 | system ("chmod 600 ${General::swroot}/ovpn/certs/serverkey.pem"); | |
c6c9630e MT |
2070 | # if ($vpnsettings{'ENABLED'} eq 'on' || |
2071 | # $vpnsettings{'ENABLE_BLUE'} eq 'on') { | |
2072 | # system('/usr/local/bin/ipsecctrl', 'S'); | |
2073 | # } | |
6e13d0a5 MT |
2074 | |
2075 | ### | |
2076 | ### Enable/Disable connection | |
2077 | ### | |
ce9abb66 AH |
2078 | |
2079 | ### | |
7c1d9faf | 2080 | # m.a.d net2net |
ce9abb66 AH |
2081 | ### |
2082 | ||
6e13d0a5 | 2083 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { |
c6c9630e MT |
2084 | |
2085 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
6e13d0a5 | 2086 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
ce9abb66 AH |
2087 | # my $n2nactive = ''; |
2088 | my $n2nactive = `/bin/ps ax|grep $confighash{$cgiparams{'KEY'}}[1]|grep -v grep|awk \'{print \$1}\'`; | |
2089 | ||
6e13d0a5 | 2090 | if ($confighash{$cgiparams{'KEY'}}) { |
8c877a82 AM |
2091 | if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') { |
2092 | $confighash{$cgiparams{'KEY'}}[0] = 'on'; | |
2093 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
ce9abb66 | 2094 | |
8c877a82 | 2095 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ |
ce9abb66 | 2096 | system('/usr/local/bin/openvpnctrl', '-sn2n', $confighash{$cgiparams{'KEY'}}[1]); |
8c877a82 AM |
2097 | } |
2098 | } else { | |
ce9abb66 | 2099 | |
8c877a82 AM |
2100 | $confighash{$cgiparams{'KEY'}}[0] = 'off'; |
2101 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
ce9abb66 | 2102 | |
8c877a82 | 2103 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ |
ce9abb66 | 2104 | if ($n2nactive ne ''){ |
8c877a82 AM |
2105 | system('/usr/local/bin/openvpnctrl', '-kn2n', $confighash{$cgiparams{'KEY'}}[1]); |
2106 | } | |
ce9abb66 | 2107 | |
8c877a82 | 2108 | } else { |
ce9abb66 | 2109 | $errormessage = $Lang::tr{'invalid key'}; |
8c877a82 | 2110 | } |
ce9abb66 AH |
2111 | } |
2112 | } | |
6e13d0a5 MT |
2113 | |
2114 | ### | |
2115 | ### Download OpenVPN client package | |
2116 | ### | |
ce9abb66 AH |
2117 | |
2118 | ||
6e13d0a5 MT |
2119 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'dl client arch'}) { |
2120 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2121 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2122 | my $file = ''; | |
2123 | my $clientovpn = ''; | |
2124 | my @fileholder; | |
2125 | my $tempdir = tempdir( CLEANUP => 1 ); | |
2126 | my $zippath = "$tempdir/"; | |
ce9abb66 AH |
2127 | |
2128 | ### | |
7c1d9faf AH |
2129 | # m.a.d net2net |
2130 | ### | |
ce9abb66 AH |
2131 | |
2132 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ | |
2133 | ||
2134 | my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-Client.zip"; | |
2135 | my $zippathname = "$zippath$zipname"; | |
2136 | $clientovpn = "$confighash{$cgiparams{'KEY'}}[1].conf"; | |
2137 | my @ovsubnettemp = split(/\./,$confighash{$cgiparams{'KEY'}}[27]); | |
54fd0535 | 2138 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; |
ce9abb66 | 2139 | my $tunmtu = ''; |
7c1d9faf | 2140 | my @remsubnet = split(/\//,$confighash{$cgiparams{'KEY'}}[8]); |
54fd0535 | 2141 | my $n2nfragment = ''; |
ce9abb66 AH |
2142 | |
2143 | open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!"; | |
2144 | flock CLIENTCONF, 2; | |
2145 | ||
2146 | my $zip = Archive::Zip->new(); | |
7c1d9faf | 2147 | print CLIENTCONF "# IPFire n2n Open VPN Client Config by ummeegge und m.a.d\n"; |
ce9abb66 | 2148 | print CLIENTCONF "# \n"; |
b278daf3 | 2149 | print CLIENTCONF "# User Security\n"; |
ce9abb66 AH |
2150 | print CLIENTCONF "user nobody\n"; |
2151 | print CLIENTCONF "group nobody\n"; | |
2152 | print CLIENTCONF "persist-tun\n"; | |
2153 | print CLIENTCONF "persist-key\n"; | |
7c1d9faf | 2154 | print CLIENTCONF "script-security 2\n"; |
60f396d7 | 2155 | print CLIENTCONF "# IP/DNS for remote Server Gateway\n"; |
531f0835 | 2156 | print CLIENTCONF "remote $vpnsettings{'VPN_IP'}\n"; |
b278daf3 | 2157 | print CLIENTCONF "float\n"; |
60f396d7 | 2158 | print CLIENTCONF "# IP adresses of the VPN Subnet\n"; |
ce9abb66 | 2159 | print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n"; |
b278daf3 | 2160 | print CLIENTCONF "# Server Gateway Network\n"; |
7c1d9faf | 2161 | print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n"; |
b278daf3 | 2162 | print CLIENTCONF "# tun Device\n"; |
ce9abb66 | 2163 | print CLIENTCONF "dev $vpnsettings{'DDEVICE'}\n"; |
60f396d7 | 2164 | print CLIENTCONF "# Port and Protokoll\n"; |
ce9abb66 | 2165 | print CLIENTCONF "port $confighash{$cgiparams{'KEY'}}[29]\n"; |
60f396d7 AH |
2166 | |
2167 | if ($confighash{$cgiparams{'KEY'}}[28] eq 'tcp') { | |
2168 | print CLIENTCONF "proto tcp-client\n"; | |
2169 | print CLIENTCONF "# Packet size\n"; | |
d96c89eb | 2170 | if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1400'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]}; |
60f396d7 | 2171 | print CLIENTCONF "tun-mtu $tunmtu\n"; |
d96c89eb | 2172 | } |
60f396d7 AH |
2173 | |
2174 | if ($confighash{$cgiparams{'KEY'}}[28] eq 'udp') { | |
2175 | print CLIENTCONF "proto udp\n"; | |
2176 | print CLIENTCONF "# Paketsize\n"; | |
2177 | if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1500'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]}; | |
2178 | print CLIENTCONF "tun-mtu $tunmtu\n"; | |
54fd0535 | 2179 | if ($confighash{$cgiparams{'KEY'}}[24] ne '') {print CLIENTCONF "fragment $confighash{$cgiparams{'KEY'}}[24]\n";} |
60f396d7 | 2180 | if ($confighash{$cgiparams{'KEY'}}[23] eq 'on') {print CLIENTCONF "mssfix\n";} |
d96c89eb | 2181 | } |
1647059d SS |
2182 | if (($confighash{$cgiparams{'KEY'}}[38] eq 'yes') || |
2183 | ($confighash{$cgiparams{'KEY'}}[38] eq 'maybe') || | |
2184 | ($confighash{$cgiparams{'KEY'}}[38] eq 'no' )) { | |
2ee746be SS |
2185 | if (($confighash{$cgiparams{'KEY'}}[23] ne 'on') || ($confighash{$cgiparams{'KEY'}}[24] eq '')) { |
2186 | if ($tunmtu eq '1500' ) { | |
350f2980 | 2187 | print CLIENTCONF "mtu-disc $confighash{$cgiparams{'KEY'}}[38]\n"; |
2ee746be SS |
2188 | } |
2189 | } | |
2190 | } | |
54fd0535 | 2191 | print CLIENTCONF "ns-cert-type server\n"; |
ce9abb66 AH |
2192 | print CLIENTCONF "# Auth. Client\n"; |
2193 | print CLIENTCONF "tls-client\n"; | |
49abe7af | 2194 | print CLIENTCONF "# Cipher\n"; |
4c962356 | 2195 | print CLIENTCONF "cipher $confighash{$cgiparams{'KEY'}}[40]\n"; |
ce9abb66 AH |
2196 | if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") { |
2197 | print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12\r\n"; | |
2198 | $zip->addFile( "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12", "$confighash{$cgiparams{'KEY'}}[1].p12") or die "Can't add file $confighash{$cgiparams{'KEY'}}[1].p12\n"; | |
49abe7af EK |
2199 | } |
2200 | if ($confighash{$cgiparams{'KEY'}}[39] eq '') { | |
2201 | print CLIENTCONF "# HMAC algorithm\n"; | |
2202 | print CLIENTCONF "auth SHA1\n"; | |
2203 | } else { | |
2204 | print CLIENTCONF "# HMAC algorithm\n"; | |
2205 | print CLIENTCONF "auth $confighash{$cgiparams{'KEY'}}[39]\n"; | |
2206 | } | |
4c962356 | 2207 | if ($confighash{$cgiparams{'KEY'}}[30] eq 'on') { |
b278daf3 | 2208 | print CLIENTCONF "# Enable Compression\n"; |
ce9abb66 | 2209 | print CLIENTCONF "comp-lzo\r\n"; |
b278daf3 | 2210 | } |
ce9abb66 AH |
2211 | print CLIENTCONF "# Debug Level\n"; |
2212 | print CLIENTCONF "verb 3\n"; | |
b278daf3 | 2213 | print CLIENTCONF "# Tunnel check\n"; |
ce9abb66 | 2214 | print CLIENTCONF "keepalive 10 60\n"; |
b278daf3 | 2215 | print CLIENTCONF "# Start as daemon\n"; |
ce9abb66 AH |
2216 | print CLIENTCONF "daemon $confighash{$cgiparams{'KEY'}}[1]n2n\n"; |
2217 | print CLIENTCONF "writepid /var/run/$confighash{$cgiparams{'KEY'}}[1]n2n.pid\n"; | |
b278daf3 | 2218 | print CLIENTCONF "# Activate Management Interface and Port\n"; |
54fd0535 MT |
2219 | if ($confighash{$cgiparams{'KEY'}}[22] eq '') {print CLIENTCONF "management localhost $confighash{$cgiparams{'KEY'}}[29]\n"} |
2220 | else {print CLIENTCONF "management localhost $confighash{$cgiparams{'KEY'}}[22]\n"}; | |
ce9abb66 | 2221 | print CLIENTCONF "# remsub $confighash{$cgiparams{'KEY'}}[11]\n"; |
531f0835 | 2222 | |
ce9abb66 AH |
2223 | |
2224 | close(CLIENTCONF); | |
2225 | ||
2226 | $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n"; | |
2227 | my $status = $zip->writeToFileNamed($zippathname); | |
2228 | ||
2229 | open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!"; | |
2230 | @fileholder = <DLFILE>; | |
2231 | print "Content-Type:application/x-download\n"; | |
2232 | print "Content-Disposition:attachment;filename=$zipname\n\n"; | |
2233 | print @fileholder; | |
2234 | exit (0); | |
2235 | } | |
2236 | else | |
2237 | { | |
2238 | my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.zip"; | |
2239 | my $zippathname = "$zippath$zipname"; | |
2240 | $clientovpn = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.ovpn"; | |
2241 | ||
2242 | ### | |
7c1d9faf | 2243 | # m.a.d net2net |
ce9abb66 AH |
2244 | ### |
2245 | ||
c6c9630e | 2246 | open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!"; |
6e13d0a5 MT |
2247 | flock CLIENTCONF, 2; |
2248 | ||
2249 | my $zip = Archive::Zip->new(); | |
2250 | ||
8c877a82 | 2251 | print CLIENTCONF "#OpenVPN Client conf\r\n"; |
6e13d0a5 MT |
2252 | print CLIENTCONF "tls-client\r\n"; |
2253 | print CLIENTCONF "client\r\n"; | |
4f6e3ae3 | 2254 | print CLIENTCONF "nobind\r\n"; |
6e13d0a5 | 2255 | print CLIENTCONF "dev $vpnsettings{'DDEVICE'}\r\n"; |
c6c9630e | 2256 | print CLIENTCONF "proto $vpnsettings{'DPROTOCOL'}\r\n"; |
2ee746be SS |
2257 | |
2258 | # Check if we are using fragment, mssfix or mtu-disc and set MTU to 1500 | |
2259 | # or use configured value. | |
2260 | if ($vpnsettings{FRAGMENT} ne '' && $vpnsettings{DPROTOCOL} ne 'tcp' ) | |
4f6e3ae3 | 2261 | { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu 1500\r\n"; } |
2ee746be | 2262 | elsif ($vpnsettings{MSSFIX} eq 'on') |
4f6e3ae3 | 2263 | { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu 1500\r\n"; } |
1647059d SS |
2264 | elsif (($vpnsettings{'PMTU_DISCOVERY'} eq 'yes') || |
2265 | ($vpnsettings{'PMTU_DISCOVERY'} eq 'maybe') || | |
2266 | ($vpnsettings{'PMTU_DISCOVERY'} eq 'no' )) | |
4f6e3ae3 | 2267 | { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu 1500\r\n"; } |
2ee746be SS |
2268 | else |
2269 | { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu $vpnsettings{'DMTU'}\r\n"; } | |
2270 | ||
6e13d0a5 MT |
2271 | if ( $vpnsettings{'ENABLED'} eq 'on'){ |
2272 | print CLIENTCONF "remote $vpnsettings{'VPN_IP'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
c6c9630e MT |
2273 | if ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){ |
2274 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Blue interface\r\n"; | |
2275 | print CLIENTCONF ";remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2276 | } | |
2277 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
2278 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n"; | |
2279 | print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2280 | } | |
2281 | } elsif ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){ | |
2282 | print CLIENTCONF "remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2283 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
2284 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n"; | |
2285 | print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2286 | } | |
2287 | } elsif ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
2288 | print CLIENTCONF "remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
6e13d0a5 MT |
2289 | } |
2290 | ||
2291 | if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") { | |
c6c9630e MT |
2292 | print CLIENTCONF "pkcs12 $confighash{$cgiparams{'KEY'}}[1].p12\r\n"; |
2293 | $zip->addFile( "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12", "$confighash{$cgiparams{'KEY'}}[1].p12") or die "Can't add file $confighash{$cgiparams{'KEY'}}[1].p12\n"; | |
6e13d0a5 | 2294 | } else { |
c6c9630e MT |
2295 | print CLIENTCONF "ca cacert.pem\r\n"; |
2296 | print CLIENTCONF "cert $confighash{$cgiparams{'KEY'}}[1]cert.pem\r\n"; | |
2297 | print CLIENTCONF "key $confighash{$cgiparams{'KEY'}}[1].key\r\n"; | |
2298 | $zip->addFile( "${General::swroot}/ovpn/ca/cacert.pem", "cacert.pem") or die "Can't add file cacert.pem\n"; | |
2299 | $zip->addFile( "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem", "$confighash{$cgiparams{'KEY'}}[1]cert.pem") or die "Can't add file $confighash{$cgiparams{'KEY'}}[1]cert.pem\n"; | |
6e13d0a5 MT |
2300 | } |
2301 | print CLIENTCONF "cipher $vpnsettings{DCIPHER}\r\n"; | |
49abe7af EK |
2302 | if ($vpnsettings{'DAUTH'} eq '') { |
2303 | print CLIENTCONF ""; | |
2304 | } else { | |
2305 | print CLIENTCONF "auth $vpnsettings{'DAUTH'}\r\n"; | |
2306 | } | |
2307 | if ($vpnsettings{'TLSAUTH'} eq 'on') { | |
2308 | print CLIENTCONF "tls-auth ta.key 1\r\n"; | |
2309 | $zip->addFile( "${General::swroot}/ovpn/ca/ta.key", "ta.key") or die "Can't add file ta.key\n"; | |
2310 | } | |
6e13d0a5 MT |
2311 | if ($vpnsettings{DCOMPLZO} eq 'on') { |
2312 | print CLIENTCONF "comp-lzo\r\n"; | |
2313 | } | |
2314 | print CLIENTCONF "verb 3\r\n"; | |
2315 | print CLIENTCONF "ns-cert-type server\r\n"; | |
a79fa1d6 JPT |
2316 | print CLIENTCONF "tls-remote $vpnsettings{ROOTCERT_HOSTNAME}\r\n"; |
2317 | if ($vpnsettings{MSSFIX} eq 'on') { | |
2318 | print CLIENTCONF "mssfix\r\n"; | |
2319 | } | |
74225cce | 2320 | if ($vpnsettings{FRAGMENT} ne '' && $vpnsettings{DPROTOCOL} ne 'tcp' ) { |
a79fa1d6 JPT |
2321 | print CLIENTCONF "fragment $vpnsettings{'FRAGMENT'}\r\n"; |
2322 | } | |
1647059d SS |
2323 | |
2324 | # Check if a valid operating mode has been choosen and use it. | |
2325 | if (($vpnsettings{'PMTU_DISCOVERY'} eq 'yes') || | |
2326 | ($vpnsettings{'PMTU_DISCOVERY'} eq 'maybe') || | |
2327 | ($vpnsettings{'PMTU_DISCOVERY'} eq 'no' )) { | |
2ee746be | 2328 | if(($vpnsettings{MSSFIX} ne 'on') || ($vpnsettings{FRAGMENT} eq '')) { |
4f6e3ae3 | 2329 | print CLIENTCONF "mtu-disc $vpnsettings{'PMTU_DISCOVERY'}\r\n"; |
2ee746be SS |
2330 | } |
2331 | } | |
6e13d0a5 | 2332 | close(CLIENTCONF); |
ce9abb66 | 2333 | |
6e13d0a5 MT |
2334 | $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n"; |
2335 | my $status = $zip->writeToFileNamed($zippathname); | |
2336 | ||
2337 | open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!"; | |
2338 | @fileholder = <DLFILE>; | |
2339 | print "Content-Type:application/x-download\n"; | |
2340 | print "Content-Disposition:attachment;filename=$zipname\n\n"; | |
2341 | print @fileholder; | |
2342 | exit (0); | |
ce9abb66 AH |
2343 | } |
2344 | ||
2345 | ||
2346 | ||
6e13d0a5 MT |
2347 | ### |
2348 | ### Remove connection | |
2349 | ### | |
ce9abb66 AH |
2350 | |
2351 | ||
6e13d0a5 MT |
2352 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) { |
2353 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2354 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e MT |
2355 | |
2356 | if ($confighash{$cgiparams{'KEY'}}) { | |
2357 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
2358 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
2359 | # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}); | |
2360 | # } | |
2361 | # | |
2362 | my $temp = `/usr/bin/openssl ca -revoke ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf`; | |
ce9abb66 AH |
2363 | |
2364 | ### | |
7c1d9faf | 2365 | # m.a.d net2net |
ce9abb66 | 2366 | ### |
7c1d9faf | 2367 | |
8e6a8fd5 | 2368 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net') { |
ce9abb66 | 2369 | my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf"); |
8e6a8fd5 MT |
2370 | my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); |
2371 | unlink ($certfile); | |
2372 | unlink ($conffile); | |
2373 | ||
2374 | if (-e "${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") { | |
2375 | rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!"; | |
2376 | } | |
ce9abb66 | 2377 | } |
ce9abb66 AH |
2378 | |
2379 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); | |
8c877a82 AM |
2380 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); |
2381 | ||
2382 | # A.Marx CCD delete ccd files and routes | |
2383 | ||
2384 | ||
2385 | if (-f "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]") | |
2386 | { | |
2387 | unlink "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]"; | |
2388 | } | |
e81be1e1 | 2389 | |
8c877a82 AM |
2390 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); |
2391 | foreach my $key (keys %ccdroutehash) { | |
2392 | if ($ccdroutehash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){ | |
2393 | delete $ccdroutehash{$key}; | |
2394 | } | |
2395 | } | |
2396 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
e81be1e1 | 2397 | |
8c877a82 AM |
2398 | &General::readhasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); |
2399 | foreach my $key (keys %ccdroute2hash) { | |
2400 | if ($ccdroute2hash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){ | |
2401 | delete $ccdroute2hash{$key}; | |
2402 | } | |
2403 | } | |
2404 | &General::writehasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
52d08bcb | 2405 | &writeserverconf; |
8c877a82 AM |
2406 | |
2407 | ||
2408 | # CCD end | |
2409 | ||
2410 | ||
c6c9630e MT |
2411 | delete $confighash{$cgiparams{'KEY'}}; |
2412 | my $temp2 = `/usr/bin/openssl ca -gencrl -out ${General::swroot}/ovpn/crls/cacrl.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf`; | |
2413 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
8c877a82 | 2414 | |
c6c9630e | 2415 | #&writeserverconf(); |
6e13d0a5 | 2416 | } else { |
c6c9630e | 2417 | $errormessage = $Lang::tr{'invalid key'}; |
6e13d0a5 | 2418 | } |
b2e75449 | 2419 | &General::firewall_reload(); |
ce9abb66 | 2420 | |
6e13d0a5 MT |
2421 | ### |
2422 | ### Download PKCS12 file | |
2423 | ### | |
2424 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download pkcs12 file'}) { | |
2425 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2426 | ||
2427 | print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . ".p12\r\n"; | |
2428 | print "Content-Type: application/octet-stream\r\n\r\n"; | |
2429 | print `/bin/cat ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12`; | |
2430 | exit (0); | |
2431 | ||
2432 | ### | |
2433 | ### Display certificate | |
2434 | ### | |
2435 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show certificate'}) { | |
2436 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2437 | ||
2438 | if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") { | |
c6c9630e | 2439 | &Header::showhttpheaders(); |
4c962356 | 2440 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
c6c9630e MT |
2441 | &Header::openbigbox('100%', 'LEFT', '', ''); |
2442 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate'}:"); | |
2443 | my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`; | |
2444 | $output = &Header::cleanhtml($output,"y"); | |
2445 | print "<pre>$output</pre>\n"; | |
2446 | &Header::closebox(); | |
2447 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2448 | &Header::closebigbox(); | |
2449 | &Header::closepage(); | |
2450 | exit(0); | |
6e13d0a5 | 2451 | } |
4c962356 EK |
2452 | |
2453 | ### | |
2454 | ### Display Diffie-Hellman key | |
2455 | ### | |
2456 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show dh'}) { | |
2457 | ||
2458 | if (! -e "${General::swroot}/ovpn/ca/dh1024.pem") { | |
49abe7af | 2459 | $errormessage = $Lang::tr{'not present'}; |
4c962356 EK |
2460 | } else { |
2461 | &Header::showhttpheaders(); | |
2462 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
2463 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2464 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'dh'}:"); | |
2465 | my $output = `/usr/bin/openssl dhparam -text -in ${General::swroot}/ovpn/ca/dh1024.pem`; | |
2466 | $output = &Header::cleanhtml($output,"y"); | |
2467 | print "<pre>$output</pre>\n"; | |
2468 | &Header::closebox(); | |
2469 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2470 | &Header::closebigbox(); | |
2471 | &Header::closepage(); | |
2472 | exit(0); | |
2473 | } | |
2474 | ||
6e13d0a5 MT |
2475 | ### |
2476 | ### Display Certificate Revoke List | |
2477 | ### | |
2478 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show crl'}) { | |
c6c9630e MT |
2479 | # &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
2480 | ||
49abe7af EK |
2481 | if (! -e "${General::swroot}/ovpn/crls/cacrl.pem") { |
2482 | $errormessage = $Lang::tr{'not present'}; | |
2483 | } else { | |
b2e75449 MT |
2484 | &Header::showhttpheaders(); |
2485 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
2486 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2487 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'crl'}:"); | |
2488 | my $output = `/usr/bin/openssl crl -text -noout -in ${General::swroot}/ovpn/crls/cacrl.pem`; | |
2489 | $output = &Header::cleanhtml($output,"y"); | |
2490 | print "<pre>$output</pre>\n"; | |
2491 | &Header::closebox(); | |
2492 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2493 | &Header::closebigbox(); | |
2494 | &Header::closepage(); | |
2495 | exit(0); | |
6e13d0a5 MT |
2496 | } |
2497 | ||
2498 | ### | |
2499 | ### Advanced Server Settings | |
2500 | ### | |
2501 | ||
2502 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'advanced server'}) { | |
2503 | %cgiparams = (); | |
2504 | %cahash = (); | |
2505 | %confighash = (); | |
8c877a82 | 2506 | my $disabled; |
6e13d0a5 | 2507 | &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams); |
54fd0535 | 2508 | read_routepushfile; |
8c877a82 AM |
2509 | |
2510 | ||
c6c9630e MT |
2511 | # if ($cgiparams{'CLIENT2CLIENT'} eq '') { |
2512 | # $cgiparams{'CLIENT2CLIENT'} = 'on'; | |
2513 | # } | |
6e13d0a5 MT |
2514 | ADV_ERROR: |
2515 | if ($cgiparams{'MAX_CLIENTS'} eq '') { | |
4c962356 | 2516 | $cgiparams{'MAX_CLIENTS'} = '100'; |
6e13d0a5 | 2517 | } |
6e13d0a5 | 2518 | if ($cgiparams{'KEEPALIVE_1'} eq '') { |
4c962356 | 2519 | $cgiparams{'KEEPALIVE_1'} = '10'; |
6e13d0a5 MT |
2520 | } |
2521 | if ($cgiparams{'KEEPALIVE_2'} eq '') { | |
4c962356 | 2522 | $cgiparams{'KEEPALIVE_2'} = '60'; |
6e13d0a5 MT |
2523 | } |
2524 | if ($cgiparams{'LOG_VERB'} eq '') { | |
4c962356 | 2525 | $cgiparams{'LOG_VERB'} = '3'; |
ae9f6139 | 2526 | } |
92b87e17 | 2527 | if ($cgiparams{'PMTU_DISCOVERY'} eq '') { |
4c962356 EK |
2528 | $cgiparams{'PMTU_DISCOVERY'} = 'off'; |
2529 | } | |
2530 | if ($cgiparams{'DAUTH'} eq '') { | |
2531 | $cgiparams{'DAUTH'} = 'SHA1'; | |
92b87e17 | 2532 | } |
49abe7af EK |
2533 | if ($cgiparams{'DAUTH'} eq '') { |
2534 | $cgiparams{'DAUTH'} = 'SHA1'; | |
2535 | } | |
2536 | if ($cgiparams{'ENGINES'} eq '') { | |
2537 | $cgiparams{'ENGINES'} = 'disabled'; | |
2538 | } | |
2539 | if ($cgiparams{'TLSAUTH'} eq '') { | |
2540 | $cgiparams{'TLSAUTH'} = 'off'; | |
2541 | } | |
6e13d0a5 MT |
2542 | $checked{'CLIENT2CLIENT'}{'off'} = ''; |
2543 | $checked{'CLIENT2CLIENT'}{'on'} = ''; | |
2544 | $checked{'CLIENT2CLIENT'}{$cgiparams{'CLIENT2CLIENT'}} = 'CHECKED'; | |
2545 | $checked{'REDIRECT_GW_DEF1'}{'off'} = ''; | |
2546 | $checked{'REDIRECT_GW_DEF1'}{'on'} = ''; | |
2547 | $checked{'REDIRECT_GW_DEF1'}{$cgiparams{'REDIRECT_GW_DEF1'}} = 'CHECKED'; | |
a79fa1d6 JPT |
2548 | $checked{'MSSFIX'}{'off'} = ''; |
2549 | $checked{'MSSFIX'}{'on'} = ''; | |
2550 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
2ee746be | 2551 | $checked{'PMTU_DISCOVERY'}{$cgiparams{'PMTU_DISCOVERY'}} = 'checked=\'checked\''; |
49abe7af | 2552 | $selected{'LOG_VERB'}{'0'} = ''; |
6e13d0a5 MT |
2553 | $selected{'LOG_VERB'}{'1'} = ''; |
2554 | $selected{'LOG_VERB'}{'2'} = ''; | |
2555 | $selected{'LOG_VERB'}{'3'} = ''; | |
2556 | $selected{'LOG_VERB'}{'4'} = ''; | |
2557 | $selected{'LOG_VERB'}{'5'} = ''; | |
2558 | $selected{'LOG_VERB'}{'6'} = ''; | |
2559 | $selected{'LOG_VERB'}{'7'} = ''; | |
2560 | $selected{'LOG_VERB'}{'8'} = ''; | |
2561 | $selected{'LOG_VERB'}{'9'} = ''; | |
2562 | $selected{'LOG_VERB'}{'10'} = ''; | |
2563 | $selected{'LOG_VERB'}{'11'} = ''; | |
6e13d0a5 | 2564 | $selected{'LOG_VERB'}{$cgiparams{'LOG_VERB'}} = 'SELECTED'; |
4c962356 EK |
2565 | $selected{'DAUTH'}{'whirlpool'} = ''; |
2566 | $selected{'DAUTH'}{'SHA512'} = ''; | |
2567 | $selected{'DAUTH'}{'SHA384'} = ''; | |
2568 | $selected{'DAUTH'}{'SHA256'} = ''; | |
4c962356 EK |
2569 | $selected{'DAUTH'}{'SHA1'} = ''; |
2570 | $selected{'DAUTH'}{$cgiparams{'DAUTH'}} = 'SELECTED'; | |
49abe7af EK |
2571 | $checked{'TLSAUTH'}{'off'} = ''; |
2572 | $checked{'TLSAUTH'}{'on'} = ''; | |
2573 | $checked{'TLSAUTH'}{$cgiparams{'TLSAUTH'}} = 'CHECKED'; | |
2574 | $selected{'ENGINES'}{'cryptodev'} = ''; | |
2575 | $selected{'ENGINES'}{'dynamic'} = ''; | |
2576 | $selected{'ENGINES'}{'aesni'} = ''; | |
2577 | $selected{'ENGINES'}{'padlock'} = ''; | |
2578 | $selected{'ENGINES'}{'disabled'} = ''; | |
2579 | $selected{'ENGINES'}{$cgiparams{'ENGINES'}} = 'SELECTED'; | |
4c962356 | 2580 | |
6e13d0a5 MT |
2581 | &Header::showhttpheaders(); |
2582 | &Header::openpage($Lang::tr{'status ovpn'}, 1, ''); | |
2583 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
2584 | if ($errormessage) { | |
c6c9630e MT |
2585 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); |
2586 | print "<class name='base'>$errormessage\n"; | |
2587 | print " </class>\n"; | |
2588 | &Header::closebox(); | |
6e13d0a5 MT |
2589 | } |
2590 | &Header::openbox('100%', 'LEFT', $Lang::tr{'advanced server'}); | |
4c962356 | 2591 | print <<END; |
b376fae4 | 2592 | <form method='post' enctype='multipart/form-data'> |
b2e75449 | 2593 | <table width='100%' border=0> |
4c962356 EK |
2594 | <tr> |
2595 | <td colspan='4'><b>$Lang::tr{'dhcp-options'}</b></td> | |
6e13d0a5 MT |
2596 | </tr> |
2597 | <tr> | |
4c962356 | 2598 | <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td> |
6e13d0a5 MT |
2599 | </tr> |
2600 | <tr> | |
4c962356 | 2601 | <td class='base'>Domain</td> |
8c877a82 | 2602 | <td><input type='TEXT' name='DHCP_DOMAIN' value='$cgiparams{'DHCP_DOMAIN'}' size='30' /></td> |
6e13d0a5 MT |
2603 | </tr> |
2604 | <tr> | |
4c962356 EK |
2605 | <td class='base'>DNS</td> |
2606 | <td><input type='TEXT' name='DHCP_DNS' value='$cgiparams{'DHCP_DNS'}' size='30' /></td> | |
6e13d0a5 MT |
2607 | </tr> |
2608 | <tr> | |
4c962356 EK |
2609 | <td class='base'>WINS</td> |
2610 | <td><input type='TEXT' name='DHCP_WINS' value='$cgiparams{'DHCP_WINS'}' size='30' /></td> | |
2611 | </tr> | |
54fd0535 | 2612 | <tr> |
4c962356 | 2613 | <td colspan='4'><b>$Lang::tr{'ovpn routes push options'}</b></td> |
54fd0535 MT |
2614 | </tr> |
2615 | <tr> | |
4c962356 EK |
2616 | <td class='base'>$Lang::tr{'ovpn routes push'}</td> |
2617 | <td colspan='2'> | |
2618 | <textarea name='ROUTES_PUSH' cols='26' rows='6' wrap='off'> | |
54fd0535 MT |
2619 | END |
2620 | ; | |
2621 | ||
2622 | if ($cgiparams{'ROUTES_PUSH'} ne '') | |
2623 | { | |
2624 | print $cgiparams{'ROUTES_PUSH'}; | |
2625 | } | |
2626 | ||
8c877a82 | 2627 | print <<END; |
54fd0535 MT |
2628 | </textarea></td> |
2629 | </tr> | |
6e13d0a5 MT |
2630 | </tr> |
2631 | </table> | |
2632 | <hr size='1'> | |
4c962356 | 2633 | <table width='100%'> |
6e13d0a5 | 2634 | <tr> |
4c962356 | 2635 | <td class'base'><b>$Lang::tr{'misc-options'}</b></td> |
6e13d0a5 MT |
2636 | </tr> |
2637 | <tr> | |
4c962356 | 2638 | <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='15%'></td><td width='35%'></td> |
6e13d0a5 MT |
2639 | </tr> |
2640 | <tr> | |
4c962356 EK |
2641 | <td class='base'>Client-To-Client</td> |
2642 | <td><input type='checkbox' name='CLIENT2CLIENT' $checked{'CLIENT2CLIENT'}{'on'} /></td> | |
6e13d0a5 MT |
2643 | </tr> |
2644 | <tr> | |
4c962356 EK |
2645 | <td class='base'>Redirect-Gateway def1</td> |
2646 | <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked{'REDIRECT_GW_DEF1'}{'on'} /></td> | |
6e13d0a5 MT |
2647 | </tr> |
2648 | <tr> | |
2649 | <td class='base'>Max-Clients</td> | |
a79fa1d6 | 2650 | <td><input type='text' name='MAX_CLIENTS' value='$cgiparams{'MAX_CLIENTS'}' size='10' /></td> |
6e13d0a5 | 2651 | </tr> |
4c962356 | 2652 | <tr> |
f0ccae18 | 2653 | <td class='base'>Keepalive <br /> |
a79fa1d6 JPT |
2654 | (ping/ping-restart)</td> |
2655 | <td><input type='TEXT' name='KEEPALIVE_1' value='$cgiparams{'KEEPALIVE_1'}' size='10' /></td> | |
2656 | <td><input type='TEXT' name='KEEPALIVE_2' value='$cgiparams{'KEEPALIVE_2'}' size='10' /></td> | |
2657 | </tr> | |
4c962356 | 2658 | <tr> |
a79fa1d6 JPT |
2659 | <td class='base'>fragment <br></td> |
2660 | <td><input type='TEXT' name='FRAGMENT' value='$cgiparams{'FRAGMENT'}' size='10' /></td> | |
60f396d7 | 2661 | </tr> |
a79fa1d6 JPT |
2662 | <tr> |
2663 | <td class='base'>mssfix</td> | |
2664 | <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td> | |
49abe7af | 2665 | <td>$Lang::tr{'openvpn default'}: off</td> |
2ee746be SS |
2666 | </tr> |
2667 | ||
2668 | <tr> | |
2669 | <td class='base'>$Lang::tr{'ovpn mtu-disc'}</td> | |
2670 | <td><input type='radio' name='PMTU_DISCOVERY' value='yes' $checked{'PMTU_DISCOVERY'}{'yes'} /> $Lang::tr{'ovpn mtu-disc yes'}</td> | |
2671 | <td><input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked{'PMTU_DISCOVERY'}{'maybe'} /> $Lang::tr{'ovpn mtu-disc maybe'}</td> | |
2672 | <td><input type='radio' name='PMTU_DISCOVERY' value='no' $checked{'PMTU_DISCOVERY'}{'no'} /> $Lang::tr{'ovpn mtu-disc no'}</td> | |
2673 | <td><input type='radio' name='PMTU_DISCOVERY' value='off' $checked{'PMTU_DISCOVERY'}{'off'} /> $Lang::tr{'ovpn mtu-disc off'}</td> | |
2674 | </tr> | |
a79fa1d6 JPT |
2675 | </table> |
2676 | ||
a79fa1d6 | 2677 | <hr size='1'> |
4c962356 | 2678 | <table width='100%'> |
a79fa1d6 | 2679 | <tr> |
49abe7af | 2680 | <td class'base'><b>$Lang::tr{'log-options'}</b></td> |
a79fa1d6 JPT |
2681 | </tr> |
2682 | <tr> | |
49abe7af | 2683 | <td width='20%'></td> <td width='30%'> </td><td width='25%'> </td><td width='25%'></td> |
4c962356 EK |
2684 | </tr> |
2685 | ||
2686 | <tr><td class='base'>VERB</td> | |
2687 | <td><select name='LOG_VERB'> | |
49abe7af EK |
2688 | <option value='0' $selected{'LOG_VERB'}{'0'}>0</option> |
2689 | <option value='1' $selected{'LOG_VERB'}{'1'}>1</option> | |
2690 | <option value='2' $selected{'LOG_VERB'}{'2'}>2</option> | |
2691 | <option value='3' $selected{'LOG_VERB'}{'3'}>3</option> | |
2692 | <option value='4' $selected{'LOG_VERB'}{'4'}>4</option> | |
2693 | <option value='5' $selected{'LOG_VERB'}{'5'}>5</option> | |
2694 | <option value='6' $selected{'LOG_VERB'}{'6'}>6</option> | |
2695 | <option value='7' $selected{'LOG_VERB'}{'7'}>7</option> | |
2696 | <option value='8' $selected{'LOG_VERB'}{'8'}>8</option> | |
2697 | <option value='9' $selected{'LOG_VERB'}{'9'}>9</option> | |
2698 | <option value='10' $selected{'LOG_VERB'}{'10'}>10</option> | |
2699 | <option value='11' $selected{'LOG_VERB'}{'11'}>11</option> | |
2700 | </td></select> | |
2701 | </table> | |
4c962356 | 2702 | |
6e13d0a5 | 2703 | <hr size='1'> |
4c962356 | 2704 | <table width='100%'> |
6e13d0a5 | 2705 | <tr> |
4c962356 EK |
2706 | <td class'base'><b>$Lang::tr{'ovpn crypt options'}</b></td> |
2707 | </tr> | |
2708 | <tr> | |
2709 | <td width='20%'></td> <td width='30%'> </td><td width='25%'> </td><td width='25%'></td> | |
6e13d0a5 | 2710 | </tr> |
4c962356 EK |
2711 | <tr><td class='base'>$Lang::tr{'ovpn ha'}</td> |
2712 | <td><select name='DAUTH'> | |
b2e75449 MT |
2713 | <option value='whirlpool' $selected{'DAUTH'}{'whirlpool'}>Whirlpool (512 $Lang::tr{'bit'})</option> |
2714 | <option value='SHA512' $selected{'DAUTH'}{'SHA512'}>SHA2 (512 $Lang::tr{'bit'})</option> | |
2715 | <option value='SHA384' $selected{'DAUTH'}{'SHA384'}>SHA2 (384 $Lang::tr{'bit'})</option> | |
2716 | <option value='SHA256' $selected{'DAUTH'}{'SHA256'}>SHA2 (256 $Lang::tr{'bit'})</option> | |
b2e75449 | 2717 | <option value='SHA1' $selected{'DAUTH'}{'SHA1'}>SHA1 (160 $Lang::tr{'bit'})</option> |
4c962356 EK |
2718 | </select> |
2719 | </td> | |
2720 | <td>Default: <span class="base">SHA1 (160 $Lang::tr{'bit'})</span></td> | |
49abe7af EK |
2721 | </tr> |
2722 | ||
2723 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn engines'}</td> | |
2724 | <td><select name='ENGINES'> | |
2725 | <option value='cryptodev' $selected{'ENGINES'}{'cryptodev'}>Cryptodev</option> | |
2726 | <option value='dynamic' $selected{'ENGINES'}{'dynamic'}>Dynamic</option> | |
2727 | <option value='aesni' $selected{'ENGINES'}{'aesni'}>AES-NI</option> | |
2728 | <option value='padlock' $selected{'ENGINES'}{'padlock'}>Padlock</option> | |
2729 | <option value='disabled' $selected{'ENGINES'}{'disabled'}>$Lang::tr{'disabled'}</option> | |
2730 | </select> | |
2731 | </td> | |
2732 | <td>Default: <span class="base">$Lang::tr{'disabled'}</span></td> | |
2733 | </tr> | |
6e13d0a5 | 2734 | </table> |
49abe7af EK |
2735 | |
2736 | <table width='100%'> | |
6e13d0a5 | 2737 | <tr> |
49abe7af | 2738 | <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='15%'></td><td width='35%'></td> |
6e13d0a5 | 2739 | </tr> |
4c962356 | 2740 | |
6e13d0a5 | 2741 | <tr> |
49abe7af EK |
2742 | <td class='base'>HMAC tls-auth</td> |
2743 | <td><input type='checkbox' name='TLSAUTH' $checked{'TLSAUTH'}{'on'} /></td> | |
2744 | </tr> | |
2745 | </table><hr> | |
8c877a82 AM |
2746 | END |
2747 | ||
2748 | if ( -e "/var/run/openvpn.pid"){ | |
2749 | print" <br><b><font color='#990000'>$Lang::tr{'attention'}:</b></font><br> | |
2750 | $Lang::tr{'server restart'}<br><br> | |
2751 | <hr>"; | |
49abe7af | 2752 | print<<END; |
52d08bcb AM |
2753 | <table width='100%'> |
2754 | <tr> | |
2755 | <td> </td> | |
2756 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' disabled='disabled' /></td> | |
2757 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td> | |
2758 | <td> </td> | |
2759 | </tr> | |
2760 | </table> | |
2761 | </form> | |
2762 | END | |
2763 | ; | |
2764 | ||
2765 | ||
2766 | }else{ | |
8c877a82 | 2767 | |
49abe7af | 2768 | print<<END; |
6e13d0a5 MT |
2769 | <table width='100%'> |
2770 | <tr> | |
2771 | <td> </td> | |
2772 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' /></td> | |
2773 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td> | |
2774 | <td> </td> | |
2775 | </tr> | |
2776 | </table> | |
2777 | </form> | |
2778 | END | |
2779 | ; | |
52d08bcb | 2780 | } |
6e13d0a5 | 2781 | &Header::closebox(); |
c6c9630e | 2782 | # print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; |
6e13d0a5 MT |
2783 | &Header::closebigbox(); |
2784 | &Header::closepage(); | |
2785 | exit(0); | |
2786 | ||
8c877a82 AM |
2787 | |
2788 | # A.Marx CCD Add,delete or edit CCD net | |
2789 | ||
2790 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'ccd net'} || | |
2791 | $cgiparams{'ACTION'} eq $Lang::tr{'ccd add'} || | |
2792 | $cgiparams{'ACTION'} eq "kill" || | |
2793 | $cgiparams{'ACTION'} eq "edit" || | |
2794 | $cgiparams{'ACTION'} eq 'editsave'){ | |
2795 | &Header::showhttpheaders(); | |
2796 | &Header::openpage($Lang::tr{'ccd net'}, 1, ''); | |
2797 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2798 | ||
2799 | if ($cgiparams{'ACTION'} eq "kill"){ | |
2800 | &delccdnet($cgiparams{'net'}); | |
2801 | } | |
2802 | ||
2803 | if ($cgiparams{'ACTION'} eq 'editsave'){ | |
2804 | my ($a,$b) =split (/\|/,$cgiparams{'ccdname'}); | |
2805 | if ( $a ne $b){ &modccdnet($a,$b);} | |
5068ac38 AM |
2806 | $cgiparams{'ccdname'}=''; |
2807 | $cgiparams{'ccdsubnet'}=''; | |
8c877a82 AM |
2808 | } |
2809 | ||
2810 | if ($cgiparams{'ACTION'} eq $Lang::tr{'ccd add'}) { | |
e2429e8d | 2811 | &addccdnet($cgiparams{'ccdname'},$cgiparams{'ccdsubnet'}); |
8c877a82 AM |
2812 | } |
2813 | if ($errormessage) { | |
2814 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
2815 | print "<class name='base'>$errormessage"; | |
2816 | print " </class>"; | |
2817 | &Header::closebox(); | |
2818 | } | |
2819 | if ($cgiparams{'ACTION'} eq "edit"){ | |
2820 | ||
2821 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ccd modify'}); | |
2822 | ||
49abe7af | 2823 | print <<END; |
631b67b7 | 2824 | <table width='100%' border='0'> |
8c877a82 AM |
2825 | <tr><form method='post'> |
2826 | <td width='10%' nowrap='nowrap'>$Lang::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value='$cgiparams{'ccdname'}' /></td> | |
b2e75449 | 2827 | <td width='8%'>$Lang::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value='$cgiparams{'ccdsubnet'}' readonly /></td></tr> |
8c877a82 AM |
2828 | <tr><td colspan='4' align='right'><hr><input type='submit' value='$Lang::tr{'save'}' /><input type='hidden' name='ACTION' value='editsave'/> |
2829 | <input type='hidden' name='ccdname' value='$cgiparams{'ccdname'}'/><input type='submit' value='$Lang::tr{'cancel'}' /> | |
2830 | </td></tr> | |
2831 | </table></form> | |
2832 | END | |
2833 | ; | |
2834 | &Header::closebox(); | |
2835 | ||
2836 | &Header::openbox('100%', 'LEFT',$Lang::tr{'ccd net'} ); | |
49abe7af | 2837 | print <<END; |
8c877a82 AM |
2838 | <table width='100%' border='0' cellpadding='0' cellspacing='1'> |
2839 | <tr> | |
2840 | <td class='boldbase' align='center'><b>$Lang::tr{'ccd name'}</td><td class='boldbase' align='center'><b>$Lang::tr{'network'}</td><td class='boldbase' width='15%' align='center'><b>$Lang::tr{'ccd used'}</td><td width='3%'></td><td width='3%'></td></tr> | |
2841 | END | |
2842 | ; | |
2843 | } | |
2844 | else{ | |
2845 | if (! -e "/var/run/openvpn.pid"){ | |
2846 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ccd add'}); | |
49abe7af | 2847 | print <<END; |
8c877a82 AM |
2848 | <table width='100%' border='0'> |
2849 | <tr><form method='post'> | |
2850 | <td colspan='4'>$Lang::tr{'ccd hint'}<br><br></td></tr> | |
2851 | <tr> | |
2852 | <td width='10%' nowrap='nwrap'>$Lang::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value='$cgiparams{'ccdname'}' /></td> | |
2853 | <td width='8%'>$Lang::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value='$cgiparams{'ccdsubnet'}' /></td></tr> | |
2854 | <tr><td colspan=4><hr /></td></tr><tr> | |
2855 | <td colspan='4' align='right'><input type='hidden' name='ACTION' value='$Lang::tr{'ccd add'}' /><input type='submit' value='$Lang::tr{'add'}' /><input type='hidden' name='DOVPN_SUBNET' value='$cgiparams{'DOVPN_SUBNET'}'/></td></tr> | |
2856 | </table></form> | |
2857 | END | |
2858 | ||
2859 | &Header::closebox(); | |
2860 | } | |
2861 | &Header::openbox('100%', 'LEFT',$Lang::tr{'ccd net'} ); | |
5068ac38 AM |
2862 | if ( -e "/var/run/openvpn.pid"){ |
2863 | print "<b>$Lang::tr{'attention'}:</b><br>"; | |
2864 | print "$Lang::tr{'ccd noaddnet'}<br><hr>"; | |
2865 | } | |
2866 | ||
4c962356 | 2867 | print <<END; |
99bfa85c | 2868 | <table width='100%' cellpadding='0' cellspacing='1'> |
8c877a82 AM |
2869 | <tr> |
2870 | <td class='boldbase' align='center' nowrap='nowrap' width='20%'><b>$Lang::tr{'ccd name'}</td><td class='boldbase' align='center' width='8%'><b>$Lang::tr{'network'}</td><td class='boldbase' width='8%' align='center' nowrap='nowrap'><b>$Lang::tr{'ccd used'}</td><td width='1%' align='center'></td><td width='1%' align='center'></td></tr> | |
2871 | END | |
2872 | ; | |
2873 | } | |
2874 | my %ccdconfhash=(); | |
2875 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
2876 | my @ccdconf=(); | |
2877 | my $count=0; | |
df9b48b7 | 2878 | foreach my $key (sort { uc($ccdconfhash{$a}[0]) cmp uc($ccdconfhash{$b}[0]) } keys %ccdconfhash) { |
8c877a82 AM |
2879 | @ccdconf=($ccdconfhash{$key}[0],$ccdconfhash{$key}[1]); |
2880 | $count++; | |
2881 | my $ccdhosts = &hostsinnet($ccdconf[0]); | |
2882 | if ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";} | |
2883 | else{ print" <tr bgcolor='$color{'color20'}'>";} | |
2884 | print"<td>$ccdconf[0]</td><td align='center'>$ccdconf[1]</td><td align='center'>$ccdhosts/".(&ccdmaxclients($ccdconf[1])+1)."</td><td>"; | |
4c962356 | 2885 | print <<END; |
8c877a82 | 2886 | <form method='post' /> |
b2e75449 | 2887 | <input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} /> |
8c877a82 AM |
2888 | <input type='hidden' name='ACTION' value='edit'/> |
2889 | <input type='hidden' name='ccdname' value='$ccdconf[0]' /> | |
2890 | <input type='hidden' name='ccdsubnet' value='$ccdconf[1]' /> | |
2891 | </form></td> | |
2892 | <form method='post' /> | |
2893 | <td><input type='hidden' name='ACTION' value='kill'/> | |
2894 | <input type='hidden' name='number' value='$count' /> | |
2895 | <input type='hidden' name='net' value='$ccdconf[0]' /> | |
b2e75449 | 2896 | <input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'remove'} title=$Lang::tr{'remove'} /></form></td></tr> |
8c877a82 AM |
2897 | END |
2898 | ; | |
2899 | } | |
2900 | print "</table></form>"; | |
2901 | &Header::closebox(); | |
2902 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2903 | &Header::closebigbox(); | |
2904 | &Header::closepage(); | |
2905 | exit(0); | |
2906 | ||
2907 | #END CCD | |
2908 | ||
6e13d0a5 MT |
2909 | ### |
2910 | ### Openvpn Connections Statistics | |
2911 | ### | |
2912 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'ovpn con stat'}) { | |
2913 | &Header::showhttpheaders(); | |
2914 | &Header::openpage($Lang::tr{'ovpn con stat'}, 1, ''); | |
2915 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2916 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ovpn con stat'}); | |
2917 | ||
2918 | # | |
2919 | # <td><b>$Lang::tr{'protocol'}</b></td> | |
2920 | # protocol temp removed | |
4c962356 | 2921 | print <<END; |
99bfa85c | 2922 | <table width='100%' cellpadding='2' cellspacing='0' class='tbl'> |
6e13d0a5 | 2923 | <tr> |
99bfa85c AM |
2924 | <th><b>$Lang::tr{'common name'}</b></th> |
2925 | <th><b>$Lang::tr{'real address'}</b></th> | |
2926 | <th><b>$Lang::tr{'virtual address'}</b></th> | |
2927 | <th><b>$Lang::tr{'loged in at'}</b></th> | |
2928 | <th><b>$Lang::tr{'bytes sent'}</b></th> | |
2929 | <th><b>$Lang::tr{'bytes received'}</b></th> | |
2930 | <th><b>$Lang::tr{'last activity'}</b></th> | |
6e13d0a5 MT |
2931 | </tr> |
2932 | END | |
2933 | ; | |
4e17adad | 2934 | my $filename = "/var/log/ovpnserver.log"; |
6e13d0a5 MT |
2935 | open(FILE, $filename) or die 'Unable to open config file.'; |
2936 | my @current = <FILE>; | |
2937 | close(FILE); | |
2938 | my @users =(); | |
2939 | my $status; | |
2940 | my $uid = 0; | |
2941 | my $cn; | |
2942 | my @match = (); | |
2943 | my $proto = "udp"; | |
2944 | my $address; | |
2945 | my %userlookup = (); | |
2946 | foreach my $line (@current) | |
2947 | { | |
2948 | chomp($line); | |
2949 | if ( $line =~ /^Updated,(.+)/){ | |
2950 | @match = split( /^Updated,(.+)/, $line); | |
2951 | $status = $match[1]; | |
2952 | } | |
c6c9630e | 2953 | #gian |
6e13d0a5 MT |
2954 | if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) { |
2955 | @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line); | |
2956 | if ($match[1] ne "Common Name") { | |
2957 | $cn = $match[1]; | |
2958 | $userlookup{$match[2]} = $uid; | |
2959 | $users[$uid]{'CommonName'} = $match[1]; | |
2960 | $users[$uid]{'RealAddress'} = $match[2]; | |
c6c9630e MT |
2961 | $users[$uid]{'BytesReceived'} = &sizeformat($match[3]); |
2962 | $users[$uid]{'BytesSent'} = &sizeformat($match[4]); | |
6e13d0a5 MT |
2963 | $users[$uid]{'Since'} = $match[5]; |
2964 | $users[$uid]{'Proto'} = $proto; | |
2965 | $uid++; | |
2966 | } | |
2967 | } | |
2968 | if ( $line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/) { | |
2969 | @match = split(m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/, $line); | |
2970 | if ($match[1] ne "Virtual Address") { | |
2971 | $address = $match[3]; | |
2972 | #find the uid in the lookup table | |
2973 | $uid = $userlookup{$address}; | |
2974 | $users[$uid]{'VirtualAddress'} = $match[1]; | |
2975 | $users[$uid]{'LastRef'} = $match[4]; | |
2976 | } | |
2977 | } | |
2978 | } | |
2979 | my $user2 = @users; | |
2980 | if ($user2 >= 1){ | |
99bfa85c | 2981 | for (my $idx = 1; $idx <= $user2; $idx++){ |
6e13d0a5 | 2982 | if ($idx % 2) { |
99bfa85c AM |
2983 | print "<tr>"; |
2984 | $col="bgcolor='$color{'color22'}'"; | |
2985 | } else { | |
2986 | print "<tr>"; | |
2987 | $col="bgcolor='$color{'color20'}'"; | |
6e13d0a5 | 2988 | } |
99bfa85c AM |
2989 | print "<td align='left' $col>$users[$idx-1]{'CommonName'}</td>"; |
2990 | print "<td align='left' $col>$users[$idx-1]{'RealAddress'}</td>"; | |
2991 | print "<td align='left' $col>$users[$idx-1]{'VirtualAddress'}</td>"; | |
2992 | print "<td align='left' $col>$users[$idx-1]{'Since'}</td>"; | |
2993 | print "<td align='left' $col>$users[$idx-1]{'BytesSent'}</td>"; | |
2994 | print "<td align='left' $col>$users[$idx-1]{'BytesReceived'}</td>"; | |
2995 | print "<td align='left' $col>$users[$idx-1]{'LastRef'}</td>"; | |
2996 | } | |
2997 | } | |
6e13d0a5 MT |
2998 | |
2999 | print "</table>"; | |
49abe7af | 3000 | print <<END; |
6e13d0a5 MT |
3001 | <table width='100%' border='0' cellpadding='2' cellspacing='0'> |
3002 | <tr><td></td></tr> | |
3003 | <tr><td></td></tr> | |
3004 | <tr><td></td></tr> | |
3005 | <tr><td></td></tr> | |
3006 | <tr><td align='center' >$Lang::tr{'the statistics were last updated at'} <b>$status</b></td></tr> | |
3007 | </table> | |
3008 | END | |
3009 | ; | |
3010 | &Header::closebox(); | |
3011 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
3012 | &Header::closebigbox(); | |
3013 | &Header::closepage(); | |
3014 | exit(0); | |
3015 | ||
3016 | ### | |
3017 | ### Download Certificate | |
3018 | ### | |
3019 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download certificate'}) { | |
3020 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 3021 | |
6e13d0a5 | 3022 | if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") { |
c6c9630e MT |
3023 | print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . "cert.pem\r\n"; |
3024 | print "Content-Type: application/octet-stream\r\n\r\n"; | |
3025 | print `/bin/cat ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`; | |
3026 | exit (0); | |
3027 | } | |
3028 | ||
3029 | ### | |
3030 | ### Enable/Disable connection | |
3031 | ### | |
ce9abb66 | 3032 | |
c6c9630e MT |
3033 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { |
3034 | ||
3035 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
3036 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3037 | ||
3038 | if ($confighash{$cgiparams{'KEY'}}) { | |
ce9abb66 | 3039 | if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') { |
c6c9630e MT |
3040 | $confighash{$cgiparams{'KEY'}}[0] = 'on'; |
3041 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3042 | #&writeserverconf(); | |
3043 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
3044 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
3045 | # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}); | |
3046 | # } | |
3047 | } else { | |
3048 | $confighash{$cgiparams{'KEY'}}[0] = 'off'; | |
3049 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
3050 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
3051 | # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}); | |
3052 | # } | |
3053 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3054 | #&writeserverconf(); | |
3055 | } | |
3056 | } else { | |
3057 | $errormessage = $Lang::tr{'invalid key'}; | |
6e13d0a5 MT |
3058 | } |
3059 | ||
3060 | ### | |
3061 | ### Restart connection | |
3062 | ### | |
3063 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'restart'}) { | |
3064 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
3065 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3066 | ||
3067 | if ($confighash{$cgiparams{'KEY'}}) { | |
c6c9630e MT |
3068 | # if ($vpnsettings{'ENABLED'} eq 'on' || |
3069 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
3070 | # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}); | |
3071 | # } | |
6e13d0a5 | 3072 | } else { |
c6c9630e | 3073 | $errormessage = $Lang::tr{'invalid key'}; |
6e13d0a5 MT |
3074 | } |
3075 | ||
3076 | ### | |
c6c9630e | 3077 | ### Remove connection |
6e13d0a5 | 3078 | ### |
c6c9630e MT |
3079 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) { |
3080 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
3081 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3082 | ||
3083 | if ($confighash{$cgiparams{'KEY'}}) { | |
3084 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
3085 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
3086 | # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}); | |
3087 | # } | |
3088 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); | |
3089 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
3090 | delete $confighash{$cgiparams{'KEY'}}; | |
3091 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3092 | #&writeserverconf(); | |
3093 | } else { | |
3094 | $errormessage = $Lang::tr{'invalid key'}; | |
3095 | } | |
ce9abb66 AH |
3096 | #test33 |
3097 | ||
3098 | ### | |
3099 | ### Choose between adding a host-net or net-net connection | |
3100 | ### | |
3101 | ||
3102 | ### | |
7c1d9faf | 3103 | # m.a.d net2net |
ce9abb66 AH |
3104 | ### |
3105 | ||
3106 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'add'} && $cgiparams{'TYPE'} eq '') { | |
3107 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
3108 | &Header::showhttpheaders(); | |
4c962356 | 3109 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
ce9abb66 AH |
3110 | &Header::openbigbox('100%', 'LEFT', '', ''); |
3111 | &Header::openbox('100%', 'LEFT', $Lang::tr{'connection type'}); | |
b278daf3 AH |
3112 | |
3113 | if ( -s "${General::swroot}/ovpn/settings") { | |
3114 | ||
49abe7af | 3115 | print <<END; |
ce9abb66 | 3116 | <b>$Lang::tr{'connection type'}:</b><br /> |
8c877a82 | 3117 | <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data"> |
ce9abb66 AH |
3118 | <tr><td><input type='radio' name='TYPE' value='host' checked /></td> |
3119 | <td class='base'>$Lang::tr{'host to net vpn'}</td></tr> | |
3120 | <tr><td><input type='radio' name='TYPE' value='net' /></td> | |
3121 | <td class='base'>$Lang::tr{'net to net vpn'}</td></tr> | |
3122 | <tr><td><input type='radio' name='TYPE' value='net2net' /></td> | |
3123 | <td class='base'>$Lang::tr{'net to net vpn'} (Upload Client Package)</td></tr> | |
3124 | <tr><td> </td><td class='base'><input type='file' name='FH' size='30'></td></tr> | |
54fd0535 | 3125 | <tr><td> </td><td>Import Connection Name <img src='/blob.gif' /></td></tr> |
b2e75449 | 3126 | <tr><td> </td><td class='base'><input type='text' name='n2nname' size='30'>Default : Client Packagename</td></tr> |
54fd0535 | 3127 | <tr><td colspan='3'><hr /></td></tr> |
8c877a82 | 3128 | <tr><td align='right' colspan='3'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr> |
54fd0535 | 3129 | <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang::tr{'this field may be blank'}</td></tr> |
ce9abb66 AH |
3130 | </form></table> |
3131 | END | |
3132 | ; | |
8c877a82 | 3133 | |
ce9abb66 | 3134 | |
b278daf3 | 3135 | } else { |
49abe7af | 3136 | print <<END; |
b278daf3 | 3137 | <b>$Lang::tr{'connection type'}:</b><br /> |
8c877a82 | 3138 | <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data"> |
b278daf3 | 3139 | <tr><td><input type='radio' name='TYPE' value='host' checked /></td> <td class='base'>$Lang::tr{'host to net vpn'}</td></tr> |
8c877a82 | 3140 | <tr><td align='right' colspan'3'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr> |
b278daf3 AH |
3141 | </form></table> |
3142 | END | |
3143 | ; | |
3144 | ||
3145 | } | |
3146 | ||
ce9abb66 | 3147 | &Header::closebox(); |
4c962356 | 3148 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; |
ce9abb66 AH |
3149 | &Header::closebigbox(); |
3150 | &Header::closepage(); | |
3151 | exit (0); | |
3152 | ||
3153 | ### | |
7c1d9faf | 3154 | # m.a.d net2net |
ce9abb66 AH |
3155 | ### |
3156 | ||
3157 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2net')){ | |
3158 | ||
3159 | my @firen2nconf; | |
3160 | my @confdetails; | |
3161 | my $uplconffilename =''; | |
54fd0535 | 3162 | my $uplconffilename2 =''; |
ce9abb66 | 3163 | my $uplp12name = ''; |
54fd0535 | 3164 | my $uplp12name2 = ''; |
ce9abb66 AH |
3165 | my @rem_subnet; |
3166 | my @rem_subnet2; | |
3167 | my @tmposupnet3; | |
3168 | my $key; | |
54fd0535 | 3169 | my @n2nname; |
ce9abb66 AH |
3170 | |
3171 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3172 | ||
3173 | # Check if a file is uploaded | |
3174 | ||
3175 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
3176 | $errormessage = $Lang::tr{'there was no file upload'}; | |
3177 | goto N2N_ERROR; | |
3178 | } | |
3179 | ||
3180 | # Move uploaded IPfire n2n package to temporary file | |
3181 | ||
3182 | (my $fh, my $filename) = tempfile( ); | |
3183 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
3184 | $errormessage = $!; | |
3185 | goto N2N_ERROR; | |
3186 | } | |
3187 | ||
3188 | my $zip = Archive::Zip->new(); | |
3189 | my $zipName = $filename; | |
3190 | my $status = $zip->read( $zipName ); | |
3191 | if ($status != AZ_OK) { | |
3192 | $errormessage = "Read of $zipName failed\n"; | |
3193 | goto N2N_ERROR; | |
3194 | } | |
3195 | ||
3196 | my $tempdir = tempdir( CLEANUP => 1 ); | |
3197 | my @files = $zip->memberNames(); | |
3198 | for(@files) { | |
3199 | $zip->extractMemberWithoutPaths($_,"$tempdir/$_"); | |
3200 | } | |
3201 | my $countfiles = @files; | |
3202 | ||
3203 | # Check if we have not more then 2 files | |
3204 | ||
3205 | if ( $countfiles == 2){ | |
3206 | foreach (@files){ | |
3207 | if ( $_ =~ /.conf$/){ | |
3208 | $uplconffilename = $_; | |
3209 | } | |
3210 | if ( $_ =~ /.p12$/){ | |
3211 | $uplp12name = $_; | |
3212 | } | |
3213 | } | |
3214 | if (($uplconffilename eq '') || ($uplp12name eq '')){ | |
3215 | $errormessage = "Either no *.conf or no *.p12 file found\n"; | |
3216 | goto N2N_ERROR; | |
3217 | } | |
3218 | ||
3219 | open(FILE, "$tempdir/$uplconffilename") or die 'Unable to open*.conf file'; | |
3220 | @firen2nconf = <FILE>; | |
3221 | close (FILE); | |
3222 | chomp(@firen2nconf); | |
3223 | ||
3224 | } else { | |
3225 | ||
3226 | $errormessage = "Filecount does not match only 2 files are allowed\n"; | |
3227 | goto N2N_ERROR; | |
3228 | } | |
3229 | ||
7c1d9faf AH |
3230 | ### |
3231 | # m.a.d net2net | |
ce9abb66 | 3232 | ### |
54fd0535 MT |
3233 | |
3234 | if ($cgiparams{'n2nname'} ne ''){ | |
3235 | ||
3236 | $uplconffilename2 = "$cgiparams{'n2nname'}.conf"; | |
3237 | $uplp12name2 = "$cgiparams{'n2nname'}.p12"; | |
3238 | $n2nname[0] = $cgiparams{'n2nname'}; | |
3239 | my @n2nname2 = split(/\./,$uplconffilename); | |
3240 | $n2nname2[0] =~ s/\n|\r//g; | |
3241 | my $input1 = "${General::swroot}/ovpn/certs/$uplp12name"; | |
3242 | my $output1 = "${General::swroot}/ovpn/certs/$uplp12name2"; | |
3243 | my $input2 = "$n2nname2[0]n2n"; | |
3244 | my $output2 = "$n2nname[0]n2n"; | |
3245 | my $filename = "$tempdir/$uplconffilename"; | |
3246 | open(FILE, "< $filename") or die 'Unable to open config file.'; | |
3247 | my @current = <FILE>; | |
3248 | close(FILE); | |
3249 | foreach (@current) {s/$input1/$output1/g;} | |
3250 | foreach (@current) {s/$input2/$output2/g;} | |
3251 | open (OUT, "> $filename") || die 'Unable to open config file.'; | |
3252 | print OUT @current; | |
3253 | close OUT; | |
ce9abb66 | 3254 | |
54fd0535 MT |
3255 | }else{ |
3256 | $uplconffilename2 = $uplconffilename; | |
3257 | $uplp12name2 = $uplp12name; | |
3258 | @n2nname = split(/\./,$uplconffilename); | |
ce9abb66 | 3259 | $n2nname[0] =~ s/\n|\r//g; |
54fd0535 | 3260 | } |
7c1d9faf AH |
3261 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} |
3262 | unless(-d "${General::swroot}/ovpn/n2nconf/$n2nname[0]"){mkdir "${General::swroot}/ovpn/n2nconf/$n2nname[0]", 0770 or die "Unable to create dir $!";} | |
ce9abb66 | 3263 | |
54fd0535 | 3264 | move("$tempdir/$uplconffilename", "${General::swroot}/ovpn/n2nconf/$n2nname[0]/$uplconffilename2"); |
ce9abb66 AH |
3265 | |
3266 | if ($? ne 0) { | |
3267 | $errormessage = "*.conf move failed: $!"; | |
3268 | unlink ($filename); | |
3269 | goto N2N_ERROR; | |
3270 | } | |
3271 | ||
54fd0535 | 3272 | move("$tempdir/$uplp12name", "${General::swroot}/ovpn/certs/$uplp12name2"); |
b278daf3 AH |
3273 | chmod 0600, "${General::swroot}/ovpn/certs/$uplp12name"; |
3274 | ||
ce9abb66 AH |
3275 | if ($? ne 0) { |
3276 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
3277 | unlink ($filename); | |
3278 | goto N2N_ERROR; | |
3279 | } | |
3280 | ||
3281 | my $complzoactive; | |
d96c89eb | 3282 | my $mssfixactive; |
4c962356 | 3283 | my $authactive; |
d96c89eb | 3284 | my $n2nfragment; |
49abe7af | 3285 | my $authactive; |
4c962356 | 3286 | my @n2nmtudisc = split(/ /, (grep { /^mtu-disc/ } @firen2nconf)[0]); |
60f396d7 | 3287 | my @n2nproto2 = split(/ /, (grep { /^proto/ } @firen2nconf)[0]); |
54fd0535 | 3288 | my @n2nproto = split(/-/, $n2nproto2[1]); |
ce9abb66 AH |
3289 | my @n2nport = split(/ /, (grep { /^port/ } @firen2nconf)[0]); |
3290 | my @n2ntunmtu = split(/ /, (grep { /^tun-mtu/ } @firen2nconf)[0]); | |
3291 | my @n2ncomplzo = grep { /^comp-lzo/ } @firen2nconf; | |
3292 | if ($n2ncomplzo[0] =~ /comp-lzo/){$complzoactive = "on";} else {$complzoactive = "off";} | |
d96c89eb AH |
3293 | my @n2nmssfix = grep { /^mssfix/ } @firen2nconf; |
3294 | if ($n2nmssfix[0] =~ /mssfix/){$mssfixactive = "on";} else {$mssfixactive = "off";} | |
54fd0535 | 3295 | #my @n2nmssfix = split(/ /, (grep { /^mssfix/ } @firen2nconf)[0]); |
d96c89eb | 3296 | my @n2nfragment = split(/ /, (grep { /^fragment/ } @firen2nconf)[0]); |
ce9abb66 AH |
3297 | my @n2nremote = split(/ /, (grep { /^remote/ } @firen2nconf)[0]); |
3298 | my @n2novpnsuball = split(/ /, (grep { /^ifconfig/ } @firen2nconf)[0]); | |
3299 | my @n2novpnsub = split(/\./,$n2novpnsuball[1]); | |
3300 | my @n2nremsub = split(/ /, (grep { /^route/ } @firen2nconf)[0]); | |
54fd0535 | 3301 | my @n2nmgmt = split(/ /, (grep { /^management/ } @firen2nconf)[0]); |
ce9abb66 | 3302 | my @n2nlocalsub = split(/ /, (grep { /^# remsub/ } @firen2nconf)[0]); |
4c962356 EK |
3303 | my @n2ncipher = split(/ /, (grep { /^cipher/ } @firen2nconf)[0]); |
3304 | my @n2nauth = split(/ /, (grep { /^auth/ } @firen2nconf)[0]); | |
49abe7af | 3305 | my @n2nengine = split(/ /, (grep { /^engine/ } @firen2nconf)[0]);; |
60f396d7 | 3306 | |
ce9abb66 AH |
3307 | ### |
3308 | # m.a.d delete CR and LF from arrays for this chomp doesnt work | |
3309 | ### | |
3310 | ||
ce9abb66 | 3311 | $n2nremote[1] =~ s/\n|\r//g; |
ce9abb66 AH |
3312 | $n2novpnsub[0] =~ s/\n|\r//g; |
3313 | $n2novpnsub[1] =~ s/\n|\r//g; | |
3314 | $n2novpnsub[2] =~ s/\n|\r//g; | |
60f396d7 | 3315 | $n2nproto[0] =~ s/\n|\r//g; |
ce9abb66 AH |
3316 | $n2nport[1] =~ s/\n|\r//g; |
3317 | $n2ntunmtu[1] =~ s/\n|\r//g; | |
3318 | $n2nremsub[1] =~ s/\n|\r//g; | |
b278daf3 | 3319 | $n2nremsub[2] =~ s/\n|\r//g; |
ce9abb66 | 3320 | $n2nlocalsub[2] =~ s/\n|\r//g; |
d96c89eb | 3321 | $n2nfragment[1] =~ s/\n|\r//g; |
54fd0535 | 3322 | $n2nmgmt[2] =~ s/\n|\r//g; |
2ee746be | 3323 | $n2nmtudisc[1] =~ s/\n|\r//g; |
4c962356 EK |
3324 | $n2ncipher[1] =~ s/\n|\r//g; |
3325 | $n2nauth[1] =~ s/\n|\r//g; | |
49abe7af | 3326 | $n2nengine[1] =~ s/\n|\r//g; |
ce9abb66 | 3327 | chomp ($complzoactive); |
d96c89eb | 3328 | chomp ($mssfixactive); |
ce9abb66 AH |
3329 | |
3330 | ### | |
7c1d9faf | 3331 | # m.a.d net2net |
ce9abb66 AH |
3332 | ### |
3333 | ||
3334 | ### | |
3335 | # Check if there is no other entry with this name | |
3336 | ### | |
3337 | ||
3338 | foreach my $dkey (keys %confighash) { | |
3339 | if ($confighash{$dkey}[1] eq $n2nname[0]) { | |
3340 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
b278daf3 AH |
3341 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
3342 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3343 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
ce9abb66 AH |
3344 | goto N2N_ERROR; |
3345 | } | |
3346 | } | |
3347 | ||
d96c89eb AH |
3348 | ### |
3349 | # Check if OpenVPN Subnet is valid | |
3350 | ### | |
3351 | ||
3352 | foreach my $dkey (keys %confighash) { | |
3353 | if ($confighash{$dkey}[27] eq "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0") { | |
3354 | $errormessage = 'The OpenVPN Subnet is already in use'; | |
b278daf3 AH |
3355 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
3356 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3357 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3358 | goto N2N_ERROR; |
3359 | } | |
3360 | } | |
3361 | ||
3362 | ### | |
4c962356 | 3363 | # Check if Dest Port is vaild |
d96c89eb AH |
3364 | ### |
3365 | ||
3366 | foreach my $dkey (keys %confighash) { | |
3367 | if ($confighash{$dkey}[29] eq $n2nport[1] ) { | |
3368 | $errormessage = 'The OpenVPN Port is already in use'; | |
b278daf3 AH |
3369 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
3370 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3371 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3372 | goto N2N_ERROR; |
3373 | } | |
3374 | } | |
3375 | ||
3376 | ||
3377 | ||
ce9abb66 AH |
3378 | $key = &General::findhasharraykey (\%confighash); |
3379 | ||
49abe7af | 3380 | foreach my $i (0 .. 42) { $confighash{$key}[$i] = "";} |
350f2980 | 3381 | |
ce9abb66 AH |
3382 | $confighash{$key}[0] = 'off'; |
3383 | $confighash{$key}[1] = $n2nname[0]; | |
350f2980 | 3384 | $confighash{$key}[2] = $n2nname[0]; |
ce9abb66 AH |
3385 | $confighash{$key}[3] = 'net'; |
3386 | $confighash{$key}[4] = 'cert'; | |
3387 | $confighash{$key}[6] = 'client'; | |
3388 | $confighash{$key}[8] = $n2nlocalsub[2]; | |
350f2980 SS |
3389 | $confighash{$key}[10] = $n2nremote[1]; |
3390 | $confighash{$key}[11] = "$n2nremsub[1]/$n2nremsub[2]"; | |
54fd0535 | 3391 | $confighash{$key}[22] = $n2nmgmt[2]; |
350f2980 | 3392 | $confighash{$key}[23] = $mssfixactive; |
d96c89eb | 3393 | $confighash{$key}[24] = $n2nfragment[1]; |
350f2980 | 3394 | $confighash{$key}[25] = 'IPFire n2n Client'; |
ce9abb66 | 3395 | $confighash{$key}[26] = 'red'; |
350f2980 SS |
3396 | $confighash{$key}[27] = "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0"; |
3397 | $confighash{$key}[28] = $n2nproto[0]; | |
3398 | $confighash{$key}[29] = $n2nport[1]; | |
3399 | $confighash{$key}[30] = $complzoactive; | |
3400 | $confighash{$key}[31] = $n2ntunmtu[1]; | |
49abe7af | 3401 | $confighash{$key}[38] = $n2nmtudisc[1]; |
4c962356 EK |
3402 | $confighash{$key}[39] = $n2nauth[1]; |
3403 | $confighash{$key}[40] = $n2ncipher[1]; | |
49abe7af | 3404 | $confighash{$key}[41] = 'disabled'; |
ce9abb66 AH |
3405 | |
3406 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
d96c89eb | 3407 | |
ce9abb66 AH |
3408 | N2N_ERROR: |
3409 | ||
3410 | &Header::showhttpheaders(); | |
3411 | &Header::openpage('Validate imported configuration', 1, ''); | |
3412 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
3413 | if ($errormessage) { | |
3414 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
3415 | print "<class name='base'>$errormessage"; | |
3416 | print " </class>"; | |
3417 | &Header::closebox(); | |
3418 | ||
3419 | } else | |
3420 | { | |
3421 | &Header::openbox('100%', 'LEFT', 'import ipfire net2net config'); | |
3422 | } | |
3423 | if ($errormessage eq ''){ | |
49abe7af | 3424 | print <<END; |
ce9abb66 AH |
3425 | <!-- ipfire net2net config gui --> |
3426 | <table width='100%'> | |
3427 | <tr><td width='25%'> </td><td width='25%'> </td></tr> | |
3428 | <tr><td class='boldbase'>$Lang::tr{'name'}:</td><td><b>$n2nname[0]</b></td></tr> | |
3429 | <tr><td> </td><td> </td></tr> | |
3430 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'Act as'}</td><td><b>$confighash{$key}[6]</b></td></tr> | |
3431 | <tr><td class='boldbase' nowrap='nowrap'>Remote Host </td><td><b>$confighash{$key}[10]</b></td></tr> | |
3432 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'}</td><td><b>$confighash{$key}[8]</b></td></tr> | |
4c962356 | 3433 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'}:</td><td><b>$confighash{$key}[11]</b></td></tr> |
ce9abb66 AH |
3434 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn subnet'}</td><td><b>$confighash{$key}[27]</b></td></tr> |
3435 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td><td><b>$confighash{$key}[28]</b></td></tr> | |
3436 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'destination port'}:</td><td><b>$confighash{$key}[29]</b></td></tr> | |
3437 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td><td><b>$confighash{$key}[30]</b></td></tr> | |
4c962356 EK |
3438 | <tr><td class='boldbase' nowrap='nowrap'>MSSFIX:</td><td><b>$confighash{$key}[23]</b></td></tr> |
3439 | <tr><td class='boldbase' nowrap='nowrap'>Fragment:</td><td><b>$confighash{$key}[24]</b></td></tr> | |
ce9abb66 | 3440 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'}</td><td><b>$confighash{$key}[31]</b></td></tr> |
350f2980 | 3441 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn mtu-disc'}</td><td><b>$confighash{$key}[38]</b></td></tr> |
54fd0535 | 3442 | <tr><td class='boldbase' nowrap='nowrap'>Management Port </td><td><b>$confighash{$key}[22]</b></td></tr> |
4c962356 EK |
3443 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn hmac'}:</td><td><b>$confighash{$key}[39]</b></td></tr> |
3444 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'cipher'}</td><td><b>$confighash{$key}[40]</b></td></tr> | |
ce9abb66 AH |
3445 | <tr><td> </td><td> </td></tr> |
3446 | </table> | |
3447 | END | |
3448 | ; | |
3449 | &Header::closebox(); | |
3450 | } | |
3451 | ||
3452 | if ($errormessage) { | |
3453 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
3454 | } else { | |
3455 | print "<div align='center'><form method='post' ENCTYPE='multipart/form-data'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' />"; | |
3456 | print "<input type='hidden' name='TYPE' value='net2netakn' />"; | |
3457 | print "<input type='hidden' name='KEY' value='$key' />"; | |
3458 | print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>"; | |
3459 | } | |
3460 | &Header::closebigbox(); | |
3461 | &Header::closepage(); | |
4c962356 | 3462 | exit(0); |
ce9abb66 AH |
3463 | |
3464 | ||
3465 | ## | |
3466 | ### Accept IPFire n2n Package Settings | |
3467 | ### | |
3468 | ||
3469 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){ | |
3470 | ||
3471 | ### | |
3472 | ### Discard and Rollback IPFire n2n Package Settings | |
3473 | ### | |
3474 | ||
3475 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'cancel'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){ | |
3476 | ||
3477 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3478 | ||
3479 | if ($confighash{$cgiparams{'KEY'}}) { | |
3480 | ||
3481 | my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf"); | |
3482 | my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
3483 | unlink ($certfile) or die "Removing $certfile fail: $!"; | |
3484 | unlink ($conffile) or die "Removing $conffile fail: $!"; | |
3485 | rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!"; | |
3486 | delete $confighash{$cgiparams{'KEY'}}; | |
3487 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3488 | ||
3489 | } else { | |
3490 | $errormessage = $Lang::tr{'invalid key'}; | |
3491 | } | |
3492 | ||
3493 | ||
3494 | ### | |
7c1d9faf | 3495 | # m.a.d net2net |
ce9abb66 AH |
3496 | ### |
3497 | ||
3498 | ||
3499 | ### | |
3500 | ### Adding a new connection | |
3501 | ### | |
6e13d0a5 MT |
3502 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) || |
3503 | ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) || | |
3504 | ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'ADVANCED'} eq '')) { | |
8c877a82 | 3505 | |
6e13d0a5 MT |
3506 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); |
3507 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
3508 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3509 | ||
3510 | if ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) { | |
8c877a82 AM |
3511 | if (! $confighash{$cgiparams{'KEY'}}[0]) { |
3512 | $errormessage = $Lang::tr{'invalid key'}; | |
3513 | goto VPNCONF_END; | |
3514 | } | |
4c962356 EK |
3515 | $cgiparams{'ENABLED'} = $confighash{$cgiparams{'KEY'}}[0]; |
3516 | $cgiparams{'NAME'} = $confighash{$cgiparams{'KEY'}}[1]; | |
3517 | $cgiparams{'TYPE'} = $confighash{$cgiparams{'KEY'}}[3]; | |
3518 | $cgiparams{'AUTH'} = $confighash{$cgiparams{'KEY'}}[4]; | |
3519 | $cgiparams{'PSK'} = $confighash{$cgiparams{'KEY'}}[5]; | |
3520 | $cgiparams{'SIDE'} = $confighash{$cgiparams{'KEY'}}[6]; | |
3521 | $cgiparams{'LOCAL_SUBNET'} = $confighash{$cgiparams{'KEY'}}[8]; | |
3522 | $cgiparams{'REMOTE'} = $confighash{$cgiparams{'KEY'}}[10]; | |
8c877a82 | 3523 | $cgiparams{'REMOTE_SUBNET'} = $confighash{$cgiparams{'KEY'}}[11]; |
4c962356 EK |
3524 | $cgiparams{'OVPN_MGMT'} = $confighash{$cgiparams{'KEY'}}[22]; |
3525 | $cgiparams{'MSSFIX'} = $confighash{$cgiparams{'KEY'}}[23]; | |
3526 | $cgiparams{'FRAGMENT'} = $confighash{$cgiparams{'KEY'}}[24]; | |
3527 | $cgiparams{'REMARK'} = $confighash{$cgiparams{'KEY'}}[25]; | |
3528 | $cgiparams{'INTERFACE'} = $confighash{$cgiparams{'KEY'}}[26]; | |
3529 | $cgiparams{'OVPN_SUBNET'} = $confighash{$cgiparams{'KEY'}}[27]; | |
3530 | $cgiparams{'PROTOCOL'} = $confighash{$cgiparams{'KEY'}}[28]; | |
3531 | $cgiparams{'DEST_PORT'} = $confighash{$cgiparams{'KEY'}}[29]; | |
3532 | $cgiparams{'COMPLZO'} = $confighash{$cgiparams{'KEY'}}[30]; | |
3533 | $cgiparams{'MTU'} = $confighash{$cgiparams{'KEY'}}[31]; | |
3534 | $cgiparams{'CHECK1'} = $confighash{$cgiparams{'KEY'}}[32]; | |
df9b48b7 | 3535 | $name=$cgiparams{'CHECK1'} ; |
4c962356 EK |
3536 | $cgiparams{$name} = $confighash{$cgiparams{'KEY'}}[33]; |
3537 | $cgiparams{'RG'} = $confighash{$cgiparams{'KEY'}}[34]; | |
3538 | $cgiparams{'CCD_DNS1'} = $confighash{$cgiparams{'KEY'}}[35]; | |
3539 | $cgiparams{'CCD_DNS2'} = $confighash{$cgiparams{'KEY'}}[36]; | |
3540 | $cgiparams{'CCD_WINS'} = $confighash{$cgiparams{'KEY'}}[37]; | |
52d08bcb | 3541 | $cgiparams{'PMTU_DISCOVERY'} = $confighash{$cgiparams{'KEY'}}[38]; |
4c962356 EK |
3542 | $cgiparams{'DAUTH'} = $confighash{$cgiparams{'KEY'}}[39]; |
3543 | $cgiparams{'DCIPHER'} = $confighash{$cgiparams{'KEY'}}[40]; | |
49abe7af EK |
3544 | $cgiparams{'TLSAUTH'} = $confighash{$cgiparams{'KEY'}}[41]; |
3545 | $cgiparams{'ENGINES'} = $confighash{$cgiparams{'KEY'}}[42]; | |
8c877a82 | 3546 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) { |
c6c9630e | 3547 | $cgiparams{'REMARK'} = &Header::cleanhtml($cgiparams{'REMARK'}); |
18837a6a | 3548 | |
8c877a82 | 3549 | #A.Marx CCD check iroute field and convert it to decimal |
52d08bcb | 3550 | if ($cgiparams{'TYPE'} eq 'host') { |
8c877a82 AM |
3551 | my @temp=(); |
3552 | my %ccdroutehash=(); | |
3553 | my $keypoint=0; | |
5068ac38 AM |
3554 | my $ip; |
3555 | my $cidr; | |
8c877a82 AM |
3556 | if ($cgiparams{'IR'} ne ''){ |
3557 | @temp = split("\n",$cgiparams{'IR'}); | |
3558 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3559 | #find key to use | |
3560 | foreach my $key (keys %ccdroutehash) { | |
3561 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}) { | |
3562 | $keypoint=$key; | |
3563 | delete $ccdroutehash{$key}; | |
3564 | }else{ | |
3565 | $keypoint = &General::findhasharraykey (\%ccdroutehash); | |
3566 | } | |
3567 | } | |
3568 | $ccdroutehash{$keypoint}[0]=$cgiparams{'NAME'}; | |
3569 | my $i=1; | |
3570 | my $val=0; | |
3571 | foreach $val (@temp){ | |
3572 | chomp($val); | |
3573 | $val=~s/\s*$//g; | |
5068ac38 | 3574 | #check if iroute exists in ccdroute or if new iroute is part of an existing one |
8c877a82 AM |
3575 | foreach my $key (keys %ccdroutehash) { |
3576 | foreach my $oldiroute ( 1 .. $#{$ccdroutehash{$key}}){ | |
5068ac38 AM |
3577 | if ($ccdroutehash{$key}[$oldiroute] eq "$val") { |
3578 | $errormessage=$errormessage.$Lang::tr{'ccd err irouteexist'}; | |
3579 | goto VPNCONF_ERROR; | |
3580 | } | |
3581 | my ($ip1,$cidr1) = split (/\//, $val); | |
82c809c7 | 3582 | $ip1 = &General::getnetworkip($ip1,&General::iporsubtocidr($cidr1)); |
5068ac38 AM |
3583 | my ($ip2,$cidr2) = split (/\//, $ccdroutehash{$key}[$oldiroute]); |
3584 | if (&General::IpInSubnet ($ip1,$ip2,$cidr2)){ | |
3585 | $errormessage=$errormessage.$Lang::tr{'ccd err irouteexist'}; | |
3586 | goto VPNCONF_ERROR; | |
3587 | } | |
3588 | ||
8c877a82 AM |
3589 | } |
3590 | } | |
5068ac38 AM |
3591 | if (!&General::validipandmask($val)){ |
3592 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($val)"; | |
3593 | goto VPNCONF_ERROR; | |
3594 | }else{ | |
3595 | ($ip,$cidr) = split(/\//,$val); | |
3596 | $ip=&General::getnetworkip($ip,&General::iporsubtocidr($cidr)); | |
3597 | $cidr=&General::iporsubtodec($cidr); | |
3598 | $ccdroutehash{$keypoint}[$i] = $ip."/".$cidr; | |
3599 | ||
3600 | } | |
8c877a82 AM |
3601 | |
3602 | #check for existing network IP's | |
52d08bcb AM |
3603 | if (&General::IpInSubnet ($ip,$netsettings{GREEN_NETADDRESS},$netsettings{GREEN_NETMASK}) && $netsettings{GREEN_NETADDRESS} ne '0.0.0.0') |
3604 | { | |
3605 | $errormessage=$Lang::tr{'ccd err green'}; | |
3606 | goto VPNCONF_ERROR; | |
3607 | }elsif(&General::IpInSubnet ($ip,$netsettings{RED_NETADDRESS},$netsettings{RED_NETMASK}) && $netsettings{RED_NETADDRESS} ne '0.0.0.0') | |
3608 | { | |
3609 | $errormessage=$Lang::tr{'ccd err red'}; | |
3610 | goto VPNCONF_ERROR; | |
3611 | }elsif(&General::IpInSubnet ($ip,$netsettings{BLUE_NETADDRESS},$netsettings{BLUE_NETMASK}) && $netsettings{BLUE_NETADDRESS} ne '0.0.0.0' && $netsettings{BLUE_NETADDRESS} gt '') | |
3612 | { | |
3613 | $errormessage=$Lang::tr{'ccd err blue'}; | |
3614 | goto VPNCONF_ERROR; | |
3615 | }elsif(&General::IpInSubnet ($ip,$netsettings{ORANGE_NETADDRESS},$netsettings{ORANGE_NETMASK}) && $netsettings{ORANGE_NETADDRESS} ne '0.0.0.0' && $netsettings{ORANGE_NETADDRESS} gt '' ) | |
3616 | { | |
3617 | $errormessage=$Lang::tr{'ccd err orange'}; | |
8c877a82 AM |
3618 | goto VPNCONF_ERROR; |
3619 | } | |
52d08bcb | 3620 | |
8c877a82 AM |
3621 | if (&General::validipandmask($val)){ |
3622 | $ccdroutehash{$keypoint}[$i] = $ip."/".$cidr; | |
3623 | }else{ | |
3624 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($ip/$cidr)"; | |
3625 | goto VPNCONF_ERROR; | |
3626 | } | |
3627 | $i++; | |
3628 | } | |
3629 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3630 | &writeserverconf; | |
3631 | }else{ | |
3632 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3633 | foreach my $key (keys %ccdroutehash) { | |
3634 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}) { | |
3635 | delete $ccdroutehash{$key}; | |
3636 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3637 | &writeserverconf; | |
3638 | } | |
3639 | } | |
3640 | } | |
3641 | undef @temp; | |
3642 | #check route field and convert it to decimal | |
8c877a82 AM |
3643 | my $val=0; |
3644 | my $i=1; | |
8c877a82 | 3645 | &General::readhasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); |
52d08bcb AM |
3646 | #find key to use |
3647 | foreach my $key (keys %ccdroute2hash) { | |
3648 | if ($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}) { | |
3649 | $keypoint=$key; | |
3650 | delete $ccdroute2hash{$key}; | |
3651 | }else{ | |
3652 | $keypoint = &General::findhasharraykey (\%ccdroute2hash); | |
3653 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3654 | &writeserverconf; | |
8c877a82 | 3655 | } |
52d08bcb AM |
3656 | } |
3657 | $ccdroute2hash{$keypoint}[0]=$cgiparams{'NAME'}; | |
3658 | if ($cgiparams{'IFROUTE'} eq ''){$cgiparams{'IFROUTE'} = $Lang::tr{'ccd none'};} | |
3659 | @temp = split(/\|/,$cgiparams{'IFROUTE'}); | |
3660 | my %ownnet=(); | |
3661 | &General::readhash("${General::swroot}/ethernet/settings", \%ownnet); | |
3662 | foreach $val (@temp){ | |
3663 | chomp($val); | |
3664 | $val=~s/\s*$//g; | |
3665 | if ($val eq $Lang::tr{'green'}) | |
3666 | { | |
3667 | $val=$ownnet{GREEN_NETADDRESS}."/".$ownnet{GREEN_NETMASK}; | |
3668 | } | |
3669 | if ($val eq $Lang::tr{'blue'}) | |
3670 | { | |
3671 | $val=$ownnet{BLUE_NETADDRESS}."/".$ownnet{BLUE_NETMASK}; | |
3672 | } | |
3673 | if ($val eq $Lang::tr{'orange'}) | |
3674 | { | |
3675 | $val=$ownnet{ORANGE_NETADDRESS}."/".$ownnet{ORANGE_NETMASK}; | |
3676 | } | |
3677 | my ($ip,$cidr) = split (/\//, $val); | |
3678 | ||
3679 | if ($val ne $Lang::tr{'ccd none'}) | |
3680 | { | |
8c877a82 AM |
3681 | if (! &check_routes_push($val)){$errormessage=$errormessage."Route $val ".$Lang::tr{'ccd err routeovpn2'}." ($val)";goto VPNCONF_ERROR;} |
3682 | if (! &check_ccdroute($val)){$errormessage=$errormessage."<br>Route $val ".$Lang::tr{'ccd err inuse'}." ($val)" ;goto VPNCONF_ERROR;} | |
3683 | if (! &check_ccdconf($val)){$errormessage=$errormessage."<br>Route $val ".$Lang::tr{'ccd err routeovpn'}." ($val)";goto VPNCONF_ERROR;} | |
3684 | if (&General::validipandmask($val)){ | |
3685 | $val=$ip."/".&General::iporsubtodec($cidr); | |
3686 | $ccdroute2hash{$keypoint}[$i] = $val; | |
3687 | }else{ | |
3688 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($val)"; | |
3689 | goto VPNCONF_ERROR; | |
3690 | } | |
52d08bcb AM |
3691 | }else{ |
3692 | $ccdroute2hash{$keypoint}[$i]=''; | |
3693 | } | |
3694 | $i++; | |
3695 | } | |
3696 | &General::writehasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
3697 | ||
8c877a82 AM |
3698 | #check dns1 ip |
3699 | if ($cgiparams{'CCD_DNS1'} ne '' && ! &General::validip($cgiparams{'CCD_DNS1'})) { | |
3700 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp dns'}." 1"; | |
3701 | goto VPNCONF_ERROR; | |
3702 | } | |
3703 | #check dns2 ip | |
3704 | if ($cgiparams{'CCD_DNS2'} ne '' && ! &General::validip($cgiparams{'CCD_DNS2'})) { | |
3705 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp dns'}." 2"; | |
3706 | goto VPNCONF_ERROR; | |
3707 | } | |
3708 | #check wins ip | |
3709 | if ($cgiparams{'CCD_WINS'} ne '' && ! &General::validip($cgiparams{'CCD_WINS'})) { | |
3710 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp wins'}; | |
3711 | goto VPNCONF_ERROR; | |
3712 | } | |
52d08bcb | 3713 | } |
8c877a82 AM |
3714 | |
3715 | #CCD End | |
52d08bcb | 3716 | |
8c877a82 AM |
3717 | |
3718 | if ($cgiparams{'TYPE'} !~ /^(host|net)$/) { | |
c6c9630e | 3719 | $errormessage = $Lang::tr{'connection type is invalid'}; |
b278daf3 AH |
3720 | if ($cgiparams{'TYPE'} eq 'net') { |
3721 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3722 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3723 | } | |
c6c9630e MT |
3724 | goto VPNCONF_ERROR; |
3725 | } | |
3726 | ||
3727 | ||
3728 | if ($cgiparams{'NAME'} !~ /^[a-zA-Z0-9]+$/) { | |
3729 | $errormessage = $Lang::tr{'name must only contain characters'}; | |
b278daf3 AH |
3730 | if ($cgiparams{'TYPE'} eq 'net') { |
3731 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3732 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3733 | } | |
3734 | goto VPNCONF_ERROR; | |
3735 | } | |
c6c9630e MT |
3736 | |
3737 | if ($cgiparams{'NAME'} =~ /^(host|01|block|private|clear|packetdefault)$/) { | |
3738 | $errormessage = $Lang::tr{'name is invalid'}; | |
b278daf3 AH |
3739 | if ($cgiparams{'TYPE'} eq 'net') { |
3740 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3741 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3742 | } | |
c6c9630e MT |
3743 | goto VPNCONF_ERROR; |
3744 | } | |
3745 | ||
3746 | if (length($cgiparams{'NAME'}) >60) { | |
3747 | $errormessage = $Lang::tr{'name too long'}; | |
b278daf3 AH |
3748 | if ($cgiparams{'TYPE'} eq 'net') { |
3749 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3750 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3751 | } | |
c6c9630e MT |
3752 | goto VPNCONF_ERROR; |
3753 | } | |
3754 | ||
d96c89eb | 3755 | ### |
7c1d9faf | 3756 | # m.a.d net2net |
d96c89eb AH |
3757 | ### |
3758 | ||
7c1d9faf | 3759 | if ($cgiparams{'TYPE'} eq 'net') { |
ab4cf06c | 3760 | if ($cgiparams{'DEST_PORT'} eq $vpnsettings{'DDEST_PORT'}) { |
cd0c0a0d | 3761 | $errormessage = $Lang::tr{'openvpn destination port used'}; |
b278daf3 AH |
3762 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3763 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3764 | goto VPNCONF_ERROR; | |
d96c89eb | 3765 | } |
ab4cf06c AM |
3766 | #Bugfix 10357 |
3767 | foreach my $key (sort keys %confighash){ | |
3768 | if ( ($confighash{$key}[22] eq $cgiparams{'DEST_PORT'} && $cgiparams{'NAME'} ne $confighash{$key}[1]) || ($confighash{$key}[29] eq $cgiparams{'DEST_PORT'} && $cgiparams{'NAME'} ne $confighash{$key}[1])){ | |
54fd0535 MT |
3769 | $errormessage = $Lang::tr{'openvpn destination port used'}; |
3770 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3771 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
ab4cf06c AM |
3772 | goto VPNCONF_ERROR; |
3773 | } | |
3774 | } | |
3775 | if ($cgiparams{'DEST_PORT'} eq '') { | |
3776 | $errormessage = $Lang::tr{'invalid port'}; | |
3777 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3778 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
54fd0535 MT |
3779 | goto VPNCONF_ERROR; |
3780 | } | |
d96c89eb | 3781 | |
f48074ba SS |
3782 | # Check if the input for the transfer net is valid. |
3783 | if (!&General::validipandmask($cgiparams{'OVPN_SUBNET'})){ | |
3784 | $errormessage = $Lang::tr{'ccd err invalidnet'}; | |
3785 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3786 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3787 | goto VPNCONF_ERROR; | |
3788 | } | |
3789 | ||
d96c89eb | 3790 | if ($cgiparams{'OVPN_SUBNET'} eq $vpnsettings{'DOVPN_SUBNET'}) { |
cd0c0a0d | 3791 | $errormessage = $Lang::tr{'openvpn subnet is used'}; |
b278daf3 AH |
3792 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3793 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3794 | goto VPNCONF_ERROR; |
3795 | } | |
3796 | ||
3797 | if (($cgiparams{'PROTOCOL'} eq 'tcp') && ($cgiparams{'MSSFIX'} eq 'on')) { | |
cd0c0a0d | 3798 | $errormessage = $Lang::tr{'openvpn mssfix allowed with udp'}; |
b278daf3 AH |
3799 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3800 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3801 | goto VPNCONF_ERROR; |
3802 | } | |
3803 | ||
3804 | if (($cgiparams{'PROTOCOL'} eq 'tcp') && ($cgiparams{'FRAGMENT'} ne '')) { | |
cd0c0a0d | 3805 | $errormessage = $Lang::tr{'openvpn fragment allowed with udp'}; |
b278daf3 AH |
3806 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3807 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3808 | goto VPNCONF_ERROR; |
3809 | } | |
d96c89eb | 3810 | |
2ee746be SS |
3811 | if ($cgiparams{'PMTU_DISCOVERY'} ne 'off') { |
3812 | if (($cgiparams{'FRAGMENT'} ne '') || ($cgiparams{'MSSFIX'} eq 'on')) { | |
3813 | $errormessage = $Lang::tr{'ovpn mtu-disc with mssfix or fragment'}; | |
3814 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3815 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3816 | goto VPNCONF_ERROR; | |
3817 | } | |
3818 | } | |
3819 | ||
4cdf8b92 SS |
3820 | if (($cgiparams{'PMTU_DISCOVERY'} ne 'off') && ($cgiparams{'MTU'} ne '1500')) { |
3821 | $errormessage = $Lang::tr{'ovpn mtu-disc and mtu not 1500'}; | |
3822 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3823 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3824 | goto VPNCONF_ERROR; | |
3825 | } | |
3826 | ||
7c1d9faf | 3827 | if ( &validdotmask ($cgiparams{'LOCAL_SUBNET'})) { |
cd0c0a0d | 3828 | $errormessage = $Lang::tr{'openvpn prefix local subnet'}; |
b278daf3 AH |
3829 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3830 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3831 | goto VPNCONF_ERROR; | |
7c1d9faf AH |
3832 | } |
3833 | ||
3834 | if ( &validdotmask ($cgiparams{'OVPN_SUBNET'})) { | |
cd0c0a0d | 3835 | $errormessage = $Lang::tr{'openvpn prefix openvpn subnet'}; |
b278daf3 AH |
3836 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3837 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3838 | goto VPNCONF_ERROR; | |
7c1d9faf AH |
3839 | } |
3840 | ||
3841 | if ( &validdotmask ($cgiparams{'REMOTE_SUBNET'})) { | |
cd0c0a0d | 3842 | $errormessage = $Lang::tr{'openvpn prefix remote subnet'}; |
b278daf3 AH |
3843 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3844 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3845 | goto VPNCONF_ERROR; | |
8c252e6a EK |
3846 | } |
3847 | ||
3848 | if ($cgiparams{'DEST_PORT'} <= 1023) { | |
3849 | $errormessage = $Lang::tr{'ovpn port in root range'}; | |
3850 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3851 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3852 | goto VPNCONF_ERROR; | |
3853 | } | |
54fd0535 | 3854 | |
4c962356 | 3855 | if ($cgiparams{'OVPN_MGMT'} eq '') { |
8c252e6a EK |
3856 | $cgiparams{'OVPN_MGMT'} = $cgiparams{'DEST_PORT'}; |
3857 | } | |
3858 | ||
3859 | if ($cgiparams{'OVPN_MGMT'} <= 1023) { | |
3860 | $errormessage = $Lang::tr{'ovpn mgmt in root range'}; | |
3861 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3862 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3863 | goto VPNCONF_ERROR; | |
b2e75449 MT |
3864 | } |
3865 | #Check if remote subnet is used elsewhere | |
3866 | my ($n2nip,$n2nsub)=split("/",$cgiparams{'REMOTE_SUBNET'}); | |
3867 | $warnmessage=&General::checksubnets('',$n2nip,'ovpn'); | |
3868 | if ($warnmessage){ | |
3869 | $warnmessage=$Lang::tr{'remote subnet'}." ($cgiparams{'REMOTE_SUBNET'}) <br>".$warnmessage; | |
3870 | } | |
7c1d9faf | 3871 | } |
d96c89eb | 3872 | |
ce9abb66 AH |
3873 | # if (($cgiparams{'TYPE'} eq 'net') && ($cgiparams{'SIDE'} !~ /^(left|right)$/)) { |
3874 | # $errormessage = $Lang::tr{'ipfire side is invalid'}; | |
3875 | # goto VPNCONF_ERROR; | |
3876 | # } | |
3877 | ||
c6c9630e MT |
3878 | # Check if there is no other entry with this name |
3879 | if (! $cgiparams{'KEY'}) { | |
3880 | foreach my $key (keys %confighash) { | |
3881 | if ($confighash{$key}[1] eq $cgiparams{'NAME'}) { | |
3882 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
b278daf3 AH |
3883 | if ($cgiparams{'TYPE'} eq 'net') { |
3884 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3885 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3886 | } | |
c6c9630e | 3887 | goto VPNCONF_ERROR; |
6e13d0a5 | 3888 | } |
c6c9630e MT |
3889 | } |
3890 | } | |
3891 | ||
c125d8a2 | 3892 | # Check if a remote host/IP has been set for the client. |
86228a56 MT |
3893 | if ($cgiparams{'TYPE'} eq 'net') { |
3894 | if ($cgiparams{'SIDE'} ne 'server' && $cgiparams{'REMOTE'} eq '') { | |
3895 | $errormessage = $Lang::tr{'invalid input for remote host/ip'}; | |
c125d8a2 | 3896 | |
86228a56 MT |
3897 | # Check if this is a N2N connection and drop temporary config. |
3898 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3899 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
ce9abb66 | 3900 | |
86228a56 MT |
3901 | goto VPNCONF_ERROR; |
3902 | } | |
c125d8a2 | 3903 | |
86228a56 MT |
3904 | # Check if a remote host/IP has been configured - the field can be empty on the server side. |
3905 | if ($cgiparams{'REMOTE'} ne '') { | |
3906 | # Check if the given IP is valid - otherwise check if it is a valid domain. | |
3907 | if (! &General::validip($cgiparams{'REMOTE'})) { | |
3908 | # Check for a valid domain. | |
3909 | if (! &General::validfqdn ($cgiparams{'REMOTE'})) { | |
3910 | $errormessage = $Lang::tr{'invalid input for remote host/ip'}; | |
c125d8a2 | 3911 | |
86228a56 MT |
3912 | # Check if this is a N2N connection and drop temporary config. |
3913 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3914 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
c125d8a2 | 3915 | |
86228a56 MT |
3916 | goto VPNCONF_ERROR; |
3917 | } | |
3918 | } | |
6e13d0a5 | 3919 | } |
c6c9630e | 3920 | } |
c125d8a2 | 3921 | |
c6c9630e MT |
3922 | if ($cgiparams{'TYPE'} ne 'host') { |
3923 | unless (&General::validipandmask($cgiparams{'LOCAL_SUBNET'})) { | |
3924 | $errormessage = $Lang::tr{'local subnet is invalid'}; | |
b278daf3 AH |
3925 | if ($cgiparams{'TYPE'} eq 'net') { |
3926 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3927 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3928 | } | |
c6c9630e MT |
3929 | goto VPNCONF_ERROR;} |
3930 | } | |
3931 | # Check if there is no other entry without IP-address and PSK | |
3932 | if ($cgiparams{'REMOTE'} eq '') { | |
3933 | foreach my $key (keys %confighash) { | |
3934 | if(($cgiparams{'KEY'} ne $key) && | |
3935 | ($confighash{$key}[4] eq 'psk' || $cgiparams{'AUTH'} eq 'psk') && | |
3936 | $confighash{$key}[10] eq '') { | |
3937 | $errormessage = $Lang::tr{'you can only define one roadwarrior connection when using pre-shared key authentication'}; | |
3938 | goto VPNCONF_ERROR; | |
6e13d0a5 | 3939 | } |
c6c9630e MT |
3940 | } |
3941 | } | |
ce9abb66 AH |
3942 | if (($cgiparams{'TYPE'} eq 'net') && (! &General::validipandmask($cgiparams{'REMOTE_SUBNET'}))) { |
3943 | $errormessage = $Lang::tr{'remote subnet is invalid'}; | |
b278daf3 AH |
3944 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3945 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3946 | goto VPNCONF_ERROR; | |
ce9abb66 | 3947 | } |
c6c9630e MT |
3948 | |
3949 | if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) { | |
3950 | $errormessage = $Lang::tr{'invalid input'}; | |
3951 | goto VPNCONF_ERROR; | |
3952 | } | |
3953 | if ($cgiparams{'EDIT_ADVANCED'} !~ /^(on|off)$/) { | |
3954 | $errormessage = $Lang::tr{'invalid input'}; | |
3955 | goto VPNCONF_ERROR; | |
3956 | } | |
3957 | ||
3958 | #fixplausi | |
3959 | if ($cgiparams{'AUTH'} eq 'psk') { | |
3960 | # if (! length($cgiparams{'PSK'}) ) { | |
3961 | # $errormessage = $Lang::tr{'pre-shared key is too short'}; | |
3962 | # goto VPNCONF_ERROR; | |
3963 | # } | |
3964 | # if ($cgiparams{'PSK'} =~ /['",&]/) { | |
3965 | # $errormessage = $Lang::tr{'invalid characters found in pre-shared key'}; | |
3966 | # goto VPNCONF_ERROR; | |
3967 | # } | |
3968 | } elsif ($cgiparams{'AUTH'} eq 'certreq') { | |
3969 | if ($cgiparams{'KEY'}) { | |
3970 | $errormessage = $Lang::tr{'cant change certificates'}; | |
3971 | goto VPNCONF_ERROR; | |
3972 | } | |
3973 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
3974 | $errormessage = $Lang::tr{'there was no file upload'}; | |
3975 | goto VPNCONF_ERROR; | |
3976 | } | |
3977 | ||
3978 | # Move uploaded certificate request to a temporary file | |
3979 | (my $fh, my $filename) = tempfile( ); | |
3980 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
3981 | $errormessage = $!; | |
3982 | goto VPNCONF_ERROR; | |
3983 | } | |
6e13d0a5 | 3984 | |
c6c9630e MT |
3985 | # Sign the certificate request and move it |
3986 | # Sign the host certificate request | |
f6e12093 | 3987 | system('/usr/bin/openssl', 'ca', '-days', "$cgiparams{'DAYS_VALID'}", |
c6c9630e MT |
3988 | '-batch', '-notext', |
3989 | '-in', $filename, | |
3990 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
3991 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
3992 | if ($?) { | |
3993 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
3994 | unlink ($filename); | |
3995 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
3996 | &newcleanssldatabase(); | |
3997 | goto VPNCONF_ERROR; | |
3998 | } else { | |
3999 | unlink ($filename); | |
4000 | &deletebackupcert(); | |
4001 | } | |
4002 | ||
4003 | my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem`; | |
4004 | $temp =~ /Subject:.*CN=(.*)[\n]/; | |
4005 | $temp = $1; | |
4006 | $temp =~ s+/Email+, E+; | |
4007 | $temp =~ s/ ST=/ S=/; | |
4008 | $cgiparams{'CERT_NAME'} = $temp; | |
4009 | $cgiparams{'CERT_NAME'} =~ s/,//g; | |
4010 | $cgiparams{'CERT_NAME'} =~ s/\'//g; | |
4011 | if ($cgiparams{'CERT_NAME'} eq '') { | |
4012 | $errormessage = $Lang::tr{'could not retrieve common name from certificate'}; | |
4013 | goto VPNCONF_ERROR; | |
4014 | } | |
4015 | } elsif ($cgiparams{'AUTH'} eq 'certfile') { | |
4016 | if ($cgiparams{'KEY'}) { | |
4017 | $errormessage = $Lang::tr{'cant change certificates'}; | |
4018 | goto VPNCONF_ERROR; | |
4019 | } | |
4020 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
4021 | $errormessage = $Lang::tr{'there was no file upload'}; | |
4022 | goto VPNCONF_ERROR; | |
4023 | } | |
4024 | # Move uploaded certificate to a temporary file | |
4025 | (my $fh, my $filename) = tempfile( ); | |
4026 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
4027 | $errormessage = $!; | |
4028 | goto VPNCONF_ERROR; | |
4029 | } | |
4030 | ||
4031 | # Verify the certificate has a valid CA and move it | |
4032 | my $validca = 0; | |
4033 | my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/cacert.pem $filename`; | |
4034 | if ($test =~ /: OK/) { | |
4035 | $validca = 1; | |
4036 | } else { | |
4037 | foreach my $key (keys %cahash) { | |
4038 | $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/$cahash{$key}[0]cert.pem $filename`; | |
4039 | if ($test =~ /: OK/) { | |
4040 | $validca = 1; | |
4041 | } | |
6e13d0a5 | 4042 | } |
c6c9630e MT |
4043 | } |
4044 | if (! $validca) { | |
4045 | $errormessage = $Lang::tr{'certificate does not have a valid ca associated with it'}; | |
4046 | unlink ($filename); | |
4047 | goto VPNCONF_ERROR; | |
4048 | } else { | |
4049 | move($filename, "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4050 | if ($? ne 0) { | |
4051 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
4052 | unlink ($filename); | |
4053 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4054 | } |
c6c9630e MT |
4055 | } |
4056 | ||
4057 | my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem`; | |
4058 | $temp =~ /Subject:.*CN=(.*)[\n]/; | |
4059 | $temp = $1; | |
4060 | $temp =~ s+/Email+, E+; | |
4061 | $temp =~ s/ ST=/ S=/; | |
4062 | $cgiparams{'CERT_NAME'} = $temp; | |
4063 | $cgiparams{'CERT_NAME'} =~ s/,//g; | |
4064 | $cgiparams{'CERT_NAME'} =~ s/\'//g; | |
4065 | if ($cgiparams{'CERT_NAME'} eq '') { | |
4066 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4067 | $errormessage = $Lang::tr{'could not retrieve common name from certificate'}; | |
4068 | goto VPNCONF_ERROR; | |
4069 | } | |
4070 | } elsif ($cgiparams{'AUTH'} eq 'certgen') { | |
4071 | if ($cgiparams{'KEY'}) { | |
4072 | $errormessage = $Lang::tr{'cant change certificates'}; | |
4073 | goto VPNCONF_ERROR; | |
4074 | } | |
4075 | # Validate input since the form was submitted | |
4076 | if (length($cgiparams{'CERT_NAME'}) >60) { | |
4077 | $errormessage = $Lang::tr{'name too long'}; | |
4078 | goto VPNCONF_ERROR; | |
4079 | } | |
4080 | if ($cgiparams{'CERT_NAME'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) { | |
4081 | $errormessage = $Lang::tr{'invalid input for name'}; | |
4c962356 EK |
4082 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
4083 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
c6c9630e MT |
4084 | goto VPNCONF_ERROR; |
4085 | } | |
4086 | if ($cgiparams{'CERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'CERT_EMAIL'}))) { | |
4087 | $errormessage = $Lang::tr{'invalid input for e-mail address'}; | |
4088 | goto VPNCONF_ERROR; | |
4089 | } | |
4090 | if (length($cgiparams{'CERT_EMAIL'}) > 40) { | |
4091 | $errormessage = $Lang::tr{'e-mail address too long'}; | |
4092 | goto VPNCONF_ERROR; | |
4093 | } | |
4094 | if ($cgiparams{'CERT_OU'} ne '' && $cgiparams{'CERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
4095 | $errormessage = $Lang::tr{'invalid input for department'}; | |
4096 | goto VPNCONF_ERROR; | |
4097 | } | |
4098 | if (length($cgiparams{'CERT_ORGANIZATION'}) >60) { | |
4099 | $errormessage = $Lang::tr{'organization too long'}; | |
4100 | goto VPNCONF_ERROR; | |
4101 | } | |
4102 | if ($cgiparams{'CERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) { | |
4103 | $errormessage = $Lang::tr{'invalid input for organization'}; | |
4104 | goto VPNCONF_ERROR; | |
4105 | } | |
4106 | if ($cgiparams{'CERT_CITY'} ne '' && $cgiparams{'CERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
4107 | $errormessage = $Lang::tr{'invalid input for city'}; | |
4108 | goto VPNCONF_ERROR; | |
4109 | } | |
4110 | if ($cgiparams{'CERT_STATE'} ne '' && $cgiparams{'CERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
4111 | $errormessage = $Lang::tr{'invalid input for state or province'}; | |
4112 | goto VPNCONF_ERROR; | |
4113 | } | |
4114 | if ($cgiparams{'CERT_COUNTRY'} !~ /^[A-Z]*$/) { | |
4115 | $errormessage = $Lang::tr{'invalid input for country'}; | |
4116 | goto VPNCONF_ERROR; | |
4117 | } | |
4118 | if ($cgiparams{'CERT_PASS1'} ne '' && $cgiparams{'CERT_PASS2'} ne ''){ | |
4119 | if (length($cgiparams{'CERT_PASS1'}) < 5) { | |
4120 | $errormessage = $Lang::tr{'password too short'}; | |
4121 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4122 | } |
c6c9630e MT |
4123 | } |
4124 | if ($cgiparams{'CERT_PASS1'} ne $cgiparams{'CERT_PASS2'}) { | |
4125 | $errormessage = $Lang::tr{'passwords do not match'}; | |
4126 | goto VPNCONF_ERROR; | |
4127 | } | |
4128 | ||
4129 | # Replace empty strings with a . | |
4130 | (my $ou = $cgiparams{'CERT_OU'}) =~ s/^\s*$/\./; | |
4131 | (my $city = $cgiparams{'CERT_CITY'}) =~ s/^\s*$/\./; | |
4132 | (my $state = $cgiparams{'CERT_STATE'}) =~ s/^\s*$/\./; | |
4133 | ||
4134 | # Create the Host certificate request client | |
4135 | my $pid = open(OPENSSL, "|-"); | |
4136 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto VPNCONF_ERROR;}; | |
4137 | if ($pid) { # parent | |
4138 | print OPENSSL "$cgiparams{'CERT_COUNTRY'}\n"; | |
4139 | print OPENSSL "$state\n"; | |
4140 | print OPENSSL "$city\n"; | |
4141 | print OPENSSL "$cgiparams{'CERT_ORGANIZATION'}\n"; | |
4142 | print OPENSSL "$ou\n"; | |
4143 | print OPENSSL "$cgiparams{'CERT_NAME'}\n"; | |
4144 | print OPENSSL "$cgiparams{'CERT_EMAIL'}\n"; | |
4145 | print OPENSSL ".\n"; | |
4146 | print OPENSSL ".\n"; | |
4147 | close (OPENSSL); | |
4148 | if ($?) { | |
4149 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4150 | unlink ("${General::swroot}ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4151 | unlink ("${General::swroot}ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4152 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4153 | } |
c6c9630e MT |
4154 | } else { # child |
4155 | unless (exec ('/usr/bin/openssl', 'req', '-nodes', '-rand', '/proc/interrupts:/proc/net/rt_cache', | |
4c962356 | 4156 | '-newkey', 'rsa:2048', |
c6c9630e MT |
4157 | '-keyout', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem", |
4158 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem", | |
4159 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) { | |
4160 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
4161 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4162 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4163 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4164 | } |
c6c9630e MT |
4165 | } |
4166 | ||
4167 | # Sign the host certificate request | |
f6e12093 | 4168 | system('/usr/bin/openssl', 'ca', '-days', "$cgiparams{'DAYS_VALID'}", |
c6c9630e MT |
4169 | '-batch', '-notext', |
4170 | '-in', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem", | |
4171 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
4172 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
4173 | if ($?) { | |
4174 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4175 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4176 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4177 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4178 | &newcleanssldatabase(); | |
4179 | goto VPNCONF_ERROR; | |
4180 | } else { | |
4181 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4182 | &deletebackupcert(); | |
4183 | } | |
4184 | ||
4185 | # Create the pkcs12 file | |
4186 | system('/usr/bin/openssl', 'pkcs12', '-export', | |
4187 | '-inkey', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem", | |
4188 | '-in', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
4189 | '-name', $cgiparams{'NAME'}, | |
4190 | '-passout', "pass:$cgiparams{'CERT_PASS1'}", | |
4191 | '-certfile', "${General::swroot}/ovpn/ca/cacert.pem", | |
4192 | '-caname', "$vpnsettings{'ROOTCERT_ORGANIZATION'} CA", | |
4193 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12"); | |
4194 | if ($?) { | |
4195 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4196 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4197 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4198 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12"); | |
4199 | goto VPNCONF_ERROR; | |
4200 | } else { | |
4201 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4202 | } | |
4203 | } elsif ($cgiparams{'AUTH'} eq 'cert') { | |
4204 | ;# Nothing, just editing | |
4205 | } else { | |
4206 | $errormessage = $Lang::tr{'invalid input for authentication method'}; | |
4207 | goto VPNCONF_ERROR; | |
4208 | } | |
4209 | ||
4210 | # Check if there is no other entry with this common name | |
4211 | if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk')) { | |
4212 | foreach my $key (keys %confighash) { | |
4213 | if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) { | |
4214 | $errormessage = $Lang::tr{'a connection with this common name already exists'}; | |
4215 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4216 | } |
c6c9630e MT |
4217 | } |
4218 | } | |
4219 | ||
ab4cf06c | 4220 | # Save the config |
c6c9630e | 4221 | my $key = $cgiparams{'KEY'}; |
8c877a82 | 4222 | |
c6c9630e MT |
4223 | if (! $key) { |
4224 | $key = &General::findhasharraykey (\%confighash); | |
49abe7af | 4225 | foreach my $i (0 .. 43) { $confighash{$key}[$i] = "";} |
c6c9630e | 4226 | } |
8c877a82 AM |
4227 | $confighash{$key}[0] = $cgiparams{'ENABLED'}; |
4228 | $confighash{$key}[1] = $cgiparams{'NAME'}; | |
c6c9630e | 4229 | if ((! $cgiparams{'KEY'}) && $cgiparams{'AUTH'} ne 'psk') { |
8c877a82 | 4230 | $confighash{$key}[2] = $cgiparams{'CERT_NAME'}; |
c6c9630e | 4231 | } |
8c877a82 AM |
4232 | |
4233 | $confighash{$key}[3] = $cgiparams{'TYPE'}; | |
c6c9630e | 4234 | if ($cgiparams{'AUTH'} eq 'psk') { |
8c877a82 AM |
4235 | $confighash{$key}[4] = 'psk'; |
4236 | $confighash{$key}[5] = $cgiparams{'PSK'}; | |
c6c9630e | 4237 | } else { |
8c877a82 | 4238 | $confighash{$key}[4] = 'cert'; |
c6c9630e | 4239 | } |
ce9abb66 | 4240 | if ($cgiparams{'TYPE'} eq 'net') { |
8c877a82 AM |
4241 | $confighash{$key}[6] = $cgiparams{'SIDE'}; |
4242 | $confighash{$key}[11] = $cgiparams{'REMOTE_SUBNET'}; | |
ce9abb66 | 4243 | } |
4c962356 | 4244 | $confighash{$key}[8] = $cgiparams{'LOCAL_SUBNET'}; |
8c877a82 | 4245 | $confighash{$key}[10] = $cgiparams{'REMOTE'}; |
4c962356 | 4246 | if ($cgiparams{'OVPN_MGMT'} eq '') { |
8c877a82 | 4247 | $confighash{$key}[22] = $confighash{$key}[29]; |
4c962356 | 4248 | } else { |
8c877a82 | 4249 | $confighash{$key}[22] = $cgiparams{'OVPN_MGMT'}; |
4c962356 | 4250 | } |
8c877a82 AM |
4251 | $confighash{$key}[23] = $cgiparams{'MSSFIX'}; |
4252 | $confighash{$key}[24] = $cgiparams{'FRAGMENT'}; | |
4253 | $confighash{$key}[25] = $cgiparams{'REMARK'}; | |
4254 | $confighash{$key}[26] = $cgiparams{'INTERFACE'}; | |
c6c9630e | 4255 | # new fields |
8c877a82 AM |
4256 | $confighash{$key}[27] = $cgiparams{'OVPN_SUBNET'}; |
4257 | $confighash{$key}[28] = $cgiparams{'PROTOCOL'}; | |
4258 | $confighash{$key}[29] = $cgiparams{'DEST_PORT'}; | |
4259 | $confighash{$key}[30] = $cgiparams{'COMPLZO'}; | |
4260 | $confighash{$key}[31] = $cgiparams{'MTU'}; | |
4261 | $confighash{$key}[32] = $cgiparams{'CHECK1'}; | |
df9b48b7 | 4262 | $name=$cgiparams{'CHECK1'}; |
8c877a82 AM |
4263 | $confighash{$key}[33] = $cgiparams{$name}; |
4264 | $confighash{$key}[34] = $cgiparams{'RG'}; | |
4265 | $confighash{$key}[35] = $cgiparams{'CCD_DNS1'}; | |
4266 | $confighash{$key}[36] = $cgiparams{'CCD_DNS2'}; | |
4267 | $confighash{$key}[37] = $cgiparams{'CCD_WINS'}; | |
4c962356 EK |
4268 | $confighash{$key}[38] = $cgiparams{'PMTU_DISCOVERY'}; |
4269 | $confighash{$key}[39] = $cgiparams{'DAUTH'}; | |
4270 | $confighash{$key}[40] = $cgiparams{'DCIPHER'}; | |
49abe7af | 4271 | $confighash{$key}[42] = $cgiparams{'ENGINES'}; |
350f2980 | 4272 | |
c6c9630e | 4273 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
8c877a82 AM |
4274 | |
4275 | if ($cgiparams{'CHECK1'} ){ | |
4276 | ||
4277 | my ($ccdip,$ccdsub)=split "/",$cgiparams{$name}; | |
4278 | my ($a,$b,$c,$d) = split (/\./,$ccdip); | |
df9b48b7 AM |
4279 | if ( -e "${General::swroot}/ovpn/ccd/$confighash{$key}[2]"){ |
4280 | unlink "${General::swroot}/ovpn/ccd/$cgiparams{'CERT_NAME'}"; | |
4281 | } | |
8c877a82 | 4282 | open ( CCDRWCONF,'>',"${General::swroot}/ovpn/ccd/$confighash{$key}[2]") or die "Unable to create clientconfigfile $!"; |
82c809c7 | 4283 | print CCDRWCONF "# OpenVPN clientconfig from ccd extension by Copymaster#\n\n"; |
8c877a82 AM |
4284 | if($cgiparams{'CHECK1'} eq 'dynamic'){ |
4285 | print CCDRWCONF "#This client uses the dynamic pool\n"; | |
4286 | }else{ | |
82c809c7 | 4287 | print CCDRWCONF "#Ip address client and server\n"; |
8c877a82 AM |
4288 | print CCDRWCONF "ifconfig-push $ccdip ".&General::getlastip($ccdip,1)."\n"; |
4289 | } | |
4290 | if ($confighash{$key}[34] eq 'on'){ | |
4291 | print CCDRWCONF "\n#Redirect Gateway: \n#All IP traffic is redirected through the vpn \n"; | |
4292 | print CCDRWCONF "push redirect-gateway\n"; | |
4293 | } | |
52d08bcb | 4294 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); |
8c877a82 | 4295 | if ($cgiparams{'IR'} ne ''){ |
82c809c7 | 4296 | print CCDRWCONF "\n#Client routes these networks (behind Client)\n"; |
8c877a82 AM |
4297 | foreach my $key (keys %ccdroutehash){ |
4298 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}){ | |
4299 | foreach my $i ( 1 .. $#{$ccdroutehash{$key}}){ | |
4300 | my ($a,$b)=split (/\//,$ccdroutehash{$key}[$i]); | |
4301 | print CCDRWCONF "iroute $a $b\n"; | |
4302 | } | |
4303 | } | |
4304 | } | |
4305 | } | |
52d08bcb | 4306 | if ($cgiparams{'IFROUTE'} eq $Lang::tr{'ccd none'} ){$cgiparams{'IFROUTE'}='';} |
8c877a82 | 4307 | if ($cgiparams{'IFROUTE'} ne ''){ |
82c809c7 | 4308 | print CCDRWCONF "\n#Client gets routes to these networks (behind IPFire)\n"; |
8c877a82 AM |
4309 | foreach my $key (keys %ccdroute2hash){ |
4310 | if ($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4311 | foreach my $i ( 1 .. $#{$ccdroute2hash{$key}}){ | |
4312 | if($ccdroute2hash{$key}[$i] eq $Lang::tr{'blue'}){ | |
4313 | my %blue=(); | |
4314 | &General::readhash("${General::swroot}/ethernet/settings", \%blue); | |
52d08bcb | 4315 | print CCDRWCONF "push \"route $blue{BLUE_ADDRESS} $blue{BLUE_NETMASK}\n"; |
8c877a82 AM |
4316 | }elsif($ccdroute2hash{$key}[$i] eq $Lang::tr{'orange'}){ |
4317 | my %orange=(); | |
4318 | &General::readhash("${General::swroot}/ethernet/settings", \%orange); | |
4319 | print CCDRWCONF "push \"route $orange{ORANGE_ADDRESS} $orange{ORANGE_NETMASK}\n"; | |
4320 | }else{ | |
4321 | my ($a,$b)=split (/\//,$ccdroute2hash{$key}[$i]); | |
4322 | print CCDRWCONF "push \"route $a $b\"\n"; | |
4323 | } | |
4324 | } | |
4325 | } | |
4326 | } | |
4327 | } | |
4328 | if(($cgiparams{'CCD_DNS1'} eq '') && ($cgiparams{'CCD_DNS1'} ne '')){ $cgiparams{'CCD_DNS1'} = $cgiparams{'CCD_DNS2'};$cgiparams{'CCD_DNS2'}='';} | |
4329 | if($cgiparams{'CCD_DNS1'} ne ''){ | |
82c809c7 | 4330 | print CCDRWCONF "\n#Client gets these nameservers\n"; |
8c877a82 AM |
4331 | print CCDRWCONF "push \"dhcp-option DNS $cgiparams{'CCD_DNS1'}\" \n"; |
4332 | } | |
4333 | if($cgiparams{'CCD_DNS2'} ne ''){ | |
4334 | print CCDRWCONF "push \"dhcp-option DNS $cgiparams{'CCD_DNS2'}\" \n"; | |
4335 | } | |
4336 | if($cgiparams{'CCD_WINS'} ne ''){ | |
4337 | print CCDRWCONF "\n#Client gets this WINS server\n"; | |
4338 | print CCDRWCONF "push \"dhcp-option WINS $cgiparams{'CCD_WINS'}\" \n"; | |
4339 | } | |
4340 | close CCDRWCONF; | |
4341 | } | |
18837a6a AH |
4342 | |
4343 | ### | |
4344 | # m.a.d n2n begin | |
4345 | ### | |
4346 | ||
4347 | if ($cgiparams{'TYPE'} eq 'net') { | |
4348 | ||
4349 | if (-e "/var/run/$confighash{$key}[1]n2n.pid") { | |
4350 | system('/usr/local/bin/openvpnctrl', '-kn2n', $confighash{$cgiparams{'KEY'}}[1]); | |
4351 | ||
4352 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
4353 | my $key = $cgiparams{'KEY'}; | |
4354 | if (! $key) { | |
4355 | $key = &General::findhasharraykey (\%confighash); | |
4356 | foreach my $i (0 .. 31) { $confighash{$key}[$i] = "";} | |
4357 | } | |
4358 | $confighash{$key}[0] = 'on'; | |
4359 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
4360 | ||
4361 | system('/usr/local/bin/openvpnctrl', '-sn2n', $confighash{$cgiparams{'KEY'}}[1]); | |
4362 | } | |
4363 | } | |
4364 | ||
4365 | ### | |
4366 | # m.a.d n2n end | |
4367 | ### | |
4368 | ||
c6c9630e MT |
4369 | if ($cgiparams{'EDIT_ADVANCED'} eq 'on') { |
4370 | $cgiparams{'KEY'} = $key; | |
4371 | $cgiparams{'ACTION'} = $Lang::tr{'advanced'}; | |
4372 | } | |
4373 | goto VPNCONF_END; | |
6e13d0a5 | 4374 | } else { |
c6c9630e | 4375 | $cgiparams{'ENABLED'} = 'on'; |
54fd0535 MT |
4376 | ### |
4377 | # m.a.d n2n begin | |
4378 | ### | |
4379 | $cgiparams{'MSSFIX'} = 'on'; | |
4380 | $cgiparams{'FRAGMENT'} = '1300'; | |
b228aaf0 | 4381 | $cgiparams{'PMTU_DISCOVERY'} = 'off'; |
49abe7af EK |
4382 | $cgiparams{'DAUTH'} = 'SHA1'; |
4383 | $cgiparams{'ENGINES'} = 'disabled'; | |
54fd0535 MT |
4384 | ### |
4385 | # m.a.d n2n end | |
4386 | ### | |
4c962356 | 4387 | $cgiparams{'SIDE'} = 'left'; |
c6c9630e MT |
4388 | if ( ! -f "${General::swroot}/ovpn/ca/cakey.pem" ) { |
4389 | $cgiparams{'AUTH'} = 'psk'; | |
4390 | } elsif ( ! -f "${General::swroot}/ovpn/ca/cacert.pem") { | |
4391 | $cgiparams{'AUTH'} = 'certfile'; | |
4392 | } else { | |
6e13d0a5 | 4393 | $cgiparams{'AUTH'} = 'certgen'; |
c6c9630e MT |
4394 | } |
4395 | $cgiparams{'LOCAL_SUBNET'} ="$netsettings{'GREEN_NETADDRESS'}/$netsettings{'GREEN_NETMASK'}"; | |
4396 | $cgiparams{'CERT_ORGANIZATION'} = $vpnsettings{'ROOTCERT_ORGANIZATION'}; | |
4397 | $cgiparams{'CERT_CITY'} = $vpnsettings{'ROOTCERT_CITY'}; | |
4398 | $cgiparams{'CERT_STATE'} = $vpnsettings{'ROOTCERT_STATE'}; | |
4399 | $cgiparams{'CERT_COUNTRY'} = $vpnsettings{'ROOTCERT_COUNTRY'}; | |
6e13d0a5 | 4400 | } |
c6c9630e | 4401 | |
6e13d0a5 | 4402 | VPNCONF_ERROR: |
6e13d0a5 MT |
4403 | $checked{'ENABLED'}{'off'} = ''; |
4404 | $checked{'ENABLED'}{'on'} = ''; | |
4405 | $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = 'CHECKED'; | |
4406 | $checked{'ENABLED_BLUE'}{'off'} = ''; | |
4407 | $checked{'ENABLED_BLUE'}{'on'} = ''; | |
4408 | $checked{'ENABLED_BLUE'}{$cgiparams{'ENABLED_BLUE'}} = 'CHECKED'; | |
4409 | $checked{'ENABLED_ORANGE'}{'off'} = ''; | |
4410 | $checked{'ENABLED_ORANGE'}{'on'} = ''; | |
4411 | $checked{'ENABLED_ORANGE'}{$cgiparams{'ENABLED_ORANGE'}} = 'CHECKED'; | |
c6c9630e MT |
4412 | |
4413 | ||
6e13d0a5 MT |
4414 | $checked{'EDIT_ADVANCED'}{'off'} = ''; |
4415 | $checked{'EDIT_ADVANCED'}{'on'} = ''; | |
4416 | $checked{'EDIT_ADVANCED'}{$cgiparams{'EDIT_ADVANCED'}} = 'CHECKED'; | |
c6c9630e | 4417 | |
6e13d0a5 MT |
4418 | $selected{'SIDE'}{'server'} = ''; |
4419 | $selected{'SIDE'}{'client'} = ''; | |
4420 | $selected{'SIDE'}{$cgiparams{'SIDE'}} = 'SELECTED'; | |
d96c89eb AH |
4421 | |
4422 | $selected{'PROTOCOL'}{'udp'} = ''; | |
4423 | $selected{'PROTOCOL'}{'tcp'} = ''; | |
4424 | $selected{'PROTOCOL'}{$cgiparams{'PROTOCOL'}} = 'SELECTED'; | |
4425 | ||
c6c9630e | 4426 | |
6e13d0a5 MT |
4427 | $checked{'AUTH'}{'psk'} = ''; |
4428 | $checked{'AUTH'}{'certreq'} = ''; | |
4429 | $checked{'AUTH'}{'certgen'} = ''; | |
4430 | $checked{'AUTH'}{'certfile'} = ''; | |
4431 | $checked{'AUTH'}{$cgiparams{'AUTH'}} = 'CHECKED'; | |
c6c9630e | 4432 | |
6e13d0a5 | 4433 | $selected{'INTERFACE'}{$cgiparams{'INTERFACE'}} = 'SELECTED'; |
c6c9630e | 4434 | |
6e13d0a5 MT |
4435 | $checked{'COMPLZO'}{'off'} = ''; |
4436 | $checked{'COMPLZO'}{'on'} = ''; | |
4437 | $checked{'COMPLZO'}{$cgiparams{'COMPLZO'}} = 'CHECKED'; | |
c6c9630e | 4438 | |
d96c89eb AH |
4439 | $checked{'MSSFIX'}{'off'} = ''; |
4440 | $checked{'MSSFIX'}{'on'} = ''; | |
4441 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
4442 | ||
92b87e17 SS |
4443 | if ($cgiparams{'PMTU_DISCOVERY'} eq '') { |
4444 | $cgiparams{'PMTU_DISCOVERY'} = 'off'; | |
4445 | } | |
2ee746be SS |
4446 | $checked{'PMTU_DISCOVERY'}{$cgiparams{'PMTU_DISCOVERY'}} = 'checked=\'checked\''; |
4447 | ||
4c962356 EK |
4448 | $selected{'DCIPHER'}{'CAMELLIA-256-CBC'} = ''; |
4449 | $selected{'DCIPHER'}{'CAMELLIA-192-CBC'} = ''; | |
4450 | $selected{'DCIPHER'}{'CAMELLIA-128-CBC'} = ''; | |
4451 | $selected{'DCIPHER'}{'AES-256-CBC'} = ''; | |
4452 | $selected{'DCIPHER'}{'AES-192-CBC'} = ''; | |
4453 | $selected{'DCIPHER'}{'AES-128-CBC'} = ''; | |
4454 | $selected{'DCIPHER'}{'DESX-CBC'} = ''; | |
4455 | $selected{'DCIPHER'}{'SEED-CBC'} = ''; | |
4456 | $selected{'DCIPHER'}{'DES-EDE3-CBC'} = ''; | |
4457 | $selected{'DCIPHER'}{'DES-EDE-CBC'} = ''; | |
4458 | $selected{'DCIPHER'}{'CAST5-CBC'} = ''; | |
4459 | $selected{'DCIPHER'}{'BF-CBC'} = ''; | |
4460 | $selected{'DCIPHER'}{'RC2-CBC'} = ''; | |
4461 | $selected{'DCIPHER'}{'DES-CBC'} = ''; | |
4462 | $selected{'DCIPHER'}{'RC2-64-CBC'} = ''; | |
4463 | $selected{'DCIPHER'}{'RC2-40-CBC'} = ''; | |
49abe7af EK |
4464 | # If no cipher has been chossen yet, select |
4465 | # the old default (AES-256-CBC) for compatiblity reasons. | |
4466 | if ($cgiparams{'DCIPHER'} eq '') { | |
4467 | $cgiparams{'DCIPHER'} = 'AES-256-CBC'; | |
4468 | } | |
4c962356 | 4469 | $selected{'DCIPHER'}{$cgiparams{'DCIPHER'}} = 'SELECTED'; |
49abe7af EK |
4470 | $selected{'DAUTH'}{'whirlpool'} = ''; |
4471 | $selected{'DAUTH'}{'SHA512'} = ''; | |
4472 | $selected{'DAUTH'}{'SHA384'} = ''; | |
4473 | $selected{'DAUTH'}{'SHA256'} = ''; | |
4474 | $selected{'DAUTH'}{'SHA1'} = ''; | |
4475 | # If no hash algorythm has been choosen yet, select | |
4476 | # the old default value (SHA1) for compatiblity reasons. | |
4477 | if ($cgiparams{'DAUTH'} eq '') { | |
4478 | $cgiparams{'DAUTH'} = 'SHA1'; | |
4479 | } | |
4480 | $selected{'DAUTH'}{$cgiparams{'DAUTH'}} = 'SELECTED'; | |
4481 | ||
4482 | $selected{'ENGINES'}{'disabled'} = ''; | |
4483 | $selected{'ENGINES'}{'cryptodev'} = ''; | |
4484 | $selected{'ENGINES'}{'dynamic'} = ''; | |
4485 | $selected{'ENGINES'}{'aesni'} = ''; | |
4486 | $selected{'ENGINES'}{'padlock'} = ''; | |
4487 | # If no engine has been choosen yet, select | |
4488 | # a default one (disabled). | |
4489 | if ($cgiparams{'ENGINES'} eq '') { | |
4490 | $cgiparams{'ENGINES'} = 'disabled'; | |
4491 | } | |
4492 | $selected{'ENGINES'}{$cgiparams{'ENGINES'}} = 'SELECTED'; | |
6e13d0a5 MT |
4493 | |
4494 | if (1) { | |
4495 | &Header::showhttpheaders(); | |
4c962356 | 4496 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
6e13d0a5 MT |
4497 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); |
4498 | if ($errormessage) { | |
4499 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
4500 | print "<class name='base'>$errormessage"; | |
4501 | print " </class>"; | |
4502 | &Header::closebox(); | |
4503 | } | |
c6c9630e | 4504 | |
6e13d0a5 MT |
4505 | if ($warnmessage) { |
4506 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'warning messages'}:"); | |
4507 | print "<class name='base'>$warnmessage"; | |
4508 | print " </class>"; | |
4509 | &Header::closebox(); | |
4510 | } | |
c6c9630e | 4511 | |
6e13d0a5 | 4512 | print "<form method='post' enctype='multipart/form-data'>"; |
ce9abb66 | 4513 | print "<input type='hidden' name='TYPE' value='$cgiparams{'TYPE'}' />"; |
c6c9630e | 4514 | |
6e13d0a5 MT |
4515 | if ($cgiparams{'KEY'}) { |
4516 | print "<input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />"; | |
4517 | print "<input type='hidden' name='AUTH' value='$cgiparams{'AUTH'}' />"; | |
6e13d0a5 | 4518 | } |
c6c9630e | 4519 | |
6e13d0a5 | 4520 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'connection'}:"); |
8c877a82 | 4521 | print "<table width='100%' border='0'>\n"; |
4c962356 | 4522 | |
8c877a82 AM |
4523 | print "<tr><td width='14%' class='boldbase'>$Lang::tr{'name'}: </td>"; |
4524 | ||
ce9abb66 | 4525 | if ($cgiparams{'TYPE'} eq 'host') { |
6e13d0a5 | 4526 | if ($cgiparams{'KEY'}) { |
8c877a82 | 4527 | print "<td width='35%' class='base'><input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />$cgiparams{'NAME'}</td>"; |
6e13d0a5 MT |
4528 | } else { |
4529 | print "<td width='35%'><input type='text' name='NAME' value='$cgiparams{'NAME'}' maxlength='20' size='30' /></td>"; | |
4530 | } | |
c6c9630e MT |
4531 | # print "<tr><td>$Lang::tr{'interface'}</td>"; |
4532 | # print "<td><select name='INTERFACE'>"; | |
4533 | # print "<option value='RED' $selected{'INTERFACE'}{'RED'}>RED</option>"; | |
4c962356 EK |
4534 | # if ($netsettings{'BLUE_DEV'} ne '') { |
4535 | # print "<option value='BLUE' $selected{'INTERFACE'}{'BLUE'}>BLUE</option>"; | |
4536 | # } | |
4537 | # print "<option value='GREEN' $selected{'INTERFACE'}{'GREEN'}>GREEN</option>"; | |
4538 | # print "<option value='ORANGE' $selected{'INTERFACE'}{'ORANGE'}>ORANGE</option>"; | |
4539 | # print "</select></td></tr>"; | |
4540 | # print <<END; | |
ce9abb66 AH |
4541 | } else { |
4542 | print "<input type='hidden' name='INTERFACE' value='red' />"; | |
4543 | if ($cgiparams{'KEY'}) { | |
4544 | print "<td width='25%' class='base' nowrap='nowrap'><input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />$cgiparams{'NAME'}</td>"; | |
4545 | } else { | |
4546 | print "<td width='25%'><input type='text' name='NAME' value='$cgiparams{'NAME'}' maxlength='20' /></td>"; | |
4547 | } | |
4c962356 | 4548 | print <<END; |
ce9abb66 AH |
4549 | <td width='25%'> </td> |
4550 | <td width='25%'> </td></tr> | |
4c962356 | 4551 | |
ce9abb66 | 4552 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'Act as'}</td> |
cd0c0a0d MT |
4553 | <td><select name='SIDE'><option value='server' $selected{'SIDE'}{'server'}>$Lang::tr{'openvpn server'}</option> |
4554 | <option value='client' $selected{'SIDE'}{'client'}>$Lang::tr{'openvpn client'}</option></select></td> | |
4c962356 | 4555 | |
ce9abb66 AH |
4556 | <td class='boldbase'>$Lang::tr{'remote host/ip'}:</td> |
4557 | <td><input type='TEXT' name='REMOTE' value='$cgiparams{'REMOTE'}' /></td></tr> | |
4c962356 | 4558 | |
ce9abb66 AH |
4559 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'}</td> |
4560 | <td><input type='TEXT' name='LOCAL_SUBNET' value='$cgiparams{'LOCAL_SUBNET'}' /></td> | |
4c962356 | 4561 | |
ce9abb66 AH |
4562 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'}</td> |
4563 | <td><input type='text' name='REMOTE_SUBNET' value='$cgiparams{'REMOTE_SUBNET'}' /></td></tr> | |
4c962356 | 4564 | |
ce9abb66 AH |
4565 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn subnet'}</td> |
4566 | <td><input type='TEXT' name='OVPN_SUBNET' value='$cgiparams{'OVPN_SUBNET'}' /></td></tr> | |
4c962356 | 4567 | |
d96c89eb | 4568 | |
4c962356 EK |
4569 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td> |
4570 | <td><select name='PROTOCOL'><option value='udp' $selected{'PROTOCOL'}{'udp'}>UDP</option> | |
49abe7af | 4571 | <option value='tcp' $selected{'PROTOCOL'}{'tcp'}>TCP</option></select></td> |
4c962356 | 4572 | |
49abe7af EK |
4573 | <td class='boldbase'>$Lang::tr{'destination port'}:</td> |
4574 | <td><input type='TEXT' name='DEST_PORT' value='$cgiparams{'DEST_PORT'}' size='5' /></td> | |
4c962356 EK |
4575 | </tr> |
4576 | ||
4577 | <tr><td class='boldbase'>$Lang::tr{'cipher'}</td> | |
4578 | <td><select name='DCIPHER'> | |
49abe7af EK |
4579 | <option value='CAMELLIA-256-CBC' $selected{'DCIPHER'}{'CAMELLIA-256-CBC'}>CAMELLIA-CBC (256 $Lang::tr{'bit'})</option> |
4580 | <option value='CAMELLIA-192-CBC' $selected{'DCIPHER'}{'CAMELLIA-192-CBC'}>CAMELLIA-CBC (196 $Lang::tr{'bit'})</option> | |
4581 | <option value='CAMELLIA-128-CBC' $selected{'DCIPHER'}{'CAMELLIA-128-CBC'}>CAMELLIA-CBC (128 $Lang::tr{'bit'})</option> | |
4582 | <option value='AES-256-CBC' $selected{'DCIPHER'}{'AES-256-CBC'}>AES-CBC (256 $Lang::tr{'bit'})</option> | |
4583 | <option value='AES-192-CBC' $selected{'DCIPHER'}{'AES-192-CBC'}>AES-CBC (192 $Lang::tr{'bit'})</option> | |
4584 | <option value='AES-128-CBC' $selected{'DCIPHER'}{'AES-128-CBC'}>AES-CBC (128 $Lang::tr{'bit'})</option> | |
4585 | <option value='DES-EDE3-CBC' $selected{'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC (192 $Lang::tr{'bit'})</option> | |
4586 | <option value='DESX-CBC' $selected{'DCIPHER'}{'DESX-CBC'}>DESX-CBC (192 $Lang::tr{'bit'})</option> | |
4587 | <option value='SEED-CBC' $selected{'DCIPHER'}{'SEED-CBC'}>SEED-CBC (128 $Lang::tr{'bit'})</option> | |
4588 | <option value='DES-EDE-CBC' $selected{'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC (128 $Lang::tr{'bit'})</option> | |
4589 | <option value='BF-CBC' $selected{'DCIPHER'}{'BF-CBC'}>BF-CBC (128 $Lang::tr{'bit'})</option> | |
4590 | <option value='CAST5-CBC' $selected{'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC (128 $Lang::tr{'bit'})</option> | |
4591 | <option value='RC2-CBC' $selected{'DCIPHER'}{'RC2-CBC'}>RC2-CBC (128 $Lang::tr{'bit'})</option> | |
4592 | <option value='DES-CBC' $selected{'DCIPHER'}{'DES-CBC'}>DES-CBC (64 $Lang::tr{'bit'} not recommended)</option> | |
4593 | <option value='RC2-64-CBC' $selected{'DCIPHER'}{'RC2-64-CBC'}>RC2-CBC (64 $Lang::tr{'bit'} not recommended)</option> | |
4594 | <option value='RC2-40-CBC' $selected{'DCIPHER'}{'RC2-40-CBC'}>RC2-CBC (40 $Lang::tr{'bit'} not recommended)</option> | |
4c962356 EK |
4595 | </select> |
4596 | </td> | |
4597 | ||
4598 | <td class='boldbase'>$Lang::tr{'ovpn ha'}:</td> | |
4599 | <td><select name='DAUTH'> | |
49abe7af EK |
4600 | <option value='whirlpool' $selected{'DAUTH'}{'whirlpool'}>Whirlpool (512 $Lang::tr{'bit'})</option> |
4601 | <option value='SHA512' $selected{'DAUTH'}{'SHA512'}>SHA2 (512 $Lang::tr{'bit'})</option> | |
4602 | <option value='SHA384' $selected{'DAUTH'}{'SHA384'}>SHA2 (384 $Lang::tr{'bit'})</option> | |
4603 | <option value='SHA256' $selected{'DAUTH'}{'SHA256'}>SHA2 (256 $Lang::tr{'bit'})</option> | |
4604 | <option value='SHA1' $selected{'DAUTH'}{'SHA1'}>SHA1 (160 $Lang::tr{'bit'} Default)</option> | |
4605 | </select> | |
4606 | </td> | |
4607 | </tr> | |
4608 | ||
4609 | <tr> <td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn engines'} <img src='/blob.gif'</td> | |
4610 | <td><select name='ENGINES'> | |
4611 | <option value='cryptodev' $selected{'ENGINES'}{'cryptodev'}>Cryptodev</option> | |
4612 | <option value='dynamic' $selected{'ENGINES'}{'dynamic'}>Dynamic</option> | |
4613 | <option value='aesni' $selected{'ENGINES'}{'aesni'}>AES-NI</option> | |
4614 | <option value='padlock' $selected{'ENGINES'}{'padlock'}>Padlock</option> | |
4615 | <option value='disabled' $selected{'ENGINES'}{'disabled'}>$Lang::tr{'disabled'} (Default)</option> | |
4c962356 EK |
4616 | </select> |
4617 | </td> | |
4618 | </tr> | |
4619 | ||
49abe7af EK |
4620 | <tr><td colspan=2><hr /></td></tr><tr> |
4621 | ||
4622 | <tr><td class='boldbase' nowrap='nowrap'>Management Port ($Lang::tr{'openvpn default'}: <span class="base">$Lang::tr{'destination port'}): <img src='/blob.gif' /></td> | |
4623 | <td> <input type='TEXT' name='OVPN_MGMT' VALUE='$cgiparams{'OVPN_MGMT'}'size='5' /></td> | |
4624 | </tr> | |
4625 | ||
ce9abb66 | 4626 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'} <img src='/blob.gif' /></td> |
4c962356 EK |
4627 | <td> <input type='TEXT' name='MTU' VALUE='$cgiparams{'MTU'}'size='5' /></td> |
4628 | <td colspan='2'>$Lang::tr{'openvpn default'}: udp/tcp <span class="base">1500/1400</span></td> | |
49abe7af | 4629 | </tr> |
4c962356 | 4630 | |
49abe7af | 4631 | <tr><td class='boldbase' nowrap='nowrap'>fragment <img src='/blob.gif' /></td> |
4c962356 EK |
4632 | <td><input type='TEXT' name='FRAGMENT' VALUE='$cgiparams{'FRAGMENT'}'size='5' /></td> |
4633 | <td>$Lang::tr{'openvpn default'}: <span class="base">1300</span></td> | |
49abe7af | 4634 | </tr> |
4c962356 | 4635 | |
49abe7af | 4636 | <tr><td class='boldbase' nowrap='nowrap'>mssfix <img src='/blob.gif' /></td> |
4c962356 EK |
4637 | <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td> |
4638 | <td>$Lang::tr{'openvpn default'}: <span class="base">on</span></td> | |
4c962356 EK |
4639 | </tr> |
4640 | ||
49abe7af EK |
4641 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'} <img src='/blob.gif'</td> |
4642 | <td><input type='checkbox' name='COMPLZO' $checked{'COMPLZO'}{'on'} /></td> | |
4c962356 | 4643 | </tr> |
2ee746be | 4644 | |
49abe7af | 4645 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn mtu-disc'}</td> |
4cdf8b92 | 4646 | <td colspan='3'> |
2ee746be SS |
4647 | <input type='radio' name='PMTU_DISCOVERY' value='yes' $checked{'PMTU_DISCOVERY'}{'yes'} /> $Lang::tr{'ovpn mtu-disc yes'} |
4648 | <input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked{'PMTU_DISCOVERY'}{'maybe'} /> $Lang::tr{'ovpn mtu-disc maybe'} | |
4649 | <input type='radio' name='PMTU_DISCOVERY' value='no' $checked{'PMTU_DISCOVERY'}{'no'} /> $Lang::tr{'ovpn mtu-disc no'} | |
4650 | <input type='radio' name='PMTU_DISCOVERY' value='off' $checked{'PMTU_DISCOVERY'}{'off'} /> $Lang::tr{'ovpn mtu-disc off'} | |
4651 | </td> | |
4652 | </tr> | |
ce9abb66 | 4653 | END |
8c877a82 | 4654 | ; |
ce9abb66 | 4655 | } |
2ee746be | 4656 | #jumper |
6e13d0a5 | 4657 | print "<tr><td class='boldbase'>$Lang::tr{'remark title'} <img src='/blob.gif' /></td>"; |
8c877a82 | 4658 | print "<td colspan='3'><input type='text' name='REMARK' value='$cgiparams{'REMARK'}' size='55' maxlength='50' /></td></tr></table>"; |
c6c9630e | 4659 | |
ce9abb66 | 4660 | if ($cgiparams{'TYPE'} eq 'host') { |
8c877a82 AM |
4661 | print "<tr><td>$Lang::tr{'enabled'} <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>"; |
4662 | } | |
ce9abb66 | 4663 | |
8c877a82 AM |
4664 | print"</tr></table><br><br>"; |
4665 | #A.Marx CCD new client | |
e81be1e1 | 4666 | if ($cgiparams{'TYPE'} eq 'host') { |
8c877a82 | 4667 | print "<table border='0' width='100%' cellspacing='1' cellpadding='0'><tr><td colspan='3'><hr><br><b>$Lang::tr{'ccd choose net'}</td></tr><tr><td height='20' colspan='3'></td></tr>"; |
8c877a82 AM |
4668 | my %vpnnet=(); |
4669 | my $vpnip; | |
4670 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnnet); | |
4671 | $vpnip=$vpnnet{'DOVPN_SUBNET'}; | |
4672 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
4673 | my @ccdconf=(); | |
4674 | my $count=0; | |
4675 | my $checked; | |
4676 | $checked{'check1'}{'off'} = ''; | |
4677 | $checked{'check1'}{'on'} = ''; | |
4678 | $checked{'check1'}{$cgiparams{'CHECK1'}} = 'CHECKED'; | |
4679 | print"<tr><td align='center' width='1%' valign='top'><input type='radio' name='CHECK1' value='dynamic' checked /></td><td align='left' valign='top' width='35%'>$Lang::tr{'ccd dynrange'} ($vpnip)</td><td width='30%'>"; | |
4680 | print"</td></tr></table><br><br>"; | |
4681 | my $name=$cgiparams{'CHECK1'}; | |
4682 | $checked{'RG'}{$cgiparams{'RG'}} = 'CHECKED'; | |
4683 | ||
4684 | if (! -z "${General::swroot}/ovpn/ccd.conf"){ | |
4685 | print"<table border='0' width='100%' cellspacing='1' cellpadding='0'><tr><td width='1%'></td><td width='30%' class='boldbase' align='center'><b>$Lang::tr{'ccd name'}</td><td width='15%' class='boldbase' align='center'><b>$Lang::tr{'network'}</td><td class='boldbase' align='center' width='18%'><b>$Lang::tr{'ccd clientip'}</td></tr>"; | |
df9b48b7 | 4686 | foreach my $key (sort { uc($ccdconfhash{$a}[0]) cmp uc($ccdconfhash{$b}[0]) } keys %ccdconfhash) { |
8c877a82 AM |
4687 | $count++; |
4688 | @ccdconf=($ccdconfhash{$key}[0],$ccdconfhash{$key}[1]); | |
4689 | if ($count % 2){print"<tr bgcolor='$color{'color22'}'>";}else{print"<tr bgcolor='$color{'color20'}'>";} | |
4690 | print"<td align='center' width='1%'><input type='radio' name='CHECK1' value='$ccdconf[0]' $checked{'check1'}{$ccdconf[0]}/></td><td>$ccdconf[0]</td><td width='40%' align='center'>$ccdconf[1]</td><td align='left' width='10%'>"; | |
4691 | &fillselectbox($ccdconf[1],$ccdconf[0],$cgiparams{$name}); | |
4692 | print"</td></tr>"; | |
4693 | } | |
4694 | print "</table><br><br><hr><br><br>"; | |
4695 | } | |
e81be1e1 | 4696 | } |
8c877a82 | 4697 | # ccd end |
6e13d0a5 MT |
4698 | &Header::closebox(); |
4699 | if ($cgiparams{'KEY'} && $cgiparams{'AUTH'} eq 'psk') { | |
8c877a82 AM |
4700 | |
4701 | } elsif (! $cgiparams{'KEY'}) { | |
4702 | ||
4703 | ||
6e13d0a5 MT |
4704 | my $disabled=''; |
4705 | my $cakeydisabled=''; | |
4706 | my $cacrtdisabled=''; | |
4707 | if ( ! -f "${General::swroot}/ovpn/ca/cakey.pem" ) { $cakeydisabled = "disabled='disabled'" } else { $cakeydisabled = "" }; | |
4708 | if ( ! -f "${General::swroot}/ovpn/ca/cacert.pem" ) { $cacrtdisabled = "disabled='disabled'" } else { $cacrtdisabled = "" }; | |
8c877a82 | 4709 | |
6e13d0a5 | 4710 | &Header::openbox('100%', 'LEFT', $Lang::tr{'authentication'}); |
ce9abb66 AH |
4711 | |
4712 | ||
4713 | if ($cgiparams{'TYPE'} eq 'host') { | |
4714 | ||
49abe7af | 4715 | print <<END; |
6e13d0a5 | 4716 | <table width='100%' cellpadding='0' cellspacing='5' border='0'> |
54fd0535 | 4717 | |
ce9abb66 AH |
4718 | <tr><td><input type='radio' name='AUTH' value='certreq' $checked{'AUTH'}{'certreq'} $cakeydisabled /></td><td class='base'>$Lang::tr{'upload a certificate request'}</td><td class='base' rowspan='2'><input type='file' name='FH' size='30' $cacrtdisabled></td></tr> |
4719 | <tr><td><input type='radio' name='AUTH' value='certfile' $checked{'AUTH'}{'certfile'} $cacrtdisabled /></td><td class='base'>$Lang::tr{'upload a certificate'}</td></tr> | |
54fd0535 MT |
4720 | <tr><td colspan='3'> </td></tr> |
4721 | <tr><td colspan='3'><hr /></td></tr> | |
4722 | <tr><td colspan='3'> </td></tr> | |
ce9abb66 AH |
4723 | <tr><td><input type='radio' name='AUTH' value='certgen' $checked{'AUTH'}{'certgen'} $cakeydisabled /></td><td class='base'>$Lang::tr{'generate a certificate'}</td><td> </td></tr> |
4724 | <tr><td> </td><td class='base'>$Lang::tr{'users fullname or system hostname'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value='$cgiparams{'CERT_NAME'}' SIZE='32' $cakeydisabled /></td></tr> | |
4725 | <tr><td> </td><td class='base'>$Lang::tr{'users email'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value='$cgiparams{'CERT_EMAIL'}' SIZE='32' $cakeydisabled /></td></tr> | |
4726 | <tr><td> </td><td class='base'>$Lang::tr{'users department'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value='$cgiparams{'CERT_OU'}' SIZE='32' $cakeydisabled /></td></tr> | |
4727 | <tr><td> </td><td class='base'>$Lang::tr{'organization name'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value='$cgiparams{'CERT_ORGANIZATION'}' SIZE='32' $cakeydisabled /></td></tr> | |
4728 | <tr><td> </td><td class='base'>$Lang::tr{'city'}: <img src='/blob.gif'></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value='$cgiparams{'CERT_CITY'}' SIZE='32' $cakeydisabled /></td></tr> | |
4729 | <tr><td> </td><td class='base'>$Lang::tr{'state or province'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value='$cgiparams{'CERT_STATE'}' SIZE='32' $cakeydisabled /></td></tr> | |
4730 | <tr><td> </td><td class='base'>$Lang::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled> | |
6e13d0a5 | 4731 | END |
ce9abb66 AH |
4732 | ; |
4733 | ||
4734 | ### | |
7c1d9faf | 4735 | # m.a.d net2net |
ce9abb66 AH |
4736 | ### |
4737 | ||
4738 | } else { | |
4739 | ||
49abe7af | 4740 | print <<END; |
ce9abb66 AH |
4741 | <table width='100%' cellpadding='0' cellspacing='5' border='0'> |
4742 | ||
4743 | <tr><td><input type='radio' name='AUTH' value='certgen' $checked{'AUTH'}{'certgen'} $cakeydisabled /></td><td class='base'>$Lang::tr{'generate a certificate'}</td><td> </td></tr> | |
4744 | <tr><td> </td><td class='base'>$Lang::tr{'users fullname or system hostname'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value='$cgiparams{'CERT_NAME'}' SIZE='32' $cakeydisabled /></td></tr> | |
4745 | <tr><td> </td><td class='base'>$Lang::tr{'users email'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value='$cgiparams{'CERT_EMAIL'}' SIZE='32' $cakeydisabled /></td></tr> | |
4746 | <tr><td> </td><td class='base'>$Lang::tr{'users department'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value='$cgiparams{'CERT_OU'}' SIZE='32' $cakeydisabled /></td></tr> | |
4747 | <tr><td> </td><td class='base'>$Lang::tr{'organization name'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value='$cgiparams{'CERT_ORGANIZATION'}' SIZE='32' $cakeydisabled /></td></tr> | |
4748 | <tr><td> </td><td class='base'>$Lang::tr{'city'}: <img src='/blob.gif'></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value='$cgiparams{'CERT_CITY'}' SIZE='32' $cakeydisabled /></td></tr> | |
4749 | <tr><td> </td><td class='base'>$Lang::tr{'state or province'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value='$cgiparams{'CERT_STATE'}' SIZE='32' $cakeydisabled /></td></tr> | |
4750 | <tr><td> </td><td class='base'>$Lang::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled> | |
54fd0535 MT |
4751 | |
4752 | ||
ce9abb66 AH |
4753 | END |
4754 | ; | |
4755 | ||
4756 | } | |
4757 | ||
4758 | ### | |
7c1d9faf | 4759 | # m.a.d net2net |
ce9abb66 | 4760 | ### |
c6c9630e | 4761 | |
6e13d0a5 MT |
4762 | foreach my $country (sort keys %{Countries::countries}) { |
4763 | print "<option value='$Countries::countries{$country}'"; | |
4764 | if ( $Countries::countries{$country} eq $cgiparams{'CERT_COUNTRY'} ) { | |
4765 | print " selected='selected'"; | |
4766 | } | |
4767 | print ">$country</option>"; | |
4768 | } | |
ce9abb66 | 4769 | ### |
7c1d9faf | 4770 | # m.a.d net2net |
ce9abb66 AH |
4771 | ### |
4772 | ||
4773 | if ($cgiparams{'TYPE'} eq 'host') { | |
49abe7af | 4774 | print <<END; |
6e13d0a5 | 4775 | </select></td></tr> |
ce9abb66 | 4776 | |
54fd0535 | 4777 | <td> </td><td class='base'>$Lang::tr{'valid till'} (days):</td> |
ce9abb66 AH |
4778 | <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value='$cgiparams{'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr> |
4779 | <tr><td> </td> | |
6e13d0a5 MT |
4780 | <td class='base'>$Lang::tr{'pkcs12 file password'}:</td> |
4781 | <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value='$cgiparams{'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr> | |
b2e75449 | 4782 | <tr><td> </td><td class='base'>$Lang::tr{'pkcs12 file password'}:<BR>($Lang::tr{'confirmation'})</td> |
6e13d0a5 | 4783 | <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value='$cgiparams{'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr> |
54fd0535 MT |
4784 | <tr><td colspan='3'> </td></tr> |
4785 | <tr><td colspan='3'><hr /></td></tr> | |
4786 | <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang::tr{'this field may be blank'}</td></tr> | |
ce9abb66 AH |
4787 | </table> |
4788 | END | |
4789 | }else{ | |
49abe7af | 4790 | print <<END; |
ce9abb66 AH |
4791 | </select></td></tr> |
4792 | <tr><td> </td><td> </td><td> </td></tr> | |
4793 | <tr><td> </td><td> </td><td> </td></tr> | |
54fd0535 MT |
4794 | <tr><td colspan='3'><hr /></td></tr> |
4795 | <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang::tr{'this field may be blank'}</td></tr> | |
ce9abb66 AH |
4796 | </table> |
4797 | ||
c6c9630e | 4798 | END |
ce9abb66 AH |
4799 | } |
4800 | ||
4801 | ### | |
7c1d9faf | 4802 | # m.a.d net2net |
ce9abb66 | 4803 | ### |
c6c9630e MT |
4804 | ; |
4805 | &Header::closebox(); | |
8c877a82 AM |
4806 | |
4807 | } | |
e81be1e1 AM |
4808 | |
4809 | #A.Marx CCD new client | |
4810 | if ($cgiparams{'TYPE'} eq 'host') { | |
8c877a82 AM |
4811 | print"<br><br>"; |
4812 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ccd client options'}:"); | |
4813 | ||
8c877a82 AM |
4814 | |
4815 | print <<END; | |
4816 | <table border='0' width='100%'> | |
4817 | <tr><td width='20%'>Redirect Gateway:</td><td colspan='3'><input type='checkbox' name='RG' $checked{'RG'}{'on'} /></td></tr> | |
4818 | <tr><td colspan='4'><b><br>$Lang::tr{'ccd routes'}</b></td></tr> | |
4819 | <tr><td colspan='4'> </td></tr> | |
4820 | <tr><td valign='top'>$Lang::tr{'ccd iroute'}</td><td align='left' width='30%'><textarea name='IR' cols='26' rows='6' wrap='off'> | |
4821 | END | |
4822 | ||
4823 | if ($cgiparams{'IR'} ne ''){ | |
4824 | print $cgiparams{'IR'}; | |
4825 | }else{ | |
4826 | &General::readhasharray ("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
4827 | foreach my $key (keys %ccdroutehash) { | |
4828 | if( $cgiparams{'NAME'} eq $ccdroutehash{$key}[0]){ | |
4829 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { | |
4830 | if ($ccdroutehash{$key}[$i] ne ''){ | |
4831 | print $ccdroutehash{$key}[$i]."\n"; | |
4832 | } | |
4833 | $cgiparams{'IR'} .= $ccdroutehash{$key}[$i]; | |
4834 | } | |
4835 | } | |
4836 | } | |
c6c9630e | 4837 | } |
8c877a82 AM |
4838 | |
4839 | print <<END; | |
4840 | </textarea></td><td valign='top' colspan='2'>$Lang::tr{'ccd iroutehint'}</td></tr> | |
4841 | <tr><td colspan='4'><br></td></tr> | |
4842 | <tr><td valign='top' rowspan='3'>$Lang::tr{'ccd iroute2'}</td><td align='left' valign='top' rowspan='3'><select name='IFROUTE' style="width: 205px"; size='6' multiple> | |
4843 | END | |
52d08bcb AM |
4844 | |
4845 | my $set=0; | |
4846 | my $selorange=0; | |
4847 | my $selblue=0; | |
4848 | my $selgreen=0; | |
4849 | my $helpblue=0; | |
4850 | my $helporange=0; | |
4851 | my $other=0; | |
df9b48b7 | 4852 | my $none=0; |
52d08bcb AM |
4853 | my @temp=(); |
4854 | ||
8c877a82 | 4855 | our @current = (); |
52d08bcb AM |
4856 | open(FILE, "${General::swroot}/main/routing") ; |
4857 | @current = <FILE>; | |
4858 | close (FILE); | |
4859 | &General::readhasharray ("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
df9b48b7 AM |
4860 | #check for "none" |
4861 | foreach my $key (keys %ccdroute2hash) { | |
4862 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4863 | if ($ccdroute2hash{$key}[1] eq ''){ | |
4864 | $none=1; | |
4865 | last; | |
4866 | } | |
4867 | } | |
4868 | } | |
4869 | if ($none ne '1'){ | |
4870 | print"<option>$Lang::tr{'ccd none'}</option>"; | |
4871 | }else{ | |
4872 | print"<option selected>$Lang::tr{'ccd none'}</option>"; | |
4873 | } | |
52d08bcb AM |
4874 | #check if static routes are defined for client |
4875 | foreach my $line (@current) { | |
4876 | chomp($line); | |
4877 | $line=~s/\s*$//g; # remove newline | |
4878 | @temp=split(/\,/,$line); | |
4879 | $temp[1] = '' unless defined $temp[1]; # not always populated | |
4880 | my ($a,$b) = split(/\//,$temp[1]); | |
4881 | $temp[1] = $a."/".&General::iporsubtocidr($b); | |
4882 | foreach my $key (keys %ccdroute2hash) { | |
4883 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4884 | foreach my $i (1 .. $#{$ccdroute2hash{$key}}) { | |
4885 | if($ccdroute2hash{$key}[$i] eq $a."/".&General::iporsubtodec($b)){ | |
4886 | $set=1; | |
8c877a82 AM |
4887 | } |
4888 | } | |
8c877a82 | 4889 | } |
52d08bcb AM |
4890 | } |
4891 | if ($set == '1' && $#temp != -1){ print"<option selected>$temp[1]</option>";$set=0;}elsif($set == '0' && $#temp != -1){print"<option>$temp[1]</option>";} | |
4892 | } | |
4893 | #check if green,blue,orange are defined for client | |
4894 | foreach my $key (keys %ccdroute2hash) { | |
4895 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4896 | $other=1; | |
4897 | foreach my $i (1 .. $#{$ccdroute2hash{$key}}) { | |
4898 | if ($ccdroute2hash{$key}[$i] eq $netsettings{'GREEN_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'GREEN_NETMASK'})){ | |
4899 | $selgreen=1; | |
4900 | } | |
4901 | if (&haveBlueNet()){ | |
4902 | if( $ccdroute2hash{$key}[$i] eq $netsettings{'BLUE_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'BLUE_NETMASK'})) { | |
4903 | $selblue=1; | |
4904 | } | |
4905 | } | |
4906 | if (&haveOrangeNet()){ | |
4907 | if( $ccdroute2hash{$key}[$i] eq $netsettings{'ORANGE_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'ORANGE_NETMASK'}) ) { | |
4908 | $selorange=1; | |
4909 | } | |
4910 | } | |
4911 | } | |
4912 | } | |
4913 | } | |
4914 | if (&haveBlueNet() && $selblue == '1'){ print"<option selected>$Lang::tr{'blue'}</option>";$selblue=0;}elsif(&haveBlueNet() && $selblue == '0'){print"<option>$Lang::tr{'blue'}</option>";} | |
4915 | if (&haveOrangeNet() && $selorange == '1'){ print"<option selected>$Lang::tr{'orange'}</option>";$selorange=0;}elsif(&haveOrangeNet() && $selorange == '0'){print"<option>$Lang::tr{'orange'}</option>";} | |
4916 | if ($selgreen == '1' || $other == '0'){ print"<option selected>$Lang::tr{'green'}</option>";$set=0;}else{print"<option>$Lang::tr{'green'}</option>";}; | |
4917 | ||
49abe7af | 4918 | print<<END; |
8c877a82 AM |
4919 | </select></td><td valign='top'>DNS1:</td><td valign='top'><input type='TEXT' name='CCD_DNS1' value='$cgiparams{'CCD_DNS1'}' size='30' /></td></tr> |
4920 | <tr valign='top'><td>DNS2:</td><td><input type='TEXT' name='CCD_DNS2' value='$cgiparams{'CCD_DNS2'}' size='30' /></td></tr> | |
4921 | <tr valign='top'><td valign='top'>WINS:</td><td><input type='TEXT' name='CCD_WINS' value='$cgiparams{'CCD_WINS'}' size='30' /></td></tr></table><br><hr> | |
4922 | ||
4923 | END | |
4924 | ; | |
4925 | &Header::closebox(); | |
e81be1e1 | 4926 | } |
c6c9630e MT |
4927 | print "<div align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' />"; |
4928 | if ($cgiparams{'KEY'}) { | |
4929 | # print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />"; | |
4930 | } | |
4931 | print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>"; | |
4932 | &Header::closebigbox(); | |
4933 | &Header::closepage(); | |
4934 | exit (0); | |
6e13d0a5 | 4935 | } |
c6c9630e | 4936 | VPNCONF_END: |
6e13d0a5 | 4937 | } |
c6c9630e MT |
4938 | |
4939 | # SETTINGS_ERROR: | |
6e13d0a5 MT |
4940 | ### |
4941 | ### Default status page | |
4942 | ### | |
c6c9630e MT |
4943 | %cgiparams = (); |
4944 | %cahash = (); | |
4945 | %confighash = (); | |
4946 | &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams); | |
4947 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
4948 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
4949 | ||
4e17adad | 4950 | my @status = `/bin/cat /var/log/ovpnserver.log`; |
c6c9630e MT |
4951 | |
4952 | if ($cgiparams{'VPN_IP'} eq '' && -e "${General::swroot}/red/active") { | |
8c877a82 AM |
4953 | if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) { |
4954 | my $ipaddr = <IPADDR>; | |
4955 | close IPADDR; | |
4956 | chomp ($ipaddr); | |
4957 | $cgiparams{'VPN_IP'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0]; | |
4958 | if ($cgiparams{'VPN_IP'} eq '') { | |
4959 | $cgiparams{'VPN_IP'} = $ipaddr; | |
4960 | } | |
4961 | } | |
c6c9630e MT |
4962 | } |
4963 | ||
6e13d0a5 | 4964 | #default setzen |
c6c9630e | 4965 | if ($cgiparams{'DCIPHER'} eq '') { |
4c962356 | 4966 | $cgiparams{'DCIPHER'} = 'AES-256-CBC'; |
c6c9630e | 4967 | } |
c6c9630e | 4968 | if ($cgiparams{'DDEST_PORT'} eq '') { |
4c962356 | 4969 | $cgiparams{'DDEST_PORT'} = '1194'; |
c6c9630e MT |
4970 | } |
4971 | if ($cgiparams{'DMTU'} eq '') { | |
4c962356 EK |
4972 | $cgiparams{'DMTU'} = '1400'; |
4973 | } | |
4974 | if ($cgiparams{'MSSFIX'} eq '') { | |
4975 | $cgiparams{'MSSFIX'} = 'off'; | |
4976 | } | |
4977 | if ($cgiparams{'DAUTH'} eq '') { | |
4978 | $cgiparams{'DAUTH'} = 'SHA1'; | |
c6c9630e | 4979 | } |
49abe7af EK |
4980 | if ($cgiparams{'ENGINES'} eq '') { |
4981 | $cgiparams{'ENGINES'} = 'disabled'; | |
4982 | } | |
c6c9630e | 4983 | if ($cgiparams{'DOVPN_SUBNET'} eq '') { |
4c962356 | 4984 | $cgiparams{'DOVPN_SUBNET'} = '10.' . int(rand(256)) . '.' . int(rand(256)) . '.0/255.255.255.0'; |
c6c9630e | 4985 | } |
4c962356 | 4986 | $checked{'ENABLED'}{'off'} = ''; |
c6c9630e MT |
4987 | $checked{'ENABLED'}{'on'} = ''; |
4988 | $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = 'CHECKED'; | |
4989 | $checked{'ENABLED_BLUE'}{'off'} = ''; | |
4990 | $checked{'ENABLED_BLUE'}{'on'} = ''; | |
4991 | $checked{'ENABLED_BLUE'}{$cgiparams{'ENABLED_BLUE'}} = 'CHECKED'; | |
4992 | $checked{'ENABLED_ORANGE'}{'off'} = ''; | |
4993 | $checked{'ENABLED_ORANGE'}{'on'} = ''; | |
4994 | $checked{'ENABLED_ORANGE'}{$cgiparams{'ENABLED_ORANGE'}} = 'CHECKED'; | |
c6c9630e MT |
4995 | $selected{'DDEVICE'}{'tun'} = ''; |
4996 | $selected{'DDEVICE'}{'tap'} = ''; | |
4997 | $selected{'DDEVICE'}{$cgiparams{'DDEVICE'}} = 'SELECTED'; | |
4998 | ||
4999 | $selected{'DPROTOCOL'}{'udp'} = ''; | |
5000 | $selected{'DPROTOCOL'}{'tcp'} = ''; | |
5001 | $selected{'DPROTOCOL'}{$cgiparams{'DPROTOCOL'}} = 'SELECTED'; | |
4c962356 EK |
5002 | |
5003 | $selected{'DCIPHER'}{'CAMELLIA-256-CBC'} = ''; | |
5004 | $selected{'DCIPHER'}{'CAMELLIA-192-CBC'} = ''; | |
5005 | $selected{'DCIPHER'}{'CAMELLIA-128-CBC'} = ''; | |
5006 | $selected{'DCIPHER'}{'AES-256-CBC'} = ''; | |
5007 | $selected{'DCIPHER'}{'AES-192-CBC'} = ''; | |
5008 | $selected{'DCIPHER'}{'AES-128-CBC'} = ''; | |
c6c9630e MT |
5009 | $selected{'DCIPHER'}{'DES-EDE3-CBC'} = ''; |
5010 | $selected{'DCIPHER'}{'DESX-CBC'} = ''; | |
4c962356 EK |
5011 | $selected{'DCIPHER'}{'SEED-CBC'} = ''; |
5012 | $selected{'DCIPHER'}{'DES-EDE-CBC'} = ''; | |
5013 | $selected{'DCIPHER'}{'CAST5-CBC'} = ''; | |
5014 | $selected{'DCIPHER'}{'BF-CBC'} = ''; | |
c6c9630e | 5015 | $selected{'DCIPHER'}{'RC2-CBC'} = ''; |
4c962356 | 5016 | $selected{'DCIPHER'}{'DES-CBC'} = ''; |
c6c9630e | 5017 | $selected{'DCIPHER'}{'RC2-64-CBC'} = ''; |
4c962356 | 5018 | $selected{'DCIPHER'}{'RC2-40-CBC'} = ''; |
c6c9630e | 5019 | $selected{'DCIPHER'}{$cgiparams{'DCIPHER'}} = 'SELECTED'; |
4c962356 EK |
5020 | |
5021 | $selected{'DAUTH'}{'whirlpool'} = ''; | |
5022 | $selected{'DAUTH'}{'SHA512'} = ''; | |
5023 | $selected{'DAUTH'}{'SHA384'} = ''; | |
5024 | $selected{'DAUTH'}{'SHA256'} = ''; | |
4c962356 EK |
5025 | $selected{'DAUTH'}{'SHA1'} = ''; |
5026 | $selected{'DAUTH'}{$cgiparams{'DAUTH'}} = 'SELECTED'; | |
5027 | ||
49abe7af EK |
5028 | $selected{'ENGINES'}{'cryptodev'} = ''; |
5029 | $selected{'ENGINES'}{'dynamic'} = ''; | |
5030 | $selected{'ENGINES'}{'aesni'} = ''; | |
5031 | $selected{'ENGINES'}{'padlock'} = ''; | |
5032 | $selected{'ENGINES'}{'disabled'} = ''; | |
5033 | $selected{'ENGINES'}{$cgiparams{'ENGINES'}} = 'SELECTED'; | |
5034 | ||
c6c9630e MT |
5035 | $checked{'DCOMPLZO'}{'off'} = ''; |
5036 | $checked{'DCOMPLZO'}{'on'} = ''; | |
5037 | $checked{'DCOMPLZO'}{$cgiparams{'DCOMPLZO'}} = 'CHECKED'; | |
4c962356 | 5038 | |
d96c89eb AH |
5039 | # m.a.d |
5040 | $checked{'MSSFIX'}{'off'} = ''; | |
5041 | $checked{'MSSFIX'}{'on'} = ''; | |
5042 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
6e13d0a5 | 5043 | #new settings |
c6c9630e MT |
5044 | &Header::showhttpheaders(); |
5045 | &Header::openpage($Lang::tr{'status ovpn'}, 1, ''); | |
5046 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
6e13d0a5 | 5047 | |
c6c9630e | 5048 | if ($errormessage) { |
6e13d0a5 MT |
5049 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); |
5050 | print "<class name='base'>$errormessage\n"; | |
5051 | print " </class>\n"; | |
5052 | &Header::closebox(); | |
c6c9630e | 5053 | } |
6e13d0a5 | 5054 | |
b2e75449 MT |
5055 | if ($warnmessage) { |
5056 | &Header::openbox('100%', 'LEFT', $Lang::tr{'warning messages'}); | |
5057 | print "$warnmessage<br>"; | |
5058 | print "$Lang::tr{'fwdfw warn1'}<br>"; | |
5059 | &Header::closebox(); | |
5060 | print"<center><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'ok'}' style='width: 5em;'></form>"; | |
5061 | &Header::closepage(); | |
5062 | exit 0; | |
5063 | } | |
4d81e0f3 | 5064 | |
c6c9630e MT |
5065 | my $sactive = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourred}' width='50%'><tr><td align='center'><b><font color='#FFFFFF'>$Lang::tr{'stopped'}</font></b></td></tr></table>"; |
5066 | my $srunning = "no"; | |
5067 | my $activeonrun = ""; | |
5068 | if ( -e "/var/run/openvpn.pid"){ | |
6e13d0a5 MT |
5069 | $sactive = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourgreen}' width='50%'><tr><td align='center'><b><font color='#FFFFFF'>$Lang::tr{'running'}</font></b></td></tr></table>"; |
5070 | $srunning ="yes"; | |
5071 | $activeonrun = ""; | |
c6c9630e | 5072 | } else { |
6e13d0a5 | 5073 | $activeonrun = "disabled='disabled'"; |
c6c9630e | 5074 | } |
afabe9f7 | 5075 | &Header::openbox('100%', 'LEFT', $Lang::tr{'global settings'}); |
4c962356 | 5076 | print <<END; |
631b67b7 | 5077 | <table width='100%' border='0'> |
c6c9630e MT |
5078 | <form method='post'> |
5079 | <td width='25%'> </td> | |
5080 | <td width='25%'> </td> | |
5081 | <td width='25%'> </td></tr> | |
5082 | <tr><td class='boldbase'>$Lang::tr{'ovpn server status'}</td> | |
5083 | <td align='left'>$sactive</td> | |
5084 | <tr><td class='boldbase'>$Lang::tr{'ovpn on red'}</td> | |
8c877a82 | 5085 | <td><input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td> |
c6c9630e MT |
5086 | END |
5087 | ; | |
5088 | if (&haveBlueNet()) { | |
5089 | print "<tr><td class='boldbase'>$Lang::tr{'ovpn on blue'}</td>"; | |
5090 | print "<td><input type='checkbox' name='ENABLED_BLUE' $checked{'ENABLED_BLUE'}{'on'} /></td>"; | |
5091 | } | |
5092 | if (&haveOrangeNet()) { | |
5093 | print "<tr><td class='boldbase'>$Lang::tr{'ovpn on orange'}</td>"; | |
5094 | print "<td><input type='checkbox' name='ENABLED_ORANGE' $checked{'ENABLED_ORANGE'}{'on'} /></td>"; | |
5095 | } | |
4c962356 | 5096 | print <<END; |
4e17adad CS |
5097 | <tr><td class='base' nowrap='nowrap' colspan='2'>$Lang::tr{'local vpn hostname/ip'}:<br /><input type='text' name='VPN_IP' value='$cgiparams{'VPN_IP'}' size='30' /></td> |
5098 | <td class='boldbase' nowrap='nowrap' colspan='2'>$Lang::tr{'ovpn subnet'}<br /><input type='TEXT' name='DOVPN_SUBNET' value='$cgiparams{'DOVPN_SUBNET'}' size='30' /></td></tr> | |
c6c9630e MT |
5099 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn device'}</td> |
5100 | <td><select name='DDEVICE' ><option value='tun' $selected{'DDEVICE'}{'tun'}>TUN</option> | |
ee79343e JPT |
5101 | <!-- this is still not working |
5102 | <option value='tap' $selected{'DDEVICE'}{'tap'}>TAP</option></select>--> </td> | |
c6c9630e MT |
5103 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td> |
5104 | <td><select name='DPROTOCOL'><option value='udp' $selected{'DPROTOCOL'}{'udp'}>UDP</option> | |
5105 | <option value='tcp' $selected{'DPROTOCOL'}{'tcp'}>TCP</option></select></td> | |
5106 | <td class='boldbase'>$Lang::tr{'destination port'}:</td> | |
5107 | <td><input type='TEXT' name='DDEST_PORT' value='$cgiparams{'DDEST_PORT'}' size='5' /></td></tr> | |
5108 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'} </td> | |
973f711a | 5109 | <td> <input type='TEXT' name='DMTU' VALUE='$cgiparams{'DMTU'}'size='5' /></td> |
4c962356 EK |
5110 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'cipher'}</td> |
5111 | <td><select name='DCIPHER'> | |
5112 | <option value='CAMELLIA-256-CBC' $selected{'DCIPHER'}{'CAMELLIA-256-CBC'}>CAMELLIA-CBC (256 $Lang::tr{'bit'})</option> | |
5113 | <option value='CAMELLIA-192-CBC' $selected{'DCIPHER'}{'CAMELLIA-192-CBC'}>CAMELLIA-CBC (196 $Lang::tr{'bit'})</option> | |
5114 | <option value='CAMELLIA-128-CBC' $selected{'DCIPHER'}{'CAMELLIA-128-CBC'}>CAMELLIA-CBC (128 $Lang::tr{'bit'})</option> | |
5115 | <option value='AES-256-CBC' $selected{'DCIPHER'}{'AES-256-CBC'}>AES-CBC (256 $Lang::tr{'bit'})</option> | |
5116 | <option value='AES-192-CBC' $selected{'DCIPHER'}{'AES-192-CBC'}>AES-CBC (192 $Lang::tr{'bit'})</option> | |
5117 | <option value='AES-128-CBC' $selected{'DCIPHER'}{'AES-128-CBC'}>AES-CBC (128 $Lang::tr{'bit'})</option> | |
5118 | <option value='DES-EDE3-CBC' $selected{'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC (192 $Lang::tr{'bit'})</option> | |
5119 | <option value='DESX-CBC' $selected{'DCIPHER'}{'DESX-CBC'}>DESX-CBC (192 $Lang::tr{'bit'})</option> | |
5120 | <option value='SEED-CBC' $selected{'DCIPHER'}{'SEED-CBC'}>SEED-CBC (128 $Lang::tr{'bit'})</option> | |
5121 | <option value='DES-EDE-CBC' $selected{'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC (128 $Lang::tr{'bit'})</option> | |
5122 | <option value='BF-CBC' $selected{'DCIPHER'}{'BF-CBC'}>BF-CBC (128 $Lang::tr{'bit'})</option> | |
5123 | <option value='CAST5-CBC' $selected{'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC (128 $Lang::tr{'bit'})</option> | |
5124 | <option value='RC2-CBC' $selected{'DCIPHER'}{'RC2-CBC'}>RC2-CBC (128 $Lang::tr{'bit'})</option> | |
5125 | <option value='DES-CBC' $selected{'DCIPHER'}{'DES-CBC'}>DES-CBC (64 $Lang::tr{'bit'} not recommended)</option> | |
5126 | <option value='RC2-64-CBC' $selected{'DCIPHER'}{'RC2-64-CBC'}>RC2-CBC (64 $Lang::tr{'bit'} not recommended)</option> | |
5127 | <option value='RC2-40-CBC' $selected{'DCIPHER'}{'RC2-40-CBC'}>RC2-CBC (40 $Lang::tr{'bit'} not recommended)</option> | |
5128 | </select> | |
5129 | </td> | |
c6c9630e MT |
5130 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td> |
5131 | <td><input type='checkbox' name='DCOMPLZO' $checked{'DCOMPLZO'}{'on'} /></td> | |
4c962356 | 5132 | </tr> |
f7edf97a | 5133 | <tr><td colspan='4'><br><br></td></tr> |
c6c9630e MT |
5134 | END |
5135 | ; | |
5136 | ||
5137 | if ( $srunning eq "yes" ) { | |
8c877a82 AM |
5138 | print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' disabled='disabled' />"; |
5139 | print "<input type='submit' name='ACTION' value='$Lang::tr{'ccd net'}' />"; | |
5140 | print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced server'}' />"; | |
5141 | print "<input type='submit' name='ACTION' value='$Lang::tr{'stop ovpn server'}' /></td></tr>"; | |
c6c9630e | 5142 | } else{ |
8c877a82 AM |
5143 | print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' />"; |
5144 | print "<input type='submit' name='ACTION' value='$Lang::tr{'ccd net'}' />"; | |
5145 | print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced server'}' />"; | |
c6c9630e MT |
5146 | if (( -e "${General::swroot}/ovpn/ca/cacert.pem" && |
5147 | -e "${General::swroot}/ovpn/ca/dh1024.pem" && | |
5148 | -e "${General::swroot}/ovpn/certs/servercert.pem" && | |
5149 | -e "${General::swroot}/ovpn/certs/serverkey.pem") && | |
5150 | (( $cgiparams{'ENABLED'} eq 'on') || | |
5151 | ( $cgiparams{'ENABLED_BLUE'} eq 'on') || | |
5152 | ( $cgiparams{'ENABLED_ORANGE'} eq 'on'))){ | |
8c877a82 | 5153 | print "<input type='submit' name='ACTION' value='$Lang::tr{'start ovpn server'}' /></td></tr>"; |
c6c9630e | 5154 | } else { |
8c877a82 | 5155 | print "<input type='submit' name='ACTION' value='$Lang::tr{'start ovpn server'}' disabled='disabled' /></td></tr>"; |
c6c9630e MT |
5156 | } |
5157 | } | |
5158 | print "</form></table>"; | |
5159 | &Header::closebox(); | |
6e13d0a5 | 5160 | |
c6c9630e | 5161 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) { |
ce9abb66 | 5162 | ### |
7c1d9faf | 5163 | # m.a.d net2net |
54fd0535 | 5164 | #<td width='25%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b><br /><img src='/images/null.gif' width='125' height='1' border='0' alt='L2089' /></td> |
ce9abb66 AH |
5165 | ### |
5166 | ||
4c962356 EK |
5167 | &Header::openbox('100%', 'LEFT', $Lang::tr{'connection status and controlc' }); |
5168 | print <<END; | |
ce9abb66 AH |
5169 | |
5170 | ||
99bfa85c | 5171 | <table width='100%' cellspacing='1' cellpadding='0' class='tbl'> |
c6c9630e | 5172 | <tr> |
99bfa85c AM |
5173 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th> |
5174 | <th width='15%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></th> | |
5175 | <th width='22%' class='boldbase' align='center'><b>$Lang::tr{'network'}</b></th> | |
5176 | <th width='20%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></th> | |
5177 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></th> | |
5178 | <th width='5%' class='boldbase' colspan='6' align='center'><b>$Lang::tr{'action'}</b></th> | |
c6c9630e | 5179 | </tr> |
6e13d0a5 | 5180 | END |
c6c9630e | 5181 | ; |
99bfa85c AM |
5182 | my $id = 0; |
5183 | my $gif; | |
f7edf97a | 5184 | my $col1=""; |
99bfa85c | 5185 | foreach my $key (sort { ncmp ($confighash{$a}[1],$confighash{$b}[1]) } keys %confighash) { |
eff2dbf8 | 5186 | if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; } |
c6c9630e | 5187 | if ($id % 2) { |
99bfa85c AM |
5188 | print "<tr>"; |
5189 | $col="bgcolor='$color{'color20'}'"; | |
bb89e92a | 5190 | } else { |
99bfa85c AM |
5191 | print "<tr>"; |
5192 | $col="bgcolor='$color{'color22'}'"; | |
c6c9630e | 5193 | } |
99bfa85c AM |
5194 | print "<td align='center' nowrap='nowrap' $col>$confighash{$key}[1]</td>"; |
5195 | print "<td align='center' nowrap='nowrap' $col>" . $Lang::tr{"$confighash{$key}[3]"} . " (" . $Lang::tr{"$confighash{$key}[4]"} . ")</td>"; | |
8c877a82 AM |
5196 | #if ($confighash{$key}[4] eq 'cert') { |
5197 | #print "<td align='left' nowrap='nowrap'>$confighash{$key}[2]</td>"; | |
5198 | #} else { | |
5199 | #print "<td align='left'> </td>"; | |
5200 | #} | |
c6c9630e MT |
5201 | my $cavalid = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem`; |
5202 | $cavalid =~ /Not After : (.*)[\n]/; | |
5203 | $cavalid = $1; | |
8c877a82 AM |
5204 | if ($confighash{$key}[32] eq "" && $confighash{$key}[3] eq 'net' ){$confighash{$key}[32]="net-2-net";} |
5205 | if ($confighash{$key}[32] eq "" && $confighash{$key}[3] eq 'host' ){$confighash{$key}[32]="dynamic";} | |
99bfa85c AM |
5206 | print "<td align='center' $col>$confighash{$key}[32]</td>"; |
5207 | print "<td align='center' $col>$confighash{$key}[25]</td>"; | |
f7edf97a AM |
5208 | $col1="bgcolor='${Header::colourred}'"; |
5209 | my $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b>"; | |
ce9abb66 | 5210 | |
c6c9630e | 5211 | if ($confighash{$key}[0] eq 'off') { |
f7edf97a AM |
5212 | $col1="bgcolor='${Header::colourblue}'"; |
5213 | $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b>"; | |
c6c9630e | 5214 | } else { |
ce9abb66 AH |
5215 | |
5216 | ### | |
7c1d9faf | 5217 | # m.a.d net2net |
f7edf97a AM |
5218 | ### |
5219 | ||
b278daf3 | 5220 | if ($confighash{$key}[3] eq 'net') { |
54fd0535 MT |
5221 | |
5222 | if (-e "/var/run/$confighash{$key}[1]n2n.pid") { | |
5223 | my @output = ""; | |
5224 | my @tustate = ""; | |
5225 | my $tport = $confighash{$key}[22]; | |
5226 | my $tnet = new Net::Telnet ( Timeout=>5, Errmode=>'return', Port=>$tport); | |
5227 | if ($tport ne '') { | |
5228 | $tnet->open('127.0.0.1'); | |
5229 | @output = $tnet->cmd(String => 'state', Prompt => '/(END.*\n|ERROR:.*\n)/'); | |
5230 | @tustate = split(/\,/, $output[1]); | |
5231 | ### | |
5232 | #CONNECTING -- OpenVPN's initial state. | |
5233 | #WAIT -- (Client only) Waiting for initial response from server. | |
5234 | #AUTH -- (Client only) Authenticating with server. | |
5235 | #GET_CONFIG -- (Client only) Downloading configuration options from server. | |
5236 | #ASSIGN_IP -- Assigning IP address to virtual network interface. | |
5237 | #ADD_ROUTES -- Adding routes to system. | |
5238 | #CONNECTED -- Initialization Sequence Completed. | |
5239 | #RECONNECTING -- A restart has occurred. | |
5240 | #EXITING -- A graceful exit is in progress. | |
5241 | #### | |
5242 | ||
4c962356 | 5243 | if ($tustate[1] eq 'CONNECTED') { |
f7edf97a AM |
5244 | $col1="bgcolor='${Header::colourgreen}'"; |
5245 | $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsopen'}</font></b>"; | |
5246 | }else { | |
5247 | $col1="bgcolor='${Header::colourred}'"; | |
5248 | $active = "<b><font color='#FFFFFF'>$tustate[1]</font></b>"; | |
5249 | } | |
54fd0535 | 5250 | } |
54fd0535 | 5251 | } |
f7edf97a AM |
5252 | }else { |
5253 | ||
5254 | my $cn; | |
5255 | my @match = (); | |
5256 | foreach my $line (@status) { | |
5257 | chomp($line); | |
5258 | if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) { | |
5259 | @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line); | |
5260 | if ($match[1] ne "Common Name") { | |
5261 | $cn = $match[1]; | |
5262 | } | |
5263 | $cn =~ s/[_]/ /g; | |
5264 | if ($cn eq "$confighash{$key}[2]") { | |
5265 | $col1="bgcolor='${Header::colourgreen}'"; | |
5266 | $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsopen'}</font></b>"; | |
5267 | } | |
5268 | } | |
5269 | } | |
c6c9630e | 5270 | } |
7c1d9faf | 5271 | } |
ce9abb66 AH |
5272 | |
5273 | ||
4c962356 | 5274 | print <<END; |
f7edf97a | 5275 | <td align='center' $col1>$active</td> |
c6c9630e | 5276 | |
99bfa85c | 5277 | <form method='post' name='frm${key}a'><td align='center' $col> |
96096995 AM |
5278 | <input type='image' name='$Lang::tr{'dl client arch'}' src='/images/openvpn.png' alt='$Lang::tr{'dl client arch'}' title='$Lang::tr{'dl client arch'}' border='0' /> |
5279 | <input type='hidden' name='ACTION' value='$Lang::tr{'dl client arch'}' /> | |
5280 | <input type='hidden' name='KEY' value='$key' /> | |
c6c9630e MT |
5281 | </td></form> |
5282 | END | |
5283 | ; | |
5284 | if ($confighash{$key}[4] eq 'cert') { | |
4c962356 | 5285 | print <<END; |
99bfa85c | 5286 | <form method='post' name='frm${key}b'><td align='center' $col> |
c6c9630e MT |
5287 | <input type='image' name='$Lang::tr{'show certificate'}' src='/images/info.gif' alt='$Lang::tr{'show certificate'}' title='$Lang::tr{'show certificate'}' border='0' /> |
5288 | <input type='hidden' name='ACTION' value='$Lang::tr{'show certificate'}' /> | |
5289 | <input type='hidden' name='KEY' value='$key' /> | |
5290 | </td></form> | |
5291 | END | |
5292 | ; } else { | |
5293 | print "<td> </td>"; | |
5294 | } | |
5295 | if ($confighash{$key}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$key}[1].p12") { | |
4c962356 | 5296 | print <<END; |
99bfa85c | 5297 | <form method='post' name='frm${key}c'><td align='center' $col> |
438dd0cc | 5298 | <input type='image' name='$Lang::tr{'download pkcs12 file'}' src='/images/media-floppy.png' alt='$Lang::tr{'download pkcs12 file'}' title='$Lang::tr{'download pkcs12 file'}' border='0' /> |
c6c9630e MT |
5299 | <input type='hidden' name='ACTION' value='$Lang::tr{'download pkcs12 file'}' /> |
5300 | <input type='hidden' name='KEY' value='$key' /> | |
5301 | </td></form> | |
5302 | END | |
5303 | ; } elsif ($confighash{$key}[4] eq 'cert') { | |
4c962356 | 5304 | print <<END; |
99bfa85c | 5305 | <form method='post' name='frm${key}c'><td align='center' $col> |
438dd0cc | 5306 | <input type='image' name='$Lang::tr{'download certificate'}' src='/images/media-floppy.png' alt='$Lang::tr{'download certificate'}' title='$Lang::tr{'download certificate'}' border='0' /> |
c6c9630e MT |
5307 | <input type='hidden' name='ACTION' value='$Lang::tr{'download certificate'}' /> |
5308 | <input type='hidden' name='KEY' value='$key' /> | |
5309 | </td></form> | |
5310 | END | |
5311 | ; } else { | |
5312 | print "<td> </td>"; | |
5313 | } | |
5314 | print <<END | |
99bfa85c | 5315 | <form method='post' name='frm${key}d'><td align='center' $col> |
c6c9630e MT |
5316 | <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$Lang::tr{'toggle enable disable'}' title='$Lang::tr{'toggle enable disable'}' border='0' /> |
5317 | <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' /> | |
5318 | <input type='hidden' name='KEY' value='$key' /> | |
5319 | </td></form> | |
5320 | ||
99bfa85c | 5321 | <form method='post' name='frm${key}e'><td align='center' $col> |
c6c9630e MT |
5322 | <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' /> |
5323 | <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' width='20' height='20' border='0'/> | |
5324 | <input type='hidden' name='KEY' value='$key' /> | |
5325 | </td></form> | |
99bfa85c | 5326 | <form method='post' name='frm${key}f'><td align='center' $col> |
c6c9630e MT |
5327 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' /> |
5328 | <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' width='20' height='20' border='0' /> | |
5329 | <input type='hidden' name='KEY' value='$key' /> | |
5330 | </td></form> | |
5331 | </tr> | |
5332 | END | |
5333 | ; | |
5334 | $id++; | |
5335 | } | |
5336 | ; | |
5337 | ||
5338 | # If the config file contains entries, print Key to action icons | |
5339 | if ( $id ) { | |
4c962356 | 5340 | print <<END; |
8c877a82 | 5341 | <table border='0'> |
c6c9630e | 5342 | <tr> |
4c962356 EK |
5343 | <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td> |
5344 | <td> <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td> | |
5345 | <td class='base'>$Lang::tr{'click to disable'}</td> | |
5346 | <td> <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td> | |
5347 | <td class='base'>$Lang::tr{'show certificate'}</td> | |
5348 | <td> <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td> | |
5349 | <td class='base'>$Lang::tr{'edit'}</td> | |
5350 | <td> <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td> | |
5351 | <td class='base'>$Lang::tr{'remove'}</td> | |
c6c9630e MT |
5352 | </tr> |
5353 | <tr> | |
4c962356 EK |
5354 | <td> </td> |
5355 | <td> <img src='/images/off.gif' alt='?OFF' /></td> | |
5356 | <td class='base'>$Lang::tr{'click to enable'}</td> | |
5357 | <td> <img src='/images/media-floppy.png' alt='?FLOPPY' /></td> | |
5358 | <td class='base'>$Lang::tr{'download certificate'}</td> | |
5359 | <td> <img src='/images/openvpn.png' alt='?RELOAD'/></td> | |
5360 | <td class='base'>$Lang::tr{'dl client arch'}</td> | |
5361 | </tr> | |
f7edf97a | 5362 | </table><br> |
c6c9630e MT |
5363 | END |
5364 | ; | |
5365 | } | |
5366 | ||
4c962356 | 5367 | print <<END; |
c6c9630e MT |
5368 | <table width='100%'> |
5369 | <form method='post'> | |
4c962356 EK |
5370 | <tr><td align='right'> |
5371 | <input type='submit' name='ACTION' value='$Lang::tr{'add'}' /> | |
5372 | <input type='submit' name='ACTION' value='$Lang::tr{'ovpn con stat'}' $activeonrun /></td> | |
5373 | </tr> | |
c6c9630e MT |
5374 | </form> |
5375 | </table> | |
5376 | END | |
4c962356 EK |
5377 | ; |
5378 | &Header::closebox(); | |
5379 | } | |
5380 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate authorities'}"); | |
5381 | print <<END; | |
5382 | <table width='100%' cellspacing='1' cellpadding='0' class='tbl'> | |
5383 | <tr> | |
5384 | <th width='25%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th> | |
5385 | <th width='65%' class='boldbase' align='center'><b>$Lang::tr{'subject'}</b></th> | |
5386 | <th width='10%' class='boldbase' colspan='3' align='center'><b>$Lang::tr{'action'}</b></th> | |
5387 | </tr> | |
5388 | END | |
5389 | ; | |
5390 | my $col1="bgcolor='$color{'color22'}'"; | |
5391 | my $col2="bgcolor='$color{'color20'}'"; | |
5392 | if (-f "${General::swroot}/ovpn/ca/cacert.pem") { | |
5393 | my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem`; | |
5394 | $casubject =~ /Subject: (.*)[\n]/; | |
5395 | $casubject = $1; | |
5396 | $casubject =~ s+/Email+, E+; | |
5397 | $casubject =~ s/ ST=/ S=/; | |
5398 | print <<END; | |
5399 | <tr> | |
5400 | <td class='base' $col1>$Lang::tr{'root certificate'}</td> | |
5401 | <td class='base' $col1>$casubject</td> | |
5402 | <form method='post' name='frmrootcrta'><td width='3%' align='center' $col1> | |
5403 | <input type='hidden' name='ACTION' value='$Lang::tr{'show root certificate'}' /> | |
5404 | <input type='image' name='$Lang::tr{'edit'}' src='/images/info.gif' alt='$Lang::tr{'show root certificate'}' title='$Lang::tr{'show root certificate'}' width='20' height='20' border='0' /> | |
5405 | </td></form> | |
5406 | <form method='post' name='frmrootcrtb'><td width='3%' align='center' $col1> | |
5407 | <input type='image' name='$Lang::tr{'download root certificate'}' src='/images/media-floppy.png' alt='$Lang::tr{'download root certificate'}' title='$Lang::tr{'download root certificate'}' border='0' /> | |
5408 | <input type='hidden' name='ACTION' value='$Lang::tr{'download root certificate'}' /> | |
5409 | </td></form> | |
5410 | <td width='4%' $col1> </td></tr> | |
5411 | END | |
5412 | ; | |
5413 | } else { | |
5414 | # display rootcert generation buttons | |
5415 | print <<END; | |
5416 | <tr> | |
5417 | <td class='base' $col1>$Lang::tr{'root certificate'}:</td> | |
5418 | <td class='base' $col1>$Lang::tr{'not present'}</td> | |
5419 | <td colspan='3' $col1> </td></tr> | |
5420 | END | |
5421 | ; | |
5422 | } | |
5423 | ||
5424 | if (-f "${General::swroot}/ovpn/certs/servercert.pem") { | |
5425 | my $hostsubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
5426 | $hostsubject =~ /Subject: (.*)[\n]/; | |
5427 | $hostsubject = $1; | |
5428 | $hostsubject =~ s+/Email+, E+; | |
5429 | $hostsubject =~ s/ ST=/ S=/; | |
5430 | ||
5431 | print <<END; | |
5432 | <tr> | |
5433 | <td class='base' $col2>$Lang::tr{'host certificate'}</td> | |
5434 | <td class='base' $col2>$hostsubject</td> | |
5435 | <form method='post' name='frmhostcrta'><td width='3%' align='center' $col2> | |
5436 | <input type='hidden' name='ACTION' value='$Lang::tr{'show host certificate'}' /> | |
5437 | <input type='image' name='$Lang::tr{'show host certificate'}' src='/images/info.gif' alt='$Lang::tr{'show host certificate'}' title='$Lang::tr{'show host certificate'}' width='20' height='20' border='0' /> | |
5438 | </td></form> | |
5439 | <form method='post' name='frmhostcrtb'><td width='3%' align='center' $col2> | |
5440 | <input type='image' name="$Lang::tr{'download host certificate'}" src='/images/media-floppy.png' alt="$Lang::tr{'download host certificate'}" title="$Lang::tr{'download host certificate'}" border='0' /> | |
5441 | <input type='hidden' name='ACTION' value="$Lang::tr{'download host certificate'}" /> | |
5442 | </td></form> | |
5443 | <td width='4%' $col2> </td></tr> | |
5444 | END | |
5445 | ; | |
5446 | } else { | |
5447 | # Nothing | |
5448 | print <<END; | |
5449 | <tr> | |
5450 | <td width='25%' class='base' $col2>$Lang::tr{'host certificate'}:</td> | |
5451 | <td class='base' $col2>$Lang::tr{'not present'}</td> | |
5452 | </td><td colspan='3' $col2> </td></tr> | |
5453 | END | |
5454 | ; | |
5455 | } | |
ce9abb66 | 5456 | |
4c962356 EK |
5457 | if (! -f "${General::swroot}/ovpn/ca/cacert.pem") { |
5458 | print "<tr><td colspan='5' align='center'><form method='post'>"; | |
5459 | print "<input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' />"; | |
5460 | print "</form></td></tr>\n"; | |
5461 | } | |
5462 | ||
5463 | if (keys %cahash > 0) { | |
5464 | foreach my $key (keys %cahash) { | |
5465 | if (($key + 1) % 2) { | |
5466 | print "<tr bgcolor='$color{'color20'}'>\n"; | |
5467 | } else { | |
5468 | print "<tr bgcolor='$color{'color22'}'>\n"; | |
5469 | } | |
5470 | print "<td class='base'>$cahash{$key}[0]</td>\n"; | |
5471 | print "<td class='base'>$cahash{$key}[1]</td>\n"; | |
5472 | print <<END; | |
5473 | <form method='post' name='cafrm${key}a'><td align='center'> | |
5474 | <input type='image' name='$Lang::tr{'show ca certificate'}' src='/images/info.gif' alt='$Lang::tr{'show ca certificate'}' title='$Lang::tr{'show ca certificate'}' border='0' /> | |
5475 | <input type='hidden' name='ACTION' value='$Lang::tr{'show ca certificate'}' /> | |
5476 | <input type='hidden' name='KEY' value='$key' /> | |
5477 | </td></form> | |
5478 | <form method='post' name='cafrm${key}b'><td align='center'> | |
5479 | <input type='image' name='$Lang::tr{'download ca certificate'}' src='/images/media-floppy.png' alt='$Lang::tr{'download ca certificate'}' title='$Lang::tr{'download ca certificate'}' border='0' /> | |
5480 | <input type='hidden' name='ACTION' value='$Lang::tr{'download ca certificate'}' /> | |
5481 | <input type='hidden' name='KEY' value='$key' /> | |
5482 | </td></form> | |
5483 | <form method='post' name='cafrm${key}c'><td align='center'> | |
5484 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove ca certificate'}' /> | |
5485 | <input type='image' name='$Lang::tr{'remove ca certificate'}' src='/images/delete.gif' alt='$Lang::tr{'remove ca certificate'}' title='$Lang::tr{'remove ca certificate'}' width='20' height='20' border='0' /> | |
5486 | <input type='hidden' name='KEY' value='$key' /> | |
5487 | </td></form></tr> | |
5488 | END | |
5489 | ; | |
5490 | } | |
5491 | } | |
5492 | ||
5493 | print "</table>"; | |
5494 | ||
5495 | # If the file contains entries, print Key to action icons | |
5496 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem") { | |
5497 | print <<END; | |
5498 | <table> | |
5499 | <tr> | |
5500 | <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td> | |
5501 | <td> <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td> | |
5502 | <td class='base'>$Lang::tr{'show certificate'}</td> | |
5503 | <td> <img src='/images/media-floppy.png' alt='$Lang::tr{'download certificate'}' /></td> | |
5504 | <td class='base'>$Lang::tr{'download certificate'}</td> | |
5505 | </tr> | |
5506 | </table> | |
5507 | END | |
5508 | ; | |
5509 | } | |
ce9abb66 | 5510 | |
4c962356 EK |
5511 | print <<END |
5512 | <hr size='1'> | |
5513 | <form method='post' enctype='multipart/form-data'> | |
5514 | <table width='100%' border='0'cellspacing='1' cellpadding='0'> | |
5515 | <tr> | |
5516 | <td class='base' nowrap='nowrap'>$Lang::tr{'ca name'}:</td> | |
5517 | <td nowrap='nowrap'><input type='text' name='CA_NAME' value='$cgiparams{'CA_NAME'}' size='15' align='left'/></td> | |
5518 | <td nowrap='nowrap'><input type='file' name='FH' size='25' /> | |
5519 | <td nowrap='nowrap' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'upload ca certificate'}' /></td> | |
5520 | </tr> | |
5521 | ||
5522 | <tr> | |
49abe7af EK |
5523 | <td class='base' nowrap='nowrap'>$Lang::tr{'ovpn dh upload'}:</td> |
5524 | <td nowrap='nowrap'><size='15' align='left'/></td> | |
4c962356 | 5525 | <td nowrap='nowrap'><input type='file' name='FH' size='25' /> |
49abe7af | 5526 | <td colspan='4' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'upload dh key'}' /></td> |
4c962356 EK |
5527 | </tr> |
5528 | <tr><td colspan='4'><br></td></tr> | |
5529 | <tr> | |
5530 | <td nowrap='nowrap'><input type='submit' name='ACTION' value='$Lang::tr{'generate dh key'}' /></td> | |
5531 | <td colspan='4' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'show dh'}' /></td> | |
5532 | </tr> | |
5533 | ||
5534 | <tr align='right'> | |
5535 | <td colspan='4' align='right' width='80%'><input type='submit' name='ACTION' value='$Lang::tr{'show crl'}' /></td> | |
5536 | </tr> | |
5537 | </table> | |
5538 | END | |
5539 | ; | |
5540 | ||
5541 | if ( $srunning eq "yes" ) { | |
5542 | print "<div align='center'><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' disabled='disabled' /></div></form>\n"; | |
5543 | } else { | |
5544 | print "<div align='center'><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' /></div></form>\n"; | |
5545 | } | |
5546 | &Header::closebox(); | |
5547 | END | |
5548 | ; | |
5549 | ||
5550 | &Header::closepage(); | |
ce9abb66 | 5551 |