]>
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 my $confighost = "${General::swroot}/fwhosts/customhosts" ;
68 my $configgrp = "${General::swroot}/fwhosts/customgroups" ;
69 my $customnet = "${General::swroot}/fwhosts/customnetworks" ;
71 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%netsettings );
72 $cgiparams { 'ENABLED' } = 'off' ;
73 $cgiparams { 'ENABLED_BLUE' } = 'off' ;
74 $cgiparams { 'ENABLED_ORANGE' } = 'off' ;
75 $cgiparams { 'EDIT_ADVANCED' } = 'off' ;
76 $cgiparams { 'NAT' } = 'off' ;
77 $cgiparams { 'COMPRESSION' } = 'off' ;
78 $cgiparams { 'ONLY_PROPOSED' } = 'off' ;
79 $cgiparams { 'ACTION' } = '' ;
80 $cgiparams { 'CA_NAME' } = '' ;
81 $cgiparams { 'DHCP_DOMAIN' } = '' ;
82 $cgiparams { 'DHCP_DNS' } = '' ;
83 $cgiparams { 'DHCP_WINS' } = '' ;
84 $cgiparams { 'ROUTES_PUSH' } = '' ;
85 $cgiparams { 'DCOMPLZO' } = 'off' ;
86 $cgiparams { 'MSSFIX' } = '' ;
87 $cgiparams { 'number' } = '' ;
88 $cgiparams { 'PMTU_DISCOVERY' } = '' ;
89 $routes_push_file = "${General::swroot}/ovpn/routes_push" ;
90 unless (- e
$routes_push_file ) { system ( "touch $routes_push_file " ); }
91 unless (- e
"${General::swroot}/ovpn/ccd.conf" ) { system ( "touch ${General::swroot}/ovpn/ccd.conf" ); }
92 unless (- e
"${General::swroot}/ovpn/ccdroute" ) { system ( "touch ${General::swroot}/ovpn/ccdroute" ); }
93 unless (- e
"${General::swroot}/ovpn/ccdroute2" ) { system ( "touch ${General::swroot}/ovpn/ccdroute2" ); }
95 & Header
:: getcgihash
( \
%cgiparams , { 'wantfile' => 1 , 'filevar' => 'FH' });
97 # prepare openvpn config file
103 if ( $netsettings { 'CONFIG_TYPE' } == 2 ) { return 1 ;}
104 if ( $netsettings { 'CONFIG_TYPE' } == 4 ) { return 1 ;}
110 if ( $netsettings { 'CONFIG_TYPE' } == 3 ) { return 1 ;}
111 if ( $netsettings { 'CONFIG_TYPE' } == 4 ) { return 1 ;}
116 my $bytesize = shift ;
119 while ( abs ( $bytesize ) >= 1024 ){
120 $bytesize = $bytesize / 1024 ;
125 my @units = ( "Bytes" , "KB" , "MB" , "GB" , "TB" , "PB" , "EB" );
126 my $newsize =( int ( $bytesize * 100 + 0.5 ))/ 100 ;
127 return ( " $newsize $units [ $i ]" );
131 my $hostname = $_ [ 0 ];
132 unless ( $hostname ) { return "No hostname" };
133 my $res = new Net
:: DNS
:: Resolver
;
134 my $query = $res -> search ( " $hostname " );
136 foreach my $rr ( $query -> answer ) {
137 ## Potential bug - we are only looking at A records:
138 return 0 if $rr -> type eq "A" ;
141 return $res -> errorstring ;
147 if ( open ( FILE
, ">${General::swroot}/ovpn/certs/serial" )) {
151 if ( open ( FILE
, ">${General::swroot}/ovpn/certs/index.txt" )) {
155 unlink ( "${General::swroot}/ovpn/certs/index.txt.old" );
156 unlink ( "${General::swroot}/ovpn/certs/serial.old" );
157 unlink ( "${General::swroot}/ovpn/certs/01.pem" );
160 sub newcleanssldatabase
162 if (! - s
"${General::swroot}/ovpn/certs/serial" ) {
163 open ( FILE
, ">${General::swroot}(ovpn/certs/serial" );
167 if (! - s
">${General::swroot}/ovpn/certs/index.txt" ) {
168 system ( "touch ${General::swroot}/ovpn/certs/index.txt" );
170 unlink ( "${General::swroot}/ovpn/certs/index.txt.old" );
171 unlink ( "${General::swroot}/ovpn/certs/serial.old" );
176 if ( open ( FILE
, "${General::swroot}/ovpn/certs/serial.old" )) {
177 my $hexvalue = < FILE
>;
180 unlink ( "${General::swroot}/ovpn/certs/ $hexvalue .pem" );
185 my $KEY2 = $_ [ 0 ]; # key2
186 my $SRC_PORT = $_ [ 1 ]; # src_port
187 my $PROTOCOL = $_ [ 2 ]; # protocol
188 my $SRC_IP = $_ [ 3 ]; # sourceip
190 my $pfwfilename = "${General::swroot}/portfw/config" ;
191 open ( FILE
, $pfwfilename ) or die 'Unable to open config file.' ;
192 my @pfwcurrent = < FILE
>;
194 my $pfwkey1 = 0 ; # used for finding last sequence number used
195 foreach my $pfwline ( @pfwcurrent )
197 my @pfwtemp = split ( /\,/ , $pfwline );
200 if ( $KEY2 eq "0" ){ # if key2 is 0 then it is a portfw addition
201 if ( $SRC_PORT eq $pfwtemp [ 3 ] &&
202 $PROTOCOL eq $pfwtemp [ 2 ] &&
203 $SRC_IP eq $pfwtemp [ 7 ])
205 $errormessage = " $Lang ::tr{'source port in use'} $SRC_PORT " ;
207 # Check if key2 = 0, if it is then it is a port forward entry and we want the sequence number
208 if ( $pfwtemp [ 1 ] eq "0" ) {
209 $pfwkey1 = $pfwtemp [ 0 ];
211 # Darren Critchley - Duplicate or overlapping Port range check
212 if ( $pfwtemp [ 1 ] eq "0" &&
213 $PROTOCOL eq $pfwtemp [ 2 ] &&
214 $SRC_IP eq $pfwtemp [ 7 ] &&
217 & portchecks
( $SRC_PORT , $pfwtemp [ 5 ]);
218 # &portchecks($pfwtemp[3], $pfwtemp[5]);
219 # &portchecks($pfwtemp[3], $SRC_IP);
223 # $errormessage="$KEY2 $SRC_PORT $PROTOCOL $SRC_IP";
230 my $portrange1 = $_ [ 0 ]; # New port range
231 my $portrange2 = $_ [ 1 ]; # existing port range
232 my @tempr1 = split ( /\:/ , $portrange1 );
233 my @tempr2 = split ( /\:/ , $portrange2 );
235 unless (& checkportinc
( $tempr1 [ 0 ], $portrange2 )){ return 0 ;}
236 unless (& checkportinc
( $tempr1 [ 1 ], $portrange2 )){ return 0 ;}
238 unless (& checkportinc
( $tempr2 [ 0 ], $portrange1 )){ return 0 ;}
239 unless (& checkportinc
( $tempr2 [ 1 ], $portrange1 )){ return 0 ;}
241 return 1 ; # Everything checks out!
244 # Darren Critchley - we want to make sure that a port entry is not within an already existing range
247 my $port1 = $_ [ 0 ]; # Port
248 my $portrange2 = $_ [ 1 ]; # Port range
249 my @tempr1 = split ( /\:/ , $portrange2 );
251 if ( $port1 < $tempr1 [ 0 ] || $port1 > $tempr1 [ 1 ]) {
257 # Darren Critchley - Duplicate or overlapping Port range check
260 my $p1 = $_ [ 0 ]; # New port range
261 my $p2 = $_ [ 1 ]; # existing port range
263 our ( $prtrange1 , $prtrange2 );
265 # if (m/:/ && $prtrange1 == 1) { # comparing two port ranges
266 # unless (&checkportoverlap($p1,$p2)) {
267 # $errormessage = "$Lang::tr{'source port overlaps'} $p1";
270 if ( m/:/ && $prtrange1 == 0 && $errormessage eq '' ) { # compare one port to a range
271 unless (& checkportinc
( $p2 , $p1 )) {
272 $errormessage = " $Lang ::tr{'srcprt within existing'} $p1 " ;
276 if (! m/:/ && $prtrange1 == 1 && $errormessage eq '' ) { # compare one port to a range
277 unless (& checkportinc
( $p1 , $p2 )) {
278 $errormessage = " $Lang ::tr{'srcprt range overlaps'} $p2 " ;
284 # Darren Critchley - certain ports are reserved for IPFire
285 # TCP 67,68,81,222,445
287 # Params passed in -> port, rangeyn, protocol
290 # port 67 and 68 same for tcp and udp, don't bother putting in an array
292 my @tcp_reserved = ( 81 , 222 , 445 );
293 my $prt = $_ [ 0 ]; # the port or range
294 my $ryn = $_ [ 1 ]; # tells us whether or not it is a port range
295 my $prot = $_ [ 2 ]; # protocol
296 my $srcdst = $_ [ 3 ]; # source or destination
297 if ( $ryn ) { # disect port range
298 if ( $srcdst eq "src" ) {
299 $msg = " $Lang ::tr{'rsvd src port overlap'}" ;
301 $msg = " $Lang ::tr{'rsvd dst port overlap'}" ;
303 my @tmprng = split ( /\:/ , $prt );
304 unless ( 67 < $tmprng [ 0 ] || 67 > $tmprng [ 1 ]) { $errormessage = " $msg 67" ; return ; }
305 unless ( 68 < $tmprng [ 0 ] || 68 > $tmprng [ 1 ]) { $errormessage = " $msg 68" ; return ; }
306 if ( $prot eq "tcp" ) {
307 foreach my $prange ( @tcp_reserved ) {
308 unless ( $prange < $tmprng [ 0 ] || $prange > $tmprng [ 1 ]) { $errormessage = " $msg $prange " ; return ; }
312 if ( $srcdst eq "src" ) {
313 $msg = " $Lang ::tr{'reserved src port'}" ;
315 $msg = " $Lang ::tr{'reserved dst port'}" ;
317 if ( $prt == 67 ) { $errormessage = " $msg 67" ; return ; }
318 if ( $prt == 68 ) { $errormessage = " $msg 68" ; return ; }
319 if ( $prot eq "tcp" ) {
320 foreach my $prange ( @tcp_reserved ) {
321 if ( $prange == $prt ) { $errormessage = " $msg $prange " ; return ; }
328 sub writeserverconf
{
329 my %sovpnsettings = ();
331 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%sovpnsettings );
334 open ( CONF
, ">${General::swroot}/ovpn/server.conf" ) or die "Unable to open ${General::swroot}/ovpn/server.conf: $!" ;
336 print CONF
"#OpenVPN Server conf \n " ;
338 print CONF
"daemon openvpnserver \n " ;
339 print CONF
"writepid /var/run/openvpn.pid \n " ;
340 print CONF
"#DAN prepare OpenVPN for listening on blue and orange \n " ;
341 print CONF
";local $sovpnsettings {'VPN_IP'} \n " ;
342 print CONF
"dev $sovpnsettings {'DDEVICE'} \n " ;
343 print CONF
"proto $sovpnsettings {'DPROTOCOL'} \n " ;
344 print CONF
"port $sovpnsettings {'DDEST_PORT'} \n " ;
345 print CONF
"script-security 3 system \n " ;
346 print CONF
"ifconfig-pool-persist /var/ipfire/ovpn/ovpn-leases.db 3600 \n " ;
347 print CONF
"client-config-dir /var/ipfire/ovpn/ccd \n " ;
348 print CONF
"tls-server \n " ;
349 print CONF
"ca /var/ipfire/ovpn/ca/cacert.pem \n " ;
350 print CONF
"cert /var/ipfire/ovpn/certs/servercert.pem \n " ;
351 print CONF
"key /var/ipfire/ovpn/certs/serverkey.pem \n " ;
352 print CONF
"dh /var/ipfire/ovpn/ca/dh1024.pem \n " ;
353 my @tempovpnsubnet = split ( "\/" , $sovpnsettings { 'DOVPN_SUBNET' });
354 print CONF
"server $tempovpnsubnet [0] $tempovpnsubnet [1] \n " ;
355 #print CONF "push \"route $netsettings{'GREEN_NETADDRESS'} $netsettings{'GREEN_NETMASK'}\"\n";
357 # Check if we are using mssfix, fragment or mtu-disc and set the corretct mtu of 1500.
358 # If we doesn't use one of them, we can use the configured mtu value.
359 if ( $sovpnsettings { 'MSSFIX' } eq 'on' )
360 { print CONF
" $sovpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
361 elsif ( $sovpnsettings { 'FRAGMENT' } ne '' && $sovpnsettings { 'DPROTOCOL' } ne 'tcp' )
362 { print CONF
" $sovpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
363 elsif (( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'yes' ) ||
364 ( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
365 ( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'no' ))
366 { print CONF
" $sovpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
368 { print CONF
" $sovpnsettings {'DDEVICE'}-mtu $sovpnsettings {'DMTU'} \n " ; }
370 if ( $vpnsettings { 'ROUTES_PUSH' } ne '' ) {
371 @temp = split ( /\n/ , $vpnsettings { 'ROUTES_PUSH' });
374 @tempovpnsubnet = split ( "\/" ,& General
:: ipcidr2msk
( $_ ));
375 print CONF
"push \" route " . $tempovpnsubnet [ 0 ]. " " . $tempovpnsubnet [ 1 ] . " \"\n " ;
380 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
381 foreach my $key ( keys %ccdconfhash ) {
382 my $a = $ccdconfhash { $key }[ 1 ];
383 my ( $b , $c ) = split ( /\/ /, $a );
384 print CONF
"route $b " .& General
:: cidrtosub
( $c ). " \n " ;
387 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
388 foreach my $key ( keys %ccdroutehash ) {
389 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}){
390 my ( $a , $b )= split ( /\/ /, $ccdroutehash { $key }[ $i ]);
391 print CONF
"route $a $b \n " ;
396 if ( $sovpnsettings { CLIENT2CLIENT
} eq 'on' ) {
397 print CONF
"client-to-client \n " ;
399 if ( $sovpnsettings { MSSFIX
} eq 'on' ) {
400 print CONF
"mssfix \n " ;
402 if ( $sovpnsettings { FRAGMENT
} ne '' && $sovpnsettings { 'DPROTOCOL' } ne 'tcp' ) {
403 print CONF
"fragment $sovpnsettings {'FRAGMENT'} \n " ;
406 # Check if a valid operating mode has been choosen and use it.
407 if (( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'yes' ) ||
408 ( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
409 ( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'no' )) {
410 print CONF
"mtu-disc $sovpnsettings {'PMTU_DISCOVERY'} \n " ;
413 if ( $sovpnsettings { KEEPALIVE_1
} > 0 && $sovpnsettings { KEEPALIVE_2
} > 0 ) {
414 print CONF
"keepalive $sovpnsettings {'KEEPALIVE_1'} $sovpnsettings {'KEEPALIVE_2'} \n " ;
416 print CONF
"status-version 1 \n " ;
417 print CONF
"status /var/log/ovpnserver.log 30 \n " ;
418 print CONF
"cipher $sovpnsettings {DCIPHER} \n " ;
419 if ( $sovpnsettings { DCOMPLZO
} eq 'on' ) {
420 print CONF
"comp-lzo \n " ;
422 if ( $sovpnsettings { REDIRECT_GW_DEF1
} eq 'on' ) {
423 print CONF
"push \" redirect-gateway def1 \"\n " ;
425 if ( $sovpnsettings { DHCP_DOMAIN
} ne '' ) {
426 print CONF
"push \" dhcp-option DOMAIN $sovpnsettings {DHCP_DOMAIN} \"\n " ;
429 if ( $sovpnsettings { DHCP_DNS
} ne '' ) {
430 print CONF
"push \" dhcp-option DNS $sovpnsettings {DHCP_DNS} \"\n " ;
433 if ( $sovpnsettings { DHCP_WINS
} ne '' ) {
434 print CONF
"push \" dhcp-option WINS $sovpnsettings {DHCP_WINS} \"\n " ;
437 if ( $sovpnsettings { DHCP_WINS
} eq '' ) {
438 print CONF
"max-clients 100 \n " ;
440 if ( $sovpnsettings { DHCP_WINS
} ne '' ) {
441 print CONF
"max-clients $sovpnsettings {MAX_CLIENTS} \n " ;
443 print CONF
"tls-verify /var/ipfire/ovpn/verify \n " ;
444 print CONF
"crl-verify /var/ipfire/ovpn/crls/cacrl.pem \n " ;
445 print CONF
"user nobody \n " ;
446 print CONF
"group nobody \n " ;
447 print CONF
"persist-key \n " ;
448 print CONF
"persist-tun \n " ;
449 if ( $sovpnsettings { LOG_VERB
} ne '' ) {
450 print CONF
"verb $sovpnsettings {LOG_VERB} \n " ;
452 print CONF
"verb 3 \n " ;
460 if ( open ( FILE
, ">/var/log/ovpnserver.log" )) {
470 my %ccdconfhash = ();
472 my $ccdnetname = $_ [ 0 ];
473 if (- f
"${General::swroot}/ovpn/ovpnconfig" ){
474 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
475 foreach my $key ( keys %ccdhash ) {
476 if ( $ccdhash { $key }[ 32 ] eq $ccdnetname ) {
477 $errormessage = $Lang :: tr
{ 'ccd err hostinnet' };
482 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
483 foreach my $key ( keys %ccdconfhash ) {
484 if ( $ccdconfhash { $key }[ 0 ] eq $ccdnetname ){
485 delete $ccdconfhash { $key };
488 & General
:: writehasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
500 my $ovpnsubnet = $_ [ 2 ];
511 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err name' }. "<br>" ;
515 if (!& General
:: validhostname
( $ccdname ))
517 $errormessage = $Lang :: tr
{ 'ccd err invalidname' };
521 ( $ccdip , $subcidr ) = split ( /\/ /, $ccdnet );
522 $subcidr =& General
:: iporsubtocidr
( $subcidr );
526 $errormessage = $Lang :: tr
{ 'ccd err invalidnet' };
530 if (!& General
:: validipandmask
( $ccdnet )){
531 $errormessage = $Lang :: tr
{ 'ccd err invalidnet' };
536 #check if we try to use same network as ovpn server
537 if (& General
:: iporsubtocidr
( $ccdnet ) eq & General
:: iporsubtocidr
( $ovpnsubnet )) {
538 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err isovpnnet' }. "<br>" ;
541 #check if we use a name/subnet that already exists
542 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
543 foreach my $key ( keys %ccdconfhash ) {
544 @ccdconf = split ( /\/ /, $ccdconfhash { $key }[ 1 ]);
545 if ( $ccdname eq $ccdconfhash { $key }[ 0 ]) { $errormessage = $errormessage . $Lang :: tr
{ 'ccd err nameexist' }. "<br>" ;}
546 my ( $newip , $newsub ) = split ( /\/ /, $ccdnet );
547 if (& General
:: IpInSubnet
( $newip , $ccdconf [ 0 ],& General
:: iporsubtodec
( $ccdconf [ 1 ]))) { $errormessage = $errormessage . $Lang :: tr
{ 'ccd err issubnet' }. "<br>" ;}
550 #check if we use one of ipfire's networks (green,orange,blue)
552 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%ownnet );
553 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' };}
554 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' };}
555 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' };}
556 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' };}
559 if (! $errormessage ) {
561 $baseaddress =& General
:: getnetworkip
( $ccdip , $subcidr );
562 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
563 my $key = & General
:: findhasharraykey
( \
%ccdconfhash );
564 foreach my $i ( 0 .. 1 ) { $ccdconfhash { $key }[ $i ] = "" ;}
565 $ccdconfhash { $key }[ 0 ] = $ccdname ;
566 $ccdconfhash { $key }[ 1 ] = $baseaddress . "/" . $subcidr ;
567 & General
:: writehasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
569 $cgiparams { 'ccdname' }= '' ;
570 $cgiparams { 'ccdsubnet' }= '' ;
582 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
583 foreach my $key ( keys %ccdconfhash ) {
584 if ( $ccdconfhash { $key }[ 0 ] eq $oldname ) {
585 foreach my $key1 ( keys %ccdconfhash ) {
586 if ( $ccdconfhash { $key1 }[ 0 ] eq $newname ){
587 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err netadrexist' };
590 $ccdconfhash { $key }[ 0 ]= $newname ;
591 & General
:: writehasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
598 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
599 foreach my $key ( keys %ccdhash ) {
600 if ( $ccdhash { $key }[ 32 ] eq $oldname ) {
601 $ccdhash { $key }[ 32 ]= $newname ;
602 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
611 my $ccdnetwork = $_ [ 0 ];
614 @octets = split ( "\/" , $ccdnetwork );
615 @subnet = split /\./ , & General
:: cidrtosub
( $octets [ 1 ]);
628 my ( $ip1 , $ip2 , $ip3 , $ip4 )= split /\./ , $ipin ;
636 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
637 $iprange [ 0 ]= $ip1 . "." . $ip2 . "." . $ip3 . "." .2 ;
638 for ( my $i = 0 ; $i <= $count - 1 ; $i ++) {
639 my $tmpip = $iprange [ $i - 1 ];
641 $iprange [ $i ]= & General
:: getnextip
( $tmpip , 4 );
644 foreach my $key ( keys %ccdhash ) {
646 foreach my $tmp ( @iprange ){
647 my ( $net , $sub ) = split ( /\/ /, $ccdhash { $key }[ 33 ]);
649 if ( $hasip ne $ccdhash { $key }[ 33 ] ){
650 splice ( @iprange , $r , 1 );
662 my ( $ccdip , $subcidr ) = split ( "/" , $_ [ 0 ]);
664 my @allccdips =& getccdadresses
( $ccdip , $subcidr ,& ccdmaxclients
( $ccdip . "/" . $subcidr ), $tz );
665 print "<select name=' $boxname ' STYLE='font-family : arial; font-size : 9pt; width:130px;' >" ;
666 foreach ( @allccdips ) {
669 print "<option value=' $ip ' " ;
670 if ( $ip eq $cgiparams { $boxname } ){
673 print "> $ip </option>" ;
683 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
684 foreach my $key ( keys %ccdhash ) {
685 if ( $ccdhash { $key }[ 32 ] eq $name ){ $i ++;}
690 sub check_routes_push
693 my ( $ip , $cidr ) = split ( /\/ /, $val );
694 ##check for existing routes in routes_push
695 if (- e
"${General::swroot}/ovpn/routes_push" ) {
696 open ( FILE
, "${General::swroot}/ovpn/routes_push" );
700 my ( $ip2 , $cidr2 ) = split ( /\/ /, " $_ " );
701 my $val2 = $ip2 . "/" .& General
:: iporsubtodec
( $cidr2 );
707 if (& General
:: IpInSubnet
( $ip , $ip2 ,& General
:: iporsubtodec
( $cidr2 ))){
720 my ( $ip , $cidr ) = split ( /\/ /, $val );
721 #check for existing routes in ccdroute
722 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
723 foreach my $key ( keys %ccdroutehash ) {
724 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}) {
725 if (& General
:: iporsubtodec
( $val ) eq $ccdroutehash { $key }[ $i ] && $ccdroutehash { $key }[ 0 ] ne $cgiparams { 'NAME' }){
728 my ( $ip2 , $cidr2 ) = split ( /\/ /, $ccdroutehash { $key }[ $i ]);
730 if (& General
:: IpInSubnet
( $ip , $ip2 , $cidr2 )&& $ccdroutehash { $key }[ 0 ] ne $cgiparams { 'NAME' } ){
741 my ( $ip , $cidr ) = split ( /\/ /, $val );
742 #check for existing routes in ccdroute
743 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
744 foreach my $key ( keys %ccdconfhash ) {
745 if (& General
:: iporsubtocidr
( $val ) eq $ccdconfhash { $key }[ 1 ]){
748 my ( $ip2 , $cidr2 ) = split ( /\/ /, $ccdconfhash { $key }[ 1 ]);
750 if (& General
:: IpInSubnet
( $ip , $ip2 ,& General
:: cidrtosub
( $cidr2 ))){
764 my $ipdotmask = $_ [ 0 ];
765 if (& General
:: validip
( $ipdotmask )) { return 0 ; }
766 if (!( $ipdotmask =~ /^(.*?)\/ (.* ?
)$/)) { }
768 if (( $mask =~ /\./ )) { return 0 ; }
772 # -------------------------------------------------------------------
774 sub write_routepushfile
776 open ( FILE
, "> $routes_push_file " );
778 if ( $vpnsettings { 'ROUTES_PUSH' } ne '' ) {
779 print FILE
$vpnsettings { 'ROUTES_PUSH' };
784 sub read_routepushfile
786 if (- e
" $routes_push_file " ) {
787 open ( FILE
, " $routes_push_file " );
788 delete $vpnsettings { 'ROUTES_PUSH' };
789 while (< FILE
>) { $vpnsettings { 'ROUTES_PUSH' } .= $_ };
791 $cgiparams { 'ROUTES_PUSH' } = $vpnsettings { 'ROUTES_PUSH' };
797 #hier die refresh page
798 if ( - e
"${General::swroot}/ovpn/gencanow" ) {
800 $refresh = "<meta http-equiv='refresh' content='15;' />" ;
801 & Header
:: showhttpheaders
();
802 & Header
:: openpage
( $Lang :: tr
{ 'OVPN' }, 1 , $refresh );
803 & Header
:: openbigbox
( '100%' , 'center' );
804 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
805 print "<tr> \n <td align='center'><img src='/images/clock.gif' alt='' /></td> \n " ;
806 print "<td colspan='2'><font color='red'>Please be patient this realy can take some time on older hardware...</font></td></tr> \n " ;
808 & Header
:: closebigbox
();
809 & Header
:: closepage
();
812 ##hier die refresh page
816 ### OpenVPN Server Control
818 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'start ovpn server' } ||
819 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'stop ovpn server' } ||
820 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart ovpn server' }) {
821 #start openvpn server
822 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'start ovpn server' }){
824 system ( '/usr/local/bin/openvpnctrl' , '-s' );
827 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'stop ovpn server' }){
828 system ( '/usr/local/bin/openvpnctrl' , '-k' );
831 # #restart openvpn server
832 # if ($cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}){
833 #workarund, till SIGHUP also works when running as nobody
834 # system('/usr/local/bin/openvpnctrl', '-r');
840 ### Save Advanced options
843 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save-adv-options' }) {
844 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
845 #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too,
846 #DAN this value has to leave.
847 #new settings for daemon
848 $vpnsettings { 'LOG_VERB' } = $cgiparams { 'LOG_VERB' };
849 $vpnsettings { 'KEEPALIVE_1' } = $cgiparams { 'KEEPALIVE_1' };
850 $vpnsettings { 'KEEPALIVE_2' } = $cgiparams { 'KEEPALIVE_2' };
851 $vpnsettings { 'MAX_CLIENTS' } = $cgiparams { 'MAX_CLIENTS' };
852 $vpnsettings { 'REDIRECT_GW_DEF1' } = $cgiparams { 'REDIRECT_GW_DEF1' };
853 $vpnsettings { 'CLIENT2CLIENT' } = $cgiparams { 'CLIENT2CLIENT' };
854 $vpnsettings { 'DHCP_DOMAIN' } = $cgiparams { 'DHCP_DOMAIN' };
855 $vpnsettings { 'DHCP_DNS' } = $cgiparams { 'DHCP_DNS' };
856 $vpnsettings { 'DHCP_WINS' } = $cgiparams { 'DHCP_WINS' };
857 $vpnsettings { 'ROUTES_PUSH' } = $cgiparams { 'ROUTES_PUSH' };
858 $vpnsettings { 'PMTU_DISCOVERY' } = $cgiparams { 'PMTU_DISCOVERY' };
861 if ( $cgiparams { 'FRAGMENT' } eq '' ) {
862 delete $vpnsettings { 'FRAGMENT' };
864 if ( $cgiparams { 'FRAGMENT' } !~ /^[0-9]+$/ ) {
865 $errormessage = "Incorrect value, please insert only numbers." ;
868 $vpnsettings { 'FRAGMENT' } = $cgiparams { 'FRAGMENT' };
871 if ( $cgiparams { 'MSSFIX' } ne 'on' ) {
872 delete $vpnsettings { 'MSSFIX' };
874 $vpnsettings { 'MSSFIX' } = $cgiparams { 'MSSFIX' };
877 if (( $cgiparams { 'PMTU_DISCOVERY' } eq 'yes' ) ||
878 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
879 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'no' )) {
881 if (( $cgiparams { 'MSSFIX' } eq 'on' ) || ( $cgiparams { 'FRAGMENT' } ne '' )) {
882 $errormessage = $Lang :: tr
{ 'ovpn mtu-disc with mssfix or fragment' };
887 if ( $cgiparams { 'DHCP_DOMAIN' } ne '' ){
888 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_DOMAIN' }) || & General
:: validip
( $cgiparams { 'DHCP_DOMAIN' })) {
889 $errormessage = $Lang :: tr
{ 'invalid input for dhcp domain' };
893 if ( $cgiparams { 'DHCP_DNS' } ne '' ){
894 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_DNS' }) || & General
:: validip
( $cgiparams { 'DHCP_DNS' })) {
895 $errormessage = $Lang :: tr
{ 'invalid input for dhcp dns' };
899 if ( $cgiparams { 'DHCP_WINS' } ne '' ){
900 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_WINS' }) || & General
:: validip
( $cgiparams { 'DHCP_WINS' })) {
901 $errormessage = $Lang :: tr
{ 'invalid input for dhcp wins' };
905 if ( $cgiparams { 'ROUTES_PUSH' } ne '' ){
906 @temp = split ( /\n/ , $cgiparams { 'ROUTES_PUSH' });
907 undef $vpnsettings { 'ROUTES_PUSH' };
909 foreach my $tmpip ( @temp )
911 s/^\s+//g ; s/\s+$//g ;
916 unless (& General
:: validipandmask
( $tmpip )) {
917 $errormessage = " $tmpip " . $Lang :: tr
{ 'ovpn errmsg invalid ip or mask' };
920 my ( $ip , $cidr ) = split ( "\/" ,& General
:: ipcidr2msk
( $tmpip ));
922 if ( $ip eq $netsettings { 'GREEN_NETADDRESS' } && $cidr eq $netsettings { 'GREEN_NETMASK' }) {
923 $errormessage = $Lang :: tr
{ 'ovpn errmsg green already pushed' };
928 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
929 foreach my $key ( keys %ccdroutehash ) {
930 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}) {
931 if ( $ip . "/" . $cidr eq $ccdroutehash { $key }[ $i ] ){
932 $errormessage = "Route $ip \/ $cidr " . $Lang :: tr
{ 'ccd err inuse' }. " $ccdroutehash { $key }[0]" ;
935 my ( $ip2 , $cidr2 ) = split ( /\/ /, $ccdroutehash { $key }[ $i ]);
936 if (& General
:: IpInSubnet
( $ip , $ip2 , $cidr2 )){
937 $errormessage = "Route $ip \/ $cidr " . $Lang :: tr
{ 'ccd err inuse' }. " $ccdroutehash { $key }[0]" ;
945 $vpnsettings { 'ROUTES_PUSH' } .= $tmpip . " \n " ;
948 & write_routepushfile
;
949 undef $vpnsettings { 'ROUTES_PUSH' };
952 undef $vpnsettings { 'ROUTES_PUSH' };
953 & write_routepushfile
;
955 if (( length ( $cgiparams { 'MAX_CLIENTS' }) == 0 ) || (( $cgiparams { 'MAX_CLIENTS' }) < 1 ) || (( $cgiparams { 'MAX_CLIENTS' }) > 255 )) {
956 $errormessage = $Lang :: tr
{ 'invalid input for max clients' };
959 if ( $cgiparams { 'KEEPALIVE_1' } ne '' ) {
960 if ( $cgiparams { 'KEEPALIVE_1' } !~ /^[0-9]+$/ ) {
961 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 1' };
965 if ( $cgiparams { 'KEEPALIVE_2' } ne '' ){
966 if ( $cgiparams { 'KEEPALIVE_2' } !~ /^[0-9]+$/ ) {
967 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 2' };
971 if ( $cgiparams { 'KEEPALIVE_2' } < ( $cgiparams { 'KEEPALIVE_1' } * 2 )){
972 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 1:2' };
976 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
977 & writeserverconf
(); #hier ok
984 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq 'net' && $cgiparams { 'SIDE' } eq 'server' )
987 my @remsubnet = split ( /\/ /, $cgiparams { 'REMOTE_SUBNET' });
988 my @ovsubnettemp = split ( /\./ , $cgiparams { 'OVPN_SUBNET' });
989 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
992 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
993 unless (- d
"${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" , 0770 or die "Unable to create dir $!" ;}
995 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: $!" ;
998 print SERVERCONF
"# IPFire n2n Open VPN Server Config by ummeegge und m.a.d \n " ;
999 print SERVERCONF
" \n " ;
1000 print SERVERCONF
"# User Security \n " ;
1001 print SERVERCONF
"user nobody \n " ;
1002 print SERVERCONF
"group nobody \n " ;
1003 print SERVERCONF
"persist-tun \n " ;
1004 print SERVERCONF
"persist-key \n " ;
1005 print SERVERCONF
"script-security 2 \n " ;
1006 print SERVERCONF
"# IP/DNS for remote Server Gateway \n " ;
1007 print SERVERCONF
"remote $cgiparams {'REMOTE'} \n " ;
1008 print SERVERCONF
"float \n " ;
1009 print SERVERCONF
"# IP adresses of the VPN Subnet \n " ;
1010 print SERVERCONF
"ifconfig $ovsubnet .1 $ovsubnet .2 \n " ;
1011 print SERVERCONF
"# Client Gateway Network \n " ;
1012 print SERVERCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
1013 print SERVERCONF
"# tun Device \n " ;
1014 print SERVERCONF
"dev tun \n " ;
1015 print SERVERCONF
"# Port and Protokol \n " ;
1016 print SERVERCONF
"port $cgiparams {'DEST_PORT'} \n " ;
1018 if ( $cgiparams { 'PROTOCOL' } eq 'tcp' ) {
1019 print SERVERCONF
"proto tcp-server \n " ;
1020 print SERVERCONF
"# Packet size \n " ;
1021 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1400' } else { $tunmtu = $cgiparams { 'MTU' }};
1022 print SERVERCONF
"tun-mtu $tunmtu \n " ;
1025 if ( $cgiparams { 'PROTOCOL' } eq 'udp' ) {
1026 print SERVERCONF
"proto udp \n " ;
1027 print SERVERCONF
"# Paketsize \n " ;
1028 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1500' } else { $tunmtu = $cgiparams { 'MTU' }};
1029 print SERVERCONF
"tun-mtu $tunmtu \n " ;
1030 if ( $cgiparams { 'FRAGMENT' } ne '' ) { print SERVERCONF
"fragment $cgiparams {'FRAGMENT'} \n " ;}
1031 if ( $cgiparams { 'MSSFIX' } eq 'on' ) { print SERVERCONF
"mssfix \n " ; };
1034 # Check if a valid operating mode has been choosen and use it.
1035 if (( $cgiparams { 'PMTU_DISCOVERY' } eq 'yes' ) ||
1036 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
1037 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'no' )) {
1038 if (( $cgiparams { 'MSSFIX' } ne 'on' ) || ( $cgiparams { 'FRAGMENT' } eq '' )) {
1039 if ( $cgiparams { 'MTU' } eq '1500' ) {
1040 print SERVERCONF
"mtu-disc $cgiparams {'PMTU_DISCOVERY'} \n " ;
1044 print SERVERCONF
"# Auth. Server \n " ;
1045 print SERVERCONF
"tls-server \n " ;
1046 print SERVERCONF
"ca ${General::swroot}/ovpn/ca/cacert.pem \n " ;
1047 print SERVERCONF
"cert ${General::swroot}/ovpn/certs/servercert.pem \n " ;
1048 print SERVERCONF
"key ${General::swroot}/ovpn/certs/serverkey.pem \n " ;
1049 print SERVERCONF
"dh ${General::swroot}/ovpn/ca/dh1024.pem \n " ;
1050 print SERVERCONF
"# Cipher \n " ;
1051 print SERVERCONF
"cipher AES-256-CBC \n " ;
1052 if ( $cgiparams { 'COMPLZO' } eq 'on' ) {
1053 print SERVERCONF
"# Enable Compression \n " ;
1054 print SERVERCONF
"comp-lzo \r\n " ;
1056 print SERVERCONF
"# Debug Level \n " ;
1057 print SERVERCONF
"verb 3 \n " ;
1058 print SERVERCONF
"# Tunnel check \n " ;
1059 print SERVERCONF
"keepalive 10 60 \n " ;
1060 print SERVERCONF
"# Start as daemon \n " ;
1061 print SERVERCONF
"daemon $cgiparams {'NAME'}n2n \n " ;
1062 print SERVERCONF
"writepid /var/run/ $cgiparams {'NAME'}n2n.pid \n " ;
1063 print SERVERCONF
"# Activate Management Interface and Port \n " ;
1064 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) { print SERVERCONF
"management localhost $cgiparams {'DEST_PORT'} \n " }
1065 else { print SERVERCONF
"management localhost $cgiparams {'OVPN_MGMT'} \n " };
1074 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq 'net' && $cgiparams { 'SIDE' } eq 'client' )
1076 my @ovsubnettemp = split ( /\./ , $cgiparams { 'OVPN_SUBNET' });
1077 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
1078 my @remsubnet = split ( /\/ /, $cgiparams { 'REMOTE_SUBNET' });
1081 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
1082 unless (- d
"${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" , 0770 or die "Unable to create dir $!" ;}
1084 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: $!" ;
1086 flock CLIENTCONF
, 2 ;
1087 print CLIENTCONF
"# IPFire rewritten n2n Open VPN Client Config by ummeegge und m.a.d \n " ;
1088 print CLIENTCONF
"# \n " ;
1089 print CLIENTCONF
"# User Security \n " ;
1090 print CLIENTCONF
"user nobody \n " ;
1091 print CLIENTCONF
"group nobody \n " ;
1092 print CLIENTCONF
"persist-tun \n " ;
1093 print CLIENTCONF
"persist-key \n " ;
1094 print CLIENTCONF
"script-security 2 \n " ;
1095 print CLIENTCONF
"# IP/DNS for remote Server Gateway \n " ;
1096 print CLIENTCONF
"remote $cgiparams {'REMOTE'} \n " ;
1097 print CLIENTCONF
"float \n " ;
1098 print CLIENTCONF
"# IP adresses of the VPN Subnet \n " ;
1099 print CLIENTCONF
"ifconfig $ovsubnet .2 $ovsubnet .1 \n " ;
1100 print CLIENTCONF
"# Server Gateway Network \n " ;
1101 print CLIENTCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
1102 print CLIENTCONF
"# tun Device \n " ;
1103 print CLIENTCONF
"dev tun \n " ;
1104 print CLIENTCONF
"# Port and Protokol \n " ;
1105 print CLIENTCONF
"port $cgiparams {'DEST_PORT'} \n " ;
1107 if ( $cgiparams { 'PROTOCOL' } eq 'tcp' ) {
1108 print CLIENTCONF
"proto tcp-client \n " ;
1109 print CLIENTCONF
"# Packet size \n " ;
1110 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1400' } else { $tunmtu = $cgiparams { 'MTU' }};
1111 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
1114 if ( $cgiparams { 'PROTOCOL' } eq 'udp' ) {
1115 print CLIENTCONF
"proto udp \n " ;
1116 print CLIENTCONF
"# Paketsize \n " ;
1117 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1500' } else { $tunmtu = $cgiparams { 'MTU' }};
1118 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
1119 if ( $cgiparams { 'FRAGMENT' } ne '' ) { print CLIENTCONF
"fragment $cgiparams {'FRAGMENT'} \n " ;}
1120 if ( $cgiparams { 'MSSFIX' } eq 'on' ) { print CLIENTCONF
"mssfix \n " ; };
1123 # Check if a valid operating mode has been choosen and use it.
1124 if (( $cgiparams { 'PMTU_DISCOVERY' } eq 'yes' ) ||
1125 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
1126 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'no' )) {
1127 if (( $cgiparams { 'MSSFIX' } ne 'on' ) || ( $cgiparams { 'FRAGMENT' } eq '' )) {
1128 if ( $cgiparams { 'MTU' } eq '1500' ) {
1129 print CLIENTCONF
"mtu-disc $cgiparams {'PMTU_DISCOVERY'} \n " ;
1134 print CLIENTCONF
"ns-cert-type server \n " ;
1135 print CLIENTCONF
"# Auth. Client \n " ;
1136 print CLIENTCONF
"tls-client \n " ;
1137 print CLIENTCONF
"# Cipher \n " ;
1138 print CLIENTCONF
"cipher AES-256-CBC \n " ;
1139 print CLIENTCONF
"pkcs12 ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12 \r\n " ;
1140 if ( $cgiparams { 'COMPLZO' } eq 'on' ) {
1141 print CLIENTCONF
"# Enable Compression \n " ;
1142 print CLIENTCONF
"comp-lzo \r\n " ;
1144 print CLIENTCONF
"# Debug Level \n " ;
1145 print CLIENTCONF
"verb 3 \n " ;
1146 print CLIENTCONF
"# Tunnel check \n " ;
1147 print CLIENTCONF
"keepalive 10 60 \n " ;
1148 print CLIENTCONF
"# Start as daemon \n " ;
1149 print CLIENTCONF
"daemon $cgiparams {'NAME'}n2n \n " ;
1150 print CLIENTCONF
"writepid /var/run/ $cgiparams {'NAME'}n2n.pid \n " ;
1151 print CLIENTCONF
"# Activate Management Interface and Port \n " ;
1152 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) { print CLIENTCONF
"management localhost $cgiparams {'DEST_PORT'} \n " }
1153 else { print CLIENTCONF
"management localhost $cgiparams {'OVPN_MGMT'} \n " };
1159 ### Save main settings
1163 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
1164 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1165 #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too,
1166 #DAN this value has to leave.
1167 if ( $cgiparams { 'ENABLED' } eq 'on' ){
1168 unless (& General
:: validfqdn
( $cgiparams { 'VPN_IP' }) || & General
:: validip
( $cgiparams { 'VPN_IP' })) {
1169 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
1170 goto SETTINGS_ERROR
;
1173 if ( $cgiparams { 'ENABLED' } eq 'on' ){
1174 & disallowreserved
( $cgiparams { 'DDEST_PORT' }, 0 , $cgiparams { 'DPROTOCOL' }, "dest" );
1176 if ( $errormessage ) { goto SETTINGS_ERROR
; }
1179 if ( $cgiparams { 'ENABLED' } eq 'on' ){
1180 & checkportfw
( 0 , $cgiparams { 'DDEST_PORT' }, $cgiparams { 'DPROTOCOL' }, '0.0.0.0' );
1183 if ( $errormessage ) { goto SETTINGS_ERROR
; }
1185 if (! & General
:: validipandmask
( $cgiparams { 'DOVPN_SUBNET' })) {
1186 $errormessage = $Lang :: tr
{ 'ovpn subnet is invalid' };
1187 goto SETTINGS_ERROR
;
1189 my @tmpovpnsubnet = split ( "\/" , $cgiparams { 'DOVPN_SUBNET' });
1191 if (& General
:: IpInSubnet
( $netsettings { 'RED_ADDRESS' },
1192 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1193 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire RED Network $netsettings {'RED_ADDRESS'}" ;
1194 goto SETTINGS_ERROR
;
1197 if (& General
:: IpInSubnet
( $netsettings { 'GREEN_ADDRESS' },
1198 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1199 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Green Network $netsettings {'GREEN_ADDRESS'}" ;
1200 goto SETTINGS_ERROR
;
1203 if (& General
:: IpInSubnet
( $netsettings { 'BLUE_ADDRESS' },
1204 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1205 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Blue Network $netsettings {'BLUE_ADDRESS'}" ;
1206 goto SETTINGS_ERROR
;
1209 if (& General
:: IpInSubnet
( $netsettings { 'ORANGE_ADDRESS' },
1210 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1211 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Orange Network $netsettings {'ORANGE_ADDRESS'}" ;
1212 goto SETTINGS_ERROR
;
1214 open ( ALIASES
, "${General::swroot}/ethernet/aliases" ) or die 'Unable to open aliases file.' ;
1218 my @tempalias = split ( /\,/ , $_ );
1219 if ( $tempalias [ 1 ] eq 'on' ) {
1220 if (& General
:: IpInSubnet
( $tempalias [ 0 ] ,
1221 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1222 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire alias entry $tempalias [0]" ;
1227 if ( $errormessage ne '' ){
1228 goto SETTINGS_ERROR
;
1230 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
1231 $errormessage = $Lang :: tr
{ 'invalid input' };
1232 goto SETTINGS_ERROR
;
1234 if (( length ( $cgiparams { 'DMTU' })== 0 ) || (( $cgiparams { 'DMTU' }) < 1000 )) {
1235 $errormessage = $Lang :: tr
{ 'invalid mtu input' };
1236 goto SETTINGS_ERROR
;
1239 unless (& General
:: validport
( $cgiparams { 'DDEST_PORT' })) {
1240 $errormessage = $Lang :: tr
{ 'invalid port' };
1241 goto SETTINGS_ERROR
;
1243 $vpnsettings { 'ENABLED_BLUE' } = $cgiparams { 'ENABLED_BLUE' };
1244 $vpnsettings { 'ENABLED_ORANGE' } = $cgiparams { 'ENABLED_ORANGE' };
1245 $vpnsettings { 'ENABLED' } = $cgiparams { 'ENABLED' };
1246 $vpnsettings { 'VPN_IP' } = $cgiparams { 'VPN_IP' };
1247 #new settings for daemon
1248 $vpnsettings { 'DOVPN_SUBNET' } = $cgiparams { 'DOVPN_SUBNET' };
1249 $vpnsettings { 'DDEVICE' } = $cgiparams { 'DDEVICE' };
1250 $vpnsettings { 'DPROTOCOL' } = $cgiparams { 'DPROTOCOL' };
1251 $vpnsettings { 'DDEST_PORT' } = $cgiparams { 'DDEST_PORT' };
1252 $vpnsettings { 'DMTU' } = $cgiparams { 'DMTU' };
1253 $vpnsettings { 'DCOMPLZO' } = $cgiparams { 'DCOMPLZO' };
1254 $vpnsettings { 'DCIPHER' } = $cgiparams { 'DCIPHER' };
1257 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" );}
1258 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" );}
1259 if ( $vpnsettings { 'ENABLED' } eq 'on' ) { system ( "touch ${General::swroot}/ovpn/enable 2>/dev/null" );} else { system ( "unlink ${General::swroot}/ovpn/enable 2>/dev/null" );}
1260 #new settings for daemon
1261 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1262 & writeserverconf
(); #hier ok
1265 ### Reset all step 2
1267 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'reset' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
1269 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1271 foreach my $key ( keys %confighash ) {
1272 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
1273 delete $confighash { $cgiparams { ' $key ' }};
1276 while ( $file = glob ( "${General::swroot}/ovpn/ca/*" )) {
1279 while ( $file = glob ( "${General::swroot}/ovpn/certs/*" )) {
1282 while ( $file = glob ( "${General::swroot}/ovpn/crls/*" )) {
1285 & cleanssldatabase
();
1286 if ( open ( FILE
, ">${General::swroot}/ovpn/caconfig" )) {
1290 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1291 #&writeserverconf();
1293 ### Reset all step 1
1295 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'reset' }) {
1296 & Header
:: showhttpheaders
();
1297 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1298 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1299 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'are you sure' });
1301 <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' />
1302 <tr><td align='center'>
1303 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1304 $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}
1305 <tr><td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'reset'}' />
1306 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td></tr>
1310 & Header
:: closebox
();
1311 & Header
:: closebigbox
();
1312 & Header
:: closepage
();
1316 ### Upload CA Certificate
1318 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
1319 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1321 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
1322 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
1323 goto UPLOADCA_ERROR
;
1326 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
1327 $errormessage = $Lang :: tr
{ 'name too long' };
1331 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
1332 $errormessage = $Lang :: tr
{ 'name is invalid' };
1333 goto UPLOAD_CA_ERROR
;
1336 # Check if there is no other entry with this name
1337 foreach my $key ( keys %cahash ) {
1338 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
1339 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
1340 goto UPLOADCA_ERROR
;
1344 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1345 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1346 goto UPLOADCA_ERROR
;
1348 # Move uploaded ca to a temporary file
1349 ( my $fh , my $filename ) = tempfile
( );
1350 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1352 goto UPLOADCA_ERROR
;
1354 my $temp = `/usr/bin/openssl x509 -text -in $filename ` ;
1355 if ( $temp !~ /CA:TRUE/i ) {
1356 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
1358 goto UPLOADCA_ERROR
;
1360 move
( $filename , "${General::swroot}/ovpn/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1362 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1364 goto UPLOADCA_ERROR
;
1368 my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/ $cgiparams {'CA_NAME'}cert.pem` ;
1369 $casubject =~ /Subject: (.*)[\n]/ ;
1371 $casubject =~ s
+/ Email
+, E
+;
1372 $casubject =~ s/ ST=/ S=/ ;
1373 $casubject = & Header
:: cleanhtml
( $casubject );
1375 my $key = & General
:: findhasharraykey
( \
%cahash );
1376 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
1377 $cahash { $key }[ 1 ] = $casubject ;
1378 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1379 # system('/usr/local/bin/ipsecctrl', 'R');
1384 ### Display ca certificate
1386 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
1387 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1389 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1390 & Header
:: showhttpheaders
();
1391 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1392 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
1393 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'ca certificate'}:" );
1394 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
1395 $output = & Header
:: cleanhtml
( $output , "y" );
1396 print "<pre> $output </pre> \n " ;
1397 & Header
:: closebox
();
1398 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1399 & Header
:: closebigbox
();
1400 & Header
:: closepage
();
1403 $errormessage = $Lang :: tr
{ 'invalid key' };
1407 ### Download ca certificate
1409 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
1410 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1412 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1413 print "Content-Type: application/octet-stream \r\n " ;
1414 print "Content-Disposition: filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
1415 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
1418 $errormessage = $Lang :: tr
{ 'invalid key' };
1422 ### Remove ca certificate (step 2)
1424 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
1425 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1426 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1428 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1429 foreach my $key ( keys %confighash ) {
1430 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` ;
1431 if ( $test =~ /: OK/ ) {
1433 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1434 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
1435 # system('/usr/local/bin/ipsecctrl', 'D', $key);
1437 unlink ( "${General::swroot}/ovpn//certs/ $confighash { $key }[1]cert.pem" );
1438 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $key }[1].p12" );
1439 delete $confighash { $key };
1440 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1441 # &writeipsecfiles();
1444 unlink ( "${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
1445 delete $cahash { $cgiparams { 'KEY' }};
1446 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1447 # system('/usr/local/bin/ipsecctrl', 'R');
1449 $errormessage = $Lang :: tr
{ 'invalid key' };
1452 ### Remove ca certificate (step 1)
1454 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
1455 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1456 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1458 my $assignedcerts = 0 ;
1459 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1460 foreach my $key ( keys %confighash ) {
1461 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` ;
1462 if ( $test =~ /: OK/ ) {
1466 if ( $assignedcerts ) {
1467 & Header
:: showhttpheaders
();
1468 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1469 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
1470 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'are you sure' });
1472 <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' />
1473 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
1474 <tr><td align='center'>
1475 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>: $assignedcerts
1476 $Lang ::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}
1477 <tr><td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
1478 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td></tr>
1482 & Header
:: closebox
();
1483 & Header
:: closebigbox
();
1484 & Header
:: closepage
();
1487 unlink ( "${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
1488 delete $cahash { $cgiparams { 'KEY' }};
1489 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1490 # system('/usr/local/bin/ipsecctrl', 'R');
1493 $errormessage = $Lang :: tr
{ 'invalid key' };
1497 ### Display root certificate
1499 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
1500 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
1502 & Header
:: showhttpheaders
();
1503 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1504 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1505 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
1506 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'root certificate'}:" );
1507 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem` ;
1509 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'host certificate'}:" );
1510 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem` ;
1512 $output = & Header
:: cleanhtml
( $output , "y" );
1513 print "<pre> $output </pre> \n " ;
1514 & Header
:: closebox
();
1515 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1516 & Header
:: closebigbox
();
1517 & Header
:: closepage
();
1521 ### Download root certificate
1523 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
1524 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
1525 print "Content-Type: application/octet-stream \r\n " ;
1526 print "Content-Disposition: filename=cacert.pem \r\n\r\n " ;
1527 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/cacert.pem` ;
1532 ### Download host certificate
1534 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
1535 if ( - f
"${General::swroot}/ovpn/certs/servercert.pem" ) {
1536 print "Content-Type: application/octet-stream \r\n " ;
1537 print "Content-Disposition: filename=servercert.pem \r\n\r\n " ;
1538 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/certs/servercert.pem` ;
1542 ### Form for generating a root certificate
1544 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
1545 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
1547 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1548 if (- f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
1549 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
1550 $cgiparams { 'ACTION' } = '' ;
1551 goto ROOTCERT_ERROR
;
1554 if (( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) && - e
"${General::swroot}/red/active" ) {
1555 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
1556 my $ipaddr = < IPADDR
>;
1559 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
1560 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
1561 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
1564 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
1566 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1567 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1568 goto ROOTCERT_ERROR
;
1571 # Move uploaded certificate request to a temporary file
1572 ( my $fh , my $filename ) = tempfile
( );
1573 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1575 goto ROOTCERT_ERROR
;
1578 # Create a temporary dirctory
1579 my $tempdir = tempdir
( CLEANUP
=> 1 );
1581 # Extract the CA certificate from the file
1582 my $pid = open ( OPENSSL
, "|-" );
1583 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1584 if ( $pid ) { # parent
1585 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1586 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1590 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1592 goto ROOTCERT_ERROR
;
1595 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-cacerts' , '-nokeys' ,
1597 '-out' , " $tempdir /cacert.pem" )) {
1598 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1600 goto ROOTCERT_ERROR
;
1604 # Extract the Host certificate from the file
1605 $pid = open ( OPENSSL
, "|-" );
1606 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1607 if ( $pid ) { # parent
1608 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1609 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1613 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1615 goto ROOTCERT_ERROR
;
1618 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-clcerts' , '-nokeys' ,
1620 '-out' , " $tempdir /hostcert.pem" )) {
1621 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1623 goto ROOTCERT_ERROR
;
1627 # Extract the Host key from the file
1628 $pid = open ( OPENSSL
, "|-" );
1629 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1630 if ( $pid ) { # parent
1631 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1632 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1636 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1638 goto ROOTCERT_ERROR
;
1641 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-nocerts' ,
1644 '-out' , " $tempdir /serverkey.pem" )) {
1645 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1647 goto ROOTCERT_ERROR
;
1651 move
( " $tempdir /cacert.pem" , "${General::swroot}/ovpn/ca/cacert.pem" );
1653 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1655 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1656 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1657 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1658 goto ROOTCERT_ERROR
;
1661 move
( " $tempdir /hostcert.pem" , "${General::swroot}/ovpn/certs/servercert.pem" );
1663 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1665 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1666 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1667 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1668 goto ROOTCERT_ERROR
;
1671 move
( " $tempdir /serverkey.pem" , "${General::swroot}/ovpn/certs/serverkey.pem" );
1673 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1675 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1676 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1677 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1678 goto ROOTCERT_ERROR
;
1681 goto ROOTCERT_SUCCESS
;
1683 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
1685 # Validate input since the form was submitted
1686 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
1687 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
1688 goto ROOTCERT_ERROR
;
1690 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
1691 $errormessage = $Lang :: tr
{ 'organization too long' };
1692 goto ROOTCERT_ERROR
;
1694 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1695 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1696 goto ROOTCERT_ERROR
;
1698 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
1699 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
1700 goto ROOTCERT_ERROR
;
1702 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
1703 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
1704 goto ROOTCERT_ERROR
;
1706 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
1707 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1708 goto ROOTCERT_ERROR
;
1710 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
1711 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1712 goto ROOTCERT_ERROR
;
1714 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1715 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1716 goto ROOTCERT_ERROR
;
1718 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1719 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1720 goto ROOTCERT_ERROR
;
1722 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1723 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1724 goto ROOTCERT_ERROR
;
1726 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1727 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1728 goto ROOTCERT_ERROR
;
1731 # Copy the cgisettings to vpnsettings and save the configfile
1732 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
1733 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
1734 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
1735 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
1736 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
1737 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
1738 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
1739 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1741 # Replace empty strings with a .
1742 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
1743 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
1744 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
1747 #system ('/bin/touch', "${General::swroot}/ovpn/gencanow");
1749 # Create the CA certificate
1750 my $pid = open ( OPENSSL
, "|-" );
1751 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1752 if ( $pid ) { # parent
1753 print OPENSSL
" $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1754 print OPENSSL
" $state \n " ;
1755 print OPENSSL
" $city \n " ;
1756 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1757 print OPENSSL
" $ou \n " ;
1758 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
1759 print OPENSSL
" $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1762 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1763 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1764 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1765 goto ROOTCERT_ERROR
;
1768 unless ( exec ( '/usr/bin/openssl' , 'req' , '-x509' , '-nodes' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
1769 '-days' , '999999' , '-newkey' , 'rsa:2048' ,
1770 '-keyout' , "${General::swroot}/ovpn/ca/cakey.pem" ,
1771 '-out' , "${General::swroot}/ovpn/ca/cacert.pem" ,
1772 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
1773 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1774 goto ROOTCERT_ERROR
;
1778 # Create the Host certificate request
1779 $pid = open ( OPENSSL
, "|-" );
1780 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1781 if ( $pid ) { # parent
1782 print OPENSSL
" $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1783 print OPENSSL
" $state \n " ;
1784 print OPENSSL
" $city \n " ;
1785 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1786 print OPENSSL
" $ou \n " ;
1787 print OPENSSL
" $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
1788 print OPENSSL
" $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1789 print OPENSSL
". \n " ;
1790 print OPENSSL
". \n " ;
1793 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1794 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1795 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1796 goto ROOTCERT_ERROR
;
1799 unless ( exec ( '/usr/bin/openssl' , 'req' , '-nodes' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
1800 '-newkey' , 'rsa:1024' ,
1801 '-keyout' , "${General::swroot}/ovpn/certs/serverkey.pem" ,
1802 '-out' , "${General::swroot}/ovpn/certs/serverreq.pem" ,
1803 '-extensions' , 'server' ,
1804 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
1805 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1806 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1807 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1808 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1809 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1810 goto ROOTCERT_ERROR
;
1814 # Sign the host certificate request
1815 system ( '/usr/bin/openssl' , 'ca' , '-days' , '999999' ,
1816 '-batch' , '-notext' ,
1817 '-in' , "${General::swroot}/ovpn/certs/serverreq.pem" ,
1818 '-out' , "${General::swroot}/ovpn/certs/servercert.pem" ,
1819 '-extensions' , 'server' ,
1820 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
1822 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1823 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1824 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1825 unlink ( "${General::swroot}/ovpn/serverkey.pem" );
1826 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1827 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1828 & newcleanssldatabase
();
1829 goto ROOTCERT_ERROR
;
1831 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1832 & deletebackupcert
();
1835 # Create an empty CRL
1836 system ( '/usr/bin/openssl' , 'ca' , '-gencrl' ,
1837 '-out' , "${General::swroot}/ovpn/crls/cacrl.pem" ,
1838 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
1840 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1841 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1842 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1843 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1844 unlink ( "${General::swroot}/ovpn/crls/cacrl.pem" );
1845 & cleanssldatabase
();
1846 goto ROOTCERT_ERROR
;
1848 # &cleanssldatabase();
1850 # Create Diffie Hellmann Parameter
1851 system ( '/usr/bin/openssl' , 'dhparam' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
1852 '-out' , "${General::swroot}/ovpn/ca/dh1024.pem" ,
1855 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1856 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1857 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1858 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1859 unlink ( "${General::swroot}/ovpn/crls/cacrl.pem" );
1860 unlink ( "${General::swroot}/ovpn/ca/dh1024.pem" );
1861 & cleanssldatabase
();
1862 goto ROOTCERT_ERROR
;
1864 # &cleanssldatabase();
1866 goto ROOTCERT_SUCCESS
;
1869 if ( $cgiparams { 'ACTION' } ne '' ) {
1870 & Header
:: showhttpheaders
();
1871 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1872 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1873 if ( $errormessage ) {
1874 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
1875 print "<class name='base'> $errormessage " ;
1876 print " </class>" ;
1877 & Header
:: closebox
();
1879 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'generate root/host certificates'}:" );
1881 <form method='post' enctype='multipart/form-data'>
1882 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1883 <tr><td width='30%' class='base'> $Lang ::tr{'organization name'}:</td>
1884 <td width='35%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td>
1885 <td width='35%' colspan='2'> </td></tr>
1886 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}:</td>
1887 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td>
1888 <td colspan='2'> </td></tr>
1889 <tr><td class='base'> $Lang ::tr{'your e-mail'}: <img src='/blob.gif' alt'*' /></td>
1890 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td>
1891 <td colspan='2'> </td></tr>
1892 <tr><td class='base'> $Lang ::tr{'your department'}: <img src='/blob.gif' alt'*' /></td>
1893 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td>
1894 <td colspan='2'> </td></tr>
1895 <tr><td class='base'> $Lang ::tr{'city'}: <img src='/blob.gif' alt'*' /></td>
1896 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td>
1897 <td colspan='2'> </td></tr>
1898 <tr><td class='base'> $Lang ::tr{'state or province'}: <img src='/blob.gif' alt'*' /></td>
1899 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td>
1900 <td colspan='2'> </td></tr>
1901 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1902 <td class='base'><select name='ROOTCERT_COUNTRY'>
1906 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1907 print "<option value=' $Countries ::countries{ $country }'" ;
1908 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1909 print " selected='selected'" ;
1911 print "> $country </option>" ;
1915 <td colspan='2'> </td></tr>
1917 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /></td>
1918 <td> </td><td> </td></tr>
1919 <tr><td class='base' colspan='4' align='left'>
1920 <img src='/blob.gif' valign='top' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
1921 <tr><td class='base' colspan='4' align='left'>
1922 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1923 $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'}
1925 <tr><td colspan='4' bgcolor='#000000'><img src='/images/null.gif' width='1' height='1' border='0' /></td></tr>
1926 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}:</td>
1927 <td nowrap='nowrap'><input type='file' name='FH' size='32'></td>
1928 <td colspan='2'> </td></tr>
1929 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' ></td>
1930 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td>
1931 <td colspan='2'> </td></tr>
1933 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td>
1934 <td colspan='2'> </td></tr>
1935 <tr><td class='base' colspan='4' align='left'>
1936 <img src='/blob.gif' valign='top' al='*' > $Lang ::tr{'this field may be blank'}</td></tr>
1940 & Header
:: closebox
();
1942 & Header
:: closebigbox
();
1943 & Header
:: closepage
();
1948 system ( "chmod 600 ${General::swroot}/ovpn/certs/serverkey.pem" );
1949 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1950 # $vpnsettings{'ENABLE_BLUE'} eq 'on') {
1951 # system('/usr/local/bin/ipsecctrl', 'S');
1955 ### Enable/Disable connection
1962 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1964 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1965 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1966 # my $n2nactive = '';
1967 my $n2nactive = `/bin/ps ax|grep $confighash { $cgiparams {'KEY'}}[1]|grep -v grep|awk \' {print \ $1 } \' ` ;
1969 if ( $confighash { $cgiparams { 'KEY' }}) {
1970 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
1971 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
1972 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1974 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
1975 system ( '/usr/local/bin/openvpnctrl' , '-sn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
1979 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
1980 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1982 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
1983 if ( $n2nactive ne '' ){
1984 system ( '/usr/local/bin/openvpnctrl' , '-kn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
1988 $errormessage = $Lang :: tr
{ 'invalid key' };
1994 ### Download OpenVPN client package
1998 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'dl client arch' }) {
1999 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2000 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2002 my $clientovpn = '' ;
2004 my $tempdir = tempdir
( CLEANUP
=> 1 );
2005 my $zippath = " $tempdir /" ;
2011 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
2013 my $zipname = " $confighash { $cgiparams {'KEY'}}[1]-Client.zip" ;
2014 my $zippathname = " $zippath $zipname " ;
2015 $clientovpn = " $confighash { $cgiparams {'KEY'}}[1].conf" ;
2016 my @ovsubnettemp = split ( /\./ , $confighash { $cgiparams { 'KEY' }}[ 27 ]);
2017 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
2019 my @remsubnet = split ( /\/ /, $confighash { $cgiparams { 'KEY' }}[ 8 ]);
2020 my $n2nfragment = '' ;
2022 open ( CLIENTCONF
, "> $tempdir / $clientovpn " ) or die "Unable to open tempfile: $!" ;
2023 flock CLIENTCONF
, 2 ;
2025 my $zip = Archive
:: Zip
-> new ();
2026 print CLIENTCONF
"# IPFire n2n Open VPN Client Config by ummeegge und m.a.d \n " ;
2027 print CLIENTCONF
"# \n " ;
2028 print CLIENTCONF
"# User Security \n " ;
2029 print CLIENTCONF
"user nobody \n " ;
2030 print CLIENTCONF
"group nobody \n " ;
2031 print CLIENTCONF
"persist-tun \n " ;
2032 print CLIENTCONF
"persist-key \n " ;
2033 print CLIENTCONF
"script-security 2 \n " ;
2034 print CLIENTCONF
"# IP/DNS for remote Server Gateway \n " ;
2035 print CLIENTCONF
"remote $vpnsettings {'VPN_IP'} \n " ;
2036 print CLIENTCONF
"float \n " ;
2037 print CLIENTCONF
"# IP adresses of the VPN Subnet \n " ;
2038 print CLIENTCONF
"ifconfig $ovsubnet .2 $ovsubnet .1 \n " ;
2039 print CLIENTCONF
"# Server Gateway Network \n " ;
2040 print CLIENTCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
2041 print CLIENTCONF
"# tun Device \n " ;
2042 print CLIENTCONF
"dev $vpnsettings {'DDEVICE'} \n " ;
2043 print CLIENTCONF
"# Port and Protokoll \n " ;
2044 print CLIENTCONF
"port $confighash { $cgiparams {'KEY'}}[29] \n " ;
2046 if ( $confighash { $cgiparams { 'KEY' }}[ 28 ] eq 'tcp' ) {
2047 print CLIENTCONF
"proto tcp-client \n " ;
2048 print CLIENTCONF
"# Packet size \n " ;
2049 if ( $confighash { $cgiparams { 'KEY' }}[ 31 ] eq '' ) { $tunmtu = '1400' } else { $tunmtu = $confighash { $cgiparams { 'KEY' }}[ 31 ]};
2050 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
2053 if ( $confighash { $cgiparams { 'KEY' }}[ 28 ] eq 'udp' ) {
2054 print CLIENTCONF
"proto udp \n " ;
2055 print CLIENTCONF
"# Paketsize \n " ;
2056 if ( $confighash { $cgiparams { 'KEY' }}[ 31 ] eq '' ) { $tunmtu = '1500' } else { $tunmtu = $confighash { $cgiparams { 'KEY' }}[ 31 ]};
2057 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
2058 if ( $confighash { $cgiparams { 'KEY' }}[ 24 ] ne '' ) { print CLIENTCONF
"fragment $confighash { $cgiparams {'KEY'}}[24] \n " ;}
2059 if ( $confighash { $cgiparams { 'KEY' }}[ 23 ] eq 'on' ) { print CLIENTCONF
"mssfix \n " ;}
2061 if (( $confighash { $cgiparams { 'KEY' }}[ 38 ] eq 'yes' ) ||
2062 ( $confighash { $cgiparams { 'KEY' }}[ 38 ] eq 'maybe' ) ||
2063 ( $confighash { $cgiparams { 'KEY' }}[ 38 ] eq 'no' )) {
2064 if (( $confighash { $cgiparams { 'KEY' }}[ 23 ] ne 'on' ) || ( $confighash { $cgiparams { 'KEY' }}[ 24 ] eq '' )) {
2065 if ( $tunmtu eq '1500' ) {
2066 print CLIENTCONF
"mtu-disc $confighash { $cgiparams {'KEY'}}[38] \n " ;
2070 print CLIENTCONF
"ns-cert-type server \n " ;
2071 print CLIENTCONF
"# Auth. Client \n " ;
2072 print CLIENTCONF
"tls-client \n " ;
2073 print CLIENTCONF
"# Cipher \n " ;
2074 print CLIENTCONF
"cipher AES-256-CBC \n " ;
2075 if ( $confighash { $cgiparams { 'KEY' }}[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ) {
2076 print CLIENTCONF
"pkcs12 ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12 \r\n " ;
2077 $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 " ;
2079 if ( $confighash { $cgiparams { 'KEY' }}[ 30 ] eq 'on' ) {
2080 print CLIENTCONF
"# Enable Compression \n " ;
2081 print CLIENTCONF
"comp-lzo \r\n " ;
2083 print CLIENTCONF
"# Debug Level \n " ;
2084 print CLIENTCONF
"verb 3 \n " ;
2085 print CLIENTCONF
"# Tunnel check \n " ;
2086 print CLIENTCONF
"keepalive 10 60 \n " ;
2087 print CLIENTCONF
"# Start as daemon \n " ;
2088 print CLIENTCONF
"daemon $confighash { $cgiparams {'KEY'}}[1]n2n \n " ;
2089 print CLIENTCONF
"writepid /var/run/ $confighash { $cgiparams {'KEY'}}[1]n2n.pid \n " ;
2090 print CLIENTCONF
"# Activate Management Interface and Port \n " ;
2091 if ( $confighash { $cgiparams { 'KEY' }}[ 22 ] eq '' ) { print CLIENTCONF
"management localhost $confighash { $cgiparams {'KEY'}}[29] \n " }
2092 else { print CLIENTCONF
"management localhost $confighash { $cgiparams {'KEY'}}[22] \n " };
2093 print CLIENTCONF
"# remsub $confighash { $cgiparams {'KEY'}}[11] \n " ;
2098 $zip -> addFile ( " $tempdir / $clientovpn " , $clientovpn ) or die "Can't add file $clientovpn \n " ;
2099 my $status = $zip -> writeToFileNamed ( $zippathname );
2101 open ( DLFILE
, "< $zippathname " ) or die "Unable to open $zippathname : $!" ;
2102 @fileholder = < DLFILE
>;
2103 print "Content-Type:application/x-download \n " ;
2104 print "Content-Disposition:attachment;filename= $zipname \n\n " ;
2110 my $zipname = " $confighash { $cgiparams {'KEY'}}[1]-TO-IPFire.zip" ;
2111 my $zippathname = " $zippath $zipname " ;
2112 $clientovpn = " $confighash { $cgiparams {'KEY'}}[1]-TO-IPFire.ovpn" ;
2118 open ( CLIENTCONF
, "> $tempdir / $clientovpn " ) or die "Unable to open tempfile: $!" ;
2119 flock CLIENTCONF
, 2 ;
2121 my $zip = Archive
:: Zip
-> new ();
2123 print CLIENTCONF
"#OpenVPN Client conf \r\n " ;
2124 print CLIENTCONF
"tls-client \r\n " ;
2125 print CLIENTCONF
"client \r\n " ;
2126 print CLIENTCONF
"nobind \n " ;
2127 print CLIENTCONF
"dev $vpnsettings {'DDEVICE'} \r\n " ;
2128 print CLIENTCONF
"proto $vpnsettings {'DPROTOCOL'} \r\n " ;
2130 # Check if we are using fragment, mssfix or mtu-disc and set MTU to 1500
2131 # or use configured value.
2132 if ( $vpnsettings { FRAGMENT
} ne '' && $vpnsettings { DPROTOCOL
} ne 'tcp' )
2133 { print CLIENTCONF
" $vpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
2134 elsif ( $vpnsettings { MSSFIX
} eq 'on' )
2135 { print CLIENTCONF
" $vpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
2136 elsif (( $vpnsettings { 'PMTU_DISCOVERY' } eq 'yes' ) ||
2137 ( $vpnsettings { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
2138 ( $vpnsettings { 'PMTU_DISCOVERY' } eq 'no' ))
2139 { print CLIENTCONF
" $vpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
2141 { print CLIENTCONF
" $vpnsettings {'DDEVICE'}-mtu $vpnsettings {'DMTU'} \r\n " ; }
2143 if ( $vpnsettings { 'ENABLED' } eq 'on' ){
2144 print CLIENTCONF
"remote $vpnsettings {'VPN_IP'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2145 if ( $vpnsettings { 'ENABLED_BLUE' } eq 'on' && (& haveBlueNet
())){
2146 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Blue interface \r\n " ;
2147 print CLIENTCONF
";remote $netsettings {'BLUE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2149 if ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
2150 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Orange interface \r\n " ;
2151 print CLIENTCONF
";remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2153 } elsif ( $vpnsettings { 'ENABLED_BLUE' } eq 'on' && (& haveBlueNet
())){
2154 print CLIENTCONF
"remote $netsettings {'BLUE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2155 if ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
2156 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Orange interface \r\n " ;
2157 print CLIENTCONF
";remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2159 } elsif ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
2160 print CLIENTCONF
"remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2163 if ( $confighash { $cgiparams { 'KEY' }}[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ) {
2164 print CLIENTCONF
"pkcs12 $confighash { $cgiparams {'KEY'}}[1].p12 \r\n " ;
2165 $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 " ;
2167 print CLIENTCONF
"ca cacert.pem \r\n " ;
2168 print CLIENTCONF
"cert $confighash { $cgiparams {'KEY'}}[1]cert.pem \r\n " ;
2169 print CLIENTCONF
"key $confighash { $cgiparams {'KEY'}}[1].key \r\n " ;
2170 $zip -> addFile ( "${General::swroot}/ovpn/ca/cacert.pem" , "cacert.pem" ) or die "Can't add file cacert.pem \n " ;
2171 $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 " ;
2173 print CLIENTCONF
"cipher $vpnsettings {DCIPHER} \r\n " ;
2174 if ( $vpnsettings { DCOMPLZO
} eq 'on' ) {
2175 print CLIENTCONF
"comp-lzo \r\n " ;
2177 print CLIENTCONF
"verb 3 \r\n " ;
2178 print CLIENTCONF
"ns-cert-type server \r\n " ;
2179 print CLIENTCONF
"tls-remote $vpnsettings {ROOTCERT_HOSTNAME} \r\n " ;
2180 if ( $vpnsettings { MSSFIX
} eq 'on' ) {
2181 print CLIENTCONF
"mssfix \r\n " ;
2183 if ( $vpnsettings { FRAGMENT
} ne '' && $vpnsettings { DPROTOCOL
} ne 'tcp' ) {
2184 print CLIENTCONF
"fragment $vpnsettings {'FRAGMENT'} \r\n " ;
2187 # Check if a valid operating mode has been choosen and use it.
2188 if (( $vpnsettings { 'PMTU_DISCOVERY' } eq 'yes' ) ||
2189 ( $vpnsettings { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
2190 ( $vpnsettings { 'PMTU_DISCOVERY' } eq 'no' )) {
2191 if (( $vpnsettings { MSSFIX
} ne 'on' ) || ( $vpnsettings { FRAGMENT
} eq '' )) {
2192 print CLIENTCONF
"mtu-disc $vpnsettings {'PMTU_DISCOVERY'} \n " ;
2197 $zip -> addFile ( " $tempdir / $clientovpn " , $clientovpn ) or die "Can't add file $clientovpn \n " ;
2198 my $status = $zip -> writeToFileNamed ( $zippathname );
2200 open ( DLFILE
, "< $zippathname " ) or die "Unable to open $zippathname : $!" ;
2201 @fileholder = < DLFILE
>;
2202 print "Content-Type:application/x-download \n " ;
2203 print "Content-Disposition:attachment;filename= $zipname \n\n " ;
2211 ### Remove connection
2215 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
2216 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2217 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2219 if ( $confighash { $cgiparams { 'KEY' }}) {
2220 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2221 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2222 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
2225 my $temp = `/usr/bin/openssl ca -revoke ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf` ;
2231 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ) {
2233 my $conffile = glob ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]/ $confighash { $cgiparams {'KEY'}}[1].conf" );
2234 my $certfile = glob ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
2235 unlink ( $certfile ) or die "Removing $certfile fail: $!" ;
2236 unlink ( $conffile ) or die "Removing $conffile fail: $!" ;
2237 rmdir ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]" ) || die "Kann Verzeichnis nicht loeschen: $!" ;
2241 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
2242 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
2244 # A.Marx CCD delete ccd files and routes
2247 if (- f
"${General::swroot}/ovpn/ccd/ $confighash { $cgiparams {'KEY'}}[2]" )
2249 unlink "${General::swroot}/ovpn/ccd/ $confighash { $cgiparams {'KEY'}}[2]" ;
2252 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
2253 foreach my $key ( keys %ccdroutehash ) {
2254 if ( $ccdroutehash { $key }[ 0 ] eq $confighash { $cgiparams { 'KEY' }}[ 1 ]){
2255 delete $ccdroutehash { $key };
2258 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
2260 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
2261 foreach my $key ( keys %ccdroute2hash ) {
2262 if ( $ccdroute2hash { $key }[ 0 ] eq $confighash { $cgiparams { 'KEY' }}[ 1 ]){
2263 delete $ccdroute2hash { $key };
2266 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
2273 delete $confighash { $cgiparams { 'KEY' }};
2274 my $temp2 = `/usr/bin/openssl ca -gencrl -out ${General::swroot}/ovpn/crls/cacrl.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf` ;
2275 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2277 #&writeserverconf();
2279 $errormessage = $Lang :: tr
{ 'invalid key' };
2284 ### Download PKCS12 file
2286 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
2287 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2289 print "Content-Disposition: filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
2290 print "Content-Type: application/octet-stream \r\n\r\n " ;
2291 print `/bin/cat ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12` ;
2295 ### Display certificate
2297 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
2298 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2300 if ( - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
2301 & Header
:: showhttpheaders
();
2302 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
2303 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2304 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'certificate'}:" );
2305 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
2306 $output = & Header
:: cleanhtml
( $output , "y" );
2307 print "<pre> $output </pre> \n " ;
2308 & Header
:: closebox
();
2309 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2310 & Header
:: closebigbox
();
2311 & Header
:: closepage
();
2315 ### Display Certificate Revoke List
2317 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show crl' }) {
2318 # &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2320 if ( - f
"${General::swroot}/ovpn/crls/cacrl.pem" ) {
2321 & Header
:: showhttpheaders
();
2322 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
2323 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2324 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'crl'}:" );
2325 my $output = `/usr/bin/openssl crl -text -noout -in ${General::swroot}/ovpn/crls/cacrl.pem` ;
2326 $output = & Header
:: cleanhtml
( $output , "y" );
2327 print "<pre> $output </pre> \n " ;
2328 & Header
:: closebox
();
2329 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2330 & Header
:: closebigbox
();
2331 & Header
:: closepage
();
2336 ### Advanced Server Settings
2339 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced server' }) {
2344 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%cgiparams );
2348 # if ($cgiparams{'CLIENT2CLIENT'} eq '') {
2349 # $cgiparams{'CLIENT2CLIENT'} = 'on';
2352 if ( $cgiparams { 'MAX_CLIENTS' } eq '' ) {
2353 $cgiparams { 'MAX_CLIENTS' } = '100' ;
2355 if ( $cgiparams { 'KEEPALIVE_1' } eq '' ) {
2356 $cgiparams { 'KEEPALIVE_1' } = '10' ;
2358 if ( $cgiparams { 'KEEPALIVE_2' } eq '' ) {
2359 $cgiparams { 'KEEPALIVE_2' } = '60' ;
2361 if ( $cgiparams { 'LOG_VERB' } eq '' ) {
2362 $cgiparams { 'LOG_VERB' } = '3' ;
2364 $checked { 'CLIENT2CLIENT' }{ 'off' } = '' ;
2365 $checked { 'CLIENT2CLIENT' }{ 'on' } = '' ;
2366 $checked { 'CLIENT2CLIENT' }{ $cgiparams { 'CLIENT2CLIENT' }} = 'CHECKED' ;
2367 $checked { 'REDIRECT_GW_DEF1' }{ 'off' } = '' ;
2368 $checked { 'REDIRECT_GW_DEF1' }{ 'on' } = '' ;
2369 $checked { 'REDIRECT_GW_DEF1' }{ $cgiparams { 'REDIRECT_GW_DEF1' }} = 'CHECKED' ;
2370 $selected { 'ENGINES' }{ $cgiparams { 'ENGINES' }} = 'SELECTED' ;
2371 $checked { 'MSSFIX' }{ 'off' } = '' ;
2372 $checked { 'MSSFIX' }{ 'on' } = '' ;
2373 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
2374 $checked { 'PMTU_DISCOVERY' }{ $cgiparams { 'PMTU_DISCOVERY' }} = 'checked= \' checked \' ' ;
2375 $selected { 'LOG_VERB' }{ '1' } = '' ;
2376 $selected { 'LOG_VERB' }{ '2' } = '' ;
2377 $selected { 'LOG_VERB' }{ '3' } = '' ;
2378 $selected { 'LOG_VERB' }{ '4' } = '' ;
2379 $selected { 'LOG_VERB' }{ '5' } = '' ;
2380 $selected { 'LOG_VERB' }{ '6' } = '' ;
2381 $selected { 'LOG_VERB' }{ '7' } = '' ;
2382 $selected { 'LOG_VERB' }{ '8' } = '' ;
2383 $selected { 'LOG_VERB' }{ '9' } = '' ;
2384 $selected { 'LOG_VERB' }{ '10' } = '' ;
2385 $selected { 'LOG_VERB' }{ '11' } = '' ;
2386 $selected { 'LOG_VERB' }{ '0' } = '' ;
2387 $selected { 'LOG_VERB' }{ $cgiparams { 'LOG_VERB' }} = 'SELECTED' ;
2389 & Header
:: showhttpheaders
();
2390 & Header
:: openpage
( $Lang :: tr
{ 'status ovpn' }, 1 , '' );
2391 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
2392 if ( $errormessage ) {
2393 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
2394 print "<class name='base'> $errormessage \n " ;
2395 print " </class> \n " ;
2396 & Header
:: closebox
();
2398 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'advanced server' });
2400 <form method='post' enctype='multipart/form-data' disabled>
2401 <table width='100%' border=0>
2403 <td colspan='4'><b> $Lang ::tr{'dhcp-options'}</b></td>
2406 <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
2409 <td class='base'>Domain</td>
2410 <td><input type='TEXT' name='DHCP_DOMAIN' value=' $cgiparams {'DHCP_DOMAIN'}' size='30' /></td>
2413 <td class='base'>DNS</td>
2414 <td><input type='TEXT' name='DHCP_DNS' value=' $cgiparams {'DHCP_DNS'}' size='30' /></td>
2417 <td class='base'>WINS</td>
2418 <td><input type='TEXT' name='DHCP_WINS' value=' $cgiparams {'DHCP_WINS'}' size='30' /></td>
2421 <td colspan='4'><b> $Lang ::tr{'ovpn routes push options'}</b></td>
2424 <td class='base'> $Lang ::tr{'ovpn routes push'}</td>
2426 <textarea name='ROUTES_PUSH' cols='26' rows='6' wrap='off'>
2430 if ( $cgiparams { 'ROUTES_PUSH' } ne '' )
2432 print $cgiparams { 'ROUTES_PUSH' };
2441 <table width='100%'>
2443 <td class'base'><b> $Lang ::tr{'misc-options'}</b></td>
2446 <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='15%'></td><td width='35%'></td>
2449 <td class='base'>Client-To-Client</td>
2450 <td><input type='checkbox' name='CLIENT2CLIENT' $checked {'CLIENT2CLIENT'}{'on'} /></td>
2453 <td class='base'>Redirect-Gateway def1</td>
2454 <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked {'REDIRECT_GW_DEF1'}{'on'} /></td>
2457 <td class='base'>Max-Clients</td>
2458 <td><input type='text' name='MAX_CLIENTS' value=' $cgiparams {'MAX_CLIENTS'}' size='10' /></td>
2461 <td class='base'>Keppalive <br />
2462 (ping/ping-restart)</td>
2463 <td><input type='TEXT' name='KEEPALIVE_1' value=' $cgiparams {'KEEPALIVE_1'}' size='10' /></td>
2464 <td><input type='TEXT' name='KEEPALIVE_2' value=' $cgiparams {'KEEPALIVE_2'}' size='10' /></td>
2467 <td class='base'>fragment <br></td>
2468 <td><input type='TEXT' name='FRAGMENT' value=' $cgiparams {'FRAGMENT'}' size='10' /></td>
2469 <td>Default: <span class="base">1300</span></td>
2472 <td class='base'>mssfix</td>
2473 <td><input type='checkbox' name='MSSFIX' $checked {'MSSFIX'}{'on'} /></td>
2474 <td>Default: on</td>
2478 <td class='base'> $Lang ::tr{'ovpn mtu-disc'}</td>
2479 <td><input type='radio' name='PMTU_DISCOVERY' value='yes' $checked {'PMTU_DISCOVERY'}{'yes'} /> $Lang ::tr{'ovpn mtu-disc yes'}</td>
2480 <td><input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked {'PMTU_DISCOVERY'}{'maybe'} /> $Lang ::tr{'ovpn mtu-disc maybe'}</td>
2481 <td><input type='radio' name='PMTU_DISCOVERY' value='no' $checked {'PMTU_DISCOVERY'}{'no'} /> $Lang ::tr{'ovpn mtu-disc no'}</td>
2482 <td><input type='radio' name='PMTU_DISCOVERY' value='off' $checked {'PMTU_DISCOVERY'}{'off'} /> $Lang ::tr{'ovpn mtu-disc off'}</td>
2488 <table width='100%'>
2490 <td class'base'><b>Crypto-Engines</b></td>
2493 <td width='15%'></td> <td width='30%'> </td><td width='25%'> </td><td width='30%'></td>
2495 <tr><td class='base'>Engines:</td>
2496 <td><select name='ENGINES'><option value="none" $selected {'ENGINES'}{'none'}>none</option>
2497 <option value="cryptodev" $selected {'ENGINES'}{'cryptodev'}>cryptodev</option>
2498 <option value="padlock" $selected {'ENGINES'}{'padlock'}>padlock</option>
2504 <table width='100%'>
2506 <td class'base'><b> $Lang ::tr{'log-options'}</b></td>
2509 <td width='15%'></td> <td width='30%'> </td><td width='25%'> </td><td width='30%'></td>
2512 <tr><td class='base'>VERB</td>
2513 <td><select name='LOG_VERB'><option value='1' $selected {'LOG_VERB'}{'1'}>1</option>
2514 <option value='2' $selected {'LOG_VERB'}{'2'}>2</option>
2515 <option value='3' $selected {'LOG_VERB'}{'3'}>3</option>
2516 <option value='4' $selected {'LOG_VERB'}{'4'}>4</option>
2517 <option value='5' $selected {'LOG_VERB'}{'5'}>5</option>
2518 <option value='6' $selected {'LOG_VERB'}{'6'}>6</option>
2519 <option value='7' $selected {'LOG_VERB'}{'7'}>7</option>
2520 <option value='8' $selected {'LOG_VERB'}{'8'}>8</option>
2521 <option value='9' $selected {'LOG_VERB'}{'9'}>9</option>
2522 <option value='10' $selected {'LOG_VERB'}{'10'}>10</option>
2523 <option value='11' $selected {'LOG_VERB'}{'11'}>11</option>
2524 <option value='0' $selected {'LOG_VERB'}{'0'}>0</option></select></td>
2528 if ( - e
"/var/run/openvpn.pid" ){
2529 print " <br><b><font color='#990000'> $Lang ::tr{'attention'}:</b></font><br>
2530 $Lang ::tr{'server restart'}<br><br>
2533 <table width='100%'>
2536 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save-adv-options'}' disabled='disabled' /></td>
2537 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'cancel-adv-options'}' /></td>
2549 <table width='100%'>
2552 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save-adv-options'}' /></td>
2553 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'cancel-adv-options'}' /></td>
2561 & Header
:: closebox
();
2562 # print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
2563 & Header
:: closebigbox
();
2564 & Header
:: closepage
();
2568 # A.Marx CCD Add,delete or edit CCD net
2570 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ccd net' } ||
2571 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ccd add' } ||
2572 $cgiparams { 'ACTION' } eq "kill" ||
2573 $cgiparams { 'ACTION' } eq "edit" ||
2574 $cgiparams { 'ACTION' } eq 'editsave' ){
2575 & Header
:: showhttpheaders
();
2576 & Header
:: openpage
( $Lang :: tr
{ 'ccd net' }, 1 , '' );
2577 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2579 if ( $cgiparams { 'ACTION' } eq "kill" ){
2580 & delccdnet
( $cgiparams { 'net' });
2583 if ( $cgiparams { 'ACTION' } eq 'editsave' ){
2584 my ( $a , $b ) = split ( /\|/ , $cgiparams { 'ccdname' });
2585 if ( $a ne $b ){ & modccdnet
( $a , $b );}
2586 $cgiparams { 'ccdname' }= '' ;
2587 $cgiparams { 'ccdsubnet' }= '' ;
2590 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ccd add' }) {
2591 & addccdnet
( $cgiparams { 'ccdname' }, $cgiparams { 'ccdsubnet' }, $cgiparams { 'DOVPN_SUBNET' });
2593 if ( $errormessage ) {
2594 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
2595 print "<class name='base'> $errormessage " ;
2596 print " </class>" ;
2597 & Header
:: closebox
();
2599 if ( $cgiparams { 'ACTION' } eq "edit" ){
2601 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd modify' });
2604 <table width='100%' border=0>
2605 <tr><form method='post'>
2606 <td width='10%' nowrap='nowrap'> $Lang ::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value=' $cgiparams {'ccdname'}' /></td>
2607 <td width='8%'> $Lang ::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value=' $cgiparams {'ccdsubnet'}' readonly /></td></tr>
2608 <tr><td colspan='4' align='right'><hr><input type='submit' value=' $Lang ::tr{'save'}' /><input type='hidden' name='ACTION' value='editsave'/>
2609 <input type='hidden' name='ccdname' value=' $cgiparams {'ccdname'}'/><input type='submit' value=' $Lang ::tr{'cancel'}' />
2614 & Header
:: closebox
();
2616 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd net' } );
2618 <table width='100%' border='0' cellpadding='0' cellspacing='1'>
2620 <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>
2625 if (! - e
"/var/run/openvpn.pid" ){
2626 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd add' });
2628 <table width='100%' border='0'>
2629 <tr><form method='post'>
2630 <td colspan='4'> $Lang ::tr{'ccd hint'}<br><br></td></tr>
2632 <td width='10%' nowrap='nwrap'> $Lang ::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value=' $cgiparams {'ccdname'}' /></td>
2633 <td width='8%'> $Lang ::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value=' $cgiparams {'ccdsubnet'}' /></td></tr>
2634 <tr><td colspan=4><hr /></td></tr><tr>
2635 <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>
2639 & Header
:: closebox
();
2641 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd net' } );
2642 if ( - e
"/var/run/openvpn.pid" ){
2643 print "<b> $Lang ::tr{'attention'}:</b><br>" ;
2644 print " $Lang ::tr{'ccd noaddnet'}<br><hr>" ;
2648 <table width='100%' border='0' cellpadding='0' cellspacing='1'>
2650 <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>
2655 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
2658 foreach my $key ( sort { uc ( $ccdconfhash { $a }[ 0 ]) cmp uc ( $ccdconfhash { $b }[ 0 ]) } keys %ccdconfhash ) {
2659 @ccdconf =( $ccdconfhash { $key }[ 0 ], $ccdconfhash { $key }[ 1 ]);
2661 my $ccdhosts = & hostsinnet
( $ccdconf [ 0 ]);
2662 if ( $count % 2 ){ print " <tr bgcolor=' $color {'color22'}'>" ;}
2663 else { print " <tr bgcolor=' $color {'color20'}'>" ;}
2664 print "<td> $ccdconf [0]</td><td align='center'> $ccdconf [1]</td><td align='center'> $ccdhosts /" .(& ccdmaxclients
( $ccdconf [ 1 ])+ 1 ). "</td><td>" ;
2666 <form method='post' />
2667 <input type='image' src='/images/edit.gif' align='middle' alt= $Lang ::tr{'edit'} title= $Lang ::tr{'edit'} />
2668 <input type='hidden' name='ACTION' value='edit'/>
2669 <input type='hidden' name='ccdname' value=' $ccdconf [0]' />
2670 <input type='hidden' name='ccdsubnet' value=' $ccdconf [1]' />
2672 <form method='post' />
2673 <td><input type='hidden' name='ACTION' value='kill'/>
2674 <input type='hidden' name='number' value=' $count ' />
2675 <input type='hidden' name='net' value=' $ccdconf [0]' />
2676 <input type='image' src='/images/delete.gif' align='middle' alt= $Lang ::tr{'remove'} title= $Lang ::tr{'remove'} /></form></td></tr>
2680 print "</table></form>" ;
2681 & Header
:: closebox
();
2682 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2683 & Header
:: closebigbox
();
2684 & Header
:: closepage
();
2690 ### Openvpn Connections Statistics
2692 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ovpn con stat' }) {
2693 & Header
:: showhttpheaders
();
2694 & Header
:: openpage
( $Lang :: tr
{ 'ovpn con stat' }, 1 , '' );
2695 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2696 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ovpn con stat' });
2699 # <td><b>$Lang::tr{'protocol'}</b></td>
2700 # protocol temp removed
2702 <table width='100%' border='0' cellpadding='2' cellspacing='0'>
2704 <td><b> $Lang ::tr{'common name'}</b></td>
2705 <td><b> $Lang ::tr{'real address'}</b></td>
2706 <td><b> $Lang ::tr{'virtual address'}</b></td>
2707 <td><b> $Lang ::tr{'loged in at'}</b></td>
2708 <td><b> $Lang ::tr{'bytes sent'}</b></td>
2709 <td><b> $Lang ::tr{'bytes received'}</b></td>
2710 <td><b> $Lang ::tr{'last activity'}</b></td>
2714 my $filename = "/var/log/ovpnserver.log" ;
2715 open ( FILE
, $filename ) or die 'Unable to open config file.' ;
2716 my @current = < FILE
>;
2725 my %userlookup = ();
2726 foreach my $line ( @current )
2729 if ( $line =~ /^Updated,(.+)/ ){
2730 @match = split ( /^Updated,(.+)/ , $line );
2731 $status = $match [ 1 ];
2734 if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ ) {
2735 @match = split ( m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ , $line );
2736 if ( $match [ 1 ] ne "Common Name" ) {
2738 $userlookup { $match [ 2 ]} = $uid ;
2739 $users [ $uid ]{ 'CommonName' } = $match [ 1 ];
2740 $users [ $uid ]{ 'RealAddress' } = $match [ 2 ];
2741 $users [ $uid ]{ 'BytesReceived' } = & sizeformat
( $match [ 3 ]);
2742 $users [ $uid ]{ 'BytesSent' } = & sizeformat
( $match [ 4 ]);
2743 $users [ $uid ]{ 'Since' } = $match [ 5 ];
2744 $users [ $uid ]{ 'Proto' } = $proto ;
2748 if ( $line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/ ) {
2749 @match = split ( m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/ , $line );
2750 if ( $match [ 1 ] ne "Virtual Address" ) {
2751 $address = $match [ 3 ];
2752 #find the uid in the lookup table
2753 $uid = $userlookup { $address };
2754 $users [ $uid ]{ 'VirtualAddress' } = $match [ 1 ];
2755 $users [ $uid ]{ 'LastRef' } = $match [ 4 ];
2761 for ( my $idx = 1 ; $idx <= $user2 ; $idx ++){
2763 print "<tr bgcolor=' $color {'color20'}'> \n " ;
2765 print "<tr bgcolor=' $color {'color22'}'> \n " ;
2767 print "<td align='left'> $users [ $idx -1]{'CommonName'}</td>" ;
2768 print "<td align='left'> $users [ $idx -1]{'RealAddress'}</td>" ;
2769 print "<td align='left'> $users [ $idx -1]{'VirtualAddress'}</td>" ;
2770 print "<td align='left'> $users [ $idx -1]{'Since'}</td>" ;
2771 print "<td align='left'> $users [ $idx -1]{'BytesSent'}</td>" ;
2772 print "<td align='left'> $users [ $idx -1]{'BytesReceived'}</td>" ;
2773 print "<td align='left'> $users [ $idx -1]{'LastRef'}</td>" ;
2774 # print "<td align='left'>$users[$idx-1]{'Proto'}</td>";
2780 <table width='100%' border='0' cellpadding='2' cellspacing='0'>
2785 <tr><td align='center' > $Lang ::tr{'the statistics were last updated at'} <b> $status </b></td></tr>
2789 & Header
:: closebox
();
2790 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2791 & Header
:: closebigbox
();
2792 & Header
:: closepage
();
2796 ### Download Certificate
2798 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
2799 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2801 if ( - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
2802 print "Content-Disposition: filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \r\n " ;
2803 print "Content-Type: application/octet-stream \r\n\r\n " ;
2804 print `/bin/cat ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
2809 ### Enable/Disable connection
2812 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
2814 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2815 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2817 if ( $confighash { $cgiparams { 'KEY' }}) {
2818 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
2819 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
2820 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2821 #&writeserverconf();
2822 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2823 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2824 # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
2827 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
2828 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2829 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2830 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
2832 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2833 #&writeserverconf();
2836 $errormessage = $Lang :: tr
{ 'invalid key' };
2840 ### Restart connection
2842 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
2843 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2844 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2846 if ( $confighash { $cgiparams { 'KEY' }}) {
2847 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2848 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2849 # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
2852 $errormessage = $Lang :: tr
{ 'invalid key' };
2856 ### Remove connection
2858 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
2859 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2860 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2862 if ( $confighash { $cgiparams { 'KEY' }}) {
2863 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2864 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2865 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
2867 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
2868 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
2869 delete $confighash { $cgiparams { 'KEY' }};
2870 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2871 #&writeserverconf();
2873 $errormessage = $Lang :: tr
{ 'invalid key' };
2878 ### Choose between adding a host-net or net-net connection
2885 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
2886 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2887 & Header
:: showhttpheaders
();
2888 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
2889 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2890 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'connection type' });
2892 if ( - s
"${General::swroot}/ovpn/settings" ) {
2895 <b> $Lang ::tr{'connection type'}:</b><br />
2896 <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data">
2897 <tr><td><input type='radio' name='TYPE' value='host' checked /></td>
2898 <td class='base'> $Lang ::tr{'host to net vpn'}</td></tr>
2899 <tr><td><input type='radio' name='TYPE' value='net' /></td>
2900 <td class='base'> $Lang ::tr{'net to net vpn'}</td></tr>
2901 <tr><td><input type='radio' name='TYPE' value='net2net' /></td>
2902 <td class='base'> $Lang ::tr{'net to net vpn'} (Upload Client Package)</td></tr>
2903 <tr><td> </td><td class='base'><input type='file' name='FH' size='30'></td></tr>
2904 <tr><td> </td><td>Import Connection Name <img src='/blob.gif' /></td></tr>
2905 <tr><td> </td><td class='base'><input type='text' name='n2nname' size='30'>Default : Client Packagename</td></tr>
2906 <tr><td colspan='3'><hr /></td></tr>
2907 <tr><td align='right' colspan='3'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td></tr>
2908 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
2916 <b> $Lang ::tr{'connection type'}:</b><br />
2917 <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data">
2918 <tr><td><input type='radio' name='TYPE' value='host' checked /></td> <td class='base'> $Lang ::tr{'host to net vpn'}</td></tr>
2919 <tr><td align='right' colspan'3'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td></tr>
2926 & Header
:: closebox
();
2927 & Header
:: closebigbox
();
2928 & Header
:: closepage
();
2935 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) && ( $cgiparams { 'TYPE' } eq 'net2net' )){
2939 my $uplconffilename = '' ;
2940 my $uplconffilename2 = '' ;
2941 my $uplp12name = '' ;
2942 my $uplp12name2 = '' ;
2949 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2951 # Check if a file is uploaded
2953 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
2954 $errormessage = $Lang :: tr
{ 'there was no file upload' };
2958 # Move uploaded IPfire n2n package to temporary file
2960 ( my $fh , my $filename ) = tempfile
( );
2961 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
2966 my $zip = Archive
:: Zip
-> new ();
2967 my $zipName = $filename ;
2968 my $status = $zip -> read ( $zipName );
2969 if ( $status != AZ_OK
) {
2970 $errormessage = "Read of $zipName failed \n " ;
2974 my $tempdir = tempdir
( CLEANUP
=> 1 );
2975 my @files = $zip -> memberNames ();
2977 $zip -> extractMemberWithoutPaths ( $_ , " $tempdir / $_ " );
2979 my $countfiles = @files ;
2981 # Check if we have not more then 2 files
2983 if ( $countfiles == 2 ){
2985 if ( $_ =~ /.conf$/ ){
2986 $uplconffilename = $_ ;
2988 if ( $_ =~ /.p12$/ ){
2992 if (( $uplconffilename eq '' ) || ( $uplp12name eq '' )){
2993 $errormessage = "Either no *.conf or no *.p12 file found \n " ;
2997 open ( FILE
, " $tempdir / $uplconffilename " ) or die 'Unable to open*.conf file' ;
2998 @firen2nconf = < FILE
>;
3000 chomp ( @firen2nconf );
3004 $errormessage = "Filecount does not match only 2 files are allowed \n " ;
3012 if ( $cgiparams { 'n2nname' } ne '' ){
3014 $uplconffilename2 = " $cgiparams {'n2nname'}.conf" ;
3015 $uplp12name2 = " $cgiparams {'n2nname'}.p12" ;
3016 $n2nname [ 0 ] = $cgiparams { 'n2nname' };
3017 my @n2nname2 = split ( /\./ , $uplconffilename );
3018 $n2nname2 [ 0 ] =~ s/\n|\r//g ;
3019 my $input1 = "${General::swroot}/ovpn/certs/ $uplp12name " ;
3020 my $output1 = "${General::swroot}/ovpn/certs/ $uplp12name2 " ;
3021 my $input2 = " $n2nname2 [0]n2n" ;
3022 my $output2 = " $n2nname [0]n2n" ;
3023 my $filename = " $tempdir / $uplconffilename " ;
3024 open ( FILE
, "< $filename " ) or die 'Unable to open config file.' ;
3025 my @current = < FILE
>;
3027 foreach ( @current ) { s/$input1/$output1/g ;}
3028 foreach ( @current ) { s/$input2/$output2/g ;}
3029 open ( OUT
, "> $filename " ) || die 'Unable to open config file.' ;
3034 $uplconffilename2 = $uplconffilename ;
3035 $uplp12name2 = $uplp12name ;
3036 @n2nname = split ( /\./ , $uplconffilename );
3037 $n2nname [ 0 ] =~ s/\n|\r//g ;
3039 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
3040 unless (- d
"${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" , 0770 or die "Unable to create dir $!" ;}
3042 move
( " $tempdir / $uplconffilename " , "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $uplconffilename2 " );
3045 $errormessage = "*.conf move failed: $!" ;
3050 move
( " $tempdir / $uplp12name " , "${General::swroot}/ovpn/certs/ $uplp12name2 " );
3051 chmod 0600 , "${General::swroot}/ovpn/certs/ $uplp12name " ;
3054 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
3062 my @n2nmtudisc = split ( / / , ( grep { /^mtu-disc/ } @firen2nconf )[ 0 ]);;
3063 my @n2nproto2 = split ( / / , ( grep { /^proto/ } @firen2nconf )[ 0 ]);
3064 my @n2nproto = split ( /-/ , $n2nproto2 [ 1 ]);
3065 my @n2nport = split ( / / , ( grep { /^port/ } @firen2nconf )[ 0 ]);
3066 my @n2ntunmtu = split ( / / , ( grep { /^tun-mtu/ } @firen2nconf )[ 0 ]);
3067 my @n2ncomplzo = grep { /^comp-lzo/ } @firen2nconf ;
3068 if ( $n2ncomplzo [ 0 ] =~ /comp-lzo/ ){ $complzoactive = "on" ;} else { $complzoactive = "off" ;}
3069 my @n2nmssfix = grep { /^mssfix/ } @firen2nconf ;
3070 if ( $n2nmssfix [ 0 ] =~ /mssfix/ ){ $mssfixactive = "on" ;} else { $mssfixactive = "off" ;}
3071 #my @n2nmssfix = split(/ /, (grep { /^mssfix/ } @firen2nconf)[0]);
3072 my @n2nfragment = split ( / / , ( grep { /^fragment/ } @firen2nconf )[ 0 ]);
3073 my @n2nremote = split ( / / , ( grep { /^remote/ } @firen2nconf )[ 0 ]);
3074 my @n2novpnsuball = split ( / / , ( grep { /^ifconfig/ } @firen2nconf )[ 0 ]);
3075 my @n2novpnsub = split ( /\./ , $n2novpnsuball [ 1 ]);
3076 my @n2nremsub = split ( / / , ( grep { /^route/ } @firen2nconf )[ 0 ]);
3077 my @n2nmgmt = split ( / / , ( grep { /^management/ } @firen2nconf )[ 0 ]);
3078 my @n2nlocalsub = split ( / / , ( grep { /^# remsub/ } @firen2nconf )[ 0 ]);
3082 # m.a.d delete CR and LF from arrays for this chomp doesnt work
3085 $n2nremote [ 1 ] =~ s/\n|\r//g ;
3086 $n2novpnsub [ 0 ] =~ s/\n|\r//g ;
3087 $n2novpnsub [ 1 ] =~ s/\n|\r//g ;
3088 $n2novpnsub [ 2 ] =~ s/\n|\r//g ;
3089 $n2nproto [ 0 ] =~ s/\n|\r//g ;
3090 $n2nport [ 1 ] =~ s/\n|\r//g ;
3091 $n2ntunmtu [ 1 ] =~ s/\n|\r//g ;
3092 $n2nremsub [ 1 ] =~ s/\n|\r//g ;
3093 $n2nremsub [ 2 ] =~ s/\n|\r//g ;
3094 $n2nlocalsub [ 2 ] =~ s/\n|\r//g ;
3095 $n2nfragment [ 1 ] =~ s/\n|\r//g ;
3096 $n2nmgmt [ 2 ] =~ s/\n|\r//g ;
3097 $n2nmtudisc [ 1 ] =~ s/\n|\r//g ;
3098 chomp ( $complzoactive );
3099 chomp ( $mssfixactive );
3106 # Check if there is no other entry with this name
3109 foreach my $dkey ( keys %confighash ) {
3110 if ( $confighash { $dkey }[ 1 ] eq $n2nname [ 0 ]) {
3111 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
3112 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
3113 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
3114 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
3120 # Check if OpenVPN Subnet is valid
3123 foreach my $dkey ( keys %confighash ) {
3124 if ( $confighash { $dkey }[ 27 ] eq " $n2novpnsub [0]. $n2novpnsub [1]. $n2novpnsub [2].0/255.255.255.0" ) {
3125 $errormessage = 'The OpenVPN Subnet is already in use' ;
3126 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
3127 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
3128 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
3134 # Check im Dest Port is vaild
3137 foreach my $dkey ( keys %confighash ) {
3138 if ( $confighash { $dkey }[ 29 ] eq $n2nport [ 1 ] ) {
3139 $errormessage = 'The OpenVPN Port is already in use' ;
3140 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
3141 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
3142 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
3149 $key = & General
:: findhasharraykey
( \
%confighash );
3151 foreach my $i ( 0 .. 39 ) { $confighash { $key }[ $i ] = "" ;}
3153 $confighash { $key }[ 0 ] = 'off' ;
3154 $confighash { $key }[ 1 ] = $n2nname [ 0 ];
3155 $confighash { $key }[ 2 ] = $n2nname [ 0 ];
3156 $confighash { $key }[ 3 ] = 'net' ;
3157 $confighash { $key }[ 4 ] = 'cert' ;
3158 $confighash { $key }[ 6 ] = 'client' ;
3159 $confighash { $key }[ 8 ] = $n2nlocalsub [ 2 ];
3160 $confighash { $key }[ 10 ] = $n2nremote [ 1 ];
3161 $confighash { $key }[ 11 ] = " $n2nremsub [1]/ $n2nremsub [2]" ;
3162 $confighash { $key }[ 22 ] = $n2nmgmt [ 2 ];
3163 $confighash { $key }[ 23 ] = $mssfixactive ;
3164 $confighash { $key }[ 24 ] = $n2nfragment [ 1 ];
3165 $confighash { $key }[ 25 ] = 'IPFire n2n Client' ;
3166 $confighash { $key }[ 26 ] = 'red' ;
3167 $confighash { $key }[ 27 ] = " $n2novpnsub [0]. $n2novpnsub [1]. $n2novpnsub [2].0/255.255.255.0" ;
3168 $confighash { $key }[ 28 ] = $n2nproto [ 0 ];
3169 $confighash { $key }[ 29 ] = $n2nport [ 1 ];
3170 $confighash { $key }[ 30 ] = $complzoactive ;
3171 $confighash { $key }[ 31 ] = $n2ntunmtu [ 1 ];
3172 $confighash { $key }[ 38 ] = $n2nmtudisc [ 1 ];
3175 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3179 & Header
:: showhttpheaders
();
3180 & Header
:: openpage
( 'Validate imported configuration' , 1 , '' );
3181 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
3182 if ( $errormessage ) {
3183 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
3184 print "<class name='base'> $errormessage " ;
3185 print " </class>" ;
3186 & Header
:: closebox
();
3190 & Header
:: openbox
( '100%' , 'LEFT' , 'import ipfire net2net config' );
3192 if ( $errormessage eq '' ){
3194 <!-- ipfire net2net config gui -->
3195 <table width='100%'>
3196 <tr><td width='25%'> </td><td width='25%'> </td></tr>
3197 <tr><td class='boldbase'> $Lang ::tr{'name'}:</td><td><b> $n2nname [0]</b></td></tr>
3198 <tr><td> </td><td> </td></tr>
3199 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'Act as'}</td><td><b> $confighash { $key }[6]</b></td></tr>
3200 <tr><td class='boldbase' nowrap='nowrap'>Remote Host </td><td><b> $confighash { $key }[10]</b></td></tr>
3201 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'}</td><td><b> $confighash { $key }[8]</b></td></tr>
3202 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'}</td><td><b> $confighash { $key }[11]</b></td></tr>
3203 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn subnet'}</td><td><b> $confighash { $key }[27]</b></td></tr>
3204 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td><td><b> $confighash { $key }[28]</b></td></tr>
3205 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'destination port'}:</td><td><b> $confighash { $key }[29]</b></td></tr>
3206 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'}</td><td><b> $confighash { $key }[30]</b></td></tr>
3207 <tr><td class='boldbase' nowrap='nowrap'>MSSFIX </td><td><b> $confighash { $key }[23]</b></td></tr>
3208 <tr><td class='boldbase' nowrap='nowrap'>Fragment </td><td><b> $confighash { $key }[24]</b></td></tr>
3209 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'}</td><td><b> $confighash { $key }[31]</b></td></tr>
3210 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn mtu-disc'}</td><td><b> $confighash { $key }[38]</b></td></tr>
3211 <tr><td class='boldbase' nowrap='nowrap'>Management Port </td><td><b> $confighash { $key }[22]</b></td></tr>
3212 <tr><td> </td><td> </td></tr>
3216 & Header
:: closebox
();
3219 if ( $errormessage ) {
3220 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
3222 print "<div align='center'><form method='post' ENCTYPE='multipart/form-data'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />" ;
3223 print "<input type='hidden' name='TYPE' value='net2netakn' />" ;
3224 print "<input type='hidden' name='KEY' value=' $key ' />" ;
3225 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
3227 & Header
:: closebigbox
();
3228 & Header
:: closepage
();
3233 ### Accept IPFire n2n Package Settings
3236 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) && ( $cgiparams { 'TYPE' } eq 'net2netakn' )){
3239 ### Discard and Rollback IPFire n2n Package Settings
3242 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'cancel' }) && ( $cgiparams { 'TYPE' } eq 'net2netakn' )){
3244 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3246 if ( $confighash { $cgiparams { 'KEY' }}) {
3248 my $conffile = glob ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]/ $confighash { $cgiparams {'KEY'}}[1].conf" );
3249 my $certfile = glob ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
3250 unlink ( $certfile ) or die "Removing $certfile fail: $!" ;
3251 unlink ( $conffile ) or die "Removing $conffile fail: $!" ;
3252 rmdir ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]" ) || die "Kann Verzeichnis nicht loeschen: $!" ;
3253 delete $confighash { $cgiparams { 'KEY' }};
3254 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3257 $errormessage = $Lang :: tr
{ 'invalid key' };
3267 ### Adding a new connection
3269 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
3270 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
3271 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
3273 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
3274 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
3275 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3277 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
3278 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
3279 $errormessage = $Lang :: tr
{ 'invalid key' };
3282 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
3283 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
3284 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
3285 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
3286 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
3287 $cgiparams { 'SIDE' } = $confighash { $cgiparams { 'KEY' }}[ 6 ];
3288 $cgiparams { 'LOCAL_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 8 ];
3289 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
3290 $cgiparams { 'REMOTE_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 11 ];
3291 $cgiparams { 'OVPN_MGMT' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
3292 $cgiparams { 'MSSFIX' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
3293 $cgiparams { 'FRAGMENT' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
3294 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
3295 $cgiparams { 'INTERFACE' } = $confighash { $cgiparams { 'KEY' }}[ 26 ];
3296 $cgiparams { 'OVPN_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
3297 $cgiparams { 'PROTOCOL' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
3298 $cgiparams { 'DEST_PORT' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
3299 $cgiparams { 'COMPLZO' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
3300 $cgiparams { 'MTU' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
3301 $cgiparams { 'CHECK1' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
3302 $name = $cgiparams { 'CHECK1' } ;
3303 $cgiparams { $name } = $confighash { $cgiparams { 'KEY' }}[ 33 ];
3304 $cgiparams { 'RG' } = $confighash { $cgiparams { 'KEY' }}[ 34 ];
3305 $cgiparams { 'CCD_DNS1' } = $confighash { $cgiparams { 'KEY' }}[ 35 ];
3306 $cgiparams { 'CCD_DNS2' } = $confighash { $cgiparams { 'KEY' }}[ 36 ];
3307 $cgiparams { 'CCD_WINS' } = $confighash { $cgiparams { 'KEY' }}[ 37 ];
3308 $cgiparams { 'PMTU_DISCOVERY' } = $confighash { $cgiparams { 'KEY' }}[ 38 ];
3309 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
3310 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
3312 #A.Marx CCD check iroute field and convert it to decimal
3313 if ( $cgiparams { 'TYPE' } eq 'host' ) {
3315 my %ccdroutehash =();
3319 if ( $cgiparams { 'IR' } ne '' ){
3320 @temp = split ( " \n " , $cgiparams { 'IR' });
3321 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3323 foreach my $key ( keys %ccdroutehash ) {
3324 if ( $ccdroutehash { $key }[ 0 ] eq $cgiparams { 'NAME' }) {
3326 delete $ccdroutehash { $key };
3328 $keypoint = & General
:: findhasharraykey
( \
%ccdroutehash );
3331 $ccdroutehash { $keypoint }[ 0 ]= $cgiparams { 'NAME' };
3334 foreach $val ( @temp ){
3337 #check if iroute exists in ccdroute or if new iroute is part of an existing one
3338 foreach my $key ( keys %ccdroutehash ) {
3339 foreach my $oldiroute ( 1 .. $ #{$ccdroutehash{$key}}){
3340 if ( $ccdroutehash { $key }[ $oldiroute ] eq " $val " ) {
3341 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err irouteexist' };
3344 my ( $ip1 , $cidr1 ) = split ( /\/ /, $val );
3345 my ( $ip2 , $cidr2 ) = split ( /\/ /, $ccdroutehash { $key }[ $oldiroute ]);
3346 if (& General
:: IpInSubnet
( $ip1 , $ip2 , $cidr2 )){
3347 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err irouteexist' };
3353 if (!& General
:: validipandmask
( $val )){
3354 $errormessage = $errormessage . "Route " . $Lang :: tr
{ 'ccd invalid' }. " ( $val )" ;
3357 ( $ip , $cidr ) = split ( /\/ /, $val );
3358 $ip =& General
:: getnetworkip
( $ip ,& General
:: iporsubtocidr
( $cidr ));
3359 $cidr =& General
:: iporsubtodec
( $cidr );
3360 $ccdroutehash { $keypoint }[ $i ] = $ip . "/" . $cidr ;
3364 #check for existing network IP's
3365 if (& General
:: IpInSubnet
( $ip , $netsettings { GREEN_NETADDRESS
}, $netsettings { GREEN_NETMASK
}) && $netsettings { GREEN_NETADDRESS
} ne '0.0.0.0' )
3367 $errormessage = $Lang :: tr
{ 'ccd err green' };
3369 } elsif (& General
:: IpInSubnet
( $ip , $netsettings { RED_NETADDRESS
}, $netsettings { RED_NETMASK
}) && $netsettings { RED_NETADDRESS
} ne '0.0.0.0' )
3371 $errormessage = $Lang :: tr
{ 'ccd err red' };
3373 } elsif (& General
:: IpInSubnet
( $ip , $netsettings { BLUE_NETADDRESS
}, $netsettings { BLUE_NETMASK
}) && $netsettings { BLUE_NETADDRESS
} ne '0.0.0.0' && $netsettings { BLUE_NETADDRESS
} gt '' )
3375 $errormessage = $Lang :: tr
{ 'ccd err blue' };
3377 } elsif (& General
:: IpInSubnet
( $ip , $netsettings { ORANGE_NETADDRESS
}, $netsettings { ORANGE_NETMASK
}) && $netsettings { ORANGE_NETADDRESS
} ne '0.0.0.0' && $netsettings { ORANGE_NETADDRESS
} gt '' )
3379 $errormessage = $Lang :: tr
{ 'ccd err orange' };
3383 if (& General
:: validipandmask
( $val )){
3384 $ccdroutehash { $keypoint }[ $i ] = $ip . "/" . $cidr ;
3386 $errormessage = $errormessage . "Route " . $Lang :: tr
{ 'ccd invalid' }. " ( $ip / $cidr )" ;
3391 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3394 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3395 foreach my $key ( keys %ccdroutehash ) {
3396 if ( $ccdroutehash { $key }[ 0 ] eq $cgiparams { 'NAME' }) {
3397 delete $ccdroutehash { $key };
3398 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3404 #check route field and convert it to decimal
3407 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
3409 foreach my $key ( keys %ccdroute2hash ) {
3410 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }) {
3412 delete $ccdroute2hash { $key };
3414 $keypoint = & General
:: findhasharraykey
( \
%ccdroute2hash );
3415 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3419 $ccdroute2hash { $keypoint }[ 0 ]= $cgiparams { 'NAME' };
3420 if ( $cgiparams { 'IFROUTE' } eq '' ){ $cgiparams { 'IFROUTE' } = $Lang :: tr
{ 'ccd none' };}
3421 @temp = split ( /\|/ , $cgiparams { 'IFROUTE' });
3423 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%ownnet );
3424 foreach $val ( @temp ){
3427 if ( $val eq $Lang :: tr
{ 'green' })
3429 $val = $ownnet { GREEN_NETADDRESS
}. "/" . $ownnet { GREEN_NETMASK
};
3431 if ( $val eq $Lang :: tr
{ 'blue' })
3433 $val = $ownnet { BLUE_NETADDRESS
}. "/" . $ownnet { BLUE_NETMASK
};
3435 if ( $val eq $Lang :: tr
{ 'orange' })
3437 $val = $ownnet { ORANGE_NETADDRESS
}. "/" . $ownnet { ORANGE_NETMASK
};
3439 my ( $ip , $cidr ) = split ( /\/ /, $val );
3441 if ( $val ne $Lang :: tr
{ 'ccd none' })
3443 if (! & check_routes_push
( $val )){ $errormessage = $errormessage . "Route $val " . $Lang :: tr
{ 'ccd err routeovpn2' }. " ( $val )" ; goto VPNCONF_ERROR
;}
3444 if (! & check_ccdroute
( $val )){ $errormessage = $errormessage . "<br>Route $val " . $Lang :: tr
{ 'ccd err inuse' }. " ( $val )" ; goto VPNCONF_ERROR
;}
3445 if (! & check_ccdconf
( $val )){ $errormessage = $errormessage . "<br>Route $val " . $Lang :: tr
{ 'ccd err routeovpn' }. " ( $val )" ; goto VPNCONF_ERROR
;}
3446 if (& General
:: validipandmask
( $val )){
3447 $val = $ip . "/" .& General
:: iporsubtodec
( $cidr );
3448 $ccdroute2hash { $keypoint }[ $i ] = $val ;
3450 $errormessage = $errormessage . "Route " . $Lang :: tr
{ 'ccd invalid' }. " ( $val )" ;
3454 $ccdroute2hash { $keypoint }[ $i ]= '' ;
3458 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
3461 if ( $cgiparams { 'CCD_DNS1' } ne '' && ! & General
:: validip
( $cgiparams { 'CCD_DNS1' })) {
3462 $errormessage = $errormessage . "<br>" . $Lang :: tr
{ 'invalid input for dhcp dns' }. " 1" ;
3466 if ( $cgiparams { 'CCD_DNS2' } ne '' && ! & General
:: validip
( $cgiparams { 'CCD_DNS2' })) {
3467 $errormessage = $errormessage . "<br>" . $Lang :: tr
{ 'invalid input for dhcp dns' }. " 2" ;
3471 if ( $cgiparams { 'CCD_WINS' } ne '' && ! & General
:: validip
( $cgiparams { 'CCD_WINS' })) {
3472 $errormessage = $errormessage . "<br>" . $Lang :: tr
{ 'invalid input for dhcp wins' };
3480 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
3481 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
3482 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3483 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3484 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3490 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
3491 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
3492 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3493 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3494 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3499 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
3500 $errormessage = $Lang :: tr
{ 'name is invalid' };
3501 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3502 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3503 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3508 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
3509 $errormessage = $Lang :: tr
{ 'name too long' };
3510 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3511 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3512 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3521 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3523 if ( $cgiparams { 'DEST_PORT' } eq $vpnsettings { 'DDEST_PORT' }) {
3524 $errormessage = $Lang :: tr
{ 'openvpn destination port used' };
3525 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3526 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3530 if ( $cgiparams { 'DEST_PORT' } eq '' ) {
3531 $errormessage = $Lang :: tr
{ 'openvpn destination port used' };
3532 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3533 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3537 if ( $cgiparams { 'OVPN_SUBNET' } eq $vpnsettings { 'DOVPN_SUBNET' }) {
3538 $errormessage = $Lang :: tr
{ 'openvpn subnet is used' };
3539 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3540 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3544 if (( $cgiparams { 'PROTOCOL' } eq 'tcp' ) && ( $cgiparams { 'MSSFIX' } eq 'on' )) {
3545 $errormessage = $Lang :: tr
{ 'openvpn mssfix allowed with udp' };
3546 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3547 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3551 if (( $cgiparams { 'PROTOCOL' } eq 'tcp' ) && ( $cgiparams { 'FRAGMENT' } ne '' )) {
3552 $errormessage = $Lang :: tr
{ 'openvpn fragment allowed with udp' };
3553 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3554 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3558 if (( $cgiparams { 'PMTU_DISCOVERY' } ne 'off' ) && ( $cgiparams { 'MTU' } ne '1500' )) {
3559 $errormessage = $Lang :: tr
{ 'ovpn mtu-disc and mtu not 1500' };
3560 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3561 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3565 if ( $cgiparams { 'PMTU_DISCOVERY' } ne 'off' ) {
3566 if (( $cgiparams { 'FRAGMENT' } ne '' ) || ( $cgiparams { 'MSSFIX' } eq 'on' )) {
3567 $errormessage = $Lang :: tr
{ 'ovpn mtu-disc with mssfix or fragment' };
3568 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3569 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3574 if ( & validdotmask
( $cgiparams { 'LOCAL_SUBNET' })) {
3575 $errormessage = $Lang :: tr
{ 'openvpn prefix local subnet' };
3576 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3577 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3581 if ( & validdotmask
( $cgiparams { 'OVPN_SUBNET' })) {
3582 $errormessage = $Lang :: tr
{ 'openvpn prefix openvpn subnet' };
3583 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3584 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3588 if ( & validdotmask
( $cgiparams { 'REMOTE_SUBNET' })) {
3589 $errormessage = $Lang :: tr
{ 'openvpn prefix remote subnet' };
3590 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3591 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3595 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) {
3596 $cgiparams { 'OVPN_MGMT' } = $cgiparams { 'DEST_PORT' };
3601 # if (($cgiparams{'TYPE'} eq 'net') && ($cgiparams{'SIDE'} !~ /^(left|right)$/)) {
3602 # $errormessage = $Lang::tr{'ipfire side is invalid'};
3603 # goto VPNCONF_ERROR;
3606 # Check if there is no other entry with this name
3607 if (! $cgiparams { 'KEY' }) {
3608 foreach my $key ( keys %confighash ) {
3609 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
3610 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
3611 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3612 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3613 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3620 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! $cgiparams { 'REMOTE' })) {
3621 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
3622 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3623 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3624 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3629 if ( $cgiparams { 'REMOTE' }) {
3630 if (! & General
:: validip
( $cgiparams { 'REMOTE' })) {
3631 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
3632 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
3633 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3634 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3635 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3639 if (& valid_dns_host
( $cgiparams { 'REMOTE' })) {
3640 $warnmessage = " $Lang ::tr{'check vpn lr'} $cgiparams {'REMOTE'}. $Lang ::tr{'dns check failed'}" ;
3641 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3648 if ( $cgiparams { 'TYPE' } ne 'host' ) {
3649 unless (& General
:: validipandmask
( $cgiparams { 'LOCAL_SUBNET' })) {
3650 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
3651 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3652 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3653 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3655 goto VPNCONF_ERROR
;}
3657 # Check if there is no other entry without IP-address and PSK
3658 if ( $cgiparams { 'REMOTE' } eq '' ) {
3659 foreach my $key ( keys %confighash ) {
3660 if (( $cgiparams { 'KEY' } ne $key ) &&
3661 ( $confighash { $key }[ 4 ] eq 'psk' || $cgiparams { 'AUTH' } eq 'psk' ) &&
3662 $confighash { $key }[ 10 ] eq '' ) {
3663 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
3668 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! & General
:: validipandmask
( $cgiparams { 'REMOTE_SUBNET' }))) {
3669 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
3670 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3671 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3675 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
3676 $errormessage = $Lang :: tr
{ 'invalid input' };
3679 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
3680 $errormessage = $Lang :: tr
{ 'invalid input' };
3685 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
3686 # if (! length($cgiparams{'PSK'}) ) {
3687 # $errormessage = $Lang::tr{'pre-shared key is too short'};
3688 # goto VPNCONF_ERROR;
3690 # if ($cgiparams{'PSK'} =~ /['",&]/) {
3691 # $errormessage = $Lang::tr{'invalid characters found in pre-shared key'};
3692 # goto VPNCONF_ERROR;
3694 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
3695 if ( $cgiparams { 'KEY' }) {
3696 $errormessage = $Lang :: tr
{ 'cant change certificates' };
3699 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
3700 $errormessage = $Lang :: tr
{ 'there was no file upload' };
3704 # Move uploaded certificate request to a temporary file
3705 ( my $fh , my $filename ) = tempfile
( );
3706 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
3711 # Sign the certificate request and move it
3712 # Sign the host certificate request
3713 system ( '/usr/bin/openssl' , 'ca' , '-days' , " $cgiparams {'DAYS_VALID'}" ,
3714 '-batch' , '-notext' ,
3716 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
3717 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
3719 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
3721 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3722 & newcleanssldatabase
();
3726 & deletebackupcert
();
3729 my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem` ;
3730 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
3732 $temp =~ s
+/ Email
+, E
+;
3733 $temp =~ s/ ST=/ S=/ ;
3734 $cgiparams { 'CERT_NAME' } = $temp ;
3735 $cgiparams { 'CERT_NAME' } =~ s/,//g ;
3736 $cgiparams { 'CERT_NAME' } =~ s/\'//g ;
3737 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
3738 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
3741 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
3742 if ( $cgiparams { 'KEY' }) {
3743 $errormessage = $Lang :: tr
{ 'cant change certificates' };
3746 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
3747 $errormessage = $Lang :: tr
{ 'there was no file upload' };
3750 # Move uploaded certificate to a temporary file
3751 ( my $fh , my $filename ) = tempfile
( );
3752 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
3757 # Verify the certificate has a valid CA and move it
3759 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/cacert.pem $filename ` ;
3760 if ( $test =~ /: OK/ ) {
3763 foreach my $key ( keys %cahash ) {
3764 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/ $cahash { $key }[0]cert.pem $filename ` ;
3765 if ( $test =~ /: OK/ ) {
3771 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
3775 move
( $filename , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3777 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
3783 my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem` ;
3784 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
3786 $temp =~ s
+/ Email
+, E
+;
3787 $temp =~ s/ ST=/ S=/ ;
3788 $cgiparams { 'CERT_NAME' } = $temp ;
3789 $cgiparams { 'CERT_NAME' } =~ s/,//g ;
3790 $cgiparams { 'CERT_NAME' } =~ s/\'//g ;
3791 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
3792 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3793 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
3796 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
3797 if ( $cgiparams { 'KEY' }) {
3798 $errormessage = $Lang :: tr
{ 'cant change certificates' };
3801 # Validate input since the form was submitted
3802 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
3803 $errormessage = $Lang :: tr
{ 'name too long' };
3806 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
3807 $errormessage = $Lang :: tr
{ 'invalid input for name' };
3810 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
3811 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
3814 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
3815 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
3818 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
3819 $errormessage = $Lang :: tr
{ 'invalid input for department' };
3822 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
3823 $errormessage = $Lang :: tr
{ 'organization too long' };
3826 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
3827 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
3830 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
3831 $errormessage = $Lang :: tr
{ 'invalid input for city' };
3834 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
3835 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
3838 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
3839 $errormessage = $Lang :: tr
{ 'invalid input for country' };
3842 if ( $cgiparams { 'CERT_PASS1' } ne '' && $cgiparams { 'CERT_PASS2' } ne '' ){
3843 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
3844 $errormessage = $Lang :: tr
{ 'password too short' };
3848 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
3849 $errormessage = $Lang :: tr
{ 'passwords do not match' };
3853 # Replace empty strings with a .
3854 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
3855 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
3856 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
3858 # Create the Host certificate request client
3859 my $pid = open ( OPENSSL
, "|-" );
3860 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto VPNCONF_ERROR
;};
3861 if ( $pid ) { # parent
3862 print OPENSSL
" $cgiparams {'CERT_COUNTRY'} \n " ;
3863 print OPENSSL
" $state \n " ;
3864 print OPENSSL
" $city \n " ;
3865 print OPENSSL
" $cgiparams {'CERT_ORGANIZATION'} \n " ;
3866 print OPENSSL
" $ou \n " ;
3867 print OPENSSL
" $cgiparams {'CERT_NAME'} \n " ;
3868 print OPENSSL
" $cgiparams {'CERT_EMAIL'} \n " ;
3869 print OPENSSL
". \n " ;
3870 print OPENSSL
". \n " ;
3873 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
3874 unlink ( "${General::swroot}ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3875 unlink ( "${General::swroot}ovpn/certs/ $cgiparams {'NAME'}req.pem" );
3879 unless ( exec ( '/usr/bin/openssl' , 'req' , '-nodes' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
3880 '-newkey' , 'rsa:1024' ,
3881 '-keyout' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" ,
3882 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" ,
3883 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
3884 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
3885 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3886 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
3891 # Sign the host certificate request
3892 system ( '/usr/bin/openssl' , 'ca' , '-days' , " $cgiparams {'DAYS_VALID'}" ,
3893 '-batch' , '-notext' ,
3894 '-in' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" ,
3895 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
3896 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
3898 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
3899 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3900 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
3901 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3902 & newcleanssldatabase
();
3905 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
3906 & deletebackupcert
();
3909 # Create the pkcs12 file
3910 system ( '/usr/bin/openssl' , 'pkcs12' , '-export' ,
3911 '-inkey' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" ,
3912 '-in' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
3913 '-name' , $cgiparams { 'NAME' },
3914 '-passout' , "pass: $cgiparams {'CERT_PASS1'}" ,
3915 '-certfile' , "${General::swroot}/ovpn/ca/cacert.pem" ,
3916 '-caname' , " $vpnsettings {'ROOTCERT_ORGANIZATION'} CA" ,
3917 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12" );
3919 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
3920 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3921 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3922 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12" );
3925 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3927 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
3928 ; # Nothing, just editing
3930 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
3934 # Check if there is no other entry with this common name
3935 if ((! $cgiparams { 'KEY' }) && ( $cgiparams { 'AUTH' } ne 'psk' )) {
3936 foreach my $key ( keys %confighash ) {
3937 if ( $confighash { $key }[ 2 ] eq $cgiparams { 'CERT_NAME' }) {
3938 $errormessage = $Lang :: tr
{ 'a connection with this common name already exists' };
3945 my $key = $cgiparams { 'KEY' };
3948 $key = & General
:: findhasharraykey
( \
%confighash );
3949 foreach my $i ( 0 .. 38 ) { $confighash { $key }[ $i ] = "" ;}
3951 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
3952 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
3953 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
3954 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
3957 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
3958 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
3959 $confighash { $key }[ 4 ] = 'psk' ;
3960 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
3962 $confighash { $key }[ 4 ] = 'cert' ;
3964 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3965 $confighash { $key }[ 6 ] = $cgiparams { 'SIDE' };
3966 $confighash { $key }[ 11 ] = $cgiparams { 'REMOTE_SUBNET' };
3968 $confighash { $key }[ 8 ] = $cgiparams { 'LOCAL_SUBNET' };
3969 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
3970 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) {
3971 $confighash { $key }[ 22 ] = $confighash { $key }[ 29 ];
3973 $confighash { $key }[ 22 ] = $cgiparams { 'OVPN_MGMT' };
3975 $confighash { $key }[ 23 ] = $cgiparams { 'MSSFIX' };
3976 $confighash { $key }[ 24 ] = $cgiparams { 'FRAGMENT' };
3977 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
3978 $confighash { $key }[ 26 ] = $cgiparams { 'INTERFACE' };
3980 $confighash { $key }[ 27 ] = $cgiparams { 'OVPN_SUBNET' };
3981 $confighash { $key }[ 28 ] = $cgiparams { 'PROTOCOL' };
3982 $confighash { $key }[ 29 ] = $cgiparams { 'DEST_PORT' };
3983 $confighash { $key }[ 30 ] = $cgiparams { 'COMPLZO' };
3984 $confighash { $key }[ 31 ] = $cgiparams { 'MTU' };
3985 $confighash { $key }[ 32 ] = $cgiparams { 'CHECK1' };
3986 $name = $cgiparams { 'CHECK1' };
3987 $confighash { $key }[ 33 ] = $cgiparams { $name };
3988 $confighash { $key }[ 34 ] = $cgiparams { 'RG' };
3989 $confighash { $key }[ 35 ] = $cgiparams { 'CCD_DNS1' };
3990 $confighash { $key }[ 36 ] = $cgiparams { 'CCD_DNS2' };
3991 $confighash { $key }[ 37 ] = $cgiparams { 'CCD_WINS' };
3992 $confighash { $key }[ 38 ] = $cgiparams { 'PMTU_DISCOVERY' };
3995 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3997 if ( $cgiparams { 'CHECK1' } ){
3999 my ( $ccdip , $ccdsub )= split "/" , $cgiparams { $name };
4000 my ( $a , $b , $c , $d ) = split ( /\./ , $ccdip );
4001 if ( - e
"${General::swroot}/ovpn/ccd/ $confighash { $key }[2]" ){
4002 unlink "${General::swroot}/ovpn/ccd/ $cgiparams {'CERT_NAME'}" ;
4004 open ( CCDRWCONF
, '>' , "${General::swroot}/ovpn/ccd/ $confighash { $key }[2]" ) or die "Unable to create clientconfigfile $!" ;
4005 print CCDRWCONF
"# OpenVPN Clientconfig from CCD extension by Copymaster# \n\n " ;
4006 if ( $cgiparams { 'CHECK1' } eq 'dynamic' ){
4007 print CCDRWCONF
"#This client uses the dynamic pool \n " ;
4009 print CCDRWCONF
"#Ip address client and Server \n " ;
4010 print CCDRWCONF
"ifconfig-push $ccdip " .& General
:: getlastip
( $ccdip , 1 ). " \n " ;
4012 if ( $confighash { $key }[ 34 ] eq 'on' ){
4013 print CCDRWCONF
" \n #Redirect Gateway: \n #All IP traffic is redirected through the vpn \n " ;
4014 print CCDRWCONF
"push redirect-gateway \n " ;
4016 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
4017 if ( $cgiparams { 'IR' } ne '' ){
4018 print CCDRWCONF
" \n #Client routes these Networks (behind Client) \n " ;
4019 foreach my $key ( keys %ccdroutehash ){
4020 if ( $ccdroutehash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4021 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}){
4022 my ( $a , $b )= split ( /\/ /, $ccdroutehash { $key }[ $i ]);
4023 print CCDRWCONF
"iroute $a $b \n " ;
4028 if ( $cgiparams { 'IFROUTE' } eq $Lang :: tr
{ 'ccd none' } ){ $cgiparams { 'IFROUTE' }= '' ;}
4029 if ( $cgiparams { 'IFROUTE' } ne '' ){
4030 print CCDRWCONF
" \n #Client gets routes to these Networks (behind IPFIRE) \n " ;
4031 foreach my $key ( keys %ccdroute2hash ){
4032 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4033 foreach my $i ( 1 .. $ #{$ccdroute2hash{$key}}){
4034 if ( $ccdroute2hash { $key }[ $i ] eq $Lang :: tr
{ 'blue' }){
4036 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%blue );
4037 print CCDRWCONF
"push \" route $blue {BLUE_ADDRESS} $blue {BLUE_NETMASK} \n " ;
4038 } elsif ( $ccdroute2hash { $key }[ $i ] eq $Lang :: tr
{ 'orange' }){
4040 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%orange );
4041 print CCDRWCONF
"push \" route $orange {ORANGE_ADDRESS} $orange {ORANGE_NETMASK} \n " ;
4043 my ( $a , $b )= split ( /\/ /, $ccdroute2hash { $key }[ $i ]);
4044 print CCDRWCONF
"push \" route $a $b \"\n " ;
4050 if (( $cgiparams { 'CCD_DNS1' } eq '' ) && ( $cgiparams { 'CCD_DNS1' } ne '' )){ $cgiparams { 'CCD_DNS1' } = $cgiparams { 'CCD_DNS2' }; $cgiparams { 'CCD_DNS2' }= '' ;}
4051 if ( $cgiparams { 'CCD_DNS1' } ne '' ){
4052 print CCDRWCONF
" \n #Client gets these Nameservers \n " ;
4053 print CCDRWCONF
"push \" dhcp-option DNS $cgiparams {'CCD_DNS1'} \" \n " ;
4055 if ( $cgiparams { 'CCD_DNS2' } ne '' ){
4056 print CCDRWCONF
"push \" dhcp-option DNS $cgiparams {'CCD_DNS2'} \" \n " ;
4058 if ( $cgiparams { 'CCD_WINS' } ne '' ){
4059 print CCDRWCONF
" \n #Client gets this WINS server \n " ;
4060 print CCDRWCONF
"push \" dhcp-option WINS $cgiparams {'CCD_WINS'} \" \n " ;
4069 if ( $cgiparams { 'TYPE' } eq 'net' ) {
4071 if (- e
"/var/run/ $confighash { $key }[1]n2n.pid" ) {
4072 system ( '/usr/local/bin/openvpnctrl' , '-kn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
4074 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
4075 my $key = $cgiparams { 'KEY' };
4077 $key = & General
:: findhasharraykey
( \
%confighash );
4078 foreach my $i ( 0 .. 31 ) { $confighash { $key }[ $i ] = "" ;}
4080 $confighash { $key }[ 0 ] = 'on' ;
4081 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
4083 system ( '/usr/local/bin/openvpnctrl' , '-sn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
4091 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
4092 $cgiparams { 'KEY' } = $key ;
4093 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
4097 $cgiparams { 'ENABLED' } = 'on' ;
4101 $cgiparams { 'MSSFIX' } = 'on' ;
4102 $cgiparams { 'FRAGMENT' } = '1300' ;
4103 $cgiparams { 'PMTU_DISCOVERY' } = 'off' ;
4107 $cgiparams { 'SIDE' } = 'left' ;
4108 if ( ! - f
"${General::swroot}/ovpn/ca/cakey.pem" ) {
4109 $cgiparams { 'AUTH' } = 'psk' ;
4110 } elsif ( ! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
4111 $cgiparams { 'AUTH' } = 'certfile' ;
4113 $cgiparams { 'AUTH' } = 'certgen' ;
4115 $cgiparams { 'LOCAL_SUBNET' } = " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" ;
4116 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
4117 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
4118 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
4119 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
4123 $checked { 'ENABLED' }{ 'off' } = '' ;
4124 $checked { 'ENABLED' }{ 'on' } = '' ;
4125 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = 'CHECKED' ;
4126 $checked { 'ENABLED_BLUE' }{ 'off' } = '' ;
4127 $checked { 'ENABLED_BLUE' }{ 'on' } = '' ;
4128 $checked { 'ENABLED_BLUE' }{ $cgiparams { 'ENABLED_BLUE' }} = 'CHECKED' ;
4129 $checked { 'ENABLED_ORANGE' }{ 'off' } = '' ;
4130 $checked { 'ENABLED_ORANGE' }{ 'on' } = '' ;
4131 $checked { 'ENABLED_ORANGE' }{ $cgiparams { 'ENABLED_ORANGE' }} = 'CHECKED' ;
4134 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
4135 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
4136 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = 'CHECKED' ;
4138 $selected { 'SIDE' }{ 'server' } = '' ;
4139 $selected { 'SIDE' }{ 'client' } = '' ;
4140 $selected { 'SIDE' }{ $cgiparams { 'SIDE' }} = 'SELECTED' ;
4142 $selected { 'PROTOCOL' }{ 'udp' } = '' ;
4143 $selected { 'PROTOCOL' }{ 'tcp' } = '' ;
4144 $selected { 'PROTOCOL' }{ $cgiparams { 'PROTOCOL' }} = 'SELECTED' ;
4147 $checked { 'AUTH' }{ 'psk' } = '' ;
4148 $checked { 'AUTH' }{ 'certreq' } = '' ;
4149 $checked { 'AUTH' }{ 'certgen' } = '' ;
4150 $checked { 'AUTH' }{ 'certfile' } = '' ;
4151 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = 'CHECKED' ;
4153 $selected { 'INTERFACE' }{ $cgiparams { 'INTERFACE' }} = 'SELECTED' ;
4155 $checked { 'COMPLZO' }{ 'off' } = '' ;
4156 $checked { 'COMPLZO' }{ 'on' } = '' ;
4157 $checked { 'COMPLZO' }{ $cgiparams { 'COMPLZO' }} = 'CHECKED' ;
4159 $checked { 'MSSFIX' }{ 'off' } = '' ;
4160 $checked { 'MSSFIX' }{ 'on' } = '' ;
4161 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
4163 $checked { 'PMTU_DISCOVERY' }{ $cgiparams { 'PMTU_DISCOVERY' }} = 'checked= \' checked \' ' ;
4167 & Header
:: showhttpheaders
();
4168 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
4169 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
4170 if ( $errormessage ) {
4171 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
4172 print "<class name='base'> $errormessage " ;
4173 print " </class>" ;
4174 & Header
:: closebox
();
4178 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'warning messages'}:" );
4179 print "<class name='base'> $warnmessage " ;
4180 print " </class>" ;
4181 & Header
:: closebox
();
4184 print "<form method='post' enctype='multipart/form-data'>" ;
4185 print "<input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />" ;
4187 if ( $cgiparams { 'KEY' }) {
4188 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
4189 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
4192 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'connection'}:" );
4193 print "<table width='100%' border='0'> \n " ;
4197 print "<tr><td width='14%' class='boldbase'> $Lang ::tr{'name'}: </td>" ;
4199 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4200 if ( $cgiparams { 'KEY' }) {
4201 print "<td width='35%' class='base'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /> $cgiparams {'NAME'}</td>" ;
4204 print "<td width='35%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' maxlength='20' size='30' /></td>" ;
4206 # print "<tr><td>$Lang::tr{'interface'}</td>";
4207 # print "<td><select name='INTERFACE'>";
4208 # print "<option value='RED' $selected{'INTERFACE'}{'RED'}>RED</option>";
4209 # if ($netsettings{'BLUE_DEV'} ne '') {
4210 # print "<option value='BLUE' $selected{'INTERFACE'}{'BLUE'}>BLUE</option>";
4212 # print "<option value='GREEN' $selected{'INTERFACE'}{'GREEN'}>GREEN</option>";
4213 # print "<option value='ORANGE' $selected{'INTERFACE'}{'ORANGE'}>ORANGE</option>";
4214 # print "</select></td></tr>";
4217 print "<input type='hidden' name='INTERFACE' value='red' />" ;
4218 if ( $cgiparams { 'KEY' }) {
4219 print "<td width='25%' class='base' nowrap='nowrap'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /> $cgiparams {'NAME'}</td>" ;
4221 print "<td width='25%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' maxlength='20' /></td>" ;
4227 <td width='25%'> </td>
4228 <td width='25%'> </td></tr>
4229 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'Act as'}</td>
4230 <td><select name='SIDE'><option value='server' $selected {'SIDE'}{'server'}> $Lang ::tr{'openvpn server'}</option>
4231 <option value='client' $selected {'SIDE'}{'client'}> $Lang ::tr{'openvpn client'}</option></select></td>
4232 <td class='boldbase'> $Lang ::tr{'remote host/ip'}:</td>
4233 <td><input type='TEXT' name='REMOTE' value=' $cgiparams {'REMOTE'}' /></td></tr>
4234 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'}</td>
4235 <td><input type='TEXT' name='LOCAL_SUBNET' value=' $cgiparams {'LOCAL_SUBNET'}' /></td>
4236 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'}</td>
4237 <td><input type='text' name='REMOTE_SUBNET' value=' $cgiparams {'REMOTE_SUBNET'}' /></td></tr>
4238 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn subnet'}</td>
4239 <td><input type='TEXT' name='OVPN_SUBNET' value=' $cgiparams {'OVPN_SUBNET'}' /></td></tr>
4240 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td>
4242 <td><select name='PROTOCOL'><option value='udp' $selected {'PROTOCOL'}{'udp'}>UDP</option>
4243 <option value='tcp' $selected {'PROTOCOL'}{'tcp'}>TCP</option></select></td>
4245 <td class='boldbase'> $Lang ::tr{'destination port'}:</td>
4246 <td><input type='TEXT' name='DEST_PORT' value=' $cgiparams {'DEST_PORT'}' size='5' /></td></tr>
4247 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'} <img src='/blob.gif'</td>
4248 <td><input type='checkbox' name='COMPLZO' $checked {'COMPLZO'}{'on'} /></td>
4250 <tr><td class='boldbase' nowrap='nowrap'>mssfix <img src='/blob.gif' /></td>
4251 <td><input type='checkbox' name='MSSFIX' $checked {'MSSFIX'}{'on'} /></td>
4252 <td> $Lang ::tr{'openvpn default'}: <span class="base">on</span></td>
4254 <tr><td class='boldbase' nowrap='nowrap'>fragment <img src='/blob.gif' /></td>
4255 <td><input type='TEXT' name='FRAGMENT' VALUE=' $cgiparams {'FRAGMENT'}'size='5' /></td>
4256 <td> $Lang ::tr{'openvpn default'}: <span class="base">1300</span></td>
4258 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'} <img src='/blob.gif' /></td>
4259 <td> <input type='TEXT' name='MTU' VALUE=' $cgiparams {'MTU'}'size='5' /></td>
4260 <td colspan='2'> $Lang ::tr{'openvpn default'}: udp/tcp <span class="base">1500/1400</span></td>
4262 <tr><td class='boldbase' nowrap='nowrap'>Management Port <img src='/blob.gif' /></td>
4263 <td> <input type='TEXT' name='OVPN_MGMT' VALUE=' $cgiparams {'OVPN_MGMT'}'size='5' /></td>
4264 <td colspan='2'> $Lang ::tr{'openvpn default'}: <span class="base"> $Lang ::tr{'destination port'}</span></td>
4267 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn mtu-disc'}</td>
4269 <input type='radio' name='PMTU_DISCOVERY' value='yes' $checked {'PMTU_DISCOVERY'}{'yes'} /> $Lang ::tr{'ovpn mtu-disc yes'}
4270 <input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked {'PMTU_DISCOVERY'}{'maybe'} /> $Lang ::tr{'ovpn mtu-disc maybe'}
4271 <input type='radio' name='PMTU_DISCOVERY' value='no' $checked {'PMTU_DISCOVERY'}{'no'} /> $Lang ::tr{'ovpn mtu-disc no'}
4272 <input type='radio' name='PMTU_DISCOVERY' value='off' $checked {'PMTU_DISCOVERY'}{'off'} /> $Lang ::tr{'ovpn mtu-disc off'}
4280 print "<tr><td class='boldbase'> $Lang ::tr{'remark title'} <img src='/blob.gif' /></td>" ;
4281 print "<td colspan='3'><input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' size='55' maxlength='50' /></td></tr></table>" ;
4283 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4284 print "<tr><td> $Lang ::tr{'enabled'} <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>" ;
4287 print "</tr></table><br><br>" ;
4288 #A.Marx CCD new client
4289 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4290 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>" ;
4293 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnnet );
4294 $vpnip = $vpnnet { 'DOVPN_SUBNET' };
4295 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
4299 $checked { 'check1' }{ 'off' } = '' ;
4300 $checked { 'check1' }{ 'on' } = '' ;
4301 $checked { 'check1' }{ $cgiparams { 'CHECK1' }} = 'CHECKED' ;
4302 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%'>" ;
4303 print "</td></tr></table><br><br>" ;
4304 my $name = $cgiparams { 'CHECK1' };
4305 $checked { 'RG' }{ $cgiparams { 'RG' }} = 'CHECKED' ;
4307 if (! - z
"${General::swroot}/ovpn/ccd.conf" ){
4308 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>" ;
4309 foreach my $key ( sort { uc ( $ccdconfhash { $a }[ 0 ]) cmp uc ( $ccdconfhash { $b }[ 0 ]) } keys %ccdconfhash ) {
4311 @ccdconf =( $ccdconfhash { $key }[ 0 ], $ccdconfhash { $key }[ 1 ]);
4312 if ( $count % 2 ){ print "<tr bgcolor=' $color {'color22'}'>" ;} else { print "<tr bgcolor=' $color {'color20'}'>" ;}
4313 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%'>" ;
4314 & fillselectbox
( $ccdconf [ 1 ], $ccdconf [ 0 ], $cgiparams { $name });
4317 print "</table><br><br><hr><br><br>" ;
4321 & Header
:: closebox
();
4322 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
4324 } elsif (! $cgiparams { 'KEY' }) {
4328 my $cakeydisabled = '' ;
4329 my $cacrtdisabled = '' ;
4330 if ( ! - f
"${General::swroot}/ovpn/ca/cakey.pem" ) { $cakeydisabled = "disabled='disabled'" } else { $cakeydisabled = "" };
4331 if ( ! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) { $cacrtdisabled = "disabled='disabled'" } else { $cacrtdisabled = "" };
4333 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'authentication' });
4336 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4339 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
4341 <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>
4342 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td><td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
4343 <tr><td colspan='3'> </td></tr>
4344 <tr><td colspan='3'><hr /></td></tr>
4345 <tr><td colspan='3'> </td></tr>
4346 <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>
4347 <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>
4348 <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>
4349 <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>
4350 <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>
4351 <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>
4352 <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>
4353 <tr><td> </td><td class='base'> $Lang ::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
4364 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
4366 <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>
4367 <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>
4368 <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>
4369 <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>
4370 <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>
4371 <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>
4372 <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>
4373 <tr><td> </td><td class='base'> $Lang ::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
4385 foreach my $country ( sort keys %{ Countries
:: countries
}) {
4386 print "<option value=' $Countries ::countries{ $country }'" ;
4387 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
4388 print " selected='selected'" ;
4390 print "> $country </option>" ;
4396 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4400 <td> </td><td class='base'> $Lang ::tr{'valid till'} (days):</td>
4401 <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value=' $cgiparams {'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr>
4403 <td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
4404 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
4405 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'}:<BR>( $Lang ::tr{'confirmation'})</td>
4406 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
4407 <tr><td colspan='3'> </td></tr>
4408 <tr><td colspan='3'><hr /></td></tr>
4409 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
4415 <tr><td> </td><td> </td><td> </td></tr>
4416 <tr><td> </td><td> </td><td> </td></tr>
4417 <tr><td colspan='3'><hr /></td></tr>
4418 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
4428 & Header
:: closebox
();
4432 #A.Marx CCD new client
4433 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4435 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'ccd client options'}:" );
4439 <table border='0' width='100%'>
4440 <tr><td width='20%'>Redirect Gateway:</td><td colspan='3'><input type='checkbox' name='RG' $checked {'RG'}{'on'} /></td></tr>
4441 <tr><td colspan='4'><b><br> $Lang ::tr{'ccd routes'}</b></td></tr>
4442 <tr><td colspan='4'> </td></tr>
4443 <tr><td valign='top'> $Lang ::tr{'ccd iroute'}</td><td align='left' width='30%'><textarea name='IR' cols='26' rows='6' wrap='off'>
4446 if ( $cgiparams { 'IR' } ne '' ){
4447 print $cgiparams { 'IR' };
4449 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
4450 foreach my $key ( keys %ccdroutehash ) {
4451 if ( $cgiparams { 'NAME' } eq $ccdroutehash { $key }[ 0 ]){
4452 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}) {
4453 if ( $ccdroutehash { $key }[ $i ] ne '' ){
4454 print $ccdroutehash { $key }[ $i ]. " \n " ;
4456 $cgiparams { 'IR' } .= $ccdroutehash { $key }[ $i ];
4463 </textarea></td><td valign='top' colspan='2'> $Lang ::tr{'ccd iroutehint'}</td></tr>
4464 <tr><td colspan='4'><br></td></tr>
4465 <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>
4479 open ( FILE
, "${General::swroot}/main/routing" ) ;
4482 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
4484 foreach my $key ( keys %ccdroute2hash ) {
4485 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4486 if ( $ccdroute2hash { $key }[ 1 ] eq '' ){
4493 print "<option> $Lang ::tr{'ccd none'}</option>" ;
4495 print "<option selected> $Lang ::tr{'ccd none'}</option>" ;
4497 #check if static routes are defined for client
4498 foreach my $line ( @current ) {
4500 $line =~ s/\s*$//g ; # remove newline
4501 @temp = split ( /\,/ , $line );
4502 $temp [ 1 ] = '' unless defined $temp [ 1 ]; # not always populated
4503 my ( $a , $b ) = split ( /\/ /, $temp [ 1 ]);
4504 $temp [ 1 ] = $a . "/" .& General
:: iporsubtocidr
( $b );
4505 foreach my $key ( keys %ccdroute2hash ) {
4506 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4507 foreach my $i ( 1 .. $ #{$ccdroute2hash{$key}}) {
4508 if ( $ccdroute2hash { $key }[ $i ] eq $a . "/" .& General
:: iporsubtodec
( $b )){
4514 if ( $set == '1' && $#temp != - 1 ){ print "<option selected> $temp [1]</option>" ; $set = 0 ;} elsif ( $set == '0' && $#temp != - 1 ){ print "<option> $temp [1]</option>" ;}
4516 #check if green,blue,orange are defined for client
4517 foreach my $key ( keys %ccdroute2hash ) {
4518 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4520 foreach my $i ( 1 .. $ #{$ccdroute2hash{$key}}) {
4521 if ( $ccdroute2hash { $key }[ $i ] eq $netsettings { 'GREEN_NETADDRESS' }. "/" .& General
:: iporsubtodec
( $netsettings { 'GREEN_NETMASK' })){
4524 if (& haveBlueNet
()){
4525 if ( $ccdroute2hash { $key }[ $i ] eq $netsettings { 'BLUE_NETADDRESS' }. "/" .& General
:: iporsubtodec
( $netsettings { 'BLUE_NETMASK' })) {
4529 if (& haveOrangeNet
()){
4530 if ( $ccdroute2hash { $key }[ $i ] eq $netsettings { 'ORANGE_NETADDRESS' }. "/" .& General
:: iporsubtodec
( $netsettings { 'ORANGE_NETMASK' }) ) {
4537 if (& haveBlueNet
() && $selblue == '1' ){ print "<option selected> $Lang ::tr{'blue'}</option>" ; $selblue = 0 ;} elsif (& haveBlueNet
() && $selblue == '0' ){ print "<option> $Lang ::tr{'blue'}</option>" ;}
4538 if (& haveOrangeNet
() && $selorange == '1' ){ print "<option selected> $Lang ::tr{'orange'}</option>" ; $selorange = 0 ;} elsif (& haveOrangeNet
() && $selorange == '0' ){ print "<option> $Lang ::tr{'orange'}</option>" ;}
4539 if ( $selgreen == '1' || $other == '0' ){ print "<option selected> $Lang ::tr{'green'}</option>" ; $set = 0 ;} else { print "<option> $Lang ::tr{'green'}</option>" ;};
4542 </select></td><td valign='top'>DNS1:</td><td valign='top'><input type='TEXT' name='CCD_DNS1' value=' $cgiparams {'CCD_DNS1'}' size='30' /></td></tr>
4543 <tr valign='top'><td>DNS2:</td><td><input type='TEXT' name='CCD_DNS2' value=' $cgiparams {'CCD_DNS2'}' size='30' /></td></tr>
4544 <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>
4548 & Header
:: closebox
();
4550 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
4551 if ( $cgiparams { 'KEY' }) {
4552 # print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />";
4554 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
4555 & Header
:: closebigbox
();
4556 & Header
:: closepage
();
4564 ### Default status page
4569 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%cgiparams );
4570 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
4571 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
4573 my @status = `/bin/cat /var/log/ovpnserver.log` ;
4575 if ( $cgiparams { 'VPN_IP' } eq '' && - e
"${General::swroot}/red/active" ) {
4576 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
4577 my $ipaddr = < IPADDR
>;
4580 $cgiparams { 'VPN_IP' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
4581 if ( $cgiparams { 'VPN_IP' } eq '' ) {
4582 $cgiparams { 'VPN_IP' } = $ipaddr ;
4588 if ( $cgiparams { 'DCIPHER' } eq '' ) {
4589 $cgiparams { 'DCIPHER' } = 'BF-CBC' ;
4591 if ( $cgiparams { 'DDEST_PORT' } eq '' ) {
4592 $cgiparams { 'DDEST_PORT' } = '1194' ;
4594 if ( $cgiparams { 'DMTU' } eq '' ) {
4595 $cgiparams { 'DMTU' } = '1400' ;
4597 if ( $cgiparams { 'DOVPN_SUBNET' } eq '' ) {
4598 $cgiparams { 'DOVPN_SUBNET' } = '10.' . int ( rand ( 256 )) . '.' . int ( rand ( 256 )) . '.0/255.255.255.0' ;
4600 $checked { 'ENABLED' }{ 'off' } = '' ;
4601 $checked { 'ENABLED' }{ 'on' } = '' ;
4602 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = 'CHECKED' ;
4603 $checked { 'ENABLED_BLUE' }{ 'off' } = '' ;
4604 $checked { 'ENABLED_BLUE' }{ 'on' } = '' ;
4605 $checked { 'ENABLED_BLUE' }{ $cgiparams { 'ENABLED_BLUE' }} = 'CHECKED' ;
4606 $checked { 'ENABLED_ORANGE' }{ 'off' } = '' ;
4607 $checked { 'ENABLED_ORANGE' }{ 'on' } = '' ;
4608 $checked { 'ENABLED_ORANGE' }{ $cgiparams { 'ENABLED_ORANGE' }} = 'CHECKED' ;
4609 $selected { 'DDEVICE' }{ 'tun' } = '' ;
4610 $selected { 'DDEVICE' }{ 'tap' } = '' ;
4611 $selected { 'DDEVICE' }{ $cgiparams { 'DDEVICE' }} = 'SELECTED' ;
4613 $selected { 'DPROTOCOL' }{ 'udp' } = '' ;
4614 $selected { 'DPROTOCOL' }{ 'tcp' } = '' ;
4615 $selected { 'DPROTOCOL' }{ $cgiparams { 'DPROTOCOL' }} = 'SELECTED' ;
4617 $selected { 'DCIPHER' }{ 'DES-CBC' } = '' ;
4618 $selected { 'DCIPHER' }{ 'DES-EDE-CBC' } = '' ;
4619 $selected { 'DCIPHER' }{ 'DES-EDE3-CBC' } = '' ;
4620 $selected { 'DCIPHER' }{ 'DESX-CBC' } = '' ;
4621 $selected { 'DCIPHER' }{ 'RC2-CBC' } = '' ;
4622 $selected { 'DCIPHER' }{ 'RC2-40-CBC' } = '' ;
4623 $selected { 'DCIPHER' }{ 'RC2-64-CBC' } = '' ;
4624 $selected { 'DCIPHER' }{ 'BF-CBC' } = '' ;
4625 $selected { 'DCIPHER' }{ 'CAST5-CBC' } = '' ;
4626 $selected { 'DCIPHER' }{ 'AES-128-CBC' } = '' ;
4627 $selected { 'DCIPHER' }{ 'AES-192-CBC' } = '' ;
4628 $selected { 'DCIPHER' }{ 'AES-256-CBC' } = '' ;
4629 $selected { 'DCIPHER' }{ $cgiparams { 'DCIPHER' }} = 'SELECTED' ;
4630 $checked { 'DCOMPLZO' }{ 'off' } = '' ;
4631 $checked { 'DCOMPLZO' }{ 'on' } = '' ;
4632 $checked { 'DCOMPLZO' }{ $cgiparams { 'DCOMPLZO' }} = 'CHECKED' ;
4634 $checked { 'MSSFIX' }{ 'off' } = '' ;
4635 $checked { 'MSSFIX' }{ 'on' } = '' ;
4636 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
4638 & Header
:: showhttpheaders
();
4639 & Header
:: openpage
( $Lang :: tr
{ 'status ovpn' }, 1 , '' );
4640 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
4642 if ( $errormessage ) {
4643 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
4644 print "<class name='base'> $errormessage \n " ;
4645 print " </class> \n " ;
4646 & Header
:: closebox
();
4649 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>" ;
4650 my $srunning = "no" ;
4651 my $activeonrun = "" ;
4652 if ( - e
"/var/run/openvpn.pid" ){
4653 $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>" ;
4657 $activeonrun = "disabled='disabled'" ;
4659 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'global settings' });
4661 <table width='100%' border=0>
4662 <form method='post'>
4663 <td width='25%'> </td>
4664 <td width='25%'> </td>
4665 <td width='25%'> </td></tr>
4666 <tr><td class='boldbase'> $Lang ::tr{'ovpn server status'}</td>
4667 <td align='left'> $sactive </td>
4668 <tr><td class='boldbase'> $Lang ::tr{'ovpn on red'}</td>
4669 <td><input type='checkbox' name='ENABLED' $checked {'ENABLED'}{'on'} /></td>
4672 if (& haveBlueNet
()) {
4673 print "<tr><td class='boldbase'> $Lang ::tr{'ovpn on blue'}</td>" ;
4674 print "<td><input type='checkbox' name='ENABLED_BLUE' $checked {'ENABLED_BLUE'}{'on'} /></td>" ;
4676 if (& haveOrangeNet
()) {
4677 print "<tr><td class='boldbase'> $Lang ::tr{'ovpn on orange'}</td>" ;
4678 print "<td><input type='checkbox' name='ENABLED_ORANGE' $checked {'ENABLED_ORANGE'}{'on'} /></td>" ;
4681 <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>
4682 <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>
4683 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn device'}</td>
4684 <td><select name='DDEVICE' ><option value='tun' $selected {'DDEVICE'}{'tun'}>TUN</option>
4685 <!-- this is still not working
4686 <option value='tap' $selected {'DDEVICE'}{'tap'}>TAP</option></select>--> </td>
4687 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td>
4688 <td><select name='DPROTOCOL'><option value='udp' $selected {'DPROTOCOL'}{'udp'}>UDP</option>
4689 <option value='tcp' $selected {'DPROTOCOL'}{'tcp'}>TCP</option></select></td>
4690 <td class='boldbase'> $Lang ::tr{'destination port'}:</td>
4691 <td><input type='TEXT' name='DDEST_PORT' value=' $cgiparams {'DDEST_PORT'}' size='5' /></td></tr>
4692 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'} </td>
4693 <td> <input type='TEXT' name='DMTU' VALUE=' $cgiparams {'DMTU'}'size='5' /></TD>
4694 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'}</td>
4695 <td><input type='checkbox' name='DCOMPLZO' $checked {'DCOMPLZO'}{'on'} /></td>
4696 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'cipher'}</td>
4697 <td><select name='DCIPHER'><option value='DES-CBC' $selected {'DCIPHER'}{'DES-CBC'}>DES-CBC</option>
4698 <option value='DES-EDE-CBC' $selected {'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC</option>
4699 <option value='DES-EDE3-CBC' $selected {'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC</option>
4700 <option value='DESX-CBC' $selected {'DCIPHER'}{'DESX-CBC'}>DESX-CBC</option>
4701 <option value='RC2-CBC' $selected {'DCIPHER'}{'RC2-CBC'}>RC2-CBC</option>
4702 <option value='RC2-40-CBC' $selected {'DCIPHER'}{'RC2-40-CBC'}>RC2-40-CBC</option>
4703 <option value='RC2-64-CBC' $selected {'DCIPHER'}{'RC2-64-CBC'}>RC2-64-CBC</option>
4704 <option value='BF-CBC' $selected {'DCIPHER'}{'BF-CBC'}>BF-CBC</option>
4705 <option value='CAST5-CBC' $selected {'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC</option>
4706 <option value='AES-128-CBC' $selected {'DCIPHER'}{'AES-128-CBC'}>AES-128-CBC</option>
4707 <option value='AES-192-CBC' $selected {'DCIPHER'}{'AES-192-CBC'}>AES-192-CBC</option>
4708 <option value='AES-256-CBC' $selected {'DCIPHER'}{'AES-256-CBC'}>AES-256-CBC</option></select></td></tr>
4709 <tr><td colspan='4'><hr /></td></tr>
4713 if ( $srunning eq "yes" ) {
4714 print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' disabled='disabled' />" ;
4715 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'ccd net'}' />" ;
4716 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced server'}' />" ;
4717 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'stop ovpn server'}' /></td></tr>" ;
4719 print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
4720 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'ccd net'}' />" ;
4721 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced server'}' />" ;
4722 if (( - e
"${General::swroot}/ovpn/ca/cacert.pem" &&
4723 - e
"${General::swroot}/ovpn/ca/dh1024.pem" &&
4724 - e
"${General::swroot}/ovpn/certs/servercert.pem" &&
4725 - e
"${General::swroot}/ovpn/certs/serverkey.pem" ) &&
4726 (( $cgiparams { 'ENABLED' } eq 'on' ) ||
4727 ( $cgiparams { 'ENABLED_BLUE' } eq 'on' ) ||
4728 ( $cgiparams { 'ENABLED_ORANGE' } eq 'on' ))){
4729 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'start ovpn server'}' /></td></tr>" ;
4731 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'start ovpn server'}' disabled='disabled' /></td></tr>" ;
4734 print "</form></table>" ;
4735 & Header
:: closebox
();
4736 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'certificate authorities'}:" );
4738 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
4740 <td width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></td>
4741 <td width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></td>
4742 <td width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></td>
4746 if (- f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
4747 my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem` ;
4748 $casubject =~ /Subject: (.*)[\n]/ ;
4750 $casubject =~ s
+/ Email
+, E
+;
4751 $casubject =~ s/ ST=/ S=/ ;
4754 <tr bgcolor=' $color {'color22'}'>
4755 <td class='base'> $Lang ::tr{'root certificate'}</td>
4756 <td class='base'> $casubject </td>
4757 <form method='post' name='frmrootcrta'><td width='3%' align='center'>
4758 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
4759 <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' />
4761 <form method='post' name='frmrootcrtb'><td width='3%' align='center'>
4762 <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' />
4763 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
4765 <td width='4%'> </td></tr>
4769 # display rootcert generation buttons
4771 <tr bgcolor=' $color {'color22'}'>
4772 <td class='base'> $Lang ::tr{'root certificate'}:</td>
4773 <td class='base'> $Lang ::tr{'not present'}</td>
4774 <td colspan='3'> </td></tr>
4779 if (- f
"${General::swroot}/ovpn/certs/servercert.pem" ) {
4780 my $hostsubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem` ;
4781 $hostsubject =~ /Subject: (.*)[\n]/ ;
4783 $hostsubject =~ s
+/ Email
+, E
+;
4784 $hostsubject =~ s/ ST=/ S=/ ;
4787 <tr bgcolor=' $color {'color20'}'>
4788 <td class='base'> $Lang ::tr{'host certificate'}</td>
4789 <td class='base'> $hostsubject </td>
4790 <form method='post' name='frmhostcrta'><td width='3%' align='center'>
4791 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
4792 <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' />
4794 <form method='post' name='frmhostcrtb'><td width='3%' align='center'>
4795 <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' />
4796 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download host certificate'}' />
4798 <td width='4%'> </td></tr>
4804 <tr bgcolor=' $color {'color20'}'>
4805 <td width='25%' class='base'> $Lang ::tr{'host certificate'}:</td>
4806 <td class='base'> $Lang ::tr{'not present'}</td>
4807 </td><td colspan='3'> </td></tr>
4812 if (! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
4813 print "<tr><td colspan='5' align='center'><form method='post'>" ;
4814 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' />" ;
4815 print "</form></td></tr> \n " ;
4818 if ( keys %cahash > 0 ) {
4819 foreach my $key ( keys %cahash ) {
4820 if (( $key + 1 ) % 2 ) {
4821 print "<tr bgcolor=' $color {'color20'}'> \n " ;
4823 print "<tr bgcolor=' $color {'color22'}'> \n " ;
4825 print "<td class='base'> $cahash { $key }[0]</td> \n " ;
4826 print "<td class='base'> $cahash { $key }[1]</td> \n " ;
4828 <form method='post' name='cafrm${key}a'><td align='center'>
4829 <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' />
4830 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
4831 <input type='hidden' name='KEY' value=' $key ' />
4833 <form method='post' name='cafrm${key}b'><td align='center'>
4834 <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' />
4835 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
4836 <input type='hidden' name='KEY' value=' $key ' />
4838 <form method='post' name='cafrm${key}c'><td align='center'>
4839 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
4840 <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' />
4841 <input type='hidden' name='KEY' value=' $key ' />
4850 # If the file contains entries, print Key to action icons
4851 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
4855 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
4856 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
4857 <td class='base'> $Lang ::tr{'show certificate'}</td>
4858 <td> <img src='/images/media-floppy.png' alt=' $Lang ::tr{'download certificate'}' /></td>
4859 <td class='base'> $Lang ::tr{'download certificate'}</td>
4867 <form method='post' enctype='multipart/form-data'>
4868 <table width='100%' border='0'>
4869 <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>
4870 <tr><td colspan='4'><hr /></td></tr>
4871 <tr align='right'><td colspan='4' align='right' width='80%'><input type='submit' name='ACTION' value=' $Lang ::tr{'show crl'}' /></td></tr>
4877 & Header
:: closebox
();
4878 if ( $srunning eq "yes" ) {
4879 print "<div align='center'><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'reset'}' disabled='disabled' /></div></form> \n " ;
4881 print "<div align='center'><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'reset'}' /></div></form> \n " ;
4883 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
4887 #<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>
4890 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'Client status and controlc' });
4894 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
4896 <td width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></td>
4897 <td width='15%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></td>
4898 <td width='22%' class='boldbase' align='center'><b> $Lang ::tr{'network'}</b></td>
4899 <td width='20%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></td>
4900 <td width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></td>
4901 <td width='5%' class='boldbase' colspan='6' align='center'><b> $Lang ::tr{'action'}</b></td>
4907 foreach my $key ( sort { uc ( $confighash { $a }[ 1 ]) cmp uc ( $confighash { $b }[ 1 ]) } keys %confighash ) {
4908 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
4911 print "<tr bgcolor=' $color {'color20'}'> \n " ;
4913 print "<tr bgcolor=' $color {'color22'}'> \n " ;
4915 print "<td align='center' nowrap='nowrap'> $confighash { $key }[1]</td>" ;
4916 print "<td align='center' nowrap='nowrap'>" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ")</td>" ;
4917 #if ($confighash{$key}[4] eq 'cert') {
4918 #print "<td align='left' nowrap='nowrap'>$confighash{$key}[2]</td>";
4920 #print "<td align='left'> </td>";
4922 my $cavalid = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $confighash { $key }[1]cert.pem` ;
4923 $cavalid =~ /Not After : (.*)[\n]/ ;
4925 if ( $confighash { $key }[ 32 ] eq "" && $confighash { $key }[ 3 ] eq 'net' ){ $confighash { $key }[ 32 ]= "net-2-net" ;}
4926 if ( $confighash { $key }[ 32 ] eq "" && $confighash { $key }[ 3 ] eq 'host' ){ $confighash { $key }[ 32 ]= "dynamic" ;}
4927 print "<td align='center'> $confighash { $key }[32]</td>" ;
4928 print "<td align='center'> $confighash { $key }[25]</td>" ;
4930 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>" ;
4932 if ( $confighash { $key }[ 0 ] eq 'off' ) {
4933 $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>" ;
4940 if ( $confighash { $key }[ 3 ] eq 'net' ) {
4942 if (- e
"/var/run/ $confighash { $key }[1]n2n.pid" ) {
4945 my $tport = $confighash { $key }[ 22 ];
4946 my $tnet = new Net
:: Telnet
( Timeout
=> 5 , Errmode
=> 'return' , Port
=> $tport );
4948 $tnet -> open ( '127.0.0.1' );
4949 @output = $tnet -> cmd ( String
=> 'state' , Prompt
=> '/(END.* \n |ERROR:.* \n )/' );
4950 @tustate = split ( /\,/ , $output [ 1 ]);
4952 #CONNECTING -- OpenVPN's initial state.
4953 #WAIT -- (Client only) Waiting for initial response from server.
4954 #AUTH -- (Client only) Authenticating with server.
4955 #GET_CONFIG -- (Client only) Downloading configuration options from server.
4956 #ASSIGN_IP -- Assigning IP address to virtual network interface.
4957 #ADD_ROUTES -- Adding routes to system.
4958 #CONNECTED -- Initialization Sequence Completed.
4959 #RECONNECTING -- A restart has occurred.
4960 #EXITING -- A graceful exit is in progress.
4963 if ( $tustate [ 1 ] eq 'CONNECTED' ) {
4964 $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>" ;
4966 $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>" ;
4974 foreach my $line ( @status ) {
4976 if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ ) {
4977 @match = split ( m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ , $line );
4978 if ( $match [ 1 ] ne "Common Name" ) {
4982 if ( $cn eq " $confighash { $key }[2]" ) {
4983 $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>" ;
4992 my $disable_clientdl = "disabled='disabled'" ;
4993 if (( $cgiparams { 'ENABLED' } eq 'on' ) ||
4994 ( $cgiparams { 'ENABLED_BLUE' } eq 'on' ) ||
4995 ( $cgiparams { 'ENABLED_ORANGE' } eq 'on' )){
4996 $disable_clientdl = "" ;
4999 <td align='center'> $active </td>
5001 <form method='post' name='frm${key}a'><td align='center'>
5002 <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' />
5003 <input type='hidden' name='ACTION' value=' $Lang ::tr{'dl client arch'}' $disable_clientdl />
5004 <input type='hidden' name='KEY' value=' $key ' $disable_clientdl />
5008 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
5010 <form method='post' name='frm${key}b'><td align='center'>
5011 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' border='0' />
5012 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
5013 <input type='hidden' name='KEY' value=' $key ' />
5017 print "<td> </td>" ;
5019 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $key }[1].p12" ) {
5021 <form method='post' name='frm${key}c'><td align='center'>
5022 <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' />
5023 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
5024 <input type='hidden' name='KEY' value=' $key ' />
5027 ; } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
5029 <form method='post' name='frm${key}c'><td align='center'>
5030 <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' />
5031 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
5032 <input type='hidden' name='KEY' value=' $key ' />
5036 print "<td> </td>" ;
5039 <form method='post' name='frm${key}d'><td align='center'>
5040 <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' />
5041 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
5042 <input type='hidden' name='KEY' value=' $key ' />
5045 <form method='post' name='frm${key}e'><td align='center'>
5046 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
5047 <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'/>
5048 <input type='hidden' name='KEY' value=' $key ' />
5050 <form method='post' name='frm${key}f'><td align='center'>
5051 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
5052 <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' />
5053 <input type='hidden' name='KEY' value=' $key ' />
5062 # If the config file contains entries, print Key to action icons
5067 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
5068 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
5069 <td class='base'> $Lang ::tr{'click to disable'}</td>
5070 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
5071 <td class='base'> $Lang ::tr{'show certificate'}</td>
5072 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
5073 <td class='base'> $Lang ::tr{'edit'}</td>
5074 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
5075 <td class='base'> $Lang ::tr{'remove'}</td>
5079 <td> <img src='/images/off.gif' alt='?OFF' /></td>
5080 <td class='base'> $Lang ::tr{'click to enable'}</td>
5081 <td> <img src='/images/media-floppy.png' alt='?FLOPPY' /></td>
5082 <td class='base'> $Lang ::tr{'download certificate'}</td>
5083 <td> <img src='/images/openvpn.png' alt='?RELOAD'/></td>
5084 <td class='base'> $Lang ::tr{'dl client arch'}</td>
5092 <table width='100%'>
5093 <form method='post'>
5094 <tr><td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />
5095 <input type='submit' name='ACTION' value=' $Lang ::tr{'ovpn con stat'}' $activeonrun /></td></tr>
5100 & Header
:: closebox
();
5102 & Header
:: closepage
();