]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/vpnmain.cgi
e71786243dc573a2b8fa8ed832b13d1023ca08e4
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2013 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 (let the ipsec do its job)
52 my $errormessage = '' ;
55 my %mainsettings = ();
56 & General
:: readhash
( "${General::swroot}/main/settings" , \
%mainsettings );
57 & General
:: readhash
( "/srv/web/ipfire/html/themes/" . $mainsettings { 'THEME' }. "/include/colors.txt" , \
%color );
59 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%netsettings );
61 my $green_cidr = & General
:: ipcidr
( " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" );
62 my $blue_cidr = "# Blue not defined" ;
63 if (& Header
:: blue_used
() && $netsettings { 'BLUE_DEV' }) {
64 $blue_cidr = & General
:: ipcidr
( " $netsettings {'BLUE_NETADDRESS'}/ $netsettings {'BLUE_NETMASK'}" );
66 my $orange_cidr = "# Orange not defined" ;
67 if (& Header
:: orange_used
() && $netsettings { 'ORANGE_DEV' }) {
68 $orange_cidr = & General
:: ipcidr
( " $netsettings {'ORANGE_NETADDRESS'}/ $netsettings {'ORANGE_NETMASK'}" );
73 $cgiparams { 'ENABLED' } = 'off' ;
74 $cgiparams { 'EDIT_ADVANCED' } = 'off' ;
75 $cgiparams { 'ACTION' } = '' ;
76 $cgiparams { 'CA_NAME' } = '' ;
77 $cgiparams { 'KEY' } = '' ;
78 $cgiparams { 'TYPE' } = '' ;
79 $cgiparams { 'ADVANCED' } = '' ;
80 $cgiparams { 'NAME' } = '' ;
81 $cgiparams { 'LOCAL_SUBNET' } = '' ;
82 $cgiparams { 'REMOTE_SUBNET' } = '' ;
83 $cgiparams { 'REMOTE' } = '' ;
84 $cgiparams { 'LOCAL_ID' } = '' ;
85 $cgiparams { 'REMOTE_ID' } = '' ;
86 $cgiparams { 'REMARK' } = '' ;
87 $cgiparams { 'PSK' } = '' ;
88 $cgiparams { 'CERT_NAME' } = '' ;
89 $cgiparams { 'CERT_EMAIL' } = '' ;
90 $cgiparams { 'CERT_OU' } = '' ;
91 $cgiparams { 'CERT_ORGANIZATION' } = '' ;
92 $cgiparams { 'CERT_CITY' } = '' ;
93 $cgiparams { 'CERT_STATE' } = '' ;
94 $cgiparams { 'CERT_COUNTRY' } = '' ;
95 $cgiparams { 'SUBJECTALTNAME' } = '' ;
96 $cgiparams { 'CERT_PASS1' } = '' ;
97 $cgiparams { 'CERT_PASS2' } = '' ;
98 $cgiparams { 'ROOTCERT_HOSTNAME' } = '' ;
99 $cgiparams { 'ROOTCERT_COUNTRY' } = '' ;
100 $cgiparams { 'P12_PASS' } = '' ;
101 $cgiparams { 'ROOTCERT_ORGANIZATION' } = '' ;
102 $cgiparams { 'ROOTCERT_HOSTNAME' } = '' ;
103 $cgiparams { 'ROOTCERT_EMAIL' } = '' ;
104 $cgiparams { 'ROOTCERT_OU' } = '' ;
105 $cgiparams { 'ROOTCERT_CITY' } = '' ;
106 $cgiparams { 'ROOTCERT_STATE' } = '' ;
107 $cgiparams { 'RW_NET' } = '' ;
108 $cgiparams { 'DPD_DELAY' } = '30' ;
109 $cgiparams { 'DPD_TIMEOUT' } = '120' ;
110 $cgiparams { 'FORCE_MOBIKE' } = 'off' ;
111 & Header
:: getcgihash
( \
%cgiparams , { 'wantfile' => 1 , 'filevar' => 'FH' });
117 my $hostname = $_ [ 0 ];
118 unless ( $hostname ) { return "No hostname" };
119 my $res = new Net
:: DNS
:: Resolver
;
120 my $query = $res -> search ( " $hostname " );
122 foreach my $rr ( $query -> answer ) {
123 ## Potential bug - we are only looking at A records:
124 return 0 if $rr -> type eq "A" ;
127 return $res -> errorstring ;
131 ### Just return true is one interface is vpn enabled
134 return ( $vpnsettings { 'ENABLED' } eq 'on' );
137 ### old version: maintain serial number to one, without explication.
138 ### this: let the counter go, so that each cert is numbered.
140 sub cleanssldatabase
{
141 if ( open ( FILE
, ">${General::swroot}/certs/serial" )) {
145 if ( open ( FILE
, ">${General::swroot}/certs/index.txt" )) {
149 unlink ( "${General::swroot}/certs/index.txt.old" );
150 unlink ( "${General::swroot}/certs/serial.old" );
151 unlink ( "${General::swroot}/certs/01.pem" );
153 sub newcleanssldatabase
{
154 if (! - s
"${General::swroot}/certs/serial" ) {
155 open ( FILE
, ">${General::swroot}/certs/serial" );
159 if (! - s
">${General::swroot}/certs/index.txt" ) {
160 system ( "touch ${General::swroot}/certs/index.txt" );
162 unlink ( "${General::swroot}/certs/index.txt.old" );
163 unlink ( "${General::swroot}/certs/serial.old" );
164 # unlink ("${General::swroot}/certs/01.pem"); numbering evolves. Wrong place to delete
168 ### Call openssl and return errormessage if any
172 my $retssl = `/usr/bin/openssl $opt 2>&1` ; #redirect stderr
174 foreach my $line ( split ( /\n/ , $retssl )) {
175 & General
:: log ( "ipsec" , " $line " ) if ( 0 ); # 1 for verbose logging
176 $ret .= '<br>' . $line if ( $line =~ /error|unknown/ );
179 $ret = & Header
:: cleanhtml
( $ret );
181 return $ret ?
" $Lang ::tr{'openssl produced an error'}: $ret " : '' ;
184 ### Obtain a CN from given cert
186 sub getCNfromcert
($) {
187 #&General::log("ipsec", "Extracting name from $_[0]...");
188 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
189 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
191 $temp =~ s
+/ Email
+, E
+;
192 $temp =~ s/ ST=/ S=/ ;
198 ### Obtain Subject from given cert
200 sub getsubjectfromcert
($) {
201 #&General::log("ipsec", "Extracting subject from $_[0]...");
202 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
203 $temp =~ /Subject: (.*)[\n]/ ;
205 $temp =~ s
+/ Email
+, E
+;
206 $temp =~ s/ ST=/ S=/ ;
210 ### Combine local subnet and connection name to make a unique name for each connection section
211 ### (this sub is not used now)
213 sub makeconnname
($) {
217 $subnet =~ /^(.*?)\/ (.* ?
)$/; # $1=IP $2=mask
218 my $ip = unpack ( 'N' , & Socket
:: inet_aton
( $1 ));
219 if ( length ( $2 ) > 2 ) {
220 my $mm = unpack ( 'N' , & Socket
:: inet_aton
( $2 ));
221 while ( ( $mm & 1 )== 0 ) {
228 return sprintf ( " %s - %X " , $conn , $ip );
231 ### Write a config file.
233 ###Type=Host : GUI can choose the interface used (RED,GREEN,BLUE) and
234 ### the side is always defined as 'left'.
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 if (- e
"/etc/ipsec.user.conf" ) {
254 print CONF
"include /etc/ipsec.user.conf \n " ;
258 print SECRETS
"include /etc/ipsec.user.secrets \n " ;
260 if (- f
"${General::swroot}/certs/hostkey.pem" ) {
261 print SECRETS
": RSA ${General::swroot}/certs/hostkey.pem \n "
263 my $last_secrets = '' ; # old the less specifics connections
265 foreach my $key ( keys %lconfighash ) {
266 next if ( $lconfighash { $key }[ 0 ] ne 'on' );
268 #remote peer is not set? => use '%any'
269 $lconfighash { $key }[ 10 ] = ' %any ' if ( $lconfighash { $key }[ 10 ] eq '' );
272 if ( $lconfighash { $key }[ 26 ] eq 'BLUE' ) {
273 $localside = $netsettings { 'BLUE_ADDRESS' };
274 } elsif ( $lconfighash { $key }[ 26 ] eq 'GREEN' ) {
275 $localside = $netsettings { 'GREEN_ADDRESS' };
276 } elsif ( $lconfighash { $key }[ 26 ] eq 'ORANGE' ) {
277 $localside = $netsettings { 'ORANGE_ADDRESS' };
279 $localside = $lvpnsettings { 'VPN_IP' };
282 print CONF
"conn $lconfighash { $key }[1] \n " ;
283 print CONF
" \t left= $localside \n " ;
284 my $cidr_net =& General
:: ipcidr
( $lconfighash { $key }[ 8 ]);
285 print CONF
" \t leftsubnet= $cidr_net \n " ;
286 print CONF
" \t leftfirewall=yes \n " ;
287 print CONF
" \t lefthostaccess=yes \n " ;
288 print CONF
" \t right= $lconfighash { $key }[10] \n " ;
290 if ( $lconfighash { $key }[ 3 ] eq 'net' ) {
291 my $cidr_net =& General
:: ipcidr
( $lconfighash { $key }[ 11 ]);
292 print CONF
" \t rightsubnet= $cidr_net \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 ]) {
310 my @encs = split ( '\|' , $lconfighash { $key }[ 18 ]);
311 my @ints = split ( '\|' , $lconfighash { $key }[ 19 ]);
312 my @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
314 my @algos = & make_algos
( "ike" , \
@encs , \
@ints , \
@groups , 1 );
315 print CONF
" \t ike=" . join ( "," , @algos );
317 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
324 if ( $lconfighash { $key }[ 21 ] && $lconfighash { $key }[ 22 ]) {
325 my @encs = split ( '\|' , $lconfighash { $key }[ 21 ]);
326 my @ints = split ( '\|' , $lconfighash { $key }[ 22 ]);
327 my @groups = split ( '\|' , $lconfighash { $key }[ 23 ]);
329 # Use IKE grouptype if no ESP group type has been selected
330 # (for backwards compatibility)
331 if ( $lconfighash { $key }[ 23 ] eq "" ) {
332 @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
335 my @algos = & make_algos
( "esp" , \
@encs , \
@ints , \
@groups , ( $pfs eq "on" ));
336 print CONF
" \t esp=" . join ( "," , @algos );
338 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
346 if (! $lconfighash { $key }[ 29 ]) {
347 $lconfighash { $key }[ 29 ] = "ikev1" ;
350 print CONF
" \t keyexchange= $lconfighash { $key }[29] \n " ;
353 print CONF
" \t ikelifetime= $lconfighash { $key }[16]h \n " if ( $lconfighash { $key }[ 16 ]);
354 print CONF
" \t keylife= $lconfighash { $key }[17]h \n " if ( $lconfighash { $key }[ 17 ]);
357 print CONF
" \t compress=yes \n " if ( $lconfighash { $key }[ 13 ] eq 'on' );
360 if (( $lconfighash { $key }[ 29 ] eq "ikev2" ) && ( $lconfighash { $key }[ 32 ] eq 'on' )) {
361 print CONF
" \t mobike=yes \n " ;
364 # Dead Peer Detection
365 my $dpdaction = $lconfighash { $key }[ 27 ];
366 print CONF
" \t dpdaction= $dpdaction \n " ;
368 # If the dead peer detection is disabled and IKEv2 is used,
369 # dpddelay must be set to zero, too.
370 if ( $dpdaction eq "none" ) {
371 if ( $lconfighash { $key }[ 29 ] eq "ikev2" ) {
372 print CONF
" \t dpddelay=0 \n " ;
375 my $dpddelay = $lconfighash { $key }[ 31 ];
379 print CONF
" \t dpddelay= $dpddelay \n " ;
380 my $dpdtimeout = $lconfighash { $key }[ 30 ];
384 print CONF
" \t dpdtimeout= $dpdtimeout \n " ;
387 # Build Authentication details: LEFTid RIGHTid : PSK psk
389 if ( $lconfighash { $key }[ 4 ] eq 'psk' ) {
390 $psk_line = ( $lconfighash { $key }[ 7 ] ?
$lconfighash { $key }[ 7 ] : $localside ) . " " ;
391 $psk_line .= $lconfighash { $key }[ 9 ] ?
$lconfighash { $key }[ 9 ] : $lconfighash { $key }[ 10 ]; #remoteid or remote address?
392 $psk_line .= " : PSK ' $lconfighash { $key }[5]' \n " ;
393 # if the line contains %any, it is less specific than two IP or ID, so move it at end of file.
394 if ( $psk_line =~ /%any/ ) {
395 $last_secrets .= $psk_line ;
397 print SECRETS
$psk_line ;
399 print CONF
" \t authby=secret \n " ;
401 print CONF
" \t authby=rsasig \n " ;
402 print CONF
" \t leftrsasigkey= %cert \n " ;
403 print CONF
" \t rightrsasigkey= %cert \n " ;
406 # Automatically start only if a net-to-net connection
407 if ( $lconfighash { $key }[ 3 ] eq 'host' ) {
408 print CONF
" \t auto=add \n " ;
409 print CONF
" \t rightsourceip= $lvpnsettings {'RW_NET'} \n " ;
411 print CONF
" \t auto=start \n " ;
415 print CONF
" \t fragmentation=yes \n " ;
420 # Add post user includes to config file
421 # After the GUI-connections allows to patch connections.
422 if (- e
"/etc/ipsec.user-post.conf" ) {
423 print CONF
"include /etc/ipsec.user-post.conf \n " ;
427 print SECRETS
$last_secrets if ( $last_secrets );
432 # Hook to regenerate the configuration files.
433 if ( $ENV { "REMOTE_ADDR" } eq "" ) {
439 ### Save main settings
441 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
442 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
444 unless (& General
:: validfqdn
( $cgiparams { 'VPN_IP' }) || & General
:: validip
( $cgiparams { 'VPN_IP' })
445 || $cgiparams { 'VPN_IP' } eq ' %defaultroute ' ) {
446 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
450 unless ( $cgiparams { 'VPN_DELAYED_START' } =~ /^[0-9]{1,3}$/ ) { #allow 0-999 seconds !
451 $errormessage = $Lang :: tr
{ 'invalid time period' };
455 if ( $cgiparams { 'RW_NET' } ne '' and !& General
:: validipandmask
( $cgiparams { 'RW_NET' }) ) {
456 $errormessage = $Lang :: tr
{ 'urlfilter invalid ip or mask error' };
460 $vpnsettings { 'ENABLED' } = $cgiparams { 'ENABLED' };
461 $vpnsettings { 'VPN_IP' } = $cgiparams { 'VPN_IP' };
462 $vpnsettings { 'VPN_DELAYED_START' } = $cgiparams { 'VPN_DELAYED_START' };
463 $vpnsettings { 'RW_NET' } = $cgiparams { 'RW_NET' };
464 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
467 system ( '/usr/local/bin/ipsecctrl' , 'S' );
469 system ( '/usr/local/bin/ipsecctrl' , 'D' );
476 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
477 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
479 foreach my $key ( keys %confighash ) {
480 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
481 delete $confighash { $key };
484 while ( my $file = glob ( "${General::swroot}/{ca,certs,crls,private}/*" )) {
488 if ( open ( FILE
, ">${General::swroot}/vpn/caconfig" )) {
492 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
494 system ( '/usr/local/bin/ipsecctrl' , 'R' );
500 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' }) {
501 & Header
:: showhttpheaders
();
502 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
503 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
504 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
506 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
510 <input type='hidden' name='AREUSURE' value='yes' />
511 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>: $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}
515 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' />
516 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
523 & Header
:: closebigbox
();
524 & Header
:: closepage
();
528 ### Upload CA Certificate
530 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
531 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
533 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
534 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
538 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
539 $errormessage = $Lang :: tr
{ 'name too long' };
543 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
544 $errormessage = $Lang :: tr
{ 'name is invalid' };
545 goto UPLOAD_CA_ERROR
;
548 # Check if there is no other entry with this name
549 foreach my $key ( keys %cahash ) {
550 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
551 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
556 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
557 $errormessage = $Lang :: tr
{ 'there was no file upload' };
560 # Move uploaded ca to a temporary file
561 ( my $fh , my $filename ) = tempfile
( );
562 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
566 my $temp = `/usr/bin/openssl x509 -text -in $filename ` ;
567 if ( $temp !~ /CA:TRUE/i ) {
568 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
572 move
( $filename , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
574 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
580 my $key = & General
:: findhasharraykey
( \
%cahash );
581 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
582 $cahash { $key }[ 1 ] = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" ));
583 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
585 system ( '/usr/local/bin/ipsecctrl' , 'R' );
591 ### Display ca certificate
593 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
594 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
596 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
597 & Header
:: showhttpheaders
();
598 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
599 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
600 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'ca certificate'}:" );
601 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
602 $output = & Header
:: cleanhtml
( $output , "y" );
603 print "<pre> $output </pre> \n " ;
605 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
606 & Header
:: closebigbox
();
607 & Header
:: closepage
();
610 $errormessage = $Lang :: tr
{ 'invalid key' };
614 ### Export ca certificate to browser
616 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
617 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
619 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
620 print "Content-Type: application/force-download \n " ;
621 print "Content-Type: application/octet-stream \r\n " ;
622 print "Content-Disposition: attachment; filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
623 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
626 $errormessage = $Lang :: tr
{ 'invalid key' };
630 ### Remove ca certificate (step 2)
632 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
633 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
634 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
636 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
637 foreach my $key ( keys %confighash ) {
638 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
639 if ( $test =~ /: OK/ ) {
641 system ( '/usr/local/bin/ipsecctrl' , 'D' , $key ) if (& vpnenabled
);
642 unlink ( "${General::swroot}/certs/ $confighash { $key }[1]cert.pem" );
643 unlink ( "${General::swroot}/certs/ $confighash { $key }[1].p12" );
644 delete $confighash { $key };
645 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
649 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
650 delete $cahash { $cgiparams { 'KEY' }};
651 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
652 system ( '/usr/local/bin/ipsecctrl' , 'R' );
655 $errormessage = $Lang :: tr
{ 'invalid key' };
658 ### Remove ca certificate (step 1)
660 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
661 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
662 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
664 my $assignedcerts = 0 ;
665 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
666 foreach my $key ( keys %confighash ) {
667 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
668 if ( $test =~ /: OK/ ) {
672 if ( $assignedcerts ) {
673 & Header
:: showhttpheaders
();
674 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
675 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
676 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
678 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
682 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
683 <input type='hidden' name='AREUSURE' value='yes' /></td>
686 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b> $Lang ::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}</td>
689 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
690 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
697 & Header
:: closebigbox
();
698 & Header
:: closepage
();
701 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
702 delete $cahash { $cgiparams { 'KEY' }};
703 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
704 system ( '/usr/local/bin/ipsecctrl' , 'R' );
708 $errormessage = $Lang :: tr
{ 'invalid key' };
712 ### Display root certificate
714 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
715 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
717 & Header
:: showhttpheaders
();
718 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
719 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
720 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
721 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'root certificate'}:" );
722 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/cacert.pem` ;
724 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'host certificate'}:" );
725 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/hostcert.pem` ;
727 $output = & Header
:: cleanhtml
( $output , "y" );
728 print "<pre> $output </pre> \n " ;
730 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
731 & Header
:: closebigbox
();
732 & Header
:: closepage
();
736 ### Export root certificate to browser
738 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
739 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
740 print "Content-Type: application/force-download \n " ;
741 print "Content-Disposition: attachment; filename=cacert.pem \r\n\r\n " ;
742 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/cacert.pem` ;
746 ### Export host certificate to browser
748 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
749 if ( - f
"${General::swroot}/certs/hostcert.pem" ) {
750 print "Content-Type: application/force-download \n " ;
751 print "Content-Disposition: attachment; filename=hostcert.pem \r\n\r\n " ;
752 print `/usr/bin/openssl x509 -in ${General::swroot}/certs/hostcert.pem` ;
756 ### Form for generating/importing the caroot+host certificate
758 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
759 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
761 if (- f
"${General::swroot}/ca/cacert.pem" ) {
762 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
766 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
767 # fill in initial values
768 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
769 if (- e
"${General::swroot}/red/active" && open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
770 my $ipaddr = < IPADDR
>;
773 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
774 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
775 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
778 $cgiparams { 'ROOTCERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' } if (! $cgiparams { 'ROOTCERT_COUNTRY' });
779 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
780 & General
:: log ( "ipsec" , "Importing from p12..." );
782 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
783 $errormessage = $Lang :: tr
{ 'there was no file upload' };
787 # Move uploaded certificate request to a temporary file
788 ( my $fh , my $filename ) = tempfile
( );
789 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
794 # Extract the CA certificate from the file
795 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
796 if ( open ( STDIN
, "-|" )) {
797 my $opt = " pkcs12 -cacerts -nokeys" ;
798 $opt .= " -in $filename " ;
799 $opt .= " -out /tmp/newcacert" ;
800 $errormessage = & callssl
( $opt );
802 print " $cgiparams {'P12_PASS'} \n " ;
806 # Extract the Host certificate from the file
807 if (! $errormessage ) {
808 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
809 if ( open ( STDIN
, "-|" )) {
810 my $opt = " pkcs12 -clcerts -nokeys" ;
811 $opt .= " -in $filename " ;
812 $opt .= " -out /tmp/newhostcert" ;
813 $errormessage = & callssl
( $opt );
815 print " $cgiparams {'P12_PASS'} \n " ;
820 # Extract the Host key from the file
821 if (! $errormessage ) {
822 & General
:: log ( "ipsec" , "Extracting private key from p12..." );
823 if ( open ( STDIN
, "-|" )) {
824 my $opt = " pkcs12 -nocerts -nodes" ;
825 $opt .= " -in $filename " ;
826 $opt .= " -out /tmp/newhostkey" ;
827 $errormessage = & callssl
( $opt );
829 print " $cgiparams {'P12_PASS'} \n " ;
834 if (! $errormessage ) {
835 & General
:: log ( "ipsec" , "Moving cacert..." );
836 move
( "/tmp/newcacert" , "${General::swroot}/ca/cacert.pem" );
837 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
840 if (! $errormessage ) {
841 & General
:: log ( "ipsec" , "Moving host cert..." );
842 move
( "/tmp/newhostcert" , "${General::swroot}/certs/hostcert.pem" );
843 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
846 if (! $errormessage ) {
847 & General
:: log ( "ipsec" , "Moving private key..." );
848 move
( "/tmp/newhostkey" , "${General::swroot}/certs/hostkey.pem" );
849 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
854 unlink ( '/tmp/newcacert' );
855 unlink ( '/tmp/newhostcert' );
856 unlink ( '/tmp/newhostkey' );
858 unlink ( "${General::swroot}/ca/cacert.pem" );
859 unlink ( "${General::swroot}/certs/hostcert.pem" );
860 unlink ( "${General::swroot}/certs/hostkey.pem" );
864 # Create empty CRL cannot be done because we don't have
865 # the private key for this CAROOT
866 # IPFire can only import certificates
868 & General
:: log ( "ipsec" , "p12 import completed!" );
870 goto ROOTCERT_SUCCESS
;
872 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
874 # Validate input since the form was submitted
875 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
876 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
879 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
880 $errormessage = $Lang :: tr
{ 'organization too long' };
883 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
884 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
887 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
888 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
891 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
892 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
895 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
896 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
899 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
900 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
903 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
904 $errormessage = $Lang :: tr
{ 'invalid input for department' };
907 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
908 $errormessage = $Lang :: tr
{ 'invalid input for city' };
911 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
912 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
915 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
916 $errormessage = $Lang :: tr
{ 'invalid input for country' };
919 #the exact syntax is a list comma separated of
920 # email:any-validemail
921 # URI: a uniform resource indicator
922 # DNS: a DNS domain name
923 # RID: a registered OBJECT IDENTIFIER
925 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
927 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
928 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
932 # Copy the cgisettings to vpnsettings and save the configfile
933 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
934 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
935 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
936 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
937 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
938 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
939 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
940 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
942 # Replace empty strings with a .
943 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
944 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
945 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
947 # Create the CA certificate
948 if (! $errormessage ) {
949 & General
:: log ( "ipsec" , "Creating cacert..." );
950 if ( open ( STDIN
, "-|" )) {
951 my $opt = " req -x509 -sha256 -nodes" ;
952 $opt .= " -days 999999" ;
953 $opt .= " -newkey rsa:4096" ;
954 $opt .= " -keyout ${General::swroot}/private/cakey.pem" ;
955 $opt .= " -out ${General::swroot}/ca/cacert.pem" ;
957 $errormessage = & callssl
( $opt );
959 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
962 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
964 print " $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
965 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
970 # Create the Host certificate request
971 if (! $errormessage ) {
972 & General
:: log ( "ipsec" , "Creating host cert..." );
973 if ( open ( STDIN
, "-|" )) {
974 my $opt = " req -sha256 -nodes" ;
975 $opt .= " -newkey rsa:2048" ;
976 $opt .= " -keyout ${General::swroot}/certs/hostkey.pem" ;
977 $opt .= " -out ${General::swroot}/certs/hostreq.pem" ;
978 $errormessage = & callssl
( $opt );
980 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
983 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
985 print " $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
986 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
993 # Sign the host certificate request
994 if (! $errormessage ) {
995 & General
:: log ( "ipsec" , "Self signing host cert..." );
997 #No easy way for specifying the contain of subjectAltName without writing a config file...
998 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1000 basicConstraints=CA:FALSE
1001 nsComment="OpenSSL Generated Certificate"
1002 subjectKeyIdentifier=hash
1003 authorityKeyIdentifier=keyid,issuer:always
1004 extendedKeyUsage = serverAuth
1007 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1010 my $opt = " ca -md sha256 -days 999999" ;
1011 $opt .= " -batch -notext" ;
1012 $opt .= " -in ${General::swroot}/certs/hostreq.pem" ;
1013 $opt .= " -out ${General::swroot}/certs/hostcert.pem" ;
1014 $opt .= " -extfile $v3extname " ;
1015 $errormessage = & callssl
( $opt );
1016 unlink ( "${General::swroot}/certs/hostreq.pem" ); #no more needed
1017 unlink ( $v3extname );
1020 # Create an empty CRL
1021 if (! $errormessage ) {
1022 & General
:: log ( "ipsec" , "Creating emptycrl..." );
1023 my $opt = " ca -gencrl" ;
1024 $opt .= " -out ${General::swroot}/crls/cacrl.pem" ;
1025 $errormessage = & callssl
( $opt );
1028 # Successfully build CA / CERT!
1029 if (! $errormessage ) {
1030 & cleanssldatabase
();
1031 goto ROOTCERT_SUCCESS
;
1035 unlink ( "${General::swroot}/ca/cacert.pem" );
1036 unlink ( "${General::swroot}/certs/hostkey.pem" );
1037 unlink ( "${General::swroot}/certs/hostcert.pem" );
1038 unlink ( "${General::swroot}/crls/cacrl.pem" );
1039 & cleanssldatabase
();
1043 & Header
:: showhttpheaders
();
1044 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1045 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1046 if ( $errormessage ) {
1047 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1048 print "<class name='base'> $errormessage " ;
1049 print " </class>" ;
1050 & Header
:: closebox
();
1052 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
1054 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
1055 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1056 <tr><td width='40%' class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
1057 <td width='60%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td></tr>
1058 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}: <img src='/blob.gif' alt='*' /></td>
1059 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td></tr>
1060 <tr><td class='base'> $Lang ::tr{'your e-mail'}:</td>
1061 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td></tr>
1062 <tr><td class='base'> $Lang ::tr{'your department'}:</td>
1063 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td></tr>
1064 <tr><td class='base'> $Lang ::tr{'city'}:</td>
1065 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td></tr>
1066 <tr><td class='base'> $Lang ::tr{'state or province'}:</td>
1067 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td></tr>
1068 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1069 <td class='base'><select name='ROOTCERT_COUNTRY'>
1072 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1073 print "<option value=' $Countries ::countries{ $country }'" ;
1074 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1075 print " selected='selected'" ;
1077 print "> $country </option>" ;
1081 <tr><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)</td>
1082 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' /></td></tr>
1084 <td><br /><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /><br /><br /></td></tr>
1085 <tr><td class='base' colspan='2' align='left'>
1086 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1087 $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'}
1089 <tr><td colspan='2'><hr></td></tr>
1090 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}:</td>
1091 <td nowrap='nowrap'><input type='file' name='FH' size='32' /></td></tr>
1092 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
1093 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td></tr>
1095 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td></tr>
1096 <tr><td class='base' colspan='2' align='left'>
1097 <img src='/blob.gif' alt='*' /> $Lang ::tr{'required field'}</td></tr>
1101 & Header
:: closebox
();
1102 & Header
:: closebigbox
();
1103 & Header
:: closepage
();
1108 system ( '/usr/local/bin/ipsecctrl' , 'S' );
1113 ### Export PKCS12 file to browser
1115 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
1116 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1117 print "Content-Type: application/force-download \n " ;
1118 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
1119 print "Content-Type: application/octet-stream \r\n\r\n " ;
1120 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12` ;
1124 ### Display certificate
1126 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
1127 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1129 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1130 & Header
:: showhttpheaders
();
1131 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1132 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1133 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'cert'}:" );
1134 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1135 $output = & Header
:: cleanhtml
( $output , "y" );
1136 print "<pre> $output </pre> \n " ;
1137 & Header
:: closebox
();
1138 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1139 & Header
:: closebigbox
();
1140 & Header
:: closepage
();
1145 ### Export Certificate to browser
1147 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
1148 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1150 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1151 print "Content-Type: application/force-download \n " ;
1152 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \n\n " ;
1153 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1158 ### Enable/Disable connection
1160 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1162 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1163 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1165 if ( $confighash { $cgiparams { 'KEY' }}) {
1166 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
1167 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
1168 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1170 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1172 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1173 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
1174 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1179 $errormessage = $Lang :: tr
{ 'invalid key' };
1183 ### Restart connection
1185 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
1186 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1187 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1189 if ( $confighash { $cgiparams { 'KEY' }}) {
1191 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
1195 $errormessage = $Lang :: tr
{ 'invalid key' };
1199 ### Remove connection
1201 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
1202 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1203 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1205 if ( $confighash { $cgiparams { 'KEY' }}) {
1206 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1207 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1208 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1209 delete $confighash { $cgiparams { 'KEY' }};
1210 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1213 $errormessage = $Lang :: tr
{ 'invalid key' };
1215 & General
:: firewall_reload
();
1217 ### Choose between adding a host-net or net-net connection
1219 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
1220 & Header
:: showhttpheaders
();
1221 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1222 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1223 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection type' });
1225 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
1226 <b> $Lang ::tr{'connection type'}:</b><br />
1228 <tr><td><input type='radio' name='TYPE' value='host' checked='checked' /></td>
1229 <td class='base'> $Lang ::tr{'host to net vpn'}</td>
1231 <td><input type='radio' name='TYPE' value='net' /></td>
1232 <td class='base'> $Lang ::tr{'net to net vpn'}</td>
1234 <td align='center' colspan='2'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td>
1239 & Header
:: closebox
();
1240 & Header
:: closebigbox
();
1241 & Header
:: closepage
();
1244 ### Adding/Editing/Saving a connection
1246 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
1247 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
1248 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
1250 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1251 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1252 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1254 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
1255 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
1256 $errormessage = $Lang :: tr
{ 'invalid key' };
1259 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
1260 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
1261 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
1262 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
1263 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
1264 #$cgiparams{'free'} = $confighash{$cgiparams{'KEY'}}[6];
1265 $cgiparams { 'LOCAL_ID' } = $confighash { $cgiparams { 'KEY' }}[ 7 ];
1266 $cgiparams { 'LOCAL_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 8 ];
1267 $cgiparams { 'REMOTE_ID' } = $confighash { $cgiparams { 'KEY' }}[ 9 ];
1268 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
1269 $cgiparams { 'REMOTE_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 11 ];
1270 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
1271 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
1272 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
1273 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
1274 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
1275 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
1276 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
1277 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
1278 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
1279 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
1280 if ( $cgiparams { 'ESP_GROUPTYPE' } eq "" ) {
1281 $cgiparams { 'ESP_GROUPTYPE' } = $cgiparams { 'IKE_GROUPTYPE' };
1283 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
1284 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
1285 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
1286 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
1287 $cgiparams { 'DPD_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
1288 $cgiparams { 'DPD_DELAY' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
1289 $cgiparams { 'FORCE_MOBIKE' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
1291 if (! $cgiparams { 'DPD_DELAY' }) {
1292 $cgiparams { 'DPD_DELAY' } = 30 ;
1295 if (! $cgiparams { 'DPD_TIMEOUT' }) {
1296 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
1299 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
1300 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
1301 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
1302 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
1306 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
1307 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
1311 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
1312 $errormessage = $Lang :: tr
{ 'name is invalid' };
1316 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
1317 $errormessage = $Lang :: tr
{ 'name too long' };
1321 # Check if there is no other entry with this name
1322 if (! $cgiparams { 'KEY' }) { #only for add
1323 foreach my $key ( keys %confighash ) {
1324 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
1325 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
1331 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! $cgiparams { 'REMOTE' })) {
1332 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1336 if ( $cgiparams { 'REMOTE' }) {
1337 if (( $cgiparams { 'REMOTE' } ne ' %any ' ) && (! & General
:: validip
( $cgiparams { 'REMOTE' }))) {
1338 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
1339 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1342 if (& valid_dns_host
( $cgiparams { 'REMOTE' })) {
1343 $warnmessage = " $Lang ::tr{'check vpn lr'} $cgiparams {'REMOTE'}. $Lang ::tr{'dns check failed'}" ;
1349 unless (& General
:: validipandmask
( $cgiparams { 'LOCAL_SUBNET' })) {
1350 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
1354 # Allow only one roadwarrior/psk without remote IP-address
1355 if ( $cgiparams { 'REMOTE' } eq '' && $cgiparams { 'AUTH' } eq 'psk' ) {
1356 foreach my $key ( keys %confighash ) {
1357 if ( ( $cgiparams { 'KEY' } ne $key ) &&
1358 ( $confighash { $key }[ 4 ] eq 'psk' ) &&
1359 ( $confighash { $key }[ 10 ] eq '' ) ) {
1360 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
1365 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! & General
:: validipandmask
( $cgiparams { 'REMOTE_SUBNET' }))) {
1366 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
1370 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
1371 $errormessage = $Lang :: tr
{ 'invalid input' };
1374 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
1375 $errormessage = $Lang :: tr
{ 'invalid input' };
1379 # Allow nothing or a string (DN,FDQN,) beginning with @
1380 # with no comma but slashes between RID eg @O=FR/C=Paris/OU=myhome/CN=franck
1381 if ( ( $cgiparams { 'LOCAL_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1382 ( $cgiparams { 'REMOTE_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1383 (( $cgiparams { 'REMOTE_ID' } eq $cgiparams { 'LOCAL_ID' }) && ( $cgiparams { 'LOCAL_ID' } ne '' ))
1385 $errormessage = $Lang :: tr
{ 'invalid local-remote id' } . '<br />' .
1386 'DER_ASN1_DN: @c =FR/ou=Paris/ou=Home/cn=*<br />' .
1387 'FQDN: @ipfire .org<br />' .
1388 'USER_FQDN: info @ipfire .org<br />' .
1389 'IPV4_ADDR: 123.123.123.123' ;
1392 # If Auth is DN, verify existance of Remote ID.
1393 if ( $cgiparams { 'REMOTE_ID' } eq '' && (
1394 $cgiparams { 'AUTH' } eq 'auth-dn' || # while creation
1395 $confighash { $cgiparams { 'KEY' }}[ 2 ] eq ' %auth -dn' )){ # while editing
1396 $errormessage = $Lang :: tr
{ 'vpn missing remote id' };
1400 if ( $cgiparams { 'TYPE' } eq 'net' ){
1401 $warnmessage =& General
:: checksubnets
( '' , $cgiparams { 'REMOTE_SUBNET' }, 'ipsec' );
1402 if ( $warnmessage ne '' ){
1403 $warnmessage = $Lang :: tr
{ 'remote subnet' }. " ( $cgiparams {'REMOTE_SUBNET'}) <br>" . $warnmessage ;
1407 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1408 if (! length ( $cgiparams { 'PSK' }) ) {
1409 $errormessage = $Lang :: tr
{ 'pre-shared key is too short' };
1412 if ( $cgiparams { 'PSK' } =~ /'/ ) {
1413 $cgiparams { 'PSK' } =~ tr/'/ / ;
1414 $errormessage = $Lang :: tr
{ 'invalid characters found in pre-shared key' };
1417 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
1418 if ( $cgiparams { 'KEY' }) {
1419 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1422 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1423 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1427 # Move uploaded certificate request to a temporary file
1428 ( my $fh , my $filename ) = tempfile
( );
1429 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1434 # Sign the certificate request
1435 & General
:: log ( "ipsec" , "Signing your cert $cgiparams {'NAME'}..." );
1436 my $opt = " ca -md sha256 -days 999999" ;
1437 $opt .= " -batch -notext" ;
1438 $opt .= " -in $filename " ;
1439 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1441 if ( $errormessage = & callssl
( $opt ) ) {
1443 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1444 & cleanssldatabase
();
1448 & cleanssldatabase
();
1451 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1452 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1453 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1456 } elsif ( $cgiparams { 'AUTH' } eq 'pkcs12' ) {
1457 & General
:: log ( "ipsec" , "Importing from p12..." );
1459 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1460 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1461 goto ROOTCERT_ERROR
;
1464 # Move uploaded certificate request to a temporary file
1465 ( my $fh , my $filename ) = tempfile
( );
1466 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1468 goto ROOTCERT_ERROR
;
1471 # Extract the CA certificate from the file
1472 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
1473 if ( open ( STDIN
, "-|" )) {
1474 my $opt = " pkcs12 -cacerts -nokeys" ;
1475 $opt .= " -in $filename " ;
1476 $opt .= " -out /tmp/newcacert" ;
1477 $errormessage = & callssl
( $opt );
1479 print " $cgiparams {'P12_PASS'} \n " ;
1483 # Extract the Host certificate from the file
1484 if (! $errormessage ) {
1485 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
1486 if ( open ( STDIN
, "-|" )) {
1487 my $opt = " pkcs12 -clcerts -nokeys" ;
1488 $opt .= " -in $filename " ;
1489 $opt .= " -out /tmp/newhostcert" ;
1490 $errormessage = & callssl
( $opt );
1492 print " $cgiparams {'P12_PASS'} \n " ;
1497 if (! $errormessage ) {
1498 & General
:: log ( "ipsec" , "Moving cacert..." );
1499 #If CA have new subject, add it to our list of CA
1500 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( '/tmp/newcacert' ));
1502 foreach my $x ( keys %cahash ) {
1503 $casubject = '' if ( $cahash { $x }[ 1 ] eq $casubject );
1504 unshift ( @names , $cahash { $x }[ 0 ]);
1506 if ( $casubject ) { # a new one!
1507 my $temp = `/usr/bin/openssl x509 -text -in /tmp/newcacert` ;
1508 if ( $temp !~ /CA:TRUE/i ) {
1509 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
1511 #compute a name for it
1513 while ( grep ( /Imported-$idx/ , @names ) ) { $idx ++};
1514 $cgiparams { 'CA_NAME' }= "Imported- $idx " ;
1515 $cgiparams { 'CERT_NAME' }=& Header
:: cleanhtml
( getCNfromcert
( '/tmp/newhostcert' ));
1516 move
( "/tmp/newcacert" , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1517 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1518 if (! $errormessage ) {
1519 my $key = & General
:: findhasharraykey
( \
%cahash );
1520 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
1521 $cahash { $key }[ 1 ] = $casubject ;
1522 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1523 system ( '/usr/local/bin/ipsecctrl' , 'R' );
1528 if (! $errormessage ) {
1529 & General
:: log ( "ipsec" , "Moving host cert..." );
1530 move
( "/tmp/newhostcert" , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1531 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1536 unlink ( '/tmp/newcacert' );
1537 unlink ( '/tmp/newhostcert' );
1538 if ( $errormessage ) {
1539 unlink ( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1540 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1543 & General
:: log ( "ipsec" , "p12 import completed!" );
1544 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
1545 if ( $cgiparams { 'KEY' }) {
1546 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1549 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1550 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1553 # Move uploaded certificate to a temporary file
1554 ( my $fh , my $filename ) = tempfile
( );
1555 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1560 # Verify the certificate has a valid CA and move it
1561 & General
:: log ( "ipsec" , "Validating imported cert against our known CA..." );
1562 my $validca = 1 ; #assume ok
1563 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/cacert.pem $filename ` ;
1564 if ( $test !~ /: OK/ ) {
1566 foreach my $key ( keys %cahash ) {
1567 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $key }[0]cert.pem $filename ` ;
1568 if ( $test =~ /: OK/ ) {
1575 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
1579 move
( $filename , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1581 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1587 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1588 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1589 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1590 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1593 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
1594 if ( $cgiparams { 'KEY' }) {
1595 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1598 # Validate input since the form was submitted
1599 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
1600 $errormessage = $Lang :: tr
{ 'name too long' };
1603 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1604 $errormessage = $Lang :: tr
{ 'invalid input for name' };
1607 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
1608 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1611 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
1612 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1615 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1616 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1619 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
1620 $errormessage = $Lang :: tr
{ 'organization too long' };
1623 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1624 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1627 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1628 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1631 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1632 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1635 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1636 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1639 #the exact syntax is a list comma separated of
1640 # email:any-validemail
1641 # URI: a uniform resource indicator
1642 # DNS: a DNS domain name
1643 # RID: a registered OBJECT IDENTIFIER
1645 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
1647 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
1648 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
1652 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
1653 $errormessage = $Lang :: tr
{ 'password too short' };
1656 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
1657 $errormessage = $Lang :: tr
{ 'passwords do not match' };
1661 # Replace empty strings with a .
1662 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
1663 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
1664 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
1666 # Create the Client certificate request
1667 & General
:: log ( "ipsec" , "Creating a cert..." );
1669 if ( open ( STDIN
, "-|" )) {
1670 my $opt = " req -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
1671 $opt .= " -newkey rsa:2048" ;
1672 $opt .= " -keyout ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1673 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1675 if ( $errormessage = & callssl
( $opt ) ) {
1676 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1677 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1681 print " $cgiparams {'CERT_COUNTRY'} \n " ;
1684 print " $cgiparams {'CERT_ORGANIZATION'} \n " ;
1686 print " $cgiparams {'CERT_NAME'} \n " ;
1687 print " $cgiparams {'CERT_EMAIL'} \n " ;
1693 # Sign the client certificate request
1694 & General
:: log ( "ipsec" , "Signing the cert $cgiparams {'NAME'}..." );
1696 #No easy way for specifying the contain of subjectAltName without writing a config file...
1697 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1699 basicConstraints=CA:FALSE
1700 nsComment="OpenSSL Generated Certificate"
1701 subjectKeyIdentifier=hash
1702 extendedKeyUsage=clientAuth
1703 authorityKeyIdentifier=keyid,issuer:always
1706 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1709 my $opt = " ca -md sha256 -days 999999 -batch -notext" ;
1710 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1711 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1712 $opt .= " -extfile $v3extname " ;
1714 if ( $errormessage = & callssl
( $opt ) ) {
1715 unlink ( $v3extname );
1716 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1717 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1718 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1719 & cleanssldatabase
();
1722 unlink ( $v3extname );
1723 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1724 & cleanssldatabase
();
1727 # Create the pkcs12 file
1728 & General
:: log ( "ipsec" , "Packing a pkcs12 file..." );
1729 $opt = " pkcs12 -export" ;
1730 $opt .= " -inkey ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1731 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1732 $opt .= " -name \" $cgiparams {'NAME'} \" " ;
1733 $opt .= " -passout pass: $cgiparams {'CERT_PASS1'}" ;
1734 $opt .= " -certfile ${General::swroot}/ca/cacert.pem" ;
1735 $opt .= " -caname \" $vpnsettings {'ROOTCERT_ORGANIZATION'} CA \" " ;
1736 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}.p12" ;
1738 if ( $errormessage = & callssl
( $opt ) ) {
1739 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1740 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1741 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}.p12" );
1744 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1746 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
1747 ; # Nothing, just editing
1748 } elsif ( $cgiparams { 'AUTH' } eq 'auth-dn' ) {
1749 $cgiparams { 'CERT_NAME' } = ' %auth -dn' ; # a special value saying 'no cert file'
1751 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
1755 # 1)Error message here is not accurate.
1756 # 2)Test is superfluous, openswan can reference same cert multiple times
1757 # 3)Present since initial version (1.3.2.11), it isn't a bug correction
1758 # Check if there is no other entry with this certificate name
1759 #if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk') && ($cgiparams{'AUTH'} ne 'auth-dn')) {
1760 # foreach my $key (keys %confighash) {
1761 # if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) {
1762 # $errormessage = $Lang::tr{'a connection with this common name already exists'};
1763 # goto VPNCONF_ERROR;
1769 my $key = $cgiparams { 'KEY' };
1771 $key = & General
:: findhasharraykey
( \
%confighash );
1772 foreach my $i ( 0 .. 32 ) { $confighash { $key }[ $i ] = "" ;}
1774 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
1775 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
1776 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
1777 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
1779 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
1780 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1781 $confighash { $key }[ 4 ] = 'psk' ;
1782 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
1784 $confighash { $key }[ 4 ] = 'cert' ;
1786 if ( $cgiparams { 'TYPE' } eq 'net' ) {
1787 $confighash { $key }[ 11 ] = $cgiparams { 'REMOTE_SUBNET' };
1789 $confighash { $key }[ 7 ] = $cgiparams { 'LOCAL_ID' };
1790 $confighash { $key }[ 8 ] = $cgiparams { 'LOCAL_SUBNET' };
1791 $confighash { $key }[ 9 ] = $cgiparams { 'REMOTE_ID' };
1792 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
1793 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
1794 $confighash { $key }[ 26 ] = "" ; # Formerly INTERFACE
1795 $confighash { $key }[ 27 ] = $cgiparams { 'DPD_ACTION' };
1796 $confighash { $key }[ 29 ] = $cgiparams { 'IKE_VERSION' };
1798 # don't forget advanced value
1799 $confighash { $key }[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
1800 $confighash { $key }[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
1801 $confighash { $key }[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
1802 $confighash { $key }[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
1803 $confighash { $key }[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
1804 $confighash { $key }[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
1805 $confighash { $key }[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
1806 $confighash { $key }[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
1807 $confighash { $key }[ 12 ] = 'off' ; # $cgiparams{'AGGRMODE'};
1808 $confighash { $key }[ 13 ] = $cgiparams { 'COMPRESSION' };
1809 $confighash { $key }[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
1810 $confighash { $key }[ 28 ] = $cgiparams { 'PFS' };
1811 $confighash { $key }[ 30 ] = $cgiparams { 'DPD_TIMEOUT' };
1812 $confighash { $key }[ 31 ] = $cgiparams { 'DPD_DELAY' };
1813 $confighash { $key }[ 32 ] = $cgiparams { 'FORCE_MOBIKE' };
1815 # free unused fields!
1816 $confighash { $key }[ 6 ] = 'off' ;
1817 $confighash { $key }[ 15 ] = 'off' ;
1819 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1822 system ( '/usr/local/bin/ipsecctrl' , 'S' , $key );
1825 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
1826 $cgiparams { 'KEY' } = $key ;
1827 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
1830 } else { # add new connection
1831 $cgiparams { 'ENABLED' } = 'on' ;
1832 if ( ! - f
"${General::swroot}/private/cakey.pem" ) {
1833 $cgiparams { 'AUTH' } = 'psk' ;
1834 } elsif ( ! - f
"${General::swroot}/ca/cacert.pem" ) {
1835 $cgiparams { 'AUTH' } = 'certfile' ;
1837 $cgiparams { 'AUTH' } = 'certgen' ;
1839 $cgiparams { 'LOCAL_SUBNET' } = " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" ;
1840 $cgiparams { 'CERT_EMAIL' } = $vpnsettings { 'ROOTCERT_EMAIL' };
1841 $cgiparams { 'CERT_OU' } = $vpnsettings { 'ROOTCERT_OU' };
1842 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
1843 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
1844 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
1845 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
1847 # choose appropriate dpd action
1848 if ( $cgiparams { 'TYPE' } eq 'host' ) {
1849 $cgiparams { 'DPD_ACTION' } = 'clear' ;
1851 $cgiparams { 'DPD_ACTION' } = 'restart' ;
1854 if (! $cgiparams { 'DPD_DELAY' }) {
1855 $cgiparams { 'DPD_DELAY' } = 30 ;
1858 if (! $cgiparams { 'DPD_TIMEOUT' }) {
1859 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
1862 if (! $cgiparams { 'FORCE_MOBIKE' }) {
1863 $cgiparams { 'FORCE_MOBIKE' } = 'no' ;
1866 # Default IKE Version to v2
1867 if (! $cgiparams { 'IKE_VERSION' }) {
1868 $cgiparams { 'IKE_VERSION' } = 'ikev2' ;
1872 $cgiparams { 'LOCAL_ID' } = '' ;
1873 $cgiparams { 'REMOTE_ID' } = '' ;
1875 #use default advanced value
1876 $cgiparams { 'IKE_ENCRYPTION' } = 'aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128' ; #[18];
1877 $cgiparams { 'IKE_INTEGRITY' } = 'sha2_512|sha2_256|sha' ; #[19];
1878 $cgiparams { 'IKE_GROUPTYPE' } = '4096|3072|2048|1536|1024' ; #[20];
1879 $cgiparams { 'IKE_LIFETIME' } = '3' ; #[16];
1880 $cgiparams { 'ESP_ENCRYPTION' } = 'aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128' ; #[21];
1881 $cgiparams { 'ESP_INTEGRITY' } = 'sha2_512|sha2_256|sha1' ; #[22];
1882 $cgiparams { 'ESP_GROUPTYPE' } = '4096|3072|2048|1536|1024' ; #[23];
1883 $cgiparams { 'ESP_KEYLIFE' } = '1' ; #[17];
1884 $cgiparams { 'COMPRESSION' } = 'on' ; #[13];
1885 $cgiparams { 'ONLY_PROPOSED' } = 'off' ; #[24];
1886 $cgiparams { 'PFS' } = 'on' ; #[28];
1890 $checked { 'ENABLED' }{ 'off' } = '' ;
1891 $checked { 'ENABLED' }{ 'on' } = '' ;
1892 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = "checked='checked'" ;
1894 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
1895 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
1896 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = "checked='checked'" ;
1898 $checked { 'AUTH' }{ 'psk' } = '' ;
1899 $checked { 'AUTH' }{ 'certreq' } = '' ;
1900 $checked { 'AUTH' }{ 'certgen' } = '' ;
1901 $checked { 'AUTH' }{ 'certfile' } = '' ;
1902 $checked { 'AUTH' }{ 'pkcs12' } = '' ;
1903 $checked { 'AUTH' }{ 'auth-dn' } = '' ;
1904 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = "checked='checked'" ;
1906 & Header
:: showhttpheaders
();
1907 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1908 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1909 if ( $errormessage ) {
1910 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1911 print "<class name='base'> $errormessage " ;
1912 print " </class>" ;
1913 & Header
:: closebox
();
1917 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'warning messages'}:" );
1918 print "<class name='base'> $warnmessage " ;
1919 print " </class>" ;
1920 & Header
:: closebox
();
1923 print "<form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>" ;
1925 <input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />
1926 <input type='hidden' name='IKE_VERSION' value=' $cgiparams {'IKE_VERSION'}' />
1927 <input type='hidden' name='IKE_ENCRYPTION' value=' $cgiparams {'IKE_ENCRYPTION'}' />
1928 <input type='hidden' name='IKE_INTEGRITY' value=' $cgiparams {'IKE_INTEGRITY'}' />
1929 <input type='hidden' name='IKE_GROUPTYPE' value=' $cgiparams {'IKE_GROUPTYPE'}' />
1930 <input type='hidden' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' />
1931 <input type='hidden' name='ESP_ENCRYPTION' value=' $cgiparams {'ESP_ENCRYPTION'}' />
1932 <input type='hidden' name='ESP_INTEGRITY' value=' $cgiparams {'ESP_INTEGRITY'}' />
1933 <input type='hidden' name='ESP_GROUPTYPE' value=' $cgiparams {'ESP_GROUPTYPE'}' />
1934 <input type='hidden' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' />
1935 <input type='hidden' name='COMPRESSION' value=' $cgiparams {'COMPRESSION'}' />
1936 <input type='hidden' name='ONLY_PROPOSED' value=' $cgiparams {'ONLY_PROPOSED'}' />
1937 <input type='hidden' name='PFS' value=' $cgiparams {'PFS'}' />
1938 <input type='hidden' name='DPD_ACTION' value=' $cgiparams {'DPD_ACTION'}' />
1939 <input type='hidden' name='DPD_DELAY' value=' $cgiparams {'DPD_DELAY'}' />
1940 <input type='hidden' name='DPD_TIMEOUT' value=' $cgiparams {'DPD_TIMEOUT'}' />
1941 <input type='hidden' name='FORCE_MOBIKE' value=' $cgiparams {'FORCE_MOBIKE'}' />
1944 if ( $cgiparams { 'KEY' }) {
1945 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
1946 print "<input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' />" ;
1947 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
1950 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'connection'}: $cgiparams {'NAME'}" );
1951 print "<table width='100%'>" ;
1952 if (! $cgiparams { 'KEY' }) {
1955 <td width='20%'> $Lang ::tr{'name'}: <img src='/blob.gif' alt='*' /></td>
1957 <input type='text' name='NAME' value=' $cgiparams {'NAME'}' size='25' />
1959 <td colspan="2"></td>
1966 if ( $cgiparams { 'TYPE' } eq 'host' ) {
1967 $disabled = "disabled='disabled'" ;
1968 } elsif ( $cgiparams { 'TYPE' } eq 'net' ) {
1969 $blob = "<img src='/blob.gif' alt='*' />" ;
1974 <td width='20%'> $Lang ::tr{'enabled'}</td>
1976 <input type='checkbox' name='ENABLED' $checked {'ENABLED'}{'on'} />
1978 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'local subnet'} <img src='/blob.gif' alt='*' /></td>
1980 <input type='text' name='LOCAL_SUBNET' value=' $cgiparams {'LOCAL_SUBNET'}' size="25" />
1984 <td class='boldbase' width='20%'> $Lang ::tr{'remote host/ip'}: $blob </td>
1986 <input type='text' name='REMOTE' value=' $cgiparams {'REMOTE'}' size="25" />
1988 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'remote subnet'} $blob </td>
1990 <input $disabled type='text' name='REMOTE_SUBNET' value=' $cgiparams {'REMOTE_SUBNET'}' size="25" />
1994 <td class='boldbase' width='20%'> $Lang ::tr{'vpn local id'}:</td>
1996 <input type='text' name='LOCAL_ID' value=' $cgiparams {'LOCAL_ID'}' size="25" />
1998 <td class='boldbase' width='20%'> $Lang ::tr{'vpn remote id'}:</td>
2000 <input type='text' name='REMOTE_ID' value=' $cgiparams {'REMOTE_ID'}' size="25" />
2003 <tr><td colspan="4"><br /></td></tr>
2005 <td class='boldbase' width='20%'> $Lang ::tr{'remark title'}</td>
2007 <input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' maxlength='50' size="73" />
2012 if (! $cgiparams { 'KEY' }) {
2013 print "<tr><td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked {'EDIT_ADVANCED'}{'on'} /> $Lang ::tr{'edit advanced settings when done'}</td></tr>" ;
2016 & Header
:: closebox
();
2018 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
2019 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2021 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2022 <tr><td class='base' width='50%'> $Lang ::tr{'use a pre-shared key'}</td>
2023 <td class='base' width='50%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td>
2028 & Header
:: closebox
();
2029 } elsif (! $cgiparams { 'KEY' }) {
2030 my $cakeydisabled = ( ! - f
"${General::swroot}/private/cakey.pem" ) ?
"disabled='disabled'" : '' ;
2031 $cgiparams { 'CERT_NAME' } = $Lang :: tr
{ 'vpn no full pki' } if ( $cakeydisabled );
2032 my $cacrtdisabled = ( ! - f
"${General::swroot}/ca/cacert.pem" ) ?
"disabled='disabled'" : '' ;
2034 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2036 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2037 <tr><td width='5%'><input type='radio' name='AUTH' value='psk' $checked {'AUTH'}{'psk'} /></td>
2038 <td class='base' width='55%'> $Lang ::tr{'use a pre-shared key'}</td>
2039 <td class='base' width='40%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td></tr>
2040 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2041 <tr><td><input type='radio' name='AUTH' value='certreq' $checked {'AUTH'}{'certreq'} $cakeydisabled /></td>
2042 <td class='base'><hr /> $Lang ::tr{'upload a certificate request'}</td>
2043 <td class='base' rowspan='3' valign='middle'><input type='file' name='FH' size='30' $cacrtdisabled /></td></tr>
2044 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td>
2045 <td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
2046 <tr><td><input type='radio' name='AUTH' value='pkcs12' $cacrtdisabled /></td>
2047 <td class='base'> $Lang ::tr{'upload p12 file'} $Lang ::tr{'pkcs12 file password'}:<input type='password' name='P12_PASS'/></td></tr>
2048 <tr><td><input type='radio' name='AUTH' value='auth-dn' $checked {'AUTH'}{'auth-dn'} $cacrtdisabled /></td>
2049 <td class='base'><hr /> $Lang ::tr{'vpn auth-dn'}</td></tr>
2050 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2051 <tr><td><input type='radio' name='AUTH' value='certgen' $checked {'AUTH'}{'certgen'} $cakeydisabled /></td>
2052 <td class='base'><hr /> $Lang ::tr{'generate a certificate'}</td><td> </td></tr>
2054 <td class='base'> $Lang ::tr{'users fullname or system hostname'}: <img src='/blob.gif' alt='*' /></td>
2055 <td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' size='32' $cakeydisabled /></td></tr>
2057 <td class='base'> $Lang ::tr{'users email'}:</td>
2058 <td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' size='32' $cakeydisabled /></td></tr>
2060 <td class='base'> $Lang ::tr{'users department'}:</td>
2061 <td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' size='32' $cakeydisabled /></td></tr>
2063 <td class='base'> $Lang ::tr{'organization name'}:</td>
2064 <td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' size='32' $cakeydisabled /></td></tr>
2066 <td class='base'> $Lang ::tr{'city'}:</td>
2067 <td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' size='32' $cakeydisabled /></td></tr>
2069 <td class='base'> $Lang ::tr{'state or province'}:</td>
2070 <td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' size='32' $cakeydisabled /></td></tr>
2072 <td class='base'> $Lang ::tr{'country'}:</td>
2073 <td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
2076 foreach my $country ( sort keys %{ Countries
:: countries
}) {
2077 print " \t\t\t <option value=' $Countries ::countries{ $country }'" ;
2078 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
2079 print " selected='selected'" ;
2081 print "> $country </option> \n " ;
2086 <tr><td> </td><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)</td>
2087 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' $cakeydisabled /></td></tr>
2089 <td class='base'> $Lang ::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' /></td>
2090 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
2091 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'} ( $Lang ::tr{'confirmation'}): <img src='/blob.gif' alt='*' /></td>
2092 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
2096 & Header
:: closebox
();
2099 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
2100 if ( $cgiparams { 'KEY' }) {
2101 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced'}' />" ;
2103 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
2104 & Header
:: closebigbox
();
2105 & Header
:: closepage
();
2112 ### Advanced settings
2114 if (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced' }) ||
2115 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq 'yes' )) {
2116 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
2117 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2118 if (! $confighash { $cgiparams { 'KEY' }}) {
2119 $errormessage = $Lang :: tr
{ 'invalid key' };
2123 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
2124 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2126 $errormessage = $Lang :: tr
{ 'invalid input' };
2127 goto ADVANCED_ERROR
;
2129 foreach my $val ( @temp ) {
2130 if ( $val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|camellia(256|192|128))$/ ) {
2131 $errormessage = $Lang :: tr
{ 'invalid input' };
2132 goto ADVANCED_ERROR
;
2135 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2137 $errormessage = $Lang :: tr
{ 'invalid input' };
2138 goto ADVANCED_ERROR
;
2140 foreach my $val ( @temp ) {
2141 if ( $val !~ /^(sha2_(512|384|256)|sha|md5|aesxcbc)$/ ) {
2142 $errormessage = $Lang :: tr
{ 'invalid input' };
2143 goto ADVANCED_ERROR
;
2146 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2148 $errormessage = $Lang :: tr
{ 'invalid input' };
2149 goto ADVANCED_ERROR
;
2151 foreach my $val ( @temp ) {
2152 if ( $val !~ /^(e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|1024|1536|2048|2048s256|2048s224|2048s160|3072|4096|6144|8192)$/ ) {
2153 $errormessage = $Lang :: tr
{ 'invalid input' };
2154 goto ADVANCED_ERROR
;
2157 if ( $cgiparams { 'IKE_LIFETIME' } !~ /^\d+$/ ) {
2158 $errormessage = $Lang :: tr
{ 'invalid input for ike lifetime' };
2159 goto ADVANCED_ERROR
;
2161 if ( $cgiparams { 'IKE_LIFETIME' } < 1 || $cgiparams { 'IKE_LIFETIME' } > 8 ) {
2162 $errormessage = $Lang :: tr
{ 'ike lifetime should be between 1 and 8 hours' };
2163 goto ADVANCED_ERROR
;
2165 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2167 $errormessage = $Lang :: tr
{ 'invalid input' };
2168 goto ADVANCED_ERROR
;
2170 foreach my $val ( @temp ) {
2171 if ( $val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|camellia(256|192|128))$/ ) {
2172 $errormessage = $Lang :: tr
{ 'invalid input' };
2173 goto ADVANCED_ERROR
;
2176 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2178 $errormessage = $Lang :: tr
{ 'invalid input' };
2179 goto ADVANCED_ERROR
;
2181 foreach my $val ( @temp ) {
2182 if ( $val !~ /^(sha2_(512|384|256)|sha1|md5|aesxcbc)$/ ) {
2183 $errormessage = $Lang :: tr
{ 'invalid input' };
2184 goto ADVANCED_ERROR
;
2187 @temp = split ( '\|' , $cgiparams { 'ESP_GROUPTYPE' });
2189 $errormessage = $Lang :: tr
{ 'invalid input' };
2190 goto ADVANCED_ERROR
;
2192 foreach my $val ( @temp ) {
2193 if ( $val !~ /^(e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|1024|1536|2048|2048s256|2048s224|2048s160|3072|4096|6144|8192|none)$/ ) {
2194 $errormessage = $Lang :: tr
{ 'invalid input' };
2195 goto ADVANCED_ERROR
;
2198 if ( $cgiparams { 'ESP_KEYLIFE' } !~ /^\d+$/ ) {
2199 $errormessage = $Lang :: tr
{ 'invalid input for esp keylife' };
2200 goto ADVANCED_ERROR
;
2202 if ( $cgiparams { 'ESP_KEYLIFE' } < 1 || $cgiparams { 'ESP_KEYLIFE' } > 24 ) {
2203 $errormessage = $Lang :: tr
{ 'esp keylife should be between 1 and 24 hours' };
2204 goto ADVANCED_ERROR
;
2207 if (( $cgiparams { 'COMPRESSION' } !~ /^(|on|off)$/ ) ||
2208 ( $cgiparams { 'FORCE_MOBIKE' } !~ /^(|on|off)$/ ) ||
2209 ( $cgiparams { 'ONLY_PROPOSED' } !~ /^(|on|off)$/ ) ||
2210 ( $cgiparams { 'PFS' } !~ /^(|on|off)$/ )) {
2211 $errormessage = $Lang :: tr
{ 'invalid input' };
2212 goto ADVANCED_ERROR
;
2215 if ( $cgiparams { 'DPD_DELAY' } !~ /^\d+$/ ) {
2216 $errormessage = $Lang :: tr
{ 'invalid input for dpd delay' };
2217 goto ADVANCED_ERROR
;
2220 if ( $cgiparams { 'DPD_TIMEOUT' } !~ /^\d+$/ ) {
2221 $errormessage = $Lang :: tr
{ 'invalid input for dpd timeout' };
2222 goto ADVANCED_ERROR
;
2225 $confighash { $cgiparams { 'KEY' }}[ 29 ] = $cgiparams { 'IKE_VERSION' };
2226 $confighash { $cgiparams { 'KEY' }}[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
2227 $confighash { $cgiparams { 'KEY' }}[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
2228 $confighash { $cgiparams { 'KEY' }}[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
2229 $confighash { $cgiparams { 'KEY' }}[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
2230 $confighash { $cgiparams { 'KEY' }}[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
2231 $confighash { $cgiparams { 'KEY' }}[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
2232 $confighash { $cgiparams { 'KEY' }}[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
2233 $confighash { $cgiparams { 'KEY' }}[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
2234 $confighash { $cgiparams { 'KEY' }}[ 12 ] = 'off' ; #$cgiparams{'AGGRMODE'};
2235 $confighash { $cgiparams { 'KEY' }}[ 13 ] = $cgiparams { 'COMPRESSION' };
2236 $confighash { $cgiparams { 'KEY' }}[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
2237 $confighash { $cgiparams { 'KEY' }}[ 28 ] = $cgiparams { 'PFS' };
2238 $confighash { $cgiparams { 'KEY' }}[ 27 ] = $cgiparams { 'DPD_ACTION' };
2239 $confighash { $cgiparams { 'KEY' }}[ 30 ] = $cgiparams { 'DPD_TIMEOUT' };
2240 $confighash { $cgiparams { 'KEY' }}[ 31 ] = $cgiparams { 'DPD_DELAY' };
2241 $confighash { $cgiparams { 'KEY' }}[ 32 ] = $cgiparams { 'FORCE_MOBIKE' };
2242 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2245 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
2250 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
2251 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
2252 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
2253 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
2254 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
2255 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
2256 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
2257 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
2258 if ( $cgiparams { 'ESP_GROUPTYPE' } eq "" ) {
2259 $cgiparams { 'ESP_GROUPTYPE' } = $cgiparams { 'IKE_GROUPTYPE' };
2261 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
2262 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
2263 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
2264 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
2265 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
2266 $cgiparams { 'DPD_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
2267 $cgiparams { 'DPD_DELAY' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
2268 $cgiparams { 'FORCE_MOBIKE' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
2270 if (! $cgiparams { 'DPD_DELAY' }) {
2271 $cgiparams { 'DPD_DELAY' } = 30 ;
2274 if (! $cgiparams { 'DPD_TIMEOUT' }) {
2275 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
2280 $checked { 'IKE_ENCRYPTION' }{ 'aes256' } = '' ;
2281 $checked { 'IKE_ENCRYPTION' }{ 'aes192' } = '' ;
2282 $checked { 'IKE_ENCRYPTION' }{ 'aes128' } = '' ;
2283 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm128' } = '' ;
2284 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm128' } = '' ;
2285 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm128' } = '' ;
2286 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm96' } = '' ;
2287 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm96' } = '' ;
2288 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm96' } = '' ;
2289 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm64' } = '' ;
2290 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm64' } = '' ;
2291 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm64' } = '' ;
2292 $checked { 'IKE_ENCRYPTION' }{ '3des' } = '' ;
2293 $checked { 'IKE_ENCRYPTION' }{ 'camellia256' } = '' ;
2294 $checked { 'IKE_ENCRYPTION' }{ 'camellia192' } = '' ;
2295 $checked { 'IKE_ENCRYPTION' }{ 'camellia128' } = '' ;
2296 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2297 foreach my $key ( @temp ) { $checked { 'IKE_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2298 $checked { 'IKE_INTEGRITY' }{ 'sha2_512' } = '' ;
2299 $checked { 'IKE_INTEGRITY' }{ 'sha2_384' } = '' ;
2300 $checked { 'IKE_INTEGRITY' }{ 'sha2_256' } = '' ;
2301 $checked { 'IKE_INTEGRITY' }{ 'sha' } = '' ;
2302 $checked { 'IKE_INTEGRITY' }{ 'md5' } = '' ;
2303 $checked { 'IKE_INTEGRITY' }{ 'aesxcbc' } = '' ;
2304 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2305 foreach my $key ( @temp ) { $checked { 'IKE_INTEGRITY' }{ $key } = "selected='selected'" ; }
2306 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2307 $checked { 'IKE_GROUPTYPE' }{ '1024' } = '' ;
2308 $checked { 'IKE_GROUPTYPE' }{ '1536' } = '' ;
2309 $checked { 'IKE_GROUPTYPE' }{ '2048' } = '' ;
2310 $checked { 'IKE_GROUPTYPE' }{ '3072' } = '' ;
2311 $checked { 'IKE_GROUPTYPE' }{ '4096' } = '' ;
2312 $checked { 'IKE_GROUPTYPE' }{ '6144' } = '' ;
2313 $checked { 'IKE_GROUPTYPE' }{ '8192' } = '' ;
2314 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2315 foreach my $key ( @temp ) { $checked { 'IKE_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2317 # 768 is not supported by strongswan
2318 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2320 $checked { 'ESP_ENCRYPTION' }{ 'aes256' } = '' ;
2321 $checked { 'ESP_ENCRYPTION' }{ 'aes192' } = '' ;
2322 $checked { 'ESP_ENCRYPTION' }{ 'aes128' } = '' ;
2323 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm128' } = '' ;
2324 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm128' } = '' ;
2325 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm128' } = '' ;
2326 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm96' } = '' ;
2327 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm96' } = '' ;
2328 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm96' } = '' ;
2329 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm64' } = '' ;
2330 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm64' } = '' ;
2331 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm64' } = '' ;
2332 $checked { 'ESP_ENCRYPTION' }{ '3des' } = '' ;
2333 $checked { 'ESP_ENCRYPTION' }{ 'camellia256' } = '' ;
2334 $checked { 'ESP_ENCRYPTION' }{ 'camellia192' } = '' ;
2335 $checked { 'ESP_ENCRYPTION' }{ 'camellia128' } = '' ;
2336 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2337 foreach my $key ( @temp ) { $checked { 'ESP_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2338 $checked { 'ESP_INTEGRITY' }{ 'sha2_512' } = '' ;
2339 $checked { 'ESP_INTEGRITY' }{ 'sha2_384' } = '' ;
2340 $checked { 'ESP_INTEGRITY' }{ 'sha2_256' } = '' ;
2341 $checked { 'ESP_INTEGRITY' }{ 'sha1' } = '' ;
2342 $checked { 'ESP_INTEGRITY' }{ 'md5' } = '' ;
2343 $checked { 'ESP_INTEGRITY' }{ 'aesxcbc' } = '' ;
2344 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2345 foreach my $key ( @temp ) { $checked { 'ESP_INTEGRITY' }{ $key } = "selected='selected'" ; }
2346 $checked { 'ESP_GROUPTYPE' }{ '768' } = '' ;
2347 $checked { 'ESP_GROUPTYPE' }{ '1024' } = '' ;
2348 $checked { 'ESP_GROUPTYPE' }{ '1536' } = '' ;
2349 $checked { 'ESP_GROUPTYPE' }{ '2048' } = '' ;
2350 $checked { 'ESP_GROUPTYPE' }{ '3072' } = '' ;
2351 $checked { 'ESP_GROUPTYPE' }{ '4096' } = '' ;
2352 $checked { 'ESP_GROUPTYPE' }{ '6144' } = '' ;
2353 $checked { 'ESP_GROUPTYPE' }{ '8192' } = '' ;
2354 $checked { 'ESP_GROUPTYPE' }{ 'none' } = '' ;
2355 @temp = split ( '\|' , $cgiparams { 'ESP_GROUPTYPE' });
2356 foreach my $key ( @temp ) { $checked { 'ESP_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2358 $checked { 'COMPRESSION' } = $cgiparams { 'COMPRESSION' } eq 'on' ?
"checked='checked'" : '' ;
2359 $checked { 'FORCE_MOBIKE' } = $cgiparams { 'FORCE_MOBIKE' } eq 'on' ?
"checked='checked'" : '' ;
2360 $checked { 'ONLY_PROPOSED' } = $cgiparams { 'ONLY_PROPOSED' } eq 'on' ?
"checked='checked'" : '' ;
2361 $checked { 'PFS' } = $cgiparams { 'PFS' } eq 'on' ?
"checked='checked'" : '' ;
2363 $selected { 'IKE_VERSION' }{ 'ikev1' } = '' ;
2364 $selected { 'IKE_VERSION' }{ 'ikev2' } = '' ;
2365 $selected { 'IKE_VERSION' }{ $cgiparams { 'IKE_VERSION' }} = "selected='selected'" ;
2367 $selected { 'DPD_ACTION' }{ 'clear' } = '' ;
2368 $selected { 'DPD_ACTION' }{ 'hold' } = '' ;
2369 $selected { 'DPD_ACTION' }{ 'restart' } = '' ;
2370 $selected { 'DPD_ACTION' }{ 'none' } = '' ;
2371 $selected { 'DPD_ACTION' }{ $cgiparams { 'DPD_ACTION' }} = "selected='selected'" ;
2373 & Header
:: showhttpheaders
();
2374 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
2375 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2377 if ( $errormessage ) {
2378 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2379 print "<class name='base'> $errormessage " ;
2380 print " </class>" ;
2381 & Header
:: closebox
();
2385 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
2386 print "<class name='base'> $warnmessage " ;
2387 print " </class>" ;
2388 & Header
:: closebox
();
2391 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'advanced'}:" );
2393 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
2394 <input type='hidden' name='ADVANCED' value='yes' />
2395 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
2397 <table width='100%'>
2400 <th width="15%"></th>
2407 <td> $Lang ::tr{'vpn keyexchange'}:</td>
2409 <select name='IKE_VERSION'>
2410 <option value='ikev2' $selected {'IKE_VERSION'}{'ikev2'}>IKEv2</option>
2411 <option value='ikev1' $selected {'IKE_VERSION'}{'ikev1'}>IKEv1</option>
2417 <td class='boldbase' width="15%"> $Lang ::tr{'encryption'}</td>
2418 <td class='boldbase'>
2419 <select name='IKE_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
2420 <option value='aes256gcm128' $checked {'IKE_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
2421 <option value='aes256gcm96' $checked {'IKE_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
2422 <option value='aes256gcm64' $checked {'IKE_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
2423 <option value='aes256' $checked {'IKE_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
2424 <option value='camellia256' $checked {'IKE_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
2425 <option value='aes192gcm128' $checked {'IKE_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
2426 <option value='aes192gcm96' $checked {'IKE_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
2427 <option value='aes192gcm64' $checked {'IKE_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
2428 <option value='aes192' $checked {'IKE_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
2429 <option value='camellia192' $checked {'IKE_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
2430 <option value='aes128gcm128' $checked {'IKE_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
2431 <option value='aes128gcm96' $checked {'IKE_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
2432 <option value='aes128gcm64' $checked {'IKE_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
2433 <option value='aes128' $checked {'IKE_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
2434 <option value='camellia128' $checked {'IKE_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
2435 <option value='3des' $checked {'IKE_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC</option>
2438 <td class='boldbase'>
2439 <select name='ESP_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
2440 <option value='aes256gcm128' $checked {'ESP_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
2441 <option value='aes256gcm96' $checked {'ESP_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
2442 <option value='aes256gcm64' $checked {'ESP_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
2443 <option value='aes256' $checked {'ESP_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
2444 <option value='camellia256' $checked {'ESP_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
2445 <option value='aes192gcm128' $checked {'ESP_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
2446 <option value='aes192gcm96' $checked {'ESP_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
2447 <option value='aes192gcm64' $checked {'ESP_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
2448 <option value='aes192' $checked {'ESP_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
2449 <option value='camellia192' $checked {'ESP_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
2450 <option value='aes128gcm128' $checked {'ESP_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
2451 <option value='aes128gcm96' $checked {'ESP_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
2452 <option value='aes128gcm64' $checked {'ESP_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
2453 <option value='aes128' $checked {'ESP_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
2454 <option value='camellia128' $checked {'ESP_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
2455 <option value='3des' $checked {'ESP_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC</option>
2461 <td class='boldbase' width="15%"> $Lang ::tr{'integrity'}</td>
2462 <td class='boldbase'>
2463 <select name='IKE_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
2464 <option value='sha2_512' $checked {'IKE_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2465 <option value='sha2_384' $checked {'IKE_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2466 <option value='sha2_256' $checked {'IKE_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2467 <option value='aesxcbc' $checked {'IKE_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2468 <option value='sha' $checked {'IKE_INTEGRITY'}{'sha'}>SHA1</option>
2469 <option value='md5' $checked {'IKE_INTEGRITY'}{'md5'}>MD5</option>
2472 <td class='boldbase'>
2473 <select name='ESP_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
2474 <option value='sha2_512' $checked {'ESP_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2475 <option value='sha2_384' $checked {'ESP_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2476 <option value='sha2_256' $checked {'ESP_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2477 <option value='aesxcbc' $checked {'ESP_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2478 <option value='sha1' $checked {'ESP_INTEGRITY'}{'sha1'}>SHA1</option>
2479 <option value='md5' $checked {'ESP_INTEGRITY'}{'md5'}>MD5</option>
2484 <td class='boldbase' width="15%"> $Lang ::tr{'lifetime'} <img src='/blob.gif' alt='*' /></td>
2485 <td class='boldbase'>
2486 <input type='text' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' size='5' /> $Lang ::tr{'hours'}
2488 <td class='boldbase'>
2489 <input type='text' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' size='5' /> $Lang ::tr{'hours'}
2493 <td class='boldbase' width="15%"> $Lang ::tr{'grouptype'}</td>
2494 <td class='boldbase'>
2495 <select name='IKE_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
2496 <option value='e521' $checked {'IKE_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
2497 <option value='e512bp' $checked {'IKE_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
2498 <option value='e384' $checked {'IKE_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
2499 <option value='e384bp' $checked {'IKE_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
2500 <option value='e256' $checked {'IKE_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
2501 <option value='e256bp' $checked {'IKE_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
2502 <option value='e224' $checked {'IKE_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
2503 <option value='e224bp' $checked {'IKE_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
2504 <option value='e192' $checked {'IKE_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
2505 <option value='8192' $checked {'IKE_GROUPTYPE'}{'8192'}>MODP-8192</option>
2506 <option value='6144' $checked {'IKE_GROUPTYPE'}{'6144'}>MODP-6144</option>
2507 <option value='4096' $checked {'IKE_GROUPTYPE'}{'4096'}>MODP-4096</option>
2508 <option value='3072' $checked {'IKE_GROUPTYPE'}{'3072'}>MODP-3072</option>
2509 <option value='2048s256' $checked {'IKE_GROUPTYPE'}{'2048s256'}>MODP-2048/256</option>
2510 <option value='2048s224' $checked {'IKE_GROUPTYPE'}{'2048s224'}>MODP-2048/224</option>
2511 <option value='2048s160' $checked {'IKE_GROUPTYPE'}{'2048s160'}>MODP-2048/160</option>
2512 <option value='2048' $checked {'IKE_GROUPTYPE'}{'2048'}>MODP-2048</option>
2513 <option value='1536' $checked {'IKE_GROUPTYPE'}{'1536'}>MODP-1536</option>
2514 <option value='1024' $checked {'IKE_GROUPTYPE'}{'1024'}>MODP-1024</option>
2517 <td class='boldbase'>
2518 <select name='ESP_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
2519 <option value='e521' $checked {'ESP_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
2520 <option value='e512bp' $checked {'ESP_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
2521 <option value='e384' $checked {'ESP_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
2522 <option value='e384bp' $checked {'ESP_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
2523 <option value='e256' $checked {'ESP_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
2524 <option value='e256bp' $checked {'ESP_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
2525 <option value='e224' $checked {'ESP_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
2526 <option value='e224bp' $checked {'ESP_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
2527 <option value='e192' $checked {'ESP_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
2528 <option value='8192' $checked {'ESP_GROUPTYPE'}{'8192'}>MODP-8192</option>
2529 <option value='6144' $checked {'ESP_GROUPTYPE'}{'6144'}>MODP-6144</option>
2530 <option value='4096' $checked {'ESP_GROUPTYPE'}{'4096'}>MODP-4096</option>
2531 <option value='3072' $checked {'ESP_GROUPTYPE'}{'3072'}>MODP-3072</option>
2532 <option value='2048s256' $checked {'ESP_GROUPTYPE'}{'2048s256'}>MODP-2048/256</option>
2533 <option value='2048s224' $checked {'ESP_GROUPTYPE'}{'2048s224'}>MODP-2048/224</option>
2534 <option value='2048s160' $checked {'ESP_GROUPTYPE'}{'2048s160'}>MODP-2048/160</option>
2535 <option value='2048' $checked {'ESP_GROUPTYPE'}{'2048'}>MODP-2048</option>
2536 <option value='1536' $checked {'ESP_GROUPTYPE'}{'1536'}>MODP-1536</option>
2537 <option value='1024' $checked {'ESP_GROUPTYPE'}{'1024'}>MODP-1024</option>
2538 <option value='none' $checked {'ESP_GROUPTYPE'}{'none'}>- $Lang ::tr{'none'} -</option>
2547 <h2> $Lang ::tr{'dead peer detection'}</h2>
2549 <table width="100%">
2551 <td width="15%"> $Lang ::tr{'dpd action'}:</td>
2553 <select name='DPD_ACTION'>
2554 <option value='none' $selected {'DPD_ACTION'}{'none'}>- $Lang ::tr{'disabled'} -</option>
2555 <option value='clear' $selected {'DPD_ACTION'}{'clear'}>clear</option>
2556 <option value='hold' $selected {'DPD_ACTION'}{'hold'}>hold</option>
2557 <option value='restart' $selected {'DPD_ACTION'}{'restart'}>restart</option>
2562 <td width="15%"> $Lang ::tr{'dpd timeout'}: <img src='/blob.gif' alt='*' /></td>
2564 <input type='text' name='DPD_TIMEOUT' size='5' value=' $cgiparams {'DPD_TIMEOUT'}' />
2568 <td width="15%"> $Lang ::tr{'dpd delay'}: <img src='/blob.gif' alt='*' /></td>
2570 <input type='text' name='DPD_DELAY' size='5' value=' $cgiparams {'DPD_DELAY'}' />
2577 <table width="100%">
2581 <input type='checkbox' name='ONLY_PROPOSED' $checked {'ONLY_PROPOSED'} />
2582 IKE+ESP: $Lang ::tr{'use only proposed settings'}
2589 <input type='checkbox' name='PFS' $checked {'PFS'} />
2590 $Lang ::tr{'pfs yes no'}
2597 <input type='checkbox' name='COMPRESSION' $checked {'COMPRESSION'} />
2598 $Lang ::tr{'vpn payload compression'}
2605 <input type='checkbox' name='FORCE_MOBIKE' $checked {'FORCE_MOBIKE'} />
2606 $Lang ::tr{'vpn force mobike'}
2615 <td align='left' colspan='1'><img src='/blob.gif' align='top' alt='*' /> $Lang ::tr{'required field'}</td>
2616 <td align='right' colspan='2'>
2617 <input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />
2618 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' />
2624 & Header
:: closebox
();
2625 & Header
:: closebigbox
();
2626 & Header
:: closepage
();
2633 ### Default status page
2638 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%cgiparams );
2639 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
2640 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2641 $cgiparams { 'CA_NAME' } = '' ;
2643 my @status = `/usr/local/bin/ipsecctrl I 2>/dev/null` ;
2645 # suggest a default name for this side
2646 if ( $cgiparams { 'VPN_IP' } eq '' && - e
"${General::swroot}/red/active" ) {
2647 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
2648 my $ipaddr = < IPADDR
>;
2651 $cgiparams { 'VPN_IP' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
2652 if ( $cgiparams { 'VPN_IP' } eq '' ) {
2653 $cgiparams { 'VPN_IP' } = $ipaddr ;
2657 # no IP found, use %defaultroute
2658 $cgiparams { 'VPN_IP' } = ' %defaultroute ' if ( $cgiparams { 'VPN_IP' } eq '' );
2660 $cgiparams { 'VPN_DELAYED_START' } = 0 if (! defined ( $cgiparams { 'VPN_DELAYED_START' }));
2661 $checked { 'ENABLED' } = $cgiparams { 'ENABLED' } eq 'on' ?
"checked='checked'" : '' ;
2663 & Header
:: showhttpheaders
();
2664 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
2665 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2667 if ( $errormessage ) {
2668 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2669 print "<class name='base'> $errormessage \n " ;
2670 print " </class> \n " ;
2671 & Header
:: closebox
();
2675 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
2676 print " $warnmessage <br>" ;
2677 print " $Lang ::tr{'fwdfw warn1'}<br>" ;
2678 & Header
:: closebox
();
2679 print "<center><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'ok'}' style='width: 5em;'></form>" ;
2680 & Header
:: closepage
();
2684 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'global settings' });
2686 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2687 <table width='100%'>
2689 <td width='20%' class='base' nowrap='nowrap'> $Lang ::tr{'vpn red name'}: <img src='/blob.gif' alt='*' /></td>
2690 <td width='20%'><input type='text' name='VPN_IP' value=' $cgiparams {'VPN_IP'}' /></td>
2691 <td width='20%' class='base'> $Lang ::tr{'enabled'}<input type='checkbox' name='ENABLED' $checked {'ENABLED'} /></td>
2697 <td class='base' nowrap='nowrap'> $Lang ::tr{'vpn delayed start'}: <img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' /></td>
2698 <td ><input type='text' name='VPN_DELAYED_START' value=' $cgiparams {'VPN_DELAYED_START'}' /></td>
2701 <td class='base' nowrap='nowrap'> $Lang ::tr{'host to net vpn'}:</td>
2702 <td ><input type='text' name='RW_NET' value=' $cgiparams {'RW_NET'}' /></td>
2707 <table width='100%'>
2709 <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
2710 <td width='70%' class='base' valign='top'> $Lang ::tr{'required field'}</td><td width='30%' align='right' class='base'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' /></td>
2713 <td class='base' valign='top' nowrap='nowrap'><img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' /> </td>
2714 <td class='base'> <font class='base'> $Lang ::tr{'vpn delayed start help'}</font></td>
2721 & Header
:: closebox
();
2723 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection status and controlc' });
2725 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
2727 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
2728 <th width='22%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></th>
2729 <th width='23%' class='boldbase' align='center'><b> $Lang ::tr{'common name'}</b></th>
2730 <th width='30%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></th>
2731 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></th>
2732 <th class='boldbase' align='center' colspan='6'><b> $Lang ::tr{'action'}</b></th>
2738 foreach my $key ( sort { ncmp
( $confighash { $a }[ 1 ], $confighash { $b }[ 1 ]) } keys %confighash ) {
2739 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
2743 $col = "bgcolor=' $color {'color20'}'" ;
2746 $col = "bgcolor=' $color {'color22'}'" ;
2748 print "<td align='center' nowrap='nowrap' $col > $confighash { $key }[1]</td>" ;
2749 print "<td align='center' nowrap='nowrap' $col >" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ") $confighash { $key }[29]</td>" ;
2750 if ( $confighash { $key }[ 2 ] eq ' %auth -dn' ) {
2751 print "<td align='left' nowrap='nowrap' $col > $confighash { $key }[9]</td>" ;
2752 } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
2753 print "<td align='left' nowrap='nowrap' $col > $confighash { $key }[2]</td>" ;
2755 print "<td align='left' $col > </td>" ;
2757 print "<td align='center' $col > $confighash { $key }[25]</td>" ;
2758 my $col1 = "bgcolor='${Header::colourred}'" ;
2760 my $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
2761 foreach my $line ( @status ) {
2762 if (( $line =~ /\"$confighash{$key}[1]\".*IPsec SA established/ ) ||
2763 ( $line =~ /$confighash{$key}[1]\{.*INSTALLED/ )) {
2764 $col1 = "bgcolor='${Header::colourgreen}'" ;
2765 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b>" ;
2768 # move to blue if really down
2769 if ( $confighash { $key }[ 0 ] eq 'off' && $col1 =~ /${Header::colourred}/ ) {
2770 $col1 = "bgcolor='${Header::colourblue}'" ;
2771 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
2774 <td align='center' $col1 > $active </td>
2775 <td align='center' $col >
2776 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2777 <input type='image' name=' $Lang ::tr{'restart'}' src='/images/reload.gif' alt=' $Lang ::tr{'restart'}' title=' $Lang ::tr{'restart'}' />
2778 <input type='hidden' name='ACTION' value=' $Lang ::tr{'restart'}' />
2779 <input type='hidden' name='KEY' value=' $key ' />
2784 if (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
2786 <td align='center' $col >
2787 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2788 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' />
2789 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
2790 <input type='hidden' name='KEY' value=' $key ' />
2796 print "<td width='2%' $col > </td>" ;
2798 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/certs/ $confighash { $key }[1].p12" ) {
2800 <td align='center' $col >
2801 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2802 <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'}' />
2803 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
2804 <input type='hidden' name='KEY' value=' $key ' />
2809 } elsif (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
2811 <td align='center' $col >
2812 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2813 <input type='image' name=' $Lang ::tr{'download certificate'}' src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' title=' $Lang ::tr{'download certificate'}' />
2814 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
2815 <input type='hidden' name='KEY' value=' $key ' />
2821 print "<td width='2%' $col > </td>" ;
2824 <td align='center' $col >
2825 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2826 <input type='image' name=' $Lang ::tr{'toggle enable disable'}' src='/images/ $gif ' alt=' $Lang ::tr{'toggle enable disable'}' title=' $Lang ::tr{'toggle enable disable'}' />
2827 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
2828 <input type='hidden' name='KEY' value=' $key ' />
2832 <td align='center' $col >
2833 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2834 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
2835 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' title=' $Lang ::tr{'edit'}' />
2836 <input type='hidden' name='KEY' value=' $key ' />
2839 <td align='center' $col >
2840 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2841 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
2842 <input type='image' name=' $Lang ::tr{'remove'}' src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' title=' $Lang ::tr{'remove'}' />
2843 <input type='hidden' name='KEY' value=' $key ' />
2853 # If the config file contains entries, print Key to action icons
2858 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
2859 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
2860 <td class='base'> $Lang ::tr{'click to disable'}</td>
2861 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
2862 <td class='base'> $Lang ::tr{'show certificate'}</td>
2863 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
2864 <td class='base'> $Lang ::tr{'edit'}</td>
2865 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
2866 <td class='base'> $Lang ::tr{'remove'}</td>
2870 <td> <img src='/images/off.gif' alt='?OFF' /></td>
2871 <td class='base'> $Lang ::tr{'click to enable'}</td>
2872 <td> <img src='/images/floppy.gif' alt='?FLOPPY' /></td>
2873 <td class='base'> $Lang ::tr{'download certificate'}</td>
2874 <td> <img src='/images/reload.gif' alt='?RELOAD'/></td>
2875 <td class='base'> $Lang ::tr{'restart'}</td>
2883 <table width='100%'>
2884 <tr><td align='right' colspan='9'>
2885 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2886 <input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />
2892 & Header
:: closebox
();
2894 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'certificate authorities'}" );
2896 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
2898 <th width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
2899 <th width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></th>
2900 <th width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></th>
2904 my $col1 = "bgcolor=' $color {'color22'}'" ;
2905 my $col2 = "bgcolor=' $color {'color20'}'" ;
2906 if (- f
"${General::swroot}/ca/cacert.pem" ) {
2907 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/cacert.pem" ));
2910 <td class='base' $col1 > $Lang ::tr{'root certificate'}</td>
2911 <td class='base' $col1 > $casubject </td>
2912 <td width='3%' align='center' $col1 >
2913 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2914 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
2915 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/info.gif' alt=' $Lang ::tr{'show root certificate'}' title=' $Lang ::tr{'show root certificate'}' />
2918 <td width='3%' align='center' $col1 >
2919 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2920 <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'}' />
2921 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
2924 <td width='4%' $col1 > </td></tr>
2928 # display rootcert generation buttons
2931 <td class='base' $col1 > $Lang ::tr{'root certificate'}:</td>
2932 <td class='base' $col1 > $Lang ::tr{'not present'}</td>
2933 <td colspan='3' $col1 > </td></tr>
2938 if (- f
"${General::swroot}/certs/hostcert.pem" ) {
2939 my $hostsubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/certs/hostcert.pem" ));
2943 <td class='base' $col2 > $Lang ::tr{'host certificate'}</td>
2944 <td class='base' $col2 > $hostsubject </td>
2945 <td width='3%' align='center' $col2 >
2946 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2947 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
2948 <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'}' />
2951 <td width='3%' align='center' $col2 >
2952 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2953 <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'}" />
2954 <input type='hidden' name='ACTION' value=" $Lang ::tr{'download host certificate'}" />
2957 <td width='4%' $col2 > </td></tr>
2964 <td width='25%' class='base' $col2 > $Lang ::tr{'host certificate'}:</td>
2965 <td class='base' $col2 > $Lang ::tr{'not present'}</td>
2966 <td colspan='3' $col2 > </td></tr>
2972 if ( keys %cahash > 0 ) {
2973 foreach my $key ( keys %cahash ) {
2974 if ( $rowcolor ++ % 2 ) {
2976 $col = "bgcolor=' $color {'color20'}'" ;
2979 $col = "bgcolor=' $color {'color22'}'" ;
2981 print "<td class='base' $col > $cahash { $key }[0]</td> \n " ;
2982 print "<td class='base' $col > $cahash { $key }[1]</td> \n " ;
2984 <td align='center' $col >
2985 <form method='post' name='cafrm${key}a' action=' $ENV {'SCRIPT_NAME'}'>
2986 <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'}' />
2987 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
2988 <input type='hidden' name='KEY' value=' $key ' />
2991 <td align='center' $col >
2992 <form method='post' name='cafrm${key}b' action=' $ENV {'SCRIPT_NAME'}'>
2993 <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'}' />
2994 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
2995 <input type='hidden' name='KEY' value=' $key ' />
2998 <td align='center' $col >
2999 <form method='post' name='cafrm${key}c' action=' $ENV {'SCRIPT_NAME'}'>
3000 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
3001 <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'}' />
3002 <input type='hidden' name='KEY' value=' $key ' />
3012 # If the file contains entries, print Key to action icons
3013 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
3016 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
3017 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
3018 <td class='base'> $Lang ::tr{'show certificate'}</td>
3019 <td> <img src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' /></td>
3020 <td class='base'> $Lang ::tr{'download certificate'}</td>
3025 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>" ;
3029 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
3030 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
3033 <td class='base' nowrap='nowrap'> $Lang ::tr{'ca name'}: <img src='/blob.gif' alt='*' /></td>
3034 <td nowrap='nowrap'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' /> </td>
3035 <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td>
3036 <td nowrap='nowrap'><input type='submit' name='ACTION' value=' $Lang ::tr{'upload ca certificate'}' /></td>
3039 <td colspan='3'> $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}:</td>
3040 <td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' /></td>
3046 & Header
:: closebox
();
3047 & Header
:: closebigbox
();
3048 & Header
:: closepage
();
3050 sub array_unique
($) {
3055 foreach my $e ( @
$array ) {
3056 next if $seen { $e }++;
3063 sub make_algos
($$$$$) {
3064 my ( $mode , $encs , $ints , $grps , $pfs ) = @_ ;
3067 foreach my $enc ( @
$encs ) {
3068 foreach my $int ( @
$ints ) {
3069 foreach my $grp ( @
$grps ) {
3072 if ( $mode eq "ike" ) {
3075 if ( $grp =~ m/^e(.*)$/ ) {
3076 push ( @algo , "ecp $1 " );
3078 push ( @algo , "modp $grp " );
3081 } elsif ( $mode eq "esp" && $pfs ) {
3082 my $is_aead = ( $enc =~ m/[cg]cm/ );
3088 if ( $grp eq "none" ) {
3090 } elsif ( $grp =~ m/^e(.*)$/ ) {
3091 push ( @algo , "ecp $1 " );
3093 push ( @algo , "modp $grp " );
3097 push ( @algos , join ( "-" , @algo ));
3102 return & array_unique
( \
@algos );