]>
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 );}
2582 $cgiparams { 'ccdname' }= '' ;
2583 $cgiparams { 'ccdsubnet' }= '' ;
2586 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ccd add' }) {
2587 & addccdnet
( $cgiparams { 'ccdname' }, $cgiparams { 'ccdsubnet' }, $cgiparams { 'DOVPN_SUBNET' });
2589 if ( $errormessage ) {
2590 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
2591 print "<class name='base'> $errormessage " ;
2592 print " </class>" ;
2593 & Header
:: closebox
();
2595 if ( $cgiparams { 'ACTION' } eq "edit" ){
2597 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd modify' });
2600 <table width='100%' border=0>
2601 <tr><form method='post'>
2602 <td width='10%' nowrap='nowrap'> $Lang ::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value=' $cgiparams {'ccdname'}' /></td>
2603 <td width='8%'> $Lang ::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value=' $cgiparams {'ccdsubnet'}' readonly /></td></tr>
2604 <tr><td colspan='4' align='right'><hr><input type='submit' value=' $Lang ::tr{'save'}' /><input type='hidden' name='ACTION' value='editsave'/>
2605 <input type='hidden' name='ccdname' value=' $cgiparams {'ccdname'}'/><input type='submit' value=' $Lang ::tr{'cancel'}' />
2610 & Header
:: closebox
();
2612 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd net' } );
2614 <table width='100%' border='0' cellpadding='0' cellspacing='1'>
2616 <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>
2621 if (! - e
"/var/run/openvpn.pid" ){
2622 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd add' });
2624 <table width='100%' border='0'>
2625 <tr><form method='post'>
2626 <td colspan='4'> $Lang ::tr{'ccd hint'}<br><br></td></tr>
2628 <td width='10%' nowrap='nwrap'> $Lang ::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value=' $cgiparams {'ccdname'}' /></td>
2629 <td width='8%'> $Lang ::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value=' $cgiparams {'ccdsubnet'}' /></td></tr>
2630 <tr><td colspan=4><hr /></td></tr><tr>
2631 <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>
2635 & Header
:: closebox
();
2637 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd net' } );
2638 if ( - e
"/var/run/openvpn.pid" ){
2639 print "<b> $Lang ::tr{'attention'}:</b><br>" ;
2640 print " $Lang ::tr{'ccd noaddnet'}<br><hr>" ;
2644 <table width='100%' border='0' cellpadding='0' cellspacing='1'>
2646 <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>
2651 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
2654 foreach my $key ( keys %ccdconfhash ) {
2655 @ccdconf =( $ccdconfhash { $key }[ 0 ], $ccdconfhash { $key }[ 1 ]);
2657 my $ccdhosts = & hostsinnet
( $ccdconf [ 0 ]);
2658 if ( $count % 2 ){ print " <tr bgcolor=' $color {'color22'}'>" ;}
2659 else { print " <tr bgcolor=' $color {'color20'}'>" ;}
2660 print "<td> $ccdconf [0]</td><td align='center'> $ccdconf [1]</td><td align='center'> $ccdhosts /" .(& ccdmaxclients
( $ccdconf [ 1 ])+ 1 ). "</td><td>" ;
2662 <form method='post' />
2663 <input type='image' src='/images/edit.gif' align='middle' alt= $Lang ::tr{'edit'} title= $Lang ::tr{'edit'} />
2664 <input type='hidden' name='ACTION' value='edit'/>
2665 <input type='hidden' name='ccdname' value=' $ccdconf [0]' />
2666 <input type='hidden' name='ccdsubnet' value=' $ccdconf [1]' />
2668 <form method='post' />
2669 <td><input type='hidden' name='ACTION' value='kill'/>
2670 <input type='hidden' name='number' value=' $count ' />
2671 <input type='hidden' name='net' value=' $ccdconf [0]' />
2672 <input type='image' src='/images/delete.gif' align='middle' alt= $Lang ::tr{'remove'} title= $Lang ::tr{'remove'} /></form></td></tr>
2676 print "</table></form>" ;
2677 & Header
:: closebox
();
2678 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2679 & Header
:: closebigbox
();
2680 & Header
:: closepage
();
2686 ### Openvpn Connections Statistics
2688 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ovpn con stat' }) {
2689 & Header
:: showhttpheaders
();
2690 & Header
:: openpage
( $Lang :: tr
{ 'ovpn con stat' }, 1 , '' );
2691 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2692 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ovpn con stat' });
2695 # <td><b>$Lang::tr{'protocol'}</b></td>
2696 # protocol temp removed
2698 <table width='100%' border='0' cellpadding='2' cellspacing='0'>
2700 <td><b> $Lang ::tr{'common name'}</b></td>
2701 <td><b> $Lang ::tr{'real address'}</b></td>
2702 <td><b> $Lang ::tr{'virtual address'}</b></td>
2703 <td><b> $Lang ::tr{'loged in at'}</b></td>
2704 <td><b> $Lang ::tr{'bytes sent'}</b></td>
2705 <td><b> $Lang ::tr{'bytes received'}</b></td>
2706 <td><b> $Lang ::tr{'last activity'}</b></td>
2710 my $filename = "/var/log/ovpnserver.log" ;
2711 open ( FILE
, $filename ) or die 'Unable to open config file.' ;
2712 my @current = < FILE
>;
2721 my %userlookup = ();
2722 foreach my $line ( @current )
2725 if ( $line =~ /^Updated,(.+)/ ){
2726 @match = split ( /^Updated,(.+)/ , $line );
2727 $status = $match [ 1 ];
2730 if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ ) {
2731 @match = split ( m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ , $line );
2732 if ( $match [ 1 ] ne "Common Name" ) {
2734 $userlookup { $match [ 2 ]} = $uid ;
2735 $users [ $uid ]{ 'CommonName' } = $match [ 1 ];
2736 $users [ $uid ]{ 'RealAddress' } = $match [ 2 ];
2737 $users [ $uid ]{ 'BytesReceived' } = & sizeformat
( $match [ 3 ]);
2738 $users [ $uid ]{ 'BytesSent' } = & sizeformat
( $match [ 4 ]);
2739 $users [ $uid ]{ 'Since' } = $match [ 5 ];
2740 $users [ $uid ]{ 'Proto' } = $proto ;
2744 if ( $line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/ ) {
2745 @match = split ( m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/ , $line );
2746 if ( $match [ 1 ] ne "Virtual Address" ) {
2747 $address = $match [ 3 ];
2748 #find the uid in the lookup table
2749 $uid = $userlookup { $address };
2750 $users [ $uid ]{ 'VirtualAddress' } = $match [ 1 ];
2751 $users [ $uid ]{ 'LastRef' } = $match [ 4 ];
2757 for ( my $idx = 1 ; $idx <= $user2 ; $idx ++){
2759 print "<tr bgcolor=' $color {'color20'}'> \n " ;
2761 print "<tr bgcolor=' $color {'color22'}'> \n " ;
2763 print "<td align='left'> $users [ $idx -1]{'CommonName'}</td>" ;
2764 print "<td align='left'> $users [ $idx -1]{'RealAddress'}</td>" ;
2765 print "<td align='left'> $users [ $idx -1]{'VirtualAddress'}</td>" ;
2766 print "<td align='left'> $users [ $idx -1]{'Since'}</td>" ;
2767 print "<td align='left'> $users [ $idx -1]{'BytesSent'}</td>" ;
2768 print "<td align='left'> $users [ $idx -1]{'BytesReceived'}</td>" ;
2769 print "<td align='left'> $users [ $idx -1]{'LastRef'}</td>" ;
2770 # print "<td align='left'>$users[$idx-1]{'Proto'}</td>";
2776 <table width='100%' border='0' cellpadding='2' cellspacing='0'>
2781 <tr><td align='center' > $Lang ::tr{'the statistics were last updated at'} <b> $status </b></td></tr>
2785 & Header
:: closebox
();
2786 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2787 & Header
:: closebigbox
();
2788 & Header
:: closepage
();
2792 ### Download Certificate
2794 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
2795 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2797 if ( - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
2798 print "Content-Disposition: filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \r\n " ;
2799 print "Content-Type: application/octet-stream \r\n\r\n " ;
2800 print `/bin/cat ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
2805 ### Enable/Disable connection
2808 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
2810 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2811 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2813 if ( $confighash { $cgiparams { 'KEY' }}) {
2814 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
2815 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
2816 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2817 #&writeserverconf();
2818 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2819 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2820 # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
2823 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
2824 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2825 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2826 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
2828 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2829 #&writeserverconf();
2832 $errormessage = $Lang :: tr
{ 'invalid key' };
2836 ### Restart connection
2838 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
2839 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2840 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2842 if ( $confighash { $cgiparams { 'KEY' }}) {
2843 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2844 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2845 # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
2848 $errormessage = $Lang :: tr
{ 'invalid key' };
2852 ### Remove connection
2854 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
2855 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2856 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2858 if ( $confighash { $cgiparams { 'KEY' }}) {
2859 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2860 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2861 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
2863 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
2864 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
2865 delete $confighash { $cgiparams { 'KEY' }};
2866 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2867 #&writeserverconf();
2869 $errormessage = $Lang :: tr
{ 'invalid key' };
2874 ### Choose between adding a host-net or net-net connection
2881 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
2882 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2883 & Header
:: showhttpheaders
();
2884 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
2885 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2886 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'connection type' });
2888 if ( - s
"${General::swroot}/ovpn/settings" ) {
2891 <b> $Lang ::tr{'connection type'}:</b><br />
2892 <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data">
2893 <tr><td><input type='radio' name='TYPE' value='host' checked /></td>
2894 <td class='base'> $Lang ::tr{'host to net vpn'}</td></tr>
2895 <tr><td><input type='radio' name='TYPE' value='net' /></td>
2896 <td class='base'> $Lang ::tr{'net to net vpn'}</td></tr>
2897 <tr><td><input type='radio' name='TYPE' value='net2net' /></td>
2898 <td class='base'> $Lang ::tr{'net to net vpn'} (Upload Client Package)</td></tr>
2899 <tr><td> </td><td class='base'><input type='file' name='FH' size='30'></td></tr>
2900 <tr><td> </td><td>Import Connection Name <img src='/blob.gif' /></td></tr>
2901 <tr><td> </td><td class='base'><input type='text' name='n2nname' size='30'>Default : Client Packagename</td></tr>
2902 <tr><td colspan='3'><hr /></td></tr>
2903 <tr><td align='right' colspan='3'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td></tr>
2904 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
2912 <b> $Lang ::tr{'connection type'}:</b><br />
2913 <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data">
2914 <tr><td><input type='radio' name='TYPE' value='host' checked /></td> <td class='base'> $Lang ::tr{'host to net vpn'}</td></tr>
2915 <tr><td align='right' colspan'3'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td></tr>
2922 & Header
:: closebox
();
2923 & Header
:: closebigbox
();
2924 & Header
:: closepage
();
2931 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) && ( $cgiparams { 'TYPE' } eq 'net2net' )){
2935 my $uplconffilename = '' ;
2936 my $uplconffilename2 = '' ;
2937 my $uplp12name = '' ;
2938 my $uplp12name2 = '' ;
2945 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2947 # Check if a file is uploaded
2949 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
2950 $errormessage = $Lang :: tr
{ 'there was no file upload' };
2954 # Move uploaded IPfire n2n package to temporary file
2956 ( my $fh , my $filename ) = tempfile
( );
2957 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
2962 my $zip = Archive
:: Zip
-> new ();
2963 my $zipName = $filename ;
2964 my $status = $zip -> read ( $zipName );
2965 if ( $status != AZ_OK
) {
2966 $errormessage = "Read of $zipName failed \n " ;
2970 my $tempdir = tempdir
( CLEANUP
=> 1 );
2971 my @files = $zip -> memberNames ();
2973 $zip -> extractMemberWithoutPaths ( $_ , " $tempdir / $_ " );
2975 my $countfiles = @files ;
2977 # Check if we have not more then 2 files
2979 if ( $countfiles == 2 ){
2981 if ( $_ =~ /.conf$/ ){
2982 $uplconffilename = $_ ;
2984 if ( $_ =~ /.p12$/ ){
2988 if (( $uplconffilename eq '' ) || ( $uplp12name eq '' )){
2989 $errormessage = "Either no *.conf or no *.p12 file found \n " ;
2993 open ( FILE
, " $tempdir / $uplconffilename " ) or die 'Unable to open*.conf file' ;
2994 @firen2nconf = < FILE
>;
2996 chomp ( @firen2nconf );
3000 $errormessage = "Filecount does not match only 2 files are allowed \n " ;
3008 if ( $cgiparams { 'n2nname' } ne '' ){
3010 $uplconffilename2 = " $cgiparams {'n2nname'}.conf" ;
3011 $uplp12name2 = " $cgiparams {'n2nname'}.p12" ;
3012 $n2nname [ 0 ] = $cgiparams { 'n2nname' };
3013 my @n2nname2 = split ( /\./ , $uplconffilename );
3014 $n2nname2 [ 0 ] =~ s/\n|\r//g ;
3015 my $input1 = "${General::swroot}/ovpn/certs/ $uplp12name " ;
3016 my $output1 = "${General::swroot}/ovpn/certs/ $uplp12name2 " ;
3017 my $input2 = " $n2nname2 [0]n2n" ;
3018 my $output2 = " $n2nname [0]n2n" ;
3019 my $filename = " $tempdir / $uplconffilename " ;
3020 open ( FILE
, "< $filename " ) or die 'Unable to open config file.' ;
3021 my @current = < FILE
>;
3023 foreach ( @current ) { s/$input1/$output1/g ;}
3024 foreach ( @current ) { s/$input2/$output2/g ;}
3025 open ( OUT
, "> $filename " ) || die 'Unable to open config file.' ;
3030 $uplconffilename2 = $uplconffilename ;
3031 $uplp12name2 = $uplp12name ;
3032 @n2nname = split ( /\./ , $uplconffilename );
3033 $n2nname [ 0 ] =~ s/\n|\r//g ;
3035 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
3036 unless (- d
"${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" , 0770 or die "Unable to create dir $!" ;}
3038 move
( " $tempdir / $uplconffilename " , "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $uplconffilename2 " );
3041 $errormessage = "*.conf move failed: $!" ;
3046 move
( " $tempdir / $uplp12name " , "${General::swroot}/ovpn/certs/ $uplp12name2 " );
3047 chmod 0600 , "${General::swroot}/ovpn/certs/ $uplp12name " ;
3050 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
3058 my @n2nmtudisc = split ( / / , ( grep { /^mtu-disc/ } @firen2nconf )[ 0 ]);;
3059 my @n2nproto2 = split ( / / , ( grep { /^proto/ } @firen2nconf )[ 0 ]);
3060 my @n2nproto = split ( /-/ , $n2nproto2 [ 1 ]);
3061 my @n2nport = split ( / / , ( grep { /^port/ } @firen2nconf )[ 0 ]);
3062 my @n2ntunmtu = split ( / / , ( grep { /^tun-mtu/ } @firen2nconf )[ 0 ]);
3063 my @n2ncomplzo = grep { /^comp-lzo/ } @firen2nconf ;
3064 if ( $n2ncomplzo [ 0 ] =~ /comp-lzo/ ){ $complzoactive = "on" ;} else { $complzoactive = "off" ;}
3065 my @n2nmssfix = grep { /^mssfix/ } @firen2nconf ;
3066 if ( $n2nmssfix [ 0 ] =~ /mssfix/ ){ $mssfixactive = "on" ;} else { $mssfixactive = "off" ;}
3067 #my @n2nmssfix = split(/ /, (grep { /^mssfix/ } @firen2nconf)[0]);
3068 my @n2nfragment = split ( / / , ( grep { /^fragment/ } @firen2nconf )[ 0 ]);
3069 my @n2nremote = split ( / / , ( grep { /^remote/ } @firen2nconf )[ 0 ]);
3070 my @n2novpnsuball = split ( / / , ( grep { /^ifconfig/ } @firen2nconf )[ 0 ]);
3071 my @n2novpnsub = split ( /\./ , $n2novpnsuball [ 1 ]);
3072 my @n2nremsub = split ( / / , ( grep { /^route/ } @firen2nconf )[ 0 ]);
3073 my @n2nmgmt = split ( / / , ( grep { /^management/ } @firen2nconf )[ 0 ]);
3074 my @n2nlocalsub = split ( / / , ( grep { /^# remsub/ } @firen2nconf )[ 0 ]);
3078 # m.a.d delete CR and LF from arrays for this chomp doesnt work
3081 $n2nremote [ 1 ] =~ s/\n|\r//g ;
3082 $n2novpnsub [ 0 ] =~ s/\n|\r//g ;
3083 $n2novpnsub [ 1 ] =~ s/\n|\r//g ;
3084 $n2novpnsub [ 2 ] =~ s/\n|\r//g ;
3085 $n2nproto [ 0 ] =~ s/\n|\r//g ;
3086 $n2nport [ 1 ] =~ s/\n|\r//g ;
3087 $n2ntunmtu [ 1 ] =~ s/\n|\r//g ;
3088 $n2nremsub [ 1 ] =~ s/\n|\r//g ;
3089 $n2nremsub [ 2 ] =~ s/\n|\r//g ;
3090 $n2nlocalsub [ 2 ] =~ s/\n|\r//g ;
3091 $n2nfragment [ 1 ] =~ s/\n|\r//g ;
3092 $n2nmgmt [ 2 ] =~ s/\n|\r//g ;
3093 $n2nmtudisc [ 1 ] =~ s/\n|\r//g ;
3094 chomp ( $complzoactive );
3095 chomp ( $mssfixactive );
3102 # Check if there is no other entry with this name
3105 foreach my $dkey ( keys %confighash ) {
3106 if ( $confighash { $dkey }[ 1 ] eq $n2nname [ 0 ]) {
3107 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
3108 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
3109 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
3110 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
3116 # Check if OpenVPN Subnet is valid
3119 foreach my $dkey ( keys %confighash ) {
3120 if ( $confighash { $dkey }[ 27 ] eq " $n2novpnsub [0]. $n2novpnsub [1]. $n2novpnsub [2].0/255.255.255.0" ) {
3121 $errormessage = 'The OpenVPN Subnet is already in use' ;
3122 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
3123 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
3124 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
3130 # Check im Dest Port is vaild
3133 foreach my $dkey ( keys %confighash ) {
3134 if ( $confighash { $dkey }[ 29 ] eq $n2nport [ 1 ] ) {
3135 $errormessage = 'The OpenVPN Port is already in use' ;
3136 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
3137 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
3138 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
3145 $key = & General
:: findhasharraykey
( \
%confighash );
3147 foreach my $i ( 0 .. 39 ) { $confighash { $key }[ $i ] = "" ;}
3149 $confighash { $key }[ 0 ] = 'off' ;
3150 $confighash { $key }[ 1 ] = $n2nname [ 0 ];
3151 $confighash { $key }[ 2 ] = $n2nname [ 0 ];
3152 $confighash { $key }[ 3 ] = 'net' ;
3153 $confighash { $key }[ 4 ] = 'cert' ;
3154 $confighash { $key }[ 6 ] = 'client' ;
3155 $confighash { $key }[ 8 ] = $n2nlocalsub [ 2 ];
3156 $confighash { $key }[ 10 ] = $n2nremote [ 1 ];
3157 $confighash { $key }[ 11 ] = " $n2nremsub [1]/ $n2nremsub [2]" ;
3158 $confighash { $key }[ 22 ] = $n2nmgmt [ 2 ];
3159 $confighash { $key }[ 23 ] = $mssfixactive ;
3160 $confighash { $key }[ 24 ] = $n2nfragment [ 1 ];
3161 $confighash { $key }[ 25 ] = 'IPFire n2n Client' ;
3162 $confighash { $key }[ 26 ] = 'red' ;
3163 $confighash { $key }[ 27 ] = " $n2novpnsub [0]. $n2novpnsub [1]. $n2novpnsub [2].0/255.255.255.0" ;
3164 $confighash { $key }[ 28 ] = $n2nproto [ 0 ];
3165 $confighash { $key }[ 29 ] = $n2nport [ 1 ];
3166 $confighash { $key }[ 30 ] = $complzoactive ;
3167 $confighash { $key }[ 31 ] = $n2ntunmtu [ 1 ];
3168 $confighash { $key }[ 38 ] = $n2nmtudisc [ 1 ];
3171 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3175 & Header
:: showhttpheaders
();
3176 & Header
:: openpage
( 'Validate imported configuration' , 1 , '' );
3177 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
3178 if ( $errormessage ) {
3179 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
3180 print "<class name='base'> $errormessage " ;
3181 print " </class>" ;
3182 & Header
:: closebox
();
3186 & Header
:: openbox
( '100%' , 'LEFT' , 'import ipfire net2net config' );
3188 if ( $errormessage eq '' ){
3190 <!-- ipfire net2net config gui -->
3191 <table width='100%'>
3192 <tr><td width='25%'> </td><td width='25%'> </td></tr>
3193 <tr><td class='boldbase'> $Lang ::tr{'name'}:</td><td><b> $n2nname [0]</b></td></tr>
3194 <tr><td> </td><td> </td></tr>
3195 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'Act as'}</td><td><b> $confighash { $key }[6]</b></td></tr>
3196 <tr><td class='boldbase' nowrap='nowrap'>Remote Host </td><td><b> $confighash { $key }[10]</b></td></tr>
3197 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'}</td><td><b> $confighash { $key }[8]</b></td></tr>
3198 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'}</td><td><b> $confighash { $key }[11]</b></td></tr>
3199 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn subnet'}</td><td><b> $confighash { $key }[27]</b></td></tr>
3200 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td><td><b> $confighash { $key }[28]</b></td></tr>
3201 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'destination port'}:</td><td><b> $confighash { $key }[29]</b></td></tr>
3202 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'}</td><td><b> $confighash { $key }[30]</b></td></tr>
3203 <tr><td class='boldbase' nowrap='nowrap'>MSSFIX </td><td><b> $confighash { $key }[23]</b></td></tr>
3204 <tr><td class='boldbase' nowrap='nowrap'>Fragment </td><td><b> $confighash { $key }[24]</b></td></tr>
3205 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'}</td><td><b> $confighash { $key }[31]</b></td></tr>
3206 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn mtu-disc'}</td><td><b> $confighash { $key }[38]</b></td></tr>
3207 <tr><td class='boldbase' nowrap='nowrap'>Management Port </td><td><b> $confighash { $key }[22]</b></td></tr>
3208 <tr><td> </td><td> </td></tr>
3212 & Header
:: closebox
();
3215 if ( $errormessage ) {
3216 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
3218 print "<div align='center'><form method='post' ENCTYPE='multipart/form-data'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />" ;
3219 print "<input type='hidden' name='TYPE' value='net2netakn' />" ;
3220 print "<input type='hidden' name='KEY' value=' $key ' />" ;
3221 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
3223 & Header
:: closebigbox
();
3224 & Header
:: closepage
();
3229 ### Accept IPFire n2n Package Settings
3232 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) && ( $cgiparams { 'TYPE' } eq 'net2netakn' )){
3235 ### Discard and Rollback IPFire n2n Package Settings
3238 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'cancel' }) && ( $cgiparams { 'TYPE' } eq 'net2netakn' )){
3240 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3242 if ( $confighash { $cgiparams { 'KEY' }}) {
3244 my $conffile = glob ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]/ $confighash { $cgiparams {'KEY'}}[1].conf" );
3245 my $certfile = glob ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
3246 unlink ( $certfile ) or die "Removing $certfile fail: $!" ;
3247 unlink ( $conffile ) or die "Removing $conffile fail: $!" ;
3248 rmdir ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]" ) || die "Kann Verzeichnis nicht loeschen: $!" ;
3249 delete $confighash { $cgiparams { 'KEY' }};
3250 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3253 $errormessage = $Lang :: tr
{ 'invalid key' };
3263 ### Adding a new connection
3265 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
3266 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
3267 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
3269 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
3270 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
3271 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3273 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
3274 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
3275 $errormessage = $Lang :: tr
{ 'invalid key' };
3278 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
3279 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
3280 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
3281 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
3282 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
3283 $cgiparams { 'SIDE' } = $confighash { $cgiparams { 'KEY' }}[ 6 ];
3284 $cgiparams { 'LOCAL_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 8 ];
3285 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
3286 $cgiparams { 'REMOTE_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 11 ];
3287 $cgiparams { 'OVPN_MGMT' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
3288 $cgiparams { 'MSSFIX' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
3289 $cgiparams { 'FRAGMENT' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
3290 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
3291 $cgiparams { 'INTERFACE' } = $confighash { $cgiparams { 'KEY' }}[ 26 ];
3292 $cgiparams { 'OVPN_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
3293 $cgiparams { 'PROTOCOL' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
3294 $cgiparams { 'DEST_PORT' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
3295 $cgiparams { 'COMPLZO' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
3296 $cgiparams { 'MTU' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
3297 $cgiparams { 'CHECK1' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
3298 my $name = $cgiparams { 'CHECK1' } ;
3299 $cgiparams { $name } = $confighash { $cgiparams { 'KEY' }}[ 33 ];
3300 $cgiparams { 'RG' } = $confighash { $cgiparams { 'KEY' }}[ 34 ];
3301 $cgiparams { 'CCD_DNS1' } = $confighash { $cgiparams { 'KEY' }}[ 35 ];
3302 $cgiparams { 'CCD_DNS2' } = $confighash { $cgiparams { 'KEY' }}[ 36 ];
3303 $cgiparams { 'CCD_WINS' } = $confighash { $cgiparams { 'KEY' }}[ 37 ];
3304 $cgiparams { 'PMTU_DISCOVERY' } = $confighash { $cgiparams { 'KEY' }}[ 38 ];
3305 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
3306 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
3308 #A.Marx CCD check iroute field and convert it to decimal
3309 if ( $cgiparams { 'TYPE' } eq 'host' ) {
3311 my %ccdroutehash =();
3315 if ( $cgiparams { 'IR' } ne '' ){
3316 @temp = split ( " \n " , $cgiparams { 'IR' });
3317 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3319 foreach my $key ( keys %ccdroutehash ) {
3320 if ( $ccdroutehash { $key }[ 0 ] eq $cgiparams { 'NAME' }) {
3322 delete $ccdroutehash { $key };
3324 $keypoint = & General
:: findhasharraykey
( \
%ccdroutehash );
3327 $ccdroutehash { $keypoint }[ 0 ]= $cgiparams { 'NAME' };
3330 foreach $val ( @temp ){
3333 #check if iroute exists in ccdroute or if new iroute is part of an existing one
3334 foreach my $key ( keys %ccdroutehash ) {
3335 foreach my $oldiroute ( 1 .. $ #{$ccdroutehash{$key}}){
3336 if ( $ccdroutehash { $key }[ $oldiroute ] eq " $val " ) {
3337 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err irouteexist' };
3340 my ( $ip1 , $cidr1 ) = split ( /\/ /, $val );
3341 my ( $ip2 , $cidr2 ) = split ( /\/ /, $ccdroutehash { $key }[ $oldiroute ]);
3342 if (& General
:: IpInSubnet
( $ip1 , $ip2 , $cidr2 )){
3343 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err irouteexist' };
3349 if (!& General
:: validipandmask
( $val )){
3350 $errormessage = $errormessage . "Route " . $Lang :: tr
{ 'ccd invalid' }. " ( $val )" ;
3353 ( $ip , $cidr ) = split ( /\/ /, $val );
3354 $ip =& General
:: getnetworkip
( $ip ,& General
:: iporsubtocidr
( $cidr ));
3355 $cidr =& General
:: iporsubtodec
( $cidr );
3356 $ccdroutehash { $keypoint }[ $i ] = $ip . "/" . $cidr ;
3360 #check for existing network IP's
3361 if (& General
:: IpInSubnet
( $ip , $netsettings { GREEN_NETADDRESS
}, $netsettings { GREEN_NETMASK
}) && $netsettings { GREEN_NETADDRESS
} ne '0.0.0.0' )
3363 $errormessage = $Lang :: tr
{ 'ccd err green' };
3365 } elsif (& General
:: IpInSubnet
( $ip , $netsettings { RED_NETADDRESS
}, $netsettings { RED_NETMASK
}) && $netsettings { RED_NETADDRESS
} ne '0.0.0.0' )
3367 $errormessage = $Lang :: tr
{ 'ccd err red' };
3369 } elsif (& General
:: IpInSubnet
( $ip , $netsettings { BLUE_NETADDRESS
}, $netsettings { BLUE_NETMASK
}) && $netsettings { BLUE_NETADDRESS
} ne '0.0.0.0' && $netsettings { BLUE_NETADDRESS
} gt '' )
3371 $errormessage = $Lang :: tr
{ 'ccd err blue' };
3373 } elsif (& General
:: IpInSubnet
( $ip , $netsettings { ORANGE_NETADDRESS
}, $netsettings { ORANGE_NETMASK
}) && $netsettings { ORANGE_NETADDRESS
} ne '0.0.0.0' && $netsettings { ORANGE_NETADDRESS
} gt '' )
3375 $errormessage = $Lang :: tr
{ 'ccd err orange' };
3379 if (& General
:: validipandmask
( $val )){
3380 $ccdroutehash { $keypoint }[ $i ] = $ip . "/" . $cidr ;
3382 $errormessage = $errormessage . "Route " . $Lang :: tr
{ 'ccd invalid' }. " ( $ip / $cidr )" ;
3387 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3390 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3391 foreach my $key ( keys %ccdroutehash ) {
3392 if ( $ccdroutehash { $key }[ 0 ] eq $cgiparams { 'NAME' }) {
3393 delete $ccdroutehash { $key };
3394 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3400 #check route field and convert it to decimal
3403 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
3405 foreach my $key ( keys %ccdroute2hash ) {
3406 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }) {
3408 delete $ccdroute2hash { $key };
3410 $keypoint = & General
:: findhasharraykey
( \
%ccdroute2hash );
3411 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3415 $ccdroute2hash { $keypoint }[ 0 ]= $cgiparams { 'NAME' };
3416 if ( $cgiparams { 'IFROUTE' } eq '' ){ $cgiparams { 'IFROUTE' } = $Lang :: tr
{ 'ccd none' };}
3417 @temp = split ( /\|/ , $cgiparams { 'IFROUTE' });
3419 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%ownnet );
3420 foreach $val ( @temp ){
3423 if ( $val eq $Lang :: tr
{ 'green' })
3425 $val = $ownnet { GREEN_NETADDRESS
}. "/" . $ownnet { GREEN_NETMASK
};
3427 if ( $val eq $Lang :: tr
{ 'blue' })
3429 $val = $ownnet { BLUE_NETADDRESS
}. "/" . $ownnet { BLUE_NETMASK
};
3431 if ( $val eq $Lang :: tr
{ 'orange' })
3433 $val = $ownnet { ORANGE_NETADDRESS
}. "/" . $ownnet { ORANGE_NETMASK
};
3435 my ( $ip , $cidr ) = split ( /\/ /, $val );
3437 if ( $val ne $Lang :: tr
{ 'ccd none' })
3439 if (! & check_routes_push
( $val )){ $errormessage = $errormessage . "Route $val " . $Lang :: tr
{ 'ccd err routeovpn2' }. " ( $val )" ; goto VPNCONF_ERROR
;}
3440 if (! & check_ccdroute
( $val )){ $errormessage = $errormessage . "<br>Route $val " . $Lang :: tr
{ 'ccd err inuse' }. " ( $val )" ; goto VPNCONF_ERROR
;}
3441 if (! & check_ccdconf
( $val )){ $errormessage = $errormessage . "<br>Route $val " . $Lang :: tr
{ 'ccd err routeovpn' }. " ( $val )" ; goto VPNCONF_ERROR
;}
3442 if (& General
:: validipandmask
( $val )){
3443 $val = $ip . "/" .& General
:: iporsubtodec
( $cidr );
3444 $ccdroute2hash { $keypoint }[ $i ] = $val ;
3446 $errormessage = $errormessage . "Route " . $Lang :: tr
{ 'ccd invalid' }. " ( $val )" ;
3450 $ccdroute2hash { $keypoint }[ $i ]= '' ;
3454 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
3457 if ( $cgiparams { 'CCD_DNS1' } ne '' && ! & General
:: validip
( $cgiparams { 'CCD_DNS1' })) {
3458 $errormessage = $errormessage . "<br>" . $Lang :: tr
{ 'invalid input for dhcp dns' }. " 1" ;
3462 if ( $cgiparams { 'CCD_DNS2' } ne '' && ! & General
:: validip
( $cgiparams { 'CCD_DNS2' })) {
3463 $errormessage = $errormessage . "<br>" . $Lang :: tr
{ 'invalid input for dhcp dns' }. " 2" ;
3467 if ( $cgiparams { 'CCD_WINS' } ne '' && ! & General
:: validip
( $cgiparams { 'CCD_WINS' })) {
3468 $errormessage = $errormessage . "<br>" . $Lang :: tr
{ 'invalid input for dhcp wins' };
3476 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
3477 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
3478 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3479 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3480 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3486 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
3487 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
3488 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3489 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3490 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3495 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
3496 $errormessage = $Lang :: tr
{ 'name is invalid' };
3497 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3498 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3499 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3504 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
3505 $errormessage = $Lang :: tr
{ 'name too long' };
3506 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3507 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3508 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3517 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3519 if ( $cgiparams { 'DEST_PORT' } eq $vpnsettings { 'DDEST_PORT' }) {
3520 $errormessage = $Lang :: tr
{ 'openvpn destination port used' };
3521 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3522 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3526 if ( $cgiparams { 'DEST_PORT' } eq '' ) {
3527 $errormessage = $Lang :: tr
{ 'openvpn destination port used' };
3528 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3529 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3533 if ( $cgiparams { 'OVPN_SUBNET' } eq $vpnsettings { 'DOVPN_SUBNET' }) {
3534 $errormessage = $Lang :: tr
{ 'openvpn subnet is used' };
3535 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3536 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3540 if (( $cgiparams { 'PROTOCOL' } eq 'tcp' ) && ( $cgiparams { 'MSSFIX' } eq 'on' )) {
3541 $errormessage = $Lang :: tr
{ 'openvpn mssfix allowed with udp' };
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: $!" ;
3547 if (( $cgiparams { 'PROTOCOL' } eq 'tcp' ) && ( $cgiparams { 'FRAGMENT' } ne '' )) {
3548 $errormessage = $Lang :: tr
{ 'openvpn fragment allowed with udp' };
3549 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3550 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3554 if (( $cgiparams { 'PMTU_DISCOVERY' } ne 'off' ) && ( $cgiparams { 'MTU' } ne '1500' )) {
3555 $errormessage = $Lang :: tr
{ 'ovpn mtu-disc and mtu not 1500' };
3556 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3557 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3561 if ( $cgiparams { 'PMTU_DISCOVERY' } ne 'off' ) {
3562 if (( $cgiparams { 'FRAGMENT' } ne '' ) || ( $cgiparams { 'MSSFIX' } eq 'on' )) {
3563 $errormessage = $Lang :: tr
{ 'ovpn mtu-disc with mssfix or fragment' };
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: $!" ;
3570 if ( & validdotmask
( $cgiparams { 'LOCAL_SUBNET' })) {
3571 $errormessage = $Lang :: tr
{ 'openvpn prefix local subnet' };
3572 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3573 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3577 if ( & validdotmask
( $cgiparams { 'OVPN_SUBNET' })) {
3578 $errormessage = $Lang :: tr
{ 'openvpn prefix openvpn subnet' };
3579 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3580 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3584 if ( & validdotmask
( $cgiparams { 'REMOTE_SUBNET' })) {
3585 $errormessage = $Lang :: tr
{ 'openvpn prefix remote subnet' };
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: $!" ;
3591 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) {
3592 $cgiparams { 'OVPN_MGMT' } = $cgiparams { 'DEST_PORT' };
3597 # if (($cgiparams{'TYPE'} eq 'net') && ($cgiparams{'SIDE'} !~ /^(left|right)$/)) {
3598 # $errormessage = $Lang::tr{'ipfire side is invalid'};
3599 # goto VPNCONF_ERROR;
3602 # Check if there is no other entry with this name
3603 if (! $cgiparams { 'KEY' }) {
3604 foreach my $key ( keys %confighash ) {
3605 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
3606 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
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: $!" ;
3616 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! $cgiparams { 'REMOTE' })) {
3617 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
3618 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3619 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3620 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3625 if ( $cgiparams { 'REMOTE' }) {
3626 if (! & General
:: validip
( $cgiparams { 'REMOTE' })) {
3627 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
3628 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
3629 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3630 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3631 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3635 if (& valid_dns_host
( $cgiparams { 'REMOTE' })) {
3636 $warnmessage = " $Lang ::tr{'check vpn lr'} $cgiparams {'REMOTE'}. $Lang ::tr{'dns check failed'}" ;
3637 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3644 if ( $cgiparams { 'TYPE' } ne 'host' ) {
3645 unless (& General
:: validipandmask
( $cgiparams { 'LOCAL_SUBNET' })) {
3646 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
3647 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3648 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3649 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3651 goto VPNCONF_ERROR
;}
3653 # Check if there is no other entry without IP-address and PSK
3654 if ( $cgiparams { 'REMOTE' } eq '' ) {
3655 foreach my $key ( keys %confighash ) {
3656 if (( $cgiparams { 'KEY' } ne $key ) &&
3657 ( $confighash { $key }[ 4 ] eq 'psk' || $cgiparams { 'AUTH' } eq 'psk' ) &&
3658 $confighash { $key }[ 10 ] eq '' ) {
3659 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
3664 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! & General
:: validipandmask
( $cgiparams { 'REMOTE_SUBNET' }))) {
3665 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
3666 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3667 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3671 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
3672 $errormessage = $Lang :: tr
{ 'invalid input' };
3675 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
3676 $errormessage = $Lang :: tr
{ 'invalid input' };
3681 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
3682 # if (! length($cgiparams{'PSK'}) ) {
3683 # $errormessage = $Lang::tr{'pre-shared key is too short'};
3684 # goto VPNCONF_ERROR;
3686 # if ($cgiparams{'PSK'} =~ /['",&]/) {
3687 # $errormessage = $Lang::tr{'invalid characters found in pre-shared key'};
3688 # goto VPNCONF_ERROR;
3690 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
3691 if ( $cgiparams { 'KEY' }) {
3692 $errormessage = $Lang :: tr
{ 'cant change certificates' };
3695 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
3696 $errormessage = $Lang :: tr
{ 'there was no file upload' };
3700 # Move uploaded certificate request to a temporary file
3701 ( my $fh , my $filename ) = tempfile
( );
3702 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
3707 # Sign the certificate request and move it
3708 # Sign the host certificate request
3709 system ( '/usr/bin/openssl' , 'ca' , '-days' , " $cgiparams {'DAYS_VALID'}" ,
3710 '-batch' , '-notext' ,
3712 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
3713 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
3715 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
3717 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3718 & newcleanssldatabase
();
3722 & deletebackupcert
();
3725 my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem` ;
3726 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
3728 $temp =~ s
+/ Email
+, E
+;
3729 $temp =~ s/ ST=/ S=/ ;
3730 $cgiparams { 'CERT_NAME' } = $temp ;
3731 $cgiparams { 'CERT_NAME' } =~ s/,//g ;
3732 $cgiparams { 'CERT_NAME' } =~ s/\'//g ;
3733 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
3734 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
3737 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
3738 if ( $cgiparams { 'KEY' }) {
3739 $errormessage = $Lang :: tr
{ 'cant change certificates' };
3742 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
3743 $errormessage = $Lang :: tr
{ 'there was no file upload' };
3746 # Move uploaded certificate to a temporary file
3747 ( my $fh , my $filename ) = tempfile
( );
3748 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
3753 # Verify the certificate has a valid CA and move it
3755 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/cacert.pem $filename ` ;
3756 if ( $test =~ /: OK/ ) {
3759 foreach my $key ( keys %cahash ) {
3760 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/ $cahash { $key }[0]cert.pem $filename ` ;
3761 if ( $test =~ /: OK/ ) {
3767 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
3771 move
( $filename , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3773 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
3779 my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem` ;
3780 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
3782 $temp =~ s
+/ Email
+, E
+;
3783 $temp =~ s/ ST=/ S=/ ;
3784 $cgiparams { 'CERT_NAME' } = $temp ;
3785 $cgiparams { 'CERT_NAME' } =~ s/,//g ;
3786 $cgiparams { 'CERT_NAME' } =~ s/\'//g ;
3787 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
3788 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3789 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
3792 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
3793 if ( $cgiparams { 'KEY' }) {
3794 $errormessage = $Lang :: tr
{ 'cant change certificates' };
3797 # Validate input since the form was submitted
3798 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
3799 $errormessage = $Lang :: tr
{ 'name too long' };
3802 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
3803 $errormessage = $Lang :: tr
{ 'invalid input for name' };
3806 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
3807 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
3810 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
3811 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
3814 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
3815 $errormessage = $Lang :: tr
{ 'invalid input for department' };
3818 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
3819 $errormessage = $Lang :: tr
{ 'organization too long' };
3822 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
3823 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
3826 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
3827 $errormessage = $Lang :: tr
{ 'invalid input for city' };
3830 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
3831 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
3834 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
3835 $errormessage = $Lang :: tr
{ 'invalid input for country' };
3838 if ( $cgiparams { 'CERT_PASS1' } ne '' && $cgiparams { 'CERT_PASS2' } ne '' ){
3839 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
3840 $errormessage = $Lang :: tr
{ 'password too short' };
3844 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
3845 $errormessage = $Lang :: tr
{ 'passwords do not match' };
3849 # Replace empty strings with a .
3850 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
3851 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
3852 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
3854 # Create the Host certificate request client
3855 my $pid = open ( OPENSSL
, "|-" );
3856 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto VPNCONF_ERROR
;};
3857 if ( $pid ) { # parent
3858 print OPENSSL
" $cgiparams {'CERT_COUNTRY'} \n " ;
3859 print OPENSSL
" $state \n " ;
3860 print OPENSSL
" $city \n " ;
3861 print OPENSSL
" $cgiparams {'CERT_ORGANIZATION'} \n " ;
3862 print OPENSSL
" $ou \n " ;
3863 print OPENSSL
" $cgiparams {'CERT_NAME'} \n " ;
3864 print OPENSSL
" $cgiparams {'CERT_EMAIL'} \n " ;
3865 print OPENSSL
". \n " ;
3866 print OPENSSL
". \n " ;
3869 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
3870 unlink ( "${General::swroot}ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3871 unlink ( "${General::swroot}ovpn/certs/ $cgiparams {'NAME'}req.pem" );
3875 unless ( exec ( '/usr/bin/openssl' , 'req' , '-nodes' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
3876 '-newkey' , 'rsa:1024' ,
3877 '-keyout' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" ,
3878 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" ,
3879 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
3880 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
3881 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3882 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
3887 # Sign the host certificate request
3888 system ( '/usr/bin/openssl' , 'ca' , '-days' , " $cgiparams {'DAYS_VALID'}" ,
3889 '-batch' , '-notext' ,
3890 '-in' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" ,
3891 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
3892 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
3894 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
3895 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3896 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
3897 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3898 & newcleanssldatabase
();
3901 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
3902 & deletebackupcert
();
3905 # Create the pkcs12 file
3906 system ( '/usr/bin/openssl' , 'pkcs12' , '-export' ,
3907 '-inkey' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" ,
3908 '-in' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
3909 '-name' , $cgiparams { 'NAME' },
3910 '-passout' , "pass: $cgiparams {'CERT_PASS1'}" ,
3911 '-certfile' , "${General::swroot}/ovpn/ca/cacert.pem" ,
3912 '-caname' , " $vpnsettings {'ROOTCERT_ORGANIZATION'} CA" ,
3913 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12" );
3915 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
3916 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3917 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3918 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12" );
3921 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3923 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
3924 ; # Nothing, just editing
3926 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
3930 # Check if there is no other entry with this common name
3931 if ((! $cgiparams { 'KEY' }) && ( $cgiparams { 'AUTH' } ne 'psk' )) {
3932 foreach my $key ( keys %confighash ) {
3933 if ( $confighash { $key }[ 2 ] eq $cgiparams { 'CERT_NAME' }) {
3934 $errormessage = $Lang :: tr
{ 'a connection with this common name already exists' };
3941 my $key = $cgiparams { 'KEY' };
3944 $key = & General
:: findhasharraykey
( \
%confighash );
3945 foreach my $i ( 0 .. 38 ) { $confighash { $key }[ $i ] = "" ;}
3947 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
3948 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
3949 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
3950 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
3953 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
3954 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
3955 $confighash { $key }[ 4 ] = 'psk' ;
3956 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
3958 $confighash { $key }[ 4 ] = 'cert' ;
3960 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3961 $confighash { $key }[ 6 ] = $cgiparams { 'SIDE' };
3962 $confighash { $key }[ 11 ] = $cgiparams { 'REMOTE_SUBNET' };
3964 $confighash { $key }[ 8 ] = $cgiparams { 'LOCAL_SUBNET' };
3965 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
3966 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) {
3967 $confighash { $key }[ 22 ] = $confighash { $key }[ 29 ];
3969 $confighash { $key }[ 22 ] = $cgiparams { 'OVPN_MGMT' };
3971 $confighash { $key }[ 23 ] = $cgiparams { 'MSSFIX' };
3972 $confighash { $key }[ 24 ] = $cgiparams { 'FRAGMENT' };
3973 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
3974 $confighash { $key }[ 26 ] = $cgiparams { 'INTERFACE' };
3976 $confighash { $key }[ 27 ] = $cgiparams { 'OVPN_SUBNET' };
3977 $confighash { $key }[ 28 ] = $cgiparams { 'PROTOCOL' };
3978 $confighash { $key }[ 29 ] = $cgiparams { 'DEST_PORT' };
3979 $confighash { $key }[ 30 ] = $cgiparams { 'COMPLZO' };
3980 $confighash { $key }[ 31 ] = $cgiparams { 'MTU' };
3981 $confighash { $key }[ 32 ] = $cgiparams { 'CHECK1' };
3982 my $name = $cgiparams { 'CHECK1' };
3983 $confighash { $key }[ 33 ] = $cgiparams { $name };
3984 $confighash { $key }[ 34 ] = $cgiparams { 'RG' };
3985 $confighash { $key }[ 35 ] = $cgiparams { 'CCD_DNS1' };
3986 $confighash { $key }[ 36 ] = $cgiparams { 'CCD_DNS2' };
3987 $confighash { $key }[ 37 ] = $cgiparams { 'CCD_WINS' };
3988 $confighash { $key }[ 38 ] = $cgiparams { 'PMTU_DISCOVERY' };
3991 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3993 if ( $cgiparams { 'CHECK1' } ){
3995 my ( $ccdip , $ccdsub )= split "/" , $cgiparams { $name };
3996 my ( $a , $b , $c , $d ) = split ( /\./ , $ccdip );
3997 if ( - e
"${General::swroot}/ovpn/ccd/ $confighash { $key }[2]" ){ unlink "${General::swroot}/ovpn/ccd/ $cgiparams {'CERT_NAME'}" ;}
3998 open ( CCDRWCONF
, '>' , "${General::swroot}/ovpn/ccd/ $confighash { $key }[2]" ) or die "Unable to create clientconfigfile $!" ;
3999 print CCDRWCONF
"# OpenVPN Clientconfig from CCD extension by Copymaster# \n\n " ;
4000 if ( $cgiparams { 'CHECK1' } eq 'dynamic' ){
4001 print CCDRWCONF
"#This client uses the dynamic pool \n " ;
4003 print CCDRWCONF
"#Ip address client and Server \n " ;
4004 print CCDRWCONF
"ifconfig-push $ccdip " .& General
:: getlastip
( $ccdip , 1 ). " \n " ;
4006 if ( $confighash { $key }[ 34 ] eq 'on' ){
4007 print CCDRWCONF
" \n #Redirect Gateway: \n #All IP traffic is redirected through the vpn \n " ;
4008 print CCDRWCONF
"push redirect-gateway \n " ;
4010 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
4011 if ( $cgiparams { 'IR' } ne '' ){
4012 print CCDRWCONF
" \n #Client routes these Networks (behind Client) \n " ;
4013 foreach my $key ( keys %ccdroutehash ){
4014 if ( $ccdroutehash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4015 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}){
4016 my ( $a , $b )= split ( /\/ /, $ccdroutehash { $key }[ $i ]);
4017 print CCDRWCONF
"iroute $a $b \n " ;
4022 if ( $cgiparams { 'IFROUTE' } eq $Lang :: tr
{ 'ccd none' } ){ $cgiparams { 'IFROUTE' }= '' ;}
4023 if ( $cgiparams { 'IFROUTE' } ne '' ){
4024 print CCDRWCONF
" \n #Client gets routes to these Networks (behind IPFIRE) \n " ;
4025 foreach my $key ( keys %ccdroute2hash ){
4026 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4027 foreach my $i ( 1 .. $ #{$ccdroute2hash{$key}}){
4028 if ( $ccdroute2hash { $key }[ $i ] eq $Lang :: tr
{ 'blue' }){
4030 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%blue );
4031 print CCDRWCONF
"push \" route $blue {BLUE_ADDRESS} $blue {BLUE_NETMASK} \n " ;
4032 } elsif ( $ccdroute2hash { $key }[ $i ] eq $Lang :: tr
{ 'orange' }){
4034 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%orange );
4035 print CCDRWCONF
"push \" route $orange {ORANGE_ADDRESS} $orange {ORANGE_NETMASK} \n " ;
4037 my ( $a , $b )= split ( /\/ /, $ccdroute2hash { $key }[ $i ]);
4038 print CCDRWCONF
"push \" route $a $b \"\n " ;
4044 if (( $cgiparams { 'CCD_DNS1' } eq '' ) && ( $cgiparams { 'CCD_DNS1' } ne '' )){ $cgiparams { 'CCD_DNS1' } = $cgiparams { 'CCD_DNS2' }; $cgiparams { 'CCD_DNS2' }= '' ;}
4045 if ( $cgiparams { 'CCD_DNS1' } ne '' ){
4046 print CCDRWCONF
" \n #Client gets these Nameservers \n " ;
4047 print CCDRWCONF
"push \" dhcp-option DNS $cgiparams {'CCD_DNS1'} \" \n " ;
4049 if ( $cgiparams { 'CCD_DNS2' } ne '' ){
4050 print CCDRWCONF
"push \" dhcp-option DNS $cgiparams {'CCD_DNS2'} \" \n " ;
4052 if ( $cgiparams { 'CCD_WINS' } ne '' ){
4053 print CCDRWCONF
" \n #Client gets this WINS server \n " ;
4054 print CCDRWCONF
"push \" dhcp-option WINS $cgiparams {'CCD_WINS'} \" \n " ;
4063 if ( $cgiparams { 'TYPE' } eq 'net' ) {
4065 if (- e
"/var/run/ $confighash { $key }[1]n2n.pid" ) {
4066 system ( '/usr/local/bin/openvpnctrl' , '-kn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
4068 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
4069 my $key = $cgiparams { 'KEY' };
4071 $key = & General
:: findhasharraykey
( \
%confighash );
4072 foreach my $i ( 0 .. 31 ) { $confighash { $key }[ $i ] = "" ;}
4074 $confighash { $key }[ 0 ] = 'on' ;
4075 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
4077 system ( '/usr/local/bin/openvpnctrl' , '-sn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
4085 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
4086 $cgiparams { 'KEY' } = $key ;
4087 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
4091 $cgiparams { 'ENABLED' } = 'on' ;
4095 $cgiparams { 'MSSFIX' } = 'on' ;
4096 $cgiparams { 'FRAGMENT' } = '1300' ;
4097 $cgiparams { 'PMTU_DISCOVERY' } = 'off' ;
4101 $cgiparams { 'SIDE' } = 'left' ;
4102 if ( ! - f
"${General::swroot}/ovpn/ca/cakey.pem" ) {
4103 $cgiparams { 'AUTH' } = 'psk' ;
4104 } elsif ( ! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
4105 $cgiparams { 'AUTH' } = 'certfile' ;
4107 $cgiparams { 'AUTH' } = 'certgen' ;
4109 $cgiparams { 'LOCAL_SUBNET' } = " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" ;
4110 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
4111 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
4112 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
4113 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
4117 $checked { 'ENABLED' }{ 'off' } = '' ;
4118 $checked { 'ENABLED' }{ 'on' } = '' ;
4119 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = 'CHECKED' ;
4120 $checked { 'ENABLED_BLUE' }{ 'off' } = '' ;
4121 $checked { 'ENABLED_BLUE' }{ 'on' } = '' ;
4122 $checked { 'ENABLED_BLUE' }{ $cgiparams { 'ENABLED_BLUE' }} = 'CHECKED' ;
4123 $checked { 'ENABLED_ORANGE' }{ 'off' } = '' ;
4124 $checked { 'ENABLED_ORANGE' }{ 'on' } = '' ;
4125 $checked { 'ENABLED_ORANGE' }{ $cgiparams { 'ENABLED_ORANGE' }} = 'CHECKED' ;
4128 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
4129 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
4130 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = 'CHECKED' ;
4132 $selected { 'SIDE' }{ 'server' } = '' ;
4133 $selected { 'SIDE' }{ 'client' } = '' ;
4134 $selected { 'SIDE' }{ $cgiparams { 'SIDE' }} = 'SELECTED' ;
4136 $selected { 'PROTOCOL' }{ 'udp' } = '' ;
4137 $selected { 'PROTOCOL' }{ 'tcp' } = '' ;
4138 $selected { 'PROTOCOL' }{ $cgiparams { 'PROTOCOL' }} = 'SELECTED' ;
4141 $checked { 'AUTH' }{ 'psk' } = '' ;
4142 $checked { 'AUTH' }{ 'certreq' } = '' ;
4143 $checked { 'AUTH' }{ 'certgen' } = '' ;
4144 $checked { 'AUTH' }{ 'certfile' } = '' ;
4145 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = 'CHECKED' ;
4147 $selected { 'INTERFACE' }{ $cgiparams { 'INTERFACE' }} = 'SELECTED' ;
4149 $checked { 'COMPLZO' }{ 'off' } = '' ;
4150 $checked { 'COMPLZO' }{ 'on' } = '' ;
4151 $checked { 'COMPLZO' }{ $cgiparams { 'COMPLZO' }} = 'CHECKED' ;
4153 $checked { 'MSSFIX' }{ 'off' } = '' ;
4154 $checked { 'MSSFIX' }{ 'on' } = '' ;
4155 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
4157 $checked { 'PMTU_DISCOVERY' }{ $cgiparams { 'PMTU_DISCOVERY' }} = 'checked= \' checked \' ' ;
4161 & Header
:: showhttpheaders
();
4162 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
4163 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
4164 if ( $errormessage ) {
4165 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
4166 print "<class name='base'> $errormessage " ;
4167 print " </class>" ;
4168 & Header
:: closebox
();
4172 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'warning messages'}:" );
4173 print "<class name='base'> $warnmessage " ;
4174 print " </class>" ;
4175 & Header
:: closebox
();
4178 print "<form method='post' enctype='multipart/form-data'>" ;
4179 print "<input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />" ;
4181 if ( $cgiparams { 'KEY' }) {
4182 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
4183 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
4186 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'connection'}:" );
4187 print "<table width='100%' border='0'> \n " ;
4191 print "<tr><td width='14%' class='boldbase'> $Lang ::tr{'name'}: </td>" ;
4193 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4194 if ( $cgiparams { 'KEY' }) {
4195 print "<td width='35%' class='base'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /> $cgiparams {'NAME'}</td>" ;
4198 print "<td width='35%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' maxlength='20' size='30' /></td>" ;
4200 # print "<tr><td>$Lang::tr{'interface'}</td>";
4201 # print "<td><select name='INTERFACE'>";
4202 # print "<option value='RED' $selected{'INTERFACE'}{'RED'}>RED</option>";
4203 # if ($netsettings{'BLUE_DEV'} ne '') {
4204 # print "<option value='BLUE' $selected{'INTERFACE'}{'BLUE'}>BLUE</option>";
4206 # print "<option value='GREEN' $selected{'INTERFACE'}{'GREEN'}>GREEN</option>";
4207 # print "<option value='ORANGE' $selected{'INTERFACE'}{'ORANGE'}>ORANGE</option>";
4208 # print "</select></td></tr>";
4211 print "<input type='hidden' name='INTERFACE' value='red' />" ;
4212 if ( $cgiparams { 'KEY' }) {
4213 print "<td width='25%' class='base' nowrap='nowrap'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /> $cgiparams {'NAME'}</td>" ;
4215 print "<td width='25%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' maxlength='20' /></td>" ;
4221 <td width='25%'> </td>
4222 <td width='25%'> </td></tr>
4223 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'Act as'}</td>
4224 <td><select name='SIDE'><option value='server' $selected {'SIDE'}{'server'}> $Lang ::tr{'openvpn server'}</option>
4225 <option value='client' $selected {'SIDE'}{'client'}> $Lang ::tr{'openvpn client'}</option></select></td>
4226 <td class='boldbase'> $Lang ::tr{'remote host/ip'}:</td>
4227 <td><input type='TEXT' name='REMOTE' value=' $cgiparams {'REMOTE'}' /></td></tr>
4228 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'}</td>
4229 <td><input type='TEXT' name='LOCAL_SUBNET' value=' $cgiparams {'LOCAL_SUBNET'}' /></td>
4230 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'}</td>
4231 <td><input type='text' name='REMOTE_SUBNET' value=' $cgiparams {'REMOTE_SUBNET'}' /></td></tr>
4232 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn subnet'}</td>
4233 <td><input type='TEXT' name='OVPN_SUBNET' value=' $cgiparams {'OVPN_SUBNET'}' /></td></tr>
4234 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td>
4236 <td><select name='PROTOCOL'><option value='udp' $selected {'PROTOCOL'}{'udp'}>UDP</option>
4237 <option value='tcp' $selected {'PROTOCOL'}{'tcp'}>TCP</option></select></td>
4239 <td class='boldbase'> $Lang ::tr{'destination port'}:</td>
4240 <td><input type='TEXT' name='DEST_PORT' value=' $cgiparams {'DEST_PORT'}' size='5' /></td></tr>
4241 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'} <img src='/blob.gif'</td>
4242 <td><input type='checkbox' name='COMPLZO' $checked {'COMPLZO'}{'on'} /></td>
4244 <tr><td class='boldbase' nowrap='nowrap'>mssfix <img src='/blob.gif' /></td>
4245 <td><input type='checkbox' name='MSSFIX' $checked {'MSSFIX'}{'on'} /></td>
4246 <td> $Lang ::tr{'openvpn default'}: <span class="base">on</span></td>
4248 <tr><td class='boldbase' nowrap='nowrap'>fragment <img src='/blob.gif' /></td>
4249 <td><input type='TEXT' name='FRAGMENT' VALUE=' $cgiparams {'FRAGMENT'}'size='5' /></td>
4250 <td> $Lang ::tr{'openvpn default'}: <span class="base">1300</span></td>
4252 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'} <img src='/blob.gif' /></td>
4253 <td> <input type='TEXT' name='MTU' VALUE=' $cgiparams {'MTU'}'size='5' /></td>
4254 <td colspan='2'> $Lang ::tr{'openvpn default'}: udp/tcp <span class="base">1500/1400</span></td>
4256 <tr><td class='boldbase' nowrap='nowrap'>Management Port <img src='/blob.gif' /></td>
4257 <td> <input type='TEXT' name='OVPN_MGMT' VALUE=' $cgiparams {'OVPN_MGMT'}'size='5' /></td>
4258 <td colspan='2'> $Lang ::tr{'openvpn default'}: <span class="base"> $Lang ::tr{'destination port'}</span></td>
4261 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn mtu-disc'}</td>
4263 <input type='radio' name='PMTU_DISCOVERY' value='yes' $checked {'PMTU_DISCOVERY'}{'yes'} /> $Lang ::tr{'ovpn mtu-disc yes'}
4264 <input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked {'PMTU_DISCOVERY'}{'maybe'} /> $Lang ::tr{'ovpn mtu-disc maybe'}
4265 <input type='radio' name='PMTU_DISCOVERY' value='no' $checked {'PMTU_DISCOVERY'}{'no'} /> $Lang ::tr{'ovpn mtu-disc no'}
4266 <input type='radio' name='PMTU_DISCOVERY' value='off' $checked {'PMTU_DISCOVERY'}{'off'} /> $Lang ::tr{'ovpn mtu-disc off'}
4274 print "<tr><td class='boldbase'> $Lang ::tr{'remark title'} <img src='/blob.gif' /></td>" ;
4275 print "<td colspan='3'><input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' size='55' maxlength='50' /></td></tr></table>" ;
4277 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4278 print "<tr><td> $Lang ::tr{'enabled'} <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>" ;
4281 print "</tr></table><br><br>" ;
4282 #A.Marx CCD new client
4283 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4284 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>" ;
4287 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnnet );
4288 $vpnip = $vpnnet { 'DOVPN_SUBNET' };
4289 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
4293 $checked { 'check1' }{ 'off' } = '' ;
4294 $checked { 'check1' }{ 'on' } = '' ;
4295 $checked { 'check1' }{ $cgiparams { 'CHECK1' }} = 'CHECKED' ;
4296 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%'>" ;
4297 print "</td></tr></table><br><br>" ;
4298 my $name = $cgiparams { 'CHECK1' };
4299 $checked { 'RG' }{ $cgiparams { 'RG' }} = 'CHECKED' ;
4301 if (! - z
"${General::swroot}/ovpn/ccd.conf" ){
4302 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>" ;
4303 foreach my $key ( keys %ccdconfhash ) {
4305 @ccdconf =( $ccdconfhash { $key }[ 0 ], $ccdconfhash { $key }[ 1 ]);
4306 if ( $count % 2 ){ print "<tr bgcolor=' $color {'color22'}'>" ;} else { print "<tr bgcolor=' $color {'color20'}'>" ;}
4307 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%'>" ;
4308 & fillselectbox
( $ccdconf [ 1 ], $ccdconf [ 0 ], $cgiparams { $name });
4311 print "</table><br><br><hr><br><br>" ;
4315 & Header
:: closebox
();
4316 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
4318 } elsif (! $cgiparams { 'KEY' }) {
4322 my $cakeydisabled = '' ;
4323 my $cacrtdisabled = '' ;
4324 if ( ! - f
"${General::swroot}/ovpn/ca/cakey.pem" ) { $cakeydisabled = "disabled='disabled'" } else { $cakeydisabled = "" };
4325 if ( ! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) { $cacrtdisabled = "disabled='disabled'" } else { $cacrtdisabled = "" };
4327 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'authentication' });
4330 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4333 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
4335 <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>
4336 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td><td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
4337 <tr><td colspan='3'> </td></tr>
4338 <tr><td colspan='3'><hr /></td></tr>
4339 <tr><td colspan='3'> </td></tr>
4340 <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>
4341 <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>
4342 <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>
4343 <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>
4344 <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>
4345 <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>
4346 <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>
4347 <tr><td> </td><td class='base'> $Lang ::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
4358 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
4360 <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>
4361 <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>
4362 <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>
4363 <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>
4364 <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>
4365 <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>
4366 <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>
4367 <tr><td> </td><td class='base'> $Lang ::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
4379 foreach my $country ( sort keys %{ Countries
:: countries
}) {
4380 print "<option value=' $Countries ::countries{ $country }'" ;
4381 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
4382 print " selected='selected'" ;
4384 print "> $country </option>" ;
4390 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4394 <td> </td><td class='base'> $Lang ::tr{'valid till'} (days):</td>
4395 <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value=' $cgiparams {'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr>
4397 <td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
4398 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
4399 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'}:<BR>( $Lang ::tr{'confirmation'})</td>
4400 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
4401 <tr><td colspan='3'> </td></tr>
4402 <tr><td colspan='3'><hr /></td></tr>
4403 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
4409 <tr><td> </td><td> </td><td> </td></tr>
4410 <tr><td> </td><td> </td><td> </td></tr>
4411 <tr><td colspan='3'><hr /></td></tr>
4412 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
4422 & Header
:: closebox
();
4426 #A.Marx CCD new client
4427 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4429 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'ccd client options'}:" );
4433 <table border='0' width='100%'>
4434 <tr><td width='20%'>Redirect Gateway:</td><td colspan='3'><input type='checkbox' name='RG' $checked {'RG'}{'on'} /></td></tr>
4435 <tr><td colspan='4'><b><br> $Lang ::tr{'ccd routes'}</b></td></tr>
4436 <tr><td colspan='4'> </td></tr>
4437 <tr><td valign='top'> $Lang ::tr{'ccd iroute'}</td><td align='left' width='30%'><textarea name='IR' cols='26' rows='6' wrap='off'>
4440 if ( $cgiparams { 'IR' } ne '' ){
4441 print $cgiparams { 'IR' };
4443 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
4444 foreach my $key ( keys %ccdroutehash ) {
4445 if ( $cgiparams { 'NAME' } eq $ccdroutehash { $key }[ 0 ]){
4446 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}) {
4447 if ( $ccdroutehash { $key }[ $i ] ne '' ){
4448 print $ccdroutehash { $key }[ $i ]. " \n " ;
4450 $cgiparams { 'IR' } .= $ccdroutehash { $key }[ $i ];
4457 </textarea></td><td valign='top' colspan='2'> $Lang ::tr{'ccd iroutehint'}</td></tr>
4458 <tr><td colspan='4'><br></td></tr>
4459 <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>
4472 open ( FILE
, "${General::swroot}/main/routing" ) ;
4475 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
4476 print "<option> $Lang ::tr{'ccd none'}</option>" ;
4477 #check if static routes are defined for client
4478 foreach my $line ( @current ) {
4480 $line =~ s/\s*$//g ; # remove newline
4481 @temp = split ( /\,/ , $line );
4482 $temp [ 1 ] = '' unless defined $temp [ 1 ]; # not always populated
4483 my ( $a , $b ) = split ( /\/ /, $temp [ 1 ]);
4484 $temp [ 1 ] = $a . "/" .& General
:: iporsubtocidr
( $b );
4485 foreach my $key ( keys %ccdroute2hash ) {
4486 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4487 foreach my $i ( 1 .. $ #{$ccdroute2hash{$key}}) {
4488 if ( $ccdroute2hash { $key }[ $i ] eq $a . "/" .& General
:: iporsubtodec
( $b )){
4494 if ( $set == '1' && $#temp != - 1 ){ print "<option selected> $temp [1]</option>" ; $set = 0 ;} elsif ( $set == '0' && $#temp != - 1 ){ print "<option> $temp [1]</option>" ;}
4496 #check if green,blue,orange are defined for client
4497 foreach my $key ( keys %ccdroute2hash ) {
4498 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4500 foreach my $i ( 1 .. $ #{$ccdroute2hash{$key}}) {
4501 if ( $ccdroute2hash { $key }[ $i ] eq $netsettings { 'GREEN_NETADDRESS' }. "/" .& General
:: iporsubtodec
( $netsettings { 'GREEN_NETMASK' })){
4504 if (& haveBlueNet
()){
4505 if ( $ccdroute2hash { $key }[ $i ] eq $netsettings { 'BLUE_NETADDRESS' }. "/" .& General
:: iporsubtodec
( $netsettings { 'BLUE_NETMASK' })) {
4509 if (& haveOrangeNet
()){
4510 if ( $ccdroute2hash { $key }[ $i ] eq $netsettings { 'ORANGE_NETADDRESS' }. "/" .& General
:: iporsubtodec
( $netsettings { 'ORANGE_NETMASK' }) ) {
4517 if (& haveBlueNet
() && $selblue == '1' ){ print "<option selected> $Lang ::tr{'blue'}</option>" ; $selblue = 0 ;} elsif (& haveBlueNet
() && $selblue == '0' ){ print "<option> $Lang ::tr{'blue'}</option>" ;}
4518 if (& haveOrangeNet
() && $selorange == '1' ){ print "<option selected> $Lang ::tr{'orange'}</option>" ; $selorange = 0 ;} elsif (& haveOrangeNet
() && $selorange == '0' ){ print "<option> $Lang ::tr{'orange'}</option>" ;}
4519 if ( $selgreen == '1' || $other == '0' ){ print "<option selected> $Lang ::tr{'green'}</option>" ; $set = 0 ;} else { print "<option> $Lang ::tr{'green'}</option>" ;};
4522 </select></td><td valign='top'>DNS1:</td><td valign='top'><input type='TEXT' name='CCD_DNS1' value=' $cgiparams {'CCD_DNS1'}' size='30' /></td></tr>
4523 <tr valign='top'><td>DNS2:</td><td><input type='TEXT' name='CCD_DNS2' value=' $cgiparams {'CCD_DNS2'}' size='30' /></td></tr>
4524 <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>
4528 & Header
:: closebox
();
4530 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
4531 if ( $cgiparams { 'KEY' }) {
4532 # print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />";
4534 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
4535 & Header
:: closebigbox
();
4536 & Header
:: closepage
();
4544 ### Default status page
4549 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%cgiparams );
4550 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
4551 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
4553 my @status = `/bin/cat /var/log/ovpnserver.log` ;
4555 if ( $cgiparams { 'VPN_IP' } eq '' && - e
"${General::swroot}/red/active" ) {
4556 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
4557 my $ipaddr = < IPADDR
>;
4560 $cgiparams { 'VPN_IP' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
4561 if ( $cgiparams { 'VPN_IP' } eq '' ) {
4562 $cgiparams { 'VPN_IP' } = $ipaddr ;
4568 if ( $cgiparams { 'DCIPHER' } eq '' ) {
4569 $cgiparams { 'DCIPHER' } = 'BF-CBC' ;
4571 if ( $cgiparams { 'DDEST_PORT' } eq '' ) {
4572 $cgiparams { 'DDEST_PORT' } = '1194' ;
4574 if ( $cgiparams { 'DMTU' } eq '' ) {
4575 $cgiparams { 'DMTU' } = '1400' ;
4577 if ( $cgiparams { 'DOVPN_SUBNET' } eq '' ) {
4578 $cgiparams { 'DOVPN_SUBNET' } = '10.' . int ( rand ( 256 )) . '.' . int ( rand ( 256 )) . '.0/255.255.255.0' ;
4580 $checked { 'ENABLED' }{ 'off' } = '' ;
4581 $checked { 'ENABLED' }{ 'on' } = '' ;
4582 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = 'CHECKED' ;
4583 $checked { 'ENABLED_BLUE' }{ 'off' } = '' ;
4584 $checked { 'ENABLED_BLUE' }{ 'on' } = '' ;
4585 $checked { 'ENABLED_BLUE' }{ $cgiparams { 'ENABLED_BLUE' }} = 'CHECKED' ;
4586 $checked { 'ENABLED_ORANGE' }{ 'off' } = '' ;
4587 $checked { 'ENABLED_ORANGE' }{ 'on' } = '' ;
4588 $checked { 'ENABLED_ORANGE' }{ $cgiparams { 'ENABLED_ORANGE' }} = 'CHECKED' ;
4589 $selected { 'DDEVICE' }{ 'tun' } = '' ;
4590 $selected { 'DDEVICE' }{ 'tap' } = '' ;
4591 $selected { 'DDEVICE' }{ $cgiparams { 'DDEVICE' }} = 'SELECTED' ;
4593 $selected { 'DPROTOCOL' }{ 'udp' } = '' ;
4594 $selected { 'DPROTOCOL' }{ 'tcp' } = '' ;
4595 $selected { 'DPROTOCOL' }{ $cgiparams { 'DPROTOCOL' }} = 'SELECTED' ;
4597 $selected { 'DCIPHER' }{ 'DES-CBC' } = '' ;
4598 $selected { 'DCIPHER' }{ 'DES-EDE-CBC' } = '' ;
4599 $selected { 'DCIPHER' }{ 'DES-EDE3-CBC' } = '' ;
4600 $selected { 'DCIPHER' }{ 'DESX-CBC' } = '' ;
4601 $selected { 'DCIPHER' }{ 'RC2-CBC' } = '' ;
4602 $selected { 'DCIPHER' }{ 'RC2-40-CBC' } = '' ;
4603 $selected { 'DCIPHER' }{ 'RC2-64-CBC' } = '' ;
4604 $selected { 'DCIPHER' }{ 'BF-CBC' } = '' ;
4605 $selected { 'DCIPHER' }{ 'CAST5-CBC' } = '' ;
4606 $selected { 'DCIPHER' }{ 'AES-128-CBC' } = '' ;
4607 $selected { 'DCIPHER' }{ 'AES-192-CBC' } = '' ;
4608 $selected { 'DCIPHER' }{ 'AES-256-CBC' } = '' ;
4609 $selected { 'DCIPHER' }{ $cgiparams { 'DCIPHER' }} = 'SELECTED' ;
4610 $checked { 'DCOMPLZO' }{ 'off' } = '' ;
4611 $checked { 'DCOMPLZO' }{ 'on' } = '' ;
4612 $checked { 'DCOMPLZO' }{ $cgiparams { 'DCOMPLZO' }} = 'CHECKED' ;
4614 $checked { 'MSSFIX' }{ 'off' } = '' ;
4615 $checked { 'MSSFIX' }{ 'on' } = '' ;
4616 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
4618 & Header
:: showhttpheaders
();
4619 & Header
:: openpage
( $Lang :: tr
{ 'status ovpn' }, 1 , '' );
4620 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
4622 if ( $errormessage ) {
4623 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
4624 print "<class name='base'> $errormessage \n " ;
4625 print " </class> \n " ;
4626 & Header
:: closebox
();
4629 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>" ;
4630 my $srunning = "no" ;
4631 my $activeonrun = "" ;
4632 if ( - e
"/var/run/openvpn.pid" ){
4633 $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>" ;
4637 $activeonrun = "disabled='disabled'" ;
4639 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'global settings' });
4641 <table width='100%' border=0>
4642 <form method='post'>
4643 <td width='25%'> </td>
4644 <td width='25%'> </td>
4645 <td width='25%'> </td></tr>
4646 <tr><td class='boldbase'> $Lang ::tr{'ovpn server status'}</td>
4647 <td align='left'> $sactive </td>
4648 <tr><td class='boldbase'> $Lang ::tr{'ovpn on red'}</td>
4649 <td><input type='checkbox' name='ENABLED' $checked {'ENABLED'}{'on'} /></td>
4652 if (& haveBlueNet
()) {
4653 print "<tr><td class='boldbase'> $Lang ::tr{'ovpn on blue'}</td>" ;
4654 print "<td><input type='checkbox' name='ENABLED_BLUE' $checked {'ENABLED_BLUE'}{'on'} /></td>" ;
4656 if (& haveOrangeNet
()) {
4657 print "<tr><td class='boldbase'> $Lang ::tr{'ovpn on orange'}</td>" ;
4658 print "<td><input type='checkbox' name='ENABLED_ORANGE' $checked {'ENABLED_ORANGE'}{'on'} /></td>" ;
4661 <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>
4662 <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>
4663 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn device'}</td>
4664 <td><select name='DDEVICE' ><option value='tun' $selected {'DDEVICE'}{'tun'}>TUN</option>
4665 <!-- this is still not working
4666 <option value='tap' $selected {'DDEVICE'}{'tap'}>TAP</option></select>--> </td>
4667 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td>
4668 <td><select name='DPROTOCOL'><option value='udp' $selected {'DPROTOCOL'}{'udp'}>UDP</option>
4669 <option value='tcp' $selected {'DPROTOCOL'}{'tcp'}>TCP</option></select></td>
4670 <td class='boldbase'> $Lang ::tr{'destination port'}:</td>
4671 <td><input type='TEXT' name='DDEST_PORT' value=' $cgiparams {'DDEST_PORT'}' size='5' /></td></tr>
4672 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'} </td>
4673 <td> <input type='TEXT' name='DMTU' VALUE=' $cgiparams {'DMTU'}'size='5' /></TD>
4674 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'}</td>
4675 <td><input type='checkbox' name='DCOMPLZO' $checked {'DCOMPLZO'}{'on'} /></td>
4676 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'cipher'}</td>
4677 <td><select name='DCIPHER'><option value='DES-CBC' $selected {'DCIPHER'}{'DES-CBC'}>DES-CBC</option>
4678 <option value='DES-EDE-CBC' $selected {'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC</option>
4679 <option value='DES-EDE3-CBC' $selected {'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC</option>
4680 <option value='DESX-CBC' $selected {'DCIPHER'}{'DESX-CBC'}>DESX-CBC</option>
4681 <option value='RC2-CBC' $selected {'DCIPHER'}{'RC2-CBC'}>RC2-CBC</option>
4682 <option value='RC2-40-CBC' $selected {'DCIPHER'}{'RC2-40-CBC'}>RC2-40-CBC</option>
4683 <option value='RC2-64-CBC' $selected {'DCIPHER'}{'RC2-64-CBC'}>RC2-64-CBC</option>
4684 <option value='BF-CBC' $selected {'DCIPHER'}{'BF-CBC'}>BF-CBC</option>
4685 <option value='CAST5-CBC' $selected {'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC</option>
4686 <option value='AES-128-CBC' $selected {'DCIPHER'}{'AES-128-CBC'}>AES-128-CBC</option>
4687 <option value='AES-192-CBC' $selected {'DCIPHER'}{'AES-192-CBC'}>AES-192-CBC</option>
4688 <option value='AES-256-CBC' $selected {'DCIPHER'}{'AES-256-CBC'}>AES-256-CBC</option></select></td></tr>
4689 <tr><td colspan='4'><hr /></td></tr>
4693 if ( $srunning eq "yes" ) {
4694 print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' disabled='disabled' />" ;
4695 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'ccd net'}' />" ;
4696 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced server'}' />" ;
4697 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'stop ovpn server'}' /></td></tr>" ;
4699 print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
4700 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'ccd net'}' />" ;
4701 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced server'}' />" ;
4702 if (( - e
"${General::swroot}/ovpn/ca/cacert.pem" &&
4703 - e
"${General::swroot}/ovpn/ca/dh1024.pem" &&
4704 - e
"${General::swroot}/ovpn/certs/servercert.pem" &&
4705 - e
"${General::swroot}/ovpn/certs/serverkey.pem" ) &&
4706 (( $cgiparams { 'ENABLED' } eq 'on' ) ||
4707 ( $cgiparams { 'ENABLED_BLUE' } eq 'on' ) ||
4708 ( $cgiparams { 'ENABLED_ORANGE' } eq 'on' ))){
4709 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'start ovpn server'}' /></td></tr>" ;
4711 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'start ovpn server'}' disabled='disabled' /></td></tr>" ;
4714 print "</form></table>" ;
4715 & Header
:: closebox
();
4716 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'certificate authorities'}:" );
4718 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
4720 <td width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></td>
4721 <td width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></td>
4722 <td width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></td>
4726 if (- f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
4727 my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem` ;
4728 $casubject =~ /Subject: (.*)[\n]/ ;
4730 $casubject =~ s
+/ Email
+, E
+;
4731 $casubject =~ s/ ST=/ S=/ ;
4734 <tr bgcolor=' $color {'color22'}'>
4735 <td class='base'> $Lang ::tr{'root certificate'}</td>
4736 <td class='base'> $casubject </td>
4737 <form method='post' name='frmrootcrta'><td width='3%' align='center'>
4738 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
4739 <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' />
4741 <form method='post' name='frmrootcrtb'><td width='3%' align='center'>
4742 <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' />
4743 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
4745 <td width='4%'> </td></tr>
4749 # display rootcert generation buttons
4751 <tr bgcolor=' $color {'color22'}'>
4752 <td class='base'> $Lang ::tr{'root certificate'}:</td>
4753 <td class='base'> $Lang ::tr{'not present'}</td>
4754 <td colspan='3'> </td></tr>
4759 if (- f
"${General::swroot}/ovpn/certs/servercert.pem" ) {
4760 my $hostsubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem` ;
4761 $hostsubject =~ /Subject: (.*)[\n]/ ;
4763 $hostsubject =~ s
+/ Email
+, E
+;
4764 $hostsubject =~ s/ ST=/ S=/ ;
4767 <tr bgcolor=' $color {'color20'}'>
4768 <td class='base'> $Lang ::tr{'host certificate'}</td>
4769 <td class='base'> $hostsubject </td>
4770 <form method='post' name='frmhostcrta'><td width='3%' align='center'>
4771 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
4772 <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' />
4774 <form method='post' name='frmhostcrtb'><td width='3%' align='center'>
4775 <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' />
4776 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download host certificate'}' />
4778 <td width='4%'> </td></tr>
4784 <tr bgcolor=' $color {'color20'}'>
4785 <td width='25%' class='base'> $Lang ::tr{'host certificate'}:</td>
4786 <td class='base'> $Lang ::tr{'not present'}</td>
4787 </td><td colspan='3'> </td></tr>
4792 if (! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
4793 print "<tr><td colspan='5' align='center'><form method='post'>" ;
4794 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' />" ;
4795 print "</form></td></tr> \n " ;
4798 if ( keys %cahash > 0 ) {
4799 foreach my $key ( keys %cahash ) {
4800 if (( $key + 1 ) % 2 ) {
4801 print "<tr bgcolor=' $color {'color20'}'> \n " ;
4803 print "<tr bgcolor=' $color {'color22'}'> \n " ;
4805 print "<td class='base'> $cahash { $key }[0]</td> \n " ;
4806 print "<td class='base'> $cahash { $key }[1]</td> \n " ;
4808 <form method='post' name='cafrm${key}a'><td align='center'>
4809 <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' />
4810 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
4811 <input type='hidden' name='KEY' value=' $key ' />
4813 <form method='post' name='cafrm${key}b'><td align='center'>
4814 <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' />
4815 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
4816 <input type='hidden' name='KEY' value=' $key ' />
4818 <form method='post' name='cafrm${key}c'><td align='center'>
4819 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
4820 <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' />
4821 <input type='hidden' name='KEY' value=' $key ' />
4830 # If the file contains entries, print Key to action icons
4831 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
4835 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
4836 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
4837 <td class='base'> $Lang ::tr{'show certificate'}</td>
4838 <td> <img src='/images/media-floppy.png' alt=' $Lang ::tr{'download certificate'}' /></td>
4839 <td class='base'> $Lang ::tr{'download certificate'}</td>
4847 <form method='post' enctype='multipart/form-data'>
4848 <table width='100%' border='0'>
4849 <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>
4850 <tr><td colspan='4'><hr /></td></tr>
4851 <tr align='right'><td colspan='4' align='right' width='80%'><input type='submit' name='ACTION' value=' $Lang ::tr{'show crl'}' /></td></tr>
4857 & Header
:: closebox
();
4858 if ( $srunning eq "yes" ) {
4859 print "<div align='center'><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'reset'}' disabled='disabled' /></div></form> \n " ;
4861 print "<div align='center'><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'reset'}' /></div></form> \n " ;
4863 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
4867 #<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>
4870 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'Client status and controlc' });
4874 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
4876 <td width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></td>
4877 <td width='15%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></td>
4878 <td width='22%' class='boldbase' align='center'><b> $Lang ::tr{'network'}</b></td>
4879 <td width='20%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></td>
4880 <td width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></td>
4881 <td width='5%' class='boldbase' colspan='6' align='center'><b> $Lang ::tr{'action'}</b></td>
4887 foreach my $key ( sort { uc ( $confighash { $a }[ 1 ]) cmp uc ( $confighash { $b }[ 1 ]) } keys %confighash ) {
4888 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
4891 print "<tr bgcolor=' $color {'color20'}'> \n " ;
4893 print "<tr bgcolor=' $color {'color22'}'> \n " ;
4895 print "<td align='center' nowrap='nowrap'> $confighash { $key }[1]</td>" ;
4896 print "<td align='center' nowrap='nowrap'>" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ")</td>" ;
4897 #if ($confighash{$key}[4] eq 'cert') {
4898 #print "<td align='left' nowrap='nowrap'>$confighash{$key}[2]</td>";
4900 #print "<td align='left'> </td>";
4902 my $cavalid = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $confighash { $key }[1]cert.pem` ;
4903 $cavalid =~ /Not After : (.*)[\n]/ ;
4905 if ( $confighash { $key }[ 32 ] eq "" && $confighash { $key }[ 3 ] eq 'net' ){ $confighash { $key }[ 32 ]= "net-2-net" ;}
4906 if ( $confighash { $key }[ 32 ] eq "" && $confighash { $key }[ 3 ] eq 'host' ){ $confighash { $key }[ 32 ]= "dynamic" ;}
4907 print "<td align='center'> $confighash { $key }[32]</td>" ;
4908 print "<td align='center'> $confighash { $key }[25]</td>" ;
4910 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>" ;
4912 if ( $confighash { $key }[ 0 ] eq 'off' ) {
4913 $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>" ;
4920 if ( $confighash { $key }[ 3 ] eq 'net' ) {
4922 if (- e
"/var/run/ $confighash { $key }[1]n2n.pid" ) {
4925 my $tport = $confighash { $key }[ 22 ];
4926 my $tnet = new Net
:: Telnet
( Timeout
=> 5 , Errmode
=> 'return' , Port
=> $tport );
4928 $tnet -> open ( '127.0.0.1' );
4929 @output = $tnet -> cmd ( String
=> 'state' , Prompt
=> '/(END.* \n |ERROR:.* \n )/' );
4930 @tustate = split ( /\,/ , $output [ 1 ]);
4932 #CONNECTING -- OpenVPN's initial state.
4933 #WAIT -- (Client only) Waiting for initial response from server.
4934 #AUTH -- (Client only) Authenticating with server.
4935 #GET_CONFIG -- (Client only) Downloading configuration options from server.
4936 #ASSIGN_IP -- Assigning IP address to virtual network interface.
4937 #ADD_ROUTES -- Adding routes to system.
4938 #CONNECTED -- Initialization Sequence Completed.
4939 #RECONNECTING -- A restart has occurred.
4940 #EXITING -- A graceful exit is in progress.
4943 if ( $tustate [ 1 ] eq 'CONNECTED' ) {
4944 $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>" ;
4946 $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>" ;
4954 foreach my $line ( @status ) {
4956 if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ ) {
4957 @match = split ( m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ , $line );
4958 if ( $match [ 1 ] ne "Common Name" ) {
4962 if ( $cn eq " $confighash { $key }[2]" ) {
4963 $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>" ;
4972 my $disable_clientdl = "disabled='disabled'" ;
4973 if (( $cgiparams { 'ENABLED' } eq 'on' ) ||
4974 ( $cgiparams { 'ENABLED_BLUE' } eq 'on' ) ||
4975 ( $cgiparams { 'ENABLED_ORANGE' } eq 'on' )){
4976 $disable_clientdl = "" ;
4979 <td align='center'> $active </td>
4981 <form method='post' name='frm${key}a'><td align='center'>
4982 <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' />
4983 <input type='hidden' name='ACTION' value=' $Lang ::tr{'dl client arch'}' $disable_clientdl />
4984 <input type='hidden' name='KEY' value=' $key ' $disable_clientdl />
4988 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
4990 <form method='post' name='frm${key}b'><td align='center'>
4991 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' border='0' />
4992 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
4993 <input type='hidden' name='KEY' value=' $key ' />
4997 print "<td> </td>" ;
4999 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $key }[1].p12" ) {
5001 <form method='post' name='frm${key}c'><td align='center'>
5002 <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' />
5003 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
5004 <input type='hidden' name='KEY' value=' $key ' />
5007 ; } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
5009 <form method='post' name='frm${key}c'><td align='center'>
5010 <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' />
5011 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
5012 <input type='hidden' name='KEY' value=' $key ' />
5016 print "<td> </td>" ;
5019 <form method='post' name='frm${key}d'><td align='center'>
5020 <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' />
5021 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
5022 <input type='hidden' name='KEY' value=' $key ' />
5025 <form method='post' name='frm${key}e'><td align='center'>
5026 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
5027 <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'/>
5028 <input type='hidden' name='KEY' value=' $key ' />
5030 <form method='post' name='frm${key}f'><td align='center'>
5031 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
5032 <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' />
5033 <input type='hidden' name='KEY' value=' $key ' />
5042 # If the config file contains entries, print Key to action icons
5047 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
5048 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
5049 <td class='base'> $Lang ::tr{'click to disable'}</td>
5050 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
5051 <td class='base'> $Lang ::tr{'show certificate'}</td>
5052 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
5053 <td class='base'> $Lang ::tr{'edit'}</td>
5054 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
5055 <td class='base'> $Lang ::tr{'remove'}</td>
5059 <td> <img src='/images/off.gif' alt='?OFF' /></td>
5060 <td class='base'> $Lang ::tr{'click to enable'}</td>
5061 <td> <img src='/images/media-floppy.png' alt='?FLOPPY' /></td>
5062 <td class='base'> $Lang ::tr{'download certificate'}</td>
5063 <td> <img src='/images/openvpn.png' alt='?RELOAD'/></td>
5064 <td class='base'> $Lang ::tr{'dl client arch'}</td>
5072 <table width='100%'>
5073 <form method='post'>
5074 <tr><td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />
5075 <input type='submit' name='ACTION' value=' $Lang ::tr{'ovpn con stat'}' $activeonrun /></td></tr>
5080 & Header
:: closebox
();
5082 & Header
:: closepage
();