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