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