]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/vpnmain.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2020 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 & Header
:: getcgihash
( \
%cgiparams , { 'wantfile' => 1 , 'filevar' => 'FH' });
133 my $hostname = $_ [ 0 ];
134 unless ( $hostname ) { return "No hostname" };
135 my $res = new Net
:: DNS
:: Resolver
;
136 my $query = $res -> search ( " $hostname " );
138 foreach my $rr ( $query -> answer ) {
139 ## Potential bug - we are only looking at A records:
140 return 0 if $rr -> type eq "A" ;
143 return $res -> errorstring ;
147 ### Just return true is one interface is vpn enabled
150 return ( $vpnsettings { 'ENABLED' } eq 'on' );
153 ### old version: maintain serial number to one, without explication.
154 ### this: let the counter go, so that each cert is numbered.
156 sub cleanssldatabase
{
157 if ( open ( FILE
, ">${General::swroot}/certs/serial" )) {
161 if ( open ( FILE
, ">${General::swroot}/certs/index.txt" )) {
165 if ( open ( FILE
, ">${General::swroot}/certs/index.txt.attr" )) {
169 unlink ( "${General::swroot}/certs/index.txt.old" );
170 unlink ( "${General::swroot}/certs/index.txt.attr.old" );
171 unlink ( "${General::swroot}/certs/serial.old" );
172 unlink ( "${General::swroot}/certs/01.pem" );
174 sub newcleanssldatabase
{
175 if (! - s
"${General::swroot}/certs/serial" ) {
176 open ( FILE
, ">${General::swroot}/certs/serial" );
180 if (! - s
">${General::swroot}/certs/index.txt" ) {
181 system ( "touch ${General::swroot}/certs/index.txt" );
183 if (! - s
">${General::swroot}/certs/index.txt.attr" ) {
184 system ( "touch ${General::swroot}/certs/index.txt.attr" );
186 unlink ( "${General::swroot}/certs/index.txt.old" );
187 unlink ( "${General::swroot}/certs/index.txt.attr.old" );
188 unlink ( "${General::swroot}/certs/serial.old" );
189 # unlink ("${General::swroot}/certs/01.pem"); numbering evolves. Wrong place to delete
193 ### Call openssl and return errormessage if any
197 my $retssl = `/usr/bin/openssl $opt 2>&1` ; #redirect stderr
199 foreach my $line ( split ( /\n/ , $retssl )) {
200 & General
:: log ( "ipsec" , " $line " ) if ( 0 ); # 1 for verbose logging
201 $ret .= '<br>' . $line if ( $line =~ /error|unknown/ );
204 $ret = & Header
:: cleanhtml
( $ret );
206 return $ret ?
" $Lang ::tr{'openssl produced an error'}: $ret " : '' ;
209 ### Obtain a CN from given cert
211 sub getCNfromcert
($) {
212 #&General::log("ipsec", "Extracting name from $_[0]...");
213 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
214 $temp =~ /Subject:.*CN = (.*)[\n]/ ;
216 $temp =~ s
+/ Email
+, E
+;
217 $temp =~ s/ ST = / S = / ;
223 ### Obtain Subject from given cert
225 sub getsubjectfromcert
($) {
226 #&General::log("ipsec", "Extracting subject from $_[0]...");
227 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
228 $temp =~ /Subject: (.*)[\n]/ ;
230 $temp =~ s
+/ Email
+, E
+;
231 $temp =~ s/ ST = / S = / ;
235 ### Combine local subnet and connection name to make a unique name for each connection section
236 ### (this sub is not used now)
238 sub makeconnname
($) {
242 $subnet =~ /^(.*?)\/ (.* ?
)$/; # $1=IP $2=mask
243 my $ip = unpack ( 'N' , & Socket
:: inet_aton
( $1 ));
244 if ( length ( $2 ) > 2 ) {
245 my $mm = unpack ( 'N' , & Socket
:: inet_aton
( $2 ));
246 while ( ( $mm & 1 )== 0 ) {
253 return sprintf ( " %s - %X " , $conn , $ip );
256 ### Write a config file.
258 ###Type=Host : GUI can choose the interface used (RED,GREEN,BLUE) and
259 ### the side is always defined as 'left'.
262 sub writeipsecfiles
{
263 my %lconfighash = ();
264 my %lvpnsettings = ();
265 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%lconfighash );
266 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%lvpnsettings );
268 open ( CONF
, ">${General::swroot}/vpn/ipsec.conf" ) or die "Unable to open ${General::swroot}/vpn/ipsec.conf: $!" ;
269 open ( SECRETS
, ">${General::swroot}/vpn/ipsec.secrets" ) or die "Unable to open ${General::swroot}/vpn/ipsec.secrets: $!" ;
272 print CONF
"version 2 \n\n " ;
273 print CONF
"conn %default \n " ;
274 print CONF
" \t keyingtries= %forever \n " ;
277 # Add user includes to config file
278 if (- e
"/etc/ipsec.user.conf" ) {
279 print CONF
"include /etc/ipsec.user.conf \n " ;
283 print SECRETS
"include /etc/ipsec.user.secrets \n " ;
285 if (- f
"${General::swroot}/certs/hostkey.pem" ) {
286 print SECRETS
": RSA ${General::swroot}/certs/hostkey.pem \n "
288 my $last_secrets = '' ; # old the less specifics connections
290 foreach my $key ( keys %lconfighash ) {
291 next if ( $lconfighash { $key }[ 0 ] ne 'on' );
293 #remote peer is not set? => use '%any'
294 $lconfighash { $key }[ 10 ] = ' %any ' if ( $lconfighash { $key }[ 10 ] eq '' );
296 # Field 6 might be "off" on old installations
297 if ( $lconfighash { $key }[ 6 ] eq "off" ) {
298 $lconfighash { $key }[ 6 ] = $lvpnsettings { "VPN_IP" };
302 if ( $lconfighash { $key }[ 6 ]) {
303 $localside = $lconfighash { $key }[ 6 ];
305 $localside = " %defaultroute " ;
308 my $interface_mode = $lconfighash { $key }[ 36 ];
310 print CONF
"conn $lconfighash { $key }[1] \n " ;
311 print CONF
" \t left= $localside \n " ;
313 if ( $interface_mode eq "gre" ) {
314 print CONF
" \t leftprotoport=gre \n " ;
315 } elsif ( $interface_mode eq "vti" ) {
316 print CONF
" \t leftsubnet=0.0.0.0/0 \n " ;
318 print CONF
" \t leftsubnet=" . & make_subnets
( "left" , $lconfighash { $key }[ 8 ]) . " \n " ;
321 print CONF
" \t leftfirewall=yes \n " ;
322 print CONF
" \t lefthostaccess=yes \n " ;
323 print CONF
" \t right= $lconfighash { $key }[10] \n " ;
325 if ( $lconfighash { $key }[ 3 ] eq 'net' ) {
326 if ( $interface_mode eq "gre" ) {
327 print CONF
" \t rightprotoport=gre \n " ;
328 } elsif ( $interface_mode eq "vti" ) {
329 print CONF
" \t rightsubnet=0.0.0.0/0 \n " ;
331 print CONF
" \t rightsubnet=" . & make_subnets
( "right" , $lconfighash { $key }[ 11 ]) . " \n " ;
335 # Local Cert and Remote Cert (unless auth is DN dn-auth)
336 if ( $lconfighash { $key }[ 4 ] eq 'cert' ) {
337 print CONF
" \t leftcert=${General::swroot}/certs/hostcert.pem \n " ;
338 print CONF
" \t rightcert=${General::swroot}/certs/ $lconfighash { $key }[1]cert.pem \n " if ( $lconfighash { $key }[ 2 ] ne ' %auth -dn' );
341 # Local and Remote IDs
342 print CONF
" \t leftid= \" $lconfighash { $key }[7] \"\n " if ( $lconfighash { $key }[ 7 ]);
343 print CONF
" \t rightid= \" $lconfighash { $key }[9] \"\n " if ( $lconfighash { $key }[ 9 ]);
346 if ( $lconfighash { $key }[ 35 ] eq "transport" ) {
347 print CONF
" \t type=transport \n " ;
349 print CONF
" \t type=tunnel \n " ;
353 if ( $interface_mode eq "vti" ) {
354 print CONF
" \t mark= $key \n " ;
358 my $pfs = $lconfighash { $key }[ 28 ] eq 'on' ?
'on' : 'off' ;
361 if ( $lconfighash { $key }[ 18 ] && $lconfighash { $key }[ 19 ] && $lconfighash { $key }[ 20 ]) {
362 my @encs = split ( '\|' , $lconfighash { $key }[ 18 ]);
363 my @ints = split ( '\|' , $lconfighash { $key }[ 19 ]);
364 my @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
366 my @algos = & make_algos
( "ike" , \
@encs , \
@ints , \
@groups , 1 );
367 print CONF
" \t ike=" . join ( "," , @algos );
369 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
376 if ( $lconfighash { $key }[ 21 ] && $lconfighash { $key }[ 22 ]) {
377 my @encs = split ( '\|' , $lconfighash { $key }[ 21 ]);
378 my @ints = split ( '\|' , $lconfighash { $key }[ 22 ]);
379 my @groups = split ( '\|' , $lconfighash { $key }[ 23 ]);
381 # Use IKE grouptype if no ESP group type has been selected
382 # (for backwards compatibility)
383 if ( $lconfighash { $key }[ 23 ] eq "" ) {
384 @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
387 my @algos = & make_algos
( "esp" , \
@encs , \
@ints , \
@groups , ( $pfs eq "on" ));
388 print CONF
" \t esp=" . join ( "," , @algos );
390 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
398 if (! $lconfighash { $key }[ 29 ]) {
399 $lconfighash { $key }[ 29 ] = "ikev1" ;
402 print CONF
" \t keyexchange= $lconfighash { $key }[29] \n " ;
405 print CONF
" \t ikelifetime= $lconfighash { $key }[16]h \n " if ( $lconfighash { $key }[ 16 ]);
406 print CONF
" \t keylife= $lconfighash { $key }[17]h \n " if ( $lconfighash { $key }[ 17 ]);
409 print CONF
" \t compress=yes \n " if ( $lconfighash { $key }[ 13 ] eq 'on' );
412 if (( $lconfighash { $key }[ 29 ] eq "ikev2" ) && ( $lconfighash { $key }[ 32 ] eq 'on' )) {
413 print CONF
" \t mobike=yes \n " ;
416 # Dead Peer Detection
417 my $dpdaction = $lconfighash { $key }[ 27 ];
418 print CONF
" \t dpdaction= $dpdaction \n " ;
420 # If the dead peer detection is disabled and IKEv2 is used,
421 # dpddelay must be set to zero, too.
422 if ( $dpdaction eq "none" ) {
423 if ( $lconfighash { $key }[ 29 ] eq "ikev2" ) {
424 print CONF
" \t dpddelay=0 \n " ;
427 my $dpddelay = $lconfighash { $key }[ 31 ];
431 print CONF
" \t dpddelay= $dpddelay \n " ;
432 my $dpdtimeout = $lconfighash { $key }[ 30 ];
436 print CONF
" \t dpdtimeout= $dpdtimeout \n " ;
439 # Build Authentication details: LEFTid RIGHTid : PSK psk
441 if ( $lconfighash { $key }[ 4 ] eq 'psk' ) {
442 $psk_line = ( $lconfighash { $key }[ 7 ] ?
$lconfighash { $key }[ 7 ] : $localside ) . " " ;
443 $psk_line .= $lconfighash { $key }[ 9 ] ?
$lconfighash { $key }[ 9 ] : $lconfighash { $key }[ 10 ]; #remoteid or remote address?
444 $psk_line .= " : PSK ' $lconfighash { $key }[5]' \n " ;
445 # if the line contains %any, it is less specific than two IP or ID, so move it at end of file.
446 if ( $psk_line =~ /%any/ ) {
447 $last_secrets .= $psk_line ;
449 print SECRETS
$psk_line ;
451 print CONF
" \t authby=secret \n " ;
453 print CONF
" \t authby=rsasig \n " ;
454 print CONF
" \t leftrsasigkey= %cert \n " ;
455 print CONF
" \t rightrsasigkey= %cert \n " ;
458 my $start_action = $lconfighash { $key }[ 33 ];
459 if (! $start_action ) {
460 $start_action = "start" ;
463 my $inactivity_timeout = $lconfighash { $key }[ 34 ];
464 if ( $inactivity_timeout eq "" ) {
465 $inactivity_timeout = 900 ;
468 # Automatically start only if a net-to-net connection
469 if ( $lconfighash { $key }[ 3 ] eq 'host' ) {
470 print CONF
" \t auto=add \n " ;
471 print CONF
" \t rightsourceip= $lvpnsettings {'RW_NET'} \n " ;
473 print CONF
" \t auto= $start_action \n " ;
475 # If in on-demand mode, we terminate the tunnel
476 # after 15 min of no traffic
477 if ( $start_action eq 'route' && $inactivity_timeout > 0 ) {
478 print CONF
" \t inactivity= $inactivity_timeout \n " ;
483 print CONF
" \t fragmentation=yes \n " ;
488 # Add post user includes to config file
489 # After the GUI-connections allows to patch connections.
490 if (- e
"/etc/ipsec.user-post.conf" ) {
491 print CONF
"include /etc/ipsec.user-post.conf \n " ;
495 print SECRETS
$last_secrets if ( $last_secrets );
500 # Hook to regenerate the configuration files.
501 if ( $ENV { "REMOTE_ADDR" } eq "" ) {
507 ### Save main settings
509 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
510 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
512 if ( $cgiparams { 'RW_ENDPOINT' } ne '' && !& General
:: validip
( $cgiparams { 'RW_ENDPOINT' }) && !& General
:: validfqdn
( $cgiparams { 'RW_ENDPOINT' })) {
513 $errormessage = $Lang :: tr
{ 'ipsec invalid ip address or fqdn for rw endpoint' };
517 if ( $cgiparams { 'RW_NET' } ne '' and !& General
:: validipandmask
( $cgiparams { 'RW_NET' }) ) {
518 $errormessage = $Lang :: tr
{ 'urlfilter invalid ip or mask error' };
522 $vpnsettings { 'ENABLED' } = $cgiparams { 'ENABLED' };
523 $vpnsettings { 'RW_ENDPOINT' } = $cgiparams { 'RW_ENDPOINT' };
524 $vpnsettings { 'RW_NET' } = $cgiparams { 'RW_NET' };
525 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
528 system ( '/usr/local/bin/ipsecctrl' , 'S' );
530 system ( '/usr/local/bin/ipsecctrl' , 'D' );
537 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
538 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
540 foreach my $key ( keys %confighash ) {
541 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
542 delete $confighash { $key };
545 while ( my $file = glob ( "${General::swroot}/{ca,certs,crls,private}/*" )) {
549 if ( open ( FILE
, ">${General::swroot}/vpn/caconfig" )) {
553 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
555 system ( '/usr/local/bin/ipsecctrl' , 'R' );
561 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' }) {
562 & Header
:: showhttpheaders
();
563 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
564 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
565 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
567 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
571 <input type='hidden' name='AREUSURE' value='yes' />
572 <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'}
576 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' />
577 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
584 & Header
:: closebigbox
();
585 & Header
:: closepage
();
589 ### Upload CA Certificate
591 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
592 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
594 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
595 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
599 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
600 $errormessage = $Lang :: tr
{ 'name too long' };
604 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
605 $errormessage = $Lang :: tr
{ 'name is invalid' };
606 goto UPLOAD_CA_ERROR
;
609 # Check if there is no other entry with this name
610 foreach my $key ( keys %cahash ) {
611 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
612 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
617 unless ( ref ( $cgiparams { 'FH' })) {
618 $errormessage = $Lang :: tr
{ 'there was no file upload' };
621 # Move uploaded ca to a temporary file
622 ( my $fh , my $filename ) = tempfile
( );
623 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
627 my $temp = `/usr/bin/openssl x509 -text -in $filename ` ;
628 if ( $temp !~ /CA:TRUE/i ) {
629 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
633 move
( $filename , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
635 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
641 my $key = & General
:: findhasharraykey
( \
%cahash );
642 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
643 $cahash { $key }[ 1 ] = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" ));
644 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
646 system ( '/usr/local/bin/ipsecctrl' , 'R' );
652 ### Display ca certificate
654 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
655 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
657 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
658 & Header
:: showhttpheaders
();
659 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
660 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
661 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'ca certificate'}:" );
662 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
663 $output = & Header
:: cleanhtml
( $output , "y" );
664 print "<pre> $output </pre> \n " ;
666 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
667 & Header
:: closebigbox
();
668 & Header
:: closepage
();
671 $errormessage = $Lang :: tr
{ 'invalid key' };
675 ### Export ca certificate to browser
677 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
678 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
680 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
681 print "Content-Type: application/force-download \n " ;
682 print "Content-Type: application/octet-stream \r\n " ;
683 print "Content-Disposition: attachment; filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
684 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
687 $errormessage = $Lang :: tr
{ 'invalid key' };
691 ### Remove ca certificate (step 2)
693 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
694 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
695 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
697 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
698 foreach my $key ( keys %confighash ) {
699 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
700 if ( $test =~ /: OK/ ) {
702 unlink ( "${General::swroot}/certs/ $confighash { $key }[1]cert.pem" );
703 unlink ( "${General::swroot}/certs/ $confighash { $key }[1].p12" );
704 delete $confighash { $key };
705 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
707 system ( '/usr/local/bin/ipsecctrl' , 'D' , $key ) if (& vpnenabled
);
710 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
711 delete $cahash { $cgiparams { 'KEY' }};
712 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
713 system ( '/usr/local/bin/ipsecctrl' , 'R' );
716 $errormessage = $Lang :: tr
{ 'invalid key' };
719 ### Remove ca certificate (step 1)
721 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
722 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
723 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
725 my $assignedcerts = 0 ;
726 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
727 foreach my $key ( keys %confighash ) {
728 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
729 if ( $test =~ /: OK/ ) {
733 if ( $assignedcerts ) {
734 & Header
:: showhttpheaders
();
735 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
736 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
737 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
739 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
743 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
744 <input type='hidden' name='AREUSURE' value='yes' /></td>
747 <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>
750 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
751 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
758 & Header
:: closebigbox
();
759 & Header
:: closepage
();
762 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
763 delete $cahash { $cgiparams { 'KEY' }};
764 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
765 system ( '/usr/local/bin/ipsecctrl' , 'R' );
769 $errormessage = $Lang :: tr
{ 'invalid key' };
773 ### Display root certificate
775 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
776 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
778 & Header
:: showhttpheaders
();
779 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
780 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
781 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
782 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'root certificate'}:" );
783 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/cacert.pem` ;
785 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'host certificate'}:" );
786 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/hostcert.pem` ;
788 $output = & Header
:: cleanhtml
( $output , "y" );
789 print "<pre> $output </pre> \n " ;
791 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
792 & Header
:: closebigbox
();
793 & Header
:: closepage
();
797 ### Export root certificate to browser
799 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
800 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
801 print "Content-Type: application/force-download \n " ;
802 print "Content-Disposition: attachment; filename=cacert.pem \r\n\r\n " ;
803 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/cacert.pem` ;
807 ### Export host certificate to browser
809 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
810 if ( - f
"${General::swroot}/certs/hostcert.pem" ) {
811 print "Content-Type: application/force-download \n " ;
812 print "Content-Disposition: attachment; filename=hostcert.pem \r\n\r\n " ;
813 print `/usr/bin/openssl x509 -in ${General::swroot}/certs/hostcert.pem` ;
817 ### Form for generating/importing the caroot+host certificate
819 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
820 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
822 if (- f
"${General::swroot}/ca/cacert.pem" ) {
823 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
827 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
828 # fill in initial values
829 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
830 if (- e
"${General::swroot}/red/active" && open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
831 my $ipaddr = < IPADDR
>;
834 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
835 $cgiparams { 'SUBJECTALTNAME' } = "DNS:" . $cgiparams { 'ROOTCERT_HOSTNAME' };
836 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
837 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
838 $cgiparams { 'SUBJECTALTNAME' } = "IP:" . $cgiparams { 'ROOTCERT_HOSTNAME' };
841 $cgiparams { 'ROOTCERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' } if (! $cgiparams { 'ROOTCERT_COUNTRY' });
842 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
843 & General
:: log ( "ipsec" , "Importing from p12..." );
845 unless ( ref ( $cgiparams { 'FH' })) {
846 $errormessage = $Lang :: tr
{ 'there was no file upload' };
850 # Move uploaded certificate request to a temporary file
851 ( my $fh , my $filename ) = tempfile
( );
852 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
857 # Extract the CA certificate from the file
858 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
859 if ( open ( STDIN
, "-|" )) {
860 my $opt = " pkcs12 -cacerts -nokeys" ;
861 $opt .= " -in $filename " ;
862 $opt .= " -out /tmp/newcacert" ;
863 $errormessage = & callssl
( $opt );
865 print " $cgiparams {'P12_PASS'} \n " ;
869 # Extract the Host certificate from the file
870 if (! $errormessage ) {
871 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
872 if ( open ( STDIN
, "-|" )) {
873 my $opt = " pkcs12 -clcerts -nokeys" ;
874 $opt .= " -in $filename " ;
875 $opt .= " -out /tmp/newhostcert" ;
876 $errormessage = & callssl
( $opt );
878 print " $cgiparams {'P12_PASS'} \n " ;
883 # Extract the Host key from the file
884 if (! $errormessage ) {
885 & General
:: log ( "ipsec" , "Extracting private key from p12..." );
886 if ( open ( STDIN
, "-|" )) {
887 my $opt = " pkcs12 -nocerts -nodes" ;
888 $opt .= " -in $filename " ;
889 $opt .= " -out /tmp/newhostkey" ;
890 $errormessage = & callssl
( $opt );
892 print " $cgiparams {'P12_PASS'} \n " ;
897 if (! $errormessage ) {
898 & General
:: log ( "ipsec" , "Moving cacert..." );
899 move
( "/tmp/newcacert" , "${General::swroot}/ca/cacert.pem" );
900 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
903 if (! $errormessage ) {
904 & General
:: log ( "ipsec" , "Moving host cert..." );
905 move
( "/tmp/newhostcert" , "${General::swroot}/certs/hostcert.pem" );
906 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
909 if (! $errormessage ) {
910 & General
:: log ( "ipsec" , "Moving private key..." );
911 move
( "/tmp/newhostkey" , "${General::swroot}/certs/hostkey.pem" );
912 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
917 unlink ( '/tmp/newcacert' );
918 unlink ( '/tmp/newhostcert' );
919 unlink ( '/tmp/newhostkey' );
921 unlink ( "${General::swroot}/ca/cacert.pem" );
922 unlink ( "${General::swroot}/certs/hostcert.pem" );
923 unlink ( "${General::swroot}/certs/hostkey.pem" );
927 # Create empty CRL cannot be done because we don't have
928 # the private key for this CAROOT
929 # IPFire can only import certificates
931 & General
:: log ( "ipsec" , "p12 import completed!" );
933 goto ROOTCERT_SUCCESS
;
935 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
937 # Validate input since the form was submitted
938 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
939 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
942 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
943 $errormessage = $Lang :: tr
{ 'organization too long' };
946 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
947 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
950 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
951 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
954 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
955 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
958 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
959 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
962 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
963 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
966 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
967 $errormessage = $Lang :: tr
{ 'invalid input for department' };
970 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
971 $errormessage = $Lang :: tr
{ 'invalid input for city' };
974 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
975 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
978 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
979 $errormessage = $Lang :: tr
{ 'invalid input for country' };
982 #the exact syntax is a list comma separated of
983 # email:any-validemail
984 # URI: a uniform resource indicator
985 # DNS: a DNS domain name
986 # RID: a registered OBJECT IDENTIFIER
988 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
990 if ( $cgiparams { 'SUBJECTALTNAME' } eq '' ) {
991 $errormessage = $Lang :: tr
{ 'vpn subjectaltname missing' };
995 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
996 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
1000 # Copy the cgisettings to vpnsettings and save the configfile
1001 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
1002 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
1003 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
1004 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
1005 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
1006 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
1007 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
1008 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1010 # Replace empty strings with a .
1011 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
1012 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
1013 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
1015 # Create the CA certificate
1016 if (! $errormessage ) {
1017 & General
:: log ( "ipsec" , "Creating cacert..." );
1018 if ( open ( STDIN
, "-|" )) {
1019 my $opt = " req -x509 -sha256 -nodes" ;
1020 $opt .= " -days 3650" ;
1021 $opt .= " -newkey rsa:4096" ;
1022 $opt .= " -keyout ${General::swroot}/private/cakey.pem" ;
1023 $opt .= " -out ${General::swroot}/ca/cacert.pem" ;
1025 $errormessage = & callssl
( $opt );
1027 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1030 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1032 print " $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
1033 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1038 # Create the Host certificate request
1039 if (! $errormessage ) {
1040 & General
:: log ( "ipsec" , "Creating host cert..." );
1041 if ( open ( STDIN
, "-|" )) {
1042 my $opt = " req -sha256 -nodes" ;
1043 $opt .= " -newkey rsa:2048" ;
1044 $opt .= " -keyout ${General::swroot}/certs/hostkey.pem" ;
1045 $opt .= " -out ${General::swroot}/certs/hostreq.pem" ;
1046 $errormessage = & callssl
( $opt );
1048 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1051 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1053 print " $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
1054 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1061 # Sign the host certificate request
1062 if (! $errormessage ) {
1063 & General
:: log ( "ipsec" , "Self signing host cert..." );
1065 #No easy way for specifying the contain of subjectAltName without writing a config file...
1066 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1068 basicConstraints=CA:FALSE
1069 nsComment="OpenSSL Generated Certificate"
1070 subjectKeyIdentifier=hash
1071 authorityKeyIdentifier=keyid,issuer:always
1072 extendedKeyUsage = serverAuth
1075 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1078 my $opt = " ca -md sha256 -days 825" ;
1079 $opt .= " -batch -notext" ;
1080 $opt .= " -in ${General::swroot}/certs/hostreq.pem" ;
1081 $opt .= " -out ${General::swroot}/certs/hostcert.pem" ;
1082 $opt .= " -extfile $v3extname " ;
1083 $errormessage = & callssl
( $opt );
1084 unlink ( "${General::swroot}/certs/hostreq.pem" ); #no more needed
1085 unlink ( $v3extname );
1088 # Create an empty CRL
1089 if (! $errormessage ) {
1090 & General
:: log ( "ipsec" , "Creating emptycrl..." );
1091 my $opt = " ca -gencrl" ;
1092 $opt .= " -out ${General::swroot}/crls/cacrl.pem" ;
1093 $errormessage = & callssl
( $opt );
1096 # Successfully build CA / CERT!
1097 if (! $errormessage ) {
1098 & cleanssldatabase
();
1099 goto ROOTCERT_SUCCESS
;
1103 unlink ( "${General::swroot}/ca/cacert.pem" );
1104 unlink ( "${General::swroot}/certs/hostkey.pem" );
1105 unlink ( "${General::swroot}/certs/hostcert.pem" );
1106 unlink ( "${General::swroot}/crls/cacrl.pem" );
1107 & cleanssldatabase
();
1111 & Header
:: showhttpheaders
();
1112 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1113 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1114 if ( $errormessage ) {
1115 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1116 print "<class name='base'> $errormessage " ;
1117 print " </class>" ;
1118 & Header
:: closebox
();
1120 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
1122 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
1123 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1124 <tr><td width='40%' class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
1125 <td width='60%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td></tr>
1126 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}: <img src='/blob.gif' alt='*' /></td>
1127 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td></tr>
1128 <tr><td class='base'> $Lang ::tr{'your e-mail'}:</td>
1129 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td></tr>
1130 <tr><td class='base'> $Lang ::tr{'your department'}:</td>
1131 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td></tr>
1132 <tr><td class='base'> $Lang ::tr{'city'}:</td>
1133 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td></tr>
1134 <tr><td class='base'> $Lang ::tr{'state or province'}:</td>
1135 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td></tr>
1136 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1137 <td class='base'><select name='ROOTCERT_COUNTRY'>
1140 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1141 print "<option value=' $Countries ::countries{ $country }'" ;
1142 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1143 print " selected='selected'" ;
1145 print "> $country </option>" ;
1149 <tr><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*) <img src='/blob.gif' alt='*' /></td>
1150 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' /></td></tr>
1152 <td><br /><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /><br /><br /></td></tr>
1153 <tr><td class='base' colspan='2' align='left'>
1154 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1155 $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'}
1157 <tr><td colspan='2'><hr></td></tr>
1158 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}:</td>
1159 <td nowrap='nowrap'><input type='file' name='FH' size='32' /></td></tr>
1160 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
1161 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td></tr>
1163 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td></tr>
1164 <tr><td class='base' colspan='2' align='left'>
1165 <img src='/blob.gif' alt='*' /> $Lang ::tr{'required field'}</td></tr>
1169 & Header
:: closebox
();
1170 & Header
:: closebigbox
();
1171 & Header
:: closepage
();
1176 system ( '/usr/local/bin/ipsecctrl' , 'S' );
1181 ### Export PKCS12 file to browser
1183 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
1184 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1185 print "Content-Type: application/force-download \n " ;
1186 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
1187 print "Content-Type: application/octet-stream \r\n\r\n " ;
1188 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12` ;
1191 # Export Apple profile to browser
1192 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download apple profile' }) {
1193 # Read global configuration
1194 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1197 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1198 my $key = $cgiparams { 'KEY' };
1200 # Create a UUID generator
1201 my $uuid = Data
:: UUID
-> new ();
1203 my $uuid1 = $uuid -> create_str ();
1204 my $uuid2 = $uuid -> create_str ();
1207 my $cert_uuid = $uuid -> create_str ();
1209 # Read and encode certificate
1210 if ( $confighash { $key }[ 4 ] eq "cert" ) {
1211 my $cert_path = "${General::swroot}/certs/ $confighash { $key }[1].p12" ;
1213 # Read certificate and encode it into Base64
1214 open ( CERT
, "<${cert_path}" );
1215 local ($/) = undef ; # slurp
1216 $cert = MIME
:: Base64
:: encode_base64
(< CERT
>);
1220 print "Content-Type: application/octet-stream \n " ;
1221 print "Content-Disposition: attachment; filename=" . $confighash { $key }[ 1 ] . ".mobileconfig \n " ;
1222 print " \n " ; # end headers
1224 # Use our own FQDN if nothing else is configured
1225 my $endpoint = ( $vpnsettings { 'RW_ENDPOINT' } ne "" ) ?
$vpnsettings { 'RW_ENDPOINT' } : & hostname
();
1227 print "<!DOCTYPE plist PUBLIC \" -//Apple//DTD PLIST 1.0//EN \" \" http://www.apple.com/DTDs/PropertyList-1.0.dtd \" > \n " ;
1228 print "<plist version= \" 1.0 \" > \n " ;
1230 print " <key>PayloadDisplayName</key> \n " ;
1231 print " <string> $confighash { $key }[1]</string> \n " ;
1232 print " <key>PayloadIdentifier</key> \n " ;
1233 print " <string> $confighash { $key }[1]</string> \n " ;
1234 print " <key>PayloadUUID</key> \n " ;
1235 print " <string>${uuid1}</string> \n " ;
1236 print " <key>PayloadType</key> \n " ;
1237 print " <string>Configuration</string> \n " ;
1238 print " <key>PayloadVersion</key> \n " ;
1239 print " <integer>1</integer> \n " ;
1240 print " <key>PayloadContent</key> \n " ;
1243 print " <key>PayloadIdentifier</key> \n " ;
1244 print " <string>org.example.vpn1.conf1</string> \n " ;
1245 print " <key>PayloadUUID</key> \n " ;
1246 print " <string>${uuid2}</string> \n " ;
1247 print " <key>PayloadType</key> \n " ;
1248 print " <string>com.apple.vpn.managed</string> \n " ;
1249 print " <key>PayloadVersion</key> \n " ;
1250 print " <integer>1</integer> \n " ;
1251 print " <key>UserDefinedName</key> \n " ;
1252 print " <string> $confighash { $key }[1]</string> \n " ;
1253 print " <key>VPNType</key> \n " ;
1254 print " <string>IKEv2</string> \n " ;
1255 print " <key>IKEv2</key> \n " ;
1257 print " <key>RemoteAddress</key> \n " ;
1258 print " <string> $endpoint </string> \n " ;
1261 my $pfs = $confighash { $key }[ 28 ];
1263 print " <key>EnablePFS</key> \n " ;
1268 if ( $confighash { $key }[ 9 ]) {
1269 print " <key>LocalIdentifier</key> \n " ;
1270 print " <string> $confighash { $key }[9]</string> \n " ;
1274 if ( $confighash { $key }[ 7 ]) {
1275 print " <key>RemoteIdentifier</key> \n " ;
1276 print " <string> $confighash { $key }[7]</string> \n " ;
1279 if ( $confighash { $key }[ 4 ] eq "cert" ) {
1280 print " <key>AuthenticationMethod</key> \n " ;
1281 print " <string>Certificate</string> \n " ;
1283 print " <key>PayloadCertificateUUID</key> \n " ;
1284 print " <string>${cert_uuid}</string> \n " ;
1286 print " <key>AuthenticationMethod</key> \n " ;
1287 print " <string>SharedSecret</string> \n " ;
1288 print " <key>SharedSecret</key> \n " ;
1289 print " <string> $confighash { $key }[5]</string> \n " ;
1292 print " <key>ExtendedAuthEnabled</key> \n " ;
1293 print " <integer>0</integer> \n " ;
1297 if ( $confighash { $key }[ 4 ] eq "cert" ) {
1299 print " <key>PayloadIdentifier</key> \n " ;
1300 print " <string>org.example.vpn1.client</string> \n " ;
1301 print " <key>PayloadUUID</key> \n " ;
1302 print " <string>${cert_uuid}</string> \n " ;
1303 print " <key>PayloadType</key> \n " ;
1304 print " <string>com.apple.security.pkcs12</string> \n " ;
1305 print " <key>PayloadVersion</key> \n " ;
1306 print " <integer>1</integer> \n " ;
1307 print " <key>PayloadContent</key> \n " ;
1310 foreach ( split /\n/ ,${ cert
}) {
1318 print " </array> \n " ;
1325 ### Display certificate
1327 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
1328 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1330 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1331 & Header
:: showhttpheaders
();
1332 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1333 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1334 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'cert'}:" );
1335 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1336 $output = & Header
:: cleanhtml
( $output , "y" );
1337 print "<pre> $output </pre> \n " ;
1338 & Header
:: closebox
();
1339 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1340 & Header
:: closebigbox
();
1341 & Header
:: closepage
();
1346 ### Export Certificate to browser
1348 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
1349 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1351 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1352 print "Content-Type: application/force-download \n " ;
1353 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \n\n " ;
1354 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1359 ### Enable/Disable connection
1361 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1363 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1364 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1366 if ( $confighash { $cgiparams { 'KEY' }}) {
1367 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
1368 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
1369 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1371 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1373 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
1374 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1376 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1380 $errormessage = $Lang :: tr
{ 'invalid key' };
1384 ### Restart connection
1386 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
1387 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1388 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1390 if ( $confighash { $cgiparams { 'KEY' }}) {
1392 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
1396 $errormessage = $Lang :: tr
{ 'invalid key' };
1400 ### Remove connection
1402 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
1403 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1404 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1406 if ( $confighash { $cgiparams { 'KEY' }}) {
1407 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1408 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1409 delete $confighash { $cgiparams { 'KEY' }};
1410 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1412 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1414 $errormessage = $Lang :: tr
{ 'invalid key' };
1416 & General
:: firewall_reload
();
1418 ### Choose between adding a host-net or net-net connection
1420 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
1421 & Header
:: showhttpheaders
();
1422 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1423 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1424 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection type' });
1426 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
1427 <b> $Lang ::tr{'connection type'}:</b><br />
1429 <tr><td><input type='radio' name='TYPE' value='host' checked='checked' /></td>
1430 <td class='base'> $Lang ::tr{'host to net vpn'}</td>
1432 <td><input type='radio' name='TYPE' value='net' /></td>
1433 <td class='base'> $Lang ::tr{'net to net vpn'}</td>
1435 <td align='center' colspan='2'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td>
1440 & Header
:: closebox
();
1441 & Header
:: closebigbox
();
1442 & Header
:: closepage
();
1445 ### Adding/Editing/Saving a connection
1447 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
1448 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
1449 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
1451 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1452 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1453 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1455 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
1456 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
1457 $errormessage = $Lang :: tr
{ 'invalid key' };
1460 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
1461 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
1462 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
1463 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
1464 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
1465 $cgiparams { 'LOCAL' } = $confighash { $cgiparams { 'KEY' }}[ 6 ];
1466 $cgiparams { 'LOCAL_ID' } = $confighash { $cgiparams { 'KEY' }}[ 7 ];
1467 my @local_subnets = split ( "," , $confighash { $cgiparams { 'KEY' }}[ 8 ]);
1468 $cgiparams { 'LOCAL_SUBNET' } = join ( /\|/ , @local_subnets );
1469 $cgiparams { 'REMOTE_ID' } = $confighash { $cgiparams { 'KEY' }}[ 9 ];
1470 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
1471 my @remote_subnets = split ( "," , $confighash { $cgiparams { 'KEY' }}[ 11 ]);
1472 $cgiparams { 'REMOTE_SUBNET' } = join ( /\|/ , @remote_subnets );
1473 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
1474 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
1475 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
1476 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
1477 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
1478 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
1479 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
1480 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
1481 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
1482 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
1483 if ( $cgiparams { 'ESP_GROUPTYPE' } eq "" ) {
1484 $cgiparams { 'ESP_GROUPTYPE' } = $cgiparams { 'IKE_GROUPTYPE' };
1486 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
1487 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
1488 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
1489 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
1490 $cgiparams { 'DPD_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
1491 $cgiparams { 'DPD_DELAY' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
1492 $cgiparams { 'FORCE_MOBIKE' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
1493 $cgiparams { 'START_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 33 ];
1494 $cgiparams { 'INACTIVITY_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 34 ];
1495 $cgiparams { 'MODE' } = $confighash { $cgiparams { 'KEY' }}[ 35 ];
1496 $cgiparams { 'INTERFACE_MODE' } = $confighash { $cgiparams { 'KEY' }}[ 36 ];
1497 $cgiparams { 'INTERFACE_ADDRESS' } = $confighash { $cgiparams { 'KEY' }}[ 37 ];
1498 $cgiparams { 'INTERFACE_MTU' } = $confighash { $cgiparams { 'KEY' }}[ 38 ];
1500 if (! $cgiparams { 'DPD_DELAY' }) {
1501 $cgiparams { 'DPD_DELAY' } = 30 ;
1504 if (! $cgiparams { 'DPD_TIMEOUT' }) {
1505 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
1508 if ( $cgiparams { 'INACTIVITY_TIMEOUT' } eq "" ) {
1509 $cgiparams { 'INACTIVITY_TIMEOUT' } = 900 ;
1512 if ( $cgiparams { 'MODE' } eq "" ) {
1513 $cgiparams { 'MODE' } = "tunnel" ;
1516 if ( $cgiparams { 'INTERFACE_MTU' } eq "" ) {
1517 $cgiparams { 'INTERFACE_MTU' } = 1500 ;
1520 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
1521 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
1522 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
1523 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
1527 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
1528 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
1532 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
1533 $errormessage = $Lang :: tr
{ 'name is invalid' };
1537 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
1538 $errormessage = $Lang :: tr
{ 'name too long' };
1542 # Check if there is no other entry with this name
1543 if (! $cgiparams { 'KEY' }) { #only for add
1544 foreach my $key ( keys %confighash ) {
1545 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
1546 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
1552 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! $cgiparams { 'REMOTE' })) {
1553 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1557 if ( $cgiparams { 'LOCAL' }) {
1558 if (( $cgiparams { 'LOCAL' } ne "" ) && (!& General
:: validip
( $cgiparams { 'LOCAL' }))) {
1559 $errormessage = $Lang :: tr
{ 'invalid input for local ip address' };
1564 if ( $cgiparams { 'REMOTE' }) {
1565 if (( $cgiparams { 'REMOTE' } ne ' %any ' ) && (! & General
:: validip
( $cgiparams { 'REMOTE' }))) {
1566 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
1567 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1570 if (& valid_dns_host
( $cgiparams { 'REMOTE' })) {
1571 $warnmessage = " $Lang ::tr{'check vpn lr'} $cgiparams {'REMOTE'}. $Lang ::tr{'dns check failed'}" ;
1577 my @local_subnets = split ( "," , $cgiparams { 'LOCAL_SUBNET' });
1578 foreach my $subnet ( @local_subnets ) {
1579 unless (& Network
:: check_subnet
( $subnet )) {
1580 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
1585 # Allow only one roadwarrior/psk without remote IP-address
1586 if ( $cgiparams { 'REMOTE' } eq '' && $cgiparams { 'AUTH' } eq 'psk' ) {
1587 foreach my $key ( keys %confighash ) {
1588 if ( ( $cgiparams { 'KEY' } ne $key ) &&
1589 ( $confighash { $key }[ 4 ] eq 'psk' ) &&
1590 ( $confighash { $key }[ 10 ] eq '' ) ) {
1591 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
1597 if ( $cgiparams { 'TYPE' } eq 'net' ) {
1598 my @remote_subnets = split ( "," , $cgiparams { 'REMOTE_SUBNET' });
1599 foreach my $subnet ( @remote_subnets ) {
1600 unless (& Network
:: check_subnet
( $subnet )) {
1601 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
1606 if ( $cgiparams { 'MODE' } !~ /^(tunnel|transport)$/ ) {
1607 $errormessage = $Lang :: tr
{ 'invalid input for mode' };
1611 if ( $cgiparams { 'INTERFACE_MODE' } !~ /^(|gre|vti)$/ ) {
1612 $errormessage = $Lang :: tr
{ 'invalid input for interface mode' };
1616 if (( $cgiparams { 'INTERFACE_MODE' } eq "vti" ) && ( $cgiparams { 'MODE' } eq "transport" )) {
1617 $errormessage = $Lang :: tr
{ 'transport mode does not support vti' };
1621 if (( $cgiparams { 'INTERFACE_MODE' } ne "" ) && !& Network
:: check_subnet
( $cgiparams { 'INTERFACE_ADDRESS' })) {
1622 $errormessage = $Lang :: tr
{ 'invalid input for interface address' };
1626 if ( $cgiparams { 'INTERFACE_MTU' } !~ /^\d+$/ ) {
1627 $errormessage = $Lang :: tr
{ 'invalid input for interface mtu' };
1632 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
1633 $errormessage = $Lang :: tr
{ 'invalid input' };
1636 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
1637 $errormessage = $Lang :: tr
{ 'invalid input' };
1641 # Allow nothing or a string (DN,FDQN,) beginning with @
1642 # with no comma but slashes between RID eg @O=FR/C=Paris/OU=myhome/CN=franck
1643 if ( ( $cgiparams { 'LOCAL_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1644 ( $cgiparams { 'REMOTE_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1645 (( $cgiparams { 'REMOTE_ID' } eq $cgiparams { 'LOCAL_ID' }) && ( $cgiparams { 'LOCAL_ID' } ne '' ))
1647 $errormessage = $Lang :: tr
{ 'invalid local-remote id' } . '<br />' .
1648 'DER_ASN1_DN: @c =FR/ou=Paris/ou=Home/cn=*<br />' .
1649 'FQDN: @ipfire .org<br />' .
1650 'USER_FQDN: info @ipfire .org<br />' .
1651 'IPV4_ADDR: 123.123.123.123' ;
1654 # If Auth is DN, verify existance of Remote ID.
1655 if ( $cgiparams { 'REMOTE_ID' } eq '' && (
1656 $cgiparams { 'AUTH' } eq 'auth-dn' || # while creation
1657 $confighash { $cgiparams { 'KEY' }}[ 2 ] eq ' %auth -dn' )){ # while editing
1658 $errormessage = $Lang :: tr
{ 'vpn missing remote id' };
1662 if ( $cgiparams { 'TYPE' } eq 'net' ){
1663 $warnmessage =& General
:: checksubnets
( '' , $cgiparams { 'REMOTE_SUBNET' }, 'ipsec' );
1664 if ( $warnmessage ne '' ){
1665 $warnmessage = $Lang :: tr
{ 'remote subnet' }. " ( $cgiparams {'REMOTE_SUBNET'}) <br>" . $warnmessage ;
1669 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1670 if (! length ( $cgiparams { 'PSK' }) ) {
1671 $errormessage = $Lang :: tr
{ 'pre-shared key is too short' };
1674 if ( $cgiparams { 'PSK' } =~ /'/ ) {
1675 $cgiparams { 'PSK' } =~ tr/'/ / ;
1676 $errormessage = $Lang :: tr
{ 'invalid characters found in pre-shared key' };
1679 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
1680 if ( $cgiparams { 'KEY' }) {
1681 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1684 unless ( ref ( $cgiparams { 'FH' })) {
1685 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1689 # Move uploaded certificate request to a temporary file
1690 ( my $fh , my $filename ) = tempfile
( );
1691 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1696 # Sign the certificate request
1697 & General
:: log ( "ipsec" , "Signing your cert $cgiparams {'NAME'}..." );
1698 my $opt = " ca -md sha256 -days 825" ;
1699 $opt .= " -batch -notext" ;
1700 $opt .= " -in $filename " ;
1701 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1703 if ( $errormessage = & callssl
( $opt ) ) {
1705 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1706 & cleanssldatabase
();
1710 & cleanssldatabase
();
1713 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1714 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1715 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1718 } elsif ( $cgiparams { 'AUTH' } eq 'pkcs12' ) {
1719 & General
:: log ( "ipsec" , "Importing from p12..." );
1721 unless ( ref ( $cgiparams { 'FH' })) {
1722 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1723 goto ROOTCERT_ERROR
;
1726 # Move uploaded certificate request to a temporary file
1727 ( my $fh , my $filename ) = tempfile
( );
1728 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1730 goto ROOTCERT_ERROR
;
1733 # Extract the CA certificate from the file
1734 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
1735 if ( open ( STDIN
, "-|" )) {
1736 my $opt = " pkcs12 -cacerts -nokeys" ;
1737 $opt .= " -in $filename " ;
1738 $opt .= " -out /tmp/newcacert" ;
1739 $errormessage = & callssl
( $opt );
1741 print " $cgiparams {'P12_PASS'} \n " ;
1745 # Extract the Host certificate from the file
1746 if (! $errormessage ) {
1747 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
1748 if ( open ( STDIN
, "-|" )) {
1749 my $opt = " pkcs12 -clcerts -nokeys" ;
1750 $opt .= " -in $filename " ;
1751 $opt .= " -out /tmp/newhostcert" ;
1752 $errormessage = & callssl
( $opt );
1754 print " $cgiparams {'P12_PASS'} \n " ;
1759 if (! $errormessage ) {
1760 & General
:: log ( "ipsec" , "Moving cacert..." );
1761 #If CA have new subject, add it to our list of CA
1762 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( '/tmp/newcacert' ));
1764 foreach my $x ( keys %cahash ) {
1765 $casubject = '' if ( $cahash { $x }[ 1 ] eq $casubject );
1766 unshift ( @names , $cahash { $x }[ 0 ]);
1768 if ( $casubject ) { # a new one!
1769 my $temp = `/usr/bin/openssl x509 -text -in /tmp/newcacert` ;
1770 if ( $temp !~ /CA:TRUE/i ) {
1771 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
1773 #compute a name for it
1775 while ( grep ( /Imported-$idx/ , @names ) ) { $idx ++};
1776 $cgiparams { 'CA_NAME' }= "Imported- $idx " ;
1777 $cgiparams { 'CERT_NAME' }=& Header
:: cleanhtml
( getCNfromcert
( '/tmp/newhostcert' ));
1778 move
( "/tmp/newcacert" , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1779 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1780 if (! $errormessage ) {
1781 my $key = & General
:: findhasharraykey
( \
%cahash );
1782 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
1783 $cahash { $key }[ 1 ] = $casubject ;
1784 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1785 system ( '/usr/local/bin/ipsecctrl' , 'R' );
1790 if (! $errormessage ) {
1791 & General
:: log ( "ipsec" , "Moving host cert..." );
1792 move
( "/tmp/newhostcert" , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1793 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1798 unlink ( '/tmp/newcacert' );
1799 unlink ( '/tmp/newhostcert' );
1800 if ( $errormessage ) {
1801 unlink ( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1802 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1805 & General
:: log ( "ipsec" , "p12 import completed!" );
1806 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
1807 if ( $cgiparams { 'KEY' }) {
1808 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1811 unless ( ref ( $cgiparams { 'FH' })) {
1812 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1815 # Move uploaded certificate to a temporary file
1816 ( my $fh , my $filename ) = tempfile
( );
1817 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1822 # Verify the certificate has a valid CA and move it
1823 & General
:: log ( "ipsec" , "Validating imported cert against our known CA..." );
1824 my $validca = 1 ; #assume ok
1825 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/cacert.pem $filename ` ;
1826 if ( $test !~ /: OK/ ) {
1828 foreach my $key ( keys %cahash ) {
1829 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $key }[0]cert.pem $filename ` ;
1830 if ( $test =~ /: OK/ ) {
1837 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
1841 move
( $filename , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1843 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1849 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1850 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1851 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1852 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1855 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
1856 if ( $cgiparams { 'KEY' }) {
1857 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1860 # Validate input since the form was submitted
1861 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
1862 $errormessage = $Lang :: tr
{ 'name too long' };
1865 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1866 $errormessage = $Lang :: tr
{ 'invalid input for name' };
1869 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
1870 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1873 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
1874 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1877 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1878 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1881 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
1882 $errormessage = $Lang :: tr
{ 'organization too long' };
1885 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1886 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1889 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1890 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1893 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1894 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1897 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1898 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1901 #the exact syntax is a list comma separated of
1902 # email:any-validemail
1903 # URI: a uniform resource indicator
1904 # DNS: a DNS domain name
1905 # RID: a registered OBJECT IDENTIFIER
1907 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
1909 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
1910 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
1914 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
1915 $errormessage = $Lang :: tr
{ 'password too short' };
1918 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
1919 $errormessage = $Lang :: tr
{ 'passwords do not match' };
1923 # Replace empty strings with a .
1924 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
1925 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
1926 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
1928 # Create the Client certificate request
1929 & General
:: log ( "ipsec" , "Creating a cert..." );
1931 if ( open ( STDIN
, "-|" )) {
1932 my $opt = " req -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
1933 $opt .= " -newkey rsa:2048" ;
1934 $opt .= " -keyout ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1935 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1937 if ( $errormessage = & callssl
( $opt ) ) {
1938 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1939 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1943 print " $cgiparams {'CERT_COUNTRY'} \n " ;
1946 print " $cgiparams {'CERT_ORGANIZATION'} \n " ;
1948 print " $cgiparams {'CERT_NAME'} \n " ;
1949 print " $cgiparams {'CERT_EMAIL'} \n " ;
1955 # Sign the client certificate request
1956 & General
:: log ( "ipsec" , "Signing the cert $cgiparams {'NAME'}..." );
1958 #No easy way for specifying the contain of subjectAltName without writing a config file...
1959 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1961 basicConstraints=CA:FALSE
1962 nsComment="OpenSSL Generated Certificate"
1963 subjectKeyIdentifier=hash
1964 extendedKeyUsage=clientAuth
1965 authorityKeyIdentifier=keyid,issuer:always
1968 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1971 my $opt = " ca -md sha256 -days 825 -batch -notext" ;
1972 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1973 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1974 $opt .= " -extfile $v3extname " ;
1976 if ( $errormessage = & callssl
( $opt ) ) {
1977 unlink ( $v3extname );
1978 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1979 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1980 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1981 & cleanssldatabase
();
1984 unlink ( $v3extname );
1985 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1986 & cleanssldatabase
();
1989 # Create the pkcs12 file
1990 & General
:: log ( "ipsec" , "Packing a pkcs12 file..." );
1991 $opt = " pkcs12 -export" ;
1992 $opt .= " -inkey ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1993 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1994 $opt .= " -name \" $cgiparams {'NAME'} \" " ;
1995 $opt .= " -passout pass: $cgiparams {'CERT_PASS1'}" ;
1996 $opt .= " -certfile ${General::swroot}/ca/cacert.pem" ;
1997 $opt .= " -caname \" $vpnsettings {'ROOTCERT_ORGANIZATION'} CA \" " ;
1998 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}.p12" ;
2000 if ( $errormessage = & callssl
( $opt ) ) {
2001 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
2002 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
2003 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}.p12" );
2006 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
2008 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
2009 ; # Nothing, just editing
2010 } elsif ( $cgiparams { 'AUTH' } eq 'auth-dn' ) {
2011 $cgiparams { 'CERT_NAME' } = ' %auth -dn' ; # a special value saying 'no cert file'
2013 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
2017 # 1)Error message here is not accurate.
2018 # 2)Test is superfluous, openswan can reference same cert multiple times
2019 # 3)Present since initial version (1.3.2.11), it isn't a bug correction
2020 # Check if there is no other entry with this certificate name
2021 #if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk') && ($cgiparams{'AUTH'} ne 'auth-dn')) {
2022 # foreach my $key (keys %confighash) {
2023 # if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) {
2024 # $errormessage = $Lang::tr{'a connection with this common name already exists'};
2025 # goto VPNCONF_ERROR;
2031 my $key = $cgiparams { 'KEY' };
2033 $key = & General
:: findhasharraykey
( \
%confighash );
2034 foreach my $i ( 0 .. 38 ) { $confighash { $key }[ $i ] = "" ;}
2036 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
2037 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
2038 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
2039 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
2041 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
2042 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
2043 $confighash { $key }[ 4 ] = 'psk' ;
2044 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
2046 $confighash { $key }[ 4 ] = 'cert' ;
2048 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2049 my @remote_subnets = split ( "," , $cgiparams { 'REMOTE_SUBNET' });
2050 $confighash { $key }[ 11 ] = join ( '|' , @remote_subnets );
2052 $confighash { $key }[ 6 ] = $cgiparams { 'LOCAL' };
2053 $confighash { $key }[ 7 ] = $cgiparams { 'LOCAL_ID' };
2054 my @local_subnets = split ( "," , $cgiparams { 'LOCAL_SUBNET' });
2055 $confighash { $key }[ 8 ] = join ( '|' , @local_subnets );
2056 $confighash { $key }[ 9 ] = $cgiparams { 'REMOTE_ID' };
2057 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
2058 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
2059 $confighash { $key }[ 26 ] = "" ; # Formerly INTERFACE
2060 $confighash { $key }[ 27 ] = $cgiparams { 'DPD_ACTION' };
2061 $confighash { $key }[ 29 ] = $cgiparams { 'IKE_VERSION' };
2063 # don't forget advanced value
2064 $confighash { $key }[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
2065 $confighash { $key }[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
2066 $confighash { $key }[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
2067 $confighash { $key }[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
2068 $confighash { $key }[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
2069 $confighash { $key }[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
2070 $confighash { $key }[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
2071 $confighash { $key }[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
2072 $confighash { $key }[ 12 ] = 'off' ; # $cgiparams{'AGGRMODE'};
2073 $confighash { $key }[ 13 ] = $cgiparams { 'COMPRESSION' };
2074 $confighash { $key }[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
2075 $confighash { $key }[ 28 ] = $cgiparams { 'PFS' };
2076 $confighash { $key }[ 30 ] = $cgiparams { 'DPD_TIMEOUT' };
2077 $confighash { $key }[ 31 ] = $cgiparams { 'DPD_DELAY' };
2078 $confighash { $key }[ 32 ] = $cgiparams { 'FORCE_MOBIKE' };
2079 $confighash { $key }[ 33 ] = $cgiparams { 'START_ACTION' };
2080 $confighash { $key }[ 34 ] = $cgiparams { 'INACTIVITY_TIMEOUT' };
2081 $confighash { $key }[ 35 ] = $cgiparams { 'MODE' };
2082 $confighash { $key }[ 36 ] = $cgiparams { 'INTERFACE_MODE' };
2083 $confighash { $key }[ 37 ] = $cgiparams { 'INTERFACE_ADDRESS' };
2084 $confighash { $key }[ 38 ] = $cgiparams { 'INTERFACE_MTU' };
2086 # free unused fields!
2087 $confighash { $key }[ 15 ] = 'off' ;
2089 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2092 system ( '/usr/local/bin/ipsecctrl' , 'S' , $key );
2095 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
2096 $cgiparams { 'KEY' } = $key ;
2097 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
2100 } else { # add new connection
2101 $cgiparams { 'ENABLED' } = 'on' ;
2102 if ( ! - f
"${General::swroot}/private/cakey.pem" ) {
2103 $cgiparams { 'AUTH' } = 'psk' ;
2104 } elsif ( ! - f
"${General::swroot}/ca/cacert.pem" ) {
2105 $cgiparams { 'AUTH' } = 'certfile' ;
2107 $cgiparams { 'AUTH' } = 'certgen' ;
2110 if ( $netsettings { "GREEN_NETADDRESS" } && $netsettings { "GREEN_NETMASK" }) {
2111 $cgiparams { "LOCAL_SUBNET" } = $netsettings { 'GREEN_NETADDRESS' } . "/" . $netsettings { 'GREEN_NETMASK' };
2113 $cgiparams { "LOCAL_SUBNET" } = "" ;
2115 $cgiparams { 'CERT_EMAIL' } = $vpnsettings { 'ROOTCERT_EMAIL' };
2116 $cgiparams { 'CERT_OU' } = $vpnsettings { 'ROOTCERT_OU' };
2117 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
2118 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
2119 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
2120 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
2122 # choose appropriate dpd action
2123 if ( $cgiparams { 'TYPE' } eq 'host' ) {
2124 $cgiparams { 'DPD_ACTION' } = 'clear' ;
2126 $cgiparams { 'DPD_ACTION' } = 'restart' ;
2129 if (! $cgiparams { 'DPD_DELAY' }) {
2130 $cgiparams { 'DPD_DELAY' } = 30 ;
2133 if (! $cgiparams { 'DPD_TIMEOUT' }) {
2134 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
2137 if (! $cgiparams { 'FORCE_MOBIKE' }) {
2138 $cgiparams { 'FORCE_MOBIKE' } = 'no' ;
2141 # Default IKE Version to v2
2142 if (! $cgiparams { 'IKE_VERSION' }) {
2143 $cgiparams { 'IKE_VERSION' } = 'ikev2' ;
2147 $cgiparams { 'LOCAL_ID' } = '' ;
2148 $cgiparams { 'REMOTE_ID' } = '' ;
2150 #use default advanced value
2151 $cgiparams { 'IKE_ENCRYPTION' } = 'chacha20poly1305|aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128' ; #[18];
2152 $cgiparams { 'IKE_INTEGRITY' } = 'sha2_512|sha2_256' ; #[19];
2153 $cgiparams { 'IKE_GROUPTYPE' } = 'curve25519|curve448|4096|3072|2048' ; #[20];
2154 $cgiparams { 'IKE_LIFETIME' } = '3' ; #[16];
2155 $cgiparams { 'ESP_ENCRYPTION' } = 'chacha20poly1305|aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128' ; #[21];
2156 $cgiparams { 'ESP_INTEGRITY' } = 'sha2_512|sha2_256' ; #[22];
2157 $cgiparams { 'ESP_GROUPTYPE' } = 'curve25519|curve448|4096|3072|2048' ; #[23];
2158 $cgiparams { 'ESP_KEYLIFE' } = '1' ; #[17];
2159 $cgiparams { 'COMPRESSION' } = 'off' ; #[13];
2160 $cgiparams { 'ONLY_PROPOSED' } = 'on' ; #[24];
2161 $cgiparams { 'PFS' } = 'on' ; #[28];
2162 $cgiparams { 'INACTIVITY_TIMEOUT' } = 900 ;
2163 $cgiparams { 'MODE' } = "tunnel" ;
2164 $cgiparams { 'INTERFACE_MODE' } = "" ;
2165 $cgiparams { 'INTERFACE_ADDRESS' } = "" ;
2166 $cgiparams { 'INTERFACE_MTU' } = 1500 ;
2170 $checked { 'ENABLED' }{ 'off' } = '' ;
2171 $checked { 'ENABLED' }{ 'on' } = '' ;
2172 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = "checked='checked'" ;
2174 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
2175 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
2176 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = "checked='checked'" ;
2178 $checked { 'AUTH' }{ 'psk' } = '' ;
2179 $checked { 'AUTH' }{ 'certreq' } = '' ;
2180 $checked { 'AUTH' }{ 'certgen' } = '' ;
2181 $checked { 'AUTH' }{ 'certfile' } = '' ;
2182 $checked { 'AUTH' }{ 'pkcs12' } = '' ;
2183 $checked { 'AUTH' }{ 'auth-dn' } = '' ;
2184 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = "checked='checked'" ;
2186 $selected { 'MODE' }{ 'tunnel' } = '' ;
2187 $selected { 'MODE' }{ 'transport' } = '' ;
2188 $selected { 'MODE' }{ $cgiparams { 'MODE' }} = "selected='selected'" ;
2190 $selected { 'INTERFACE_MODE' }{ '' } = '' ;
2191 $selected { 'INTERFACE_MODE' }{ 'gre' } = '' ;
2192 $selected { 'INTERFACE_MODE' }{ 'vti' } = '' ;
2193 $selected { 'INTERFACE_MODE' }{ $cgiparams { 'INTERFACE_MODE' }} = "selected='selected'" ;
2195 $selected { 'LOCAL' }{ '' } = '' ;
2196 foreach my $alias ( sort keys %aliases ) {
2197 my $address = $aliases { $alias }{ 'IPT' };
2199 $selected { 'LOCAL' }{ $address } = '' ;
2201 $selected { 'LOCAL' }{ $cgiparams { 'LOCAL' }} = "selected='selected'" ;
2203 & Header
:: showhttpheaders
();
2204 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
2205 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2206 if ( $errormessage ) {
2207 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2208 print "<class name='base'> $errormessage " ;
2209 print " </class>" ;
2210 & Header
:: closebox
();
2214 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'warning messages'}:" );
2215 print "<class name='base'> $warnmessage " ;
2216 print " </class>" ;
2217 & Header
:: closebox
();
2220 print "<form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>" ;
2222 <input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />
2223 <input type='hidden' name='IKE_VERSION' value=' $cgiparams {'IKE_VERSION'}' />
2224 <input type='hidden' name='IKE_ENCRYPTION' value=' $cgiparams {'IKE_ENCRYPTION'}' />
2225 <input type='hidden' name='IKE_INTEGRITY' value=' $cgiparams {'IKE_INTEGRITY'}' />
2226 <input type='hidden' name='IKE_GROUPTYPE' value=' $cgiparams {'IKE_GROUPTYPE'}' />
2227 <input type='hidden' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' />
2228 <input type='hidden' name='ESP_ENCRYPTION' value=' $cgiparams {'ESP_ENCRYPTION'}' />
2229 <input type='hidden' name='ESP_INTEGRITY' value=' $cgiparams {'ESP_INTEGRITY'}' />
2230 <input type='hidden' name='ESP_GROUPTYPE' value=' $cgiparams {'ESP_GROUPTYPE'}' />
2231 <input type='hidden' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' />
2232 <input type='hidden' name='COMPRESSION' value=' $cgiparams {'COMPRESSION'}' />
2233 <input type='hidden' name='ONLY_PROPOSED' value=' $cgiparams {'ONLY_PROPOSED'}' />
2234 <input type='hidden' name='PFS' value=' $cgiparams {'PFS'}' />
2235 <input type='hidden' name='DPD_ACTION' value=' $cgiparams {'DPD_ACTION'}' />
2236 <input type='hidden' name='DPD_DELAY' value=' $cgiparams {'DPD_DELAY'}' />
2237 <input type='hidden' name='DPD_TIMEOUT' value=' $cgiparams {'DPD_TIMEOUT'}' />
2238 <input type='hidden' name='FORCE_MOBIKE' value=' $cgiparams {'FORCE_MOBIKE'}' />
2239 <input type='hidden' name='START_ACTION' value=' $cgiparams {'START_ACTION'}' />
2240 <input type='hidden' name='INACTIVITY_TIMEOUT' value=' $cgiparams {'INACTIVITY_TIMEOUT'}' />
2243 if ( $cgiparams { 'KEY' }) {
2244 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
2245 print "<input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' />" ;
2246 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
2249 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'connection'}: $cgiparams {'NAME'}" );
2250 print "<table width='100%'>" ;
2251 if (! $cgiparams { 'KEY' }) {
2254 <td width='20%'> $Lang ::tr{'name'}: <img src='/blob.gif' alt='*' /></td>
2256 <input type='text' name='NAME' value=' $cgiparams {'NAME'}' size='25' />
2258 <td colspan="2"></td>
2265 if ( $cgiparams { 'TYPE' } eq 'host' ) {
2266 $disabled = "disabled='disabled'" ;
2267 } elsif ( $cgiparams { 'TYPE' } eq 'net' ) {
2268 $blob = "<img src='/blob.gif' alt='*' />" ;
2271 my @local_subnets = split ( /\|/ , $cgiparams { 'LOCAL_SUBNET' });
2272 my $local_subnets = join ( "," , @local_subnets );
2274 my @remote_subnets = split ( /\|/ , $cgiparams { 'REMOTE_SUBNET' });
2275 my $remote_subnets = join ( "," , @remote_subnets );
2279 <td width='20%'> $Lang ::tr{'enabled'}</td>
2281 <input type='checkbox' name='ENABLED' $checked {'ENABLED'}{'on'} />
2283 <td colspan="2"></td>
2286 <td class='boldbase' width='20%'> $Lang ::tr{'local ip address'}:</td>
2288 <select name="LOCAL">
2289 <option value="" $selected {'LOCAL'}{''}>- $Lang ::tr{'default IP address'} -</option>
2292 foreach my $alias ( sort keys %aliases ) {
2293 my $address = $aliases { $alias }{ 'IPT' };
2295 <option value=" $address " $selected {'LOCAL'}{ $address }> $alias ( $address )</option>
2302 <td class='boldbase' width='20%'> $Lang ::tr{'remote host/ip'}: $blob </td>
2304 <input type='text' name='REMOTE' value=' $cgiparams {'REMOTE'}' size="25" />
2308 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'local subnet'} <img src='/blob.gif' alt='*' /></td>
2310 <input type='text' name='LOCAL_SUBNET' value=' $local_subnets ' size="25" />
2312 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'remote subnet'} $blob </td>
2314 <input $disabled type='text' name='REMOTE_SUBNET' value=' $remote_subnets ' size="25" />
2318 <td class='boldbase' width='20%'> $Lang ::tr{'vpn local id'}:</td>
2320 <input type='text' name='LOCAL_ID' value=' $cgiparams {'LOCAL_ID'}' size="25" />
2322 <td class='boldbase' width='20%'> $Lang ::tr{'vpn remote id'}:</td>
2324 <input type='text' name='REMOTE_ID' value=' $cgiparams {'REMOTE_ID'}' size="25" />
2327 <tr><td colspan="4"><br /></td></tr>
2329 <td class='boldbase' width='20%'> $Lang ::tr{'remark title'}</td>
2331 <input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' maxlength='50' size="73" />
2336 if (! $cgiparams { 'KEY' }) {
2337 print "<tr><td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked {'EDIT_ADVANCED'}{'on'} /> $Lang ::tr{'edit advanced settings when done'}</td></tr>" ;
2340 & Header
:: closebox
();
2342 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2343 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'ipsec settings' });
2345 <table width='100%'>
2348 <td class='boldbase' width='20%'> $Lang ::tr{'mode'}:</td>
2350 <select name='MODE'>
2351 <option value='tunnel' $selected {'MODE'}{'tunnel'}> $Lang ::tr{'ipsec mode tunnel'}</option>
2352 <option value='transport' $selected {'MODE'}{'transport'}> $Lang ::tr{'ipsec mode transport'}</option>
2355 <td colspan='2'></td>
2359 <td class='boldbase' width='20%'> $Lang ::tr{'interface mode'}:</td>
2361 <select name='INTERFACE_MODE'>
2362 <option value='' $selected {'INTERFACE_MODE'}{''}> $Lang ::tr{'ipsec interface mode none'}</option>
2363 <option value='gre' $selected {'INTERFACE_MODE'}{'gre'}> $Lang ::tr{'ipsec interface mode gre'}</option>
2364 <option value='vti' $selected {'INTERFACE_MODE'}{'vti'}> $Lang ::tr{'ipsec interface mode vti'}</option>
2368 <td class='boldbase' width='20%'> $Lang ::tr{'ip address'}/ $Lang ::tr{'subnet mask'}:</td>
2370 <input type="text" name="INTERFACE_ADDRESS" value=" $cgiparams {'INTERFACE_ADDRESS'}">
2375 <td class='boldbase' width='20%'> $Lang ::tr{'mtu'}:</td>
2377 <input type="number" name="INTERFACE_MTU" value=" $cgiparams {'INTERFACE_MTU'}" min="576" max="9000">
2379 <td colspan='2'></td>
2384 & Header
:: closebox
();
2387 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
2388 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2390 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2391 <tr><td class='base' width='50%'> $Lang ::tr{'use a pre-shared key'}</td>
2392 <td class='base' width='50%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td>
2397 & Header
:: closebox
();
2398 } elsif (! $cgiparams { 'KEY' }) {
2399 my $cakeydisabled = ( ! - f
"${General::swroot}/private/cakey.pem" ) ?
"disabled='disabled'" : '' ;
2400 $cgiparams { 'CERT_NAME' } = $Lang :: tr
{ 'vpn no full pki' } if ( $cakeydisabled );
2401 my $cacrtdisabled = ( ! - f
"${General::swroot}/ca/cacert.pem" ) ?
"disabled='disabled'" : '' ;
2403 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2405 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2406 <tr><td width='5%'><input type='radio' name='AUTH' value='psk' $checked {'AUTH'}{'psk'} /></td>
2407 <td class='base' width='55%'> $Lang ::tr{'use a pre-shared key'}</td>
2408 <td class='base' width='40%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td></tr>
2409 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2410 <tr><td><input type='radio' name='AUTH' value='certreq' $checked {'AUTH'}{'certreq'} $cakeydisabled /></td>
2411 <td class='base'><hr /> $Lang ::tr{'upload a certificate request'}</td>
2412 <td class='base' rowspan='3' valign='middle'><input type='file' name='FH' size='30' $cacrtdisabled /></td></tr>
2413 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td>
2414 <td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
2415 <tr><td><input type='radio' name='AUTH' value='pkcs12' $cacrtdisabled /></td>
2416 <td class='base'> $Lang ::tr{'upload p12 file'} $Lang ::tr{'pkcs12 file password'}:<input type='password' name='P12_PASS'/></td></tr>
2417 <tr><td><input type='radio' name='AUTH' value='auth-dn' $checked {'AUTH'}{'auth-dn'} $cacrtdisabled /></td>
2418 <td class='base'><hr /> $Lang ::tr{'vpn auth-dn'}</td></tr>
2419 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2420 <tr><td><input type='radio' name='AUTH' value='certgen' $checked {'AUTH'}{'certgen'} $cakeydisabled /></td>
2421 <td class='base'><hr /> $Lang ::tr{'generate a certificate'}</td><td> </td></tr>
2423 <td class='base'> $Lang ::tr{'users fullname or system hostname'}: <img src='/blob.gif' alt='*' /></td>
2424 <td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' size='32' $cakeydisabled /></td></tr>
2426 <td class='base'> $Lang ::tr{'users email'}:</td>
2427 <td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' size='32' $cakeydisabled /></td></tr>
2429 <td class='base'> $Lang ::tr{'users department'}:</td>
2430 <td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' size='32' $cakeydisabled /></td></tr>
2432 <td class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
2433 <td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' size='32' $cakeydisabled /></td></tr>
2435 <td class='base'> $Lang ::tr{'city'}:</td>
2436 <td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' size='32' $cakeydisabled /></td></tr>
2438 <td class='base'> $Lang ::tr{'state or province'}:</td>
2439 <td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' size='32' $cakeydisabled /></td></tr>
2441 <td class='base'> $Lang ::tr{'country'}:</td>
2442 <td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
2445 foreach my $country ( sort keys %{ Countries
:: countries
}) {
2446 print " \t\t\t <option value=' $Countries ::countries{ $country }'" ;
2447 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
2448 print " selected='selected'" ;
2450 print "> $country </option> \n " ;
2455 <tr><td> </td><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)</td>
2456 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' $cakeydisabled /></td></tr>
2458 <td class='base'> $Lang ::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' /></td>
2459 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
2460 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'} ( $Lang ::tr{'confirmation'}): <img src='/blob.gif' alt='*' /></td>
2461 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
2465 & Header
:: closebox
();
2468 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
2469 if ( $cgiparams { 'KEY' }) {
2470 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced'}' />" ;
2472 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
2473 & Header
:: closebigbox
();
2474 & Header
:: closepage
();
2481 ### Advanced settings
2483 if (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced' }) ||
2484 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq 'yes' )) {
2485 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
2486 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2487 if (! $confighash { $cgiparams { 'KEY' }}) {
2488 $errormessage = $Lang :: tr
{ 'invalid key' };
2492 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
2493 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2495 $errormessage = $Lang :: tr
{ 'invalid input' };
2496 goto ADVANCED_ERROR
;
2498 foreach my $val ( @temp ) {
2499 if ( $val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|chacha20poly1305|camellia(256|192|128))$/ ) {
2500 $errormessage = $Lang :: tr
{ 'invalid input' };
2501 goto ADVANCED_ERROR
;
2504 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2506 $errormessage = $Lang :: tr
{ 'invalid input' };
2507 goto ADVANCED_ERROR
;
2509 foreach my $val ( @temp ) {
2510 if ( $val !~ /^(sha2_(512|384|256)|sha|md5|aesxcbc)$/ ) {
2511 $errormessage = $Lang :: tr
{ 'invalid input' };
2512 goto ADVANCED_ERROR
;
2515 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2517 $errormessage = $Lang :: tr
{ 'invalid input' };
2518 goto ADVANCED_ERROR
;
2520 foreach my $val ( @temp ) {
2521 if ( $val !~ /^(curve25519|curve448|e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|768|1024|1536|2048|3072|4096|6144|8192)$/ ) {
2522 $errormessage = $Lang :: tr
{ 'invalid input' };
2523 goto ADVANCED_ERROR
;
2526 if ( $cgiparams { 'IKE_LIFETIME' } !~ /^\d+$/ ) {
2527 $errormessage = $Lang :: tr
{ 'invalid input for ike lifetime' };
2528 goto ADVANCED_ERROR
;
2530 if ( $cgiparams { 'IKE_LIFETIME' } < 1 || $cgiparams { 'IKE_LIFETIME' } > 24 ) {
2531 $errormessage = $Lang :: tr
{ 'ike lifetime should be between 1 and 24 hours' };
2532 goto ADVANCED_ERROR
;
2534 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2536 $errormessage = $Lang :: tr
{ 'invalid input' };
2537 goto ADVANCED_ERROR
;
2539 foreach my $val ( @temp ) {
2540 if ( $val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|chacha20poly1305|camellia(256|192|128))$/ ) {
2541 $errormessage = $Lang :: tr
{ 'invalid input' };
2542 goto ADVANCED_ERROR
;
2545 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2547 $errormessage = $Lang :: tr
{ 'invalid input' };
2548 goto ADVANCED_ERROR
;
2550 foreach my $val ( @temp ) {
2551 if ( $val !~ /^(sha2_(512|384|256)|sha1|md5|aesxcbc)$/ ) {
2552 $errormessage = $Lang :: tr
{ 'invalid input' };
2553 goto ADVANCED_ERROR
;
2556 @temp = split ( '\|' , $cgiparams { 'ESP_GROUPTYPE' });
2558 $errormessage = $Lang :: tr
{ 'invalid input' };
2559 goto ADVANCED_ERROR
;
2561 foreach my $val ( @temp ) {
2562 if ( $val !~ /^(curve25519|curve448|e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|768|1024|1536|2048|3072|4096|6144|8192|none)$/ ) {
2563 $errormessage = $Lang :: tr
{ 'invalid input' };
2564 goto ADVANCED_ERROR
;
2567 if ( $cgiparams { 'ESP_KEYLIFE' } !~ /^\d+$/ ) {
2568 $errormessage = $Lang :: tr
{ 'invalid input for esp keylife' };
2569 goto ADVANCED_ERROR
;
2571 if ( $cgiparams { 'ESP_KEYLIFE' } < 1 || $cgiparams { 'ESP_KEYLIFE' } > 24 ) {
2572 $errormessage = $Lang :: tr
{ 'esp keylife should be between 1 and 24 hours' };
2573 goto ADVANCED_ERROR
;
2576 if (( $cgiparams { 'COMPRESSION' } !~ /^(|on|off)$/ ) ||
2577 ( $cgiparams { 'FORCE_MOBIKE' } !~ /^(|on|off)$/ ) ||
2578 ( $cgiparams { 'ONLY_PROPOSED' } !~ /^(|on|off)$/ ) ||
2579 ( $cgiparams { 'PFS' } !~ /^(|on|off)$/ )) {
2580 $errormessage = $Lang :: tr
{ 'invalid input' };
2581 goto ADVANCED_ERROR
;
2584 if ( $cgiparams { 'DPD_DELAY' } !~ /^\d+$/ ) {
2585 $errormessage = $Lang :: tr
{ 'invalid input for dpd delay' };
2586 goto ADVANCED_ERROR
;
2589 if ( $cgiparams { 'DPD_TIMEOUT' } !~ /^\d+$/ ) {
2590 $errormessage = $Lang :: tr
{ 'invalid input for dpd timeout' };
2591 goto ADVANCED_ERROR
;
2594 if ( $cgiparams { 'INACTIVITY_TIMEOUT' } !~ /^\d+$/ ) {
2595 $errormessage = $Lang :: tr
{ 'invalid input for inactivity timeout' };
2596 goto ADVANCED_ERROR
;
2599 $confighash { $cgiparams { 'KEY' }}[ 29 ] = $cgiparams { 'IKE_VERSION' };
2600 $confighash { $cgiparams { 'KEY' }}[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
2601 $confighash { $cgiparams { 'KEY' }}[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
2602 $confighash { $cgiparams { 'KEY' }}[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
2603 $confighash { $cgiparams { 'KEY' }}[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
2604 $confighash { $cgiparams { 'KEY' }}[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
2605 $confighash { $cgiparams { 'KEY' }}[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
2606 $confighash { $cgiparams { 'KEY' }}[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
2607 $confighash { $cgiparams { 'KEY' }}[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
2608 $confighash { $cgiparams { 'KEY' }}[ 12 ] = 'off' ; #$cgiparams{'AGGRMODE'};
2609 $confighash { $cgiparams { 'KEY' }}[ 13 ] = $cgiparams { 'COMPRESSION' };
2610 $confighash { $cgiparams { 'KEY' }}[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
2611 $confighash { $cgiparams { 'KEY' }}[ 28 ] = $cgiparams { 'PFS' };
2612 $confighash { $cgiparams { 'KEY' }}[ 27 ] = $cgiparams { 'DPD_ACTION' };
2613 $confighash { $cgiparams { 'KEY' }}[ 30 ] = $cgiparams { 'DPD_TIMEOUT' };
2614 $confighash { $cgiparams { 'KEY' }}[ 31 ] = $cgiparams { 'DPD_DELAY' };
2615 $confighash { $cgiparams { 'KEY' }}[ 32 ] = $cgiparams { 'FORCE_MOBIKE' };
2616 $confighash { $cgiparams { 'KEY' }}[ 33 ] = $cgiparams { 'START_ACTION' };
2617 $confighash { $cgiparams { 'KEY' }}[ 34 ] = $cgiparams { 'INACTIVITY_TIMEOUT' };
2618 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2621 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
2626 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
2627 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
2628 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
2629 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
2630 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
2631 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
2632 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
2633 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
2634 if ( $cgiparams { 'ESP_GROUPTYPE' } eq "" ) {
2635 $cgiparams { 'ESP_GROUPTYPE' } = $cgiparams { 'IKE_GROUPTYPE' };
2637 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
2638 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
2639 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
2640 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
2641 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
2642 $cgiparams { 'DPD_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
2643 $cgiparams { 'DPD_DELAY' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
2644 $cgiparams { 'FORCE_MOBIKE' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
2645 $cgiparams { 'START_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 33 ];
2646 $cgiparams { 'INACTIVITY_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 34 ];
2647 $cgiparams { 'MODE' } = $confighash { $cgiparams { 'KEY' }}[ 35 ];
2648 $cgiparams { 'INTERFACE_MODE' } = $confighash { $cgiparams { 'KEY' }}[ 36 ];
2649 $cgiparams { 'INTERFACE_ADDRESS' } = $confighash { $cgiparams { 'KEY' }}[ 37 ];
2650 $cgiparams { 'INTERFACE_MTU' } = $confighash { $cgiparams { 'KEY' }}[ 38 ];
2652 if (! $cgiparams { 'DPD_DELAY' }) {
2653 $cgiparams { 'DPD_DELAY' } = 30 ;
2656 if (! $cgiparams { 'DPD_TIMEOUT' }) {
2657 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
2660 if (! $cgiparams { 'START_ACTION' }) {
2661 $cgiparams { 'START_ACTION' } = "start" ;
2664 if ( $cgiparams { 'INACTIVITY_TIMEOUT' } eq "" ) {
2665 $cgiparams { 'INACTIVITY_TIMEOUT' } = 900 ; # 15 min
2668 if ( $cgiparams { 'MODE' } eq "" ) {
2669 $cgiparams { 'MODE' } = "tunnel" ;
2674 $checked { 'IKE_ENCRYPTION' }{ 'chacha20poly1305' } = '' ;
2675 $checked { 'IKE_ENCRYPTION' }{ 'aes256' } = '' ;
2676 $checked { 'IKE_ENCRYPTION' }{ 'aes192' } = '' ;
2677 $checked { 'IKE_ENCRYPTION' }{ 'aes128' } = '' ;
2678 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm128' } = '' ;
2679 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm128' } = '' ;
2680 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm128' } = '' ;
2681 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm96' } = '' ;
2682 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm96' } = '' ;
2683 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm96' } = '' ;
2684 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm64' } = '' ;
2685 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm64' } = '' ;
2686 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm64' } = '' ;
2687 $checked { 'IKE_ENCRYPTION' }{ '3des' } = '' ;
2688 $checked { 'IKE_ENCRYPTION' }{ 'camellia256' } = '' ;
2689 $checked { 'IKE_ENCRYPTION' }{ 'camellia192' } = '' ;
2690 $checked { 'IKE_ENCRYPTION' }{ 'camellia128' } = '' ;
2691 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2692 foreach my $key ( @temp ) { $checked { 'IKE_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2693 $checked { 'IKE_INTEGRITY' }{ 'sha2_512' } = '' ;
2694 $checked { 'IKE_INTEGRITY' }{ 'sha2_384' } = '' ;
2695 $checked { 'IKE_INTEGRITY' }{ 'sha2_256' } = '' ;
2696 $checked { 'IKE_INTEGRITY' }{ 'sha' } = '' ;
2697 $checked { 'IKE_INTEGRITY' }{ 'md5' } = '' ;
2698 $checked { 'IKE_INTEGRITY' }{ 'aesxcbc' } = '' ;
2699 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2700 foreach my $key ( @temp ) { $checked { 'IKE_INTEGRITY' }{ $key } = "selected='selected'" ; }
2701 $checked { 'IKE_GROUPTYPE' }{ 'curve25519' } = '' ;
2702 $checked { 'IKE_GROUPTYPE' }{ 'curve448' } = '' ;
2703 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2704 $checked { 'IKE_GROUPTYPE' }{ '1024' } = '' ;
2705 $checked { 'IKE_GROUPTYPE' }{ '1536' } = '' ;
2706 $checked { 'IKE_GROUPTYPE' }{ '2048' } = '' ;
2707 $checked { 'IKE_GROUPTYPE' }{ '3072' } = '' ;
2708 $checked { 'IKE_GROUPTYPE' }{ '4096' } = '' ;
2709 $checked { 'IKE_GROUPTYPE' }{ '6144' } = '' ;
2710 $checked { 'IKE_GROUPTYPE' }{ '8192' } = '' ;
2711 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2712 foreach my $key ( @temp ) { $checked { 'IKE_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2714 $checked { 'ESP_ENCRYPTION' }{ 'chacha20poly1305' } = '' ;
2715 $checked { 'ESP_ENCRYPTION' }{ 'aes256' } = '' ;
2716 $checked { 'ESP_ENCRYPTION' }{ 'aes192' } = '' ;
2717 $checked { 'ESP_ENCRYPTION' }{ 'aes128' } = '' ;
2718 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm128' } = '' ;
2719 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm128' } = '' ;
2720 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm128' } = '' ;
2721 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm96' } = '' ;
2722 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm96' } = '' ;
2723 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm96' } = '' ;
2724 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm64' } = '' ;
2725 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm64' } = '' ;
2726 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm64' } = '' ;
2727 $checked { 'ESP_ENCRYPTION' }{ '3des' } = '' ;
2728 $checked { 'ESP_ENCRYPTION' }{ 'camellia256' } = '' ;
2729 $checked { 'ESP_ENCRYPTION' }{ 'camellia192' } = '' ;
2730 $checked { 'ESP_ENCRYPTION' }{ 'camellia128' } = '' ;
2731 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2732 foreach my $key ( @temp ) { $checked { 'ESP_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2733 $checked { 'ESP_INTEGRITY' }{ 'sha2_512' } = '' ;
2734 $checked { 'ESP_INTEGRITY' }{ 'sha2_384' } = '' ;
2735 $checked { 'ESP_INTEGRITY' }{ 'sha2_256' } = '' ;
2736 $checked { 'ESP_INTEGRITY' }{ 'sha1' } = '' ;
2737 $checked { 'ESP_INTEGRITY' }{ 'md5' } = '' ;
2738 $checked { 'ESP_INTEGRITY' }{ 'aesxcbc' } = '' ;
2739 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2740 foreach my $key ( @temp ) { $checked { 'ESP_INTEGRITY' }{ $key } = "selected='selected'" ; }
2741 $checked { 'ESP_GROUPTYPE' }{ 'curve25519' } = '' ;
2742 $checked { 'ESP_GROUPTYPE' }{ 'curve448' } = '' ;
2743 $checked { 'ESP_GROUPTYPE' }{ '768' } = '' ;
2744 $checked { 'ESP_GROUPTYPE' }{ '1024' } = '' ;
2745 $checked { 'ESP_GROUPTYPE' }{ '1536' } = '' ;
2746 $checked { 'ESP_GROUPTYPE' }{ '2048' } = '' ;
2747 $checked { 'ESP_GROUPTYPE' }{ '3072' } = '' ;
2748 $checked { 'ESP_GROUPTYPE' }{ '4096' } = '' ;
2749 $checked { 'ESP_GROUPTYPE' }{ '6144' } = '' ;
2750 $checked { 'ESP_GROUPTYPE' }{ '8192' } = '' ;
2751 $checked { 'ESP_GROUPTYPE' }{ 'none' } = '' ;
2752 @temp = split ( '\|' , $cgiparams { 'ESP_GROUPTYPE' });
2753 foreach my $key ( @temp ) { $checked { 'ESP_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2755 $checked { 'COMPRESSION' } = $cgiparams { 'COMPRESSION' } eq 'on' ?
"checked='checked'" : '' ;
2756 $checked { 'FORCE_MOBIKE' } = $cgiparams { 'FORCE_MOBIKE' } eq 'on' ?
"checked='checked'" : '' ;
2757 $checked { 'ONLY_PROPOSED' } = $cgiparams { 'ONLY_PROPOSED' } eq 'on' ?
"checked='checked'" : '' ;
2758 $checked { 'PFS' } = $cgiparams { 'PFS' } eq 'on' ?
"checked='checked'" : '' ;
2760 $selected { 'IKE_VERSION' }{ 'ikev1' } = '' ;
2761 $selected { 'IKE_VERSION' }{ 'ikev2' } = '' ;
2762 $selected { 'IKE_VERSION' }{ $cgiparams { 'IKE_VERSION' }} = "selected='selected'" ;
2764 $selected { 'DPD_ACTION' }{ 'clear' } = '' ;
2765 $selected { 'DPD_ACTION' }{ 'hold' } = '' ;
2766 $selected { 'DPD_ACTION' }{ 'restart' } = '' ;
2767 $selected { 'DPD_ACTION' }{ 'none' } = '' ;
2768 $selected { 'DPD_ACTION' }{ $cgiparams { 'DPD_ACTION' }} = "selected='selected'" ;
2770 $selected { 'START_ACTION' }{ 'add' } = '' ;
2771 $selected { 'START_ACTION' }{ 'route' } = '' ;
2772 $selected { 'START_ACTION' }{ 'start' } = '' ;
2773 $selected { 'START_ACTION' }{ $cgiparams { 'START_ACTION' }} = "selected='selected'" ;
2775 $selected { 'INACTIVITY_TIMEOUT' } = ();
2776 foreach my $timeout ( keys %INACTIVITY_TIMEOUTS ) {
2777 $selected { 'INACTIVITY_TIMEOUT' }{ $timeout } = "" ;
2779 $selected { 'INACTIVITY_TIMEOUT' }{ $cgiparams { 'INACTIVITY_TIMEOUT' }} = "selected" ;
2781 & Header
:: showhttpheaders
();
2782 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
2783 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2785 if ( $errormessage ) {
2786 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2787 print "<class name='base'> $errormessage " ;
2788 print " </class>" ;
2789 & Header
:: closebox
();
2793 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
2794 print "<class name='base'> $warnmessage " ;
2795 print " </class>" ;
2796 & Header
:: closebox
();
2799 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'advanced'}:" );
2801 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
2802 <input type='hidden' name='ADVANCED' value='yes' />
2803 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
2805 <table width='100%'>
2808 <th width="15%"></th>
2815 <td> $Lang ::tr{'vpn keyexchange'}:</td>
2817 <select name='IKE_VERSION'>
2818 <option value='ikev2' $selected {'IKE_VERSION'}{'ikev2'}>IKEv2</option>
2819 <option value='ikev1' $selected {'IKE_VERSION'}{'ikev1'}>IKEv1</option>
2825 <td class='boldbase' width="15%"> $Lang ::tr{'encryption'}</td>
2826 <td class='boldbase'>
2827 <select name='IKE_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
2828 <option value='chacha20poly1305' $checked {'IKE_ENCRYPTION'}{'chacha20poly1305'}>256 bit ChaCha20-Poly1305/128 bit ICV</option>
2829 <option value='aes256gcm128' $checked {'IKE_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
2830 <option value='aes256gcm96' $checked {'IKE_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
2831 <option value='aes256gcm64' $checked {'IKE_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
2832 <option value='aes256' $checked {'IKE_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
2833 <option value='camellia256' $checked {'IKE_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
2834 <option value='aes192gcm128' $checked {'IKE_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
2835 <option value='aes192gcm96' $checked {'IKE_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
2836 <option value='aes192gcm64' $checked {'IKE_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
2837 <option value='aes192' $checked {'IKE_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
2838 <option value='camellia192' $checked {'IKE_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
2839 <option value='aes128gcm128' $checked {'IKE_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
2840 <option value='aes128gcm96' $checked {'IKE_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
2841 <option value='aes128gcm64' $checked {'IKE_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
2842 <option value='aes128' $checked {'IKE_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
2843 <option value='camellia128' $checked {'IKE_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
2844 <option value='3des' $checked {'IKE_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC ( $Lang ::tr{'vpn weak'})</option>
2847 <td class='boldbase'>
2848 <select name='ESP_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
2849 <option value='chacha20poly1305' $checked {'ESP_ENCRYPTION'}{'chacha20poly1305'}>256 bit ChaCha20-Poly1305/128 bit ICV</option>
2850 <option value='aes256gcm128' $checked {'ESP_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
2851 <option value='aes256gcm96' $checked {'ESP_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
2852 <option value='aes256gcm64' $checked {'ESP_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
2853 <option value='aes256' $checked {'ESP_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
2854 <option value='camellia256' $checked {'ESP_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
2855 <option value='aes192gcm128' $checked {'ESP_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
2856 <option value='aes192gcm96' $checked {'ESP_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
2857 <option value='aes192gcm64' $checked {'ESP_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
2858 <option value='aes192' $checked {'ESP_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
2859 <option value='camellia192' $checked {'ESP_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
2860 <option value='aes128gcm128' $checked {'ESP_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
2861 <option value='aes128gcm96' $checked {'ESP_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
2862 <option value='aes128gcm64' $checked {'ESP_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
2863 <option value='aes128' $checked {'ESP_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
2864 <option value='camellia128' $checked {'ESP_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
2865 <option value='3des' $checked {'ESP_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC ( $Lang ::tr{'vpn weak'})</option>
2871 <td class='boldbase' width="15%"> $Lang ::tr{'integrity'}</td>
2872 <td class='boldbase'>
2873 <select name='IKE_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
2874 <option value='sha2_512' $checked {'IKE_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2875 <option value='sha2_384' $checked {'IKE_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2876 <option value='sha2_256' $checked {'IKE_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2877 <option value='aesxcbc' $checked {'IKE_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2878 <option value='sha' $checked {'IKE_INTEGRITY'}{'sha'}>SHA1 ( $Lang ::tr{'vpn weak'})</option>
2879 <option value='md5' $checked {'IKE_INTEGRITY'}{'md5'}>MD5 ( $Lang ::tr{'vpn broken'})</option>
2882 <td class='boldbase'>
2883 <select name='ESP_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
2884 <option value='sha2_512' $checked {'ESP_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2885 <option value='sha2_384' $checked {'ESP_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2886 <option value='sha2_256' $checked {'ESP_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2887 <option value='aesxcbc' $checked {'ESP_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2888 <option value='sha1' $checked {'ESP_INTEGRITY'}{'sha1'}>SHA1 ( $Lang ::tr{'vpn weak'})</option>
2889 <option value='md5' $checked {'ESP_INTEGRITY'}{'md5'}>MD5 ( $Lang ::tr{'vpn broken'})</option>
2894 <td class='boldbase' width="15%"> $Lang ::tr{'lifetime'} <img src='/blob.gif' alt='*' /></td>
2895 <td class='boldbase'>
2896 <input type='text' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' size='5' /> $Lang ::tr{'hours'}
2898 <td class='boldbase'>
2899 <input type='text' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' size='5' /> $Lang ::tr{'hours'}
2903 <td class='boldbase' width="15%"> $Lang ::tr{'grouptype'}</td>
2904 <td class='boldbase'>
2905 <select name='IKE_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
2906 <option value='curve25519' $checked {'IKE_GROUPTYPE'}{'curve25519'}>Curve 25519 (256 bit)</option>
2907 <option value='curve448' $checked {'IKE_GROUPTYPE'}{'curve448'}>Curve 448 (224 bit)</option>
2908 <option value='e521' $checked {'IKE_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
2909 <option value='e512bp' $checked {'IKE_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
2910 <option value='e384' $checked {'IKE_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
2911 <option value='e384bp' $checked {'IKE_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
2912 <option value='e256' $checked {'IKE_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
2913 <option value='e256bp' $checked {'IKE_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
2914 <option value='e224' $checked {'IKE_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
2915 <option value='e224bp' $checked {'IKE_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
2916 <option value='e192' $checked {'IKE_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
2917 <option value='8192' $checked {'IKE_GROUPTYPE'}{'8192'}>MODP-8192</option>
2918 <option value='6144' $checked {'IKE_GROUPTYPE'}{'6144'}>MODP-6144</option>
2919 <option value='4096' $checked {'IKE_GROUPTYPE'}{'4096'}>MODP-4096</option>
2920 <option value='3072' $checked {'IKE_GROUPTYPE'}{'3072'}>MODP-3072</option>
2921 <option value='2048' $checked {'IKE_GROUPTYPE'}{'2048'}>MODP-2048</option>
2922 <option value='1536' $checked {'IKE_GROUPTYPE'}{'1536'}>MODP-1536</option>
2923 <option value='1024' $checked {'IKE_GROUPTYPE'}{'1024'}>MODP-1024 ( $Lang ::tr{'vpn broken'})</option>
2924 <option value='768' $checked {'IKE_GROUPTYPE'}{'768'}>MODP-768 ( $Lang ::tr{'vpn broken'})</option>
2927 <td class='boldbase'>
2928 <select name='ESP_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
2929 <option value='curve25519' $checked {'ESP_GROUPTYPE'}{'curve25519'}>Curve 25519 (256 bit)</option>
2930 <option value='curve448' $checked {'ESP_GROUPTYPE'}{'curve448'}>Curve 448 (224 bit)</option>
2931 <option value='e521' $checked {'ESP_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
2932 <option value='e512bp' $checked {'ESP_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
2933 <option value='e384' $checked {'ESP_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
2934 <option value='e384bp' $checked {'ESP_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
2935 <option value='e256' $checked {'ESP_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
2936 <option value='e256bp' $checked {'ESP_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
2937 <option value='e224' $checked {'ESP_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
2938 <option value='e224bp' $checked {'ESP_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
2939 <option value='e192' $checked {'ESP_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
2940 <option value='8192' $checked {'ESP_GROUPTYPE'}{'8192'}>MODP-8192</option>
2941 <option value='6144' $checked {'ESP_GROUPTYPE'}{'6144'}>MODP-6144</option>
2942 <option value='4096' $checked {'ESP_GROUPTYPE'}{'4096'}>MODP-4096</option>
2943 <option value='3072' $checked {'ESP_GROUPTYPE'}{'3072'}>MODP-3072</option>
2944 <option value='2048' $checked {'ESP_GROUPTYPE'}{'2048'}>MODP-2048</option>
2945 <option value='1536' $checked {'ESP_GROUPTYPE'}{'1536'}>MODP-1536</option>
2946 <option value='1024' $checked {'ESP_GROUPTYPE'}{'1024'}>MODP-1024 ( $Lang ::tr{'vpn broken'})</option>
2947 <option value='768' $checked {'ESP_GROUPTYPE'}{'768'}>MODP-768 ( $Lang ::tr{'vpn broken'})</option>
2948 <option value='none' $checked {'ESP_GROUPTYPE'}{'none'}>- $Lang ::tr{'none'} -</option>
2957 <h2> $Lang ::tr{'dead peer detection'}</h2>
2959 <table width="100%">
2961 <td width="15%"> $Lang ::tr{'dpd action'}:</td>
2963 <select name='DPD_ACTION'>
2964 <option value='none' $selected {'DPD_ACTION'}{'none'}>- $Lang ::tr{'disabled'} -</option>
2965 <option value='clear' $selected {'DPD_ACTION'}{'clear'}>clear</option>
2966 <option value='hold' $selected {'DPD_ACTION'}{'hold'}>hold</option>
2967 <option value='restart' $selected {'DPD_ACTION'}{'restart'}>restart</option>
2972 <td width="15%"> $Lang ::tr{'dpd timeout'}: <img src='/blob.gif' alt='*' /></td>
2974 <input type='text' name='DPD_TIMEOUT' size='5' value=' $cgiparams {'DPD_TIMEOUT'}' />
2978 <td width="15%"> $Lang ::tr{'dpd delay'}: <img src='/blob.gif' alt='*' /></td>
2980 <input type='text' name='DPD_DELAY' size='5' value=' $cgiparams {'DPD_DELAY'}' />
2987 <table width="100%">
2991 <input type='checkbox' name='ONLY_PROPOSED' $checked {'ONLY_PROPOSED'} />
2992 IKE+ESP: $Lang ::tr{'use only proposed settings'}
2996 <label> $Lang ::tr{'vpn start action'}</label>
2997 <select name="START_ACTION">
2998 <option value="route" $selected {'START_ACTION'}{'route'}> $Lang ::tr{'vpn start action route'}</option>
2999 <option value="start" $selected {'START_ACTION'}{'start'}> $Lang ::tr{'vpn start action start'}</option>
3000 <option value="add" $selected {'START_ACTION'}{'add'} > $Lang ::tr{'vpn start action add'}</option>
3007 <input type='checkbox' name='PFS' $checked {'PFS'} />
3008 $Lang ::tr{'pfs yes no'}
3012 <label> $Lang ::tr{'vpn inactivity timeout'}</label>
3013 <select name="INACTIVITY_TIMEOUT">
3015 foreach my $t ( sort { $a <=> $b } keys %INACTIVITY_TIMEOUTS ) {
3016 print "<option value= \" $t \" $selected {'INACTIVITY_TIMEOUT'}{ $t }> $INACTIVITY_TIMEOUTS { $t }</option> \n " ;
3027 <input type='checkbox' name='COMPRESSION' $checked {'COMPRESSION'} />
3028 $Lang ::tr{'vpn payload compression'}
3035 <input type='checkbox' name='FORCE_MOBIKE' $checked {'FORCE_MOBIKE'} />
3036 $Lang ::tr{'vpn force mobike'}
3041 <td align='left'><img src='/blob.gif' align='top' alt='*' /> $Lang ::tr{'required field'}</td>
3043 <input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />
3044 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' />
3050 & Header
:: closebox
();
3051 & Header
:: closebigbox
();
3052 & Header
:: closepage
();
3059 ### Default status page
3064 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%cgiparams );
3065 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
3066 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
3067 $cgiparams { 'CA_NAME' } = '' ;
3069 my @status = `/usr/local/bin/ipsecctrl I 2>/dev/null` ;
3071 $checked { 'ENABLED' } = $cgiparams { 'ENABLED' } eq 'on' ?
"checked='checked'" : '' ;
3073 & Header
:: showhttpheaders
();
3074 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
3075 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
3077 if ( $errormessage ) {
3078 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
3079 print "<class name='base'> $errormessage \n " ;
3080 print " </class> \n " ;
3081 & Header
:: closebox
();
3085 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
3086 print " $warnmessage <br>" ;
3087 print " $Lang ::tr{'fwdfw warn1'}<br>" ;
3088 & Header
:: closebox
();
3089 print "<center><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'ok'}' style='width: 5em;'></form>" ;
3090 & Header
:: closepage
();
3094 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'global settings' });
3096 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3097 <table width='100%'>
3099 <td width='60%' class='base'>
3100 $Lang ::tr{'enabled'}
3103 <input type='checkbox' name='ENABLED' $checked {'ENABLED'} />
3107 <td class='base' nowrap='nowrap' width="60%"> $Lang ::tr{'ipsec roadwarrior endpoint'}:</td>
3108 <td width="40%"><input type='text' name='RW_ENDPOINT' value=' $cgiparams {'RW_ENDPOINT'}' /></td>
3111 <td class='base' nowrap='nowrap' width="60%"> $Lang ::tr{'host to net vpn'}:</td>
3112 <td width="40%"><input type='text' name='RW_NET' value=' $cgiparams {'RW_NET'}' /></td>
3115 <td width='100%' colspan="2" align='right' class='base'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' /></td>
3121 & Header
:: closebox
();
3123 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection status and controlc' });
3125 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
3127 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
3128 <th width='22%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></th>
3129 <th width='23%' class='boldbase' align='center'><b> $Lang ::tr{'common name'}</b></th>
3130 <th width='30%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></th>
3131 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></th>
3132 <th class='boldbase' align='center' colspan='7'><b> $Lang ::tr{'action'}</b></th>
3138 foreach my $key ( sort { ncmp
( $confighash { $a }[ 1 ], $confighash { $b }[ 1 ]) } keys %confighash ) {
3139 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
3143 $col = "bgcolor=' $color {'color20'}'" ;
3146 $col = "bgcolor=' $color {'color22'}'" ;
3148 print "<td align='center' nowrap='nowrap' $col > $confighash { $key }[1]</td>" ;
3149 print "<td align='center' nowrap='nowrap' $col >" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ") $confighash { $key }[29]</td>" ;
3150 if ( $confighash { $key }[ 2 ] eq ' %auth -dn' ) {
3151 print "<td align='left' nowrap='nowrap' $col > $confighash { $key }[9]</td>" ;
3152 } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
3153 print "<td align='left' nowrap='nowrap' $col > $confighash { $key }[2]</td>" ;
3155 print "<td align='left' $col > </td>" ;
3157 print "<td align='center' $col > $confighash { $key }[25]</td>" ;
3158 my $col1 = "bgcolor='${Header::colourred}'" ;
3159 my $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
3160 if ( $confighash { $key }[ 33 ] eq "add" ) {
3161 $col1 = "bgcolor='${Header::colourorange}'" ;
3162 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'vpn wait'}</font></b>" ;
3164 foreach my $line ( @status ) {
3165 if (( $line =~ /\"$confighash{$key}[1]\".*IPsec SA established/ ) ||
3166 ( $line =~ /$confighash{$key}[1]\{.*INSTALLED/ )) {
3167 $col1 = "bgcolor='${Header::colourgreen}'" ;
3168 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b>" ;
3170 } elsif ( $line =~ /$confighash{$key}[1]\[.*CONNECTING/ ) {
3171 $col1 = "bgcolor='${Header::colourorange}'" ;
3172 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'vpn connecting'}</font></b>" ;
3173 } elsif ( $line =~ /$confighash{$key}[1]\{.*ROUTED/ ) {
3174 $col1 = "bgcolor='${Header::colourorange}'" ;
3175 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'vpn on-demand'}</font></b>" ;
3178 # move to blue if really down
3179 if ( $confighash { $key }[ 0 ] eq 'off' && $col1 =~ /${Header::colourred}/ ) {
3180 $col1 = "bgcolor='${Header::colourblue}'" ;
3181 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
3184 <td align='center' $col1 > $active </td>
3185 <td align='center' $col >
3186 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3187 <input type='image' name=' $Lang ::tr{'restart'}' src='/images/reload.gif' alt=' $Lang ::tr{'restart'}' title=' $Lang ::tr{'restart'}' />
3188 <input type='hidden' name='ACTION' value=' $Lang ::tr{'restart'}' />
3189 <input type='hidden' name='KEY' value=' $key ' />
3194 if (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
3196 <td align='center' $col >
3197 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3198 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' />
3199 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
3200 <input type='hidden' name='KEY' value=' $key ' />
3206 print "<td width='2%' $col > </td>" ;
3208 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/certs/ $confighash { $key }[1].p12" ) {
3210 <td align='center' $col >
3211 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3212 <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'}' />
3213 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
3214 <input type='hidden' name='KEY' value=' $key ' />
3219 } elsif (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
3221 <td align='center' $col >
3222 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3223 <input type='image' name=' $Lang ::tr{'download certificate'}' src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' title=' $Lang ::tr{'download certificate'}' />
3224 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
3225 <input type='hidden' name='KEY' value=' $key ' />
3231 print "<td width='2%' $col > </td>" ;
3235 if ( $confighash { $key }[ 3 ] eq 'host' ) {
3237 <td align='center' $col >
3238 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3239 <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'}' />
3240 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download apple profile'}' />
3241 <input type='hidden' name='KEY' value=' $key ' />
3246 print "<td width='2%' $col > </td>" ;
3250 <td align='center' $col >
3251 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3252 <input type='image' name=' $Lang ::tr{'toggle enable disable'}' src='/images/ $gif ' alt=' $Lang ::tr{'toggle enable disable'}' title=' $Lang ::tr{'toggle enable disable'}' />
3253 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
3254 <input type='hidden' name='KEY' value=' $key ' />
3258 <td align='center' $col >
3259 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3260 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
3261 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' title=' $Lang ::tr{'edit'}' />
3262 <input type='hidden' name='KEY' value=' $key ' />
3265 <td align='center' $col >
3266 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3267 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
3268 <input type='image' name=' $Lang ::tr{'remove'}' src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' title=' $Lang ::tr{'remove'}' />
3269 <input type='hidden' name='KEY' value=' $key ' />
3279 # If the config file contains entries, print Key to action icons
3284 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
3285 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
3286 <td class='base'> $Lang ::tr{'click to disable'}</td>
3287 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
3288 <td class='base'> $Lang ::tr{'show certificate'}</td>
3289 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
3290 <td class='base'> $Lang ::tr{'edit'}</td>
3291 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
3292 <td class='base'> $Lang ::tr{'remove'}</td>
3296 <td> <img src='/images/off.gif' alt='?OFF' /></td>
3297 <td class='base'> $Lang ::tr{'click to enable'}</td>
3298 <td> <img src='/images/floppy.gif' alt='?FLOPPY' /></td>
3299 <td class='base'> $Lang ::tr{'download certificate'}</td>
3300 <td> <img src='/images/reload.gif' alt='?RELOAD'/></td>
3301 <td class='base'> $Lang ::tr{'restart'}</td>
3309 <table width='100%'>
3310 <tr><td align='right' colspan='9'>
3311 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3312 <input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />
3318 & Header
:: closebox
();
3320 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'certificate authorities'}" );
3322 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
3324 <th width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
3325 <th width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></th>
3326 <th width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></th>
3330 my $col1 = "bgcolor=' $color {'color22'}'" ;
3331 my $col2 = "bgcolor=' $color {'color20'}'" ;
3332 if (- f
"${General::swroot}/ca/cacert.pem" ) {
3333 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/cacert.pem" ));
3336 <td class='base' $col1 > $Lang ::tr{'root certificate'}</td>
3337 <td class='base' $col1 > $casubject </td>
3338 <td width='3%' align='center' $col1 >
3339 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3340 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
3341 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/info.gif' alt=' $Lang ::tr{'show root certificate'}' title=' $Lang ::tr{'show root certificate'}' />
3344 <td width='3%' align='center' $col1 >
3345 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3346 <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'}' />
3347 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
3350 <td width='4%' $col1 > </td></tr>
3354 # display rootcert generation buttons
3357 <td class='base' $col1 > $Lang ::tr{'root certificate'}:</td>
3358 <td class='base' $col1 > $Lang ::tr{'not present'}</td>
3359 <td colspan='3' $col1 > </td></tr>
3364 if (- f
"${General::swroot}/certs/hostcert.pem" ) {
3365 my $hostsubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/certs/hostcert.pem" ));
3369 <td class='base' $col2 > $Lang ::tr{'host certificate'}</td>
3370 <td class='base' $col2 > $hostsubject </td>
3371 <td width='3%' align='center' $col2 >
3372 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3373 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
3374 <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'}' />
3377 <td width='3%' align='center' $col2 >
3378 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3379 <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'}" />
3380 <input type='hidden' name='ACTION' value=" $Lang ::tr{'download host certificate'}" />
3383 <td width='4%' $col2 > </td></tr>
3390 <td width='25%' class='base' $col2 > $Lang ::tr{'host certificate'}:</td>
3391 <td class='base' $col2 > $Lang ::tr{'not present'}</td>
3392 <td colspan='3' $col2 > </td></tr>
3398 if ( keys %cahash > 0 ) {
3399 foreach my $key ( keys %cahash ) {
3400 if ( $rowcolor ++ % 2 ) {
3402 $col = "bgcolor=' $color {'color20'}'" ;
3405 $col = "bgcolor=' $color {'color22'}'" ;
3407 print "<td class='base' $col > $cahash { $key }[0]</td> \n " ;
3408 print "<td class='base' $col > $cahash { $key }[1]</td> \n " ;
3410 <td align='center' $col >
3411 <form method='post' name='cafrm${key}a' action=' $ENV {'SCRIPT_NAME'}'>
3412 <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'}' />
3413 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
3414 <input type='hidden' name='KEY' value=' $key ' />
3417 <td align='center' $col >
3418 <form method='post' name='cafrm${key}b' action=' $ENV {'SCRIPT_NAME'}'>
3419 <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'}' />
3420 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
3421 <input type='hidden' name='KEY' value=' $key ' />
3424 <td align='center' $col >
3425 <form method='post' name='cafrm${key}c' action=' $ENV {'SCRIPT_NAME'}'>
3426 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
3427 <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'}' />
3428 <input type='hidden' name='KEY' value=' $key ' />
3438 # If the file contains entries, print Key to action icons
3439 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
3442 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
3443 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
3444 <td class='base'> $Lang ::tr{'show certificate'}</td>
3445 <td> <img src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' /></td>
3446 <td class='base'> $Lang ::tr{'download certificate'}</td>
3451 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>" ;
3455 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
3456 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
3459 <td class='base' nowrap='nowrap'> $Lang ::tr{'ca name'}: <img src='/blob.gif' alt='*' /></td>
3460 <td nowrap='nowrap'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' /> </td>
3461 <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td>
3462 <td nowrap='nowrap'><input type='submit' name='ACTION' value=' $Lang ::tr{'upload ca certificate'}' /></td>
3465 <td colspan='3'> $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}:</td>
3466 <td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' /></td>
3472 & Header
:: closebox
();
3473 & Header
:: closebigbox
();
3474 & Header
:: closepage
();
3476 sub array_unique
($) {
3481 foreach my $e ( @
$array ) {
3482 next if $seen { $e }++;
3489 sub make_algos
($$$$$) {
3490 my ( $mode , $encs , $ints , $grps , $pfs ) = @_ ;
3493 foreach my $enc ( @
$encs ) {
3494 foreach my $int ( @
$ints ) {
3495 foreach my $grp ( @
$grps ) {
3498 if ( $mode eq "ike" ) {
3501 if ( $grp =~ m/^e(.*)$/ ) {
3502 push ( @algo , "ecp $1 " );
3503 } elsif ( $grp =~ m/curve(25519|448)/ ) {
3504 push ( @algo , " $grp " );
3506 push ( @algo , "modp $grp " );
3509 } elsif ( $mode eq "esp" ) {
3510 my $is_aead = ( $enc =~ m/[cg]cm/ );
3516 if (! $pfs || $grp eq "none" ) {
3518 } elsif ( $grp =~ m/^e(.*)$/ ) {
3519 push ( @algo , "ecp $1 " );
3520 } elsif ( $grp =~ m/curve(25519|448)/ ) {
3521 push ( @algo , " $grp " );
3523 push ( @algo , "modp $grp " );
3527 push ( @algos , join ( "-" , @algo ));
3532 return & array_unique
( \
@algos );
3535 sub make_subnets
($$) {
3536 my $direction = shift ;
3537 my $subnets = shift ;
3539 my @nets = split ( /\|/ , $subnets );
3541 foreach my $net ( @nets ) {
3542 my $cidr_net = & General
:: ipcidr
( $net );
3544 # Skip 0.0.0.0/0 for remote because this renders the
3545 # while system inaccessible
3546 next if (( $direction eq "right" ) && ( $cidr_net eq "0.0.0.0/0" ));
3548 push ( @cidr_nets , $cidr_net );
3551 return join ( "," , @cidr_nets );