]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl | |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2007-2013 IPFire Team <info@ipfire.org> # | |
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 | ############################################################################### | |
21 | ### | |
22 | # Based on IPFireCore 55 | |
23 | ### | |
24 | use CGI; | |
25 | use CGI qw/:standard/; | |
26 | use Net::DNS; | |
27 | use Net::Ping; | |
28 | use Net::Telnet; | |
29 | use File::Copy; | |
30 | use File::Temp qw/ tempfile tempdir /; | |
31 | use strict; | |
32 | use Archive::Zip qw(:ERROR_CODES :CONSTANTS); | |
33 | require '/var/ipfire/general-functions.pl'; | |
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 | |
39 | #use warnings; | |
40 | #use CGI::Carp 'fatalsToBrowser'; | |
41 | #workaround to suppress a warning when a variable is used only once | |
42 | my @dummy = ( ${Header::colourgreen}, ${Header::colourblue} ); | |
43 | undef (@dummy); | |
44 | ||
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); | |
49 | ||
50 | ### | |
51 | ### Initialize variables | |
52 | ### | |
53 | my %ccdconfhash=(); | |
54 | my %ccdroutehash=(); | |
55 | my %ccdroute2hash=(); | |
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=(); | |
66 | my $routes_push_file = ''; | |
67 | my $confighost="${General::swroot}/fwhosts/customhosts"; | |
68 | my $configgrp="${General::swroot}/fwhosts/customgroups"; | |
69 | my $customnet="${General::swroot}/fwhosts/customnetworks"; | |
70 | my $name; | |
71 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); | |
72 | $cgiparams{'ENABLED'} = 'off'; | |
73 | $cgiparams{'ENABLED_BLUE'} = 'off'; | |
74 | $cgiparams{'ENABLED_ORANGE'} = 'off'; | |
75 | $cgiparams{'EDIT_ADVANCED'} = 'off'; | |
76 | $cgiparams{'NAT'} = 'off'; | |
77 | $cgiparams{'COMPRESSION'} = 'off'; | |
78 | $cgiparams{'ONLY_PROPOSED'} = 'off'; | |
79 | $cgiparams{'ACTION'} = ''; | |
80 | $cgiparams{'CA_NAME'} = ''; | |
81 | $cgiparams{'DHCP_DOMAIN'} = ''; | |
82 | $cgiparams{'DHCP_DNS'} = ''; | |
83 | $cgiparams{'DHCP_WINS'} = ''; | |
84 | $cgiparams{'ROUTES_PUSH'} = ''; | |
85 | $cgiparams{'DCOMPLZO'} = 'off'; | |
86 | $cgiparams{'MSSFIX'} = ''; | |
87 | $cgiparams{'number'} = ''; | |
88 | $cgiparams{'PMTU_DISCOVERY'} = ''; | |
89 | $routes_push_file = "${General::swroot}/ovpn/routes_push"; | |
90 | unless (-e $routes_push_file) { system("touch $routes_push_file"); } | |
91 | unless (-e "${General::swroot}/ovpn/ccd.conf") { system("touch ${General::swroot}/ovpn/ccd.conf"); } | |
92 | unless (-e "${General::swroot}/ovpn/ccdroute") { system("touch ${General::swroot}/ovpn/ccdroute"); } | |
93 | unless (-e "${General::swroot}/ovpn/ccdroute2") { system("touch ${General::swroot}/ovpn/ccdroute2"); } | |
94 | ||
95 | &Header::getcgihash(\%cgiparams, {'wantfile' => 1, 'filevar' => 'FH'}); | |
96 | ||
97 | # prepare openvpn config file | |
98 | ### | |
99 | ### Useful functions | |
100 | ### | |
101 | sub haveOrangeNet | |
102 | { | |
103 | if ($netsettings{'CONFIG_TYPE'} == 2) {return 1;} | |
104 | if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;} | |
105 | return 0; | |
106 | } | |
107 | ||
108 | sub haveBlueNet | |
109 | { | |
110 | if ($netsettings{'CONFIG_TYPE'} == 3) {return 1;} | |
111 | if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;} | |
112 | return 0; | |
113 | } | |
114 | ||
115 | sub sizeformat{ | |
116 | my $bytesize = shift; | |
117 | my $i = 0; | |
118 | ||
119 | while(abs($bytesize) >= 1024){ | |
120 | $bytesize=$bytesize/1024; | |
121 | $i++; | |
122 | last if($i==6); | |
123 | } | |
124 | ||
125 | my @units = ("Bytes","KB","MB","GB","TB","PB","EB"); | |
126 | my $newsize=(int($bytesize*100 +0.5))/100; | |
127 | return("$newsize $units[$i]"); | |
128 | } | |
129 | ||
130 | sub valid_dns_host { | |
131 | my $hostname = $_[0]; | |
132 | unless ($hostname) { return "No hostname"}; | |
133 | my $res = new Net::DNS::Resolver; | |
134 | my $query = $res->search("$hostname"); | |
135 | if ($query) { | |
136 | foreach my $rr ($query->answer) { | |
137 | ## Potential bug - we are only looking at A records: | |
138 | return 0 if $rr->type eq "A"; | |
139 | } | |
140 | } else { | |
141 | return $res->errorstring; | |
142 | } | |
143 | } | |
144 | ||
145 | sub cleanssldatabase | |
146 | { | |
147 | if (open(FILE, ">${General::swroot}/ovpn/certs/serial")) { | |
148 | print FILE "01"; | |
149 | close FILE; | |
150 | } | |
151 | if (open(FILE, ">${General::swroot}/ovpn/certs/index.txt")) { | |
152 | print FILE ""; | |
153 | close FILE; | |
154 | } | |
155 | unlink ("${General::swroot}/ovpn/certs/index.txt.old"); | |
156 | unlink ("${General::swroot}/ovpn/certs/serial.old"); | |
157 | unlink ("${General::swroot}/ovpn/certs/01.pem"); | |
158 | } | |
159 | ||
160 | sub newcleanssldatabase | |
161 | { | |
162 | if (! -s "${General::swroot}/ovpn/certs/serial" ) { | |
163 | open(FILE, ">${General::swroot}(ovpn/certs/serial"); | |
164 | print FILE "01"; | |
165 | close FILE; | |
166 | } | |
167 | if (! -s ">${General::swroot}/ovpn/certs/index.txt") { | |
168 | system ("touch ${General::swroot}/ovpn/certs/index.txt"); | |
169 | } | |
170 | unlink ("${General::swroot}/ovpn/certs/index.txt.old"); | |
171 | unlink ("${General::swroot}/ovpn/certs/serial.old"); | |
172 | } | |
173 | ||
174 | sub deletebackupcert | |
175 | { | |
176 | if (open(FILE, "${General::swroot}/ovpn/certs/serial.old")) { | |
177 | my $hexvalue = <FILE>; | |
178 | chomp $hexvalue; | |
179 | close FILE; | |
180 | unlink ("${General::swroot}/ovpn/certs/$hexvalue.pem"); | |
181 | } | |
182 | } | |
183 | ||
184 | sub checkportfw { | |
185 | my $KEY2 = $_[0]; # key2 | |
186 | my $SRC_PORT = $_[1]; # src_port | |
187 | my $PROTOCOL = $_[2]; # protocol | |
188 | my $SRC_IP = $_[3]; # sourceip | |
189 | ||
190 | my $pfwfilename = "${General::swroot}/portfw/config"; | |
191 | open(FILE, $pfwfilename) or die 'Unable to open config file.'; | |
192 | my @pfwcurrent = <FILE>; | |
193 | close(FILE); | |
194 | my $pfwkey1 = 0; # used for finding last sequence number used | |
195 | foreach my $pfwline (@pfwcurrent) | |
196 | { | |
197 | my @pfwtemp = split(/\,/,$pfwline); | |
198 | ||
199 | chomp ($pfwtemp[8]); | |
200 | if ($KEY2 eq "0"){ # if key2 is 0 then it is a portfw addition | |
201 | if ( $SRC_PORT eq $pfwtemp[3] && | |
202 | $PROTOCOL eq $pfwtemp[2] && | |
203 | $SRC_IP eq $pfwtemp[7]) | |
204 | { | |
205 | $errormessage = "$Lang::tr{'source port in use'} $SRC_PORT"; | |
206 | } | |
207 | # Check if key2 = 0, if it is then it is a port forward entry and we want the sequence number | |
208 | if ( $pfwtemp[1] eq "0") { | |
209 | $pfwkey1=$pfwtemp[0]; | |
210 | } | |
211 | # Darren Critchley - Duplicate or overlapping Port range check | |
212 | if ($pfwtemp[1] eq "0" && | |
213 | $PROTOCOL eq $pfwtemp[2] && | |
214 | $SRC_IP eq $pfwtemp[7] && | |
215 | $errormessage eq '') | |
216 | { | |
217 | &portchecks($SRC_PORT, $pfwtemp[5]); | |
218 | # &portchecks($pfwtemp[3], $pfwtemp[5]); | |
219 | # &portchecks($pfwtemp[3], $SRC_IP); | |
220 | } | |
221 | } | |
222 | } | |
223 | # $errormessage="$KEY2 $SRC_PORT $PROTOCOL $SRC_IP"; | |
224 | ||
225 | return; | |
226 | } | |
227 | ||
228 | sub checkportoverlap | |
229 | { | |
230 | my $portrange1 = $_[0]; # New port range | |
231 | my $portrange2 = $_[1]; # existing port range | |
232 | my @tempr1 = split(/\:/,$portrange1); | |
233 | my @tempr2 = split(/\:/,$portrange2); | |
234 | ||
235 | unless (&checkportinc($tempr1[0], $portrange2)){ return 0;} | |
236 | unless (&checkportinc($tempr1[1], $portrange2)){ return 0;} | |
237 | ||
238 | unless (&checkportinc($tempr2[0], $portrange1)){ return 0;} | |
239 | unless (&checkportinc($tempr2[1], $portrange1)){ return 0;} | |
240 | ||
241 | return 1; # Everything checks out! | |
242 | } | |
243 | ||
244 | # Darren Critchley - we want to make sure that a port entry is not within an already existing range | |
245 | sub checkportinc | |
246 | { | |
247 | my $port1 = $_[0]; # Port | |
248 | my $portrange2 = $_[1]; # Port range | |
249 | my @tempr1 = split(/\:/,$portrange2); | |
250 | ||
251 | if ($port1 < $tempr1[0] || $port1 > $tempr1[1]) { | |
252 | return 1; | |
253 | } else { | |
254 | return 0; | |
255 | } | |
256 | } | |
257 | # Darren Critchley - Duplicate or overlapping Port range check | |
258 | sub portchecks | |
259 | { | |
260 | my $p1 = $_[0]; # New port range | |
261 | my $p2 = $_[1]; # existing port range | |
262 | # $_ = $_[0]; | |
263 | our ($prtrange1, $prtrange2); | |
264 | $prtrange1 = 0; | |
265 | # if (m/:/ && $prtrange1 == 1) { # comparing two port ranges | |
266 | # unless (&checkportoverlap($p1,$p2)) { | |
267 | # $errormessage = "$Lang::tr{'source port overlaps'} $p1"; | |
268 | # } | |
269 | # } | |
270 | if (m/:/ && $prtrange1 == 0 && $errormessage eq '') { # compare one port to a range | |
271 | unless (&checkportinc($p2,$p1)) { | |
272 | $errormessage = "$Lang::tr{'srcprt within existing'} $p1"; | |
273 | } | |
274 | } | |
275 | $prtrange1 = 1; | |
276 | if (! m/:/ && $prtrange1 == 1 && $errormessage eq '') { # compare one port to a range | |
277 | unless (&checkportinc($p1,$p2)) { | |
278 | $errormessage = "$Lang::tr{'srcprt range overlaps'} $p2"; | |
279 | } | |
280 | } | |
281 | return; | |
282 | } | |
283 | ||
284 | # Darren Critchley - certain ports are reserved for IPFire | |
285 | # TCP 67,68,81,222,445 | |
286 | # UDP 67,68 | |
287 | # Params passed in -> port, rangeyn, protocol | |
288 | sub disallowreserved | |
289 | { | |
290 | # port 67 and 68 same for tcp and udp, don't bother putting in an array | |
291 | my $msg = ""; | |
292 | my @tcp_reserved = (81,222,445); | |
293 | my $prt = $_[0]; # the port or range | |
294 | my $ryn = $_[1]; # tells us whether or not it is a port range | |
295 | my $prot = $_[2]; # protocol | |
296 | my $srcdst = $_[3]; # source or destination | |
297 | if ($ryn) { # disect port range | |
298 | if ($srcdst eq "src") { | |
299 | $msg = "$Lang::tr{'rsvd src port overlap'}"; | |
300 | } else { | |
301 | $msg = "$Lang::tr{'rsvd dst port overlap'}"; | |
302 | } | |
303 | my @tmprng = split(/\:/,$prt); | |
304 | unless (67 < $tmprng[0] || 67 > $tmprng[1]) { $errormessage="$msg 67"; return; } | |
305 | unless (68 < $tmprng[0] || 68 > $tmprng[1]) { $errormessage="$msg 68"; return; } | |
306 | if ($prot eq "tcp") { | |
307 | foreach my $prange (@tcp_reserved) { | |
308 | unless ($prange < $tmprng[0] || $prange > $tmprng[1]) { $errormessage="$msg $prange"; return; } | |
309 | } | |
310 | } | |
311 | } else { | |
312 | if ($srcdst eq "src") { | |
313 | $msg = "$Lang::tr{'reserved src port'}"; | |
314 | } else { | |
315 | $msg = "$Lang::tr{'reserved dst port'}"; | |
316 | } | |
317 | if ($prt == 67) { $errormessage="$msg 67"; return; } | |
318 | if ($prt == 68) { $errormessage="$msg 68"; return; } | |
319 | if ($prot eq "tcp") { | |
320 | foreach my $prange (@tcp_reserved) { | |
321 | if ($prange == $prt) { $errormessage="$msg $prange"; return; } | |
322 | } | |
323 | } | |
324 | } | |
325 | return; | |
326 | } | |
327 | ||
328 | sub writeserverconf { | |
329 | my %sovpnsettings = (); | |
330 | my @temp = (); | |
331 | &General::readhash("${General::swroot}/ovpn/settings", \%sovpnsettings); | |
332 | &read_routepushfile; | |
333 | ||
334 | open(CONF, ">${General::swroot}/ovpn/server.conf") or die "Unable to open ${General::swroot}/ovpn/server.conf: $!"; | |
335 | flock CONF, 2; | |
336 | print CONF "#OpenVPN Server conf\n"; | |
337 | print CONF "\n"; | |
338 | print CONF "daemon openvpnserver\n"; | |
339 | print CONF "writepid /var/run/openvpn.pid\n"; | |
340 | print CONF "#DAN prepare OpenVPN for listening on blue and orange\n"; | |
341 | print CONF ";local $sovpnsettings{'VPN_IP'}\n"; | |
342 | print CONF "dev $sovpnsettings{'DDEVICE'}\n"; | |
343 | print CONF "proto $sovpnsettings{'DPROTOCOL'}\n"; | |
344 | print CONF "port $sovpnsettings{'DDEST_PORT'}\n"; | |
345 | print CONF "script-security 3 system\n"; | |
346 | print CONF "ifconfig-pool-persist /var/ipfire/ovpn/ovpn-leases.db 3600\n"; | |
347 | print CONF "client-config-dir /var/ipfire/ovpn/ccd\n"; | |
348 | print CONF "tls-server\n"; | |
349 | print CONF "ca /var/ipfire/ovpn/ca/cacert.pem\n"; | |
350 | print CONF "cert /var/ipfire/ovpn/certs/servercert.pem\n"; | |
351 | print CONF "key /var/ipfire/ovpn/certs/serverkey.pem\n"; | |
352 | print CONF "dh /var/ipfire/ovpn/ca/dh1024.pem\n"; | |
353 | my @tempovpnsubnet = split("\/",$sovpnsettings{'DOVPN_SUBNET'}); | |
354 | print CONF "server $tempovpnsubnet[0] $tempovpnsubnet[1]\n"; | |
355 | #print CONF "push \"route $netsettings{'GREEN_NETADDRESS'} $netsettings{'GREEN_NETMASK'}\"\n"; | |
356 | ||
357 | # Check if we are using mssfix, fragment or mtu-disc and set the corretct mtu of 1500. | |
358 | # If we doesn't use one of them, we can use the configured mtu value. | |
359 | if ($sovpnsettings{'MSSFIX'} eq 'on') | |
360 | { print CONF "$sovpnsettings{'DDEVICE'}-mtu 1500\n"; } | |
361 | elsif ($sovpnsettings{'FRAGMENT'} ne '' && $sovpnsettings{'DPROTOCOL'} ne 'tcp') | |
362 | { print CONF "$sovpnsettings{'DDEVICE'}-mtu 1500\n"; } | |
363 | elsif (($sovpnsettings{'PMTU_DISCOVERY'} eq 'yes') || | |
364 | ($sovpnsettings{'PMTU_DISCOVERY'} eq 'maybe') || | |
365 | ($sovpnsettings{'PMTU_DISCOVERY'} eq 'no' )) | |
366 | { print CONF "$sovpnsettings{'DDEVICE'}-mtu 1500\n"; } | |
367 | else | |
368 | { print CONF "$sovpnsettings{'DDEVICE'}-mtu $sovpnsettings{'DMTU'}\n"; } | |
369 | ||
370 | if ($vpnsettings{'ROUTES_PUSH'} ne '') { | |
371 | @temp = split(/\n/,$vpnsettings{'ROUTES_PUSH'}); | |
372 | foreach (@temp) | |
373 | { | |
374 | @tempovpnsubnet = split("\/",&General::ipcidr2msk($_)); | |
375 | print CONF "push \"route " . $tempovpnsubnet[0]. " " . $tempovpnsubnet[1] . "\"\n"; | |
376 | } | |
377 | } | |
378 | # a.marx ccd | |
379 | my %ccdconfhash=(); | |
380 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
381 | foreach my $key (keys %ccdconfhash) { | |
382 | my $a=$ccdconfhash{$key}[1]; | |
383 | my ($b,$c) = split (/\//, $a); | |
384 | print CONF "route $b ".&General::cidrtosub($c)."\n"; | |
385 | } | |
386 | my %ccdroutehash=(); | |
387 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
388 | foreach my $key (keys %ccdroutehash) { | |
389 | foreach my $i ( 1 .. $#{$ccdroutehash{$key}}){ | |
390 | my ($a,$b)=split (/\//,$ccdroutehash{$key}[$i]); | |
391 | print CONF "route $a $b\n"; | |
392 | } | |
393 | } | |
394 | # ccd end | |
395 | ||
396 | if ($sovpnsettings{CLIENT2CLIENT} eq 'on') { | |
397 | print CONF "client-to-client\n"; | |
398 | } | |
399 | if ($sovpnsettings{MSSFIX} eq 'on') { | |
400 | print CONF "mssfix\n"; | |
401 | } | |
402 | if ($sovpnsettings{FRAGMENT} ne '' && $sovpnsettings{'DPROTOCOL'} ne 'tcp') { | |
403 | print CONF "fragment $sovpnsettings{'FRAGMENT'}\n"; | |
404 | } | |
405 | ||
406 | # Check if a valid operating mode has been choosen and use it. | |
407 | if (($sovpnsettings{'PMTU_DISCOVERY'} eq 'yes') || | |
408 | ($sovpnsettings{'PMTU_DISCOVERY'} eq 'maybe') || | |
409 | ($sovpnsettings{'PMTU_DISCOVERY'} eq 'no' )) { | |
410 | print CONF "mtu-disc $sovpnsettings{'PMTU_DISCOVERY'}\n"; | |
411 | } | |
412 | ||
413 | if ($sovpnsettings{KEEPALIVE_1} > 0 && $sovpnsettings{KEEPALIVE_2} > 0) { | |
414 | print CONF "keepalive $sovpnsettings{'KEEPALIVE_1'} $sovpnsettings{'KEEPALIVE_2'}\n"; | |
415 | } | |
416 | print CONF "status-version 1\n"; | |
417 | print CONF "status /var/log/ovpnserver.log 30\n"; | |
418 | print CONF "cipher $sovpnsettings{DCIPHER}\n"; | |
419 | if ($sovpnsettings{DCOMPLZO} eq 'on') { | |
420 | print CONF "comp-lzo\n"; | |
421 | } | |
422 | if ($sovpnsettings{REDIRECT_GW_DEF1} eq 'on') { | |
423 | print CONF "push \"redirect-gateway def1\"\n"; | |
424 | } | |
425 | if ($sovpnsettings{DHCP_DOMAIN} ne '') { | |
426 | print CONF "push \"dhcp-option DOMAIN $sovpnsettings{DHCP_DOMAIN}\"\n"; | |
427 | } | |
428 | ||
429 | if ($sovpnsettings{DHCP_DNS} ne '') { | |
430 | print CONF "push \"dhcp-option DNS $sovpnsettings{DHCP_DNS}\"\n"; | |
431 | } | |
432 | ||
433 | if ($sovpnsettings{DHCP_WINS} ne '') { | |
434 | print CONF "push \"dhcp-option WINS $sovpnsettings{DHCP_WINS}\"\n"; | |
435 | } | |
436 | ||
437 | if ($sovpnsettings{DHCP_WINS} eq '') { | |
438 | print CONF "max-clients 100\n"; | |
439 | } | |
440 | if ($sovpnsettings{DHCP_WINS} ne '') { | |
441 | print CONF "max-clients $sovpnsettings{MAX_CLIENTS}\n"; | |
442 | } | |
443 | print CONF "tls-verify /var/ipfire/ovpn/verify\n"; | |
444 | print CONF "crl-verify /var/ipfire/ovpn/crls/cacrl.pem\n"; | |
445 | print CONF "user nobody\n"; | |
446 | print CONF "group nobody\n"; | |
447 | print CONF "persist-key\n"; | |
448 | print CONF "persist-tun\n"; | |
449 | if ($sovpnsettings{LOG_VERB} ne '') { | |
450 | print CONF "verb $sovpnsettings{LOG_VERB}\n"; | |
451 | } else { | |
452 | print CONF "verb 3\n"; | |
453 | } | |
454 | print CONF "\n"; | |
455 | ||
456 | close(CONF); | |
457 | } | |
458 | ||
459 | sub emptyserverlog{ | |
460 | if (open(FILE, ">/var/log/ovpnserver.log")) { | |
461 | flock FILE, 2; | |
462 | print FILE ""; | |
463 | close FILE; | |
464 | } | |
465 | ||
466 | } | |
467 | ||
468 | sub delccdnet | |
469 | { | |
470 | my %ccdconfhash = (); | |
471 | my %ccdhash = (); | |
472 | my $ccdnetname=$_[0]; | |
473 | if (-f "${General::swroot}/ovpn/ovpnconfig"){ | |
474 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
475 | foreach my $key (keys %ccdhash) { | |
476 | if ($ccdhash{$key}[32] eq $ccdnetname) { | |
477 | $errormessage=$Lang::tr{'ccd err hostinnet'}; | |
478 | return; | |
479 | } | |
480 | } | |
481 | } | |
482 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
483 | foreach my $key (keys %ccdconfhash) { | |
484 | if ($ccdconfhash{$key}[0] eq $ccdnetname){ | |
485 | delete $ccdconfhash{$key}; | |
486 | } | |
487 | } | |
488 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
489 | ||
490 | &writeserverconf; | |
491 | return 0; | |
492 | } | |
493 | ||
494 | sub addccdnet | |
495 | { | |
496 | my %ccdconfhash=(); | |
497 | my @ccdconf=(); | |
498 | my $ccdname=$_[0]; | |
499 | my $ccdnet=$_[1]; | |
500 | my $subcidr; | |
501 | my @ip2=(); | |
502 | my $checkup; | |
503 | my $ccdip; | |
504 | my $baseaddress; | |
505 | ||
506 | ||
507 | #check name | |
508 | if ($ccdname eq '') | |
509 | { | |
510 | $errormessage=$errormessage.$Lang::tr{'ccd err name'}."<br>"; | |
511 | return | |
512 | } | |
513 | ||
514 | if(!&General::validhostname($ccdname)) | |
515 | { | |
516 | $errormessage=$Lang::tr{'ccd err invalidname'}; | |
517 | return; | |
518 | } | |
519 | ||
520 | ($ccdip,$subcidr) = split (/\//,$ccdnet); | |
521 | $subcidr=&General::iporsubtocidr($subcidr); | |
522 | #check subnet | |
523 | if ($subcidr > 30) | |
524 | { | |
525 | $errormessage=$Lang::tr{'ccd err invalidnet'}; | |
526 | return; | |
527 | } | |
528 | #check ip | |
529 | if (!&General::validipandmask($ccdnet)){ | |
530 | $errormessage=$Lang::tr{'ccd err invalidnet'}; | |
531 | return; | |
532 | } | |
533 | ||
534 | $errormessage=&General::checksubnets($ccdname,$ccdnet); | |
535 | ||
536 | ||
537 | if (!$errormessage) { | |
538 | my %ccdconfhash=(); | |
539 | $baseaddress=&General::getnetworkip($ccdip,$subcidr); | |
540 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
541 | my $key = &General::findhasharraykey (\%ccdconfhash); | |
542 | foreach my $i (0 .. 1) { $ccdconfhash{$key}[$i] = "";} | |
543 | $ccdconfhash{$key}[0] = $ccdname; | |
544 | $ccdconfhash{$key}[1] = $baseaddress."/".$subcidr; | |
545 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
546 | &writeserverconf; | |
547 | $cgiparams{'ccdname'}=''; | |
548 | $cgiparams{'ccdsubnet'}=''; | |
549 | return 1; | |
550 | } | |
551 | } | |
552 | ||
553 | sub modccdnet | |
554 | { | |
555 | ||
556 | my $newname=$_[0]; | |
557 | my $oldname=$_[1]; | |
558 | my %ccdconfhash=(); | |
559 | my %ccdhash=(); | |
560 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
561 | foreach my $key (keys %ccdconfhash) { | |
562 | if ($ccdconfhash{$key}[0] eq $oldname) { | |
563 | foreach my $key1 (keys %ccdconfhash) { | |
564 | if ($ccdconfhash{$key1}[0] eq $newname){ | |
565 | $errormessage=$errormessage.$Lang::tr{'ccd err netadrexist'}; | |
566 | return; | |
567 | }else{ | |
568 | $ccdconfhash{$key}[0]= $newname; | |
569 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
570 | last; | |
571 | } | |
572 | } | |
573 | } | |
574 | } | |
575 | ||
576 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
577 | foreach my $key (keys %ccdhash) { | |
578 | if ($ccdhash{$key}[32] eq $oldname) { | |
579 | $ccdhash{$key}[32]=$newname; | |
580 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
581 | last; | |
582 | } | |
583 | } | |
584 | ||
585 | return 0; | |
586 | } | |
587 | sub ccdmaxclients | |
588 | { | |
589 | my $ccdnetwork=$_[0]; | |
590 | my @octets=(); | |
591 | my @subnet=(); | |
592 | @octets=split("\/",$ccdnetwork); | |
593 | @subnet= split /\./, &General::cidrtosub($octets[1]); | |
594 | my ($a,$b,$c,$d,$e); | |
595 | $a=256-$subnet[0]; | |
596 | $b=256-$subnet[1]; | |
597 | $c=256-$subnet[2]; | |
598 | $d=256-$subnet[3]; | |
599 | $e=($a*$b*$c*$d)/4; | |
600 | return $e-1; | |
601 | } | |
602 | ||
603 | sub getccdadresses | |
604 | { | |
605 | my $ipin=$_[0]; | |
606 | my ($ip1,$ip2,$ip3,$ip4)=split /\./, $ipin; | |
607 | my $cidr=$_[1]; | |
608 | chomp($cidr); | |
609 | my $count=$_[2]; | |
610 | my $hasip=$_[3]; | |
611 | chomp($hasip); | |
612 | my @iprange=(); | |
613 | my %ccdhash=(); | |
614 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
615 | $iprange[0]=$ip1.".".$ip2.".".$ip3.".".2; | |
616 | for (my $i=1;$i<=$count;$i++) { | |
617 | my $tmpip=$iprange[$i-1]; | |
618 | my $stepper=$i*4; | |
619 | $iprange[$i]= &General::getnextip($tmpip,4); | |
620 | } | |
621 | my $r=0; | |
622 | foreach my $key (keys %ccdhash) { | |
623 | $r=0; | |
624 | foreach my $tmp (@iprange){ | |
625 | my ($net,$sub) = split (/\//,$ccdhash{$key}[33]); | |
626 | if ($net eq $tmp) { | |
627 | if ( $hasip ne $ccdhash{$key}[33] ){ | |
628 | splice (@iprange,$r,1); | |
629 | } | |
630 | } | |
631 | $r++; | |
632 | } | |
633 | } | |
634 | return @iprange; | |
635 | } | |
636 | ||
637 | sub fillselectbox | |
638 | { | |
639 | my $boxname=$_[1]; | |
640 | my ($ccdip,$subcidr) = split("/",$_[0]); | |
641 | my $tz=$_[2]; | |
642 | my @allccdips=&getccdadresses($ccdip,$subcidr,&ccdmaxclients($ccdip."/".$subcidr),$tz); | |
643 | print"<select name='$boxname' STYLE='font-family : arial; font-size : 9pt; width:130px;' >"; | |
644 | foreach (@allccdips) { | |
645 | my $ip=$_."/30"; | |
646 | chomp($ip); | |
647 | print "<option value='$ip' "; | |
648 | if ( $ip eq $cgiparams{$boxname} ){ | |
649 | print"selected"; | |
650 | } | |
651 | print ">$ip</option>"; | |
652 | } | |
653 | print "</select>"; | |
654 | } | |
655 | ||
656 | sub hostsinnet | |
657 | { | |
658 | my $name=$_[0]; | |
659 | my %ccdhash=(); | |
660 | my $i=0; | |
661 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
662 | foreach my $key (keys %ccdhash) { | |
663 | if ($ccdhash{$key}[32] eq $name){ $i++;} | |
664 | } | |
665 | return $i; | |
666 | } | |
667 | ||
668 | sub check_routes_push | |
669 | { | |
670 | my $val=$_[0]; | |
671 | my ($ip,$cidr) = split (/\//, $val); | |
672 | ##check for existing routes in routes_push | |
673 | if (-e "${General::swroot}/ovpn/routes_push") { | |
674 | open(FILE,"${General::swroot}/ovpn/routes_push"); | |
675 | while (<FILE>) { | |
676 | $_=~s/\s*$//g; | |
677 | ||
678 | my ($ip2,$cidr2) = split (/\//,"$_"); | |
679 | my $val2=$ip2."/".&General::iporsubtodec($cidr2); | |
680 | ||
681 | if($val eq $val2){ | |
682 | return 0; | |
683 | } | |
684 | #subnetcheck | |
685 | if (&General::IpInSubnet ($ip,$ip2,&General::iporsubtodec($cidr2))){ | |
686 | return 0; | |
687 | } | |
688 | }; | |
689 | close(FILE); | |
690 | } | |
691 | return 1; | |
692 | } | |
693 | ||
694 | sub check_ccdroute | |
695 | { | |
696 | my %ccdroutehash=(); | |
697 | my $val=$_[0]; | |
698 | my ($ip,$cidr) = split (/\//, $val); | |
699 | #check for existing routes in ccdroute | |
700 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
701 | foreach my $key (keys %ccdroutehash) { | |
702 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { | |
703 | if (&General::iporsubtodec($val) eq $ccdroutehash{$key}[$i] && $ccdroutehash{$key}[0] ne $cgiparams{'NAME'}){ | |
704 | return 0; | |
705 | } | |
706 | my ($ip2,$cidr2) = split (/\//,$ccdroutehash{$key}[$i]); | |
707 | #subnetcheck | |
708 | if (&General::IpInSubnet ($ip,$ip2,$cidr2)&& $ccdroutehash{$key}[0] ne $cgiparams{'NAME'} ){ | |
709 | return 0; | |
710 | } | |
711 | } | |
712 | } | |
713 | return 1; | |
714 | } | |
715 | sub check_ccdconf | |
716 | { | |
717 | my %ccdconfhash=(); | |
718 | my $val=$_[0]; | |
719 | my ($ip,$cidr) = split (/\//, $val); | |
720 | #check for existing routes in ccdroute | |
721 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
722 | foreach my $key (keys %ccdconfhash) { | |
723 | if (&General::iporsubtocidr($val) eq $ccdconfhash{$key}[1]){ | |
724 | return 0; | |
725 | } | |
726 | my ($ip2,$cidr2) = split (/\//,$ccdconfhash{$key}[1]); | |
727 | #subnetcheck | |
728 | if (&General::IpInSubnet ($ip,$ip2,&General::cidrtosub($cidr2))){ | |
729 | return 0; | |
730 | } | |
731 | ||
732 | } | |
733 | return 1; | |
734 | } | |
735 | ||
736 | ### | |
737 | # m.a.d net2net | |
738 | ### | |
739 | ||
740 | sub validdotmask | |
741 | { | |
742 | my $ipdotmask = $_[0]; | |
743 | if (&General::validip($ipdotmask)) { return 0; } | |
744 | if (!($ipdotmask =~ /^(.*?)\/(.*?)$/)) { } | |
745 | my $mask = $2; | |
746 | if (($mask =~ /\./ )) { return 0; } | |
747 | return 1; | |
748 | } | |
749 | ||
750 | # ------------------------------------------------------------------- | |
751 | ||
752 | sub write_routepushfile | |
753 | { | |
754 | open(FILE, ">$routes_push_file"); | |
755 | flock(FILE, 2); | |
756 | if ($vpnsettings{'ROUTES_PUSH'} ne '') { | |
757 | print FILE $vpnsettings{'ROUTES_PUSH'}; | |
758 | } | |
759 | close(FILE); | |
760 | } | |
761 | ||
762 | sub read_routepushfile | |
763 | { | |
764 | if (-e "$routes_push_file") { | |
765 | open(FILE,"$routes_push_file"); | |
766 | delete $vpnsettings{'ROUTES_PUSH'}; | |
767 | while (<FILE>) { $vpnsettings{'ROUTES_PUSH'} .= $_ }; | |
768 | close(FILE); | |
769 | $cgiparams{'ROUTES_PUSH'} = $vpnsettings{'ROUTES_PUSH'}; | |
770 | ||
771 | } | |
772 | } | |
773 | ||
774 | ||
775 | #hier die refresh page | |
776 | if ( -e "${General::swroot}/ovpn/gencanow") { | |
777 | my $refresh = ''; | |
778 | $refresh = "<meta http-equiv='refresh' content='15;' />"; | |
779 | &Header::showhttpheaders(); | |
780 | &Header::openpage($Lang::tr{'OVPN'}, 1, $refresh); | |
781 | &Header::openbigbox('100%', 'center'); | |
782 | &Header::openbox('100%', 'left', "$Lang::tr{'generate root/host certificates'}:"); | |
783 | print "<tr>\n<td align='center'><img src='/images/clock.gif' alt='' /></td>\n"; | |
784 | print "<td colspan='2'><font color='red'>Please be patient this realy can take some time on older hardware...</font></td></tr>\n"; | |
785 | &Header::closebox(); | |
786 | &Header::closebigbox(); | |
787 | &Header::closepage(); | |
788 | exit (0); | |
789 | } | |
790 | ##hier die refresh page | |
791 | ||
792 | ||
793 | ### | |
794 | ### OpenVPN Server Control | |
795 | ### | |
796 | if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'} || | |
797 | $cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'} || | |
798 | $cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}) { | |
799 | #start openvpn server | |
800 | if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'}){ | |
801 | &emptyserverlog(); | |
802 | system('/usr/local/bin/openvpnctrl', '-s'); | |
803 | } | |
804 | #stop openvpn server | |
805 | if ($cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'}){ | |
806 | system('/usr/local/bin/openvpnctrl', '-k'); | |
807 | &emptyserverlog(); | |
808 | } | |
809 | # #restart openvpn server | |
810 | # if ($cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}){ | |
811 | #workarund, till SIGHUP also works when running as nobody | |
812 | # system('/usr/local/bin/openvpnctrl', '-r'); | |
813 | # &emptyserverlog(); | |
814 | # } | |
815 | } | |
816 | ||
817 | ### | |
818 | ### Save Advanced options | |
819 | ### | |
820 | ||
821 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save-adv-options'}) { | |
822 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
823 | #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too, | |
824 | #DAN this value has to leave. | |
825 | #new settings for daemon | |
826 | $vpnsettings{'LOG_VERB'} = $cgiparams{'LOG_VERB'}; | |
827 | $vpnsettings{'KEEPALIVE_1'} = $cgiparams{'KEEPALIVE_1'}; | |
828 | $vpnsettings{'KEEPALIVE_2'} = $cgiparams{'KEEPALIVE_2'}; | |
829 | $vpnsettings{'MAX_CLIENTS'} = $cgiparams{'MAX_CLIENTS'}; | |
830 | $vpnsettings{'REDIRECT_GW_DEF1'} = $cgiparams{'REDIRECT_GW_DEF1'}; | |
831 | $vpnsettings{'CLIENT2CLIENT'} = $cgiparams{'CLIENT2CLIENT'}; | |
832 | $vpnsettings{'DHCP_DOMAIN'} = $cgiparams{'DHCP_DOMAIN'}; | |
833 | $vpnsettings{'DHCP_DNS'} = $cgiparams{'DHCP_DNS'}; | |
834 | $vpnsettings{'DHCP_WINS'} = $cgiparams{'DHCP_WINS'}; | |
835 | $vpnsettings{'ROUTES_PUSH'} = $cgiparams{'ROUTES_PUSH'}; | |
836 | $vpnsettings{'PMTU_DISCOVERY'} = $cgiparams{'PMTU_DISCOVERY'}; | |
837 | my @temp=(); | |
838 | ||
839 | if ($cgiparams{'FRAGMENT'} eq '') { | |
840 | delete $vpnsettings{'FRAGMENT'}; | |
841 | } else { | |
842 | if ($cgiparams{'FRAGMENT'} !~ /^[0-9]+$/) { | |
843 | $errormessage = "Incorrect value, please insert only numbers."; | |
844 | goto ADV_ERROR; | |
845 | } else { | |
846 | $vpnsettings{'FRAGMENT'} = $cgiparams{'FRAGMENT'}; | |
847 | } | |
848 | } | |
849 | if ($cgiparams{'MSSFIX'} ne 'on') { | |
850 | delete $vpnsettings{'MSSFIX'}; | |
851 | } else { | |
852 | $vpnsettings{'MSSFIX'} = $cgiparams{'MSSFIX'}; | |
853 | } | |
854 | ||
855 | if (($cgiparams{'PMTU_DISCOVERY'} eq 'yes') || | |
856 | ($cgiparams{'PMTU_DISCOVERY'} eq 'maybe') || | |
857 | ($cgiparams{'PMTU_DISCOVERY'} eq 'no' )) { | |
858 | ||
859 | if (($cgiparams{'MSSFIX'} eq 'on') || ($cgiparams{'FRAGMENT'} ne '')) { | |
860 | $errormessage = $Lang::tr{'ovpn mtu-disc with mssfix or fragment'}; | |
861 | goto ADV_ERROR; | |
862 | } | |
863 | } | |
864 | ||
865 | if ($cgiparams{'DHCP_DOMAIN'} ne ''){ | |
866 | unless (&General::validdomainname($cgiparams{'DHCP_DOMAIN'}) || &General::validip($cgiparams{'DHCP_DOMAIN'})) { | |
867 | $errormessage = $Lang::tr{'invalid input for dhcp domain'}; | |
868 | goto ADV_ERROR; | |
869 | } | |
870 | } | |
871 | if ($cgiparams{'DHCP_DNS'} ne ''){ | |
872 | unless (&General::validfqdn($cgiparams{'DHCP_DNS'}) || &General::validip($cgiparams{'DHCP_DNS'})) { | |
873 | $errormessage = $Lang::tr{'invalid input for dhcp dns'}; | |
874 | goto ADV_ERROR; | |
875 | } | |
876 | } | |
877 | if ($cgiparams{'DHCP_WINS'} ne ''){ | |
878 | unless (&General::validfqdn($cgiparams{'DHCP_WINS'}) || &General::validip($cgiparams{'DHCP_WINS'})) { | |
879 | $errormessage = $Lang::tr{'invalid input for dhcp wins'}; | |
880 | goto ADV_ERROR; | |
881 | } | |
882 | } | |
883 | if ($cgiparams{'ROUTES_PUSH'} ne ''){ | |
884 | @temp = split(/\n/,$cgiparams{'ROUTES_PUSH'}); | |
885 | undef $vpnsettings{'ROUTES_PUSH'}; | |
886 | ||
887 | foreach my $tmpip (@temp) | |
888 | { | |
889 | s/^\s+//g; s/\s+$//g; | |
890 | ||
891 | if ($tmpip) | |
892 | { | |
893 | $tmpip=~s/\s*$//g; | |
894 | unless (&General::validipandmask($tmpip)) { | |
895 | $errormessage = "$tmpip ".$Lang::tr{'ovpn errmsg invalid ip or mask'}; | |
896 | goto ADV_ERROR; | |
897 | } | |
898 | my ($ip, $cidr) = split("\/",&General::ipcidr2msk($tmpip)); | |
899 | ||
900 | if ($ip eq $netsettings{'GREEN_NETADDRESS'} && $cidr eq $netsettings{'GREEN_NETMASK'}) { | |
901 | $errormessage = $Lang::tr{'ovpn errmsg green already pushed'}; | |
902 | goto ADV_ERROR; | |
903 | } | |
904 | # a.marx ccd | |
905 | my %ccdroutehash=(); | |
906 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
907 | foreach my $key (keys %ccdroutehash) { | |
908 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { | |
909 | if ( $ip."/".$cidr eq $ccdroutehash{$key}[$i] ){ | |
910 | $errormessage="Route $ip\/$cidr ".$Lang::tr{'ccd err inuse'}." $ccdroutehash{$key}[0]" ; | |
911 | goto ADV_ERROR; | |
912 | } | |
913 | my ($ip2,$cidr2) = split(/\//,$ccdroutehash{$key}[$i]); | |
914 | if (&General::IpInSubnet ($ip,$ip2,$cidr2)){ | |
915 | $errormessage="Route $ip\/$cidr ".$Lang::tr{'ccd err inuse'}." $ccdroutehash{$key}[0]" ; | |
916 | goto ADV_ERROR; | |
917 | } | |
918 | } | |
919 | } | |
920 | ||
921 | # ccd end | |
922 | ||
923 | $vpnsettings{'ROUTES_PUSH'} .= $tmpip."\n"; | |
924 | } | |
925 | } | |
926 | &write_routepushfile; | |
927 | undef $vpnsettings{'ROUTES_PUSH'}; | |
928 | } | |
929 | else { | |
930 | undef $vpnsettings{'ROUTES_PUSH'}; | |
931 | &write_routepushfile; | |
932 | } | |
933 | if ((length($cgiparams{'MAX_CLIENTS'}) == 0) || (($cgiparams{'MAX_CLIENTS'}) < 1 ) || (($cgiparams{'MAX_CLIENTS'}) > 255 )) { | |
934 | $errormessage = $Lang::tr{'invalid input for max clients'}; | |
935 | goto ADV_ERROR; | |
936 | } | |
937 | if ($cgiparams{'KEEPALIVE_1'} ne '') { | |
938 | if ($cgiparams{'KEEPALIVE_1'} !~ /^[0-9]+$/) { | |
939 | $errormessage = $Lang::tr{'invalid input for keepalive 1'}; | |
940 | goto ADV_ERROR; | |
941 | } | |
942 | } | |
943 | if ($cgiparams{'KEEPALIVE_2'} ne ''){ | |
944 | if ($cgiparams{'KEEPALIVE_2'} !~ /^[0-9]+$/) { | |
945 | $errormessage = $Lang::tr{'invalid input for keepalive 2'}; | |
946 | goto ADV_ERROR; | |
947 | } | |
948 | } | |
949 | if ($cgiparams{'KEEPALIVE_2'} < ($cgiparams{'KEEPALIVE_1'} * 2)){ | |
950 | $errormessage = $Lang::tr{'invalid input for keepalive 1:2'}; | |
951 | goto ADV_ERROR; | |
952 | } | |
953 | ||
954 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
955 | &writeserverconf();#hier ok | |
956 | } | |
957 | ||
958 | ### | |
959 | # m.a.d net2net | |
960 | ### | |
961 | ||
962 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'server') | |
963 | { | |
964 | ||
965 | my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'}); | |
966 | my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'}); | |
967 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; | |
968 | my $tunmtu = ''; | |
969 | ||
970 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} | |
971 | unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";} | |
972 | ||
973 | 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: $!"; | |
974 | ||
975 | flock SERVERCONF, 2; | |
976 | print SERVERCONF "# IPFire n2n Open VPN Server Config by ummeegge und m.a.d\n"; | |
977 | print SERVERCONF "\n"; | |
978 | print SERVERCONF "# User Security\n"; | |
979 | print SERVERCONF "user nobody\n"; | |
980 | print SERVERCONF "group nobody\n"; | |
981 | print SERVERCONF "persist-tun\n"; | |
982 | print SERVERCONF "persist-key\n"; | |
983 | print SERVERCONF "script-security 2\n"; | |
984 | print SERVERCONF "# IP/DNS for remote Server Gateway\n"; | |
985 | print SERVERCONF "remote $cgiparams{'REMOTE'}\n"; | |
986 | print SERVERCONF "float\n"; | |
987 | print SERVERCONF "# IP adresses of the VPN Subnet\n"; | |
988 | print SERVERCONF "ifconfig $ovsubnet.1 $ovsubnet.2\n"; | |
989 | print SERVERCONF "# Client Gateway Network\n"; | |
990 | print SERVERCONF "route $remsubnet[0] $remsubnet[1]\n"; | |
991 | print SERVERCONF "# tun Device\n"; | |
992 | print SERVERCONF "dev tun\n"; | |
993 | print SERVERCONF "# Port and Protokol\n"; | |
994 | print SERVERCONF "port $cgiparams{'DEST_PORT'}\n"; | |
995 | ||
996 | if ($cgiparams{'PROTOCOL'} eq 'tcp') { | |
997 | print SERVERCONF "proto tcp-server\n"; | |
998 | print SERVERCONF "# Packet size\n"; | |
999 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}}; | |
1000 | print SERVERCONF "tun-mtu $tunmtu\n"; | |
1001 | } | |
1002 | ||
1003 | if ($cgiparams{'PROTOCOL'} eq 'udp') { | |
1004 | print SERVERCONF "proto udp\n"; | |
1005 | print SERVERCONF "# Paketsize\n"; | |
1006 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1500'} else {$tunmtu = $cgiparams{'MTU'}}; | |
1007 | print SERVERCONF "tun-mtu $tunmtu\n"; | |
1008 | if ($cgiparams{'FRAGMENT'} ne '') {print SERVERCONF "fragment $cgiparams{'FRAGMENT'}\n";} | |
1009 | if ($cgiparams{'MSSFIX'} eq 'on') {print SERVERCONF "mssfix\n"; }; | |
1010 | } | |
1011 | ||
1012 | # Check if a valid operating mode has been choosen and use it. | |
1013 | if (($cgiparams{'PMTU_DISCOVERY'} eq 'yes') || | |
1014 | ($cgiparams{'PMTU_DISCOVERY'} eq 'maybe') || | |
1015 | ($cgiparams{'PMTU_DISCOVERY'} eq 'no' )) { | |
1016 | if(($cgiparams{'MSSFIX'} ne 'on') || ($cgiparams{'FRAGMENT'} eq '')) { | |
1017 | if($cgiparams{'MTU'} eq '1500') { | |
1018 | print SERVERCONF "mtu-disc $cgiparams{'PMTU_DISCOVERY'}\n"; | |
1019 | } | |
1020 | } | |
1021 | } | |
1022 | print SERVERCONF "# Auth. Server\n"; | |
1023 | print SERVERCONF "tls-server\n"; | |
1024 | print SERVERCONF "ca ${General::swroot}/ovpn/ca/cacert.pem\n"; | |
1025 | print SERVERCONF "cert ${General::swroot}/ovpn/certs/servercert.pem\n"; | |
1026 | print SERVERCONF "key ${General::swroot}/ovpn/certs/serverkey.pem\n"; | |
1027 | print SERVERCONF "dh ${General::swroot}/ovpn/ca/dh1024.pem\n"; | |
1028 | print SERVERCONF "# Cipher\n"; | |
1029 | print SERVERCONF "cipher AES-256-CBC\n"; | |
1030 | if ($cgiparams{'COMPLZO'} eq 'on') { | |
1031 | print SERVERCONF "# Enable Compression\n"; | |
1032 | print SERVERCONF "comp-lzo\r\n"; | |
1033 | } | |
1034 | print SERVERCONF "# Debug Level\n"; | |
1035 | print SERVERCONF "verb 3\n"; | |
1036 | print SERVERCONF "# Tunnel check\n"; | |
1037 | print SERVERCONF "keepalive 10 60\n"; | |
1038 | print SERVERCONF "# Start as daemon\n"; | |
1039 | print SERVERCONF "daemon $cgiparams{'NAME'}n2n\n"; | |
1040 | print SERVERCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n"; | |
1041 | print SERVERCONF "# Activate Management Interface and Port\n"; | |
1042 | if ($cgiparams{'OVPN_MGMT'} eq '') {print SERVERCONF "management localhost $cgiparams{'DEST_PORT'}\n"} | |
1043 | else {print SERVERCONF "management localhost $cgiparams{'OVPN_MGMT'}\n"}; | |
1044 | close(SERVERCONF); | |
1045 | ||
1046 | } | |
1047 | ||
1048 | ### | |
1049 | # m.a.d net2net | |
1050 | ### | |
1051 | ||
1052 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'client') | |
1053 | { | |
1054 | my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'}); | |
1055 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; | |
1056 | my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'}); | |
1057 | my $tunmtu = ''; | |
1058 | ||
1059 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} | |
1060 | unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";} | |
1061 | ||
1062 | 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: $!"; | |
1063 | ||
1064 | flock CLIENTCONF, 2; | |
1065 | print CLIENTCONF "# IPFire rewritten n2n Open VPN Client Config by ummeegge und m.a.d\n"; | |
1066 | print CLIENTCONF "#\n"; | |
1067 | print CLIENTCONF "# User Security\n"; | |
1068 | print CLIENTCONF "user nobody\n"; | |
1069 | print CLIENTCONF "group nobody\n"; | |
1070 | print CLIENTCONF "persist-tun\n"; | |
1071 | print CLIENTCONF "persist-key\n"; | |
1072 | print CLIENTCONF "script-security 2\n"; | |
1073 | print CLIENTCONF "# IP/DNS for remote Server Gateway\n"; | |
1074 | print CLIENTCONF "remote $cgiparams{'REMOTE'}\n"; | |
1075 | print CLIENTCONF "float\n"; | |
1076 | print CLIENTCONF "# IP adresses of the VPN Subnet\n"; | |
1077 | print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n"; | |
1078 | print CLIENTCONF "# Server Gateway Network\n"; | |
1079 | print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n"; | |
1080 | print CLIENTCONF "# tun Device\n"; | |
1081 | print CLIENTCONF "dev tun\n"; | |
1082 | print CLIENTCONF "# Port and Protokol\n"; | |
1083 | print CLIENTCONF "port $cgiparams{'DEST_PORT'}\n"; | |
1084 | ||
1085 | if ($cgiparams{'PROTOCOL'} eq 'tcp') { | |
1086 | print CLIENTCONF "proto tcp-client\n"; | |
1087 | print CLIENTCONF "# Packet size\n"; | |
1088 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}}; | |
1089 | print CLIENTCONF "tun-mtu $tunmtu\n"; | |
1090 | } | |
1091 | ||
1092 | if ($cgiparams{'PROTOCOL'} eq 'udp') { | |
1093 | print CLIENTCONF "proto udp\n"; | |
1094 | print CLIENTCONF "# Paketsize\n"; | |
1095 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1500'} else {$tunmtu = $cgiparams{'MTU'}}; | |
1096 | print CLIENTCONF "tun-mtu $tunmtu\n"; | |
1097 | if ($cgiparams{'FRAGMENT'} ne '') {print CLIENTCONF "fragment $cgiparams{'FRAGMENT'}\n";} | |
1098 | if ($cgiparams{'MSSFIX'} eq 'on') {print CLIENTCONF "mssfix\n"; }; | |
1099 | } | |
1100 | ||
1101 | # Check if a valid operating mode has been choosen and use it. | |
1102 | if (($cgiparams{'PMTU_DISCOVERY'} eq 'yes') || | |
1103 | ($cgiparams{'PMTU_DISCOVERY'} eq 'maybe') || | |
1104 | ($cgiparams{'PMTU_DISCOVERY'} eq 'no' )) { | |
1105 | if(($cgiparams{'MSSFIX'} ne 'on') || ($cgiparams{'FRAGMENT'} eq '')) { | |
1106 | if ($cgiparams{'MTU'} eq '1500') { | |
1107 | print CLIENTCONF "mtu-disc $cgiparams{'PMTU_DISCOVERY'}\n"; | |
1108 | } | |
1109 | } | |
1110 | } | |
1111 | ||
1112 | print CLIENTCONF "ns-cert-type server\n"; | |
1113 | print CLIENTCONF "# Auth. Client\n"; | |
1114 | print CLIENTCONF "tls-client\n"; | |
1115 | print CLIENTCONF "# Cipher\n"; | |
1116 | print CLIENTCONF "cipher AES-256-CBC\n"; | |
1117 | print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12\r\n"; | |
1118 | if ($cgiparams{'COMPLZO'} eq 'on') { | |
1119 | print CLIENTCONF "# Enable Compression\n"; | |
1120 | print CLIENTCONF "comp-lzo\r\n"; | |
1121 | } | |
1122 | print CLIENTCONF "# Debug Level\n"; | |
1123 | print CLIENTCONF "verb 3\n"; | |
1124 | print CLIENTCONF "# Tunnel check\n"; | |
1125 | print CLIENTCONF "keepalive 10 60\n"; | |
1126 | print CLIENTCONF "# Start as daemon\n"; | |
1127 | print CLIENTCONF "daemon $cgiparams{'NAME'}n2n\n"; | |
1128 | print CLIENTCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n"; | |
1129 | print CLIENTCONF "# Activate Management Interface and Port\n"; | |
1130 | if ($cgiparams{'OVPN_MGMT'} eq '') {print CLIENTCONF "management localhost $cgiparams{'DEST_PORT'}\n"} | |
1131 | else {print CLIENTCONF "management localhost $cgiparams{'OVPN_MGMT'}\n"}; | |
1132 | close(CLIENTCONF); | |
1133 | ||
1134 | } | |
1135 | ||
1136 | ### | |
1137 | ### Save main settings | |
1138 | ### | |
1139 | ||
1140 | ||
1141 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq '' && $cgiparams{'KEY'} eq '') { | |
1142 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
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'}; | |
1148 | goto SETTINGS_ERROR; | |
1149 | } | |
1150 | } | |
1151 | if ($cgiparams{'ENABLED'} eq 'on'){ | |
1152 | &disallowreserved($cgiparams{'DDEST_PORT'},0,$cgiparams{'DPROTOCOL'},"dest"); | |
1153 | } | |
1154 | if ($errormessage) { goto SETTINGS_ERROR; } | |
1155 | ||
1156 | ||
1157 | if ($cgiparams{'ENABLED'} eq 'on'){ | |
1158 | &checkportfw(0,$cgiparams{'DDEST_PORT'},$cgiparams{'DPROTOCOL'},'0.0.0.0'); | |
1159 | } | |
1160 | ||
1161 | if ($errormessage) { goto SETTINGS_ERROR; } | |
1162 | ||
1163 | if (! &General::validipandmask($cgiparams{'DOVPN_SUBNET'})) { | |
1164 | $errormessage = $Lang::tr{'ovpn subnet is invalid'}; | |
1165 | goto SETTINGS_ERROR; | |
1166 | } | |
1167 | my @tmpovpnsubnet = split("\/",$cgiparams{'DOVPN_SUBNET'}); | |
1168 | ||
1169 | if (&General::IpInSubnet ( $netsettings{'RED_ADDRESS'}, | |
1170 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1171 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire RED Network $netsettings{'RED_ADDRESS'}"; | |
1172 | goto SETTINGS_ERROR; | |
1173 | } | |
1174 | ||
1175 | if (&General::IpInSubnet ( $netsettings{'GREEN_ADDRESS'}, | |
1176 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1177 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Green Network $netsettings{'GREEN_ADDRESS'}"; | |
1178 | goto SETTINGS_ERROR; | |
1179 | } | |
1180 | ||
1181 | if (&General::IpInSubnet ( $netsettings{'BLUE_ADDRESS'}, | |
1182 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1183 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Blue Network $netsettings{'BLUE_ADDRESS'}"; | |
1184 | goto SETTINGS_ERROR; | |
1185 | } | |
1186 | ||
1187 | if (&General::IpInSubnet ( $netsettings{'ORANGE_ADDRESS'}, | |
1188 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1189 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Orange Network $netsettings{'ORANGE_ADDRESS'}"; | |
1190 | goto SETTINGS_ERROR; | |
1191 | } | |
1192 | open(ALIASES, "${General::swroot}/ethernet/aliases") or die 'Unable to open aliases file.'; | |
1193 | while (<ALIASES>) | |
1194 | { | |
1195 | chomp($_); | |
1196 | my @tempalias = split(/\,/,$_); | |
1197 | if ($tempalias[1] eq 'on') { | |
1198 | if (&General::IpInSubnet ($tempalias[0] , | |
1199 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1200 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire alias entry $tempalias[0]"; | |
1201 | } | |
1202 | } | |
1203 | } | |
1204 | close(ALIASES); | |
1205 | if ($errormessage ne ''){ | |
1206 | goto SETTINGS_ERROR; | |
1207 | } | |
1208 | if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) { | |
1209 | $errormessage = $Lang::tr{'invalid input'}; | |
1210 | goto SETTINGS_ERROR; | |
1211 | } | |
1212 | if ((length($cgiparams{'DMTU'})==0) || (($cgiparams{'DMTU'}) < 1000 )) { | |
1213 | $errormessage = $Lang::tr{'invalid mtu input'}; | |
1214 | goto SETTINGS_ERROR; | |
1215 | } | |
1216 | ||
1217 | unless (&General::validport($cgiparams{'DDEST_PORT'})) { | |
1218 | $errormessage = $Lang::tr{'invalid port'}; | |
1219 | goto SETTINGS_ERROR; | |
1220 | } | |
1221 | $vpnsettings{'ENABLED_BLUE'} = $cgiparams{'ENABLED_BLUE'}; | |
1222 | $vpnsettings{'ENABLED_ORANGE'} =$cgiparams{'ENABLED_ORANGE'}; | |
1223 | $vpnsettings{'ENABLED'} = $cgiparams{'ENABLED'}; | |
1224 | $vpnsettings{'VPN_IP'} = $cgiparams{'VPN_IP'}; | |
1225 | #new settings for daemon | |
1226 | $vpnsettings{'DOVPN_SUBNET'} = $cgiparams{'DOVPN_SUBNET'}; | |
1227 | $vpnsettings{'DDEVICE'} = $cgiparams{'DDEVICE'}; | |
1228 | $vpnsettings{'DPROTOCOL'} = $cgiparams{'DPROTOCOL'}; | |
1229 | $vpnsettings{'DDEST_PORT'} = $cgiparams{'DDEST_PORT'}; | |
1230 | $vpnsettings{'DMTU'} = $cgiparams{'DMTU'}; | |
1231 | $vpnsettings{'DCOMPLZO'} = $cgiparams{'DCOMPLZO'}; | |
1232 | $vpnsettings{'DCIPHER'} = $cgiparams{'DCIPHER'}; | |
1233 | #wrtie enable | |
1234 | ||
1235 | 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");} | |
1236 | 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");} | |
1237 | if ( $vpnsettings{'ENABLED'} eq 'on' ) {system("touch ${General::swroot}/ovpn/enable 2>/dev/null");}else{system("unlink ${General::swroot}/ovpn/enable 2>/dev/null");} | |
1238 | #new settings for daemon | |
1239 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1240 | &writeserverconf();#hier ok | |
1241 | SETTINGS_ERROR: | |
1242 | ### | |
1243 | ### Reset all step 2 | |
1244 | ### | |
1245 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'reset'} && $cgiparams{'AREUSURE'} eq 'yes') { | |
1246 | my $file = ''; | |
1247 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1248 | ||
1249 | foreach my $key (keys %confighash) { | |
1250 | if ($confighash{$key}[4] eq 'cert') { | |
1251 | delete $confighash{$cgiparams{'$key'}}; | |
1252 | } | |
1253 | } | |
1254 | while ($file = glob("${General::swroot}/ovpn/ca/*")) { | |
1255 | unlink $file | |
1256 | } | |
1257 | while ($file = glob("${General::swroot}/ovpn/certs/*")) { | |
1258 | unlink $file | |
1259 | } | |
1260 | while ($file = glob("${General::swroot}/ovpn/crls/*")) { | |
1261 | unlink $file | |
1262 | } | |
1263 | &cleanssldatabase(); | |
1264 | if (open(FILE, ">${General::swroot}/ovpn/caconfig")) { | |
1265 | print FILE ""; | |
1266 | close FILE; | |
1267 | } | |
1268 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1269 | #&writeserverconf(); | |
1270 | ### | |
1271 | ### Reset all step 1 | |
1272 | ### | |
1273 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'reset'}) { | |
1274 | &Header::showhttpheaders(); | |
1275 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
1276 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
1277 | &Header::openbox('100%', 'LEFT', $Lang::tr{'are you sure'}); | |
1278 | print <<END | |
1279 | <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' /> | |
1280 | <tr><td align='center'> | |
1281 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: | |
1282 | $Lang::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'} | |
1283 | <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'reset'}' /> | |
1284 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td></tr> | |
1285 | </form></table> | |
1286 | END | |
1287 | ; | |
1288 | &Header::closebox(); | |
1289 | &Header::closebigbox(); | |
1290 | &Header::closepage(); | |
1291 | exit (0); | |
1292 | ||
1293 | ### | |
1294 | ### Upload CA Certificate | |
1295 | ### | |
1296 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload ca certificate'}) { | |
1297 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1298 | ||
1299 | if ($cgiparams{'CA_NAME'} !~ /^[a-zA-Z0-9]+$/) { | |
1300 | $errormessage = $Lang::tr{'name must only contain characters'}; | |
1301 | goto UPLOADCA_ERROR; | |
1302 | } | |
1303 | ||
1304 | if (length($cgiparams{'CA_NAME'}) >60) { | |
1305 | $errormessage = $Lang::tr{'name too long'}; | |
1306 | goto VPNCONF_ERROR; | |
1307 | } | |
1308 | ||
1309 | if ($cgiparams{'CA_NAME'} eq 'ca') { | |
1310 | $errormessage = $Lang::tr{'name is invalid'}; | |
1311 | goto UPLOAD_CA_ERROR; | |
1312 | } | |
1313 | ||
1314 | # Check if there is no other entry with this name | |
1315 | foreach my $key (keys %cahash) { | |
1316 | if ($cahash{$key}[0] eq $cgiparams{'CA_NAME'}) { | |
1317 | $errormessage = $Lang::tr{'a ca certificate with this name already exists'}; | |
1318 | goto UPLOADCA_ERROR; | |
1319 | } | |
1320 | } | |
1321 | ||
1322 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
1323 | $errormessage = $Lang::tr{'there was no file upload'}; | |
1324 | goto UPLOADCA_ERROR; | |
1325 | } | |
1326 | # Move uploaded ca to a temporary file | |
1327 | (my $fh, my $filename) = tempfile( ); | |
1328 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
1329 | $errormessage = $!; | |
1330 | goto UPLOADCA_ERROR; | |
1331 | } | |
1332 | my $temp = `/usr/bin/openssl x509 -text -in $filename`; | |
1333 | if ($temp !~ /CA:TRUE/i) { | |
1334 | $errormessage = $Lang::tr{'not a valid ca certificate'}; | |
1335 | unlink ($filename); | |
1336 | goto UPLOADCA_ERROR; | |
1337 | } else { | |
1338 | move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem"); | |
1339 | if ($? ne 0) { | |
1340 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1341 | unlink ($filename); | |
1342 | goto UPLOADCA_ERROR; | |
1343 | } | |
1344 | } | |
1345 | ||
1346 | my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem`; | |
1347 | $casubject =~ /Subject: (.*)[\n]/; | |
1348 | $casubject = $1; | |
1349 | $casubject =~ s+/Email+, E+; | |
1350 | $casubject =~ s/ ST=/ S=/; | |
1351 | $casubject = &Header::cleanhtml($casubject); | |
1352 | ||
1353 | my $key = &General::findhasharraykey (\%cahash); | |
1354 | $cahash{$key}[0] = $cgiparams{'CA_NAME'}; | |
1355 | $cahash{$key}[1] = $casubject; | |
1356 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1357 | # system('/usr/local/bin/ipsecctrl', 'R'); | |
1358 | ||
1359 | UPLOADCA_ERROR: | |
1360 | ||
1361 | ### | |
1362 | ### Display ca certificate | |
1363 | ### | |
1364 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show ca certificate'}) { | |
1365 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1366 | ||
1367 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem") { | |
1368 | &Header::showhttpheaders(); | |
1369 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
1370 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
1371 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ca certificate'}:"); | |
1372 | my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`; | |
1373 | $output = &Header::cleanhtml($output,"y"); | |
1374 | print "<pre>$output</pre>\n"; | |
1375 | &Header::closebox(); | |
1376 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1377 | &Header::closebigbox(); | |
1378 | &Header::closepage(); | |
1379 | exit(0); | |
1380 | } else { | |
1381 | $errormessage = $Lang::tr{'invalid key'}; | |
1382 | } | |
1383 | ||
1384 | ### | |
1385 | ### Download ca certificate | |
1386 | ### | |
1387 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download ca certificate'}) { | |
1388 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1389 | ||
1390 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
1391 | print "Content-Type: application/octet-stream\r\n"; | |
1392 | print "Content-Disposition: filename=$cahash{$cgiparams{'KEY'}}[0]cert.pem\r\n\r\n"; | |
1393 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`; | |
1394 | exit(0); | |
1395 | } else { | |
1396 | $errormessage = $Lang::tr{'invalid key'}; | |
1397 | } | |
1398 | ||
1399 | ### | |
1400 | ### Remove ca certificate (step 2) | |
1401 | ### | |
1402 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'} && $cgiparams{'AREUSURE'} eq 'yes') { | |
1403 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1404 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1405 | ||
1406 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
1407 | foreach my $key (keys %confighash) { | |
1408 | 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`; | |
1409 | if ($test =~ /: OK/) { | |
1410 | # Delete connection | |
1411 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
1412 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
1413 | # system('/usr/local/bin/ipsecctrl', 'D', $key); | |
1414 | # } | |
1415 | unlink ("${General::swroot}/ovpn//certs/$confighash{$key}[1]cert.pem"); | |
1416 | unlink ("${General::swroot}/ovpn/certs/$confighash{$key}[1].p12"); | |
1417 | delete $confighash{$key}; | |
1418 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1419 | # &writeipsecfiles(); | |
1420 | } | |
1421 | } | |
1422 | unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
1423 | delete $cahash{$cgiparams{'KEY'}}; | |
1424 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1425 | # system('/usr/local/bin/ipsecctrl', 'R'); | |
1426 | } else { | |
1427 | $errormessage = $Lang::tr{'invalid key'}; | |
1428 | } | |
1429 | ### | |
1430 | ### Remove ca certificate (step 1) | |
1431 | ### | |
1432 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'}) { | |
1433 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1434 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1435 | ||
1436 | my $assignedcerts = 0; | |
1437 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
1438 | foreach my $key (keys %confighash) { | |
1439 | 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`; | |
1440 | if ($test =~ /: OK/) { | |
1441 | $assignedcerts++; | |
1442 | } | |
1443 | } | |
1444 | if ($assignedcerts) { | |
1445 | &Header::showhttpheaders(); | |
1446 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
1447 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
1448 | &Header::openbox('100%', 'LEFT', $Lang::tr{'are you sure'}); | |
1449 | print <<END | |
1450 | <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' /> | |
1451 | <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' /> | |
1452 | <tr><td align='center'> | |
1453 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: $assignedcerts | |
1454 | $Lang::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'} | |
1455 | <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'remove ca certificate'}' /> | |
1456 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td></tr> | |
1457 | </form></table> | |
1458 | END | |
1459 | ; | |
1460 | &Header::closebox(); | |
1461 | &Header::closebigbox(); | |
1462 | &Header::closepage(); | |
1463 | exit (0); | |
1464 | } else { | |
1465 | unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
1466 | delete $cahash{$cgiparams{'KEY'}}; | |
1467 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1468 | # system('/usr/local/bin/ipsecctrl', 'R'); | |
1469 | } | |
1470 | } else { | |
1471 | $errormessage = $Lang::tr{'invalid key'}; | |
1472 | } | |
1473 | ||
1474 | ### | |
1475 | ### Display root certificate | |
1476 | ### | |
1477 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'} || | |
1478 | $cgiparams{'ACTION'} eq $Lang::tr{'show host certificate'}) { | |
1479 | my $output; | |
1480 | &Header::showhttpheaders(); | |
1481 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
1482 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
1483 | if ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'}) { | |
1484 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'root certificate'}:"); | |
1485 | $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem`; | |
1486 | } else { | |
1487 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'host certificate'}:"); | |
1488 | $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
1489 | } | |
1490 | $output = &Header::cleanhtml($output,"y"); | |
1491 | print "<pre>$output</pre>\n"; | |
1492 | &Header::closebox(); | |
1493 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1494 | &Header::closebigbox(); | |
1495 | &Header::closepage(); | |
1496 | exit(0); | |
1497 | ||
1498 | ### | |
1499 | ### Download root certificate | |
1500 | ### | |
1501 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download root certificate'}) { | |
1502 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) { | |
1503 | print "Content-Type: application/octet-stream\r\n"; | |
1504 | print "Content-Disposition: filename=cacert.pem\r\n\r\n"; | |
1505 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/cacert.pem`; | |
1506 | exit(0); | |
1507 | } | |
1508 | ||
1509 | ### | |
1510 | ### Download host certificate | |
1511 | ### | |
1512 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download host certificate'}) { | |
1513 | if ( -f "${General::swroot}/ovpn/certs/servercert.pem" ) { | |
1514 | print "Content-Type: application/octet-stream\r\n"; | |
1515 | print "Content-Disposition: filename=servercert.pem\r\n\r\n"; | |
1516 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
1517 | exit(0); | |
1518 | } | |
1519 | ### | |
1520 | ### Form for generating a root certificate | |
1521 | ### | |
1522 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate root/host certificates'} || | |
1523 | $cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) { | |
1524 | ||
1525 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1526 | if (-f "${General::swroot}/ovpn/ca/cacert.pem") { | |
1527 | $errormessage = $Lang::tr{'valid root certificate already exists'}; | |
1528 | $cgiparams{'ACTION'} = ''; | |
1529 | goto ROOTCERT_ERROR; | |
1530 | } | |
1531 | ||
1532 | if (($cgiparams{'ROOTCERT_HOSTNAME'} eq '') && -e "${General::swroot}/red/active") { | |
1533 | if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) { | |
1534 | my $ipaddr = <IPADDR>; | |
1535 | close IPADDR; | |
1536 | chomp ($ipaddr); | |
1537 | $cgiparams{'ROOTCERT_HOSTNAME'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0]; | |
1538 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq '') { | |
1539 | $cgiparams{'ROOTCERT_HOSTNAME'} = $ipaddr; | |
1540 | } | |
1541 | } | |
1542 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) { | |
1543 | ||
1544 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
1545 | $errormessage = $Lang::tr{'there was no file upload'}; | |
1546 | goto ROOTCERT_ERROR; | |
1547 | } | |
1548 | ||
1549 | # Move uploaded certificate request to a temporary file | |
1550 | (my $fh, my $filename) = tempfile( ); | |
1551 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
1552 | $errormessage = $!; | |
1553 | goto ROOTCERT_ERROR; | |
1554 | } | |
1555 | ||
1556 | # Create a temporary dirctory | |
1557 | my $tempdir = tempdir( CLEANUP => 1 ); | |
1558 | ||
1559 | # Extract the CA certificate from the file | |
1560 | my $pid = open(OPENSSL, "|-"); | |
1561 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1562 | if ($pid) { # parent | |
1563 | if ($cgiparams{'P12_PASS'} ne '') { | |
1564 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1565 | } | |
1566 | close (OPENSSL); | |
1567 | if ($?) { | |
1568 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1569 | unlink ($filename); | |
1570 | goto ROOTCERT_ERROR; | |
1571 | } | |
1572 | } else { # child | |
1573 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-cacerts', '-nokeys', | |
1574 | '-in', $filename, | |
1575 | '-out', "$tempdir/cacert.pem")) { | |
1576 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1577 | unlink ($filename); | |
1578 | goto ROOTCERT_ERROR; | |
1579 | } | |
1580 | } | |
1581 | ||
1582 | # Extract the Host certificate from the file | |
1583 | $pid = open(OPENSSL, "|-"); | |
1584 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1585 | if ($pid) { # parent | |
1586 | if ($cgiparams{'P12_PASS'} ne '') { | |
1587 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1588 | } | |
1589 | close (OPENSSL); | |
1590 | if ($?) { | |
1591 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1592 | unlink ($filename); | |
1593 | goto ROOTCERT_ERROR; | |
1594 | } | |
1595 | } else { # child | |
1596 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-clcerts', '-nokeys', | |
1597 | '-in', $filename, | |
1598 | '-out', "$tempdir/hostcert.pem")) { | |
1599 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1600 | unlink ($filename); | |
1601 | goto ROOTCERT_ERROR; | |
1602 | } | |
1603 | } | |
1604 | ||
1605 | # Extract the Host key from the file | |
1606 | $pid = open(OPENSSL, "|-"); | |
1607 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1608 | if ($pid) { # parent | |
1609 | if ($cgiparams{'P12_PASS'} ne '') { | |
1610 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1611 | } | |
1612 | close (OPENSSL); | |
1613 | if ($?) { | |
1614 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1615 | unlink ($filename); | |
1616 | goto ROOTCERT_ERROR; | |
1617 | } | |
1618 | } else { # child | |
1619 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-nocerts', | |
1620 | '-nodes', | |
1621 | '-in', $filename, | |
1622 | '-out', "$tempdir/serverkey.pem")) { | |
1623 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1624 | unlink ($filename); | |
1625 | goto ROOTCERT_ERROR; | |
1626 | } | |
1627 | } | |
1628 | ||
1629 | move("$tempdir/cacert.pem", "${General::swroot}/ovpn/ca/cacert.pem"); | |
1630 | if ($? ne 0) { | |
1631 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1632 | unlink ($filename); | |
1633 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1634 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1635 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1636 | goto ROOTCERT_ERROR; | |
1637 | } | |
1638 | ||
1639 | move("$tempdir/hostcert.pem", "${General::swroot}/ovpn/certs/servercert.pem"); | |
1640 | if ($? ne 0) { | |
1641 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1642 | unlink ($filename); | |
1643 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1644 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1645 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1646 | goto ROOTCERT_ERROR; | |
1647 | } | |
1648 | ||
1649 | move("$tempdir/serverkey.pem", "${General::swroot}/ovpn/certs/serverkey.pem"); | |
1650 | if ($? ne 0) { | |
1651 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1652 | unlink ($filename); | |
1653 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1654 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1655 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1656 | goto ROOTCERT_ERROR; | |
1657 | } | |
1658 | ||
1659 | goto ROOTCERT_SUCCESS; | |
1660 | ||
1661 | } elsif ($cgiparams{'ROOTCERT_COUNTRY'} ne '') { | |
1662 | ||
1663 | # Validate input since the form was submitted | |
1664 | if ($cgiparams{'ROOTCERT_ORGANIZATION'} eq ''){ | |
1665 | $errormessage = $Lang::tr{'organization cant be empty'}; | |
1666 | goto ROOTCERT_ERROR; | |
1667 | } | |
1668 | if (length($cgiparams{'ROOTCERT_ORGANIZATION'}) >60) { | |
1669 | $errormessage = $Lang::tr{'organization too long'}; | |
1670 | goto ROOTCERT_ERROR; | |
1671 | } | |
1672 | if ($cgiparams{'ROOTCERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1673 | $errormessage = $Lang::tr{'invalid input for organization'}; | |
1674 | goto ROOTCERT_ERROR; | |
1675 | } | |
1676 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq ''){ | |
1677 | $errormessage = $Lang::tr{'hostname cant be empty'}; | |
1678 | goto ROOTCERT_ERROR; | |
1679 | } | |
1680 | unless (&General::validfqdn($cgiparams{'ROOTCERT_HOSTNAME'}) || &General::validip($cgiparams{'ROOTCERT_HOSTNAME'})) { | |
1681 | $errormessage = $Lang::tr{'invalid input for hostname'}; | |
1682 | goto ROOTCERT_ERROR; | |
1683 | } | |
1684 | if ($cgiparams{'ROOTCERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'ROOTCERT_EMAIL'}))) { | |
1685 | $errormessage = $Lang::tr{'invalid input for e-mail address'}; | |
1686 | goto ROOTCERT_ERROR; | |
1687 | } | |
1688 | if (length($cgiparams{'ROOTCERT_EMAIL'}) > 40) { | |
1689 | $errormessage = $Lang::tr{'e-mail address too long'}; | |
1690 | goto ROOTCERT_ERROR; | |
1691 | } | |
1692 | if ($cgiparams{'ROOTCERT_OU'} ne '' && $cgiparams{'ROOTCERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1693 | $errormessage = $Lang::tr{'invalid input for department'}; | |
1694 | goto ROOTCERT_ERROR; | |
1695 | } | |
1696 | if ($cgiparams{'ROOTCERT_CITY'} ne '' && $cgiparams{'ROOTCERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1697 | $errormessage = $Lang::tr{'invalid input for city'}; | |
1698 | goto ROOTCERT_ERROR; | |
1699 | } | |
1700 | if ($cgiparams{'ROOTCERT_STATE'} ne '' && $cgiparams{'ROOTCERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1701 | $errormessage = $Lang::tr{'invalid input for state or province'}; | |
1702 | goto ROOTCERT_ERROR; | |
1703 | } | |
1704 | if ($cgiparams{'ROOTCERT_COUNTRY'} !~ /^[A-Z]*$/) { | |
1705 | $errormessage = $Lang::tr{'invalid input for country'}; | |
1706 | goto ROOTCERT_ERROR; | |
1707 | } | |
1708 | ||
1709 | # Copy the cgisettings to vpnsettings and save the configfile | |
1710 | $vpnsettings{'ROOTCERT_ORGANIZATION'} = $cgiparams{'ROOTCERT_ORGANIZATION'}; | |
1711 | $vpnsettings{'ROOTCERT_HOSTNAME'} = $cgiparams{'ROOTCERT_HOSTNAME'}; | |
1712 | $vpnsettings{'ROOTCERT_EMAIL'} = $cgiparams{'ROOTCERT_EMAIL'}; | |
1713 | $vpnsettings{'ROOTCERT_OU'} = $cgiparams{'ROOTCERT_OU'}; | |
1714 | $vpnsettings{'ROOTCERT_CITY'} = $cgiparams{'ROOTCERT_CITY'}; | |
1715 | $vpnsettings{'ROOTCERT_STATE'} = $cgiparams{'ROOTCERT_STATE'}; | |
1716 | $vpnsettings{'ROOTCERT_COUNTRY'} = $cgiparams{'ROOTCERT_COUNTRY'}; | |
1717 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1718 | ||
1719 | # Replace empty strings with a . | |
1720 | (my $ou = $cgiparams{'ROOTCERT_OU'}) =~ s/^\s*$/\./; | |
1721 | (my $city = $cgiparams{'ROOTCERT_CITY'}) =~ s/^\s*$/\./; | |
1722 | (my $state = $cgiparams{'ROOTCERT_STATE'}) =~ s/^\s*$/\./; | |
1723 | ||
1724 | # refresh | |
1725 | #system ('/bin/touch', "${General::swroot}/ovpn/gencanow"); | |
1726 | ||
1727 | # Create the CA certificate | |
1728 | my $pid = open(OPENSSL, "|-"); | |
1729 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1730 | if ($pid) { # parent | |
1731 | print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n"; | |
1732 | print OPENSSL "$state\n"; | |
1733 | print OPENSSL "$city\n"; | |
1734 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n"; | |
1735 | print OPENSSL "$ou\n"; | |
1736 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'} CA\n"; | |
1737 | print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n"; | |
1738 | close (OPENSSL); | |
1739 | if ($?) { | |
1740 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1741 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1742 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1743 | goto ROOTCERT_ERROR; | |
1744 | } | |
1745 | } else { # child | |
1746 | unless (exec ('/usr/bin/openssl', 'req', '-x509', '-nodes', '-rand', '/proc/interrupts:/proc/net/rt_cache', | |
1747 | '-days', '999999', '-newkey', 'rsa:2048', | |
1748 | '-keyout', "${General::swroot}/ovpn/ca/cakey.pem", | |
1749 | '-out', "${General::swroot}/ovpn/ca/cacert.pem", | |
1750 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) { | |
1751 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1752 | goto ROOTCERT_ERROR; | |
1753 | } | |
1754 | } | |
1755 | ||
1756 | # Create the Host certificate request | |
1757 | $pid = open(OPENSSL, "|-"); | |
1758 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1759 | if ($pid) { # parent | |
1760 | print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n"; | |
1761 | print OPENSSL "$state\n"; | |
1762 | print OPENSSL "$city\n"; | |
1763 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n"; | |
1764 | print OPENSSL "$ou\n"; | |
1765 | print OPENSSL "$cgiparams{'ROOTCERT_HOSTNAME'}\n"; | |
1766 | print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n"; | |
1767 | print OPENSSL ".\n"; | |
1768 | print OPENSSL ".\n"; | |
1769 | close (OPENSSL); | |
1770 | if ($?) { | |
1771 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1772 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1773 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1774 | goto ROOTCERT_ERROR; | |
1775 | } | |
1776 | } else { # child | |
1777 | unless (exec ('/usr/bin/openssl', 'req', '-nodes', '-rand', '/proc/interrupts:/proc/net/rt_cache', | |
1778 | '-newkey', 'rsa:1024', | |
1779 | '-keyout', "${General::swroot}/ovpn/certs/serverkey.pem", | |
1780 | '-out', "${General::swroot}/ovpn/certs/serverreq.pem", | |
1781 | '-extensions', 'server', | |
1782 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" )) { | |
1783 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1784 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1785 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1786 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1787 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1788 | goto ROOTCERT_ERROR; | |
1789 | } | |
1790 | } | |
1791 | ||
1792 | # Sign the host certificate request | |
1793 | system('/usr/bin/openssl', 'ca', '-days', '999999', | |
1794 | '-batch', '-notext', | |
1795 | '-in', "${General::swroot}/ovpn/certs/serverreq.pem", | |
1796 | '-out', "${General::swroot}/ovpn/certs/servercert.pem", | |
1797 | '-extensions', 'server', | |
1798 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
1799 | if ($?) { | |
1800 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1801 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1802 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1803 | unlink ("${General::swroot}/ovpn/serverkey.pem"); | |
1804 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1805 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1806 | &newcleanssldatabase(); | |
1807 | goto ROOTCERT_ERROR; | |
1808 | } else { | |
1809 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1810 | &deletebackupcert(); | |
1811 | } | |
1812 | ||
1813 | # Create an empty CRL | |
1814 | system('/usr/bin/openssl', 'ca', '-gencrl', | |
1815 | '-out', "${General::swroot}/ovpn/crls/cacrl.pem", | |
1816 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" ); | |
1817 | if ($?) { | |
1818 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1819 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1820 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1821 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1822 | unlink ("${General::swroot}/ovpn/crls/cacrl.pem"); | |
1823 | &cleanssldatabase(); | |
1824 | goto ROOTCERT_ERROR; | |
1825 | # } else { | |
1826 | # &cleanssldatabase(); | |
1827 | } | |
1828 | # Create Diffie Hellmann Parameter | |
1829 | system('/usr/bin/openssl', 'dhparam', '-rand', '/proc/interrupts:/proc/net/rt_cache', | |
1830 | '-out', "${General::swroot}/ovpn/ca/dh1024.pem", | |
1831 | '1024' ); | |
1832 | if ($?) { | |
1833 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1834 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1835 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1836 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1837 | unlink ("${General::swroot}/ovpn/crls/cacrl.pem"); | |
1838 | unlink ("${General::swroot}/ovpn/ca/dh1024.pem"); | |
1839 | &cleanssldatabase(); | |
1840 | goto ROOTCERT_ERROR; | |
1841 | # } else { | |
1842 | # &cleanssldatabase(); | |
1843 | } | |
1844 | goto ROOTCERT_SUCCESS; | |
1845 | } | |
1846 | ROOTCERT_ERROR: | |
1847 | if ($cgiparams{'ACTION'} ne '') { | |
1848 | &Header::showhttpheaders(); | |
1849 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
1850 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
1851 | if ($errormessage) { | |
1852 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
1853 | print "<class name='base'>$errormessage"; | |
1854 | print " </class>"; | |
1855 | &Header::closebox(); | |
1856 | } | |
1857 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'generate root/host certificates'}:"); | |
1858 | print <<END | |
1859 | <form method='post' enctype='multipart/form-data'> | |
1860 | <table width='100%' border='0' cellspacing='1' cellpadding='0'> | |
1861 | <tr><td width='30%' class='base'>$Lang::tr{'organization name'}:</td> | |
1862 | <td width='35%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value='$cgiparams{'ROOTCERT_ORGANIZATION'}' size='32' /></td> | |
1863 | <td width='35%' colspan='2'> </td></tr> | |
1864 | <tr><td class='base'>$Lang::tr{'ipfires hostname'}:</td> | |
1865 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value='$cgiparams{'ROOTCERT_HOSTNAME'}' size='32' /></td> | |
1866 | <td colspan='2'> </td></tr> | |
1867 | <tr><td class='base'>$Lang::tr{'your e-mail'}: <img src='/blob.gif' alt'*' /></td> | |
1868 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value='$cgiparams{'ROOTCERT_EMAIL'}' size='32' /></td> | |
1869 | <td colspan='2'> </td></tr> | |
1870 | <tr><td class='base'>$Lang::tr{'your department'}: <img src='/blob.gif' alt'*' /></td> | |
1871 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value='$cgiparams{'ROOTCERT_OU'}' size='32' /></td> | |
1872 | <td colspan='2'> </td></tr> | |
1873 | <tr><td class='base'>$Lang::tr{'city'}: <img src='/blob.gif' alt'*' /></td> | |
1874 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value='$cgiparams{'ROOTCERT_CITY'}' size='32' /></td> | |
1875 | <td colspan='2'> </td></tr> | |
1876 | <tr><td class='base'>$Lang::tr{'state or province'}: <img src='/blob.gif' alt'*' /></td> | |
1877 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value='$cgiparams{'ROOTCERT_STATE'}' size='32' /></td> | |
1878 | <td colspan='2'> </td></tr> | |
1879 | <tr><td class='base'>$Lang::tr{'country'}:</td> | |
1880 | <td class='base'><select name='ROOTCERT_COUNTRY'> | |
1881 | ||
1882 | END | |
1883 | ; | |
1884 | foreach my $country (sort keys %{Countries::countries}) { | |
1885 | print "<option value='$Countries::countries{$country}'"; | |
1886 | if ( $Countries::countries{$country} eq $cgiparams{'ROOTCERT_COUNTRY'} ) { | |
1887 | print " selected='selected'"; | |
1888 | } | |
1889 | print ">$country</option>"; | |
1890 | } | |
1891 | print <<END | |
1892 | </select></td> | |
1893 | <td colspan='2'> </td></tr> | |
1894 | <tr><td> </td> | |
1895 | <td><input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' /></td> | |
1896 | <td> </td><td> </td></tr> | |
1897 | <tr><td class='base' colspan='4' align='left'> | |
1898 | <img src='/blob.gif' valign='top' alt='*' /> $Lang::tr{'this field may be blank'}</td></tr> | |
1899 | <tr><td class='base' colspan='4' align='left'> | |
1900 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: | |
1901 | $Lang::tr{'generating the root and host certificates may take a long time. it can take up to several minutes on older hardware. please be patient'} | |
1902 | </td></tr> | |
1903 | <tr><td colspan='4' bgcolor='#000000'><img src='/images/null.gif' width='1' height='1' border='0' /></td></tr> | |
1904 | <tr><td class='base' nowrap='nowrap'>$Lang::tr{'upload p12 file'}:</td> | |
1905 | <td nowrap='nowrap'><input type='file' name='FH' size='32'></td> | |
1906 | <td colspan='2'> </td></tr> | |
1907 | <tr><td class='base'>$Lang::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' ></td> | |
1908 | <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value='$cgiparams{'P12_PASS'}' size='32' /></td> | |
1909 | <td colspan='2'> </td></tr> | |
1910 | <tr><td> </td> | |
1911 | <td><input type='submit' name='ACTION' value='$Lang::tr{'upload p12 file'}' /></td> | |
1912 | <td colspan='2'> </td></tr> | |
1913 | <tr><td class='base' colspan='4' align='left'> | |
1914 | <img src='/blob.gif' valign='top' al='*' > $Lang::tr{'this field may be blank'}</td></tr> | |
1915 | </form></table> | |
1916 | END | |
1917 | ; | |
1918 | &Header::closebox(); | |
1919 | ||
1920 | &Header::closebigbox(); | |
1921 | &Header::closepage(); | |
1922 | exit(0) | |
1923 | } | |
1924 | ||
1925 | ROOTCERT_SUCCESS: | |
1926 | system ("chmod 600 ${General::swroot}/ovpn/certs/serverkey.pem"); | |
1927 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
1928 | # $vpnsettings{'ENABLE_BLUE'} eq 'on') { | |
1929 | # system('/usr/local/bin/ipsecctrl', 'S'); | |
1930 | # } | |
1931 | ||
1932 | ### | |
1933 | ### Enable/Disable connection | |
1934 | ### | |
1935 | ||
1936 | ### | |
1937 | # m.a.d net2net | |
1938 | ### | |
1939 | ||
1940 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { | |
1941 | ||
1942 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1943 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1944 | # my $n2nactive = ''; | |
1945 | my $n2nactive = `/bin/ps ax|grep $confighash{$cgiparams{'KEY'}}[1]|grep -v grep|awk \'{print \$1}\'`; | |
1946 | ||
1947 | if ($confighash{$cgiparams{'KEY'}}) { | |
1948 | if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') { | |
1949 | $confighash{$cgiparams{'KEY'}}[0] = 'on'; | |
1950 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1951 | ||
1952 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ | |
1953 | system('/usr/local/bin/openvpnctrl', '-sn2n', $confighash{$cgiparams{'KEY'}}[1]); | |
1954 | } | |
1955 | } else { | |
1956 | ||
1957 | $confighash{$cgiparams{'KEY'}}[0] = 'off'; | |
1958 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1959 | ||
1960 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ | |
1961 | if ($n2nactive ne ''){ | |
1962 | system('/usr/local/bin/openvpnctrl', '-kn2n', $confighash{$cgiparams{'KEY'}}[1]); | |
1963 | } | |
1964 | ||
1965 | } else { | |
1966 | $errormessage = $Lang::tr{'invalid key'}; | |
1967 | } | |
1968 | } | |
1969 | } | |
1970 | ||
1971 | ### | |
1972 | ### Download OpenVPN client package | |
1973 | ### | |
1974 | ||
1975 | ||
1976 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'dl client arch'}) { | |
1977 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1978 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1979 | my $file = ''; | |
1980 | my $clientovpn = ''; | |
1981 | my @fileholder; | |
1982 | my $tempdir = tempdir( CLEANUP => 1 ); | |
1983 | my $zippath = "$tempdir/"; | |
1984 | ||
1985 | ### | |
1986 | # m.a.d net2net | |
1987 | ### | |
1988 | ||
1989 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ | |
1990 | ||
1991 | my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-Client.zip"; | |
1992 | my $zippathname = "$zippath$zipname"; | |
1993 | $clientovpn = "$confighash{$cgiparams{'KEY'}}[1].conf"; | |
1994 | my @ovsubnettemp = split(/\./,$confighash{$cgiparams{'KEY'}}[27]); | |
1995 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; | |
1996 | my $tunmtu = ''; | |
1997 | my @remsubnet = split(/\//,$confighash{$cgiparams{'KEY'}}[8]); | |
1998 | my $n2nfragment = ''; | |
1999 | ||
2000 | open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!"; | |
2001 | flock CLIENTCONF, 2; | |
2002 | ||
2003 | my $zip = Archive::Zip->new(); | |
2004 | print CLIENTCONF "# IPFire n2n Open VPN Client Config by ummeegge und m.a.d\n"; | |
2005 | print CLIENTCONF "# \n"; | |
2006 | print CLIENTCONF "# User Security\n"; | |
2007 | print CLIENTCONF "user nobody\n"; | |
2008 | print CLIENTCONF "group nobody\n"; | |
2009 | print CLIENTCONF "persist-tun\n"; | |
2010 | print CLIENTCONF "persist-key\n"; | |
2011 | print CLIENTCONF "script-security 2\n"; | |
2012 | print CLIENTCONF "# IP/DNS for remote Server Gateway\n"; | |
2013 | print CLIENTCONF "remote $vpnsettings{'VPN_IP'}\n"; | |
2014 | print CLIENTCONF "float\n"; | |
2015 | print CLIENTCONF "# IP adresses of the VPN Subnet\n"; | |
2016 | print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n"; | |
2017 | print CLIENTCONF "# Server Gateway Network\n"; | |
2018 | print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n"; | |
2019 | print CLIENTCONF "# tun Device\n"; | |
2020 | print CLIENTCONF "dev $vpnsettings{'DDEVICE'}\n"; | |
2021 | print CLIENTCONF "# Port and Protokoll\n"; | |
2022 | print CLIENTCONF "port $confighash{$cgiparams{'KEY'}}[29]\n"; | |
2023 | ||
2024 | if ($confighash{$cgiparams{'KEY'}}[28] eq 'tcp') { | |
2025 | print CLIENTCONF "proto tcp-client\n"; | |
2026 | print CLIENTCONF "# Packet size\n"; | |
2027 | if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1400'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]}; | |
2028 | print CLIENTCONF "tun-mtu $tunmtu\n"; | |
2029 | } | |
2030 | ||
2031 | if ($confighash{$cgiparams{'KEY'}}[28] eq 'udp') { | |
2032 | print CLIENTCONF "proto udp\n"; | |
2033 | print CLIENTCONF "# Paketsize\n"; | |
2034 | if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1500'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]}; | |
2035 | print CLIENTCONF "tun-mtu $tunmtu\n"; | |
2036 | if ($confighash{$cgiparams{'KEY'}}[24] ne '') {print CLIENTCONF "fragment $confighash{$cgiparams{'KEY'}}[24]\n";} | |
2037 | if ($confighash{$cgiparams{'KEY'}}[23] eq 'on') {print CLIENTCONF "mssfix\n";} | |
2038 | } | |
2039 | if (($confighash{$cgiparams{'KEY'}}[38] eq 'yes') || | |
2040 | ($confighash{$cgiparams{'KEY'}}[38] eq 'maybe') || | |
2041 | ($confighash{$cgiparams{'KEY'}}[38] eq 'no' )) { | |
2042 | if (($confighash{$cgiparams{'KEY'}}[23] ne 'on') || ($confighash{$cgiparams{'KEY'}}[24] eq '')) { | |
2043 | if ($tunmtu eq '1500' ) { | |
2044 | print CLIENTCONF "mtu-disc $confighash{$cgiparams{'KEY'}}[38]\n"; | |
2045 | } | |
2046 | } | |
2047 | } | |
2048 | print CLIENTCONF "ns-cert-type server\n"; | |
2049 | print CLIENTCONF "# Auth. Client\n"; | |
2050 | print CLIENTCONF "tls-client\n"; | |
2051 | print CLIENTCONF "# Cipher\n"; | |
2052 | print CLIENTCONF "cipher AES-256-CBC\n"; | |
2053 | if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") { | |
2054 | print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12\r\n"; | |
2055 | $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"; | |
2056 | } | |
2057 | if ($confighash{$cgiparams{'KEY'}}[30] eq 'on') { | |
2058 | print CLIENTCONF "# Enable Compression\n"; | |
2059 | print CLIENTCONF "comp-lzo\r\n"; | |
2060 | } | |
2061 | print CLIENTCONF "# Debug Level\n"; | |
2062 | print CLIENTCONF "verb 3\n"; | |
2063 | print CLIENTCONF "# Tunnel check\n"; | |
2064 | print CLIENTCONF "keepalive 10 60\n"; | |
2065 | print CLIENTCONF "# Start as daemon\n"; | |
2066 | print CLIENTCONF "daemon $confighash{$cgiparams{'KEY'}}[1]n2n\n"; | |
2067 | print CLIENTCONF "writepid /var/run/$confighash{$cgiparams{'KEY'}}[1]n2n.pid\n"; | |
2068 | print CLIENTCONF "# Activate Management Interface and Port\n"; | |
2069 | if ($confighash{$cgiparams{'KEY'}}[22] eq '') {print CLIENTCONF "management localhost $confighash{$cgiparams{'KEY'}}[29]\n"} | |
2070 | else {print CLIENTCONF "management localhost $confighash{$cgiparams{'KEY'}}[22]\n"}; | |
2071 | print CLIENTCONF "# remsub $confighash{$cgiparams{'KEY'}}[11]\n"; | |
2072 | ||
2073 | ||
2074 | close(CLIENTCONF); | |
2075 | ||
2076 | $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n"; | |
2077 | my $status = $zip->writeToFileNamed($zippathname); | |
2078 | ||
2079 | open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!"; | |
2080 | @fileholder = <DLFILE>; | |
2081 | print "Content-Type:application/x-download\n"; | |
2082 | print "Content-Disposition:attachment;filename=$zipname\n\n"; | |
2083 | print @fileholder; | |
2084 | exit (0); | |
2085 | } | |
2086 | else | |
2087 | { | |
2088 | my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.zip"; | |
2089 | my $zippathname = "$zippath$zipname"; | |
2090 | $clientovpn = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.ovpn"; | |
2091 | ||
2092 | ### | |
2093 | # m.a.d net2net | |
2094 | ### | |
2095 | ||
2096 | open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!"; | |
2097 | flock CLIENTCONF, 2; | |
2098 | ||
2099 | my $zip = Archive::Zip->new(); | |
2100 | ||
2101 | print CLIENTCONF "#OpenVPN Client conf\r\n"; | |
2102 | print CLIENTCONF "tls-client\r\n"; | |
2103 | print CLIENTCONF "client\r\n"; | |
2104 | print CLIENTCONF "nobind\r\n"; | |
2105 | print CLIENTCONF "dev $vpnsettings{'DDEVICE'}\r\n"; | |
2106 | print CLIENTCONF "proto $vpnsettings{'DPROTOCOL'}\r\n"; | |
2107 | ||
2108 | # Check if we are using fragment, mssfix or mtu-disc and set MTU to 1500 | |
2109 | # or use configured value. | |
2110 | if ($vpnsettings{FRAGMENT} ne '' && $vpnsettings{DPROTOCOL} ne 'tcp' ) | |
2111 | { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu 1500\r\n"; } | |
2112 | elsif ($vpnsettings{MSSFIX} eq 'on') | |
2113 | { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu 1500\r\n"; } | |
2114 | elsif (($vpnsettings{'PMTU_DISCOVERY'} eq 'yes') || | |
2115 | ($vpnsettings{'PMTU_DISCOVERY'} eq 'maybe') || | |
2116 | ($vpnsettings{'PMTU_DISCOVERY'} eq 'no' )) | |
2117 | { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu 1500\r\n"; } | |
2118 | else | |
2119 | { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu $vpnsettings{'DMTU'}\r\n"; } | |
2120 | ||
2121 | if ( $vpnsettings{'ENABLED'} eq 'on'){ | |
2122 | print CLIENTCONF "remote $vpnsettings{'VPN_IP'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2123 | if ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){ | |
2124 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Blue interface\r\n"; | |
2125 | print CLIENTCONF ";remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2126 | } | |
2127 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
2128 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n"; | |
2129 | print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2130 | } | |
2131 | } elsif ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){ | |
2132 | print CLIENTCONF "remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2133 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
2134 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n"; | |
2135 | print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2136 | } | |
2137 | } elsif ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
2138 | print CLIENTCONF "remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2139 | } | |
2140 | ||
2141 | if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") { | |
2142 | print CLIENTCONF "pkcs12 $confighash{$cgiparams{'KEY'}}[1].p12\r\n"; | |
2143 | $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"; | |
2144 | } else { | |
2145 | print CLIENTCONF "ca cacert.pem\r\n"; | |
2146 | print CLIENTCONF "cert $confighash{$cgiparams{'KEY'}}[1]cert.pem\r\n"; | |
2147 | print CLIENTCONF "key $confighash{$cgiparams{'KEY'}}[1].key\r\n"; | |
2148 | $zip->addFile( "${General::swroot}/ovpn/ca/cacert.pem", "cacert.pem") or die "Can't add file cacert.pem\n"; | |
2149 | $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"; | |
2150 | } | |
2151 | print CLIENTCONF "cipher $vpnsettings{DCIPHER}\r\n"; | |
2152 | if ($vpnsettings{DCOMPLZO} eq 'on') { | |
2153 | print CLIENTCONF "comp-lzo\r\n"; | |
2154 | } | |
2155 | print CLIENTCONF "verb 3\r\n"; | |
2156 | print CLIENTCONF "ns-cert-type server\r\n"; | |
2157 | print CLIENTCONF "tls-remote $vpnsettings{ROOTCERT_HOSTNAME}\r\n"; | |
2158 | if ($vpnsettings{MSSFIX} eq 'on') { | |
2159 | print CLIENTCONF "mssfix\r\n"; | |
2160 | } | |
2161 | if ($vpnsettings{FRAGMENT} ne '' && $vpnsettings{DPROTOCOL} ne 'tcp' ) { | |
2162 | print CLIENTCONF "fragment $vpnsettings{'FRAGMENT'}\r\n"; | |
2163 | } | |
2164 | ||
2165 | # Check if a valid operating mode has been choosen and use it. | |
2166 | if (($vpnsettings{'PMTU_DISCOVERY'} eq 'yes') || | |
2167 | ($vpnsettings{'PMTU_DISCOVERY'} eq 'maybe') || | |
2168 | ($vpnsettings{'PMTU_DISCOVERY'} eq 'no' )) { | |
2169 | if(($vpnsettings{MSSFIX} ne 'on') || ($vpnsettings{FRAGMENT} eq '')) { | |
2170 | print CLIENTCONF "mtu-disc $vpnsettings{'PMTU_DISCOVERY'}\r\n"; | |
2171 | } | |
2172 | } | |
2173 | close(CLIENTCONF); | |
2174 | ||
2175 | $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n"; | |
2176 | my $status = $zip->writeToFileNamed($zippathname); | |
2177 | ||
2178 | open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!"; | |
2179 | @fileholder = <DLFILE>; | |
2180 | print "Content-Type:application/x-download\n"; | |
2181 | print "Content-Disposition:attachment;filename=$zipname\n\n"; | |
2182 | print @fileholder; | |
2183 | exit (0); | |
2184 | } | |
2185 | ||
2186 | ||
2187 | ||
2188 | ### | |
2189 | ### Remove connection | |
2190 | ### | |
2191 | ||
2192 | ||
2193 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) { | |
2194 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2195 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2196 | ||
2197 | if ($confighash{$cgiparams{'KEY'}}) { | |
2198 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
2199 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
2200 | # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}); | |
2201 | # } | |
2202 | # | |
2203 | my $temp = `/usr/bin/openssl ca -revoke ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf`; | |
2204 | ||
2205 | ### | |
2206 | # m.a.d net2net | |
2207 | ### | |
2208 | ||
2209 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net') { | |
2210 | ||
2211 | my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf"); | |
2212 | my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
2213 | unlink ($certfile) or die "Removing $certfile fail: $!"; | |
2214 | unlink ($conffile) or die "Removing $conffile fail: $!"; | |
2215 | rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!"; | |
2216 | ||
2217 | } | |
2218 | ||
2219 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); | |
2220 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
2221 | ||
2222 | # A.Marx CCD delete ccd files and routes | |
2223 | ||
2224 | ||
2225 | if (-f "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]") | |
2226 | { | |
2227 | unlink "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]"; | |
2228 | } | |
2229 | ||
2230 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
2231 | foreach my $key (keys %ccdroutehash) { | |
2232 | if ($ccdroutehash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){ | |
2233 | delete $ccdroutehash{$key}; | |
2234 | } | |
2235 | } | |
2236 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
2237 | ||
2238 | &General::readhasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
2239 | foreach my $key (keys %ccdroute2hash) { | |
2240 | if ($ccdroute2hash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){ | |
2241 | delete $ccdroute2hash{$key}; | |
2242 | } | |
2243 | } | |
2244 | &General::writehasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
2245 | &writeserverconf; | |
2246 | ||
2247 | ||
2248 | # CCD end | |
2249 | ||
2250 | ||
2251 | delete $confighash{$cgiparams{'KEY'}}; | |
2252 | my $temp2 = `/usr/bin/openssl ca -gencrl -out ${General::swroot}/ovpn/crls/cacrl.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf`; | |
2253 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2254 | ||
2255 | #&writeserverconf(); | |
2256 | } else { | |
2257 | $errormessage = $Lang::tr{'invalid key'}; | |
2258 | } | |
2259 | ||
2260 | ||
2261 | ### | |
2262 | ### Download PKCS12 file | |
2263 | ### | |
2264 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download pkcs12 file'}) { | |
2265 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2266 | ||
2267 | print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . ".p12\r\n"; | |
2268 | print "Content-Type: application/octet-stream\r\n\r\n"; | |
2269 | print `/bin/cat ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12`; | |
2270 | exit (0); | |
2271 | ||
2272 | ### | |
2273 | ### Display certificate | |
2274 | ### | |
2275 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show certificate'}) { | |
2276 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2277 | ||
2278 | if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") { | |
2279 | &Header::showhttpheaders(); | |
2280 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
2281 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2282 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate'}:"); | |
2283 | my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`; | |
2284 | $output = &Header::cleanhtml($output,"y"); | |
2285 | print "<pre>$output</pre>\n"; | |
2286 | &Header::closebox(); | |
2287 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2288 | &Header::closebigbox(); | |
2289 | &Header::closepage(); | |
2290 | exit(0); | |
2291 | } | |
2292 | ### | |
2293 | ### Display Certificate Revoke List | |
2294 | ### | |
2295 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show crl'}) { | |
2296 | # &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2297 | ||
2298 | if ( -f "${General::swroot}/ovpn/crls/cacrl.pem") { | |
2299 | &Header::showhttpheaders(); | |
2300 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
2301 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2302 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'crl'}:"); | |
2303 | my $output = `/usr/bin/openssl crl -text -noout -in ${General::swroot}/ovpn/crls/cacrl.pem`; | |
2304 | $output = &Header::cleanhtml($output,"y"); | |
2305 | print "<pre>$output</pre>\n"; | |
2306 | &Header::closebox(); | |
2307 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2308 | &Header::closebigbox(); | |
2309 | &Header::closepage(); | |
2310 | exit(0); | |
2311 | } | |
2312 | ||
2313 | ### | |
2314 | ### Advanced Server Settings | |
2315 | ### | |
2316 | ||
2317 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'advanced server'}) { | |
2318 | %cgiparams = (); | |
2319 | %cahash = (); | |
2320 | %confighash = (); | |
2321 | my $disabled; | |
2322 | &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams); | |
2323 | read_routepushfile; | |
2324 | ||
2325 | ||
2326 | # if ($cgiparams{'CLIENT2CLIENT'} eq '') { | |
2327 | # $cgiparams{'CLIENT2CLIENT'} = 'on'; | |
2328 | # } | |
2329 | ADV_ERROR: | |
2330 | if ($cgiparams{'MAX_CLIENTS'} eq '') { | |
2331 | $cgiparams{'MAX_CLIENTS'} = '100'; | |
2332 | } | |
2333 | if ($cgiparams{'KEEPALIVE_1'} eq '') { | |
2334 | $cgiparams{'KEEPALIVE_1'} = '10'; | |
2335 | } | |
2336 | if ($cgiparams{'KEEPALIVE_2'} eq '') { | |
2337 | $cgiparams{'KEEPALIVE_2'} = '60'; | |
2338 | } | |
2339 | if ($cgiparams{'LOG_VERB'} eq '') { | |
2340 | $cgiparams{'LOG_VERB'} = '3'; | |
2341 | } | |
2342 | if ($cgiparams{'PMTU_DISCOVERY'} eq '') { | |
2343 | $cgiparams{'PMTU_DISCOVERY'} = 'off'; | |
2344 | } | |
2345 | $checked{'CLIENT2CLIENT'}{'off'} = ''; | |
2346 | $checked{'CLIENT2CLIENT'}{'on'} = ''; | |
2347 | $checked{'CLIENT2CLIENT'}{$cgiparams{'CLIENT2CLIENT'}} = 'CHECKED'; | |
2348 | $checked{'REDIRECT_GW_DEF1'}{'off'} = ''; | |
2349 | $checked{'REDIRECT_GW_DEF1'}{'on'} = ''; | |
2350 | $checked{'REDIRECT_GW_DEF1'}{$cgiparams{'REDIRECT_GW_DEF1'}} = 'CHECKED'; | |
2351 | $selected{'ENGINES'}{$cgiparams{'ENGINES'}} = 'SELECTED'; | |
2352 | $checked{'MSSFIX'}{'off'} = ''; | |
2353 | $checked{'MSSFIX'}{'on'} = ''; | |
2354 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
2355 | $checked{'PMTU_DISCOVERY'}{$cgiparams{'PMTU_DISCOVERY'}} = 'checked=\'checked\''; | |
2356 | $selected{'LOG_VERB'}{'1'} = ''; | |
2357 | $selected{'LOG_VERB'}{'2'} = ''; | |
2358 | $selected{'LOG_VERB'}{'3'} = ''; | |
2359 | $selected{'LOG_VERB'}{'4'} = ''; | |
2360 | $selected{'LOG_VERB'}{'5'} = ''; | |
2361 | $selected{'LOG_VERB'}{'6'} = ''; | |
2362 | $selected{'LOG_VERB'}{'7'} = ''; | |
2363 | $selected{'LOG_VERB'}{'8'} = ''; | |
2364 | $selected{'LOG_VERB'}{'9'} = ''; | |
2365 | $selected{'LOG_VERB'}{'10'} = ''; | |
2366 | $selected{'LOG_VERB'}{'11'} = ''; | |
2367 | $selected{'LOG_VERB'}{'0'} = ''; | |
2368 | $selected{'LOG_VERB'}{$cgiparams{'LOG_VERB'}} = 'SELECTED'; | |
2369 | ||
2370 | &Header::showhttpheaders(); | |
2371 | &Header::openpage($Lang::tr{'status ovpn'}, 1, ''); | |
2372 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
2373 | if ($errormessage) { | |
2374 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
2375 | print "<class name='base'>$errormessage\n"; | |
2376 | print " </class>\n"; | |
2377 | &Header::closebox(); | |
2378 | } | |
2379 | &Header::openbox('100%', 'LEFT', $Lang::tr{'advanced server'}); | |
2380 | print <<END | |
2381 | <form method='post' enctype='multipart/form-data'> | |
2382 | <table width='100%' border=0> | |
2383 | <tr> | |
2384 | <td colspan='4'><b>$Lang::tr{'dhcp-options'}</b></td> | |
2385 | </tr> | |
2386 | <tr> | |
2387 | <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td> | |
2388 | </tr> | |
2389 | <tr> | |
2390 | <td class='base'>Domain</td> | |
2391 | <td><input type='TEXT' name='DHCP_DOMAIN' value='$cgiparams{'DHCP_DOMAIN'}' size='30' /></td> | |
2392 | </tr> | |
2393 | <tr> | |
2394 | <td class='base'>DNS</td> | |
2395 | <td><input type='TEXT' name='DHCP_DNS' value='$cgiparams{'DHCP_DNS'}' size='30' /></td> | |
2396 | </tr> | |
2397 | <tr> | |
2398 | <td class='base'>WINS</td> | |
2399 | <td><input type='TEXT' name='DHCP_WINS' value='$cgiparams{'DHCP_WINS'}' size='30' /></td> | |
2400 | </tr> | |
2401 | <tr> | |
2402 | <td colspan='4'><b>$Lang::tr{'ovpn routes push options'}</b></td> | |
2403 | </tr> | |
2404 | <tr> | |
2405 | <td class='base'>$Lang::tr{'ovpn routes push'}</td> | |
2406 | <td colspan='2'> | |
2407 | <textarea name='ROUTES_PUSH' cols='26' rows='6' wrap='off'> | |
2408 | END | |
2409 | ; | |
2410 | ||
2411 | if ($cgiparams{'ROUTES_PUSH'} ne '') | |
2412 | { | |
2413 | print $cgiparams{'ROUTES_PUSH'}; | |
2414 | } | |
2415 | ||
2416 | print <<END; | |
2417 | </textarea></td> | |
2418 | </tr> | |
2419 | </tr> | |
2420 | </table> | |
2421 | <hr size='1'> | |
2422 | <table width='100%'> | |
2423 | <tr> | |
2424 | <td class'base'><b>$Lang::tr{'misc-options'}</b></td> | |
2425 | </tr> | |
2426 | <tr> | |
2427 | <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='15%'></td><td width='35%'></td> | |
2428 | </tr> | |
2429 | <tr> | |
2430 | <td class='base'>Client-To-Client</td> | |
2431 | <td><input type='checkbox' name='CLIENT2CLIENT' $checked{'CLIENT2CLIENT'}{'on'} /></td> | |
2432 | </tr> | |
2433 | <tr> | |
2434 | <td class='base'>Redirect-Gateway def1</td> | |
2435 | <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked{'REDIRECT_GW_DEF1'}{'on'} /></td> | |
2436 | </tr> | |
2437 | <tr> | |
2438 | <td class='base'>Max-Clients</td> | |
2439 | <td><input type='text' name='MAX_CLIENTS' value='$cgiparams{'MAX_CLIENTS'}' size='10' /></td> | |
2440 | </tr> | |
2441 | <tr> | |
2442 | <td class='base'>Keepalive <br /> | |
2443 | (ping/ping-restart)</td> | |
2444 | <td><input type='TEXT' name='KEEPALIVE_1' value='$cgiparams{'KEEPALIVE_1'}' size='10' /></td> | |
2445 | <td><input type='TEXT' name='KEEPALIVE_2' value='$cgiparams{'KEEPALIVE_2'}' size='10' /></td> | |
2446 | </tr> | |
2447 | <tr> | |
2448 | <td class='base'>fragment <br></td> | |
2449 | <td><input type='TEXT' name='FRAGMENT' value='$cgiparams{'FRAGMENT'}' size='10' /></td> | |
2450 | <td>Default: <span class="base">1300</span></td> | |
2451 | </tr> | |
2452 | <tr> | |
2453 | <td class='base'>mssfix</td> | |
2454 | <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td> | |
2455 | <td>Default: on</td> | |
2456 | </tr> | |
2457 | ||
2458 | <tr> | |
2459 | <td class='base'>$Lang::tr{'ovpn mtu-disc'}</td> | |
2460 | <td><input type='radio' name='PMTU_DISCOVERY' value='yes' $checked{'PMTU_DISCOVERY'}{'yes'} /> $Lang::tr{'ovpn mtu-disc yes'}</td> | |
2461 | <td><input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked{'PMTU_DISCOVERY'}{'maybe'} /> $Lang::tr{'ovpn mtu-disc maybe'}</td> | |
2462 | <td><input type='radio' name='PMTU_DISCOVERY' value='no' $checked{'PMTU_DISCOVERY'}{'no'} /> $Lang::tr{'ovpn mtu-disc no'}</td> | |
2463 | <td><input type='radio' name='PMTU_DISCOVERY' value='off' $checked{'PMTU_DISCOVERY'}{'off'} /> $Lang::tr{'ovpn mtu-disc off'}</td> | |
2464 | </tr> | |
2465 | </table> | |
2466 | ||
2467 | <!-- | |
2468 | <hr size='1'> | |
2469 | <table width='100%'> | |
2470 | <tr> | |
2471 | <td class'base'><b>Crypto-Engines</b></td> | |
2472 | </tr> | |
2473 | <tr> | |
2474 | <td width='15%'></td> <td width='30%'> </td><td width='25%'> </td><td width='30%'></td> | |
2475 | </tr> | |
2476 | <tr><td class='base'>Engines:</td> | |
2477 | <td><select name='ENGINES'><option value="none" $selected{'ENGINES'}{'none'}>none</option> | |
2478 | <option value="cryptodev" $selected{'ENGINES'}{'cryptodev'}>cryptodev</option> | |
2479 | <option value="padlock" $selected{'ENGINES'}{'padlock'}>padlock</option> | |
2480 | </select> | |
2481 | </td> | |
2482 | </table> | |
2483 | --> | |
2484 | <hr size='1'> | |
2485 | <table width='100%'> | |
2486 | <tr> | |
2487 | <td class'base'><b>$Lang::tr{'log-options'}</b></td> | |
2488 | </tr> | |
2489 | <tr> | |
2490 | <td width='15%'></td> <td width='30%'> </td><td width='25%'> </td><td width='30%'></td> | |
2491 | </tr> | |
2492 | ||
2493 | <tr><td class='base'>VERB</td> | |
2494 | <td><select name='LOG_VERB'><option value='1' $selected{'LOG_VERB'}{'1'}>1</option> | |
2495 | <option value='2' $selected{'LOG_VERB'}{'2'}>2</option> | |
2496 | <option value='3' $selected{'LOG_VERB'}{'3'}>3</option> | |
2497 | <option value='4' $selected{'LOG_VERB'}{'4'}>4</option> | |
2498 | <option value='5' $selected{'LOG_VERB'}{'5'}>5</option> | |
2499 | <option value='6' $selected{'LOG_VERB'}{'6'}>6</option> | |
2500 | <option value='7' $selected{'LOG_VERB'}{'7'}>7</option> | |
2501 | <option value='8' $selected{'LOG_VERB'}{'8'}>8</option> | |
2502 | <option value='9' $selected{'LOG_VERB'}{'9'}>9</option> | |
2503 | <option value='10' $selected{'LOG_VERB'}{'10'}>10</option> | |
2504 | <option value='11' $selected{'LOG_VERB'}{'11'}>11</option> | |
2505 | <option value='0' $selected{'LOG_VERB'}{'0'}>0</option></select></td> | |
2506 | </table><hr> | |
2507 | END | |
2508 | ||
2509 | if ( -e "/var/run/openvpn.pid"){ | |
2510 | print" <br><b><font color='#990000'>$Lang::tr{'attention'}:</b></font><br> | |
2511 | $Lang::tr{'server restart'}<br><br> | |
2512 | <hr>"; | |
2513 | print<<END | |
2514 | <table width='100%'> | |
2515 | <tr> | |
2516 | <td> </td> | |
2517 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' disabled='disabled' /></td> | |
2518 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td> | |
2519 | <td> </td> | |
2520 | </tr> | |
2521 | </table> | |
2522 | </form> | |
2523 | END | |
2524 | ; | |
2525 | ||
2526 | ||
2527 | }else{ | |
2528 | ||
2529 | print<<END | |
2530 | <table width='100%'> | |
2531 | <tr> | |
2532 | <td> </td> | |
2533 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' /></td> | |
2534 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td> | |
2535 | <td> </td> | |
2536 | </tr> | |
2537 | </table> | |
2538 | </form> | |
2539 | END | |
2540 | ; | |
2541 | } | |
2542 | &Header::closebox(); | |
2543 | # print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2544 | &Header::closebigbox(); | |
2545 | &Header::closepage(); | |
2546 | exit(0); | |
2547 | ||
2548 | ||
2549 | # A.Marx CCD Add,delete or edit CCD net | |
2550 | ||
2551 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'ccd net'} || | |
2552 | $cgiparams{'ACTION'} eq $Lang::tr{'ccd add'} || | |
2553 | $cgiparams{'ACTION'} eq "kill" || | |
2554 | $cgiparams{'ACTION'} eq "edit" || | |
2555 | $cgiparams{'ACTION'} eq 'editsave'){ | |
2556 | &Header::showhttpheaders(); | |
2557 | &Header::openpage($Lang::tr{'ccd net'}, 1, ''); | |
2558 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2559 | ||
2560 | if ($cgiparams{'ACTION'} eq "kill"){ | |
2561 | &delccdnet($cgiparams{'net'}); | |
2562 | } | |
2563 | ||
2564 | if ($cgiparams{'ACTION'} eq 'editsave'){ | |
2565 | my ($a,$b) =split (/\|/,$cgiparams{'ccdname'}); | |
2566 | if ( $a ne $b){ &modccdnet($a,$b);} | |
2567 | $cgiparams{'ccdname'}=''; | |
2568 | $cgiparams{'ccdsubnet'}=''; | |
2569 | } | |
2570 | ||
2571 | if ($cgiparams{'ACTION'} eq $Lang::tr{'ccd add'}) { | |
2572 | &addccdnet($cgiparams{'ccdname'},$cgiparams{'ccdsubnet'}); | |
2573 | } | |
2574 | if ($errormessage) { | |
2575 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
2576 | print "<class name='base'>$errormessage"; | |
2577 | print " </class>"; | |
2578 | &Header::closebox(); | |
2579 | } | |
2580 | if ($cgiparams{'ACTION'} eq "edit"){ | |
2581 | ||
2582 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ccd modify'}); | |
2583 | ||
2584 | print <<END | |
2585 | <table width='100%' border=0> | |
2586 | <tr><form method='post'> | |
2587 | <td width='10%' nowrap='nowrap'>$Lang::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value='$cgiparams{'ccdname'}' /></td> | |
2588 | <td width='8%'>$Lang::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value='$cgiparams{'ccdsubnet'}' readonly /></td></tr> | |
2589 | <tr><td colspan='4' align='right'><hr><input type='submit' value='$Lang::tr{'save'}' /><input type='hidden' name='ACTION' value='editsave'/> | |
2590 | <input type='hidden' name='ccdname' value='$cgiparams{'ccdname'}'/><input type='submit' value='$Lang::tr{'cancel'}' /> | |
2591 | </td></tr> | |
2592 | </table></form> | |
2593 | END | |
2594 | ; | |
2595 | &Header::closebox(); | |
2596 | ||
2597 | &Header::openbox('100%', 'LEFT',$Lang::tr{'ccd net'} ); | |
2598 | print <<END | |
2599 | <table width='100%' border='0' cellpadding='0' cellspacing='1'> | |
2600 | <tr> | |
2601 | <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> | |
2602 | END | |
2603 | ; | |
2604 | } | |
2605 | else{ | |
2606 | if (! -e "/var/run/openvpn.pid"){ | |
2607 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ccd add'}); | |
2608 | print <<END; | |
2609 | <table width='100%' border='0'> | |
2610 | <tr><form method='post'> | |
2611 | <td colspan='4'>$Lang::tr{'ccd hint'}<br><br></td></tr> | |
2612 | <tr> | |
2613 | <td width='10%' nowrap='nwrap'>$Lang::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value='$cgiparams{'ccdname'}' /></td> | |
2614 | <td width='8%'>$Lang::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value='$cgiparams{'ccdsubnet'}' /></td></tr> | |
2615 | <tr><td colspan=4><hr /></td></tr><tr> | |
2616 | <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> | |
2617 | </table></form> | |
2618 | END | |
2619 | ||
2620 | &Header::closebox(); | |
2621 | } | |
2622 | &Header::openbox('100%', 'LEFT',$Lang::tr{'ccd net'} ); | |
2623 | if ( -e "/var/run/openvpn.pid"){ | |
2624 | print "<b>$Lang::tr{'attention'}:</b><br>"; | |
2625 | print "$Lang::tr{'ccd noaddnet'}<br><hr>"; | |
2626 | } | |
2627 | ||
2628 | print <<END | |
2629 | <table width='100%' border='0' cellpadding='0' cellspacing='1'> | |
2630 | <tr> | |
2631 | <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> | |
2632 | END | |
2633 | ; | |
2634 | } | |
2635 | my %ccdconfhash=(); | |
2636 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
2637 | my @ccdconf=(); | |
2638 | my $count=0; | |
2639 | foreach my $key (sort { uc($ccdconfhash{$a}[0]) cmp uc($ccdconfhash{$b}[0]) } keys %ccdconfhash) { | |
2640 | @ccdconf=($ccdconfhash{$key}[0],$ccdconfhash{$key}[1]); | |
2641 | $count++; | |
2642 | my $ccdhosts = &hostsinnet($ccdconf[0]); | |
2643 | if ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";} | |
2644 | else{ print" <tr bgcolor='$color{'color20'}'>";} | |
2645 | print"<td>$ccdconf[0]</td><td align='center'>$ccdconf[1]</td><td align='center'>$ccdhosts/".(&ccdmaxclients($ccdconf[1])+1)."</td><td>"; | |
2646 | print <<END | |
2647 | <form method='post' /> | |
2648 | <input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} /> | |
2649 | <input type='hidden' name='ACTION' value='edit'/> | |
2650 | <input type='hidden' name='ccdname' value='$ccdconf[0]' /> | |
2651 | <input type='hidden' name='ccdsubnet' value='$ccdconf[1]' /> | |
2652 | </form></td> | |
2653 | <form method='post' /> | |
2654 | <td><input type='hidden' name='ACTION' value='kill'/> | |
2655 | <input type='hidden' name='number' value='$count' /> | |
2656 | <input type='hidden' name='net' value='$ccdconf[0]' /> | |
2657 | <input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'remove'} title=$Lang::tr{'remove'} /></form></td></tr> | |
2658 | END | |
2659 | ; | |
2660 | } | |
2661 | print "</table></form>"; | |
2662 | &Header::closebox(); | |
2663 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2664 | &Header::closebigbox(); | |
2665 | &Header::closepage(); | |
2666 | exit(0); | |
2667 | ||
2668 | #END CCD | |
2669 | ||
2670 | ### | |
2671 | ### Openvpn Connections Statistics | |
2672 | ### | |
2673 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'ovpn con stat'}) { | |
2674 | &Header::showhttpheaders(); | |
2675 | &Header::openpage($Lang::tr{'ovpn con stat'}, 1, ''); | |
2676 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2677 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ovpn con stat'}); | |
2678 | ||
2679 | # | |
2680 | # <td><b>$Lang::tr{'protocol'}</b></td> | |
2681 | # protocol temp removed | |
2682 | print <<END | |
2683 | <table width='100%' border='0' cellpadding='2' cellspacing='0'> | |
2684 | <tr> | |
2685 | <td><b>$Lang::tr{'common name'}</b></td> | |
2686 | <td><b>$Lang::tr{'real address'}</b></td> | |
2687 | <td><b>$Lang::tr{'virtual address'}</b></td> | |
2688 | <td><b>$Lang::tr{'loged in at'}</b></td> | |
2689 | <td><b>$Lang::tr{'bytes sent'}</b></td> | |
2690 | <td><b>$Lang::tr{'bytes received'}</b></td> | |
2691 | <td><b>$Lang::tr{'last activity'}</b></td> | |
2692 | </tr> | |
2693 | END | |
2694 | ; | |
2695 | my $filename = "/var/log/ovpnserver.log"; | |
2696 | open(FILE, $filename) or die 'Unable to open config file.'; | |
2697 | my @current = <FILE>; | |
2698 | close(FILE); | |
2699 | my @users =(); | |
2700 | my $status; | |
2701 | my $uid = 0; | |
2702 | my $cn; | |
2703 | my @match = (); | |
2704 | my $proto = "udp"; | |
2705 | my $address; | |
2706 | my %userlookup = (); | |
2707 | foreach my $line (@current) | |
2708 | { | |
2709 | chomp($line); | |
2710 | if ( $line =~ /^Updated,(.+)/){ | |
2711 | @match = split( /^Updated,(.+)/, $line); | |
2712 | $status = $match[1]; | |
2713 | } | |
2714 | #gian | |
2715 | if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) { | |
2716 | @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line); | |
2717 | if ($match[1] ne "Common Name") { | |
2718 | $cn = $match[1]; | |
2719 | $userlookup{$match[2]} = $uid; | |
2720 | $users[$uid]{'CommonName'} = $match[1]; | |
2721 | $users[$uid]{'RealAddress'} = $match[2]; | |
2722 | $users[$uid]{'BytesReceived'} = &sizeformat($match[3]); | |
2723 | $users[$uid]{'BytesSent'} = &sizeformat($match[4]); | |
2724 | $users[$uid]{'Since'} = $match[5]; | |
2725 | $users[$uid]{'Proto'} = $proto; | |
2726 | $uid++; | |
2727 | } | |
2728 | } | |
2729 | if ( $line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/) { | |
2730 | @match = split(m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/, $line); | |
2731 | if ($match[1] ne "Virtual Address") { | |
2732 | $address = $match[3]; | |
2733 | #find the uid in the lookup table | |
2734 | $uid = $userlookup{$address}; | |
2735 | $users[$uid]{'VirtualAddress'} = $match[1]; | |
2736 | $users[$uid]{'LastRef'} = $match[4]; | |
2737 | } | |
2738 | } | |
2739 | } | |
2740 | my $user2 = @users; | |
2741 | if ($user2 >= 1){ | |
2742 | for (my $idx = 1; $idx <= $user2; $idx++){ | |
2743 | if ($idx % 2) { | |
2744 | print "<tr bgcolor='$color{'color20'}'>\n"; | |
2745 | } else { | |
2746 | print "<tr bgcolor='$color{'color22'}'>\n"; | |
2747 | } | |
2748 | print "<td align='left'>$users[$idx-1]{'CommonName'}</td>"; | |
2749 | print "<td align='left'>$users[$idx-1]{'RealAddress'}</td>"; | |
2750 | print "<td align='left'>$users[$idx-1]{'VirtualAddress'}</td>"; | |
2751 | print "<td align='left'>$users[$idx-1]{'Since'}</td>"; | |
2752 | print "<td align='left'>$users[$idx-1]{'BytesSent'}</td>"; | |
2753 | print "<td align='left'>$users[$idx-1]{'BytesReceived'}</td>"; | |
2754 | print "<td align='left'>$users[$idx-1]{'LastRef'}</td>"; | |
2755 | # print "<td align='left'>$users[$idx-1]{'Proto'}</td>"; | |
2756 | } | |
2757 | } | |
2758 | ||
2759 | print "</table>"; | |
2760 | print <<END | |
2761 | <table width='100%' border='0' cellpadding='2' cellspacing='0'> | |
2762 | <tr><td></td></tr> | |
2763 | <tr><td></td></tr> | |
2764 | <tr><td></td></tr> | |
2765 | <tr><td></td></tr> | |
2766 | <tr><td align='center' >$Lang::tr{'the statistics were last updated at'} <b>$status</b></td></tr> | |
2767 | </table> | |
2768 | END | |
2769 | ; | |
2770 | &Header::closebox(); | |
2771 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2772 | &Header::closebigbox(); | |
2773 | &Header::closepage(); | |
2774 | exit(0); | |
2775 | ||
2776 | ### | |
2777 | ### Download Certificate | |
2778 | ### | |
2779 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download certificate'}) { | |
2780 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2781 | ||
2782 | if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") { | |
2783 | print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . "cert.pem\r\n"; | |
2784 | print "Content-Type: application/octet-stream\r\n\r\n"; | |
2785 | print `/bin/cat ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`; | |
2786 | exit (0); | |
2787 | } | |
2788 | ||
2789 | ### | |
2790 | ### Enable/Disable connection | |
2791 | ### | |
2792 | ||
2793 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { | |
2794 | ||
2795 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2796 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2797 | ||
2798 | if ($confighash{$cgiparams{'KEY'}}) { | |
2799 | if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') { | |
2800 | $confighash{$cgiparams{'KEY'}}[0] = 'on'; | |
2801 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2802 | #&writeserverconf(); | |
2803 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
2804 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
2805 | # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}); | |
2806 | # } | |
2807 | } else { | |
2808 | $confighash{$cgiparams{'KEY'}}[0] = 'off'; | |
2809 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
2810 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
2811 | # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}); | |
2812 | # } | |
2813 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2814 | #&writeserverconf(); | |
2815 | } | |
2816 | } else { | |
2817 | $errormessage = $Lang::tr{'invalid key'}; | |
2818 | } | |
2819 | ||
2820 | ### | |
2821 | ### Restart connection | |
2822 | ### | |
2823 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'restart'}) { | |
2824 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2825 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2826 | ||
2827 | if ($confighash{$cgiparams{'KEY'}}) { | |
2828 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
2829 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
2830 | # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}); | |
2831 | # } | |
2832 | } else { | |
2833 | $errormessage = $Lang::tr{'invalid key'}; | |
2834 | } | |
2835 | ||
2836 | ### | |
2837 | ### Remove connection | |
2838 | ### | |
2839 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) { | |
2840 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2841 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2842 | ||
2843 | if ($confighash{$cgiparams{'KEY'}}) { | |
2844 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
2845 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
2846 | # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}); | |
2847 | # } | |
2848 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); | |
2849 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
2850 | delete $confighash{$cgiparams{'KEY'}}; | |
2851 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2852 | #&writeserverconf(); | |
2853 | } else { | |
2854 | $errormessage = $Lang::tr{'invalid key'}; | |
2855 | } | |
2856 | #test33 | |
2857 | ||
2858 | ### | |
2859 | ### Choose between adding a host-net or net-net connection | |
2860 | ### | |
2861 | ||
2862 | ### | |
2863 | # m.a.d net2net | |
2864 | ### | |
2865 | ||
2866 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'add'} && $cgiparams{'TYPE'} eq '') { | |
2867 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2868 | &Header::showhttpheaders(); | |
2869 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
2870 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2871 | &Header::openbox('100%', 'LEFT', $Lang::tr{'connection type'}); | |
2872 | ||
2873 | if ( -s "${General::swroot}/ovpn/settings") { | |
2874 | ||
2875 | print <<END | |
2876 | <b>$Lang::tr{'connection type'}:</b><br /> | |
2877 | <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data"> | |
2878 | <tr><td><input type='radio' name='TYPE' value='host' checked /></td> | |
2879 | <td class='base'>$Lang::tr{'host to net vpn'}</td></tr> | |
2880 | <tr><td><input type='radio' name='TYPE' value='net' /></td> | |
2881 | <td class='base'>$Lang::tr{'net to net vpn'}</td></tr> | |
2882 | <tr><td><input type='radio' name='TYPE' value='net2net' /></td> | |
2883 | <td class='base'>$Lang::tr{'net to net vpn'} (Upload Client Package)</td></tr> | |
2884 | <tr><td> </td><td class='base'><input type='file' name='FH' size='30'></td></tr> | |
2885 | <tr><td> </td><td>Import Connection Name <img src='/blob.gif' /></td></tr> | |
2886 | <tr><td> </td><td class='base'><input type='text' name='n2nname' size='30'>Default : Client Packagename</td></tr> | |
2887 | <tr><td colspan='3'><hr /></td></tr> | |
2888 | <tr><td align='right' colspan='3'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr> | |
2889 | <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang::tr{'this field may be blank'}</td></tr> | |
2890 | </form></table> | |
2891 | END | |
2892 | ; | |
2893 | ||
2894 | ||
2895 | } else { | |
2896 | print <<END | |
2897 | <b>$Lang::tr{'connection type'}:</b><br /> | |
2898 | <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data"> | |
2899 | <tr><td><input type='radio' name='TYPE' value='host' checked /></td> <td class='base'>$Lang::tr{'host to net vpn'}</td></tr> | |
2900 | <tr><td align='right' colspan'3'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr> | |
2901 | </form></table> | |
2902 | END | |
2903 | ; | |
2904 | ||
2905 | } | |
2906 | ||
2907 | &Header::closebox(); | |
2908 | &Header::closebigbox(); | |
2909 | &Header::closepage(); | |
2910 | exit (0); | |
2911 | ||
2912 | ### | |
2913 | # m.a.d net2net | |
2914 | ### | |
2915 | ||
2916 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2net')){ | |
2917 | ||
2918 | my @firen2nconf; | |
2919 | my @confdetails; | |
2920 | my $uplconffilename =''; | |
2921 | my $uplconffilename2 =''; | |
2922 | my $uplp12name = ''; | |
2923 | my $uplp12name2 = ''; | |
2924 | my @rem_subnet; | |
2925 | my @rem_subnet2; | |
2926 | my @tmposupnet3; | |
2927 | my $key; | |
2928 | my @n2nname; | |
2929 | ||
2930 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2931 | ||
2932 | # Check if a file is uploaded | |
2933 | ||
2934 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
2935 | $errormessage = $Lang::tr{'there was no file upload'}; | |
2936 | goto N2N_ERROR; | |
2937 | } | |
2938 | ||
2939 | # Move uploaded IPfire n2n package to temporary file | |
2940 | ||
2941 | (my $fh, my $filename) = tempfile( ); | |
2942 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
2943 | $errormessage = $!; | |
2944 | goto N2N_ERROR; | |
2945 | } | |
2946 | ||
2947 | my $zip = Archive::Zip->new(); | |
2948 | my $zipName = $filename; | |
2949 | my $status = $zip->read( $zipName ); | |
2950 | if ($status != AZ_OK) { | |
2951 | $errormessage = "Read of $zipName failed\n"; | |
2952 | goto N2N_ERROR; | |
2953 | } | |
2954 | ||
2955 | my $tempdir = tempdir( CLEANUP => 1 ); | |
2956 | my @files = $zip->memberNames(); | |
2957 | for(@files) { | |
2958 | $zip->extractMemberWithoutPaths($_,"$tempdir/$_"); | |
2959 | } | |
2960 | my $countfiles = @files; | |
2961 | ||
2962 | # Check if we have not more then 2 files | |
2963 | ||
2964 | if ( $countfiles == 2){ | |
2965 | foreach (@files){ | |
2966 | if ( $_ =~ /.conf$/){ | |
2967 | $uplconffilename = $_; | |
2968 | } | |
2969 | if ( $_ =~ /.p12$/){ | |
2970 | $uplp12name = $_; | |
2971 | } | |
2972 | } | |
2973 | if (($uplconffilename eq '') || ($uplp12name eq '')){ | |
2974 | $errormessage = "Either no *.conf or no *.p12 file found\n"; | |
2975 | goto N2N_ERROR; | |
2976 | } | |
2977 | ||
2978 | open(FILE, "$tempdir/$uplconffilename") or die 'Unable to open*.conf file'; | |
2979 | @firen2nconf = <FILE>; | |
2980 | close (FILE); | |
2981 | chomp(@firen2nconf); | |
2982 | ||
2983 | } else { | |
2984 | ||
2985 | $errormessage = "Filecount does not match only 2 files are allowed\n"; | |
2986 | goto N2N_ERROR; | |
2987 | } | |
2988 | ||
2989 | ### | |
2990 | # m.a.d net2net | |
2991 | ### | |
2992 | ||
2993 | if ($cgiparams{'n2nname'} ne ''){ | |
2994 | ||
2995 | $uplconffilename2 = "$cgiparams{'n2nname'}.conf"; | |
2996 | $uplp12name2 = "$cgiparams{'n2nname'}.p12"; | |
2997 | $n2nname[0] = $cgiparams{'n2nname'}; | |
2998 | my @n2nname2 = split(/\./,$uplconffilename); | |
2999 | $n2nname2[0] =~ s/\n|\r//g; | |
3000 | my $input1 = "${General::swroot}/ovpn/certs/$uplp12name"; | |
3001 | my $output1 = "${General::swroot}/ovpn/certs/$uplp12name2"; | |
3002 | my $input2 = "$n2nname2[0]n2n"; | |
3003 | my $output2 = "$n2nname[0]n2n"; | |
3004 | my $filename = "$tempdir/$uplconffilename"; | |
3005 | open(FILE, "< $filename") or die 'Unable to open config file.'; | |
3006 | my @current = <FILE>; | |
3007 | close(FILE); | |
3008 | foreach (@current) {s/$input1/$output1/g;} | |
3009 | foreach (@current) {s/$input2/$output2/g;} | |
3010 | open (OUT, "> $filename") || die 'Unable to open config file.'; | |
3011 | print OUT @current; | |
3012 | close OUT; | |
3013 | ||
3014 | }else{ | |
3015 | $uplconffilename2 = $uplconffilename; | |
3016 | $uplp12name2 = $uplp12name; | |
3017 | @n2nname = split(/\./,$uplconffilename); | |
3018 | $n2nname[0] =~ s/\n|\r//g; | |
3019 | } | |
3020 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} | |
3021 | unless(-d "${General::swroot}/ovpn/n2nconf/$n2nname[0]"){mkdir "${General::swroot}/ovpn/n2nconf/$n2nname[0]", 0770 or die "Unable to create dir $!";} | |
3022 | ||
3023 | move("$tempdir/$uplconffilename", "${General::swroot}/ovpn/n2nconf/$n2nname[0]/$uplconffilename2"); | |
3024 | ||
3025 | if ($? ne 0) { | |
3026 | $errormessage = "*.conf move failed: $!"; | |
3027 | unlink ($filename); | |
3028 | goto N2N_ERROR; | |
3029 | } | |
3030 | ||
3031 | move("$tempdir/$uplp12name", "${General::swroot}/ovpn/certs/$uplp12name2"); | |
3032 | chmod 0600, "${General::swroot}/ovpn/certs/$uplp12name"; | |
3033 | ||
3034 | if ($? ne 0) { | |
3035 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
3036 | unlink ($filename); | |
3037 | goto N2N_ERROR; | |
3038 | } | |
3039 | ||
3040 | my $complzoactive; | |
3041 | my $mssfixactive; | |
3042 | my $n2nfragment; | |
3043 | my @n2nmtudisc = split(/ /, (grep { /^mtu-disc/ } @firen2nconf)[0]);; | |
3044 | my @n2nproto2 = split(/ /, (grep { /^proto/ } @firen2nconf)[0]); | |
3045 | my @n2nproto = split(/-/, $n2nproto2[1]); | |
3046 | my @n2nport = split(/ /, (grep { /^port/ } @firen2nconf)[0]); | |
3047 | my @n2ntunmtu = split(/ /, (grep { /^tun-mtu/ } @firen2nconf)[0]); | |
3048 | my @n2ncomplzo = grep { /^comp-lzo/ } @firen2nconf; | |
3049 | if ($n2ncomplzo[0] =~ /comp-lzo/){$complzoactive = "on";} else {$complzoactive = "off";} | |
3050 | my @n2nmssfix = grep { /^mssfix/ } @firen2nconf; | |
3051 | if ($n2nmssfix[0] =~ /mssfix/){$mssfixactive = "on";} else {$mssfixactive = "off";} | |
3052 | #my @n2nmssfix = split(/ /, (grep { /^mssfix/ } @firen2nconf)[0]); | |
3053 | my @n2nfragment = split(/ /, (grep { /^fragment/ } @firen2nconf)[0]); | |
3054 | my @n2nremote = split(/ /, (grep { /^remote/ } @firen2nconf)[0]); | |
3055 | my @n2novpnsuball = split(/ /, (grep { /^ifconfig/ } @firen2nconf)[0]); | |
3056 | my @n2novpnsub = split(/\./,$n2novpnsuball[1]); | |
3057 | my @n2nremsub = split(/ /, (grep { /^route/ } @firen2nconf)[0]); | |
3058 | my @n2nmgmt = split(/ /, (grep { /^management/ } @firen2nconf)[0]); | |
3059 | my @n2nlocalsub = split(/ /, (grep { /^# remsub/ } @firen2nconf)[0]); | |
3060 | ||
3061 | ||
3062 | ### | |
3063 | # m.a.d delete CR and LF from arrays for this chomp doesnt work | |
3064 | ### | |
3065 | ||
3066 | $n2nremote[1] =~ s/\n|\r//g; | |
3067 | $n2novpnsub[0] =~ s/\n|\r//g; | |
3068 | $n2novpnsub[1] =~ s/\n|\r//g; | |
3069 | $n2novpnsub[2] =~ s/\n|\r//g; | |
3070 | $n2nproto[0] =~ s/\n|\r//g; | |
3071 | $n2nport[1] =~ s/\n|\r//g; | |
3072 | $n2ntunmtu[1] =~ s/\n|\r//g; | |
3073 | $n2nremsub[1] =~ s/\n|\r//g; | |
3074 | $n2nremsub[2] =~ s/\n|\r//g; | |
3075 | $n2nlocalsub[2] =~ s/\n|\r//g; | |
3076 | $n2nfragment[1] =~ s/\n|\r//g; | |
3077 | $n2nmgmt[2] =~ s/\n|\r//g; | |
3078 | $n2nmtudisc[1] =~ s/\n|\r//g; | |
3079 | chomp ($complzoactive); | |
3080 | chomp ($mssfixactive); | |
3081 | ||
3082 | ### | |
3083 | # m.a.d net2net | |
3084 | ### | |
3085 | ||
3086 | ### | |
3087 | # Check if there is no other entry with this name | |
3088 | ### | |
3089 | ||
3090 | foreach my $dkey (keys %confighash) { | |
3091 | if ($confighash{$dkey}[1] eq $n2nname[0]) { | |
3092 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
3093 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; | |
3094 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3095 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
3096 | goto N2N_ERROR; | |
3097 | } | |
3098 | } | |
3099 | ||
3100 | ### | |
3101 | # Check if OpenVPN Subnet is valid | |
3102 | ### | |
3103 | ||
3104 | foreach my $dkey (keys %confighash) { | |
3105 | if ($confighash{$dkey}[27] eq "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0") { | |
3106 | $errormessage = 'The OpenVPN Subnet is already in use'; | |
3107 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; | |
3108 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3109 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
3110 | goto N2N_ERROR; | |
3111 | } | |
3112 | } | |
3113 | ||
3114 | ### | |
3115 | # Check im Dest Port is vaild | |
3116 | ### | |
3117 | ||
3118 | foreach my $dkey (keys %confighash) { | |
3119 | if ($confighash{$dkey}[29] eq $n2nport[1] ) { | |
3120 | $errormessage = 'The OpenVPN Port is already in use'; | |
3121 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; | |
3122 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3123 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
3124 | goto N2N_ERROR; | |
3125 | } | |
3126 | } | |
3127 | ||
3128 | ||
3129 | ||
3130 | $key = &General::findhasharraykey (\%confighash); | |
3131 | ||
3132 | foreach my $i (0 .. 39) { $confighash{$key}[$i] = "";} | |
3133 | ||
3134 | $confighash{$key}[0] = 'off'; | |
3135 | $confighash{$key}[1] = $n2nname[0]; | |
3136 | $confighash{$key}[2] = $n2nname[0]; | |
3137 | $confighash{$key}[3] = 'net'; | |
3138 | $confighash{$key}[4] = 'cert'; | |
3139 | $confighash{$key}[6] = 'client'; | |
3140 | $confighash{$key}[8] = $n2nlocalsub[2]; | |
3141 | $confighash{$key}[10] = $n2nremote[1]; | |
3142 | $confighash{$key}[11] = "$n2nremsub[1]/$n2nremsub[2]"; | |
3143 | $confighash{$key}[22] = $n2nmgmt[2]; | |
3144 | $confighash{$key}[23] = $mssfixactive; | |
3145 | $confighash{$key}[24] = $n2nfragment[1]; | |
3146 | $confighash{$key}[25] = 'IPFire n2n Client'; | |
3147 | $confighash{$key}[26] = 'red'; | |
3148 | $confighash{$key}[27] = "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0"; | |
3149 | $confighash{$key}[28] = $n2nproto[0]; | |
3150 | $confighash{$key}[29] = $n2nport[1]; | |
3151 | $confighash{$key}[30] = $complzoactive; | |
3152 | $confighash{$key}[31] = $n2ntunmtu[1]; | |
3153 | $confighash{$key}[38] = $n2nmtudisc[1]; | |
3154 | ||
3155 | ||
3156 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3157 | ||
3158 | N2N_ERROR: | |
3159 | ||
3160 | &Header::showhttpheaders(); | |
3161 | &Header::openpage('Validate imported configuration', 1, ''); | |
3162 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
3163 | if ($errormessage) { | |
3164 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
3165 | print "<class name='base'>$errormessage"; | |
3166 | print " </class>"; | |
3167 | &Header::closebox(); | |
3168 | ||
3169 | } else | |
3170 | { | |
3171 | &Header::openbox('100%', 'LEFT', 'import ipfire net2net config'); | |
3172 | } | |
3173 | if ($errormessage eq ''){ | |
3174 | print <<END | |
3175 | <!-- ipfire net2net config gui --> | |
3176 | <table width='100%'> | |
3177 | <tr><td width='25%'> </td><td width='25%'> </td></tr> | |
3178 | <tr><td class='boldbase'>$Lang::tr{'name'}:</td><td><b>$n2nname[0]</b></td></tr> | |
3179 | <tr><td> </td><td> </td></tr> | |
3180 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'Act as'}</td><td><b>$confighash{$key}[6]</b></td></tr> | |
3181 | <tr><td class='boldbase' nowrap='nowrap'>Remote Host </td><td><b>$confighash{$key}[10]</b></td></tr> | |
3182 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'}</td><td><b>$confighash{$key}[8]</b></td></tr> | |
3183 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'}</td><td><b>$confighash{$key}[11]</b></td></tr> | |
3184 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn subnet'}</td><td><b>$confighash{$key}[27]</b></td></tr> | |
3185 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td><td><b>$confighash{$key}[28]</b></td></tr> | |
3186 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'destination port'}:</td><td><b>$confighash{$key}[29]</b></td></tr> | |
3187 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td><td><b>$confighash{$key}[30]</b></td></tr> | |
3188 | <tr><td class='boldbase' nowrap='nowrap'>MSSFIX </td><td><b>$confighash{$key}[23]</b></td></tr> | |
3189 | <tr><td class='boldbase' nowrap='nowrap'>Fragment </td><td><b>$confighash{$key}[24]</b></td></tr> | |
3190 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'}</td><td><b>$confighash{$key}[31]</b></td></tr> | |
3191 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn mtu-disc'}</td><td><b>$confighash{$key}[38]</b></td></tr> | |
3192 | <tr><td class='boldbase' nowrap='nowrap'>Management Port </td><td><b>$confighash{$key}[22]</b></td></tr> | |
3193 | <tr><td> </td><td> </td></tr> | |
3194 | </table> | |
3195 | END | |
3196 | ; | |
3197 | &Header::closebox(); | |
3198 | } | |
3199 | ||
3200 | if ($errormessage) { | |
3201 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
3202 | } else { | |
3203 | print "<div align='center'><form method='post' ENCTYPE='multipart/form-data'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' />"; | |
3204 | print "<input type='hidden' name='TYPE' value='net2netakn' />"; | |
3205 | print "<input type='hidden' name='KEY' value='$key' />"; | |
3206 | print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>"; | |
3207 | } | |
3208 | &Header::closebigbox(); | |
3209 | &Header::closepage(); | |
3210 | exit(0); | |
3211 | ||
3212 | ||
3213 | ## | |
3214 | ### Accept IPFire n2n Package Settings | |
3215 | ### | |
3216 | ||
3217 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){ | |
3218 | ||
3219 | ### | |
3220 | ### Discard and Rollback IPFire n2n Package Settings | |
3221 | ### | |
3222 | ||
3223 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'cancel'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){ | |
3224 | ||
3225 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3226 | ||
3227 | if ($confighash{$cgiparams{'KEY'}}) { | |
3228 | ||
3229 | my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf"); | |
3230 | my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
3231 | unlink ($certfile) or die "Removing $certfile fail: $!"; | |
3232 | unlink ($conffile) or die "Removing $conffile fail: $!"; | |
3233 | rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!"; | |
3234 | delete $confighash{$cgiparams{'KEY'}}; | |
3235 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3236 | ||
3237 | } else { | |
3238 | $errormessage = $Lang::tr{'invalid key'}; | |
3239 | } | |
3240 | ||
3241 | ||
3242 | ### | |
3243 | # m.a.d net2net | |
3244 | ### | |
3245 | ||
3246 | ||
3247 | ### | |
3248 | ### Adding a new connection | |
3249 | ### | |
3250 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) || | |
3251 | ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) || | |
3252 | ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'ADVANCED'} eq '')) { | |
3253 | ||
3254 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
3255 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
3256 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3257 | ||
3258 | if ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) { | |
3259 | if (! $confighash{$cgiparams{'KEY'}}[0]) { | |
3260 | $errormessage = $Lang::tr{'invalid key'}; | |
3261 | goto VPNCONF_END; | |
3262 | } | |
3263 | $cgiparams{'ENABLED'} = $confighash{$cgiparams{'KEY'}}[0]; | |
3264 | $cgiparams{'NAME'} = $confighash{$cgiparams{'KEY'}}[1]; | |
3265 | $cgiparams{'TYPE'} = $confighash{$cgiparams{'KEY'}}[3]; | |
3266 | $cgiparams{'AUTH'} = $confighash{$cgiparams{'KEY'}}[4]; | |
3267 | $cgiparams{'PSK'} = $confighash{$cgiparams{'KEY'}}[5]; | |
3268 | $cgiparams{'SIDE'} = $confighash{$cgiparams{'KEY'}}[6]; | |
3269 | $cgiparams{'LOCAL_SUBNET'} = $confighash{$cgiparams{'KEY'}}[8]; | |
3270 | $cgiparams{'REMOTE'} = $confighash{$cgiparams{'KEY'}}[10]; | |
3271 | $cgiparams{'REMOTE_SUBNET'} = $confighash{$cgiparams{'KEY'}}[11]; | |
3272 | $cgiparams{'OVPN_MGMT'} = $confighash{$cgiparams{'KEY'}}[22]; | |
3273 | $cgiparams{'MSSFIX'} = $confighash{$cgiparams{'KEY'}}[23]; | |
3274 | $cgiparams{'FRAGMENT'} = $confighash{$cgiparams{'KEY'}}[24]; | |
3275 | $cgiparams{'REMARK'} = $confighash{$cgiparams{'KEY'}}[25]; | |
3276 | $cgiparams{'INTERFACE'} = $confighash{$cgiparams{'KEY'}}[26]; | |
3277 | $cgiparams{'OVPN_SUBNET'} = $confighash{$cgiparams{'KEY'}}[27]; | |
3278 | $cgiparams{'PROTOCOL'} = $confighash{$cgiparams{'KEY'}}[28]; | |
3279 | $cgiparams{'DEST_PORT'} = $confighash{$cgiparams{'KEY'}}[29]; | |
3280 | $cgiparams{'COMPLZO'} = $confighash{$cgiparams{'KEY'}}[30]; | |
3281 | $cgiparams{'MTU'} = $confighash{$cgiparams{'KEY'}}[31]; | |
3282 | $cgiparams{'CHECK1'} = $confighash{$cgiparams{'KEY'}}[32]; | |
3283 | $name=$cgiparams{'CHECK1'} ; | |
3284 | $cgiparams{$name} = $confighash{$cgiparams{'KEY'}}[33]; | |
3285 | $cgiparams{'RG'} = $confighash{$cgiparams{'KEY'}}[34]; | |
3286 | $cgiparams{'CCD_DNS1'} = $confighash{$cgiparams{'KEY'}}[35]; | |
3287 | $cgiparams{'CCD_DNS2'} = $confighash{$cgiparams{'KEY'}}[36]; | |
3288 | $cgiparams{'CCD_WINS'} = $confighash{$cgiparams{'KEY'}}[37]; | |
3289 | $cgiparams{'PMTU_DISCOVERY'} = $confighash{$cgiparams{'KEY'}}[38]; | |
3290 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) { | |
3291 | $cgiparams{'REMARK'} = &Header::cleanhtml($cgiparams{'REMARK'}); | |
3292 | ||
3293 | #A.Marx CCD check iroute field and convert it to decimal | |
3294 | if ($cgiparams{'TYPE'} eq 'host') { | |
3295 | my @temp=(); | |
3296 | my %ccdroutehash=(); | |
3297 | my $keypoint=0; | |
3298 | my $ip; | |
3299 | my $cidr; | |
3300 | if ($cgiparams{'IR'} ne ''){ | |
3301 | @temp = split("\n",$cgiparams{'IR'}); | |
3302 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3303 | #find key to use | |
3304 | foreach my $key (keys %ccdroutehash) { | |
3305 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}) { | |
3306 | $keypoint=$key; | |
3307 | delete $ccdroutehash{$key}; | |
3308 | }else{ | |
3309 | $keypoint = &General::findhasharraykey (\%ccdroutehash); | |
3310 | } | |
3311 | } | |
3312 | $ccdroutehash{$keypoint}[0]=$cgiparams{'NAME'}; | |
3313 | my $i=1; | |
3314 | my $val=0; | |
3315 | foreach $val (@temp){ | |
3316 | chomp($val); | |
3317 | $val=~s/\s*$//g; | |
3318 | #check if iroute exists in ccdroute or if new iroute is part of an existing one | |
3319 | foreach my $key (keys %ccdroutehash) { | |
3320 | foreach my $oldiroute ( 1 .. $#{$ccdroutehash{$key}}){ | |
3321 | if ($ccdroutehash{$key}[$oldiroute] eq "$val") { | |
3322 | $errormessage=$errormessage.$Lang::tr{'ccd err irouteexist'}; | |
3323 | goto VPNCONF_ERROR; | |
3324 | } | |
3325 | my ($ip1,$cidr1) = split (/\//, $val); | |
3326 | $ip1 = &General::getnetworkip($ip1,&General::iporsubtocidr($cidr1)); | |
3327 | my ($ip2,$cidr2) = split (/\//, $ccdroutehash{$key}[$oldiroute]); | |
3328 | if (&General::IpInSubnet ($ip1,$ip2,$cidr2)){ | |
3329 | $errormessage=$errormessage.$Lang::tr{'ccd err irouteexist'}; | |
3330 | goto VPNCONF_ERROR; | |
3331 | } | |
3332 | ||
3333 | } | |
3334 | } | |
3335 | if (!&General::validipandmask($val)){ | |
3336 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($val)"; | |
3337 | goto VPNCONF_ERROR; | |
3338 | }else{ | |
3339 | ($ip,$cidr) = split(/\//,$val); | |
3340 | $ip=&General::getnetworkip($ip,&General::iporsubtocidr($cidr)); | |
3341 | $cidr=&General::iporsubtodec($cidr); | |
3342 | $ccdroutehash{$keypoint}[$i] = $ip."/".$cidr; | |
3343 | ||
3344 | } | |
3345 | ||
3346 | #check for existing network IP's | |
3347 | if (&General::IpInSubnet ($ip,$netsettings{GREEN_NETADDRESS},$netsettings{GREEN_NETMASK}) && $netsettings{GREEN_NETADDRESS} ne '0.0.0.0') | |
3348 | { | |
3349 | $errormessage=$Lang::tr{'ccd err green'}; | |
3350 | goto VPNCONF_ERROR; | |
3351 | }elsif(&General::IpInSubnet ($ip,$netsettings{RED_NETADDRESS},$netsettings{RED_NETMASK}) && $netsettings{RED_NETADDRESS} ne '0.0.0.0') | |
3352 | { | |
3353 | $errormessage=$Lang::tr{'ccd err red'}; | |
3354 | goto VPNCONF_ERROR; | |
3355 | }elsif(&General::IpInSubnet ($ip,$netsettings{BLUE_NETADDRESS},$netsettings{BLUE_NETMASK}) && $netsettings{BLUE_NETADDRESS} ne '0.0.0.0' && $netsettings{BLUE_NETADDRESS} gt '') | |
3356 | { | |
3357 | $errormessage=$Lang::tr{'ccd err blue'}; | |
3358 | goto VPNCONF_ERROR; | |
3359 | }elsif(&General::IpInSubnet ($ip,$netsettings{ORANGE_NETADDRESS},$netsettings{ORANGE_NETMASK}) && $netsettings{ORANGE_NETADDRESS} ne '0.0.0.0' && $netsettings{ORANGE_NETADDRESS} gt '' ) | |
3360 | { | |
3361 | $errormessage=$Lang::tr{'ccd err orange'}; | |
3362 | goto VPNCONF_ERROR; | |
3363 | } | |
3364 | ||
3365 | if (&General::validipandmask($val)){ | |
3366 | $ccdroutehash{$keypoint}[$i] = $ip."/".$cidr; | |
3367 | }else{ | |
3368 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($ip/$cidr)"; | |
3369 | goto VPNCONF_ERROR; | |
3370 | } | |
3371 | $i++; | |
3372 | } | |
3373 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3374 | &writeserverconf; | |
3375 | }else{ | |
3376 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3377 | foreach my $key (keys %ccdroutehash) { | |
3378 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}) { | |
3379 | delete $ccdroutehash{$key}; | |
3380 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3381 | &writeserverconf; | |
3382 | } | |
3383 | } | |
3384 | } | |
3385 | undef @temp; | |
3386 | #check route field and convert it to decimal | |
3387 | my $val=0; | |
3388 | my $i=1; | |
3389 | &General::readhasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
3390 | #find key to use | |
3391 | foreach my $key (keys %ccdroute2hash) { | |
3392 | if ($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}) { | |
3393 | $keypoint=$key; | |
3394 | delete $ccdroute2hash{$key}; | |
3395 | }else{ | |
3396 | $keypoint = &General::findhasharraykey (\%ccdroute2hash); | |
3397 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3398 | &writeserverconf; | |
3399 | } | |
3400 | } | |
3401 | $ccdroute2hash{$keypoint}[0]=$cgiparams{'NAME'}; | |
3402 | if ($cgiparams{'IFROUTE'} eq ''){$cgiparams{'IFROUTE'} = $Lang::tr{'ccd none'};} | |
3403 | @temp = split(/\|/,$cgiparams{'IFROUTE'}); | |
3404 | my %ownnet=(); | |
3405 | &General::readhash("${General::swroot}/ethernet/settings", \%ownnet); | |
3406 | foreach $val (@temp){ | |
3407 | chomp($val); | |
3408 | $val=~s/\s*$//g; | |
3409 | if ($val eq $Lang::tr{'green'}) | |
3410 | { | |
3411 | $val=$ownnet{GREEN_NETADDRESS}."/".$ownnet{GREEN_NETMASK}; | |
3412 | } | |
3413 | if ($val eq $Lang::tr{'blue'}) | |
3414 | { | |
3415 | $val=$ownnet{BLUE_NETADDRESS}."/".$ownnet{BLUE_NETMASK}; | |
3416 | } | |
3417 | if ($val eq $Lang::tr{'orange'}) | |
3418 | { | |
3419 | $val=$ownnet{ORANGE_NETADDRESS}."/".$ownnet{ORANGE_NETMASK}; | |
3420 | } | |
3421 | my ($ip,$cidr) = split (/\//, $val); | |
3422 | ||
3423 | if ($val ne $Lang::tr{'ccd none'}) | |
3424 | { | |
3425 | if (! &check_routes_push($val)){$errormessage=$errormessage."Route $val ".$Lang::tr{'ccd err routeovpn2'}." ($val)";goto VPNCONF_ERROR;} | |
3426 | if (! &check_ccdroute($val)){$errormessage=$errormessage."<br>Route $val ".$Lang::tr{'ccd err inuse'}." ($val)" ;goto VPNCONF_ERROR;} | |
3427 | if (! &check_ccdconf($val)){$errormessage=$errormessage."<br>Route $val ".$Lang::tr{'ccd err routeovpn'}." ($val)";goto VPNCONF_ERROR;} | |
3428 | if (&General::validipandmask($val)){ | |
3429 | $val=$ip."/".&General::iporsubtodec($cidr); | |
3430 | $ccdroute2hash{$keypoint}[$i] = $val; | |
3431 | }else{ | |
3432 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($val)"; | |
3433 | goto VPNCONF_ERROR; | |
3434 | } | |
3435 | }else{ | |
3436 | $ccdroute2hash{$keypoint}[$i]=''; | |
3437 | } | |
3438 | $i++; | |
3439 | } | |
3440 | &General::writehasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
3441 | ||
3442 | #check dns1 ip | |
3443 | if ($cgiparams{'CCD_DNS1'} ne '' && ! &General::validip($cgiparams{'CCD_DNS1'})) { | |
3444 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp dns'}." 1"; | |
3445 | goto VPNCONF_ERROR; | |
3446 | } | |
3447 | #check dns2 ip | |
3448 | if ($cgiparams{'CCD_DNS2'} ne '' && ! &General::validip($cgiparams{'CCD_DNS2'})) { | |
3449 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp dns'}." 2"; | |
3450 | goto VPNCONF_ERROR; | |
3451 | } | |
3452 | #check wins ip | |
3453 | if ($cgiparams{'CCD_WINS'} ne '' && ! &General::validip($cgiparams{'CCD_WINS'})) { | |
3454 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp wins'}; | |
3455 | goto VPNCONF_ERROR; | |
3456 | } | |
3457 | } | |
3458 | ||
3459 | #CCD End | |
3460 | ||
3461 | ||
3462 | if ($cgiparams{'TYPE'} !~ /^(host|net)$/) { | |
3463 | $errormessage = $Lang::tr{'connection type is invalid'}; | |
3464 | if ($cgiparams{'TYPE'} eq 'net') { | |
3465 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3466 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3467 | } | |
3468 | goto VPNCONF_ERROR; | |
3469 | } | |
3470 | ||
3471 | ||
3472 | if ($cgiparams{'NAME'} !~ /^[a-zA-Z0-9]+$/) { | |
3473 | $errormessage = $Lang::tr{'name must only contain characters'}; | |
3474 | if ($cgiparams{'TYPE'} eq 'net') { | |
3475 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3476 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3477 | } | |
3478 | goto VPNCONF_ERROR; | |
3479 | } | |
3480 | ||
3481 | if ($cgiparams{'NAME'} =~ /^(host|01|block|private|clear|packetdefault)$/) { | |
3482 | $errormessage = $Lang::tr{'name is invalid'}; | |
3483 | if ($cgiparams{'TYPE'} eq 'net') { | |
3484 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3485 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3486 | } | |
3487 | goto VPNCONF_ERROR; | |
3488 | } | |
3489 | ||
3490 | if (length($cgiparams{'NAME'}) >60) { | |
3491 | $errormessage = $Lang::tr{'name too long'}; | |
3492 | if ($cgiparams{'TYPE'} eq 'net') { | |
3493 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3494 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3495 | } | |
3496 | goto VPNCONF_ERROR; | |
3497 | } | |
3498 | ||
3499 | ### | |
3500 | # m.a.d net2net | |
3501 | ### | |
3502 | ||
3503 | if ($cgiparams{'TYPE'} eq 'net') { | |
3504 | if ($cgiparams{'DEST_PORT'} eq $vpnsettings{'DDEST_PORT'}) { | |
3505 | $errormessage = $Lang::tr{'openvpn destination port used'}; | |
3506 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3507 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3508 | goto VPNCONF_ERROR; | |
3509 | } | |
3510 | #Bugfix 10357 | |
3511 | foreach my $key (sort keys %confighash){ | |
3512 | 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])){ | |
3513 | $errormessage = $Lang::tr{'openvpn destination port used'}; | |
3514 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3515 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3516 | goto VPNCONF_ERROR; | |
3517 | } | |
3518 | } | |
3519 | if ($cgiparams{'DEST_PORT'} eq '') { | |
3520 | $errormessage = $Lang::tr{'invalid port'}; | |
3521 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3522 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3523 | goto VPNCONF_ERROR; | |
3524 | } | |
3525 | ||
3526 | # Check if the input for the transfer net is valid. | |
3527 | if (!&General::validipandmask($cgiparams{'OVPN_SUBNET'})){ | |
3528 | $errormessage = $Lang::tr{'ccd err invalidnet'}; | |
3529 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3530 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3531 | goto VPNCONF_ERROR; | |
3532 | } | |
3533 | ||
3534 | if ($cgiparams{'OVPN_SUBNET'} eq $vpnsettings{'DOVPN_SUBNET'}) { | |
3535 | $errormessage = $Lang::tr{'openvpn subnet is used'}; | |
3536 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3537 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3538 | goto VPNCONF_ERROR; | |
3539 | } | |
3540 | ||
3541 | if (($cgiparams{'PROTOCOL'} eq 'tcp') && ($cgiparams{'MSSFIX'} eq 'on')) { | |
3542 | $errormessage = $Lang::tr{'openvpn mssfix allowed with udp'}; | |
3543 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3544 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3545 | goto VPNCONF_ERROR; | |
3546 | } | |
3547 | ||
3548 | if (($cgiparams{'PROTOCOL'} eq 'tcp') && ($cgiparams{'FRAGMENT'} ne '')) { | |
3549 | $errormessage = $Lang::tr{'openvpn fragment allowed with udp'}; | |
3550 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3551 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3552 | goto VPNCONF_ERROR; | |
3553 | } | |
3554 | ||
3555 | if ($cgiparams{'PMTU_DISCOVERY'} ne 'off') { | |
3556 | if (($cgiparams{'FRAGMENT'} ne '') || ($cgiparams{'MSSFIX'} eq 'on')) { | |
3557 | $errormessage = $Lang::tr{'ovpn mtu-disc with mssfix or fragment'}; | |
3558 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3559 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3560 | goto VPNCONF_ERROR; | |
3561 | } | |
3562 | } | |
3563 | ||
3564 | if (($cgiparams{'PMTU_DISCOVERY'} ne 'off') && ($cgiparams{'MTU'} ne '1500')) { | |
3565 | $errormessage = $Lang::tr{'ovpn mtu-disc and mtu not 1500'}; | |
3566 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3567 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3568 | goto VPNCONF_ERROR; | |
3569 | } | |
3570 | ||
3571 | if ( &validdotmask ($cgiparams{'LOCAL_SUBNET'})) { | |
3572 | $errormessage = $Lang::tr{'openvpn prefix local subnet'}; | |
3573 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3574 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3575 | goto VPNCONF_ERROR; | |
3576 | } | |
3577 | ||
3578 | if ( &validdotmask ($cgiparams{'OVPN_SUBNET'})) { | |
3579 | $errormessage = $Lang::tr{'openvpn prefix openvpn subnet'}; | |
3580 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3581 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3582 | goto VPNCONF_ERROR; | |
3583 | } | |
3584 | ||
3585 | if ( &validdotmask ($cgiparams{'REMOTE_SUBNET'})) { | |
3586 | $errormessage = $Lang::tr{'openvpn prefix remote subnet'}; | |
3587 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3588 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3589 | goto VPNCONF_ERROR; | |
3590 | } | |
3591 | ||
3592 | if ($cgiparams{'OVPN_MGMT'} eq '') { | |
3593 | $cgiparams{'OVPN_MGMT'} = $cgiparams{'DEST_PORT'}; | |
3594 | } | |
3595 | ||
3596 | } | |
3597 | ||
3598 | # if (($cgiparams{'TYPE'} eq 'net') && ($cgiparams{'SIDE'} !~ /^(left|right)$/)) { | |
3599 | # $errormessage = $Lang::tr{'ipfire side is invalid'}; | |
3600 | # goto VPNCONF_ERROR; | |
3601 | # } | |
3602 | ||
3603 | # Check if there is no other entry with this name | |
3604 | if (! $cgiparams{'KEY'}) { | |
3605 | foreach my $key (keys %confighash) { | |
3606 | if ($confighash{$key}[1] eq $cgiparams{'NAME'}) { | |
3607 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
3608 | if ($cgiparams{'TYPE'} eq 'net') { | |
3609 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3610 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3611 | } | |
3612 | goto VPNCONF_ERROR; | |
3613 | } | |
3614 | } | |
3615 | } | |
3616 | ||
3617 | if (($cgiparams{'TYPE'} eq 'net') && (! $cgiparams{'REMOTE'})) { | |
3618 | $errormessage = $Lang::tr{'invalid input for remote host/ip'}; | |
3619 | if ($cgiparams{'TYPE'} eq 'net') { | |
3620 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3621 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3622 | } | |
3623 | goto VPNCONF_ERROR; | |
3624 | } | |
3625 | ||
3626 | if ($cgiparams{'REMOTE'}) { | |
3627 | if (! &General::validip($cgiparams{'REMOTE'})) { | |
3628 | if (! &General::validfqdn ($cgiparams{'REMOTE'})) { | |
3629 | $errormessage = $Lang::tr{'invalid input for remote host/ip'}; | |
3630 | if ($cgiparams{'TYPE'} eq 'net') { | |
3631 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3632 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3633 | } | |
3634 | goto VPNCONF_ERROR; | |
3635 | } else { | |
3636 | if (&valid_dns_host($cgiparams{'REMOTE'})) { | |
3637 | $warnmessage = "$Lang::tr{'check vpn lr'} $cgiparams{'REMOTE'}. $Lang::tr{'dns check failed'}"; | |
3638 | if ($cgiparams{'TYPE'} eq 'net') { | |
3639 | ||
3640 | } | |
3641 | } | |
3642 | } | |
3643 | } | |
3644 | } | |
3645 | if ($cgiparams{'TYPE'} ne 'host') { | |
3646 | unless (&General::validipandmask($cgiparams{'LOCAL_SUBNET'})) { | |
3647 | $errormessage = $Lang::tr{'local subnet is invalid'}; | |
3648 | if ($cgiparams{'TYPE'} eq 'net') { | |
3649 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3650 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3651 | } | |
3652 | goto VPNCONF_ERROR;} | |
3653 | } | |
3654 | # Check if there is no other entry without IP-address and PSK | |
3655 | if ($cgiparams{'REMOTE'} eq '') { | |
3656 | foreach my $key (keys %confighash) { | |
3657 | if(($cgiparams{'KEY'} ne $key) && | |
3658 | ($confighash{$key}[4] eq 'psk' || $cgiparams{'AUTH'} eq 'psk') && | |
3659 | $confighash{$key}[10] eq '') { | |
3660 | $errormessage = $Lang::tr{'you can only define one roadwarrior connection when using pre-shared key authentication'}; | |
3661 | goto VPNCONF_ERROR; | |
3662 | } | |
3663 | } | |
3664 | } | |
3665 | if (($cgiparams{'TYPE'} eq 'net') && (! &General::validipandmask($cgiparams{'REMOTE_SUBNET'}))) { | |
3666 | $errormessage = $Lang::tr{'remote subnet is invalid'}; | |
3667 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3668 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3669 | goto VPNCONF_ERROR; | |
3670 | } | |
3671 | ||
3672 | if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) { | |
3673 | $errormessage = $Lang::tr{'invalid input'}; | |
3674 | goto VPNCONF_ERROR; | |
3675 | } | |
3676 | if ($cgiparams{'EDIT_ADVANCED'} !~ /^(on|off)$/) { | |
3677 | $errormessage = $Lang::tr{'invalid input'}; | |
3678 | goto VPNCONF_ERROR; | |
3679 | } | |
3680 | ||
3681 | #fixplausi | |
3682 | if ($cgiparams{'AUTH'} eq 'psk') { | |
3683 | # if (! length($cgiparams{'PSK'}) ) { | |
3684 | # $errormessage = $Lang::tr{'pre-shared key is too short'}; | |
3685 | # goto VPNCONF_ERROR; | |
3686 | # } | |
3687 | # if ($cgiparams{'PSK'} =~ /['",&]/) { | |
3688 | # $errormessage = $Lang::tr{'invalid characters found in pre-shared key'}; | |
3689 | # goto VPNCONF_ERROR; | |
3690 | # } | |
3691 | } elsif ($cgiparams{'AUTH'} eq 'certreq') { | |
3692 | if ($cgiparams{'KEY'}) { | |
3693 | $errormessage = $Lang::tr{'cant change certificates'}; | |
3694 | goto VPNCONF_ERROR; | |
3695 | } | |
3696 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
3697 | $errormessage = $Lang::tr{'there was no file upload'}; | |
3698 | goto VPNCONF_ERROR; | |
3699 | } | |
3700 | ||
3701 | # Move uploaded certificate request to a temporary file | |
3702 | (my $fh, my $filename) = tempfile( ); | |
3703 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
3704 | $errormessage = $!; | |
3705 | goto VPNCONF_ERROR; | |
3706 | } | |
3707 | ||
3708 | # Sign the certificate request and move it | |
3709 | # Sign the host certificate request | |
3710 | system('/usr/bin/openssl', 'ca', '-days', "$cgiparams{'DAYS_VALID'}", | |
3711 | '-batch', '-notext', | |
3712 | '-in', $filename, | |
3713 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
3714 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
3715 | if ($?) { | |
3716 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
3717 | unlink ($filename); | |
3718 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
3719 | &newcleanssldatabase(); | |
3720 | goto VPNCONF_ERROR; | |
3721 | } else { | |
3722 | unlink ($filename); | |
3723 | &deletebackupcert(); | |
3724 | } | |
3725 | ||
3726 | my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem`; | |
3727 | $temp =~ /Subject:.*CN=(.*)[\n]/; | |
3728 | $temp = $1; | |
3729 | $temp =~ s+/Email+, E+; | |
3730 | $temp =~ s/ ST=/ S=/; | |
3731 | $cgiparams{'CERT_NAME'} = $temp; | |
3732 | $cgiparams{'CERT_NAME'} =~ s/,//g; | |
3733 | $cgiparams{'CERT_NAME'} =~ s/\'//g; | |
3734 | if ($cgiparams{'CERT_NAME'} eq '') { | |
3735 | $errormessage = $Lang::tr{'could not retrieve common name from certificate'}; | |
3736 | goto VPNCONF_ERROR; | |
3737 | } | |
3738 | } elsif ($cgiparams{'AUTH'} eq 'certfile') { | |
3739 | if ($cgiparams{'KEY'}) { | |
3740 | $errormessage = $Lang::tr{'cant change certificates'}; | |
3741 | goto VPNCONF_ERROR; | |
3742 | } | |
3743 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
3744 | $errormessage = $Lang::tr{'there was no file upload'}; | |
3745 | goto VPNCONF_ERROR; | |
3746 | } | |
3747 | # Move uploaded certificate to a temporary file | |
3748 | (my $fh, my $filename) = tempfile( ); | |
3749 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
3750 | $errormessage = $!; | |
3751 | goto VPNCONF_ERROR; | |
3752 | } | |
3753 | ||
3754 | # Verify the certificate has a valid CA and move it | |
3755 | my $validca = 0; | |
3756 | my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/cacert.pem $filename`; | |
3757 | if ($test =~ /: OK/) { | |
3758 | $validca = 1; | |
3759 | } else { | |
3760 | foreach my $key (keys %cahash) { | |
3761 | $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/$cahash{$key}[0]cert.pem $filename`; | |
3762 | if ($test =~ /: OK/) { | |
3763 | $validca = 1; | |
3764 | } | |
3765 | } | |
3766 | } | |
3767 | if (! $validca) { | |
3768 | $errormessage = $Lang::tr{'certificate does not have a valid ca associated with it'}; | |
3769 | unlink ($filename); | |
3770 | goto VPNCONF_ERROR; | |
3771 | } else { | |
3772 | move($filename, "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
3773 | if ($? ne 0) { | |
3774 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
3775 | unlink ($filename); | |
3776 | goto VPNCONF_ERROR; | |
3777 | } | |
3778 | } | |
3779 | ||
3780 | my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem`; | |
3781 | $temp =~ /Subject:.*CN=(.*)[\n]/; | |
3782 | $temp = $1; | |
3783 | $temp =~ s+/Email+, E+; | |
3784 | $temp =~ s/ ST=/ S=/; | |
3785 | $cgiparams{'CERT_NAME'} = $temp; | |
3786 | $cgiparams{'CERT_NAME'} =~ s/,//g; | |
3787 | $cgiparams{'CERT_NAME'} =~ s/\'//g; | |
3788 | if ($cgiparams{'CERT_NAME'} eq '') { | |
3789 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
3790 | $errormessage = $Lang::tr{'could not retrieve common name from certificate'}; | |
3791 | goto VPNCONF_ERROR; | |
3792 | } | |
3793 | } elsif ($cgiparams{'AUTH'} eq 'certgen') { | |
3794 | if ($cgiparams{'KEY'}) { | |
3795 | $errormessage = $Lang::tr{'cant change certificates'}; | |
3796 | goto VPNCONF_ERROR; | |
3797 | } | |
3798 | # Validate input since the form was submitted | |
3799 | if (length($cgiparams{'CERT_NAME'}) >60) { | |
3800 | $errormessage = $Lang::tr{'name too long'}; | |
3801 | goto VPNCONF_ERROR; | |
3802 | } | |
3803 | if ($cgiparams{'CERT_NAME'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) { | |
3804 | $errormessage = $Lang::tr{'invalid input for name'}; | |
3805 | goto VPNCONF_ERROR; | |
3806 | } | |
3807 | if ($cgiparams{'CERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'CERT_EMAIL'}))) { | |
3808 | $errormessage = $Lang::tr{'invalid input for e-mail address'}; | |
3809 | goto VPNCONF_ERROR; | |
3810 | } | |
3811 | if (length($cgiparams{'CERT_EMAIL'}) > 40) { | |
3812 | $errormessage = $Lang::tr{'e-mail address too long'}; | |
3813 | goto VPNCONF_ERROR; | |
3814 | } | |
3815 | if ($cgiparams{'CERT_OU'} ne '' && $cgiparams{'CERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
3816 | $errormessage = $Lang::tr{'invalid input for department'}; | |
3817 | goto VPNCONF_ERROR; | |
3818 | } | |
3819 | if (length($cgiparams{'CERT_ORGANIZATION'}) >60) { | |
3820 | $errormessage = $Lang::tr{'organization too long'}; | |
3821 | goto VPNCONF_ERROR; | |
3822 | } | |
3823 | if ($cgiparams{'CERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) { | |
3824 | $errormessage = $Lang::tr{'invalid input for organization'}; | |
3825 | goto VPNCONF_ERROR; | |
3826 | } | |
3827 | if ($cgiparams{'CERT_CITY'} ne '' && $cgiparams{'CERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
3828 | $errormessage = $Lang::tr{'invalid input for city'}; | |
3829 | goto VPNCONF_ERROR; | |
3830 | } | |
3831 | if ($cgiparams{'CERT_STATE'} ne '' && $cgiparams{'CERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
3832 | $errormessage = $Lang::tr{'invalid input for state or province'}; | |
3833 | goto VPNCONF_ERROR; | |
3834 | } | |
3835 | if ($cgiparams{'CERT_COUNTRY'} !~ /^[A-Z]*$/) { | |
3836 | $errormessage = $Lang::tr{'invalid input for country'}; | |
3837 | goto VPNCONF_ERROR; | |
3838 | } | |
3839 | if ($cgiparams{'CERT_PASS1'} ne '' && $cgiparams{'CERT_PASS2'} ne ''){ | |
3840 | if (length($cgiparams{'CERT_PASS1'}) < 5) { | |
3841 | $errormessage = $Lang::tr{'password too short'}; | |
3842 | goto VPNCONF_ERROR; | |
3843 | } | |
3844 | } | |
3845 | if ($cgiparams{'CERT_PASS1'} ne $cgiparams{'CERT_PASS2'}) { | |
3846 | $errormessage = $Lang::tr{'passwords do not match'}; | |
3847 | goto VPNCONF_ERROR; | |
3848 | } | |
3849 | ||
3850 | # Replace empty strings with a . | |
3851 | (my $ou = $cgiparams{'CERT_OU'}) =~ s/^\s*$/\./; | |
3852 | (my $city = $cgiparams{'CERT_CITY'}) =~ s/^\s*$/\./; | |
3853 | (my $state = $cgiparams{'CERT_STATE'}) =~ s/^\s*$/\./; | |
3854 | ||
3855 | # Create the Host certificate request client | |
3856 | my $pid = open(OPENSSL, "|-"); | |
3857 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto VPNCONF_ERROR;}; | |
3858 | if ($pid) { # parent | |
3859 | print OPENSSL "$cgiparams{'CERT_COUNTRY'}\n"; | |
3860 | print OPENSSL "$state\n"; | |
3861 | print OPENSSL "$city\n"; | |
3862 | print OPENSSL "$cgiparams{'CERT_ORGANIZATION'}\n"; | |
3863 | print OPENSSL "$ou\n"; | |
3864 | print OPENSSL "$cgiparams{'CERT_NAME'}\n"; | |
3865 | print OPENSSL "$cgiparams{'CERT_EMAIL'}\n"; | |
3866 | print OPENSSL ".\n"; | |
3867 | print OPENSSL ".\n"; | |
3868 | close (OPENSSL); | |
3869 | if ($?) { | |
3870 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
3871 | unlink ("${General::swroot}ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
3872 | unlink ("${General::swroot}ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
3873 | goto VPNCONF_ERROR; | |
3874 | } | |
3875 | } else { # child | |
3876 | unless (exec ('/usr/bin/openssl', 'req', '-nodes', '-rand', '/proc/interrupts:/proc/net/rt_cache', | |
3877 | '-newkey', 'rsa:1024', | |
3878 | '-keyout', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem", | |
3879 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem", | |
3880 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) { | |
3881 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
3882 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
3883 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
3884 | goto VPNCONF_ERROR; | |
3885 | } | |
3886 | } | |
3887 | ||
3888 | # Sign the host certificate request | |
3889 | system('/usr/bin/openssl', 'ca', '-days', "$cgiparams{'DAYS_VALID'}", | |
3890 | '-batch', '-notext', | |
3891 | '-in', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem", | |
3892 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
3893 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
3894 | if ($?) { | |
3895 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
3896 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
3897 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
3898 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
3899 | &newcleanssldatabase(); | |
3900 | goto VPNCONF_ERROR; | |
3901 | } else { | |
3902 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
3903 | &deletebackupcert(); | |
3904 | } | |
3905 | ||
3906 | # Create the pkcs12 file | |
3907 | system('/usr/bin/openssl', 'pkcs12', '-export', | |
3908 | '-inkey', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem", | |
3909 | '-in', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
3910 | '-name', $cgiparams{'NAME'}, | |
3911 | '-passout', "pass:$cgiparams{'CERT_PASS1'}", | |
3912 | '-certfile', "${General::swroot}/ovpn/ca/cacert.pem", | |
3913 | '-caname', "$vpnsettings{'ROOTCERT_ORGANIZATION'} CA", | |
3914 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12"); | |
3915 | if ($?) { | |
3916 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
3917 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
3918 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
3919 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12"); | |
3920 | goto VPNCONF_ERROR; | |
3921 | } else { | |
3922 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
3923 | } | |
3924 | } elsif ($cgiparams{'AUTH'} eq 'cert') { | |
3925 | ;# Nothing, just editing | |
3926 | } else { | |
3927 | $errormessage = $Lang::tr{'invalid input for authentication method'}; | |
3928 | goto VPNCONF_ERROR; | |
3929 | } | |
3930 | ||
3931 | # Check if there is no other entry with this common name | |
3932 | if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk')) { | |
3933 | foreach my $key (keys %confighash) { | |
3934 | if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) { | |
3935 | $errormessage = $Lang::tr{'a connection with this common name already exists'}; | |
3936 | goto VPNCONF_ERROR; | |
3937 | } | |
3938 | } | |
3939 | } | |
3940 | ||
3941 | # Save the config | |
3942 | my $key = $cgiparams{'KEY'}; | |
3943 | ||
3944 | if (! $key) { | |
3945 | $key = &General::findhasharraykey (\%confighash); | |
3946 | foreach my $i (0 .. 38) { $confighash{$key}[$i] = "";} | |
3947 | } | |
3948 | $confighash{$key}[0] = $cgiparams{'ENABLED'}; | |
3949 | $confighash{$key}[1] = $cgiparams{'NAME'}; | |
3950 | if ((! $cgiparams{'KEY'}) && $cgiparams{'AUTH'} ne 'psk') { | |
3951 | $confighash{$key}[2] = $cgiparams{'CERT_NAME'}; | |
3952 | } | |
3953 | ||
3954 | $confighash{$key}[3] = $cgiparams{'TYPE'}; | |
3955 | if ($cgiparams{'AUTH'} eq 'psk') { | |
3956 | $confighash{$key}[4] = 'psk'; | |
3957 | $confighash{$key}[5] = $cgiparams{'PSK'}; | |
3958 | } else { | |
3959 | $confighash{$key}[4] = 'cert'; | |
3960 | } | |
3961 | if ($cgiparams{'TYPE'} eq 'net') { | |
3962 | $confighash{$key}[6] = $cgiparams{'SIDE'}; | |
3963 | $confighash{$key}[11] = $cgiparams{'REMOTE_SUBNET'}; | |
3964 | } | |
3965 | $confighash{$key}[8] = $cgiparams{'LOCAL_SUBNET'}; | |
3966 | $confighash{$key}[10] = $cgiparams{'REMOTE'}; | |
3967 | if ($cgiparams{'OVPN_MGMT'} eq '') { | |
3968 | $confighash{$key}[22] = $confighash{$key}[29]; | |
3969 | } else { | |
3970 | $confighash{$key}[22] = $cgiparams{'OVPN_MGMT'}; | |
3971 | } | |
3972 | $confighash{$key}[23] = $cgiparams{'MSSFIX'}; | |
3973 | $confighash{$key}[24] = $cgiparams{'FRAGMENT'}; | |
3974 | $confighash{$key}[25] = $cgiparams{'REMARK'}; | |
3975 | $confighash{$key}[26] = $cgiparams{'INTERFACE'}; | |
3976 | # new fields | |
3977 | $confighash{$key}[27] = $cgiparams{'OVPN_SUBNET'}; | |
3978 | $confighash{$key}[28] = $cgiparams{'PROTOCOL'}; | |
3979 | $confighash{$key}[29] = $cgiparams{'DEST_PORT'}; | |
3980 | $confighash{$key}[30] = $cgiparams{'COMPLZO'}; | |
3981 | $confighash{$key}[31] = $cgiparams{'MTU'}; | |
3982 | $confighash{$key}[32] = $cgiparams{'CHECK1'}; | |
3983 | $name=$cgiparams{'CHECK1'}; | |
3984 | $confighash{$key}[33] = $cgiparams{$name}; | |
3985 | $confighash{$key}[34] = $cgiparams{'RG'}; | |
3986 | $confighash{$key}[35] = $cgiparams{'CCD_DNS1'}; | |
3987 | $confighash{$key}[36] = $cgiparams{'CCD_DNS2'}; | |
3988 | $confighash{$key}[37] = $cgiparams{'CCD_WINS'}; | |
3989 | $confighash{$key}[38] = $cgiparams{'PMTU_DISCOVERY'}; | |
3990 | ||
3991 | ||
3992 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3993 | ||
3994 | if ($cgiparams{'CHECK1'} ){ | |
3995 | ||
3996 | my ($ccdip,$ccdsub)=split "/",$cgiparams{$name}; | |
3997 | my ($a,$b,$c,$d) = split (/\./,$ccdip); | |
3998 | if ( -e "${General::swroot}/ovpn/ccd/$confighash{$key}[2]"){ | |
3999 | unlink "${General::swroot}/ovpn/ccd/$cgiparams{'CERT_NAME'}"; | |
4000 | } | |
4001 | $confighash{$key}[2] =~ s/ /_/gi; | |
4002 | open ( CCDRWCONF,'>',"${General::swroot}/ovpn/ccd/$confighash{$key}[2]") or die "Unable to create clientconfigfile $!"; | |
4003 | print CCDRWCONF "# OpenVPN clientconfig from ccd extension by Copymaster#\n\n"; | |
4004 | if($cgiparams{'CHECK1'} eq 'dynamic'){ | |
4005 | print CCDRWCONF "#This client uses the dynamic pool\n"; | |
4006 | }else{ | |
4007 | print CCDRWCONF "#Ip address client and server\n"; | |
4008 | print CCDRWCONF "ifconfig-push $ccdip ".&General::getlastip($ccdip,1)."\n"; | |
4009 | } | |
4010 | if ($confighash{$key}[34] eq 'on'){ | |
4011 | print CCDRWCONF "\n#Redirect Gateway: \n#All IP traffic is redirected through the vpn \n"; | |
4012 | print CCDRWCONF "push redirect-gateway\n"; | |
4013 | } | |
4014 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
4015 | if ($cgiparams{'IR'} ne ''){ | |
4016 | print CCDRWCONF "\n#Client routes these networks (behind Client)\n"; | |
4017 | foreach my $key (keys %ccdroutehash){ | |
4018 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}){ | |
4019 | foreach my $i ( 1 .. $#{$ccdroutehash{$key}}){ | |
4020 | my ($a,$b)=split (/\//,$ccdroutehash{$key}[$i]); | |
4021 | print CCDRWCONF "iroute $a $b\n"; | |
4022 | } | |
4023 | } | |
4024 | } | |
4025 | } | |
4026 | if ($cgiparams{'IFROUTE'} eq $Lang::tr{'ccd none'} ){$cgiparams{'IFROUTE'}='';} | |
4027 | if ($cgiparams{'IFROUTE'} ne ''){ | |
4028 | print CCDRWCONF "\n#Client gets routes to these networks (behind IPFire)\n"; | |
4029 | foreach my $key (keys %ccdroute2hash){ | |
4030 | if ($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4031 | foreach my $i ( 1 .. $#{$ccdroute2hash{$key}}){ | |
4032 | if($ccdroute2hash{$key}[$i] eq $Lang::tr{'blue'}){ | |
4033 | my %blue=(); | |
4034 | &General::readhash("${General::swroot}/ethernet/settings", \%blue); | |
4035 | print CCDRWCONF "push \"route $blue{BLUE_ADDRESS} $blue{BLUE_NETMASK}\n"; | |
4036 | }elsif($ccdroute2hash{$key}[$i] eq $Lang::tr{'orange'}){ | |
4037 | my %orange=(); | |
4038 | &General::readhash("${General::swroot}/ethernet/settings", \%orange); | |
4039 | print CCDRWCONF "push \"route $orange{ORANGE_ADDRESS} $orange{ORANGE_NETMASK}\n"; | |
4040 | }else{ | |
4041 | my ($a,$b)=split (/\//,$ccdroute2hash{$key}[$i]); | |
4042 | print CCDRWCONF "push \"route $a $b\"\n"; | |
4043 | } | |
4044 | } | |
4045 | } | |
4046 | } | |
4047 | } | |
4048 | if(($cgiparams{'CCD_DNS1'} eq '') && ($cgiparams{'CCD_DNS1'} ne '')){ $cgiparams{'CCD_DNS1'} = $cgiparams{'CCD_DNS2'};$cgiparams{'CCD_DNS2'}='';} | |
4049 | if($cgiparams{'CCD_DNS1'} ne ''){ | |
4050 | print CCDRWCONF "\n#Client gets these nameservers\n"; | |
4051 | print CCDRWCONF "push \"dhcp-option DNS $cgiparams{'CCD_DNS1'}\" \n"; | |
4052 | } | |
4053 | if($cgiparams{'CCD_DNS2'} ne ''){ | |
4054 | print CCDRWCONF "push \"dhcp-option DNS $cgiparams{'CCD_DNS2'}\" \n"; | |
4055 | } | |
4056 | if($cgiparams{'CCD_WINS'} ne ''){ | |
4057 | print CCDRWCONF "\n#Client gets this WINS server\n"; | |
4058 | print CCDRWCONF "push \"dhcp-option WINS $cgiparams{'CCD_WINS'}\" \n"; | |
4059 | } | |
4060 | close CCDRWCONF; | |
4061 | } | |
4062 | ||
4063 | ### | |
4064 | # m.a.d n2n begin | |
4065 | ### | |
4066 | ||
4067 | if ($cgiparams{'TYPE'} eq 'net') { | |
4068 | ||
4069 | if (-e "/var/run/$confighash{$key}[1]n2n.pid") { | |
4070 | system('/usr/local/bin/openvpnctrl', '-kn2n', $confighash{$cgiparams{'KEY'}}[1]); | |
4071 | ||
4072 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
4073 | my $key = $cgiparams{'KEY'}; | |
4074 | if (! $key) { | |
4075 | $key = &General::findhasharraykey (\%confighash); | |
4076 | foreach my $i (0 .. 31) { $confighash{$key}[$i] = "";} | |
4077 | } | |
4078 | $confighash{$key}[0] = 'on'; | |
4079 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
4080 | ||
4081 | system('/usr/local/bin/openvpnctrl', '-sn2n', $confighash{$cgiparams{'KEY'}}[1]); | |
4082 | } | |
4083 | } | |
4084 | ||
4085 | ### | |
4086 | # m.a.d n2n end | |
4087 | ### | |
4088 | ||
4089 | if ($cgiparams{'EDIT_ADVANCED'} eq 'on') { | |
4090 | $cgiparams{'KEY'} = $key; | |
4091 | $cgiparams{'ACTION'} = $Lang::tr{'advanced'}; | |
4092 | } | |
4093 | goto VPNCONF_END; | |
4094 | } else { | |
4095 | $cgiparams{'ENABLED'} = 'on'; | |
4096 | ### | |
4097 | # m.a.d n2n begin | |
4098 | ### | |
4099 | $cgiparams{'MSSFIX'} = 'on'; | |
4100 | $cgiparams{'FRAGMENT'} = '1300'; | |
4101 | $cgiparams{'PMTU_DISCOVERY'} = 'off'; | |
4102 | ### | |
4103 | # m.a.d n2n end | |
4104 | ### | |
4105 | $cgiparams{'SIDE'} = 'left'; | |
4106 | if ( ! -f "${General::swroot}/ovpn/ca/cakey.pem" ) { | |
4107 | $cgiparams{'AUTH'} = 'psk'; | |
4108 | } elsif ( ! -f "${General::swroot}/ovpn/ca/cacert.pem") { | |
4109 | $cgiparams{'AUTH'} = 'certfile'; | |
4110 | } else { | |
4111 | $cgiparams{'AUTH'} = 'certgen'; | |
4112 | } | |
4113 | $cgiparams{'LOCAL_SUBNET'} ="$netsettings{'GREEN_NETADDRESS'}/$netsettings{'GREEN_NETMASK'}"; | |
4114 | $cgiparams{'CERT_ORGANIZATION'} = $vpnsettings{'ROOTCERT_ORGANIZATION'}; | |
4115 | $cgiparams{'CERT_CITY'} = $vpnsettings{'ROOTCERT_CITY'}; | |
4116 | $cgiparams{'CERT_STATE'} = $vpnsettings{'ROOTCERT_STATE'}; | |
4117 | $cgiparams{'CERT_COUNTRY'} = $vpnsettings{'ROOTCERT_COUNTRY'}; | |
4118 | } | |
4119 | ||
4120 | VPNCONF_ERROR: | |
4121 | $checked{'ENABLED'}{'off'} = ''; | |
4122 | $checked{'ENABLED'}{'on'} = ''; | |
4123 | $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = 'CHECKED'; | |
4124 | $checked{'ENABLED_BLUE'}{'off'} = ''; | |
4125 | $checked{'ENABLED_BLUE'}{'on'} = ''; | |
4126 | $checked{'ENABLED_BLUE'}{$cgiparams{'ENABLED_BLUE'}} = 'CHECKED'; | |
4127 | $checked{'ENABLED_ORANGE'}{'off'} = ''; | |
4128 | $checked{'ENABLED_ORANGE'}{'on'} = ''; | |
4129 | $checked{'ENABLED_ORANGE'}{$cgiparams{'ENABLED_ORANGE'}} = 'CHECKED'; | |
4130 | ||
4131 | ||
4132 | $checked{'EDIT_ADVANCED'}{'off'} = ''; | |
4133 | $checked{'EDIT_ADVANCED'}{'on'} = ''; | |
4134 | $checked{'EDIT_ADVANCED'}{$cgiparams{'EDIT_ADVANCED'}} = 'CHECKED'; | |
4135 | ||
4136 | $selected{'SIDE'}{'server'} = ''; | |
4137 | $selected{'SIDE'}{'client'} = ''; | |
4138 | $selected{'SIDE'}{$cgiparams{'SIDE'}} = 'SELECTED'; | |
4139 | ||
4140 | $selected{'PROTOCOL'}{'udp'} = ''; | |
4141 | $selected{'PROTOCOL'}{'tcp'} = ''; | |
4142 | $selected{'PROTOCOL'}{$cgiparams{'PROTOCOL'}} = 'SELECTED'; | |
4143 | ||
4144 | ||
4145 | $checked{'AUTH'}{'psk'} = ''; | |
4146 | $checked{'AUTH'}{'certreq'} = ''; | |
4147 | $checked{'AUTH'}{'certgen'} = ''; | |
4148 | $checked{'AUTH'}{'certfile'} = ''; | |
4149 | $checked{'AUTH'}{$cgiparams{'AUTH'}} = 'CHECKED'; | |
4150 | ||
4151 | $selected{'INTERFACE'}{$cgiparams{'INTERFACE'}} = 'SELECTED'; | |
4152 | ||
4153 | $checked{'COMPLZO'}{'off'} = ''; | |
4154 | $checked{'COMPLZO'}{'on'} = ''; | |
4155 | $checked{'COMPLZO'}{$cgiparams{'COMPLZO'}} = 'CHECKED'; | |
4156 | ||
4157 | $checked{'MSSFIX'}{'off'} = ''; | |
4158 | $checked{'MSSFIX'}{'on'} = ''; | |
4159 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
4160 | ||
4161 | if ($cgiparams{'PMTU_DISCOVERY'} eq '') { | |
4162 | $cgiparams{'PMTU_DISCOVERY'} = 'off'; | |
4163 | } | |
4164 | $checked{'PMTU_DISCOVERY'}{$cgiparams{'PMTU_DISCOVERY'}} = 'checked=\'checked\''; | |
4165 | ||
4166 | ||
4167 | if (1) { | |
4168 | &Header::showhttpheaders(); | |
4169 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
4170 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
4171 | if ($errormessage) { | |
4172 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
4173 | print "<class name='base'>$errormessage"; | |
4174 | print " </class>"; | |
4175 | &Header::closebox(); | |
4176 | } | |
4177 | ||
4178 | if ($warnmessage) { | |
4179 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'warning messages'}:"); | |
4180 | print "<class name='base'>$warnmessage"; | |
4181 | print " </class>"; | |
4182 | &Header::closebox(); | |
4183 | } | |
4184 | ||
4185 | print "<form method='post' enctype='multipart/form-data'>"; | |
4186 | print "<input type='hidden' name='TYPE' value='$cgiparams{'TYPE'}' />"; | |
4187 | ||
4188 | if ($cgiparams{'KEY'}) { | |
4189 | print "<input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />"; | |
4190 | print "<input type='hidden' name='AUTH' value='$cgiparams{'AUTH'}' />"; | |
4191 | } | |
4192 | ||
4193 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'connection'}:"); | |
4194 | print "<table width='100%' border='0'>\n"; | |
4195 | ||
4196 | ||
4197 | ||
4198 | print "<tr><td width='14%' class='boldbase'>$Lang::tr{'name'}: </td>"; | |
4199 | ||
4200 | if ($cgiparams{'TYPE'} eq 'host') { | |
4201 | if ($cgiparams{'KEY'}) { | |
4202 | print "<td width='35%' class='base'><input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />$cgiparams{'NAME'}</td>"; | |
4203 | } else { | |
4204 | ||
4205 | print "<td width='35%'><input type='text' name='NAME' value='$cgiparams{'NAME'}' maxlength='20' size='30' /></td>"; | |
4206 | } | |
4207 | # print "<tr><td>$Lang::tr{'interface'}</td>"; | |
4208 | # print "<td><select name='INTERFACE'>"; | |
4209 | # print "<option value='RED' $selected{'INTERFACE'}{'RED'}>RED</option>"; | |
4210 | # if ($netsettings{'BLUE_DEV'} ne '') { | |
4211 | # print "<option value='BLUE' $selected{'INTERFACE'}{'BLUE'}>BLUE</option>"; | |
4212 | # } | |
4213 | # print "<option value='GREEN' $selected{'INTERFACE'}{'GREEN'}>GREEN</option>"; | |
4214 | # print "<option value='ORANGE' $selected{'INTERFACE'}{'ORANGE'}>ORANGE</option>"; | |
4215 | # print "</select></td></tr>"; | |
4216 | # print <<END | |
4217 | } else { | |
4218 | print "<input type='hidden' name='INTERFACE' value='red' />"; | |
4219 | if ($cgiparams{'KEY'}) { | |
4220 | print "<td width='25%' class='base' nowrap='nowrap'><input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />$cgiparams{'NAME'}</td>"; | |
4221 | } else { | |
4222 | print "<td width='25%'><input type='text' name='NAME' value='$cgiparams{'NAME'}' maxlength='20' /></td>"; | |
4223 | } | |
4224 | ||
4225 | ||
4226 | ||
4227 | print <<END | |
4228 | <td width='25%'> </td> | |
4229 | <td width='25%'> </td></tr> | |
4230 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'Act as'}</td> | |
4231 | <td><select name='SIDE'><option value='server' $selected{'SIDE'}{'server'}>$Lang::tr{'openvpn server'}</option> | |
4232 | <option value='client' $selected{'SIDE'}{'client'}>$Lang::tr{'openvpn client'}</option></select></td> | |
4233 | <td class='boldbase'>$Lang::tr{'remote host/ip'}:</td> | |
4234 | <td><input type='TEXT' name='REMOTE' value='$cgiparams{'REMOTE'}' /></td></tr> | |
4235 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'}</td> | |
4236 | <td><input type='TEXT' name='LOCAL_SUBNET' value='$cgiparams{'LOCAL_SUBNET'}' /></td> | |
4237 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'}</td> | |
4238 | <td><input type='text' name='REMOTE_SUBNET' value='$cgiparams{'REMOTE_SUBNET'}' /></td></tr> | |
4239 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn subnet'}</td> | |
4240 | <td><input type='TEXT' name='OVPN_SUBNET' value='$cgiparams{'OVPN_SUBNET'}' /></td></tr> | |
4241 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td> | |
4242 | ||
4243 | <td><select name='PROTOCOL'><option value='udp' $selected{'PROTOCOL'}{'udp'}>UDP</option> | |
4244 | <option value='tcp' $selected{'PROTOCOL'}{'tcp'}>TCP</option></select></td> | |
4245 | ||
4246 | <td class='boldbase'>$Lang::tr{'destination port'}:</td> | |
4247 | <td><input type='TEXT' name='DEST_PORT' value='$cgiparams{'DEST_PORT'}' size='5' /></td></tr> | |
4248 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'} <img src='/blob.gif'</td> | |
4249 | <td><input type='checkbox' name='COMPLZO' $checked{'COMPLZO'}{'on'} /></td> | |
4250 | ||
4251 | <tr><td class='boldbase' nowrap='nowrap'>mssfix <img src='/blob.gif' /></td> | |
4252 | <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td> | |
4253 | <td>$Lang::tr{'openvpn default'}: <span class="base">on</span></td> | |
4254 | ||
4255 | <tr><td class='boldbase' nowrap='nowrap'>fragment <img src='/blob.gif' /></td> | |
4256 | <td><input type='TEXT' name='FRAGMENT' VALUE='$cgiparams{'FRAGMENT'}'size='5' /></td> | |
4257 | <td>$Lang::tr{'openvpn default'}: <span class="base">1300</span></td> | |
4258 | ||
4259 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'} <img src='/blob.gif' /></td> | |
4260 | <td> <input type='TEXT' name='MTU' VALUE='$cgiparams{'MTU'}'size='5' /></td> | |
4261 | <td colspan='2'>$Lang::tr{'openvpn default'}: udp/tcp <span class="base">1500/1400</span></td> | |
4262 | ||
4263 | <tr><td class='boldbase' nowrap='nowrap'>Management Port <img src='/blob.gif' /></td> | |
4264 | <td> <input type='TEXT' name='OVPN_MGMT' VALUE='$cgiparams{'OVPN_MGMT'}'size='5' /></td> | |
4265 | <td colspan='2'>$Lang::tr{'openvpn default'}: <span class="base">$Lang::tr{'destination port'}</span></td> | |
4266 | ||
4267 | <tr> | |
4268 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn mtu-disc'}</td> | |
4269 | <td colspan='3'> | |
4270 | <input type='radio' name='PMTU_DISCOVERY' value='yes' $checked{'PMTU_DISCOVERY'}{'yes'} /> $Lang::tr{'ovpn mtu-disc yes'} | |
4271 | <input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked{'PMTU_DISCOVERY'}{'maybe'} /> $Lang::tr{'ovpn mtu-disc maybe'} | |
4272 | <input type='radio' name='PMTU_DISCOVERY' value='no' $checked{'PMTU_DISCOVERY'}{'no'} /> $Lang::tr{'ovpn mtu-disc no'} | |
4273 | <input type='radio' name='PMTU_DISCOVERY' value='off' $checked{'PMTU_DISCOVERY'}{'off'} /> $Lang::tr{'ovpn mtu-disc off'} | |
4274 | </td> | |
4275 | </tr> | |
4276 | ||
4277 | END | |
4278 | ; | |
4279 | } | |
4280 | #jumper | |
4281 | print "<tr><td class='boldbase'>$Lang::tr{'remark title'} <img src='/blob.gif' /></td>"; | |
4282 | print "<td colspan='3'><input type='text' name='REMARK' value='$cgiparams{'REMARK'}' size='55' maxlength='50' /></td></tr></table>"; | |
4283 | ||
4284 | if ($cgiparams{'TYPE'} eq 'host') { | |
4285 | print "<tr><td>$Lang::tr{'enabled'} <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>"; | |
4286 | } | |
4287 | ||
4288 | print"</tr></table><br><br>"; | |
4289 | #A.Marx CCD new client | |
4290 | if ($cgiparams{'TYPE'} eq 'host') { | |
4291 | 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>"; | |
4292 | my %vpnnet=(); | |
4293 | my $vpnip; | |
4294 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnnet); | |
4295 | $vpnip=$vpnnet{'DOVPN_SUBNET'}; | |
4296 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
4297 | my @ccdconf=(); | |
4298 | my $count=0; | |
4299 | my $checked; | |
4300 | $checked{'check1'}{'off'} = ''; | |
4301 | $checked{'check1'}{'on'} = ''; | |
4302 | $checked{'check1'}{$cgiparams{'CHECK1'}} = 'CHECKED'; | |
4303 | 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%'>"; | |
4304 | print"</td></tr></table><br><br>"; | |
4305 | my $name=$cgiparams{'CHECK1'}; | |
4306 | $checked{'RG'}{$cgiparams{'RG'}} = 'CHECKED'; | |
4307 | ||
4308 | if (! -z "${General::swroot}/ovpn/ccd.conf"){ | |
4309 | 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>"; | |
4310 | foreach my $key (sort { uc($ccdconfhash{$a}[0]) cmp uc($ccdconfhash{$b}[0]) } keys %ccdconfhash) { | |
4311 | $count++; | |
4312 | @ccdconf=($ccdconfhash{$key}[0],$ccdconfhash{$key}[1]); | |
4313 | if ($count % 2){print"<tr bgcolor='$color{'color22'}'>";}else{print"<tr bgcolor='$color{'color20'}'>";} | |
4314 | 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%'>"; | |
4315 | &fillselectbox($ccdconf[1],$ccdconf[0],$cgiparams{$name}); | |
4316 | print"</td></tr>"; | |
4317 | } | |
4318 | print "</table><br><br><hr><br><br>"; | |
4319 | } | |
4320 | } | |
4321 | # ccd end | |
4322 | &Header::closebox(); | |
4323 | if ($cgiparams{'KEY'} && $cgiparams{'AUTH'} eq 'psk') { | |
4324 | ||
4325 | } elsif (! $cgiparams{'KEY'}) { | |
4326 | ||
4327 | ||
4328 | my $disabled=''; | |
4329 | my $cakeydisabled=''; | |
4330 | my $cacrtdisabled=''; | |
4331 | if ( ! -f "${General::swroot}/ovpn/ca/cakey.pem" ) { $cakeydisabled = "disabled='disabled'" } else { $cakeydisabled = "" }; | |
4332 | if ( ! -f "${General::swroot}/ovpn/ca/cacert.pem" ) { $cacrtdisabled = "disabled='disabled'" } else { $cacrtdisabled = "" }; | |
4333 | ||
4334 | &Header::openbox('100%', 'LEFT', $Lang::tr{'authentication'}); | |
4335 | ||
4336 | ||
4337 | if ($cgiparams{'TYPE'} eq 'host') { | |
4338 | ||
4339 | print <<END | |
4340 | <table width='100%' cellpadding='0' cellspacing='5' border='0'> | |
4341 | ||
4342 | <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> | |
4343 | <tr><td><input type='radio' name='AUTH' value='certfile' $checked{'AUTH'}{'certfile'} $cacrtdisabled /></td><td class='base'>$Lang::tr{'upload a certificate'}</td></tr> | |
4344 | <tr><td colspan='3'> </td></tr> | |
4345 | <tr><td colspan='3'><hr /></td></tr> | |
4346 | <tr><td colspan='3'> </td></tr> | |
4347 | <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> | |
4348 | <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> | |
4349 | <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> | |
4350 | <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> | |
4351 | <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> | |
4352 | <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> | |
4353 | <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> | |
4354 | <tr><td> </td><td class='base'>$Lang::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled> | |
4355 | END | |
4356 | ; | |
4357 | ||
4358 | ### | |
4359 | # m.a.d net2net | |
4360 | ### | |
4361 | ||
4362 | } else { | |
4363 | ||
4364 | print <<END | |
4365 | <table width='100%' cellpadding='0' cellspacing='5' border='0'> | |
4366 | ||
4367 | <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> | |
4368 | <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> | |
4369 | <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> | |
4370 | <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> | |
4371 | <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> | |
4372 | <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> | |
4373 | <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> | |
4374 | <tr><td> </td><td class='base'>$Lang::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled> | |
4375 | ||
4376 | ||
4377 | END | |
4378 | ; | |
4379 | ||
4380 | } | |
4381 | ||
4382 | ### | |
4383 | # m.a.d net2net | |
4384 | ### | |
4385 | ||
4386 | foreach my $country (sort keys %{Countries::countries}) { | |
4387 | print "<option value='$Countries::countries{$country}'"; | |
4388 | if ( $Countries::countries{$country} eq $cgiparams{'CERT_COUNTRY'} ) { | |
4389 | print " selected='selected'"; | |
4390 | } | |
4391 | print ">$country</option>"; | |
4392 | } | |
4393 | ### | |
4394 | # m.a.d net2net | |
4395 | ### | |
4396 | ||
4397 | if ($cgiparams{'TYPE'} eq 'host') { | |
4398 | print <<END | |
4399 | </select></td></tr> | |
4400 | ||
4401 | <td> </td><td class='base'>$Lang::tr{'valid till'} (days):</td> | |
4402 | <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value='$cgiparams{'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr> | |
4403 | <tr><td> </td> | |
4404 | <td class='base'>$Lang::tr{'pkcs12 file password'}:</td> | |
4405 | <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value='$cgiparams{'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr> | |
4406 | <tr><td> </td><td class='base'>$Lang::tr{'pkcs12 file password'}:<BR>($Lang::tr{'confirmation'})</td> | |
4407 | <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value='$cgiparams{'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr> | |
4408 | <tr><td colspan='3'> </td></tr> | |
4409 | <tr><td colspan='3'><hr /></td></tr> | |
4410 | <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang::tr{'this field may be blank'}</td></tr> | |
4411 | </table> | |
4412 | END | |
4413 | }else{ | |
4414 | print <<END | |
4415 | </select></td></tr> | |
4416 | <tr><td> </td><td> </td><td> </td></tr> | |
4417 | <tr><td> </td><td> </td><td> </td></tr> | |
4418 | <tr><td colspan='3'><hr /></td></tr> | |
4419 | <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang::tr{'this field may be blank'}</td></tr> | |
4420 | </table> | |
4421 | ||
4422 | END | |
4423 | } | |
4424 | ||
4425 | ### | |
4426 | # m.a.d net2net | |
4427 | ### | |
4428 | ; | |
4429 | &Header::closebox(); | |
4430 | ||
4431 | } | |
4432 | ||
4433 | #A.Marx CCD new client | |
4434 | if ($cgiparams{'TYPE'} eq 'host') { | |
4435 | print"<br><br>"; | |
4436 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ccd client options'}:"); | |
4437 | ||
4438 | ||
4439 | print <<END; | |
4440 | <table border='0' width='100%'> | |
4441 | <tr><td width='20%'>Redirect Gateway:</td><td colspan='3'><input type='checkbox' name='RG' $checked{'RG'}{'on'} /></td></tr> | |
4442 | <tr><td colspan='4'><b><br>$Lang::tr{'ccd routes'}</b></td></tr> | |
4443 | <tr><td colspan='4'> </td></tr> | |
4444 | <tr><td valign='top'>$Lang::tr{'ccd iroute'}</td><td align='left' width='30%'><textarea name='IR' cols='26' rows='6' wrap='off'> | |
4445 | END | |
4446 | ||
4447 | if ($cgiparams{'IR'} ne ''){ | |
4448 | print $cgiparams{'IR'}; | |
4449 | }else{ | |
4450 | &General::readhasharray ("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
4451 | foreach my $key (keys %ccdroutehash) { | |
4452 | if( $cgiparams{'NAME'} eq $ccdroutehash{$key}[0]){ | |
4453 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { | |
4454 | if ($ccdroutehash{$key}[$i] ne ''){ | |
4455 | print $ccdroutehash{$key}[$i]."\n"; | |
4456 | } | |
4457 | $cgiparams{'IR'} .= $ccdroutehash{$key}[$i]; | |
4458 | } | |
4459 | } | |
4460 | } | |
4461 | } | |
4462 | ||
4463 | print <<END; | |
4464 | </textarea></td><td valign='top' colspan='2'>$Lang::tr{'ccd iroutehint'}</td></tr> | |
4465 | <tr><td colspan='4'><br></td></tr> | |
4466 | <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> | |
4467 | END | |
4468 | ||
4469 | my $set=0; | |
4470 | my $selorange=0; | |
4471 | my $selblue=0; | |
4472 | my $selgreen=0; | |
4473 | my $helpblue=0; | |
4474 | my $helporange=0; | |
4475 | my $other=0; | |
4476 | my $none=0; | |
4477 | my @temp=(); | |
4478 | ||
4479 | our @current = (); | |
4480 | open(FILE, "${General::swroot}/main/routing") ; | |
4481 | @current = <FILE>; | |
4482 | close (FILE); | |
4483 | &General::readhasharray ("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
4484 | #check for "none" | |
4485 | foreach my $key (keys %ccdroute2hash) { | |
4486 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4487 | if ($ccdroute2hash{$key}[1] eq ''){ | |
4488 | $none=1; | |
4489 | last; | |
4490 | } | |
4491 | } | |
4492 | } | |
4493 | if ($none ne '1'){ | |
4494 | print"<option>$Lang::tr{'ccd none'}</option>"; | |
4495 | }else{ | |
4496 | print"<option selected>$Lang::tr{'ccd none'}</option>"; | |
4497 | } | |
4498 | #check if static routes are defined for client | |
4499 | foreach my $line (@current) { | |
4500 | chomp($line); | |
4501 | $line=~s/\s*$//g; # remove newline | |
4502 | @temp=split(/\,/,$line); | |
4503 | $temp[1] = '' unless defined $temp[1]; # not always populated | |
4504 | my ($a,$b) = split(/\//,$temp[1]); | |
4505 | $temp[1] = $a."/".&General::iporsubtocidr($b); | |
4506 | foreach my $key (keys %ccdroute2hash) { | |
4507 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4508 | foreach my $i (1 .. $#{$ccdroute2hash{$key}}) { | |
4509 | if($ccdroute2hash{$key}[$i] eq $a."/".&General::iporsubtodec($b)){ | |
4510 | $set=1; | |
4511 | } | |
4512 | } | |
4513 | } | |
4514 | } | |
4515 | if ($set == '1' && $#temp != -1){ print"<option selected>$temp[1]</option>";$set=0;}elsif($set == '0' && $#temp != -1){print"<option>$temp[1]</option>";} | |
4516 | } | |
4517 | #check if green,blue,orange are defined for client | |
4518 | foreach my $key (keys %ccdroute2hash) { | |
4519 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4520 | $other=1; | |
4521 | foreach my $i (1 .. $#{$ccdroute2hash{$key}}) { | |
4522 | if ($ccdroute2hash{$key}[$i] eq $netsettings{'GREEN_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'GREEN_NETMASK'})){ | |
4523 | $selgreen=1; | |
4524 | } | |
4525 | if (&haveBlueNet()){ | |
4526 | if( $ccdroute2hash{$key}[$i] eq $netsettings{'BLUE_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'BLUE_NETMASK'})) { | |
4527 | $selblue=1; | |
4528 | } | |
4529 | } | |
4530 | if (&haveOrangeNet()){ | |
4531 | if( $ccdroute2hash{$key}[$i] eq $netsettings{'ORANGE_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'ORANGE_NETMASK'}) ) { | |
4532 | $selorange=1; | |
4533 | } | |
4534 | } | |
4535 | } | |
4536 | } | |
4537 | } | |
4538 | if (&haveBlueNet() && $selblue == '1'){ print"<option selected>$Lang::tr{'blue'}</option>";$selblue=0;}elsif(&haveBlueNet() && $selblue == '0'){print"<option>$Lang::tr{'blue'}</option>";} | |
4539 | if (&haveOrangeNet() && $selorange == '1'){ print"<option selected>$Lang::tr{'orange'}</option>";$selorange=0;}elsif(&haveOrangeNet() && $selorange == '0'){print"<option>$Lang::tr{'orange'}</option>";} | |
4540 | if ($selgreen == '1' || $other == '0'){ print"<option selected>$Lang::tr{'green'}</option>";$set=0;}else{print"<option>$Lang::tr{'green'}</option>";}; | |
4541 | ||
4542 | print<<END | |
4543 | </select></td><td valign='top'>DNS1:</td><td valign='top'><input type='TEXT' name='CCD_DNS1' value='$cgiparams{'CCD_DNS1'}' size='30' /></td></tr> | |
4544 | <tr valign='top'><td>DNS2:</td><td><input type='TEXT' name='CCD_DNS2' value='$cgiparams{'CCD_DNS2'}' size='30' /></td></tr> | |
4545 | <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> | |
4546 | ||
4547 | END | |
4548 | ; | |
4549 | &Header::closebox(); | |
4550 | } | |
4551 | print "<div align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' />"; | |
4552 | if ($cgiparams{'KEY'}) { | |
4553 | # print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />"; | |
4554 | } | |
4555 | print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>"; | |
4556 | &Header::closebigbox(); | |
4557 | &Header::closepage(); | |
4558 | exit (0); | |
4559 | } | |
4560 | VPNCONF_END: | |
4561 | } | |
4562 | ||
4563 | # SETTINGS_ERROR: | |
4564 | ### | |
4565 | ### Default status page | |
4566 | ### | |
4567 | %cgiparams = (); | |
4568 | %cahash = (); | |
4569 | %confighash = (); | |
4570 | &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams); | |
4571 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
4572 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
4573 | ||
4574 | my @status = `/bin/cat /var/log/ovpnserver.log`; | |
4575 | ||
4576 | if ($cgiparams{'VPN_IP'} eq '' && -e "${General::swroot}/red/active") { | |
4577 | if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) { | |
4578 | my $ipaddr = <IPADDR>; | |
4579 | close IPADDR; | |
4580 | chomp ($ipaddr); | |
4581 | $cgiparams{'VPN_IP'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0]; | |
4582 | if ($cgiparams{'VPN_IP'} eq '') { | |
4583 | $cgiparams{'VPN_IP'} = $ipaddr; | |
4584 | } | |
4585 | } | |
4586 | } | |
4587 | ||
4588 | #default setzen | |
4589 | if ($cgiparams{'DCIPHER'} eq '') { | |
4590 | $cgiparams{'DCIPHER'} = 'BF-CBC'; | |
4591 | } | |
4592 | if ($cgiparams{'DDEST_PORT'} eq '') { | |
4593 | $cgiparams{'DDEST_PORT'} = '1194'; | |
4594 | } | |
4595 | if ($cgiparams{'DMTU'} eq '') { | |
4596 | $cgiparams{'DMTU'} = '1400'; | |
4597 | } | |
4598 | if ($cgiparams{'DOVPN_SUBNET'} eq '') { | |
4599 | $cgiparams{'DOVPN_SUBNET'} = '10.' . int(rand(256)) . '.' . int(rand(256)) . '.0/255.255.255.0'; | |
4600 | } | |
4601 | $checked{'ENABLED'}{'off'} = ''; | |
4602 | $checked{'ENABLED'}{'on'} = ''; | |
4603 | $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = 'CHECKED'; | |
4604 | $checked{'ENABLED_BLUE'}{'off'} = ''; | |
4605 | $checked{'ENABLED_BLUE'}{'on'} = ''; | |
4606 | $checked{'ENABLED_BLUE'}{$cgiparams{'ENABLED_BLUE'}} = 'CHECKED'; | |
4607 | $checked{'ENABLED_ORANGE'}{'off'} = ''; | |
4608 | $checked{'ENABLED_ORANGE'}{'on'} = ''; | |
4609 | $checked{'ENABLED_ORANGE'}{$cgiparams{'ENABLED_ORANGE'}} = 'CHECKED'; | |
4610 | $selected{'DDEVICE'}{'tun'} = ''; | |
4611 | $selected{'DDEVICE'}{'tap'} = ''; | |
4612 | $selected{'DDEVICE'}{$cgiparams{'DDEVICE'}} = 'SELECTED'; | |
4613 | ||
4614 | $selected{'DPROTOCOL'}{'udp'} = ''; | |
4615 | $selected{'DPROTOCOL'}{'tcp'} = ''; | |
4616 | $selected{'DPROTOCOL'}{$cgiparams{'DPROTOCOL'}} = 'SELECTED'; | |
4617 | ||
4618 | $selected{'DCIPHER'}{'DES-CBC'} = ''; | |
4619 | $selected{'DCIPHER'}{'DES-EDE-CBC'} = ''; | |
4620 | $selected{'DCIPHER'}{'DES-EDE3-CBC'} = ''; | |
4621 | $selected{'DCIPHER'}{'DESX-CBC'} = ''; | |
4622 | $selected{'DCIPHER'}{'RC2-CBC'} = ''; | |
4623 | $selected{'DCIPHER'}{'RC2-40-CBC'} = ''; | |
4624 | $selected{'DCIPHER'}{'RC2-64-CBC'} = ''; | |
4625 | $selected{'DCIPHER'}{'BF-CBC'} = ''; | |
4626 | $selected{'DCIPHER'}{'CAST5-CBC'} = ''; | |
4627 | $selected{'DCIPHER'}{'AES-128-CBC'} = ''; | |
4628 | $selected{'DCIPHER'}{'AES-192-CBC'} = ''; | |
4629 | $selected{'DCIPHER'}{'AES-256-CBC'} = ''; | |
4630 | $selected{'DCIPHER'}{$cgiparams{'DCIPHER'}} = 'SELECTED'; | |
4631 | $checked{'DCOMPLZO'}{'off'} = ''; | |
4632 | $checked{'DCOMPLZO'}{'on'} = ''; | |
4633 | $checked{'DCOMPLZO'}{$cgiparams{'DCOMPLZO'}} = 'CHECKED'; | |
4634 | # m.a.d | |
4635 | $checked{'MSSFIX'}{'off'} = ''; | |
4636 | $checked{'MSSFIX'}{'on'} = ''; | |
4637 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
4638 | #new settings | |
4639 | &Header::showhttpheaders(); | |
4640 | &Header::openpage($Lang::tr{'status ovpn'}, 1, ''); | |
4641 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
4642 | ||
4643 | if ($errormessage) { | |
4644 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
4645 | print "<class name='base'>$errormessage\n"; | |
4646 | print " </class>\n"; | |
4647 | &Header::closebox(); | |
4648 | } | |
4649 | ||
4650 | 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>"; | |
4651 | my $srunning = "no"; | |
4652 | my $activeonrun = ""; | |
4653 | if ( -e "/var/run/openvpn.pid"){ | |
4654 | $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>"; | |
4655 | $srunning ="yes"; | |
4656 | $activeonrun = ""; | |
4657 | } else { | |
4658 | $activeonrun = "disabled='disabled'"; | |
4659 | } | |
4660 | &Header::openbox('100%', 'LEFT', $Lang::tr{'global settings'}); | |
4661 | print <<END | |
4662 | <table width='100%' border=0> | |
4663 | <form method='post'> | |
4664 | <td width='25%'> </td> | |
4665 | <td width='25%'> </td> | |
4666 | <td width='25%'> </td></tr> | |
4667 | <tr><td class='boldbase'>$Lang::tr{'ovpn server status'}</td> | |
4668 | <td align='left'>$sactive</td> | |
4669 | <tr><td class='boldbase'>$Lang::tr{'ovpn on red'}</td> | |
4670 | <td><input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td> | |
4671 | END | |
4672 | ; | |
4673 | if (&haveBlueNet()) { | |
4674 | print "<tr><td class='boldbase'>$Lang::tr{'ovpn on blue'}</td>"; | |
4675 | print "<td><input type='checkbox' name='ENABLED_BLUE' $checked{'ENABLED_BLUE'}{'on'} /></td>"; | |
4676 | } | |
4677 | if (&haveOrangeNet()) { | |
4678 | print "<tr><td class='boldbase'>$Lang::tr{'ovpn on orange'}</td>"; | |
4679 | print "<td><input type='checkbox' name='ENABLED_ORANGE' $checked{'ENABLED_ORANGE'}{'on'} /></td>"; | |
4680 | } | |
4681 | print <<END | |
4682 | <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> | |
4683 | <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> | |
4684 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn device'}</td> | |
4685 | <td><select name='DDEVICE' ><option value='tun' $selected{'DDEVICE'}{'tun'}>TUN</option> | |
4686 | <!-- this is still not working | |
4687 | <option value='tap' $selected{'DDEVICE'}{'tap'}>TAP</option></select>--> </td> | |
4688 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td> | |
4689 | <td><select name='DPROTOCOL'><option value='udp' $selected{'DPROTOCOL'}{'udp'}>UDP</option> | |
4690 | <option value='tcp' $selected{'DPROTOCOL'}{'tcp'}>TCP</option></select></td> | |
4691 | <td class='boldbase'>$Lang::tr{'destination port'}:</td> | |
4692 | <td><input type='TEXT' name='DDEST_PORT' value='$cgiparams{'DDEST_PORT'}' size='5' /></td></tr> | |
4693 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'} </td> | |
4694 | <td> <input type='TEXT' name='DMTU' VALUE='$cgiparams{'DMTU'}'size='5' /></TD> | |
4695 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td> | |
4696 | <td><input type='checkbox' name='DCOMPLZO' $checked{'DCOMPLZO'}{'on'} /></td> | |
4697 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'cipher'}</td> | |
4698 | <td><select name='DCIPHER'><option value='DES-CBC' $selected{'DCIPHER'}{'DES-CBC'}>DES-CBC</option> | |
4699 | <option value='DES-EDE-CBC' $selected{'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC</option> | |
4700 | <option value='DES-EDE3-CBC' $selected{'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC</option> | |
4701 | <option value='DESX-CBC' $selected{'DCIPHER'}{'DESX-CBC'}>DESX-CBC</option> | |
4702 | <option value='RC2-CBC' $selected{'DCIPHER'}{'RC2-CBC'}>RC2-CBC</option> | |
4703 | <option value='RC2-40-CBC' $selected{'DCIPHER'}{'RC2-40-CBC'}>RC2-40-CBC</option> | |
4704 | <option value='RC2-64-CBC' $selected{'DCIPHER'}{'RC2-64-CBC'}>RC2-64-CBC</option> | |
4705 | <option value='BF-CBC' $selected{'DCIPHER'}{'BF-CBC'}>BF-CBC</option> | |
4706 | <option value='CAST5-CBC' $selected{'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC</option> | |
4707 | <option value='AES-128-CBC' $selected{'DCIPHER'}{'AES-128-CBC'}>AES-128-CBC</option> | |
4708 | <option value='AES-192-CBC' $selected{'DCIPHER'}{'AES-192-CBC'}>AES-192-CBC</option> | |
4709 | <option value='AES-256-CBC' $selected{'DCIPHER'}{'AES-256-CBC'}>AES-256-CBC</option></select></td></tr> | |
4710 | <tr><td colspan='4'><hr /></td></tr> | |
4711 | END | |
4712 | ; | |
4713 | ||
4714 | if ( $srunning eq "yes" ) { | |
4715 | print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' disabled='disabled' />"; | |
4716 | print "<input type='submit' name='ACTION' value='$Lang::tr{'ccd net'}' />"; | |
4717 | print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced server'}' />"; | |
4718 | print "<input type='submit' name='ACTION' value='$Lang::tr{'stop ovpn server'}' /></td></tr>"; | |
4719 | } else{ | |
4720 | print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' />"; | |
4721 | print "<input type='submit' name='ACTION' value='$Lang::tr{'ccd net'}' />"; | |
4722 | print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced server'}' />"; | |
4723 | if (( -e "${General::swroot}/ovpn/ca/cacert.pem" && | |
4724 | -e "${General::swroot}/ovpn/ca/dh1024.pem" && | |
4725 | -e "${General::swroot}/ovpn/certs/servercert.pem" && | |
4726 | -e "${General::swroot}/ovpn/certs/serverkey.pem") && | |
4727 | (( $cgiparams{'ENABLED'} eq 'on') || | |
4728 | ( $cgiparams{'ENABLED_BLUE'} eq 'on') || | |
4729 | ( $cgiparams{'ENABLED_ORANGE'} eq 'on'))){ | |
4730 | print "<input type='submit' name='ACTION' value='$Lang::tr{'start ovpn server'}' /></td></tr>"; | |
4731 | } else { | |
4732 | print "<input type='submit' name='ACTION' value='$Lang::tr{'start ovpn server'}' disabled='disabled' /></td></tr>"; | |
4733 | } | |
4734 | } | |
4735 | print "</form></table>"; | |
4736 | &Header::closebox(); | |
4737 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate authorities'}:"); | |
4738 | print <<EOF#' | |
4739 | <table width='100%' border='0' cellspacing='1' cellpadding='0'> | |
4740 | <tr> | |
4741 | <td width='25%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></td> | |
4742 | <td width='65%' class='boldbase' align='center'><b>$Lang::tr{'subject'}</b></td> | |
4743 | <td width='10%' class='boldbase' colspan='3' align='center'><b>$Lang::tr{'action'}</b></td> | |
4744 | </tr> | |
4745 | EOF | |
4746 | ; | |
4747 | if (-f "${General::swroot}/ovpn/ca/cacert.pem") { | |
4748 | my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem`; | |
4749 | $casubject =~ /Subject: (.*)[\n]/; | |
4750 | $casubject = $1; | |
4751 | $casubject =~ s+/Email+, E+; | |
4752 | $casubject =~ s/ ST=/ S=/; | |
4753 | ||
4754 | print <<END | |
4755 | <tr bgcolor='$color{'color22'}'> | |
4756 | <td class='base'>$Lang::tr{'root certificate'}</td> | |
4757 | <td class='base'>$casubject</td> | |
4758 | <form method='post' name='frmrootcrta'><td width='3%' align='center'> | |
4759 | <input type='hidden' name='ACTION' value='$Lang::tr{'show root certificate'}' /> | |
4760 | <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' /> | |
4761 | </td></form> | |
4762 | <form method='post' name='frmrootcrtb'><td width='3%' align='center'> | |
4763 | <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' /> | |
4764 | <input type='hidden' name='ACTION' value='$Lang::tr{'download root certificate'}' /> | |
4765 | </td></form> | |
4766 | <td width='4%'> </td></tr> | |
4767 | END | |
4768 | ; | |
4769 | } else { | |
4770 | # display rootcert generation buttons | |
4771 | print <<END | |
4772 | <tr bgcolor='$color{'color22'}'> | |
4773 | <td class='base'>$Lang::tr{'root certificate'}:</td> | |
4774 | <td class='base'>$Lang::tr{'not present'}</td> | |
4775 | <td colspan='3'> </td></tr> | |
4776 | END | |
4777 | ; | |
4778 | } | |
4779 | ||
4780 | if (-f "${General::swroot}/ovpn/certs/servercert.pem") { | |
4781 | my $hostsubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
4782 | $hostsubject =~ /Subject: (.*)[\n]/; | |
4783 | $hostsubject = $1; | |
4784 | $hostsubject =~ s+/Email+, E+; | |
4785 | $hostsubject =~ s/ ST=/ S=/; | |
4786 | ||
4787 | print <<END | |
4788 | <tr bgcolor='$color{'color20'}'> | |
4789 | <td class='base'>$Lang::tr{'host certificate'}</td> | |
4790 | <td class='base'>$hostsubject</td> | |
4791 | <form method='post' name='frmhostcrta'><td width='3%' align='center'> | |
4792 | <input type='hidden' name='ACTION' value='$Lang::tr{'show host certificate'}' /> | |
4793 | <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' /> | |
4794 | </td></form> | |
4795 | <form method='post' name='frmhostcrtb'><td width='3%' align='center'> | |
4796 | <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' /> | |
4797 | <input type='hidden' name='ACTION' value='$Lang::tr{'download host certificate'}' /> | |
4798 | </td></form> | |
4799 | <td width='4%'> </td></tr> | |
4800 | END | |
4801 | ; | |
4802 | } else { | |
4803 | # Nothing | |
4804 | print <<END | |
4805 | <tr bgcolor='$color{'color20'}'> | |
4806 | <td width='25%' class='base'>$Lang::tr{'host certificate'}:</td> | |
4807 | <td class='base'>$Lang::tr{'not present'}</td> | |
4808 | </td><td colspan='3'> </td></tr> | |
4809 | END | |
4810 | ; | |
4811 | } | |
4812 | ||
4813 | if (! -f "${General::swroot}/ovpn/ca/cacert.pem") { | |
4814 | print "<tr><td colspan='5' align='center'><form method='post'>"; | |
4815 | print "<input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' />"; | |
4816 | print "</form></td></tr>\n"; | |
4817 | } | |
4818 | ||
4819 | if (keys %cahash > 0) { | |
4820 | foreach my $key (keys %cahash) { | |
4821 | if (($key + 1) % 2) { | |
4822 | print "<tr bgcolor='$color{'color20'}'>\n"; | |
4823 | } else { | |
4824 | print "<tr bgcolor='$color{'color22'}'>\n"; | |
4825 | } | |
4826 | print "<td class='base'>$cahash{$key}[0]</td>\n"; | |
4827 | print "<td class='base'>$cahash{$key}[1]</td>\n"; | |
4828 | print <<END | |
4829 | <form method='post' name='cafrm${key}a'><td align='center'> | |
4830 | <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' /> | |
4831 | <input type='hidden' name='ACTION' value='$Lang::tr{'show ca certificate'}' /> | |
4832 | <input type='hidden' name='KEY' value='$key' /> | |
4833 | </td></form> | |
4834 | <form method='post' name='cafrm${key}b'><td align='center'> | |
4835 | <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' /> | |
4836 | <input type='hidden' name='ACTION' value='$Lang::tr{'download ca certificate'}' /> | |
4837 | <input type='hidden' name='KEY' value='$key' /> | |
4838 | </td></form> | |
4839 | <form method='post' name='cafrm${key}c'><td align='center'> | |
4840 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove ca certificate'}' /> | |
4841 | <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' /> | |
4842 | <input type='hidden' name='KEY' value='$key' /> | |
4843 | </td></form></tr> | |
4844 | END | |
4845 | ; | |
4846 | } | |
4847 | } | |
4848 | ||
4849 | print "</table>"; | |
4850 | ||
4851 | # If the file contains entries, print Key to action icons | |
4852 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem") { | |
4853 | print <<END | |
4854 | <table> | |
4855 | <tr> | |
4856 | <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td> | |
4857 | <td> <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td> | |
4858 | <td class='base'>$Lang::tr{'show certificate'}</td> | |
4859 | <td> <img src='/images/media-floppy.png' alt='$Lang::tr{'download certificate'}' /></td> | |
4860 | <td class='base'>$Lang::tr{'download certificate'}</td> | |
4861 | </tr> | |
4862 | </table> | |
4863 | END | |
4864 | ; | |
4865 | } | |
4866 | ||
4867 | print <<END | |
4868 | <form method='post' enctype='multipart/form-data'> | |
4869 | <table width='100%' border='0'> | |
4870 | <tr><td class='base' nowrap='nowrap'>$Lang::tr{'ca name'}:</td><td nowrap='nowrap' width='8%'><input type='text' name='CA_NAME' value='$cgiparams{'CA_NAME'}' size='15' align='left'/></td><td nowrap='nowrap' align='right'><input type='file' name='FH' size='25' /><input type='submit' name='ACTION' value='$Lang::tr{'upload ca certificate'}' /></td></tr> | |
4871 | <tr><td colspan='4'><hr /></td></tr> | |
4872 | <tr align='right'><td colspan='4' align='right' width='80%'><input type='submit' name='ACTION' value='$Lang::tr{'show crl'}' /></td></tr> | |
4873 | </table> | |
4874 | END | |
4875 | ; | |
4876 | ||
4877 | ||
4878 | &Header::closebox(); | |
4879 | if ( $srunning eq "yes" ) { | |
4880 | print "<div align='center'><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'reset'}' disabled='disabled' /></div></form>\n"; | |
4881 | }else{ | |
4882 | print "<div align='center'><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'reset'}' /></div></form>\n"; | |
4883 | } | |
4884 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) { | |
4885 | ||
4886 | ### | |
4887 | # m.a.d net2net | |
4888 | #<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> | |
4889 | ### | |
4890 | ||
4891 | &Header::openbox('100%', 'LEFT', $Lang::tr{'Client status and controlc' }); | |
4892 | print <<END | |
4893 | ||
4894 | ||
4895 | <table width='100%' border='0' cellspacing='1' cellpadding='0'> | |
4896 | <tr> | |
4897 | <td width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></td> | |
4898 | <td width='15%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></td> | |
4899 | <td width='22%' class='boldbase' align='center'><b>$Lang::tr{'network'}</b></td> | |
4900 | <td width='20%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></td> | |
4901 | <td width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></td> | |
4902 | <td width='5%' class='boldbase' colspan='6' align='center'><b>$Lang::tr{'action'}</b></td> | |
4903 | </tr> | |
4904 | END | |
4905 | ; | |
4906 | my $id = 0; | |
4907 | my $gif; | |
4908 | foreach my $key (sort { uc($confighash{$a}[1]) cmp uc($confighash{$b}[1]) } keys %confighash) { | |
4909 | if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; } | |
4910 | ||
4911 | if ($id % 2) { | |
4912 | print "<tr bgcolor='$color{'color20'}'>\n"; | |
4913 | } else { | |
4914 | print "<tr bgcolor='$color{'color22'}'>\n"; | |
4915 | } | |
4916 | print "<td align='center' nowrap='nowrap'>$confighash{$key}[1]</td>"; | |
4917 | print "<td align='center' nowrap='nowrap'>" . $Lang::tr{"$confighash{$key}[3]"} . " (" . $Lang::tr{"$confighash{$key}[4]"} . ")</td>"; | |
4918 | #if ($confighash{$key}[4] eq 'cert') { | |
4919 | #print "<td align='left' nowrap='nowrap'>$confighash{$key}[2]</td>"; | |
4920 | #} else { | |
4921 | #print "<td align='left'> </td>"; | |
4922 | #} | |
4923 | my $cavalid = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem`; | |
4924 | $cavalid =~ /Not After : (.*)[\n]/; | |
4925 | $cavalid = $1; | |
4926 | if ($confighash{$key}[32] eq "" && $confighash{$key}[3] eq 'net' ){$confighash{$key}[32]="net-2-net";} | |
4927 | if ($confighash{$key}[32] eq "" && $confighash{$key}[3] eq 'host' ){$confighash{$key}[32]="dynamic";} | |
4928 | print "<td align='center'>$confighash{$key}[32]</td>"; | |
4929 | print "<td align='center'>$confighash{$key}[25]</td>"; | |
4930 | ||
4931 | my $active = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourred}' width='100%'><tr><td align='center'><b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b></td></tr></table>"; | |
4932 | ||
4933 | if ($confighash{$key}[0] eq 'off') { | |
4934 | $active = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourblue}' width='100%'><tr><td align='center'><b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b></td></tr></table>"; | |
4935 | } else { | |
4936 | ||
4937 | ### | |
4938 | # m.a.d net2net | |
4939 | ### | |
4940 | ||
4941 | if ($confighash{$key}[3] eq 'net') { | |
4942 | ||
4943 | if (-e "/var/run/$confighash{$key}[1]n2n.pid") { | |
4944 | my @output = ""; | |
4945 | my @tustate = ""; | |
4946 | my $tport = $confighash{$key}[22]; | |
4947 | my $tnet = new Net::Telnet ( Timeout=>5, Errmode=>'return', Port=>$tport); | |
4948 | if ($tport ne '') { | |
4949 | $tnet->open('127.0.0.1'); | |
4950 | @output = $tnet->cmd(String => 'state', Prompt => '/(END.*\n|ERROR:.*\n)/'); | |
4951 | @tustate = split(/\,/, $output[1]); | |
4952 | ### | |
4953 | #CONNECTING -- OpenVPN's initial state. | |
4954 | #WAIT -- (Client only) Waiting for initial response from server. | |
4955 | #AUTH -- (Client only) Authenticating with server. | |
4956 | #GET_CONFIG -- (Client only) Downloading configuration options from server. | |
4957 | #ASSIGN_IP -- Assigning IP address to virtual network interface. | |
4958 | #ADD_ROUTES -- Adding routes to system. | |
4959 | #CONNECTED -- Initialization Sequence Completed. | |
4960 | #RECONNECTING -- A restart has occurred. | |
4961 | #EXITING -- A graceful exit is in progress. | |
4962 | #### | |
4963 | ||
4964 | if ( $tustate[1] eq 'CONNECTED') { | |
4965 | $active = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourgreen}' width='100%'><tr><td align='center'><b><font color='#FFFFFF'>$Lang::tr{'capsopen'}</font></b></tr></td></table>"; | |
4966 | } else { | |
4967 | $active = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourred}' width='100%'><tr><td align='center'><b><font color='#FFFFFF'>$tustate[1]</font></b></td></tr></table>"; | |
4968 | } | |
4969 | } | |
4970 | } | |
4971 | } else { | |
4972 | ||
4973 | my $cn; | |
4974 | my @match = (); | |
4975 | foreach my $line (@status) { | |
4976 | chomp($line); | |
4977 | if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) { | |
4978 | @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line); | |
4979 | if ($match[1] ne "Common Name") { | |
4980 | $cn = $match[1]; | |
4981 | } | |
4982 | $cn =~ s/[_]/ /g; | |
4983 | if ($cn eq "$confighash{$key}[2]") { | |
4984 | $active = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourgreen}' width='100%'><tr><td align='center'><b><font color='#FFFFFF'>$Lang::tr{'capsopen'}</font></b></td></tr></table>"; | |
4985 | } | |
4986 | } | |
4987 | ||
4988 | } | |
4989 | } | |
4990 | } | |
4991 | ||
4992 | ||
4993 | print <<END | |
4994 | <td align='center'>$active</td> | |
4995 | ||
4996 | <form method='post' name='frm${key}a'><td align='center'> | |
4997 | <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' /> | |
4998 | <input type='hidden' name='ACTION' value='$Lang::tr{'dl client arch'}' /> | |
4999 | <input type='hidden' name='KEY' value='$key' /> | |
5000 | </td></form> | |
5001 | END | |
5002 | ; | |
5003 | if ($confighash{$key}[4] eq 'cert') { | |
5004 | print <<END | |
5005 | <form method='post' name='frm${key}b'><td align='center'> | |
5006 | <input type='image' name='$Lang::tr{'show certificate'}' src='/images/info.gif' alt='$Lang::tr{'show certificate'}' title='$Lang::tr{'show certificate'}' border='0' /> | |
5007 | <input type='hidden' name='ACTION' value='$Lang::tr{'show certificate'}' /> | |
5008 | <input type='hidden' name='KEY' value='$key' /> | |
5009 | </td></form> | |
5010 | END | |
5011 | ; } else { | |
5012 | print "<td> </td>"; | |
5013 | } | |
5014 | if ($confighash{$key}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$key}[1].p12") { | |
5015 | print <<END | |
5016 | <form method='post' name='frm${key}c'><td align='center'> | |
5017 | <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' /> | |
5018 | <input type='hidden' name='ACTION' value='$Lang::tr{'download pkcs12 file'}' /> | |
5019 | <input type='hidden' name='KEY' value='$key' /> | |
5020 | </td></form> | |
5021 | END | |
5022 | ; } elsif ($confighash{$key}[4] eq 'cert') { | |
5023 | print <<END | |
5024 | <form method='post' name='frm${key}c'><td align='center'> | |
5025 | <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' /> | |
5026 | <input type='hidden' name='ACTION' value='$Lang::tr{'download certificate'}' /> | |
5027 | <input type='hidden' name='KEY' value='$key' /> | |
5028 | </td></form> | |
5029 | END | |
5030 | ; } else { | |
5031 | print "<td> </td>"; | |
5032 | } | |
5033 | print <<END | |
5034 | <form method='post' name='frm${key}d'><td align='center'> | |
5035 | <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' /> | |
5036 | <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' /> | |
5037 | <input type='hidden' name='KEY' value='$key' /> | |
5038 | </td></form> | |
5039 | ||
5040 | <form method='post' name='frm${key}e'><td align='center'> | |
5041 | <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' /> | |
5042 | <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'/> | |
5043 | <input type='hidden' name='KEY' value='$key' /> | |
5044 | </td></form> | |
5045 | <form method='post' name='frm${key}f'><td align='center'> | |
5046 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' /> | |
5047 | <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' /> | |
5048 | <input type='hidden' name='KEY' value='$key' /> | |
5049 | </td></form> | |
5050 | </tr> | |
5051 | END | |
5052 | ; | |
5053 | $id++; | |
5054 | } | |
5055 | ; | |
5056 | ||
5057 | # If the config file contains entries, print Key to action icons | |
5058 | if ( $id ) { | |
5059 | print <<END | |
5060 | <table border='0'> | |
5061 | <tr> | |
5062 | <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td> | |
5063 | <td> <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td> | |
5064 | <td class='base'>$Lang::tr{'click to disable'}</td> | |
5065 | <td> <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td> | |
5066 | <td class='base'>$Lang::tr{'show certificate'}</td> | |
5067 | <td> <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td> | |
5068 | <td class='base'>$Lang::tr{'edit'}</td> | |
5069 | <td> <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td> | |
5070 | <td class='base'>$Lang::tr{'remove'}</td> | |
5071 | </tr> | |
5072 | <tr> | |
5073 | <td> </td> | |
5074 | <td> <img src='/images/off.gif' alt='?OFF' /></td> | |
5075 | <td class='base'>$Lang::tr{'click to enable'}</td> | |
5076 | <td> <img src='/images/media-floppy.png' alt='?FLOPPY' /></td> | |
5077 | <td class='base'>$Lang::tr{'download certificate'}</td> | |
5078 | <td> <img src='/images/openvpn.png' alt='?RELOAD'/></td> | |
5079 | <td class='base'>$Lang::tr{'dl client arch'}</td> | |
5080 | </tr> | |
5081 | </table><hr> | |
5082 | END | |
5083 | ; | |
5084 | } | |
5085 | ||
5086 | print <<END | |
5087 | <table width='100%'> | |
5088 | <form method='post'> | |
5089 | <tr><td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /> | |
5090 | <input type='submit' name='ACTION' value='$Lang::tr{'ovpn con stat'}' $activeonrun /></td></tr> | |
5091 | </form> | |
5092 | </table> | |
5093 | END | |
5094 | ; | |
5095 | &Header::closebox(); | |
5096 | } | |
5097 | &Header::closepage(); | |
5098 | ||
5099 | ||
5100 |