]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/vpnmain.cgi
4e64860ec13d9b8ddefebe8e58947ee4f7d02498
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2020 IPFire Team <info@ipfire.org> #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
26 use File
:: Temp qw
/ tempfile tempdir / ;
30 # enable only the following on debugging purpose
32 #use CGI::Carp 'fatalsToBrowser';
34 require '/var/ipfire/general-functions.pl' ;
35 require "${General::swroot}/lang.pl" ;
36 require "${General::swroot}/header.pl" ;
37 require "${General::swroot}/countries.pl" ;
39 #workaround to suppress a warning when a variable is used only once
40 my @dummy = ( ${ Header
:: colourgreen
}, ${ Header
:: colourblue
} );
44 ### Initialize variables
46 my $sleepDelay = 4 ; # after a call to ipsecctrl S or R, wait this delay (seconds) before reading status (let the ipsec do its job)
55 my $errormessage = '' ;
58 my %mainsettings = ();
59 & General
:: readhash
( "${General::swroot}/main/settings" , \
%mainsettings );
60 & General
:: readhash
( "/srv/web/ipfire/html/themes/ipfire/include/colors.txt" , \
%color );
62 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%netsettings );
64 my %INACTIVITY_TIMEOUTS = (
65 300 => $Lang :: tr
{ 'five minutes' },
66 600 => $Lang :: tr
{ 'ten minutes' },
67 900 => $Lang :: tr
{ 'fifteen minutes' },
68 1800 => $Lang :: tr
{ 'thirty minutes' },
69 3600 => $Lang :: tr
{ 'one hour' },
70 43200 => $Lang :: tr
{ 'twelve hours' },
71 86400 => $Lang :: tr
{ '24 hours' },
72 0 => "- $Lang ::tr{'unlimited'} -" ,
77 & General
:: get_aliases
( \
%aliases );
81 $cgiparams { 'ENABLED' } = 'off' ;
82 $cgiparams { 'EDIT_ADVANCED' } = 'off' ;
83 $cgiparams { 'ACTION' } = '' ;
84 $cgiparams { 'CA_NAME' } = '' ;
85 $cgiparams { 'KEY' } = '' ;
86 $cgiparams { 'TYPE' } = '' ;
87 $cgiparams { 'ADVANCED' } = '' ;
88 $cgiparams { 'NAME' } = '' ;
89 $cgiparams { 'LOCAL_SUBNET' } = '' ;
90 $cgiparams { 'REMOTE_SUBNET' } = '' ;
91 $cgiparams { 'LOCAL' } = '' ;
92 $cgiparams { 'REMOTE' } = '' ;
93 $cgiparams { 'LOCAL_ID' } = '' ;
94 $cgiparams { 'REMOTE_ID' } = '' ;
95 $cgiparams { 'REMARK' } = '' ;
96 $cgiparams { 'PSK' } = '' ;
97 $cgiparams { 'CERT_NAME' } = '' ;
98 $cgiparams { 'CERT_EMAIL' } = '' ;
99 $cgiparams { 'CERT_OU' } = '' ;
100 $cgiparams { 'CERT_ORGANIZATION' } = '' ;
101 $cgiparams { 'CERT_CITY' } = '' ;
102 $cgiparams { 'CERT_STATE' } = '' ;
103 $cgiparams { 'CERT_COUNTRY' } = '' ;
104 $cgiparams { 'SUBJECTALTNAME' } = '' ;
105 $cgiparams { 'CERT_PASS1' } = '' ;
106 $cgiparams { 'CERT_PASS2' } = '' ;
107 $cgiparams { 'ROOTCERT_HOSTNAME' } = '' ;
108 $cgiparams { 'ROOTCERT_COUNTRY' } = '' ;
109 $cgiparams { 'P12_PASS' } = '' ;
110 $cgiparams { 'ROOTCERT_ORGANIZATION' } = '' ;
111 $cgiparams { 'ROOTCERT_HOSTNAME' } = '' ;
112 $cgiparams { 'ROOTCERT_EMAIL' } = '' ;
113 $cgiparams { 'ROOTCERT_OU' } = '' ;
114 $cgiparams { 'ROOTCERT_CITY' } = '' ;
115 $cgiparams { 'ROOTCERT_STATE' } = '' ;
116 $cgiparams { 'RW_ENDPOINT' } = '' ;
117 $cgiparams { 'RW_NET' } = '' ;
118 $cgiparams { 'DPD_DELAY' } = '30' ;
119 $cgiparams { 'DPD_TIMEOUT' } = '120' ;
120 $cgiparams { 'FORCE_MOBIKE' } = 'off' ;
121 $cgiparams { 'START_ACTION' } = 'route' ;
122 $cgiparams { 'INACTIVITY_TIMEOUT' } = 1800 ;
123 $cgiparams { 'MODE' } = "tunnel" ;
124 $cgiparams { 'INTERFACE_MODE' } = "" ;
125 $cgiparams { 'INTERFACE_ADDRESS' } = "" ;
126 $cgiparams { 'INTERFACE_MTU' } = 1500 ;
127 $cgiparams { 'DNS_SERVERS' } = "" ;
128 & Header
:: getcgihash
( \
%cgiparams , { 'wantfile' => 1 , 'filevar' => 'FH' });
130 my %APPLE_CIPHERS = (
131 "aes256gcm128" => "AES-256-GCM" ,
132 "aes128gcm128" => "AES-128-GCM" ,
133 "aes256" => "AES-256" ,
134 "aes128" => "AES-128" ,
138 my %APPLE_INTEGRITIES = (
139 "sha2_512" => "SHA2-512" ,
140 "sha2_384" => "SHA2-384" ,
141 "sha2_256" => "SHA2-256" ,
142 "sha1" => "SHA1-160" ,
145 my %APPLE_DH_GROUPS = (
163 my $hostname = $_ [ 0 ];
164 unless ( $hostname ) { return "No hostname" };
165 my $res = new Net
:: DNS
:: Resolver
;
166 my $query = $res -> search ( " $hostname " );
168 foreach my $rr ( $query -> answer ) {
169 ## Potential bug - we are only looking at A records:
170 return 0 if $rr -> type eq "A" ;
173 return $res -> errorstring ;
177 ### Just return true is one interface is vpn enabled
180 return ( $vpnsettings { 'ENABLED' } eq 'on' );
183 ### old version: maintain serial number to one, without explication.
184 ### this: let the counter go, so that each cert is numbered.
186 sub cleanssldatabase
{
187 if ( open ( FILE
, ">${General::swroot}/certs/serial" )) {
191 if ( open ( FILE
, ">${General::swroot}/certs/index.txt" )) {
195 if ( open ( FILE
, ">${General::swroot}/certs/index.txt.attr" )) {
199 unlink ( "${General::swroot}/certs/index.txt.old" );
200 unlink ( "${General::swroot}/certs/index.txt.attr.old" );
201 unlink ( "${General::swroot}/certs/serial.old" );
202 unlink ( "${General::swroot}/certs/01.pem" );
204 sub newcleanssldatabase
{
205 if (! - s
"${General::swroot}/certs/serial" ) {
206 open ( FILE
, ">${General::swroot}/certs/serial" );
210 if (! - s
">${General::swroot}/certs/index.txt" ) {
211 system ( "touch ${General::swroot}/certs/index.txt" );
213 if (! - s
">${General::swroot}/certs/index.txt.attr" ) {
214 system ( "touch ${General::swroot}/certs/index.txt.attr" );
216 unlink ( "${General::swroot}/certs/index.txt.old" );
217 unlink ( "${General::swroot}/certs/index.txt.attr.old" );
218 unlink ( "${General::swroot}/certs/serial.old" );
219 # unlink ("${General::swroot}/certs/01.pem"); numbering evolves. Wrong place to delete
223 ### Call openssl and return errormessage if any
227 my $retssl = `/usr/bin/openssl $opt 2>&1` ; #redirect stderr
229 foreach my $line ( split ( /\n/ , $retssl )) {
230 & General
:: log ( "ipsec" , " $line " ) if ( 0 ); # 1 for verbose logging
231 $ret .= '<br>' . $line if ( $line =~ /error|unknown/ );
234 $ret = & Header
:: cleanhtml
( $ret );
236 return $ret ?
" $Lang ::tr{'openssl produced an error'}: $ret " : '' ;
239 ### Obtain a CN from given cert
241 sub getCNfromcert
($) {
242 #&General::log("ipsec", "Extracting name from $_[0]...");
243 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
244 $temp =~ /Subject:.*CN = (.*)[\n]/ ;
246 $temp =~ s
+/ Email
+, E
+;
247 $temp =~ s/ ST = / S = / ;
253 ### Obtain Subject from given cert
255 sub getsubjectfromcert
($) {
256 #&General::log("ipsec", "Extracting subject from $_[0]...");
257 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
258 $temp =~ /Subject: (.*)[\n]/ ;
260 $temp =~ s
+/ Email
+, E
+;
261 $temp =~ s/ ST = / S = / ;
265 ### Combine local subnet and connection name to make a unique name for each connection section
266 ### (this sub is not used now)
268 sub makeconnname
($) {
272 $subnet =~ /^(.*?)\/ (.* ?
)$/; # $1=IP $2=mask
273 my $ip = unpack ( 'N' , & Socket
:: inet_aton
( $1 ));
274 if ( length ( $2 ) > 2 ) {
275 my $mm = unpack ( 'N' , & Socket
:: inet_aton
( $2 ));
276 while ( ( $mm & 1 )== 0 ) {
283 return sprintf ( " %s - %X " , $conn , $ip );
286 ### Write a config file.
288 ###Type=Host : GUI can choose the interface used (RED,GREEN,BLUE) and
289 ### the side is always defined as 'left'.
292 sub writeipsecfiles
{
293 my %lconfighash = ();
294 my %lvpnsettings = ();
295 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%lconfighash );
296 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%lvpnsettings );
298 open ( CONF
, ">${General::swroot}/vpn/ipsec.conf" ) or die "Unable to open ${General::swroot}/vpn/ipsec.conf: $!" ;
299 open ( SECRETS
, ">${General::swroot}/vpn/ipsec.secrets" ) or die "Unable to open ${General::swroot}/vpn/ipsec.secrets: $!" ;
302 print CONF
"version 2 \n\n " ;
303 print CONF
"conn %default \n " ;
304 print CONF
" \t keyingtries= %forever \n " ;
307 # Add user includes to config file
308 if (- e
"/etc/ipsec.user.conf" ) {
309 print CONF
"include /etc/ipsec.user.conf \n " ;
313 print SECRETS
"include /etc/ipsec.user.secrets \n " ;
315 if (- f
"${General::swroot}/certs/hostkey.pem" ) {
316 print SECRETS
": RSA ${General::swroot}/certs/hostkey.pem \n "
318 my $last_secrets = '' ; # old the less specifics connections
320 foreach my $key ( keys %lconfighash ) {
321 next if ( $lconfighash { $key }[ 0 ] ne 'on' );
323 #remote peer is not set? => use '%any'
324 $lconfighash { $key }[ 10 ] = ' %any ' if ( $lconfighash { $key }[ 10 ] eq '' );
326 # Field 6 might be "off" on old installations
327 if ( $lconfighash { $key }[ 6 ] eq "off" ) {
328 $lconfighash { $key }[ 6 ] = $lvpnsettings { "VPN_IP" };
332 if ( $lconfighash { $key }[ 6 ]) {
333 $localside = $lconfighash { $key }[ 6 ];
335 $localside = " %defaultroute " ;
338 my $interface_mode = $lconfighash { $key }[ 36 ];
340 print CONF
"conn $lconfighash { $key }[1] \n " ;
341 print CONF
" \t left= $localside \n " ;
343 if ( $interface_mode eq "gre" ) {
344 print CONF
" \t leftprotoport=gre \n " ;
345 } elsif ( $interface_mode eq "vti" ) {
346 print CONF
" \t leftsubnet=0.0.0.0/0 \n " ;
348 print CONF
" \t leftsubnet=" . & make_subnets
( "left" , $lconfighash { $key }[ 8 ]) . " \n " ;
351 print CONF
" \t leftfirewall=yes \n " ;
352 print CONF
" \t lefthostaccess=yes \n " ;
354 # Always send the host certificate
355 if ( $lconfighash { $key }[ 3 ] eq 'host' ) {
356 print CONF
" \t leftsendcert=always \n " ;
359 print CONF
" \t right= $lconfighash { $key }[10] \n " ;
361 if ( $lconfighash { $key }[ 3 ] eq 'net' ) {
362 if ( $interface_mode eq "gre" ) {
363 print CONF
" \t rightprotoport=gre \n " ;
364 } elsif ( $interface_mode eq "vti" ) {
365 print CONF
" \t rightsubnet=0.0.0.0/0 \n " ;
367 print CONF
" \t rightsubnet=" . & make_subnets
( "right" , $lconfighash { $key }[ 11 ]) . " \n " ;
371 # Local Cert and Remote Cert (unless auth is DN dn-auth)
372 if ( $lconfighash { $key }[ 4 ] eq 'cert' ) {
373 print CONF
" \t leftcert=${General::swroot}/certs/hostcert.pem \n " ;
374 print CONF
" \t rightcert=${General::swroot}/certs/ $lconfighash { $key }[1]cert.pem \n " if ( $lconfighash { $key }[ 2 ] ne ' %auth -dn' );
377 # Local and Remote IDs
378 print CONF
" \t leftid= \" $lconfighash { $key }[7] \"\n " if ( $lconfighash { $key }[ 7 ]);
379 print CONF
" \t rightid= \" $lconfighash { $key }[9] \"\n " if ( $lconfighash { $key }[ 9 ]);
382 if ( $lconfighash { $key }[ 35 ] eq "transport" ) {
383 print CONF
" \t type=transport \n " ;
385 print CONF
" \t type=tunnel \n " ;
389 if ( $interface_mode eq "vti" ) {
390 print CONF
" \t mark= $key \n " ;
394 my $pfs = $lconfighash { $key }[ 28 ] eq 'on' ?
'on' : 'off' ;
397 if ( $lconfighash { $key }[ 18 ] && $lconfighash { $key }[ 19 ] && $lconfighash { $key }[ 20 ]) {
398 my @encs = split ( '\|' , $lconfighash { $key }[ 18 ]);
399 my @ints = split ( '\|' , $lconfighash { $key }[ 19 ]);
400 my @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
402 my @algos = & make_algos
( "ike" , \
@encs , \
@ints , \
@groups , 1 );
403 print CONF
" \t ike=" . join ( "," , @algos );
405 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
412 if ( $lconfighash { $key }[ 21 ] && $lconfighash { $key }[ 22 ]) {
413 my @encs = split ( '\|' , $lconfighash { $key }[ 21 ]);
414 my @ints = split ( '\|' , $lconfighash { $key }[ 22 ]);
415 my @groups = split ( '\|' , $lconfighash { $key }[ 23 ]);
417 # Use IKE grouptype if no ESP group type has been selected
418 # (for backwards compatibility)
419 if ( $lconfighash { $key }[ 23 ] eq "" ) {
420 @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
423 my @algos = & make_algos
( "esp" , \
@encs , \
@ints , \
@groups , ( $pfs eq "on" ));
424 print CONF
" \t esp=" . join ( "," , @algos );
426 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
434 if (! $lconfighash { $key }[ 29 ]) {
435 $lconfighash { $key }[ 29 ] = "ikev1" ;
438 print CONF
" \t keyexchange= $lconfighash { $key }[29] \n " ;
441 print CONF
" \t ikelifetime= $lconfighash { $key }[16]h \n " if ( $lconfighash { $key }[ 16 ]);
442 print CONF
" \t keylife= $lconfighash { $key }[17]h \n " if ( $lconfighash { $key }[ 17 ]);
445 print CONF
" \t compress=yes \n " if ( $lconfighash { $key }[ 13 ] eq 'on' );
448 if (( $lconfighash { $key }[ 29 ] eq "ikev2" ) && ( $lconfighash { $key }[ 32 ] eq 'on' )) {
449 print CONF
" \t mobike=yes \n " ;
452 # Dead Peer Detection
453 my $dpdaction = $lconfighash { $key }[ 27 ];
454 print CONF
" \t dpdaction= $dpdaction \n " ;
456 # If the dead peer detection is disabled and IKEv2 is used,
457 # dpddelay must be set to zero, too.
458 if ( $dpdaction eq "none" ) {
459 if ( $lconfighash { $key }[ 29 ] eq "ikev2" ) {
460 print CONF
" \t dpddelay=0 \n " ;
463 my $dpddelay = $lconfighash { $key }[ 31 ];
467 print CONF
" \t dpddelay= $dpddelay \n " ;
468 my $dpdtimeout = $lconfighash { $key }[ 30 ];
472 print CONF
" \t dpdtimeout= $dpdtimeout \n " ;
475 # Build Authentication details: LEFTid RIGHTid : PSK psk
477 if ( $lconfighash { $key }[ 4 ] eq 'psk' ) {
478 $psk_line = ( $lconfighash { $key }[ 7 ] ?
$lconfighash { $key }[ 7 ] : $localside ) . " " ;
479 $psk_line .= $lconfighash { $key }[ 9 ] ?
$lconfighash { $key }[ 9 ] : $lconfighash { $key }[ 10 ]; #remoteid or remote address?
480 $psk_line .= " : PSK ' $lconfighash { $key }[5]' \n " ;
481 # if the line contains %any, it is less specific than two IP or ID, so move it at end of file.
482 if ( $psk_line =~ /%any/ ) {
483 $last_secrets .= $psk_line ;
485 print SECRETS
$psk_line ;
487 print CONF
" \t authby=secret \n " ;
489 print CONF
" \t authby=rsasig \n " ;
490 print CONF
" \t leftrsasigkey= %cert \n " ;
491 print CONF
" \t rightrsasigkey= %cert \n " ;
494 my $start_action = $lconfighash { $key }[ 33 ];
495 if (! $start_action ) {
496 $start_action = "start" ;
499 my $inactivity_timeout = $lconfighash { $key }[ 34 ];
500 if ( $inactivity_timeout eq "" ) {
501 $inactivity_timeout = 900 ;
504 # Automatically start only if a net-to-net connection
505 if ( $lconfighash { $key }[ 3 ] eq 'host' ) {
506 print CONF
" \t auto=add \n " ;
507 print CONF
" \t rightsourceip= $lvpnsettings {'RW_NET'} \n " ;
509 print CONF
" \t auto= $start_action \n " ;
511 # If in on-demand mode, we terminate the tunnel
512 # after 15 min of no traffic
513 if ( $start_action eq 'route' && $inactivity_timeout > 0 ) {
514 print CONF
" \t inactivity= $inactivity_timeout \n " ;
519 print CONF
" \t fragmentation=yes \n " ;
522 if ( $lconfighash { $key }[ 3 ] eq 'host' ) {
523 my @servers = split ( /\|/ , $lconfighash { $key }[ 39 ]);
525 print CONF
" \t rightdns=" . join ( "," , @servers ) . " \n " ;
531 # Add post user includes to config file
532 # After the GUI-connections allows to patch connections.
533 if (- e
"/etc/ipsec.user-post.conf" ) {
534 print CONF
"include /etc/ipsec.user-post.conf \n " ;
538 print SECRETS
$last_secrets if ( $last_secrets );
543 # Hook to regenerate the configuration files.
544 if ( $ENV { "REMOTE_ADDR" } eq "" ) {
550 ### Save main settings
552 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
553 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
555 if ( $cgiparams { 'RW_ENDPOINT' } ne '' && !& General
:: validip
( $cgiparams { 'RW_ENDPOINT' }) && !& General
:: validfqdn
( $cgiparams { 'RW_ENDPOINT' })) {
556 $errormessage = $Lang :: tr
{ 'ipsec invalid ip address or fqdn for rw endpoint' };
560 if ( $cgiparams { 'RW_NET' } ne '' and !& General
:: validipandmask
( $cgiparams { 'RW_NET' }) ) {
561 $errormessage = $Lang :: tr
{ 'urlfilter invalid ip or mask error' };
565 $vpnsettings { 'ENABLED' } = $cgiparams { 'ENABLED' };
566 $vpnsettings { 'RW_ENDPOINT' } = $cgiparams { 'RW_ENDPOINT' };
567 $vpnsettings { 'RW_NET' } = $cgiparams { 'RW_NET' };
568 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
571 system ( '/usr/local/bin/ipsecctrl' , 'S' );
573 system ( '/usr/local/bin/ipsecctrl' , 'D' );
580 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
581 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
583 foreach my $key ( keys %confighash ) {
584 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
585 delete $confighash { $key };
588 while ( my $file = glob ( "${General::swroot}/{ca,certs,crls,private}/*" )) {
592 if ( open ( FILE
, ">${General::swroot}/vpn/caconfig" )) {
596 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
598 system ( '/usr/local/bin/ipsecctrl' , 'R' );
604 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' }) {
605 & Header
:: showhttpheaders
();
606 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
607 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
608 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
610 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
614 <input type='hidden' name='AREUSURE' value='yes' />
615 <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'}
619 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' />
620 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
627 & Header
:: closebigbox
();
628 & Header
:: closepage
();
632 ### Upload CA Certificate
634 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
635 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
637 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
638 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
642 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
643 $errormessage = $Lang :: tr
{ 'name too long' };
647 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
648 $errormessage = $Lang :: tr
{ 'name is invalid' };
649 goto UPLOAD_CA_ERROR
;
652 # Check if there is no other entry with this name
653 foreach my $key ( keys %cahash ) {
654 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
655 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
660 unless ( ref ( $cgiparams { 'FH' })) {
661 $errormessage = $Lang :: tr
{ 'there was no file upload' };
664 # Move uploaded ca to a temporary file
665 ( my $fh , my $filename ) = tempfile
( );
666 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
670 my $temp = `/usr/bin/openssl x509 -text -in $filename ` ;
671 if ( $temp !~ /CA:TRUE/i ) {
672 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
676 move
( $filename , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
678 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
684 my $key = & General
:: findhasharraykey
( \
%cahash );
685 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
686 $cahash { $key }[ 1 ] = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" ));
687 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
689 system ( '/usr/local/bin/ipsecctrl' , 'R' );
695 ### Display ca certificate
697 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
698 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
700 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
701 & Header
:: showhttpheaders
();
702 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
703 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
704 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'ca certificate'}:" );
705 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
706 $output = & Header
:: cleanhtml
( $output , "y" );
707 print "<pre> $output </pre> \n " ;
709 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
710 & Header
:: closebigbox
();
711 & Header
:: closepage
();
714 $errormessage = $Lang :: tr
{ 'invalid key' };
718 ### Export ca certificate to browser
720 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
721 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
723 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
724 print "Content-Type: application/force-download \n " ;
725 print "Content-Type: application/octet-stream \r\n " ;
726 print "Content-Disposition: attachment; filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
727 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
730 $errormessage = $Lang :: tr
{ 'invalid key' };
734 ### Remove ca certificate (step 2)
736 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
737 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
738 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
740 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
741 foreach my $key ( keys %confighash ) {
742 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
743 if ( $test =~ /: OK/ ) {
745 unlink ( "${General::swroot}/certs/ $confighash { $key }[1]cert.pem" );
746 unlink ( "${General::swroot}/certs/ $confighash { $key }[1].p12" );
747 delete $confighash { $key };
748 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
750 system ( '/usr/local/bin/ipsecctrl' , 'D' , $key ) if (& vpnenabled
);
753 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
754 delete $cahash { $cgiparams { 'KEY' }};
755 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
756 system ( '/usr/local/bin/ipsecctrl' , 'R' );
759 $errormessage = $Lang :: tr
{ 'invalid key' };
762 ### Remove ca certificate (step 1)
764 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
765 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
766 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
768 my $assignedcerts = 0 ;
769 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
770 foreach my $key ( keys %confighash ) {
771 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
772 if ( $test =~ /: OK/ ) {
776 if ( $assignedcerts ) {
777 & Header
:: showhttpheaders
();
778 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
779 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
780 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
782 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
786 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
787 <input type='hidden' name='AREUSURE' value='yes' /></td>
790 <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>
793 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
794 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
801 & Header
:: closebigbox
();
802 & Header
:: closepage
();
805 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
806 delete $cahash { $cgiparams { 'KEY' }};
807 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
808 system ( '/usr/local/bin/ipsecctrl' , 'R' );
812 $errormessage = $Lang :: tr
{ 'invalid key' };
816 ### Display root certificate
818 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
819 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
821 & Header
:: showhttpheaders
();
822 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
823 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
824 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
825 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'root certificate'}:" );
826 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/cacert.pem` ;
828 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'host certificate'}:" );
829 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/hostcert.pem` ;
831 $output = & Header
:: cleanhtml
( $output , "y" );
832 print "<pre> $output </pre> \n " ;
834 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
835 & Header
:: closebigbox
();
836 & Header
:: closepage
();
840 ### Export root certificate to browser
842 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
843 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
844 print "Content-Type: application/force-download \n " ;
845 print "Content-Disposition: attachment; filename=cacert.pem \r\n\r\n " ;
846 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/cacert.pem` ;
850 ### Export host certificate to browser
852 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
853 if ( - f
"${General::swroot}/certs/hostcert.pem" ) {
854 print "Content-Type: application/force-download \n " ;
855 print "Content-Disposition: attachment; filename=hostcert.pem \r\n\r\n " ;
856 print `/usr/bin/openssl x509 -in ${General::swroot}/certs/hostcert.pem` ;
860 ### Form for generating/importing the caroot+host certificate
862 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
863 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
865 if (- f
"${General::swroot}/ca/cacert.pem" ) {
866 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
870 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
871 # fill in initial values
872 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
873 if (- e
"${General::swroot}/red/active" && open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
874 my $ipaddr = < IPADDR
>;
877 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
878 $cgiparams { 'SUBJECTALTNAME' } = "DNS:" . $cgiparams { 'ROOTCERT_HOSTNAME' };
879 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
880 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
881 $cgiparams { 'SUBJECTALTNAME' } = "IP:" . $cgiparams { 'ROOTCERT_HOSTNAME' };
884 $cgiparams { 'ROOTCERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' } if (! $cgiparams { 'ROOTCERT_COUNTRY' });
885 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
886 & General
:: log ( "ipsec" , "Importing from p12..." );
888 unless ( ref ( $cgiparams { 'FH' })) {
889 $errormessage = $Lang :: tr
{ 'there was no file upload' };
893 # Move uploaded certificate request to a temporary file
894 ( my $fh , my $filename ) = tempfile
( );
895 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
900 # Extract the CA certificate from the file
901 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
902 if ( open ( STDIN
, "-|" )) {
903 my $opt = " pkcs12 -cacerts -nokeys" ;
904 $opt .= " -in $filename " ;
905 $opt .= " -out /tmp/newcacert" ;
906 $errormessage = & callssl
( $opt );
908 print " $cgiparams {'P12_PASS'} \n " ;
912 # Extract the Host certificate from the file
913 if (! $errormessage ) {
914 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
915 if ( open ( STDIN
, "-|" )) {
916 my $opt = " pkcs12 -clcerts -nokeys" ;
917 $opt .= " -in $filename " ;
918 $opt .= " -out /tmp/newhostcert" ;
919 $errormessage = & callssl
( $opt );
921 print " $cgiparams {'P12_PASS'} \n " ;
926 # Extract the Host key from the file
927 if (! $errormessage ) {
928 & General
:: log ( "ipsec" , "Extracting private key from p12..." );
929 if ( open ( STDIN
, "-|" )) {
930 my $opt = " pkcs12 -nocerts -nodes" ;
931 $opt .= " -in $filename " ;
932 $opt .= " -out /tmp/newhostkey" ;
933 $errormessage = & callssl
( $opt );
935 print " $cgiparams {'P12_PASS'} \n " ;
940 if (! $errormessage ) {
941 & General
:: log ( "ipsec" , "Moving cacert..." );
942 move
( "/tmp/newcacert" , "${General::swroot}/ca/cacert.pem" );
943 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
946 if (! $errormessage ) {
947 & General
:: log ( "ipsec" , "Moving host cert..." );
948 move
( "/tmp/newhostcert" , "${General::swroot}/certs/hostcert.pem" );
949 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
952 if (! $errormessage ) {
953 & General
:: log ( "ipsec" , "Moving private key..." );
954 move
( "/tmp/newhostkey" , "${General::swroot}/certs/hostkey.pem" );
955 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
960 unlink ( '/tmp/newcacert' );
961 unlink ( '/tmp/newhostcert' );
962 unlink ( '/tmp/newhostkey' );
964 unlink ( "${General::swroot}/ca/cacert.pem" );
965 unlink ( "${General::swroot}/certs/hostcert.pem" );
966 unlink ( "${General::swroot}/certs/hostkey.pem" );
970 # Create empty CRL cannot be done because we don't have
971 # the private key for this CAROOT
972 # IPFire can only import certificates
974 & General
:: log ( "ipsec" , "p12 import completed!" );
976 goto ROOTCERT_SUCCESS
;
978 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
980 # Validate input since the form was submitted
981 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
982 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
985 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
986 $errormessage = $Lang :: tr
{ 'organization too long' };
989 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
990 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
993 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
994 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
997 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
998 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
1001 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
1002 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1003 goto ROOTCERT_ERROR
;
1005 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
1006 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1007 goto ROOTCERT_ERROR
;
1009 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1010 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1011 goto ROOTCERT_ERROR
;
1013 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1014 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1015 goto ROOTCERT_ERROR
;
1017 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1018 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1019 goto ROOTCERT_ERROR
;
1021 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1022 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1023 goto ROOTCERT_ERROR
;
1025 #the exact syntax is a list comma separated of
1026 # email:any-validemail
1027 # URI: a uniform resource indicator
1028 # DNS: a DNS domain name
1029 # RID: a registered OBJECT IDENTIFIER
1031 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
1033 if ( $cgiparams { 'SUBJECTALTNAME' } eq '' ) {
1034 $errormessage = $Lang :: tr
{ 'vpn subjectaltname missing' };
1035 goto ROOTCERT_ERROR
;
1038 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
1039 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
1043 # Copy the cgisettings to vpnsettings and save the configfile
1044 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
1045 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
1046 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
1047 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
1048 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
1049 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
1050 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
1051 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1053 # Replace empty strings with a .
1054 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
1055 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
1056 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
1058 # Create the CA certificate
1059 if (! $errormessage ) {
1060 & General
:: log ( "ipsec" , "Creating cacert..." );
1061 if ( open ( STDIN
, "-|" )) {
1062 my $opt = " req -x509 -sha256 -nodes" ;
1063 $opt .= " -days 3650" ;
1064 $opt .= " -newkey rsa:4096" ;
1065 $opt .= " -keyout ${General::swroot}/private/cakey.pem" ;
1066 $opt .= " -out ${General::swroot}/ca/cacert.pem" ;
1068 $errormessage = & callssl
( $opt );
1070 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1073 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1075 print " $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
1076 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1081 # Create the Host certificate request
1082 if (! $errormessage ) {
1083 & General
:: log ( "ipsec" , "Creating host cert..." );
1084 if ( open ( STDIN
, "-|" )) {
1085 my $opt = " req -sha256 -nodes" ;
1086 $opt .= " -newkey rsa:2048" ;
1087 $opt .= " -keyout ${General::swroot}/certs/hostkey.pem" ;
1088 $opt .= " -out ${General::swroot}/certs/hostreq.pem" ;
1089 $errormessage = & callssl
( $opt );
1091 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1094 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1096 print " $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
1097 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1104 # Sign the host certificate request
1105 if (! $errormessage ) {
1106 & General
:: log ( "ipsec" , "Self signing host cert..." );
1108 #No easy way for specifying the contain of subjectAltName without writing a config file...
1109 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1111 basicConstraints=CA:FALSE
1112 nsComment="OpenSSL Generated Certificate"
1113 subjectKeyIdentifier=hash
1114 authorityKeyIdentifier=keyid,issuer:always
1115 extendedKeyUsage = serverAuth
1118 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1121 my $opt = " ca -md sha256 -days 825" ;
1122 $opt .= " -batch -notext" ;
1123 $opt .= " -in ${General::swroot}/certs/hostreq.pem" ;
1124 $opt .= " -out ${General::swroot}/certs/hostcert.pem" ;
1125 $opt .= " -extfile $v3extname " ;
1126 $errormessage = & callssl
( $opt );
1127 unlink ( "${General::swroot}/certs/hostreq.pem" ); #no more needed
1128 unlink ( $v3extname );
1131 # Create an empty CRL
1132 if (! $errormessage ) {
1133 & General
:: log ( "ipsec" , "Creating emptycrl..." );
1134 my $opt = " ca -gencrl" ;
1135 $opt .= " -out ${General::swroot}/crls/cacrl.pem" ;
1136 $errormessage = & callssl
( $opt );
1139 # Successfully build CA / CERT!
1140 if (! $errormessage ) {
1141 & cleanssldatabase
();
1142 goto ROOTCERT_SUCCESS
;
1146 unlink ( "${General::swroot}/ca/cacert.pem" );
1147 unlink ( "${General::swroot}/certs/hostkey.pem" );
1148 unlink ( "${General::swroot}/certs/hostcert.pem" );
1149 unlink ( "${General::swroot}/crls/cacrl.pem" );
1150 & cleanssldatabase
();
1154 & Header
:: showhttpheaders
();
1155 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1156 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1157 if ( $errormessage ) {
1158 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1159 print "<class name='base'> $errormessage " ;
1160 print " </class>" ;
1161 & Header
:: closebox
();
1163 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
1165 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
1166 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1167 <tr><td width='40%' class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
1168 <td width='60%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td></tr>
1169 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}: <img src='/blob.gif' alt='*' /></td>
1170 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td></tr>
1171 <tr><td class='base'> $Lang ::tr{'your e-mail'}:</td>
1172 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td></tr>
1173 <tr><td class='base'> $Lang ::tr{'your department'}:</td>
1174 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td></tr>
1175 <tr><td class='base'> $Lang ::tr{'city'}:</td>
1176 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td></tr>
1177 <tr><td class='base'> $Lang ::tr{'state or province'}:</td>
1178 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td></tr>
1179 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1180 <td class='base'><select name='ROOTCERT_COUNTRY'>
1183 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1184 print "<option value=' $Countries ::countries{ $country }'" ;
1185 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1186 print " selected='selected'" ;
1188 print "> $country </option>" ;
1192 <tr><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*) <img src='/blob.gif' alt='*' /></td>
1193 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' /></td></tr>
1195 <td><br /><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /><br /><br /></td></tr>
1196 <tr><td class='base' colspan='2' align='left'>
1197 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1198 $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'}
1200 <tr><td colspan='2'><hr></td></tr>
1201 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}:</td>
1202 <td nowrap='nowrap'><input type='file' name='FH' size='32' /></td></tr>
1203 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
1204 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td></tr>
1206 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td></tr>
1207 <tr><td class='base' colspan='2' align='left'>
1208 <img src='/blob.gif' alt='*' /> $Lang ::tr{'required field'}</td></tr>
1212 & Header
:: closebox
();
1213 & Header
:: closebigbox
();
1214 & Header
:: closepage
();
1219 system ( '/usr/local/bin/ipsecctrl' , 'S' );
1224 ### Export PKCS12 file to browser
1226 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
1227 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1228 print "Content-Type: application/force-download \n " ;
1229 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
1230 print "Content-Type: application/octet-stream \r\n\r\n " ;
1231 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12` ;
1234 # Export Apple profile to browser
1235 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download apple profile' }) {
1236 # Read global configuration
1237 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1240 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1241 my $key = $cgiparams { 'KEY' };
1243 # Create a UUID generator
1244 my $uuid = Data
:: UUID
-> new ();
1246 my $uuid1 = $uuid -> create_str ();
1247 my $uuid2 = $uuid -> create_str ();
1250 my $cert_uuid = $uuid -> create_str ();
1252 # Read and encode certificate
1253 if ( $confighash { $key }[ 4 ] eq "cert" ) {
1254 my $cert_path = "${General::swroot}/certs/ $confighash { $key }[1].p12" ;
1256 # Read certificate and encode it into Base64
1257 open ( CERT
, "<${cert_path}" );
1258 local ($/) = undef ; # slurp
1259 $cert = MIME
:: Base64
:: encode_base64
(< CERT
>);
1263 print "Content-Type: application/octet-stream \n " ;
1264 print "Content-Disposition: attachment; filename=" . $confighash { $key }[ 1 ] . ".mobileconfig \n " ;
1265 print " \n " ; # end headers
1267 # Use our own FQDN if nothing else is configured
1268 my $endpoint = ( $vpnsettings { 'RW_ENDPOINT' } ne "" ) ?
$vpnsettings { 'RW_ENDPOINT' } : & hostname
();
1270 print "<!DOCTYPE plist PUBLIC \" -//Apple//DTD PLIST 1.0//EN \" \" http://www.apple.com/DTDs/PropertyList-1.0.dtd \" > \n " ;
1271 print "<plist version= \" 1.0 \" > \n " ;
1273 print " <key>PayloadDisplayName</key> \n " ;
1274 print " <string> $confighash { $key }[1]</string> \n " ;
1275 print " <key>PayloadIdentifier</key> \n " ;
1276 print " <string> $confighash { $key }[1]</string> \n " ;
1277 print " <key>PayloadUUID</key> \n " ;
1278 print " <string>${uuid1}</string> \n " ;
1279 print " <key>PayloadType</key> \n " ;
1280 print " <string>Configuration</string> \n " ;
1281 print " <key>PayloadVersion</key> \n " ;
1282 print " <integer>1</integer> \n " ;
1283 print " <key>PayloadContent</key> \n " ;
1286 print " <key>PayloadIdentifier</key> \n " ;
1287 print " <string>org.example.vpn1.conf1</string> \n " ;
1288 print " <key>PayloadUUID</key> \n " ;
1289 print " <string>${uuid2}</string> \n " ;
1290 print " <key>PayloadType</key> \n " ;
1291 print " <string>com.apple.vpn.managed</string> \n " ;
1292 print " <key>PayloadVersion</key> \n " ;
1293 print " <integer>1</integer> \n " ;
1294 print " <key>UserDefinedName</key> \n " ;
1295 print " <string> $confighash { $key }[1]</string> \n " ;
1296 print " <key>VPNType</key> \n " ;
1297 print " <string>IKEv2</string> \n " ;
1298 print " <key>IKEv2</key> \n " ;
1300 print " <key>RemoteAddress</key> \n " ;
1301 print " <string> $endpoint </string> \n " ;
1304 my $pfs = $confighash { $key }[ 28 ];
1306 print " <key>EnablePFS</key> \n " ;
1311 print " <key>IKESecurityAssociationParameters</key> \n " ;
1315 foreach my $cipher ( split ( /\|/ , $confighash { $key }[ 18 ])) {
1316 # Skip all unsupported ciphers
1317 next unless ( exists $APPLE_CIPHERS { $cipher });
1319 print " <key>EncryptionAlgorithm</key> \n " ;
1320 print " <string> $APPLE_CIPHERS { $cipher }</string> \n " ;
1325 foreach my $integrity ( split ( /\|/ , $confighash { $key }[ 19 ])) {
1326 # Skip all unsupported algorithms
1327 next unless ( exists $APPLE_INTEGRITIES { $integrity });
1329 print " <key>IntegrityAlgorithm</key> \n " ;
1330 print " <string> $APPLE_INTEGRITIES { $integrity }</string> \n " ;
1334 # Diffie Hellman Groups
1335 foreach my $group ( split ( /\|/ , $confighash { $key }[ 20 ])) {
1336 # Skip all unsupported algorithms
1337 next unless ( exists $APPLE_DH_GROUPS { $group });
1339 print " <key>DiffieHellmanGroup</key> \n " ;
1340 print " <string> $APPLE_DH_GROUPS { $group }</string> \n " ;
1345 my $lifetime = $confighash { $key }[ 16 ] * 60 ;
1346 print " <key>LifeTimeInMinutes</key> \n " ;
1347 print " <integer> $lifetime </integer> \n " ;
1351 print " <key>ChildSecurityAssociationParameters</key> \n " ;
1355 foreach my $cipher ( split ( /\|/ , $confighash { $key }[ 21 ])) {
1356 # Skip all unsupported ciphers
1357 next unless ( exists $APPLE_CIPHERS { $cipher });
1359 print " <key>EncryptionAlgorithm</key> \n " ;
1360 print " <string> $APPLE_CIPHERS { $cipher }</string> \n " ;
1365 foreach my $integrity ( split ( /\|/ , $confighash { $key }[ 22 ])) {
1366 # Skip all unsupported algorithms
1367 next unless ( exists $APPLE_INTEGRITIES { $integrity });
1369 print " <key>IntegrityAlgorithm</key> \n " ;
1370 print " <string> $APPLE_INTEGRITIES { $integrity }</string> \n " ;
1374 # Diffie Hellman Groups
1375 foreach my $group ( split ( /\|/ , $confighash { $key }[ 23 ])) {
1376 # Skip all unsupported algorithms
1377 next unless ( exists $APPLE_DH_GROUPS { $group });
1379 print " <key>DiffieHellmanGroup</key> \n " ;
1380 print " <string> $APPLE_DH_GROUPS { $group }</string> \n " ;
1385 my $lifetime = $confighash { $key }[ 17 ] * 60 ;
1386 print " <key>LifeTimeInMinutes</key> \n " ;
1387 print " <integer> $lifetime </integer> \n " ;
1392 if ( $confighash { $key }[ 9 ]) {
1393 my $leftid = $confighash { $key }[ 9 ];
1395 # Strip leading @ from FQDNs
1396 if ( $leftid =~ m/^@(.*)$/ ) {
1400 print " <key>LocalIdentifier</key> \n " ;
1401 print " <string> $leftid </string> \n " ;
1405 if ( $confighash { $key }[ 7 ]) {
1406 my $rightid = $confighash { $key }[ 7 ];
1408 # Strip leading @ from FQDNs
1409 if ( $rightid =~ m/^@(.*)$/ ) {
1413 print " <key>RemoteIdentifier</key> \n " ;
1414 print " <string> $rightid </string> \n " ;
1417 if ( $confighash { $key }[ 4 ] eq "cert" ) {
1418 print " <key>AuthenticationMethod</key> \n " ;
1419 print " <string>Certificate</string> \n " ;
1421 print " <key>PayloadCertificateUUID</key> \n " ;
1422 print " <string>${cert_uuid}</string> \n " ;
1424 print " <key>AuthenticationMethod</key> \n " ;
1425 print " <string>SharedSecret</string> \n " ;
1426 print " <key>SharedSecret</key> \n " ;
1427 print " <string> $confighash { $key }[5]</string> \n " ;
1430 print " <key>ExtendedAuthEnabled</key> \n " ;
1431 print " <integer>0</integer> \n " ;
1433 # Connect the VPN automatically
1434 print " <key>OnDemandEnabled</key> \n " ;
1435 print " <integer>1</integer> \n " ;
1436 print " <key>OnDemandRules</key> \n " ;
1439 print " <key>Action</key> \n " ;
1440 print " <string>Connect</string> \n " ;
1442 print " </array> \n " ;
1447 if ( $confighash { $key }[ 4 ] eq "cert" ) {
1449 print " <key>PayloadIdentifier</key> \n " ;
1450 print " <string>org.example.vpn1.client</string> \n " ;
1451 print " <key>PayloadDisplayName</key> \n " ;
1452 print " <string> $confighash { $key }[1]</string> \n " ;
1453 print " <key>PayloadUUID</key> \n " ;
1454 print " <string>${cert_uuid}</string> \n " ;
1455 print " <key>PayloadType</key> \n " ;
1456 print " <string>com.apple.security.pkcs12</string> \n " ;
1457 print " <key>PayloadVersion</key> \n " ;
1458 print " <integer>1</integer> \n " ;
1459 print " <key>PayloadContent</key> \n " ;
1462 foreach ( split /\n/ ,${ cert
}) {
1470 print " </array> \n " ;
1477 ### Display certificate
1479 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
1480 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1482 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1483 & Header
:: showhttpheaders
();
1484 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1485 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1486 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'cert'}:" );
1487 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1488 $output = & Header
:: cleanhtml
( $output , "y" );
1489 print "<pre> $output </pre> \n " ;
1490 & Header
:: closebox
();
1491 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1492 & Header
:: closebigbox
();
1493 & Header
:: closepage
();
1498 ### Export Certificate to browser
1500 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
1501 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1503 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1504 print "Content-Type: application/force-download \n " ;
1505 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \n\n " ;
1506 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1511 ### Enable/Disable connection
1513 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1515 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1516 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1518 if ( $confighash { $cgiparams { 'KEY' }}) {
1519 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
1520 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
1521 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1523 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1525 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
1526 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1528 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1532 $errormessage = $Lang :: tr
{ 'invalid key' };
1536 ### Restart connection
1538 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
1539 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1540 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1542 if ( $confighash { $cgiparams { 'KEY' }}) {
1544 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
1548 $errormessage = $Lang :: tr
{ 'invalid key' };
1552 ### Remove connection
1554 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
1555 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1556 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1558 if ( $confighash { $cgiparams { 'KEY' }}) {
1559 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1560 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1561 delete $confighash { $cgiparams { 'KEY' }};
1562 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1564 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1566 $errormessage = $Lang :: tr
{ 'invalid key' };
1568 & General
:: firewall_reload
();
1570 ### Choose between adding a host-net or net-net connection
1572 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
1573 & Header
:: showhttpheaders
();
1574 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
1575 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1576 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection type' });
1578 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
1579 <b> $Lang ::tr{'connection type'}:</b><br />
1581 <tr><td><input type='radio' name='TYPE' value='host' checked='checked' /></td>
1582 <td class='base'> $Lang ::tr{'host to net vpn'}</td>
1584 <td><input type='radio' name='TYPE' value='net' /></td>
1585 <td class='base'> $Lang ::tr{'net to net vpn'}</td>
1587 <td align='center' colspan='2'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td>
1592 & Header
:: closebox
();
1593 & Header
:: closebigbox
();
1594 & Header
:: closepage
();
1597 ### Adding/Editing/Saving a connection
1599 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
1600 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
1601 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
1603 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1604 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1605 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1607 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
1608 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
1609 $errormessage = $Lang :: tr
{ 'invalid key' };
1612 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
1613 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
1614 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
1615 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
1616 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
1617 $cgiparams { 'LOCAL' } = $confighash { $cgiparams { 'KEY' }}[ 6 ];
1618 $cgiparams { 'LOCAL_ID' } = $confighash { $cgiparams { 'KEY' }}[ 7 ];
1619 my @local_subnets = split ( "," , $confighash { $cgiparams { 'KEY' }}[ 8 ]);
1620 $cgiparams { 'LOCAL_SUBNET' } = join ( /\|/ , @local_subnets );
1621 $cgiparams { 'REMOTE_ID' } = $confighash { $cgiparams { 'KEY' }}[ 9 ];
1622 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
1623 my @remote_subnets = split ( "," , $confighash { $cgiparams { 'KEY' }}[ 11 ]);
1624 $cgiparams { 'REMOTE_SUBNET' } = join ( /\|/ , @remote_subnets );
1625 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
1626 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
1627 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
1628 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
1629 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
1630 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
1631 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
1632 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
1633 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
1634 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
1635 if ( $cgiparams { 'ESP_GROUPTYPE' } eq "" ) {
1636 $cgiparams { 'ESP_GROUPTYPE' } = $cgiparams { 'IKE_GROUPTYPE' };
1638 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
1639 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
1640 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
1641 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
1642 $cgiparams { 'DPD_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
1643 $cgiparams { 'DPD_DELAY' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
1644 $cgiparams { 'FORCE_MOBIKE' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
1645 $cgiparams { 'START_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 33 ];
1646 $cgiparams { 'INACTIVITY_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 34 ];
1647 $cgiparams { 'MODE' } = $confighash { $cgiparams { 'KEY' }}[ 35 ];
1648 $cgiparams { 'INTERFACE_MODE' } = $confighash { $cgiparams { 'KEY' }}[ 36 ];
1649 $cgiparams { 'INTERFACE_ADDRESS' } = $confighash { $cgiparams { 'KEY' }}[ 37 ];
1650 $cgiparams { 'INTERFACE_MTU' } = $confighash { $cgiparams { 'KEY' }}[ 38 ];
1651 $cgiparams { 'DNS_SERVERS' } = $confighash { $cgiparams { 'KEY' }}[ 39 ];
1653 if (! $cgiparams { 'DPD_DELAY' }) {
1654 $cgiparams { 'DPD_DELAY' } = 30 ;
1657 if (! $cgiparams { 'DPD_TIMEOUT' }) {
1658 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
1661 if ( $cgiparams { 'INACTIVITY_TIMEOUT' } eq "" ) {
1662 $cgiparams { 'INACTIVITY_TIMEOUT' } = 900 ;
1665 if ( $cgiparams { 'MODE' } eq "" ) {
1666 $cgiparams { 'MODE' } = "tunnel" ;
1669 if ( $cgiparams { 'INTERFACE_MTU' } eq "" ) {
1670 $cgiparams { 'INTERFACE_MTU' } = 1500 ;
1673 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
1674 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
1675 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
1676 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
1680 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
1681 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
1685 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
1686 $errormessage = $Lang :: tr
{ 'name is invalid' };
1690 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
1691 $errormessage = $Lang :: tr
{ 'name too long' };
1695 # Check if there is no other entry with this name
1696 if (! $cgiparams { 'KEY' }) { #only for add
1697 foreach my $key ( keys %confighash ) {
1698 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
1699 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
1705 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! $cgiparams { 'REMOTE' })) {
1706 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1710 if ( $cgiparams { 'LOCAL' }) {
1711 if (( $cgiparams { 'LOCAL' } ne "" ) && (!& General
:: validip
( $cgiparams { 'LOCAL' }))) {
1712 $errormessage = $Lang :: tr
{ 'invalid input for local ip address' };
1717 if ( $cgiparams { 'REMOTE' }) {
1718 if (( $cgiparams { 'REMOTE' } ne ' %any ' ) && (! & General
:: validip
( $cgiparams { 'REMOTE' }))) {
1719 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
1720 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1723 if (& valid_dns_host
( $cgiparams { 'REMOTE' })) {
1724 $warnmessage = " $Lang ::tr{'check vpn lr'} $cgiparams {'REMOTE'}. $Lang ::tr{'dns check failed'}" ;
1730 my @local_subnets = split ( "," , $cgiparams { 'LOCAL_SUBNET' });
1731 foreach my $subnet ( @local_subnets ) {
1732 unless (& Network
:: check_subnet
( $subnet )) {
1733 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
1738 # Allow only one roadwarrior/psk without remote IP-address
1739 if ( $cgiparams { 'REMOTE' } eq '' && $cgiparams { 'AUTH' } eq 'psk' ) {
1740 foreach my $key ( keys %confighash ) {
1741 if ( ( $cgiparams { 'KEY' } ne $key ) &&
1742 ( $confighash { $key }[ 4 ] eq 'psk' ) &&
1743 ( $confighash { $key }[ 10 ] eq '' ) ) {
1744 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
1750 if ( $cgiparams { 'TYPE' } eq 'net' ) {
1751 my @remote_subnets = split ( "," , $cgiparams { 'REMOTE_SUBNET' });
1752 foreach my $subnet ( @remote_subnets ) {
1753 unless (& Network
:: check_subnet
( $subnet )) {
1754 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
1759 if ( $cgiparams { 'MODE' } !~ /^(tunnel|transport)$/ ) {
1760 $errormessage = $Lang :: tr
{ 'invalid input for mode' };
1764 if ( $cgiparams { 'INTERFACE_MODE' } !~ /^(|gre|vti)$/ ) {
1765 $errormessage = $Lang :: tr
{ 'invalid input for interface mode' };
1769 if (( $cgiparams { 'INTERFACE_MODE' } eq "vti" ) && ( $cgiparams { 'MODE' } eq "transport" )) {
1770 $errormessage = $Lang :: tr
{ 'transport mode does not support vti' };
1774 if (( $cgiparams { 'INTERFACE_MODE' } ne "" ) && !& Network
:: check_subnet
( $cgiparams { 'INTERFACE_ADDRESS' })) {
1775 $errormessage = $Lang :: tr
{ 'invalid input for interface address' };
1779 if ( $cgiparams { 'INTERFACE_MTU' } !~ /^\d+$/ ) {
1780 $errormessage = $Lang :: tr
{ 'invalid input for interface mtu' };
1785 if ( $cgiparams { 'TYPE' } eq 'host' ) {
1786 my @servers = split ( "," , $cgiparams { 'DNS_SERVERS' });
1787 foreach my $server ( @servers ) {
1788 unless (& Network
:: check_ip_address
( $server )) {
1789 $errormessage = $Lang :: tr
{ 'ipsec dns server address is invalid' };
1795 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
1796 $errormessage = $Lang :: tr
{ 'invalid input' };
1799 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
1800 $errormessage = $Lang :: tr
{ 'invalid input' };
1804 # Allow nothing or a string (DN,FDQN,) beginning with @
1805 # with no comma but slashes between RID eg @O=FR/C=Paris/OU=myhome/CN=franck
1806 if ( ( $cgiparams { 'LOCAL_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1807 ( $cgiparams { 'REMOTE_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d
+ \
. \d
+ \
. \d
+ \
. \d
+)$/) ||
1808 (( $cgiparams { 'REMOTE_ID' } eq $cgiparams { 'LOCAL_ID' }) && ( $cgiparams { 'LOCAL_ID' } ne '' ))
1810 $errormessage = $Lang :: tr
{ 'invalid local-remote id' } . '<br />' .
1811 'DER_ASN1_DN: @c =FR/ou=Paris/ou=Home/cn=*<br />' .
1812 'FQDN: @ipfire .org<br />' .
1813 'USER_FQDN: info @ipfire .org<br />' .
1814 'IPV4_ADDR: 123.123.123.123' ;
1817 # If Auth is DN, verify existance of Remote ID.
1818 if ( $cgiparams { 'REMOTE_ID' } eq '' && (
1819 $cgiparams { 'AUTH' } eq 'auth-dn' || # while creation
1820 $confighash { $cgiparams { 'KEY' }}[ 2 ] eq ' %auth -dn' )){ # while editing
1821 $errormessage = $Lang :: tr
{ 'vpn missing remote id' };
1825 if ( $cgiparams { 'TYPE' } eq 'net' ){
1826 $warnmessage =& General
:: checksubnets
( '' , $cgiparams { 'REMOTE_SUBNET' }, 'ipsec' );
1827 if ( $warnmessage ne '' ){
1828 $warnmessage = $Lang :: tr
{ 'remote subnet' }. " ( $cgiparams {'REMOTE_SUBNET'}) <br>" . $warnmessage ;
1832 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1833 if (! length ( $cgiparams { 'PSK' }) ) {
1834 $errormessage = $Lang :: tr
{ 'pre-shared key is too short' };
1837 if ( $cgiparams { 'PSK' } =~ /'/ ) {
1838 $cgiparams { 'PSK' } =~ tr/'/ / ;
1839 $errormessage = $Lang :: tr
{ 'invalid characters found in pre-shared key' };
1842 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
1843 if ( $cgiparams { 'KEY' }) {
1844 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1847 unless ( ref ( $cgiparams { 'FH' })) {
1848 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1852 # Move uploaded certificate request to a temporary file
1853 ( my $fh , my $filename ) = tempfile
( );
1854 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1859 # Sign the certificate request
1860 & General
:: log ( "ipsec" , "Signing your cert $cgiparams {'NAME'}..." );
1861 my $opt = " ca -md sha256 -days 825" ;
1862 $opt .= " -batch -notext" ;
1863 $opt .= " -in $filename " ;
1864 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1866 if ( $errormessage = & callssl
( $opt ) ) {
1868 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1869 & cleanssldatabase
();
1873 & cleanssldatabase
();
1876 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1877 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1878 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1881 } elsif ( $cgiparams { 'AUTH' } eq 'pkcs12' ) {
1882 & General
:: log ( "ipsec" , "Importing from p12..." );
1884 unless ( ref ( $cgiparams { 'FH' })) {
1885 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1886 goto ROOTCERT_ERROR
;
1889 # Move uploaded certificate request to a temporary file
1890 ( my $fh , my $filename ) = tempfile
( );
1891 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1893 goto ROOTCERT_ERROR
;
1896 # Extract the CA certificate from the file
1897 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
1898 if ( open ( STDIN
, "-|" )) {
1899 my $opt = " pkcs12 -cacerts -nokeys" ;
1900 $opt .= " -in $filename " ;
1901 $opt .= " -out /tmp/newcacert" ;
1902 $errormessage = & callssl
( $opt );
1904 print " $cgiparams {'P12_PASS'} \n " ;
1908 # Extract the Host certificate from the file
1909 if (! $errormessage ) {
1910 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
1911 if ( open ( STDIN
, "-|" )) {
1912 my $opt = " pkcs12 -clcerts -nokeys" ;
1913 $opt .= " -in $filename " ;
1914 $opt .= " -out /tmp/newhostcert" ;
1915 $errormessage = & callssl
( $opt );
1917 print " $cgiparams {'P12_PASS'} \n " ;
1922 if (! $errormessage ) {
1923 & General
:: log ( "ipsec" , "Moving cacert..." );
1924 #If CA have new subject, add it to our list of CA
1925 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( '/tmp/newcacert' ));
1927 foreach my $x ( keys %cahash ) {
1928 $casubject = '' if ( $cahash { $x }[ 1 ] eq $casubject );
1929 unshift ( @names , $cahash { $x }[ 0 ]);
1931 if ( $casubject ) { # a new one!
1932 my $temp = `/usr/bin/openssl x509 -text -in /tmp/newcacert` ;
1933 if ( $temp !~ /CA:TRUE/i ) {
1934 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
1936 #compute a name for it
1938 while ( grep ( /Imported-$idx/ , @names ) ) { $idx ++};
1939 $cgiparams { 'CA_NAME' }= "Imported- $idx " ;
1940 $cgiparams { 'CERT_NAME' }=& Header
:: cleanhtml
( getCNfromcert
( '/tmp/newhostcert' ));
1941 move
( "/tmp/newcacert" , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1942 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1943 if (! $errormessage ) {
1944 my $key = & General
:: findhasharraykey
( \
%cahash );
1945 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
1946 $cahash { $key }[ 1 ] = $casubject ;
1947 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1948 system ( '/usr/local/bin/ipsecctrl' , 'R' );
1953 if (! $errormessage ) {
1954 & General
:: log ( "ipsec" , "Moving host cert..." );
1955 move
( "/tmp/newhostcert" , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1956 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1961 unlink ( '/tmp/newcacert' );
1962 unlink ( '/tmp/newhostcert' );
1963 if ( $errormessage ) {
1964 unlink ( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1965 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1968 & General
:: log ( "ipsec" , "p12 import completed!" );
1969 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
1970 if ( $cgiparams { 'KEY' }) {
1971 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1974 unless ( ref ( $cgiparams { 'FH' })) {
1975 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1978 # Move uploaded certificate to a temporary file
1979 ( my $fh , my $filename ) = tempfile
( );
1980 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1985 # Verify the certificate has a valid CA and move it
1986 & General
:: log ( "ipsec" , "Validating imported cert against our known CA..." );
1987 my $validca = 1 ; #assume ok
1988 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/cacert.pem $filename ` ;
1989 if ( $test !~ /: OK/ ) {
1991 foreach my $key ( keys %cahash ) {
1992 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $key }[0]cert.pem $filename ` ;
1993 if ( $test =~ /: OK/ ) {
2000 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
2004 move
( $filename , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
2006 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
2012 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
2013 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
2014 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
2015 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
2018 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
2019 if ( $cgiparams { 'KEY' }) {
2020 $errormessage = $Lang :: tr
{ 'cant change certificates' };
2023 # Validate input since the form was submitted
2024 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
2025 $errormessage = $Lang :: tr
{ 'name too long' };
2028 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
2029 $errormessage = $Lang :: tr
{ 'invalid input for name' };
2032 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
2033 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
2036 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
2037 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
2040 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
2041 $errormessage = $Lang :: tr
{ 'invalid input for department' };
2044 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
2045 $errormessage = $Lang :: tr
{ 'organization too long' };
2048 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
2049 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
2052 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
2053 $errormessage = $Lang :: tr
{ 'invalid input for city' };
2056 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
2057 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
2060 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
2061 $errormessage = $Lang :: tr
{ 'invalid input for country' };
2064 #the exact syntax is a list comma separated of
2065 # email:any-validemail
2066 # URI: a uniform resource indicator
2067 # DNS: a DNS domain name
2068 # RID: a registered OBJECT IDENTIFIER
2070 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
2072 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
2073 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
2077 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
2078 $errormessage = $Lang :: tr
{ 'password too short' };
2081 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
2082 $errormessage = $Lang :: tr
{ 'passwords do not match' };
2086 # Replace empty strings with a .
2087 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
2088 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
2089 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
2091 # Create the Client certificate request
2092 & General
:: log ( "ipsec" , "Creating a cert..." );
2094 if ( open ( STDIN
, "-|" )) {
2095 my $opt = " req -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
2096 $opt .= " -newkey rsa:2048" ;
2097 $opt .= " -keyout ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
2098 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
2100 if ( $errormessage = & callssl
( $opt ) ) {
2101 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
2102 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
2106 print " $cgiparams {'CERT_COUNTRY'} \n " ;
2109 print " $cgiparams {'CERT_ORGANIZATION'} \n " ;
2111 print " $cgiparams {'CERT_NAME'} \n " ;
2112 print " $cgiparams {'CERT_EMAIL'} \n " ;
2118 # Sign the client certificate request
2119 & General
:: log ( "ipsec" , "Signing the cert $cgiparams {'NAME'}..." );
2121 #No easy way for specifying the contain of subjectAltName without writing a config file...
2122 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
2124 basicConstraints=CA:FALSE
2125 nsComment="OpenSSL Generated Certificate"
2126 subjectKeyIdentifier=hash
2127 extendedKeyUsage=clientAuth
2128 authorityKeyIdentifier=keyid,issuer:always
2131 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
2134 my $opt = " ca -md sha256 -days 825 -batch -notext" ;
2135 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
2136 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
2137 $opt .= " -extfile $v3extname " ;
2139 if ( $errormessage = & callssl
( $opt ) ) {
2140 unlink ( $v3extname );
2141 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
2142 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
2143 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
2144 & cleanssldatabase
();
2147 unlink ( $v3extname );
2148 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
2149 & cleanssldatabase
();
2152 # Create the pkcs12 file
2153 & General
:: log ( "ipsec" , "Packing a pkcs12 file..." );
2154 $opt = " pkcs12 -export" ;
2155 $opt .= " -inkey ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
2156 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
2157 $opt .= " -name \" $cgiparams {'NAME'} \" " ;
2158 $opt .= " -passout pass: $cgiparams {'CERT_PASS1'}" ;
2159 $opt .= " -certfile ${General::swroot}/ca/cacert.pem" ;
2160 $opt .= " -caname \" $vpnsettings {'ROOTCERT_ORGANIZATION'} CA \" " ;
2161 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}.p12" ;
2163 if ( $errormessage = & callssl
( $opt ) ) {
2164 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
2165 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
2166 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}.p12" );
2169 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
2171 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
2172 ; # Nothing, just editing
2173 } elsif ( $cgiparams { 'AUTH' } eq 'auth-dn' ) {
2174 $cgiparams { 'CERT_NAME' } = ' %auth -dn' ; # a special value saying 'no cert file'
2176 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
2180 # 1)Error message here is not accurate.
2181 # 2)Test is superfluous, openswan can reference same cert multiple times
2182 # 3)Present since initial version (1.3.2.11), it isn't a bug correction
2183 # Check if there is no other entry with this certificate name
2184 #if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk') && ($cgiparams{'AUTH'} ne 'auth-dn')) {
2185 # foreach my $key (keys %confighash) {
2186 # if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) {
2187 # $errormessage = $Lang::tr{'a connection with this common name already exists'};
2188 # goto VPNCONF_ERROR;
2194 my $key = $cgiparams { 'KEY' };
2196 $key = & General
:: findhasharraykey
( \
%confighash );
2197 foreach my $i ( 0 .. 39 ) { $confighash { $key }[ $i ] = "" ;}
2199 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
2200 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
2201 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
2202 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
2204 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
2205 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
2206 $confighash { $key }[ 4 ] = 'psk' ;
2207 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
2209 $confighash { $key }[ 4 ] = 'cert' ;
2211 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2212 my @remote_subnets = split ( "," , $cgiparams { 'REMOTE_SUBNET' });
2213 $confighash { $key }[ 11 ] = join ( '|' , @remote_subnets );
2215 $confighash { $key }[ 6 ] = $cgiparams { 'LOCAL' };
2216 $confighash { $key }[ 7 ] = $cgiparams { 'LOCAL_ID' };
2217 my @local_subnets = split ( "," , $cgiparams { 'LOCAL_SUBNET' });
2218 $confighash { $key }[ 8 ] = join ( '|' , @local_subnets );
2219 $confighash { $key }[ 9 ] = $cgiparams { 'REMOTE_ID' };
2220 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
2221 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
2222 $confighash { $key }[ 26 ] = "" ; # Formerly INTERFACE
2223 $confighash { $key }[ 27 ] = $cgiparams { 'DPD_ACTION' };
2224 $confighash { $key }[ 29 ] = $cgiparams { 'IKE_VERSION' };
2226 # don't forget advanced value
2227 $confighash { $key }[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
2228 $confighash { $key }[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
2229 $confighash { $key }[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
2230 $confighash { $key }[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
2231 $confighash { $key }[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
2232 $confighash { $key }[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
2233 $confighash { $key }[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
2234 $confighash { $key }[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
2235 $confighash { $key }[ 12 ] = 'off' ; # $cgiparams{'AGGRMODE'};
2236 $confighash { $key }[ 13 ] = $cgiparams { 'COMPRESSION' };
2237 $confighash { $key }[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
2238 $confighash { $key }[ 28 ] = $cgiparams { 'PFS' };
2239 $confighash { $key }[ 30 ] = $cgiparams { 'DPD_TIMEOUT' };
2240 $confighash { $key }[ 31 ] = $cgiparams { 'DPD_DELAY' };
2241 $confighash { $key }[ 32 ] = $cgiparams { 'FORCE_MOBIKE' };
2242 $confighash { $key }[ 33 ] = $cgiparams { 'START_ACTION' };
2243 $confighash { $key }[ 34 ] = $cgiparams { 'INACTIVITY_TIMEOUT' };
2244 $confighash { $key }[ 35 ] = $cgiparams { 'MODE' };
2245 $confighash { $key }[ 36 ] = $cgiparams { 'INTERFACE_MODE' };
2246 $confighash { $key }[ 37 ] = $cgiparams { 'INTERFACE_ADDRESS' };
2247 $confighash { $key }[ 38 ] = $cgiparams { 'INTERFACE_MTU' };
2248 $confighash { $key }[ 39 ] = join ( "|" , split ( "," , $cgiparams { 'DNS_SERVERS' }));
2250 # free unused fields!
2251 $confighash { $key }[ 15 ] = 'off' ;
2253 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2256 system ( '/usr/local/bin/ipsecctrl' , 'S' , $key );
2259 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
2260 $cgiparams { 'KEY' } = $key ;
2261 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
2264 } else { # add new connection
2265 $cgiparams { 'ENABLED' } = 'on' ;
2266 if ( ! - f
"${General::swroot}/private/cakey.pem" ) {
2267 $cgiparams { 'AUTH' } = 'psk' ;
2268 } elsif ( ! - f
"${General::swroot}/ca/cacert.pem" ) {
2269 $cgiparams { 'AUTH' } = 'certfile' ;
2271 $cgiparams { 'AUTH' } = 'certgen' ;
2274 if ( $netsettings { "GREEN_NETADDRESS" } && $netsettings { "GREEN_NETMASK" }) {
2275 $cgiparams { "LOCAL_SUBNET" } = $netsettings { 'GREEN_NETADDRESS' } . "/" . $netsettings { 'GREEN_NETMASK' };
2277 $cgiparams { "LOCAL_SUBNET" } = "" ;
2279 $cgiparams { 'CERT_EMAIL' } = $vpnsettings { 'ROOTCERT_EMAIL' };
2280 $cgiparams { 'CERT_OU' } = $vpnsettings { 'ROOTCERT_OU' };
2281 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
2282 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
2283 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
2284 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
2286 # choose appropriate dpd action
2287 if ( $cgiparams { 'TYPE' } eq 'host' ) {
2288 $cgiparams { 'DPD_ACTION' } = 'clear' ;
2290 $cgiparams { 'DPD_ACTION' } = 'restart' ;
2293 if (! $cgiparams { 'DPD_DELAY' }) {
2294 $cgiparams { 'DPD_DELAY' } = 30 ;
2297 if (! $cgiparams { 'DPD_TIMEOUT' }) {
2298 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
2301 if (! $cgiparams { 'FORCE_MOBIKE' }) {
2302 $cgiparams { 'FORCE_MOBIKE' } = 'no' ;
2305 # Default IKE Version to v2
2306 if (! $cgiparams { 'IKE_VERSION' }) {
2307 $cgiparams { 'IKE_VERSION' } = 'ikev2' ;
2311 $cgiparams { 'LOCAL_ID' } = '' ;
2312 $cgiparams { 'REMOTE_ID' } = '' ;
2314 #use default advanced value
2315 $cgiparams { 'IKE_ENCRYPTION' } = 'chacha20poly1305|aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128' ; #[18];
2316 $cgiparams { 'IKE_INTEGRITY' } = 'sha2_512|sha2_256' ; #[19];
2317 $cgiparams { 'IKE_GROUPTYPE' } = 'curve25519|curve448|4096|3072|2048' ; #[20];
2318 $cgiparams { 'IKE_LIFETIME' } = '3' ; #[16];
2319 $cgiparams { 'ESP_ENCRYPTION' } = 'chacha20poly1305|aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128' ; #[21];
2320 $cgiparams { 'ESP_INTEGRITY' } = 'sha2_512|sha2_256' ; #[22];
2321 $cgiparams { 'ESP_GROUPTYPE' } = 'curve25519|curve448|4096|3072|2048' ; #[23];
2322 $cgiparams { 'ESP_KEYLIFE' } = '1' ; #[17];
2323 $cgiparams { 'COMPRESSION' } = 'off' ; #[13];
2324 $cgiparams { 'ONLY_PROPOSED' } = 'on' ; #[24];
2325 $cgiparams { 'PFS' } = 'on' ; #[28];
2326 $cgiparams { 'INACTIVITY_TIMEOUT' } = 900 ;
2327 $cgiparams { 'MODE' } = "tunnel" ;
2328 $cgiparams { 'INTERFACE_MODE' } = "" ;
2329 $cgiparams { 'INTERFACE_ADDRESS' } = "" ;
2330 $cgiparams { 'INTERFACE_MTU' } = 1500 ;
2331 $cgiparams { 'DNS_SERVERS' } = "" ;
2335 $checked { 'ENABLED' }{ 'off' } = '' ;
2336 $checked { 'ENABLED' }{ 'on' } = '' ;
2337 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = "checked='checked'" ;
2339 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
2340 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
2341 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = "checked='checked'" ;
2343 $checked { 'AUTH' }{ 'psk' } = '' ;
2344 $checked { 'AUTH' }{ 'certreq' } = '' ;
2345 $checked { 'AUTH' }{ 'certgen' } = '' ;
2346 $checked { 'AUTH' }{ 'certfile' } = '' ;
2347 $checked { 'AUTH' }{ 'pkcs12' } = '' ;
2348 $checked { 'AUTH' }{ 'auth-dn' } = '' ;
2349 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = "checked='checked'" ;
2351 $selected { 'MODE' }{ 'tunnel' } = '' ;
2352 $selected { 'MODE' }{ 'transport' } = '' ;
2353 $selected { 'MODE' }{ $cgiparams { 'MODE' }} = "selected='selected'" ;
2355 $selected { 'INTERFACE_MODE' }{ '' } = '' ;
2356 $selected { 'INTERFACE_MODE' }{ 'gre' } = '' ;
2357 $selected { 'INTERFACE_MODE' }{ 'vti' } = '' ;
2358 $selected { 'INTERFACE_MODE' }{ $cgiparams { 'INTERFACE_MODE' }} = "selected='selected'" ;
2360 $selected { 'LOCAL' }{ '' } = '' ;
2361 foreach my $alias ( sort keys %aliases ) {
2362 my $address = $aliases { $alias }{ 'IPT' };
2364 $selected { 'LOCAL' }{ $address } = '' ;
2366 $selected { 'LOCAL' }{ $cgiparams { 'LOCAL' }} = "selected='selected'" ;
2368 & Header
:: showhttpheaders
();
2369 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
2370 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2371 if ( $errormessage ) {
2372 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2373 print "<class name='base'> $errormessage " ;
2374 print " </class>" ;
2375 & Header
:: closebox
();
2379 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'warning messages'}:" );
2380 print "<class name='base'> $warnmessage " ;
2381 print " </class>" ;
2382 & Header
:: closebox
();
2385 print "<form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>" ;
2387 <input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />
2388 <input type='hidden' name='IKE_VERSION' value=' $cgiparams {'IKE_VERSION'}' />
2389 <input type='hidden' name='IKE_ENCRYPTION' value=' $cgiparams {'IKE_ENCRYPTION'}' />
2390 <input type='hidden' name='IKE_INTEGRITY' value=' $cgiparams {'IKE_INTEGRITY'}' />
2391 <input type='hidden' name='IKE_GROUPTYPE' value=' $cgiparams {'IKE_GROUPTYPE'}' />
2392 <input type='hidden' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' />
2393 <input type='hidden' name='ESP_ENCRYPTION' value=' $cgiparams {'ESP_ENCRYPTION'}' />
2394 <input type='hidden' name='ESP_INTEGRITY' value=' $cgiparams {'ESP_INTEGRITY'}' />
2395 <input type='hidden' name='ESP_GROUPTYPE' value=' $cgiparams {'ESP_GROUPTYPE'}' />
2396 <input type='hidden' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' />
2397 <input type='hidden' name='COMPRESSION' value=' $cgiparams {'COMPRESSION'}' />
2398 <input type='hidden' name='ONLY_PROPOSED' value=' $cgiparams {'ONLY_PROPOSED'}' />
2399 <input type='hidden' name='PFS' value=' $cgiparams {'PFS'}' />
2400 <input type='hidden' name='DPD_ACTION' value=' $cgiparams {'DPD_ACTION'}' />
2401 <input type='hidden' name='DPD_DELAY' value=' $cgiparams {'DPD_DELAY'}' />
2402 <input type='hidden' name='DPD_TIMEOUT' value=' $cgiparams {'DPD_TIMEOUT'}' />
2403 <input type='hidden' name='FORCE_MOBIKE' value=' $cgiparams {'FORCE_MOBIKE'}' />
2404 <input type='hidden' name='START_ACTION' value=' $cgiparams {'START_ACTION'}' />
2405 <input type='hidden' name='INACTIVITY_TIMEOUT' value=' $cgiparams {'INACTIVITY_TIMEOUT'}' />
2408 if ( $cgiparams { 'KEY' }) {
2409 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
2410 print "<input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' />" ;
2411 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
2414 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'connection'}: $cgiparams {'NAME'}" );
2415 print "<table width='100%'>" ;
2416 if (! $cgiparams { 'KEY' }) {
2419 <td width='20%'> $Lang ::tr{'name'}: <img src='/blob.gif' alt='*' /></td>
2421 <input type='text' name='NAME' value=' $cgiparams {'NAME'}' size='25' />
2423 <td colspan="2"></td>
2429 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2430 $blob = "<img src='/blob.gif' alt='*' />" ;
2433 my @local_subnets = split ( /\|/ , $cgiparams { 'LOCAL_SUBNET' });
2434 my $local_subnets = join ( "," , @local_subnets );
2436 my @remote_subnets = split ( /\|/ , $cgiparams { 'REMOTE_SUBNET' });
2437 my $remote_subnets = join ( "," , @remote_subnets );
2439 my @dns_servers = split ( /\|/ , $cgiparams { 'DNS_SERVERS' });
2440 my $dns_servers = join ( "," , @dns_servers );
2444 <td width='20%'> $Lang ::tr{'enabled'}</td>
2446 <input type='checkbox' name='ENABLED' $checked {'ENABLED'}{'on'} />
2448 <td colspan="2"></td>
2451 <td class='boldbase' width='20%'> $Lang ::tr{'local ip address'}:</td>
2453 <select name="LOCAL">
2454 <option value="" $selected {'LOCAL'}{''}>- $Lang ::tr{'default IP address'} -</option>
2457 foreach my $alias ( sort keys %aliases ) {
2458 my $address = $aliases { $alias }{ 'IPT' };
2460 <option value=" $address " $selected {'LOCAL'}{ $address }> $alias ( $address )</option>
2467 <td class='boldbase' width='20%'> $Lang ::tr{'remote host/ip'}: $blob </td>
2469 <input type='text' name='REMOTE' value=' $cgiparams {'REMOTE'}' size="25" />
2473 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'local subnet'} <img src='/blob.gif' alt='*' /></td>
2475 <input type='text' name='LOCAL_SUBNET' value=' $local_subnets ' size="25" />
2479 if ( $cgiparams { 'TYPE' } eq "net" ) {
2481 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'remote subnet'} <img src='/blob.gif' alt='*' /></td>
2483 <input type='text' name='REMOTE_SUBNET' value=' $remote_subnets ' size="25" />
2487 } elsif ( $cgiparams { 'TYPE' } eq "host" ) {
2489 <td class='boldbase' nowrap='nowrap' width='20%'> $Lang ::tr{'dns servers'}:</td>
2491 <input type='text' name='DNS_SERVERS' value=' $dns_servers ' size="25" />
2499 <td class='boldbase' width='20%'> $Lang ::tr{'vpn local id'}:</td>
2501 <input type='text' name='LOCAL_ID' value=' $cgiparams {'LOCAL_ID'}' size="25" />
2503 <td class='boldbase' width='20%'> $Lang ::tr{'vpn remote id'}:</td>
2505 <input type='text' name='REMOTE_ID' value=' $cgiparams {'REMOTE_ID'}' size="25" />
2508 <tr><td colspan="4"><br /></td></tr>
2510 <td class='boldbase' width='20%'> $Lang ::tr{'remark title'}</td>
2512 <input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' maxlength='50' size="73" />
2517 if (! $cgiparams { 'KEY' }) {
2518 print "<tr><td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked {'EDIT_ADVANCED'}{'on'} /> $Lang ::tr{'edit advanced settings when done'}</td></tr>" ;
2521 & Header
:: closebox
();
2523 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2524 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'ipsec settings' });
2526 <table width='100%'>
2529 <td class='boldbase' width='20%'> $Lang ::tr{'mode'}:</td>
2531 <select name='MODE'>
2532 <option value='tunnel' $selected {'MODE'}{'tunnel'}> $Lang ::tr{'ipsec mode tunnel'}</option>
2533 <option value='transport' $selected {'MODE'}{'transport'}> $Lang ::tr{'ipsec mode transport'}</option>
2536 <td colspan='2'></td>
2540 <td class='boldbase' width='20%'> $Lang ::tr{'interface mode'}:</td>
2542 <select name='INTERFACE_MODE'>
2543 <option value='' $selected {'INTERFACE_MODE'}{''}> $Lang ::tr{'ipsec interface mode none'}</option>
2544 <option value='gre' $selected {'INTERFACE_MODE'}{'gre'}> $Lang ::tr{'ipsec interface mode gre'}</option>
2545 <option value='vti' $selected {'INTERFACE_MODE'}{'vti'}> $Lang ::tr{'ipsec interface mode vti'}</option>
2549 <td class='boldbase' width='20%'> $Lang ::tr{'ip address'}/ $Lang ::tr{'subnet mask'}:</td>
2551 <input type="text" name="INTERFACE_ADDRESS" value=" $cgiparams {'INTERFACE_ADDRESS'}">
2556 <td class='boldbase' width='20%'> $Lang ::tr{'mtu'}:</td>
2558 <input type="number" name="INTERFACE_MTU" value=" $cgiparams {'INTERFACE_MTU'}" min="576" max="9000">
2560 <td colspan='2'></td>
2565 & Header
:: closebox
();
2568 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
2569 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2571 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2572 <tr><td class='base' width='50%'> $Lang ::tr{'use a pre-shared key'}</td>
2573 <td class='base' width='50%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td>
2578 & Header
:: closebox
();
2579 } elsif (! $cgiparams { 'KEY' }) {
2580 my $cakeydisabled = ( ! - f
"${General::swroot}/private/cakey.pem" ) ?
"disabled='disabled'" : '' ;
2581 $cgiparams { 'CERT_NAME' } = $Lang :: tr
{ 'vpn no full pki' } if ( $cakeydisabled );
2582 my $cacrtdisabled = ( ! - f
"${General::swroot}/ca/cacert.pem" ) ?
"disabled='disabled'" : '' ;
2584 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2586 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2587 <tr><td width='5%'><input type='radio' name='AUTH' value='psk' $checked {'AUTH'}{'psk'} /></td>
2588 <td class='base' width='55%'> $Lang ::tr{'use a pre-shared key'}</td>
2589 <td class='base' width='40%'><input type='password' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td></tr>
2590 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2591 <tr><td><input type='radio' name='AUTH' value='certreq' $checked {'AUTH'}{'certreq'} $cakeydisabled /></td>
2592 <td class='base'><hr /> $Lang ::tr{'upload a certificate request'}</td>
2593 <td class='base' rowspan='3' valign='middle'><input type='file' name='FH' size='30' $cacrtdisabled /></td></tr>
2594 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td>
2595 <td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
2596 <tr><td><input type='radio' name='AUTH' value='pkcs12' $cacrtdisabled /></td>
2597 <td class='base'> $Lang ::tr{'upload p12 file'} $Lang ::tr{'pkcs12 file password'}:<input type='password' name='P12_PASS'/></td></tr>
2598 <tr><td><input type='radio' name='AUTH' value='auth-dn' $checked {'AUTH'}{'auth-dn'} $cacrtdisabled /></td>
2599 <td class='base'><hr /> $Lang ::tr{'vpn auth-dn'}</td></tr>
2600 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2601 <tr><td><input type='radio' name='AUTH' value='certgen' $checked {'AUTH'}{'certgen'} $cakeydisabled /></td>
2602 <td class='base'><hr /> $Lang ::tr{'generate a certificate'}</td><td> </td></tr>
2604 <td class='base'> $Lang ::tr{'users fullname or system hostname'}: <img src='/blob.gif' alt='*' /></td>
2605 <td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' size='32' $cakeydisabled /></td></tr>
2607 <td class='base'> $Lang ::tr{'users email'}:</td>
2608 <td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' size='32' $cakeydisabled /></td></tr>
2610 <td class='base'> $Lang ::tr{'users department'}:</td>
2611 <td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' size='32' $cakeydisabled /></td></tr>
2613 <td class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
2614 <td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' size='32' $cakeydisabled /></td></tr>
2616 <td class='base'> $Lang ::tr{'city'}:</td>
2617 <td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' size='32' $cakeydisabled /></td></tr>
2619 <td class='base'> $Lang ::tr{'state or province'}:</td>
2620 <td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' size='32' $cakeydisabled /></td></tr>
2622 <td class='base'> $Lang ::tr{'country'}:</td>
2623 <td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
2626 foreach my $country ( sort keys %{ Countries
:: countries
}) {
2627 print " \t\t\t <option value=' $Countries ::countries{ $country }'" ;
2628 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
2629 print " selected='selected'" ;
2631 print "> $country </option> \n " ;
2636 <tr><td> </td><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)</td>
2637 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' $cakeydisabled /></td></tr>
2639 <td class='base'> $Lang ::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' /></td>
2640 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
2641 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'} ( $Lang ::tr{'confirmation'}): <img src='/blob.gif' alt='*' /></td>
2642 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
2646 & Header
:: closebox
();
2649 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
2650 if ( $cgiparams { 'KEY' }) {
2651 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced'}' />" ;
2653 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
2654 & Header
:: closebigbox
();
2655 & Header
:: closepage
();
2662 ### Advanced settings
2664 if (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced' }) ||
2665 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq 'yes' )) {
2666 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
2667 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2668 if (! $confighash { $cgiparams { 'KEY' }}) {
2669 $errormessage = $Lang :: tr
{ 'invalid key' };
2673 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
2674 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2676 $errormessage = $Lang :: tr
{ 'invalid input' };
2677 goto ADVANCED_ERROR
;
2679 foreach my $val ( @temp ) {
2680 if ( $val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|chacha20poly1305|camellia(256|192|128))$/ ) {
2681 $errormessage = $Lang :: tr
{ 'invalid input' };
2682 goto ADVANCED_ERROR
;
2685 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2687 $errormessage = $Lang :: tr
{ 'invalid input' };
2688 goto ADVANCED_ERROR
;
2690 foreach my $val ( @temp ) {
2691 if ( $val !~ /^(sha2_(512|384|256)|sha|md5|aesxcbc)$/ ) {
2692 $errormessage = $Lang :: tr
{ 'invalid input' };
2693 goto ADVANCED_ERROR
;
2696 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2698 $errormessage = $Lang :: tr
{ 'invalid input' };
2699 goto ADVANCED_ERROR
;
2701 foreach my $val ( @temp ) {
2702 if ( $val !~ /^(curve25519|curve448|e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|768|1024|1536|2048|3072|4096|6144|8192)$/ ) {
2703 $errormessage = $Lang :: tr
{ 'invalid input' };
2704 goto ADVANCED_ERROR
;
2707 if ( $cgiparams { 'IKE_LIFETIME' } !~ /^\d+$/ ) {
2708 $errormessage = $Lang :: tr
{ 'invalid input for ike lifetime' };
2709 goto ADVANCED_ERROR
;
2711 if ( $cgiparams { 'IKE_LIFETIME' } < 1 || $cgiparams { 'IKE_LIFETIME' } > 24 ) {
2712 $errormessage = $Lang :: tr
{ 'ike lifetime should be between 1 and 24 hours' };
2713 goto ADVANCED_ERROR
;
2715 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2717 $errormessage = $Lang :: tr
{ 'invalid input' };
2718 goto ADVANCED_ERROR
;
2720 foreach my $val ( @temp ) {
2721 if ( $val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|chacha20poly1305|camellia(256|192|128))$/ ) {
2722 $errormessage = $Lang :: tr
{ 'invalid input' };
2723 goto ADVANCED_ERROR
;
2726 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2728 $errormessage = $Lang :: tr
{ 'invalid input' };
2729 goto ADVANCED_ERROR
;
2731 foreach my $val ( @temp ) {
2732 if ( $val !~ /^(sha2_(512|384|256)|sha1|md5|aesxcbc)$/ ) {
2733 $errormessage = $Lang :: tr
{ 'invalid input' };
2734 goto ADVANCED_ERROR
;
2737 @temp = split ( '\|' , $cgiparams { 'ESP_GROUPTYPE' });
2739 $errormessage = $Lang :: tr
{ 'invalid input' };
2740 goto ADVANCED_ERROR
;
2742 foreach my $val ( @temp ) {
2743 if ( $val !~ /^(curve25519|curve448|e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|768|1024|1536|2048|3072|4096|6144|8192|none)$/ ) {
2744 $errormessage = $Lang :: tr
{ 'invalid input' };
2745 goto ADVANCED_ERROR
;
2748 if ( $cgiparams { 'ESP_KEYLIFE' } !~ /^\d+$/ ) {
2749 $errormessage = $Lang :: tr
{ 'invalid input for esp keylife' };
2750 goto ADVANCED_ERROR
;
2752 if ( $cgiparams { 'ESP_KEYLIFE' } < 1 || $cgiparams { 'ESP_KEYLIFE' } > 24 ) {
2753 $errormessage = $Lang :: tr
{ 'esp keylife should be between 1 and 24 hours' };
2754 goto ADVANCED_ERROR
;
2757 if (( $cgiparams { 'COMPRESSION' } !~ /^(|on|off)$/ ) ||
2758 ( $cgiparams { 'FORCE_MOBIKE' } !~ /^(|on|off)$/ ) ||
2759 ( $cgiparams { 'ONLY_PROPOSED' } !~ /^(|on|off)$/ ) ||
2760 ( $cgiparams { 'PFS' } !~ /^(|on|off)$/ )) {
2761 $errormessage = $Lang :: tr
{ 'invalid input' };
2762 goto ADVANCED_ERROR
;
2765 if ( $cgiparams { 'DPD_DELAY' } !~ /^\d+$/ ) {
2766 $errormessage = $Lang :: tr
{ 'invalid input for dpd delay' };
2767 goto ADVANCED_ERROR
;
2770 if ( $cgiparams { 'DPD_TIMEOUT' } !~ /^\d+$/ ) {
2771 $errormessage = $Lang :: tr
{ 'invalid input for dpd timeout' };
2772 goto ADVANCED_ERROR
;
2775 if ( $cgiparams { 'INACTIVITY_TIMEOUT' } !~ /^\d+$/ ) {
2776 $errormessage = $Lang :: tr
{ 'invalid input for inactivity timeout' };
2777 goto ADVANCED_ERROR
;
2780 $confighash { $cgiparams { 'KEY' }}[ 29 ] = $cgiparams { 'IKE_VERSION' };
2781 $confighash { $cgiparams { 'KEY' }}[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
2782 $confighash { $cgiparams { 'KEY' }}[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
2783 $confighash { $cgiparams { 'KEY' }}[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
2784 $confighash { $cgiparams { 'KEY' }}[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
2785 $confighash { $cgiparams { 'KEY' }}[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
2786 $confighash { $cgiparams { 'KEY' }}[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
2787 $confighash { $cgiparams { 'KEY' }}[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
2788 $confighash { $cgiparams { 'KEY' }}[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
2789 $confighash { $cgiparams { 'KEY' }}[ 12 ] = 'off' ; #$cgiparams{'AGGRMODE'};
2790 $confighash { $cgiparams { 'KEY' }}[ 13 ] = $cgiparams { 'COMPRESSION' };
2791 $confighash { $cgiparams { 'KEY' }}[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
2792 $confighash { $cgiparams { 'KEY' }}[ 28 ] = $cgiparams { 'PFS' };
2793 $confighash { $cgiparams { 'KEY' }}[ 27 ] = $cgiparams { 'DPD_ACTION' };
2794 $confighash { $cgiparams { 'KEY' }}[ 30 ] = $cgiparams { 'DPD_TIMEOUT' };
2795 $confighash { $cgiparams { 'KEY' }}[ 31 ] = $cgiparams { 'DPD_DELAY' };
2796 $confighash { $cgiparams { 'KEY' }}[ 32 ] = $cgiparams { 'FORCE_MOBIKE' };
2797 $confighash { $cgiparams { 'KEY' }}[ 33 ] = $cgiparams { 'START_ACTION' };
2798 $confighash { $cgiparams { 'KEY' }}[ 34 ] = $cgiparams { 'INACTIVITY_TIMEOUT' };
2799 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2802 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
2807 $cgiparams { 'IKE_VERSION' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
2808 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
2809 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
2810 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
2811 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
2812 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
2813 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
2814 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
2815 if ( $cgiparams { 'ESP_GROUPTYPE' } eq "" ) {
2816 $cgiparams { 'ESP_GROUPTYPE' } = $cgiparams { 'IKE_GROUPTYPE' };
2818 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
2819 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
2820 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
2821 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
2822 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
2823 $cgiparams { 'DPD_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
2824 $cgiparams { 'DPD_DELAY' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
2825 $cgiparams { 'FORCE_MOBIKE' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
2826 $cgiparams { 'START_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 33 ];
2827 $cgiparams { 'INACTIVITY_TIMEOUT' } = $confighash { $cgiparams { 'KEY' }}[ 34 ];
2828 $cgiparams { 'MODE' } = $confighash { $cgiparams { 'KEY' }}[ 35 ];
2829 $cgiparams { 'INTERFACE_MODE' } = $confighash { $cgiparams { 'KEY' }}[ 36 ];
2830 $cgiparams { 'INTERFACE_ADDRESS' } = $confighash { $cgiparams { 'KEY' }}[ 37 ];
2831 $cgiparams { 'INTERFACE_MTU' } = $confighash { $cgiparams { 'KEY' }}[ 38 ];
2832 $cgiparams { 'DNS_SERVERS' } = $confighash { $cgiparams { 'KEY' }}[ 39 ];
2834 if (! $cgiparams { 'DPD_DELAY' }) {
2835 $cgiparams { 'DPD_DELAY' } = 30 ;
2838 if (! $cgiparams { 'DPD_TIMEOUT' }) {
2839 $cgiparams { 'DPD_TIMEOUT' } = 120 ;
2842 if (! $cgiparams { 'START_ACTION' }) {
2843 $cgiparams { 'START_ACTION' } = "start" ;
2846 if ( $cgiparams { 'INACTIVITY_TIMEOUT' } eq "" ) {
2847 $cgiparams { 'INACTIVITY_TIMEOUT' } = 900 ; # 15 min
2850 if ( $cgiparams { 'MODE' } eq "" ) {
2851 $cgiparams { 'MODE' } = "tunnel" ;
2856 $checked { 'IKE_ENCRYPTION' }{ 'chacha20poly1305' } = '' ;
2857 $checked { 'IKE_ENCRYPTION' }{ 'aes256' } = '' ;
2858 $checked { 'IKE_ENCRYPTION' }{ 'aes192' } = '' ;
2859 $checked { 'IKE_ENCRYPTION' }{ 'aes128' } = '' ;
2860 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm128' } = '' ;
2861 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm128' } = '' ;
2862 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm128' } = '' ;
2863 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm96' } = '' ;
2864 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm96' } = '' ;
2865 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm96' } = '' ;
2866 $checked { 'IKE_ENCRYPTION' }{ 'aes256gcm64' } = '' ;
2867 $checked { 'IKE_ENCRYPTION' }{ 'aes192gcm64' } = '' ;
2868 $checked { 'IKE_ENCRYPTION' }{ 'aes128gcm64' } = '' ;
2869 $checked { 'IKE_ENCRYPTION' }{ '3des' } = '' ;
2870 $checked { 'IKE_ENCRYPTION' }{ 'camellia256' } = '' ;
2871 $checked { 'IKE_ENCRYPTION' }{ 'camellia192' } = '' ;
2872 $checked { 'IKE_ENCRYPTION' }{ 'camellia128' } = '' ;
2873 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2874 foreach my $key ( @temp ) { $checked { 'IKE_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2875 $checked { 'IKE_INTEGRITY' }{ 'sha2_512' } = '' ;
2876 $checked { 'IKE_INTEGRITY' }{ 'sha2_384' } = '' ;
2877 $checked { 'IKE_INTEGRITY' }{ 'sha2_256' } = '' ;
2878 $checked { 'IKE_INTEGRITY' }{ 'sha' } = '' ;
2879 $checked { 'IKE_INTEGRITY' }{ 'md5' } = '' ;
2880 $checked { 'IKE_INTEGRITY' }{ 'aesxcbc' } = '' ;
2881 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2882 foreach my $key ( @temp ) { $checked { 'IKE_INTEGRITY' }{ $key } = "selected='selected'" ; }
2883 $checked { 'IKE_GROUPTYPE' }{ 'curve25519' } = '' ;
2884 $checked { 'IKE_GROUPTYPE' }{ 'curve448' } = '' ;
2885 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2886 $checked { 'IKE_GROUPTYPE' }{ '1024' } = '' ;
2887 $checked { 'IKE_GROUPTYPE' }{ '1536' } = '' ;
2888 $checked { 'IKE_GROUPTYPE' }{ '2048' } = '' ;
2889 $checked { 'IKE_GROUPTYPE' }{ '3072' } = '' ;
2890 $checked { 'IKE_GROUPTYPE' }{ '4096' } = '' ;
2891 $checked { 'IKE_GROUPTYPE' }{ '6144' } = '' ;
2892 $checked { 'IKE_GROUPTYPE' }{ '8192' } = '' ;
2893 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2894 foreach my $key ( @temp ) { $checked { 'IKE_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2896 $checked { 'ESP_ENCRYPTION' }{ 'chacha20poly1305' } = '' ;
2897 $checked { 'ESP_ENCRYPTION' }{ 'aes256' } = '' ;
2898 $checked { 'ESP_ENCRYPTION' }{ 'aes192' } = '' ;
2899 $checked { 'ESP_ENCRYPTION' }{ 'aes128' } = '' ;
2900 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm128' } = '' ;
2901 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm128' } = '' ;
2902 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm128' } = '' ;
2903 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm96' } = '' ;
2904 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm96' } = '' ;
2905 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm96' } = '' ;
2906 $checked { 'ESP_ENCRYPTION' }{ 'aes256gcm64' } = '' ;
2907 $checked { 'ESP_ENCRYPTION' }{ 'aes192gcm64' } = '' ;
2908 $checked { 'ESP_ENCRYPTION' }{ 'aes128gcm64' } = '' ;
2909 $checked { 'ESP_ENCRYPTION' }{ '3des' } = '' ;
2910 $checked { 'ESP_ENCRYPTION' }{ 'camellia256' } = '' ;
2911 $checked { 'ESP_ENCRYPTION' }{ 'camellia192' } = '' ;
2912 $checked { 'ESP_ENCRYPTION' }{ 'camellia128' } = '' ;
2913 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2914 foreach my $key ( @temp ) { $checked { 'ESP_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2915 $checked { 'ESP_INTEGRITY' }{ 'sha2_512' } = '' ;
2916 $checked { 'ESP_INTEGRITY' }{ 'sha2_384' } = '' ;
2917 $checked { 'ESP_INTEGRITY' }{ 'sha2_256' } = '' ;
2918 $checked { 'ESP_INTEGRITY' }{ 'sha1' } = '' ;
2919 $checked { 'ESP_INTEGRITY' }{ 'md5' } = '' ;
2920 $checked { 'ESP_INTEGRITY' }{ 'aesxcbc' } = '' ;
2921 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2922 foreach my $key ( @temp ) { $checked { 'ESP_INTEGRITY' }{ $key } = "selected='selected'" ; }
2923 $checked { 'ESP_GROUPTYPE' }{ 'curve25519' } = '' ;
2924 $checked { 'ESP_GROUPTYPE' }{ 'curve448' } = '' ;
2925 $checked { 'ESP_GROUPTYPE' }{ '768' } = '' ;
2926 $checked { 'ESP_GROUPTYPE' }{ '1024' } = '' ;
2927 $checked { 'ESP_GROUPTYPE' }{ '1536' } = '' ;
2928 $checked { 'ESP_GROUPTYPE' }{ '2048' } = '' ;
2929 $checked { 'ESP_GROUPTYPE' }{ '3072' } = '' ;
2930 $checked { 'ESP_GROUPTYPE' }{ '4096' } = '' ;
2931 $checked { 'ESP_GROUPTYPE' }{ '6144' } = '' ;
2932 $checked { 'ESP_GROUPTYPE' }{ '8192' } = '' ;
2933 $checked { 'ESP_GROUPTYPE' }{ 'none' } = '' ;
2934 @temp = split ( '\|' , $cgiparams { 'ESP_GROUPTYPE' });
2935 foreach my $key ( @temp ) { $checked { 'ESP_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2937 $checked { 'COMPRESSION' } = $cgiparams { 'COMPRESSION' } eq 'on' ?
"checked='checked'" : '' ;
2938 $checked { 'FORCE_MOBIKE' } = $cgiparams { 'FORCE_MOBIKE' } eq 'on' ?
"checked='checked'" : '' ;
2939 $checked { 'ONLY_PROPOSED' } = $cgiparams { 'ONLY_PROPOSED' } eq 'on' ?
"checked='checked'" : '' ;
2940 $checked { 'PFS' } = $cgiparams { 'PFS' } eq 'on' ?
"checked='checked'" : '' ;
2942 $selected { 'IKE_VERSION' }{ 'ikev1' } = '' ;
2943 $selected { 'IKE_VERSION' }{ 'ikev2' } = '' ;
2944 $selected { 'IKE_VERSION' }{ $cgiparams { 'IKE_VERSION' }} = "selected='selected'" ;
2946 $selected { 'DPD_ACTION' }{ 'clear' } = '' ;
2947 $selected { 'DPD_ACTION' }{ 'hold' } = '' ;
2948 $selected { 'DPD_ACTION' }{ 'restart' } = '' ;
2949 $selected { 'DPD_ACTION' }{ 'none' } = '' ;
2950 $selected { 'DPD_ACTION' }{ $cgiparams { 'DPD_ACTION' }} = "selected='selected'" ;
2952 $selected { 'START_ACTION' }{ 'add' } = '' ;
2953 $selected { 'START_ACTION' }{ 'route' } = '' ;
2954 $selected { 'START_ACTION' }{ 'start' } = '' ;
2955 $selected { 'START_ACTION' }{ $cgiparams { 'START_ACTION' }} = "selected='selected'" ;
2957 $selected { 'INACTIVITY_TIMEOUT' } = ();
2958 foreach my $timeout ( keys %INACTIVITY_TIMEOUTS ) {
2959 $selected { 'INACTIVITY_TIMEOUT' }{ $timeout } = "" ;
2961 $selected { 'INACTIVITY_TIMEOUT' }{ $cgiparams { 'INACTIVITY_TIMEOUT' }} = "selected" ;
2963 & Header
:: showhttpheaders
();
2964 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
2965 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2967 if ( $errormessage ) {
2968 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2969 print "<class name='base'> $errormessage " ;
2970 print " </class>" ;
2971 & Header
:: closebox
();
2975 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
2976 print "<class name='base'> $warnmessage " ;
2977 print " </class>" ;
2978 & Header
:: closebox
();
2981 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'advanced'}:" );
2983 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
2984 <input type='hidden' name='ADVANCED' value='yes' />
2985 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
2987 <table width='100%'>
2990 <th width="15%"></th>
2997 <td> $Lang ::tr{'vpn keyexchange'}:</td>
2999 <select name='IKE_VERSION'>
3000 <option value='ikev2' $selected {'IKE_VERSION'}{'ikev2'}>IKEv2</option>
3001 <option value='ikev1' $selected {'IKE_VERSION'}{'ikev1'}>IKEv1</option>
3007 <td class='boldbase' width="15%"> $Lang ::tr{'encryption'}</td>
3008 <td class='boldbase'>
3009 <select name='IKE_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
3010 <option value='chacha20poly1305' $checked {'IKE_ENCRYPTION'}{'chacha20poly1305'}>256 bit ChaCha20-Poly1305/128 bit ICV</option>
3011 <option value='aes256gcm128' $checked {'IKE_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
3012 <option value='aes256gcm96' $checked {'IKE_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
3013 <option value='aes256gcm64' $checked {'IKE_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
3014 <option value='aes256' $checked {'IKE_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
3015 <option value='camellia256' $checked {'IKE_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
3016 <option value='aes192gcm128' $checked {'IKE_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
3017 <option value='aes192gcm96' $checked {'IKE_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
3018 <option value='aes192gcm64' $checked {'IKE_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
3019 <option value='aes192' $checked {'IKE_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
3020 <option value='camellia192' $checked {'IKE_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
3021 <option value='aes128gcm128' $checked {'IKE_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
3022 <option value='aes128gcm96' $checked {'IKE_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
3023 <option value='aes128gcm64' $checked {'IKE_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
3024 <option value='aes128' $checked {'IKE_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
3025 <option value='camellia128' $checked {'IKE_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
3026 <option value='3des' $checked {'IKE_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC ( $Lang ::tr{'vpn weak'})</option>
3029 <td class='boldbase'>
3030 <select name='ESP_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'>
3031 <option value='chacha20poly1305' $checked {'ESP_ENCRYPTION'}{'chacha20poly1305'}>256 bit ChaCha20-Poly1305/128 bit ICV</option>
3032 <option value='aes256gcm128' $checked {'ESP_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option>
3033 <option value='aes256gcm96' $checked {'ESP_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option>
3034 <option value='aes256gcm64' $checked {'ESP_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option>
3035 <option value='aes256' $checked {'ESP_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option>
3036 <option value='camellia256' $checked {'ESP_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option>
3037 <option value='aes192gcm128' $checked {'ESP_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option>
3038 <option value='aes192gcm96' $checked {'ESP_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option>
3039 <option value='aes192gcm64' $checked {'ESP_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option>
3040 <option value='aes192' $checked {'ESP_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option>
3041 <option value='camellia192' $checked {'ESP_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option>
3042 <option value='aes128gcm128' $checked {'ESP_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option>
3043 <option value='aes128gcm96' $checked {'ESP_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option>
3044 <option value='aes128gcm64' $checked {'ESP_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option>
3045 <option value='aes128' $checked {'ESP_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option>
3046 <option value='camellia128' $checked {'ESP_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option>
3047 <option value='3des' $checked {'ESP_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC ( $Lang ::tr{'vpn weak'})</option>
3053 <td class='boldbase' width="15%"> $Lang ::tr{'integrity'}</td>
3054 <td class='boldbase'>
3055 <select name='IKE_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
3056 <option value='sha2_512' $checked {'IKE_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
3057 <option value='sha2_384' $checked {'IKE_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
3058 <option value='sha2_256' $checked {'IKE_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
3059 <option value='aesxcbc' $checked {'IKE_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
3060 <option value='sha' $checked {'IKE_INTEGRITY'}{'sha'}>SHA1 ( $Lang ::tr{'vpn weak'})</option>
3061 <option value='md5' $checked {'IKE_INTEGRITY'}{'md5'}>MD5 ( $Lang ::tr{'vpn broken'})</option>
3064 <td class='boldbase'>
3065 <select name='ESP_INTEGRITY' multiple='multiple' size='6' style='width: 100%'>
3066 <option value='sha2_512' $checked {'ESP_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option>
3067 <option value='sha2_384' $checked {'ESP_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option>
3068 <option value='sha2_256' $checked {'ESP_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option>
3069 <option value='aesxcbc' $checked {'ESP_INTEGRITY'}{'aesxcbc'}>AES XCBC</option>
3070 <option value='sha1' $checked {'ESP_INTEGRITY'}{'sha1'}>SHA1 ( $Lang ::tr{'vpn weak'})</option>
3071 <option value='md5' $checked {'ESP_INTEGRITY'}{'md5'}>MD5 ( $Lang ::tr{'vpn broken'})</option>
3076 <td class='boldbase' width="15%"> $Lang ::tr{'lifetime'} <img src='/blob.gif' alt='*' /></td>
3077 <td class='boldbase'>
3078 <input type='text' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' size='5' /> $Lang ::tr{'hours'}
3080 <td class='boldbase'>
3081 <input type='text' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' size='5' /> $Lang ::tr{'hours'}
3085 <td class='boldbase' width="15%"> $Lang ::tr{'grouptype'}</td>
3086 <td class='boldbase'>
3087 <select name='IKE_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
3088 <option value='curve25519' $checked {'IKE_GROUPTYPE'}{'curve25519'}>Curve 25519 (256 bit)</option>
3089 <option value='curve448' $checked {'IKE_GROUPTYPE'}{'curve448'}>Curve 448 (224 bit)</option>
3090 <option value='e521' $checked {'IKE_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
3091 <option value='e512bp' $checked {'IKE_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
3092 <option value='e384' $checked {'IKE_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
3093 <option value='e384bp' $checked {'IKE_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
3094 <option value='e256' $checked {'IKE_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
3095 <option value='e256bp' $checked {'IKE_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
3096 <option value='e224' $checked {'IKE_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
3097 <option value='e224bp' $checked {'IKE_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
3098 <option value='e192' $checked {'IKE_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
3099 <option value='8192' $checked {'IKE_GROUPTYPE'}{'8192'}>MODP-8192</option>
3100 <option value='6144' $checked {'IKE_GROUPTYPE'}{'6144'}>MODP-6144</option>
3101 <option value='4096' $checked {'IKE_GROUPTYPE'}{'4096'}>MODP-4096</option>
3102 <option value='3072' $checked {'IKE_GROUPTYPE'}{'3072'}>MODP-3072</option>
3103 <option value='2048' $checked {'IKE_GROUPTYPE'}{'2048'}>MODP-2048</option>
3104 <option value='1536' $checked {'IKE_GROUPTYPE'}{'1536'}>MODP-1536</option>
3105 <option value='1024' $checked {'IKE_GROUPTYPE'}{'1024'}>MODP-1024 ( $Lang ::tr{'vpn broken'})</option>
3106 <option value='768' $checked {'IKE_GROUPTYPE'}{'768'}>MODP-768 ( $Lang ::tr{'vpn broken'})</option>
3109 <td class='boldbase'>
3110 <select name='ESP_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'>
3111 <option value='curve25519' $checked {'ESP_GROUPTYPE'}{'curve25519'}>Curve 25519 (256 bit)</option>
3112 <option value='curve448' $checked {'ESP_GROUPTYPE'}{'curve448'}>Curve 448 (224 bit)</option>
3113 <option value='e521' $checked {'ESP_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option>
3114 <option value='e512bp' $checked {'ESP_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option>
3115 <option value='e384' $checked {'ESP_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option>
3116 <option value='e384bp' $checked {'ESP_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option>
3117 <option value='e256' $checked {'ESP_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option>
3118 <option value='e256bp' $checked {'ESP_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option>
3119 <option value='e224' $checked {'ESP_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option>
3120 <option value='e224bp' $checked {'ESP_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option>
3121 <option value='e192' $checked {'ESP_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option>
3122 <option value='8192' $checked {'ESP_GROUPTYPE'}{'8192'}>MODP-8192</option>
3123 <option value='6144' $checked {'ESP_GROUPTYPE'}{'6144'}>MODP-6144</option>
3124 <option value='4096' $checked {'ESP_GROUPTYPE'}{'4096'}>MODP-4096</option>
3125 <option value='3072' $checked {'ESP_GROUPTYPE'}{'3072'}>MODP-3072</option>
3126 <option value='2048' $checked {'ESP_GROUPTYPE'}{'2048'}>MODP-2048</option>
3127 <option value='1536' $checked {'ESP_GROUPTYPE'}{'1536'}>MODP-1536</option>
3128 <option value='1024' $checked {'ESP_GROUPTYPE'}{'1024'}>MODP-1024 ( $Lang ::tr{'vpn broken'})</option>
3129 <option value='768' $checked {'ESP_GROUPTYPE'}{'768'}>MODP-768 ( $Lang ::tr{'vpn broken'})</option>
3130 <option value='none' $checked {'ESP_GROUPTYPE'}{'none'}>- $Lang ::tr{'none'} -</option>
3139 <h2> $Lang ::tr{'dead peer detection'}</h2>
3141 <table width="100%">
3143 <td width="15%"> $Lang ::tr{'dpd action'}:</td>
3145 <select name='DPD_ACTION'>
3146 <option value='none' $selected {'DPD_ACTION'}{'none'}>- $Lang ::tr{'disabled'} -</option>
3147 <option value='clear' $selected {'DPD_ACTION'}{'clear'}>clear</option>
3148 <option value='hold' $selected {'DPD_ACTION'}{'hold'}>hold</option>
3149 <option value='restart' $selected {'DPD_ACTION'}{'restart'}>restart</option>
3154 <td width="15%"> $Lang ::tr{'dpd timeout'}: <img src='/blob.gif' alt='*' /></td>
3156 <input type='text' name='DPD_TIMEOUT' size='5' value=' $cgiparams {'DPD_TIMEOUT'}' />
3160 <td width="15%"> $Lang ::tr{'dpd delay'}: <img src='/blob.gif' alt='*' /></td>
3162 <input type='text' name='DPD_DELAY' size='5' value=' $cgiparams {'DPD_DELAY'}' />
3169 <table width="100%">
3173 <input type='checkbox' name='ONLY_PROPOSED' $checked {'ONLY_PROPOSED'} />
3174 IKE+ESP: $Lang ::tr{'use only proposed settings'}
3178 <label> $Lang ::tr{'vpn start action'}</label>
3179 <select name="START_ACTION">
3180 <option value="route" $selected {'START_ACTION'}{'route'}> $Lang ::tr{'vpn start action route'}</option>
3181 <option value="start" $selected {'START_ACTION'}{'start'}> $Lang ::tr{'vpn start action start'}</option>
3182 <option value="add" $selected {'START_ACTION'}{'add'} > $Lang ::tr{'vpn start action add'}</option>
3189 <input type='checkbox' name='PFS' $checked {'PFS'} />
3190 $Lang ::tr{'pfs yes no'}
3194 <label> $Lang ::tr{'vpn inactivity timeout'}</label>
3195 <select name="INACTIVITY_TIMEOUT">
3197 foreach my $t ( sort { $a <=> $b } keys %INACTIVITY_TIMEOUTS ) {
3198 print "<option value= \" $t \" $selected {'INACTIVITY_TIMEOUT'}{ $t }> $INACTIVITY_TIMEOUTS { $t }</option> \n " ;
3209 <input type='checkbox' name='COMPRESSION' $checked {'COMPRESSION'} />
3210 $Lang ::tr{'vpn payload compression'}
3217 <input type='checkbox' name='FORCE_MOBIKE' $checked {'FORCE_MOBIKE'} />
3218 $Lang ::tr{'vpn force mobike'}
3223 <td align='left'><img src='/blob.gif' align='top' alt='*' /> $Lang ::tr{'required field'}</td>
3225 <input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />
3226 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' />
3232 & Header
:: closebox
();
3233 & Header
:: closebigbox
();
3234 & Header
:: closepage
();
3241 ### Default status page
3246 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%cgiparams );
3247 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
3248 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
3249 $cgiparams { 'CA_NAME' } = '' ;
3251 my @status = `/usr/local/bin/ipsecctrl I 2>/dev/null` ;
3253 $checked { 'ENABLED' } = $cgiparams { 'ENABLED' } eq 'on' ?
"checked='checked'" : '' ;
3255 & Header
:: showhttpheaders
();
3256 & Header
:: openpage
( $Lang :: tr
{ 'ipsec' }, 1 , '' );
3257 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
3259 if ( $errormessage ) {
3260 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
3261 print "<class name='base'> $errormessage \n " ;
3262 print " </class> \n " ;
3263 & Header
:: closebox
();
3267 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
3268 print " $warnmessage <br>" ;
3269 print " $Lang ::tr{'fwdfw warn1'}<br>" ;
3270 & Header
:: closebox
();
3271 print "<center><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'ok'}' style='width: 5em;'></form>" ;
3272 & Header
:: closepage
();
3276 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'global settings' });
3278 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3279 <table width='100%'>
3281 <td width='60%' class='base'>
3282 $Lang ::tr{'enabled'}
3285 <input type='checkbox' name='ENABLED' $checked {'ENABLED'} />
3289 <td class='base' nowrap='nowrap' width="60%"> $Lang ::tr{'ipsec roadwarrior endpoint'}:</td>
3290 <td width="40%"><input type='text' name='RW_ENDPOINT' value=' $cgiparams {'RW_ENDPOINT'}' /></td>
3293 <td class='base' nowrap='nowrap' width="60%"> $Lang ::tr{'host to net vpn'}:</td>
3294 <td width="40%"><input type='text' name='RW_NET' value=' $cgiparams {'RW_NET'}' /></td>
3297 <td width='100%' colspan="2" align='right' class='base'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' /></td>
3303 & Header
:: closebox
();
3305 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection status and controlc' });
3307 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
3309 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
3310 <th width='22%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></th>
3311 <th width='23%' class='boldbase' align='center'><b> $Lang ::tr{'common name'}</b></th>
3312 <th width='30%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></th>
3313 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></th>
3314 <th class='boldbase' align='center' colspan='7'><b> $Lang ::tr{'action'}</b></th>
3320 foreach my $key ( sort { ncmp
( $confighash { $a }[ 1 ], $confighash { $b }[ 1 ]) } keys %confighash ) {
3321 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
3325 $col = "bgcolor=' $color {'color20'}'" ;
3328 $col = "bgcolor=' $color {'color22'}'" ;
3330 print "<td align='center' nowrap='nowrap' $col > $confighash { $key }[1]</td>" ;
3331 print "<td align='center' nowrap='nowrap' $col >" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ") $confighash { $key }[29]</td>" ;
3332 if ( $confighash { $key }[ 2 ] eq ' %auth -dn' ) {
3333 print "<td align='left' nowrap='nowrap' $col > $confighash { $key }[9]</td>" ;
3334 } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
3335 print "<td align='left' nowrap='nowrap' $col > $confighash { $key }[2]</td>" ;
3337 print "<td align='left' $col > </td>" ;
3339 print "<td align='center' $col > $confighash { $key }[25]</td>" ;
3340 my $col1 = "bgcolor='${Header::colourred}'" ;
3341 my $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
3342 if ( $confighash { $key }[ 33 ] eq "add" ) {
3343 $col1 = "bgcolor='${Header::colourorange}'" ;
3344 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'vpn wait'}</font></b>" ;
3346 foreach my $line ( @status ) {
3347 if (( $line =~ /\"$confighash{$key}[1]\".*IPsec SA established/ ) ||
3348 ( $line =~ /$confighash{$key}[1]\{.*INSTALLED/ )) {
3349 $col1 = "bgcolor='${Header::colourgreen}'" ;
3350 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b>" ;
3352 } elsif ( $line =~ /$confighash{$key}[1]\[.*CONNECTING/ ) {
3353 $col1 = "bgcolor='${Header::colourorange}'" ;
3354 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'vpn connecting'}</font></b>" ;
3355 } elsif ( $line =~ /$confighash{$key}[1]\{.*ROUTED/ ) {
3356 $col1 = "bgcolor='${Header::colourorange}'" ;
3357 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'vpn on-demand'}</font></b>" ;
3360 # move to blue if really down
3361 if ( $confighash { $key }[ 0 ] eq 'off' && $col1 =~ /${Header::colourred}/ ) {
3362 $col1 = "bgcolor='${Header::colourblue}'" ;
3363 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
3366 <td align='center' $col1 > $active </td>
3367 <td align='center' $col >
3368 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3369 <input type='image' name=' $Lang ::tr{'restart'}' src='/images/reload.gif' alt=' $Lang ::tr{'restart'}' title=' $Lang ::tr{'restart'}' />
3370 <input type='hidden' name='ACTION' value=' $Lang ::tr{'restart'}' />
3371 <input type='hidden' name='KEY' value=' $key ' />
3376 if (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
3378 <td align='center' $col >
3379 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3380 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' />
3381 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
3382 <input type='hidden' name='KEY' value=' $key ' />
3388 print "<td width='2%' $col > </td>" ;
3390 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/certs/ $confighash { $key }[1].p12" ) {
3392 <td align='center' $col >
3393 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3394 <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'}' />
3395 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
3396 <input type='hidden' name='KEY' value=' $key ' />
3401 } elsif (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
3403 <td align='center' $col >
3404 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3405 <input type='image' name=' $Lang ::tr{'download certificate'}' src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' title=' $Lang ::tr{'download certificate'}' />
3406 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
3407 <input type='hidden' name='KEY' value=' $key ' />
3413 print "<td width='2%' $col > </td>" ;
3417 if ( $confighash { $key }[ 3 ] eq 'host' ) {
3419 <td align='center' $col >
3420 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3421 <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'}' />
3422 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download apple profile'}' />
3423 <input type='hidden' name='KEY' value=' $key ' />
3428 print "<td width='2%' $col > </td>" ;
3432 <td align='center' $col >
3433 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3434 <input type='image' name=' $Lang ::tr{'toggle enable disable'}' src='/images/ $gif ' alt=' $Lang ::tr{'toggle enable disable'}' title=' $Lang ::tr{'toggle enable disable'}' />
3435 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
3436 <input type='hidden' name='KEY' value=' $key ' />
3440 <td align='center' $col >
3441 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3442 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
3443 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' title=' $Lang ::tr{'edit'}' />
3444 <input type='hidden' name='KEY' value=' $key ' />
3447 <td align='center' $col >
3448 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3449 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
3450 <input type='image' name=' $Lang ::tr{'remove'}' src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' title=' $Lang ::tr{'remove'}' />
3451 <input type='hidden' name='KEY' value=' $key ' />
3461 # If the config file contains entries, print Key to action icons
3466 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
3467 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
3468 <td class='base'> $Lang ::tr{'click to disable'}</td>
3469 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
3470 <td class='base'> $Lang ::tr{'show certificate'}</td>
3471 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
3472 <td class='base'> $Lang ::tr{'edit'}</td>
3473 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
3474 <td class='base'> $Lang ::tr{'remove'}</td>
3478 <td> <img src='/images/off.gif' alt='?OFF' /></td>
3479 <td class='base'> $Lang ::tr{'click to enable'}</td>
3480 <td> <img src='/images/floppy.gif' alt='?FLOPPY' /></td>
3481 <td class='base'> $Lang ::tr{'download certificate'}</td>
3482 <td> <img src='/images/reload.gif' alt='?RELOAD'/></td>
3483 <td class='base'> $Lang ::tr{'restart'}</td>
3491 <table width='100%'>
3492 <tr><td align='right' colspan='9'>
3493 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3494 <input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />
3500 & Header
:: closebox
();
3502 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'certificate authorities'}" );
3504 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
3506 <th width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
3507 <th width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></th>
3508 <th width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></th>
3512 my $col1 = "bgcolor=' $color {'color22'}'" ;
3513 my $col2 = "bgcolor=' $color {'color20'}'" ;
3514 if (- f
"${General::swroot}/ca/cacert.pem" ) {
3515 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/cacert.pem" ));
3518 <td class='base' $col1 > $Lang ::tr{'root certificate'}</td>
3519 <td class='base' $col1 > $casubject </td>
3520 <td width='3%' align='center' $col1 >
3521 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3522 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
3523 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/info.gif' alt=' $Lang ::tr{'show root certificate'}' title=' $Lang ::tr{'show root certificate'}' />
3526 <td width='3%' align='center' $col1 >
3527 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3528 <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'}' />
3529 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
3532 <td width='4%' $col1 > </td></tr>
3536 # display rootcert generation buttons
3539 <td class='base' $col1 > $Lang ::tr{'root certificate'}:</td>
3540 <td class='base' $col1 > $Lang ::tr{'not present'}</td>
3541 <td colspan='3' $col1 > </td></tr>
3546 if (- f
"${General::swroot}/certs/hostcert.pem" ) {
3547 my $hostsubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/certs/hostcert.pem" ));
3551 <td class='base' $col2 > $Lang ::tr{'host certificate'}</td>
3552 <td class='base' $col2 > $hostsubject </td>
3553 <td width='3%' align='center' $col2 >
3554 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3555 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
3556 <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'}' />
3559 <td width='3%' align='center' $col2 >
3560 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
3561 <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'}" />
3562 <input type='hidden' name='ACTION' value=" $Lang ::tr{'download host certificate'}" />
3565 <td width='4%' $col2 > </td></tr>
3572 <td width='25%' class='base' $col2 > $Lang ::tr{'host certificate'}:</td>
3573 <td class='base' $col2 > $Lang ::tr{'not present'}</td>
3574 <td colspan='3' $col2 > </td></tr>
3580 if ( keys %cahash > 0 ) {
3581 foreach my $key ( keys %cahash ) {
3582 if ( $rowcolor ++ % 2 ) {
3584 $col = "bgcolor=' $color {'color20'}'" ;
3587 $col = "bgcolor=' $color {'color22'}'" ;
3589 print "<td class='base' $col > $cahash { $key }[0]</td> \n " ;
3590 print "<td class='base' $col > $cahash { $key }[1]</td> \n " ;
3592 <td align='center' $col >
3593 <form method='post' name='cafrm${key}a' action=' $ENV {'SCRIPT_NAME'}'>
3594 <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'}' />
3595 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
3596 <input type='hidden' name='KEY' value=' $key ' />
3599 <td align='center' $col >
3600 <form method='post' name='cafrm${key}b' action=' $ENV {'SCRIPT_NAME'}'>
3601 <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'}' />
3602 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
3603 <input type='hidden' name='KEY' value=' $key ' />
3606 <td align='center' $col >
3607 <form method='post' name='cafrm${key}c' action=' $ENV {'SCRIPT_NAME'}'>
3608 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
3609 <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'}' />
3610 <input type='hidden' name='KEY' value=' $key ' />
3620 # If the file contains entries, print Key to action icons
3621 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
3624 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
3625 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
3626 <td class='base'> $Lang ::tr{'show certificate'}</td>
3627 <td> <img src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' /></td>
3628 <td class='base'> $Lang ::tr{'download certificate'}</td>
3633 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>" ;
3637 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
3638 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
3641 <td class='base' nowrap='nowrap'> $Lang ::tr{'ca name'}: <img src='/blob.gif' alt='*' /></td>
3642 <td nowrap='nowrap'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' /> </td>
3643 <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td>
3644 <td nowrap='nowrap'><input type='submit' name='ACTION' value=' $Lang ::tr{'upload ca certificate'}' /></td>
3647 <td colspan='3'> $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}:</td>
3648 <td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' /></td>
3654 & Header
:: closebox
();
3655 & Header
:: closebigbox
();
3656 & Header
:: closepage
();
3658 sub array_unique
($) {
3663 foreach my $e ( @
$array ) {
3664 next if $seen { $e }++;
3671 sub make_algos
($$$$$) {
3672 my ( $mode , $encs , $ints , $grps , $pfs ) = @_ ;
3675 foreach my $enc ( @
$encs ) {
3676 foreach my $int ( @
$ints ) {
3677 foreach my $grp ( @
$grps ) {
3680 if ( $mode eq "ike" ) {
3683 if ( $grp =~ m/^e(.*)$/ ) {
3684 push ( @algo , "ecp $1 " );
3685 } elsif ( $grp =~ m/curve(25519|448)/ ) {
3686 push ( @algo , " $grp " );
3688 push ( @algo , "modp $grp " );
3691 } elsif ( $mode eq "esp" ) {
3692 my $is_aead = ( $enc =~ m/[cg]cm/ );
3698 if (! $pfs || $grp eq "none" ) {
3700 } elsif ( $grp =~ m/^e(.*)$/ ) {
3701 push ( @algo , "ecp $1 " );
3702 } elsif ( $grp =~ m/curve(25519|448)/ ) {
3703 push ( @algo , " $grp " );
3705 push ( @algo , "modp $grp " );
3709 push ( @algos , join ( "-" , @algo ));
3714 return & array_unique
( \
@algos );
3717 sub make_subnets
($$) {
3718 my $direction = shift ;
3719 my $subnets = shift ;
3721 my @nets = split ( /\|/ , $subnets );
3723 foreach my $net ( @nets ) {
3724 my $cidr_net = & General
:: ipcidr
( $net );
3726 # Skip 0.0.0.0/0 for remote because this renders the
3727 # while system inaccessible
3728 next if (( $direction eq "right" ) && ( $cidr_net eq "0.0.0.0/0" ));
3730 push ( @cidr_nets , $cidr_net );
3733 return join ( "," , @cidr_nets );