]>
git.ipfire.org Git - people/pmueller/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 (let the ipsec do its job)
52 my $errormessage = '' ;
55 my %mainsettings = ();
56 & General
:: readhash
( "${General::swroot}/main/settings" , \
%mainsettings );
57 & General
:: readhash
( "/srv/web/ipfire/html/themes/" . $mainsettings { 'THEME' }. "/include/colors.txt" , \
%color );
59 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%netsettings );
61 my $green_cidr = & General
:: ipcidr
( " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" );
62 my $blue_cidr = "# Blue not defined" ;
63 if (& Header
:: blue_used
() && $netsettings { 'BLUE_DEV' }) {
64 $blue_cidr = & General
:: ipcidr
( " $netsettings {'BLUE_NETADDRESS'}/ $netsettings {'BLUE_NETMASK'}" );
66 my $orange_cidr = "# Orange not defined" ;
67 if (& Header
:: orange_used
() && $netsettings { 'ORANGE_DEV' }) {
68 $orange_cidr = & General
:: ipcidr
( " $netsettings {'ORANGE_NETADDRESS'}/ $netsettings {'ORANGE_NETMASK'}" );
73 $cgiparams { 'ENABLED' } = 'off' ;
74 $cgiparams { 'EDIT_ADVANCED' } = 'off' ;
75 $cgiparams { 'ACTION' } = '' ;
76 $cgiparams { 'CA_NAME' } = '' ;
77 $cgiparams { 'KEY' } = '' ;
78 $cgiparams { 'TYPE' } = '' ;
79 $cgiparams { 'ADVANCED' } = '' ;
80 $cgiparams { 'NAME' } = '' ;
81 $cgiparams { 'LOCAL_SUBNET' } = '' ;
82 $cgiparams { 'REMOTE_SUBNET' } = '' ;
83 $cgiparams { 'REMOTE' } = '' ;
84 $cgiparams { 'LOCAL_ID' } = '' ;
85 $cgiparams { 'REMOTE_ID' } = '' ;
86 $cgiparams { 'REMARK' } = '' ;
87 $cgiparams { 'PSK' } = '' ;
88 $cgiparams { 'CERT_NAME' } = '' ;
89 $cgiparams { 'CERT_EMAIL' } = '' ;
90 $cgiparams { 'CERT_OU' } = '' ;
91 $cgiparams { 'CERT_ORGANIZATION' } = '' ;
92 $cgiparams { 'CERT_CITY' } = '' ;
93 $cgiparams { 'CERT_STATE' } = '' ;
94 $cgiparams { 'CERT_COUNTRY' } = '' ;
95 $cgiparams { 'SUBJECTALTNAME' } = '' ;
96 $cgiparams { 'CERT_PASS1' } = '' ;
97 $cgiparams { 'CERT_PASS2' } = '' ;
98 $cgiparams { 'ROOTCERT_HOSTNAME' } = '' ;
99 $cgiparams { 'ROOTCERT_COUNTRY' } = '' ;
100 $cgiparams { 'P12_PASS' } = '' ;
101 $cgiparams { 'ROOTCERT_ORGANIZATION' } = '' ;
102 $cgiparams { 'ROOTCERT_HOSTNAME' } = '' ;
103 $cgiparams { 'ROOTCERT_EMAIL' } = '' ;
104 $cgiparams { 'ROOTCERT_OU' } = '' ;
105 $cgiparams { 'ROOTCERT_CITY' } = '' ;
106 $cgiparams { 'ROOTCERT_STATE' } = '' ;
107 $cgiparams { 'RW_NET' } = '' ;
108 $cgiparams { 'DPD_DELAY' } = '30' ;
109 $cgiparams { 'DPD_TIMEOUT' } = '120' ;
110 $cgiparams { 'FORCE_MOBIKE' } = 'off' ;
111 $cgiparams { 'START_ACTION' } = 'start' ;
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.
141 sub cleanssldatabase
{
142 if ( open ( FILE
, ">${General::swroot}/certs/serial" )) {
146 if ( open ( FILE
, ">${General::swroot}/certs/index.txt" )) {
150 unlink ( "${General::swroot}/certs/index.txt.old" );
151 unlink ( "${General::swroot}/certs/serial.old" );
152 unlink ( "${General::swroot}/certs/01.pem" );
154 sub newcleanssldatabase
{
155 if (! - s
"${General::swroot}/certs/serial" ) {
156 open ( FILE
, ">${General::swroot}/certs/serial" );
160 if (! - s
">${General::swroot}/certs/index.txt" ) {
161 system ( "touch ${General::swroot}/certs/index.txt" );
163 unlink ( "${General::swroot}/certs/index.txt.old" );
164 unlink ( "${General::swroot}/certs/serial.old" );
165 # unlink ("${General::swroot}/certs/01.pem"); numbering evolves. Wrong place to delete
169 ### Call openssl and return errormessage if any
173 my $retssl = `/usr/bin/openssl $opt 2>&1` ; #redirect stderr
175 foreach my $line ( split ( /\n/ , $retssl )) {
176 & General
:: log ( "ipsec" , " $line " ) if ( 0 ); # 1 for verbose logging
177 $ret .= '<br>' . $line if ( $line =~ /error|unknown/ );
180 $ret = & Header
:: cleanhtml
( $ret );
182 return $ret ?
" $Lang ::tr{'openssl produced an error'}: $ret " : '' ;
185 ### Obtain a CN from given cert
187 sub getCNfromcert
($) {
188 #&General::log("ipsec", "Extracting name from $_[0]...");
189 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
190 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
192 $temp =~ s
+/ Email
+, E
+;
193 $temp =~ s/ ST=/ S=/ ;
199 ### Obtain Subject from given cert
201 sub getsubjectfromcert
($) {
202 #&General::log("ipsec", "Extracting subject from $_[0]...");
203 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
204 $temp =~ /Subject: (.*)[\n]/ ;
206 $temp =~ s
+/ Email
+, E
+;
207 $temp =~ s/ ST=/ S=/ ;
211 ### Combine local subnet and connection name to make a unique name for each connection section
212 ### (this sub is not used now)
214 sub makeconnname
($) {
218 $subnet =~ /^(.*?)\/ (.* ?
)$/; # $1=IP $2=mask
219 my $ip = unpack ( 'N' , & Socket
:: inet_aton
( $1 ));
220 if ( length ( $2 ) > 2 ) {
221 my $mm = unpack ( 'N' , & Socket
:: inet_aton
( $2 ));
222 while ( ( $mm & 1 )== 0 ) {
229 return sprintf ( " %s - %X " , $conn , $ip );
232 ### Write a config file.
234 ###Type=Host : GUI can choose the interface used (RED,GREEN,BLUE) and
235 ### the side is always defined as 'left'.
238 sub writeipsecfiles
{
239 my %lconfighash = ();
240 my %lvpnsettings = ();
241 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%lconfighash );
242 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%lvpnsettings );
244 open ( CONF
, ">${General::swroot}/vpn/ipsec.conf" ) or die "Unable to open ${General::swroot}/vpn/ipsec.conf: $!" ;
245 open ( SECRETS
, ">${General::swroot}/vpn/ipsec.secrets" ) or die "Unable to open ${General::swroot}/vpn/ipsec.secrets: $!" ;
248 print CONF
"version 2 \n\n " ;
249 print CONF
"conn %default \n " ;
250 print CONF
" \t keyingtries= %forever \n " ;
253 # Add user includes to config file
254 if (- e
"/etc/ipsec.user.conf" ) {
255 print CONF
"include /etc/ipsec.user.conf \n " ;
259 print SECRETS
"include /etc/ipsec.user.secrets \n " ;
261 if (- f
"${General::swroot}/certs/hostkey.pem" ) {
262 print SECRETS
": RSA ${General::swroot}/certs/hostkey.pem \n "
264 my $last_secrets = '' ; # old the less specifics connections
266 foreach my $key ( keys %lconfighash ) {
267 next if ( $lconfighash { $key }[ 0 ] ne 'on' );
269 #remote peer is not set? => use '%any'
270 $lconfighash { $key }[ 10 ] = ' %any ' if ( $lconfighash { $key }[ 10 ] eq '' );
273 if ( $lconfighash { $key }[ 26 ] eq 'BLUE' ) {
274 $localside = $netsettings { 'BLUE_ADDRESS' };
275 } elsif ( $lconfighash { $key }[ 26 ] eq 'GREEN' ) {
276 $localside = $netsettings { 'GREEN_ADDRESS' };
277 } elsif ( $lconfighash { $key }[ 26 ] eq 'ORANGE' ) {
278 $localside = $netsettings { 'ORANGE_ADDRESS' };
280 $localside = $lvpnsettings { 'VPN_IP' };
283 print CONF
"conn $lconfighash { $key }[1] \n " ;
284 print CONF
" \t left= $localside \n " ;
285 print CONF
" \t leftsubnet=" . & make_subnets
( $lconfighash { $key }[ 8 ]) . " \n " ;
286 print CONF
" \t leftfirewall=yes \n " ;
287 print CONF
" \t lefthostaccess=yes \n " ;
288 print CONF
" \t right= $lconfighash { $key }[10] \n " ;
290 if ( $lconfighash { $key }[ 3 ] eq 'net' ) {
291 print CONF
" \t rightsubnet=" . & make_subnets
( $lconfighash { $key }[ 11 ]) . " \n " ;
294 # Local Cert and Remote Cert (unless auth is DN dn-auth)
295 if ( $lconfighash { $key }[ 4 ] eq 'cert' ) {
296 print CONF
" \t leftcert=${General::swroot}/certs/hostcert.pem \n " ;
297 print CONF
" \t rightcert=${General::swroot}/certs/ $lconfighash { $key }[1]cert.pem \n " if ( $lconfighash { $key }[ 2 ] ne ' %auth -dn' );
300 # Local and Remote IDs
301 print CONF
" \t leftid= \" $lconfighash { $key }[7] \"\n " if ( $lconfighash { $key }[ 7 ]);
302 print CONF
" \t rightid= \" $lconfighash { $key }[9] \"\n " if ( $lconfighash { $key }[ 9 ]);
305 my $pfs = $lconfighash { $key }[ 28 ] eq 'on' ?
'on' : 'off' ;
308 if ( $lconfighash { $key }[ 18 ] && $lconfighash { $key }[ 19 ] && $lconfighash { $key }[ 20 ]) {
309 my @encs = split ( '\|' , $lconfighash { $key }[ 18 ]);
310 my @ints = split ( '\|' , $lconfighash { $key }[ 19 ]);
311 my @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
313 my @algos = & make_algos
( "ike" , \
@encs , \
@ints , \
@groups , 1 );
314 print CONF
" \t ike=" . join ( "," , @algos );
316 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
323 if ( $lconfighash { $key }[ 21 ] && $lconfighash { $key }[ 22 ]) {
324 my @encs = split ( '\|' , $lconfighash { $key }[ 21 ]);
325 my @ints = split ( '\|' , $lconfighash { $key }[ 22 ]);
326 my @groups = split ( '\|' , $lconfighash { $key }[ 23 ]);
328 # Use IKE grouptype if no ESP group type has been selected
329 # (for backwards compatibility)
330 if ( $lconfighash { $key }[ 23 ] eq "" ) {
331 @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
334 my @algos = & make_algos
( "esp" , \
@encs , \
@ints , \
@groups , ( $pfs eq "on" ));
335 print CONF
" \t esp=" . join ( "," , @algos );
337 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
345 if (! $lconfighash { $key }[ 29 ]) {
346 $lconfighash { $key }[ 29 ] = "ikev1" ;
349 print CONF
" \t keyexchange= $lconfighash { $key }[29] \n " ;
352 print CONF
" \t ikelifetime= $lconfighash { $key }[16]h \n " if ( $lconfighash { $key }[ 16 ]);
353 print CONF
" \t keylife= $lconfighash { $key }[17]h \n " if ( $lconfighash { $key }[ 17 ]);
356 print CONF
" \t compress=yes \n " if ( $lconfighash { $key }[ 13 ] eq 'on' );
359 if (( $lconfighash { $key }[ 29 ] eq "ikev2" ) && ( $lconfighash { $key }[ 32 ] eq 'on' )) {
360 print CONF
" \t mobike=yes \n " ;
363 # Dead Peer Detection
364 my $dpdaction = $lconfighash { $key }[ 27 ];
365 print CONF
" \t dpdaction= $dpdaction \n " ;
367 # If the dead peer detection is disabled and IKEv2 is used,
368 # dpddelay must be set to zero, too.
369 if ( $dpdaction eq "none" ) {
370 if ( $lconfighash { $key }[ 29 ] eq "ikev2" ) {
371 print CONF
" \t dpddelay=0 \n " ;
374 my $dpddelay = $lconfighash { $key }[ 31 ];
378 print CONF
" \t dpddelay= $dpddelay \n " ;
379 my $dpdtimeout = $lconfighash { $key }[ 30 ];
383 print CONF
" \t dpdtimeout= $dpdtimeout \n " ;
386 # Build Authentication details: LEFTid RIGHTid : PSK psk
388 if ( $lconfighash { $key }[ 4 ] eq 'psk' ) {
389 $psk_line = ( $lconfighash { $key }[ 7 ] ?
$lconfighash { $key }[ 7 ] : $localside ) . " " ;
390 $psk_line .= $lconfighash { $key }[ 9 ] ?
$lconfighash { $key }[ 9 ] : $lconfighash { $key }[ 10 ]; #remoteid or remote address?
391 $psk_line .= " : PSK ' $lconfighash { $key }[5]' \n " ;
392 # if the line contains %any, it is less specific than two IP or ID, so move it at end of file.
393 if ( $psk_line =~ /%any/ ) {
394 $last_secrets .= $psk_line ;
396 print SECRETS
$psk_line ;
398 print CONF
" \t authby=secret \n " ;
400 print CONF
" \t authby=rsasig \n " ;
401 print CONF
" \t leftrsasigkey= %cert \n " ;
402 print CONF
" \t rightrsasigkey= %cert \n " ;
405 my $start_action = $lconfighash { $key }[ 33 ];
406 if (! $start_action ) {
407 $start_action = "start" ;
410 # Automatically start only if a net-to-net connection
411 if ( $lconfighash { $key }[ 3 ] eq 'host' ) {
412 print CONF
" \t auto=add \n " ;
413 print CONF
" \t rightsourceip= $lvpnsettings {'RW_NET'} \n " ;
415 print CONF
" \t auto= $start_action \n " ;
419 print CONF
" \t fragmentation=yes \n " ;
424 # Add post user includes to config file
425 # After the GUI-connections allows to patch connections.
426 if (- e
"/etc/ipsec.user-post.conf" ) {
427 print CONF
"include /etc/ipsec.user-post.conf \n " ;
431 print SECRETS
$last_secrets if ( $last_secrets );
436 # Hook to regenerate the configuration files.
437 if ( $ENV { "REMOTE_ADDR" } eq "" ) {
443 ### Save main settings
445 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
446 & 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>: $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}
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> $Lang ::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}</td>
693 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
694 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
701 & Header
:: closebigbox
();
702 & Header
:: closepage
();
705 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
706 delete $cahash { $cgiparams { 'KEY' }};
707 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
708 system ( '/usr/local/bin/ipsecctrl' , 'R' );
712 $errormessage = $Lang :: tr
{ 'invalid key' };
716 ### Display root certificate
718 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
719 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
721 & Header
:: showhttpheaders
();
722 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
723 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
724 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
725 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'root certificate'}:" );
726 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/cacert.pem` ;
728 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'host certificate'}:" );
729 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/hostcert.pem` ;
731 $output = & Header
:: cleanhtml
( $output , "y" );
732 print "<pre> $output </pre> \n " ;
734 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
735 & Header
:: closebigbox
();
736 & Header
:: closepage
();
740 ### Export root certificate to browser
742 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
743 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
744 print "Content-Type: application/force-download \n " ;
745 print "Content-Disposition: attachment; filename=cacert.pem \r\n\r\n " ;
746 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/cacert.pem` ;
750 ### Export host certificate to browser
752 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
753 if ( - f
"${General::swroot}/certs/hostcert.pem" ) {
754 print "Content-Type: application/force-download \n " ;
755 print "Content-Disposition: attachment; filename=hostcert.pem \r\n\r\n " ;
756 print `/usr/bin/openssl x509 -in ${General::swroot}/certs/hostcert.pem` ;
760 ### Form for generating/importing the caroot+host certificate
762 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
763 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
765 if (- f
"${General::swroot}/ca/cacert.pem" ) {
766 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
770 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
771 # fill in initial values
772 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
773 if (- e
"${General::swroot}/red/active" && open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
774 my $ipaddr = < IPADDR
>;
777 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
778 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
779 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
782 $cgiparams { 'ROOTCERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' } if (! $cgiparams { 'ROOTCERT_COUNTRY' });
783 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
784 & General
:: log ( "ipsec" , "Importing from p12..." );
786 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
787 $errormessage = $Lang :: tr
{ 'there was no file upload' };
791 # Move uploaded certificate request to a temporary file
792 ( my $fh , my $filename ) = tempfile
( );
793 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
798 # Extract the CA certificate from the file
799 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
800 if ( open ( STDIN
, "-|" )) {
801 my $opt = " pkcs12 -cacerts -nokeys" ;
802 $opt .= " -in $filename " ;
803 $opt .= " -out /tmp/newcacert" ;
804 $errormessage = & callssl
( $opt );
806 print " $cgiparams {'P12_PASS'} \n " ;
810 # Extract the Host certificate from the file
811 if (! $errormessage ) {
812 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
813 if ( open ( STDIN
, "-|" )) {
814 my $opt = " pkcs12 -clcerts -nokeys" ;
815 $opt .= " -in $filename " ;
816 $opt .= " -out /tmp/newhostcert" ;
817 $errormessage = & callssl
( $opt );
819 print " $cgiparams {'P12_PASS'} \n " ;
824 # Extract the Host key from the file
825 if (! $errormessage ) {
826 & General
:: log ( "ipsec" , "Extracting private key from p12..." );
827 if ( open ( STDIN
, "-|" )) {
828 my $opt = " pkcs12 -nocerts -nodes" ;
829 $opt .= " -in $filename " ;
830 $opt .= " -out /tmp/newhostkey" ;
831 $errormessage = & callssl
( $opt );
833 print " $cgiparams {'P12_PASS'} \n " ;
838 if (! $errormessage ) {
839 & General
:: log ( "ipsec" , "Moving cacert..." );
840 move
( "/tmp/newcacert" , "${General::swroot}/ca/cacert.pem" );
841 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
844 if (! $errormessage ) {
845 & General
:: log ( "ipsec" , "Moving host cert..." );
846 move
( "/tmp/newhostcert" , "${General::swroot}/certs/hostcert.pem" );
847 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
850 if (! $errormessage ) {
851 & General
:: log ( "ipsec" , "Moving private key..." );
852 move
( "/tmp/newhostkey" , "${General::swroot}/certs/hostkey.pem" );
853 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
858 unlink ( '/tmp/newcacert' );
859 unlink ( '/tmp/newhostcert' );
860 unlink ( '/tmp/newhostkey' );
862 unlink ( "${General::swroot}/ca/cacert.pem" );
863 unlink ( "${General::swroot}/certs/hostcert.pem" );
864 unlink ( "${General::swroot}/certs/hostkey.pem" );
868 # Create empty CRL cannot be done because we don't have
869 # the private key for this CAROOT
870 # IPFire can only import certificates
872 & General
:: log ( "ipsec" , "p12 import completed!" );
874 goto ROOTCERT_SUCCESS
;
876 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
878 # Validate input since the form was submitted
879 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
880 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
883 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
884 $errormessage = $Lang :: tr
{ 'organization too long' };
887 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
888 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
891 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
892 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
895 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
896 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
899 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
900 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
903 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
904 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
907 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
908 $errormessage = $Lang :: tr
{ 'invalid input for department' };
911 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
912 $errormessage = $Lang :: tr
{ 'invalid input for city' };
915 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
916 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
919 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
920 $errormessage = $Lang :: tr
{ 'invalid input for country' };
923 #the exact syntax is a list comma separated of
924 # email:any-validemail
925 # URI: a uniform resource indicator
926 # DNS: a DNS domain name
927 # RID: a registered OBJECT IDENTIFIER
929 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
931 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
932 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
936 # Copy the cgisettings to vpnsettings and save the configfile
937 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
938 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
939 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
940 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
941 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
942 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
943 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
944 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
946 # Replace empty strings with a .
947 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
948 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
949 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
951 # Create the CA certificate
952 if (! $errormessage ) {
953 & General
:: log ( "ipsec" , "Creating cacert..." );
954 if ( open ( STDIN
, "-|" )) {
955 my $opt = " req -x509 -sha256 -nodes" ;
956 $opt .= " -days 999999" ;
957 $opt .= " -newkey rsa:4096" ;
958 $opt .= " -keyout ${General::swroot}/private/cakey.pem" ;
959 $opt .= " -out ${General::swroot}/ca/cacert.pem" ;
961 $errormessage = & callssl
( $opt );
963 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
966 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
968 print " $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
969 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
974 # Create the Host certificate request
975 if (! $errormessage ) {
976 & General
:: log ( "ipsec" , "Creating host cert..." );
977 if ( open ( STDIN
, "-|" )) {
978 my $opt = " req -sha256 -nodes" ;
979 $opt .= " -newkey rsa:2048" ;
980 $opt .= " -keyout ${General::swroot}/certs/hostkey.pem" ;
981 $opt .= " -out ${General::swroot}/certs/hostreq.pem" ;
982 $errormessage = & callssl
( $opt );
984 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
987 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
989 print " $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
990 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
997 # Sign the host certificate request
998 if (! $errormessage ) {
999 & General
:: log ( "ipsec" , "Self signing host cert..." );
1001 #No easy way for specifying the contain of subjectAltName without writing a config file...
1002 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1004 basicConstraints=CA:FALSE
1005 nsComment="OpenSSL Generated Certificate"
1006 subjectKeyIdentifier=hash
1007 authorityKeyIdentifier=keyid,issuer:always
1008 extendedKeyUsage = serverAuth
1011 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1014 my $opt = " ca -md sha256 -days 999999" ;
1015 $opt .= " -batch -notext" ;
1016 $opt .= " -in ${General::swroot}/certs/hostreq.pem" ;
1017 $opt .= " -out ${General::swroot}/certs/hostcert.pem" ;
1018 $opt .= " -extfile $v3extname " ;
1019 $errormessage = & callssl
( $opt );
1020 unlink ( "${General::swroot}/certs/hostreq.pem" ); #no more needed
1021 unlink ( $v3extname );
1024 # Create an empty CRL
1025 if (! $errormessage ) {
1026 & General
:: log ( "ipsec" , "Creating emptycrl..." );
1027 my $opt = " ca -gencrl" ;
1028 $opt .= " -out ${General::swroot}/crls/cacrl.pem" ;
1029 $errormessage = & callssl
( $opt );
1032 # Successfully build CA / CERT!
1033 if (! $errormessage ) {
1034 & cleanssldatabase
();
1035 goto ROOTCERT_SUCCESS
;
1039 unlink ( "${General::swroot}/ca/cacert.pem" );
1040 unlink ( "${General::swroot}/certs/hostkey.pem" );
1041 unlink ( "${General::swroot}/certs/hostcert.pem" );
1042 unlink ( "${General::swroot}/crls/cacrl.pem" );
1043 & cleanssldatabase
();
1047 & Header
:: showhttpheaders
();
1048 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1049 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1050 if ( $errormessage ) {
1051 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1052 print "<class name='base'> $errormessage " ;
1053 print " </class>" ;
1054 & Header
:: closebox
();
1056 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
1058 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
1059 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1060 <tr><td width='40%' class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
1061 <td width='60%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td></tr>
1062 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}: <img src='/blob.gif' alt='*' /></td>
1063 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td></tr>
1064 <tr><td class='base'> $Lang ::tr{'your e-mail'}:</td>
1065 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td></tr>
1066 <tr><td class='base'> $Lang ::tr{'your department'}:</td>
1067 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td></tr>
1068 <tr><td class='base'> $Lang ::tr{'city'}:</td>
1069 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td></tr>
1070 <tr><td class='base'> $Lang ::tr{'state or province'}:</td>
1071 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td></tr>
1072 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1073 <td class='base'><select name='ROOTCERT_COUNTRY'>
1076 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1077 print "<option value=' $Countries ::countries{ $country }'" ;
1078 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1079 print " selected='selected'" ;
1081 print "> $country </option>" ;
1085 <tr><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)</td>
1086 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' /></td></tr>
1088 <td><br /><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /><br /><br /></td></tr>
1089 <tr><td class='base' colspan='2' align='left'>
1090 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1091 $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'}
1093 <tr><td colspan='2'><hr></td></tr>
1094 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}:</td>
1095 <td nowrap='nowrap'><input type='file' name='FH' size='32' /></td></tr>
1096 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
1097 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td></tr>
1099 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td></tr>
1100 <tr><td class='base' colspan='2' align='left'>
1101 <img src='/blob.gif' alt='*' /> $Lang ::tr{'required field'}</td></tr>
1105 & Header
:: closebox
();
1106 & Header
:: closebigbox
();
1107 & Header
:: closepage
();
1112 system ( '/usr/local/bin/ipsecctrl' , 'S' );
1117 ### Export PKCS12 file to browser
1119 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
1120 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1121 print "Content-Type: application/force-download \n " ;
1122 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
1123 print "Content-Type: application/octet-stream \r\n\r\n " ;
1124 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12` ;
1128 ### Display certificate
1130 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
1131 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1133 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1134 & Header
:: showhttpheaders
();
1135 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1136 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1137 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'cert'}:" );
1138 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1139 $output = & Header
:: cleanhtml
( $output , "y" );
1140 print "<pre> $output </pre> \n " ;
1141 & Header
:: closebox
();
1142 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1143 & Header
:: closebigbox
();
1144 & Header
:: closepage
();
1149 ### Export Certificate to browser
1151 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
1152 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1154 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1155 print "Content-Type: application/force-download \n " ;
1156 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \n\n " ;
1157 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1162 ### Enable/Disable connection
1164 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1166 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1167 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1169 if ( $confighash { $cgiparams { 'KEY' }}) {
1170 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
1171 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
1172 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1174 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1176 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1177 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
1178 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1183 $errormessage = $Lang :: tr
{ 'invalid key' };
1187 ### Restart connection
1189 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
1190 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1191 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1193 if ( $confighash { $cgiparams { 'KEY' }}) {
1195 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
1199 $errormessage = $Lang :: tr
{ 'invalid key' };
1203 ### Remove connection
1205 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
1206 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1207 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1209 if ( $confighash { $cgiparams { 'KEY' }}) {
1210 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1211 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1212 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1213 delete $confighash { $cgiparams { 'KEY' }};
1214 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1217 $errormessage = $Lang :: tr
{ 'invalid key' };
1219 & General
:: firewall_reload
();
1221 ### Choose between adding a host-net or net-net connection
1223 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
1224 & Header
:: showhttpheaders
();
1225 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1226 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1227 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection type' });
1229 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
1230 <b> $Lang ::tr{'connection type'}:</b><br />
1232 <tr><td><input type='radio' name='TYPE' value='host' checked='checked' /></td>
1233 <td class='base'> $Lang ::tr{'host to net vpn'}</td>
1235 <td><input type='radio' name='TYPE' value='net' /></td>
1236 <td class='base'> $Lang ::tr{'net to net vpn'}</td>
1238 <td align='center' colspan='2'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td>
1243 & Header
:: closebox
();
1244 & Header
:: closebigbox
();
1245 & Header
:: closepage
();
1248 ### Adding/Editing/Saving a connection
1250 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
1251 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
1252 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
1254 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1255 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1256 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1258 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
1259 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
1260 $errormessage = $Lang :: tr
{ 'invalid key' };
1263 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
1264 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
1265 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
1266 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
1267 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
1268 #$cgiparams{'free'} = $confighash{$cgiparams{'KEY'}}[6];
1269 $cgiparams { 'LOCAL_ID' } = $confighash { $cgiparams { 'KEY' }}[ 7 ];
1270 my @local_subnets = split ( "," , $confighash { $cgiparams { 'KEY' }}[ 8 ]);
1271 $cgiparams { 'LOCAL_SUBNET' } = join ( /\|/ , @local_subnets );
1272 $cgiparams { 'REMOTE_ID' } = $confighash { $cgiparams { 'KEY' }}[ 9 ];
1273 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
1274 my @remote_subnets = split ( "," , $confighash { $cgiparams { 'KEY' }}[ 11 ]);
1275 $cgiparams { 'REMOTE_SUBNET' } = join ( /\|/ , @remote_subnets );
1276 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
1277 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
1278 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
1279 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
1280 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
1281 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
1282 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
1283 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
1284 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
1285 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
1286 if ( $cgiparams { 'ESP_GROUPTYPE' } eq "" ) {
1287 $cgiparams { 'ESP_GROUPTYPE' } = $cgiparams { 'IKE_GROUPTYPE' };
1289 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
1290 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
1291 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
1292 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
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 my @local_subnets = split ( "," , $cgiparams { 'LOCAL_SUBNET' });
1356 foreach my $subnet ( @local_subnets ) {
1357 unless (& Network
:: check_subnet
( $subnet )) {
1358 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
1363 # Allow only one roadwarrior/psk without remote IP-address
1364 if ( $cgiparams { 'REMOTE' } eq '' && $cgiparams { 'AUTH' } eq 'psk' ) {
1365 foreach my $key ( keys %confighash ) {
1366 if ( ( $cgiparams { 'KEY' } ne $key ) &&
1367 ( $confighash { $key }[ 4 ] eq 'psk' ) &&
1368 ( $confighash { $key }[ 10 ] eq '' ) ) {
1369 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
1375 if ( $cgiparams { 'TYPE' } eq 'net' ) {
1376 my @remote_subnets = split ( "," , $cgiparams { 'REMOTE_SUBNET' });
1377 foreach my $subnet ( @remote_subnets ) {
1378 unless (& Network
:: check_subnet
( $subnet )) {
1379 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
1385 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
1386 $errormessage = $Lang :: tr
{ 'invalid input' };
1389 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
1390 $errormessage = $Lang :: tr
{ 'invalid input' };
1394 # Allow nothing or a string (DN,FDQN,) beginning with @
1395 # with no comma but slashes between RID eg @O=FR/C=Paris/OU=myhome/CN=franck
1396 if ( ( $cgiparams { 'LOCAL_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1397 ( $cgiparams { 'REMOTE_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1398 (( $cgiparams { 'REMOTE_ID' } eq $cgiparams { 'LOCAL_ID' }) && ( $cgiparams { 'LOCAL_ID' } ne '' ))
1400 $errormessage = $Lang :: tr
{ 'invalid local-remote id' } . '<br />' .
1401 'DER_ASN1_DN: @c =FR/ou=Paris/ou=Home/cn=*<br />' .
1402 'FQDN: @ipfire .org<br />' .
1403 'USER_FQDN: info @ipfire .org<br />' .
1404 'IPV4_ADDR: 123.123.123.123' ;
1407 # If Auth is DN, verify existance of Remote ID.
1408 if ( $cgiparams { 'REMOTE_ID' } eq '' && (
1409 $cgiparams { 'AUTH' } eq 'auth-dn' || # while creation
1410 $confighash { $cgiparams { 'KEY' }}[ 2 ] eq ' %auth -dn' )){ # while editing
1411 $errormessage = $Lang :: tr
{ 'vpn missing remote id' };
1415 if ( $cgiparams { 'TYPE' } eq 'net' ){
1416 $warnmessage =& General
:: checksubnets
( '' , $cgiparams { 'REMOTE_SUBNET' }, 'ipsec' );
1417 if ( $warnmessage ne '' ){
1418 $warnmessage = $Lang :: tr
{ 'remote subnet' }. " ( $cgiparams {'REMOTE_SUBNET'}) <br>" . $warnmessage ;
1422 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1423 if (! length ( $cgiparams { 'PSK' }) ) {
1424 $errormessage = $Lang :: tr
{ 'pre-shared key is too short' };
1427 if ( $cgiparams { 'PSK' } =~ /'/ ) {
1428 $cgiparams { 'PSK' } =~ tr/'/ / ;
1429 $errormessage = $Lang :: tr
{ 'invalid characters found in pre-shared key' };
1432 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
1433 if ( $cgiparams { 'KEY' }) {
1434 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1437 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1438 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1442 # Move uploaded certificate request to a temporary file
1443 ( my $fh , my $filename ) = tempfile
( );
1444 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1449 # Sign the certificate request
1450 & General
:: log ( "ipsec" , "Signing your cert $cgiparams {'NAME'}..." );
1451 my $opt = " ca -md sha256 -days 999999" ;
1452 $opt .= " -batch -notext" ;
1453 $opt .= " -in $filename " ;
1454 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1456 if ( $errormessage = & callssl
( $opt ) ) {
1458 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1459 & cleanssldatabase
();
1463 & cleanssldatabase
();
1466 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1467 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1468 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1471 } elsif ( $cgiparams { 'AUTH' } eq 'pkcs12' ) {
1472 & General
:: log ( "ipsec" , "Importing from p12..." );
1474 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1475 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1476 goto ROOTCERT_ERROR
;
1479 # Move uploaded certificate request to a temporary file
1480 ( my $fh , my $filename ) = tempfile
( );
1481 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1483 goto ROOTCERT_ERROR
;
1486 # Extract the CA certificate from the file
1487 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
1488 if ( open ( STDIN
, "-|" )) {
1489 my $opt = " pkcs12 -cacerts -nokeys" ;
1490 $opt .= " -in $filename " ;
1491 $opt .= " -out /tmp/newcacert" ;
1492 $errormessage = & callssl
( $opt );
1494 print " $cgiparams {'P12_PASS'} \n " ;
1498 # Extract the Host certificate from the file
1499 if (! $errormessage ) {
1500 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
1501 if ( open ( STDIN
, "-|" )) {
1502 my $opt = " pkcs12 -clcerts -nokeys" ;
1503 $opt .= " -in $filename " ;
1504 $opt .= " -out /tmp/newhostcert" ;
1505 $errormessage = & callssl
( $opt );
1507 print " $cgiparams {'P12_PASS'} \n " ;
1512 if (! $errormessage ) {
1513 & General
:: log ( "ipsec" , "Moving cacert..." );
1514 #If CA have new subject, add it to our list of CA
1515 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( '/tmp/newcacert' ));
1517 foreach my $x ( keys %cahash ) {
1518 $casubject = '' if ( $cahash { $x }[ 1 ] eq $casubject );
1519 unshift ( @names , $cahash { $x }[ 0 ]);
1521 if ( $casubject ) { # a new one!
1522 my $temp = `/usr/bin/openssl x509 -text -in /tmp/newcacert` ;
1523 if ( $temp !~ /CA:TRUE/i ) {
1524 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
1526 #compute a name for it
1528 while ( grep ( /Imported-$idx/ , @names ) ) { $idx ++};
1529 $cgiparams { 'CA_NAME' }= "Imported- $idx " ;
1530 $cgiparams { 'CERT_NAME' }=& Header
:: cleanhtml
( getCNfromcert
( '/tmp/newhostcert' ));
1531 move
( "/tmp/newcacert" , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1532 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1533 if (! $errormessage ) {
1534 my $key = & General
:: findhasharraykey
( \
%cahash );
1535 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
1536 $cahash { $key }[ 1 ] = $casubject ;
1537 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1538 system ( '/usr/local/bin/ipsecctrl' , 'R' );
1543 if (! $errormessage ) {
1544 & General
:: log ( "ipsec" , "Moving host cert..." );
1545 move
( "/tmp/newhostcert" , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1546 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1551 unlink ( '/tmp/newcacert' );
1552 unlink ( '/tmp/newhostcert' );
1553 if ( $errormessage ) {
1554 unlink ( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1555 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1558 & General
:: log ( "ipsec" , "p12 import completed!" );
1559 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
1560 if ( $cgiparams { 'KEY' }) {
1561 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1564 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1565 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1568 # Move uploaded certificate to a temporary file
1569 ( my $fh , my $filename ) = tempfile
( );
1570 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1575 # Verify the certificate has a valid CA and move it
1576 & General
:: log ( "ipsec" , "Validating imported cert against our known CA..." );
1577 my $validca = 1 ; #assume ok
1578 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/cacert.pem $filename ` ;
1579 if ( $test !~ /: OK/ ) {
1581 foreach my $key ( keys %cahash ) {
1582 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $key }[0]cert.pem $filename ` ;
1583 if ( $test =~ /: OK/ ) {
1590 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
1594 move
( $filename , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1596 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1602 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1603 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1604 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1605 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1608 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
1609 if ( $cgiparams { 'KEY' }) {
1610 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1613 # Validate input since the form was submitted
1614 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
1615 $errormessage = $Lang :: tr
{ 'name too long' };
1618 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1619 $errormessage = $Lang :: tr
{ 'invalid input for name' };
1622 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
1623 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1626 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
1627 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1630 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1631 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1634 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
1635 $errormessage = $Lang :: tr
{ 'organization too long' };
1638 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1639 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1642 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1643 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1646 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1647 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1650 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1651 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1654 #the exact syntax is a list comma separated of
1655 # email:any-validemail
1656 # URI: a uniform resource indicator
1657 # DNS: a DNS domain name
1658 # RID: a registered OBJECT IDENTIFIER
1660 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
1662 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
1663 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
1667 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
1668 $errormessage = $Lang :: tr
{ 'password too short' };
1671 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
1672 $errormessage = $Lang :: tr
{ 'passwords do not match' };
1676 # Replace empty strings with a .
1677 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
1678 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
1679 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
1681 # Create the Client certificate request
1682 & General
:: log ( "ipsec" , "Creating a cert..." );
1684 if ( open ( STDIN
, "-|" )) {
1685 my $opt = " req -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
1686 $opt .= " -newkey rsa:2048" ;
1687 $opt .= " -keyout ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1688 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1690 if ( $errormessage = & callssl
( $opt ) ) {
1691 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1692 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1696 print " $cgiparams {'CERT_COUNTRY'} \n " ;
1699 print " $cgiparams {'CERT_ORGANIZATION'} \n " ;
1701 print " $cgiparams {'CERT_NAME'} \n " ;
1702 print " $cgiparams {'CERT_EMAIL'} \n " ;
1708 # Sign the client certificate request
1709 & General
:: log ( "ipsec" , "Signing the cert $cgiparams {'NAME'}..." );
1711 #No easy way for specifying the contain of subjectAltName without writing a config file...
1712 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1714 basicConstraints=CA:FALSE
1715 nsComment="OpenSSL Generated Certificate"
1716 subjectKeyIdentifier=hash
1717 extendedKeyUsage=clientAuth
1718 authorityKeyIdentifier=keyid,issuer:always
1721 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1724 my $opt = " ca -md sha256 -days 999999 -batch -notext" ;
1725 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1726 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1727 $opt .= " -extfile $v3extname " ;
1729 if ( $errormessage = & callssl
( $opt ) ) {
1730 unlink ( $v3extname );
1731 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1732 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1733 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1734 & cleanssldatabase
();
1737 unlink ( $v3extname );
1738 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1739 & cleanssldatabase
();
1742 # Create the pkcs12 file
1743 & General
:: log ( "ipsec" , "Packing a pkcs12 file..." );
1744 $opt = " pkcs12 -export" ;
1745 $opt .= " -inkey ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1746 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1747 $opt .= " -name \" $cgiparams {'NAME'} \" " ;
1748 $opt .= " -passout pass: $cgiparams {'CERT_PASS1'}" ;
1749 $opt .= " -certfile ${General::swroot}/ca/cacert.pem" ;
1750 $opt .= " -caname \" $vpnsettings {'ROOTCERT_ORGANIZATION'} CA \" " ;
1751 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}.p12" ;
1753 if ( $errormessage = & callssl
( $opt ) ) {
1754 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1755 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1756 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}.p12" );
1759 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1761 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
1762 ; # Nothing, just editing
1763 } elsif ( $cgiparams { 'AUTH' } eq 'auth-dn' ) {
1764 $cgiparams { 'CERT_NAME' } = ' %auth -dn' ; # a special value saying 'no cert file'
1766 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
1770 # 1)Error message here is not accurate.
1771 # 2)Test is superfluous, openswan can reference same cert multiple times
1772 # 3)Present since initial version (1.3.2.11), it isn't a bug correction
1773 # Check if there is no other entry with this certificate name
1774 #if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk') && ($cgiparams{'AUTH'} ne 'auth-dn')) {
1775 # foreach my $key (keys %confighash) {
1776 # if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) {
1777 # $errormessage = $Lang::tr{'a connection with this common name already exists'};
1778 # goto VPNCONF_ERROR;
1784 my $key = $cgiparams { 'KEY' };
1786 $key = & General
:: findhasharraykey
( \
%confighash );
1787 foreach my $i ( 0 .. 33 ) { $confighash { $key }[ $i ] = "" ;}
1789 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
1790 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
1791 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
1792 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
1794 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
1795 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1796 $confighash { $key }[ 4 ] = 'psk' ;
1797 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
1799 $confighash { $key }[ 4 ] = 'cert' ;
1801 if ( $cgiparams { 'TYPE' } eq 'net' ) {
1802 my @remote_subnets = split ( "," , $cgiparams { 'REMOTE_SUBNET' });
1803 $confighash { $key }[ 11 ] = join ( '|' , @remote_subnets );
1805 $confighash { $key }[ 7 ] = $cgiparams { 'LOCAL_ID' };
1806 my @local_subnets = split ( "," , $cgiparams { 'LOCAL_SUBNET' });
1807 $confighash { $key }[ 8 ] = join ( '|' , @local_subnets );
1808 $confighash { $key }[ 9 ] = $cgiparams { 'REMOTE_ID' };
1809 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
1810 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
1811 $confighash { $key }[ 26 ] = "" ; # Formerly INTERFACE
1812 $confighash { $key }[ 27 ] = $cgiparams { 'DPD_ACTION' };
1813 $confighash { $key }[ 29 ] = $cgiparams { 'IKE_VERSION' };
1815 # don't forget advanced value
1816 $confighash { $key }[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
1817 $confighash { $key }[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
1818 $confighash { $key }[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
1819 $confighash { $key }[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
1820 $confighash { $key }[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
1821 $confighash { $key }[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
1822 $confighash { $key }[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
1823 $confighash { $key }[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
1824 $confighash { $key }[ 12 ] = 'off' ; # $cgiparams{'AGGRMODE'};
1825 $confighash { $key }[ 13 ] = $cgiparams { 'COMPRESSION' };
1826 $confighash { $key }[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
1827 $confighash { $key }[ 28 ] = $cgiparams { 'PFS' };
1828 $confighash { $key }[ 30 ] = $cgiparams { 'DPD_TIMEOUT' };
1829 $confighash { $key }[ 31 ] = $cgiparams { 'DPD_DELAY' };
1830 $confighash { $key }[ 32 ] = $cgiparams { 'FORCE_MOBIKE' };
1832 # free unused fields!
1833 $confighash { $key }[ 6 ] = 'off' ;
1834 $confighash { $key }[ 15 ] = 'off' ;
1836 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1839 system ( '/usr/local/bin/ipsecctrl' , 'S' , $key );
1842 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
1843 $cgiparams { 'KEY' } = $key ;
1844 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
1847 } else { # add new connection
1848 $cgiparams { 'ENABLED' } = 'on' ;
1849 if ( ! - f
"${General::swroot}/private/cakey.pem" ) {
1850 $cgiparams { 'AUTH' } = 'psk' ;
1851 } elsif ( ! - f
"${General::swroot}/ca/cacert.pem" ) {
1852 $cgiparams { 'AUTH' } = 'certfile' ;
1854 $cgiparams { 'AUTH' } = 'certgen' ;
1856 $cgiparams { 'LOCAL_SUBNET' } = " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" ;
1857 $cgiparams { 'CERT_EMAIL' } = $vpnsettings { 'ROOTCERT_EMAIL' };
1858 $cgiparams { 'CERT_OU' } = $vpnsettings { 'ROOTCERT_OU' };
1859 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
1860 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
1861 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
1862 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
1864 # choose appropriate dpd action
1865 if ( $cgiparams { 'TYPE' } eq 'host' ) {
1866 $cgiparams { 'DPD_ACTION' } = 'clear' ;
1868 $cgiparams { 'DPD_ACTION' } = 'restart' ;
1871 if (! $cgiparams { 'DPD_DELAY' }) {
1872 $cgiparams { 'DPD_DELAY' } = 30 ;
1875 if (! $cgiparams { 'DPD_TIMEOUT' }) {
1876 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
1879 if (! $cgiparams { 'FORCE_MOBIKE' }) {
1880 $cgiparams { 'FORCE_MOBIKE' } = 'no' ;
1883 # Default IKE Version to v2
1884 if (! $cgiparams { 'IKE_VERSION' }) {
1885 $cgiparams { 'IKE_VERSION' } = 'ikev2' ;
1889 $cgiparams { 'LOCAL_ID' } = '' ;
1890 $cgiparams { 'REMOTE_ID' } = '' ;
1892 #use default advanced value
1893 $cgiparams { 'IKE_ENCRYPTION' } = 'aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128' ; #[18];
1894 $cgiparams { 'IKE_INTEGRITY' } = 'sha2_512|sha2_256|sha' ; #[19];
1895 $cgiparams { 'IKE_GROUPTYPE' } = '4096|3072|2048|1536|1024' ; #[20];
1896 $cgiparams { 'IKE_LIFETIME' } = '3' ; #[16];
1897 $cgiparams { 'ESP_ENCRYPTION' } = 'aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128' ; #[21];
1898 $cgiparams { 'ESP_INTEGRITY' } = 'sha2_512|sha2_256|sha1' ; #[22];
1899 $cgiparams { 'ESP_GROUPTYPE' } = '4096|3072|2048|1536|1024' ; #[23];
1900 $cgiparams { 'ESP_KEYLIFE' } = '1' ; #[17];
1901 $cgiparams { 'COMPRESSION' } = 'on' ; #[13];
1902 $cgiparams { 'ONLY_PROPOSED' } = 'off' ; #[24];
1903 $cgiparams { 'PFS' } = 'on' ; #[28];
1907 $checked { 'ENABLED' }{ 'off' } = '' ;
1908 $checked { 'ENABLED' }{ 'on' } = '' ;
1909 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = "checked='checked'" ;
1911 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
1912 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
1913 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = "checked='checked'" ;
1915 $checked { 'AUTH' }{ 'psk' } = '' ;
1916 $checked { 'AUTH' }{ 'certreq' } = '' ;
1917 $checked { 'AUTH' }{ 'certgen' } = '' ;
1918 $checked { 'AUTH' }{ 'certfile' } = '' ;
1919 $checked { 'AUTH' }{ 'pkcs12' } = '' ;
1920 $checked { 'AUTH' }{ 'auth-dn' } = '' ;
1921 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = "checked='checked'" ;
1923 & Header
:: showhttpheaders
();
1924 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1925 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1926 if ( $errormessage ) {
1927 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1928 print "<class name='base'> $errormessage " ;
1929 print " </class>" ;
1930 & Header
:: closebox
();
1934 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'warning messages'}:" );
1935 print "<class name='base'> $warnmessage " ;
1936 print " </class>" ;
1937 & Header
:: closebox
();
1940 print "<form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>" ;
1942 <input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />
1943 <input type='hidden' name='IKE_VERSION' value=' $cgiparams {'IKE_VERSION'}' />
1944 <input type='hidden' name='IKE_ENCRYPTION' value=' $cgiparams {'IKE_ENCRYPTION'}' />
1945 <input type='hidden' name='IKE_INTEGRITY' value=' $cgiparams {'IKE_INTEGRITY'}' />
1946 <input type='hidden' name='IKE_GROUPTYPE' value=' $cgiparams {'IKE_GROUPTYPE'}' />
1947 <input type='hidden' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' />
1948 <input type='hidden' name='ESP_ENCRYPTION' value=' $cgiparams {'ESP_ENCRYPTION'}' />
1949 <input type='hidden' name='ESP_INTEGRITY' value=' $cgiparams {'ESP_INTEGRITY'}' />
1950 <input type='hidden' name='ESP_GROUPTYPE' value=' $cgiparams {'ESP_GROUPTYPE'}' />
1951 <input type='hidden' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' />
1952 <input type='hidden' name='COMPRESSION' value=' $cgiparams {'COMPRESSION'}' />
1953 <input type='hidden' name='ONLY_PROPOSED' value=' $cgiparams {'ONLY_PROPOSED'}' />
1954 <input type='hidden' name='PFS' value=' $cgiparams {'PFS'}' />
1955 <input type='hidden' name='DPD_ACTION' value=' $cgiparams {'DPD_ACTION'}' />
1956 <input type='hidden' name='DPD_DELAY' value=' $cgiparams {'DPD_DELAY'}' />
1957 <input type='hidden' name='DPD_TIMEOUT' value=' $cgiparams {'DPD_TIMEOUT'}' />
1958 <input type='hidden' name='FORCE_MOBIKE' value=' $cgiparams {'FORCE_MOBIKE'}' />
1961 if ( $cgiparams { 'KEY' }) {
1962 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
1963 print "<input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' />" ;
1964 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
1967 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'connection'}: $cgiparams {'NAME'}" );
1968 print "<table width='100%'>" ;
1969 if (! $cgiparams { 'KEY' }) {
1972 <td width='20%'> $Lang ::tr{'name'}: <img src='/blob.gif' alt='*' /></td>
1974 <input type='text' name='NAME' value=' $cgiparams {'NAME'}' size='25' />
1976 <td colspan="2"></td>
1983 if ( $cgiparams { 'TYPE' } eq 'host' ) {
1984 $disabled = "disabled='disabled'" ;
1985 } elsif ( $cgiparams { 'TYPE' } eq 'net' ) {
1986 $blob = "<img src='/blob.gif' alt='*' />" ;
1989 my @local_subnets = split ( /\|/ , $cgiparams { 'LOCAL_SUBNET' });
1990 my $local_subnets = join ( "," , @local_subnets );
1992 my @remote_subnets = split ( /\|/ , $cgiparams { 'REMOTE_SUBNET' });
1993 my $remote_subnets = join ( "," , @remote_subnets );
1997 <td width='20%'> $Lang ::tr{'enabled'}</td>
1999 <input type='checkbox' name='ENABLED' $checked {'ENABLED'}{'on'} />
2001 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'local subnet'} <img src='/blob.gif' alt='*' /></td>
2003 <input type='text' name='LOCAL_SUBNET' value=' $local_subnets ' />
2007 <td class='boldbase' width='20%'> $Lang ::tr{'remote host/ip'}: $blob </td>
2009 <input type='text' name='REMOTE' value=' $cgiparams {'REMOTE'}' size="25" />
2011 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'remote subnet'} $blob </td>
2013 <input $disabled type='text' name='REMOTE_SUBNET' value=' $remote_subnets ' />
2017 <td class='boldbase' width='20%'> $Lang ::tr{'vpn local id'}:</td>
2019 <input type='text' name='LOCAL_ID' value=' $cgiparams {'LOCAL_ID'}' size="25" />
2021 <td class='boldbase' width='20%'> $Lang ::tr{'vpn remote id'}:</td>
2023 <input type='text' name='REMOTE_ID' value=' $cgiparams {'REMOTE_ID'}' size="25" />
2026 <tr><td colspan="4"><br /></td></tr>
2028 <td class='boldbase' width='20%'> $Lang ::tr{'remark title'}</td>
2030 <input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' maxlength='50' size="73" />
2035 if (! $cgiparams { 'KEY' }) {
2036 print "<tr><td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked {'EDIT_ADVANCED'}{'on'} /> $Lang ::tr{'edit advanced settings when done'}</td></tr>" ;
2039 & Header
:: closebox
();
2041 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
2042 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2044 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2045 <tr><td class='base' width='50%'> $Lang ::tr{'use a pre-shared key'}</td>
2046 <td class='base' width='50%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td>
2051 & Header
:: closebox
();
2052 } elsif (! $cgiparams { 'KEY' }) {
2053 my $cakeydisabled = ( ! - f
"${General::swroot}/private/cakey.pem" ) ?
"disabled='disabled'" : '' ;
2054 $cgiparams { 'CERT_NAME' } = $Lang :: tr
{ 'vpn no full pki' } if ( $cakeydisabled );
2055 my $cacrtdisabled = ( ! - f
"${General::swroot}/ca/cacert.pem" ) ?
"disabled='disabled'" : '' ;
2057 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2059 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2060 <tr><td width='5%'><input type='radio' name='AUTH' value='psk' $checked {'AUTH'}{'psk'} /></td>
2061 <td class='base' width='55%'> $Lang ::tr{'use a pre-shared key'}</td>
2062 <td class='base' width='40%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td></tr>
2063 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2064 <tr><td><input type='radio' name='AUTH' value='certreq' $checked {'AUTH'}{'certreq'} $cakeydisabled /></td>
2065 <td class='base'><hr /> $Lang ::tr{'upload a certificate request'}</td>
2066 <td class='base' rowspan='3' valign='middle'><input type='file' name='FH' size='30' $cacrtdisabled /></td></tr>
2067 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td>
2068 <td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
2069 <tr><td><input type='radio' name='AUTH' value='pkcs12' $cacrtdisabled /></td>
2070 <td class='base'> $Lang ::tr{'upload p12 file'} $Lang ::tr{'pkcs12 file password'}:<input type='password' name='P12_PASS'/></td></tr>
2071 <tr><td><input type='radio' name='AUTH' value='auth-dn' $checked {'AUTH'}{'auth-dn'} $cacrtdisabled /></td>
2072 <td class='base'><hr /> $Lang ::tr{'vpn auth-dn'}</td></tr>
2073 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2074 <tr><td><input type='radio' name='AUTH' value='certgen' $checked {'AUTH'}{'certgen'} $cakeydisabled /></td>
2075 <td class='base'><hr /> $Lang ::tr{'generate a certificate'}</td><td> </td></tr>
2077 <td class='base'> $Lang ::tr{'users fullname or system hostname'}: <img src='/blob.gif' alt='*' /></td>
2078 <td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' size='32' $cakeydisabled /></td></tr>
2080 <td class='base'> $Lang ::tr{'users email'}:</td>
2081 <td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' size='32' $cakeydisabled /></td></tr>
2083 <td class='base'> $Lang ::tr{'users department'}:</td>
2084 <td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' size='32' $cakeydisabled /></td></tr>
2086 <td class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
2087 <td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' size='32' $cakeydisabled /></td></tr>
2089 <td class='base'> $Lang ::tr{'city'}:</td>
2090 <td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' size='32' $cakeydisabled /></td></tr>
2092 <td class='base'> $Lang ::tr{'state or province'}:</td>
2093 <td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' size='32' $cakeydisabled /></td></tr>
2095 <td class='base'> $Lang ::tr{'country'}:</td>
2096 <td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
2099 foreach my $country ( sort keys %{ Countries
:: countries
}) {
2100 print " \t\t\t <option value=' $Countries ::countries{ $country }'" ;
2101 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
2102 print " selected='selected'" ;
2104 print "> $country </option> \n " ;
2109 <tr><td> </td><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)</td>
2110 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' $cakeydisabled /></td></tr>
2112 <td class='base'> $Lang ::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' /></td>
2113 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
2114 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'} ( $Lang ::tr{'confirmation'}): <img src='/blob.gif' alt='*' /></td>
2115 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
2119 & Header
:: closebox
();
2122 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
2123 if ( $cgiparams { 'KEY' }) {
2124 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced'}' />" ;
2126 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
2127 & Header
:: closebigbox
();
2128 & Header
:: closepage
();
2135 ### Advanced settings
2137 if (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced' }) ||
2138 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq 'yes' )) {
2139 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
2140 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2141 if (! $confighash { $cgiparams { 'KEY' }}) {
2142 $errormessage = $Lang :: tr
{ 'invalid key' };
2146 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
2147 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2149 $errormessage = $Lang :: tr
{ 'invalid input' };
2150 goto ADVANCED_ERROR
;
2152 foreach my $val ( @temp ) {
2153 if ( $val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|camellia(256|192|128))$/ ) {
2154 $errormessage = $Lang :: tr
{ 'invalid input' };
2155 goto ADVANCED_ERROR
;
2158 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2160 $errormessage = $Lang :: tr
{ 'invalid input' };
2161 goto ADVANCED_ERROR
;
2163 foreach my $val ( @temp ) {
2164 if ( $val !~ /^(sha2_(512|384|256)|sha|md5|aesxcbc)$/ ) {
2165 $errormessage = $Lang :: tr
{ 'invalid input' };
2166 goto ADVANCED_ERROR
;
2169 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2171 $errormessage = $Lang :: tr
{ 'invalid input' };
2172 goto ADVANCED_ERROR
;
2174 foreach my $val ( @temp ) {
2175 if ( $val !~ /^(e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|1024|1536|2048|2048s256|2048s224|2048s160|3072|4096|6144|8192)$/ ) {
2176 $errormessage = $Lang :: tr
{ 'invalid input' };
2177 goto ADVANCED_ERROR
;
2180 if ( $cgiparams { 'IKE_LIFETIME' } !~ /^\d+$/ ) {
2181 $errormessage = $Lang :: tr
{ 'invalid input for ike lifetime' };
2182 goto ADVANCED_ERROR
;
2184 if ( $cgiparams { 'IKE_LIFETIME' } < 1 || $cgiparams { 'IKE_LIFETIME' } > 8 ) {
2185 $errormessage = $Lang :: tr
{ 'ike lifetime should be between 1 and 8 hours' };
2186 goto ADVANCED_ERROR
;
2188 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2190 $errormessage = $Lang :: tr
{ 'invalid input' };
2191 goto ADVANCED_ERROR
;
2193 foreach my $val ( @temp ) {
2194 if ( $val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|camellia(256|192|128))$/ ) {
2195 $errormessage = $Lang :: tr
{ 'invalid input' };
2196 goto ADVANCED_ERROR
;
2199 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2201 $errormessage = $Lang :: tr
{ 'invalid input' };
2202 goto ADVANCED_ERROR
;
2204 foreach my $val ( @temp ) {
2205 if ( $val !~ /^(sha2_(512|384|256)|sha1|md5|aesxcbc)$/ ) {
2206 $errormessage = $Lang :: tr
{ 'invalid input' };
2207 goto ADVANCED_ERROR
;
2210 @temp = split ( '\|' , $cgiparams { 'ESP_GROUPTYPE' });
2212 $errormessage = $Lang :: tr
{ 'invalid input' };
2213 goto ADVANCED_ERROR
;
2215 foreach my $val ( @temp ) {
2216 if ( $val !~ /^(e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|1024|1536|2048|2048s256|2048s224|2048s160|3072|4096|6144|8192|none)$/ ) {
2217 $errormessage = $Lang :: tr
{ 'invalid input' };
2218 goto ADVANCED_ERROR
;
2221 if ( $cgiparams { 'ESP_KEYLIFE' } !~ /^\d+$/ ) {
2222 $errormessage = $Lang :: tr
{ 'invalid input for esp keylife' };
2223 goto ADVANCED_ERROR
;
2225 if ( $cgiparams { 'ESP_KEYLIFE' } < 1 || $cgiparams { 'ESP_KEYLIFE' } > 24 ) {
2226 $errormessage = $Lang :: tr
{ 'esp keylife should be between 1 and 24 hours' };
2227 goto ADVANCED_ERROR
;
2230 if (( $cgiparams { 'COMPRESSION' } !~ /^(|on|off)$/ ) ||
2231 ( $cgiparams { 'FORCE_MOBIKE' } !~ /^(|on|off)$/ ) ||
2232 ( $cgiparams { 'ONLY_PROPOSED' } !~ /^(|on|off)$/ ) ||
2233 ( $cgiparams { 'PFS' } !~ /^(|on|off)$/ )) {
2234 $errormessage = $Lang :: tr
{ 'invalid input' };
2235 goto ADVANCED_ERROR
;
2238 if ( $cgiparams { 'DPD_DELAY' } !~ /^\d+$/ ) {
2239 $errormessage = $Lang :: tr
{ 'invalid input for dpd delay' };
2240 goto ADVANCED_ERROR
;
2243 if ( $cgiparams { 'DPD_TIMEOUT' } !~ /^\d+$/ ) {
2244 $errormessage = $Lang :: tr
{ 'invalid input for dpd timeout' };
2245 goto ADVANCED_ERROR
;
2248 $confighash { $cgiparams { 'KEY' }}[ 29 ] = $cgiparams { 'IKE_VERSION' };
2249 $confighash { $cgiparams { 'KEY' }}[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
2250 $confighash { $cgiparams { 'KEY' }}[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
2251 $confighash { $cgiparams { 'KEY' }}[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
2252 $confighash { $cgiparams { 'KEY' }}[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
2253 $confighash { $cgiparams { 'KEY' }}[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
2254 $confighash { $cgiparams { 'KEY' }}[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
2255 $confighash { $cgiparams { 'KEY' }}[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
2256 $confighash { $cgiparams { 'KEY' }}[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
2257 $confighash { $cgiparams { 'KEY' }}[ 12 ] = 'off' ; #$cgiparams{'AGGRMODE'};
2258 $confighash { $cgiparams { 'KEY' }}[ 13 ] = $cgiparams { 'COMPRESSION' };
2259 $confighash { $cgiparams { 'KEY' }}[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
2260 $confighash { $cgiparams { 'KEY' }}[ 28 ] = $cgiparams { 'PFS' };
2261 $confighash { $cgiparams { 'KEY' }}[ 27 ] = $cgiparams { 'DPD_ACTION' };
2262 $confighash { $cgiparams { 'KEY' }}[ 30 ] = $cgiparams { 'DPD_TIMEOUT' };
2263 $confighash { $cgiparams { 'KEY' }}[ 31 ] = $cgiparams { 'DPD_DELAY' };
2264 $confighash { $cgiparams { 'KEY' }}[ 32 ] = $cgiparams { 'FORCE_MOBIKE' };
2265 $confighash { $cgiparams { 'KEY' }}[ 33 ] = $cgiparams { 'START_ACTION' };
2266 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2269 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
2274 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
2275 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
2276 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
2277 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
2278 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
2279 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
2280 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
2281 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
2282 if ( $cgiparams { 'ESP_GROUPTYPE' } eq "" ) {
2283 $cgiparams { 'ESP_GROUPTYPE' } = $cgiparams { 'IKE_GROUPTYPE' };
2285 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
2286 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
2287 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
2288 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
2289 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
2290 $cgiparams { 'DPD_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
2291 $cgiparams { 'DPD_DELAY' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
2292 $cgiparams { 'FORCE_MOBIKE' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
2293 $cgiparams { 'START_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 33 ];
2295 if (! $cgiparams { 'DPD_DELAY' }) {
2296 $cgiparams { 'DPD_DELAY' } = 30 ;
2299 if (! $cgiparams { 'DPD_TIMEOUT' }) {
2300 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
2303 if (! $cgiparams { 'START_ACTION' }) {
2304 $cgiparams { 'START_ACTION' } = "start" ;
2309 $checked { 'IKE_ENCRYPTION' }{ 'aes256' } = '' ;
2310 $checked { 'IKE_ENCRYPTION' }{ 'aes192' } = '' ;
2311 $checked { 'IKE_ENCRYPTION' }{ 'aes128' } = '' ;
2312 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm128' } = '' ;
2313 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm128' } = '' ;
2314 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm128' } = '' ;
2315 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm96' } = '' ;
2316 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm96' } = '' ;
2317 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm96' } = '' ;
2318 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm64' } = '' ;
2319 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm64' } = '' ;
2320 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm64' } = '' ;
2321 $checked { 'IKE_ENCRYPTION' }{ '3des' } = '' ;
2322 $checked { 'IKE_ENCRYPTION' }{ 'camellia256' } = '' ;
2323 $checked { 'IKE_ENCRYPTION' }{ 'camellia192' } = '' ;
2324 $checked { 'IKE_ENCRYPTION' }{ 'camellia128' } = '' ;
2325 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2326 foreach my $key ( @temp ) { $checked { 'IKE_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2327 $checked { 'IKE_INTEGRITY' }{ 'sha2_512' } = '' ;
2328 $checked { 'IKE_INTEGRITY' }{ 'sha2_384' } = '' ;
2329 $checked { 'IKE_INTEGRITY' }{ 'sha2_256' } = '' ;
2330 $checked { 'IKE_INTEGRITY' }{ 'sha' } = '' ;
2331 $checked { 'IKE_INTEGRITY' }{ 'md5' } = '' ;
2332 $checked { 'IKE_INTEGRITY' }{ 'aesxcbc' } = '' ;
2333 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2334 foreach my $key ( @temp ) { $checked { 'IKE_INTEGRITY' }{ $key } = "selected='selected'" ; }
2335 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2336 $checked { 'IKE_GROUPTYPE' }{ '1024' } = '' ;
2337 $checked { 'IKE_GROUPTYPE' }{ '1536' } = '' ;
2338 $checked { 'IKE_GROUPTYPE' }{ '2048' } = '' ;
2339 $checked { 'IKE_GROUPTYPE' }{ '3072' } = '' ;
2340 $checked { 'IKE_GROUPTYPE' }{ '4096' } = '' ;
2341 $checked { 'IKE_GROUPTYPE' }{ '6144' } = '' ;
2342 $checked { 'IKE_GROUPTYPE' }{ '8192' } = '' ;
2343 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2344 foreach my $key ( @temp ) { $checked { 'IKE_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2346 # 768 is not supported by strongswan
2347 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2349 $checked { 'ESP_ENCRYPTION' }{ 'aes256' } = '' ;
2350 $checked { 'ESP_ENCRYPTION' }{ 'aes192' } = '' ;
2351 $checked { 'ESP_ENCRYPTION' }{ 'aes128' } = '' ;
2352 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm128' } = '' ;
2353 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm128' } = '' ;
2354 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm128' } = '' ;
2355 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm96' } = '' ;
2356 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm96' } = '' ;
2357 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm96' } = '' ;
2358 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm64' } = '' ;
2359 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm64' } = '' ;
2360 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm64' } = '' ;
2361 $checked { 'ESP_ENCRYPTION' }{ '3des' } = '' ;
2362 $checked { 'ESP_ENCRYPTION' }{ 'camellia256' } = '' ;
2363 $checked { 'ESP_ENCRYPTION' }{ 'camellia192' } = '' ;
2364 $checked { 'ESP_ENCRYPTION' }{ 'camellia128' } = '' ;
2365 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2366 foreach my $key ( @temp ) { $checked { 'ESP_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2367 $checked { 'ESP_INTEGRITY' }{ 'sha2_512' } = '' ;
2368 $checked { 'ESP_INTEGRITY' }{ 'sha2_384' } = '' ;
2369 $checked { 'ESP_INTEGRITY' }{ 'sha2_256' } = '' ;
2370 $checked { 'ESP_INTEGRITY' }{ 'sha1' } = '' ;
2371 $checked { 'ESP_INTEGRITY' }{ 'md5' } = '' ;
2372 $checked { 'ESP_INTEGRITY' }{ 'aesxcbc' } = '' ;
2373 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2374 foreach my $key ( @temp ) { $checked { 'ESP_INTEGRITY' }{ $key } = "selected='selected'" ; }
2375 $checked { 'ESP_GROUPTYPE' }{ '768' } = '' ;
2376 $checked { 'ESP_GROUPTYPE' }{ '1024' } = '' ;
2377 $checked { 'ESP_GROUPTYPE' }{ '1536' } = '' ;
2378 $checked { 'ESP_GROUPTYPE' }{ '2048' } = '' ;
2379 $checked { 'ESP_GROUPTYPE' }{ '3072' } = '' ;
2380 $checked { 'ESP_GROUPTYPE' }{ '4096' } = '' ;
2381 $checked { 'ESP_GROUPTYPE' }{ '6144' } = '' ;
2382 $checked { 'ESP_GROUPTYPE' }{ '8192' } = '' ;
2383 $checked { 'ESP_GROUPTYPE' }{ 'none' } = '' ;
2384 @temp = split ( '\|' , $cgiparams { 'ESP_GROUPTYPE' });
2385 foreach my $key ( @temp ) { $checked { 'ESP_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2387 $checked { 'COMPRESSION' } = $cgiparams { 'COMPRESSION' } eq 'on' ?
"checked='checked'" : '' ;
2388 $checked { 'FORCE_MOBIKE' } = $cgiparams { 'FORCE_MOBIKE' } eq 'on' ?
"checked='checked'" : '' ;
2389 $checked { 'ONLY_PROPOSED' } = $cgiparams { 'ONLY_PROPOSED' } eq 'on' ?
"checked='checked'" : '' ;
2390 $checked { 'PFS' } = $cgiparams { 'PFS' } eq 'on' ?
"checked='checked'" : '' ;
2392 $selected { 'IKE_VERSION' }{ 'ikev1' } = '' ;
2393 $selected { 'IKE_VERSION' }{ 'ikev2' } = '' ;
2394 $selected { 'IKE_VERSION' }{ $cgiparams { 'IKE_VERSION' }} = "selected='selected'" ;
2396 $selected { 'DPD_ACTION' }{ 'clear' } = '' ;
2397 $selected { 'DPD_ACTION' }{ 'hold' } = '' ;
2398 $selected { 'DPD_ACTION' }{ 'restart' } = '' ;
2399 $selected { 'DPD_ACTION' }{ 'none' } = '' ;
2400 $selected { 'DPD_ACTION' }{ $cgiparams { 'DPD_ACTION' }} = "selected='selected'" ;
2402 $selected { 'START_ACTION' }{ 'route' } = '' ;
2403 $selected { 'START_ACTION' }{ 'start' } = '' ;
2404 $selected { 'START_ACTION' }{ $cgiparams { 'START_ACTION' }} = "selected='selected'" ;
2406 & Header
:: showhttpheaders
();
2407 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
2408 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2410 if ( $errormessage ) {
2411 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2412 print "<class name='base'> $errormessage " ;
2413 print " </class>" ;
2414 & Header
:: closebox
();
2418 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
2419 print "<class name='base'> $warnmessage " ;
2420 print " </class>" ;
2421 & Header
:: closebox
();
2424 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'advanced'}:" );
2426 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
2427 <input type='hidden' name='ADVANCED' value='yes' />
2428 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
2430 <table width='100%'>
2433 <th width="15%"></th>
2440 <td> $Lang ::tr{'vpn keyexchange'}:</td>
2442 <select name='IKE_VERSION'>
2443 <option value='ikev2' $selected {'IKE_VERSION'}{'ikev2'}>IKEv2</option>
2444 <option value='ikev1' $selected {'IKE_VERSION'}{'ikev1'}>IKEv1</option>
2450 <td class='boldbase' width="15%"> $Lang ::tr{'encryption'}</td>
2451 <td class='boldbase'>
2452 <select name='IKE_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
2453 <option value='aes256gcm128' $checked {'IKE_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
2454 <option value='aes256gcm96' $checked {'IKE_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
2455 <option value='aes256gcm64' $checked {'IKE_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
2456 <option value='aes256' $checked {'IKE_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
2457 <option value='camellia256' $checked {'IKE_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
2458 <option value='aes192gcm128' $checked {'IKE_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
2459 <option value='aes192gcm96' $checked {'IKE_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
2460 <option value='aes192gcm64' $checked {'IKE_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
2461 <option value='aes192' $checked {'IKE_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
2462 <option value='camellia192' $checked {'IKE_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
2463 <option value='aes128gcm128' $checked {'IKE_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
2464 <option value='aes128gcm96' $checked {'IKE_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
2465 <option value='aes128gcm64' $checked {'IKE_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
2466 <option value='aes128' $checked {'IKE_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
2467 <option value='camellia128' $checked {'IKE_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
2468 <option value='3des' $checked {'IKE_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC</option>
2471 <td class='boldbase'>
2472 <select name='ESP_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
2473 <option value='aes256gcm128' $checked {'ESP_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
2474 <option value='aes256gcm96' $checked {'ESP_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
2475 <option value='aes256gcm64' $checked {'ESP_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
2476 <option value='aes256' $checked {'ESP_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
2477 <option value='camellia256' $checked {'ESP_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
2478 <option value='aes192gcm128' $checked {'ESP_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
2479 <option value='aes192gcm96' $checked {'ESP_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
2480 <option value='aes192gcm64' $checked {'ESP_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
2481 <option value='aes192' $checked {'ESP_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
2482 <option value='camellia192' $checked {'ESP_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
2483 <option value='aes128gcm128' $checked {'ESP_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
2484 <option value='aes128gcm96' $checked {'ESP_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
2485 <option value='aes128gcm64' $checked {'ESP_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
2486 <option value='aes128' $checked {'ESP_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
2487 <option value='camellia128' $checked {'ESP_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
2488 <option value='3des' $checked {'ESP_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC</option>
2494 <td class='boldbase' width="15%"> $Lang ::tr{'integrity'}</td>
2495 <td class='boldbase'>
2496 <select name='IKE_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
2497 <option value='sha2_512' $checked {'IKE_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2498 <option value='sha2_384' $checked {'IKE_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2499 <option value='sha2_256' $checked {'IKE_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2500 <option value='aesxcbc' $checked {'IKE_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2501 <option value='sha' $checked {'IKE_INTEGRITY'}{'sha'}>SHA1</option>
2502 <option value='md5' $checked {'IKE_INTEGRITY'}{'md5'}>MD5</option>
2505 <td class='boldbase'>
2506 <select name='ESP_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
2507 <option value='sha2_512' $checked {'ESP_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2508 <option value='sha2_384' $checked {'ESP_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2509 <option value='sha2_256' $checked {'ESP_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2510 <option value='aesxcbc' $checked {'ESP_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2511 <option value='sha1' $checked {'ESP_INTEGRITY'}{'sha1'}>SHA1</option>
2512 <option value='md5' $checked {'ESP_INTEGRITY'}{'md5'}>MD5</option>
2517 <td class='boldbase' width="15%"> $Lang ::tr{'lifetime'} <img src='/blob.gif' alt='*' /></td>
2518 <td class='boldbase'>
2519 <input type='text' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' size='5' /> $Lang ::tr{'hours'}
2521 <td class='boldbase'>
2522 <input type='text' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' size='5' /> $Lang ::tr{'hours'}
2526 <td class='boldbase' width="15%"> $Lang ::tr{'grouptype'}</td>
2527 <td class='boldbase'>
2528 <select name='IKE_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
2529 <option value='e521' $checked {'IKE_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
2530 <option value='e512bp' $checked {'IKE_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
2531 <option value='e384' $checked {'IKE_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
2532 <option value='e384bp' $checked {'IKE_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
2533 <option value='e256' $checked {'IKE_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
2534 <option value='e256bp' $checked {'IKE_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
2535 <option value='e224' $checked {'IKE_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
2536 <option value='e224bp' $checked {'IKE_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
2537 <option value='e192' $checked {'IKE_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
2538 <option value='8192' $checked {'IKE_GROUPTYPE'}{'8192'}>MODP-8192</option>
2539 <option value='6144' $checked {'IKE_GROUPTYPE'}{'6144'}>MODP-6144</option>
2540 <option value='4096' $checked {'IKE_GROUPTYPE'}{'4096'}>MODP-4096</option>
2541 <option value='3072' $checked {'IKE_GROUPTYPE'}{'3072'}>MODP-3072</option>
2542 <option value='2048s256' $checked {'IKE_GROUPTYPE'}{'2048s256'}>MODP-2048/256</option>
2543 <option value='2048s224' $checked {'IKE_GROUPTYPE'}{'2048s224'}>MODP-2048/224</option>
2544 <option value='2048s160' $checked {'IKE_GROUPTYPE'}{'2048s160'}>MODP-2048/160</option>
2545 <option value='2048' $checked {'IKE_GROUPTYPE'}{'2048'}>MODP-2048</option>
2546 <option value='1536' $checked {'IKE_GROUPTYPE'}{'1536'}>MODP-1536</option>
2547 <option value='1024' $checked {'IKE_GROUPTYPE'}{'1024'}>MODP-1024</option>
2550 <td class='boldbase'>
2551 <select name='ESP_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
2552 <option value='e521' $checked {'ESP_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
2553 <option value='e512bp' $checked {'ESP_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
2554 <option value='e384' $checked {'ESP_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
2555 <option value='e384bp' $checked {'ESP_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
2556 <option value='e256' $checked {'ESP_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
2557 <option value='e256bp' $checked {'ESP_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
2558 <option value='e224' $checked {'ESP_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
2559 <option value='e224bp' $checked {'ESP_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
2560 <option value='e192' $checked {'ESP_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
2561 <option value='8192' $checked {'ESP_GROUPTYPE'}{'8192'}>MODP-8192</option>
2562 <option value='6144' $checked {'ESP_GROUPTYPE'}{'6144'}>MODP-6144</option>
2563 <option value='4096' $checked {'ESP_GROUPTYPE'}{'4096'}>MODP-4096</option>
2564 <option value='3072' $checked {'ESP_GROUPTYPE'}{'3072'}>MODP-3072</option>
2565 <option value='2048s256' $checked {'ESP_GROUPTYPE'}{'2048s256'}>MODP-2048/256</option>
2566 <option value='2048s224' $checked {'ESP_GROUPTYPE'}{'2048s224'}>MODP-2048/224</option>
2567 <option value='2048s160' $checked {'ESP_GROUPTYPE'}{'2048s160'}>MODP-2048/160</option>
2568 <option value='2048' $checked {'ESP_GROUPTYPE'}{'2048'}>MODP-2048</option>
2569 <option value='1536' $checked {'ESP_GROUPTYPE'}{'1536'}>MODP-1536</option>
2570 <option value='1024' $checked {'ESP_GROUPTYPE'}{'1024'}>MODP-1024</option>
2571 <option value='none' $checked {'ESP_GROUPTYPE'}{'none'}>- $Lang ::tr{'none'} -</option>
2580 <h2> $Lang ::tr{'dead peer detection'}</h2>
2582 <table width="100%">
2584 <td width="15%"> $Lang ::tr{'dpd action'}:</td>
2586 <select name='DPD_ACTION'>
2587 <option value='none' $selected {'DPD_ACTION'}{'none'}>- $Lang ::tr{'disabled'} -</option>
2588 <option value='clear' $selected {'DPD_ACTION'}{'clear'}>clear</option>
2589 <option value='hold' $selected {'DPD_ACTION'}{'hold'}>hold</option>
2590 <option value='restart' $selected {'DPD_ACTION'}{'restart'}>restart</option>
2595 <td width="15%"> $Lang ::tr{'dpd timeout'}: <img src='/blob.gif' alt='*' /></td>
2597 <input type='text' name='DPD_TIMEOUT' size='5' value=' $cgiparams {'DPD_TIMEOUT'}' />
2601 <td width="15%"> $Lang ::tr{'dpd delay'}: <img src='/blob.gif' alt='*' /></td>
2603 <input type='text' name='DPD_DELAY' size='5' value=' $cgiparams {'DPD_DELAY'}' />
2610 <table width="100%">
2614 <input type='checkbox' name='ONLY_PROPOSED' $checked {'ONLY_PROPOSED'} />
2615 IKE+ESP: $Lang ::tr{'use only proposed settings'}
2619 <label> $Lang ::tr{'vpn start action'}</label>
2620 <select name="START_ACTION">
2621 <option value="route" $selected {'START_ACTION'}{'route'}> $Lang ::tr{'vpn start action route'}</option>
2622 <option value="start" $selected {'START_ACTION'}{'start'}> $Lang ::tr{'vpn start action start'}</option>
2629 <input type='checkbox' name='PFS' $checked {'PFS'} />
2630 $Lang ::tr{'pfs yes no'}
2637 <input type='checkbox' name='COMPRESSION' $checked {'COMPRESSION'} />
2638 $Lang ::tr{'vpn payload compression'}
2645 <input type='checkbox' name='FORCE_MOBIKE' $checked {'FORCE_MOBIKE'} />
2646 $Lang ::tr{'vpn force mobike'}
2651 <td align='left'><img src='/blob.gif' align='top' alt='*' /> $Lang ::tr{'required field'}</td>
2653 <input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />
2654 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' />
2660 & Header
:: closebox
();
2661 & Header
:: closebigbox
();
2662 & Header
:: closepage
();
2669 ### Default status page
2674 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%cgiparams );
2675 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
2676 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2677 $cgiparams { 'CA_NAME' } = '' ;
2679 my @status = `/usr/local/bin/ipsecctrl I 2>/dev/null` ;
2681 # suggest a default name for this side
2682 if ( $cgiparams { 'VPN_IP' } eq '' && - e
"${General::swroot}/red/active" ) {
2683 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
2684 my $ipaddr = < IPADDR
>;
2687 $cgiparams { 'VPN_IP' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
2688 if ( $cgiparams { 'VPN_IP' } eq '' ) {
2689 $cgiparams { 'VPN_IP' } = $ipaddr ;
2693 # no IP found, use %defaultroute
2694 $cgiparams { 'VPN_IP' } = ' %defaultroute ' if ( $cgiparams { 'VPN_IP' } eq '' );
2696 $cgiparams { 'VPN_DELAYED_START' } = 0 if (! defined ( $cgiparams { 'VPN_DELAYED_START' }));
2697 $checked { 'ENABLED' } = $cgiparams { 'ENABLED' } eq 'on' ?
"checked='checked'" : '' ;
2699 & Header
:: showhttpheaders
();
2700 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
2701 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2703 if ( $errormessage ) {
2704 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2705 print "<class name='base'> $errormessage \n " ;
2706 print " </class> \n " ;
2707 & Header
:: closebox
();
2711 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
2712 print " $warnmessage <br>" ;
2713 print " $Lang ::tr{'fwdfw warn1'}<br>" ;
2714 & Header
:: closebox
();
2715 print "<center><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'ok'}' style='width: 5em;'></form>" ;
2716 & Header
:: closepage
();
2720 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'global settings' });
2722 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2723 <table width='100%'>
2725 <td width='20%' class='base' nowrap='nowrap'> $Lang ::tr{'vpn red name'}: <img src='/blob.gif' alt='*' /></td>
2726 <td width='20%'><input type='text' name='VPN_IP' value=' $cgiparams {'VPN_IP'}' /></td>
2727 <td width='20%' class='base'> $Lang ::tr{'enabled'}<input type='checkbox' name='ENABLED' $checked {'ENABLED'} /></td>
2733 <td class='base' nowrap='nowrap'> $Lang ::tr{'vpn delayed start'}: <img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' /></td>
2734 <td ><input type='text' name='VPN_DELAYED_START' value=' $cgiparams {'VPN_DELAYED_START'}' /></td>
2737 <td class='base' nowrap='nowrap'> $Lang ::tr{'host to net vpn'}:</td>
2738 <td ><input type='text' name='RW_NET' value=' $cgiparams {'RW_NET'}' /></td>
2743 <table width='100%'>
2745 <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
2746 <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>
2749 <td class='base' valign='top' nowrap='nowrap'><img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' /> </td>
2750 <td class='base'> <font class='base'> $Lang ::tr{'vpn delayed start help'}</font></td>
2757 & Header
:: closebox
();
2759 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection status and controlc' });
2761 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
2763 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
2764 <th width='22%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></th>
2765 <th width='23%' class='boldbase' align='center'><b> $Lang ::tr{'common name'}</b></th>
2766 <th width='30%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></th>
2767 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></th>
2768 <th class='boldbase' align='center' colspan='6'><b> $Lang ::tr{'action'}</b></th>
2774 foreach my $key ( sort { ncmp
( $confighash { $a }[ 1 ], $confighash { $b }[ 1 ]) } keys %confighash ) {
2775 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
2779 $col = "bgcolor=' $color {'color20'}'" ;
2782 $col = "bgcolor=' $color {'color22'}'" ;
2784 print "<td align='center' nowrap='nowrap' $col > $confighash { $key }[1]</td>" ;
2785 print "<td align='center' nowrap='nowrap' $col >" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ") $confighash { $key }[29]</td>" ;
2786 if ( $confighash { $key }[ 2 ] eq ' %auth -dn' ) {
2787 print "<td align='left' nowrap='nowrap' $col > $confighash { $key }[9]</td>" ;
2788 } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
2789 print "<td align='left' nowrap='nowrap' $col > $confighash { $key }[2]</td>" ;
2791 print "<td align='left' $col > </td>" ;
2793 print "<td align='center' $col > $confighash { $key }[25]</td>" ;
2794 my $col1 = "bgcolor='${Header::colourred}'" ;
2796 my $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
2797 foreach my $line ( @status ) {
2798 if (( $line =~ /\"$confighash{$key}[1]\".*IPsec SA established/ ) ||
2799 ( $line =~ /$confighash{$key}[1]\{.*INSTALLED/ )) {
2800 $col1 = "bgcolor='${Header::colourgreen}'" ;
2801 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b>" ;
2804 # move to blue if really down
2805 if ( $confighash { $key }[ 0 ] eq 'off' && $col1 =~ /${Header::colourred}/ ) {
2806 $col1 = "bgcolor='${Header::colourblue}'" ;
2807 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
2810 <td align='center' $col1 > $active </td>
2811 <td align='center' $col >
2812 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2813 <input type='image' name=' $Lang ::tr{'restart'}' src='/images/reload.gif' alt=' $Lang ::tr{'restart'}' title=' $Lang ::tr{'restart'}' />
2814 <input type='hidden' name='ACTION' value=' $Lang ::tr{'restart'}' />
2815 <input type='hidden' name='KEY' value=' $key ' />
2820 if (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
2822 <td align='center' $col >
2823 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2824 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' />
2825 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
2826 <input type='hidden' name='KEY' value=' $key ' />
2832 print "<td width='2%' $col > </td>" ;
2834 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/certs/ $confighash { $key }[1].p12" ) {
2836 <td align='center' $col >
2837 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2838 <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'}' />
2839 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
2840 <input type='hidden' name='KEY' value=' $key ' />
2845 } elsif (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
2847 <td align='center' $col >
2848 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2849 <input type='image' name=' $Lang ::tr{'download certificate'}' src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' title=' $Lang ::tr{'download certificate'}' />
2850 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
2851 <input type='hidden' name='KEY' value=' $key ' />
2857 print "<td width='2%' $col > </td>" ;
2860 <td align='center' $col >
2861 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2862 <input type='image' name=' $Lang ::tr{'toggle enable disable'}' src='/images/ $gif ' alt=' $Lang ::tr{'toggle enable disable'}' title=' $Lang ::tr{'toggle enable disable'}' />
2863 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
2864 <input type='hidden' name='KEY' value=' $key ' />
2868 <td align='center' $col >
2869 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2870 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
2871 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' title=' $Lang ::tr{'edit'}' />
2872 <input type='hidden' name='KEY' value=' $key ' />
2875 <td align='center' $col >
2876 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2877 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
2878 <input type='image' name=' $Lang ::tr{'remove'}' src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' title=' $Lang ::tr{'remove'}' />
2879 <input type='hidden' name='KEY' value=' $key ' />
2889 # If the config file contains entries, print Key to action icons
2894 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
2895 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
2896 <td class='base'> $Lang ::tr{'click to disable'}</td>
2897 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
2898 <td class='base'> $Lang ::tr{'show certificate'}</td>
2899 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
2900 <td class='base'> $Lang ::tr{'edit'}</td>
2901 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
2902 <td class='base'> $Lang ::tr{'remove'}</td>
2906 <td> <img src='/images/off.gif' alt='?OFF' /></td>
2907 <td class='base'> $Lang ::tr{'click to enable'}</td>
2908 <td> <img src='/images/floppy.gif' alt='?FLOPPY' /></td>
2909 <td class='base'> $Lang ::tr{'download certificate'}</td>
2910 <td> <img src='/images/reload.gif' alt='?RELOAD'/></td>
2911 <td class='base'> $Lang ::tr{'restart'}</td>
2919 <table width='100%'>
2920 <tr><td align='right' colspan='9'>
2921 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2922 <input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />
2928 & Header
:: closebox
();
2930 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'certificate authorities'}" );
2932 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
2934 <th width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
2935 <th width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></th>
2936 <th width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></th>
2940 my $col1 = "bgcolor=' $color {'color22'}'" ;
2941 my $col2 = "bgcolor=' $color {'color20'}'" ;
2942 if (- f
"${General::swroot}/ca/cacert.pem" ) {
2943 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/cacert.pem" ));
2946 <td class='base' $col1 > $Lang ::tr{'root certificate'}</td>
2947 <td class='base' $col1 > $casubject </td>
2948 <td width='3%' align='center' $col1 >
2949 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2950 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
2951 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/info.gif' alt=' $Lang ::tr{'show root certificate'}' title=' $Lang ::tr{'show root certificate'}' />
2954 <td width='3%' align='center' $col1 >
2955 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2956 <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'}' />
2957 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
2960 <td width='4%' $col1 > </td></tr>
2964 # display rootcert generation buttons
2967 <td class='base' $col1 > $Lang ::tr{'root certificate'}:</td>
2968 <td class='base' $col1 > $Lang ::tr{'not present'}</td>
2969 <td colspan='3' $col1 > </td></tr>
2974 if (- f
"${General::swroot}/certs/hostcert.pem" ) {
2975 my $hostsubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/certs/hostcert.pem" ));
2979 <td class='base' $col2 > $Lang ::tr{'host certificate'}</td>
2980 <td class='base' $col2 > $hostsubject </td>
2981 <td width='3%' align='center' $col2 >
2982 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2983 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
2984 <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'}' />
2987 <td width='3%' align='center' $col2 >
2988 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2989 <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'}" />
2990 <input type='hidden' name='ACTION' value=" $Lang ::tr{'download host certificate'}" />
2993 <td width='4%' $col2 > </td></tr>
3000 <td width='25%' class='base' $col2 > $Lang ::tr{'host certificate'}:</td>
3001 <td class='base' $col2 > $Lang ::tr{'not present'}</td>
3002 <td colspan='3' $col2 > </td></tr>
3008 if ( keys %cahash > 0 ) {
3009 foreach my $key ( keys %cahash ) {
3010 if ( $rowcolor ++ % 2 ) {
3012 $col = "bgcolor=' $color {'color20'}'" ;
3015 $col = "bgcolor=' $color {'color22'}'" ;
3017 print "<td class='base' $col > $cahash { $key }[0]</td> \n " ;
3018 print "<td class='base' $col > $cahash { $key }[1]</td> \n " ;
3020 <td align='center' $col >
3021 <form method='post' name='cafrm${key}a' action=' $ENV {'SCRIPT_NAME'}'>
3022 <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'}' />
3023 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
3024 <input type='hidden' name='KEY' value=' $key ' />
3027 <td align='center' $col >
3028 <form method='post' name='cafrm${key}b' action=' $ENV {'SCRIPT_NAME'}'>
3029 <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'}' />
3030 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
3031 <input type='hidden' name='KEY' value=' $key ' />
3034 <td align='center' $col >
3035 <form method='post' name='cafrm${key}c' action=' $ENV {'SCRIPT_NAME'}'>
3036 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
3037 <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'}' />
3038 <input type='hidden' name='KEY' value=' $key ' />
3048 # If the file contains entries, print Key to action icons
3049 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
3052 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
3053 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
3054 <td class='base'> $Lang ::tr{'show certificate'}</td>
3055 <td> <img src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' /></td>
3056 <td class='base'> $Lang ::tr{'download certificate'}</td>
3061 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>" ;
3065 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
3066 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
3069 <td class='base' nowrap='nowrap'> $Lang ::tr{'ca name'}: <img src='/blob.gif' alt='*' /></td>
3070 <td nowrap='nowrap'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' /> </td>
3071 <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td>
3072 <td nowrap='nowrap'><input type='submit' name='ACTION' value=' $Lang ::tr{'upload ca certificate'}' /></td>
3075 <td colspan='3'> $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}:</td>
3076 <td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' /></td>
3082 & Header
:: closebox
();
3083 & Header
:: closebigbox
();
3084 & Header
:: closepage
();
3086 sub array_unique
($) {
3091 foreach my $e ( @
$array ) {
3092 next if $seen { $e }++;
3099 sub make_algos
($$$$$) {
3100 my ( $mode , $encs , $ints , $grps , $pfs ) = @_ ;
3103 foreach my $enc ( @
$encs ) {
3104 foreach my $int ( @
$ints ) {
3105 foreach my $grp ( @
$grps ) {
3108 if ( $mode eq "ike" ) {
3111 if ( $grp =~ m/^e(.*)$/ ) {
3112 push ( @algo , "ecp $1 " );
3114 push ( @algo , "modp $grp " );
3117 } elsif ( $mode eq "esp" && $pfs ) {
3118 my $is_aead = ( $enc =~ m/[cg]cm/ );
3124 if ( $grp eq "none" ) {
3126 } elsif ( $grp =~ m/^e(.*)$/ ) {
3127 push ( @algo , "ecp $1 " );
3129 push ( @algo , "modp $grp " );
3133 push ( @algos , join ( "-" , @algo ));
3138 return & array_unique
( \
@algos );
3141 sub make_subnets
($) {
3142 my $subnets = shift ;
3144 my @nets = split ( /\|/ , $subnets );
3146 foreach my $net ( @nets ) {
3147 my $cidr_net = & General
:: ipcidr
( $net );
3148 push ( @cidr_nets , $cidr_net );
3151 return join ( "," , @cidr_nets );