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