]>
git.ipfire.org Git - people/jschlag/ipfire-2.x.git/blob - html/cgi-bin/vpnmain.cgi
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
44 # (let the ipsec do its job)
53 my $errormessage = '' ;
56 my %mainsettings = ();
57 & General
:: readhash
( "${General::swroot}/main/settings" , \
%mainsettings );
58 & General
:: readhash
( "/srv/web/ipfire/html/themes/" . $mainsettings { 'THEME' }. "/include/colors.txt" , \
%color );
60 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%netsettings );
62 my $green_cidr = & General
:: ipcidr
( " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" );
63 my $blue_cidr = "# Blue not defined" ;
64 if (& Header
:: blue_used
() && $netsettings { 'BLUE_DEV' }) {
65 $blue_cidr = & General
:: ipcidr
( " $netsettings {'BLUE_NETADDRESS'}/ $netsettings {'BLUE_NETMASK'}" );
67 my $orange_cidr = "# Orange not defined" ;
68 if (& Header
:: orange_used
() && $netsettings { 'ORANGE_DEV' }) {
69 $orange_cidr = & General
:: ipcidr
( " $netsettings {'ORANGE_NETADDRESS'}/ $netsettings {'ORANGE_NETMASK'}" );
74 $cgiparams { 'ENABLED' } = 'off' ;
75 $cgiparams { 'EDIT_ADVANCED' } = 'off' ;
76 $cgiparams { 'ACTION' } = '' ;
77 $cgiparams { 'CA_NAME' } = '' ;
78 $cgiparams { 'KEY' } = '' ;
79 $cgiparams { 'TYPE' } = '' ;
80 $cgiparams { 'ADVANCED' } = '' ;
81 $cgiparams { 'NAME' } = '' ;
82 $cgiparams { 'LOCAL_SUBNET' } = '' ;
83 $cgiparams { 'REMOTE_SUBNET' } = '' ;
84 $cgiparams { 'REMOTE' } = '' ;
85 $cgiparams { 'LOCAL_ID' } = '' ;
86 $cgiparams { 'REMOTE_ID' } = '' ;
87 $cgiparams { 'REMARK' } = '' ;
88 $cgiparams { 'PSK' } = '' ;
89 $cgiparams { 'CERT_NAME' } = '' ;
90 $cgiparams { 'CERT_EMAIL' } = '' ;
91 $cgiparams { 'CERT_OU' } = '' ;
92 $cgiparams { 'CERT_ORGANIZATION' } = '' ;
93 $cgiparams { 'CERT_CITY' } = '' ;
94 $cgiparams { 'CERT_STATE' } = '' ;
95 $cgiparams { 'CERT_COUNTRY' } = '' ;
96 $cgiparams { 'SUBJECTALTNAME' } = '' ;
97 $cgiparams { 'CERT_PASS1' } = '' ;
98 $cgiparams { 'CERT_PASS2' } = '' ;
99 $cgiparams { 'ROOTCERT_HOSTNAME' } = '' ;
100 $cgiparams { 'ROOTCERT_COUNTRY' } = '' ;
101 $cgiparams { 'P12_PASS' } = '' ;
102 $cgiparams { 'ROOTCERT_ORGANIZATION' } = '' ;
103 $cgiparams { 'ROOTCERT_HOSTNAME' } = '' ;
104 $cgiparams { 'ROOTCERT_EMAIL' } = '' ;
105 $cgiparams { 'ROOTCERT_OU' } = '' ;
106 $cgiparams { 'ROOTCERT_CITY' } = '' ;
107 $cgiparams { 'ROOTCERT_STATE' } = '' ;
108 $cgiparams { 'RW_NET' } = '' ;
109 $cgiparams { 'DPD_DELAY' } = '30' ;
110 $cgiparams { 'DPD_TIMEOUT' } = '120' ;
111 $cgiparams { 'FORCE_MOBIKE' } = 'off' ;
112 & Header
:: getcgihash
( \
%cgiparams , { 'wantfile' => 1 , 'filevar' => 'FH' });
118 my $hostname = $_ [ 0 ];
119 unless ( $hostname ) { return "No hostname" };
120 my $res = new Net
:: DNS
:: Resolver
;
121 my $query = $res -> search ( " $hostname " );
123 foreach my $rr ( $query -> answer ) {
124 ## Potential bug - we are only looking at A records:
125 return 0 if $rr -> type eq "A" ;
128 return $res -> errorstring ;
132 ### Just return true is one interface is vpn enabled
135 return ( $vpnsettings { 'ENABLED' } eq 'on' );
138 ### old version: maintain serial number to one, without explication.
139 ### this : let the counter go, so that each cert is numbered.
143 if ( open ( FILE
, ">${General::swroot}/certs/serial" )) {
147 if ( open ( FILE
, ">${General::swroot}/certs/index.txt" )) {
151 unlink ( "${General::swroot}/certs/index.txt.old" );
152 unlink ( "${General::swroot}/certs/serial.old" );
153 unlink ( "${General::swroot}/certs/01.pem" );
155 sub newcleanssldatabase
157 if (! - s
"${General::swroot}/certs/serial" ) {
158 open ( FILE
, ">${General::swroot}/certs/serial" );
162 if (! - s
">${General::swroot}/certs/index.txt" ) {
163 system ( "touch ${General::swroot}/certs/index.txt" );
165 unlink ( "${General::swroot}/certs/index.txt.old" );
166 unlink ( "${General::swroot}/certs/serial.old" );
167 # unlink ("${General::swroot}/certs/01.pem"); numbering evolves. Wrong place to delete
171 ### Call openssl and return errormessage if any
175 my $retssl = `/usr/bin/openssl $opt 2>&1` ; #redirect stderr
177 foreach my $line ( split ( /\n/ , $retssl )) {
178 & General
:: log ( "ipsec" , " $line " ) if ( 0 ); # 1 for verbose logging
179 $ret .= '<br>' . $line if ( $line =~ /error|unknown/ );
182 $ret = & Header
:: cleanhtml
( $ret );
184 return $ret ?
" $Lang ::tr{'openssl produced an error'}: $ret " : '' ;
187 ### Obtain a CN from given cert
189 sub getCNfromcert
($) {
190 #&General::log("ipsec", "Extracting name from $_[0]...");
191 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
192 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
194 $temp =~ s
+/ Email
+, E
+;
195 $temp =~ s/ ST=/ S=/ ;
201 ### Obtain Subject from given cert
203 sub getsubjectfromcert
($) {
204 #&General::log("ipsec", "Extracting subject from $_[0]...");
205 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
206 $temp =~ /Subject: (.*)[\n]/ ;
208 $temp =~ s
+/ Email
+, E
+;
209 $temp =~ s/ ST=/ S=/ ;
213 ### Combine local subnet and connection name to make a unique name for each connection section
214 ### (this sub is not used now)
216 sub makeconnname
($) {
220 $subnet =~ /^(.*?)\/ (.* ?
)$/; # $1=IP $2=mask
221 my $ip = unpack ( 'N' , & Socket
:: inet_aton
( $1 ));
222 if ( length ( $2 ) > 2 ) {
223 my $mm = unpack ( 'N' , & Socket
:: inet_aton
( $2 ));
224 while ( ( $mm & 1 )== 0 ) {
231 return sprintf ( " %s - %X " , $conn , $ip );
234 ### Write a config file.
236 ###Type=Host : GUI can choose the interface used (RED,GREEN,BLUE) and
237 ### the side is always defined as 'left'.
238 ### configihash[14]: 'VHOST' is allowed
241 sub writeipsecfiles
{
242 my %lconfighash = ();
243 my %lvpnsettings = ();
244 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%lconfighash );
245 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%lvpnsettings );
247 open ( CONF
, ">${General::swroot}/vpn/ipsec.conf" ) or die "Unable to open ${General::swroot}/vpn/ipsec.conf: $!" ;
248 open ( SECRETS
, ">${General::swroot}/vpn/ipsec.secrets" ) or die "Unable to open ${General::swroot}/vpn/ipsec.secrets: $!" ;
251 print CONF
"version 2 \n\n " ;
252 print CONF
"conn %default \n " ;
253 print CONF
" \t keyingtries= %forever \n " ;
256 # Add user includes to config file
257 if (- e
"/etc/ipsec.user.conf" ) {
258 print CONF
"include /etc/ipsec.user.conf \n " ;
262 print SECRETS
"include /etc/ipsec.user.secrets \n " ;
264 if (- f
"${General::swroot}/certs/hostkey.pem" ) {
265 print SECRETS
": RSA ${General::swroot}/certs/hostkey.pem \n "
267 my $last_secrets = '' ; # old the less specifics connections
269 foreach my $key ( keys %lconfighash ) {
270 next if ( $lconfighash { $key }[ 0 ] ne 'on' );
272 #remote peer is not set? => use '%any'
273 $lconfighash { $key }[ 10 ] = ' %any ' if ( $lconfighash { $key }[ 10 ] eq '' );
276 if ( $lconfighash { $key }[ 26 ] eq 'BLUE' ) {
277 $localside = $netsettings { 'BLUE_ADDRESS' };
278 } elsif ( $lconfighash { $key }[ 26 ] eq 'GREEN' ) {
279 $localside = $netsettings { 'GREEN_ADDRESS' };
280 } elsif ( $lconfighash { $key }[ 26 ] eq 'ORANGE' ) {
281 $localside = $netsettings { 'ORANGE_ADDRESS' };
283 $localside = $lvpnsettings { 'VPN_IP' };
286 print CONF
"conn $lconfighash { $key }[1] \n " ;
287 print CONF
" \t left= $localside \n " ;
288 my $cidr_net =& General
:: ipcidr
( $lconfighash { $key }[ 8 ]);
289 print CONF
" \t leftsubnet= $cidr_net \n " ;
290 print CONF
" \t leftfirewall=yes \n " ;
291 print CONF
" \t lefthostaccess=yes \n " ;
293 print CONF
" \t right= $lconfighash { $key }[10] \n " ;
294 if ( $lconfighash { $key }[ 3 ] eq 'net' ) {
295 my $cidr_net =& General
:: ipcidr
( $lconfighash { $key }[ 11 ]);
296 print CONF
" \t rightsubnet= $cidr_net \n " ;
297 } elsif ( $lconfighash { $key }[ 10 ] eq ' %any ' && $lconfighash { $key }[ 14 ] eq 'on' ) { #vhost allowed for roadwarriors?
298 print CONF
" \t rightsubnet=vhost: %no , %priv \n " ;
301 # Local Cert and Remote Cert (unless auth is DN dn-auth)
302 if ( $lconfighash { $key }[ 4 ] eq 'cert' ) {
303 print CONF
" \t leftcert=${General::swroot}/certs/hostcert.pem \n " ;
304 print CONF
" \t rightcert=${General::swroot}/certs/ $lconfighash { $key }[1]cert.pem \n " if ( $lconfighash { $key }[ 2 ] ne ' %auth -dn' );
307 # Local and Remote IDs
308 print CONF
" \t leftid= \" $lconfighash { $key }[7] \"\n " if ( $lconfighash { $key }[ 7 ]);
309 print CONF
" \t rightid= \" $lconfighash { $key }[9] \"\n " if ( $lconfighash { $key }[ 9 ]);
312 my $pfs = $lconfighash { $key }[ 28 ] eq 'on' ?
'on' : 'off' ;
315 if ( $lconfighash { $key }[ 18 ] && $lconfighash { $key }[ 19 ] && $lconfighash { $key }[ 20 ]) {
316 my @encs = split ( '\|' , $lconfighash { $key }[ 18 ]);
317 my @ints = split ( '\|' , $lconfighash { $key }[ 19 ]);
318 my @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
320 my @algos = & make_algos
( "ike" , \
@encs , \
@ints , \
@groups , 1 );
321 print CONF
" \t ike=" . join ( "," , @algos );
323 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
330 if ( $lconfighash { $key }[ 21 ] && $lconfighash { $key }[ 22 ]) {
331 my @encs = split ( '\|' , $lconfighash { $key }[ 21 ]);
332 my @ints = split ( '\|' , $lconfighash { $key }[ 22 ]);
333 my @groups = split ( '\|' , $lconfighash { $key }[ 23 ]);
335 # Use IKE grouptype if no ESP group type has been selected
336 # (for backwards compatibility)
337 if ( $lconfighash { $key }[ 23 ] eq "" ) {
338 @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
341 my @algos = & make_algos
( "esp" , \
@encs , \
@ints , \
@groups , ( $pfs eq "on" ));
342 print CONF
" \t esp=" . join ( "," , @algos );
344 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
352 if (! $lconfighash { $key }[ 29 ]) {
353 $lconfighash { $key }[ 29 ] = "ikev1" ;
355 print CONF
" \t keyexchange= $lconfighash { $key }[29] \n " ;
358 print CONF
" \t ikelifetime= $lconfighash { $key }[16]h \n " if ( $lconfighash { $key }[ 16 ]);
359 print CONF
" \t keylife= $lconfighash { $key }[17]h \n " if ( $lconfighash { $key }[ 17 ]);
362 print CONF
" \t compress=yes \n " if ( $lconfighash { $key }[ 13 ] eq 'on' );
365 if (( $lconfighash { $key }[ 29 ] eq "ikev2" ) && ( $lconfighash { $key }[ 32 ] eq 'on' )) {
366 print CONF
" \t mobike=yes \n " ;
369 # Dead Peer Detection
370 my $dpdaction = $lconfighash { $key }[ 27 ];
371 print CONF
" \t dpdaction= $dpdaction \n " ;
373 # If the dead peer detection is disabled and IKEv2 is used,
374 # dpddelay must be set to zero, too.
375 if ( $dpdaction eq "none" ) {
376 if ( $lconfighash { $key }[ 29 ] eq "ikev2" ) {
377 print CONF
" \t dpddelay=0 \n " ;
380 my $dpddelay = $lconfighash { $key }[ 31 ];
384 print CONF
" \t dpddelay= $dpddelay \n " ;
385 my $dpdtimeout = $lconfighash { $key }[ 30 ];
389 print CONF
" \t dpdtimeout= $dpdtimeout \n " ;
392 # Build Authentication details: LEFTid RIGHTid : PSK psk
394 if ( $lconfighash { $key }[ 4 ] eq 'psk' ) {
395 $psk_line = ( $lconfighash { $key }[ 7 ] ?
$lconfighash { $key }[ 7 ] : $localside ) . " " ;
396 $psk_line .= $lconfighash { $key }[ 9 ] ?
$lconfighash { $key }[ 9 ] : $lconfighash { $key }[ 10 ]; #remoteid or remote address?
397 $psk_line .= " : PSK ' $lconfighash { $key }[5]' \n " ;
398 # if the line contains %any, it is less specific than two IP or ID, so move it at end of file.
399 if ( $psk_line =~ /%any/ ) {
400 $last_secrets .= $psk_line ;
402 print SECRETS
$psk_line ;
404 print CONF
" \t authby=secret \n " ;
406 print CONF
" \t authby=rsasig \n " ;
407 print CONF
" \t leftrsasigkey= %cert \n " ;
408 print CONF
" \t rightrsasigkey= %cert \n " ;
411 # Automatically start only if a net-to-net connection
412 if ( $lconfighash { $key }[ 3 ] eq 'host' ) {
413 print CONF
" \t auto=add \n " ;
414 print CONF
" \t rightsourceip= $lvpnsettings {'RW_NET'} \n " ;
416 print CONF
" \t auto=start \n " ;
420 print CONF
" \t fragmentation=yes \n " ;
425 # Add post user includes to config file
426 # After the GUI-connections allows to patch connections.
427 if (- e
"/etc/ipsec.user-post.conf" ) {
428 print CONF
"include /etc/ipsec.user-post.conf \n " ;
432 print SECRETS
$last_secrets if ( $last_secrets );
437 # Hook to regenerate the configuration files.
438 if ( $ENV { "REMOTE_ADDR" } eq "" ) {
444 ### Save main settings
446 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
447 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
448 unless (& General
:: validfqdn
( $cgiparams { 'VPN_IP' }) || & General
:: validip
( $cgiparams { 'VPN_IP' })
449 || $cgiparams { 'VPN_IP' } eq ' %defaultroute ' ) {
450 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
454 unless ( $cgiparams { 'VPN_DELAYED_START' } =~ /^[0-9]{1,3}$/ ) { #allow 0-999 seconds !
455 $errormessage = $Lang :: tr
{ 'invalid time period' };
459 if ( $cgiparams { 'RW_NET' } ne '' and !& General
:: validipandmask
( $cgiparams { 'RW_NET' }) ) {
460 $errormessage = $Lang :: tr
{ 'urlfilter invalid ip or mask error' };
464 $vpnsettings { 'ENABLED' } = $cgiparams { 'ENABLED' };
465 $vpnsettings { 'VPN_IP' } = $cgiparams { 'VPN_IP' };
466 $vpnsettings { 'VPN_DELAYED_START' } = $cgiparams { 'VPN_DELAYED_START' };
467 $vpnsettings { 'RW_NET' } = $cgiparams { 'RW_NET' };
468 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
471 system ( '/usr/local/bin/ipsecctrl' , 'S' );
473 system ( '/usr/local/bin/ipsecctrl' , 'D' );
480 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
481 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
483 foreach my $key ( keys %confighash ) {
484 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
485 delete $confighash { $key };
488 while ( my $file = glob ( "${General::swroot}/{ca,certs,crls,private}/*" )) {
492 if ( open ( FILE
, ">${General::swroot}/vpn/caconfig" )) {
496 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
498 system ( '/usr/local/bin/ipsecctrl' , 'R' );
504 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' }) {
505 & Header
:: showhttpheaders
();
506 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
507 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
508 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
510 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
514 <input type='hidden' name='AREUSURE' value='yes' />
515 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
516 $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}</td>
519 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' />
520 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
527 & Header
:: closebigbox
();
528 & Header
:: closepage
();
532 ### Upload CA Certificate
534 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
535 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
537 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
538 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
542 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
543 $errormessage = $Lang :: tr
{ 'name too long' };
547 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
548 $errormessage = $Lang :: tr
{ 'name is invalid' };
549 goto UPLOAD_CA_ERROR
;
552 # Check if there is no other entry with this name
553 foreach my $key ( keys %cahash ) {
554 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
555 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
560 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
561 $errormessage = $Lang :: tr
{ 'there was no file upload' };
564 # Move uploaded ca to a temporary file
565 ( my $fh , my $filename ) = tempfile
( );
566 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
570 my $temp = `/usr/bin/openssl x509 -text -in $filename ` ;
571 if ( $temp !~ /CA:TRUE/i ) {
572 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
576 move
( $filename , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
578 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
584 my $key = & General
:: findhasharraykey
( \
%cahash );
585 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
586 $cahash { $key }[ 1 ] = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" ));
587 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
589 system ( '/usr/local/bin/ipsecctrl' , 'R' );
595 ### Display ca certificate
597 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
598 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
600 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
601 & Header
:: showhttpheaders
();
602 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
603 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
604 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'ca certificate'}:" );
605 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
606 $output = & Header
:: cleanhtml
( $output , "y" );
607 print "<pre> $output </pre> \n " ;
609 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
610 & Header
:: closebigbox
();
611 & Header
:: closepage
();
614 $errormessage = $Lang :: tr
{ 'invalid key' };
618 ### Export ca certificate to browser
620 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
621 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
623 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
624 print "Content-Type: application/force-download \n " ;
625 print "Content-Type: application/octet-stream \r\n " ;
626 print "Content-Disposition: attachment; filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
627 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
630 $errormessage = $Lang :: tr
{ 'invalid key' };
634 ### Remove ca certificate (step 2)
636 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
637 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
638 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
640 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
641 foreach my $key ( keys %confighash ) {
642 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
643 if ( $test =~ /: OK/ ) {
645 system ( '/usr/local/bin/ipsecctrl' , 'D' , $key ) if (& vpnenabled
);
646 unlink ( "${General::swroot}/certs/ $confighash { $key }[1]cert.pem" );
647 unlink ( "${General::swroot}/certs/ $confighash { $key }[1].p12" );
648 delete $confighash { $key };
649 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
653 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
654 delete $cahash { $cgiparams { 'KEY' }};
655 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
656 system ( '/usr/local/bin/ipsecctrl' , 'R' );
659 $errormessage = $Lang :: tr
{ 'invalid key' };
662 ### Remove ca certificate (step 1)
664 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
665 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
666 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
668 my $assignedcerts = 0 ;
669 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
670 foreach my $key ( keys %confighash ) {
671 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
672 if ( $test =~ /: OK/ ) {
676 if ( $assignedcerts ) {
677 & Header
:: showhttpheaders
();
678 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
679 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
680 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
682 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
686 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
687 <input type='hidden' name='AREUSURE' value='yes' /></td>
690 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>
691 $Lang ::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}</td>
694 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
695 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
702 & Header
:: closebigbox
();
703 & Header
:: closepage
();
706 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
707 delete $cahash { $cgiparams { 'KEY' }};
708 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
709 system ( '/usr/local/bin/ipsecctrl' , 'R' );
713 $errormessage = $Lang :: tr
{ 'invalid key' };
717 ### Display root certificate
719 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
720 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
722 & Header
:: showhttpheaders
();
723 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
724 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
725 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
726 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'root certificate'}:" );
727 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/cacert.pem` ;
729 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'host certificate'}:" );
730 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/hostcert.pem` ;
732 $output = & Header
:: cleanhtml
( $output , "y" );
733 print "<pre> $output </pre> \n " ;
735 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
736 & Header
:: closebigbox
();
737 & Header
:: closepage
();
741 ### Export root certificate to browser
743 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
744 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
745 print "Content-Type: application/force-download \n " ;
746 print "Content-Disposition: attachment; filename=cacert.pem \r\n\r\n " ;
747 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/cacert.pem` ;
751 ### Export host certificate to browser
753 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
754 if ( - f
"${General::swroot}/certs/hostcert.pem" ) {
755 print "Content-Type: application/force-download \n " ;
756 print "Content-Disposition: attachment; filename=hostcert.pem \r\n\r\n " ;
757 print `/usr/bin/openssl x509 -in ${General::swroot}/certs/hostcert.pem` ;
761 ### Form for generating/importing the caroot+host certificate
763 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
764 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
766 if (- f
"${General::swroot}/ca/cacert.pem" ) {
767 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
771 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
772 # fill in initial values
773 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
774 if (- e
"${General::swroot}/red/active" && open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
775 my $ipaddr = < IPADDR
>;
778 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
779 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
780 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
783 $cgiparams { 'ROOTCERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' } if (! $cgiparams { 'ROOTCERT_COUNTRY' });
784 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
785 & General
:: log ( "ipsec" , "Importing from p12..." );
787 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
788 $errormessage = $Lang :: tr
{ 'there was no file upload' };
792 # Move uploaded certificate request to a temporary file
793 ( my $fh , my $filename ) = tempfile
( );
794 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
799 # Extract the CA certificate from the file
800 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
801 if ( open ( STDIN
, "-|" )) {
802 my $opt = " pkcs12 -cacerts -nokeys" ;
803 $opt .= " -in $filename " ;
804 $opt .= " -out /tmp/newcacert" ;
805 $errormessage = & callssl
( $opt );
807 print " $cgiparams {'P12_PASS'} \n " ;
811 # Extract the Host certificate from the file
812 if (! $errormessage ) {
813 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
814 if ( open ( STDIN
, "-|" )) {
815 my $opt = " pkcs12 -clcerts -nokeys" ;
816 $opt .= " -in $filename " ;
817 $opt .= " -out /tmp/newhostcert" ;
818 $errormessage = & callssl
( $opt );
820 print " $cgiparams {'P12_PASS'} \n " ;
825 # Extract the Host key from the file
826 if (! $errormessage ) {
827 & General
:: log ( "ipsec" , "Extracting private key from p12..." );
828 if ( open ( STDIN
, "-|" )) {
829 my $opt = " pkcs12 -nocerts -nodes" ;
830 $opt .= " -in $filename " ;
831 $opt .= " -out /tmp/newhostkey" ;
832 $errormessage = & callssl
( $opt );
834 print " $cgiparams {'P12_PASS'} \n " ;
839 if (! $errormessage ) {
840 & General
:: log ( "ipsec" , "Moving cacert..." );
841 move
( "/tmp/newcacert" , "${General::swroot}/ca/cacert.pem" );
842 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
845 if (! $errormessage ) {
846 & General
:: log ( "ipsec" , "Moving host cert..." );
847 move
( "/tmp/newhostcert" , "${General::swroot}/certs/hostcert.pem" );
848 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
851 if (! $errormessage ) {
852 & General
:: log ( "ipsec" , "Moving private key..." );
853 move
( "/tmp/newhostkey" , "${General::swroot}/certs/hostkey.pem" );
854 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
859 unlink ( '/tmp/newcacert' );
860 unlink ( '/tmp/newhostcert' );
861 unlink ( '/tmp/newhostkey' );
863 unlink ( "${General::swroot}/ca/cacert.pem" );
864 unlink ( "${General::swroot}/certs/hostcert.pem" );
865 unlink ( "${General::swroot}/certs/hostkey.pem" );
869 # Create empty CRL cannot be done because we don't have
870 # the private key for this CAROOT
871 # IPFire can only import certificates
873 & General
:: log ( "ipsec" , "p12 import completed!" );
875 goto ROOTCERT_SUCCESS
;
877 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
879 # Validate input since the form was submitted
880 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
881 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
884 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
885 $errormessage = $Lang :: tr
{ 'organization too long' };
888 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
889 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
892 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
893 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
896 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
897 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
900 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
901 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
904 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
905 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
908 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
909 $errormessage = $Lang :: tr
{ 'invalid input for department' };
912 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
913 $errormessage = $Lang :: tr
{ 'invalid input for city' };
916 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
917 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
920 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
921 $errormessage = $Lang :: tr
{ 'invalid input for country' };
924 #the exact syntax is a list comma separated of
925 # email:any-validemail
926 # URI: a uniform resource indicator
927 # DNS: a DNS domain name
928 # RID: a registered OBJECT IDENTIFIER
930 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
932 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
933 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
937 # Copy the cgisettings to vpnsettings and save the configfile
938 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
939 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
940 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
941 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
942 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
943 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
944 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
945 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
947 # Replace empty strings with a .
948 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
949 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
950 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
952 # Create the CA certificate
953 if (! $errormessage ) {
954 & General
:: log ( "ipsec" , "Creating cacert..." );
955 if ( open ( STDIN
, "-|" )) {
956 my $opt = " req -x509 -sha256 -nodes" ;
957 $opt .= " -days 999999" ;
958 $opt .= " -newkey rsa:4096" ;
959 $opt .= " -keyout ${General::swroot}/private/cakey.pem" ;
960 $opt .= " -out ${General::swroot}/ca/cacert.pem" ;
962 $errormessage = & callssl
( $opt );
964 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
967 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
969 print " $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
970 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
975 # Create the Host certificate request
976 if (! $errormessage ) {
977 & General
:: log ( "ipsec" , "Creating host cert..." );
978 if ( open ( STDIN
, "-|" )) {
979 my $opt = " req -sha256 -nodes" ;
980 $opt .= " -newkey rsa:2048" ;
981 $opt .= " -keyout ${General::swroot}/certs/hostkey.pem" ;
982 $opt .= " -out ${General::swroot}/certs/hostreq.pem" ;
983 $errormessage = & callssl
( $opt );
985 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
988 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
990 print " $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
991 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
998 # Sign the host certificate request
999 if (! $errormessage ) {
1000 & General
:: log ( "ipsec" , "Self signing host cert..." );
1002 #No easy way for specifying the contain of subjectAltName without writing a config file...
1003 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1005 basicConstraints=CA:FALSE
1006 nsComment="OpenSSL Generated Certificate"
1007 subjectKeyIdentifier=hash
1008 authorityKeyIdentifier=keyid,issuer:always
1009 extendedKeyUsage = serverAuth
1012 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1015 my $opt = " ca -md sha256 -days 999999" ;
1016 $opt .= " -batch -notext" ;
1017 $opt .= " -in ${General::swroot}/certs/hostreq.pem" ;
1018 $opt .= " -out ${General::swroot}/certs/hostcert.pem" ;
1019 $opt .= " -extfile $v3extname " ;
1020 $errormessage = & callssl
( $opt );
1021 unlink ( "${General::swroot}/certs/hostreq.pem" ); #no more needed
1022 unlink ( $v3extname );
1025 # Create an empty CRL
1026 if (! $errormessage ) {
1027 & General
:: log ( "ipsec" , "Creating emptycrl..." );
1028 my $opt = " ca -gencrl" ;
1029 $opt .= " -out ${General::swroot}/crls/cacrl.pem" ;
1030 $errormessage = & callssl
( $opt );
1033 # Successfully build CA / CERT!
1034 if (! $errormessage ) {
1035 & cleanssldatabase
();
1036 goto ROOTCERT_SUCCESS
;
1040 unlink ( "${General::swroot}/ca/cacert.pem" );
1041 unlink ( "${General::swroot}/certs/hostkey.pem" );
1042 unlink ( "${General::swroot}/certs/hostcert.pem" );
1043 unlink ( "${General::swroot}/crls/cacrl.pem" );
1044 & cleanssldatabase
();
1048 & Header
:: showhttpheaders
();
1049 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1050 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1051 if ( $errormessage ) {
1052 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1053 print "<class name='base'> $errormessage " ;
1054 print " </class>" ;
1055 & Header
:: closebox
();
1057 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
1059 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
1060 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1061 <tr><td width='40%' class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
1062 <td width='60%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td></tr>
1063 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}: <img src='/blob.gif' alt='*' /></td>
1064 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td></tr>
1065 <tr><td class='base'> $Lang ::tr{'your e-mail'}:</td>
1066 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td></tr>
1067 <tr><td class='base'> $Lang ::tr{'your department'}:</td>
1068 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td></tr>
1069 <tr><td class='base'> $Lang ::tr{'city'}:</td>
1070 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td></tr>
1071 <tr><td class='base'> $Lang ::tr{'state or province'}:</td>
1072 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td></tr>
1073 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1074 <td class='base'><select name='ROOTCERT_COUNTRY'>
1077 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1078 print "<option value=' $Countries ::countries{ $country }'" ;
1079 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1080 print " selected='selected'" ;
1082 print "> $country </option>" ;
1086 <tr><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)</td>
1087 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' /></td></tr>
1089 <td><br /><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /><br /><br /></td></tr>
1090 <tr><td class='base' colspan='2' align='left'>
1091 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1092 $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'}
1094 <tr><td colspan='2'><hr></td></tr>
1095 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}:</td>
1096 <td nowrap='nowrap'><input type='file' name='FH' size='32' /></td></tr>
1097 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
1098 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td></tr>
1100 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td></tr>
1101 <tr><td class='base' colspan='2' align='left'>
1102 <img src='/blob.gif' alt='*' /> $Lang ::tr{'required field'}</td></tr>
1106 & Header
:: closebox
();
1107 & Header
:: closebigbox
();
1108 & Header
:: closepage
();
1113 system ( '/usr/local/bin/ipsecctrl' , 'S' );
1118 ### Export PKCS12 file to browser
1120 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
1121 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1122 print "Content-Type: application/force-download \n " ;
1123 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
1124 print "Content-Type: application/octet-stream \r\n\r\n " ;
1125 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12` ;
1129 ### Display certificate
1131 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
1132 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1134 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1135 & Header
:: showhttpheaders
();
1136 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1137 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1138 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'cert'}:" );
1139 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1140 $output = & Header
:: cleanhtml
( $output , "y" );
1141 print "<pre> $output </pre> \n " ;
1142 & Header
:: closebox
();
1143 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1144 & Header
:: closebigbox
();
1145 & Header
:: closepage
();
1150 ### Export Certificate to browser
1152 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
1153 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1155 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1156 print "Content-Type: application/force-download \n " ;
1157 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \n\n " ;
1158 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1163 ### Enable/Disable connection
1165 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1167 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1168 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1170 if ( $confighash { $cgiparams { 'KEY' }}) {
1171 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
1172 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
1173 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1175 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1177 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1178 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
1179 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1184 $errormessage = $Lang :: tr
{ 'invalid key' };
1188 ### Restart connection
1190 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
1191 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1192 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1194 if ( $confighash { $cgiparams { 'KEY' }}) {
1196 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
1200 $errormessage = $Lang :: tr
{ 'invalid key' };
1204 ### Remove connection
1206 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
1207 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1208 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1210 if ( $confighash { $cgiparams { 'KEY' }}) {
1211 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1212 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1213 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1214 delete $confighash { $cgiparams { 'KEY' }};
1215 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1218 $errormessage = $Lang :: tr
{ 'invalid key' };
1220 & General
:: firewall_reload
();
1222 ### Choose between adding a host-net or net-net connection
1224 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
1225 & Header
:: showhttpheaders
();
1226 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1227 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1228 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection type' });
1230 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
1231 <b> $Lang ::tr{'connection type'}:</b><br />
1233 <tr><td><input type='radio' name='TYPE' value='host' checked='checked' /></td>
1234 <td class='base'> $Lang ::tr{'host to net vpn'}</td>
1236 <td><input type='radio' name='TYPE' value='net' /></td>
1237 <td class='base'> $Lang ::tr{'net to net vpn'}</td>
1239 <td align='center' colspan='2'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td>
1244 & Header
:: closebox
();
1245 & Header
:: closebigbox
();
1246 & Header
:: closepage
();
1249 ### Adding/Editing/Saving a connection
1251 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
1252 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
1253 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
1255 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1256 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1257 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1259 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
1260 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
1261 $errormessage = $Lang :: tr
{ 'invalid key' };
1264 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
1265 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
1266 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
1267 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
1268 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
1269 #$cgiparams{'free'} = $confighash{$cgiparams{'KEY'}}[6];
1270 $cgiparams { 'LOCAL_ID' } = $confighash { $cgiparams { 'KEY' }}[ 7 ];
1271 $cgiparams { 'LOCAL_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 8 ];
1272 $cgiparams { 'REMOTE_ID' } = $confighash { $cgiparams { 'KEY' }}[ 9 ];
1273 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
1274 $cgiparams { 'REMOTE_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 11 ];
1275 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
1276 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
1277 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
1278 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
1279 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
1280 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
1281 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
1282 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
1283 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
1284 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
1285 if ( $cgiparams { 'ESP_GROUPTYPE' } eq "" ) {
1286 $cgiparams { 'ESP_GROUPTYPE' } = $cgiparams { 'IKE_GROUPTYPE' };
1288 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
1289 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
1290 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
1291 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
1292 $cgiparams { 'VHOST' } = $confighash { $cgiparams { 'KEY' }}[ 14 ];
1293 $cgiparams { 'DPD_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
1294 $cgiparams { 'DPD_DELAY' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
1295 $cgiparams { 'FORCE_MOBIKE' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
1297 if (! $cgiparams { 'DPD_DELAY' }) {
1298 $cgiparams { 'DPD_DELAY' } = 30 ;
1301 if (! $cgiparams { 'DPD_TIMEOUT' }) {
1302 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
1305 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
1306 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
1307 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
1308 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
1312 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
1313 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
1317 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
1318 $errormessage = $Lang :: tr
{ 'name is invalid' };
1322 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
1323 $errormessage = $Lang :: tr
{ 'name too long' };
1327 # Check if there is no other entry with this name
1328 if (! $cgiparams { 'KEY' }) { #only for add
1329 foreach my $key ( keys %confighash ) {
1330 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
1331 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
1337 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! $cgiparams { 'REMOTE' })) {
1338 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1342 if ( $cgiparams { 'REMOTE' }) {
1343 if (( $cgiparams { 'REMOTE' } ne ' %any ' ) && (! & General
:: validip
( $cgiparams { 'REMOTE' }))) {
1344 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
1345 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1348 if (& valid_dns_host
( $cgiparams { 'REMOTE' })) {
1349 $warnmessage = " $Lang ::tr{'check vpn lr'} $cgiparams {'REMOTE'}. $Lang ::tr{'dns check failed'}" ;
1355 unless (& General
:: validipandmask
( $cgiparams { 'LOCAL_SUBNET' })) {
1356 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
1360 # Allow only one roadwarrior/psk without remote IP-address
1361 if ( $cgiparams { 'REMOTE' } eq '' && $cgiparams { 'AUTH' } eq 'psk' ) {
1362 foreach my $key ( keys %confighash ) {
1363 if ( ( $cgiparams { 'KEY' } ne $key ) &&
1364 ( $confighash { $key }[ 4 ] eq 'psk' ) &&
1365 ( $confighash { $key }[ 10 ] eq '' ) ) {
1366 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
1371 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! & General
:: validipandmask
( $cgiparams { 'REMOTE_SUBNET' }))) {
1372 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
1376 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
1377 $errormessage = $Lang :: tr
{ 'invalid input' };
1380 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
1381 $errormessage = $Lang :: tr
{ 'invalid input' };
1385 # Allow nothing or a string (DN,FDQN,) beginning with @
1386 # with no comma but slashes between RID eg @O=FR/C=Paris/OU=myhome/CN=franck
1387 if ( ( $cgiparams { 'LOCAL_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1388 ( $cgiparams { 'REMOTE_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1389 (( $cgiparams { 'REMOTE_ID' } eq $cgiparams { 'LOCAL_ID' }) && ( $cgiparams { 'LOCAL_ID' } ne '' ))
1391 $errormessage = $Lang :: tr
{ 'invalid local-remote id' } . '<br />' .
1392 'DER_ASN1_DN: @c =FR/ou=Paris/ou=Home/cn=*<br />' .
1393 'FQDN: @ipfire .org<br />' .
1394 'USER_FQDN: info @ipfire .org<br />' .
1395 'IPV4_ADDR: 123.123.123.123' ;
1398 # If Auth is DN, verify existance of Remote ID.
1399 if ( $cgiparams { 'REMOTE_ID' } eq '' && (
1400 $cgiparams { 'AUTH' } eq 'auth-dn' || # while creation
1401 $confighash { $cgiparams { 'KEY' }}[ 2 ] eq ' %auth -dn' )){ # while editing
1402 $errormessage = $Lang :: tr
{ 'vpn missing remote id' };
1406 if ( $cgiparams { 'TYPE' } eq 'net' ){
1407 $warnmessage =& General
:: checksubnets
( '' , $cgiparams { 'REMOTE_SUBNET' }, 'ipsec' );
1408 if ( $warnmessage ne '' ){
1409 $warnmessage = $Lang :: tr
{ 'remote subnet' }. " ( $cgiparams {'REMOTE_SUBNET'}) <br>" . $warnmessage ;
1413 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1414 if (! length ( $cgiparams { 'PSK' }) ) {
1415 $errormessage = $Lang :: tr
{ 'pre-shared key is too short' };
1418 if ( $cgiparams { 'PSK' } =~ /'/ ) {
1419 $cgiparams { 'PSK' } =~ tr/'/ / ;
1420 $errormessage = $Lang :: tr
{ 'invalid characters found in pre-shared key' };
1423 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
1424 if ( $cgiparams { 'KEY' }) {
1425 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1428 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1429 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1433 # Move uploaded certificate request to a temporary file
1434 ( my $fh , my $filename ) = tempfile
( );
1435 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1440 # Sign the certificate request
1441 & General
:: log ( "ipsec" , "Signing your cert $cgiparams {'NAME'}..." );
1442 my $opt = " ca -md sha256 -days 999999" ;
1443 $opt .= " -batch -notext" ;
1444 $opt .= " -in $filename " ;
1445 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1447 if ( $errormessage = & callssl
( $opt ) ) {
1449 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1450 & cleanssldatabase
();
1454 & cleanssldatabase
();
1457 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1458 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1459 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1462 } elsif ( $cgiparams { 'AUTH' } eq 'pkcs12' ) {
1463 & General
:: log ( "ipsec" , "Importing from p12..." );
1465 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1466 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1467 goto ROOTCERT_ERROR
;
1470 # Move uploaded certificate request to a temporary file
1471 ( my $fh , my $filename ) = tempfile
( );
1472 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1474 goto ROOTCERT_ERROR
;
1477 # Extract the CA certificate from the file
1478 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
1479 if ( open ( STDIN
, "-|" )) {
1480 my $opt = " pkcs12 -cacerts -nokeys" ;
1481 $opt .= " -in $filename " ;
1482 $opt .= " -out /tmp/newcacert" ;
1483 $errormessage = & callssl
( $opt );
1485 print " $cgiparams {'P12_PASS'} \n " ;
1489 # Extract the Host certificate from the file
1490 if (! $errormessage ) {
1491 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
1492 if ( open ( STDIN
, "-|" )) {
1493 my $opt = " pkcs12 -clcerts -nokeys" ;
1494 $opt .= " -in $filename " ;
1495 $opt .= " -out /tmp/newhostcert" ;
1496 $errormessage = & callssl
( $opt );
1498 print " $cgiparams {'P12_PASS'} \n " ;
1503 if (! $errormessage ) {
1504 & General
:: log ( "ipsec" , "Moving cacert..." );
1505 #If CA have new subject, add it to our list of CA
1506 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( '/tmp/newcacert' ));
1508 foreach my $x ( keys %cahash ) {
1509 $casubject = '' if ( $cahash { $x }[ 1 ] eq $casubject );
1510 unshift ( @names , $cahash { $x }[ 0 ]);
1512 if ( $casubject ) { # a new one!
1513 my $temp = `/usr/bin/openssl x509 -text -in /tmp/newcacert` ;
1514 if ( $temp !~ /CA:TRUE/i ) {
1515 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
1517 #compute a name for it
1519 while ( grep ( /Imported-$idx/ , @names ) ) { $idx ++};
1520 $cgiparams { 'CA_NAME' }= "Imported- $idx " ;
1521 $cgiparams { 'CERT_NAME' }=& Header
:: cleanhtml
( getCNfromcert
( '/tmp/newhostcert' ));
1522 move
( "/tmp/newcacert" , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1523 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1524 if (! $errormessage ) {
1525 my $key = & General
:: findhasharraykey
( \
%cahash );
1526 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
1527 $cahash { $key }[ 1 ] = $casubject ;
1528 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1529 system ( '/usr/local/bin/ipsecctrl' , 'R' );
1534 if (! $errormessage ) {
1535 & General
:: log ( "ipsec" , "Moving host cert..." );
1536 move
( "/tmp/newhostcert" , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1537 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1542 unlink ( '/tmp/newcacert' );
1543 unlink ( '/tmp/newhostcert' );
1544 if ( $errormessage ) {
1545 unlink ( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1546 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1549 & General
:: log ( "ipsec" , "p12 import completed!" );
1550 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
1551 if ( $cgiparams { 'KEY' }) {
1552 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1555 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1556 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1559 # Move uploaded certificate to a temporary file
1560 ( my $fh , my $filename ) = tempfile
( );
1561 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1566 # Verify the certificate has a valid CA and move it
1567 & General
:: log ( "ipsec" , "Validating imported cert against our known CA..." );
1568 my $validca = 1 ; #assume ok
1569 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/cacert.pem $filename ` ;
1570 if ( $test !~ /: OK/ ) {
1572 foreach my $key ( keys %cahash ) {
1573 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $key }[0]cert.pem $filename ` ;
1574 if ( $test =~ /: OK/ ) {
1581 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
1585 move
( $filename , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1587 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1593 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1594 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1595 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1596 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1599 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
1600 if ( $cgiparams { 'KEY' }) {
1601 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1604 # Validate input since the form was submitted
1605 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
1606 $errormessage = $Lang :: tr
{ 'name too long' };
1609 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1610 $errormessage = $Lang :: tr
{ 'invalid input for name' };
1613 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
1614 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1617 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
1618 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1621 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1622 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1625 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
1626 $errormessage = $Lang :: tr
{ 'organization too long' };
1629 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1630 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1633 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1634 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1637 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1638 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1641 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1642 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1645 #the exact syntax is a list comma separated of
1646 # email:any-validemail
1647 # URI: a uniform resource indicator
1648 # DNS: a DNS domain name
1649 # RID: a registered OBJECT IDENTIFIER
1651 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
1653 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
1654 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
1658 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
1659 $errormessage = $Lang :: tr
{ 'password too short' };
1662 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
1663 $errormessage = $Lang :: tr
{ 'passwords do not match' };
1667 # Replace empty strings with a .
1668 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
1669 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
1670 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
1672 # Create the Client certificate request
1673 & General
:: log ( "ipsec" , "Creating a cert..." );
1675 if ( open ( STDIN
, "-|" )) {
1676 my $opt = " req -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
1677 $opt .= " -newkey rsa:2048" ;
1678 $opt .= " -keyout ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1679 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1681 if ( $errormessage = & callssl
( $opt ) ) {
1682 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1683 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1687 print " $cgiparams {'CERT_COUNTRY'} \n " ;
1690 print " $cgiparams {'CERT_ORGANIZATION'} \n " ;
1692 print " $cgiparams {'CERT_NAME'} \n " ;
1693 print " $cgiparams {'CERT_EMAIL'} \n " ;
1699 # Sign the client certificate request
1700 & General
:: log ( "ipsec" , "Signing the cert $cgiparams {'NAME'}..." );
1702 #No easy way for specifying the contain of subjectAltName without writing a config file...
1703 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1705 basicConstraints=CA:FALSE
1706 nsComment="OpenSSL Generated Certificate"
1707 subjectKeyIdentifier=hash
1708 extendedKeyUsage=clientAuth
1709 authorityKeyIdentifier=keyid,issuer:always
1712 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1715 my $opt = " ca -md sha256 -days 999999 -batch -notext" ;
1716 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1717 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1718 $opt .= " -extfile $v3extname " ;
1720 if ( $errormessage = & callssl
( $opt ) ) {
1721 unlink ( $v3extname );
1722 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1723 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1724 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1725 & cleanssldatabase
();
1728 unlink ( $v3extname );
1729 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1730 & cleanssldatabase
();
1733 # Create the pkcs12 file
1734 & General
:: log ( "ipsec" , "Packing a pkcs12 file..." );
1735 $opt = " pkcs12 -export" ;
1736 $opt .= " -inkey ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1737 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1738 $opt .= " -name \" $cgiparams {'NAME'} \" " ;
1739 $opt .= " -passout pass: $cgiparams {'CERT_PASS1'}" ;
1740 $opt .= " -certfile ${General::swroot}/ca/cacert.pem" ;
1741 $opt .= " -caname \" $vpnsettings {'ROOTCERT_ORGANIZATION'} CA \" " ;
1742 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}.p12" ;
1744 if ( $errormessage = & callssl
( $opt ) ) {
1745 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1746 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1747 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}.p12" );
1750 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1752 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
1753 ; # Nothing, just editing
1754 } elsif ( $cgiparams { 'AUTH' } eq 'auth-dn' ) {
1755 $cgiparams { 'CERT_NAME' } = ' %auth -dn' ; # a special value saying 'no cert file'
1757 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
1761 # 1)Error message here is not accurate.
1762 # 2)Test is superfluous, openswan can reference same cert multiple times
1763 # 3)Present since initial version (1.3.2.11), it isn't a bug correction
1764 # Check if there is no other entry with this certificate name
1765 #if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk') && ($cgiparams{'AUTH'} ne 'auth-dn')) {
1766 # foreach my $key (keys %confighash) {
1767 # if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) {
1768 # $errormessage = $Lang::tr{'a connection with this common name already exists'};
1769 # goto VPNCONF_ERROR;
1775 my $key = $cgiparams { 'KEY' };
1777 $key = & General
:: findhasharraykey
( \
%confighash );
1778 foreach my $i ( 0 .. 32 ) { $confighash { $key }[ $i ] = "" ;}
1780 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
1781 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
1782 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
1783 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
1785 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
1786 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1787 $confighash { $key }[ 4 ] = 'psk' ;
1788 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
1790 $confighash { $key }[ 4 ] = 'cert' ;
1792 if ( $cgiparams { 'TYPE' } eq 'net' ) {
1793 $confighash { $key }[ 11 ] = $cgiparams { 'REMOTE_SUBNET' };
1795 $confighash { $key }[ 7 ] = $cgiparams { 'LOCAL_ID' };
1796 $confighash { $key }[ 8 ] = $cgiparams { 'LOCAL_SUBNET' };
1797 $confighash { $key }[ 9 ] = $cgiparams { 'REMOTE_ID' };
1798 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
1799 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
1800 $confighash { $key }[ 26 ] = "" ; # Formerly INTERFACE
1801 $confighash { $key }[ 27 ] = $cgiparams { 'DPD_ACTION' };
1802 $confighash { $key }[ 29 ] = $cgiparams { 'IKE_VERSION' };
1804 #dont forget advanced value
1805 $confighash { $key }[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
1806 $confighash { $key }[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
1807 $confighash { $key }[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
1808 $confighash { $key }[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
1809 $confighash { $key }[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
1810 $confighash { $key }[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
1811 $confighash { $key }[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
1812 $confighash { $key }[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
1813 $confighash { $key }[ 12 ] = 'off' ; # $cgiparams{'AGGRMODE'};
1814 $confighash { $key }[ 13 ] = $cgiparams { 'COMPRESSION' };
1815 $confighash { $key }[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
1816 $confighash { $key }[ 28 ] = $cgiparams { 'PFS' };
1817 $confighash { $key }[ 14 ] = $cgiparams { 'VHOST' };
1818 $confighash { $key }[ 30 ] = $cgiparams { 'DPD_TIMEOUT' };
1819 $confighash { $key }[ 31 ] = $cgiparams { 'DPD_DELAY' };
1820 $confighash { $key }[ 32 ] = $cgiparams { 'FORCE_MOBIKE' };
1822 #free unused fields!
1823 $confighash { $key }[ 6 ] = 'off' ;
1824 $confighash { $key }[ 15 ] = 'off' ;
1826 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1829 system ( '/usr/local/bin/ipsecctrl' , 'S' , $key );
1832 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
1833 $cgiparams { 'KEY' } = $key ;
1834 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
1837 } else { # add new connection
1838 $cgiparams { 'ENABLED' } = 'on' ;
1839 if ( ! - f
"${General::swroot}/private/cakey.pem" ) {
1840 $cgiparams { 'AUTH' } = 'psk' ;
1841 } elsif ( ! - f
"${General::swroot}/ca/cacert.pem" ) {
1842 $cgiparams { 'AUTH' } = 'certfile' ;
1844 $cgiparams { 'AUTH' } = 'certgen' ;
1846 $cgiparams { 'LOCAL_SUBNET' } = " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" ;
1847 $cgiparams { 'CERT_EMAIL' } = $vpnsettings { 'ROOTCERT_EMAIL' };
1848 $cgiparams { 'CERT_OU' } = $vpnsettings { 'ROOTCERT_OU' };
1849 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
1850 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
1851 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
1852 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
1854 # choose appropriate dpd action
1855 if ( $cgiparams { 'TYPE' } eq 'host' ) {
1856 $cgiparams { 'DPD_ACTION' } = 'clear' ;
1858 $cgiparams { 'DPD_ACTION' } = 'restart' ;
1861 if (! $cgiparams { 'DPD_DELAY' }) {
1862 $cgiparams { 'DPD_DELAY' } = 30 ;
1865 if (! $cgiparams { 'DPD_TIMEOUT' }) {
1866 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
1869 if (! $cgiparams { 'FORCE_MOBIKE' }) {
1870 $cgiparams { 'FORCE_MOBIKE' } = 'no' ;
1873 # Default IKE Version to v2
1874 if (! $cgiparams { 'IKE_VERSION' }) {
1875 $cgiparams { 'IKE_VERSION' } = 'ikev2' ;
1879 $cgiparams { 'LOCAL_ID' } = '' ;
1880 $cgiparams { 'REMOTE_ID' } = '' ;
1882 #use default advanced value
1883 $cgiparams { 'IKE_ENCRYPTION' } = 'aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128' ; #[18];
1884 $cgiparams { 'IKE_INTEGRITY' } = 'sha2_512|sha2_256|sha' ; #[19];
1885 $cgiparams { 'IKE_GROUPTYPE' } = '4096|3072|2048|1536|1024' ; #[20];
1886 $cgiparams { 'IKE_LIFETIME' } = '3' ; #[16];
1887 $cgiparams { 'ESP_ENCRYPTION' } = 'aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128' ; #[21];
1888 $cgiparams { 'ESP_INTEGRITY' } = 'sha2_512|sha2_256|sha1' ; #[22];
1889 $cgiparams { 'ESP_GROUPTYPE' } = '4096|3072|2048|1536|1024' ; #[23];
1890 $cgiparams { 'ESP_KEYLIFE' } = '1' ; #[17];
1891 $cgiparams { 'COMPRESSION' } = 'on' ; #[13];
1892 $cgiparams { 'ONLY_PROPOSED' } = 'off' ; #[24];
1893 $cgiparams { 'PFS' } = 'on' ; #[28];
1894 $cgiparams { 'VHOST' } = 'on' ; #[14];
1898 $checked { 'ENABLED' }{ 'off' } = '' ;
1899 $checked { 'ENABLED' }{ 'on' } = '' ;
1900 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = "checked='checked'" ;
1902 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
1903 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
1904 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = "checked='checked'" ;
1906 $checked { 'AUTH' }{ 'psk' } = '' ;
1907 $checked { 'AUTH' }{ 'certreq' } = '' ;
1908 $checked { 'AUTH' }{ 'certgen' } = '' ;
1909 $checked { 'AUTH' }{ 'certfile' } = '' ;
1910 $checked { 'AUTH' }{ 'pkcs12' } = '' ;
1911 $checked { 'AUTH' }{ 'auth-dn' } = '' ;
1912 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = "checked='checked'" ;
1914 & Header
:: showhttpheaders
();
1915 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1916 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1917 if ( $errormessage ) {
1918 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1919 print "<class name='base'> $errormessage " ;
1920 print " </class>" ;
1921 & Header
:: closebox
();
1925 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'warning messages'}:" );
1926 print "<class name='base'> $warnmessage " ;
1927 print " </class>" ;
1928 & Header
:: closebox
();
1931 print "<form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>" ;
1933 <input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />
1934 <input type='hidden' name='IKE_VERSION' value=' $cgiparams {'IKE_VERSION'}' />
1935 <input type='hidden' name='IKE_ENCRYPTION' value=' $cgiparams {'IKE_ENCRYPTION'}' />
1936 <input type='hidden' name='IKE_INTEGRITY' value=' $cgiparams {'IKE_INTEGRITY'}' />
1937 <input type='hidden' name='IKE_GROUPTYPE' value=' $cgiparams {'IKE_GROUPTYPE'}' />
1938 <input type='hidden' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' />
1939 <input type='hidden' name='ESP_ENCRYPTION' value=' $cgiparams {'ESP_ENCRYPTION'}' />
1940 <input type='hidden' name='ESP_INTEGRITY' value=' $cgiparams {'ESP_INTEGRITY'}' />
1941 <input type='hidden' name='ESP_GROUPTYPE' value=' $cgiparams {'ESP_GROUPTYPE'}' />
1942 <input type='hidden' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' />
1943 <input type='hidden' name='COMPRESSION' value=' $cgiparams {'COMPRESSION'}' />
1944 <input type='hidden' name='ONLY_PROPOSED' value=' $cgiparams {'ONLY_PROPOSED'}' />
1945 <input type='hidden' name='PFS' value=' $cgiparams {'PFS'}' />
1946 <input type='hidden' name='VHOST' value=' $cgiparams {'VHOST'}' />
1947 <input type='hidden' name='DPD_ACTION' value=' $cgiparams {'DPD_ACTION'}' />
1948 <input type='hidden' name='DPD_DELAY' value=' $cgiparams {'DPD_DELAY'}' />
1949 <input type='hidden' name='DPD_TIMEOUT' value=' $cgiparams {'DPD_TIMEOUT'}' />
1950 <input type='hidden' name='FORCE_MOBIKE' value=' $cgiparams {'FORCE_MOBIKE'}' />
1953 if ( $cgiparams { 'KEY' }) {
1954 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
1955 print "<input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' />" ;
1956 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
1959 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'connection'}: $cgiparams {'NAME'}" );
1960 print "<table width='100%'>" ;
1961 if (! $cgiparams { 'KEY' }) {
1964 <td width='20%'> $Lang ::tr{'name'}: <img src='/blob.gif' alt='*' /></td>
1966 <input type='text' name='NAME' value=' $cgiparams {'NAME'}' size='25' />
1968 <td colspan="2"></td>
1975 if ( $cgiparams { 'TYPE' } eq 'host' ) {
1976 $disabled = "disabled='disabled'" ;
1977 } elsif ( $cgiparams { 'TYPE' } eq 'net' ) {
1978 $blob = "<img src='/blob.gif' alt='*' />" ;
1983 <td width='20%'> $Lang ::tr{'enabled'}</td>
1985 <input type='checkbox' name='ENABLED' $checked {'ENABLED'}{'on'} />
1987 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'local subnet'} <img src='/blob.gif' alt='*' /></td>
1989 <input type='text' name='LOCAL_SUBNET' value=' $cgiparams {'LOCAL_SUBNET'}' size="25" />
1993 <td class='boldbase' width='20%'> $Lang ::tr{'remote host/ip'}: $blob </td>
1995 <input type='text' name='REMOTE' value=' $cgiparams {'REMOTE'}' size="25" />
1997 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'remote subnet'} $blob </td>
1999 <input $disabled type='text' name='REMOTE_SUBNET' value=' $cgiparams {'REMOTE_SUBNET'}' size="25" />
2003 <td class='boldbase' width='20%'> $Lang ::tr{'vpn local id'}:</td>
2005 <input type='text' name='LOCAL_ID' value=' $cgiparams {'LOCAL_ID'}' size="25" />
2007 <td class='boldbase' width='20%'> $Lang ::tr{'vpn remote id'}:</td>
2009 <input type='text' name='REMOTE_ID' value=' $cgiparams {'REMOTE_ID'}' size="25" />
2012 <tr><td colspan="4"><br /></td></tr>
2014 <td class='boldbase' width='20%'> $Lang ::tr{'remark title'}</td>
2016 <input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' maxlength='50' size="73" />
2021 if (! $cgiparams { 'KEY' }) {
2022 print "<tr><td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked {'EDIT_ADVANCED'}{'on'} /> $Lang ::tr{'edit advanced settings when done'}</td></tr>" ;
2025 & Header
:: closebox
();
2027 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
2028 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2030 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2031 <tr><td class='base' width='50%'> $Lang ::tr{'use a pre-shared key'}</td>
2032 <td class='base' width='50%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td>
2037 & Header
:: closebox
();
2038 } elsif (! $cgiparams { 'KEY' }) {
2039 my $cakeydisabled = ( ! - f
"${General::swroot}/private/cakey.pem" ) ?
"disabled='disabled'" : '' ;
2040 $cgiparams { 'CERT_NAME' } = $Lang :: tr
{ 'vpn no full pki' } if ( $cakeydisabled );
2041 my $cacrtdisabled = ( ! - f
"${General::swroot}/ca/cacert.pem" ) ?
"disabled='disabled'" : '' ;
2043 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2045 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2046 <tr><td width='5%'><input type='radio' name='AUTH' value='psk' $checked {'AUTH'}{'psk'} /></td>
2047 <td class='base' width='55%'> $Lang ::tr{'use a pre-shared key'}</td>
2048 <td class='base' width='40%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td></tr>
2049 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2050 <tr><td><input type='radio' name='AUTH' value='certreq' $checked {'AUTH'}{'certreq'} $cakeydisabled /></td>
2051 <td class='base'><hr /> $Lang ::tr{'upload a certificate request'}</td>
2052 <td class='base' rowspan='3' valign='middle'><input type='file' name='FH' size='30' $cacrtdisabled /></td></tr>
2053 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td>
2054 <td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
2055 <tr><td><input type='radio' name='AUTH' value='pkcs12' $cacrtdisabled /></td>
2056 <td class='base'> $Lang ::tr{'upload p12 file'} $Lang ::tr{'pkcs12 file password'}:<input type='password' name='P12_PASS'/></td></tr>
2057 <tr><td><input type='radio' name='AUTH' value='auth-dn' $checked {'AUTH'}{'auth-dn'} $cacrtdisabled /></td>
2058 <td class='base'><hr /> $Lang ::tr{'vpn auth-dn'}</td></tr>
2059 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2060 <tr><td><input type='radio' name='AUTH' value='certgen' $checked {'AUTH'}{'certgen'} $cakeydisabled /></td>
2061 <td class='base'><hr /> $Lang ::tr{'generate a certificate'}</td><td> </td></tr>
2063 <td class='base'> $Lang ::tr{'users fullname or system hostname'}: <img src='/blob.gif' alt='*' /></td>
2064 <td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' size='32' $cakeydisabled /></td></tr>
2066 <td class='base'> $Lang ::tr{'users email'}:</td>
2067 <td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' size='32' $cakeydisabled /></td></tr>
2069 <td class='base'> $Lang ::tr{'users department'}:</td>
2070 <td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' size='32' $cakeydisabled /></td></tr>
2072 <td class='base'> $Lang ::tr{'organization name'}:</td>
2073 <td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' size='32' $cakeydisabled /></td></tr>
2075 <td class='base'> $Lang ::tr{'city'}:</td>
2076 <td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' size='32' $cakeydisabled /></td></tr>
2078 <td class='base'> $Lang ::tr{'state or province'}:</td>
2079 <td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' size='32' $cakeydisabled /></td></tr>
2081 <td class='base'> $Lang ::tr{'country'}:</td>
2082 <td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
2085 foreach my $country ( sort keys %{ Countries
:: countries
}) {
2086 print " \t\t\t <option value=' $Countries ::countries{ $country }'" ;
2087 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
2088 print " selected='selected'" ;
2090 print "> $country </option> \n " ;
2095 <tr><td> </td><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)</td>
2096 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' $cakeydisabled /></td></tr>
2098 <td class='base'> $Lang ::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' /></td>
2099 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
2100 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'} ( $Lang ::tr{'confirmation'}): <img src='/blob.gif' alt='*' /></td>
2101 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
2105 & Header
:: closebox
();
2108 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
2109 if ( $cgiparams { 'KEY' }) {
2110 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced'}' />" ;
2112 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
2113 & Header
:: closebigbox
();
2114 & Header
:: closepage
();
2121 ### Advanced settings
2123 if (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced' }) ||
2124 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq 'yes' )) {
2125 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
2126 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2127 if (! $confighash { $cgiparams { 'KEY' }}) {
2128 $errormessage = $Lang :: tr
{ 'invalid key' };
2132 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
2133 # I didn't read any incompatibilities here....
2134 #if ($cgiparams{'VHOST'} eq 'on' && $cgiparams{'COMPRESSION'} eq 'on') {
2135 # $errormessage = $Lang::tr{'cannot enable both nat traversal and compression'};
2136 # goto ADVANCED_ERROR;
2138 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2140 $errormessage = $Lang :: tr
{ 'invalid input' };
2141 goto ADVANCED_ERROR
;
2143 foreach my $val ( @temp ) {
2144 if ( $val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|camellia(256|192|128))$/ ) {
2145 $errormessage = $Lang :: tr
{ 'invalid input' };
2146 goto ADVANCED_ERROR
;
2149 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2151 $errormessage = $Lang :: tr
{ 'invalid input' };
2152 goto ADVANCED_ERROR
;
2154 foreach my $val ( @temp ) {
2155 if ( $val !~ /^(sha2_(512|384|256)|sha|md5|aesxcbc)$/ ) {
2156 $errormessage = $Lang :: tr
{ 'invalid input' };
2157 goto ADVANCED_ERROR
;
2160 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2162 $errormessage = $Lang :: tr
{ 'invalid input' };
2163 goto ADVANCED_ERROR
;
2165 foreach my $val ( @temp ) {
2166 if ( $val !~ /^(e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|1024|1536|2048|2048s256|2048s224|2048s160|3072|4096|6144|8192)$/ ) {
2167 $errormessage = $Lang :: tr
{ 'invalid input' };
2168 goto ADVANCED_ERROR
;
2171 if ( $cgiparams { 'IKE_LIFETIME' } !~ /^\d+$/ ) {
2172 $errormessage = $Lang :: tr
{ 'invalid input for ike lifetime' };
2173 goto ADVANCED_ERROR
;
2175 if ( $cgiparams { 'IKE_LIFETIME' } < 1 || $cgiparams { 'IKE_LIFETIME' } > 8 ) {
2176 $errormessage = $Lang :: tr
{ 'ike lifetime should be between 1 and 8 hours' };
2177 goto ADVANCED_ERROR
;
2179 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2181 $errormessage = $Lang :: tr
{ 'invalid input' };
2182 goto ADVANCED_ERROR
;
2184 foreach my $val ( @temp ) {
2185 if ( $val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|camellia(256|192|128))$/ ) {
2186 $errormessage = $Lang :: tr
{ 'invalid input' };
2187 goto ADVANCED_ERROR
;
2190 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2192 $errormessage = $Lang :: tr
{ 'invalid input' };
2193 goto ADVANCED_ERROR
;
2195 foreach my $val ( @temp ) {
2196 if ( $val !~ /^(sha2_(512|384|256)|sha1|md5|aesxcbc)$/ ) {
2197 $errormessage = $Lang :: tr
{ 'invalid input' };
2198 goto ADVANCED_ERROR
;
2201 @temp = split ( '\|' , $cgiparams { 'ESP_GROUPTYPE' });
2203 $errormessage = $Lang :: tr
{ 'invalid input' };
2204 goto ADVANCED_ERROR
;
2206 foreach my $val ( @temp ) {
2207 if ( $val !~ /^(e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|1024|1536|2048|2048s256|2048s224|2048s160|3072|4096|6144|8192|none)$/ ) {
2208 $errormessage = $Lang :: tr
{ 'invalid input' };
2209 goto ADVANCED_ERROR
;
2212 if ( $cgiparams { 'ESP_KEYLIFE' } !~ /^\d+$/ ) {
2213 $errormessage = $Lang :: tr
{ 'invalid input for esp keylife' };
2214 goto ADVANCED_ERROR
;
2216 if ( $cgiparams { 'ESP_KEYLIFE' } < 1 || $cgiparams { 'ESP_KEYLIFE' } > 24 ) {
2217 $errormessage = $Lang :: tr
{ 'esp keylife should be between 1 and 24 hours' };
2218 goto ADVANCED_ERROR
;
2222 ( $cgiparams { 'COMPRESSION' } !~ /^(|on|off)$/ ) ||
2223 ( $cgiparams { 'FORCE_MOBIKE' } !~ /^(|on|off)$/ ) ||
2224 ( $cgiparams { 'ONLY_PROPOSED' } !~ /^(|on|off)$/ ) ||
2225 ( $cgiparams { 'PFS' } !~ /^(|on|off)$/ ) ||
2226 ( $cgiparams { 'VHOST' } !~ /^(|on|off)$/ )
2228 $errormessage = $Lang :: tr
{ 'invalid input' };
2229 goto ADVANCED_ERROR
;
2232 if ( $cgiparams { 'DPD_DELAY' } !~ /^\d+$/ ) {
2233 $errormessage = $Lang :: tr
{ 'invalid input for dpd delay' };
2234 goto ADVANCED_ERROR
;
2237 if ( $cgiparams { 'DPD_TIMEOUT' } !~ /^\d+$/ ) {
2238 $errormessage = $Lang :: tr
{ 'invalid input for dpd timeout' };
2239 goto ADVANCED_ERROR
;
2242 $confighash { $cgiparams { 'KEY' }}[ 29 ] = $cgiparams { 'IKE_VERSION' };
2243 $confighash { $cgiparams { 'KEY' }}[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
2244 $confighash { $cgiparams { 'KEY' }}[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
2245 $confighash { $cgiparams { 'KEY' }}[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
2246 $confighash { $cgiparams { 'KEY' }}[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
2247 $confighash { $cgiparams { 'KEY' }}[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
2248 $confighash { $cgiparams { 'KEY' }}[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
2249 $confighash { $cgiparams { 'KEY' }}[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
2250 $confighash { $cgiparams { 'KEY' }}[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
2251 $confighash { $cgiparams { 'KEY' }}[ 12 ] = 'off' ; #$cgiparams{'AGGRMODE'};
2252 $confighash { $cgiparams { 'KEY' }}[ 13 ] = $cgiparams { 'COMPRESSION' };
2253 $confighash { $cgiparams { 'KEY' }}[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
2254 $confighash { $cgiparams { 'KEY' }}[ 28 ] = $cgiparams { 'PFS' };
2255 $confighash { $cgiparams { 'KEY' }}[ 14 ] = $cgiparams { 'VHOST' };
2256 $confighash { $cgiparams { 'KEY' }}[ 27 ] = $cgiparams { 'DPD_ACTION' };
2257 $confighash { $cgiparams { 'KEY' }}[ 30 ] = $cgiparams { 'DPD_TIMEOUT' };
2258 $confighash { $cgiparams { 'KEY' }}[ 31 ] = $cgiparams { 'DPD_DELAY' };
2259 $confighash { $cgiparams { 'KEY' }}[ 32 ] = $cgiparams { 'FORCE_MOBIKE' };
2260 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2263 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
2268 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
2269 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
2270 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
2271 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
2272 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
2273 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
2274 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
2275 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
2276 if ( $cgiparams { 'ESP_GROUPTYPE' } eq "" ) {
2277 $cgiparams { 'ESP_GROUPTYPE' } = $cgiparams { 'IKE_GROUPTYPE' };
2279 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
2280 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
2281 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
2282 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
2283 $cgiparams { 'VHOST' } = $confighash { $cgiparams { 'KEY' }}[ 14 ];
2284 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
2285 $cgiparams { 'DPD_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
2286 $cgiparams { 'DPD_DELAY' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
2287 $cgiparams { 'FORCE_MOBIKE' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
2289 if (! $cgiparams { 'DPD_DELAY' }) {
2290 $cgiparams { 'DPD_DELAY' } = 30 ;
2293 if (! $cgiparams { 'DPD_TIMEOUT' }) {
2294 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
2297 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' || $confighash { $cgiparams { 'KEY' }}[ 10 ]) {
2298 $cgiparams { 'VHOST' } = 'off' ;
2303 $checked { 'IKE_ENCRYPTION' }{ 'aes256' } = '' ;
2304 $checked { 'IKE_ENCRYPTION' }{ 'aes192' } = '' ;
2305 $checked { 'IKE_ENCRYPTION' }{ 'aes128' } = '' ;
2306 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm128' } = '' ;
2307 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm128' } = '' ;
2308 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm128' } = '' ;
2309 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm96' } = '' ;
2310 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm96' } = '' ;
2311 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm96' } = '' ;
2312 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm64' } = '' ;
2313 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm64' } = '' ;
2314 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm64' } = '' ;
2315 $checked { 'IKE_ENCRYPTION' }{ '3des' } = '' ;
2316 $checked { 'IKE_ENCRYPTION' }{ 'camellia256' } = '' ;
2317 $checked { 'IKE_ENCRYPTION' }{ 'camellia192' } = '' ;
2318 $checked { 'IKE_ENCRYPTION' }{ 'camellia128' } = '' ;
2319 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2320 foreach my $key ( @temp ) { $checked { 'IKE_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2321 $checked { 'IKE_INTEGRITY' }{ 'sha2_512' } = '' ;
2322 $checked { 'IKE_INTEGRITY' }{ 'sha2_384' } = '' ;
2323 $checked { 'IKE_INTEGRITY' }{ 'sha2_256' } = '' ;
2324 $checked { 'IKE_INTEGRITY' }{ 'sha' } = '' ;
2325 $checked { 'IKE_INTEGRITY' }{ 'md5' } = '' ;
2326 $checked { 'IKE_INTEGRITY' }{ 'aesxcbc' } = '' ;
2327 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2328 foreach my $key ( @temp ) { $checked { 'IKE_INTEGRITY' }{ $key } = "selected='selected'" ; }
2329 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2330 $checked { 'IKE_GROUPTYPE' }{ '1024' } = '' ;
2331 $checked { 'IKE_GROUPTYPE' }{ '1536' } = '' ;
2332 $checked { 'IKE_GROUPTYPE' }{ '2048' } = '' ;
2333 $checked { 'IKE_GROUPTYPE' }{ '3072' } = '' ;
2334 $checked { 'IKE_GROUPTYPE' }{ '4096' } = '' ;
2335 $checked { 'IKE_GROUPTYPE' }{ '6144' } = '' ;
2336 $checked { 'IKE_GROUPTYPE' }{ '8192' } = '' ;
2337 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2338 foreach my $key ( @temp ) { $checked { 'IKE_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2340 # 768 is not supported by strongswan
2341 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2343 $checked { 'ESP_ENCRYPTION' }{ 'aes256' } = '' ;
2344 $checked { 'ESP_ENCRYPTION' }{ 'aes192' } = '' ;
2345 $checked { 'ESP_ENCRYPTION' }{ 'aes128' } = '' ;
2346 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm128' } = '' ;
2347 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm128' } = '' ;
2348 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm128' } = '' ;
2349 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm96' } = '' ;
2350 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm96' } = '' ;
2351 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm96' } = '' ;
2352 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm64' } = '' ;
2353 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm64' } = '' ;
2354 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm64' } = '' ;
2355 $checked { 'ESP_ENCRYPTION' }{ '3des' } = '' ;
2356 $checked { 'ESP_ENCRYPTION' }{ 'camellia256' } = '' ;
2357 $checked { 'ESP_ENCRYPTION' }{ 'camellia192' } = '' ;
2358 $checked { 'ESP_ENCRYPTION' }{ 'camellia128' } = '' ;
2359 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2360 foreach my $key ( @temp ) { $checked { 'ESP_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2361 $checked { 'ESP_INTEGRITY' }{ 'sha2_512' } = '' ;
2362 $checked { 'ESP_INTEGRITY' }{ 'sha2_384' } = '' ;
2363 $checked { 'ESP_INTEGRITY' }{ 'sha2_256' } = '' ;
2364 $checked { 'ESP_INTEGRITY' }{ 'sha1' } = '' ;
2365 $checked { 'ESP_INTEGRITY' }{ 'md5' } = '' ;
2366 $checked { 'ESP_INTEGRITY' }{ 'aesxcbc' } = '' ;
2367 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2368 foreach my $key ( @temp ) { $checked { 'ESP_INTEGRITY' }{ $key } = "selected='selected'" ; }
2369 $checked { 'ESP_GROUPTYPE' }{ '768' } = '' ;
2370 $checked { 'ESP_GROUPTYPE' }{ '1024' } = '' ;
2371 $checked { 'ESP_GROUPTYPE' }{ '1536' } = '' ;
2372 $checked { 'ESP_GROUPTYPE' }{ '2048' } = '' ;
2373 $checked { 'ESP_GROUPTYPE' }{ '3072' } = '' ;
2374 $checked { 'ESP_GROUPTYPE' }{ '4096' } = '' ;
2375 $checked { 'ESP_GROUPTYPE' }{ '6144' } = '' ;
2376 $checked { 'ESP_GROUPTYPE' }{ '8192' } = '' ;
2377 $checked { 'ESP_GROUPTYPE' }{ 'none' } = '' ;
2378 @temp = split ( '\|' , $cgiparams { 'ESP_GROUPTYPE' });
2379 foreach my $key ( @temp ) { $checked { 'ESP_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2381 $checked { 'COMPRESSION' } = $cgiparams { 'COMPRESSION' } eq 'on' ?
"checked='checked'" : '' ;
2382 $checked { 'FORCE_MOBIKE' } = $cgiparams { 'FORCE_MOBIKE' } eq 'on' ?
"checked='checked'" : '' ;
2383 $checked { 'ONLY_PROPOSED' } = $cgiparams { 'ONLY_PROPOSED' } eq 'on' ?
"checked='checked'" : '' ;
2384 $checked { 'PFS' } = $cgiparams { 'PFS' } eq 'on' ?
"checked='checked'" : '' ;
2385 $checked { 'VHOST' } = $cgiparams { 'VHOST' } eq 'on' ?
"checked='checked'" : '' ;
2387 $selected { 'IKE_VERSION' }{ 'ikev1' } = '' ;
2388 $selected { 'IKE_VERSION' }{ 'ikev2' } = '' ;
2389 $selected { 'IKE_VERSION' }{ $cgiparams { 'IKE_VERSION' }} = "selected='selected'" ;
2391 $selected { 'DPD_ACTION' }{ 'clear' } = '' ;
2392 $selected { 'DPD_ACTION' }{ 'hold' } = '' ;
2393 $selected { 'DPD_ACTION' }{ 'restart' } = '' ;
2394 $selected { 'DPD_ACTION' }{ 'none' } = '' ;
2395 $selected { 'DPD_ACTION' }{ $cgiparams { 'DPD_ACTION' }} = "selected='selected'" ;
2397 & Header
:: showhttpheaders
();
2398 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
2399 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2401 if ( $errormessage ) {
2402 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2403 print "<class name='base'> $errormessage " ;
2404 print " </class>" ;
2405 & Header
:: closebox
();
2409 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
2410 print "<class name='base'> $warnmessage " ;
2411 print " </class>" ;
2412 & Header
:: closebox
();
2415 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'advanced'}:" );
2417 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
2418 <input type='hidden' name='ADVANCED' value='yes' />
2419 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
2421 <table width='100%'>
2424 <th width="15%"></th>
2431 <td> $Lang ::tr{'vpn keyexchange'}:</td>
2433 <select name='IKE_VERSION'>
2434 <option value='ikev2' $selected {'IKE_VERSION'}{'ikev2'}>IKEv2</option>
2435 <option value='ikev1' $selected {'IKE_VERSION'}{'ikev1'}>IKEv1</option>
2441 <td class='boldbase' width="15%"> $Lang ::tr{'encryption'}</td>
2442 <td class='boldbase'>
2443 <select name='IKE_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
2444 <option value='aes256gcm128' $checked {'IKE_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
2445 <option value='aes256gcm96' $checked {'IKE_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
2446 <option value='aes256gcm64' $checked {'IKE_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
2447 <option value='aes256' $checked {'IKE_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
2448 <option value='camellia256' $checked {'IKE_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
2449 <option value='aes192gcm128' $checked {'IKE_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
2450 <option value='aes192gcm96' $checked {'IKE_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
2451 <option value='aes192gcm64' $checked {'IKE_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
2452 <option value='aes192' $checked {'IKE_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
2453 <option value='camellia192' $checked {'IKE_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
2454 <option value='aes128gcm128' $checked {'IKE_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
2455 <option value='aes128gcm96' $checked {'IKE_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
2456 <option value='aes128gcm64' $checked {'IKE_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
2457 <option value='aes128' $checked {'IKE_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
2458 <option value='camellia128' $checked {'IKE_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
2459 <option value='3des' $checked {'IKE_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC</option>
2462 <td class='boldbase'>
2463 <select name='ESP_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
2464 <option value='aes256gcm128' $checked {'ESP_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
2465 <option value='aes256gcm96' $checked {'ESP_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
2466 <option value='aes256gcm64' $checked {'ESP_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
2467 <option value='aes256' $checked {'ESP_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
2468 <option value='camellia256' $checked {'ESP_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
2469 <option value='aes192gcm128' $checked {'ESP_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
2470 <option value='aes192gcm96' $checked {'ESP_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
2471 <option value='aes192gcm64' $checked {'ESP_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
2472 <option value='aes192' $checked {'ESP_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
2473 <option value='camellia192' $checked {'ESP_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
2474 <option value='aes128gcm128' $checked {'ESP_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
2475 <option value='aes128gcm96' $checked {'ESP_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
2476 <option value='aes128gcm64' $checked {'ESP_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
2477 <option value='aes128' $checked {'ESP_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
2478 <option value='camellia128' $checked {'ESP_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
2479 <option value='3des' $checked {'ESP_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC</option>
2485 <td class='boldbase' width="15%"> $Lang ::tr{'integrity'}</td>
2486 <td class='boldbase'>
2487 <select name='IKE_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
2488 <option value='sha2_512' $checked {'IKE_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2489 <option value='sha2_384' $checked {'IKE_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2490 <option value='sha2_256' $checked {'IKE_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2491 <option value='aesxcbc' $checked {'IKE_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2492 <option value='sha' $checked {'IKE_INTEGRITY'}{'sha'}>SHA1</option>
2493 <option value='md5' $checked {'IKE_INTEGRITY'}{'md5'}>MD5</option>
2496 <td class='boldbase'>
2497 <select name='ESP_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
2498 <option value='sha2_512' $checked {'ESP_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2499 <option value='sha2_384' $checked {'ESP_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2500 <option value='sha2_256' $checked {'ESP_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2501 <option value='aesxcbc' $checked {'ESP_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2502 <option value='sha1' $checked {'ESP_INTEGRITY'}{'sha1'}>SHA1</option>
2503 <option value='md5' $checked {'ESP_INTEGRITY'}{'md5'}>MD5</option>
2508 <td class='boldbase' width="15%"> $Lang ::tr{'lifetime'} <img src='/blob.gif' alt='*' /></td>
2509 <td class='boldbase'>
2510 <input type='text' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' size='5' /> $Lang ::tr{'hours'}
2512 <td class='boldbase'>
2513 <input type='text' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' size='5' /> $Lang ::tr{'hours'}
2517 <td class='boldbase' width="15%"> $Lang ::tr{'grouptype'}</td>
2518 <td class='boldbase'>
2519 <select name='IKE_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
2520 <option value='e521' $checked {'IKE_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
2521 <option value='e512bp' $checked {'IKE_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
2522 <option value='e384' $checked {'IKE_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
2523 <option value='e384bp' $checked {'IKE_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
2524 <option value='e256' $checked {'IKE_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
2525 <option value='e256bp' $checked {'IKE_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
2526 <option value='e224' $checked {'IKE_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
2527 <option value='e224bp' $checked {'IKE_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
2528 <option value='e192' $checked {'IKE_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
2529 <option value='8192' $checked {'IKE_GROUPTYPE'}{'8192'}>MODP-8192</option>
2530 <option value='6144' $checked {'IKE_GROUPTYPE'}{'6144'}>MODP-6144</option>
2531 <option value='4096' $checked {'IKE_GROUPTYPE'}{'4096'}>MODP-4096</option>
2532 <option value='3072' $checked {'IKE_GROUPTYPE'}{'3072'}>MODP-3072</option>
2533 <option value='2048s256' $checked {'IKE_GROUPTYPE'}{'2048s256'}>MODP-2048/256</option>
2534 <option value='2048s224' $checked {'IKE_GROUPTYPE'}{'2048s224'}>MODP-2048/224</option>
2535 <option value='2048s160' $checked {'IKE_GROUPTYPE'}{'2048s160'}>MODP-2048/160</option>
2536 <option value='2048' $checked {'IKE_GROUPTYPE'}{'2048'}>MODP-2048</option>
2537 <option value='1536' $checked {'IKE_GROUPTYPE'}{'1536'}>MODP-1536</option>
2538 <option value='1024' $checked {'IKE_GROUPTYPE'}{'1024'}>MODP-1024</option>
2541 <td class='boldbase'>
2542 <select name='ESP_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
2543 <option value='e521' $checked {'ESP_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
2544 <option value='e512bp' $checked {'ESP_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
2545 <option value='e384' $checked {'ESP_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
2546 <option value='e384bp' $checked {'ESP_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
2547 <option value='e256' $checked {'ESP_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
2548 <option value='e256bp' $checked {'ESP_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
2549 <option value='e224' $checked {'ESP_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
2550 <option value='e224bp' $checked {'ESP_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
2551 <option value='e192' $checked {'ESP_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
2552 <option value='8192' $checked {'ESP_GROUPTYPE'}{'8192'}>MODP-8192</option>
2553 <option value='6144' $checked {'ESP_GROUPTYPE'}{'6144'}>MODP-6144</option>
2554 <option value='4096' $checked {'ESP_GROUPTYPE'}{'4096'}>MODP-4096</option>
2555 <option value='3072' $checked {'ESP_GROUPTYPE'}{'3072'}>MODP-3072</option>
2556 <option value='2048s256' $checked {'ESP_GROUPTYPE'}{'2048s256'}>MODP-2048/256</option>
2557 <option value='2048s224' $checked {'ESP_GROUPTYPE'}{'2048s224'}>MODP-2048/224</option>
2558 <option value='2048s160' $checked {'ESP_GROUPTYPE'}{'2048s160'}>MODP-2048/160</option>
2559 <option value='2048' $checked {'ESP_GROUPTYPE'}{'2048'}>MODP-2048</option>
2560 <option value='1536' $checked {'ESP_GROUPTYPE'}{'1536'}>MODP-1536</option>
2561 <option value='1024' $checked {'ESP_GROUPTYPE'}{'1024'}>MODP-1024</option>
2562 <option value='none' $checked {'ESP_GROUPTYPE'}{'none'}>- $Lang ::tr{'none'} -</option>
2571 <h2> $Lang ::tr{'dead peer detection'}</h2>
2573 <table width="100%">
2575 <td width="15%"> $Lang ::tr{'dpd action'}:</td>
2577 <select name='DPD_ACTION'>
2578 <option value='none' $selected {'DPD_ACTION'}{'none'}>- $Lang ::tr{'disabled'} -</option>
2579 <option value='clear' $selected {'DPD_ACTION'}{'clear'}>clear</option>
2580 <option value='hold' $selected {'DPD_ACTION'}{'hold'}>hold</option>
2581 <option value='restart' $selected {'DPD_ACTION'}{'restart'}>restart</option>
2586 <td width="15%"> $Lang ::tr{'dpd timeout'}: <img src='/blob.gif' alt='*' /></td>
2588 <input type='text' name='DPD_TIMEOUT' size='5' value=' $cgiparams {'DPD_TIMEOUT'}' />
2592 <td width="15%"> $Lang ::tr{'dpd delay'}: <img src='/blob.gif' alt='*' /></td>
2594 <input type='text' name='DPD_DELAY' size='5' value=' $cgiparams {'DPD_DELAY'}' />
2601 <table width="100%">
2605 <input type='checkbox' name='ONLY_PROPOSED' $checked {'ONLY_PROPOSED'} />
2606 IKE+ESP: $Lang ::tr{'use only proposed settings'}
2613 <input type='checkbox' name='PFS' $checked {'PFS'} />
2614 $Lang ::tr{'pfs yes no'}
2621 <input type='checkbox' name='COMPRESSION' $checked {'COMPRESSION'} />
2622 $Lang ::tr{'vpn payload compression'}
2629 <input type='checkbox' name='FORCE_MOBIKE' $checked {'FORCE_MOBIKE'} />
2630 $Lang ::tr{'vpn force mobike'}
2636 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ) {
2637 print "<tr><td><input type='hidden' name='VHOST' value='off' /></td></tr>" ;
2638 } elsif ( $confighash { $cgiparams { 'KEY' }}[ 10 ]) {
2639 print "<tr><td><label><input type='checkbox' name='VHOST' $checked {'VHOST'} disabled='disabled' />" ;
2640 print " $Lang ::tr{'vpn vhost'}</label></td></tr>" ;
2642 print "<tr><td><label><input type='checkbox' name='VHOST' $checked {'VHOST'} />" ;
2643 print " $Lang ::tr{'vpn vhost'}</label></td></tr>" ;
2648 <td align='left' colspan='1'><img src='/blob.gif' align='top' alt='*' /> $Lang ::tr{'required field'}</td>
2649 <td align='right' colspan='2'>
2650 <input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />
2651 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' />
2657 & Header
:: closebox
();
2658 & Header
:: closebigbox
();
2659 & Header
:: closepage
();
2666 ### Default status page
2671 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%cgiparams );
2672 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
2673 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2674 $cgiparams { 'CA_NAME' } = '' ;
2676 my @status = `/usr/local/bin/ipsecctrl I 2>/dev/null` ;
2678 # suggest a default name for this side
2679 if ( $cgiparams { 'VPN_IP' } eq '' && - e
"${General::swroot}/red/active" ) {
2680 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
2681 my $ipaddr = < IPADDR
>;
2684 $cgiparams { 'VPN_IP' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
2685 if ( $cgiparams { 'VPN_IP' } eq '' ) {
2686 $cgiparams { 'VPN_IP' } = $ipaddr ;
2690 # no IP found, use %defaultroute
2691 $cgiparams { 'VPN_IP' } = ' %defaultroute ' if ( $cgiparams { 'VPN_IP' } eq '' );
2693 $cgiparams { 'VPN_DELAYED_START' } = 0 if (! defined ( $cgiparams { 'VPN_DELAYED_START' }));
2694 $checked { 'ENABLED' } = $cgiparams { 'ENABLED' } eq 'on' ?
"checked='checked'" : '' ;
2696 & Header
:: showhttpheaders
();
2697 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
2698 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2700 if ( $errormessage ) {
2701 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2702 print "<class name='base'> $errormessage \n " ;
2703 print " </class> \n " ;
2704 & Header
:: closebox
();
2708 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
2709 print " $warnmessage <br>" ;
2710 print " $Lang ::tr{'fwdfw warn1'}<br>" ;
2711 & Header
:: closebox
();
2712 print "<center><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'ok'}' style='width: 5em;'></form>" ;
2713 & Header
:: closepage
();
2717 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'global settings' });
2719 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2720 <table width='100%'>
2722 <td width='20%' class='base' nowrap='nowrap'> $Lang ::tr{'vpn red name'}: <img src='/blob.gif' alt='*' /></td>
2723 <td width='20%'><input type='text' name='VPN_IP' value=' $cgiparams {'VPN_IP'}' /></td>
2724 <td width='20%' class='base'> $Lang ::tr{'enabled'}<input type='checkbox' name='ENABLED' $checked {'ENABLED'} /></td>
2730 <td class='base' nowrap='nowrap'> $Lang ::tr{'vpn delayed start'}: <img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' /></td>
2731 <td ><input type='text' name='VPN_DELAYED_START' value=' $cgiparams {'VPN_DELAYED_START'}' /></td>
2734 <td class='base' nowrap='nowrap'> $Lang ::tr{'host to net vpn'}:</td>
2735 <td ><input type='text' name='RW_NET' value=' $cgiparams {'RW_NET'}' /></td>
2740 <table width='100%'>
2742 <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
2743 <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>
2746 <td class='base' valign='top' nowrap='nowrap'><img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' /> </td>
2747 <td class='base'> <font class='base'> $Lang ::tr{'vpn delayed start help'}</font></td>
2754 & Header
:: closebox
();
2756 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection status and controlc' });
2758 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
2760 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
2761 <th width='22%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></th>
2762 <th width='23%' class='boldbase' align='center'><b> $Lang ::tr{'common name'}</b></th>
2763 <th width='30%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></th>
2764 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></th>
2765 <th class='boldbase' align='center' colspan='6'><b> $Lang ::tr{'action'}</b></th>
2771 foreach my $key ( sort { ncmp
( $confighash { $a }[ 1 ], $confighash { $b }[ 1 ]) } keys %confighash ) {
2772 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
2776 $col = "bgcolor=' $color {'color20'}'" ;
2779 $col = "bgcolor=' $color {'color22'}'" ;
2781 print "<td align='center' nowrap='nowrap' $col > $confighash { $key }[1]</td>" ;
2782 print "<td align='center' nowrap='nowrap' $col >" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ") $confighash { $key }[29]</td>" ;
2783 if ( $confighash { $key }[ 2 ] eq ' %auth -dn' ) {
2784 print "<td align='left' nowrap='nowrap' $col > $confighash { $key }[9]</td>" ;
2785 } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
2786 print "<td align='left' nowrap='nowrap' $col > $confighash { $key }[2]</td>" ;
2788 print "<td align='left' $col > </td>" ;
2790 print "<td align='center' $col > $confighash { $key }[25]</td>" ;
2791 my $col1 = "bgcolor='${Header::colourred}'" ;
2793 my $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
2794 foreach my $line ( @status ) {
2795 if (( $line =~ /\"$confighash{$key}[1]\".*IPsec SA established/ ) ||
2796 ( $line =~ /$confighash{$key}[1]\{.*INSTALLED/ ))
2798 $col1 = "bgcolor='${Header::colourgreen}'" ;
2799 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b>" ;
2802 # move to blueif really down
2803 if ( $confighash { $key }[ 0 ] eq 'off' && $col1 =~ /${Header::colourred}/ ) {
2804 $col1 = "bgcolor='${Header::colourblue}'" ;
2805 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
2808 <td align='center' $col1 > $active </td>
2809 <td align='center' $col >
2810 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2811 <input type='image' name=' $Lang ::tr{'restart'}' src='/images/reload.gif' alt=' $Lang ::tr{'restart'}' title=' $Lang ::tr{'restart'}' />
2812 <input type='hidden' name='ACTION' value=' $Lang ::tr{'restart'}' />
2813 <input type='hidden' name='KEY' value=' $key ' />
2818 if (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
2820 <td align='center' $col >
2821 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2822 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' />
2823 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
2824 <input type='hidden' name='KEY' value=' $key ' />
2829 print "<td width='2%' $col > </td>" ;
2831 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/certs/ $confighash { $key }[1].p12" ) {
2833 <td align='center' $col >
2834 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2835 <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'}' />
2836 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
2837 <input type='hidden' name='KEY' value=' $key ' />
2841 ; } elsif (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
2843 <td align='center' $col >
2844 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2845 <input type='image' name=' $Lang ::tr{'download certificate'}' src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' title=' $Lang ::tr{'download certificate'}' />
2846 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
2847 <input type='hidden' name='KEY' value=' $key ' />
2852 print "<td width='2%' $col > </td>" ;
2855 <td align='center' $col >
2856 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2857 <input type='image' name=' $Lang ::tr{'toggle enable disable'}' src='/images/ $gif ' alt=' $Lang ::tr{'toggle enable disable'}' title=' $Lang ::tr{'toggle enable disable'}' />
2858 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
2859 <input type='hidden' name='KEY' value=' $key ' />
2863 <td align='center' $col >
2864 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2865 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
2866 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' title=' $Lang ::tr{'edit'}' />
2867 <input type='hidden' name='KEY' value=' $key ' />
2870 <td align='center' $col >
2871 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2872 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
2873 <input type='image' name=' $Lang ::tr{'remove'}' src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' title=' $Lang ::tr{'remove'}' />
2874 <input type='hidden' name='KEY' value=' $key ' />
2884 # If the config file contains entries, print Key to action icons
2889 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
2890 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
2891 <td class='base'> $Lang ::tr{'click to disable'}</td>
2892 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
2893 <td class='base'> $Lang ::tr{'show certificate'}</td>
2894 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
2895 <td class='base'> $Lang ::tr{'edit'}</td>
2896 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
2897 <td class='base'> $Lang ::tr{'remove'}</td>
2901 <td> <img src='/images/off.gif' alt='?OFF' /></td>
2902 <td class='base'> $Lang ::tr{'click to enable'}</td>
2903 <td> <img src='/images/floppy.gif' alt='?FLOPPY' /></td>
2904 <td class='base'> $Lang ::tr{'download certificate'}</td>
2905 <td> <img src='/images/reload.gif' alt='?RELOAD'/></td>
2906 <td class='base'> $Lang ::tr{'restart'}</td>
2914 <table width='100%'>
2915 <tr><td align='right' colspan='9'>
2916 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2917 <input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />
2923 & Header
:: closebox
();
2925 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'certificate authorities'}" );
2927 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
2929 <th width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
2930 <th width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></th>
2931 <th width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></th>
2935 my $col1 = "bgcolor=' $color {'color22'}'" ;
2936 my $col2 = "bgcolor=' $color {'color20'}'" ;
2937 if (- f
"${General::swroot}/ca/cacert.pem" ) {
2938 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/cacert.pem" ));
2941 <td class='base' $col1 > $Lang ::tr{'root certificate'}</td>
2942 <td class='base' $col1 > $casubject </td>
2943 <td width='3%' align='center' $col1 >
2944 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2945 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
2946 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/info.gif' alt=' $Lang ::tr{'show root certificate'}' title=' $Lang ::tr{'show root certificate'}' />
2949 <td width='3%' align='center' $col1 >
2950 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2951 <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'}' />
2952 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
2955 <td width='4%' $col1 > </td></tr>
2959 # display rootcert generation buttons
2962 <td class='base' $col1 > $Lang ::tr{'root certificate'}:</td>
2963 <td class='base' $col1 > $Lang ::tr{'not present'}</td>
2964 <td colspan='3' $col1 > </td></tr>
2969 if (- f
"${General::swroot}/certs/hostcert.pem" ) {
2970 my $hostsubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/certs/hostcert.pem" ));
2974 <td class='base' $col2 > $Lang ::tr{'host certificate'}</td>
2975 <td class='base' $col2 > $hostsubject </td>
2976 <td width='3%' align='center' $col2 >
2977 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2978 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
2979 <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'}' />
2982 <td width='3%' align='center' $col2 >
2983 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2984 <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'}" />
2985 <input type='hidden' name='ACTION' value=" $Lang ::tr{'download host certificate'}" />
2988 <td width='4%' $col2 > </td></tr>
2995 <td width='25%' class='base' $col2 > $Lang ::tr{'host certificate'}:</td>
2996 <td class='base' $col2 > $Lang ::tr{'not present'}</td>
2997 <td colspan='3' $col2 > </td></tr>
3003 if ( keys %cahash > 0 ) {
3004 foreach my $key ( keys %cahash ) {
3005 if ( $rowcolor ++ % 2 ) {
3007 $col = "bgcolor=' $color {'color20'}'" ;
3010 $col = "bgcolor=' $color {'color22'}'" ;
3012 print "<td class='base' $col > $cahash { $key }[0]</td> \n " ;
3013 print "<td class='base' $col > $cahash { $key }[1]</td> \n " ;
3015 <td align='center' $col >
3016 <form method='post' name='cafrm${key}a' action=' $ENV {'SCRIPT_NAME'}'>
3017 <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'}' />
3018 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
3019 <input type='hidden' name='KEY' value=' $key ' />
3022 <td align='center' $col >
3023 <form method='post' name='cafrm${key}b' action=' $ENV {'SCRIPT_NAME'}'>
3024 <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'}' />
3025 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
3026 <input type='hidden' name='KEY' value=' $key ' />
3029 <td align='center' $col >
3030 <form method='post' name='cafrm${key}c' action=' $ENV {'SCRIPT_NAME'}'>
3031 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
3032 <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'}' />
3033 <input type='hidden' name='KEY' value=' $key ' />
3043 # If the file contains entries, print Key to action icons
3044 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
3047 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
3048 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
3049 <td class='base'> $Lang ::tr{'show certificate'}</td>
3050 <td> <img src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' /></td>
3051 <td class='base'> $Lang ::tr{'download certificate'}</td>
3056 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>" ;
3060 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
3061 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
3064 <td class='base' nowrap='nowrap'> $Lang ::tr{'ca name'}: <img src='/blob.gif' alt='*' /></td>
3065 <td nowrap='nowrap'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' /> </td>
3066 <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td>
3067 <td nowrap='nowrap'><input type='submit' name='ACTION' value=' $Lang ::tr{'upload ca certificate'}' /></td>
3070 <td colspan='3'> $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}:</td>
3071 <td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' /></td>
3077 & Header
:: closebox
();
3078 & Header
:: closebigbox
();
3079 & Header
:: closepage
();
3081 sub array_unique
($) {
3086 foreach my $e ( @
$array ) {
3087 next if $seen { $e }++;
3094 sub make_algos
($$$$$) {
3095 my ( $mode , $encs , $ints , $grps , $pfs ) = @_ ;
3098 foreach my $enc ( @
$encs ) {
3099 foreach my $int ( @
$ints ) {
3100 foreach my $grp ( @
$grps ) {
3103 if ( $mode eq "ike" ) {
3106 if ( $grp =~ m/^e(.*)$/ ) {
3107 push ( @algo , "ecp $1 " );
3109 push ( @algo , "modp $grp " );
3112 } elsif ( $mode eq "esp" && $pfs ) {
3113 my $is_aead = ( $enc =~ m/[cg]cm/ );
3119 if ( $grp eq "none" ) {
3121 } elsif ( $grp =~ m/^e(.*)$/ ) {
3122 push ( @algo , "ecp $1 " );
3124 push ( @algo , "modp $grp " );
3128 push ( @algos , join ( "-" , @algo ));
3133 return & array_unique
( \
@algos );