]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/vpnmain.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-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' ,
260 'DBG_KLIPS' , 'DBG_DNS' , 'DBG_NAT_T' ));
261 $plutodebug = 'none' if $plutodebug eq '' ; # if nothing selected, use 'none'.
262 print CONF
" \t klipsdebug= \" 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 " ;
320 print CONF
" \t right= $lconfighash { $key }[10] \n " ;
321 if ( $lconfighash { $key }[ 3 ] eq 'net' ) {
322 print CONF
" \t rightsubnet= $lconfighash { $key }[11] \n " ;
323 print CONF
" \t rightnexthop= %defaultroute \n " ;
324 } elsif ( $lconfighash { $key }[ 10 ] eq ' %any ' && $lconfighash { $key }[ 14 ] eq 'on' ) { #vhost allowed for roadwarriors?
325 print CONF
" \t rightsubnet=vhost: %no , %priv \n " ;
328 # Local Cert and Remote Cert (unless auth is DN dn-auth)
329 if ( $lconfighash { $key }[ 4 ] eq 'cert' ) {
330 print CONF
" \t leftcert=${General::swroot}/certs/hostcert.pem \n " ;
331 print CONF
" \t rightcert=${General::swroot}/certs/ $lconfighash { $key }[1]cert.pem \n " if ( $lconfighash { $key }[ 2 ] ne ' %auth -dn' );
334 # Local and Remote IDs
335 print CONF
" \t leftid= \" $lconfighash { $key }[7] \"\n " if ( $lconfighash { $key }[ 7 ]);
336 print CONF
" \t rightid= \" $lconfighash { $key }[9] \"\n " if ( $lconfighash { $key }[ 9 ]);
339 if ( $lconfighash { $key }[ 18 ] && $lconfighash { $key }[ 19 ] && $lconfighash { $key }[ 20 ]) {
341 my @encs = split ( '\|' , $lconfighash { $key }[ 18 ]);
342 my @ints = split ( '\|' , $lconfighash { $key }[ 19 ]);
343 my @groups = split ( '\|' , $lconfighash { $key }[ 20 ]);
345 foreach my $i ( @encs ) {
346 foreach my $j ( @ints ) {
347 foreach my $k ( @groups ) {
348 if ( $comma != 0 ) { print CONF
"," ; } else { $comma = 1 ; }
349 print CONF
" $i - $j -modp $k " ;
353 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
359 if ( $lconfighash { $key }[ 21 ] && $lconfighash { $key }[ 22 ]) {
361 my @encs = split ( '\|' , $lconfighash { $key }[ 21 ]);
362 my @ints = split ( '\|' , $lconfighash { $key }[ 22 ]);
364 foreach my $i ( @encs ) {
365 foreach my $j ( @ints ) {
366 if ( $comma != 0 ) { print CONF
"," ; } else { $comma = 1 ; }
370 if ( $lconfighash { $key }[ 24 ] eq 'on' ) { #only proposed algorythms?
376 if ( $lconfighash { $key }[ 23 ]) {
377 print CONF
" \t pfsgroup= $lconfighash { $key }[23] \n " ;
381 print CONF
" \t ikelifetime= $lconfighash { $key }[16]h \n " if ( $lconfighash { $key }[ 16 ]);
382 print CONF
" \t keylife= $lconfighash { $key }[17]h \n " if ( $lconfighash { $key }[ 17 ]);
385 print CONF
" \t compress=yes \n " if ( $lconfighash { $key }[ 13 ] eq 'on' );
387 # Dead Peer Detection
388 print CONF
" \t dpddelay=30 \n " ;
389 print CONF
" \t dpdtimeout=120 \n " ;
390 print CONF
" \t dpdaction= $lconfighash { $key }[27] \n " ;
393 print CONF
" \t pfs=" . ( $lconfighash { $key }[ 28 ] eq 'on' ?
"yes \n " : "no \n " );
395 # Build Authentication details: LEFTid RIGHTid : PSK psk
397 if ( $lconfighash { $key }[ 4 ] eq 'psk' ) {
398 $psk_line = ( $lconfighash { $key }[ 7 ] ?
$lconfighash { $key }[ 7 ] : $localside ) . " " ;
399 $psk_line .= $lconfighash { $key }[ 9 ] ?
$lconfighash { $key }[ 9 ] : $lconfighash { $key }[ 10 ]; #remoteid or remote address?
400 $psk_line .= " : PSK ' $lconfighash { $key }[5]' \n " ;
401 # if the line contains %any, it is less specific than two IP or ID, so move it at end of file.
402 if ( $psk_line =~ /%any/ ) {
403 $last_secrets .= $psk_line ;
405 print SECRETS
$psk_line ;
407 print CONF
" \t authby=secret \n " ;
409 print CONF
" \t authby=rsasig \n " ;
410 print CONF
" \t leftrsasigkey= %cert \n " ;
411 print CONF
" \t rightrsasigkey= %cert \n " ;
414 # Automatically start only if a net-to-net connection
415 if ( $lconfighash { $key }[ 3 ] eq 'host' ) {
416 print CONF
" \t auto=add \n " ;
418 print CONF
" \t auto=start \n " ;
422 print SECRETS
$last_secrets if ( $last_secrets );
428 ### Save main settings
430 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
431 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
432 unless (& General
:: validfqdn
( $cgiparams { 'VPN_IP' }) || & General
:: validip
( $cgiparams { 'VPN_IP' })
433 || $cgiparams { 'VPN_IP' } eq ' %defaultroute ' ) {
434 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
438 unless ( $cgiparams { 'VPN_DELAYED_START' } =~ /^[0-9]{1,3}$/ ) { #allow 0-999 seconds !
439 $errormessage = $Lang :: tr
{ 'invalid time period' };
443 unless ( $cgiparams { 'VPN_OVERRIDE_MTU' } =~ /^(|[0-9]{1,5})$/ ) { #allow 0-99999
444 $errormessage = $Lang :: tr
{ 'vpn mtu invalid' };
448 unless ( $cgiparams { 'VPN_WATCH' } =~ /^(|off|on)$/ ) {
449 $errormessage = $Lang :: tr
{ 'invalid input' };
453 map ( $vpnsettings { $_ } = $cgiparams { $_ },
454 ( 'ENABLED' , 'DBG_CRYPT' , 'DBG_PARSING' , 'DBG_EMITTING' , 'DBG_CONTROL' ,
455 'DBG_KLIPS' , 'DBG_DNS' , 'DBG_NAT_T' ));
457 $vpnsettings { 'VPN_IP' } = $cgiparams { 'VPN_IP' };
458 $vpnsettings { 'VPN_DELAYED_START' } = $cgiparams { 'VPN_DELAYED_START' };
459 $vpnsettings { 'VPN_OVERRIDE_MTU' } = $cgiparams { 'VPN_OVERRIDE_MTU' };
460 $vpnsettings { 'VPN_WATCH' } = $cgiparams { 'VPN_WATCH' };
461 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
464 system ( '/usr/local/bin/ipsecctrl' , 'S' );
466 system ( '/usr/local/bin/ipsecctrl' , 'D' );
473 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
474 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
476 foreach my $key ( keys %confighash ) {
477 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
478 delete $confighash { $key };
481 while ( my $file = glob ( "${General::swroot}/{ca,certs,crls,private}/*" )) {
485 if ( open ( FILE
, ">${General::swroot}/vpn/caconfig" )) {
489 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
491 system ( '/usr/local/bin/ipsecctrl' , 'R' );
497 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' }) {
498 & Header
:: showhttpheaders
();
499 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
500 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
501 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
503 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
507 <input type='hidden' name='AREUSURE' value='yes' />
508 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
509 $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}</td>
512 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' />
513 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
520 & Header
:: closebigbox
();
521 & Header
:: closepage
();
525 ### Upload CA Certificate
527 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
528 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
530 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
531 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
535 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
536 $errormessage = $Lang :: tr
{ 'name too long' };
540 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
541 $errormessage = $Lang :: tr
{ 'name is invalid' };
542 goto UPLOAD_CA_ERROR
;
545 # Check if there is no other entry with this name
546 foreach my $key ( keys %cahash ) {
547 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
548 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
553 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
554 $errormessage = $Lang :: tr
{ 'there was no file upload' };
557 # Move uploaded ca to a temporary file
558 ( my $fh , my $filename ) = tempfile
( );
559 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
563 my $temp = `/usr/bin/openssl x509 -text -in $filename ` ;
564 if ( $temp !~ /CA:TRUE/i ) {
565 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
569 move
( $filename , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
571 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
577 my $key = & General
:: findhasharraykey
( \
%cahash );
578 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
579 $cahash { $key }[ 1 ] = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" ));
580 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
582 system ( '/usr/local/bin/ipsecctrl' , 'R' );
588 ### Display ca certificate
590 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
591 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
593 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
594 & Header
:: showhttpheaders
();
595 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
596 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
597 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'ca certificate'}:" );
598 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
599 $output = & Header
:: cleanhtml
( $output , "y" );
600 print "<pre> $output </pre> \n " ;
602 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
603 & Header
:: closebigbox
();
604 & Header
:: closepage
();
607 $errormessage = $Lang :: tr
{ 'invalid key' };
611 ### Export ca certificate to browser
613 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
614 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
616 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
617 print "Content-Type: application/force-download \n " ;
618 print "Content-Type: application/octet-stream \r\n " ;
619 print "Content-Disposition: attachment; filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
620 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
623 $errormessage = $Lang :: tr
{ 'invalid key' };
627 ### Remove ca certificate (step 2)
629 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
630 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
631 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
633 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
634 foreach my $key ( keys %confighash ) {
635 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
636 if ( $test =~ /: OK/ ) {
638 system ( '/usr/local/bin/ipsecctrl' , 'D' , $key ) if (& vpnenabled
);
639 unlink ( "${General::swroot}/certs/ $confighash { $key }[1]cert.pem" );
640 unlink ( "${General::swroot}/certs/ $confighash { $key }[1].p12" );
641 delete $confighash { $key };
642 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
646 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
647 delete $cahash { $cgiparams { 'KEY' }};
648 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
649 system ( '/usr/local/bin/ipsecctrl' , 'R' );
652 $errormessage = $Lang :: tr
{ 'invalid key' };
655 ### Remove ca certificate (step 1)
657 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
658 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
659 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
661 my $assignedcerts = 0 ;
662 if ( - f
"${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
663 foreach my $key ( keys %confighash ) {
664 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/certs/ $confighash { $key }[1]cert.pem` ;
665 if ( $test =~ /: OK/ ) {
669 if ( $assignedcerts ) {
670 & Header
:: showhttpheaders
();
671 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
672 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
673 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
675 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
679 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
680 <input type='hidden' name='AREUSURE' value='yes' /></td>
683 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>
684 $Lang ::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}</td>
687 <input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
688 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
695 & Header
:: closebigbox
();
696 & Header
:: closepage
();
699 unlink ( "${General::swroot}/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
700 delete $cahash { $cgiparams { 'KEY' }};
701 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
702 system ( '/usr/local/bin/ipsecctrl' , 'R' );
706 $errormessage = $Lang :: tr
{ 'invalid key' };
710 ### Display root certificate
712 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
713 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
715 & Header
:: showhttpheaders
();
716 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
717 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
718 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
719 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'root certificate'}:" );
720 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/cacert.pem` ;
722 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'host certificate'}:" );
723 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/hostcert.pem` ;
725 $output = & Header
:: cleanhtml
( $output , "y" );
726 print "<pre> $output </pre> \n " ;
728 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
729 & Header
:: closebigbox
();
730 & Header
:: closepage
();
734 ### Export root certificate to browser
736 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
737 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
738 print "Content-Type: application/force-download \n " ;
739 print "Content-Disposition: attachment; filename=cacert.pem \r\n\r\n " ;
740 print `/usr/bin/openssl x509 -in ${General::swroot}/ca/cacert.pem` ;
744 ### Export host certificate to browser
746 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
747 if ( - f
"${General::swroot}/certs/hostcert.pem" ) {
748 print "Content-Type: application/force-download \n " ;
749 print "Content-Disposition: attachment; filename=hostcert.pem \r\n\r\n " ;
750 print `/usr/bin/openssl x509 -in ${General::swroot}/certs/hostcert.pem` ;
754 ### Form for generating/importing the caroot+host certificate
756 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
757 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
759 if (- f
"${General::swroot}/ca/cacert.pem" ) {
760 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
764 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
765 # fill in initial values
766 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
767 if (- e
"${General::swroot}/red/active" && open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
768 my $ipaddr = < IPADDR
>;
771 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
772 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
773 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
776 $cgiparams { 'ROOTCERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' } if (! $cgiparams { 'ROOTCERT_COUNTRY' });
777 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
778 & General
:: log ( "ipsec" , "Importing from p12..." );
780 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
781 $errormessage = $Lang :: tr
{ 'there was no file upload' };
785 # Move uploaded certificate request to a temporary file
786 ( my $fh , my $filename ) = tempfile
( );
787 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
792 # Extract the CA certificate from the file
793 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
794 if ( open ( STDIN
, "-|" )) {
795 my $opt = " pkcs12 -cacerts -nokeys" ;
796 $opt .= " -in $filename " ;
797 $opt .= " -out /tmp/newcacert" ;
798 $errormessage = & callssl
( $opt );
800 print " $cgiparams {'P12_PASS'} \n " ;
804 # Extract the Host certificate from the file
805 if (! $errormessage ) {
806 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
807 if ( open ( STDIN
, "-|" )) {
808 my $opt = " pkcs12 -clcerts -nokeys" ;
809 $opt .= " -in $filename " ;
810 $opt .= " -out /tmp/newhostcert" ;
811 $errormessage = & callssl
( $opt );
813 print " $cgiparams {'P12_PASS'} \n " ;
818 # Extract the Host key from the file
819 if (! $errormessage ) {
820 & General
:: log ( "ipsec" , "Extracting private key from p12..." );
821 if ( open ( STDIN
, "-|" )) {
822 my $opt = " pkcs12 -nocerts -nodes" ;
823 $opt .= " -in $filename " ;
824 $opt .= " -out /tmp/newhostkey" ;
825 $errormessage = & callssl
( $opt );
827 print " $cgiparams {'P12_PASS'} \n " ;
832 if (! $errormessage ) {
833 & General
:: log ( "ipsec" , "Moving cacert..." );
834 move
( "/tmp/newcacert" , "${General::swroot}/ca/cacert.pem" );
835 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
838 if (! $errormessage ) {
839 & General
:: log ( "ipsec" , "Moving host cert..." );
840 move
( "/tmp/newhostcert" , "${General::swroot}/certs/hostcert.pem" );
841 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
844 if (! $errormessage ) {
845 & General
:: log ( "ipsec" , "Moving private key..." );
846 move
( "/tmp/newhostkey" , "${General::swroot}/certs/hostkey.pem" );
847 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
852 unlink ( '/tmp/newcacert' );
853 unlink ( '/tmp/newhostcert' );
854 unlink ( '/tmp/newhostkey' );
856 unlink ( "${General::swroot}/ca/cacert.pem" );
857 unlink ( "${General::swroot}/certs/hostcert.pem" );
858 unlink ( "${General::swroot}/certs/hostkey.pem" );
862 # Create empty CRL cannot be done because we don't have
863 # the private key for this CAROOT
864 # IPFire can only import certificates
866 & General
:: log ( "ipsec" , "p12 import completed!" );
868 goto ROOTCERT_SUCCESS
;
870 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
872 # Validate input since the form was submitted
873 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
874 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
877 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
878 $errormessage = $Lang :: tr
{ 'organization too long' };
881 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
882 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
885 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
886 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
889 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
890 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
893 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
894 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
897 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
898 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
901 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
902 $errormessage = $Lang :: tr
{ 'invalid input for department' };
905 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
906 $errormessage = $Lang :: tr
{ 'invalid input for city' };
909 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
910 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
913 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
914 $errormessage = $Lang :: tr
{ 'invalid input for country' };
917 #the exact syntax is a list comma separated of
918 # email:any-validemail
919 # URI: a uniform resource indicator
920 # DNS: a DNS domain name
921 # RID: a registered OBJECT IDENTIFIER
923 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
925 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
926 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
930 # Copy the cgisettings to vpnsettings and save the configfile
931 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
932 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
933 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
934 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
935 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
936 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
937 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
938 & General
:: writehash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
940 # Replace empty strings with a .
941 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
942 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
943 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
945 # Create the CA certificate
946 if (! $errormessage ) {
947 & General
:: log ( "ipsec" , "Creating cacert..." );
948 if ( open ( STDIN
, "-|" )) {
949 my $opt = " req -x509 -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
950 $opt .= " -days 999999" ;
951 $opt .= " -newkey rsa:2048" ;
952 $opt .= " -keyout ${General::swroot}/private/cakey.pem" ;
953 $opt .= " -out ${General::swroot}/ca/cacert.pem" ;
955 $errormessage = & callssl
( $opt );
957 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
960 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
962 print " $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
963 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
968 # Create the Host certificate request
969 if (! $errormessage ) {
970 & General
:: log ( "ipsec" , "Creating host cert..." );
971 if ( open ( STDIN
, "-|" )) {
972 my $opt = " req -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
973 $opt .= " -newkey rsa:1024" ;
974 $opt .= " -keyout ${General::swroot}/certs/hostkey.pem" ;
975 $opt .= " -out ${General::swroot}/certs/hostreq.pem" ;
976 $errormessage = & callssl
( $opt );
978 print " $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
981 print " $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
983 print " $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
984 print " $cgiparams {'ROOTCERT_EMAIL'} \n " ;
991 # Sign the host certificate request
992 if (! $errormessage ) {
993 & General
:: log ( "ipsec" , "Self signing host cert..." );
995 #No easy way for specifying the contain of subjectAltName without writing a config file...
996 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
998 basicConstraints=CA:FALSE
999 nsComment="OpenSSL Generated Certificate"
1000 subjectKeyIdentifier=hash
1001 authorityKeyIdentifier=keyid,issuer:always
1004 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1007 my $opt = " ca -days 999999" ;
1008 $opt .= " -batch -notext" ;
1009 $opt .= " -in ${General::swroot}/certs/hostreq.pem" ;
1010 $opt .= " -out ${General::swroot}/certs/hostcert.pem" ;
1011 $opt .= " -extfile $v3extname " ;
1012 $errormessage = & callssl
( $opt );
1013 unlink ( "${General::swroot}/certs/hostreq.pem" ); #no more needed
1014 unlink ( $v3extname );
1017 # Create an empty CRL
1018 if (! $errormessage ) {
1019 & General
:: log ( "ipsec" , "Creating emptycrl..." );
1020 my $opt = " ca -gencrl" ;
1021 $opt .= " -out ${General::swroot}/crls/cacrl.pem" ;
1022 $errormessage = & callssl
( $opt );
1025 # Successfully build CA / CERT!
1026 if (! $errormessage ) {
1027 & cleanssldatabase
();
1028 goto ROOTCERT_SUCCESS
;
1032 unlink ( "${General::swroot}/ca/cacert.pem" );
1033 unlink ( "${General::swroot}/certs/hostkey.pem" );
1034 unlink ( "${General::swroot}/certs/hostcert.pem" );
1035 unlink ( "${General::swroot}/crls/cacrl.pem" );
1036 & cleanssldatabase
();
1040 & Header
:: showhttpheaders
();
1041 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1042 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1043 if ( $errormessage ) {
1044 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1045 print "<class name='base'> $errormessage " ;
1046 print " </class>" ;
1047 & Header
:: closebox
();
1049 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
1051 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
1052 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1053 <tr><td width='40%' class='base'> $Lang ::tr{'organization name'}:</td>
1054 <td width='60%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td></tr>
1055 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}:</td>
1056 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td></tr>
1057 <tr><td class='base'> $Lang ::tr{'your e-mail'}: <img src='/blob.gif' alt='*' /></td>
1058 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td></tr>
1059 <tr><td class='base'> $Lang ::tr{'your department'}: <img src='/blob.gif' alt='*' /></td>
1060 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td></tr>
1061 <tr><td class='base'> $Lang ::tr{'city'}: <img src='/blob.gif' alt='*' /></td>
1062 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td></tr>
1063 <tr><td class='base'> $Lang ::tr{'state or province'}: <img src='/blob.gif' alt='*' /></td>
1064 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td></tr>
1065 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1066 <td class='base'><select name='ROOTCERT_COUNTRY'>
1069 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1070 print "<option value=' $Countries ::countries{ $country }'" ;
1071 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1072 print " selected='selected'" ;
1074 print "> $country </option>" ;
1078 <tr><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*) <img src='/blob.gif' alt='*' /></td>
1079 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' /></td></tr>
1081 <td><br /><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /><br /><br /></td></tr>
1082 <tr><td class='base' colspan='2' align='left'>
1083 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1084 $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'}
1086 <tr><td colspan='2'><hr /></td></tr>
1087 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}:</td>
1088 <td nowrap='nowrap'><input type='file' name='FH' size='32' /></td></tr>
1089 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' /></td>
1090 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td></tr>
1092 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td></tr>
1093 <tr><td class='base' colspan='2' align='left'>
1094 <img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
1098 & Header
:: closebox
();
1099 & Header
:: closebigbox
();
1100 & Header
:: closepage
();
1105 system ( '/usr/local/bin/ipsecctrl' , 'S' );
1110 ### Export PKCS12 file to browser
1112 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
1113 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1114 print "Content-Type: application/force-download \n " ;
1115 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
1116 print "Content-Type: application/octet-stream \r\n\r\n " ;
1117 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12` ;
1121 ### Display certificate
1123 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
1124 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1126 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1127 & Header
:: showhttpheaders
();
1128 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1129 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1130 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'cert'}:" );
1131 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1132 $output = & Header
:: cleanhtml
( $output , "y" );
1133 print "<pre> $output </pre> \n " ;
1134 & Header
:: closebox
();
1135 print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1136 & Header
:: closebigbox
();
1137 & Header
:: closepage
();
1142 ### Export Certificate to browser
1144 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
1145 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1147 if ( - f
"${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1148 print "Content-Type: application/force-download \n " ;
1149 print "Content-Disposition: attachment; filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \n\n " ;
1150 print `/bin/cat ${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1155 ### Enable/Disable connection
1157 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1159 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1160 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1162 if ( $confighash { $cgiparams { 'KEY' }}) {
1163 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
1164 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
1165 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1167 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1169 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1170 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
1171 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1176 $errormessage = $Lang :: tr
{ 'invalid key' };
1180 ### Restart connection
1182 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
1183 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1184 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1186 if ( $confighash { $cgiparams { 'KEY' }}) {
1188 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
1192 $errormessage = $Lang :: tr
{ 'invalid key' };
1196 ### Remove connection
1198 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
1199 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1200 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1202 if ( $confighash { $cgiparams { 'KEY' }}) {
1203 system ( '/usr/local/bin/ipsecctrl' , 'D' , $cgiparams { 'KEY' }) if (& vpnenabled
);
1204 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1205 unlink ( "${General::swroot}/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1206 delete $confighash { $cgiparams { 'KEY' }};
1207 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1210 $errormessage = $Lang :: tr
{ 'invalid key' };
1214 ### Choose between adding a host-net or net-net connection
1216 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
1217 & Header
:: showhttpheaders
();
1218 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1219 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1220 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection type' });
1222 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
1223 <b> $Lang ::tr{'connection type'}:</b><br />
1225 <tr><td><input type='radio' name='TYPE' value='host' checked='checked' /></td>
1226 <td class='base'> $Lang ::tr{'host to net vpn'}</td>
1228 <td><input type='radio' name='TYPE' value='net' /></td>
1229 <td class='base'> $Lang ::tr{'net to net vpn'}</td>
1231 <td align='center' colspan='2'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td>
1236 & Header
:: closebox
();
1237 & Header
:: closebigbox
();
1238 & Header
:: closepage
();
1241 ### Adding/Editing/Saving a connection
1243 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
1244 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
1245 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
1247 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
1248 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1249 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1251 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
1252 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
1253 $errormessage = $Lang :: tr
{ 'invalid key' };
1256 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
1257 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
1258 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
1259 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
1260 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
1261 #$cgiparams{'free'} = $confighash{$cgiparams{'KEY'}}[6];
1262 $cgiparams { 'LOCAL_ID' } = $confighash { $cgiparams { 'KEY' }}[ 7 ];
1263 $cgiparams { 'LOCAL_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 8 ];
1264 $cgiparams { 'REMOTE_ID' } = $confighash { $cgiparams { 'KEY' }}[ 9 ];
1265 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
1266 $cgiparams { 'REMOTE_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 11 ];
1267 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
1268 $cgiparams { 'INTERFACE' } = $confighash { $cgiparams { 'KEY' }}[ 26 ];
1269 $cgiparams { 'DPD_ACTION' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
1270 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
1271 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
1272 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
1273 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
1274 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
1275 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
1276 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
1277 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
1278 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
1279 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
1280 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
1281 $cgiparams { 'VHOST' } = $confighash { $cgiparams { 'KEY' }}[ 14 ];
1283 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
1284 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
1285 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
1286 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
1290 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
1291 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
1295 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
1296 $errormessage = $Lang :: tr
{ 'name is invalid' };
1300 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
1301 $errormessage = $Lang :: tr
{ 'name too long' };
1305 # Check if there is no other entry with this name
1306 if (! $cgiparams { 'KEY' }) { #only for add
1307 foreach my $key ( keys %confighash ) {
1308 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
1309 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
1315 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! $cgiparams { 'REMOTE' })) {
1316 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1320 if ( $cgiparams { 'REMOTE' }) {
1321 if (! & General
:: validip
( $cgiparams { 'REMOTE' })) {
1322 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
1323 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1326 if (& valid_dns_host
( $cgiparams { 'REMOTE' })) {
1327 $warnmessage = " $Lang ::tr{'check vpn lr'} $cgiparams {'REMOTE'}. $Lang ::tr{'dns check failed'}" ;
1333 unless (& General
:: validipandmask
( $cgiparams { 'LOCAL_SUBNET' })) {
1334 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
1338 # Allow only one roadwarrior/psk without remote IP-address
1339 if ( $cgiparams { 'REMOTE' } eq '' && $cgiparams { 'AUTH' } eq 'psk' ) {
1340 foreach my $key ( keys %confighash ) {
1341 if ( ( $cgiparams { 'KEY' } ne $key ) &&
1342 ( $confighash { $key }[ 4 ] eq 'psk' ) &&
1343 ( $confighash { $key }[ 10 ] eq '' ) ) {
1344 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
1349 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! & General
:: validipandmask
( $cgiparams { 'REMOTE_SUBNET' }))) {
1350 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
1354 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
1355 $errormessage = $Lang :: tr
{ 'invalid input' };
1358 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
1359 $errormessage = $Lang :: tr
{ 'invalid input' };
1363 # Allow nothing or a string (DN,FDQN,) beginning with @
1364 # with no comma but slashes between RID eg @O=FR/C=Paris/OU=myhome/CN=franck
1365 if ( ( $cgiparams { 'LOCAL_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d\
. \d\
. \d\
. \d
)$/) ||
1366 ( $cgiparams { 'REMOTE_ID' } !~ /^(|[\w.-]*@[\w. =*\/ -]+| \d\
. \d\
. \d\
. \d
)$/) ||
1367 (( $cgiparams { 'REMOTE_ID' } eq $cgiparams { 'LOCAL_ID' }) && ( $cgiparams { 'LOCAL_ID' } ne '' ))
1369 $errormessage = $Lang :: tr
{ 'invalid local-remote id' } . '<br />' .
1370 'DER_ASN1_DN: @c =FR/ou=Paris/ou=Home/cn=*<br />' .
1371 'FQDN: @ipfire .org<br />' .
1372 'USER_FQDN: info @ipfire .org<br />' .
1373 'IPV4_ADDR: @123 .123.123.123' ;
1376 # If Auth is DN, verify existance of Remote ID.
1377 if ( $cgiparams { 'REMOTE_ID' } eq '' && (
1378 $cgiparams { 'AUTH' } eq 'auth-dn' || # while creation
1379 $confighash { $cgiparams { 'KEY' }}[ 2 ] eq ' %auth -dn' )){ # while editing
1380 $errormessage = $Lang :: tr
{ 'vpn missing remote id' };
1384 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1385 if (! length ( $cgiparams { 'PSK' }) ) {
1386 $errormessage = $Lang :: tr
{ 'pre-shared key is too short' };
1389 if ( $cgiparams { 'PSK' } =~ /'/ ) {
1390 $cgiparams { 'PSK' } =~ tr/'/ / ;
1391 $errormessage = $Lang :: tr
{ 'invalid characters found in pre-shared key' };
1394 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
1395 if ( $cgiparams { 'KEY' }) {
1396 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1399 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1400 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1404 # Move uploaded certificate request to a temporary file
1405 ( my $fh , my $filename ) = tempfile
( );
1406 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1411 # Sign the certificate request
1412 & General
:: log ( "ipsec" , "Signing your cert $cgiparams {'NAME'}..." );
1413 my $opt = " ca -days 999999" ;
1414 $opt .= " -batch -notext" ;
1415 $opt .= " -in $filename " ;
1416 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1418 if ( $errormessage = & callssl
( $opt ) ) {
1420 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1421 & cleanssldatabase
();
1425 & cleanssldatabase
();
1428 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1429 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1430 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1433 } elsif ( $cgiparams { 'AUTH' } eq 'pkcs12' ) {
1434 & General
:: log ( "ipsec" , "Importing from p12..." );
1436 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1437 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1438 goto ROOTCERT_ERROR
;
1441 # Move uploaded certificate request to a temporary file
1442 ( my $fh , my $filename ) = tempfile
( );
1443 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1445 goto ROOTCERT_ERROR
;
1448 # Extract the CA certificate from the file
1449 & General
:: log ( "ipsec" , "Extracting caroot from p12..." );
1450 if ( open ( STDIN
, "-|" )) {
1451 my $opt = " pkcs12 -cacerts -nokeys" ;
1452 $opt .= " -in $filename " ;
1453 $opt .= " -out /tmp/newcacert" ;
1454 $errormessage = & callssl
( $opt );
1456 print " $cgiparams {'P12_PASS'} \n " ;
1460 # Extract the Host certificate from the file
1461 if (! $errormessage ) {
1462 & General
:: log ( "ipsec" , "Extracting host cert from p12..." );
1463 if ( open ( STDIN
, "-|" )) {
1464 my $opt = " pkcs12 -clcerts -nokeys" ;
1465 $opt .= " -in $filename " ;
1466 $opt .= " -out /tmp/newhostcert" ;
1467 $errormessage = & callssl
( $opt );
1469 print " $cgiparams {'P12_PASS'} \n " ;
1474 if (! $errormessage ) {
1475 & General
:: log ( "ipsec" , "Moving cacert..." );
1476 #If CA have new subject, add it to our list of CA
1477 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( '/tmp/newcacert' ));
1479 foreach my $x ( keys %cahash ) {
1480 $casubject = '' if ( $cahash { $x }[ 1 ] eq $casubject );
1481 unshift ( @names , $cahash { $x }[ 0 ]);
1483 if ( $casubject ) { # a new one!
1484 my $temp = `/usr/bin/openssl x509 -text -in /tmp/newcacert` ;
1485 if ( $temp !~ /CA:TRUE/i ) {
1486 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
1488 #compute a name for it
1490 while ( grep ( /Imported-$idx/ , @names ) ) { $idx ++};
1491 $cgiparams { 'CA_NAME' }= "Imported- $idx " ;
1492 $cgiparams { 'CERT_NAME' }=& Header
:: cleanhtml
( getCNfromcert
( '/tmp/newhostcert' ));
1493 move
( "/tmp/newcacert" , "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1494 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1495 if (! $errormessage ) {
1496 my $key = & General
:: findhasharraykey
( \
%cahash );
1497 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
1498 $cahash { $key }[ 1 ] = $casubject ;
1499 & General
:: writehasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
1500 system ( '/usr/local/bin/ipsecctrl' , 'R' );
1505 if (! $errormessage ) {
1506 & General
:: log ( "ipsec" , "Moving host cert..." );
1507 move
( "/tmp/newhostcert" , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1508 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" if ($ ?
ne 0 );
1513 unlink ( '/tmp/newcacert' );
1514 unlink ( '/tmp/newhostcert' );
1515 if ( $errormessage ) {
1516 unlink ( "${General::swroot}/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1517 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1520 & General
:: log ( "ipsec" , "p12 import completed!" );
1521 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
1522 if ( $cgiparams { 'KEY' }) {
1523 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1526 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1527 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1530 # Move uploaded certificate to a temporary file
1531 ( my $fh , my $filename ) = tempfile
( );
1532 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1537 # Verify the certificate has a valid CA and move it
1538 & General
:: log ( "ipsec" , "Validating imported cert against our known CA..." );
1539 my $validca = 1 ; #assume ok
1540 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/cacert.pem $filename ` ;
1541 if ( $test !~ /: OK/ ) {
1543 foreach my $key ( keys %cahash ) {
1544 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ca/ $cahash { $key }[0]cert.pem $filename ` ;
1545 if ( $test =~ /: OK/ ) {
1552 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
1556 move
( $filename , "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1558 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1564 $cgiparams { 'CERT_NAME' } = getCNfromcert
( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1565 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1566 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1567 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1570 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
1571 if ( $cgiparams { 'KEY' }) {
1572 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1575 # Validate input since the form was submitted
1576 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
1577 $errormessage = $Lang :: tr
{ 'name too long' };
1580 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1581 $errormessage = $Lang :: tr
{ 'invalid input for name' };
1584 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
1585 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1588 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
1589 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1592 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1593 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1596 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
1597 $errormessage = $Lang :: tr
{ 'organization too long' };
1600 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
1601 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1604 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1605 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1608 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1609 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1612 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1613 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1616 #the exact syntax is a list comma separated of
1617 # email:any-validemail
1618 # URI: a uniform resource indicator
1619 # DNS: a DNS domain name
1620 # RID: a registered OBJECT IDENTIFIER
1622 # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com
1624 if ( $cgiparams { 'SUBJECTALTNAME' } ne '' && $cgiparams { 'SUBJECTALTNAME' } !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/ , \
. \
- _@
]*$/) {
1625 $errormessage = $Lang :: tr
{ 'vpn altname syntax' };
1629 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
1630 $errormessage = $Lang :: tr
{ 'password too short' };
1633 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
1634 $errormessage = $Lang :: tr
{ 'passwords do not match' };
1638 # Replace empty strings with a .
1639 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
1640 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
1641 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
1643 # Create the Host certificate request
1644 & General
:: log ( "ipsec" , "Creating a cert..." );
1646 if ( open ( STDIN
, "-|" )) {
1647 my $opt = " req -nodes -rand /proc/interrupts:/proc/net/rt_cache" ;
1648 $opt .= " -newkey rsa:1024" ;
1649 $opt .= " -keyout ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1650 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1652 if ( $errormessage = & callssl
( $opt ) ) {
1653 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1654 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1658 print " $cgiparams {'CERT_COUNTRY'} \n " ;
1661 print " $cgiparams {'CERT_ORGANIZATION'} \n " ;
1663 print " $cgiparams {'CERT_NAME'} \n " ;
1664 print " $cgiparams {'CERT_EMAIL'} \n " ;
1670 # Sign the host certificate request
1671 & General
:: log ( "ipsec" , "Signing the cert $cgiparams {'NAME'}..." );
1673 #No easy way for specifying the contain of subjectAltName without writing a config file...
1674 my ( $fh , $v3extname ) = tempfile
( '/tmp/XXXXXXXX' );
1676 basicConstraints=CA:FALSE
1677 nsComment="OpenSSL Generated Certificate"
1678 subjectKeyIdentifier=hash
1679 authorityKeyIdentifier=keyid,issuer:always
1682 print $fh "subjectAltName= $cgiparams {'SUBJECTALTNAME'}" if ( $cgiparams { 'SUBJECTALTNAME' });
1685 my $opt = " ca -days 999999 -batch -notext" ;
1686 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" ;
1687 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1688 $opt .= " -extfile $v3extname " ;
1690 if ( $errormessage = & callssl
( $opt ) ) {
1691 unlink ( $v3extname );
1692 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1693 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1694 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1695 & cleanssldatabase
();
1698 unlink ( $v3extname );
1699 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}req.pem" );
1700 & cleanssldatabase
();
1703 # Create the pkcs12 file
1704 & General
:: log ( "ipsec" , "Packing a pkcs12 file..." );
1705 $opt = " pkcs12 -export" ;
1706 $opt .= " -inkey ${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" ;
1707 $opt .= " -in ${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" ;
1708 $opt .= " -name \" $cgiparams {'NAME'} \" " ;
1709 $opt .= " -passout pass: $cgiparams {'CERT_PASS1'}" ;
1710 $opt .= " -certfile ${General::swroot}/ca/cacert.pem" ;
1711 $opt .= " -caname \" $vpnsettings {'ROOTCERT_ORGANIZATION'} CA \" " ;
1712 $opt .= " -out ${General::swroot}/certs/ $cgiparams {'NAME'}.p12" ;
1714 if ( $errormessage = & callssl
( $opt ) ) {
1715 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1716 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}cert.pem" );
1717 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}.p12" );
1720 unlink ( "${General::swroot}/certs/ $cgiparams {'NAME'}key.pem" );
1722 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
1723 ; # Nothing, just editing
1724 } elsif ( $cgiparams { 'AUTH' } eq 'auth-dn' ) {
1725 $cgiparams { 'CERT_NAME' } = ' %auth -dn' ; # a special value saying 'no cert file'
1727 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
1731 # 1)Error message here is not accurate.
1732 # 2)Test is superfluous, openswan can reference same cert multiple times
1733 # 3)Present since initial version (1.3.2.11), it isn't a bug correction
1734 # Check if there is no other entry with this certificate name
1735 #if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk') && ($cgiparams{'AUTH'} ne 'auth-dn')) {
1736 # foreach my $key (keys %confighash) {
1737 # if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) {
1738 # $errormessage = $Lang::tr{'a connection with this common name already exists'};
1739 # goto VPNCONF_ERROR;
1745 my $key = $cgiparams { 'KEY' };
1747 $key = & General
:: findhasharraykey
( \
%confighash );
1748 foreach my $i ( 0 .. 28 ) { $confighash { $key }[ $i ] = "" ;}
1750 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
1751 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
1752 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
1753 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
1755 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
1756 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1757 $confighash { $key }[ 4 ] = 'psk' ;
1758 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
1760 $confighash { $key }[ 4 ] = 'cert' ;
1762 if ( $cgiparams { 'TYPE' } eq 'net' ) {
1763 $confighash { $key }[ 11 ] = $cgiparams { 'REMOTE_SUBNET' };
1765 $confighash { $key }[ 7 ] = $cgiparams { 'LOCAL_ID' };
1766 $confighash { $key }[ 8 ] = $cgiparams { 'LOCAL_SUBNET' };
1767 $confighash { $key }[ 9 ] = $cgiparams { 'REMOTE_ID' };
1768 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
1769 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
1770 $confighash { $key }[ 26 ] = $cgiparams { 'INTERFACE' };
1771 $confighash { $key }[ 27 ] = $cgiparams { 'DPD_ACTION' };
1773 #dont forget advanced value
1774 $confighash { $key }[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
1775 $confighash { $key }[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
1776 $confighash { $key }[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
1777 $confighash { $key }[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
1778 $confighash { $key }[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
1779 $confighash { $key }[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
1780 $confighash { $key }[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
1781 $confighash { $key }[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
1782 $confighash { $key }[ 12 ] = 'off' ; # $cgiparams{'AGGRMODE'};
1783 $confighash { $key }[ 13 ] = $cgiparams { 'COMPRESSION' };
1784 $confighash { $key }[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
1785 $confighash { $key }[ 28 ] = $cgiparams { 'PFS' };
1786 $confighash { $key }[ 14 ] = $cgiparams { 'VHOST' };
1788 #free unused fields!
1789 $confighash { $key }[ 6 ] = 'off' ;
1790 $confighash { $key }[ 15 ] = 'off' ;
1792 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
1795 system ( '/usr/local/bin/ipsecctrl' , 'S' , $key );
1798 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
1799 $cgiparams { 'KEY' } = $key ;
1800 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
1803 } else { # add new connection
1804 $cgiparams { 'ENABLED' } = 'on' ;
1805 if ( ! - f
"${General::swroot}/private/cakey.pem" ) {
1806 $cgiparams { 'AUTH' } = 'psk' ;
1807 } elsif ( ! - f
"${General::swroot}/ca/cacert.pem" ) {
1808 $cgiparams { 'AUTH' } = 'certfile' ;
1810 $cgiparams { 'AUTH' } = 'certgen' ;
1812 $cgiparams { 'LOCAL_SUBNET' } = " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" ;
1813 $cgiparams { 'CERT_EMAIL' } = $vpnsettings { 'ROOTCERT_EMAIL' };
1814 $cgiparams { 'CERT_OU' } = $vpnsettings { 'ROOTCERT_OU' };
1815 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
1816 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
1817 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
1818 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
1820 # choose appropriate dpd action
1821 if ( $cgiparams { 'TYPE' } eq 'host' ) {
1822 $cgiparams { 'DPD_ACTION' } = 'clear' ;
1824 $cgiparams { 'DPD_ACTION' } = 'restart' ;
1827 # Default is yes for 'pfs'
1828 $cgiparams { 'PFS' } = 'on' ;
1831 $cgiparams { 'LOCAL_ID' } = '' ;
1832 $cgiparams { 'REMOTE_ID' } = '' ;
1834 #use default advanced value
1835 $cgiparams { 'IKE_ENCRYPTION' } = 'aes128|3des' ; #[18];
1836 $cgiparams { 'IKE_INTEGRITY' } = 'sha|md5' ; #[19];
1837 $cgiparams { 'IKE_GROUPTYPE' } = '1536|1024' ; #[20];
1838 $cgiparams { 'IKE_LIFETIME' } = '1' ; #[16];
1839 $cgiparams { 'ESP_ENCRYPTION' } = 'aes128|3des' ; #[21];
1840 $cgiparams { 'ESP_INTEGRITY' } = 'sha1|md5' ; #[22];
1841 $cgiparams { 'ESP_GROUPTYPE' } = '' ; #[23];
1842 $cgiparams { 'ESP_KEYLIFE' } = '8' ; #[17];
1843 $cgiparams { 'COMPRESSION' } = 'off' ; #[13];
1844 $cgiparams { 'ONLY_PROPOSED' } = 'off' ; #[24];
1845 $cgiparams { 'PFS' } = 'on' ; #[28];
1846 $cgiparams { 'VHOST' } = 'on' ; #[14];
1850 $checked { 'ENABLED' }{ 'off' } = '' ;
1851 $checked { 'ENABLED' }{ 'on' } = '' ;
1852 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = "checked='checked'" ;
1854 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
1855 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
1856 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = "checked='checked'" ;
1858 $checked { 'AUTH' }{ 'psk' } = '' ;
1859 $checked { 'AUTH' }{ 'certreq' } = '' ;
1860 $checked { 'AUTH' }{ 'certgen' } = '' ;
1861 $checked { 'AUTH' }{ 'certfile' } = '' ;
1862 $checked { 'AUTH' }{ 'pkcs12' } = '' ;
1863 $checked { 'AUTH' }{ 'auth-dn' } = '' ;
1864 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = "checked='checked'" ;
1866 $selected { 'INTERFACE' }{ 'RED' } = '' ;
1867 $selected { 'INTERFACE' }{ 'ORANGE' } = '' ;
1868 $selected { 'INTERFACE' }{ 'GREEN' } = '' ;
1869 $selected { 'INTERFACE' }{ 'BLUE' } = '' ;
1870 $selected { 'INTERFACE' }{ $cgiparams { 'INTERFACE' }} = "selected='selected'" ;
1872 $selected { 'DPD_ACTION' }{ 'clear' } = '' ;
1873 $selected { 'DPD_ACTION' }{ 'hold' } = '' ;
1874 $selected { 'DPD_ACTION' }{ 'restart' } = '' ;
1875 $selected { 'DPD_ACTION' }{ $cgiparams { 'DPD_ACTION' }} = "selected='selected'" ;
1877 & Header
:: showhttpheaders
();
1878 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1879 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
1880 if ( $errormessage ) {
1881 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
1882 print "<class name='base'> $errormessage " ;
1883 print " </class>" ;
1884 & Header
:: closebox
();
1888 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'warning messages'}:" );
1889 print "<class name='base'> $warnmessage " ;
1890 print " </class>" ;
1891 & Header
:: closebox
();
1894 print "<form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>" ;
1896 <input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />
1897 <input type='hidden' name='IKE_ENCRYPTION' value=' $cgiparams {'IKE_ENCRYPTION'}' />
1898 <input type='hidden' name='IKE_INTEGRITY' value=' $cgiparams {'IKE_INTEGRITY'}' />
1899 <input type='hidden' name='IKE_GROUPTYPE' value=' $cgiparams {'IKE_GROUPTYPE'}' />
1900 <input type='hidden' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' />
1901 <input type='hidden' name='ESP_ENCRYPTION' value=' $cgiparams {'ESP_ENCRYPTION'}' />
1902 <input type='hidden' name='ESP_INTEGRITY' value=' $cgiparams {'ESP_INTEGRITY'}' />
1903 <input type='hidden' name='ESP_GROUPTYPE' value=' $cgiparams {'ESP_GROUPTYPE'}' />
1904 <input type='hidden' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' />
1905 <input type='hidden' name='COMPRESSION' value=' $cgiparams {'COMPRESSION'}' />
1906 <input type='hidden' name='ONLY_PROPOSED' value=' $cgiparams {'ONLY_PROPOSED'}' />
1907 <input type='hidden' name='PFS' value=' $cgiparams {'PFS'}' />
1908 <input type='hidden' name='VHOST' value=' $cgiparams {'VHOST'}' />
1911 if ( $cgiparams { 'KEY' }) {
1912 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
1913 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
1916 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'connection'}:" );
1917 print "<table width='100%'>" ;
1918 print "<tr><td width='25%' class='boldbase'> $Lang ::tr{'name'}:</td>" ;
1919 if ( $cgiparams { 'KEY' }) {
1920 print "<td width='25%' class='base'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /><b> $cgiparams {'NAME'}</b></td>" ;
1922 print "<td width='25%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' size='30' /></td>" ;
1924 print "<td> $Lang ::tr{'enabled'}</td><td><input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td></tr>" ;
1925 print '</tr><td><br /></td><tr>' ;
1929 if ( $cgiparams { 'TYPE' } eq 'host' ) {
1930 $disabled = "disabled='disabled'" ;
1931 $blob = "<img src='/blob.gif' alt='*' />" ;
1934 print "<tr><td> $Lang ::tr{'host ip'}:</td>" ;
1935 print "<td><select name='INTERFACE'>" ;
1936 print "<option value='RED' $selected {'INTERFACE'}{'RED'}>RED ( $vpnsettings {'VPN_IP'})</option>" ;
1937 print "<option value='GREEN' $selected {'INTERFACE'}{'GREEN'}>GREEN ( $netsettings {'GREEN_ADDRESS'})</option>" ;
1938 print "<option value='BLUE' $selected {'INTERFACE'}{'BLUE'}>BLUE ( $netsettings {'BLUE_ADDRESS'})</option>" if ( $netsettings { 'BLUE_DEV' } ne '' );
1939 print "<option value='ORANGE' $selected {'INTERFACE'}{'ORANGE'}>ORANGE ( $netsettings {'ORANGE_ADDRESS'})</option>" if ( $netsettings { 'ORANGE_DEV' } ne '' );
1940 print "</select></td>" ;
1942 <td class='boldbase'> $Lang ::tr{'remote host/ip'}: $blob </td>
1943 <td><input type='text' name='REMOTE' value=' $cgiparams {'REMOTE'}' size='30' /></td>
1945 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'}</td>
1946 <td><input type='text' name='LOCAL_SUBNET' value=' $cgiparams {'LOCAL_SUBNET'}' size='30' /></td>
1947 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'}</td>
1948 <td><input $disabled type='text' name='REMOTE_SUBNET' value=' $cgiparams {'REMOTE_SUBNET'}' size='30' /></td>
1950 <td class='boldbase'> $Lang ::tr{'vpn local id'}:<br />( $Lang ::tr{'eg'} <tt>@xy.example.com</tt>)</td>
1951 <td><input type='text' name='LOCAL_ID' value=' $cgiparams {'LOCAL_ID'}' /></td>
1952 <td class='boldbase'> $Lang ::tr{'vpn remote id'}:</td>
1953 <td><input type='text' name='REMOTE_ID' value=' $cgiparams {'REMOTE_ID'}' /></td>
1955 </tr><td><br /></td><tr>
1956 <td> $Lang ::tr{'dpd action'}:</td>
1957 <td><select name='DPD_ACTION'>
1958 <option value='clear' $selected {'DPD_ACTION'}{'clear'}>clear</option>
1959 <option value='hold' $selected {'DPD_ACTION'}{'hold'}>hold</option>
1960 <option value='restart' $selected {'DPD_ACTION'}{'restart'}>restart</option>
1961 </select> <a href='http://www.openswan.com/docs/local/README.DPD'>?</a>
1964 <!--http://www.openswan.com/docs/local/README.DPD
1965 http://bugs.xelerance.com/view.php?id=156
1966 restart = clear + reinitiate connection
1968 <td class='boldbase'> $Lang ::tr{'remark title'} <img src='/blob.gif' alt='*' /></td>
1969 <td colspan='3'><input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' size='55' maxlength='50' /></td>
1973 if (! $cgiparams { 'KEY' }) {
1974 print "<tr><td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked {'EDIT_ADVANCED'}{'on'} /> $Lang ::tr{'edit advanced settings when done'}</td></tr>" ;
1977 & Header
:: closebox
();
1979 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
1980 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
1982 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
1983 <tr><td class='base' width='50%'> $Lang ::tr{'use a pre-shared key'}</td>
1984 <td class='base' width='50%'><input type='text' name='PSK' size='30' value=' $cgiparams {'PSK'}' /></td>
1989 & Header
:: closebox
();
1990 } elsif (! $cgiparams { 'KEY' }) {
1991 my $pskdisabled = ( $vpnsettings { 'VPN_IP' } eq ' %defaultroute ' ) ?
"disabled='disabled'" : '' ;
1992 $cgiparams { 'PSK' } = $Lang :: tr
{ 'vpn incompatible use of defaultroute' } if ( $pskdisabled );
1993 my $cakeydisabled = ( ! - f
"${General::swroot}/private/cakey.pem" ) ?
"disabled='disabled'" : '' ;
1994 $cgiparams { 'CERT_NAME' } = $Lang :: tr
{ 'vpn no full pki' } if ( $cakeydisabled );
1995 my $cacrtdisabled = ( ! - f
"${General::swroot}/ca/cacert.pem" ) ?
"disabled='disabled'" : '' ;
1997 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'authentication' });
1999 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2000 <tr><td width='5%'><input type='radio' name='AUTH' value='psk' $checked {'AUTH'}{'psk'} $pskdisabled /></td>
2001 <td class='base' width='55%'> $Lang ::tr{'use a pre-shared key'}</td>
2002 <td class='base' width='40%'><input type='text' name='PSK' size='30' value=' $cgiparams {'PSK'}' $pskdisabled /></td></tr>
2003 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2004 <tr><td><input type='radio' name='AUTH' value='certreq' $checked {'AUTH'}{'certreq'} $cakeydisabled /></td>
2005 <td class='base'><hr /> $Lang ::tr{'upload a certificate request'}</td>
2006 <td class='base' rowspan='3' valign='middle'><input type='file' name='FH' size='30' $cacrtdisabled /></td></tr>
2007 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td>
2008 <td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
2009 <tr><td><input type='radio' name='AUTH' value='pkcs12' $cacrtdisabled /></td>
2010 <td class='base'> $Lang ::tr{'upload p12 file'} $Lang ::tr{'pkcs12 file password'}:<input type='password' name='P12_PASS'/></td></tr>
2011 <tr><td><input type='radio' name='AUTH' value='auth-dn' $checked {'AUTH'}{'auth-dn'} $cacrtdisabled /></td>
2012 <td class='base'><hr /> $Lang ::tr{'vpn auth-dn'}</td></tr>
2013 <tr><td colspan='3' bgcolor='#000000'></td></tr>
2014 <tr><td><input type='radio' name='AUTH' value='certgen' $checked {'AUTH'}{'certgen'} $cakeydisabled /></td>
2015 <td class='base'><hr /> $Lang ::tr{'generate a certificate'}</td><td> </td></tr>
2017 <td class='base'> $Lang ::tr{'users fullname or system hostname'}:</td>
2018 <td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' size='32' $cakeydisabled /></td></tr>
2020 <td class='base'> $Lang ::tr{'users email'}: <img src='/blob.gif' alt='*' /></td>
2021 <td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' size='32' $cakeydisabled /></td></tr>
2023 <td class='base'> $Lang ::tr{'users department'}: <img src='/blob.gif' alt='*' /></td>
2024 <td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' size='32' $cakeydisabled /></td></tr>
2026 <td class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
2027 <td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' size='32' $cakeydisabled /></td></tr>
2029 <td class='base'> $Lang ::tr{'city'}: <img src='/blob.gif' alt='*' /></td>
2030 <td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' size='32' $cakeydisabled /></td></tr>
2032 <td class='base'> $Lang ::tr{'state or province'}: <img src='/blob.gif' alt='*' /></td>
2033 <td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' size='32' $cakeydisabled /></td></tr>
2035 <td class='base'> $Lang ::tr{'country'}:</td>
2036 <td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
2039 foreach my $country ( sort keys %{ Countries
:: countries
}) {
2040 print " \t\t\t <option value=' $Countries ::countries{ $country }'" ;
2041 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
2042 print " selected='selected'" ;
2044 print "> $country </option> \n " ;
2049 <tr><td> </td><td class='base'> $Lang ::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)<img src='/blob.gif' alt='*' /></td>
2050 <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value=' $cgiparams {'SUBJECTALTNAME'}' size='32' $cakeydisabled /></td></tr>
2052 <td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
2053 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
2054 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'}:( $Lang ::tr{'confirmation'})</td>
2055 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
2059 & Header
:: closebox
();
2062 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
2063 if ( $cgiparams { 'KEY' }) {
2064 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced'}' />" ;
2066 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
2067 & Header
:: closebigbox
();
2068 & Header
:: closepage
();
2075 ### Advanced settings
2077 if (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced' }) ||
2078 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq 'yes' )) {
2079 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%vpnsettings );
2080 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2081 if (! $confighash { $cgiparams { 'KEY' }}) {
2082 $errormessage = $Lang :: tr
{ 'invalid key' };
2086 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
2087 # I didn't read any incompatibilities here....
2088 #if ($cgiparams{'VHOST'} eq 'on' && $cgiparams{'COMPRESSION'} eq 'on') {
2089 # $errormessage = $Lang::tr{'cannot enable both nat traversal and compression'};
2090 # goto ADVANCED_ERROR;
2092 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2094 $errormessage = $Lang :: tr
{ 'invalid input' };
2095 goto ADVANCED_ERROR
;
2097 foreach my $val ( @temp ) {
2098 if ( $val !~ /^(aes256|aes128|3des)$/ ) {
2099 $errormessage = $Lang :: tr
{ 'invalid input' };
2100 goto ADVANCED_ERROR
;
2103 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2105 $errormessage = $Lang :: tr
{ 'invalid input' };
2106 goto ADVANCED_ERROR
;
2108 foreach my $val ( @temp ) {
2109 if ( $val !~ /^(sha2_512|sha2_256|sha|md5)$/ ) {
2110 $errormessage = $Lang :: tr
{ 'invalid input' };
2111 goto ADVANCED_ERROR
;
2114 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2116 $errormessage = $Lang :: tr
{ 'invalid input' };
2117 goto ADVANCED_ERROR
;
2119 foreach my $val ( @temp ) {
2120 if ( $val !~ /^(768|1024|1536|2048|3072|4096|6144|8192)$/ ) {
2121 $errormessage = $Lang :: tr
{ 'invalid input' };
2122 goto ADVANCED_ERROR
;
2125 if ( $cgiparams { 'IKE_LIFETIME' } !~ /^\d+$/ ) {
2126 $errormessage = $Lang :: tr
{ 'invalid input for ike lifetime' };
2127 goto ADVANCED_ERROR
;
2129 if ( $cgiparams { 'IKE_LIFETIME' } < 1 || $cgiparams { 'IKE_LIFETIME' } > 8 ) {
2130 $errormessage = $Lang :: tr
{ 'ike lifetime should be between 1 and 8 hours' };
2131 goto ADVANCED_ERROR
;
2133 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2135 $errormessage = $Lang :: tr
{ 'invalid input' };
2136 goto ADVANCED_ERROR
;
2138 foreach my $val ( @temp ) {
2139 if ( $val !~ /^(aes256|aes128|3des)$/ ) {
2140 $errormessage = $Lang :: tr
{ 'invalid input' };
2141 goto ADVANCED_ERROR
;
2144 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2146 $errormessage = $Lang :: tr
{ 'invalid input' };
2147 goto ADVANCED_ERROR
;
2149 foreach my $val ( @temp ) {
2150 if ( $val !~ /^(sha2_512|sha2_256|sha1|md5)$/ ) {
2151 $errormessage = $Lang :: tr
{ 'invalid input' };
2152 goto ADVANCED_ERROR
;
2155 if ( $cgiparams { 'ESP_GROUPTYPE' } ne '' &&
2156 $cgiparams { 'ESP_GROUPTYPE' } !~ /^modp(768|1024|1536|2048|3072|4096)$/ ) {
2157 $errormessage = $Lang :: tr
{ 'invalid input' };
2158 goto ADVANCED_ERROR
;
2161 if ( $cgiparams { 'ESP_KEYLIFE' } !~ /^\d+$/ ) {
2162 $errormessage = $Lang :: tr
{ 'invalid input for esp keylife' };
2163 goto ADVANCED_ERROR
;
2165 if ( $cgiparams { 'ESP_KEYLIFE' } < 1 || $cgiparams { 'ESP_KEYLIFE' } > 24 ) {
2166 $errormessage = $Lang :: tr
{ 'esp keylife should be between 1 and 24 hours' };
2167 goto ADVANCED_ERROR
;
2171 ( $cgiparams { 'COMPRESSION' } !~ /^(|on|off)$/ ) ||
2172 ( $cgiparams { 'ONLY_PROPOSED' } !~ /^(|on|off)$/ ) ||
2173 ( $cgiparams { 'PFS' } !~ /^(|on|off)$/ ) ||
2174 ( $cgiparams { 'VHOST' } !~ /^(|on|off)$/ )
2176 $errormessage = $Lang :: tr
{ 'invalid input' };
2177 goto ADVANCED_ERROR
;
2180 $confighash { $cgiparams { 'KEY' }}[ 18 ] = $cgiparams { 'IKE_ENCRYPTION' };
2181 $confighash { $cgiparams { 'KEY' }}[ 19 ] = $cgiparams { 'IKE_INTEGRITY' };
2182 $confighash { $cgiparams { 'KEY' }}[ 20 ] = $cgiparams { 'IKE_GROUPTYPE' };
2183 $confighash { $cgiparams { 'KEY' }}[ 16 ] = $cgiparams { 'IKE_LIFETIME' };
2184 $confighash { $cgiparams { 'KEY' }}[ 21 ] = $cgiparams { 'ESP_ENCRYPTION' };
2185 $confighash { $cgiparams { 'KEY' }}[ 22 ] = $cgiparams { 'ESP_INTEGRITY' };
2186 $confighash { $cgiparams { 'KEY' }}[ 23 ] = $cgiparams { 'ESP_GROUPTYPE' };
2187 $confighash { $cgiparams { 'KEY' }}[ 17 ] = $cgiparams { 'ESP_KEYLIFE' };
2188 $confighash { $cgiparams { 'KEY' }}[ 12 ] = 'off' ; #$cgiparams{'AGGRMODE'};
2189 $confighash { $cgiparams { 'KEY' }}[ 13 ] = $cgiparams { 'COMPRESSION' };
2190 $confighash { $cgiparams { 'KEY' }}[ 24 ] = $cgiparams { 'ONLY_PROPOSED' };
2191 $confighash { $cgiparams { 'KEY' }}[ 28 ] = $cgiparams { 'PFS' };
2192 $confighash { $cgiparams { 'KEY' }}[ 14 ] = $cgiparams { 'VHOST' };
2193 & General
:: writehasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2196 system ( '/usr/local/bin/ipsecctrl' , 'S' , $cgiparams { 'KEY' });
2201 $cgiparams { 'IKE_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 18 ];
2202 $cgiparams { 'IKE_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 19 ];
2203 $cgiparams { 'IKE_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 20 ];
2204 $cgiparams { 'IKE_LIFETIME' } = $confighash { $cgiparams { 'KEY' }}[ 16 ];
2205 $cgiparams { 'ESP_ENCRYPTION' } = $confighash { $cgiparams { 'KEY' }}[ 21 ];
2206 $cgiparams { 'ESP_INTEGRITY' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
2207 $cgiparams { 'ESP_GROUPTYPE' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
2208 $cgiparams { 'ESP_KEYLIFE' } = $confighash { $cgiparams { 'KEY' }}[ 17 ];
2209 $cgiparams { 'COMPRESSION' } = $confighash { $cgiparams { 'KEY' }}[ 13 ];
2210 $cgiparams { 'ONLY_PROPOSED' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
2211 $cgiparams { 'PFS' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
2212 $cgiparams { 'VHOST' } = $confighash { $cgiparams { 'KEY' }}[ 14 ];
2214 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' || $confighash { $cgiparams { 'KEY' }}[ 10 ]) {
2215 $cgiparams { 'VHOST' } = 'off' ;
2220 $checked { 'IKE_ENCRYPTION' }{ 'aes256' } = '' ;
2221 $checked { 'IKE_ENCRYPTION' }{ 'aes128' } = '' ;
2222 $checked { 'IKE_ENCRYPTION' }{ '3des' } = '' ;
2223 my @temp = split ( '\|' , $cgiparams { 'IKE_ENCRYPTION' });
2224 foreach my $key ( @temp ) { $checked { 'IKE_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2225 $checked { 'IKE_INTEGRITY' }{ 'sha2_512' } = '' ;
2226 $checked { 'IKE_INTEGRITY' }{ 'sha2_256' } = '' ;
2227 $checked { 'IKE_INTEGRITY' }{ 'sha' } = '' ;
2228 $checked { 'IKE_INTEGRITY' }{ 'md5' } = '' ;
2229 @temp = split ( '\|' , $cgiparams { 'IKE_INTEGRITY' });
2230 foreach my $key ( @temp ) { $checked { 'IKE_INTEGRITY' }{ $key } = "selected='selected'" ; }
2231 $checked { 'IKE_GROUPTYPE' }{ '768' } = '' ;
2232 $checked { 'IKE_GROUPTYPE' }{ '1024' } = '' ;
2233 $checked { 'IKE_GROUPTYPE' }{ '1536' } = '' ;
2234 $checked { 'IKE_GROUPTYPE' }{ '2048' } = '' ;
2235 $checked { 'IKE_GROUPTYPE' }{ '3072' } = '' ;
2236 $checked { 'IKE_GROUPTYPE' }{ '4096' } = '' ;
2237 $checked { 'IKE_GROUPTYPE' }{ '6144' } = '' ;
2238 $checked { 'IKE_GROUPTYPE' }{ '8192' } = '' ;
2239 @temp = split ( '\|' , $cgiparams { 'IKE_GROUPTYPE' });
2240 foreach my $key ( @temp ) { $checked { 'IKE_GROUPTYPE' }{ $key } = "selected='selected'" ; }
2241 $checked { 'ESP_ENCRYPTION' }{ 'aes256' } = '' ;
2242 $checked { 'ESP_ENCRYPTION' }{ 'aes128' } = '' ;
2243 $checked { 'ESP_ENCRYPTION' }{ '3des' } = '' ;
2244 @temp = split ( '\|' , $cgiparams { 'ESP_ENCRYPTION' });
2245 foreach my $key ( @temp ) { $checked { 'ESP_ENCRYPTION' }{ $key } = "selected='selected'" ; }
2246 $checked { 'ESP_INTEGRITY' }{ 'sha2_512' } = '' ;
2247 $checked { 'ESP_INTEGRITY' }{ 'sha2_256' } = '' ;
2248 $checked { 'ESP_INTEGRITY' }{ 'sha1' } = '' ;
2249 $checked { 'ESP_INTEGRITY' }{ 'md5' } = '' ;
2250 @temp = split ( '\|' , $cgiparams { 'ESP_INTEGRITY' });
2251 foreach my $key ( @temp ) { $checked { 'ESP_INTEGRITY' }{ $key } = "selected='selected'" ; }
2252 $checked { 'ESP_GROUPTYPE' }{ $cgiparams { 'ESP_GROUPTYPE' }} = "selected='selected'" ;
2254 $checked { 'COMPRESSION' } = $cgiparams { 'COMPRESSION' } eq 'on' ?
"checked='checked'" : '' ;
2255 $checked { 'ONLY_PROPOSED' } = $cgiparams { 'ONLY_PROPOSED' } eq 'on' ?
"checked='checked'" : '' ;
2256 $checked { 'PFS' } = $cgiparams { 'PFS' } eq 'on' ?
"checked='checked'" : '' ;
2257 $checked { 'VHOST' } = $cgiparams { 'VHOST' } eq 'on' ?
"checked='checked'" : '' ;
2259 & Header
:: showhttpheaders
();
2260 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
2261 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2263 if ( $errormessage ) {
2264 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2265 print "<class name='base'> $errormessage " ;
2266 print " </class>" ;
2267 & Header
:: closebox
();
2271 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'warning messages' });
2272 print "<class name='base'> $warnmessage " ;
2273 print " </class>" ;
2274 & Header
:: closebox
();
2277 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'advanced'}:" );
2279 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
2280 <input type='hidden' name='ADVANCED' value='yes' />
2281 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
2283 <table width='100%'>
2284 <tr><td class='boldbase' align='right' valign='top'> $Lang ::tr{'ike encryption'}</td><td class='boldbase' valign='top'>
2285 <select name='IKE_ENCRYPTION' multiple='multiple' size='4'>
2286 <option value='aes256' $checked {'IKE_ENCRYPTION'}{'aes256'}>AES (256 bit)</option>
2287 <option value='aes128' $checked {'IKE_ENCRYPTION'}{'aes128'}>AES (128 bit)</option>
2288 <option value='3des' $checked {'IKE_ENCRYPTION'}{'3des'}>3DES</option>
2291 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'ike integrity'}</td><td class='boldbase' valign='top'>
2292 <select name='IKE_INTEGRITY' multiple='multiple' size='4'>
2293 <option value='sha' $checked {'IKE_INTEGRITY'}{'sha'}>SHA</option>
2294 <option value='md5' $checked {'IKE_INTEGRITY'}{'md5'}>MD5</option>
2297 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'ike grouptype'}</td><td class='boldbase' valign='top'>
2298 <select name='IKE_GROUPTYPE' multiple='multiple' size='4'>
2299 <option value='8192' $checked {'IKE_GROUPTYPE'}{'8192'}>MODP-8192</option>
2300 <option value='6144' $checked {'IKE_GROUPTYPE'}{'6144'}>MODP-6144</option>
2301 <option value='4096' $checked {'IKE_GROUPTYPE'}{'4096'}>MODP-4096</option>
2302 <option value='3072' $checked {'IKE_GROUPTYPE'}{'3072'}>MODP-3072</option>
2303 <option value='2048' $checked {'IKE_GROUPTYPE'}{'2048'}>MODP-2048</option>
2304 <option value='1536' $checked {'IKE_GROUPTYPE'}{'1536'}>MODP-1536</option>
2305 <option value='1024' $checked {'IKE_GROUPTYPE'}{'1024'}>MODP-1024</option>
2306 <option value='768' $checked {'IKE_GROUPTYPE'}{'768'}>MODP-768</option>
2309 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'ike lifetime'}</td><td class='boldbase' valign='top'>
2310 <input type='text' name='IKE_LIFETIME' value=' $cgiparams {'IKE_LIFETIME'}' size='5' /> $Lang ::tr{'hours'}</td>
2313 <td colspan='1'><hr /></td>
2315 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'esp encryption'}</td><td class='boldbase' valign='top'>
2316 <select name='ESP_ENCRYPTION' multiple='multiple' size='4'>
2317 <option value='aes256' $checked {'ESP_ENCRYPTION'}{'aes256'}>AES (256 bit)</option>
2318 <option value='aes128' $checked {'ESP_ENCRYPTION'}{'aes128'}>AES (128 bit)</option>
2319 <option value='3des' $checked {'ESP_ENCRYPTION'}{'3des'}>3DES</option>
2321 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'esp integrity'}</td><td class='boldbase' valign='top'>
2322 <select name='ESP_INTEGRITY' multiple='multiple' size='4'>
2323 <option value='sha1' $checked {'ESP_INTEGRITY'}{'sha1'}>SHA1</option>
2324 <option value='md5' $checked {'ESP_INTEGRITY'}{'md5'}>MD5</option></select></td>
2326 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'esp grouptype'}</td><td class='boldbase' valign='top'>
2327 <select name='ESP_GROUPTYPE'>
2328 <option value=''> $Lang ::tr{'phase1 group'}</option></select></td>
2330 <td class='boldbase' align='right' valign='top'> $Lang ::tr{'esp keylife'}</td><td class='boldbase' valign='top'>
2331 <input type='text' name='ESP_KEYLIFE' value=' $cgiparams {'ESP_KEYLIFE'}' size='5' /> $Lang ::tr{'hours'}</td>
2333 <td colspan='1'><hr /></td>
2335 <td colspan='5'><input type='checkbox' name='ONLY_PROPOSED' $checked {'ONLY_PROPOSED'} />
2336 IKE+ESP: $Lang ::tr{'use only proposed settings'}</td>
2338 <td colspan='5'><input type='checkbox' name='PFS' $checked {'PFS'} />
2339 $Lang ::tr{'pfs yes no'}</td>
2340 <td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' /></td>
2342 <td colspan='5'><input type='checkbox' name='COMPRESSION' $checked {'COMPRESSION'} />
2343 $Lang ::tr{'vpn payload compression'}</td>
2344 <td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
2348 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ) {
2349 print "<tr><td><input type='hidden' name='VHOST' value='off' /></td></tr>" ;
2350 } elsif ( $confighash { $cgiparams { 'KEY' }}[ 10 ]) {
2351 print "<tr><td colspan='5'><input type='checkbox' name='VHOST' $checked {'VHOST'} disabled='disabled' />" ;
2352 print " $Lang ::tr{'vpn vhost'}</td></tr>" ;
2354 print "<tr><td colspan='5'><input type='checkbox' name='VHOST' $checked {'VHOST'} />" ;
2355 print " $Lang ::tr{'vpn vhost'}</td></tr>" ;
2358 print "</table></form>" ;
2359 & Header
:: closebox
();
2360 & Header
:: closebigbox
();
2361 & Header
:: closepage
();
2368 ### Default status page
2373 & General
:: readhash
( "${General::swroot}/vpn/settings" , \
%cgiparams );
2374 & General
:: readhasharray
( "${General::swroot}/vpn/caconfig" , \
%cahash );
2375 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
2376 $cgiparams { 'CA_NAME' } = '' ;
2378 my @status = `/usr/local/bin/ipsecctrl I` ;
2380 # suggest a default name for this side
2381 if ( $cgiparams { 'VPN_IP' } eq '' && - e
"${General::swroot}/red/active" ) {
2382 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
2383 my $ipaddr = < IPADDR
>;
2386 $cgiparams { 'VPN_IP' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
2387 if ( $cgiparams { 'VPN_IP' } eq '' ) {
2388 $cgiparams { 'VPN_IP' } = $ipaddr ;
2392 # no IP found, use %defaultroute
2393 $cgiparams { 'VPN_IP' } = ' %defaultroute ' if ( $cgiparams { 'VPN_IP' } eq '' );
2395 $cgiparams { 'VPN_DELAYED_START' } = 0 if (! defined ( $cgiparams { 'VPN_DELAYED_START' }));
2396 $checked { 'VPN_WATCH' } = $cgiparams { 'VPN_WATCH' } eq 'on' ?
"checked='checked'" : '' ;
2397 map ( $checked { $_ } = $cgiparams { $_ } eq 'on' ?
"checked='checked'" : '' ,
2398 ( 'ENABLED' , 'DBG_CRYPT' , 'DBG_PARSING' , 'DBG_EMITTING' , 'DBG_CONTROL' ,
2399 'DBG_KLIPS' , 'DBG_DNS' , 'DBG_NAT_T' ));
2402 & Header
:: showhttpheaders
();
2403 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
2404 & Header
:: openbigbox
( '100%' , 'left' , '' , $errormessage );
2406 if ( $errormessage ) {
2407 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
2408 print "<class name='base'> $errormessage \n " ;
2409 print " </class> \n " ;
2410 & Header
:: closebox
();
2413 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'global settings' });
2415 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2416 <table width='100%'>
2418 <td width='20%' class='base' nowrap='nowrap'> $Lang ::tr{'vpn red name'}:</td>
2419 <td width='20%'><input type='text' name='VPN_IP' value=' $cgiparams {'VPN_IP'}' /></td>
2420 <td width='20%' class='base'> $Lang ::tr{'enabled'}<input type='checkbox' name='ENABLED' $checked {'ENABLED'} /></td>
2426 <td class='base' nowrap='nowrap'> $Lang ::tr{'override mtu'}: <img src='/blob.gif' alt='*' /></td>
2427 <td ><input type='text' name='VPN_OVERRIDE_MTU' value=' $cgiparams {'VPN_OVERRIDE_MTU'}' /></td>
2433 <td class='base' nowrap='nowrap'> $Lang ::tr{'vpn delayed start'}: <img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' /></td>
2434 <td ><input type='text' name='VPN_DELAYED_START' value=' $cgiparams {'VPN_DELAYED_START'}' /></td>
2437 <p> $Lang ::tr{'vpn watch'}:<input type='checkbox' name='VPN_WATCH' $checked {'VPN_WATCH'} /></p>
2438 <p>PLUTO DEBUG =
2439 crypt:<input type='checkbox' name='DBG_CRYPT' $checked {'DBG_CRYPT'} />,
2440 parsing:<input type='checkbox' name='DBG_PARSING' $checked {'DBG_PARSING'} />,
2441 emitting:<input type='checkbox' name='DBG_EMITTING' $checked {'DBG_EMITTING'} />,
2442 control:<input type='checkbox' name='DBG_CONTROL' $checked {'DBG_CONTROL'} />,
2443 klips:<input type='checkbox' name='DBG_KLIPS' $checked {'DBG_KLIPS'} />,
2444 dns:<input type='checkbox' name='DBG_DNS' $checked {'DBG_DNS'} />,
2445 nat_t:<input type='checkbox' name='DBG_NAT_T' $checked {'DBG_NAT_T'} /></p>
2448 <table width='100%'>
2450 <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
2451 <td width='70%' class='base' valign='top'> $Lang ::tr{'this field may be blank'}</td>
2454 <td class='base' valign='top' nowrap='nowrap'><img src='/blob.gif' alt='*' /><img src='/blob.gif' alt='*' /> </td>
2455 <td class='base'> <font class='base'> $Lang ::tr{'vpn delayed start help'}</font></td>
2456 <td width='30%' align='center' class='base'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' /></td>
2462 & Header
:: closebox
();
2464 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'connection status and controlc' });
2466 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
2468 <td width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></td>
2469 <td width='22%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></td>
2470 <td width='23%' class='boldbase' align='center'><b> $Lang ::tr{'common name'}</b></td>
2471 <td width='30%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></td>
2472 <td width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></td>
2473 <td class='boldbase' align='center' colspan='6'><b> $Lang ::tr{'action'}</b></td>
2479 foreach my $key ( keys %confighash ) {
2480 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
2483 print "<tr bgcolor=' $color {'color20'}'> \n " ;
2485 print "<tr bgcolor=' $color {'color22'}'> \n " ;
2487 print "<td align='center' nowrap='nowrap'> $confighash { $key }[1]</td>" ;
2488 print "<td align='center' nowrap='nowrap'>" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ")</td>" ;
2489 if ( $confighash { $key }[ 2 ] eq ' %auth -dn' ) {
2490 print "<td align='left' nowrap='nowrap'> $confighash { $key }[9]</td>" ;
2491 } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
2492 print "<td align='left' nowrap='nowrap'> $confighash { $key }[2]</td>" ;
2494 print "<td align='left'> </td>" ;
2496 print "<td align='center'> $confighash { $key }[25]</td>" ;
2498 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>" ;
2499 foreach my $line ( @status ) {
2500 if ( $line =~ /\"$confighash{$key}[1]\".*IPsec SA established/ ) {
2501 $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>" ;
2504 # move to blueif really down
2505 if ( $confighash { $key }[ 0 ] eq 'off' && $active =~ /${Header::colourred}/ ) {
2506 $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>" ;
2509 <td align='center'> $active </td>
2511 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2512 <input type='image' name=' $Lang ::tr{'restart'}' src='/images/reload.gif' alt=' $Lang ::tr{'restart'}' title=' $Lang ::tr{'restart'}' />
2513 <input type='hidden' name='ACTION' value=' $Lang ::tr{'restart'}' />
2514 <input type='hidden' name='KEY' value=' $key ' />
2519 if (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
2522 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2523 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' />
2524 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
2525 <input type='hidden' name='KEY' value=' $key ' />
2530 print "<td width='2%'> </td>" ;
2532 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/certs/ $confighash { $key }[1].p12" ) {
2535 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2536 <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'}' />
2537 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
2538 <input type='hidden' name='KEY' value=' $key ' />
2542 ; } elsif (( $confighash { $key }[ 4 ] eq 'cert' ) && ( $confighash { $key }[ 2 ] ne ' %auth -dn' )) {
2545 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2546 <input type='image' name=' $Lang ::tr{'download certificate'}' src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' title=' $Lang ::tr{'download certificate'}' />
2547 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
2548 <input type='hidden' name='KEY' value=' $key ' />
2553 print "<td width='2%'> </td>" ;
2557 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2558 <input type='image' name=' $Lang ::tr{'toggle enable disable'}' src='/images/ $gif ' alt=' $Lang ::tr{'toggle enable disable'}' title=' $Lang ::tr{'toggle enable disable'}' />
2559 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
2560 <input type='hidden' name='KEY' value=' $key ' />
2565 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2566 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
2567 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' title=' $Lang ::tr{'edit'}' />
2568 <input type='hidden' name='KEY' value=' $key ' />
2571 <td align='center' >
2572 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2573 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
2574 <input type='image' name=' $Lang ::tr{'remove'}' src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' title=' $Lang ::tr{'remove'}' />
2575 <input type='hidden' name='KEY' value=' $key ' />
2585 # If the config file contains entries, print Key to action icons
2590 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
2591 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
2592 <td class='base'> $Lang ::tr{'click to disable'}</td>
2593 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
2594 <td class='base'> $Lang ::tr{'show certificate'}</td>
2595 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
2596 <td class='base'> $Lang ::tr{'edit'}</td>
2597 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
2598 <td class='base'> $Lang ::tr{'remove'}</td>
2602 <td> <img src='/images/off.gif' alt='?OFF' /></td>
2603 <td class='base'> $Lang ::tr{'click to enable'}</td>
2604 <td> <img src='/images/floppy.gif' alt='?FLOPPY' /></td>
2605 <td class='base'> $Lang ::tr{'download certificate'}</td>
2606 <td> <img src='/images/reload.gif' alt='?RELOAD'/></td>
2607 <td class='base'> $Lang ::tr{'restart'}</td>
2615 <table width='100%'>
2616 <tr><td align='center' colspan='9'>
2617 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2618 <input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />
2624 & Header
:: closebox
();
2626 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'certificate authorities'}:" );
2628 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
2630 <td width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></td>
2631 <td width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></td>
2632 <td width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></td>
2636 if (- f
"${General::swroot}/ca/cacert.pem" ) {
2637 my $casubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/ca/cacert.pem" ));
2640 <tr bgcolor=' $color {'color22'}'>
2641 <td class='base'> $Lang ::tr{'root certificate'}</td>
2642 <td class='base'> $casubject </td>
2643 <td width='3%' align='center'>
2644 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2645 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
2646 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/info.gif' alt=' $Lang ::tr{'show root certificate'}' title=' $Lang ::tr{'show root certificate'}' />
2649 <td width='3%' align='center'>
2650 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2651 <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'}' />
2652 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
2655 <td width='4%'> </td></tr>
2659 # display rootcert generation buttons
2661 <tr bgcolor=' $color {'color22'}'>
2662 <td class='base'> $Lang ::tr{'root certificate'}:</td>
2663 <td class='base'> $Lang ::tr{'not present'}</td>
2664 <td colspan='3'> </td></tr>
2669 if (- f
"${General::swroot}/certs/hostcert.pem" ) {
2670 my $hostsubject = & Header
:: cleanhtml
( getsubjectfromcert
( "${General::swroot}/certs/hostcert.pem" ));
2673 <tr bgcolor=' $color {'color20'}'>
2674 <td class='base'> $Lang ::tr{'host certificate'}</td>
2675 <td class='base'> $hostsubject </td>
2676 <td width='3%' align='center'>
2677 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2678 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
2679 <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'}' />
2682 <td width='3%' align='center'>
2683 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
2684 <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'}' />
2685 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download host certificate'}' />
2688 <td width='4%'> </td></tr>
2694 <tr bgcolor=' $color {'color20'}'>
2695 <td width='25%' class='base'> $Lang ::tr{'host certificate'}:</td>
2696 <td class='base'> $Lang ::tr{'not present'}</td>
2697 <td colspan='3'> </td></tr>
2703 if ( keys %cahash > 0 ) {
2704 foreach my $key ( keys %cahash ) {
2705 if ( $rowcolor ++ % 2 ) {
2706 print "<tr bgcolor=' $color {'color20'}'> \n " ;
2708 print "<tr bgcolor=' $color {'color22'}'> \n " ;
2710 print "<td class='base'> $cahash { $key }[0]</td> \n " ;
2711 print "<td class='base'> $cahash { $key }[1]</td> \n " ;
2714 <form method='post' name='cafrm${key}a' action=' $ENV {'SCRIPT_NAME'}'>
2715 <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'}' />
2716 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
2717 <input type='hidden' name='KEY' value=' $key ' />
2721 <form method='post' name='cafrm${key}b' action=' $ENV {'SCRIPT_NAME'}'>
2722 <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'}' />
2723 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
2724 <input type='hidden' name='KEY' value=' $key ' />
2728 <form method='post' name='cafrm${key}c' action=' $ENV {'SCRIPT_NAME'}'>
2729 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
2730 <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'}' />
2731 <input type='hidden' name='KEY' value=' $key ' />
2741 # If the file contains entries, print Key to action icons
2742 if ( - f
"${General::swroot}/ca/cacert.pem" ) {
2745 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
2746 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
2747 <td class='base'> $Lang ::tr{'show certificate'}</td>
2748 <td> <img src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' /></td>
2749 <td class='base'> $Lang ::tr{'download certificate'}</td>
2754 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>" ;
2757 <form method='post' enctype='multipart/form-data' action=' $ENV {'SCRIPT_NAME'}'>
2758 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
2761 <td class='base' nowrap='nowrap'> $Lang ::tr{'ca name'}:</td>
2762 <td nowrap='nowrap'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' /> </td>
2763 <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td>
2764 <td nowrap='nowrap'><input type='submit' name='ACTION' value=' $Lang ::tr{'upload ca certificate'}' /></td>
2767 <td colspan='3'> $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}:</td>
2768 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' /></td>
2774 & Header
:: closebox
();
2775 & Header
:: closebigbox
();
2776 & Header
:: closepage
();