]>
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
232 foreach my $line ( split ( /\n/ , $retssl )) {
233 & General
:: log ( "ipsec" , " $line " ) if ( 0 ); # 1 for verbose logging
234 $ret .= '<br>' . $line if ( $line =~ /error|unknown/ );
237 $ret = & Header
:: cleanhtml
( $ret );
239 return $ret ?
" $Lang ::tr{'openssl produced an error'}: $ret " : '' ;
242 ### Obtain a CN from given cert
244 sub getCNfromcert
($) {
245 #&General::log("ipsec", "Extracting name from $_[0]...");
246 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
247 $temp =~ /Subject:.*CN = (.*)[\n]/ ;
249 $temp =~ s
+/ Email
+, E
+;
250 $temp =~ s/ ST = / S = / ;
256 ### Obtain Subject from given cert
258 sub getsubjectfromcert
($) {
259 #&General::log("ipsec", "Extracting subject from $_[0]...");
260 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
261 $temp =~ /Subject: (.*)[\n]/ ;
263 $temp =~ s
+/ Email
+, E
+;
264 $temp =~ s/ ST = / S = / ;
268 ### Combine local subnet and connection name to make a unique name for each connection section
269 ### (this sub is not used now)
271 sub makeconnname
($) {
275 $subnet =~ /^(.*?)\/ (.* ?
)$/; # $1=IP $2=mask
276 my $ip = unpack ( 'N' , & Socket
:: inet_aton
( $1 ));
277 if ( length ( $2 ) > 2 ) {
278 my $mm = unpack ( 'N' , & Socket
:: inet_aton
( $2 ));
279 while ( ( $mm & 1 )== 0 ) {
286 return sprintf ( " %s - %X " , $conn , $ip );
289 ### Write a config file.
291 ###Type=Host : GUI can choose the interface used (RED,GREEN,BLUE) and
292 ### the side is always defined as 'left'.
295 sub writeipsecfiles
{
296 my %lconfighash = ();
297 my %lvpnsettings = ();
298 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%lconfighash );
299 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%lvpnsettings );
301 open ( CONF
, ">${General::swroot}/vpn/ipsec.conf" ) or die "Unable to open ${General::swroot}/vpn/ipsec.conf: $!" ;
302 open ( SECRETS
, ">${General::swroot}/vpn/ipsec.secrets" ) or die "Unable to open ${General::swroot}/vpn/ipsec.secrets: $!" ;
305 print CONF
"version 2 \n\n " ;
306 print CONF
"conn %default \n " ;
307 print CONF
" \t keyingtries= %forever \n " ;
310 # Add user includes to config file
311 if (- e
"/etc/ipsec.user.conf" ) {
312 print CONF
"include /etc/ipsec.user.conf \n " ;
316 print SECRETS
"include /etc/ipsec.user.secrets \n " ;
318 if (- f
"${General::swroot}/certs/hostkey.pem" ) {
319 print SECRETS
": RSA ${General::swroot}/certs/hostkey.pem \n "
321 my $last_secrets = '' ; # old the less specifics connections
323 foreach my $key ( keys %lconfighash ) {
324 next if ( $lconfighash { $key }[ 0 ] ne 'on' );
326 #remote peer is not set? => use '%any'
327 $lconfighash { $key }[ 10 ] = ' %any ' if ( $lconfighash { $key }[ 10 ] eq '' );
329 # Field 6 might be "off" on old installations
330 if ( $lconfighash { $key }[ 6 ] eq "off" ) {
331 $lconfighash { $key }[ 6 ] = $lvpnsettings { "VPN_IP" };
335 if ( $lconfighash { $key }[ 6 ]) {
336 $localside = $lconfighash { $key }[ 6 ];
338 $localside = " %defaultroute " ;
341 my $interface_mode = $lconfighash { $key }[ 36 ];
343 print CONF
"conn $lconfighash { $key }[1] \n " ;
344 print CONF
" \t left= $localside \n " ;
346 if ( $interface_mode eq "gre" ) {
347 print CONF
" \t leftprotoport=gre \n " ;
348 } elsif ( $interface_mode eq "vti" ) {
349 print CONF
" \t leftsubnet=0.0.0.0/0 \n " ;
351 print CONF
" \t leftsubnet=" . & make_subnets
( "left" , $lconfighash { $key }[ 8 ]) . " \n " ;
354 print CONF
" \t leftfirewall=yes \n " ;
355 print CONF
" \t lefthostaccess=yes \n " ;
357 # Always send the host certificate
358 if ( $lconfighash { $key }[ 3 ] eq 'host' ) {
359 print CONF
" \t leftsendcert=always \n " ;
362 print CONF
" \t right= $lconfighash { $key }[10] \n " ;
364 if ( $lconfighash { $key }[ 3 ] eq 'net' ) {
365 if ( $interface_mode eq "gre" ) {
366 print CONF
" \t rightprotoport=gre \n " ;
367 } elsif ( $interface_mode eq "vti" ) {
368 print CONF
" \t rightsubnet=0.0.0.0/0 \n " ;
370 print CONF
" \t rightsubnet=" . & make_subnets
( "right" , $lconfighash { $key }[ 11 ]) . " \n " ;
374 # Local Cert and Remote Cert (unless auth is DN dn-auth)
375 if ( $lconfighash { $key }[ 4 ] eq 'cert' ) {
376 print CONF
" \t leftcert=${General::swroot}/certs/hostcert.pem \n " ;
377 print CONF
" \t rightcert=${General::swroot}/certs/ $lconfighash { $key }[1]cert.pem \n " if ( $lconfighash { $key }[ 2 ] ne ' %auth -dn' );
380 # Local and Remote IDs
381 print CONF
" \t leftid= \" $lconfighash { $key }[7] \"\n " if ( $lconfighash { $key }[ 7 ]);
382 print CONF
" \t rightid= \" $lconfighash { $key }[9] \"\n " if ( $lconfighash { $key }[ 9 ]);
385 if ( $lconfighash { $key }[ 35 ] eq "transport" ) {
386 print CONF
" \t type=transport \n " ;
388 print CONF
" \t type=tunnel \n " ;
392 if ( $interface_mode eq "vti" ) {
393 print CONF
" \t mark= $key \n " ;
397 my $pfs = $lconfighash { $key }[ 28 ] eq 'on' ?
'on' : 'off' ;
400 if ( $lconfighash { $key }[ 18 ] && $lconfighash { $key }[ 19 ] && $lconfighash { $key }[ 20 ]) {
401 my @encs = split ( '\|' , $lconfighash { $key }[ 18 ]);
402 my @ints = split ( '\|' , $lconfighash { $key }[ 19 ]);
403 my @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
405 my @algos = & make_algos
( "ike" , \
@encs , \
@ints , \
@groups , 1 );
406 print CONF
" \t ike=" . join ( "," , @algos );
408 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
415 if ( $lconfighash { $key }[ 21 ] && $lconfighash { $key }[ 22 ]) {
416 my @encs = split ( '\|' , $lconfighash { $key }[ 21 ]);
417 my @ints = split ( '\|' , $lconfighash { $key }[ 22 ]);
418 my @groups = split ( '\|' , $lconfighash { $key }[ 23 ]);
420 # Use IKE grouptype if no ESP group type has been selected
421 # (for backwards compatibility)
422 if ( $lconfighash { $key }[ 23 ] eq "" ) {
423 @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
426 my @algos = & make_algos
( "esp" , \
@encs , \
@ints , \
@groups , ( $pfs eq "on" ));
427 print CONF
" \t esp=" . join ( "," , @algos );
429 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
437 if (! $lconfighash { $key }[ 29 ]) {
438 $lconfighash { $key }[ 29 ] = "ikev1" ;
441 print CONF
" \t keyexchange= $lconfighash { $key }[29] \n " ;
444 print CONF
" \t ikelifetime= $lconfighash { $key }[16]h \n " if ( $lconfighash { $key }[ 16 ]);
445 print CONF
" \t keylife= $lconfighash { $key }[17]h \n " if ( $lconfighash { $key }[ 17 ]);
448 print CONF
" \t compress=yes \n " if ( $lconfighash { $key }[ 13 ] eq 'on' );
451 if (( $lconfighash { $key }[ 29 ] eq "ikev2" ) && ( $lconfighash { $key }[ 32 ] eq 'on' )) {
452 print CONF
" \t mobike=yes \n " ;
455 # Dead Peer Detection
456 my $dpdaction = $lconfighash { $key }[ 27 ];
457 print CONF
" \t dpdaction= $dpdaction \n " ;
459 # If the dead peer detection is disabled and IKEv2 is used,
460 # dpddelay must be set to zero, too.
461 if ( $dpdaction eq "none" ) {
462 if ( $lconfighash { $key }[ 29 ] eq "ikev2" ) {
463 print CONF
" \t dpddelay=0 \n " ;
466 my $dpddelay = $lconfighash { $key }[ 31 ];
470 print CONF
" \t dpddelay= $dpddelay \n " ;
471 my $dpdtimeout = $lconfighash { $key }[ 30 ];
475 print CONF
" \t dpdtimeout= $dpdtimeout \n " ;
478 # Build Authentication details: LEFTid RIGHTid : PSK psk
480 if ( $lconfighash { $key }[ 4 ] eq 'psk' ) {
481 $psk_line = ( $lconfighash { $key }[ 7 ] ?
$lconfighash { $key }[ 7 ] : $localside ) . " " ;
482 $psk_line .= $lconfighash { $key }[ 9 ] ?
$lconfighash { $key }[ 9 ] : $lconfighash { $key }[ 10 ]; #remoteid or remote address?
483 $psk_line .= " : PSK ' $lconfighash { $key }[5]' \n " ;
484 # if the line contains %any, it is less specific than two IP or ID, so move it at end of file.
485 if ( $psk_line =~ /%any/ ) {
486 $last_secrets .= $psk_line ;
488 print SECRETS
$psk_line ;
490 print CONF
" \t authby=secret \n " ;
492 print CONF
" \t authby=rsasig \n " ;
493 print CONF
" \t leftrsasigkey= %cert \n " ;
494 print CONF
" \t rightrsasigkey= %cert \n " ;
497 my $start_action = $lconfighash { $key }[ 33 ];
498 if (! $start_action ) {
499 $start_action = "start" ;
502 my $inactivity_timeout = $lconfighash { $key }[ 34 ];
503 if ( $inactivity_timeout eq "" ) {
504 $inactivity_timeout = 900 ;
507 # Automatically start only if a net-to-net connection
508 if ( $lconfighash { $key }[ 3 ] eq 'host' ) {
509 print CONF
" \t auto=add \n " ;
510 print CONF
" \t rightsourceip= $lvpnsettings {'RW_NET'} \n " ;
512 print CONF
" \t auto= $start_action \n " ;
514 # If in on-demand mode, we terminate the tunnel
515 # after 15 min of no traffic
516 if ( $start_action eq 'route' && $inactivity_timeout > 0 ) {
517 print CONF
" \t inactivity= $inactivity_timeout \n " ;
522 print CONF
" \t fragmentation=yes \n " ;
525 if ( $lconfighash { $key }[ 3 ] eq 'host' ) {
526 my @servers = split ( /\|/ , $lconfighash { $key }[ 39 ]);
528 print CONF
" \t rightdns=" . join ( "," , @servers ) . " \n " ;
534 # Add post user includes to config file
535 # After the GUI-connections allows to patch connections.
536 if (- e
"/etc/ipsec.user-post.conf" ) {
537 print CONF
"include /etc/ipsec.user-post.conf \n " ;
541 print SECRETS
$last_secrets if ( $last_secrets );
546 # Hook to regenerate the configuration files.
547 if ( $ENV { "REMOTE_ADDR" } eq "" ) {
553 ### Save main settings
555 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
556 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
558 if ( $cgiparams { 'RW_ENDPOINT' } ne '' && !& General
:: validip
( $cgiparams { 'RW_ENDPOINT' }) && !& General
:: validfqdn
( $cgiparams { 'RW_ENDPOINT' })) {
559 $errormessage = $Lang :: tr
{ 'ipsec invalid ip address or fqdn for rw endpoint' };
563 if ( $cgiparams { 'RW_NET' } ne '' and !& General
:: validipandmask
( $cgiparams { 'RW_NET' }) ) {
564 $errormessage = $Lang :: tr
{ 'urlfilter invalid ip or mask error' };
568 $vpnsettings { 'ENABLED' } = $cgiparams { 'ENABLED' };
569 $vpnsettings { 'RW_ENDPOINT' } = $cgiparams { 'RW_ENDPOINT' };
570 $vpnsettings { 'RW_NET' } = $cgiparams { 'RW_NET' };
571 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
574 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'S' );
576 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'D' );
583 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
584 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
586 foreach my $key ( keys %confighash ) {
587 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
588 delete $confighash { $key };
591 while ( my $file = glob ( "${General::swroot}/{ca,certs,crls,private}/*" )) {
595 if ( open ( FILE
, ">${General::swroot}/vpn/caconfig" )) {
599 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
601 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'R' );
607 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' }) {
608 & Header
:: showhttpheaders
();
609 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
610 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
611 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
613 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
617 <input type='hidden' name='AREUSURE' value='yes' />
618 <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'}
622 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' />
623 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
630 & Header
:: closebigbox
();
631 & Header
:: closepage
();
635 ### Upload CA Certificate
637 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
638 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
640 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
641 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
645 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
646 $errormessage = $Lang :: tr
{ 'name too long' };
650 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
651 $errormessage = $Lang :: tr
{ 'name is invalid' };
652 goto UPLOAD_CA_ERROR
;
655 # Check if there is no other entry with this name
656 foreach my $key ( keys %cahash ) {
657 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
658 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
663 unless ( ref ( $cgiparams { 'FH' })) {
664 $errormessage = $Lang :: tr
{ 'there was no file upload' };
667 # Move uploaded ca to a temporary file
668 ( my $fh , my $filename ) = tempfile
( );
669 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
673 my $temp = `/usr/bin/openssl x509 -text -in $filename ` ;
674 if ( $temp !~ /CA:TRUE/i ) {
675 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
679 unless ( move
( $filename , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" )) {
680 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
686 my $key = & General
:: findhasharraykey
( \
%cahash );
687 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
688 $cahash { $key }[ 1 ] = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" ));
689 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
691 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'R' );
697 ### Display ca certificate
699 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
700 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
702 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
703 & Header
:: showhttpheaders
();
704 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
705 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
706 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'ca certificate'}:" );
707 my @output = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
708 my $output = & Header
:: cleanhtml
( join ( "" , @output ) , "y" );
709 print "<pre> $output </pre> \n " ;
711 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
712 & Header
:: closebigbox
();
713 & Header
:: closepage
();
716 $errormessage = $Lang :: tr
{ 'invalid key' };
720 ### Export ca certificate to browser
722 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
723 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
725 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
726 print "Content-Type: application/force-download \n " ;
727 print "Content-Type: application/octet-stream \r\n " ;
728 print "Content-Disposition: attachment; filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
730 my @cert = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-in" , "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
734 $errormessage = $Lang :: tr
{ 'invalid key' };
738 ### Remove ca certificate (step 2)
740 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
741 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
742 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
744 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
745 foreach my $key ( keys %confighash ) {
746 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" );
747 if ( grep ( /: OK/ , @test )) {
749 unlink ( "${General::swroot}/certs/ $confighash { $key }[1]cert.pem" );
750 unlink ( "${General::swroot}/certs/ $confighash { $key }[1].p12" );
751 delete $confighash { $key };
752 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
754 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'D' , $key ) if (& vpnenabled
);
757 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
758 delete $cahash { $cgiparams { 'KEY' }};
759 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
760 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'R' );
763 $errormessage = $Lang :: tr
{ 'invalid key' };
766 ### Remove ca certificate (step 1)
768 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
769 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
770 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
772 my $assignedcerts = 0 ;
773 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
774 foreach my $key ( keys %confighash ) {
775 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" );
776 if ( grep ( /: OK/ , @test )) {
780 if ( $assignedcerts ) {
781 & Header
:: showhttpheaders
();
782 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
783 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
784 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
786 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
790 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
791 <input type='hidden' name='AREUSURE' value='yes' /></td>
794 <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>
797 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
798 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
805 & Header
:: closebigbox
();
806 & Header
:: closepage
();
809 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
810 delete $cahash { $cgiparams { 'KEY' }};
811 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
812 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'R' );
816 $errormessage = $Lang :: tr
{ 'invalid key' };
820 ### Display root certificate
822 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
823 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
825 & Header
:: showhttpheaders
();
826 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
827 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
828 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
829 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'root certificate'}:" );
830 @output = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "${General::swroot}/ca/cacert.pem" );
832 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'host certificate'}:" );
833 @output = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "${General::swroot}/certs/hostcert.pem" );
835 my $output = & Header
:: cleanhtml
( join ( "" , @output ) , "y" );
836 print "<pre> $output </pre> \n " ;
838 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
839 & Header
:: closebigbox
();
840 & Header
:: closepage
();
844 ### Export root certificate to browser
846 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
847 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
848 print "Content-Type: application/force-download \n " ;
849 print "Content-Disposition: attachment; filename=cacert.pem \r\n\r\n " ;
851 my @cert = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-in" , "${General::swroot}/ca/cacert.pem" );
852 print join ( "" , @cert );
856 ### Export host certificate to browser
858 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
859 if ( - f
"${General::swroot}/certs/hostcert.pem" ) {
860 print "Content-Type: application/force-download \n " ;
861 print "Content-Disposition: attachment; filename=hostcert.pem \r\n\r\n " ;
863 my @cert = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-in" , "${General::swroot}/certs/hostcert.pem" );
864 print join ( "" , @cert );
868 ### Form for generating/importing the caroot+host certificate
870 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
871 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
873 & newcleanssldatabase
();
875 if (- f
"${General::swroot}/ca/cacert.pem" ) {
876 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
880 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
881 # fill in initial values
882 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
883 if (- e
"${General::swroot}/red/active" && open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
884 my $ipaddr = < IPADDR
>;
887 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
888 $cgiparams { 'SUBJECTALTNAME' } = "DNS:" . $cgiparams { 'ROOTCERT_HOSTNAME' };
889 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
890 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
891 $cgiparams { 'SUBJECTALTNAME' } = "IP:" . $cgiparams { 'ROOTCERT_HOSTNAME' };
894 $cgiparams { 'ROOTCERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' } if (! $cgiparams { 'ROOTCERT_COUNTRY' });
895 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
896 & General
:: log ( "ipsec" , "Importing from p12..." );
898 unless ( ref ( $cgiparams { 'FH' })) {
899 $errormessage = $Lang :: tr
{ 'there was no file upload' };
903 # Move uploaded certificate request to a temporary file
904 ( my $fh , my $filename ) = tempfile
( );
905 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
910 # Extract the CA certificate from the file
911 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
912 if ( open ( STDIN
, "-|" )) {
913 my $opt = " pkcs12 -legacy -cacerts -nokeys" ;
914 $opt .= " -in $filename " ;
915 $opt .= " -out /tmp/newcacert" ;
916 $errormessage = & callssl
( $opt );
918 print " $cgiparams {'P12_PASS'} \n " ;
922 # Extract the Host certificate from the file
923 if (! $errormessage ) {
924 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
925 if ( open ( STDIN
, "-|" )) {
926 my $opt = " pkcs12 -legacy -clcerts -nokeys" ;
927 $opt .= " -in $filename " ;
928 $opt .= " -out /tmp/newhostcert" ;
929 $errormessage = & callssl
( $opt );
931 print " $cgiparams {'P12_PASS'} \n " ;
936 # Extract the Host key from the file
937 if (! $errormessage ) {
938 & General
:: log ( "ipsec" , "Extracting private key from p12..." );
939 if ( open ( STDIN
, "-|" )) {
940 my $opt = " pkcs12 -legacy -nocerts -nodes" ;
941 $opt .= " -in $filename " ;
942 $opt .= " -out /tmp/newhostkey" ;
943 $errormessage = & callssl
( $opt );
945 print " $cgiparams {'P12_PASS'} \n " ;
950 if (! $errormessage ) {
951 & General
:: log ( "ipsec" , "Moving cacert..." );
952 unless ( move
( "/tmp/newcacert" , "${General::swroot}/ca/cacert.pem" )) {
953 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
957 if (! $errormessage ) {
958 & General
:: log ( "ipsec" , "Moving host cert..." );
959 unless ( move
( "/tmp/newhostcert" , "${General::swroot}/certs/hostcert.pem" )) {
960 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
964 if (! $errormessage ) {
965 & General
:: log ( "ipsec" , "Moving private key..." );
966 unless ( move
( "/tmp/newhostkey" , "${General::swroot}/certs/hostkey.pem" )) {
967 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
973 unlink ( '/tmp/newcacert' );
974 unlink ( '/tmp/newhostcert' );
975 unlink ( '/tmp/newhostkey' );
977 unlink ( "${General::swroot}/ca/cacert.pem" );
978 unlink ( "${General::swroot}/certs/hostcert.pem" );
979 unlink ( "${General::swroot}/certs/hostkey.pem" );
983 # Create empty CRL cannot be done because we don't have
984 # the private key for this CAROOT
985 # IPFire can only import certificates
987 & General
:: log ( "ipsec" , "p12 import completed!" );
989 goto ROOTCERT_SUCCESS
;
991 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
993 # Validate input since the form was submitted
994 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
995 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
998 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
999 $errormessage = $Lang :: tr
{ 'organization too long' };
1000 goto ROOTCERT_ERROR
;
1002 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1003 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1004 goto ROOTCERT_ERROR
;
1006 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
1007 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
1008 goto ROOTCERT_ERROR
;
1010 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
1011 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
1012 goto ROOTCERT_ERROR
;
1014 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
1015 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1016 goto ROOTCERT_ERROR
;
1018 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
1019 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1020 goto ROOTCERT_ERROR
;
1022 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1023 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1024 goto ROOTCERT_ERROR
;
1026 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1027 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1028 goto ROOTCERT_ERROR
;
1030 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1031 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1032 goto ROOTCERT_ERROR
;
1034 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1035 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1036 goto ROOTCERT_ERROR
;
1038 #the exact syntax is a list comma separated of
1039 # email:any-validemail
1040 # URI: a uniform resource indicator
1041 # DNS: a DNS domain name
1042 # RID: a registered OBJECT IDENTIFIER
1044 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
1046 if ( $cgiparams { 'SUBJECTALTNAME' } eq '' ) {
1047 $errormessage = $Lang :: tr
{ 'vpn subjectaltname missing' };
1048 goto ROOTCERT_ERROR
;
1051 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
1052 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
1056 # Copy the cgisettings to vpnsettings and save the configfile
1057 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
1058 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
1059 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
1060 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
1061 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
1062 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
1063 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
1064 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1066 # Replace empty strings with a .
1067 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
1068 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
1069 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
1071 # Create the CA certificate
1072 if (! $errormessage ) {
1073 & General
:: log ( "ipsec" , "Creating cacert..." );
1074 if ( open ( STDIN
, "-|" )) {
1075 my $opt = " req -x509 -sha256 -nodes" ;
1076 $opt .= " -days 3650" ;
1077 $opt .= " -newkey rsa:4096" ;
1078 $opt .= " -keyout ${General::swroot}/private/cakey.pem" ;
1079 $opt .= " -out ${General::swroot}/ca/cacert.pem" ;
1081 $errormessage = & callssl
( $opt );
1083 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1086 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1088 print " $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
1089 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1094 # Create the Host certificate request
1095 if (! $errormessage ) {
1096 & General
:: log ( "ipsec" , "Creating host cert..." );
1097 if ( open ( STDIN
, "-|" )) {
1098 my $opt = " req -sha256 -nodes" ;
1099 $opt .= " -newkey rsa:4096" ;
1100 $opt .= " -keyout ${General::swroot}/certs/hostkey.pem" ;
1101 $opt .= " -out ${General::swroot}/certs/hostreq.pem" ;
1102 $errormessage = & callssl
( $opt );
1104 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1107 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1109 print " $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
1110 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1117 # Sign the host certificate request
1118 if (! $errormessage ) {
1119 & General
:: log ( "ipsec" , "Self signing host cert..." );
1121 #No easy way for specifying the contain of subjectAltName without writing a config file...
1122 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1124 basicConstraints=CA:FALSE
1125 nsComment="OpenSSL Generated Certificate"
1126 subjectKeyIdentifier=hash
1127 authorityKeyIdentifier=keyid,issuer:always
1128 extendedKeyUsage = serverAuth
1131 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1134 my $opt = " ca -md sha256 -days 825" ;
1135 $opt .= " -batch -notext" ;
1136 $opt .= " -in ${General::swroot}/certs/hostreq.pem" ;
1137 $opt .= " -out ${General::swroot}/certs/hostcert.pem" ;
1138 $opt .= " -extfile $v3extname " ;
1139 $errormessage = & callssl
( $opt );
1140 unlink ( "${General::swroot}/certs/hostreq.pem" ); #no more needed
1141 unlink ( $v3extname );
1144 # Create an empty CRL
1145 if (! $errormessage ) {
1146 & General
:: log ( "ipsec" , "Creating emptycrl..." );
1147 my $opt = " ca -gencrl" ;
1148 $opt .= " -out ${General::swroot}/crls/cacrl.pem" ;
1149 $errormessage = & callssl
( $opt );
1152 # Successfully build CA / CERT!
1153 if (! $errormessage ) {
1154 & cleanssldatabase
();
1155 goto ROOTCERT_SUCCESS
;
1159 unlink ( "${General::swroot}/ca/cacert.pem" );
1160 unlink ( "${General::swroot}/certs/hostkey.pem" );
1161 unlink ( "${General::swroot}/certs/hostcert.pem" );
1162 unlink ( "${General::swroot}/crls/cacrl.pem" );
1163 & cleanssldatabase
();
1167 & Header
:: showhttpheaders
();
1168 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1169 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1170 if ( $errormessage ) {
1171 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1172 print "<class name='base'> $errormessage " ;
1173 print " </class>" ;
1174 & Header
:: closebox
();
1176 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
1178 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
1179 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1180 <tr><td width='40%' class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
1181 <td width='60%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td></tr>
1182 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}: <img src='/blob.gif' alt='*' /></td>
1183 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td></tr>
1184 <tr><td class='base'> $Lang ::tr{'your e-mail'}:</td>
1185 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td></tr>
1186 <tr><td class='base'> $Lang ::tr{'your department'}:</td>
1187 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td></tr>
1188 <tr><td class='base'> $Lang ::tr{'city'}:</td>
1189 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td></tr>
1190 <tr><td class='base'> $Lang ::tr{'state or province'}:</td>
1191 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td></tr>
1192 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1193 <td class='base'><select name='ROOTCERT_COUNTRY'>
1196 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1197 print "<option value=' $Countries ::countries{ $country }'" ;
1198 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1199 print " selected='selected'" ;
1201 print "> $country </option>" ;
1205 <tr><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*) <img src='/blob.gif' alt='*' /></td>
1206 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' /></td></tr>
1208 <td><br /><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /><br /><br /></td></tr>
1209 <tr><td class='base' colspan='2' align='left'>
1210 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1211 $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'}
1213 <tr><td colspan='2'><hr></td></tr>
1214 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}:</td>
1215 <td nowrap='nowrap'><input type='file' name='FH' size='32' /></td></tr>
1216 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
1217 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td></tr>
1219 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td></tr>
1220 <tr><td class='base' colspan='2' align='left'>
1221 <img src='/blob.gif' alt='*' /> $Lang ::tr{'required field'}</td></tr>
1225 & Header
:: closebox
();
1226 & Header
:: closebigbox
();
1227 & Header
:: closepage
();
1232 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'S' );
1237 ### Export PKCS12 file to browser
1239 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
1240 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1241 print "Content-Type: application/force-download \n " ;
1242 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
1243 print "Content-Type: application/octet-stream \r\n\r\n " ;
1245 open ( FILE
, "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1248 print join ( "" , @p12 );
1252 # Export Apple profile to browser
1253 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download apple profile' }) {
1254 # Read global configuration
1255 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1258 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1259 my $key = $cgiparams { 'KEY' };
1261 # Create a UUID generator
1262 my $uuid = Data
:: UUID
-> new ();
1264 my $uuid1 = $uuid -> create_str ();
1265 my $uuid2 = $uuid -> create_str ();
1268 my $ca_uuid = $uuid -> create_str ();
1271 my $cert_uuid = $uuid -> create_str ();
1273 # Read and encode the CA & certificate
1274 if ( $confighash { $key }[ 4 ] eq "cert" ) {
1275 my $ca_path = "${General::swroot}/ca/cacert.pem" ;
1276 my $cert_path = "${General::swroot}/certs/ $confighash { $key }[1].p12" ;
1278 # Read the CA and encode it into Base64
1279 open ( CA
, "<${ca_path}" );
1280 local ($/) = undef ; # slurp
1281 $ca = MIME
:: Base64
:: encode_base64
(< CA
>);
1284 # Read certificate and encode it into Base64
1285 open ( CERT
, "<${cert_path}" );
1286 local ($/) = undef ; # slurp
1287 $cert = MIME
:: Base64
:: encode_base64
(< CERT
>);
1291 print "Content-Type: application/octet-stream \n " ;
1292 print "Content-Disposition: attachment; filename=" . $confighash { $key }[ 1 ] . ".mobileconfig \n " ;
1293 print " \n " ; # end headers
1295 # Use our own FQDN if nothing else is configured
1296 my $endpoint = ( $vpnsettings { 'RW_ENDPOINT' } ne "" ) ?
$vpnsettings { 'RW_ENDPOINT' } : & hostname
();
1298 print "<!DOCTYPE plist PUBLIC \" -//Apple//DTD PLIST 1.0//EN \" \" http://www.apple.com/DTDs/PropertyList-1.0.dtd \" > \n " ;
1299 print "<plist version= \" 1.0 \" > \n " ;
1301 print " <key>PayloadDisplayName</key> \n " ;
1302 print " <string> $confighash { $key }[1]</string> \n " ;
1303 print " <key>PayloadIdentifier</key> \n " ;
1304 print " <string> $confighash { $key }[1]</string> \n " ;
1305 print " <key>PayloadUUID</key> \n " ;
1306 print " <string>${uuid1}</string> \n " ;
1307 print " <key>PayloadType</key> \n " ;
1308 print " <string>Configuration</string> \n " ;
1309 print " <key>PayloadVersion</key> \n " ;
1310 print " <integer>1</integer> \n " ;
1311 print " <key>PayloadContent</key> \n " ;
1314 print " <key>PayloadIdentifier</key> \n " ;
1315 print " <string>org.example.vpn1.conf1</string> \n " ;
1316 print " <key>PayloadUUID</key> \n " ;
1317 print " <string>${uuid2}</string> \n " ;
1318 print " <key>PayloadType</key> \n " ;
1319 print " <string>com.apple.vpn.managed</string> \n " ;
1320 print " <key>PayloadVersion</key> \n " ;
1321 print " <integer>1</integer> \n " ;
1322 print " <key>UserDefinedName</key> \n " ;
1323 print " <string> $confighash { $key }[1]</string> \n " ;
1324 print " <key>VPNType</key> \n " ;
1325 print " <string>IKEv2</string> \n " ;
1326 print " <key>IKEv2</key> \n " ;
1328 print " <key>RemoteAddress</key> \n " ;
1329 print " <string> $endpoint </string> \n " ;
1332 my $pfs = $confighash { $key }[ 28 ];
1334 print " <key>EnablePFS</key> \n " ;
1339 print " <key>IKESecurityAssociationParameters</key> \n " ;
1343 foreach my $cipher ( split ( /\|/ , $confighash { $key }[ 18 ])) {
1344 # Skip all unsupported ciphers
1345 next unless ( exists $APPLE_CIPHERS { $cipher });
1347 print " <key>EncryptionAlgorithm</key> \n " ;
1348 print " <string> $APPLE_CIPHERS { $cipher }</string> \n " ;
1353 foreach my $integrity ( split ( /\|/ , $confighash { $key }[ 19 ])) {
1354 # Skip all unsupported algorithms
1355 next unless ( exists $APPLE_INTEGRITIES { $integrity });
1357 print " <key>IntegrityAlgorithm</key> \n " ;
1358 print " <string> $APPLE_INTEGRITIES { $integrity }</string> \n " ;
1362 # Diffie Hellman Groups
1363 foreach my $group ( split ( /\|/ , $confighash { $key }[ 20 ])) {
1364 # Skip all unsupported algorithms
1365 next unless ( exists $APPLE_DH_GROUPS { $group });
1367 print " <key>DiffieHellmanGroup</key> \n " ;
1368 print " <string> $APPLE_DH_GROUPS { $group }</string> \n " ;
1373 my $lifetime = $confighash { $key }[ 16 ] * 60 ;
1374 print " <key>LifeTimeInMinutes</key> \n " ;
1375 print " <integer> $lifetime </integer> \n " ;
1379 print " <key>ChildSecurityAssociationParameters</key> \n " ;
1383 foreach my $cipher ( split ( /\|/ , $confighash { $key }[ 21 ])) {
1384 # Skip all unsupported ciphers
1385 next unless ( exists $APPLE_CIPHERS { $cipher });
1387 print " <key>EncryptionAlgorithm</key> \n " ;
1388 print " <string> $APPLE_CIPHERS { $cipher }</string> \n " ;
1393 foreach my $integrity ( split ( /\|/ , $confighash { $key }[ 22 ])) {
1394 # Skip all unsupported algorithms
1395 next unless ( exists $APPLE_INTEGRITIES { $integrity });
1397 print " <key>IntegrityAlgorithm</key> \n " ;
1398 print " <string> $APPLE_INTEGRITIES { $integrity }</string> \n " ;
1402 # Diffie Hellman Groups
1403 foreach my $group ( split ( /\|/ , $confighash { $key }[ 23 ])) {
1404 # Skip all unsupported algorithms
1405 next unless ( exists $APPLE_DH_GROUPS { $group });
1407 print " <key>DiffieHellmanGroup</key> \n " ;
1408 print " <string> $APPLE_DH_GROUPS { $group }</string> \n " ;
1413 my $lifetime = $confighash { $key }[ 17 ] * 60 ;
1414 print " <key>LifeTimeInMinutes</key> \n " ;
1415 print " <integer> $lifetime </integer> \n " ;
1420 if ( $confighash { $key }[ 9 ]) {
1421 my $leftid = $confighash { $key }[ 9 ];
1423 # Strip leading @ from FQDNs
1424 if ( $leftid =~ m/^@(.*)$/ ) {
1428 print " <key>LocalIdentifier</key> \n " ;
1429 print " <string> $leftid </string> \n " ;
1433 if ( $confighash { $key }[ 7 ]) {
1434 my $rightid = $confighash { $key }[ 7 ];
1436 # Strip leading @ from FQDNs
1437 if ( $rightid =~ m/^@(.*)$/ ) {
1441 print " <key>RemoteIdentifier</key> \n " ;
1442 print " <string> $rightid </string> \n " ;
1445 if ( $confighash { $key }[ 4 ] eq "cert" ) {
1446 print " <key>AuthenticationMethod</key> \n " ;
1447 print " <string>Certificate</string> \n " ;
1449 print " <key>PayloadCertificateUUID</key> \n " ;
1450 print " <string>${cert_uuid}</string> \n " ;
1452 print " <key>AuthenticationMethod</key> \n " ;
1453 print " <string>SharedSecret</string> \n " ;
1454 print " <key>SharedSecret</key> \n " ;
1455 print " <string> $confighash { $key }[5]</string> \n " ;
1458 print " <key>ExtendedAuthEnabled</key> \n " ;
1459 print " <integer>0</integer> \n " ;
1461 # These are not needed, but we provide some default to stop iPhone asking for credentials
1462 print " <key>AuthName</key> \n " ;
1463 print " <string> $confighash { $key }[1]</string> \n " ;
1464 print " <key>AuthPassword</key> \n " ;
1465 print " <string></string> \n " ;
1469 if ( $confighash { $key }[ 4 ] eq "cert" ) {
1471 print " <key>PayloadIdentifier</key> \n " ;
1472 print " <string>org.example.vpn1.client</string> \n " ;
1473 print " <key>PayloadDisplayName</key> \n " ;
1474 print " <string> $confighash { $key }[1]</string> \n " ;
1475 print " <key>PayloadUUID</key> \n " ;
1476 print " <string>${cert_uuid}</string> \n " ;
1477 print " <key>PayloadType</key> \n " ;
1478 print " <string>com.apple.security.pkcs12</string> \n " ;
1479 print " <key>PayloadVersion</key> \n " ;
1480 print " <integer>1</integer> \n " ;
1481 print " <key>PayloadContent</key> \n " ;
1484 foreach ( split /\n/ ,${ cert
}) {
1492 print " <key>PayloadIdentifier</key> \n " ;
1493 print " <string>org.example.ca</string> \n " ;
1494 print " <key>PayloadUUID</key> \n " ;
1495 print " <string>${ca_uuid}</string> \n " ;
1496 print " <key>PayloadType</key> \n " ;
1497 print " <string>com.apple.security.root</string> \n " ;
1498 print " <key>PayloadVersion</key> \n " ;
1499 print " <integer>1</integer> \n " ;
1500 print " <key>PayloadContent</key> \n " ;
1503 foreach ( split /\n/ ,${ ca
}) {
1511 print " </array> \n " ;
1518 ### Display certificate
1520 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
1521 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1523 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1524 & Header
:: showhttpheaders
();
1525 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1526 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1527 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'cert'}:" );
1528 my @output = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1529 my $output = & Header
:: cleanhtml
( join ( "" , @output ) , "y" );
1530 print "<pre> $output </pre> \n " ;
1531 & Header
:: closebox
();
1532 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1533 & Header
:: closebigbox
();
1534 & Header
:: closepage
();
1539 ### Export Certificate to browser
1541 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
1542 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1544 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1545 print "Content-Type: application/force-download \n " ;
1546 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \n\n " ;
1548 open ( FILE
, "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1557 ### Enable/Disable connection
1559 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1561 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1562 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1564 if ( $confighash { $cgiparams { 'KEY' }}) {
1565 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
1566 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
1567 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1569 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1571 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
1572 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1574 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1578 $errormessage = $Lang :: tr
{ 'invalid key' };
1582 ### Restart connection
1584 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
1585 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1586 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1588 if ( $confighash { $cgiparams { 'KEY' }}) {
1590 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
1594 $errormessage = $Lang :: tr
{ 'invalid key' };
1598 ### Remove connection
1600 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
1601 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1602 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1604 if ( $confighash { $cgiparams { 'KEY' }}) {
1605 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1606 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1607 delete $confighash { $cgiparams { 'KEY' }};
1608 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1610 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1612 $errormessage = $Lang :: tr
{ 'invalid key' };
1614 & General
:: firewall_reload
();
1616 ### Choose between adding a host-net or net-net connection
1618 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
1619 & Header
:: showhttpheaders
();
1620 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1621 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1622 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection type' });
1624 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
1625 <b> $Lang ::tr{'connection type'}:</b><br />
1627 <tr><td><input type='radio' name='TYPE' value='host' checked='checked' /></td>
1628 <td class='base'> $Lang ::tr{'host to net vpn'}</td>
1630 <td><input type='radio' name='TYPE' value='net' /></td>
1631 <td class='base'> $Lang ::tr{'net to net vpn'}</td>
1633 <td align='center' colspan='2'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td>
1638 & Header
:: closebox
();
1639 & Header
:: closebigbox
();
1640 & Header
:: closepage
();
1643 ### Adding/Editing/Saving a connection
1645 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
1646 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
1647 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
1649 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1650 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1651 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1653 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
1654 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
1655 $errormessage = $Lang :: tr
{ 'invalid key' };
1658 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
1659 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
1660 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
1661 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
1662 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
1663 $cgiparams { 'LOCAL' } = $confighash { $cgiparams { 'KEY' }}[ 6 ];
1664 $cgiparams { 'LOCAL_ID' } = $confighash { $cgiparams { 'KEY' }}[ 7 ];
1665 my @local_subnets = split ( "," , $confighash { $cgiparams { 'KEY' }}[ 8 ]);
1666 $cgiparams { 'LOCAL_SUBNET' } = join ( /\|/ , @local_subnets );
1667 $cgiparams { 'REMOTE_ID' } = $confighash { $cgiparams { 'KEY' }}[ 9 ];
1668 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
1669 my @remote_subnets = split ( "," , $confighash { $cgiparams { 'KEY' }}[ 11 ]);
1670 $cgiparams { 'REMOTE_SUBNET' } = join ( /\|/ , @remote_subnets );
1671 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
1672 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
1673 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
1674 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
1675 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
1676 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
1677 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
1678 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
1679 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
1680 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
1681 if ( $cgiparams { 'ESP_GROUPTYPE' } eq "" ) {
1682 $cgiparams { 'ESP_GROUPTYPE' } = $cgiparams { 'IKE_GROUPTYPE' };
1684 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
1685 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
1686 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
1687 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
1688 $cgiparams { 'DPD_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
1689 $cgiparams { 'DPD_DELAY' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
1690 $cgiparams { 'FORCE_MOBIKE' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
1691 $cgiparams { 'START_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 33 ];
1692 $cgiparams { 'INACTIVITY_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 34 ];
1693 $cgiparams { 'MODE' } = $confighash { $cgiparams { 'KEY' }}[ 35 ];
1694 $cgiparams { 'INTERFACE_MODE' } = $confighash { $cgiparams { 'KEY' }}[ 36 ];
1695 $cgiparams { 'INTERFACE_ADDRESS' } = $confighash { $cgiparams { 'KEY' }}[ 37 ];
1696 $cgiparams { 'INTERFACE_MTU' } = $confighash { $cgiparams { 'KEY' }}[ 38 ];
1697 $cgiparams { 'DNS_SERVERS' } = $confighash { $cgiparams { 'KEY' }}[ 39 ];
1699 if (! $cgiparams { 'DPD_DELAY' }) {
1700 $cgiparams { 'DPD_DELAY' } = 30 ;
1703 if (! $cgiparams { 'DPD_TIMEOUT' }) {
1704 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
1707 if ( $cgiparams { 'INACTIVITY_TIMEOUT' } eq "" ) {
1708 $cgiparams { 'INACTIVITY_TIMEOUT' } = 900 ;
1711 if ( $cgiparams { 'MODE' } eq "" ) {
1712 $cgiparams { 'MODE' } = "tunnel" ;
1715 if ( $cgiparams { 'INTERFACE_MTU' } eq "" ) {
1716 $cgiparams { 'INTERFACE_MTU' } = 1500 ;
1719 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
1720 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
1721 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
1722 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
1726 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
1727 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
1731 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
1732 $errormessage = $Lang :: tr
{ 'name is invalid' };
1736 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
1737 $errormessage = $Lang :: tr
{ 'name too long' };
1741 # Check if there is no other entry with this name
1742 if (! $cgiparams { 'KEY' }) { #only for add
1743 foreach my $key ( keys %confighash ) {
1744 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
1745 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
1751 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! $cgiparams { 'REMOTE' })) {
1752 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1756 if ( $cgiparams { 'LOCAL' }) {
1757 if (( $cgiparams { 'LOCAL' } ne "" ) && (!& General
:: validip
( $cgiparams { 'LOCAL' }))) {
1758 $errormessage = $Lang :: tr
{ 'invalid input for local ip address' };
1763 if ( $cgiparams { 'REMOTE' }) {
1764 if (( $cgiparams { 'REMOTE' } ne ' %any ' ) && (! & General
:: validip
( $cgiparams { 'REMOTE' }))) {
1765 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
1766 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1769 if (& valid_dns_host
( $cgiparams { 'REMOTE' })) {
1770 $warnmessage = " $Lang ::tr{'check vpn lr'} $cgiparams {'REMOTE'}. $Lang ::tr{'dns check failed'}" ;
1776 my @local_subnets = split ( "," , $cgiparams { 'LOCAL_SUBNET' });
1777 foreach my $subnet ( @local_subnets ) {
1778 unless (& Network
:: check_subnet
( $subnet )) {
1779 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
1784 # Allow only one roadwarrior/psk without remote IP-address
1785 if ( $cgiparams { 'REMOTE' } eq '' && $cgiparams { 'AUTH' } eq 'psk' ) {
1786 foreach my $key ( keys %confighash ) {
1787 if ( ( $cgiparams { 'KEY' } ne $key ) &&
1788 ( $confighash { $key }[ 4 ] eq 'psk' ) &&
1789 ( $confighash { $key }[ 10 ] eq '' ) ) {
1790 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
1796 if ( $cgiparams { 'TYPE' } eq 'net' ) {
1797 my @remote_subnets = split ( "," , $cgiparams { 'REMOTE_SUBNET' });
1798 foreach my $subnet ( @remote_subnets ) {
1799 unless (& Network
:: check_subnet
( $subnet )) {
1800 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
1805 if ( $cgiparams { 'MODE' } !~ /^(tunnel|transport)$/ ) {
1806 $errormessage = $Lang :: tr
{ 'invalid input for mode' };
1810 if ( $cgiparams { 'INTERFACE_MODE' } !~ /^(|gre|vti)$/ ) {
1811 $errormessage = $Lang :: tr
{ 'invalid input for interface mode' };
1815 if (( $cgiparams { 'INTERFACE_MODE' } eq "vti" ) && ( $cgiparams { 'MODE' } eq "transport" )) {
1816 $errormessage = $Lang :: tr
{ 'transport mode does not support vti' };
1820 if (( $cgiparams { 'INTERFACE_MODE' } ne "" ) && !& Network
:: check_subnet
( $cgiparams { 'INTERFACE_ADDRESS' })) {
1821 $errormessage = $Lang :: tr
{ 'invalid input for interface address' };
1825 if ( $cgiparams { 'INTERFACE_MTU' } !~ /^\d+$/ ) {
1826 $errormessage = $Lang :: tr
{ 'invalid input for interface mtu' };
1831 if ( $cgiparams { 'TYPE' } eq 'host' ) {
1832 my @servers = split ( "," , $cgiparams { 'DNS_SERVERS' });
1833 foreach my $server ( @servers ) {
1834 unless (& Network
:: check_ip_address
( $server )) {
1835 $errormessage = $Lang :: tr
{ 'ipsec dns server address is invalid' };
1841 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
1842 $errormessage = $Lang :: tr
{ 'invalid input' };
1845 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
1846 $errormessage = $Lang :: tr
{ 'invalid input' };
1850 # Allow nothing or a string (DN,FDQN,) beginning with @
1851 # with no comma but slashes between RID eg @O=FR/C=Paris/OU=myhome/CN=franck
1852 if ( ( $cgiparams { 'LOCAL_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1853 ( $cgiparams { 'REMOTE_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1854 (( $cgiparams { 'REMOTE_ID' } eq $cgiparams { 'LOCAL_ID' }) && ( $cgiparams { 'LOCAL_ID' } ne '' ))
1856 $errormessage = $Lang :: tr
{ 'invalid local-remote id' } . '<br />' .
1857 'DER_ASN1_DN: @c =FR/ou=Paris/ou=Home/cn=*<br />' .
1858 'FQDN: @ipfire .org<br />' .
1859 'USER_FQDN: info @ipfire .org<br />' .
1860 'IPV4_ADDR: 123.123.123.123' ;
1863 # If Auth is DN, verify existance of Remote ID.
1864 if ( $cgiparams { 'REMOTE_ID' } eq '' && (
1865 $cgiparams { 'AUTH' } eq 'auth-dn' || # while creation
1866 $confighash { $cgiparams { 'KEY' }}[ 2 ] eq ' %auth -dn' )){ # while editing
1867 $errormessage = $Lang :: tr
{ 'vpn missing remote id' };
1871 if ( $cgiparams { 'TYPE' } eq 'net' ){
1872 $warnmessage =& General
:: checksubnets
( '' , $cgiparams { 'REMOTE_SUBNET' }, 'ipsec' );
1873 if ( $warnmessage ne '' ){
1874 $warnmessage = $Lang :: tr
{ 'remote subnet' }. " ( $cgiparams {'REMOTE_SUBNET'}) <br>" . $warnmessage ;
1878 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1879 if (! length ( $cgiparams { 'PSK' }) ) {
1880 $errormessage = $Lang :: tr
{ 'pre-shared key is too short' };
1883 if ( $cgiparams { 'PSK' } =~ /'/ ) {
1884 $cgiparams { 'PSK' } =~ tr/'/ / ;
1885 $errormessage = $Lang :: tr
{ 'invalid characters found in pre-shared key' };
1888 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
1889 if ( $cgiparams { 'KEY' }) {
1890 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1893 unless ( ref ( $cgiparams { 'FH' })) {
1894 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1898 # Move uploaded certificate request to a temporary file
1899 ( my $fh , my $filename ) = tempfile
( );
1900 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1905 # Sign the certificate request
1906 & General
:: log ( "ipsec" , "Signing your cert $cgiparams {'NAME'}..." );
1907 my $opt = " ca -md sha256 -days 825" ;
1908 $opt .= " -batch -notext" ;
1909 $opt .= " -in $filename " ;
1910 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1912 if ( $errormessage = & callssl
( $opt ) ) {
1914 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1915 & cleanssldatabase
();
1919 & cleanssldatabase
();
1922 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1923 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1924 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1927 } elsif ( $cgiparams { 'AUTH' } eq 'pkcs12' ) {
1928 & General
:: log ( "ipsec" , "Importing from p12..." );
1930 unless ( ref ( $cgiparams { 'FH' })) {
1931 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1932 goto ROOTCERT_ERROR
;
1935 # Move uploaded certificate request to a temporary file
1936 ( my $fh , my $filename ) = tempfile
( );
1937 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1939 goto ROOTCERT_ERROR
;
1942 # Extract the CA certificate from the file
1943 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
1944 if ( open ( STDIN
, "-|" )) {
1945 my $opt = " pkcs12 -legacy -cacerts -nokeys" ;
1946 $opt .= " -in $filename " ;
1947 $opt .= " -out /tmp/newcacert" ;
1948 $errormessage = & callssl
( $opt );
1950 print " $cgiparams {'P12_PASS'} \n " ;
1954 # Extract the Host certificate from the file
1955 if (! $errormessage ) {
1956 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
1957 if ( open ( STDIN
, "-|" )) {
1958 my $opt = " pkcs12 -legacy -clcerts -nokeys" ;
1959 $opt .= " -in $filename " ;
1960 $opt .= " -out /tmp/newhostcert" ;
1961 $errormessage = & callssl
( $opt );
1963 print " $cgiparams {'P12_PASS'} \n " ;
1968 if (! $errormessage ) {
1969 & General
:: log ( "ipsec" , "Moving cacert..." );
1970 #If CA have new subject, add it to our list of CA
1971 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( '/tmp/newcacert' ));
1973 foreach my $x ( keys %cahash ) {
1974 $casubject = '' if ( $cahash { $x }[ 1 ] eq $casubject );
1975 unshift ( @names , $cahash { $x }[ 0 ]);
1977 if ( $casubject ) { # a new one!
1978 my @temp = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "/tmp/newcacert" );
1979 if (! grep ( /CA:TRUE/ , @temp )) {
1980 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
1982 #compute a name for it
1984 while ( grep ( /Imported-$idx/ , @names ) ) { $idx ++};
1985 $cgiparams { 'CA_NAME' }= "Imported- $idx " ;
1986 $cgiparams { 'CERT_NAME' }=& Header
:: cleanhtml
( getCNfromcert
( '/tmp/newhostcert' ));
1988 unless ( move
( "/tmp/newcacert" , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" )) {
1989 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1992 if (! $errormessage ) {
1993 my $key = & General
:: findhasharraykey
( \
%cahash );
1994 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
1995 $cahash { $key }[ 1 ] = $casubject ;
1996 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1997 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'R' );
2002 if (! $errormessage ) {
2003 & General
:: log ( "ipsec" , "Moving host cert..." );
2004 unless ( move
( "/tmp/newhostcert" , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" )) {
2005 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
2011 unlink ( '/tmp/newcacert' );
2012 unlink ( '/tmp/newhostcert' );
2013 if ( $errormessage ) {
2014 unlink ( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
2015 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
2018 & General
:: log ( "ipsec" , "p12 import completed!" );
2019 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
2020 if ( $cgiparams { 'KEY' }) {
2021 $errormessage = $Lang :: tr
{ 'cant change certificates' };
2024 unless ( ref ( $cgiparams { 'FH' })) {
2025 $errormessage = $Lang :: tr
{ 'there was no file upload' };
2028 # Move uploaded certificate to a temporary file
2029 ( my $fh , my $filename ) = tempfile
( );
2030 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
2035 # Verify the certificate has a valid CA and move it
2036 & General
:: log ( "ipsec" , "Validating imported cert against our known CA..." );
2037 my $validca = 1 ; #assume ok
2038 my @test = & General
:: system_output
( "/usr/bin/openssl" , "verify" , "-CAfile" , "${General::swroot}/ca/cacert.pem" , " $filename " );
2039 if (! grep ( /: OK/ , @test )) {
2041 foreach my $key ( keys %cahash ) {
2042 @test = & General
:: system_output
( "/usr/bin/openssl" , "verify" , "-CAfile" , "${General::swroot}/ca/ $cahash { $key }[0]cert.pem" , " $filename " );
2043 if ( grep ( /: OK/ , @test )) {
2050 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
2054 unless ( move
( $filename , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" )) {
2055 $errormessage = " $Lang ::tr{'certificate file move failed'} ( $filename ): $!" ;
2061 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
2062 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
2063 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
2064 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
2067 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
2068 if ( $cgiparams { 'KEY' }) {
2069 $errormessage = $Lang :: tr
{ 'cant change certificates' };
2072 # Validate input since the form was submitted
2073 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
2074 $errormessage = $Lang :: tr
{ 'name too long' };
2077 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
2078 $errormessage = $Lang :: tr
{ 'invalid input for name' };
2081 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
2082 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
2085 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
2086 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
2089 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
2090 $errormessage = $Lang :: tr
{ 'invalid input for department' };
2093 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
2094 $errormessage = $Lang :: tr
{ 'organization too long' };
2097 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
2098 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
2101 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
2102 $errormessage = $Lang :: tr
{ 'invalid input for city' };
2105 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
2106 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
2109 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
2110 $errormessage = $Lang :: tr
{ 'invalid input for country' };
2113 #the exact syntax is a list comma separated of
2114 # email:any-validemail
2115 # URI: a uniform resource indicator
2116 # DNS: a DNS domain name
2117 # RID: a registered OBJECT IDENTIFIER
2119 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
2121 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
2122 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
2126 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
2127 $errormessage = $Lang :: tr
{ 'password too short' };
2130 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
2131 $errormessage = $Lang :: tr
{ 'passwords do not match' };
2135 # Replace empty strings with a .
2136 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
2137 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
2138 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
2140 # Create the Client certificate request
2141 & General
:: log ( "ipsec" , "Creating a cert..." );
2143 if ( open ( STDIN
, "-|" )) {
2144 my $opt = " req -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
2145 $opt .= " -newkey rsa:4096" ;
2146 $opt .= " -keyout ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
2147 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
2149 if ( $errormessage = & callssl
( $opt ) ) {
2150 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
2151 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
2155 print " $cgiparams {'CERT_COUNTRY'} \n " ;
2158 print " $cgiparams {'CERT_ORGANIZATION'} \n " ;
2160 print " $cgiparams {'CERT_NAME'} \n " ;
2161 print " $cgiparams {'CERT_EMAIL'} \n " ;
2167 # Sign the client certificate request
2168 & General
:: log ( "ipsec" , "Signing the cert $cgiparams {'NAME'}..." );
2170 #No easy way for specifying the contain of subjectAltName without writing a config file...
2171 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
2173 basicConstraints=CA:FALSE
2174 nsComment="OpenSSL Generated Certificate"
2175 subjectKeyIdentifier=hash
2176 extendedKeyUsage=clientAuth
2177 authorityKeyIdentifier=keyid,issuer:always
2180 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
2183 my $opt = " ca -md sha256 -days 825 -batch -notext" ;
2184 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
2185 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
2186 $opt .= " -extfile $v3extname " ;
2188 if ( $errormessage = & callssl
( $opt ) ) {
2189 unlink ( $v3extname );
2190 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
2191 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
2192 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
2193 & cleanssldatabase
();
2196 unlink ( $v3extname );
2197 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
2198 & cleanssldatabase
();
2201 # Create the pkcs12 file
2202 & General
:: log ( "ipsec" , "Packing a pkcs12 file..." );
2203 $opt = " pkcs12 -legacy -export" ;
2204 $opt .= " -inkey ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
2205 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
2206 $opt .= " -name \" $cgiparams {'NAME'} \" " ;
2207 $opt .= " -passout pass: $cgiparams {'CERT_PASS1'}" ;
2208 $opt .= " -certfile ${General::swroot}/ca/cacert.pem" ;
2209 $opt .= " -caname \" $vpnsettings {'ROOTCERT_ORGANIZATION'} CA \" " ;
2210 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}.p12" ;
2212 if ( $errormessage = & callssl
( $opt ) ) {
2213 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
2214 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
2215 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}.p12" );
2218 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
2220 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
2221 ; # Nothing, just editing
2222 } elsif ( $cgiparams { 'AUTH' } eq 'auth-dn' ) {
2223 $cgiparams { 'CERT_NAME' } = ' %auth -dn' ; # a special value saying 'no cert file'
2225 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
2229 # 1)Error message here is not accurate.
2230 # 2)Test is superfluous, openswan can reference same cert multiple times
2231 # 3)Present since initial version (1.3.2.11), it isn't a bug correction
2232 # Check if there is no other entry with this certificate name
2233 #if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk') && ($cgiparams{'AUTH'} ne 'auth-dn')) {
2234 # foreach my $key (keys %confighash) {
2235 # if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) {
2236 # $errormessage = $Lang::tr{'a connection with this common name already exists'};
2237 # goto VPNCONF_ERROR;
2243 my $key = $cgiparams { 'KEY' };
2245 $key = & General
:: findhasharraykey
( \
%confighash );
2246 foreach my $i ( 0 .. 39 ) { $confighash { $key }[ $i ] = "" ;}
2248 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
2249 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
2250 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
2251 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
2253 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
2254 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
2255 $confighash { $key }[ 4 ] = 'psk' ;
2256 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
2258 $confighash { $key }[ 4 ] = 'cert' ;
2260 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2261 my @remote_subnets = split ( "," , $cgiparams { 'REMOTE_SUBNET' });
2262 $confighash { $key }[ 11 ] = join ( '|' , @remote_subnets );
2264 $confighash { $key }[ 6 ] = $cgiparams { 'LOCAL' };
2265 $confighash { $key }[ 7 ] = $cgiparams { 'LOCAL_ID' };
2266 my @local_subnets = split ( "," , $cgiparams { 'LOCAL_SUBNET' });
2267 $confighash { $key }[ 8 ] = join ( '|' , @local_subnets );
2268 $confighash { $key }[ 9 ] = $cgiparams { 'REMOTE_ID' };
2269 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
2270 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
2271 $confighash { $key }[ 26 ] = "" ; # Formerly INTERFACE
2272 $confighash { $key }[ 27 ] = $cgiparams { 'DPD_ACTION' };
2273 $confighash { $key }[ 29 ] = $cgiparams { 'IKE_VERSION' };
2275 # don't forget advanced value
2276 $confighash { $key }[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
2277 $confighash { $key }[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
2278 $confighash { $key }[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
2279 $confighash { $key }[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
2280 $confighash { $key }[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
2281 $confighash { $key }[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
2282 $confighash { $key }[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
2283 $confighash { $key }[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
2284 $confighash { $key }[ 12 ] = 'off' ; # $cgiparams{'AGGRMODE'};
2285 $confighash { $key }[ 13 ] = $cgiparams { 'COMPRESSION' };
2286 $confighash { $key }[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
2287 $confighash { $key }[ 28 ] = $cgiparams { 'PFS' };
2288 $confighash { $key }[ 30 ] = $cgiparams { 'DPD_TIMEOUT' };
2289 $confighash { $key }[ 31 ] = $cgiparams { 'DPD_DELAY' };
2290 $confighash { $key }[ 32 ] = $cgiparams { 'FORCE_MOBIKE' };
2291 $confighash { $key }[ 33 ] = $cgiparams { 'START_ACTION' };
2292 $confighash { $key }[ 34 ] = $cgiparams { 'INACTIVITY_TIMEOUT' };
2293 $confighash { $key }[ 35 ] = $cgiparams { 'MODE' };
2294 $confighash { $key }[ 36 ] = $cgiparams { 'INTERFACE_MODE' };
2295 $confighash { $key }[ 37 ] = $cgiparams { 'INTERFACE_ADDRESS' };
2296 $confighash { $key }[ 38 ] = $cgiparams { 'INTERFACE_MTU' };
2297 $confighash { $key }[ 39 ] = join ( "|" , split ( "," , $cgiparams { 'DNS_SERVERS' }));
2299 # free unused fields!
2300 $confighash { $key }[ 15 ] = 'off' ;
2302 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2305 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'S' , $key );
2308 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
2309 $cgiparams { 'KEY' } = $key ;
2310 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
2313 } else { # add new connection
2314 $cgiparams { 'ENABLED' } = 'on' ;
2315 if ( ! - f
"${General::swroot}/private/cakey.pem" ) {
2316 $cgiparams { 'AUTH' } = 'psk' ;
2317 } elsif ( ! - f
"${General::swroot}/ca/cacert.pem" ) {
2318 $cgiparams { 'AUTH' } = 'certfile' ;
2320 $cgiparams { 'AUTH' } = 'certgen' ;
2323 if ( $netsettings { "GREEN_NETADDRESS" } && $netsettings { "GREEN_NETMASK" }) {
2324 $cgiparams { "LOCAL_SUBNET" } = $netsettings { 'GREEN_NETADDRESS' } . "/" . $netsettings { 'GREEN_NETMASK' };
2326 $cgiparams { "LOCAL_SUBNET" } = "" ;
2328 $cgiparams { 'CERT_EMAIL' } = $vpnsettings { 'ROOTCERT_EMAIL' };
2329 $cgiparams { 'CERT_OU' } = $vpnsettings { 'ROOTCERT_OU' };
2330 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
2331 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
2332 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
2333 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
2335 # choose appropriate dpd action
2336 if ( $cgiparams { 'TYPE' } eq 'host' ) {
2337 $cgiparams { 'DPD_ACTION' } = 'clear' ;
2339 $cgiparams { 'DPD_ACTION' } = 'restart' ;
2342 if (! $cgiparams { 'DPD_DELAY' }) {
2343 $cgiparams { 'DPD_DELAY' } = 30 ;
2346 if (! $cgiparams { 'DPD_TIMEOUT' }) {
2347 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
2350 if (! $cgiparams { 'FORCE_MOBIKE' }) {
2351 $cgiparams { 'FORCE_MOBIKE' } = 'no' ;
2354 # Default IKE Version to v2
2355 if (! $cgiparams { 'IKE_VERSION' }) {
2356 $cgiparams { 'IKE_VERSION' } = 'ikev2' ;
2360 $cgiparams { 'LOCAL_ID' } = '' ;
2361 $cgiparams { 'REMOTE_ID' } = '' ;
2363 #use default advanced value
2364 $cgiparams { 'IKE_ENCRYPTION' } = 'chacha20poly1305|aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128' ; #[18];
2365 $cgiparams { 'IKE_INTEGRITY' } = 'sha2_512|sha2_256' ; #[19];
2366 $cgiparams { 'IKE_GROUPTYPE' } = 'curve448|curve25519|e521|e384|4096|3072' ; #[20];
2367 $cgiparams { 'IKE_LIFETIME' } = '3' ; #[16];
2368 $cgiparams { 'ESP_ENCRYPTION' } = 'chacha20poly1305|aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128' ; #[21];
2369 $cgiparams { 'ESP_INTEGRITY' } = 'sha2_512|sha2_256' ; #[22];
2370 $cgiparams { 'ESP_GROUPTYPE' } = 'curve448|curve25519|e521|e384|4096|3072' ; #[23];
2371 $cgiparams { 'ESP_KEYLIFE' } = '1' ; #[17];
2372 $cgiparams { 'COMPRESSION' } = 'off' ; #[13];
2373 $cgiparams { 'ONLY_PROPOSED' } = 'on' ; #[24];
2374 $cgiparams { 'PFS' } = 'on' ; #[28];
2375 $cgiparams { 'INACTIVITY_TIMEOUT' } = 900 ;
2376 $cgiparams { 'MODE' } = "tunnel" ;
2377 $cgiparams { 'INTERFACE_MODE' } = "" ;
2378 $cgiparams { 'INTERFACE_ADDRESS' } = "" ;
2379 $cgiparams { 'INTERFACE_MTU' } = 1500 ;
2380 $cgiparams { 'DNS_SERVERS' } = "" ;
2384 $checked { 'ENABLED' }{ 'off' } = '' ;
2385 $checked { 'ENABLED' }{ 'on' } = '' ;
2386 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = "checked='checked'" ;
2388 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
2389 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
2390 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = "checked='checked'" ;
2392 $checked { 'AUTH' }{ 'psk' } = '' ;
2393 $checked { 'AUTH' }{ 'certreq' } = '' ;
2394 $checked { 'AUTH' }{ 'certgen' } = '' ;
2395 $checked { 'AUTH' }{ 'certfile' } = '' ;
2396 $checked { 'AUTH' }{ 'pkcs12' } = '' ;
2397 $checked { 'AUTH' }{ 'auth-dn' } = '' ;
2398 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = "checked='checked'" ;
2400 $selected { 'MODE' }{ 'tunnel' } = '' ;
2401 $selected { 'MODE' }{ 'transport' } = '' ;
2402 $selected { 'MODE' }{ $cgiparams { 'MODE' }} = "selected='selected'" ;
2404 $selected { 'INTERFACE_MODE' }{ '' } = '' ;
2405 $selected { 'INTERFACE_MODE' }{ 'gre' } = '' ;
2406 $selected { 'INTERFACE_MODE' }{ 'vti' } = '' ;
2407 $selected { 'INTERFACE_MODE' }{ $cgiparams { 'INTERFACE_MODE' }} = "selected='selected'" ;
2409 $selected { 'LOCAL' }{ '' } = '' ;
2410 foreach my $alias ( sort keys %aliases ) {
2411 my $address = $aliases { $alias }{ 'IPT' };
2413 $selected { 'LOCAL' }{ $address } = '' ;
2415 $selected { 'LOCAL' }{ $cgiparams { 'LOCAL' }} = "selected='selected'" ;
2417 & Header
:: showhttpheaders
();
2418 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
2419 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2420 if ( $errormessage ) {
2421 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2422 print "<class name='base'> $errormessage " ;
2423 print " </class>" ;
2424 & Header
:: closebox
();
2428 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'warning messages'}:" );
2429 print "<class name='base'> $warnmessage " ;
2430 print " </class>" ;
2431 & Header
:: closebox
();
2434 print "<form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>" ;
2436 <input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />
2437 <input type='hidden' name='IKE_VERSION' value=' $cgiparams {'IKE_VERSION'}' />
2438 <input type='hidden' name='IKE_ENCRYPTION' value=' $cgiparams {'IKE_ENCRYPTION'}' />
2439 <input type='hidden' name='IKE_INTEGRITY' value=' $cgiparams {'IKE_INTEGRITY'}' />
2440 <input type='hidden' name='IKE_GROUPTYPE' value=' $cgiparams {'IKE_GROUPTYPE'}' />
2441 <input type='hidden' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' />
2442 <input type='hidden' name='ESP_ENCRYPTION' value=' $cgiparams {'ESP_ENCRYPTION'}' />
2443 <input type='hidden' name='ESP_INTEGRITY' value=' $cgiparams {'ESP_INTEGRITY'}' />
2444 <input type='hidden' name='ESP_GROUPTYPE' value=' $cgiparams {'ESP_GROUPTYPE'}' />
2445 <input type='hidden' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' />
2446 <input type='hidden' name='COMPRESSION' value=' $cgiparams {'COMPRESSION'}' />
2447 <input type='hidden' name='ONLY_PROPOSED' value=' $cgiparams {'ONLY_PROPOSED'}' />
2448 <input type='hidden' name='PFS' value=' $cgiparams {'PFS'}' />
2449 <input type='hidden' name='DPD_ACTION' value=' $cgiparams {'DPD_ACTION'}' />
2450 <input type='hidden' name='DPD_DELAY' value=' $cgiparams {'DPD_DELAY'}' />
2451 <input type='hidden' name='DPD_TIMEOUT' value=' $cgiparams {'DPD_TIMEOUT'}' />
2452 <input type='hidden' name='FORCE_MOBIKE' value=' $cgiparams {'FORCE_MOBIKE'}' />
2453 <input type='hidden' name='START_ACTION' value=' $cgiparams {'START_ACTION'}' />
2454 <input type='hidden' name='INACTIVITY_TIMEOUT' value=' $cgiparams {'INACTIVITY_TIMEOUT'}' />
2457 if ( $cgiparams { 'KEY' }) {
2458 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
2459 print "<input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' />" ;
2460 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
2463 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'connection'}: $cgiparams {'NAME'}" );
2464 print "<table width='100%'>" ;
2465 if (! $cgiparams { 'KEY' }) {
2468 <td width='20%'> $Lang ::tr{'name'}: <img src='/blob.gif' alt='*' /></td>
2470 <input type='text' name='NAME' value=' $cgiparams {'NAME'}' size='25' />
2472 <td colspan="2"></td>
2478 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2479 $blob = "<img src='/blob.gif' alt='*' />" ;
2482 my @local_subnets = split ( /\|/ , $cgiparams { 'LOCAL_SUBNET' });
2483 my $local_subnets = join ( "," , @local_subnets );
2485 my @remote_subnets = split ( /\|/ , $cgiparams { 'REMOTE_SUBNET' });
2486 my $remote_subnets = join ( "," , @remote_subnets );
2488 my @dns_servers = split ( /\|/ , $cgiparams { 'DNS_SERVERS' });
2489 my $dns_servers = join ( "," , @dns_servers );
2493 <td width='20%'> $Lang ::tr{'enabled'}</td>
2495 <input type='checkbox' name='ENABLED' $checked {'ENABLED'}{'on'} />
2497 <td colspan="2"></td>
2500 <td class='boldbase' width='20%'> $Lang ::tr{'local ip address'}:</td>
2502 <select name="LOCAL">
2503 <option value="" $selected {'LOCAL'}{''}>- $Lang ::tr{'default IP address'} -</option>
2506 foreach my $alias ( sort keys %aliases ) {
2507 my $address = $aliases { $alias }{ 'IPT' };
2509 <option value=" $address " $selected {'LOCAL'}{ $address }> $alias ( $address )</option>
2516 <td class='boldbase' width='20%'> $Lang ::tr{'remote host/ip'}: $blob </td>
2518 <input type='text' name='REMOTE' value=' $cgiparams {'REMOTE'}' size="25" />
2522 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'local subnet'} <img src='/blob.gif' alt='*' /></td>
2524 <input type='text' name='LOCAL_SUBNET' value=' $local_subnets ' size="25" />
2528 if ( $cgiparams { 'TYPE' } eq "net" ) {
2530 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'remote subnet'} <img src='/blob.gif' alt='*' /></td>
2532 <input type='text' name='REMOTE_SUBNET' value=' $remote_subnets ' size="25" />
2536 } elsif ( $cgiparams { 'TYPE' } eq "host" ) {
2538 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'dns servers'}:</td>
2540 <input type='text' name='DNS_SERVERS' value=' $dns_servers ' size="25" />
2548 <td class='boldbase' width='20%'> $Lang ::tr{'vpn local id'}:</td>
2550 <input type='text' name='LOCAL_ID' value=' $cgiparams {'LOCAL_ID'}' size="25" />
2552 <td class='boldbase' width='20%'> $Lang ::tr{'vpn remote id'}:</td>
2554 <input type='text' name='REMOTE_ID' value=' $cgiparams {'REMOTE_ID'}' size="25" />
2557 <tr><td colspan="4"><br /></td></tr>
2559 <td class='boldbase' width='20%'> $Lang ::tr{'remark title'}</td>
2561 <input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' maxlength='50' size="73" />
2566 if (! $cgiparams { 'KEY' }) {
2567 print "<tr><td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked {'EDIT_ADVANCED'}{'on'} /> $Lang ::tr{'edit advanced settings when done'}</td></tr>" ;
2570 & Header
:: closebox
();
2572 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2573 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'ipsec settings' });
2575 <table width='100%'>
2578 <td class='boldbase' width='20%'> $Lang ::tr{'mode'}:</td>
2580 <select name='MODE'>
2581 <option value='tunnel' $selected {'MODE'}{'tunnel'}> $Lang ::tr{'ipsec mode tunnel'}</option>
2582 <option value='transport' $selected {'MODE'}{'transport'}> $Lang ::tr{'ipsec mode transport'}</option>
2585 <td colspan='2'></td>
2589 <td class='boldbase' width='20%'> $Lang ::tr{'interface mode'}:</td>
2591 <select name='INTERFACE_MODE'>
2592 <option value='' $selected {'INTERFACE_MODE'}{''}> $Lang ::tr{'ipsec interface mode none'}</option>
2593 <option value='gre' $selected {'INTERFACE_MODE'}{'gre'}> $Lang ::tr{'ipsec interface mode gre'}</option>
2594 <option value='vti' $selected {'INTERFACE_MODE'}{'vti'}> $Lang ::tr{'ipsec interface mode vti'}</option>
2598 <td class='boldbase' width='20%'> $Lang ::tr{'ip address'}/ $Lang ::tr{'subnet mask'}:</td>
2600 <input type="text" name="INTERFACE_ADDRESS" value=" $cgiparams {'INTERFACE_ADDRESS'}">
2605 <td class='boldbase' width='20%'> $Lang ::tr{'mtu'}:</td>
2607 <input type="number" name="INTERFACE_MTU" value=" $cgiparams {'INTERFACE_MTU'}" min="576" max="9000">
2609 <td colspan='2'></td>
2614 & Header
:: closebox
();
2617 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
2618 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2620 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2621 <tr><td class='base' width='50%'> $Lang ::tr{'use a pre-shared key'}</td>
2622 <td class='base' width='50%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td>
2627 & Header
:: closebox
();
2628 } elsif (! $cgiparams { 'KEY' }) {
2629 my $cakeydisabled = ( ! - f
"${General::swroot}/private/cakey.pem" ) ?
"disabled='disabled'" : '' ;
2630 $cgiparams { 'CERT_NAME' } = $Lang :: tr
{ 'vpn no full pki' } if ( $cakeydisabled );
2631 my $cacrtdisabled = ( ! - f
"${General::swroot}/ca/cacert.pem" ) ?
"disabled='disabled'" : '' ;
2633 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2635 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2636 <tr><td width='5%'><input type='radio' name='AUTH' value='psk' $checked {'AUTH'}{'psk'} /></td>
2637 <td class='base' width='55%'> $Lang ::tr{'use a pre-shared key'}</td>
2638 <td class='base' width='40%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td></tr>
2639 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2640 <tr><td><input type='radio' name='AUTH' value='certreq' $checked {'AUTH'}{'certreq'} $cakeydisabled /></td>
2641 <td class='base'><hr /> $Lang ::tr{'upload a certificate request'}</td>
2642 <td class='base' rowspan='3' valign='middle'><input type='file' name='FH' size='30' $cacrtdisabled /></td></tr>
2643 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td>
2644 <td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
2645 <tr><td><input type='radio' name='AUTH' value='pkcs12' $cacrtdisabled /></td>
2646 <td class='base'> $Lang ::tr{'upload p12 file'} $Lang ::tr{'pkcs12 file password'}:<input type='password' name='P12_PASS'/></td></tr>
2647 <tr><td><input type='radio' name='AUTH' value='auth-dn' $checked {'AUTH'}{'auth-dn'} $cacrtdisabled /></td>
2648 <td class='base'><hr /> $Lang ::tr{'vpn auth-dn'}</td></tr>
2649 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2650 <tr><td><input type='radio' name='AUTH' value='certgen' $checked {'AUTH'}{'certgen'} $cakeydisabled /></td>
2651 <td class='base'><hr /> $Lang ::tr{'generate a certificate'}</td><td> </td></tr>
2653 <td class='base'> $Lang ::tr{'users fullname or system hostname'}: <img src='/blob.gif' alt='*' /></td>
2654 <td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' size='32' $cakeydisabled /></td></tr>
2656 <td class='base'> $Lang ::tr{'users email'}:</td>
2657 <td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' size='32' $cakeydisabled /></td></tr>
2659 <td class='base'> $Lang ::tr{'users department'}:</td>
2660 <td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' size='32' $cakeydisabled /></td></tr>
2662 <td class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
2663 <td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' size='32' $cakeydisabled /></td></tr>
2665 <td class='base'> $Lang ::tr{'city'}:</td>
2666 <td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' size='32' $cakeydisabled /></td></tr>
2668 <td class='base'> $Lang ::tr{'state or province'}:</td>
2669 <td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' size='32' $cakeydisabled /></td></tr>
2671 <td class='base'> $Lang ::tr{'country'}:</td>
2672 <td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
2675 foreach my $country ( sort keys %{ Countries
:: countries
}) {
2676 print " \t\t\t <option value=' $Countries ::countries{ $country }'" ;
2677 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
2678 print " selected='selected'" ;
2680 print "> $country </option> \n " ;
2685 <tr><td> </td><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)</td>
2686 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' $cakeydisabled /></td></tr>
2688 <td class='base'> $Lang ::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' /></td>
2689 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
2690 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'} ( $Lang ::tr{'confirmation'}): <img src='/blob.gif' alt='*' /></td>
2691 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
2695 & Header
:: closebox
();
2698 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
2699 if ( $cgiparams { 'KEY' }) {
2700 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced'}' />" ;
2702 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
2703 & Header
:: closebigbox
();
2704 & Header
:: closepage
();
2711 ### Advanced settings
2713 if (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced' }) ||
2714 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq 'yes' )) {
2715 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
2716 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2717 if (! $confighash { $cgiparams { 'KEY' }}) {
2718 $errormessage = $Lang :: tr
{ 'invalid key' };
2722 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
2723 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2725 $errormessage = $Lang :: tr
{ 'invalid input' };
2726 goto ADVANCED_ERROR
;
2728 foreach my $val ( @temp ) {
2729 if ( $val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|chacha20poly1305|camellia(256|192|128))$/ ) {
2730 $errormessage = $Lang :: tr
{ 'invalid input' };
2731 goto ADVANCED_ERROR
;
2734 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2736 $errormessage = $Lang :: tr
{ 'invalid input' };
2737 goto ADVANCED_ERROR
;
2739 foreach my $val ( @temp ) {
2740 if ( $val !~ /^(sha2_(512|384|256)|sha|md5|aesxcbc)$/ ) {
2741 $errormessage = $Lang :: tr
{ 'invalid input' };
2742 goto ADVANCED_ERROR
;
2745 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2747 $errormessage = $Lang :: tr
{ 'invalid input' };
2748 goto ADVANCED_ERROR
;
2750 foreach my $val ( @temp ) {
2751 if ( $val !~ /^(curve448|curve25519|e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|768|1024|1536|2048|3072|4096|6144|8192)$/ ) {
2752 $errormessage = $Lang :: tr
{ 'invalid input' };
2753 goto ADVANCED_ERROR
;
2756 if ( $cgiparams { 'IKE_LIFETIME' } !~ /^\d+$/ ) {
2757 $errormessage = $Lang :: tr
{ 'invalid input for ike lifetime' };
2758 goto ADVANCED_ERROR
;
2760 if ( $cgiparams { 'IKE_LIFETIME' } < 1 || $cgiparams { 'IKE_LIFETIME' } > 24 ) {
2761 $errormessage = $Lang :: tr
{ 'ike lifetime should be between 1 and 24 hours' };
2762 goto ADVANCED_ERROR
;
2764 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2766 $errormessage = $Lang :: tr
{ 'invalid input' };
2767 goto ADVANCED_ERROR
;
2769 foreach my $val ( @temp ) {
2770 if ( $val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|chacha20poly1305|camellia(256|192|128))$/ ) {
2771 $errormessage = $Lang :: tr
{ 'invalid input' };
2772 goto ADVANCED_ERROR
;
2775 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2777 $errormessage = $Lang :: tr
{ 'invalid input' };
2778 goto ADVANCED_ERROR
;
2780 foreach my $val ( @temp ) {
2781 if ( $val !~ /^(sha2_(512|384|256)|sha1|md5|aesxcbc)$/ ) {
2782 $errormessage = $Lang :: tr
{ 'invalid input' };
2783 goto ADVANCED_ERROR
;
2786 @temp = split ( '\|' , $cgiparams { 'ESP_GROUPTYPE' });
2788 $errormessage = $Lang :: tr
{ 'invalid input' };
2789 goto ADVANCED_ERROR
;
2791 foreach my $val ( @temp ) {
2792 if ( $val !~ /^(curve448|curve25519|e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|768|1024|1536|2048|3072|4096|6144|8192|none)$/ ) {
2793 $errormessage = $Lang :: tr
{ 'invalid input' };
2794 goto ADVANCED_ERROR
;
2797 if ( $cgiparams { 'ESP_KEYLIFE' } !~ /^\d+$/ ) {
2798 $errormessage = $Lang :: tr
{ 'invalid input for esp keylife' };
2799 goto ADVANCED_ERROR
;
2801 if ( $cgiparams { 'ESP_KEYLIFE' } < 1 || $cgiparams { 'ESP_KEYLIFE' } > 24 ) {
2802 $errormessage = $Lang :: tr
{ 'esp keylife should be between 1 and 24 hours' };
2803 goto ADVANCED_ERROR
;
2806 if (( $cgiparams { 'COMPRESSION' } !~ /^(|on|off)$/ ) ||
2807 ( $cgiparams { 'FORCE_MOBIKE' } !~ /^(|on|off)$/ ) ||
2808 ( $cgiparams { 'ONLY_PROPOSED' } !~ /^(|on|off)$/ ) ||
2809 ( $cgiparams { 'PFS' } !~ /^(|on|off)$/ )) {
2810 $errormessage = $Lang :: tr
{ 'invalid input' };
2811 goto ADVANCED_ERROR
;
2814 if ( $cgiparams { 'DPD_DELAY' } !~ /^\d+$/ ) {
2815 $errormessage = $Lang :: tr
{ 'invalid input for dpd delay' };
2816 goto ADVANCED_ERROR
;
2819 if ( $cgiparams { 'DPD_TIMEOUT' } !~ /^\d+$/ ) {
2820 $errormessage = $Lang :: tr
{ 'invalid input for dpd timeout' };
2821 goto ADVANCED_ERROR
;
2824 if ( $cgiparams { 'INACTIVITY_TIMEOUT' } !~ /^\d+$/ ) {
2825 $errormessage = $Lang :: tr
{ 'invalid input for inactivity timeout' };
2826 goto ADVANCED_ERROR
;
2829 $confighash { $cgiparams { 'KEY' }}[ 29 ] = $cgiparams { 'IKE_VERSION' };
2830 $confighash { $cgiparams { 'KEY' }}[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
2831 $confighash { $cgiparams { 'KEY' }}[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
2832 $confighash { $cgiparams { 'KEY' }}[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
2833 $confighash { $cgiparams { 'KEY' }}[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
2834 $confighash { $cgiparams { 'KEY' }}[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
2835 $confighash { $cgiparams { 'KEY' }}[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
2836 $confighash { $cgiparams { 'KEY' }}[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
2837 $confighash { $cgiparams { 'KEY' }}[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
2838 $confighash { $cgiparams { 'KEY' }}[ 12 ] = 'off' ; #$cgiparams{'AGGRMODE'};
2839 $confighash { $cgiparams { 'KEY' }}[ 13 ] = $cgiparams { 'COMPRESSION' };
2840 $confighash { $cgiparams { 'KEY' }}[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
2841 $confighash { $cgiparams { 'KEY' }}[ 28 ] = $cgiparams { 'PFS' };
2842 $confighash { $cgiparams { 'KEY' }}[ 27 ] = $cgiparams { 'DPD_ACTION' };
2843 $confighash { $cgiparams { 'KEY' }}[ 30 ] = $cgiparams { 'DPD_TIMEOUT' };
2844 $confighash { $cgiparams { 'KEY' }}[ 31 ] = $cgiparams { 'DPD_DELAY' };
2845 $confighash { $cgiparams { 'KEY' }}[ 32 ] = $cgiparams { 'FORCE_MOBIKE' };
2846 $confighash { $cgiparams { 'KEY' }}[ 33 ] = $cgiparams { 'START_ACTION' };
2847 $confighash { $cgiparams { 'KEY' }}[ 34 ] = $cgiparams { 'INACTIVITY_TIMEOUT' };
2848 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2851 & General
:: system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
2856 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
2857 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
2858 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
2859 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
2860 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
2861 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
2862 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
2863 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
2864 if ( $cgiparams { 'ESP_GROUPTYPE' } eq "" ) {
2865 $cgiparams { 'ESP_GROUPTYPE' } = $cgiparams { 'IKE_GROUPTYPE' };
2867 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
2868 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
2869 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
2870 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
2871 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
2872 $cgiparams { 'DPD_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
2873 $cgiparams { 'DPD_DELAY' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
2874 $cgiparams { 'FORCE_MOBIKE' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
2875 $cgiparams { 'START_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 33 ];
2876 $cgiparams { 'INACTIVITY_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 34 ];
2877 $cgiparams { 'MODE' } = $confighash { $cgiparams { 'KEY' }}[ 35 ];
2878 $cgiparams { 'INTERFACE_MODE' } = $confighash { $cgiparams { 'KEY' }}[ 36 ];
2879 $cgiparams { 'INTERFACE_ADDRESS' } = $confighash { $cgiparams { 'KEY' }}[ 37 ];
2880 $cgiparams { 'INTERFACE_MTU' } = $confighash { $cgiparams { 'KEY' }}[ 38 ];
2881 $cgiparams { 'DNS_SERVERS' } = $confighash { $cgiparams { 'KEY' }}[ 39 ];
2883 if (! $cgiparams { 'DPD_DELAY' }) {
2884 $cgiparams { 'DPD_DELAY' } = 30 ;
2887 if (! $cgiparams { 'DPD_TIMEOUT' }) {
2888 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
2891 if (! $cgiparams { 'START_ACTION' }) {
2892 $cgiparams { 'START_ACTION' } = "start" ;
2895 if ( $cgiparams { 'INACTIVITY_TIMEOUT' } eq "" ) {
2896 $cgiparams { 'INACTIVITY_TIMEOUT' } = 900 ; # 15 min
2899 if ( $cgiparams { 'MODE' } eq "" ) {
2900 $cgiparams { 'MODE' } = "tunnel" ;
2905 $checked { 'IKE_ENCRYPTION' }{ 'chacha20poly1305' } = '' ;
2906 $checked { 'IKE_ENCRYPTION' }{ 'aes256' } = '' ;
2907 $checked { 'IKE_ENCRYPTION' }{ 'aes192' } = '' ;
2908 $checked { 'IKE_ENCRYPTION' }{ 'aes128' } = '' ;
2909 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm128' } = '' ;
2910 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm128' } = '' ;
2911 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm128' } = '' ;
2912 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm96' } = '' ;
2913 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm96' } = '' ;
2914 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm96' } = '' ;
2915 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm64' } = '' ;
2916 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm64' } = '' ;
2917 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm64' } = '' ;
2918 $checked { 'IKE_ENCRYPTION' }{ '3des' } = '' ;
2919 $checked { 'IKE_ENCRYPTION' }{ 'camellia256' } = '' ;
2920 $checked { 'IKE_ENCRYPTION' }{ 'camellia192' } = '' ;
2921 $checked { 'IKE_ENCRYPTION' }{ 'camellia128' } = '' ;
2922 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2923 foreach my $key ( @temp ) { $checked { 'IKE_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2924 $checked { 'IKE_INTEGRITY' }{ 'sha2_512' } = '' ;
2925 $checked { 'IKE_INTEGRITY' }{ 'sha2_384' } = '' ;
2926 $checked { 'IKE_INTEGRITY' }{ 'sha2_256' } = '' ;
2927 $checked { 'IKE_INTEGRITY' }{ 'sha' } = '' ;
2928 $checked { 'IKE_INTEGRITY' }{ 'md5' } = '' ;
2929 $checked { 'IKE_INTEGRITY' }{ 'aesxcbc' } = '' ;
2930 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2931 foreach my $key ( @temp ) { $checked { 'IKE_INTEGRITY' }{ $key } = "selected='selected'" ; }
2932 $checked { 'IKE_GROUPTYPE' }{ 'curve448' } = '' ;
2933 $checked { 'IKE_GROUPTYPE' }{ 'curve25519' } = '' ;
2934 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2935 $checked { 'IKE_GROUPTYPE' }{ '1024' } = '' ;
2936 $checked { 'IKE_GROUPTYPE' }{ '1536' } = '' ;
2937 $checked { 'IKE_GROUPTYPE' }{ '2048' } = '' ;
2938 $checked { 'IKE_GROUPTYPE' }{ '3072' } = '' ;
2939 $checked { 'IKE_GROUPTYPE' }{ '4096' } = '' ;
2940 $checked { 'IKE_GROUPTYPE' }{ '6144' } = '' ;
2941 $checked { 'IKE_GROUPTYPE' }{ '8192' } = '' ;
2942 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2943 foreach my $key ( @temp ) { $checked { 'IKE_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2945 $checked { 'ESP_ENCRYPTION' }{ 'chacha20poly1305' } = '' ;
2946 $checked { 'ESP_ENCRYPTION' }{ 'aes256' } = '' ;
2947 $checked { 'ESP_ENCRYPTION' }{ 'aes192' } = '' ;
2948 $checked { 'ESP_ENCRYPTION' }{ 'aes128' } = '' ;
2949 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm128' } = '' ;
2950 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm128' } = '' ;
2951 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm128' } = '' ;
2952 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm96' } = '' ;
2953 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm96' } = '' ;
2954 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm96' } = '' ;
2955 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm64' } = '' ;
2956 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm64' } = '' ;
2957 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm64' } = '' ;
2958 $checked { 'ESP_ENCRYPTION' }{ '3des' } = '' ;
2959 $checked { 'ESP_ENCRYPTION' }{ 'camellia256' } = '' ;
2960 $checked { 'ESP_ENCRYPTION' }{ 'camellia192' } = '' ;
2961 $checked { 'ESP_ENCRYPTION' }{ 'camellia128' } = '' ;
2962 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2963 foreach my $key ( @temp ) { $checked { 'ESP_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2964 $checked { 'ESP_INTEGRITY' }{ 'sha2_512' } = '' ;
2965 $checked { 'ESP_INTEGRITY' }{ 'sha2_384' } = '' ;
2966 $checked { 'ESP_INTEGRITY' }{ 'sha2_256' } = '' ;
2967 $checked { 'ESP_INTEGRITY' }{ 'sha1' } = '' ;
2968 $checked { 'ESP_INTEGRITY' }{ 'md5' } = '' ;
2969 $checked { 'ESP_INTEGRITY' }{ 'aesxcbc' } = '' ;
2970 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2971 foreach my $key ( @temp ) { $checked { 'ESP_INTEGRITY' }{ $key } = "selected='selected'" ; }
2972 $checked { 'ESP_GROUPTYPE' }{ 'curve448' } = '' ;
2973 $checked { 'ESP_GROUPTYPE' }{ 'curve25519' } = '' ;
2974 $checked { 'ESP_GROUPTYPE' }{ '768' } = '' ;
2975 $checked { 'ESP_GROUPTYPE' }{ '1024' } = '' ;
2976 $checked { 'ESP_GROUPTYPE' }{ '1536' } = '' ;
2977 $checked { 'ESP_GROUPTYPE' }{ '2048' } = '' ;
2978 $checked { 'ESP_GROUPTYPE' }{ '3072' } = '' ;
2979 $checked { 'ESP_GROUPTYPE' }{ '4096' } = '' ;
2980 $checked { 'ESP_GROUPTYPE' }{ '6144' } = '' ;
2981 $checked { 'ESP_GROUPTYPE' }{ '8192' } = '' ;
2982 $checked { 'ESP_GROUPTYPE' }{ 'none' } = '' ;
2983 @temp = split ( '\|' , $cgiparams { 'ESP_GROUPTYPE' });
2984 foreach my $key ( @temp ) { $checked { 'ESP_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2986 $checked { 'COMPRESSION' } = $cgiparams { 'COMPRESSION' } eq 'on' ?
"checked='checked'" : '' ;
2987 $checked { 'FORCE_MOBIKE' } = $cgiparams { 'FORCE_MOBIKE' } eq 'on' ?
"checked='checked'" : '' ;
2988 $checked { 'ONLY_PROPOSED' } = $cgiparams { 'ONLY_PROPOSED' } eq 'on' ?
"checked='checked'" : '' ;
2989 $checked { 'PFS' } = $cgiparams { 'PFS' } eq 'on' ?
"checked='checked'" : '' ;
2991 $selected { 'IKE_VERSION' }{ 'ikev1' } = '' ;
2992 $selected { 'IKE_VERSION' }{ 'ikev2' } = '' ;
2993 $selected { 'IKE_VERSION' }{ $cgiparams { 'IKE_VERSION' }} = "selected='selected'" ;
2995 $selected { 'DPD_ACTION' }{ 'clear' } = '' ;
2996 $selected { 'DPD_ACTION' }{ 'hold' } = '' ;
2997 $selected { 'DPD_ACTION' }{ 'restart' } = '' ;
2998 $selected { 'DPD_ACTION' }{ 'none' } = '' ;
2999 $selected { 'DPD_ACTION' }{ $cgiparams { 'DPD_ACTION' }} = "selected='selected'" ;
3001 $selected { 'START_ACTION' }{ 'add' } = '' ;
3002 $selected { 'START_ACTION' }{ 'route' } = '' ;
3003 $selected { 'START_ACTION' }{ 'start' } = '' ;
3004 $selected { 'START_ACTION' }{ $cgiparams { 'START_ACTION' }} = "selected='selected'" ;
3006 $selected { 'INACTIVITY_TIMEOUT' } = ();
3007 foreach my $timeout ( keys %INACTIVITY_TIMEOUTS ) {
3008 $selected { 'INACTIVITY_TIMEOUT' }{ $timeout } = "" ;
3010 $selected { 'INACTIVITY_TIMEOUT' }{ $cgiparams { 'INACTIVITY_TIMEOUT' }} = "selected" ;
3012 & Header
:: showhttpheaders
();
3013 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
3014 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
3016 if ( $errormessage ) {
3017 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
3018 print "<class name='base'> $errormessage " ;
3019 print " </class>" ;
3020 & Header
:: closebox
();
3024 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
3025 print "<class name='base'> $warnmessage " ;
3026 print " </class>" ;
3027 & Header
:: closebox
();
3030 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'advanced'}:" );
3032 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
3033 <input type='hidden' name='ADVANCED' value='yes' />
3034 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
3036 <table width='100%'>
3039 <th width="15%"></th>
3046 <td> $Lang ::tr{'vpn keyexchange'}:</td>
3048 <select name='IKE_VERSION'>
3049 <option value='ikev2' $selected {'IKE_VERSION'}{'ikev2'}>IKEv2</option>
3050 <option value='ikev1' $selected {'IKE_VERSION'}{'ikev1'}>IKEv1</option>
3056 <td class='boldbase' width="15%"> $Lang ::tr{'encryption'}</td>
3057 <td class='boldbase'>
3058 <select name='IKE_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
3059 <option value='chacha20poly1305' $checked {'IKE_ENCRYPTION'}{'chacha20poly1305'}>256 bit ChaCha20-Poly1305/128 bit ICV</option>
3060 <option value='aes256gcm128' $checked {'IKE_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
3061 <option value='aes256gcm96' $checked {'IKE_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
3062 <option value='aes256gcm64' $checked {'IKE_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
3063 <option value='aes256' $checked {'IKE_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
3064 <option value='camellia256' $checked {'IKE_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
3065 <option value='aes192gcm128' $checked {'IKE_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
3066 <option value='aes192gcm96' $checked {'IKE_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
3067 <option value='aes192gcm64' $checked {'IKE_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
3068 <option value='aes192' $checked {'IKE_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
3069 <option value='camellia192' $checked {'IKE_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
3070 <option value='aes128gcm128' $checked {'IKE_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
3071 <option value='aes128gcm96' $checked {'IKE_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
3072 <option value='aes128gcm64' $checked {'IKE_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
3073 <option value='aes128' $checked {'IKE_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
3074 <option value='camellia128' $checked {'IKE_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
3075 <option value='3des' $checked {'IKE_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC ( $Lang ::tr{'vpn weak'})</option>
3078 <td class='boldbase'>
3079 <select name='ESP_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
3080 <option value='chacha20poly1305' $checked {'ESP_ENCRYPTION'}{'chacha20poly1305'}>256 bit ChaCha20-Poly1305/128 bit ICV</option>
3081 <option value='aes256gcm128' $checked {'ESP_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
3082 <option value='aes256gcm96' $checked {'ESP_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
3083 <option value='aes256gcm64' $checked {'ESP_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
3084 <option value='aes256' $checked {'ESP_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
3085 <option value='camellia256' $checked {'ESP_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
3086 <option value='aes192gcm128' $checked {'ESP_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
3087 <option value='aes192gcm96' $checked {'ESP_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
3088 <option value='aes192gcm64' $checked {'ESP_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
3089 <option value='aes192' $checked {'ESP_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
3090 <option value='camellia192' $checked {'ESP_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
3091 <option value='aes128gcm128' $checked {'ESP_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
3092 <option value='aes128gcm96' $checked {'ESP_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
3093 <option value='aes128gcm64' $checked {'ESP_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
3094 <option value='aes128' $checked {'ESP_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
3095 <option value='camellia128' $checked {'ESP_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
3096 <option value='3des' $checked {'ESP_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC ( $Lang ::tr{'vpn weak'})</option>
3102 <td class='boldbase' width="15%"> $Lang ::tr{'integrity'}</td>
3103 <td class='boldbase'>
3104 <select name='IKE_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
3105 <option value='sha2_512' $checked {'IKE_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
3106 <option value='sha2_384' $checked {'IKE_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
3107 <option value='sha2_256' $checked {'IKE_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
3108 <option value='aesxcbc' $checked {'IKE_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
3109 <option value='sha' $checked {'IKE_INTEGRITY'}{'sha'}>SHA1 ( $Lang ::tr{'vpn weak'})</option>
3110 <option value='md5' $checked {'IKE_INTEGRITY'}{'md5'}>MD5 ( $Lang ::tr{'vpn broken'})</option>
3113 <td class='boldbase'>
3114 <select name='ESP_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
3115 <option value='sha2_512' $checked {'ESP_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
3116 <option value='sha2_384' $checked {'ESP_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
3117 <option value='sha2_256' $checked {'ESP_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
3118 <option value='aesxcbc' $checked {'ESP_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
3119 <option value='sha1' $checked {'ESP_INTEGRITY'}{'sha1'}>SHA1 ( $Lang ::tr{'vpn weak'})</option>
3120 <option value='md5' $checked {'ESP_INTEGRITY'}{'md5'}>MD5 ( $Lang ::tr{'vpn broken'})</option>
3125 <td class='boldbase' width="15%"> $Lang ::tr{'lifetime'} <img src='/blob.gif' alt='*' /></td>
3126 <td class='boldbase'>
3127 <input type='text' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' size='5' /> $Lang ::tr{'hours'}
3129 <td class='boldbase'>
3130 <input type='text' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' size='5' /> $Lang ::tr{'hours'}
3134 <td class='boldbase' width="15%"> $Lang ::tr{'grouptype'}</td>
3135 <td class='boldbase'>
3136 <select name='IKE_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
3137 <option value='curve448' $checked {'IKE_GROUPTYPE'}{'curve448'}>Curve 448 (224 bit)</option>
3138 <option value='curve25519' $checked {'IKE_GROUPTYPE'}{'curve25519'}>Curve 25519 (128 bit)</option>
3139 <option value='e521' $checked {'IKE_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
3140 <option value='e512bp' $checked {'IKE_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
3141 <option value='e384' $checked {'IKE_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
3142 <option value='e384bp' $checked {'IKE_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
3143 <option value='e256' $checked {'IKE_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
3144 <option value='e256bp' $checked {'IKE_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
3145 <option value='e224' $checked {'IKE_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
3146 <option value='e224bp' $checked {'IKE_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
3147 <option value='e192' $checked {'IKE_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
3148 <option value='8192' $checked {'IKE_GROUPTYPE'}{'8192'}>MODP-8192</option>
3149 <option value='6144' $checked {'IKE_GROUPTYPE'}{'6144'}>MODP-6144</option>
3150 <option value='4096' $checked {'IKE_GROUPTYPE'}{'4096'}>MODP-4096</option>
3151 <option value='3072' $checked {'IKE_GROUPTYPE'}{'3072'}>MODP-3072</option>
3152 <option value='2048' $checked {'IKE_GROUPTYPE'}{'2048'}>MODP-2048 ( $Lang ::tr{'vpn weak'})</option>
3153 <option value='1536' $checked {'IKE_GROUPTYPE'}{'1536'}>MODP-1536 ( $Lang ::tr{'vpn broken'})</option>
3154 <option value='1024' $checked {'IKE_GROUPTYPE'}{'1024'}>MODP-1024 ( $Lang ::tr{'vpn broken'})</option>
3155 <option value='768' $checked {'IKE_GROUPTYPE'}{'768'}>MODP-768 ( $Lang ::tr{'vpn broken'})</option>
3158 <td class='boldbase'>
3159 <select name='ESP_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
3160 <option value='curve448' $checked {'ESP_GROUPTYPE'}{'curve448'}>Curve 448 (224 bit)</option>
3161 <option value='curve25519' $checked {'ESP_GROUPTYPE'}{'curve25519'}>Curve 25519 (128 bit)</option>
3162 <option value='e521' $checked {'ESP_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
3163 <option value='e512bp' $checked {'ESP_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
3164 <option value='e384' $checked {'ESP_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
3165 <option value='e384bp' $checked {'ESP_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
3166 <option value='e256' $checked {'ESP_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
3167 <option value='e256bp' $checked {'ESP_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
3168 <option value='e224' $checked {'ESP_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
3169 <option value='e224bp' $checked {'ESP_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
3170 <option value='e192' $checked {'ESP_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
3171 <option value='8192' $checked {'ESP_GROUPTYPE'}{'8192'}>MODP-8192</option>
3172 <option value='6144' $checked {'ESP_GROUPTYPE'}{'6144'}>MODP-6144</option>
3173 <option value='4096' $checked {'ESP_GROUPTYPE'}{'4096'}>MODP-4096</option>
3174 <option value='3072' $checked {'ESP_GROUPTYPE'}{'3072'}>MODP-3072</option>
3175 <option value='2048' $checked {'ESP_GROUPTYPE'}{'2048'}>MODP-2048 ( $Lang ::tr{'vpn weak'})</option>
3176 <option value='1536' $checked {'ESP_GROUPTYPE'}{'1536'}>MODP-1536 ( $Lang ::tr{'vpn broken'})</option>
3177 <option value='1024' $checked {'ESP_GROUPTYPE'}{'1024'}>MODP-1024 ( $Lang ::tr{'vpn broken'})</option>
3178 <option value='768' $checked {'ESP_GROUPTYPE'}{'768'}>MODP-768 ( $Lang ::tr{'vpn broken'})</option>
3179 <option value='none' $checked {'ESP_GROUPTYPE'}{'none'}>- $Lang ::tr{'none'} -</option>
3188 <h2> $Lang ::tr{'dead peer detection'}</h2>
3190 <table width="100%">
3192 <td width="15%"> $Lang ::tr{'dpd action'}:</td>
3194 <select name='DPD_ACTION'>
3195 <option value='none' $selected {'DPD_ACTION'}{'none'}>- $Lang ::tr{'disabled'} -</option>
3196 <option value='clear' $selected {'DPD_ACTION'}{'clear'}>clear</option>
3197 <option value='hold' $selected {'DPD_ACTION'}{'hold'}>hold</option>
3198 <option value='restart' $selected {'DPD_ACTION'}{'restart'}>restart</option>
3203 <td width="15%"> $Lang ::tr{'dpd timeout'}: <img src='/blob.gif' alt='*' /></td>
3205 <input type='text' name='DPD_TIMEOUT' size='5' value=' $cgiparams {'DPD_TIMEOUT'}' />
3209 <td width="15%"> $Lang ::tr{'dpd delay'}: <img src='/blob.gif' alt='*' /></td>
3211 <input type='text' name='DPD_DELAY' size='5' value=' $cgiparams {'DPD_DELAY'}' />
3218 <table width="100%">
3222 <input type='checkbox' name='ONLY_PROPOSED' $checked {'ONLY_PROPOSED'} />
3223 IKE+ESP: $Lang ::tr{'use only proposed settings'}
3227 <label> $Lang ::tr{'vpn start action'}</label>
3228 <select name="START_ACTION">
3229 <option value="route" $selected {'START_ACTION'}{'route'}> $Lang ::tr{'vpn start action route'}</option>
3230 <option value="start" $selected {'START_ACTION'}{'start'}> $Lang ::tr{'vpn start action start'}</option>
3231 <option value="add" $selected {'START_ACTION'}{'add'} > $Lang ::tr{'vpn start action add'}</option>
3238 <input type='checkbox' name='PFS' $checked {'PFS'} />
3239 $Lang ::tr{'pfs yes no'}
3243 <label> $Lang ::tr{'vpn inactivity timeout'}</label>
3244 <select name="INACTIVITY_TIMEOUT">
3246 foreach my $t ( sort { $a <=> $b } keys %INACTIVITY_TIMEOUTS ) {
3247 print "<option value= \" $t \" $selected {'INACTIVITY_TIMEOUT'}{ $t }> $INACTIVITY_TIMEOUTS { $t }</option> \n " ;
3258 <input type='checkbox' name='COMPRESSION' $checked {'COMPRESSION'} />
3259 $Lang ::tr{'vpn payload compression'}
3266 <input type='checkbox' name='FORCE_MOBIKE' $checked {'FORCE_MOBIKE'} />
3267 $Lang ::tr{'vpn force mobike'}
3272 <td align='left'><img src='/blob.gif' align='top' alt='*' /> $Lang ::tr{'required field'}</td>
3274 <input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />
3275 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' />
3281 & Header
:: closebox
();
3282 & Header
:: closebigbox
();
3283 & Header
:: closepage
();
3290 ### Default status page
3295 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%cgiparams );
3296 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
3297 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
3298 $cgiparams { 'CA_NAME' } = '' ;
3300 my @status = & General
:: system_output
( "/usr/local/bin/ipsecctrl" , "I" );
3302 $checked { 'ENABLED' } = $cgiparams { 'ENABLED' } eq 'on' ?
"checked='checked'" : '' ;
3304 & Header
:: showhttpheaders
();
3305 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
3306 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
3308 if ( $errormessage ) {
3309 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
3310 print "<class name='base'> $errormessage \n " ;
3311 print " </class> \n " ;
3312 & Header
:: closebox
();
3316 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
3317 print " $warnmessage <br>" ;
3318 print " $Lang ::tr{'fwdfw warn1'}<br>" ;
3319 & Header
:: closebox
();
3320 print "<center><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'ok'}' style='width: 5em;'></form>" ;
3321 & Header
:: closepage
();
3325 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'global settings' });
3327 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3328 <table width='100%'>
3330 <td width='60%' class='base'>
3331 $Lang ::tr{'enabled'}
3334 <input type='checkbox' name='ENABLED' $checked {'ENABLED'} />
3338 <td class='base' nowrap='nowrap' width="60%"> $Lang ::tr{'ipsec roadwarrior endpoint'}:</td>
3339 <td width="40%"><input type='text' name='RW_ENDPOINT' value=' $cgiparams {'RW_ENDPOINT'}' /></td>
3342 <td class='base' nowrap='nowrap' width="60%"> $Lang ::tr{'host to net vpn'}:</td>
3343 <td width="40%"><input type='text' name='RW_NET' value=' $cgiparams {'RW_NET'}' /></td>
3346 <td width='100%' colspan="2" align='right' class='base'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' /></td>
3352 & Header
:: closebox
();
3354 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection status and controlc' });
3356 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
3358 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
3359 <th width='22%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></th>
3360 <th width='23%' class='boldbase' align='center'><b> $Lang ::tr{'common name'}</b></th>
3361 <th width='30%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></th>
3362 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></th>
3363 <th class='boldbase' align='center' colspan='7'><b> $Lang ::tr{'action'}</b></th>
3369 foreach my $key ( sort { ncmp
( $confighash { $a }[ 1 ], $confighash { $b }[ 1 ]) } keys %confighash ) {
3370 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
3374 $col = "bgcolor=' $color {'color20'}'" ;
3377 $col = "bgcolor=' $color {'color22'}'" ;
3379 print "<td align='center' nowrap='nowrap' $col > $confighash { $key }[1]</td>" ;
3380 print "<td align='center' nowrap='nowrap' $col >" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ") $confighash { $key }[29]</td>" ;
3381 if ( $confighash { $key }[ 2 ] eq ' %auth -dn' ) {
3382 print "<td align='left' nowrap='nowrap' $col > $confighash { $key }[9]</td>" ;
3383 } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
3384 print "<td align='left' nowrap='nowrap' $col > $confighash { $key }[2]</td>" ;
3386 print "<td align='left' $col > </td>" ;
3388 print "<td align='center' $col > $confighash { $key }[25]</td>" ;
3389 my $col1 = "bgcolor='${Header::colourred}'" ;
3390 my $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
3391 if ( $confighash { $key }[ 33 ] eq "add" ) {
3392 $col1 = "bgcolor='${Header::colourorange}'" ;
3393 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'vpn wait'}</font></b>" ;
3395 foreach my $line ( @status ) {
3396 if (( $line =~ /\"$confighash{$key}[1]\".*IPsec SA established/ ) ||
3397 ( $line =~ /$confighash{$key}[1]\{.*INSTALLED/ )) {
3398 $col1 = "bgcolor='${Header::colourgreen}'" ;
3399 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b>" ;
3401 } elsif ( $line =~ /$confighash{$key}[1]\[.*CONNECTING/ ) {
3402 $col1 = "bgcolor='${Header::colourorange}'" ;
3403 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'vpn connecting'}</font></b>" ;
3404 } elsif ( $line =~ /$confighash{$key}[1]\{.*ROUTED/ ) {
3405 $col1 = "bgcolor='${Header::colourorange}'" ;
3406 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'vpn on-demand'}</font></b>" ;
3409 # move to blue if really down
3410 if ( $confighash { $key }[ 0 ] eq 'off' && $col1 =~ /${Header::colourred}/ ) {
3411 $col1 = "bgcolor='${Header::colourblue}'" ;
3412 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
3415 <td align='center' $col1 > $active </td>
3416 <td align='center' $col >
3417 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3418 <input type='image' name=' $Lang ::tr{'restart'}' src='/images/reload.gif' alt=' $Lang ::tr{'restart'}' title=' $Lang ::tr{'restart'}' />
3419 <input type='hidden' name='ACTION' value=' $Lang ::tr{'restart'}' />
3420 <input type='hidden' name='KEY' value=' $key ' />
3425 if (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
3427 <td align='center' $col >
3428 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3429 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' />
3430 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
3431 <input type='hidden' name='KEY' value=' $key ' />
3437 print "<td width='2%' $col > </td>" ;
3439 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/certs/ $confighash { $key }[1].p12" ) {
3441 <td align='center' $col >
3442 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3443 <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'}' />
3444 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
3445 <input type='hidden' name='KEY' value=' $key ' />
3450 } elsif (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
3452 <td align='center' $col >
3453 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3454 <input type='image' name=' $Lang ::tr{'download certificate'}' src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' title=' $Lang ::tr{'download certificate'}' />
3455 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
3456 <input type='hidden' name='KEY' value=' $key ' />
3462 print "<td width='2%' $col > </td>" ;
3466 if ( $confighash { $key }[ 3 ] eq 'host' ) {
3468 <td align='center' $col >
3469 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3470 <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'}' />
3471 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download apple profile'}' />
3472 <input type='hidden' name='KEY' value=' $key ' />
3477 print "<td width='2%' $col > </td>" ;
3481 <td align='center' $col >
3482 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3483 <input type='image' name=' $Lang ::tr{'toggle enable disable'}' src='/images/ $gif ' alt=' $Lang ::tr{'toggle enable disable'}' title=' $Lang ::tr{'toggle enable disable'}' />
3484 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
3485 <input type='hidden' name='KEY' value=' $key ' />
3489 <td align='center' $col >
3490 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3491 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
3492 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' title=' $Lang ::tr{'edit'}' />
3493 <input type='hidden' name='KEY' value=' $key ' />
3496 <td align='center' $col >
3497 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3498 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
3499 <input type='image' name=' $Lang ::tr{'remove'}' src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' title=' $Lang ::tr{'remove'}' />
3500 <input type='hidden' name='KEY' value=' $key ' />
3510 # If the config file contains entries, print Key to action icons
3515 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
3516 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
3517 <td class='base'> $Lang ::tr{'click to disable'}</td>
3518 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
3519 <td class='base'> $Lang ::tr{'show certificate'}</td>
3520 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
3521 <td class='base'> $Lang ::tr{'edit'}</td>
3522 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
3523 <td class='base'> $Lang ::tr{'remove'}</td>
3527 <td> <img src='/images/off.gif' alt='?OFF' /></td>
3528 <td class='base'> $Lang ::tr{'click to enable'}</td>
3529 <td> <img src='/images/floppy.gif' alt='?FLOPPY' /></td>
3530 <td class='base'> $Lang ::tr{'download certificate'}</td>
3531 <td> <img src='/images/reload.gif' alt='?RELOAD'/></td>
3532 <td class='base'> $Lang ::tr{'restart'}</td>
3540 <table width='100%'>
3541 <tr><td align='right' colspan='9'>
3542 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3543 <input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />
3549 & Header
:: closebox
();
3551 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'certificate authorities'}" );
3553 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
3555 <th width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
3556 <th width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></th>
3557 <th width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></th>
3561 my $col1 = "bgcolor=' $color {'color22'}'" ;
3562 my $col2 = "bgcolor=' $color {'color20'}'" ;
3563 if (- f
"${General::swroot}/ca/cacert.pem" ) {
3564 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/cacert.pem" ));
3567 <td class='base' $col1 > $Lang ::tr{'root certificate'}</td>
3568 <td class='base' $col1 > $casubject </td>
3569 <td width='3%' align='center' $col1 >
3570 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3571 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
3572 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/info.gif' alt=' $Lang ::tr{'show root certificate'}' title=' $Lang ::tr{'show root certificate'}' />
3575 <td width='3%' align='center' $col1 >
3576 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3577 <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'}' />
3578 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
3581 <td width='4%' $col1 > </td></tr>
3585 # display rootcert generation buttons
3588 <td class='base' $col1 > $Lang ::tr{'root certificate'}:</td>
3589 <td class='base' $col1 > $Lang ::tr{'not present'}</td>
3590 <td colspan='3' $col1 > </td></tr>
3595 if (- f
"${General::swroot}/certs/hostcert.pem" ) {
3596 my $hostsubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/certs/hostcert.pem" ));
3600 <td class='base' $col2 > $Lang ::tr{'host certificate'}</td>
3601 <td class='base' $col2 > $hostsubject </td>
3602 <td width='3%' align='center' $col2 >
3603 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3604 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
3605 <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'}' />
3608 <td width='3%' align='center' $col2 >
3609 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3610 <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'}" />
3611 <input type='hidden' name='ACTION' value=" $Lang ::tr{'download host certificate'}" />
3614 <td width='4%' $col2 > </td></tr>
3621 <td width='25%' class='base' $col2 > $Lang ::tr{'host certificate'}:</td>
3622 <td class='base' $col2 > $Lang ::tr{'not present'}</td>
3623 <td colspan='3' $col2 > </td></tr>
3629 if ( keys %cahash > 0 ) {
3630 foreach my $key ( keys %cahash ) {
3631 if ( $rowcolor ++ % 2 ) {
3633 $col = "bgcolor=' $color {'color20'}'" ;
3636 $col = "bgcolor=' $color {'color22'}'" ;
3638 print "<td class='base' $col > $cahash { $key }[0]</td> \n " ;
3639 print "<td class='base' $col > $cahash { $key }[1]</td> \n " ;
3641 <td align='center' $col >
3642 <form method='post' name='cafrm${key}a' action=' $ENV {'SCRIPT_NAME'}'>
3643 <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'}' />
3644 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
3645 <input type='hidden' name='KEY' value=' $key ' />
3648 <td align='center' $col >
3649 <form method='post' name='cafrm${key}b' action=' $ENV {'SCRIPT_NAME'}'>
3650 <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'}' />
3651 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
3652 <input type='hidden' name='KEY' value=' $key ' />
3655 <td align='center' $col >
3656 <form method='post' name='cafrm${key}c' action=' $ENV {'SCRIPT_NAME'}'>
3657 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
3658 <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'}' />
3659 <input type='hidden' name='KEY' value=' $key ' />
3669 # If the file contains entries, print Key to action icons
3670 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
3673 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
3674 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
3675 <td class='base'> $Lang ::tr{'show certificate'}</td>
3676 <td> <img src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' /></td>
3677 <td class='base'> $Lang ::tr{'download certificate'}</td>
3682 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>" ;
3686 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
3687 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
3690 <td class='base' nowrap='nowrap'> $Lang ::tr{'ca name'}: <img src='/blob.gif' alt='*' /></td>
3691 <td nowrap='nowrap'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' /> </td>
3692 <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td>
3693 <td nowrap='nowrap'><input type='submit' name='ACTION' value=' $Lang ::tr{'upload ca certificate'}' /></td>
3696 <td colspan='3'> $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}:</td>
3697 <td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' /></td>
3703 & Header
:: closebox
();
3704 & Header
:: closebigbox
();
3705 & Header
:: closepage
();
3707 sub array_unique
($) {
3712 foreach my $e ( @
$array ) {
3713 next if $seen { $e }++;
3720 sub make_algos
($$$$$) {
3721 my ( $mode , $encs , $ints , $grps , $pfs ) = @_ ;
3724 foreach my $enc ( @
$encs ) {
3725 foreach my $int ( @
$ints ) {
3726 foreach my $grp ( @
$grps ) {
3729 if ( $mode eq "ike" ) {
3732 if ( $grp =~ m/^e(.*)$/ ) {
3733 push ( @algo , "ecp $1 " );
3734 } elsif ( $grp =~ m/curve(448|25519)/ ) {
3735 push ( @algo , " $grp " );
3737 push ( @algo , "modp $grp " );
3740 } elsif ( $mode eq "esp" ) {
3741 my $is_aead = ( $enc =~ m/[cg]cm/ );
3747 if (! $pfs || $grp eq "none" ) {
3749 } elsif ( $grp =~ m/^e(.*)$/ ) {
3750 push ( @algo , "ecp $1 " );
3751 } elsif ( $grp =~ m/curve(448|25519)/ ) {
3752 push ( @algo , " $grp " );
3754 push ( @algo , "modp $grp " );
3758 push ( @algos , join ( "-" , @algo ));
3763 return & array_unique
( \
@algos );
3766 sub make_subnets
($$) {
3767 my $direction = shift ;
3768 my $subnets = shift ;
3770 my @nets = split ( /\|/ , $subnets );
3772 foreach my $net ( @nets ) {
3773 my $cidr_net = & General
:: ipcidr
( $net );
3775 # Skip 0.0.0.0/0 for remote because this renders the
3776 # while system inaccessible
3777 next if (( $direction eq "right" ) && ( $cidr_net eq "0.0.0.0/0" ));
3779 push ( @cidr_nets , $cidr_net );
3782 return join ( "," , @cidr_nets );