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