]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/vpnmain.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-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 ###############################################################################
25 use File
:: Temp qw
/ tempfile tempdir / ;
28 # enable only the following on debugging purpose
30 #use CGI::Carp 'fatalsToBrowser';
32 require '/var/ipfire/general-functions.pl' ;
33 require "${General::swroot}/lang.pl" ;
34 require "${General::swroot}/header.pl" ;
35 require "${General::swroot}/countries.pl" ;
37 #workaround to suppress a warning when a variable is used only once
38 my @dummy = ( ${ Header
:: colourgreen
}, ${ Header
:: colourblue
} );
42 ### Initialize variables
44 my $sleepDelay = 4 ; # after a call to ipsecctrl S or R, wait this delay (seconds) before reading status (let the ipsec do its job)
53 my $errormessage = '' ;
56 my %mainsettings = ();
57 & General
:: readhash
( "${General::swroot}/main/settings" , \
%mainsettings );
58 & General
:: readhash
( "/srv/web/ipfire/html/themes/ipfire/include/colors.txt" , \
%color );
60 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%netsettings );
62 my %INACTIVITY_TIMEOUTS = (
63 300 => $Lang :: tr
{ 'five minutes' },
64 600 => $Lang :: tr
{ 'ten minutes' },
65 900 => $Lang :: tr
{ 'fifteen minutes' },
66 1800 => $Lang :: tr
{ 'thirty minutes' },
67 3600 => $Lang :: tr
{ 'one hour' },
68 43200 => $Lang :: tr
{ 'twelve hours' },
69 86400 => $Lang :: tr
{ '24 hours' },
70 0 => "- $Lang ::tr{'unlimited'} -" ,
75 & General
:: get_aliases
( \
%aliases );
79 $cgiparams { 'ENABLED' } = 'off' ;
80 $cgiparams { 'EDIT_ADVANCED' } = 'off' ;
81 $cgiparams { 'ACTION' } = '' ;
82 $cgiparams { 'CA_NAME' } = '' ;
83 $cgiparams { 'KEY' } = '' ;
84 $cgiparams { 'TYPE' } = '' ;
85 $cgiparams { 'ADVANCED' } = '' ;
86 $cgiparams { 'NAME' } = '' ;
87 $cgiparams { 'LOCAL_SUBNET' } = '' ;
88 $cgiparams { 'REMOTE_SUBNET' } = '' ;
89 $cgiparams { 'LOCAL' } = '' ;
90 $cgiparams { 'REMOTE' } = '' ;
91 $cgiparams { 'LOCAL_ID' } = '' ;
92 $cgiparams { 'REMOTE_ID' } = '' ;
93 $cgiparams { 'REMARK' } = '' ;
94 $cgiparams { 'PSK' } = '' ;
95 $cgiparams { 'CERT_NAME' } = '' ;
96 $cgiparams { 'CERT_EMAIL' } = '' ;
97 $cgiparams { 'CERT_OU' } = '' ;
98 $cgiparams { 'CERT_ORGANIZATION' } = '' ;
99 $cgiparams { 'CERT_CITY' } = '' ;
100 $cgiparams { 'CERT_STATE' } = '' ;
101 $cgiparams { 'CERT_COUNTRY' } = '' ;
102 $cgiparams { 'SUBJECTALTNAME' } = '' ;
103 $cgiparams { 'CERT_PASS1' } = '' ;
104 $cgiparams { 'CERT_PASS2' } = '' ;
105 $cgiparams { 'ROOTCERT_HOSTNAME' } = '' ;
106 $cgiparams { 'ROOTCERT_COUNTRY' } = '' ;
107 $cgiparams { 'P12_PASS' } = '' ;
108 $cgiparams { 'ROOTCERT_ORGANIZATION' } = '' ;
109 $cgiparams { 'ROOTCERT_HOSTNAME' } = '' ;
110 $cgiparams { 'ROOTCERT_EMAIL' } = '' ;
111 $cgiparams { 'ROOTCERT_OU' } = '' ;
112 $cgiparams { 'ROOTCERT_CITY' } = '' ;
113 $cgiparams { 'ROOTCERT_STATE' } = '' ;
114 $cgiparams { 'RW_NET' } = '' ;
115 $cgiparams { 'DPD_DELAY' } = '30' ;
116 $cgiparams { 'DPD_TIMEOUT' } = '120' ;
117 $cgiparams { 'FORCE_MOBIKE' } = 'off' ;
118 $cgiparams { 'START_ACTION' } = 'route' ;
119 $cgiparams { 'INACTIVITY_TIMEOUT' } = 1800 ;
120 $cgiparams { 'MODE' } = "tunnel" ;
121 $cgiparams { 'INTERFACE_MODE' } = "" ;
122 $cgiparams { 'INTERFACE_ADDRESS' } = "" ;
123 $cgiparams { 'INTERFACE_MTU' } = 1500 ;
124 & Header
:: getcgihash
( \
%cgiparams , { 'wantfile' => 1 , 'filevar' => 'FH' });
130 my $hostname = $_ [ 0 ];
131 unless ( $hostname ) { return "No hostname" };
132 my $res = new Net
:: DNS
:: Resolver
;
133 my $query = $res -> search ( " $hostname " );
135 foreach my $rr ( $query -> answer ) {
136 ## Potential bug - we are only looking at A records:
137 return 0 if $rr -> type eq "A" ;
140 return $res -> errorstring ;
144 ### Just return true is one interface is vpn enabled
147 return ( $vpnsettings { 'ENABLED' } eq 'on' );
150 ### old version: maintain serial number to one, without explication.
151 ### this: let the counter go, so that each cert is numbered.
153 sub cleanssldatabase
{
154 if ( open ( FILE
, ">${General::swroot}/certs/serial" )) {
158 if ( open ( FILE
, ">${General::swroot}/certs/index.txt" )) {
162 if ( open ( FILE
, ">${General::swroot}/certs/index.txt.attr" )) {
166 unlink ( "${General::swroot}/certs/index.txt.old" );
167 unlink ( "${General::swroot}/certs/index.txt.attr.old" );
168 unlink ( "${General::swroot}/certs/serial.old" );
169 unlink ( "${General::swroot}/certs/01.pem" );
171 sub newcleanssldatabase
{
172 if (! - s
"${General::swroot}/certs/serial" ) {
173 open ( FILE
, ">${General::swroot}/certs/serial" );
177 if (! - s
">${General::swroot}/certs/index.txt" ) {
178 system ( "touch ${General::swroot}/certs/index.txt" );
180 if (! - s
">${General::swroot}/certs/index.txt.attr" ) {
181 system ( "touch ${General::swroot}/certs/index.txt.attr" );
183 unlink ( "${General::swroot}/certs/index.txt.old" );
184 unlink ( "${General::swroot}/certs/index.txt.attr.old" );
185 unlink ( "${General::swroot}/certs/serial.old" );
186 # unlink ("${General::swroot}/certs/01.pem"); numbering evolves. Wrong place to delete
190 ### Call openssl and return errormessage if any
194 my $retssl = `/usr/bin/openssl $opt 2>&1` ; #redirect stderr
196 foreach my $line ( split ( /\n/ , $retssl )) {
197 & General
:: log ( "ipsec" , " $line " ) if ( 0 ); # 1 for verbose logging
198 $ret .= '<br>' . $line if ( $line =~ /error|unknown/ );
201 $ret = & Header
:: cleanhtml
( $ret );
203 return $ret ?
" $Lang ::tr{'openssl produced an error'}: $ret " : '' ;
206 ### Obtain a CN from given cert
208 sub getCNfromcert
($) {
209 #&General::log("ipsec", "Extracting name from $_[0]...");
210 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
211 $temp =~ /Subject:.*CN = (.*)[\n]/ ;
213 $temp =~ s
+/ Email
+, E
+;
214 $temp =~ s/ ST = / S = / ;
220 ### Obtain Subject from given cert
222 sub getsubjectfromcert
($) {
223 #&General::log("ipsec", "Extracting subject from $_[0]...");
224 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
225 $temp =~ /Subject: (.*)[\n]/ ;
227 $temp =~ s
+/ Email
+, E
+;
228 $temp =~ s/ ST = / S = / ;
232 ### Combine local subnet and connection name to make a unique name for each connection section
233 ### (this sub is not used now)
235 sub makeconnname
($) {
239 $subnet =~ /^(.*?)\/ (.* ?
)$/; # $1=IP $2=mask
240 my $ip = unpack ( 'N' , & Socket
:: inet_aton
( $1 ));
241 if ( length ( $2 ) > 2 ) {
242 my $mm = unpack ( 'N' , & Socket
:: inet_aton
( $2 ));
243 while ( ( $mm & 1 )== 0 ) {
250 return sprintf ( " %s - %X " , $conn , $ip );
253 ### Write a config file.
255 ###Type=Host : GUI can choose the interface used (RED,GREEN,BLUE) and
256 ### the side is always defined as 'left'.
259 sub writeipsecfiles
{
260 my %lconfighash = ();
261 my %lvpnsettings = ();
262 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%lconfighash );
263 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%lvpnsettings );
265 open ( CONF
, ">${General::swroot}/vpn/ipsec.conf" ) or die "Unable to open ${General::swroot}/vpn/ipsec.conf: $!" ;
266 open ( SECRETS
, ">${General::swroot}/vpn/ipsec.secrets" ) or die "Unable to open ${General::swroot}/vpn/ipsec.secrets: $!" ;
269 print CONF
"version 2 \n\n " ;
270 print CONF
"conn %default \n " ;
271 print CONF
" \t keyingtries= %forever \n " ;
274 # Add user includes to config file
275 if (- e
"/etc/ipsec.user.conf" ) {
276 print CONF
"include /etc/ipsec.user.conf \n " ;
280 print SECRETS
"include /etc/ipsec.user.secrets \n " ;
282 if (- f
"${General::swroot}/certs/hostkey.pem" ) {
283 print SECRETS
": RSA ${General::swroot}/certs/hostkey.pem \n "
285 my $last_secrets = '' ; # old the less specifics connections
287 foreach my $key ( keys %lconfighash ) {
288 next if ( $lconfighash { $key }[ 0 ] ne 'on' );
290 #remote peer is not set? => use '%any'
291 $lconfighash { $key }[ 10 ] = ' %any ' if ( $lconfighash { $key }[ 10 ] eq '' );
293 # Field 6 might be "off" on old installations
294 if ( $lconfighash { $key }[ 6 ] eq "off" ) {
295 $lconfighash { $key }[ 6 ] = $lvpnsettings { "VPN_IP" };
299 if ( $lconfighash { $key }[ 6 ]) {
300 $localside = $lconfighash { $key }[ 6 ];
302 $localside = " %defaultroute " ;
305 my $interface_mode = $lconfighash { $key }[ 36 ];
307 print CONF
"conn $lconfighash { $key }[1] \n " ;
308 print CONF
" \t left= $localside \n " ;
310 if ( $interface_mode eq "gre" ) {
311 print CONF
" \t leftprotoport=gre \n " ;
312 } elsif ( $interface_mode eq "vti" ) {
313 print CONF
" \t leftsubnet=0.0.0.0/0 \n " ;
315 print CONF
" \t leftsubnet=" . & make_subnets
( "left" , $lconfighash { $key }[ 8 ]) . " \n " ;
318 print CONF
" \t leftfirewall=yes \n " ;
319 print CONF
" \t lefthostaccess=yes \n " ;
320 print CONF
" \t right= $lconfighash { $key }[10] \n " ;
322 if ( $lconfighash { $key }[ 3 ] eq 'net' ) {
323 if ( $interface_mode eq "gre" ) {
324 print CONF
" \t rightprotoport=gre \n " ;
325 } elsif ( $interface_mode eq "vti" ) {
326 print CONF
" \t rightsubnet=0.0.0.0/0 \n " ;
328 print CONF
" \t rightsubnet=" . & make_subnets
( "right" , $lconfighash { $key }[ 11 ]) . " \n " ;
332 # Local Cert and Remote Cert (unless auth is DN dn-auth)
333 if ( $lconfighash { $key }[ 4 ] eq 'cert' ) {
334 print CONF
" \t leftcert=${General::swroot}/certs/hostcert.pem \n " ;
335 print CONF
" \t rightcert=${General::swroot}/certs/ $lconfighash { $key }[1]cert.pem \n " if ( $lconfighash { $key }[ 2 ] ne ' %auth -dn' );
338 # Local and Remote IDs
339 print CONF
" \t leftid= \" $lconfighash { $key }[7] \"\n " if ( $lconfighash { $key }[ 7 ]);
340 print CONF
" \t rightid= \" $lconfighash { $key }[9] \"\n " if ( $lconfighash { $key }[ 9 ]);
343 if ( $lconfighash { $key }[ 35 ] eq "transport" ) {
344 print CONF
" \t type=transport \n " ;
346 print CONF
" \t type=tunnel \n " ;
350 if ( $interface_mode eq "vti" ) {
351 print CONF
" \t mark= $key \n " ;
355 my $pfs = $lconfighash { $key }[ 28 ] eq 'on' ?
'on' : 'off' ;
358 if ( $lconfighash { $key }[ 18 ] && $lconfighash { $key }[ 19 ] && $lconfighash { $key }[ 20 ]) {
359 my @encs = split ( '\|' , $lconfighash { $key }[ 18 ]);
360 my @ints = split ( '\|' , $lconfighash { $key }[ 19 ]);
361 my @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
363 my @algos = & make_algos
( "ike" , \
@encs , \
@ints , \
@groups , 1 );
364 print CONF
" \t ike=" . join ( "," , @algos );
366 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
373 if ( $lconfighash { $key }[ 21 ] && $lconfighash { $key }[ 22 ]) {
374 my @encs = split ( '\|' , $lconfighash { $key }[ 21 ]);
375 my @ints = split ( '\|' , $lconfighash { $key }[ 22 ]);
376 my @groups = split ( '\|' , $lconfighash { $key }[ 23 ]);
378 # Use IKE grouptype if no ESP group type has been selected
379 # (for backwards compatibility)
380 if ( $lconfighash { $key }[ 23 ] eq "" ) {
381 @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
384 my @algos = & make_algos
( "esp" , \
@encs , \
@ints , \
@groups , ( $pfs eq "on" ));
385 print CONF
" \t esp=" . join ( "," , @algos );
387 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
395 if (! $lconfighash { $key }[ 29 ]) {
396 $lconfighash { $key }[ 29 ] = "ikev1" ;
399 print CONF
" \t keyexchange= $lconfighash { $key }[29] \n " ;
402 print CONF
" \t ikelifetime= $lconfighash { $key }[16]h \n " if ( $lconfighash { $key }[ 16 ]);
403 print CONF
" \t keylife= $lconfighash { $key }[17]h \n " if ( $lconfighash { $key }[ 17 ]);
406 print CONF
" \t compress=yes \n " if ( $lconfighash { $key }[ 13 ] eq 'on' );
409 if (( $lconfighash { $key }[ 29 ] eq "ikev2" ) && ( $lconfighash { $key }[ 32 ] eq 'on' )) {
410 print CONF
" \t mobike=yes \n " ;
413 # Dead Peer Detection
414 my $dpdaction = $lconfighash { $key }[ 27 ];
415 print CONF
" \t dpdaction= $dpdaction \n " ;
417 # If the dead peer detection is disabled and IKEv2 is used,
418 # dpddelay must be set to zero, too.
419 if ( $dpdaction eq "none" ) {
420 if ( $lconfighash { $key }[ 29 ] eq "ikev2" ) {
421 print CONF
" \t dpddelay=0 \n " ;
424 my $dpddelay = $lconfighash { $key }[ 31 ];
428 print CONF
" \t dpddelay= $dpddelay \n " ;
429 my $dpdtimeout = $lconfighash { $key }[ 30 ];
433 print CONF
" \t dpdtimeout= $dpdtimeout \n " ;
436 # Build Authentication details: LEFTid RIGHTid : PSK psk
438 if ( $lconfighash { $key }[ 4 ] eq 'psk' ) {
439 $psk_line = ( $lconfighash { $key }[ 7 ] ?
$lconfighash { $key }[ 7 ] : $localside ) . " " ;
440 $psk_line .= $lconfighash { $key }[ 9 ] ?
$lconfighash { $key }[ 9 ] : $lconfighash { $key }[ 10 ]; #remoteid or remote address?
441 $psk_line .= " : PSK ' $lconfighash { $key }[5]' \n " ;
442 # if the line contains %any, it is less specific than two IP or ID, so move it at end of file.
443 if ( $psk_line =~ /%any/ ) {
444 $last_secrets .= $psk_line ;
446 print SECRETS
$psk_line ;
448 print CONF
" \t authby=secret \n " ;
450 print CONF
" \t authby=rsasig \n " ;
451 print CONF
" \t leftrsasigkey= %cert \n " ;
452 print CONF
" \t rightrsasigkey= %cert \n " ;
455 my $start_action = $lconfighash { $key }[ 33 ];
456 if (! $start_action ) {
457 $start_action = "start" ;
460 my $inactivity_timeout = $lconfighash { $key }[ 34 ];
461 if ( $inactivity_timeout eq "" ) {
462 $inactivity_timeout = 900 ;
465 # Automatically start only if a net-to-net connection
466 if ( $lconfighash { $key }[ 3 ] eq 'host' ) {
467 print CONF
" \t auto=add \n " ;
468 print CONF
" \t rightsourceip= $lvpnsettings {'RW_NET'} \n " ;
470 print CONF
" \t auto= $start_action \n " ;
472 # If in on-demand mode, we terminate the tunnel
473 # after 15 min of no traffic
474 if ( $start_action eq 'route' && $inactivity_timeout > 0 ) {
475 print CONF
" \t inactivity= $inactivity_timeout \n " ;
480 print CONF
" \t fragmentation=yes \n " ;
485 # Add post user includes to config file
486 # After the GUI-connections allows to patch connections.
487 if (- e
"/etc/ipsec.user-post.conf" ) {
488 print CONF
"include /etc/ipsec.user-post.conf \n " ;
492 print SECRETS
$last_secrets if ( $last_secrets );
497 # Hook to regenerate the configuration files.
498 if ( $ENV { "REMOTE_ADDR" } eq "" ) {
504 ### Save main settings
506 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
507 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
509 if ( $cgiparams { 'RW_NET' } ne '' and !& General
:: validipandmask
( $cgiparams { 'RW_NET' }) ) {
510 $errormessage = $Lang :: tr
{ 'urlfilter invalid ip or mask error' };
514 $vpnsettings { 'ENABLED' } = $cgiparams { 'ENABLED' };
515 $vpnsettings { 'RW_NET' } = $cgiparams { 'RW_NET' };
516 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
519 system ( '/usr/local/bin/ipsecctrl' , 'S' );
521 system ( '/usr/local/bin/ipsecctrl' , 'D' );
528 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
529 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
531 foreach my $key ( keys %confighash ) {
532 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
533 delete $confighash { $key };
536 while ( my $file = glob ( "${General::swroot}/{ca,certs,crls,private}/*" )) {
540 if ( open ( FILE
, ">${General::swroot}/vpn/caconfig" )) {
544 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
546 system ( '/usr/local/bin/ipsecctrl' , 'R' );
552 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' }) {
553 & Header
:: showhttpheaders
();
554 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
555 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
556 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
558 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
562 <input type='hidden' name='AREUSURE' value='yes' />
563 <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'}
567 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' />
568 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
575 & Header
:: closebigbox
();
576 & Header
:: closepage
();
580 ### Upload CA Certificate
582 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
583 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
585 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
586 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
590 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
591 $errormessage = $Lang :: tr
{ 'name too long' };
595 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
596 $errormessage = $Lang :: tr
{ 'name is invalid' };
597 goto UPLOAD_CA_ERROR
;
600 # Check if there is no other entry with this name
601 foreach my $key ( keys %cahash ) {
602 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
603 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
608 unless ( ref ( $cgiparams { 'FH' })) {
609 $errormessage = $Lang :: tr
{ 'there was no file upload' };
612 # Move uploaded ca to a temporary file
613 ( my $fh , my $filename ) = tempfile
( );
614 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
618 my $temp = `/usr/bin/openssl x509 -text -in $filename ` ;
619 if ( $temp !~ /CA:TRUE/i ) {
620 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
624 move
( $filename , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
626 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
632 my $key = & General
:: findhasharraykey
( \
%cahash );
633 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
634 $cahash { $key }[ 1 ] = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" ));
635 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
637 system ( '/usr/local/bin/ipsecctrl' , 'R' );
643 ### Display ca certificate
645 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
646 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
648 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
649 & Header
:: showhttpheaders
();
650 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
651 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
652 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'ca certificate'}:" );
653 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
654 $output = & Header
:: cleanhtml
( $output , "y" );
655 print "<pre> $output </pre> \n " ;
657 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
658 & Header
:: closebigbox
();
659 & Header
:: closepage
();
662 $errormessage = $Lang :: tr
{ 'invalid key' };
666 ### Export ca certificate to browser
668 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
669 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
671 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
672 print "Content-Type: application/force-download \n " ;
673 print "Content-Type: application/octet-stream \r\n " ;
674 print "Content-Disposition: attachment; filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
675 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
678 $errormessage = $Lang :: tr
{ 'invalid key' };
682 ### Remove ca certificate (step 2)
684 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
685 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
686 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
688 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
689 foreach my $key ( keys %confighash ) {
690 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
691 if ( $test =~ /: OK/ ) {
693 unlink ( "${General::swroot}/certs/ $confighash { $key }[1]cert.pem" );
694 unlink ( "${General::swroot}/certs/ $confighash { $key }[1].p12" );
695 delete $confighash { $key };
696 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
698 system ( '/usr/local/bin/ipsecctrl' , 'D' , $key ) if (& vpnenabled
);
701 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
702 delete $cahash { $cgiparams { 'KEY' }};
703 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
704 system ( '/usr/local/bin/ipsecctrl' , 'R' );
707 $errormessage = $Lang :: tr
{ 'invalid key' };
710 ### Remove ca certificate (step 1)
712 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
713 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
714 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
716 my $assignedcerts = 0 ;
717 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
718 foreach my $key ( keys %confighash ) {
719 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
720 if ( $test =~ /: OK/ ) {
724 if ( $assignedcerts ) {
725 & Header
:: showhttpheaders
();
726 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
727 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
728 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
730 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
734 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
735 <input type='hidden' name='AREUSURE' value='yes' /></td>
738 <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>
741 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
742 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
749 & Header
:: closebigbox
();
750 & Header
:: closepage
();
753 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
754 delete $cahash { $cgiparams { 'KEY' }};
755 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
756 system ( '/usr/local/bin/ipsecctrl' , 'R' );
760 $errormessage = $Lang :: tr
{ 'invalid key' };
764 ### Display root certificate
766 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
767 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
769 & Header
:: showhttpheaders
();
770 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
771 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
772 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
773 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'root certificate'}:" );
774 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/cacert.pem` ;
776 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'host certificate'}:" );
777 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/hostcert.pem` ;
779 $output = & Header
:: cleanhtml
( $output , "y" );
780 print "<pre> $output </pre> \n " ;
782 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
783 & Header
:: closebigbox
();
784 & Header
:: closepage
();
788 ### Export root certificate to browser
790 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
791 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
792 print "Content-Type: application/force-download \n " ;
793 print "Content-Disposition: attachment; filename=cacert.pem \r\n\r\n " ;
794 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/cacert.pem` ;
798 ### Export host certificate to browser
800 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
801 if ( - f
"${General::swroot}/certs/hostcert.pem" ) {
802 print "Content-Type: application/force-download \n " ;
803 print "Content-Disposition: attachment; filename=hostcert.pem \r\n\r\n " ;
804 print `/usr/bin/openssl x509 -in ${General::swroot}/certs/hostcert.pem` ;
808 ### Form for generating/importing the caroot+host certificate
810 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
811 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
813 if (- f
"${General::swroot}/ca/cacert.pem" ) {
814 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
818 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
819 # fill in initial values
820 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
821 if (- e
"${General::swroot}/red/active" && open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
822 my $ipaddr = < IPADDR
>;
825 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
826 $cgiparams { 'SUBJECTALTNAME' } = "DNS:" . $cgiparams { 'ROOTCERT_HOSTNAME' };
827 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
828 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
829 $cgiparams { 'SUBJECTALTNAME' } = "IP:" . $cgiparams { 'ROOTCERT_HOSTNAME' };
832 $cgiparams { 'ROOTCERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' } if (! $cgiparams { 'ROOTCERT_COUNTRY' });
833 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
834 & General
:: log ( "ipsec" , "Importing from p12..." );
836 unless ( ref ( $cgiparams { 'FH' })) {
837 $errormessage = $Lang :: tr
{ 'there was no file upload' };
841 # Move uploaded certificate request to a temporary file
842 ( my $fh , my $filename ) = tempfile
( );
843 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
848 # Extract the CA certificate from the file
849 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
850 if ( open ( STDIN
, "-|" )) {
851 my $opt = " pkcs12 -cacerts -nokeys" ;
852 $opt .= " -in $filename " ;
853 $opt .= " -out /tmp/newcacert" ;
854 $errormessage = & callssl
( $opt );
856 print " $cgiparams {'P12_PASS'} \n " ;
860 # Extract the Host certificate from the file
861 if (! $errormessage ) {
862 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
863 if ( open ( STDIN
, "-|" )) {
864 my $opt = " pkcs12 -clcerts -nokeys" ;
865 $opt .= " -in $filename " ;
866 $opt .= " -out /tmp/newhostcert" ;
867 $errormessage = & callssl
( $opt );
869 print " $cgiparams {'P12_PASS'} \n " ;
874 # Extract the Host key from the file
875 if (! $errormessage ) {
876 & General
:: log ( "ipsec" , "Extracting private key from p12..." );
877 if ( open ( STDIN
, "-|" )) {
878 my $opt = " pkcs12 -nocerts -nodes" ;
879 $opt .= " -in $filename " ;
880 $opt .= " -out /tmp/newhostkey" ;
881 $errormessage = & callssl
( $opt );
883 print " $cgiparams {'P12_PASS'} \n " ;
888 if (! $errormessage ) {
889 & General
:: log ( "ipsec" , "Moving cacert..." );
890 move
( "/tmp/newcacert" , "${General::swroot}/ca/cacert.pem" );
891 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
894 if (! $errormessage ) {
895 & General
:: log ( "ipsec" , "Moving host cert..." );
896 move
( "/tmp/newhostcert" , "${General::swroot}/certs/hostcert.pem" );
897 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
900 if (! $errormessage ) {
901 & General
:: log ( "ipsec" , "Moving private key..." );
902 move
( "/tmp/newhostkey" , "${General::swroot}/certs/hostkey.pem" );
903 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
908 unlink ( '/tmp/newcacert' );
909 unlink ( '/tmp/newhostcert' );
910 unlink ( '/tmp/newhostkey' );
912 unlink ( "${General::swroot}/ca/cacert.pem" );
913 unlink ( "${General::swroot}/certs/hostcert.pem" );
914 unlink ( "${General::swroot}/certs/hostkey.pem" );
918 # Create empty CRL cannot be done because we don't have
919 # the private key for this CAROOT
920 # IPFire can only import certificates
922 & General
:: log ( "ipsec" , "p12 import completed!" );
924 goto ROOTCERT_SUCCESS
;
926 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
928 # Validate input since the form was submitted
929 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
930 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
933 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
934 $errormessage = $Lang :: tr
{ 'organization too long' };
937 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
938 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
941 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
942 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
945 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
946 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
949 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
950 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
953 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
954 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
957 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
958 $errormessage = $Lang :: tr
{ 'invalid input for department' };
961 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
962 $errormessage = $Lang :: tr
{ 'invalid input for city' };
965 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
966 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
969 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
970 $errormessage = $Lang :: tr
{ 'invalid input for country' };
973 #the exact syntax is a list comma separated of
974 # email:any-validemail
975 # URI: a uniform resource indicator
976 # DNS: a DNS domain name
977 # RID: a registered OBJECT IDENTIFIER
979 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
981 if ( $cgiparams { 'SUBJECTALTNAME' } eq '' ) {
982 $errormessage = $Lang :: tr
{ 'vpn subjectaltname missing' };
986 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
987 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
991 # Copy the cgisettings to vpnsettings and save the configfile
992 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
993 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
994 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
995 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
996 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
997 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
998 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
999 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1001 # Replace empty strings with a .
1002 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
1003 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
1004 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
1006 # Create the CA certificate
1007 if (! $errormessage ) {
1008 & General
:: log ( "ipsec" , "Creating cacert..." );
1009 if ( open ( STDIN
, "-|" )) {
1010 my $opt = " req -x509 -sha256 -nodes" ;
1011 $opt .= " -days 3650" ;
1012 $opt .= " -newkey rsa:4096" ;
1013 $opt .= " -keyout ${General::swroot}/private/cakey.pem" ;
1014 $opt .= " -out ${General::swroot}/ca/cacert.pem" ;
1016 $errormessage = & callssl
( $opt );
1018 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1021 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1023 print " $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
1024 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1029 # Create the Host certificate request
1030 if (! $errormessage ) {
1031 & General
:: log ( "ipsec" , "Creating host cert..." );
1032 if ( open ( STDIN
, "-|" )) {
1033 my $opt = " req -sha256 -nodes" ;
1034 $opt .= " -newkey rsa:2048" ;
1035 $opt .= " -keyout ${General::swroot}/certs/hostkey.pem" ;
1036 $opt .= " -out ${General::swroot}/certs/hostreq.pem" ;
1037 $errormessage = & callssl
( $opt );
1039 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1042 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1044 print " $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
1045 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1052 # Sign the host certificate request
1053 if (! $errormessage ) {
1054 & General
:: log ( "ipsec" , "Self signing host cert..." );
1056 #No easy way for specifying the contain of subjectAltName without writing a config file...
1057 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1059 basicConstraints=CA:FALSE
1060 nsComment="OpenSSL Generated Certificate"
1061 subjectKeyIdentifier=hash
1062 authorityKeyIdentifier=keyid,issuer:always
1063 extendedKeyUsage = serverAuth
1066 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1069 my $opt = " ca -md sha256 -days 825" ;
1070 $opt .= " -batch -notext" ;
1071 $opt .= " -in ${General::swroot}/certs/hostreq.pem" ;
1072 $opt .= " -out ${General::swroot}/certs/hostcert.pem" ;
1073 $opt .= " -extfile $v3extname " ;
1074 $errormessage = & callssl
( $opt );
1075 unlink ( "${General::swroot}/certs/hostreq.pem" ); #no more needed
1076 unlink ( $v3extname );
1079 # Create an empty CRL
1080 if (! $errormessage ) {
1081 & General
:: log ( "ipsec" , "Creating emptycrl..." );
1082 my $opt = " ca -gencrl" ;
1083 $opt .= " -out ${General::swroot}/crls/cacrl.pem" ;
1084 $errormessage = & callssl
( $opt );
1087 # Successfully build CA / CERT!
1088 if (! $errormessage ) {
1089 & cleanssldatabase
();
1090 goto ROOTCERT_SUCCESS
;
1094 unlink ( "${General::swroot}/ca/cacert.pem" );
1095 unlink ( "${General::swroot}/certs/hostkey.pem" );
1096 unlink ( "${General::swroot}/certs/hostcert.pem" );
1097 unlink ( "${General::swroot}/crls/cacrl.pem" );
1098 & cleanssldatabase
();
1102 & Header
:: showhttpheaders
();
1103 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1104 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1105 if ( $errormessage ) {
1106 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1107 print "<class name='base'> $errormessage " ;
1108 print " </class>" ;
1109 & Header
:: closebox
();
1111 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
1113 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
1114 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1115 <tr><td width='40%' class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
1116 <td width='60%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td></tr>
1117 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}: <img src='/blob.gif' alt='*' /></td>
1118 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td></tr>
1119 <tr><td class='base'> $Lang ::tr{'your e-mail'}:</td>
1120 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td></tr>
1121 <tr><td class='base'> $Lang ::tr{'your department'}:</td>
1122 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td></tr>
1123 <tr><td class='base'> $Lang ::tr{'city'}:</td>
1124 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td></tr>
1125 <tr><td class='base'> $Lang ::tr{'state or province'}:</td>
1126 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td></tr>
1127 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1128 <td class='base'><select name='ROOTCERT_COUNTRY'>
1131 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1132 print "<option value=' $Countries ::countries{ $country }'" ;
1133 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1134 print " selected='selected'" ;
1136 print "> $country </option>" ;
1140 <tr><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*) <img src='/blob.gif' alt='*' /></td>
1141 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' /></td></tr>
1143 <td><br /><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /><br /><br /></td></tr>
1144 <tr><td class='base' colspan='2' align='left'>
1145 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1146 $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'}
1148 <tr><td colspan='2'><hr></td></tr>
1149 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}:</td>
1150 <td nowrap='nowrap'><input type='file' name='FH' size='32' /></td></tr>
1151 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
1152 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td></tr>
1154 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td></tr>
1155 <tr><td class='base' colspan='2' align='left'>
1156 <img src='/blob.gif' alt='*' /> $Lang ::tr{'required field'}</td></tr>
1160 & Header
:: closebox
();
1161 & Header
:: closebigbox
();
1162 & Header
:: closepage
();
1167 system ( '/usr/local/bin/ipsecctrl' , 'S' );
1172 ### Export PKCS12 file to browser
1174 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
1175 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1176 print "Content-Type: application/force-download \n " ;
1177 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
1178 print "Content-Type: application/octet-stream \r\n\r\n " ;
1179 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12` ;
1182 # Export Apple profile to browser
1183 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download apple profile' }) {
1184 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1185 my $key = $cgiparams { 'KEY' };
1187 my $uuid1 = "AAAABBBB" ;
1188 my $uuid2 = "CCCCDDDD" ;
1191 my $cert_uuid = "123456789" ;
1193 # Read and encode certificate
1194 if ( $confighash { $key }[ 4 ] eq "cert" ) {
1195 my $cert_path = "${General::swroot}/certs/ $confighash { $key }[1].p12" ;
1197 # Read certificate and encode it into Base64
1198 open ( CERT
, "<${cert_path}" );
1199 local ($/) = undef ; # slurp
1200 $cert = MIME
:: Base64
:: encode_base64
(< CERT
>);
1204 print "Content-Type: application/octet-stream \n " ;
1205 print "Content-Disposition: attachment; filename=" . $confighash { $key }[ 1 ] . ".mobileconfig \n " ;
1206 print " \n " ; # end headers
1208 print "<!DOCTYPE plist PUBLIC \" -//Apple//DTD PLIST 1.0//EN \" \" http://www.apple.com/DTDs/PropertyList-1.0.dtd \" > \n " ;
1209 print "<plist version= \" 1.0 \" > \n " ;
1211 print " <key>PayloadDisplayName</key> \n " ;
1212 print " <string> $confighash { $key }[1]</string> \n " ;
1213 print " <key>PayloadIdentifier</key> \n " ;
1214 print " <string> $confighash { $key }[1]</string> \n " ;
1215 print " <key>PayloadUUID</key> \n " ;
1216 print " <string>${uuid1}</string> \n " ;
1217 print " <key>PayloadType</key> \n " ;
1218 print " <string>Configuration</string> \n " ;
1219 print " <key>PayloadVersion</key> \n " ;
1220 print " <integer>1</integer> \n " ;
1221 print " <key>PayloadContent</key> \n " ;
1224 print " <key>PayloadIdentifier</key> \n " ;
1225 print " <string>org.example.vpn1.conf1</string> \n " ;
1226 print " <key>PayloadUUID</key> \n " ;
1227 print " <string>${uuid2}</string> \n " ;
1228 print " <key>PayloadType</key> \n " ;
1229 print " <string>com.apple.vpn.managed</string> \n " ;
1230 print " <key>PayloadVersion</key> \n " ;
1231 print " <integer>1</integer> \n " ;
1232 print " <key>UserDefinedName</key> \n " ;
1233 print " <string> $confighash { $key }[1]</string> \n " ;
1234 print " <key>VPNType</key> \n " ;
1235 print " <string>IKEv2</string> \n " ;
1236 print " <key>IKEv2</key> \n " ;
1238 print " <key>RemoteAddress</key> \n " ;
1239 print " <string>18.206.152.26</string> \n " ;
1242 if ( $confighash { $key }[ 9 ]) {
1243 print " <key>LocalIdentifier</key> \n " ;
1244 print " <string> $confighash { $key }[9]</string> \n " ;
1248 if ( $confighash { $key }[ 7 ]) {
1249 print " <key>RemoteIdentifier</key> \n " ;
1250 print " <string> $confighash { $key }[7]</string> \n " ;
1253 if ( $confighash { $key }[ 4 ] eq "cert" ) {
1254 print " <key>AuthenticationMethod</key> \n " ;
1255 print " <string>Certificate</string> \n " ;
1257 print " <key>PayloadCertificateUUID</key> \n " ;
1258 print " <string>${cert_uuid}</string> \n " ;
1260 print " <key>AuthenticationMethod</key> \n " ;
1261 print " <string>SharedSecret</string> \n " ;
1262 print " <key>SharedSecret</key> \n " ;
1263 print " <string> $confighash { $key }[5]</string> \n " ;
1266 print " <key>ExtendedAuthEnabled</key> \n " ;
1267 print " <integer>0</integer> \n " ;
1271 if ( $confighash { $key }[ 4 ] eq "cert" ) {
1273 print " <key>PayloadIdentifier</key> \n " ;
1274 print " <string>org.example.vpn1.client</string> \n " ;
1275 print " <key>PayloadUUID</key> \n " ;
1276 print " <string>${cert_uuid}</string> \n " ;
1277 print " <key>PayloadType</key> \n " ;
1278 print " <string>com.apple.security.pkcs12</string> \n " ;
1279 print " <key>PayloadVersion</key> \n " ;
1280 print " <integer>1</integer> \n " ;
1281 print " <key>PayloadContent</key> \n " ;
1284 foreach ( split /\n/ ,${ cert
}) {
1292 print " </array> \n " ;
1299 ### Display certificate
1301 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
1302 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1304 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1305 & Header
:: showhttpheaders
();
1306 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1307 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1308 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'cert'}:" );
1309 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1310 $output = & Header
:: cleanhtml
( $output , "y" );
1311 print "<pre> $output </pre> \n " ;
1312 & Header
:: closebox
();
1313 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1314 & Header
:: closebigbox
();
1315 & Header
:: closepage
();
1320 ### Export Certificate to browser
1322 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
1323 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1325 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1326 print "Content-Type: application/force-download \n " ;
1327 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \n\n " ;
1328 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1333 ### Enable/Disable connection
1335 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1337 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1338 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1340 if ( $confighash { $cgiparams { 'KEY' }}) {
1341 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
1342 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
1343 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1345 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1347 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
1348 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1350 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1354 $errormessage = $Lang :: tr
{ 'invalid key' };
1358 ### Restart connection
1360 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
1361 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1362 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1364 if ( $confighash { $cgiparams { 'KEY' }}) {
1366 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
1370 $errormessage = $Lang :: tr
{ 'invalid key' };
1374 ### Remove connection
1376 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
1377 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1378 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1380 if ( $confighash { $cgiparams { 'KEY' }}) {
1381 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1382 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1383 delete $confighash { $cgiparams { 'KEY' }};
1384 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1386 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1388 $errormessage = $Lang :: tr
{ 'invalid key' };
1390 & General
:: firewall_reload
();
1392 ### Choose between adding a host-net or net-net connection
1394 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
1395 & Header
:: showhttpheaders
();
1396 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1397 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1398 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection type' });
1400 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
1401 <b> $Lang ::tr{'connection type'}:</b><br />
1403 <tr><td><input type='radio' name='TYPE' value='host' checked='checked' /></td>
1404 <td class='base'> $Lang ::tr{'host to net vpn'}</td>
1406 <td><input type='radio' name='TYPE' value='net' /></td>
1407 <td class='base'> $Lang ::tr{'net to net vpn'}</td>
1409 <td align='center' colspan='2'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td>
1414 & Header
:: closebox
();
1415 & Header
:: closebigbox
();
1416 & Header
:: closepage
();
1419 ### Adding/Editing/Saving a connection
1421 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
1422 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
1423 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
1425 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1426 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1427 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1429 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
1430 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
1431 $errormessage = $Lang :: tr
{ 'invalid key' };
1434 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
1435 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
1436 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
1437 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
1438 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
1439 $cgiparams { 'LOCAL' } = $confighash { $cgiparams { 'KEY' }}[ 6 ];
1440 $cgiparams { 'LOCAL_ID' } = $confighash { $cgiparams { 'KEY' }}[ 7 ];
1441 my @local_subnets = split ( "," , $confighash { $cgiparams { 'KEY' }}[ 8 ]);
1442 $cgiparams { 'LOCAL_SUBNET' } = join ( /\|/ , @local_subnets );
1443 $cgiparams { 'REMOTE_ID' } = $confighash { $cgiparams { 'KEY' }}[ 9 ];
1444 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
1445 my @remote_subnets = split ( "," , $confighash { $cgiparams { 'KEY' }}[ 11 ]);
1446 $cgiparams { 'REMOTE_SUBNET' } = join ( /\|/ , @remote_subnets );
1447 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
1448 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
1449 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
1450 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
1451 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
1452 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
1453 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
1454 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
1455 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
1456 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
1457 if ( $cgiparams { 'ESP_GROUPTYPE' } eq "" ) {
1458 $cgiparams { 'ESP_GROUPTYPE' } = $cgiparams { 'IKE_GROUPTYPE' };
1460 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
1461 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
1462 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
1463 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
1464 $cgiparams { 'DPD_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
1465 $cgiparams { 'DPD_DELAY' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
1466 $cgiparams { 'FORCE_MOBIKE' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
1467 $cgiparams { 'START_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 33 ];
1468 $cgiparams { 'INACTIVITY_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 34 ];
1469 $cgiparams { 'MODE' } = $confighash { $cgiparams { 'KEY' }}[ 35 ];
1470 $cgiparams { 'INTERFACE_MODE' } = $confighash { $cgiparams { 'KEY' }}[ 36 ];
1471 $cgiparams { 'INTERFACE_ADDRESS' } = $confighash { $cgiparams { 'KEY' }}[ 37 ];
1472 $cgiparams { 'INTERFACE_MTU' } = $confighash { $cgiparams { 'KEY' }}[ 38 ];
1474 if (! $cgiparams { 'DPD_DELAY' }) {
1475 $cgiparams { 'DPD_DELAY' } = 30 ;
1478 if (! $cgiparams { 'DPD_TIMEOUT' }) {
1479 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
1482 if ( $cgiparams { 'INACTIVITY_TIMEOUT' } eq "" ) {
1483 $cgiparams { 'INACTIVITY_TIMEOUT' } = 900 ;
1486 if ( $cgiparams { 'MODE' } eq "" ) {
1487 $cgiparams { 'MODE' } = "tunnel" ;
1490 if ( $cgiparams { 'INTERFACE_MTU' } eq "" ) {
1491 $cgiparams { 'INTERFACE_MTU' } = 1500 ;
1494 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
1495 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
1496 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
1497 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
1501 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
1502 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
1506 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
1507 $errormessage = $Lang :: tr
{ 'name is invalid' };
1511 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
1512 $errormessage = $Lang :: tr
{ 'name too long' };
1516 # Check if there is no other entry with this name
1517 if (! $cgiparams { 'KEY' }) { #only for add
1518 foreach my $key ( keys %confighash ) {
1519 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
1520 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
1526 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! $cgiparams { 'REMOTE' })) {
1527 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1531 if ( $cgiparams { 'LOCAL' }) {
1532 if (( $cgiparams { 'LOCAL' } ne "" ) && (!& General
:: validip
( $cgiparams { 'LOCAL' }))) {
1533 $errormessage = $Lang :: tr
{ 'invalid input for local ip address' };
1538 if ( $cgiparams { 'REMOTE' }) {
1539 if (( $cgiparams { 'REMOTE' } ne ' %any ' ) && (! & General
:: validip
( $cgiparams { 'REMOTE' }))) {
1540 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
1541 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1544 if (& valid_dns_host
( $cgiparams { 'REMOTE' })) {
1545 $warnmessage = " $Lang ::tr{'check vpn lr'} $cgiparams {'REMOTE'}. $Lang ::tr{'dns check failed'}" ;
1551 my @local_subnets = split ( "," , $cgiparams { 'LOCAL_SUBNET' });
1552 foreach my $subnet ( @local_subnets ) {
1553 unless (& Network
:: check_subnet
( $subnet )) {
1554 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
1559 # Allow only one roadwarrior/psk without remote IP-address
1560 if ( $cgiparams { 'REMOTE' } eq '' && $cgiparams { 'AUTH' } eq 'psk' ) {
1561 foreach my $key ( keys %confighash ) {
1562 if ( ( $cgiparams { 'KEY' } ne $key ) &&
1563 ( $confighash { $key }[ 4 ] eq 'psk' ) &&
1564 ( $confighash { $key }[ 10 ] eq '' ) ) {
1565 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
1571 if ( $cgiparams { 'TYPE' } eq 'net' ) {
1572 my @remote_subnets = split ( "," , $cgiparams { 'REMOTE_SUBNET' });
1573 foreach my $subnet ( @remote_subnets ) {
1574 unless (& Network
:: check_subnet
( $subnet )) {
1575 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
1580 if ( $cgiparams { 'MODE' } !~ /^(tunnel|transport)$/ ) {
1581 $errormessage = $Lang :: tr
{ 'invalid input for mode' };
1585 if ( $cgiparams { 'INTERFACE_MODE' } !~ /^(|gre|vti)$/ ) {
1586 $errormessage = $Lang :: tr
{ 'invalid input for interface mode' };
1590 if (( $cgiparams { 'INTERFACE_MODE' } eq "vti" ) && ( $cgiparams { 'MODE' } eq "transport" )) {
1591 $errormessage = $Lang :: tr
{ 'transport mode does not support vti' };
1595 if (( $cgiparams { 'INTERFACE_MODE' } ne "" ) && !& Network
:: check_subnet
( $cgiparams { 'INTERFACE_ADDRESS' })) {
1596 $errormessage = $Lang :: tr
{ 'invalid input for interface address' };
1600 if ( $cgiparams { 'INTERFACE_MTU' } !~ /^\d+$/ ) {
1601 $errormessage = $Lang :: tr
{ 'invalid input for interface mtu' };
1606 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
1607 $errormessage = $Lang :: tr
{ 'invalid input' };
1610 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
1611 $errormessage = $Lang :: tr
{ 'invalid input' };
1615 # Allow nothing or a string (DN,FDQN,) beginning with @
1616 # with no comma but slashes between RID eg @O=FR/C=Paris/OU=myhome/CN=franck
1617 if ( ( $cgiparams { 'LOCAL_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1618 ( $cgiparams { 'REMOTE_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1619 (( $cgiparams { 'REMOTE_ID' } eq $cgiparams { 'LOCAL_ID' }) && ( $cgiparams { 'LOCAL_ID' } ne '' ))
1621 $errormessage = $Lang :: tr
{ 'invalid local-remote id' } . '<br />' .
1622 'DER_ASN1_DN: @c =FR/ou=Paris/ou=Home/cn=*<br />' .
1623 'FQDN: @ipfire .org<br />' .
1624 'USER_FQDN: info @ipfire .org<br />' .
1625 'IPV4_ADDR: 123.123.123.123' ;
1628 # If Auth is DN, verify existance of Remote ID.
1629 if ( $cgiparams { 'REMOTE_ID' } eq '' && (
1630 $cgiparams { 'AUTH' } eq 'auth-dn' || # while creation
1631 $confighash { $cgiparams { 'KEY' }}[ 2 ] eq ' %auth -dn' )){ # while editing
1632 $errormessage = $Lang :: tr
{ 'vpn missing remote id' };
1636 if ( $cgiparams { 'TYPE' } eq 'net' ){
1637 $warnmessage =& General
:: checksubnets
( '' , $cgiparams { 'REMOTE_SUBNET' }, 'ipsec' );
1638 if ( $warnmessage ne '' ){
1639 $warnmessage = $Lang :: tr
{ 'remote subnet' }. " ( $cgiparams {'REMOTE_SUBNET'}) <br>" . $warnmessage ;
1643 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1644 if (! length ( $cgiparams { 'PSK' }) ) {
1645 $errormessage = $Lang :: tr
{ 'pre-shared key is too short' };
1648 if ( $cgiparams { 'PSK' } =~ /'/ ) {
1649 $cgiparams { 'PSK' } =~ tr/'/ / ;
1650 $errormessage = $Lang :: tr
{ 'invalid characters found in pre-shared key' };
1653 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
1654 if ( $cgiparams { 'KEY' }) {
1655 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1658 unless ( ref ( $cgiparams { 'FH' })) {
1659 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1663 # Move uploaded certificate request to a temporary file
1664 ( my $fh , my $filename ) = tempfile
( );
1665 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1670 # Sign the certificate request
1671 & General
:: log ( "ipsec" , "Signing your cert $cgiparams {'NAME'}..." );
1672 my $opt = " ca -md sha256 -days 825" ;
1673 $opt .= " -batch -notext" ;
1674 $opt .= " -in $filename " ;
1675 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1677 if ( $errormessage = & callssl
( $opt ) ) {
1679 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1680 & cleanssldatabase
();
1684 & cleanssldatabase
();
1687 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1688 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1689 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1692 } elsif ( $cgiparams { 'AUTH' } eq 'pkcs12' ) {
1693 & General
:: log ( "ipsec" , "Importing from p12..." );
1695 unless ( ref ( $cgiparams { 'FH' })) {
1696 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1697 goto ROOTCERT_ERROR
;
1700 # Move uploaded certificate request to a temporary file
1701 ( my $fh , my $filename ) = tempfile
( );
1702 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1704 goto ROOTCERT_ERROR
;
1707 # Extract the CA certificate from the file
1708 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
1709 if ( open ( STDIN
, "-|" )) {
1710 my $opt = " pkcs12 -cacerts -nokeys" ;
1711 $opt .= " -in $filename " ;
1712 $opt .= " -out /tmp/newcacert" ;
1713 $errormessage = & callssl
( $opt );
1715 print " $cgiparams {'P12_PASS'} \n " ;
1719 # Extract the Host certificate from the file
1720 if (! $errormessage ) {
1721 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
1722 if ( open ( STDIN
, "-|" )) {
1723 my $opt = " pkcs12 -clcerts -nokeys" ;
1724 $opt .= " -in $filename " ;
1725 $opt .= " -out /tmp/newhostcert" ;
1726 $errormessage = & callssl
( $opt );
1728 print " $cgiparams {'P12_PASS'} \n " ;
1733 if (! $errormessage ) {
1734 & General
:: log ( "ipsec" , "Moving cacert..." );
1735 #If CA have new subject, add it to our list of CA
1736 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( '/tmp/newcacert' ));
1738 foreach my $x ( keys %cahash ) {
1739 $casubject = '' if ( $cahash { $x }[ 1 ] eq $casubject );
1740 unshift ( @names , $cahash { $x }[ 0 ]);
1742 if ( $casubject ) { # a new one!
1743 my $temp = `/usr/bin/openssl x509 -text -in /tmp/newcacert` ;
1744 if ( $temp !~ /CA:TRUE/i ) {
1745 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
1747 #compute a name for it
1749 while ( grep ( /Imported-$idx/ , @names ) ) { $idx ++};
1750 $cgiparams { 'CA_NAME' }= "Imported- $idx " ;
1751 $cgiparams { 'CERT_NAME' }=& Header
:: cleanhtml
( getCNfromcert
( '/tmp/newhostcert' ));
1752 move
( "/tmp/newcacert" , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1753 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1754 if (! $errormessage ) {
1755 my $key = & General
:: findhasharraykey
( \
%cahash );
1756 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
1757 $cahash { $key }[ 1 ] = $casubject ;
1758 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1759 system ( '/usr/local/bin/ipsecctrl' , 'R' );
1764 if (! $errormessage ) {
1765 & General
:: log ( "ipsec" , "Moving host cert..." );
1766 move
( "/tmp/newhostcert" , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1767 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1772 unlink ( '/tmp/newcacert' );
1773 unlink ( '/tmp/newhostcert' );
1774 if ( $errormessage ) {
1775 unlink ( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1776 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1779 & General
:: log ( "ipsec" , "p12 import completed!" );
1780 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
1781 if ( $cgiparams { 'KEY' }) {
1782 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1785 unless ( ref ( $cgiparams { 'FH' })) {
1786 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1789 # Move uploaded certificate to a temporary file
1790 ( my $fh , my $filename ) = tempfile
( );
1791 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1796 # Verify the certificate has a valid CA and move it
1797 & General
:: log ( "ipsec" , "Validating imported cert against our known CA..." );
1798 my $validca = 1 ; #assume ok
1799 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/cacert.pem $filename ` ;
1800 if ( $test !~ /: OK/ ) {
1802 foreach my $key ( keys %cahash ) {
1803 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $key }[0]cert.pem $filename ` ;
1804 if ( $test =~ /: OK/ ) {
1811 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
1815 move
( $filename , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1817 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1823 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1824 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1825 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1826 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1829 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
1830 if ( $cgiparams { 'KEY' }) {
1831 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1834 # Validate input since the form was submitted
1835 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
1836 $errormessage = $Lang :: tr
{ 'name too long' };
1839 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1840 $errormessage = $Lang :: tr
{ 'invalid input for name' };
1843 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
1844 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1847 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
1848 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1851 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1852 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1855 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
1856 $errormessage = $Lang :: tr
{ 'organization too long' };
1859 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1860 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1863 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1864 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1867 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1868 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1871 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1872 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1875 #the exact syntax is a list comma separated of
1876 # email:any-validemail
1877 # URI: a uniform resource indicator
1878 # DNS: a DNS domain name
1879 # RID: a registered OBJECT IDENTIFIER
1881 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
1883 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
1884 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
1888 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
1889 $errormessage = $Lang :: tr
{ 'password too short' };
1892 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
1893 $errormessage = $Lang :: tr
{ 'passwords do not match' };
1897 # Replace empty strings with a .
1898 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
1899 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
1900 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
1902 # Create the Client certificate request
1903 & General
:: log ( "ipsec" , "Creating a cert..." );
1905 if ( open ( STDIN
, "-|" )) {
1906 my $opt = " req -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
1907 $opt .= " -newkey rsa:2048" ;
1908 $opt .= " -keyout ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1909 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1911 if ( $errormessage = & callssl
( $opt ) ) {
1912 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1913 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1917 print " $cgiparams {'CERT_COUNTRY'} \n " ;
1920 print " $cgiparams {'CERT_ORGANIZATION'} \n " ;
1922 print " $cgiparams {'CERT_NAME'} \n " ;
1923 print " $cgiparams {'CERT_EMAIL'} \n " ;
1929 # Sign the client certificate request
1930 & General
:: log ( "ipsec" , "Signing the cert $cgiparams {'NAME'}..." );
1932 #No easy way for specifying the contain of subjectAltName without writing a config file...
1933 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1935 basicConstraints=CA:FALSE
1936 nsComment="OpenSSL Generated Certificate"
1937 subjectKeyIdentifier=hash
1938 extendedKeyUsage=clientAuth
1939 authorityKeyIdentifier=keyid,issuer:always
1942 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1945 my $opt = " ca -md sha256 -days 825 -batch -notext" ;
1946 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1947 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1948 $opt .= " -extfile $v3extname " ;
1950 if ( $errormessage = & callssl
( $opt ) ) {
1951 unlink ( $v3extname );
1952 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1953 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1954 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1955 & cleanssldatabase
();
1958 unlink ( $v3extname );
1959 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1960 & cleanssldatabase
();
1963 # Create the pkcs12 file
1964 & General
:: log ( "ipsec" , "Packing a pkcs12 file..." );
1965 $opt = " pkcs12 -export" ;
1966 $opt .= " -inkey ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1967 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1968 $opt .= " -name \" $cgiparams {'NAME'} \" " ;
1969 $opt .= " -passout pass: $cgiparams {'CERT_PASS1'}" ;
1970 $opt .= " -certfile ${General::swroot}/ca/cacert.pem" ;
1971 $opt .= " -caname \" $vpnsettings {'ROOTCERT_ORGANIZATION'} CA \" " ;
1972 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}.p12" ;
1974 if ( $errormessage = & callssl
( $opt ) ) {
1975 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1976 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1977 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}.p12" );
1980 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1982 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
1983 ; # Nothing, just editing
1984 } elsif ( $cgiparams { 'AUTH' } eq 'auth-dn' ) {
1985 $cgiparams { 'CERT_NAME' } = ' %auth -dn' ; # a special value saying 'no cert file'
1987 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
1991 # 1)Error message here is not accurate.
1992 # 2)Test is superfluous, openswan can reference same cert multiple times
1993 # 3)Present since initial version (1.3.2.11), it isn't a bug correction
1994 # Check if there is no other entry with this certificate name
1995 #if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk') && ($cgiparams{'AUTH'} ne 'auth-dn')) {
1996 # foreach my $key (keys %confighash) {
1997 # if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) {
1998 # $errormessage = $Lang::tr{'a connection with this common name already exists'};
1999 # goto VPNCONF_ERROR;
2005 my $key = $cgiparams { 'KEY' };
2007 $key = & General
:: findhasharraykey
( \
%confighash );
2008 foreach my $i ( 0 .. 38 ) { $confighash { $key }[ $i ] = "" ;}
2010 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
2011 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
2012 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
2013 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
2015 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
2016 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
2017 $confighash { $key }[ 4 ] = 'psk' ;
2018 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
2020 $confighash { $key }[ 4 ] = 'cert' ;
2022 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2023 my @remote_subnets = split ( "," , $cgiparams { 'REMOTE_SUBNET' });
2024 $confighash { $key }[ 11 ] = join ( '|' , @remote_subnets );
2026 $confighash { $key }[ 6 ] = $cgiparams { 'LOCAL' };
2027 $confighash { $key }[ 7 ] = $cgiparams { 'LOCAL_ID' };
2028 my @local_subnets = split ( "," , $cgiparams { 'LOCAL_SUBNET' });
2029 $confighash { $key }[ 8 ] = join ( '|' , @local_subnets );
2030 $confighash { $key }[ 9 ] = $cgiparams { 'REMOTE_ID' };
2031 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
2032 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
2033 $confighash { $key }[ 26 ] = "" ; # Formerly INTERFACE
2034 $confighash { $key }[ 27 ] = $cgiparams { 'DPD_ACTION' };
2035 $confighash { $key }[ 29 ] = $cgiparams { 'IKE_VERSION' };
2037 # don't forget advanced value
2038 $confighash { $key }[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
2039 $confighash { $key }[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
2040 $confighash { $key }[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
2041 $confighash { $key }[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
2042 $confighash { $key }[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
2043 $confighash { $key }[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
2044 $confighash { $key }[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
2045 $confighash { $key }[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
2046 $confighash { $key }[ 12 ] = 'off' ; # $cgiparams{'AGGRMODE'};
2047 $confighash { $key }[ 13 ] = $cgiparams { 'COMPRESSION' };
2048 $confighash { $key }[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
2049 $confighash { $key }[ 28 ] = $cgiparams { 'PFS' };
2050 $confighash { $key }[ 30 ] = $cgiparams { 'DPD_TIMEOUT' };
2051 $confighash { $key }[ 31 ] = $cgiparams { 'DPD_DELAY' };
2052 $confighash { $key }[ 32 ] = $cgiparams { 'FORCE_MOBIKE' };
2053 $confighash { $key }[ 33 ] = $cgiparams { 'START_ACTION' };
2054 $confighash { $key }[ 34 ] = $cgiparams { 'INACTIVITY_TIMEOUT' };
2055 $confighash { $key }[ 35 ] = $cgiparams { 'MODE' };
2056 $confighash { $key }[ 36 ] = $cgiparams { 'INTERFACE_MODE' };
2057 $confighash { $key }[ 37 ] = $cgiparams { 'INTERFACE_ADDRESS' };
2058 $confighash { $key }[ 38 ] = $cgiparams { 'INTERFACE_MTU' };
2060 # free unused fields!
2061 $confighash { $key }[ 15 ] = 'off' ;
2063 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2066 system ( '/usr/local/bin/ipsecctrl' , 'S' , $key );
2069 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
2070 $cgiparams { 'KEY' } = $key ;
2071 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
2074 } else { # add new connection
2075 $cgiparams { 'ENABLED' } = 'on' ;
2076 if ( ! - f
"${General::swroot}/private/cakey.pem" ) {
2077 $cgiparams { 'AUTH' } = 'psk' ;
2078 } elsif ( ! - f
"${General::swroot}/ca/cacert.pem" ) {
2079 $cgiparams { 'AUTH' } = 'certfile' ;
2081 $cgiparams { 'AUTH' } = 'certgen' ;
2084 if ( $netsettings { "GREEN_NETADDRESS" } && $netsettings { "GREEN_NETMASK" }) {
2085 $cgiparams { "LOCAL_SUBNET" } = $netsettings { 'GREEN_NETADDRESS' } . "/" . $netsettings { 'GREEN_NETMASK' };
2087 $cgiparams { "LOCAL_SUBNET" } = "" ;
2089 $cgiparams { 'CERT_EMAIL' } = $vpnsettings { 'ROOTCERT_EMAIL' };
2090 $cgiparams { 'CERT_OU' } = $vpnsettings { 'ROOTCERT_OU' };
2091 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
2092 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
2093 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
2094 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
2096 # choose appropriate dpd action
2097 if ( $cgiparams { 'TYPE' } eq 'host' ) {
2098 $cgiparams { 'DPD_ACTION' } = 'clear' ;
2100 $cgiparams { 'DPD_ACTION' } = 'restart' ;
2103 if (! $cgiparams { 'DPD_DELAY' }) {
2104 $cgiparams { 'DPD_DELAY' } = 30 ;
2107 if (! $cgiparams { 'DPD_TIMEOUT' }) {
2108 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
2111 if (! $cgiparams { 'FORCE_MOBIKE' }) {
2112 $cgiparams { 'FORCE_MOBIKE' } = 'no' ;
2115 # Default IKE Version to v2
2116 if (! $cgiparams { 'IKE_VERSION' }) {
2117 $cgiparams { 'IKE_VERSION' } = 'ikev2' ;
2121 $cgiparams { 'LOCAL_ID' } = '' ;
2122 $cgiparams { 'REMOTE_ID' } = '' ;
2124 #use default advanced value
2125 $cgiparams { 'IKE_ENCRYPTION' } = 'chacha20poly1305|aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128' ; #[18];
2126 $cgiparams { 'IKE_INTEGRITY' } = 'sha2_512|sha2_256' ; #[19];
2127 $cgiparams { 'IKE_GROUPTYPE' } = 'curve25519|curve448|4096|3072|2048' ; #[20];
2128 $cgiparams { 'IKE_LIFETIME' } = '3' ; #[16];
2129 $cgiparams { 'ESP_ENCRYPTION' } = 'chacha20poly1305|aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128' ; #[21];
2130 $cgiparams { 'ESP_INTEGRITY' } = 'sha2_512|sha2_256' ; #[22];
2131 $cgiparams { 'ESP_GROUPTYPE' } = 'curve25519|curve448|4096|3072|2048' ; #[23];
2132 $cgiparams { 'ESP_KEYLIFE' } = '1' ; #[17];
2133 $cgiparams { 'COMPRESSION' } = 'off' ; #[13];
2134 $cgiparams { 'ONLY_PROPOSED' } = 'on' ; #[24];
2135 $cgiparams { 'PFS' } = 'on' ; #[28];
2136 $cgiparams { 'INACTIVITY_TIMEOUT' } = 900 ;
2137 $cgiparams { 'MODE' } = "tunnel" ;
2138 $cgiparams { 'INTERFACE_MODE' } = "" ;
2139 $cgiparams { 'INTERFACE_ADDRESS' } = "" ;
2140 $cgiparams { 'INTERFACE_MTU' } = 1500 ;
2144 $checked { 'ENABLED' }{ 'off' } = '' ;
2145 $checked { 'ENABLED' }{ 'on' } = '' ;
2146 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = "checked='checked'" ;
2148 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
2149 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
2150 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = "checked='checked'" ;
2152 $checked { 'AUTH' }{ 'psk' } = '' ;
2153 $checked { 'AUTH' }{ 'certreq' } = '' ;
2154 $checked { 'AUTH' }{ 'certgen' } = '' ;
2155 $checked { 'AUTH' }{ 'certfile' } = '' ;
2156 $checked { 'AUTH' }{ 'pkcs12' } = '' ;
2157 $checked { 'AUTH' }{ 'auth-dn' } = '' ;
2158 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = "checked='checked'" ;
2160 $selected { 'MODE' }{ 'tunnel' } = '' ;
2161 $selected { 'MODE' }{ 'transport' } = '' ;
2162 $selected { 'MODE' }{ $cgiparams { 'MODE' }} = "selected='selected'" ;
2164 $selected { 'INTERFACE_MODE' }{ '' } = '' ;
2165 $selected { 'INTERFACE_MODE' }{ 'gre' } = '' ;
2166 $selected { 'INTERFACE_MODE' }{ 'vti' } = '' ;
2167 $selected { 'INTERFACE_MODE' }{ $cgiparams { 'INTERFACE_MODE' }} = "selected='selected'" ;
2169 $selected { 'LOCAL' }{ '' } = '' ;
2170 foreach my $alias ( sort keys %aliases ) {
2171 my $address = $aliases { $alias }{ 'IPT' };
2173 $selected { 'LOCAL' }{ $address } = '' ;
2175 $selected { 'LOCAL' }{ $cgiparams { 'LOCAL' }} = "selected='selected'" ;
2177 & Header
:: showhttpheaders
();
2178 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
2179 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2180 if ( $errormessage ) {
2181 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2182 print "<class name='base'> $errormessage " ;
2183 print " </class>" ;
2184 & Header
:: closebox
();
2188 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'warning messages'}:" );
2189 print "<class name='base'> $warnmessage " ;
2190 print " </class>" ;
2191 & Header
:: closebox
();
2194 print "<form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>" ;
2196 <input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />
2197 <input type='hidden' name='IKE_VERSION' value=' $cgiparams {'IKE_VERSION'}' />
2198 <input type='hidden' name='IKE_ENCRYPTION' value=' $cgiparams {'IKE_ENCRYPTION'}' />
2199 <input type='hidden' name='IKE_INTEGRITY' value=' $cgiparams {'IKE_INTEGRITY'}' />
2200 <input type='hidden' name='IKE_GROUPTYPE' value=' $cgiparams {'IKE_GROUPTYPE'}' />
2201 <input type='hidden' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' />
2202 <input type='hidden' name='ESP_ENCRYPTION' value=' $cgiparams {'ESP_ENCRYPTION'}' />
2203 <input type='hidden' name='ESP_INTEGRITY' value=' $cgiparams {'ESP_INTEGRITY'}' />
2204 <input type='hidden' name='ESP_GROUPTYPE' value=' $cgiparams {'ESP_GROUPTYPE'}' />
2205 <input type='hidden' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' />
2206 <input type='hidden' name='COMPRESSION' value=' $cgiparams {'COMPRESSION'}' />
2207 <input type='hidden' name='ONLY_PROPOSED' value=' $cgiparams {'ONLY_PROPOSED'}' />
2208 <input type='hidden' name='PFS' value=' $cgiparams {'PFS'}' />
2209 <input type='hidden' name='DPD_ACTION' value=' $cgiparams {'DPD_ACTION'}' />
2210 <input type='hidden' name='DPD_DELAY' value=' $cgiparams {'DPD_DELAY'}' />
2211 <input type='hidden' name='DPD_TIMEOUT' value=' $cgiparams {'DPD_TIMEOUT'}' />
2212 <input type='hidden' name='FORCE_MOBIKE' value=' $cgiparams {'FORCE_MOBIKE'}' />
2213 <input type='hidden' name='START_ACTION' value=' $cgiparams {'START_ACTION'}' />
2214 <input type='hidden' name='INACTIVITY_TIMEOUT' value=' $cgiparams {'INACTIVITY_TIMEOUT'}' />
2217 if ( $cgiparams { 'KEY' }) {
2218 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
2219 print "<input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' />" ;
2220 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
2223 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'connection'}: $cgiparams {'NAME'}" );
2224 print "<table width='100%'>" ;
2225 if (! $cgiparams { 'KEY' }) {
2228 <td width='20%'> $Lang ::tr{'name'}: <img src='/blob.gif' alt='*' /></td>
2230 <input type='text' name='NAME' value=' $cgiparams {'NAME'}' size='25' />
2232 <td colspan="2"></td>
2239 if ( $cgiparams { 'TYPE' } eq 'host' ) {
2240 $disabled = "disabled='disabled'" ;
2241 } elsif ( $cgiparams { 'TYPE' } eq 'net' ) {
2242 $blob = "<img src='/blob.gif' alt='*' />" ;
2245 my @local_subnets = split ( /\|/ , $cgiparams { 'LOCAL_SUBNET' });
2246 my $local_subnets = join ( "," , @local_subnets );
2248 my @remote_subnets = split ( /\|/ , $cgiparams { 'REMOTE_SUBNET' });
2249 my $remote_subnets = join ( "," , @remote_subnets );
2253 <td width='20%'> $Lang ::tr{'enabled'}</td>
2255 <input type='checkbox' name='ENABLED' $checked {'ENABLED'}{'on'} />
2257 <td colspan="2"></td>
2260 <td class='boldbase' width='20%'> $Lang ::tr{'local ip address'}:</td>
2262 <select name="LOCAL">
2263 <option value="" $selected {'LOCAL'}{''}>- $Lang ::tr{'default IP address'} -</option>
2266 foreach my $alias ( sort keys %aliases ) {
2267 my $address = $aliases { $alias }{ 'IPT' };
2269 <option value=" $address " $selected {'LOCAL'}{ $address }> $alias ( $address )</option>
2276 <td class='boldbase' width='20%'> $Lang ::tr{'remote host/ip'}: $blob </td>
2278 <input type='text' name='REMOTE' value=' $cgiparams {'REMOTE'}' size="25" />
2282 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'local subnet'} <img src='/blob.gif' alt='*' /></td>
2284 <input type='text' name='LOCAL_SUBNET' value=' $local_subnets ' size="25" />
2286 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'remote subnet'} $blob </td>
2288 <input $disabled type='text' name='REMOTE_SUBNET' value=' $remote_subnets ' size="25" />
2292 <td class='boldbase' width='20%'> $Lang ::tr{'vpn local id'}:</td>
2294 <input type='text' name='LOCAL_ID' value=' $cgiparams {'LOCAL_ID'}' size="25" />
2296 <td class='boldbase' width='20%'> $Lang ::tr{'vpn remote id'}:</td>
2298 <input type='text' name='REMOTE_ID' value=' $cgiparams {'REMOTE_ID'}' size="25" />
2301 <tr><td colspan="4"><br /></td></tr>
2303 <td class='boldbase' width='20%'> $Lang ::tr{'remark title'}</td>
2305 <input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' maxlength='50' size="73" />
2310 if (! $cgiparams { 'KEY' }) {
2311 print "<tr><td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked {'EDIT_ADVANCED'}{'on'} /> $Lang ::tr{'edit advanced settings when done'}</td></tr>" ;
2314 & Header
:: closebox
();
2316 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2317 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'ipsec settings' });
2319 <table width='100%'>
2322 <td class='boldbase' width='20%'> $Lang ::tr{'mode'}:</td>
2324 <select name='MODE'>
2325 <option value='tunnel' $selected {'MODE'}{'tunnel'}> $Lang ::tr{'ipsec mode tunnel'}</option>
2326 <option value='transport' $selected {'MODE'}{'transport'}> $Lang ::tr{'ipsec mode transport'}</option>
2329 <td colspan='2'></td>
2333 <td class='boldbase' width='20%'> $Lang ::tr{'interface mode'}:</td>
2335 <select name='INTERFACE_MODE'>
2336 <option value='' $selected {'INTERFACE_MODE'}{''}> $Lang ::tr{'ipsec interface mode none'}</option>
2337 <option value='gre' $selected {'INTERFACE_MODE'}{'gre'}> $Lang ::tr{'ipsec interface mode gre'}</option>
2338 <option value='vti' $selected {'INTERFACE_MODE'}{'vti'}> $Lang ::tr{'ipsec interface mode vti'}</option>
2342 <td class='boldbase' width='20%'> $Lang ::tr{'ip address'}/ $Lang ::tr{'subnet mask'}:</td>
2344 <input type="text" name="INTERFACE_ADDRESS" value=" $cgiparams {'INTERFACE_ADDRESS'}">
2349 <td class='boldbase' width='20%'> $Lang ::tr{'mtu'}:</td>
2351 <input type="number" name="INTERFACE_MTU" value=" $cgiparams {'INTERFACE_MTU'}" min="576" max="9000">
2353 <td colspan='2'></td>
2358 & Header
:: closebox
();
2361 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
2362 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2364 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2365 <tr><td class='base' width='50%'> $Lang ::tr{'use a pre-shared key'}</td>
2366 <td class='base' width='50%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td>
2371 & Header
:: closebox
();
2372 } elsif (! $cgiparams { 'KEY' }) {
2373 my $cakeydisabled = ( ! - f
"${General::swroot}/private/cakey.pem" ) ?
"disabled='disabled'" : '' ;
2374 $cgiparams { 'CERT_NAME' } = $Lang :: tr
{ 'vpn no full pki' } if ( $cakeydisabled );
2375 my $cacrtdisabled = ( ! - f
"${General::swroot}/ca/cacert.pem" ) ?
"disabled='disabled'" : '' ;
2377 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2379 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2380 <tr><td width='5%'><input type='radio' name='AUTH' value='psk' $checked {'AUTH'}{'psk'} /></td>
2381 <td class='base' width='55%'> $Lang ::tr{'use a pre-shared key'}</td>
2382 <td class='base' width='40%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td></tr>
2383 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2384 <tr><td><input type='radio' name='AUTH' value='certreq' $checked {'AUTH'}{'certreq'} $cakeydisabled /></td>
2385 <td class='base'><hr /> $Lang ::tr{'upload a certificate request'}</td>
2386 <td class='base' rowspan='3' valign='middle'><input type='file' name='FH' size='30' $cacrtdisabled /></td></tr>
2387 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td>
2388 <td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
2389 <tr><td><input type='radio' name='AUTH' value='pkcs12' $cacrtdisabled /></td>
2390 <td class='base'> $Lang ::tr{'upload p12 file'} $Lang ::tr{'pkcs12 file password'}:<input type='password' name='P12_PASS'/></td></tr>
2391 <tr><td><input type='radio' name='AUTH' value='auth-dn' $checked {'AUTH'}{'auth-dn'} $cacrtdisabled /></td>
2392 <td class='base'><hr /> $Lang ::tr{'vpn auth-dn'}</td></tr>
2393 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2394 <tr><td><input type='radio' name='AUTH' value='certgen' $checked {'AUTH'}{'certgen'} $cakeydisabled /></td>
2395 <td class='base'><hr /> $Lang ::tr{'generate a certificate'}</td><td> </td></tr>
2397 <td class='base'> $Lang ::tr{'users fullname or system hostname'}: <img src='/blob.gif' alt='*' /></td>
2398 <td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' size='32' $cakeydisabled /></td></tr>
2400 <td class='base'> $Lang ::tr{'users email'}:</td>
2401 <td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' size='32' $cakeydisabled /></td></tr>
2403 <td class='base'> $Lang ::tr{'users department'}:</td>
2404 <td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' size='32' $cakeydisabled /></td></tr>
2406 <td class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
2407 <td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' size='32' $cakeydisabled /></td></tr>
2409 <td class='base'> $Lang ::tr{'city'}:</td>
2410 <td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' size='32' $cakeydisabled /></td></tr>
2412 <td class='base'> $Lang ::tr{'state or province'}:</td>
2413 <td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' size='32' $cakeydisabled /></td></tr>
2415 <td class='base'> $Lang ::tr{'country'}:</td>
2416 <td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
2419 foreach my $country ( sort keys %{ Countries
:: countries
}) {
2420 print " \t\t\t <option value=' $Countries ::countries{ $country }'" ;
2421 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
2422 print " selected='selected'" ;
2424 print "> $country </option> \n " ;
2429 <tr><td> </td><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)</td>
2430 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' $cakeydisabled /></td></tr>
2432 <td class='base'> $Lang ::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' /></td>
2433 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
2434 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'} ( $Lang ::tr{'confirmation'}): <img src='/blob.gif' alt='*' /></td>
2435 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
2439 & Header
:: closebox
();
2442 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
2443 if ( $cgiparams { 'KEY' }) {
2444 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced'}' />" ;
2446 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
2447 & Header
:: closebigbox
();
2448 & Header
:: closepage
();
2455 ### Advanced settings
2457 if (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced' }) ||
2458 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq 'yes' )) {
2459 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
2460 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2461 if (! $confighash { $cgiparams { 'KEY' }}) {
2462 $errormessage = $Lang :: tr
{ 'invalid key' };
2466 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
2467 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2469 $errormessage = $Lang :: tr
{ 'invalid input' };
2470 goto ADVANCED_ERROR
;
2472 foreach my $val ( @temp ) {
2473 if ( $val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|chacha20poly1305|camellia(256|192|128))$/ ) {
2474 $errormessage = $Lang :: tr
{ 'invalid input' };
2475 goto ADVANCED_ERROR
;
2478 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2480 $errormessage = $Lang :: tr
{ 'invalid input' };
2481 goto ADVANCED_ERROR
;
2483 foreach my $val ( @temp ) {
2484 if ( $val !~ /^(sha2_(512|384|256)|sha|md5|aesxcbc)$/ ) {
2485 $errormessage = $Lang :: tr
{ 'invalid input' };
2486 goto ADVANCED_ERROR
;
2489 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2491 $errormessage = $Lang :: tr
{ 'invalid input' };
2492 goto ADVANCED_ERROR
;
2494 foreach my $val ( @temp ) {
2495 if ( $val !~ /^(curve25519|curve448|e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|768|1024|1536|2048|3072|4096|6144|8192)$/ ) {
2496 $errormessage = $Lang :: tr
{ 'invalid input' };
2497 goto ADVANCED_ERROR
;
2500 if ( $cgiparams { 'IKE_LIFETIME' } !~ /^\d+$/ ) {
2501 $errormessage = $Lang :: tr
{ 'invalid input for ike lifetime' };
2502 goto ADVANCED_ERROR
;
2504 if ( $cgiparams { 'IKE_LIFETIME' } < 1 || $cgiparams { 'IKE_LIFETIME' } > 24 ) {
2505 $errormessage = $Lang :: tr
{ 'ike lifetime should be between 1 and 24 hours' };
2506 goto ADVANCED_ERROR
;
2508 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2510 $errormessage = $Lang :: tr
{ 'invalid input' };
2511 goto ADVANCED_ERROR
;
2513 foreach my $val ( @temp ) {
2514 if ( $val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|chacha20poly1305|camellia(256|192|128))$/ ) {
2515 $errormessage = $Lang :: tr
{ 'invalid input' };
2516 goto ADVANCED_ERROR
;
2519 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2521 $errormessage = $Lang :: tr
{ 'invalid input' };
2522 goto ADVANCED_ERROR
;
2524 foreach my $val ( @temp ) {
2525 if ( $val !~ /^(sha2_(512|384|256)|sha1|md5|aesxcbc)$/ ) {
2526 $errormessage = $Lang :: tr
{ 'invalid input' };
2527 goto ADVANCED_ERROR
;
2530 @temp = split ( '\|' , $cgiparams { 'ESP_GROUPTYPE' });
2532 $errormessage = $Lang :: tr
{ 'invalid input' };
2533 goto ADVANCED_ERROR
;
2535 foreach my $val ( @temp ) {
2536 if ( $val !~ /^(curve25519|curve448|e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|768|1024|1536|2048|3072|4096|6144|8192|none)$/ ) {
2537 $errormessage = $Lang :: tr
{ 'invalid input' };
2538 goto ADVANCED_ERROR
;
2541 if ( $cgiparams { 'ESP_KEYLIFE' } !~ /^\d+$/ ) {
2542 $errormessage = $Lang :: tr
{ 'invalid input for esp keylife' };
2543 goto ADVANCED_ERROR
;
2545 if ( $cgiparams { 'ESP_KEYLIFE' } < 1 || $cgiparams { 'ESP_KEYLIFE' } > 24 ) {
2546 $errormessage = $Lang :: tr
{ 'esp keylife should be between 1 and 24 hours' };
2547 goto ADVANCED_ERROR
;
2550 if (( $cgiparams { 'COMPRESSION' } !~ /^(|on|off)$/ ) ||
2551 ( $cgiparams { 'FORCE_MOBIKE' } !~ /^(|on|off)$/ ) ||
2552 ( $cgiparams { 'ONLY_PROPOSED' } !~ /^(|on|off)$/ ) ||
2553 ( $cgiparams { 'PFS' } !~ /^(|on|off)$/ )) {
2554 $errormessage = $Lang :: tr
{ 'invalid input' };
2555 goto ADVANCED_ERROR
;
2558 if ( $cgiparams { 'DPD_DELAY' } !~ /^\d+$/ ) {
2559 $errormessage = $Lang :: tr
{ 'invalid input for dpd delay' };
2560 goto ADVANCED_ERROR
;
2563 if ( $cgiparams { 'DPD_TIMEOUT' } !~ /^\d+$/ ) {
2564 $errormessage = $Lang :: tr
{ 'invalid input for dpd timeout' };
2565 goto ADVANCED_ERROR
;
2568 if ( $cgiparams { 'INACTIVITY_TIMEOUT' } !~ /^\d+$/ ) {
2569 $errormessage = $Lang :: tr
{ 'invalid input for inactivity timeout' };
2570 goto ADVANCED_ERROR
;
2573 $confighash { $cgiparams { 'KEY' }}[ 29 ] = $cgiparams { 'IKE_VERSION' };
2574 $confighash { $cgiparams { 'KEY' }}[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
2575 $confighash { $cgiparams { 'KEY' }}[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
2576 $confighash { $cgiparams { 'KEY' }}[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
2577 $confighash { $cgiparams { 'KEY' }}[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
2578 $confighash { $cgiparams { 'KEY' }}[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
2579 $confighash { $cgiparams { 'KEY' }}[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
2580 $confighash { $cgiparams { 'KEY' }}[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
2581 $confighash { $cgiparams { 'KEY' }}[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
2582 $confighash { $cgiparams { 'KEY' }}[ 12 ] = 'off' ; #$cgiparams{'AGGRMODE'};
2583 $confighash { $cgiparams { 'KEY' }}[ 13 ] = $cgiparams { 'COMPRESSION' };
2584 $confighash { $cgiparams { 'KEY' }}[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
2585 $confighash { $cgiparams { 'KEY' }}[ 28 ] = $cgiparams { 'PFS' };
2586 $confighash { $cgiparams { 'KEY' }}[ 27 ] = $cgiparams { 'DPD_ACTION' };
2587 $confighash { $cgiparams { 'KEY' }}[ 30 ] = $cgiparams { 'DPD_TIMEOUT' };
2588 $confighash { $cgiparams { 'KEY' }}[ 31 ] = $cgiparams { 'DPD_DELAY' };
2589 $confighash { $cgiparams { 'KEY' }}[ 32 ] = $cgiparams { 'FORCE_MOBIKE' };
2590 $confighash { $cgiparams { 'KEY' }}[ 33 ] = $cgiparams { 'START_ACTION' };
2591 $confighash { $cgiparams { 'KEY' }}[ 34 ] = $cgiparams { 'INACTIVITY_TIMEOUT' };
2592 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2595 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
2600 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
2601 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
2602 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
2603 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
2604 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
2605 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
2606 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
2607 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
2608 if ( $cgiparams { 'ESP_GROUPTYPE' } eq "" ) {
2609 $cgiparams { 'ESP_GROUPTYPE' } = $cgiparams { 'IKE_GROUPTYPE' };
2611 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
2612 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
2613 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
2614 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
2615 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
2616 $cgiparams { 'DPD_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
2617 $cgiparams { 'DPD_DELAY' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
2618 $cgiparams { 'FORCE_MOBIKE' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
2619 $cgiparams { 'START_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 33 ];
2620 $cgiparams { 'INACTIVITY_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 34 ];
2621 $cgiparams { 'MODE' } = $confighash { $cgiparams { 'KEY' }}[ 35 ];
2622 $cgiparams { 'INTERFACE_MODE' } = $confighash { $cgiparams { 'KEY' }}[ 36 ];
2623 $cgiparams { 'INTERFACE_ADDRESS' } = $confighash { $cgiparams { 'KEY' }}[ 37 ];
2624 $cgiparams { 'INTERFACE_MTU' } = $confighash { $cgiparams { 'KEY' }}[ 38 ];
2626 if (! $cgiparams { 'DPD_DELAY' }) {
2627 $cgiparams { 'DPD_DELAY' } = 30 ;
2630 if (! $cgiparams { 'DPD_TIMEOUT' }) {
2631 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
2634 if (! $cgiparams { 'START_ACTION' }) {
2635 $cgiparams { 'START_ACTION' } = "start" ;
2638 if ( $cgiparams { 'INACTIVITY_TIMEOUT' } eq "" ) {
2639 $cgiparams { 'INACTIVITY_TIMEOUT' } = 900 ; # 15 min
2642 if ( $cgiparams { 'MODE' } eq "" ) {
2643 $cgiparams { 'MODE' } = "tunnel" ;
2648 $checked { 'IKE_ENCRYPTION' }{ 'chacha20poly1305' } = '' ;
2649 $checked { 'IKE_ENCRYPTION' }{ 'aes256' } = '' ;
2650 $checked { 'IKE_ENCRYPTION' }{ 'aes192' } = '' ;
2651 $checked { 'IKE_ENCRYPTION' }{ 'aes128' } = '' ;
2652 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm128' } = '' ;
2653 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm128' } = '' ;
2654 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm128' } = '' ;
2655 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm96' } = '' ;
2656 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm96' } = '' ;
2657 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm96' } = '' ;
2658 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm64' } = '' ;
2659 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm64' } = '' ;
2660 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm64' } = '' ;
2661 $checked { 'IKE_ENCRYPTION' }{ '3des' } = '' ;
2662 $checked { 'IKE_ENCRYPTION' }{ 'camellia256' } = '' ;
2663 $checked { 'IKE_ENCRYPTION' }{ 'camellia192' } = '' ;
2664 $checked { 'IKE_ENCRYPTION' }{ 'camellia128' } = '' ;
2665 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2666 foreach my $key ( @temp ) { $checked { 'IKE_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2667 $checked { 'IKE_INTEGRITY' }{ 'sha2_512' } = '' ;
2668 $checked { 'IKE_INTEGRITY' }{ 'sha2_384' } = '' ;
2669 $checked { 'IKE_INTEGRITY' }{ 'sha2_256' } = '' ;
2670 $checked { 'IKE_INTEGRITY' }{ 'sha' } = '' ;
2671 $checked { 'IKE_INTEGRITY' }{ 'md5' } = '' ;
2672 $checked { 'IKE_INTEGRITY' }{ 'aesxcbc' } = '' ;
2673 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2674 foreach my $key ( @temp ) { $checked { 'IKE_INTEGRITY' }{ $key } = "selected='selected'" ; }
2675 $checked { 'IKE_GROUPTYPE' }{ 'curve25519' } = '' ;
2676 $checked { 'IKE_GROUPTYPE' }{ 'curve448' } = '' ;
2677 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2678 $checked { 'IKE_GROUPTYPE' }{ '1024' } = '' ;
2679 $checked { 'IKE_GROUPTYPE' }{ '1536' } = '' ;
2680 $checked { 'IKE_GROUPTYPE' }{ '2048' } = '' ;
2681 $checked { 'IKE_GROUPTYPE' }{ '3072' } = '' ;
2682 $checked { 'IKE_GROUPTYPE' }{ '4096' } = '' ;
2683 $checked { 'IKE_GROUPTYPE' }{ '6144' } = '' ;
2684 $checked { 'IKE_GROUPTYPE' }{ '8192' } = '' ;
2685 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2686 foreach my $key ( @temp ) { $checked { 'IKE_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2688 $checked { 'ESP_ENCRYPTION' }{ 'chacha20poly1305' } = '' ;
2689 $checked { 'ESP_ENCRYPTION' }{ 'aes256' } = '' ;
2690 $checked { 'ESP_ENCRYPTION' }{ 'aes192' } = '' ;
2691 $checked { 'ESP_ENCRYPTION' }{ 'aes128' } = '' ;
2692 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm128' } = '' ;
2693 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm128' } = '' ;
2694 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm128' } = '' ;
2695 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm96' } = '' ;
2696 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm96' } = '' ;
2697 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm96' } = '' ;
2698 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm64' } = '' ;
2699 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm64' } = '' ;
2700 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm64' } = '' ;
2701 $checked { 'ESP_ENCRYPTION' }{ '3des' } = '' ;
2702 $checked { 'ESP_ENCRYPTION' }{ 'camellia256' } = '' ;
2703 $checked { 'ESP_ENCRYPTION' }{ 'camellia192' } = '' ;
2704 $checked { 'ESP_ENCRYPTION' }{ 'camellia128' } = '' ;
2705 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2706 foreach my $key ( @temp ) { $checked { 'ESP_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2707 $checked { 'ESP_INTEGRITY' }{ 'sha2_512' } = '' ;
2708 $checked { 'ESP_INTEGRITY' }{ 'sha2_384' } = '' ;
2709 $checked { 'ESP_INTEGRITY' }{ 'sha2_256' } = '' ;
2710 $checked { 'ESP_INTEGRITY' }{ 'sha1' } = '' ;
2711 $checked { 'ESP_INTEGRITY' }{ 'md5' } = '' ;
2712 $checked { 'ESP_INTEGRITY' }{ 'aesxcbc' } = '' ;
2713 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2714 foreach my $key ( @temp ) { $checked { 'ESP_INTEGRITY' }{ $key } = "selected='selected'" ; }
2715 $checked { 'ESP_GROUPTYPE' }{ 'curve25519' } = '' ;
2716 $checked { 'ESP_GROUPTYPE' }{ 'curve448' } = '' ;
2717 $checked { 'ESP_GROUPTYPE' }{ '768' } = '' ;
2718 $checked { 'ESP_GROUPTYPE' }{ '1024' } = '' ;
2719 $checked { 'ESP_GROUPTYPE' }{ '1536' } = '' ;
2720 $checked { 'ESP_GROUPTYPE' }{ '2048' } = '' ;
2721 $checked { 'ESP_GROUPTYPE' }{ '3072' } = '' ;
2722 $checked { 'ESP_GROUPTYPE' }{ '4096' } = '' ;
2723 $checked { 'ESP_GROUPTYPE' }{ '6144' } = '' ;
2724 $checked { 'ESP_GROUPTYPE' }{ '8192' } = '' ;
2725 $checked { 'ESP_GROUPTYPE' }{ 'none' } = '' ;
2726 @temp = split ( '\|' , $cgiparams { 'ESP_GROUPTYPE' });
2727 foreach my $key ( @temp ) { $checked { 'ESP_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2729 $checked { 'COMPRESSION' } = $cgiparams { 'COMPRESSION' } eq 'on' ?
"checked='checked'" : '' ;
2730 $checked { 'FORCE_MOBIKE' } = $cgiparams { 'FORCE_MOBIKE' } eq 'on' ?
"checked='checked'" : '' ;
2731 $checked { 'ONLY_PROPOSED' } = $cgiparams { 'ONLY_PROPOSED' } eq 'on' ?
"checked='checked'" : '' ;
2732 $checked { 'PFS' } = $cgiparams { 'PFS' } eq 'on' ?
"checked='checked'" : '' ;
2734 $selected { 'IKE_VERSION' }{ 'ikev1' } = '' ;
2735 $selected { 'IKE_VERSION' }{ 'ikev2' } = '' ;
2736 $selected { 'IKE_VERSION' }{ $cgiparams { 'IKE_VERSION' }} = "selected='selected'" ;
2738 $selected { 'DPD_ACTION' }{ 'clear' } = '' ;
2739 $selected { 'DPD_ACTION' }{ 'hold' } = '' ;
2740 $selected { 'DPD_ACTION' }{ 'restart' } = '' ;
2741 $selected { 'DPD_ACTION' }{ 'none' } = '' ;
2742 $selected { 'DPD_ACTION' }{ $cgiparams { 'DPD_ACTION' }} = "selected='selected'" ;
2744 $selected { 'START_ACTION' }{ 'add' } = '' ;
2745 $selected { 'START_ACTION' }{ 'route' } = '' ;
2746 $selected { 'START_ACTION' }{ 'start' } = '' ;
2747 $selected { 'START_ACTION' }{ $cgiparams { 'START_ACTION' }} = "selected='selected'" ;
2749 $selected { 'INACTIVITY_TIMEOUT' } = ();
2750 foreach my $timeout ( keys %INACTIVITY_TIMEOUTS ) {
2751 $selected { 'INACTIVITY_TIMEOUT' }{ $timeout } = "" ;
2753 $selected { 'INACTIVITY_TIMEOUT' }{ $cgiparams { 'INACTIVITY_TIMEOUT' }} = "selected" ;
2755 & Header
:: showhttpheaders
();
2756 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
2757 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2759 if ( $errormessage ) {
2760 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2761 print "<class name='base'> $errormessage " ;
2762 print " </class>" ;
2763 & Header
:: closebox
();
2767 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
2768 print "<class name='base'> $warnmessage " ;
2769 print " </class>" ;
2770 & Header
:: closebox
();
2773 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'advanced'}:" );
2775 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
2776 <input type='hidden' name='ADVANCED' value='yes' />
2777 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
2779 <table width='100%'>
2782 <th width="15%"></th>
2789 <td> $Lang ::tr{'vpn keyexchange'}:</td>
2791 <select name='IKE_VERSION'>
2792 <option value='ikev2' $selected {'IKE_VERSION'}{'ikev2'}>IKEv2</option>
2793 <option value='ikev1' $selected {'IKE_VERSION'}{'ikev1'}>IKEv1</option>
2799 <td class='boldbase' width="15%"> $Lang ::tr{'encryption'}</td>
2800 <td class='boldbase'>
2801 <select name='IKE_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
2802 <option value='chacha20poly1305' $checked {'IKE_ENCRYPTION'}{'chacha20poly1305'}>256 bit ChaCha20-Poly1305/128 bit ICV</option>
2803 <option value='aes256gcm128' $checked {'IKE_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
2804 <option value='aes256gcm96' $checked {'IKE_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
2805 <option value='aes256gcm64' $checked {'IKE_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
2806 <option value='aes256' $checked {'IKE_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
2807 <option value='camellia256' $checked {'IKE_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
2808 <option value='aes192gcm128' $checked {'IKE_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
2809 <option value='aes192gcm96' $checked {'IKE_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
2810 <option value='aes192gcm64' $checked {'IKE_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
2811 <option value='aes192' $checked {'IKE_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
2812 <option value='camellia192' $checked {'IKE_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
2813 <option value='aes128gcm128' $checked {'IKE_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
2814 <option value='aes128gcm96' $checked {'IKE_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
2815 <option value='aes128gcm64' $checked {'IKE_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
2816 <option value='aes128' $checked {'IKE_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
2817 <option value='camellia128' $checked {'IKE_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
2818 <option value='3des' $checked {'IKE_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC ( $Lang ::tr{'vpn weak'})</option>
2821 <td class='boldbase'>
2822 <select name='ESP_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
2823 <option value='chacha20poly1305' $checked {'ESP_ENCRYPTION'}{'chacha20poly1305'}>256 bit ChaCha20-Poly1305/128 bit ICV</option>
2824 <option value='aes256gcm128' $checked {'ESP_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
2825 <option value='aes256gcm96' $checked {'ESP_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
2826 <option value='aes256gcm64' $checked {'ESP_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
2827 <option value='aes256' $checked {'ESP_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
2828 <option value='camellia256' $checked {'ESP_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
2829 <option value='aes192gcm128' $checked {'ESP_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
2830 <option value='aes192gcm96' $checked {'ESP_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
2831 <option value='aes192gcm64' $checked {'ESP_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
2832 <option value='aes192' $checked {'ESP_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
2833 <option value='camellia192' $checked {'ESP_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
2834 <option value='aes128gcm128' $checked {'ESP_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
2835 <option value='aes128gcm96' $checked {'ESP_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
2836 <option value='aes128gcm64' $checked {'ESP_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
2837 <option value='aes128' $checked {'ESP_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
2838 <option value='camellia128' $checked {'ESP_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
2839 <option value='3des' $checked {'ESP_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC ( $Lang ::tr{'vpn weak'})</option>
2845 <td class='boldbase' width="15%"> $Lang ::tr{'integrity'}</td>
2846 <td class='boldbase'>
2847 <select name='IKE_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
2848 <option value='sha2_512' $checked {'IKE_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2849 <option value='sha2_384' $checked {'IKE_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2850 <option value='sha2_256' $checked {'IKE_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2851 <option value='aesxcbc' $checked {'IKE_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2852 <option value='sha' $checked {'IKE_INTEGRITY'}{'sha'}>SHA1 ( $Lang ::tr{'vpn weak'})</option>
2853 <option value='md5' $checked {'IKE_INTEGRITY'}{'md5'}>MD5 ( $Lang ::tr{'vpn broken'})</option>
2856 <td class='boldbase'>
2857 <select name='ESP_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
2858 <option value='sha2_512' $checked {'ESP_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2859 <option value='sha2_384' $checked {'ESP_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2860 <option value='sha2_256' $checked {'ESP_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2861 <option value='aesxcbc' $checked {'ESP_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2862 <option value='sha1' $checked {'ESP_INTEGRITY'}{'sha1'}>SHA1 ( $Lang ::tr{'vpn weak'})</option>
2863 <option value='md5' $checked {'ESP_INTEGRITY'}{'md5'}>MD5 ( $Lang ::tr{'vpn broken'})</option>
2868 <td class='boldbase' width="15%"> $Lang ::tr{'lifetime'} <img src='/blob.gif' alt='*' /></td>
2869 <td class='boldbase'>
2870 <input type='text' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' size='5' /> $Lang ::tr{'hours'}
2872 <td class='boldbase'>
2873 <input type='text' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' size='5' /> $Lang ::tr{'hours'}
2877 <td class='boldbase' width="15%"> $Lang ::tr{'grouptype'}</td>
2878 <td class='boldbase'>
2879 <select name='IKE_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
2880 <option value='curve25519' $checked {'IKE_GROUPTYPE'}{'curve25519'}>Curve 25519 (256 bit)</option>
2881 <option value='curve448' $checked {'IKE_GROUPTYPE'}{'curve448'}>Curve 448 (224 bit)</option>
2882 <option value='e521' $checked {'IKE_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
2883 <option value='e512bp' $checked {'IKE_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
2884 <option value='e384' $checked {'IKE_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
2885 <option value='e384bp' $checked {'IKE_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
2886 <option value='e256' $checked {'IKE_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
2887 <option value='e256bp' $checked {'IKE_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
2888 <option value='e224' $checked {'IKE_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
2889 <option value='e224bp' $checked {'IKE_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
2890 <option value='e192' $checked {'IKE_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
2891 <option value='8192' $checked {'IKE_GROUPTYPE'}{'8192'}>MODP-8192</option>
2892 <option value='6144' $checked {'IKE_GROUPTYPE'}{'6144'}>MODP-6144</option>
2893 <option value='4096' $checked {'IKE_GROUPTYPE'}{'4096'}>MODP-4096</option>
2894 <option value='3072' $checked {'IKE_GROUPTYPE'}{'3072'}>MODP-3072</option>
2895 <option value='2048' $checked {'IKE_GROUPTYPE'}{'2048'}>MODP-2048</option>
2896 <option value='1536' $checked {'IKE_GROUPTYPE'}{'1536'}>MODP-1536</option>
2897 <option value='1024' $checked {'IKE_GROUPTYPE'}{'1024'}>MODP-1024 ( $Lang ::tr{'vpn broken'})</option>
2898 <option value='768' $checked {'IKE_GROUPTYPE'}{'768'}>MODP-768 ( $Lang ::tr{'vpn broken'})</option>
2901 <td class='boldbase'>
2902 <select name='ESP_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
2903 <option value='curve25519' $checked {'ESP_GROUPTYPE'}{'curve25519'}>Curve 25519 (256 bit)</option>
2904 <option value='curve448' $checked {'ESP_GROUPTYPE'}{'curve448'}>Curve 448 (224 bit)</option>
2905 <option value='e521' $checked {'ESP_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
2906 <option value='e512bp' $checked {'ESP_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
2907 <option value='e384' $checked {'ESP_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
2908 <option value='e384bp' $checked {'ESP_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
2909 <option value='e256' $checked {'ESP_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
2910 <option value='e256bp' $checked {'ESP_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
2911 <option value='e224' $checked {'ESP_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
2912 <option value='e224bp' $checked {'ESP_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
2913 <option value='e192' $checked {'ESP_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
2914 <option value='8192' $checked {'ESP_GROUPTYPE'}{'8192'}>MODP-8192</option>
2915 <option value='6144' $checked {'ESP_GROUPTYPE'}{'6144'}>MODP-6144</option>
2916 <option value='4096' $checked {'ESP_GROUPTYPE'}{'4096'}>MODP-4096</option>
2917 <option value='3072' $checked {'ESP_GROUPTYPE'}{'3072'}>MODP-3072</option>
2918 <option value='2048' $checked {'ESP_GROUPTYPE'}{'2048'}>MODP-2048</option>
2919 <option value='1536' $checked {'ESP_GROUPTYPE'}{'1536'}>MODP-1536</option>
2920 <option value='1024' $checked {'ESP_GROUPTYPE'}{'1024'}>MODP-1024 ( $Lang ::tr{'vpn broken'})</option>
2921 <option value='768' $checked {'ESP_GROUPTYPE'}{'768'}>MODP-768 ( $Lang ::tr{'vpn broken'})</option>
2922 <option value='none' $checked {'ESP_GROUPTYPE'}{'none'}>- $Lang ::tr{'none'} -</option>
2931 <h2> $Lang ::tr{'dead peer detection'}</h2>
2933 <table width="100%">
2935 <td width="15%"> $Lang ::tr{'dpd action'}:</td>
2937 <select name='DPD_ACTION'>
2938 <option value='none' $selected {'DPD_ACTION'}{'none'}>- $Lang ::tr{'disabled'} -</option>
2939 <option value='clear' $selected {'DPD_ACTION'}{'clear'}>clear</option>
2940 <option value='hold' $selected {'DPD_ACTION'}{'hold'}>hold</option>
2941 <option value='restart' $selected {'DPD_ACTION'}{'restart'}>restart</option>
2946 <td width="15%"> $Lang ::tr{'dpd timeout'}: <img src='/blob.gif' alt='*' /></td>
2948 <input type='text' name='DPD_TIMEOUT' size='5' value=' $cgiparams {'DPD_TIMEOUT'}' />
2952 <td width="15%"> $Lang ::tr{'dpd delay'}: <img src='/blob.gif' alt='*' /></td>
2954 <input type='text' name='DPD_DELAY' size='5' value=' $cgiparams {'DPD_DELAY'}' />
2961 <table width="100%">
2965 <input type='checkbox' name='ONLY_PROPOSED' $checked {'ONLY_PROPOSED'} />
2966 IKE+ESP: $Lang ::tr{'use only proposed settings'}
2970 <label> $Lang ::tr{'vpn start action'}</label>
2971 <select name="START_ACTION">
2972 <option value="route" $selected {'START_ACTION'}{'route'}> $Lang ::tr{'vpn start action route'}</option>
2973 <option value="start" $selected {'START_ACTION'}{'start'}> $Lang ::tr{'vpn start action start'}</option>
2974 <option value="add" $selected {'START_ACTION'}{'add'} > $Lang ::tr{'vpn start action add'}</option>
2981 <input type='checkbox' name='PFS' $checked {'PFS'} />
2982 $Lang ::tr{'pfs yes no'}
2986 <label> $Lang ::tr{'vpn inactivity timeout'}</label>
2987 <select name="INACTIVITY_TIMEOUT">
2989 foreach my $t ( sort { $a <=> $b } keys %INACTIVITY_TIMEOUTS ) {
2990 print "<option value= \" $t \" $selected {'INACTIVITY_TIMEOUT'}{ $t }> $INACTIVITY_TIMEOUTS { $t }</option> \n " ;
3001 <input type='checkbox' name='COMPRESSION' $checked {'COMPRESSION'} />
3002 $Lang ::tr{'vpn payload compression'}
3009 <input type='checkbox' name='FORCE_MOBIKE' $checked {'FORCE_MOBIKE'} />
3010 $Lang ::tr{'vpn force mobike'}
3015 <td align='left'><img src='/blob.gif' align='top' alt='*' /> $Lang ::tr{'required field'}</td>
3017 <input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />
3018 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' />
3024 & Header
:: closebox
();
3025 & Header
:: closebigbox
();
3026 & Header
:: closepage
();
3033 ### Default status page
3038 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%cgiparams );
3039 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
3040 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
3041 $cgiparams { 'CA_NAME' } = '' ;
3043 my @status = `/usr/local/bin/ipsecctrl I 2>/dev/null` ;
3045 $checked { 'ENABLED' } = $cgiparams { 'ENABLED' } eq 'on' ?
"checked='checked'" : '' ;
3047 & Header
:: showhttpheaders
();
3048 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
3049 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
3051 if ( $errormessage ) {
3052 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
3053 print "<class name='base'> $errormessage \n " ;
3054 print " </class> \n " ;
3055 & Header
:: closebox
();
3059 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
3060 print " $warnmessage <br>" ;
3061 print " $Lang ::tr{'fwdfw warn1'}<br>" ;
3062 & Header
:: closebox
();
3063 print "<center><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'ok'}' style='width: 5em;'></form>" ;
3064 & Header
:: closepage
();
3068 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'global settings' });
3070 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3071 <table width='100%'>
3073 <td width='60%' class='base'>
3074 $Lang ::tr{'enabled'}
3077 <input type='checkbox' name='ENABLED' $checked {'ENABLED'} />
3081 <td class='base' nowrap='nowrap' width="60%"> $Lang ::tr{'host to net vpn'}:</td>
3082 <td width="40%"><input type='text' name='RW_NET' value=' $cgiparams {'RW_NET'}' /></td>
3085 <td width='100%' colspan="2" align='right' class='base'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' /></td>
3091 & Header
:: closebox
();
3093 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection status and controlc' });
3095 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
3097 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
3098 <th width='22%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></th>
3099 <th width='23%' class='boldbase' align='center'><b> $Lang ::tr{'common name'}</b></th>
3100 <th width='30%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></th>
3101 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></th>
3102 <th class='boldbase' align='center' colspan='7'><b> $Lang ::tr{'action'}</b></th>
3108 foreach my $key ( sort { ncmp
( $confighash { $a }[ 1 ], $confighash { $b }[ 1 ]) } keys %confighash ) {
3109 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
3113 $col = "bgcolor=' $color {'color20'}'" ;
3116 $col = "bgcolor=' $color {'color22'}'" ;
3118 print "<td align='center' nowrap='nowrap' $col > $confighash { $key }[1]</td>" ;
3119 print "<td align='center' nowrap='nowrap' $col >" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ") $confighash { $key }[29]</td>" ;
3120 if ( $confighash { $key }[ 2 ] eq ' %auth -dn' ) {
3121 print "<td align='left' nowrap='nowrap' $col > $confighash { $key }[9]</td>" ;
3122 } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
3123 print "<td align='left' nowrap='nowrap' $col > $confighash { $key }[2]</td>" ;
3125 print "<td align='left' $col > </td>" ;
3127 print "<td align='center' $col > $confighash { $key }[25]</td>" ;
3128 my $col1 = "bgcolor='${Header::colourred}'" ;
3129 my $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
3130 if ( $confighash { $key }[ 33 ] eq "add" ) {
3131 $col1 = "bgcolor='${Header::colourorange}'" ;
3132 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'vpn wait'}</font></b>" ;
3134 foreach my $line ( @status ) {
3135 if (( $line =~ /\"$confighash{$key}[1]\".*IPsec SA established/ ) ||
3136 ( $line =~ /$confighash{$key}[1]\{.*INSTALLED/ )) {
3137 $col1 = "bgcolor='${Header::colourgreen}'" ;
3138 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b>" ;
3140 } elsif ( $line =~ /$confighash{$key}[1]\[.*CONNECTING/ ) {
3141 $col1 = "bgcolor='${Header::colourorange}'" ;
3142 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'vpn connecting'}</font></b>" ;
3143 } elsif ( $line =~ /$confighash{$key}[1]\{.*ROUTED/ ) {
3144 $col1 = "bgcolor='${Header::colourorange}'" ;
3145 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'vpn on-demand'}</font></b>" ;
3148 # move to blue if really down
3149 if ( $confighash { $key }[ 0 ] eq 'off' && $col1 =~ /${Header::colourred}/ ) {
3150 $col1 = "bgcolor='${Header::colourblue}'" ;
3151 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
3154 <td align='center' $col1 > $active </td>
3155 <td align='center' $col >
3156 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3157 <input type='image' name=' $Lang ::tr{'restart'}' src='/images/reload.gif' alt=' $Lang ::tr{'restart'}' title=' $Lang ::tr{'restart'}' />
3158 <input type='hidden' name='ACTION' value=' $Lang ::tr{'restart'}' />
3159 <input type='hidden' name='KEY' value=' $key ' />
3164 if (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
3166 <td align='center' $col >
3167 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3168 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' />
3169 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
3170 <input type='hidden' name='KEY' value=' $key ' />
3176 print "<td width='2%' $col > </td>" ;
3178 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/certs/ $confighash { $key }[1].p12" ) {
3180 <td align='center' $col >
3181 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3182 <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'}' />
3183 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
3184 <input type='hidden' name='KEY' value=' $key ' />
3189 } elsif (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
3191 <td align='center' $col >
3192 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3193 <input type='image' name=' $Lang ::tr{'download certificate'}' src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' title=' $Lang ::tr{'download certificate'}' />
3194 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
3195 <input type='hidden' name='KEY' value=' $key ' />
3201 print "<td width='2%' $col > </td>" ;
3205 if ( $confighash { $key }[ 3 ] eq 'host' ) {
3207 <td align='center' $col >
3208 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3209 <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'}' />
3210 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download apple profile'}' />
3211 <input type='hidden' name='KEY' value=' $key ' />
3216 print "<td width='2%' $col > </td>" ;
3220 <td align='center' $col >
3221 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3222 <input type='image' name=' $Lang ::tr{'toggle enable disable'}' src='/images/ $gif ' alt=' $Lang ::tr{'toggle enable disable'}' title=' $Lang ::tr{'toggle enable disable'}' />
3223 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
3224 <input type='hidden' name='KEY' value=' $key ' />
3228 <td align='center' $col >
3229 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3230 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
3231 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' title=' $Lang ::tr{'edit'}' />
3232 <input type='hidden' name='KEY' value=' $key ' />
3235 <td align='center' $col >
3236 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3237 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
3238 <input type='image' name=' $Lang ::tr{'remove'}' src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' title=' $Lang ::tr{'remove'}' />
3239 <input type='hidden' name='KEY' value=' $key ' />
3249 # If the config file contains entries, print Key to action icons
3254 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
3255 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
3256 <td class='base'> $Lang ::tr{'click to disable'}</td>
3257 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
3258 <td class='base'> $Lang ::tr{'show certificate'}</td>
3259 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
3260 <td class='base'> $Lang ::tr{'edit'}</td>
3261 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
3262 <td class='base'> $Lang ::tr{'remove'}</td>
3266 <td> <img src='/images/off.gif' alt='?OFF' /></td>
3267 <td class='base'> $Lang ::tr{'click to enable'}</td>
3268 <td> <img src='/images/floppy.gif' alt='?FLOPPY' /></td>
3269 <td class='base'> $Lang ::tr{'download certificate'}</td>
3270 <td> <img src='/images/reload.gif' alt='?RELOAD'/></td>
3271 <td class='base'> $Lang ::tr{'restart'}</td>
3279 <table width='100%'>
3280 <tr><td align='right' colspan='9'>
3281 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3282 <input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />
3288 & Header
:: closebox
();
3290 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'certificate authorities'}" );
3292 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
3294 <th width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
3295 <th width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></th>
3296 <th width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></th>
3300 my $col1 = "bgcolor=' $color {'color22'}'" ;
3301 my $col2 = "bgcolor=' $color {'color20'}'" ;
3302 if (- f
"${General::swroot}/ca/cacert.pem" ) {
3303 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/cacert.pem" ));
3306 <td class='base' $col1 > $Lang ::tr{'root certificate'}</td>
3307 <td class='base' $col1 > $casubject </td>
3308 <td width='3%' align='center' $col1 >
3309 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3310 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
3311 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/info.gif' alt=' $Lang ::tr{'show root certificate'}' title=' $Lang ::tr{'show root certificate'}' />
3314 <td width='3%' align='center' $col1 >
3315 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3316 <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'}' />
3317 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
3320 <td width='4%' $col1 > </td></tr>
3324 # display rootcert generation buttons
3327 <td class='base' $col1 > $Lang ::tr{'root certificate'}:</td>
3328 <td class='base' $col1 > $Lang ::tr{'not present'}</td>
3329 <td colspan='3' $col1 > </td></tr>
3334 if (- f
"${General::swroot}/certs/hostcert.pem" ) {
3335 my $hostsubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/certs/hostcert.pem" ));
3339 <td class='base' $col2 > $Lang ::tr{'host certificate'}</td>
3340 <td class='base' $col2 > $hostsubject </td>
3341 <td width='3%' align='center' $col2 >
3342 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3343 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
3344 <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'}' />
3347 <td width='3%' align='center' $col2 >
3348 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3349 <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'}" />
3350 <input type='hidden' name='ACTION' value=" $Lang ::tr{'download host certificate'}" />
3353 <td width='4%' $col2 > </td></tr>
3360 <td width='25%' class='base' $col2 > $Lang ::tr{'host certificate'}:</td>
3361 <td class='base' $col2 > $Lang ::tr{'not present'}</td>
3362 <td colspan='3' $col2 > </td></tr>
3368 if ( keys %cahash > 0 ) {
3369 foreach my $key ( keys %cahash ) {
3370 if ( $rowcolor ++ % 2 ) {
3372 $col = "bgcolor=' $color {'color20'}'" ;
3375 $col = "bgcolor=' $color {'color22'}'" ;
3377 print "<td class='base' $col > $cahash { $key }[0]</td> \n " ;
3378 print "<td class='base' $col > $cahash { $key }[1]</td> \n " ;
3380 <td align='center' $col >
3381 <form method='post' name='cafrm${key}a' action=' $ENV {'SCRIPT_NAME'}'>
3382 <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'}' />
3383 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
3384 <input type='hidden' name='KEY' value=' $key ' />
3387 <td align='center' $col >
3388 <form method='post' name='cafrm${key}b' action=' $ENV {'SCRIPT_NAME'}'>
3389 <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'}' />
3390 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
3391 <input type='hidden' name='KEY' value=' $key ' />
3394 <td align='center' $col >
3395 <form method='post' name='cafrm${key}c' action=' $ENV {'SCRIPT_NAME'}'>
3396 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
3397 <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'}' />
3398 <input type='hidden' name='KEY' value=' $key ' />
3408 # If the file contains entries, print Key to action icons
3409 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
3412 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
3413 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
3414 <td class='base'> $Lang ::tr{'show certificate'}</td>
3415 <td> <img src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' /></td>
3416 <td class='base'> $Lang ::tr{'download certificate'}</td>
3421 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>" ;
3425 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
3426 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
3429 <td class='base' nowrap='nowrap'> $Lang ::tr{'ca name'}: <img src='/blob.gif' alt='*' /></td>
3430 <td nowrap='nowrap'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' /> </td>
3431 <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td>
3432 <td nowrap='nowrap'><input type='submit' name='ACTION' value=' $Lang ::tr{'upload ca certificate'}' /></td>
3435 <td colspan='3'> $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}:</td>
3436 <td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' /></td>
3442 & Header
:: closebox
();
3443 & Header
:: closebigbox
();
3444 & Header
:: closepage
();
3446 sub array_unique
($) {
3451 foreach my $e ( @
$array ) {
3452 next if $seen { $e }++;
3459 sub make_algos
($$$$$) {
3460 my ( $mode , $encs , $ints , $grps , $pfs ) = @_ ;
3463 foreach my $enc ( @
$encs ) {
3464 foreach my $int ( @
$ints ) {
3465 foreach my $grp ( @
$grps ) {
3468 if ( $mode eq "ike" ) {
3471 if ( $grp =~ m/^e(.*)$/ ) {
3472 push ( @algo , "ecp $1 " );
3473 } elsif ( $grp =~ m/curve(25519|448)/ ) {
3474 push ( @algo , " $grp " );
3476 push ( @algo , "modp $grp " );
3479 } elsif ( $mode eq "esp" ) {
3480 my $is_aead = ( $enc =~ m/[cg]cm/ );
3486 if (! $pfs || $grp eq "none" ) {
3488 } elsif ( $grp =~ m/^e(.*)$/ ) {
3489 push ( @algo , "ecp $1 " );
3490 } elsif ( $grp =~ m/curve(25519|448)/ ) {
3491 push ( @algo , " $grp " );
3493 push ( @algo , "modp $grp " );
3497 push ( @algos , join ( "-" , @algo ));
3502 return & array_unique
( \
@algos );
3505 sub make_subnets
($$) {
3506 my $direction = shift ;
3507 my $subnets = shift ;
3509 my @nets = split ( /\|/ , $subnets );
3511 foreach my $net ( @nets ) {
3512 my $cidr_net = & General
:: ipcidr
( $net );
3514 # Skip 0.0.0.0/0 for remote because this renders the
3515 # while system inaccessible
3516 next if (( $direction eq "right" ) && ( $cidr_net eq "0.0.0.0/0" ));
3518 push ( @cidr_nets , $cidr_net );
3521 return join ( "," , @cidr_nets );