]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/vpnmain.cgi
Merge remote-tracking branch 'origin/next' into thirteen
[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-2011 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 if ($cgiparams{'AUTH'} eq 'psk') {
1368 if (! length($cgiparams{'PSK'}) ) {
1369 $errormessage = $Lang::tr{'pre-shared key is too short'};
1370 goto VPNCONF_ERROR;
1371 }
1372 if ($cgiparams{'PSK'} =~ /'/) {
1373 $cgiparams{'PSK'} =~ tr/'/ /;
1374 $errormessage = $Lang::tr{'invalid characters found in pre-shared key'};
1375 goto VPNCONF_ERROR;
1376 }
1377 } elsif ($cgiparams{'AUTH'} eq 'certreq') {
1378 if ($cgiparams{'KEY'}) {
1379 $errormessage = $Lang::tr{'cant change certificates'};
1380 goto VPNCONF_ERROR;
1381 }
1382 if (ref ($cgiparams{'FH'}) ne 'Fh') {
1383 $errormessage = $Lang::tr{'there was no file upload'};
1384 goto VPNCONF_ERROR;
1385 }
1386
1387 # Move uploaded certificate request to a temporary file
1388 (my $fh, my $filename) = tempfile( );
1389 if (copy ($cgiparams{'FH'}, $fh) != 1) {
1390 $errormessage = $!;
1391 goto VPNCONF_ERROR;
1392 }
1393
1394 # Sign the certificate request
1395 &General::log("ipsec", "Signing your cert $cgiparams{'NAME'}...");
1396 my $opt = " ca -days 999999";
1397 $opt .= " -batch -notext";
1398 $opt .= " -in $filename";
1399 $opt .= " -out ${General::swroot}/certs/$cgiparams{'NAME'}cert.pem";
1400
1401 if ( $errormessage = &callssl ($opt) ) {
1402 unlink ($filename);
1403 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1404 &cleanssldatabase();
1405 goto VPNCONF_ERROR;
1406 } else {
1407 unlink ($filename);
1408 &cleanssldatabase();
1409 }
1410
1411 $cgiparams{'CERT_NAME'} = getCNfromcert ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1412 if ($cgiparams{'CERT_NAME'} eq '') {
1413 $errormessage = $Lang::tr{'could not retrieve common name from certificate'};
1414 goto VPNCONF_ERROR;
1415 }
1416 } elsif ($cgiparams{'AUTH'} eq 'pkcs12') {
1417 &General::log("ipsec", "Importing from p12...");
1418
1419 if (ref ($cgiparams{'FH'}) ne 'Fh') {
1420 $errormessage = $Lang::tr{'there was no file upload'};
1421 goto ROOTCERT_ERROR;
1422 }
1423
1424 # Move uploaded certificate request to a temporary file
1425 (my $fh, my $filename) = tempfile( );
1426 if (copy ($cgiparams{'FH'}, $fh) != 1) {
1427 $errormessage = $!;
1428 goto ROOTCERT_ERROR;
1429 }
1430
1431 # Extract the CA certificate from the file
1432 &General::log("ipsec", "Extracting caroot from p12...");
1433 if (open(STDIN, "-|")) {
1434 my $opt = " pkcs12 -cacerts -nokeys";
1435 $opt .= " -in $filename";
1436 $opt .= " -out /tmp/newcacert";
1437 $errormessage = &callssl ($opt);
1438 } else { #child
1439 print "$cgiparams{'P12_PASS'}\n";
1440 exit (0);
1441 }
1442
1443 # Extract the Host certificate from the file
1444 if (!$errormessage) {
1445 &General::log("ipsec", "Extracting host cert from p12...");
1446 if (open(STDIN, "-|")) {
1447 my $opt = " pkcs12 -clcerts -nokeys";
1448 $opt .= " -in $filename";
1449 $opt .= " -out /tmp/newhostcert";
1450 $errormessage = &callssl ($opt);
1451 } else { #child
1452 print "$cgiparams{'P12_PASS'}\n";
1453 exit (0);
1454 }
1455 }
1456
1457 if (!$errormessage) {
1458 &General::log("ipsec", "Moving cacert...");
1459 #If CA have new subject, add it to our list of CA
1460 my $casubject = &Header::cleanhtml(getsubjectfromcert ('/tmp/newcacert'));
1461 my @names;
1462 foreach my $x (keys %cahash) {
1463 $casubject='' if ($cahash{$x}[1] eq $casubject);
1464 unshift (@names,$cahash{$x}[0]);
1465 }
1466 if ($casubject) { # a new one!
1467 my $temp = `/usr/bin/openssl x509 -text -in /tmp/newcacert`;
1468 if ($temp !~ /CA:TRUE/i) {
1469 $errormessage = $Lang::tr{'not a valid ca certificate'};
1470 } else {
1471 #compute a name for it
1472 my $idx=0;
1473 while (grep(/Imported-$idx/, @names) ) {$idx++};
1474 $cgiparams{'CA_NAME'}="Imported-$idx";
1475 $cgiparams{'CERT_NAME'}=&Header::cleanhtml(getCNfromcert ('/tmp/newhostcert'));
1476 move("/tmp/newcacert", "${General::swroot}/ca/$cgiparams{'CA_NAME'}cert.pem");
1477 $errormessage = "$Lang::tr{'certificate file move failed'}: $!" if ($? ne 0);
1478 if (!$errormessage) {
1479 my $key = &General::findhasharraykey (\%cahash);
1480 $cahash{$key}[0] = $cgiparams{'CA_NAME'};
1481 $cahash{$key}[1] = $casubject;
1482 &General::writehasharray("${General::swroot}/vpn/caconfig", \%cahash);
1483 system('/usr/local/bin/ipsecctrl', 'R');
1484 }
1485 }
1486 }
1487 }
1488 if (!$errormessage) {
1489 &General::log("ipsec", "Moving host cert...");
1490 move("/tmp/newhostcert", "${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1491 $errormessage = "$Lang::tr{'certificate file move failed'}: $!" if ($? ne 0);
1492 }
1493
1494 #cleanup temp files
1495 unlink ($filename);
1496 unlink ('/tmp/newcacert');
1497 unlink ('/tmp/newhostcert');
1498 if ($errormessage) {
1499 unlink ("${General::swroot}/ca/$cgiparams{'CA_NAME'}cert.pem");
1500 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1501 goto VPNCONF_ERROR;
1502 }
1503 &General::log("ipsec", "p12 import completed!");
1504 } elsif ($cgiparams{'AUTH'} eq 'certfile') {
1505 if ($cgiparams{'KEY'}) {
1506 $errormessage = $Lang::tr{'cant change certificates'};
1507 goto VPNCONF_ERROR;
1508 }
1509 if (ref ($cgiparams{'FH'}) ne 'Fh') {
1510 $errormessage = $Lang::tr{'there was no file upload'};
1511 goto VPNCONF_ERROR;
1512 }
1513 # Move uploaded certificate to a temporary file
1514 (my $fh, my $filename) = tempfile( );
1515 if (copy ($cgiparams{'FH'}, $fh) != 1) {
1516 $errormessage = $!;
1517 goto VPNCONF_ERROR;
1518 }
1519
1520 # Verify the certificate has a valid CA and move it
1521 &General::log("ipsec", "Validating imported cert against our known CA...");
1522 my $validca = 1; #assume ok
1523 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/cacert.pem $filename`;
1524 if ($test !~ /: OK/) {
1525 my $validca = 0;
1526 foreach my $key (keys %cahash) {
1527 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/$cahash{$key}[0]cert.pem $filename`;
1528 if ($test =~ /: OK/) {
1529 $validca = 1;
1530 last;
1531 }
1532 }
1533 }
1534 if (! $validca) {
1535 $errormessage = $Lang::tr{'certificate does not have a valid ca associated with it'};
1536 unlink ($filename);
1537 goto VPNCONF_ERROR;
1538 } else {
1539 move($filename, "${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1540 if ($? ne 0) {
1541 $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
1542 unlink ($filename);
1543 goto VPNCONF_ERROR;
1544 }
1545 }
1546
1547 $cgiparams{'CERT_NAME'} = getCNfromcert ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1548 if ($cgiparams{'CERT_NAME'} eq '') {
1549 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1550 $errormessage = $Lang::tr{'could not retrieve common name from certificate'};
1551 goto VPNCONF_ERROR;
1552 }
1553 } elsif ($cgiparams{'AUTH'} eq 'certgen') {
1554 if ($cgiparams{'KEY'}) {
1555 $errormessage = $Lang::tr{'cant change certificates'};
1556 goto VPNCONF_ERROR;
1557 }
1558 # Validate input since the form was submitted
1559 if (length($cgiparams{'CERT_NAME'}) >60) {
1560 $errormessage = $Lang::tr{'name too long'};
1561 goto VPNCONF_ERROR;
1562 }
1563 if ($cgiparams{'CERT_NAME'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) {
1564 $errormessage = $Lang::tr{'invalid input for name'};
1565 goto VPNCONF_ERROR;
1566 }
1567 if ($cgiparams{'CERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'CERT_EMAIL'}))) {
1568 $errormessage = $Lang::tr{'invalid input for e-mail address'};
1569 goto VPNCONF_ERROR;
1570 }
1571 if (length($cgiparams{'CERT_EMAIL'}) > 40) {
1572 $errormessage = $Lang::tr{'e-mail address too long'};
1573 goto VPNCONF_ERROR;
1574 }
1575 if ($cgiparams{'CERT_OU'} ne '' && $cgiparams{'CERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1576 $errormessage = $Lang::tr{'invalid input for department'};
1577 goto VPNCONF_ERROR;
1578 }
1579 if (length($cgiparams{'CERT_ORGANIZATION'}) >60) {
1580 $errormessage = $Lang::tr{'organization too long'};
1581 goto VPNCONF_ERROR;
1582 }
1583 if ($cgiparams{'CERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) {
1584 $errormessage = $Lang::tr{'invalid input for organization'};
1585 goto VPNCONF_ERROR;
1586 }
1587 if ($cgiparams{'CERT_CITY'} ne '' && $cgiparams{'CERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1588 $errormessage = $Lang::tr{'invalid input for city'};
1589 goto VPNCONF_ERROR;
1590 }
1591 if ($cgiparams{'CERT_STATE'} ne '' && $cgiparams{'CERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1592 $errormessage = $Lang::tr{'invalid input for state or province'};
1593 goto VPNCONF_ERROR;
1594 }
1595 if ($cgiparams{'CERT_COUNTRY'} !~ /^[A-Z]*$/) {
1596 $errormessage = $Lang::tr{'invalid input for country'};
1597 goto VPNCONF_ERROR;
1598 }
1599 #the exact syntax is a list comma separated of
1600 # email:any-validemail
1601 # URI: a uniform resource indicator
1602 # DNS: a DNS domain name
1603 # RID: a registered OBJECT IDENTIFIER
1604 # IP: an IP address
1605 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
1606
1607 if ($cgiparams{'SUBJECTALTNAME'} ne '' && $cgiparams{'SUBJECTALTNAME'} !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/,\.\-_@]*$/) {
1608 $errormessage = $Lang::tr{'vpn altname syntax'};
1609 goto VPNCONF_ERROR;
1610 }
1611
1612 if (length($cgiparams{'CERT_PASS1'}) < 5) {
1613 $errormessage = $Lang::tr{'password too short'};
1614 goto VPNCONF_ERROR;
1615 }
1616 if ($cgiparams{'CERT_PASS1'} ne $cgiparams{'CERT_PASS2'}) {
1617 $errormessage = $Lang::tr{'passwords do not match'};
1618 goto VPNCONF_ERROR;
1619 }
1620
1621 # Replace empty strings with a .
1622 (my $ou = $cgiparams{'CERT_OU'}) =~ s/^\s*$/\./;
1623 (my $city = $cgiparams{'CERT_CITY'}) =~ s/^\s*$/\./;
1624 (my $state = $cgiparams{'CERT_STATE'}) =~ s/^\s*$/\./;
1625
1626 # Create the Host certificate request
1627 &General::log("ipsec", "Creating a cert...");
1628
1629 if (open(STDIN, "-|")) {
1630 my $opt = " req -nodes -rand /proc/interrupts:/proc/net/rt_cache";
1631 $opt .= " -newkey rsa:1024";
1632 $opt .= " -keyout ${General::swroot}/certs/$cgiparams{'NAME'}key.pem";
1633 $opt .= " -out ${General::swroot}/certs/$cgiparams{'NAME'}req.pem";
1634
1635 if ( $errormessage = &callssl ($opt) ) {
1636 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}key.pem");
1637 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}req.pem");
1638 goto VPNCONF_ERROR;
1639 }
1640 } else { #child
1641 print "$cgiparams{'CERT_COUNTRY'}\n";
1642 print "$state\n";
1643 print "$city\n";
1644 print "$cgiparams{'CERT_ORGANIZATION'}\n";
1645 print "$ou\n";
1646 print "$cgiparams{'CERT_NAME'}\n";
1647 print "$cgiparams{'CERT_EMAIL'}\n";
1648 print ".\n";
1649 print ".\n";
1650 exit (0);
1651 }
1652
1653 # Sign the host certificate request
1654 &General::log("ipsec", "Signing the cert $cgiparams{'NAME'}...");
1655
1656 #No easy way for specifying the contain of subjectAltName without writing a config file...
1657 my ($fh, $v3extname) = tempfile ('/tmp/XXXXXXXX');
1658 print $fh <<END
1659 basicConstraints=CA:FALSE
1660 nsComment="OpenSSL Generated Certificate"
1661 subjectKeyIdentifier=hash
1662 authorityKeyIdentifier=keyid,issuer:always
1663 END
1664 ;
1665 print $fh "subjectAltName=$cgiparams{'SUBJECTALTNAME'}" if ($cgiparams{'SUBJECTALTNAME'});
1666 close ($fh);
1667
1668 my $opt = " ca -days 999999 -batch -notext";
1669 $opt .= " -in ${General::swroot}/certs/$cgiparams{'NAME'}req.pem";
1670 $opt .= " -out ${General::swroot}/certs/$cgiparams{'NAME'}cert.pem";
1671 $opt .= " -extfile $v3extname";
1672
1673 if ( $errormessage = &callssl ($opt) ) {
1674 unlink ($v3extname);
1675 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}key.pem");
1676 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}req.pem");
1677 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1678 &cleanssldatabase();
1679 goto VPNCONF_ERROR;
1680 } else {
1681 unlink ($v3extname);
1682 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}req.pem");
1683 &cleanssldatabase();
1684 }
1685
1686 # Create the pkcs12 file
1687 &General::log("ipsec", "Packing a pkcs12 file...");
1688 $opt = " pkcs12 -export";
1689 $opt .= " -inkey ${General::swroot}/certs/$cgiparams{'NAME'}key.pem";
1690 $opt .= " -in ${General::swroot}/certs/$cgiparams{'NAME'}cert.pem";
1691 $opt .= " -name \"$cgiparams{'NAME'}\"";
1692 $opt .= " -passout pass:$cgiparams{'CERT_PASS1'}";
1693 $opt .= " -certfile ${General::swroot}/ca/cacert.pem";
1694 $opt .= " -caname \"$vpnsettings{'ROOTCERT_ORGANIZATION'} CA\"";
1695 $opt .= " -out ${General::swroot}/certs/$cgiparams{'NAME'}.p12";
1696
1697 if ( $errormessage = &callssl ($opt) ) {
1698 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}key.pem");
1699 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem");
1700 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}.p12");
1701 goto VPNCONF_ERROR;
1702 } else {
1703 unlink ("${General::swroot}/certs/$cgiparams{'NAME'}key.pem");
1704 }
1705 } elsif ($cgiparams{'AUTH'} eq 'cert') {
1706 ;# Nothing, just editing
1707 } elsif ($cgiparams{'AUTH'} eq 'auth-dn') {
1708 $cgiparams{'CERT_NAME'} = '%auth-dn'; # a special value saying 'no cert file'
1709 } else {
1710 $errormessage = $Lang::tr{'invalid input for authentication method'};
1711 goto VPNCONF_ERROR;
1712 }
1713
1714 # 1)Error message here is not accurate.
1715 # 2)Test is superfluous, openswan can reference same cert multiple times
1716 # 3)Present since initial version (1.3.2.11), it isn't a bug correction
1717 # Check if there is no other entry with this certificate name
1718 #if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk') && ($cgiparams{'AUTH'} ne 'auth-dn')) {
1719 # foreach my $key (keys %confighash) {
1720 # if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) {
1721 # $errormessage = $Lang::tr{'a connection with this common name already exists'};
1722 # goto VPNCONF_ERROR;
1723 # }
1724 # }
1725 #}
1726 # Save the config
1727
1728 my $key = $cgiparams{'KEY'};
1729 if (! $key) {
1730 $key = &General::findhasharraykey (\%confighash);
1731 foreach my $i (0 .. 28) { $confighash{$key}[$i] = "";}
1732 }
1733 $confighash{$key}[0] = $cgiparams{'ENABLED'};
1734 $confighash{$key}[1] = $cgiparams{'NAME'};
1735 if ((! $cgiparams{'KEY'}) && $cgiparams{'AUTH'} ne 'psk') {
1736 $confighash{$key}[2] = $cgiparams{'CERT_NAME'};
1737 }
1738 $confighash{$key}[3] = $cgiparams{'TYPE'};
1739 if ($cgiparams{'AUTH'} eq 'psk') {
1740 $confighash{$key}[4] = 'psk';
1741 $confighash{$key}[5] = $cgiparams{'PSK'};
1742 } else {
1743 $confighash{$key}[4] = 'cert';
1744 }
1745 if ($cgiparams{'TYPE'} eq 'net') {
1746 $confighash{$key}[11] = $cgiparams{'REMOTE_SUBNET'};
1747 }
1748 $confighash{$key}[7] = $cgiparams{'LOCAL_ID'};
1749 $confighash{$key}[8] = $cgiparams{'LOCAL_SUBNET'};
1750 $confighash{$key}[9] = $cgiparams{'REMOTE_ID'};
1751 $confighash{$key}[10] = $cgiparams{'REMOTE'};
1752 $confighash{$key}[25] = $cgiparams{'REMARK'};
1753 $confighash{$key}[26] = ""; # Formerly INTERFACE
1754 $confighash{$key}[27] = $cgiparams{'DPD_ACTION'};
1755 $confighash{$key}[29] = $cgiparams{'IKE_VERSION'};
1756
1757 #dont forget advanced value
1758 $confighash{$key}[18] = $cgiparams{'IKE_ENCRYPTION'};
1759 $confighash{$key}[19] = $cgiparams{'IKE_INTEGRITY'};
1760 $confighash{$key}[20] = $cgiparams{'IKE_GROUPTYPE'};
1761 $confighash{$key}[16] = $cgiparams{'IKE_LIFETIME'};
1762 $confighash{$key}[21] = $cgiparams{'ESP_ENCRYPTION'};
1763 $confighash{$key}[22] = $cgiparams{'ESP_INTEGRITY'};
1764 $confighash{$key}[23] = $cgiparams{'ESP_GROUPTYPE'};
1765 $confighash{$key}[17] = $cgiparams{'ESP_KEYLIFE'};
1766 $confighash{$key}[12] = 'off'; # $cgiparams{'AGGRMODE'};
1767 $confighash{$key}[13] = $cgiparams{'COMPRESSION'};
1768 $confighash{$key}[24] = $cgiparams{'ONLY_PROPOSED'};
1769 $confighash{$key}[28] = $cgiparams{'PFS'};
1770 $confighash{$key}[14] = $cgiparams{'VHOST'};
1771
1772 #free unused fields!
1773 $confighash{$key}[6] = 'off';
1774 $confighash{$key}[15] = 'off';
1775
1776 &General::writehasharray("${General::swroot}/vpn/config", \%confighash);
1777 &writeipsecfiles();
1778 if (&vpnenabled) {
1779 system('/usr/local/bin/ipsecctrl', 'S', $key);
1780 sleep $sleepDelay;
1781 }
1782 if ($cgiparams{'EDIT_ADVANCED'} eq 'on') {
1783 $cgiparams{'KEY'} = $key;
1784 $cgiparams{'ACTION'} = $Lang::tr{'advanced'};
1785 }
1786 goto VPNCONF_END;
1787 } else { # add new connection
1788 $cgiparams{'ENABLED'} = 'on';
1789 if ( ! -f "${General::swroot}/private/cakey.pem" ) {
1790 $cgiparams{'AUTH'} = 'psk';
1791 } elsif ( ! -f "${General::swroot}/ca/cacert.pem") {
1792 $cgiparams{'AUTH'} = 'certfile';
1793 } else {
1794 $cgiparams{'AUTH'} = 'certgen';
1795 }
1796 $cgiparams{'LOCAL_SUBNET'} ="$netsettings{'GREEN_NETADDRESS'}/$netsettings{'GREEN_NETMASK'}";
1797 $cgiparams{'CERT_EMAIL'} = $vpnsettings{'ROOTCERT_EMAIL'};
1798 $cgiparams{'CERT_OU'} = $vpnsettings{'ROOTCERT_OU'};
1799 $cgiparams{'CERT_ORGANIZATION'} = $vpnsettings{'ROOTCERT_ORGANIZATION'};
1800 $cgiparams{'CERT_CITY'} = $vpnsettings{'ROOTCERT_CITY'};
1801 $cgiparams{'CERT_STATE'} = $vpnsettings{'ROOTCERT_STATE'};
1802 $cgiparams{'CERT_COUNTRY'} = $vpnsettings{'ROOTCERT_COUNTRY'};
1803
1804 # choose appropriate dpd action
1805 if ($cgiparams{'TYPE'} eq 'host') {
1806 $cgiparams{'DPD_ACTION'} = 'clear';
1807 } else {
1808 $cgiparams{'DPD_ACTION'} = 'restart';
1809 }
1810
1811 # Default IKE Version to v2
1812 if (!$cgiparams{'IKE_VERSION'}) {
1813 $cgiparams{'IKE_VERSION'} = 'ikev2';
1814 }
1815
1816 # ID are empty
1817 $cgiparams{'LOCAL_ID'} = '';
1818 $cgiparams{'REMOTE_ID'} = '';
1819
1820 #use default advanced value
1821 $cgiparams{'IKE_ENCRYPTION'} = 'aes256|aes192|aes128|3des'; #[18];
1822 $cgiparams{'IKE_INTEGRITY'} = 'sha2_256|sha|md5'; #[19];
1823 $cgiparams{'IKE_GROUPTYPE'} = '8192|6144|4096|3072|2048|1536|1024'; #[20];
1824 $cgiparams{'IKE_LIFETIME'} = '1'; #[16];
1825 $cgiparams{'ESP_ENCRYPTION'} = 'aes256|aes192|aes128|3des'; #[21];
1826 $cgiparams{'ESP_INTEGRITY'} = 'sha2_256|sha1|md5'; #[22];
1827 $cgiparams{'ESP_GROUPTYPE'} = ''; #[23];
1828 $cgiparams{'ESP_KEYLIFE'} = '8'; #[17];
1829 $cgiparams{'COMPRESSION'} = 'on'; #[13];
1830 $cgiparams{'ONLY_PROPOSED'} = 'off'; #[24];
1831 $cgiparams{'PFS'} = 'on'; #[28];
1832 $cgiparams{'VHOST'} = 'on'; #[14];
1833 }
1834
1835 VPNCONF_ERROR:
1836 $checked{'ENABLED'}{'off'} = '';
1837 $checked{'ENABLED'}{'on'} = '';
1838 $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = "checked='checked'";
1839
1840 $checked{'EDIT_ADVANCED'}{'off'} = '';
1841 $checked{'EDIT_ADVANCED'}{'on'} = '';
1842 $checked{'EDIT_ADVANCED'}{$cgiparams{'EDIT_ADVANCED'}} = "checked='checked'";
1843
1844 $checked{'AUTH'}{'psk'} = '';
1845 $checked{'AUTH'}{'certreq'} = '';
1846 $checked{'AUTH'}{'certgen'} = '';
1847 $checked{'AUTH'}{'certfile'} = '';
1848 $checked{'AUTH'}{'pkcs12'} = '';
1849 $checked{'AUTH'}{'auth-dn'} = '';
1850 $checked{'AUTH'}{$cgiparams{'AUTH'}} = "checked='checked'";
1851
1852 $selected{'DPD_ACTION'}{'clear'} = '';
1853 $selected{'DPD_ACTION'}{'hold'} = '';
1854 $selected{'DPD_ACTION'}{'restart'} = '';
1855 $selected{'DPD_ACTION'}{$cgiparams{'DPD_ACTION'}} = "selected='selected'";
1856
1857 $selected{'IKE_VERSION'}{'ikev1'} = '';
1858 $selected{'IKE_VERSION'}{'ikev2'} = '';
1859 $selected{'IKE_VERSION'}{$cgiparams{'IKE_VERSION'}} = "selected='selected'";
1860
1861 &Header::showhttpheaders();
1862 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
1863 &Header::openbigbox('100%', 'left', '', $errormessage);
1864 if ($errormessage) {
1865 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
1866 print "<class name='base'>$errormessage";
1867 print "&nbsp;</class>";
1868 &Header::closebox();
1869 }
1870
1871 if ($warnmessage) {
1872 &Header::openbox('100%', 'left', "$Lang::tr{'warning messages'}:");
1873 print "<class name='base'>$warnmessage";
1874 print "&nbsp;</class>";
1875 &Header::closebox();
1876 }
1877
1878 print "<form method='post' enctype='multipart/form-data' action='$ENV{'SCRIPT_NAME'}'>";
1879 print<<END
1880 <input type='hidden' name='TYPE' value='$cgiparams{'TYPE'}' />
1881 <input type='hidden' name='IKE_ENCRYPTION' value='$cgiparams{'IKE_ENCRYPTION'}' />
1882 <input type='hidden' name='IKE_INTEGRITY' value='$cgiparams{'IKE_INTEGRITY'}' />
1883 <input type='hidden' name='IKE_GROUPTYPE' value='$cgiparams{'IKE_GROUPTYPE'}' />
1884 <input type='hidden' name='IKE_LIFETIME' value='$cgiparams{'IKE_LIFETIME'}' />
1885 <input type='hidden' name='ESP_ENCRYPTION' value='$cgiparams{'ESP_ENCRYPTION'}' />
1886 <input type='hidden' name='ESP_INTEGRITY' value='$cgiparams{'ESP_INTEGRITY'}' />
1887 <input type='hidden' name='ESP_GROUPTYPE' value='$cgiparams{'ESP_GROUPTYPE'}' />
1888 <input type='hidden' name='ESP_KEYLIFE' value='$cgiparams{'ESP_KEYLIFE'}' />
1889 <input type='hidden' name='COMPRESSION' value='$cgiparams{'COMPRESSION'}' />
1890 <input type='hidden' name='ONLY_PROPOSED' value='$cgiparams{'ONLY_PROPOSED'}' />
1891 <input type='hidden' name='PFS' value='$cgiparams{'PFS'}' />
1892 <input type='hidden' name='VHOST' value='$cgiparams{'VHOST'}' />
1893 END
1894 ;
1895 if ($cgiparams{'KEY'}) {
1896 print "<input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />";
1897 print "<input type='hidden' name='AUTH' value='$cgiparams{'AUTH'}' />";
1898 }
1899
1900 &Header::openbox('100%', 'left', "$Lang::tr{'connection'}:");
1901 print "<table width='100%'>";
1902 print "<tr><td width='25%' class='boldbase'>$Lang::tr{'name'}:</td>";
1903 if ($cgiparams{'KEY'}) {
1904 print "<td width='25%' class='base'><input type='hidden' name='NAME' value='$cgiparams{'NAME'}' /><b>$cgiparams{'NAME'}</b></td>";
1905 } else {
1906 print "<td width='25%'><input type='text' name='NAME' value='$cgiparams{'NAME'}' size='30' /></td>";
1907 }
1908 print "<td>$Lang::tr{'enabled'}</td><td><input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td></tr>";
1909 print '</tr><td><br /></td><tr>';
1910
1911 my $disabled;
1912 my $blob;
1913 if ($cgiparams{'TYPE'} eq 'host') {
1914 $disabled = "disabled='disabled'";
1915 $blob = "<img src='/blob.gif' alt='*' />";
1916 };
1917
1918 print <<END
1919 <tr>
1920 <td class='boldbase'>$Lang::tr{'remote host/ip'}:&nbsp;$blob</td>
1921 <td>
1922 <input type='text' name='REMOTE' value='$cgiparams{'REMOTE'}' size='30' />
1923 </td>
1924 <td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'}</td>
1925 <td>
1926 <input $disabled type='text' name='REMOTE_SUBNET' value='$cgiparams{'REMOTE_SUBNET'}' size='30' />
1927 </td>
1928 </tr>
1929 <tr>
1930 <td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'}</td>
1931 <td colspan='3'>
1932 <input type='text' name='LOCAL_SUBNET' value='$cgiparams{'LOCAL_SUBNET'}' size='30' />
1933 </td>
1934 </tr>
1935 <tr>
1936 <td class='boldbase'>$Lang::tr{'vpn local id'}:<br />($Lang::tr{'eg'} <tt>&#64;xy.example.com</tt>)</td>
1937 <td><input type='text' name='LOCAL_ID' value='$cgiparams{'LOCAL_ID'}' /></td>
1938 <td class='boldbase'>$Lang::tr{'vpn remote id'}:</td>
1939 <td><input type='text' name='REMOTE_ID' value='$cgiparams{'REMOTE_ID'}' /></td>
1940 </tr><tr>
1941 </tr><td><br /></td><tr>
1942 <td>$Lang::tr{'vpn keyexchange'}:</td>
1943 <td><select name='IKE_VERSION'>
1944 <option value='ikev2' $selected{'IKE_VERSION'}{'ikev2'}>IKEv2</option>
1945 <option value='ikev1' $selected{'IKE_VERSION'}{'ikev1'}>IKEv1</option>
1946 </select>
1947 </td>
1948 <td>$Lang::tr{'dpd action'}:</td>
1949 <td><select name='DPD_ACTION'>
1950 <option value='clear' $selected{'DPD_ACTION'}{'clear'}>clear</option>
1951 <option value='hold' $selected{'DPD_ACTION'}{'hold'}>hold</option>
1952 <option value='restart' $selected{'DPD_ACTION'}{'restart'}>restart</option>
1953 </select>
1954 </td>
1955 </tr><tr>
1956 <td class='boldbase'>$Lang::tr{'remark title'}&nbsp;<img src='/blob.gif' alt='*' /></td>
1957 <td colspan='3'><input type='text' name='REMARK' value='$cgiparams{'REMARK'}' size='55' maxlength='50' /></td>
1958 </tr>
1959 END
1960 ;
1961 if (!$cgiparams{'KEY'}) {
1962 print "<tr><td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked{'EDIT_ADVANCED'}{'on'} /> $Lang::tr{'edit advanced settings when done'}</td></tr>";
1963 }
1964 print "</table>";
1965 &Header::closebox();
1966
1967 if ($cgiparams{'KEY'} && $cgiparams{'AUTH'} eq 'psk') {
1968 &Header::openbox('100%', 'left', $Lang::tr{'authentication'});
1969 print <<END
1970 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
1971 <tr><td class='base' width='50%'>$Lang::tr{'use a pre-shared key'}</td>
1972 <td class='base' width='50%'><input type='password' name='PSK' size='30' value='$cgiparams{'PSK'}' /></td>
1973 </tr>
1974 </table>
1975 END
1976 ;
1977 &Header::closebox();
1978 } elsif (! $cgiparams{'KEY'}) {
1979 my $pskdisabled = ($vpnsettings{'VPN_IP'} eq '%defaultroute') ? "disabled='disabled'" : '' ;
1980 $cgiparams{'PSK'} = $Lang::tr{'vpn incompatible use of defaultroute'} if ($pskdisabled);
1981 my $cakeydisabled = ( ! -f "${General::swroot}/private/cakey.pem" ) ? "disabled='disabled'" : '';
1982 $cgiparams{'CERT_NAME'} = $Lang::tr{'vpn no full pki'} if ($cakeydisabled);
1983 my $cacrtdisabled = ( ! -f "${General::swroot}/ca/cacert.pem" ) ? "disabled='disabled'" : '';
1984
1985 &Header::openbox('100%', 'left', $Lang::tr{'authentication'});
1986 print <<END
1987 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
1988 <tr><td width='5%'><input type='radio' name='AUTH' value='psk' $checked{'AUTH'}{'psk'} $pskdisabled/></td>
1989 <td class='base' width='55%'>$Lang::tr{'use a pre-shared key'}</td>
1990 <td class='base' width='40%'><input type='password' name='PSK' size='30' value='$cgiparams{'PSK'}' $pskdisabled/></td></tr>
1991 <tr><td colspan='3' bgcolor='#000000'></td></tr>
1992 <tr><td><input type='radio' name='AUTH' value='certreq' $checked{'AUTH'}{'certreq'} $cakeydisabled /></td>
1993 <td class='base'><hr />$Lang::tr{'upload a certificate request'}</td>
1994 <td class='base' rowspan='3' valign='middle'><input type='file' name='FH' size='30' $cacrtdisabled /></td></tr>
1995 <tr><td><input type='radio' name='AUTH' value='certfile' $checked{'AUTH'}{'certfile'} $cacrtdisabled /></td>
1996 <td class='base'>$Lang::tr{'upload a certificate'}</td></tr>
1997 <tr><td><input type='radio' name='AUTH' value='pkcs12' $cacrtdisabled /></td>
1998 <td class='base'>$Lang::tr{'upload p12 file'} $Lang::tr{'pkcs12 file password'}:<input type='password' name='P12_PASS'/></td></tr>
1999 <tr><td><input type='radio' name='AUTH' value='auth-dn' $checked{'AUTH'}{'auth-dn'} $cacrtdisabled /></td>
2000 <td class='base'><hr />$Lang::tr{'vpn auth-dn'}</td></tr>
2001 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2002 <tr><td><input type='radio' name='AUTH' value='certgen' $checked{'AUTH'}{'certgen'} $cakeydisabled /></td>
2003 <td class='base'><hr />$Lang::tr{'generate a certificate'}</td><td>&nbsp;</td></tr>
2004 <tr><td>&nbsp;</td>
2005 <td class='base'>$Lang::tr{'users fullname or system hostname'}:</td>
2006 <td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value='$cgiparams{'CERT_NAME'}' size='32' $cakeydisabled /></td></tr>
2007 <tr><td>&nbsp;</td>
2008 <td class='base'>$Lang::tr{'users email'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
2009 <td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value='$cgiparams{'CERT_EMAIL'}' size='32' $cakeydisabled /></td></tr>
2010 <tr><td>&nbsp;</td>
2011 <td class='base'>$Lang::tr{'users department'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
2012 <td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value='$cgiparams{'CERT_OU'}' size='32' $cakeydisabled /></td></tr>
2013 <tr><td>&nbsp;</td>
2014 <td class='base'>$Lang::tr{'organization name'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
2015 <td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value='$cgiparams{'CERT_ORGANIZATION'}' size='32' $cakeydisabled /></td></tr>
2016 <tr><td>&nbsp;</td>
2017 <td class='base'>$Lang::tr{'city'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
2018 <td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value='$cgiparams{'CERT_CITY'}' size='32' $cakeydisabled /></td></tr>
2019 <tr><td>&nbsp;</td>
2020 <td class='base'>$Lang::tr{'state or province'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
2021 <td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value='$cgiparams{'CERT_STATE'}' size='32' $cakeydisabled /></td></tr>
2022 <tr><td>&nbsp;</td>
2023 <td class='base'>$Lang::tr{'country'}:</td>
2024 <td class='base'><select name='CERT_COUNTRY' $cakeydisabled>
2025 END
2026 ;
2027 foreach my $country (sort keys %{Countries::countries}) {
2028 print "\t\t\t<option value='$Countries::countries{$country}'";
2029 if ( $Countries::countries{$country} eq $cgiparams{'CERT_COUNTRY'} ) {
2030 print " selected='selected'";
2031 }
2032 print ">$country</option>\n";
2033 }
2034 print <<END
2035 </select></td></tr>
2036
2037 <tr><td>&nbsp;</td><td class='base'>$Lang::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)<img src='/blob.gif' alt='*' /></td>
2038 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value='$cgiparams{'SUBJECTALTNAME'}' size='32' $cakeydisabled /></td></tr>
2039 <tr><td>&nbsp;</td>
2040 <td class='base'>$Lang::tr{'pkcs12 file password'}:</td>
2041 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value='$cgiparams{'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
2042 <tr><td>&nbsp;</td><td class='base'>$Lang::tr{'pkcs12 file password'}:($Lang::tr{'confirmation'})</td>
2043 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value='$cgiparams{'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
2044 </table>
2045 END
2046 ;
2047 &Header::closebox();
2048 }
2049
2050 print "<div align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' />";
2051 if ($cgiparams{'KEY'}) {
2052 print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />";
2053 }
2054 print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>";
2055 &Header::closebigbox();
2056 &Header::closepage();
2057 exit (0);
2058
2059 VPNCONF_END:
2060 }
2061
2062 ###
2063 ### Advanced settings
2064 ###
2065 if(($cgiparams{'ACTION'} eq $Lang::tr{'advanced'}) ||
2066 ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'ADVANCED'} eq 'yes')) {
2067 &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings);
2068 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
2069 if (! $confighash{$cgiparams{'KEY'}}) {
2070 $errormessage = $Lang::tr{'invalid key'};
2071 goto ADVANCED_END;
2072 }
2073
2074 if ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) {
2075 # I didn't read any incompatibilities here....
2076 #if ($cgiparams{'VHOST'} eq 'on' && $cgiparams{'COMPRESSION'} eq 'on') {
2077 # $errormessage = $Lang::tr{'cannot enable both nat traversal and compression'};
2078 # goto ADVANCED_ERROR;
2079 #}
2080 my @temp = split('\|', $cgiparams{'IKE_ENCRYPTION'});
2081 if ($#temp < 0) {
2082 $errormessage = $Lang::tr{'invalid input'};
2083 goto ADVANCED_ERROR;
2084 }
2085 foreach my $val (@temp) {
2086 if ($val !~ /^(aes256|aes128|3des)$/) {
2087 $errormessage = $Lang::tr{'invalid input'};
2088 goto ADVANCED_ERROR;
2089 }
2090 }
2091 @temp = split('\|', $cgiparams{'IKE_INTEGRITY'});
2092 if ($#temp < 0) {
2093 $errormessage = $Lang::tr{'invalid input'};
2094 goto ADVANCED_ERROR;
2095 }
2096 foreach my $val (@temp) {
2097 if ($val !~ /^(sha2_512|sha2_384|sha2_256|sha|md5|aesxcbc)$/) {
2098 $errormessage = $Lang::tr{'invalid input'};
2099 goto ADVANCED_ERROR;
2100 }
2101 }
2102 @temp = split('\|', $cgiparams{'IKE_GROUPTYPE'});
2103 if ($#temp < 0) {
2104 $errormessage = $Lang::tr{'invalid input'};
2105 goto ADVANCED_ERROR;
2106 }
2107 foreach my $val (@temp) {
2108 if ($val !~ /^(1024|1536|2048|3072|4096|6144|8192)$/) {
2109 $errormessage = $Lang::tr{'invalid input'};
2110 goto ADVANCED_ERROR;
2111 }
2112 }
2113 if ($cgiparams{'IKE_LIFETIME'} !~ /^\d+$/) {
2114 $errormessage = $Lang::tr{'invalid input for ike lifetime'};
2115 goto ADVANCED_ERROR;
2116 }
2117 if ($cgiparams{'IKE_LIFETIME'} < 1 || $cgiparams{'IKE_LIFETIME'} > 8) {
2118 $errormessage = $Lang::tr{'ike lifetime should be between 1 and 8 hours'};
2119 goto ADVANCED_ERROR;
2120 }
2121 @temp = split('\|', $cgiparams{'ESP_ENCRYPTION'});
2122 if ($#temp < 0) {
2123 $errormessage = $Lang::tr{'invalid input'};
2124 goto ADVANCED_ERROR;
2125 }
2126 foreach my $val (@temp) {
2127 if ($val !~ /^(aes256|aes192|aes128|3des)$/) {
2128 $errormessage = $Lang::tr{'invalid input'};
2129 goto ADVANCED_ERROR;
2130 }
2131 }
2132 @temp = split('\|', $cgiparams{'ESP_INTEGRITY'});
2133 if ($#temp < 0) {
2134 $errormessage = $Lang::tr{'invalid input'};
2135 goto ADVANCED_ERROR;
2136 }
2137 foreach my $val (@temp) {
2138 if ($val !~ /^(sha2_512|sha2_384|sha2_256|sha1|md5|aesxcbc)$/) {
2139 $errormessage = $Lang::tr{'invalid input'};
2140 goto ADVANCED_ERROR;
2141 }
2142 }
2143 if ($cgiparams{'ESP_GROUPTYPE'} ne '' &&
2144 $cgiparams{'ESP_GROUPTYPE'} !~ /^modp(1024|1536|2048|3072|4096|6144|8192)$/) {
2145 $errormessage = $Lang::tr{'invalid input'};
2146 goto ADVANCED_ERROR;
2147 }
2148
2149 if ($cgiparams{'ESP_KEYLIFE'} !~ /^\d+$/) {
2150 $errormessage = $Lang::tr{'invalid input for esp keylife'};
2151 goto ADVANCED_ERROR;
2152 }
2153 if ($cgiparams{'ESP_KEYLIFE'} < 1 || $cgiparams{'ESP_KEYLIFE'} > 24) {
2154 $errormessage = $Lang::tr{'esp keylife should be between 1 and 24 hours'};
2155 goto ADVANCED_ERROR;
2156 }
2157
2158 if (
2159 ($cgiparams{'COMPRESSION'} !~ /^(|on|off)$/) ||
2160 ($cgiparams{'ONLY_PROPOSED'} !~ /^(|on|off)$/) ||
2161 ($cgiparams{'PFS'} !~ /^(|on|off)$/) ||
2162 ($cgiparams{'VHOST'} !~ /^(|on|off)$/)
2163 ){
2164 $errormessage = $Lang::tr{'invalid input'};
2165 goto ADVANCED_ERROR;
2166 }
2167
2168 $confighash{$cgiparams{'KEY'}}[18] = $cgiparams{'IKE_ENCRYPTION'};
2169 $confighash{$cgiparams{'KEY'}}[19] = $cgiparams{'IKE_INTEGRITY'};
2170 $confighash{$cgiparams{'KEY'}}[20] = $cgiparams{'IKE_GROUPTYPE'};
2171 $confighash{$cgiparams{'KEY'}}[16] = $cgiparams{'IKE_LIFETIME'};
2172 $confighash{$cgiparams{'KEY'}}[21] = $cgiparams{'ESP_ENCRYPTION'};
2173 $confighash{$cgiparams{'KEY'}}[22] = $cgiparams{'ESP_INTEGRITY'};
2174 $confighash{$cgiparams{'KEY'}}[23] = $cgiparams{'ESP_GROUPTYPE'};
2175 $confighash{$cgiparams{'KEY'}}[17] = $cgiparams{'ESP_KEYLIFE'};
2176 $confighash{$cgiparams{'KEY'}}[12] = 'off'; #$cgiparams{'AGGRMODE'};
2177 $confighash{$cgiparams{'KEY'}}[13] = $cgiparams{'COMPRESSION'};
2178 $confighash{$cgiparams{'KEY'}}[24] = $cgiparams{'ONLY_PROPOSED'};
2179 $confighash{$cgiparams{'KEY'}}[28] = $cgiparams{'PFS'};
2180 $confighash{$cgiparams{'KEY'}}[14] = $cgiparams{'VHOST'};
2181 &General::writehasharray("${General::swroot}/vpn/config", \%confighash);
2182 &writeipsecfiles();
2183 if (&vpnenabled) {
2184 system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
2185 sleep $sleepDelay;
2186 }
2187 goto ADVANCED_END;
2188 } else {
2189 $cgiparams{'IKE_ENCRYPTION'} = $confighash{$cgiparams{'KEY'}}[18];
2190 $cgiparams{'IKE_INTEGRITY'} = $confighash{$cgiparams{'KEY'}}[19];
2191 $cgiparams{'IKE_GROUPTYPE'} = $confighash{$cgiparams{'KEY'}}[20];
2192 $cgiparams{'IKE_LIFETIME'} = $confighash{$cgiparams{'KEY'}}[16];
2193 $cgiparams{'ESP_ENCRYPTION'} = $confighash{$cgiparams{'KEY'}}[21];
2194 $cgiparams{'ESP_INTEGRITY'} = $confighash{$cgiparams{'KEY'}}[22];
2195 $cgiparams{'ESP_GROUPTYPE'} = $confighash{$cgiparams{'KEY'}}[23];
2196 $cgiparams{'ESP_KEYLIFE'} = $confighash{$cgiparams{'KEY'}}[17];
2197 $cgiparams{'COMPRESSION'} = $confighash{$cgiparams{'KEY'}}[13];
2198 $cgiparams{'ONLY_PROPOSED'} = $confighash{$cgiparams{'KEY'}}[24];
2199 $cgiparams{'PFS'} = $confighash{$cgiparams{'KEY'}}[28];
2200 $cgiparams{'VHOST'} = $confighash{$cgiparams{'KEY'}}[14];
2201
2202 if ($confighash{$cgiparams{'KEY'}}[3] eq 'net' || $confighash{$cgiparams{'KEY'}}[10]) {
2203 $cgiparams{'VHOST'} = 'off';
2204 }
2205 }
2206
2207 ADVANCED_ERROR:
2208 $checked{'IKE_ENCRYPTION'}{'aes256'} = '';
2209 $checked{'IKE_ENCRYPTION'}{'aes192'} = '';
2210 $checked{'IKE_ENCRYPTION'}{'aes128'} = '';
2211 $checked{'IKE_ENCRYPTION'}{'3des'} = '';
2212 my @temp = split('\|', $cgiparams{'IKE_ENCRYPTION'});
2213 foreach my $key (@temp) {$checked{'IKE_ENCRYPTION'}{$key} = "selected='selected'"; }
2214 $checked{'IKE_INTEGRITY'}{'sha2_512'} = '';
2215 $checked{'IKE_INTEGRITY'}{'sha2_384'} = '';
2216 $checked{'IKE_INTEGRITY'}{'sha2_256'} = '';
2217 $checked{'IKE_INTEGRITY'}{'sha'} = '';
2218 $checked{'IKE_INTEGRITY'}{'md5'} = '';
2219 $checked{'IKE_INTEGRITY'}{'aesxcbc'} = '';
2220 @temp = split('\|', $cgiparams{'IKE_INTEGRITY'});
2221 foreach my $key (@temp) {$checked{'IKE_INTEGRITY'}{$key} = "selected='selected'"; }
2222 $checked{'IKE_GROUPTYPE'}{'768'} = '';
2223 $checked{'IKE_GROUPTYPE'}{'1024'} = '';
2224 $checked{'IKE_GROUPTYPE'}{'1536'} = '';
2225 $checked{'IKE_GROUPTYPE'}{'2048'} = '';
2226 $checked{'IKE_GROUPTYPE'}{'3072'} = '';
2227 $checked{'IKE_GROUPTYPE'}{'4096'} = '';
2228 $checked{'IKE_GROUPTYPE'}{'6144'} = '';
2229 $checked{'IKE_GROUPTYPE'}{'8192'} = '';
2230 @temp = split('\|', $cgiparams{'IKE_GROUPTYPE'});
2231 foreach my $key (@temp) {$checked{'IKE_GROUPTYPE'}{$key} = "selected='selected'"; }
2232
2233 # 768 is not supported by strongswan
2234 $checked{'IKE_GROUPTYPE'}{'768'} = '';
2235
2236 $checked{'ESP_ENCRYPTION'}{'aes256'} = '';
2237 $checked{'ESP_ENCRYPTION'}{'aes192'} = '';
2238 $checked{'ESP_ENCRYPTION'}{'aes128'} = '';
2239 $checked{'ESP_ENCRYPTION'}{'3des'} = '';
2240 @temp = split('\|', $cgiparams{'ESP_ENCRYPTION'});
2241 foreach my $key (@temp) {$checked{'ESP_ENCRYPTION'}{$key} = "selected='selected'"; }
2242 $checked{'ESP_INTEGRITY'}{'sha2_512'} = '';
2243 $checked{'ESP_INTEGRITY'}{'sha2_384'} = '';
2244 $checked{'ESP_INTEGRITY'}{'sha2_256'} = '';
2245 $checked{'ESP_INTEGRITY'}{'sha1'} = '';
2246 $checked{'ESP_INTEGRITY'}{'md5'} = '';
2247 $checked{'ESP_INTEGRITY'}{'aesxcbc'} = '';
2248 @temp = split('\|', $cgiparams{'ESP_INTEGRITY'});
2249 foreach my $key (@temp) {$checked{'ESP_INTEGRITY'}{$key} = "selected='selected'"; }
2250 $checked{'ESP_GROUPTYPE'}{$cgiparams{'ESP_GROUPTYPE'}} = "selected='selected'";
2251
2252 $checked{'COMPRESSION'} = $cgiparams{'COMPRESSION'} eq 'on' ? "checked='checked'" : '' ;
2253 $checked{'ONLY_PROPOSED'} = $cgiparams{'ONLY_PROPOSED'} eq 'on' ? "checked='checked'" : '' ;
2254 $checked{'PFS'} = $cgiparams{'PFS'} eq 'on' ? "checked='checked'" : '' ;
2255 $checked{'VHOST'} = $cgiparams{'VHOST'} eq 'on' ? "checked='checked'" : '' ;
2256
2257 &Header::showhttpheaders();
2258 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
2259 &Header::openbigbox('100%', 'left', '', $errormessage);
2260
2261 if ($errormessage) {
2262 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
2263 print "<class name='base'>$errormessage";
2264 print "&nbsp;</class>";
2265 &Header::closebox();
2266 }
2267
2268 if ($warnmessage) {
2269 &Header::openbox('100%', 'left', $Lang::tr{'warning messages'});
2270 print "<class name='base'>$warnmessage";
2271 print "&nbsp;</class>";
2272 &Header::closebox();
2273 }
2274
2275 &Header::openbox('100%', 'left', "$Lang::tr{'advanced'}:");
2276 print <<EOF
2277 <form method='post' enctype='multipart/form-data' action='$ENV{'SCRIPT_NAME'}'>
2278 <input type='hidden' name='ADVANCED' value='yes' />
2279 <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />
2280
2281 <table width='100%'>
2282 <tr><td class='boldbase' align='right' valign='top'>$Lang::tr{'ike encryption'}</td><td class='boldbase' valign='top'>
2283 <select name='IKE_ENCRYPTION' multiple='multiple' size='4'>
2284 <option value='aes256' $checked{'IKE_ENCRYPTION'}{'aes256'}>AES (256 bit)</option>
2285 <option value='aes192' $checked{'IKE_ENCRYPTION'}{'aes192'}>AES (192 bit)</option>
2286 <option value='aes128' $checked{'IKE_ENCRYPTION'}{'aes128'}>AES (128 bit)</option>
2287 <option value='3des' $checked{'IKE_ENCRYPTION'}{'3des'}>3DES</option>
2288 </select></td>
2289
2290 <td class='boldbase' align='right' valign='top'>$Lang::tr{'ike integrity'}</td><td class='boldbase' valign='top'>
2291 <select name='IKE_INTEGRITY' multiple='multiple' size='4'>
2292 <option value='sha2_512' $checked{'IKE_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2293 <option value='sha2_384' $checked{'IKE_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2294 <option value='sha2_256' $checked{'IKE_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2295 <option value='sha' $checked{'IKE_INTEGRITY'}{'sha'}>SHA1</option>
2296 <option value='md5' $checked{'IKE_INTEGRITY'}{'md5'}>MD5</option>
2297 <option value='aesxcbc' $checked{'IKE_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2298 </select></td>
2299
2300 <td class='boldbase' align='right' valign='top'>$Lang::tr{'ike grouptype'}</td><td class='boldbase' valign='top'>
2301 <select name='IKE_GROUPTYPE' multiple='multiple' size='4'>
2302 <option value='8192' $checked{'IKE_GROUPTYPE'}{'8192'}>MODP-8192</option>
2303 <option value='6144' $checked{'IKE_GROUPTYPE'}{'6144'}>MODP-6144</option>
2304 <option value='4096' $checked{'IKE_GROUPTYPE'}{'4096'}>MODP-4096</option>
2305 <option value='3072' $checked{'IKE_GROUPTYPE'}{'3072'}>MODP-3072</option>
2306 <option value='2048' $checked{'IKE_GROUPTYPE'}{'2048'}>MODP-2048</option>
2307 <option value='1536' $checked{'IKE_GROUPTYPE'}{'1536'}>MODP-1536</option>
2308 <option value='1024' $checked{'IKE_GROUPTYPE'}{'1024'}>MODP-1024</option>
2309 </select></td>
2310 </tr><tr>
2311 <td class='boldbase' align='right' valign='top'>$Lang::tr{'ike lifetime'}</td><td class='boldbase' valign='top'>
2312 <input type='text' name='IKE_LIFETIME' value='$cgiparams{'IKE_LIFETIME'}' size='5' /> $Lang::tr{'hours'}</td>
2313
2314 </tr><tr>
2315 <td colspan='1'><hr /></td>
2316 </tr><tr>
2317 <td class='boldbase' align='right' valign='top'>$Lang::tr{'esp encryption'}</td><td class='boldbase' valign='top'>
2318 <select name='ESP_ENCRYPTION' multiple='multiple' size='4'>
2319 <option value='aes256' $checked{'ESP_ENCRYPTION'}{'aes256'}>AES (256 bit)</option>
2320 <option value='aes192' $checked{'ESP_ENCRYPTION'}{'aes192'}>AES (192 bit)</option>
2321 <option value='aes128' $checked{'ESP_ENCRYPTION'}{'aes128'}>AES (128 bit)</option>
2322 <option value='3des' $checked{'ESP_ENCRYPTION'}{'3des'}>3DES</option>
2323
2324 <td class='boldbase' align='right' valign='top'>$Lang::tr{'esp integrity'}</td><td class='boldbase' valign='top'>
2325 <select name='ESP_INTEGRITY' multiple='multiple' size='4'>
2326 <option value='sha2_512' $checked{'ESP_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2327 <option value='sha2_384' $checked{'ESP_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2328 <option value='sha2_256' $checked{'ESP_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2329 <option value='sha1' $checked{'ESP_INTEGRITY'}{'sha1'}>SHA1</option>
2330 <option value='md5' $checked{'ESP_INTEGRITY'}{'md5'}>MD5</option>
2331 <option value='aesxcbc' $checked{'ESP_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2332 </select></td>
2333
2334 <td class='boldbase' align='right' valign='top'>$Lang::tr{'esp grouptype'}</td><td class='boldbase' valign='top'>
2335 <select name='ESP_GROUPTYPE'>
2336 <option value=''>$Lang::tr{'phase1 group'}</option></select></td>
2337 </tr><tr>
2338 <td class='boldbase' align='right' valign='top'>$Lang::tr{'esp keylife'}</td><td class='boldbase' valign='top'>
2339 <input type='text' name='ESP_KEYLIFE' value='$cgiparams{'ESP_KEYLIFE'}' size='5' /> $Lang::tr{'hours'}</td>
2340 </tr><tr>
2341 <td colspan='1'><hr /></td>
2342 </tr><tr>
2343 <td colspan='5'><input type='checkbox' name='ONLY_PROPOSED' $checked{'ONLY_PROPOSED'} />
2344 IKE+ESP: $Lang::tr{'use only proposed settings'}</td>
2345 </tr><tr>
2346 <td colspan='5'><input type='checkbox' name='PFS' $checked{'PFS'} />
2347 $Lang::tr{'pfs yes no'}</td>
2348 <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
2349 </tr><tr>
2350 <td colspan='5'><input type='checkbox' name='COMPRESSION' $checked{'COMPRESSION'} />
2351 $Lang::tr{'vpn payload compression'}</td>
2352 <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td>
2353 </tr>
2354 EOF
2355 ;
2356 if ($confighash{$cgiparams{'KEY'}}[3] eq 'net') {
2357 print "<tr><td><input type='hidden' name='VHOST' value='off' /></td></tr>";
2358 } elsif ($confighash{$cgiparams{'KEY'}}[10]) {
2359 print "<tr><td colspan='5'><input type='checkbox' name='VHOST' $checked{'VHOST'} disabled='disabled' />";
2360 print " $Lang::tr{'vpn vhost'}</td></tr>";
2361 } else {
2362 print "<tr><td colspan='5'><input type='checkbox' name='VHOST' $checked{'VHOST'} />";
2363 print " $Lang::tr{'vpn vhost'}</td></tr>";
2364 }
2365
2366 print "</table></form>";
2367 &Header::closebox();
2368 &Header::closebigbox();
2369 &Header::closepage();
2370 exit(0);
2371
2372 ADVANCED_END:
2373 }
2374
2375 ###
2376 ### Default status page
2377 ###
2378 %cgiparams = ();
2379 %cahash = ();
2380 %confighash = ();
2381 &General::readhash("${General::swroot}/vpn/settings", \%cgiparams);
2382 &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash);
2383 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
2384 $cgiparams{'CA_NAME'} = '';
2385
2386 my @status = `/usr/local/bin/ipsecctrl I 2>/dev/null`;
2387
2388 # suggest a default name for this side
2389 if ($cgiparams{'VPN_IP'} eq '' && -e "${General::swroot}/red/active") {
2390 if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) {
2391 my $ipaddr = <IPADDR>;
2392 close IPADDR;
2393 chomp ($ipaddr);
2394 $cgiparams{'VPN_IP'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0];
2395 if ($cgiparams{'VPN_IP'} eq '') {
2396 $cgiparams{'VPN_IP'} = $ipaddr;
2397 }
2398 }
2399 }
2400 # no IP found, use %defaultroute
2401 $cgiparams{'VPN_IP'} ='%defaultroute' if ($cgiparams{'VPN_IP'} eq '');
2402
2403 $cgiparams{'VPN_DELAYED_START'} = 0 if (! defined ($cgiparams{'VPN_DELAYED_START'}));
2404 $checked{'ENABLED'} = $cgiparams{'ENABLED'} eq 'on' ? "checked='checked'" : '';
2405
2406 &Header::showhttpheaders();
2407 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
2408 &Header::openbigbox('100%', 'left', '', $errormessage);
2409
2410 if ($errormessage) {
2411 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
2412 print "<class name='base'>$errormessage\n";
2413 print "&nbsp;</class>\n";
2414 &Header::closebox();
2415 }
2416
2417 &Header::openbox('100%', 'left', $Lang::tr{'global settings'});
2418 print <<END
2419 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2420 <table width='100%'>
2421 <tr>
2422 <td width='20%' class='base' nowrap='nowrap'>$Lang::tr{'vpn red name'}:</td>
2423 <td width='20%'><input type='text' name='VPN_IP' value='$cgiparams{'VPN_IP'}' /></td>
2424 <td width='20%' class='base'>$Lang::tr{'enabled'}<input type='checkbox' name='ENABLED' $checked{'ENABLED'} /></td>
2425 </tr>
2426 END
2427 ;
2428 print <<END
2429 <tr>
2430 <td class='base' nowrap='nowrap'>$Lang::tr{'vpn delayed start'}:&nbsp;<img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' /></td>
2431 <td ><input type='text' name='VPN_DELAYED_START' value='$cgiparams{'VPN_DELAYED_START'}' /></td>
2432 </tr>
2433 <tr>
2434 <td class='base' nowrap='nowrap'>$Lang::tr{'host to net vpn'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
2435 <td ><input type='text' name='RW_NET' value='$cgiparams{'RW_NET'}' /></td>
2436 </tr>
2437 </table>
2438 <hr />
2439 <table width='100%'>
2440 <tr>
2441 <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
2442 <td width='70%' class='base' valign='top'>$Lang::tr{'this field may be blank'}</td>
2443 </tr>
2444 <tr>
2445 <td class='base' valign='top' nowrap='nowrap'><img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' />&nbsp;</td>
2446 <td class='base'> <font class='base'>$Lang::tr{'vpn delayed start help'}</font></td>
2447 <td width='30%' align='center' class='base'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
2448 </tr>
2449 </table>
2450 END
2451 ;
2452 print "</form>";
2453 &Header::closebox();
2454
2455 &Header::openbox('100%', 'left', $Lang::tr{'connection status and controlc'});
2456 print <<END
2457 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
2458 <tr>
2459 <td width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></td>
2460 <td width='22%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></td>
2461 <td width='23%' class='boldbase' align='center'><b>$Lang::tr{'common name'}</b></td>
2462 <td width='30%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></td>
2463 <td width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></td>
2464 <td class='boldbase' align='center' colspan='6'><b>$Lang::tr{'action'}</b></td>
2465 </tr>
2466 END
2467 ;
2468 my $id = 0;
2469 my $gif;
2470 foreach my $key (keys %confighash) {
2471 if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; }
2472
2473 if ($id % 2) {
2474 print "<tr bgcolor='$color{'color20'}'>\n";
2475 } else {
2476 print "<tr bgcolor='$color{'color22'}'>\n";
2477 }
2478 print "<td align='center' nowrap='nowrap'>$confighash{$key}[1]</td>";
2479 print "<td align='center' nowrap='nowrap'>" . $Lang::tr{"$confighash{$key}[3]"} . " (" . $Lang::tr{"$confighash{$key}[4]"} . ") $confighash{$key}[29]</td>";
2480 if ($confighash{$key}[2] eq '%auth-dn') {
2481 print "<td align='left' nowrap='nowrap'>$confighash{$key}[9]</td>";
2482 } elsif ($confighash{$key}[4] eq 'cert') {
2483 print "<td align='left' nowrap='nowrap'>$confighash{$key}[2]</td>";
2484 } else {
2485 print "<td align='left'>&nbsp;</td>";
2486 }
2487 print "<td align='center'>$confighash{$key}[25]</td>";
2488 # get real state
2489 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>";
2490 foreach my $line (@status) {
2491 if (($line =~ /\"$confighash{$key}[1]\".*IPsec SA established/) ||
2492 ($line =~ /$confighash{$key}[1]\{.*INSTALLED/))
2493 {
2494 $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>";
2495 }
2496 }
2497 # move to blueif really down
2498 if ($confighash{$key}[0] eq 'off' && $active =~ /${Header::colourred}/ ) {
2499 $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>";
2500 }
2501 print <<END
2502 <td align='center'>$active</td>
2503 <td align='center'>
2504 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2505 <input type='image' name='$Lang::tr{'restart'}' src='/images/reload.gif' alt='$Lang::tr{'restart'}' title='$Lang::tr{'restart'}' />
2506 <input type='hidden' name='ACTION' value='$Lang::tr{'restart'}' />
2507 <input type='hidden' name='KEY' value='$key' />
2508 </form>
2509 </td>
2510 END
2511 ;
2512 if (($confighash{$key}[4] eq 'cert') && ($confighash{$key}[2] ne '%auth-dn')) {
2513 print <<END
2514 <td align='center'>
2515 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2516 <input type='image' name='$Lang::tr{'show certificate'}' src='/images/info.gif' alt='$Lang::tr{'show certificate'}' title='$Lang::tr{'show certificate'}' />
2517 <input type='hidden' name='ACTION' value='$Lang::tr{'show certificate'}' />
2518 <input type='hidden' name='KEY' value='$key' />
2519 </form>
2520 </td>
2521 END
2522 ; } else {
2523 print "<td width='2%'>&nbsp;</td>";
2524 }
2525 if ($confighash{$key}[4] eq 'cert' && -f "${General::swroot}/certs/$confighash{$key}[1].p12") {
2526 print <<END
2527 <td align='center'>
2528 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2529 <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'}' />
2530 <input type='hidden' name='ACTION' value='$Lang::tr{'download pkcs12 file'}' />
2531 <input type='hidden' name='KEY' value='$key' />
2532 </form>
2533 </td>
2534 END
2535 ; } elsif (($confighash{$key}[4] eq 'cert') && ($confighash{$key}[2] ne '%auth-dn')) {
2536 print <<END
2537 <td align='center'>
2538 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2539 <input type='image' name='$Lang::tr{'download certificate'}' src='/images/floppy.gif' alt='$Lang::tr{'download certificate'}' title='$Lang::tr{'download certificate'}' />
2540 <input type='hidden' name='ACTION' value='$Lang::tr{'download certificate'}' />
2541 <input type='hidden' name='KEY' value='$key' />
2542 </form>
2543 </td>
2544 END
2545 ; } else {
2546 print "<td width='2%'>&nbsp;</td>";
2547 }
2548 print <<END
2549 <td align='center'>
2550 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2551 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$Lang::tr{'toggle enable disable'}' title='$Lang::tr{'toggle enable disable'}' />
2552 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
2553 <input type='hidden' name='KEY' value='$key' />
2554 </form>
2555 </td>
2556
2557 <td align='center'>
2558 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2559 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
2560 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
2561 <input type='hidden' name='KEY' value='$key' />
2562 </form>
2563 </td>
2564 <td align='center' >
2565 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2566 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
2567 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
2568 <input type='hidden' name='KEY' value='$key' />
2569 </form>
2570 </td>
2571 </tr>
2572 END
2573 ;
2574 $id++;
2575 }
2576 print "</table>";
2577
2578 # If the config file contains entries, print Key to action icons
2579 if ( $id ) {
2580 print <<END
2581 <table>
2582 <tr>
2583 <td class='boldbase'>&nbsp; <b>$Lang::tr{'legend'}:</b></td>
2584 <td>&nbsp; <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
2585 <td class='base'>$Lang::tr{'click to disable'}</td>
2586 <td>&nbsp; &nbsp; <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td>
2587 <td class='base'>$Lang::tr{'show certificate'}</td>
2588 <td>&nbsp; &nbsp; <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
2589 <td class='base'>$Lang::tr{'edit'}</td>
2590 <td>&nbsp; &nbsp; <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
2591 <td class='base'>$Lang::tr{'remove'}</td>
2592 </tr>
2593 <tr>
2594 <td>&nbsp; </td>
2595 <td>&nbsp; <img src='/images/off.gif' alt='?OFF' /></td>
2596 <td class='base'>$Lang::tr{'click to enable'}</td>
2597 <td>&nbsp; &nbsp; <img src='/images/floppy.gif' alt='?FLOPPY' /></td>
2598 <td class='base'>$Lang::tr{'download certificate'}</td>
2599 <td>&nbsp; &nbsp; <img src='/images/reload.gif' alt='?RELOAD'/></td>
2600 <td class='base'>$Lang::tr{'restart'}</td>
2601 </tr>
2602 </table>
2603 END
2604 ;
2605 }
2606
2607 print <<END
2608 <table width='100%'>
2609 <tr><td align='center' colspan='9'>
2610 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2611 <input type='submit' name='ACTION' value='$Lang::tr{'add'}' />
2612 </form>
2613 </td></tr>
2614 </table>
2615 END
2616 ;
2617 &Header::closebox();
2618
2619 &Header::openbox('100%', 'left', "$Lang::tr{'certificate authorities'}:");
2620 print <<EOF
2621 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
2622 <tr>
2623 <td width='25%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></td>
2624 <td width='65%' class='boldbase' align='center'><b>$Lang::tr{'subject'}</b></td>
2625 <td width='10%' class='boldbase' colspan='3' align='center'><b>$Lang::tr{'action'}</b></td>
2626 </tr>
2627 EOF
2628 ;
2629 if (-f "${General::swroot}/ca/cacert.pem") {
2630 my $casubject = &Header::cleanhtml(getsubjectfromcert ("${General::swroot}/ca/cacert.pem"));
2631
2632 print <<END
2633 <tr bgcolor='$color{'color22'}'>
2634 <td class='base'>$Lang::tr{'root certificate'}</td>
2635 <td class='base'>$casubject</td>
2636 <td width='3%' align='center'>
2637 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2638 <input type='hidden' name='ACTION' value='$Lang::tr{'show root certificate'}' />
2639 <input type='image' name='$Lang::tr{'edit'}' src='/images/info.gif' alt='$Lang::tr{'show root certificate'}' title='$Lang::tr{'show root certificate'}' />
2640 </form>
2641 </td>
2642 <td width='3%' align='center'>
2643 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2644 <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'}' />
2645 <input type='hidden' name='ACTION' value='$Lang::tr{'download root certificate'}' />
2646 </form>
2647 </td>
2648 <td width='4%'>&nbsp;</td></tr>
2649 END
2650 ;
2651 } else {
2652 # display rootcert generation buttons
2653 print <<END
2654 <tr bgcolor='$color{'color22'}'>
2655 <td class='base'>$Lang::tr{'root certificate'}:</td>
2656 <td class='base'>$Lang::tr{'not present'}</td>
2657 <td colspan='3'>&nbsp;</td></tr>
2658 END
2659 ;
2660 }
2661
2662 if (-f "${General::swroot}/certs/hostcert.pem") {
2663 my $hostsubject = &Header::cleanhtml(getsubjectfromcert ("${General::swroot}/certs/hostcert.pem"));
2664
2665 print <<END
2666 <tr bgcolor='$color{'color20'}'>
2667 <td class='base'>$Lang::tr{'host certificate'}</td>
2668 <td class='base'>$hostsubject</td>
2669 <td width='3%' align='center'>
2670 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2671 <input type='hidden' name='ACTION' value='$Lang::tr{'show host certificate'}' />
2672 <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'}' />
2673 </form>
2674 </td>
2675 <td width='3%' align='center'>
2676 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2677 <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'}' />
2678 <input type='hidden' name='ACTION' value='$Lang::tr{'download host certificate'}' />
2679 </form>
2680 </td>
2681 <td width='4%'>&nbsp;</td></tr>
2682 END
2683 ;
2684 } else {
2685 # Nothing
2686 print <<END
2687 <tr bgcolor='$color{'color20'}'>
2688 <td width='25%' class='base'>$Lang::tr{'host certificate'}:</td>
2689 <td class='base'>$Lang::tr{'not present'}</td>
2690 <td colspan='3'>&nbsp;</td></tr>
2691 END
2692 ;
2693 }
2694
2695 my $rowcolor = 0;
2696 if (keys %cahash > 0) {
2697 foreach my $key (keys %cahash) {
2698 if ($rowcolor++ % 2) {
2699 print "<tr bgcolor='$color{'color20'}'>\n";
2700 } else {
2701 print "<tr bgcolor='$color{'color22'}'>\n";
2702 }
2703 print "<td class='base'>$cahash{$key}[0]</td>\n";
2704 print "<td class='base'>$cahash{$key}[1]</td>\n";
2705 print <<END
2706 <td align='center'>
2707 <form method='post' name='cafrm${key}a' action='$ENV{'SCRIPT_NAME'}'>
2708 <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'}' />
2709 <input type='hidden' name='ACTION' value='$Lang::tr{'show ca certificate'}' />
2710 <input type='hidden' name='KEY' value='$key' />
2711 </form>
2712 </td>
2713 <td align='center'>
2714 <form method='post' name='cafrm${key}b' action='$ENV{'SCRIPT_NAME'}'>
2715 <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'}' />
2716 <input type='hidden' name='ACTION' value='$Lang::tr{'download ca certificate'}' />
2717 <input type='hidden' name='KEY' value='$key' />
2718 </form>
2719 </td>
2720 <td align='center'>
2721 <form method='post' name='cafrm${key}c' action='$ENV{'SCRIPT_NAME'}'>
2722 <input type='hidden' name='ACTION' value='$Lang::tr{'remove ca certificate'}' />
2723 <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'}' />
2724 <input type='hidden' name='KEY' value='$key' />
2725 </form>
2726 </td>
2727 </tr>
2728 END
2729 ;
2730 }
2731 }
2732 print "</table>";
2733
2734 # If the file contains entries, print Key to action icons
2735 if ( -f "${General::swroot}/ca/cacert.pem") {
2736 print <<END
2737 <table><tr>
2738 <td class='boldbase'>&nbsp; <b>$Lang::tr{'legend'}:</b></td>
2739 <td>&nbsp; &nbsp; <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td>
2740 <td class='base'>$Lang::tr{'show certificate'}</td>
2741 <td>&nbsp; &nbsp; <img src='/images/floppy.gif' alt='$Lang::tr{'download certificate'}' /></td>
2742 <td class='base'>$Lang::tr{'download certificate'}</td>
2743 </tr></table>
2744 END
2745 ;
2746 }
2747 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>";
2748 print <<END
2749 <hr />
2750 <form method='post' enctype='multipart/form-data' action='$ENV{'SCRIPT_NAME'}'>
2751 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
2752 $createCA
2753 <tr>
2754 <td class='base' nowrap='nowrap'>$Lang::tr{'ca name'}:</td>
2755 <td nowrap='nowrap'><input type='text' name='CA_NAME' value='$cgiparams{'CA_NAME'}' size='15' /> </td>
2756 <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td>
2757 <td nowrap='nowrap'><input type='submit' name='ACTION' value='$Lang::tr{'upload ca certificate'}' /></td>
2758 </tr>
2759 <tr>
2760 <td colspan='3'>$Lang::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}:</td>
2761 <td><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' /></td>
2762 </tr>
2763 </table>
2764 </form>
2765 END
2766 ;
2767 &Header::closebox();
2768 &Header::closebigbox();
2769 &Header::closepage();