]>
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 ###############################################################################
26 use File
:: Temp qw
/ tempfile tempdir / ;
29 # enable only the following on debugging purpose
31 #use CGI::Carp 'fatalsToBrowser';
33 require '/var/ipfire/general-functions.pl' ;
34 require "${General::swroot}/lang.pl" ;
35 require "${General::swroot}/header.pl" ;
36 require "${General::swroot}/countries.pl" ;
38 #workaround to suppress a warning when a variable is used only once
39 my @dummy = ( ${ Header
:: colourgreen
}, ${ Header
:: colourblue
} );
43 ### Initialize variables
45 my $sleepDelay = 4 ; # after a call to ipsecctrl S or R, wait this delay (seconds) before reading status (let the ipsec do its job)
54 my $errormessage = '' ;
57 my %mainsettings = ();
58 & General
:: readhash
( "${General::swroot}/main/settings" , \
%mainsettings );
59 & General
:: readhash
( "/srv/web/ipfire/html/themes/ipfire/include/colors.txt" , \
%color );
61 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%netsettings );
63 my %INACTIVITY_TIMEOUTS = (
64 300 => $Lang :: tr
{ 'five minutes' },
65 600 => $Lang :: tr
{ 'ten minutes' },
66 900 => $Lang :: tr
{ 'fifteen minutes' },
67 1800 => $Lang :: tr
{ 'thirty minutes' },
68 3600 => $Lang :: tr
{ 'one hour' },
69 43200 => $Lang :: tr
{ 'twelve hours' },
70 86400 => $Lang :: tr
{ '24 hours' },
71 0 => "- $Lang ::tr{'unlimited'} -" ,
76 & General
:: get_aliases
( \
%aliases );
80 $cgiparams { 'ENABLED' } = 'off' ;
81 $cgiparams { 'EDIT_ADVANCED' } = 'off' ;
82 $cgiparams { 'ACTION' } = '' ;
83 $cgiparams { 'CA_NAME' } = '' ;
84 $cgiparams { 'KEY' } = '' ;
85 $cgiparams { 'TYPE' } = '' ;
86 $cgiparams { 'ADVANCED' } = '' ;
87 $cgiparams { 'NAME' } = '' ;
88 $cgiparams { 'LOCAL_SUBNET' } = '' ;
89 $cgiparams { 'REMOTE_SUBNET' } = '' ;
90 $cgiparams { 'LOCAL' } = '' ;
91 $cgiparams { 'REMOTE' } = '' ;
92 $cgiparams { 'LOCAL_ID' } = '' ;
93 $cgiparams { 'REMOTE_ID' } = '' ;
94 $cgiparams { 'REMARK' } = '' ;
95 $cgiparams { 'PSK' } = '' ;
96 $cgiparams { 'CERT_NAME' } = '' ;
97 $cgiparams { 'CERT_EMAIL' } = '' ;
98 $cgiparams { 'CERT_OU' } = '' ;
99 $cgiparams { 'CERT_ORGANIZATION' } = '' ;
100 $cgiparams { 'CERT_CITY' } = '' ;
101 $cgiparams { 'CERT_STATE' } = '' ;
102 $cgiparams { 'CERT_COUNTRY' } = '' ;
103 $cgiparams { 'SUBJECTALTNAME' } = '' ;
104 $cgiparams { 'CERT_PASS1' } = '' ;
105 $cgiparams { 'CERT_PASS2' } = '' ;
106 $cgiparams { 'ROOTCERT_HOSTNAME' } = '' ;
107 $cgiparams { 'ROOTCERT_COUNTRY' } = '' ;
108 $cgiparams { 'P12_PASS' } = '' ;
109 $cgiparams { 'ROOTCERT_ORGANIZATION' } = '' ;
110 $cgiparams { 'ROOTCERT_HOSTNAME' } = '' ;
111 $cgiparams { 'ROOTCERT_EMAIL' } = '' ;
112 $cgiparams { 'ROOTCERT_OU' } = '' ;
113 $cgiparams { 'ROOTCERT_CITY' } = '' ;
114 $cgiparams { 'ROOTCERT_STATE' } = '' ;
115 $cgiparams { 'RW_NET' } = '' ;
116 $cgiparams { 'DPD_DELAY' } = '30' ;
117 $cgiparams { 'DPD_TIMEOUT' } = '120' ;
118 $cgiparams { 'FORCE_MOBIKE' } = 'off' ;
119 $cgiparams { 'START_ACTION' } = 'route' ;
120 $cgiparams { 'INACTIVITY_TIMEOUT' } = 1800 ;
121 $cgiparams { 'MODE' } = "tunnel" ;
122 $cgiparams { 'INTERFACE_MODE' } = "" ;
123 $cgiparams { 'INTERFACE_ADDRESS' } = "" ;
124 $cgiparams { 'INTERFACE_MTU' } = 1500 ;
125 & Header
:: getcgihash
( \
%cgiparams , { 'wantfile' => 1 , 'filevar' => 'FH' });
131 my $hostname = $_ [ 0 ];
132 unless ( $hostname ) { return "No hostname" };
133 my $res = new Net
:: DNS
:: Resolver
;
134 my $query = $res -> search ( " $hostname " );
136 foreach my $rr ( $query -> answer ) {
137 ## Potential bug - we are only looking at A records:
138 return 0 if $rr -> type eq "A" ;
141 return $res -> errorstring ;
145 ### Just return true is one interface is vpn enabled
148 return ( $vpnsettings { 'ENABLED' } eq 'on' );
151 ### old version: maintain serial number to one, without explication.
152 ### this: let the counter go, so that each cert is numbered.
154 sub cleanssldatabase
{
155 if ( open ( FILE
, ">${General::swroot}/certs/serial" )) {
159 if ( open ( FILE
, ">${General::swroot}/certs/index.txt" )) {
163 if ( open ( FILE
, ">${General::swroot}/certs/index.txt.attr" )) {
167 unlink ( "${General::swroot}/certs/index.txt.old" );
168 unlink ( "${General::swroot}/certs/index.txt.attr.old" );
169 unlink ( "${General::swroot}/certs/serial.old" );
170 unlink ( "${General::swroot}/certs/01.pem" );
172 sub newcleanssldatabase
{
173 if (! - s
"${General::swroot}/certs/serial" ) {
174 open ( FILE
, ">${General::swroot}/certs/serial" );
178 if (! - s
">${General::swroot}/certs/index.txt" ) {
179 system ( "touch ${General::swroot}/certs/index.txt" );
181 if (! - s
">${General::swroot}/certs/index.txt.attr" ) {
182 system ( "touch ${General::swroot}/certs/index.txt.attr" );
184 unlink ( "${General::swroot}/certs/index.txt.old" );
185 unlink ( "${General::swroot}/certs/index.txt.attr.old" );
186 unlink ( "${General::swroot}/certs/serial.old" );
187 # unlink ("${General::swroot}/certs/01.pem"); numbering evolves. Wrong place to delete
191 ### Call openssl and return errormessage if any
195 my $retssl = `/usr/bin/openssl $opt 2>&1` ; #redirect stderr
197 foreach my $line ( split ( /\n/ , $retssl )) {
198 & General
:: log ( "ipsec" , " $line " ) if ( 0 ); # 1 for verbose logging
199 $ret .= '<br>' . $line if ( $line =~ /error|unknown/ );
202 $ret = & Header
:: cleanhtml
( $ret );
204 return $ret ?
" $Lang ::tr{'openssl produced an error'}: $ret " : '' ;
207 ### Obtain a CN from given cert
209 sub getCNfromcert
($) {
210 #&General::log("ipsec", "Extracting name from $_[0]...");
211 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
212 $temp =~ /Subject:.*CN = (.*)[\n]/ ;
214 $temp =~ s
+/ Email
+, E
+;
215 $temp =~ s/ ST = / S = / ;
221 ### Obtain Subject from given cert
223 sub getsubjectfromcert
($) {
224 #&General::log("ipsec", "Extracting subject from $_[0]...");
225 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
226 $temp =~ /Subject: (.*)[\n]/ ;
228 $temp =~ s
+/ Email
+, E
+;
229 $temp =~ s/ ST = / S = / ;
233 ### Combine local subnet and connection name to make a unique name for each connection section
234 ### (this sub is not used now)
236 sub makeconnname
($) {
240 $subnet =~ /^(.*?)\/ (.* ?
)$/; # $1=IP $2=mask
241 my $ip = unpack ( 'N' , & Socket
:: inet_aton
( $1 ));
242 if ( length ( $2 ) > 2 ) {
243 my $mm = unpack ( 'N' , & Socket
:: inet_aton
( $2 ));
244 while ( ( $mm & 1 )== 0 ) {
251 return sprintf ( " %s - %X " , $conn , $ip );
254 ### Write a config file.
256 ###Type=Host : GUI can choose the interface used (RED,GREEN,BLUE) and
257 ### the side is always defined as 'left'.
260 sub writeipsecfiles
{
261 my %lconfighash = ();
262 my %lvpnsettings = ();
263 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%lconfighash );
264 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%lvpnsettings );
266 open ( CONF
, ">${General::swroot}/vpn/ipsec.conf" ) or die "Unable to open ${General::swroot}/vpn/ipsec.conf: $!" ;
267 open ( SECRETS
, ">${General::swroot}/vpn/ipsec.secrets" ) or die "Unable to open ${General::swroot}/vpn/ipsec.secrets: $!" ;
270 print CONF
"version 2 \n\n " ;
271 print CONF
"conn %default \n " ;
272 print CONF
" \t keyingtries= %forever \n " ;
275 # Add user includes to config file
276 if (- e
"/etc/ipsec.user.conf" ) {
277 print CONF
"include /etc/ipsec.user.conf \n " ;
281 print SECRETS
"include /etc/ipsec.user.secrets \n " ;
283 if (- f
"${General::swroot}/certs/hostkey.pem" ) {
284 print SECRETS
": RSA ${General::swroot}/certs/hostkey.pem \n "
286 my $last_secrets = '' ; # old the less specifics connections
288 foreach my $key ( keys %lconfighash ) {
289 next if ( $lconfighash { $key }[ 0 ] ne 'on' );
291 #remote peer is not set? => use '%any'
292 $lconfighash { $key }[ 10 ] = ' %any ' if ( $lconfighash { $key }[ 10 ] eq '' );
294 # Field 6 might be "off" on old installations
295 if ( $lconfighash { $key }[ 6 ] eq "off" ) {
296 $lconfighash { $key }[ 6 ] = $lvpnsettings { "VPN_IP" };
300 if ( $lconfighash { $key }[ 6 ]) {
301 $localside = $lconfighash { $key }[ 6 ];
303 $localside = " %defaultroute " ;
306 my $interface_mode = $lconfighash { $key }[ 36 ];
308 print CONF
"conn $lconfighash { $key }[1] \n " ;
309 print CONF
" \t left= $localside \n " ;
311 if ( $interface_mode eq "gre" ) {
312 print CONF
" \t leftprotoport=gre \n " ;
313 } elsif ( $interface_mode eq "vti" ) {
314 print CONF
" \t leftsubnet=0.0.0.0/0 \n " ;
316 print CONF
" \t leftsubnet=" . & make_subnets
( "left" , $lconfighash { $key }[ 8 ]) . " \n " ;
319 print CONF
" \t leftfirewall=yes \n " ;
320 print CONF
" \t lefthostaccess=yes \n " ;
321 print CONF
" \t right= $lconfighash { $key }[10] \n " ;
323 if ( $lconfighash { $key }[ 3 ] eq 'net' ) {
324 if ( $interface_mode eq "gre" ) {
325 print CONF
" \t rightprotoport=gre \n " ;
326 } elsif ( $interface_mode eq "vti" ) {
327 print CONF
" \t rightsubnet=0.0.0.0/0 \n " ;
329 print CONF
" \t rightsubnet=" . & make_subnets
( "right" , $lconfighash { $key }[ 11 ]) . " \n " ;
333 # Local Cert and Remote Cert (unless auth is DN dn-auth)
334 if ( $lconfighash { $key }[ 4 ] eq 'cert' ) {
335 print CONF
" \t leftcert=${General::swroot}/certs/hostcert.pem \n " ;
336 print CONF
" \t rightcert=${General::swroot}/certs/ $lconfighash { $key }[1]cert.pem \n " if ( $lconfighash { $key }[ 2 ] ne ' %auth -dn' );
339 # Local and Remote IDs
340 print CONF
" \t leftid= \" $lconfighash { $key }[7] \"\n " if ( $lconfighash { $key }[ 7 ]);
341 print CONF
" \t rightid= \" $lconfighash { $key }[9] \"\n " if ( $lconfighash { $key }[ 9 ]);
344 if ( $lconfighash { $key }[ 35 ] eq "transport" ) {
345 print CONF
" \t type=transport \n " ;
347 print CONF
" \t type=tunnel \n " ;
351 if ( $interface_mode eq "vti" ) {
352 print CONF
" \t mark= $key \n " ;
356 my $pfs = $lconfighash { $key }[ 28 ] eq 'on' ?
'on' : 'off' ;
359 if ( $lconfighash { $key }[ 18 ] && $lconfighash { $key }[ 19 ] && $lconfighash { $key }[ 20 ]) {
360 my @encs = split ( '\|' , $lconfighash { $key }[ 18 ]);
361 my @ints = split ( '\|' , $lconfighash { $key }[ 19 ]);
362 my @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
364 my @algos = & make_algos
( "ike" , \
@encs , \
@ints , \
@groups , 1 );
365 print CONF
" \t ike=" . join ( "," , @algos );
367 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
374 if ( $lconfighash { $key }[ 21 ] && $lconfighash { $key }[ 22 ]) {
375 my @encs = split ( '\|' , $lconfighash { $key }[ 21 ]);
376 my @ints = split ( '\|' , $lconfighash { $key }[ 22 ]);
377 my @groups = split ( '\|' , $lconfighash { $key }[ 23 ]);
379 # Use IKE grouptype if no ESP group type has been selected
380 # (for backwards compatibility)
381 if ( $lconfighash { $key }[ 23 ] eq "" ) {
382 @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
385 my @algos = & make_algos
( "esp" , \
@encs , \
@ints , \
@groups , ( $pfs eq "on" ));
386 print CONF
" \t esp=" . join ( "," , @algos );
388 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
396 if (! $lconfighash { $key }[ 29 ]) {
397 $lconfighash { $key }[ 29 ] = "ikev1" ;
400 print CONF
" \t keyexchange= $lconfighash { $key }[29] \n " ;
403 print CONF
" \t ikelifetime= $lconfighash { $key }[16]h \n " if ( $lconfighash { $key }[ 16 ]);
404 print CONF
" \t keylife= $lconfighash { $key }[17]h \n " if ( $lconfighash { $key }[ 17 ]);
407 print CONF
" \t compress=yes \n " if ( $lconfighash { $key }[ 13 ] eq 'on' );
410 if (( $lconfighash { $key }[ 29 ] eq "ikev2" ) && ( $lconfighash { $key }[ 32 ] eq 'on' )) {
411 print CONF
" \t mobike=yes \n " ;
414 # Dead Peer Detection
415 my $dpdaction = $lconfighash { $key }[ 27 ];
416 print CONF
" \t dpdaction= $dpdaction \n " ;
418 # If the dead peer detection is disabled and IKEv2 is used,
419 # dpddelay must be set to zero, too.
420 if ( $dpdaction eq "none" ) {
421 if ( $lconfighash { $key }[ 29 ] eq "ikev2" ) {
422 print CONF
" \t dpddelay=0 \n " ;
425 my $dpddelay = $lconfighash { $key }[ 31 ];
429 print CONF
" \t dpddelay= $dpddelay \n " ;
430 my $dpdtimeout = $lconfighash { $key }[ 30 ];
434 print CONF
" \t dpdtimeout= $dpdtimeout \n " ;
437 # Build Authentication details: LEFTid RIGHTid : PSK psk
439 if ( $lconfighash { $key }[ 4 ] eq 'psk' ) {
440 $psk_line = ( $lconfighash { $key }[ 7 ] ?
$lconfighash { $key }[ 7 ] : $localside ) . " " ;
441 $psk_line .= $lconfighash { $key }[ 9 ] ?
$lconfighash { $key }[ 9 ] : $lconfighash { $key }[ 10 ]; #remoteid or remote address?
442 $psk_line .= " : PSK ' $lconfighash { $key }[5]' \n " ;
443 # if the line contains %any, it is less specific than two IP or ID, so move it at end of file.
444 if ( $psk_line =~ /%any/ ) {
445 $last_secrets .= $psk_line ;
447 print SECRETS
$psk_line ;
449 print CONF
" \t authby=secret \n " ;
451 print CONF
" \t authby=rsasig \n " ;
452 print CONF
" \t leftrsasigkey= %cert \n " ;
453 print CONF
" \t rightrsasigkey= %cert \n " ;
456 my $start_action = $lconfighash { $key }[ 33 ];
457 if (! $start_action ) {
458 $start_action = "start" ;
461 my $inactivity_timeout = $lconfighash { $key }[ 34 ];
462 if ( $inactivity_timeout eq "" ) {
463 $inactivity_timeout = 900 ;
466 # Automatically start only if a net-to-net connection
467 if ( $lconfighash { $key }[ 3 ] eq 'host' ) {
468 print CONF
" \t auto=add \n " ;
469 print CONF
" \t rightsourceip= $lvpnsettings {'RW_NET'} \n " ;
471 print CONF
" \t auto= $start_action \n " ;
473 # If in on-demand mode, we terminate the tunnel
474 # after 15 min of no traffic
475 if ( $start_action eq 'route' && $inactivity_timeout > 0 ) {
476 print CONF
" \t inactivity= $inactivity_timeout \n " ;
481 print CONF
" \t fragmentation=yes \n " ;
486 # Add post user includes to config file
487 # After the GUI-connections allows to patch connections.
488 if (- e
"/etc/ipsec.user-post.conf" ) {
489 print CONF
"include /etc/ipsec.user-post.conf \n " ;
493 print SECRETS
$last_secrets if ( $last_secrets );
498 # Hook to regenerate the configuration files.
499 if ( $ENV { "REMOTE_ADDR" } eq "" ) {
505 ### Save main settings
507 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
508 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
510 if ( $cgiparams { 'RW_NET' } ne '' and !& General
:: validipandmask
( $cgiparams { 'RW_NET' }) ) {
511 $errormessage = $Lang :: tr
{ 'urlfilter invalid ip or mask error' };
515 $vpnsettings { 'ENABLED' } = $cgiparams { 'ENABLED' };
516 $vpnsettings { 'RW_NET' } = $cgiparams { 'RW_NET' };
517 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
520 system ( '/usr/local/bin/ipsecctrl' , 'S' );
522 system ( '/usr/local/bin/ipsecctrl' , 'D' );
529 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
530 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
532 foreach my $key ( keys %confighash ) {
533 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
534 delete $confighash { $key };
537 while ( my $file = glob ( "${General::swroot}/{ca,certs,crls,private}/*" )) {
541 if ( open ( FILE
, ">${General::swroot}/vpn/caconfig" )) {
545 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
547 system ( '/usr/local/bin/ipsecctrl' , 'R' );
553 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' }) {
554 & Header
:: showhttpheaders
();
555 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
556 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
557 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
559 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
563 <input type='hidden' name='AREUSURE' value='yes' />
564 <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'}
568 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' />
569 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
576 & Header
:: closebigbox
();
577 & Header
:: closepage
();
581 ### Upload CA Certificate
583 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
584 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
586 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
587 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
591 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
592 $errormessage = $Lang :: tr
{ 'name too long' };
596 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
597 $errormessage = $Lang :: tr
{ 'name is invalid' };
598 goto UPLOAD_CA_ERROR
;
601 # Check if there is no other entry with this name
602 foreach my $key ( keys %cahash ) {
603 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
604 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
609 unless ( ref ( $cgiparams { 'FH' })) {
610 $errormessage = $Lang :: tr
{ 'there was no file upload' };
613 # Move uploaded ca to a temporary file
614 ( my $fh , my $filename ) = tempfile
( );
615 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
619 my $temp = `/usr/bin/openssl x509 -text -in $filename ` ;
620 if ( $temp !~ /CA:TRUE/i ) {
621 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
625 move
( $filename , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
627 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
633 my $key = & General
:: findhasharraykey
( \
%cahash );
634 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
635 $cahash { $key }[ 1 ] = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" ));
636 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
638 system ( '/usr/local/bin/ipsecctrl' , 'R' );
644 ### Display ca certificate
646 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
647 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
649 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
650 & Header
:: showhttpheaders
();
651 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
652 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
653 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'ca certificate'}:" );
654 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
655 $output = & Header
:: cleanhtml
( $output , "y" );
656 print "<pre> $output </pre> \n " ;
658 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
659 & Header
:: closebigbox
();
660 & Header
:: closepage
();
663 $errormessage = $Lang :: tr
{ 'invalid key' };
667 ### Export ca certificate to browser
669 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
670 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
672 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
673 print "Content-Type: application/force-download \n " ;
674 print "Content-Type: application/octet-stream \r\n " ;
675 print "Content-Disposition: attachment; filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
676 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
679 $errormessage = $Lang :: tr
{ 'invalid key' };
683 ### Remove ca certificate (step 2)
685 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
686 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
687 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
689 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
690 foreach my $key ( keys %confighash ) {
691 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
692 if ( $test =~ /: OK/ ) {
694 unlink ( "${General::swroot}/certs/ $confighash { $key }[1]cert.pem" );
695 unlink ( "${General::swroot}/certs/ $confighash { $key }[1].p12" );
696 delete $confighash { $key };
697 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
699 system ( '/usr/local/bin/ipsecctrl' , 'D' , $key ) if (& vpnenabled
);
702 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
703 delete $cahash { $cgiparams { 'KEY' }};
704 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
705 system ( '/usr/local/bin/ipsecctrl' , 'R' );
708 $errormessage = $Lang :: tr
{ 'invalid key' };
711 ### Remove ca certificate (step 1)
713 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
714 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
715 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
717 my $assignedcerts = 0 ;
718 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
719 foreach my $key ( keys %confighash ) {
720 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
721 if ( $test =~ /: OK/ ) {
725 if ( $assignedcerts ) {
726 & Header
:: showhttpheaders
();
727 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
728 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
729 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
731 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
735 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
736 <input type='hidden' name='AREUSURE' value='yes' /></td>
739 <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>
742 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
743 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
750 & Header
:: closebigbox
();
751 & Header
:: closepage
();
754 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
755 delete $cahash { $cgiparams { 'KEY' }};
756 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
757 system ( '/usr/local/bin/ipsecctrl' , 'R' );
761 $errormessage = $Lang :: tr
{ 'invalid key' };
765 ### Display root certificate
767 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
768 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
770 & Header
:: showhttpheaders
();
771 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
772 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
773 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
774 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'root certificate'}:" );
775 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/cacert.pem` ;
777 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'host certificate'}:" );
778 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/hostcert.pem` ;
780 $output = & Header
:: cleanhtml
( $output , "y" );
781 print "<pre> $output </pre> \n " ;
783 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
784 & Header
:: closebigbox
();
785 & Header
:: closepage
();
789 ### Export root certificate to browser
791 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
792 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
793 print "Content-Type: application/force-download \n " ;
794 print "Content-Disposition: attachment; filename=cacert.pem \r\n\r\n " ;
795 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/cacert.pem` ;
799 ### Export host certificate to browser
801 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
802 if ( - f
"${General::swroot}/certs/hostcert.pem" ) {
803 print "Content-Type: application/force-download \n " ;
804 print "Content-Disposition: attachment; filename=hostcert.pem \r\n\r\n " ;
805 print `/usr/bin/openssl x509 -in ${General::swroot}/certs/hostcert.pem` ;
809 ### Form for generating/importing the caroot+host certificate
811 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
812 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
814 if (- f
"${General::swroot}/ca/cacert.pem" ) {
815 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
819 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
820 # fill in initial values
821 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
822 if (- e
"${General::swroot}/red/active" && open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
823 my $ipaddr = < IPADDR
>;
826 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
827 $cgiparams { 'SUBJECTALTNAME' } = "DNS:" . $cgiparams { 'ROOTCERT_HOSTNAME' };
828 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
829 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
830 $cgiparams { 'SUBJECTALTNAME' } = "IP:" . $cgiparams { 'ROOTCERT_HOSTNAME' };
833 $cgiparams { 'ROOTCERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' } if (! $cgiparams { 'ROOTCERT_COUNTRY' });
834 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
835 & General
:: log ( "ipsec" , "Importing from p12..." );
837 unless ( ref ( $cgiparams { 'FH' })) {
838 $errormessage = $Lang :: tr
{ 'there was no file upload' };
842 # Move uploaded certificate request to a temporary file
843 ( my $fh , my $filename ) = tempfile
( );
844 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
849 # Extract the CA certificate from the file
850 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
851 if ( open ( STDIN
, "-|" )) {
852 my $opt = " pkcs12 -cacerts -nokeys" ;
853 $opt .= " -in $filename " ;
854 $opt .= " -out /tmp/newcacert" ;
855 $errormessage = & callssl
( $opt );
857 print " $cgiparams {'P12_PASS'} \n " ;
861 # Extract the Host certificate from the file
862 if (! $errormessage ) {
863 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
864 if ( open ( STDIN
, "-|" )) {
865 my $opt = " pkcs12 -clcerts -nokeys" ;
866 $opt .= " -in $filename " ;
867 $opt .= " -out /tmp/newhostcert" ;
868 $errormessage = & callssl
( $opt );
870 print " $cgiparams {'P12_PASS'} \n " ;
875 # Extract the Host key from the file
876 if (! $errormessage ) {
877 & General
:: log ( "ipsec" , "Extracting private key from p12..." );
878 if ( open ( STDIN
, "-|" )) {
879 my $opt = " pkcs12 -nocerts -nodes" ;
880 $opt .= " -in $filename " ;
881 $opt .= " -out /tmp/newhostkey" ;
882 $errormessage = & callssl
( $opt );
884 print " $cgiparams {'P12_PASS'} \n " ;
889 if (! $errormessage ) {
890 & General
:: log ( "ipsec" , "Moving cacert..." );
891 move
( "/tmp/newcacert" , "${General::swroot}/ca/cacert.pem" );
892 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
895 if (! $errormessage ) {
896 & General
:: log ( "ipsec" , "Moving host cert..." );
897 move
( "/tmp/newhostcert" , "${General::swroot}/certs/hostcert.pem" );
898 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
901 if (! $errormessage ) {
902 & General
:: log ( "ipsec" , "Moving private key..." );
903 move
( "/tmp/newhostkey" , "${General::swroot}/certs/hostkey.pem" );
904 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
909 unlink ( '/tmp/newcacert' );
910 unlink ( '/tmp/newhostcert' );
911 unlink ( '/tmp/newhostkey' );
913 unlink ( "${General::swroot}/ca/cacert.pem" );
914 unlink ( "${General::swroot}/certs/hostcert.pem" );
915 unlink ( "${General::swroot}/certs/hostkey.pem" );
919 # Create empty CRL cannot be done because we don't have
920 # the private key for this CAROOT
921 # IPFire can only import certificates
923 & General
:: log ( "ipsec" , "p12 import completed!" );
925 goto ROOTCERT_SUCCESS
;
927 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
929 # Validate input since the form was submitted
930 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
931 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
934 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
935 $errormessage = $Lang :: tr
{ 'organization too long' };
938 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
939 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
942 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
943 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
946 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
947 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
950 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
951 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
954 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
955 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
958 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
959 $errormessage = $Lang :: tr
{ 'invalid input for department' };
962 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
963 $errormessage = $Lang :: tr
{ 'invalid input for city' };
966 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
967 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
970 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
971 $errormessage = $Lang :: tr
{ 'invalid input for country' };
974 #the exact syntax is a list comma separated of
975 # email:any-validemail
976 # URI: a uniform resource indicator
977 # DNS: a DNS domain name
978 # RID: a registered OBJECT IDENTIFIER
980 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
982 if ( $cgiparams { 'SUBJECTALTNAME' } eq '' ) {
983 $errormessage = $Lang :: tr
{ 'vpn subjectaltname missing' };
987 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
988 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
992 # Copy the cgisettings to vpnsettings and save the configfile
993 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
994 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
995 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
996 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
997 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
998 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
999 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
1000 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1002 # Replace empty strings with a .
1003 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
1004 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
1005 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
1007 # Create the CA certificate
1008 if (! $errormessage ) {
1009 & General
:: log ( "ipsec" , "Creating cacert..." );
1010 if ( open ( STDIN
, "-|" )) {
1011 my $opt = " req -x509 -sha256 -nodes" ;
1012 $opt .= " -days 3650" ;
1013 $opt .= " -newkey rsa:4096" ;
1014 $opt .= " -keyout ${General::swroot}/private/cakey.pem" ;
1015 $opt .= " -out ${General::swroot}/ca/cacert.pem" ;
1017 $errormessage = & callssl
( $opt );
1019 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1022 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1024 print " $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
1025 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1030 # Create the Host certificate request
1031 if (! $errormessage ) {
1032 & General
:: log ( "ipsec" , "Creating host cert..." );
1033 if ( open ( STDIN
, "-|" )) {
1034 my $opt = " req -sha256 -nodes" ;
1035 $opt .= " -newkey rsa:2048" ;
1036 $opt .= " -keyout ${General::swroot}/certs/hostkey.pem" ;
1037 $opt .= " -out ${General::swroot}/certs/hostreq.pem" ;
1038 $errormessage = & callssl
( $opt );
1040 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1043 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1045 print " $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
1046 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1053 # Sign the host certificate request
1054 if (! $errormessage ) {
1055 & General
:: log ( "ipsec" , "Self signing host cert..." );
1057 #No easy way for specifying the contain of subjectAltName without writing a config file...
1058 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1060 basicConstraints=CA:FALSE
1061 nsComment="OpenSSL Generated Certificate"
1062 subjectKeyIdentifier=hash
1063 authorityKeyIdentifier=keyid,issuer:always
1064 extendedKeyUsage = serverAuth
1067 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1070 my $opt = " ca -md sha256 -days 825" ;
1071 $opt .= " -batch -notext" ;
1072 $opt .= " -in ${General::swroot}/certs/hostreq.pem" ;
1073 $opt .= " -out ${General::swroot}/certs/hostcert.pem" ;
1074 $opt .= " -extfile $v3extname " ;
1075 $errormessage = & callssl
( $opt );
1076 unlink ( "${General::swroot}/certs/hostreq.pem" ); #no more needed
1077 unlink ( $v3extname );
1080 # Create an empty CRL
1081 if (! $errormessage ) {
1082 & General
:: log ( "ipsec" , "Creating emptycrl..." );
1083 my $opt = " ca -gencrl" ;
1084 $opt .= " -out ${General::swroot}/crls/cacrl.pem" ;
1085 $errormessage = & callssl
( $opt );
1088 # Successfully build CA / CERT!
1089 if (! $errormessage ) {
1090 & cleanssldatabase
();
1091 goto ROOTCERT_SUCCESS
;
1095 unlink ( "${General::swroot}/ca/cacert.pem" );
1096 unlink ( "${General::swroot}/certs/hostkey.pem" );
1097 unlink ( "${General::swroot}/certs/hostcert.pem" );
1098 unlink ( "${General::swroot}/crls/cacrl.pem" );
1099 & cleanssldatabase
();
1103 & Header
:: showhttpheaders
();
1104 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1105 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1106 if ( $errormessage ) {
1107 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1108 print "<class name='base'> $errormessage " ;
1109 print " </class>" ;
1110 & Header
:: closebox
();
1112 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
1114 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
1115 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1116 <tr><td width='40%' class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
1117 <td width='60%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td></tr>
1118 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}: <img src='/blob.gif' alt='*' /></td>
1119 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td></tr>
1120 <tr><td class='base'> $Lang ::tr{'your e-mail'}:</td>
1121 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td></tr>
1122 <tr><td class='base'> $Lang ::tr{'your department'}:</td>
1123 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td></tr>
1124 <tr><td class='base'> $Lang ::tr{'city'}:</td>
1125 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td></tr>
1126 <tr><td class='base'> $Lang ::tr{'state or province'}:</td>
1127 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td></tr>
1128 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1129 <td class='base'><select name='ROOTCERT_COUNTRY'>
1132 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1133 print "<option value=' $Countries ::countries{ $country }'" ;
1134 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1135 print " selected='selected'" ;
1137 print "> $country </option>" ;
1141 <tr><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*) <img src='/blob.gif' alt='*' /></td>
1142 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' /></td></tr>
1144 <td><br /><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /><br /><br /></td></tr>
1145 <tr><td class='base' colspan='2' align='left'>
1146 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1147 $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'}
1149 <tr><td colspan='2'><hr></td></tr>
1150 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}:</td>
1151 <td nowrap='nowrap'><input type='file' name='FH' size='32' /></td></tr>
1152 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
1153 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td></tr>
1155 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td></tr>
1156 <tr><td class='base' colspan='2' align='left'>
1157 <img src='/blob.gif' alt='*' /> $Lang ::tr{'required field'}</td></tr>
1161 & Header
:: closebox
();
1162 & Header
:: closebigbox
();
1163 & Header
:: closepage
();
1168 system ( '/usr/local/bin/ipsecctrl' , 'S' );
1173 ### Export PKCS12 file to browser
1175 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
1176 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1177 print "Content-Type: application/force-download \n " ;
1178 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
1179 print "Content-Type: application/octet-stream \r\n\r\n " ;
1180 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12` ;
1183 # Export Apple profile to browser
1184 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download apple profile' }) {
1185 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1186 my $key = $cgiparams { 'KEY' };
1188 # Create a UUID generator
1189 my $uuid = Data
:: UUID
-> new ();
1191 my $uuid1 = $uuid -> create_str ();
1192 my $uuid2 = $uuid -> create_str ();
1195 my $cert_uuid = $uuid -> create_str ();
1197 # Read and encode certificate
1198 if ( $confighash { $key }[ 4 ] eq "cert" ) {
1199 my $cert_path = "${General::swroot}/certs/ $confighash { $key }[1].p12" ;
1201 # Read certificate and encode it into Base64
1202 open ( CERT
, "<${cert_path}" );
1203 local ($/) = undef ; # slurp
1204 $cert = MIME
:: Base64
:: encode_base64
(< CERT
>);
1208 print "Content-Type: application/octet-stream \n " ;
1209 print "Content-Disposition: attachment; filename=" . $confighash { $key }[ 1 ] . ".mobileconfig \n " ;
1210 print " \n " ; # end headers
1212 print "<!DOCTYPE plist PUBLIC \" -//Apple//DTD PLIST 1.0//EN \" \" http://www.apple.com/DTDs/PropertyList-1.0.dtd \" > \n " ;
1213 print "<plist version= \" 1.0 \" > \n " ;
1215 print " <key>PayloadDisplayName</key> \n " ;
1216 print " <string> $confighash { $key }[1]</string> \n " ;
1217 print " <key>PayloadIdentifier</key> \n " ;
1218 print " <string> $confighash { $key }[1]</string> \n " ;
1219 print " <key>PayloadUUID</key> \n " ;
1220 print " <string>${uuid1}</string> \n " ;
1221 print " <key>PayloadType</key> \n " ;
1222 print " <string>Configuration</string> \n " ;
1223 print " <key>PayloadVersion</key> \n " ;
1224 print " <integer>1</integer> \n " ;
1225 print " <key>PayloadContent</key> \n " ;
1228 print " <key>PayloadIdentifier</key> \n " ;
1229 print " <string>org.example.vpn1.conf1</string> \n " ;
1230 print " <key>PayloadUUID</key> \n " ;
1231 print " <string>${uuid2}</string> \n " ;
1232 print " <key>PayloadType</key> \n " ;
1233 print " <string>com.apple.vpn.managed</string> \n " ;
1234 print " <key>PayloadVersion</key> \n " ;
1235 print " <integer>1</integer> \n " ;
1236 print " <key>UserDefinedName</key> \n " ;
1237 print " <string> $confighash { $key }[1]</string> \n " ;
1238 print " <key>VPNType</key> \n " ;
1239 print " <string>IKEv2</string> \n " ;
1240 print " <key>IKEv2</key> \n " ;
1242 print " <key>RemoteAddress</key> \n " ;
1243 print " <string>18.206.152.26</string> \n " ;
1246 if ( $confighash { $key }[ 9 ]) {
1247 print " <key>LocalIdentifier</key> \n " ;
1248 print " <string> $confighash { $key }[9]</string> \n " ;
1252 if ( $confighash { $key }[ 7 ]) {
1253 print " <key>RemoteIdentifier</key> \n " ;
1254 print " <string> $confighash { $key }[7]</string> \n " ;
1257 if ( $confighash { $key }[ 4 ] eq "cert" ) {
1258 print " <key>AuthenticationMethod</key> \n " ;
1259 print " <string>Certificate</string> \n " ;
1261 print " <key>PayloadCertificateUUID</key> \n " ;
1262 print " <string>${cert_uuid}</string> \n " ;
1264 print " <key>AuthenticationMethod</key> \n " ;
1265 print " <string>SharedSecret</string> \n " ;
1266 print " <key>SharedSecret</key> \n " ;
1267 print " <string> $confighash { $key }[5]</string> \n " ;
1270 print " <key>ExtendedAuthEnabled</key> \n " ;
1271 print " <integer>0</integer> \n " ;
1275 if ( $confighash { $key }[ 4 ] eq "cert" ) {
1277 print " <key>PayloadIdentifier</key> \n " ;
1278 print " <string>org.example.vpn1.client</string> \n " ;
1279 print " <key>PayloadUUID</key> \n " ;
1280 print " <string>${cert_uuid}</string> \n " ;
1281 print " <key>PayloadType</key> \n " ;
1282 print " <string>com.apple.security.pkcs12</string> \n " ;
1283 print " <key>PayloadVersion</key> \n " ;
1284 print " <integer>1</integer> \n " ;
1285 print " <key>PayloadContent</key> \n " ;
1288 foreach ( split /\n/ ,${ cert
}) {
1296 print " </array> \n " ;
1303 ### Display certificate
1305 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
1306 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1308 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1309 & Header
:: showhttpheaders
();
1310 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1311 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1312 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'cert'}:" );
1313 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1314 $output = & Header
:: cleanhtml
( $output , "y" );
1315 print "<pre> $output </pre> \n " ;
1316 & Header
:: closebox
();
1317 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1318 & Header
:: closebigbox
();
1319 & Header
:: closepage
();
1324 ### Export Certificate to browser
1326 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
1327 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1329 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1330 print "Content-Type: application/force-download \n " ;
1331 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \n\n " ;
1332 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1337 ### Enable/Disable connection
1339 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1341 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1342 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1344 if ( $confighash { $cgiparams { 'KEY' }}) {
1345 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
1346 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
1347 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1349 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1351 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
1352 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1354 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1358 $errormessage = $Lang :: tr
{ 'invalid key' };
1362 ### Restart connection
1364 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
1365 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1366 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1368 if ( $confighash { $cgiparams { 'KEY' }}) {
1370 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
1374 $errormessage = $Lang :: tr
{ 'invalid key' };
1378 ### Remove connection
1380 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
1381 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1382 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1384 if ( $confighash { $cgiparams { 'KEY' }}) {
1385 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1386 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1387 delete $confighash { $cgiparams { 'KEY' }};
1388 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1390 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1392 $errormessage = $Lang :: tr
{ 'invalid key' };
1394 & General
:: firewall_reload
();
1396 ### Choose between adding a host-net or net-net connection
1398 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
1399 & Header
:: showhttpheaders
();
1400 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1401 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1402 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection type' });
1404 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
1405 <b> $Lang ::tr{'connection type'}:</b><br />
1407 <tr><td><input type='radio' name='TYPE' value='host' checked='checked' /></td>
1408 <td class='base'> $Lang ::tr{'host to net vpn'}</td>
1410 <td><input type='radio' name='TYPE' value='net' /></td>
1411 <td class='base'> $Lang ::tr{'net to net vpn'}</td>
1413 <td align='center' colspan='2'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td>
1418 & Header
:: closebox
();
1419 & Header
:: closebigbox
();
1420 & Header
:: closepage
();
1423 ### Adding/Editing/Saving a connection
1425 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
1426 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
1427 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
1429 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1430 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1431 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1433 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
1434 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
1435 $errormessage = $Lang :: tr
{ 'invalid key' };
1438 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
1439 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
1440 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
1441 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
1442 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
1443 $cgiparams { 'LOCAL' } = $confighash { $cgiparams { 'KEY' }}[ 6 ];
1444 $cgiparams { 'LOCAL_ID' } = $confighash { $cgiparams { 'KEY' }}[ 7 ];
1445 my @local_subnets = split ( "," , $confighash { $cgiparams { 'KEY' }}[ 8 ]);
1446 $cgiparams { 'LOCAL_SUBNET' } = join ( /\|/ , @local_subnets );
1447 $cgiparams { 'REMOTE_ID' } = $confighash { $cgiparams { 'KEY' }}[ 9 ];
1448 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
1449 my @remote_subnets = split ( "," , $confighash { $cgiparams { 'KEY' }}[ 11 ]);
1450 $cgiparams { 'REMOTE_SUBNET' } = join ( /\|/ , @remote_subnets );
1451 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
1452 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
1453 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
1454 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
1455 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
1456 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
1457 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
1458 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
1459 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
1460 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
1461 if ( $cgiparams { 'ESP_GROUPTYPE' } eq "" ) {
1462 $cgiparams { 'ESP_GROUPTYPE' } = $cgiparams { 'IKE_GROUPTYPE' };
1464 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
1465 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
1466 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
1467 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
1468 $cgiparams { 'DPD_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
1469 $cgiparams { 'DPD_DELAY' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
1470 $cgiparams { 'FORCE_MOBIKE' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
1471 $cgiparams { 'START_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 33 ];
1472 $cgiparams { 'INACTIVITY_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 34 ];
1473 $cgiparams { 'MODE' } = $confighash { $cgiparams { 'KEY' }}[ 35 ];
1474 $cgiparams { 'INTERFACE_MODE' } = $confighash { $cgiparams { 'KEY' }}[ 36 ];
1475 $cgiparams { 'INTERFACE_ADDRESS' } = $confighash { $cgiparams { 'KEY' }}[ 37 ];
1476 $cgiparams { 'INTERFACE_MTU' } = $confighash { $cgiparams { 'KEY' }}[ 38 ];
1478 if (! $cgiparams { 'DPD_DELAY' }) {
1479 $cgiparams { 'DPD_DELAY' } = 30 ;
1482 if (! $cgiparams { 'DPD_TIMEOUT' }) {
1483 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
1486 if ( $cgiparams { 'INACTIVITY_TIMEOUT' } eq "" ) {
1487 $cgiparams { 'INACTIVITY_TIMEOUT' } = 900 ;
1490 if ( $cgiparams { 'MODE' } eq "" ) {
1491 $cgiparams { 'MODE' } = "tunnel" ;
1494 if ( $cgiparams { 'INTERFACE_MTU' } eq "" ) {
1495 $cgiparams { 'INTERFACE_MTU' } = 1500 ;
1498 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
1499 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
1500 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
1501 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
1505 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
1506 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
1510 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
1511 $errormessage = $Lang :: tr
{ 'name is invalid' };
1515 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
1516 $errormessage = $Lang :: tr
{ 'name too long' };
1520 # Check if there is no other entry with this name
1521 if (! $cgiparams { 'KEY' }) { #only for add
1522 foreach my $key ( keys %confighash ) {
1523 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
1524 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
1530 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! $cgiparams { 'REMOTE' })) {
1531 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1535 if ( $cgiparams { 'LOCAL' }) {
1536 if (( $cgiparams { 'LOCAL' } ne "" ) && (!& General
:: validip
( $cgiparams { 'LOCAL' }))) {
1537 $errormessage = $Lang :: tr
{ 'invalid input for local ip address' };
1542 if ( $cgiparams { 'REMOTE' }) {
1543 if (( $cgiparams { 'REMOTE' } ne ' %any ' ) && (! & General
:: validip
( $cgiparams { 'REMOTE' }))) {
1544 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
1545 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1548 if (& valid_dns_host
( $cgiparams { 'REMOTE' })) {
1549 $warnmessage = " $Lang ::tr{'check vpn lr'} $cgiparams {'REMOTE'}. $Lang ::tr{'dns check failed'}" ;
1555 my @local_subnets = split ( "," , $cgiparams { 'LOCAL_SUBNET' });
1556 foreach my $subnet ( @local_subnets ) {
1557 unless (& Network
:: check_subnet
( $subnet )) {
1558 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
1563 # Allow only one roadwarrior/psk without remote IP-address
1564 if ( $cgiparams { 'REMOTE' } eq '' && $cgiparams { 'AUTH' } eq 'psk' ) {
1565 foreach my $key ( keys %confighash ) {
1566 if ( ( $cgiparams { 'KEY' } ne $key ) &&
1567 ( $confighash { $key }[ 4 ] eq 'psk' ) &&
1568 ( $confighash { $key }[ 10 ] eq '' ) ) {
1569 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
1575 if ( $cgiparams { 'TYPE' } eq 'net' ) {
1576 my @remote_subnets = split ( "," , $cgiparams { 'REMOTE_SUBNET' });
1577 foreach my $subnet ( @remote_subnets ) {
1578 unless (& Network
:: check_subnet
( $subnet )) {
1579 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
1584 if ( $cgiparams { 'MODE' } !~ /^(tunnel|transport)$/ ) {
1585 $errormessage = $Lang :: tr
{ 'invalid input for mode' };
1589 if ( $cgiparams { 'INTERFACE_MODE' } !~ /^(|gre|vti)$/ ) {
1590 $errormessage = $Lang :: tr
{ 'invalid input for interface mode' };
1594 if (( $cgiparams { 'INTERFACE_MODE' } eq "vti" ) && ( $cgiparams { 'MODE' } eq "transport" )) {
1595 $errormessage = $Lang :: tr
{ 'transport mode does not support vti' };
1599 if (( $cgiparams { 'INTERFACE_MODE' } ne "" ) && !& Network
:: check_subnet
( $cgiparams { 'INTERFACE_ADDRESS' })) {
1600 $errormessage = $Lang :: tr
{ 'invalid input for interface address' };
1604 if ( $cgiparams { 'INTERFACE_MTU' } !~ /^\d+$/ ) {
1605 $errormessage = $Lang :: tr
{ 'invalid input for interface mtu' };
1610 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
1611 $errormessage = $Lang :: tr
{ 'invalid input' };
1614 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
1615 $errormessage = $Lang :: tr
{ 'invalid input' };
1619 # Allow nothing or a string (DN,FDQN,) beginning with @
1620 # with no comma but slashes between RID eg @O=FR/C=Paris/OU=myhome/CN=franck
1621 if ( ( $cgiparams { 'LOCAL_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1622 ( $cgiparams { 'REMOTE_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1623 (( $cgiparams { 'REMOTE_ID' } eq $cgiparams { 'LOCAL_ID' }) && ( $cgiparams { 'LOCAL_ID' } ne '' ))
1625 $errormessage = $Lang :: tr
{ 'invalid local-remote id' } . '<br />' .
1626 'DER_ASN1_DN: @c =FR/ou=Paris/ou=Home/cn=*<br />' .
1627 'FQDN: @ipfire .org<br />' .
1628 'USER_FQDN: info @ipfire .org<br />' .
1629 'IPV4_ADDR: 123.123.123.123' ;
1632 # If Auth is DN, verify existance of Remote ID.
1633 if ( $cgiparams { 'REMOTE_ID' } eq '' && (
1634 $cgiparams { 'AUTH' } eq 'auth-dn' || # while creation
1635 $confighash { $cgiparams { 'KEY' }}[ 2 ] eq ' %auth -dn' )){ # while editing
1636 $errormessage = $Lang :: tr
{ 'vpn missing remote id' };
1640 if ( $cgiparams { 'TYPE' } eq 'net' ){
1641 $warnmessage =& General
:: checksubnets
( '' , $cgiparams { 'REMOTE_SUBNET' }, 'ipsec' );
1642 if ( $warnmessage ne '' ){
1643 $warnmessage = $Lang :: tr
{ 'remote subnet' }. " ( $cgiparams {'REMOTE_SUBNET'}) <br>" . $warnmessage ;
1647 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1648 if (! length ( $cgiparams { 'PSK' }) ) {
1649 $errormessage = $Lang :: tr
{ 'pre-shared key is too short' };
1652 if ( $cgiparams { 'PSK' } =~ /'/ ) {
1653 $cgiparams { 'PSK' } =~ tr/'/ / ;
1654 $errormessage = $Lang :: tr
{ 'invalid characters found in pre-shared key' };
1657 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
1658 if ( $cgiparams { 'KEY' }) {
1659 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1662 unless ( ref ( $cgiparams { 'FH' })) {
1663 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1667 # Move uploaded certificate request to a temporary file
1668 ( my $fh , my $filename ) = tempfile
( );
1669 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1674 # Sign the certificate request
1675 & General
:: log ( "ipsec" , "Signing your cert $cgiparams {'NAME'}..." );
1676 my $opt = " ca -md sha256 -days 825" ;
1677 $opt .= " -batch -notext" ;
1678 $opt .= " -in $filename " ;
1679 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1681 if ( $errormessage = & callssl
( $opt ) ) {
1683 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1684 & cleanssldatabase
();
1688 & cleanssldatabase
();
1691 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1692 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1693 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1696 } elsif ( $cgiparams { 'AUTH' } eq 'pkcs12' ) {
1697 & General
:: log ( "ipsec" , "Importing from p12..." );
1699 unless ( ref ( $cgiparams { 'FH' })) {
1700 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1701 goto ROOTCERT_ERROR
;
1704 # Move uploaded certificate request to a temporary file
1705 ( my $fh , my $filename ) = tempfile
( );
1706 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1708 goto ROOTCERT_ERROR
;
1711 # Extract the CA certificate from the file
1712 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
1713 if ( open ( STDIN
, "-|" )) {
1714 my $opt = " pkcs12 -cacerts -nokeys" ;
1715 $opt .= " -in $filename " ;
1716 $opt .= " -out /tmp/newcacert" ;
1717 $errormessage = & callssl
( $opt );
1719 print " $cgiparams {'P12_PASS'} \n " ;
1723 # Extract the Host certificate from the file
1724 if (! $errormessage ) {
1725 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
1726 if ( open ( STDIN
, "-|" )) {
1727 my $opt = " pkcs12 -clcerts -nokeys" ;
1728 $opt .= " -in $filename " ;
1729 $opt .= " -out /tmp/newhostcert" ;
1730 $errormessage = & callssl
( $opt );
1732 print " $cgiparams {'P12_PASS'} \n " ;
1737 if (! $errormessage ) {
1738 & General
:: log ( "ipsec" , "Moving cacert..." );
1739 #If CA have new subject, add it to our list of CA
1740 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( '/tmp/newcacert' ));
1742 foreach my $x ( keys %cahash ) {
1743 $casubject = '' if ( $cahash { $x }[ 1 ] eq $casubject );
1744 unshift ( @names , $cahash { $x }[ 0 ]);
1746 if ( $casubject ) { # a new one!
1747 my $temp = `/usr/bin/openssl x509 -text -in /tmp/newcacert` ;
1748 if ( $temp !~ /CA:TRUE/i ) {
1749 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
1751 #compute a name for it
1753 while ( grep ( /Imported-$idx/ , @names ) ) { $idx ++};
1754 $cgiparams { 'CA_NAME' }= "Imported- $idx " ;
1755 $cgiparams { 'CERT_NAME' }=& Header
:: cleanhtml
( getCNfromcert
( '/tmp/newhostcert' ));
1756 move
( "/tmp/newcacert" , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1757 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1758 if (! $errormessage ) {
1759 my $key = & General
:: findhasharraykey
( \
%cahash );
1760 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
1761 $cahash { $key }[ 1 ] = $casubject ;
1762 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1763 system ( '/usr/local/bin/ipsecctrl' , 'R' );
1768 if (! $errormessage ) {
1769 & General
:: log ( "ipsec" , "Moving host cert..." );
1770 move
( "/tmp/newhostcert" , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1771 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1776 unlink ( '/tmp/newcacert' );
1777 unlink ( '/tmp/newhostcert' );
1778 if ( $errormessage ) {
1779 unlink ( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1780 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1783 & General
:: log ( "ipsec" , "p12 import completed!" );
1784 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
1785 if ( $cgiparams { 'KEY' }) {
1786 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1789 unless ( ref ( $cgiparams { 'FH' })) {
1790 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1793 # Move uploaded certificate to a temporary file
1794 ( my $fh , my $filename ) = tempfile
( );
1795 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1800 # Verify the certificate has a valid CA and move it
1801 & General
:: log ( "ipsec" , "Validating imported cert against our known CA..." );
1802 my $validca = 1 ; #assume ok
1803 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/cacert.pem $filename ` ;
1804 if ( $test !~ /: OK/ ) {
1806 foreach my $key ( keys %cahash ) {
1807 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $key }[0]cert.pem $filename ` ;
1808 if ( $test =~ /: OK/ ) {
1815 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
1819 move
( $filename , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1821 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1827 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1828 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1829 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1830 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1833 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
1834 if ( $cgiparams { 'KEY' }) {
1835 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1838 # Validate input since the form was submitted
1839 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
1840 $errormessage = $Lang :: tr
{ 'name too long' };
1843 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1844 $errormessage = $Lang :: tr
{ 'invalid input for name' };
1847 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
1848 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1851 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
1852 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1855 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1856 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1859 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
1860 $errormessage = $Lang :: tr
{ 'organization too long' };
1863 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1864 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1867 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1868 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1871 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1872 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1875 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1876 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1879 #the exact syntax is a list comma separated of
1880 # email:any-validemail
1881 # URI: a uniform resource indicator
1882 # DNS: a DNS domain name
1883 # RID: a registered OBJECT IDENTIFIER
1885 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
1887 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
1888 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
1892 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
1893 $errormessage = $Lang :: tr
{ 'password too short' };
1896 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
1897 $errormessage = $Lang :: tr
{ 'passwords do not match' };
1901 # Replace empty strings with a .
1902 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
1903 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
1904 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
1906 # Create the Client certificate request
1907 & General
:: log ( "ipsec" , "Creating a cert..." );
1909 if ( open ( STDIN
, "-|" )) {
1910 my $opt = " req -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
1911 $opt .= " -newkey rsa:2048" ;
1912 $opt .= " -keyout ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1913 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1915 if ( $errormessage = & callssl
( $opt ) ) {
1916 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1917 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1921 print " $cgiparams {'CERT_COUNTRY'} \n " ;
1924 print " $cgiparams {'CERT_ORGANIZATION'} \n " ;
1926 print " $cgiparams {'CERT_NAME'} \n " ;
1927 print " $cgiparams {'CERT_EMAIL'} \n " ;
1933 # Sign the client certificate request
1934 & General
:: log ( "ipsec" , "Signing the cert $cgiparams {'NAME'}..." );
1936 #No easy way for specifying the contain of subjectAltName without writing a config file...
1937 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1939 basicConstraints=CA:FALSE
1940 nsComment="OpenSSL Generated Certificate"
1941 subjectKeyIdentifier=hash
1942 extendedKeyUsage=clientAuth
1943 authorityKeyIdentifier=keyid,issuer:always
1946 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1949 my $opt = " ca -md sha256 -days 825 -batch -notext" ;
1950 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1951 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1952 $opt .= " -extfile $v3extname " ;
1954 if ( $errormessage = & callssl
( $opt ) ) {
1955 unlink ( $v3extname );
1956 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1957 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1958 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1959 & cleanssldatabase
();
1962 unlink ( $v3extname );
1963 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1964 & cleanssldatabase
();
1967 # Create the pkcs12 file
1968 & General
:: log ( "ipsec" , "Packing a pkcs12 file..." );
1969 $opt = " pkcs12 -export" ;
1970 $opt .= " -inkey ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1971 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1972 $opt .= " -name \" $cgiparams {'NAME'} \" " ;
1973 $opt .= " -passout pass: $cgiparams {'CERT_PASS1'}" ;
1974 $opt .= " -certfile ${General::swroot}/ca/cacert.pem" ;
1975 $opt .= " -caname \" $vpnsettings {'ROOTCERT_ORGANIZATION'} CA \" " ;
1976 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}.p12" ;
1978 if ( $errormessage = & callssl
( $opt ) ) {
1979 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1980 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1981 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}.p12" );
1984 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1986 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
1987 ; # Nothing, just editing
1988 } elsif ( $cgiparams { 'AUTH' } eq 'auth-dn' ) {
1989 $cgiparams { 'CERT_NAME' } = ' %auth -dn' ; # a special value saying 'no cert file'
1991 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
1995 # 1)Error message here is not accurate.
1996 # 2)Test is superfluous, openswan can reference same cert multiple times
1997 # 3)Present since initial version (1.3.2.11), it isn't a bug correction
1998 # Check if there is no other entry with this certificate name
1999 #if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk') && ($cgiparams{'AUTH'} ne 'auth-dn')) {
2000 # foreach my $key (keys %confighash) {
2001 # if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) {
2002 # $errormessage = $Lang::tr{'a connection with this common name already exists'};
2003 # goto VPNCONF_ERROR;
2009 my $key = $cgiparams { 'KEY' };
2011 $key = & General
:: findhasharraykey
( \
%confighash );
2012 foreach my $i ( 0 .. 38 ) { $confighash { $key }[ $i ] = "" ;}
2014 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
2015 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
2016 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
2017 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
2019 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
2020 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
2021 $confighash { $key }[ 4 ] = 'psk' ;
2022 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
2024 $confighash { $key }[ 4 ] = 'cert' ;
2026 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2027 my @remote_subnets = split ( "," , $cgiparams { 'REMOTE_SUBNET' });
2028 $confighash { $key }[ 11 ] = join ( '|' , @remote_subnets );
2030 $confighash { $key }[ 6 ] = $cgiparams { 'LOCAL' };
2031 $confighash { $key }[ 7 ] = $cgiparams { 'LOCAL_ID' };
2032 my @local_subnets = split ( "," , $cgiparams { 'LOCAL_SUBNET' });
2033 $confighash { $key }[ 8 ] = join ( '|' , @local_subnets );
2034 $confighash { $key }[ 9 ] = $cgiparams { 'REMOTE_ID' };
2035 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
2036 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
2037 $confighash { $key }[ 26 ] = "" ; # Formerly INTERFACE
2038 $confighash { $key }[ 27 ] = $cgiparams { 'DPD_ACTION' };
2039 $confighash { $key }[ 29 ] = $cgiparams { 'IKE_VERSION' };
2041 # don't forget advanced value
2042 $confighash { $key }[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
2043 $confighash { $key }[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
2044 $confighash { $key }[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
2045 $confighash { $key }[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
2046 $confighash { $key }[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
2047 $confighash { $key }[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
2048 $confighash { $key }[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
2049 $confighash { $key }[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
2050 $confighash { $key }[ 12 ] = 'off' ; # $cgiparams{'AGGRMODE'};
2051 $confighash { $key }[ 13 ] = $cgiparams { 'COMPRESSION' };
2052 $confighash { $key }[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
2053 $confighash { $key }[ 28 ] = $cgiparams { 'PFS' };
2054 $confighash { $key }[ 30 ] = $cgiparams { 'DPD_TIMEOUT' };
2055 $confighash { $key }[ 31 ] = $cgiparams { 'DPD_DELAY' };
2056 $confighash { $key }[ 32 ] = $cgiparams { 'FORCE_MOBIKE' };
2057 $confighash { $key }[ 33 ] = $cgiparams { 'START_ACTION' };
2058 $confighash { $key }[ 34 ] = $cgiparams { 'INACTIVITY_TIMEOUT' };
2059 $confighash { $key }[ 35 ] = $cgiparams { 'MODE' };
2060 $confighash { $key }[ 36 ] = $cgiparams { 'INTERFACE_MODE' };
2061 $confighash { $key }[ 37 ] = $cgiparams { 'INTERFACE_ADDRESS' };
2062 $confighash { $key }[ 38 ] = $cgiparams { 'INTERFACE_MTU' };
2064 # free unused fields!
2065 $confighash { $key }[ 15 ] = 'off' ;
2067 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2070 system ( '/usr/local/bin/ipsecctrl' , 'S' , $key );
2073 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
2074 $cgiparams { 'KEY' } = $key ;
2075 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
2078 } else { # add new connection
2079 $cgiparams { 'ENABLED' } = 'on' ;
2080 if ( ! - f
"${General::swroot}/private/cakey.pem" ) {
2081 $cgiparams { 'AUTH' } = 'psk' ;
2082 } elsif ( ! - f
"${General::swroot}/ca/cacert.pem" ) {
2083 $cgiparams { 'AUTH' } = 'certfile' ;
2085 $cgiparams { 'AUTH' } = 'certgen' ;
2088 if ( $netsettings { "GREEN_NETADDRESS" } && $netsettings { "GREEN_NETMASK" }) {
2089 $cgiparams { "LOCAL_SUBNET" } = $netsettings { 'GREEN_NETADDRESS' } . "/" . $netsettings { 'GREEN_NETMASK' };
2091 $cgiparams { "LOCAL_SUBNET" } = "" ;
2093 $cgiparams { 'CERT_EMAIL' } = $vpnsettings { 'ROOTCERT_EMAIL' };
2094 $cgiparams { 'CERT_OU' } = $vpnsettings { 'ROOTCERT_OU' };
2095 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
2096 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
2097 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
2098 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
2100 # choose appropriate dpd action
2101 if ( $cgiparams { 'TYPE' } eq 'host' ) {
2102 $cgiparams { 'DPD_ACTION' } = 'clear' ;
2104 $cgiparams { 'DPD_ACTION' } = 'restart' ;
2107 if (! $cgiparams { 'DPD_DELAY' }) {
2108 $cgiparams { 'DPD_DELAY' } = 30 ;
2111 if (! $cgiparams { 'DPD_TIMEOUT' }) {
2112 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
2115 if (! $cgiparams { 'FORCE_MOBIKE' }) {
2116 $cgiparams { 'FORCE_MOBIKE' } = 'no' ;
2119 # Default IKE Version to v2
2120 if (! $cgiparams { 'IKE_VERSION' }) {
2121 $cgiparams { 'IKE_VERSION' } = 'ikev2' ;
2125 $cgiparams { 'LOCAL_ID' } = '' ;
2126 $cgiparams { 'REMOTE_ID' } = '' ;
2128 #use default advanced value
2129 $cgiparams { 'IKE_ENCRYPTION' } = 'chacha20poly1305|aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128' ; #[18];
2130 $cgiparams { 'IKE_INTEGRITY' } = 'sha2_512|sha2_256' ; #[19];
2131 $cgiparams { 'IKE_GROUPTYPE' } = 'curve25519|curve448|4096|3072|2048' ; #[20];
2132 $cgiparams { 'IKE_LIFETIME' } = '3' ; #[16];
2133 $cgiparams { 'ESP_ENCRYPTION' } = 'chacha20poly1305|aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128' ; #[21];
2134 $cgiparams { 'ESP_INTEGRITY' } = 'sha2_512|sha2_256' ; #[22];
2135 $cgiparams { 'ESP_GROUPTYPE' } = 'curve25519|curve448|4096|3072|2048' ; #[23];
2136 $cgiparams { 'ESP_KEYLIFE' } = '1' ; #[17];
2137 $cgiparams { 'COMPRESSION' } = 'off' ; #[13];
2138 $cgiparams { 'ONLY_PROPOSED' } = 'on' ; #[24];
2139 $cgiparams { 'PFS' } = 'on' ; #[28];
2140 $cgiparams { 'INACTIVITY_TIMEOUT' } = 900 ;
2141 $cgiparams { 'MODE' } = "tunnel" ;
2142 $cgiparams { 'INTERFACE_MODE' } = "" ;
2143 $cgiparams { 'INTERFACE_ADDRESS' } = "" ;
2144 $cgiparams { 'INTERFACE_MTU' } = 1500 ;
2148 $checked { 'ENABLED' }{ 'off' } = '' ;
2149 $checked { 'ENABLED' }{ 'on' } = '' ;
2150 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = "checked='checked'" ;
2152 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
2153 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
2154 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = "checked='checked'" ;
2156 $checked { 'AUTH' }{ 'psk' } = '' ;
2157 $checked { 'AUTH' }{ 'certreq' } = '' ;
2158 $checked { 'AUTH' }{ 'certgen' } = '' ;
2159 $checked { 'AUTH' }{ 'certfile' } = '' ;
2160 $checked { 'AUTH' }{ 'pkcs12' } = '' ;
2161 $checked { 'AUTH' }{ 'auth-dn' } = '' ;
2162 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = "checked='checked'" ;
2164 $selected { 'MODE' }{ 'tunnel' } = '' ;
2165 $selected { 'MODE' }{ 'transport' } = '' ;
2166 $selected { 'MODE' }{ $cgiparams { 'MODE' }} = "selected='selected'" ;
2168 $selected { 'INTERFACE_MODE' }{ '' } = '' ;
2169 $selected { 'INTERFACE_MODE' }{ 'gre' } = '' ;
2170 $selected { 'INTERFACE_MODE' }{ 'vti' } = '' ;
2171 $selected { 'INTERFACE_MODE' }{ $cgiparams { 'INTERFACE_MODE' }} = "selected='selected'" ;
2173 $selected { 'LOCAL' }{ '' } = '' ;
2174 foreach my $alias ( sort keys %aliases ) {
2175 my $address = $aliases { $alias }{ 'IPT' };
2177 $selected { 'LOCAL' }{ $address } = '' ;
2179 $selected { 'LOCAL' }{ $cgiparams { 'LOCAL' }} = "selected='selected'" ;
2181 & Header
:: showhttpheaders
();
2182 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
2183 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2184 if ( $errormessage ) {
2185 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2186 print "<class name='base'> $errormessage " ;
2187 print " </class>" ;
2188 & Header
:: closebox
();
2192 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'warning messages'}:" );
2193 print "<class name='base'> $warnmessage " ;
2194 print " </class>" ;
2195 & Header
:: closebox
();
2198 print "<form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>" ;
2200 <input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />
2201 <input type='hidden' name='IKE_VERSION' value=' $cgiparams {'IKE_VERSION'}' />
2202 <input type='hidden' name='IKE_ENCRYPTION' value=' $cgiparams {'IKE_ENCRYPTION'}' />
2203 <input type='hidden' name='IKE_INTEGRITY' value=' $cgiparams {'IKE_INTEGRITY'}' />
2204 <input type='hidden' name='IKE_GROUPTYPE' value=' $cgiparams {'IKE_GROUPTYPE'}' />
2205 <input type='hidden' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' />
2206 <input type='hidden' name='ESP_ENCRYPTION' value=' $cgiparams {'ESP_ENCRYPTION'}' />
2207 <input type='hidden' name='ESP_INTEGRITY' value=' $cgiparams {'ESP_INTEGRITY'}' />
2208 <input type='hidden' name='ESP_GROUPTYPE' value=' $cgiparams {'ESP_GROUPTYPE'}' />
2209 <input type='hidden' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' />
2210 <input type='hidden' name='COMPRESSION' value=' $cgiparams {'COMPRESSION'}' />
2211 <input type='hidden' name='ONLY_PROPOSED' value=' $cgiparams {'ONLY_PROPOSED'}' />
2212 <input type='hidden' name='PFS' value=' $cgiparams {'PFS'}' />
2213 <input type='hidden' name='DPD_ACTION' value=' $cgiparams {'DPD_ACTION'}' />
2214 <input type='hidden' name='DPD_DELAY' value=' $cgiparams {'DPD_DELAY'}' />
2215 <input type='hidden' name='DPD_TIMEOUT' value=' $cgiparams {'DPD_TIMEOUT'}' />
2216 <input type='hidden' name='FORCE_MOBIKE' value=' $cgiparams {'FORCE_MOBIKE'}' />
2217 <input type='hidden' name='START_ACTION' value=' $cgiparams {'START_ACTION'}' />
2218 <input type='hidden' name='INACTIVITY_TIMEOUT' value=' $cgiparams {'INACTIVITY_TIMEOUT'}' />
2221 if ( $cgiparams { 'KEY' }) {
2222 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
2223 print "<input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' />" ;
2224 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
2227 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'connection'}: $cgiparams {'NAME'}" );
2228 print "<table width='100%'>" ;
2229 if (! $cgiparams { 'KEY' }) {
2232 <td width='20%'> $Lang ::tr{'name'}: <img src='/blob.gif' alt='*' /></td>
2234 <input type='text' name='NAME' value=' $cgiparams {'NAME'}' size='25' />
2236 <td colspan="2"></td>
2243 if ( $cgiparams { 'TYPE' } eq 'host' ) {
2244 $disabled = "disabled='disabled'" ;
2245 } elsif ( $cgiparams { 'TYPE' } eq 'net' ) {
2246 $blob = "<img src='/blob.gif' alt='*' />" ;
2249 my @local_subnets = split ( /\|/ , $cgiparams { 'LOCAL_SUBNET' });
2250 my $local_subnets = join ( "," , @local_subnets );
2252 my @remote_subnets = split ( /\|/ , $cgiparams { 'REMOTE_SUBNET' });
2253 my $remote_subnets = join ( "," , @remote_subnets );
2257 <td width='20%'> $Lang ::tr{'enabled'}</td>
2259 <input type='checkbox' name='ENABLED' $checked {'ENABLED'}{'on'} />
2261 <td colspan="2"></td>
2264 <td class='boldbase' width='20%'> $Lang ::tr{'local ip address'}:</td>
2266 <select name="LOCAL">
2267 <option value="" $selected {'LOCAL'}{''}>- $Lang ::tr{'default IP address'} -</option>
2270 foreach my $alias ( sort keys %aliases ) {
2271 my $address = $aliases { $alias }{ 'IPT' };
2273 <option value=" $address " $selected {'LOCAL'}{ $address }> $alias ( $address )</option>
2280 <td class='boldbase' width='20%'> $Lang ::tr{'remote host/ip'}: $blob </td>
2282 <input type='text' name='REMOTE' value=' $cgiparams {'REMOTE'}' size="25" />
2286 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'local subnet'} <img src='/blob.gif' alt='*' /></td>
2288 <input type='text' name='LOCAL_SUBNET' value=' $local_subnets ' size="25" />
2290 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'remote subnet'} $blob </td>
2292 <input $disabled type='text' name='REMOTE_SUBNET' value=' $remote_subnets ' size="25" />
2296 <td class='boldbase' width='20%'> $Lang ::tr{'vpn local id'}:</td>
2298 <input type='text' name='LOCAL_ID' value=' $cgiparams {'LOCAL_ID'}' size="25" />
2300 <td class='boldbase' width='20%'> $Lang ::tr{'vpn remote id'}:</td>
2302 <input type='text' name='REMOTE_ID' value=' $cgiparams {'REMOTE_ID'}' size="25" />
2305 <tr><td colspan="4"><br /></td></tr>
2307 <td class='boldbase' width='20%'> $Lang ::tr{'remark title'}</td>
2309 <input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' maxlength='50' size="73" />
2314 if (! $cgiparams { 'KEY' }) {
2315 print "<tr><td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked {'EDIT_ADVANCED'}{'on'} /> $Lang ::tr{'edit advanced settings when done'}</td></tr>" ;
2318 & Header
:: closebox
();
2320 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2321 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'ipsec settings' });
2323 <table width='100%'>
2326 <td class='boldbase' width='20%'> $Lang ::tr{'mode'}:</td>
2328 <select name='MODE'>
2329 <option value='tunnel' $selected {'MODE'}{'tunnel'}> $Lang ::tr{'ipsec mode tunnel'}</option>
2330 <option value='transport' $selected {'MODE'}{'transport'}> $Lang ::tr{'ipsec mode transport'}</option>
2333 <td colspan='2'></td>
2337 <td class='boldbase' width='20%'> $Lang ::tr{'interface mode'}:</td>
2339 <select name='INTERFACE_MODE'>
2340 <option value='' $selected {'INTERFACE_MODE'}{''}> $Lang ::tr{'ipsec interface mode none'}</option>
2341 <option value='gre' $selected {'INTERFACE_MODE'}{'gre'}> $Lang ::tr{'ipsec interface mode gre'}</option>
2342 <option value='vti' $selected {'INTERFACE_MODE'}{'vti'}> $Lang ::tr{'ipsec interface mode vti'}</option>
2346 <td class='boldbase' width='20%'> $Lang ::tr{'ip address'}/ $Lang ::tr{'subnet mask'}:</td>
2348 <input type="text" name="INTERFACE_ADDRESS" value=" $cgiparams {'INTERFACE_ADDRESS'}">
2353 <td class='boldbase' width='20%'> $Lang ::tr{'mtu'}:</td>
2355 <input type="number" name="INTERFACE_MTU" value=" $cgiparams {'INTERFACE_MTU'}" min="576" max="9000">
2357 <td colspan='2'></td>
2362 & Header
:: closebox
();
2365 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
2366 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2368 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2369 <tr><td class='base' width='50%'> $Lang ::tr{'use a pre-shared key'}</td>
2370 <td class='base' width='50%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td>
2375 & Header
:: closebox
();
2376 } elsif (! $cgiparams { 'KEY' }) {
2377 my $cakeydisabled = ( ! - f
"${General::swroot}/private/cakey.pem" ) ?
"disabled='disabled'" : '' ;
2378 $cgiparams { 'CERT_NAME' } = $Lang :: tr
{ 'vpn no full pki' } if ( $cakeydisabled );
2379 my $cacrtdisabled = ( ! - f
"${General::swroot}/ca/cacert.pem" ) ?
"disabled='disabled'" : '' ;
2381 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2383 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2384 <tr><td width='5%'><input type='radio' name='AUTH' value='psk' $checked {'AUTH'}{'psk'} /></td>
2385 <td class='base' width='55%'> $Lang ::tr{'use a pre-shared key'}</td>
2386 <td class='base' width='40%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td></tr>
2387 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2388 <tr><td><input type='radio' name='AUTH' value='certreq' $checked {'AUTH'}{'certreq'} $cakeydisabled /></td>
2389 <td class='base'><hr /> $Lang ::tr{'upload a certificate request'}</td>
2390 <td class='base' rowspan='3' valign='middle'><input type='file' name='FH' size='30' $cacrtdisabled /></td></tr>
2391 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td>
2392 <td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
2393 <tr><td><input type='radio' name='AUTH' value='pkcs12' $cacrtdisabled /></td>
2394 <td class='base'> $Lang ::tr{'upload p12 file'} $Lang ::tr{'pkcs12 file password'}:<input type='password' name='P12_PASS'/></td></tr>
2395 <tr><td><input type='radio' name='AUTH' value='auth-dn' $checked {'AUTH'}{'auth-dn'} $cacrtdisabled /></td>
2396 <td class='base'><hr /> $Lang ::tr{'vpn auth-dn'}</td></tr>
2397 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2398 <tr><td><input type='radio' name='AUTH' value='certgen' $checked {'AUTH'}{'certgen'} $cakeydisabled /></td>
2399 <td class='base'><hr /> $Lang ::tr{'generate a certificate'}</td><td> </td></tr>
2401 <td class='base'> $Lang ::tr{'users fullname or system hostname'}: <img src='/blob.gif' alt='*' /></td>
2402 <td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' size='32' $cakeydisabled /></td></tr>
2404 <td class='base'> $Lang ::tr{'users email'}:</td>
2405 <td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' size='32' $cakeydisabled /></td></tr>
2407 <td class='base'> $Lang ::tr{'users department'}:</td>
2408 <td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' size='32' $cakeydisabled /></td></tr>
2410 <td class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
2411 <td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' size='32' $cakeydisabled /></td></tr>
2413 <td class='base'> $Lang ::tr{'city'}:</td>
2414 <td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' size='32' $cakeydisabled /></td></tr>
2416 <td class='base'> $Lang ::tr{'state or province'}:</td>
2417 <td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' size='32' $cakeydisabled /></td></tr>
2419 <td class='base'> $Lang ::tr{'country'}:</td>
2420 <td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
2423 foreach my $country ( sort keys %{ Countries
:: countries
}) {
2424 print " \t\t\t <option value=' $Countries ::countries{ $country }'" ;
2425 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
2426 print " selected='selected'" ;
2428 print "> $country </option> \n " ;
2433 <tr><td> </td><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)</td>
2434 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' $cakeydisabled /></td></tr>
2436 <td class='base'> $Lang ::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' /></td>
2437 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
2438 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'} ( $Lang ::tr{'confirmation'}): <img src='/blob.gif' alt='*' /></td>
2439 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
2443 & Header
:: closebox
();
2446 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
2447 if ( $cgiparams { 'KEY' }) {
2448 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced'}' />" ;
2450 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
2451 & Header
:: closebigbox
();
2452 & Header
:: closepage
();
2459 ### Advanced settings
2461 if (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced' }) ||
2462 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq 'yes' )) {
2463 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
2464 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2465 if (! $confighash { $cgiparams { 'KEY' }}) {
2466 $errormessage = $Lang :: tr
{ 'invalid key' };
2470 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
2471 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2473 $errormessage = $Lang :: tr
{ 'invalid input' };
2474 goto ADVANCED_ERROR
;
2476 foreach my $val ( @temp ) {
2477 if ( $val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|chacha20poly1305|camellia(256|192|128))$/ ) {
2478 $errormessage = $Lang :: tr
{ 'invalid input' };
2479 goto ADVANCED_ERROR
;
2482 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2484 $errormessage = $Lang :: tr
{ 'invalid input' };
2485 goto ADVANCED_ERROR
;
2487 foreach my $val ( @temp ) {
2488 if ( $val !~ /^(sha2_(512|384|256)|sha|md5|aesxcbc)$/ ) {
2489 $errormessage = $Lang :: tr
{ 'invalid input' };
2490 goto ADVANCED_ERROR
;
2493 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2495 $errormessage = $Lang :: tr
{ 'invalid input' };
2496 goto ADVANCED_ERROR
;
2498 foreach my $val ( @temp ) {
2499 if ( $val !~ /^(curve25519|curve448|e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|768|1024|1536|2048|3072|4096|6144|8192)$/ ) {
2500 $errormessage = $Lang :: tr
{ 'invalid input' };
2501 goto ADVANCED_ERROR
;
2504 if ( $cgiparams { 'IKE_LIFETIME' } !~ /^\d+$/ ) {
2505 $errormessage = $Lang :: tr
{ 'invalid input for ike lifetime' };
2506 goto ADVANCED_ERROR
;
2508 if ( $cgiparams { 'IKE_LIFETIME' } < 1 || $cgiparams { 'IKE_LIFETIME' } > 24 ) {
2509 $errormessage = $Lang :: tr
{ 'ike lifetime should be between 1 and 24 hours' };
2510 goto ADVANCED_ERROR
;
2512 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2514 $errormessage = $Lang :: tr
{ 'invalid input' };
2515 goto ADVANCED_ERROR
;
2517 foreach my $val ( @temp ) {
2518 if ( $val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|chacha20poly1305|camellia(256|192|128))$/ ) {
2519 $errormessage = $Lang :: tr
{ 'invalid input' };
2520 goto ADVANCED_ERROR
;
2523 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2525 $errormessage = $Lang :: tr
{ 'invalid input' };
2526 goto ADVANCED_ERROR
;
2528 foreach my $val ( @temp ) {
2529 if ( $val !~ /^(sha2_(512|384|256)|sha1|md5|aesxcbc)$/ ) {
2530 $errormessage = $Lang :: tr
{ 'invalid input' };
2531 goto ADVANCED_ERROR
;
2534 @temp = split ( '\|' , $cgiparams { 'ESP_GROUPTYPE' });
2536 $errormessage = $Lang :: tr
{ 'invalid input' };
2537 goto ADVANCED_ERROR
;
2539 foreach my $val ( @temp ) {
2540 if ( $val !~ /^(curve25519|curve448|e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|768|1024|1536|2048|3072|4096|6144|8192|none)$/ ) {
2541 $errormessage = $Lang :: tr
{ 'invalid input' };
2542 goto ADVANCED_ERROR
;
2545 if ( $cgiparams { 'ESP_KEYLIFE' } !~ /^\d+$/ ) {
2546 $errormessage = $Lang :: tr
{ 'invalid input for esp keylife' };
2547 goto ADVANCED_ERROR
;
2549 if ( $cgiparams { 'ESP_KEYLIFE' } < 1 || $cgiparams { 'ESP_KEYLIFE' } > 24 ) {
2550 $errormessage = $Lang :: tr
{ 'esp keylife should be between 1 and 24 hours' };
2551 goto ADVANCED_ERROR
;
2554 if (( $cgiparams { 'COMPRESSION' } !~ /^(|on|off)$/ ) ||
2555 ( $cgiparams { 'FORCE_MOBIKE' } !~ /^(|on|off)$/ ) ||
2556 ( $cgiparams { 'ONLY_PROPOSED' } !~ /^(|on|off)$/ ) ||
2557 ( $cgiparams { 'PFS' } !~ /^(|on|off)$/ )) {
2558 $errormessage = $Lang :: tr
{ 'invalid input' };
2559 goto ADVANCED_ERROR
;
2562 if ( $cgiparams { 'DPD_DELAY' } !~ /^\d+$/ ) {
2563 $errormessage = $Lang :: tr
{ 'invalid input for dpd delay' };
2564 goto ADVANCED_ERROR
;
2567 if ( $cgiparams { 'DPD_TIMEOUT' } !~ /^\d+$/ ) {
2568 $errormessage = $Lang :: tr
{ 'invalid input for dpd timeout' };
2569 goto ADVANCED_ERROR
;
2572 if ( $cgiparams { 'INACTIVITY_TIMEOUT' } !~ /^\d+$/ ) {
2573 $errormessage = $Lang :: tr
{ 'invalid input for inactivity timeout' };
2574 goto ADVANCED_ERROR
;
2577 $confighash { $cgiparams { 'KEY' }}[ 29 ] = $cgiparams { 'IKE_VERSION' };
2578 $confighash { $cgiparams { 'KEY' }}[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
2579 $confighash { $cgiparams { 'KEY' }}[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
2580 $confighash { $cgiparams { 'KEY' }}[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
2581 $confighash { $cgiparams { 'KEY' }}[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
2582 $confighash { $cgiparams { 'KEY' }}[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
2583 $confighash { $cgiparams { 'KEY' }}[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
2584 $confighash { $cgiparams { 'KEY' }}[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
2585 $confighash { $cgiparams { 'KEY' }}[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
2586 $confighash { $cgiparams { 'KEY' }}[ 12 ] = 'off' ; #$cgiparams{'AGGRMODE'};
2587 $confighash { $cgiparams { 'KEY' }}[ 13 ] = $cgiparams { 'COMPRESSION' };
2588 $confighash { $cgiparams { 'KEY' }}[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
2589 $confighash { $cgiparams { 'KEY' }}[ 28 ] = $cgiparams { 'PFS' };
2590 $confighash { $cgiparams { 'KEY' }}[ 27 ] = $cgiparams { 'DPD_ACTION' };
2591 $confighash { $cgiparams { 'KEY' }}[ 30 ] = $cgiparams { 'DPD_TIMEOUT' };
2592 $confighash { $cgiparams { 'KEY' }}[ 31 ] = $cgiparams { 'DPD_DELAY' };
2593 $confighash { $cgiparams { 'KEY' }}[ 32 ] = $cgiparams { 'FORCE_MOBIKE' };
2594 $confighash { $cgiparams { 'KEY' }}[ 33 ] = $cgiparams { 'START_ACTION' };
2595 $confighash { $cgiparams { 'KEY' }}[ 34 ] = $cgiparams { 'INACTIVITY_TIMEOUT' };
2596 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2599 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
2604 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
2605 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
2606 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
2607 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
2608 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
2609 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
2610 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
2611 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
2612 if ( $cgiparams { 'ESP_GROUPTYPE' } eq "" ) {
2613 $cgiparams { 'ESP_GROUPTYPE' } = $cgiparams { 'IKE_GROUPTYPE' };
2615 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
2616 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
2617 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
2618 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
2619 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
2620 $cgiparams { 'DPD_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
2621 $cgiparams { 'DPD_DELAY' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
2622 $cgiparams { 'FORCE_MOBIKE' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
2623 $cgiparams { 'START_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 33 ];
2624 $cgiparams { 'INACTIVITY_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 34 ];
2625 $cgiparams { 'MODE' } = $confighash { $cgiparams { 'KEY' }}[ 35 ];
2626 $cgiparams { 'INTERFACE_MODE' } = $confighash { $cgiparams { 'KEY' }}[ 36 ];
2627 $cgiparams { 'INTERFACE_ADDRESS' } = $confighash { $cgiparams { 'KEY' }}[ 37 ];
2628 $cgiparams { 'INTERFACE_MTU' } = $confighash { $cgiparams { 'KEY' }}[ 38 ];
2630 if (! $cgiparams { 'DPD_DELAY' }) {
2631 $cgiparams { 'DPD_DELAY' } = 30 ;
2634 if (! $cgiparams { 'DPD_TIMEOUT' }) {
2635 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
2638 if (! $cgiparams { 'START_ACTION' }) {
2639 $cgiparams { 'START_ACTION' } = "start" ;
2642 if ( $cgiparams { 'INACTIVITY_TIMEOUT' } eq "" ) {
2643 $cgiparams { 'INACTIVITY_TIMEOUT' } = 900 ; # 15 min
2646 if ( $cgiparams { 'MODE' } eq "" ) {
2647 $cgiparams { 'MODE' } = "tunnel" ;
2652 $checked { 'IKE_ENCRYPTION' }{ 'chacha20poly1305' } = '' ;
2653 $checked { 'IKE_ENCRYPTION' }{ 'aes256' } = '' ;
2654 $checked { 'IKE_ENCRYPTION' }{ 'aes192' } = '' ;
2655 $checked { 'IKE_ENCRYPTION' }{ 'aes128' } = '' ;
2656 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm128' } = '' ;
2657 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm128' } = '' ;
2658 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm128' } = '' ;
2659 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm96' } = '' ;
2660 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm96' } = '' ;
2661 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm96' } = '' ;
2662 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm64' } = '' ;
2663 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm64' } = '' ;
2664 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm64' } = '' ;
2665 $checked { 'IKE_ENCRYPTION' }{ '3des' } = '' ;
2666 $checked { 'IKE_ENCRYPTION' }{ 'camellia256' } = '' ;
2667 $checked { 'IKE_ENCRYPTION' }{ 'camellia192' } = '' ;
2668 $checked { 'IKE_ENCRYPTION' }{ 'camellia128' } = '' ;
2669 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2670 foreach my $key ( @temp ) { $checked { 'IKE_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2671 $checked { 'IKE_INTEGRITY' }{ 'sha2_512' } = '' ;
2672 $checked { 'IKE_INTEGRITY' }{ 'sha2_384' } = '' ;
2673 $checked { 'IKE_INTEGRITY' }{ 'sha2_256' } = '' ;
2674 $checked { 'IKE_INTEGRITY' }{ 'sha' } = '' ;
2675 $checked { 'IKE_INTEGRITY' }{ 'md5' } = '' ;
2676 $checked { 'IKE_INTEGRITY' }{ 'aesxcbc' } = '' ;
2677 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2678 foreach my $key ( @temp ) { $checked { 'IKE_INTEGRITY' }{ $key } = "selected='selected'" ; }
2679 $checked { 'IKE_GROUPTYPE' }{ 'curve25519' } = '' ;
2680 $checked { 'IKE_GROUPTYPE' }{ 'curve448' } = '' ;
2681 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2682 $checked { 'IKE_GROUPTYPE' }{ '1024' } = '' ;
2683 $checked { 'IKE_GROUPTYPE' }{ '1536' } = '' ;
2684 $checked { 'IKE_GROUPTYPE' }{ '2048' } = '' ;
2685 $checked { 'IKE_GROUPTYPE' }{ '3072' } = '' ;
2686 $checked { 'IKE_GROUPTYPE' }{ '4096' } = '' ;
2687 $checked { 'IKE_GROUPTYPE' }{ '6144' } = '' ;
2688 $checked { 'IKE_GROUPTYPE' }{ '8192' } = '' ;
2689 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2690 foreach my $key ( @temp ) { $checked { 'IKE_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2692 $checked { 'ESP_ENCRYPTION' }{ 'chacha20poly1305' } = '' ;
2693 $checked { 'ESP_ENCRYPTION' }{ 'aes256' } = '' ;
2694 $checked { 'ESP_ENCRYPTION' }{ 'aes192' } = '' ;
2695 $checked { 'ESP_ENCRYPTION' }{ 'aes128' } = '' ;
2696 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm128' } = '' ;
2697 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm128' } = '' ;
2698 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm128' } = '' ;
2699 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm96' } = '' ;
2700 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm96' } = '' ;
2701 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm96' } = '' ;
2702 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm64' } = '' ;
2703 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm64' } = '' ;
2704 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm64' } = '' ;
2705 $checked { 'ESP_ENCRYPTION' }{ '3des' } = '' ;
2706 $checked { 'ESP_ENCRYPTION' }{ 'camellia256' } = '' ;
2707 $checked { 'ESP_ENCRYPTION' }{ 'camellia192' } = '' ;
2708 $checked { 'ESP_ENCRYPTION' }{ 'camellia128' } = '' ;
2709 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2710 foreach my $key ( @temp ) { $checked { 'ESP_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2711 $checked { 'ESP_INTEGRITY' }{ 'sha2_512' } = '' ;
2712 $checked { 'ESP_INTEGRITY' }{ 'sha2_384' } = '' ;
2713 $checked { 'ESP_INTEGRITY' }{ 'sha2_256' } = '' ;
2714 $checked { 'ESP_INTEGRITY' }{ 'sha1' } = '' ;
2715 $checked { 'ESP_INTEGRITY' }{ 'md5' } = '' ;
2716 $checked { 'ESP_INTEGRITY' }{ 'aesxcbc' } = '' ;
2717 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2718 foreach my $key ( @temp ) { $checked { 'ESP_INTEGRITY' }{ $key } = "selected='selected'" ; }
2719 $checked { 'ESP_GROUPTYPE' }{ 'curve25519' } = '' ;
2720 $checked { 'ESP_GROUPTYPE' }{ 'curve448' } = '' ;
2721 $checked { 'ESP_GROUPTYPE' }{ '768' } = '' ;
2722 $checked { 'ESP_GROUPTYPE' }{ '1024' } = '' ;
2723 $checked { 'ESP_GROUPTYPE' }{ '1536' } = '' ;
2724 $checked { 'ESP_GROUPTYPE' }{ '2048' } = '' ;
2725 $checked { 'ESP_GROUPTYPE' }{ '3072' } = '' ;
2726 $checked { 'ESP_GROUPTYPE' }{ '4096' } = '' ;
2727 $checked { 'ESP_GROUPTYPE' }{ '6144' } = '' ;
2728 $checked { 'ESP_GROUPTYPE' }{ '8192' } = '' ;
2729 $checked { 'ESP_GROUPTYPE' }{ 'none' } = '' ;
2730 @temp = split ( '\|' , $cgiparams { 'ESP_GROUPTYPE' });
2731 foreach my $key ( @temp ) { $checked { 'ESP_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2733 $checked { 'COMPRESSION' } = $cgiparams { 'COMPRESSION' } eq 'on' ?
"checked='checked'" : '' ;
2734 $checked { 'FORCE_MOBIKE' } = $cgiparams { 'FORCE_MOBIKE' } eq 'on' ?
"checked='checked'" : '' ;
2735 $checked { 'ONLY_PROPOSED' } = $cgiparams { 'ONLY_PROPOSED' } eq 'on' ?
"checked='checked'" : '' ;
2736 $checked { 'PFS' } = $cgiparams { 'PFS' } eq 'on' ?
"checked='checked'" : '' ;
2738 $selected { 'IKE_VERSION' }{ 'ikev1' } = '' ;
2739 $selected { 'IKE_VERSION' }{ 'ikev2' } = '' ;
2740 $selected { 'IKE_VERSION' }{ $cgiparams { 'IKE_VERSION' }} = "selected='selected'" ;
2742 $selected { 'DPD_ACTION' }{ 'clear' } = '' ;
2743 $selected { 'DPD_ACTION' }{ 'hold' } = '' ;
2744 $selected { 'DPD_ACTION' }{ 'restart' } = '' ;
2745 $selected { 'DPD_ACTION' }{ 'none' } = '' ;
2746 $selected { 'DPD_ACTION' }{ $cgiparams { 'DPD_ACTION' }} = "selected='selected'" ;
2748 $selected { 'START_ACTION' }{ 'add' } = '' ;
2749 $selected { 'START_ACTION' }{ 'route' } = '' ;
2750 $selected { 'START_ACTION' }{ 'start' } = '' ;
2751 $selected { 'START_ACTION' }{ $cgiparams { 'START_ACTION' }} = "selected='selected'" ;
2753 $selected { 'INACTIVITY_TIMEOUT' } = ();
2754 foreach my $timeout ( keys %INACTIVITY_TIMEOUTS ) {
2755 $selected { 'INACTIVITY_TIMEOUT' }{ $timeout } = "" ;
2757 $selected { 'INACTIVITY_TIMEOUT' }{ $cgiparams { 'INACTIVITY_TIMEOUT' }} = "selected" ;
2759 & Header
:: showhttpheaders
();
2760 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
2761 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2763 if ( $errormessage ) {
2764 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2765 print "<class name='base'> $errormessage " ;
2766 print " </class>" ;
2767 & Header
:: closebox
();
2771 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
2772 print "<class name='base'> $warnmessage " ;
2773 print " </class>" ;
2774 & Header
:: closebox
();
2777 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'advanced'}:" );
2779 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
2780 <input type='hidden' name='ADVANCED' value='yes' />
2781 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
2783 <table width='100%'>
2786 <th width="15%"></th>
2793 <td> $Lang ::tr{'vpn keyexchange'}:</td>
2795 <select name='IKE_VERSION'>
2796 <option value='ikev2' $selected {'IKE_VERSION'}{'ikev2'}>IKEv2</option>
2797 <option value='ikev1' $selected {'IKE_VERSION'}{'ikev1'}>IKEv1</option>
2803 <td class='boldbase' width="15%"> $Lang ::tr{'encryption'}</td>
2804 <td class='boldbase'>
2805 <select name='IKE_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
2806 <option value='chacha20poly1305' $checked {'IKE_ENCRYPTION'}{'chacha20poly1305'}>256 bit ChaCha20-Poly1305/128 bit ICV</option>
2807 <option value='aes256gcm128' $checked {'IKE_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
2808 <option value='aes256gcm96' $checked {'IKE_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
2809 <option value='aes256gcm64' $checked {'IKE_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
2810 <option value='aes256' $checked {'IKE_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
2811 <option value='camellia256' $checked {'IKE_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
2812 <option value='aes192gcm128' $checked {'IKE_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
2813 <option value='aes192gcm96' $checked {'IKE_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
2814 <option value='aes192gcm64' $checked {'IKE_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
2815 <option value='aes192' $checked {'IKE_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
2816 <option value='camellia192' $checked {'IKE_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
2817 <option value='aes128gcm128' $checked {'IKE_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
2818 <option value='aes128gcm96' $checked {'IKE_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
2819 <option value='aes128gcm64' $checked {'IKE_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
2820 <option value='aes128' $checked {'IKE_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
2821 <option value='camellia128' $checked {'IKE_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
2822 <option value='3des' $checked {'IKE_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC ( $Lang ::tr{'vpn weak'})</option>
2825 <td class='boldbase'>
2826 <select name='ESP_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
2827 <option value='chacha20poly1305' $checked {'ESP_ENCRYPTION'}{'chacha20poly1305'}>256 bit ChaCha20-Poly1305/128 bit ICV</option>
2828 <option value='aes256gcm128' $checked {'ESP_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
2829 <option value='aes256gcm96' $checked {'ESP_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
2830 <option value='aes256gcm64' $checked {'ESP_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
2831 <option value='aes256' $checked {'ESP_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
2832 <option value='camellia256' $checked {'ESP_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
2833 <option value='aes192gcm128' $checked {'ESP_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
2834 <option value='aes192gcm96' $checked {'ESP_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
2835 <option value='aes192gcm64' $checked {'ESP_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
2836 <option value='aes192' $checked {'ESP_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
2837 <option value='camellia192' $checked {'ESP_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
2838 <option value='aes128gcm128' $checked {'ESP_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
2839 <option value='aes128gcm96' $checked {'ESP_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
2840 <option value='aes128gcm64' $checked {'ESP_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
2841 <option value='aes128' $checked {'ESP_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
2842 <option value='camellia128' $checked {'ESP_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
2843 <option value='3des' $checked {'ESP_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC ( $Lang ::tr{'vpn weak'})</option>
2849 <td class='boldbase' width="15%"> $Lang ::tr{'integrity'}</td>
2850 <td class='boldbase'>
2851 <select name='IKE_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
2852 <option value='sha2_512' $checked {'IKE_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2853 <option value='sha2_384' $checked {'IKE_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2854 <option value='sha2_256' $checked {'IKE_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2855 <option value='aesxcbc' $checked {'IKE_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2856 <option value='sha' $checked {'IKE_INTEGRITY'}{'sha'}>SHA1 ( $Lang ::tr{'vpn weak'})</option>
2857 <option value='md5' $checked {'IKE_INTEGRITY'}{'md5'}>MD5 ( $Lang ::tr{'vpn broken'})</option>
2860 <td class='boldbase'>
2861 <select name='ESP_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
2862 <option value='sha2_512' $checked {'ESP_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
2863 <option value='sha2_384' $checked {'ESP_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
2864 <option value='sha2_256' $checked {'ESP_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
2865 <option value='aesxcbc' $checked {'ESP_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
2866 <option value='sha1' $checked {'ESP_INTEGRITY'}{'sha1'}>SHA1 ( $Lang ::tr{'vpn weak'})</option>
2867 <option value='md5' $checked {'ESP_INTEGRITY'}{'md5'}>MD5 ( $Lang ::tr{'vpn broken'})</option>
2872 <td class='boldbase' width="15%"> $Lang ::tr{'lifetime'} <img src='/blob.gif' alt='*' /></td>
2873 <td class='boldbase'>
2874 <input type='text' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' size='5' /> $Lang ::tr{'hours'}
2876 <td class='boldbase'>
2877 <input type='text' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' size='5' /> $Lang ::tr{'hours'}
2881 <td class='boldbase' width="15%"> $Lang ::tr{'grouptype'}</td>
2882 <td class='boldbase'>
2883 <select name='IKE_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
2884 <option value='curve25519' $checked {'IKE_GROUPTYPE'}{'curve25519'}>Curve 25519 (256 bit)</option>
2885 <option value='curve448' $checked {'IKE_GROUPTYPE'}{'curve448'}>Curve 448 (224 bit)</option>
2886 <option value='e521' $checked {'IKE_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
2887 <option value='e512bp' $checked {'IKE_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
2888 <option value='e384' $checked {'IKE_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
2889 <option value='e384bp' $checked {'IKE_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
2890 <option value='e256' $checked {'IKE_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
2891 <option value='e256bp' $checked {'IKE_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
2892 <option value='e224' $checked {'IKE_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
2893 <option value='e224bp' $checked {'IKE_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
2894 <option value='e192' $checked {'IKE_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
2895 <option value='8192' $checked {'IKE_GROUPTYPE'}{'8192'}>MODP-8192</option>
2896 <option value='6144' $checked {'IKE_GROUPTYPE'}{'6144'}>MODP-6144</option>
2897 <option value='4096' $checked {'IKE_GROUPTYPE'}{'4096'}>MODP-4096</option>
2898 <option value='3072' $checked {'IKE_GROUPTYPE'}{'3072'}>MODP-3072</option>
2899 <option value='2048' $checked {'IKE_GROUPTYPE'}{'2048'}>MODP-2048</option>
2900 <option value='1536' $checked {'IKE_GROUPTYPE'}{'1536'}>MODP-1536</option>
2901 <option value='1024' $checked {'IKE_GROUPTYPE'}{'1024'}>MODP-1024 ( $Lang ::tr{'vpn broken'})</option>
2902 <option value='768' $checked {'IKE_GROUPTYPE'}{'768'}>MODP-768 ( $Lang ::tr{'vpn broken'})</option>
2905 <td class='boldbase'>
2906 <select name='ESP_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
2907 <option value='curve25519' $checked {'ESP_GROUPTYPE'}{'curve25519'}>Curve 25519 (256 bit)</option>
2908 <option value='curve448' $checked {'ESP_GROUPTYPE'}{'curve448'}>Curve 448 (224 bit)</option>
2909 <option value='e521' $checked {'ESP_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
2910 <option value='e512bp' $checked {'ESP_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
2911 <option value='e384' $checked {'ESP_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
2912 <option value='e384bp' $checked {'ESP_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
2913 <option value='e256' $checked {'ESP_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
2914 <option value='e256bp' $checked {'ESP_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
2915 <option value='e224' $checked {'ESP_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
2916 <option value='e224bp' $checked {'ESP_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
2917 <option value='e192' $checked {'ESP_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
2918 <option value='8192' $checked {'ESP_GROUPTYPE'}{'8192'}>MODP-8192</option>
2919 <option value='6144' $checked {'ESP_GROUPTYPE'}{'6144'}>MODP-6144</option>
2920 <option value='4096' $checked {'ESP_GROUPTYPE'}{'4096'}>MODP-4096</option>
2921 <option value='3072' $checked {'ESP_GROUPTYPE'}{'3072'}>MODP-3072</option>
2922 <option value='2048' $checked {'ESP_GROUPTYPE'}{'2048'}>MODP-2048</option>
2923 <option value='1536' $checked {'ESP_GROUPTYPE'}{'1536'}>MODP-1536</option>
2924 <option value='1024' $checked {'ESP_GROUPTYPE'}{'1024'}>MODP-1024 ( $Lang ::tr{'vpn broken'})</option>
2925 <option value='768' $checked {'ESP_GROUPTYPE'}{'768'}>MODP-768 ( $Lang ::tr{'vpn broken'})</option>
2926 <option value='none' $checked {'ESP_GROUPTYPE'}{'none'}>- $Lang ::tr{'none'} -</option>
2935 <h2> $Lang ::tr{'dead peer detection'}</h2>
2937 <table width="100%">
2939 <td width="15%"> $Lang ::tr{'dpd action'}:</td>
2941 <select name='DPD_ACTION'>
2942 <option value='none' $selected {'DPD_ACTION'}{'none'}>- $Lang ::tr{'disabled'} -</option>
2943 <option value='clear' $selected {'DPD_ACTION'}{'clear'}>clear</option>
2944 <option value='hold' $selected {'DPD_ACTION'}{'hold'}>hold</option>
2945 <option value='restart' $selected {'DPD_ACTION'}{'restart'}>restart</option>
2950 <td width="15%"> $Lang ::tr{'dpd timeout'}: <img src='/blob.gif' alt='*' /></td>
2952 <input type='text' name='DPD_TIMEOUT' size='5' value=' $cgiparams {'DPD_TIMEOUT'}' />
2956 <td width="15%"> $Lang ::tr{'dpd delay'}: <img src='/blob.gif' alt='*' /></td>
2958 <input type='text' name='DPD_DELAY' size='5' value=' $cgiparams {'DPD_DELAY'}' />
2965 <table width="100%">
2969 <input type='checkbox' name='ONLY_PROPOSED' $checked {'ONLY_PROPOSED'} />
2970 IKE+ESP: $Lang ::tr{'use only proposed settings'}
2974 <label> $Lang ::tr{'vpn start action'}</label>
2975 <select name="START_ACTION">
2976 <option value="route" $selected {'START_ACTION'}{'route'}> $Lang ::tr{'vpn start action route'}</option>
2977 <option value="start" $selected {'START_ACTION'}{'start'}> $Lang ::tr{'vpn start action start'}</option>
2978 <option value="add" $selected {'START_ACTION'}{'add'} > $Lang ::tr{'vpn start action add'}</option>
2985 <input type='checkbox' name='PFS' $checked {'PFS'} />
2986 $Lang ::tr{'pfs yes no'}
2990 <label> $Lang ::tr{'vpn inactivity timeout'}</label>
2991 <select name="INACTIVITY_TIMEOUT">
2993 foreach my $t ( sort { $a <=> $b } keys %INACTIVITY_TIMEOUTS ) {
2994 print "<option value= \" $t \" $selected {'INACTIVITY_TIMEOUT'}{ $t }> $INACTIVITY_TIMEOUTS { $t }</option> \n " ;
3005 <input type='checkbox' name='COMPRESSION' $checked {'COMPRESSION'} />
3006 $Lang ::tr{'vpn payload compression'}
3013 <input type='checkbox' name='FORCE_MOBIKE' $checked {'FORCE_MOBIKE'} />
3014 $Lang ::tr{'vpn force mobike'}
3019 <td align='left'><img src='/blob.gif' align='top' alt='*' /> $Lang ::tr{'required field'}</td>
3021 <input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />
3022 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' />
3028 & Header
:: closebox
();
3029 & Header
:: closebigbox
();
3030 & Header
:: closepage
();
3037 ### Default status page
3042 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%cgiparams );
3043 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
3044 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
3045 $cgiparams { 'CA_NAME' } = '' ;
3047 my @status = `/usr/local/bin/ipsecctrl I 2>/dev/null` ;
3049 $checked { 'ENABLED' } = $cgiparams { 'ENABLED' } eq 'on' ?
"checked='checked'" : '' ;
3051 & Header
:: showhttpheaders
();
3052 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
3053 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
3055 if ( $errormessage ) {
3056 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
3057 print "<class name='base'> $errormessage \n " ;
3058 print " </class> \n " ;
3059 & Header
:: closebox
();
3063 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
3064 print " $warnmessage <br>" ;
3065 print " $Lang ::tr{'fwdfw warn1'}<br>" ;
3066 & Header
:: closebox
();
3067 print "<center><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'ok'}' style='width: 5em;'></form>" ;
3068 & Header
:: closepage
();
3072 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'global settings' });
3074 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3075 <table width='100%'>
3077 <td width='60%' class='base'>
3078 $Lang ::tr{'enabled'}
3081 <input type='checkbox' name='ENABLED' $checked {'ENABLED'} />
3085 <td class='base' nowrap='nowrap' width="60%"> $Lang ::tr{'host to net vpn'}:</td>
3086 <td width="40%"><input type='text' name='RW_NET' value=' $cgiparams {'RW_NET'}' /></td>
3089 <td width='100%' colspan="2" align='right' class='base'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' /></td>
3095 & Header
:: closebox
();
3097 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection status and controlc' });
3099 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
3101 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
3102 <th width='22%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></th>
3103 <th width='23%' class='boldbase' align='center'><b> $Lang ::tr{'common name'}</b></th>
3104 <th width='30%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></th>
3105 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></th>
3106 <th class='boldbase' align='center' colspan='7'><b> $Lang ::tr{'action'}</b></th>
3112 foreach my $key ( sort { ncmp
( $confighash { $a }[ 1 ], $confighash { $b }[ 1 ]) } keys %confighash ) {
3113 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
3117 $col = "bgcolor=' $color {'color20'}'" ;
3120 $col = "bgcolor=' $color {'color22'}'" ;
3122 print "<td align='center' nowrap='nowrap' $col > $confighash { $key }[1]</td>" ;
3123 print "<td align='center' nowrap='nowrap' $col >" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ") $confighash { $key }[29]</td>" ;
3124 if ( $confighash { $key }[ 2 ] eq ' %auth -dn' ) {
3125 print "<td align='left' nowrap='nowrap' $col > $confighash { $key }[9]</td>" ;
3126 } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
3127 print "<td align='left' nowrap='nowrap' $col > $confighash { $key }[2]</td>" ;
3129 print "<td align='left' $col > </td>" ;
3131 print "<td align='center' $col > $confighash { $key }[25]</td>" ;
3132 my $col1 = "bgcolor='${Header::colourred}'" ;
3133 my $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
3134 if ( $confighash { $key }[ 33 ] eq "add" ) {
3135 $col1 = "bgcolor='${Header::colourorange}'" ;
3136 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'vpn wait'}</font></b>" ;
3138 foreach my $line ( @status ) {
3139 if (( $line =~ /\"$confighash{$key}[1]\".*IPsec SA established/ ) ||
3140 ( $line =~ /$confighash{$key}[1]\{.*INSTALLED/ )) {
3141 $col1 = "bgcolor='${Header::colourgreen}'" ;
3142 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b>" ;
3144 } elsif ( $line =~ /$confighash{$key}[1]\[.*CONNECTING/ ) {
3145 $col1 = "bgcolor='${Header::colourorange}'" ;
3146 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'vpn connecting'}</font></b>" ;
3147 } elsif ( $line =~ /$confighash{$key}[1]\{.*ROUTED/ ) {
3148 $col1 = "bgcolor='${Header::colourorange}'" ;
3149 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'vpn on-demand'}</font></b>" ;
3152 # move to blue if really down
3153 if ( $confighash { $key }[ 0 ] eq 'off' && $col1 =~ /${Header::colourred}/ ) {
3154 $col1 = "bgcolor='${Header::colourblue}'" ;
3155 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
3158 <td align='center' $col1 > $active </td>
3159 <td align='center' $col >
3160 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3161 <input type='image' name=' $Lang ::tr{'restart'}' src='/images/reload.gif' alt=' $Lang ::tr{'restart'}' title=' $Lang ::tr{'restart'}' />
3162 <input type='hidden' name='ACTION' value=' $Lang ::tr{'restart'}' />
3163 <input type='hidden' name='KEY' value=' $key ' />
3168 if (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
3170 <td align='center' $col >
3171 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3172 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' />
3173 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
3174 <input type='hidden' name='KEY' value=' $key ' />
3180 print "<td width='2%' $col > </td>" ;
3182 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/certs/ $confighash { $key }[1].p12" ) {
3184 <td align='center' $col >
3185 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3186 <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'}' />
3187 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
3188 <input type='hidden' name='KEY' value=' $key ' />
3193 } elsif (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
3195 <td align='center' $col >
3196 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3197 <input type='image' name=' $Lang ::tr{'download certificate'}' src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' title=' $Lang ::tr{'download certificate'}' />
3198 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
3199 <input type='hidden' name='KEY' value=' $key ' />
3205 print "<td width='2%' $col > </td>" ;
3209 if ( $confighash { $key }[ 3 ] eq 'host' ) {
3211 <td align='center' $col >
3212 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3213 <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'}' />
3214 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download apple profile'}' />
3215 <input type='hidden' name='KEY' value=' $key ' />
3220 print "<td width='2%' $col > </td>" ;
3224 <td align='center' $col >
3225 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3226 <input type='image' name=' $Lang ::tr{'toggle enable disable'}' src='/images/ $gif ' alt=' $Lang ::tr{'toggle enable disable'}' title=' $Lang ::tr{'toggle enable disable'}' />
3227 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
3228 <input type='hidden' name='KEY' value=' $key ' />
3232 <td align='center' $col >
3233 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3234 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
3235 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' title=' $Lang ::tr{'edit'}' />
3236 <input type='hidden' name='KEY' value=' $key ' />
3239 <td align='center' $col >
3240 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3241 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
3242 <input type='image' name=' $Lang ::tr{'remove'}' src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' title=' $Lang ::tr{'remove'}' />
3243 <input type='hidden' name='KEY' value=' $key ' />
3253 # If the config file contains entries, print Key to action icons
3258 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
3259 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
3260 <td class='base'> $Lang ::tr{'click to disable'}</td>
3261 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
3262 <td class='base'> $Lang ::tr{'show certificate'}</td>
3263 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
3264 <td class='base'> $Lang ::tr{'edit'}</td>
3265 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
3266 <td class='base'> $Lang ::tr{'remove'}</td>
3270 <td> <img src='/images/off.gif' alt='?OFF' /></td>
3271 <td class='base'> $Lang ::tr{'click to enable'}</td>
3272 <td> <img src='/images/floppy.gif' alt='?FLOPPY' /></td>
3273 <td class='base'> $Lang ::tr{'download certificate'}</td>
3274 <td> <img src='/images/reload.gif' alt='?RELOAD'/></td>
3275 <td class='base'> $Lang ::tr{'restart'}</td>
3283 <table width='100%'>
3284 <tr><td align='right' colspan='9'>
3285 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3286 <input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />
3292 & Header
:: closebox
();
3294 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'certificate authorities'}" );
3296 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
3298 <th width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
3299 <th width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></th>
3300 <th width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></th>
3304 my $col1 = "bgcolor=' $color {'color22'}'" ;
3305 my $col2 = "bgcolor=' $color {'color20'}'" ;
3306 if (- f
"${General::swroot}/ca/cacert.pem" ) {
3307 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/cacert.pem" ));
3310 <td class='base' $col1 > $Lang ::tr{'root certificate'}</td>
3311 <td class='base' $col1 > $casubject </td>
3312 <td width='3%' align='center' $col1 >
3313 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3314 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
3315 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/info.gif' alt=' $Lang ::tr{'show root certificate'}' title=' $Lang ::tr{'show root certificate'}' />
3318 <td width='3%' align='center' $col1 >
3319 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3320 <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'}' />
3321 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
3324 <td width='4%' $col1 > </td></tr>
3328 # display rootcert generation buttons
3331 <td class='base' $col1 > $Lang ::tr{'root certificate'}:</td>
3332 <td class='base' $col1 > $Lang ::tr{'not present'}</td>
3333 <td colspan='3' $col1 > </td></tr>
3338 if (- f
"${General::swroot}/certs/hostcert.pem" ) {
3339 my $hostsubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/certs/hostcert.pem" ));
3343 <td class='base' $col2 > $Lang ::tr{'host certificate'}</td>
3344 <td class='base' $col2 > $hostsubject </td>
3345 <td width='3%' align='center' $col2 >
3346 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3347 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
3348 <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'}' />
3351 <td width='3%' align='center' $col2 >
3352 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3353 <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'}" />
3354 <input type='hidden' name='ACTION' value=" $Lang ::tr{'download host certificate'}" />
3357 <td width='4%' $col2 > </td></tr>
3364 <td width='25%' class='base' $col2 > $Lang ::tr{'host certificate'}:</td>
3365 <td class='base' $col2 > $Lang ::tr{'not present'}</td>
3366 <td colspan='3' $col2 > </td></tr>
3372 if ( keys %cahash > 0 ) {
3373 foreach my $key ( keys %cahash ) {
3374 if ( $rowcolor ++ % 2 ) {
3376 $col = "bgcolor=' $color {'color20'}'" ;
3379 $col = "bgcolor=' $color {'color22'}'" ;
3381 print "<td class='base' $col > $cahash { $key }[0]</td> \n " ;
3382 print "<td class='base' $col > $cahash { $key }[1]</td> \n " ;
3384 <td align='center' $col >
3385 <form method='post' name='cafrm${key}a' action=' $ENV {'SCRIPT_NAME'}'>
3386 <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'}' />
3387 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
3388 <input type='hidden' name='KEY' value=' $key ' />
3391 <td align='center' $col >
3392 <form method='post' name='cafrm${key}b' action=' $ENV {'SCRIPT_NAME'}'>
3393 <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'}' />
3394 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
3395 <input type='hidden' name='KEY' value=' $key ' />
3398 <td align='center' $col >
3399 <form method='post' name='cafrm${key}c' action=' $ENV {'SCRIPT_NAME'}'>
3400 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
3401 <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'}' />
3402 <input type='hidden' name='KEY' value=' $key ' />
3412 # If the file contains entries, print Key to action icons
3413 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
3416 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
3417 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
3418 <td class='base'> $Lang ::tr{'show certificate'}</td>
3419 <td> <img src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' /></td>
3420 <td class='base'> $Lang ::tr{'download certificate'}</td>
3425 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>" ;
3429 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
3430 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
3433 <td class='base' nowrap='nowrap'> $Lang ::tr{'ca name'}: <img src='/blob.gif' alt='*' /></td>
3434 <td nowrap='nowrap'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' /> </td>
3435 <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td>
3436 <td nowrap='nowrap'><input type='submit' name='ACTION' value=' $Lang ::tr{'upload ca certificate'}' /></td>
3439 <td colspan='3'> $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}:</td>
3440 <td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' /></td>
3446 & Header
:: closebox
();
3447 & Header
:: closebigbox
();
3448 & Header
:: closepage
();
3450 sub array_unique
($) {
3455 foreach my $e ( @
$array ) {
3456 next if $seen { $e }++;
3463 sub make_algos
($$$$$) {
3464 my ( $mode , $encs , $ints , $grps , $pfs ) = @_ ;
3467 foreach my $enc ( @
$encs ) {
3468 foreach my $int ( @
$ints ) {
3469 foreach my $grp ( @
$grps ) {
3472 if ( $mode eq "ike" ) {
3475 if ( $grp =~ m/^e(.*)$/ ) {
3476 push ( @algo , "ecp $1 " );
3477 } elsif ( $grp =~ m/curve(25519|448)/ ) {
3478 push ( @algo , " $grp " );
3480 push ( @algo , "modp $grp " );
3483 } elsif ( $mode eq "esp" ) {
3484 my $is_aead = ( $enc =~ m/[cg]cm/ );
3490 if (! $pfs || $grp eq "none" ) {
3492 } elsif ( $grp =~ m/^e(.*)$/ ) {
3493 push ( @algo , "ecp $1 " );
3494 } elsif ( $grp =~ m/curve(25519|448)/ ) {
3495 push ( @algo , " $grp " );
3497 push ( @algo , "modp $grp " );
3501 push ( @algos , join ( "-" , @algo ));
3506 return & array_unique
( \
@algos );
3509 sub make_subnets
($$) {
3510 my $direction = shift ;
3511 my $subnets = shift ;
3513 my @nets = split ( /\|/ , $subnets );
3515 foreach my $net ( @nets ) {
3516 my $cidr_net = & General
:: ipcidr
( $net );
3518 # Skip 0.0.0.0/0 for remote because this renders the
3519 # while system inaccessible
3520 next if (( $direction eq "right" ) && ( $cidr_net eq "0.0.0.0/0" ));
3522 push ( @cidr_nets , $cidr_net );
3525 return join ( "," , @cidr_nets );