]>
git.ipfire.org Git - people/teissler/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 if (- f
"${General::swroot}/certs/hostkey.pem" ) {
293 print SECRETS
": RSA ${General::swroot}/certs/hostkey.pem \n "
295 my $last_secrets = '' ; # old the less specifics connections
297 foreach my $key ( keys %lconfighash ) {
298 next if ( $lconfighash { $key }[ 0 ] ne 'on' );
300 #remote peer is not set? => use '%any'
301 $lconfighash { $key }[ 10 ] = ' %any ' if ( $lconfighash { $key }[ 10 ] eq '' );
304 if ( $lconfighash { $key }[ 26 ] eq 'BLUE' ) {
305 $localside = $netsettings { 'BLUE_ADDRESS' };
306 } elsif ( $lconfighash { $key }[ 26 ] eq 'GREEN' ) {
307 $localside = $netsettings { 'GREEN_ADDRESS' };
308 } elsif ( $lconfighash { $key }[ 26 ] eq 'ORANGE' ) {
309 $localside = $netsettings { 'ORANGE_ADDRESS' };
311 $localside = $lvpnsettings { 'VPN_IP' };
314 print CONF
"conn $lconfighash { $key }[1] \n " ;
315 print CONF
" \t left= $localside \n " ;
316 print CONF
" \t leftnexthop= %defaultroute \n " if ( $lconfighash { $key }[ 26 ] eq 'RED' && $lvpnsettings { 'VPN_IP' } ne ' %defaultroute ' );
317 print CONF
" \t leftsubnet= $lconfighash { $key }[8] \n " ;
318 print CONF
" \t leftfirewall=yes \n " ;
319 print CONF
" \t lefthostaccess=yes \n " ;
321 print CONF
" \t right= $lconfighash { $key }[10] \n " ;
322 if ( $lconfighash { $key }[ 3 ] eq 'net' ) {
323 print CONF
" \t rightsubnet= $lconfighash { $key }[11] \n " ;
324 print CONF
" \t rightnexthop= %defaultroute \n " ;
325 } elsif ( $lconfighash { $key }[ 10 ] eq ' %any ' && $lconfighash { $key }[ 14 ] eq 'on' ) { #vhost allowed for roadwarriors?
326 print CONF
" \t rightsubnet=vhost: %no , %priv \n " ;
329 # Local Cert and Remote Cert (unless auth is DN dn-auth)
330 if ( $lconfighash { $key }[ 4 ] eq 'cert' ) {
331 print CONF
" \t leftcert=${General::swroot}/certs/hostcert.pem \n " ;
332 print CONF
" \t rightcert=${General::swroot}/certs/ $lconfighash { $key }[1]cert.pem \n " if ( $lconfighash { $key }[ 2 ] ne ' %auth -dn' );
335 # Local and Remote IDs
336 print CONF
" \t leftid= \" $lconfighash { $key }[7] \"\n " if ( $lconfighash { $key }[ 7 ]);
337 print CONF
" \t rightid= \" $lconfighash { $key }[9] \"\n " if ( $lconfighash { $key }[ 9 ]);
340 if ( $lconfighash { $key }[ 18 ] && $lconfighash { $key }[ 19 ] && $lconfighash { $key }[ 20 ]) {
342 my @encs = split ( '\|' , $lconfighash { $key }[ 18 ]);
343 my @ints = split ( '\|' , $lconfighash { $key }[ 19 ]);
344 my @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
346 foreach my $i ( @encs ) {
347 foreach my $j ( @ints ) {
348 foreach my $k ( @groups ) {
349 if ( $comma != 0 ) { print CONF
"," ; } else { $comma = 1 ; }
350 print CONF
" $i - $j -modp $k " ;
354 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
360 if ( $lconfighash { $key }[ 21 ] && $lconfighash { $key }[ 22 ]) {
362 my @encs = split ( '\|' , $lconfighash { $key }[ 21 ]);
363 my @ints = split ( '\|' , $lconfighash { $key }[ 22 ]);
365 foreach my $i ( @encs ) {
366 foreach my $j ( @ints ) {
367 if ( $comma != 0 ) { print CONF
"," ; } else { $comma = 1 ; }
371 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
377 if ( $lconfighash { $key }[ 23 ]) {
378 print CONF
" \t pfsgroup= $lconfighash { $key }[23] \n " ;
382 print CONF
" \t ikelifetime= $lconfighash { $key }[16]h \n " if ( $lconfighash { $key }[ 16 ]);
383 print CONF
" \t keylife= $lconfighash { $key }[17]h \n " if ( $lconfighash { $key }[ 17 ]);
386 print CONF
" \t compress=yes \n " if ( $lconfighash { $key }[ 13 ] eq 'on' );
388 # Dead Peer Detection
389 print CONF
" \t dpddelay=30 \n " ;
390 print CONF
" \t dpdtimeout=120 \n " ;
391 print CONF
" \t dpdaction= $lconfighash { $key }[27] \n " ;
394 print CONF
" \t pfs=" . ( $lconfighash { $key }[ 28 ] eq 'on' ?
"yes \n " : "no \n " );
396 # Build Authentication details: LEFTid RIGHTid : PSK psk
398 if ( $lconfighash { $key }[ 4 ] eq 'psk' ) {
399 $psk_line = ( $lconfighash { $key }[ 7 ] ?
$lconfighash { $key }[ 7 ] : $localside ) . " " ;
400 $psk_line .= $lconfighash { $key }[ 9 ] ?
$lconfighash { $key }[ 9 ] : $lconfighash { $key }[ 10 ]; #remoteid or remote address?
401 $psk_line .= " : PSK ' $lconfighash { $key }[5]' \n " ;
402 # if the line contains %any, it is less specific than two IP or ID, so move it at end of file.
403 if ( $psk_line =~ /%any/ ) {
404 $last_secrets .= $psk_line ;
406 print SECRETS
$psk_line ;
408 print CONF
" \t authby=secret \n " ;
410 print CONF
" \t authby=rsasig \n " ;
411 print CONF
" \t leftrsasigkey= %cert \n " ;
412 print CONF
" \t rightrsasigkey= %cert \n " ;
415 # Automatically start only if a net-to-net connection
416 if ( $lconfighash { $key }[ 3 ] eq 'host' ) {
417 print CONF
" \t auto=add \n " ;
419 print CONF
" \t auto=start \n " ;
423 print SECRETS
$last_secrets if ( $last_secrets );
429 ### Save main settings
431 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
432 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
433 unless (& General
:: validfqdn
( $cgiparams { 'VPN_IP' }) || & General
:: validip
( $cgiparams { 'VPN_IP' })
434 || $cgiparams { 'VPN_IP' } eq ' %defaultroute ' ) {
435 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
439 unless ( $cgiparams { 'VPN_DELAYED_START' } =~ /^[0-9]{1,3}$/ ) { #allow 0-999 seconds !
440 $errormessage = $Lang :: tr
{ 'invalid time period' };
444 unless ( $cgiparams { 'VPN_OVERRIDE_MTU' } =~ /^(|[0-9]{1,5})$/ ) { #allow 0-99999
445 $errormessage = $Lang :: tr
{ 'vpn mtu invalid' };
449 unless ( $cgiparams { 'VPN_WATCH' } =~ /^(|off|on)$/ ) {
450 $errormessage = $Lang :: tr
{ 'invalid input' };
454 map ( $vpnsettings { $_ } = $cgiparams { $_ },
455 ( 'ENABLED' , 'DBG_CRYPT' , 'DBG_PARSING' , 'DBG_EMITTING' , 'DBG_CONTROL' ,
458 $vpnsettings { 'VPN_IP' } = $cgiparams { 'VPN_IP' };
459 $vpnsettings { 'VPN_DELAYED_START' } = $cgiparams { 'VPN_DELAYED_START' };
460 $vpnsettings { 'VPN_OVERRIDE_MTU' } = $cgiparams { 'VPN_OVERRIDE_MTU' };
461 $vpnsettings { 'VPN_WATCH' } = $cgiparams { 'VPN_WATCH' };
462 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
465 system ( '/usr/local/bin/ipsecctrl' , 'S' );
467 system ( '/usr/local/bin/ipsecctrl' , 'D' );
474 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
475 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
477 foreach my $key ( keys %confighash ) {
478 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
479 delete $confighash { $key };
482 while ( my $file = glob ( "${General::swroot}/{ca,certs,crls,private}/*" )) {
486 if ( open ( FILE
, ">${General::swroot}/vpn/caconfig" )) {
490 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
492 system ( '/usr/local/bin/ipsecctrl' , 'R' );
498 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' }) {
499 & Header
:: showhttpheaders
();
500 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
501 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
502 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
504 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
508 <input type='hidden' name='AREUSURE' value='yes' />
509 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
510 $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}</td>
513 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' />
514 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
521 & Header
:: closebigbox
();
522 & Header
:: closepage
();
526 ### Upload CA Certificate
528 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
529 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
531 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
532 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
536 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
537 $errormessage = $Lang :: tr
{ 'name too long' };
541 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
542 $errormessage = $Lang :: tr
{ 'name is invalid' };
543 goto UPLOAD_CA_ERROR
;
546 # Check if there is no other entry with this name
547 foreach my $key ( keys %cahash ) {
548 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
549 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
554 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
555 $errormessage = $Lang :: tr
{ 'there was no file upload' };
558 # Move uploaded ca to a temporary file
559 ( my $fh , my $filename ) = tempfile
( );
560 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
564 my $temp = `/usr/bin/openssl x509 -text -in $filename ` ;
565 if ( $temp !~ /CA:TRUE/i ) {
566 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
570 move
( $filename , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
572 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
578 my $key = & General
:: findhasharraykey
( \
%cahash );
579 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
580 $cahash { $key }[ 1 ] = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" ));
581 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
583 system ( '/usr/local/bin/ipsecctrl' , 'R' );
589 ### Display ca certificate
591 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
592 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
594 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
595 & Header
:: showhttpheaders
();
596 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
597 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
598 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'ca certificate'}:" );
599 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
600 $output = & Header
:: cleanhtml
( $output , "y" );
601 print "<pre> $output </pre> \n " ;
603 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
604 & Header
:: closebigbox
();
605 & Header
:: closepage
();
608 $errormessage = $Lang :: tr
{ 'invalid key' };
612 ### Export ca certificate to browser
614 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
615 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
617 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
618 print "Content-Type: application/force-download \n " ;
619 print "Content-Type: application/octet-stream \r\n " ;
620 print "Content-Disposition: attachment; filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
621 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
624 $errormessage = $Lang :: tr
{ 'invalid key' };
628 ### Remove ca certificate (step 2)
630 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
631 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
632 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
634 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
635 foreach my $key ( keys %confighash ) {
636 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
637 if ( $test =~ /: OK/ ) {
639 system ( '/usr/local/bin/ipsecctrl' , 'D' , $key ) if (& vpnenabled
);
640 unlink ( "${General::swroot}/certs/ $confighash { $key }[1]cert.pem" );
641 unlink ( "${General::swroot}/certs/ $confighash { $key }[1].p12" );
642 delete $confighash { $key };
643 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
647 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
648 delete $cahash { $cgiparams { 'KEY' }};
649 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
650 system ( '/usr/local/bin/ipsecctrl' , 'R' );
653 $errormessage = $Lang :: tr
{ 'invalid key' };
656 ### Remove ca certificate (step 1)
658 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
659 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
660 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
662 my $assignedcerts = 0 ;
663 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
664 foreach my $key ( keys %confighash ) {
665 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
666 if ( $test =~ /: OK/ ) {
670 if ( $assignedcerts ) {
671 & Header
:: showhttpheaders
();
672 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
673 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
674 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
676 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
680 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
681 <input type='hidden' name='AREUSURE' value='yes' /></td>
684 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>
685 $Lang ::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}</td>
688 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
689 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
696 & Header
:: closebigbox
();
697 & Header
:: closepage
();
700 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
701 delete $cahash { $cgiparams { 'KEY' }};
702 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
703 system ( '/usr/local/bin/ipsecctrl' , 'R' );
707 $errormessage = $Lang :: tr
{ 'invalid key' };
711 ### Display root certificate
713 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
714 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
716 & Header
:: showhttpheaders
();
717 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
718 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
719 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
720 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'root certificate'}:" );
721 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/cacert.pem` ;
723 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'host certificate'}:" );
724 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/hostcert.pem` ;
726 $output = & Header
:: cleanhtml
( $output , "y" );
727 print "<pre> $output </pre> \n " ;
729 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
730 & Header
:: closebigbox
();
731 & Header
:: closepage
();
735 ### Export root certificate to browser
737 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
738 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
739 print "Content-Type: application/force-download \n " ;
740 print "Content-Disposition: attachment; filename=cacert.pem \r\n\r\n " ;
741 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/cacert.pem` ;
745 ### Export host certificate to browser
747 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
748 if ( - f
"${General::swroot}/certs/hostcert.pem" ) {
749 print "Content-Type: application/force-download \n " ;
750 print "Content-Disposition: attachment; filename=hostcert.pem \r\n\r\n " ;
751 print `/usr/bin/openssl x509 -in ${General::swroot}/certs/hostcert.pem` ;
755 ### Form for generating/importing the caroot+host certificate
757 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
758 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
760 if (- f
"${General::swroot}/ca/cacert.pem" ) {
761 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
765 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
766 # fill in initial values
767 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
768 if (- e
"${General::swroot}/red/active" && open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
769 my $ipaddr = < IPADDR
>;
772 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
773 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
774 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
777 $cgiparams { 'ROOTCERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' } if (! $cgiparams { 'ROOTCERT_COUNTRY' });
778 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
779 & General
:: log ( "ipsec" , "Importing from p12..." );
781 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
782 $errormessage = $Lang :: tr
{ 'there was no file upload' };
786 # Move uploaded certificate request to a temporary file
787 ( my $fh , my $filename ) = tempfile
( );
788 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
793 # Extract the CA certificate from the file
794 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
795 if ( open ( STDIN
, "-|" )) {
796 my $opt = " pkcs12 -cacerts -nokeys" ;
797 $opt .= " -in $filename " ;
798 $opt .= " -out /tmp/newcacert" ;
799 $errormessage = & callssl
( $opt );
801 print " $cgiparams {'P12_PASS'} \n " ;
805 # Extract the Host certificate from the file
806 if (! $errormessage ) {
807 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
808 if ( open ( STDIN
, "-|" )) {
809 my $opt = " pkcs12 -clcerts -nokeys" ;
810 $opt .= " -in $filename " ;
811 $opt .= " -out /tmp/newhostcert" ;
812 $errormessage = & callssl
( $opt );
814 print " $cgiparams {'P12_PASS'} \n " ;
819 # Extract the Host key from the file
820 if (! $errormessage ) {
821 & General
:: log ( "ipsec" , "Extracting private key from p12..." );
822 if ( open ( STDIN
, "-|" )) {
823 my $opt = " pkcs12 -nocerts -nodes" ;
824 $opt .= " -in $filename " ;
825 $opt .= " -out /tmp/newhostkey" ;
826 $errormessage = & callssl
( $opt );
828 print " $cgiparams {'P12_PASS'} \n " ;
833 if (! $errormessage ) {
834 & General
:: log ( "ipsec" , "Moving cacert..." );
835 move
( "/tmp/newcacert" , "${General::swroot}/ca/cacert.pem" );
836 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
839 if (! $errormessage ) {
840 & General
:: log ( "ipsec" , "Moving host cert..." );
841 move
( "/tmp/newhostcert" , "${General::swroot}/certs/hostcert.pem" );
842 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
845 if (! $errormessage ) {
846 & General
:: log ( "ipsec" , "Moving private key..." );
847 move
( "/tmp/newhostkey" , "${General::swroot}/certs/hostkey.pem" );
848 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
853 unlink ( '/tmp/newcacert' );
854 unlink ( '/tmp/newhostcert' );
855 unlink ( '/tmp/newhostkey' );
857 unlink ( "${General::swroot}/ca/cacert.pem" );
858 unlink ( "${General::swroot}/certs/hostcert.pem" );
859 unlink ( "${General::swroot}/certs/hostkey.pem" );
863 # Create empty CRL cannot be done because we don't have
864 # the private key for this CAROOT
865 # IPFire can only import certificates
867 & General
:: log ( "ipsec" , "p12 import completed!" );
869 goto ROOTCERT_SUCCESS
;
871 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
873 # Validate input since the form was submitted
874 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
875 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
878 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
879 $errormessage = $Lang :: tr
{ 'organization too long' };
882 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
883 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
886 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
887 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
890 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
891 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
894 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
895 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
898 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
899 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
902 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
903 $errormessage = $Lang :: tr
{ 'invalid input for department' };
906 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
907 $errormessage = $Lang :: tr
{ 'invalid input for city' };
910 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
911 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
914 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
915 $errormessage = $Lang :: tr
{ 'invalid input for country' };
918 #the exact syntax is a list comma separated of
919 # email:any-validemail
920 # URI: a uniform resource indicator
921 # DNS: a DNS domain name
922 # RID: a registered OBJECT IDENTIFIER
924 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
926 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
927 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
931 # Copy the cgisettings to vpnsettings and save the configfile
932 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
933 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
934 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
935 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
936 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
937 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
938 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
939 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
941 # Replace empty strings with a .
942 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
943 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
944 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
946 # Create the CA certificate
947 if (! $errormessage ) {
948 & General
:: log ( "ipsec" , "Creating cacert..." );
949 if ( open ( STDIN
, "-|" )) {
950 my $opt = " req -x509 -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
951 $opt .= " -days 999999" ;
952 $opt .= " -newkey rsa:2048" ;
953 $opt .= " -keyout ${General::swroot}/private/cakey.pem" ;
954 $opt .= " -out ${General::swroot}/ca/cacert.pem" ;
956 $errormessage = & callssl
( $opt );
958 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
961 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
963 print " $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
964 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
969 # Create the Host certificate request
970 if (! $errormessage ) {
971 & General
:: log ( "ipsec" , "Creating host cert..." );
972 if ( open ( STDIN
, "-|" )) {
973 my $opt = " req -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
974 $opt .= " -newkey rsa:1024" ;
975 $opt .= " -keyout ${General::swroot}/certs/hostkey.pem" ;
976 $opt .= " -out ${General::swroot}/certs/hostreq.pem" ;
977 $errormessage = & callssl
( $opt );
979 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
982 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
984 print " $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
985 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
992 # Sign the host certificate request
993 if (! $errormessage ) {
994 & General
:: log ( "ipsec" , "Self signing host cert..." );
996 #No easy way for specifying the contain of subjectAltName without writing a config file...
997 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
999 basicConstraints=CA:FALSE
1000 nsComment="OpenSSL Generated Certificate"
1001 subjectKeyIdentifier=hash
1002 authorityKeyIdentifier=keyid,issuer:always
1005 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1008 my $opt = " ca -days 999999" ;
1009 $opt .= " -batch -notext" ;
1010 $opt .= " -in ${General::swroot}/certs/hostreq.pem" ;
1011 $opt .= " -out ${General::swroot}/certs/hostcert.pem" ;
1012 $opt .= " -extfile $v3extname " ;
1013 $errormessage = & callssl
( $opt );
1014 unlink ( "${General::swroot}/certs/hostreq.pem" ); #no more needed
1015 unlink ( $v3extname );
1018 # Create an empty CRL
1019 if (! $errormessage ) {
1020 & General
:: log ( "ipsec" , "Creating emptycrl..." );
1021 my $opt = " ca -gencrl" ;
1022 $opt .= " -out ${General::swroot}/crls/cacrl.pem" ;
1023 $errormessage = & callssl
( $opt );
1026 # Successfully build CA / CERT!
1027 if (! $errormessage ) {
1028 & cleanssldatabase
();
1029 goto ROOTCERT_SUCCESS
;
1033 unlink ( "${General::swroot}/ca/cacert.pem" );
1034 unlink ( "${General::swroot}/certs/hostkey.pem" );
1035 unlink ( "${General::swroot}/certs/hostcert.pem" );
1036 unlink ( "${General::swroot}/crls/cacrl.pem" );
1037 & cleanssldatabase
();
1041 & Header
:: showhttpheaders
();
1042 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1043 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1044 if ( $errormessage ) {
1045 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1046 print "<class name='base'> $errormessage " ;
1047 print " </class>" ;
1048 & Header
:: closebox
();
1050 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
1052 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
1053 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1054 <tr><td width='40%' class='base'> $Lang ::tr{'organization name'}:</td>
1055 <td width='60%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td></tr>
1056 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}:</td>
1057 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td></tr>
1058 <tr><td class='base'> $Lang ::tr{'your e-mail'}: <img src='/blob.gif' alt='*' /></td>
1059 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td></tr>
1060 <tr><td class='base'> $Lang ::tr{'your department'}: <img src='/blob.gif' alt='*' /></td>
1061 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td></tr>
1062 <tr><td class='base'> $Lang ::tr{'city'}: <img src='/blob.gif' alt='*' /></td>
1063 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td></tr>
1064 <tr><td class='base'> $Lang ::tr{'state or province'}: <img src='/blob.gif' alt='*' /></td>
1065 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td></tr>
1066 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1067 <td class='base'><select name='ROOTCERT_COUNTRY'>
1070 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1071 print "<option value=' $Countries ::countries{ $country }'" ;
1072 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1073 print " selected='selected'" ;
1075 print "> $country </option>" ;
1079 <tr><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*) <img src='/blob.gif' alt='*' /></td>
1080 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' /></td></tr>
1082 <td><br /><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /><br /><br /></td></tr>
1083 <tr><td class='base' colspan='2' align='left'>
1084 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1085 $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'}
1087 <tr><td colspan='2'><hr /></td></tr>
1088 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}:</td>
1089 <td nowrap='nowrap'><input type='file' name='FH' size='32' /></td></tr>
1090 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' /></td>
1091 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td></tr>
1093 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td></tr>
1094 <tr><td class='base' colspan='2' align='left'>
1095 <img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
1099 & Header
:: closebox
();
1100 & Header
:: closebigbox
();
1101 & Header
:: closepage
();
1106 system ( '/usr/local/bin/ipsecctrl' , 'S' );
1111 ### Export PKCS12 file to browser
1113 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
1114 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1115 print "Content-Type: application/force-download \n " ;
1116 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
1117 print "Content-Type: application/octet-stream \r\n\r\n " ;
1118 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12` ;
1122 ### Display certificate
1124 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
1125 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1127 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1128 & Header
:: showhttpheaders
();
1129 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1130 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1131 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'cert'}:" );
1132 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1133 $output = & Header
:: cleanhtml
( $output , "y" );
1134 print "<pre> $output </pre> \n " ;
1135 & Header
:: closebox
();
1136 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1137 & Header
:: closebigbox
();
1138 & Header
:: closepage
();
1143 ### Export Certificate to browser
1145 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
1146 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1148 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1149 print "Content-Type: application/force-download \n " ;
1150 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \n\n " ;
1151 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1156 ### Enable/Disable connection
1158 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1160 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1161 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1163 if ( $confighash { $cgiparams { 'KEY' }}) {
1164 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
1165 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
1166 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1168 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1170 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1171 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
1172 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1177 $errormessage = $Lang :: tr
{ 'invalid key' };
1181 ### Restart connection
1183 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
1184 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1185 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1187 if ( $confighash { $cgiparams { 'KEY' }}) {
1189 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
1193 $errormessage = $Lang :: tr
{ 'invalid key' };
1197 ### Remove connection
1199 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
1200 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1201 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1203 if ( $confighash { $cgiparams { 'KEY' }}) {
1204 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1205 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1206 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1207 delete $confighash { $cgiparams { 'KEY' }};
1208 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1211 $errormessage = $Lang :: tr
{ 'invalid key' };
1215 ### Choose between adding a host-net or net-net connection
1217 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
1218 & Header
:: showhttpheaders
();
1219 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1220 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1221 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection type' });
1223 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
1224 <b> $Lang ::tr{'connection type'}:</b><br />
1226 <tr><td><input type='radio' name='TYPE' value='host' checked='checked' /></td>
1227 <td class='base'> $Lang ::tr{'host to net vpn'}</td>
1229 <td><input type='radio' name='TYPE' value='net' /></td>
1230 <td class='base'> $Lang ::tr{'net to net vpn'}</td>
1232 <td align='center' colspan='2'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td>
1237 & Header
:: closebox
();
1238 & Header
:: closebigbox
();
1239 & Header
:: closepage
();
1242 ### Adding/Editing/Saving a connection
1244 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
1245 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
1246 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
1248 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1249 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1250 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1252 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
1253 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
1254 $errormessage = $Lang :: tr
{ 'invalid key' };
1257 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
1258 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
1259 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
1260 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
1261 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
1262 #$cgiparams{'free'} = $confighash{$cgiparams{'KEY'}}[6];
1263 $cgiparams { 'LOCAL_ID' } = $confighash { $cgiparams { 'KEY' }}[ 7 ];
1264 $cgiparams { 'LOCAL_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 8 ];
1265 $cgiparams { 'REMOTE_ID' } = $confighash { $cgiparams { 'KEY' }}[ 9 ];
1266 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
1267 $cgiparams { 'REMOTE_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 11 ];
1268 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
1269 $cgiparams { 'INTERFACE' } = $confighash { $cgiparams { 'KEY' }}[ 26 ];
1270 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
1271 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
1272 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
1273 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
1274 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
1275 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
1276 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
1277 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
1278 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
1279 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
1280 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
1281 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
1282 $cgiparams { 'VHOST' } = $confighash { $cgiparams { 'KEY' }}[ 14 ];
1284 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
1285 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
1286 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
1287 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
1291 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
1292 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
1296 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
1297 $errormessage = $Lang :: tr
{ 'name is invalid' };
1301 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
1302 $errormessage = $Lang :: tr
{ 'name too long' };
1306 # Check if there is no other entry with this name
1307 if (! $cgiparams { 'KEY' }) { #only for add
1308 foreach my $key ( keys %confighash ) {
1309 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
1310 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
1316 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! $cgiparams { 'REMOTE' })) {
1317 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1321 if ( $cgiparams { 'REMOTE' }) {
1322 if (! & General
:: validip
( $cgiparams { 'REMOTE' })) {
1323 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
1324 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1327 if (& valid_dns_host
( $cgiparams { 'REMOTE' })) {
1328 $warnmessage = " $Lang ::tr{'check vpn lr'} $cgiparams {'REMOTE'}. $Lang ::tr{'dns check failed'}" ;
1334 unless (& General
:: validipandmask
( $cgiparams { 'LOCAL_SUBNET' })) {
1335 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
1339 # Allow only one roadwarrior/psk without remote IP-address
1340 if ( $cgiparams { 'REMOTE' } eq '' && $cgiparams { 'AUTH' } eq 'psk' ) {
1341 foreach my $key ( keys %confighash ) {
1342 if ( ( $cgiparams { 'KEY' } ne $key ) &&
1343 ( $confighash { $key }[ 4 ] eq 'psk' ) &&
1344 ( $confighash { $key }[ 10 ] eq '' ) ) {
1345 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
1350 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! & General
:: validipandmask
( $cgiparams { 'REMOTE_SUBNET' }))) {
1351 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
1355 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
1356 $errormessage = $Lang :: tr
{ 'invalid input' };
1359 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
1360 $errormessage = $Lang :: tr
{ 'invalid input' };
1364 # Allow nothing or a string (DN,FDQN,) beginning with @
1365 # with no comma but slashes between RID eg @O=FR/C=Paris/OU=myhome/CN=franck
1366 if ( ( $cgiparams { 'LOCAL_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d\
. \d\
. \d\
. \d
)$/) ||
1367 ( $cgiparams { 'REMOTE_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d\
. \d\
. \d\
. \d
)$/) ||
1368 (( $cgiparams { 'REMOTE_ID' } eq $cgiparams { 'LOCAL_ID' }) && ( $cgiparams { 'LOCAL_ID' } ne '' ))
1370 $errormessage = $Lang :: tr
{ 'invalid local-remote id' } . '<br />' .
1371 'DER_ASN1_DN: @c =FR/ou=Paris/ou=Home/cn=*<br />' .
1372 'FQDN: @ipfire .org<br />' .
1373 'USER_FQDN: info @ipfire .org<br />' .
1374 'IPV4_ADDR: @123 .123.123.123' ;
1377 # If Auth is DN, verify existance of Remote ID.
1378 if ( $cgiparams { 'REMOTE_ID' } eq '' && (
1379 $cgiparams { 'AUTH' } eq 'auth-dn' || # while creation
1380 $confighash { $cgiparams { 'KEY' }}[ 2 ] eq ' %auth -dn' )){ # while editing
1381 $errormessage = $Lang :: tr
{ 'vpn missing remote id' };
1385 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1386 if (! length ( $cgiparams { 'PSK' }) ) {
1387 $errormessage = $Lang :: tr
{ 'pre-shared key is too short' };
1390 if ( $cgiparams { 'PSK' } =~ /'/ ) {
1391 $cgiparams { 'PSK' } =~ tr/'/ / ;
1392 $errormessage = $Lang :: tr
{ 'invalid characters found in pre-shared key' };
1395 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
1396 if ( $cgiparams { 'KEY' }) {
1397 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1400 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1401 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1405 # Move uploaded certificate request to a temporary file
1406 ( my $fh , my $filename ) = tempfile
( );
1407 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1412 # Sign the certificate request
1413 & General
:: log ( "ipsec" , "Signing your cert $cgiparams {'NAME'}..." );
1414 my $opt = " ca -days 999999" ;
1415 $opt .= " -batch -notext" ;
1416 $opt .= " -in $filename " ;
1417 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1419 if ( $errormessage = & callssl
( $opt ) ) {
1421 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1422 & cleanssldatabase
();
1426 & cleanssldatabase
();
1429 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1430 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1431 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1434 } elsif ( $cgiparams { 'AUTH' } eq 'pkcs12' ) {
1435 & General
:: log ( "ipsec" , "Importing from p12..." );
1437 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1438 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1439 goto ROOTCERT_ERROR
;
1442 # Move uploaded certificate request to a temporary file
1443 ( my $fh , my $filename ) = tempfile
( );
1444 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1446 goto ROOTCERT_ERROR
;
1449 # Extract the CA certificate from the file
1450 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
1451 if ( open ( STDIN
, "-|" )) {
1452 my $opt = " pkcs12 -cacerts -nokeys" ;
1453 $opt .= " -in $filename " ;
1454 $opt .= " -out /tmp/newcacert" ;
1455 $errormessage = & callssl
( $opt );
1457 print " $cgiparams {'P12_PASS'} \n " ;
1461 # Extract the Host certificate from the file
1462 if (! $errormessage ) {
1463 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
1464 if ( open ( STDIN
, "-|" )) {
1465 my $opt = " pkcs12 -clcerts -nokeys" ;
1466 $opt .= " -in $filename " ;
1467 $opt .= " -out /tmp/newhostcert" ;
1468 $errormessage = & callssl
( $opt );
1470 print " $cgiparams {'P12_PASS'} \n " ;
1475 if (! $errormessage ) {
1476 & General
:: log ( "ipsec" , "Moving cacert..." );
1477 #If CA have new subject, add it to our list of CA
1478 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( '/tmp/newcacert' ));
1480 foreach my $x ( keys %cahash ) {
1481 $casubject = '' if ( $cahash { $x }[ 1 ] eq $casubject );
1482 unshift ( @names , $cahash { $x }[ 0 ]);
1484 if ( $casubject ) { # a new one!
1485 my $temp = `/usr/bin/openssl x509 -text -in /tmp/newcacert` ;
1486 if ( $temp !~ /CA:TRUE/i ) {
1487 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
1489 #compute a name for it
1491 while ( grep ( /Imported-$idx/ , @names ) ) { $idx ++};
1492 $cgiparams { 'CA_NAME' }= "Imported- $idx " ;
1493 $cgiparams { 'CERT_NAME' }=& Header
:: cleanhtml
( getCNfromcert
( '/tmp/newhostcert' ));
1494 move
( "/tmp/newcacert" , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1495 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1496 if (! $errormessage ) {
1497 my $key = & General
:: findhasharraykey
( \
%cahash );
1498 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
1499 $cahash { $key }[ 1 ] = $casubject ;
1500 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1501 system ( '/usr/local/bin/ipsecctrl' , 'R' );
1506 if (! $errormessage ) {
1507 & General
:: log ( "ipsec" , "Moving host cert..." );
1508 move
( "/tmp/newhostcert" , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1509 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1514 unlink ( '/tmp/newcacert' );
1515 unlink ( '/tmp/newhostcert' );
1516 if ( $errormessage ) {
1517 unlink ( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1518 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1521 & General
:: log ( "ipsec" , "p12 import completed!" );
1522 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
1523 if ( $cgiparams { 'KEY' }) {
1524 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1527 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1528 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1531 # Move uploaded certificate to a temporary file
1532 ( my $fh , my $filename ) = tempfile
( );
1533 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1538 # Verify the certificate has a valid CA and move it
1539 & General
:: log ( "ipsec" , "Validating imported cert against our known CA..." );
1540 my $validca = 1 ; #assume ok
1541 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/cacert.pem $filename ` ;
1542 if ( $test !~ /: OK/ ) {
1544 foreach my $key ( keys %cahash ) {
1545 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $key }[0]cert.pem $filename ` ;
1546 if ( $test =~ /: OK/ ) {
1553 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
1557 move
( $filename , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1559 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1565 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1566 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1567 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1568 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1571 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
1572 if ( $cgiparams { 'KEY' }) {
1573 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1576 # Validate input since the form was submitted
1577 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
1578 $errormessage = $Lang :: tr
{ 'name too long' };
1581 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1582 $errormessage = $Lang :: tr
{ 'invalid input for name' };
1585 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
1586 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1589 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
1590 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1593 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1594 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1597 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
1598 $errormessage = $Lang :: tr
{ 'organization too long' };
1601 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1602 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1605 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1606 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1609 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1610 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1613 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1614 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1617 #the exact syntax is a list comma separated of
1618 # email:any-validemail
1619 # URI: a uniform resource indicator
1620 # DNS: a DNS domain name
1621 # RID: a registered OBJECT IDENTIFIER
1623 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
1625 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
1626 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
1630 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
1631 $errormessage = $Lang :: tr
{ 'password too short' };
1634 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
1635 $errormessage = $Lang :: tr
{ 'passwords do not match' };
1639 # Replace empty strings with a .
1640 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
1641 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
1642 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
1644 # Create the Host certificate request
1645 & General
:: log ( "ipsec" , "Creating a cert..." );
1647 if ( open ( STDIN
, "-|" )) {
1648 my $opt = " req -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
1649 $opt .= " -newkey rsa:1024" ;
1650 $opt .= " -keyout ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1651 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1653 if ( $errormessage = & callssl
( $opt ) ) {
1654 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1655 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1659 print " $cgiparams {'CERT_COUNTRY'} \n " ;
1662 print " $cgiparams {'CERT_ORGANIZATION'} \n " ;
1664 print " $cgiparams {'CERT_NAME'} \n " ;
1665 print " $cgiparams {'CERT_EMAIL'} \n " ;
1671 # Sign the host certificate request
1672 & General
:: log ( "ipsec" , "Signing the cert $cgiparams {'NAME'}..." );
1674 #No easy way for specifying the contain of subjectAltName without writing a config file...
1675 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1677 basicConstraints=CA:FALSE
1678 nsComment="OpenSSL Generated Certificate"
1679 subjectKeyIdentifier=hash
1680 authorityKeyIdentifier=keyid,issuer:always
1683 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1686 my $opt = " ca -days 999999 -batch -notext" ;
1687 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1688 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1689 $opt .= " -extfile $v3extname " ;
1691 if ( $errormessage = & callssl
( $opt ) ) {
1692 unlink ( $v3extname );
1693 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1694 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1695 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1696 & cleanssldatabase
();
1699 unlink ( $v3extname );
1700 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1701 & cleanssldatabase
();
1704 # Create the pkcs12 file
1705 & General
:: log ( "ipsec" , "Packing a pkcs12 file..." );
1706 $opt = " pkcs12 -export" ;
1707 $opt .= " -inkey ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1708 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1709 $opt .= " -name \" $cgiparams {'NAME'} \" " ;
1710 $opt .= " -passout pass: $cgiparams {'CERT_PASS1'}" ;
1711 $opt .= " -certfile ${General::swroot}/ca/cacert.pem" ;
1712 $opt .= " -caname \" $vpnsettings {'ROOTCERT_ORGANIZATION'} CA \" " ;
1713 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}.p12" ;
1715 if ( $errormessage = & callssl
( $opt ) ) {
1716 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1717 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1718 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}.p12" );
1721 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1723 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
1724 ; # Nothing, just editing
1725 } elsif ( $cgiparams { 'AUTH' } eq 'auth-dn' ) {
1726 $cgiparams { 'CERT_NAME' } = ' %auth -dn' ; # a special value saying 'no cert file'
1728 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
1732 # 1)Error message here is not accurate.
1733 # 2)Test is superfluous, openswan can reference same cert multiple times
1734 # 3)Present since initial version (1.3.2.11), it isn't a bug correction
1735 # Check if there is no other entry with this certificate name
1736 #if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk') && ($cgiparams{'AUTH'} ne 'auth-dn')) {
1737 # foreach my $key (keys %confighash) {
1738 # if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) {
1739 # $errormessage = $Lang::tr{'a connection with this common name already exists'};
1740 # goto VPNCONF_ERROR;
1746 my $key = $cgiparams { 'KEY' };
1748 $key = & General
:: findhasharraykey
( \
%confighash );
1749 foreach my $i ( 0 .. 28 ) { $confighash { $key }[ $i ] = "" ;}
1751 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
1752 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
1753 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
1754 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
1756 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
1757 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1758 $confighash { $key }[ 4 ] = 'psk' ;
1759 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
1761 $confighash { $key }[ 4 ] = 'cert' ;
1763 if ( $cgiparams { 'TYPE' } eq 'net' ) {
1764 $confighash { $key }[ 11 ] = $cgiparams { 'REMOTE_SUBNET' };
1766 $confighash { $key }[ 7 ] = $cgiparams { 'LOCAL_ID' };
1767 $confighash { $key }[ 8 ] = $cgiparams { 'LOCAL_SUBNET' };
1768 $confighash { $key }[ 9 ] = $cgiparams { 'REMOTE_ID' };
1769 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
1770 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
1771 $confighash { $key }[ 26 ] = $cgiparams { 'INTERFACE' };
1772 $confighash { $key }[ 27 ] = $cgiparams { 'DPD_ACTION' };
1774 #dont forget advanced value
1775 $confighash { $key }[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
1776 $confighash { $key }[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
1777 $confighash { $key }[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
1778 $confighash { $key }[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
1779 $confighash { $key }[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
1780 $confighash { $key }[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
1781 $confighash { $key }[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
1782 $confighash { $key }[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
1783 $confighash { $key }[ 12 ] = 'off' ; # $cgiparams{'AGGRMODE'};
1784 $confighash { $key }[ 13 ] = $cgiparams { 'COMPRESSION' };
1785 $confighash { $key }[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
1786 $confighash { $key }[ 28 ] = $cgiparams { 'PFS' };
1787 $confighash { $key }[ 14 ] = $cgiparams { 'VHOST' };
1789 #free unused fields!
1790 $confighash { $key }[ 6 ] = 'off' ;
1791 $confighash { $key }[ 15 ] = 'off' ;
1793 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1796 system ( '/usr/local/bin/ipsecctrl' , 'S' , $key );
1799 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
1800 $cgiparams { 'KEY' } = $key ;
1801 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
1804 } else { # add new connection
1805 $cgiparams { 'ENABLED' } = 'on' ;
1806 if ( ! - f
"${General::swroot}/private/cakey.pem" ) {
1807 $cgiparams { 'AUTH' } = 'psk' ;
1808 } elsif ( ! - f
"${General::swroot}/ca/cacert.pem" ) {
1809 $cgiparams { 'AUTH' } = 'certfile' ;
1811 $cgiparams { 'AUTH' } = 'certgen' ;
1813 $cgiparams { 'LOCAL_SUBNET' } = " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" ;
1814 $cgiparams { 'CERT_EMAIL' } = $vpnsettings { 'ROOTCERT_EMAIL' };
1815 $cgiparams { 'CERT_OU' } = $vpnsettings { 'ROOTCERT_OU' };
1816 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
1817 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
1818 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
1819 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
1821 # choose appropriate dpd action
1822 if ( $cgiparams { 'TYPE' } eq 'host' ) {
1823 $cgiparams { 'DPD_ACTION' } = 'clear' ;
1825 $cgiparams { 'DPD_ACTION' } = 'restart' ;
1828 # Default is yes for 'pfs'
1829 $cgiparams { 'PFS' } = 'on' ;
1832 $cgiparams { 'LOCAL_ID' } = '' ;
1833 $cgiparams { 'REMOTE_ID' } = '' ;
1835 #use default advanced value
1836 $cgiparams { 'IKE_ENCRYPTION' } = 'aes128|3des' ; #[18];
1837 $cgiparams { 'IKE_INTEGRITY' } = 'sha|md5' ; #[19];
1838 $cgiparams { 'IKE_GROUPTYPE' } = '1536|1024' ; #[20];
1839 $cgiparams { 'IKE_LIFETIME' } = '1' ; #[16];
1840 $cgiparams { 'ESP_ENCRYPTION' } = 'aes128|3des' ; #[21];
1841 $cgiparams { 'ESP_INTEGRITY' } = 'sha1|md5' ; #[22];
1842 $cgiparams { 'ESP_GROUPTYPE' } = '' ; #[23];
1843 $cgiparams { 'ESP_KEYLIFE' } = '8' ; #[17];
1844 $cgiparams { 'COMPRESSION' } = 'off' ; #[13];
1845 $cgiparams { 'ONLY_PROPOSED' } = 'off' ; #[24];
1846 $cgiparams { 'PFS' } = 'on' ; #[28];
1847 $cgiparams { 'VHOST' } = 'on' ; #[14];
1851 $checked { 'ENABLED' }{ 'off' } = '' ;
1852 $checked { 'ENABLED' }{ 'on' } = '' ;
1853 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = "checked='checked'" ;
1855 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
1856 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
1857 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = "checked='checked'" ;
1859 $checked { 'AUTH' }{ 'psk' } = '' ;
1860 $checked { 'AUTH' }{ 'certreq' } = '' ;
1861 $checked { 'AUTH' }{ 'certgen' } = '' ;
1862 $checked { 'AUTH' }{ 'certfile' } = '' ;
1863 $checked { 'AUTH' }{ 'pkcs12' } = '' ;
1864 $checked { 'AUTH' }{ 'auth-dn' } = '' ;
1865 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = "checked='checked'" ;
1867 $selected { 'INTERFACE' }{ 'RED' } = '' ;
1868 $selected { 'INTERFACE' }{ 'ORANGE' } = '' ;
1869 $selected { 'INTERFACE' }{ 'GREEN' } = '' ;
1870 $selected { 'INTERFACE' }{ 'BLUE' } = '' ;
1871 $selected { 'INTERFACE' }{ $cgiparams { 'INTERFACE' }} = "selected='selected'" ;
1873 $selected { 'DPD_ACTION' }{ 'clear' } = '' ;
1874 $selected { 'DPD_ACTION' }{ 'hold' } = '' ;
1875 $selected { 'DPD_ACTION' }{ 'restart' } = '' ;
1876 $selected { 'DPD_ACTION' }{ $cgiparams { 'DPD_ACTION' }} = "selected='selected'" ;
1878 & Header
:: showhttpheaders
();
1879 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1880 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1881 if ( $errormessage ) {
1882 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1883 print "<class name='base'> $errormessage " ;
1884 print " </class>" ;
1885 & Header
:: closebox
();
1889 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'warning messages'}:" );
1890 print "<class name='base'> $warnmessage " ;
1891 print " </class>" ;
1892 & Header
:: closebox
();
1895 print "<form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>" ;
1897 <input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />
1898 <input type='hidden' name='IKE_ENCRYPTION' value=' $cgiparams {'IKE_ENCRYPTION'}' />
1899 <input type='hidden' name='IKE_INTEGRITY' value=' $cgiparams {'IKE_INTEGRITY'}' />
1900 <input type='hidden' name='IKE_GROUPTYPE' value=' $cgiparams {'IKE_GROUPTYPE'}' />
1901 <input type='hidden' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' />
1902 <input type='hidden' name='ESP_ENCRYPTION' value=' $cgiparams {'ESP_ENCRYPTION'}' />
1903 <input type='hidden' name='ESP_INTEGRITY' value=' $cgiparams {'ESP_INTEGRITY'}' />
1904 <input type='hidden' name='ESP_GROUPTYPE' value=' $cgiparams {'ESP_GROUPTYPE'}' />
1905 <input type='hidden' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' />
1906 <input type='hidden' name='COMPRESSION' value=' $cgiparams {'COMPRESSION'}' />
1907 <input type='hidden' name='ONLY_PROPOSED' value=' $cgiparams {'ONLY_PROPOSED'}' />
1908 <input type='hidden' name='PFS' value=' $cgiparams {'PFS'}' />
1909 <input type='hidden' name='VHOST' value=' $cgiparams {'VHOST'}' />
1912 if ( $cgiparams { 'KEY' }) {
1913 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
1914 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
1917 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'connection'}:" );
1918 print "<table width='100%'>" ;
1919 print "<tr><td width='25%' class='boldbase'> $Lang ::tr{'name'}:</td>" ;
1920 if ( $cgiparams { 'KEY' }) {
1921 print "<td width='25%' class='base'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /><b> $cgiparams {'NAME'}</b></td>" ;
1923 print "<td width='25%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' size='30' /></td>" ;
1925 print "<td> $Lang ::tr{'enabled'}</td><td><input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td></tr>" ;
1926 print '</tr><td><br /></td><tr>' ;
1930 if ( $cgiparams { 'TYPE' } eq 'host' ) {
1931 $disabled = "disabled='disabled'" ;
1932 $blob = "<img src='/blob.gif' alt='*' />" ;
1935 print "<tr><td> $Lang ::tr{'host ip'}:</td>" ;
1936 print "<td><select name='INTERFACE'>" ;
1937 print "<option value='RED' $selected {'INTERFACE'}{'RED'}>RED ( $vpnsettings {'VPN_IP'})</option>" ;
1938 print "<option value='GREEN' $selected {'INTERFACE'}{'GREEN'}>GREEN ( $netsettings {'GREEN_ADDRESS'})</option>" ;
1939 print "<option value='BLUE' $selected {'INTERFACE'}{'BLUE'}>BLUE ( $netsettings {'BLUE_ADDRESS'})</option>" if ( $netsettings { 'BLUE_DEV' } ne '' );
1940 print "<option value='ORANGE' $selected {'INTERFACE'}{'ORANGE'}>ORANGE ( $netsettings {'ORANGE_ADDRESS'})</option>" if ( $netsettings { 'ORANGE_DEV' } ne '' );
1941 print "</select></td>" ;
1943 <td class='boldbase'> $Lang ::tr{'remote host/ip'}: $blob </td>
1944 <td><input type='text' name='REMOTE' value=' $cgiparams {'REMOTE'}' size='30' /></td>
1946 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'}</td>
1947 <td><input type='text' name='LOCAL_SUBNET' value=' $cgiparams {'LOCAL_SUBNET'}' size='30' /></td>
1948 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'}</td>
1949 <td><input $disabled type='text' name='REMOTE_SUBNET' value=' $cgiparams {'REMOTE_SUBNET'}' size='30' /></td>
1951 <td class='boldbase'> $Lang ::tr{'vpn local id'}:<br />( $Lang ::tr{'eg'} <tt>@xy.example.com</tt>)</td>
1952 <td><input type='text' name='LOCAL_ID' value=' $cgiparams {'LOCAL_ID'}' /></td>
1953 <td class='boldbase'> $Lang ::tr{'vpn remote id'}:</td>
1954 <td><input type='text' name='REMOTE_ID' value=' $cgiparams {'REMOTE_ID'}' /></td>
1956 </tr><td><br /></td><tr>
1957 <td> $Lang ::tr{'dpd action'}:</td>
1958 <td><select name='DPD_ACTION'>
1959 <option value='clear' $selected {'DPD_ACTION'}{'clear'}>clear</option>
1960 <option value='hold' $selected {'DPD_ACTION'}{'hold'}>hold</option>
1961 <option value='restart' $selected {'DPD_ACTION'}{'restart'}>restart</option>
1962 </select> <a href='http://www.openswan.com/docs/local/README.DPD'>?</a>
1965 <!--http://www.openswan.com/docs/local/README.DPD
1966 http://bugs.xelerance.com/view.php?id=156
1967 restart = clear + reinitiate connection
1969 <td class='boldbase'> $Lang ::tr{'remark title'} <img src='/blob.gif' alt='*' /></td>
1970 <td colspan='3'><input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' size='55' maxlength='50' /></td>
1974 if (! $cgiparams { 'KEY' }) {
1975 print "<tr><td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked {'EDIT_ADVANCED'}{'on'} /> $Lang ::tr{'edit advanced settings when done'}</td></tr>" ;
1978 & Header
:: closebox
();
1980 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
1981 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
1983 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
1984 <tr><td class='base' width='50%'> $Lang ::tr{'use a pre-shared key'}</td>
1985 <td class='base' width='50%'><input type='text' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td>
1990 & Header
:: closebox
();
1991 } elsif (! $cgiparams { 'KEY' }) {
1992 my $pskdisabled = ( $vpnsettings { 'VPN_IP' } eq ' %defaultroute ' ) ?
"disabled='disabled'" : '' ;
1993 $cgiparams { 'PSK' } = $Lang :: tr
{ 'vpn incompatible use of defaultroute' } if ( $pskdisabled );
1994 my $cakeydisabled = ( ! - f
"${General::swroot}/private/cakey.pem" ) ?
"disabled='disabled'" : '' ;
1995 $cgiparams { 'CERT_NAME' } = $Lang :: tr
{ 'vpn no full pki' } if ( $cakeydisabled );
1996 my $cacrtdisabled = ( ! - f
"${General::swroot}/ca/cacert.pem" ) ?
"disabled='disabled'" : '' ;
1998 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
2000 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2001 <tr><td width='5%'><input type='radio' name='AUTH' value='psk' $checked {'AUTH'}{'psk'} $pskdisabled /></td>
2002 <td class='base' width='55%'> $Lang ::tr{'use a pre-shared key'}</td>
2003 <td class='base' width='40%'><input type='text' name='PSK' size='30' value=' $cgiparams {'PSK'}' $pskdisabled /></td></tr>
2004 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2005 <tr><td><input type='radio' name='AUTH' value='certreq' $checked {'AUTH'}{'certreq'} $cakeydisabled /></td>
2006 <td class='base'><hr /> $Lang ::tr{'upload a certificate request'}</td>
2007 <td class='base' rowspan='3' valign='middle'><input type='file' name='FH' size='30' $cacrtdisabled /></td></tr>
2008 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td>
2009 <td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
2010 <tr><td><input type='radio' name='AUTH' value='pkcs12' $cacrtdisabled /></td>
2011 <td class='base'> $Lang ::tr{'upload p12 file'} $Lang ::tr{'pkcs12 file password'}:<input type='password' name='P12_PASS'/></td></tr>
2012 <tr><td><input type='radio' name='AUTH' value='auth-dn' $checked {'AUTH'}{'auth-dn'} $cacrtdisabled /></td>
2013 <td class='base'><hr /> $Lang ::tr{'vpn auth-dn'}</td></tr>
2014 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2015 <tr><td><input type='radio' name='AUTH' value='certgen' $checked {'AUTH'}{'certgen'} $cakeydisabled /></td>
2016 <td class='base'><hr /> $Lang ::tr{'generate a certificate'}</td><td> </td></tr>
2018 <td class='base'> $Lang ::tr{'users fullname or system hostname'}:</td>
2019 <td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' size='32' $cakeydisabled /></td></tr>
2021 <td class='base'> $Lang ::tr{'users email'}: <img src='/blob.gif' alt='*' /></td>
2022 <td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' size='32' $cakeydisabled /></td></tr>
2024 <td class='base'> $Lang ::tr{'users department'}: <img src='/blob.gif' alt='*' /></td>
2025 <td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' size='32' $cakeydisabled /></td></tr>
2027 <td class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
2028 <td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' size='32' $cakeydisabled /></td></tr>
2030 <td class='base'> $Lang ::tr{'city'}: <img src='/blob.gif' alt='*' /></td>
2031 <td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' size='32' $cakeydisabled /></td></tr>
2033 <td class='base'> $Lang ::tr{'state or province'}: <img src='/blob.gif' alt='*' /></td>
2034 <td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' size='32' $cakeydisabled /></td></tr>
2036 <td class='base'> $Lang ::tr{'country'}:</td>
2037 <td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
2040 foreach my $country ( sort keys %{ Countries
:: countries
}) {
2041 print " \t\t\t <option value=' $Countries ::countries{ $country }'" ;
2042 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
2043 print " selected='selected'" ;
2045 print "> $country </option> \n " ;
2050 <tr><td> </td><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)<img src='/blob.gif' alt='*' /></td>
2051 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' $cakeydisabled /></td></tr>
2053 <td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
2054 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
2055 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'}:( $Lang ::tr{'confirmation'})</td>
2056 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
2060 & Header
:: closebox
();
2063 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
2064 if ( $cgiparams { 'KEY' }) {
2065 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced'}' />" ;
2067 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
2068 & Header
:: closebigbox
();
2069 & Header
:: closepage
();
2076 ### Advanced settings
2078 if (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced' }) ||
2079 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq 'yes' )) {
2080 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
2081 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2082 if (! $confighash { $cgiparams { 'KEY' }}) {
2083 $errormessage = $Lang :: tr
{ 'invalid key' };
2087 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
2088 # I didn't read any incompatibilities here....
2089 #if ($cgiparams{'VHOST'} eq 'on' && $cgiparams{'COMPRESSION'} eq 'on') {
2090 # $errormessage = $Lang::tr{'cannot enable both nat traversal and compression'};
2091 # goto ADVANCED_ERROR;
2093 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2095 $errormessage = $Lang :: tr
{ 'invalid input' };
2096 goto ADVANCED_ERROR
;
2098 foreach my $val ( @temp ) {
2099 if ( $val !~ /^(aes256|aes128|3des)$/ ) {
2100 $errormessage = $Lang :: tr
{ 'invalid input' };
2101 goto ADVANCED_ERROR
;
2104 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2106 $errormessage = $Lang :: tr
{ 'invalid input' };
2107 goto ADVANCED_ERROR
;
2109 foreach my $val ( @temp ) {
2110 if ( $val !~ /^(sha2_512|sha2_256|sha|md5)$/ ) {
2111 $errormessage = $Lang :: tr
{ 'invalid input' };
2112 goto ADVANCED_ERROR
;
2115 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2117 $errormessage = $Lang :: tr
{ 'invalid input' };
2118 goto ADVANCED_ERROR
;
2120 foreach my $val ( @temp ) {
2121 if ( $val !~ /^(1024|1536|2048|3072|4096|6144|8192)$/ ) {
2122 $errormessage = $Lang :: tr
{ 'invalid input' };
2123 goto ADVANCED_ERROR
;
2126 if ( $cgiparams { 'IKE_LIFETIME' } !~ /^\d+$/ ) {
2127 $errormessage = $Lang :: tr
{ 'invalid input for ike lifetime' };
2128 goto ADVANCED_ERROR
;
2130 if ( $cgiparams { 'IKE_LIFETIME' } < 1 || $cgiparams { 'IKE_LIFETIME' } > 8 ) {
2131 $errormessage = $Lang :: tr
{ 'ike lifetime should be between 1 and 8 hours' };
2132 goto ADVANCED_ERROR
;
2134 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2136 $errormessage = $Lang :: tr
{ 'invalid input' };
2137 goto ADVANCED_ERROR
;
2139 foreach my $val ( @temp ) {
2140 if ( $val !~ /^(aes256|aes128|3des)$/ ) {
2141 $errormessage = $Lang :: tr
{ 'invalid input' };
2142 goto ADVANCED_ERROR
;
2145 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2147 $errormessage = $Lang :: tr
{ 'invalid input' };
2148 goto ADVANCED_ERROR
;
2150 foreach my $val ( @temp ) {
2151 if ( $val !~ /^(sha2_512|sha2_256|sha1|md5)$/ ) {
2152 $errormessage = $Lang :: tr
{ 'invalid input' };
2153 goto ADVANCED_ERROR
;
2156 if ( $cgiparams { 'ESP_GROUPTYPE' } ne '' &&
2157 $cgiparams { 'ESP_GROUPTYPE' } !~ /^modp(1024|1536|2048|3072|4096)$/ ) {
2158 $errormessage = $Lang :: tr
{ 'invalid input' };
2159 goto ADVANCED_ERROR
;
2162 if ( $cgiparams { 'ESP_KEYLIFE' } !~ /^\d+$/ ) {
2163 $errormessage = $Lang :: tr
{ 'invalid input for esp keylife' };
2164 goto ADVANCED_ERROR
;
2166 if ( $cgiparams { 'ESP_KEYLIFE' } < 1 || $cgiparams { 'ESP_KEYLIFE' } > 24 ) {
2167 $errormessage = $Lang :: tr
{ 'esp keylife should be between 1 and 24 hours' };
2168 goto ADVANCED_ERROR
;
2172 ( $cgiparams { 'COMPRESSION' } !~ /^(|on|off)$/ ) ||
2173 ( $cgiparams { 'ONLY_PROPOSED' } !~ /^(|on|off)$/ ) ||
2174 ( $cgiparams { 'PFS' } !~ /^(|on|off)$/ ) ||
2175 ( $cgiparams { 'VHOST' } !~ /^(|on|off)$/ )
2177 $errormessage = $Lang :: tr
{ 'invalid input' };
2178 goto ADVANCED_ERROR
;
2181 $confighash { $cgiparams { 'KEY' }}[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
2182 $confighash { $cgiparams { 'KEY' }}[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
2183 $confighash { $cgiparams { 'KEY' }}[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
2184 $confighash { $cgiparams { 'KEY' }}[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
2185 $confighash { $cgiparams { 'KEY' }}[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
2186 $confighash { $cgiparams { 'KEY' }}[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
2187 $confighash { $cgiparams { 'KEY' }}[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
2188 $confighash { $cgiparams { 'KEY' }}[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
2189 $confighash { $cgiparams { 'KEY' }}[ 12 ] = 'off' ; #$cgiparams{'AGGRMODE'};
2190 $confighash { $cgiparams { 'KEY' }}[ 13 ] = $cgiparams { 'COMPRESSION' };
2191 $confighash { $cgiparams { 'KEY' }}[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
2192 $confighash { $cgiparams { 'KEY' }}[ 28 ] = $cgiparams { 'PFS' };
2193 $confighash { $cgiparams { 'KEY' }}[ 14 ] = $cgiparams { 'VHOST' };
2194 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2197 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
2202 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
2203 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
2204 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
2205 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
2206 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
2207 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
2208 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
2209 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
2210 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
2211 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
2212 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
2213 $cgiparams { 'VHOST' } = $confighash { $cgiparams { 'KEY' }}[ 14 ];
2215 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' || $confighash { $cgiparams { 'KEY' }}[ 10 ]) {
2216 $cgiparams { 'VHOST' } = 'off' ;
2221 $checked { 'IKE_ENCRYPTION' }{ 'aes256' } = '' ;
2222 $checked { 'IKE_ENCRYPTION' }{ 'aes128' } = '' ;
2223 $checked { 'IKE_ENCRYPTION' }{ '3des' } = '' ;
2224 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2225 foreach my $key ( @temp ) { $checked { 'IKE_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2226 $checked { 'IKE_INTEGRITY' }{ 'sha2_512' } = '' ;
2227 $checked { 'IKE_INTEGRITY' }{ 'sha2_256' } = '' ;
2228 $checked { 'IKE_INTEGRITY' }{ 'sha' } = '' ;
2229 $checked { 'IKE_INTEGRITY' }{ 'md5' } = '' ;
2230 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2231 foreach my $key ( @temp ) { $checked { 'IKE_INTEGRITY' }{ $key } = "selected='selected'" ; }
2232 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2233 $checked { 'IKE_GROUPTYPE' }{ '1024' } = '' ;
2234 $checked { 'IKE_GROUPTYPE' }{ '1536' } = '' ;
2235 $checked { 'IKE_GROUPTYPE' }{ '2048' } = '' ;
2236 $checked { 'IKE_GROUPTYPE' }{ '3072' } = '' ;
2237 $checked { 'IKE_GROUPTYPE' }{ '4096' } = '' ;
2238 $checked { 'IKE_GROUPTYPE' }{ '6144' } = '' ;
2239 $checked { 'IKE_GROUPTYPE' }{ '8192' } = '' ;
2240 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2241 foreach my $key ( @temp ) { $checked { 'IKE_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2243 # 768 is not supported by strongswan
2244 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2247 $checked { 'ESP_ENCRYPTION' }{ 'aes256' } = '' ;
2248 $checked { 'ESP_ENCRYPTION' }{ 'aes128' } = '' ;
2249 $checked { 'ESP_ENCRYPTION' }{ '3des' } = '' ;
2250 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2251 foreach my $key ( @temp ) { $checked { 'ESP_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2252 $checked { 'ESP_INTEGRITY' }{ 'sha2_512' } = '' ;
2253 $checked { 'ESP_INTEGRITY' }{ 'sha2_256' } = '' ;
2254 $checked { 'ESP_INTEGRITY' }{ 'sha1' } = '' ;
2255 $checked { 'ESP_INTEGRITY' }{ 'md5' } = '' ;
2256 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2257 foreach my $key ( @temp ) { $checked { 'ESP_INTEGRITY' }{ $key } = "selected='selected'" ; }
2258 $checked { 'ESP_GROUPTYPE' }{ $cgiparams { 'ESP_GROUPTYPE' }} = "selected='selected'" ;
2260 $checked { 'COMPRESSION' } = $cgiparams { 'COMPRESSION' } eq 'on' ?
"checked='checked'" : '' ;
2261 $checked { 'ONLY_PROPOSED' } = $cgiparams { 'ONLY_PROPOSED' } eq 'on' ?
"checked='checked'" : '' ;
2262 $checked { 'PFS' } = $cgiparams { 'PFS' } eq 'on' ?
"checked='checked'" : '' ;
2263 $checked { 'VHOST' } = $cgiparams { 'VHOST' } eq 'on' ?
"checked='checked'" : '' ;
2265 & Header
:: showhttpheaders
();
2266 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
2267 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2269 if ( $errormessage ) {
2270 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2271 print "<class name='base'> $errormessage " ;
2272 print " </class>" ;
2273 & Header
:: closebox
();
2277 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
2278 print "<class name='base'> $warnmessage " ;
2279 print " </class>" ;
2280 & Header
:: closebox
();
2283 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'advanced'}:" );
2285 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
2286 <input type='hidden' name='ADVANCED' value='yes' />
2287 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
2289 <table width='100%'>
2290 <tr><td class='boldbase' align='right' valign='top'> $Lang ::tr{'ike encryption'}</td><td class='boldbase' valign='top'>
2291 <select name='IKE_ENCRYPTION' multiple='multiple' size='4'>
2292 <option value='aes256' $checked {'IKE_ENCRYPTION'}{'aes256'}>AES (256 bit)</option>
2293 <option value='aes128' $checked {'IKE_ENCRYPTION'}{'aes128'}>AES (128 bit)</option>
2294 <option value='3des' $checked {'IKE_ENCRYPTION'}{'3des'}>3DES</option>
2297 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'ike integrity'}</td><td class='boldbase' valign='top'>
2298 <select name='IKE_INTEGRITY' multiple='multiple' size='4'>
2299 <option value='sha' $checked {'IKE_INTEGRITY'}{'sha'}>SHA</option>
2300 <option value='md5' $checked {'IKE_INTEGRITY'}{'md5'}>MD5</option>
2303 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'ike grouptype'}</td><td class='boldbase' valign='top'>
2304 <select name='IKE_GROUPTYPE' multiple='multiple' size='4'>
2305 <option value='8192' $checked {'IKE_GROUPTYPE'}{'8192'}>MODP-8192</option>
2306 <option value='6144' $checked {'IKE_GROUPTYPE'}{'6144'}>MODP-6144</option>
2307 <option value='4096' $checked {'IKE_GROUPTYPE'}{'4096'}>MODP-4096</option>
2308 <option value='3072' $checked {'IKE_GROUPTYPE'}{'3072'}>MODP-3072</option>
2309 <option value='2048' $checked {'IKE_GROUPTYPE'}{'2048'}>MODP-2048</option>
2310 <option value='1536' $checked {'IKE_GROUPTYPE'}{'1536'}>MODP-1536</option>
2311 <option value='1024' $checked {'IKE_GROUPTYPE'}{'1024'}>MODP-1024</option>
2314 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'ike lifetime'}</td><td class='boldbase' valign='top'>
2315 <input type='text' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' size='5' /> $Lang ::tr{'hours'}</td>
2318 <td colspan='1'><hr /></td>
2320 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'esp encryption'}</td><td class='boldbase' valign='top'>
2321 <select name='ESP_ENCRYPTION' multiple='multiple' size='4'>
2322 <option value='aes256' $checked {'ESP_ENCRYPTION'}{'aes256'}>AES (256 bit)</option>
2323 <option value='aes128' $checked {'ESP_ENCRYPTION'}{'aes128'}>AES (128 bit)</option>
2324 <option value='3des' $checked {'ESP_ENCRYPTION'}{'3des'}>3DES</option>
2326 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'esp integrity'}</td><td class='boldbase' valign='top'>
2327 <select name='ESP_INTEGRITY' multiple='multiple' size='4'>
2328 <option value='sha1' $checked {'ESP_INTEGRITY'}{'sha1'}>SHA1</option>
2329 <option value='md5' $checked {'ESP_INTEGRITY'}{'md5'}>MD5</option></select></td>
2331 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'esp grouptype'}</td><td class='boldbase' valign='top'>
2332 <select name='ESP_GROUPTYPE'>
2333 <option value=''> $Lang ::tr{'phase1 group'}</option></select></td>
2335 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'esp keylife'}</td><td class='boldbase' valign='top'>
2336 <input type='text' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' size='5' /> $Lang ::tr{'hours'}</td>
2338 <td colspan='1'><hr /></td>
2340 <td colspan='5'><input type='checkbox' name='ONLY_PROPOSED' $checked {'ONLY_PROPOSED'} />
2341 IKE+ESP: $Lang ::tr{'use only proposed settings'}</td>
2343 <td colspan='5'><input type='checkbox' name='PFS' $checked {'PFS'} />
2344 $Lang ::tr{'pfs yes no'}</td>
2345 <td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' /></td>
2347 <td colspan='5'><input type='checkbox' name='COMPRESSION' $checked {'COMPRESSION'} />
2348 $Lang ::tr{'vpn payload compression'}</td>
2349 <td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
2353 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ) {
2354 print "<tr><td><input type='hidden' name='VHOST' value='off' /></td></tr>" ;
2355 } elsif ( $confighash { $cgiparams { 'KEY' }}[ 10 ]) {
2356 print "<tr><td colspan='5'><input type='checkbox' name='VHOST' $checked {'VHOST'} disabled='disabled' />" ;
2357 print " $Lang ::tr{'vpn vhost'}</td></tr>" ;
2359 print "<tr><td colspan='5'><input type='checkbox' name='VHOST' $checked {'VHOST'} />" ;
2360 print " $Lang ::tr{'vpn vhost'}</td></tr>" ;
2363 print "</table></form>" ;
2364 & Header
:: closebox
();
2365 & Header
:: closebigbox
();
2366 & Header
:: closepage
();
2373 ### Default status page
2378 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%cgiparams );
2379 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
2380 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2381 $cgiparams { 'CA_NAME' } = '' ;
2383 my @status = `/usr/local/bin/ipsecctrl I` ;
2385 # suggest a default name for this side
2386 if ( $cgiparams { 'VPN_IP' } eq '' && - e
"${General::swroot}/red/active" ) {
2387 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
2388 my $ipaddr = < IPADDR
>;
2391 $cgiparams { 'VPN_IP' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
2392 if ( $cgiparams { 'VPN_IP' } eq '' ) {
2393 $cgiparams { 'VPN_IP' } = $ipaddr ;
2397 # no IP found, use %defaultroute
2398 $cgiparams { 'VPN_IP' } = ' %defaultroute ' if ( $cgiparams { 'VPN_IP' } eq '' );
2400 $cgiparams { 'VPN_DELAYED_START' } = 0 if (! defined ( $cgiparams { 'VPN_DELAYED_START' }));
2401 $checked { 'VPN_WATCH' } = $cgiparams { 'VPN_WATCH' } eq 'on' ?
"checked='checked'" : '' ;
2402 map ( $checked { $_ } = $cgiparams { $_ } eq 'on' ?
"checked='checked'" : '' ,
2403 ( 'ENABLED' , 'DBG_CRYPT' , 'DBG_PARSING' , 'DBG_EMITTING' , 'DBG_CONTROL' ,
2407 & Header
:: showhttpheaders
();
2408 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
2409 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2411 if ( $errormessage ) {
2412 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2413 print "<class name='base'> $errormessage \n " ;
2414 print " </class> \n " ;
2415 & Header
:: closebox
();
2418 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'global settings' });
2420 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2421 <table width='100%'>
2423 <td width='20%' class='base' nowrap='nowrap'> $Lang ::tr{'vpn red name'}:</td>
2424 <td width='20%'><input type='text' name='VPN_IP' value=' $cgiparams {'VPN_IP'}' /></td>
2425 <td width='20%' class='base'> $Lang ::tr{'enabled'}<input type='checkbox' name='ENABLED' $checked {'ENABLED'} /></td>
2431 <td class='base' nowrap='nowrap'> $Lang ::tr{'override mtu'}: <img src='/blob.gif' alt='*' /></td>
2432 <td ><input type='text' name='VPN_OVERRIDE_MTU' value=' $cgiparams {'VPN_OVERRIDE_MTU'}' /></td>
2438 <td class='base' nowrap='nowrap'> $Lang ::tr{'vpn delayed start'}: <img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' /></td>
2439 <td ><input type='text' name='VPN_DELAYED_START' value=' $cgiparams {'VPN_DELAYED_START'}' /></td>
2442 <p> $Lang ::tr{'vpn watch'}:<input type='checkbox' name='VPN_WATCH' $checked {'VPN_WATCH'} /></p>
2443 <p>PLUTO DEBUG =
2444 crypt:<input type='checkbox' name='DBG_CRYPT' $checked {'DBG_CRYPT'} />,
2445 parsing:<input type='checkbox' name='DBG_PARSING' $checked {'DBG_PARSING'} />,
2446 emitting:<input type='checkbox' name='DBG_EMITTING' $checked {'DBG_EMITTING'} />,
2447 control:<input type='checkbox' name='DBG_CONTROL' $checked {'DBG_CONTROL'} />,
2448 dns:<input type='checkbox' name='DBG_DNS' $checked {'DBG_DNS'} />
2450 <table width='100%'>
2452 <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
2453 <td width='70%' class='base' valign='top'> $Lang ::tr{'this field may be blank'}</td>
2456 <td class='base' valign='top' nowrap='nowrap'><img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' /> </td>
2457 <td class='base'> <font class='base'> $Lang ::tr{'vpn delayed start help'}</font></td>
2458 <td width='30%' align='center' class='base'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' /></td>
2464 & Header
:: closebox
();
2466 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection status and controlc' });
2468 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
2470 <td width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></td>
2471 <td width='22%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></td>
2472 <td width='23%' class='boldbase' align='center'><b> $Lang ::tr{'common name'}</b></td>
2473 <td width='30%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></td>
2474 <td width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></td>
2475 <td class='boldbase' align='center' colspan='6'><b> $Lang ::tr{'action'}</b></td>
2481 foreach my $key ( keys %confighash ) {
2482 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
2485 print "<tr bgcolor=' $color {'color20'}'> \n " ;
2487 print "<tr bgcolor=' $color {'color22'}'> \n " ;
2489 print "<td align='center' nowrap='nowrap'> $confighash { $key }[1]</td>" ;
2490 print "<td align='center' nowrap='nowrap'>" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ")</td>" ;
2491 if ( $confighash { $key }[ 2 ] eq ' %auth -dn' ) {
2492 print "<td align='left' nowrap='nowrap'> $confighash { $key }[9]</td>" ;
2493 } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
2494 print "<td align='left' nowrap='nowrap'> $confighash { $key }[2]</td>" ;
2496 print "<td align='left'> </td>" ;
2498 print "<td align='center'> $confighash { $key }[25]</td>" ;
2500 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>" ;
2501 foreach my $line ( @status ) {
2502 if ( $line =~ /\"$confighash{$key}[1]\".*IPsec SA established/ ) {
2503 $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>" ;
2506 # move to blueif really down
2507 if ( $confighash { $key }[ 0 ] eq 'off' && $active =~ /${Header::colourred}/ ) {
2508 $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>" ;
2511 <td align='center'> $active </td>
2513 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2514 <input type='image' name=' $Lang ::tr{'restart'}' src='/images/reload.gif' alt=' $Lang ::tr{'restart'}' title=' $Lang ::tr{'restart'}' />
2515 <input type='hidden' name='ACTION' value=' $Lang ::tr{'restart'}' />
2516 <input type='hidden' name='KEY' value=' $key ' />
2521 if (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
2524 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2525 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' />
2526 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
2527 <input type='hidden' name='KEY' value=' $key ' />
2532 print "<td width='2%'> </td>" ;
2534 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/certs/ $confighash { $key }[1].p12" ) {
2537 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2538 <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'}' />
2539 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
2540 <input type='hidden' name='KEY' value=' $key ' />
2544 ; } elsif (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
2547 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2548 <input type='image' name=' $Lang ::tr{'download certificate'}' src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' title=' $Lang ::tr{'download certificate'}' />
2549 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
2550 <input type='hidden' name='KEY' value=' $key ' />
2555 print "<td width='2%'> </td>" ;
2559 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2560 <input type='image' name=' $Lang ::tr{'toggle enable disable'}' src='/images/ $gif ' alt=' $Lang ::tr{'toggle enable disable'}' title=' $Lang ::tr{'toggle enable disable'}' />
2561 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
2562 <input type='hidden' name='KEY' value=' $key ' />
2567 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2568 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
2569 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' title=' $Lang ::tr{'edit'}' />
2570 <input type='hidden' name='KEY' value=' $key ' />
2573 <td align='center' >
2574 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2575 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
2576 <input type='image' name=' $Lang ::tr{'remove'}' src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' title=' $Lang ::tr{'remove'}' />
2577 <input type='hidden' name='KEY' value=' $key ' />
2587 # If the config file contains entries, print Key to action icons
2592 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
2593 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
2594 <td class='base'> $Lang ::tr{'click to disable'}</td>
2595 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
2596 <td class='base'> $Lang ::tr{'show certificate'}</td>
2597 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
2598 <td class='base'> $Lang ::tr{'edit'}</td>
2599 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
2600 <td class='base'> $Lang ::tr{'remove'}</td>
2604 <td> <img src='/images/off.gif' alt='?OFF' /></td>
2605 <td class='base'> $Lang ::tr{'click to enable'}</td>
2606 <td> <img src='/images/floppy.gif' alt='?FLOPPY' /></td>
2607 <td class='base'> $Lang ::tr{'download certificate'}</td>
2608 <td> <img src='/images/reload.gif' alt='?RELOAD'/></td>
2609 <td class='base'> $Lang ::tr{'restart'}</td>
2617 <table width='100%'>
2618 <tr><td align='center' colspan='9'>
2619 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2620 <input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />
2626 & Header
:: closebox
();
2628 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'certificate authorities'}:" );
2630 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
2632 <td width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></td>
2633 <td width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></td>
2634 <td width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></td>
2638 if (- f
"${General::swroot}/ca/cacert.pem" ) {
2639 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/cacert.pem" ));
2642 <tr bgcolor=' $color {'color22'}'>
2643 <td class='base'> $Lang ::tr{'root certificate'}</td>
2644 <td class='base'> $casubject </td>
2645 <td width='3%' align='center'>
2646 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2647 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
2648 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/info.gif' alt=' $Lang ::tr{'show root certificate'}' title=' $Lang ::tr{'show root certificate'}' />
2651 <td width='3%' align='center'>
2652 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2653 <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'}' />
2654 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
2657 <td width='4%'> </td></tr>
2661 # display rootcert generation buttons
2663 <tr bgcolor=' $color {'color22'}'>
2664 <td class='base'> $Lang ::tr{'root certificate'}:</td>
2665 <td class='base'> $Lang ::tr{'not present'}</td>
2666 <td colspan='3'> </td></tr>
2671 if (- f
"${General::swroot}/certs/hostcert.pem" ) {
2672 my $hostsubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/certs/hostcert.pem" ));
2675 <tr bgcolor=' $color {'color20'}'>
2676 <td class='base'> $Lang ::tr{'host certificate'}</td>
2677 <td class='base'> $hostsubject </td>
2678 <td width='3%' align='center'>
2679 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2680 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
2681 <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'}' />
2684 <td width='3%' align='center'>
2685 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2686 <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'}' />
2687 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download host certificate'}' />
2690 <td width='4%'> </td></tr>
2696 <tr bgcolor=' $color {'color20'}'>
2697 <td width='25%' class='base'> $Lang ::tr{'host certificate'}:</td>
2698 <td class='base'> $Lang ::tr{'not present'}</td>
2699 <td colspan='3'> </td></tr>
2705 if ( keys %cahash > 0 ) {
2706 foreach my $key ( keys %cahash ) {
2707 if ( $rowcolor ++ % 2 ) {
2708 print "<tr bgcolor=' $color {'color20'}'> \n " ;
2710 print "<tr bgcolor=' $color {'color22'}'> \n " ;
2712 print "<td class='base'> $cahash { $key }[0]</td> \n " ;
2713 print "<td class='base'> $cahash { $key }[1]</td> \n " ;
2716 <form method='post' name='cafrm${key}a' action=' $ENV {'SCRIPT_NAME'}'>
2717 <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'}' />
2718 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
2719 <input type='hidden' name='KEY' value=' $key ' />
2723 <form method='post' name='cafrm${key}b' action=' $ENV {'SCRIPT_NAME'}'>
2724 <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'}' />
2725 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
2726 <input type='hidden' name='KEY' value=' $key ' />
2730 <form method='post' name='cafrm${key}c' action=' $ENV {'SCRIPT_NAME'}'>
2731 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
2732 <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'}' />
2733 <input type='hidden' name='KEY' value=' $key ' />
2743 # If the file contains entries, print Key to action icons
2744 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
2747 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
2748 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
2749 <td class='base'> $Lang ::tr{'show certificate'}</td>
2750 <td> <img src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' /></td>
2751 <td class='base'> $Lang ::tr{'download certificate'}</td>
2756 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>" ;
2759 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
2760 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
2763 <td class='base' nowrap='nowrap'> $Lang ::tr{'ca name'}:</td>
2764 <td nowrap='nowrap'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' /> </td>
2765 <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td>
2766 <td nowrap='nowrap'><input type='submit' name='ACTION' value=' $Lang ::tr{'upload ca certificate'}' /></td>
2769 <td colspan='3'> $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}:</td>
2770 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' /></td>
2776 & Header
:: closebox
();
2777 & Header
:: closebigbox
();
2778 & Header
:: closepage
();