]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/vpnmain.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2010 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 ###############################################################################
24 use File
:: Temp qw
/ tempfile tempdir / ;
27 # enable only the following on debugging purpose
29 #use CGI::Carp 'fatalsToBrowser';
31 require '/var/ipfire/general-functions.pl' ;
32 require "${General::swroot}/lang.pl" ;
33 require "${General::swroot}/header.pl" ;
34 require "${General::swroot}/countries.pl" ;
36 #workaround to suppress a warning when a variable is used only once
37 my @dummy = ( ${ Header
:: colourgreen
}, ${ Header
:: colourblue
} );
41 ### Initialize variables
43 my $sleepDelay = 4 ; # after a call to ipsecctrl S or R, wait this delay (seconds) before reading status
44 # (let the ipsec do its job)
53 my $errormessage = '' ;
56 my %mainsettings = ();
57 & General
:: readhash
( "${General::swroot}/main/settings" , \
%mainsettings );
58 & General
:: readhash
( "/srv/web/ipfire/html/themes/" . $mainsettings { 'THEME' }. "/include/colors.txt" , \
%color );
60 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%netsettings );
61 $cgiparams { 'ENABLED' } = 'off' ;
62 $cgiparams { 'EDIT_ADVANCED' } = 'off' ;
63 $cgiparams { 'ACTION' } = '' ;
64 $cgiparams { 'CA_NAME' } = '' ;
65 $cgiparams { 'DBG_CRYPT' } = '' ;
66 $cgiparams { 'DBG_PARSING' } = '' ;
67 $cgiparams { 'DBG_EMITTING' } = '' ;
68 $cgiparams { 'DBG_CONTROL' } = '' ;
69 $cgiparams { 'DBG_KLIPS' } = '' ;
70 $cgiparams { 'DBG_DNS' } = '' ;
71 $cgiparams { 'DBG_NAT_T' } = '' ;
72 $cgiparams { 'KEY' } = '' ;
73 $cgiparams { 'TYPE' } = '' ;
74 $cgiparams { 'ADVANCED' } = '' ;
75 $cgiparams { 'INTERFACE' } = '' ;
76 $cgiparams { 'NAME' } = '' ;
77 $cgiparams { 'LOCAL_SUBNET' } = '' ;
78 $cgiparams { 'REMOTE_SUBNET' } = '' ;
79 $cgiparams { 'REMOTE' } = '' ;
80 $cgiparams { 'LOCAL_ID' } = '' ;
81 $cgiparams { 'REMOTE_ID' } = '' ;
82 $cgiparams { 'REMARK' } = '' ;
83 $cgiparams { 'PSK' } = '' ;
84 $cgiparams { 'CERT_NAME' } = '' ;
85 $cgiparams { 'CERT_EMAIL' } = '' ;
86 $cgiparams { 'CERT_OU' } = '' ;
87 $cgiparams { 'CERT_ORGANIZATION' } = '' ;
88 $cgiparams { 'CERT_CITY' } = '' ;
89 $cgiparams { 'CERT_STATE' } = '' ;
90 $cgiparams { 'CERT_COUNTRY' } = '' ;
91 $cgiparams { 'SUBJECTALTNAME' } = '' ;
92 $cgiparams { 'CERT_PASS1' } = '' ;
93 $cgiparams { 'CERT_PASS2' } = '' ;
94 $cgiparams { 'ROOTCERT_HOSTNAME' } = '' ;
95 $cgiparams { 'ROOTCERT_COUNTRY' } = '' ;
96 $cgiparams { 'P12_PASS' } = '' ;
97 $cgiparams { 'ROOTCERT_ORGANIZATION' } = '' ;
98 $cgiparams { 'ROOTCERT_HOSTNAME' } = '' ;
99 $cgiparams { 'ROOTCERT_EMAIL' } = '' ;
100 $cgiparams { 'ROOTCERT_OU' } = '' ;
101 $cgiparams { 'ROOTCERT_CITY' } = '' ;
102 $cgiparams { 'ROOTCERT_STATE' } = '' ;
104 & Header
:: getcgihash
( \
%cgiparams , { 'wantfile' => 1 , 'filevar' => 'FH' });
110 my $hostname = $_ [ 0 ];
111 unless ( $hostname ) { return "No hostname" };
112 my $res = new Net
:: DNS
:: Resolver
;
113 my $query = $res -> search ( " $hostname " );
115 foreach my $rr ( $query -> answer ) {
116 ## Potential bug - we are only looking at A records:
117 return 0 if $rr -> type eq "A" ;
120 return $res -> errorstring ;
124 ### Just return true is one interface is vpn enabled
127 return ( $vpnsettings { 'ENABLED' } eq 'on' );
130 ### old version: maintain serial number to one, without explication.
131 ### this : let the counter go, so that each cert is numbered.
135 if ( open ( FILE
, ">${General::swroot}/certs/serial" )) {
139 if ( open ( FILE
, ">${General::swroot}/certs/index.txt" )) {
143 unlink ( "${General::swroot}/certs/index.txt.old" );
144 unlink ( "${General::swroot}/certs/serial.old" );
145 unlink ( "${General::swroot}/certs/01.pem" );
147 sub newcleanssldatabase
149 if (! - s
"${General::swroot}/certs/serial" ) {
150 open ( FILE
, ">${General::swroot}/certs/serial" );
154 if (! - s
">${General::swroot}/certs/index.txt" ) {
155 system ( "touch ${General::swroot}/certs/index.txt" );
157 unlink ( "${General::swroot}/certs/index.txt.old" );
158 unlink ( "${General::swroot}/certs/serial.old" );
159 # unlink ("${General::swroot}/certs/01.pem"); numbering evolves. Wrong place to delete
163 ### Call openssl and return errormessage if any
167 my $retssl = `/usr/bin/openssl $opt 2>&1` ; #redirect stderr
169 foreach my $line ( split ( /\n/ , $retssl )) {
170 & General
:: log ( "ipsec" , " $line " ) if ( 0 ); # 1 for verbose logging
171 $ret .= '<br>' . $line if ( $line =~ /error|unknown/ );
174 $ret = & Header
:: cleanhtml
( $ret );
176 return $ret ?
" $Lang ::tr{'openssl produced an error'}: $ret " : '' ;
179 ### Obtain a CN from given cert
181 sub getCNfromcert
($) {
182 #&General::log("ipsec", "Extracting name from $_[0]...");
183 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
184 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
186 $temp =~ s
+/ Email
+, E
+;
187 $temp =~ s/ ST=/ S=/ ;
193 ### Obtain Subject from given cert
195 sub getsubjectfromcert
($) {
196 #&General::log("ipsec", "Extracting subject from $_[0]...");
197 my $temp = `/usr/bin/openssl x509 -text -in $_ [0]` ;
198 $temp =~ /Subject: (.*)[\n]/ ;
200 $temp =~ s
+/ Email
+, E
+;
201 $temp =~ s/ ST=/ S=/ ;
205 ### Combine local subnet and connection name to make a unique name for each connection section
206 ### (this sub is not used now)
208 sub makeconnname
($) {
212 $subnet =~ /^(.*?)\/ (.* ?
)$/; # $1=IP $2=mask
213 my $ip = unpack ( 'N' , & Socket
:: inet_aton
( $1 ));
214 if ( length ( $2 ) > 2 ) {
215 my $mm = unpack ( 'N' , & Socket
:: inet_aton
( $2 ));
216 while ( ( $mm & 1 )== 0 ) {
223 return sprintf ( " %s - %X " , $conn , $ip );
226 ### Write a config file.
228 ###Type=Host : GUI can choose the interface used (RED,GREEN,BLUE) and
229 ### the side is always defined as 'left'.
230 ### configihash[14]: 'VHOST' is allowed
233 sub writeipsecfiles
{
234 my %lconfighash = ();
235 my %lvpnsettings = ();
236 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%lconfighash );
237 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%lvpnsettings );
239 open ( CONF
, ">${General::swroot}/vpn/ipsec.conf" ) or die "Unable to open ${General::swroot}/vpn/ipsec.conf: $!" ;
240 open ( SECRETS
, ">${General::swroot}/vpn/ipsec.secrets" ) or die "Unable to open ${General::swroot}/vpn/ipsec.secrets: $!" ;
243 print CONF
"version 2 \n\n " ;
244 print CONF
"config setup \n " ;
245 #create an ipsec Interface for each 'enabled' ones
246 #loop trought configuration and add physical interfaces to the list
247 my $interfaces = " \t interfaces= \" " ;
248 foreach my $key ( keys %lconfighash ) {
249 next if ( $lconfighash { $key }[ 0 ] ne 'on' );
250 $interfaces .= " %defaultroute " if ( $interfaces !~ /defaultroute/ && $lconfighash { $key }[ 26 ] eq 'RED' );
251 $interfaces .= " $netsettings {'GREEN_DEV'} " if ( $interfaces !~ /ipsec1/ && $lconfighash { $key }[ 26 ] eq 'GREEN' );
252 $interfaces .= " $netsettings {'BLUE_DEV'} " if ( $interfaces !~ /ipsec2/ && $lconfighash { $key }[ 26 ] eq 'BLUE' );
253 $interfaces .= " $netsettings {'ORANGE_DEV'} " if ( $interfaces !~ /ipsec3/ && $lconfighash { $key }[ 26 ] eq 'ORANGE' );
255 print CONF
$interfaces . " \"\n " ;
257 my $plutodebug = '' ; # build debug list
258 map ( $plutodebug .= $lvpnsettings { $_ } eq 'on' ?
lc ( substr ( $_ , 4 )). ' ' : '' ,
259 ( 'DBG_CRYPT' , 'DBG_PARSING' , 'DBG_EMITTING' , 'DBG_CONTROL' ,
261 $plutodebug = 'none' if $plutodebug eq '' ; # if nothing selected, use 'none'.
262 #print CONF "\tklipsdebug=\"none\"\n";
263 print CONF
" \t plutodebug= \" $plutodebug \"\n " ;
264 # deprecated in ipsec.conf version 2
265 #print CONF "\tplutoload=%search\n";
266 #print CONF "\tplutostart=%search\n";
267 #Disable IKEv2 deamon
268 print CONF
" \t charonstart=no \n " ;
269 print CONF
" \t uniqueids=yes \n " ;
270 print CONF
" \t nat_traversal=yes \n " ;
271 print CONF
" \t overridemtu= $lvpnsettings {'VPN_OVERRIDE_MTU'} \n " if ( $lvpnsettings { 'VPN_OVERRIDE_MTU' } ne '' );
272 print CONF
" \t virtual_private= %v4 :10.0.0.0/8, %v4 :172.16.0.0/12, %v4 :192.168.0.0/16" ;
273 print CONF
", %v4 :! $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" ;
274 if ( length ( $netsettings { 'ORANGE_DEV' }) > 2 ) {
275 print CONF
", %v4 :! $netsettings {'ORANGE_NETADDRESS'}/ $netsettings {'ORANGE_NETMASK'}" ;
277 if ( length ( $netsettings { 'BLUE_DEV' }) > 2 ) {
278 print CONF
", %v4 :! $netsettings {'BLUE_NETADDRESS'}/ $netsettings {'BLUE_NETMASK'}" ;
280 foreach my $key ( keys %lconfighash ) {
281 if ( $lconfighash { $key }[ 3 ] eq 'net' ) {
282 print CONF
", %v4 :! $lconfighash { $key }[11]" ;
286 print CONF
"conn %default \n " ;
287 print CONF
" \t keyingtries=0 \n " ;
288 #strongswan doesn't know this
289 #print CONF "\tdisablearrivalcheck=no\n";
292 # Add user includes to config file
293 print CONF
"include /etc/ipsec.user.conf \n " ;
296 print SECRETS
"include /etc/ipsec.user/secrets \n " ;
298 if (- f
"${General::swroot}/certs/hostkey.pem" ) {
299 print SECRETS
": RSA ${General::swroot}/certs/hostkey.pem \n "
301 my $last_secrets = '' ; # old the less specifics connections
303 foreach my $key ( keys %lconfighash ) {
304 next if ( $lconfighash { $key }[ 0 ] ne 'on' );
306 #remote peer is not set? => use '%any'
307 $lconfighash { $key }[ 10 ] = ' %any ' if ( $lconfighash { $key }[ 10 ] eq '' );
310 if ( $lconfighash { $key }[ 26 ] eq 'BLUE' ) {
311 $localside = $netsettings { 'BLUE_ADDRESS' };
312 } elsif ( $lconfighash { $key }[ 26 ] eq 'GREEN' ) {
313 $localside = $netsettings { 'GREEN_ADDRESS' };
314 } elsif ( $lconfighash { $key }[ 26 ] eq 'ORANGE' ) {
315 $localside = $netsettings { 'ORANGE_ADDRESS' };
317 $localside = $lvpnsettings { 'VPN_IP' };
320 print CONF
"conn $lconfighash { $key }[1] \n " ;
321 print CONF
" \t left= $localside \n " ;
322 print CONF
" \t leftnexthop= %defaultroute \n " if ( $lconfighash { $key }[ 26 ] eq 'RED' && $lvpnsettings { 'VPN_IP' } ne ' %defaultroute ' );
323 print CONF
" \t leftsubnet= $lconfighash { $key }[8] \n " ;
324 print CONF
" \t leftfirewall=yes \n " ;
325 print CONF
" \t lefthostaccess=yes \n " ;
327 print CONF
" \t right= $lconfighash { $key }[10] \n " ;
328 if ( $lconfighash { $key }[ 3 ] eq 'net' ) {
329 print CONF
" \t rightsubnet= $lconfighash { $key }[11] \n " ;
330 print CONF
" \t rightnexthop= %defaultroute \n " ;
331 } elsif ( $lconfighash { $key }[ 10 ] eq ' %any ' && $lconfighash { $key }[ 14 ] eq 'on' ) { #vhost allowed for roadwarriors?
332 print CONF
" \t rightsubnet=vhost: %no , %priv \n " ;
335 # Local Cert and Remote Cert (unless auth is DN dn-auth)
336 if ( $lconfighash { $key }[ 4 ] eq 'cert' ) {
337 print CONF
" \t leftcert=${General::swroot}/certs/hostcert.pem \n " ;
338 print CONF
" \t rightcert=${General::swroot}/certs/ $lconfighash { $key }[1]cert.pem \n " if ( $lconfighash { $key }[ 2 ] ne ' %auth -dn' );
341 # Local and Remote IDs
342 print CONF
" \t leftid= \" $lconfighash { $key }[7] \"\n " if ( $lconfighash { $key }[ 7 ]);
343 print CONF
" \t rightid= \" $lconfighash { $key }[9] \"\n " if ( $lconfighash { $key }[ 9 ]);
346 if ( $lconfighash { $key }[ 18 ] && $lconfighash { $key }[ 19 ] && $lconfighash { $key }[ 20 ]) {
348 my @encs = split ( '\|' , $lconfighash { $key }[ 18 ]);
349 my @ints = split ( '\|' , $lconfighash { $key }[ 19 ]);
350 my @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
352 foreach my $i ( @encs ) {
353 foreach my $j ( @ints ) {
354 foreach my $k ( @groups ) {
355 if ( $comma != 0 ) { print CONF
"," ; } else { $comma = 1 ; }
356 print CONF
" $i - $j -modp $k " ;
360 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
366 if ( $lconfighash { $key }[ 21 ] && $lconfighash { $key }[ 22 ]) {
368 my @encs = split ( '\|' , $lconfighash { $key }[ 21 ]);
369 my @ints = split ( '\|' , $lconfighash { $key }[ 22 ]);
371 foreach my $i ( @encs ) {
372 foreach my $j ( @ints ) {
373 if ( $comma != 0 ) { print CONF
"," ; } else { $comma = 1 ; }
377 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
383 if ( $lconfighash { $key }[ 23 ]) {
384 print CONF
" \t pfsgroup= $lconfighash { $key }[23] \n " ;
388 print CONF
" \t ikelifetime= $lconfighash { $key }[16]h \n " if ( $lconfighash { $key }[ 16 ]);
389 print CONF
" \t keylife= $lconfighash { $key }[17]h \n " if ( $lconfighash { $key }[ 17 ]);
392 print CONF
" \t compress=yes \n " if ( $lconfighash { $key }[ 13 ] eq 'on' );
394 # Dead Peer Detection
395 print CONF
" \t dpddelay=30 \n " ;
396 print CONF
" \t dpdtimeout=120 \n " ;
397 print CONF
" \t dpdaction= $lconfighash { $key }[27] \n " ;
400 print CONF
" \t pfs=" . ( $lconfighash { $key }[ 28 ] eq 'on' ?
"yes \n " : "no \n " );
402 # Build Authentication details: LEFTid RIGHTid : PSK psk
404 if ( $lconfighash { $key }[ 4 ] eq 'psk' ) {
405 $psk_line = ( $lconfighash { $key }[ 7 ] ?
$lconfighash { $key }[ 7 ] : $localside ) . " " ;
406 $psk_line .= $lconfighash { $key }[ 9 ] ?
$lconfighash { $key }[ 9 ] : $lconfighash { $key }[ 10 ]; #remoteid or remote address?
407 $psk_line .= " : PSK ' $lconfighash { $key }[5]' \n " ;
408 # if the line contains %any, it is less specific than two IP or ID, so move it at end of file.
409 if ( $psk_line =~ /%any/ ) {
410 $last_secrets .= $psk_line ;
412 print SECRETS
$psk_line ;
414 print CONF
" \t authby=secret \n " ;
416 print CONF
" \t authby=rsasig \n " ;
417 print CONF
" \t leftrsasigkey= %cert \n " ;
418 print CONF
" \t rightrsasigkey= %cert \n " ;
421 # Automatically start only if a net-to-net connection
422 if ( $lconfighash { $key }[ 3 ] eq 'host' ) {
423 print CONF
" \t auto=add \n " ;
425 print CONF
" \t auto=start \n " ;
429 print SECRETS
$last_secrets if ( $last_secrets );
435 ### Save main settings
437 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
438 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
439 unless (& General
:: validfqdn
( $cgiparams { 'VPN_IP' }) || & General
:: validip
( $cgiparams { 'VPN_IP' })
440 || $cgiparams { 'VPN_IP' } eq ' %defaultroute ' ) {
441 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
445 unless ( $cgiparams { 'VPN_DELAYED_START' } =~ /^[0-9]{1,3}$/ ) { #allow 0-999 seconds !
446 $errormessage = $Lang :: tr
{ 'invalid time period' };
450 unless ( $cgiparams { 'VPN_OVERRIDE_MTU' } =~ /^(|[0-9]{1,5})$/ ) { #allow 0-99999
451 $errormessage = $Lang :: tr
{ 'vpn mtu invalid' };
455 unless ( $cgiparams { 'VPN_WATCH' } =~ /^(|off|on)$/ ) {
456 $errormessage = $Lang :: tr
{ 'invalid input' };
460 map ( $vpnsettings { $_ } = $cgiparams { $_ },
461 ( 'ENABLED' , 'DBG_CRYPT' , 'DBG_PARSING' , 'DBG_EMITTING' , 'DBG_CONTROL' ,
464 $vpnsettings { 'VPN_IP' } = $cgiparams { 'VPN_IP' };
465 $vpnsettings { 'VPN_DELAYED_START' } = $cgiparams { 'VPN_DELAYED_START' };
466 $vpnsettings { 'VPN_OVERRIDE_MTU' } = $cgiparams { 'VPN_OVERRIDE_MTU' };
467 $vpnsettings { 'VPN_WATCH' } = $cgiparams { 'VPN_WATCH' };
468 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
471 system ( '/usr/local/bin/ipsecctrl' , 'S' );
473 system ( '/usr/local/bin/ipsecctrl' , 'D' );
480 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
481 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
483 foreach my $key ( keys %confighash ) {
484 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
485 delete $confighash { $key };
488 while ( my $file = glob ( "${General::swroot}/{ca,certs,crls,private}/*" )) {
492 if ( open ( FILE
, ">${General::swroot}/vpn/caconfig" )) {
496 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
498 system ( '/usr/local/bin/ipsecctrl' , 'R' );
504 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' }) {
505 & Header
:: showhttpheaders
();
506 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
507 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
508 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
510 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
514 <input type='hidden' name='AREUSURE' value='yes' />
515 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
516 $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}</td>
519 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' />
520 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
527 & Header
:: closebigbox
();
528 & Header
:: closepage
();
532 ### Upload CA Certificate
534 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
535 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
537 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
538 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
542 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
543 $errormessage = $Lang :: tr
{ 'name too long' };
547 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
548 $errormessage = $Lang :: tr
{ 'name is invalid' };
549 goto UPLOAD_CA_ERROR
;
552 # Check if there is no other entry with this name
553 foreach my $key ( keys %cahash ) {
554 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
555 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
560 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
561 $errormessage = $Lang :: tr
{ 'there was no file upload' };
564 # Move uploaded ca to a temporary file
565 ( my $fh , my $filename ) = tempfile
( );
566 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
570 my $temp = `/usr/bin/openssl x509 -text -in $filename ` ;
571 if ( $temp !~ /CA:TRUE/i ) {
572 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
576 move
( $filename , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
578 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
584 my $key = & General
:: findhasharraykey
( \
%cahash );
585 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
586 $cahash { $key }[ 1 ] = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" ));
587 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
589 system ( '/usr/local/bin/ipsecctrl' , 'R' );
595 ### Display ca certificate
597 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
598 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
600 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
601 & Header
:: showhttpheaders
();
602 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
603 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
604 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'ca certificate'}:" );
605 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
606 $output = & Header
:: cleanhtml
( $output , "y" );
607 print "<pre> $output </pre> \n " ;
609 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
610 & Header
:: closebigbox
();
611 & Header
:: closepage
();
614 $errormessage = $Lang :: tr
{ 'invalid key' };
618 ### Export ca certificate to browser
620 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
621 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
623 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
624 print "Content-Type: application/force-download \n " ;
625 print "Content-Type: application/octet-stream \r\n " ;
626 print "Content-Disposition: attachment; filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
627 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
630 $errormessage = $Lang :: tr
{ 'invalid key' };
634 ### Remove ca certificate (step 2)
636 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
637 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
638 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
640 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
641 foreach my $key ( keys %confighash ) {
642 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
643 if ( $test =~ /: OK/ ) {
645 system ( '/usr/local/bin/ipsecctrl' , 'D' , $key ) if (& vpnenabled
);
646 unlink ( "${General::swroot}/certs/ $confighash { $key }[1]cert.pem" );
647 unlink ( "${General::swroot}/certs/ $confighash { $key }[1].p12" );
648 delete $confighash { $key };
649 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
653 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
654 delete $cahash { $cgiparams { 'KEY' }};
655 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
656 system ( '/usr/local/bin/ipsecctrl' , 'R' );
659 $errormessage = $Lang :: tr
{ 'invalid key' };
662 ### Remove ca certificate (step 1)
664 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
665 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
666 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
668 my $assignedcerts = 0 ;
669 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
670 foreach my $key ( keys %confighash ) {
671 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
672 if ( $test =~ /: OK/ ) {
676 if ( $assignedcerts ) {
677 & Header
:: showhttpheaders
();
678 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
679 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
680 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
682 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
686 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
687 <input type='hidden' name='AREUSURE' value='yes' /></td>
690 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>
691 $Lang ::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}</td>
694 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
695 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
702 & Header
:: closebigbox
();
703 & Header
:: closepage
();
706 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
707 delete $cahash { $cgiparams { 'KEY' }};
708 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
709 system ( '/usr/local/bin/ipsecctrl' , 'R' );
713 $errormessage = $Lang :: tr
{ 'invalid key' };
717 ### Display root certificate
719 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
720 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
722 & Header
:: showhttpheaders
();
723 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
724 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
725 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
726 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'root certificate'}:" );
727 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/cacert.pem` ;
729 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'host certificate'}:" );
730 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/hostcert.pem` ;
732 $output = & Header
:: cleanhtml
( $output , "y" );
733 print "<pre> $output </pre> \n " ;
735 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
736 & Header
:: closebigbox
();
737 & Header
:: closepage
();
741 ### Export root certificate to browser
743 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
744 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
745 print "Content-Type: application/force-download \n " ;
746 print "Content-Disposition: attachment; filename=cacert.pem \r\n\r\n " ;
747 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/cacert.pem` ;
751 ### Export host certificate to browser
753 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
754 if ( - f
"${General::swroot}/certs/hostcert.pem" ) {
755 print "Content-Type: application/force-download \n " ;
756 print "Content-Disposition: attachment; filename=hostcert.pem \r\n\r\n " ;
757 print `/usr/bin/openssl x509 -in ${General::swroot}/certs/hostcert.pem` ;
761 ### Form for generating/importing the caroot+host certificate
763 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
764 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
766 if (- f
"${General::swroot}/ca/cacert.pem" ) {
767 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
771 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
772 # fill in initial values
773 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
774 if (- e
"${General::swroot}/red/active" && open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
775 my $ipaddr = < IPADDR
>;
778 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
779 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
780 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
783 $cgiparams { 'ROOTCERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' } if (! $cgiparams { 'ROOTCERT_COUNTRY' });
784 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
785 & General
:: log ( "ipsec" , "Importing from p12..." );
787 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
788 $errormessage = $Lang :: tr
{ 'there was no file upload' };
792 # Move uploaded certificate request to a temporary file
793 ( my $fh , my $filename ) = tempfile
( );
794 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
799 # Extract the CA certificate from the file
800 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
801 if ( open ( STDIN
, "-|" )) {
802 my $opt = " pkcs12 -cacerts -nokeys" ;
803 $opt .= " -in $filename " ;
804 $opt .= " -out /tmp/newcacert" ;
805 $errormessage = & callssl
( $opt );
807 print " $cgiparams {'P12_PASS'} \n " ;
811 # Extract the Host certificate from the file
812 if (! $errormessage ) {
813 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
814 if ( open ( STDIN
, "-|" )) {
815 my $opt = " pkcs12 -clcerts -nokeys" ;
816 $opt .= " -in $filename " ;
817 $opt .= " -out /tmp/newhostcert" ;
818 $errormessage = & callssl
( $opt );
820 print " $cgiparams {'P12_PASS'} \n " ;
825 # Extract the Host key from the file
826 if (! $errormessage ) {
827 & General
:: log ( "ipsec" , "Extracting private key from p12..." );
828 if ( open ( STDIN
, "-|" )) {
829 my $opt = " pkcs12 -nocerts -nodes" ;
830 $opt .= " -in $filename " ;
831 $opt .= " -out /tmp/newhostkey" ;
832 $errormessage = & callssl
( $opt );
834 print " $cgiparams {'P12_PASS'} \n " ;
839 if (! $errormessage ) {
840 & General
:: log ( "ipsec" , "Moving cacert..." );
841 move
( "/tmp/newcacert" , "${General::swroot}/ca/cacert.pem" );
842 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
845 if (! $errormessage ) {
846 & General
:: log ( "ipsec" , "Moving host cert..." );
847 move
( "/tmp/newhostcert" , "${General::swroot}/certs/hostcert.pem" );
848 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
851 if (! $errormessage ) {
852 & General
:: log ( "ipsec" , "Moving private key..." );
853 move
( "/tmp/newhostkey" , "${General::swroot}/certs/hostkey.pem" );
854 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
859 unlink ( '/tmp/newcacert' );
860 unlink ( '/tmp/newhostcert' );
861 unlink ( '/tmp/newhostkey' );
863 unlink ( "${General::swroot}/ca/cacert.pem" );
864 unlink ( "${General::swroot}/certs/hostcert.pem" );
865 unlink ( "${General::swroot}/certs/hostkey.pem" );
869 # Create empty CRL cannot be done because we don't have
870 # the private key for this CAROOT
871 # IPFire can only import certificates
873 & General
:: log ( "ipsec" , "p12 import completed!" );
875 goto ROOTCERT_SUCCESS
;
877 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
879 # Validate input since the form was submitted
880 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
881 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
884 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
885 $errormessage = $Lang :: tr
{ 'organization too long' };
888 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
889 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
892 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
893 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
896 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
897 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
900 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
901 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
904 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
905 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
908 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
909 $errormessage = $Lang :: tr
{ 'invalid input for department' };
912 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
913 $errormessage = $Lang :: tr
{ 'invalid input for city' };
916 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
917 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
920 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
921 $errormessage = $Lang :: tr
{ 'invalid input for country' };
924 #the exact syntax is a list comma separated of
925 # email:any-validemail
926 # URI: a uniform resource indicator
927 # DNS: a DNS domain name
928 # RID: a registered OBJECT IDENTIFIER
930 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
932 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
933 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
937 # Copy the cgisettings to vpnsettings and save the configfile
938 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
939 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
940 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
941 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
942 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
943 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
944 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
945 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
947 # Replace empty strings with a .
948 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
949 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
950 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
952 # Create the CA certificate
953 if (! $errormessage ) {
954 & General
:: log ( "ipsec" , "Creating cacert..." );
955 if ( open ( STDIN
, "-|" )) {
956 my $opt = " req -x509 -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
957 $opt .= " -days 999999" ;
958 $opt .= " -newkey rsa:2048" ;
959 $opt .= " -keyout ${General::swroot}/private/cakey.pem" ;
960 $opt .= " -out ${General::swroot}/ca/cacert.pem" ;
962 $errormessage = & callssl
( $opt );
964 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
967 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
969 print " $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
970 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
975 # Create the Host certificate request
976 if (! $errormessage ) {
977 & General
:: log ( "ipsec" , "Creating host cert..." );
978 if ( open ( STDIN
, "-|" )) {
979 my $opt = " req -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
980 $opt .= " -newkey rsa:1024" ;
981 $opt .= " -keyout ${General::swroot}/certs/hostkey.pem" ;
982 $opt .= " -out ${General::swroot}/certs/hostreq.pem" ;
983 $errormessage = & callssl
( $opt );
985 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
988 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
990 print " $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
991 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
998 # Sign the host certificate request
999 if (! $errormessage ) {
1000 & General
:: log ( "ipsec" , "Self signing host cert..." );
1002 #No easy way for specifying the contain of subjectAltName without writing a config file...
1003 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1005 basicConstraints=CA:FALSE
1006 nsComment="OpenSSL Generated Certificate"
1007 subjectKeyIdentifier=hash
1008 authorityKeyIdentifier=keyid,issuer:always
1011 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1014 my $opt = " ca -days 999999" ;
1015 $opt .= " -batch -notext" ;
1016 $opt .= " -in ${General::swroot}/certs/hostreq.pem" ;
1017 $opt .= " -out ${General::swroot}/certs/hostcert.pem" ;
1018 $opt .= " -extfile $v3extname " ;
1019 $errormessage = & callssl
( $opt );
1020 unlink ( "${General::swroot}/certs/hostreq.pem" ); #no more needed
1021 unlink ( $v3extname );
1024 # Create an empty CRL
1025 if (! $errormessage ) {
1026 & General
:: log ( "ipsec" , "Creating emptycrl..." );
1027 my $opt = " ca -gencrl" ;
1028 $opt .= " -out ${General::swroot}/crls/cacrl.pem" ;
1029 $errormessage = & callssl
( $opt );
1032 # Successfully build CA / CERT!
1033 if (! $errormessage ) {
1034 & cleanssldatabase
();
1035 goto ROOTCERT_SUCCESS
;
1039 unlink ( "${General::swroot}/ca/cacert.pem" );
1040 unlink ( "${General::swroot}/certs/hostkey.pem" );
1041 unlink ( "${General::swroot}/certs/hostcert.pem" );
1042 unlink ( "${General::swroot}/crls/cacrl.pem" );
1043 & cleanssldatabase
();
1047 & Header
:: showhttpheaders
();
1048 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1049 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1050 if ( $errormessage ) {
1051 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1052 print "<class name='base'> $errormessage " ;
1053 print " </class>" ;
1054 & Header
:: closebox
();
1056 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
1058 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
1059 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1060 <tr><td width='40%' class='base'> $Lang ::tr{'organization name'}:</td>
1061 <td width='60%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td></tr>
1062 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}:</td>
1063 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td></tr>
1064 <tr><td class='base'> $Lang ::tr{'your e-mail'}: <img src='/blob.gif' alt='*' /></td>
1065 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td></tr>
1066 <tr><td class='base'> $Lang ::tr{'your department'}: <img src='/blob.gif' alt='*' /></td>
1067 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td></tr>
1068 <tr><td class='base'> $Lang ::tr{'city'}: <img src='/blob.gif' alt='*' /></td>
1069 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td></tr>
1070 <tr><td class='base'> $Lang ::tr{'state or province'}: <img src='/blob.gif' alt='*' /></td>
1071 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td></tr>
1072 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1073 <td class='base'><select name='ROOTCERT_COUNTRY'>
1076 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1077 print "<option value=' $Countries ::countries{ $country }'" ;
1078 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1079 print " selected='selected'" ;
1081 print "> $country </option>" ;
1085 <tr><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*) <img src='/blob.gif' alt='*' /></td>
1086 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' /></td></tr>
1088 <td><br /><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /><br /><br /></td></tr>
1089 <tr><td class='base' colspan='2' align='left'>
1090 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1091 $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'}
1093 <tr><td colspan='2'><hr /></td></tr>
1094 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}:</td>
1095 <td nowrap='nowrap'><input type='file' name='FH' size='32' /></td></tr>
1096 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' /></td>
1097 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td></tr>
1099 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td></tr>
1100 <tr><td class='base' colspan='2' align='left'>
1101 <img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
1105 & Header
:: closebox
();
1106 & Header
:: closebigbox
();
1107 & Header
:: closepage
();
1112 system ( '/usr/local/bin/ipsecctrl' , 'S' );
1117 ### Export PKCS12 file to browser
1119 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
1120 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1121 print "Content-Type: application/force-download \n " ;
1122 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
1123 print "Content-Type: application/octet-stream \r\n\r\n " ;
1124 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12` ;
1128 ### Display certificate
1130 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
1131 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1133 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1134 & Header
:: showhttpheaders
();
1135 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1136 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1137 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'cert'}:" );
1138 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1139 $output = & Header
:: cleanhtml
( $output , "y" );
1140 print "<pre> $output </pre> \n " ;
1141 & Header
:: closebox
();
1142 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1143 & Header
:: closebigbox
();
1144 & Header
:: closepage
();
1149 ### Export Certificate to browser
1151 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
1152 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1154 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1155 print "Content-Type: application/force-download \n " ;
1156 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \n\n " ;
1157 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1162 ### Enable/Disable connection
1164 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1166 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1167 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1169 if ( $confighash { $cgiparams { 'KEY' }}) {
1170 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
1171 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
1172 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1174 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1176 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1177 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
1178 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1183 $errormessage = $Lang :: tr
{ 'invalid key' };
1187 ### Restart connection
1189 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
1190 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1191 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1193 if ( $confighash { $cgiparams { 'KEY' }}) {
1195 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
1199 $errormessage = $Lang :: tr
{ 'invalid key' };
1203 ### Remove connection
1205 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
1206 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1207 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1209 if ( $confighash { $cgiparams { 'KEY' }}) {
1210 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1211 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1212 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1213 delete $confighash { $cgiparams { 'KEY' }};
1214 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1217 $errormessage = $Lang :: tr
{ 'invalid key' };
1221 ### Choose between adding a host-net or net-net connection
1223 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
1224 & Header
:: showhttpheaders
();
1225 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1226 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1227 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection type' });
1229 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
1230 <b> $Lang ::tr{'connection type'}:</b><br />
1232 <tr><td><input type='radio' name='TYPE' value='host' checked='checked' /></td>
1233 <td class='base'> $Lang ::tr{'host to net vpn'}</td>
1235 <td><input type='radio' name='TYPE' value='net' /></td>
1236 <td class='base'> $Lang ::tr{'net to net vpn'}</td>
1238 <td align='center' colspan='2'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td>
1243 & Header
:: closebox
();
1244 & Header
:: closebigbox
();
1245 & Header
:: closepage
();
1248 ### Adding/Editing/Saving a connection
1250 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
1251 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
1252 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
1254 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1255 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1256 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1258 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
1259 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
1260 $errormessage = $Lang :: tr
{ 'invalid key' };
1263 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
1264 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
1265 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
1266 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
1267 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
1268 #$cgiparams{'free'} = $confighash{$cgiparams{'KEY'}}[6];
1269 $cgiparams { 'LOCAL_ID' } = $confighash { $cgiparams { 'KEY' }}[ 7 ];
1270 $cgiparams { 'LOCAL_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 8 ];
1271 $cgiparams { 'REMOTE_ID' } = $confighash { $cgiparams { 'KEY' }}[ 9 ];
1272 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
1273 $cgiparams { 'REMOTE_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 11 ];
1274 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
1275 $cgiparams { 'INTERFACE' } = $confighash { $cgiparams { 'KEY' }}[ 26 ];
1276 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
1277 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
1278 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
1279 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
1280 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
1281 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
1282 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
1283 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
1284 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
1285 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
1286 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
1287 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
1288 $cgiparams { 'VHOST' } = $confighash { $cgiparams { 'KEY' }}[ 14 ];
1290 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
1291 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
1292 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
1293 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
1297 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
1298 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
1302 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
1303 $errormessage = $Lang :: tr
{ 'name is invalid' };
1307 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
1308 $errormessage = $Lang :: tr
{ 'name too long' };
1312 # Check if there is no other entry with this name
1313 if (! $cgiparams { 'KEY' }) { #only for add
1314 foreach my $key ( keys %confighash ) {
1315 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
1316 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
1322 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! $cgiparams { 'REMOTE' })) {
1323 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1327 if ( $cgiparams { 'REMOTE' }) {
1328 if (! & General
:: validip
( $cgiparams { 'REMOTE' })) {
1329 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
1330 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1333 if (& valid_dns_host
( $cgiparams { 'REMOTE' })) {
1334 $warnmessage = " $Lang ::tr{'check vpn lr'} $cgiparams {'REMOTE'}. $Lang ::tr{'dns check failed'}" ;
1340 unless (& General
:: validipandmask
( $cgiparams { 'LOCAL_SUBNET' })) {
1341 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
1345 # Allow only one roadwarrior/psk without remote IP-address
1346 if ( $cgiparams { 'REMOTE' } eq '' && $cgiparams { 'AUTH' } eq 'psk' ) {
1347 foreach my $key ( keys %confighash ) {
1348 if ( ( $cgiparams { 'KEY' } ne $key ) &&
1349 ( $confighash { $key }[ 4 ] eq 'psk' ) &&
1350 ( $confighash { $key }[ 10 ] eq '' ) ) {
1351 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
1356 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! & General
:: validipandmask
( $cgiparams { 'REMOTE_SUBNET' }))) {
1357 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
1361 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
1362 $errormessage = $Lang :: tr
{ 'invalid input' };
1365 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
1366 $errormessage = $Lang :: tr
{ 'invalid input' };
1370 # Allow nothing or a string (DN,FDQN,) beginning with @
1371 # with no comma but slashes between RID eg @O=FR/C=Paris/OU=myhome/CN=franck
1372 if ( ( $cgiparams { 'LOCAL_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d\
. \d\
. \d\
. \d
)$/) ||
1373 ( $cgiparams { 'REMOTE_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d\
. \d\
. \d\
. \d
)$/) ||
1374 (( $cgiparams { 'REMOTE_ID' } eq $cgiparams { 'LOCAL_ID' }) && ( $cgiparams { 'LOCAL_ID' } ne '' ))
1376 $errormessage = $Lang :: tr
{ 'invalid local-remote id' } . '<br />' .
1377 'DER_ASN1_DN: @c =FR/ou=Paris/ou=Home/cn=*<br />' .
1378 'FQDN: @ipfire .org<br />' .
1379 'USER_FQDN: info @ipfire .org<br />' .
1380 'IPV4_ADDR: @123 .123.123.123' ;
1383 # If Auth is DN, verify existance of Remote ID.
1384 if ( $cgiparams { 'REMOTE_ID' } eq '' && (
1385 $cgiparams { 'AUTH' } eq 'auth-dn' || # while creation
1386 $confighash { $cgiparams { 'KEY' }}[ 2 ] eq ' %auth -dn' )){ # while editing
1387 $errormessage = $Lang :: tr
{ 'vpn missing remote id' };
1391 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1392 if (! length ( $cgiparams { 'PSK' }) ) {
1393 $errormessage = $Lang :: tr
{ 'pre-shared key is too short' };
1396 if ( $cgiparams { 'PSK' } =~ /'/ ) {
1397 $cgiparams { 'PSK' } =~ tr/'/ / ;
1398 $errormessage = $Lang :: tr
{ 'invalid characters found in pre-shared key' };
1401 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
1402 if ( $cgiparams { 'KEY' }) {
1403 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1406 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1407 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1411 # Move uploaded certificate request to a temporary file
1412 ( my $fh , my $filename ) = tempfile
( );
1413 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1418 # Sign the certificate request
1419 & General
:: log ( "ipsec" , "Signing your cert $cgiparams {'NAME'}..." );
1420 my $opt = " ca -days 999999" ;
1421 $opt .= " -batch -notext" ;
1422 $opt .= " -in $filename " ;
1423 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1425 if ( $errormessage = & callssl
( $opt ) ) {
1427 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1428 & cleanssldatabase
();
1432 & cleanssldatabase
();
1435 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1436 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1437 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1440 } elsif ( $cgiparams { 'AUTH' } eq 'pkcs12' ) {
1441 & General
:: log ( "ipsec" , "Importing from p12..." );
1443 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1444 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1445 goto ROOTCERT_ERROR
;
1448 # Move uploaded certificate request to a temporary file
1449 ( my $fh , my $filename ) = tempfile
( );
1450 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1452 goto ROOTCERT_ERROR
;
1455 # Extract the CA certificate from the file
1456 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
1457 if ( open ( STDIN
, "-|" )) {
1458 my $opt = " pkcs12 -cacerts -nokeys" ;
1459 $opt .= " -in $filename " ;
1460 $opt .= " -out /tmp/newcacert" ;
1461 $errormessage = & callssl
( $opt );
1463 print " $cgiparams {'P12_PASS'} \n " ;
1467 # Extract the Host certificate from the file
1468 if (! $errormessage ) {
1469 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
1470 if ( open ( STDIN
, "-|" )) {
1471 my $opt = " pkcs12 -clcerts -nokeys" ;
1472 $opt .= " -in $filename " ;
1473 $opt .= " -out /tmp/newhostcert" ;
1474 $errormessage = & callssl
( $opt );
1476 print " $cgiparams {'P12_PASS'} \n " ;
1481 if (! $errormessage ) {
1482 & General
:: log ( "ipsec" , "Moving cacert..." );
1483 #If CA have new subject, add it to our list of CA
1484 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( '/tmp/newcacert' ));
1486 foreach my $x ( keys %cahash ) {
1487 $casubject = '' if ( $cahash { $x }[ 1 ] eq $casubject );
1488 unshift ( @names , $cahash { $x }[ 0 ]);
1490 if ( $casubject ) { # a new one!
1491 my $temp = `/usr/bin/openssl x509 -text -in /tmp/newcacert` ;
1492 if ( $temp !~ /CA:TRUE/i ) {
1493 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
1495 #compute a name for it
1497 while ( grep ( /Imported-$idx/ , @names ) ) { $idx ++};
1498 $cgiparams { 'CA_NAME' }= "Imported- $idx " ;
1499 $cgiparams { 'CERT_NAME' }=& Header
:: cleanhtml
( getCNfromcert
( '/tmp/newhostcert' ));
1500 move
( "/tmp/newcacert" , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1501 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1502 if (! $errormessage ) {
1503 my $key = & General
:: findhasharraykey
( \
%cahash );
1504 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
1505 $cahash { $key }[ 1 ] = $casubject ;
1506 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1507 system ( '/usr/local/bin/ipsecctrl' , 'R' );
1512 if (! $errormessage ) {
1513 & General
:: log ( "ipsec" , "Moving host cert..." );
1514 move
( "/tmp/newhostcert" , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1515 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1520 unlink ( '/tmp/newcacert' );
1521 unlink ( '/tmp/newhostcert' );
1522 if ( $errormessage ) {
1523 unlink ( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1524 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1527 & General
:: log ( "ipsec" , "p12 import completed!" );
1528 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
1529 if ( $cgiparams { 'KEY' }) {
1530 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1533 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1534 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1537 # Move uploaded certificate to a temporary file
1538 ( my $fh , my $filename ) = tempfile
( );
1539 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1544 # Verify the certificate has a valid CA and move it
1545 & General
:: log ( "ipsec" , "Validating imported cert against our known CA..." );
1546 my $validca = 1 ; #assume ok
1547 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/cacert.pem $filename ` ;
1548 if ( $test !~ /: OK/ ) {
1550 foreach my $key ( keys %cahash ) {
1551 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $key }[0]cert.pem $filename ` ;
1552 if ( $test =~ /: OK/ ) {
1559 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
1563 move
( $filename , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1565 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1571 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1572 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1573 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1574 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1577 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
1578 if ( $cgiparams { 'KEY' }) {
1579 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1582 # Validate input since the form was submitted
1583 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
1584 $errormessage = $Lang :: tr
{ 'name too long' };
1587 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1588 $errormessage = $Lang :: tr
{ 'invalid input for name' };
1591 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
1592 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1595 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
1596 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1599 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1600 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1603 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
1604 $errormessage = $Lang :: tr
{ 'organization too long' };
1607 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1608 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1611 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1612 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1615 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1616 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1619 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1620 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1623 #the exact syntax is a list comma separated of
1624 # email:any-validemail
1625 # URI: a uniform resource indicator
1626 # DNS: a DNS domain name
1627 # RID: a registered OBJECT IDENTIFIER
1629 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
1631 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
1632 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
1636 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
1637 $errormessage = $Lang :: tr
{ 'password too short' };
1640 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
1641 $errormessage = $Lang :: tr
{ 'passwords do not match' };
1645 # Replace empty strings with a .
1646 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
1647 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
1648 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
1650 # Create the Host certificate request
1651 & General
:: log ( "ipsec" , "Creating a cert..." );
1653 if ( open ( STDIN
, "-|" )) {
1654 my $opt = " req -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
1655 $opt .= " -newkey rsa:1024" ;
1656 $opt .= " -keyout ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1657 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1659 if ( $errormessage = & callssl
( $opt ) ) {
1660 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1661 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1665 print " $cgiparams {'CERT_COUNTRY'} \n " ;
1668 print " $cgiparams {'CERT_ORGANIZATION'} \n " ;
1670 print " $cgiparams {'CERT_NAME'} \n " ;
1671 print " $cgiparams {'CERT_EMAIL'} \n " ;
1677 # Sign the host certificate request
1678 & General
:: log ( "ipsec" , "Signing the cert $cgiparams {'NAME'}..." );
1680 #No easy way for specifying the contain of subjectAltName without writing a config file...
1681 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1683 basicConstraints=CA:FALSE
1684 nsComment="OpenSSL Generated Certificate"
1685 subjectKeyIdentifier=hash
1686 authorityKeyIdentifier=keyid,issuer:always
1689 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1692 my $opt = " ca -days 999999 -batch -notext" ;
1693 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1694 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1695 $opt .= " -extfile $v3extname " ;
1697 if ( $errormessage = & callssl
( $opt ) ) {
1698 unlink ( $v3extname );
1699 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1700 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1701 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1702 & cleanssldatabase
();
1705 unlink ( $v3extname );
1706 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1707 & cleanssldatabase
();
1710 # Create the pkcs12 file
1711 & General
:: log ( "ipsec" , "Packing a pkcs12 file..." );
1712 $opt = " pkcs12 -export" ;
1713 $opt .= " -inkey ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1714 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1715 $opt .= " -name \" $cgiparams {'NAME'} \" " ;
1716 $opt .= " -passout pass: $cgiparams {'CERT_PASS1'}" ;
1717 $opt .= " -certfile ${General::swroot}/ca/cacert.pem" ;
1718 $opt .= " -caname \" $vpnsettings {'ROOTCERT_ORGANIZATION'} CA \" " ;
1719 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}.p12" ;
1721 if ( $errormessage = & callssl
( $opt ) ) {
1722 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1723 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1724 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}.p12" );
1727 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1729 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
1730 ; # Nothing, just editing
1731 } elsif ( $cgiparams { 'AUTH' } eq 'auth-dn' ) {
1732 $cgiparams { 'CERT_NAME' } = ' %auth -dn' ; # a special value saying 'no cert file'
1734 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
1738 # 1)Error message here is not accurate.
1739 # 2)Test is superfluous, openswan can reference same cert multiple times
1740 # 3)Present since initial version (1.3.2.11), it isn't a bug correction
1741 # Check if there is no other entry with this certificate name
1742 #if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk') && ($cgiparams{'AUTH'} ne 'auth-dn')) {
1743 # foreach my $key (keys %confighash) {
1744 # if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) {
1745 # $errormessage = $Lang::tr{'a connection with this common name already exists'};
1746 # goto VPNCONF_ERROR;
1752 my $key = $cgiparams { 'KEY' };
1754 $key = & General
:: findhasharraykey
( \
%confighash );
1755 foreach my $i ( 0 .. 28 ) { $confighash { $key }[ $i ] = "" ;}
1757 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
1758 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
1759 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
1760 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
1762 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
1763 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1764 $confighash { $key }[ 4 ] = 'psk' ;
1765 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
1767 $confighash { $key }[ 4 ] = 'cert' ;
1769 if ( $cgiparams { 'TYPE' } eq 'net' ) {
1770 $confighash { $key }[ 11 ] = $cgiparams { 'REMOTE_SUBNET' };
1772 $confighash { $key }[ 7 ] = $cgiparams { 'LOCAL_ID' };
1773 $confighash { $key }[ 8 ] = $cgiparams { 'LOCAL_SUBNET' };
1774 $confighash { $key }[ 9 ] = $cgiparams { 'REMOTE_ID' };
1775 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
1776 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
1777 $confighash { $key }[ 26 ] = $cgiparams { 'INTERFACE' };
1778 $confighash { $key }[ 27 ] = $cgiparams { 'DPD_ACTION' };
1780 #dont forget advanced value
1781 $confighash { $key }[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
1782 $confighash { $key }[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
1783 $confighash { $key }[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
1784 $confighash { $key }[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
1785 $confighash { $key }[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
1786 $confighash { $key }[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
1787 $confighash { $key }[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
1788 $confighash { $key }[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
1789 $confighash { $key }[ 12 ] = 'off' ; # $cgiparams{'AGGRMODE'};
1790 $confighash { $key }[ 13 ] = $cgiparams { 'COMPRESSION' };
1791 $confighash { $key }[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
1792 $confighash { $key }[ 28 ] = $cgiparams { 'PFS' };
1793 $confighash { $key }[ 14 ] = $cgiparams { 'VHOST' };
1795 #free unused fields!
1796 $confighash { $key }[ 6 ] = 'off' ;
1797 $confighash { $key }[ 15 ] = 'off' ;
1799 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1802 system ( '/usr/local/bin/ipsecctrl' , 'S' , $key );
1805 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
1806 $cgiparams { 'KEY' } = $key ;
1807 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
1810 } else { # add new connection
1811 $cgiparams { 'ENABLED' } = 'on' ;
1812 if ( ! - f
"${General::swroot}/private/cakey.pem" ) {
1813 $cgiparams { 'AUTH' } = 'psk' ;
1814 } elsif ( ! - f
"${General::swroot}/ca/cacert.pem" ) {
1815 $cgiparams { 'AUTH' } = 'certfile' ;
1817 $cgiparams { 'AUTH' } = 'certgen' ;
1819 $cgiparams { 'LOCAL_SUBNET' } = " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" ;
1820 $cgiparams { 'CERT_EMAIL' } = $vpnsettings { 'ROOTCERT_EMAIL' };
1821 $cgiparams { 'CERT_OU' } = $vpnsettings { 'ROOTCERT_OU' };
1822 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
1823 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
1824 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
1825 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
1827 # choose appropriate dpd action
1828 if ( $cgiparams { 'TYPE' } eq 'host' ) {
1829 $cgiparams { 'DPD_ACTION' } = 'clear' ;
1831 $cgiparams { 'DPD_ACTION' } = 'restart' ;
1834 # Default is yes for 'pfs'
1835 $cgiparams { 'PFS' } = 'on' ;
1838 $cgiparams { 'LOCAL_ID' } = '' ;
1839 $cgiparams { 'REMOTE_ID' } = '' ;
1841 #use default advanced value
1842 $cgiparams { 'IKE_ENCRYPTION' } = 'aes128|3des' ; #[18];
1843 $cgiparams { 'IKE_INTEGRITY' } = 'sha|md5' ; #[19];
1844 $cgiparams { 'IKE_GROUPTYPE' } = '1536|1024' ; #[20];
1845 $cgiparams { 'IKE_LIFETIME' } = '1' ; #[16];
1846 $cgiparams { 'ESP_ENCRYPTION' } = 'aes128|3des' ; #[21];
1847 $cgiparams { 'ESP_INTEGRITY' } = 'sha1|md5' ; #[22];
1848 $cgiparams { 'ESP_GROUPTYPE' } = '' ; #[23];
1849 $cgiparams { 'ESP_KEYLIFE' } = '8' ; #[17];
1850 $cgiparams { 'COMPRESSION' } = 'off' ; #[13];
1851 $cgiparams { 'ONLY_PROPOSED' } = 'off' ; #[24];
1852 $cgiparams { 'PFS' } = 'on' ; #[28];
1853 $cgiparams { 'VHOST' } = 'on' ; #[14];
1857 $checked { 'ENABLED' }{ 'off' } = '' ;
1858 $checked { 'ENABLED' }{ 'on' } = '' ;
1859 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = "checked='checked'" ;
1861 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
1862 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
1863 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = "checked='checked'" ;
1865 $checked { 'AUTH' }{ 'psk' } = '' ;
1866 $checked { 'AUTH' }{ 'certreq' } = '' ;
1867 $checked { 'AUTH' }{ 'certgen' } = '' ;
1868 $checked { 'AUTH' }{ 'certfile' } = '' ;
1869 $checked { 'AUTH' }{ 'pkcs12' } = '' ;
1870 $checked { 'AUTH' }{ 'auth-dn' } = '' ;
1871 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = "checked='checked'" ;
1873 $selected { 'INTERFACE' }{ 'RED' } = '' ;
1874 $selected { 'INTERFACE' }{ 'ORANGE' } = '' ;
1875 $selected { 'INTERFACE' }{ 'GREEN' } = '' ;
1876 $selected { 'INTERFACE' }{ 'BLUE' } = '' ;
1877 $selected { 'INTERFACE' }{ $cgiparams { 'INTERFACE' }} = "selected='selected'" ;
1879 $selected { 'DPD_ACTION' }{ 'clear' } = '' ;
1880 $selected { 'DPD_ACTION' }{ 'hold' } = '' ;
1881 $selected { 'DPD_ACTION' }{ 'restart' } = '' ;
1882 $selected { 'DPD_ACTION' }{ $cgiparams { 'DPD_ACTION' }} = "selected='selected'" ;
1884 & Header
:: showhttpheaders
();
1885 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1886 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1887 if ( $errormessage ) {
1888 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1889 print "<class name='base'> $errormessage " ;
1890 print " </class>" ;
1891 & Header
:: closebox
();
1895 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'warning messages'}:" );
1896 print "<class name='base'> $warnmessage " ;
1897 print " </class>" ;
1898 & Header
:: closebox
();
1901 print "<form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>" ;
1903 <input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />
1904 <input type='hidden' name='IKE_ENCRYPTION' value=' $cgiparams {'IKE_ENCRYPTION'}' />
1905 <input type='hidden' name='IKE_INTEGRITY' value=' $cgiparams {'IKE_INTEGRITY'}' />
1906 <input type='hidden' name='IKE_GROUPTYPE' value=' $cgiparams {'IKE_GROUPTYPE'}' />
1907 <input type='hidden' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' />
1908 <input type='hidden' name='ESP_ENCRYPTION' value=' $cgiparams {'ESP_ENCRYPTION'}' />
1909 <input type='hidden' name='ESP_INTEGRITY' value=' $cgiparams {'ESP_INTEGRITY'}' />
1910 <input type='hidden' name='ESP_GROUPTYPE' value=' $cgiparams {'ESP_GROUPTYPE'}' />
1911 <input type='hidden' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' />
1912 <input type='hidden' name='COMPRESSION' value=' $cgiparams {'COMPRESSION'}' />
1913 <input type='hidden' name='ONLY_PROPOSED' value=' $cgiparams {'ONLY_PROPOSED'}' />
1914 <input type='hidden' name='PFS' value=' $cgiparams {'PFS'}' />
1915 <input type='hidden' name='VHOST' value=' $cgiparams {'VHOST'}' />
1918 if ( $cgiparams { 'KEY' }) {
1919 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
1920 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
1923 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'connection'}:" );
1924 print "<table width='100%'>" ;
1925 print "<tr><td width='25%' class='boldbase'> $Lang ::tr{'name'}:</td>" ;
1926 if ( $cgiparams { 'KEY' }) {
1927 print "<td width='25%' class='base'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /><b> $cgiparams {'NAME'}</b></td>" ;
1929 print "<td width='25%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' size='30' /></td>" ;
1931 print "<td> $Lang ::tr{'enabled'}</td><td><input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td></tr>" ;
1932 print '</tr><td><br /></td><tr>' ;
1936 if ( $cgiparams { 'TYPE' } eq 'host' ) {
1937 $disabled = "disabled='disabled'" ;
1938 $blob = "<img src='/blob.gif' alt='*' />" ;
1941 print "<tr><td> $Lang ::tr{'host ip'}:</td>" ;
1942 print "<td><select name='INTERFACE'>" ;
1943 print "<option value='RED' $selected {'INTERFACE'}{'RED'}>RED ( $vpnsettings {'VPN_IP'})</option>" ;
1944 print "<option value='GREEN' $selected {'INTERFACE'}{'GREEN'}>GREEN ( $netsettings {'GREEN_ADDRESS'})</option>" ;
1945 print "<option value='BLUE' $selected {'INTERFACE'}{'BLUE'}>BLUE ( $netsettings {'BLUE_ADDRESS'})</option>" if ( $netsettings { 'BLUE_DEV' } ne '' );
1946 print "<option value='ORANGE' $selected {'INTERFACE'}{'ORANGE'}>ORANGE ( $netsettings {'ORANGE_ADDRESS'})</option>" if ( $netsettings { 'ORANGE_DEV' } ne '' );
1947 print "</select></td>" ;
1949 <td class='boldbase'> $Lang ::tr{'remote host/ip'}: $blob </td>
1950 <td><input type='text' name='REMOTE' value=' $cgiparams {'REMOTE'}' size='30' /></td>
1952 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'}</td>
1953 <td><input type='text' name='LOCAL_SUBNET' value=' $cgiparams {'LOCAL_SUBNET'}' size='30' /></td>
1954 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'}</td>
1955 <td><input $disabled type='text' name='REMOTE_SUBNET' value=' $cgiparams {'REMOTE_SUBNET'}' size='30' /></td>
1957 <td class='boldbase'> $Lang ::tr{'vpn local id'}:<br />( $Lang ::tr{'eg'} <tt>@xy.example.com</tt>)</td>
1958 <td><input type='text' name='LOCAL_ID' value=' $cgiparams {'LOCAL_ID'}' /></td>
1959 <td class='boldbase'> $Lang ::tr{'vpn remote id'}:</td>
1960 <td><input type='text' name='REMOTE_ID' value=' $cgiparams {'REMOTE_ID'}' /></td>
1962 </tr><td><br /></td><tr>
1963 <td> $Lang ::tr{'dpd action'}:</td>
1964 <td><select name='DPD_ACTION'>
1965 <option value='clear' $selected {'DPD_ACTION'}{'clear'}>clear</option>
1966 <option value='hold' $selected {'DPD_ACTION'}{'hold'}>hold</option>
1967 <option value='restart' $selected {'DPD_ACTION'}{'restart'}>restart</option>
1968 </select> <a href='http://www.openswan.com/docs/local/README.DPD'>?</a>
1971 <!--http://www.openswan.com/docs/local/README.DPD
1972 http://bugs.xelerance.com/view.php?id=156
1973 restart = clear + reinitiate connection
1975 <td class='boldbase'> $Lang ::tr{'remark title'} <img src='/blob.gif' alt='*' /></td>
1976 <td colspan='3'><input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' size='55' maxlength='50' /></td>
1980 if (! $cgiparams { 'KEY' }) {
1981 print "<tr><td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked {'EDIT_ADVANCED'}{'on'} /> $Lang ::tr{'edit advanced settings when done'}</td></tr>" ;
1984 & Header
:: closebox
();
1986 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
1987 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
1989 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
1990 <tr><td class='base' width='50%'> $Lang ::tr{'use a pre-shared key'}</td>
1991 <td class='base' width='50%'><input type='text' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td>
1996 & Header
:: closebox
();
1997 } elsif (! $cgiparams { 'KEY' }) {
1998 my $pskdisabled = ( $vpnsettings { 'VPN_IP' } eq ' %defaultroute ' ) ?
"disabled='disabled'" : '' ;
1999 $cgiparams { 'PSK' } = $Lang :: tr
{ 'vpn incompatible use of defaultroute' } if ( $pskdisabled );
2000 my $cakeydisabled = ( ! - f
"${General::swroot}/private/cakey.pem" ) ?
"disabled='disabled'" : '' ;
2001 $cgiparams { 'CERT_NAME' } = $Lang :: tr
{ 'vpn no full pki' } if ( $cakeydisabled );
2002 my $cacrtdisabled = ( ! - f
"${General::swroot}/ca/cacert.pem" ) ?
"disabled='disabled'" : '' ;
2004 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2006 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2007 <tr><td width='5%'><input type='radio' name='AUTH' value='psk' $checked {'AUTH'}{'psk'} $pskdisabled /></td>
2008 <td class='base' width='55%'> $Lang ::tr{'use a pre-shared key'}</td>
2009 <td class='base' width='40%'><input type='text' name='PSK' size='30' value=' $cgiparams {'PSK'}' $pskdisabled /></td></tr>
2010 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2011 <tr><td><input type='radio' name='AUTH' value='certreq' $checked {'AUTH'}{'certreq'} $cakeydisabled /></td>
2012 <td class='base'><hr /> $Lang ::tr{'upload a certificate request'}</td>
2013 <td class='base' rowspan='3' valign='middle'><input type='file' name='FH' size='30' $cacrtdisabled /></td></tr>
2014 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td>
2015 <td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
2016 <tr><td><input type='radio' name='AUTH' value='pkcs12' $cacrtdisabled /></td>
2017 <td class='base'> $Lang ::tr{'upload p12 file'} $Lang ::tr{'pkcs12 file password'}:<input type='password' name='P12_PASS'/></td></tr>
2018 <tr><td><input type='radio' name='AUTH' value='auth-dn' $checked {'AUTH'}{'auth-dn'} $cacrtdisabled /></td>
2019 <td class='base'><hr /> $Lang ::tr{'vpn auth-dn'}</td></tr>
2020 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2021 <tr><td><input type='radio' name='AUTH' value='certgen' $checked {'AUTH'}{'certgen'} $cakeydisabled /></td>
2022 <td class='base'><hr /> $Lang ::tr{'generate a certificate'}</td><td> </td></tr>
2024 <td class='base'> $Lang ::tr{'users fullname or system hostname'}:</td>
2025 <td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' size='32' $cakeydisabled /></td></tr>
2027 <td class='base'> $Lang ::tr{'users email'}: <img src='/blob.gif' alt='*' /></td>
2028 <td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' size='32' $cakeydisabled /></td></tr>
2030 <td class='base'> $Lang ::tr{'users department'}: <img src='/blob.gif' alt='*' /></td>
2031 <td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' size='32' $cakeydisabled /></td></tr>
2033 <td class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
2034 <td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' size='32' $cakeydisabled /></td></tr>
2036 <td class='base'> $Lang ::tr{'city'}: <img src='/blob.gif' alt='*' /></td>
2037 <td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' size='32' $cakeydisabled /></td></tr>
2039 <td class='base'> $Lang ::tr{'state or province'}: <img src='/blob.gif' alt='*' /></td>
2040 <td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' size='32' $cakeydisabled /></td></tr>
2042 <td class='base'> $Lang ::tr{'country'}:</td>
2043 <td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
2046 foreach my $country ( sort keys %{ Countries
:: countries
}) {
2047 print " \t\t\t <option value=' $Countries ::countries{ $country }'" ;
2048 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
2049 print " selected='selected'" ;
2051 print "> $country </option> \n " ;
2056 <tr><td> </td><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)<img src='/blob.gif' alt='*' /></td>
2057 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' $cakeydisabled /></td></tr>
2059 <td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
2060 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
2061 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'}:( $Lang ::tr{'confirmation'})</td>
2062 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
2066 & Header
:: closebox
();
2069 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
2070 if ( $cgiparams { 'KEY' }) {
2071 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced'}' />" ;
2073 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
2074 & Header
:: closebigbox
();
2075 & Header
:: closepage
();
2082 ### Advanced settings
2084 if (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced' }) ||
2085 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq 'yes' )) {
2086 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
2087 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2088 if (! $confighash { $cgiparams { 'KEY' }}) {
2089 $errormessage = $Lang :: tr
{ 'invalid key' };
2093 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
2094 # I didn't read any incompatibilities here....
2095 #if ($cgiparams{'VHOST'} eq 'on' && $cgiparams{'COMPRESSION'} eq 'on') {
2096 # $errormessage = $Lang::tr{'cannot enable both nat traversal and compression'};
2097 # goto ADVANCED_ERROR;
2099 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2101 $errormessage = $Lang :: tr
{ 'invalid input' };
2102 goto ADVANCED_ERROR
;
2104 foreach my $val ( @temp ) {
2105 if ( $val !~ /^(aes256|aes128|3des)$/ ) {
2106 $errormessage = $Lang :: tr
{ 'invalid input' };
2107 goto ADVANCED_ERROR
;
2110 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2112 $errormessage = $Lang :: tr
{ 'invalid input' };
2113 goto ADVANCED_ERROR
;
2115 foreach my $val ( @temp ) {
2116 if ( $val !~ /^(sha2_512|sha2_256|sha|md5)$/ ) {
2117 $errormessage = $Lang :: tr
{ 'invalid input' };
2118 goto ADVANCED_ERROR
;
2121 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2123 $errormessage = $Lang :: tr
{ 'invalid input' };
2124 goto ADVANCED_ERROR
;
2126 foreach my $val ( @temp ) {
2127 if ( $val !~ /^(1024|1536|2048|3072|4096|6144|8192)$/ ) {
2128 $errormessage = $Lang :: tr
{ 'invalid input' };
2129 goto ADVANCED_ERROR
;
2132 if ( $cgiparams { 'IKE_LIFETIME' } !~ /^\d+$/ ) {
2133 $errormessage = $Lang :: tr
{ 'invalid input for ike lifetime' };
2134 goto ADVANCED_ERROR
;
2136 if ( $cgiparams { 'IKE_LIFETIME' } < 1 || $cgiparams { 'IKE_LIFETIME' } > 8 ) {
2137 $errormessage = $Lang :: tr
{ 'ike lifetime should be between 1 and 8 hours' };
2138 goto ADVANCED_ERROR
;
2140 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2142 $errormessage = $Lang :: tr
{ 'invalid input' };
2143 goto ADVANCED_ERROR
;
2145 foreach my $val ( @temp ) {
2146 if ( $val !~ /^(aes256|aes128|3des)$/ ) {
2147 $errormessage = $Lang :: tr
{ 'invalid input' };
2148 goto ADVANCED_ERROR
;
2151 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2153 $errormessage = $Lang :: tr
{ 'invalid input' };
2154 goto ADVANCED_ERROR
;
2156 foreach my $val ( @temp ) {
2157 if ( $val !~ /^(sha2_512|sha2_256|sha1|md5)$/ ) {
2158 $errormessage = $Lang :: tr
{ 'invalid input' };
2159 goto ADVANCED_ERROR
;
2162 if ( $cgiparams { 'ESP_GROUPTYPE' } ne '' &&
2163 $cgiparams { 'ESP_GROUPTYPE' } !~ /^modp(1024|1536|2048|3072|4096)$/ ) {
2164 $errormessage = $Lang :: tr
{ 'invalid input' };
2165 goto ADVANCED_ERROR
;
2168 if ( $cgiparams { 'ESP_KEYLIFE' } !~ /^\d+$/ ) {
2169 $errormessage = $Lang :: tr
{ 'invalid input for esp keylife' };
2170 goto ADVANCED_ERROR
;
2172 if ( $cgiparams { 'ESP_KEYLIFE' } < 1 || $cgiparams { 'ESP_KEYLIFE' } > 24 ) {
2173 $errormessage = $Lang :: tr
{ 'esp keylife should be between 1 and 24 hours' };
2174 goto ADVANCED_ERROR
;
2178 ( $cgiparams { 'COMPRESSION' } !~ /^(|on|off)$/ ) ||
2179 ( $cgiparams { 'ONLY_PROPOSED' } !~ /^(|on|off)$/ ) ||
2180 ( $cgiparams { 'PFS' } !~ /^(|on|off)$/ ) ||
2181 ( $cgiparams { 'VHOST' } !~ /^(|on|off)$/ )
2183 $errormessage = $Lang :: tr
{ 'invalid input' };
2184 goto ADVANCED_ERROR
;
2187 $confighash { $cgiparams { 'KEY' }}[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
2188 $confighash { $cgiparams { 'KEY' }}[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
2189 $confighash { $cgiparams { 'KEY' }}[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
2190 $confighash { $cgiparams { 'KEY' }}[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
2191 $confighash { $cgiparams { 'KEY' }}[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
2192 $confighash { $cgiparams { 'KEY' }}[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
2193 $confighash { $cgiparams { 'KEY' }}[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
2194 $confighash { $cgiparams { 'KEY' }}[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
2195 $confighash { $cgiparams { 'KEY' }}[ 12 ] = 'off' ; #$cgiparams{'AGGRMODE'};
2196 $confighash { $cgiparams { 'KEY' }}[ 13 ] = $cgiparams { 'COMPRESSION' };
2197 $confighash { $cgiparams { 'KEY' }}[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
2198 $confighash { $cgiparams { 'KEY' }}[ 28 ] = $cgiparams { 'PFS' };
2199 $confighash { $cgiparams { 'KEY' }}[ 14 ] = $cgiparams { 'VHOST' };
2200 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2203 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
2208 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
2209 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
2210 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
2211 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
2212 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
2213 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
2214 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
2215 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
2216 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
2217 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
2218 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
2219 $cgiparams { 'VHOST' } = $confighash { $cgiparams { 'KEY' }}[ 14 ];
2221 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' || $confighash { $cgiparams { 'KEY' }}[ 10 ]) {
2222 $cgiparams { 'VHOST' } = 'off' ;
2227 $checked { 'IKE_ENCRYPTION' }{ 'aes256' } = '' ;
2228 $checked { 'IKE_ENCRYPTION' }{ 'aes128' } = '' ;
2229 $checked { 'IKE_ENCRYPTION' }{ '3des' } = '' ;
2230 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2231 foreach my $key ( @temp ) { $checked { 'IKE_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2232 $checked { 'IKE_INTEGRITY' }{ 'sha2_512' } = '' ;
2233 $checked { 'IKE_INTEGRITY' }{ 'sha2_256' } = '' ;
2234 $checked { 'IKE_INTEGRITY' }{ 'sha' } = '' ;
2235 $checked { 'IKE_INTEGRITY' }{ 'md5' } = '' ;
2236 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2237 foreach my $key ( @temp ) { $checked { 'IKE_INTEGRITY' }{ $key } = "selected='selected'" ; }
2238 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2239 $checked { 'IKE_GROUPTYPE' }{ '1024' } = '' ;
2240 $checked { 'IKE_GROUPTYPE' }{ '1536' } = '' ;
2241 $checked { 'IKE_GROUPTYPE' }{ '2048' } = '' ;
2242 $checked { 'IKE_GROUPTYPE' }{ '3072' } = '' ;
2243 $checked { 'IKE_GROUPTYPE' }{ '4096' } = '' ;
2244 $checked { 'IKE_GROUPTYPE' }{ '6144' } = '' ;
2245 $checked { 'IKE_GROUPTYPE' }{ '8192' } = '' ;
2246 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2247 foreach my $key ( @temp ) { $checked { 'IKE_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2249 # 768 is not supported by strongswan
2250 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2253 $checked { 'ESP_ENCRYPTION' }{ 'aes256' } = '' ;
2254 $checked { 'ESP_ENCRYPTION' }{ 'aes128' } = '' ;
2255 $checked { 'ESP_ENCRYPTION' }{ '3des' } = '' ;
2256 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2257 foreach my $key ( @temp ) { $checked { 'ESP_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2258 $checked { 'ESP_INTEGRITY' }{ 'sha2_512' } = '' ;
2259 $checked { 'ESP_INTEGRITY' }{ 'sha2_256' } = '' ;
2260 $checked { 'ESP_INTEGRITY' }{ 'sha1' } = '' ;
2261 $checked { 'ESP_INTEGRITY' }{ 'md5' } = '' ;
2262 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2263 foreach my $key ( @temp ) { $checked { 'ESP_INTEGRITY' }{ $key } = "selected='selected'" ; }
2264 $checked { 'ESP_GROUPTYPE' }{ $cgiparams { 'ESP_GROUPTYPE' }} = "selected='selected'" ;
2266 $checked { 'COMPRESSION' } = $cgiparams { 'COMPRESSION' } eq 'on' ?
"checked='checked'" : '' ;
2267 $checked { 'ONLY_PROPOSED' } = $cgiparams { 'ONLY_PROPOSED' } eq 'on' ?
"checked='checked'" : '' ;
2268 $checked { 'PFS' } = $cgiparams { 'PFS' } eq 'on' ?
"checked='checked'" : '' ;
2269 $checked { 'VHOST' } = $cgiparams { 'VHOST' } eq 'on' ?
"checked='checked'" : '' ;
2271 & Header
:: showhttpheaders
();
2272 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
2273 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2275 if ( $errormessage ) {
2276 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2277 print "<class name='base'> $errormessage " ;
2278 print " </class>" ;
2279 & Header
:: closebox
();
2283 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
2284 print "<class name='base'> $warnmessage " ;
2285 print " </class>" ;
2286 & Header
:: closebox
();
2289 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'advanced'}:" );
2291 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
2292 <input type='hidden' name='ADVANCED' value='yes' />
2293 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
2295 <table width='100%'>
2296 <tr><td class='boldbase' align='right' valign='top'> $Lang ::tr{'ike encryption'}</td><td class='boldbase' valign='top'>
2297 <select name='IKE_ENCRYPTION' multiple='multiple' size='4'>
2298 <option value='aes256' $checked {'IKE_ENCRYPTION'}{'aes256'}>AES (256 bit)</option>
2299 <option value='aes128' $checked {'IKE_ENCRYPTION'}{'aes128'}>AES (128 bit)</option>
2300 <option value='3des' $checked {'IKE_ENCRYPTION'}{'3des'}>3DES</option>
2303 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'ike integrity'}</td><td class='boldbase' valign='top'>
2304 <select name='IKE_INTEGRITY' multiple='multiple' size='4'>
2305 <option value='sha' $checked {'IKE_INTEGRITY'}{'sha'}>SHA</option>
2306 <option value='md5' $checked {'IKE_INTEGRITY'}{'md5'}>MD5</option>
2309 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'ike grouptype'}</td><td class='boldbase' valign='top'>
2310 <select name='IKE_GROUPTYPE' multiple='multiple' size='4'>
2311 <option value='8192' $checked {'IKE_GROUPTYPE'}{'8192'}>MODP-8192</option>
2312 <option value='6144' $checked {'IKE_GROUPTYPE'}{'6144'}>MODP-6144</option>
2313 <option value='4096' $checked {'IKE_GROUPTYPE'}{'4096'}>MODP-4096</option>
2314 <option value='3072' $checked {'IKE_GROUPTYPE'}{'3072'}>MODP-3072</option>
2315 <option value='2048' $checked {'IKE_GROUPTYPE'}{'2048'}>MODP-2048</option>
2316 <option value='1536' $checked {'IKE_GROUPTYPE'}{'1536'}>MODP-1536</option>
2317 <option value='1024' $checked {'IKE_GROUPTYPE'}{'1024'}>MODP-1024</option>
2320 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'ike lifetime'}</td><td class='boldbase' valign='top'>
2321 <input type='text' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' size='5' /> $Lang ::tr{'hours'}</td>
2324 <td colspan='1'><hr /></td>
2326 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'esp encryption'}</td><td class='boldbase' valign='top'>
2327 <select name='ESP_ENCRYPTION' multiple='multiple' size='4'>
2328 <option value='aes256' $checked {'ESP_ENCRYPTION'}{'aes256'}>AES (256 bit)</option>
2329 <option value='aes128' $checked {'ESP_ENCRYPTION'}{'aes128'}>AES (128 bit)</option>
2330 <option value='3des' $checked {'ESP_ENCRYPTION'}{'3des'}>3DES</option>
2332 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'esp integrity'}</td><td class='boldbase' valign='top'>
2333 <select name='ESP_INTEGRITY' multiple='multiple' size='4'>
2334 <option value='sha1' $checked {'ESP_INTEGRITY'}{'sha1'}>SHA1</option>
2335 <option value='md5' $checked {'ESP_INTEGRITY'}{'md5'}>MD5</option></select></td>
2337 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'esp grouptype'}</td><td class='boldbase' valign='top'>
2338 <select name='ESP_GROUPTYPE'>
2339 <option value=''> $Lang ::tr{'phase1 group'}</option></select></td>
2341 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'esp keylife'}</td><td class='boldbase' valign='top'>
2342 <input type='text' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' size='5' /> $Lang ::tr{'hours'}</td>
2344 <td colspan='1'><hr /></td>
2346 <td colspan='5'><input type='checkbox' name='ONLY_PROPOSED' $checked {'ONLY_PROPOSED'} />
2347 IKE+ESP: $Lang ::tr{'use only proposed settings'}</td>
2349 <td colspan='5'><input type='checkbox' name='PFS' $checked {'PFS'} />
2350 $Lang ::tr{'pfs yes no'}</td>
2351 <td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' /></td>
2353 <td colspan='5'><input type='checkbox' name='COMPRESSION' $checked {'COMPRESSION'} />
2354 $Lang ::tr{'vpn payload compression'}</td>
2355 <td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
2359 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ) {
2360 print "<tr><td><input type='hidden' name='VHOST' value='off' /></td></tr>" ;
2361 } elsif ( $confighash { $cgiparams { 'KEY' }}[ 10 ]) {
2362 print "<tr><td colspan='5'><input type='checkbox' name='VHOST' $checked {'VHOST'} disabled='disabled' />" ;
2363 print " $Lang ::tr{'vpn vhost'}</td></tr>" ;
2365 print "<tr><td colspan='5'><input type='checkbox' name='VHOST' $checked {'VHOST'} />" ;
2366 print " $Lang ::tr{'vpn vhost'}</td></tr>" ;
2369 print "</table></form>" ;
2370 & Header
:: closebox
();
2371 & Header
:: closebigbox
();
2372 & Header
:: closepage
();
2379 ### Default status page
2384 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%cgiparams );
2385 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
2386 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2387 $cgiparams { 'CA_NAME' } = '' ;
2389 my @status = `/usr/local/bin/ipsecctrl I` ;
2391 # suggest a default name for this side
2392 if ( $cgiparams { 'VPN_IP' } eq '' && - e
"${General::swroot}/red/active" ) {
2393 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
2394 my $ipaddr = < IPADDR
>;
2397 $cgiparams { 'VPN_IP' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
2398 if ( $cgiparams { 'VPN_IP' } eq '' ) {
2399 $cgiparams { 'VPN_IP' } = $ipaddr ;
2403 # no IP found, use %defaultroute
2404 $cgiparams { 'VPN_IP' } = ' %defaultroute ' if ( $cgiparams { 'VPN_IP' } eq '' );
2406 $cgiparams { 'VPN_DELAYED_START' } = 0 if (! defined ( $cgiparams { 'VPN_DELAYED_START' }));
2407 $checked { 'VPN_WATCH' } = $cgiparams { 'VPN_WATCH' } eq 'on' ?
"checked='checked'" : '' ;
2408 map ( $checked { $_ } = $cgiparams { $_ } eq 'on' ?
"checked='checked'" : '' ,
2409 ( 'ENABLED' , 'DBG_CRYPT' , 'DBG_PARSING' , 'DBG_EMITTING' , 'DBG_CONTROL' ,
2413 & Header
:: showhttpheaders
();
2414 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
2415 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2417 if ( $errormessage ) {
2418 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2419 print "<class name='base'> $errormessage \n " ;
2420 print " </class> \n " ;
2421 & Header
:: closebox
();
2424 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'global settings' });
2426 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2427 <table width='100%'>
2429 <td width='20%' class='base' nowrap='nowrap'> $Lang ::tr{'vpn red name'}:</td>
2430 <td width='20%'><input type='text' name='VPN_IP' value=' $cgiparams {'VPN_IP'}' /></td>
2431 <td width='20%' class='base'> $Lang ::tr{'enabled'}<input type='checkbox' name='ENABLED' $checked {'ENABLED'} /></td>
2437 <td class='base' nowrap='nowrap'> $Lang ::tr{'override mtu'}: <img src='/blob.gif' alt='*' /></td>
2438 <td ><input type='text' name='VPN_OVERRIDE_MTU' value=' $cgiparams {'VPN_OVERRIDE_MTU'}' /></td>
2444 <td class='base' nowrap='nowrap'> $Lang ::tr{'vpn delayed start'}: <img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' /></td>
2445 <td ><input type='text' name='VPN_DELAYED_START' value=' $cgiparams {'VPN_DELAYED_START'}' /></td>
2448 <p> $Lang ::tr{'vpn watch'}:<input type='checkbox' name='VPN_WATCH' $checked {'VPN_WATCH'} /></p>
2449 <p>PLUTO DEBUG =
2450 crypt:<input type='checkbox' name='DBG_CRYPT' $checked {'DBG_CRYPT'} />,
2451 parsing:<input type='checkbox' name='DBG_PARSING' $checked {'DBG_PARSING'} />,
2452 emitting:<input type='checkbox' name='DBG_EMITTING' $checked {'DBG_EMITTING'} />,
2453 control:<input type='checkbox' name='DBG_CONTROL' $checked {'DBG_CONTROL'} />,
2454 dns:<input type='checkbox' name='DBG_DNS' $checked {'DBG_DNS'} />
2456 <table width='100%'>
2458 <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
2459 <td width='70%' class='base' valign='top'> $Lang ::tr{'this field may be blank'}</td>
2462 <td class='base' valign='top' nowrap='nowrap'><img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' /> </td>
2463 <td class='base'> <font class='base'> $Lang ::tr{'vpn delayed start help'}</font></td>
2464 <td width='30%' align='center' class='base'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' /></td>
2470 & Header
:: closebox
();
2472 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection status and controlc' });
2474 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
2476 <td width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></td>
2477 <td width='22%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></td>
2478 <td width='23%' class='boldbase' align='center'><b> $Lang ::tr{'common name'}</b></td>
2479 <td width='30%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></td>
2480 <td width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></td>
2481 <td class='boldbase' align='center' colspan='6'><b> $Lang ::tr{'action'}</b></td>
2487 foreach my $key ( keys %confighash ) {
2488 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
2491 print "<tr bgcolor=' $color {'color20'}'> \n " ;
2493 print "<tr bgcolor=' $color {'color22'}'> \n " ;
2495 print "<td align='center' nowrap='nowrap'> $confighash { $key }[1]</td>" ;
2496 print "<td align='center' nowrap='nowrap'>" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ")</td>" ;
2497 if ( $confighash { $key }[ 2 ] eq ' %auth -dn' ) {
2498 print "<td align='left' nowrap='nowrap'> $confighash { $key }[9]</td>" ;
2499 } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
2500 print "<td align='left' nowrap='nowrap'> $confighash { $key }[2]</td>" ;
2502 print "<td align='left'> </td>" ;
2504 print "<td align='center'> $confighash { $key }[25]</td>" ;
2506 my $active = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourred}' width='100%'><tr><td align='center'><b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b></td></tr></table>" ;
2507 foreach my $line ( @status ) {
2508 if ( $line =~ /\"$confighash{$key}[1]\".*IPsec SA established/ ) {
2509 $active = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourgreen}' width='100%'><tr><td align='center'><b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b></td></tr></table>" ;
2512 # move to blueif really down
2513 if ( $confighash { $key }[ 0 ] eq 'off' && $active =~ /${Header::colourred}/ ) {
2514 $active = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourblue}' width='100%'><tr><td align='center'><b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b></td></tr></table>" ;
2517 <td align='center'> $active </td>
2519 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2520 <input type='image' name=' $Lang ::tr{'restart'}' src='/images/reload.gif' alt=' $Lang ::tr{'restart'}' title=' $Lang ::tr{'restart'}' />
2521 <input type='hidden' name='ACTION' value=' $Lang ::tr{'restart'}' />
2522 <input type='hidden' name='KEY' value=' $key ' />
2527 if (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
2530 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2531 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' />
2532 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
2533 <input type='hidden' name='KEY' value=' $key ' />
2538 print "<td width='2%'> </td>" ;
2540 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/certs/ $confighash { $key }[1].p12" ) {
2543 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2544 <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'}' />
2545 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
2546 <input type='hidden' name='KEY' value=' $key ' />
2550 ; } elsif (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
2553 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2554 <input type='image' name=' $Lang ::tr{'download certificate'}' src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' title=' $Lang ::tr{'download certificate'}' />
2555 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
2556 <input type='hidden' name='KEY' value=' $key ' />
2561 print "<td width='2%'> </td>" ;
2565 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2566 <input type='image' name=' $Lang ::tr{'toggle enable disable'}' src='/images/ $gif ' alt=' $Lang ::tr{'toggle enable disable'}' title=' $Lang ::tr{'toggle enable disable'}' />
2567 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
2568 <input type='hidden' name='KEY' value=' $key ' />
2573 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2574 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
2575 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' title=' $Lang ::tr{'edit'}' />
2576 <input type='hidden' name='KEY' value=' $key ' />
2579 <td align='center' >
2580 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2581 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
2582 <input type='image' name=' $Lang ::tr{'remove'}' src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' title=' $Lang ::tr{'remove'}' />
2583 <input type='hidden' name='KEY' value=' $key ' />
2593 # If the config file contains entries, print Key to action icons
2598 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
2599 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
2600 <td class='base'> $Lang ::tr{'click to disable'}</td>
2601 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
2602 <td class='base'> $Lang ::tr{'show certificate'}</td>
2603 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
2604 <td class='base'> $Lang ::tr{'edit'}</td>
2605 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
2606 <td class='base'> $Lang ::tr{'remove'}</td>
2610 <td> <img src='/images/off.gif' alt='?OFF' /></td>
2611 <td class='base'> $Lang ::tr{'click to enable'}</td>
2612 <td> <img src='/images/floppy.gif' alt='?FLOPPY' /></td>
2613 <td class='base'> $Lang ::tr{'download certificate'}</td>
2614 <td> <img src='/images/reload.gif' alt='?RELOAD'/></td>
2615 <td class='base'> $Lang ::tr{'restart'}</td>
2623 <table width='100%'>
2624 <tr><td align='center' colspan='9'>
2625 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2626 <input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />
2632 & Header
:: closebox
();
2634 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'certificate authorities'}:" );
2636 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
2638 <td width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></td>
2639 <td width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></td>
2640 <td width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></td>
2644 if (- f
"${General::swroot}/ca/cacert.pem" ) {
2645 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/cacert.pem" ));
2648 <tr bgcolor=' $color {'color22'}'>
2649 <td class='base'> $Lang ::tr{'root certificate'}</td>
2650 <td class='base'> $casubject </td>
2651 <td width='3%' align='center'>
2652 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2653 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
2654 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/info.gif' alt=' $Lang ::tr{'show root certificate'}' title=' $Lang ::tr{'show root certificate'}' />
2657 <td width='3%' align='center'>
2658 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2659 <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'}' />
2660 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
2663 <td width='4%'> </td></tr>
2667 # display rootcert generation buttons
2669 <tr bgcolor=' $color {'color22'}'>
2670 <td class='base'> $Lang ::tr{'root certificate'}:</td>
2671 <td class='base'> $Lang ::tr{'not present'}</td>
2672 <td colspan='3'> </td></tr>
2677 if (- f
"${General::swroot}/certs/hostcert.pem" ) {
2678 my $hostsubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/certs/hostcert.pem" ));
2681 <tr bgcolor=' $color {'color20'}'>
2682 <td class='base'> $Lang ::tr{'host certificate'}</td>
2683 <td class='base'> $hostsubject </td>
2684 <td width='3%' align='center'>
2685 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2686 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
2687 <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'}' />
2690 <td width='3%' align='center'>
2691 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2692 <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'}' />
2693 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download host certificate'}' />
2696 <td width='4%'> </td></tr>
2702 <tr bgcolor=' $color {'color20'}'>
2703 <td width='25%' class='base'> $Lang ::tr{'host certificate'}:</td>
2704 <td class='base'> $Lang ::tr{'not present'}</td>
2705 <td colspan='3'> </td></tr>
2711 if ( keys %cahash > 0 ) {
2712 foreach my $key ( keys %cahash ) {
2713 if ( $rowcolor ++ % 2 ) {
2714 print "<tr bgcolor=' $color {'color20'}'> \n " ;
2716 print "<tr bgcolor=' $color {'color22'}'> \n " ;
2718 print "<td class='base'> $cahash { $key }[0]</td> \n " ;
2719 print "<td class='base'> $cahash { $key }[1]</td> \n " ;
2722 <form method='post' name='cafrm${key}a' action=' $ENV {'SCRIPT_NAME'}'>
2723 <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'}' />
2724 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
2725 <input type='hidden' name='KEY' value=' $key ' />
2729 <form method='post' name='cafrm${key}b' action=' $ENV {'SCRIPT_NAME'}'>
2730 <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'}' />
2731 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
2732 <input type='hidden' name='KEY' value=' $key ' />
2736 <form method='post' name='cafrm${key}c' action=' $ENV {'SCRIPT_NAME'}'>
2737 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
2738 <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'}' />
2739 <input type='hidden' name='KEY' value=' $key ' />
2749 # If the file contains entries, print Key to action icons
2750 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
2753 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
2754 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
2755 <td class='base'> $Lang ::tr{'show certificate'}</td>
2756 <td> <img src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' /></td>
2757 <td class='base'> $Lang ::tr{'download certificate'}</td>
2762 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>" ;
2765 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
2766 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
2769 <td class='base' nowrap='nowrap'> $Lang ::tr{'ca name'}:</td>
2770 <td nowrap='nowrap'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' /> </td>
2771 <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td>
2772 <td nowrap='nowrap'><input type='submit' name='ACTION' value=' $Lang ::tr{'upload ca certificate'}' /></td>
2775 <td colspan='3'> $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}:</td>
2776 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' /></td>
2782 & Header
:: closebox
();
2783 & Header
:: closebigbox
();
2784 & Header
:: closepage
();