]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/vpnmain.cgi
7489e5390efd5b001e659a70c482c6d9d797b905
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / vpnmain.cgi
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 use Net::DNS;
23 use File::Copy;
24 use File::Temp qw/ tempfile tempdir /;
25 use strict;
26 use Sort::Naturally;
27 # enable only the following on debugging purpose
28 #use warnings;
29 #use CGI::Carp 'fatalsToBrowser';
30
31 require '/var/ipfire/general-functions.pl';
32 require "${General::swroot}/lang.pl";
33 require "${General::swroot}/header.pl";
34 require "${General::swroot}/countries.pl";
35
36 #workaround to suppress a warning when a variable is used only once
37 my @dummy = ( ${Header::colourgreen}, ${Header::colourblue} );
38 undef (@dummy);
39
40 ###
41 ### Initialize variables
42 ###
43 my $sleepDelay = 4; # after a call to ipsecctrl S or R, wait this delay (seconds) before reading status (let the ipsec do its job)
44 my %netsettings=();
45 our %cgiparams=();
46 our %vpnsettings=();
47 my %checked=();
48 my %confighash=();
49 my %cahash=();
50 my %selected=();
51 my $warnmessage = '';
52 my $errormessage = '';
53
54 my %color = ();
55 my %mainsettings = ();
56 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
57 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
58
59 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
60
61 my %INACTIVITY_TIMEOUTS = (
62 300 => $Lang::tr{'five minutes'},
63 600 => $Lang::tr{'ten minutes'},
64 900 => $Lang::tr{'fifteen minutes'},
65 1800 => $Lang::tr{'thirty minutes'},
66 3600 => $Lang::tr{'one hour'},
67 43200 => $Lang::tr{'twelve hours'},
68 86400 => $Lang::tr{'24 hours'},
69 0 => "- $Lang::tr{'unlimited'} -",
70 );
71
72 my $col="";
73
74 $cgiparams{'ENABLED'} = 'off';
75 $cgiparams{'EDIT_ADVANCED'} = 'off';
76 $cgiparams{'ACTION'} = '';
77 $cgiparams{'CA_NAME'} = '';
78 $cgiparams{'KEY'} = '';
79 $cgiparams{'TYPE'} = '';
80 $cgiparams{'ADVANCED'} = '';
81 $cgiparams{'NAME'} = '';
82 $cgiparams{'LOCAL_SUBNET'} = '';
83 $cgiparams{'REMOTE_SUBNET'} = '';
84 $cgiparams{'REMOTE'} = '';
85 $cgiparams{'LOCAL_ID'} = '';
86 $cgiparams{'REMOTE_ID'} = '';
87 $cgiparams{'REMARK'} = '';
88 $cgiparams{'PSK'} = '';
89 $cgiparams{'CERT_NAME'} = '';
90 $cgiparams{'CERT_EMAIL'} = '';
91 $cgiparams{'CERT_OU'} = '';
92 $cgiparams{'CERT_ORGANIZATION'} = '';
93 $cgiparams{'CERT_CITY'} = '';
94 $cgiparams{'CERT_STATE'} = '';
95 $cgiparams{'CERT_COUNTRY'} = '';
96 $cgiparams{'SUBJECTALTNAME'} = '';
97 $cgiparams{'CERT_PASS1'} = '';
98 $cgiparams{'CERT_PASS2'} = '';
99 $cgiparams{'ROOTCERT_HOSTNAME'} = '';
100 $cgiparams{'ROOTCERT_COUNTRY'} = '';
101 $cgiparams{'P12_PASS'} = '';
102 $cgiparams{'ROOTCERT_ORGANIZATION'} = '';
103 $cgiparams{'ROOTCERT_HOSTNAME'} = '';
104 $cgiparams{'ROOTCERT_EMAIL'} = '';
105 $cgiparams{'ROOTCERT_OU'} = '';
106 $cgiparams{'ROOTCERT_CITY'} = '';
107 $cgiparams{'ROOTCERT_STATE'} = '';
108 $cgiparams{'RW_NET'} = '';
109 $cgiparams{'DPD_DELAY'} = '30';
110 $cgiparams{'DPD_TIMEOUT'} = '120';
111 $cgiparams{'FORCE_MOBIKE'} = 'off';
112 $cgiparams{'START_ACTION'} = 'start';
113 $cgiparams{'INACTIVITY_TIMEOUT'} = 900;
114 &Header::getcgihash(\%cgiparams, {'wantfile' => 1, 'filevar' => 'FH'});
115
116 ###
117 ### Useful functions
118 ###
119 sub valid_dns_host {
120 my $hostname = $_[0];
121 unless ($hostname) { return "No hostname"};
122 my $res = new Net::DNS::Resolver;
123 my $query = $res->search("$hostname");
124 if ($query) {
125 foreach my $rr ($query->answer) {
126 ## Potential bug - we are only looking at A records:
127 return 0 if $rr->type eq "A";
128 }
129 } else {
130 return $res->errorstring;
131 }
132 }
133 ###
134 ### Just return true is one interface is vpn enabled
135 ###
136 sub vpnenabled {
137 return ($vpnsettings{'ENABLED'} eq 'on');
138 }
139 ###
140 ### old version: maintain serial number to one, without explication.
141 ### this: let the counter go, so that each cert is numbered.
142 ###
143 sub cleanssldatabase {
144 if (open(FILE, ">${General::swroot}/certs/serial")) {
145 print FILE "01";
146 close FILE;
147 }
148 if (open(FILE, ">${General::swroot}/certs/index.txt")) {
149 print FILE "";
150 close FILE;
151 }
152 if (open(FILE, ">${General::swroot}/certs/index.txt.attr")) {
153 print FILE "";
154 close FILE;
155 }
156 unlink ("${General::swroot}/certs/index.txt.old");
157 unlink ("${General::swroot}/certs/index.txt.attr.old");
158 unlink ("${General::swroot}/certs/serial.old");
159 unlink ("${General::swroot}/certs/01.pem");
160 }
161 sub newcleanssldatabase {
162 if (! -s "${General::swroot}/certs/serial" ) {
163 open(FILE, ">${General::swroot}/certs/serial");
164 print FILE "01";
165 close FILE;
166 }
167 if (! -s ">${General::swroot}/certs/index.txt") {
168 system ("touch ${General::swroot}/certs/index.txt");
169 }
170 if (! -s ">${General::swroot}/certs/index.txt.attr") {
171 system ("touch ${General::swroot}/certs/index.txt.attr");
172 }
173 unlink ("${General::swroot}/certs/index.txt.old");
174 unlink ("${General::swroot}/certs/index.txt.attr.old");
175 unlink ("${General::swroot}/certs/serial.old");
176 # unlink ("${General::swroot}/certs/01.pem"); numbering evolves. Wrong place to delete
177 }
178
179 ###
180 ### Call openssl and return errormessage if any
181 ###
182 sub callssl ($) {
183 my $opt = shift;
184 my $retssl = `/usr/bin/openssl $opt 2>&1`; #redirect stderr
185 my $ret = '';
186 foreach my $line (split (/\n/, $retssl)) {
187 &General::log("ipsec", "$line") if (0); # 1 for verbose logging
188 $ret .= '<br>'.$line if ( $line =~ /error|unknown/ );
189 }
190 if ($ret) {
191 $ret= &Header::cleanhtml($ret);
192 }
193 return $ret ? "$Lang::tr{'openssl produced an error'}: $ret" : '' ;
194 }
195 ###
196 ### Obtain a CN from given cert
197 ###
198 sub getCNfromcert ($) {
199 #&General::log("ipsec", "Extracting name from $_[0]...");
200 my $temp = `/usr/bin/openssl x509 -text -in $_[0]`;
201 $temp =~ /Subject:.*CN = (.*)[\n]/;
202 $temp = $1;
203 $temp =~ s+/Email+, E+;
204 $temp =~ s/ ST = / S = /;
205 $temp =~ s/,//g;
206 $temp =~ s/\'//g;
207 return $temp;
208 }
209 ###
210 ### Obtain Subject from given cert
211 ###
212 sub getsubjectfromcert ($) {
213 #&General::log("ipsec", "Extracting subject from $_[0]...");
214 my $temp = `/usr/bin/openssl x509 -text -in $_[0]`;
215 $temp =~ /Subject: (.*)[\n]/;
216 $temp = $1;
217 $temp =~ s+/Email+, E+;
218 $temp =~ s/ ST = / S = /;
219 return $temp;
220 }
221 ###
222 ### Combine local subnet and connection name to make a unique name for each connection section
223 ### (this sub is not used now)
224 ###
225 sub makeconnname ($) {
226 my $conn = shift;
227 my $subnet = shift;
228
229 $subnet =~ /^(.*?)\/(.*?)$/; # $1=IP $2=mask
230 my $ip = unpack('N', &Socket::inet_aton($1));
231 if (length ($2) > 2) {
232 my $mm = unpack('N', &Socket::inet_aton($2));
233 while ( ($mm & 1)==0 ) {
234 $ip >>= 1;
235 $mm >>= 1;
236 };
237 } else {
238 $ip >>= (32 - $2);
239 }
240 return sprintf ("%s-%X", $conn, $ip);
241 }
242 ###
243 ### Write a config file.
244 ###
245 ###Type=Host : GUI can choose the interface used (RED,GREEN,BLUE) and
246 ### the side is always defined as 'left'.
247 ###
248
249 sub writeipsecfiles {
250 my %lconfighash = ();
251 my %lvpnsettings = ();
252 &General::readhasharray("${General::swroot}/vpn/config", \%lconfighash);
253 &General::readhash("${General::swroot}/vpn/settings", \%lvpnsettings);
254
255 open(CONF, ">${General::swroot}/vpn/ipsec.conf") or die "Unable to open ${General::swroot}/vpn/ipsec.conf: $!";
256 open(SECRETS, ">${General::swroot}/vpn/ipsec.secrets") or die "Unable to open ${General::swroot}/vpn/ipsec.secrets: $!";
257 flock CONF, 2;
258 flock SECRETS, 2;
259 print CONF "version 2\n\n";
260 print CONF "conn %default\n";
261 print CONF "\tkeyingtries=%forever\n";
262 print CONF "\n";
263
264 # Add user includes to config file
265 if (-e "/etc/ipsec.user.conf") {
266 print CONF "include /etc/ipsec.user.conf\n";
267 print CONF "\n";
268 }
269
270 print SECRETS "include /etc/ipsec.user.secrets\n";
271
272 if (-f "${General::swroot}/certs/hostkey.pem") {
273 print SECRETS ": RSA ${General::swroot}/certs/hostkey.pem\n"
274 }
275 my $last_secrets = ''; # old the less specifics connections
276
277 foreach my $key (keys %lconfighash) {
278 next if ($lconfighash{$key}[0] ne 'on');
279
280 #remote peer is not set? => use '%any'
281 $lconfighash{$key}[10] = '%any' if ($lconfighash{$key}[10] eq '');
282
283 my $localside;
284 if ($lconfighash{$key}[26] eq 'BLUE') {
285 $localside = $netsettings{'BLUE_ADDRESS'};
286 } elsif ($lconfighash{$key}[26] eq 'GREEN') {
287 $localside = $netsettings{'GREEN_ADDRESS'};
288 } elsif ($lconfighash{$key}[26] eq 'ORANGE') {
289 $localside = $netsettings{'ORANGE_ADDRESS'};
290 } else { # it is RED
291 $localside = $lvpnsettings{'VPN_IP'};
292 }
293
294 print CONF "conn $lconfighash{$key}[1]\n";
295 print CONF "\tleft=$localside\n";
296 print CONF "\tleftsubnet=" . &make_subnets($lconfighash{$key}[8]) . "\n";
297 print CONF "\tleftfirewall=yes\n";
298 print CONF "\tlefthostaccess=yes\n";
299 print CONF "\tright=$lconfighash{$key}[10]\n";
300
301 if ($lconfighash{$key}[3] eq 'net') {
302 print CONF "\trightsubnet=" . &make_subnets($lconfighash{$key}[11]) . "\n";
303 }
304
305 # Local Cert and Remote Cert (unless auth is DN dn-auth)
306 if ($lconfighash{$key}[4] eq 'cert') {
307 print CONF "\tleftcert=${General::swroot}/certs/hostcert.pem\n";
308 print CONF "\trightcert=${General::swroot}/certs/$lconfighash{$key}[1]cert.pem\n" if ($lconfighash{$key}[2] ne '%auth-dn');
309 }
310
311 # Local and Remote IDs
312 print CONF "\tleftid=\"$lconfighash{$key}[7]\"\n" if ($lconfighash{$key}[7]);
313 print CONF "\trightid=\"$lconfighash{$key}[9]\"\n" if ($lconfighash{$key}[9]);
314
315 # Is PFS enabled?
316 my $pfs = $lconfighash{$key}[28] eq 'on' ? 'on' : 'off';
317
318 # Algorithms
319 if ($lconfighash{$key}[18] && $lconfighash{$key}[19] && $lconfighash{$key}[20]) {
320 my @encs = split('\|', $lconfighash{$key}[18]);
321 my @ints = split('\|', $lconfighash{$key}[19]);
322 my @groups = split('\|', $lconfighash{$key}[20]);
323
324 my @algos = &make_algos("ike", \@encs, \@ints, \@groups, 1);
325 print CONF "\tike=" . join(",", @algos);
326
327 if ($lconfighash{$key}[24] eq 'on') { #only proposed algorythms?
328 print CONF "!\n";
329 } else {
330 print CONF "\n";
331 }
332 }
333
334 if ($lconfighash{$key}[21] && $lconfighash{$key}[22]) {
335 my @encs = split('\|', $lconfighash{$key}[21]);
336 my @ints = split('\|', $lconfighash{$key}[22]);
337 my @groups = split('\|', $lconfighash{$key}[23]);
338
339 # Use IKE grouptype if no ESP group type has been selected
340 # (for backwards compatibility)
341 if ($lconfighash{$key}[23] eq "") {
342 @groups = split('\|', $lconfighash{$key}[20]);
343 }
344
345 my @algos = &make_algos("esp", \@encs, \@ints, \@groups, ($pfs eq "on"));
346 print CONF "\tesp=" . join(",", @algos);
347
348 if ($lconfighash{$key}[24] eq 'on') { #only proposed algorythms?
349 print CONF "!\n";
350 } else {
351 print CONF "\n";
352 }
353 }
354
355 # IKE V1 or V2
356 if (! $lconfighash{$key}[29]) {
357 $lconfighash{$key}[29] = "ikev1";
358 }
359
360 print CONF "\tkeyexchange=$lconfighash{$key}[29]\n";
361
362 # Lifetimes
363 print CONF "\tikelifetime=$lconfighash{$key}[16]h\n" if ($lconfighash{$key}[16]);
364 print CONF "\tkeylife=$lconfighash{$key}[17]h\n" if ($lconfighash{$key}[17]);
365
366 # Compression
367 print CONF "\tcompress=yes\n" if ($lconfighash{$key}[13] eq 'on');
368
369 # Force MOBIKE?
370 if (($lconfighash{$key}[29] eq "ikev2") && ($lconfighash{$key}[32] eq 'on')) {
371 print CONF "\tmobike=yes\n";
372 }
373
374 # Dead Peer Detection
375 my $dpdaction = $lconfighash{$key}[27];
376 print CONF "\tdpdaction=$dpdaction\n";
377
378 # If the dead peer detection is disabled and IKEv2 is used,
379 # dpddelay must be set to zero, too.
380 if ($dpdaction eq "none") {
381 if ($lconfighash{$key}[29] eq "ikev2") {
382 print CONF "\tdpddelay=0\n";
383 }
384 } else {
385 my $dpddelay = $lconfighash{$key}[31];
386 if (!$dpddelay) {
387 $dpddelay = 30;
388 }
389 print CONF "\tdpddelay=$dpddelay\n";
390 my $dpdtimeout = $lconfighash{$key}[30];
391 if (!$dpdtimeout) {
392 $dpdtimeout = 120;
393 }
394 print CONF "\tdpdtimeout=$dpdtimeout\n";
395 }
396
397 # Build Authentication details: LEFTid RIGHTid : PSK psk
398 my $psk_line;
399 if ($lconfighash{$key}[4] eq 'psk') {
400 $psk_line = ($lconfighash{$key}[7] ? $lconfighash{$key}[7] : $localside) . " " ;
401 $psk_line .= $lconfighash{$key}[9] ? $lconfighash{$key}[9] : $lconfighash{$key}[10]; #remoteid or remote address?
402 $psk_line .= " : PSK '$lconfighash{$key}[5]'\n";
403 # if the line contains %any, it is less specific than two IP or ID, so move it at end of file.
404 if ($psk_line =~ /%any/) {
405 $last_secrets .= $psk_line;
406 } else {
407 print SECRETS $psk_line;
408 }
409 print CONF "\tauthby=secret\n";
410 } else {
411 print CONF "\tauthby=rsasig\n";
412 print CONF "\tleftrsasigkey=%cert\n";
413 print CONF "\trightrsasigkey=%cert\n";
414 }
415
416 my $start_action = $lconfighash{$key}[33];
417 if (!$start_action) {
418 $start_action = "start";
419 }
420
421 my $inactivity_timeout = $lconfighash{$key}[34];
422 if ($inactivity_timeout eq "") {
423 $inactivity_timeout = 900;
424 }
425
426 # Automatically start only if a net-to-net connection
427 if ($lconfighash{$key}[3] eq 'host') {
428 print CONF "\tauto=add\n";
429 print CONF "\trightsourceip=$lvpnsettings{'RW_NET'}\n";
430 } else {
431 print CONF "\tauto=$start_action\n";
432
433 # If in on-demand mode, we terminate the tunnel
434 # after 15 min of no traffic
435 if ($start_action eq 'route' && $inactivity_timeout > 0) {
436 print CONF "\tinactivity=$inactivity_timeout\n";
437 }
438 }
439
440 # Fragmentation
441 print CONF "\tfragmentation=yes\n";
442
443 print CONF "\n";
444 } #foreach key
445
446 # Add post user includes to config file
447 # After the GUI-connections allows to patch connections.
448 if (-e "/etc/ipsec.user-post.conf") {
449 print CONF "include /etc/ipsec.user-post.conf\n";
450 print CONF "\n";
451 }
452
453 print SECRETS $last_secrets if ($last_secrets);
454 close(CONF);
455 close(SECRETS);
456 }
457
458 # Hook to regenerate the configuration files.
459 if ($ENV{"REMOTE_ADDR"} eq "") {
460 writeipsecfiles();
461 exit(0);
462 }
463
464 ###
465 ### Save main settings
466 ###
467 if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq '' && $cgiparams{'KEY'} eq '') {
468 &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings);
469
470 unless (&General::validfqdn($cgiparams{'VPN_IP'}) || &General::validip($cgiparams{'VPN_IP'})
471 || $cgiparams{'VPN_IP'} eq '%defaultroute' ) {
472 $errormessage = $Lang::tr{'invalid input for hostname'};
473 goto SAVE_ERROR;
474 }
475
476 unless ($cgiparams{'VPN_DELAYED_START'} =~ /^[0-9]{1,3}$/ ) { #allow 0-999 seconds !
477 $errormessage = $Lang::tr{'invalid time period'};
478 goto SAVE_ERROR;
479 }
480
481 if ( $cgiparams{'RW_NET'} ne '' and !&General::validipandmask($cgiparams{'RW_NET'}) ) {
482 $errormessage = $Lang::tr{'urlfilter invalid ip or mask error'};
483 goto SAVE_ERROR;
484 }
485
486 $vpnsettings{'ENABLED'} = $cgiparams{'ENABLED'};
487 $vpnsettings{'VPN_IP'} = $cgiparams{'VPN_IP'};
488 $vpnsettings{'VPN_DELAYED_START'} = $cgiparams{'VPN_DELAYED_START'};
489 $vpnsettings{'RW_NET'} = $cgiparams{'RW_NET'};
490 &General::writehash("${General::swroot}/vpn/settings", \%vpnsettings);
491 &writeipsecfiles();
492 if (&vpnenabled) {
493 system('/usr/local/bin/ipsecctrl', 'S');
494 } else {
495 system('/usr/local/bin/ipsecctrl', 'D');
496 }
497 sleep $sleepDelay;
498 SAVE_ERROR:
499 ###
500 ### Reset all step 2
501 ###
502 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove x509'} && $cgiparams{'AREUSURE'} eq 'yes') {
503 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
504
505 foreach my $key (keys %confighash) {
506 if ($confighash{$key}[4] eq 'cert') {
507 delete $confighash{$key};
508 }
509 }
510 while (my $file = glob("${General::swroot}/{ca,certs,crls,private}/*")) {
511 unlink $file
512 }
513 &cleanssldatabase();
514 if (open(FILE, ">${General::swroot}/vpn/caconfig")) {
515 print FILE "";
516 close FILE;
517 }
518 &General::writehasharray("${General::swroot}/vpn/config", \%confighash);
519 &writeipsecfiles();
520 system('/usr/local/bin/ipsecctrl', 'R');
521 sleep $sleepDelay;
522
523 ###
524 ### Reset all step 1
525 ###
526 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove x509'}) {
527 &Header::showhttpheaders();
528 &Header::openpage($Lang::tr{'ipsec'}, 1, '');
529 &Header::openbigbox('100%', 'left', '', '');
530 &Header::openbox('100%', 'left', $Lang::tr{'are you sure'});
531 print <<END
532 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
533 <table width='100%'>
534 <tr>
535 <td align='center'>
536 <input type='hidden' name='AREUSURE' value='yes' />
537 <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>:&nbsp;$Lang::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}
538 </td>
539 </tr><tr>
540 <td align='center'>
541 <input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' />
542 <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td>
543 </tr>
544 </table>
545 </form>
546 END
547 ;
548 &Header::closebox();
549 &Header::closebigbox();
550 &Header::closepage();
551 exit (0);
552
553 ###
554 ### Upload CA Certificate
555 ###
556 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload ca certificate'}) {
557 &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash);
558
559 if ($cgiparams{'CA_NAME'} !~ /^[a-zA-Z0-9]+$/) {
560 $errormessage = $Lang::tr{'name must only contain characters'};
561 goto UPLOADCA_ERROR;
562 }
563
564 if (length($cgiparams{'CA_NAME'}) >60) {
565 $errormessage = $Lang::tr{'name too long'};
566 goto VPNCONF_ERROR;
567 }
568
569 if ($cgiparams{'CA_NAME'} eq 'ca') {
570 $errormessage = $Lang::tr{'name is invalid'};
571 goto UPLOAD_CA_ERROR;
572 }
573
574 # Check if there is no other entry with this name
575 foreach my $key (keys %cahash) {
576 if ($cahash{$key}[0] eq $cgiparams{'CA_NAME'}) {
577 $errormessage = $Lang::tr{'a ca certificate with this name already exists'};
578 goto UPLOADCA_ERROR;
579 }
580 }
581
582 if (ref ($cgiparams{'FH'}) ne 'Fh') {
583 $errormessage = $Lang::tr{'there was no file upload'};
584 goto UPLOADCA_ERROR;
585 }
586 # Move uploaded ca to a temporary file
587 (my $fh, my $filename) = tempfile( );
588 if (copy ($cgiparams{'FH'}, $fh) != 1) {
589 $errormessage = $!;
590 goto UPLOADCA_ERROR;
591 }
592 my $temp = `/usr/bin/openssl x509 -text -in $filename`;
593 if ($temp !~ /CA:TRUE/i) {
594 $errormessage = $Lang::tr{'not a valid ca certificate'};
595 unlink ($filename);
596 goto UPLOADCA_ERROR;
597 } else {
598 move($filename, "${General::swroot}/ca/$cgiparams{'CA_NAME'}cert.pem");
599 if ($? ne 0) {
600 $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
601 unlink ($filename);
602 goto UPLOADCA_ERROR;
603 }
604 }
605
606 my $key = &General::findhasharraykey (\%cahash);
607 $cahash{$key}[0] = $cgiparams{'CA_NAME'};
608 $cahash{$key}[1] = &Header::cleanhtml(getsubjectfromcert ("${General::swroot}/ca/$cgiparams{'CA_NAME'}cert.pem"));
609 &General::writehasharray("${General::swroot}/vpn/caconfig", \%cahash);
610
611 system('/usr/local/bin/ipsecctrl', 'R');
612 sleep $sleepDelay;
613
614 UPLOADCA_ERROR:
615
616 ###
617 ### Display ca certificate
618 ###
619 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show ca certificate'}) {
620 &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash);
621
622 if ( -f "${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem") {
623 &Header::showhttpheaders();
624 &Header::openpage($Lang::tr{'ipsec'}, 1, '');
625 &Header::openbigbox('100%', 'left', '', '');
626 &Header::openbox('100%', 'left', "$Lang::tr{'ca certificate'}:");
627 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`;
628 $output = &Header::cleanhtml($output,"y");
629 print "<pre>$output</pre>\n";
630 &Header::closebox();
631 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'>$Lang::tr{'back'}</a></div>";
632 &Header::closebigbox();
633 &Header::closepage();
634 exit(0);
635 } else {
636 $errormessage = $Lang::tr{'invalid key'};
637 }
638
639 ###
640 ### Export ca certificate to browser
641 ###
642 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download ca certificate'}) {
643 &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash);
644
645 if ( -f "${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) {
646 print "Content-Type: application/force-download\n";
647 print "Content-Type: application/octet-stream\r\n";
648 print "Content-Disposition: attachment; filename=$cahash{$cgiparams{'KEY'}}[0]cert.pem\r\n\r\n";
649 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`;
650 exit(0);
651 } else {
652 $errormessage = $Lang::tr{'invalid key'};
653 }
654
655 ###
656 ### Remove ca certificate (step 2)
657 ###
658 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'} && $cgiparams{'AREUSURE'} eq 'yes') {
659 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
660 &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash);
661
662 if ( -f "${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) {
663 foreach my $key (keys %confighash) {
664 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem ${General::swroot}/certs/$confighash{$key}[1]cert.pem`;
665 if ($test =~ /: OK/) {
666 # Delete connection
667 system('/usr/local/bin/ipsecctrl', 'D', $key) if (&vpnenabled);
668 unlink ("${General::swroot}/certs/$confighash{$key}[1]cert.pem");
669 unlink ("${General::swroot}/certs/$confighash{$key}[1].p12");
670 delete $confighash{$key};
671 &General::writehasharray("${General::swroot}/vpn/config", \%confighash);
672 &writeipsecfiles();
673 }
674 }
675 unlink ("${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem");
676 delete $cahash{$cgiparams{'KEY'}};
677 &General::writehasharray("${General::swroot}/vpn/caconfig", \%cahash);
678 system('/usr/local/bin/ipsecctrl', 'R');
679 sleep $sleepDelay;
680 } else {
681 $errormessage = $Lang::tr{'invalid key'};
682 }
683 ###
684 ### Remove ca certificate (step 1)
685 ###
686 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'}) {
687 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
688 &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash);
689
690 my $assignedcerts = 0;
691 if ( -f "${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) {
692 foreach my $key (keys %confighash) {
693 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem ${General::swroot}/certs/$confighash{$key}[1]cert.pem`;
694 if ($test =~ /: OK/) {
695 $assignedcerts++;
696 }
697 }
698 if ($assignedcerts) {
699 &Header::showhttpheaders();
700 &Header::openpage($Lang::tr{'ipsec'}, 1, '');
701 &Header::openbigbox('100%', 'left', '', '');
702 &Header::openbox('100%', 'left', $Lang::tr{'are you sure'});
703 print <<END
704 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
705 <table width='100%'>
706 <tr>
707 <td align='center'>
708 <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />
709 <input type='hidden' name='AREUSURE' value='yes' /></td>
710 </tr><tr>
711 <td align='center'>
712 <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>&nbsp;$Lang::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}</td>
713 </tr><tr>
714 <td align='center'>
715 <input type='submit' name='ACTION' value='$Lang::tr{'remove ca certificate'}' />
716 <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td>
717 </tr>
718 </table>
719 </form>
720 END
721 ;
722 &Header::closebox();
723 &Header::closebigbox();
724 &Header::closepage();
725 exit (0);
726 } else {
727 unlink ("${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem");
728 delete $cahash{$cgiparams{'KEY'}};
729 &General::writehasharray("${General::swroot}/vpn/caconfig", \%cahash);
730 system('/usr/local/bin/ipsecctrl', 'R');
731 sleep $sleepDelay;
732 }
733 } else {
734 $errormessage = $Lang::tr{'invalid key'};
735 }
736
737 ###
738 ### Display root certificate
739 ###
740 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'} ||
741 $cgiparams{'ACTION'} eq $Lang::tr{'show host certificate'}) {
742 my $output;
743 &Header::showhttpheaders();
744 &Header::openpage($Lang::tr{'ipsec'}, 1, '');
745 &Header::openbigbox('100%', 'left', '', '');
746 if ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'}) {
747 &Header::openbox('100%', 'left', "$Lang::tr{'root certificate'}:");
748 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/cacert.pem`;
749 } else {
750 &Header::openbox('100%', 'left', "$Lang::tr{'host certificate'}:");
751 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/hostcert.pem`;
752 }
753 $output = &Header::cleanhtml($output,"y");
754 print "<pre>$output</pre>\n";
755 &Header::closebox();
756 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'>$Lang::tr{'back'}</a></div>";
757 &Header::closebigbox();
758 &Header::closepage();
759 exit(0);
760
761 ###
762 ### Export root certificate to browser
763 ###
764 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download root certificate'}) {
765 if ( -f "${General::swroot}/ca/cacert.pem" ) {
766 print "Content-Type: application/force-download\n";
767 print "Content-Disposition: attachment; filename=cacert.pem\r\n\r\n";
768 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/cacert.pem`;
769 exit(0);
770 }
771 ###
772 ### Export host certificate to browser
773 ###
774 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download host certificate'}) {
775 if ( -f "${General::swroot}/certs/hostcert.pem" ) {
776 print "Content-Type: application/force-download\n";
777 print "Content-Disposition: attachment; filename=hostcert.pem\r\n\r\n";
778 print `/usr/bin/openssl x509 -in ${General::swroot}/certs/hostcert.pem`;
779 exit(0);
780 }
781 ###
782 ### Form for generating/importing the caroot+host certificate
783 ###
784 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate root/host certificates'} ||
785 $cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) {
786
787 if (-f "${General::swroot}/ca/cacert.pem") {
788 $errormessage = $Lang::tr{'valid root certificate already exists'};
789 goto ROOTCERT_SKIP;
790 }
791
792 &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings);
793 # fill in initial values
794 if ($cgiparams{'ROOTCERT_HOSTNAME'} eq '') {
795 if (-e "${General::swroot}/red/active" && open(IPADDR, "${General::swroot}/red/local-ipaddress")) {
796 my $ipaddr = <IPADDR>;
797 close IPADDR;
798 chomp ($ipaddr);
799 $cgiparams{'ROOTCERT_HOSTNAME'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0];
800 if ($cgiparams{'ROOTCERT_HOSTNAME'} eq '') {
801 $cgiparams{'ROOTCERT_HOSTNAME'} = $ipaddr;
802 }
803 }
804 $cgiparams{'ROOTCERT_COUNTRY'} = $vpnsettings{'ROOTCERT_COUNTRY'} if (!$cgiparams{'ROOTCERT_COUNTRY'});
805 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) {
806 &General::log("ipsec", "Importing from p12...");
807
808 if (ref ($cgiparams{'FH'}) ne 'Fh') {
809 $errormessage = $Lang::tr{'there was no file upload'};
810 goto ROOTCERT_ERROR;
811 }
812
813 # Move uploaded certificate request to a temporary file
814 (my $fh, my $filename) = tempfile( );
815 if (copy ($cgiparams{'FH'}, $fh) != 1) {
816 $errormessage = $!;
817 goto ROOTCERT_ERROR;
818 }
819
820 # Extract the CA certificate from the file
821 &General::log("ipsec", "Extracting caroot from p12...");
822 if (open(STDIN, "-|")) {
823 my $opt = " pkcs12 -cacerts -nokeys";
824 $opt .= " -in $filename";
825 $opt .= " -out /tmp/newcacert";
826 $errormessage = &callssl ($opt);
827 } else { #child
828 print "$cgiparams{'P12_PASS'}\n";
829 exit (0);
830 }
831
832 # Extract the Host certificate from the file
833 if (!$errormessage) {
834 &General::log("ipsec", "Extracting host cert from p12...");
835 if (open(STDIN, "-|")) {
836 my $opt = " pkcs12 -clcerts -nokeys";
837 $opt .= " -in $filename";
838 $opt .= " -out /tmp/newhostcert";
839 $errormessage = &callssl ($opt);
840 } else { #child
841 print "$cgiparams{'P12_PASS'}\n";
842 exit (0);
843 }
844 }
845
846 # Extract the Host key from the file
847 if (!$errormessage) {
848 &General::log("ipsec", "Extracting private key from p12...");
849 if (open(STDIN, "-|")) {
850 my $opt = " pkcs12 -nocerts -nodes";
851 $opt .= " -in $filename";
852 $opt .= " -out /tmp/newhostkey";
853 $errormessage = &callssl ($opt);
854 } else { #child
855 print "$cgiparams{'P12_PASS'}\n";
856 exit (0);
857 }
858 }
859
860 if (!$errormessage) {
861 &General::log("ipsec", "Moving cacert...");
862 move("/tmp/newcacert", "${General::swroot}/ca/cacert.pem");
863 $errormessage = "$Lang::tr{'certificate file move failed'}: $!" if ($? ne 0);
864 }
865
866 if (!$errormessage) {
867 &General::log("ipsec", "Moving host cert...");
868 move("/tmp/newhostcert", "${General::swroot}/certs/hostcert.pem");
869 $errormessage = "$Lang::tr{'certificate file move failed'}: $!" if ($? ne 0);
870 }
871
872 if (!$errormessage) {
873 &General::log("ipsec", "Moving private key...");
874 move("/tmp/newhostkey", "${General::swroot}/certs/hostkey.pem");
875 $errormessage = "$Lang::tr{'certificate file move failed'}: $!" if ($? ne 0);
876 }
877
878 #cleanup temp files
879 unlink ($filename);
880 unlink ('/tmp/newcacert');
881 unlink ('/tmp/newhostcert');
882 unlink ('/tmp/newhostkey');
883 if ($errormessage) {
884 unlink ("${General::swroot}/ca/cacert.pem");
885 unlink ("${General::swroot}/certs/hostcert.pem");
886 unlink ("${General::swroot}/certs/hostkey.pem");
887 goto ROOTCERT_ERROR;
888 }
889
890 # Create empty CRL cannot be done because we don't have
891 # the private key for this CAROOT
892 # IPFire can only import certificates
893
894 &General::log("ipsec", "p12 import completed!");
895 &cleanssldatabase();
896 goto ROOTCERT_SUCCESS;
897
898 } elsif ($cgiparams{'ROOTCERT_COUNTRY'} ne '') {
899
900 # Validate input since the form was submitted
901 if ($cgiparams{'ROOTCERT_ORGANIZATION'} eq ''){
902 $errormessage = $Lang::tr{'organization cant be empty'};
903 goto ROOTCERT_ERROR;
904 }
905 if (length($cgiparams{'ROOTCERT_ORGANIZATION'}) >60) {
906 $errormessage = $Lang::tr{'organization too long'};
907 goto ROOTCERT_ERROR;
908 }
909 if ($cgiparams{'ROOTCERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
910 $errormessage = $Lang::tr{'invalid input for organization'};
911 goto ROOTCERT_ERROR;
912 }
913 if ($cgiparams{'ROOTCERT_HOSTNAME'} eq ''){
914 $errormessage = $Lang::tr{'hostname cant be empty'};
915 goto ROOTCERT_ERROR;
916 }
917 unless (&General::validfqdn($cgiparams{'ROOTCERT_HOSTNAME'}) || &General::validip($cgiparams{'ROOTCERT_HOSTNAME'})) {
918 $errormessage = $Lang::tr{'invalid input for hostname'};
919 goto ROOTCERT_ERROR;
920 }
921 if ($cgiparams{'ROOTCERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'ROOTCERT_EMAIL'}))) {
922 $errormessage = $Lang::tr{'invalid input for e-mail address'};
923 goto ROOTCERT_ERROR;
924 }
925 if (length($cgiparams{'ROOTCERT_EMAIL'}) > 40) {
926 $errormessage = $Lang::tr{'e-mail address too long'};
927 goto ROOTCERT_ERROR;
928 }
929 if ($cgiparams{'ROOTCERT_OU'} ne '' && $cgiparams{'ROOTCERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
930 $errormessage = $Lang::tr{'invalid input for department'};
931 goto ROOTCERT_ERROR;
932 }
933 if ($cgiparams{'ROOTCERT_CITY'} ne '' && $cgiparams{'ROOTCERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
934 $errormessage = $Lang::tr{'invalid input for city'};
935 goto ROOTCERT_ERROR;
936 }
937 if ($cgiparams{'ROOTCERT_STATE'} ne '' && $cgiparams{'ROOTCERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
938 $errormessage = $Lang::tr{'invalid input for state or province'};
939 goto ROOTCERT_ERROR;
940 }
941 if ($cgiparams{'ROOTCERT_COUNTRY'} !~ /^[A-Z]*$/) {
942 $errormessage = $Lang::tr{'invalid input for country'};
943 goto ROOTCERT_ERROR;
944 }
945 #the exact syntax is a list comma separated of
946 # email:any-validemail
947 # URI: a uniform resource indicator
948 # DNS: a DNS domain name
949 # RID: a registered OBJECT IDENTIFIER
950 # IP: an IP address
951 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
952
953 if ($cgiparams{'SUBJECTALTNAME'} ne '' && $cgiparams{'SUBJECTALTNAME'} !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/,\.\-_@]*$/) {
954 $errormessage = $Lang::tr{'vpn altname syntax'};
955 goto VPNCONF_ERROR;
956 }
957
958 # Copy the cgisettings to vpnsettings and save the configfile
959 $vpnsettings{'ROOTCERT_ORGANIZATION'} = $cgiparams{'ROOTCERT_ORGANIZATION'};
960 $vpnsettings{'ROOTCERT_HOSTNAME'} = $cgiparams{'ROOTCERT_HOSTNAME'};
961 $vpnsettings{'ROOTCERT_EMAIL'} = $cgiparams{'ROOTCERT_EMAIL'};
962 $vpnsettings{'ROOTCERT_OU'} = $cgiparams{'ROOTCERT_OU'};
963 $vpnsettings{'ROOTCERT_CITY'} = $cgiparams{'ROOTCERT_CITY'};
964 $vpnsettings{'ROOTCERT_STATE'} = $cgiparams{'ROOTCERT_STATE'};
965 $vpnsettings{'ROOTCERT_COUNTRY'} = $cgiparams{'ROOTCERT_COUNTRY'};
966 &General::writehash("${General::swroot}/vpn/settings", \%vpnsettings);
967
968 # Replace empty strings with a .
969 (my $ou = $cgiparams{'ROOTCERT_OU'}) =~ s/^\s*$/\./;
970 (my $city = $cgiparams{'ROOTCERT_CITY'}) =~ s/^\s*$/\./;
971 (my $state = $cgiparams{'ROOTCERT_STATE'}) =~ s/^\s*$/\./;
972
973 # Create the CA certificate
974 if (!$errormessage) {
975 &General::log("ipsec", "Creating cacert...");
976 if (open(STDIN, "-|")) {
977 my $opt = " req -x509 -sha256 -nodes";
978 $opt .= " -days 999999";
979 $opt .= " -newkey rsa:4096";
980 $opt .= " -keyout ${General::swroot}/private/cakey.pem";
981 $opt .= " -out ${General::swroot}/ca/cacert.pem";
982
983 $errormessage = &callssl ($opt);
984 } else { #child
985 print "$cgiparams{'ROOTCERT_COUNTRY'}\n";
986 print "$state\n";
987 print "$city\n";
988 print "$cgiparams{'ROOTCERT_ORGANIZATION'}\n";
989 print "$ou\n";
990 print "$cgiparams{'ROOTCERT_ORGANIZATION'} CA\n";
991 print "$cgiparams{'ROOTCERT_EMAIL'}\n";
992 exit (0);
993 }
994 }
995
996 # Create the Host certificate request
997 if (!$errormessage) {
998 &General::log("ipsec", "Creating host cert...");
999 if (open(STDIN, "-|")) {
1000 my $opt = " req -sha256 -nodes";
1001 $opt .= " -newkey rsa:2048";
1002 $opt .= " -keyout ${General::swroot}/certs/hostkey.pem";
1003 $opt .= " -out ${General::swroot}/certs/hostreq.pem";
1004 $errormessage = &callssl ($opt);
1005 } else { #child
1006 print "$cgiparams{'ROOTCERT_COUNTRY'}\n";
1007 print "$state\n";
1008 print "$city\n";
1009 print "$cgiparams{'ROOTCERT_ORGANIZATION'}\n";
1010 print "$ou\n";
1011 print "$cgiparams{'ROOTCERT_HOSTNAME'}\n";
1012 print "$cgiparams{'ROOTCERT_EMAIL'}\n";
1013 print ".\n";
1014 print ".\n";
1015 exit (0);
1016 }
1017 }
1018
1019 # Sign the host certificate request
1020 if (!$errormessage) {
1021 &General::log("ipsec", "Self signing host cert...");
1022
1023 #No easy way for specifying the contain of subjectAltName without writing a config file...
1024 my ($fh, $v3extname) = tempfile ('/tmp/XXXXXXXX');
1025 print $fh <<END
1026 basicConstraints=CA:FALSE
1027 nsComment="OpenSSL Generated Certificate"
1028 subjectKeyIdentifier=hash
1029 authorityKeyIdentifier=keyid,issuer:always
1030 extendedKeyUsage = serverAuth
1031 END
1032 ;
1033 print $fh "subjectAltName=$cgiparams{'SUBJECTALTNAME'}" if ($cgiparams{'SUBJECTALTNAME'});
1034 close ($fh);
1035
1036 my $opt = " ca -md sha256 -days 999999";
1037 $opt .= " -batch -notext";
1038 $opt .= " -in ${General::swroot}/certs/hostreq.pem";
1039 $opt .= " -out ${General::swroot}/certs/hostcert.pem";
1040 $opt .= " -extfile $v3extname";
1041 $errormessage = &callssl ($opt);
1042 unlink ("${General::swroot}/certs/hostreq.pem"); #no more needed
1043 unlink ($v3extname);
1044 }
1045
1046 # Create an empty CRL
1047 if (!$errormessage) {
1048 &General::log("ipsec", "Creating emptycrl...");
1049 my $opt = " ca -gencrl";
1050 $opt .= " -out ${General::swroot}/crls/cacrl.pem";
1051 $errormessage = &callssl ($opt);
1052 }
1053
1054 # Successfully build CA / CERT!
1055 if (!$errormessage) {
1056 &cleanssldatabase();
1057 goto ROOTCERT_SUCCESS;
1058 }
1059
1060 #Cleanup
1061 unlink ("${General::swroot}/ca/cacert.pem");
1062 unlink ("${General::swroot}/certs/hostkey.pem");
1063 unlink ("${General::swroot}/certs/hostcert.pem");
1064 unlink ("${General::swroot}/crls/cacrl.pem");
1065 &cleanssldatabase();
1066 }
1067
1068 ROOTCERT_ERROR:
1069 &Header::showhttpheaders();
1070 &Header::openpage($Lang::tr{'ipsec'}, 1, '');
1071 &Header::openbigbox('100%', 'left', '', $errormessage);
1072 if ($errormessage) {
1073 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
1074 print "<class name='base'>$errormessage";
1075 print "&nbsp;</class>";
1076 &Header::closebox();
1077 }
1078 &Header::openbox('100%', 'left', "$Lang::tr{'generate root/host certificates'}:");
1079 print <<END
1080 <form method='post' enctype='multipart/form-data' action='$ENV{'SCRIPT_NAME'}'>
1081 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1082 <tr><td width='40%' class='base'>$Lang::tr{'organization name'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1083 <td width='60%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value='$cgiparams{'ROOTCERT_ORGANIZATION'}' size='32' /></td></tr>
1084 <tr><td class='base'>$Lang::tr{'ipfires hostname'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1085 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value='$cgiparams{'ROOTCERT_HOSTNAME'}' size='32' /></td></tr>
1086 <tr><td class='base'>$Lang::tr{'your e-mail'}:</td>
1087 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value='$cgiparams{'ROOTCERT_EMAIL'}' size='32' /></td></tr>
1088 <tr><td class='base'>$Lang::tr{'your department'}:</td>
1089 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value='$cgiparams{'ROOTCERT_OU'}' size='32' /></td></tr>
1090 <tr><td class='base'>$Lang::tr{'city'}:</td>
1091 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value='$cgiparams{'ROOTCERT_CITY'}' size='32' /></td></tr>
1092 <tr><td class='base'>$Lang::tr{'state or province'}:</td>
1093 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value='$cgiparams{'ROOTCERT_STATE'}' size='32' /></td></tr>
1094 <tr><td class='base'>$Lang::tr{'country'}:</td>
1095 <td class='base'><select name='ROOTCERT_COUNTRY'>
1096 END
1097 ;
1098 foreach my $country (sort keys %{Countries::countries}) {
1099 print "<option value='$Countries::countries{$country}'";
1100 if ( $Countries::countries{$country} eq $cgiparams{'ROOTCERT_COUNTRY'} ) {
1101 print " selected='selected'";
1102 }
1103 print ">$country</option>";
1104 }
1105 print <<END
1106 </select></td></tr>
1107 <tr><td class='base'>$Lang::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)</td>
1108 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value='$cgiparams{'SUBJECTALTNAME'}' size='32' /></td></tr>
1109 <tr><td>&nbsp;</td>
1110 <td><br /><input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' /><br /><br /></td></tr>
1111 <tr><td class='base' colspan='2' align='left'>
1112 <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>:
1113 $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'}
1114 </td></tr>
1115 <tr><td colspan='2'><hr></td></tr>
1116 <tr><td class='base' nowrap='nowrap'>$Lang::tr{'upload p12 file'}:</td>
1117 <td nowrap='nowrap'><input type='file' name='FH' size='32' /></td></tr>
1118 <tr><td class='base'>$Lang::tr{'pkcs12 file password'}:</td>
1119 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value='$cgiparams{'P12_PASS'}' size='32' /></td></tr>
1120 <tr><td>&nbsp;</td>
1121 <td><input type='submit' name='ACTION' value='$Lang::tr{'upload p12 file'}' /></td></tr>
1122 <tr><td class='base' colspan='2' align='left'>
1123 <img src='/blob.gif' alt='*' />&nbsp;$Lang::tr{'required field'}</td></tr>
1124 </table></form>
1125 END
1126 ;
1127 &Header::closebox();
1128 &Header::closebigbox();
1129 &Header::closepage();
1130 exit(0);
1131
1132 ROOTCERT_SUCCESS:
1133 if (&vpnenabled) {
1134 system('/usr/local/bin/ipsecctrl', 'S');
1135 sleep $sleepDelay;
1136 }
1137 ROOTCERT_SKIP:
1138 ###
1139 ### Export PKCS12 file to browser
1140 ###
1141 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download pkcs12 file'}) {
1142 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
1143 print "Content-Type: application/force-download\n";
1144 print "Content-Disposition: attachment; filename=" . $confighash{$cgiparams{'KEY'}}[1] . ".p12\r\n";
1145 print "Content-Type: application/octet-stream\r\n\r\n";
1146 print `/bin/cat ${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1].p12`;
1147 exit (0);
1148
1149 ###
1150 ### Display certificate
1151 ###
1152 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show certificate'}) {
1153 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
1154
1155 if ( -f "${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") {
1156 &Header::showhttpheaders();
1157 &Header::openpage($Lang::tr{'ipsec'}, 1, '');
1158 &Header::openbigbox('100%', 'left', '', '');
1159 &Header::openbox('100%', 'left', "$Lang::tr{'cert'}:");
1160 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`;
1161 $output = &Header::cleanhtml($output,"y");
1162 print "<pre>$output</pre>\n";
1163 &Header::closebox();
1164 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'>$Lang::tr{'back'}</a></div>";
1165 &Header::closebigbox();
1166 &Header::closepage();
1167 exit(0);
1168 }
1169
1170 ###
1171 ### Export Certificate to browser
1172 ###
1173 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download certificate'}) {
1174 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
1175
1176 if ( -f "${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") {
1177 print "Content-Type: application/force-download\n";
1178 print "Content-Disposition: attachment; filename=" . $confighash{$cgiparams{'KEY'}}[1] . "cert.pem\n\n";
1179 print `/bin/cat ${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`;
1180 exit (0);
1181 }
1182
1183 ###
1184 ### Enable/Disable connection
1185 ###
1186 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) {
1187
1188 &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings);
1189 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
1190
1191 if ($confighash{$cgiparams{'KEY'}}) {
1192 if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') {
1193 $confighash{$cgiparams{'KEY'}}[0] = 'on';
1194 &General::writehasharray("${General::swroot}/vpn/config", \%confighash);
1195 &writeipsecfiles();
1196 system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}) if (&vpnenabled);
1197 } else {
1198 system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}) if (&vpnenabled);
1199 $confighash{$cgiparams{'KEY'}}[0] = 'off';
1200 &General::writehasharray("${General::swroot}/vpn/config", \%confighash);
1201 &writeipsecfiles();
1202 }
1203 sleep $sleepDelay;
1204 } else {
1205 $errormessage = $Lang::tr{'invalid key'};
1206 }
1207
1208 ###
1209 ### Restart connection
1210 ###
1211 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'restart'}) {
1212 &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings);
1213 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
1214
1215 if ($confighash{$cgiparams{'KEY'}}) {
1216 if (&vpnenabled) {
1217 system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
1218 sleep $sleepDelay;
1219 }
1220 } else {
1221 $errormessage = $Lang::tr{'invalid key'};
1222 }
1223
1224 ###
1225 ### Remove connection
1226 ###
1227 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) {
1228 &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings);
1229 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
1230
1231 if ($confighash{$cgiparams{'KEY'}}) {
1232 system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}) if (&vpnenabled);
1233 unlink ("${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem");
1234 unlink ("${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1].p12");
1235 delete $confighash{$cgiparams{'KEY'}};
1236 &General::writehasharray("${General::swroot}/vpn/config", \%confighash);
1237 &writeipsecfiles();
1238 } else {
1239 $errormessage = $Lang::tr{'invalid key'};
1240 }
1241 &General::firewall_reload();
1242 ###
1243 ### Choose between adding a host-net or net-net connection
1244 ###
1245 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'add'} && $cgiparams{'TYPE'} eq '') {
1246 &Header::showhttpheaders();
1247 &Header::openpage($Lang::tr{'ipsec'}, 1, '');
1248 &Header::openbigbox('100%', 'left', '', '');
1249 &Header::openbox('100%', 'left', $Lang::tr{'connection type'});
1250 print <<END
1251 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1252 <b>$Lang::tr{'connection type'}:</b><br />
1253 <table>
1254 <tr><td><input type='radio' name='TYPE' value='host' checked='checked' /></td>
1255 <td class='base'>$Lang::tr{'host to net vpn'}</td>
1256 </tr><tr>
1257 <td><input type='radio' name='TYPE' value='net' /></td>
1258 <td class='base'>$Lang::tr{'net to net vpn'}</td>
1259 </tr><tr>
1260 <td align='center' colspan='2'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td>
1261 </tr>
1262 </table></form>
1263 END
1264 ;
1265 &Header::closebox();
1266 &Header::closebigbox();
1267 &Header::closepage();
1268 exit (0);
1269 ###
1270 ### Adding/Editing/Saving a connection
1271 ###
1272 } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) ||
1273 ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) ||
1274 ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'ADVANCED'} eq '')) {
1275
1276 &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings);
1277 &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash);
1278 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
1279
1280 if ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) {
1281 if (! $confighash{$cgiparams{'KEY'}}[0]) {
1282 $errormessage = $Lang::tr{'invalid key'};
1283 goto VPNCONF_END;
1284 }
1285 $cgiparams{'ENABLED'} = $confighash{$cgiparams{'KEY'}}[0];
1286 $cgiparams{'NAME'} = $confighash{$cgiparams{'KEY'}}[1];
1287 $cgiparams{'TYPE'} = $confighash{$cgiparams{'KEY'}}[3];
1288 $cgiparams{'AUTH'} = $confighash{$cgiparams{'KEY'}}[4];
1289 $cgiparams{'PSK'} = $confighash{$cgiparams{'KEY'}}[5];
1290 #$cgiparams{'free'} = $confighash{$cgiparams{'KEY'}}[6];
1291 $cgiparams{'LOCAL_ID'} = $confighash{$cgiparams{'KEY'}}[7];
1292 my @local_subnets = split(",", $confighash{$cgiparams{'KEY'}}[8]);
1293 $cgiparams{'LOCAL_SUBNET'} = join(/\|/, @local_subnets);
1294 $cgiparams{'REMOTE_ID'} = $confighash{$cgiparams{'KEY'}}[9];
1295 $cgiparams{'REMOTE'} = $confighash{$cgiparams{'KEY'}}[10];
1296 my @remote_subnets = split(",", $confighash{$cgiparams{'KEY'}}[11]);
1297 $cgiparams{'REMOTE_SUBNET'} = join(/\|/, @remote_subnets);
1298 $cgiparams{'REMARK'} = $confighash{$cgiparams{'KEY'}}[25];
1299 $cgiparams{'DPD_ACTION'} = $confighash{$cgiparams{'KEY'}}[27];
1300 $cgiparams{'IKE_VERSION'} = $confighash{$cgiparams{'KEY'}}[29];
1301 $cgiparams{'IKE_ENCRYPTION'} = $confighash{$cgiparams{'KEY'}}[18];
1302 $cgiparams{'IKE_INTEGRITY'} = $confighash{$cgiparams{'KEY'}}[19];
1303 $cgiparams{'IKE_GROUPTYPE'} = $confighash{$cgiparams{'KEY'}}[20];
1304 $cgiparams{'IKE_LIFETIME'} = $confighash{$cgiparams{'KEY'}}[16];
1305 $cgiparams{'ESP_ENCRYPTION'} = $confighash{$cgiparams{'KEY'}}[21];
1306 $cgiparams{'ESP_INTEGRITY'} = $confighash{$cgiparams{'KEY'}}[22];
1307 $cgiparams{'ESP_GROUPTYPE'} = $confighash{$cgiparams{'KEY'}}[23];
1308 if ($cgiparams{'ESP_GROUPTYPE'} eq "") {
1309 $cgiparams{'ESP_GROUPTYPE'} = $cgiparams{'IKE_GROUPTYPE'};
1310 }
1311 $cgiparams{'ESP_KEYLIFE'} = $confighash{$cgiparams{'KEY'}}[17];
1312 $cgiparams{'COMPRESSION'} = $confighash{$cgiparams{'KEY'}}[13];
1313 $cgiparams{'ONLY_PROPOSED'} = $confighash{$cgiparams{'KEY'}}[24];
1314 $cgiparams{'PFS'} = $confighash{$cgiparams{'KEY'}}[28];
1315 $cgiparams{'DPD_TIMEOUT'} = $confighash{$cgiparams{'KEY'}}[30];
1316 $cgiparams{'DPD_DELAY'} = $confighash{$cgiparams{'KEY'}}[31];
1317 $cgiparams{'FORCE_MOBIKE'} = $confighash{$cgiparams{'KEY'}}[32];
1318 $cgiparams{'START_ACTION'} = $confighash{$cgiparams{'KEY'}}[33];
1319 $cgiparams{'INACTIVITY_TIMEOUT'} = $confighash{$cgiparams{'KEY'}}[34];
1320
1321 if (!$cgiparams{'DPD_DELAY'}) {
1322 $cgiparams{'DPD_DELAY'} = 30;
1323 }
1324
1325 if (!$cgiparams{'DPD_TIMEOUT'}) {
1326 $cgiparams{'DPD_TIMEOUT'} = 120;
1327 }
1328
1329 if ($cgiparams{'INACTIVITY_TIMEOUT'} eq "") {
1330 $cgiparams{'INACTIVITY_TIMEOUT'} = 900;
1331 }
1332
1333 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) {
1334 $cgiparams{'REMARK'} = &Header::cleanhtml($cgiparams{'REMARK'});
1335 if ($cgiparams{'TYPE'} !~ /^(host|net)$/) {
1336 $errormessage = $Lang::tr{'connection type is invalid'};
1337 goto VPNCONF_ERROR;
1338 }
1339
1340 if ($cgiparams{'NAME'} !~ /^[a-zA-Z0-9]+$/) {
1341 $errormessage = $Lang::tr{'name must only contain characters'};
1342 goto VPNCONF_ERROR;
1343 }
1344
1345 if ($cgiparams{'NAME'} =~ /^(host|01|block|private|clear|packetdefault)$/) {
1346 $errormessage = $Lang::tr{'name is invalid'};
1347 goto VPNCONF_ERROR;
1348 }
1349
1350 if (length($cgiparams{'NAME'}) >60) {
1351 $errormessage = $Lang::tr{'name too long'};
1352 goto VPNCONF_ERROR;
1353 }
1354
1355 # Check if there is no other entry with this name
1356 if (! $cgiparams{'KEY'}) { #only for add
1357 foreach my $key (keys %confighash) {
1358 if ($confighash{$key}[1] eq $cgiparams{'NAME'}) {
1359 $errormessage = $Lang::tr{'a connection with this name already exists'};
1360 goto VPNCONF_ERROR;
1361 }
1362 }
1363 }
1364
1365 if (($cgiparams{'TYPE'} eq 'net') && (! $cgiparams{'REMOTE'})) {
1366 $errormessage = $Lang::tr{'invalid input for remote host/ip'};
1367 goto VPNCONF_ERROR;
1368 }
1369
1370 if ($cgiparams{'REMOTE'}) {
1371 if (($cgiparams{'REMOTE'} ne '%any') && (! &General::validip($cgiparams{'REMOTE'}))) {
1372 if (! &General::validfqdn ($cgiparams{'REMOTE'})) {
1373 $errormessage = $Lang::tr{'invalid input for remote host/ip'};
1374 goto VPNCONF_ERROR;
1375 } else {
1376 if (&valid_dns_host($cgiparams{'REMOTE'})) {
1377 $warnmessage = "$Lang::tr{'check vpn lr'} $cgiparams{'REMOTE'}. $Lang::tr{'dns check failed'}";
1378 }
1379 }
1380 }
1381 }
1382
1383 my @local_subnets = split(",", $cgiparams{'LOCAL_SUBNET'});
1384 foreach my $subnet (@local_subnets) {
1385 unless (&Network::check_subnet($subnet)) {
1386 $errormessage = $Lang::tr{'local subnet is invalid'};
1387 goto VPNCONF_ERROR;
1388 }
1389 }
1390
1391 # Allow only one roadwarrior/psk without remote IP-address
1392 if ($cgiparams{'REMOTE'} eq '' && $cgiparams{'AUTH'} eq 'psk') {
1393 foreach my $key (keys %confighash) {
1394 if ( ($cgiparams{'KEY'} ne $key) &&
1395 ($confighash{$key}[4] eq 'psk') &&
1396 ($confighash{$key}[10] eq '') ) {
1397 $errormessage = $Lang::tr{'you can only define one roadwarrior connection when using pre-shared key authentication'};
1398 goto VPNCONF_ERROR;
1399 }
1400 }
1401 }
1402
1403 if ($cgiparams{'TYPE'} eq 'net') {
1404 my @remote_subnets = split(",", $cgiparams{'REMOTE_SUBNET'});
1405 foreach my $subnet (@remote_subnets) {
1406 unless (&Network::check_subnet($subnet)) {
1407 $errormessage = $Lang::tr{'remote subnet is invalid'};
1408 goto VPNCONF_ERROR;
1409 }
1410 }
1411 }
1412
1413 if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) {
1414 $errormessage = $Lang::tr{'invalid input'};
1415 goto VPNCONF_ERROR;
1416 }
1417 if ($cgiparams{'EDIT_ADVANCED'} !~ /^(on|off)$/) {
1418 $errormessage = $Lang::tr{'invalid input'};
1419 goto VPNCONF_ERROR;
1420 }
1421
1422 # Allow nothing or a string (DN,FDQN,) beginning with @
1423 # with no comma but slashes between RID eg @O=FR/C=Paris/OU=myhome/CN=franck
1424 if ( ($cgiparams{'LOCAL_ID'} !~ /^(|[\w.-]*@[\w. =*\/-]+|\d+\.\d+\.\d+\.\d+)$/) ||
1425 ($cgiparams{'REMOTE_ID'} !~ /^(|[\w.-]*@[\w. =*\/-]+|\d+\.\d+\.\d+\.\d+)$/) ||
1426 (($cgiparams{'REMOTE_ID'} eq $cgiparams{'LOCAL_ID'}) && ($cgiparams{'LOCAL_ID'} ne ''))
1427 ) {
1428 $errormessage = $Lang::tr{'invalid local-remote id'} . '<br />' .
1429 'DER_ASN1_DN: @c=FR/ou=Paris/ou=Home/cn=*<br />' .
1430 'FQDN: @ipfire.org<br />' .
1431 'USER_FQDN: info@ipfire.org<br />' .
1432 'IPV4_ADDR: 123.123.123.123';
1433 goto VPNCONF_ERROR;
1434 }
1435 # If Auth is DN, verify existance of Remote ID.
1436 if ( $cgiparams{'REMOTE_ID'} eq '' && (
1437 $cgiparams{'AUTH'} eq 'auth-dn'|| # while creation
1438 $confighash{$cgiparams{'KEY'}}[2] eq '%auth-dn')){ # while editing
1439 $errormessage = $Lang::tr{'vpn missing remote id'};
1440 goto VPNCONF_ERROR;
1441 }
1442
1443 if ($cgiparams{'TYPE'} eq 'net'){
1444 $warnmessage=&General::checksubnets('',$cgiparams{'REMOTE_SUBNET'},'ipsec');
1445 if ($warnmessage ne ''){
1446 $warnmessage=$Lang::tr{'remote subnet'}." ($cgiparams{'REMOTE_SUBNET'}) <br>".$warnmessage;
1447 }
1448 }
1449
1450 if ($cgiparams{'AUTH'} eq 'psk') {
1451 if (! length($cgiparams{'PSK'}) ) {
1452 $errormessage = $Lang::tr{'pre-shared key is too short'};
1453 goto VPNCONF_ERROR;
1454 }
1455 if ($cgiparams{'PSK'} =~ /'/) {
1456 $cgiparams{'PSK'} =~ tr/'/ /;
1457 $errormessage = $Lang::tr{'invalid characters found in pre-shared key'};
1458 goto VPNCONF_ERROR;
1459 }
1460 } elsif ($cgiparams{'AUTH'} eq 'certreq') {
1461 if ($cgiparams{'KEY'}) {
1462 $errormessage = $Lang::tr{'cant change certificates'};
1463 goto VPNCONF_ERROR;
1464 }
1465 if (ref ($cgiparams{'FH'}) ne 'Fh') {
1466 $errormessage = $Lang::tr{'there was no file upload'};
1467 goto VPNCONF_ERROR;
1468 }
1469
1470 # Move uploaded certificate request to a temporary file
1471 (my $fh, my $filename) = tempfile( );
1472 if (copy ($cgiparams{'FH'}, $fh) != 1) {
1473 $errormessage = $!;
1474 goto VPNCONF_ERROR;
1475 }
1476
1477 # Sign the certificate request
1478 &General::log("ipsec", "Signing your cert $cgiparams{'NAME'}...");
1479 my $opt = " ca -md sha256 -days 999999";
1480 $opt .= " -batch -notext";
1481 $opt .= " -in $filename";
1482 $opt .= " -out ${General::swroot}/certs/$cgiparams{'NAME'}cert.pem";
1483
1484 if ( $errormessage = &callssl ($opt) ) {
1485 unlink ($filename);
1486 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1487 &cleanssldatabase();
1488 goto VPNCONF_ERROR;
1489 } else {
1490 unlink ($filename);
1491 &cleanssldatabase();
1492 }
1493
1494 $cgiparams{'CERT_NAME'} = getCNfromcert ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1495 if ($cgiparams{'CERT_NAME'} eq '') {
1496 $errormessage = $Lang::tr{'could not retrieve common name from certificate'};
1497 goto VPNCONF_ERROR;
1498 }
1499 } elsif ($cgiparams{'AUTH'} eq 'pkcs12') {
1500 &General::log("ipsec", "Importing from p12...");
1501
1502 if (ref ($cgiparams{'FH'}) ne 'Fh') {
1503 $errormessage = $Lang::tr{'there was no file upload'};
1504 goto ROOTCERT_ERROR;
1505 }
1506
1507 # Move uploaded certificate request to a temporary file
1508 (my $fh, my $filename) = tempfile( );
1509 if (copy ($cgiparams{'FH'}, $fh) != 1) {
1510 $errormessage = $!;
1511 goto ROOTCERT_ERROR;
1512 }
1513
1514 # Extract the CA certificate from the file
1515 &General::log("ipsec", "Extracting caroot from p12...");
1516 if (open(STDIN, "-|")) {
1517 my $opt = " pkcs12 -cacerts -nokeys";
1518 $opt .= " -in $filename";
1519 $opt .= " -out /tmp/newcacert";
1520 $errormessage = &callssl ($opt);
1521 } else { #child
1522 print "$cgiparams{'P12_PASS'}\n";
1523 exit (0);
1524 }
1525
1526 # Extract the Host certificate from the file
1527 if (!$errormessage) {
1528 &General::log("ipsec", "Extracting host cert from p12...");
1529 if (open(STDIN, "-|")) {
1530 my $opt = " pkcs12 -clcerts -nokeys";
1531 $opt .= " -in $filename";
1532 $opt .= " -out /tmp/newhostcert";
1533 $errormessage = &callssl ($opt);
1534 } else { #child
1535 print "$cgiparams{'P12_PASS'}\n";
1536 exit (0);
1537 }
1538 }
1539
1540 if (!$errormessage) {
1541 &General::log("ipsec", "Moving cacert...");
1542 #If CA have new subject, add it to our list of CA
1543 my $casubject = &Header::cleanhtml(getsubjectfromcert ('/tmp/newcacert'));
1544 my @names;
1545 foreach my $x (keys %cahash) {
1546 $casubject='' if ($cahash{$x}[1] eq $casubject);
1547 unshift (@names,$cahash{$x}[0]);
1548 }
1549 if ($casubject) { # a new one!
1550 my $temp = `/usr/bin/openssl x509 -text -in /tmp/newcacert`;
1551 if ($temp !~ /CA:TRUE/i) {
1552 $errormessage = $Lang::tr{'not a valid ca certificate'};
1553 } else {
1554 #compute a name for it
1555 my $idx=0;
1556 while (grep(/Imported-$idx/, @names) ) {$idx++};
1557 $cgiparams{'CA_NAME'}="Imported-$idx";
1558 $cgiparams{'CERT_NAME'}=&Header::cleanhtml(getCNfromcert ('/tmp/newhostcert'));
1559 move("/tmp/newcacert", "${General::swroot}/ca/$cgiparams{'CA_NAME'}cert.pem");
1560 $errormessage = "$Lang::tr{'certificate file move failed'}: $!" if ($? ne 0);
1561 if (!$errormessage) {
1562 my $key = &General::findhasharraykey (\%cahash);
1563 $cahash{$key}[0] = $cgiparams{'CA_NAME'};
1564 $cahash{$key}[1] = $casubject;
1565 &General::writehasharray("${General::swroot}/vpn/caconfig", \%cahash);
1566 system('/usr/local/bin/ipsecctrl', 'R');
1567 }
1568 }
1569 }
1570 }
1571 if (!$errormessage) {
1572 &General::log("ipsec", "Moving host cert...");
1573 move("/tmp/newhostcert", "${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1574 $errormessage = "$Lang::tr{'certificate file move failed'}: $!" if ($? ne 0);
1575 }
1576
1577 #cleanup temp files
1578 unlink ($filename);
1579 unlink ('/tmp/newcacert');
1580 unlink ('/tmp/newhostcert');
1581 if ($errormessage) {
1582 unlink ("${General::swroot}/ca/$cgiparams{'CA_NAME'}cert.pem");
1583 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1584 goto VPNCONF_ERROR;
1585 }
1586 &General::log("ipsec", "p12 import completed!");
1587 } elsif ($cgiparams{'AUTH'} eq 'certfile') {
1588 if ($cgiparams{'KEY'}) {
1589 $errormessage = $Lang::tr{'cant change certificates'};
1590 goto VPNCONF_ERROR;
1591 }
1592 if (ref ($cgiparams{'FH'}) ne 'Fh') {
1593 $errormessage = $Lang::tr{'there was no file upload'};
1594 goto VPNCONF_ERROR;
1595 }
1596 # Move uploaded certificate to a temporary file
1597 (my $fh, my $filename) = tempfile( );
1598 if (copy ($cgiparams{'FH'}, $fh) != 1) {
1599 $errormessage = $!;
1600 goto VPNCONF_ERROR;
1601 }
1602
1603 # Verify the certificate has a valid CA and move it
1604 &General::log("ipsec", "Validating imported cert against our known CA...");
1605 my $validca = 1; #assume ok
1606 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/cacert.pem $filename`;
1607 if ($test !~ /: OK/) {
1608 my $validca = 0;
1609 foreach my $key (keys %cahash) {
1610 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/$cahash{$key}[0]cert.pem $filename`;
1611 if ($test =~ /: OK/) {
1612 $validca = 1;
1613 last;
1614 }
1615 }
1616 }
1617 if (! $validca) {
1618 $errormessage = $Lang::tr{'certificate does not have a valid ca associated with it'};
1619 unlink ($filename);
1620 goto VPNCONF_ERROR;
1621 } else {
1622 move($filename, "${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1623 if ($? ne 0) {
1624 $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
1625 unlink ($filename);
1626 goto VPNCONF_ERROR;
1627 }
1628 }
1629
1630 $cgiparams{'CERT_NAME'} = getCNfromcert ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1631 if ($cgiparams{'CERT_NAME'} eq '') {
1632 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1633 $errormessage = $Lang::tr{'could not retrieve common name from certificate'};
1634 goto VPNCONF_ERROR;
1635 }
1636 } elsif ($cgiparams{'AUTH'} eq 'certgen') {
1637 if ($cgiparams{'KEY'}) {
1638 $errormessage = $Lang::tr{'cant change certificates'};
1639 goto VPNCONF_ERROR;
1640 }
1641 # Validate input since the form was submitted
1642 if (length($cgiparams{'CERT_NAME'}) >60) {
1643 $errormessage = $Lang::tr{'name too long'};
1644 goto VPNCONF_ERROR;
1645 }
1646 if ($cgiparams{'CERT_NAME'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) {
1647 $errormessage = $Lang::tr{'invalid input for name'};
1648 goto VPNCONF_ERROR;
1649 }
1650 if ($cgiparams{'CERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'CERT_EMAIL'}))) {
1651 $errormessage = $Lang::tr{'invalid input for e-mail address'};
1652 goto VPNCONF_ERROR;
1653 }
1654 if (length($cgiparams{'CERT_EMAIL'}) > 40) {
1655 $errormessage = $Lang::tr{'e-mail address too long'};
1656 goto VPNCONF_ERROR;
1657 }
1658 if ($cgiparams{'CERT_OU'} ne '' && $cgiparams{'CERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1659 $errormessage = $Lang::tr{'invalid input for department'};
1660 goto VPNCONF_ERROR;
1661 }
1662 if (length($cgiparams{'CERT_ORGANIZATION'}) >60) {
1663 $errormessage = $Lang::tr{'organization too long'};
1664 goto VPNCONF_ERROR;
1665 }
1666 if ($cgiparams{'CERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) {
1667 $errormessage = $Lang::tr{'invalid input for organization'};
1668 goto VPNCONF_ERROR;
1669 }
1670 if ($cgiparams{'CERT_CITY'} ne '' && $cgiparams{'CERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1671 $errormessage = $Lang::tr{'invalid input for city'};
1672 goto VPNCONF_ERROR;
1673 }
1674 if ($cgiparams{'CERT_STATE'} ne '' && $cgiparams{'CERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1675 $errormessage = $Lang::tr{'invalid input for state or province'};
1676 goto VPNCONF_ERROR;
1677 }
1678 if ($cgiparams{'CERT_COUNTRY'} !~ /^[A-Z]*$/) {
1679 $errormessage = $Lang::tr{'invalid input for country'};
1680 goto VPNCONF_ERROR;
1681 }
1682 #the exact syntax is a list comma separated of
1683 # email:any-validemail
1684 # URI: a uniform resource indicator
1685 # DNS: a DNS domain name
1686 # RID: a registered OBJECT IDENTIFIER
1687 # IP: an IP address
1688 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
1689
1690 if ($cgiparams{'SUBJECTALTNAME'} ne '' && $cgiparams{'SUBJECTALTNAME'} !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/,\.\-_@]*$/) {
1691 $errormessage = $Lang::tr{'vpn altname syntax'};
1692 goto VPNCONF_ERROR;
1693 }
1694
1695 if (length($cgiparams{'CERT_PASS1'}) < 5) {
1696 $errormessage = $Lang::tr{'password too short'};
1697 goto VPNCONF_ERROR;
1698 }
1699 if ($cgiparams{'CERT_PASS1'} ne $cgiparams{'CERT_PASS2'}) {
1700 $errormessage = $Lang::tr{'passwords do not match'};
1701 goto VPNCONF_ERROR;
1702 }
1703
1704 # Replace empty strings with a .
1705 (my $ou = $cgiparams{'CERT_OU'}) =~ s/^\s*$/\./;
1706 (my $city = $cgiparams{'CERT_CITY'}) =~ s/^\s*$/\./;
1707 (my $state = $cgiparams{'CERT_STATE'}) =~ s/^\s*$/\./;
1708
1709 # Create the Client certificate request
1710 &General::log("ipsec", "Creating a cert...");
1711
1712 if (open(STDIN, "-|")) {
1713 my $opt = " req -nodes -rand /proc/interrupts:/proc/net/rt_cache";
1714 $opt .= " -newkey rsa:2048";
1715 $opt .= " -keyout ${General::swroot}/certs/$cgiparams{'NAME'}key.pem";
1716 $opt .= " -out ${General::swroot}/certs/$cgiparams{'NAME'}req.pem";
1717
1718 if ( $errormessage = &callssl ($opt) ) {
1719 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}key.pem");
1720 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}req.pem");
1721 goto VPNCONF_ERROR;
1722 }
1723 } else { #child
1724 print "$cgiparams{'CERT_COUNTRY'}\n";
1725 print "$state\n";
1726 print "$city\n";
1727 print "$cgiparams{'CERT_ORGANIZATION'}\n";
1728 print "$ou\n";
1729 print "$cgiparams{'CERT_NAME'}\n";
1730 print "$cgiparams{'CERT_EMAIL'}\n";
1731 print ".\n";
1732 print ".\n";
1733 exit (0);
1734 }
1735
1736 # Sign the client certificate request
1737 &General::log("ipsec", "Signing the cert $cgiparams{'NAME'}...");
1738
1739 #No easy way for specifying the contain of subjectAltName without writing a config file...
1740 my ($fh, $v3extname) = tempfile ('/tmp/XXXXXXXX');
1741 print $fh <<END
1742 basicConstraints=CA:FALSE
1743 nsComment="OpenSSL Generated Certificate"
1744 subjectKeyIdentifier=hash
1745 extendedKeyUsage=clientAuth
1746 authorityKeyIdentifier=keyid,issuer:always
1747 END
1748 ;
1749 print $fh "subjectAltName=$cgiparams{'SUBJECTALTNAME'}" if ($cgiparams{'SUBJECTALTNAME'});
1750 close ($fh);
1751
1752 my $opt = " ca -md sha256 -days 999999 -batch -notext";
1753 $opt .= " -in ${General::swroot}/certs/$cgiparams{'NAME'}req.pem";
1754 $opt .= " -out ${General::swroot}/certs/$cgiparams{'NAME'}cert.pem";
1755 $opt .= " -extfile $v3extname";
1756
1757 if ( $errormessage = &callssl ($opt) ) {
1758 unlink ($v3extname);
1759 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}key.pem");
1760 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}req.pem");
1761 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1762 &cleanssldatabase();
1763 goto VPNCONF_ERROR;
1764 } else {
1765 unlink ($v3extname);
1766 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}req.pem");
1767 &cleanssldatabase();
1768 }
1769
1770 # Create the pkcs12 file
1771 &General::log("ipsec", "Packing a pkcs12 file...");
1772 $opt = " pkcs12 -export";
1773 $opt .= " -inkey ${General::swroot}/certs/$cgiparams{'NAME'}key.pem";
1774 $opt .= " -in ${General::swroot}/certs/$cgiparams{'NAME'}cert.pem";
1775 $opt .= " -name \"$cgiparams{'NAME'}\"";
1776 $opt .= " -passout pass:$cgiparams{'CERT_PASS1'}";
1777 $opt .= " -certfile ${General::swroot}/ca/cacert.pem";
1778 $opt .= " -caname \"$vpnsettings{'ROOTCERT_ORGANIZATION'} CA\"";
1779 $opt .= " -out ${General::swroot}/certs/$cgiparams{'NAME'}.p12";
1780
1781 if ( $errormessage = &callssl ($opt) ) {
1782 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}key.pem");
1783 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1784 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}.p12");
1785 goto VPNCONF_ERROR;
1786 } else {
1787 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}key.pem");
1788 }
1789 } elsif ($cgiparams{'AUTH'} eq 'cert') {
1790 ;# Nothing, just editing
1791 } elsif ($cgiparams{'AUTH'} eq 'auth-dn') {
1792 $cgiparams{'CERT_NAME'} = '%auth-dn'; # a special value saying 'no cert file'
1793 } else {
1794 $errormessage = $Lang::tr{'invalid input for authentication method'};
1795 goto VPNCONF_ERROR;
1796 }
1797
1798 # 1)Error message here is not accurate.
1799 # 2)Test is superfluous, openswan can reference same cert multiple times
1800 # 3)Present since initial version (1.3.2.11), it isn't a bug correction
1801 # Check if there is no other entry with this certificate name
1802 #if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk') && ($cgiparams{'AUTH'} ne 'auth-dn')) {
1803 # foreach my $key (keys %confighash) {
1804 # if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) {
1805 # $errormessage = $Lang::tr{'a connection with this common name already exists'};
1806 # goto VPNCONF_ERROR;
1807 # }
1808 # }
1809 #}
1810 # Save the config
1811
1812 my $key = $cgiparams{'KEY'};
1813 if (! $key) {
1814 $key = &General::findhasharraykey (\%confighash);
1815 foreach my $i (0 .. 34) { $confighash{$key}[$i] = "";}
1816 }
1817 $confighash{$key}[0] = $cgiparams{'ENABLED'};
1818 $confighash{$key}[1] = $cgiparams{'NAME'};
1819 if ((! $cgiparams{'KEY'}) && $cgiparams{'AUTH'} ne 'psk') {
1820 $confighash{$key}[2] = $cgiparams{'CERT_NAME'};
1821 }
1822 $confighash{$key}[3] = $cgiparams{'TYPE'};
1823 if ($cgiparams{'AUTH'} eq 'psk') {
1824 $confighash{$key}[4] = 'psk';
1825 $confighash{$key}[5] = $cgiparams{'PSK'};
1826 } else {
1827 $confighash{$key}[4] = 'cert';
1828 }
1829 if ($cgiparams{'TYPE'} eq 'net') {
1830 my @remote_subnets = split(",", $cgiparams{'REMOTE_SUBNET'});
1831 $confighash{$key}[11] = join('|', @remote_subnets);
1832 }
1833 $confighash{$key}[7] = $cgiparams{'LOCAL_ID'};
1834 my @local_subnets = split(",", $cgiparams{'LOCAL_SUBNET'});
1835 $confighash{$key}[8] = join('|', @local_subnets);
1836 $confighash{$key}[9] = $cgiparams{'REMOTE_ID'};
1837 $confighash{$key}[10] = $cgiparams{'REMOTE'};
1838 $confighash{$key}[25] = $cgiparams{'REMARK'};
1839 $confighash{$key}[26] = ""; # Formerly INTERFACE
1840 $confighash{$key}[27] = $cgiparams{'DPD_ACTION'};
1841 $confighash{$key}[29] = $cgiparams{'IKE_VERSION'};
1842
1843 # don't forget advanced value
1844 $confighash{$key}[18] = $cgiparams{'IKE_ENCRYPTION'};
1845 $confighash{$key}[19] = $cgiparams{'IKE_INTEGRITY'};
1846 $confighash{$key}[20] = $cgiparams{'IKE_GROUPTYPE'};
1847 $confighash{$key}[16] = $cgiparams{'IKE_LIFETIME'};
1848 $confighash{$key}[21] = $cgiparams{'ESP_ENCRYPTION'};
1849 $confighash{$key}[22] = $cgiparams{'ESP_INTEGRITY'};
1850 $confighash{$key}[23] = $cgiparams{'ESP_GROUPTYPE'};
1851 $confighash{$key}[17] = $cgiparams{'ESP_KEYLIFE'};
1852 $confighash{$key}[12] = 'off'; # $cgiparams{'AGGRMODE'};
1853 $confighash{$key}[13] = $cgiparams{'COMPRESSION'};
1854 $confighash{$key}[24] = $cgiparams{'ONLY_PROPOSED'};
1855 $confighash{$key}[28] = $cgiparams{'PFS'};
1856 $confighash{$key}[30] = $cgiparams{'DPD_TIMEOUT'};
1857 $confighash{$key}[31] = $cgiparams{'DPD_DELAY'};
1858 $confighash{$key}[32] = $cgiparams{'FORCE_MOBIKE'};
1859 $confighash{$key}[33] = $cgiparams{'START_ACTION'};
1860 $confighash{$key}[34] = $cgiparams{'INACTIVITY_TIMEOUT'};
1861
1862 # free unused fields!
1863 $confighash{$key}[6] = 'off';
1864 $confighash{$key}[15] = 'off';
1865
1866 &General::writehasharray("${General::swroot}/vpn/config", \%confighash);
1867 &writeipsecfiles();
1868 if (&vpnenabled) {
1869 system('/usr/local/bin/ipsecctrl', 'S', $key);
1870 sleep $sleepDelay;
1871 }
1872 if ($cgiparams{'EDIT_ADVANCED'} eq 'on') {
1873 $cgiparams{'KEY'} = $key;
1874 $cgiparams{'ACTION'} = $Lang::tr{'advanced'};
1875 }
1876 goto VPNCONF_END;
1877 } else { # add new connection
1878 $cgiparams{'ENABLED'} = 'on';
1879 if ( ! -f "${General::swroot}/private/cakey.pem" ) {
1880 $cgiparams{'AUTH'} = 'psk';
1881 } elsif ( ! -f "${General::swroot}/ca/cacert.pem") {
1882 $cgiparams{'AUTH'} = 'certfile';
1883 } else {
1884 $cgiparams{'AUTH'} = 'certgen';
1885 }
1886 $cgiparams{'LOCAL_SUBNET'} = "$netsettings{'GREEN_NETADDRESS'}/$netsettings{'GREEN_NETMASK'}";
1887 $cgiparams{'CERT_EMAIL'} = $vpnsettings{'ROOTCERT_EMAIL'};
1888 $cgiparams{'CERT_OU'} = $vpnsettings{'ROOTCERT_OU'};
1889 $cgiparams{'CERT_ORGANIZATION'} = $vpnsettings{'ROOTCERT_ORGANIZATION'};
1890 $cgiparams{'CERT_CITY'} = $vpnsettings{'ROOTCERT_CITY'};
1891 $cgiparams{'CERT_STATE'} = $vpnsettings{'ROOTCERT_STATE'};
1892 $cgiparams{'CERT_COUNTRY'} = $vpnsettings{'ROOTCERT_COUNTRY'};
1893
1894 # choose appropriate dpd action
1895 if ($cgiparams{'TYPE'} eq 'host') {
1896 $cgiparams{'DPD_ACTION'} = 'clear';
1897 } else {
1898 $cgiparams{'DPD_ACTION'} = 'restart';
1899 }
1900
1901 if (!$cgiparams{'DPD_DELAY'}) {
1902 $cgiparams{'DPD_DELAY'} = 30;
1903 }
1904
1905 if (!$cgiparams{'DPD_TIMEOUT'}) {
1906 $cgiparams{'DPD_TIMEOUT'} = 120;
1907 }
1908
1909 if (!$cgiparams{'FORCE_MOBIKE'}) {
1910 $cgiparams{'FORCE_MOBIKE'} = 'no';
1911 }
1912
1913 # Default IKE Version to v2
1914 if (!$cgiparams{'IKE_VERSION'}) {
1915 $cgiparams{'IKE_VERSION'} = 'ikev2';
1916 }
1917
1918 # ID are empty
1919 $cgiparams{'LOCAL_ID'} = '';
1920 $cgiparams{'REMOTE_ID'} = '';
1921
1922 #use default advanced value
1923 $cgiparams{'IKE_ENCRYPTION'} = 'chacha20poly1305|aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128'; #[18];
1924 $cgiparams{'IKE_INTEGRITY'} = 'sha2_512|sha2_256'; #[19];
1925 $cgiparams{'IKE_GROUPTYPE'} = 'curve25519|4096|3072|2048'; #[20];
1926 $cgiparams{'IKE_LIFETIME'} = '3'; #[16];
1927 $cgiparams{'ESP_ENCRYPTION'} = 'chacha20poly1305|aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128'; #[21];
1928 $cgiparams{'ESP_INTEGRITY'} = 'sha2_512|sha2_256'; #[22];
1929 $cgiparams{'ESP_GROUPTYPE'} = 'curve25519|4096|3072|2048'; #[23];
1930 $cgiparams{'ESP_KEYLIFE'} = '1'; #[17];
1931 $cgiparams{'COMPRESSION'} = 'off'; #[13];
1932 $cgiparams{'ONLY_PROPOSED'} = 'on'; #[24];
1933 $cgiparams{'PFS'} = 'on'; #[28];
1934 $cgiparams{'INACTIVITY_TIMEOUT'} = 900;
1935 }
1936
1937 VPNCONF_ERROR:
1938 $checked{'ENABLED'}{'off'} = '';
1939 $checked{'ENABLED'}{'on'} = '';
1940 $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = "checked='checked'";
1941
1942 $checked{'EDIT_ADVANCED'}{'off'} = '';
1943 $checked{'EDIT_ADVANCED'}{'on'} = '';
1944 $checked{'EDIT_ADVANCED'}{$cgiparams{'EDIT_ADVANCED'}} = "checked='checked'";
1945
1946 $checked{'AUTH'}{'psk'} = '';
1947 $checked{'AUTH'}{'certreq'} = '';
1948 $checked{'AUTH'}{'certgen'} = '';
1949 $checked{'AUTH'}{'certfile'} = '';
1950 $checked{'AUTH'}{'pkcs12'} = '';
1951 $checked{'AUTH'}{'auth-dn'} = '';
1952 $checked{'AUTH'}{$cgiparams{'AUTH'}} = "checked='checked'";
1953
1954 &Header::showhttpheaders();
1955 &Header::openpage($Lang::tr{'ipsec'}, 1, '');
1956 &Header::openbigbox('100%', 'left', '', $errormessage);
1957 if ($errormessage) {
1958 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
1959 print "<class name='base'>$errormessage";
1960 print "&nbsp;</class>";
1961 &Header::closebox();
1962 }
1963
1964 if ($warnmessage) {
1965 &Header::openbox('100%', 'left', "$Lang::tr{'warning messages'}:");
1966 print "<class name='base'>$warnmessage";
1967 print "&nbsp;</class>";
1968 &Header::closebox();
1969 }
1970
1971 print "<form method='post' enctype='multipart/form-data' action='$ENV{'SCRIPT_NAME'}'>";
1972 print<<END
1973 <input type='hidden' name='TYPE' value='$cgiparams{'TYPE'}' />
1974 <input type='hidden' name='IKE_VERSION' value='$cgiparams{'IKE_VERSION'}' />
1975 <input type='hidden' name='IKE_ENCRYPTION' value='$cgiparams{'IKE_ENCRYPTION'}' />
1976 <input type='hidden' name='IKE_INTEGRITY' value='$cgiparams{'IKE_INTEGRITY'}' />
1977 <input type='hidden' name='IKE_GROUPTYPE' value='$cgiparams{'IKE_GROUPTYPE'}' />
1978 <input type='hidden' name='IKE_LIFETIME' value='$cgiparams{'IKE_LIFETIME'}' />
1979 <input type='hidden' name='ESP_ENCRYPTION' value='$cgiparams{'ESP_ENCRYPTION'}' />
1980 <input type='hidden' name='ESP_INTEGRITY' value='$cgiparams{'ESP_INTEGRITY'}' />
1981 <input type='hidden' name='ESP_GROUPTYPE' value='$cgiparams{'ESP_GROUPTYPE'}' />
1982 <input type='hidden' name='ESP_KEYLIFE' value='$cgiparams{'ESP_KEYLIFE'}' />
1983 <input type='hidden' name='COMPRESSION' value='$cgiparams{'COMPRESSION'}' />
1984 <input type='hidden' name='ONLY_PROPOSED' value='$cgiparams{'ONLY_PROPOSED'}' />
1985 <input type='hidden' name='PFS' value='$cgiparams{'PFS'}' />
1986 <input type='hidden' name='DPD_ACTION' value='$cgiparams{'DPD_ACTION'}' />
1987 <input type='hidden' name='DPD_DELAY' value='$cgiparams{'DPD_DELAY'}' />
1988 <input type='hidden' name='DPD_TIMEOUT' value='$cgiparams{'DPD_TIMEOUT'}' />
1989 <input type='hidden' name='FORCE_MOBIKE' value='$cgiparams{'FORCE_MOBIKE'}' />
1990 <input type='hidden' name='START_ACTION' value='$cgiparams{'START_ACTION'}' />
1991 END
1992 ;
1993 if ($cgiparams{'KEY'}) {
1994 print "<input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />";
1995 print "<input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />";
1996 print "<input type='hidden' name='AUTH' value='$cgiparams{'AUTH'}' />";
1997 }
1998
1999 &Header::openbox('100%', 'left', "$Lang::tr{'connection'}: $cgiparams{'NAME'}");
2000 print "<table width='100%'>";
2001 if (!$cgiparams{'KEY'}) {
2002 print <<EOF;
2003 <tr>
2004 <td width='20%'>$Lang::tr{'name'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
2005 <td width='30%'>
2006 <input type='text' name='NAME' value='$cgiparams{'NAME'}' size='25' />
2007 </td>
2008 <td colspan="2"></td>
2009 </tr>
2010 EOF
2011 }
2012
2013 my $disabled;
2014 my $blob;
2015 if ($cgiparams{'TYPE'} eq 'host') {
2016 $disabled = "disabled='disabled'";
2017 } elsif ($cgiparams{'TYPE'} eq 'net') {
2018 $blob = "<img src='/blob.gif' alt='*' />";
2019 };
2020
2021 my @local_subnets = split(/\|/, $cgiparams{'LOCAL_SUBNET'});
2022 my $local_subnets = join(",", @local_subnets);
2023
2024 my @remote_subnets = split(/\|/, $cgiparams{'REMOTE_SUBNET'});
2025 my $remote_subnets = join(",", @remote_subnets);
2026
2027 print <<END
2028 <tr>
2029 <td width='20%'>$Lang::tr{'enabled'}</td>
2030 <td width='30%'>
2031 <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} />
2032 </td>
2033 <td class='boldbase' nowrap='nowrap' width='20%'>$Lang::tr{'local subnet'}&nbsp;<img src='/blob.gif' alt='*' /></td>
2034 <td width='30%'>
2035 <input type='text' name='LOCAL_SUBNET' value='$local_subnets' />
2036 </td>
2037 </tr>
2038 <tr>
2039 <td class='boldbase' width='20%'>$Lang::tr{'remote host/ip'}:&nbsp;$blob</td>
2040 <td width='30%'>
2041 <input type='text' name='REMOTE' value='$cgiparams{'REMOTE'}' size="25" />
2042 </td>
2043 <td class='boldbase' nowrap='nowrap' width='20%'>$Lang::tr{'remote subnet'}&nbsp;$blob</td>
2044 <td width='30%'>
2045 <input $disabled type='text' name='REMOTE_SUBNET' value='$remote_subnets' />
2046 </td>
2047 </tr>
2048 <tr>
2049 <td class='boldbase' width='20%'>$Lang::tr{'vpn local id'}:</td>
2050 <td width='30%'>
2051 <input type='text' name='LOCAL_ID' value='$cgiparams{'LOCAL_ID'}' size="25" />
2052 </td>
2053 <td class='boldbase' width='20%'>$Lang::tr{'vpn remote id'}:</td>
2054 <td width='30%'>
2055 <input type='text' name='REMOTE_ID' value='$cgiparams{'REMOTE_ID'}' size="25" />
2056 </td>
2057 </tr>
2058 <tr><td colspan="4"><br /></td></tr>
2059 <tr>
2060 <td class='boldbase' width='20%'>$Lang::tr{'remark title'}</td>
2061 <td colspan='3'>
2062 <input type='text' name='REMARK' value='$cgiparams{'REMARK'}' maxlength='50' size="73" />
2063 </td>
2064 </tr>
2065 END
2066 ;
2067 if (!$cgiparams{'KEY'}) {
2068 print "<tr><td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked{'EDIT_ADVANCED'}{'on'} /> $Lang::tr{'edit advanced settings when done'}</td></tr>";
2069 }
2070 print "</table>";
2071 &Header::closebox();
2072
2073 if ($cgiparams{'KEY'} && $cgiparams{'AUTH'} eq 'psk') {
2074 &Header::openbox('100%', 'left', $Lang::tr{'authentication'});
2075 print <<END
2076 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2077 <tr><td class='base' width='50%'>$Lang::tr{'use a pre-shared key'}</td>
2078 <td class='base' width='50%'><input type='password' name='PSK' size='30' value='$cgiparams{'PSK'}' /></td>
2079 </tr>
2080 </table>
2081 END
2082 ;
2083 &Header::closebox();
2084 } elsif (! $cgiparams{'KEY'}) {
2085 my $cakeydisabled = ( ! -f "${General::swroot}/private/cakey.pem" ) ? "disabled='disabled'" : '';
2086 $cgiparams{'CERT_NAME'} = $Lang::tr{'vpn no full pki'} if ($cakeydisabled);
2087 my $cacrtdisabled = ( ! -f "${General::swroot}/ca/cacert.pem" ) ? "disabled='disabled'" : '';
2088
2089 &Header::openbox('100%', 'left', $Lang::tr{'authentication'});
2090 print <<END
2091 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2092 <tr><td width='5%'><input type='radio' name='AUTH' value='psk' $checked{'AUTH'}{'psk'} /></td>
2093 <td class='base' width='55%'>$Lang::tr{'use a pre-shared key'}</td>
2094 <td class='base' width='40%'><input type='password' name='PSK' size='30' value='$cgiparams{'PSK'}' /></td></tr>
2095 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2096 <tr><td><input type='radio' name='AUTH' value='certreq' $checked{'AUTH'}{'certreq'} $cakeydisabled /></td>
2097 <td class='base'><hr />$Lang::tr{'upload a certificate request'}</td>
2098 <td class='base' rowspan='3' valign='middle'><input type='file' name='FH' size='30' $cacrtdisabled /></td></tr>
2099 <tr><td><input type='radio' name='AUTH' value='certfile' $checked{'AUTH'}{'certfile'} $cacrtdisabled /></td>
2100 <td class='base'>$Lang::tr{'upload a certificate'}</td></tr>
2101 <tr><td><input type='radio' name='AUTH' value='pkcs12' $cacrtdisabled /></td>
2102 <td class='base'>$Lang::tr{'upload p12 file'} $Lang::tr{'pkcs12 file password'}:<input type='password' name='P12_PASS'/></td></tr>
2103 <tr><td><input type='radio' name='AUTH' value='auth-dn' $checked{'AUTH'}{'auth-dn'} $cacrtdisabled /></td>
2104 <td class='base'><hr />$Lang::tr{'vpn auth-dn'}</td></tr>
2105 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2106 <tr><td><input type='radio' name='AUTH' value='certgen' $checked{'AUTH'}{'certgen'} $cakeydisabled /></td>
2107 <td class='base'><hr />$Lang::tr{'generate a certificate'}</td><td>&nbsp;</td></tr>
2108 <tr><td>&nbsp;</td>
2109 <td class='base'>$Lang::tr{'users fullname or system hostname'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
2110 <td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value='$cgiparams{'CERT_NAME'}' size='32' $cakeydisabled /></td></tr>
2111 <tr><td>&nbsp;</td>
2112 <td class='base'>$Lang::tr{'users email'}:</td>
2113 <td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value='$cgiparams{'CERT_EMAIL'}' size='32' $cakeydisabled /></td></tr>
2114 <tr><td>&nbsp;</td>
2115 <td class='base'>$Lang::tr{'users department'}:</td>
2116 <td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value='$cgiparams{'CERT_OU'}' size='32' $cakeydisabled /></td></tr>
2117 <tr><td>&nbsp;</td>
2118 <td class='base'>$Lang::tr{'organization name'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
2119 <td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value='$cgiparams{'CERT_ORGANIZATION'}' size='32' $cakeydisabled /></td></tr>
2120 <tr><td>&nbsp;</td>
2121 <td class='base'>$Lang::tr{'city'}:</td>
2122 <td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value='$cgiparams{'CERT_CITY'}' size='32' $cakeydisabled /></td></tr>
2123 <tr><td>&nbsp;</td>
2124 <td class='base'>$Lang::tr{'state or province'}:</td>
2125 <td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value='$cgiparams{'CERT_STATE'}' size='32' $cakeydisabled /></td></tr>
2126 <tr><td>&nbsp;</td>
2127 <td class='base'>$Lang::tr{'country'}:</td>
2128 <td class='base'><select name='CERT_COUNTRY' $cakeydisabled>
2129 END
2130 ;
2131 foreach my $country (sort keys %{Countries::countries}) {
2132 print "\t\t\t<option value='$Countries::countries{$country}'";
2133 if ( $Countries::countries{$country} eq $cgiparams{'CERT_COUNTRY'} ) {
2134 print " selected='selected'";
2135 }
2136 print ">$country</option>\n";
2137 }
2138 print <<END
2139 </select></td></tr>
2140
2141 <tr><td>&nbsp;</td><td class='base'>$Lang::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)</td>
2142 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value='$cgiparams{'SUBJECTALTNAME'}' size='32' $cakeydisabled /></td></tr>
2143 <tr><td>&nbsp;</td>
2144 <td class='base'>$Lang::tr{'pkcs12 file password'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
2145 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value='$cgiparams{'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
2146 <tr><td>&nbsp;</td><td class='base'>$Lang::tr{'pkcs12 file password'}&nbsp;($Lang::tr{'confirmation'}):&nbsp;<img src='/blob.gif' alt='*' /></td>
2147 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value='$cgiparams{'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
2148 </table>
2149 END
2150 ;
2151 &Header::closebox();
2152 }
2153
2154 print "<div align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' />";
2155 if ($cgiparams{'KEY'}) {
2156 print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />";
2157 }
2158 print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>";
2159 &Header::closebigbox();
2160 &Header::closepage();
2161 exit (0);
2162
2163 VPNCONF_END:
2164 }
2165
2166 ###
2167 ### Advanced settings
2168 ###
2169 if(($cgiparams{'ACTION'} eq $Lang::tr{'advanced'}) ||
2170 ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'ADVANCED'} eq 'yes')) {
2171 &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings);
2172 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
2173 if (! $confighash{$cgiparams{'KEY'}}) {
2174 $errormessage = $Lang::tr{'invalid key'};
2175 goto ADVANCED_END;
2176 }
2177
2178 if ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) {
2179 my @temp = split('\|', $cgiparams{'IKE_ENCRYPTION'});
2180 if ($#temp < 0) {
2181 $errormessage = $Lang::tr{'invalid input'};
2182 goto ADVANCED_ERROR;
2183 }
2184 foreach my $val (@temp) {
2185 if ($val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|chacha20poly1305|camellia(256|192|128))$/) {
2186 $errormessage = $Lang::tr{'invalid input'};
2187 goto ADVANCED_ERROR;
2188 }
2189 }
2190 @temp = split('\|', $cgiparams{'IKE_INTEGRITY'});
2191 if ($#temp < 0) {
2192 $errormessage = $Lang::tr{'invalid input'};
2193 goto ADVANCED_ERROR;
2194 }
2195 foreach my $val (@temp) {
2196 if ($val !~ /^(sha2_(512|384|256)|sha|md5|aesxcbc)$/) {
2197 $errormessage = $Lang::tr{'invalid input'};
2198 goto ADVANCED_ERROR;
2199 }
2200 }
2201 @temp = split('\|', $cgiparams{'IKE_GROUPTYPE'});
2202 if ($#temp < 0) {
2203 $errormessage = $Lang::tr{'invalid input'};
2204 goto ADVANCED_ERROR;
2205 }
2206 foreach my $val (@temp) {
2207 if ($val !~ /^(curve25519|e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|768|1024|1536|2048|3072|4096|6144|8192)$/) {
2208 $errormessage = $Lang::tr{'invalid input'};
2209 goto ADVANCED_ERROR;
2210 }
2211 }
2212 if ($cgiparams{'IKE_LIFETIME'} !~ /^\d+$/) {
2213 $errormessage = $Lang::tr{'invalid input for ike lifetime'};
2214 goto ADVANCED_ERROR;
2215 }
2216 if ($cgiparams{'IKE_LIFETIME'} < 1 || $cgiparams{'IKE_LIFETIME'} > 8) {
2217 $errormessage = $Lang::tr{'ike lifetime should be between 1 and 8 hours'};
2218 goto ADVANCED_ERROR;
2219 }
2220 @temp = split('\|', $cgiparams{'ESP_ENCRYPTION'});
2221 if ($#temp < 0) {
2222 $errormessage = $Lang::tr{'invalid input'};
2223 goto ADVANCED_ERROR;
2224 }
2225 foreach my $val (@temp) {
2226 if ($val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|chacha20poly1305|camellia(256|192|128))$/) {
2227 $errormessage = $Lang::tr{'invalid input'};
2228 goto ADVANCED_ERROR;
2229 }
2230 }
2231 @temp = split('\|', $cgiparams{'ESP_INTEGRITY'});
2232 if ($#temp < 0) {
2233 $errormessage = $Lang::tr{'invalid input'};
2234 goto ADVANCED_ERROR;
2235 }
2236 foreach my $val (@temp) {
2237 if ($val !~ /^(sha2_(512|384|256)|sha1|md5|aesxcbc)$/) {
2238 $errormessage = $Lang::tr{'invalid input'};
2239 goto ADVANCED_ERROR;
2240 }
2241 }
2242 @temp = split('\|', $cgiparams{'ESP_GROUPTYPE'});
2243 if ($#temp < 0) {
2244 $errormessage = $Lang::tr{'invalid input'};
2245 goto ADVANCED_ERROR;
2246 }
2247 foreach my $val (@temp) {
2248 if ($val !~ /^(curve25519|e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|768|1024|1536|2048|3072|4096|6144|8192|none)$/) {
2249 $errormessage = $Lang::tr{'invalid input'};
2250 goto ADVANCED_ERROR;
2251 }
2252 }
2253 if ($cgiparams{'ESP_KEYLIFE'} !~ /^\d+$/) {
2254 $errormessage = $Lang::tr{'invalid input for esp keylife'};
2255 goto ADVANCED_ERROR;
2256 }
2257 if ($cgiparams{'ESP_KEYLIFE'} < 1 || $cgiparams{'ESP_KEYLIFE'} > 24) {
2258 $errormessage = $Lang::tr{'esp keylife should be between 1 and 24 hours'};
2259 goto ADVANCED_ERROR;
2260 }
2261
2262 if (($cgiparams{'COMPRESSION'} !~ /^(|on|off)$/) ||
2263 ($cgiparams{'FORCE_MOBIKE'} !~ /^(|on|off)$/) ||
2264 ($cgiparams{'ONLY_PROPOSED'} !~ /^(|on|off)$/) ||
2265 ($cgiparams{'PFS'} !~ /^(|on|off)$/)) {
2266 $errormessage = $Lang::tr{'invalid input'};
2267 goto ADVANCED_ERROR;
2268 }
2269
2270 if ($cgiparams{'DPD_DELAY'} !~ /^\d+$/) {
2271 $errormessage = $Lang::tr{'invalid input for dpd delay'};
2272 goto ADVANCED_ERROR;
2273 }
2274
2275 if ($cgiparams{'DPD_TIMEOUT'} !~ /^\d+$/) {
2276 $errormessage = $Lang::tr{'invalid input for dpd timeout'};
2277 goto ADVANCED_ERROR;
2278 }
2279
2280 if ($cgiparams{'INACTIVITY_TIMEOUT'} !~ /^\d+$/) {
2281 $errormessage = $Lang::tr{'invalid input for inactivity timeout'};
2282 goto ADVANCED_ERROR;
2283 }
2284
2285 $confighash{$cgiparams{'KEY'}}[29] = $cgiparams{'IKE_VERSION'};
2286 $confighash{$cgiparams{'KEY'}}[18] = $cgiparams{'IKE_ENCRYPTION'};
2287 $confighash{$cgiparams{'KEY'}}[19] = $cgiparams{'IKE_INTEGRITY'};
2288 $confighash{$cgiparams{'KEY'}}[20] = $cgiparams{'IKE_GROUPTYPE'};
2289 $confighash{$cgiparams{'KEY'}}[16] = $cgiparams{'IKE_LIFETIME'};
2290 $confighash{$cgiparams{'KEY'}}[21] = $cgiparams{'ESP_ENCRYPTION'};
2291 $confighash{$cgiparams{'KEY'}}[22] = $cgiparams{'ESP_INTEGRITY'};
2292 $confighash{$cgiparams{'KEY'}}[23] = $cgiparams{'ESP_GROUPTYPE'};
2293 $confighash{$cgiparams{'KEY'}}[17] = $cgiparams{'ESP_KEYLIFE'};
2294 $confighash{$cgiparams{'KEY'}}[12] = 'off'; #$cgiparams{'AGGRMODE'};
2295 $confighash{$cgiparams{'KEY'}}[13] = $cgiparams{'COMPRESSION'};
2296 $confighash{$cgiparams{'KEY'}}[24] = $cgiparams{'ONLY_PROPOSED'};
2297 $confighash{$cgiparams{'KEY'}}[28] = $cgiparams{'PFS'};
2298 $confighash{$cgiparams{'KEY'}}[27] = $cgiparams{'DPD_ACTION'};
2299 $confighash{$cgiparams{'KEY'}}[30] = $cgiparams{'DPD_TIMEOUT'};
2300 $confighash{$cgiparams{'KEY'}}[31] = $cgiparams{'DPD_DELAY'};
2301 $confighash{$cgiparams{'KEY'}}[32] = $cgiparams{'FORCE_MOBIKE'};
2302 $confighash{$cgiparams{'KEY'}}[33] = $cgiparams{'START_ACTION'};
2303 $confighash{$cgiparams{'KEY'}}[34] = $cgiparams{'INACTIVITY_TIMEOUT'};
2304 &General::writehasharray("${General::swroot}/vpn/config", \%confighash);
2305 &writeipsecfiles();
2306 if (&vpnenabled) {
2307 system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
2308 sleep $sleepDelay;
2309 }
2310 goto ADVANCED_END;
2311 } else {
2312 $cgiparams{'IKE_VERSION'} = $confighash{$cgiparams{'KEY'}}[29];
2313 $cgiparams{'IKE_ENCRYPTION'} = $confighash{$cgiparams{'KEY'}}[18];
2314 $cgiparams{'IKE_INTEGRITY'} = $confighash{$cgiparams{'KEY'}}[19];
2315 $cgiparams{'IKE_GROUPTYPE'} = $confighash{$cgiparams{'KEY'}}[20];
2316 $cgiparams{'IKE_LIFETIME'} = $confighash{$cgiparams{'KEY'}}[16];
2317 $cgiparams{'ESP_ENCRYPTION'} = $confighash{$cgiparams{'KEY'}}[21];
2318 $cgiparams{'ESP_INTEGRITY'} = $confighash{$cgiparams{'KEY'}}[22];
2319 $cgiparams{'ESP_GROUPTYPE'} = $confighash{$cgiparams{'KEY'}}[23];
2320 if ($cgiparams{'ESP_GROUPTYPE'} eq "") {
2321 $cgiparams{'ESP_GROUPTYPE'} = $cgiparams{'IKE_GROUPTYPE'};
2322 }
2323 $cgiparams{'ESP_KEYLIFE'} = $confighash{$cgiparams{'KEY'}}[17];
2324 $cgiparams{'COMPRESSION'} = $confighash{$cgiparams{'KEY'}}[13];
2325 $cgiparams{'ONLY_PROPOSED'} = $confighash{$cgiparams{'KEY'}}[24];
2326 $cgiparams{'PFS'} = $confighash{$cgiparams{'KEY'}}[28];
2327 $cgiparams{'DPD_ACTION'} = $confighash{$cgiparams{'KEY'}}[27];
2328 $cgiparams{'DPD_TIMEOUT'} = $confighash{$cgiparams{'KEY'}}[30];
2329 $cgiparams{'DPD_DELAY'} = $confighash{$cgiparams{'KEY'}}[31];
2330 $cgiparams{'FORCE_MOBIKE'} = $confighash{$cgiparams{'KEY'}}[32];
2331 $cgiparams{'START_ACTION'} = $confighash{$cgiparams{'KEY'}}[33];
2332 $cgiparams{'INACTIVITY_TIMEOUT'} = $confighash{$cgiparams{'KEY'}}[34];
2333
2334 if (!$cgiparams{'DPD_DELAY'}) {
2335 $cgiparams{'DPD_DELAY'} = 30;
2336 }
2337
2338 if (!$cgiparams{'DPD_TIMEOUT'}) {
2339 $cgiparams{'DPD_TIMEOUT'} = 120;
2340 }
2341
2342 if (!$cgiparams{'START_ACTION'}) {
2343 $cgiparams{'START_ACTION'} = "start";
2344 }
2345
2346 if ($cgiparams{'INACTIVITY_TIMEOUT'} eq "") {
2347 $cgiparams{'INACTIVITY_TIMEOUT'} = 900; # 15 min
2348 }
2349 }
2350
2351 ADVANCED_ERROR:
2352 $checked{'IKE_ENCRYPTION'}{'chacha20poly1305'} = '';
2353 $checked{'IKE_ENCRYPTION'}{'aes256'} = '';
2354 $checked{'IKE_ENCRYPTION'}{'aes192'} = '';
2355 $checked{'IKE_ENCRYPTION'}{'aes128'} = '';
2356 $checked{'IKE_ENCRYPTION'}{'aes256gcm128'} = '';
2357 $checked{'IKE_ENCRYPTION'}{'aes192gcm128'} = '';
2358 $checked{'IKE_ENCRYPTION'}{'aes128gcm128'} = '';
2359 $checked{'IKE_ENCRYPTION'}{'aes256gcm96'} = '';
2360 $checked{'IKE_ENCRYPTION'}{'aes192gcm96'} = '';
2361 $checked{'IKE_ENCRYPTION'}{'aes128gcm96'} = '';
2362 $checked{'IKE_ENCRYPTION'}{'aes256gcm64'} = '';
2363 $checked{'IKE_ENCRYPTION'}{'aes192gcm64'} = '';
2364 $checked{'IKE_ENCRYPTION'}{'aes128gcm64'} = '';
2365 $checked{'IKE_ENCRYPTION'}{'3des'} = '';
2366 $checked{'IKE_ENCRYPTION'}{'camellia256'} = '';
2367 $checked{'IKE_ENCRYPTION'}{'camellia192'} = '';
2368 $checked{'IKE_ENCRYPTION'}{'camellia128'} = '';
2369 my @temp = split('\|', $cgiparams{'IKE_ENCRYPTION'});
2370 foreach my $key (@temp) {$checked{'IKE_ENCRYPTION'}{$key} = "selected='selected'"; }
2371 $checked{'IKE_INTEGRITY'}{'sha2_512'} = '';
2372 $checked{'IKE_INTEGRITY'}{'sha2_384'} = '';
2373 $checked{'IKE_INTEGRITY'}{'sha2_256'} = '';
2374 $checked{'IKE_INTEGRITY'}{'sha'} = '';
2375 $checked{'IKE_INTEGRITY'}{'md5'} = '';
2376 $checked{'IKE_INTEGRITY'}{'aesxcbc'} = '';
2377 @temp = split('\|', $cgiparams{'IKE_INTEGRITY'});
2378 foreach my $key (@temp) {$checked{'IKE_INTEGRITY'}{$key} = "selected='selected'"; }
2379 $checked{'IKE_GROUPTYPE'}{'curve25519'} = '';
2380 $checked{'IKE_GROUPTYPE'}{'768'} = '';
2381 $checked{'IKE_GROUPTYPE'}{'1024'} = '';
2382 $checked{'IKE_GROUPTYPE'}{'1536'} = '';
2383 $checked{'IKE_GROUPTYPE'}{'2048'} = '';
2384 $checked{'IKE_GROUPTYPE'}{'3072'} = '';
2385 $checked{'IKE_GROUPTYPE'}{'4096'} = '';
2386 $checked{'IKE_GROUPTYPE'}{'6144'} = '';
2387 $checked{'IKE_GROUPTYPE'}{'8192'} = '';
2388 @temp = split('\|', $cgiparams{'IKE_GROUPTYPE'});
2389 foreach my $key (@temp) {$checked{'IKE_GROUPTYPE'}{$key} = "selected='selected'"; }
2390
2391 $checked{'ESP_ENCRYPTION'}{'chacha20poly1305'} = '';
2392 $checked{'ESP_ENCRYPTION'}{'aes256'} = '';
2393 $checked{'ESP_ENCRYPTION'}{'aes192'} = '';
2394 $checked{'ESP_ENCRYPTION'}{'aes128'} = '';
2395 $checked{'ESP_ENCRYPTION'}{'aes256gcm128'} = '';
2396 $checked{'ESP_ENCRYPTION'}{'aes192gcm128'} = '';
2397 $checked{'ESP_ENCRYPTION'}{'aes128gcm128'} = '';
2398 $checked{'ESP_ENCRYPTION'}{'aes256gcm96'} = '';
2399 $checked{'ESP_ENCRYPTION'}{'aes192gcm96'} = '';
2400 $checked{'ESP_ENCRYPTION'}{'aes128gcm96'} = '';
2401 $checked{'ESP_ENCRYPTION'}{'aes256gcm64'} = '';
2402 $checked{'ESP_ENCRYPTION'}{'aes192gcm64'} = '';
2403 $checked{'ESP_ENCRYPTION'}{'aes128gcm64'} = '';
2404 $checked{'ESP_ENCRYPTION'}{'3des'} = '';
2405 $checked{'ESP_ENCRYPTION'}{'camellia256'} = '';
2406 $checked{'ESP_ENCRYPTION'}{'camellia192'} = '';
2407 $checked{'ESP_ENCRYPTION'}{'camellia128'} = '';
2408 @temp = split('\|', $cgiparams{'ESP_ENCRYPTION'});
2409 foreach my $key (@temp) {$checked{'ESP_ENCRYPTION'}{$key} = "selected='selected'"; }
2410 $checked{'ESP_INTEGRITY'}{'sha2_512'} = '';
2411 $checked{'ESP_INTEGRITY'}{'sha2_384'} = '';
2412 $checked{'ESP_INTEGRITY'}{'sha2_256'} = '';
2413 $checked{'ESP_INTEGRITY'}{'sha1'} = '';
2414 $checked{'ESP_INTEGRITY'}{'md5'} = '';
2415 $checked{'ESP_INTEGRITY'}{'aesxcbc'} = '';
2416 @temp = split('\|', $cgiparams{'ESP_INTEGRITY'});
2417 foreach my $key (@temp) {$checked{'ESP_INTEGRITY'}{$key} = "selected='selected'"; }
2418 $checked{'ESP_GROUPTYPE'}{'curve25519'} = '';
2419 $checked{'ESP_GROUPTYPE'}{'768'} = '';
2420 $checked{'ESP_GROUPTYPE'}{'1024'} = '';
2421 $checked{'ESP_GROUPTYPE'}{'1536'} = '';
2422 $checked{'ESP_GROUPTYPE'}{'2048'} = '';
2423 $checked{'ESP_GROUPTYPE'}{'3072'} = '';
2424 $checked{'ESP_GROUPTYPE'}{'4096'} = '';
2425 $checked{'ESP_GROUPTYPE'}{'6144'} = '';
2426 $checked{'ESP_GROUPTYPE'}{'8192'} = '';
2427 $checked{'ESP_GROUPTYPE'}{'none'} = '';
2428 @temp = split('\|', $cgiparams{'ESP_GROUPTYPE'});
2429 foreach my $key (@temp) {$checked{'ESP_GROUPTYPE'}{$key} = "selected='selected'"; }
2430
2431 $checked{'COMPRESSION'} = $cgiparams{'COMPRESSION'} eq 'on' ? "checked='checked'" : '' ;
2432 $checked{'FORCE_MOBIKE'} = $cgiparams{'FORCE_MOBIKE'} eq 'on' ? "checked='checked'" : '' ;
2433 $checked{'ONLY_PROPOSED'} = $cgiparams{'ONLY_PROPOSED'} eq 'on' ? "checked='checked'" : '' ;
2434 $checked{'PFS'} = $cgiparams{'PFS'} eq 'on' ? "checked='checked'" : '' ;
2435
2436 $selected{'IKE_VERSION'}{'ikev1'} = '';
2437 $selected{'IKE_VERSION'}{'ikev2'} = '';
2438 $selected{'IKE_VERSION'}{$cgiparams{'IKE_VERSION'}} = "selected='selected'";
2439
2440 $selected{'DPD_ACTION'}{'clear'} = '';
2441 $selected{'DPD_ACTION'}{'hold'} = '';
2442 $selected{'DPD_ACTION'}{'restart'} = '';
2443 $selected{'DPD_ACTION'}{'none'} = '';
2444 $selected{'DPD_ACTION'}{$cgiparams{'DPD_ACTION'}} = "selected='selected'";
2445
2446 $selected{'START_ACTION'}{'add'} = '';
2447 $selected{'START_ACTION'}{'route'} = '';
2448 $selected{'START_ACTION'}{'start'} = '';
2449 $selected{'START_ACTION'}{$cgiparams{'START_ACTION'}} = "selected='selected'";
2450
2451 $selected{'INACTIVITY_TIMEOUT'} = ();
2452 foreach my $timeout (keys %INACTIVITY_TIMEOUTS) {
2453 $selected{'INACTIVITY_TIMEOUT'}{$timeout} = "";
2454 }
2455 $selected{'INACTIVITY_TIMEOUT'}{$cgiparams{'INACTIVITY_TIMEOUT'}} = "selected";
2456
2457 &Header::showhttpheaders();
2458 &Header::openpage($Lang::tr{'ipsec'}, 1, '');
2459 &Header::openbigbox('100%', 'left', '', $errormessage);
2460
2461 if ($errormessage) {
2462 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
2463 print "<class name='base'>$errormessage";
2464 print "&nbsp;</class>";
2465 &Header::closebox();
2466 }
2467
2468 if ($warnmessage) {
2469 &Header::openbox('100%', 'left', $Lang::tr{'warning messages'});
2470 print "<class name='base'>$warnmessage";
2471 print "&nbsp;</class>";
2472 &Header::closebox();
2473 }
2474
2475 &Header::openbox('100%', 'left', "$Lang::tr{'advanced'}:");
2476 print <<EOF;
2477 <form method='post' enctype='multipart/form-data' action='$ENV{'SCRIPT_NAME'}'>
2478 <input type='hidden' name='ADVANCED' value='yes' />
2479 <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />
2480
2481 <table width='100%'>
2482 <thead>
2483 <tr>
2484 <th width="15%"></th>
2485 <th>IKE</th>
2486 <th>ESP</th>
2487 </tr>
2488 </thead>
2489 <tbody>
2490 <tr>
2491 <td>$Lang::tr{'vpn keyexchange'}:</td>
2492 <td>
2493 <select name='IKE_VERSION'>
2494 <option value='ikev2' $selected{'IKE_VERSION'}{'ikev2'}>IKEv2</option>
2495 <option value='ikev1' $selected{'IKE_VERSION'}{'ikev1'}>IKEv1</option>
2496 </select>
2497 </td>
2498 <td></td>
2499 </tr>
2500 <tr>
2501 <td class='boldbase' width="15%">$Lang::tr{'encryption'}</td>
2502 <td class='boldbase'>
2503 <select name='IKE_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
2504 <option value='chacha20poly1305' $checked{'IKE_ENCRYPTION'}{'chacha20poly1305'}>256 bit ChaCha20-Poly1305/128 bit ICV</option>
2505 <option value='aes256gcm128' $checked{'IKE_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
2506 <option value='aes256gcm96' $checked{'IKE_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
2507 <option value='aes256gcm64' $checked{'IKE_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
2508 <option value='aes256' $checked{'IKE_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
2509 <option value='camellia256' $checked{'IKE_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
2510 <option value='aes192gcm128' $checked{'IKE_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
2511 <option value='aes192gcm96' $checked{'IKE_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
2512 <option value='aes192gcm64' $checked{'IKE_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
2513 <option value='aes192' $checked{'IKE_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
2514 <option value='camellia192' $checked{'IKE_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
2515 <option value='aes128gcm128' $checked{'IKE_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
2516 <option value='aes128gcm96' $checked{'IKE_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
2517 <option value='aes128gcm64' $checked{'IKE_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
2518 <option value='aes128' $checked{'IKE_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
2519 <option value='camellia128' $checked{'IKE_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
2520 <option value='3des' $checked{'IKE_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC ($Lang::tr{'vpn weak'})</option>
2521 </select>
2522 </td>
2523 <td class='boldbase'>
2524 <select name='ESP_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
2525 <option value='chacha20poly1305' $checked{'ESP_ENCRYPTION'}{'chacha20poly1305'}>256 bit ChaCha20-Poly1305/128 bit ICV</option>
2526 <option value='aes256gcm128' $checked{'ESP_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
2527 <option value='aes256gcm96' $checked{'ESP_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
2528 <option value='aes256gcm64' $checked{'ESP_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
2529 <option value='aes256' $checked{'ESP_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
2530 <option value='camellia256' $checked{'ESP_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
2531 <option value='aes192gcm128' $checked{'ESP_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
2532 <option value='aes192gcm96' $checked{'ESP_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
2533 <option value='aes192gcm64' $checked{'ESP_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
2534 <option value='aes192' $checked{'ESP_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
2535 <option value='camellia192' $checked{'ESP_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
2536 <option value='aes128gcm128' $checked{'ESP_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
2537 <option value='aes128gcm96' $checked{'ESP_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
2538 <option value='aes128gcm64' $checked{'ESP_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
2539 <option value='aes128' $checked{'ESP_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
2540 <option value='camellia128' $checked{'ESP_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
2541 <option value='3des' $checked{'ESP_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC ($Lang::tr{'vpn weak'})</option>
2542 </select>
2543 </td>
2544 </tr>
2545
2546 <tr>
2547 <td class='boldbase' width="15%">$Lang::tr{'integrity'}</td>
2548 <td class='boldbase'>
2549 <select name='IKE_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
2550 <option value='sha2_512' $checked{'IKE_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2551 <option value='sha2_384' $checked{'IKE_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2552 <option value='sha2_256' $checked{'IKE_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2553 <option value='aesxcbc' $checked{'IKE_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2554 <option value='sha' $checked{'IKE_INTEGRITY'}{'sha'}>SHA1 ($Lang::tr{'vpn weak'})</option>
2555 <option value='md5' $checked{'IKE_INTEGRITY'}{'md5'}>MD5 ($Lang::tr{'vpn broken'})</option>
2556 </select>
2557 </td>
2558 <td class='boldbase'>
2559 <select name='ESP_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
2560 <option value='sha2_512' $checked{'ESP_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2561 <option value='sha2_384' $checked{'ESP_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2562 <option value='sha2_256' $checked{'ESP_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2563 <option value='aesxcbc' $checked{'ESP_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2564 <option value='sha1' $checked{'ESP_INTEGRITY'}{'sha1'}>SHA1 ($Lang::tr{'vpn weak'})</option>
2565 <option value='md5' $checked{'ESP_INTEGRITY'}{'md5'}>MD5 ($Lang::tr{'vpn broken'})</option>
2566 </select>
2567 </td>
2568 </tr>
2569 <tr>
2570 <td class='boldbase' width="15%">$Lang::tr{'lifetime'}&nbsp;<img src='/blob.gif' alt='*' /></td>
2571 <td class='boldbase'>
2572 <input type='text' name='IKE_LIFETIME' value='$cgiparams{'IKE_LIFETIME'}' size='5' /> $Lang::tr{'hours'}
2573 </td>
2574 <td class='boldbase'>
2575 <input type='text' name='ESP_KEYLIFE' value='$cgiparams{'ESP_KEYLIFE'}' size='5' /> $Lang::tr{'hours'}
2576 </td>
2577 </tr>
2578 <tr>
2579 <td class='boldbase' width="15%">$Lang::tr{'grouptype'}</td>
2580 <td class='boldbase'>
2581 <select name='IKE_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
2582 <option value='curve25519' $checked{'IKE_GROUPTYPE'}{'curve25519'}>Curve 25519 (256 bit)</option>
2583 <option value='e521' $checked{'IKE_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
2584 <option value='e512bp' $checked{'IKE_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
2585 <option value='e384' $checked{'IKE_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
2586 <option value='e384bp' $checked{'IKE_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
2587 <option value='e256' $checked{'IKE_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
2588 <option value='e256bp' $checked{'IKE_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
2589 <option value='e224' $checked{'IKE_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
2590 <option value='e224bp' $checked{'IKE_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
2591 <option value='e192' $checked{'IKE_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
2592 <option value='8192' $checked{'IKE_GROUPTYPE'}{'8192'}>MODP-8192</option>
2593 <option value='6144' $checked{'IKE_GROUPTYPE'}{'6144'}>MODP-6144</option>
2594 <option value='4096' $checked{'IKE_GROUPTYPE'}{'4096'}>MODP-4096</option>
2595 <option value='3072' $checked{'IKE_GROUPTYPE'}{'3072'}>MODP-3072</option>
2596 <option value='2048' $checked{'IKE_GROUPTYPE'}{'2048'}>MODP-2048</option>
2597 <option value='1536' $checked{'IKE_GROUPTYPE'}{'1536'}>MODP-1536</option>
2598 <option value='1024' $checked{'IKE_GROUPTYPE'}{'1024'}>MODP-1024 ($Lang::tr{'vpn broken'})</option>
2599 <option value='768' $checked{'IKE_GROUPTYPE'}{'768'}>MODP-768 ($Lang::tr{'vpn broken'})</option>
2600 </select>
2601 </td>
2602 <td class='boldbase'>
2603 <select name='ESP_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
2604 <option value='curve25519' $checked{'ESP_GROUPTYPE'}{'curve25519'}>Curve 25519 (256 bit)</option>
2605 <option value='e521' $checked{'ESP_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
2606 <option value='e512bp' $checked{'ESP_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
2607 <option value='e384' $checked{'ESP_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
2608 <option value='e384bp' $checked{'ESP_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
2609 <option value='e256' $checked{'ESP_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
2610 <option value='e256bp' $checked{'ESP_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
2611 <option value='e224' $checked{'ESP_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
2612 <option value='e224bp' $checked{'ESP_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
2613 <option value='e192' $checked{'ESP_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
2614 <option value='8192' $checked{'ESP_GROUPTYPE'}{'8192'}>MODP-8192</option>
2615 <option value='6144' $checked{'ESP_GROUPTYPE'}{'6144'}>MODP-6144</option>
2616 <option value='4096' $checked{'ESP_GROUPTYPE'}{'4096'}>MODP-4096</option>
2617 <option value='3072' $checked{'ESP_GROUPTYPE'}{'3072'}>MODP-3072</option>
2618 <option value='2048' $checked{'ESP_GROUPTYPE'}{'2048'}>MODP-2048</option>
2619 <option value='1536' $checked{'ESP_GROUPTYPE'}{'1536'}>MODP-1536</option>
2620 <option value='1024' $checked{'ESP_GROUPTYPE'}{'1024'}>MODP-1024 ($Lang::tr{'vpn broken'})</option>
2621 <option value='768' $checked{'ESP_GROUPTYPE'}{'768'}>MODP-768 ($Lang::tr{'vpn broken'})</option>
2622 <option value='none' $checked{'ESP_GROUPTYPE'}{'none'}>- $Lang::tr{'none'} -</option>
2623 </select>
2624 </td>
2625 </tr>
2626 </tbody>
2627 </table>
2628
2629 <br><br>
2630
2631 <h2>$Lang::tr{'dead peer detection'}</h2>
2632
2633 <table width="100%">
2634 <tr>
2635 <td width="15%">$Lang::tr{'dpd action'}:</td>
2636 <td>
2637 <select name='DPD_ACTION'>
2638 <option value='none' $selected{'DPD_ACTION'}{'none'}>- $Lang::tr{'disabled'} -</option>
2639 <option value='clear' $selected{'DPD_ACTION'}{'clear'}>clear</option>
2640 <option value='hold' $selected{'DPD_ACTION'}{'hold'}>hold</option>
2641 <option value='restart' $selected{'DPD_ACTION'}{'restart'}>restart</option>
2642 </select>
2643 </td>
2644 </tr>
2645 <tr>
2646 <td width="15%">$Lang::tr{'dpd timeout'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
2647 <td>
2648 <input type='text' name='DPD_TIMEOUT' size='5' value='$cgiparams{'DPD_TIMEOUT'}' />
2649 </td>
2650 </tr>
2651 <tr>
2652 <td width="15%">$Lang::tr{'dpd delay'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
2653 <td>
2654 <input type='text' name='DPD_DELAY' size='5' value='$cgiparams{'DPD_DELAY'}' />
2655 </td>
2656 </tr>
2657 </table>
2658
2659 <hr>
2660
2661 <table width="100%">
2662 <tr>
2663 <td>
2664 <label>
2665 <input type='checkbox' name='ONLY_PROPOSED' $checked{'ONLY_PROPOSED'} />
2666 IKE+ESP: $Lang::tr{'use only proposed settings'}
2667 </label>
2668 </td>
2669 <td>
2670 <label>$Lang::tr{'vpn start action'}</label>
2671 <select name="START_ACTION">
2672 <option value="route" $selected{'START_ACTION'}{'route'}>$Lang::tr{'vpn start action route'}</option>
2673 <option value="start" $selected{'START_ACTION'}{'start'}>$Lang::tr{'vpn start action start'}</option>
2674 <option value="add" $selected{'START_ACTION'}{'add'} >$Lang::tr{'vpn start action add'}</option>
2675 </select>
2676 </td>
2677 </tr>
2678 <tr>
2679 <td>
2680 <label>
2681 <input type='checkbox' name='PFS' $checked{'PFS'} />
2682 $Lang::tr{'pfs yes no'}
2683 </label>
2684 </td>
2685 <td>
2686 <label>$Lang::tr{'vpn inactivity timeout'}</label>
2687 <select name="INACTIVITY_TIMEOUT">
2688 EOF
2689 foreach my $t (sort { $a <=> $b } keys %INACTIVITY_TIMEOUTS) {
2690 print "<option value=\"$t\" $selected{'INACTIVITY_TIMEOUT'}{$t}>$INACTIVITY_TIMEOUTS{$t}</option>\n";
2691 }
2692
2693 print <<EOF;
2694
2695 </select>
2696 </td>
2697 </tr>
2698 <tr>
2699 <td colspan="2">
2700 <label>
2701 <input type='checkbox' name='COMPRESSION' $checked{'COMPRESSION'} />
2702 $Lang::tr{'vpn payload compression'}
2703 </label>
2704 </td>
2705 </tr>
2706 <tr>
2707 <td colspan="2">
2708 <label>
2709 <input type='checkbox' name='FORCE_MOBIKE' $checked{'FORCE_MOBIKE'} />
2710 $Lang::tr{'vpn force mobike'}
2711 </label>
2712 </td>
2713 </tr>
2714 <tr>
2715 <td align='left'><img src='/blob.gif' align='top' alt='*' />&nbsp;$Lang::tr{'required field'}</td>
2716 <td align='right'>
2717 <input type='submit' name='ACTION' value='$Lang::tr{'save'}' />
2718 <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' />
2719 </td>
2720 </tr>
2721 </table></form>
2722 EOF
2723
2724 &Header::closebox();
2725 &Header::closebigbox();
2726 &Header::closepage();
2727 exit(0);
2728
2729 ADVANCED_END:
2730 }
2731
2732 ###
2733 ### Default status page
2734 ###
2735 %cgiparams = ();
2736 %cahash = ();
2737 %confighash = ();
2738 &General::readhash("${General::swroot}/vpn/settings", \%cgiparams);
2739 &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash);
2740 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
2741 $cgiparams{'CA_NAME'} = '';
2742
2743 my @status = `/usr/local/bin/ipsecctrl I 2>/dev/null`;
2744
2745 # suggest a default name for this side
2746 if ($cgiparams{'VPN_IP'} eq '' && -e "${General::swroot}/red/active") {
2747 if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) {
2748 my $ipaddr = <IPADDR>;
2749 close IPADDR;
2750 chomp ($ipaddr);
2751 $cgiparams{'VPN_IP'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0];
2752 if ($cgiparams{'VPN_IP'} eq '') {
2753 $cgiparams{'VPN_IP'} = $ipaddr;
2754 }
2755 }
2756 }
2757 # no IP found, use %defaultroute
2758 $cgiparams{'VPN_IP'} ='%defaultroute' if ($cgiparams{'VPN_IP'} eq '');
2759
2760 $cgiparams{'VPN_DELAYED_START'} = 0 if (! defined ($cgiparams{'VPN_DELAYED_START'}));
2761 $checked{'ENABLED'} = $cgiparams{'ENABLED'} eq 'on' ? "checked='checked'" : '';
2762
2763 &Header::showhttpheaders();
2764 &Header::openpage($Lang::tr{'ipsec'}, 1, '');
2765 &Header::openbigbox('100%', 'left', '', $errormessage);
2766
2767 if ($errormessage) {
2768 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
2769 print "<class name='base'>$errormessage\n";
2770 print "&nbsp;</class>\n";
2771 &Header::closebox();
2772 }
2773
2774 if ($warnmessage) {
2775 &Header::openbox('100%', 'left', $Lang::tr{'warning messages'});
2776 print "$warnmessage<br>";
2777 print "$Lang::tr{'fwdfw warn1'}<br>";
2778 &Header::closebox();
2779 print"<center><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'ok'}' style='width: 5em;'></form>";
2780 &Header::closepage();
2781 exit 0;
2782 }
2783
2784 &Header::openbox('100%', 'left', $Lang::tr{'global settings'});
2785 print <<END
2786 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2787 <table width='100%'>
2788 <tr>
2789 <td width='20%' class='base' nowrap='nowrap'>$Lang::tr{'vpn red name'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
2790 <td width='20%'><input type='text' name='VPN_IP' value='$cgiparams{'VPN_IP'}' /></td>
2791 <td width='20%' class='base'>$Lang::tr{'enabled'}<input type='checkbox' name='ENABLED' $checked{'ENABLED'} /></td>
2792 </tr>
2793 END
2794 ;
2795 print <<END
2796 <tr>
2797 <td class='base' nowrap='nowrap'>$Lang::tr{'vpn delayed start'}:&nbsp;<img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' /></td>
2798 <td ><input type='text' name='VPN_DELAYED_START' value='$cgiparams{'VPN_DELAYED_START'}' /></td>
2799 </tr>
2800 <tr>
2801 <td class='base' nowrap='nowrap'>$Lang::tr{'host to net vpn'}:</td>
2802 <td ><input type='text' name='RW_NET' value='$cgiparams{'RW_NET'}' /></td>
2803 </tr>
2804 </table>
2805 <br>
2806 <hr />
2807 <table width='100%'>
2808 <tr>
2809 <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
2810 <td width='70%' class='base' valign='top'>$Lang::tr{'required field'}</td><td width='30%' align='right' class='base'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
2811 </tr>
2812 <tr>
2813 <td class='base' valign='top' nowrap='nowrap'><img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' />&nbsp;</td>
2814 <td class='base'> <font class='base'>$Lang::tr{'vpn delayed start help'}</font></td>
2815 <td></td>
2816 </tr>
2817 </table>
2818 END
2819 ;
2820 print "</form>";
2821 &Header::closebox();
2822
2823 &Header::openbox('100%', 'left', $Lang::tr{'connection status and controlc'});
2824 print <<END
2825 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
2826 <tr>
2827 <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th>
2828 <th width='22%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></th>
2829 <th width='23%' class='boldbase' align='center'><b>$Lang::tr{'common name'}</b></th>
2830 <th width='30%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></th>
2831 <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></th>
2832 <th class='boldbase' align='center' colspan='6'><b>$Lang::tr{'action'}</b></th>
2833 </tr>
2834 END
2835 ;
2836 my $id = 0;
2837 my $gif;
2838 foreach my $key (sort { ncmp ($confighash{$a}[1],$confighash{$b}[1]) } keys %confighash) {
2839 if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; }
2840
2841 if ($id % 2) {
2842 print "<tr>";
2843 $col="bgcolor='$color{'color20'}'";
2844 } else {
2845 print "<tr>";
2846 $col="bgcolor='$color{'color22'}'";
2847 }
2848 print "<td align='center' nowrap='nowrap' $col>$confighash{$key}[1]</td>";
2849 print "<td align='center' nowrap='nowrap' $col>" . $Lang::tr{"$confighash{$key}[3]"} . " (" . $Lang::tr{"$confighash{$key}[4]"} . ") $confighash{$key}[29]</td>";
2850 if ($confighash{$key}[2] eq '%auth-dn') {
2851 print "<td align='left' nowrap='nowrap' $col>$confighash{$key}[9]</td>";
2852 } elsif ($confighash{$key}[4] eq 'cert') {
2853 print "<td align='left' nowrap='nowrap' $col>$confighash{$key}[2]</td>";
2854 } else {
2855 print "<td align='left' $col>&nbsp;</td>";
2856 }
2857 print "<td align='center' $col>$confighash{$key}[25]</td>";
2858 my $col1="bgcolor='${Header::colourred}'";
2859 my $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b>";
2860 if ($confighash{$key}[33] eq "add") {
2861 $col1="bgcolor='${Header::colourorange}'";
2862 $active = "<b><font color='#FFFFFF'>$Lang::tr{'vpn wait'}</font></b>";
2863 }
2864 foreach my $line (@status) {
2865 if (($line =~ /\"$confighash{$key}[1]\".*IPsec SA established/) ||
2866 ($line =~ /$confighash{$key}[1]\{.*INSTALLED/)) {
2867 $col1="bgcolor='${Header::colourgreen}'";
2868 $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsopen'}</font></b>";
2869 } elsif ($line =~ /$confighash{$key}[1]\[.*CONNECTING/) {
2870 $col1="bgcolor='${Header::colourorange}'";
2871 $active = "<b><font color='#FFFFFF'>$Lang::tr{'vpn connecting'}</font></b>";
2872 } elsif ($line =~ /$confighash{$key}[1]\{.*ROUTED/) {
2873 $col1="bgcolor='${Header::colourorange}'";
2874 $active = "<b><font color='#FFFFFF'>$Lang::tr{'vpn on-demand'}</font></b>";
2875 }
2876 }
2877 # move to blue if really down
2878 if ($confighash{$key}[0] eq 'off' && $col1 =~ /${Header::colourred}/ ) {
2879 $col1="bgcolor='${Header::colourblue}'";
2880 $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b>";
2881 }
2882 print <<END
2883 <td align='center' $col1>$active</td>
2884 <td align='center' $col>
2885 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2886 <input type='image' name='$Lang::tr{'restart'}' src='/images/reload.gif' alt='$Lang::tr{'restart'}' title='$Lang::tr{'restart'}' />
2887 <input type='hidden' name='ACTION' value='$Lang::tr{'restart'}' />
2888 <input type='hidden' name='KEY' value='$key' />
2889 </form>
2890 </td>
2891 END
2892 ;
2893 if (($confighash{$key}[4] eq 'cert') && ($confighash{$key}[2] ne '%auth-dn')) {
2894 print <<END
2895 <td align='center' $col>
2896 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2897 <input type='image' name='$Lang::tr{'show certificate'}' src='/images/info.gif' alt='$Lang::tr{'show certificate'}' title='$Lang::tr{'show certificate'}' />
2898 <input type='hidden' name='ACTION' value='$Lang::tr{'show certificate'}' />
2899 <input type='hidden' name='KEY' value='$key' />
2900 </form>
2901 </td>
2902 END
2903 ;
2904 } else {
2905 print "<td width='2%' $col>&nbsp;</td>";
2906 }
2907 if ($confighash{$key}[4] eq 'cert' && -f "${General::swroot}/certs/$confighash{$key}[1].p12") {
2908 print <<END
2909 <td align='center' $col>
2910 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2911 <input type='image' name='$Lang::tr{'download pkcs12 file'}' src='/images/floppy.gif' alt='$Lang::tr{'download pkcs12 file'}' title='$Lang::tr{'download pkcs12 file'}' />
2912 <input type='hidden' name='ACTION' value='$Lang::tr{'download pkcs12 file'}' />
2913 <input type='hidden' name='KEY' value='$key' />
2914 </form>
2915 </td>
2916 END
2917 ;
2918 } elsif (($confighash{$key}[4] eq 'cert') && ($confighash{$key}[2] ne '%auth-dn')) {
2919 print <<END
2920 <td align='center' $col>
2921 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2922 <input type='image' name='$Lang::tr{'download certificate'}' src='/images/floppy.gif' alt='$Lang::tr{'download certificate'}' title='$Lang::tr{'download certificate'}' />
2923 <input type='hidden' name='ACTION' value='$Lang::tr{'download certificate'}' />
2924 <input type='hidden' name='KEY' value='$key' />
2925 </form>
2926 </td>
2927 END
2928 ;
2929 } else {
2930 print "<td width='2%' $col>&nbsp;</td>";
2931 }
2932 print <<END
2933 <td align='center' $col>
2934 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2935 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$Lang::tr{'toggle enable disable'}' title='$Lang::tr{'toggle enable disable'}' />
2936 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
2937 <input type='hidden' name='KEY' value='$key' />
2938 </form>
2939 </td>
2940
2941 <td align='center' $col>
2942 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2943 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
2944 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
2945 <input type='hidden' name='KEY' value='$key' />
2946 </form>
2947 </td>
2948 <td align='center' $col>
2949 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2950 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
2951 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
2952 <input type='hidden' name='KEY' value='$key' />
2953 </form>
2954 </td>
2955 </tr>
2956 END
2957 ;
2958 $id++;
2959 }
2960 print "</table>";
2961
2962 # If the config file contains entries, print Key to action icons
2963 if ( $id ) {
2964 print <<END
2965 <table>
2966 <tr>
2967 <td class='boldbase'>&nbsp; <b>$Lang::tr{'legend'}:</b></td>
2968 <td>&nbsp; <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
2969 <td class='base'>$Lang::tr{'click to disable'}</td>
2970 <td>&nbsp; &nbsp; <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td>
2971 <td class='base'>$Lang::tr{'show certificate'}</td>
2972 <td>&nbsp; &nbsp; <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
2973 <td class='base'>$Lang::tr{'edit'}</td>
2974 <td>&nbsp; &nbsp; <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
2975 <td class='base'>$Lang::tr{'remove'}</td>
2976 </tr>
2977 <tr>
2978 <td>&nbsp; </td>
2979 <td>&nbsp; <img src='/images/off.gif' alt='?OFF' /></td>
2980 <td class='base'>$Lang::tr{'click to enable'}</td>
2981 <td>&nbsp; &nbsp; <img src='/images/floppy.gif' alt='?FLOPPY' /></td>
2982 <td class='base'>$Lang::tr{'download certificate'}</td>
2983 <td>&nbsp; &nbsp; <img src='/images/reload.gif' alt='?RELOAD'/></td>
2984 <td class='base'>$Lang::tr{'restart'}</td>
2985 </tr>
2986 </table>
2987 END
2988 ;
2989 }
2990
2991 print <<END
2992 <table width='100%'>
2993 <tr><td align='right' colspan='9'>
2994 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2995 <input type='submit' name='ACTION' value='$Lang::tr{'add'}' />
2996 </form>
2997 </td></tr>
2998 </table>
2999 END
3000 ;
3001 &Header::closebox();
3002
3003 &Header::openbox('100%', 'left', "$Lang::tr{'certificate authorities'}");
3004 print <<EOF
3005 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
3006 <tr>
3007 <th width='25%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th>
3008 <th width='65%' class='boldbase' align='center'><b>$Lang::tr{'subject'}</b></th>
3009 <th width='10%' class='boldbase' colspan='3' align='center'><b>$Lang::tr{'action'}</b></th>
3010 </tr>
3011 EOF
3012 ;
3013 my $col1="bgcolor='$color{'color22'}'";
3014 my $col2="bgcolor='$color{'color20'}'";
3015 if (-f "${General::swroot}/ca/cacert.pem") {
3016 my $casubject = &Header::cleanhtml(getsubjectfromcert ("${General::swroot}/ca/cacert.pem"));
3017 print <<END
3018 <tr>
3019 <td class='base' $col1>$Lang::tr{'root certificate'}</td>
3020 <td class='base' $col1>$casubject</td>
3021 <td width='3%' align='center' $col1>
3022 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
3023 <input type='hidden' name='ACTION' value='$Lang::tr{'show root certificate'}' />
3024 <input type='image' name='$Lang::tr{'edit'}' src='/images/info.gif' alt='$Lang::tr{'show root certificate'}' title='$Lang::tr{'show root certificate'}' />
3025 </form>
3026 </td>
3027 <td width='3%' align='center' $col1>
3028 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
3029 <input type='image' name='$Lang::tr{'download root certificate'}' src='/images/floppy.gif' alt='$Lang::tr{'download root certificate'}' title='$Lang::tr{'download root certificate'}' />
3030 <input type='hidden' name='ACTION' value='$Lang::tr{'download root certificate'}' />
3031 </form>
3032 </td>
3033 <td width='4%' $col1>&nbsp;</td></tr>
3034 END
3035 ;
3036 } else {
3037 # display rootcert generation buttons
3038 print <<END
3039 <tr>
3040 <td class='base' $col1>$Lang::tr{'root certificate'}:</td>
3041 <td class='base' $col1>$Lang::tr{'not present'}</td>
3042 <td colspan='3' $col1>&nbsp;</td></tr>
3043 END
3044 ;
3045 }
3046
3047 if (-f "${General::swroot}/certs/hostcert.pem") {
3048 my $hostsubject = &Header::cleanhtml(getsubjectfromcert ("${General::swroot}/certs/hostcert.pem"));
3049
3050 print <<END
3051 <tr>
3052 <td class='base' $col2>$Lang::tr{'host certificate'}</td>
3053 <td class='base' $col2>$hostsubject</td>
3054 <td width='3%' align='center' $col2>
3055 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
3056 <input type='hidden' name='ACTION' value='$Lang::tr{'show host certificate'}' />
3057 <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'}' />
3058 </form>
3059 </td>
3060 <td width='3%' align='center' $col2>
3061 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
3062 <input type='image' name="$Lang::tr{'download host certificate'}" src='/images/floppy.gif' alt="$Lang::tr{'download host certificate'}" title="$Lang::tr{'download host certificate'}" />
3063 <input type='hidden' name='ACTION' value="$Lang::tr{'download host certificate'}" />
3064 </form>
3065 </td>
3066 <td width='4%' $col2>&nbsp;</td></tr>
3067 END
3068 ;
3069 } else {
3070 # Nothing
3071 print <<END
3072 <tr>
3073 <td width='25%' class='base' $col2>$Lang::tr{'host certificate'}:</td>
3074 <td class='base' $col2>$Lang::tr{'not present'}</td>
3075 <td colspan='3' $col2>&nbsp;</td></tr>
3076 END
3077 ;
3078 }
3079
3080 my $rowcolor = 0;
3081 if (keys %cahash > 0) {
3082 foreach my $key (keys %cahash) {
3083 if ($rowcolor++ % 2) {
3084 print "<tr>";
3085 $col="bgcolor='$color{'color20'}'";
3086 } else {
3087 print "<tr>";
3088 $col="bgcolor='$color{'color22'}'";
3089 }
3090 print "<td class='base' $col>$cahash{$key}[0]</td>\n";
3091 print "<td class='base' $col>$cahash{$key}[1]</td>\n";
3092 print <<END
3093 <td align='center' $col>
3094 <form method='post' name='cafrm${key}a' action='$ENV{'SCRIPT_NAME'}'>
3095 <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'}' />
3096 <input type='hidden' name='ACTION' value='$Lang::tr{'show ca certificate'}' />
3097 <input type='hidden' name='KEY' value='$key' />
3098 </form>
3099 </td>
3100 <td align='center' $col>
3101 <form method='post' name='cafrm${key}b' action='$ENV{'SCRIPT_NAME'}'>
3102 <input type='image' name='$Lang::tr{'download ca certificate'}' src='/images/floppy.gif' alt='$Lang::tr{'download ca certificate'}' title='$Lang::tr{'download ca certificate'}' />
3103 <input type='hidden' name='ACTION' value='$Lang::tr{'download ca certificate'}' />
3104 <input type='hidden' name='KEY' value='$key' />
3105 </form>
3106 </td>
3107 <td align='center' $col>
3108 <form method='post' name='cafrm${key}c' action='$ENV{'SCRIPT_NAME'}'>
3109 <input type='hidden' name='ACTION' value='$Lang::tr{'remove ca certificate'}' />
3110 <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'}' />
3111 <input type='hidden' name='KEY' value='$key' />
3112 </form>
3113 </td>
3114 </tr>
3115 END
3116 ;
3117 }
3118 }
3119 print "</table>";
3120
3121 # If the file contains entries, print Key to action icons
3122 if ( -f "${General::swroot}/ca/cacert.pem") {
3123 print <<END
3124 <table><tr>
3125 <td class='boldbase'>&nbsp; <b>$Lang::tr{'legend'}:</b></td>
3126 <td>&nbsp; &nbsp; <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td>
3127 <td class='base'>$Lang::tr{'show certificate'}</td>
3128 <td>&nbsp; &nbsp; <img src='/images/floppy.gif' alt='$Lang::tr{'download certificate'}' /></td>
3129 <td class='base'>$Lang::tr{'download certificate'}</td>
3130 </tr></table>
3131 END
3132 ;
3133 }
3134 my $createCA = -f "${General::swroot}/ca/cacert.pem" ? '' : "<tr><td colspan='3'></td><td><input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' /></td></tr>";
3135 print <<END
3136 <br>
3137 <hr />
3138 <form method='post' enctype='multipart/form-data' action='$ENV{'SCRIPT_NAME'}'>
3139 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
3140 $createCA
3141 <tr>
3142 <td class='base' nowrap='nowrap'>$Lang::tr{'ca name'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
3143 <td nowrap='nowrap'><input type='text' name='CA_NAME' value='$cgiparams{'CA_NAME'}' size='15' /> </td>
3144 <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td>
3145 <td nowrap='nowrap'><input type='submit' name='ACTION' value='$Lang::tr{'upload ca certificate'}' /></td>
3146 </tr>
3147 <tr>
3148 <td colspan='3'>$Lang::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}:</td>
3149 <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' /></td>
3150 </tr>
3151 </table>
3152 </form>
3153 END
3154 ;
3155 &Header::closebox();
3156 &Header::closebigbox();
3157 &Header::closepage();
3158
3159 sub array_unique($) {
3160 my $array = shift;
3161 my @unique = ();
3162
3163 my %seen = ();
3164 foreach my $e (@$array) {
3165 next if $seen{$e}++;
3166 push(@unique, $e);
3167 }
3168
3169 return @unique;
3170 }
3171
3172 sub make_algos($$$$$) {
3173 my ($mode, $encs, $ints, $grps, $pfs) = @_;
3174 my @algos = ();
3175
3176 foreach my $enc (@$encs) {
3177 foreach my $int (@$ints) {
3178 foreach my $grp (@$grps) {
3179 my @algo = ($enc);
3180
3181 if ($mode eq "ike") {
3182 push(@algo, $int);
3183
3184 if ($grp =~ m/^e(.*)$/) {
3185 push(@algo, "ecp$1");
3186 } elsif ($grp =~ m/curve25519/) {
3187 push(@algo, "$grp");
3188 } else {
3189 push(@algo, "modp$grp");
3190 }
3191
3192 } elsif ($mode eq "esp" && $pfs) {
3193 my $is_aead = ($enc =~ m/[cg]cm/);
3194
3195 if (!$is_aead) {
3196 push(@algo, $int);
3197 }
3198
3199 if ($grp eq "none") {
3200 # noop
3201 } elsif ($grp =~ m/^e(.*)$/) {
3202 push(@algo, "ecp$1");
3203 } elsif ($grp =~ m/curve25519/) {
3204 push(@algo, "$grp");
3205 } else {
3206 push(@algo, "modp$grp");
3207 }
3208 }
3209
3210 push(@algos, join("-", @algo));
3211 }
3212 }
3213 }
3214
3215 return &array_unique(\@algos);
3216 }
3217
3218 sub make_subnets($) {
3219 my $subnets = shift;
3220
3221 my @nets = split(/\|/, $subnets);
3222 my @cidr_nets = ();
3223 foreach my $net (@nets) {
3224 my $cidr_net = &General::ipcidr($net);
3225 push(@cidr_nets, $cidr_net);
3226 }
3227
3228 return join(",", @cidr_nets);
3229 }