]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/ovpnmain.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2011 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 ###############################################################################
22 # Based on IPFireCore 55
25 use CGI qw
/:standard/ ;
30 use File
:: Temp qw
/ tempfile tempdir / ;
32 use Archive
:: Zip
qw(:ERROR_CODES :CONSTANTS) ;
33 require '/var/ipfire/general-functions.pl' ;
34 require "${General::swroot}/lang.pl" ;
35 require "${General::swroot}/header.pl" ;
36 require "${General::swroot}/countries.pl" ;
38 # enable only the following on debugging purpose
40 #use CGI::Carp 'fatalsToBrowser';
41 #workaround to suppress a warning when a variable is used only once
42 my @dummy = ( ${ Header
:: colourgreen
}, ${ Header
:: colourblue
} );
46 my %mainsettings = ();
47 & General
:: readhash
( "${General::swroot}/main/settings" , \
%mainsettings );
48 & General
:: readhash
( "/srv/web/ipfire/html/themes/" . $mainsettings { 'THEME' }. "/include/colors.txt" , \
%color );
51 ### Initialize variables
64 my $errormessage = '' ;
66 my $routes_push_file = '' ;
67 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%netsettings );
68 $cgiparams { 'ENABLED' } = 'off' ;
69 $cgiparams { 'ENABLED_BLUE' } = 'off' ;
70 $cgiparams { 'ENABLED_ORANGE' } = 'off' ;
71 $cgiparams { 'EDIT_ADVANCED' } = 'off' ;
72 $cgiparams { 'NAT' } = 'off' ;
73 $cgiparams { 'COMPRESSION' } = 'off' ;
74 $cgiparams { 'ONLY_PROPOSED' } = 'off' ;
75 $cgiparams { 'ACTION' } = '' ;
76 $cgiparams { 'CA_NAME' } = '' ;
77 $cgiparams { 'DHCP_DOMAIN' } = '' ;
78 $cgiparams { 'DHCP_DNS' } = '' ;
79 $cgiparams { 'DHCP_WINS' } = '' ;
80 $cgiparams { 'ROUTES_PUSH' } = '' ;
81 $cgiparams { 'DCOMPLZO' } = 'off' ;
82 $cgiparams { 'MSSFIX' } = '' ;
83 $cgiparams { 'number' } = '' ;
84 $cgiparams { 'PMTU_DISCOVERY' } = '' ;
85 $routes_push_file = "${General::swroot}/ovpn/routes_push" ;
86 unless (- e
$routes_push_file ) { system ( "touch $routes_push_file " ); }
87 unless (- e
"${General::swroot}/ovpn/ccd.conf" ) { system ( "touch ${General::swroot}/ovpn/ccd.conf" ); }
88 unless (- e
"${General::swroot}/ovpn/ccdroute" ) { system ( "touch ${General::swroot}/ovpn/ccdroute" ); }
89 unless (- e
"${General::swroot}/ovpn/ccdroute2" ) { system ( "touch ${General::swroot}/ovpn/ccdroute2" ); }
91 & Header
:: getcgihash
( \
%cgiparams , { 'wantfile' => 1 , 'filevar' => 'FH' });
93 # prepare openvpn config file
99 if ( $netsettings { 'CONFIG_TYPE' } == 2 ) { return 1 ;}
100 if ( $netsettings { 'CONFIG_TYPE' } == 4 ) { return 1 ;}
106 if ( $netsettings { 'CONFIG_TYPE' } == 3 ) { return 1 ;}
107 if ( $netsettings { 'CONFIG_TYPE' } == 4 ) { return 1 ;}
112 my $bytesize = shift ;
115 while ( abs ( $bytesize ) >= 1024 ){
116 $bytesize = $bytesize / 1024 ;
121 my @units = ( "Bytes" , "KB" , "MB" , "GB" , "TB" , "PB" , "EB" );
122 my $newsize =( int ( $bytesize * 100 + 0.5 ))/ 100 ;
123 return ( " $newsize $units [ $i ]" );
127 my $hostname = $_ [ 0 ];
128 unless ( $hostname ) { return "No hostname" };
129 my $res = new Net
:: DNS
:: Resolver
;
130 my $query = $res -> search ( " $hostname " );
132 foreach my $rr ( $query -> answer ) {
133 ## Potential bug - we are only looking at A records:
134 return 0 if $rr -> type eq "A" ;
137 return $res -> errorstring ;
143 if ( open ( FILE
, ">${General::swroot}/ovpn/certs/serial" )) {
147 if ( open ( FILE
, ">${General::swroot}/ovpn/certs/index.txt" )) {
151 unlink ( "${General::swroot}/ovpn/certs/index.txt.old" );
152 unlink ( "${General::swroot}/ovpn/certs/serial.old" );
153 unlink ( "${General::swroot}/ovpn/certs/01.pem" );
156 sub newcleanssldatabase
158 if (! - s
"${General::swroot}/ovpn/certs/serial" ) {
159 open ( FILE
, ">${General::swroot}(ovpn/certs/serial" );
163 if (! - s
">${General::swroot}/ovpn/certs/index.txt" ) {
164 system ( "touch ${General::swroot}/ovpn/certs/index.txt" );
166 unlink ( "${General::swroot}/ovpn/certs/index.txt.old" );
167 unlink ( "${General::swroot}/ovpn/certs/serial.old" );
172 if ( open ( FILE
, "${General::swroot}/ovpn/certs/serial.old" )) {
173 my $hexvalue = < FILE
>;
176 unlink ( "${General::swroot}/ovpn/certs/ $hexvalue .pem" );
181 my $KEY2 = $_ [ 0 ]; # key2
182 my $SRC_PORT = $_ [ 1 ]; # src_port
183 my $PROTOCOL = $_ [ 2 ]; # protocol
184 my $SRC_IP = $_ [ 3 ]; # sourceip
186 my $pfwfilename = "${General::swroot}/portfw/config" ;
187 open ( FILE
, $pfwfilename ) or die 'Unable to open config file.' ;
188 my @pfwcurrent = < FILE
>;
190 my $pfwkey1 = 0 ; # used for finding last sequence number used
191 foreach my $pfwline ( @pfwcurrent )
193 my @pfwtemp = split ( /\,/ , $pfwline );
196 if ( $KEY2 eq "0" ){ # if key2 is 0 then it is a portfw addition
197 if ( $SRC_PORT eq $pfwtemp [ 3 ] &&
198 $PROTOCOL eq $pfwtemp [ 2 ] &&
199 $SRC_IP eq $pfwtemp [ 7 ])
201 $errormessage = " $Lang ::tr{'source port in use'} $SRC_PORT " ;
203 # Check if key2 = 0, if it is then it is a port forward entry and we want the sequence number
204 if ( $pfwtemp [ 1 ] eq "0" ) {
205 $pfwkey1 = $pfwtemp [ 0 ];
207 # Darren Critchley - Duplicate or overlapping Port range check
208 if ( $pfwtemp [ 1 ] eq "0" &&
209 $PROTOCOL eq $pfwtemp [ 2 ] &&
210 $SRC_IP eq $pfwtemp [ 7 ] &&
213 & portchecks
( $SRC_PORT , $pfwtemp [ 5 ]);
214 # &portchecks($pfwtemp[3], $pfwtemp[5]);
215 # &portchecks($pfwtemp[3], $SRC_IP);
219 # $errormessage="$KEY2 $SRC_PORT $PROTOCOL $SRC_IP";
226 my $portrange1 = $_ [ 0 ]; # New port range
227 my $portrange2 = $_ [ 1 ]; # existing port range
228 my @tempr1 = split ( /\:/ , $portrange1 );
229 my @tempr2 = split ( /\:/ , $portrange2 );
231 unless (& checkportinc
( $tempr1 [ 0 ], $portrange2 )){ return 0 ;}
232 unless (& checkportinc
( $tempr1 [ 1 ], $portrange2 )){ return 0 ;}
234 unless (& checkportinc
( $tempr2 [ 0 ], $portrange1 )){ return 0 ;}
235 unless (& checkportinc
( $tempr2 [ 1 ], $portrange1 )){ return 0 ;}
237 return 1 ; # Everything checks out!
240 # Darren Critchley - we want to make sure that a port entry is not within an already existing range
243 my $port1 = $_ [ 0 ]; # Port
244 my $portrange2 = $_ [ 1 ]; # Port range
245 my @tempr1 = split ( /\:/ , $portrange2 );
247 if ( $port1 < $tempr1 [ 0 ] || $port1 > $tempr1 [ 1 ]) {
253 # Darren Critchley - Duplicate or overlapping Port range check
256 my $p1 = $_ [ 0 ]; # New port range
257 my $p2 = $_ [ 1 ]; # existing port range
259 our ( $prtrange1 , $prtrange2 );
261 # if (m/:/ && $prtrange1 == 1) { # comparing two port ranges
262 # unless (&checkportoverlap($p1,$p2)) {
263 # $errormessage = "$Lang::tr{'source port overlaps'} $p1";
266 if ( m/:/ && $prtrange1 == 0 && $errormessage eq '' ) { # compare one port to a range
267 unless (& checkportinc
( $p2 , $p1 )) {
268 $errormessage = " $Lang ::tr{'srcprt within existing'} $p1 " ;
272 if (! m/:/ && $prtrange1 == 1 && $errormessage eq '' ) { # compare one port to a range
273 unless (& checkportinc
( $p1 , $p2 )) {
274 $errormessage = " $Lang ::tr{'srcprt range overlaps'} $p2 " ;
280 # Darren Critchley - certain ports are reserved for IPFire
281 # TCP 67,68,81,222,445
283 # Params passed in -> port, rangeyn, protocol
286 # port 67 and 68 same for tcp and udp, don't bother putting in an array
288 my @tcp_reserved = ( 81 , 222 , 445 );
289 my $prt = $_ [ 0 ]; # the port or range
290 my $ryn = $_ [ 1 ]; # tells us whether or not it is a port range
291 my $prot = $_ [ 2 ]; # protocol
292 my $srcdst = $_ [ 3 ]; # source or destination
293 if ( $ryn ) { # disect port range
294 if ( $srcdst eq "src" ) {
295 $msg = " $Lang ::tr{'rsvd src port overlap'}" ;
297 $msg = " $Lang ::tr{'rsvd dst port overlap'}" ;
299 my @tmprng = split ( /\:/ , $prt );
300 unless ( 67 < $tmprng [ 0 ] || 67 > $tmprng [ 1 ]) { $errormessage = " $msg 67" ; return ; }
301 unless ( 68 < $tmprng [ 0 ] || 68 > $tmprng [ 1 ]) { $errormessage = " $msg 68" ; return ; }
302 if ( $prot eq "tcp" ) {
303 foreach my $prange ( @tcp_reserved ) {
304 unless ( $prange < $tmprng [ 0 ] || $prange > $tmprng [ 1 ]) { $errormessage = " $msg $prange " ; return ; }
308 if ( $srcdst eq "src" ) {
309 $msg = " $Lang ::tr{'reserved src port'}" ;
311 $msg = " $Lang ::tr{'reserved dst port'}" ;
313 if ( $prt == 67 ) { $errormessage = " $msg 67" ; return ; }
314 if ( $prt == 68 ) { $errormessage = " $msg 68" ; return ; }
315 if ( $prot eq "tcp" ) {
316 foreach my $prange ( @tcp_reserved ) {
317 if ( $prange == $prt ) { $errormessage = " $msg $prange " ; return ; }
324 sub writeserverconf
{
325 my %sovpnsettings = ();
327 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%sovpnsettings );
330 open ( CONF
, ">${General::swroot}/ovpn/server.conf" ) or die "Unable to open ${General::swroot}/ovpn/server.conf: $!" ;
332 print CONF
"#OpenVPN Server conf \n " ;
334 print CONF
"daemon openvpnserver \n " ;
335 print CONF
"writepid /var/run/openvpn.pid \n " ;
336 print CONF
"#DAN prepare OpenVPN for listening on blue and orange \n " ;
337 print CONF
";local $sovpnsettings {'VPN_IP'} \n " ;
338 print CONF
"dev $sovpnsettings {'DDEVICE'} \n " ;
339 print CONF
"proto $sovpnsettings {'DPROTOCOL'} \n " ;
340 print CONF
"port $sovpnsettings {'DDEST_PORT'} \n " ;
341 print CONF
"script-security 3 system \n " ;
342 print CONF
"ifconfig-pool-persist /var/ipfire/ovpn/ovpn-leases.db 3600 \n " ;
343 print CONF
"client-config-dir /var/ipfire/ovpn/ccd \n " ;
344 print CONF
"tls-server \n " ;
345 print CONF
"ca /var/ipfire/ovpn/ca/cacert.pem \n " ;
346 print CONF
"cert /var/ipfire/ovpn/certs/servercert.pem \n " ;
347 print CONF
"key /var/ipfire/ovpn/certs/serverkey.pem \n " ;
348 print CONF
"dh /var/ipfire/ovpn/ca/dh1024.pem \n " ;
349 my @tempovpnsubnet = split ( "\/" , $sovpnsettings { 'DOVPN_SUBNET' });
350 print CONF
"server $tempovpnsubnet [0] $tempovpnsubnet [1] \n " ;
351 #print CONF "push \"route $netsettings{'GREEN_NETADDRESS'} $netsettings{'GREEN_NETMASK'}\"\n";
353 # Check if we are using mssfix, fragment or mtu-disc and set the corretct mtu of 1500.
354 # If we doesn't use one of them, we can use the configured mtu value.
355 if ( $sovpnsettings { 'MSSFIX' } eq 'on' )
356 { print CONF
" $sovpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
357 elsif ( $sovpnsettings { 'FRAGMENT' } ne '' && $sovpnsettings { 'DPROTOCOL' } ne 'tcp' )
358 { print CONF
" $sovpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
359 elsif (( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'yes' ) ||
360 ( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
361 ( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'no' ))
362 { print CONF
" $sovpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
364 { print CONF
" $sovpnsettings {'DDEVICE'}-mtu $sovpnsettings {'DMTU'} \n " ; }
366 if ( $vpnsettings { 'ROUTES_PUSH' } ne '' ) {
367 @temp = split ( /\n/ , $vpnsettings { 'ROUTES_PUSH' });
370 @tempovpnsubnet = split ( "\/" ,& General
:: ipcidr2msk
( $_ ));
371 print CONF
"push \" route " . $tempovpnsubnet [ 0 ]. " " . $tempovpnsubnet [ 1 ] . " \"\n " ;
376 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
377 foreach my $key ( keys %ccdconfhash ) {
378 my $a = $ccdconfhash { $key }[ 1 ];
379 my ( $b , $c ) = split ( /\/ /, $a );
380 print CONF
"route $b " .& General
:: cidrtosub
( $c ). " \n " ;
383 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
384 foreach my $key ( keys %ccdroutehash ) {
385 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}){
386 my ( $a , $b )= split ( /\/ /, $ccdroutehash { $key }[ $i ]);
387 print CONF
"route $a $b \n " ;
392 if ( $sovpnsettings { CLIENT2CLIENT
} eq 'on' ) {
393 print CONF
"client-to-client \n " ;
395 if ( $sovpnsettings { MSSFIX
} eq 'on' ) {
396 print CONF
"mssfix \n " ;
398 if ( $sovpnsettings { FRAGMENT
} ne '' && $sovpnsettings { 'DPROTOCOL' } ne 'tcp' ) {
399 print CONF
"fragment $sovpnsettings {'FRAGMENT'} \n " ;
402 # Check if a valid operating mode has been choosen and use it.
403 if (( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'yes' ) ||
404 ( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
405 ( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'no' )) {
406 print CONF
"mtu-disc $sovpnsettings {'PMTU_DISCOVERY'} \n " ;
409 if ( $sovpnsettings { KEEPALIVE_1
} > 0 && $sovpnsettings { KEEPALIVE_2
} > 0 ) {
410 print CONF
"keepalive $sovpnsettings {'KEEPALIVE_1'} $sovpnsettings {'KEEPALIVE_2'} \n " ;
412 print CONF
"status-version 1 \n " ;
413 print CONF
"status /var/log/ovpnserver.log 30 \n " ;
414 print CONF
"cipher $sovpnsettings {DCIPHER} \n " ;
415 if ( $sovpnsettings { DCOMPLZO
} eq 'on' ) {
416 print CONF
"comp-lzo \n " ;
418 if ( $sovpnsettings { REDIRECT_GW_DEF1
} eq 'on' ) {
419 print CONF
"push \" redirect-gateway def1 \"\n " ;
421 if ( $sovpnsettings { DHCP_DOMAIN
} ne '' ) {
422 print CONF
"push \" dhcp-option DOMAIN $sovpnsettings {DHCP_DOMAIN} \"\n " ;
425 if ( $sovpnsettings { DHCP_DNS
} ne '' ) {
426 print CONF
"push \" dhcp-option DNS $sovpnsettings {DHCP_DNS} \"\n " ;
429 if ( $sovpnsettings { DHCP_WINS
} ne '' ) {
430 print CONF
"push \" dhcp-option WINS $sovpnsettings {DHCP_WINS} \"\n " ;
433 if ( $sovpnsettings { DHCP_WINS
} eq '' ) {
434 print CONF
"max-clients 100 \n " ;
436 if ( $sovpnsettings { DHCP_WINS
} ne '' ) {
437 print CONF
"max-clients $sovpnsettings {MAX_CLIENTS} \n " ;
439 print CONF
"tls-verify /var/ipfire/ovpn/verify \n " ;
440 print CONF
"crl-verify /var/ipfire/ovpn/crls/cacrl.pem \n " ;
441 print CONF
"user nobody \n " ;
442 print CONF
"group nobody \n " ;
443 print CONF
"persist-key \n " ;
444 print CONF
"persist-tun \n " ;
445 if ( $sovpnsettings { LOG_VERB
} ne '' ) {
446 print CONF
"verb $sovpnsettings {LOG_VERB} \n " ;
448 print CONF
"verb 3 \n " ;
456 if ( open ( FILE
, ">/var/log/ovpnserver.log" )) {
466 my %ccdconfhash = ();
468 my $ccdnetname = $_ [ 0 ];
469 if (- f
"${General::swroot}/ovpn/ovpnconfig" ){
470 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
471 foreach my $key ( keys %ccdhash ) {
472 if ( $ccdhash { $key }[ 32 ] eq $ccdnetname ) {
473 $errormessage = $Lang :: tr
{ 'ccd err hostinnet' };
478 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
479 foreach my $key ( keys %ccdconfhash ) {
480 if ( $ccdconfhash { $key }[ 0 ] eq $ccdnetname ){
481 delete $ccdconfhash { $key };
484 & General
:: writehasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
496 my $ovpnsubnet = $_ [ 2 ];
507 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err name' }. "<br>" ;
511 if (!& General
:: validhostname
( $ccdname ))
513 $errormessage = $Lang :: tr
{ 'ccd err invalidname' };
517 ( $ccdip , $subcidr ) = split ( /\/ /, $ccdnet );
518 $subcidr =& General
:: iporsubtocidr
( $subcidr );
522 $errormessage = $Lang :: tr
{ 'ccd err invalidnet' };
526 if (!& General
:: validipandmask
( $ccdnet )){
527 $errormessage = $Lang :: tr
{ 'ccd err invalidnet' };
532 #check if we try to use same network as ovpn server
533 if (& General
:: iporsubtocidr
( $ccdnet ) eq & General
:: iporsubtocidr
( $ovpnsubnet )) {
534 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err isovpnnet' }. "<br>" ;
537 #check if we use a name/subnet that already exists
538 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
539 foreach my $key ( keys %ccdconfhash ) {
540 @ccdconf = split ( /\/ /, $ccdconfhash { $key }[ 1 ]);
541 if ( $ccdname eq $ccdconfhash { $key }[ 0 ]) { $errormessage = $errormessage . $Lang :: tr
{ 'ccd err nameexist' }. "<br>" ;}
542 my ( $newip , $newsub ) = split ( /\/ /, $ccdnet );
543 if (& General
:: IpInSubnet
( $newip , $ccdconf [ 0 ],& General
:: iporsubtodec
( $ccdconf [ 1 ]))) { $errormessage = $errormessage . $Lang :: tr
{ 'ccd err issubnet' }. "<br>" ;}
546 #check if we use one of ipfire's networks (green,orange,blue)
548 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%ownnet );
549 if (( $ownnet { 'GREEN_NETADDRESS' } ne '' && $ownnet { 'GREEN_NETADDRESS' } ne '0.0.0.0' ) && & General
:: IpInSubnet
( $ownnet { 'GREEN_NETADDRESS' }, $ccdip ,& General
:: iporsubtodec
( $subcidr ))){ $errormessage = $Lang :: tr
{ 'ccd err green' };}
550 if (( $ownnet { 'ORANGE_NETADDRESS' } ne '' && $ownnet { 'ORANGE_NETADDRESS' } ne '0.0.0.0' ) && & General
:: IpInSubnet
( $ownnet { 'ORANGE_NETADDRESS' }, $ccdip ,& General
:: iporsubtodec
( $subcidr ))){ $errormessage = $Lang :: tr
{ 'ccd err orange' };}
551 if (( $ownnet { 'BLUE_NETADDRESS' } ne '' && $ownnet { 'BLUE_NETADDRESS' } ne '0.0.0.0' ) && & General
:: IpInSubnet
( $ownnet { 'BLUE_NETADDRESS' }, $ccdip ,& General
:: iporsubtodec
( $subcidr ))){ $errormessage = $Lang :: tr
{ 'ccd err blue' };}
552 if (( $ownnet { 'RED_NETADDRESS' } ne '' && $ownnet { 'RED_NETADDRESS' } ne '0.0.0.0' ) && & General
:: IpInSubnet
( $ownnet { 'RED_NETADDRESS' }, $ccdip ,& General
:: iporsubtodec
( $subcidr ))){ $errormessage = $Lang :: tr
{ 'ccd err red' };}
555 if (! $errormessage ) {
557 $baseaddress =& General
:: getnetworkip
( $ccdip , $subcidr );
558 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
559 my $key = & General
:: findhasharraykey
( \
%ccdconfhash );
560 foreach my $i ( 0 .. 1 ) { $ccdconfhash { $key }[ $i ] = "" ;}
561 $ccdconfhash { $key }[ 0 ] = $ccdname ;
562 $ccdconfhash { $key }[ 1 ] = $baseaddress . "/" . $subcidr ;
563 & General
:: writehasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
565 $cgiparams { 'ccdname' }= '' ;
566 $cgiparams { 'ccdsubnet' }= '' ;
578 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
579 foreach my $key ( keys %ccdconfhash ) {
580 if ( $ccdconfhash { $key }[ 0 ] eq $oldname ) {
581 foreach my $key1 ( keys %ccdconfhash ) {
582 if ( $ccdconfhash { $key1 }[ 0 ] eq $newname ){
583 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err netadrexist' };
586 $ccdconfhash { $key }[ 0 ]= $newname ;
587 & General
:: writehasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
594 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
595 foreach my $key ( keys %ccdhash ) {
596 if ( $ccdhash { $key }[ 32 ] eq $oldname ) {
597 $ccdhash { $key }[ 32 ]= $newname ;
598 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
607 my $ccdnetwork = $_ [ 0 ];
610 @octets = split ( "\/" , $ccdnetwork );
611 @subnet = split /\./ , & General
:: cidrtosub
( $octets [ 1 ]);
624 my ( $ip1 , $ip2 , $ip3 , $ip4 )= split /\./ , $ipin ;
632 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
633 $iprange [ 0 ]= $ip1 . "." . $ip2 . "." . $ip3 . "." .2 ;
634 for ( my $i = 0 ; $i <= $count - 1 ; $i ++) {
635 my $tmpip = $iprange [ $i - 1 ];
637 $iprange [ $i ]= & General
:: getnextip
( $tmpip , 4 );
640 foreach my $key ( keys %ccdhash ) {
642 foreach my $tmp ( @iprange ){
643 my ( $net , $sub ) = split ( /\/ /, $ccdhash { $key }[ 33 ]);
645 if ( $hasip ne $ccdhash { $key }[ 33 ] ){
646 splice ( @iprange , $r , 1 );
658 my ( $ccdip , $subcidr ) = split ( "/" , $_ [ 0 ]);
660 my @allccdips =& getccdadresses
( $ccdip , $subcidr ,& ccdmaxclients
( $ccdip . "/" . $subcidr ), $tz );
661 print "<select name=' $boxname ' STYLE='font-family : arial; font-size : 9pt; width:130px;' >" ;
662 foreach ( @allccdips ) {
665 print "<option value=' $ip ' " ;
666 if ( $ip eq $cgiparams { $boxname } ){
669 print "> $ip </option>" ;
679 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
680 foreach my $key ( keys %ccdhash ) {
681 if ( $ccdhash { $key }[ 32 ] eq $name ){ $i ++;}
686 sub check_routes_push
689 my ( $ip , $cidr ) = split ( /\/ /, $val );
690 ##check for existing routes in routes_push
691 if (- e
"${General::swroot}/ovpn/routes_push" ) {
692 open ( FILE
, "${General::swroot}/ovpn/routes_push" );
696 my ( $ip2 , $cidr2 ) = split ( /\/ /, " $_ " );
697 my $val2 = $ip2 . "/" .& General
:: iporsubtodec
( $cidr2 );
703 if (& General
:: IpInSubnet
( $ip , $ip2 ,& General
:: iporsubtodec
( $cidr2 ))){
716 my ( $ip , $cidr ) = split ( /\/ /, $val );
717 #check for existing routes in ccdroute
718 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
719 foreach my $key ( keys %ccdroutehash ) {
720 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}) {
721 if (& General
:: iporsubtodec
( $val ) eq $ccdroutehash { $key }[ $i ] && $ccdroutehash { $key }[ 0 ] ne $cgiparams { 'NAME' }){
724 my ( $ip2 , $cidr2 ) = split ( /\/ /, $ccdroutehash { $key }[ $i ]);
726 if (& General
:: IpInSubnet
( $ip , $ip2 , $cidr2 )&& $ccdroutehash { $key }[ 0 ] ne $cgiparams { 'NAME' } ){
737 my ( $ip , $cidr ) = split ( /\/ /, $val );
738 #check for existing routes in ccdroute
739 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
740 foreach my $key ( keys %ccdconfhash ) {
741 if (& General
:: iporsubtocidr
( $val ) eq $ccdconfhash { $key }[ 1 ]){
744 my ( $ip2 , $cidr2 ) = split ( /\/ /, $ccdconfhash { $key }[ 1 ]);
746 if (& General
:: IpInSubnet
( $ip , $ip2 ,& General
:: cidrtosub
( $cidr2 ))){
760 my $ipdotmask = $_ [ 0 ];
761 if (& General
:: validip
( $ipdotmask )) { return 0 ; }
762 if (!( $ipdotmask =~ /^(.*?)\/ (.* ?
)$/)) { }
764 if (( $mask =~ /\./ )) { return 0 ; }
768 # -------------------------------------------------------------------
770 sub write_routepushfile
772 open ( FILE
, "> $routes_push_file " );
774 if ( $vpnsettings { 'ROUTES_PUSH' } ne '' ) {
775 print FILE
$vpnsettings { 'ROUTES_PUSH' };
780 sub read_routepushfile
782 if (- e
" $routes_push_file " ) {
783 open ( FILE
, " $routes_push_file " );
784 delete $vpnsettings { 'ROUTES_PUSH' };
785 while (< FILE
>) { $vpnsettings { 'ROUTES_PUSH' } .= $_ };
787 $cgiparams { 'ROUTES_PUSH' } = $vpnsettings { 'ROUTES_PUSH' };
793 #hier die refresh page
794 if ( - e
"${General::swroot}/ovpn/gencanow" ) {
796 $refresh = "<meta http-equiv='refresh' content='15;' />" ;
797 & Header
:: showhttpheaders
();
798 & Header
:: openpage
( $Lang :: tr
{ 'OVPN' }, 1 , $refresh );
799 & Header
:: openbigbox
( '100%' , 'center' );
800 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
801 print "<tr> \n <td align='center'><img src='/images/clock.gif' alt='' /></td> \n " ;
802 print "<td colspan='2'><font color='red'>Please be patient this realy can take some time on older hardware...</font></td></tr> \n " ;
804 & Header
:: closebigbox
();
805 & Header
:: closepage
();
808 ##hier die refresh page
812 ### OpenVPN Server Control
814 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'start ovpn server' } ||
815 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'stop ovpn server' } ||
816 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart ovpn server' }) {
817 #start openvpn server
818 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'start ovpn server' }){
820 system ( '/usr/local/bin/openvpnctrl' , '-s' );
823 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'stop ovpn server' }){
824 system ( '/usr/local/bin/openvpnctrl' , '-k' );
827 # #restart openvpn server
828 # if ($cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}){
829 #workarund, till SIGHUP also works when running as nobody
830 # system('/usr/local/bin/openvpnctrl', '-r');
836 ### Save Advanced options
839 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save-adv-options' }) {
840 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
841 #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too,
842 #DAN this value has to leave.
843 #new settings for daemon
844 $vpnsettings { 'LOG_VERB' } = $cgiparams { 'LOG_VERB' };
845 $vpnsettings { 'KEEPALIVE_1' } = $cgiparams { 'KEEPALIVE_1' };
846 $vpnsettings { 'KEEPALIVE_2' } = $cgiparams { 'KEEPALIVE_2' };
847 $vpnsettings { 'MAX_CLIENTS' } = $cgiparams { 'MAX_CLIENTS' };
848 $vpnsettings { 'REDIRECT_GW_DEF1' } = $cgiparams { 'REDIRECT_GW_DEF1' };
849 $vpnsettings { 'CLIENT2CLIENT' } = $cgiparams { 'CLIENT2CLIENT' };
850 $vpnsettings { 'DHCP_DOMAIN' } = $cgiparams { 'DHCP_DOMAIN' };
851 $vpnsettings { 'DHCP_DNS' } = $cgiparams { 'DHCP_DNS' };
852 $vpnsettings { 'DHCP_WINS' } = $cgiparams { 'DHCP_WINS' };
853 $vpnsettings { 'ROUTES_PUSH' } = $cgiparams { 'ROUTES_PUSH' };
854 $vpnsettings { 'PMTU_DISCOVERY' } = $cgiparams { 'PMTU_DISCOVERY' };
857 if ( $cgiparams { 'FRAGMENT' } eq '' ) {
858 delete $vpnsettings { 'FRAGMENT' };
860 if ( $cgiparams { 'FRAGMENT' } !~ /^[0-9]+$/ ) {
861 $errormessage = "Incorrect value, please insert only numbers." ;
864 $vpnsettings { 'FRAGMENT' } = $cgiparams { 'FRAGMENT' };
867 if ( $cgiparams { 'MSSFIX' } ne 'on' ) {
868 delete $vpnsettings { 'MSSFIX' };
870 $vpnsettings { 'MSSFIX' } = $cgiparams { 'MSSFIX' };
873 if (( $cgiparams { 'PMTU_DISCOVERY' } eq 'yes' ) ||
874 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
875 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'no' )) {
877 if (( $cgiparams { 'MSSFIX' } eq 'on' ) || ( $cgiparams { 'FRAGMENT' } ne '' )) {
878 $errormessage = $Lang :: tr
{ 'ovpn mtu-disc with mssfix or fragment' };
883 if ( $cgiparams { 'DHCP_DOMAIN' } ne '' ){
884 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_DOMAIN' }) || & General
:: validip
( $cgiparams { 'DHCP_DOMAIN' })) {
885 $errormessage = $Lang :: tr
{ 'invalid input for dhcp domain' };
889 if ( $cgiparams { 'DHCP_DNS' } ne '' ){
890 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_DNS' }) || & General
:: validip
( $cgiparams { 'DHCP_DNS' })) {
891 $errormessage = $Lang :: tr
{ 'invalid input for dhcp dns' };
895 if ( $cgiparams { 'DHCP_WINS' } ne '' ){
896 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_WINS' }) || & General
:: validip
( $cgiparams { 'DHCP_WINS' })) {
897 $errormessage = $Lang :: tr
{ 'invalid input for dhcp wins' };
901 if ( $cgiparams { 'ROUTES_PUSH' } ne '' ){
902 @temp = split ( /\n/ , $cgiparams { 'ROUTES_PUSH' });
903 undef $vpnsettings { 'ROUTES_PUSH' };
905 foreach my $tmpip ( @temp )
907 s/^\s+//g ; s/\s+$//g ;
912 unless (& General
:: validipandmask
( $tmpip )) {
913 $errormessage = " $tmpip " . $Lang :: tr
{ 'ovpn errmsg invalid ip or mask' };
916 my ( $ip , $cidr ) = split ( "\/" ,& General
:: ipcidr2msk
( $tmpip ));
918 if ( $ip eq $netsettings { 'GREEN_NETADDRESS' } && $cidr eq $netsettings { 'GREEN_NETMASK' }) {
919 $errormessage = $Lang :: tr
{ 'ovpn errmsg green already pushed' };
924 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
925 foreach my $key ( keys %ccdroutehash ) {
926 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}) {
927 if ( $ip . "/" . $cidr eq $ccdroutehash { $key }[ $i ] ){
928 $errormessage = "Route $ip \/ $cidr " . $Lang :: tr
{ 'ccd err inuse' }. " $ccdroutehash { $key }[0]" ;
931 my ( $ip2 , $cidr2 ) = split ( /\/ /, $ccdroutehash { $key }[ $i ]);
932 if (& General
:: IpInSubnet
( $ip , $ip2 , $cidr2 )){
933 $errormessage = "Route $ip \/ $cidr " . $Lang :: tr
{ 'ccd err inuse' }. " $ccdroutehash { $key }[0]" ;
941 $vpnsettings { 'ROUTES_PUSH' } .= $tmpip . " \n " ;
944 & write_routepushfile
;
945 undef $vpnsettings { 'ROUTES_PUSH' };
948 undef $vpnsettings { 'ROUTES_PUSH' };
949 & write_routepushfile
;
951 if (( length ( $cgiparams { 'MAX_CLIENTS' }) == 0 ) || (( $cgiparams { 'MAX_CLIENTS' }) < 1 ) || (( $cgiparams { 'MAX_CLIENTS' }) > 255 )) {
952 $errormessage = $Lang :: tr
{ 'invalid input for max clients' };
955 if ( $cgiparams { 'KEEPALIVE_1' } ne '' ) {
956 if ( $cgiparams { 'KEEPALIVE_1' } !~ /^[0-9]+$/ ) {
957 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 1' };
961 if ( $cgiparams { 'KEEPALIVE_2' } ne '' ){
962 if ( $cgiparams { 'KEEPALIVE_2' } !~ /^[0-9]+$/ ) {
963 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 2' };
967 if ( $cgiparams { 'KEEPALIVE_2' } < ( $cgiparams { 'KEEPALIVE_1' } * 2 )){
968 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 1:2' };
972 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
973 & writeserverconf
(); #hier ok
980 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq 'net' && $cgiparams { 'SIDE' } eq 'server' )
983 my @remsubnet = split ( /\/ /, $cgiparams { 'REMOTE_SUBNET' });
984 my @ovsubnettemp = split ( /\./ , $cgiparams { 'OVPN_SUBNET' });
985 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
988 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
989 unless (- d
"${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" , 0770 or die "Unable to create dir $!" ;}
991 open ( SERVERCONF
, ">${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Unable to open ${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf: $!" ;
994 print SERVERCONF
"# IPFire n2n Open VPN Server Config by ummeegge und m.a.d \n " ;
995 print SERVERCONF
" \n " ;
996 print SERVERCONF
"# User Security \n " ;
997 print SERVERCONF
"user nobody \n " ;
998 print SERVERCONF
"group nobody \n " ;
999 print SERVERCONF
"persist-tun \n " ;
1000 print SERVERCONF
"persist-key \n " ;
1001 print SERVERCONF
"script-security 2 \n " ;
1002 print SERVERCONF
"# IP/DNS for remote Server Gateway \n " ;
1003 print SERVERCONF
"remote $cgiparams {'REMOTE'} \n " ;
1004 print SERVERCONF
"float \n " ;
1005 print SERVERCONF
"# IP adresses of the VPN Subnet \n " ;
1006 print SERVERCONF
"ifconfig $ovsubnet .1 $ovsubnet .2 \n " ;
1007 print SERVERCONF
"# Client Gateway Network \n " ;
1008 print SERVERCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
1009 print SERVERCONF
"# tun Device \n " ;
1010 print SERVERCONF
"dev tun \n " ;
1011 print SERVERCONF
"# Port and Protokol \n " ;
1012 print SERVERCONF
"port $cgiparams {'DEST_PORT'} \n " ;
1014 if ( $cgiparams { 'PROTOCOL' } eq 'tcp' ) {
1015 print SERVERCONF
"proto tcp-server \n " ;
1016 print SERVERCONF
"# Packet size \n " ;
1017 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1400' } else { $tunmtu = $cgiparams { 'MTU' }};
1018 print SERVERCONF
"tun-mtu $tunmtu \n " ;
1021 if ( $cgiparams { 'PROTOCOL' } eq 'udp' ) {
1022 print SERVERCONF
"proto udp \n " ;
1023 print SERVERCONF
"# Paketsize \n " ;
1024 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1500' } else { $tunmtu = $cgiparams { 'MTU' }};
1025 print SERVERCONF
"tun-mtu $tunmtu \n " ;
1026 if ( $cgiparams { 'FRAGMENT' } ne '' ) { print SERVERCONF
"fragment $cgiparams {'FRAGMENT'} \n " ;}
1027 if ( $cgiparams { 'MSSFIX' } eq 'on' ) { print SERVERCONF
"mssfix \n " ; };
1030 # Check if a valid operating mode has been choosen and use it.
1031 if (( $cgiparams { 'PMTU_DISCOVERY' } eq 'yes' ) ||
1032 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
1033 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'no' )) {
1034 if (( $cgiparams { 'MSSFIX' } ne 'on' ) || ( $cgiparams { 'FRAGMENT' } eq '' )) {
1035 if ( $cgiparams { 'MTU' } eq '1500' ) {
1036 print SERVERCONF
"mtu-disc $cgiparams {'PMTU_DISCOVERY'} \n " ;
1040 print SERVERCONF
"# Auth. Server \n " ;
1041 print SERVERCONF
"tls-server \n " ;
1042 print SERVERCONF
"ca ${General::swroot}/ovpn/ca/cacert.pem \n " ;
1043 print SERVERCONF
"cert ${General::swroot}/ovpn/certs/servercert.pem \n " ;
1044 print SERVERCONF
"key ${General::swroot}/ovpn/certs/serverkey.pem \n " ;
1045 print SERVERCONF
"dh ${General::swroot}/ovpn/ca/dh1024.pem \n " ;
1046 print SERVERCONF
"# Cipher \n " ;
1047 print SERVERCONF
"cipher AES-256-CBC \n " ;
1048 if ( $cgiparams { 'COMPLZO' } eq 'on' ) {
1049 print SERVERCONF
"# Enable Compression \n " ;
1050 print SERVERCONF
"comp-lzo \r\n " ;
1052 print SERVERCONF
"# Debug Level \n " ;
1053 print SERVERCONF
"verb 3 \n " ;
1054 print SERVERCONF
"# Tunnel check \n " ;
1055 print SERVERCONF
"keepalive 10 60 \n " ;
1056 print SERVERCONF
"# Start as daemon \n " ;
1057 print SERVERCONF
"daemon $cgiparams {'NAME'}n2n \n " ;
1058 print SERVERCONF
"writepid /var/run/ $cgiparams {'NAME'}n2n.pid \n " ;
1059 print SERVERCONF
"# Activate Management Interface and Port \n " ;
1060 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) { print SERVERCONF
"management localhost $cgiparams {'DEST_PORT'} \n " }
1061 else { print SERVERCONF
"management localhost $cgiparams {'OVPN_MGMT'} \n " };
1070 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq 'net' && $cgiparams { 'SIDE' } eq 'client' )
1072 my @ovsubnettemp = split ( /\./ , $cgiparams { 'OVPN_SUBNET' });
1073 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
1074 my @remsubnet = split ( /\/ /, $cgiparams { 'REMOTE_SUBNET' });
1077 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
1078 unless (- d
"${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" , 0770 or die "Unable to create dir $!" ;}
1080 open ( CLIENTCONF
, ">${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Unable to open ${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf: $!" ;
1082 flock CLIENTCONF
, 2 ;
1083 print CLIENTCONF
"# IPFire rewritten n2n Open VPN Client Config by ummeegge und m.a.d \n " ;
1084 print CLIENTCONF
"# \n " ;
1085 print CLIENTCONF
"# User Security \n " ;
1086 print CLIENTCONF
"user nobody \n " ;
1087 print CLIENTCONF
"group nobody \n " ;
1088 print CLIENTCONF
"persist-tun \n " ;
1089 print CLIENTCONF
"persist-key \n " ;
1090 print CLIENTCONF
"script-security 2 \n " ;
1091 print CLIENTCONF
"# IP/DNS for remote Server Gateway \n " ;
1092 print CLIENTCONF
"remote $cgiparams {'REMOTE'} \n " ;
1093 print CLIENTCONF
"float \n " ;
1094 print CLIENTCONF
"# IP adresses of the VPN Subnet \n " ;
1095 print CLIENTCONF
"ifconfig $ovsubnet .2 $ovsubnet .1 \n " ;
1096 print CLIENTCONF
"# Server Gateway Network \n " ;
1097 print CLIENTCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
1098 print CLIENTCONF
"# tun Device \n " ;
1099 print CLIENTCONF
"dev tun \n " ;
1100 print CLIENTCONF
"# Port and Protokol \n " ;
1101 print CLIENTCONF
"port $cgiparams {'DEST_PORT'} \n " ;
1103 if ( $cgiparams { 'PROTOCOL' } eq 'tcp' ) {
1104 print CLIENTCONF
"proto tcp-client \n " ;
1105 print CLIENTCONF
"# Packet size \n " ;
1106 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1400' } else { $tunmtu = $cgiparams { 'MTU' }};
1107 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
1110 if ( $cgiparams { 'PROTOCOL' } eq 'udp' ) {
1111 print CLIENTCONF
"proto udp \n " ;
1112 print CLIENTCONF
"# Paketsize \n " ;
1113 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1500' } else { $tunmtu = $cgiparams { 'MTU' }};
1114 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
1115 if ( $cgiparams { 'FRAGMENT' } ne '' ) { print CLIENTCONF
"fragment $cgiparams {'FRAGMENT'} \n " ;}
1116 if ( $cgiparams { 'MSSFIX' } eq 'on' ) { print CLIENTCONF
"mssfix \n " ; };
1119 # Check if a valid operating mode has been choosen and use it.
1120 if (( $cgiparams { 'PMTU_DISCOVERY' } eq 'yes' ) ||
1121 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
1122 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'no' )) {
1123 if (( $cgiparams { 'MSSFIX' } ne 'on' ) || ( $cgiparams { 'FRAGMENT' } eq '' )) {
1124 if ( $cgiparams { 'MTU' } eq '1500' ) {
1125 print CLIENTCONF
"mtu-disc $cgiparams {'PMTU_DISCOVERY'} \n " ;
1130 print CLIENTCONF
"ns-cert-type server \n " ;
1131 print CLIENTCONF
"# Auth. Client \n " ;
1132 print CLIENTCONF
"tls-client \n " ;
1133 print CLIENTCONF
"# Cipher \n " ;
1134 print CLIENTCONF
"cipher AES-256-CBC \n " ;
1135 print CLIENTCONF
"pkcs12 ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12 \r\n " ;
1136 if ( $cgiparams { 'COMPLZO' } eq 'on' ) {
1137 print CLIENTCONF
"# Enable Compression \n " ;
1138 print CLIENTCONF
"comp-lzo \r\n " ;
1140 print CLIENTCONF
"# Debug Level \n " ;
1141 print CLIENTCONF
"verb 3 \n " ;
1142 print CLIENTCONF
"# Tunnel check \n " ;
1143 print CLIENTCONF
"keepalive 10 60 \n " ;
1144 print CLIENTCONF
"# Start as daemon \n " ;
1145 print CLIENTCONF
"daemon $cgiparams {'NAME'}n2n \n " ;
1146 print CLIENTCONF
"writepid /var/run/ $cgiparams {'NAME'}n2n.pid \n " ;
1147 print CLIENTCONF
"# Activate Management Interface and Port \n " ;
1148 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) { print CLIENTCONF
"management localhost $cgiparams {'DEST_PORT'} \n " }
1149 else { print CLIENTCONF
"management localhost $cgiparams {'OVPN_MGMT'} \n " };
1155 ### Save main settings
1159 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
1160 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1161 #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too,
1162 #DAN this value has to leave.
1163 if ( $cgiparams { 'ENABLED' } eq 'on' ){
1164 unless (& General
:: validfqdn
( $cgiparams { 'VPN_IP' }) || & General
:: validip
( $cgiparams { 'VPN_IP' })) {
1165 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
1166 goto SETTINGS_ERROR
;
1169 if ( $cgiparams { 'ENABLED' } eq 'on' ){
1170 & disallowreserved
( $cgiparams { 'DDEST_PORT' }, 0 , $cgiparams { 'DPROTOCOL' }, "dest" );
1172 if ( $errormessage ) { goto SETTINGS_ERROR
; }
1175 if ( $cgiparams { 'ENABLED' } eq 'on' ){
1176 & checkportfw
( 0 , $cgiparams { 'DDEST_PORT' }, $cgiparams { 'DPROTOCOL' }, '0.0.0.0' );
1179 if ( $errormessage ) { goto SETTINGS_ERROR
; }
1181 if (! & General
:: validipandmask
( $cgiparams { 'DOVPN_SUBNET' })) {
1182 $errormessage = $Lang :: tr
{ 'ovpn subnet is invalid' };
1183 goto SETTINGS_ERROR
;
1185 my @tmpovpnsubnet = split ( "\/" , $cgiparams { 'DOVPN_SUBNET' });
1187 if (& General
:: IpInSubnet
( $netsettings { 'RED_ADDRESS' },
1188 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1189 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire RED Network $netsettings {'RED_ADDRESS'}" ;
1190 goto SETTINGS_ERROR
;
1193 if (& General
:: IpInSubnet
( $netsettings { 'GREEN_ADDRESS' },
1194 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1195 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Green Network $netsettings {'GREEN_ADDRESS'}" ;
1196 goto SETTINGS_ERROR
;
1199 if (& General
:: IpInSubnet
( $netsettings { 'BLUE_ADDRESS' },
1200 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1201 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Blue Network $netsettings {'BLUE_ADDRESS'}" ;
1202 goto SETTINGS_ERROR
;
1205 if (& General
:: IpInSubnet
( $netsettings { 'ORANGE_ADDRESS' },
1206 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1207 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Orange Network $netsettings {'ORANGE_ADDRESS'}" ;
1208 goto SETTINGS_ERROR
;
1210 open ( ALIASES
, "${General::swroot}/ethernet/aliases" ) or die 'Unable to open aliases file.' ;
1214 my @tempalias = split ( /\,/ , $_ );
1215 if ( $tempalias [ 1 ] eq 'on' ) {
1216 if (& General
:: IpInSubnet
( $tempalias [ 0 ] ,
1217 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1218 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire alias entry $tempalias [0]" ;
1223 if ( $errormessage ne '' ){
1224 goto SETTINGS_ERROR
;
1226 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
1227 $errormessage = $Lang :: tr
{ 'invalid input' };
1228 goto SETTINGS_ERROR
;
1230 if (( length ( $cgiparams { 'DMTU' })== 0 ) || (( $cgiparams { 'DMTU' }) < 1000 )) {
1231 $errormessage = $Lang :: tr
{ 'invalid mtu input' };
1232 goto SETTINGS_ERROR
;
1235 unless (& General
:: validport
( $cgiparams { 'DDEST_PORT' })) {
1236 $errormessage = $Lang :: tr
{ 'invalid port' };
1237 goto SETTINGS_ERROR
;
1239 $vpnsettings { 'ENABLED_BLUE' } = $cgiparams { 'ENABLED_BLUE' };
1240 $vpnsettings { 'ENABLED_ORANGE' } = $cgiparams { 'ENABLED_ORANGE' };
1241 $vpnsettings { 'ENABLED' } = $cgiparams { 'ENABLED' };
1242 $vpnsettings { 'VPN_IP' } = $cgiparams { 'VPN_IP' };
1243 #new settings for daemon
1244 $vpnsettings { 'DOVPN_SUBNET' } = $cgiparams { 'DOVPN_SUBNET' };
1245 $vpnsettings { 'DDEVICE' } = $cgiparams { 'DDEVICE' };
1246 $vpnsettings { 'DPROTOCOL' } = $cgiparams { 'DPROTOCOL' };
1247 $vpnsettings { 'DDEST_PORT' } = $cgiparams { 'DDEST_PORT' };
1248 $vpnsettings { 'DMTU' } = $cgiparams { 'DMTU' };
1249 $vpnsettings { 'DCOMPLZO' } = $cgiparams { 'DCOMPLZO' };
1250 $vpnsettings { 'DCIPHER' } = $cgiparams { 'DCIPHER' };
1253 if ( $vpnsettings { 'ENABLED_BLUE' } eq 'on' ) { system ( "touch ${General::swroot}/ovpn/enable_blue 2>/dev/null" );} else { system ( "unlink ${General::swroot}/ovpn/enable_blue 2>/dev/null" );}
1254 if ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' ) { system ( "touch ${General::swroot}/ovpn/enable_orange 2>/dev/null" );} else { system ( "unlink ${General::swroot}/ovpn/enable_orange 2>/dev/null" );}
1255 if ( $vpnsettings { 'ENABLED' } eq 'on' ) { system ( "touch ${General::swroot}/ovpn/enable 2>/dev/null" );} else { system ( "unlink ${General::swroot}/ovpn/enable 2>/dev/null" );}
1256 #new settings for daemon
1257 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1258 & writeserverconf
(); #hier ok
1261 ### Reset all step 2
1263 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'reset' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
1265 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1267 foreach my $key ( keys %confighash ) {
1268 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
1269 delete $confighash { $cgiparams { ' $key ' }};
1272 while ( $file = glob ( "${General::swroot}/ovpn/ca/*" )) {
1275 while ( $file = glob ( "${General::swroot}/ovpn/certs/*" )) {
1278 while ( $file = glob ( "${General::swroot}/ovpn/crls/*" )) {
1281 & cleanssldatabase
();
1282 if ( open ( FILE
, ">${General::swroot}/ovpn/caconfig" )) {
1286 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1287 #&writeserverconf();
1289 ### Reset all step 1
1291 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'reset' }) {
1292 & Header
:: showhttpheaders
();
1293 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1294 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1295 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'are you sure' });
1297 <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' />
1298 <tr><td align='center'>
1299 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1300 $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}
1301 <tr><td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'reset'}' />
1302 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td></tr>
1306 & Header
:: closebox
();
1307 & Header
:: closebigbox
();
1308 & Header
:: closepage
();
1312 ### Upload CA Certificate
1314 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
1315 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1317 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
1318 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
1319 goto UPLOADCA_ERROR
;
1322 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
1323 $errormessage = $Lang :: tr
{ 'name too long' };
1327 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
1328 $errormessage = $Lang :: tr
{ 'name is invalid' };
1329 goto UPLOAD_CA_ERROR
;
1332 # Check if there is no other entry with this name
1333 foreach my $key ( keys %cahash ) {
1334 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
1335 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
1336 goto UPLOADCA_ERROR
;
1340 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1341 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1342 goto UPLOADCA_ERROR
;
1344 # Move uploaded ca to a temporary file
1345 ( my $fh , my $filename ) = tempfile
( );
1346 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1348 goto UPLOADCA_ERROR
;
1350 my $temp = `/usr/bin/openssl x509 -text -in $filename ` ;
1351 if ( $temp !~ /CA:TRUE/i ) {
1352 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
1354 goto UPLOADCA_ERROR
;
1356 move
( $filename , "${General::swroot}/ovpn/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1358 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1360 goto UPLOADCA_ERROR
;
1364 my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/ $cgiparams {'CA_NAME'}cert.pem` ;
1365 $casubject =~ /Subject: (.*)[\n]/ ;
1367 $casubject =~ s
+/ Email
+, E
+;
1368 $casubject =~ s/ ST=/ S=/ ;
1369 $casubject = & Header
:: cleanhtml
( $casubject );
1371 my $key = & General
:: findhasharraykey
( \
%cahash );
1372 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
1373 $cahash { $key }[ 1 ] = $casubject ;
1374 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1375 # system('/usr/local/bin/ipsecctrl', 'R');
1380 ### Display ca certificate
1382 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
1383 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1385 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1386 & Header
:: showhttpheaders
();
1387 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1388 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
1389 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'ca certificate'}:" );
1390 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
1391 $output = & Header
:: cleanhtml
( $output , "y" );
1392 print "<pre> $output </pre> \n " ;
1393 & Header
:: closebox
();
1394 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1395 & Header
:: closebigbox
();
1396 & Header
:: closepage
();
1399 $errormessage = $Lang :: tr
{ 'invalid key' };
1403 ### Download ca certificate
1405 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
1406 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1408 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1409 print "Content-Type: application/octet-stream \r\n " ;
1410 print "Content-Disposition: filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
1411 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
1414 $errormessage = $Lang :: tr
{ 'invalid key' };
1418 ### Remove ca certificate (step 2)
1420 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
1421 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1422 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1424 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1425 foreach my $key ( keys %confighash ) {
1426 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/ovpn/certs/ $confighash { $key }[1]cert.pem` ;
1427 if ( $test =~ /: OK/ ) {
1429 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1430 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
1431 # system('/usr/local/bin/ipsecctrl', 'D', $key);
1433 unlink ( "${General::swroot}/ovpn//certs/ $confighash { $key }[1]cert.pem" );
1434 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $key }[1].p12" );
1435 delete $confighash { $key };
1436 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1437 # &writeipsecfiles();
1440 unlink ( "${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
1441 delete $cahash { $cgiparams { 'KEY' }};
1442 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1443 # system('/usr/local/bin/ipsecctrl', 'R');
1445 $errormessage = $Lang :: tr
{ 'invalid key' };
1448 ### Remove ca certificate (step 1)
1450 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
1451 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1452 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1454 my $assignedcerts = 0 ;
1455 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1456 foreach my $key ( keys %confighash ) {
1457 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/ovpn/certs/ $confighash { $key }[1]cert.pem` ;
1458 if ( $test =~ /: OK/ ) {
1462 if ( $assignedcerts ) {
1463 & Header
:: showhttpheaders
();
1464 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1465 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
1466 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'are you sure' });
1468 <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' />
1469 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
1470 <tr><td align='center'>
1471 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>: $assignedcerts
1472 $Lang ::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}
1473 <tr><td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
1474 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td></tr>
1478 & Header
:: closebox
();
1479 & Header
:: closebigbox
();
1480 & Header
:: closepage
();
1483 unlink ( "${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
1484 delete $cahash { $cgiparams { 'KEY' }};
1485 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1486 # system('/usr/local/bin/ipsecctrl', 'R');
1489 $errormessage = $Lang :: tr
{ 'invalid key' };
1493 ### Display root certificate
1495 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
1496 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
1498 & Header
:: showhttpheaders
();
1499 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1500 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1501 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
1502 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'root certificate'}:" );
1503 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem` ;
1505 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'host certificate'}:" );
1506 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem` ;
1508 $output = & Header
:: cleanhtml
( $output , "y" );
1509 print "<pre> $output </pre> \n " ;
1510 & Header
:: closebox
();
1511 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1512 & Header
:: closebigbox
();
1513 & Header
:: closepage
();
1517 ### Download root certificate
1519 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
1520 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
1521 print "Content-Type: application/octet-stream \r\n " ;
1522 print "Content-Disposition: filename=cacert.pem \r\n\r\n " ;
1523 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/cacert.pem` ;
1528 ### Download host certificate
1530 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
1531 if ( - f
"${General::swroot}/ovpn/certs/servercert.pem" ) {
1532 print "Content-Type: application/octet-stream \r\n " ;
1533 print "Content-Disposition: filename=servercert.pem \r\n\r\n " ;
1534 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/certs/servercert.pem` ;
1538 ### Form for generating a root certificate
1540 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
1541 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
1543 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1544 if (- f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
1545 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
1546 $cgiparams { 'ACTION' } = '' ;
1547 goto ROOTCERT_ERROR
;
1550 if (( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) && - e
"${General::swroot}/red/active" ) {
1551 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
1552 my $ipaddr = < IPADDR
>;
1555 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
1556 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
1557 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
1560 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
1562 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1563 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1564 goto ROOTCERT_ERROR
;
1567 # Move uploaded certificate request to a temporary file
1568 ( my $fh , my $filename ) = tempfile
( );
1569 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1571 goto ROOTCERT_ERROR
;
1574 # Create a temporary dirctory
1575 my $tempdir = tempdir
( CLEANUP
=> 1 );
1577 # Extract the CA certificate from the file
1578 my $pid = open ( OPENSSL
, "|-" );
1579 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1580 if ( $pid ) { # parent
1581 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1582 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1586 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1588 goto ROOTCERT_ERROR
;
1591 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-cacerts' , '-nokeys' ,
1593 '-out' , " $tempdir /cacert.pem" )) {
1594 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1596 goto ROOTCERT_ERROR
;
1600 # Extract the Host certificate from the file
1601 $pid = open ( OPENSSL
, "|-" );
1602 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1603 if ( $pid ) { # parent
1604 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1605 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1609 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1611 goto ROOTCERT_ERROR
;
1614 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-clcerts' , '-nokeys' ,
1616 '-out' , " $tempdir /hostcert.pem" )) {
1617 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1619 goto ROOTCERT_ERROR
;
1623 # Extract the Host key from the file
1624 $pid = open ( OPENSSL
, "|-" );
1625 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1626 if ( $pid ) { # parent
1627 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1628 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1632 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1634 goto ROOTCERT_ERROR
;
1637 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-nocerts' ,
1640 '-out' , " $tempdir /serverkey.pem" )) {
1641 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1643 goto ROOTCERT_ERROR
;
1647 move
( " $tempdir /cacert.pem" , "${General::swroot}/ovpn/ca/cacert.pem" );
1649 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1651 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1652 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1653 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1654 goto ROOTCERT_ERROR
;
1657 move
( " $tempdir /hostcert.pem" , "${General::swroot}/ovpn/certs/servercert.pem" );
1659 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1661 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1662 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1663 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1664 goto ROOTCERT_ERROR
;
1667 move
( " $tempdir /serverkey.pem" , "${General::swroot}/ovpn/certs/serverkey.pem" );
1669 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1671 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1672 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1673 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1674 goto ROOTCERT_ERROR
;
1677 goto ROOTCERT_SUCCESS
;
1679 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
1681 # Validate input since the form was submitted
1682 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
1683 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
1684 goto ROOTCERT_ERROR
;
1686 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
1687 $errormessage = $Lang :: tr
{ 'organization too long' };
1688 goto ROOTCERT_ERROR
;
1690 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1691 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1692 goto ROOTCERT_ERROR
;
1694 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
1695 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
1696 goto ROOTCERT_ERROR
;
1698 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
1699 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
1700 goto ROOTCERT_ERROR
;
1702 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
1703 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1704 goto ROOTCERT_ERROR
;
1706 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
1707 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1708 goto ROOTCERT_ERROR
;
1710 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1711 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1712 goto ROOTCERT_ERROR
;
1714 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1715 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1716 goto ROOTCERT_ERROR
;
1718 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1719 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1720 goto ROOTCERT_ERROR
;
1722 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1723 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1724 goto ROOTCERT_ERROR
;
1727 # Copy the cgisettings to vpnsettings and save the configfile
1728 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
1729 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
1730 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
1731 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
1732 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
1733 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
1734 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
1735 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1737 # Replace empty strings with a .
1738 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
1739 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
1740 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
1743 #system ('/bin/touch', "${General::swroot}/ovpn/gencanow");
1745 # Create the CA certificate
1746 my $pid = open ( OPENSSL
, "|-" );
1747 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1748 if ( $pid ) { # parent
1749 print OPENSSL
" $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1750 print OPENSSL
" $state \n " ;
1751 print OPENSSL
" $city \n " ;
1752 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1753 print OPENSSL
" $ou \n " ;
1754 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
1755 print OPENSSL
" $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1758 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1759 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1760 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1761 goto ROOTCERT_ERROR
;
1764 unless ( exec ( '/usr/bin/openssl' , 'req' , '-x509' , '-nodes' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
1765 '-days' , '999999' , '-newkey' , 'rsa:2048' ,
1766 '-keyout' , "${General::swroot}/ovpn/ca/cakey.pem" ,
1767 '-out' , "${General::swroot}/ovpn/ca/cacert.pem" ,
1768 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
1769 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1770 goto ROOTCERT_ERROR
;
1774 # Create the Host certificate request
1775 $pid = open ( OPENSSL
, "|-" );
1776 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1777 if ( $pid ) { # parent
1778 print OPENSSL
" $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1779 print OPENSSL
" $state \n " ;
1780 print OPENSSL
" $city \n " ;
1781 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1782 print OPENSSL
" $ou \n " ;
1783 print OPENSSL
" $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
1784 print OPENSSL
" $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1785 print OPENSSL
". \n " ;
1786 print OPENSSL
". \n " ;
1789 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1790 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1791 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1792 goto ROOTCERT_ERROR
;
1795 unless ( exec ( '/usr/bin/openssl' , 'req' , '-nodes' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
1796 '-newkey' , 'rsa:1024' ,
1797 '-keyout' , "${General::swroot}/ovpn/certs/serverkey.pem" ,
1798 '-out' , "${General::swroot}/ovpn/certs/serverreq.pem" ,
1799 '-extensions' , 'server' ,
1800 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
1801 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1802 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1803 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1804 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1805 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1806 goto ROOTCERT_ERROR
;
1810 # Sign the host certificate request
1811 system ( '/usr/bin/openssl' , 'ca' , '-days' , '999999' ,
1812 '-batch' , '-notext' ,
1813 '-in' , "${General::swroot}/ovpn/certs/serverreq.pem" ,
1814 '-out' , "${General::swroot}/ovpn/certs/servercert.pem" ,
1815 '-extensions' , 'server' ,
1816 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
1818 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1819 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1820 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1821 unlink ( "${General::swroot}/ovpn/serverkey.pem" );
1822 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1823 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1824 & newcleanssldatabase
();
1825 goto ROOTCERT_ERROR
;
1827 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1828 & deletebackupcert
();
1831 # Create an empty CRL
1832 system ( '/usr/bin/openssl' , 'ca' , '-gencrl' ,
1833 '-out' , "${General::swroot}/ovpn/crls/cacrl.pem" ,
1834 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
1836 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1837 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1838 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1839 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1840 unlink ( "${General::swroot}/ovpn/crls/cacrl.pem" );
1841 & cleanssldatabase
();
1842 goto ROOTCERT_ERROR
;
1844 # &cleanssldatabase();
1846 # Create Diffie Hellmann Parameter
1847 system ( '/usr/bin/openssl' , 'dhparam' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
1848 '-out' , "${General::swroot}/ovpn/ca/dh1024.pem" ,
1851 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1852 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1853 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1854 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1855 unlink ( "${General::swroot}/ovpn/crls/cacrl.pem" );
1856 unlink ( "${General::swroot}/ovpn/ca/dh1024.pem" );
1857 & cleanssldatabase
();
1858 goto ROOTCERT_ERROR
;
1860 # &cleanssldatabase();
1862 goto ROOTCERT_SUCCESS
;
1865 if ( $cgiparams { 'ACTION' } ne '' ) {
1866 & Header
:: showhttpheaders
();
1867 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1868 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1869 if ( $errormessage ) {
1870 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
1871 print "<class name='base'> $errormessage " ;
1872 print " </class>" ;
1873 & Header
:: closebox
();
1875 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'generate root/host certificates'}:" );
1877 <form method='post' enctype='multipart/form-data'>
1878 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1879 <tr><td width='30%' class='base'> $Lang ::tr{'organization name'}:</td>
1880 <td width='35%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td>
1881 <td width='35%' colspan='2'> </td></tr>
1882 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}:</td>
1883 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td>
1884 <td colspan='2'> </td></tr>
1885 <tr><td class='base'> $Lang ::tr{'your e-mail'}: <img src='/blob.gif' alt'*' /></td>
1886 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td>
1887 <td colspan='2'> </td></tr>
1888 <tr><td class='base'> $Lang ::tr{'your department'}: <img src='/blob.gif' alt'*' /></td>
1889 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td>
1890 <td colspan='2'> </td></tr>
1891 <tr><td class='base'> $Lang ::tr{'city'}: <img src='/blob.gif' alt'*' /></td>
1892 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td>
1893 <td colspan='2'> </td></tr>
1894 <tr><td class='base'> $Lang ::tr{'state or province'}: <img src='/blob.gif' alt'*' /></td>
1895 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td>
1896 <td colspan='2'> </td></tr>
1897 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1898 <td class='base'><select name='ROOTCERT_COUNTRY'>
1902 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1903 print "<option value=' $Countries ::countries{ $country }'" ;
1904 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1905 print " selected='selected'" ;
1907 print "> $country </option>" ;
1911 <td colspan='2'> </td></tr>
1913 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /></td>
1914 <td> </td><td> </td></tr>
1915 <tr><td class='base' colspan='4' align='left'>
1916 <img src='/blob.gif' valign='top' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
1917 <tr><td class='base' colspan='4' align='left'>
1918 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1919 $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'}
1921 <tr><td colspan='4' bgcolor='#000000'><img src='/images/null.gif' width='1' height='1' border='0' /></td></tr>
1922 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}:</td>
1923 <td nowrap='nowrap'><input type='file' name='FH' size='32'></td>
1924 <td colspan='2'> </td></tr>
1925 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' ></td>
1926 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td>
1927 <td colspan='2'> </td></tr>
1929 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td>
1930 <td colspan='2'> </td></tr>
1931 <tr><td class='base' colspan='4' align='left'>
1932 <img src='/blob.gif' valign='top' al='*' > $Lang ::tr{'this field may be blank'}</td></tr>
1936 & Header
:: closebox
();
1938 & Header
:: closebigbox
();
1939 & Header
:: closepage
();
1944 system ( "chmod 600 ${General::swroot}/ovpn/certs/serverkey.pem" );
1945 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1946 # $vpnsettings{'ENABLE_BLUE'} eq 'on') {
1947 # system('/usr/local/bin/ipsecctrl', 'S');
1951 ### Enable/Disable connection
1958 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1960 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1961 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1962 # my $n2nactive = '';
1963 my $n2nactive = `/bin/ps ax|grep $confighash { $cgiparams {'KEY'}}[1]|grep -v grep|awk \' {print \ $1 } \' ` ;
1965 if ( $confighash { $cgiparams { 'KEY' }}) {
1966 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
1967 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
1968 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1970 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
1971 system ( '/usr/local/bin/openvpnctrl' , '-sn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
1975 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
1976 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1978 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
1979 if ( $n2nactive ne '' ){
1980 system ( '/usr/local/bin/openvpnctrl' , '-kn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
1984 $errormessage = $Lang :: tr
{ 'invalid key' };
1990 ### Download OpenVPN client package
1994 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'dl client arch' }) {
1995 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1996 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1998 my $clientovpn = '' ;
2000 my $tempdir = tempdir
( CLEANUP
=> 1 );
2001 my $zippath = " $tempdir /" ;
2007 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
2009 my $zipname = " $confighash { $cgiparams {'KEY'}}[1]-Client.zip" ;
2010 my $zippathname = " $zippath $zipname " ;
2011 $clientovpn = " $confighash { $cgiparams {'KEY'}}[1].conf" ;
2012 my @ovsubnettemp = split ( /\./ , $confighash { $cgiparams { 'KEY' }}[ 27 ]);
2013 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
2015 my @remsubnet = split ( /\/ /, $confighash { $cgiparams { 'KEY' }}[ 8 ]);
2016 my $n2nfragment = '' ;
2018 open ( CLIENTCONF
, "> $tempdir / $clientovpn " ) or die "Unable to open tempfile: $!" ;
2019 flock CLIENTCONF
, 2 ;
2021 my $zip = Archive
:: Zip
-> new ();
2022 print CLIENTCONF
"# IPFire n2n Open VPN Client Config by ummeegge und m.a.d \n " ;
2023 print CLIENTCONF
"# \n " ;
2024 print CLIENTCONF
"# User Security \n " ;
2025 print CLIENTCONF
"user nobody \n " ;
2026 print CLIENTCONF
"group nobody \n " ;
2027 print CLIENTCONF
"persist-tun \n " ;
2028 print CLIENTCONF
"persist-key \n " ;
2029 print CLIENTCONF
"script-security 2 \n " ;
2030 print CLIENTCONF
"# IP/DNS for remote Server Gateway \n " ;
2031 print CLIENTCONF
"remote $vpnsettings {'VPN_IP'} \n " ;
2032 print CLIENTCONF
"float \n " ;
2033 print CLIENTCONF
"# IP adresses of the VPN Subnet \n " ;
2034 print CLIENTCONF
"ifconfig $ovsubnet .2 $ovsubnet .1 \n " ;
2035 print CLIENTCONF
"# Server Gateway Network \n " ;
2036 print CLIENTCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
2037 print CLIENTCONF
"# tun Device \n " ;
2038 print CLIENTCONF
"dev $vpnsettings {'DDEVICE'} \n " ;
2039 print CLIENTCONF
"# Port and Protokoll \n " ;
2040 print CLIENTCONF
"port $confighash { $cgiparams {'KEY'}}[29] \n " ;
2042 if ( $confighash { $cgiparams { 'KEY' }}[ 28 ] eq 'tcp' ) {
2043 print CLIENTCONF
"proto tcp-client \n " ;
2044 print CLIENTCONF
"# Packet size \n " ;
2045 if ( $confighash { $cgiparams { 'KEY' }}[ 31 ] eq '' ) { $tunmtu = '1400' } else { $tunmtu = $confighash { $cgiparams { 'KEY' }}[ 31 ]};
2046 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
2049 if ( $confighash { $cgiparams { 'KEY' }}[ 28 ] eq 'udp' ) {
2050 print CLIENTCONF
"proto udp \n " ;
2051 print CLIENTCONF
"# Paketsize \n " ;
2052 if ( $confighash { $cgiparams { 'KEY' }}[ 31 ] eq '' ) { $tunmtu = '1500' } else { $tunmtu = $confighash { $cgiparams { 'KEY' }}[ 31 ]};
2053 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
2054 if ( $confighash { $cgiparams { 'KEY' }}[ 24 ] ne '' ) { print CLIENTCONF
"fragment $confighash { $cgiparams {'KEY'}}[24] \n " ;}
2055 if ( $confighash { $cgiparams { 'KEY' }}[ 23 ] eq 'on' ) { print CLIENTCONF
"mssfix \n " ;}
2057 if (( $confighash { $cgiparams { 'KEY' }}[ 38 ] eq 'yes' ) ||
2058 ( $confighash { $cgiparams { 'KEY' }}[ 38 ] eq 'maybe' ) ||
2059 ( $confighash { $cgiparams { 'KEY' }}[ 38 ] eq 'no' )) {
2060 if (( $confighash { $cgiparams { 'KEY' }}[ 23 ] ne 'on' ) || ( $confighash { $cgiparams { 'KEY' }}[ 24 ] eq '' )) {
2061 if ( $tunmtu eq '1500' ) {
2062 print CLIENTCONF
"mtu-disc $confighash { $cgiparams {'KEY'}}[38] \n " ;
2066 print CLIENTCONF
"ns-cert-type server \n " ;
2067 print CLIENTCONF
"# Auth. Client \n " ;
2068 print CLIENTCONF
"tls-client \n " ;
2069 print CLIENTCONF
"# Cipher \n " ;
2070 print CLIENTCONF
"cipher AES-256-CBC \n " ;
2071 if ( $confighash { $cgiparams { 'KEY' }}[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ) {
2072 print CLIENTCONF
"pkcs12 ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12 \r\n " ;
2073 $zip -> addFile ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" , " $confighash { $cgiparams {'KEY'}}[1].p12" ) or die "Can't add file $confighash { $cgiparams {'KEY'}}[1].p12 \n " ;
2075 if ( $confighash { $cgiparams { 'KEY' }}[ 30 ] eq 'on' ) {
2076 print CLIENTCONF
"# Enable Compression \n " ;
2077 print CLIENTCONF
"comp-lzo \r\n " ;
2079 print CLIENTCONF
"# Debug Level \n " ;
2080 print CLIENTCONF
"verb 3 \n " ;
2081 print CLIENTCONF
"# Tunnel check \n " ;
2082 print CLIENTCONF
"keepalive 10 60 \n " ;
2083 print CLIENTCONF
"# Start as daemon \n " ;
2084 print CLIENTCONF
"daemon $confighash { $cgiparams {'KEY'}}[1]n2n \n " ;
2085 print CLIENTCONF
"writepid /var/run/ $confighash { $cgiparams {'KEY'}}[1]n2n.pid \n " ;
2086 print CLIENTCONF
"# Activate Management Interface and Port \n " ;
2087 if ( $confighash { $cgiparams { 'KEY' }}[ 22 ] eq '' ) { print CLIENTCONF
"management localhost $confighash { $cgiparams {'KEY'}}[29] \n " }
2088 else { print CLIENTCONF
"management localhost $confighash { $cgiparams {'KEY'}}[22] \n " };
2089 print CLIENTCONF
"# remsub $confighash { $cgiparams {'KEY'}}[11] \n " ;
2094 $zip -> addFile ( " $tempdir / $clientovpn " , $clientovpn ) or die "Can't add file $clientovpn \n " ;
2095 my $status = $zip -> writeToFileNamed ( $zippathname );
2097 open ( DLFILE
, "< $zippathname " ) or die "Unable to open $zippathname : $!" ;
2098 @fileholder = < DLFILE
>;
2099 print "Content-Type:application/x-download \n " ;
2100 print "Content-Disposition:attachment;filename= $zipname \n\n " ;
2106 my $zipname = " $confighash { $cgiparams {'KEY'}}[1]-TO-IPFire.zip" ;
2107 my $zippathname = " $zippath $zipname " ;
2108 $clientovpn = " $confighash { $cgiparams {'KEY'}}[1]-TO-IPFire.ovpn" ;
2114 open ( CLIENTCONF
, "> $tempdir / $clientovpn " ) or die "Unable to open tempfile: $!" ;
2115 flock CLIENTCONF
, 2 ;
2117 my $zip = Archive
:: Zip
-> new ();
2119 print CLIENTCONF
"#OpenVPN Client conf \r\n " ;
2120 print CLIENTCONF
"tls-client \r\n " ;
2121 print CLIENTCONF
"client \r\n " ;
2122 print CLIENTCONF
"nobind \n " ;
2123 print CLIENTCONF
"dev $vpnsettings {'DDEVICE'} \r\n " ;
2124 print CLIENTCONF
"proto $vpnsettings {'DPROTOCOL'} \r\n " ;
2126 # Check if we are using fragment, mssfix or mtu-disc and set MTU to 1500
2127 # or use configured value.
2128 if ( $vpnsettings { FRAGMENT
} ne '' && $vpnsettings { DPROTOCOL
} ne 'tcp' )
2129 { print CLIENTCONF
" $vpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
2130 elsif ( $vpnsettings { MSSFIX
} eq 'on' )
2131 { print CLIENTCONF
" $vpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
2132 elsif (( $vpnsettings { 'PMTU_DISCOVERY' } eq 'yes' ) ||
2133 ( $vpnsettings { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
2134 ( $vpnsettings { 'PMTU_DISCOVERY' } eq 'no' ))
2135 { print CLIENTCONF
" $vpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
2137 { print CLIENTCONF
" $vpnsettings {'DDEVICE'}-mtu $vpnsettings {'DMTU'} \r\n " ; }
2139 if ( $vpnsettings { 'ENABLED' } eq 'on' ){
2140 print CLIENTCONF
"remote $vpnsettings {'VPN_IP'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2141 if ( $vpnsettings { 'ENABLED_BLUE' } eq 'on' && (& haveBlueNet
())){
2142 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Blue interface \r\n " ;
2143 print CLIENTCONF
";remote $netsettings {'BLUE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2145 if ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
2146 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Orange interface \r\n " ;
2147 print CLIENTCONF
";remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2149 } elsif ( $vpnsettings { 'ENABLED_BLUE' } eq 'on' && (& haveBlueNet
())){
2150 print CLIENTCONF
"remote $netsettings {'BLUE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2151 if ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
2152 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Orange interface \r\n " ;
2153 print CLIENTCONF
";remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2155 } elsif ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
2156 print CLIENTCONF
"remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2159 if ( $confighash { $cgiparams { 'KEY' }}[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ) {
2160 print CLIENTCONF
"pkcs12 $confighash { $cgiparams {'KEY'}}[1].p12 \r\n " ;
2161 $zip -> addFile ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" , " $confighash { $cgiparams {'KEY'}}[1].p12" ) or die "Can't add file $confighash { $cgiparams {'KEY'}}[1].p12 \n " ;
2163 print CLIENTCONF
"ca cacert.pem \r\n " ;
2164 print CLIENTCONF
"cert $confighash { $cgiparams {'KEY'}}[1]cert.pem \r\n " ;
2165 print CLIENTCONF
"key $confighash { $cgiparams {'KEY'}}[1].key \r\n " ;
2166 $zip -> addFile ( "${General::swroot}/ovpn/ca/cacert.pem" , "cacert.pem" ) or die "Can't add file cacert.pem \n " ;
2167 $zip -> addFile ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" , " $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) or die "Can't add file $confighash { $cgiparams {'KEY'}}[1]cert.pem \n " ;
2169 print CLIENTCONF
"cipher $vpnsettings {DCIPHER} \r\n " ;
2170 if ( $vpnsettings { DCOMPLZO
} eq 'on' ) {
2171 print CLIENTCONF
"comp-lzo \r\n " ;
2173 print CLIENTCONF
"verb 3 \r\n " ;
2174 print CLIENTCONF
"ns-cert-type server \r\n " ;
2175 print CLIENTCONF
"tls-remote $vpnsettings {ROOTCERT_HOSTNAME} \r\n " ;
2176 if ( $vpnsettings { MSSFIX
} eq 'on' ) {
2177 print CLIENTCONF
"mssfix \r\n " ;
2179 if ( $vpnsettings { FRAGMENT
} ne '' && $vpnsettings { DPROTOCOL
} ne 'tcp' ) {
2180 print CLIENTCONF
"fragment $vpnsettings {'FRAGMENT'} \r\n " ;
2183 # Check if a valid operating mode has been choosen and use it.
2184 if (( $vpnsettings { 'PMTU_DISCOVERY' } eq 'yes' ) ||
2185 ( $vpnsettings { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
2186 ( $vpnsettings { 'PMTU_DISCOVERY' } eq 'no' )) {
2187 if (( $vpnsettings { MSSFIX
} ne 'on' ) || ( $vpnsettings { FRAGMENT
} eq '' )) {
2188 print CLIENTCONF
"mtu-disc $vpnsettings {'PMTU_DISCOVERY'} \n " ;
2193 $zip -> addFile ( " $tempdir / $clientovpn " , $clientovpn ) or die "Can't add file $clientovpn \n " ;
2194 my $status = $zip -> writeToFileNamed ( $zippathname );
2196 open ( DLFILE
, "< $zippathname " ) or die "Unable to open $zippathname : $!" ;
2197 @fileholder = < DLFILE
>;
2198 print "Content-Type:application/x-download \n " ;
2199 print "Content-Disposition:attachment;filename= $zipname \n\n " ;
2207 ### Remove connection
2211 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
2212 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2213 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2215 if ( $confighash { $cgiparams { 'KEY' }}) {
2216 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2217 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2218 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
2221 my $temp = `/usr/bin/openssl ca -revoke ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf` ;
2227 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ) {
2229 my $conffile = glob ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]/ $confighash { $cgiparams {'KEY'}}[1].conf" );
2230 my $certfile = glob ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
2231 unlink ( $certfile ) or die "Removing $certfile fail: $!" ;
2232 unlink ( $conffile ) or die "Removing $conffile fail: $!" ;
2233 rmdir ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]" ) || die "Kann Verzeichnis nicht loeschen: $!" ;
2237 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
2238 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
2240 # A.Marx CCD delete ccd files and routes
2243 if (- f
"${General::swroot}/ovpn/ccd/ $confighash { $cgiparams {'KEY'}}[2]" )
2245 unlink "${General::swroot}/ovpn/ccd/ $confighash { $cgiparams {'KEY'}}[2]" ;
2248 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
2249 foreach my $key ( keys %ccdroutehash ) {
2250 if ( $ccdroutehash { $key }[ 0 ] eq $confighash { $cgiparams { 'KEY' }}[ 1 ]){
2251 delete $ccdroutehash { $key };
2254 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
2256 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
2257 foreach my $key ( keys %ccdroute2hash ) {
2258 if ( $ccdroute2hash { $key }[ 0 ] eq $confighash { $cgiparams { 'KEY' }}[ 1 ]){
2259 delete $ccdroute2hash { $key };
2262 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
2269 delete $confighash { $cgiparams { 'KEY' }};
2270 my $temp2 = `/usr/bin/openssl ca -gencrl -out ${General::swroot}/ovpn/crls/cacrl.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf` ;
2271 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2273 #&writeserverconf();
2275 $errormessage = $Lang :: tr
{ 'invalid key' };
2280 ### Download PKCS12 file
2282 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
2283 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2285 print "Content-Disposition: filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
2286 print "Content-Type: application/octet-stream \r\n\r\n " ;
2287 print `/bin/cat ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12` ;
2291 ### Display certificate
2293 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
2294 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2296 if ( - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
2297 & Header
:: showhttpheaders
();
2298 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
2299 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2300 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'certificate'}:" );
2301 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
2302 $output = & Header
:: cleanhtml
( $output , "y" );
2303 print "<pre> $output </pre> \n " ;
2304 & Header
:: closebox
();
2305 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2306 & Header
:: closebigbox
();
2307 & Header
:: closepage
();
2311 ### Display Certificate Revoke List
2313 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show crl' }) {
2314 # &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2316 if ( - f
"${General::swroot}/ovpn/crls/cacrl.pem" ) {
2317 & Header
:: showhttpheaders
();
2318 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
2319 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2320 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'crl'}:" );
2321 my $output = `/usr/bin/openssl crl -text -noout -in ${General::swroot}/ovpn/crls/cacrl.pem` ;
2322 $output = & Header
:: cleanhtml
( $output , "y" );
2323 print "<pre> $output </pre> \n " ;
2324 & Header
:: closebox
();
2325 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2326 & Header
:: closebigbox
();
2327 & Header
:: closepage
();
2332 ### Advanced Server Settings
2335 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced server' }) {
2340 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%cgiparams );
2344 # if ($cgiparams{'CLIENT2CLIENT'} eq '') {
2345 # $cgiparams{'CLIENT2CLIENT'} = 'on';
2348 if ( $cgiparams { 'MAX_CLIENTS' } eq '' ) {
2349 $cgiparams { 'MAX_CLIENTS' } = '100' ;
2351 if ( $cgiparams { 'KEEPALIVE_1' } eq '' ) {
2352 $cgiparams { 'KEEPALIVE_1' } = '10' ;
2354 if ( $cgiparams { 'KEEPALIVE_2' } eq '' ) {
2355 $cgiparams { 'KEEPALIVE_2' } = '60' ;
2357 if ( $cgiparams { 'LOG_VERB' } eq '' ) {
2358 $cgiparams { 'LOG_VERB' } = '3' ;
2360 $checked { 'CLIENT2CLIENT' }{ 'off' } = '' ;
2361 $checked { 'CLIENT2CLIENT' }{ 'on' } = '' ;
2362 $checked { 'CLIENT2CLIENT' }{ $cgiparams { 'CLIENT2CLIENT' }} = 'CHECKED' ;
2363 $checked { 'REDIRECT_GW_DEF1' }{ 'off' } = '' ;
2364 $checked { 'REDIRECT_GW_DEF1' }{ 'on' } = '' ;
2365 $checked { 'REDIRECT_GW_DEF1' }{ $cgiparams { 'REDIRECT_GW_DEF1' }} = 'CHECKED' ;
2366 $selected { 'ENGINES' }{ $cgiparams { 'ENGINES' }} = 'SELECTED' ;
2367 $checked { 'MSSFIX' }{ 'off' } = '' ;
2368 $checked { 'MSSFIX' }{ 'on' } = '' ;
2369 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
2370 $checked { 'PMTU_DISCOVERY' }{ $cgiparams { 'PMTU_DISCOVERY' }} = 'checked= \' checked \' ' ;
2371 $selected { 'LOG_VERB' }{ '1' } = '' ;
2372 $selected { 'LOG_VERB' }{ '2' } = '' ;
2373 $selected { 'LOG_VERB' }{ '3' } = '' ;
2374 $selected { 'LOG_VERB' }{ '4' } = '' ;
2375 $selected { 'LOG_VERB' }{ '5' } = '' ;
2376 $selected { 'LOG_VERB' }{ '6' } = '' ;
2377 $selected { 'LOG_VERB' }{ '7' } = '' ;
2378 $selected { 'LOG_VERB' }{ '8' } = '' ;
2379 $selected { 'LOG_VERB' }{ '9' } = '' ;
2380 $selected { 'LOG_VERB' }{ '10' } = '' ;
2381 $selected { 'LOG_VERB' }{ '11' } = '' ;
2382 $selected { 'LOG_VERB' }{ '0' } = '' ;
2383 $selected { 'LOG_VERB' }{ $cgiparams { 'LOG_VERB' }} = 'SELECTED' ;
2385 & Header
:: showhttpheaders
();
2386 & Header
:: openpage
( $Lang :: tr
{ 'status ovpn' }, 1 , '' );
2387 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
2388 if ( $errormessage ) {
2389 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
2390 print "<class name='base'> $errormessage \n " ;
2391 print " </class> \n " ;
2392 & Header
:: closebox
();
2394 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'advanced server' });
2396 <form method='post' enctype='multipart/form-data' disabled>
2397 <table width='100%' border=0>
2399 <td colspan='4'><b> $Lang ::tr{'dhcp-options'}</b></td>
2402 <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
2405 <td class='base'>Domain</td>
2406 <td><input type='TEXT' name='DHCP_DOMAIN' value=' $cgiparams {'DHCP_DOMAIN'}' size='30' /></td>
2409 <td class='base'>DNS</td>
2410 <td><input type='TEXT' name='DHCP_DNS' value=' $cgiparams {'DHCP_DNS'}' size='30' /></td>
2413 <td class='base'>WINS</td>
2414 <td><input type='TEXT' name='DHCP_WINS' value=' $cgiparams {'DHCP_WINS'}' size='30' /></td>
2417 <td colspan='4'><b> $Lang ::tr{'ovpn routes push options'}</b></td>
2420 <td class='base'> $Lang ::tr{'ovpn routes push'}</td>
2422 <textarea name='ROUTES_PUSH' cols='26' rows='6' wrap='off'>
2426 if ( $cgiparams { 'ROUTES_PUSH' } ne '' )
2428 print $cgiparams { 'ROUTES_PUSH' };
2437 <table width='100%'>
2439 <td class'base'><b> $Lang ::tr{'misc-options'}</b></td>
2442 <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='15%'></td><td width='35%'></td>
2445 <td class='base'>Client-To-Client</td>
2446 <td><input type='checkbox' name='CLIENT2CLIENT' $checked {'CLIENT2CLIENT'}{'on'} /></td>
2449 <td class='base'>Redirect-Gateway def1</td>
2450 <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked {'REDIRECT_GW_DEF1'}{'on'} /></td>
2453 <td class='base'>Max-Clients</td>
2454 <td><input type='text' name='MAX_CLIENTS' value=' $cgiparams {'MAX_CLIENTS'}' size='10' /></td>
2457 <td class='base'>Keppalive <br />
2458 (ping/ping-restart)</td>
2459 <td><input type='TEXT' name='KEEPALIVE_1' value=' $cgiparams {'KEEPALIVE_1'}' size='10' /></td>
2460 <td><input type='TEXT' name='KEEPALIVE_2' value=' $cgiparams {'KEEPALIVE_2'}' size='10' /></td>
2463 <td class='base'>fragment <br></td>
2464 <td><input type='TEXT' name='FRAGMENT' value=' $cgiparams {'FRAGMENT'}' size='10' /></td>
2465 <td>Default: <span class="base">1300</span></td>
2468 <td class='base'>mssfix</td>
2469 <td><input type='checkbox' name='MSSFIX' $checked {'MSSFIX'}{'on'} /></td>
2470 <td>Default: on</td>
2474 <td class='base'> $Lang ::tr{'ovpn mtu-disc'}</td>
2475 <td><input type='radio' name='PMTU_DISCOVERY' value='yes' $checked {'PMTU_DISCOVERY'}{'yes'} /> $Lang ::tr{'ovpn mtu-disc yes'}</td>
2476 <td><input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked {'PMTU_DISCOVERY'}{'maybe'} /> $Lang ::tr{'ovpn mtu-disc maybe'}</td>
2477 <td><input type='radio' name='PMTU_DISCOVERY' value='no' $checked {'PMTU_DISCOVERY'}{'no'} /> $Lang ::tr{'ovpn mtu-disc no'}</td>
2478 <td><input type='radio' name='PMTU_DISCOVERY' value='off' $checked {'PMTU_DISCOVERY'}{'off'} /> $Lang ::tr{'ovpn mtu-disc off'}</td>
2484 <table width='100%'>
2486 <td class'base'><b>Crypto-Engines</b></td>
2489 <td width='15%'></td> <td width='30%'> </td><td width='25%'> </td><td width='30%'></td>
2491 <tr><td class='base'>Engines:</td>
2492 <td><select name='ENGINES'><option value="none" $selected {'ENGINES'}{'none'}>none</option>
2493 <option value="cryptodev" $selected {'ENGINES'}{'cryptodev'}>cryptodev</option>
2494 <option value="padlock" $selected {'ENGINES'}{'padlock'}>padlock</option>
2500 <table width='100%'>
2502 <td class'base'><b> $Lang ::tr{'log-options'}</b></td>
2505 <td width='15%'></td> <td width='30%'> </td><td width='25%'> </td><td width='30%'></td>
2508 <tr><td class='base'>VERB</td>
2509 <td><select name='LOG_VERB'><option value='1' $selected {'LOG_VERB'}{'1'}>1</option>
2510 <option value='2' $selected {'LOG_VERB'}{'2'}>2</option>
2511 <option value='3' $selected {'LOG_VERB'}{'3'}>3</option>
2512 <option value='4' $selected {'LOG_VERB'}{'4'}>4</option>
2513 <option value='5' $selected {'LOG_VERB'}{'5'}>5</option>
2514 <option value='6' $selected {'LOG_VERB'}{'6'}>6</option>
2515 <option value='7' $selected {'LOG_VERB'}{'7'}>7</option>
2516 <option value='8' $selected {'LOG_VERB'}{'8'}>8</option>
2517 <option value='9' $selected {'LOG_VERB'}{'9'}>9</option>
2518 <option value='10' $selected {'LOG_VERB'}{'10'}>10</option>
2519 <option value='11' $selected {'LOG_VERB'}{'11'}>11</option>
2520 <option value='0' $selected {'LOG_VERB'}{'0'}>0</option></select></td>
2524 if ( - e
"/var/run/openvpn.pid" ){
2525 print " <br><b><font color='#990000'> $Lang ::tr{'attention'}:</b></font><br>
2526 $Lang ::tr{'server restart'}<br><br>
2529 <table width='100%'>
2532 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save-adv-options'}' disabled='disabled' /></td>
2533 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'cancel-adv-options'}' /></td>
2545 <table width='100%'>
2548 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save-adv-options'}' /></td>
2549 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'cancel-adv-options'}' /></td>
2557 & Header
:: closebox
();
2558 # print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
2559 & Header
:: closebigbox
();
2560 & Header
:: closepage
();
2564 # A.Marx CCD Add,delete or edit CCD net
2566 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ccd net' } ||
2567 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ccd add' } ||
2568 $cgiparams { 'ACTION' } eq "kill" ||
2569 $cgiparams { 'ACTION' } eq "edit" ||
2570 $cgiparams { 'ACTION' } eq 'editsave' ){
2571 & Header
:: showhttpheaders
();
2572 & Header
:: openpage
( $Lang :: tr
{ 'ccd net' }, 1 , '' );
2573 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2575 if ( $cgiparams { 'ACTION' } eq "kill" ){
2576 & delccdnet
( $cgiparams { 'net' });
2579 if ( $cgiparams { 'ACTION' } eq 'editsave' ){
2580 my ( $a , $b ) = split ( /\|/ , $cgiparams { 'ccdname' });
2581 if ( $a ne $b ){ & modccdnet
( $a , $b );}
2584 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ccd add' }) {
2585 & addccdnet
( $cgiparams { 'ccdname' }, $cgiparams { 'ccdsubnet' }, $cgiparams { 'DOVPN_SUBNET' });
2587 if ( $errormessage ) {
2588 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
2589 print "<class name='base'> $errormessage " ;
2590 print " </class>" ;
2591 & Header
:: closebox
();
2593 if ( $cgiparams { 'ACTION' } eq "edit" ){
2595 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd modify' });
2598 <table width='100%' border=0>
2599 <tr><form method='post'>
2600 <td width='10%' nowrap='nowrap'> $Lang ::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value=' $cgiparams {'ccdname'}' /></td>
2601 <td width='8%'> $Lang ::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value=' $cgiparams {'ccdsubnet'}' readonly /></td></tr>
2602 <tr><td colspan='4' align='right'><hr><input type='submit' value=' $Lang ::tr{'save'}' /><input type='hidden' name='ACTION' value='editsave'/>
2603 <input type='hidden' name='ccdname' value=' $cgiparams {'ccdname'}'/><input type='submit' value=' $Lang ::tr{'cancel'}' />
2608 & Header
:: closebox
();
2610 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd net' } );
2612 <table width='100%' border='0' cellpadding='0' cellspacing='1'>
2614 <td class='boldbase' align='center'><b> $Lang ::tr{'ccd name'}</td><td class='boldbase' align='center'><b> $Lang ::tr{'network'}</td><td class='boldbase' width='15%' align='center'><b> $Lang ::tr{'ccd used'}</td><td width='3%'></td><td width='3%'></td></tr>
2619 if (! - e
"/var/run/openvpn.pid" ){
2620 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd add' });
2622 <table width='100%' border='0'>
2623 <tr><form method='post'>
2624 <td colspan='4'> $Lang ::tr{'ccd hint'}<br><br></td></tr>
2626 <td width='10%' nowrap='nwrap'> $Lang ::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value=' $cgiparams {'ccdname'}' /></td>
2627 <td width='8%'> $Lang ::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value=' $cgiparams {'ccdsubnet'}' /></td></tr>
2628 <tr><td colspan=4><hr /></td></tr><tr>
2629 <td colspan='4' align='right'><input type='hidden' name='ACTION' value=' $Lang ::tr{'ccd add'}' /><input type='submit' value=' $Lang ::tr{'add'}' /><input type='hidden' name='DOVPN_SUBNET' value=' $cgiparams {'DOVPN_SUBNET'}'/></td></tr>
2633 & Header
:: closebox
();
2635 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd net' } );
2637 <table width='100%' border='0' cellpadding='0' cellspacing='1'>
2639 <td class='boldbase' align='center' nowrap='nowrap' width='20%'><b> $Lang ::tr{'ccd name'}</td><td class='boldbase' align='center' width='8%'><b> $Lang ::tr{'network'}</td><td class='boldbase' width='8%' align='center' nowrap='nowrap'><b> $Lang ::tr{'ccd used'}</td><td width='1%' align='center'></td><td width='1%' align='center'></td></tr>
2644 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
2647 foreach my $key ( keys %ccdconfhash ) {
2648 @ccdconf =( $ccdconfhash { $key }[ 0 ], $ccdconfhash { $key }[ 1 ]);
2650 my $ccdhosts = & hostsinnet
( $ccdconf [ 0 ]);
2651 if ( $count % 2 ){ print " <tr bgcolor=' $color {'color22'}'>" ;}
2652 else { print " <tr bgcolor=' $color {'color20'}'>" ;}
2653 print "<td> $ccdconf [0]</td><td align='center'> $ccdconf [1]</td><td align='center'> $ccdhosts /" .(& ccdmaxclients
( $ccdconf [ 1 ])+ 1 ). "</td><td>" ;
2655 <form method='post' />
2656 <input type='image' src='/images/edit.gif' align='middle' alt= $Lang ::tr{'edit'} title= $Lang ::tr{'edit'} />
2657 <input type='hidden' name='ACTION' value='edit'/>
2658 <input type='hidden' name='ccdname' value=' $ccdconf [0]' />
2659 <input type='hidden' name='ccdsubnet' value=' $ccdconf [1]' />
2661 <form method='post' />
2662 <td><input type='hidden' name='ACTION' value='kill'/>
2663 <input type='hidden' name='number' value=' $count ' />
2664 <input type='hidden' name='net' value=' $ccdconf [0]' />
2665 <input type='image' src='/images/delete.gif' align='middle' alt= $Lang ::tr{'remove'} title= $Lang ::tr{'remove'} /></form></td></tr>
2669 print "</table></form>" ;
2670 & Header
:: closebox
();
2671 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2672 & Header
:: closebigbox
();
2673 & Header
:: closepage
();
2679 ### Openvpn Connections Statistics
2681 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ovpn con stat' }) {
2682 & Header
:: showhttpheaders
();
2683 & Header
:: openpage
( $Lang :: tr
{ 'ovpn con stat' }, 1 , '' );
2684 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2685 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ovpn con stat' });
2688 # <td><b>$Lang::tr{'protocol'}</b></td>
2689 # protocol temp removed
2691 <table width='100%' border='0' cellpadding='2' cellspacing='0'>
2693 <td><b> $Lang ::tr{'common name'}</b></td>
2694 <td><b> $Lang ::tr{'real address'}</b></td>
2695 <td><b> $Lang ::tr{'virtual address'}</b></td>
2696 <td><b> $Lang ::tr{'loged in at'}</b></td>
2697 <td><b> $Lang ::tr{'bytes sent'}</b></td>
2698 <td><b> $Lang ::tr{'bytes received'}</b></td>
2699 <td><b> $Lang ::tr{'last activity'}</b></td>
2703 my $filename = "/var/log/ovpnserver.log" ;
2704 open ( FILE
, $filename ) or die 'Unable to open config file.' ;
2705 my @current = < FILE
>;
2714 my %userlookup = ();
2715 foreach my $line ( @current )
2718 if ( $line =~ /^Updated,(.+)/ ){
2719 @match = split ( /^Updated,(.+)/ , $line );
2720 $status = $match [ 1 ];
2723 if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ ) {
2724 @match = split ( m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ , $line );
2725 if ( $match [ 1 ] ne "Common Name" ) {
2727 $userlookup { $match [ 2 ]} = $uid ;
2728 $users [ $uid ]{ 'CommonName' } = $match [ 1 ];
2729 $users [ $uid ]{ 'RealAddress' } = $match [ 2 ];
2730 $users [ $uid ]{ 'BytesReceived' } = & sizeformat
( $match [ 3 ]);
2731 $users [ $uid ]{ 'BytesSent' } = & sizeformat
( $match [ 4 ]);
2732 $users [ $uid ]{ 'Since' } = $match [ 5 ];
2733 $users [ $uid ]{ 'Proto' } = $proto ;
2737 if ( $line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/ ) {
2738 @match = split ( m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/ , $line );
2739 if ( $match [ 1 ] ne "Virtual Address" ) {
2740 $address = $match [ 3 ];
2741 #find the uid in the lookup table
2742 $uid = $userlookup { $address };
2743 $users [ $uid ]{ 'VirtualAddress' } = $match [ 1 ];
2744 $users [ $uid ]{ 'LastRef' } = $match [ 4 ];
2750 for ( my $idx = 1 ; $idx <= $user2 ; $idx ++){
2752 print "<tr bgcolor=' $color {'color20'}'> \n " ;
2754 print "<tr bgcolor=' $color {'color22'}'> \n " ;
2756 print "<td align='left'> $users [ $idx -1]{'CommonName'}</td>" ;
2757 print "<td align='left'> $users [ $idx -1]{'RealAddress'}</td>" ;
2758 print "<td align='left'> $users [ $idx -1]{'VirtualAddress'}</td>" ;
2759 print "<td align='left'> $users [ $idx -1]{'Since'}</td>" ;
2760 print "<td align='left'> $users [ $idx -1]{'BytesSent'}</td>" ;
2761 print "<td align='left'> $users [ $idx -1]{'BytesReceived'}</td>" ;
2762 print "<td align='left'> $users [ $idx -1]{'LastRef'}</td>" ;
2763 # print "<td align='left'>$users[$idx-1]{'Proto'}</td>";
2769 <table width='100%' border='0' cellpadding='2' cellspacing='0'>
2774 <tr><td align='center' > $Lang ::tr{'the statistics were last updated at'} <b> $status </b></td></tr>
2778 & Header
:: closebox
();
2779 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2780 & Header
:: closebigbox
();
2781 & Header
:: closepage
();
2785 ### Download Certificate
2787 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
2788 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2790 if ( - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
2791 print "Content-Disposition: filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \r\n " ;
2792 print "Content-Type: application/octet-stream \r\n\r\n " ;
2793 print `/bin/cat ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
2798 ### Enable/Disable connection
2801 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
2803 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2804 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2806 if ( $confighash { $cgiparams { 'KEY' }}) {
2807 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
2808 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
2809 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2810 #&writeserverconf();
2811 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2812 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2813 # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
2816 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
2817 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2818 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2819 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
2821 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2822 #&writeserverconf();
2825 $errormessage = $Lang :: tr
{ 'invalid key' };
2829 ### Restart connection
2831 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
2832 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2833 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2835 if ( $confighash { $cgiparams { 'KEY' }}) {
2836 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2837 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2838 # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
2841 $errormessage = $Lang :: tr
{ 'invalid key' };
2845 ### Remove connection
2847 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
2848 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2849 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2851 if ( $confighash { $cgiparams { 'KEY' }}) {
2852 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2853 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2854 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
2856 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
2857 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
2858 delete $confighash { $cgiparams { 'KEY' }};
2859 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2860 #&writeserverconf();
2862 $errormessage = $Lang :: tr
{ 'invalid key' };
2867 ### Choose between adding a host-net or net-net connection
2874 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
2875 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2876 & Header
:: showhttpheaders
();
2877 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
2878 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2879 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'connection type' });
2881 if ( - s
"${General::swroot}/ovpn/settings" ) {
2884 <b> $Lang ::tr{'connection type'}:</b><br />
2885 <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data">
2886 <tr><td><input type='radio' name='TYPE' value='host' checked /></td>
2887 <td class='base'> $Lang ::tr{'host to net vpn'}</td></tr>
2888 <tr><td><input type='radio' name='TYPE' value='net' /></td>
2889 <td class='base'> $Lang ::tr{'net to net vpn'}</td></tr>
2890 <tr><td><input type='radio' name='TYPE' value='net2net' /></td>
2891 <td class='base'> $Lang ::tr{'net to net vpn'} (Upload Client Package)</td></tr>
2892 <tr><td> </td><td class='base'><input type='file' name='FH' size='30'></td></tr>
2893 <tr><td> </td><td>Import Connection Name <img src='/blob.gif' /></td></tr>
2894 <tr><td> </td><td class='base'><input type='text' name='n2nname' size='30'>Default : Client Packagename</td></tr>
2895 <tr><td colspan='3'><hr /></td></tr>
2896 <tr><td align='right' colspan='3'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td></tr>
2897 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
2905 <b> $Lang ::tr{'connection type'}:</b><br />
2906 <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data">
2907 <tr><td><input type='radio' name='TYPE' value='host' checked /></td> <td class='base'> $Lang ::tr{'host to net vpn'}</td></tr>
2908 <tr><td align='right' colspan'3'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td></tr>
2915 & Header
:: closebox
();
2916 & Header
:: closebigbox
();
2917 & Header
:: closepage
();
2924 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) && ( $cgiparams { 'TYPE' } eq 'net2net' )){
2928 my $uplconffilename = '' ;
2929 my $uplconffilename2 = '' ;
2930 my $uplp12name = '' ;
2931 my $uplp12name2 = '' ;
2938 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2940 # Check if a file is uploaded
2942 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
2943 $errormessage = $Lang :: tr
{ 'there was no file upload' };
2947 # Move uploaded IPfire n2n package to temporary file
2949 ( my $fh , my $filename ) = tempfile
( );
2950 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
2955 my $zip = Archive
:: Zip
-> new ();
2956 my $zipName = $filename ;
2957 my $status = $zip -> read ( $zipName );
2958 if ( $status != AZ_OK
) {
2959 $errormessage = "Read of $zipName failed \n " ;
2963 my $tempdir = tempdir
( CLEANUP
=> 1 );
2964 my @files = $zip -> memberNames ();
2966 $zip -> extractMemberWithoutPaths ( $_ , " $tempdir / $_ " );
2968 my $countfiles = @files ;
2970 # Check if we have not more then 2 files
2972 if ( $countfiles == 2 ){
2974 if ( $_ =~ /.conf$/ ){
2975 $uplconffilename = $_ ;
2977 if ( $_ =~ /.p12$/ ){
2981 if (( $uplconffilename eq '' ) || ( $uplp12name eq '' )){
2982 $errormessage = "Either no *.conf or no *.p12 file found \n " ;
2986 open ( FILE
, " $tempdir / $uplconffilename " ) or die 'Unable to open*.conf file' ;
2987 @firen2nconf = < FILE
>;
2989 chomp ( @firen2nconf );
2993 $errormessage = "Filecount does not match only 2 files are allowed \n " ;
3001 if ( $cgiparams { 'n2nname' } ne '' ){
3003 $uplconffilename2 = " $cgiparams {'n2nname'}.conf" ;
3004 $uplp12name2 = " $cgiparams {'n2nname'}.p12" ;
3005 $n2nname [ 0 ] = $cgiparams { 'n2nname' };
3006 my @n2nname2 = split ( /\./ , $uplconffilename );
3007 $n2nname2 [ 0 ] =~ s/\n|\r//g ;
3008 my $input1 = "${General::swroot}/ovpn/certs/ $uplp12name " ;
3009 my $output1 = "${General::swroot}/ovpn/certs/ $uplp12name2 " ;
3010 my $input2 = " $n2nname2 [0]n2n" ;
3011 my $output2 = " $n2nname [0]n2n" ;
3012 my $filename = " $tempdir / $uplconffilename " ;
3013 open ( FILE
, "< $filename " ) or die 'Unable to open config file.' ;
3014 my @current = < FILE
>;
3016 foreach ( @current ) { s/$input1/$output1/g ;}
3017 foreach ( @current ) { s/$input2/$output2/g ;}
3018 open ( OUT
, "> $filename " ) || die 'Unable to open config file.' ;
3023 $uplconffilename2 = $uplconffilename ;
3024 $uplp12name2 = $uplp12name ;
3025 @n2nname = split ( /\./ , $uplconffilename );
3026 $n2nname [ 0 ] =~ s/\n|\r//g ;
3028 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
3029 unless (- d
"${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" , 0770 or die "Unable to create dir $!" ;}
3031 move
( " $tempdir / $uplconffilename " , "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $uplconffilename2 " );
3034 $errormessage = "*.conf move failed: $!" ;
3039 move
( " $tempdir / $uplp12name " , "${General::swroot}/ovpn/certs/ $uplp12name2 " );
3040 chmod 0600 , "${General::swroot}/ovpn/certs/ $uplp12name " ;
3043 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
3051 my @n2nmtudisc = split ( / / , ( grep { /^mtu-disc/ } @firen2nconf )[ 0 ]);;
3052 my @n2nproto2 = split ( / / , ( grep { /^proto/ } @firen2nconf )[ 0 ]);
3053 my @n2nproto = split ( /-/ , $n2nproto2 [ 1 ]);
3054 my @n2nport = split ( / / , ( grep { /^port/ } @firen2nconf )[ 0 ]);
3055 my @n2ntunmtu = split ( / / , ( grep { /^tun-mtu/ } @firen2nconf )[ 0 ]);
3056 my @n2ncomplzo = grep { /^comp-lzo/ } @firen2nconf ;
3057 if ( $n2ncomplzo [ 0 ] =~ /comp-lzo/ ){ $complzoactive = "on" ;} else { $complzoactive = "off" ;}
3058 my @n2nmssfix = grep { /^mssfix/ } @firen2nconf ;
3059 if ( $n2nmssfix [ 0 ] =~ /mssfix/ ){ $mssfixactive = "on" ;} else { $mssfixactive = "off" ;}
3060 #my @n2nmssfix = split(/ /, (grep { /^mssfix/ } @firen2nconf)[0]);
3061 my @n2nfragment = split ( / / , ( grep { /^fragment/ } @firen2nconf )[ 0 ]);
3062 my @n2nremote = split ( / / , ( grep { /^remote/ } @firen2nconf )[ 0 ]);
3063 my @n2novpnsuball = split ( / / , ( grep { /^ifconfig/ } @firen2nconf )[ 0 ]);
3064 my @n2novpnsub = split ( /\./ , $n2novpnsuball [ 1 ]);
3065 my @n2nremsub = split ( / / , ( grep { /^route/ } @firen2nconf )[ 0 ]);
3066 my @n2nmgmt = split ( / / , ( grep { /^management/ } @firen2nconf )[ 0 ]);
3067 my @n2nlocalsub = split ( / / , ( grep { /^# remsub/ } @firen2nconf )[ 0 ]);
3071 # m.a.d delete CR and LF from arrays for this chomp doesnt work
3074 $n2nremote [ 1 ] =~ s/\n|\r//g ;
3075 $n2novpnsub [ 0 ] =~ s/\n|\r//g ;
3076 $n2novpnsub [ 1 ] =~ s/\n|\r//g ;
3077 $n2novpnsub [ 2 ] =~ s/\n|\r//g ;
3078 $n2nproto [ 0 ] =~ s/\n|\r//g ;
3079 $n2nport [ 1 ] =~ s/\n|\r//g ;
3080 $n2ntunmtu [ 1 ] =~ s/\n|\r//g ;
3081 $n2nremsub [ 1 ] =~ s/\n|\r//g ;
3082 $n2nremsub [ 2 ] =~ s/\n|\r//g ;
3083 $n2nlocalsub [ 2 ] =~ s/\n|\r//g ;
3084 $n2nfragment [ 1 ] =~ s/\n|\r//g ;
3085 $n2nmgmt [ 2 ] =~ s/\n|\r//g ;
3086 $n2nmtudisc [ 1 ] =~ s/\n|\r//g ;
3087 chomp ( $complzoactive );
3088 chomp ( $mssfixactive );
3095 # Check if there is no other entry with this name
3098 foreach my $dkey ( keys %confighash ) {
3099 if ( $confighash { $dkey }[ 1 ] eq $n2nname [ 0 ]) {
3100 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
3101 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
3102 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
3103 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
3109 # Check if OpenVPN Subnet is valid
3112 foreach my $dkey ( keys %confighash ) {
3113 if ( $confighash { $dkey }[ 27 ] eq " $n2novpnsub [0]. $n2novpnsub [1]. $n2novpnsub [2].0/255.255.255.0" ) {
3114 $errormessage = 'The OpenVPN Subnet is already in use' ;
3115 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
3116 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
3117 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
3123 # Check im Dest Port is vaild
3126 foreach my $dkey ( keys %confighash ) {
3127 if ( $confighash { $dkey }[ 29 ] eq $n2nport [ 1 ] ) {
3128 $errormessage = 'The OpenVPN Port is already in use' ;
3129 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
3130 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
3131 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
3138 $key = & General
:: findhasharraykey
( \
%confighash );
3140 foreach my $i ( 0 .. 39 ) { $confighash { $key }[ $i ] = "" ;}
3142 $confighash { $key }[ 0 ] = 'off' ;
3143 $confighash { $key }[ 1 ] = $n2nname [ 0 ];
3144 $confighash { $key }[ 2 ] = $n2nname [ 0 ];
3145 $confighash { $key }[ 3 ] = 'net' ;
3146 $confighash { $key }[ 4 ] = 'cert' ;
3147 $confighash { $key }[ 6 ] = 'client' ;
3148 $confighash { $key }[ 8 ] = $n2nlocalsub [ 2 ];
3149 $confighash { $key }[ 10 ] = $n2nremote [ 1 ];
3150 $confighash { $key }[ 11 ] = " $n2nremsub [1]/ $n2nremsub [2]" ;
3151 $confighash { $key }[ 22 ] = $n2nmgmt [ 2 ];
3152 $confighash { $key }[ 23 ] = $mssfixactive ;
3153 $confighash { $key }[ 24 ] = $n2nfragment [ 1 ];
3154 $confighash { $key }[ 25 ] = 'IPFire n2n Client' ;
3155 $confighash { $key }[ 26 ] = 'red' ;
3156 $confighash { $key }[ 27 ] = " $n2novpnsub [0]. $n2novpnsub [1]. $n2novpnsub [2].0/255.255.255.0" ;
3157 $confighash { $key }[ 28 ] = $n2nproto [ 0 ];
3158 $confighash { $key }[ 29 ] = $n2nport [ 1 ];
3159 $confighash { $key }[ 30 ] = $complzoactive ;
3160 $confighash { $key }[ 31 ] = $n2ntunmtu [ 1 ];
3161 $confighash { $key }[ 38 ] = $n2nmtudisc [ 1 ];
3164 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3168 & Header
:: showhttpheaders
();
3169 & Header
:: openpage
( 'Validate imported configuration' , 1 , '' );
3170 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
3171 if ( $errormessage ) {
3172 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
3173 print "<class name='base'> $errormessage " ;
3174 print " </class>" ;
3175 & Header
:: closebox
();
3179 & Header
:: openbox
( '100%' , 'LEFT' , 'import ipfire net2net config' );
3181 if ( $errormessage eq '' ){
3183 <!-- ipfire net2net config gui -->
3184 <table width='100%'>
3185 <tr><td width='25%'> </td><td width='25%'> </td></tr>
3186 <tr><td class='boldbase'> $Lang ::tr{'name'}:</td><td><b> $n2nname [0]</b></td></tr>
3187 <tr><td> </td><td> </td></tr>
3188 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'Act as'}</td><td><b> $confighash { $key }[6]</b></td></tr>
3189 <tr><td class='boldbase' nowrap='nowrap'>Remote Host </td><td><b> $confighash { $key }[10]</b></td></tr>
3190 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'}</td><td><b> $confighash { $key }[8]</b></td></tr>
3191 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'}</td><td><b> $confighash { $key }[11]</b></td></tr>
3192 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn subnet'}</td><td><b> $confighash { $key }[27]</b></td></tr>
3193 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td><td><b> $confighash { $key }[28]</b></td></tr>
3194 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'destination port'}:</td><td><b> $confighash { $key }[29]</b></td></tr>
3195 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'}</td><td><b> $confighash { $key }[30]</b></td></tr>
3196 <tr><td class='boldbase' nowrap='nowrap'>MSSFIX </td><td><b> $confighash { $key }[23]</b></td></tr>
3197 <tr><td class='boldbase' nowrap='nowrap'>Fragment </td><td><b> $confighash { $key }[24]</b></td></tr>
3198 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'}</td><td><b> $confighash { $key }[31]</b></td></tr>
3199 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn mtu-disc'}</td><td><b> $confighash { $key }[38]</b></td></tr>
3200 <tr><td class='boldbase' nowrap='nowrap'>Management Port </td><td><b> $confighash { $key }[22]</b></td></tr>
3201 <tr><td> </td><td> </td></tr>
3205 & Header
:: closebox
();
3208 if ( $errormessage ) {
3209 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
3211 print "<div align='center'><form method='post' ENCTYPE='multipart/form-data'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />" ;
3212 print "<input type='hidden' name='TYPE' value='net2netakn' />" ;
3213 print "<input type='hidden' name='KEY' value=' $key ' />" ;
3214 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
3216 & Header
:: closebigbox
();
3217 & Header
:: closepage
();
3222 ### Accept IPFire n2n Package Settings
3225 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) && ( $cgiparams { 'TYPE' } eq 'net2netakn' )){
3228 ### Discard and Rollback IPFire n2n Package Settings
3231 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'cancel' }) && ( $cgiparams { 'TYPE' } eq 'net2netakn' )){
3233 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3235 if ( $confighash { $cgiparams { 'KEY' }}) {
3237 my $conffile = glob ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]/ $confighash { $cgiparams {'KEY'}}[1].conf" );
3238 my $certfile = glob ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
3239 unlink ( $certfile ) or die "Removing $certfile fail: $!" ;
3240 unlink ( $conffile ) or die "Removing $conffile fail: $!" ;
3241 rmdir ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]" ) || die "Kann Verzeichnis nicht loeschen: $!" ;
3242 delete $confighash { $cgiparams { 'KEY' }};
3243 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3246 $errormessage = $Lang :: tr
{ 'invalid key' };
3256 ### Adding a new connection
3258 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
3259 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
3260 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
3262 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
3263 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
3264 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3266 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
3267 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
3268 $errormessage = $Lang :: tr
{ 'invalid key' };
3271 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
3272 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
3273 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
3274 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
3275 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
3276 $cgiparams { 'SIDE' } = $confighash { $cgiparams { 'KEY' }}[ 6 ];
3277 $cgiparams { 'LOCAL_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 8 ];
3278 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
3279 $cgiparams { 'REMOTE_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 11 ];
3280 $cgiparams { 'OVPN_MGMT' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
3281 $cgiparams { 'MSSFIX' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
3282 $cgiparams { 'FRAGMENT' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
3283 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
3284 $cgiparams { 'INTERFACE' } = $confighash { $cgiparams { 'KEY' }}[ 26 ];
3285 $cgiparams { 'OVPN_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
3286 $cgiparams { 'PROTOCOL' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
3287 $cgiparams { 'DEST_PORT' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
3288 $cgiparams { 'COMPLZO' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
3289 $cgiparams { 'MTU' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
3290 $cgiparams { 'CHECK1' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
3291 my $name = $cgiparams { 'CHECK1' } ;
3292 $cgiparams { $name } = $confighash { $cgiparams { 'KEY' }}[ 33 ];
3293 $cgiparams { 'RG' } = $confighash { $cgiparams { 'KEY' }}[ 34 ];
3294 $cgiparams { 'CCD_DNS1' } = $confighash { $cgiparams { 'KEY' }}[ 35 ];
3295 $cgiparams { 'CCD_DNS2' } = $confighash { $cgiparams { 'KEY' }}[ 36 ];
3296 $cgiparams { 'CCD_WINS' } = $confighash { $cgiparams { 'KEY' }}[ 37 ];
3297 $cgiparams { 'PMTU_DISCOVERY' } = $confighash { $cgiparams { 'KEY' }}[ 38 ];
3298 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
3299 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
3301 #A.Marx CCD check iroute field and convert it to decimal
3302 if ( $cgiparams { 'TYPE' } eq 'host' ) {
3304 my %ccdroutehash =();
3306 if ( $cgiparams { 'IR' } ne '' ){
3307 @temp = split ( " \n " , $cgiparams { 'IR' });
3308 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3310 foreach my $key ( keys %ccdroutehash ) {
3311 if ( $ccdroutehash { $key }[ 0 ] eq $cgiparams { 'NAME' }) {
3313 delete $ccdroutehash { $key };
3315 $keypoint = & General
:: findhasharraykey
( \
%ccdroutehash );
3318 $ccdroutehash { $keypoint }[ 0 ]= $cgiparams { 'NAME' };
3321 foreach $val ( @temp ){
3324 my ( $ip , $cidr ) = split ( /\/ /, $val );
3325 $ip =& General
:: getnetworkip
( $ip ,& General
:: iporsubtocidr
( $cidr ));
3326 $cidr =& General
:: iporsubtodec
( $cidr );
3328 #check if iroute exists in ccdroute
3329 foreach my $key ( keys %ccdroutehash ) {
3330 foreach my $oldiroute ( 1 .. $ #{$ccdroutehash{$key}}){
3331 if ( $ccdroutehash { $key }[ $oldiroute ] eq " $ip / $cidr " ) {
3332 $errormessage = $Lang :: tr
{ 'ccd err irouteexist' };
3338 #check for existing network IP's
3339 if (& General
:: IpInSubnet
( $ip , $netsettings { GREEN_NETADDRESS
}, $netsettings { GREEN_NETMASK
}) && $netsettings { GREEN_NETADDRESS
} ne '0.0.0.0' )
3341 $errormessage = $Lang :: tr
{ 'ccd err green' };
3343 } elsif (& General
:: IpInSubnet
( $ip , $netsettings { RED_NETADDRESS
}, $netsettings { RED_NETMASK
}) && $netsettings { RED_NETADDRESS
} ne '0.0.0.0' )
3345 $errormessage = $Lang :: tr
{ 'ccd err red' };
3347 } elsif (& General
:: IpInSubnet
( $ip , $netsettings { BLUE_NETADDRESS
}, $netsettings { BLUE_NETMASK
}) && $netsettings { BLUE_NETADDRESS
} ne '0.0.0.0' && $netsettings { BLUE_NETADDRESS
} gt '' )
3349 $errormessage = $Lang :: tr
{ 'ccd err blue' };
3351 } elsif (& General
:: IpInSubnet
( $ip , $netsettings { ORANGE_NETADDRESS
}, $netsettings { ORANGE_NETMASK
}) && $netsettings { ORANGE_NETADDRESS
} ne '0.0.0.0' && $netsettings { ORANGE_NETADDRESS
} gt '' )
3353 $errormessage = $Lang :: tr
{ 'ccd err orange' };
3357 if (& General
:: validipandmask
( $val )){
3358 $ccdroutehash { $keypoint }[ $i ] = $ip . "/" . $cidr ;
3360 $errormessage = $errormessage . "Route " . $Lang :: tr
{ 'ccd invalid' }. " ( $ip / $cidr )" ;
3365 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3368 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3369 foreach my $key ( keys %ccdroutehash ) {
3370 if ( $ccdroutehash { $key }[ 0 ] eq $cgiparams { 'NAME' }) {
3371 delete $ccdroutehash { $key };
3372 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3378 #check route field and convert it to decimal
3381 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
3383 foreach my $key ( keys %ccdroute2hash ) {
3384 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }) {
3386 delete $ccdroute2hash { $key };
3388 $keypoint = & General
:: findhasharraykey
( \
%ccdroute2hash );
3389 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3393 $ccdroute2hash { $keypoint }[ 0 ]= $cgiparams { 'NAME' };
3394 if ( $cgiparams { 'IFROUTE' } eq '' ){ $cgiparams { 'IFROUTE' } = $Lang :: tr
{ 'ccd none' };}
3395 @temp = split ( /\|/ , $cgiparams { 'IFROUTE' });
3397 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%ownnet );
3398 foreach $val ( @temp ){
3401 if ( $val eq $Lang :: tr
{ 'green' })
3403 $val = $ownnet { GREEN_NETADDRESS
}. "/" . $ownnet { GREEN_NETMASK
};
3405 if ( $val eq $Lang :: tr
{ 'blue' })
3407 $val = $ownnet { BLUE_NETADDRESS
}. "/" . $ownnet { BLUE_NETMASK
};
3409 if ( $val eq $Lang :: tr
{ 'orange' })
3411 $val = $ownnet { ORANGE_NETADDRESS
}. "/" . $ownnet { ORANGE_NETMASK
};
3413 my ( $ip , $cidr ) = split ( /\/ /, $val );
3415 if ( $val ne $Lang :: tr
{ 'ccd none' })
3417 if (! & check_routes_push
( $val )){ $errormessage = $errormessage . "Route $val " . $Lang :: tr
{ 'ccd err routeovpn2' }. " ( $val )" ; goto VPNCONF_ERROR
;}
3418 if (! & check_ccdroute
( $val )){ $errormessage = $errormessage . "<br>Route $val " . $Lang :: tr
{ 'ccd err inuse' }. " ( $val )" ; goto VPNCONF_ERROR
;}
3419 if (! & check_ccdconf
( $val )){ $errormessage = $errormessage . "<br>Route $val " . $Lang :: tr
{ 'ccd err routeovpn' }. " ( $val )" ; goto VPNCONF_ERROR
;}
3420 if (& General
:: validipandmask
( $val )){
3421 $val = $ip . "/" .& General
:: iporsubtodec
( $cidr );
3422 $ccdroute2hash { $keypoint }[ $i ] = $val ;
3424 $errormessage = $errormessage . "Route " . $Lang :: tr
{ 'ccd invalid' }. " ( $val )" ;
3428 $ccdroute2hash { $keypoint }[ $i ]= '' ;
3432 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
3435 if ( $cgiparams { 'CCD_DNS1' } ne '' && ! & General
:: validip
( $cgiparams { 'CCD_DNS1' })) {
3436 $errormessage = $errormessage . "<br>" . $Lang :: tr
{ 'invalid input for dhcp dns' }. " 1" ;
3440 if ( $cgiparams { 'CCD_DNS2' } ne '' && ! & General
:: validip
( $cgiparams { 'CCD_DNS2' })) {
3441 $errormessage = $errormessage . "<br>" . $Lang :: tr
{ 'invalid input for dhcp dns' }. " 2" ;
3445 if ( $cgiparams { 'CCD_WINS' } ne '' && ! & General
:: validip
( $cgiparams { 'CCD_WINS' })) {
3446 $errormessage = $errormessage . "<br>" . $Lang :: tr
{ 'invalid input for dhcp wins' };
3454 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
3455 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
3456 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3457 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3458 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3464 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
3465 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
3466 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3467 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3468 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3473 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
3474 $errormessage = $Lang :: tr
{ 'name is invalid' };
3475 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3476 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3477 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3482 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
3483 $errormessage = $Lang :: tr
{ 'name too long' };
3484 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3485 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3486 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3495 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3497 if ( $cgiparams { 'DEST_PORT' } eq $vpnsettings { 'DDEST_PORT' }) {
3498 $errormessage = $Lang :: tr
{ 'openvpn destination port used' };
3499 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3500 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3504 if ( $cgiparams { 'DEST_PORT' } eq '' ) {
3505 $errormessage = $Lang :: tr
{ 'openvpn destination port used' };
3506 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3507 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3511 if ( $cgiparams { 'OVPN_SUBNET' } eq $vpnsettings { 'DOVPN_SUBNET' }) {
3512 $errormessage = $Lang :: tr
{ 'openvpn subnet is used' };
3513 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3514 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3518 if (( $cgiparams { 'PROTOCOL' } eq 'tcp' ) && ( $cgiparams { 'MSSFIX' } eq 'on' )) {
3519 $errormessage = $Lang :: tr
{ 'openvpn mssfix allowed with udp' };
3520 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3521 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3525 if (( $cgiparams { 'PROTOCOL' } eq 'tcp' ) && ( $cgiparams { 'FRAGMENT' } ne '' )) {
3526 $errormessage = $Lang :: tr
{ 'openvpn fragment allowed with udp' };
3527 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3528 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3532 if (( $cgiparams { 'PMTU_DISCOVERY' } ne 'off' ) && ( $cgiparams { 'MTU' } ne '1500' )) {
3533 $errormessage = $Lang :: tr
{ 'ovpn mtu-disc and mtu not 1500' };
3534 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3535 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3539 if ( $cgiparams { 'PMTU_DISCOVERY' } ne 'off' ) {
3540 if (( $cgiparams { 'FRAGMENT' } ne '' ) || ( $cgiparams { 'MSSFIX' } eq 'on' )) {
3541 $errormessage = $Lang :: tr
{ 'ovpn mtu-disc with mssfix or fragment' };
3542 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3543 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3548 if ( & validdotmask
( $cgiparams { 'LOCAL_SUBNET' })) {
3549 $errormessage = $Lang :: tr
{ 'openvpn prefix local subnet' };
3550 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3551 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3555 if ( & validdotmask
( $cgiparams { 'OVPN_SUBNET' })) {
3556 $errormessage = $Lang :: tr
{ 'openvpn prefix openvpn subnet' };
3557 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3558 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3562 if ( & validdotmask
( $cgiparams { 'REMOTE_SUBNET' })) {
3563 $errormessage = $Lang :: tr
{ 'openvpn prefix remote subnet' };
3564 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3565 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3569 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) {
3570 $cgiparams { 'OVPN_MGMT' } = $cgiparams { 'DEST_PORT' };
3575 # if (($cgiparams{'TYPE'} eq 'net') && ($cgiparams{'SIDE'} !~ /^(left|right)$/)) {
3576 # $errormessage = $Lang::tr{'ipfire side is invalid'};
3577 # goto VPNCONF_ERROR;
3580 # Check if there is no other entry with this name
3581 if (! $cgiparams { 'KEY' }) {
3582 foreach my $key ( keys %confighash ) {
3583 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
3584 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
3585 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3586 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3587 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3594 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! $cgiparams { 'REMOTE' })) {
3595 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
3596 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3597 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3598 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3603 if ( $cgiparams { 'REMOTE' }) {
3604 if (! & General
:: validip
( $cgiparams { 'REMOTE' })) {
3605 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
3606 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
3607 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3608 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3609 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3613 if (& valid_dns_host
( $cgiparams { 'REMOTE' })) {
3614 $warnmessage = " $Lang ::tr{'check vpn lr'} $cgiparams {'REMOTE'}. $Lang ::tr{'dns check failed'}" ;
3615 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3622 if ( $cgiparams { 'TYPE' } ne 'host' ) {
3623 unless (& General
:: validipandmask
( $cgiparams { 'LOCAL_SUBNET' })) {
3624 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
3625 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3626 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3627 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3629 goto VPNCONF_ERROR
;}
3631 # Check if there is no other entry without IP-address and PSK
3632 if ( $cgiparams { 'REMOTE' } eq '' ) {
3633 foreach my $key ( keys %confighash ) {
3634 if (( $cgiparams { 'KEY' } ne $key ) &&
3635 ( $confighash { $key }[ 4 ] eq 'psk' || $cgiparams { 'AUTH' } eq 'psk' ) &&
3636 $confighash { $key }[ 10 ] eq '' ) {
3637 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
3642 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! & General
:: validipandmask
( $cgiparams { 'REMOTE_SUBNET' }))) {
3643 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
3644 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3645 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3649 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
3650 $errormessage = $Lang :: tr
{ 'invalid input' };
3653 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
3654 $errormessage = $Lang :: tr
{ 'invalid input' };
3659 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
3660 # if (! length($cgiparams{'PSK'}) ) {
3661 # $errormessage = $Lang::tr{'pre-shared key is too short'};
3662 # goto VPNCONF_ERROR;
3664 # if ($cgiparams{'PSK'} =~ /['",&]/) {
3665 # $errormessage = $Lang::tr{'invalid characters found in pre-shared key'};
3666 # goto VPNCONF_ERROR;
3668 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
3669 if ( $cgiparams { 'KEY' }) {
3670 $errormessage = $Lang :: tr
{ 'cant change certificates' };
3673 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
3674 $errormessage = $Lang :: tr
{ 'there was no file upload' };
3678 # Move uploaded certificate request to a temporary file
3679 ( my $fh , my $filename ) = tempfile
( );
3680 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
3685 # Sign the certificate request and move it
3686 # Sign the host certificate request
3687 system ( '/usr/bin/openssl' , 'ca' , '-days' , " $cgiparams {'DAYS_VALID'}" ,
3688 '-batch' , '-notext' ,
3690 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
3691 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
3693 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
3695 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3696 & newcleanssldatabase
();
3700 & deletebackupcert
();
3703 my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem` ;
3704 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
3706 $temp =~ s
+/ Email
+, E
+;
3707 $temp =~ s/ ST=/ S=/ ;
3708 $cgiparams { 'CERT_NAME' } = $temp ;
3709 $cgiparams { 'CERT_NAME' } =~ s/,//g ;
3710 $cgiparams { 'CERT_NAME' } =~ s/\'//g ;
3711 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
3712 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
3715 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
3716 if ( $cgiparams { 'KEY' }) {
3717 $errormessage = $Lang :: tr
{ 'cant change certificates' };
3720 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
3721 $errormessage = $Lang :: tr
{ 'there was no file upload' };
3724 # Move uploaded certificate to a temporary file
3725 ( my $fh , my $filename ) = tempfile
( );
3726 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
3731 # Verify the certificate has a valid CA and move it
3733 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/cacert.pem $filename ` ;
3734 if ( $test =~ /: OK/ ) {
3737 foreach my $key ( keys %cahash ) {
3738 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/ $cahash { $key }[0]cert.pem $filename ` ;
3739 if ( $test =~ /: OK/ ) {
3745 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
3749 move
( $filename , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3751 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
3757 my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem` ;
3758 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
3760 $temp =~ s
+/ Email
+, E
+;
3761 $temp =~ s/ ST=/ S=/ ;
3762 $cgiparams { 'CERT_NAME' } = $temp ;
3763 $cgiparams { 'CERT_NAME' } =~ s/,//g ;
3764 $cgiparams { 'CERT_NAME' } =~ s/\'//g ;
3765 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
3766 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3767 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
3770 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
3771 if ( $cgiparams { 'KEY' }) {
3772 $errormessage = $Lang :: tr
{ 'cant change certificates' };
3775 # Validate input since the form was submitted
3776 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
3777 $errormessage = $Lang :: tr
{ 'name too long' };
3780 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
3781 $errormessage = $Lang :: tr
{ 'invalid input for name' };
3784 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
3785 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
3788 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
3789 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
3792 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
3793 $errormessage = $Lang :: tr
{ 'invalid input for department' };
3796 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
3797 $errormessage = $Lang :: tr
{ 'organization too long' };
3800 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
3801 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
3804 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
3805 $errormessage = $Lang :: tr
{ 'invalid input for city' };
3808 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
3809 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
3812 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
3813 $errormessage = $Lang :: tr
{ 'invalid input for country' };
3816 if ( $cgiparams { 'CERT_PASS1' } ne '' && $cgiparams { 'CERT_PASS2' } ne '' ){
3817 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
3818 $errormessage = $Lang :: tr
{ 'password too short' };
3822 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
3823 $errormessage = $Lang :: tr
{ 'passwords do not match' };
3827 # Replace empty strings with a .
3828 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
3829 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
3830 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
3832 # Create the Host certificate request client
3833 my $pid = open ( OPENSSL
, "|-" );
3834 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto VPNCONF_ERROR
;};
3835 if ( $pid ) { # parent
3836 print OPENSSL
" $cgiparams {'CERT_COUNTRY'} \n " ;
3837 print OPENSSL
" $state \n " ;
3838 print OPENSSL
" $city \n " ;
3839 print OPENSSL
" $cgiparams {'CERT_ORGANIZATION'} \n " ;
3840 print OPENSSL
" $ou \n " ;
3841 print OPENSSL
" $cgiparams {'CERT_NAME'} \n " ;
3842 print OPENSSL
" $cgiparams {'CERT_EMAIL'} \n " ;
3843 print OPENSSL
". \n " ;
3844 print OPENSSL
". \n " ;
3847 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
3848 unlink ( "${General::swroot}ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3849 unlink ( "${General::swroot}ovpn/certs/ $cgiparams {'NAME'}req.pem" );
3853 unless ( exec ( '/usr/bin/openssl' , 'req' , '-nodes' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
3854 '-newkey' , 'rsa:1024' ,
3855 '-keyout' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" ,
3856 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" ,
3857 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
3858 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
3859 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3860 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
3865 # Sign the host certificate request
3866 system ( '/usr/bin/openssl' , 'ca' , '-days' , " $cgiparams {'DAYS_VALID'}" ,
3867 '-batch' , '-notext' ,
3868 '-in' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" ,
3869 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
3870 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
3872 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
3873 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3874 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
3875 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3876 & newcleanssldatabase
();
3879 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
3880 & deletebackupcert
();
3883 # Create the pkcs12 file
3884 system ( '/usr/bin/openssl' , 'pkcs12' , '-export' ,
3885 '-inkey' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" ,
3886 '-in' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
3887 '-name' , $cgiparams { 'NAME' },
3888 '-passout' , "pass: $cgiparams {'CERT_PASS1'}" ,
3889 '-certfile' , "${General::swroot}/ovpn/ca/cacert.pem" ,
3890 '-caname' , " $vpnsettings {'ROOTCERT_ORGANIZATION'} CA" ,
3891 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12" );
3893 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
3894 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3895 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3896 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12" );
3899 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3901 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
3902 ; # Nothing, just editing
3904 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
3908 # Check if there is no other entry with this common name
3909 if ((! $cgiparams { 'KEY' }) && ( $cgiparams { 'AUTH' } ne 'psk' )) {
3910 foreach my $key ( keys %confighash ) {
3911 if ( $confighash { $key }[ 2 ] eq $cgiparams { 'CERT_NAME' }) {
3912 $errormessage = $Lang :: tr
{ 'a connection with this common name already exists' };
3919 my $key = $cgiparams { 'KEY' };
3922 $key = & General
:: findhasharraykey
( \
%confighash );
3923 foreach my $i ( 0 .. 38 ) { $confighash { $key }[ $i ] = "" ;}
3925 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
3926 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
3927 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
3928 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
3931 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
3932 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
3933 $confighash { $key }[ 4 ] = 'psk' ;
3934 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
3936 $confighash { $key }[ 4 ] = 'cert' ;
3938 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3939 $confighash { $key }[ 6 ] = $cgiparams { 'SIDE' };
3940 $confighash { $key }[ 11 ] = $cgiparams { 'REMOTE_SUBNET' };
3942 $confighash { $key }[ 8 ] = $cgiparams { 'LOCAL_SUBNET' };
3943 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
3944 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) {
3945 $confighash { $key }[ 22 ] = $confighash { $key }[ 29 ];
3947 $confighash { $key }[ 22 ] = $cgiparams { 'OVPN_MGMT' };
3949 $confighash { $key }[ 23 ] = $cgiparams { 'MSSFIX' };
3950 $confighash { $key }[ 24 ] = $cgiparams { 'FRAGMENT' };
3951 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
3952 $confighash { $key }[ 26 ] = $cgiparams { 'INTERFACE' };
3954 $confighash { $key }[ 27 ] = $cgiparams { 'OVPN_SUBNET' };
3955 $confighash { $key }[ 28 ] = $cgiparams { 'PROTOCOL' };
3956 $confighash { $key }[ 29 ] = $cgiparams { 'DEST_PORT' };
3957 $confighash { $key }[ 30 ] = $cgiparams { 'COMPLZO' };
3958 $confighash { $key }[ 31 ] = $cgiparams { 'MTU' };
3959 $confighash { $key }[ 32 ] = $cgiparams { 'CHECK1' };
3960 my $name = $cgiparams { 'CHECK1' };
3961 $confighash { $key }[ 33 ] = $cgiparams { $name };
3962 $confighash { $key }[ 34 ] = $cgiparams { 'RG' };
3963 $confighash { $key }[ 35 ] = $cgiparams { 'CCD_DNS1' };
3964 $confighash { $key }[ 36 ] = $cgiparams { 'CCD_DNS2' };
3965 $confighash { $key }[ 37 ] = $cgiparams { 'CCD_WINS' };
3966 $confighash { $key }[ 38 ] = $cgiparams { 'PMTU_DISCOVERY' };
3969 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3971 if ( $cgiparams { 'CHECK1' } ){
3973 my ( $ccdip , $ccdsub )= split "/" , $cgiparams { $name };
3974 my ( $a , $b , $c , $d ) = split ( /\./ , $ccdip );
3975 if ( - e
"${General::swroot}/ovpn/ccd/ $confighash { $key }[2]" ){ unlink "${General::swroot}/ovpn/ccd/ $cgiparams {'CERT_NAME'}" ;}
3976 open ( CCDRWCONF
, '>' , "${General::swroot}/ovpn/ccd/ $confighash { $key }[2]" ) or die "Unable to create clientconfigfile $!" ;
3977 print CCDRWCONF
"# OpenVPN Clientconfig from CCD extension by Copymaster# \n\n " ;
3978 if ( $cgiparams { 'CHECK1' } eq 'dynamic' ){
3979 print CCDRWCONF
"#This client uses the dynamic pool \n " ;
3981 print CCDRWCONF
"#Ip address client and Server \n " ;
3982 print CCDRWCONF
"ifconfig-push $ccdip " .& General
:: getlastip
( $ccdip , 1 ). " \n " ;
3984 if ( $confighash { $key }[ 34 ] eq 'on' ){
3985 print CCDRWCONF
" \n #Redirect Gateway: \n #All IP traffic is redirected through the vpn \n " ;
3986 print CCDRWCONF
"push redirect-gateway \n " ;
3988 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3989 if ( $cgiparams { 'IR' } ne '' ){
3990 print CCDRWCONF
" \n #Client routes these Networks (behind Client) \n " ;
3991 foreach my $key ( keys %ccdroutehash ){
3992 if ( $ccdroutehash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
3993 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}){
3994 my ( $a , $b )= split ( /\/ /, $ccdroutehash { $key }[ $i ]);
3995 print CCDRWCONF
"iroute $a $b \n " ;
4000 if ( $cgiparams { 'IFROUTE' } eq $Lang :: tr
{ 'ccd none' } ){ $cgiparams { 'IFROUTE' }= '' ;}
4001 if ( $cgiparams { 'IFROUTE' } ne '' ){
4002 print CCDRWCONF
" \n #Client gets routes to these Networks (behind IPFIRE) \n " ;
4003 foreach my $key ( keys %ccdroute2hash ){
4004 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4005 foreach my $i ( 1 .. $ #{$ccdroute2hash{$key}}){
4006 if ( $ccdroute2hash { $key }[ $i ] eq $Lang :: tr
{ 'blue' }){
4008 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%blue );
4009 print CCDRWCONF
"push \" route $blue {BLUE_ADDRESS} $blue {BLUE_NETMASK} \n " ;
4010 } elsif ( $ccdroute2hash { $key }[ $i ] eq $Lang :: tr
{ 'orange' }){
4012 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%orange );
4013 print CCDRWCONF
"push \" route $orange {ORANGE_ADDRESS} $orange {ORANGE_NETMASK} \n " ;
4015 my ( $a , $b )= split ( /\/ /, $ccdroute2hash { $key }[ $i ]);
4016 print CCDRWCONF
"push \" route $a $b \"\n " ;
4022 if (( $cgiparams { 'CCD_DNS1' } eq '' ) && ( $cgiparams { 'CCD_DNS1' } ne '' )){ $cgiparams { 'CCD_DNS1' } = $cgiparams { 'CCD_DNS2' }; $cgiparams { 'CCD_DNS2' }= '' ;}
4023 if ( $cgiparams { 'CCD_DNS1' } ne '' ){
4024 print CCDRWCONF
" \n #Client gets these Nameservers \n " ;
4025 print CCDRWCONF
"push \" dhcp-option DNS $cgiparams {'CCD_DNS1'} \" \n " ;
4027 if ( $cgiparams { 'CCD_DNS2' } ne '' ){
4028 print CCDRWCONF
"push \" dhcp-option DNS $cgiparams {'CCD_DNS2'} \" \n " ;
4030 if ( $cgiparams { 'CCD_WINS' } ne '' ){
4031 print CCDRWCONF
" \n #Client gets this WINS server \n " ;
4032 print CCDRWCONF
"push \" dhcp-option WINS $cgiparams {'CCD_WINS'} \" \n " ;
4041 if ( $cgiparams { 'TYPE' } eq 'net' ) {
4043 if (- e
"/var/run/ $confighash { $key }[1]n2n.pid" ) {
4044 system ( '/usr/local/bin/openvpnctrl' , '-kn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
4046 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
4047 my $key = $cgiparams { 'KEY' };
4049 $key = & General
:: findhasharraykey
( \
%confighash );
4050 foreach my $i ( 0 .. 31 ) { $confighash { $key }[ $i ] = "" ;}
4052 $confighash { $key }[ 0 ] = 'on' ;
4053 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
4055 system ( '/usr/local/bin/openvpnctrl' , '-sn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
4063 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
4064 $cgiparams { 'KEY' } = $key ;
4065 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
4069 $cgiparams { 'ENABLED' } = 'on' ;
4073 $cgiparams { 'MSSFIX' } = 'on' ;
4074 $cgiparams { 'FRAGMENT' } = '1300' ;
4075 $cgiparams { 'PMTU_DISCOVERY' } = 'off' ;
4079 $cgiparams { 'SIDE' } = 'left' ;
4080 if ( ! - f
"${General::swroot}/ovpn/ca/cakey.pem" ) {
4081 $cgiparams { 'AUTH' } = 'psk' ;
4082 } elsif ( ! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
4083 $cgiparams { 'AUTH' } = 'certfile' ;
4085 $cgiparams { 'AUTH' } = 'certgen' ;
4087 $cgiparams { 'LOCAL_SUBNET' } = " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" ;
4088 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
4089 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
4090 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
4091 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
4095 $checked { 'ENABLED' }{ 'off' } = '' ;
4096 $checked { 'ENABLED' }{ 'on' } = '' ;
4097 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = 'CHECKED' ;
4098 $checked { 'ENABLED_BLUE' }{ 'off' } = '' ;
4099 $checked { 'ENABLED_BLUE' }{ 'on' } = '' ;
4100 $checked { 'ENABLED_BLUE' }{ $cgiparams { 'ENABLED_BLUE' }} = 'CHECKED' ;
4101 $checked { 'ENABLED_ORANGE' }{ 'off' } = '' ;
4102 $checked { 'ENABLED_ORANGE' }{ 'on' } = '' ;
4103 $checked { 'ENABLED_ORANGE' }{ $cgiparams { 'ENABLED_ORANGE' }} = 'CHECKED' ;
4106 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
4107 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
4108 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = 'CHECKED' ;
4110 $selected { 'SIDE' }{ 'server' } = '' ;
4111 $selected { 'SIDE' }{ 'client' } = '' ;
4112 $selected { 'SIDE' }{ $cgiparams { 'SIDE' }} = 'SELECTED' ;
4114 $selected { 'PROTOCOL' }{ 'udp' } = '' ;
4115 $selected { 'PROTOCOL' }{ 'tcp' } = '' ;
4116 $selected { 'PROTOCOL' }{ $cgiparams { 'PROTOCOL' }} = 'SELECTED' ;
4119 $checked { 'AUTH' }{ 'psk' } = '' ;
4120 $checked { 'AUTH' }{ 'certreq' } = '' ;
4121 $checked { 'AUTH' }{ 'certgen' } = '' ;
4122 $checked { 'AUTH' }{ 'certfile' } = '' ;
4123 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = 'CHECKED' ;
4125 $selected { 'INTERFACE' }{ $cgiparams { 'INTERFACE' }} = 'SELECTED' ;
4127 $checked { 'COMPLZO' }{ 'off' } = '' ;
4128 $checked { 'COMPLZO' }{ 'on' } = '' ;
4129 $checked { 'COMPLZO' }{ $cgiparams { 'COMPLZO' }} = 'CHECKED' ;
4131 $checked { 'MSSFIX' }{ 'off' } = '' ;
4132 $checked { 'MSSFIX' }{ 'on' } = '' ;
4133 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
4135 $checked { 'PMTU_DISCOVERY' }{ $cgiparams { 'PMTU_DISCOVERY' }} = 'checked= \' checked \' ' ;
4139 & Header
:: showhttpheaders
();
4140 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
4141 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
4142 if ( $errormessage ) {
4143 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
4144 print "<class name='base'> $errormessage " ;
4145 print " </class>" ;
4146 & Header
:: closebox
();
4150 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'warning messages'}:" );
4151 print "<class name='base'> $warnmessage " ;
4152 print " </class>" ;
4153 & Header
:: closebox
();
4156 print "<form method='post' enctype='multipart/form-data'>" ;
4157 print "<input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />" ;
4159 if ( $cgiparams { 'KEY' }) {
4160 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
4161 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
4164 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'connection'}:" );
4165 print "<table width='100%' border='0'> \n " ;
4169 print "<tr><td width='14%' class='boldbase'> $Lang ::tr{'name'}: </td>" ;
4171 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4172 if ( $cgiparams { 'KEY' }) {
4173 print "<td width='35%' class='base'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /> $cgiparams {'NAME'}</td>" ;
4176 print "<td width='35%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' maxlength='20' size='30' /></td>" ;
4178 # print "<tr><td>$Lang::tr{'interface'}</td>";
4179 # print "<td><select name='INTERFACE'>";
4180 # print "<option value='RED' $selected{'INTERFACE'}{'RED'}>RED</option>";
4181 # if ($netsettings{'BLUE_DEV'} ne '') {
4182 # print "<option value='BLUE' $selected{'INTERFACE'}{'BLUE'}>BLUE</option>";
4184 # print "<option value='GREEN' $selected{'INTERFACE'}{'GREEN'}>GREEN</option>";
4185 # print "<option value='ORANGE' $selected{'INTERFACE'}{'ORANGE'}>ORANGE</option>";
4186 # print "</select></td></tr>";
4189 print "<input type='hidden' name='INTERFACE' value='red' />" ;
4190 if ( $cgiparams { 'KEY' }) {
4191 print "<td width='25%' class='base' nowrap='nowrap'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /> $cgiparams {'NAME'}</td>" ;
4193 print "<td width='25%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' maxlength='20' /></td>" ;
4199 <td width='25%'> </td>
4200 <td width='25%'> </td></tr>
4201 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'Act as'}</td>
4202 <td><select name='SIDE'><option value='server' $selected {'SIDE'}{'server'}> $Lang ::tr{'openvpn server'}</option>
4203 <option value='client' $selected {'SIDE'}{'client'}> $Lang ::tr{'openvpn client'}</option></select></td>
4204 <td class='boldbase'> $Lang ::tr{'remote host/ip'}:</td>
4205 <td><input type='TEXT' name='REMOTE' value=' $cgiparams {'REMOTE'}' /></td></tr>
4206 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'}</td>
4207 <td><input type='TEXT' name='LOCAL_SUBNET' value=' $cgiparams {'LOCAL_SUBNET'}' /></td>
4208 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'}</td>
4209 <td><input type='text' name='REMOTE_SUBNET' value=' $cgiparams {'REMOTE_SUBNET'}' /></td></tr>
4210 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn subnet'}</td>
4211 <td><input type='TEXT' name='OVPN_SUBNET' value=' $cgiparams {'OVPN_SUBNET'}' /></td></tr>
4212 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td>
4214 <td><select name='PROTOCOL'><option value='udp' $selected {'PROTOCOL'}{'udp'}>UDP</option>
4215 <option value='tcp' $selected {'PROTOCOL'}{'tcp'}>TCP</option></select></td>
4217 <td class='boldbase'> $Lang ::tr{'destination port'}:</td>
4218 <td><input type='TEXT' name='DEST_PORT' value=' $cgiparams {'DEST_PORT'}' size='5' /></td></tr>
4219 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'} <img src='/blob.gif'</td>
4220 <td><input type='checkbox' name='COMPLZO' $checked {'COMPLZO'}{'on'} /></td>
4222 <tr><td class='boldbase' nowrap='nowrap'>mssfix <img src='/blob.gif' /></td>
4223 <td><input type='checkbox' name='MSSFIX' $checked {'MSSFIX'}{'on'} /></td>
4224 <td> $Lang ::tr{'openvpn default'}: <span class="base">on</span></td>
4226 <tr><td class='boldbase' nowrap='nowrap'>fragment <img src='/blob.gif' /></td>
4227 <td><input type='TEXT' name='FRAGMENT' VALUE=' $cgiparams {'FRAGMENT'}'size='5' /></td>
4228 <td> $Lang ::tr{'openvpn default'}: <span class="base">1300</span></td>
4230 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'} <img src='/blob.gif' /></td>
4231 <td> <input type='TEXT' name='MTU' VALUE=' $cgiparams {'MTU'}'size='5' /></td>
4232 <td colspan='2'> $Lang ::tr{'openvpn default'}: udp/tcp <span class="base">1500/1400</span></td>
4234 <tr><td class='boldbase' nowrap='nowrap'>Management Port <img src='/blob.gif' /></td>
4235 <td> <input type='TEXT' name='OVPN_MGMT' VALUE=' $cgiparams {'OVPN_MGMT'}'size='5' /></td>
4236 <td colspan='2'> $Lang ::tr{'openvpn default'}: <span class="base"> $Lang ::tr{'destination port'}</span></td>
4239 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn mtu-disc'}</td>
4241 <input type='radio' name='PMTU_DISCOVERY' value='yes' $checked {'PMTU_DISCOVERY'}{'yes'} /> $Lang ::tr{'ovpn mtu-disc yes'}
4242 <input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked {'PMTU_DISCOVERY'}{'maybe'} /> $Lang ::tr{'ovpn mtu-disc maybe'}
4243 <input type='radio' name='PMTU_DISCOVERY' value='no' $checked {'PMTU_DISCOVERY'}{'no'} /> $Lang ::tr{'ovpn mtu-disc no'}
4244 <input type='radio' name='PMTU_DISCOVERY' value='off' $checked {'PMTU_DISCOVERY'}{'off'} /> $Lang ::tr{'ovpn mtu-disc off'}
4252 print "<tr><td class='boldbase'> $Lang ::tr{'remark title'} <img src='/blob.gif' /></td>" ;
4253 print "<td colspan='3'><input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' size='55' maxlength='50' /></td></tr></table>" ;
4255 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4256 print "<tr><td> $Lang ::tr{'enabled'} <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>" ;
4259 print "</tr></table><br><br>" ;
4260 #A.Marx CCD new client
4261 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4262 print "<table border='0' width='100%' cellspacing='1' cellpadding='0'><tr><td colspan='3'><hr><br><b> $Lang ::tr{'ccd choose net'}</td></tr><tr><td height='20' colspan='3'></td></tr>" ;
4265 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnnet );
4266 $vpnip = $vpnnet { 'DOVPN_SUBNET' };
4267 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
4271 $checked { 'check1' }{ 'off' } = '' ;
4272 $checked { 'check1' }{ 'on' } = '' ;
4273 $checked { 'check1' }{ $cgiparams { 'CHECK1' }} = 'CHECKED' ;
4274 print "<tr><td align='center' width='1%' valign='top'><input type='radio' name='CHECK1' value='dynamic' checked /></td><td align='left' valign='top' width='35%'> $Lang ::tr{'ccd dynrange'} ( $vpnip )</td><td width='30%'>" ;
4275 print "</td></tr></table><br><br>" ;
4276 my $name = $cgiparams { 'CHECK1' };
4277 $checked { 'RG' }{ $cgiparams { 'RG' }} = 'CHECKED' ;
4279 if (! - z
"${General::swroot}/ovpn/ccd.conf" ){
4280 print "<table border='0' width='100%' cellspacing='1' cellpadding='0'><tr><td width='1%'></td><td width='30%' class='boldbase' align='center'><b> $Lang ::tr{'ccd name'}</td><td width='15%' class='boldbase' align='center'><b> $Lang ::tr{'network'}</td><td class='boldbase' align='center' width='18%'><b> $Lang ::tr{'ccd clientip'}</td></tr>" ;
4281 foreach my $key ( keys %ccdconfhash ) {
4283 @ccdconf =( $ccdconfhash { $key }[ 0 ], $ccdconfhash { $key }[ 1 ]);
4284 if ( $count % 2 ){ print "<tr bgcolor=' $color {'color22'}'>" ;} else { print "<tr bgcolor=' $color {'color20'}'>" ;}
4285 print "<td align='center' width='1%'><input type='radio' name='CHECK1' value=' $ccdconf [0]' $checked {'check1'}{ $ccdconf [0]}/></td><td> $ccdconf [0]</td><td width='40%' align='center'> $ccdconf [1]</td><td align='left' width='10%'>" ;
4286 & fillselectbox
( $ccdconf [ 1 ], $ccdconf [ 0 ], $cgiparams { $name });
4289 print "</table><br><br><hr><br><br>" ;
4293 & Header
:: closebox
();
4294 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
4296 } elsif (! $cgiparams { 'KEY' }) {
4300 my $cakeydisabled = '' ;
4301 my $cacrtdisabled = '' ;
4302 if ( ! - f
"${General::swroot}/ovpn/ca/cakey.pem" ) { $cakeydisabled = "disabled='disabled'" } else { $cakeydisabled = "" };
4303 if ( ! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) { $cacrtdisabled = "disabled='disabled'" } else { $cacrtdisabled = "" };
4305 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'authentication' });
4308 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4311 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
4313 <tr><td><input type='radio' name='AUTH' value='certreq' $checked {'AUTH'}{'certreq'} $cakeydisabled /></td><td class='base'> $Lang ::tr{'upload a certificate request'}</td><td class='base' rowspan='2'><input type='file' name='FH' size='30' $cacrtdisabled ></td></tr>
4314 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td><td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
4315 <tr><td colspan='3'> </td></tr>
4316 <tr><td colspan='3'><hr /></td></tr>
4317 <tr><td colspan='3'> </td></tr>
4318 <tr><td><input type='radio' name='AUTH' value='certgen' $checked {'AUTH'}{'certgen'} $cakeydisabled /></td><td class='base'> $Lang ::tr{'generate a certificate'}</td><td> </td></tr>
4319 <tr><td> </td><td class='base'> $Lang ::tr{'users fullname or system hostname'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' SIZE='32' $cakeydisabled /></td></tr>
4320 <tr><td> </td><td class='base'> $Lang ::tr{'users email'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' SIZE='32' $cakeydisabled /></td></tr>
4321 <tr><td> </td><td class='base'> $Lang ::tr{'users department'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' SIZE='32' $cakeydisabled /></td></tr>
4322 <tr><td> </td><td class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' SIZE='32' $cakeydisabled /></td></tr>
4323 <tr><td> </td><td class='base'> $Lang ::tr{'city'}: <img src='/blob.gif'></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' SIZE='32' $cakeydisabled /></td></tr>
4324 <tr><td> </td><td class='base'> $Lang ::tr{'state or province'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' SIZE='32' $cakeydisabled /></td></tr>
4325 <tr><td> </td><td class='base'> $Lang ::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
4336 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
4338 <tr><td><input type='radio' name='AUTH' value='certgen' $checked {'AUTH'}{'certgen'} $cakeydisabled /></td><td class='base'> $Lang ::tr{'generate a certificate'}</td><td> </td></tr>
4339 <tr><td> </td><td class='base'> $Lang ::tr{'users fullname or system hostname'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' SIZE='32' $cakeydisabled /></td></tr>
4340 <tr><td> </td><td class='base'> $Lang ::tr{'users email'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' SIZE='32' $cakeydisabled /></td></tr>
4341 <tr><td> </td><td class='base'> $Lang ::tr{'users department'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' SIZE='32' $cakeydisabled /></td></tr>
4342 <tr><td> </td><td class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' SIZE='32' $cakeydisabled /></td></tr>
4343 <tr><td> </td><td class='base'> $Lang ::tr{'city'}: <img src='/blob.gif'></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' SIZE='32' $cakeydisabled /></td></tr>
4344 <tr><td> </td><td class='base'> $Lang ::tr{'state or province'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' SIZE='32' $cakeydisabled /></td></tr>
4345 <tr><td> </td><td class='base'> $Lang ::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
4357 foreach my $country ( sort keys %{ Countries
:: countries
}) {
4358 print "<option value=' $Countries ::countries{ $country }'" ;
4359 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
4360 print " selected='selected'" ;
4362 print "> $country </option>" ;
4368 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4372 <td> </td><td class='base'> $Lang ::tr{'valid till'} (days):</td>
4373 <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value=' $cgiparams {'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr>
4375 <td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
4376 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
4377 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'}:<BR>( $Lang ::tr{'confirmation'})</td>
4378 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
4379 <tr><td colspan='3'> </td></tr>
4380 <tr><td colspan='3'><hr /></td></tr>
4381 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
4387 <tr><td> </td><td> </td><td> </td></tr>
4388 <tr><td> </td><td> </td><td> </td></tr>
4389 <tr><td colspan='3'><hr /></td></tr>
4390 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
4400 & Header
:: closebox
();
4404 #A.Marx CCD new client
4405 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4407 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'ccd client options'}:" );
4411 <table border='0' width='100%'>
4412 <tr><td width='20%'>Redirect Gateway:</td><td colspan='3'><input type='checkbox' name='RG' $checked {'RG'}{'on'} /></td></tr>
4413 <tr><td colspan='4'><b><br> $Lang ::tr{'ccd routes'}</b></td></tr>
4414 <tr><td colspan='4'> </td></tr>
4415 <tr><td valign='top'> $Lang ::tr{'ccd iroute'}</td><td align='left' width='30%'><textarea name='IR' cols='26' rows='6' wrap='off'>
4418 if ( $cgiparams { 'IR' } ne '' ){
4419 print $cgiparams { 'IR' };
4421 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
4422 foreach my $key ( keys %ccdroutehash ) {
4423 if ( $cgiparams { 'NAME' } eq $ccdroutehash { $key }[ 0 ]){
4424 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}) {
4425 if ( $ccdroutehash { $key }[ $i ] ne '' ){
4426 print $ccdroutehash { $key }[ $i ]. " \n " ;
4428 $cgiparams { 'IR' } .= $ccdroutehash { $key }[ $i ];
4435 </textarea></td><td valign='top' colspan='2'> $Lang ::tr{'ccd iroutehint'}</td></tr>
4436 <tr><td colspan='4'><br></td></tr>
4437 <tr><td valign='top' rowspan='3'> $Lang ::tr{'ccd iroute2'}</td><td align='left' valign='top' rowspan='3'><select name='IFROUTE' style="width: 205px"; size='6' multiple>
4450 open ( FILE
, "${General::swroot}/main/routing" ) ;
4453 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
4454 print "<option> $Lang ::tr{'ccd none'}</option>" ;
4455 #check if static routes are defined for client
4456 foreach my $line ( @current ) {
4458 $line =~ s/\s*$//g ; # remove newline
4459 @temp = split ( /\,/ , $line );
4460 $temp [ 1 ] = '' unless defined $temp [ 1 ]; # not always populated
4461 my ( $a , $b ) = split ( /\/ /, $temp [ 1 ]);
4462 $temp [ 1 ] = $a . "/" .& General
:: iporsubtocidr
( $b );
4463 foreach my $key ( keys %ccdroute2hash ) {
4464 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4465 foreach my $i ( 1 .. $ #{$ccdroute2hash{$key}}) {
4466 if ( $ccdroute2hash { $key }[ $i ] eq $a . "/" .& General
:: iporsubtodec
( $b )){
4472 if ( $set == '1' && $#temp != - 1 ){ print "<option selected> $temp [1]</option>" ; $set = 0 ;} elsif ( $set == '0' && $#temp != - 1 ){ print "<option> $temp [1]</option>" ;}
4474 #check if green,blue,orange are defined for client
4475 foreach my $key ( keys %ccdroute2hash ) {
4476 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4478 foreach my $i ( 1 .. $ #{$ccdroute2hash{$key}}) {
4479 if ( $ccdroute2hash { $key }[ $i ] eq $netsettings { 'GREEN_NETADDRESS' }. "/" .& General
:: iporsubtodec
( $netsettings { 'GREEN_NETMASK' })){
4482 if (& haveBlueNet
()){
4483 if ( $ccdroute2hash { $key }[ $i ] eq $netsettings { 'BLUE_NETADDRESS' }. "/" .& General
:: iporsubtodec
( $netsettings { 'BLUE_NETMASK' })) {
4487 if (& haveOrangeNet
()){
4488 if ( $ccdroute2hash { $key }[ $i ] eq $netsettings { 'ORANGE_NETADDRESS' }. "/" .& General
:: iporsubtodec
( $netsettings { 'ORANGE_NETMASK' }) ) {
4495 if (& haveBlueNet
() && $selblue == '1' ){ print "<option selected> $Lang ::tr{'blue'}</option>" ; $selblue = 0 ;} elsif (& haveBlueNet
() && $selblue == '0' ){ print "<option> $Lang ::tr{'blue'}</option>" ;}
4496 if (& haveOrangeNet
() && $selorange == '1' ){ print "<option selected> $Lang ::tr{'orange'}</option>" ; $selorange = 0 ;} elsif (& haveOrangeNet
() && $selorange == '0' ){ print "<option> $Lang ::tr{'orange'}</option>" ;}
4497 if ( $selgreen == '1' || $other == '0' ){ print "<option selected> $Lang ::tr{'green'}</option>" ; $set = 0 ;} else { print "<option> $Lang ::tr{'green'}</option>" ;};
4500 </select></td><td valign='top'>DNS1:</td><td valign='top'><input type='TEXT' name='CCD_DNS1' value=' $cgiparams {'CCD_DNS1'}' size='30' /></td></tr>
4501 <tr valign='top'><td>DNS2:</td><td><input type='TEXT' name='CCD_DNS2' value=' $cgiparams {'CCD_DNS2'}' size='30' /></td></tr>
4502 <tr valign='top'><td valign='top'>WINS:</td><td><input type='TEXT' name='CCD_WINS' value=' $cgiparams {'CCD_WINS'}' size='30' /></td></tr></table><br><hr>
4506 & Header
:: closebox
();
4508 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
4509 if ( $cgiparams { 'KEY' }) {
4510 # print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />";
4512 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
4513 & Header
:: closebigbox
();
4514 & Header
:: closepage
();
4522 ### Default status page
4527 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%cgiparams );
4528 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
4529 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
4531 my @status = `/bin/cat /var/log/ovpnserver.log` ;
4533 if ( $cgiparams { 'VPN_IP' } eq '' && - e
"${General::swroot}/red/active" ) {
4534 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
4535 my $ipaddr = < IPADDR
>;
4538 $cgiparams { 'VPN_IP' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
4539 if ( $cgiparams { 'VPN_IP' } eq '' ) {
4540 $cgiparams { 'VPN_IP' } = $ipaddr ;
4546 if ( $cgiparams { 'DCIPHER' } eq '' ) {
4547 $cgiparams { 'DCIPHER' } = 'BF-CBC' ;
4549 if ( $cgiparams { 'DDEST_PORT' } eq '' ) {
4550 $cgiparams { 'DDEST_PORT' } = '1194' ;
4552 if ( $cgiparams { 'DMTU' } eq '' ) {
4553 $cgiparams { 'DMTU' } = '1400' ;
4555 if ( $cgiparams { 'DOVPN_SUBNET' } eq '' ) {
4556 $cgiparams { 'DOVPN_SUBNET' } = '10.' . int ( rand ( 256 )) . '.' . int ( rand ( 256 )) . '.0/255.255.255.0' ;
4558 $checked { 'ENABLED' }{ 'off' } = '' ;
4559 $checked { 'ENABLED' }{ 'on' } = '' ;
4560 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = 'CHECKED' ;
4561 $checked { 'ENABLED_BLUE' }{ 'off' } = '' ;
4562 $checked { 'ENABLED_BLUE' }{ 'on' } = '' ;
4563 $checked { 'ENABLED_BLUE' }{ $cgiparams { 'ENABLED_BLUE' }} = 'CHECKED' ;
4564 $checked { 'ENABLED_ORANGE' }{ 'off' } = '' ;
4565 $checked { 'ENABLED_ORANGE' }{ 'on' } = '' ;
4566 $checked { 'ENABLED_ORANGE' }{ $cgiparams { 'ENABLED_ORANGE' }} = 'CHECKED' ;
4567 $selected { 'DDEVICE' }{ 'tun' } = '' ;
4568 $selected { 'DDEVICE' }{ 'tap' } = '' ;
4569 $selected { 'DDEVICE' }{ $cgiparams { 'DDEVICE' }} = 'SELECTED' ;
4571 $selected { 'DPROTOCOL' }{ 'udp' } = '' ;
4572 $selected { 'DPROTOCOL' }{ 'tcp' } = '' ;
4573 $selected { 'DPROTOCOL' }{ $cgiparams { 'DPROTOCOL' }} = 'SELECTED' ;
4575 $selected { 'DCIPHER' }{ 'DES-CBC' } = '' ;
4576 $selected { 'DCIPHER' }{ 'DES-EDE-CBC' } = '' ;
4577 $selected { 'DCIPHER' }{ 'DES-EDE3-CBC' } = '' ;
4578 $selected { 'DCIPHER' }{ 'DESX-CBC' } = '' ;
4579 $selected { 'DCIPHER' }{ 'RC2-CBC' } = '' ;
4580 $selected { 'DCIPHER' }{ 'RC2-40-CBC' } = '' ;
4581 $selected { 'DCIPHER' }{ 'RC2-64-CBC' } = '' ;
4582 $selected { 'DCIPHER' }{ 'BF-CBC' } = '' ;
4583 $selected { 'DCIPHER' }{ 'CAST5-CBC' } = '' ;
4584 $selected { 'DCIPHER' }{ 'AES-128-CBC' } = '' ;
4585 $selected { 'DCIPHER' }{ 'AES-192-CBC' } = '' ;
4586 $selected { 'DCIPHER' }{ 'AES-256-CBC' } = '' ;
4587 $selected { 'DCIPHER' }{ $cgiparams { 'DCIPHER' }} = 'SELECTED' ;
4588 $checked { 'DCOMPLZO' }{ 'off' } = '' ;
4589 $checked { 'DCOMPLZO' }{ 'on' } = '' ;
4590 $checked { 'DCOMPLZO' }{ $cgiparams { 'DCOMPLZO' }} = 'CHECKED' ;
4592 $checked { 'MSSFIX' }{ 'off' } = '' ;
4593 $checked { 'MSSFIX' }{ 'on' } = '' ;
4594 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
4596 & Header
:: showhttpheaders
();
4597 & Header
:: openpage
( $Lang :: tr
{ 'status ovpn' }, 1 , '' );
4598 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
4600 if ( $errormessage ) {
4601 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
4602 print "<class name='base'> $errormessage \n " ;
4603 print " </class> \n " ;
4604 & Header
:: closebox
();
4607 my $sactive = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourred}' width='50%'><tr><td align='center'><b><font color='#FFFFFF'> $Lang ::tr{'stopped'}</font></b></td></tr></table>" ;
4608 my $srunning = "no" ;
4609 my $activeonrun = "" ;
4610 if ( - e
"/var/run/openvpn.pid" ){
4611 $sactive = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourgreen}' width='50%'><tr><td align='center'><b><font color='#FFFFFF'> $Lang ::tr{'running'}</font></b></td></tr></table>" ;
4615 $activeonrun = "disabled='disabled'" ;
4617 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'global settings' });
4619 <table width='100%' border=0>
4620 <form method='post'>
4621 <td width='25%'> </td>
4622 <td width='25%'> </td>
4623 <td width='25%'> </td></tr>
4624 <tr><td class='boldbase'> $Lang ::tr{'ovpn server status'}</td>
4625 <td align='left'> $sactive </td>
4626 <tr><td class='boldbase'> $Lang ::tr{'ovpn on red'}</td>
4627 <td><input type='checkbox' name='ENABLED' $checked {'ENABLED'}{'on'} /></td>
4630 if (& haveBlueNet
()) {
4631 print "<tr><td class='boldbase'> $Lang ::tr{'ovpn on blue'}</td>" ;
4632 print "<td><input type='checkbox' name='ENABLED_BLUE' $checked {'ENABLED_BLUE'}{'on'} /></td>" ;
4634 if (& haveOrangeNet
()) {
4635 print "<tr><td class='boldbase'> $Lang ::tr{'ovpn on orange'}</td>" ;
4636 print "<td><input type='checkbox' name='ENABLED_ORANGE' $checked {'ENABLED_ORANGE'}{'on'} /></td>" ;
4639 <tr><td class='base' nowrap='nowrap' colspan='2'> $Lang ::tr{'local vpn hostname/ip'}:<br /><input type='text' name='VPN_IP' value=' $cgiparams {'VPN_IP'}' size='30' /></td>
4640 <td class='boldbase' nowrap='nowrap' colspan='2'> $Lang ::tr{'ovpn subnet'}<br /><input type='TEXT' name='DOVPN_SUBNET' value=' $cgiparams {'DOVPN_SUBNET'}' size='30' /></td></tr>
4641 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn device'}</td>
4642 <td><select name='DDEVICE' ><option value='tun' $selected {'DDEVICE'}{'tun'}>TUN</option>
4643 <!-- this is still not working
4644 <option value='tap' $selected {'DDEVICE'}{'tap'}>TAP</option></select>--> </td>
4645 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td>
4646 <td><select name='DPROTOCOL'><option value='udp' $selected {'DPROTOCOL'}{'udp'}>UDP</option>
4647 <option value='tcp' $selected {'DPROTOCOL'}{'tcp'}>TCP</option></select></td>
4648 <td class='boldbase'> $Lang ::tr{'destination port'}:</td>
4649 <td><input type='TEXT' name='DDEST_PORT' value=' $cgiparams {'DDEST_PORT'}' size='5' /></td></tr>
4650 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'} </td>
4651 <td> <input type='TEXT' name='DMTU' VALUE=' $cgiparams {'DMTU'}'size='5' /></TD>
4652 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'}</td>
4653 <td><input type='checkbox' name='DCOMPLZO' $checked {'DCOMPLZO'}{'on'} /></td>
4654 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'cipher'}</td>
4655 <td><select name='DCIPHER'><option value='DES-CBC' $selected {'DCIPHER'}{'DES-CBC'}>DES-CBC</option>
4656 <option value='DES-EDE-CBC' $selected {'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC</option>
4657 <option value='DES-EDE3-CBC' $selected {'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC</option>
4658 <option value='DESX-CBC' $selected {'DCIPHER'}{'DESX-CBC'}>DESX-CBC</option>
4659 <option value='RC2-CBC' $selected {'DCIPHER'}{'RC2-CBC'}>RC2-CBC</option>
4660 <option value='RC2-40-CBC' $selected {'DCIPHER'}{'RC2-40-CBC'}>RC2-40-CBC</option>
4661 <option value='RC2-64-CBC' $selected {'DCIPHER'}{'RC2-64-CBC'}>RC2-64-CBC</option>
4662 <option value='BF-CBC' $selected {'DCIPHER'}{'BF-CBC'}>BF-CBC</option>
4663 <option value='CAST5-CBC' $selected {'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC</option>
4664 <option value='AES-128-CBC' $selected {'DCIPHER'}{'AES-128-CBC'}>AES-128-CBC</option>
4665 <option value='AES-192-CBC' $selected {'DCIPHER'}{'AES-192-CBC'}>AES-192-CBC</option>
4666 <option value='AES-256-CBC' $selected {'DCIPHER'}{'AES-256-CBC'}>AES-256-CBC</option></select></td></tr>
4667 <tr><td colspan='4'><hr /></td></tr>
4671 if ( $srunning eq "yes" ) {
4672 print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' disabled='disabled' />" ;
4673 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'ccd net'}' />" ;
4674 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced server'}' />" ;
4675 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'stop ovpn server'}' /></td></tr>" ;
4677 print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
4678 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'ccd net'}' />" ;
4679 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced server'}' />" ;
4680 if (( - e
"${General::swroot}/ovpn/ca/cacert.pem" &&
4681 - e
"${General::swroot}/ovpn/ca/dh1024.pem" &&
4682 - e
"${General::swroot}/ovpn/certs/servercert.pem" &&
4683 - e
"${General::swroot}/ovpn/certs/serverkey.pem" ) &&
4684 (( $cgiparams { 'ENABLED' } eq 'on' ) ||
4685 ( $cgiparams { 'ENABLED_BLUE' } eq 'on' ) ||
4686 ( $cgiparams { 'ENABLED_ORANGE' } eq 'on' ))){
4687 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'start ovpn server'}' /></td></tr>" ;
4689 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'start ovpn server'}' disabled='disabled' /></td></tr>" ;
4692 print "</form></table>" ;
4693 & Header
:: closebox
();
4694 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'certificate authorities'}:" );
4696 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
4698 <td width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></td>
4699 <td width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></td>
4700 <td width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></td>
4704 if (- f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
4705 my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem` ;
4706 $casubject =~ /Subject: (.*)[\n]/ ;
4708 $casubject =~ s
+/ Email
+, E
+;
4709 $casubject =~ s/ ST=/ S=/ ;
4712 <tr bgcolor=' $color {'color22'}'>
4713 <td class='base'> $Lang ::tr{'root certificate'}</td>
4714 <td class='base'> $casubject </td>
4715 <form method='post' name='frmrootcrta'><td width='3%' align='center'>
4716 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
4717 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/info.gif' alt=' $Lang ::tr{'show root certificate'}' title=' $Lang ::tr{'show root certificate'}' width='20' height='20' border='0' />
4719 <form method='post' name='frmrootcrtb'><td width='3%' align='center'>
4720 <input type='image' name=' $Lang ::tr{'download root certificate'}' src='/images/media-floppy.png' alt=' $Lang ::tr{'download root certificate'}' title=' $Lang ::tr{'download root certificate'}' border='0' />
4721 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
4723 <td width='4%'> </td></tr>
4727 # display rootcert generation buttons
4729 <tr bgcolor=' $color {'color22'}'>
4730 <td class='base'> $Lang ::tr{'root certificate'}:</td>
4731 <td class='base'> $Lang ::tr{'not present'}</td>
4732 <td colspan='3'> </td></tr>
4737 if (- f
"${General::swroot}/ovpn/certs/servercert.pem" ) {
4738 my $hostsubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem` ;
4739 $hostsubject =~ /Subject: (.*)[\n]/ ;
4741 $hostsubject =~ s
+/ Email
+, E
+;
4742 $hostsubject =~ s/ ST=/ S=/ ;
4745 <tr bgcolor=' $color {'color20'}'>
4746 <td class='base'> $Lang ::tr{'host certificate'}</td>
4747 <td class='base'> $hostsubject </td>
4748 <form method='post' name='frmhostcrta'><td width='3%' align='center'>
4749 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
4750 <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'}' width='20' height='20' border='0' />
4752 <form method='post' name='frmhostcrtb'><td width='3%' align='center'>
4753 <input type='image' name=' $Lang ::tr{'download host certificate'}' src='/images/media-floppy.png' alt=' $Lang ::tr{'download host certificate'}' title=' $Lang ::tr{'download host certificate'}' border='0' />
4754 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download host certificate'}' />
4756 <td width='4%'> </td></tr>
4762 <tr bgcolor=' $color {'color20'}'>
4763 <td width='25%' class='base'> $Lang ::tr{'host certificate'}:</td>
4764 <td class='base'> $Lang ::tr{'not present'}</td>
4765 </td><td colspan='3'> </td></tr>
4770 if (! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
4771 print "<tr><td colspan='5' align='center'><form method='post'>" ;
4772 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' />" ;
4773 print "</form></td></tr> \n " ;
4776 if ( keys %cahash > 0 ) {
4777 foreach my $key ( keys %cahash ) {
4778 if (( $key + 1 ) % 2 ) {
4779 print "<tr bgcolor=' $color {'color20'}'> \n " ;
4781 print "<tr bgcolor=' $color {'color22'}'> \n " ;
4783 print "<td class='base'> $cahash { $key }[0]</td> \n " ;
4784 print "<td class='base'> $cahash { $key }[1]</td> \n " ;
4786 <form method='post' name='cafrm${key}a'><td align='center'>
4787 <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'}' border='0' />
4788 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
4789 <input type='hidden' name='KEY' value=' $key ' />
4791 <form method='post' name='cafrm${key}b'><td align='center'>
4792 <input type='image' name=' $Lang ::tr{'download ca certificate'}' src='/images/media-floppy.png' alt=' $Lang ::tr{'download ca certificate'}' title=' $Lang ::tr{'download ca certificate'}' border='0' />
4793 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
4794 <input type='hidden' name='KEY' value=' $key ' />
4796 <form method='post' name='cafrm${key}c'><td align='center'>
4797 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
4798 <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'}' width='20' height='20' border='0' />
4799 <input type='hidden' name='KEY' value=' $key ' />
4808 # If the file contains entries, print Key to action icons
4809 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
4813 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
4814 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
4815 <td class='base'> $Lang ::tr{'show certificate'}</td>
4816 <td> <img src='/images/media-floppy.png' alt=' $Lang ::tr{'download certificate'}' /></td>
4817 <td class='base'> $Lang ::tr{'download certificate'}</td>
4825 <form method='post' enctype='multipart/form-data'>
4826 <table width='100%' border='0'>
4827 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'ca name'}:</td><td nowrap='nowrap' width='8%'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' align='left'/></td><td nowrap='nowrap' align='right'><input type='file' name='FH' size='25' /><input type='submit' name='ACTION' value=' $Lang ::tr{'upload ca certificate'}' /></td></tr>
4828 <tr><td colspan='4'><hr /></td></tr>
4829 <tr align='right'><td colspan='4' align='right' width='80%'><input type='submit' name='ACTION' value=' $Lang ::tr{'show crl'}' /></td></tr>
4835 & Header
:: closebox
();
4836 if ( $srunning eq "yes" ) {
4837 print "<div align='center'><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'reset'}' disabled='disabled' /></div></form> \n " ;
4839 print "<div align='center'><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'reset'}' /></div></form> \n " ;
4841 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
4845 #<td width='25%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b><br /><img src='/images/null.gif' width='125' height='1' border='0' alt='L2089' /></td>
4848 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'Client status and controlc' });
4852 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
4854 <td width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></td>
4855 <td width='15%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></td>
4856 <td width='22%' class='boldbase' align='center'><b> $Lang ::tr{'network'}</b></td>
4857 <td width='20%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></td>
4858 <td width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></td>
4859 <td width='5%' class='boldbase' colspan='6' align='center'><b> $Lang ::tr{'action'}</b></td>
4865 foreach my $key ( sort { uc ( $confighash { $a }[ 1 ]) cmp uc ( $confighash { $b }[ 1 ]) } keys %confighash ) {
4866 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
4869 print "<tr bgcolor=' $color {'color20'}'> \n " ;
4871 print "<tr bgcolor=' $color {'color22'}'> \n " ;
4873 print "<td align='center' nowrap='nowrap'> $confighash { $key }[1]</td>" ;
4874 print "<td align='center' nowrap='nowrap'>" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ")</td>" ;
4875 #if ($confighash{$key}[4] eq 'cert') {
4876 #print "<td align='left' nowrap='nowrap'>$confighash{$key}[2]</td>";
4878 #print "<td align='left'> </td>";
4880 my $cavalid = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $confighash { $key }[1]cert.pem` ;
4881 $cavalid =~ /Not After : (.*)[\n]/ ;
4883 if ( $confighash { $key }[ 32 ] eq "" && $confighash { $key }[ 3 ] eq 'net' ){ $confighash { $key }[ 32 ]= "net-2-net" ;}
4884 if ( $confighash { $key }[ 32 ] eq "" && $confighash { $key }[ 3 ] eq 'host' ){ $confighash { $key }[ 32 ]= "dynamic" ;}
4885 print "<td align='center'> $confighash { $key }[32]</td>" ;
4886 print "<td align='center'> $confighash { $key }[25]</td>" ;
4888 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>" ;
4890 if ( $confighash { $key }[ 0 ] eq 'off' ) {
4891 $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>" ;
4898 if ( $confighash { $key }[ 3 ] eq 'net' ) {
4900 if (- e
"/var/run/ $confighash { $key }[1]n2n.pid" ) {
4903 my $tport = $confighash { $key }[ 22 ];
4904 my $tnet = new Net
:: Telnet
( Timeout
=> 5 , Errmode
=> 'return' , Port
=> $tport );
4906 $tnet -> open ( '127.0.0.1' );
4907 @output = $tnet -> cmd ( String
=> 'state' , Prompt
=> '/(END.* \n |ERROR:.* \n )/' );
4908 @tustate = split ( /\,/ , $output [ 1 ]);
4910 #CONNECTING -- OpenVPN's initial state.
4911 #WAIT -- (Client only) Waiting for initial response from server.
4912 #AUTH -- (Client only) Authenticating with server.
4913 #GET_CONFIG -- (Client only) Downloading configuration options from server.
4914 #ASSIGN_IP -- Assigning IP address to virtual network interface.
4915 #ADD_ROUTES -- Adding routes to system.
4916 #CONNECTED -- Initialization Sequence Completed.
4917 #RECONNECTING -- A restart has occurred.
4918 #EXITING -- A graceful exit is in progress.
4921 if ( $tustate [ 1 ] eq 'CONNECTED' ) {
4922 $active = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourgreen}' width='100%'><tr><td align='center'><b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b></tr></td></table>" ;
4924 $active = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourred}' width='100%'><tr><td align='center'><b><font color='#FFFFFF'> $tustate [1]</font></b></td></tr></table>" ;
4932 foreach my $line ( @status ) {
4934 if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ ) {
4935 @match = split ( m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ , $line );
4936 if ( $match [ 1 ] ne "Common Name" ) {
4940 if ( $cn eq " $confighash { $key }[2]" ) {
4941 $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>" ;
4950 my $disable_clientdl = "disabled='disabled'" ;
4951 if (( $cgiparams { 'ENABLED' } eq 'on' ) ||
4952 ( $cgiparams { 'ENABLED_BLUE' } eq 'on' ) ||
4953 ( $cgiparams { 'ENABLED_ORANGE' } eq 'on' )){
4954 $disable_clientdl = "" ;
4957 <td align='center'> $active </td>
4959 <form method='post' name='frm${key}a'><td align='center'>
4960 <input type='image' name=' $Lang ::tr{'dl client arch'}' $disable_clientdl src='/images/openvpn.png' alt=' $Lang ::tr{'dl client arch'}' title=' $Lang ::tr{'dl client arch'}' border='0' />
4961 <input type='hidden' name='ACTION' value=' $Lang ::tr{'dl client arch'}' $disable_clientdl />
4962 <input type='hidden' name='KEY' value=' $key ' $disable_clientdl />
4966 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
4968 <form method='post' name='frm${key}b'><td align='center'>
4969 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' border='0' />
4970 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
4971 <input type='hidden' name='KEY' value=' $key ' />
4975 print "<td> </td>" ;
4977 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $key }[1].p12" ) {
4979 <form method='post' name='frm${key}c'><td align='center'>
4980 <input type='image' name=' $Lang ::tr{'download pkcs12 file'}' src='/images/media-floppy.png' alt=' $Lang ::tr{'download pkcs12 file'}' title=' $Lang ::tr{'download pkcs12 file'}' border='0' />
4981 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
4982 <input type='hidden' name='KEY' value=' $key ' />
4985 ; } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
4987 <form method='post' name='frm${key}c'><td align='center'>
4988 <input type='image' name=' $Lang ::tr{'download certificate'}' src='/images/media-floppy.png' alt=' $Lang ::tr{'download certificate'}' title=' $Lang ::tr{'download certificate'}' border='0' />
4989 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
4990 <input type='hidden' name='KEY' value=' $key ' />
4994 print "<td> </td>" ;
4997 <form method='post' name='frm${key}d'><td align='center'>
4998 <input type='image' name=' $Lang ::tr{'toggle enable disable'}' src='/images/ $gif ' alt=' $Lang ::tr{'toggle enable disable'}' title=' $Lang ::tr{'toggle enable disable'}' border='0' />
4999 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
5000 <input type='hidden' name='KEY' value=' $key ' />
5003 <form method='post' name='frm${key}e'><td align='center'>
5004 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
5005 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' title=' $Lang ::tr{'edit'}' width='20' height='20' border='0'/>
5006 <input type='hidden' name='KEY' value=' $key ' />
5008 <form method='post' name='frm${key}f'><td align='center'>
5009 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
5010 <input type='image' name=' $Lang ::tr{'remove'}' src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' title=' $Lang ::tr{'remove'}' width='20' height='20' border='0' />
5011 <input type='hidden' name='KEY' value=' $key ' />
5020 # If the config file contains entries, print Key to action icons
5025 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
5026 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
5027 <td class='base'> $Lang ::tr{'click to disable'}</td>
5028 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
5029 <td class='base'> $Lang ::tr{'show certificate'}</td>
5030 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
5031 <td class='base'> $Lang ::tr{'edit'}</td>
5032 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
5033 <td class='base'> $Lang ::tr{'remove'}</td>
5037 <td> <img src='/images/off.gif' alt='?OFF' /></td>
5038 <td class='base'> $Lang ::tr{'click to enable'}</td>
5039 <td> <img src='/images/media-floppy.png' alt='?FLOPPY' /></td>
5040 <td class='base'> $Lang ::tr{'download certificate'}</td>
5041 <td> <img src='/images/openvpn.png' alt='?RELOAD'/></td>
5042 <td class='base'> $Lang ::tr{'dl client arch'}</td>
5050 <table width='100%'>
5051 <form method='post'>
5052 <tr><td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />
5053 <input type='submit' name='ACTION' value=' $Lang ::tr{'ovpn con stat'}' $activeonrun /></td></tr>
5058 & Header
:: closebox
();
5060 & Header
:: closepage
();