]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/ovpnmain.cgi
5afe54f5583d21aa17b58eece5d5b00212ff0613
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2023 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 ###############################################################################
23 use CGI qw
/:standard/ ;
27 use URI
:: Encode
qw(uri_encode uri_decode) ;;
32 use File
:: Temp qw
/ tempfile tempdir / ;
34 use Archive
:: Zip
qw(:ERROR_CODES :CONSTANTS) ;
37 require '/var/ipfire/general-functions.pl' ;
38 require "${General::swroot}/lang.pl" ;
39 require "${General::swroot}/header.pl" ;
40 require "${General::swroot}/countries.pl" ;
41 require "${General::swroot}/location-functions.pl" ;
43 # enable only the following on debugging purpose
45 #use CGI::Carp 'fatalsToBrowser';
47 #workaround to suppress a warning when a variable is used only once
48 my @dummy = ( ${ Header
:: colourgreen
}, ${ Header
:: colourblue
} );
52 my %mainsettings = ();
53 & General
:: readhash
( "${General::swroot}/main/settings" , \
%mainsettings );
54 & General
:: readhash
( "/srv/web/ipfire/html/themes/ipfire/include/colors.txt" , \
%color );
57 ### Initialize variables
70 my $errormessage = '' ;
72 my $cryptowarning = '' ;
74 my $routes_push_file = '' ;
75 my $confighost = "${General::swroot}/fwhosts/customhosts" ;
76 my $configgrp = "${General::swroot}/fwhosts/customgroups" ;
77 my $customnet = "${General::swroot}/fwhosts/customnetworks" ;
80 my $local_serverconf = "${General::swroot}/ovpn/scripts/server.conf.local" ;
81 my $local_clientconf = "${General::swroot}/ovpn/scripts/client.conf.local" ;
82 my $dhparameter = "/etc/ssl/ffdhe4096.pem" ;
84 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%netsettings );
85 $cgiparams { 'ENABLED' } = 'off' ;
86 $cgiparams { 'ENABLED_BLUE' } = 'off' ;
87 $cgiparams { 'ENABLED_ORANGE' } = 'off' ;
88 $cgiparams { 'EDIT_ADVANCED' } = 'off' ;
89 $cgiparams { 'NAT' } = 'off' ;
90 $cgiparams { 'COMPRESSION' } = 'off' ;
91 $cgiparams { 'ONLY_PROPOSED' } = 'off' ;
92 $cgiparams { 'ACTION' } = '' ;
93 $cgiparams { 'CA_NAME' } = '' ;
94 $cgiparams { 'DHCP_DOMAIN' } = '' ;
95 $cgiparams { 'DHCP_DNS' } = '' ;
96 $cgiparams { 'DHCP_WINS' } = '' ;
97 $cgiparams { 'ROUTES_PUSH' } = '' ;
98 $cgiparams { 'DCOMPLZO' } = 'off' ;
99 $cgiparams { 'MSSFIX' } = '' ;
100 $cgiparams { 'number' } = '' ;
101 $cgiparams { 'DCIPHER' } = '' ;
102 $cgiparams { 'DAUTH' } = '' ;
103 $cgiparams { 'TLSAUTH' } = '' ;
104 $routes_push_file = "${General::swroot}/ovpn/routes_push" ;
105 # Perform crypto and configration test
108 # Add CCD files if not already presant
109 unless (- e
$routes_push_file ) {
110 open ( RPF
, "> $routes_push_file " );
113 unless (- e
"${General::swroot}/ovpn/ccd.conf" ) {
114 open ( CCDC
, ">${General::swroot}/ovpn/ccd.conf" );
117 unless (- e
"${General::swroot}/ovpn/ccdroute" ) {
118 open ( CCDR
, ">${General::swroot}/ovpn/ccdroute" );
121 unless (- e
"${General::swroot}/ovpn/ccdroute2" ) {
122 open ( CCDRT
, ">${General::swroot}/ovpn/ccdroute2" );
125 # Add additional configs if not already presant
126 unless (- e
" $local_serverconf " ) {
127 open ( LSC
, "> $local_serverconf " );
130 unless (- e
" $local_clientconf " ) {
131 open ( LCC
, "> $local_clientconf " );
135 & Header
:: getcgihash
( \
%cgiparams , { 'wantfile' => 1 , 'filevar' => 'FH' });
137 # prepare openvpn config file
144 my @certinfo = & General
:: system_output
( "/usr/bin/openssl" , "pkcs12" , "-info" , "-nodes" ,
145 "-in" , " $file .p12" , "-noout" , "-passin" , "pass:''" );
146 if ( index ( $certinfo [ 0 ], "MAC: sha1" ) != - 1 ) {
154 if ( $netsettings { 'CONFIG_TYPE' } == 2 ) { return 1 ;}
155 if ( $netsettings { 'CONFIG_TYPE' } == 4 ) { return 1 ;}
161 if ( $netsettings { 'CONFIG_TYPE' } == 3 ) { return 1 ;}
162 if ( $netsettings { 'CONFIG_TYPE' } == 4 ) { return 1 ;}
167 my $bytesize = shift ;
170 while ( abs ( $bytesize ) >= 1024 ){
171 $bytesize = $bytesize / 1024 ;
176 my @units = ( "Bytes" , "KB" , "MB" , "GB" , "TB" , "PB" , "EB" );
177 my $newsize =( int ( $bytesize * 100 + 0.5 ))/ 100 ;
178 return ( " $newsize $units [ $i ]" );
183 if ( open ( FILE
, ">${General::swroot}/ovpn/certs/serial" )) {
187 if ( open ( FILE
, ">${General::swroot}/ovpn/certs/index.txt" )) {
191 if ( open ( FILE
, ">${General::swroot}/ovpn/certs/index.txt.attr" )) {
195 unlink ( "${General::swroot}/ovpn/certs/index.txt.old" );
196 unlink ( "${General::swroot}/ovpn/certs/index.txt.attr.old" );
197 unlink ( "${General::swroot}/ovpn/certs/serial.old" );
198 unlink ( "${General::swroot}/ovpn/certs/01.pem" );
201 sub newcleanssldatabase
203 if (! - s
"${General::swroot}/ovpn/certs/serial" ) {
204 open ( FILE
, ">${General::swroot}(ovpn/certs/serial" );
208 if (! - s
">${General::swroot}/ovpn/certs/index.txt" ) {
209 & General
:: system ( "touch" , "${General::swroot}/ovpn/certs/index.txt" );
211 if (! - s
">${General::swroot}/ovpn/certs/index.txt.attr" ) {
212 & General
:: system ( "touch" , "${General::swroot}/ovpn/certs/index.txt.attr" );
214 unlink ( "${General::swroot}/ovpn/certs/index.txt.old" );
215 unlink ( "${General::swroot}/ovpn/certs/index.txt.attr.old" );
216 unlink ( "${General::swroot}/ovpn/certs/serial.old" );
221 if ( open ( FILE
, "${General::swroot}/ovpn/certs/serial.old" )) {
222 my $hexvalue = < FILE
>;
225 unlink ( "${General::swroot}/ovpn/certs/ $hexvalue .pem" );
230 ### Check for PKI and configure problems
235 # Warning if md5 is in usage
236 if (- f
"${General::swroot}/ovpn/certs/servercert.pem" ) {
237 my @signature = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-noout" , "-text" , "-in" , "${General::swroot}/ovpn/certs/servercert.pem" );
238 if ( grep ( /md5WithRSAEncryption/ , @signature ) ) {
239 $cryptoerror = " $Lang ::tr{'ovpn error md5'}" ;
246 # Warning if certificate is not compliant to RFC3280 TLS rules
247 if (- f
"${General::swroot}/ovpn/certs/servercert.pem" ) {
248 my @extendkeyusage = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-noout" , "-text" , "-in" , "${General::swroot}/ovpn/certs/servercert.pem" );
249 if ( ! grep ( /TLS Web Server Authentication/ , @extendkeyusage )) {
250 $cryptowarning = " $Lang ::tr{'ovpn warning rfc3280'}" ;
258 sub writeserverconf
{
259 my %sovpnsettings = ();
261 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%sovpnsettings );
264 open ( CONF
, ">${General::swroot}/ovpn/server.conf" ) or die "Unable to open ${General::swroot}/ovpn/server.conf: $!" ;
266 print CONF
"#OpenVPN Server conf \n " ;
268 print CONF
"daemon openvpnserver \n " ;
269 print CONF
"writepid /var/run/openvpn.pid \n " ;
270 print CONF
"#DAN prepare OpenVPN for listening on blue and orange \n " ;
271 print CONF
";local $sovpnsettings {'VPN_IP'} \n " ;
272 print CONF
"dev tun \n " ;
273 print CONF
"proto $sovpnsettings {'DPROTOCOL'} \n " ;
274 print CONF
"port $sovpnsettings {'DDEST_PORT'} \n " ;
275 print CONF
"script-security 3 \n " ;
276 print CONF
"ifconfig-pool-persist /var/ipfire/ovpn/ovpn-leases.db 3600 \n " ;
277 print CONF
"client-config-dir /var/ipfire/ovpn/ccd \n " ;
278 print CONF
"tls-server \n " ;
279 print CONF
"ca ${General::swroot}/ovpn/ca/cacert.pem \n " ;
280 print CONF
"cert ${General::swroot}/ovpn/certs/servercert.pem \n " ;
281 print CONF
"key ${General::swroot}/ovpn/certs/serverkey.pem \n " ;
282 print CONF
"dh $dhparameter \n " ;
283 my @tempovpnsubnet = split ( "\/" , $sovpnsettings { 'DOVPN_SUBNET' });
284 print CONF
"server $tempovpnsubnet [0] $tempovpnsubnet [1] \n " ;
285 #print CONF "push \"route $netsettings{'GREEN_NETADDRESS'} $netsettings{'GREEN_NETMASK'}\"\n";
287 print CONF
"tun-mtu $sovpnsettings {'DMTU'} \n " ;
289 if ( $vpnsettings { 'ROUTES_PUSH' } ne '' ) {
290 @temp = split ( /\n/ , $vpnsettings { 'ROUTES_PUSH' });
293 @tempovpnsubnet = split ( "\/" ,& General
:: ipcidr2msk
( $_ ));
294 print CONF
"push \" route " . $tempovpnsubnet [ 0 ]. " " . $tempovpnsubnet [ 1 ] . " \"\n " ;
299 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
300 foreach my $key ( keys %ccdconfhash ) {
301 my $a = $ccdconfhash { $key }[ 1 ];
302 my ( $b , $c ) = split ( /\/ /, $a );
303 print CONF
"route $b " .& General
:: cidrtosub
( $c ). " \n " ;
306 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
307 foreach my $key ( keys %ccdroutehash ) {
308 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}){
309 my ( $a , $b )= split ( /\/ /, $ccdroutehash { $key }[ $i ]);
310 print CONF
"route $a $b \n " ;
315 if ( $sovpnsettings { CLIENT2CLIENT
} eq 'on' ) {
316 print CONF
"client-to-client \n " ;
318 if ( $sovpnsettings { MSSFIX
} eq 'on' ) {
319 print CONF
"mssfix \n " ;
321 print CONF
"mssfix 0 \n " ;
323 if ( $sovpnsettings { FRAGMENT
} ne '' && $sovpnsettings { 'DPROTOCOL' } ne 'tcp' ) {
324 print CONF
"fragment $sovpnsettings {'FRAGMENT'} \n " ;
327 if ( $sovpnsettings { KEEPALIVE_1
} > 0 && $sovpnsettings { KEEPALIVE_2
} > 0 ) {
328 print CONF
"keepalive $sovpnsettings {'KEEPALIVE_1'} $sovpnsettings {'KEEPALIVE_2'} \n " ;
330 print CONF
"status-version 1 \n " ;
331 print CONF
"status /var/run/ovpnserver.log 30 \n " ;
332 print CONF
"ncp-disable \n " ;
333 print CONF
"cipher $sovpnsettings {DCIPHER} \n " ;
334 print CONF
"auth $sovpnsettings {'DAUTH'} \n " ;
335 # Set TLSv2 as minimum
336 print CONF
"tls-version-min 1.2 \n " ;
338 if ( $sovpnsettings { 'TLSAUTH' } eq 'on' ) {
339 print CONF
"tls-auth ${General::swroot}/ovpn/certs/ta.key \n " ;
341 if ( $sovpnsettings { DCOMPLZO
} eq 'on' ) {
342 print CONF
"comp-lzo \n " ;
344 if ( $sovpnsettings { REDIRECT_GW_DEF1
} eq 'on' ) {
345 print CONF
"push \" redirect-gateway def1 \"\n " ;
347 if ( $sovpnsettings { DHCP_DOMAIN
} ne '' ) {
348 print CONF
"push \" dhcp-option DOMAIN $sovpnsettings {DHCP_DOMAIN} \"\n " ;
351 if ( $sovpnsettings { DHCP_DNS
} ne '' ) {
352 print CONF
"push \" dhcp-option DNS $sovpnsettings {DHCP_DNS} \"\n " ;
355 if ( $sovpnsettings { DHCP_WINS
} ne '' ) {
356 print CONF
"push \" dhcp-option WINS $sovpnsettings {DHCP_WINS} \"\n " ;
359 if ( $sovpnsettings { MAX_CLIENTS
} eq '' ) {
360 print CONF
"max-clients 100 \n " ;
362 if ( $sovpnsettings { MAX_CLIENTS
} ne '' ) {
363 print CONF
"max-clients $sovpnsettings {MAX_CLIENTS} \n " ;
365 print CONF
"tls-verify /usr/lib/openvpn/verify \n " ;
366 print CONF
"crl-verify /var/ipfire/ovpn/crls/cacrl.pem \n " ;
367 print CONF
"auth-user-pass-optional \n " ;
368 print CONF
"reneg-sec 86400 \n " ;
369 print CONF
"user nobody \n " ;
370 print CONF
"group nobody \n " ;
371 print CONF
"persist-key \n " ;
372 print CONF
"persist-tun \n " ;
373 if ( $sovpnsettings { LOG_VERB
} ne '' ) {
374 print CONF
"verb $sovpnsettings {LOG_VERB} \n " ;
376 print CONF
"verb 3 \n " ;
379 print CONF
"# Log clients connecting/disconnecting \n " ;
380 print CONF
"client-connect \" /usr/sbin/openvpn-metrics client-connect \"\n " ;
381 print CONF
"client-disconnect \" /usr/sbin/openvpn-metrics client-disconnect \"\n " ;
384 print CONF
"# Enable Management Socket \n " ;
385 print CONF
"management /var/run/openvpn.sock unix \n " ;
386 print CONF
"management-client-auth \n " ;
388 # Print server.conf.local if entries exist to server.conf
389 if ( !- z
$local_serverconf && $sovpnsettings { 'ADDITIONAL_CONFIGS' } eq 'on' ) {
390 open ( LSC
, " $local_serverconf " );
391 print CONF
" \n #--------------------------- \n " ;
392 print CONF
"# Start of custom directives \n " ;
393 print CONF
"# from server.conf.local \n " ;
394 print CONF
"#--------------------------- \n\n " ;
398 print CONF
" \n #----------------------------- \n " ;
399 print CONF
"# End of custom directives \n " ;
400 print CONF
"#----------------------------- \n " ;
409 if ( open ( FILE
, ">/var/run/ovpnserver.log" )) {
419 my %ccdconfhash = ();
421 my $ccdnetname = $_ [ 0 ];
422 if (- f
"${General::swroot}/ovpn/ovpnconfig" ){
423 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
424 foreach my $key ( keys %ccdhash ) {
425 if ( $ccdhash { $key }[ 32 ] eq $ccdnetname ) {
426 $errormessage = $Lang :: tr
{ 'ccd err hostinnet' };
431 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
432 foreach my $key ( keys %ccdconfhash ) {
433 if ( $ccdconfhash { $key }[ 0 ] eq $ccdnetname ){
434 delete $ccdconfhash { $key };
437 & General
:: writehasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
459 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err name' }. "<br>" ;
463 if (!& General
:: validccdname
( $ccdname ))
465 $errormessage = $Lang :: tr
{ 'ccd err invalidname' };
469 ( $ccdip , $subcidr ) = split ( /\/ /, $ccdnet );
470 $subcidr =& General
:: iporsubtocidr
( $subcidr );
474 $errormessage = $Lang :: tr
{ 'ccd err invalidnet' };
478 if (!& General
:: validipandmask
( $ccdnet )){
479 $errormessage = $Lang :: tr
{ 'ccd err invalidnet' };
483 if (! $errormessage ) {
485 $baseaddress =& General
:: getnetworkip
( $ccdip , $subcidr );
486 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
487 my $key = & General
:: findhasharraykey
( \
%ccdconfhash );
488 foreach my $i ( 0 .. 1 ) { $ccdconfhash { $key }[ $i ] = "" ;}
489 $ccdconfhash { $key }[ 0 ] = $ccdname ;
490 $ccdconfhash { $key }[ 1 ] = $baseaddress . "/" . $subcidr ;
491 & General
:: writehasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
493 $cgiparams { 'ccdname' }= '' ;
494 $cgiparams { 'ccdsubnet' }= '' ;
507 # Check if the new name is valid.
508 if (!& General
:: validccdname
( $newname )) {
509 $errormessage = $Lang :: tr
{ 'ccd err invalidname' };
513 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
514 foreach my $key ( keys %ccdconfhash ) {
515 if ( $ccdconfhash { $key }[ 0 ] eq $oldname ) {
516 foreach my $key1 ( keys %ccdconfhash ) {
517 if ( $ccdconfhash { $key1 }[ 0 ] eq $newname ){
518 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err netadrexist' };
521 $ccdconfhash { $key }[ 0 ]= $newname ;
522 & General
:: writehasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
529 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
530 foreach my $key ( keys %ccdhash ) {
531 if ( $ccdhash { $key }[ 32 ] eq $oldname ) {
532 $ccdhash { $key }[ 32 ]= $newname ;
533 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
542 my $ccdnetwork = $_ [ 0 ];
545 @octets = split ( "\/" , $ccdnetwork );
546 @subnet = split /\./ , & General
:: cidrtosub
( $octets [ 1 ]);
559 my ( $ip1 , $ip2 , $ip3 , $ip4 )= split /\./ , $ipin ;
567 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
568 $iprange [ 0 ]= $ip1 . "." . $ip2 . "." . $ip3 . "." .( $ip4 + 2 );
569 for ( my $i = 1 ; $i <= $count ; $i ++) {
570 my $tmpip = $iprange [ $i - 1 ];
572 $iprange [ $i ]= & General
:: getnextip
( $tmpip , 4 );
575 foreach my $key ( keys %ccdhash ) {
577 foreach my $tmp ( @iprange ){
578 my ( $net , $sub ) = split ( /\/ /, $ccdhash { $key }[ 33 ]);
580 if ( $hasip ne $ccdhash { $key }[ 33 ] ){
581 splice ( @iprange , $r , 1 );
593 my ( $ccdip , $subcidr ) = split ( "/" , $_ [ 0 ]);
595 my @allccdips =& getccdadresses
( $ccdip , $subcidr ,& ccdmaxclients
( $ccdip . "/" . $subcidr ), $tz );
596 print "<select name=' $boxname ' STYLE='font-family : arial; font-size : 9pt; width:130px;' >" ;
597 foreach ( @allccdips ) {
600 print "<option value=' $ip ' " ;
601 if ( $ip eq $cgiparams { $boxname } ){
604 print "> $ip </option>" ;
614 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
615 foreach my $key ( keys %ccdhash ) {
616 if ( $ccdhash { $key }[ 32 ] eq $name ){ $i ++;}
621 sub check_routes_push
624 my ( $ip , $cidr ) = split ( /\/ /, $val );
625 ##check for existing routes in routes_push
626 if (- e
"${General::swroot}/ovpn/routes_push" ) {
627 open ( FILE
, "${General::swroot}/ovpn/routes_push" );
631 my ( $ip2 , $cidr2 ) = split ( /\/ /, " $_ " );
632 my $val2 = $ip2 . "/" .& General
:: iporsubtodec
( $cidr2 );
638 if (& General
:: IpInSubnet
( $ip , $ip2 ,& General
:: iporsubtodec
( $cidr2 ))){
651 my ( $ip , $cidr ) = split ( /\/ /, $val );
652 #check for existing routes in ccdroute
653 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
654 foreach my $key ( keys %ccdroutehash ) {
655 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}) {
656 if (& General
:: iporsubtodec
( $val ) eq $ccdroutehash { $key }[ $i ] && $ccdroutehash { $key }[ 0 ] ne $cgiparams { 'NAME' }){
659 my ( $ip2 , $cidr2 ) = split ( /\/ /, $ccdroutehash { $key }[ $i ]);
661 if (& General
:: IpInSubnet
( $ip , $ip2 , $cidr2 )&& $ccdroutehash { $key }[ 0 ] ne $cgiparams { 'NAME' } ){
672 my ( $ip , $cidr ) = split ( /\/ /, $val );
673 #check for existing routes in ccdroute
674 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
675 foreach my $key ( keys %ccdconfhash ) {
676 if (& General
:: iporsubtocidr
( $val ) eq $ccdconfhash { $key }[ 1 ]){
679 my ( $ip2 , $cidr2 ) = split ( /\/ /, $ccdconfhash { $key }[ 1 ]);
681 if (& General
:: IpInSubnet
( $ip , $ip2 ,& General
:: cidrtosub
( $cidr2 ))){
695 my $ipdotmask = $_ [ 0 ];
696 if (& General
:: validip
( $ipdotmask )) { return 0 ; }
697 if (!( $ipdotmask =~ /^(.*?)\/ (.* ?
)$/)) { }
699 if (( $mask =~ /\./ )) { return 0 ; }
703 # -------------------------------------------------------------------
705 sub write_routepushfile
707 open ( FILE
, "> $routes_push_file " );
709 if ( $vpnsettings { 'ROUTES_PUSH' } ne '' ) {
710 print FILE
$vpnsettings { 'ROUTES_PUSH' };
715 sub read_routepushfile
717 if (- e
" $routes_push_file " ) {
718 open ( FILE
, " $routes_push_file " );
719 delete $vpnsettings { 'ROUTES_PUSH' };
720 while (< FILE
>) { $vpnsettings { 'ROUTES_PUSH' } .= $_ };
722 $cgiparams { 'ROUTES_PUSH' } = $vpnsettings { 'ROUTES_PUSH' };
727 sub writecollectdconf
{
731 open ( COLLECTDVPN
, ">${General::swroot}/ovpn/collectd.vpn" ) or die "Unable to open collectd.vpn: $!" ;
732 print COLLECTDVPN
"Loadplugin openvpn \n " ;
733 print COLLECTDVPN
" \n " ;
734 print COLLECTDVPN
"<Plugin openvpn> \n " ;
735 print COLLECTDVPN
"Statusfile \" /var/run/ovpnserver.log \"\n " ;
737 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
738 foreach my $key ( keys %ccdhash ) {
739 if ( $ccdhash { $key }[ 0 ] eq 'on' && $ccdhash { $key }[ 3 ] eq 'net' ) {
740 print COLLECTDVPN
"Statusfile \" /var/run/openvpn/ $ccdhash { $key }[1]-n2n \"\n " ;
744 print COLLECTDVPN
"</Plugin> \n " ;
747 # Reload collectd afterwards
748 & General
:: system ( "/usr/local/bin/collectdctrl" , "restart" );
751 #hier die refresh page
752 if ( - e
"${General::swroot}/ovpn/gencanow" ) {
754 $refresh = "<meta http-equiv='refresh' content='15;' />" ;
755 & Header
:: showhttpheaders
();
756 & Header
:: openpage
( $Lang :: tr
{ 'OVPN' }, 1 , $refresh );
757 & Header
:: openbigbox
( '100%' , 'center' );
758 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
759 print "<tr> \n <td align='center'><img src='/images/clock.gif' alt='' /></td> \n " ;
760 print "<td colspan='2'><font color='red'>Please be patient this realy can take some time on older hardware...</font></td></tr> \n " ;
762 & Header
:: closebigbox
();
763 & Header
:: closepage
();
766 ##hier die refresh page
770 ### OpenVPN Server Control
772 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'start ovpn server' } ||
773 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'stop ovpn server' } ||
774 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart ovpn server' }) {
775 #start openvpn server
776 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'start ovpn server' }){
778 & General
:: system ( "/usr/local/bin/openvpnctrl" , "-s" );
781 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'stop ovpn server' }){
782 & General
:: system ( "/usr/local/bin/openvpnctrl" , "-k" );
785 # #restart openvpn server
786 # if ($cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}){
787 #workarund, till SIGHUP also works when running as nobody
788 # system('/usr/local/bin/openvpnctrl', '-r');
794 ### Save Advanced options
797 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save-adv-options' }) {
798 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
799 #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too,
800 #DAN this value has to leave.
801 #new settings for daemon
802 $vpnsettings { 'LOG_VERB' } = $cgiparams { 'LOG_VERB' };
803 $vpnsettings { 'KEEPALIVE_1' } = $cgiparams { 'KEEPALIVE_1' };
804 $vpnsettings { 'KEEPALIVE_2' } = $cgiparams { 'KEEPALIVE_2' };
805 $vpnsettings { 'MAX_CLIENTS' } = $cgiparams { 'MAX_CLIENTS' };
806 $vpnsettings { 'REDIRECT_GW_DEF1' } = $cgiparams { 'REDIRECT_GW_DEF1' };
807 $vpnsettings { 'CLIENT2CLIENT' } = $cgiparams { 'CLIENT2CLIENT' };
808 $vpnsettings { 'DCOMPLZO' } = $cgiparams { 'DCOMPLZO' };
809 $vpnsettings { 'ADDITIONAL_CONFIGS' } = $cgiparams { 'ADDITIONAL_CONFIGS' };
810 $vpnsettings { 'DHCP_DOMAIN' } = $cgiparams { 'DHCP_DOMAIN' };
811 $vpnsettings { 'DHCP_DNS' } = $cgiparams { 'DHCP_DNS' };
812 $vpnsettings { 'DHCP_WINS' } = $cgiparams { 'DHCP_WINS' };
813 $vpnsettings { 'ROUTES_PUSH' } = $cgiparams { 'ROUTES_PUSH' };
816 if ( $cgiparams { 'FRAGMENT' } eq '' ) {
817 delete $vpnsettings { 'FRAGMENT' };
819 if ( $cgiparams { 'FRAGMENT' } !~ /^[0-9]+$/ ) {
820 $errormessage = "Incorrect value, please insert only numbers." ;
823 $vpnsettings { 'FRAGMENT' } = $cgiparams { 'FRAGMENT' };
827 if ( $cgiparams { 'MSSFIX' } ne 'on' ) {
828 delete $vpnsettings { 'MSSFIX' };
830 $vpnsettings { 'MSSFIX' } = $cgiparams { 'MSSFIX' };
833 if ( $cgiparams { 'DHCP_DOMAIN' } ne '' ){
834 unless (& General
:: validdomainname
( $cgiparams { 'DHCP_DOMAIN' }) || & General
:: validip
( $cgiparams { 'DHCP_DOMAIN' })) {
835 $errormessage = $Lang :: tr
{ 'invalid input for dhcp domain' };
839 if ( $cgiparams { 'DHCP_DNS' } ne '' ){
840 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_DNS' }) || & General
:: validip
( $cgiparams { 'DHCP_DNS' })) {
841 $errormessage = $Lang :: tr
{ 'invalid input for dhcp dns' };
845 if ( $cgiparams { 'DHCP_WINS' } ne '' ){
846 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_WINS' }) || & General
:: validip
( $cgiparams { 'DHCP_WINS' })) {
847 $errormessage = $Lang :: tr
{ 'invalid input for dhcp wins' };
851 if ( $cgiparams { 'ROUTES_PUSH' } ne '' ){
852 @temp = split ( /\n/ , $cgiparams { 'ROUTES_PUSH' });
853 undef $vpnsettings { 'ROUTES_PUSH' };
855 foreach my $tmpip ( @temp )
857 s/^\s+//g ; s/\s+$//g ;
862 unless (& General
:: validipandmask
( $tmpip )) {
863 $errormessage = " $tmpip " . $Lang :: tr
{ 'ovpn errmsg invalid ip or mask' };
866 my ( $ip , $cidr ) = split ( "\/" ,& General
:: ipcidr2msk
( $tmpip ));
868 if ( $ip eq $netsettings { 'GREEN_NETADDRESS' } && $cidr eq $netsettings { 'GREEN_NETMASK' }) {
869 $errormessage = $Lang :: tr
{ 'ovpn errmsg green already pushed' };
874 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
875 foreach my $key ( keys %ccdroutehash ) {
876 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}) {
877 if ( $ip . "/" . $cidr eq $ccdroutehash { $key }[ $i ] ){
878 $errormessage = "Route $ip \/ $cidr " . $Lang :: tr
{ 'ccd err inuse' }. " $ccdroutehash { $key }[0]" ;
881 my ( $ip2 , $cidr2 ) = split ( /\/ /, $ccdroutehash { $key }[ $i ]);
882 if (& General
:: IpInSubnet
( $ip , $ip2 , $cidr2 )){
883 $errormessage = "Route $ip \/ $cidr " . $Lang :: tr
{ 'ccd err inuse' }. " $ccdroutehash { $key }[0]" ;
891 $vpnsettings { 'ROUTES_PUSH' } .= $tmpip . " \n " ;
894 & write_routepushfile
;
895 undef $vpnsettings { 'ROUTES_PUSH' };
898 undef $vpnsettings { 'ROUTES_PUSH' };
899 & write_routepushfile
;
901 if (( length ( $cgiparams { 'MAX_CLIENTS' }) == 0 ) || (( $cgiparams { 'MAX_CLIENTS' }) < 1 ) || (( $cgiparams { 'MAX_CLIENTS' }) > 1024 )) {
902 $errormessage = $Lang :: tr
{ 'invalid input for max clients' };
905 if ( $cgiparams { 'KEEPALIVE_1' } ne '' ) {
906 if ( $cgiparams { 'KEEPALIVE_1' } !~ /^[0-9]+$/ ) {
907 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 1' };
911 if ( $cgiparams { 'KEEPALIVE_2' } ne '' ){
912 if ( $cgiparams { 'KEEPALIVE_2' } !~ /^[0-9]+$/ ) {
913 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 2' };
917 if ( $cgiparams { 'KEEPALIVE_2' } < ( $cgiparams { 'KEEPALIVE_1' } * 2 )){
918 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 1:2' };
921 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
922 & writeserverconf
(); #hier ok
929 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq 'net' && $cgiparams { 'SIDE' } eq 'server' )
932 my @remsubnet = split ( /\/ /, $cgiparams { 'REMOTE_SUBNET' });
933 my @ovsubnettemp = split ( /\./ , $cgiparams { 'OVPN_SUBNET' });
934 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
937 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
938 unless (- d
"${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" , 0770 or die "Unable to create dir $!" ;}
940 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: $!" ;
943 print SERVERCONF
"# IPFire n2n Open VPN Server Config by ummeegge und m.a.d \n " ;
944 print SERVERCONF
" \n " ;
945 print SERVERCONF
"# User Security \n " ;
946 print SERVERCONF
"user nobody \n " ;
947 print SERVERCONF
"group nobody \n " ;
948 print SERVERCONF
"persist-tun \n " ;
949 print SERVERCONF
"persist-key \n " ;
950 print SERVERCONF
"script-security 2 \n " ;
951 print SERVERCONF
"# IP/DNS for remote Server Gateway \n " ;
953 if ( $cgiparams { 'REMOTE' } ne '' ) {
954 print SERVERCONF
"remote $cgiparams {'REMOTE'} \n " ;
957 print SERVERCONF
"float \n " ;
958 print SERVERCONF
"# IP adresses of the VPN Subnet \n " ;
959 print SERVERCONF
"ifconfig $ovsubnet .1 $ovsubnet .2 \n " ;
960 print SERVERCONF
"# Client Gateway Network \n " ;
961 print SERVERCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
962 print SERVERCONF
"up \" /etc/init.d/static-routes start \"\n " ;
963 print SERVERCONF
"# tun Device \n " ;
964 print SERVERCONF
"dev tun \n " ;
965 print SERVERCONF
"#Logfile for statistics \n " ;
966 print SERVERCONF
"status-version 1 \n " ;
967 print SERVERCONF
"status /var/run/openvpn/ $cgiparams {'NAME'}-n2n 10 \n " ;
968 print SERVERCONF
"# Port and Protokol \n " ;
969 print SERVERCONF
"port $cgiparams {'DEST_PORT'} \n " ;
971 if ( $cgiparams { 'PROTOCOL' } eq 'tcp' ) {
972 print SERVERCONF
"proto tcp4-server \n " ;
973 print SERVERCONF
"# Packet size \n " ;
974 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1400' } else { $tunmtu = $cgiparams { 'MTU' }};
975 print SERVERCONF
"tun-mtu $tunmtu \n " ;
978 if ( $cgiparams { 'PROTOCOL' } eq 'udp' ) {
979 print SERVERCONF
"proto udp4 \n " ;
980 print SERVERCONF
"# Paketsize \n " ;
981 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1500' } else { $tunmtu = $cgiparams { 'MTU' }};
982 print SERVERCONF
"tun-mtu $tunmtu \n " ;
983 if ( $cgiparams { 'FRAGMENT' } ne '' ) { print SERVERCONF
"fragment $cgiparams {'FRAGMENT'} \n " ;}
984 if ( $cgiparams { 'MSSFIX' } eq 'on' ) { print SERVERCONF
"mssfix \n " ; } else { print SERVERCONF
"mssfix 0 \n " };
987 print SERVERCONF
"# Auth. Server \n " ;
988 print SERVERCONF
"tls-server \n " ;
989 print SERVERCONF
"ca ${General::swroot}/ovpn/ca/cacert.pem \n " ;
990 print SERVERCONF
"cert ${General::swroot}/ovpn/certs/servercert.pem \n " ;
991 print SERVERCONF
"key ${General::swroot}/ovpn/certs/serverkey.pem \n " ;
992 print SERVERCONF
"dh $dhparameter \n " ;
993 print SERVERCONF
"# Cipher \n " ;
994 print SERVERCONF
"cipher $cgiparams {'DCIPHER'} \n " ;
996 # If GCM cipher is used, do not use --auth
997 if (( $cgiparams { 'DCIPHER' } eq 'AES-256-GCM' ) ||
998 ( $cgiparams { 'DCIPHER' } eq 'AES-192-GCM' ) ||
999 ( $cgiparams { 'DCIPHER' } eq 'AES-128-GCM' )) {
1000 print SERVERCONF
unless "# HMAC algorithm \n " ;
1001 print SERVERCONF
unless "auth $cgiparams {'DAUTH'} \n " ;
1003 print SERVERCONF
"# HMAC algorithm \n " ;
1004 print SERVERCONF
"auth $cgiparams {'DAUTH'} \n " ;
1007 # Set TLSv1.2 as minimum
1008 print SERVERCONF
"tls-version-min 1.2 \n " ;
1010 if ( $cgiparams { 'COMPLZO' } eq 'on' ) {
1011 print SERVERCONF
"# Enable Compression \n " ;
1012 print SERVERCONF
"comp-lzo \n " ;
1014 print SERVERCONF
"# Debug Level \n " ;
1015 print SERVERCONF
"verb 3 \n " ;
1016 print SERVERCONF
"# Tunnel check \n " ;
1017 print SERVERCONF
"keepalive 10 60 \n " ;
1018 print SERVERCONF
"# Start as daemon \n " ;
1019 print SERVERCONF
"daemon $cgiparams {'NAME'}n2n \n " ;
1020 print SERVERCONF
"writepid /var/run/ $cgiparams {'NAME'}n2n.pid \n " ;
1021 print SERVERCONF
"# Activate Management Interface and Port \n " ;
1022 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) { print SERVERCONF
"management localhost $cgiparams {'DEST_PORT'} \n " }
1023 else { print SERVERCONF
"management localhost $cgiparams {'OVPN_MGMT'} \n " };
1032 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq 'net' && $cgiparams { 'SIDE' } eq 'client' )
1035 my @ovsubnettemp = split ( /\./ , $cgiparams { 'OVPN_SUBNET' });
1036 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
1037 my @remsubnet = split ( /\/ /, $cgiparams { 'REMOTE_SUBNET' });
1040 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
1041 unless (- d
"${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" , 0770 or die "Unable to create dir $!" ;}
1043 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: $!" ;
1045 flock CLIENTCONF
, 2 ;
1046 print CLIENTCONF
"# IPFire rewritten n2n Open VPN Client Config by ummeegge und m.a.d \n " ;
1047 print CLIENTCONF
"# \n " ;
1048 print CLIENTCONF
"# User Security \n " ;
1049 print CLIENTCONF
"user nobody \n " ;
1050 print CLIENTCONF
"group nobody \n " ;
1051 print CLIENTCONF
"persist-tun \n " ;
1052 print CLIENTCONF
"persist-key \n " ;
1053 print CLIENTCONF
"script-security 2 \n " ;
1054 print CLIENTCONF
"# IP/DNS for remote Server Gateway \n " ;
1055 print CLIENTCONF
"remote $cgiparams {'REMOTE'} \n " ;
1056 print CLIENTCONF
"float \n " ;
1057 print CLIENTCONF
"# IP adresses of the VPN Subnet \n " ;
1058 print CLIENTCONF
"ifconfig $ovsubnet .2 $ovsubnet .1 \n " ;
1059 print CLIENTCONF
"# Server Gateway Network \n " ;
1060 print CLIENTCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
1061 print CLIENTCONF
"up \" /etc/init.d/static-routes start \"\n " ;
1062 print CLIENTCONF
"# tun Device \n " ;
1063 print CLIENTCONF
"dev tun \n " ;
1064 print CLIENTCONF
"#Logfile for statistics \n " ;
1065 print CLIENTCONF
"status-version 1 \n " ;
1066 print CLIENTCONF
"status /var/run/openvpn/ $cgiparams {'NAME'}-n2n 10 \n " ;
1067 print CLIENTCONF
"# Port and Protokol \n " ;
1068 print CLIENTCONF
"port $cgiparams {'DEST_PORT'} \n " ;
1070 if ( $cgiparams { 'PROTOCOL' } eq 'tcp' ) {
1071 print CLIENTCONF
"proto tcp4-client \n " ;
1072 print CLIENTCONF
"# Packet size \n " ;
1073 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1400' } else { $tunmtu = $cgiparams { 'MTU' }};
1074 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
1077 if ( $cgiparams { 'PROTOCOL' } eq 'udp' ) {
1078 print CLIENTCONF
"proto udp4 \n " ;
1079 print CLIENTCONF
"# Paketsize \n " ;
1080 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1500' } else { $tunmtu = $cgiparams { 'MTU' }};
1081 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
1082 if ( $cgiparams { 'FRAGMENT' } ne '' ) { print CLIENTCONF
"fragment $cgiparams {'FRAGMENT'} \n " ;}
1083 if ( $cgiparams { 'MSSFIX' } eq 'on' ) { print CLIENTCONF
"mssfix \n " ; } else { print CLIENTCONF
"mssfix 0 \n " };
1086 # Check host certificate if X509 is RFC3280 compliant.
1087 # If not, old --ns-cert-type directive will be used.
1088 # If appropriate key usage extension exists, new --remote-cert-tls directive will be used.
1089 my @hostcert = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "${General::swroot}/ovpn/certs/servercert.pem" );
1090 if ( ! grep ( /TLS Web Server Authentication/ , @hostcert )) {
1091 print CLIENTCONF
"ns-cert-type server \n " ;
1093 print CLIENTCONF
"remote-cert-tls server \n " ;
1095 print CLIENTCONF
"# Auth. Client \n " ;
1096 print CLIENTCONF
"tls-client \n " ;
1097 print CLIENTCONF
"# Cipher \n " ;
1098 print CLIENTCONF
"cipher $cgiparams {'DCIPHER'} \n " ;
1099 print CLIENTCONF
"pkcs12 ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12 \r\n " ;
1101 # If GCM cipher is used, do not use --auth
1102 if (( $cgiparams { 'DCIPHER' } eq 'AES-256-GCM' ) ||
1103 ( $cgiparams { 'DCIPHER' } eq 'AES-192-GCM' ) ||
1104 ( $cgiparams { 'DCIPHER' } eq 'AES-128-GCM' )) {
1105 print CLIENTCONF
unless "# HMAC algorithm \n " ;
1106 print CLIENTCONF
unless "auth $cgiparams {'DAUTH'} \n " ;
1108 print CLIENTCONF
"# HMAC algorithm \n " ;
1109 print CLIENTCONF
"auth $cgiparams {'DAUTH'} \n " ;
1112 # Set TLSv1.2 as minimum
1113 print CLIENTCONF
"tls-version-min 1.2 \n " ;
1115 if ( $cgiparams { 'COMPLZO' } eq 'on' ) {
1116 print CLIENTCONF
"# Enable Compression \n " ;
1117 print CLIENTCONF
"comp-lzo \n " ;
1119 print CLIENTCONF
"# Debug Level \n " ;
1120 print CLIENTCONF
"verb 3 \n " ;
1121 print CLIENTCONF
"# Tunnel check \n " ;
1122 print CLIENTCONF
"keepalive 10 60 \n " ;
1123 print CLIENTCONF
"# Start as daemon \n " ;
1124 print CLIENTCONF
"daemon $cgiparams {'NAME'}n2n \n " ;
1125 print CLIENTCONF
"writepid /var/run/ $cgiparams {'NAME'}n2n.pid \n " ;
1126 print CLIENTCONF
"# Activate Management Interface and Port \n " ;
1127 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) { print CLIENTCONF
"management localhost $cgiparams {'DEST_PORT'} \n " }
1128 else { print CLIENTCONF
"management localhost $cgiparams {'OVPN_MGMT'} \n " };
1129 if (& iscertlegacy
( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}" )) {
1130 print CLIENTCONF
"providers legacy default \n " ;
1137 ### Save main settings
1140 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
1141 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1142 #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too,
1143 #DAN this value has to leave.
1144 if ( $cgiparams { 'ENABLED' } eq 'on' ){
1145 unless (& General
:: validfqdn
( $cgiparams { 'VPN_IP' }) || & General
:: validip
( $cgiparams { 'VPN_IP' })) {
1146 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
1147 goto SETTINGS_ERROR
;
1151 if (! & General
:: validipandmask
( $cgiparams { 'DOVPN_SUBNET' })) {
1152 $errormessage = $Lang :: tr
{ 'ovpn subnet is invalid' };
1153 goto SETTINGS_ERROR
;
1155 my @tmpovpnsubnet = split ( "\/" , $cgiparams { 'DOVPN_SUBNET' });
1157 if (& General
:: IpInSubnet
( $netsettings { 'RED_ADDRESS' },
1158 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1159 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire RED Network $netsettings {'RED_ADDRESS'}" ;
1160 goto SETTINGS_ERROR
;
1163 if (& General
:: IpInSubnet
( $netsettings { 'GREEN_ADDRESS' },
1164 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1165 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Green Network $netsettings {'GREEN_ADDRESS'}" ;
1166 goto SETTINGS_ERROR
;
1169 if (& General
:: IpInSubnet
( $netsettings { 'BLUE_ADDRESS' },
1170 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1171 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Blue Network $netsettings {'BLUE_ADDRESS'}" ;
1172 goto SETTINGS_ERROR
;
1175 if (& General
:: IpInSubnet
( $netsettings { 'ORANGE_ADDRESS' },
1176 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1177 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Orange Network $netsettings {'ORANGE_ADDRESS'}" ;
1178 goto SETTINGS_ERROR
;
1180 open ( ALIASES
, "${General::swroot}/ethernet/aliases" ) or die 'Unable to open aliases file.' ;
1184 my @tempalias = split ( /\,/ , $_ );
1185 if ( $tempalias [ 1 ] eq 'on' ) {
1186 if (& General
:: IpInSubnet
( $tempalias [ 0 ] ,
1187 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1188 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire alias entry $tempalias [0]" ;
1193 if ( $errormessage ne '' ){
1194 goto SETTINGS_ERROR
;
1196 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
1197 $errormessage = $Lang :: tr
{ 'invalid input' };
1198 goto SETTINGS_ERROR
;
1200 if (( length ( $cgiparams { 'DMTU' })== 0 ) || (( $cgiparams { 'DMTU' }) < 1000 )) {
1201 $errormessage = $Lang :: tr
{ 'invalid mtu input' };
1202 goto SETTINGS_ERROR
;
1205 unless (& General
:: validport
( $cgiparams { 'DDEST_PORT' })) {
1206 $errormessage = $Lang :: tr
{ 'invalid port' };
1207 goto SETTINGS_ERROR
;
1210 # Create ta.key for tls-auth if not presant
1211 if ( $cgiparams { 'TLSAUTH' } eq 'on' ) {
1212 if ( ! - e
"${General::swroot}/ovpn/certs/ta.key" ) {
1213 # This system call is safe, because all arguements are passed as an array.
1214 system ( "/usr/sbin/openvpn" , "--genkey" , "secret" , "${General::swroot}/ovpn/certs/ta.key" );
1216 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1217 goto SETTINGS_ERROR
;
1222 $vpnsettings { 'ENABLED_BLUE' } = $cgiparams { 'ENABLED_BLUE' };
1223 $vpnsettings { 'ENABLED_ORANGE' } = $cgiparams { 'ENABLED_ORANGE' };
1224 $vpnsettings { 'ENABLED' } = $cgiparams { 'ENABLED' };
1225 $vpnsettings { 'VPN_IP' } = $cgiparams { 'VPN_IP' };
1226 #new settings for daemon
1227 $vpnsettings { 'DOVPN_SUBNET' } = $cgiparams { 'DOVPN_SUBNET' };
1228 $vpnsettings { 'DPROTOCOL' } = $cgiparams { 'DPROTOCOL' };
1229 $vpnsettings { 'DDEST_PORT' } = $cgiparams { 'DDEST_PORT' };
1230 $vpnsettings { 'DMTU' } = $cgiparams { 'DMTU' };
1231 $vpnsettings { 'DCOMPLZO' } = $cgiparams { 'DCOMPLZO' };
1232 $vpnsettings { 'DCIPHER' } = $cgiparams { 'DCIPHER' };
1233 $vpnsettings { 'DAUTH' } = $cgiparams { 'DAUTH' };
1234 $vpnsettings { 'TLSAUTH' } = $cgiparams { 'TLSAUTH' };
1237 if ( $vpnsettings { 'ENABLED_BLUE' } eq 'on' ) {
1238 & General
:: system ( "touch" , "${General::swroot}/ovpn/enable_blue" );
1240 unlink ( "${General::swroot}/ovpn/enable_blue" );
1243 if ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' ) {
1244 & General
:: system ( "touch" , "${General::swroot}/ovpn/enable_orange" );
1246 unlink ( "${General::swroot}/ovpn/enable_orange" );
1249 if ( $vpnsettings { 'ENABLED' } eq 'on' ) {
1250 & General
:: system ( "touch" , "${General::swroot}/ovpn/enable" );
1252 unlink ( "${General::swroot}/ovpn/enable" );
1255 #new settings for daemon
1256 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1257 & writeserverconf
(); #hier ok
1260 ### Reset all step 2
1262 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
1264 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1266 # Kill all N2N connections
1267 & General
:: system ( "/usr/local/bin/openvpnctrl" , "-kn2n" );
1269 foreach my $key ( keys %confighash ) {
1270 my $name = $confighash { $cgiparams { ' $key ' }}[ 1 ];
1272 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
1273 delete $confighash { $cgiparams { ' $key ' }};
1276 & General
:: system ( "/usr/local/bin/openvpnctrl" , "-drrd" , " $name " );
1278 while ( $file = glob ( "${General::swroot}/ovpn/ca/*" )) {
1281 while ( $file = glob ( "${General::swroot}/ovpn/certs/*" )) {
1284 while ( $file = glob ( "${General::swroot}/ovpn/crls/*" )) {
1287 & cleanssldatabase
();
1288 if ( open ( FILE
, ">${General::swroot}/ovpn/caconfig" )) {
1292 if ( open ( FILE
, ">${General::swroot}/ovpn/ccdroute" )) {
1296 if ( open ( FILE
, ">${General::swroot}/ovpn/ccdroute2" )) {
1300 while ( $file = glob ( "${General::swroot}/ovpn/ccd/*" )) {
1303 while ( $file = glob ( "${General::swroot}/ovpn/ccd/*" )) {
1306 if ( open ( FILE
, ">${General::swroot}/ovpn/ovpn-leases.db" )) {
1310 if ( open ( FILE
, ">${General::swroot}/ovpn/ovpnconfig" )) {
1314 while ( $file = glob ( "${General::swroot}/ovpn/n2nconf/*" )) {
1318 # Remove everything from the collectd configuration
1319 & writecollectdconf
();
1321 #&writeserverconf();
1323 ### Reset all step 1
1325 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' }) {
1326 & Header
:: showhttpheaders
();
1327 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
1328 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1329 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
1331 <form method='post'>
1332 <table width='100%'>
1335 <input type='hidden' name='AREUSURE' value='yes' />
1336 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1337 $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}</td>
1340 <td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' />
1341 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
1347 & Header
:: closebox
();
1348 & Header
:: closebigbox
();
1349 & Header
:: closepage
();
1353 ### Upload CA Certificate
1355 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
1356 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1358 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
1359 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
1360 goto UPLOADCA_ERROR
;
1363 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
1364 $errormessage = $Lang :: tr
{ 'name too long' };
1368 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
1369 $errormessage = $Lang :: tr
{ 'name is invalid' };
1370 goto UPLOADCA_ERROR
;
1373 # Check if there is no other entry with this name
1374 foreach my $key ( keys %cahash ) {
1375 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
1376 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
1377 goto UPLOADCA_ERROR
;
1381 unless ( ref ( $cgiparams { 'FH' })) {
1382 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1383 goto UPLOADCA_ERROR
;
1385 # Move uploaded ca to a temporary file
1386 ( my $fh , my $filename ) = tempfile
( );
1387 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1389 goto UPLOADCA_ERROR
;
1391 my @temp = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , " $filename " );
1392 if ( ! grep ( /CA:TRUE/i , @temp )) {
1393 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
1395 goto UPLOADCA_ERROR
;
1397 unless ( move
( $filename , "${General::swroot}/ovpn/ca/ $cgiparams {'CA_NAME'}cert.pem" )) {
1398 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1400 goto UPLOADCA_ERROR
;
1404 my @casubject = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "${General::swroot}/ovpn/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1407 foreach my $line ( @casubject ) {
1408 if ( $line =~ /Subject: (.*)[\n]/ ) {
1410 $casubject =~ s
+/ Email
+, E
+;
1411 $casubject =~ s/ ST=/ S=/ ;
1417 $casubject = & Header
:: cleanhtml
( $casubject );
1419 my $key = & General
:: findhasharraykey
( \
%cahash );
1420 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
1421 $cahash { $key }[ 1 ] = $casubject ;
1422 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1423 # system('/usr/local/bin/ipsecctrl', 'R');
1428 ### Display ca certificate
1430 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
1431 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1433 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1434 & Header
:: showhttpheaders
();
1435 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
1436 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
1437 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'ca certificate'}:" );
1438 my @output = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
1439 my $output = & Header
:: cleanhtml
( join ( "" , @output ), "y" );
1440 print "<pre> $output </pre> \n " ;
1441 & Header
:: closebox
();
1442 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1443 & Header
:: closebigbox
();
1444 & Header
:: closepage
();
1447 $errormessage = $Lang :: tr
{ 'invalid key' };
1451 ### Download ca certificate
1453 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
1454 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1456 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1457 print "Content-Type: application/octet-stream \r\n " ;
1458 print "Content-Disposition: filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
1460 my @tmp = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-in" , "${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
1465 $errormessage = $Lang :: tr
{ 'invalid key' };
1469 ### Remove ca certificate (step 2)
1471 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
1472 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1473 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1475 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1476 foreach my $key ( keys %confighash ) {
1477 my @test = & General
:: system_output
( "/usr/bin/openssl" , "verify" , "-CAfile" , "${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" , "${General::swroot}/ovpn/certs/ $confighash { $key }[1]cert.pem" );
1478 if ( grep ( /: OK/ , @test )) {
1480 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1481 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
1482 # system('/usr/local/bin/ipsecctrl', 'D', $key);
1484 unlink ( "${General::swroot}/ovpn//certs/ $confighash { $key }[1]cert.pem" );
1485 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $key }[1].p12" );
1486 delete $confighash { $key };
1487 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1488 # &writeipsecfiles();
1491 unlink ( "${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
1492 delete $cahash { $cgiparams { 'KEY' }};
1493 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1494 # system('/usr/local/bin/ipsecctrl', 'R');
1496 $errormessage = $Lang :: tr
{ 'invalid key' };
1499 ### Remove ca certificate (step 1)
1501 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
1502 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1503 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1505 my $assignedcerts = 0 ;
1506 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1507 foreach my $key ( keys %confighash ) {
1508 my @test = & General
:: system_output
( "/usr/bin/openssl" , "verify" , "-CAfile" , "${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" , "${General::swroot}/ovpn/certs/ $confighash { $key }[1]cert.pem" );
1509 if ( grep ( /: OK/ , @test )) {
1513 if ( $assignedcerts ) {
1514 & Header
:: showhttpheaders
();
1515 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
1516 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
1517 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'are you sure' });
1519 <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' />
1520 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
1521 <tr><td align='center'>
1522 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>: $assignedcerts
1523 $Lang ::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}
1524 <tr><td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
1525 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td></tr>
1529 & Header
:: closebox
();
1530 & Header
:: closebigbox
();
1531 & Header
:: closepage
();
1534 unlink ( "${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
1535 delete $cahash { $cgiparams { 'KEY' }};
1536 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1537 # system('/usr/local/bin/ipsecctrl', 'R');
1540 $errormessage = $Lang :: tr
{ 'invalid key' };
1544 ### Display root certificate
1546 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
1547 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
1549 & Header
:: showhttpheaders
();
1550 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
1551 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1552 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
1553 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'root certificate'}:" );
1554 @output = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "${General::swroot}/ovpn/ca/cacert.pem" );
1556 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'host certificate'}:" );
1557 @output = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "${General::swroot}/ovpn/certs/servercert.pem" );
1559 my $output = & Header
:: cleanhtml
( join ( "" , @output ), "y" );
1560 print "<pre> $output </pre> \n " ;
1561 & Header
:: closebox
();
1562 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1563 & Header
:: closebigbox
();
1564 & Header
:: closepage
();
1568 ### Download root certificate
1570 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
1571 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
1572 print "Content-Type: application/octet-stream \r\n " ;
1573 print "Content-Disposition: filename=cacert.pem \r\n\r\n " ;
1575 my @tmp = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-in" , "${General::swroot}/ovpn/ca/cacert.pem" );
1582 ### Download host certificate
1584 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
1585 if ( - f
"${General::swroot}/ovpn/certs/servercert.pem" ) {
1586 print "Content-Type: application/octet-stream \r\n " ;
1587 print "Content-Disposition: filename=servercert.pem \r\n\r\n " ;
1589 my @tmp = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-in" , "${General::swroot}/ovpn/certs/servercert.pem" );
1596 ### Download tls-auth key
1598 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download tls-auth key' }) {
1599 if ( - f
"${General::swroot}/ovpn/certs/ta.key" ) {
1600 print "Content-Type: application/octet-stream \r\n " ;
1601 print "Content-Disposition: filename=ta.key \r\n\r\n " ;
1603 open ( FILE
, "${General::swroot}/ovpn/certs/ta.key" );
1613 ### Form for generating a root certificate
1615 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
1616 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
1618 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1619 if (- f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
1620 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
1621 $cgiparams { 'ACTION' } = '' ;
1622 goto ROOTCERT_ERROR
;
1625 if (( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) && - e
"${General::swroot}/red/active" ) {
1626 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
1627 my $ipaddr = < IPADDR
>;
1630 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
1631 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
1632 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
1635 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
1636 unless ( ref ( $cgiparams { 'FH' })) {
1637 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1638 goto ROOTCERT_ERROR
;
1641 # Move uploaded certificate request to a temporary file
1642 ( my $fh , my $filename ) = tempfile
( );
1643 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1645 goto ROOTCERT_ERROR
;
1648 # Create a temporary dirctory
1649 my $tempdir = tempdir
( CLEANUP
=> 1 );
1651 # Extract the CA certificate from the file
1652 my $pid = open ( OPENSSL
, "|-" );
1653 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1654 if ( $pid ) { # parent
1655 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1656 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1660 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1662 goto ROOTCERT_ERROR
;
1665 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-cacerts' , '-nokeys' ,
1667 '-out' , " $tempdir /cacert.pem" )) {
1668 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1670 goto ROOTCERT_ERROR
;
1674 # Extract the Host certificate from the file
1675 $pid = open ( OPENSSL
, "|-" );
1676 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1677 if ( $pid ) { # parent
1678 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1679 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1683 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1685 goto ROOTCERT_ERROR
;
1688 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-clcerts' , '-nokeys' ,
1690 '-out' , " $tempdir /hostcert.pem" )) {
1691 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1693 goto ROOTCERT_ERROR
;
1697 # Extract the Host key from the file
1698 $pid = open ( OPENSSL
, "|-" );
1699 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1700 if ( $pid ) { # parent
1701 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1702 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1706 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1708 goto ROOTCERT_ERROR
;
1711 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-nocerts' ,
1714 '-out' , " $tempdir /serverkey.pem" )) {
1715 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1717 goto ROOTCERT_ERROR
;
1721 unless ( move
( " $tempdir /cacert.pem" , "${General::swroot}/ovpn/ca/cacert.pem" )) {
1722 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1724 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1725 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1726 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1727 goto ROOTCERT_ERROR
;
1730 unless ( move
( " $tempdir /hostcert.pem" , "${General::swroot}/ovpn/certs/servercert.pem" )) {
1731 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1733 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1734 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1735 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1736 goto ROOTCERT_ERROR
;
1739 unless ( move
( " $tempdir /serverkey.pem" , "${General::swroot}/ovpn/certs/serverkey.pem" )) {
1740 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1742 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1743 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1744 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1745 goto ROOTCERT_ERROR
;
1748 goto ROOTCERT_SUCCESS
;
1750 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
1752 # Validate input since the form was submitted
1753 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
1754 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
1755 goto ROOTCERT_ERROR
;
1757 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
1758 $errormessage = $Lang :: tr
{ 'organization too long' };
1759 goto ROOTCERT_ERROR
;
1761 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1762 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1763 goto ROOTCERT_ERROR
;
1765 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
1766 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
1767 goto ROOTCERT_ERROR
;
1769 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
1770 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
1771 goto ROOTCERT_ERROR
;
1773 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
1774 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1775 goto ROOTCERT_ERROR
;
1777 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
1778 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1779 goto ROOTCERT_ERROR
;
1781 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1782 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1783 goto ROOTCERT_ERROR
;
1785 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1786 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1787 goto ROOTCERT_ERROR
;
1789 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1790 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1791 goto ROOTCERT_ERROR
;
1793 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1794 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1795 goto ROOTCERT_ERROR
;
1798 # Copy the cgisettings to vpnsettings and save the configfile
1799 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
1800 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
1801 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
1802 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
1803 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
1804 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
1805 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
1806 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1808 # Replace empty strings with a .
1809 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
1810 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
1811 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
1814 #system ('/bin/touch', "${General::swroot}/ovpn/gencanow");
1816 # Create the CA certificate
1817 my $pid = open ( OPENSSL
, "|-" );
1818 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1819 if ( $pid ) { # parent
1820 print OPENSSL
" $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1821 print OPENSSL
" $state \n " ;
1822 print OPENSSL
" $city \n " ;
1823 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1824 print OPENSSL
" $ou \n " ;
1825 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
1826 print OPENSSL
" $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1829 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1830 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1831 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1832 goto ROOTCERT_ERROR
;
1835 unless ( exec ( '/usr/bin/openssl' , 'req' , '-x509' , '-nodes' ,
1836 '-days' , '999999' , '-newkey' , 'rsa:4096' , '-sha512' ,
1837 '-keyout' , "${General::swroot}/ovpn/ca/cakey.pem" ,
1838 '-out' , "${General::swroot}/ovpn/ca/cacert.pem" ,
1839 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
1840 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1841 goto ROOTCERT_ERROR
;
1845 # Create the Host certificate request
1846 $pid = open ( OPENSSL
, "|-" );
1847 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1848 if ( $pid ) { # parent
1849 print OPENSSL
" $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1850 print OPENSSL
" $state \n " ;
1851 print OPENSSL
" $city \n " ;
1852 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1853 print OPENSSL
" $ou \n " ;
1854 print OPENSSL
" $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
1855 print OPENSSL
" $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1856 print OPENSSL
". \n " ;
1857 print OPENSSL
". \n " ;
1860 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1861 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1862 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1863 goto ROOTCERT_ERROR
;
1866 unless ( exec ( '/usr/bin/openssl' , 'req' , '-nodes' ,
1867 '-newkey' , 'rsa:4096' ,
1868 '-keyout' , "${General::swroot}/ovpn/certs/serverkey.pem" ,
1869 '-out' , "${General::swroot}/ovpn/certs/serverreq.pem" ,
1870 '-extensions' , 'server' ,
1871 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
1872 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1873 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1874 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1875 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1876 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1877 goto ROOTCERT_ERROR
;
1881 # Sign the host certificate request
1882 # This system call is safe, because all argeuments are passed as an array.
1883 system ( '/usr/bin/openssl' , 'ca' , '-days' , '999999' ,
1884 '-batch' , '-notext' ,
1885 '-in' , "${General::swroot}/ovpn/certs/serverreq.pem" ,
1886 '-out' , "${General::swroot}/ovpn/certs/servercert.pem" ,
1887 '-extensions' , 'server' ,
1888 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
1890 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1891 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1892 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1893 unlink ( "${General::swroot}/ovpn/serverkey.pem" );
1894 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1895 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1896 & newcleanssldatabase
();
1897 goto ROOTCERT_ERROR
;
1899 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1900 & deletebackupcert
();
1903 # Create an empty CRL
1904 # System call is safe, because all arguments are passed as array.
1905 system ( '/usr/bin/openssl' , 'ca' , '-gencrl' ,
1906 '-out' , "${General::swroot}/ovpn/crls/cacrl.pem" ,
1907 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
1909 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1910 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1911 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1912 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1913 unlink ( "${General::swroot}/ovpn/crls/cacrl.pem" );
1914 & cleanssldatabase
();
1915 goto ROOTCERT_ERROR
;
1917 # &cleanssldatabase();
1919 # Create ta.key for tls-auth
1920 # This system call is safe, because all arguments are passed as an array.
1921 system ( '/usr/sbin/openvpn' , '--genkey' , 'secret' , "${General::swroot}/ovpn/certs/ta.key" );
1923 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1924 & cleanssldatabase
();
1925 goto ROOTCERT_ERROR
;
1927 goto ROOTCERT_SUCCESS
;
1930 if ( $cgiparams { 'ACTION' } ne '' ) {
1931 & Header
:: showhttpheaders
();
1932 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
1933 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1934 if ( $errormessage ) {
1935 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
1936 print "<class name='base'> $errormessage " ;
1937 print " </class>" ;
1938 & Header
:: closebox
();
1940 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'generate root/host certificates'}:" );
1942 <form method='post' enctype='multipart/form-data'>
1943 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1944 <tr><td width='30%' class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
1945 <td width='35%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td>
1946 <td width='35%' colspan='2'> </td></tr>
1947 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}: <img src='/blob.gif' alt='*' /></td>
1948 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td>
1949 <td colspan='2'> </td></tr>
1950 <tr><td class='base'> $Lang ::tr{'your e-mail'}:</td>
1951 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td>
1952 <td colspan='2'> </td></tr>
1953 <tr><td class='base'> $Lang ::tr{'your department'}:</td>
1954 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td>
1955 <td colspan='2'> </td></tr>
1956 <tr><td class='base'> $Lang ::tr{'city'}:</td>
1957 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td>
1958 <td colspan='2'> </td></tr>
1959 <tr><td class='base'> $Lang ::tr{'state or province'}:</td>
1960 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td>
1961 <td colspan='2'> </td></tr>
1962 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1963 <td class='base'><select name='ROOTCERT_COUNTRY'>
1967 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1968 print "<option value=' $Countries ::countries{ $country }'" ;
1969 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1970 print " selected='selected'" ;
1972 print "> $country </option>" ;
1978 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /></td>
1979 <td> </td><td> </td></tr>
1980 <tr><td class='base' colspan='4' align='left'>
1981 <img src='/blob.gif' valign='top' alt='*' /> $Lang ::tr{'required field'}</td></tr>
1982 <tr><td colspan='2'><br></td></tr>
1985 <table width='100%'>
1986 <tr><td colspan='4'><hr></td></tr>
1987 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}: <img src='/blob.gif' alt='*' /></td>
1988 <td nowrap='nowrap'><input type='file' name='FH' size='32'></td>
1989 <td colspan='2'> </td></tr>
1990 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
1991 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td>
1992 <td colspan='2'> </td></tr>
1994 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td>
1995 <td colspan='2'> </td></tr>
1996 <tr><td class='base' colspan='4' align='left'>
1997 <img src='/blob.gif' valign='top' alt='*' > $Lang ::tr{'required field'}</td>
2002 & Header
:: closebox
();
2003 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2004 & Header
:: closebigbox
();
2005 & Header
:: closepage
();
2010 & General
:: system ( "chmod" , "600" , "${General::swroot}/ovpn/certs/serverkey.pem" );
2011 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2012 # $vpnsettings{'ENABLE_BLUE'} eq 'on') {
2013 # system('/usr/local/bin/ipsecctrl', 'S');
2017 ### Enable/Disable connection
2024 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
2026 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2027 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2029 my @ps = & General
:: system_output
( "/bin/ps" , "ax" );
2031 if ( grep ( /$confighash{$cgiparams{'KEY'}}[1]/ , @ps )) {
2035 if ( $confighash { $cgiparams { 'KEY' }}) {
2036 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
2037 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
2038 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2040 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
2041 & General
:: system ( "/usr/local/bin/openvpnctrl" , "-sn2n" , " $confighash { $cgiparams {'KEY'}}[1]" );
2042 & writecollectdconf
();
2046 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
2047 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2049 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
2050 if ( $n2nactive ne '' ) {
2051 & General
:: system ( "/usr/local/bin/openvpnctrl" , "-kn2n" , " $confighash { $cgiparams {'KEY'}}[1]" );
2052 & writecollectdconf
();
2059 ### Download OpenVPN client package
2063 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'dl client arch' }) {
2064 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2065 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2067 my $clientovpn = '' ;
2069 my $tempdir = tempdir
( CLEANUP
=> 1 );
2070 my $zippath = " $tempdir /" ;
2076 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
2078 my $zipname = " $confighash { $cgiparams {'KEY'}}[1]-Client.zip" ;
2079 my $zippathname = " $zippath $zipname " ;
2080 $clientovpn = " $confighash { $cgiparams {'KEY'}}[1].conf" ;
2081 my @ovsubnettemp = split ( /\./ , $confighash { $cgiparams { 'KEY' }}[ 27 ]);
2082 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
2084 my @remsubnet = split ( /\/ /, $confighash { $cgiparams { 'KEY' }}[ 8 ]);
2085 my $n2nfragment = '' ;
2087 open ( CLIENTCONF
, "> $tempdir / $clientovpn " ) or die "Unable to open tempfile: $!" ;
2088 flock CLIENTCONF
, 2 ;
2090 my $zip = Archive
:: Zip
-> new ();
2091 print CLIENTCONF
"# IPFire n2n Open VPN Client Config by ummeegge und m.a.d \n " ;
2092 print CLIENTCONF
"# \n " ;
2093 print CLIENTCONF
"# User Security \n " ;
2094 print CLIENTCONF
"user nobody \n " ;
2095 print CLIENTCONF
"group nobody \n " ;
2096 print CLIENTCONF
"persist-tun \n " ;
2097 print CLIENTCONF
"persist-key \n " ;
2098 print CLIENTCONF
"script-security 2 \n " ;
2099 print CLIENTCONF
"# IP/DNS for remote Server Gateway \n " ;
2100 print CLIENTCONF
"remote $vpnsettings {'VPN_IP'} \n " ;
2101 print CLIENTCONF
"float \n " ;
2102 print CLIENTCONF
"# IP adresses of the VPN Subnet \n " ;
2103 print CLIENTCONF
"ifconfig $ovsubnet .2 $ovsubnet .1 \n " ;
2104 print CLIENTCONF
"# Server Gateway Network \n " ;
2105 print CLIENTCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
2106 print CLIENTCONF
"# tun Device \n " ;
2107 print CLIENTCONF
"dev tun \n " ;
2108 print CLIENTCONF
"#Logfile for statistics \n " ;
2109 print CLIENTCONF
"status-version 1 \n " ;
2110 print CLIENTCONF
"status /var/run/openvpn/ $cgiparams {'NAME'}-n2n 10 \n " ;
2111 print CLIENTCONF
"# Port and Protokoll \n " ;
2112 print CLIENTCONF
"port $confighash { $cgiparams {'KEY'}}[29] \n " ;
2114 if ( $confighash { $cgiparams { 'KEY' }}[ 28 ] eq 'tcp' ) {
2115 print CLIENTCONF
"proto tcp4-client \n " ;
2116 print CLIENTCONF
"# Packet size \n " ;
2117 if ( $confighash { $cgiparams { 'KEY' }}[ 31 ] eq '' ) { $tunmtu = '1400' } else { $tunmtu = $confighash { $cgiparams { 'KEY' }}[ 31 ]};
2118 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
2121 if ( $confighash { $cgiparams { 'KEY' }}[ 28 ] eq 'udp' ) {
2122 print CLIENTCONF
"proto udp4 \n " ;
2123 print CLIENTCONF
"# Paketsize \n " ;
2124 if ( $confighash { $cgiparams { 'KEY' }}[ 31 ] eq '' ) { $tunmtu = '1500' } else { $tunmtu = $confighash { $cgiparams { 'KEY' }}[ 31 ]};
2125 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
2126 if ( $confighash { $cgiparams { 'KEY' }}[ 24 ] ne '' ) { print CLIENTCONF
"fragment $confighash { $cgiparams {'KEY'}}[24] \n " ;}
2127 if ( $confighash { $cgiparams { 'KEY' }}[ 23 ] eq 'on' ) { print CLIENTCONF
"mssfix \n " ;} else { print CLIENTCONF
"mssfix 0 \n " ; }
2129 # Check host certificate if X509 is RFC3280 compliant.
2130 # If not, old --ns-cert-type directive will be used.
2131 # If appropriate key usage extension exists, new --remote-cert-tls directive will be used.
2132 my @hostcert = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "${General::swroot}/ovpn/certs/servercert.pem" );
2133 if (! grep ( /TLS Web Server Authentication/ , @hostcert )) {
2134 print CLIENTCONF
"ns-cert-type server \n " ;
2136 print CLIENTCONF
"remote-cert-tls server \n " ;
2138 print CLIENTCONF
"# Auth. Client \n " ;
2139 print CLIENTCONF
"tls-client \n " ;
2140 print CLIENTCONF
"# Cipher \n " ;
2141 print CLIENTCONF
"cipher $confighash { $cgiparams {'KEY'}}[40] \n " ;
2142 if ( $confighash { $cgiparams { 'KEY' }}[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ) {
2143 print CLIENTCONF
"pkcs12 ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12 \r\n " ;
2144 $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 " ;
2147 # If GCM cipher is used, do not use --auth
2148 if (( $confighash { $cgiparams { 'KEY' }}[ 40 ] eq 'AES-256-GCM' ) ||
2149 ( $confighash { $cgiparams { 'KEY' }}[ 40 ] eq 'AES-192-GCM' ) ||
2150 ( $confighash { $cgiparams { 'KEY' }}[ 40 ] eq 'AES-128-GCM' )) {
2151 print CLIENTCONF
unless "# HMAC algorithm \n " ;
2152 print CLIENTCONF
unless "auth $confighash { $cgiparams {'KEY'}}[39] \n " ;
2154 print CLIENTCONF
"# HMAC algorithm \n " ;
2155 print CLIENTCONF
"auth $confighash { $cgiparams {'KEY'}}[39] \n " ;
2158 if ( $confighash { $cgiparams { 'KEY' }}[ 30 ] eq 'on' ) {
2159 print CLIENTCONF
"# Enable Compression \n " ;
2160 print CLIENTCONF
"comp-lzo \n " ;
2162 print CLIENTCONF
"# Debug Level \n " ;
2163 print CLIENTCONF
"verb 3 \n " ;
2164 print CLIENTCONF
"# Tunnel check \n " ;
2165 print CLIENTCONF
"keepalive 10 60 \n " ;
2166 print CLIENTCONF
"# Start as daemon \n " ;
2167 print CLIENTCONF
"daemon $confighash { $cgiparams {'KEY'}}[1]n2n \n " ;
2168 print CLIENTCONF
"writepid /var/run/ $confighash { $cgiparams {'KEY'}}[1]n2n.pid \n " ;
2169 print CLIENTCONF
"# Activate Management Interface and Port \n " ;
2170 if ( $confighash { $cgiparams { 'KEY' }}[ 22 ] eq '' ) { print CLIENTCONF
"management localhost $confighash { $cgiparams {'KEY'}}[29] \n " }
2171 else { print CLIENTCONF
"management localhost $confighash { $cgiparams {'KEY'}}[22] \n " };
2172 print CLIENTCONF
"# remsub $confighash { $cgiparams {'KEY'}}[11] \n " ;
2173 if (& iscertlegacy
( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]" )) {
2174 print CLIENTCONF
"providers legacy default \n " ;
2181 $zip -> addFile ( " $tempdir / $clientovpn " , $clientovpn ) or die "Can't add file $clientovpn \n " ;
2182 my $status = $zip -> writeToFileNamed ( $zippathname );
2184 open ( DLFILE
, "< $zippathname " ) or die "Unable to open $zippathname : $!" ;
2185 @fileholder = < DLFILE
>;
2186 print "Content-Type:application/x-download \n " ;
2187 print "Content-Disposition:attachment;filename= $zipname \n\n " ;
2193 my $zipname = " $confighash { $cgiparams {'KEY'}}[1]-TO-IPFire.zip" ;
2194 my $zippathname = " $zippath $zipname " ;
2195 $clientovpn = " $confighash { $cgiparams {'KEY'}}[1]-TO-IPFire.ovpn" ;
2201 open ( CLIENTCONF
, "> $tempdir / $clientovpn " ) or die "Unable to open tempfile: $!" ;
2202 flock CLIENTCONF
, 2 ;
2204 my $zip = Archive
:: Zip
-> new ();
2206 print CLIENTCONF
"#OpenVPN Client conf \r\n " ;
2207 print CLIENTCONF
"tls-client \r\n " ;
2208 print CLIENTCONF
"client \r\n " ;
2209 print CLIENTCONF
"nobind \r\n " ;
2210 print CLIENTCONF
"dev tun \r\n " ;
2211 print CLIENTCONF
"proto $vpnsettings {'DPROTOCOL'} \r\n " ;
2212 print CLIENTCONF
"tun-mtu $vpnsettings {'DMTU'} \r\n " ;
2214 if ( $vpnsettings { 'ENABLED' } eq 'on' ){
2215 print CLIENTCONF
"remote $vpnsettings {'VPN_IP'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2216 if ( $vpnsettings { 'ENABLED_BLUE' } eq 'on' && (& haveBlueNet
())){
2217 print CLIENTCONF
"#comment the above line and uncomment the next line, if you want to connect on the Blue interface \r\n " ;
2218 print CLIENTCONF
";remote $netsettings {'BLUE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2220 if ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
2221 print CLIENTCONF
"#comment the above line and uncomment the next line, if you want to connect on the Orange interface \r\n " ;
2222 print CLIENTCONF
";remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2224 } elsif ( $vpnsettings { 'ENABLED_BLUE' } eq 'on' && (& haveBlueNet
())){
2225 print CLIENTCONF
"remote $netsettings {'BLUE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2226 if ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
2227 print CLIENTCONF
"#comment the above line and uncomment the next line, if you want to connect on the Orange interface \r\n " ;
2228 print CLIENTCONF
";remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2230 } elsif ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
2231 print CLIENTCONF
"remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2234 my $file_crt = new File
:: Temp
( UNLINK
=> 1 );
2235 my $file_key = new File
:: Temp
( UNLINK
=> 1 );
2236 my $include_certs = 0 ;
2238 if ( $confighash { $cgiparams { 'KEY' }}[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ) {
2239 if ( $cgiparams { 'MODE' } eq 'insecure' ) {
2243 print CLIENTCONF
";ca cacert.pem \r\n " ;
2244 $zip -> addFile ( "${General::swroot}/ovpn/ca/cacert.pem" , "cacert.pem" ) or die "Can't add file cacert.pem \n " ;
2246 # Extract the certificate
2247 # This system call is safe, because all arguments are passed as an array.
2248 if (& iscertlegacy
( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]" )) {
2249 system ( '/usr/bin/openssl' , 'pkcs12' , '-legacy' , '-in' , "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ,
2250 '-clcerts' , '-nokeys' , '-nodes' , '-out' , " $file_crt " , '-passin' , 'pass:' );
2252 die "openssl error: $?" ;
2255 system ( '/usr/bin/openssl' , 'pkcs12' , '-in' , "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ,
2256 '-clcerts' , '-nokeys' , '-nodes' , '-out' , " $file_crt " , '-passin' , 'pass:' );
2258 die "openssl error: $?" ;
2262 $zip -> addFile ( " $file_crt " , " $confighash { $cgiparams {'KEY'}}[1].pem" ) or die ;
2263 print CLIENTCONF
";cert $confighash { $cgiparams {'KEY'}}[1].pem \r\n " ;
2266 # This system call is safe, because all arguments are passed as an array.
2267 if (& iscertlegacy
( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]" )) {
2268 system ( '/usr/bin/openssl' , 'pkcs12' , '-legacy' , '-in' , "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ,
2269 '-nocerts' , '-nodes' , '-out' , " $file_key " , '-passin' , 'pass:' );
2271 die "openssl error: $?" ;
2274 system ( '/usr/bin/openssl' , 'pkcs12' , '-in' , "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ,
2275 '-nocerts' , '-nodes' , '-out' , " $file_key " , '-passin' , 'pass:' );
2277 die "openssl error: $?" ;
2281 $zip -> addFile ( " $file_key " , " $confighash { $cgiparams {'KEY'}}[1].key" ) or die ;
2282 print CLIENTCONF
";key $confighash { $cgiparams {'KEY'}}[1].key \r\n " ;
2284 print CLIENTCONF
"pkcs12 $confighash { $cgiparams {'KEY'}}[1].p12 \r\n " ;
2285 $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 " ;
2288 print CLIENTCONF
"ca cacert.pem \r\n " ;
2289 print CLIENTCONF
"cert $confighash { $cgiparams {'KEY'}}[1]cert.pem \r\n " ;
2290 print CLIENTCONF
"key $confighash { $cgiparams {'KEY'}}[1].key \r\n " ;
2291 $zip -> addFile ( "${General::swroot}/ovpn/ca/cacert.pem" , "cacert.pem" ) or die "Can't add file cacert.pem \n " ;
2292 $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 " ;
2294 print CLIENTCONF
"cipher $vpnsettings {DCIPHER} \r\n " ;
2295 print CLIENTCONF
"auth $vpnsettings {'DAUTH'} \r\n " ;
2297 if ( $vpnsettings { 'TLSAUTH' } eq 'on' ) {
2298 if ( $cgiparams { 'MODE' } eq 'insecure' ) {
2299 print CLIENTCONF
";" ;
2301 print CLIENTCONF
"tls-auth ta.key \r\n " ;
2302 $zip -> addFile ( "${General::swroot}/ovpn/certs/ta.key" , "ta.key" ) or die "Can't add file ta.key \n " ;
2304 if ( $vpnsettings { DCOMPLZO
} eq 'on' ) {
2305 print CLIENTCONF
"comp-lzo \r\n " ;
2307 print CLIENTCONF
"verb 3 \r\n " ;
2308 # Check host certificate if X509 is RFC3280 compliant.
2309 # If not, old --ns-cert-type directive will be used.
2310 # If appropriate key usage extension exists, new --remote-cert-tls directive will be used.
2311 my @hostcert = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "${General::swroot}/ovpn/certs/servercert.pem" );
2312 if (! grep ( /TLS Web Server Authentication/ , @hostcert )) {
2313 print CLIENTCONF
"ns-cert-type server \r\n " ;
2315 print CLIENTCONF
"remote-cert-tls server \r\n " ;
2317 print CLIENTCONF
"verify-x509-name $vpnsettings {ROOTCERT_HOSTNAME} name \r\n " ;
2318 if ( $vpnsettings { MSSFIX
} eq 'on' ) {
2319 print CLIENTCONF
"mssfix \r\n " ;
2321 print CLIENTCONF
"mssfix 0 \r\n " ;
2323 if ( $vpnsettings { FRAGMENT
} ne '' && $vpnsettings { DPROTOCOL
} ne 'tcp' ) {
2324 print CLIENTCONF
"fragment $vpnsettings {'FRAGMENT'} \r\n " ;
2327 # Disable storing any credentials in memory
2328 print CLIENTCONF
"auth-nocache \r\n " ;
2330 # Set a fake user name for authentication
2331 print CLIENTCONF
"auth-token-user USER \r\n " ;
2332 print CLIENTCONF
"auth-token TOTP \r\n " ;
2334 # If the server is asking for TOTP this needs to happen interactively
2335 print CLIENTCONF
"auth-retry interact \r\n " ;
2337 # Add provider line if certificate is legacy type
2338 if (& iscertlegacy
( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]" )) {
2339 print CLIENTCONF
"providers legacy default \r\n " ;
2342 if ( $include_certs ) {
2343 print CLIENTCONF
" \r\n " ;
2346 open ( FILE
, "<${General::swroot}/ovpn/ca/cacert.pem" );
2347 print CLIENTCONF
"<ca> \r\n " ;
2350 print CLIENTCONF
" $_ \r\n " ;
2352 print CLIENTCONF
"</ca> \r\n\r\n " ;
2356 open ( FILE
, "< $file_crt " );
2357 print CLIENTCONF
"<cert> \r\n " ;
2360 print CLIENTCONF
" $_ \r\n " ;
2362 print CLIENTCONF
"</cert> \r\n\r\n " ;
2366 open ( FILE
, "< $file_key " );
2367 print CLIENTCONF
"<key> \r\n " ;
2370 print CLIENTCONF
" $_ \r\n " ;
2372 print CLIENTCONF
"</key> \r\n\r\n " ;
2376 if ( $vpnsettings { 'TLSAUTH' } eq 'on' ) {
2377 open ( FILE
, "<${General::swroot}/ovpn/certs/ta.key" );
2378 print CLIENTCONF
"<tls-auth> \r\n " ;
2381 print CLIENTCONF
" $_ \r\n " ;
2383 print CLIENTCONF
"</tls-auth> \r\n\r\n " ;
2388 # Print client.conf.local if entries exist to client.ovpn
2389 if (!- z
$local_clientconf && $vpnsettings { 'ADDITIONAL_CONFIGS' } eq 'on' ) {
2390 open ( LCC
, " $local_clientconf " );
2391 print CLIENTCONF
" \n #--------------------------- \n " ;
2392 print CLIENTCONF
"# Start of custom directives \n " ;
2393 print CLIENTCONF
"# from client.conf.local \n " ;
2394 print CLIENTCONF
"#--------------------------- \n\n " ;
2396 print CLIENTCONF
$_ ;
2398 print CLIENTCONF
" \n #--------------------------- \n " ;
2399 print CLIENTCONF
"# End of custom directives \n " ;
2400 print CLIENTCONF
"#--------------------------- \n\n " ;
2405 $zip -> addFile ( " $tempdir / $clientovpn " , $clientovpn ) or die "Can't add file $clientovpn \n " ;
2406 my $status = $zip -> writeToFileNamed ( $zippathname );
2408 open ( DLFILE
, "< $zippathname " ) or die "Unable to open $zippathname : $!" ;
2409 @fileholder = < DLFILE
>;
2410 print "Content-Type:application/x-download \n " ;
2411 print "Content-Disposition:attachment;filename= $zipname \n\n " ;
2419 ### Remove connection
2423 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
2424 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2425 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2427 if ( $confighash { $cgiparams { 'KEY' }}) {
2428 # Revoke certificate if certificate was deleted and rewrite the CRL
2429 & General
:: system ( "/usr/bin/openssl" , "ca" , "-revoke" , "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" , "-config" , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
2430 & General
:: system ( "/usr/bin/openssl" , "ca" , "-gencrl" , "-out" , "${General::swroot}/ovpn/crls/cacrl.pem" , "-config" , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
2436 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ) {
2437 # Stop the N2N connection before it is removed
2438 & General
:: system ( "/usr/local/bin/openvpnctrl" , "-kn2n" , " $confighash { $cgiparams {'KEY'}}[1]" );
2440 my $conffile = glob ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]/ $confighash { $cgiparams {'KEY'}}[1].conf" );
2441 my $certfile = glob ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
2445 if (- e
"${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]" ) {
2446 rmdir ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]" ) || die "Kann Verzeichnis nicht loeschen: $!" ;
2450 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
2451 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
2453 # A.Marx CCD delete ccd files and routes
2455 if (- f
"${General::swroot}/ovpn/ccd/ $confighash { $cgiparams {'KEY'}}[2]" )
2457 unlink "${General::swroot}/ovpn/ccd/ $confighash { $cgiparams {'KEY'}}[2]" ;
2460 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
2461 foreach my $key ( keys %ccdroutehash ) {
2462 if ( $ccdroutehash { $key }[ 0 ] eq $confighash { $cgiparams { 'KEY' }}[ 1 ]){
2463 delete $ccdroutehash { $key };
2466 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
2468 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
2469 foreach my $key ( keys %ccdroute2hash ) {
2470 if ( $ccdroute2hash { $key }[ 0 ] eq $confighash { $cgiparams { 'KEY' }}[ 1 ]){
2471 delete $ccdroute2hash { $key };
2474 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
2478 # Update collectd configuration and delete all RRD files of the removed connection
2479 & writecollectdconf
();
2480 & General
:: system ( "/usr/local/bin/openvpnctrl" , "-drrd" , " $confighash { $cgiparams {'KEY'}}[1]" );
2482 delete $confighash { $cgiparams { 'KEY' }};
2483 & General
:: system ( "/usr/bin/openssl" , "ca" , "-gencrl" , "-out" , "${General::swroot}/ovpn/crls/cacrl.pem" , "-config" , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
2484 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2487 $errormessage = $Lang :: tr
{ 'invalid key' };
2489 & General
:: firewall_reload
();
2492 ### Download PKCS12 file
2494 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
2495 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2497 print "Content-Disposition: filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
2498 print "Content-Type: application/octet-stream \r\n\r\n " ;
2500 open ( FILE
, "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
2508 ### Display certificate
2510 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
2511 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2513 if ( - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
2514 & Header
:: showhttpheaders
();
2515 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
2516 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2517 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'certificate'}:" );
2518 my @output = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
2519 my $output = & Header
:: cleanhtml
( join ( "" , @output ), "y" );
2520 print "<pre> $output </pre> \n " ;
2521 & Header
:: closebox
();
2522 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2523 & Header
:: closebigbox
();
2524 & Header
:: closepage
();
2529 ### Display OTP QRCode
2531 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show otp qrcode' }) {
2532 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2534 my $qrcode = Imager
:: QRCode
-> new (
2541 lightcolor
=> Imager
:: Color
-> new ( 255 , 255 , 255 ),
2542 darkcolor
=> Imager
:: Color
-> new ( 0 , 0 , 0 ),
2544 my $cn = uri_encode
( $confighash { $cgiparams { 'KEY' }}[ 2 ]);
2545 my $secret = encode_base32
( pack ( 'H*' , $confighash { $cgiparams { 'KEY' }}[ 44 ]));
2546 my $issuer = uri_encode
( " $mainsettings {'HOSTNAME'}. $mainsettings {'DOMAINNAME'}" );
2547 my $qrcodeimg = $qrcode -> plot ( "otpauth://totp/ $cn ?secret= $secret &issuer= $issuer " );
2549 $qrcodeimg -> write ( data
=> \
$qrcodeimgdata , type
=> 'png' )
2550 or die $qrcodeimg -> errstr ;
2551 $qrcodeimgdata = encode_base64
( $qrcodeimgdata , '' );
2553 & Header
:: showhttpheaders
();
2554 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
2555 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2556 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'otp qrcode'}:" );
2558 $Lang ::tr{'secret'}: $secret </br></br>
2559 <img alt=" $Lang ::tr{'otp qrcode'}" src="data:image/png;base64, $qrcodeimgdata ">
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 ### Display Diffie-Hellman key
2570 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show dh' }) {
2572 if (! - e
" $dhparameter " ) {
2573 $errormessage = $Lang :: tr
{ 'not present' };
2575 & Header
:: showhttpheaders
();
2576 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
2577 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2578 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'dh'}:" );
2579 my @output = & General
:: system_output
( "/usr/bin/openssl" , "dhparam" , "-text" , "-in" , " $dhparameter " );
2580 my $output = & Header
:: cleanhtml
( join ( "" , @output ) , "y" );
2581 print "<pre> $output </pre> \n " ;
2582 & Header
:: closebox
();
2583 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2584 & Header
:: closebigbox
();
2585 & Header
:: closepage
();
2590 ### Display tls-auth key
2592 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show tls-auth key' }) {
2594 if (! - e
"${General::swroot}/ovpn/certs/ta.key" ) {
2595 $errormessage = $Lang :: tr
{ 'not present' };
2597 & Header
:: showhttpheaders
();
2598 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
2599 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2600 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'ta key'}:" );
2602 open ( FILE
, "${General::swroot}/ovpn/certs/ta.key" );
2603 my @output = < FILE
>;
2606 my $output = & Header
:: cleanhtml
( join ( "" , @output ), "y" );
2607 print "<pre> $output </pre> \n " ;
2608 & Header
:: closebox
();
2609 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2610 & Header
:: closebigbox
();
2611 & Header
:: closepage
();
2616 ### Display Certificate Revoke List
2618 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show crl' }) {
2619 # &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2621 if (! - e
"${General::swroot}/ovpn/crls/cacrl.pem" ) {
2622 $errormessage = $Lang :: tr
{ 'not present' };
2624 & Header
:: showhttpheaders
();
2625 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
2626 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2627 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'crl'}:" );
2628 my @output = & General
:: system_output
( "/usr/bin/openssl" , "crl" , "-text" , "-noout" , "-in" , "${General::swroot}/ovpn/crls/cacrl.pem" );
2629 my $output = & Header
:: cleanhtml
( join ( "" , @output ), "y" );
2630 print "<pre> $output </pre> \n " ;
2631 & Header
:: closebox
();
2632 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2633 & Header
:: closebigbox
();
2634 & Header
:: closepage
();
2639 ### Advanced Server Settings
2642 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced server' }) {
2647 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%cgiparams );
2651 # if ($cgiparams{'CLIENT2CLIENT'} eq '') {
2652 # $cgiparams{'CLIENT2CLIENT'} = 'on';
2655 if ( $cgiparams { 'MAX_CLIENTS' } eq '' ) {
2656 $cgiparams { 'MAX_CLIENTS' } = '100' ;
2658 if ( $cgiparams { 'KEEPALIVE_1' } eq '' ) {
2659 $cgiparams { 'KEEPALIVE_1' } = '10' ;
2661 if ( $cgiparams { 'KEEPALIVE_2' } eq '' ) {
2662 $cgiparams { 'KEEPALIVE_2' } = '60' ;
2664 if ( $cgiparams { 'LOG_VERB' } eq '' ) {
2665 $cgiparams { 'LOG_VERB' } = '3' ;
2667 if ( $cgiparams { 'TLSAUTH' } eq '' ) {
2668 $cgiparams { 'TLSAUTH' } = 'off' ;
2670 $checked { 'CLIENT2CLIENT' }{ 'off' } = '' ;
2671 $checked { 'CLIENT2CLIENT' }{ 'on' } = '' ;
2672 $checked { 'CLIENT2CLIENT' }{ $cgiparams { 'CLIENT2CLIENT' }} = 'CHECKED' ;
2673 $checked { 'REDIRECT_GW_DEF1' }{ 'off' } = '' ;
2674 $checked { 'REDIRECT_GW_DEF1' }{ 'on' } = '' ;
2675 $checked { 'REDIRECT_GW_DEF1' }{ $cgiparams { 'REDIRECT_GW_DEF1' }} = 'CHECKED' ;
2676 $checked { 'DCOMPLZO' }{ 'off' } = '' ;
2677 $checked { 'DCOMPLZO' }{ 'on' } = '' ;
2678 $checked { 'DCOMPLZO' }{ $cgiparams { 'DCOMPLZO' }} = 'CHECKED' ;
2679 $checked { 'ADDITIONAL_CONFIGS' }{ 'off' } = '' ;
2680 $checked { 'ADDITIONAL_CONFIGS' }{ 'on' } = '' ;
2681 $checked { 'ADDITIONAL_CONFIGS' }{ $cgiparams { 'ADDITIONAL_CONFIGS' }} = 'CHECKED' ;
2682 $checked { 'MSSFIX' }{ 'off' } = '' ;
2683 $checked { 'MSSFIX' }{ 'on' } = '' ;
2684 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
2685 $selected { 'LOG_VERB' }{ '0' } = '' ;
2686 $selected { 'LOG_VERB' }{ '1' } = '' ;
2687 $selected { 'LOG_VERB' }{ '2' } = '' ;
2688 $selected { 'LOG_VERB' }{ '3' } = '' ;
2689 $selected { 'LOG_VERB' }{ '4' } = '' ;
2690 $selected { 'LOG_VERB' }{ '5' } = '' ;
2691 $selected { 'LOG_VERB' }{ '6' } = '' ;
2692 $selected { 'LOG_VERB' }{ '7' } = '' ;
2693 $selected { 'LOG_VERB' }{ '8' } = '' ;
2694 $selected { 'LOG_VERB' }{ '9' } = '' ;
2695 $selected { 'LOG_VERB' }{ '10' } = '' ;
2696 $selected { 'LOG_VERB' }{ '11' } = '' ;
2697 $selected { 'LOG_VERB' }{ $cgiparams { 'LOG_VERB' }} = 'SELECTED' ;
2699 & Header
:: showhttpheaders
();
2700 & Header
:: openpage
( $Lang :: tr
{ 'status ovpn' }, 1 , '' );
2701 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
2702 if ( $errormessage ) {
2703 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
2704 print "<class name='base'> $errormessage \n " ;
2705 print " </class> \n " ;
2706 & Header
:: closebox
();
2708 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'advanced server' });
2710 <form method='post' enctype='multipart/form-data'>
2711 <table width='100%' border=0>
2713 <td colspan='4'><b> $Lang ::tr{'dhcp-options'}</b></td>
2716 <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
2719 <td class='base'>Domain</td>
2720 <td><input type='TEXT' name='DHCP_DOMAIN' value=' $cgiparams {'DHCP_DOMAIN'}' size='30' /></td>
2723 <td class='base'>DNS</td>
2724 <td><input type='TEXT' name='DHCP_DNS' value=' $cgiparams {'DHCP_DNS'}' size='30' /></td>
2727 <td class='base'>WINS</td>
2728 <td><input type='TEXT' name='DHCP_WINS' value=' $cgiparams {'DHCP_WINS'}' size='30' /></td>
2731 <td colspan='4'><b> $Lang ::tr{'ovpn routes push options'}</b></td>
2734 <td class='base'> $Lang ::tr{'ovpn routes push'}</td>
2736 <textarea name='ROUTES_PUSH' cols='26' rows='6' wrap='off'>
2740 if ( $cgiparams { 'ROUTES_PUSH' } ne '' )
2742 print $cgiparams { 'ROUTES_PUSH' };
2751 <table width='100%'>
2753 <td class='base'><b> $Lang ::tr{'misc-options'}</b></td>
2757 <td width='20%'></td> <td width='15%'> </td><td width='35%'> </td><td width='20%'></td><td width='35%'></td>
2761 <td class='base'>Client-To-Client</td>
2762 <td><input type='checkbox' name='CLIENT2CLIENT' $checked {'CLIENT2CLIENT'}{'on'} /></td>
2766 <td class='base'>Redirect-Gateway def1</td>
2767 <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked {'REDIRECT_GW_DEF1'}{'on'} /></td>
2770 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'}</td>
2771 <td><input type='checkbox' name='DCOMPLZO' $checked {'DCOMPLZO'}{'on'} /></td>
2772 <td> $Lang ::tr{'openvpn default'}: off <font color='red'>( $Lang ::tr{'attention'} exploitable via Voracle)</font></td>
2776 <td class='base'> $Lang ::tr{'ovpn add conf'}</td>
2777 <td><input type='checkbox' name='ADDITIONAL_CONFIGS' $checked {'ADDITIONAL_CONFIGS'}{'on'} /></td>
2778 <td> $Lang ::tr{'openvpn default'}: off</td>
2782 <td class='base'>mssfix</td>
2783 <td><input type='checkbox' name='MSSFIX' $checked {'MSSFIX'}{'on'} /></td>
2784 <td> $Lang ::tr{'openvpn default'}: off</td>
2788 <td class='base'>fragment <br></td>
2789 <td><input type='TEXT' name='FRAGMENT' value=' $cgiparams {'FRAGMENT'}' size='10' /></td>
2794 <td class='base'>Max-Clients</td>
2795 <td><input type='text' name='MAX_CLIENTS' value=' $cgiparams {'MAX_CLIENTS'}' size='10' /></td>
2798 <td class='base'>Keepalive <br />
2799 (ping/ping-restart)</td>
2800 <td><input type='TEXT' name='KEEPALIVE_1' value=' $cgiparams {'KEEPALIVE_1'}' size='10' /></td>
2801 <td><input type='TEXT' name='KEEPALIVE_2' value=' $cgiparams {'KEEPALIVE_2'}' size='10' /></td>
2806 <table width='100%'>
2808 <td class='base'><b> $Lang ::tr{'log-options'}</b></td>
2811 <td width='20%'></td> <td width='30%'> </td><td width='25%'> </td><td width='25%'></td>
2814 <tr><td class='base'>VERB</td>
2815 <td><select name='LOG_VERB'>
2816 <option value='0' $selected {'LOG_VERB'}{'0'}>0</option>
2817 <option value='1' $selected {'LOG_VERB'}{'1'}>1</option>
2818 <option value='2' $selected {'LOG_VERB'}{'2'}>2</option>
2819 <option value='3' $selected {'LOG_VERB'}{'3'}>3</option>
2820 <option value='4' $selected {'LOG_VERB'}{'4'}>4</option>
2821 <option value='5' $selected {'LOG_VERB'}{'5'}>5</option>
2822 <option value='6' $selected {'LOG_VERB'}{'6'}>6</option>
2823 <option value='7' $selected {'LOG_VERB'}{'7'}>7</option>
2824 <option value='8' $selected {'LOG_VERB'}{'8'}>8</option>
2825 <option value='9' $selected {'LOG_VERB'}{'9'}>9</option>
2826 <option value='10' $selected {'LOG_VERB'}{'10'}>10</option>
2827 <option value='11' $selected {'LOG_VERB'}{'11'}>11</option>
2834 if ( - e
"/var/run/openvpn.pid" ){
2835 print " <br><b><font color='#990000'> $Lang ::tr{'attention'}:</b></font><br>
2836 $Lang ::tr{'server restart'}<br><br>
2839 <table width='100%'>
2842 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save-adv-options'}' disabled='disabled' /></td>
2843 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'cancel-adv-options'}' /></td>
2855 <table width='100%'>
2858 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save-adv-options'}' /></td>
2859 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'cancel-adv-options'}' /></td>
2867 & Header
:: closebox
();
2868 # print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
2869 & Header
:: closebigbox
();
2870 & Header
:: closepage
();
2874 # A.Marx CCD Add,delete or edit CCD net
2876 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ccd net' } ||
2877 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ccd add' } ||
2878 $cgiparams { 'ACTION' } eq "kill" ||
2879 $cgiparams { 'ACTION' } eq "edit" ||
2880 $cgiparams { 'ACTION' } eq 'editsave' ){
2881 & Header
:: showhttpheaders
();
2882 & Header
:: openpage
( $Lang :: tr
{ 'ccd net' }, 1 , '' );
2883 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2885 if ( $cgiparams { 'ACTION' } eq "kill" ){
2886 & delccdnet
( $cgiparams { 'net' });
2889 if ( $cgiparams { 'ACTION' } eq 'editsave' ){
2890 my ( $a , $b ) = split ( /\|/ , $cgiparams { 'ccdname' });
2891 if ( $a ne $b ){ & modccdnet
( $a , $b );}
2892 $cgiparams { 'ccdname' }= '' ;
2893 $cgiparams { 'ccdsubnet' }= '' ;
2896 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ccd add' }) {
2897 & addccdnet
( $cgiparams { 'ccdname' }, $cgiparams { 'ccdsubnet' });
2899 if ( $errormessage ) {
2900 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
2901 print "<class name='base'> $errormessage " ;
2902 print " </class>" ;
2903 & Header
:: closebox
();
2905 if ( $cgiparams { 'ACTION' } eq "edit" ){
2907 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd modify' });
2910 <table width='100%' border='0'>
2911 <tr><form method='post'>
2912 <td width='10%' nowrap='nowrap'> $Lang ::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value=' $cgiparams {'ccdname'}' /></td>
2913 <td width='8%'> $Lang ::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value=' $cgiparams {'ccdsubnet'}' readonly='readonly' /></td></tr>
2914 <tr><td colspan='4' align='right'><hr><input type='submit' value=' $Lang ::tr{'save'}' /><input type='hidden' name='ACTION' value='editsave'/>
2915 <input type='hidden' name='ccdname' value=' $cgiparams {'ccdname'}'/><input type='submit' value=' $Lang ::tr{'cancel'}' />
2920 & Header
:: closebox
();
2922 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd net' } );
2924 <table width='100%' border='0' cellpadding='0' cellspacing='1'>
2926 <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>
2931 if (! - e
"/var/run/openvpn.pid" ){
2932 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd add' });
2934 <table width='100%' border='0'>
2935 <tr><form method='post'>
2936 <td colspan='4'> $Lang ::tr{'ccd hint'}<br><br></td></tr>
2938 <td width='10%' nowrap='nwrap'> $Lang ::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value=' $cgiparams {'ccdname'}' /></td>
2939 <td width='8%'> $Lang ::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value=' $cgiparams {'ccdsubnet'}' /></td></tr>
2940 <tr><td colspan=4><hr /></td></tr><tr>
2941 <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>
2945 & Header
:: closebox
();
2947 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd net' } );
2948 if ( - e
"/var/run/openvpn.pid" ){
2949 print "<b> $Lang ::tr{'attention'}:</b><br>" ;
2950 print " $Lang ::tr{'ccd noaddnet'}<br><hr>" ;
2954 <table width='100%' cellpadding='0' cellspacing='1'>
2956 <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>
2961 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
2964 foreach my $key ( sort { uc ( $ccdconfhash { $a }[ 0 ]) cmp uc ( $ccdconfhash { $b }[ 0 ]) } keys %ccdconfhash ) {
2965 @ccdconf =( $ccdconfhash { $key }[ 0 ], $ccdconfhash { $key }[ 1 ]);
2967 my $ccdhosts = & hostsinnet
( $ccdconf [ 0 ]);
2968 if ( $count % 2 ){ print " <tr bgcolor=' $color {'color22'}'>" ;}
2969 else { print " <tr bgcolor=' $color {'color20'}'>" ;}
2970 print "<td> $ccdconf [0]</td><td align='center'> $ccdconf [1]</td><td align='center'> $ccdhosts /" .(& ccdmaxclients
( $ccdconf [ 1 ])+ 1 ). "</td><td>" ;
2972 <form method='post' />
2973 <input type='image' src='/images/edit.gif' align='middle' alt=' $Lang ::tr{'edit'}' title=' $Lang ::tr{'edit'}' />
2974 <input type='hidden' name='ACTION' value='edit'/>
2975 <input type='hidden' name='ccdname' value=' $ccdconf [0]' />
2976 <input type='hidden' name='ccdsubnet' value=' $ccdconf [1]' />
2978 <form method='post' />
2979 <td><input type='hidden' name='ACTION' value='kill'/>
2980 <input type='hidden' name='number' value=' $count ' />
2981 <input type='hidden' name='net' value=' $ccdconf [0]' />
2982 <input type='image' src='/images/delete.gif' align='middle' alt=' $Lang ::tr{'remove'}' title=' $Lang ::tr{'remove'}' /></form></td></tr>
2986 print "</table></form>" ;
2987 & Header
:: closebox
();
2988 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2989 & Header
:: closebigbox
();
2990 & Header
:: closepage
();
2996 ### Openvpn Connections Statistics
2998 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ovpn con stat' }) {
2999 & Header
:: showhttpheaders
();
3000 & Header
:: openpage
( $Lang :: tr
{ 'ovpn con stat' }, 1 , '' );
3001 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
3002 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ovpn con stat' });
3005 # <td><b>$Lang::tr{'protocol'}</b></td>
3006 # protocol temp removed
3008 <table width='100%' cellpadding='2' cellspacing='0' class='tbl'>
3010 <th><b> $Lang ::tr{'common name'}</b></th>
3011 <th><b> $Lang ::tr{'real address'}</b></th>
3012 <th><b> $Lang ::tr{'country'}</b></th>
3013 <th><b> $Lang ::tr{'virtual address'}</b></th>
3014 <th><b> $Lang ::tr{'loged in at'}</b></th>
3015 <th><b> $Lang ::tr{'bytes sent'}</b></th>
3016 <th><b> $Lang ::tr{'bytes received'}</b></th>
3017 <th><b> $Lang ::tr{'last activity'}</b></th>
3021 my $filename = "/var/run/ovpnserver.log" ;
3022 open ( FILE
, $filename ) or die 'Unable to open config file.' ;
3023 my @current = < FILE
>;
3032 my %userlookup = ();
3033 foreach my $line ( @current )
3036 if ( $line =~ /^Updated,(.+)/ ){
3037 @match = split ( /^Updated,(.+)/ , $line );
3038 $status = $match [ 1 ];
3041 if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ ) {
3042 @match = split ( m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ , $line );
3043 if ( $match [ 1 ] ne "Common Name" ) {
3045 $userlookup { $match [ 2 ]} = $uid ;
3046 $users [ $uid ]{ 'CommonName' } = $match [ 1 ];
3047 $users [ $uid ]{ 'RealAddress' } = $match [ 2 ];
3048 $users [ $uid ]{ 'BytesReceived' } = & sizeformat
( $match [ 3 ]);
3049 $users [ $uid ]{ 'BytesSent' } = & sizeformat
( $match [ 4 ]);
3050 $users [ $uid ]{ 'Since' } = $match [ 5 ];
3051 $users [ $uid ]{ 'Proto' } = $proto ;
3053 # get country code for "RealAddress"...
3054 my $ccode = & Location
:: Functions
:: lookup_country_code
(( split ':' , $users [ $uid ]{ 'RealAddress' })[ 0 ]);
3055 my $flag_icon = & Location
:: Functions
:: get_flag_icon
( $ccode );
3056 $users [ $uid ]{ 'Country' } = "<a href='country.cgi# $ccode '><img src=' $flag_icon ' border='0' align='absmiddle' alt=' $ccode ' title=' $ccode ' /></a>" ;
3060 if ( $line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/ ) {
3061 @match = split ( m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/ , $line );
3062 if ( $match [ 1 ] ne "Virtual Address" ) {
3063 $address = $match [ 3 ];
3064 #find the uid in the lookup table
3065 $uid = $userlookup { $address };
3066 $users [ $uid ]{ 'VirtualAddress' } = $match [ 1 ];
3067 $users [ $uid ]{ 'LastRef' } = $match [ 4 ];
3073 for ( my $idx = 1 ; $idx <= $user2 ; $idx ++){
3076 $col = "bgcolor=' $color {'color22'}'" ;
3079 $col = "bgcolor=' $color {'color20'}'" ;
3081 print "<td align='left' $col > $users [ $idx -1]{'CommonName'}</td>" ;
3082 print "<td align='left' $col > $users [ $idx -1]{'RealAddress'}</td>" ;
3083 print "<td align='center' $col > $users [ $idx -1]{'Country'}</td>" ;
3084 print "<td align='center' $col > $users [ $idx -1]{'VirtualAddress'}</td>" ;
3085 print "<td align='left' $col > $users [ $idx -1]{'Since'}</td>" ;
3086 print "<td align='left' $col > $users [ $idx -1]{'BytesSent'}</td>" ;
3087 print "<td align='left' $col > $users [ $idx -1]{'BytesReceived'}</td>" ;
3088 print "<td align='left' $col > $users [ $idx -1]{'LastRef'}</td>" ;
3094 <table width='100%' border='0' cellpadding='2' cellspacing='0'>
3099 <tr><td align='center' > $Lang ::tr{'the statistics were last updated at'} <b> $status </b></td></tr>
3103 & Header
:: closebox
();
3104 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
3105 & Header
:: closebigbox
();
3106 & Header
:: closepage
();
3110 ### Download Certificate
3112 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
3113 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3115 if ( - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
3116 print "Content-Disposition: filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \r\n " ;
3117 print "Content-Type: application/octet-stream \r\n\r\n " ;
3119 open ( FILE
, "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
3128 ### Enable/Disable connection
3131 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
3133 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
3134 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3136 if ( $confighash { $cgiparams { 'KEY' }}) {
3137 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
3138 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
3139 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3140 #&writeserverconf();
3141 # if ($vpnsettings{'ENABLED'} eq 'on' ||
3142 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
3143 # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
3146 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
3147 # if ($vpnsettings{'ENABLED'} eq 'on' ||
3148 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
3149 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
3151 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3152 #&writeserverconf();
3155 $errormessage = $Lang :: tr
{ 'invalid key' };
3159 ### Restart connection
3161 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
3162 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
3163 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3165 if ( $confighash { $cgiparams { 'KEY' }}) {
3166 # if ($vpnsettings{'ENABLED'} eq 'on' ||
3167 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
3168 # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
3171 $errormessage = $Lang :: tr
{ 'invalid key' };
3178 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
3179 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
3180 & Header
:: showhttpheaders
();
3181 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
3182 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
3183 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'connection type' });
3185 if ( - s
"${General::swroot}/ovpn/settings" ) {
3188 <b> $Lang ::tr{'connection type'}:</b><br />
3189 <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data">
3190 <tr><td><input type='radio' name='TYPE' value='host' checked /></td>
3191 <td class='base'> $Lang ::tr{'host to net vpn'}</td></tr>
3192 <tr><td><input type='radio' name='TYPE' value='net' /></td>
3193 <td class='base'> $Lang ::tr{'net to net vpn'}</td></tr>
3194 <tr><td><input type='radio' name='TYPE' value='net2net' /></td>
3195 <td class='base'> $Lang ::tr{'net to net vpn'} (Upload Client Package)</td></tr>
3196 <tr><td> </td><td class='base'><input type='file' name='FH' size='30'></td></tr>
3197 <tr><td> </td><td>Import Connection Name</td></tr>
3198 <tr><td> </td><td class='base'><input type='text' name='n2nname' size='30'> $Lang ::tr{'openvpn default'}: Client Packagename</td></tr>
3199 <tr><td colspan='3'><hr /></td></tr>
3200 <tr><td align='right' colspan='3'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td></tr>
3208 <b> $Lang ::tr{'connection type'}:</b><br />
3209 <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data">
3210 <tr><td><input type='radio' name='TYPE' value='host' checked /></td> <td class='base'> $Lang ::tr{'host to net vpn'}</td></tr>
3211 <tr><td align='right' colspan'3'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td></tr>
3218 & Header
:: closebox
();
3219 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
3220 & Header
:: closebigbox
();
3221 & Header
:: closepage
();
3228 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) && ( $cgiparams { 'TYPE' } eq 'net2net' )){
3232 my $uplconffilename = '' ;
3233 my $uplconffilename2 = '' ;
3234 my $uplp12name = '' ;
3235 my $uplp12name2 = '' ;
3242 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3244 # Check if a file is uploaded
3245 unless ( ref ( $cgiparams { 'FH' })) {
3246 $errormessage = $Lang :: tr
{ 'there was no file upload' };
3250 # Move uploaded IPfire n2n package to temporary file
3252 ( my $fh , my $filename ) = tempfile
( );
3253 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
3258 my $zip = Archive
:: Zip
-> new ();
3259 my $zipName = $filename ;
3260 my $status = $zip -> read ( $zipName );
3261 if ( $status != AZ_OK
) {
3262 $errormessage = "Read of $zipName failed \n " ;
3266 my $tempdir = tempdir
( CLEANUP
=> 1 );
3267 my @files = $zip -> memberNames ();
3269 $zip -> extractMemberWithoutPaths ( $_ , " $tempdir / $_ " );
3271 my $countfiles = @files ;
3273 # Check if we have not more then 2 files
3275 if ( $countfiles == 2 ){
3277 if ( $_ =~ /.conf$/ ){
3278 $uplconffilename = $_ ;
3280 if ( $_ =~ /.p12$/ ){
3284 if (( $uplconffilename eq '' ) || ( $uplp12name eq '' )){
3285 $errormessage = "Either no *.conf or no *.p12 file found \n " ;
3289 open ( FILE
, " $tempdir / $uplconffilename " ) or die 'Unable to open*.conf file' ;
3290 @firen2nconf = < FILE
>;
3292 chomp ( @firen2nconf );
3295 $errormessage = "Filecount does not match only 2 files are allowed \n " ;
3303 if ( $cgiparams { 'n2nname' } ne '' ){
3305 $uplconffilename2 = " $cgiparams {'n2nname'}.conf" ;
3306 $uplp12name2 = " $cgiparams {'n2nname'}.p12" ;
3307 $n2nname [ 0 ] = $cgiparams { 'n2nname' };
3308 my @n2nname2 = split ( /\./ , $uplconffilename );
3309 $n2nname2 [ 0 ] =~ s/\n|\r//g ;
3310 my $input1 = "${General::swroot}/ovpn/certs/ $uplp12name " ;
3311 my $output1 = "${General::swroot}/ovpn/certs/ $uplp12name2 " ;
3312 my $input2 = " $n2nname2 [0]n2n" ;
3313 my $output2 = " $n2nname [0]n2n" ;
3314 my $filename = " $tempdir / $uplconffilename " ;
3315 open ( FILE
, "< $filename " ) or die 'Unable to open config file.' ;
3316 my @current = < FILE
>;
3318 foreach ( @current ) { s/$input1/$output1/g ;}
3319 foreach ( @current ) { s/$input2/$output2/g ;}
3320 open ( OUT
, "> $filename " ) || die 'Unable to open config file.' ;
3325 $uplconffilename2 = $uplconffilename ;
3326 $uplp12name2 = $uplp12name ;
3327 @n2nname = split ( /\./ , $uplconffilename );
3328 $n2nname [ 0 ] =~ s/\n|\r//g ;
3330 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
3331 unless (- d
"${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" , 0770 or die "Unable to create dir $!" ;}
3333 #Add collectd settings to configfile
3334 open ( FILE
, ">> $tempdir / $uplconffilename " ) or die 'Unable to open config file.' ;
3335 print FILE
"# Logfile \n " ;
3336 print FILE
"status-version 1 \n " ;
3337 print FILE
"status /var/run/openvpn/ $n2nname [0]-n2n 10 \n " ;
3338 if (& iscertlegacy
( "${General::swroot}/ovpn/certs/ $cgiparams {'n2nname'}" )) {
3339 print CLIENTCONF
"providers legacy default \n " ;
3344 unless ( move
( " $tempdir / $uplconffilename " , "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $uplconffilename2 " )) {
3345 $errormessage = "*.conf move failed: $!" ;
3350 unless ( move
( " $tempdir / $uplp12name " , "${General::swroot}/ovpn/certs/ $uplp12name2 " )) {
3351 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
3356 chmod 0600 , "${General::swroot}/ovpn/certs/ $uplp12name " ;
3362 my @n2nproto2 = split ( / / , ( grep { /^proto/ } @firen2nconf )[ 0 ]);
3363 my @n2nproto = split ( /-/ , $n2nproto2 [ 1 ]);
3364 my @n2nport = split ( / / , ( grep { /^port/ } @firen2nconf )[ 0 ]);
3365 my @n2ntunmtu = split ( / / , ( grep { /^tun-mtu/ } @firen2nconf )[ 0 ]);
3366 my @n2ncomplzo = grep { /^comp-lzo/ } @firen2nconf ;
3367 if ( $n2ncomplzo [ 0 ] =~ /comp-lzo/ ){ $complzoactive = "on" ;} else { $complzoactive = "off" ;}
3368 my @n2nmssfix = grep { /^mssfix/ } @firen2nconf ;
3369 if ( $n2nmssfix [ 0 ] =~ /mssfix/ ){ $mssfixactive = "on" ;} else { $mssfixactive = "off" ;}
3370 #my @n2nmssfix = split(/ /, (grep { /^mssfix/ } @firen2nconf)[0]);
3371 my @n2nfragment = split ( / / , ( grep { /^fragment/ } @firen2nconf )[ 0 ]);
3372 my @n2nremote = split ( / / , ( grep { /^remote/ } @firen2nconf )[ 0 ]);
3373 my @n2novpnsuball = split ( / / , ( grep { /^ifconfig/ } @firen2nconf )[ 0 ]);
3374 my @n2novpnsub = split ( /\./ , $n2novpnsuball [ 1 ]);
3375 my @n2nremsub = split ( / / , ( grep { /^route/ } @firen2nconf )[ 0 ]);
3376 my @n2nmgmt = split ( / / , ( grep { /^management/ } @firen2nconf )[ 0 ]);
3377 my @n2nlocalsub = split ( / / , ( grep { /^# remsub/ } @firen2nconf )[ 0 ]);
3378 my @n2ncipher = split ( / / , ( grep { /^cipher/ } @firen2nconf )[ 0 ]);
3379 my @n2nauth = split ( / / , ( grep { /^auth/ } @firen2nconf )[ 0 ]);;
3382 # m.a.d delete CR and LF from arrays for this chomp doesnt work
3385 $n2nremote [ 1 ] =~ s/\n|\r//g ;
3386 $n2novpnsub [ 0 ] =~ s/\n|\r//g ;
3387 $n2novpnsub [ 1 ] =~ s/\n|\r//g ;
3388 $n2novpnsub [ 2 ] =~ s/\n|\r//g ;
3389 $n2nproto [ 0 ] =~ s/\n|\r//g ;
3390 $n2nport [ 1 ] =~ s/\n|\r//g ;
3391 $n2ntunmtu [ 1 ] =~ s/\n|\r//g ;
3392 $n2nremsub [ 1 ] =~ s/\n|\r//g ;
3393 $n2nremsub [ 2 ] =~ s/\n|\r//g ;
3394 $n2nlocalsub [ 2 ] =~ s/\n|\r//g ;
3395 $n2nfragment [ 1 ] =~ s/\n|\r//g ;
3396 $n2nmgmt [ 2 ] =~ s/\n|\r//g ;
3397 $n2ncipher [ 1 ] =~ s/\n|\r//g ;
3398 $n2nauth [ 1 ] =~ s/\n|\r//g ;
3399 chomp ( $complzoactive );
3400 chomp ( $mssfixactive );
3407 # Check if there is no other entry with this name
3410 foreach my $dkey ( keys %confighash ) {
3411 if ( $confighash { $dkey }[ 1 ] eq $n2nname [ 0 ]) {
3412 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
3413 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
3414 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
3415 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
3421 # Check if OpenVPN Subnet is valid
3424 foreach my $dkey ( keys %confighash ) {
3425 if ( $confighash { $dkey }[ 27 ] eq " $n2novpnsub [0]. $n2novpnsub [1]. $n2novpnsub [2].0/255.255.255.0" ) {
3426 $errormessage = 'The OpenVPN Subnet is already in use' ;
3427 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
3428 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
3429 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
3435 # Check if Dest Port is vaild
3438 foreach my $dkey ( keys %confighash ) {
3439 if ( $confighash { $dkey }[ 29 ] eq $n2nport [ 1 ] ) {
3440 $errormessage = 'The OpenVPN Port is already in use' ;
3441 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
3442 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
3443 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
3450 $key = & General
:: findhasharraykey
( \
%confighash );
3452 foreach my $i ( 0 .. 42 ) { $confighash { $key }[ $i ] = "" ;}
3454 $confighash { $key }[ 0 ] = 'off' ;
3455 $confighash { $key }[ 1 ] = $n2nname [ 0 ];
3456 $confighash { $key }[ 2 ] = $n2nname [ 0 ];
3457 $confighash { $key }[ 3 ] = 'net' ;
3458 $confighash { $key }[ 4 ] = 'cert' ;
3459 $confighash { $key }[ 6 ] = 'client' ;
3460 $confighash { $key }[ 8 ] = $n2nlocalsub [ 2 ];
3461 $confighash { $key }[ 10 ] = $n2nremote [ 1 ];
3462 $confighash { $key }[ 11 ] = " $n2nremsub [1]/ $n2nremsub [2]" ;
3463 $confighash { $key }[ 22 ] = $n2nmgmt [ 2 ];
3464 $confighash { $key }[ 23 ] = $mssfixactive ;
3465 $confighash { $key }[ 24 ] = $n2nfragment [ 1 ];
3466 $confighash { $key }[ 25 ] = 'IPFire n2n Client' ;
3467 $confighash { $key }[ 26 ] = 'red' ;
3468 $confighash { $key }[ 27 ] = " $n2novpnsub [0]. $n2novpnsub [1]. $n2novpnsub [2].0/255.255.255.0" ;
3469 $confighash { $key }[ 28 ] = $n2nproto [ 0 ];
3470 $confighash { $key }[ 29 ] = $n2nport [ 1 ];
3471 $confighash { $key }[ 30 ] = $complzoactive ;
3472 $confighash { $key }[ 31 ] = $n2ntunmtu [ 1 ];
3473 $confighash { $key }[ 39 ] = $n2nauth [ 1 ];
3474 $confighash { $key }[ 40 ] = $n2ncipher [ 1 ];
3475 $confighash { $key }[ 41 ] = 'disabled' ;
3477 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3481 & Header
:: showhttpheaders
();
3482 & Header
:: openpage
( 'Validate imported configuration' , 1 , '' );
3483 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
3484 if ( $errormessage ) {
3485 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
3486 print "<class name='base'> $errormessage " ;
3487 print " </class>" ;
3488 & Header
:: closebox
();
3492 & Header
:: openbox
( '100%' , 'LEFT' , 'import ipfire net2net config' );
3494 if ( $errormessage eq '' ){
3496 <!-- ipfire net2net config gui -->
3497 <table width='100%'>
3498 <tr><td width='25%'> </td><td width='25%'> </td></tr>
3499 <tr><td class='boldbase'> $Lang ::tr{'name'}:</td><td><b> $n2nname [0]</b></td></tr>
3500 <tr><td> </td><td> </td></tr>
3501 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'Act as'}</td><td><b> $confighash { $key }[6]</b></td></tr>
3502 <tr><td class='boldbase' nowrap='nowrap'>Remote Host </td><td><b> $confighash { $key }[10]</b></td></tr>
3503 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'}</td><td><b> $confighash { $key }[8]</b></td></tr>
3504 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'}:</td><td><b> $confighash { $key }[11]</b></td></tr>
3505 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn subnet'}</td><td><b> $confighash { $key }[27]</b></td></tr>
3506 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td><td><b> $confighash { $key }[28]</b></td></tr>
3507 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'destination port'}:</td><td><b> $confighash { $key }[29]</b></td></tr>
3508 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'}</td><td><b> $confighash { $key }[30]</b></td></tr>
3509 <tr><td class='boldbase' nowrap='nowrap'>MSSFIX:</td><td><b> $confighash { $key }[23]</b></td></tr>
3510 <tr><td class='boldbase' nowrap='nowrap'>Fragment:</td><td><b> $confighash { $key }[24]</b></td></tr>
3511 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'}</td><td><b> $confighash { $key }[31]</b></td></tr>
3512 <tr><td class='boldbase' nowrap='nowrap'>Management Port </td><td><b> $confighash { $key }[22]</b></td></tr>
3513 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn tls auth'}:</td><td><b> $confighash { $key }[39]</b></td></tr>
3514 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'cipher'}</td><td><b> $confighash { $key }[40]</b></td></tr>
3515 <tr><td> </td><td> </td></tr>
3519 & Header
:: closebox
();
3522 if ( $errormessage ) {
3523 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
3525 print "<div align='center'><form method='post' ENCTYPE='multipart/form-data'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />" ;
3526 print "<input type='hidden' name='TYPE' value='net2netakn' />" ;
3527 print "<input type='hidden' name='KEY' value=' $key ' />" ;
3528 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
3530 & Header
:: closebigbox
();
3531 & Header
:: closepage
();
3536 ### Accept IPFire n2n Package Settings
3539 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) && ( $cgiparams { 'TYPE' } eq 'net2netakn' )){
3542 ### Discard and Rollback IPFire n2n Package Settings
3545 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'cancel' }) && ( $cgiparams { 'TYPE' } eq 'net2netakn' )){
3547 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3549 if ( $confighash { $cgiparams { 'KEY' }}) {
3551 my $conffile = glob ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]/ $confighash { $cgiparams {'KEY'}}[1].conf" );
3552 my $certfile = glob ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
3553 unlink ( $certfile ) or die "Removing $certfile fail: $!" ;
3554 unlink ( $conffile ) or die "Removing $conffile fail: $!" ;
3555 rmdir ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]" ) || die "Kann Verzeichnis nicht loeschen: $!" ;
3556 delete $confighash { $cgiparams { 'KEY' }};
3557 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3560 $errormessage = $Lang :: tr
{ 'invalid key' };
3570 ### Adding a new connection
3572 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
3573 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
3574 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
3576 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
3577 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
3578 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3580 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
3581 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
3582 $errormessage = $Lang :: tr
{ 'invalid key' };
3585 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
3586 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
3587 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
3588 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
3589 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
3590 $cgiparams { 'SIDE' } = $confighash { $cgiparams { 'KEY' }}[ 6 ];
3591 $cgiparams { 'LOCAL_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 8 ];
3592 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
3593 $cgiparams { 'REMOTE_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 11 ];
3594 $cgiparams { 'OVPN_MGMT' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
3595 $cgiparams { 'MSSFIX' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
3596 $cgiparams { 'FRAGMENT' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
3597 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
3598 $cgiparams { 'INTERFACE' } = $confighash { $cgiparams { 'KEY' }}[ 26 ];
3599 $cgiparams { 'OVPN_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
3600 $cgiparams { 'PROTOCOL' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
3601 $cgiparams { 'DEST_PORT' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
3602 $cgiparams { 'COMPLZO' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
3603 $cgiparams { 'MTU' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
3604 $cgiparams { 'CHECK1' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
3605 $name = $cgiparams { 'CHECK1' } ;
3606 $cgiparams { $name } = $confighash { $cgiparams { 'KEY' }}[ 33 ];
3607 $cgiparams { 'RG' } = $confighash { $cgiparams { 'KEY' }}[ 34 ];
3608 $cgiparams { 'CCD_DNS1' } = $confighash { $cgiparams { 'KEY' }}[ 35 ];
3609 $cgiparams { 'CCD_DNS2' } = $confighash { $cgiparams { 'KEY' }}[ 36 ];
3610 $cgiparams { 'CCD_WINS' } = $confighash { $cgiparams { 'KEY' }}[ 37 ];
3611 $cgiparams { 'DAUTH' } = $confighash { $cgiparams { 'KEY' }}[ 39 ];
3612 $cgiparams { 'DCIPHER' } = $confighash { $cgiparams { 'KEY' }}[ 40 ];
3613 $cgiparams { 'TLSAUTH' } = $confighash { $cgiparams { 'KEY' }}[ 41 ];
3614 $cgiparams { 'OTP_STATE' } = $confighash { $cgiparams { 'KEY' }}[ 43 ];
3615 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
3616 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
3618 #A.Marx CCD check iroute field and convert it to decimal
3619 if ( $cgiparams { 'TYPE' } eq 'host' ) {
3621 my %ccdroutehash =();
3625 if ( $cgiparams { 'IR' } ne '' ){
3626 @temp = split ( " \n " , $cgiparams { 'IR' });
3627 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3629 foreach my $key ( keys %ccdroutehash ) {
3630 if ( $ccdroutehash { $key }[ 0 ] eq $cgiparams { 'NAME' }) {
3632 delete $ccdroutehash { $key };
3634 $keypoint = & General
:: findhasharraykey
( \
%ccdroutehash );
3637 $ccdroutehash { $keypoint }[ 0 ]= $cgiparams { 'NAME' };
3640 foreach $val ( @temp ){
3643 #check if iroute exists in ccdroute or if new iroute is part of an existing one
3644 foreach my $key ( keys %ccdroutehash ) {
3645 foreach my $oldiroute ( 1 .. $ #{$ccdroutehash{$key}}){
3646 if ( $ccdroutehash { $key }[ $oldiroute ] eq " $val " ) {
3647 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err irouteexist' };
3650 my ( $ip1 , $cidr1 ) = split ( /\/ /, $val );
3651 $ip1 = & General
:: getnetworkip
( $ip1 ,& General
:: iporsubtocidr
( $cidr1 ));
3652 my ( $ip2 , $cidr2 ) = split ( /\/ /, $ccdroutehash { $key }[ $oldiroute ]);
3653 if (& General
:: IpInSubnet
( $ip1 , $ip2 , $cidr2 )){
3654 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err irouteexist' };
3660 if (!& General
:: validipandmask
( $val )){
3661 $errormessage = $errormessage . "Route " . $Lang :: tr
{ 'ccd invalid' }. " ( $val )" ;
3664 ( $ip , $cidr ) = split ( /\/ /, $val );
3665 $ip =& General
:: getnetworkip
( $ip ,& General
:: iporsubtocidr
( $cidr ));
3666 $cidr =& General
:: iporsubtodec
( $cidr );
3667 $ccdroutehash { $keypoint }[ $i ] = $ip . "/" . $cidr ;
3671 #check for existing network IP's
3672 if (& General
:: IpInSubnet
( $ip , $netsettings { GREEN_NETADDRESS
}, $netsettings { GREEN_NETMASK
}) && $netsettings { GREEN_NETADDRESS
} ne '0.0.0.0' )
3674 $errormessage = $Lang :: tr
{ 'ccd err green' };
3676 } elsif (& General
:: IpInSubnet
( $ip , $netsettings { RED_NETADDRESS
}, $netsettings { RED_NETMASK
}) && $netsettings { RED_NETADDRESS
} ne '0.0.0.0' )
3678 $errormessage = $Lang :: tr
{ 'ccd err red' };
3680 } elsif (& General
:: IpInSubnet
( $ip , $netsettings { BLUE_NETADDRESS
}, $netsettings { BLUE_NETMASK
}) && $netsettings { BLUE_NETADDRESS
} ne '0.0.0.0' && $netsettings { BLUE_NETADDRESS
} gt '' )
3682 $errormessage = $Lang :: tr
{ 'ccd err blue' };
3684 } elsif (& General
:: IpInSubnet
( $ip , $netsettings { ORANGE_NETADDRESS
}, $netsettings { ORANGE_NETMASK
}) && $netsettings { ORANGE_NETADDRESS
} ne '0.0.0.0' && $netsettings { ORANGE_NETADDRESS
} gt '' )
3686 $errormessage = $Lang :: tr
{ 'ccd err orange' };
3690 if (& General
:: validipandmask
( $val )){
3691 $ccdroutehash { $keypoint }[ $i ] = $ip . "/" . $cidr ;
3693 $errormessage = $errormessage . "Route " . $Lang :: tr
{ 'ccd invalid' }. " ( $ip / $cidr )" ;
3698 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3701 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3702 foreach my $key ( keys %ccdroutehash ) {
3703 if ( $ccdroutehash { $key }[ 0 ] eq $cgiparams { 'NAME' }) {
3704 delete $ccdroutehash { $key };
3705 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3711 #check route field and convert it to decimal
3714 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
3716 foreach my $key ( keys %ccdroute2hash ) {
3717 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }) {
3719 delete $ccdroute2hash { $key };
3721 $keypoint = & General
:: findhasharraykey
( \
%ccdroute2hash );
3722 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3726 $ccdroute2hash { $keypoint }[ 0 ]= $cgiparams { 'NAME' };
3727 if ( $cgiparams { 'IFROUTE' } eq '' ){ $cgiparams { 'IFROUTE' } = $Lang :: tr
{ 'ccd none' };}
3728 @temp = split ( /\|/ , $cgiparams { 'IFROUTE' });
3730 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%ownnet );
3731 foreach $val ( @temp ){
3734 if ( $val eq $Lang :: tr
{ 'green' })
3736 $val = $ownnet { GREEN_NETADDRESS
}. "/" . $ownnet { GREEN_NETMASK
};
3738 if ( $val eq $Lang :: tr
{ 'blue' })
3740 $val = $ownnet { BLUE_NETADDRESS
}. "/" . $ownnet { BLUE_NETMASK
};
3742 if ( $val eq $Lang :: tr
{ 'orange' })
3744 $val = $ownnet { ORANGE_NETADDRESS
}. "/" . $ownnet { ORANGE_NETMASK
};
3746 my ( $ip , $cidr ) = split ( /\/ /, $val );
3748 if ( $val ne $Lang :: tr
{ 'ccd none' })
3750 if (! & check_routes_push
( $val )){ $errormessage = $errormessage . "Route $val " . $Lang :: tr
{ 'ccd err routeovpn2' }. " ( $val )" ; goto VPNCONF_ERROR
;}
3751 if (! & check_ccdroute
( $val )){ $errormessage = $errormessage . "<br>Route $val " . $Lang :: tr
{ 'ccd err inuse' }. " ( $val )" ; goto VPNCONF_ERROR
;}
3752 if (! & check_ccdconf
( $val )){ $errormessage = $errormessage . "<br>Route $val " . $Lang :: tr
{ 'ccd err routeovpn' }. " ( $val )" ; goto VPNCONF_ERROR
;}
3753 if (& General
:: validipandmask
( $val )){
3754 $val = $ip . "/" .& General
:: iporsubtodec
( $cidr );
3755 $ccdroute2hash { $keypoint }[ $i ] = $val ;
3757 $errormessage = $errormessage . "Route " . $Lang :: tr
{ 'ccd invalid' }. " ( $val )" ;
3761 $ccdroute2hash { $keypoint }[ $i ]= '' ;
3765 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
3768 if ( $cgiparams { 'CCD_DNS1' } ne '' && ! & General
:: validip
( $cgiparams { 'CCD_DNS1' })) {
3769 $errormessage = $errormessage . "<br>" . $Lang :: tr
{ 'invalid input for dhcp dns' }. " 1" ;
3773 if ( $cgiparams { 'CCD_DNS2' } ne '' && ! & General
:: validip
( $cgiparams { 'CCD_DNS2' })) {
3774 $errormessage = $errormessage . "<br>" . $Lang :: tr
{ 'invalid input for dhcp dns' }. " 2" ;
3778 if ( $cgiparams { 'CCD_WINS' } ne '' && ! & General
:: validip
( $cgiparams { 'CCD_WINS' })) {
3779 $errormessage = $errormessage . "<br>" . $Lang :: tr
{ 'invalid input for dhcp wins' };
3787 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
3788 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
3789 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3790 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3791 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3797 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
3798 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
3799 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3805 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
3806 $errormessage = $Lang :: tr
{ 'name is invalid' };
3807 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3808 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3809 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3815 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
3816 $errormessage = $Lang :: tr
{ 'name too long' };
3817 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3818 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3819 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3829 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3830 if ( $cgiparams { 'DEST_PORT' } eq $vpnsettings { 'DDEST_PORT' }) {
3831 $errormessage = $Lang :: tr
{ 'openvpn destination port used' };
3832 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3833 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3837 foreach my $key ( sort keys %confighash ){
3838 if ( ( $confighash { $key }[ 22 ] eq $cgiparams { 'DEST_PORT' } && $cgiparams { 'NAME' } ne $confighash { $key }[ 1 ]) || ( $confighash { $key }[ 29 ] eq $cgiparams { 'DEST_PORT' } && $cgiparams { 'NAME' } ne $confighash { $key }[ 1 ])){
3839 $errormessage = $Lang :: tr
{ 'openvpn destination port used' };
3840 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3841 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3845 if ( $cgiparams { 'DEST_PORT' } eq '' ) {
3846 $errormessage = $Lang :: tr
{ 'invalid port' };
3847 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3848 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3852 # Check if the input for the transfer net is valid.
3853 if (!& General
:: validipandmask
( $cgiparams { 'OVPN_SUBNET' })){
3854 $errormessage = $Lang :: tr
{ 'ccd err invalidnet' };
3855 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3856 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3860 if ( $cgiparams { 'OVPN_SUBNET' } eq $vpnsettings { 'DOVPN_SUBNET' }) {
3861 $errormessage = $Lang :: tr
{ 'openvpn subnet is used' };
3862 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3863 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3867 if (( $cgiparams { 'PROTOCOL' } eq 'tcp' ) && ( $cgiparams { 'MSSFIX' } eq 'on' )) {
3868 $errormessage = $Lang :: tr
{ 'openvpn mssfix allowed with udp' };
3869 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3870 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3874 if (( $cgiparams { 'PROTOCOL' } eq 'tcp' ) && ( $cgiparams { 'FRAGMENT' } ne '' )) {
3875 $errormessage = $Lang :: tr
{ 'openvpn fragment allowed with udp' };
3876 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3877 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3881 if ( & validdotmask
( $cgiparams { 'LOCAL_SUBNET' })) {
3882 $errormessage = $Lang :: tr
{ 'openvpn prefix local subnet' };
3883 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3884 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3888 if ( & validdotmask
( $cgiparams { 'OVPN_SUBNET' })) {
3889 $errormessage = $Lang :: tr
{ 'openvpn prefix openvpn subnet' };
3890 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3891 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3895 if ( & validdotmask
( $cgiparams { 'REMOTE_SUBNET' })) {
3896 $errormessage = $Lang :: tr
{ 'openvpn prefix remote subnet' };
3897 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3898 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3902 if ( $cgiparams { 'DEST_PORT' } <= 1023 ) {
3903 $errormessage = $Lang :: tr
{ 'ovpn port in root range' };
3904 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3905 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3909 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) {
3910 $cgiparams { 'OVPN_MGMT' } = $cgiparams { 'DEST_PORT' };
3913 if ( $cgiparams { 'OVPN_MGMT' } <= 1023 ) {
3914 $errormessage = $Lang :: tr
{ 'ovpn mgmt in root range' };
3915 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3916 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3919 #Check if remote subnet is used elsewhere
3920 my ( $n2nip , $n2nsub )= split ( "/" , $cgiparams { 'REMOTE_SUBNET' });
3921 $warnmessage =& General
:: checksubnets
( '' , $n2nip , 'ovpn' );
3923 $warnmessage = $Lang :: tr
{ 'remote subnet' }. " ( $cgiparams {'REMOTE_SUBNET'}) <br>" . $warnmessage ;
3927 # if (($cgiparams{'TYPE'} eq 'net') && ($cgiparams{'SIDE'} !~ /^(left|right)$/)) {
3928 # $errormessage = $Lang::tr{'ipfire side is invalid'};
3929 # goto VPNCONF_ERROR;
3932 # Check if there is no other entry with this name
3933 if (! $cgiparams { 'KEY' }) {
3934 foreach my $key ( keys %confighash ) {
3935 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
3936 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
3937 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3938 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3939 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3946 # Check if a remote host/IP has been set for the client.
3947 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3948 if ( $cgiparams { 'SIDE' } ne 'server' && $cgiparams { 'REMOTE' } eq '' ) {
3949 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
3951 # Check if this is a N2N connection and drop temporary config.
3952 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3953 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3958 # Check if a remote host/IP has been configured - the field can be empty on the server side.
3959 if ( $cgiparams { 'REMOTE' } ne '' ) {
3960 # Check if the given IP is valid - otherwise check if it is a valid domain.
3961 if (! & General
:: validip
( $cgiparams { 'REMOTE' })) {
3962 # Check for a valid domain.
3963 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
3964 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
3966 # Check if this is a N2N connection and drop temporary config.
3967 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3968 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3976 if ( $cgiparams { 'TYPE' } ne 'host' ) {
3977 unless (& General
:: validipandmask
( $cgiparams { 'LOCAL_SUBNET' })) {
3978 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
3979 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3980 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3981 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3983 goto VPNCONF_ERROR
;}
3985 # Check if there is no other entry without IP-address and PSK
3986 if ( $cgiparams { 'REMOTE' } eq '' ) {
3987 foreach my $key ( keys %confighash ) {
3988 if (( $cgiparams { 'KEY' } ne $key ) &&
3989 ( $confighash { $key }[ 4 ] eq 'psk' || $cgiparams { 'AUTH' } eq 'psk' ) &&
3990 $confighash { $key }[ 10 ] eq '' ) {
3991 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
3996 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! & General
:: validipandmask
( $cgiparams { 'REMOTE_SUBNET' }))) {
3997 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
3998 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3999 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
4003 # Check for N2N that OpenSSL maximum of valid days will not be exceeded
4004 if ( $cgiparams { 'TYPE' } eq 'net' ) {
4005 if ( $cgiparams { 'DAYS_VALID' } >= '999999' ) {
4006 $errormessage = $Lang :: tr
{ 'invalid input for valid till days' };
4007 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
4008 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
4013 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
4014 $errormessage = $Lang :: tr
{ 'invalid input' };
4017 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
4018 $errormessage = $Lang :: tr
{ 'invalid input' };
4023 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
4024 # if (! length($cgiparams{'PSK'}) ) {
4025 # $errormessage = $Lang::tr{'pre-shared key is too short'};
4026 # goto VPNCONF_ERROR;
4028 # if ($cgiparams{'PSK'} =~ /['",&]/) {
4029 # $errormessage = $Lang::tr{'invalid characters found in pre-shared key'};
4030 # goto VPNCONF_ERROR;
4032 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
4033 if ( $cgiparams { 'KEY' }) {
4034 $errormessage = $Lang :: tr
{ 'cant change certificates' };
4037 unless ( ref ( $cgiparams { 'FH' })) {
4038 $errormessage = $Lang :: tr
{ 'there was no file upload' };
4042 # Move uploaded certificate request to a temporary file
4043 ( my $fh , my $filename ) = tempfile
( );
4044 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
4049 # Sign the certificate request and move it
4050 # Sign the host certificate request
4051 # The system call is safe, because all arguments are passed as an array.
4052 system ( '/usr/bin/openssl' , 'ca' , '-days' , " $cgiparams {'DAYS_VALID'}" ,
4053 '-batch' , '-notext' ,
4055 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
4056 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
4058 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
4060 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
4061 & newcleanssldatabase
();
4065 & deletebackupcert
();
4068 my @temp = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
4071 foreach my $line ( @temp ) {
4072 if ( $line =~ /Subject:.*CN\s?=\s?(.*)[\n]/ ) {
4074 $temp =~ s
+/ Email
+, E
+;
4075 $temp =~ s/ ST=/ S=/ ;
4081 $cgiparams { 'CERT_NAME' } = $temp ;
4082 $cgiparams { 'CERT_NAME' } =~ s/,//g ;
4083 $cgiparams { 'CERT_NAME' } =~ s/\'//g ;
4084 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
4085 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
4088 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
4089 if ( $cgiparams { 'KEY' }) {
4090 $errormessage = $Lang :: tr
{ 'cant change certificates' };
4093 unless ( ref ( $cgiparams { 'FH' })) {
4094 $errormessage = $Lang :: tr
{ 'there was no file upload' };
4097 # Move uploaded certificate to a temporary file
4098 ( my $fh , my $filename ) = tempfile
( );
4099 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
4104 # Verify the certificate has a valid CA and move it
4106 my @test = & General
:: system_output
( "/usr/bin/openssl" , "verify" , "-CAfile" , "${General::swroot}/ovpn/ca/cacert.pem" , " $filename " );
4107 if ( grep ( /: OK/ , @test )) {
4110 foreach my $key ( keys %cahash ) {
4111 @test = & General
:: system_output
( "/usr/bin/openssl" , "verify" , "-CAfile" , "${General::swroot}/ovpn/ca/ $cahash { $key }[0]cert.pem" , " $filename " );
4112 if ( grep ( /: OK/ , @test )) {
4118 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
4122 unless ( move
( $filename , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" )) {
4123 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
4129 my @temp = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
4132 foreach my $line ( @temp ) {
4133 if ( $line =~ /Subject:.*CN\s?=\s?(.*)[\n]/ ) {
4135 $temp =~ s
+/ Email
+, E
+;
4136 $temp =~ s/ ST=/ S=/ ;
4142 $cgiparams { 'CERT_NAME' } = $temp ;
4143 $cgiparams { 'CERT_NAME' } =~ s/,//g ;
4144 $cgiparams { 'CERT_NAME' } =~ s/\'//g ;
4145 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
4146 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
4147 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
4150 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
4151 if ( $cgiparams { 'KEY' }) {
4152 $errormessage = $Lang :: tr
{ 'cant change certificates' };
4155 # Validate input since the form was submitted
4156 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
4157 $errormessage = $Lang :: tr
{ 'name too long' };
4160 if ( $cgiparams { 'CERT_NAME' } eq '' || $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
4161 $errormessage = $Lang :: tr
{ 'invalid input for name' };
4164 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
4165 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
4168 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
4169 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
4172 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
4173 $errormessage = $Lang :: tr
{ 'invalid input for department' };
4176 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
4177 $errormessage = $Lang :: tr
{ 'organization too long' };
4180 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
4181 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
4184 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
4185 $errormessage = $Lang :: tr
{ 'invalid input for city' };
4188 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
4189 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
4192 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
4193 $errormessage = $Lang :: tr
{ 'invalid input for country' };
4196 if ( $cgiparams { 'CERT_PASS1' } ne '' && $cgiparams { 'CERT_PASS2' } ne '' ){
4197 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
4198 $errormessage = $Lang :: tr
{ 'password too short' };
4202 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
4203 $errormessage = $Lang :: tr
{ 'passwords do not match' };
4206 if ( $cgiparams { 'DAYS_VALID' } eq '' && $cgiparams { 'DAYS_VALID' } !~ /^[0-9]+$/ ) {
4207 $errormessage = $Lang :: tr
{ 'invalid input for valid till days' };
4211 # Check for RW that OpenSSL maximum of valid days will not be exceeded
4212 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4213 if ( $cgiparams { 'DAYS_VALID' } >= '999999' ) {
4214 $errormessage = $Lang :: tr
{ 'invalid input for valid till days' };
4219 # Check for RW if client name is already set
4220 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4221 foreach my $key ( keys %confighash ) {
4222 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
4223 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
4229 # Replace empty strings with a .
4230 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
4231 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
4232 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
4234 # Create the Host certificate request client
4235 my $pid = open ( OPENSSL
, "|-" );
4236 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto VPNCONF_ERROR
;};
4237 if ( $pid ) { # parent
4238 print OPENSSL
" $cgiparams {'CERT_COUNTRY'} \n " ;
4239 print OPENSSL
" $state \n " ;
4240 print OPENSSL
" $city \n " ;
4241 print OPENSSL
" $cgiparams {'CERT_ORGANIZATION'} \n " ;
4242 print OPENSSL
" $ou \n " ;
4243 print OPENSSL
" $cgiparams {'CERT_NAME'} \n " ;
4244 print OPENSSL
" $cgiparams {'CERT_EMAIL'} \n " ;
4245 print OPENSSL
". \n " ;
4246 print OPENSSL
". \n " ;
4249 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
4250 unlink ( "${General::swroot}ovpn/certs/ $cgiparams {'NAME'}key.pem" );
4251 unlink ( "${General::swroot}ovpn/certs/ $cgiparams {'NAME'}req.pem" );
4255 unless ( exec ( '/usr/bin/openssl' , 'req' , '-nodes' ,
4256 '-newkey' , 'rsa:4096' ,
4257 '-keyout' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" ,
4258 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" ,
4259 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
4260 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
4261 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
4262 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
4267 # Sign the host certificate request
4268 # The system call is safe, because all arguments are passed as an array.
4269 system ( '/usr/bin/openssl' , 'ca' , '-days' , " $cgiparams {'DAYS_VALID'}" ,
4270 '-batch' , '-notext' ,
4271 '-in' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" ,
4272 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
4273 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
4275 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
4276 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
4277 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
4278 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
4279 & newcleanssldatabase
();
4282 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
4283 & deletebackupcert
();
4286 # Create the pkcs12 file
4287 # The system call is safe, because all arguments are passed as an array.
4288 system ( '/usr/bin/openssl' , 'pkcs12' , '-export' ,
4289 '-inkey' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" ,
4290 '-in' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
4291 '-name' , $cgiparams { 'NAME' },
4292 '-passout' , "pass: $cgiparams {'CERT_PASS1'}" ,
4293 '-certfile' , "${General::swroot}/ovpn/ca/cacert.pem" ,
4294 '-caname' , " $vpnsettings {'ROOTCERT_ORGANIZATION'} CA" ,
4295 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12" );
4297 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
4298 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
4299 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
4300 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12" );
4303 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
4305 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
4306 ; # Nothing, just editing
4308 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
4312 # Check if there is no other entry with this common name
4313 if ((! $cgiparams { 'KEY' }) && ( $cgiparams { 'AUTH' } ne 'psk' )) {
4314 foreach my $key ( keys %confighash ) {
4315 if ( $confighash { $key }[ 2 ] eq $cgiparams { 'CERT_NAME' }) {
4316 $errormessage = $Lang :: tr
{ 'a connection with this common name already exists' };
4323 my $key = $cgiparams { 'KEY' };
4326 $key = & General
:: findhasharraykey
( \
%confighash );
4327 foreach my $i ( 0 .. 43 ) { $confighash { $key }[ $i ] = "" ;}
4329 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
4330 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
4331 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
4332 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
4335 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
4336 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
4337 $confighash { $key }[ 4 ] = 'psk' ;
4338 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
4340 $confighash { $key }[ 4 ] = 'cert' ;
4342 if ( $cgiparams { 'TYPE' } eq 'net' ) {
4343 $confighash { $key }[ 6 ] = $cgiparams { 'SIDE' };
4344 $confighash { $key }[ 11 ] = $cgiparams { 'REMOTE_SUBNET' };
4346 $confighash { $key }[ 8 ] = $cgiparams { 'LOCAL_SUBNET' };
4347 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
4348 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) {
4349 $confighash { $key }[ 22 ] = $confighash { $key }[ 29 ];
4351 $confighash { $key }[ 22 ] = $cgiparams { 'OVPN_MGMT' };
4353 $confighash { $key }[ 23 ] = $cgiparams { 'MSSFIX' };
4354 $confighash { $key }[ 24 ] = $cgiparams { 'FRAGMENT' };
4355 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
4356 $confighash { $key }[ 26 ] = $cgiparams { 'INTERFACE' };
4358 $confighash { $key }[ 27 ] = $cgiparams { 'OVPN_SUBNET' };
4359 $confighash { $key }[ 28 ] = $cgiparams { 'PROTOCOL' };
4360 $confighash { $key }[ 29 ] = $cgiparams { 'DEST_PORT' };
4361 $confighash { $key }[ 30 ] = $cgiparams { 'COMPLZO' };
4362 $confighash { $key }[ 31 ] = $cgiparams { 'MTU' };
4363 $confighash { $key }[ 32 ] = $cgiparams { 'CHECK1' };
4364 $name = $cgiparams { 'CHECK1' };
4365 $confighash { $key }[ 33 ] = $cgiparams { $name };
4366 $confighash { $key }[ 34 ] = $cgiparams { 'RG' };
4367 $confighash { $key }[ 35 ] = $cgiparams { 'CCD_DNS1' };
4368 $confighash { $key }[ 36 ] = $cgiparams { 'CCD_DNS2' };
4369 $confighash { $key }[ 37 ] = $cgiparams { 'CCD_WINS' };
4370 $confighash { $key }[ 39 ] = $cgiparams { 'DAUTH' };
4371 $confighash { $key }[ 40 ] = $cgiparams { 'DCIPHER' };
4373 if (( $cgiparams { 'TYPE' } eq 'host' ) && ( $cgiparams { 'CERT_PASS1' } eq "" )) {
4374 $confighash { $key }[ 41 ] = "no-pass" ;
4377 $confighash { $key }[ 42 ] = 'HOTP/T30/6' ;
4378 $confighash { $key }[ 43 ] = $cgiparams { 'OTP_STATE' };
4379 if (( $confighash { $key }[ 43 ] eq 'on' ) && ( $confighash { $key }[ 44 ] eq '' )) {
4380 my @otp_secret = & General
:: system_output
( "/usr/bin/openssl" , "rand" , "-hex" , "20" );
4381 chomp ( $otp_secret [ 0 ]);
4382 $confighash { $key }[ 44 ] = $otp_secret [ 0 ];
4383 } elsif ( $confighash { $key }[ 43 ] eq '' ) {
4384 $confighash { $key }[ 44 ] = '' ;
4387 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
4389 if ( $cgiparams { 'CHECK1' } ){
4391 my ( $ccdip , $ccdsub )= split "/" , $cgiparams { $name };
4392 my ( $a , $b , $c , $d ) = split ( /\./ , $ccdip );
4393 if ( - e
"${General::swroot}/ovpn/ccd/ $confighash { $key }[2]" ){
4394 unlink "${General::swroot}/ovpn/ccd/ $cgiparams {'CERT_NAME'}" ;
4396 open ( CCDRWCONF
, '>' , "${General::swroot}/ovpn/ccd/ $confighash { $key }[2]" ) or die "Unable to create clientconfigfile $!" ;
4397 print CCDRWCONF
"# OpenVPN clientconfig from ccd extension by Copymaster# \n\n " ;
4398 if ( $cgiparams { 'CHECK1' } eq 'dynamic' ){
4399 print CCDRWCONF
"#This client uses the dynamic pool \n " ;
4401 print CCDRWCONF
"#Ip address client and server \n " ;
4402 print CCDRWCONF
"ifconfig-push $ccdip " .& General
:: getlastip
( $ccdip , 1 ). " \n " ;
4404 if ( $confighash { $key }[ 34 ] eq 'on' ){
4405 print CCDRWCONF
" \n #Redirect Gateway: \n #All IP traffic is redirected through the vpn \n " ;
4406 print CCDRWCONF
"push redirect-gateway \n " ;
4408 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
4409 if ( $cgiparams { 'IR' } ne '' ){
4410 print CCDRWCONF
" \n #Client routes these networks (behind Client) \n " ;
4411 foreach my $key ( keys %ccdroutehash ){
4412 if ( $ccdroutehash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4413 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}){
4414 my ( $a , $b )= split ( /\/ /, $ccdroutehash { $key }[ $i ]);
4415 print CCDRWCONF
"iroute $a $b \n " ;
4420 if ( $cgiparams { 'IFROUTE' } eq $Lang :: tr
{ 'ccd none' } ){ $cgiparams { 'IFROUTE' }= '' ;}
4421 if ( $cgiparams { 'IFROUTE' } ne '' ){
4422 print CCDRWCONF
" \n #Client gets routes to these networks (behind IPFire) \n " ;
4423 foreach my $key ( keys %ccdroute2hash ){
4424 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4425 foreach my $i ( 1 .. $ #{$ccdroute2hash{$key}}){
4426 if ( $ccdroute2hash { $key }[ $i ] eq $Lang :: tr
{ 'blue' }){
4428 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%blue );
4429 print CCDRWCONF
"push \" route $blue {BLUE_ADDRESS} $blue {BLUE_NETMASK} \n " ;
4430 } elsif ( $ccdroute2hash { $key }[ $i ] eq $Lang :: tr
{ 'orange' }){
4432 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%orange );
4433 print CCDRWCONF
"push \" route $orange {ORANGE_ADDRESS} $orange {ORANGE_NETMASK} \n " ;
4435 my ( $a , $b )= split ( /\/ /, $ccdroute2hash { $key }[ $i ]);
4436 print CCDRWCONF
"push \" route $a $b \"\n " ;
4442 if (( $cgiparams { 'CCD_DNS1' } eq '' ) && ( $cgiparams { 'CCD_DNS1' } ne '' )){ $cgiparams { 'CCD_DNS1' } = $cgiparams { 'CCD_DNS2' }; $cgiparams { 'CCD_DNS2' }= '' ;}
4443 if ( $cgiparams { 'CCD_DNS1' } ne '' ){
4444 print CCDRWCONF
" \n #Client gets these nameservers \n " ;
4445 print CCDRWCONF
"push \" dhcp-option DNS $cgiparams {'CCD_DNS1'} \" \n " ;
4447 if ( $cgiparams { 'CCD_DNS2' } ne '' ){
4448 print CCDRWCONF
"push \" dhcp-option DNS $cgiparams {'CCD_DNS2'} \" \n " ;
4450 if ( $cgiparams { 'CCD_WINS' } ne '' ){
4451 print CCDRWCONF
" \n #Client gets this WINS server \n " ;
4452 print CCDRWCONF
"push \" dhcp-option WINS $cgiparams {'CCD_WINS'} \" \n " ;
4461 if ( $cgiparams { 'TYPE' } eq 'net' ) {
4463 if (- e
"/var/run/ $confighash { $key }[1]n2n.pid" ) {
4464 & General
:: system ( "/usr/local/bin/openvpnctrl" , "-kn2n" , " $confighash { $cgiparams {'KEY'}}[1]" );
4466 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
4467 my $key = $cgiparams { 'KEY' };
4469 $key = & General
:: findhasharraykey
( \
%confighash );
4470 foreach my $i ( 0 .. 31 ) {
4471 $confighash { $key }[ $i ] = "" ;
4475 $confighash { $key }[ 0 ] = 'on' ;
4476 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
4478 & General
:: system ( "/usr/local/bin/openvpnctrl" , "-sn2n" , " $confighash { $cgiparams {'KEY'}}[1]" );
4486 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
4487 $cgiparams { 'KEY' } = $key ;
4488 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
4492 $cgiparams { 'ENABLED' } = 'on' ;
4496 $cgiparams { 'MSSFIX' } = 'on' ;
4497 $cgiparams { 'FRAGMENT' } = '1300' ;
4498 $cgiparams { 'DAUTH' } = 'SHA512' ;
4502 $cgiparams { 'SIDE' } = 'left' ;
4503 if ( ! - f
"${General::swroot}/ovpn/ca/cakey.pem" ) {
4504 $cgiparams { 'AUTH' } = 'psk' ;
4505 } elsif ( ! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
4506 $cgiparams { 'AUTH' } = 'certfile' ;
4508 $cgiparams { 'AUTH' } = 'certgen' ;
4510 $cgiparams { 'LOCAL_SUBNET' } = " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" ;
4511 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
4512 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
4513 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
4514 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
4515 $cgiparams { 'DAYS_VALID' } = $vpnsettings { 'DAYS_VALID' } = '730' ;
4519 $checked { 'ENABLED' }{ 'off' } = '' ;
4520 $checked { 'ENABLED' }{ 'on' } = '' ;
4521 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = 'CHECKED' ;
4522 $checked { 'ENABLED_BLUE' }{ 'off' } = '' ;
4523 $checked { 'ENABLED_BLUE' }{ 'on' } = '' ;
4524 $checked { 'ENABLED_BLUE' }{ $cgiparams { 'ENABLED_BLUE' }} = 'CHECKED' ;
4525 $checked { 'ENABLED_ORANGE' }{ 'off' } = '' ;
4526 $checked { 'ENABLED_ORANGE' }{ 'on' } = '' ;
4527 $checked { 'ENABLED_ORANGE' }{ $cgiparams { 'ENABLED_ORANGE' }} = 'CHECKED' ;
4530 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
4531 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
4532 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = 'CHECKED' ;
4534 $selected { 'SIDE' }{ 'server' } = '' ;
4535 $selected { 'SIDE' }{ 'client' } = '' ;
4536 $selected { 'SIDE' }{ $cgiparams { 'SIDE' }} = 'SELECTED' ;
4538 $selected { 'PROTOCOL' }{ 'udp' } = '' ;
4539 $selected { 'PROTOCOL' }{ 'tcp' } = '' ;
4540 $selected { 'PROTOCOL' }{ $cgiparams { 'PROTOCOL' }} = 'SELECTED' ;
4543 $checked { 'AUTH' }{ 'psk' } = '' ;
4544 $checked { 'AUTH' }{ 'certreq' } = '' ;
4545 $checked { 'AUTH' }{ 'certgen' } = '' ;
4546 $checked { 'AUTH' }{ 'certfile' } = '' ;
4547 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = 'CHECKED' ;
4549 $selected { 'INTERFACE' }{ $cgiparams { 'INTERFACE' }} = 'SELECTED' ;
4551 $checked { 'COMPLZO' }{ 'off' } = '' ;
4552 $checked { 'COMPLZO' }{ 'on' } = '' ;
4553 $checked { 'COMPLZO' }{ $cgiparams { 'COMPLZO' }} = 'CHECKED' ;
4555 $checked { 'MSSFIX' }{ 'off' } = '' ;
4556 $checked { 'MSSFIX' }{ 'on' } = '' ;
4557 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
4559 $selected { 'DCIPHER' }{ 'AES-256-GCM' } = '' ;
4560 $selected { 'DCIPHER' }{ 'AES-192-GCM' } = '' ;
4561 $selected { 'DCIPHER' }{ 'AES-128-GCM' } = '' ;
4562 $selected { 'DCIPHER' }{ 'CAMELLIA-256-CBC' } = '' ;
4563 $selected { 'DCIPHER' }{ 'CAMELLIA-192-CBC' } = '' ;
4564 $selected { 'DCIPHER' }{ 'CAMELLIA-128-CBC' } = '' ;
4565 $selected { 'DCIPHER' }{ 'AES-256-CBC' } = '' ;
4566 $selected { 'DCIPHER' }{ 'AES-192-CBC' } = '' ;
4567 $selected { 'DCIPHER' }{ 'AES-128-CBC' } = '' ;
4568 $selected { 'DCIPHER' }{ 'DESX-CBC' } = '' ;
4569 $selected { 'DCIPHER' }{ 'SEED-CBC' } = '' ;
4570 $selected { 'DCIPHER' }{ 'DES-EDE3-CBC' } = '' ;
4571 $selected { 'DCIPHER' }{ 'DES-EDE-CBC' } = '' ;
4572 $selected { 'DCIPHER' }{ 'CAST5-CBC' } = '' ;
4573 $selected { 'DCIPHER' }{ 'BF-CBC' } = '' ;
4574 $selected { 'DCIPHER' }{ 'DES-CBC' } = '' ;
4575 # If no cipher has been chossen yet, select
4576 # the old default (AES-256-CBC) for compatiblity reasons.
4577 if ( $cgiparams { 'DCIPHER' } eq '' ) {
4578 $cgiparams { 'DCIPHER' } = 'AES-256-CBC' ;
4580 $selected { 'DCIPHER' }{ $cgiparams { 'DCIPHER' }} = 'SELECTED' ;
4581 $selected { 'DAUTH' }{ 'whirlpool' } = '' ;
4582 $selected { 'DAUTH' }{ 'SHA512' } = '' ;
4583 $selected { 'DAUTH' }{ 'SHA384' } = '' ;
4584 $selected { 'DAUTH' }{ 'SHA256' } = '' ;
4585 $selected { 'DAUTH' }{ 'SHA1' } = '' ;
4586 $selected { 'DAUTH' }{ $cgiparams { 'DAUTH' }} = 'SELECTED' ;
4587 $checked { 'TLSAUTH' }{ 'off' } = '' ;
4588 $checked { 'TLSAUTH' }{ 'on' } = '' ;
4589 $checked { 'TLSAUTH' }{ $cgiparams { 'TLSAUTH' }} = 'CHECKED' ;
4592 & Header
:: showhttpheaders
();
4593 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
4594 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
4595 if ( $errormessage ) {
4596 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
4597 print "<class name='base'> $errormessage " ;
4598 print " </class>" ;
4599 & Header
:: closebox
();
4603 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'warning messages'}:" );
4604 print "<class name='base'> $warnmessage " ;
4605 print " </class>" ;
4606 & Header
:: closebox
();
4609 print "<form method='post' enctype='multipart/form-data'>" ;
4610 print "<input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />" ;
4612 if ( $cgiparams { 'KEY' }) {
4613 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
4614 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
4617 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'connection'}:" );
4618 print "<table width='100%' border='0'> \n " ;
4620 print "<tr><td width='14%' class='boldbase'> $Lang ::tr{'name'}: <img src='/blob.gif' alt='*' /></td>" ;
4622 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4623 if ( $cgiparams { 'KEY' }) {
4624 print "<td width='35%' class='base'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /> $cgiparams {'NAME'}</td>" ;
4626 print "<td width='35%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' maxlength='20' size='30' /></td>" ;
4628 # print "<tr><td>$Lang::tr{'interface'}</td>";
4629 # print "<td><select name='INTERFACE'>";
4630 # print "<option value='RED' $selected{'INTERFACE'}{'RED'}>RED</option>";
4631 # if ($netsettings{'BLUE_DEV'} ne '') {
4632 # print "<option value='BLUE' $selected{'INTERFACE'}{'BLUE'}>BLUE</option>";
4634 # print "<option value='GREEN' $selected{'INTERFACE'}{'GREEN'}>GREEN</option>";
4635 # print "<option value='ORANGE' $selected{'INTERFACE'}{'ORANGE'}>ORANGE</option>";
4636 # print "</select></td></tr>";
4639 print "<input type='hidden' name='INTERFACE' value='red' />" ;
4640 if ( $cgiparams { 'KEY' }) {
4641 print "<td width='25%' class='base' nowrap='nowrap'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /> $cgiparams {'NAME'}</td>" ;
4643 print "<td width='25%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' maxlength='20' /></td>" ;
4646 # If GCM ciphers are in usage, HMAC menu is disabled
4648 if (( $confighash { $cgiparams { 'KEY' }}[ 40 ] eq 'AES-256-GCM' ) ||
4649 ( $confighash { $cgiparams { 'KEY' }}[ 40 ] eq 'AES-192-GCM' ) ||
4650 ( $confighash { $cgiparams { 'KEY' }}[ 40 ] eq 'AES-128-GCM' )) {
4651 $hmacdisabled = "disabled='disabled'" ;
4655 <td width='25%'> </td>
4656 <td width='25%'> </td></tr>
4657 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'Act as'}</td>
4658 <td><select name='SIDE'>
4659 <option value='server' $selected {'SIDE'}{'server'}> $Lang ::tr{'openvpn server'}</option>
4660 <option value='client' $selected {'SIDE'}{'client'}> $Lang ::tr{'openvpn client'}</option>
4664 <td class='boldbase'> $Lang ::tr{'remote host/ip'}:</td>
4665 <td><input type='TEXT' name='REMOTE' value=' $cgiparams {'REMOTE'}' /></td>
4668 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'} <img src='/blob.gif' alt='*' /></td>
4669 <td><input type='TEXT' name='LOCAL_SUBNET' value=' $cgiparams {'LOCAL_SUBNET'}' /></td>
4671 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'} <img src='/blob.gif' alt='*' /></td>
4672 <td><input type='text' name='REMOTE_SUBNET' value=' $cgiparams {'REMOTE_SUBNET'}' /></td>
4675 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn subnet'} <img src='/blob.gif' alt='*' /></td>
4676 <td><input type='TEXT' name='OVPN_SUBNET' value=' $cgiparams {'OVPN_SUBNET'}' /></td>
4678 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td>
4679 <td><select name='PROTOCOL'>
4680 <option value='udp' $selected {'PROTOCOL'}{'udp'}>UDP</option>
4681 <option value='tcp' $selected {'PROTOCOL'}{'tcp'}>TCP</option></select></td>
4685 <td class='boldbase'> $Lang ::tr{'destination port'}: <img src='/blob.gif' alt='*' /></td>
4686 <td><input type='TEXT' name='DEST_PORT' value=' $cgiparams {'DEST_PORT'}' size='5' /></td>
4688 <td class='boldbase' nowrap='nowrap'>Management Port ( $Lang ::tr{'openvpn default'}: <span class="base"> $Lang ::tr{'destination port'}):</td>
4689 <td> <input type='TEXT' name='OVPN_MGMT' VALUE=' $cgiparams {'OVPN_MGMT'}'size='5' /></td>
4692 <tr><td colspan=4><hr /></td></tr><tr>
4695 <td class='base'><b> $Lang ::tr{'MTU settings'}</b></td>
4698 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'}</td>
4699 <td><input type='TEXT' name='MTU' VALUE=' $cgiparams {'MTU'}'size='5' /></td>
4700 <td colspan='2'> $Lang ::tr{'openvpn default'}: udp/tcp <span class="base">1500/1400</span></td>
4703 <tr><td class='boldbase' nowrap='nowrap'>fragment:</td>
4704 <td><input type='TEXT' name='FRAGMENT' VALUE=' $cgiparams {'FRAGMENT'}'size='5' /></td>
4705 <td> $Lang ::tr{'openvpn default'}: <span class="base">1300</span></td>
4708 <tr><td class='boldbase' nowrap='nowrap'>mssfix:</td>
4709 <td><input type='checkbox' name='MSSFIX' $checked {'MSSFIX'}{'on'} /></td>
4710 <td> $Lang ::tr{'openvpn default'}: <span class="base">on</span></td>
4713 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'}</td>
4714 <td><input type='checkbox' name='COMPLZO' $checked {'COMPLZO'}{'on'} /></td>
4717 <tr><td colspan=4><hr /></td></tr><tr>
4719 <td class='base'><b> $Lang ::tr{'ovpn crypt options'}:</b></td>
4722 <tr><td class='boldbase'> $Lang ::tr{'cipher'}</td>
4723 <td><select name='DCIPHER' id="n2ncipher" required>
4724 <option value='AES-256-GCM' $selected {'DCIPHER'}{'AES-256-GCM'}>AES-GCM (256 $Lang ::tr{'bit'})</option>
4725 <option value='AES-192-GCM' $selected {'DCIPHER'}{'AES-192-GCM'}>AES-GCM (192 $Lang ::tr{'bit'})</option>
4726 <option value='AES-128-GCM' $selected {'DCIPHER'}{'AES-128-GCM'}>AES-GCM (128 $Lang ::tr{'bit'})</option>
4727 <option value='CAMELLIA-256-CBC' $selected {'DCIPHER'}{'CAMELLIA-256-CBC'}>CAMELLIA-CBC (256 $Lang ::tr{'bit'})</option>
4728 <option value='CAMELLIA-192-CBC' $selected {'DCIPHER'}{'CAMELLIA-192-CBC'}>CAMELLIA-CBC (192 $Lang ::tr{'bit'})</option>
4729 <option value='CAMELLIA-128-CBC' $selected {'DCIPHER'}{'CAMELLIA-128-CBC'}>CAMELLIA-CBC (128 $Lang ::tr{'bit'})</option>
4730 <option value='AES-256-CBC' $selected {'DCIPHER'}{'AES-256-CBC'}>AES-CBC (256 $Lang ::tr{'bit'}, $Lang ::tr{'default'})</option>
4731 <option value='AES-192-CBC' $selected {'DCIPHER'}{'AES-192-CBC'}>AES-CBC (192 $Lang ::tr{'bit'})</option>
4732 <option value='AES-128-CBC' $selected {'DCIPHER'}{'AES-128-CBC'}>AES-CBC (128 $Lang ::tr{'bit'})</option>
4733 <option value='SEED-CBC' $selected {'DCIPHER'}{'SEED-CBC'}>SEED-CBC (128 $Lang ::tr{'bit'})</option>
4734 <option value='DES-EDE3-CBC' $selected {'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC (192 $Lang ::tr{'bit'}, $Lang ::tr{'vpn weak'})</option>
4735 <option value='DESX-CBC' $selected {'DCIPHER'}{'DESX-CBC'}>DESX-CBC (192 $Lang ::tr{'bit'}, $Lang ::tr{'vpn weak'})</option>
4736 <option value='DES-EDE-CBC' $selected {'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC (128 $Lang ::tr{'bit'}, $Lang ::tr{'vpn weak'})</option>
4737 <option value='BF-CBC' $selected {'DCIPHER'}{'BF-CBC'}>BF-CBC (128 $Lang ::tr{'bit'}, $Lang ::tr{'vpn weak'})</option>
4738 <option value='CAST5-CBC' $selected {'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC (128 $Lang ::tr{'bit'}, $Lang ::tr{'vpn weak'})</option>
4742 <td class='boldbase'> $Lang ::tr{'ovpn ha'}:</td>
4743 <td><select name='DAUTH' id="n2nhmac" $hmacdisabled >
4744 <option value='whirlpool' $selected {'DAUTH'}{'whirlpool'}>Whirlpool (512 $Lang ::tr{'bit'})</option>
4745 <option value='SHA512' $selected {'DAUTH'}{'SHA512'}>SHA2 (512 $Lang ::tr{'bit'})</option>
4746 <option value='SHA384' $selected {'DAUTH'}{'SHA384'}>SHA2 (384 $Lang ::tr{'bit'})</option>
4747 <option value='SHA256' $selected {'DAUTH'}{'SHA256'}>SHA2 (256 $Lang ::tr{'bit'})</option>
4748 <option value='SHA1' $selected {'DAUTH'}{'SHA1'}>SHA1 (160 $Lang ::tr{'bit'}, $Lang ::tr{'vpn weak'})</option>
4752 <tr><td colspan=4><hr /></td></tr><tr>
4758 #### JAVA SCRIPT ####
4759 # Validate N2N cipher. If GCM will be used, HMAC menu will be disabled onchange
4762 var disable_options = false;
4763 document.getElementById('n2ncipher').onchange = function () {
4764 if((this.value == "AES-256-GCM"||this.value == "AES-192-GCM"||this.value == "AES-128-GCM")) {
4765 document.getElementById('n2nhmac').setAttribute('disabled', true);
4767 document.getElementById('n2nhmac').removeAttribute('disabled');
4774 print "<tr><td class='boldbase'> $Lang ::tr{'remark title'}</td>" ;
4775 print "<td colspan='3'><input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' size='55' maxlength='50' /></td></tr></table>" ;
4777 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4778 print "<tr><td> $Lang ::tr{'enabled'} <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>" ;
4781 print "</tr></table><br><br>" ;
4782 #A.Marx CCD new client
4783 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4784 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>" ;
4787 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnnet );
4788 $vpnip = $vpnnet { 'DOVPN_SUBNET' };
4789 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
4793 $checked { 'check1' }{ 'off' } = '' ;
4794 $checked { 'check1' }{ 'on' } = '' ;
4795 $checked { 'check1' }{ $cgiparams { 'CHECK1' }} = 'CHECKED' ;
4796 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%'>" ;
4797 print "</td></tr></table><br><br>" ;
4798 my $name = $cgiparams { 'CHECK1' };
4799 $checked { 'RG' }{ $cgiparams { 'RG' }} = 'CHECKED' ;
4800 $checked { 'OTP_STATE' }{ $cgiparams { 'OTP_STATE' }} = 'CHECKED' ;
4802 if (! - z
"${General::swroot}/ovpn/ccd.conf" ){
4803 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>" ;
4804 foreach my $key ( sort { uc ( $ccdconfhash { $a }[ 0 ]) cmp uc ( $ccdconfhash { $b }[ 0 ]) } keys %ccdconfhash ) {
4806 @ccdconf =( $ccdconfhash { $key }[ 0 ], $ccdconfhash { $key }[ 1 ]);
4807 if ( $count % 2 ){ print "<tr bgcolor=' $color {'color22'}'>" ;} else { print "<tr bgcolor=' $color {'color20'}'>" ;}
4808 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%'>" ;
4809 & fillselectbox
( $ccdconf [ 1 ], $ccdconf [ 0 ], $cgiparams { $name });
4812 print "</table><br><br><hr><br><br>" ;
4816 & Header
:: closebox
();
4817 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
4819 } elsif (! $cgiparams { 'KEY' }) {
4823 my $cakeydisabled = '' ;
4824 my $cacrtdisabled = '' ;
4825 if ( ! - f
"${General::swroot}/ovpn/ca/cakey.pem" ) { $cakeydisabled = "disabled='disabled'" } else { $cakeydisabled = "" };
4826 if ( ! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) { $cacrtdisabled = "disabled='disabled'" } else { $cacrtdisabled = "" };
4828 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'authentication' });
4831 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4834 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
4836 <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>
4837 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td><td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
4838 <tr><td colspan='3'> </td></tr>
4839 <tr><td colspan='3'><hr /></td></tr>
4840 <tr><td colspan='3'> </td></tr>
4841 <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>
4842 <tr><td> </td><td class='base'> $Lang ::tr{'users fullname or system hostname'}: <img src='/blob.gif' alt='*' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' SIZE='32' $cakeydisabled /></td></tr>
4843 <tr><td> </td><td class='base'> $Lang ::tr{'users email'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' SIZE='32' $cakeydisabled /></td></tr>
4844 <tr><td> </td><td class='base'> $Lang ::tr{'users department'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' SIZE='32' $cakeydisabled /></td></tr>
4845 <tr><td> </td><td class='base'> $Lang ::tr{'organization name'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' SIZE='32' $cakeydisabled /></td></tr>
4846 <tr><td> </td><td class='base'> $Lang ::tr{'city'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' SIZE='32' $cakeydisabled /></td></tr>
4847 <tr><td> </td><td class='base'> $Lang ::tr{'state or province'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' SIZE='32' $cakeydisabled /></td></tr>
4848 <tr><td> </td><td class='base'> $Lang ::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
4859 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
4861 <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>
4862 <tr><td> </td><td class='base'> $Lang ::tr{'users fullname or system hostname'}: <img src='/blob.gif' alt='*' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' SIZE='32' $cakeydisabled /></td></tr>
4863 <tr><td> </td><td class='base'> $Lang ::tr{'users email'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' SIZE='32' $cakeydisabled /></td></tr>
4864 <tr><td> </td><td class='base'> $Lang ::tr{'users department'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' SIZE='32' $cakeydisabled /></td></tr>
4865 <tr><td> </td><td class='base'> $Lang ::tr{'organization name'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' SIZE='32' $cakeydisabled /></td></tr>
4866 <tr><td> </td><td class='base'> $Lang ::tr{'city'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' SIZE='32' $cakeydisabled /></td></tr>
4867 <tr><td> </td><td class='base'> $Lang ::tr{'state or province'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' SIZE='32' $cakeydisabled /></td></tr>
4868 <tr><td> </td><td class='base'> $Lang ::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
4880 foreach my $country ( sort keys %{ Countries
:: countries
}) {
4881 print "<option value=' $Countries ::countries{ $country }'" ;
4882 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
4883 print " selected='selected'" ;
4885 print "> $country </option>" ;
4891 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4894 <td> </td><td class='base'> $Lang ::tr{'valid till'} (days): <img src='/blob.gif' alt='*' /</td>
4895 <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value=' $cgiparams {'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr>
4897 <td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
4898 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
4899 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'}:<br>( $Lang ::tr{'confirmation'})</td>
4900 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
4901 <tr><td colspan='3'> </td></tr>
4902 <tr><td colspan='3'><hr /></td></tr>
4903 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'required field'}</td></tr>
4909 <td> </td><td class='base'> $Lang ::tr{'valid till'} (days): <img src='/blob.gif' alt='*' /</td>
4910 <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value=' $cgiparams {'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr>
4911 <tr><td> </td><td> </td><td> </td></tr>
4912 <tr><td> </td><td> </td><td> </td></tr>
4913 <tr><td colspan='3'><hr /></td></tr>
4914 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'required field'}</td></tr>
4924 & Header
:: closebox
();
4928 #A.Marx CCD new client
4929 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4931 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'ccd client options'}:" );
4935 <table border='0' width='100%'>
4936 <tr><td width='20%'> $Lang ::tr{'enable otp'}:</td><td colspan='3'><input type='checkbox' name='OTP_STATE' $checked{'OTP_STATE'}{'on'} /></td></tr>
4937 <tr><td width='20%'>Redirect Gateway:</td><td colspan='3'><input type='checkbox' name='RG' $checked {'RG'}{'on'} /></td></tr>
4938 <tr><td colspan='4'><b><br> $Lang ::tr{'ccd routes'}</b></td></tr>
4939 <tr><td colspan='4'> </td></tr>
4940 <tr><td valign='top'> $Lang ::tr{'ccd iroute'}</td><td align='left' width='30%'><textarea name='IR' cols='26' rows='6' wrap='off'>
4943 if ( $cgiparams { 'IR' } ne '' ){
4944 print $cgiparams { 'IR' };
4946 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
4947 foreach my $key ( keys %ccdroutehash ) {
4948 if ( $cgiparams { 'NAME' } eq $ccdroutehash { $key }[ 0 ]){
4949 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}) {
4950 if ( $ccdroutehash { $key }[ $i ] ne '' ){
4951 print $ccdroutehash { $key }[ $i ]. " \n " ;
4953 $cgiparams { 'IR' } .= $ccdroutehash { $key }[ $i ];
4960 </textarea></td><td valign='top' colspan='2'> $Lang ::tr{'ccd iroutehint'}</td></tr>
4961 <tr><td colspan='4'><br></td></tr>
4962 <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>
4976 open ( FILE
, "${General::swroot}/main/routing" ) ;
4979 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
4981 foreach my $key ( keys %ccdroute2hash ) {
4982 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4983 if ( $ccdroute2hash { $key }[ 1 ] eq '' ){
4990 print "<option> $Lang ::tr{'ccd none'}</option>" ;
4992 print "<option selected> $Lang ::tr{'ccd none'}</option>" ;
4994 #check if static routes are defined for client
4995 foreach my $line ( @current ) {
4997 $line =~ s/\s*$//g ; # remove newline
4998 @temp = split ( /\,/ , $line );
4999 $temp [ 1 ] = '' unless defined $temp [ 1 ]; # not always populated
5000 my ( $a , $b ) = split ( /\/ /, $temp [ 1 ]);
5001 $temp [ 1 ] = $a . "/" .& General
:: iporsubtocidr
( $b );
5002 foreach my $key ( keys %ccdroute2hash ) {
5003 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
5004 foreach my $i ( 1 .. $ #{$ccdroute2hash{$key}}) {
5005 if ( $ccdroute2hash { $key }[ $i ] eq $a . "/" .& General
:: iporsubtodec
( $b )){
5011 if ( $set == '1' && $#temp != - 1 ){ print "<option selected> $temp [1]</option>" ; $set = 0 ;} elsif ( $set == '0' && $#temp != - 1 ){ print "<option> $temp [1]</option>" ;}
5015 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%vpnconfig );
5016 foreach my $vpn ( keys %vpnconfig ) {
5017 # Skip all disabled VPN connections
5018 my $enabled = $vpnconfig { $vpn }[ 0 ];
5019 next unless ( $enabled eq "on" );
5021 my $name = $vpnconfig { $vpn }[ 1 ];
5024 my @networks = split ( /\|/ , $vpnconfig { $vpn }[ 11 ]);
5025 foreach my $network ( @networks ) {
5028 foreach my $key ( keys %ccdroute2hash ) {
5029 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }) {
5030 foreach my $i ( 1 .. $ #{$ccdroute2hash{$key}}) {
5031 if ( $ccdroute2hash { $key }[ $i ] eq $network ) {
5032 $selected = "selected" ;
5038 print "<option value= \" $network \" $selected > $name ( $network )</option> \n " ;
5042 #check if green,blue,orange are defined for client
5043 foreach my $key ( keys %ccdroute2hash ) {
5044 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
5046 foreach my $i ( 1 .. $ #{$ccdroute2hash{$key}}) {
5047 if ( $ccdroute2hash { $key }[ $i ] eq $netsettings { 'GREEN_NETADDRESS' }. "/" .& General
:: iporsubtodec
( $netsettings { 'GREEN_NETMASK' })){
5050 if (& haveBlueNet
()){
5051 if ( $ccdroute2hash { $key }[ $i ] eq $netsettings { 'BLUE_NETADDRESS' }. "/" .& General
:: iporsubtodec
( $netsettings { 'BLUE_NETMASK' })) {
5055 if (& haveOrangeNet
()){
5056 if ( $ccdroute2hash { $key }[ $i ] eq $netsettings { 'ORANGE_NETADDRESS' }. "/" .& General
:: iporsubtodec
( $netsettings { 'ORANGE_NETMASK' }) ) {
5063 if (& haveBlueNet
() && $selblue == '1' ){ print "<option selected> $Lang ::tr{'blue'}</option>" ; $selblue = 0 ;} elsif (& haveBlueNet
() && $selblue == '0' ){ print "<option> $Lang ::tr{'blue'}</option>" ;}
5064 if (& haveOrangeNet
() && $selorange == '1' ){ print "<option selected> $Lang ::tr{'orange'}</option>" ; $selorange = 0 ;} elsif (& haveOrangeNet
() && $selorange == '0' ){ print "<option> $Lang ::tr{'orange'}</option>" ;}
5065 if ( $selgreen == '1' || $other == '0' ){ print "<option selected> $Lang ::tr{'green'}</option>" ; $set = 0 ;} else { print "<option> $Lang ::tr{'green'}</option>" ;};
5068 </select></td><td valign='top'>DNS1:</td><td valign='top'><input type='TEXT' name='CCD_DNS1' value=' $cgiparams {'CCD_DNS1'}' size='30' /></td></tr>
5069 <tr valign='top'><td>DNS2:</td><td><input type='TEXT' name='CCD_DNS2' value=' $cgiparams {'CCD_DNS2'}' size='30' /></td></tr>
5070 <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>
5074 & Header
:: closebox
();
5076 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
5077 if ( $cgiparams { 'KEY' }) {
5078 # print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />";
5080 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
5081 & Header
:: closebigbox
();
5082 & Header
:: closepage
();
5090 ### Default status page
5095 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%cgiparams );
5096 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
5097 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
5099 open ( FILE
, "/var/run/ovpnserver.log" );
5100 my @status = < FILE
>;
5103 if ( $cgiparams { 'VPN_IP' } eq '' && - e
"${General::swroot}/red/active" ) {
5104 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
5105 my $ipaddr = < IPADDR
>;
5108 $cgiparams { 'VPN_IP' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
5109 if ( $cgiparams { 'VPN_IP' } eq '' ) {
5110 $cgiparams { 'VPN_IP' } = $ipaddr ;
5116 if ( $cgiparams { 'DCIPHER' } eq '' ) {
5117 $cgiparams { 'DCIPHER' } = 'AES-256-CBC' ;
5119 if ( $cgiparams { 'DDEST_PORT' } eq '' ) {
5120 $cgiparams { 'DDEST_PORT' } = '1194' ;
5122 if ( $cgiparams { 'DMTU' } eq '' ) {
5123 $cgiparams { 'DMTU' } = '1400' ;
5125 if ( $cgiparams { 'MSSFIX' } eq '' ) {
5126 $cgiparams { 'MSSFIX' } = 'off' ;
5128 if ( $cgiparams { 'DAUTH' } eq '' ) {
5129 if (- z
"${General::swroot}/ovpn/ovpnconfig" ) {
5130 $cgiparams { 'DAUTH' } = 'SHA512' ;
5132 foreach my $key ( keys %confighash ) {
5133 if ( $confighash { $key }[ 3 ] ne 'host' ) {
5134 $cgiparams { 'DAUTH' } = 'SHA512' ;
5136 $cgiparams { 'DAUTH' } = 'SHA1' ;
5140 if ( $cgiparams { 'TLSAUTH' } eq '' ) {
5141 $cgiparams { 'TLSAUTH' } = 'off' ;
5143 if ( $cgiparams { 'DOVPN_SUBNET' } eq '' ) {
5144 $cgiparams { 'DOVPN_SUBNET' } = '10.' . int ( rand ( 256 )) . '.' . int ( rand ( 256 )) . '.0/255.255.255.0' ;
5146 $checked { 'ENABLED' }{ 'off' } = '' ;
5147 $checked { 'ENABLED' }{ 'on' } = '' ;
5148 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = 'CHECKED' ;
5149 $checked { 'ENABLED_BLUE' }{ 'off' } = '' ;
5150 $checked { 'ENABLED_BLUE' }{ 'on' } = '' ;
5151 $checked { 'ENABLED_BLUE' }{ $cgiparams { 'ENABLED_BLUE' }} = 'CHECKED' ;
5152 $checked { 'ENABLED_ORANGE' }{ 'off' } = '' ;
5153 $checked { 'ENABLED_ORANGE' }{ 'on' } = '' ;
5154 $checked { 'ENABLED_ORANGE' }{ $cgiparams { 'ENABLED_ORANGE' }} = 'CHECKED' ;
5156 $selected { 'DPROTOCOL' }{ 'udp' } = '' ;
5157 $selected { 'DPROTOCOL' }{ 'tcp' } = '' ;
5158 $selected { 'DPROTOCOL' }{ $cgiparams { 'DPROTOCOL' }} = 'SELECTED' ;
5160 $selected { 'DCIPHER' }{ 'AES-256-GCM' } = '' ;
5161 $selected { 'DCIPHER' }{ 'AES-192-GCM' } = '' ;
5162 $selected { 'DCIPHER' }{ 'AES-128-GCM' } = '' ;
5163 $selected { 'DCIPHER' }{ 'CAMELLIA-256-CBC' } = '' ;
5164 $selected { 'DCIPHER' }{ 'CAMELLIA-192-CBC' } = '' ;
5165 $selected { 'DCIPHER' }{ 'CAMELLIA-128-CBC' } = '' ;
5166 $selected { 'DCIPHER' }{ 'AES-256-CBC' } = '' ;
5167 $selected { 'DCIPHER' }{ 'AES-192-CBC' } = '' ;
5168 $selected { 'DCIPHER' }{ 'AES-128-CBC' } = '' ;
5169 $selected { 'DCIPHER' }{ 'DES-EDE3-CBC' } = '' ;
5170 $selected { 'DCIPHER' }{ 'DESX-CBC' } = '' ;
5171 $selected { 'DCIPHER' }{ 'SEED-CBC' } = '' ;
5172 $selected { 'DCIPHER' }{ 'DES-EDE-CBC' } = '' ;
5173 $selected { 'DCIPHER' }{ 'CAST5-CBC' } = '' ;
5174 $selected { 'DCIPHER' }{ 'BF-CBC' } = '' ;
5175 $selected { 'DCIPHER' }{ 'DES-CBC' } = '' ;
5176 $selected { 'DCIPHER' }{ $cgiparams { 'DCIPHER' }} = 'SELECTED' ;
5178 $selected { 'DAUTH' }{ 'whirlpool' } = '' ;
5179 $selected { 'DAUTH' }{ 'SHA512' } = '' ;
5180 $selected { 'DAUTH' }{ 'SHA384' } = '' ;
5181 $selected { 'DAUTH' }{ 'SHA256' } = '' ;
5182 $selected { 'DAUTH' }{ 'SHA1' } = '' ;
5183 $selected { 'DAUTH' }{ $cgiparams { 'DAUTH' }} = 'SELECTED' ;
5185 $checked { 'TLSAUTH' }{ 'off' } = '' ;
5186 $checked { 'TLSAUTH' }{ 'on' } = '' ;
5187 $checked { 'TLSAUTH' }{ $cgiparams { 'TLSAUTH' }} = 'CHECKED' ;
5189 $checked { 'DCOMPLZO' }{ 'off' } = '' ;
5190 $checked { 'DCOMPLZO' }{ 'on' } = '' ;
5191 $checked { 'DCOMPLZO' }{ $cgiparams { 'DCOMPLZO' }} = 'CHECKED' ;
5194 $checked { 'MSSFIX' }{ 'off' } = '' ;
5195 $checked { 'MSSFIX' }{ 'on' } = '' ;
5196 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
5198 & Header
:: showhttpheaders
();
5199 & Header
:: openpage
( $Lang :: tr
{ 'status ovpn' }, 1 , '' );
5200 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
5202 if ( $errormessage ) {
5203 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
5204 print "<class name='base'> $errormessage \n " ;
5205 print " </class> \n " ;
5206 & Header
:: closebox
();
5210 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'crypto error' });
5211 print "<class name='base'> $cryptoerror " ;
5212 print " </class>" ;
5213 & Header
:: closebox
();
5216 if ( $cryptowarning ) {
5217 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'crypto warning' });
5218 print "<class name='base'> $cryptowarning " ;
5219 print " </class>" ;
5220 & Header
:: closebox
();
5224 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'warning messages' });
5225 print " $warnmessage <br>" ;
5226 print " $Lang ::tr{'fwdfw warn1'}<br>" ;
5227 & Header
:: closebox
();
5228 print "<center><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'ok'}' style='width: 5em;'></form>" ;
5229 & Header
:: closepage
();
5233 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>" ;
5234 my $srunning = "no" ;
5235 my $activeonrun = "" ;
5236 if ( - e
"/var/run/openvpn.pid" ){
5237 $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>" ;
5241 $activeonrun = "disabled='disabled'" ;
5243 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'global settings' });
5245 <table width='100%' border='0'>
5246 <form method='post'>
5247 <td width='25%'> </td>
5248 <td width='25%'> </td>
5249 <td width='25%'> </td></tr>
5250 <tr><td class='boldbase'> $Lang ::tr{'ovpn server status'}</td>
5251 <td align='left'> $sactive </td>
5252 <tr><td class='boldbase'> $Lang ::tr{'ovpn on red'}</td>
5253 <td><input type='checkbox' name='ENABLED' $checked {'ENABLED'}{'on'} /></td>
5256 if (& haveBlueNet
()) {
5257 print "<tr><td class='boldbase'> $Lang ::tr{'ovpn on blue'}</td>" ;
5258 print "<td><input type='checkbox' name='ENABLED_BLUE' $checked {'ENABLED_BLUE'}{'on'} /></td>" ;
5260 if (& haveOrangeNet
()) {
5261 print "<tr><td class='boldbase'> $Lang ::tr{'ovpn on orange'}</td>" ;
5262 print "<td><input type='checkbox' name='ENABLED_ORANGE' $checked {'ENABLED_ORANGE'}{'on'} /></td>" ;
5267 <tr><td colspan='4'><br></td></tr>
5269 <td class='base'><b> $Lang ::tr{'net config'}:</b></td>
5271 <tr><td colspan='1'><br></td></tr>
5273 <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>
5274 <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>
5275 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td>
5276 <td><select name='DPROTOCOL'><option value='udp' $selected {'DPROTOCOL'}{'udp'}>UDP</option>
5277 <option value='tcp' $selected {'DPROTOCOL'}{'tcp'}>TCP</option></select></td>
5278 <td class='boldbase'> $Lang ::tr{'destination port'}:</td>
5279 <td><input type='TEXT' name='DDEST_PORT' value=' $cgiparams {'DDEST_PORT'}' size='5' /></td></tr>
5280 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'} </td>
5281 <td> <input type='TEXT' name='DMTU' VALUE=' $cgiparams {'DMTU'}' size='5' /></td>
5284 <tr><td colspan='4'><br></td></tr>
5286 <td class='base'><b> $Lang ::tr{'ovpn crypt options'}:</b></td>
5288 <tr><td colspan='1'><br></td></tr>
5291 <td class='base'> $Lang ::tr{'ovpn ha'}</td>
5292 <td><select name='DAUTH'>
5293 <option value='whirlpool' $selected {'DAUTH'}{'whirlpool'}>Whirlpool (512 $Lang ::tr{'bit'})</option>
5294 <option value='SHA512' $selected {'DAUTH'}{'SHA512'}>SHA2 (512 $Lang ::tr{'bit'})</option>
5295 <option value='SHA384' $selected {'DAUTH'}{'SHA384'}>SHA2 (384 $Lang ::tr{'bit'})</option>
5296 <option value='SHA256' $selected {'DAUTH'}{'SHA256'}>SHA2 (256 $Lang ::tr{'bit'})</option>
5297 <option value='SHA1' $selected {'DAUTH'}{'SHA1'}>SHA1 (160 $Lang ::tr{'bit'}, $Lang ::tr{'vpn weak'})</option>
5301 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'cipher'}</td>
5302 <td><select name='DCIPHER'>
5303 <option value='AES-256-GCM' $selected {'DCIPHER'}{'AES-256-GCM'}>AES-GCM (256 $Lang ::tr{'bit'})</option>
5304 <option value='AES-192-GCM' $selected {'DCIPHER'}{'AES-192-GCM'}>AES-GCM (192 $Lang ::tr{'bit'})</option>
5305 <option value='AES-128-GCM' $selected {'DCIPHER'}{'AES-128-GCM'}>AES-GCM (128 $Lang ::tr{'bit'})</option>
5306 <option value='CAMELLIA-256-CBC' $selected {'DCIPHER'}{'CAMELLIA-256-CBC'}>CAMELLIA-CBC (256 $Lang ::tr{'bit'})</option>
5307 <option value='CAMELLIA-192-CBC' $selected {'DCIPHER'}{'CAMELLIA-192-CBC'}>CAMELLIA-CBC (192 $Lang ::tr{'bit'})</option>
5308 <option value='CAMELLIA-128-CBC' $selected {'DCIPHER'}{'CAMELLIA-128-CBC'}>CAMELLIA-CBC (128 $Lang ::tr{'bit'})</option>
5309 <option value='AES-256-CBC' $selected {'DCIPHER'}{'AES-256-CBC'}>AES-CBC (256 $Lang ::tr{'bit'})</option>
5310 <option value='AES-192-CBC' $selected {'DCIPHER'}{'AES-192-CBC'}>AES-CBC (192 $Lang ::tr{'bit'})</option>
5311 <option value='AES-128-CBC' $selected {'DCIPHER'}{'AES-128-CBC'}>AES-CBC (128 $Lang ::tr{'bit'})</option>
5312 <option value='SEED-CBC' $selected {'DCIPHER'}{'SEED-CBC'}>SEED-CBC (128 $Lang ::tr{'bit'})</option>
5313 <option value='DES-EDE3-CBC' $selected {'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC (192 $Lang ::tr{'bit'}, $Lang ::tr{'vpn weak'})</option>
5314 <option value='DESX-CBC' $selected {'DCIPHER'}{'DESX-CBC'}>DESX-CBC (192 $Lang ::tr{'bit'}, $Lang ::tr{'vpn weak'})</option>
5315 <option value='DES-EDE-CBC' $selected {'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC (128 $Lang ::tr{'bit'}, $Lang ::tr{'vpn weak'})</option>
5316 <option value='BF-CBC' $selected {'DCIPHER'}{'BF-CBC'}>BF-CBC (128 $Lang ::tr{'bit'}, $Lang ::tr{'vpn weak'})</option>
5317 <option value='CAST5-CBC' $selected {'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC (128 $Lang ::tr{'bit'}, $Lang ::tr{'vpn weak'})</option>
5322 <tr><td colspan='4'><br></td></tr>
5324 <td class='base'> $Lang ::tr{'ovpn tls auth'}</td>
5325 <td><input type='checkbox' name='TLSAUTH' $checked {'TLSAUTH'}{'on'} /></td>
5328 <tr><td colspan='4'><br><br></td></tr>
5332 if ( $srunning eq "yes" ) {
5333 print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' disabled='disabled' />" ;
5334 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'ccd net'}' />" ;
5335 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced server'}' />" ;
5336 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'stop ovpn server'}' /></td></tr>" ;
5338 print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
5339 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'ccd net'}' />" ;
5340 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced server'}' />" ;
5341 if (( - e
"${General::swroot}/ovpn/ca/cacert.pem" &&
5342 - e
" $dhparameter " &&
5343 - e
"${General::swroot}/ovpn/certs/servercert.pem" &&
5344 - e
"${General::swroot}/ovpn/certs/serverkey.pem" ) &&
5345 (( $cgiparams { 'ENABLED' } eq 'on' ) ||
5346 ( $cgiparams { 'ENABLED_BLUE' } eq 'on' ) ||
5347 ( $cgiparams { 'ENABLED_ORANGE' } eq 'on' ))){
5348 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'start ovpn server'}' /></td></tr>" ;
5350 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'start ovpn server'}' disabled='disabled' /></td></tr>" ;
5353 print "</form></table>" ;
5354 & Header
:: closebox
();
5356 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
5359 #<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>
5362 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'connection status and controlc' });
5368 foreach my $key ( sort { ncmp
( $confighash { $a }[ 32 ], $confighash { $b }[ 32 ]) } sort { ncmp
( $confighash { $a }[ 1 ], $confighash { $b }[ 1 ]) } keys %confighash ) {
5369 if ( $confighash { $key }[ 32 ] eq "" && $confighash { $key }[ 3 ] eq 'net' ){ $confighash { $key }[ 32 ]= $Lang :: tr
{ 'fwhost OpenVPN N-2-N' };}
5370 if ( $confighash { $key }[ 32 ] eq "dynamic" ){ $confighash { $key }[ 32 ]= $Lang :: tr
{ 'ccd dynrange' };}
5372 print "<b> $confighash { $key }[32]</b>" ;
5374 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
5376 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
5377 <th width='15%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></th>
5378 <th width='20%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></th>
5379 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></th>
5380 <th width='5%' class='boldbase' colspan='8' align='center'><b> $Lang ::tr{'action'}</b></th>
5384 if ( $id > 0 && $lastnet ne $confighash { $key }[ 32 ]){
5385 print "</table><br>" ;
5386 print "<b> $confighash { $key }[32]</b>" ;
5388 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
5390 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
5391 <th width='15%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></th>
5392 <th width='20%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></th>
5393 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></th>
5394 <th width='5%' class='boldbase' colspan='8' align='center'><b> $Lang ::tr{'action'}</b></th>
5398 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
5400 # Create some simple booleans to check the status
5404 # Fetch information about the certificate for non-N2N connections only
5405 if ( $confighash { $key }[ 3 ] ne 'net' ) {
5406 my @cavalid = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" ,
5407 "-in" , "${General::swroot}/ovpn/certs/ $confighash { $key }[1]cert.pem" );
5411 # Parse the certificate information
5412 foreach my $line ( @cavalid ) {
5413 if ( $line =~ /Not After : (.*)[\n]/ ) {
5414 $expiryDate = & Date
:: Parse
:: str2time
( $1 );
5419 # Calculate the remaining time
5420 my $remainingTime = $expiryDate - time ();
5422 # Determine whether the certificate has already expired, or will so soon
5423 $hasExpired = ( $remainingTime <= 0 );
5424 $expiresSoon = ( $remainingTime <= 30 * 24 * 3600 );
5427 # Populate booleans with dummy values for N2N connections (#13066)
5434 if ( $hasExpired || $expiresSoon ) {
5435 $col = "bgcolor=' $color {'color14'}'" ;
5437 $col = "bgcolor=' $color {'color20'}'" ;
5439 $col = "bgcolor=' $color {'color22'}'" ;
5441 print "<td align='center' nowrap='nowrap' $col > $confighash { $key }[1]" ;
5443 print " ( $Lang ::tr{'openvpn cert has expired'})" ;
5444 } elsif ( $expiresSoon ) {
5445 print " ( $Lang ::tr{'openvpn cert expires soon'})" ;
5448 print "<td align='center' nowrap='nowrap' $col >" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ")</td>" ;
5449 print "<td align='center' $col > $confighash { $key }[25]</td>" ;
5450 $col1 = "bgcolor='${Header::colourred}'" ;
5451 my $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
5453 if ( $confighash { $key }[ 0 ] eq 'off' ) {
5454 $col1 = "bgcolor='${Header::colourblue}'" ;
5455 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
5462 if ( $confighash { $key }[ 3 ] eq 'net' ) {
5464 if (- e
"/var/run/ $confighash { $key }[1]n2n.pid" ) {
5467 my $tport = $confighash { $key }[ 22 ];
5468 my $tnet = new Net
:: Telnet
( Timeout
=> 5 , Errmode
=> 'return' , Port
=> $tport );
5470 $tnet -> open ( '127.0.0.1' );
5471 @output = $tnet -> cmd ( String
=> 'state' , Prompt
=> '/(END.* \n |ERROR:.* \n )/' );
5472 @tustate = split ( /\,/ , $output [ 1 ]);
5474 #CONNECTING -- OpenVPN's initial state.
5475 #WAIT -- (Client only) Waiting for initial response from server.
5476 #AUTH -- (Client only) Authenticating with server.
5477 #GET_CONFIG -- (Client only) Downloading configuration options from server.
5478 #ASSIGN_IP -- Assigning IP address to virtual network interface.
5479 #ADD_ROUTES -- Adding routes to system.
5480 #CONNECTED -- Initialization Sequence Completed.
5481 #RECONNECTING -- A restart has occurred.
5482 #EXITING -- A graceful exit is in progress.
5485 if (( $tustate [ 1 ] eq 'CONNECTED' ) || ( $tustate [ 1 ] eq 'WAIT' )) {
5486 $col1 = "bgcolor='${Header::colourgreen}'" ;
5487 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b>" ;
5489 $col1 = "bgcolor='${Header::colourred}'" ;
5490 $active = "<b><font color='#FFFFFF'> $tustate [1]</font></b>" ;
5498 foreach my $line ( @status ) {
5500 if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ ) {
5501 @match = split ( m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ , $line );
5502 if ( $match [ 1 ] ne "Common Name" ) {
5505 if ( $cn eq " $confighash { $key }[2]" ) {
5506 $col1 = "bgcolor='${Header::colourgreen}'" ;
5507 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b>" ;
5516 <td align='center' $col1 > $active </td>
5518 <form method='post' name='frm${key}a'><td align='center' $col >
5519 <input type='image' name=' $Lang ::tr{'dl client arch'}' src='/images/openvpn.png' alt=' $Lang ::tr{'dl client arch'}' title=' $Lang ::tr{'dl client arch'}' border='0' />
5520 <input type='hidden' name='ACTION' value=' $Lang ::tr{'dl client arch'}' />
5521 <input type='hidden' name='KEY' value=' $key ' />
5526 if ( $confighash { $key }[ 41 ] eq "no-pass" ) {
5528 <form method='post' name='frm${key}g'><td align='center' $col >
5529 <input type='image' name=' $Lang ::tr{'dl client arch insecure'}' src='/images/openvpn.png'
5530 alt=' $Lang ::tr{'dl client arch insecure'}' title=' $Lang ::tr{'dl client arch insecure'}' border='0' />
5531 <input type='hidden' name='ACTION' value=' $Lang ::tr{'dl client arch'}' />
5532 <input type='hidden' name='MODE' value='insecure' />
5533 <input type='hidden' name='KEY' value=' $key ' />
5537 print "<td $col > </td>" ;
5540 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
5542 <form method='post' name='frm${key}b'><td align='center' $col >
5543 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' border='0' />
5544 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
5545 <input type='hidden' name='KEY' value=' $key ' />
5549 print "<td> </td>" ;
5552 if ( $confighash { $key }[ 43 ] eq 'on' ) {
5554 <form method='post' name='frm${key}o'><td align='center' $col >
5555 <input type='image' name=' $Lang ::tr{'show otp qrcode'}' src='/images/qr-code.png' alt=' $Lang ::tr{'show otp qrcode'}' title=' $Lang ::tr{'show otp qrcode'}' border='0' />
5556 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show otp qrcode'}' />
5557 <input type='hidden' name='KEY' value=' $key ' />
5561 print "<td $col > </td>" ;
5564 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $key }[1].p12" ) {
5566 <form method='post' name='frm${key}c'><td align='center' $col >
5567 <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' />
5568 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
5569 <input type='hidden' name='KEY' value=' $key ' />
5572 ; } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
5574 <form method='post' name='frm${key}c'><td align='center' $col >
5575 <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' />
5576 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
5577 <input type='hidden' name='KEY' value=' $key ' />
5581 print "<td> </td>" ;
5584 <form method='post' name='frm${key}d'><td align='center' $col >
5585 <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' />
5586 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
5587 <input type='hidden' name='KEY' value=' $key ' />
5590 <form method='post' name='frm${key}e'><td align='center' $col >
5591 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
5592 <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'/>
5593 <input type='hidden' name='KEY' value=' $key ' />
5595 <form method='post' name='frm${key}f'><td align='center' $col >
5596 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
5597 <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' />
5598 <input type='hidden' name='KEY' value=' $key ' />
5604 $lastnet = $confighash { $key }[ 32 ];
5609 # If the config file contains entries, print Key to action icons
5614 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
5615 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
5616 <td class='base'> $Lang ::tr{'click to disable'}</td>
5617 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
5618 <td class='base'> $Lang ::tr{'show certificate'}</td>
5619 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
5620 <td class='base'> $Lang ::tr{'edit'}</td>
5621 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
5622 <td class='base'> $Lang ::tr{'remove'}</td>
5626 <td> <img src='/images/off.gif' alt='?OFF' /></td>
5627 <td class='base'> $Lang ::tr{'click to enable'}</td>
5628 <td> <img src='/images/media-floppy.png' alt='?FLOPPY' /></td>
5629 <td class='base'> $Lang ::tr{'download certificate'}</td>
5630 <td> <img src='/images/openvpn.png' alt='?RELOAD'/></td>
5631 <td class='base'> $Lang ::tr{'dl client arch'}</td>
5632 <td> <img src='/images/qr-code.png' alt=' $Lang ::tr{'show otp qrcode'}'/></td>
5633 <td class='base'> $Lang ::tr{'show otp qrcode'}</td>
5641 <table width='100%'>
5642 <form method='post'>
5643 <tr><td align='right'>
5644 <input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />
5645 <input type='submit' name='ACTION' value=' $Lang ::tr{'ovpn con stat'}' $activeonrun /></td>
5651 & Header
:: closebox
();
5655 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'certificate authorities'}" );
5657 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
5659 <th width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
5660 <th width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></th>
5661 <th width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></th>
5665 my $col1 = "bgcolor=' $color {'color22'}'" ;
5666 my $col2 = "bgcolor=' $color {'color20'}'" ;
5668 my $col3 = "bgcolor=' $color {'color22'}'" ;
5670 my $col4 = "bgcolor=' $color {'color20'}'" ;
5672 if (- f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
5673 my @casubject = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "${General::swroot}/ovpn/ca/cacert.pem" );
5676 foreach my $line ( @casubject ) {
5677 if ( $line =~ /Subject: (.*)[\n]/ ) {
5679 $casubject =~ s
+/ Email
+, E
+;
5680 $casubject =~ s/ ST=/ S=/ ;
5688 <td class='base' $col1 > $Lang ::tr{'root certificate'}</td>
5689 <td class='base' $col1 > $casubject </td>
5690 <form method='post' name='frmrootcrta'><td width='3%' align='center' $col1 >
5691 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
5692 <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' />
5694 <form method='post' name='frmrootcrtb'><td width='3%' align='center' $col1 >
5695 <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' />
5696 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
5698 <td width='4%' $col1 > </td>
5703 # display rootcert generation buttons
5706 <td class='base' $col1 > $Lang ::tr{'root certificate'}:</td>
5707 <td class='base' $col1 > $Lang ::tr{'not present'}</td>
5708 <td colspan='3' $col1 > </td>
5714 if (- f
"${General::swroot}/ovpn/certs/servercert.pem" ) {
5715 my @hostsubject = & General
:: system_output
( "/usr/bin/openssl" , "x509" , "-text" , "-in" , "${General::swroot}/ovpn/certs/servercert.pem" );
5718 foreach my $line ( @hostsubject ) {
5719 if ( $line =~ /Subject: (.*)[\n]/ ) {
5721 $hostsubject =~ s
+/ Email
+, E
+;
5722 $hostsubject =~ s/ ST=/ S=/ ;
5730 <td class='base' $col2 > $Lang ::tr{'host certificate'}</td>
5731 <td class='base' $col2 > $hostsubject </td>
5732 <form method='post' name='frmhostcrta'><td width='3%' align='center' $col2 >
5733 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
5734 <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' />
5736 <form method='post' name='frmhostcrtb'><td width='3%' align='center' $col2 >
5737 <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' />
5738 <input type='hidden' name='ACTION' value=" $Lang ::tr{'download host certificate'}" />
5740 <td width='4%' $col2 > </td>
5748 <td width='25%' class='base' $col2 > $Lang ::tr{'host certificate'}:</td>
5749 <td class='base' $col2 > $Lang ::tr{'not present'}</td>
5750 </td><td colspan='3' $col2 > </td>
5756 # Adding DH parameter to chart
5757 if (- f
" $dhparameter " ) {
5758 my @dhsubject = & General
:: system_output
( "/usr/bin/openssl" , "dhparam" , "-text" , "-in" , " $dhparameter " );
5761 foreach my $line ( @dhsubject ) {
5762 if ( $line =~ / (.*)[\n]/ ) {
5771 <td class='base' $col3 > $Lang ::tr{'dh'}</td>
5772 <td class='base' $col3 > $dhsubject </td>
5773 <form method='post' name='frmdhparam'><td width='3%' align='center' $col3 >
5774 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show dh'}' />
5775 <input type='image' name=' $Lang ::tr{'show dh'}' src='/images/info.gif' alt=' $Lang ::tr{'show dh'}' title=' $Lang ::tr{'show dh'}' width='20' height='20' border='0' />
5777 <form method='post' name='frmdhparam'><td width='3%' align='center' $col3 >
5779 <td width='4%' $col3 > </td>
5787 <td width='25%' class='base' $col3 > $Lang ::tr{'dh'}:</td>
5788 <td class='base' $col3 > $Lang ::tr{'not present'}</td>
5789 </td><td colspan='3' $col3 > </td>
5795 # Adding ta.key to chart
5796 if (- f
"${General::swroot}/ovpn/certs/ta.key" ) {
5797 open ( FILE
, "${General::swroot}/ovpn/certs/ta.key" );
5798 my @tasubject = < FILE
>;
5802 foreach my $line ( @tasubject ) {
5803 if ( $line =~ /# (.*)[\n]/ ) {
5813 <td class='base' $col4 > $Lang ::tr{'ta key'}</td>
5814 <td class='base' $col4 > $tasubject </td>
5815 <form method='post' name='frmtakey'><td width='3%' align='center' $col4 >
5816 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show tls-auth key'}' />
5817 <input type='image' name=' $Lang ::tr{'edit'}' src='/images/info.gif' alt=' $Lang ::tr{'show tls-auth key'}' title=' $Lang ::tr{'show tls-auth key'}' width='20' height='20' border='0' />
5819 <form method='post' name='frmtakey'><td width='3%' align='center' $col4 >
5820 <input type='image' name=' $Lang ::tr{'download tls-auth key'}' src='/images/media-floppy.png' alt=' $Lang ::tr{'download tls-auth key'}' title=' $Lang ::tr{'download tls-auth key'}' border='0' />
5821 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download tls-auth key'}' />
5823 <td width='4%' $col4 > </td>
5831 <td width='25%' class='base' $col4 > $Lang ::tr{'ta key'}:</td>
5832 <td class='base' $col4 > $Lang ::tr{'not present'}</td>
5833 <td colspan='3' $col4 > </td>
5839 if (! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
5840 print "<tr><td colspan='5' align='center'><form method='post'>" ;
5841 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' />" ;
5842 print "</form></td></tr> \n " ;
5845 if ( keys %cahash > 0 ) {
5846 foreach my $key ( keys %cahash ) {
5847 if (( $key + 1 ) % 2 ) {
5848 print "<tr bgcolor=' $color {'color20'}'> \n " ;
5850 print "<tr bgcolor=' $color {'color22'}'> \n " ;
5852 print "<td class='base'> $cahash { $key }[0]</td> \n " ;
5853 print "<td class='base'> $cahash { $key }[1]</td> \n " ;
5855 <form method='post' name='cafrm${key}a'><td align='center'>
5856 <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' />
5857 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
5858 <input type='hidden' name='KEY' value=' $key ' />
5860 <form method='post' name='cafrm${key}b'><td align='center'>
5861 <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' />
5862 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
5863 <input type='hidden' name='KEY' value=' $key ' />
5865 <form method='post' name='cafrm${key}c'><td align='center'>
5866 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
5867 <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' />
5868 <input type='hidden' name='KEY' value=' $key ' />
5877 # If the file contains entries, print Key to action icons
5878 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
5882 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
5883 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
5884 <td class='base'> $Lang ::tr{'show certificate'}</td>
5885 <td> <img src='/images/media-floppy.png' alt=' $Lang ::tr{'download certificate'}' /></td>
5886 <td class='base'> $Lang ::tr{'download certificate'}</td>
5897 <form method='post' enctype='multipart/form-data'>
5898 <table border='0' width='100%'>
5900 <td colspan='4'><b> $Lang ::tr{'upload ca certificate'}</b></td>
5904 <td width='10%'> $Lang ::tr{'ca name'}:</td>
5905 <td width='30%'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' align='left'></td>
5906 <td width='30%'><input type='file' name='FH' size='25'>
5907 <td width='30%'align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'upload ca certificate'}'></td>
5911 <td colspan='3'> </td>
5912 <td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'show crl'}' /></td>
5921 if ( $srunning eq "yes" ) {
5922 print "<div align='center'><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' disabled='disabled' /></div></form> \n " ;
5924 print "<div align='center'><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' /></div></form> \n " ;
5926 & Header
:: closebox
();
5930 & Header
:: closepage
();