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