]>
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-2022 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 ###############################################################################
26 use File
:: Temp qw
/ tempfile tempdir / ;
30 # enable only the following on debugging purpose
32 #use CGI::Carp 'fatalsToBrowser';
34 require '/var/ipfire/general-functions.pl' ;
35 require "${General::swroot}/lang.pl" ;
36 require "${General::swroot}/header.pl" ;
37 require "${General::swroot}/countries.pl" ;
39 #workaround to suppress a warning when a variable is used only once
40 my @dummy = ( ${ Header
:: colourgreen
}, ${ Header
:: colourblue
} );
44 ### Initialize variables
46 my $sleepDelay = 4 ; # after a call to ipsecctrl S or R, wait this delay (seconds) before reading status (let the ipsec do its job)
55 my $errormessage = '' ;
58 my %mainsettings = ();
59 & General
:: readhash
( "${General::swroot}/main/settings" , \
%mainsettings );
60 & General
:: readhash
( "/srv/web/ipfire/html/themes/ipfire/include/colors.txt" , \
%color );
62 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%netsettings );
64 my %INACTIVITY_TIMEOUTS = (
65 300 => $Lang :: tr
{ 'five minutes' },
66 600 => $Lang :: tr
{ 'ten minutes' },
67 900 => $Lang :: tr
{ 'fifteen minutes' },
68 1800 => $Lang :: tr
{ 'thirty minutes' },
69 3600 => $Lang :: tr
{ 'one hour' },
70 43200 => $Lang :: tr
{ 'twelve hours' },
71 86400 => $Lang :: tr
{ '24 hours' },
72 0 => "- $Lang ::tr{'unlimited'} -" ,
77 & General
:: get_aliases
( \
%aliases );
81 $cgiparams { 'ENABLED' } = 'off' ;
82 $cgiparams { 'EDIT_ADVANCED' } = 'off' ;
83 $cgiparams { 'ACTION' } = '' ;
84 $cgiparams { 'CA_NAME' } = '' ;
85 $cgiparams { 'KEY' } = '' ;
86 $cgiparams { 'TYPE' } = '' ;
87 $cgiparams { 'ADVANCED' } = '' ;
88 $cgiparams { 'NAME' } = '' ;
89 $cgiparams { 'LOCAL_SUBNET' } = '' ;
90 $cgiparams { 'REMOTE_SUBNET' } = '' ;
91 $cgiparams { 'LOCAL' } = '' ;
92 $cgiparams { 'REMOTE' } = '' ;
93 $cgiparams { 'LOCAL_ID' } = '' ;
94 $cgiparams { 'REMOTE_ID' } = '' ;
95 $cgiparams { 'REMARK' } = '' ;
96 $cgiparams { 'PSK' } = '' ;
97 $cgiparams { 'CERT_NAME' } = '' ;
98 $cgiparams { 'CERT_EMAIL' } = '' ;
99 $cgiparams { 'CERT_OU' } = '' ;
100 $cgiparams { 'CERT_ORGANIZATION' } = '' ;
101 $cgiparams { 'CERT_CITY' } = '' ;
102 $cgiparams { 'CERT_STATE' } = '' ;
103 $cgiparams { 'CERT_COUNTRY' } = '' ;
104 $cgiparams { 'SUBJECTALTNAME' } = '' ;
105 $cgiparams { 'CERT_PASS1' } = '' ;
106 $cgiparams { 'CERT_PASS2' } = '' ;
107 $cgiparams { 'ROOTCERT_HOSTNAME' } = '' ;
108 $cgiparams { 'ROOTCERT_COUNTRY' } = '' ;
109 $cgiparams { 'P12_PASS' } = '' ;
110 $cgiparams { 'ROOTCERT_ORGANIZATION' } = '' ;
111 $cgiparams { 'ROOTCERT_HOSTNAME' } = '' ;
112 $cgiparams { 'ROOTCERT_EMAIL' } = '' ;
113 $cgiparams { 'ROOTCERT_OU' } = '' ;
114 $cgiparams { 'ROOTCERT_CITY' } = '' ;
115 $cgiparams { 'ROOTCERT_STATE' } = '' ;
116 $cgiparams { 'RW_ENDPOINT' } = '' ;
117 $cgiparams { 'RW_NET' } = '' ;
118 $cgiparams { 'DPD_DELAY' } = '30' ;
119 $cgiparams { 'DPD_TIMEOUT' } = '120' ;
120 $cgiparams { 'FORCE_MOBIKE' } = 'off' ;
121 $cgiparams { 'START_ACTION' } = 'route' ;
122 $cgiparams { 'INACTIVITY_TIMEOUT' } = 1800 ;
123 $cgiparams { 'MODE' } = "tunnel" ;
124 $cgiparams { 'INTERFACE_MODE' } = "" ;
125 $cgiparams { 'INTERFACE_ADDRESS' } = "" ;
126 $cgiparams { 'INTERFACE_MTU' } = 1500 ;
127 $cgiparams { 'DNS_SERVERS' } = "" ;
128 & Header
:: getcgihash
( \
%cgiparams , { 'wantfile' => 1 , 'filevar' => 'FH' });
130 my %APPLE_CIPHERS = (
131 "aes256gcm128" => "AES-256-GCM" ,
132 "aes128gcm128" => "AES-128-GCM" ,
133 "aes256" => "AES-256" ,
134 "aes128" => "AES-128" ,
138 my %APPLE_INTEGRITIES = (
139 "sha2_512" => "SHA2-512" ,
140 "sha2_384" => "SHA2-384" ,
141 "sha2_256" => "SHA2-256" ,
142 "sha1" => "SHA1-160" ,
145 my %APPLE_DH_GROUPS = (
163 my $hostname = $_ [ 0 ];
164 unless ( $hostname ) { return "No hostname" };
165 my $res = new Net
:: DNS
:: Resolver
;
166 my $query = $res -> search ( " $hostname " );
168 foreach my $rr ( $query -> answer ) {
169 ## Potential bug - we are only looking at A records:
170 return 0 if $rr -> type eq "A" ;
173 return $res -> errorstring ;
177 ### Just return true is one interface is vpn enabled
180 return ( $vpnsettings { 'ENABLED' } eq 'on' );
183 ### old version: maintain serial number to one, without explication.
184 ### this: let the counter go, so that each cert is numbered.
186 sub cleanssldatabase
{
187 if ( open ( FILE
, ">${General::swroot}/certs/serial" )) {
191 if ( open ( FILE
, ">${General::swroot}/certs/index.txt" )) {
195 if ( open ( FILE
, ">${General::swroot}/certs/index.txt.attr" )) {
196 print FILE
"unique_subject = yes" ;
199 unlink ( "${General::swroot}/certs/index.txt.old" );
200 unlink ( "${General::swroot}/certs/index.txt.attr.old" );
201 unlink ( "${General::swroot}/certs/serial.old" );
202 unlink ( "${General::swroot}/certs/01.pem" );
204 sub newcleanssldatabase
{
205 if (! - s
"${General::swroot}/certs/serial" ) {
206 open ( FILE
, ">${General::swroot}/certs/serial" );
210 if (! - s
">${General::swroot}/certs/index.txt" ) {
211 open ( FILE
, ">${General::swroot}/certs/index.txt" );
214 if (! - s
">${General::swroot}/certs/index.txt.attr" ) {
215 open ( FILE
, ">${General::swroot}/certs/index.txt.attr" );
216 print FILE
"unique_subject = yes" ;
219 unlink ( "${General::swroot}/certs/index.txt.old" );
220 unlink ( "${General::swroot}/certs/index.txt.attr.old" );
221 unlink ( "${General::swroot}/certs/serial.old" );
222 # unlink ("${General::swroot}/certs/01.pem"); numbering evolves. Wrong place to delete
226 ### Call openssl and return errormessage if any
230 my $retssl = `/usr/bin/openssl $opt 2>&1` ; #redirect stderr
234 foreach my $line ( split ( /\n/ , $retssl )) {
235 & General
:: log ( "ipsec" , " $line " ) if ( 0 ); # 1 for verbose logging
236 $ret .= '<br>' . & Header
:: escape
( $line );
240 return $ret ?
" $Lang ::tr{'openssl produced an error'}: $ret " : '' ;
243 ### Obtain a CN from given cert
245 sub getCNfromcert
($) {
246 #&General::log("ipsec", "Extracting name from $_[0]...");
247 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
248 $temp =~ /Subject:.*CN\s*=\s*(.*)[\n]/ ;
250 $temp =~ s
+/ Email
+, E
+;
251 $temp =~ s/ ST = / S = / ;
257 ### Obtain Subject from given cert
259 sub getsubjectfromcert
($) {
260 #&General::log("ipsec", "Extracting subject from $_[0]...");
261 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
262 $temp =~ /Subject: (.*)[\n]/ ;
264 $temp =~ s
+/ Email
+, E
+;
265 $temp =~ s/ ST = / S = / ;
269 ### Combine local subnet and connection name to make a unique name for each connection section
270 ### (this sub is not used now)
272 sub makeconnname
($) {
276 $subnet =~ /^(.*?)\/ (.* ?
)$/; # $1=IP $2=mask
277 my $ip = unpack ( 'N' , & Socket
:: inet_aton
( $1 ));
278 if ( length ( $2 ) > 2 ) {
279 my $mm = unpack ( 'N' , & Socket
:: inet_aton
( $2 ));
280 while ( ( $mm & 1 )== 0 ) {
287 return sprintf ( " %s - %X " , $conn , $ip );
290 ### Write a config file.
292 ###Type=Host : GUI can choose the interface used (RED,GREEN,BLUE) and
293 ### the side is always defined as 'left'.
296 sub writeipsecfiles
{
297 my %lconfighash = ();
298 my %lvpnsettings = ();
299 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%lconfighash );
300 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%lvpnsettings );
302 open ( CONF
, ">${General::swroot}/vpn/ipsec.conf" ) or die "Unable to open ${General::swroot}/vpn/ipsec.conf: $!" ;
303 open ( SECRETS
, ">${General::swroot}/vpn/ipsec.secrets" ) or die "Unable to open ${General::swroot}/vpn/ipsec.secrets: $!" ;
306 print CONF
"version 2 \n\n " ;
307 print CONF
"conn %default \n " ;
308 print CONF
" \t keyingtries= %forever \n " ;
311 # Add user includes to config file
312 if (- e
"/etc/ipsec.user.conf" ) {
313 print CONF
"include /etc/ipsec.user.conf \n " ;
317 print SECRETS
"include /etc/ipsec.user.secrets \n " ;
319 if (- f
"${General::swroot}/certs/hostkey.pem" ) {
320 print SECRETS
": RSA ${General::swroot}/certs/hostkey.pem \n "
322 my $last_secrets = '' ; # old the less specifics connections
324 foreach my $key ( keys %lconfighash ) {
325 next if ( $lconfighash { $key }[ 0 ] ne 'on' );
327 #remote peer is not set? => use '%any'
328 $lconfighash { $key }[ 10 ] = ' %any ' if ( $lconfighash { $key }[ 10 ] eq '' );
330 # Field 6 might be "off" on old installations
331 if ( $lconfighash { $key }[ 6 ] eq "off" ) {
332 $lconfighash { $key }[ 6 ] = $lvpnsettings { "VPN_IP" };
336 if ( $lconfighash { $key }[ 6 ]) {
337 $localside = $lconfighash { $key }[ 6 ];
339 $localside = " %defaultroute " ;
342 my $interface_mode = $lconfighash { $key }[ 36 ];
344 print CONF
"conn $lconfighash { $key }[1] \n " ;
345 print CONF
" \t left= $localside \n " ;
347 if ( $interface_mode eq "gre" ) {
348 print CONF
" \t leftprotoport=gre \n " ;
349 } elsif ( $interface_mode eq "vti" ) {
350 print CONF
" \t leftsubnet=0.0.0.0/0 \n " ;
352 print CONF
" \t leftsubnet=" . & make_subnets
( "left" , $lconfighash { $key }[ 8 ]) . " \n " ;
355 print CONF
" \t leftfirewall=yes \n " ;
356 print CONF
" \t lefthostaccess=yes \n " ;
358 # Always send the host certificate
359 if ( $lconfighash { $key }[ 3 ] eq 'host' ) {
360 print CONF
" \t leftsendcert=always \n " ;
363 print CONF
" \t right= $lconfighash { $key }[10] \n " ;
365 if ( $lconfighash { $key }[ 3 ] eq 'net' ) {
366 if ( $interface_mode eq "gre" ) {
367 print CONF
" \t rightprotoport=gre \n " ;
368 } elsif ( $interface_mode eq "vti" ) {
369 print CONF
" \t rightsubnet=0.0.0.0/0 \n " ;
371 print CONF
" \t rightsubnet=" . & make_subnets
( "right" , $lconfighash { $key }[ 11 ]) . " \n " ;
375 # Local Cert and Remote Cert (unless auth is DN dn-auth)
376 if ( $lconfighash { $key }[ 4 ] eq 'cert' ) {
377 print CONF
" \t leftcert=${General::swroot}/certs/hostcert.pem \n " ;
378 print CONF
" \t rightcert=${General::swroot}/certs/ $lconfighash { $key }[1]cert.pem \n " if ( $lconfighash { $key }[ 2 ] ne ' %auth -dn' );
381 # Local and Remote IDs
382 print CONF
" \t leftid= \" $lconfighash { $key }[7] \"\n " if ( $lconfighash { $key }[ 7 ]);
383 print CONF
" \t rightid= \" $lconfighash { $key }[9] \"\n " if ( $lconfighash { $key }[ 9 ]);
386 if ( $lconfighash { $key }[ 35 ] eq "transport" ) {
387 print CONF
" \t type=transport \n " ;
389 print CONF
" \t type=tunnel \n " ;
393 if ( $interface_mode eq "vti" ) {
394 print CONF
" \t mark= $key \n " ;
398 my $pfs = $lconfighash { $key }[ 28 ] eq 'on' ?
'on' : 'off' ;
401 if ( $lconfighash { $key }[ 18 ] && $lconfighash { $key }[ 19 ] && $lconfighash { $key }[ 20 ]) {
402 my @encs = split ( '\|' , $lconfighash { $key }[ 18 ]);
403 my @ints = split ( '\|' , $lconfighash { $key }[ 19 ]);
404 my @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
406 my @algos = & make_algos
( "ike" , \
@encs , \
@ints , \
@groups , 1 );
407 print CONF
" \t ike=" . join ( "," , @algos );
409 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
416 if ( $lconfighash { $key }[ 21 ] && $lconfighash { $key }[ 22 ]) {
417 my @encs = split ( '\|' , $lconfighash { $key }[ 21 ]);
418 my @ints = split ( '\|' , $lconfighash { $key }[ 22 ]);
419 my @groups = split ( '\|' , $lconfighash { $key }[ 23 ]);
421 # Use IKE grouptype if no ESP group type has been selected
422 # (for backwards compatibility)
423 if ( $lconfighash { $key }[ 23 ] eq "" ) {
424 @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
427 my @algos = & make_algos
( "esp" , \
@encs , \
@ints , \
@groups , ( $pfs eq "on" ));
428 print CONF
" \t esp=" . join ( "," , @algos );
430 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
438 if (! $lconfighash { $key }[ 29 ]) {
439 $lconfighash { $key }[ 29 ] = "ikev1" ;
442 print CONF
" \t keyexchange= $lconfighash { $key }[29] \n " ;
445 print CONF
" \t ikelifetime= $lconfighash { $key }[16]h \n " if ( $lconfighash { $key }[ 16 ]);
446 print CONF
" \t keylife= $lconfighash { $key }[17]h \n " if ( $lconfighash { $key }[ 17 ]);
449 print CONF
" \t compress=yes \n " if ( $lconfighash { $key }[ 13 ] eq 'on' );
452 if (( $lconfighash { $key }[ 29 ] eq "ikev2" ) && ( $lconfighash { $key }[ 32 ] eq 'on' )) {
453 print CONF
" \t mobike=yes \n " ;
456 # Dead Peer Detection
457 my $dpdaction = $lconfighash { $key }[ 27 ];
458 print CONF
" \t dpdaction= $dpdaction \n " ;
460 # If the dead peer detection is disabled and IKEv2 is used,
461 # dpddelay must be set to zero, too.
462 if ( $dpdaction eq "none" ) {
463 if ( $lconfighash { $key }[ 29 ] eq "ikev2" ) {
464 print CONF
" \t dpddelay=0 \n " ;
467 my $dpddelay = $lconfighash { $key }[ 31 ];
471 print CONF
" \t dpddelay= $dpddelay \n " ;
472 my $dpdtimeout = $lconfighash { $key }[ 30 ];
476 print CONF
" \t dpdtimeout= $dpdtimeout \n " ;
479 # Build Authentication details: LEFTid RIGHTid : PSK psk
481 if ( $lconfighash { $key }[ 4 ] eq 'psk' ) {
482 $psk_line = ( $lconfighash { $key }[ 7 ] ?
$lconfighash { $key }[ 7 ] : $localside ) . " " ;
483 $psk_line .= $lconfighash { $key }[ 9 ] ?
$lconfighash { $key }[ 9 ] : $lconfighash { $key }[ 10 ]; #remoteid or remote address?
484 $psk_line .= " : PSK ' $lconfighash { $key }[5]' \n " ;
485 # if the line contains %any, it is less specific than two IP or ID, so move it at end of file.
486 if ( $psk_line =~ /%any/ ) {
487 $last_secrets .= $psk_line ;
489 print SECRETS
$psk_line ;
491 print CONF
" \t authby=secret \n " ;
493 print CONF
" \t authby=rsasig \n " ;
494 print CONF
" \t leftrsasigkey= %cert \n " ;
495 print CONF
" \t rightrsasigkey= %cert \n " ;
498 my $start_action = $lconfighash { $key }[ 33 ];
499 if (! $start_action ) {
500 $start_action = "start" ;
503 my $inactivity_timeout = $lconfighash { $key }[ 34 ];
504 if ( $inactivity_timeout eq "" ) {
505 $inactivity_timeout = 900 ;
508 # Automatically start only if a net-to-net connection
509 if ( $lconfighash { $key }[ 3 ] eq 'host' ) {
510 print CONF
" \t auto=add \n " ;
511 print CONF
" \t rightsourceip= $lvpnsettings {'RW_NET'} \n " ;
513 print CONF
" \t auto= $start_action \n " ;
515 # If in on-demand mode, we terminate the tunnel
516 # after 15 min of no traffic
517 if ( $start_action eq 'route' && $inactivity_timeout > 0 ) {
518 print CONF
" \t inactivity= $inactivity_timeout \n " ;
523 print CONF
" \t fragmentation=yes \n " ;
526 if ( $lconfighash { $key }[ 3 ] eq 'host' ) {
527 my @servers = split ( /\|/ , $lconfighash { $key }[ 39 ]);
529 print CONF
" \t rightdns=" . join ( "," , @servers ) . " \n " ;
535 # Add post user includes to config file
536 # After the GUI-connections allows to patch connections.
537 if (- e
"/etc/ipsec.user-post.conf" ) {
538 print CONF
"include /etc/ipsec.user-post.conf \n " ;
542 print SECRETS
$last_secrets if ( $last_secrets );
547 # Hook to regenerate the configuration files.
548 if ( $ENV { "REMOTE_ADDR" } eq "" ) {
554 ### Save main settings
556 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
557 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
559 if ( $cgiparams { 'RW_ENDPOINT' } ne '' && !& General
:: validip
( $cgiparams { 'RW_ENDPOINT' }) && !& General
:: validfqdn
( $cgiparams { 'RW_ENDPOINT' })) {
560 $errormessage = $Lang :: tr
{ 'ipsec invalid ip address or fqdn for rw endpoint' };
564 if ( $cgiparams { 'RW_NET' } ne '' and !& General
:: validipandmask
( $cgiparams { 'RW_NET' }) ) {
565 $errormessage = $Lang :: tr
{ 'urlfilter invalid ip or mask error' };
569 $vpnsettings { 'ENABLED' } = $cgiparams { 'ENABLED' };
570 $vpnsettings { 'RW_ENDPOINT' } = $cgiparams { 'RW_ENDPOINT' };
571 $vpnsettings { 'RW_NET' } = $cgiparams { 'RW_NET' };
572 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
575 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'S' );
577 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'D' );
584 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
585 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
587 foreach my $key ( keys %confighash ) {
588 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
589 delete $confighash { $key };
592 while ( my $file = glob ( "${General::swroot}/{ca,certs,crls,private}/*" )) {
596 if ( open ( FILE
, ">${General::swroot}/vpn/caconfig" )) {
600 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
602 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'R' );
608 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' }) {
609 & Header
:: showhttpheaders
();
610 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
611 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
612 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
614 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
618 <input type='hidden' name='AREUSURE' value='yes' />
619 <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'}
623 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' />
624 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
631 & Header
:: closebigbox
();
632 & Header
:: closepage
();
636 ### Upload CA Certificate
638 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
639 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
641 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
642 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
646 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
647 $errormessage = $Lang :: tr
{ 'name too long' };
651 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
652 $errormessage = $Lang :: tr
{ 'name is invalid' };
653 goto UPLOAD_CA_ERROR
;
656 # Check if there is no other entry with this name
657 foreach my $key ( keys %cahash ) {
658 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
659 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
664 unless ( ref ( $cgiparams { 'FH' })) {
665 $errormessage = $Lang :: tr
{ 'there was no file upload' };
668 # Move uploaded ca to a temporary file
669 ( my $fh , my $filename ) = tempfile
( );
670 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
674 my $temp = `/usr/bin/openssl x509 -text -in $filename ` ;
675 if ( $temp !~ /CA:TRUE/i ) {
676 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
680 unless ( move
( $filename , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" )) {
681 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
687 my $key = & General
:: findhasharraykey
( \
%cahash );
688 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
689 $cahash { $key }[ 1 ] = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" ));
690 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
692 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'R' );
698 ### Display ca certificate
700 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
701 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
703 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
704 & Header
:: showhttpheaders
();
705 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
706 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
707 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'ca certificate'}:" );
708 my @output = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
709 my $output = & Header
:: cleanhtml
( join ( "" , @output ) , "y" );
710 print "<pre> $output </pre> \n " ;
712 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
713 & Header
:: closebigbox
();
714 & Header
:: closepage
();
717 $errormessage = $Lang :: tr
{ 'invalid key' };
721 ### Export ca certificate to browser
723 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
724 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
726 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
727 print "Content-Type: application/force-download \n " ;
728 print "Content-Type: application/octet-stream \r\n " ;
729 print "Content-Disposition: attachment; filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
731 my @cert = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-in" , "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
735 $errormessage = $Lang :: tr
{ 'invalid key' };
739 ### Remove ca certificate (step 2)
741 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
742 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
743 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
745 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
746 foreach my $key ( keys %confighash ) {
747 my @test = & General
:: system_output
( "/usr/bin/openssl" , "verify" , "-CAfile" , "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" , "${General::swroot}/certs/ $confighash { $key }[1]cert.pem" );
748 if ( grep ( /: OK/ , @test )) {
750 unlink ( "${General::swroot}/certs/ $confighash { $key }[1]cert.pem" );
751 unlink ( "${General::swroot}/certs/ $confighash { $key }[1].p12" );
752 delete $confighash { $key };
753 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
755 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'D' , $key ) if (& vpnenabled
);
758 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
759 delete $cahash { $cgiparams { 'KEY' }};
760 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
761 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'R' );
764 $errormessage = $Lang :: tr
{ 'invalid key' };
767 ### Remove ca certificate (step 1)
769 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
770 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
771 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
773 my $assignedcerts = 0 ;
774 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
775 foreach my $key ( keys %confighash ) {
776 my @test = & General
:: system_output
( "/usr/bin/openssl" , "verify" , "-CAfile" , "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" , "${General::swroot}/certs/ $confighash { $key }[1]cert.pem" );
777 if ( grep ( /: OK/ , @test )) {
781 if ( $assignedcerts ) {
782 & Header
:: showhttpheaders
();
783 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
784 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
785 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
787 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
791 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
792 <input type='hidden' name='AREUSURE' value='yes' /></td>
795 <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>
798 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
799 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
806 & Header
:: closebigbox
();
807 & Header
:: closepage
();
810 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
811 delete $cahash { $cgiparams { 'KEY' }};
812 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
813 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'R' );
817 $errormessage = $Lang :: tr
{ 'invalid key' };
821 ### Display root certificate
823 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
824 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
826 & Header
:: showhttpheaders
();
827 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
828 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
829 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
830 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'root certificate'}:" );
831 @output = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "${General::swroot}/ca/cacert.pem" );
833 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'host certificate'}:" );
834 @output = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "${General::swroot}/certs/hostcert.pem" );
836 my $output = & Header
:: cleanhtml
( join ( "" , @output ) , "y" );
837 print "<pre> $output </pre> \n " ;
839 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
840 & Header
:: closebigbox
();
841 & Header
:: closepage
();
845 ### Export root certificate to browser
847 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
848 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
849 print "Content-Type: application/force-download \n " ;
850 print "Content-Disposition: attachment; filename=cacert.pem \r\n\r\n " ;
852 my @cert = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-in" , "${General::swroot}/ca/cacert.pem" );
853 print join ( "" , @cert );
857 ### Export host certificate to browser
859 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
860 if ( - f
"${General::swroot}/certs/hostcert.pem" ) {
861 print "Content-Type: application/force-download \n " ;
862 print "Content-Disposition: attachment; filename=hostcert.pem \r\n\r\n " ;
864 my @cert = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-in" , "${General::swroot}/certs/hostcert.pem" );
865 print join ( "" , @cert );
869 ### Form for generating/importing the caroot+host certificate
871 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
872 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
874 & newcleanssldatabase
();
876 if (- f
"${General::swroot}/ca/cacert.pem" ) {
877 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
881 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
882 # fill in initial values
883 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
884 if (- e
"${General::swroot}/red/active" && open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
885 my $ipaddr = < IPADDR
>;
888 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
889 $cgiparams { 'SUBJECTALTNAME' } = "DNS:" . $cgiparams { 'ROOTCERT_HOSTNAME' };
890 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
891 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
892 $cgiparams { 'SUBJECTALTNAME' } = "IP:" . $cgiparams { 'ROOTCERT_HOSTNAME' };
895 $cgiparams { 'ROOTCERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' } if (! $cgiparams { 'ROOTCERT_COUNTRY' });
896 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
897 & General
:: log ( "ipsec" , "Importing from p12..." );
899 unless ( ref ( $cgiparams { 'FH' })) {
900 $errormessage = $Lang :: tr
{ 'there was no file upload' };
904 # Move uploaded certificate request to a temporary file
905 ( my $fh , my $filename ) = tempfile
( );
906 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
911 # Extract the CA certificate from the file
912 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
913 if ( open ( STDIN
, "-|" )) {
914 my $opt = " pkcs12 -legacy -cacerts -nokeys" ;
915 $opt .= " -in $filename " ;
916 $opt .= " -out /tmp/newcacert" ;
917 $errormessage = & callssl
( $opt );
919 print " $cgiparams {'P12_PASS'} \n " ;
923 # Extract the Host certificate from the file
924 if (! $errormessage ) {
925 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
926 if ( open ( STDIN
, "-|" )) {
927 my $opt = " pkcs12 -legacy -clcerts -nokeys" ;
928 $opt .= " -in $filename " ;
929 $opt .= " -out /tmp/newhostcert" ;
930 $errormessage = & callssl
( $opt );
932 print " $cgiparams {'P12_PASS'} \n " ;
937 # Extract the Host key from the file
938 if (! $errormessage ) {
939 & General
:: log ( "ipsec" , "Extracting private key from p12..." );
940 if ( open ( STDIN
, "-|" )) {
941 my $opt = " pkcs12 -legacy -nocerts -nodes" ;
942 $opt .= " -in $filename " ;
943 $opt .= " -out /tmp/newhostkey" ;
944 $errormessage = & callssl
( $opt );
946 print " $cgiparams {'P12_PASS'} \n " ;
951 if (! $errormessage ) {
952 & General
:: log ( "ipsec" , "Moving cacert..." );
953 unless ( move
( "/tmp/newcacert" , "${General::swroot}/ca/cacert.pem" )) {
954 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
958 if (! $errormessage ) {
959 & General
:: log ( "ipsec" , "Moving host cert..." );
960 unless ( move
( "/tmp/newhostcert" , "${General::swroot}/certs/hostcert.pem" )) {
961 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
965 if (! $errormessage ) {
966 & General
:: log ( "ipsec" , "Moving private key..." );
967 unless ( move
( "/tmp/newhostkey" , "${General::swroot}/certs/hostkey.pem" )) {
968 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
974 unlink ( '/tmp/newcacert' );
975 unlink ( '/tmp/newhostcert' );
976 unlink ( '/tmp/newhostkey' );
978 unlink ( "${General::swroot}/ca/cacert.pem" );
979 unlink ( "${General::swroot}/certs/hostcert.pem" );
980 unlink ( "${General::swroot}/certs/hostkey.pem" );
984 # Create empty CRL cannot be done because we don't have
985 # the private key for this CAROOT
986 # IPFire can only import certificates
988 & General
:: log ( "ipsec" , "p12 import completed!" );
990 goto ROOTCERT_SUCCESS
;
992 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
994 # Validate input since the form was submitted
995 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
996 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
999 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
1000 $errormessage = $Lang :: tr
{ 'organization too long' };
1001 goto ROOTCERT_ERROR
;
1003 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1004 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1005 goto ROOTCERT_ERROR
;
1007 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
1008 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
1009 goto ROOTCERT_ERROR
;
1011 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
1012 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
1013 goto ROOTCERT_ERROR
;
1015 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
1016 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1017 goto ROOTCERT_ERROR
;
1019 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
1020 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1021 goto ROOTCERT_ERROR
;
1023 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1024 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1025 goto ROOTCERT_ERROR
;
1027 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1028 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1029 goto ROOTCERT_ERROR
;
1031 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1032 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1033 goto ROOTCERT_ERROR
;
1035 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1036 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1037 goto ROOTCERT_ERROR
;
1039 #the exact syntax is a list comma separated of
1040 # email:any-validemail
1041 # URI: a uniform resource indicator
1042 # DNS: a DNS domain name
1043 # RID: a registered OBJECT IDENTIFIER
1045 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
1047 if ( $cgiparams { 'SUBJECTALTNAME' } eq '' ) {
1048 $errormessage = $Lang :: tr
{ 'vpn subjectaltname missing' };
1049 goto ROOTCERT_ERROR
;
1052 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
1053 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
1057 # Copy the cgisettings to vpnsettings and save the configfile
1058 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
1059 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
1060 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
1061 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
1062 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
1063 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
1064 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
1065 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1067 # Replace empty strings with a .
1068 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
1069 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
1070 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
1072 # Create the CA certificate
1073 if (! $errormessage ) {
1074 & General
:: log ( "ipsec" , "Creating cacert..." );
1075 if ( open ( STDIN
, "-|" )) {
1076 my $opt = " req -x509 -sha256 -nodes" ;
1077 $opt .= " -days 3650" ;
1078 $opt .= " -newkey rsa:4096" ;
1079 $opt .= " -keyout ${General::swroot}/private/cakey.pem" ;
1080 $opt .= " -out ${General::swroot}/ca/cacert.pem" ;
1082 $errormessage = & callssl
( $opt );
1084 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1087 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1089 print " $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
1090 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1095 # Create the Host certificate request
1096 if (! $errormessage ) {
1097 & General
:: log ( "ipsec" , "Creating host cert..." );
1098 if ( open ( STDIN
, "-|" )) {
1099 my $opt = " req -sha256 -nodes" ;
1100 $opt .= " -newkey rsa:4096" ;
1101 $opt .= " -keyout ${General::swroot}/certs/hostkey.pem" ;
1102 $opt .= " -out ${General::swroot}/certs/hostreq.pem" ;
1103 $errormessage = & callssl
( $opt );
1105 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1108 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1110 print " $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
1111 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1118 # Sign the host certificate request
1119 if (! $errormessage ) {
1120 & General
:: log ( "ipsec" , "Self signing host cert..." );
1122 #No easy way for specifying the contain of subjectAltName without writing a config file...
1123 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1125 basicConstraints=CA:FALSE
1126 nsComment="OpenSSL Generated Certificate"
1127 subjectKeyIdentifier=hash
1128 authorityKeyIdentifier=keyid,issuer:always
1129 extendedKeyUsage = serverAuth
1132 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1135 my $opt = " ca -md sha256 -days 825" ;
1136 $opt .= " -batch -notext" ;
1137 $opt .= " -in ${General::swroot}/certs/hostreq.pem" ;
1138 $opt .= " -out ${General::swroot}/certs/hostcert.pem" ;
1139 $opt .= " -extfile $v3extname " ;
1140 $errormessage = & callssl
( $opt );
1141 unlink ( "${General::swroot}/certs/hostreq.pem" ); #no more needed
1142 unlink ( $v3extname );
1145 # Create an empty CRL
1146 if (! $errormessage ) {
1147 & General
:: log ( "ipsec" , "Creating emptycrl..." );
1148 my $opt = " ca -gencrl" ;
1149 $opt .= " -out ${General::swroot}/crls/cacrl.pem" ;
1150 $errormessage = & callssl
( $opt );
1153 # Successfully build CA / CERT!
1154 if (! $errormessage ) {
1155 & cleanssldatabase
();
1156 goto ROOTCERT_SUCCESS
;
1160 unlink ( "${General::swroot}/ca/cacert.pem" );
1161 unlink ( "${General::swroot}/certs/hostkey.pem" );
1162 unlink ( "${General::swroot}/certs/hostcert.pem" );
1163 unlink ( "${General::swroot}/crls/cacrl.pem" );
1164 & cleanssldatabase
();
1168 & Header
:: showhttpheaders
();
1169 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1170 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1171 if ( $errormessage ) {
1172 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1173 print "<class name='base'> $errormessage " ;
1174 print " </class>" ;
1175 & Header
:: closebox
();
1177 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
1179 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
1180 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1181 <tr><td width='40%' class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
1182 <td width='60%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td></tr>
1183 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}: <img src='/blob.gif' alt='*' /></td>
1184 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td></tr>
1185 <tr><td class='base'> $Lang ::tr{'your e-mail'}:</td>
1186 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td></tr>
1187 <tr><td class='base'> $Lang ::tr{'your department'}:</td>
1188 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td></tr>
1189 <tr><td class='base'> $Lang ::tr{'city'}:</td>
1190 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td></tr>
1191 <tr><td class='base'> $Lang ::tr{'state or province'}:</td>
1192 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td></tr>
1193 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1194 <td class='base'><select name='ROOTCERT_COUNTRY'>
1197 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1198 print "<option value=' $Countries ::countries{ $country }'" ;
1199 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1200 print " selected='selected'" ;
1202 print "> $country </option>" ;
1206 <tr><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*) <img src='/blob.gif' alt='*' /></td>
1207 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' /></td></tr>
1209 <td><br /><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /><br /><br /></td></tr>
1210 <tr><td class='base' colspan='2' align='left'>
1211 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1212 $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'}
1214 <tr><td colspan='2'><hr></td></tr>
1215 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}:</td>
1216 <td nowrap='nowrap'><input type='file' name='FH' size='32' /></td></tr>
1217 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
1218 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td></tr>
1220 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td></tr>
1221 <tr><td class='base' colspan='2' align='left'>
1222 <img src='/blob.gif' alt='*' /> $Lang ::tr{'required field'}</td></tr>
1226 & Header
:: closebox
();
1227 & Header
:: closebigbox
();
1228 & Header
:: closepage
();
1233 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'S' );
1238 ### Export PKCS12 file to browser
1240 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
1241 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1242 print "Content-Type: application/force-download \n " ;
1243 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
1244 print "Content-Type: application/octet-stream \r\n\r\n " ;
1246 open ( FILE
, "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1249 print join ( "" , @p12 );
1253 # Export Apple profile to browser
1254 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download apple profile' }) {
1255 # Read global configuration
1256 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1259 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1260 my $key = $cgiparams { 'KEY' };
1262 # Create a UUID generator
1263 my $uuid = Data
:: UUID
-> new ();
1265 my $uuid1 = $uuid -> create_str ();
1266 my $uuid2 = $uuid -> create_str ();
1269 my $ca_uuid = $uuid -> create_str ();
1272 my $cert_uuid = $uuid -> create_str ();
1274 # Read and encode the CA & certificate
1275 if ( $confighash { $key }[ 4 ] eq "cert" ) {
1276 my $ca_path = "${General::swroot}/ca/cacert.pem" ;
1277 my $cert_path = "${General::swroot}/certs/ $confighash { $key }[1].p12" ;
1279 # Read the CA and encode it into Base64
1280 open ( CA
, "<${ca_path}" );
1281 local ($/) = undef ; # slurp
1282 $ca = MIME
:: Base64
:: encode_base64
(< CA
>);
1285 # Read certificate and encode it into Base64
1286 open ( CERT
, "<${cert_path}" );
1287 local ($/) = undef ; # slurp
1288 $cert = MIME
:: Base64
:: encode_base64
(< CERT
>);
1292 print "Content-Type: application/octet-stream \n " ;
1293 print "Content-Disposition: attachment; filename=" . $confighash { $key }[ 1 ] . ".mobileconfig \n " ;
1294 print " \n " ; # end headers
1296 # Use our own FQDN if nothing else is configured
1297 my $endpoint = ( $vpnsettings { 'RW_ENDPOINT' } ne "" ) ?
$vpnsettings { 'RW_ENDPOINT' } : & hostname
();
1299 print "<!DOCTYPE plist PUBLIC \" -//Apple//DTD PLIST 1.0//EN \" \" http://www.apple.com/DTDs/PropertyList-1.0.dtd \" > \n " ;
1300 print "<plist version= \" 1.0 \" > \n " ;
1302 print " <key>PayloadDisplayName</key> \n " ;
1303 print " <string> $confighash { $key }[1]</string> \n " ;
1304 print " <key>PayloadIdentifier</key> \n " ;
1305 print " <string> $confighash { $key }[1]</string> \n " ;
1306 print " <key>PayloadUUID</key> \n " ;
1307 print " <string>${uuid1}</string> \n " ;
1308 print " <key>PayloadType</key> \n " ;
1309 print " <string>Configuration</string> \n " ;
1310 print " <key>PayloadVersion</key> \n " ;
1311 print " <integer>1</integer> \n " ;
1312 print " <key>PayloadContent</key> \n " ;
1315 print " <key>PayloadIdentifier</key> \n " ;
1316 print " <string>org.example.vpn1.conf1</string> \n " ;
1317 print " <key>PayloadUUID</key> \n " ;
1318 print " <string>${uuid2}</string> \n " ;
1319 print " <key>PayloadType</key> \n " ;
1320 print " <string>com.apple.vpn.managed</string> \n " ;
1321 print " <key>PayloadVersion</key> \n " ;
1322 print " <integer>1</integer> \n " ;
1323 print " <key>UserDefinedName</key> \n " ;
1324 print " <string> $confighash { $key }[1]</string> \n " ;
1325 print " <key>VPNType</key> \n " ;
1326 print " <string>IKEv2</string> \n " ;
1327 print " <key>IKEv2</key> \n " ;
1329 print " <key>RemoteAddress</key> \n " ;
1330 print " <string> $endpoint </string> \n " ;
1333 my $pfs = $confighash { $key }[ 28 ];
1335 print " <key>EnablePFS</key> \n " ;
1340 print " <key>IKESecurityAssociationParameters</key> \n " ;
1344 foreach my $cipher ( split ( /\|/ , $confighash { $key }[ 18 ])) {
1345 # Skip all unsupported ciphers
1346 next unless ( exists $APPLE_CIPHERS { $cipher });
1348 print " <key>EncryptionAlgorithm</key> \n " ;
1349 print " <string> $APPLE_CIPHERS { $cipher }</string> \n " ;
1354 foreach my $integrity ( split ( /\|/ , $confighash { $key }[ 19 ])) {
1355 # Skip all unsupported algorithms
1356 next unless ( exists $APPLE_INTEGRITIES { $integrity });
1358 print " <key>IntegrityAlgorithm</key> \n " ;
1359 print " <string> $APPLE_INTEGRITIES { $integrity }</string> \n " ;
1363 # Diffie Hellman Groups
1364 foreach my $group ( split ( /\|/ , $confighash { $key }[ 20 ])) {
1365 # Skip all unsupported algorithms
1366 next unless ( exists $APPLE_DH_GROUPS { $group });
1368 print " <key>DiffieHellmanGroup</key> \n " ;
1369 print " <string> $APPLE_DH_GROUPS { $group }</string> \n " ;
1374 my $lifetime = $confighash { $key }[ 16 ] * 60 ;
1375 print " <key>LifeTimeInMinutes</key> \n " ;
1376 print " <integer> $lifetime </integer> \n " ;
1380 print " <key>ChildSecurityAssociationParameters</key> \n " ;
1384 foreach my $cipher ( split ( /\|/ , $confighash { $key }[ 21 ])) {
1385 # Skip all unsupported ciphers
1386 next unless ( exists $APPLE_CIPHERS { $cipher });
1388 print " <key>EncryptionAlgorithm</key> \n " ;
1389 print " <string> $APPLE_CIPHERS { $cipher }</string> \n " ;
1394 foreach my $integrity ( split ( /\|/ , $confighash { $key }[ 22 ])) {
1395 # Skip all unsupported algorithms
1396 next unless ( exists $APPLE_INTEGRITIES { $integrity });
1398 print " <key>IntegrityAlgorithm</key> \n " ;
1399 print " <string> $APPLE_INTEGRITIES { $integrity }</string> \n " ;
1403 # Diffie Hellman Groups
1404 foreach my $group ( split ( /\|/ , $confighash { $key }[ 23 ])) {
1405 # Skip all unsupported algorithms
1406 next unless ( exists $APPLE_DH_GROUPS { $group });
1408 print " <key>DiffieHellmanGroup</key> \n " ;
1409 print " <string> $APPLE_DH_GROUPS { $group }</string> \n " ;
1414 my $lifetime = $confighash { $key }[ 17 ] * 60 ;
1415 print " <key>LifeTimeInMinutes</key> \n " ;
1416 print " <integer> $lifetime </integer> \n " ;
1421 if ( $confighash { $key }[ 9 ]) {
1422 my $leftid = $confighash { $key }[ 9 ];
1424 # Strip leading @ from FQDNs
1425 if ( $leftid =~ m/^@(.*)$/ ) {
1429 print " <key>LocalIdentifier</key> \n " ;
1430 print " <string> $leftid </string> \n " ;
1434 if ( $confighash { $key }[ 7 ]) {
1435 my $rightid = $confighash { $key }[ 7 ];
1437 # Strip leading @ from FQDNs
1438 if ( $rightid =~ m/^@(.*)$/ ) {
1442 print " <key>RemoteIdentifier</key> \n " ;
1443 print " <string> $rightid </string> \n " ;
1446 if ( $confighash { $key }[ 4 ] eq "cert" ) {
1447 print " <key>AuthenticationMethod</key> \n " ;
1448 print " <string>Certificate</string> \n " ;
1450 print " <key>PayloadCertificateUUID</key> \n " ;
1451 print " <string>${cert_uuid}</string> \n " ;
1453 print " <key>AuthenticationMethod</key> \n " ;
1454 print " <string>SharedSecret</string> \n " ;
1455 print " <key>SharedSecret</key> \n " ;
1456 print " <string> $confighash { $key }[5]</string> \n " ;
1459 print " <key>ExtendedAuthEnabled</key> \n " ;
1460 print " <integer>0</integer> \n " ;
1462 # These are not needed, but we provide some default to stop iPhone asking for credentials
1463 print " <key>AuthName</key> \n " ;
1464 print " <string> $confighash { $key }[1]</string> \n " ;
1465 print " <key>AuthPassword</key> \n " ;
1466 print " <string></string> \n " ;
1470 if ( $confighash { $key }[ 4 ] eq "cert" ) {
1472 print " <key>PayloadIdentifier</key> \n " ;
1473 print " <string>org.example.vpn1.client</string> \n " ;
1474 print " <key>PayloadDisplayName</key> \n " ;
1475 print " <string> $confighash { $key }[1]</string> \n " ;
1476 print " <key>PayloadUUID</key> \n " ;
1477 print " <string>${cert_uuid}</string> \n " ;
1478 print " <key>PayloadType</key> \n " ;
1479 print " <string>com.apple.security.pkcs12</string> \n " ;
1480 print " <key>PayloadVersion</key> \n " ;
1481 print " <integer>1</integer> \n " ;
1482 print " <key>PayloadContent</key> \n " ;
1485 foreach ( split /\n/ ,${ cert
}) {
1493 print " <key>PayloadIdentifier</key> \n " ;
1494 print " <string>org.example.ca</string> \n " ;
1495 print " <key>PayloadUUID</key> \n " ;
1496 print " <string>${ca_uuid}</string> \n " ;
1497 print " <key>PayloadType</key> \n " ;
1498 print " <string>com.apple.security.root</string> \n " ;
1499 print " <key>PayloadVersion</key> \n " ;
1500 print " <integer>1</integer> \n " ;
1501 print " <key>PayloadContent</key> \n " ;
1504 foreach ( split /\n/ ,${ ca
}) {
1512 print " </array> \n " ;
1519 ### Display certificate
1521 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
1522 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1524 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1525 & Header
:: showhttpheaders
();
1526 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1527 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1528 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'cert'}:" );
1529 my @output = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1530 my $output = & Header
:: cleanhtml
( join ( "" , @output ) , "y" );
1531 print "<pre> $output </pre> \n " ;
1532 & Header
:: closebox
();
1533 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1534 & Header
:: closebigbox
();
1535 & Header
:: closepage
();
1540 ### Export Certificate to browser
1542 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
1543 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1545 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1546 print "Content-Type: application/force-download \n " ;
1547 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \n\n " ;
1549 open ( FILE
, "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1558 ### Enable/Disable connection
1560 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1562 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1563 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1565 if ( $confighash { $cgiparams { 'KEY' }}) {
1566 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
1567 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
1568 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1570 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1572 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
1573 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1575 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1579 $errormessage = $Lang :: tr
{ 'invalid key' };
1583 ### Restart connection
1585 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
1586 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1587 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1589 if ( $confighash { $cgiparams { 'KEY' }}) {
1591 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
1595 $errormessage = $Lang :: tr
{ 'invalid key' };
1599 ### Remove connection
1601 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
1602 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1603 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1605 if ( $confighash { $cgiparams { 'KEY' }}) {
1606 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1607 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1608 delete $confighash { $cgiparams { 'KEY' }};
1609 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1611 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1613 $errormessage = $Lang :: tr
{ 'invalid key' };
1615 & General
:: firewall_reload
();
1617 ### Choose between adding a host-net or net-net connection
1619 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
1620 & Header
:: showhttpheaders
();
1621 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1622 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1623 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection type' });
1625 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
1626 <b> $Lang ::tr{'connection type'}:</b><br />
1628 <tr><td><input type='radio' name='TYPE' value='host' checked='checked' /></td>
1629 <td class='base'> $Lang ::tr{'host to net vpn'}</td>
1631 <td><input type='radio' name='TYPE' value='net' /></td>
1632 <td class='base'> $Lang ::tr{'net to net vpn'}</td>
1634 <td align='center' colspan='2'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td>
1639 & Header
:: closebox
();
1640 & Header
:: closebigbox
();
1641 & Header
:: closepage
();
1644 ### Adding/Editing/Saving a connection
1646 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
1647 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
1648 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
1650 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1651 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1652 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1654 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
1655 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
1656 $errormessage = $Lang :: tr
{ 'invalid key' };
1659 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
1660 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
1661 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
1662 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
1663 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
1664 $cgiparams { 'LOCAL' } = $confighash { $cgiparams { 'KEY' }}[ 6 ];
1665 $cgiparams { 'LOCAL_ID' } = $confighash { $cgiparams { 'KEY' }}[ 7 ];
1666 my @local_subnets = split ( "," , $confighash { $cgiparams { 'KEY' }}[ 8 ]);
1667 $cgiparams { 'LOCAL_SUBNET' } = join ( /\|/ , @local_subnets );
1668 $cgiparams { 'REMOTE_ID' } = $confighash { $cgiparams { 'KEY' }}[ 9 ];
1669 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
1670 my @remote_subnets = split ( "," , $confighash { $cgiparams { 'KEY' }}[ 11 ]);
1671 $cgiparams { 'REMOTE_SUBNET' } = join ( /\|/ , @remote_subnets );
1672 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
1673 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
1674 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
1675 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
1676 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
1677 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
1678 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
1679 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
1680 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
1681 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
1682 if ( $cgiparams { 'ESP_GROUPTYPE' } eq "" ) {
1683 $cgiparams { 'ESP_GROUPTYPE' } = $cgiparams { 'IKE_GROUPTYPE' };
1685 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
1686 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
1687 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
1688 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
1689 $cgiparams { 'DPD_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
1690 $cgiparams { 'DPD_DELAY' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
1691 $cgiparams { 'FORCE_MOBIKE' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
1692 $cgiparams { 'START_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 33 ];
1693 $cgiparams { 'INACTIVITY_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 34 ];
1694 $cgiparams { 'MODE' } = $confighash { $cgiparams { 'KEY' }}[ 35 ];
1695 $cgiparams { 'INTERFACE_MODE' } = $confighash { $cgiparams { 'KEY' }}[ 36 ];
1696 $cgiparams { 'INTERFACE_ADDRESS' } = $confighash { $cgiparams { 'KEY' }}[ 37 ];
1697 $cgiparams { 'INTERFACE_MTU' } = $confighash { $cgiparams { 'KEY' }}[ 38 ];
1698 $cgiparams { 'DNS_SERVERS' } = $confighash { $cgiparams { 'KEY' }}[ 39 ];
1700 if (! $cgiparams { 'DPD_DELAY' }) {
1701 $cgiparams { 'DPD_DELAY' } = 30 ;
1704 if (! $cgiparams { 'DPD_TIMEOUT' }) {
1705 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
1708 if ( $cgiparams { 'INACTIVITY_TIMEOUT' } eq "" ) {
1709 $cgiparams { 'INACTIVITY_TIMEOUT' } = 900 ;
1712 if ( $cgiparams { 'MODE' } eq "" ) {
1713 $cgiparams { 'MODE' } = "tunnel" ;
1716 if ( $cgiparams { 'INTERFACE_MTU' } eq "" ) {
1717 $cgiparams { 'INTERFACE_MTU' } = 1500 ;
1720 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
1721 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
1722 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
1723 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
1727 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
1728 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
1732 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
1733 $errormessage = $Lang :: tr
{ 'name is invalid' };
1737 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
1738 $errormessage = $Lang :: tr
{ 'name too long' };
1742 # Check if there is no other entry with this name
1743 if (! $cgiparams { 'KEY' }) { #only for add
1744 foreach my $key ( keys %confighash ) {
1745 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
1746 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
1752 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! $cgiparams { 'REMOTE' })) {
1753 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1757 if ( $cgiparams { 'LOCAL' }) {
1758 if (( $cgiparams { 'LOCAL' } ne "" ) && (!& General
:: validip
( $cgiparams { 'LOCAL' }))) {
1759 $errormessage = $Lang :: tr
{ 'invalid input for local ip address' };
1764 if ( $cgiparams { 'REMOTE' }) {
1765 if (( $cgiparams { 'REMOTE' } ne ' %any ' ) && (! & General
:: validip
( $cgiparams { 'REMOTE' }))) {
1766 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
1767 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1770 if (& valid_dns_host
( $cgiparams { 'REMOTE' })) {
1771 $warnmessage = " $Lang ::tr{'check vpn lr'} $cgiparams {'REMOTE'}. $Lang ::tr{'dns check failed'}" ;
1777 my @local_subnets = split ( "," , $cgiparams { 'LOCAL_SUBNET' });
1778 foreach my $subnet ( @local_subnets ) {
1779 unless (& Network
:: check_subnet
( $subnet )) {
1780 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
1785 # Allow only one roadwarrior/psk without remote IP-address
1786 if ( $cgiparams { 'REMOTE' } eq '' && $cgiparams { 'AUTH' } eq 'psk' ) {
1787 foreach my $key ( keys %confighash ) {
1788 if ( ( $cgiparams { 'KEY' } ne $key ) &&
1789 ( $confighash { $key }[ 4 ] eq 'psk' ) &&
1790 ( $confighash { $key }[ 10 ] eq '' ) ) {
1791 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
1797 if ( $cgiparams { 'TYPE' } eq 'net' ) {
1798 my @remote_subnets = split ( "," , $cgiparams { 'REMOTE_SUBNET' });
1799 foreach my $subnet ( @remote_subnets ) {
1800 unless (& Network
:: check_subnet
( $subnet )) {
1801 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
1806 if ( $cgiparams { 'MODE' } !~ /^(tunnel|transport)$/ ) {
1807 $errormessage = $Lang :: tr
{ 'invalid input for mode' };
1811 if ( $cgiparams { 'INTERFACE_MODE' } !~ /^(|gre|vti)$/ ) {
1812 $errormessage = $Lang :: tr
{ 'invalid input for interface mode' };
1816 if (( $cgiparams { 'INTERFACE_MODE' } eq "vti" ) && ( $cgiparams { 'MODE' } eq "transport" )) {
1817 $errormessage = $Lang :: tr
{ 'transport mode does not support vti' };
1821 if (( $cgiparams { 'INTERFACE_MODE' } ne "" ) && !& Network
:: check_subnet
( $cgiparams { 'INTERFACE_ADDRESS' })) {
1822 $errormessage = $Lang :: tr
{ 'invalid input for interface address' };
1826 if ( $cgiparams { 'INTERFACE_MTU' } !~ /^\d+$/ ) {
1827 $errormessage = $Lang :: tr
{ 'invalid input for interface mtu' };
1832 if ( $cgiparams { 'TYPE' } eq 'host' ) {
1833 my @servers = split ( "," , $cgiparams { 'DNS_SERVERS' });
1834 foreach my $server ( @servers ) {
1835 unless (& Network
:: check_ip_address
( $server )) {
1836 $errormessage = $Lang :: tr
{ 'ipsec dns server address is invalid' };
1842 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
1843 $errormessage = $Lang :: tr
{ 'invalid input' };
1846 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
1847 $errormessage = $Lang :: tr
{ 'invalid input' };
1851 # Allow nothing or a string (DN,FDQN,) beginning with @
1852 # with no comma but slashes between RID eg @O=FR/C=Paris/OU=myhome/CN=franck
1853 if ( ( $cgiparams { 'LOCAL_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1854 ( $cgiparams { 'REMOTE_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1855 (( $cgiparams { 'REMOTE_ID' } eq $cgiparams { 'LOCAL_ID' }) && ( $cgiparams { 'LOCAL_ID' } ne '' ))
1857 $errormessage = $Lang :: tr
{ 'invalid local-remote id' } . '<br />' .
1858 'DER_ASN1_DN: @c =FR/ou=Paris/ou=Home/cn=*<br />' .
1859 'FQDN: @ipfire .org<br />' .
1860 'USER_FQDN: info @ipfire .org<br />' .
1861 'IPV4_ADDR: 123.123.123.123' ;
1864 # If Auth is DN, verify existance of Remote ID.
1865 if ( $cgiparams { 'REMOTE_ID' } eq '' && (
1866 $cgiparams { 'AUTH' } eq 'auth-dn' || # while creation
1867 $confighash { $cgiparams { 'KEY' }}[ 2 ] eq ' %auth -dn' )){ # while editing
1868 $errormessage = $Lang :: tr
{ 'vpn missing remote id' };
1872 if ( $cgiparams { 'TYPE' } eq 'net' ){
1873 $warnmessage =& General
:: checksubnets
( '' , $cgiparams { 'REMOTE_SUBNET' }, 'ipsec' );
1874 if ( $warnmessage ne '' ){
1875 $warnmessage = $Lang :: tr
{ 'remote subnet' }. " ( $cgiparams {'REMOTE_SUBNET'}) <br>" . $warnmessage ;
1879 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1880 if (! length ( $cgiparams { 'PSK' }) ) {
1881 $errormessage = $Lang :: tr
{ 'pre-shared key is too short' };
1884 if ( $cgiparams { 'PSK' } =~ /'/ ) {
1885 $cgiparams { 'PSK' } =~ tr/'/ / ;
1886 $errormessage = $Lang :: tr
{ 'invalid characters found in pre-shared key' };
1889 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
1890 if ( $cgiparams { 'KEY' }) {
1891 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1894 unless ( ref ( $cgiparams { 'FH' })) {
1895 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1899 # Move uploaded certificate request to a temporary file
1900 ( my $fh , my $filename ) = tempfile
( );
1901 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1906 # Sign the certificate request
1907 & General
:: log ( "ipsec" , "Signing your cert $cgiparams {'NAME'}..." );
1908 my $opt = " ca -md sha256 -days 825" ;
1909 $opt .= " -batch -notext" ;
1910 $opt .= " -in $filename " ;
1911 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1913 if ( $errormessage = & callssl
( $opt ) ) {
1915 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1916 & cleanssldatabase
();
1920 & cleanssldatabase
();
1923 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1924 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1925 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1928 } elsif ( $cgiparams { 'AUTH' } eq 'pkcs12' ) {
1929 & General
:: log ( "ipsec" , "Importing from p12..." );
1931 unless ( ref ( $cgiparams { 'FH' })) {
1932 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1933 goto ROOTCERT_ERROR
;
1936 # Move uploaded certificate request to a temporary file
1937 ( my $fh , my $filename ) = tempfile
( );
1938 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1940 goto ROOTCERT_ERROR
;
1943 # Extract the CA certificate from the file
1944 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
1945 if ( open ( STDIN
, "-|" )) {
1946 my $opt = " pkcs12 -legacy -cacerts -nokeys" ;
1947 $opt .= " -in $filename " ;
1948 $opt .= " -out /tmp/newcacert" ;
1949 $errormessage = & callssl
( $opt );
1951 print " $cgiparams {'P12_PASS'} \n " ;
1955 # Extract the Host certificate from the file
1956 if (! $errormessage ) {
1957 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
1958 if ( open ( STDIN
, "-|" )) {
1959 my $opt = " pkcs12 -legacy -clcerts -nokeys" ;
1960 $opt .= " -in $filename " ;
1961 $opt .= " -out /tmp/newhostcert" ;
1962 $errormessage = & callssl
( $opt );
1964 print " $cgiparams {'P12_PASS'} \n " ;
1969 if (! $errormessage ) {
1970 & General
:: log ( "ipsec" , "Moving cacert..." );
1971 #If CA have new subject, add it to our list of CA
1972 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( '/tmp/newcacert' ));
1974 foreach my $x ( keys %cahash ) {
1975 $casubject = '' if ( $cahash { $x }[ 1 ] eq $casubject );
1976 unshift ( @names , $cahash { $x }[ 0 ]);
1978 if ( $casubject ) { # a new one!
1979 my @temp = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "/tmp/newcacert" );
1980 if (! grep ( /CA:TRUE/ , @temp )) {
1981 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
1983 #compute a name for it
1985 while ( grep ( /Imported-$idx/ , @names ) ) { $idx ++};
1986 $cgiparams { 'CA_NAME' }= "Imported- $idx " ;
1987 $cgiparams { 'CERT_NAME' }=& Header
:: cleanhtml
( getCNfromcert
( '/tmp/newhostcert' ));
1989 unless ( move
( "/tmp/newcacert" , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" )) {
1990 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1993 if (! $errormessage ) {
1994 my $key = & General
:: findhasharraykey
( \
%cahash );
1995 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
1996 $cahash { $key }[ 1 ] = $casubject ;
1997 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1998 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'R' );
2003 if (! $errormessage ) {
2004 & General
:: log ( "ipsec" , "Moving host cert..." );
2005 unless ( move
( "/tmp/newhostcert" , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" )) {
2006 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
2012 unlink ( '/tmp/newcacert' );
2013 unlink ( '/tmp/newhostcert' );
2014 if ( $errormessage ) {
2015 unlink ( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
2016 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
2019 & General
:: log ( "ipsec" , "p12 import completed!" );
2020 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
2021 if ( $cgiparams { 'KEY' }) {
2022 $errormessage = $Lang :: tr
{ 'cant change certificates' };
2025 unless ( ref ( $cgiparams { 'FH' })) {
2026 $errormessage = $Lang :: tr
{ 'there was no file upload' };
2029 # Move uploaded certificate to a temporary file
2030 ( my $fh , my $filename ) = tempfile
( );
2031 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
2036 # Verify the certificate has a valid CA and move it
2037 & General
:: log ( "ipsec" , "Validating imported cert against our known CA..." );
2038 my $validca = 1 ; #assume ok
2039 my @test = & General
:: system_output
( "/usr/bin/openssl" , "verify" , "-CAfile" , "${General::swroot}/ca/cacert.pem" , " $filename " );
2040 if (! grep ( /: OK/ , @test )) {
2042 foreach my $key ( keys %cahash ) {
2043 @test = & General
:: system_output
( "/usr/bin/openssl" , "verify" , "-CAfile" , "${General::swroot}/ca/ $cahash { $key }[0]cert.pem" , " $filename " );
2044 if ( grep ( /: OK/ , @test )) {
2051 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
2055 unless ( move
( $filename , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" )) {
2056 $errormessage = " $Lang ::tr{'certificate file move failed'} ( $filename ): $!" ;
2062 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
2063 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
2064 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
2065 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
2068 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
2069 if ( $cgiparams { 'KEY' }) {
2070 $errormessage = $Lang :: tr
{ 'cant change certificates' };
2073 # Validate input since the form was submitted
2074 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
2075 $errormessage = $Lang :: tr
{ 'name too long' };
2078 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
2079 $errormessage = $Lang :: tr
{ 'invalid input for name' };
2082 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
2083 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
2086 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
2087 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
2090 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
2091 $errormessage = $Lang :: tr
{ 'invalid input for department' };
2094 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
2095 $errormessage = $Lang :: tr
{ 'organization too long' };
2098 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
2099 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
2102 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
2103 $errormessage = $Lang :: tr
{ 'invalid input for city' };
2106 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
2107 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
2110 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
2111 $errormessage = $Lang :: tr
{ 'invalid input for country' };
2114 #the exact syntax is a list comma separated of
2115 # email:any-validemail
2116 # URI: a uniform resource indicator
2117 # DNS: a DNS domain name
2118 # RID: a registered OBJECT IDENTIFIER
2120 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
2122 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
2123 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
2127 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
2128 $errormessage = $Lang :: tr
{ 'password too short' };
2131 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
2132 $errormessage = $Lang :: tr
{ 'passwords do not match' };
2136 # Replace empty strings with a .
2137 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
2138 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
2139 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
2141 # Create the Client certificate request
2142 & General
:: log ( "ipsec" , "Creating a cert..." );
2144 if ( open ( STDIN
, "-|" )) {
2145 my $opt = " req -nodes" ;
2146 $opt .= " -newkey rsa:4096" ;
2147 $opt .= " -keyout ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
2148 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
2150 if ( $errormessage = & callssl
( $opt ) ) {
2151 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
2152 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
2156 print " $cgiparams {'CERT_COUNTRY'} \n " ;
2159 print " $cgiparams {'CERT_ORGANIZATION'} \n " ;
2161 print " $cgiparams {'CERT_NAME'} \n " ;
2162 print " $cgiparams {'CERT_EMAIL'} \n " ;
2168 # Sign the client certificate request
2169 & General
:: log ( "ipsec" , "Signing the cert $cgiparams {'NAME'}..." );
2171 #No easy way for specifying the contain of subjectAltName without writing a config file...
2172 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
2174 basicConstraints=CA:FALSE
2175 nsComment="OpenSSL Generated Certificate"
2176 subjectKeyIdentifier=hash
2177 extendedKeyUsage=clientAuth
2178 authorityKeyIdentifier=keyid,issuer:always
2181 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
2184 my $opt = " ca -md sha256 -days 825 -batch -notext" ;
2185 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
2186 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
2187 $opt .= " -extfile $v3extname " ;
2189 if ( $errormessage = & callssl
( $opt ) ) {
2190 unlink ( $v3extname );
2191 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
2192 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
2193 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
2194 & cleanssldatabase
();
2197 unlink ( $v3extname );
2198 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
2199 & cleanssldatabase
();
2202 # Create the pkcs12 file
2203 & General
:: log ( "ipsec" , "Packing a pkcs12 file..." );
2204 $opt = " pkcs12 -legacy -export" ;
2205 $opt .= " -inkey ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
2206 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
2207 $opt .= " -name \" $cgiparams {'NAME'} \" " ;
2208 $opt .= " -passout pass: $cgiparams {'CERT_PASS1'}" ;
2209 $opt .= " -certfile ${General::swroot}/ca/cacert.pem" ;
2210 $opt .= " -caname \" $vpnsettings {'ROOTCERT_ORGANIZATION'} CA \" " ;
2211 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}.p12" ;
2213 if ( $errormessage = & callssl
( $opt ) ) {
2214 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
2215 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
2216 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}.p12" );
2219 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
2221 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
2222 ; # Nothing, just editing
2223 } elsif ( $cgiparams { 'AUTH' } eq 'auth-dn' ) {
2224 $cgiparams { 'CERT_NAME' } = ' %auth -dn' ; # a special value saying 'no cert file'
2226 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
2230 # 1)Error message here is not accurate.
2231 # 2)Test is superfluous, openswan can reference same cert multiple times
2232 # 3)Present since initial version (1.3.2.11), it isn't a bug correction
2233 # Check if there is no other entry with this certificate name
2234 #if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk') && ($cgiparams{'AUTH'} ne 'auth-dn')) {
2235 # foreach my $key (keys %confighash) {
2236 # if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) {
2237 # $errormessage = $Lang::tr{'a connection with this common name already exists'};
2238 # goto VPNCONF_ERROR;
2244 my $key = $cgiparams { 'KEY' };
2246 $key = & General
:: findhasharraykey
( \
%confighash );
2247 foreach my $i ( 0 .. 39 ) { $confighash { $key }[ $i ] = "" ;}
2249 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
2250 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
2251 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
2252 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
2254 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
2255 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
2256 $confighash { $key }[ 4 ] = 'psk' ;
2257 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
2259 $confighash { $key }[ 4 ] = 'cert' ;
2261 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2262 my @remote_subnets = split ( "," , $cgiparams { 'REMOTE_SUBNET' });
2263 $confighash { $key }[ 11 ] = join ( '|' , @remote_subnets );
2265 $confighash { $key }[ 6 ] = $cgiparams { 'LOCAL' };
2266 $confighash { $key }[ 7 ] = $cgiparams { 'LOCAL_ID' };
2267 my @local_subnets = split ( "," , $cgiparams { 'LOCAL_SUBNET' });
2268 $confighash { $key }[ 8 ] = join ( '|' , @local_subnets );
2269 $confighash { $key }[ 9 ] = $cgiparams { 'REMOTE_ID' };
2270 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
2271 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
2272 $confighash { $key }[ 26 ] = "" ; # Formerly INTERFACE
2273 $confighash { $key }[ 27 ] = $cgiparams { 'DPD_ACTION' };
2274 $confighash { $key }[ 29 ] = $cgiparams { 'IKE_VERSION' };
2276 # don't forget advanced value
2277 $confighash { $key }[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
2278 $confighash { $key }[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
2279 $confighash { $key }[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
2280 $confighash { $key }[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
2281 $confighash { $key }[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
2282 $confighash { $key }[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
2283 $confighash { $key }[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
2284 $confighash { $key }[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
2285 $confighash { $key }[ 12 ] = 'off' ; # $cgiparams{'AGGRMODE'};
2286 $confighash { $key }[ 13 ] = $cgiparams { 'COMPRESSION' };
2287 $confighash { $key }[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
2288 $confighash { $key }[ 28 ] = $cgiparams { 'PFS' };
2289 $confighash { $key }[ 30 ] = $cgiparams { 'DPD_TIMEOUT' };
2290 $confighash { $key }[ 31 ] = $cgiparams { 'DPD_DELAY' };
2291 $confighash { $key }[ 32 ] = $cgiparams { 'FORCE_MOBIKE' };
2292 $confighash { $key }[ 33 ] = $cgiparams { 'START_ACTION' };
2293 $confighash { $key }[ 34 ] = $cgiparams { 'INACTIVITY_TIMEOUT' };
2294 $confighash { $key }[ 35 ] = $cgiparams { 'MODE' };
2295 $confighash { $key }[ 36 ] = $cgiparams { 'INTERFACE_MODE' };
2296 $confighash { $key }[ 37 ] = $cgiparams { 'INTERFACE_ADDRESS' };
2297 $confighash { $key }[ 38 ] = $cgiparams { 'INTERFACE_MTU' };
2298 $confighash { $key }[ 39 ] = join ( "|" , split ( "," , $cgiparams { 'DNS_SERVERS' }));
2300 # free unused fields!
2301 $confighash { $key }[ 15 ] = 'off' ;
2303 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2306 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'S' , $key );
2309 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
2310 $cgiparams { 'KEY' } = $key ;
2311 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
2314 } else { # add new connection
2315 $cgiparams { 'ENABLED' } = 'on' ;
2316 if ( ! - f
"${General::swroot}/private/cakey.pem" ) {
2317 $cgiparams { 'AUTH' } = 'psk' ;
2318 } elsif ( ! - f
"${General::swroot}/ca/cacert.pem" ) {
2319 $cgiparams { 'AUTH' } = 'certfile' ;
2321 $cgiparams { 'AUTH' } = 'certgen' ;
2324 if ( $netsettings { "GREEN_NETADDRESS" } && $netsettings { "GREEN_NETMASK" }) {
2325 $cgiparams { "LOCAL_SUBNET" } = $netsettings { 'GREEN_NETADDRESS' } . "/" . $netsettings { 'GREEN_NETMASK' };
2327 $cgiparams { "LOCAL_SUBNET" } = "" ;
2329 $cgiparams { 'CERT_EMAIL' } = $vpnsettings { 'ROOTCERT_EMAIL' };
2330 $cgiparams { 'CERT_OU' } = $vpnsettings { 'ROOTCERT_OU' };
2331 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
2332 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
2333 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
2334 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
2336 # choose appropriate dpd action
2337 if ( $cgiparams { 'TYPE' } eq 'host' ) {
2338 $cgiparams { 'DPD_ACTION' } = 'clear' ;
2340 $cgiparams { 'DPD_ACTION' } = 'restart' ;
2343 if (! $cgiparams { 'DPD_DELAY' }) {
2344 $cgiparams { 'DPD_DELAY' } = 30 ;
2347 if (! $cgiparams { 'DPD_TIMEOUT' }) {
2348 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
2351 if (! $cgiparams { 'FORCE_MOBIKE' }) {
2352 $cgiparams { 'FORCE_MOBIKE' } = 'no' ;
2355 # Default IKE Version to v2
2356 if (! $cgiparams { 'IKE_VERSION' }) {
2357 $cgiparams { 'IKE_VERSION' } = 'ikev2' ;
2361 $cgiparams { 'LOCAL_ID' } = '' ;
2362 $cgiparams { 'REMOTE_ID' } = '' ;
2364 #use default advanced value
2365 $cgiparams { 'IKE_ENCRYPTION' } = 'chacha20poly1305|aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128' ; #[18];
2366 $cgiparams { 'IKE_INTEGRITY' } = 'sha2_512|sha2_256' ; #[19];
2367 $cgiparams { 'IKE_GROUPTYPE' } = 'curve448|curve25519|e521|e384|4096|3072' ; #[20];
2368 $cgiparams { 'IKE_LIFETIME' } = '3' ; #[16];
2369 $cgiparams { 'ESP_ENCRYPTION' } = 'chacha20poly1305|aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128' ; #[21];
2370 $cgiparams { 'ESP_INTEGRITY' } = 'sha2_512|sha2_256' ; #[22];
2371 $cgiparams { 'ESP_GROUPTYPE' } = 'curve448|curve25519|e521|e384|4096|3072' ; #[23];
2372 $cgiparams { 'ESP_KEYLIFE' } = '1' ; #[17];
2373 $cgiparams { 'COMPRESSION' } = 'off' ; #[13];
2374 $cgiparams { 'ONLY_PROPOSED' } = 'on' ; #[24];
2375 $cgiparams { 'PFS' } = 'on' ; #[28];
2376 $cgiparams { 'INACTIVITY_TIMEOUT' } = 900 ;
2377 $cgiparams { 'MODE' } = "tunnel" ;
2378 $cgiparams { 'INTERFACE_MODE' } = "" ;
2379 $cgiparams { 'INTERFACE_ADDRESS' } = "" ;
2380 $cgiparams { 'INTERFACE_MTU' } = 1500 ;
2381 $cgiparams { 'DNS_SERVERS' } = "" ;
2385 $checked { 'ENABLED' }{ 'off' } = '' ;
2386 $checked { 'ENABLED' }{ 'on' } = '' ;
2387 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = "checked='checked'" ;
2389 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
2390 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
2391 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = "checked='checked'" ;
2393 $checked { 'AUTH' }{ 'psk' } = '' ;
2394 $checked { 'AUTH' }{ 'certreq' } = '' ;
2395 $checked { 'AUTH' }{ 'certgen' } = '' ;
2396 $checked { 'AUTH' }{ 'certfile' } = '' ;
2397 $checked { 'AUTH' }{ 'pkcs12' } = '' ;
2398 $checked { 'AUTH' }{ 'auth-dn' } = '' ;
2399 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = "checked='checked'" ;
2401 $selected { 'MODE' }{ 'tunnel' } = '' ;
2402 $selected { 'MODE' }{ 'transport' } = '' ;
2403 $selected { 'MODE' }{ $cgiparams { 'MODE' }} = "selected='selected'" ;
2405 $selected { 'INTERFACE_MODE' }{ '' } = '' ;
2406 $selected { 'INTERFACE_MODE' }{ 'gre' } = '' ;
2407 $selected { 'INTERFACE_MODE' }{ 'vti' } = '' ;
2408 $selected { 'INTERFACE_MODE' }{ $cgiparams { 'INTERFACE_MODE' }} = "selected='selected'" ;
2410 $selected { 'LOCAL' }{ '' } = '' ;
2411 foreach my $alias ( sort keys %aliases ) {
2412 my $address = $aliases { $alias }{ 'IPT' };
2414 $selected { 'LOCAL' }{ $address } = '' ;
2416 $selected { 'LOCAL' }{ $cgiparams { 'LOCAL' }} = "selected='selected'" ;
2418 & Header
:: showhttpheaders
();
2419 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
2420 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2421 if ( $errormessage ) {
2422 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2423 print "<class name='base'> $errormessage " ;
2424 print " </class>" ;
2425 & Header
:: closebox
();
2429 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'warning messages'}:" );
2430 print "<class name='base'> $warnmessage " ;
2431 print " </class>" ;
2432 & Header
:: closebox
();
2435 print "<form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>" ;
2437 <input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />
2438 <input type='hidden' name='IKE_VERSION' value=' $cgiparams {'IKE_VERSION'}' />
2439 <input type='hidden' name='IKE_ENCRYPTION' value=' $cgiparams {'IKE_ENCRYPTION'}' />
2440 <input type='hidden' name='IKE_INTEGRITY' value=' $cgiparams {'IKE_INTEGRITY'}' />
2441 <input type='hidden' name='IKE_GROUPTYPE' value=' $cgiparams {'IKE_GROUPTYPE'}' />
2442 <input type='hidden' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' />
2443 <input type='hidden' name='ESP_ENCRYPTION' value=' $cgiparams {'ESP_ENCRYPTION'}' />
2444 <input type='hidden' name='ESP_INTEGRITY' value=' $cgiparams {'ESP_INTEGRITY'}' />
2445 <input type='hidden' name='ESP_GROUPTYPE' value=' $cgiparams {'ESP_GROUPTYPE'}' />
2446 <input type='hidden' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' />
2447 <input type='hidden' name='COMPRESSION' value=' $cgiparams {'COMPRESSION'}' />
2448 <input type='hidden' name='ONLY_PROPOSED' value=' $cgiparams {'ONLY_PROPOSED'}' />
2449 <input type='hidden' name='PFS' value=' $cgiparams {'PFS'}' />
2450 <input type='hidden' name='DPD_ACTION' value=' $cgiparams {'DPD_ACTION'}' />
2451 <input type='hidden' name='DPD_DELAY' value=' $cgiparams {'DPD_DELAY'}' />
2452 <input type='hidden' name='DPD_TIMEOUT' value=' $cgiparams {'DPD_TIMEOUT'}' />
2453 <input type='hidden' name='FORCE_MOBIKE' value=' $cgiparams {'FORCE_MOBIKE'}' />
2454 <input type='hidden' name='START_ACTION' value=' $cgiparams {'START_ACTION'}' />
2455 <input type='hidden' name='INACTIVITY_TIMEOUT' value=' $cgiparams {'INACTIVITY_TIMEOUT'}' />
2458 if ( $cgiparams { 'KEY' }) {
2459 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
2460 print "<input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' />" ;
2461 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
2464 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'connection'}: $cgiparams {'NAME'}" );
2465 print "<table width='100%'>" ;
2466 if (! $cgiparams { 'KEY' }) {
2469 <td width='20%'> $Lang ::tr{'name'}: <img src='/blob.gif' alt='*' /></td>
2471 <input type='text' name='NAME' value=' $cgiparams {'NAME'}' size='25' />
2473 <td colspan="2"></td>
2479 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2480 $blob = "<img src='/blob.gif' alt='*' />" ;
2483 my @local_subnets = split ( /\|/ , $cgiparams { 'LOCAL_SUBNET' });
2484 my $local_subnets = join ( "," , @local_subnets );
2486 my @remote_subnets = split ( /\|/ , $cgiparams { 'REMOTE_SUBNET' });
2487 my $remote_subnets = join ( "," , @remote_subnets );
2489 my @dns_servers = split ( /\|/ , $cgiparams { 'DNS_SERVERS' });
2490 my $dns_servers = join ( "," , @dns_servers );
2494 <td width='20%'> $Lang ::tr{'enabled'}</td>
2496 <input type='checkbox' name='ENABLED' $checked {'ENABLED'}{'on'} />
2498 <td colspan="2"></td>
2501 <td class='boldbase' width='20%'> $Lang ::tr{'local ip address'}:</td>
2503 <select name="LOCAL">
2504 <option value="" $selected {'LOCAL'}{''}>- $Lang ::tr{'default IP address'} -</option>
2507 foreach my $alias ( sort keys %aliases ) {
2508 my $address = $aliases { $alias }{ 'IPT' };
2510 <option value=" $address " $selected {'LOCAL'}{ $address }> $alias ( $address )</option>
2517 <td class='boldbase' width='20%'> $Lang ::tr{'remote host/ip'}: $blob </td>
2519 <input type='text' name='REMOTE' value=' $cgiparams {'REMOTE'}' size="25" />
2523 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'local subnet'} <img src='/blob.gif' alt='*' /></td>
2525 <input type='text' name='LOCAL_SUBNET' value=' $local_subnets ' size="25" />
2529 if ( $cgiparams { 'TYPE' } eq "net" ) {
2531 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'remote subnet'} <img src='/blob.gif' alt='*' /></td>
2533 <input type='text' name='REMOTE_SUBNET' value=' $remote_subnets ' size="25" />
2537 } elsif ( $cgiparams { 'TYPE' } eq "host" ) {
2539 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'dns servers'}:</td>
2541 <input type='text' name='DNS_SERVERS' value=' $dns_servers ' size="25" />
2549 <td class='boldbase' width='20%'> $Lang ::tr{'vpn local id'}:</td>
2551 <input type='text' name='LOCAL_ID' value=' $cgiparams {'LOCAL_ID'}' size="25" />
2553 <td class='boldbase' width='20%'> $Lang ::tr{'vpn remote id'}:</td>
2555 <input type='text' name='REMOTE_ID' value=' $cgiparams {'REMOTE_ID'}' size="25" />
2558 <tr><td colspan="4"><br /></td></tr>
2560 <td class='boldbase' width='20%'> $Lang ::tr{'remark title'}</td>
2562 <input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' maxlength='50' size="73" />
2567 if (! $cgiparams { 'KEY' }) {
2568 print "<tr><td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked {'EDIT_ADVANCED'}{'on'} /> $Lang ::tr{'edit advanced settings when done'}</td></tr>" ;
2571 & Header
:: closebox
();
2573 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2574 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'ipsec settings' });
2576 <table width='100%'>
2579 <td class='boldbase' width='20%'> $Lang ::tr{'mode'}:</td>
2581 <select name='MODE'>
2582 <option value='tunnel' $selected {'MODE'}{'tunnel'}> $Lang ::tr{'ipsec mode tunnel'}</option>
2583 <option value='transport' $selected {'MODE'}{'transport'}> $Lang ::tr{'ipsec mode transport'}</option>
2586 <td colspan='2'></td>
2590 <td class='boldbase' width='20%'> $Lang ::tr{'interface mode'}:</td>
2592 <select name='INTERFACE_MODE'>
2593 <option value='' $selected {'INTERFACE_MODE'}{''}> $Lang ::tr{'ipsec interface mode none'}</option>
2594 <option value='gre' $selected {'INTERFACE_MODE'}{'gre'}> $Lang ::tr{'ipsec interface mode gre'}</option>
2595 <option value='vti' $selected {'INTERFACE_MODE'}{'vti'}> $Lang ::tr{'ipsec interface mode vti'}</option>
2599 <td class='boldbase' width='20%'> $Lang ::tr{'ip address'}/ $Lang ::tr{'subnet mask'}:</td>
2601 <input type="text" name="INTERFACE_ADDRESS" value=" $cgiparams {'INTERFACE_ADDRESS'}">
2606 <td class='boldbase' width='20%'> $Lang ::tr{'mtu'}:</td>
2608 <input type="number" name="INTERFACE_MTU" value=" $cgiparams {'INTERFACE_MTU'}" min="576" max="9000">
2610 <td colspan='2'></td>
2615 & Header
:: closebox
();
2618 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
2619 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2621 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2622 <tr><td class='base' width='50%'> $Lang ::tr{'use a pre-shared key'}</td>
2623 <td class='base' width='50%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td>
2628 & Header
:: closebox
();
2629 } elsif (! $cgiparams { 'KEY' }) {
2630 my $cakeydisabled = ( ! - f
"${General::swroot}/private/cakey.pem" ) ?
"disabled='disabled'" : '' ;
2631 $cgiparams { 'CERT_NAME' } = $Lang :: tr
{ 'vpn no full pki' } if ( $cakeydisabled );
2632 my $cacrtdisabled = ( ! - f
"${General::swroot}/ca/cacert.pem" ) ?
"disabled='disabled'" : '' ;
2634 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2636 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2637 <tr><td width='5%'><input type='radio' name='AUTH' value='psk' $checked {'AUTH'}{'psk'} /></td>
2638 <td class='base' width='55%'> $Lang ::tr{'use a pre-shared key'}</td>
2639 <td class='base' width='40%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td></tr>
2640 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2641 <tr><td><input type='radio' name='AUTH' value='certreq' $checked {'AUTH'}{'certreq'} $cakeydisabled /></td>
2642 <td class='base'><hr /> $Lang ::tr{'upload a certificate request'}</td>
2643 <td class='base' rowspan='3' valign='middle'><input type='file' name='FH' size='30' $cacrtdisabled /></td></tr>
2644 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td>
2645 <td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
2646 <tr><td><input type='radio' name='AUTH' value='pkcs12' $cacrtdisabled /></td>
2647 <td class='base'> $Lang ::tr{'upload p12 file'} $Lang ::tr{'pkcs12 file password'}:<input type='password' name='P12_PASS'/></td></tr>
2648 <tr><td><input type='radio' name='AUTH' value='auth-dn' $checked {'AUTH'}{'auth-dn'} $cacrtdisabled /></td>
2649 <td class='base'><hr /> $Lang ::tr{'vpn auth-dn'}</td></tr>
2650 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2651 <tr><td><input type='radio' name='AUTH' value='certgen' $checked {'AUTH'}{'certgen'} $cakeydisabled /></td>
2652 <td class='base'><hr /> $Lang ::tr{'generate a certificate'}</td><td> </td></tr>
2654 <td class='base'> $Lang ::tr{'users fullname or system hostname'}: <img src='/blob.gif' alt='*' /></td>
2655 <td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' size='32' $cakeydisabled /></td></tr>
2657 <td class='base'> $Lang ::tr{'users email'}:</td>
2658 <td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' size='32' $cakeydisabled /></td></tr>
2660 <td class='base'> $Lang ::tr{'users department'}:</td>
2661 <td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' size='32' $cakeydisabled /></td></tr>
2663 <td class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
2664 <td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' size='32' $cakeydisabled /></td></tr>
2666 <td class='base'> $Lang ::tr{'city'}:</td>
2667 <td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' size='32' $cakeydisabled /></td></tr>
2669 <td class='base'> $Lang ::tr{'state or province'}:</td>
2670 <td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' size='32' $cakeydisabled /></td></tr>
2672 <td class='base'> $Lang ::tr{'country'}:</td>
2673 <td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
2676 foreach my $country ( sort keys %{ Countries
:: countries
}) {
2677 print " \t\t\t <option value=' $Countries ::countries{ $country }'" ;
2678 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
2679 print " selected='selected'" ;
2681 print "> $country </option> \n " ;
2686 <tr><td> </td><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)</td>
2687 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' $cakeydisabled /></td></tr>
2689 <td class='base'> $Lang ::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' /></td>
2690 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
2691 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'} ( $Lang ::tr{'confirmation'}): <img src='/blob.gif' alt='*' /></td>
2692 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
2696 & Header
:: closebox
();
2699 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
2700 if ( $cgiparams { 'KEY' }) {
2701 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced'}' />" ;
2703 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
2704 & Header
:: closebigbox
();
2705 & Header
:: closepage
();
2712 ### Advanced settings
2714 if (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced' }) ||
2715 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq 'yes' )) {
2716 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
2717 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2718 if (! $confighash { $cgiparams { 'KEY' }}) {
2719 $errormessage = $Lang :: tr
{ 'invalid key' };
2723 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
2724 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2726 $errormessage = $Lang :: tr
{ 'invalid input' };
2727 goto ADVANCED_ERROR
;
2729 foreach my $val ( @temp ) {
2730 if ( $val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|chacha20poly1305|camellia(256|192|128))$/ ) {
2731 $errormessage = $Lang :: tr
{ 'invalid input' };
2732 goto ADVANCED_ERROR
;
2735 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2737 $errormessage = $Lang :: tr
{ 'invalid input' };
2738 goto ADVANCED_ERROR
;
2740 foreach my $val ( @temp ) {
2741 if ( $val !~ /^(sha2_(512|384|256)|sha|md5|aesxcbc)$/ ) {
2742 $errormessage = $Lang :: tr
{ 'invalid input' };
2743 goto ADVANCED_ERROR
;
2746 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2748 $errormessage = $Lang :: tr
{ 'invalid input' };
2749 goto ADVANCED_ERROR
;
2751 foreach my $val ( @temp ) {
2752 if ( $val !~ /^(curve448|curve25519|e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|768|1024|1536|2048|3072|4096|6144|8192)$/ ) {
2753 $errormessage = $Lang :: tr
{ 'invalid input' };
2754 goto ADVANCED_ERROR
;
2757 if ( $cgiparams { 'IKE_LIFETIME' } !~ /^\d+$/ ) {
2758 $errormessage = $Lang :: tr
{ 'invalid input for ike lifetime' };
2759 goto ADVANCED_ERROR
;
2761 if ( $cgiparams { 'IKE_LIFETIME' } < 1 || $cgiparams { 'IKE_LIFETIME' } > 24 ) {
2762 $errormessage = $Lang :: tr
{ 'ike lifetime should be between 1 and 24 hours' };
2763 goto ADVANCED_ERROR
;
2765 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2767 $errormessage = $Lang :: tr
{ 'invalid input' };
2768 goto ADVANCED_ERROR
;
2770 foreach my $val ( @temp ) {
2771 if ( $val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|chacha20poly1305|camellia(256|192|128))$/ ) {
2772 $errormessage = $Lang :: tr
{ 'invalid input' };
2773 goto ADVANCED_ERROR
;
2776 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2778 $errormessage = $Lang :: tr
{ 'invalid input' };
2779 goto ADVANCED_ERROR
;
2781 foreach my $val ( @temp ) {
2782 if ( $val !~ /^(sha2_(512|384|256)|sha1|md5|aesxcbc)$/ ) {
2783 $errormessage = $Lang :: tr
{ 'invalid input' };
2784 goto ADVANCED_ERROR
;
2787 @temp = split ( '\|' , $cgiparams { 'ESP_GROUPTYPE' });
2789 $errormessage = $Lang :: tr
{ 'invalid input' };
2790 goto ADVANCED_ERROR
;
2792 foreach my $val ( @temp ) {
2793 if ( $val !~ /^(curve448|curve25519|e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|768|1024|1536|2048|3072|4096|6144|8192|none)$/ ) {
2794 $errormessage = $Lang :: tr
{ 'invalid input' };
2795 goto ADVANCED_ERROR
;
2798 if ( $cgiparams { 'ESP_KEYLIFE' } !~ /^\d+$/ ) {
2799 $errormessage = $Lang :: tr
{ 'invalid input for esp keylife' };
2800 goto ADVANCED_ERROR
;
2802 if ( $cgiparams { 'ESP_KEYLIFE' } < 1 || $cgiparams { 'ESP_KEYLIFE' } > 24 ) {
2803 $errormessage = $Lang :: tr
{ 'esp keylife should be between 1 and 24 hours' };
2804 goto ADVANCED_ERROR
;
2807 if (( $cgiparams { 'COMPRESSION' } !~ /^(|on|off)$/ ) ||
2808 ( $cgiparams { 'FORCE_MOBIKE' } !~ /^(|on|off)$/ ) ||
2809 ( $cgiparams { 'ONLY_PROPOSED' } !~ /^(|on|off)$/ ) ||
2810 ( $cgiparams { 'PFS' } !~ /^(|on|off)$/ )) {
2811 $errormessage = $Lang :: tr
{ 'invalid input' };
2812 goto ADVANCED_ERROR
;
2815 if ( $cgiparams { 'DPD_DELAY' } !~ /^\d+$/ ) {
2816 $errormessage = $Lang :: tr
{ 'invalid input for dpd delay' };
2817 goto ADVANCED_ERROR
;
2820 if ( $cgiparams { 'DPD_TIMEOUT' } !~ /^\d+$/ ) {
2821 $errormessage = $Lang :: tr
{ 'invalid input for dpd timeout' };
2822 goto ADVANCED_ERROR
;
2825 if ( $cgiparams { 'INACTIVITY_TIMEOUT' } !~ /^\d+$/ ) {
2826 $errormessage = $Lang :: tr
{ 'invalid input for inactivity timeout' };
2827 goto ADVANCED_ERROR
;
2830 $confighash { $cgiparams { 'KEY' }}[ 29 ] = $cgiparams { 'IKE_VERSION' };
2831 $confighash { $cgiparams { 'KEY' }}[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
2832 $confighash { $cgiparams { 'KEY' }}[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
2833 $confighash { $cgiparams { 'KEY' }}[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
2834 $confighash { $cgiparams { 'KEY' }}[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
2835 $confighash { $cgiparams { 'KEY' }}[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
2836 $confighash { $cgiparams { 'KEY' }}[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
2837 $confighash { $cgiparams { 'KEY' }}[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
2838 $confighash { $cgiparams { 'KEY' }}[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
2839 $confighash { $cgiparams { 'KEY' }}[ 12 ] = 'off' ; #$cgiparams{'AGGRMODE'};
2840 $confighash { $cgiparams { 'KEY' }}[ 13 ] = $cgiparams { 'COMPRESSION' };
2841 $confighash { $cgiparams { 'KEY' }}[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
2842 $confighash { $cgiparams { 'KEY' }}[ 28 ] = $cgiparams { 'PFS' };
2843 $confighash { $cgiparams { 'KEY' }}[ 27 ] = $cgiparams { 'DPD_ACTION' };
2844 $confighash { $cgiparams { 'KEY' }}[ 30 ] = $cgiparams { 'DPD_TIMEOUT' };
2845 $confighash { $cgiparams { 'KEY' }}[ 31 ] = $cgiparams { 'DPD_DELAY' };
2846 $confighash { $cgiparams { 'KEY' }}[ 32 ] = $cgiparams { 'FORCE_MOBIKE' };
2847 $confighash { $cgiparams { 'KEY' }}[ 33 ] = $cgiparams { 'START_ACTION' };
2848 $confighash { $cgiparams { 'KEY' }}[ 34 ] = $cgiparams { 'INACTIVITY_TIMEOUT' };
2849 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2852 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
2857 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
2858 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
2859 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
2860 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
2861 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
2862 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
2863 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
2864 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
2865 if ( $cgiparams { 'ESP_GROUPTYPE' } eq "" ) {
2866 $cgiparams { 'ESP_GROUPTYPE' } = $cgiparams { 'IKE_GROUPTYPE' };
2868 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
2869 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
2870 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
2871 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
2872 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
2873 $cgiparams { 'DPD_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
2874 $cgiparams { 'DPD_DELAY' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
2875 $cgiparams { 'FORCE_MOBIKE' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
2876 $cgiparams { 'START_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 33 ];
2877 $cgiparams { 'INACTIVITY_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 34 ];
2878 $cgiparams { 'MODE' } = $confighash { $cgiparams { 'KEY' }}[ 35 ];
2879 $cgiparams { 'INTERFACE_MODE' } = $confighash { $cgiparams { 'KEY' }}[ 36 ];
2880 $cgiparams { 'INTERFACE_ADDRESS' } = $confighash { $cgiparams { 'KEY' }}[ 37 ];
2881 $cgiparams { 'INTERFACE_MTU' } = $confighash { $cgiparams { 'KEY' }}[ 38 ];
2882 $cgiparams { 'DNS_SERVERS' } = $confighash { $cgiparams { 'KEY' }}[ 39 ];
2884 if (! $cgiparams { 'DPD_DELAY' }) {
2885 $cgiparams { 'DPD_DELAY' } = 30 ;
2888 if (! $cgiparams { 'DPD_TIMEOUT' }) {
2889 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
2892 if (! $cgiparams { 'START_ACTION' }) {
2893 $cgiparams { 'START_ACTION' } = "start" ;
2896 if ( $cgiparams { 'INACTIVITY_TIMEOUT' } eq "" ) {
2897 $cgiparams { 'INACTIVITY_TIMEOUT' } = 900 ; # 15 min
2900 if ( $cgiparams { 'MODE' } eq "" ) {
2901 $cgiparams { 'MODE' } = "tunnel" ;
2906 $checked { 'IKE_ENCRYPTION' }{ 'chacha20poly1305' } = '' ;
2907 $checked { 'IKE_ENCRYPTION' }{ 'aes256' } = '' ;
2908 $checked { 'IKE_ENCRYPTION' }{ 'aes192' } = '' ;
2909 $checked { 'IKE_ENCRYPTION' }{ 'aes128' } = '' ;
2910 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm128' } = '' ;
2911 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm128' } = '' ;
2912 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm128' } = '' ;
2913 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm96' } = '' ;
2914 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm96' } = '' ;
2915 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm96' } = '' ;
2916 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm64' } = '' ;
2917 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm64' } = '' ;
2918 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm64' } = '' ;
2919 $checked { 'IKE_ENCRYPTION' }{ '3des' } = '' ;
2920 $checked { 'IKE_ENCRYPTION' }{ 'camellia256' } = '' ;
2921 $checked { 'IKE_ENCRYPTION' }{ 'camellia192' } = '' ;
2922 $checked { 'IKE_ENCRYPTION' }{ 'camellia128' } = '' ;
2923 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2924 foreach my $key ( @temp ) { $checked { 'IKE_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2925 $checked { 'IKE_INTEGRITY' }{ 'sha2_512' } = '' ;
2926 $checked { 'IKE_INTEGRITY' }{ 'sha2_384' } = '' ;
2927 $checked { 'IKE_INTEGRITY' }{ 'sha2_256' } = '' ;
2928 $checked { 'IKE_INTEGRITY' }{ 'sha' } = '' ;
2929 $checked { 'IKE_INTEGRITY' }{ 'md5' } = '' ;
2930 $checked { 'IKE_INTEGRITY' }{ 'aesxcbc' } = '' ;
2931 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2932 foreach my $key ( @temp ) { $checked { 'IKE_INTEGRITY' }{ $key } = "selected='selected'" ; }
2933 $checked { 'IKE_GROUPTYPE' }{ 'curve448' } = '' ;
2934 $checked { 'IKE_GROUPTYPE' }{ 'curve25519' } = '' ;
2935 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2936 $checked { 'IKE_GROUPTYPE' }{ '1024' } = '' ;
2937 $checked { 'IKE_GROUPTYPE' }{ '1536' } = '' ;
2938 $checked { 'IKE_GROUPTYPE' }{ '2048' } = '' ;
2939 $checked { 'IKE_GROUPTYPE' }{ '3072' } = '' ;
2940 $checked { 'IKE_GROUPTYPE' }{ '4096' } = '' ;
2941 $checked { 'IKE_GROUPTYPE' }{ '6144' } = '' ;
2942 $checked { 'IKE_GROUPTYPE' }{ '8192' } = '' ;
2943 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2944 foreach my $key ( @temp ) { $checked { 'IKE_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2946 $checked { 'ESP_ENCRYPTION' }{ 'chacha20poly1305' } = '' ;
2947 $checked { 'ESP_ENCRYPTION' }{ 'aes256' } = '' ;
2948 $checked { 'ESP_ENCRYPTION' }{ 'aes192' } = '' ;
2949 $checked { 'ESP_ENCRYPTION' }{ 'aes128' } = '' ;
2950 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm128' } = '' ;
2951 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm128' } = '' ;
2952 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm128' } = '' ;
2953 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm96' } = '' ;
2954 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm96' } = '' ;
2955 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm96' } = '' ;
2956 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm64' } = '' ;
2957 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm64' } = '' ;
2958 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm64' } = '' ;
2959 $checked { 'ESP_ENCRYPTION' }{ '3des' } = '' ;
2960 $checked { 'ESP_ENCRYPTION' }{ 'camellia256' } = '' ;
2961 $checked { 'ESP_ENCRYPTION' }{ 'camellia192' } = '' ;
2962 $checked { 'ESP_ENCRYPTION' }{ 'camellia128' } = '' ;
2963 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2964 foreach my $key ( @temp ) { $checked { 'ESP_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2965 $checked { 'ESP_INTEGRITY' }{ 'sha2_512' } = '' ;
2966 $checked { 'ESP_INTEGRITY' }{ 'sha2_384' } = '' ;
2967 $checked { 'ESP_INTEGRITY' }{ 'sha2_256' } = '' ;
2968 $checked { 'ESP_INTEGRITY' }{ 'sha1' } = '' ;
2969 $checked { 'ESP_INTEGRITY' }{ 'md5' } = '' ;
2970 $checked { 'ESP_INTEGRITY' }{ 'aesxcbc' } = '' ;
2971 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2972 foreach my $key ( @temp ) { $checked { 'ESP_INTEGRITY' }{ $key } = "selected='selected'" ; }
2973 $checked { 'ESP_GROUPTYPE' }{ 'curve448' } = '' ;
2974 $checked { 'ESP_GROUPTYPE' }{ 'curve25519' } = '' ;
2975 $checked { 'ESP_GROUPTYPE' }{ '768' } = '' ;
2976 $checked { 'ESP_GROUPTYPE' }{ '1024' } = '' ;
2977 $checked { 'ESP_GROUPTYPE' }{ '1536' } = '' ;
2978 $checked { 'ESP_GROUPTYPE' }{ '2048' } = '' ;
2979 $checked { 'ESP_GROUPTYPE' }{ '3072' } = '' ;
2980 $checked { 'ESP_GROUPTYPE' }{ '4096' } = '' ;
2981 $checked { 'ESP_GROUPTYPE' }{ '6144' } = '' ;
2982 $checked { 'ESP_GROUPTYPE' }{ '8192' } = '' ;
2983 $checked { 'ESP_GROUPTYPE' }{ 'none' } = '' ;
2984 @temp = split ( '\|' , $cgiparams { 'ESP_GROUPTYPE' });
2985 foreach my $key ( @temp ) { $checked { 'ESP_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2987 $checked { 'COMPRESSION' } = $cgiparams { 'COMPRESSION' } eq 'on' ?
"checked='checked'" : '' ;
2988 $checked { 'FORCE_MOBIKE' } = $cgiparams { 'FORCE_MOBIKE' } eq 'on' ?
"checked='checked'" : '' ;
2989 $checked { 'ONLY_PROPOSED' } = $cgiparams { 'ONLY_PROPOSED' } eq 'on' ?
"checked='checked'" : '' ;
2990 $checked { 'PFS' } = $cgiparams { 'PFS' } eq 'on' ?
"checked='checked'" : '' ;
2992 $selected { 'IKE_VERSION' }{ 'ikev1' } = '' ;
2993 $selected { 'IKE_VERSION' }{ 'ikev2' } = '' ;
2994 $selected { 'IKE_VERSION' }{ $cgiparams { 'IKE_VERSION' }} = "selected='selected'" ;
2996 $selected { 'DPD_ACTION' }{ 'clear' } = '' ;
2997 $selected { 'DPD_ACTION' }{ 'hold' } = '' ;
2998 $selected { 'DPD_ACTION' }{ 'restart' } = '' ;
2999 $selected { 'DPD_ACTION' }{ 'none' } = '' ;
3000 $selected { 'DPD_ACTION' }{ $cgiparams { 'DPD_ACTION' }} = "selected='selected'" ;
3002 $selected { 'START_ACTION' }{ 'add' } = '' ;
3003 $selected { 'START_ACTION' }{ 'route' } = '' ;
3004 $selected { 'START_ACTION' }{ 'start' } = '' ;
3005 $selected { 'START_ACTION' }{ $cgiparams { 'START_ACTION' }} = "selected='selected'" ;
3007 $selected { 'INACTIVITY_TIMEOUT' } = ();
3008 foreach my $timeout ( keys %INACTIVITY_TIMEOUTS ) {
3009 $selected { 'INACTIVITY_TIMEOUT' }{ $timeout } = "" ;
3011 $selected { 'INACTIVITY_TIMEOUT' }{ $cgiparams { 'INACTIVITY_TIMEOUT' }} = "selected" ;
3013 & Header
:: showhttpheaders
();
3014 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
3015 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
3017 if ( $errormessage ) {
3018 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
3019 print "<class name='base'> $errormessage " ;
3020 print " </class>" ;
3021 & Header
:: closebox
();
3025 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
3026 print "<class name='base'> $warnmessage " ;
3027 print " </class>" ;
3028 & Header
:: closebox
();
3031 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'advanced'}:" );
3033 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
3034 <input type='hidden' name='ADVANCED' value='yes' />
3035 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
3037 <table width='100%'>
3040 <th width="15%"></th>
3047 <td> $Lang ::tr{'vpn keyexchange'}:</td>
3049 <select name='IKE_VERSION'>
3050 <option value='ikev2' $selected {'IKE_VERSION'}{'ikev2'}>IKEv2</option>
3051 <option value='ikev1' $selected {'IKE_VERSION'}{'ikev1'}>IKEv1</option>
3057 <td class='boldbase' width="15%"> $Lang ::tr{'encryption'}</td>
3058 <td class='boldbase'>
3059 <select name='IKE_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
3060 <option value='chacha20poly1305' $checked {'IKE_ENCRYPTION'}{'chacha20poly1305'}>256 bit ChaCha20-Poly1305/128 bit ICV</option>
3061 <option value='aes256gcm128' $checked {'IKE_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
3062 <option value='aes256gcm96' $checked {'IKE_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
3063 <option value='aes256gcm64' $checked {'IKE_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
3064 <option value='aes256' $checked {'IKE_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
3065 <option value='camellia256' $checked {'IKE_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
3066 <option value='aes192gcm128' $checked {'IKE_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
3067 <option value='aes192gcm96' $checked {'IKE_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
3068 <option value='aes192gcm64' $checked {'IKE_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
3069 <option value='aes192' $checked {'IKE_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
3070 <option value='camellia192' $checked {'IKE_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
3071 <option value='aes128gcm128' $checked {'IKE_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
3072 <option value='aes128gcm96' $checked {'IKE_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
3073 <option value='aes128gcm64' $checked {'IKE_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
3074 <option value='aes128' $checked {'IKE_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
3075 <option value='camellia128' $checked {'IKE_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
3076 <option value='3des' $checked {'IKE_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC ( $Lang ::tr{'vpn weak'})</option>
3079 <td class='boldbase'>
3080 <select name='ESP_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
3081 <option value='chacha20poly1305' $checked {'ESP_ENCRYPTION'}{'chacha20poly1305'}>256 bit ChaCha20-Poly1305/128 bit ICV</option>
3082 <option value='aes256gcm128' $checked {'ESP_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
3083 <option value='aes256gcm96' $checked {'ESP_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
3084 <option value='aes256gcm64' $checked {'ESP_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
3085 <option value='aes256' $checked {'ESP_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
3086 <option value='camellia256' $checked {'ESP_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
3087 <option value='aes192gcm128' $checked {'ESP_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
3088 <option value='aes192gcm96' $checked {'ESP_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
3089 <option value='aes192gcm64' $checked {'ESP_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
3090 <option value='aes192' $checked {'ESP_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
3091 <option value='camellia192' $checked {'ESP_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
3092 <option value='aes128gcm128' $checked {'ESP_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
3093 <option value='aes128gcm96' $checked {'ESP_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
3094 <option value='aes128gcm64' $checked {'ESP_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
3095 <option value='aes128' $checked {'ESP_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
3096 <option value='camellia128' $checked {'ESP_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
3097 <option value='3des' $checked {'ESP_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC ( $Lang ::tr{'vpn weak'})</option>
3103 <td class='boldbase' width="15%"> $Lang ::tr{'integrity'}</td>
3104 <td class='boldbase'>
3105 <select name='IKE_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
3106 <option value='sha2_512' $checked {'IKE_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
3107 <option value='sha2_384' $checked {'IKE_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
3108 <option value='sha2_256' $checked {'IKE_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
3109 <option value='aesxcbc' $checked {'IKE_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
3110 <option value='sha' $checked {'IKE_INTEGRITY'}{'sha'}>SHA1 ( $Lang ::tr{'vpn weak'})</option>
3111 <option value='md5' $checked {'IKE_INTEGRITY'}{'md5'}>MD5 ( $Lang ::tr{'vpn broken'})</option>
3114 <td class='boldbase'>
3115 <select name='ESP_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
3116 <option value='sha2_512' $checked {'ESP_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
3117 <option value='sha2_384' $checked {'ESP_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
3118 <option value='sha2_256' $checked {'ESP_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
3119 <option value='aesxcbc' $checked {'ESP_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
3120 <option value='sha1' $checked {'ESP_INTEGRITY'}{'sha1'}>SHA1 ( $Lang ::tr{'vpn weak'})</option>
3121 <option value='md5' $checked {'ESP_INTEGRITY'}{'md5'}>MD5 ( $Lang ::tr{'vpn broken'})</option>
3126 <td class='boldbase' width="15%"> $Lang ::tr{'lifetime'} <img src='/blob.gif' alt='*' /></td>
3127 <td class='boldbase'>
3128 <input type='text' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' size='5' /> $Lang ::tr{'hours'}
3130 <td class='boldbase'>
3131 <input type='text' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' size='5' /> $Lang ::tr{'hours'}
3135 <td class='boldbase' width="15%"> $Lang ::tr{'grouptype'}</td>
3136 <td class='boldbase'>
3137 <select name='IKE_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
3138 <option value='curve448' $checked {'IKE_GROUPTYPE'}{'curve448'}>Curve 448 (224 bit)</option>
3139 <option value='curve25519' $checked {'IKE_GROUPTYPE'}{'curve25519'}>Curve 25519 (128 bit)</option>
3140 <option value='e521' $checked {'IKE_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
3141 <option value='e512bp' $checked {'IKE_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
3142 <option value='e384' $checked {'IKE_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
3143 <option value='e384bp' $checked {'IKE_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
3144 <option value='e256' $checked {'IKE_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
3145 <option value='e256bp' $checked {'IKE_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
3146 <option value='e224' $checked {'IKE_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
3147 <option value='e224bp' $checked {'IKE_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
3148 <option value='e192' $checked {'IKE_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
3149 <option value='8192' $checked {'IKE_GROUPTYPE'}{'8192'}>MODP-8192</option>
3150 <option value='6144' $checked {'IKE_GROUPTYPE'}{'6144'}>MODP-6144</option>
3151 <option value='4096' $checked {'IKE_GROUPTYPE'}{'4096'}>MODP-4096</option>
3152 <option value='3072' $checked {'IKE_GROUPTYPE'}{'3072'}>MODP-3072</option>
3153 <option value='2048' $checked {'IKE_GROUPTYPE'}{'2048'}>MODP-2048 ( $Lang ::tr{'vpn weak'})</option>
3154 <option value='1536' $checked {'IKE_GROUPTYPE'}{'1536'}>MODP-1536 ( $Lang ::tr{'vpn broken'})</option>
3155 <option value='1024' $checked {'IKE_GROUPTYPE'}{'1024'}>MODP-1024 ( $Lang ::tr{'vpn broken'})</option>
3156 <option value='768' $checked {'IKE_GROUPTYPE'}{'768'}>MODP-768 ( $Lang ::tr{'vpn broken'})</option>
3159 <td class='boldbase'>
3160 <select name='ESP_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
3161 <option value='curve448' $checked {'ESP_GROUPTYPE'}{'curve448'}>Curve 448 (224 bit)</option>
3162 <option value='curve25519' $checked {'ESP_GROUPTYPE'}{'curve25519'}>Curve 25519 (128 bit)</option>
3163 <option value='e521' $checked {'ESP_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
3164 <option value='e512bp' $checked {'ESP_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
3165 <option value='e384' $checked {'ESP_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
3166 <option value='e384bp' $checked {'ESP_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
3167 <option value='e256' $checked {'ESP_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
3168 <option value='e256bp' $checked {'ESP_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
3169 <option value='e224' $checked {'ESP_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
3170 <option value='e224bp' $checked {'ESP_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
3171 <option value='e192' $checked {'ESP_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
3172 <option value='8192' $checked {'ESP_GROUPTYPE'}{'8192'}>MODP-8192</option>
3173 <option value='6144' $checked {'ESP_GROUPTYPE'}{'6144'}>MODP-6144</option>
3174 <option value='4096' $checked {'ESP_GROUPTYPE'}{'4096'}>MODP-4096</option>
3175 <option value='3072' $checked {'ESP_GROUPTYPE'}{'3072'}>MODP-3072</option>
3176 <option value='2048' $checked {'ESP_GROUPTYPE'}{'2048'}>MODP-2048 ( $Lang ::tr{'vpn weak'})</option>
3177 <option value='1536' $checked {'ESP_GROUPTYPE'}{'1536'}>MODP-1536 ( $Lang ::tr{'vpn broken'})</option>
3178 <option value='1024' $checked {'ESP_GROUPTYPE'}{'1024'}>MODP-1024 ( $Lang ::tr{'vpn broken'})</option>
3179 <option value='768' $checked {'ESP_GROUPTYPE'}{'768'}>MODP-768 ( $Lang ::tr{'vpn broken'})</option>
3180 <option value='none' $checked {'ESP_GROUPTYPE'}{'none'}>- $Lang ::tr{'none'} -</option>
3189 <h2> $Lang ::tr{'dead peer detection'}</h2>
3191 <table width="100%">
3193 <td width="15%"> $Lang ::tr{'dpd action'}:</td>
3195 <select name='DPD_ACTION'>
3196 <option value='none' $selected {'DPD_ACTION'}{'none'}>- $Lang ::tr{'disabled'} -</option>
3197 <option value='clear' $selected {'DPD_ACTION'}{'clear'}>clear</option>
3198 <option value='hold' $selected {'DPD_ACTION'}{'hold'}>hold</option>
3199 <option value='restart' $selected {'DPD_ACTION'}{'restart'}>restart</option>
3204 <td width="15%"> $Lang ::tr{'dpd timeout'}: <img src='/blob.gif' alt='*' /></td>
3206 <input type='text' name='DPD_TIMEOUT' size='5' value=' $cgiparams {'DPD_TIMEOUT'}' />
3210 <td width="15%"> $Lang ::tr{'dpd delay'}: <img src='/blob.gif' alt='*' /></td>
3212 <input type='text' name='DPD_DELAY' size='5' value=' $cgiparams {'DPD_DELAY'}' />
3219 <table width="100%">
3223 <input type='checkbox' name='ONLY_PROPOSED' $checked {'ONLY_PROPOSED'} />
3224 IKE+ESP: $Lang ::tr{'use only proposed settings'}
3228 <label> $Lang ::tr{'vpn start action'}</label>
3229 <select name="START_ACTION">
3230 <option value="route" $selected {'START_ACTION'}{'route'}> $Lang ::tr{'vpn start action route'}</option>
3231 <option value="start" $selected {'START_ACTION'}{'start'}> $Lang ::tr{'vpn start action start'}</option>
3232 <option value="add" $selected {'START_ACTION'}{'add'} > $Lang ::tr{'vpn start action add'}</option>
3239 <input type='checkbox' name='PFS' $checked {'PFS'} />
3240 $Lang ::tr{'pfs yes no'}
3244 <label> $Lang ::tr{'vpn inactivity timeout'}</label>
3245 <select name="INACTIVITY_TIMEOUT">
3247 foreach my $t ( sort { $a <=> $b } keys %INACTIVITY_TIMEOUTS ) {
3248 print "<option value= \" $t \" $selected {'INACTIVITY_TIMEOUT'}{ $t }> $INACTIVITY_TIMEOUTS { $t }</option> \n " ;
3259 <input type='checkbox' name='COMPRESSION' $checked {'COMPRESSION'} />
3260 $Lang ::tr{'vpn payload compression'}
3267 <input type='checkbox' name='FORCE_MOBIKE' $checked {'FORCE_MOBIKE'} />
3268 $Lang ::tr{'vpn force mobike'}
3273 <td align='left'><img src='/blob.gif' align='top' alt='*' /> $Lang ::tr{'required field'}</td>
3275 <input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />
3276 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' />
3282 & Header
:: closebox
();
3283 & Header
:: closebigbox
();
3284 & Header
:: closepage
();
3291 ### Default status page
3296 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%cgiparams );
3297 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
3298 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
3299 $cgiparams { 'CA_NAME' } = '' ;
3301 my @status = & General
:: system_output
( "/usr/local/bin/ipsecctrl" , "I" );
3303 $checked { 'ENABLED' } = $cgiparams { 'ENABLED' } eq 'on' ?
"checked='checked'" : '' ;
3305 & Header
:: showhttpheaders
();
3306 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
3307 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
3309 if ( $errormessage ) {
3310 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
3311 print "<class name='base'> $errormessage \n " ;
3312 print " </class> \n " ;
3313 & Header
:: closebox
();
3317 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
3318 print " $warnmessage <br>" ;
3319 print " $Lang ::tr{'fwdfw warn1'}<br>" ;
3320 & Header
:: closebox
();
3321 print "<center><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'ok'}' style='width: 5em;'></form>" ;
3322 & Header
:: closepage
();
3326 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'global settings' });
3328 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3329 <table width='100%'>
3331 <td width='60%' class='base'>
3332 $Lang ::tr{'enabled'}
3335 <input type='checkbox' name='ENABLED' $checked {'ENABLED'} />
3339 <td class='base' nowrap='nowrap' width="60%"> $Lang ::tr{'ipsec roadwarrior endpoint'}:</td>
3340 <td width="40%"><input type='text' name='RW_ENDPOINT' value=' $cgiparams {'RW_ENDPOINT'}' /></td>
3343 <td class='base' nowrap='nowrap' width="60%"> $Lang ::tr{'host to net vpn'}:</td>
3344 <td width="40%"><input type='text' name='RW_NET' value=' $cgiparams {'RW_NET'}' /></td>
3347 <td width='100%' colspan="2" align='right' class='base'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' /></td>
3353 & Header
:: closebox
();
3355 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection status and controlc' });
3357 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
3359 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
3360 <th width='22%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></th>
3361 <th width='23%' class='boldbase' align='center'><b> $Lang ::tr{'common name'}</b></th>
3362 <th width='30%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></th>
3363 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></th>
3364 <th class='boldbase' align='center' colspan='7'><b> $Lang ::tr{'action'}</b></th>
3370 foreach my $key ( sort { ncmp
( $confighash { $a }[ 1 ], $confighash { $b }[ 1 ]) } keys %confighash ) {
3371 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
3375 $col = "bgcolor=' $color {'color20'}'" ;
3378 $col = "bgcolor=' $color {'color22'}'" ;
3380 print "<td align='center' nowrap='nowrap' $col > $confighash { $key }[1]</td>" ;
3381 print "<td align='center' nowrap='nowrap' $col >" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ") $confighash { $key }[29]</td>" ;
3382 if ( $confighash { $key }[ 2 ] eq ' %auth -dn' ) {
3383 print "<td align='left' nowrap='nowrap' $col > $confighash { $key }[9]</td>" ;
3384 } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
3385 print "<td align='left' nowrap='nowrap' $col > $confighash { $key }[2]</td>" ;
3387 print "<td align='left' $col > </td>" ;
3389 print "<td align='center' $col > $confighash { $key }[25]</td>" ;
3390 my $col1 = "bgcolor='${Header::colourred}'" ;
3391 my $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
3392 if ( $confighash { $key }[ 33 ] eq "add" ) {
3393 $col1 = "bgcolor='${Header::colourorange}'" ;
3394 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'vpn wait'}</font></b>" ;
3396 foreach my $line ( @status ) {
3397 if (( $line =~ /\"$confighash{$key}[1]\".*IPsec SA established/ ) ||
3398 ( $line =~ /$confighash{$key}[1]\{.*INSTALLED/ )) {
3399 $col1 = "bgcolor='${Header::colourgreen}'" ;
3400 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b>" ;
3402 } elsif ( $line =~ /$confighash{$key}[1]\[.*CONNECTING/ ) {
3403 $col1 = "bgcolor='${Header::colourorange}'" ;
3404 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'vpn connecting'}</font></b>" ;
3405 } elsif ( $line =~ /$confighash{$key}[1]\{.*ROUTED/ ) {
3406 $col1 = "bgcolor='${Header::colourorange}'" ;
3407 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'vpn on-demand'}</font></b>" ;
3410 # move to blue if really down
3411 if ( $confighash { $key }[ 0 ] eq 'off' && $col1 =~ /${Header::colourred}/ ) {
3412 $col1 = "bgcolor='${Header::colourblue}'" ;
3413 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
3416 <td align='center' $col1 > $active </td>
3417 <td align='center' $col >
3418 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3419 <input type='image' name=' $Lang ::tr{'restart'}' src='/images/reload.gif' alt=' $Lang ::tr{'restart'}' title=' $Lang ::tr{'restart'}' />
3420 <input type='hidden' name='ACTION' value=' $Lang ::tr{'restart'}' />
3421 <input type='hidden' name='KEY' value=' $key ' />
3426 if (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
3428 <td align='center' $col >
3429 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3430 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' />
3431 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
3432 <input type='hidden' name='KEY' value=' $key ' />
3438 print "<td width='2%' $col > </td>" ;
3440 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/certs/ $confighash { $key }[1].p12" ) {
3442 <td align='center' $col >
3443 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3444 <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'}' />
3445 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
3446 <input type='hidden' name='KEY' value=' $key ' />
3451 } elsif (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
3453 <td align='center' $col >
3454 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3455 <input type='image' name=' $Lang ::tr{'download certificate'}' src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' title=' $Lang ::tr{'download certificate'}' />
3456 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
3457 <input type='hidden' name='KEY' value=' $key ' />
3463 print "<td width='2%' $col > </td>" ;
3467 if ( $confighash { $key }[ 3 ] eq 'host' ) {
3469 <td align='center' $col >
3470 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3471 <input type='image' name=' $Lang ::tr{'download apple profile'}' src='/images/apple.png' alt=' $Lang ::tr{'download apple profile'}' title=' $Lang ::tr{'download apple profile'}' />
3472 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download apple profile'}' />
3473 <input type='hidden' name='KEY' value=' $key ' />
3478 print "<td width='2%' $col > </td>" ;
3482 <td align='center' $col >
3483 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3484 <input type='image' name=' $Lang ::tr{'toggle enable disable'}' src='/images/ $gif ' alt=' $Lang ::tr{'toggle enable disable'}' title=' $Lang ::tr{'toggle enable disable'}' />
3485 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
3486 <input type='hidden' name='KEY' value=' $key ' />
3490 <td align='center' $col >
3491 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3492 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
3493 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' title=' $Lang ::tr{'edit'}' />
3494 <input type='hidden' name='KEY' value=' $key ' />
3497 <td align='center' $col >
3498 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3499 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
3500 <input type='image' name=' $Lang ::tr{'remove'}' src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' title=' $Lang ::tr{'remove'}' />
3501 <input type='hidden' name='KEY' value=' $key ' />
3511 # If the config file contains entries, print Key to action icons
3516 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
3517 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
3518 <td class='base'> $Lang ::tr{'click to disable'}</td>
3519 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
3520 <td class='base'> $Lang ::tr{'show certificate'}</td>
3521 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
3522 <td class='base'> $Lang ::tr{'edit'}</td>
3523 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
3524 <td class='base'> $Lang ::tr{'remove'}</td>
3528 <td> <img src='/images/off.gif' alt='?OFF' /></td>
3529 <td class='base'> $Lang ::tr{'click to enable'}</td>
3530 <td> <img src='/images/floppy.gif' alt='?FLOPPY' /></td>
3531 <td class='base'> $Lang ::tr{'download certificate'}</td>
3532 <td> <img src='/images/reload.gif' alt='?RELOAD'/></td>
3533 <td class='base'> $Lang ::tr{'restart'}</td>
3541 <table width='100%'>
3542 <tr><td align='right' colspan='9'>
3543 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3544 <input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />
3550 & Header
:: closebox
();
3552 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'certificate authorities'}" );
3554 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
3556 <th width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
3557 <th width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></th>
3558 <th width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></th>
3562 my $col1 = "bgcolor=' $color {'color22'}'" ;
3563 my $col2 = "bgcolor=' $color {'color20'}'" ;
3564 if (- f
"${General::swroot}/ca/cacert.pem" ) {
3565 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/cacert.pem" ));
3568 <td class='base' $col1 > $Lang ::tr{'root certificate'}</td>
3569 <td class='base' $col1 > $casubject </td>
3570 <td width='3%' align='center' $col1 >
3571 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3572 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
3573 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/info.gif' alt=' $Lang ::tr{'show root certificate'}' title=' $Lang ::tr{'show root certificate'}' />
3576 <td width='3%' align='center' $col1 >
3577 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3578 <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'}' />
3579 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
3582 <td width='4%' $col1 > </td></tr>
3586 # display rootcert generation buttons
3589 <td class='base' $col1 > $Lang ::tr{'root certificate'}:</td>
3590 <td class='base' $col1 > $Lang ::tr{'not present'}</td>
3591 <td colspan='3' $col1 > </td></tr>
3596 if (- f
"${General::swroot}/certs/hostcert.pem" ) {
3597 my $hostsubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/certs/hostcert.pem" ));
3601 <td class='base' $col2 > $Lang ::tr{'host certificate'}</td>
3602 <td class='base' $col2 > $hostsubject </td>
3603 <td width='3%' align='center' $col2 >
3604 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3605 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
3606 <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'}' />
3609 <td width='3%' align='center' $col2 >
3610 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3611 <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'}" />
3612 <input type='hidden' name='ACTION' value=" $Lang ::tr{'download host certificate'}" />
3615 <td width='4%' $col2 > </td></tr>
3622 <td width='25%' class='base' $col2 > $Lang ::tr{'host certificate'}:</td>
3623 <td class='base' $col2 > $Lang ::tr{'not present'}</td>
3624 <td colspan='3' $col2 > </td></tr>
3630 if ( keys %cahash > 0 ) {
3631 foreach my $key ( keys %cahash ) {
3632 if ( $rowcolor ++ % 2 ) {
3634 $col = "bgcolor=' $color {'color20'}'" ;
3637 $col = "bgcolor=' $color {'color22'}'" ;
3639 print "<td class='base' $col > $cahash { $key }[0]</td> \n " ;
3640 print "<td class='base' $col > $cahash { $key }[1]</td> \n " ;
3642 <td align='center' $col >
3643 <form method='post' name='cafrm${key}a' action=' $ENV {'SCRIPT_NAME'}'>
3644 <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'}' />
3645 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
3646 <input type='hidden' name='KEY' value=' $key ' />
3649 <td align='center' $col >
3650 <form method='post' name='cafrm${key}b' action=' $ENV {'SCRIPT_NAME'}'>
3651 <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'}' />
3652 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
3653 <input type='hidden' name='KEY' value=' $key ' />
3656 <td align='center' $col >
3657 <form method='post' name='cafrm${key}c' action=' $ENV {'SCRIPT_NAME'}'>
3658 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
3659 <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'}' />
3660 <input type='hidden' name='KEY' value=' $key ' />
3670 # If the file contains entries, print Key to action icons
3671 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
3674 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
3675 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
3676 <td class='base'> $Lang ::tr{'show certificate'}</td>
3677 <td> <img src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' /></td>
3678 <td class='base'> $Lang ::tr{'download certificate'}</td>
3683 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>" ;
3687 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
3688 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
3691 <td class='base' nowrap='nowrap'> $Lang ::tr{'ca name'}: <img src='/blob.gif' alt='*' /></td>
3692 <td nowrap='nowrap'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' /> </td>
3693 <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td>
3694 <td nowrap='nowrap'><input type='submit' name='ACTION' value=' $Lang ::tr{'upload ca certificate'}' /></td>
3697 <td colspan='3'> $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}:</td>
3698 <td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' /></td>
3704 & Header
:: closebox
();
3705 & Header
:: closebigbox
();
3706 & Header
:: closepage
();
3708 sub array_unique
($) {
3713 foreach my $e ( @
$array ) {
3714 next if $seen { $e }++;
3721 sub make_algos
($$$$$) {
3722 my ( $mode , $encs , $ints , $grps , $pfs ) = @_ ;
3725 foreach my $enc ( @
$encs ) {
3726 foreach my $int ( @
$ints ) {
3727 foreach my $grp ( @
$grps ) {
3730 if ( $mode eq "ike" ) {
3733 if ( $grp =~ m/^e(.*)$/ ) {
3734 push ( @algo , "ecp $1 " );
3735 } elsif ( $grp =~ m/curve(448|25519)/ ) {
3736 push ( @algo , " $grp " );
3738 push ( @algo , "modp $grp " );
3741 } elsif ( $mode eq "esp" ) {
3742 my $is_aead = ( $enc =~ m/[cg]cm/ );
3748 if (! $pfs || $grp eq "none" ) {
3750 } elsif ( $grp =~ m/^e(.*)$/ ) {
3751 push ( @algo , "ecp $1 " );
3752 } elsif ( $grp =~ m/curve(448|25519)/ ) {
3753 push ( @algo , " $grp " );
3755 push ( @algo , "modp $grp " );
3759 push ( @algos , join ( "-" , @algo ));
3764 return & array_unique
( \
@algos );
3767 sub make_subnets
($$) {
3768 my $direction = shift ;
3769 my $subnets = shift ;
3771 my @nets = split ( /\|/ , $subnets );
3773 foreach my $net ( @nets ) {
3774 my $cidr_net = & General
:: ipcidr
( $net );
3776 # Skip 0.0.0.0/0 for remote because this renders the
3777 # while system inaccessible
3778 next if (( $direction eq "right" ) && ( $cidr_net eq "0.0.0.0/0" ));
3780 push ( @cidr_nets , $cidr_net );
3783 return join ( "," , @cidr_nets );