]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/vpnmain.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2011 IPFire Team info@ipfire.org #
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. #
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. #
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/>. #
20 ###############################################################################
24 use File
:: Temp qw
/ tempfile tempdir / ;
27 # enable only the following on debugging purpose
29 #use CGI::Carp 'fatalsToBrowser';
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" ;
36 #workaround to suppress a warning when a variable is used only once
37 my @dummy = ( ${ Header
:: colourgreen
}, ${ Header
:: colourblue
} );
41 ### Initialize variables
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)
53 my $errormessage = '' ;
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 );
60 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%netsettings );
62 my $green_cidr = & General
:: ipcidr
( " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" );
63 my $blue_cidr = "# Blue not defined" ;
64 if ( $netsettings { 'BLUE_DEV' }) {
65 $blue_cidr = & General
:: ipcidr
( " $netsettings {'BLUE_NETADDRESS'}/ $netsettings {'BLUE_NETMASK'}" );
67 my $orange_cidr = "# Orange not defined" ;
68 if ( $netsettings { 'ORANGE_DEV' }) {
69 $orange_cidr = & General
:: ipcidr
( " $netsettings {'ORANGE_NETADDRESS'}/ $netsettings {'ORANGE_NETMASK'}" );
72 $cgiparams { 'ENABLED' } = 'off' ;
73 $cgiparams { 'EDIT_ADVANCED' } = 'off' ;
74 $cgiparams { 'ACTION' } = '' ;
75 $cgiparams { 'CA_NAME' } = '' ;
76 $cgiparams { 'KEY' } = '' ;
77 $cgiparams { 'TYPE' } = '' ;
78 $cgiparams { 'ADVANCED' } = '' ;
79 $cgiparams { 'NAME' } = '' ;
80 $cgiparams { 'LOCAL_SUBNET' } = '' ;
81 $cgiparams { 'REMOTE_SUBNET' } = '' ;
82 $cgiparams { 'REMOTE' } = '' ;
83 $cgiparams { 'LOCAL_ID' } = '' ;
84 $cgiparams { 'REMOTE_ID' } = '' ;
85 $cgiparams { 'REMARK' } = '' ;
86 $cgiparams { 'PSK' } = '' ;
87 $cgiparams { 'CERT_NAME' } = '' ;
88 $cgiparams { 'CERT_EMAIL' } = '' ;
89 $cgiparams { 'CERT_OU' } = '' ;
90 $cgiparams { 'CERT_ORGANIZATION' } = '' ;
91 $cgiparams { 'CERT_CITY' } = '' ;
92 $cgiparams { 'CERT_STATE' } = '' ;
93 $cgiparams { 'CERT_COUNTRY' } = '' ;
94 $cgiparams { 'SUBJECTALTNAME' } = '' ;
95 $cgiparams { 'CERT_PASS1' } = '' ;
96 $cgiparams { 'CERT_PASS2' } = '' ;
97 $cgiparams { 'ROOTCERT_HOSTNAME' } = '' ;
98 $cgiparams { 'ROOTCERT_COUNTRY' } = '' ;
99 $cgiparams { 'P12_PASS' } = '' ;
100 $cgiparams { 'ROOTCERT_ORGANIZATION' } = '' ;
101 $cgiparams { 'ROOTCERT_HOSTNAME' } = '' ;
102 $cgiparams { 'ROOTCERT_EMAIL' } = '' ;
103 $cgiparams { 'ROOTCERT_OU' } = '' ;
104 $cgiparams { 'ROOTCERT_CITY' } = '' ;
105 $cgiparams { 'ROOTCERT_STATE' } = '' ;
106 $cgiparams { 'RW_NET' } = '' ;
108 & Header
:: getcgihash
( \
%cgiparams , { 'wantfile' => 1 , 'filevar' => 'FH' });
114 my $hostname = $_ [ 0 ];
115 unless ( $hostname ) { return "No hostname" };
116 my $res = new Net
:: DNS
:: Resolver
;
117 my $query = $res -> search ( " $hostname " );
119 foreach my $rr ( $query -> answer ) {
120 ## Potential bug - we are only looking at A records:
121 return 0 if $rr -> type eq "A" ;
124 return $res -> errorstring ;
128 ### Just return true is one interface is vpn enabled
131 return ( $vpnsettings { 'ENABLED' } eq 'on' );
134 ### old version: maintain serial number to one, without explication.
135 ### this : let the counter go, so that each cert is numbered.
139 if ( open ( FILE
, ">${General::swroot}/certs/serial" )) {
143 if ( open ( FILE
, ">${General::swroot}/certs/index.txt" )) {
147 unlink ( "${General::swroot}/certs/index.txt.old" );
148 unlink ( "${General::swroot}/certs/serial.old" );
149 unlink ( "${General::swroot}/certs/01.pem" );
151 sub newcleanssldatabase
153 if (! - s
"${General::swroot}/certs/serial" ) {
154 open ( FILE
, ">${General::swroot}/certs/serial" );
158 if (! - s
">${General::swroot}/certs/index.txt" ) {
159 system ( "touch ${General::swroot}/certs/index.txt" );
161 unlink ( "${General::swroot}/certs/index.txt.old" );
162 unlink ( "${General::swroot}/certs/serial.old" );
163 # unlink ("${General::swroot}/certs/01.pem"); numbering evolves. Wrong place to delete
167 ### Call openssl and return errormessage if any
171 my $retssl = `/usr/bin/openssl $opt 2>&1` ; #redirect stderr
173 foreach my $line ( split ( /\n/ , $retssl )) {
174 & General
:: log ( "ipsec" , " $line " ) if ( 0 ); # 1 for verbose logging
175 $ret .= '<br>' . $line if ( $line =~ /error|unknown/ );
178 $ret = & Header
:: cleanhtml
( $ret );
180 return $ret ?
" $Lang ::tr{'openssl produced an error'}: $ret " : '' ;
183 ### Obtain a CN from given cert
185 sub getCNfromcert
($) {
186 #&General::log("ipsec", "Extracting name from $_[0]...");
187 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
188 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
190 $temp =~ s
+/ Email
+, E
+;
191 $temp =~ s/ ST=/ S=/ ;
197 ### Obtain Subject from given cert
199 sub getsubjectfromcert
($) {
200 #&General::log("ipsec", "Extracting subject from $_[0]...");
201 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
202 $temp =~ /Subject: (.*)[\n]/ ;
204 $temp =~ s
+/ Email
+, E
+;
205 $temp =~ s/ ST=/ S=/ ;
209 ### Combine local subnet and connection name to make a unique name for each connection section
210 ### (this sub is not used now)
212 sub makeconnname
($) {
216 $subnet =~ /^(.*?)\/ (.* ?
)$/; # $1=IP $2=mask
217 my $ip = unpack ( 'N' , & Socket
:: inet_aton
( $1 ));
218 if ( length ( $2 ) > 2 ) {
219 my $mm = unpack ( 'N' , & Socket
:: inet_aton
( $2 ));
220 while ( ( $mm & 1 )== 0 ) {
227 return sprintf ( " %s - %X " , $conn , $ip );
230 ### Write a config file.
232 ###Type=Host : GUI can choose the interface used (RED,GREEN,BLUE) and
233 ### the side is always defined as 'left'.
234 ### configihash[14]: 'VHOST' is allowed
237 sub writeipsecfiles
{
238 my %lconfighash = ();
239 my %lvpnsettings = ();
240 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%lconfighash );
241 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%lvpnsettings );
243 open ( CONF
, ">${General::swroot}/vpn/ipsec.conf" ) or die "Unable to open ${General::swroot}/vpn/ipsec.conf: $!" ;
244 open ( SECRETS
, ">${General::swroot}/vpn/ipsec.secrets" ) or die "Unable to open ${General::swroot}/vpn/ipsec.secrets: $!" ;
247 print CONF
"version 2 \n\n " ;
248 print CONF
"conn %default \n " ;
249 print CONF
" \t keyingtries= %forever \n " ;
252 # Add user includes to config file
253 print CONF
"include /etc/ipsec.user.conf \n " ;
256 print SECRETS
"include /etc/ipsec.user.secrets \n " ;
258 if (- f
"${General::swroot}/certs/hostkey.pem" ) {
259 print SECRETS
": RSA ${General::swroot}/certs/hostkey.pem \n "
261 my $last_secrets = '' ; # old the less specifics connections
263 foreach my $key ( keys %lconfighash ) {
264 next if ( $lconfighash { $key }[ 0 ] ne 'on' );
266 #remote peer is not set? => use '%any'
267 $lconfighash { $key }[ 10 ] = ' %any ' if ( $lconfighash { $key }[ 10 ] eq '' );
270 if ( $lconfighash { $key }[ 26 ] eq 'BLUE' ) {
271 $localside = $netsettings { 'BLUE_ADDRESS' };
272 } elsif ( $lconfighash { $key }[ 26 ] eq 'GREEN' ) {
273 $localside = $netsettings { 'GREEN_ADDRESS' };
274 } elsif ( $lconfighash { $key }[ 26 ] eq 'ORANGE' ) {
275 $localside = $netsettings { 'ORANGE_ADDRESS' };
277 $localside = $lvpnsettings { 'VPN_IP' };
280 print CONF
"conn $lconfighash { $key }[1] \n " ;
281 print CONF
" \t left= $localside \n " ;
282 my $cidr_net =& General
:: ipcidr
( $lconfighash { $key }[ 8 ]);
283 print CONF
" \t leftsubnet= $cidr_net \n " ;
284 print CONF
" \t leftfirewall=yes \n " ;
285 print CONF
" \t lefthostaccess=yes \n " ;
287 print CONF
" \t right= $lconfighash { $key }[10] \n " ;
288 if ( $lconfighash { $key }[ 3 ] eq 'net' ) {
289 my $cidr_net =& General
:: ipcidr
( $lconfighash { $key }[ 11 ]);
290 print CONF
" \t rightsubnet= $cidr_net \n " ;
291 } elsif ( $lconfighash { $key }[ 10 ] eq ' %any ' && $lconfighash { $key }[ 14 ] eq 'on' ) { #vhost allowed for roadwarriors?
292 print CONF
" \t rightsubnet=vhost: %no , %priv \n " ;
295 # Local Cert and Remote Cert (unless auth is DN dn-auth)
296 if ( $lconfighash { $key }[ 4 ] eq 'cert' ) {
297 print CONF
" \t leftcert=${General::swroot}/certs/hostcert.pem \n " ;
298 print CONF
" \t rightcert=${General::swroot}/certs/ $lconfighash { $key }[1]cert.pem \n " if ( $lconfighash { $key }[ 2 ] ne ' %auth -dn' );
301 # Local and Remote IDs
302 print CONF
" \t leftid= \" $lconfighash { $key }[7] \"\n " if ( $lconfighash { $key }[ 7 ]);
303 print CONF
" \t rightid= \" $lconfighash { $key }[9] \"\n " if ( $lconfighash { $key }[ 9 ]);
306 my $pfs = $lconfighash { $key }[ 28 ] eq 'on' ?
'on' : 'off' ;
309 if ( $lconfighash { $key }[ 18 ] && $lconfighash { $key }[ 19 ] && $lconfighash { $key }[ 20 ]) {
311 my @encs = split ( '\|' , $lconfighash { $key }[ 18 ]);
312 my @ints = split ( '\|' , $lconfighash { $key }[ 19 ]);
313 my @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
315 foreach my $i ( @encs ) {
316 foreach my $j ( @ints ) {
317 foreach my $k ( @groups ) {
318 if ( $comma != 0 ) { print CONF
"," ; } else { $comma = 1 ; }
319 print CONF
" $i - $j -modp $k " ;
323 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
329 if ( $lconfighash { $key }[ 21 ] && $lconfighash { $key }[ 22 ]) {
331 my @encs = split ( '\|' , $lconfighash { $key }[ 21 ]);
332 my @ints = split ( '\|' , $lconfighash { $key }[ 22 ]);
333 my @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
335 foreach my $i ( @encs ) {
336 foreach my $j ( @ints ) {
339 foreach my $k ( @groups ) {
340 if ( $comma != 0 ) { print CONF
"," ; } else { $comma = 1 ; }
346 print CONF
" $i - $j $modp " ;
349 if ( $comma != 0 ) { print CONF
"," ; } else { $comma = 1 ; }
354 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
362 if (! $lconfighash { $key }[ 29 ]) {
363 $lconfighash { $key }[ 29 ] = "ikev1" ;
365 print CONF
" \t keyexchange= $lconfighash { $key }[29] \n " ;
368 print CONF
" \t ikelifetime= $lconfighash { $key }[16]h \n " if ( $lconfighash { $key }[ 16 ]);
369 print CONF
" \t keylife= $lconfighash { $key }[17]h \n " if ( $lconfighash { $key }[ 17 ]);
372 print CONF
" \t compress=yes \n " if ( $lconfighash { $key }[ 13 ] eq 'on' );
374 # Dead Peer Detection
375 print CONF
" \t dpddelay=30 \n " ;
376 print CONF
" \t dpdtimeout=120 \n " ;
377 print CONF
" \t dpdaction= $lconfighash { $key }[27] \n " ;
379 # Build Authentication details: LEFTid RIGHTid : PSK psk
381 if ( $lconfighash { $key }[ 4 ] eq 'psk' ) {
382 $psk_line = ( $lconfighash { $key }[ 7 ] ?
$lconfighash { $key }[ 7 ] : $localside ) . " " ;
383 $psk_line .= $lconfighash { $key }[ 9 ] ?
$lconfighash { $key }[ 9 ] : $lconfighash { $key }[ 10 ]; #remoteid or remote address?
384 $psk_line .= " : PSK ' $lconfighash { $key }[5]' \n " ;
385 # if the line contains %any, it is less specific than two IP or ID, so move it at end of file.
386 if ( $psk_line =~ /%any/ ) {
387 $last_secrets .= $psk_line ;
389 print SECRETS
$psk_line ;
391 print CONF
" \t authby=secret \n " ;
393 print CONF
" \t authby=rsasig \n " ;
394 print CONF
" \t leftrsasigkey= %cert \n " ;
395 print CONF
" \t rightrsasigkey= %cert \n " ;
398 # Automatically start only if a net-to-net connection
399 if ( $lconfighash { $key }[ 3 ] eq 'host' ) {
400 print CONF
" \t auto=add \n " ;
401 print CONF
" \t rightsourceip= $lvpnsettings {'RW_NET'} \n " ;
403 print CONF
" \t auto=start \n " ;
407 print SECRETS
$last_secrets if ( $last_secrets );
412 # Hook to regenerate the configuration files.
413 if ( $ENV { "REMOTE_ADDR" } eq "" ) {
419 ### Save main settings
421 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
422 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
423 unless (& General
:: validfqdn
( $cgiparams { 'VPN_IP' }) || & General
:: validip
( $cgiparams { 'VPN_IP' })
424 || $cgiparams { 'VPN_IP' } eq ' %defaultroute ' ) {
425 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
429 unless ( $cgiparams { 'VPN_DELAYED_START' } =~ /^[0-9]{1,3}$/ ) { #allow 0-999 seconds !
430 $errormessage = $Lang :: tr
{ 'invalid time period' };
434 if ( $cgiparams { 'RW_NET' } ne '' and !& General
:: validipandmask
( $cgiparams { 'RW_NET' }) ) {
435 $errormessage = $Lang :: tr
{ 'urlfilter invalid ip or mask error' };
439 $vpnsettings { 'ENABLED' } = $cgiparams { 'ENABLED' };
440 $vpnsettings { 'VPN_IP' } = $cgiparams { 'VPN_IP' };
441 $vpnsettings { 'VPN_DELAYED_START' } = $cgiparams { 'VPN_DELAYED_START' };
442 $vpnsettings { 'RW_NET' } = $cgiparams { 'RW_NET' };
443 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
446 system ( '/usr/local/bin/ipsecctrl' , 'S' );
448 system ( '/usr/local/bin/ipsecctrl' , 'D' );
455 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
456 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
458 foreach my $key ( keys %confighash ) {
459 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
460 delete $confighash { $key };
463 while ( my $file = glob ( "${General::swroot}/{ca,certs,crls,private}/*" )) {
467 if ( open ( FILE
, ">${General::swroot}/vpn/caconfig" )) {
471 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
473 system ( '/usr/local/bin/ipsecctrl' , 'R' );
479 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' }) {
480 & Header
:: showhttpheaders
();
481 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
482 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
483 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
485 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
489 <input type='hidden' name='AREUSURE' value='yes' />
490 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
491 $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}</td>
494 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' />
495 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
502 & Header
:: closebigbox
();
503 & Header
:: closepage
();
507 ### Upload CA Certificate
509 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
510 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
512 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
513 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
517 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
518 $errormessage = $Lang :: tr
{ 'name too long' };
522 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
523 $errormessage = $Lang :: tr
{ 'name is invalid' };
524 goto UPLOAD_CA_ERROR
;
527 # Check if there is no other entry with this name
528 foreach my $key ( keys %cahash ) {
529 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
530 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
535 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
536 $errormessage = $Lang :: tr
{ 'there was no file upload' };
539 # Move uploaded ca to a temporary file
540 ( my $fh , my $filename ) = tempfile
( );
541 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
545 my $temp = `/usr/bin/openssl x509 -text -in $filename ` ;
546 if ( $temp !~ /CA:TRUE/i ) {
547 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
551 move
( $filename , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
553 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
559 my $key = & General
:: findhasharraykey
( \
%cahash );
560 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
561 $cahash { $key }[ 1 ] = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" ));
562 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
564 system ( '/usr/local/bin/ipsecctrl' , 'R' );
570 ### Display ca certificate
572 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
573 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
575 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
576 & Header
:: showhttpheaders
();
577 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
578 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
579 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'ca certificate'}:" );
580 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
581 $output = & Header
:: cleanhtml
( $output , "y" );
582 print "<pre> $output </pre> \n " ;
584 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
585 & Header
:: closebigbox
();
586 & Header
:: closepage
();
589 $errormessage = $Lang :: tr
{ 'invalid key' };
593 ### Export ca certificate to browser
595 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
596 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
598 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
599 print "Content-Type: application/force-download \n " ;
600 print "Content-Type: application/octet-stream \r\n " ;
601 print "Content-Disposition: attachment; filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
602 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
605 $errormessage = $Lang :: tr
{ 'invalid key' };
609 ### Remove ca certificate (step 2)
611 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
612 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
613 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
615 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
616 foreach my $key ( keys %confighash ) {
617 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
618 if ( $test =~ /: OK/ ) {
620 system ( '/usr/local/bin/ipsecctrl' , 'D' , $key ) if (& vpnenabled
);
621 unlink ( "${General::swroot}/certs/ $confighash { $key }[1]cert.pem" );
622 unlink ( "${General::swroot}/certs/ $confighash { $key }[1].p12" );
623 delete $confighash { $key };
624 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
628 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
629 delete $cahash { $cgiparams { 'KEY' }};
630 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
631 system ( '/usr/local/bin/ipsecctrl' , 'R' );
634 $errormessage = $Lang :: tr
{ 'invalid key' };
637 ### Remove ca certificate (step 1)
639 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
640 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
641 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
643 my $assignedcerts = 0 ;
644 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
645 foreach my $key ( keys %confighash ) {
646 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
647 if ( $test =~ /: OK/ ) {
651 if ( $assignedcerts ) {
652 & Header
:: showhttpheaders
();
653 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
654 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
655 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
657 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
661 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
662 <input type='hidden' name='AREUSURE' value='yes' /></td>
665 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>
666 $Lang ::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}</td>
669 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
670 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
677 & Header
:: closebigbox
();
678 & Header
:: closepage
();
681 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
682 delete $cahash { $cgiparams { 'KEY' }};
683 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
684 system ( '/usr/local/bin/ipsecctrl' , 'R' );
688 $errormessage = $Lang :: tr
{ 'invalid key' };
692 ### Display root certificate
694 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
695 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
697 & Header
:: showhttpheaders
();
698 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
699 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
700 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
701 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'root certificate'}:" );
702 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/cacert.pem` ;
704 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'host certificate'}:" );
705 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/hostcert.pem` ;
707 $output = & Header
:: cleanhtml
( $output , "y" );
708 print "<pre> $output </pre> \n " ;
710 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
711 & Header
:: closebigbox
();
712 & Header
:: closepage
();
716 ### Export root certificate to browser
718 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
719 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
720 print "Content-Type: application/force-download \n " ;
721 print "Content-Disposition: attachment; filename=cacert.pem \r\n\r\n " ;
722 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/cacert.pem` ;
726 ### Export host certificate to browser
728 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
729 if ( - f
"${General::swroot}/certs/hostcert.pem" ) {
730 print "Content-Type: application/force-download \n " ;
731 print "Content-Disposition: attachment; filename=hostcert.pem \r\n\r\n " ;
732 print `/usr/bin/openssl x509 -in ${General::swroot}/certs/hostcert.pem` ;
736 ### Form for generating/importing the caroot+host certificate
738 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
739 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
741 if (- f
"${General::swroot}/ca/cacert.pem" ) {
742 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
746 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
747 # fill in initial values
748 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
749 if (- e
"${General::swroot}/red/active" && open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
750 my $ipaddr = < IPADDR
>;
753 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
754 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
755 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
758 $cgiparams { 'ROOTCERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' } if (! $cgiparams { 'ROOTCERT_COUNTRY' });
759 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
760 & General
:: log ( "ipsec" , "Importing from p12..." );
762 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
763 $errormessage = $Lang :: tr
{ 'there was no file upload' };
767 # Move uploaded certificate request to a temporary file
768 ( my $fh , my $filename ) = tempfile
( );
769 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
774 # Extract the CA certificate from the file
775 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
776 if ( open ( STDIN
, "-|" )) {
777 my $opt = " pkcs12 -cacerts -nokeys" ;
778 $opt .= " -in $filename " ;
779 $opt .= " -out /tmp/newcacert" ;
780 $errormessage = & callssl
( $opt );
782 print " $cgiparams {'P12_PASS'} \n " ;
786 # Extract the Host certificate from the file
787 if (! $errormessage ) {
788 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
789 if ( open ( STDIN
, "-|" )) {
790 my $opt = " pkcs12 -clcerts -nokeys" ;
791 $opt .= " -in $filename " ;
792 $opt .= " -out /tmp/newhostcert" ;
793 $errormessage = & callssl
( $opt );
795 print " $cgiparams {'P12_PASS'} \n " ;
800 # Extract the Host key from the file
801 if (! $errormessage ) {
802 & General
:: log ( "ipsec" , "Extracting private key from p12..." );
803 if ( open ( STDIN
, "-|" )) {
804 my $opt = " pkcs12 -nocerts -nodes" ;
805 $opt .= " -in $filename " ;
806 $opt .= " -out /tmp/newhostkey" ;
807 $errormessage = & callssl
( $opt );
809 print " $cgiparams {'P12_PASS'} \n " ;
814 if (! $errormessage ) {
815 & General
:: log ( "ipsec" , "Moving cacert..." );
816 move
( "/tmp/newcacert" , "${General::swroot}/ca/cacert.pem" );
817 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
820 if (! $errormessage ) {
821 & General
:: log ( "ipsec" , "Moving host cert..." );
822 move
( "/tmp/newhostcert" , "${General::swroot}/certs/hostcert.pem" );
823 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
826 if (! $errormessage ) {
827 & General
:: log ( "ipsec" , "Moving private key..." );
828 move
( "/tmp/newhostkey" , "${General::swroot}/certs/hostkey.pem" );
829 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
834 unlink ( '/tmp/newcacert' );
835 unlink ( '/tmp/newhostcert' );
836 unlink ( '/tmp/newhostkey' );
838 unlink ( "${General::swroot}/ca/cacert.pem" );
839 unlink ( "${General::swroot}/certs/hostcert.pem" );
840 unlink ( "${General::swroot}/certs/hostkey.pem" );
844 # Create empty CRL cannot be done because we don't have
845 # the private key for this CAROOT
846 # IPFire can only import certificates
848 & General
:: log ( "ipsec" , "p12 import completed!" );
850 goto ROOTCERT_SUCCESS
;
852 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
854 # Validate input since the form was submitted
855 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
856 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
859 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
860 $errormessage = $Lang :: tr
{ 'organization too long' };
863 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
864 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
867 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
868 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
871 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
872 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
875 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
876 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
879 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
880 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
883 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
884 $errormessage = $Lang :: tr
{ 'invalid input for department' };
887 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
888 $errormessage = $Lang :: tr
{ 'invalid input for city' };
891 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
892 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
895 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
896 $errormessage = $Lang :: tr
{ 'invalid input for country' };
899 #the exact syntax is a list comma separated of
900 # email:any-validemail
901 # URI: a uniform resource indicator
902 # DNS: a DNS domain name
903 # RID: a registered OBJECT IDENTIFIER
905 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
907 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
908 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
912 # Copy the cgisettings to vpnsettings and save the configfile
913 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
914 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
915 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
916 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
917 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
918 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
919 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
920 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
922 # Replace empty strings with a .
923 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
924 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
925 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
927 # Create the CA certificate
928 if (! $errormessage ) {
929 & General
:: log ( "ipsec" , "Creating cacert..." );
930 if ( open ( STDIN
, "-|" )) {
931 my $opt = " req -x509 -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
932 $opt .= " -days 999999" ;
933 $opt .= " -newkey rsa:2048" ;
934 $opt .= " -keyout ${General::swroot}/private/cakey.pem" ;
935 $opt .= " -out ${General::swroot}/ca/cacert.pem" ;
937 $errormessage = & callssl
( $opt );
939 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
942 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
944 print " $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
945 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
950 # Create the Host certificate request
951 if (! $errormessage ) {
952 & General
:: log ( "ipsec" , "Creating host cert..." );
953 if ( open ( STDIN
, "-|" )) {
954 my $opt = " req -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
955 $opt .= " -newkey rsa:1024" ;
956 $opt .= " -keyout ${General::swroot}/certs/hostkey.pem" ;
957 $opt .= " -out ${General::swroot}/certs/hostreq.pem" ;
958 $errormessage = & callssl
( $opt );
960 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
963 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
965 print " $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
966 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
973 # Sign the host certificate request
974 if (! $errormessage ) {
975 & General
:: log ( "ipsec" , "Self signing host cert..." );
977 #No easy way for specifying the contain of subjectAltName without writing a config file...
978 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
980 basicConstraints=CA:FALSE
981 nsComment="OpenSSL Generated Certificate"
982 subjectKeyIdentifier=hash
983 authorityKeyIdentifier=keyid,issuer:always
984 extendedKeyUsage = serverAuth
987 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
990 my $opt = " ca -days 999999" ;
991 $opt .= " -batch -notext" ;
992 $opt .= " -in ${General::swroot}/certs/hostreq.pem" ;
993 $opt .= " -out ${General::swroot}/certs/hostcert.pem" ;
994 $opt .= " -extfile $v3extname " ;
995 $errormessage = & callssl
( $opt );
996 unlink ( "${General::swroot}/certs/hostreq.pem" ); #no more needed
1000 # Create an empty CRL
1001 if (! $errormessage ) {
1002 & General
:: log ( "ipsec" , "Creating emptycrl..." );
1003 my $opt = " ca -gencrl" ;
1004 $opt .= " -out ${General::swroot}/crls/cacrl.pem" ;
1005 $errormessage = & callssl
( $opt );
1008 # Successfully build CA / CERT!
1009 if (! $errormessage ) {
1010 & cleanssldatabase
();
1011 goto ROOTCERT_SUCCESS
;
1015 unlink ( "${General::swroot}/ca/cacert.pem" );
1016 unlink ( "${General::swroot}/certs/hostkey.pem" );
1017 unlink ( "${General::swroot}/certs/hostcert.pem" );
1018 unlink ( "${General::swroot}/crls/cacrl.pem" );
1019 & cleanssldatabase
();
1023 & Header
:: showhttpheaders
();
1024 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1025 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1026 if ( $errormessage ) {
1027 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1028 print "<class name='base'> $errormessage " ;
1029 print " </class>" ;
1030 & Header
:: closebox
();
1032 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
1034 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
1035 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1036 <tr><td width='40%' class='base'> $Lang ::tr{'organization name'}:</td>
1037 <td width='60%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td></tr>
1038 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}:</td>
1039 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td></tr>
1040 <tr><td class='base'> $Lang ::tr{'your e-mail'}: <img src='/blob.gif' alt='*' /></td>
1041 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td></tr>
1042 <tr><td class='base'> $Lang ::tr{'your department'}: <img src='/blob.gif' alt='*' /></td>
1043 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td></tr>
1044 <tr><td class='base'> $Lang ::tr{'city'}: <img src='/blob.gif' alt='*' /></td>
1045 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td></tr>
1046 <tr><td class='base'> $Lang ::tr{'state or province'}: <img src='/blob.gif' alt='*' /></td>
1047 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td></tr>
1048 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1049 <td class='base'><select name='ROOTCERT_COUNTRY'>
1052 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1053 print "<option value=' $Countries ::countries{ $country }'" ;
1054 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1055 print " selected='selected'" ;
1057 print "> $country </option>" ;
1061 <tr><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*) <img src='/blob.gif' alt='*' /></td>
1062 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' /></td></tr>
1064 <td><br /><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /><br /><br /></td></tr>
1065 <tr><td class='base' colspan='2' align='left'>
1066 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1067 $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'}
1069 <tr><td colspan='2'><hr /></td></tr>
1070 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}:</td>
1071 <td nowrap='nowrap'><input type='file' name='FH' size='32' /></td></tr>
1072 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' /></td>
1073 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td></tr>
1075 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td></tr>
1076 <tr><td class='base' colspan='2' align='left'>
1077 <img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
1081 & Header
:: closebox
();
1082 & Header
:: closebigbox
();
1083 & Header
:: closepage
();
1088 system ( '/usr/local/bin/ipsecctrl' , 'S' );
1093 ### Export PKCS12 file to browser
1095 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
1096 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1097 print "Content-Type: application/force-download \n " ;
1098 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
1099 print "Content-Type: application/octet-stream \r\n\r\n " ;
1100 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12` ;
1104 ### Display certificate
1106 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
1107 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1109 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1110 & Header
:: showhttpheaders
();
1111 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1112 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1113 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'cert'}:" );
1114 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1115 $output = & Header
:: cleanhtml
( $output , "y" );
1116 print "<pre> $output </pre> \n " ;
1117 & Header
:: closebox
();
1118 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1119 & Header
:: closebigbox
();
1120 & Header
:: closepage
();
1125 ### Export Certificate to browser
1127 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
1128 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1130 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1131 print "Content-Type: application/force-download \n " ;
1132 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \n\n " ;
1133 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1138 ### Enable/Disable connection
1140 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1142 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1143 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1145 if ( $confighash { $cgiparams { 'KEY' }}) {
1146 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
1147 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
1148 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1150 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1152 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1153 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
1154 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1159 $errormessage = $Lang :: tr
{ 'invalid key' };
1163 ### Restart connection
1165 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
1166 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1167 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1169 if ( $confighash { $cgiparams { 'KEY' }}) {
1171 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
1175 $errormessage = $Lang :: tr
{ 'invalid key' };
1179 ### Remove connection
1181 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
1182 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1183 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1185 if ( $confighash { $cgiparams { 'KEY' }}) {
1186 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1187 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1188 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1189 delete $confighash { $cgiparams { 'KEY' }};
1190 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1193 $errormessage = $Lang :: tr
{ 'invalid key' };
1197 ### Choose between adding a host-net or net-net connection
1199 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
1200 & Header
:: showhttpheaders
();
1201 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1202 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1203 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection type' });
1205 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
1206 <b> $Lang ::tr{'connection type'}:</b><br />
1208 <tr><td><input type='radio' name='TYPE' value='host' checked='checked' /></td>
1209 <td class='base'> $Lang ::tr{'host to net vpn'}</td>
1211 <td><input type='radio' name='TYPE' value='net' /></td>
1212 <td class='base'> $Lang ::tr{'net to net vpn'}</td>
1214 <td align='center' colspan='2'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td>
1219 & Header
:: closebox
();
1220 & Header
:: closebigbox
();
1221 & Header
:: closepage
();
1224 ### Adding/Editing/Saving a connection
1226 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
1227 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
1228 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
1230 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1231 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1232 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1234 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
1235 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
1236 $errormessage = $Lang :: tr
{ 'invalid key' };
1239 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
1240 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
1241 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
1242 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
1243 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
1244 #$cgiparams{'free'} = $confighash{$cgiparams{'KEY'}}[6];
1245 $cgiparams { 'LOCAL_ID' } = $confighash { $cgiparams { 'KEY' }}[ 7 ];
1246 $cgiparams { 'LOCAL_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 8 ];
1247 $cgiparams { 'REMOTE_ID' } = $confighash { $cgiparams { 'KEY' }}[ 9 ];
1248 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
1249 $cgiparams { 'REMOTE_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 11 ];
1250 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
1251 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
1252 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
1253 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
1254 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
1255 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
1256 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
1257 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
1258 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
1259 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
1260 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
1261 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
1262 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
1263 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
1264 $cgiparams { 'VHOST' } = $confighash { $cgiparams { 'KEY' }}[ 14 ];
1266 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
1267 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
1268 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
1269 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
1273 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
1274 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
1278 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
1279 $errormessage = $Lang :: tr
{ 'name is invalid' };
1283 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
1284 $errormessage = $Lang :: tr
{ 'name too long' };
1288 # Check if there is no other entry with this name
1289 if (! $cgiparams { 'KEY' }) { #only for add
1290 foreach my $key ( keys %confighash ) {
1291 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
1292 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
1298 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! $cgiparams { 'REMOTE' })) {
1299 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1303 if ( $cgiparams { 'REMOTE' }) {
1304 if (( $cgiparams { 'REMOTE' } ne ' %any ' ) && (! & General
:: validip
( $cgiparams { 'REMOTE' }))) {
1305 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
1306 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1309 if (& valid_dns_host
( $cgiparams { 'REMOTE' })) {
1310 $warnmessage = " $Lang ::tr{'check vpn lr'} $cgiparams {'REMOTE'}. $Lang ::tr{'dns check failed'}" ;
1316 unless (& General
:: validipandmask
( $cgiparams { 'LOCAL_SUBNET' })) {
1317 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
1321 # Allow only one roadwarrior/psk without remote IP-address
1322 if ( $cgiparams { 'REMOTE' } eq '' && $cgiparams { 'AUTH' } eq 'psk' ) {
1323 foreach my $key ( keys %confighash ) {
1324 if ( ( $cgiparams { 'KEY' } ne $key ) &&
1325 ( $confighash { $key }[ 4 ] eq 'psk' ) &&
1326 ( $confighash { $key }[ 10 ] eq '' ) ) {
1327 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
1332 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! & General
:: validipandmask
( $cgiparams { 'REMOTE_SUBNET' }))) {
1333 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
1337 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
1338 $errormessage = $Lang :: tr
{ 'invalid input' };
1341 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
1342 $errormessage = $Lang :: tr
{ 'invalid input' };
1346 # Allow nothing or a string (DN,FDQN,) beginning with @
1347 # with no comma but slashes between RID eg @O=FR/C=Paris/OU=myhome/CN=franck
1348 if ( ( $cgiparams { 'LOCAL_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1349 ( $cgiparams { 'REMOTE_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1350 (( $cgiparams { 'REMOTE_ID' } eq $cgiparams { 'LOCAL_ID' }) && ( $cgiparams { 'LOCAL_ID' } ne '' ))
1352 $errormessage = $Lang :: tr
{ 'invalid local-remote id' } . '<br />' .
1353 'DER_ASN1_DN: @c =FR/ou=Paris/ou=Home/cn=*<br />' .
1354 'FQDN: @ipfire .org<br />' .
1355 'USER_FQDN: info @ipfire .org<br />' .
1356 'IPV4_ADDR: 123.123.123.123' ;
1359 # If Auth is DN, verify existance of Remote ID.
1360 if ( $cgiparams { 'REMOTE_ID' } eq '' && (
1361 $cgiparams { 'AUTH' } eq 'auth-dn' || # while creation
1362 $confighash { $cgiparams { 'KEY' }}[ 2 ] eq ' %auth -dn' )){ # while editing
1363 $errormessage = $Lang :: tr
{ 'vpn missing remote id' };
1367 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1368 if (! length ( $cgiparams { 'PSK' }) ) {
1369 $errormessage = $Lang :: tr
{ 'pre-shared key is too short' };
1372 if ( $cgiparams { 'PSK' } =~ /'/ ) {
1373 $cgiparams { 'PSK' } =~ tr/'/ / ;
1374 $errormessage = $Lang :: tr
{ 'invalid characters found in pre-shared key' };
1377 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
1378 if ( $cgiparams { 'KEY' }) {
1379 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1382 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1383 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1387 # Move uploaded certificate request to a temporary file
1388 ( my $fh , my $filename ) = tempfile
( );
1389 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1394 # Sign the certificate request
1395 & General
:: log ( "ipsec" , "Signing your cert $cgiparams {'NAME'}..." );
1396 my $opt = " ca -days 999999" ;
1397 $opt .= " -batch -notext" ;
1398 $opt .= " -in $filename " ;
1399 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1401 if ( $errormessage = & callssl
( $opt ) ) {
1403 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1404 & cleanssldatabase
();
1408 & cleanssldatabase
();
1411 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1412 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1413 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1416 } elsif ( $cgiparams { 'AUTH' } eq 'pkcs12' ) {
1417 & General
:: log ( "ipsec" , "Importing from p12..." );
1419 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1420 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1421 goto ROOTCERT_ERROR
;
1424 # Move uploaded certificate request to a temporary file
1425 ( my $fh , my $filename ) = tempfile
( );
1426 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1428 goto ROOTCERT_ERROR
;
1431 # Extract the CA certificate from the file
1432 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
1433 if ( open ( STDIN
, "-|" )) {
1434 my $opt = " pkcs12 -cacerts -nokeys" ;
1435 $opt .= " -in $filename " ;
1436 $opt .= " -out /tmp/newcacert" ;
1437 $errormessage = & callssl
( $opt );
1439 print " $cgiparams {'P12_PASS'} \n " ;
1443 # Extract the Host certificate from the file
1444 if (! $errormessage ) {
1445 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
1446 if ( open ( STDIN
, "-|" )) {
1447 my $opt = " pkcs12 -clcerts -nokeys" ;
1448 $opt .= " -in $filename " ;
1449 $opt .= " -out /tmp/newhostcert" ;
1450 $errormessage = & callssl
( $opt );
1452 print " $cgiparams {'P12_PASS'} \n " ;
1457 if (! $errormessage ) {
1458 & General
:: log ( "ipsec" , "Moving cacert..." );
1459 #If CA have new subject, add it to our list of CA
1460 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( '/tmp/newcacert' ));
1462 foreach my $x ( keys %cahash ) {
1463 $casubject = '' if ( $cahash { $x }[ 1 ] eq $casubject );
1464 unshift ( @names , $cahash { $x }[ 0 ]);
1466 if ( $casubject ) { # a new one!
1467 my $temp = `/usr/bin/openssl x509 -text -in /tmp/newcacert` ;
1468 if ( $temp !~ /CA:TRUE/i ) {
1469 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
1471 #compute a name for it
1473 while ( grep ( /Imported-$idx/ , @names ) ) { $idx ++};
1474 $cgiparams { 'CA_NAME' }= "Imported- $idx " ;
1475 $cgiparams { 'CERT_NAME' }=& Header
:: cleanhtml
( getCNfromcert
( '/tmp/newhostcert' ));
1476 move
( "/tmp/newcacert" , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1477 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1478 if (! $errormessage ) {
1479 my $key = & General
:: findhasharraykey
( \
%cahash );
1480 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
1481 $cahash { $key }[ 1 ] = $casubject ;
1482 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1483 system ( '/usr/local/bin/ipsecctrl' , 'R' );
1488 if (! $errormessage ) {
1489 & General
:: log ( "ipsec" , "Moving host cert..." );
1490 move
( "/tmp/newhostcert" , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1491 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1496 unlink ( '/tmp/newcacert' );
1497 unlink ( '/tmp/newhostcert' );
1498 if ( $errormessage ) {
1499 unlink ( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1500 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1503 & General
:: log ( "ipsec" , "p12 import completed!" );
1504 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
1505 if ( $cgiparams { 'KEY' }) {
1506 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1509 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1510 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1513 # Move uploaded certificate to a temporary file
1514 ( my $fh , my $filename ) = tempfile
( );
1515 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1520 # Verify the certificate has a valid CA and move it
1521 & General
:: log ( "ipsec" , "Validating imported cert against our known CA..." );
1522 my $validca = 1 ; #assume ok
1523 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/cacert.pem $filename ` ;
1524 if ( $test !~ /: OK/ ) {
1526 foreach my $key ( keys %cahash ) {
1527 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $key }[0]cert.pem $filename ` ;
1528 if ( $test =~ /: OK/ ) {
1535 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
1539 move
( $filename , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1541 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1547 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1548 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1549 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1550 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1553 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
1554 if ( $cgiparams { 'KEY' }) {
1555 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1558 # Validate input since the form was submitted
1559 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
1560 $errormessage = $Lang :: tr
{ 'name too long' };
1563 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1564 $errormessage = $Lang :: tr
{ 'invalid input for name' };
1567 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
1568 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1571 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
1572 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1575 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1576 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1579 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
1580 $errormessage = $Lang :: tr
{ 'organization too long' };
1583 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1584 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1587 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1588 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1591 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1592 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1595 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1596 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1599 #the exact syntax is a list comma separated of
1600 # email:any-validemail
1601 # URI: a uniform resource indicator
1602 # DNS: a DNS domain name
1603 # RID: a registered OBJECT IDENTIFIER
1605 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
1607 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
1608 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
1612 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
1613 $errormessage = $Lang :: tr
{ 'password too short' };
1616 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
1617 $errormessage = $Lang :: tr
{ 'passwords do not match' };
1621 # Replace empty strings with a .
1622 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
1623 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
1624 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
1626 # Create the Host certificate request
1627 & General
:: log ( "ipsec" , "Creating a cert..." );
1629 if ( open ( STDIN
, "-|" )) {
1630 my $opt = " req -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
1631 $opt .= " -newkey rsa:1024" ;
1632 $opt .= " -keyout ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1633 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1635 if ( $errormessage = & callssl
( $opt ) ) {
1636 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1637 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1641 print " $cgiparams {'CERT_COUNTRY'} \n " ;
1644 print " $cgiparams {'CERT_ORGANIZATION'} \n " ;
1646 print " $cgiparams {'CERT_NAME'} \n " ;
1647 print " $cgiparams {'CERT_EMAIL'} \n " ;
1653 # Sign the host certificate request
1654 & General
:: log ( "ipsec" , "Signing the cert $cgiparams {'NAME'}..." );
1656 #No easy way for specifying the contain of subjectAltName without writing a config file...
1657 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1659 basicConstraints=CA:FALSE
1660 nsComment="OpenSSL Generated Certificate"
1661 subjectKeyIdentifier=hash
1662 authorityKeyIdentifier=keyid,issuer:always
1665 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1668 my $opt = " ca -days 999999 -batch -notext" ;
1669 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1670 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1671 $opt .= " -extfile $v3extname " ;
1673 if ( $errormessage = & callssl
( $opt ) ) {
1674 unlink ( $v3extname );
1675 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1676 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1677 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1678 & cleanssldatabase
();
1681 unlink ( $v3extname );
1682 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1683 & cleanssldatabase
();
1686 # Create the pkcs12 file
1687 & General
:: log ( "ipsec" , "Packing a pkcs12 file..." );
1688 $opt = " pkcs12 -export" ;
1689 $opt .= " -inkey ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1690 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1691 $opt .= " -name \" $cgiparams {'NAME'} \" " ;
1692 $opt .= " -passout pass: $cgiparams {'CERT_PASS1'}" ;
1693 $opt .= " -certfile ${General::swroot}/ca/cacert.pem" ;
1694 $opt .= " -caname \" $vpnsettings {'ROOTCERT_ORGANIZATION'} CA \" " ;
1695 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}.p12" ;
1697 if ( $errormessage = & callssl
( $opt ) ) {
1698 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1699 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1700 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}.p12" );
1703 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1705 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
1706 ; # Nothing, just editing
1707 } elsif ( $cgiparams { 'AUTH' } eq 'auth-dn' ) {
1708 $cgiparams { 'CERT_NAME' } = ' %auth -dn' ; # a special value saying 'no cert file'
1710 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
1714 # 1)Error message here is not accurate.
1715 # 2)Test is superfluous, openswan can reference same cert multiple times
1716 # 3)Present since initial version (1.3.2.11), it isn't a bug correction
1717 # Check if there is no other entry with this certificate name
1718 #if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk') && ($cgiparams{'AUTH'} ne 'auth-dn')) {
1719 # foreach my $key (keys %confighash) {
1720 # if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) {
1721 # $errormessage = $Lang::tr{'a connection with this common name already exists'};
1722 # goto VPNCONF_ERROR;
1728 my $key = $cgiparams { 'KEY' };
1730 $key = & General
:: findhasharraykey
( \
%confighash );
1731 foreach my $i ( 0 .. 28 ) { $confighash { $key }[ $i ] = "" ;}
1733 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
1734 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
1735 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
1736 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
1738 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
1739 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1740 $confighash { $key }[ 4 ] = 'psk' ;
1741 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
1743 $confighash { $key }[ 4 ] = 'cert' ;
1745 if ( $cgiparams { 'TYPE' } eq 'net' ) {
1746 $confighash { $key }[ 11 ] = $cgiparams { 'REMOTE_SUBNET' };
1748 $confighash { $key }[ 7 ] = $cgiparams { 'LOCAL_ID' };
1749 $confighash { $key }[ 8 ] = $cgiparams { 'LOCAL_SUBNET' };
1750 $confighash { $key }[ 9 ] = $cgiparams { 'REMOTE_ID' };
1751 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
1752 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
1753 $confighash { $key }[ 26 ] = "" ; # Formerly INTERFACE
1754 $confighash { $key }[ 27 ] = $cgiparams { 'DPD_ACTION' };
1755 $confighash { $key }[ 29 ] = $cgiparams { 'IKE_VERSION' };
1757 #dont forget advanced value
1758 $confighash { $key }[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
1759 $confighash { $key }[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
1760 $confighash { $key }[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
1761 $confighash { $key }[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
1762 $confighash { $key }[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
1763 $confighash { $key }[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
1764 $confighash { $key }[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
1765 $confighash { $key }[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
1766 $confighash { $key }[ 12 ] = 'off' ; # $cgiparams{'AGGRMODE'};
1767 $confighash { $key }[ 13 ] = $cgiparams { 'COMPRESSION' };
1768 $confighash { $key }[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
1769 $confighash { $key }[ 28 ] = $cgiparams { 'PFS' };
1770 $confighash { $key }[ 14 ] = $cgiparams { 'VHOST' };
1772 #free unused fields!
1773 $confighash { $key }[ 6 ] = 'off' ;
1774 $confighash { $key }[ 15 ] = 'off' ;
1776 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1779 system ( '/usr/local/bin/ipsecctrl' , 'S' , $key );
1782 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
1783 $cgiparams { 'KEY' } = $key ;
1784 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
1787 } else { # add new connection
1788 $cgiparams { 'ENABLED' } = 'on' ;
1789 if ( ! - f
"${General::swroot}/private/cakey.pem" ) {
1790 $cgiparams { 'AUTH' } = 'psk' ;
1791 } elsif ( ! - f
"${General::swroot}/ca/cacert.pem" ) {
1792 $cgiparams { 'AUTH' } = 'certfile' ;
1794 $cgiparams { 'AUTH' } = 'certgen' ;
1796 $cgiparams { 'LOCAL_SUBNET' } = " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" ;
1797 $cgiparams { 'CERT_EMAIL' } = $vpnsettings { 'ROOTCERT_EMAIL' };
1798 $cgiparams { 'CERT_OU' } = $vpnsettings { 'ROOTCERT_OU' };
1799 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
1800 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
1801 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
1802 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
1804 # choose appropriate dpd action
1805 if ( $cgiparams { 'TYPE' } eq 'host' ) {
1806 $cgiparams { 'DPD_ACTION' } = 'clear' ;
1808 $cgiparams { 'DPD_ACTION' } = 'restart' ;
1811 # Default IKE Version to v2
1812 if (! $cgiparams { 'IKE_VERSION' }) {
1813 $cgiparams { 'IKE_VERSION' } = 'ikev2' ;
1817 $cgiparams { 'LOCAL_ID' } = '' ;
1818 $cgiparams { 'REMOTE_ID' } = '' ;
1820 #use default advanced value
1821 $cgiparams { 'IKE_ENCRYPTION' } = 'aes256|aes192|aes128|3des' ; #[18];
1822 $cgiparams { 'IKE_INTEGRITY' } = 'sha2_256|sha|md5' ; #[19];
1823 $cgiparams { 'IKE_GROUPTYPE' } = '8192|6144|4096|3072|2048|1536|1024' ; #[20];
1824 $cgiparams { 'IKE_LIFETIME' } = '1' ; #[16];
1825 $cgiparams { 'ESP_ENCRYPTION' } = 'aes256|aes192|aes128|3des' ; #[21];
1826 $cgiparams { 'ESP_INTEGRITY' } = 'sha2_256|sha1|md5' ; #[22];
1827 $cgiparams { 'ESP_GROUPTYPE' } = '' ; #[23];
1828 $cgiparams { 'ESP_KEYLIFE' } = '8' ; #[17];
1829 $cgiparams { 'COMPRESSION' } = 'on' ; #[13];
1830 $cgiparams { 'ONLY_PROPOSED' } = 'off' ; #[24];
1831 $cgiparams { 'PFS' } = 'on' ; #[28];
1832 $cgiparams { 'VHOST' } = 'on' ; #[14];
1836 $checked { 'ENABLED' }{ 'off' } = '' ;
1837 $checked { 'ENABLED' }{ 'on' } = '' ;
1838 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = "checked='checked'" ;
1840 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
1841 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
1842 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = "checked='checked'" ;
1844 $checked { 'AUTH' }{ 'psk' } = '' ;
1845 $checked { 'AUTH' }{ 'certreq' } = '' ;
1846 $checked { 'AUTH' }{ 'certgen' } = '' ;
1847 $checked { 'AUTH' }{ 'certfile' } = '' ;
1848 $checked { 'AUTH' }{ 'pkcs12' } = '' ;
1849 $checked { 'AUTH' }{ 'auth-dn' } = '' ;
1850 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = "checked='checked'" ;
1852 $selected { 'DPD_ACTION' }{ 'clear' } = '' ;
1853 $selected { 'DPD_ACTION' }{ 'hold' } = '' ;
1854 $selected { 'DPD_ACTION' }{ 'restart' } = '' ;
1855 $selected { 'DPD_ACTION' }{ $cgiparams { 'DPD_ACTION' }} = "selected='selected'" ;
1857 $selected { 'IKE_VERSION' }{ 'ikev1' } = '' ;
1858 $selected { 'IKE_VERSION' }{ 'ikev2' } = '' ;
1859 $selected { 'IKE_VERSION' }{ $cgiparams { 'IKE_VERSION' }} = "selected='selected'" ;
1861 & Header
:: showhttpheaders
();
1862 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1863 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1864 if ( $errormessage ) {
1865 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1866 print "<class name='base'> $errormessage " ;
1867 print " </class>" ;
1868 & Header
:: closebox
();
1872 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'warning messages'}:" );
1873 print "<class name='base'> $warnmessage " ;
1874 print " </class>" ;
1875 & Header
:: closebox
();
1878 print "<form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>" ;
1880 <input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />
1881 <input type='hidden' name='IKE_ENCRYPTION' value=' $cgiparams {'IKE_ENCRYPTION'}' />
1882 <input type='hidden' name='IKE_INTEGRITY' value=' $cgiparams {'IKE_INTEGRITY'}' />
1883 <input type='hidden' name='IKE_GROUPTYPE' value=' $cgiparams {'IKE_GROUPTYPE'}' />
1884 <input type='hidden' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' />
1885 <input type='hidden' name='ESP_ENCRYPTION' value=' $cgiparams {'ESP_ENCRYPTION'}' />
1886 <input type='hidden' name='ESP_INTEGRITY' value=' $cgiparams {'ESP_INTEGRITY'}' />
1887 <input type='hidden' name='ESP_GROUPTYPE' value=' $cgiparams {'ESP_GROUPTYPE'}' />
1888 <input type='hidden' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' />
1889 <input type='hidden' name='COMPRESSION' value=' $cgiparams {'COMPRESSION'}' />
1890 <input type='hidden' name='ONLY_PROPOSED' value=' $cgiparams {'ONLY_PROPOSED'}' />
1891 <input type='hidden' name='PFS' value=' $cgiparams {'PFS'}' />
1892 <input type='hidden' name='VHOST' value=' $cgiparams {'VHOST'}' />
1895 if ( $cgiparams { 'KEY' }) {
1896 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
1897 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
1900 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'connection'}:" );
1901 print "<table width='100%'>" ;
1902 print "<tr><td width='25%' class='boldbase'> $Lang ::tr{'name'}:</td>" ;
1903 if ( $cgiparams { 'KEY' }) {
1904 print "<td width='25%' class='base'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /><b> $cgiparams {'NAME'}</b></td>" ;
1906 print "<td width='25%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' size='30' /></td>" ;
1908 print "<td> $Lang ::tr{'enabled'}</td><td><input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td></tr>" ;
1909 print '</tr><td><br /></td><tr>' ;
1913 if ( $cgiparams { 'TYPE' } eq 'host' ) {
1914 $disabled = "disabled='disabled'" ;
1915 $blob = "<img src='/blob.gif' alt='*' />" ;
1920 <td class='boldbase'> $Lang ::tr{'remote host/ip'}: $blob </td>
1922 <input type='text' name='REMOTE' value=' $cgiparams {'REMOTE'}' size='30' />
1924 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'}</td>
1926 <input $disabled type='text' name='REMOTE_SUBNET' value=' $cgiparams {'REMOTE_SUBNET'}' size='30' />
1930 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'}</td>
1932 <input type='text' name='LOCAL_SUBNET' value=' $cgiparams {'LOCAL_SUBNET'}' size='30' />
1936 <td class='boldbase'> $Lang ::tr{'vpn local id'}:<br />( $Lang ::tr{'eg'} <tt>@xy.example.com</tt>)</td>
1937 <td><input type='text' name='LOCAL_ID' value=' $cgiparams {'LOCAL_ID'}' /></td>
1938 <td class='boldbase'> $Lang ::tr{'vpn remote id'}:</td>
1939 <td><input type='text' name='REMOTE_ID' value=' $cgiparams {'REMOTE_ID'}' /></td>
1941 </tr><td><br /></td><tr>
1942 <td> $Lang ::tr{'vpn keyexchange'}:</td>
1943 <td><select name='IKE_VERSION'>
1944 <option value='ikev2' $selected {'IKE_VERSION'}{'ikev2'}>IKEv2</option>
1945 <option value='ikev1' $selected {'IKE_VERSION'}{'ikev1'}>IKEv1</option>
1948 <td> $Lang ::tr{'dpd action'}:</td>
1949 <td><select name='DPD_ACTION'>
1950 <option value='clear' $selected {'DPD_ACTION'}{'clear'}>clear</option>
1951 <option value='hold' $selected {'DPD_ACTION'}{'hold'}>hold</option>
1952 <option value='restart' $selected {'DPD_ACTION'}{'restart'}>restart</option>
1956 <td class='boldbase'> $Lang ::tr{'remark title'} <img src='/blob.gif' alt='*' /></td>
1957 <td colspan='3'><input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' size='55' maxlength='50' /></td>
1961 if (! $cgiparams { 'KEY' }) {
1962 print "<tr><td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked {'EDIT_ADVANCED'}{'on'} /> $Lang ::tr{'edit advanced settings when done'}</td></tr>" ;
1965 & Header
:: closebox
();
1967 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
1968 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
1970 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
1971 <tr><td class='base' width='50%'> $Lang ::tr{'use a pre-shared key'}</td>
1972 <td class='base' width='50%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td>
1977 & Header
:: closebox
();
1978 } elsif (! $cgiparams { 'KEY' }) {
1979 my $pskdisabled = ( $vpnsettings { 'VPN_IP' } eq ' %defaultroute ' ) ?
"disabled='disabled'" : '' ;
1980 $cgiparams { 'PSK' } = $Lang :: tr
{ 'vpn incompatible use of defaultroute' } if ( $pskdisabled );
1981 my $cakeydisabled = ( ! - f
"${General::swroot}/private/cakey.pem" ) ?
"disabled='disabled'" : '' ;
1982 $cgiparams { 'CERT_NAME' } = $Lang :: tr
{ 'vpn no full pki' } if ( $cakeydisabled );
1983 my $cacrtdisabled = ( ! - f
"${General::swroot}/ca/cacert.pem" ) ?
"disabled='disabled'" : '' ;
1985 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
1987 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
1988 <tr><td width='5%'><input type='radio' name='AUTH' value='psk' $checked {'AUTH'}{'psk'} $pskdisabled /></td>
1989 <td class='base' width='55%'> $Lang ::tr{'use a pre-shared key'}</td>
1990 <td class='base' width='40%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' $pskdisabled /></td></tr>
1991 <tr><td colspan='3' bgcolor='#000000'></td></tr>
1992 <tr><td><input type='radio' name='AUTH' value='certreq' $checked {'AUTH'}{'certreq'} $cakeydisabled /></td>
1993 <td class='base'><hr /> $Lang ::tr{'upload a certificate request'}</td>
1994 <td class='base' rowspan='3' valign='middle'><input type='file' name='FH' size='30' $cacrtdisabled /></td></tr>
1995 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td>
1996 <td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
1997 <tr><td><input type='radio' name='AUTH' value='pkcs12' $cacrtdisabled /></td>
1998 <td class='base'> $Lang ::tr{'upload p12 file'} $Lang ::tr{'pkcs12 file password'}:<input type='password' name='P12_PASS'/></td></tr>
1999 <tr><td><input type='radio' name='AUTH' value='auth-dn' $checked {'AUTH'}{'auth-dn'} $cacrtdisabled /></td>
2000 <td class='base'><hr /> $Lang ::tr{'vpn auth-dn'}</td></tr>
2001 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2002 <tr><td><input type='radio' name='AUTH' value='certgen' $checked {'AUTH'}{'certgen'} $cakeydisabled /></td>
2003 <td class='base'><hr /> $Lang ::tr{'generate a certificate'}</td><td> </td></tr>
2005 <td class='base'> $Lang ::tr{'users fullname or system hostname'}:</td>
2006 <td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' size='32' $cakeydisabled /></td></tr>
2008 <td class='base'> $Lang ::tr{'users email'}: <img src='/blob.gif' alt='*' /></td>
2009 <td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' size='32' $cakeydisabled /></td></tr>
2011 <td class='base'> $Lang ::tr{'users department'}: <img src='/blob.gif' alt='*' /></td>
2012 <td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' size='32' $cakeydisabled /></td></tr>
2014 <td class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
2015 <td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' size='32' $cakeydisabled /></td></tr>
2017 <td class='base'> $Lang ::tr{'city'}: <img src='/blob.gif' alt='*' /></td>
2018 <td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' size='32' $cakeydisabled /></td></tr>
2020 <td class='base'> $Lang ::tr{'state or province'}: <img src='/blob.gif' alt='*' /></td>
2021 <td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' size='32' $cakeydisabled /></td></tr>
2023 <td class='base'> $Lang ::tr{'country'}:</td>
2024 <td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
2027 foreach my $country ( sort keys %{ Countries
:: countries
}) {
2028 print " \t\t\t <option value=' $Countries ::countries{ $country }'" ;
2029 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
2030 print " selected='selected'" ;
2032 print "> $country </option> \n " ;
2037 <tr><td> </td><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)<img src='/blob.gif' alt='*' /></td>
2038 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' $cakeydisabled /></td></tr>
2040 <td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
2041 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
2042 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'}:( $Lang ::tr{'confirmation'})</td>
2043 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
2047 & Header
:: closebox
();
2050 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
2051 if ( $cgiparams { 'KEY' }) {
2052 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced'}' />" ;
2054 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
2055 & Header
:: closebigbox
();
2056 & Header
:: closepage
();
2063 ### Advanced settings
2065 if (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced' }) ||
2066 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq 'yes' )) {
2067 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
2068 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2069 if (! $confighash { $cgiparams { 'KEY' }}) {
2070 $errormessage = $Lang :: tr
{ 'invalid key' };
2074 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
2075 # I didn't read any incompatibilities here....
2076 #if ($cgiparams{'VHOST'} eq 'on' && $cgiparams{'COMPRESSION'} eq 'on') {
2077 # $errormessage = $Lang::tr{'cannot enable both nat traversal and compression'};
2078 # goto ADVANCED_ERROR;
2080 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2082 $errormessage = $Lang :: tr
{ 'invalid input' };
2083 goto ADVANCED_ERROR
;
2085 foreach my $val ( @temp ) {
2086 if ( $val !~ /^(aes256|aes128|3des)$/ ) {
2087 $errormessage = $Lang :: tr
{ 'invalid input' };
2088 goto ADVANCED_ERROR
;
2091 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2093 $errormessage = $Lang :: tr
{ 'invalid input' };
2094 goto ADVANCED_ERROR
;
2096 foreach my $val ( @temp ) {
2097 if ( $val !~ /^(sha2_512|sha2_384|sha2_256|sha|md5|aesxcbc)$/ ) {
2098 $errormessage = $Lang :: tr
{ 'invalid input' };
2099 goto ADVANCED_ERROR
;
2102 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2104 $errormessage = $Lang :: tr
{ 'invalid input' };
2105 goto ADVANCED_ERROR
;
2107 foreach my $val ( @temp ) {
2108 if ( $val !~ /^(1024|1536|2048|3072|4096|6144|8192)$/ ) {
2109 $errormessage = $Lang :: tr
{ 'invalid input' };
2110 goto ADVANCED_ERROR
;
2113 if ( $cgiparams { 'IKE_LIFETIME' } !~ /^\d+$/ ) {
2114 $errormessage = $Lang :: tr
{ 'invalid input for ike lifetime' };
2115 goto ADVANCED_ERROR
;
2117 if ( $cgiparams { 'IKE_LIFETIME' } < 1 || $cgiparams { 'IKE_LIFETIME' } > 8 ) {
2118 $errormessage = $Lang :: tr
{ 'ike lifetime should be between 1 and 8 hours' };
2119 goto ADVANCED_ERROR
;
2121 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2123 $errormessage = $Lang :: tr
{ 'invalid input' };
2124 goto ADVANCED_ERROR
;
2126 foreach my $val ( @temp ) {
2127 if ( $val !~ /^(aes256|aes192|aes128|3des)$/ ) {
2128 $errormessage = $Lang :: tr
{ 'invalid input' };
2129 goto ADVANCED_ERROR
;
2132 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2134 $errormessage = $Lang :: tr
{ 'invalid input' };
2135 goto ADVANCED_ERROR
;
2137 foreach my $val ( @temp ) {
2138 if ( $val !~ /^(sha2_512|sha2_384|sha2_256|sha1|md5|aesxcbc)$/ ) {
2139 $errormessage = $Lang :: tr
{ 'invalid input' };
2140 goto ADVANCED_ERROR
;
2143 if ( $cgiparams { 'ESP_GROUPTYPE' } ne '' &&
2144 $cgiparams { 'ESP_GROUPTYPE' } !~ /^modp(1024|1536|2048|3072|4096|6144|8192)$/ ) {
2145 $errormessage = $Lang :: tr
{ 'invalid input' };
2146 goto ADVANCED_ERROR
;
2149 if ( $cgiparams { 'ESP_KEYLIFE' } !~ /^\d+$/ ) {
2150 $errormessage = $Lang :: tr
{ 'invalid input for esp keylife' };
2151 goto ADVANCED_ERROR
;
2153 if ( $cgiparams { 'ESP_KEYLIFE' } < 1 || $cgiparams { 'ESP_KEYLIFE' } > 24 ) {
2154 $errormessage = $Lang :: tr
{ 'esp keylife should be between 1 and 24 hours' };
2155 goto ADVANCED_ERROR
;
2159 ( $cgiparams { 'COMPRESSION' } !~ /^(|on|off)$/ ) ||
2160 ( $cgiparams { 'ONLY_PROPOSED' } !~ /^(|on|off)$/ ) ||
2161 ( $cgiparams { 'PFS' } !~ /^(|on|off)$/ ) ||
2162 ( $cgiparams { 'VHOST' } !~ /^(|on|off)$/ )
2164 $errormessage = $Lang :: tr
{ 'invalid input' };
2165 goto ADVANCED_ERROR
;
2168 $confighash { $cgiparams { 'KEY' }}[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
2169 $confighash { $cgiparams { 'KEY' }}[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
2170 $confighash { $cgiparams { 'KEY' }}[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
2171 $confighash { $cgiparams { 'KEY' }}[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
2172 $confighash { $cgiparams { 'KEY' }}[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
2173 $confighash { $cgiparams { 'KEY' }}[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
2174 $confighash { $cgiparams { 'KEY' }}[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
2175 $confighash { $cgiparams { 'KEY' }}[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
2176 $confighash { $cgiparams { 'KEY' }}[ 12 ] = 'off' ; #$cgiparams{'AGGRMODE'};
2177 $confighash { $cgiparams { 'KEY' }}[ 13 ] = $cgiparams { 'COMPRESSION' };
2178 $confighash { $cgiparams { 'KEY' }}[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
2179 $confighash { $cgiparams { 'KEY' }}[ 28 ] = $cgiparams { 'PFS' };
2180 $confighash { $cgiparams { 'KEY' }}[ 14 ] = $cgiparams { 'VHOST' };
2181 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2184 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
2189 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
2190 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
2191 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
2192 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
2193 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
2194 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
2195 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
2196 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
2197 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
2198 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
2199 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
2200 $cgiparams { 'VHOST' } = $confighash { $cgiparams { 'KEY' }}[ 14 ];
2202 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' || $confighash { $cgiparams { 'KEY' }}[ 10 ]) {
2203 $cgiparams { 'VHOST' } = 'off' ;
2208 $checked { 'IKE_ENCRYPTION' }{ 'aes256' } = '' ;
2209 $checked { 'IKE_ENCRYPTION' }{ 'aes192' } = '' ;
2210 $checked { 'IKE_ENCRYPTION' }{ 'aes128' } = '' ;
2211 $checked { 'IKE_ENCRYPTION' }{ '3des' } = '' ;
2212 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2213 foreach my $key ( @temp ) { $checked { 'IKE_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2214 $checked { 'IKE_INTEGRITY' }{ 'sha2_512' } = '' ;
2215 $checked { 'IKE_INTEGRITY' }{ 'sha2_384' } = '' ;
2216 $checked { 'IKE_INTEGRITY' }{ 'sha2_256' } = '' ;
2217 $checked { 'IKE_INTEGRITY' }{ 'sha' } = '' ;
2218 $checked { 'IKE_INTEGRITY' }{ 'md5' } = '' ;
2219 $checked { 'IKE_INTEGRITY' }{ 'aesxcbc' } = '' ;
2220 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2221 foreach my $key ( @temp ) { $checked { 'IKE_INTEGRITY' }{ $key } = "selected='selected'" ; }
2222 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2223 $checked { 'IKE_GROUPTYPE' }{ '1024' } = '' ;
2224 $checked { 'IKE_GROUPTYPE' }{ '1536' } = '' ;
2225 $checked { 'IKE_GROUPTYPE' }{ '2048' } = '' ;
2226 $checked { 'IKE_GROUPTYPE' }{ '3072' } = '' ;
2227 $checked { 'IKE_GROUPTYPE' }{ '4096' } = '' ;
2228 $checked { 'IKE_GROUPTYPE' }{ '6144' } = '' ;
2229 $checked { 'IKE_GROUPTYPE' }{ '8192' } = '' ;
2230 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2231 foreach my $key ( @temp ) { $checked { 'IKE_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2233 # 768 is not supported by strongswan
2234 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2236 $checked { 'ESP_ENCRYPTION' }{ 'aes256' } = '' ;
2237 $checked { 'ESP_ENCRYPTION' }{ 'aes192' } = '' ;
2238 $checked { 'ESP_ENCRYPTION' }{ 'aes128' } = '' ;
2239 $checked { 'ESP_ENCRYPTION' }{ '3des' } = '' ;
2240 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2241 foreach my $key ( @temp ) { $checked { 'ESP_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2242 $checked { 'ESP_INTEGRITY' }{ 'sha2_512' } = '' ;
2243 $checked { 'ESP_INTEGRITY' }{ 'sha2_384' } = '' ;
2244 $checked { 'ESP_INTEGRITY' }{ 'sha2_256' } = '' ;
2245 $checked { 'ESP_INTEGRITY' }{ 'sha1' } = '' ;
2246 $checked { 'ESP_INTEGRITY' }{ 'md5' } = '' ;
2247 $checked { 'ESP_INTEGRITY' }{ 'aesxcbc' } = '' ;
2248 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2249 foreach my $key ( @temp ) { $checked { 'ESP_INTEGRITY' }{ $key } = "selected='selected'" ; }
2250 $checked { 'ESP_GROUPTYPE' }{ $cgiparams { 'ESP_GROUPTYPE' }} = "selected='selected'" ;
2252 $checked { 'COMPRESSION' } = $cgiparams { 'COMPRESSION' } eq 'on' ?
"checked='checked'" : '' ;
2253 $checked { 'ONLY_PROPOSED' } = $cgiparams { 'ONLY_PROPOSED' } eq 'on' ?
"checked='checked'" : '' ;
2254 $checked { 'PFS' } = $cgiparams { 'PFS' } eq 'on' ?
"checked='checked'" : '' ;
2255 $checked { 'VHOST' } = $cgiparams { 'VHOST' } eq 'on' ?
"checked='checked'" : '' ;
2257 & Header
:: showhttpheaders
();
2258 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
2259 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2261 if ( $errormessage ) {
2262 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2263 print "<class name='base'> $errormessage " ;
2264 print " </class>" ;
2265 & Header
:: closebox
();
2269 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
2270 print "<class name='base'> $warnmessage " ;
2271 print " </class>" ;
2272 & Header
:: closebox
();
2275 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'advanced'}:" );
2277 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
2278 <input type='hidden' name='ADVANCED' value='yes' />
2279 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
2281 <table width='100%'>
2282 <tr><td class='boldbase' align='right' valign='top'> $Lang ::tr{'ike encryption'}</td><td class='boldbase' valign='top'>
2283 <select name='IKE_ENCRYPTION' multiple='multiple' size='4'>
2284 <option value='aes256' $checked {'IKE_ENCRYPTION'}{'aes256'}>AES (256 bit)</option>
2285 <option value='aes192' $checked {'IKE_ENCRYPTION'}{'aes192'}>AES (192 bit)</option>
2286 <option value='aes128' $checked {'IKE_ENCRYPTION'}{'aes128'}>AES (128 bit)</option>
2287 <option value='3des' $checked {'IKE_ENCRYPTION'}{'3des'}>3DES</option>
2290 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'ike integrity'}</td><td class='boldbase' valign='top'>
2291 <select name='IKE_INTEGRITY' multiple='multiple' size='4'>
2292 <option value='sha2_512' $checked {'IKE_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2293 <option value='sha2_384' $checked {'IKE_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2294 <option value='sha2_256' $checked {'IKE_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2295 <option value='sha' $checked {'IKE_INTEGRITY'}{'sha'}>SHA1</option>
2296 <option value='md5' $checked {'IKE_INTEGRITY'}{'md5'}>MD5</option>
2297 <option value='aesxcbc' $checked {'IKE_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2300 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'ike grouptype'}</td><td class='boldbase' valign='top'>
2301 <select name='IKE_GROUPTYPE' multiple='multiple' size='4'>
2302 <option value='8192' $checked {'IKE_GROUPTYPE'}{'8192'}>MODP-8192</option>
2303 <option value='6144' $checked {'IKE_GROUPTYPE'}{'6144'}>MODP-6144</option>
2304 <option value='4096' $checked {'IKE_GROUPTYPE'}{'4096'}>MODP-4096</option>
2305 <option value='3072' $checked {'IKE_GROUPTYPE'}{'3072'}>MODP-3072</option>
2306 <option value='2048' $checked {'IKE_GROUPTYPE'}{'2048'}>MODP-2048</option>
2307 <option value='1536' $checked {'IKE_GROUPTYPE'}{'1536'}>MODP-1536</option>
2308 <option value='1024' $checked {'IKE_GROUPTYPE'}{'1024'}>MODP-1024</option>
2311 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'ike lifetime'}</td><td class='boldbase' valign='top'>
2312 <input type='text' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' size='5' /> $Lang ::tr{'hours'}</td>
2315 <td colspan='1'><hr /></td>
2317 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'esp encryption'}</td><td class='boldbase' valign='top'>
2318 <select name='ESP_ENCRYPTION' multiple='multiple' size='4'>
2319 <option value='aes256' $checked {'ESP_ENCRYPTION'}{'aes256'}>AES (256 bit)</option>
2320 <option value='aes192' $checked {'ESP_ENCRYPTION'}{'aes192'}>AES (192 bit)</option>
2321 <option value='aes128' $checked {'ESP_ENCRYPTION'}{'aes128'}>AES (128 bit)</option>
2322 <option value='3des' $checked {'ESP_ENCRYPTION'}{'3des'}>3DES</option>
2324 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'esp integrity'}</td><td class='boldbase' valign='top'>
2325 <select name='ESP_INTEGRITY' multiple='multiple' size='4'>
2326 <option value='sha2_512' $checked {'ESP_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2327 <option value='sha2_384' $checked {'ESP_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2328 <option value='sha2_256' $checked {'ESP_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2329 <option value='sha1' $checked {'ESP_INTEGRITY'}{'sha1'}>SHA1</option>
2330 <option value='md5' $checked {'ESP_INTEGRITY'}{'md5'}>MD5</option>
2331 <option value='aesxcbc' $checked {'ESP_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2334 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'esp grouptype'}</td><td class='boldbase' valign='top'>
2335 <select name='ESP_GROUPTYPE'>
2336 <option value=''> $Lang ::tr{'phase1 group'}</option></select></td>
2338 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'esp keylife'}</td><td class='boldbase' valign='top'>
2339 <input type='text' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' size='5' /> $Lang ::tr{'hours'}</td>
2341 <td colspan='1'><hr /></td>
2343 <td colspan='5'><input type='checkbox' name='ONLY_PROPOSED' $checked {'ONLY_PROPOSED'} />
2344 IKE+ESP: $Lang ::tr{'use only proposed settings'}</td>
2346 <td colspan='5'><input type='checkbox' name='PFS' $checked {'PFS'} />
2347 $Lang ::tr{'pfs yes no'}</td>
2348 <td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' /></td>
2350 <td colspan='5'><input type='checkbox' name='COMPRESSION' $checked {'COMPRESSION'} />
2351 $Lang ::tr{'vpn payload compression'}</td>
2352 <td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
2356 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ) {
2357 print "<tr><td><input type='hidden' name='VHOST' value='off' /></td></tr>" ;
2358 } elsif ( $confighash { $cgiparams { 'KEY' }}[ 10 ]) {
2359 print "<tr><td colspan='5'><input type='checkbox' name='VHOST' $checked {'VHOST'} disabled='disabled' />" ;
2360 print " $Lang ::tr{'vpn vhost'}</td></tr>" ;
2362 print "<tr><td colspan='5'><input type='checkbox' name='VHOST' $checked {'VHOST'} />" ;
2363 print " $Lang ::tr{'vpn vhost'}</td></tr>" ;
2366 print "</table></form>" ;
2367 & Header
:: closebox
();
2368 & Header
:: closebigbox
();
2369 & Header
:: closepage
();
2376 ### Default status page
2381 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%cgiparams );
2382 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
2383 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2384 $cgiparams { 'CA_NAME' } = '' ;
2386 my @status = `/usr/local/bin/ipsecctrl I 2>/dev/null` ;
2388 # suggest a default name for this side
2389 if ( $cgiparams { 'VPN_IP' } eq '' && - e
"${General::swroot}/red/active" ) {
2390 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
2391 my $ipaddr = < IPADDR
>;
2394 $cgiparams { 'VPN_IP' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
2395 if ( $cgiparams { 'VPN_IP' } eq '' ) {
2396 $cgiparams { 'VPN_IP' } = $ipaddr ;
2400 # no IP found, use %defaultroute
2401 $cgiparams { 'VPN_IP' } = ' %defaultroute ' if ( $cgiparams { 'VPN_IP' } eq '' );
2403 $cgiparams { 'VPN_DELAYED_START' } = 0 if (! defined ( $cgiparams { 'VPN_DELAYED_START' }));
2404 $checked { 'ENABLED' } = $cgiparams { 'ENABLED' } eq 'on' ?
"checked='checked'" : '' ;
2406 & Header
:: showhttpheaders
();
2407 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
2408 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2410 if ( $errormessage ) {
2411 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2412 print "<class name='base'> $errormessage \n " ;
2413 print " </class> \n " ;
2414 & Header
:: closebox
();
2417 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'global settings' });
2419 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2420 <table width='100%'>
2422 <td width='20%' class='base' nowrap='nowrap'> $Lang ::tr{'vpn red name'}:</td>
2423 <td width='20%'><input type='text' name='VPN_IP' value=' $cgiparams {'VPN_IP'}' /></td>
2424 <td width='20%' class='base'> $Lang ::tr{'enabled'}<input type='checkbox' name='ENABLED' $checked {'ENABLED'} /></td>
2430 <td class='base' nowrap='nowrap'> $Lang ::tr{'vpn delayed start'}: <img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' /></td>
2431 <td ><input type='text' name='VPN_DELAYED_START' value=' $cgiparams {'VPN_DELAYED_START'}' /></td>
2434 <td class='base' nowrap='nowrap'> $Lang ::tr{'host to net vpn'}: <img src='/blob.gif' alt='*' /></td>
2435 <td ><input type='text' name='RW_NET' value=' $cgiparams {'RW_NET'}' /></td>
2439 <table width='100%'>
2441 <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
2442 <td width='70%' class='base' valign='top'> $Lang ::tr{'this field may be blank'}</td>
2445 <td class='base' valign='top' nowrap='nowrap'><img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' /> </td>
2446 <td class='base'> <font class='base'> $Lang ::tr{'vpn delayed start help'}</font></td>
2447 <td width='30%' align='center' class='base'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' /></td>
2453 & Header
:: closebox
();
2455 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection status and controlc' });
2457 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
2459 <td width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></td>
2460 <td width='22%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></td>
2461 <td width='23%' class='boldbase' align='center'><b> $Lang ::tr{'common name'}</b></td>
2462 <td width='30%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></td>
2463 <td width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></td>
2464 <td class='boldbase' align='center' colspan='6'><b> $Lang ::tr{'action'}</b></td>
2470 foreach my $key ( keys %confighash ) {
2471 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
2474 print "<tr bgcolor=' $color {'color20'}'> \n " ;
2476 print "<tr bgcolor=' $color {'color22'}'> \n " ;
2478 print "<td align='center' nowrap='nowrap'> $confighash { $key }[1]</td>" ;
2479 print "<td align='center' nowrap='nowrap'>" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ") $confighash { $key }[29]</td>" ;
2480 if ( $confighash { $key }[ 2 ] eq ' %auth -dn' ) {
2481 print "<td align='left' nowrap='nowrap'> $confighash { $key }[9]</td>" ;
2482 } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
2483 print "<td align='left' nowrap='nowrap'> $confighash { $key }[2]</td>" ;
2485 print "<td align='left'> </td>" ;
2487 print "<td align='center'> $confighash { $key }[25]</td>" ;
2489 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>" ;
2490 foreach my $line ( @status ) {
2491 if (( $line =~ /\"$confighash{$key}[1]\".*IPsec SA established/ ) ||
2492 ( $line =~ /$confighash{$key}[1]\{.*INSTALLED/ ))
2494 $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>" ;
2497 # move to blueif really down
2498 if ( $confighash { $key }[ 0 ] eq 'off' && $active =~ /${Header::colourred}/ ) {
2499 $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>" ;
2502 <td align='center'> $active </td>
2504 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2505 <input type='image' name=' $Lang ::tr{'restart'}' src='/images/reload.gif' alt=' $Lang ::tr{'restart'}' title=' $Lang ::tr{'restart'}' />
2506 <input type='hidden' name='ACTION' value=' $Lang ::tr{'restart'}' />
2507 <input type='hidden' name='KEY' value=' $key ' />
2512 if (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
2515 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2516 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' />
2517 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
2518 <input type='hidden' name='KEY' value=' $key ' />
2523 print "<td width='2%'> </td>" ;
2525 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/certs/ $confighash { $key }[1].p12" ) {
2528 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2529 <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'}' />
2530 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
2531 <input type='hidden' name='KEY' value=' $key ' />
2535 ; } elsif (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
2538 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2539 <input type='image' name=' $Lang ::tr{'download certificate'}' src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' title=' $Lang ::tr{'download certificate'}' />
2540 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
2541 <input type='hidden' name='KEY' value=' $key ' />
2546 print "<td width='2%'> </td>" ;
2550 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2551 <input type='image' name=' $Lang ::tr{'toggle enable disable'}' src='/images/ $gif ' alt=' $Lang ::tr{'toggle enable disable'}' title=' $Lang ::tr{'toggle enable disable'}' />
2552 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
2553 <input type='hidden' name='KEY' value=' $key ' />
2558 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2559 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
2560 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' title=' $Lang ::tr{'edit'}' />
2561 <input type='hidden' name='KEY' value=' $key ' />
2564 <td align='center' >
2565 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2566 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
2567 <input type='image' name=' $Lang ::tr{'remove'}' src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' title=' $Lang ::tr{'remove'}' />
2568 <input type='hidden' name='KEY' value=' $key ' />
2578 # If the config file contains entries, print Key to action icons
2583 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
2584 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
2585 <td class='base'> $Lang ::tr{'click to disable'}</td>
2586 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
2587 <td class='base'> $Lang ::tr{'show certificate'}</td>
2588 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
2589 <td class='base'> $Lang ::tr{'edit'}</td>
2590 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
2591 <td class='base'> $Lang ::tr{'remove'}</td>
2595 <td> <img src='/images/off.gif' alt='?OFF' /></td>
2596 <td class='base'> $Lang ::tr{'click to enable'}</td>
2597 <td> <img src='/images/floppy.gif' alt='?FLOPPY' /></td>
2598 <td class='base'> $Lang ::tr{'download certificate'}</td>
2599 <td> <img src='/images/reload.gif' alt='?RELOAD'/></td>
2600 <td class='base'> $Lang ::tr{'restart'}</td>
2608 <table width='100%'>
2609 <tr><td align='center' colspan='9'>
2610 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2611 <input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />
2617 & Header
:: closebox
();
2619 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'certificate authorities'}:" );
2621 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
2623 <td width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></td>
2624 <td width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></td>
2625 <td width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></td>
2629 if (- f
"${General::swroot}/ca/cacert.pem" ) {
2630 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/cacert.pem" ));
2633 <tr bgcolor=' $color {'color22'}'>
2634 <td class='base'> $Lang ::tr{'root certificate'}</td>
2635 <td class='base'> $casubject </td>
2636 <td width='3%' align='center'>
2637 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2638 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
2639 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/info.gif' alt=' $Lang ::tr{'show root certificate'}' title=' $Lang ::tr{'show root certificate'}' />
2642 <td width='3%' align='center'>
2643 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2644 <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'}' />
2645 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
2648 <td width='4%'> </td></tr>
2652 # display rootcert generation buttons
2654 <tr bgcolor=' $color {'color22'}'>
2655 <td class='base'> $Lang ::tr{'root certificate'}:</td>
2656 <td class='base'> $Lang ::tr{'not present'}</td>
2657 <td colspan='3'> </td></tr>
2662 if (- f
"${General::swroot}/certs/hostcert.pem" ) {
2663 my $hostsubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/certs/hostcert.pem" ));
2666 <tr bgcolor=' $color {'color20'}'>
2667 <td class='base'> $Lang ::tr{'host certificate'}</td>
2668 <td class='base'> $hostsubject </td>
2669 <td width='3%' align='center'>
2670 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2671 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
2672 <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'}' />
2675 <td width='3%' align='center'>
2676 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2677 <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'}' />
2678 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download host certificate'}' />
2681 <td width='4%'> </td></tr>
2687 <tr bgcolor=' $color {'color20'}'>
2688 <td width='25%' class='base'> $Lang ::tr{'host certificate'}:</td>
2689 <td class='base'> $Lang ::tr{'not present'}</td>
2690 <td colspan='3'> </td></tr>
2696 if ( keys %cahash > 0 ) {
2697 foreach my $key ( keys %cahash ) {
2698 if ( $rowcolor ++ % 2 ) {
2699 print "<tr bgcolor=' $color {'color20'}'> \n " ;
2701 print "<tr bgcolor=' $color {'color22'}'> \n " ;
2703 print "<td class='base'> $cahash { $key }[0]</td> \n " ;
2704 print "<td class='base'> $cahash { $key }[1]</td> \n " ;
2707 <form method='post' name='cafrm${key}a' action=' $ENV {'SCRIPT_NAME'}'>
2708 <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'}' />
2709 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
2710 <input type='hidden' name='KEY' value=' $key ' />
2714 <form method='post' name='cafrm${key}b' action=' $ENV {'SCRIPT_NAME'}'>
2715 <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'}' />
2716 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
2717 <input type='hidden' name='KEY' value=' $key ' />
2721 <form method='post' name='cafrm${key}c' action=' $ENV {'SCRIPT_NAME'}'>
2722 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
2723 <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'}' />
2724 <input type='hidden' name='KEY' value=' $key ' />
2734 # If the file contains entries, print Key to action icons
2735 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
2738 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
2739 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
2740 <td class='base'> $Lang ::tr{'show certificate'}</td>
2741 <td> <img src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' /></td>
2742 <td class='base'> $Lang ::tr{'download certificate'}</td>
2747 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>" ;
2750 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
2751 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
2754 <td class='base' nowrap='nowrap'> $Lang ::tr{'ca name'}:</td>
2755 <td nowrap='nowrap'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' /> </td>
2756 <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td>
2757 <td nowrap='nowrap'><input type='submit' name='ACTION' value=' $Lang ::tr{'upload ca certificate'}' /></td>
2760 <td colspan='3'> $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}:</td>
2761 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' /></td>
2767 & Header
:: closebox
();
2768 & Header
:: closebigbox
();
2769 & Header
:: closepage
();