]>
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 & Header
:: getcgihash
( \
%cgiparams , { 'wantfile' => 1 , 'filevar' => 'FH' });
117 my $hostname = $_ [ 0 ];
118 unless ( $hostname ) { return "No hostname" };
119 my $res = new Net
:: DNS
:: Resolver
;
120 my $query = $res -> search ( " $hostname " );
122 foreach my $rr ( $query -> answer ) {
123 ## Potential bug - we are only looking at A records:
124 return 0 if $rr -> type eq "A" ;
127 return $res -> errorstring ;
131 ### Just return true is one interface is vpn enabled
134 return ( $vpnsettings { 'ENABLED' } eq 'on' );
137 ### old version: maintain serial number to one, without explication.
138 ### this: let the counter go, so that each cert is numbered.
140 sub cleanssldatabase
{
141 if ( open ( FILE
, ">${General::swroot}/certs/serial" )) {
145 if ( open ( FILE
, ">${General::swroot}/certs/index.txt" )) {
149 unlink ( "${General::swroot}/certs/index.txt.old" );
150 unlink ( "${General::swroot}/certs/serial.old" );
151 unlink ( "${General::swroot}/certs/01.pem" );
153 sub newcleanssldatabase
{
154 if (! - s
"${General::swroot}/certs/serial" ) {
155 open ( FILE
, ">${General::swroot}/certs/serial" );
159 if (! - s
">${General::swroot}/certs/index.txt" ) {
160 system ( "touch ${General::swroot}/certs/index.txt" );
162 unlink ( "${General::swroot}/certs/index.txt.old" );
163 unlink ( "${General::swroot}/certs/serial.old" );
164 # unlink ("${General::swroot}/certs/01.pem"); numbering evolves. Wrong place to delete
168 ### Call openssl and return errormessage if any
172 my $retssl = `/usr/bin/openssl $opt 2>&1` ; #redirect stderr
174 foreach my $line ( split ( /\n/ , $retssl )) {
175 & General
:: log ( "ipsec" , " $line " ) if ( 0 ); # 1 for verbose logging
176 $ret .= '<br>' . $line if ( $line =~ /error|unknown/ );
179 $ret = & Header
:: cleanhtml
( $ret );
181 return $ret ?
" $Lang ::tr{'openssl produced an error'}: $ret " : '' ;
184 ### Obtain a CN from given cert
186 sub getCNfromcert
($) {
187 #&General::log("ipsec", "Extracting name from $_[0]...");
188 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
189 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
191 $temp =~ s
+/ Email
+, E
+;
192 $temp =~ s/ ST=/ S=/ ;
198 ### Obtain Subject from given cert
200 sub getsubjectfromcert
($) {
201 #&General::log("ipsec", "Extracting subject from $_[0]...");
202 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
203 $temp =~ /Subject: (.*)[\n]/ ;
205 $temp =~ s
+/ Email
+, E
+;
206 $temp =~ s/ ST=/ S=/ ;
210 ### Combine local subnet and connection name to make a unique name for each connection section
211 ### (this sub is not used now)
213 sub makeconnname
($) {
217 $subnet =~ /^(.*?)\/ (.* ?
)$/; # $1=IP $2=mask
218 my $ip = unpack ( 'N' , & Socket
:: inet_aton
( $1 ));
219 if ( length ( $2 ) > 2 ) {
220 my $mm = unpack ( 'N' , & Socket
:: inet_aton
( $2 ));
221 while ( ( $mm & 1 )== 0 ) {
228 return sprintf ( " %s - %X " , $conn , $ip );
231 ### Write a config file.
233 ###Type=Host : GUI can choose the interface used (RED,GREEN,BLUE) and
234 ### the side is always defined as 'left'.
237 sub writeipsecfiles
{
238 my %lconfighash = ();
239 my %lvpnsettings = ();
240 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%lconfighash );
241 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%lvpnsettings );
243 open ( CONF
, ">${General::swroot}/vpn/ipsec.conf" ) or die "Unable to open ${General::swroot}/vpn/ipsec.conf: $!" ;
244 open ( SECRETS
, ">${General::swroot}/vpn/ipsec.secrets" ) or die "Unable to open ${General::swroot}/vpn/ipsec.secrets: $!" ;
247 print CONF
"version 2 \n\n " ;
248 print CONF
"conn %default \n " ;
249 print CONF
" \t keyingtries= %forever \n " ;
252 # Add user includes to config file
253 if (- e
"/etc/ipsec.user.conf" ) {
254 print CONF
"include /etc/ipsec.user.conf \n " ;
258 print SECRETS
"include /etc/ipsec.user.secrets \n " ;
260 if (- f
"${General::swroot}/certs/hostkey.pem" ) {
261 print SECRETS
": RSA ${General::swroot}/certs/hostkey.pem \n "
263 my $last_secrets = '' ; # old the less specifics connections
265 foreach my $key ( keys %lconfighash ) {
266 next if ( $lconfighash { $key }[ 0 ] ne 'on' );
268 #remote peer is not set? => use '%any'
269 $lconfighash { $key }[ 10 ] = ' %any ' if ( $lconfighash { $key }[ 10 ] eq '' );
272 if ( $lconfighash { $key }[ 26 ] eq 'BLUE' ) {
273 $localside = $netsettings { 'BLUE_ADDRESS' };
274 } elsif ( $lconfighash { $key }[ 26 ] eq 'GREEN' ) {
275 $localside = $netsettings { 'GREEN_ADDRESS' };
276 } elsif ( $lconfighash { $key }[ 26 ] eq 'ORANGE' ) {
277 $localside = $netsettings { 'ORANGE_ADDRESS' };
279 $localside = $lvpnsettings { 'VPN_IP' };
282 print CONF
"conn $lconfighash { $key }[1] \n " ;
283 print CONF
" \t left= $localside \n " ;
284 print CONF
" \t leftsubnet=" . & make_subnets
( $lconfighash { $key }[ 8 ]) . " \n " ;
285 print CONF
" \t leftfirewall=yes \n " ;
286 print CONF
" \t lefthostaccess=yes \n " ;
287 print CONF
" \t right= $lconfighash { $key }[10] \n " ;
289 if ( $lconfighash { $key }[ 3 ] eq 'net' ) {
290 print CONF
" \t rightsubnet=" . & make_subnets
( $lconfighash { $key }[ 11 ]) . " \n " ;
293 # Local Cert and Remote Cert (unless auth is DN dn-auth)
294 if ( $lconfighash { $key }[ 4 ] eq 'cert' ) {
295 print CONF
" \t leftcert=${General::swroot}/certs/hostcert.pem \n " ;
296 print CONF
" \t rightcert=${General::swroot}/certs/ $lconfighash { $key }[1]cert.pem \n " if ( $lconfighash { $key }[ 2 ] ne ' %auth -dn' );
299 # Local and Remote IDs
300 print CONF
" \t leftid= \" $lconfighash { $key }[7] \"\n " if ( $lconfighash { $key }[ 7 ]);
301 print CONF
" \t rightid= \" $lconfighash { $key }[9] \"\n " if ( $lconfighash { $key }[ 9 ]);
304 my $pfs = $lconfighash { $key }[ 28 ] eq 'on' ?
'on' : 'off' ;
307 if ( $lconfighash { $key }[ 18 ] && $lconfighash { $key }[ 19 ] && $lconfighash { $key }[ 20 ]) {
308 my @encs = split ( '\|' , $lconfighash { $key }[ 18 ]);
309 my @ints = split ( '\|' , $lconfighash { $key }[ 19 ]);
310 my @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
312 my @algos = & make_algos
( "ike" , \
@encs , \
@ints , \
@groups , 1 );
313 print CONF
" \t ike=" . join ( "," , @algos );
315 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
322 if ( $lconfighash { $key }[ 21 ] && $lconfighash { $key }[ 22 ]) {
323 my @encs = split ( '\|' , $lconfighash { $key }[ 21 ]);
324 my @ints = split ( '\|' , $lconfighash { $key }[ 22 ]);
325 my @groups = split ( '\|' , $lconfighash { $key }[ 23 ]);
327 # Use IKE grouptype if no ESP group type has been selected
328 # (for backwards compatibility)
329 if ( $lconfighash { $key }[ 23 ] eq "" ) {
330 @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
333 my @algos = & make_algos
( "esp" , \
@encs , \
@ints , \
@groups , ( $pfs eq "on" ));
334 print CONF
" \t esp=" . join ( "," , @algos );
336 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
344 if (! $lconfighash { $key }[ 29 ]) {
345 $lconfighash { $key }[ 29 ] = "ikev1" ;
348 print CONF
" \t keyexchange= $lconfighash { $key }[29] \n " ;
351 print CONF
" \t ikelifetime= $lconfighash { $key }[16]h \n " if ( $lconfighash { $key }[ 16 ]);
352 print CONF
" \t keylife= $lconfighash { $key }[17]h \n " if ( $lconfighash { $key }[ 17 ]);
355 print CONF
" \t compress=yes \n " if ( $lconfighash { $key }[ 13 ] eq 'on' );
358 if (( $lconfighash { $key }[ 29 ] eq "ikev2" ) && ( $lconfighash { $key }[ 32 ] eq 'on' )) {
359 print CONF
" \t mobike=yes \n " ;
362 # Dead Peer Detection
363 my $dpdaction = $lconfighash { $key }[ 27 ];
364 print CONF
" \t dpdaction= $dpdaction \n " ;
366 # If the dead peer detection is disabled and IKEv2 is used,
367 # dpddelay must be set to zero, too.
368 if ( $dpdaction eq "none" ) {
369 if ( $lconfighash { $key }[ 29 ] eq "ikev2" ) {
370 print CONF
" \t dpddelay=0 \n " ;
373 my $dpddelay = $lconfighash { $key }[ 31 ];
377 print CONF
" \t dpddelay= $dpddelay \n " ;
378 my $dpdtimeout = $lconfighash { $key }[ 30 ];
382 print CONF
" \t dpdtimeout= $dpdtimeout \n " ;
385 # Build Authentication details: LEFTid RIGHTid : PSK psk
387 if ( $lconfighash { $key }[ 4 ] eq 'psk' ) {
388 $psk_line = ( $lconfighash { $key }[ 7 ] ?
$lconfighash { $key }[ 7 ] : $localside ) . " " ;
389 $psk_line .= $lconfighash { $key }[ 9 ] ?
$lconfighash { $key }[ 9 ] : $lconfighash { $key }[ 10 ]; #remoteid or remote address?
390 $psk_line .= " : PSK ' $lconfighash { $key }[5]' \n " ;
391 # if the line contains %any, it is less specific than two IP or ID, so move it at end of file.
392 if ( $psk_line =~ /%any/ ) {
393 $last_secrets .= $psk_line ;
395 print SECRETS
$psk_line ;
397 print CONF
" \t authby=secret \n " ;
399 print CONF
" \t authby=rsasig \n " ;
400 print CONF
" \t leftrsasigkey= %cert \n " ;
401 print CONF
" \t rightrsasigkey= %cert \n " ;
404 # Automatically start only if a net-to-net connection
405 if ( $lconfighash { $key }[ 3 ] eq 'host' ) {
406 print CONF
" \t auto=add \n " ;
407 print CONF
" \t rightsourceip= $lvpnsettings {'RW_NET'} \n " ;
409 print CONF
" \t auto=start \n " ;
413 print CONF
" \t fragmentation=yes \n " ;
418 # Add post user includes to config file
419 # After the GUI-connections allows to patch connections.
420 if (- e
"/etc/ipsec.user-post.conf" ) {
421 print CONF
"include /etc/ipsec.user-post.conf \n " ;
425 print SECRETS
$last_secrets if ( $last_secrets );
430 # Hook to regenerate the configuration files.
431 if ( $ENV { "REMOTE_ADDR" } eq "" ) {
437 ### Save main settings
439 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
440 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
442 unless (& General
:: validfqdn
( $cgiparams { 'VPN_IP' }) || & General
:: validip
( $cgiparams { 'VPN_IP' })
443 || $cgiparams { 'VPN_IP' } eq ' %defaultroute ' ) {
444 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
448 unless ( $cgiparams { 'VPN_DELAYED_START' } =~ /^[0-9]{1,3}$/ ) { #allow 0-999 seconds !
449 $errormessage = $Lang :: tr
{ 'invalid time period' };
453 if ( $cgiparams { 'RW_NET' } ne '' and !& General
:: validipandmask
( $cgiparams { 'RW_NET' }) ) {
454 $errormessage = $Lang :: tr
{ 'urlfilter invalid ip or mask error' };
458 $vpnsettings { 'ENABLED' } = $cgiparams { 'ENABLED' };
459 $vpnsettings { 'VPN_IP' } = $cgiparams { 'VPN_IP' };
460 $vpnsettings { 'VPN_DELAYED_START' } = $cgiparams { 'VPN_DELAYED_START' };
461 $vpnsettings { 'RW_NET' } = $cgiparams { 'RW_NET' };
462 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
465 system ( '/usr/local/bin/ipsecctrl' , 'S' );
467 system ( '/usr/local/bin/ipsecctrl' , 'D' );
474 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
475 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
477 foreach my $key ( keys %confighash ) {
478 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
479 delete $confighash { $key };
482 while ( my $file = glob ( "${General::swroot}/{ca,certs,crls,private}/*" )) {
486 if ( open ( FILE
, ">${General::swroot}/vpn/caconfig" )) {
490 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
492 system ( '/usr/local/bin/ipsecctrl' , 'R' );
498 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' }) {
499 & Header
:: showhttpheaders
();
500 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
501 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
502 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
504 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
508 <input type='hidden' name='AREUSURE' value='yes' />
509 <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'}
513 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' />
514 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
521 & Header
:: closebigbox
();
522 & Header
:: closepage
();
526 ### Upload CA Certificate
528 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
529 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
531 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
532 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
536 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
537 $errormessage = $Lang :: tr
{ 'name too long' };
541 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
542 $errormessage = $Lang :: tr
{ 'name is invalid' };
543 goto UPLOAD_CA_ERROR
;
546 # Check if there is no other entry with this name
547 foreach my $key ( keys %cahash ) {
548 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
549 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
554 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
555 $errormessage = $Lang :: tr
{ 'there was no file upload' };
558 # Move uploaded ca to a temporary file
559 ( my $fh , my $filename ) = tempfile
( );
560 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
564 my $temp = `/usr/bin/openssl x509 -text -in $filename ` ;
565 if ( $temp !~ /CA:TRUE/i ) {
566 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
570 move
( $filename , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
572 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
578 my $key = & General
:: findhasharraykey
( \
%cahash );
579 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
580 $cahash { $key }[ 1 ] = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" ));
581 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
583 system ( '/usr/local/bin/ipsecctrl' , 'R' );
589 ### Display ca certificate
591 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
592 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
594 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
595 & Header
:: showhttpheaders
();
596 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
597 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
598 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'ca certificate'}:" );
599 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
600 $output = & Header
:: cleanhtml
( $output , "y" );
601 print "<pre> $output </pre> \n " ;
603 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
604 & Header
:: closebigbox
();
605 & Header
:: closepage
();
608 $errormessage = $Lang :: tr
{ 'invalid key' };
612 ### Export ca certificate to browser
614 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
615 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
617 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
618 print "Content-Type: application/force-download \n " ;
619 print "Content-Type: application/octet-stream \r\n " ;
620 print "Content-Disposition: attachment; filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
621 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
624 $errormessage = $Lang :: tr
{ 'invalid key' };
628 ### Remove ca certificate (step 2)
630 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
631 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
632 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
634 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
635 foreach my $key ( keys %confighash ) {
636 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
637 if ( $test =~ /: OK/ ) {
639 system ( '/usr/local/bin/ipsecctrl' , 'D' , $key ) if (& vpnenabled
);
640 unlink ( "${General::swroot}/certs/ $confighash { $key }[1]cert.pem" );
641 unlink ( "${General::swroot}/certs/ $confighash { $key }[1].p12" );
642 delete $confighash { $key };
643 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
647 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
648 delete $cahash { $cgiparams { 'KEY' }};
649 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
650 system ( '/usr/local/bin/ipsecctrl' , 'R' );
653 $errormessage = $Lang :: tr
{ 'invalid key' };
656 ### Remove ca certificate (step 1)
658 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
659 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
660 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
662 my $assignedcerts = 0 ;
663 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
664 foreach my $key ( keys %confighash ) {
665 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
666 if ( $test =~ /: OK/ ) {
670 if ( $assignedcerts ) {
671 & Header
:: showhttpheaders
();
672 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
673 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
674 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
676 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
680 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
681 <input type='hidden' name='AREUSURE' value='yes' /></td>
684 <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>
687 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
688 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
695 & Header
:: closebigbox
();
696 & Header
:: closepage
();
699 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
700 delete $cahash { $cgiparams { 'KEY' }};
701 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
702 system ( '/usr/local/bin/ipsecctrl' , 'R' );
706 $errormessage = $Lang :: tr
{ 'invalid key' };
710 ### Display root certificate
712 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
713 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
715 & Header
:: showhttpheaders
();
716 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
717 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
718 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
719 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'root certificate'}:" );
720 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/cacert.pem` ;
722 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'host certificate'}:" );
723 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/hostcert.pem` ;
725 $output = & Header
:: cleanhtml
( $output , "y" );
726 print "<pre> $output </pre> \n " ;
728 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
729 & Header
:: closebigbox
();
730 & Header
:: closepage
();
734 ### Export root certificate to browser
736 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
737 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
738 print "Content-Type: application/force-download \n " ;
739 print "Content-Disposition: attachment; filename=cacert.pem \r\n\r\n " ;
740 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/cacert.pem` ;
744 ### Export host certificate to browser
746 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
747 if ( - f
"${General::swroot}/certs/hostcert.pem" ) {
748 print "Content-Type: application/force-download \n " ;
749 print "Content-Disposition: attachment; filename=hostcert.pem \r\n\r\n " ;
750 print `/usr/bin/openssl x509 -in ${General::swroot}/certs/hostcert.pem` ;
754 ### Form for generating/importing the caroot+host certificate
756 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
757 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
759 if (- f
"${General::swroot}/ca/cacert.pem" ) {
760 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
764 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
765 # fill in initial values
766 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
767 if (- e
"${General::swroot}/red/active" && open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
768 my $ipaddr = < IPADDR
>;
771 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
772 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
773 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
776 $cgiparams { 'ROOTCERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' } if (! $cgiparams { 'ROOTCERT_COUNTRY' });
777 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
778 & General
:: log ( "ipsec" , "Importing from p12..." );
780 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
781 $errormessage = $Lang :: tr
{ 'there was no file upload' };
785 # Move uploaded certificate request to a temporary file
786 ( my $fh , my $filename ) = tempfile
( );
787 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
792 # Extract the CA certificate from the file
793 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
794 if ( open ( STDIN
, "-|" )) {
795 my $opt = " pkcs12 -cacerts -nokeys" ;
796 $opt .= " -in $filename " ;
797 $opt .= " -out /tmp/newcacert" ;
798 $errormessage = & callssl
( $opt );
800 print " $cgiparams {'P12_PASS'} \n " ;
804 # Extract the Host certificate from the file
805 if (! $errormessage ) {
806 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
807 if ( open ( STDIN
, "-|" )) {
808 my $opt = " pkcs12 -clcerts -nokeys" ;
809 $opt .= " -in $filename " ;
810 $opt .= " -out /tmp/newhostcert" ;
811 $errormessage = & callssl
( $opt );
813 print " $cgiparams {'P12_PASS'} \n " ;
818 # Extract the Host key from the file
819 if (! $errormessage ) {
820 & General
:: log ( "ipsec" , "Extracting private key from p12..." );
821 if ( open ( STDIN
, "-|" )) {
822 my $opt = " pkcs12 -nocerts -nodes" ;
823 $opt .= " -in $filename " ;
824 $opt .= " -out /tmp/newhostkey" ;
825 $errormessage = & callssl
( $opt );
827 print " $cgiparams {'P12_PASS'} \n " ;
832 if (! $errormessage ) {
833 & General
:: log ( "ipsec" , "Moving cacert..." );
834 move
( "/tmp/newcacert" , "${General::swroot}/ca/cacert.pem" );
835 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
838 if (! $errormessage ) {
839 & General
:: log ( "ipsec" , "Moving host cert..." );
840 move
( "/tmp/newhostcert" , "${General::swroot}/certs/hostcert.pem" );
841 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
844 if (! $errormessage ) {
845 & General
:: log ( "ipsec" , "Moving private key..." );
846 move
( "/tmp/newhostkey" , "${General::swroot}/certs/hostkey.pem" );
847 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
852 unlink ( '/tmp/newcacert' );
853 unlink ( '/tmp/newhostcert' );
854 unlink ( '/tmp/newhostkey' );
856 unlink ( "${General::swroot}/ca/cacert.pem" );
857 unlink ( "${General::swroot}/certs/hostcert.pem" );
858 unlink ( "${General::swroot}/certs/hostkey.pem" );
862 # Create empty CRL cannot be done because we don't have
863 # the private key for this CAROOT
864 # IPFire can only import certificates
866 & General
:: log ( "ipsec" , "p12 import completed!" );
868 goto ROOTCERT_SUCCESS
;
870 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
872 # Validate input since the form was submitted
873 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
874 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
877 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
878 $errormessage = $Lang :: tr
{ 'organization too long' };
881 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
882 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
885 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
886 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
889 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
890 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
893 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
894 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
897 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
898 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
901 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
902 $errormessage = $Lang :: tr
{ 'invalid input for department' };
905 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
906 $errormessage = $Lang :: tr
{ 'invalid input for city' };
909 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
910 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
913 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
914 $errormessage = $Lang :: tr
{ 'invalid input for country' };
917 #the exact syntax is a list comma separated of
918 # email:any-validemail
919 # URI: a uniform resource indicator
920 # DNS: a DNS domain name
921 # RID: a registered OBJECT IDENTIFIER
923 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
925 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
926 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
930 # Copy the cgisettings to vpnsettings and save the configfile
931 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
932 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
933 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
934 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
935 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
936 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
937 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
938 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
940 # Replace empty strings with a .
941 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
942 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
943 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
945 # Create the CA certificate
946 if (! $errormessage ) {
947 & General
:: log ( "ipsec" , "Creating cacert..." );
948 if ( open ( STDIN
, "-|" )) {
949 my $opt = " req -x509 -sha256 -nodes" ;
950 $opt .= " -days 999999" ;
951 $opt .= " -newkey rsa:4096" ;
952 $opt .= " -keyout ${General::swroot}/private/cakey.pem" ;
953 $opt .= " -out ${General::swroot}/ca/cacert.pem" ;
955 $errormessage = & callssl
( $opt );
957 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
960 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
962 print " $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
963 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
968 # Create the Host certificate request
969 if (! $errormessage ) {
970 & General
:: log ( "ipsec" , "Creating host cert..." );
971 if ( open ( STDIN
, "-|" )) {
972 my $opt = " req -sha256 -nodes" ;
973 $opt .= " -newkey rsa:2048" ;
974 $opt .= " -keyout ${General::swroot}/certs/hostkey.pem" ;
975 $opt .= " -out ${General::swroot}/certs/hostreq.pem" ;
976 $errormessage = & callssl
( $opt );
978 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
981 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
983 print " $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
984 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
991 # Sign the host certificate request
992 if (! $errormessage ) {
993 & General
:: log ( "ipsec" , "Self signing host cert..." );
995 #No easy way for specifying the contain of subjectAltName without writing a config file...
996 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
998 basicConstraints=CA:FALSE
999 nsComment="OpenSSL Generated Certificate"
1000 subjectKeyIdentifier=hash
1001 authorityKeyIdentifier=keyid,issuer:always
1002 extendedKeyUsage = serverAuth
1005 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1008 my $opt = " ca -md sha256 -days 999999" ;
1009 $opt .= " -batch -notext" ;
1010 $opt .= " -in ${General::swroot}/certs/hostreq.pem" ;
1011 $opt .= " -out ${General::swroot}/certs/hostcert.pem" ;
1012 $opt .= " -extfile $v3extname " ;
1013 $errormessage = & callssl
( $opt );
1014 unlink ( "${General::swroot}/certs/hostreq.pem" ); #no more needed
1015 unlink ( $v3extname );
1018 # Create an empty CRL
1019 if (! $errormessage ) {
1020 & General
:: log ( "ipsec" , "Creating emptycrl..." );
1021 my $opt = " ca -gencrl" ;
1022 $opt .= " -out ${General::swroot}/crls/cacrl.pem" ;
1023 $errormessage = & callssl
( $opt );
1026 # Successfully build CA / CERT!
1027 if (! $errormessage ) {
1028 & cleanssldatabase
();
1029 goto ROOTCERT_SUCCESS
;
1033 unlink ( "${General::swroot}/ca/cacert.pem" );
1034 unlink ( "${General::swroot}/certs/hostkey.pem" );
1035 unlink ( "${General::swroot}/certs/hostcert.pem" );
1036 unlink ( "${General::swroot}/crls/cacrl.pem" );
1037 & cleanssldatabase
();
1041 & Header
:: showhttpheaders
();
1042 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1043 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1044 if ( $errormessage ) {
1045 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1046 print "<class name='base'> $errormessage " ;
1047 print " </class>" ;
1048 & Header
:: closebox
();
1050 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
1052 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
1053 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1054 <tr><td width='40%' class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
1055 <td width='60%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td></tr>
1056 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}: <img src='/blob.gif' alt='*' /></td>
1057 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td></tr>
1058 <tr><td class='base'> $Lang ::tr{'your e-mail'}:</td>
1059 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td></tr>
1060 <tr><td class='base'> $Lang ::tr{'your department'}:</td>
1061 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td></tr>
1062 <tr><td class='base'> $Lang ::tr{'city'}:</td>
1063 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td></tr>
1064 <tr><td class='base'> $Lang ::tr{'state or province'}:</td>
1065 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td></tr>
1066 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1067 <td class='base'><select name='ROOTCERT_COUNTRY'>
1070 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1071 print "<option value=' $Countries ::countries{ $country }'" ;
1072 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1073 print " selected='selected'" ;
1075 print "> $country </option>" ;
1079 <tr><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)</td>
1080 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' /></td></tr>
1082 <td><br /><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /><br /><br /></td></tr>
1083 <tr><td class='base' colspan='2' align='left'>
1084 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1085 $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'}
1087 <tr><td colspan='2'><hr></td></tr>
1088 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}:</td>
1089 <td nowrap='nowrap'><input type='file' name='FH' size='32' /></td></tr>
1090 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
1091 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td></tr>
1093 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td></tr>
1094 <tr><td class='base' colspan='2' align='left'>
1095 <img src='/blob.gif' alt='*' /> $Lang ::tr{'required field'}</td></tr>
1099 & Header
:: closebox
();
1100 & Header
:: closebigbox
();
1101 & Header
:: closepage
();
1106 system ( '/usr/local/bin/ipsecctrl' , 'S' );
1111 ### Export PKCS12 file to browser
1113 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
1114 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1115 print "Content-Type: application/force-download \n " ;
1116 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
1117 print "Content-Type: application/octet-stream \r\n\r\n " ;
1118 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12` ;
1122 ### Display certificate
1124 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
1125 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1127 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1128 & Header
:: showhttpheaders
();
1129 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1130 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1131 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'cert'}:" );
1132 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1133 $output = & Header
:: cleanhtml
( $output , "y" );
1134 print "<pre> $output </pre> \n " ;
1135 & Header
:: closebox
();
1136 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1137 & Header
:: closebigbox
();
1138 & Header
:: closepage
();
1143 ### Export Certificate to browser
1145 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
1146 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1148 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1149 print "Content-Type: application/force-download \n " ;
1150 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \n\n " ;
1151 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1156 ### Enable/Disable connection
1158 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1160 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1161 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1163 if ( $confighash { $cgiparams { 'KEY' }}) {
1164 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
1165 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
1166 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1168 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1170 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1171 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
1172 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1177 $errormessage = $Lang :: tr
{ 'invalid key' };
1181 ### Restart connection
1183 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
1184 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1185 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1187 if ( $confighash { $cgiparams { 'KEY' }}) {
1189 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
1193 $errormessage = $Lang :: tr
{ 'invalid key' };
1197 ### Remove connection
1199 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
1200 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1201 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1203 if ( $confighash { $cgiparams { 'KEY' }}) {
1204 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1205 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1206 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1207 delete $confighash { $cgiparams { 'KEY' }};
1208 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1211 $errormessage = $Lang :: tr
{ 'invalid key' };
1213 & General
:: firewall_reload
();
1215 ### Choose between adding a host-net or net-net connection
1217 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
1218 & Header
:: showhttpheaders
();
1219 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1220 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1221 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection type' });
1223 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
1224 <b> $Lang ::tr{'connection type'}:</b><br />
1226 <tr><td><input type='radio' name='TYPE' value='host' checked='checked' /></td>
1227 <td class='base'> $Lang ::tr{'host to net vpn'}</td>
1229 <td><input type='radio' name='TYPE' value='net' /></td>
1230 <td class='base'> $Lang ::tr{'net to net vpn'}</td>
1232 <td align='center' colspan='2'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td>
1237 & Header
:: closebox
();
1238 & Header
:: closebigbox
();
1239 & Header
:: closepage
();
1242 ### Adding/Editing/Saving a connection
1244 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
1245 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
1246 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
1248 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1249 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1250 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1252 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
1253 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
1254 $errormessage = $Lang :: tr
{ 'invalid key' };
1257 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
1258 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
1259 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
1260 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
1261 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
1262 #$cgiparams{'free'} = $confighash{$cgiparams{'KEY'}}[6];
1263 $cgiparams { 'LOCAL_ID' } = $confighash { $cgiparams { 'KEY' }}[ 7 ];
1264 my @local_subnets = split ( "," , $confighash { $cgiparams { 'KEY' }}[ 8 ]);
1265 $cgiparams { 'LOCAL_SUBNET' } = join ( /\|/ , @local_subnets );
1266 $cgiparams { 'REMOTE_ID' } = $confighash { $cgiparams { 'KEY' }}[ 9 ];
1267 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
1268 my @remote_subnets = split ( "," , $confighash { $cgiparams { 'KEY' }}[ 11 ]);
1269 $cgiparams { 'REMOTE_SUBNET' } = join ( /\|/ , @remote_subnets );
1270 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
1271 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
1272 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
1273 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
1274 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
1275 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
1276 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
1277 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
1278 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
1279 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
1280 if ( $cgiparams { 'ESP_GROUPTYPE' } eq "" ) {
1281 $cgiparams { 'ESP_GROUPTYPE' } = $cgiparams { 'IKE_GROUPTYPE' };
1283 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
1284 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
1285 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
1286 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
1287 $cgiparams { 'DPD_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
1288 $cgiparams { 'DPD_DELAY' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
1289 $cgiparams { 'FORCE_MOBIKE' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
1291 if (! $cgiparams { 'DPD_DELAY' }) {
1292 $cgiparams { 'DPD_DELAY' } = 30 ;
1295 if (! $cgiparams { 'DPD_TIMEOUT' }) {
1296 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
1299 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
1300 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
1301 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
1302 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
1306 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
1307 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
1311 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
1312 $errormessage = $Lang :: tr
{ 'name is invalid' };
1316 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
1317 $errormessage = $Lang :: tr
{ 'name too long' };
1321 # Check if there is no other entry with this name
1322 if (! $cgiparams { 'KEY' }) { #only for add
1323 foreach my $key ( keys %confighash ) {
1324 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
1325 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
1331 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! $cgiparams { 'REMOTE' })) {
1332 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1336 if ( $cgiparams { 'REMOTE' }) {
1337 if (( $cgiparams { 'REMOTE' } ne ' %any ' ) && (! & General
:: validip
( $cgiparams { 'REMOTE' }))) {
1338 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
1339 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1342 if (& valid_dns_host
( $cgiparams { 'REMOTE' })) {
1343 $warnmessage = " $Lang ::tr{'check vpn lr'} $cgiparams {'REMOTE'}. $Lang ::tr{'dns check failed'}" ;
1349 my @local_subnets = split ( "," , $cgiparams { 'LOCAL_SUBNET' });
1350 foreach my $subnet ( @local_subnets ) {
1351 unless (& Network
:: check_subnet
( $subnet )) {
1352 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
1357 # Allow only one roadwarrior/psk without remote IP-address
1358 if ( $cgiparams { 'REMOTE' } eq '' && $cgiparams { 'AUTH' } eq 'psk' ) {
1359 foreach my $key ( keys %confighash ) {
1360 if ( ( $cgiparams { 'KEY' } ne $key ) &&
1361 ( $confighash { $key }[ 4 ] eq 'psk' ) &&
1362 ( $confighash { $key }[ 10 ] eq '' ) ) {
1363 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
1369 if ( $cgiparams { 'TYPE' } eq 'net' ) {
1370 my @remote_subnets = split ( "," , $cgiparams { 'REMOTE_SUBNET' });
1371 foreach my $subnet ( @remote_subnets ) {
1372 unless (& Network
:: check_subnet
( $subnet )) {
1373 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
1379 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
1380 $errormessage = $Lang :: tr
{ 'invalid input' };
1383 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
1384 $errormessage = $Lang :: tr
{ 'invalid input' };
1388 # Allow nothing or a string (DN,FDQN,) beginning with @
1389 # with no comma but slashes between RID eg @O=FR/C=Paris/OU=myhome/CN=franck
1390 if ( ( $cgiparams { 'LOCAL_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1391 ( $cgiparams { 'REMOTE_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1392 (( $cgiparams { 'REMOTE_ID' } eq $cgiparams { 'LOCAL_ID' }) && ( $cgiparams { 'LOCAL_ID' } ne '' ))
1394 $errormessage = $Lang :: tr
{ 'invalid local-remote id' } . '<br />' .
1395 'DER_ASN1_DN: @c =FR/ou=Paris/ou=Home/cn=*<br />' .
1396 'FQDN: @ipfire .org<br />' .
1397 'USER_FQDN: info @ipfire .org<br />' .
1398 'IPV4_ADDR: 123.123.123.123' ;
1401 # If Auth is DN, verify existance of Remote ID.
1402 if ( $cgiparams { 'REMOTE_ID' } eq '' && (
1403 $cgiparams { 'AUTH' } eq 'auth-dn' || # while creation
1404 $confighash { $cgiparams { 'KEY' }}[ 2 ] eq ' %auth -dn' )){ # while editing
1405 $errormessage = $Lang :: tr
{ 'vpn missing remote id' };
1409 if ( $cgiparams { 'TYPE' } eq 'net' ){
1410 $warnmessage =& General
:: checksubnets
( '' , $cgiparams { 'REMOTE_SUBNET' }, 'ipsec' );
1411 if ( $warnmessage ne '' ){
1412 $warnmessage = $Lang :: tr
{ 'remote subnet' }. " ( $cgiparams {'REMOTE_SUBNET'}) <br>" . $warnmessage ;
1416 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1417 if (! length ( $cgiparams { 'PSK' }) ) {
1418 $errormessage = $Lang :: tr
{ 'pre-shared key is too short' };
1421 if ( $cgiparams { 'PSK' } =~ /'/ ) {
1422 $cgiparams { 'PSK' } =~ tr/'/ / ;
1423 $errormessage = $Lang :: tr
{ 'invalid characters found in pre-shared key' };
1426 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
1427 if ( $cgiparams { 'KEY' }) {
1428 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1431 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1432 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1436 # Move uploaded certificate request to a temporary file
1437 ( my $fh , my $filename ) = tempfile
( );
1438 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1443 # Sign the certificate request
1444 & General
:: log ( "ipsec" , "Signing your cert $cgiparams {'NAME'}..." );
1445 my $opt = " ca -md sha256 -days 999999" ;
1446 $opt .= " -batch -notext" ;
1447 $opt .= " -in $filename " ;
1448 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1450 if ( $errormessage = & callssl
( $opt ) ) {
1452 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1453 & cleanssldatabase
();
1457 & cleanssldatabase
();
1460 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1461 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1462 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1465 } elsif ( $cgiparams { 'AUTH' } eq 'pkcs12' ) {
1466 & General
:: log ( "ipsec" , "Importing from p12..." );
1468 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1469 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1470 goto ROOTCERT_ERROR
;
1473 # Move uploaded certificate request to a temporary file
1474 ( my $fh , my $filename ) = tempfile
( );
1475 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1477 goto ROOTCERT_ERROR
;
1480 # Extract the CA certificate from the file
1481 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
1482 if ( open ( STDIN
, "-|" )) {
1483 my $opt = " pkcs12 -cacerts -nokeys" ;
1484 $opt .= " -in $filename " ;
1485 $opt .= " -out /tmp/newcacert" ;
1486 $errormessage = & callssl
( $opt );
1488 print " $cgiparams {'P12_PASS'} \n " ;
1492 # Extract the Host certificate from the file
1493 if (! $errormessage ) {
1494 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
1495 if ( open ( STDIN
, "-|" )) {
1496 my $opt = " pkcs12 -clcerts -nokeys" ;
1497 $opt .= " -in $filename " ;
1498 $opt .= " -out /tmp/newhostcert" ;
1499 $errormessage = & callssl
( $opt );
1501 print " $cgiparams {'P12_PASS'} \n " ;
1506 if (! $errormessage ) {
1507 & General
:: log ( "ipsec" , "Moving cacert..." );
1508 #If CA have new subject, add it to our list of CA
1509 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( '/tmp/newcacert' ));
1511 foreach my $x ( keys %cahash ) {
1512 $casubject = '' if ( $cahash { $x }[ 1 ] eq $casubject );
1513 unshift ( @names , $cahash { $x }[ 0 ]);
1515 if ( $casubject ) { # a new one!
1516 my $temp = `/usr/bin/openssl x509 -text -in /tmp/newcacert` ;
1517 if ( $temp !~ /CA:TRUE/i ) {
1518 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
1520 #compute a name for it
1522 while ( grep ( /Imported-$idx/ , @names ) ) { $idx ++};
1523 $cgiparams { 'CA_NAME' }= "Imported- $idx " ;
1524 $cgiparams { 'CERT_NAME' }=& Header
:: cleanhtml
( getCNfromcert
( '/tmp/newhostcert' ));
1525 move
( "/tmp/newcacert" , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1526 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1527 if (! $errormessage ) {
1528 my $key = & General
:: findhasharraykey
( \
%cahash );
1529 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
1530 $cahash { $key }[ 1 ] = $casubject ;
1531 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1532 system ( '/usr/local/bin/ipsecctrl' , 'R' );
1537 if (! $errormessage ) {
1538 & General
:: log ( "ipsec" , "Moving host cert..." );
1539 move
( "/tmp/newhostcert" , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1540 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1545 unlink ( '/tmp/newcacert' );
1546 unlink ( '/tmp/newhostcert' );
1547 if ( $errormessage ) {
1548 unlink ( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1549 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1552 & General
:: log ( "ipsec" , "p12 import completed!" );
1553 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
1554 if ( $cgiparams { 'KEY' }) {
1555 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1558 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1559 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1562 # Move uploaded certificate to a temporary file
1563 ( my $fh , my $filename ) = tempfile
( );
1564 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1569 # Verify the certificate has a valid CA and move it
1570 & General
:: log ( "ipsec" , "Validating imported cert against our known CA..." );
1571 my $validca = 1 ; #assume ok
1572 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/cacert.pem $filename ` ;
1573 if ( $test !~ /: OK/ ) {
1575 foreach my $key ( keys %cahash ) {
1576 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $key }[0]cert.pem $filename ` ;
1577 if ( $test =~ /: OK/ ) {
1584 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
1588 move
( $filename , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1590 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1596 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1597 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1598 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1599 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1602 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
1603 if ( $cgiparams { 'KEY' }) {
1604 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1607 # Validate input since the form was submitted
1608 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
1609 $errormessage = $Lang :: tr
{ 'name too long' };
1612 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1613 $errormessage = $Lang :: tr
{ 'invalid input for name' };
1616 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
1617 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1620 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
1621 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1624 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1625 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1628 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
1629 $errormessage = $Lang :: tr
{ 'organization too long' };
1632 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1633 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1636 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1637 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1640 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1641 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1644 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1645 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1648 #the exact syntax is a list comma separated of
1649 # email:any-validemail
1650 # URI: a uniform resource indicator
1651 # DNS: a DNS domain name
1652 # RID: a registered OBJECT IDENTIFIER
1654 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
1656 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
1657 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
1661 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
1662 $errormessage = $Lang :: tr
{ 'password too short' };
1665 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
1666 $errormessage = $Lang :: tr
{ 'passwords do not match' };
1670 # Replace empty strings with a .
1671 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
1672 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
1673 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
1675 # Create the Client certificate request
1676 & General
:: log ( "ipsec" , "Creating a cert..." );
1678 if ( open ( STDIN
, "-|" )) {
1679 my $opt = " req -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
1680 $opt .= " -newkey rsa:2048" ;
1681 $opt .= " -keyout ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1682 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1684 if ( $errormessage = & callssl
( $opt ) ) {
1685 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1686 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1690 print " $cgiparams {'CERT_COUNTRY'} \n " ;
1693 print " $cgiparams {'CERT_ORGANIZATION'} \n " ;
1695 print " $cgiparams {'CERT_NAME'} \n " ;
1696 print " $cgiparams {'CERT_EMAIL'} \n " ;
1702 # Sign the client certificate request
1703 & General
:: log ( "ipsec" , "Signing the cert $cgiparams {'NAME'}..." );
1705 #No easy way for specifying the contain of subjectAltName without writing a config file...
1706 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1708 basicConstraints=CA:FALSE
1709 nsComment="OpenSSL Generated Certificate"
1710 subjectKeyIdentifier=hash
1711 extendedKeyUsage=clientAuth
1712 authorityKeyIdentifier=keyid,issuer:always
1715 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1718 my $opt = " ca -md sha256 -days 999999 -batch -notext" ;
1719 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1720 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1721 $opt .= " -extfile $v3extname " ;
1723 if ( $errormessage = & callssl
( $opt ) ) {
1724 unlink ( $v3extname );
1725 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1726 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1727 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1728 & cleanssldatabase
();
1731 unlink ( $v3extname );
1732 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1733 & cleanssldatabase
();
1736 # Create the pkcs12 file
1737 & General
:: log ( "ipsec" , "Packing a pkcs12 file..." );
1738 $opt = " pkcs12 -export" ;
1739 $opt .= " -inkey ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1740 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1741 $opt .= " -name \" $cgiparams {'NAME'} \" " ;
1742 $opt .= " -passout pass: $cgiparams {'CERT_PASS1'}" ;
1743 $opt .= " -certfile ${General::swroot}/ca/cacert.pem" ;
1744 $opt .= " -caname \" $vpnsettings {'ROOTCERT_ORGANIZATION'} CA \" " ;
1745 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}.p12" ;
1747 if ( $errormessage = & callssl
( $opt ) ) {
1748 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1749 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1750 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}.p12" );
1753 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1755 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
1756 ; # Nothing, just editing
1757 } elsif ( $cgiparams { 'AUTH' } eq 'auth-dn' ) {
1758 $cgiparams { 'CERT_NAME' } = ' %auth -dn' ; # a special value saying 'no cert file'
1760 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
1764 # 1)Error message here is not accurate.
1765 # 2)Test is superfluous, openswan can reference same cert multiple times
1766 # 3)Present since initial version (1.3.2.11), it isn't a bug correction
1767 # Check if there is no other entry with this certificate name
1768 #if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk') && ($cgiparams{'AUTH'} ne 'auth-dn')) {
1769 # foreach my $key (keys %confighash) {
1770 # if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) {
1771 # $errormessage = $Lang::tr{'a connection with this common name already exists'};
1772 # goto VPNCONF_ERROR;
1778 my $key = $cgiparams { 'KEY' };
1780 $key = & General
:: findhasharraykey
( \
%confighash );
1781 foreach my $i ( 0 .. 32 ) { $confighash { $key }[ $i ] = "" ;}
1783 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
1784 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
1785 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
1786 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
1788 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
1789 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1790 $confighash { $key }[ 4 ] = 'psk' ;
1791 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
1793 $confighash { $key }[ 4 ] = 'cert' ;
1795 if ( $cgiparams { 'TYPE' } eq 'net' ) {
1796 my @remote_subnets = split ( "," , $cgiparams { 'REMOTE_SUBNET' });
1797 $confighash { $key }[ 11 ] = join ( '|' , @remote_subnets );
1799 $confighash { $key }[ 7 ] = $cgiparams { 'LOCAL_ID' };
1800 my @local_subnets = split ( "," , $cgiparams { 'LOCAL_SUBNET' });
1801 $confighash { $key }[ 8 ] = join ( '|' , @local_subnets );
1802 $confighash { $key }[ 9 ] = $cgiparams { 'REMOTE_ID' };
1803 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
1804 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
1805 $confighash { $key }[ 26 ] = "" ; # Formerly INTERFACE
1806 $confighash { $key }[ 27 ] = $cgiparams { 'DPD_ACTION' };
1807 $confighash { $key }[ 29 ] = $cgiparams { 'IKE_VERSION' };
1809 # don't forget advanced value
1810 $confighash { $key }[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
1811 $confighash { $key }[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
1812 $confighash { $key }[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
1813 $confighash { $key }[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
1814 $confighash { $key }[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
1815 $confighash { $key }[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
1816 $confighash { $key }[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
1817 $confighash { $key }[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
1818 $confighash { $key }[ 12 ] = 'off' ; # $cgiparams{'AGGRMODE'};
1819 $confighash { $key }[ 13 ] = $cgiparams { 'COMPRESSION' };
1820 $confighash { $key }[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
1821 $confighash { $key }[ 28 ] = $cgiparams { 'PFS' };
1822 $confighash { $key }[ 30 ] = $cgiparams { 'DPD_TIMEOUT' };
1823 $confighash { $key }[ 31 ] = $cgiparams { 'DPD_DELAY' };
1824 $confighash { $key }[ 32 ] = $cgiparams { 'FORCE_MOBIKE' };
1826 # free unused fields!
1827 $confighash { $key }[ 6 ] = 'off' ;
1828 $confighash { $key }[ 15 ] = 'off' ;
1830 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1833 system ( '/usr/local/bin/ipsecctrl' , 'S' , $key );
1836 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
1837 $cgiparams { 'KEY' } = $key ;
1838 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
1841 } else { # add new connection
1842 $cgiparams { 'ENABLED' } = 'on' ;
1843 if ( ! - f
"${General::swroot}/private/cakey.pem" ) {
1844 $cgiparams { 'AUTH' } = 'psk' ;
1845 } elsif ( ! - f
"${General::swroot}/ca/cacert.pem" ) {
1846 $cgiparams { 'AUTH' } = 'certfile' ;
1848 $cgiparams { 'AUTH' } = 'certgen' ;
1850 $cgiparams { 'LOCAL_SUBNET' } = " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" ;
1851 $cgiparams { 'CERT_EMAIL' } = $vpnsettings { 'ROOTCERT_EMAIL' };
1852 $cgiparams { 'CERT_OU' } = $vpnsettings { 'ROOTCERT_OU' };
1853 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
1854 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
1855 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
1856 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
1858 # choose appropriate dpd action
1859 if ( $cgiparams { 'TYPE' } eq 'host' ) {
1860 $cgiparams { 'DPD_ACTION' } = 'clear' ;
1862 $cgiparams { 'DPD_ACTION' } = 'restart' ;
1865 if (! $cgiparams { 'DPD_DELAY' }) {
1866 $cgiparams { 'DPD_DELAY' } = 30 ;
1869 if (! $cgiparams { 'DPD_TIMEOUT' }) {
1870 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
1873 if (! $cgiparams { 'FORCE_MOBIKE' }) {
1874 $cgiparams { 'FORCE_MOBIKE' } = 'no' ;
1877 # Default IKE Version to v2
1878 if (! $cgiparams { 'IKE_VERSION' }) {
1879 $cgiparams { 'IKE_VERSION' } = 'ikev2' ;
1883 $cgiparams { 'LOCAL_ID' } = '' ;
1884 $cgiparams { 'REMOTE_ID' } = '' ;
1886 #use default advanced value
1887 $cgiparams { 'IKE_ENCRYPTION' } = 'aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128' ; #[18];
1888 $cgiparams { 'IKE_INTEGRITY' } = 'sha2_512|sha2_256|sha' ; #[19];
1889 $cgiparams { 'IKE_GROUPTYPE' } = '4096|3072|2048|1536|1024' ; #[20];
1890 $cgiparams { 'IKE_LIFETIME' } = '3' ; #[16];
1891 $cgiparams { 'ESP_ENCRYPTION' } = 'aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128' ; #[21];
1892 $cgiparams { 'ESP_INTEGRITY' } = 'sha2_512|sha2_256|sha1' ; #[22];
1893 $cgiparams { 'ESP_GROUPTYPE' } = '4096|3072|2048|1536|1024' ; #[23];
1894 $cgiparams { 'ESP_KEYLIFE' } = '1' ; #[17];
1895 $cgiparams { 'COMPRESSION' } = 'on' ; #[13];
1896 $cgiparams { 'ONLY_PROPOSED' } = 'off' ; #[24];
1897 $cgiparams { 'PFS' } = 'on' ; #[28];
1901 $checked { 'ENABLED' }{ 'off' } = '' ;
1902 $checked { 'ENABLED' }{ 'on' } = '' ;
1903 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = "checked='checked'" ;
1905 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
1906 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
1907 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = "checked='checked'" ;
1909 $checked { 'AUTH' }{ 'psk' } = '' ;
1910 $checked { 'AUTH' }{ 'certreq' } = '' ;
1911 $checked { 'AUTH' }{ 'certgen' } = '' ;
1912 $checked { 'AUTH' }{ 'certfile' } = '' ;
1913 $checked { 'AUTH' }{ 'pkcs12' } = '' ;
1914 $checked { 'AUTH' }{ 'auth-dn' } = '' ;
1915 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = "checked='checked'" ;
1917 & Header
:: showhttpheaders
();
1918 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1919 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1920 if ( $errormessage ) {
1921 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1922 print "<class name='base'> $errormessage " ;
1923 print " </class>" ;
1924 & Header
:: closebox
();
1928 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'warning messages'}:" );
1929 print "<class name='base'> $warnmessage " ;
1930 print " </class>" ;
1931 & Header
:: closebox
();
1934 print "<form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>" ;
1936 <input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />
1937 <input type='hidden' name='IKE_VERSION' value=' $cgiparams {'IKE_VERSION'}' />
1938 <input type='hidden' name='IKE_ENCRYPTION' value=' $cgiparams {'IKE_ENCRYPTION'}' />
1939 <input type='hidden' name='IKE_INTEGRITY' value=' $cgiparams {'IKE_INTEGRITY'}' />
1940 <input type='hidden' name='IKE_GROUPTYPE' value=' $cgiparams {'IKE_GROUPTYPE'}' />
1941 <input type='hidden' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' />
1942 <input type='hidden' name='ESP_ENCRYPTION' value=' $cgiparams {'ESP_ENCRYPTION'}' />
1943 <input type='hidden' name='ESP_INTEGRITY' value=' $cgiparams {'ESP_INTEGRITY'}' />
1944 <input type='hidden' name='ESP_GROUPTYPE' value=' $cgiparams {'ESP_GROUPTYPE'}' />
1945 <input type='hidden' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' />
1946 <input type='hidden' name='COMPRESSION' value=' $cgiparams {'COMPRESSION'}' />
1947 <input type='hidden' name='ONLY_PROPOSED' value=' $cgiparams {'ONLY_PROPOSED'}' />
1948 <input type='hidden' name='PFS' value=' $cgiparams {'PFS'}' />
1949 <input type='hidden' name='DPD_ACTION' value=' $cgiparams {'DPD_ACTION'}' />
1950 <input type='hidden' name='DPD_DELAY' value=' $cgiparams {'DPD_DELAY'}' />
1951 <input type='hidden' name='DPD_TIMEOUT' value=' $cgiparams {'DPD_TIMEOUT'}' />
1952 <input type='hidden' name='FORCE_MOBIKE' value=' $cgiparams {'FORCE_MOBIKE'}' />
1955 if ( $cgiparams { 'KEY' }) {
1956 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
1957 print "<input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' />" ;
1958 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
1961 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'connection'}: $cgiparams {'NAME'}" );
1962 print "<table width='100%'>" ;
1963 if (! $cgiparams { 'KEY' }) {
1966 <td width='20%'> $Lang ::tr{'name'}: <img src='/blob.gif' alt='*' /></td>
1968 <input type='text' name='NAME' value=' $cgiparams {'NAME'}' size='25' />
1970 <td colspan="2"></td>
1977 if ( $cgiparams { 'TYPE' } eq 'host' ) {
1978 $disabled = "disabled='disabled'" ;
1979 } elsif ( $cgiparams { 'TYPE' } eq 'net' ) {
1980 $blob = "<img src='/blob.gif' alt='*' />" ;
1983 my @local_subnets = split ( /\|/ , $cgiparams { 'LOCAL_SUBNET' });
1984 my $local_subnets = join ( "," , @local_subnets );
1986 my @remote_subnets = split ( /\|/ , $cgiparams { 'REMOTE_SUBNET' });
1987 my $remote_subnets = join ( "," , @remote_subnets );
1991 <td width='20%'> $Lang ::tr{'enabled'}</td>
1993 <input type='checkbox' name='ENABLED' $checked {'ENABLED'}{'on'} />
1995 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'local subnet'} <img src='/blob.gif' alt='*' /></td>
1997 <input type='text' name='LOCAL_SUBNET' value=' $local_subnets ' />
2001 <td class='boldbase' width='20%'> $Lang ::tr{'remote host/ip'}: $blob </td>
2003 <input type='text' name='REMOTE' value=' $cgiparams {'REMOTE'}' size="25" />
2005 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'remote subnet'} $blob </td>
2007 <input $disabled type='text' name='REMOTE_SUBNET' value=' $remote_subnets ' />
2011 <td class='boldbase' width='20%'> $Lang ::tr{'vpn local id'}:</td>
2013 <input type='text' name='LOCAL_ID' value=' $cgiparams {'LOCAL_ID'}' size="25" />
2015 <td class='boldbase' width='20%'> $Lang ::tr{'vpn remote id'}:</td>
2017 <input type='text' name='REMOTE_ID' value=' $cgiparams {'REMOTE_ID'}' size="25" />
2020 <tr><td colspan="4"><br /></td></tr>
2022 <td class='boldbase' width='20%'> $Lang ::tr{'remark title'}</td>
2024 <input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' maxlength='50' size="73" />
2029 if (! $cgiparams { 'KEY' }) {
2030 print "<tr><td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked {'EDIT_ADVANCED'}{'on'} /> $Lang ::tr{'edit advanced settings when done'}</td></tr>" ;
2033 & Header
:: closebox
();
2035 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
2036 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2038 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2039 <tr><td class='base' width='50%'> $Lang ::tr{'use a pre-shared key'}</td>
2040 <td class='base' width='50%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td>
2045 & Header
:: closebox
();
2046 } elsif (! $cgiparams { 'KEY' }) {
2047 my $cakeydisabled = ( ! - f
"${General::swroot}/private/cakey.pem" ) ?
"disabled='disabled'" : '' ;
2048 $cgiparams { 'CERT_NAME' } = $Lang :: tr
{ 'vpn no full pki' } if ( $cakeydisabled );
2049 my $cacrtdisabled = ( ! - f
"${General::swroot}/ca/cacert.pem" ) ?
"disabled='disabled'" : '' ;
2051 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2053 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2054 <tr><td width='5%'><input type='radio' name='AUTH' value='psk' $checked {'AUTH'}{'psk'} /></td>
2055 <td class='base' width='55%'> $Lang ::tr{'use a pre-shared key'}</td>
2056 <td class='base' width='40%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td></tr>
2057 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2058 <tr><td><input type='radio' name='AUTH' value='certreq' $checked {'AUTH'}{'certreq'} $cakeydisabled /></td>
2059 <td class='base'><hr /> $Lang ::tr{'upload a certificate request'}</td>
2060 <td class='base' rowspan='3' valign='middle'><input type='file' name='FH' size='30' $cacrtdisabled /></td></tr>
2061 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td>
2062 <td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
2063 <tr><td><input type='radio' name='AUTH' value='pkcs12' $cacrtdisabled /></td>
2064 <td class='base'> $Lang ::tr{'upload p12 file'} $Lang ::tr{'pkcs12 file password'}:<input type='password' name='P12_PASS'/></td></tr>
2065 <tr><td><input type='radio' name='AUTH' value='auth-dn' $checked {'AUTH'}{'auth-dn'} $cacrtdisabled /></td>
2066 <td class='base'><hr /> $Lang ::tr{'vpn auth-dn'}</td></tr>
2067 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2068 <tr><td><input type='radio' name='AUTH' value='certgen' $checked {'AUTH'}{'certgen'} $cakeydisabled /></td>
2069 <td class='base'><hr /> $Lang ::tr{'generate a certificate'}</td><td> </td></tr>
2071 <td class='base'> $Lang ::tr{'users fullname or system hostname'}: <img src='/blob.gif' alt='*' /></td>
2072 <td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' size='32' $cakeydisabled /></td></tr>
2074 <td class='base'> $Lang ::tr{'users email'}:</td>
2075 <td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' size='32' $cakeydisabled /></td></tr>
2077 <td class='base'> $Lang ::tr{'users department'}:</td>
2078 <td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' size='32' $cakeydisabled /></td></tr>
2080 <td class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
2081 <td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' size='32' $cakeydisabled /></td></tr>
2083 <td class='base'> $Lang ::tr{'city'}:</td>
2084 <td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' size='32' $cakeydisabled /></td></tr>
2086 <td class='base'> $Lang ::tr{'state or province'}:</td>
2087 <td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' size='32' $cakeydisabled /></td></tr>
2089 <td class='base'> $Lang ::tr{'country'}:</td>
2090 <td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
2093 foreach my $country ( sort keys %{ Countries
:: countries
}) {
2094 print " \t\t\t <option value=' $Countries ::countries{ $country }'" ;
2095 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
2096 print " selected='selected'" ;
2098 print "> $country </option> \n " ;
2103 <tr><td> </td><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)</td>
2104 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' $cakeydisabled /></td></tr>
2106 <td class='base'> $Lang ::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' /></td>
2107 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
2108 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'} ( $Lang ::tr{'confirmation'}): <img src='/blob.gif' alt='*' /></td>
2109 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
2113 & Header
:: closebox
();
2116 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
2117 if ( $cgiparams { 'KEY' }) {
2118 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced'}' />" ;
2120 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
2121 & Header
:: closebigbox
();
2122 & Header
:: closepage
();
2129 ### Advanced settings
2131 if (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced' }) ||
2132 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq 'yes' )) {
2133 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
2134 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2135 if (! $confighash { $cgiparams { 'KEY' }}) {
2136 $errormessage = $Lang :: tr
{ 'invalid key' };
2140 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
2141 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2143 $errormessage = $Lang :: tr
{ 'invalid input' };
2144 goto ADVANCED_ERROR
;
2146 foreach my $val ( @temp ) {
2147 if ( $val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|camellia(256|192|128))$/ ) {
2148 $errormessage = $Lang :: tr
{ 'invalid input' };
2149 goto ADVANCED_ERROR
;
2152 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2154 $errormessage = $Lang :: tr
{ 'invalid input' };
2155 goto ADVANCED_ERROR
;
2157 foreach my $val ( @temp ) {
2158 if ( $val !~ /^(sha2_(512|384|256)|sha|md5|aesxcbc)$/ ) {
2159 $errormessage = $Lang :: tr
{ 'invalid input' };
2160 goto ADVANCED_ERROR
;
2163 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2165 $errormessage = $Lang :: tr
{ 'invalid input' };
2166 goto ADVANCED_ERROR
;
2168 foreach my $val ( @temp ) {
2169 if ( $val !~ /^(e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|1024|1536|2048|2048s256|2048s224|2048s160|3072|4096|6144|8192)$/ ) {
2170 $errormessage = $Lang :: tr
{ 'invalid input' };
2171 goto ADVANCED_ERROR
;
2174 if ( $cgiparams { 'IKE_LIFETIME' } !~ /^\d+$/ ) {
2175 $errormessage = $Lang :: tr
{ 'invalid input for ike lifetime' };
2176 goto ADVANCED_ERROR
;
2178 if ( $cgiparams { 'IKE_LIFETIME' } < 1 || $cgiparams { 'IKE_LIFETIME' } > 8 ) {
2179 $errormessage = $Lang :: tr
{ 'ike lifetime should be between 1 and 8 hours' };
2180 goto ADVANCED_ERROR
;
2182 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2184 $errormessage = $Lang :: tr
{ 'invalid input' };
2185 goto ADVANCED_ERROR
;
2187 foreach my $val ( @temp ) {
2188 if ( $val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|camellia(256|192|128))$/ ) {
2189 $errormessage = $Lang :: tr
{ 'invalid input' };
2190 goto ADVANCED_ERROR
;
2193 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2195 $errormessage = $Lang :: tr
{ 'invalid input' };
2196 goto ADVANCED_ERROR
;
2198 foreach my $val ( @temp ) {
2199 if ( $val !~ /^(sha2_(512|384|256)|sha1|md5|aesxcbc)$/ ) {
2200 $errormessage = $Lang :: tr
{ 'invalid input' };
2201 goto ADVANCED_ERROR
;
2204 @temp = split ( '\|' , $cgiparams { 'ESP_GROUPTYPE' });
2206 $errormessage = $Lang :: tr
{ 'invalid input' };
2207 goto ADVANCED_ERROR
;
2209 foreach my $val ( @temp ) {
2210 if ( $val !~ /^(e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|1024|1536|2048|2048s256|2048s224|2048s160|3072|4096|6144|8192|none)$/ ) {
2211 $errormessage = $Lang :: tr
{ 'invalid input' };
2212 goto ADVANCED_ERROR
;
2215 if ( $cgiparams { 'ESP_KEYLIFE' } !~ /^\d+$/ ) {
2216 $errormessage = $Lang :: tr
{ 'invalid input for esp keylife' };
2217 goto ADVANCED_ERROR
;
2219 if ( $cgiparams { 'ESP_KEYLIFE' } < 1 || $cgiparams { 'ESP_KEYLIFE' } > 24 ) {
2220 $errormessage = $Lang :: tr
{ 'esp keylife should be between 1 and 24 hours' };
2221 goto ADVANCED_ERROR
;
2224 if (( $cgiparams { 'COMPRESSION' } !~ /^(|on|off)$/ ) ||
2225 ( $cgiparams { 'FORCE_MOBIKE' } !~ /^(|on|off)$/ ) ||
2226 ( $cgiparams { 'ONLY_PROPOSED' } !~ /^(|on|off)$/ ) ||
2227 ( $cgiparams { 'PFS' } !~ /^(|on|off)$/ )) {
2228 $errormessage = $Lang :: tr
{ 'invalid input' };
2229 goto ADVANCED_ERROR
;
2232 if ( $cgiparams { 'DPD_DELAY' } !~ /^\d+$/ ) {
2233 $errormessage = $Lang :: tr
{ 'invalid input for dpd delay' };
2234 goto ADVANCED_ERROR
;
2237 if ( $cgiparams { 'DPD_TIMEOUT' } !~ /^\d+$/ ) {
2238 $errormessage = $Lang :: tr
{ 'invalid input for dpd timeout' };
2239 goto ADVANCED_ERROR
;
2242 $confighash { $cgiparams { 'KEY' }}[ 29 ] = $cgiparams { 'IKE_VERSION' };
2243 $confighash { $cgiparams { 'KEY' }}[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
2244 $confighash { $cgiparams { 'KEY' }}[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
2245 $confighash { $cgiparams { 'KEY' }}[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
2246 $confighash { $cgiparams { 'KEY' }}[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
2247 $confighash { $cgiparams { 'KEY' }}[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
2248 $confighash { $cgiparams { 'KEY' }}[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
2249 $confighash { $cgiparams { 'KEY' }}[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
2250 $confighash { $cgiparams { 'KEY' }}[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
2251 $confighash { $cgiparams { 'KEY' }}[ 12 ] = 'off' ; #$cgiparams{'AGGRMODE'};
2252 $confighash { $cgiparams { 'KEY' }}[ 13 ] = $cgiparams { 'COMPRESSION' };
2253 $confighash { $cgiparams { 'KEY' }}[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
2254 $confighash { $cgiparams { 'KEY' }}[ 28 ] = $cgiparams { 'PFS' };
2255 $confighash { $cgiparams { 'KEY' }}[ 27 ] = $cgiparams { 'DPD_ACTION' };
2256 $confighash { $cgiparams { 'KEY' }}[ 30 ] = $cgiparams { 'DPD_TIMEOUT' };
2257 $confighash { $cgiparams { 'KEY' }}[ 31 ] = $cgiparams { 'DPD_DELAY' };
2258 $confighash { $cgiparams { 'KEY' }}[ 32 ] = $cgiparams { 'FORCE_MOBIKE' };
2259 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2262 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
2267 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
2268 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
2269 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
2270 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
2271 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
2272 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
2273 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
2274 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
2275 if ( $cgiparams { 'ESP_GROUPTYPE' } eq "" ) {
2276 $cgiparams { 'ESP_GROUPTYPE' } = $cgiparams { 'IKE_GROUPTYPE' };
2278 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
2279 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
2280 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
2281 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
2282 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
2283 $cgiparams { 'DPD_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
2284 $cgiparams { 'DPD_DELAY' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
2285 $cgiparams { 'FORCE_MOBIKE' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
2287 if (! $cgiparams { 'DPD_DELAY' }) {
2288 $cgiparams { 'DPD_DELAY' } = 30 ;
2291 if (! $cgiparams { 'DPD_TIMEOUT' }) {
2292 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
2297 $checked { 'IKE_ENCRYPTION' }{ 'aes256' } = '' ;
2298 $checked { 'IKE_ENCRYPTION' }{ 'aes192' } = '' ;
2299 $checked { 'IKE_ENCRYPTION' }{ 'aes128' } = '' ;
2300 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm128' } = '' ;
2301 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm128' } = '' ;
2302 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm128' } = '' ;
2303 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm96' } = '' ;
2304 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm96' } = '' ;
2305 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm96' } = '' ;
2306 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm64' } = '' ;
2307 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm64' } = '' ;
2308 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm64' } = '' ;
2309 $checked { 'IKE_ENCRYPTION' }{ '3des' } = '' ;
2310 $checked { 'IKE_ENCRYPTION' }{ 'camellia256' } = '' ;
2311 $checked { 'IKE_ENCRYPTION' }{ 'camellia192' } = '' ;
2312 $checked { 'IKE_ENCRYPTION' }{ 'camellia128' } = '' ;
2313 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2314 foreach my $key ( @temp ) { $checked { 'IKE_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2315 $checked { 'IKE_INTEGRITY' }{ 'sha2_512' } = '' ;
2316 $checked { 'IKE_INTEGRITY' }{ 'sha2_384' } = '' ;
2317 $checked { 'IKE_INTEGRITY' }{ 'sha2_256' } = '' ;
2318 $checked { 'IKE_INTEGRITY' }{ 'sha' } = '' ;
2319 $checked { 'IKE_INTEGRITY' }{ 'md5' } = '' ;
2320 $checked { 'IKE_INTEGRITY' }{ 'aesxcbc' } = '' ;
2321 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2322 foreach my $key ( @temp ) { $checked { 'IKE_INTEGRITY' }{ $key } = "selected='selected'" ; }
2323 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2324 $checked { 'IKE_GROUPTYPE' }{ '1024' } = '' ;
2325 $checked { 'IKE_GROUPTYPE' }{ '1536' } = '' ;
2326 $checked { 'IKE_GROUPTYPE' }{ '2048' } = '' ;
2327 $checked { 'IKE_GROUPTYPE' }{ '3072' } = '' ;
2328 $checked { 'IKE_GROUPTYPE' }{ '4096' } = '' ;
2329 $checked { 'IKE_GROUPTYPE' }{ '6144' } = '' ;
2330 $checked { 'IKE_GROUPTYPE' }{ '8192' } = '' ;
2331 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2332 foreach my $key ( @temp ) { $checked { 'IKE_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2334 # 768 is not supported by strongswan
2335 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2337 $checked { 'ESP_ENCRYPTION' }{ 'aes256' } = '' ;
2338 $checked { 'ESP_ENCRYPTION' }{ 'aes192' } = '' ;
2339 $checked { 'ESP_ENCRYPTION' }{ 'aes128' } = '' ;
2340 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm128' } = '' ;
2341 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm128' } = '' ;
2342 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm128' } = '' ;
2343 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm96' } = '' ;
2344 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm96' } = '' ;
2345 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm96' } = '' ;
2346 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm64' } = '' ;
2347 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm64' } = '' ;
2348 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm64' } = '' ;
2349 $checked { 'ESP_ENCRYPTION' }{ '3des' } = '' ;
2350 $checked { 'ESP_ENCRYPTION' }{ 'camellia256' } = '' ;
2351 $checked { 'ESP_ENCRYPTION' }{ 'camellia192' } = '' ;
2352 $checked { 'ESP_ENCRYPTION' }{ 'camellia128' } = '' ;
2353 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2354 foreach my $key ( @temp ) { $checked { 'ESP_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2355 $checked { 'ESP_INTEGRITY' }{ 'sha2_512' } = '' ;
2356 $checked { 'ESP_INTEGRITY' }{ 'sha2_384' } = '' ;
2357 $checked { 'ESP_INTEGRITY' }{ 'sha2_256' } = '' ;
2358 $checked { 'ESP_INTEGRITY' }{ 'sha1' } = '' ;
2359 $checked { 'ESP_INTEGRITY' }{ 'md5' } = '' ;
2360 $checked { 'ESP_INTEGRITY' }{ 'aesxcbc' } = '' ;
2361 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2362 foreach my $key ( @temp ) { $checked { 'ESP_INTEGRITY' }{ $key } = "selected='selected'" ; }
2363 $checked { 'ESP_GROUPTYPE' }{ '768' } = '' ;
2364 $checked { 'ESP_GROUPTYPE' }{ '1024' } = '' ;
2365 $checked { 'ESP_GROUPTYPE' }{ '1536' } = '' ;
2366 $checked { 'ESP_GROUPTYPE' }{ '2048' } = '' ;
2367 $checked { 'ESP_GROUPTYPE' }{ '3072' } = '' ;
2368 $checked { 'ESP_GROUPTYPE' }{ '4096' } = '' ;
2369 $checked { 'ESP_GROUPTYPE' }{ '6144' } = '' ;
2370 $checked { 'ESP_GROUPTYPE' }{ '8192' } = '' ;
2371 $checked { 'ESP_GROUPTYPE' }{ 'none' } = '' ;
2372 @temp = split ( '\|' , $cgiparams { 'ESP_GROUPTYPE' });
2373 foreach my $key ( @temp ) { $checked { 'ESP_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2375 $checked { 'COMPRESSION' } = $cgiparams { 'COMPRESSION' } eq 'on' ?
"checked='checked'" : '' ;
2376 $checked { 'FORCE_MOBIKE' } = $cgiparams { 'FORCE_MOBIKE' } eq 'on' ?
"checked='checked'" : '' ;
2377 $checked { 'ONLY_PROPOSED' } = $cgiparams { 'ONLY_PROPOSED' } eq 'on' ?
"checked='checked'" : '' ;
2378 $checked { 'PFS' } = $cgiparams { 'PFS' } eq 'on' ?
"checked='checked'" : '' ;
2380 $selected { 'IKE_VERSION' }{ 'ikev1' } = '' ;
2381 $selected { 'IKE_VERSION' }{ 'ikev2' } = '' ;
2382 $selected { 'IKE_VERSION' }{ $cgiparams { 'IKE_VERSION' }} = "selected='selected'" ;
2384 $selected { 'DPD_ACTION' }{ 'clear' } = '' ;
2385 $selected { 'DPD_ACTION' }{ 'hold' } = '' ;
2386 $selected { 'DPD_ACTION' }{ 'restart' } = '' ;
2387 $selected { 'DPD_ACTION' }{ 'none' } = '' ;
2388 $selected { 'DPD_ACTION' }{ $cgiparams { 'DPD_ACTION' }} = "selected='selected'" ;
2390 & Header
:: showhttpheaders
();
2391 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
2392 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2394 if ( $errormessage ) {
2395 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2396 print "<class name='base'> $errormessage " ;
2397 print " </class>" ;
2398 & Header
:: closebox
();
2402 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
2403 print "<class name='base'> $warnmessage " ;
2404 print " </class>" ;
2405 & Header
:: closebox
();
2408 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'advanced'}:" );
2410 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
2411 <input type='hidden' name='ADVANCED' value='yes' />
2412 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
2414 <table width='100%'>
2417 <th width="15%"></th>
2424 <td> $Lang ::tr{'vpn keyexchange'}:</td>
2426 <select name='IKE_VERSION'>
2427 <option value='ikev2' $selected {'IKE_VERSION'}{'ikev2'}>IKEv2</option>
2428 <option value='ikev1' $selected {'IKE_VERSION'}{'ikev1'}>IKEv1</option>
2434 <td class='boldbase' width="15%"> $Lang ::tr{'encryption'}</td>
2435 <td class='boldbase'>
2436 <select name='IKE_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
2437 <option value='aes256gcm128' $checked {'IKE_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
2438 <option value='aes256gcm96' $checked {'IKE_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
2439 <option value='aes256gcm64' $checked {'IKE_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
2440 <option value='aes256' $checked {'IKE_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
2441 <option value='camellia256' $checked {'IKE_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
2442 <option value='aes192gcm128' $checked {'IKE_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
2443 <option value='aes192gcm96' $checked {'IKE_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
2444 <option value='aes192gcm64' $checked {'IKE_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
2445 <option value='aes192' $checked {'IKE_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
2446 <option value='camellia192' $checked {'IKE_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
2447 <option value='aes128gcm128' $checked {'IKE_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
2448 <option value='aes128gcm96' $checked {'IKE_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
2449 <option value='aes128gcm64' $checked {'IKE_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
2450 <option value='aes128' $checked {'IKE_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
2451 <option value='camellia128' $checked {'IKE_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
2452 <option value='3des' $checked {'IKE_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC</option>
2455 <td class='boldbase'>
2456 <select name='ESP_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
2457 <option value='aes256gcm128' $checked {'ESP_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
2458 <option value='aes256gcm96' $checked {'ESP_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
2459 <option value='aes256gcm64' $checked {'ESP_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
2460 <option value='aes256' $checked {'ESP_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
2461 <option value='camellia256' $checked {'ESP_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
2462 <option value='aes192gcm128' $checked {'ESP_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
2463 <option value='aes192gcm96' $checked {'ESP_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
2464 <option value='aes192gcm64' $checked {'ESP_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
2465 <option value='aes192' $checked {'ESP_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
2466 <option value='camellia192' $checked {'ESP_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
2467 <option value='aes128gcm128' $checked {'ESP_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
2468 <option value='aes128gcm96' $checked {'ESP_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
2469 <option value='aes128gcm64' $checked {'ESP_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
2470 <option value='aes128' $checked {'ESP_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
2471 <option value='camellia128' $checked {'ESP_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
2472 <option value='3des' $checked {'ESP_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC</option>
2478 <td class='boldbase' width="15%"> $Lang ::tr{'integrity'}</td>
2479 <td class='boldbase'>
2480 <select name='IKE_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
2481 <option value='sha2_512' $checked {'IKE_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2482 <option value='sha2_384' $checked {'IKE_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2483 <option value='sha2_256' $checked {'IKE_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2484 <option value='aesxcbc' $checked {'IKE_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2485 <option value='sha' $checked {'IKE_INTEGRITY'}{'sha'}>SHA1</option>
2486 <option value='md5' $checked {'IKE_INTEGRITY'}{'md5'}>MD5</option>
2489 <td class='boldbase'>
2490 <select name='ESP_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
2491 <option value='sha2_512' $checked {'ESP_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2492 <option value='sha2_384' $checked {'ESP_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2493 <option value='sha2_256' $checked {'ESP_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2494 <option value='aesxcbc' $checked {'ESP_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2495 <option value='sha1' $checked {'ESP_INTEGRITY'}{'sha1'}>SHA1</option>
2496 <option value='md5' $checked {'ESP_INTEGRITY'}{'md5'}>MD5</option>
2501 <td class='boldbase' width="15%"> $Lang ::tr{'lifetime'} <img src='/blob.gif' alt='*' /></td>
2502 <td class='boldbase'>
2503 <input type='text' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' size='5' /> $Lang ::tr{'hours'}
2505 <td class='boldbase'>
2506 <input type='text' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' size='5' /> $Lang ::tr{'hours'}
2510 <td class='boldbase' width="15%"> $Lang ::tr{'grouptype'}</td>
2511 <td class='boldbase'>
2512 <select name='IKE_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
2513 <option value='e521' $checked {'IKE_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
2514 <option value='e512bp' $checked {'IKE_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
2515 <option value='e384' $checked {'IKE_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
2516 <option value='e384bp' $checked {'IKE_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
2517 <option value='e256' $checked {'IKE_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
2518 <option value='e256bp' $checked {'IKE_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
2519 <option value='e224' $checked {'IKE_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
2520 <option value='e224bp' $checked {'IKE_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
2521 <option value='e192' $checked {'IKE_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
2522 <option value='8192' $checked {'IKE_GROUPTYPE'}{'8192'}>MODP-8192</option>
2523 <option value='6144' $checked {'IKE_GROUPTYPE'}{'6144'}>MODP-6144</option>
2524 <option value='4096' $checked {'IKE_GROUPTYPE'}{'4096'}>MODP-4096</option>
2525 <option value='3072' $checked {'IKE_GROUPTYPE'}{'3072'}>MODP-3072</option>
2526 <option value='2048s256' $checked {'IKE_GROUPTYPE'}{'2048s256'}>MODP-2048/256</option>
2527 <option value='2048s224' $checked {'IKE_GROUPTYPE'}{'2048s224'}>MODP-2048/224</option>
2528 <option value='2048s160' $checked {'IKE_GROUPTYPE'}{'2048s160'}>MODP-2048/160</option>
2529 <option value='2048' $checked {'IKE_GROUPTYPE'}{'2048'}>MODP-2048</option>
2530 <option value='1536' $checked {'IKE_GROUPTYPE'}{'1536'}>MODP-1536</option>
2531 <option value='1024' $checked {'IKE_GROUPTYPE'}{'1024'}>MODP-1024</option>
2534 <td class='boldbase'>
2535 <select name='ESP_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
2536 <option value='e521' $checked {'ESP_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
2537 <option value='e512bp' $checked {'ESP_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
2538 <option value='e384' $checked {'ESP_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
2539 <option value='e384bp' $checked {'ESP_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
2540 <option value='e256' $checked {'ESP_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
2541 <option value='e256bp' $checked {'ESP_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
2542 <option value='e224' $checked {'ESP_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
2543 <option value='e224bp' $checked {'ESP_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
2544 <option value='e192' $checked {'ESP_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
2545 <option value='8192' $checked {'ESP_GROUPTYPE'}{'8192'}>MODP-8192</option>
2546 <option value='6144' $checked {'ESP_GROUPTYPE'}{'6144'}>MODP-6144</option>
2547 <option value='4096' $checked {'ESP_GROUPTYPE'}{'4096'}>MODP-4096</option>
2548 <option value='3072' $checked {'ESP_GROUPTYPE'}{'3072'}>MODP-3072</option>
2549 <option value='2048s256' $checked {'ESP_GROUPTYPE'}{'2048s256'}>MODP-2048/256</option>
2550 <option value='2048s224' $checked {'ESP_GROUPTYPE'}{'2048s224'}>MODP-2048/224</option>
2551 <option value='2048s160' $checked {'ESP_GROUPTYPE'}{'2048s160'}>MODP-2048/160</option>
2552 <option value='2048' $checked {'ESP_GROUPTYPE'}{'2048'}>MODP-2048</option>
2553 <option value='1536' $checked {'ESP_GROUPTYPE'}{'1536'}>MODP-1536</option>
2554 <option value='1024' $checked {'ESP_GROUPTYPE'}{'1024'}>MODP-1024</option>
2555 <option value='none' $checked {'ESP_GROUPTYPE'}{'none'}>- $Lang ::tr{'none'} -</option>
2564 <h2> $Lang ::tr{'dead peer detection'}</h2>
2566 <table width="100%">
2568 <td width="15%"> $Lang ::tr{'dpd action'}:</td>
2570 <select name='DPD_ACTION'>
2571 <option value='none' $selected {'DPD_ACTION'}{'none'}>- $Lang ::tr{'disabled'} -</option>
2572 <option value='clear' $selected {'DPD_ACTION'}{'clear'}>clear</option>
2573 <option value='hold' $selected {'DPD_ACTION'}{'hold'}>hold</option>
2574 <option value='restart' $selected {'DPD_ACTION'}{'restart'}>restart</option>
2579 <td width="15%"> $Lang ::tr{'dpd timeout'}: <img src='/blob.gif' alt='*' /></td>
2581 <input type='text' name='DPD_TIMEOUT' size='5' value=' $cgiparams {'DPD_TIMEOUT'}' />
2585 <td width="15%"> $Lang ::tr{'dpd delay'}: <img src='/blob.gif' alt='*' /></td>
2587 <input type='text' name='DPD_DELAY' size='5' value=' $cgiparams {'DPD_DELAY'}' />
2594 <table width="100%">
2598 <input type='checkbox' name='ONLY_PROPOSED' $checked {'ONLY_PROPOSED'} />
2599 IKE+ESP: $Lang ::tr{'use only proposed settings'}
2606 <input type='checkbox' name='PFS' $checked {'PFS'} />
2607 $Lang ::tr{'pfs yes no'}
2614 <input type='checkbox' name='COMPRESSION' $checked {'COMPRESSION'} />
2615 $Lang ::tr{'vpn payload compression'}
2622 <input type='checkbox' name='FORCE_MOBIKE' $checked {'FORCE_MOBIKE'} />
2623 $Lang ::tr{'vpn force mobike'}
2632 <td align='left' colspan='1'><img src='/blob.gif' align='top' alt='*' /> $Lang ::tr{'required field'}</td>
2633 <td align='right' colspan='2'>
2634 <input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />
2635 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' />
2641 & Header
:: closebox
();
2642 & Header
:: closebigbox
();
2643 & Header
:: closepage
();
2650 ### Default status page
2655 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%cgiparams );
2656 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
2657 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2658 $cgiparams { 'CA_NAME' } = '' ;
2660 my @status = `/usr/local/bin/ipsecctrl I 2>/dev/null` ;
2662 # suggest a default name for this side
2663 if ( $cgiparams { 'VPN_IP' } eq '' && - e
"${General::swroot}/red/active" ) {
2664 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
2665 my $ipaddr = < IPADDR
>;
2668 $cgiparams { 'VPN_IP' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
2669 if ( $cgiparams { 'VPN_IP' } eq '' ) {
2670 $cgiparams { 'VPN_IP' } = $ipaddr ;
2674 # no IP found, use %defaultroute
2675 $cgiparams { 'VPN_IP' } = ' %defaultroute ' if ( $cgiparams { 'VPN_IP' } eq '' );
2677 $cgiparams { 'VPN_DELAYED_START' } = 0 if (! defined ( $cgiparams { 'VPN_DELAYED_START' }));
2678 $checked { 'ENABLED' } = $cgiparams { 'ENABLED' } eq 'on' ?
"checked='checked'" : '' ;
2680 & Header
:: showhttpheaders
();
2681 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
2682 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2684 if ( $errormessage ) {
2685 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2686 print "<class name='base'> $errormessage \n " ;
2687 print " </class> \n " ;
2688 & Header
:: closebox
();
2692 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
2693 print " $warnmessage <br>" ;
2694 print " $Lang ::tr{'fwdfw warn1'}<br>" ;
2695 & Header
:: closebox
();
2696 print "<center><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'ok'}' style='width: 5em;'></form>" ;
2697 & Header
:: closepage
();
2701 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'global settings' });
2703 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2704 <table width='100%'>
2706 <td width='20%' class='base' nowrap='nowrap'> $Lang ::tr{'vpn red name'}: <img src='/blob.gif' alt='*' /></td>
2707 <td width='20%'><input type='text' name='VPN_IP' value=' $cgiparams {'VPN_IP'}' /></td>
2708 <td width='20%' class='base'> $Lang ::tr{'enabled'}<input type='checkbox' name='ENABLED' $checked {'ENABLED'} /></td>
2714 <td class='base' nowrap='nowrap'> $Lang ::tr{'vpn delayed start'}: <img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' /></td>
2715 <td ><input type='text' name='VPN_DELAYED_START' value=' $cgiparams {'VPN_DELAYED_START'}' /></td>
2718 <td class='base' nowrap='nowrap'> $Lang ::tr{'host to net vpn'}:</td>
2719 <td ><input type='text' name='RW_NET' value=' $cgiparams {'RW_NET'}' /></td>
2724 <table width='100%'>
2726 <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
2727 <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>
2730 <td class='base' valign='top' nowrap='nowrap'><img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' /> </td>
2731 <td class='base'> <font class='base'> $Lang ::tr{'vpn delayed start help'}</font></td>
2738 & Header
:: closebox
();
2740 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection status and controlc' });
2742 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
2744 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
2745 <th width='22%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></th>
2746 <th width='23%' class='boldbase' align='center'><b> $Lang ::tr{'common name'}</b></th>
2747 <th width='30%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></th>
2748 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></th>
2749 <th class='boldbase' align='center' colspan='6'><b> $Lang ::tr{'action'}</b></th>
2755 foreach my $key ( sort { ncmp
( $confighash { $a }[ 1 ], $confighash { $b }[ 1 ]) } keys %confighash ) {
2756 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
2760 $col = "bgcolor=' $color {'color20'}'" ;
2763 $col = "bgcolor=' $color {'color22'}'" ;
2765 print "<td align='center' nowrap='nowrap' $col > $confighash { $key }[1]</td>" ;
2766 print "<td align='center' nowrap='nowrap' $col >" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ") $confighash { $key }[29]</td>" ;
2767 if ( $confighash { $key }[ 2 ] eq ' %auth -dn' ) {
2768 print "<td align='left' nowrap='nowrap' $col > $confighash { $key }[9]</td>" ;
2769 } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
2770 print "<td align='left' nowrap='nowrap' $col > $confighash { $key }[2]</td>" ;
2772 print "<td align='left' $col > </td>" ;
2774 print "<td align='center' $col > $confighash { $key }[25]</td>" ;
2775 my $col1 = "bgcolor='${Header::colourred}'" ;
2777 my $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
2778 foreach my $line ( @status ) {
2779 if (( $line =~ /\"$confighash{$key}[1]\".*IPsec SA established/ ) ||
2780 ( $line =~ /$confighash{$key}[1]\{.*INSTALLED/ )) {
2781 $col1 = "bgcolor='${Header::colourgreen}'" ;
2782 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b>" ;
2785 # move to blue if really down
2786 if ( $confighash { $key }[ 0 ] eq 'off' && $col1 =~ /${Header::colourred}/ ) {
2787 $col1 = "bgcolor='${Header::colourblue}'" ;
2788 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
2791 <td align='center' $col1 > $active </td>
2792 <td align='center' $col >
2793 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2794 <input type='image' name=' $Lang ::tr{'restart'}' src='/images/reload.gif' alt=' $Lang ::tr{'restart'}' title=' $Lang ::tr{'restart'}' />
2795 <input type='hidden' name='ACTION' value=' $Lang ::tr{'restart'}' />
2796 <input type='hidden' name='KEY' value=' $key ' />
2801 if (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
2803 <td align='center' $col >
2804 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2805 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' />
2806 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
2807 <input type='hidden' name='KEY' value=' $key ' />
2813 print "<td width='2%' $col > </td>" ;
2815 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/certs/ $confighash { $key }[1].p12" ) {
2817 <td align='center' $col >
2818 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2819 <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'}' />
2820 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
2821 <input type='hidden' name='KEY' value=' $key ' />
2826 } elsif (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
2828 <td align='center' $col >
2829 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2830 <input type='image' name=' $Lang ::tr{'download certificate'}' src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' title=' $Lang ::tr{'download certificate'}' />
2831 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
2832 <input type='hidden' name='KEY' value=' $key ' />
2838 print "<td width='2%' $col > </td>" ;
2841 <td align='center' $col >
2842 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2843 <input type='image' name=' $Lang ::tr{'toggle enable disable'}' src='/images/ $gif ' alt=' $Lang ::tr{'toggle enable disable'}' title=' $Lang ::tr{'toggle enable disable'}' />
2844 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
2845 <input type='hidden' name='KEY' value=' $key ' />
2849 <td align='center' $col >
2850 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2851 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
2852 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' title=' $Lang ::tr{'edit'}' />
2853 <input type='hidden' name='KEY' value=' $key ' />
2856 <td align='center' $col >
2857 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2858 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
2859 <input type='image' name=' $Lang ::tr{'remove'}' src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' title=' $Lang ::tr{'remove'}' />
2860 <input type='hidden' name='KEY' value=' $key ' />
2870 # If the config file contains entries, print Key to action icons
2875 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
2876 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
2877 <td class='base'> $Lang ::tr{'click to disable'}</td>
2878 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
2879 <td class='base'> $Lang ::tr{'show certificate'}</td>
2880 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
2881 <td class='base'> $Lang ::tr{'edit'}</td>
2882 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
2883 <td class='base'> $Lang ::tr{'remove'}</td>
2887 <td> <img src='/images/off.gif' alt='?OFF' /></td>
2888 <td class='base'> $Lang ::tr{'click to enable'}</td>
2889 <td> <img src='/images/floppy.gif' alt='?FLOPPY' /></td>
2890 <td class='base'> $Lang ::tr{'download certificate'}</td>
2891 <td> <img src='/images/reload.gif' alt='?RELOAD'/></td>
2892 <td class='base'> $Lang ::tr{'restart'}</td>
2900 <table width='100%'>
2901 <tr><td align='right' colspan='9'>
2902 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2903 <input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />
2909 & Header
:: closebox
();
2911 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'certificate authorities'}" );
2913 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
2915 <th width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
2916 <th width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></th>
2917 <th width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></th>
2921 my $col1 = "bgcolor=' $color {'color22'}'" ;
2922 my $col2 = "bgcolor=' $color {'color20'}'" ;
2923 if (- f
"${General::swroot}/ca/cacert.pem" ) {
2924 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/cacert.pem" ));
2927 <td class='base' $col1 > $Lang ::tr{'root certificate'}</td>
2928 <td class='base' $col1 > $casubject </td>
2929 <td width='3%' align='center' $col1 >
2930 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2931 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
2932 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/info.gif' alt=' $Lang ::tr{'show root certificate'}' title=' $Lang ::tr{'show root certificate'}' />
2935 <td width='3%' align='center' $col1 >
2936 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2937 <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'}' />
2938 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
2941 <td width='4%' $col1 > </td></tr>
2945 # display rootcert generation buttons
2948 <td class='base' $col1 > $Lang ::tr{'root certificate'}:</td>
2949 <td class='base' $col1 > $Lang ::tr{'not present'}</td>
2950 <td colspan='3' $col1 > </td></tr>
2955 if (- f
"${General::swroot}/certs/hostcert.pem" ) {
2956 my $hostsubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/certs/hostcert.pem" ));
2960 <td class='base' $col2 > $Lang ::tr{'host certificate'}</td>
2961 <td class='base' $col2 > $hostsubject </td>
2962 <td width='3%' align='center' $col2 >
2963 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2964 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
2965 <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'}' />
2968 <td width='3%' align='center' $col2 >
2969 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2970 <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'}" />
2971 <input type='hidden' name='ACTION' value=" $Lang ::tr{'download host certificate'}" />
2974 <td width='4%' $col2 > </td></tr>
2981 <td width='25%' class='base' $col2 > $Lang ::tr{'host certificate'}:</td>
2982 <td class='base' $col2 > $Lang ::tr{'not present'}</td>
2983 <td colspan='3' $col2 > </td></tr>
2989 if ( keys %cahash > 0 ) {
2990 foreach my $key ( keys %cahash ) {
2991 if ( $rowcolor ++ % 2 ) {
2993 $col = "bgcolor=' $color {'color20'}'" ;
2996 $col = "bgcolor=' $color {'color22'}'" ;
2998 print "<td class='base' $col > $cahash { $key }[0]</td> \n " ;
2999 print "<td class='base' $col > $cahash { $key }[1]</td> \n " ;
3001 <td align='center' $col >
3002 <form method='post' name='cafrm${key}a' action=' $ENV {'SCRIPT_NAME'}'>
3003 <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'}' />
3004 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
3005 <input type='hidden' name='KEY' value=' $key ' />
3008 <td align='center' $col >
3009 <form method='post' name='cafrm${key}b' action=' $ENV {'SCRIPT_NAME'}'>
3010 <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'}' />
3011 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
3012 <input type='hidden' name='KEY' value=' $key ' />
3015 <td align='center' $col >
3016 <form method='post' name='cafrm${key}c' action=' $ENV {'SCRIPT_NAME'}'>
3017 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
3018 <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'}' />
3019 <input type='hidden' name='KEY' value=' $key ' />
3029 # If the file contains entries, print Key to action icons
3030 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
3033 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
3034 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
3035 <td class='base'> $Lang ::tr{'show certificate'}</td>
3036 <td> <img src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' /></td>
3037 <td class='base'> $Lang ::tr{'download certificate'}</td>
3042 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>" ;
3046 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
3047 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
3050 <td class='base' nowrap='nowrap'> $Lang ::tr{'ca name'}: <img src='/blob.gif' alt='*' /></td>
3051 <td nowrap='nowrap'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' /> </td>
3052 <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td>
3053 <td nowrap='nowrap'><input type='submit' name='ACTION' value=' $Lang ::tr{'upload ca certificate'}' /></td>
3056 <td colspan='3'> $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}:</td>
3057 <td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' /></td>
3063 & Header
:: closebox
();
3064 & Header
:: closebigbox
();
3065 & Header
:: closepage
();
3067 sub array_unique
($) {
3072 foreach my $e ( @
$array ) {
3073 next if $seen { $e }++;
3080 sub make_algos
($$$$$) {
3081 my ( $mode , $encs , $ints , $grps , $pfs ) = @_ ;
3084 foreach my $enc ( @
$encs ) {
3085 foreach my $int ( @
$ints ) {
3086 foreach my $grp ( @
$grps ) {
3089 if ( $mode eq "ike" ) {
3092 if ( $grp =~ m/^e(.*)$/ ) {
3093 push ( @algo , "ecp $1 " );
3095 push ( @algo , "modp $grp " );
3098 } elsif ( $mode eq "esp" && $pfs ) {
3099 my $is_aead = ( $enc =~ m/[cg]cm/ );
3105 if ( $grp eq "none" ) {
3107 } elsif ( $grp =~ m/^e(.*)$/ ) {
3108 push ( @algo , "ecp $1 " );
3110 push ( @algo , "modp $grp " );
3114 push ( @algos , join ( "-" , @algo ));
3119 return & array_unique
( \
@algos );
3122 sub make_subnets
($) {
3123 my $subnets = shift ;
3125 my @nets = split ( /\|/ , $subnets );
3127 foreach my $net ( @nets ) {
3128 my $cidr_net = & General
:: ipcidr
( $net );
3129 push ( @cidr_nets , $cidr_net );
3132 return join ( "," , @cidr_nets );