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