]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/ovpnmain.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2014 IPFire Team <info@ipfire.org> #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
22 # Based on IPFireCore 77
25 use CGI qw
/:standard/ ;
30 use File
:: Temp qw
/ tempfile tempdir / ;
32 use Archive
:: Zip
qw(:ERROR_CODES :CONSTANTS) ;
34 require '/var/ipfire/general-functions.pl' ;
35 require "${General::swroot}/lang.pl" ;
36 require "${General::swroot}/header.pl" ;
37 require "${General::swroot}/countries.pl" ;
39 # enable only the following on debugging purpose
41 #use CGI::Carp 'fatalsToBrowser';
42 #workaround to suppress a warning when a variable is used only once
43 my @dummy = ( ${ Header
:: colourgreen
}, ${ Header
:: colourblue
} );
47 my %mainsettings = ();
48 & General
:: readhash
( "${General::swroot}/main/settings" , \
%mainsettings );
49 & General
:: readhash
( "/srv/web/ipfire/html/themes/" . $mainsettings { 'THEME' }. "/include/colors.txt" , \
%color );
52 ### Initialize variables
65 my $errormessage = '' ;
67 my $routes_push_file = '' ;
68 my $confighost = "${General::swroot}/fwhosts/customhosts" ;
69 my $configgrp = "${General::swroot}/fwhosts/customgroups" ;
70 my $customnet = "${General::swroot}/fwhosts/customnetworks" ;
73 my $local_serverconf = "${General::swroot}/ovpn/scripts/server.conf.local" ;
74 my $local_clientconf = "${General::swroot}/ovpn/scripts/client.conf.local" ;
76 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%netsettings );
77 $cgiparams { 'ENABLED' } = 'off' ;
78 $cgiparams { 'ENABLED_BLUE' } = 'off' ;
79 $cgiparams { 'ENABLED_ORANGE' } = 'off' ;
80 $cgiparams { 'EDIT_ADVANCED' } = 'off' ;
81 $cgiparams { 'NAT' } = 'off' ;
82 $cgiparams { 'COMPRESSION' } = 'off' ;
83 $cgiparams { 'ONLY_PROPOSED' } = 'off' ;
84 $cgiparams { 'ACTION' } = '' ;
85 $cgiparams { 'CA_NAME' } = '' ;
86 $cgiparams { 'DH_NAME' } = 'dh1024.pem' ;
87 $cgiparams { 'DHLENGHT' } = '' ;
88 $cgiparams { 'DHCP_DOMAIN' } = '' ;
89 $cgiparams { 'DHCP_DNS' } = '' ;
90 $cgiparams { 'DHCP_WINS' } = '' ;
91 $cgiparams { 'ROUTES_PUSH' } = '' ;
92 $cgiparams { 'DCOMPLZO' } = 'off' ;
93 $cgiparams { 'MSSFIX' } = '' ;
94 $cgiparams { 'number' } = '' ;
95 $cgiparams { 'PMTU_DISCOVERY' } = '' ;
96 $cgiparams { 'DCIPHER' } = '' ;
97 $cgiparams { 'DAUTH' } = '' ;
98 $cgiparams { 'TLSAUTH' } = '' ;
99 $routes_push_file = "${General::swroot}/ovpn/routes_push" ;
101 # Add CCD files if not already presant
102 unless (- e
$routes_push_file ) {
103 open ( RPF
, "> $routes_push_file " );
106 unless (- e
"${General::swroot}/ovpn/ccd.conf" ) {
107 open ( CCDC
, ">${General::swroot}/ovpn/ccd.conf" );
110 unless (- e
"${General::swroot}/ovpn/ccdroute" ) {
111 open ( CCDR
, ">${General::swroot}/ovpn/ccdroute" );
114 unless (- e
"${General::swroot}/ovpn/ccdroute2" ) {
115 open ( CCDRT
, ">${General::swroot}/ovpn/ccdroute2" );
118 # Add additional configs if not already presant
119 unless (- e
" $local_serverconf " ) {
120 open ( LSC
, "> $local_serverconf " );
123 unless (- e
" $local_clientconf " ) {
124 open ( LCC
, "> $local_clientconf " );
128 & Header
:: getcgihash
( \
%cgiparams , { 'wantfile' => 1 , 'filevar' => 'FH' });
130 # prepare openvpn config file
136 if ( $netsettings { 'CONFIG_TYPE' } == 2 ) { return 1 ;}
137 if ( $netsettings { 'CONFIG_TYPE' } == 4 ) { return 1 ;}
143 if ( $netsettings { 'CONFIG_TYPE' } == 3 ) { return 1 ;}
144 if ( $netsettings { 'CONFIG_TYPE' } == 4 ) { return 1 ;}
149 my $bytesize = shift ;
152 while ( abs ( $bytesize ) >= 1024 ){
153 $bytesize = $bytesize / 1024 ;
158 my @units = ( "Bytes" , "KB" , "MB" , "GB" , "TB" , "PB" , "EB" );
159 my $newsize =( int ( $bytesize * 100 + 0.5 ))/ 100 ;
160 return ( " $newsize $units [ $i ]" );
165 if ( open ( FILE
, ">${General::swroot}/ovpn/certs/serial" )) {
169 if ( open ( FILE
, ">${General::swroot}/ovpn/certs/index.txt" )) {
173 unlink ( "${General::swroot}/ovpn/certs/index.txt.old" );
174 unlink ( "${General::swroot}/ovpn/certs/serial.old" );
175 unlink ( "${General::swroot}/ovpn/certs/01.pem" );
178 sub newcleanssldatabase
180 if (! - s
"${General::swroot}/ovpn/certs/serial" ) {
181 open ( FILE
, ">${General::swroot}(ovpn/certs/serial" );
185 if (! - s
">${General::swroot}/ovpn/certs/index.txt" ) {
186 system ( "touch ${General::swroot}/ovpn/certs/index.txt" );
188 unlink ( "${General::swroot}/ovpn/certs/index.txt.old" );
189 unlink ( "${General::swroot}/ovpn/certs/serial.old" );
194 if ( open ( FILE
, "${General::swroot}/ovpn/certs/serial.old" )) {
195 my $hexvalue = < FILE
>;
198 unlink ( "${General::swroot}/ovpn/certs/ $hexvalue .pem" );
202 sub writeserverconf
{
203 my %sovpnsettings = ();
205 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%sovpnsettings );
208 open ( CONF
, ">${General::swroot}/ovpn/server.conf" ) or die "Unable to open ${General::swroot}/ovpn/server.conf: $!" ;
210 print CONF
"#OpenVPN Server conf \n " ;
212 print CONF
"daemon openvpnserver \n " ;
213 print CONF
"writepid /var/run/openvpn.pid \n " ;
214 print CONF
"#DAN prepare OpenVPN for listening on blue and orange \n " ;
215 print CONF
";local $sovpnsettings {'VPN_IP'} \n " ;
216 print CONF
"dev tun \n " ;
217 print CONF
"proto $sovpnsettings {'DPROTOCOL'} \n " ;
218 print CONF
"port $sovpnsettings {'DDEST_PORT'} \n " ;
219 print CONF
"script-security 3 system \n " ;
220 print CONF
"ifconfig-pool-persist /var/ipfire/ovpn/ovpn-leases.db 3600 \n " ;
221 print CONF
"client-config-dir /var/ipfire/ovpn/ccd \n " ;
222 print CONF
"tls-server \n " ;
223 print CONF
"ca ${General::swroot}/ovpn/ca/cacert.pem \n " ;
224 print CONF
"cert ${General::swroot}/ovpn/certs/servercert.pem \n " ;
225 print CONF
"key ${General::swroot}/ovpn/certs/serverkey.pem \n " ;
226 print CONF
"dh ${General::swroot}/ovpn/ca/ $cgiparams {'DH_NAME'} \n " ;
227 my @tempovpnsubnet = split ( "\/" , $sovpnsettings { 'DOVPN_SUBNET' });
228 print CONF
"server $tempovpnsubnet [0] $tempovpnsubnet [1] \n " ;
229 #print CONF "push \"route $netsettings{'GREEN_NETADDRESS'} $netsettings{'GREEN_NETMASK'}\"\n";
231 # Check if we are using mssfix, fragment or mtu-disc and set the corretct mtu of 1500.
232 # If we doesn't use one of them, we can use the configured mtu value.
233 if ( $sovpnsettings { 'MSSFIX' } eq 'on' )
234 { print CONF
"tun-mtu 1500 \n " ; }
235 elsif ( $sovpnsettings { 'FRAGMENT' } ne '' && $sovpnsettings { 'DPROTOCOL' } ne 'tcp' )
236 { print CONF
"tun-mtu 1500 \n " ; }
237 elsif (( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'yes' ) ||
238 ( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
239 ( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'no' ))
240 { print CONF
"tun-mtu 1500 \n " ; }
242 { print CONF
"tun-mtu $sovpnsettings {'DMTU'} \n " ; }
244 if ( $vpnsettings { 'ROUTES_PUSH' } ne '' ) {
245 @temp = split ( /\n/ , $vpnsettings { 'ROUTES_PUSH' });
248 @tempovpnsubnet = split ( "\/" ,& General
:: ipcidr2msk
( $_ ));
249 print CONF
"push \" route " . $tempovpnsubnet [ 0 ]. " " . $tempovpnsubnet [ 1 ] . " \"\n " ;
254 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
255 foreach my $key ( keys %ccdconfhash ) {
256 my $a = $ccdconfhash { $key }[ 1 ];
257 my ( $b , $c ) = split ( /\/ /, $a );
258 print CONF
"route $b " .& General
:: cidrtosub
( $c ). " \n " ;
261 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
262 foreach my $key ( keys %ccdroutehash ) {
263 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}){
264 my ( $a , $b )= split ( /\/ /, $ccdroutehash { $key }[ $i ]);
265 print CONF
"route $a $b \n " ;
270 if ( $sovpnsettings { CLIENT2CLIENT
} eq 'on' ) {
271 print CONF
"client-to-client \n " ;
273 if ( $sovpnsettings { MSSFIX
} eq 'on' ) {
274 print CONF
"mssfix \n " ;
276 if ( $sovpnsettings { FRAGMENT
} ne '' && $sovpnsettings { 'DPROTOCOL' } ne 'tcp' ) {
277 print CONF
"fragment $sovpnsettings {'FRAGMENT'} \n " ;
280 # Check if a valid operating mode has been choosen and use it.
281 if (( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'yes' ) ||
282 ( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
283 ( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'no' )) {
284 print CONF
"mtu-disc $sovpnsettings {'PMTU_DISCOVERY'} \n " ;
287 if ( $sovpnsettings { KEEPALIVE_1
} > 0 && $sovpnsettings { KEEPALIVE_2
} > 0 ) {
288 print CONF
"keepalive $sovpnsettings {'KEEPALIVE_1'} $sovpnsettings {'KEEPALIVE_2'} \n " ;
290 print CONF
"status-version 1 \n " ;
291 print CONF
"status /var/run/ovpnserver.log 30 \n " ;
292 print CONF
"cipher $sovpnsettings {DCIPHER} \n " ;
293 if ( $sovpnsettings { 'DAUTH' } eq '' ) {
296 print CONF
"auth $sovpnsettings {'DAUTH'} \n " ;
298 if ( $sovpnsettings { 'TLSAUTH' } eq 'on' ) {
299 print CONF
"tls-auth ${General::swroot}/ovpn/certs/ta.key \n " ;
301 if ( $sovpnsettings { DCOMPLZO
} eq 'on' ) {
302 print CONF
"comp-lzo \n " ;
304 if ( $sovpnsettings { REDIRECT_GW_DEF1
} eq 'on' ) {
305 print CONF
"push \" redirect-gateway def1 \"\n " ;
307 if ( $sovpnsettings { DHCP_DOMAIN
} ne '' ) {
308 print CONF
"push \" dhcp-option DOMAIN $sovpnsettings {DHCP_DOMAIN} \"\n " ;
311 if ( $sovpnsettings { DHCP_DNS
} ne '' ) {
312 print CONF
"push \" dhcp-option DNS $sovpnsettings {DHCP_DNS} \"\n " ;
315 if ( $sovpnsettings { DHCP_WINS
} ne '' ) {
316 print CONF
"push \" dhcp-option WINS $sovpnsettings {DHCP_WINS} \"\n " ;
319 if ( $sovpnsettings { DHCP_WINS
} eq '' ) {
320 print CONF
"max-clients 100 \n " ;
322 if ( $sovpnsettings { DHCP_WINS
} ne '' ) {
323 print CONF
"max-clients $sovpnsettings {MAX_CLIENTS} \n " ;
325 print CONF
"tls-verify /usr/lib/openvpn/verify \n " ;
326 print CONF
"crl-verify /var/ipfire/ovpn/crls/cacrl.pem \n " ;
327 print CONF
"user nobody \n " ;
328 print CONF
"group nobody \n " ;
329 print CONF
"persist-key \n " ;
330 print CONF
"persist-tun \n " ;
331 if ( $sovpnsettings { LOG_VERB
} ne '' ) {
332 print CONF
"verb $sovpnsettings {LOG_VERB} \n " ;
334 print CONF
"verb 3 \n " ;
336 # Print server.conf.local if entries exist to server.conf
337 if ( !- z
$local_serverconf && $sovpnsettings { 'ADDITIONAL_CONFIGS' } eq 'on' ) {
338 open ( LSC
, " $local_serverconf " );
339 print CONF
" \n #--------------------------- \n " ;
340 print CONF
"# Start of custom directives \n " ;
341 print CONF
"# from server.conf.local \n " ;
342 print CONF
"#--------------------------- \n\n " ;
346 print CONF
" \n #----------------------------- \n " ;
347 print CONF
"# End of custom directives \n " ;
348 print CONF
"#----------------------------- \n " ;
357 if ( open ( FILE
, ">/var/run/ovpnserver.log" )) {
367 my %ccdconfhash = ();
369 my $ccdnetname = $_ [ 0 ];
370 if (- f
"${General::swroot}/ovpn/ovpnconfig" ){
371 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
372 foreach my $key ( keys %ccdhash ) {
373 if ( $ccdhash { $key }[ 32 ] eq $ccdnetname ) {
374 $errormessage = $Lang :: tr
{ 'ccd err hostinnet' };
379 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
380 foreach my $key ( keys %ccdconfhash ) {
381 if ( $ccdconfhash { $key }[ 0 ] eq $ccdnetname ){
382 delete $ccdconfhash { $key };
385 & General
:: writehasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
407 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err name' }. "<br>" ;
411 if (!& General
:: validhostname
( $ccdname ))
413 $errormessage = $Lang :: tr
{ 'ccd err invalidname' };
417 ( $ccdip , $subcidr ) = split ( /\/ /, $ccdnet );
418 $subcidr =& General
:: iporsubtocidr
( $subcidr );
422 $errormessage = $Lang :: tr
{ 'ccd err invalidnet' };
426 if (!& General
:: validipandmask
( $ccdnet )){
427 $errormessage = $Lang :: tr
{ 'ccd err invalidnet' };
431 $errormessage =& General
:: checksubnets
( $ccdname , $ccdnet );
434 if (! $errormessage ) {
436 $baseaddress =& General
:: getnetworkip
( $ccdip , $subcidr );
437 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
438 my $key = & General
:: findhasharraykey
( \
%ccdconfhash );
439 foreach my $i ( 0 .. 1 ) { $ccdconfhash { $key }[ $i ] = "" ;}
440 $ccdconfhash { $key }[ 0 ] = $ccdname ;
441 $ccdconfhash { $key }[ 1 ] = $baseaddress . "/" . $subcidr ;
442 & General
:: writehasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
444 $cgiparams { 'ccdname' }= '' ;
445 $cgiparams { 'ccdsubnet' }= '' ;
457 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
458 foreach my $key ( keys %ccdconfhash ) {
459 if ( $ccdconfhash { $key }[ 0 ] eq $oldname ) {
460 foreach my $key1 ( keys %ccdconfhash ) {
461 if ( $ccdconfhash { $key1 }[ 0 ] eq $newname ){
462 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err netadrexist' };
465 $ccdconfhash { $key }[ 0 ]= $newname ;
466 & General
:: writehasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
473 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
474 foreach my $key ( keys %ccdhash ) {
475 if ( $ccdhash { $key }[ 32 ] eq $oldname ) {
476 $ccdhash { $key }[ 32 ]= $newname ;
477 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
486 my $ccdnetwork = $_ [ 0 ];
489 @octets = split ( "\/" , $ccdnetwork );
490 @subnet = split /\./ , & General
:: cidrtosub
( $octets [ 1 ]);
503 my ( $ip1 , $ip2 , $ip3 , $ip4 )= split /\./ , $ipin ;
511 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
512 $iprange [ 0 ]= $ip1 . "." . $ip2 . "." . $ip3 . "." .( $ip4 + 2 );
513 for ( my $i = 1 ; $i <= $count ; $i ++) {
514 my $tmpip = $iprange [ $i - 1 ];
516 $iprange [ $i ]= & General
:: getnextip
( $tmpip , 4 );
519 foreach my $key ( keys %ccdhash ) {
521 foreach my $tmp ( @iprange ){
522 my ( $net , $sub ) = split ( /\/ /, $ccdhash { $key }[ 33 ]);
524 if ( $hasip ne $ccdhash { $key }[ 33 ] ){
525 splice ( @iprange , $r , 1 );
537 my ( $ccdip , $subcidr ) = split ( "/" , $_ [ 0 ]);
539 my @allccdips =& getccdadresses
( $ccdip , $subcidr ,& ccdmaxclients
( $ccdip . "/" . $subcidr ), $tz );
540 print "<select name=' $boxname ' STYLE='font-family : arial; font-size : 9pt; width:130px;' >" ;
541 foreach ( @allccdips ) {
544 print "<option value=' $ip ' " ;
545 if ( $ip eq $cgiparams { $boxname } ){
548 print "> $ip </option>" ;
558 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
559 foreach my $key ( keys %ccdhash ) {
560 if ( $ccdhash { $key }[ 32 ] eq $name ){ $i ++;}
565 sub check_routes_push
568 my ( $ip , $cidr ) = split ( /\/ /, $val );
569 ##check for existing routes in routes_push
570 if (- e
"${General::swroot}/ovpn/routes_push" ) {
571 open ( FILE
, "${General::swroot}/ovpn/routes_push" );
575 my ( $ip2 , $cidr2 ) = split ( /\/ /, " $_ " );
576 my $val2 = $ip2 . "/" .& General
:: iporsubtodec
( $cidr2 );
582 if (& General
:: IpInSubnet
( $ip , $ip2 ,& General
:: iporsubtodec
( $cidr2 ))){
595 my ( $ip , $cidr ) = split ( /\/ /, $val );
596 #check for existing routes in ccdroute
597 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
598 foreach my $key ( keys %ccdroutehash ) {
599 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}) {
600 if (& General
:: iporsubtodec
( $val ) eq $ccdroutehash { $key }[ $i ] && $ccdroutehash { $key }[ 0 ] ne $cgiparams { 'NAME' }){
603 my ( $ip2 , $cidr2 ) = split ( /\/ /, $ccdroutehash { $key }[ $i ]);
605 if (& General
:: IpInSubnet
( $ip , $ip2 , $cidr2 )&& $ccdroutehash { $key }[ 0 ] ne $cgiparams { 'NAME' } ){
616 my ( $ip , $cidr ) = split ( /\/ /, $val );
617 #check for existing routes in ccdroute
618 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
619 foreach my $key ( keys %ccdconfhash ) {
620 if (& General
:: iporsubtocidr
( $val ) eq $ccdconfhash { $key }[ 1 ]){
623 my ( $ip2 , $cidr2 ) = split ( /\/ /, $ccdconfhash { $key }[ 1 ]);
625 if (& General
:: IpInSubnet
( $ip , $ip2 ,& General
:: cidrtosub
( $cidr2 ))){
639 my $ipdotmask = $_ [ 0 ];
640 if (& General
:: validip
( $ipdotmask )) { return 0 ; }
641 if (!( $ipdotmask =~ /^(.*?)\/ (.* ?
)$/)) { }
643 if (( $mask =~ /\./ )) { return 0 ; }
647 # -------------------------------------------------------------------
649 sub write_routepushfile
651 open ( FILE
, "> $routes_push_file " );
653 if ( $vpnsettings { 'ROUTES_PUSH' } ne '' ) {
654 print FILE
$vpnsettings { 'ROUTES_PUSH' };
659 sub read_routepushfile
661 if (- e
" $routes_push_file " ) {
662 open ( FILE
, " $routes_push_file " );
663 delete $vpnsettings { 'ROUTES_PUSH' };
664 while (< FILE
>) { $vpnsettings { 'ROUTES_PUSH' } .= $_ };
666 $cgiparams { 'ROUTES_PUSH' } = $vpnsettings { 'ROUTES_PUSH' };
671 sub writecollectdconf
{
675 open ( COLLECTDVPN
, ">${General::swroot}/ovpn/collectd.vpn" ) or die "Unable to open collectd.vpn: $!" ;
676 print COLLECTDVPN
"Loadplugin openvpn \n " ;
677 print COLLECTDVPN
" \n " ;
678 print COLLECTDVPN
"<Plugin openvpn> \n " ;
679 print COLLECTDVPN
"Statusfile \" /var/run/ovpnserver.log \"\n " ;
681 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
682 foreach my $key ( keys %ccdhash ) {
683 if ( $ccdhash { $key }[ 0 ] eq 'on' && $ccdhash { $key }[ 3 ] eq 'net' ) {
684 print COLLECTDVPN
"Statusfile \" /var/run/openvpn/ $ccdhash { $key }[1]-n2n \"\n " ;
688 print COLLECTDVPN
"</Plugin> \n " ;
691 # Reload collectd afterwards
692 system ( "/usr/local/bin/collectdctrl restart &>/dev/null" );
695 #hier die refresh page
696 if ( - e
"${General::swroot}/ovpn/gencanow" ) {
698 $refresh = "<meta http-equiv='refresh' content='15;' />" ;
699 & Header
:: showhttpheaders
();
700 & Header
:: openpage
( $Lang :: tr
{ 'OVPN' }, 1 , $refresh );
701 & Header
:: openbigbox
( '100%' , 'center' );
702 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
703 print "<tr> \n <td align='center'><img src='/images/clock.gif' alt='' /></td> \n " ;
704 print "<td colspan='2'><font color='red'>Please be patient this realy can take some time on older hardware...</font></td></tr> \n " ;
706 & Header
:: closebigbox
();
707 & Header
:: closepage
();
710 ##hier die refresh page
714 ### OpenVPN Server Control
716 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'start ovpn server' } ||
717 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'stop ovpn server' } ||
718 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart ovpn server' }) {
719 #start openvpn server
720 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'start ovpn server' }){
722 system ( '/usr/local/bin/openvpnctrl' , '-s' );
725 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'stop ovpn server' }){
726 system ( '/usr/local/bin/openvpnctrl' , '-k' );
729 # #restart openvpn server
730 # if ($cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}){
731 #workarund, till SIGHUP also works when running as nobody
732 # system('/usr/local/bin/openvpnctrl', '-r');
738 ### Save Advanced options
741 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save-adv-options' }) {
742 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
743 #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too,
744 #DAN this value has to leave.
745 #new settings for daemon
746 $vpnsettings { 'LOG_VERB' } = $cgiparams { 'LOG_VERB' };
747 $vpnsettings { 'KEEPALIVE_1' } = $cgiparams { 'KEEPALIVE_1' };
748 $vpnsettings { 'KEEPALIVE_2' } = $cgiparams { 'KEEPALIVE_2' };
749 $vpnsettings { 'MAX_CLIENTS' } = $cgiparams { 'MAX_CLIENTS' };
750 $vpnsettings { 'REDIRECT_GW_DEF1' } = $cgiparams { 'REDIRECT_GW_DEF1' };
751 $vpnsettings { 'CLIENT2CLIENT' } = $cgiparams { 'CLIENT2CLIENT' };
752 $vpnsettings { 'ADDITIONAL_CONFIGS' } = $cgiparams { 'ADDITIONAL_CONFIGS' };
753 $vpnsettings { 'DHCP_DOMAIN' } = $cgiparams { 'DHCP_DOMAIN' };
754 $vpnsettings { 'DHCP_DNS' } = $cgiparams { 'DHCP_DNS' };
755 $vpnsettings { 'DHCP_WINS' } = $cgiparams { 'DHCP_WINS' };
756 $vpnsettings { 'ROUTES_PUSH' } = $cgiparams { 'ROUTES_PUSH' };
757 $vpnsettings { 'PMTU_DISCOVERY' } = $cgiparams { 'PMTU_DISCOVERY' };
758 $vpnsettings { 'DAUTH' } = $cgiparams { 'DAUTH' };
759 $vpnsettings { 'TLSAUTH' } = $cgiparams { 'TLSAUTH' };
762 if ( $cgiparams { 'FRAGMENT' } eq '' ) {
763 delete $vpnsettings { 'FRAGMENT' };
765 if ( $cgiparams { 'FRAGMENT' } !~ /^[0-9]+$/ ) {
766 $errormessage = "Incorrect value, please insert only numbers." ;
769 $vpnsettings { 'FRAGMENT' } = $cgiparams { 'FRAGMENT' };
773 if ( $cgiparams { 'MSSFIX' } ne 'on' ) {
774 delete $vpnsettings { 'MSSFIX' };
776 $vpnsettings { 'MSSFIX' } = $cgiparams { 'MSSFIX' };
779 if (( $cgiparams { 'PMTU_DISCOVERY' } eq 'yes' ) ||
780 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
781 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'no' )) {
783 if (( $cgiparams { 'MSSFIX' } eq 'on' ) || ( $cgiparams { 'FRAGMENT' } ne '' )) {
784 $errormessage = $Lang :: tr
{ 'ovpn mtu-disc with mssfix or fragment' };
789 if ( $cgiparams { 'DHCP_DOMAIN' } ne '' ){
790 unless (& General
:: validdomainname
( $cgiparams { 'DHCP_DOMAIN' }) || & General
:: validip
( $cgiparams { 'DHCP_DOMAIN' })) {
791 $errormessage = $Lang :: tr
{ 'invalid input for dhcp domain' };
795 if ( $cgiparams { 'DHCP_DNS' } ne '' ){
796 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_DNS' }) || & General
:: validip
( $cgiparams { 'DHCP_DNS' })) {
797 $errormessage = $Lang :: tr
{ 'invalid input for dhcp dns' };
801 if ( $cgiparams { 'DHCP_WINS' } ne '' ){
802 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_WINS' }) || & General
:: validip
( $cgiparams { 'DHCP_WINS' })) {
803 $errormessage = $Lang :: tr
{ 'invalid input for dhcp wins' };
807 if ( $cgiparams { 'ROUTES_PUSH' } ne '' ){
808 @temp = split ( /\n/ , $cgiparams { 'ROUTES_PUSH' });
809 undef $vpnsettings { 'ROUTES_PUSH' };
811 foreach my $tmpip ( @temp )
813 s/^\s+//g ; s/\s+$//g ;
818 unless (& General
:: validipandmask
( $tmpip )) {
819 $errormessage = " $tmpip " . $Lang :: tr
{ 'ovpn errmsg invalid ip or mask' };
822 my ( $ip , $cidr ) = split ( "\/" ,& General
:: ipcidr2msk
( $tmpip ));
824 if ( $ip eq $netsettings { 'GREEN_NETADDRESS' } && $cidr eq $netsettings { 'GREEN_NETMASK' }) {
825 $errormessage = $Lang :: tr
{ 'ovpn errmsg green already pushed' };
830 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
831 foreach my $key ( keys %ccdroutehash ) {
832 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}) {
833 if ( $ip . "/" . $cidr eq $ccdroutehash { $key }[ $i ] ){
834 $errormessage = "Route $ip \/ $cidr " . $Lang :: tr
{ 'ccd err inuse' }. " $ccdroutehash { $key }[0]" ;
837 my ( $ip2 , $cidr2 ) = split ( /\/ /, $ccdroutehash { $key }[ $i ]);
838 if (& General
:: IpInSubnet
( $ip , $ip2 , $cidr2 )){
839 $errormessage = "Route $ip \/ $cidr " . $Lang :: tr
{ 'ccd err inuse' }. " $ccdroutehash { $key }[0]" ;
847 $vpnsettings { 'ROUTES_PUSH' } .= $tmpip . " \n " ;
850 & write_routepushfile
;
851 undef $vpnsettings { 'ROUTES_PUSH' };
854 undef $vpnsettings { 'ROUTES_PUSH' };
855 & write_routepushfile
;
857 if (( length ( $cgiparams { 'MAX_CLIENTS' }) == 0 ) || (( $cgiparams { 'MAX_CLIENTS' }) < 1 ) || (( $cgiparams { 'MAX_CLIENTS' }) > 255 )) {
858 $errormessage = $Lang :: tr
{ 'invalid input for max clients' };
861 if ( $cgiparams { 'KEEPALIVE_1' } ne '' ) {
862 if ( $cgiparams { 'KEEPALIVE_1' } !~ /^[0-9]+$/ ) {
863 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 1' };
867 if ( $cgiparams { 'KEEPALIVE_2' } ne '' ){
868 if ( $cgiparams { 'KEEPALIVE_2' } !~ /^[0-9]+$/ ) {
869 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 2' };
873 if ( $cgiparams { 'KEEPALIVE_2' } < ( $cgiparams { 'KEEPALIVE_1' } * 2 )){
874 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 1:2' };
877 # Create ta.key for tls-auth if not presant
878 if ( $cgiparams { 'TLSAUTH' } eq 'on' ) {
879 if ( ! - e
"${General::swroot}/ovpn/certs/ta.key" ) {
880 system ( '/usr/sbin/openvpn' , '--genkey' , '--secret' , "${General::swroot}/ovpn/certs/ta.key" );
882 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
888 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
889 & writeserverconf
(); #hier ok
896 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq 'net' && $cgiparams { 'SIDE' } eq 'server' )
899 my @remsubnet = split ( /\/ /, $cgiparams { 'REMOTE_SUBNET' });
900 my @ovsubnettemp = split ( /\./ , $cgiparams { 'OVPN_SUBNET' });
901 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
904 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
905 unless (- d
"${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" , 0770 or die "Unable to create dir $!" ;}
907 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: $!" ;
910 print SERVERCONF
"# IPFire n2n Open VPN Server Config by ummeegge und m.a.d \n " ;
911 print SERVERCONF
" \n " ;
912 print SERVERCONF
"# User Security \n " ;
913 print SERVERCONF
"user nobody \n " ;
914 print SERVERCONF
"group nobody \n " ;
915 print SERVERCONF
"persist-tun \n " ;
916 print SERVERCONF
"persist-key \n " ;
917 print SERVERCONF
"script-security 2 \n " ;
918 print SERVERCONF
"# IP/DNS for remote Server Gateway \n " ;
920 if ( $cgiparams { 'REMOTE' } ne '' ) {
921 print SERVERCONF
"remote $cgiparams {'REMOTE'} \n " ;
924 print SERVERCONF
"float \n " ;
925 print SERVERCONF
"# IP adresses of the VPN Subnet \n " ;
926 print SERVERCONF
"ifconfig $ovsubnet .1 $ovsubnet .2 \n " ;
927 print SERVERCONF
"# Client Gateway Network \n " ;
928 print SERVERCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
929 print SERVERCONF
"up \" /etc/init.d/static-routes start \"\n " ;
930 print SERVERCONF
"# tun Device \n " ;
931 print SERVERCONF
"dev tun \n " ;
932 print SERVERCONF
"#Logfile for statistics \n " ;
933 print SERVERCONF
"status-version 1 \n " ;
934 print SERVERCONF
"status /var/run/openvpn/ $cgiparams {'NAME'}-n2n 10 \n " ;
935 print SERVERCONF
"# Port and Protokol \n " ;
936 print SERVERCONF
"port $cgiparams {'DEST_PORT'} \n " ;
938 if ( $cgiparams { 'PROTOCOL' } eq 'tcp' ) {
939 print SERVERCONF
"proto tcp-server \n " ;
940 print SERVERCONF
"# Packet size \n " ;
941 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1400' } else { $tunmtu = $cgiparams { 'MTU' }};
942 print SERVERCONF
"tun-mtu $tunmtu \n " ;
945 if ( $cgiparams { 'PROTOCOL' } eq 'udp' ) {
946 print SERVERCONF
"proto udp \n " ;
947 print SERVERCONF
"# Paketsize \n " ;
948 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1500' } else { $tunmtu = $cgiparams { 'MTU' }};
949 print SERVERCONF
"tun-mtu $tunmtu \n " ;
950 if ( $cgiparams { 'FRAGMENT' } ne '' ) { print SERVERCONF
"fragment $cgiparams {'FRAGMENT'} \n " ;}
951 if ( $cgiparams { 'MSSFIX' } eq 'on' ) { print SERVERCONF
"mssfix \n " ; };
954 # Check if a valid operating mode has been choosen and use it.
955 if (( $cgiparams { 'PMTU_DISCOVERY' } eq 'yes' ) ||
956 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
957 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'no' )) {
958 if (( $cgiparams { 'MSSFIX' } ne 'on' ) || ( $cgiparams { 'FRAGMENT' } eq '' )) {
959 if ( $cgiparams { 'MTU' } eq '1500' ) {
960 print SERVERCONF
"mtu-disc $cgiparams {'PMTU_DISCOVERY'} \n " ;
964 print SERVERCONF
"# Auth. Server \n " ;
965 print SERVERCONF
"tls-server \n " ;
966 print SERVERCONF
"ca ${General::swroot}/ovpn/ca/cacert.pem \n " ;
967 print SERVERCONF
"cert ${General::swroot}/ovpn/certs/servercert.pem \n " ;
968 print SERVERCONF
"key ${General::swroot}/ovpn/certs/serverkey.pem \n " ;
969 print SERVERCONF
"dh ${General::swroot}/ovpn/ca/ $cgiparams {'DH_NAME'} \n " ;
970 print SERVERCONF
"# Cipher \n " ;
971 print SERVERCONF
"cipher $cgiparams {'DCIPHER'} \n " ;
972 if ( $cgiparams { 'DAUTH' } eq '' ) {
973 print SERVERCONF
"auth SHA1 \n " ;
975 print SERVERCONF
"# HMAC algorithm \n " ;
976 print SERVERCONF
"auth $cgiparams {'DAUTH'} \n " ;
978 if ( $cgiparams { 'COMPLZO' } eq 'on' ) {
979 print SERVERCONF
"# Enable Compression \n " ;
980 print SERVERCONF
"comp-lzo \n " ;
982 print SERVERCONF
"# Debug Level \n " ;
983 print SERVERCONF
"verb 3 \n " ;
984 print SERVERCONF
"# Tunnel check \n " ;
985 print SERVERCONF
"keepalive 10 60 \n " ;
986 print SERVERCONF
"# Start as daemon \n " ;
987 print SERVERCONF
"daemon $cgiparams {'NAME'}n2n \n " ;
988 print SERVERCONF
"writepid /var/run/ $cgiparams {'NAME'}n2n.pid \n " ;
989 print SERVERCONF
"# Activate Management Interface and Port \n " ;
990 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) { print SERVERCONF
"management localhost $cgiparams {'DEST_PORT'} \n " }
991 else { print SERVERCONF
"management localhost $cgiparams {'OVPN_MGMT'} \n " };
1000 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq 'net' && $cgiparams { 'SIDE' } eq 'client' )
1003 my @ovsubnettemp = split ( /\./ , $cgiparams { 'OVPN_SUBNET' });
1004 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
1005 my @remsubnet = split ( /\/ /, $cgiparams { 'REMOTE_SUBNET' });
1008 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
1009 unless (- d
"${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" , 0770 or die "Unable to create dir $!" ;}
1011 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: $!" ;
1013 flock CLIENTCONF
, 2 ;
1014 print CLIENTCONF
"# IPFire rewritten n2n Open VPN Client Config by ummeegge und m.a.d \n " ;
1015 print CLIENTCONF
"# \n " ;
1016 print CLIENTCONF
"# User Security \n " ;
1017 print CLIENTCONF
"user nobody \n " ;
1018 print CLIENTCONF
"group nobody \n " ;
1019 print CLIENTCONF
"persist-tun \n " ;
1020 print CLIENTCONF
"persist-key \n " ;
1021 print CLIENTCONF
"script-security 2 \n " ;
1022 print CLIENTCONF
"# IP/DNS for remote Server Gateway \n " ;
1023 print CLIENTCONF
"remote $cgiparams {'REMOTE'} \n " ;
1024 print CLIENTCONF
"float \n " ;
1025 print CLIENTCONF
"# IP adresses of the VPN Subnet \n " ;
1026 print CLIENTCONF
"ifconfig $ovsubnet .2 $ovsubnet .1 \n " ;
1027 print CLIENTCONF
"# Server Gateway Network \n " ;
1028 print CLIENTCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
1029 print CLIENTCONF
"up \" /etc/init.d/static-routes start \"\n " ;
1030 print CLIENTCONF
"# tun Device \n " ;
1031 print CLIENTCONF
"dev tun \n " ;
1032 print CLIENTCONF
"# Port and Protokol \n " ;
1033 print CLIENTCONF
"port $cgiparams {'DEST_PORT'} \n " ;
1035 if ( $cgiparams { 'PROTOCOL' } eq 'tcp' ) {
1036 print CLIENTCONF
"proto tcp-client \n " ;
1037 print CLIENTCONF
"# Packet size \n " ;
1038 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1400' } else { $tunmtu = $cgiparams { 'MTU' }};
1039 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
1042 if ( $cgiparams { 'PROTOCOL' } eq 'udp' ) {
1043 print CLIENTCONF
"proto udp \n " ;
1044 print CLIENTCONF
"# Paketsize \n " ;
1045 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1500' } else { $tunmtu = $cgiparams { 'MTU' }};
1046 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
1047 if ( $cgiparams { 'FRAGMENT' } ne '' ) { print CLIENTCONF
"fragment $cgiparams {'FRAGMENT'} \n " ;}
1048 if ( $cgiparams { 'MSSFIX' } eq 'on' ) { print CLIENTCONF
"mssfix \n " ; };
1051 # Check if a valid operating mode has been choosen and use it.
1052 if (( $cgiparams { 'PMTU_DISCOVERY' } eq 'yes' ) ||
1053 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
1054 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'no' )) {
1055 if (( $cgiparams { 'MSSFIX' } ne 'on' ) || ( $cgiparams { 'FRAGMENT' } eq '' )) {
1056 if ( $cgiparams { 'MTU' } eq '1500' ) {
1057 print CLIENTCONF
"mtu-disc $cgiparams {'PMTU_DISCOVERY'} \n " ;
1062 print CLIENTCONF
"ns-cert-type server \n " ;
1063 print CLIENTCONF
"# Auth. Client \n " ;
1064 print CLIENTCONF
"tls-client \n " ;
1065 print CLIENTCONF
"# Cipher \n " ;
1066 print CLIENTCONF
"cipher $cgiparams {'DCIPHER'} \n " ;
1067 print CLIENTCONF
"pkcs12 ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12 \r\n " ;
1068 if ( $cgiparams { 'DAUTH' } eq '' ) {
1069 print CLIENTCONF
"auth SHA1 \n " ;
1071 print CLIENTCONF
"# HMAC algorithm \n " ;
1072 print CLIENTCONF
"auth $cgiparams {'DAUTH'} \n " ;
1074 if ( $cgiparams { 'COMPLZO' } eq 'on' ) {
1075 print CLIENTCONF
"# Enable Compression \n " ;
1076 print CLIENTCONF
"comp-lzo \n " ;
1078 print CLIENTCONF
"# Debug Level \n " ;
1079 print CLIENTCONF
"verb 3 \n " ;
1080 print CLIENTCONF
"# Tunnel check \n " ;
1081 print CLIENTCONF
"keepalive 10 60 \n " ;
1082 print CLIENTCONF
"# Start as daemon \n " ;
1083 print CLIENTCONF
"daemon $cgiparams {'NAME'}n2n \n " ;
1084 print CLIENTCONF
"writepid /var/run/ $cgiparams {'NAME'}n2n.pid \n " ;
1085 print CLIENTCONF
"# Activate Management Interface and Port \n " ;
1086 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) { print CLIENTCONF
"management localhost $cgiparams {'DEST_PORT'} \n " }
1087 else { print CLIENTCONF
"management localhost $cgiparams {'OVPN_MGMT'} \n " };
1093 ### Save main settings
1096 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
1097 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1098 #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too,
1099 #DAN this value has to leave.
1100 if ( $cgiparams { 'ENABLED' } eq 'on' ){
1101 unless (& General
:: validfqdn
( $cgiparams { 'VPN_IP' }) || & General
:: validip
( $cgiparams { 'VPN_IP' })) {
1102 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
1103 goto SETTINGS_ERROR
;
1107 if (! & General
:: validipandmask
( $cgiparams { 'DOVPN_SUBNET' })) {
1108 $errormessage = $Lang :: tr
{ 'ovpn subnet is invalid' };
1109 goto SETTINGS_ERROR
;
1111 my @tmpovpnsubnet = split ( "\/" , $cgiparams { 'DOVPN_SUBNET' });
1113 if (& General
:: IpInSubnet
( $netsettings { 'RED_ADDRESS' },
1114 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1115 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire RED Network $netsettings {'RED_ADDRESS'}" ;
1116 goto SETTINGS_ERROR
;
1119 if (& General
:: IpInSubnet
( $netsettings { 'GREEN_ADDRESS' },
1120 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1121 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Green Network $netsettings {'GREEN_ADDRESS'}" ;
1122 goto SETTINGS_ERROR
;
1125 if (& General
:: IpInSubnet
( $netsettings { 'BLUE_ADDRESS' },
1126 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1127 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Blue Network $netsettings {'BLUE_ADDRESS'}" ;
1128 goto SETTINGS_ERROR
;
1131 if (& General
:: IpInSubnet
( $netsettings { 'ORANGE_ADDRESS' },
1132 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1133 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Orange Network $netsettings {'ORANGE_ADDRESS'}" ;
1134 goto SETTINGS_ERROR
;
1136 open ( ALIASES
, "${General::swroot}/ethernet/aliases" ) or die 'Unable to open aliases file.' ;
1140 my @tempalias = split ( /\,/ , $_ );
1141 if ( $tempalias [ 1 ] eq 'on' ) {
1142 if (& General
:: IpInSubnet
( $tempalias [ 0 ] ,
1143 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1144 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire alias entry $tempalias [0]" ;
1149 if ( $errormessage ne '' ){
1150 goto SETTINGS_ERROR
;
1152 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
1153 $errormessage = $Lang :: tr
{ 'invalid input' };
1154 goto SETTINGS_ERROR
;
1156 if (( length ( $cgiparams { 'DMTU' })== 0 ) || (( $cgiparams { 'DMTU' }) < 1000 )) {
1157 $errormessage = $Lang :: tr
{ 'invalid mtu input' };
1158 goto SETTINGS_ERROR
;
1161 unless (& General
:: validport
( $cgiparams { 'DDEST_PORT' })) {
1162 $errormessage = $Lang :: tr
{ 'invalid port' };
1163 goto SETTINGS_ERROR
;
1166 $vpnsettings { 'ENABLED_BLUE' } = $cgiparams { 'ENABLED_BLUE' };
1167 $vpnsettings { 'ENABLED_ORANGE' } = $cgiparams { 'ENABLED_ORANGE' };
1168 $vpnsettings { 'ENABLED' } = $cgiparams { 'ENABLED' };
1169 $vpnsettings { 'VPN_IP' } = $cgiparams { 'VPN_IP' };
1170 #new settings for daemon
1171 $vpnsettings { 'DOVPN_SUBNET' } = $cgiparams { 'DOVPN_SUBNET' };
1172 $vpnsettings { 'DPROTOCOL' } = $cgiparams { 'DPROTOCOL' };
1173 $vpnsettings { 'DDEST_PORT' } = $cgiparams { 'DDEST_PORT' };
1174 $vpnsettings { 'DMTU' } = $cgiparams { 'DMTU' };
1175 $vpnsettings { 'DCOMPLZO' } = $cgiparams { 'DCOMPLZO' };
1176 $vpnsettings { 'DCIPHER' } = $cgiparams { 'DCIPHER' };
1179 if ( $vpnsettings { 'ENABLED_BLUE' } eq 'on' ) { system ( "touch ${General::swroot}/ovpn/enable_blue 2>/dev/null" );} else { system ( "unlink ${General::swroot}/ovpn/enable_blue 2>/dev/null" );}
1180 if ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' ) { system ( "touch ${General::swroot}/ovpn/enable_orange 2>/dev/null" );} else { system ( "unlink ${General::swroot}/ovpn/enable_orange 2>/dev/null" );}
1181 if ( $vpnsettings { 'ENABLED' } eq 'on' ) { system ( "touch ${General::swroot}/ovpn/enable 2>/dev/null" );} else { system ( "unlink ${General::swroot}/ovpn/enable 2>/dev/null" );}
1182 #new settings for daemon
1183 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1184 & writeserverconf
(); #hier ok
1187 ### Reset all step 2
1189 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
1191 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1193 # Kill all N2N connections
1194 system ( "/usr/local/bin/openvpnctrl -kn2n &>/dev/null" );
1196 foreach my $key ( keys %confighash ) {
1197 my $name = $confighash { $cgiparams { ' $key ' }}[ 1 ];
1199 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
1200 delete $confighash { $cgiparams { ' $key ' }};
1203 system ( "/usr/local/bin/openvpnctrl -drrd $name " );
1205 while ( $file = glob ( "${General::swroot}/ovpn/ca/*" )) {
1208 while ( $file = glob ( "${General::swroot}/ovpn/certs/*" )) {
1211 while ( $file = glob ( "${General::swroot}/ovpn/crls/*" )) {
1214 & cleanssldatabase
();
1215 if ( open ( FILE
, ">${General::swroot}/ovpn/caconfig" )) {
1219 if ( open ( FILE
, ">${General::swroot}/ovpn/ccdroute" )) {
1223 if ( open ( FILE
, ">${General::swroot}/ovpn/ccdroute2" )) {
1227 while ( $file = glob ( "${General::swroot}/ovpn/ccd/*" )) {
1230 while ( $file = glob ( "${General::swroot}/ovpn/ccd/*" )) {
1233 if ( open ( FILE
, ">${General::swroot}/ovpn/ovpn-leases.db" )) {
1237 if ( open ( FILE
, ">${General::swroot}/ovpn/ovpnconfig" )) {
1241 while ( $file = glob ( "${General::swroot}/ovpn/n2nconf/*" )) {
1242 system ( "rm -rf $file " );
1245 # Remove everything from the collectd configuration
1246 & writecollectdconf
();
1248 #&writeserverconf();
1250 ### Reset all step 1
1252 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' }) {
1253 & Header
:: showhttpheaders
();
1254 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
1255 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1256 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
1258 <form method='post'>
1259 <table width='100%'>
1262 <input type='hidden' name='AREUSURE' value='yes' />
1263 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1264 $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}</td>
1267 <td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' />
1268 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
1274 & Header
:: closebox
();
1275 & Header
:: closebigbox
();
1276 & Header
:: closepage
();
1280 ### Generate DH key step 2
1282 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate dh key' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
1283 # Delete if old key exists
1284 if (- f
"${General::swroot}/ovpn/ca/ $cgiparams {'DH_NAME'}" ) {
1285 unlink "${General::swroot}/ovpn/ca/ $cgiparams {'DH_NAME'}" ;
1287 # Create Diffie Hellmann Parameter
1288 system ( '/usr/bin/openssl' , 'dhparam' , '-out' , "${General::swroot}/ovpn/ca/dh1024.pem" , " $cgiparams {'DHLENGHT'}" );
1290 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1291 unlink ( "${General::swroot}/ovpn/ca/dh1024.pem" );
1295 ### Generate DH key step 1
1297 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate dh key' }) {
1298 & Header
:: showhttpheaders
();
1299 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
1300 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1301 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'gen dh'}:" );
1303 <table width='100%'>
1305 <td width='20%'> </td> <td width='15%'></td> <td width='65%'></td>
1308 <td class='base'> $Lang ::tr{'ovpn dh'}:</td>
1310 <form method='post'><input type='hidden' name='AREUSURE' value='yes' />
1311 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
1312 <select name='DHLENGHT'>
1313 <option value='1024' $selected {'DHLENGHT'}{'1024'}>1024 $Lang ::tr{'bit'}</option>
1314 <option value='2048' $selected {'DHLENGHT'}{'2048'}>2048 $Lang ::tr{'bit'}</option>
1315 <option value='3072' $selected {'DHLENGHT'}{'3072'}>3072 $Lang ::tr{'bit'}</option>
1316 <option value='4096' $selected {'DHLENGHT'}{'4096'}>4096 $Lang ::tr{'bit'}</option>
1320 <tr><td colspan='4'><br></td></tr>
1322 <table width='100%'>
1324 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}: </font></b> $Lang ::tr{'dh key warn'}
1327 <td class='base'> $Lang ::tr{'dh key warn1'}</td>
1329 <tr><td colspan='2'><br></td></tr>
1331 <td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'generate dh key'}' /></td>
1338 & Header
:: closebox
();
1339 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1340 & Header
:: closebigbox
();
1341 & Header
:: closepage
();
1347 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload dh key' }) {
1348 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1349 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1350 goto UPLOADCA_ERROR
;
1352 # Move uploaded dh key to a temporary file
1353 ( my $fh , my $filename ) = tempfile
( );
1354 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1356 goto UPLOADCA_ERROR
;
1358 my $temp = `/usr/bin/openssl dhparam -text -in $filename ` ;
1359 if ( $temp !~ /DH Parameters: \((1024|2048|3072|4096) bit\)/ ) {
1360 $errormessage = $Lang :: tr
{ 'not a valid dh key' };
1362 goto UPLOADCA_ERROR
;
1364 # Delete if old key exists
1365 if (- f
"${General::swroot}/ovpn/ca/ $cgiparams {'DH_NAME'}" ) {
1366 unlink "${General::swroot}/ovpn/ca/ $cgiparams {'DH_NAME'}" ;
1368 move
( $filename , "${General::swroot}/ovpn/ca/ $cgiparams {'DH_NAME'}" );
1370 $errormessage = " $Lang ::tr{'dh key move failed'}: $!" ;
1372 goto UPLOADCA_ERROR
;
1377 ### Upload CA Certificate
1379 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
1380 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1382 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
1383 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
1384 goto UPLOADCA_ERROR
;
1387 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
1388 $errormessage = $Lang :: tr
{ 'name too long' };
1392 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
1393 $errormessage = $Lang :: tr
{ 'name is invalid' };
1394 goto UPLOADCA_ERROR
;
1397 # Check if there is no other entry with this name
1398 foreach my $key ( keys %cahash ) {
1399 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
1400 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
1401 goto UPLOADCA_ERROR
;
1405 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1406 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1407 goto UPLOADCA_ERROR
;
1409 # Move uploaded ca to a temporary file
1410 ( my $fh , my $filename ) = tempfile
( );
1411 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1413 goto UPLOADCA_ERROR
;
1415 my $temp = `/usr/bin/openssl x509 -text -in $filename ` ;
1416 if ( $temp !~ /CA:TRUE/i ) {
1417 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
1419 goto UPLOADCA_ERROR
;
1421 move
( $filename , "${General::swroot}/ovpn/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1423 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1425 goto UPLOADCA_ERROR
;
1429 my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/ $cgiparams {'CA_NAME'}cert.pem` ;
1430 $casubject =~ /Subject: (.*)[\n]/ ;
1432 $casubject =~ s
+/ Email
+, E
+;
1433 $casubject =~ s/ ST=/ S=/ ;
1434 $casubject = & Header
:: cleanhtml
( $casubject );
1436 my $key = & General
:: findhasharraykey
( \
%cahash );
1437 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
1438 $cahash { $key }[ 1 ] = $casubject ;
1439 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1440 # system('/usr/local/bin/ipsecctrl', 'R');
1445 ### Display ca certificate
1447 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
1448 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1450 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1451 & Header
:: showhttpheaders
();
1452 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
1453 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
1454 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'ca certificate'}:" );
1455 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
1456 $output = & Header
:: cleanhtml
( $output , "y" );
1457 print "<pre> $output </pre> \n " ;
1458 & Header
:: closebox
();
1459 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1460 & Header
:: closebigbox
();
1461 & Header
:: closepage
();
1464 $errormessage = $Lang :: tr
{ 'invalid key' };
1468 ### Download ca certificate
1470 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
1471 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1473 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1474 print "Content-Type: application/octet-stream \r\n " ;
1475 print "Content-Disposition: filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
1476 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
1479 $errormessage = $Lang :: tr
{ 'invalid key' };
1483 ### Remove ca certificate (step 2)
1485 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
1486 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1487 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1489 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1490 foreach my $key ( keys %confighash ) {
1491 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/ovpn/certs/ $confighash { $key }[1]cert.pem` ;
1492 if ( $test =~ /: OK/ ) {
1494 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1495 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
1496 # system('/usr/local/bin/ipsecctrl', 'D', $key);
1498 unlink ( "${General::swroot}/ovpn//certs/ $confighash { $key }[1]cert.pem" );
1499 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $key }[1].p12" );
1500 delete $confighash { $key };
1501 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1502 # &writeipsecfiles();
1505 unlink ( "${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
1506 delete $cahash { $cgiparams { 'KEY' }};
1507 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1508 # system('/usr/local/bin/ipsecctrl', 'R');
1510 $errormessage = $Lang :: tr
{ 'invalid key' };
1513 ### Remove ca certificate (step 1)
1515 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
1516 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1517 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1519 my $assignedcerts = 0 ;
1520 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1521 foreach my $key ( keys %confighash ) {
1522 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem ${General::swroot}/ovpn/certs/ $confighash { $key }[1]cert.pem` ;
1523 if ( $test =~ /: OK/ ) {
1527 if ( $assignedcerts ) {
1528 & Header
:: showhttpheaders
();
1529 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
1530 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
1531 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'are you sure' });
1533 <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' />
1534 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
1535 <tr><td align='center'>
1536 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>: $assignedcerts
1537 $Lang ::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}
1538 <tr><td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
1539 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td></tr>
1543 & Header
:: closebox
();
1544 & Header
:: closebigbox
();
1545 & Header
:: closepage
();
1548 unlink ( "${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
1549 delete $cahash { $cgiparams { 'KEY' }};
1550 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1551 # system('/usr/local/bin/ipsecctrl', 'R');
1554 $errormessage = $Lang :: tr
{ 'invalid key' };
1558 ### Display root certificate
1560 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
1561 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
1563 & Header
:: showhttpheaders
();
1564 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
1565 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1566 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
1567 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'root certificate'}:" );
1568 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem` ;
1570 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'host certificate'}:" );
1571 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem` ;
1573 $output = & Header
:: cleanhtml
( $output , "y" );
1574 print "<pre> $output </pre> \n " ;
1575 & Header
:: closebox
();
1576 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1577 & Header
:: closebigbox
();
1578 & Header
:: closepage
();
1582 ### Download root certificate
1584 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
1585 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
1586 print "Content-Type: application/octet-stream \r\n " ;
1587 print "Content-Disposition: filename=cacert.pem \r\n\r\n " ;
1588 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/cacert.pem` ;
1593 ### Download host certificate
1595 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
1596 if ( - f
"${General::swroot}/ovpn/certs/servercert.pem" ) {
1597 print "Content-Type: application/octet-stream \r\n " ;
1598 print "Content-Disposition: filename=servercert.pem \r\n\r\n " ;
1599 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/certs/servercert.pem` ;
1604 ### Download tls-auth key
1606 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download tls-auth key' }) {
1607 if ( - f
"${General::swroot}/ovpn/certs/ta.key" ) {
1608 print "Content-Type: application/octet-stream \r\n " ;
1609 print "Content-Disposition: filename=ta.key \r\n\r\n " ;
1610 print `/bin/cat ${General::swroot}/ovpn/certs/ta.key` ;
1615 ### Form for generating a root certificate
1617 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
1618 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
1620 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1621 if (- f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
1622 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
1623 $cgiparams { 'ACTION' } = '' ;
1624 goto ROOTCERT_ERROR
;
1627 if (( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) && - e
"${General::swroot}/red/active" ) {
1628 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
1629 my $ipaddr = < IPADDR
>;
1632 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
1633 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
1634 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
1637 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
1639 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1640 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1641 goto ROOTCERT_ERROR
;
1644 # Move uploaded certificate request to a temporary file
1645 ( my $fh , my $filename ) = tempfile
( );
1646 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1648 goto ROOTCERT_ERROR
;
1651 # Create a temporary dirctory
1652 my $tempdir = tempdir
( CLEANUP
=> 1 );
1654 # Extract the CA certificate from the file
1655 my $pid = open ( OPENSSL
, "|-" );
1656 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1657 if ( $pid ) { # parent
1658 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1659 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1663 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1665 goto ROOTCERT_ERROR
;
1668 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-cacerts' , '-nokeys' ,
1670 '-out' , " $tempdir /cacert.pem" )) {
1671 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1673 goto ROOTCERT_ERROR
;
1677 # Extract the Host certificate from the file
1678 $pid = open ( OPENSSL
, "|-" );
1679 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1680 if ( $pid ) { # parent
1681 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1682 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1686 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1688 goto ROOTCERT_ERROR
;
1691 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-clcerts' , '-nokeys' ,
1693 '-out' , " $tempdir /hostcert.pem" )) {
1694 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1696 goto ROOTCERT_ERROR
;
1700 # Extract the Host key from the file
1701 $pid = open ( OPENSSL
, "|-" );
1702 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1703 if ( $pid ) { # parent
1704 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1705 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1709 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1711 goto ROOTCERT_ERROR
;
1714 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-nocerts' ,
1717 '-out' , " $tempdir /serverkey.pem" )) {
1718 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1720 goto ROOTCERT_ERROR
;
1724 move
( " $tempdir /cacert.pem" , "${General::swroot}/ovpn/ca/cacert.pem" );
1726 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1728 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1729 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1730 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1731 goto ROOTCERT_ERROR
;
1734 move
( " $tempdir /hostcert.pem" , "${General::swroot}/ovpn/certs/servercert.pem" );
1736 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1738 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1739 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1740 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1741 goto ROOTCERT_ERROR
;
1744 move
( " $tempdir /serverkey.pem" , "${General::swroot}/ovpn/certs/serverkey.pem" );
1746 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1748 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1749 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1750 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1751 goto ROOTCERT_ERROR
;
1754 goto ROOTCERT_SUCCESS
;
1756 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
1758 # Validate input since the form was submitted
1759 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
1760 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
1761 goto ROOTCERT_ERROR
;
1763 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
1764 $errormessage = $Lang :: tr
{ 'organization too long' };
1765 goto ROOTCERT_ERROR
;
1767 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1768 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1769 goto ROOTCERT_ERROR
;
1771 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
1772 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
1773 goto ROOTCERT_ERROR
;
1775 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
1776 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
1777 goto ROOTCERT_ERROR
;
1779 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
1780 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1781 goto ROOTCERT_ERROR
;
1783 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
1784 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1785 goto ROOTCERT_ERROR
;
1787 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1788 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1789 goto ROOTCERT_ERROR
;
1791 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1792 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1793 goto ROOTCERT_ERROR
;
1795 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1796 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1797 goto ROOTCERT_ERROR
;
1799 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1800 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1801 goto ROOTCERT_ERROR
;
1804 # Copy the cgisettings to vpnsettings and save the configfile
1805 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
1806 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
1807 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
1808 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
1809 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
1810 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
1811 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
1812 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1814 # Replace empty strings with a .
1815 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
1816 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
1817 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
1820 #system ('/bin/touch', "${General::swroot}/ovpn/gencanow");
1822 # Create the CA certificate
1823 my $pid = open ( OPENSSL
, "|-" );
1824 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1825 if ( $pid ) { # parent
1826 print OPENSSL
" $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1827 print OPENSSL
" $state \n " ;
1828 print OPENSSL
" $city \n " ;
1829 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1830 print OPENSSL
" $ou \n " ;
1831 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
1832 print OPENSSL
" $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1835 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1836 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1837 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1838 goto ROOTCERT_ERROR
;
1841 unless ( exec ( '/usr/bin/openssl' , 'req' , '-x509' , '-nodes' ,
1842 '-days' , '999999' , '-newkey' , 'rsa:4096' , '-sha512' ,
1843 '-keyout' , "${General::swroot}/ovpn/ca/cakey.pem" ,
1844 '-out' , "${General::swroot}/ovpn/ca/cacert.pem" ,
1845 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
1846 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1847 goto ROOTCERT_ERROR
;
1851 # Create the Host certificate request
1852 $pid = open ( OPENSSL
, "|-" );
1853 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1854 if ( $pid ) { # parent
1855 print OPENSSL
" $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1856 print OPENSSL
" $state \n " ;
1857 print OPENSSL
" $city \n " ;
1858 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1859 print OPENSSL
" $ou \n " ;
1860 print OPENSSL
" $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
1861 print OPENSSL
" $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1862 print OPENSSL
". \n " ;
1863 print OPENSSL
". \n " ;
1866 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1867 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1868 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1869 goto ROOTCERT_ERROR
;
1872 unless ( exec ( '/usr/bin/openssl' , 'req' , '-nodes' ,
1873 '-newkey' , 'rsa:2048' ,
1874 '-keyout' , "${General::swroot}/ovpn/certs/serverkey.pem" ,
1875 '-out' , "${General::swroot}/ovpn/certs/serverreq.pem" ,
1876 '-extensions' , 'server' ,
1877 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
1878 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1879 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1880 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1881 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1882 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1883 goto ROOTCERT_ERROR
;
1887 # Sign the host certificate request
1888 system ( '/usr/bin/openssl' , 'ca' , '-days' , '999999' ,
1889 '-batch' , '-notext' ,
1890 '-in' , "${General::swroot}/ovpn/certs/serverreq.pem" ,
1891 '-out' , "${General::swroot}/ovpn/certs/servercert.pem" ,
1892 '-extensions' , 'server' ,
1893 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
1895 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1896 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1897 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1898 unlink ( "${General::swroot}/ovpn/serverkey.pem" );
1899 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1900 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1901 & newcleanssldatabase
();
1902 goto ROOTCERT_ERROR
;
1904 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1905 & deletebackupcert
();
1908 # Create an empty CRL
1909 system ( '/usr/bin/openssl' , 'ca' , '-gencrl' ,
1910 '-out' , "${General::swroot}/ovpn/crls/cacrl.pem" ,
1911 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
1913 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1914 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1915 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1916 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1917 unlink ( "${General::swroot}/ovpn/crls/cacrl.pem" );
1918 & cleanssldatabase
();
1919 goto ROOTCERT_ERROR
;
1921 # &cleanssldatabase();
1923 # Create Diffie Hellmann Parameter
1924 system ( '/usr/bin/openssl' , 'dhparam' , '-out' , "${General::swroot}/ovpn/ca/dh1024.pem" , " $cgiparams {'DHLENGHT'}" );
1926 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1927 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1928 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1929 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1930 unlink ( "${General::swroot}/ovpn/crls/cacrl.pem" );
1931 unlink ( "${General::swroot}/ovpn/ca/dh1024.pem" );
1932 & cleanssldatabase
();
1933 goto ROOTCERT_ERROR
;
1935 # &cleanssldatabase();
1937 # Create ta.key for tls-auth
1938 system ( '/usr/sbin/openvpn' , '--genkey' , '--secret' , "${General::swroot}/ovpn/certs/ta.key" );
1940 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1941 & cleanssldatabase
();
1942 goto ROOTCERT_ERROR
;
1944 goto ROOTCERT_SUCCESS
;
1947 if ( $cgiparams { 'ACTION' } ne '' ) {
1948 & Header
:: showhttpheaders
();
1949 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
1950 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1951 if ( $errormessage ) {
1952 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
1953 print "<class name='base'> $errormessage " ;
1954 print " </class>" ;
1955 & Header
:: closebox
();
1957 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'generate root/host certificates'}:" );
1959 <form method='post' enctype='multipart/form-data'>
1960 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1961 <tr><td width='30%' class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td>
1962 <td width='35%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td>
1963 <td width='35%' colspan='2'> </td></tr>
1964 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}: <img src='/blob.gif' alt='*' /></td>
1965 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td>
1966 <td colspan='2'> </td></tr>
1967 <tr><td class='base'> $Lang ::tr{'your e-mail'}:</td>
1968 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td>
1969 <td colspan='2'> </td></tr>
1970 <tr><td class='base'> $Lang ::tr{'your department'}:</td>
1971 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td>
1972 <td colspan='2'> </td></tr>
1973 <tr><td class='base'> $Lang ::tr{'city'}:</td>
1974 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td>
1975 <td colspan='2'> </td></tr>
1976 <tr><td class='base'> $Lang ::tr{'state or province'}:</td>
1977 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td>
1978 <td colspan='2'> </td></tr>
1979 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1980 <td class='base'><select name='ROOTCERT_COUNTRY'>
1984 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1985 print "<option value=' $Countries ::countries{ $country }'" ;
1986 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1987 print " selected='selected'" ;
1989 print "> $country </option>" ;
1993 <tr><td class='base'> $Lang ::tr{'ovpn dh'}:</td>
1994 <td class='base'><select name='DHLENGHT'>
1995 <option value='1024' $selected {'DHLENGHT'}{'1024'}>1024 $Lang ::tr{'bit'}</option>
1996 <option value='2048' $selected {'DHLENGHT'}{'2048'}>2048 $Lang ::tr{'bit'}</option>
1997 <option value='3072' $selected {'DHLENGHT'}{'3072'}>3072 $Lang ::tr{'bit'}</option>
1998 <option value='4096' $selected {'DHLENGHT'}{'4096'}>4096 $Lang ::tr{'bit'}</option>
2004 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /></td>
2005 <td> </td><td> </td></tr>
2006 <tr><td class='base' colspan='4' align='left'>
2007 <img src='/blob.gif' valign='top' alt='*' /> $Lang ::tr{'required field'}</td></tr>
2008 <tr><td colspan='2'><br></td></tr>
2009 <table width='100%'>
2011 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}: </font></b> $Lang ::tr{'ovpn generating the root and host certificates'}
2012 <td class='base'> $Lang ::tr{'dh key warn'}</td>
2015 <td class='base'> $Lang ::tr{'dh key warn1'}</td>
2017 <tr><td colspan='2'><br></td></tr>
2021 <table width='100%'>
2022 <tr><td colspan='4'><hr></td></tr>
2023 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}: <img src='/blob.gif' alt='*' /></td>
2024 <td nowrap='nowrap'><input type='file' name='FH' size='32'></td>
2025 <td colspan='2'> </td></tr>
2026 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
2027 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td>
2028 <td colspan='2'> </td></tr>
2030 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td>
2031 <td colspan='2'> </td></tr>
2032 <tr><td class='base' colspan='4' align='left'>
2033 <img src='/blob.gif' valign='top' alt='*' > $Lang ::tr{'required field'}</td>
2038 & Header
:: closebox
();
2039 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2040 & Header
:: closebigbox
();
2041 & Header
:: closepage
();
2046 system ( "chmod 600 ${General::swroot}/ovpn/certs/serverkey.pem" );
2047 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2048 # $vpnsettings{'ENABLE_BLUE'} eq 'on') {
2049 # system('/usr/local/bin/ipsecctrl', 'S');
2053 ### Enable/Disable connection
2060 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
2062 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2063 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2064 # my $n2nactive = '';
2065 my $n2nactive = `/bin/ps ax|grep $confighash { $cgiparams {'KEY'}}[1]|grep -v grep|awk \' {print \ $1 } \' ` ;
2067 if ( $confighash { $cgiparams { 'KEY' }}) {
2068 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
2069 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
2070 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2072 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
2073 system ( '/usr/local/bin/openvpnctrl' , '-sn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
2074 & writecollectdconf
();
2078 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
2079 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2081 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
2082 if ( $n2nactive ne '' ) {
2083 system ( '/usr/local/bin/openvpnctrl' , '-kn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
2084 & writecollectdconf
();
2088 $errormessage = $Lang :: tr
{ 'invalid key' };
2094 ### Download OpenVPN client package
2098 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'dl client arch' }) {
2099 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2100 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2102 my $clientovpn = '' ;
2104 my $tempdir = tempdir
( CLEANUP
=> 1 );
2105 my $zippath = " $tempdir /" ;
2111 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
2113 my $zipname = " $confighash { $cgiparams {'KEY'}}[1]-Client.zip" ;
2114 my $zippathname = " $zippath $zipname " ;
2115 $clientovpn = " $confighash { $cgiparams {'KEY'}}[1].conf" ;
2116 my @ovsubnettemp = split ( /\./ , $confighash { $cgiparams { 'KEY' }}[ 27 ]);
2117 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
2119 my @remsubnet = split ( /\/ /, $confighash { $cgiparams { 'KEY' }}[ 8 ]);
2120 my $n2nfragment = '' ;
2122 open ( CLIENTCONF
, "> $tempdir / $clientovpn " ) or die "Unable to open tempfile: $!" ;
2123 flock CLIENTCONF
, 2 ;
2125 my $zip = Archive
:: Zip
-> new ();
2126 print CLIENTCONF
"# IPFire n2n Open VPN Client Config by ummeegge und m.a.d \n " ;
2127 print CLIENTCONF
"# \n " ;
2128 print CLIENTCONF
"# User Security \n " ;
2129 print CLIENTCONF
"user nobody \n " ;
2130 print CLIENTCONF
"group nobody \n " ;
2131 print CLIENTCONF
"persist-tun \n " ;
2132 print CLIENTCONF
"persist-key \n " ;
2133 print CLIENTCONF
"script-security 2 \n " ;
2134 print CLIENTCONF
"# IP/DNS for remote Server Gateway \n " ;
2135 print CLIENTCONF
"remote $vpnsettings {'VPN_IP'} \n " ;
2136 print CLIENTCONF
"float \n " ;
2137 print CLIENTCONF
"# IP adresses of the VPN Subnet \n " ;
2138 print CLIENTCONF
"ifconfig $ovsubnet .2 $ovsubnet .1 \n " ;
2139 print CLIENTCONF
"# Server Gateway Network \n " ;
2140 print CLIENTCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
2141 print CLIENTCONF
"# tun Device \n " ;
2142 print CLIENTCONF
"dev tun \n " ;
2143 print CLIENTCONF
"# Port and Protokoll \n " ;
2144 print CLIENTCONF
"port $confighash { $cgiparams {'KEY'}}[29] \n " ;
2146 if ( $confighash { $cgiparams { 'KEY' }}[ 28 ] eq 'tcp' ) {
2147 print CLIENTCONF
"proto tcp-client \n " ;
2148 print CLIENTCONF
"# Packet size \n " ;
2149 if ( $confighash { $cgiparams { 'KEY' }}[ 31 ] eq '' ) { $tunmtu = '1400' } else { $tunmtu = $confighash { $cgiparams { 'KEY' }}[ 31 ]};
2150 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
2153 if ( $confighash { $cgiparams { 'KEY' }}[ 28 ] eq 'udp' ) {
2154 print CLIENTCONF
"proto udp \n " ;
2155 print CLIENTCONF
"# Paketsize \n " ;
2156 if ( $confighash { $cgiparams { 'KEY' }}[ 31 ] eq '' ) { $tunmtu = '1500' } else { $tunmtu = $confighash { $cgiparams { 'KEY' }}[ 31 ]};
2157 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
2158 if ( $confighash { $cgiparams { 'KEY' }}[ 24 ] ne '' ) { print CLIENTCONF
"fragment $confighash { $cgiparams {'KEY'}}[24] \n " ;}
2159 if ( $confighash { $cgiparams { 'KEY' }}[ 23 ] eq 'on' ) { print CLIENTCONF
"mssfix \n " ;}
2161 if (( $confighash { $cgiparams { 'KEY' }}[ 38 ] eq 'yes' ) ||
2162 ( $confighash { $cgiparams { 'KEY' }}[ 38 ] eq 'maybe' ) ||
2163 ( $confighash { $cgiparams { 'KEY' }}[ 38 ] eq 'no' )) {
2164 if (( $confighash { $cgiparams { 'KEY' }}[ 23 ] ne 'on' ) || ( $confighash { $cgiparams { 'KEY' }}[ 24 ] eq '' )) {
2165 if ( $tunmtu eq '1500' ) {
2166 print CLIENTCONF
"mtu-disc $confighash { $cgiparams {'KEY'}}[38] \n " ;
2170 print CLIENTCONF
"ns-cert-type server \n " ;
2171 print CLIENTCONF
"# Auth. Client \n " ;
2172 print CLIENTCONF
"tls-client \n " ;
2173 print CLIENTCONF
"# Cipher \n " ;
2174 print CLIENTCONF
"cipher $confighash { $cgiparams {'KEY'}}[40] \n " ;
2175 if ( $confighash { $cgiparams { 'KEY' }}[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ) {
2176 print CLIENTCONF
"pkcs12 ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12 \r\n " ;
2177 $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 " ;
2179 if ( $confighash { $cgiparams { 'KEY' }}[ 39 ] eq '' ) {
2180 print CLIENTCONF
"# HMAC algorithm \n " ;
2181 print CLIENTCONF
"auth SHA1 \n " ;
2183 print CLIENTCONF
"# HMAC algorithm \n " ;
2184 print CLIENTCONF
"auth $confighash { $cgiparams {'KEY'}}[39] \n " ;
2186 if ( $confighash { $cgiparams { 'KEY' }}[ 30 ] eq 'on' ) {
2187 print CLIENTCONF
"# Enable Compression \n " ;
2188 print CLIENTCONF
"comp-lzo \n " ;
2190 print CLIENTCONF
"# Debug Level \n " ;
2191 print CLIENTCONF
"verb 3 \n " ;
2192 print CLIENTCONF
"# Tunnel check \n " ;
2193 print CLIENTCONF
"keepalive 10 60 \n " ;
2194 print CLIENTCONF
"# Start as daemon \n " ;
2195 print CLIENTCONF
"daemon $confighash { $cgiparams {'KEY'}}[1]n2n \n " ;
2196 print CLIENTCONF
"writepid /var/run/ $confighash { $cgiparams {'KEY'}}[1]n2n.pid \n " ;
2197 print CLIENTCONF
"# Activate Management Interface and Port \n " ;
2198 if ( $confighash { $cgiparams { 'KEY' }}[ 22 ] eq '' ) { print CLIENTCONF
"management localhost $confighash { $cgiparams {'KEY'}}[29] \n " }
2199 else { print CLIENTCONF
"management localhost $confighash { $cgiparams {'KEY'}}[22] \n " };
2200 print CLIENTCONF
"# remsub $confighash { $cgiparams {'KEY'}}[11] \n " ;
2205 $zip -> addFile ( " $tempdir / $clientovpn " , $clientovpn ) or die "Can't add file $clientovpn \n " ;
2206 my $status = $zip -> writeToFileNamed ( $zippathname );
2208 open ( DLFILE
, "< $zippathname " ) or die "Unable to open $zippathname : $!" ;
2209 @fileholder = < DLFILE
>;
2210 print "Content-Type:application/x-download \n " ;
2211 print "Content-Disposition:attachment;filename= $zipname \n\n " ;
2217 my $zipname = " $confighash { $cgiparams {'KEY'}}[1]-TO-IPFire.zip" ;
2218 my $zippathname = " $zippath $zipname " ;
2219 $clientovpn = " $confighash { $cgiparams {'KEY'}}[1]-TO-IPFire.ovpn" ;
2225 open ( CLIENTCONF
, "> $tempdir / $clientovpn " ) or die "Unable to open tempfile: $!" ;
2226 flock CLIENTCONF
, 2 ;
2228 my $zip = Archive
:: Zip
-> new ();
2230 print CLIENTCONF
"#OpenVPN Client conf \r\n " ;
2231 print CLIENTCONF
"tls-client \r\n " ;
2232 print CLIENTCONF
"client \r\n " ;
2233 print CLIENTCONF
"nobind \r\n " ;
2234 print CLIENTCONF
"dev tun \r\n " ;
2235 print CLIENTCONF
"proto $vpnsettings {'DPROTOCOL'} \r\n " ;
2237 # Check if we are using fragment, mssfix or mtu-disc and set MTU to 1500
2238 # or use configured value.
2239 if ( $vpnsettings { FRAGMENT
} ne '' && $vpnsettings { DPROTOCOL
} ne 'tcp' )
2240 { print CLIENTCONF
"tun-mtu 1500 \r\n " ; }
2241 elsif ( $vpnsettings { MSSFIX
} eq 'on' )
2242 { print CLIENTCONF
"tun-mtu 1500 \r\n " ; }
2243 elsif (( $vpnsettings { 'PMTU_DISCOVERY' } eq 'yes' ) ||
2244 ( $vpnsettings { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
2245 ( $vpnsettings { 'PMTU_DISCOVERY' } eq 'no' ))
2246 { print CLIENTCONF
"tun-mtu 1500 \r\n " ; }
2248 { print CLIENTCONF
"tun-mtu $vpnsettings {'DMTU'} \r\n " ; }
2250 if ( $vpnsettings { 'ENABLED' } eq 'on' ){
2251 print CLIENTCONF
"remote $vpnsettings {'VPN_IP'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2252 if ( $vpnsettings { 'ENABLED_BLUE' } eq 'on' && (& haveBlueNet
())){
2253 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Blue interface \r\n " ;
2254 print CLIENTCONF
";remote $netsettings {'BLUE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2256 if ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
2257 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Orange interface \r\n " ;
2258 print CLIENTCONF
";remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2260 } elsif ( $vpnsettings { 'ENABLED_BLUE' } eq 'on' && (& haveBlueNet
())){
2261 print CLIENTCONF
"remote $netsettings {'BLUE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2262 if ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
2263 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Orange interface \r\n " ;
2264 print CLIENTCONF
";remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2266 } elsif ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
2267 print CLIENTCONF
"remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2270 my $file_crt = new File
:: Temp
( UNLINK
=> 1 );
2271 my $file_key = new File
:: Temp
( UNLINK
=> 1 );
2272 my $include_certs = 0 ;
2274 if ( $confighash { $cgiparams { 'KEY' }}[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ) {
2275 if ( $cgiparams { 'MODE' } eq 'insecure' ) {
2279 print CLIENTCONF
";ca cacert.pem \r\n " ;
2280 $zip -> addFile ( "${General::swroot}/ovpn/ca/cacert.pem" , "cacert.pem" ) or die "Can't add file cacert.pem \n " ;
2282 # Extract the certificate
2283 system ( '/usr/bin/openssl' , 'pkcs12' , '-in' , "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ,
2284 '-clcerts' , '-nokeys' , '-nodes' , '-out' , " $file_crt " , '-passin' , 'pass:' );
2286 die "openssl error: $?" ;
2289 $zip -> addFile ( " $file_crt " , " $confighash { $cgiparams {'KEY'}}[1].pem" ) or die ;
2290 print CLIENTCONF
";cert $confighash { $cgiparams {'KEY'}}[1].pem \r\n " ;
2293 system ( '/usr/bin/openssl' , 'pkcs12' , '-in' , "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ,
2294 '-nocerts' , '-nodes' , '-out' , " $file_key " , '-passin' , 'pass:' );
2296 die "openssl error: $?" ;
2299 $zip -> addFile ( " $file_key " , " $confighash { $cgiparams {'KEY'}}[1].key" ) or die ;
2300 print CLIENTCONF
";key $confighash { $cgiparams {'KEY'}}[1].key \r\n " ;
2302 print CLIENTCONF
"pkcs12 $confighash { $cgiparams {'KEY'}}[1].p12 \r\n " ;
2303 $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 " ;
2306 print CLIENTCONF
"ca cacert.pem \r\n " ;
2307 print CLIENTCONF
"cert $confighash { $cgiparams {'KEY'}}[1]cert.pem \r\n " ;
2308 print CLIENTCONF
"key $confighash { $cgiparams {'KEY'}}[1].key \r\n " ;
2309 $zip -> addFile ( "${General::swroot}/ovpn/ca/cacert.pem" , "cacert.pem" ) or die "Can't add file cacert.pem \n " ;
2310 $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 " ;
2312 print CLIENTCONF
"cipher $vpnsettings {DCIPHER} \r\n " ;
2313 if ( $vpnsettings { 'DAUTH' } eq '' ) {
2314 print CLIENTCONF
"" ;
2316 print CLIENTCONF
"auth $vpnsettings {'DAUTH'} \r\n " ;
2318 if ( $vpnsettings { 'TLSAUTH' } eq 'on' ) {
2319 if ( $cgiparams { 'MODE' } eq 'insecure' ) {
2320 print CLIENTCONF
";" ;
2322 print CLIENTCONF
"tls-auth ta.key \r\n " ;
2323 $zip -> addFile ( "${General::swroot}/ovpn/certs/ta.key" , "ta.key" ) or die "Can't add file ta.key \n " ;
2325 if ( $vpnsettings { DCOMPLZO
} eq 'on' ) {
2326 print CLIENTCONF
"comp-lzo \r\n " ;
2328 print CLIENTCONF
"verb 3 \r\n " ;
2329 print CLIENTCONF
"ns-cert-type server \r\n " ;
2330 print CLIENTCONF
"tls-remote $vpnsettings {ROOTCERT_HOSTNAME} \r\n " ;
2331 if ( $vpnsettings { MSSFIX
} eq 'on' ) {
2332 print CLIENTCONF
"mssfix \r\n " ;
2334 if ( $vpnsettings { FRAGMENT
} ne '' && $vpnsettings { DPROTOCOL
} ne 'tcp' ) {
2335 print CLIENTCONF
"fragment $vpnsettings {'FRAGMENT'} \r\n " ;
2338 # Check if a valid operating mode has been choosen and use it.
2339 if (( $vpnsettings { 'PMTU_DISCOVERY' } eq 'yes' ) ||
2340 ( $vpnsettings { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
2341 ( $vpnsettings { 'PMTU_DISCOVERY' } eq 'no' )) {
2342 if (( $vpnsettings { MSSFIX
} ne 'on' ) || ( $vpnsettings { FRAGMENT
} eq '' )) {
2343 print CLIENTCONF
"mtu-disc $vpnsettings {'PMTU_DISCOVERY'} \r\n " ;
2347 if ( $include_certs ) {
2348 print CLIENTCONF
" \r\n " ;
2351 open ( FILE
, "<${General::swroot}/ovpn/ca/cacert.pem" );
2352 print CLIENTCONF
"<ca> \r\n " ;
2355 print CLIENTCONF
" $_ \r\n " ;
2357 print CLIENTCONF
"</ca> \r\n\r\n " ;
2361 open ( FILE
, "< $file_crt " );
2362 print CLIENTCONF
"<cert> \r\n " ;
2365 print CLIENTCONF
" $_ \r\n " ;
2367 print CLIENTCONF
"</cert> \r\n\r\n " ;
2371 open ( FILE
, "< $file_key " );
2372 print CLIENTCONF
"<key> \r\n " ;
2375 print CLIENTCONF
" $_ \r\n " ;
2377 print CLIENTCONF
"</key> \r\n\r\n " ;
2381 if ( $vpnsettings { 'TLSAUTH' } eq 'on' ) {
2382 open ( FILE
, "<${General::swroot}/ovpn/certs/ta.key" );
2383 print CLIENTCONF
"<tls-auth> \r\n " ;
2386 print CLIENTCONF
" $_ \r\n " ;
2388 print CLIENTCONF
"</tls-auth> \r\n\r\n " ;
2393 # Print client.conf.local if entries exist to client.ovpn
2394 if (!- z
$local_clientconf && $vpnsettings { 'ADDITIONAL_CONFIGS' } eq 'on' ) {
2395 open ( LCC
, " $local_clientconf " );
2396 print CLIENTCONF
" \n #--------------------------- \n " ;
2397 print CLIENTCONF
"# Start of custom directives \n " ;
2398 print CLIENTCONF
"# from client.conf.local \n " ;
2399 print CLIENTCONF
"#--------------------------- \n\n " ;
2401 print CLIENTCONF
$_ ;
2403 print CLIENTCONF
" \n #--------------------------- \n " ;
2404 print CLIENTCONF
"# End of custom directives \n " ;
2405 print CLIENTCONF
"#--------------------------- \n\n " ;
2410 $zip -> addFile ( " $tempdir / $clientovpn " , $clientovpn ) or die "Can't add file $clientovpn \n " ;
2411 my $status = $zip -> writeToFileNamed ( $zippathname );
2413 open ( DLFILE
, "< $zippathname " ) or die "Unable to open $zippathname : $!" ;
2414 @fileholder = < DLFILE
>;
2415 print "Content-Type:application/x-download \n " ;
2416 print "Content-Disposition:attachment;filename= $zipname \n\n " ;
2424 ### Remove connection
2428 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
2429 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2430 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2432 if ( $confighash { $cgiparams { 'KEY' }}) {
2433 # Revoke certificate if certificate was deleted and rewrite the CRL
2434 my $temp = `/usr/bin/openssl ca -revoke ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf` ;
2435 my $tempA = `/usr/bin/openssl ca -gencrl -out ${General::swroot}/ovpn/crls/cacrl.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf` ;
2441 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ) {
2442 # Stop the N2N connection before it is removed
2443 system ( "/usr/local/bin/openvpnctrl -kn2n $confighash { $cgiparams {'KEY'}}[1] &>/dev/null" );
2445 my $conffile = glob ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]/ $confighash { $cgiparams {'KEY'}}[1].conf" );
2446 my $certfile = glob ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
2450 if (- e
"${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]" ) {
2451 rmdir ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]" ) || die "Kann Verzeichnis nicht loeschen: $!" ;
2455 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
2456 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
2458 # A.Marx CCD delete ccd files and routes
2460 if (- f
"${General::swroot}/ovpn/ccd/ $confighash { $cgiparams {'KEY'}}[2]" )
2462 unlink "${General::swroot}/ovpn/ccd/ $confighash { $cgiparams {'KEY'}}[2]" ;
2465 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
2466 foreach my $key ( keys %ccdroutehash ) {
2467 if ( $ccdroutehash { $key }[ 0 ] eq $confighash { $cgiparams { 'KEY' }}[ 1 ]){
2468 delete $ccdroutehash { $key };
2471 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
2473 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
2474 foreach my $key ( keys %ccdroute2hash ) {
2475 if ( $ccdroute2hash { $key }[ 0 ] eq $confighash { $cgiparams { 'KEY' }}[ 1 ]){
2476 delete $ccdroute2hash { $key };
2479 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
2483 # Update collectd configuration and delete all RRD files of the removed connection
2484 & writecollectdconf
();
2485 system ( "/usr/local/bin/openvpnctrl -drrd $confighash { $cgiparams {'KEY'}}[1]" );
2487 delete $confighash { $cgiparams { 'KEY' }};
2488 my $temp2 = `/usr/bin/openssl ca -gencrl -out ${General::swroot}/ovpn/crls/cacrl.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf` ;
2489 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2492 $errormessage = $Lang :: tr
{ 'invalid key' };
2494 & General
:: firewall_reload
();
2497 ### Download PKCS12 file
2499 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
2500 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2502 print "Content-Disposition: filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
2503 print "Content-Type: application/octet-stream \r\n\r\n " ;
2504 print `/bin/cat ${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 = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
2519 $output = & Header
:: cleanhtml
( $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 Diffie-Hellman key
2531 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show dh' }) {
2533 if (! - e
"${General::swroot}/ovpn/ca/dh1024.pem" ) {
2534 $errormessage = $Lang :: tr
{ 'not present' };
2536 & Header
:: showhttpheaders
();
2537 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
2538 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2539 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'dh'}:" );
2540 my $output = `/usr/bin/openssl dhparam -text -in ${General::swroot}/ovpn/ca/dh1024.pem` ;
2541 $output = & Header
:: cleanhtml
( $output , "y" );
2542 print "<pre> $output </pre> \n " ;
2543 & Header
:: closebox
();
2544 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2545 & Header
:: closebigbox
();
2546 & Header
:: closepage
();
2551 ### Display tls-auth key
2553 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show tls-auth key' }) {
2555 if (! - e
"${General::swroot}/ovpn/certs/ta.key" ) {
2556 $errormessage = $Lang :: tr
{ 'not present' };
2558 & Header
:: showhttpheaders
();
2559 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
2560 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2561 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'ta key'}:" );
2562 my $output = `/bin/cat ${General::swroot}/ovpn/certs/ta.key` ;
2563 $output = & Header
:: cleanhtml
( $output , "y" );
2564 print "<pre> $output </pre> \n " ;
2565 & Header
:: closebox
();
2566 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2567 & Header
:: closebigbox
();
2568 & Header
:: closepage
();
2573 ### Display Certificate Revoke List
2575 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show crl' }) {
2576 # &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2578 if (! - e
"${General::swroot}/ovpn/crls/cacrl.pem" ) {
2579 $errormessage = $Lang :: tr
{ 'not present' };
2581 & Header
:: showhttpheaders
();
2582 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
2583 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2584 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'crl'}:" );
2585 my $output = `/usr/bin/openssl crl -text -noout -in ${General::swroot}/ovpn/crls/cacrl.pem` ;
2586 $output = & Header
:: cleanhtml
( $output , "y" );
2587 print "<pre> $output </pre> \n " ;
2588 & Header
:: closebox
();
2589 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2590 & Header
:: closebigbox
();
2591 & Header
:: closepage
();
2596 ### Advanced Server Settings
2599 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced server' }) {
2604 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%cgiparams );
2608 # if ($cgiparams{'CLIENT2CLIENT'} eq '') {
2609 # $cgiparams{'CLIENT2CLIENT'} = 'on';
2612 if ( $cgiparams { 'MAX_CLIENTS' } eq '' ) {
2613 $cgiparams { 'MAX_CLIENTS' } = '100' ;
2615 if ( $cgiparams { 'KEEPALIVE_1' } eq '' ) {
2616 $cgiparams { 'KEEPALIVE_1' } = '10' ;
2618 if ( $cgiparams { 'KEEPALIVE_2' } eq '' ) {
2619 $cgiparams { 'KEEPALIVE_2' } = '60' ;
2621 if ( $cgiparams { 'LOG_VERB' } eq '' ) {
2622 $cgiparams { 'LOG_VERB' } = '3' ;
2624 if ( $cgiparams { 'PMTU_DISCOVERY' } eq '' ) {
2625 $cgiparams { 'PMTU_DISCOVERY' } = 'off' ;
2627 if ( $cgiparams { 'DAUTH' } eq '' ) {
2628 $cgiparams { 'DAUTH' } = 'SHA1' ;
2630 if ( $cgiparams { 'TLSAUTH' } eq '' ) {
2631 $cgiparams { 'TLSAUTH' } = 'off' ;
2633 $checked { 'CLIENT2CLIENT' }{ 'off' } = '' ;
2634 $checked { 'CLIENT2CLIENT' }{ 'on' } = '' ;
2635 $checked { 'CLIENT2CLIENT' }{ $cgiparams { 'CLIENT2CLIENT' }} = 'CHECKED' ;
2636 $checked { 'REDIRECT_GW_DEF1' }{ 'off' } = '' ;
2637 $checked { 'REDIRECT_GW_DEF1' }{ 'on' } = '' ;
2638 $checked { 'REDIRECT_GW_DEF1' }{ $cgiparams { 'REDIRECT_GW_DEF1' }} = 'CHECKED' ;
2639 $checked { 'ADDITIONAL_CONFIGS' }{ 'off' } = '' ;
2640 $checked { 'ADDITIONAL_CONFIGS' }{ 'on' } = '' ;
2641 $checked { 'ADDITIONAL_CONFIGS' }{ $cgiparams { 'ADDITIONAL_CONFIGS' }} = 'CHECKED' ;
2642 $checked { 'MSSFIX' }{ 'off' } = '' ;
2643 $checked { 'MSSFIX' }{ 'on' } = '' ;
2644 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
2645 $checked { 'PMTU_DISCOVERY' }{ $cgiparams { 'PMTU_DISCOVERY' }} = 'checked= \' checked \' ' ;
2646 $selected { 'LOG_VERB' }{ '0' } = '' ;
2647 $selected { 'LOG_VERB' }{ '1' } = '' ;
2648 $selected { 'LOG_VERB' }{ '2' } = '' ;
2649 $selected { 'LOG_VERB' }{ '3' } = '' ;
2650 $selected { 'LOG_VERB' }{ '4' } = '' ;
2651 $selected { 'LOG_VERB' }{ '5' } = '' ;
2652 $selected { 'LOG_VERB' }{ '6' } = '' ;
2653 $selected { 'LOG_VERB' }{ '7' } = '' ;
2654 $selected { 'LOG_VERB' }{ '8' } = '' ;
2655 $selected { 'LOG_VERB' }{ '9' } = '' ;
2656 $selected { 'LOG_VERB' }{ '10' } = '' ;
2657 $selected { 'LOG_VERB' }{ '11' } = '' ;
2658 $selected { 'LOG_VERB' }{ $cgiparams { 'LOG_VERB' }} = 'SELECTED' ;
2659 $selected { 'DAUTH' }{ 'whirlpool' } = '' ;
2660 $selected { 'DAUTH' }{ 'SHA512' } = '' ;
2661 $selected { 'DAUTH' }{ 'SHA384' } = '' ;
2662 $selected { 'DAUTH' }{ 'SHA256' } = '' ;
2663 $selected { 'DAUTH' }{ 'SHA1' } = '' ;
2664 $selected { 'DAUTH' }{ $cgiparams { 'DAUTH' }} = 'SELECTED' ;
2665 $checked { 'TLSAUTH' }{ 'off' } = '' ;
2666 $checked { 'TLSAUTH' }{ 'on' } = '' ;
2667 $checked { 'TLSAUTH' }{ $cgiparams { 'TLSAUTH' }} = 'CHECKED' ;
2669 & Header
:: showhttpheaders
();
2670 & Header
:: openpage
( $Lang :: tr
{ 'status ovpn' }, 1 , '' );
2671 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
2672 if ( $errormessage ) {
2673 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
2674 print "<class name='base'> $errormessage \n " ;
2675 print " </class> \n " ;
2676 & Header
:: closebox
();
2678 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'advanced server' });
2680 <form method='post' enctype='multipart/form-data'>
2681 <table width='100%' border=0>
2683 <td colspan='4'><b> $Lang ::tr{'dhcp-options'}</b></td>
2686 <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
2689 <td class='base'>Domain</td>
2690 <td><input type='TEXT' name='DHCP_DOMAIN' value=' $cgiparams {'DHCP_DOMAIN'}' size='30' /></td>
2693 <td class='base'>DNS</td>
2694 <td><input type='TEXT' name='DHCP_DNS' value=' $cgiparams {'DHCP_DNS'}' size='30' /></td>
2697 <td class='base'>WINS</td>
2698 <td><input type='TEXT' name='DHCP_WINS' value=' $cgiparams {'DHCP_WINS'}' size='30' /></td>
2701 <td colspan='4'><b> $Lang ::tr{'ovpn routes push options'}</b></td>
2704 <td class='base'> $Lang ::tr{'ovpn routes push'}</td>
2706 <textarea name='ROUTES_PUSH' cols='26' rows='6' wrap='off'>
2710 if ( $cgiparams { 'ROUTES_PUSH' } ne '' )
2712 print $cgiparams { 'ROUTES_PUSH' };
2721 <table width='100%'>
2723 <td class'base'><b> $Lang ::tr{'misc-options'}</b></td>
2727 <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='15%'></td><td width='35%'></td>
2731 <td class='base'>Client-To-Client</td>
2732 <td><input type='checkbox' name='CLIENT2CLIENT' $checked {'CLIENT2CLIENT'}{'on'} /></td>
2736 <td class='base'>Redirect-Gateway def1</td>
2737 <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked {'REDIRECT_GW_DEF1'}{'on'} /></td>
2741 <td class='base'> $Lang ::tr{'ovpn add conf'}</td>
2742 <td><input type='checkbox' name='ADDITIONAL_CONFIGS' $checked {'ADDITIONAL_CONFIGS'}{'on'} /></td>
2743 <td> $Lang ::tr{'openvpn default'}: off</td>
2747 <td class='base'>mssfix</td>
2748 <td><input type='checkbox' name='MSSFIX' $checked {'MSSFIX'}{'on'} /></td>
2749 <td> $Lang ::tr{'openvpn default'}: off</td>
2753 <td class='base'>fragment <br></td>
2754 <td><input type='TEXT' name='FRAGMENT' value=' $cgiparams {'FRAGMENT'}' size='10' /></td>
2759 <td class='base'>Max-Clients</td>
2760 <td><input type='text' name='MAX_CLIENTS' value=' $cgiparams {'MAX_CLIENTS'}' size='10' /></td>
2763 <td class='base'>Keepalive <br />
2764 (ping/ping-restart)</td>
2765 <td><input type='TEXT' name='KEEPALIVE_1' value=' $cgiparams {'KEEPALIVE_1'}' size='10' /></td>
2766 <td><input type='TEXT' name='KEEPALIVE_2' value=' $cgiparams {'KEEPALIVE_2'}' size='10' /></td>
2770 <td class='base'> $Lang ::tr{'ovpn mtu-disc'}</td>
2771 <td><input type='radio' name='PMTU_DISCOVERY' value='yes' $checked {'PMTU_DISCOVERY'}{'yes'} /> $Lang ::tr{'ovpn mtu-disc yes'}</td>
2772 <td><input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked {'PMTU_DISCOVERY'}{'maybe'} /> $Lang ::tr{'ovpn mtu-disc maybe'}</td>
2773 <td><input type='radio' name='PMTU_DISCOVERY' value='no' $checked {'PMTU_DISCOVERY'}{'no'} /> $Lang ::tr{'ovpn mtu-disc no'}</td>
2774 <td><input type='radio' name='PMTU_DISCOVERY' value='off' $checked {'PMTU_DISCOVERY'}{'off'} /> $Lang ::tr{'ovpn mtu-disc off'}</td>
2779 <table width='100%'>
2781 <td class'base'><b> $Lang ::tr{'log-options'}</b></td>
2784 <td width='20%'></td> <td width='30%'> </td><td width='25%'> </td><td width='25%'></td>
2787 <tr><td class='base'>VERB</td>
2788 <td><select name='LOG_VERB'>
2789 <option value='0' $selected {'LOG_VERB'}{'0'}>0</option>
2790 <option value='1' $selected {'LOG_VERB'}{'1'}>1</option>
2791 <option value='2' $selected {'LOG_VERB'}{'2'}>2</option>
2792 <option value='3' $selected {'LOG_VERB'}{'3'}>3</option>
2793 <option value='4' $selected {'LOG_VERB'}{'4'}>4</option>
2794 <option value='5' $selected {'LOG_VERB'}{'5'}>5</option>
2795 <option value='6' $selected {'LOG_VERB'}{'6'}>6</option>
2796 <option value='7' $selected {'LOG_VERB'}{'7'}>7</option>
2797 <option value='8' $selected {'LOG_VERB'}{'8'}>8</option>
2798 <option value='9' $selected {'LOG_VERB'}{'9'}>9</option>
2799 <option value='10' $selected {'LOG_VERB'}{'10'}>10</option>
2800 <option value='11' $selected {'LOG_VERB'}{'11'}>11</option>
2805 <table width='100%'>
2807 <td class'base'><b> $Lang ::tr{'ovpn crypt options'}</b></td>
2810 <td width='20%'></td> <td width='30%'> </td><td width='25%'> </td><td width='25%'></td>
2812 <tr><td class='base'> $Lang ::tr{'ovpn ha'}</td>
2813 <td><select name='DAUTH'>
2814 <option value='whirlpool' $selected {'DAUTH'}{'whirlpool'}>Whirlpool (512 $Lang ::tr{'bit'})</option>
2815 <option value='SHA512' $selected {'DAUTH'}{'SHA512'}>SHA2 (512 $Lang ::tr{'bit'})</option>
2816 <option value='SHA384' $selected {'DAUTH'}{'SHA384'}>SHA2 (384 $Lang ::tr{'bit'})</option>
2817 <option value='SHA256' $selected {'DAUTH'}{'SHA256'}>SHA2 (256 $Lang ::tr{'bit'})</option>
2818 <option value='SHA1' $selected {'DAUTH'}{'SHA1'}>SHA1 (160 $Lang ::tr{'bit'})</option>
2821 <td> $Lang ::tr{'openvpn default'}: <span class="base">SHA1 (160 $Lang ::tr{'bit'})</span></td>
2825 <table width='100%'>
2827 <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='15%'></td><td width='35%'></td>
2831 <td class='base'>HMAC tls-auth</td>
2832 <td><input type='checkbox' name='TLSAUTH' $checked {'TLSAUTH'}{'on'} /></td>
2837 if ( - e
"/var/run/openvpn.pid" ){
2838 print " <br><b><font color='#990000'> $Lang ::tr{'attention'}:</b></font><br>
2839 $Lang ::tr{'server restart'}<br><br>
2842 <table width='100%'>
2845 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save-adv-options'}' disabled='disabled' /></td>
2846 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'cancel-adv-options'}' /></td>
2858 <table width='100%'>
2861 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save-adv-options'}' /></td>
2862 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'cancel-adv-options'}' /></td>
2870 & Header
:: closebox
();
2871 # print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
2872 & Header
:: closebigbox
();
2873 & Header
:: closepage
();
2877 # A.Marx CCD Add,delete or edit CCD net
2879 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ccd net' } ||
2880 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ccd add' } ||
2881 $cgiparams { 'ACTION' } eq "kill" ||
2882 $cgiparams { 'ACTION' } eq "edit" ||
2883 $cgiparams { 'ACTION' } eq 'editsave' ){
2884 & Header
:: showhttpheaders
();
2885 & Header
:: openpage
( $Lang :: tr
{ 'ccd net' }, 1 , '' );
2886 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2888 if ( $cgiparams { 'ACTION' } eq "kill" ){
2889 & delccdnet
( $cgiparams { 'net' });
2892 if ( $cgiparams { 'ACTION' } eq 'editsave' ){
2893 my ( $a , $b ) = split ( /\|/ , $cgiparams { 'ccdname' });
2894 if ( $a ne $b ){ & modccdnet
( $a , $b );}
2895 $cgiparams { 'ccdname' }= '' ;
2896 $cgiparams { 'ccdsubnet' }= '' ;
2899 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ccd add' }) {
2900 & addccdnet
( $cgiparams { 'ccdname' }, $cgiparams { 'ccdsubnet' });
2902 if ( $errormessage ) {
2903 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
2904 print "<class name='base'> $errormessage " ;
2905 print " </class>" ;
2906 & Header
:: closebox
();
2908 if ( $cgiparams { 'ACTION' } eq "edit" ){
2910 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd modify' });
2913 <table width='100%' border='0'>
2914 <tr><form method='post'>
2915 <td width='10%' nowrap='nowrap'> $Lang ::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value=' $cgiparams {'ccdname'}' /></td>
2916 <td width='8%'> $Lang ::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value=' $cgiparams {'ccdsubnet'}' readonly='readonly' /></td></tr>
2917 <tr><td colspan='4' align='right'><hr><input type='submit' value=' $Lang ::tr{'save'}' /><input type='hidden' name='ACTION' value='editsave'/>
2918 <input type='hidden' name='ccdname' value=' $cgiparams {'ccdname'}'/><input type='submit' value=' $Lang ::tr{'cancel'}' />
2923 & Header
:: closebox
();
2925 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd net' } );
2927 <table width='100%' border='0' cellpadding='0' cellspacing='1'>
2929 <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>
2934 if (! - e
"/var/run/openvpn.pid" ){
2935 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd add' });
2937 <table width='100%' border='0'>
2938 <tr><form method='post'>
2939 <td colspan='4'> $Lang ::tr{'ccd hint'}<br><br></td></tr>
2941 <td width='10%' nowrap='nwrap'> $Lang ::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value=' $cgiparams {'ccdname'}' /></td>
2942 <td width='8%'> $Lang ::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value=' $cgiparams {'ccdsubnet'}' /></td></tr>
2943 <tr><td colspan=4><hr /></td></tr><tr>
2944 <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>
2948 & Header
:: closebox
();
2950 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd net' } );
2951 if ( - e
"/var/run/openvpn.pid" ){
2952 print "<b> $Lang ::tr{'attention'}:</b><br>" ;
2953 print " $Lang ::tr{'ccd noaddnet'}<br><hr>" ;
2957 <table width='100%' cellpadding='0' cellspacing='1'>
2959 <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>
2964 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
2967 foreach my $key ( sort { uc ( $ccdconfhash { $a }[ 0 ]) cmp uc ( $ccdconfhash { $b }[ 0 ]) } keys %ccdconfhash ) {
2968 @ccdconf =( $ccdconfhash { $key }[ 0 ], $ccdconfhash { $key }[ 1 ]);
2970 my $ccdhosts = & hostsinnet
( $ccdconf [ 0 ]);
2971 if ( $count % 2 ){ print " <tr bgcolor=' $color {'color22'}'>" ;}
2972 else { print " <tr bgcolor=' $color {'color20'}'>" ;}
2973 print "<td> $ccdconf [0]</td><td align='center'> $ccdconf [1]</td><td align='center'> $ccdhosts /" .(& ccdmaxclients
( $ccdconf [ 1 ])+ 1 ). "</td><td>" ;
2975 <form method='post' />
2976 <input type='image' src='/images/edit.gif' align='middle' alt=' $Lang ::tr{'edit'}' title=' $Lang ::tr{'edit'}' />
2977 <input type='hidden' name='ACTION' value='edit'/>
2978 <input type='hidden' name='ccdname' value=' $ccdconf [0]' />
2979 <input type='hidden' name='ccdsubnet' value=' $ccdconf [1]' />
2981 <form method='post' />
2982 <td><input type='hidden' name='ACTION' value='kill'/>
2983 <input type='hidden' name='number' value=' $count ' />
2984 <input type='hidden' name='net' value=' $ccdconf [0]' />
2985 <input type='image' src='/images/delete.gif' align='middle' alt=' $Lang ::tr{'remove'}' title=' $Lang ::tr{'remove'}' /></form></td></tr>
2989 print "</table></form>" ;
2990 & Header
:: closebox
();
2991 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2992 & Header
:: closebigbox
();
2993 & Header
:: closepage
();
2999 ### Openvpn Connections Statistics
3001 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ovpn con stat' }) {
3002 & Header
:: showhttpheaders
();
3003 & Header
:: openpage
( $Lang :: tr
{ 'ovpn con stat' }, 1 , '' );
3004 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
3005 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ovpn con stat' });
3008 # <td><b>$Lang::tr{'protocol'}</b></td>
3009 # protocol temp removed
3011 <table width='100%' cellpadding='2' cellspacing='0' class='tbl'>
3013 <th><b> $Lang ::tr{'common name'}</b></th>
3014 <th><b> $Lang ::tr{'real address'}</b></th>
3015 <th><b> $Lang ::tr{'virtual address'}</b></th>
3016 <th><b> $Lang ::tr{'loged in at'}</b></th>
3017 <th><b> $Lang ::tr{'bytes sent'}</b></th>
3018 <th><b> $Lang ::tr{'bytes received'}</b></th>
3019 <th><b> $Lang ::tr{'last activity'}</b></th>
3023 my $filename = "/var/run/ovpnserver.log" ;
3024 open ( FILE
, $filename ) or die 'Unable to open config file.' ;
3025 my @current = < FILE
>;
3034 my %userlookup = ();
3035 foreach my $line ( @current )
3038 if ( $line =~ /^Updated,(.+)/ ){
3039 @match = split ( /^Updated,(.+)/ , $line );
3040 $status = $match [ 1 ];
3043 if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ ) {
3044 @match = split ( m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ , $line );
3045 if ( $match [ 1 ] ne "Common Name" ) {
3047 $userlookup { $match [ 2 ]} = $uid ;
3048 $users [ $uid ]{ 'CommonName' } = $match [ 1 ];
3049 $users [ $uid ]{ 'RealAddress' } = $match [ 2 ];
3050 $users [ $uid ]{ 'BytesReceived' } = & sizeformat
( $match [ 3 ]);
3051 $users [ $uid ]{ 'BytesSent' } = & sizeformat
( $match [ 4 ]);
3052 $users [ $uid ]{ 'Since' } = $match [ 5 ];
3053 $users [ $uid ]{ 'Proto' } = $proto ;
3057 if ( $line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/ ) {
3058 @match = split ( m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/ , $line );
3059 if ( $match [ 1 ] ne "Virtual Address" ) {
3060 $address = $match [ 3 ];
3061 #find the uid in the lookup table
3062 $uid = $userlookup { $address };
3063 $users [ $uid ]{ 'VirtualAddress' } = $match [ 1 ];
3064 $users [ $uid ]{ 'LastRef' } = $match [ 4 ];
3070 for ( my $idx = 1 ; $idx <= $user2 ; $idx ++){
3073 $col = "bgcolor=' $color {'color22'}'" ;
3076 $col = "bgcolor=' $color {'color20'}'" ;
3078 print "<td align='left' $col > $users [ $idx -1]{'CommonName'}</td>" ;
3079 print "<td align='left' $col > $users [ $idx -1]{'RealAddress'}</td>" ;
3080 print "<td align='left' $col > $users [ $idx -1]{'VirtualAddress'}</td>" ;
3081 print "<td align='left' $col > $users [ $idx -1]{'Since'}</td>" ;
3082 print "<td align='left' $col > $users [ $idx -1]{'BytesSent'}</td>" ;
3083 print "<td align='left' $col > $users [ $idx -1]{'BytesReceived'}</td>" ;
3084 print "<td align='left' $col > $users [ $idx -1]{'LastRef'}</td>" ;
3090 <table width='100%' border='0' cellpadding='2' cellspacing='0'>
3095 <tr><td align='center' > $Lang ::tr{'the statistics were last updated at'} <b> $status </b></td></tr>
3099 & Header
:: closebox
();
3100 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
3101 & Header
:: closebigbox
();
3102 & Header
:: closepage
();
3106 ### Download Certificate
3108 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
3109 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3111 if ( - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
3112 print "Content-Disposition: filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \r\n " ;
3113 print "Content-Type: application/octet-stream \r\n\r\n " ;
3114 print `/bin/cat ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
3119 ### Enable/Disable connection
3122 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
3124 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
3125 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3127 if ( $confighash { $cgiparams { 'KEY' }}) {
3128 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
3129 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
3130 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3131 #&writeserverconf();
3132 # if ($vpnsettings{'ENABLED'} eq 'on' ||
3133 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
3134 # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
3137 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
3138 # if ($vpnsettings{'ENABLED'} eq 'on' ||
3139 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
3140 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
3142 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3143 #&writeserverconf();
3146 $errormessage = $Lang :: tr
{ 'invalid key' };
3150 ### Restart connection
3152 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
3153 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
3154 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3156 if ( $confighash { $cgiparams { 'KEY' }}) {
3157 # if ($vpnsettings{'ENABLED'} eq 'on' ||
3158 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
3159 # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
3162 $errormessage = $Lang :: tr
{ 'invalid key' };
3169 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
3170 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
3171 & Header
:: showhttpheaders
();
3172 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
3173 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
3174 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'connection type' });
3176 if ( - s
"${General::swroot}/ovpn/settings" ) {
3179 <b> $Lang ::tr{'connection type'}:</b><br />
3180 <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data">
3181 <tr><td><input type='radio' name='TYPE' value='host' checked /></td>
3182 <td class='base'> $Lang ::tr{'host to net vpn'}</td></tr>
3183 <tr><td><input type='radio' name='TYPE' value='net' /></td>
3184 <td class='base'> $Lang ::tr{'net to net vpn'}</td></tr>
3185 <tr><td><input type='radio' name='TYPE' value='net2net' /></td>
3186 <td class='base'> $Lang ::tr{'net to net vpn'} (Upload Client Package)</td></tr>
3187 <tr><td> </td><td class='base'><input type='file' name='FH' size='30'></td></tr>
3188 <tr><td> </td><td>Import Connection Name</td></tr>
3189 <tr><td> </td><td class='base'><input type='text' name='n2nname' size='30'> $Lang ::tr{'openvpn default'}: Client Packagename</td></tr>
3190 <tr><td colspan='3'><hr /></td></tr>
3191 <tr><td align='right' colspan='3'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td></tr>
3199 <b> $Lang ::tr{'connection type'}:</b><br />
3200 <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data">
3201 <tr><td><input type='radio' name='TYPE' value='host' checked /></td> <td class='base'> $Lang ::tr{'host to net vpn'}</td></tr>
3202 <tr><td align='right' colspan'3'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td></tr>
3209 & Header
:: closebox
();
3210 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
3211 & Header
:: closebigbox
();
3212 & Header
:: closepage
();
3219 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) && ( $cgiparams { 'TYPE' } eq 'net2net' )){
3223 my $uplconffilename = '' ;
3224 my $uplconffilename2 = '' ;
3225 my $uplp12name = '' ;
3226 my $uplp12name2 = '' ;
3233 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3235 # Check if a file is uploaded
3237 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
3238 $errormessage = $Lang :: tr
{ 'there was no file upload' };
3242 # Move uploaded IPfire n2n package to temporary file
3244 ( my $fh , my $filename ) = tempfile
( );
3245 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
3250 my $zip = Archive
:: Zip
-> new ();
3251 my $zipName = $filename ;
3252 my $status = $zip -> read ( $zipName );
3253 if ( $status != AZ_OK
) {
3254 $errormessage = "Read of $zipName failed \n " ;
3258 my $tempdir = tempdir
( CLEANUP
=> 1 );
3259 my @files = $zip -> memberNames ();
3261 $zip -> extractMemberWithoutPaths ( $_ , " $tempdir / $_ " );
3263 my $countfiles = @files ;
3265 # Check if we have not more then 2 files
3267 if ( $countfiles == 2 ){
3269 if ( $_ =~ /.conf$/ ){
3270 $uplconffilename = $_ ;
3272 if ( $_ =~ /.p12$/ ){
3276 if (( $uplconffilename eq '' ) || ( $uplp12name eq '' )){
3277 $errormessage = "Either no *.conf or no *.p12 file found \n " ;
3281 open ( FILE
, " $tempdir / $uplconffilename " ) or die 'Unable to open*.conf file' ;
3282 @firen2nconf = < FILE
>;
3284 chomp ( @firen2nconf );
3287 $errormessage = "Filecount does not match only 2 files are allowed \n " ;
3295 if ( $cgiparams { 'n2nname' } ne '' ){
3297 $uplconffilename2 = " $cgiparams {'n2nname'}.conf" ;
3298 $uplp12name2 = " $cgiparams {'n2nname'}.p12" ;
3299 $n2nname [ 0 ] = $cgiparams { 'n2nname' };
3300 my @n2nname2 = split ( /\./ , $uplconffilename );
3301 $n2nname2 [ 0 ] =~ s/\n|\r//g ;
3302 my $input1 = "${General::swroot}/ovpn/certs/ $uplp12name " ;
3303 my $output1 = "${General::swroot}/ovpn/certs/ $uplp12name2 " ;
3304 my $input2 = " $n2nname2 [0]n2n" ;
3305 my $output2 = " $n2nname [0]n2n" ;
3306 my $filename = " $tempdir / $uplconffilename " ;
3307 open ( FILE
, "< $filename " ) or die 'Unable to open config file.' ;
3308 my @current = < FILE
>;
3310 foreach ( @current ) { s/$input1/$output1/g ;}
3311 foreach ( @current ) { s/$input2/$output2/g ;}
3312 open ( OUT
, "> $filename " ) || die 'Unable to open config file.' ;
3317 $uplconffilename2 = $uplconffilename ;
3318 $uplp12name2 = $uplp12name ;
3319 @n2nname = split ( /\./ , $uplconffilename );
3320 $n2nname [ 0 ] =~ s/\n|\r//g ;
3322 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
3323 unless (- d
"${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" , 0770 or die "Unable to create dir $!" ;}
3325 #Add collectd settings to configfile
3326 open ( FILE
, ">> $tempdir / $uplconffilename " ) or die 'Unable to open config file.' ;
3327 print FILE
"# Logfile \n " ;
3328 print FILE
"status-version 1 \n " ;
3329 print FILE
"status /var/run/openvpn/ $n2nname [0]-n2n 10 \n " ;
3332 move
( " $tempdir / $uplconffilename " , "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $uplconffilename2 " );
3335 $errormessage = "*.conf move failed: $!" ;
3340 move
( " $tempdir / $uplp12name " , "${General::swroot}/ovpn/certs/ $uplp12name2 " );
3341 chmod 0600 , "${General::swroot}/ovpn/certs/ $uplp12name " ;
3344 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
3353 my @n2nmtudisc = split ( / / , ( grep { /^mtu-disc/ } @firen2nconf )[ 0 ]);
3354 my @n2nproto2 = split ( / / , ( grep { /^proto/ } @firen2nconf )[ 0 ]);
3355 my @n2nproto = split ( /-/ , $n2nproto2 [ 1 ]);
3356 my @n2nport = split ( / / , ( grep { /^port/ } @firen2nconf )[ 0 ]);
3357 my @n2ntunmtu = split ( / / , ( grep { /^tun-mtu/ } @firen2nconf )[ 0 ]);
3358 my @n2ncomplzo = grep { /^comp-lzo/ } @firen2nconf ;
3359 if ( $n2ncomplzo [ 0 ] =~ /comp-lzo/ ){ $complzoactive = "on" ;} else { $complzoactive = "off" ;}
3360 my @n2nmssfix = grep { /^mssfix/ } @firen2nconf ;
3361 if ( $n2nmssfix [ 0 ] =~ /mssfix/ ){ $mssfixactive = "on" ;} else { $mssfixactive = "off" ;}
3362 #my @n2nmssfix = split(/ /, (grep { /^mssfix/ } @firen2nconf)[0]);
3363 my @n2nfragment = split ( / / , ( grep { /^fragment/ } @firen2nconf )[ 0 ]);
3364 my @n2nremote = split ( / / , ( grep { /^remote/ } @firen2nconf )[ 0 ]);
3365 my @n2novpnsuball = split ( / / , ( grep { /^ifconfig/ } @firen2nconf )[ 0 ]);
3366 my @n2novpnsub = split ( /\./ , $n2novpnsuball [ 1 ]);
3367 my @n2nremsub = split ( / / , ( grep { /^route/ } @firen2nconf )[ 0 ]);
3368 my @n2nmgmt = split ( / / , ( grep { /^management/ } @firen2nconf )[ 0 ]);
3369 my @n2nlocalsub = split ( / / , ( grep { /^# remsub/ } @firen2nconf )[ 0 ]);
3370 my @n2ncipher = split ( / / , ( grep { /^cipher/ } @firen2nconf )[ 0 ]);
3371 my @n2nauth = split ( / / , ( grep { /^auth/ } @firen2nconf )[ 0 ]);;
3374 # m.a.d delete CR and LF from arrays for this chomp doesnt work
3377 $n2nremote [ 1 ] =~ s/\n|\r//g ;
3378 $n2novpnsub [ 0 ] =~ s/\n|\r//g ;
3379 $n2novpnsub [ 1 ] =~ s/\n|\r//g ;
3380 $n2novpnsub [ 2 ] =~ s/\n|\r//g ;
3381 $n2nproto [ 0 ] =~ s/\n|\r//g ;
3382 $n2nport [ 1 ] =~ s/\n|\r//g ;
3383 $n2ntunmtu [ 1 ] =~ s/\n|\r//g ;
3384 $n2nremsub [ 1 ] =~ s/\n|\r//g ;
3385 $n2nremsub [ 2 ] =~ s/\n|\r//g ;
3386 $n2nlocalsub [ 2 ] =~ s/\n|\r//g ;
3387 $n2nfragment [ 1 ] =~ s/\n|\r//g ;
3388 $n2nmgmt [ 2 ] =~ s/\n|\r//g ;
3389 $n2nmtudisc [ 1 ] =~ s/\n|\r//g ;
3390 $n2ncipher [ 1 ] =~ s/\n|\r//g ;
3391 $n2nauth [ 1 ] =~ s/\n|\r//g ;
3392 chomp ( $complzoactive );
3393 chomp ( $mssfixactive );
3400 # Check if there is no other entry with this name
3403 foreach my $dkey ( keys %confighash ) {
3404 if ( $confighash { $dkey }[ 1 ] eq $n2nname [ 0 ]) {
3405 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
3406 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
3407 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
3408 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
3414 # Check if OpenVPN Subnet is valid
3417 foreach my $dkey ( keys %confighash ) {
3418 if ( $confighash { $dkey }[ 27 ] eq " $n2novpnsub [0]. $n2novpnsub [1]. $n2novpnsub [2].0/255.255.255.0" ) {
3419 $errormessage = 'The OpenVPN Subnet is already in use' ;
3420 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
3421 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
3422 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
3428 # Check if Dest Port is vaild
3431 foreach my $dkey ( keys %confighash ) {
3432 if ( $confighash { $dkey }[ 29 ] eq $n2nport [ 1 ] ) {
3433 $errormessage = 'The OpenVPN Port is already in use' ;
3434 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
3435 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
3436 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
3443 $key = & General
:: findhasharraykey
( \
%confighash );
3445 foreach my $i ( 0 .. 42 ) { $confighash { $key }[ $i ] = "" ;}
3447 $confighash { $key }[ 0 ] = 'off' ;
3448 $confighash { $key }[ 1 ] = $n2nname [ 0 ];
3449 $confighash { $key }[ 2 ] = $n2nname [ 0 ];
3450 $confighash { $key }[ 3 ] = 'net' ;
3451 $confighash { $key }[ 4 ] = 'cert' ;
3452 $confighash { $key }[ 6 ] = 'client' ;
3453 $confighash { $key }[ 8 ] = $n2nlocalsub [ 2 ];
3454 $confighash { $key }[ 10 ] = $n2nremote [ 1 ];
3455 $confighash { $key }[ 11 ] = " $n2nremsub [1]/ $n2nremsub [2]" ;
3456 $confighash { $key }[ 22 ] = $n2nmgmt [ 2 ];
3457 $confighash { $key }[ 23 ] = $mssfixactive ;
3458 $confighash { $key }[ 24 ] = $n2nfragment [ 1 ];
3459 $confighash { $key }[ 25 ] = 'IPFire n2n Client' ;
3460 $confighash { $key }[ 26 ] = 'red' ;
3461 $confighash { $key }[ 27 ] = " $n2novpnsub [0]. $n2novpnsub [1]. $n2novpnsub [2].0/255.255.255.0" ;
3462 $confighash { $key }[ 28 ] = $n2nproto [ 0 ];
3463 $confighash { $key }[ 29 ] = $n2nport [ 1 ];
3464 $confighash { $key }[ 30 ] = $complzoactive ;
3465 $confighash { $key }[ 31 ] = $n2ntunmtu [ 1 ];
3466 $confighash { $key }[ 38 ] = $n2nmtudisc [ 1 ];
3467 $confighash { $key }[ 39 ] = $n2nauth [ 1 ];
3468 $confighash { $key }[ 40 ] = $n2ncipher [ 1 ];
3469 $confighash { $key }[ 41 ] = 'disabled' ;
3471 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3475 & Header
:: showhttpheaders
();
3476 & Header
:: openpage
( 'Validate imported configuration' , 1 , '' );
3477 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
3478 if ( $errormessage ) {
3479 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
3480 print "<class name='base'> $errormessage " ;
3481 print " </class>" ;
3482 & Header
:: closebox
();
3486 & Header
:: openbox
( '100%' , 'LEFT' , 'import ipfire net2net config' );
3488 if ( $errormessage eq '' ){
3490 <!-- ipfire net2net config gui -->
3491 <table width='100%'>
3492 <tr><td width='25%'> </td><td width='25%'> </td></tr>
3493 <tr><td class='boldbase'> $Lang ::tr{'name'}:</td><td><b> $n2nname [0]</b></td></tr>
3494 <tr><td> </td><td> </td></tr>
3495 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'Act as'}</td><td><b> $confighash { $key }[6]</b></td></tr>
3496 <tr><td class='boldbase' nowrap='nowrap'>Remote Host </td><td><b> $confighash { $key }[10]</b></td></tr>
3497 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'}</td><td><b> $confighash { $key }[8]</b></td></tr>
3498 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'}:</td><td><b> $confighash { $key }[11]</b></td></tr>
3499 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn subnet'}</td><td><b> $confighash { $key }[27]</b></td></tr>
3500 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td><td><b> $confighash { $key }[28]</b></td></tr>
3501 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'destination port'}:</td><td><b> $confighash { $key }[29]</b></td></tr>
3502 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'}</td><td><b> $confighash { $key }[30]</b></td></tr>
3503 <tr><td class='boldbase' nowrap='nowrap'>MSSFIX:</td><td><b> $confighash { $key }[23]</b></td></tr>
3504 <tr><td class='boldbase' nowrap='nowrap'>Fragment:</td><td><b> $confighash { $key }[24]</b></td></tr>
3505 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'}</td><td><b> $confighash { $key }[31]</b></td></tr>
3506 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn mtu-disc'}</td><td><b> $confighash { $key }[38]</b></td></tr>
3507 <tr><td class='boldbase' nowrap='nowrap'>Management Port </td><td><b> $confighash { $key }[22]</b></td></tr>
3508 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn hmac'}:</td><td><b> $confighash { $key }[39]</b></td></tr>
3509 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'cipher'}</td><td><b> $confighash { $key }[40]</b></td></tr>
3510 <tr><td> </td><td> </td></tr>
3514 & Header
:: closebox
();
3517 if ( $errormessage ) {
3518 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
3520 print "<div align='center'><form method='post' ENCTYPE='multipart/form-data'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />" ;
3521 print "<input type='hidden' name='TYPE' value='net2netakn' />" ;
3522 print "<input type='hidden' name='KEY' value=' $key ' />" ;
3523 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
3525 & Header
:: closebigbox
();
3526 & Header
:: closepage
();
3531 ### Accept IPFire n2n Package Settings
3534 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) && ( $cgiparams { 'TYPE' } eq 'net2netakn' )){
3537 ### Discard and Rollback IPFire n2n Package Settings
3540 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'cancel' }) && ( $cgiparams { 'TYPE' } eq 'net2netakn' )){
3542 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3544 if ( $confighash { $cgiparams { 'KEY' }}) {
3546 my $conffile = glob ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]/ $confighash { $cgiparams {'KEY'}}[1].conf" );
3547 my $certfile = glob ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
3548 unlink ( $certfile ) or die "Removing $certfile fail: $!" ;
3549 unlink ( $conffile ) or die "Removing $conffile fail: $!" ;
3550 rmdir ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]" ) || die "Kann Verzeichnis nicht loeschen: $!" ;
3551 delete $confighash { $cgiparams { 'KEY' }};
3552 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3555 $errormessage = $Lang :: tr
{ 'invalid key' };
3565 ### Adding a new connection
3567 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
3568 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
3569 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
3571 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
3572 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
3573 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3575 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
3576 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
3577 $errormessage = $Lang :: tr
{ 'invalid key' };
3580 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
3581 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
3582 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
3583 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
3584 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
3585 $cgiparams { 'SIDE' } = $confighash { $cgiparams { 'KEY' }}[ 6 ];
3586 $cgiparams { 'LOCAL_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 8 ];
3587 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
3588 $cgiparams { 'REMOTE_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 11 ];
3589 $cgiparams { 'OVPN_MGMT' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
3590 $cgiparams { 'MSSFIX' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
3591 $cgiparams { 'FRAGMENT' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
3592 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
3593 $cgiparams { 'INTERFACE' } = $confighash { $cgiparams { 'KEY' }}[ 26 ];
3594 $cgiparams { 'OVPN_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
3595 $cgiparams { 'PROTOCOL' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
3596 $cgiparams { 'DEST_PORT' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
3597 $cgiparams { 'COMPLZO' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
3598 $cgiparams { 'MTU' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
3599 $cgiparams { 'CHECK1' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
3600 $name = $cgiparams { 'CHECK1' } ;
3601 $cgiparams { $name } = $confighash { $cgiparams { 'KEY' }}[ 33 ];
3602 $cgiparams { 'RG' } = $confighash { $cgiparams { 'KEY' }}[ 34 ];
3603 $cgiparams { 'CCD_DNS1' } = $confighash { $cgiparams { 'KEY' }}[ 35 ];
3604 $cgiparams { 'CCD_DNS2' } = $confighash { $cgiparams { 'KEY' }}[ 36 ];
3605 $cgiparams { 'CCD_WINS' } = $confighash { $cgiparams { 'KEY' }}[ 37 ];
3606 $cgiparams { 'PMTU_DISCOVERY' } = $confighash { $cgiparams { 'KEY' }}[ 38 ];
3607 $cgiparams { 'DAUTH' } = $confighash { $cgiparams { 'KEY' }}[ 39 ];
3608 $cgiparams { 'DCIPHER' } = $confighash { $cgiparams { 'KEY' }}[ 40 ];
3609 $cgiparams { 'TLSAUTH' } = $confighash { $cgiparams { 'KEY' }}[ 41 ];
3610 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
3611 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
3613 #A.Marx CCD check iroute field and convert it to decimal
3614 if ( $cgiparams { 'TYPE' } eq 'host' ) {
3616 my %ccdroutehash =();
3620 if ( $cgiparams { 'IR' } ne '' ){
3621 @temp = split ( " \n " , $cgiparams { 'IR' });
3622 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3624 foreach my $key ( keys %ccdroutehash ) {
3625 if ( $ccdroutehash { $key }[ 0 ] eq $cgiparams { 'NAME' }) {
3627 delete $ccdroutehash { $key };
3629 $keypoint = & General
:: findhasharraykey
( \
%ccdroutehash );
3632 $ccdroutehash { $keypoint }[ 0 ]= $cgiparams { 'NAME' };
3635 foreach $val ( @temp ){
3638 #check if iroute exists in ccdroute or if new iroute is part of an existing one
3639 foreach my $key ( keys %ccdroutehash ) {
3640 foreach my $oldiroute ( 1 .. $ #{$ccdroutehash{$key}}){
3641 if ( $ccdroutehash { $key }[ $oldiroute ] eq " $val " ) {
3642 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err irouteexist' };
3645 my ( $ip1 , $cidr1 ) = split ( /\/ /, $val );
3646 $ip1 = & General
:: getnetworkip
( $ip1 ,& General
:: iporsubtocidr
( $cidr1 ));
3647 my ( $ip2 , $cidr2 ) = split ( /\/ /, $ccdroutehash { $key }[ $oldiroute ]);
3648 if (& General
:: IpInSubnet
( $ip1 , $ip2 , $cidr2 )){
3649 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err irouteexist' };
3655 if (!& General
:: validipandmask
( $val )){
3656 $errormessage = $errormessage . "Route " . $Lang :: tr
{ 'ccd invalid' }. " ( $val )" ;
3659 ( $ip , $cidr ) = split ( /\/ /, $val );
3660 $ip =& General
:: getnetworkip
( $ip ,& General
:: iporsubtocidr
( $cidr ));
3661 $cidr =& General
:: iporsubtodec
( $cidr );
3662 $ccdroutehash { $keypoint }[ $i ] = $ip . "/" . $cidr ;
3666 #check for existing network IP's
3667 if (& General
:: IpInSubnet
( $ip , $netsettings { GREEN_NETADDRESS
}, $netsettings { GREEN_NETMASK
}) && $netsettings { GREEN_NETADDRESS
} ne '0.0.0.0' )
3669 $errormessage = $Lang :: tr
{ 'ccd err green' };
3671 } elsif (& General
:: IpInSubnet
( $ip , $netsettings { RED_NETADDRESS
}, $netsettings { RED_NETMASK
}) && $netsettings { RED_NETADDRESS
} ne '0.0.0.0' )
3673 $errormessage = $Lang :: tr
{ 'ccd err red' };
3675 } elsif (& General
:: IpInSubnet
( $ip , $netsettings { BLUE_NETADDRESS
}, $netsettings { BLUE_NETMASK
}) && $netsettings { BLUE_NETADDRESS
} ne '0.0.0.0' && $netsettings { BLUE_NETADDRESS
} gt '' )
3677 $errormessage = $Lang :: tr
{ 'ccd err blue' };
3679 } elsif (& General
:: IpInSubnet
( $ip , $netsettings { ORANGE_NETADDRESS
}, $netsettings { ORANGE_NETMASK
}) && $netsettings { ORANGE_NETADDRESS
} ne '0.0.0.0' && $netsettings { ORANGE_NETADDRESS
} gt '' )
3681 $errormessage = $Lang :: tr
{ 'ccd err orange' };
3685 if (& General
:: validipandmask
( $val )){
3686 $ccdroutehash { $keypoint }[ $i ] = $ip . "/" . $cidr ;
3688 $errormessage = $errormessage . "Route " . $Lang :: tr
{ 'ccd invalid' }. " ( $ip / $cidr )" ;
3693 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3696 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3697 foreach my $key ( keys %ccdroutehash ) {
3698 if ( $ccdroutehash { $key }[ 0 ] eq $cgiparams { 'NAME' }) {
3699 delete $ccdroutehash { $key };
3700 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3706 #check route field and convert it to decimal
3709 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
3711 foreach my $key ( keys %ccdroute2hash ) {
3712 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }) {
3714 delete $ccdroute2hash { $key };
3716 $keypoint = & General
:: findhasharraykey
( \
%ccdroute2hash );
3717 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3721 $ccdroute2hash { $keypoint }[ 0 ]= $cgiparams { 'NAME' };
3722 if ( $cgiparams { 'IFROUTE' } eq '' ){ $cgiparams { 'IFROUTE' } = $Lang :: tr
{ 'ccd none' };}
3723 @temp = split ( /\|/ , $cgiparams { 'IFROUTE' });
3725 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%ownnet );
3726 foreach $val ( @temp ){
3729 if ( $val eq $Lang :: tr
{ 'green' })
3731 $val = $ownnet { GREEN_NETADDRESS
}. "/" . $ownnet { GREEN_NETMASK
};
3733 if ( $val eq $Lang :: tr
{ 'blue' })
3735 $val = $ownnet { BLUE_NETADDRESS
}. "/" . $ownnet { BLUE_NETMASK
};
3737 if ( $val eq $Lang :: tr
{ 'orange' })
3739 $val = $ownnet { ORANGE_NETADDRESS
}. "/" . $ownnet { ORANGE_NETMASK
};
3741 my ( $ip , $cidr ) = split ( /\/ /, $val );
3743 if ( $val ne $Lang :: tr
{ 'ccd none' })
3745 if (! & check_routes_push
( $val )){ $errormessage = $errormessage . "Route $val " . $Lang :: tr
{ 'ccd err routeovpn2' }. " ( $val )" ; goto VPNCONF_ERROR
;}
3746 if (! & check_ccdroute
( $val )){ $errormessage = $errormessage . "<br>Route $val " . $Lang :: tr
{ 'ccd err inuse' }. " ( $val )" ; goto VPNCONF_ERROR
;}
3747 if (! & check_ccdconf
( $val )){ $errormessage = $errormessage . "<br>Route $val " . $Lang :: tr
{ 'ccd err routeovpn' }. " ( $val )" ; goto VPNCONF_ERROR
;}
3748 if (& General
:: validipandmask
( $val )){
3749 $val = $ip . "/" .& General
:: iporsubtodec
( $cidr );
3750 $ccdroute2hash { $keypoint }[ $i ] = $val ;
3752 $errormessage = $errormessage . "Route " . $Lang :: tr
{ 'ccd invalid' }. " ( $val )" ;
3756 $ccdroute2hash { $keypoint }[ $i ]= '' ;
3760 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
3763 if ( $cgiparams { 'CCD_DNS1' } ne '' && ! & General
:: validip
( $cgiparams { 'CCD_DNS1' })) {
3764 $errormessage = $errormessage . "<br>" . $Lang :: tr
{ 'invalid input for dhcp dns' }. " 1" ;
3768 if ( $cgiparams { 'CCD_DNS2' } ne '' && ! & General
:: validip
( $cgiparams { 'CCD_DNS2' })) {
3769 $errormessage = $errormessage . "<br>" . $Lang :: tr
{ 'invalid input for dhcp dns' }. " 2" ;
3773 if ( $cgiparams { 'CCD_WINS' } ne '' && ! & General
:: validip
( $cgiparams { 'CCD_WINS' })) {
3774 $errormessage = $errormessage . "<br>" . $Lang :: tr
{ 'invalid input for dhcp wins' };
3782 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
3783 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
3784 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3785 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3786 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3792 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
3793 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
3794 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3795 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3796 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3801 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
3802 $errormessage = $Lang :: tr
{ 'name is invalid' };
3803 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3804 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3805 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3810 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
3811 $errormessage = $Lang :: tr
{ 'name too long' };
3812 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3813 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3814 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3823 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3824 if ( $cgiparams { 'DEST_PORT' } eq $vpnsettings { 'DDEST_PORT' }) {
3825 $errormessage = $Lang :: tr
{ 'openvpn destination port used' };
3826 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3827 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3831 foreach my $key ( sort keys %confighash ){
3832 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 ])){
3833 $errormessage = $Lang :: tr
{ 'openvpn destination port used' };
3834 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3835 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3839 if ( $cgiparams { 'DEST_PORT' } eq '' ) {
3840 $errormessage = $Lang :: tr
{ 'invalid port' };
3841 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3842 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3846 # Check if the input for the transfer net is valid.
3847 if (!& General
:: validipandmask
( $cgiparams { 'OVPN_SUBNET' })){
3848 $errormessage = $Lang :: tr
{ 'ccd err invalidnet' };
3849 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3850 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3854 if ( $cgiparams { 'OVPN_SUBNET' } eq $vpnsettings { 'DOVPN_SUBNET' }) {
3855 $errormessage = $Lang :: tr
{ 'openvpn subnet is used' };
3856 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3857 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3861 if (( $cgiparams { 'PROTOCOL' } eq 'tcp' ) && ( $cgiparams { 'MSSFIX' } eq 'on' )) {
3862 $errormessage = $Lang :: tr
{ 'openvpn mssfix allowed with udp' };
3863 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3864 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3868 if (( $cgiparams { 'PROTOCOL' } eq 'tcp' ) && ( $cgiparams { 'FRAGMENT' } ne '' )) {
3869 $errormessage = $Lang :: tr
{ 'openvpn fragment allowed with udp' };
3870 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3871 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3875 if ( $cgiparams { 'PMTU_DISCOVERY' } ne 'off' ) {
3876 if (( $cgiparams { 'FRAGMENT' } ne '' ) || ( $cgiparams { 'MSSFIX' } eq 'on' )) {
3877 $errormessage = $Lang :: tr
{ 'ovpn mtu-disc with mssfix or fragment' };
3878 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3879 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3884 if (( $cgiparams { 'PMTU_DISCOVERY' } ne 'off' ) && ( $cgiparams { 'MTU' } ne '1500' )) {
3885 $errormessage = $Lang :: tr
{ 'ovpn mtu-disc and mtu not 1500' };
3886 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3887 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3891 if ( & validdotmask
( $cgiparams { 'LOCAL_SUBNET' })) {
3892 $errormessage = $Lang :: tr
{ 'openvpn prefix local subnet' };
3893 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3894 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3898 if ( & validdotmask
( $cgiparams { 'OVPN_SUBNET' })) {
3899 $errormessage = $Lang :: tr
{ 'openvpn prefix openvpn subnet' };
3900 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3901 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3905 if ( & validdotmask
( $cgiparams { 'REMOTE_SUBNET' })) {
3906 $errormessage = $Lang :: tr
{ 'openvpn prefix remote subnet' };
3907 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3908 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3912 if ( $cgiparams { 'DEST_PORT' } <= 1023 ) {
3913 $errormessage = $Lang :: tr
{ 'ovpn port in root range' };
3914 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3915 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3919 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) {
3920 $cgiparams { 'OVPN_MGMT' } = $cgiparams { 'DEST_PORT' };
3923 if ( $cgiparams { 'OVPN_MGMT' } <= 1023 ) {
3924 $errormessage = $Lang :: tr
{ 'ovpn mgmt in root range' };
3925 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3926 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3929 #Check if remote subnet is used elsewhere
3930 my ( $n2nip , $n2nsub )= split ( "/" , $cgiparams { 'REMOTE_SUBNET' });
3931 $warnmessage =& General
:: checksubnets
( '' , $n2nip , 'ovpn' );
3933 $warnmessage = $Lang :: tr
{ 'remote subnet' }. " ( $cgiparams {'REMOTE_SUBNET'}) <br>" . $warnmessage ;
3937 # if (($cgiparams{'TYPE'} eq 'net') && ($cgiparams{'SIDE'} !~ /^(left|right)$/)) {
3938 # $errormessage = $Lang::tr{'ipfire side is invalid'};
3939 # goto VPNCONF_ERROR;
3942 # Check if there is no other entry with this name
3943 if (! $cgiparams { 'KEY' }) {
3944 foreach my $key ( keys %confighash ) {
3945 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
3946 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
3947 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3948 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3949 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3956 # Check if a remote host/IP has been set for the client.
3957 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3958 if ( $cgiparams { 'SIDE' } ne 'server' && $cgiparams { 'REMOTE' } eq '' ) {
3959 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
3961 # Check if this is a N2N connection and drop temporary config.
3962 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3963 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3968 # Check if a remote host/IP has been configured - the field can be empty on the server side.
3969 if ( $cgiparams { 'REMOTE' } ne '' ) {
3970 # Check if the given IP is valid - otherwise check if it is a valid domain.
3971 if (! & General
:: validip
( $cgiparams { 'REMOTE' })) {
3972 # Check for a valid domain.
3973 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
3974 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
3976 # Check if this is a N2N connection and drop temporary config.
3977 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3978 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3986 if ( $cgiparams { 'TYPE' } ne 'host' ) {
3987 unless (& General
:: validipandmask
( $cgiparams { 'LOCAL_SUBNET' })) {
3988 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
3989 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3990 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3991 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3993 goto VPNCONF_ERROR
;}
3995 # Check if there is no other entry without IP-address and PSK
3996 if ( $cgiparams { 'REMOTE' } eq '' ) {
3997 foreach my $key ( keys %confighash ) {
3998 if (( $cgiparams { 'KEY' } ne $key ) &&
3999 ( $confighash { $key }[ 4 ] eq 'psk' || $cgiparams { 'AUTH' } eq 'psk' ) &&
4000 $confighash { $key }[ 10 ] eq '' ) {
4001 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
4006 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! & General
:: validipandmask
( $cgiparams { 'REMOTE_SUBNET' }))) {
4007 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
4008 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
4009 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 if ( ref ( $cgiparams { 'FH' }) ne '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 system ( '/usr/bin/openssl' , 'ca' , '-days' , " $cgiparams {'DAYS_VALID'}" ,
4052 '-batch' , '-notext' ,
4054 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
4055 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
4057 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
4059 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
4060 & newcleanssldatabase
();
4064 & deletebackupcert
();
4067 my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem` ;
4068 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
4070 $temp =~ s
+/ Email
+, E
+;
4071 $temp =~ s/ ST=/ S=/ ;
4072 $cgiparams { 'CERT_NAME' } = $temp ;
4073 $cgiparams { 'CERT_NAME' } =~ s/,//g ;
4074 $cgiparams { 'CERT_NAME' } =~ s/\'//g ;
4075 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
4076 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
4079 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
4080 if ( $cgiparams { 'KEY' }) {
4081 $errormessage = $Lang :: tr
{ 'cant change certificates' };
4084 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
4085 $errormessage = $Lang :: tr
{ 'there was no file upload' };
4088 # Move uploaded certificate to a temporary file
4089 ( my $fh , my $filename ) = tempfile
( );
4090 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
4095 # Verify the certificate has a valid CA and move it
4097 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/cacert.pem $filename ` ;
4098 if ( $test =~ /: OK/ ) {
4101 foreach my $key ( keys %cahash ) {
4102 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/ $cahash { $key }[0]cert.pem $filename ` ;
4103 if ( $test =~ /: OK/ ) {
4109 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
4113 move
( $filename , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
4115 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
4121 my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem` ;
4122 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
4124 $temp =~ s
+/ Email
+, E
+;
4125 $temp =~ s/ ST=/ S=/ ;
4126 $cgiparams { 'CERT_NAME' } = $temp ;
4127 $cgiparams { 'CERT_NAME' } =~ s/,//g ;
4128 $cgiparams { 'CERT_NAME' } =~ s/\'//g ;
4129 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
4130 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
4131 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
4134 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
4135 if ( $cgiparams { 'KEY' }) {
4136 $errormessage = $Lang :: tr
{ 'cant change certificates' };
4139 # Validate input since the form was submitted
4140 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
4141 $errormessage = $Lang :: tr
{ 'name too long' };
4144 if ( $cgiparams { 'CERT_NAME' } eq '' || $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
4145 $errormessage = $Lang :: tr
{ 'invalid input for name' };
4148 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
4149 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
4152 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
4153 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
4156 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
4157 $errormessage = $Lang :: tr
{ 'invalid input for department' };
4160 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
4161 $errormessage = $Lang :: tr
{ 'organization too long' };
4164 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
4165 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
4168 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
4169 $errormessage = $Lang :: tr
{ 'invalid input for city' };
4172 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
4173 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
4176 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
4177 $errormessage = $Lang :: tr
{ 'invalid input for country' };
4180 if ( $cgiparams { 'CERT_PASS1' } ne '' && $cgiparams { 'CERT_PASS2' } ne '' ){
4181 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
4182 $errormessage = $Lang :: tr
{ 'password too short' };
4186 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
4187 $errormessage = $Lang :: tr
{ 'passwords do not match' };
4190 if ( $cgiparams { 'DAYS_VALID' } ne '' && $cgiparams { 'DAYS_VALID' } !~ /^[0-9]+$/ ) {
4191 $errormessage = $Lang :: tr
{ 'invalid input for valid till days' };
4195 # Replace empty strings with a .
4196 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
4197 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
4198 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
4200 # Create the Host certificate request client
4201 my $pid = open ( OPENSSL
, "|-" );
4202 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto VPNCONF_ERROR
;};
4203 if ( $pid ) { # parent
4204 print OPENSSL
" $cgiparams {'CERT_COUNTRY'} \n " ;
4205 print OPENSSL
" $state \n " ;
4206 print OPENSSL
" $city \n " ;
4207 print OPENSSL
" $cgiparams {'CERT_ORGANIZATION'} \n " ;
4208 print OPENSSL
" $ou \n " ;
4209 print OPENSSL
" $cgiparams {'CERT_NAME'} \n " ;
4210 print OPENSSL
" $cgiparams {'CERT_EMAIL'} \n " ;
4211 print OPENSSL
". \n " ;
4212 print OPENSSL
". \n " ;
4215 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
4216 unlink ( "${General::swroot}ovpn/certs/ $cgiparams {'NAME'}key.pem" );
4217 unlink ( "${General::swroot}ovpn/certs/ $cgiparams {'NAME'}req.pem" );
4221 unless ( exec ( '/usr/bin/openssl' , 'req' , '-nodes' ,
4222 '-newkey' , 'rsa:2048' ,
4223 '-keyout' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" ,
4224 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" ,
4225 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
4226 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
4227 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
4228 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
4233 # Sign the host certificate request
4234 system ( '/usr/bin/openssl' , 'ca' , '-days' , " $cgiparams {'DAYS_VALID'}" ,
4235 '-batch' , '-notext' ,
4236 '-in' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" ,
4237 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
4238 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
4240 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
4241 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
4242 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
4243 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
4244 & newcleanssldatabase
();
4247 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
4248 & deletebackupcert
();
4251 # Create the pkcs12 file
4252 system ( '/usr/bin/openssl' , 'pkcs12' , '-export' ,
4253 '-inkey' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" ,
4254 '-in' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
4255 '-name' , $cgiparams { 'NAME' },
4256 '-passout' , "pass: $cgiparams {'CERT_PASS1'}" ,
4257 '-certfile' , "${General::swroot}/ovpn/ca/cacert.pem" ,
4258 '-caname' , " $vpnsettings {'ROOTCERT_ORGANIZATION'} CA" ,
4259 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12" );
4261 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
4262 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
4263 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
4264 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12" );
4267 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
4269 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
4270 ; # Nothing, just editing
4272 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
4276 # Check if there is no other entry with this common name
4277 if ((! $cgiparams { 'KEY' }) && ( $cgiparams { 'AUTH' } ne 'psk' )) {
4278 foreach my $key ( keys %confighash ) {
4279 if ( $confighash { $key }[ 2 ] eq $cgiparams { 'CERT_NAME' }) {
4280 $errormessage = $Lang :: tr
{ 'a connection with this common name already exists' };
4287 my $key = $cgiparams { 'KEY' };
4290 $key = & General
:: findhasharraykey
( \
%confighash );
4291 foreach my $i ( 0 .. 43 ) { $confighash { $key }[ $i ] = "" ;}
4293 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
4294 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
4295 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
4296 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
4299 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
4300 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
4301 $confighash { $key }[ 4 ] = 'psk' ;
4302 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
4304 $confighash { $key }[ 4 ] = 'cert' ;
4306 if ( $cgiparams { 'TYPE' } eq 'net' ) {
4307 $confighash { $key }[ 6 ] = $cgiparams { 'SIDE' };
4308 $confighash { $key }[ 11 ] = $cgiparams { 'REMOTE_SUBNET' };
4310 $confighash { $key }[ 8 ] = $cgiparams { 'LOCAL_SUBNET' };
4311 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
4312 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) {
4313 $confighash { $key }[ 22 ] = $confighash { $key }[ 29 ];
4315 $confighash { $key }[ 22 ] = $cgiparams { 'OVPN_MGMT' };
4317 $confighash { $key }[ 23 ] = $cgiparams { 'MSSFIX' };
4318 $confighash { $key }[ 24 ] = $cgiparams { 'FRAGMENT' };
4319 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
4320 $confighash { $key }[ 26 ] = $cgiparams { 'INTERFACE' };
4322 $confighash { $key }[ 27 ] = $cgiparams { 'OVPN_SUBNET' };
4323 $confighash { $key }[ 28 ] = $cgiparams { 'PROTOCOL' };
4324 $confighash { $key }[ 29 ] = $cgiparams { 'DEST_PORT' };
4325 $confighash { $key }[ 30 ] = $cgiparams { 'COMPLZO' };
4326 $confighash { $key }[ 31 ] = $cgiparams { 'MTU' };
4327 $confighash { $key }[ 32 ] = $cgiparams { 'CHECK1' };
4328 $name = $cgiparams { 'CHECK1' };
4329 $confighash { $key }[ 33 ] = $cgiparams { $name };
4330 $confighash { $key }[ 34 ] = $cgiparams { 'RG' };
4331 $confighash { $key }[ 35 ] = $cgiparams { 'CCD_DNS1' };
4332 $confighash { $key }[ 36 ] = $cgiparams { 'CCD_DNS2' };
4333 $confighash { $key }[ 37 ] = $cgiparams { 'CCD_WINS' };
4334 $confighash { $key }[ 38 ] = $cgiparams { 'PMTU_DISCOVERY' };
4335 $confighash { $key }[ 39 ] = $cgiparams { 'DAUTH' };
4336 $confighash { $key }[ 40 ] = $cgiparams { 'DCIPHER' };
4338 if (( $cgiparams { 'TYPE' } eq 'host' ) && ( $cgiparams { 'CERT_PASS1' } eq "" )) {
4339 $confighash { $key }[ 41 ] = "no-pass" ;
4342 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
4344 if ( $cgiparams { 'CHECK1' } ){
4346 my ( $ccdip , $ccdsub )= split "/" , $cgiparams { $name };
4347 my ( $a , $b , $c , $d ) = split ( /\./ , $ccdip );
4348 if ( - e
"${General::swroot}/ovpn/ccd/ $confighash { $key }[2]" ){
4349 unlink "${General::swroot}/ovpn/ccd/ $cgiparams {'CERT_NAME'}" ;
4351 open ( CCDRWCONF
, '>' , "${General::swroot}/ovpn/ccd/ $confighash { $key }[2]" ) or die "Unable to create clientconfigfile $!" ;
4352 print CCDRWCONF
"# OpenVPN clientconfig from ccd extension by Copymaster# \n\n " ;
4353 if ( $cgiparams { 'CHECK1' } eq 'dynamic' ){
4354 print CCDRWCONF
"#This client uses the dynamic pool \n " ;
4356 print CCDRWCONF
"#Ip address client and server \n " ;
4357 print CCDRWCONF
"ifconfig-push $ccdip " .& General
:: getlastip
( $ccdip , 1 ). " \n " ;
4359 if ( $confighash { $key }[ 34 ] eq 'on' ){
4360 print CCDRWCONF
" \n #Redirect Gateway: \n #All IP traffic is redirected through the vpn \n " ;
4361 print CCDRWCONF
"push redirect-gateway \n " ;
4363 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
4364 if ( $cgiparams { 'IR' } ne '' ){
4365 print CCDRWCONF
" \n #Client routes these networks (behind Client) \n " ;
4366 foreach my $key ( keys %ccdroutehash ){
4367 if ( $ccdroutehash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4368 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}){
4369 my ( $a , $b )= split ( /\/ /, $ccdroutehash { $key }[ $i ]);
4370 print CCDRWCONF
"iroute $a $b \n " ;
4375 if ( $cgiparams { 'IFROUTE' } eq $Lang :: tr
{ 'ccd none' } ){ $cgiparams { 'IFROUTE' }= '' ;}
4376 if ( $cgiparams { 'IFROUTE' } ne '' ){
4377 print CCDRWCONF
" \n #Client gets routes to these networks (behind IPFire) \n " ;
4378 foreach my $key ( keys %ccdroute2hash ){
4379 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4380 foreach my $i ( 1 .. $ #{$ccdroute2hash{$key}}){
4381 if ( $ccdroute2hash { $key }[ $i ] eq $Lang :: tr
{ 'blue' }){
4383 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%blue );
4384 print CCDRWCONF
"push \" route $blue {BLUE_ADDRESS} $blue {BLUE_NETMASK} \n " ;
4385 } elsif ( $ccdroute2hash { $key }[ $i ] eq $Lang :: tr
{ 'orange' }){
4387 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%orange );
4388 print CCDRWCONF
"push \" route $orange {ORANGE_ADDRESS} $orange {ORANGE_NETMASK} \n " ;
4390 my ( $a , $b )= split ( /\/ /, $ccdroute2hash { $key }[ $i ]);
4391 print CCDRWCONF
"push \" route $a $b \"\n " ;
4397 if (( $cgiparams { 'CCD_DNS1' } eq '' ) && ( $cgiparams { 'CCD_DNS1' } ne '' )){ $cgiparams { 'CCD_DNS1' } = $cgiparams { 'CCD_DNS2' }; $cgiparams { 'CCD_DNS2' }= '' ;}
4398 if ( $cgiparams { 'CCD_DNS1' } ne '' ){
4399 print CCDRWCONF
" \n #Client gets these nameservers \n " ;
4400 print CCDRWCONF
"push \" dhcp-option DNS $cgiparams {'CCD_DNS1'} \" \n " ;
4402 if ( $cgiparams { 'CCD_DNS2' } ne '' ){
4403 print CCDRWCONF
"push \" dhcp-option DNS $cgiparams {'CCD_DNS2'} \" \n " ;
4405 if ( $cgiparams { 'CCD_WINS' } ne '' ){
4406 print CCDRWCONF
" \n #Client gets this WINS server \n " ;
4407 print CCDRWCONF
"push \" dhcp-option WINS $cgiparams {'CCD_WINS'} \" \n " ;
4416 if ( $cgiparams { 'TYPE' } eq 'net' ) {
4418 if (- e
"/var/run/ $confighash { $key }[1]n2n.pid" ) {
4419 system ( '/usr/local/bin/openvpnctrl' , '-kn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
4421 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
4422 my $key = $cgiparams { 'KEY' };
4424 $key = & General
:: findhasharraykey
( \
%confighash );
4425 foreach my $i ( 0 .. 31 ) { $confighash { $key }[ $i ] = "" ;}
4427 $confighash { $key }[ 0 ] = 'on' ;
4428 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
4430 system ( '/usr/local/bin/openvpnctrl' , '-sn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
4438 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
4439 $cgiparams { 'KEY' } = $key ;
4440 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
4444 $cgiparams { 'ENABLED' } = 'on' ;
4448 $cgiparams { 'MSSFIX' } = 'on' ;
4449 $cgiparams { 'FRAGMENT' } = '1300' ;
4450 $cgiparams { 'PMTU_DISCOVERY' } = 'off' ;
4451 $cgiparams { 'DAUTH' } = 'SHA1' ;
4455 $cgiparams { 'SIDE' } = 'left' ;
4456 if ( ! - f
"${General::swroot}/ovpn/ca/cakey.pem" ) {
4457 $cgiparams { 'AUTH' } = 'psk' ;
4458 } elsif ( ! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
4459 $cgiparams { 'AUTH' } = 'certfile' ;
4461 $cgiparams { 'AUTH' } = 'certgen' ;
4463 $cgiparams { 'LOCAL_SUBNET' } = " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" ;
4464 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
4465 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
4466 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
4467 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
4468 $cgiparams { 'DAYS_VALID' } = $vpnsettings { 'DAYS_VALID' };
4472 $checked { 'ENABLED' }{ 'off' } = '' ;
4473 $checked { 'ENABLED' }{ 'on' } = '' ;
4474 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = 'CHECKED' ;
4475 $checked { 'ENABLED_BLUE' }{ 'off' } = '' ;
4476 $checked { 'ENABLED_BLUE' }{ 'on' } = '' ;
4477 $checked { 'ENABLED_BLUE' }{ $cgiparams { 'ENABLED_BLUE' }} = 'CHECKED' ;
4478 $checked { 'ENABLED_ORANGE' }{ 'off' } = '' ;
4479 $checked { 'ENABLED_ORANGE' }{ 'on' } = '' ;
4480 $checked { 'ENABLED_ORANGE' }{ $cgiparams { 'ENABLED_ORANGE' }} = 'CHECKED' ;
4483 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
4484 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
4485 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = 'CHECKED' ;
4487 $selected { 'SIDE' }{ 'server' } = '' ;
4488 $selected { 'SIDE' }{ 'client' } = '' ;
4489 $selected { 'SIDE' }{ $cgiparams { 'SIDE' }} = 'SELECTED' ;
4491 $selected { 'PROTOCOL' }{ 'udp' } = '' ;
4492 $selected { 'PROTOCOL' }{ 'tcp' } = '' ;
4493 $selected { 'PROTOCOL' }{ $cgiparams { 'PROTOCOL' }} = 'SELECTED' ;
4496 $checked { 'AUTH' }{ 'psk' } = '' ;
4497 $checked { 'AUTH' }{ 'certreq' } = '' ;
4498 $checked { 'AUTH' }{ 'certgen' } = '' ;
4499 $checked { 'AUTH' }{ 'certfile' } = '' ;
4500 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = 'CHECKED' ;
4502 $selected { 'INTERFACE' }{ $cgiparams { 'INTERFACE' }} = 'SELECTED' ;
4504 $checked { 'COMPLZO' }{ 'off' } = '' ;
4505 $checked { 'COMPLZO' }{ 'on' } = '' ;
4506 $checked { 'COMPLZO' }{ $cgiparams { 'COMPLZO' }} = 'CHECKED' ;
4508 $checked { 'MSSFIX' }{ 'off' } = '' ;
4509 $checked { 'MSSFIX' }{ 'on' } = '' ;
4510 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
4512 if ( $cgiparams { 'PMTU_DISCOVERY' } eq '' ) {
4513 $cgiparams { 'PMTU_DISCOVERY' } = 'off' ;
4515 $checked { 'PMTU_DISCOVERY' }{ $cgiparams { 'PMTU_DISCOVERY' }} = 'checked= \' checked \' ' ;
4517 $selected { 'DCIPHER' }{ 'CAMELLIA-256-CBC' } = '' ;
4518 $selected { 'DCIPHER' }{ 'CAMELLIA-192-CBC' } = '' ;
4519 $selected { 'DCIPHER' }{ 'CAMELLIA-128-CBC' } = '' ;
4520 $selected { 'DCIPHER' }{ 'AES-256-CBC' } = '' ;
4521 $selected { 'DCIPHER' }{ 'AES-192-CBC' } = '' ;
4522 $selected { 'DCIPHER' }{ 'AES-128-CBC' } = '' ;
4523 $selected { 'DCIPHER' }{ 'DESX-CBC' } = '' ;
4524 $selected { 'DCIPHER' }{ 'SEED-CBC' } = '' ;
4525 $selected { 'DCIPHER' }{ 'DES-EDE3-CBC' } = '' ;
4526 $selected { 'DCIPHER' }{ 'DES-EDE-CBC' } = '' ;
4527 $selected { 'DCIPHER' }{ 'CAST5-CBC' } = '' ;
4528 $selected { 'DCIPHER' }{ 'BF-CBC' } = '' ;
4529 $selected { 'DCIPHER' }{ 'DES-CBC' } = '' ;
4530 # If no cipher has been chossen yet, select
4531 # the old default (AES-256-CBC) for compatiblity reasons.
4532 if ( $cgiparams { 'DCIPHER' } eq '' ) {
4533 $cgiparams { 'DCIPHER' } = 'AES-256-CBC' ;
4535 $selected { 'DCIPHER' }{ $cgiparams { 'DCIPHER' }} = 'SELECTED' ;
4536 $selected { 'DAUTH' }{ 'whirlpool' } = '' ;
4537 $selected { 'DAUTH' }{ 'SHA512' } = '' ;
4538 $selected { 'DAUTH' }{ 'SHA384' } = '' ;
4539 $selected { 'DAUTH' }{ 'SHA256' } = '' ;
4540 $selected { 'DAUTH' }{ 'SHA1' } = '' ;
4541 # If no hash algorythm has been choosen yet, select
4542 # the old default value (SHA1) for compatiblity reasons.
4543 if ( $cgiparams { 'DAUTH' } eq '' ) {
4544 $cgiparams { 'DAUTH' } = 'SHA1' ;
4546 $selected { 'DAUTH' }{ $cgiparams { 'DAUTH' }} = 'SELECTED' ;
4549 & Header
:: showhttpheaders
();
4550 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
4551 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
4552 if ( $errormessage ) {
4553 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
4554 print "<class name='base'> $errormessage " ;
4555 print " </class>" ;
4556 & Header
:: closebox
();
4560 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'warning messages'}:" );
4561 print "<class name='base'> $warnmessage " ;
4562 print " </class>" ;
4563 & Header
:: closebox
();
4566 print "<form method='post' enctype='multipart/form-data'>" ;
4567 print "<input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />" ;
4569 if ( $cgiparams { 'KEY' }) {
4570 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
4571 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
4574 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'connection'}:" );
4575 print "<table width='100%' border='0'> \n " ;
4577 print "<tr><td width='14%' class='boldbase'> $Lang ::tr{'name'}: <img src='/blob.gif' alt='*' /></td>" ;
4579 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4580 if ( $cgiparams { 'KEY' }) {
4581 print "<td width='35%' class='base'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /> $cgiparams {'NAME'}</td>" ;
4583 print "<td width='35%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' maxlength='20' size='30' /></td>" ;
4585 # print "<tr><td>$Lang::tr{'interface'}</td>";
4586 # print "<td><select name='INTERFACE'>";
4587 # print "<option value='RED' $selected{'INTERFACE'}{'RED'}>RED</option>";
4588 # if ($netsettings{'BLUE_DEV'} ne '') {
4589 # print "<option value='BLUE' $selected{'INTERFACE'}{'BLUE'}>BLUE</option>";
4591 # print "<option value='GREEN' $selected{'INTERFACE'}{'GREEN'}>GREEN</option>";
4592 # print "<option value='ORANGE' $selected{'INTERFACE'}{'ORANGE'}>ORANGE</option>";
4593 # print "</select></td></tr>";
4596 print "<input type='hidden' name='INTERFACE' value='red' />" ;
4597 if ( $cgiparams { 'KEY' }) {
4598 print "<td width='25%' class='base' nowrap='nowrap'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /> $cgiparams {'NAME'}</td>" ;
4600 print "<td width='25%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' maxlength='20' /></td>" ;
4603 <td width='25%'> </td>
4604 <td width='25%'> </td></tr>
4605 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'Act as'}</td>
4606 <td><select name='SIDE'>
4607 <option value='server' $selected {'SIDE'}{'server'}> $Lang ::tr{'openvpn server'}</option>
4608 <option value='client' $selected {'SIDE'}{'client'}> $Lang ::tr{'openvpn client'}</option>
4612 <td class='boldbase'> $Lang ::tr{'remote host/ip'}:</td>
4613 <td><input type='TEXT' name='REMOTE' value=' $cgiparams {'REMOTE'}' /></td>
4616 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'} <img src='/blob.gif' alt='*' /></td>
4617 <td><input type='TEXT' name='LOCAL_SUBNET' value=' $cgiparams {'LOCAL_SUBNET'}' /></td>
4619 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'} <img src='/blob.gif' alt='*' /></td>
4620 <td><input type='text' name='REMOTE_SUBNET' value=' $cgiparams {'REMOTE_SUBNET'}' /></td>
4623 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn subnet'} <img src='/blob.gif' alt='*' /></td>
4624 <td><input type='TEXT' name='OVPN_SUBNET' value=' $cgiparams {'OVPN_SUBNET'}' /></td>
4626 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td>
4627 <td><select name='PROTOCOL'>
4628 <option value='udp' $selected {'PROTOCOL'}{'udp'}>UDP</option>
4629 <option value='tcp' $selected {'PROTOCOL'}{'tcp'}>TCP</option></select></td>
4633 <td class='boldbase'> $Lang ::tr{'destination port'}: <img src='/blob.gif' alt='*' /></td>
4634 <td><input type='TEXT' name='DEST_PORT' value=' $cgiparams {'DEST_PORT'}' size='5' /></td>
4636 <td class='boldbase' nowrap='nowrap'>Management Port ( $Lang ::tr{'openvpn default'}: <span class="base"> $Lang ::tr{'destination port'}):</td>
4637 <td> <input type='TEXT' name='OVPN_MGMT' VALUE=' $cgiparams {'OVPN_MGMT'}'size='5' /></td>
4640 <tr><td colspan=4><hr /></td></tr><tr>
4643 <td class'base'><b> $Lang ::tr{'MTU settings'}</b></td>
4646 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'}</td>
4647 <td><input type='TEXT' name='MTU' VALUE=' $cgiparams {'MTU'}'size='5' /></td>
4648 <td colspan='2'> $Lang ::tr{'openvpn default'}: udp/tcp <span class="base">1500/1400</span></td>
4651 <tr><td class='boldbase' nowrap='nowrap'>fragment:</td>
4652 <td><input type='TEXT' name='FRAGMENT' VALUE=' $cgiparams {'FRAGMENT'}'size='5' /></td>
4653 <td> $Lang ::tr{'openvpn default'}: <span class="base">1300</span></td>
4656 <tr><td class='boldbase' nowrap='nowrap'>mssfix:</td>
4657 <td><input type='checkbox' name='MSSFIX' $checked {'MSSFIX'}{'on'} /></td>
4658 <td> $Lang ::tr{'openvpn default'}: <span class="base">on</span></td>
4661 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'}</td>
4662 <td><input type='checkbox' name='COMPLZO' $checked {'COMPLZO'}{'on'} /></td>
4665 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn mtu-disc'}</td>
4667 <input type='radio' name='PMTU_DISCOVERY' value='yes' $checked {'PMTU_DISCOVERY'}{'yes'} /> $Lang ::tr{'ovpn mtu-disc yes'}
4668 <input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked {'PMTU_DISCOVERY'}{'maybe'} /> $Lang ::tr{'ovpn mtu-disc maybe'}
4669 <input type='radio' name='PMTU_DISCOVERY' value='no' $checked {'PMTU_DISCOVERY'}{'no'} /> $Lang ::tr{'ovpn mtu-disc no'}
4670 <input type='radio' name='PMTU_DISCOVERY' value='off' $checked {'PMTU_DISCOVERY'}{'off'} /> $Lang ::tr{'ovpn mtu-disc off'}
4674 <tr><td colspan=4><hr /></td></tr><tr>
4676 <td class'base'><b> $Lang ::tr{'ovpn crypt options'}:</b></td>
4679 <tr><td class='boldbase'> $Lang ::tr{'cipher'}</td>
4680 <td><select name='DCIPHER'>
4681 <option value='CAMELLIA-256-CBC' $selected {'DCIPHER'}{'CAMELLIA-256-CBC'}>CAMELLIA-CBC (256 $Lang ::tr{'bit'})</option>
4682 <option value='CAMELLIA-192-CBC' $selected {'DCIPHER'}{'CAMELLIA-192-CBC'}>CAMELLIA-CBC (192 $Lang ::tr{'bit'})</option>
4683 <option value='CAMELLIA-128-CBC' $selected {'DCIPHER'}{'CAMELLIA-128-CBC'}>CAMELLIA-CBC (128 $Lang ::tr{'bit'})</option>
4684 <option value='AES-256-CBC' $selected {'DCIPHER'}{'AES-256-CBC'}>AES-CBC (256 $Lang ::tr{'bit'}, $Lang ::tr{'default'})</option>
4685 <option value='AES-192-CBC' $selected {'DCIPHER'}{'AES-192-CBC'}>AES-CBC (192 $Lang ::tr{'bit'})</option>
4686 <option value='AES-128-CBC' $selected {'DCIPHER'}{'AES-128-CBC'}>AES-CBC (128 $Lang ::tr{'bit'})</option>
4687 <option value='DES-EDE3-CBC' $selected {'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC (192 $Lang ::tr{'bit'})</option>
4688 <option value='DESX-CBC' $selected {'DCIPHER'}{'DESX-CBC'}>DESX-CBC (192 $Lang ::tr{'bit'})</option>
4689 <option value='SEED-CBC' $selected {'DCIPHER'}{'SEED-CBC'}>SEED-CBC (128 $Lang ::tr{'bit'})</option>
4690 <option value='DES-EDE-CBC' $selected {'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC (128 $Lang ::tr{'bit'})</option>
4691 <option value='BF-CBC' $selected {'DCIPHER'}{'BF-CBC'}>BF-CBC (128 $Lang ::tr{'bit'})</option>
4692 <option value='CAST5-CBC' $selected {'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC (128 $Lang ::tr{'bit'})</option>
4696 <td class='boldbase'> $Lang ::tr{'ovpn ha'}:</td>
4697 <td><select name='DAUTH'>
4698 <option value='whirlpool' $selected {'DAUTH'}{'whirlpool'}>Whirlpool (512 $Lang ::tr{'bit'})</option>
4699 <option value='SHA512' $selected {'DAUTH'}{'SHA512'}>SHA2 (512 $Lang ::tr{'bit'})</option>
4700 <option value='SHA384' $selected {'DAUTH'}{'SHA384'}>SHA2 (384 $Lang ::tr{'bit'})</option>
4701 <option value='SHA256' $selected {'DAUTH'}{'SHA256'}>SHA2 (256 $Lang ::tr{'bit'})</option>
4702 <option value='SHA1' $selected {'DAUTH'}{'SHA1'}>SHA1 (160 $Lang ::tr{'bit'} Default)</option>
4706 <tr><td colspan=4><hr /></td></tr><tr>
4712 print "<tr><td class='boldbase'> $Lang ::tr{'remark title'}</td>" ;
4713 print "<td colspan='3'><input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' size='55' maxlength='50' /></td></tr></table>" ;
4715 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4716 print "<tr><td> $Lang ::tr{'enabled'} <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>" ;
4719 print "</tr></table><br><br>" ;
4720 #A.Marx CCD new client
4721 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4722 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>" ;
4725 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnnet );
4726 $vpnip = $vpnnet { 'DOVPN_SUBNET' };
4727 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
4731 $checked { 'check1' }{ 'off' } = '' ;
4732 $checked { 'check1' }{ 'on' } = '' ;
4733 $checked { 'check1' }{ $cgiparams { 'CHECK1' }} = 'CHECKED' ;
4734 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%'>" ;
4735 print "</td></tr></table><br><br>" ;
4736 my $name = $cgiparams { 'CHECK1' };
4737 $checked { 'RG' }{ $cgiparams { 'RG' }} = 'CHECKED' ;
4739 if (! - z
"${General::swroot}/ovpn/ccd.conf" ){
4740 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>" ;
4741 foreach my $key ( sort { uc ( $ccdconfhash { $a }[ 0 ]) cmp uc ( $ccdconfhash { $b }[ 0 ]) } keys %ccdconfhash ) {
4743 @ccdconf =( $ccdconfhash { $key }[ 0 ], $ccdconfhash { $key }[ 1 ]);
4744 if ( $count % 2 ){ print "<tr bgcolor=' $color {'color22'}'>" ;} else { print "<tr bgcolor=' $color {'color20'}'>" ;}
4745 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%'>" ;
4746 & fillselectbox
( $ccdconf [ 1 ], $ccdconf [ 0 ], $cgiparams { $name });
4749 print "</table><br><br><hr><br><br>" ;
4753 & Header
:: closebox
();
4754 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
4756 } elsif (! $cgiparams { 'KEY' }) {
4760 my $cakeydisabled = '' ;
4761 my $cacrtdisabled = '' ;
4762 if ( ! - f
"${General::swroot}/ovpn/ca/cakey.pem" ) { $cakeydisabled = "disabled='disabled'" } else { $cakeydisabled = "" };
4763 if ( ! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) { $cacrtdisabled = "disabled='disabled'" } else { $cacrtdisabled = "" };
4765 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'authentication' });
4768 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4771 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
4773 <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>
4774 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td><td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
4775 <tr><td colspan='3'> </td></tr>
4776 <tr><td colspan='3'><hr /></td></tr>
4777 <tr><td colspan='3'> </td></tr>
4778 <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>
4779 <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>
4780 <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>
4781 <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>
4782 <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>
4783 <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>
4784 <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>
4785 <tr><td> </td><td class='base'> $Lang ::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
4796 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
4798 <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>
4799 <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>
4800 <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>
4801 <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>
4802 <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>
4803 <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>
4804 <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>
4805 <tr><td> </td><td class='base'> $Lang ::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
4817 foreach my $country ( sort keys %{ Countries
:: countries
}) {
4818 print "<option value=' $Countries ::countries{ $country }'" ;
4819 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
4820 print " selected='selected'" ;
4822 print "> $country </option>" ;
4828 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4831 <td> </td><td class='base'> $Lang ::tr{'valid till'} (days):</td>
4832 <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value=' $cgiparams {'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr>
4834 <td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
4835 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
4836 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'}:<br>( $Lang ::tr{'confirmation'})</td>
4837 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
4838 <tr><td colspan='3'> </td></tr>
4839 <tr><td colspan='3'><hr /></td></tr>
4840 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'required field'}</td></tr>
4846 <td> </td><td class='base'> $Lang ::tr{'valid till'} (days):</td>
4847 <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value=' $cgiparams {'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr>
4848 <tr><td> </td><td> </td><td> </td></tr>
4849 <tr><td> </td><td> </td><td> </td></tr>
4850 <tr><td colspan='3'><hr /></td></tr>
4851 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'required field'}</td></tr>
4861 & Header
:: closebox
();
4865 #A.Marx CCD new client
4866 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4868 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'ccd client options'}:" );
4872 <table border='0' width='100%'>
4873 <tr><td width='20%'>Redirect Gateway:</td><td colspan='3'><input type='checkbox' name='RG' $checked {'RG'}{'on'} /></td></tr>
4874 <tr><td colspan='4'><b><br> $Lang ::tr{'ccd routes'}</b></td></tr>
4875 <tr><td colspan='4'> </td></tr>
4876 <tr><td valign='top'> $Lang ::tr{'ccd iroute'}</td><td align='left' width='30%'><textarea name='IR' cols='26' rows='6' wrap='off'>
4879 if ( $cgiparams { 'IR' } ne '' ){
4880 print $cgiparams { 'IR' };
4882 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
4883 foreach my $key ( keys %ccdroutehash ) {
4884 if ( $cgiparams { 'NAME' } eq $ccdroutehash { $key }[ 0 ]){
4885 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}) {
4886 if ( $ccdroutehash { $key }[ $i ] ne '' ){
4887 print $ccdroutehash { $key }[ $i ]. " \n " ;
4889 $cgiparams { 'IR' } .= $ccdroutehash { $key }[ $i ];
4896 </textarea></td><td valign='top' colspan='2'> $Lang ::tr{'ccd iroutehint'}</td></tr>
4897 <tr><td colspan='4'><br></td></tr>
4898 <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>
4912 open ( FILE
, "${General::swroot}/main/routing" ) ;
4915 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
4917 foreach my $key ( keys %ccdroute2hash ) {
4918 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4919 if ( $ccdroute2hash { $key }[ 1 ] eq '' ){
4926 print "<option> $Lang ::tr{'ccd none'}</option>" ;
4928 print "<option selected> $Lang ::tr{'ccd none'}</option>" ;
4930 #check if static routes are defined for client
4931 foreach my $line ( @current ) {
4933 $line =~ s/\s*$//g ; # remove newline
4934 @temp = split ( /\,/ , $line );
4935 $temp [ 1 ] = '' unless defined $temp [ 1 ]; # not always populated
4936 my ( $a , $b ) = split ( /\/ /, $temp [ 1 ]);
4937 $temp [ 1 ] = $a . "/" .& General
:: iporsubtocidr
( $b );
4938 foreach my $key ( keys %ccdroute2hash ) {
4939 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4940 foreach my $i ( 1 .. $ #{$ccdroute2hash{$key}}) {
4941 if ( $ccdroute2hash { $key }[ $i ] eq $a . "/" .& General
:: iporsubtodec
( $b )){
4947 if ( $set == '1' && $#temp != - 1 ){ print "<option selected> $temp [1]</option>" ; $set = 0 ;} elsif ( $set == '0' && $#temp != - 1 ){ print "<option> $temp [1]</option>" ;}
4949 #check if green,blue,orange are defined for client
4950 foreach my $key ( keys %ccdroute2hash ) {
4951 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4953 foreach my $i ( 1 .. $ #{$ccdroute2hash{$key}}) {
4954 if ( $ccdroute2hash { $key }[ $i ] eq $netsettings { 'GREEN_NETADDRESS' }. "/" .& General
:: iporsubtodec
( $netsettings { 'GREEN_NETMASK' })){
4957 if (& haveBlueNet
()){
4958 if ( $ccdroute2hash { $key }[ $i ] eq $netsettings { 'BLUE_NETADDRESS' }. "/" .& General
:: iporsubtodec
( $netsettings { 'BLUE_NETMASK' })) {
4962 if (& haveOrangeNet
()){
4963 if ( $ccdroute2hash { $key }[ $i ] eq $netsettings { 'ORANGE_NETADDRESS' }. "/" .& General
:: iporsubtodec
( $netsettings { 'ORANGE_NETMASK' }) ) {
4970 if (& haveBlueNet
() && $selblue == '1' ){ print "<option selected> $Lang ::tr{'blue'}</option>" ; $selblue = 0 ;} elsif (& haveBlueNet
() && $selblue == '0' ){ print "<option> $Lang ::tr{'blue'}</option>" ;}
4971 if (& haveOrangeNet
() && $selorange == '1' ){ print "<option selected> $Lang ::tr{'orange'}</option>" ; $selorange = 0 ;} elsif (& haveOrangeNet
() && $selorange == '0' ){ print "<option> $Lang ::tr{'orange'}</option>" ;}
4972 if ( $selgreen == '1' || $other == '0' ){ print "<option selected> $Lang ::tr{'green'}</option>" ; $set = 0 ;} else { print "<option> $Lang ::tr{'green'}</option>" ;};
4975 </select></td><td valign='top'>DNS1:</td><td valign='top'><input type='TEXT' name='CCD_DNS1' value=' $cgiparams {'CCD_DNS1'}' size='30' /></td></tr>
4976 <tr valign='top'><td>DNS2:</td><td><input type='TEXT' name='CCD_DNS2' value=' $cgiparams {'CCD_DNS2'}' size='30' /></td></tr>
4977 <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>
4981 & Header
:: closebox
();
4983 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
4984 if ( $cgiparams { 'KEY' }) {
4985 # print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />";
4987 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
4988 & Header
:: closebigbox
();
4989 & Header
:: closepage
();
4997 ### Default status page
5002 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%cgiparams );
5003 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
5004 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
5006 my @status = `/bin/cat /var/run/ovpnserver.log` ;
5008 if ( $cgiparams { 'VPN_IP' } eq '' && - e
"${General::swroot}/red/active" ) {
5009 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
5010 my $ipaddr = < IPADDR
>;
5013 $cgiparams { 'VPN_IP' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
5014 if ( $cgiparams { 'VPN_IP' } eq '' ) {
5015 $cgiparams { 'VPN_IP' } = $ipaddr ;
5021 if ( $cgiparams { 'DCIPHER' } eq '' ) {
5022 $cgiparams { 'DCIPHER' } = 'AES-256-CBC' ;
5024 if ( $cgiparams { 'DDEST_PORT' } eq '' ) {
5025 $cgiparams { 'DDEST_PORT' } = '1194' ;
5027 if ( $cgiparams { 'DMTU' } eq '' ) {
5028 $cgiparams { 'DMTU' } = '1400' ;
5030 if ( $cgiparams { 'MSSFIX' } eq '' ) {
5031 $cgiparams { 'MSSFIX' } = 'off' ;
5033 if ( $cgiparams { 'DAUTH' } eq '' ) {
5034 $cgiparams { 'DAUTH' } = 'SHA1' ;
5036 if ( $cgiparams { 'DOVPN_SUBNET' } eq '' ) {
5037 $cgiparams { 'DOVPN_SUBNET' } = '10.' . int ( rand ( 256 )) . '.' . int ( rand ( 256 )) . '.0/255.255.255.0' ;
5039 $checked { 'ENABLED' }{ 'off' } = '' ;
5040 $checked { 'ENABLED' }{ 'on' } = '' ;
5041 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = 'CHECKED' ;
5042 $checked { 'ENABLED_BLUE' }{ 'off' } = '' ;
5043 $checked { 'ENABLED_BLUE' }{ 'on' } = '' ;
5044 $checked { 'ENABLED_BLUE' }{ $cgiparams { 'ENABLED_BLUE' }} = 'CHECKED' ;
5045 $checked { 'ENABLED_ORANGE' }{ 'off' } = '' ;
5046 $checked { 'ENABLED_ORANGE' }{ 'on' } = '' ;
5047 $checked { 'ENABLED_ORANGE' }{ $cgiparams { 'ENABLED_ORANGE' }} = 'CHECKED' ;
5049 $selected { 'DPROTOCOL' }{ 'udp' } = '' ;
5050 $selected { 'DPROTOCOL' }{ 'tcp' } = '' ;
5051 $selected { 'DPROTOCOL' }{ $cgiparams { 'DPROTOCOL' }} = 'SELECTED' ;
5053 $selected { 'DCIPHER' }{ 'CAMELLIA-256-CBC' } = '' ;
5054 $selected { 'DCIPHER' }{ 'CAMELLIA-192-CBC' } = '' ;
5055 $selected { 'DCIPHER' }{ 'CAMELLIA-128-CBC' } = '' ;
5056 $selected { 'DCIPHER' }{ 'AES-256-CBC' } = '' ;
5057 $selected { 'DCIPHER' }{ 'AES-192-CBC' } = '' ;
5058 $selected { 'DCIPHER' }{ 'AES-128-CBC' } = '' ;
5059 $selected { 'DCIPHER' }{ 'DES-EDE3-CBC' } = '' ;
5060 $selected { 'DCIPHER' }{ 'DESX-CBC' } = '' ;
5061 $selected { 'DCIPHER' }{ 'SEED-CBC' } = '' ;
5062 $selected { 'DCIPHER' }{ 'DES-EDE-CBC' } = '' ;
5063 $selected { 'DCIPHER' }{ 'CAST5-CBC' } = '' ;
5064 $selected { 'DCIPHER' }{ 'BF-CBC' } = '' ;
5065 $selected { 'DCIPHER' }{ 'DES-CBC' } = '' ;
5066 $selected { 'DCIPHER' }{ $cgiparams { 'DCIPHER' }} = 'SELECTED' ;
5068 $selected { 'DAUTH' }{ 'whirlpool' } = '' ;
5069 $selected { 'DAUTH' }{ 'SHA512' } = '' ;
5070 $selected { 'DAUTH' }{ 'SHA384' } = '' ;
5071 $selected { 'DAUTH' }{ 'SHA256' } = '' ;
5072 $selected { 'DAUTH' }{ 'SHA1' } = '' ;
5073 $selected { 'DAUTH' }{ $cgiparams { 'DAUTH' }} = 'SELECTED' ;
5075 $checked { 'DCOMPLZO' }{ 'off' } = '' ;
5076 $checked { 'DCOMPLZO' }{ 'on' } = '' ;
5077 $checked { 'DCOMPLZO' }{ $cgiparams { 'DCOMPLZO' }} = 'CHECKED' ;
5080 $checked { 'MSSFIX' }{ 'off' } = '' ;
5081 $checked { 'MSSFIX' }{ 'on' } = '' ;
5082 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
5084 & Header
:: showhttpheaders
();
5085 & Header
:: openpage
( $Lang :: tr
{ 'status ovpn' }, 1 , '' );
5086 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
5088 if ( $errormessage ) {
5089 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
5090 print "<class name='base'> $errormessage \n " ;
5091 print " </class> \n " ;
5092 & Header
:: closebox
();
5096 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'warning messages' });
5097 print " $warnmessage <br>" ;
5098 print " $Lang ::tr{'fwdfw warn1'}<br>" ;
5099 & Header
:: closebox
();
5100 print "<center><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'ok'}' style='width: 5em;'></form>" ;
5101 & Header
:: closepage
();
5105 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>" ;
5106 my $srunning = "no" ;
5107 my $activeonrun = "" ;
5108 if ( - e
"/var/run/openvpn.pid" ){
5109 $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>" ;
5113 $activeonrun = "disabled='disabled'" ;
5115 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'global settings' });
5117 <table width='100%' border='0'>
5118 <form method='post'>
5119 <td width='25%'> </td>
5120 <td width='25%'> </td>
5121 <td width='25%'> </td></tr>
5122 <tr><td class='boldbase'> $Lang ::tr{'ovpn server status'}</td>
5123 <td align='left'> $sactive </td>
5124 <tr><td class='boldbase'> $Lang ::tr{'ovpn on red'}</td>
5125 <td><input type='checkbox' name='ENABLED' $checked {'ENABLED'}{'on'} /></td>
5128 if (& haveBlueNet
()) {
5129 print "<tr><td class='boldbase'> $Lang ::tr{'ovpn on blue'}</td>" ;
5130 print "<td><input type='checkbox' name='ENABLED_BLUE' $checked {'ENABLED_BLUE'}{'on'} /></td>" ;
5132 if (& haveOrangeNet
()) {
5133 print "<tr><td class='boldbase'> $Lang ::tr{'ovpn on orange'}</td>" ;
5134 print "<td><input type='checkbox' name='ENABLED_ORANGE' $checked {'ENABLED_ORANGE'}{'on'} /></td>" ;
5137 <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>
5138 <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>
5139 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td>
5140 <td><select name='DPROTOCOL'><option value='udp' $selected {'DPROTOCOL'}{'udp'}>UDP</option>
5141 <option value='tcp' $selected {'DPROTOCOL'}{'tcp'}>TCP</option></select></td>
5142 <td class='boldbase'> $Lang ::tr{'destination port'}:</td>
5143 <td><input type='TEXT' name='DDEST_PORT' value=' $cgiparams {'DDEST_PORT'}' size='5' /></td></tr>
5144 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'} </td>
5145 <td> <input type='TEXT' name='DMTU' VALUE=' $cgiparams {'DMTU'}' size='5' /></td>
5147 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'cipher'}</td>
5148 <td><select name='DCIPHER'>
5149 <option value='CAMELLIA-256-CBC' $selected {'DCIPHER'}{'CAMELLIA-256-CBC'}>CAMELLIA-CBC (256 $Lang ::tr{'bit'})</option>
5150 <option value='CAMELLIA-192-CBC' $selected {'DCIPHER'}{'CAMELLIA-192-CBC'}>CAMELLIA-CBC (192 $Lang ::tr{'bit'})</option>
5151 <option value='CAMELLIA-128-CBC' $selected {'DCIPHER'}{'CAMELLIA-128-CBC'}>CAMELLIA-CBC (128 $Lang ::tr{'bit'})</option>
5152 <option value='AES-256-CBC' $selected {'DCIPHER'}{'AES-256-CBC'}>AES-CBC (256 $Lang ::tr{'bit'})</option>
5153 <option value='AES-192-CBC' $selected {'DCIPHER'}{'AES-192-CBC'}>AES-CBC (192 $Lang ::tr{'bit'})</option>
5154 <option value='AES-128-CBC' $selected {'DCIPHER'}{'AES-128-CBC'}>AES-CBC (128 $Lang ::tr{'bit'})</option>
5155 <option value='DES-EDE3-CBC' $selected {'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC (192 $Lang ::tr{'bit'})</option>
5156 <option value='DESX-CBC' $selected {'DCIPHER'}{'DESX-CBC'}>DESX-CBC (192 $Lang ::tr{'bit'})</option>
5157 <option value='SEED-CBC' $selected {'DCIPHER'}{'SEED-CBC'}>SEED-CBC (128 $Lang ::tr{'bit'})</option>
5158 <option value='DES-EDE-CBC' $selected {'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC (128 $Lang ::tr{'bit'})</option>
5159 <option value='BF-CBC' $selected {'DCIPHER'}{'BF-CBC'}>BF-CBC (128 $Lang ::tr{'bit'})</option>
5160 <option value='CAST5-CBC' $selected {'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC (128 $Lang ::tr{'bit'})</option>
5163 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'}</td>
5164 <td><input type='checkbox' name='DCOMPLZO' $checked {'DCOMPLZO'}{'on'} /></td>
5166 <tr><td colspan='4'><br><br></td></tr>
5170 if ( $srunning eq "yes" ) {
5171 print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' disabled='disabled' />" ;
5172 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'ccd net'}' />" ;
5173 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced server'}' />" ;
5174 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'stop ovpn server'}' /></td></tr>" ;
5176 print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
5177 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'ccd net'}' />" ;
5178 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced server'}' />" ;
5179 if (( - e
"${General::swroot}/ovpn/ca/cacert.pem" &&
5180 - e
"${General::swroot}/ovpn/ca/dh1024.pem" &&
5181 - e
"${General::swroot}/ovpn/certs/servercert.pem" &&
5182 - e
"${General::swroot}/ovpn/certs/serverkey.pem" ) &&
5183 (( $cgiparams { 'ENABLED' } eq 'on' ) ||
5184 ( $cgiparams { 'ENABLED_BLUE' } eq 'on' ) ||
5185 ( $cgiparams { 'ENABLED_ORANGE' } eq 'on' ))){
5186 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'start ovpn server'}' /></td></tr>" ;
5188 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'start ovpn server'}' disabled='disabled' /></td></tr>" ;
5191 print "</form></table>" ;
5192 & Header
:: closebox
();
5194 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
5197 #<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>
5200 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'connection status and controlc' });
5206 foreach my $key ( sort { ncmp
( $confighash { $a }[ 32 ], $confighash { $b }[ 32 ]) } sort { ncmp
( $confighash { $a }[ 1 ], $confighash { $b }[ 1 ]) } keys %confighash ) {
5207 if ( $confighash { $key }[ 32 ] eq "" && $confighash { $key }[ 3 ] eq 'net' ){ $confighash { $key }[ 32 ]= $Lang :: tr
{ 'fwhost OpenVPN N-2-N' };}
5208 if ( $confighash { $key }[ 32 ] eq "dynamic" ){ $confighash { $key }[ 32 ]= $Lang :: tr
{ 'ccd dynrange' };}
5210 print "<b> $confighash { $key }[32]</b>" ;
5212 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
5214 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
5215 <th width='15%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></th>
5216 <th width='20%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></th>
5217 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></th>
5218 <th width='5%' class='boldbase' colspan='7' align='center'><b> $Lang ::tr{'action'}</b></th>
5222 if ( $id > 0 && $lastnet ne $confighash { $key }[ 32 ]){
5223 print "</table><br>" ;
5224 print "<b> $confighash { $key }[32]</b>" ;
5226 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
5228 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
5229 <th width='15%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></th>
5230 <th width='20%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></th>
5231 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></th>
5232 <th width='5%' class='boldbase' colspan='7' align='center'><b> $Lang ::tr{'action'}</b></th>
5236 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
5239 $col = "bgcolor=' $color {'color20'}'" ;
5242 $col = "bgcolor=' $color {'color22'}'" ;
5244 print "<td align='center' nowrap='nowrap' $col > $confighash { $key }[1]</td>" ;
5245 print "<td align='center' nowrap='nowrap' $col >" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ")</td>" ;
5246 #if ($confighash{$key}[4] eq 'cert') {
5247 #print "<td align='left' nowrap='nowrap'>$confighash{$key}[2]</td>";
5249 #print "<td align='left'> </td>";
5251 my $cavalid = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $confighash { $key }[1]cert.pem` ;
5252 $cavalid =~ /Not After : (.*)[\n]/ ;
5254 print "<td align='center' $col > $confighash { $key }[25]</td>" ;
5255 $col1 = "bgcolor='${Header::colourred}'" ;
5256 my $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
5258 if ( $confighash { $key }[ 0 ] eq 'off' ) {
5259 $col1 = "bgcolor='${Header::colourblue}'" ;
5260 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
5267 if ( $confighash { $key }[ 3 ] eq 'net' ) {
5269 if (- e
"/var/run/ $confighash { $key }[1]n2n.pid" ) {
5272 my $tport = $confighash { $key }[ 22 ];
5273 my $tnet = new Net
:: Telnet
( Timeout
=> 5 , Errmode
=> 'return' , Port
=> $tport );
5275 $tnet -> open ( '127.0.0.1' );
5276 @output = $tnet -> cmd ( String
=> 'state' , Prompt
=> '/(END.* \n |ERROR:.* \n )/' );
5277 @tustate = split ( /\,/ , $output [ 1 ]);
5279 #CONNECTING -- OpenVPN's initial state.
5280 #WAIT -- (Client only) Waiting for initial response from server.
5281 #AUTH -- (Client only) Authenticating with server.
5282 #GET_CONFIG -- (Client only) Downloading configuration options from server.
5283 #ASSIGN_IP -- Assigning IP address to virtual network interface.
5284 #ADD_ROUTES -- Adding routes to system.
5285 #CONNECTED -- Initialization Sequence Completed.
5286 #RECONNECTING -- A restart has occurred.
5287 #EXITING -- A graceful exit is in progress.
5290 if (( $tustate [ 1 ] eq 'CONNECTED' ) || ( $tustate [ 1 ] eq 'WAIT' )) {
5291 $col1 = "bgcolor='${Header::colourgreen}'" ;
5292 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b>" ;
5294 $col1 = "bgcolor='${Header::colourred}'" ;
5295 $active = "<b><font color='#FFFFFF'> $tustate [1]</font></b>" ;
5303 foreach my $line ( @status ) {
5305 if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ ) {
5306 @match = split ( m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ , $line );
5307 if ( $match [ 1 ] ne "Common Name" ) {
5311 if ( $cn eq " $confighash { $key }[2]" ) {
5312 $col1 = "bgcolor='${Header::colourgreen}'" ;
5313 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b>" ;
5322 <td align='center' $col1 > $active </td>
5324 <form method='post' name='frm${key}a'><td align='center' $col >
5325 <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' />
5326 <input type='hidden' name='ACTION' value=' $Lang ::tr{'dl client arch'}' />
5327 <input type='hidden' name='KEY' value=' $key ' />
5332 if ( $confighash { $key }[ 41 ] eq "no-pass" ) {
5334 <form method='post' name='frm${key}g'><td align='center' $col >
5335 <input type='image' name=' $Lang ::tr{'dl client arch insecure'}' src='/images/openvpn.png'
5336 alt=' $Lang ::tr{'dl client arch insecure'}' title=' $Lang ::tr{'dl client arch insecure'}' border='0' />
5337 <input type='hidden' name='ACTION' value=' $Lang ::tr{'dl client arch'}' />
5338 <input type='hidden' name='MODE' value='insecure' />
5339 <input type='hidden' name='KEY' value=' $key ' />
5343 print "<td $col > </td>" ;
5346 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
5348 <form method='post' name='frm${key}b'><td align='center' $col >
5349 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' border='0' />
5350 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
5351 <input type='hidden' name='KEY' value=' $key ' />
5355 print "<td> </td>" ;
5357 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $key }[1].p12" ) {
5359 <form method='post' name='frm${key}c'><td align='center' $col >
5360 <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' />
5361 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
5362 <input type='hidden' name='KEY' value=' $key ' />
5365 ; } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
5367 <form method='post' name='frm${key}c'><td align='center' $col >
5368 <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' />
5369 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
5370 <input type='hidden' name='KEY' value=' $key ' />
5374 print "<td> </td>" ;
5377 <form method='post' name='frm${key}d'><td align='center' $col >
5378 <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' />
5379 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
5380 <input type='hidden' name='KEY' value=' $key ' />
5383 <form method='post' name='frm${key}e'><td align='center' $col >
5384 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
5385 <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'/>
5386 <input type='hidden' name='KEY' value=' $key ' />
5388 <form method='post' name='frm${key}f'><td align='center' $col >
5389 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
5390 <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' />
5391 <input type='hidden' name='KEY' value=' $key ' />
5397 $lastnet = $confighash { $key }[ 32 ];
5402 # If the config file contains entries, print Key to action icons
5407 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
5408 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
5409 <td class='base'> $Lang ::tr{'click to disable'}</td>
5410 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
5411 <td class='base'> $Lang ::tr{'show certificate'}</td>
5412 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
5413 <td class='base'> $Lang ::tr{'edit'}</td>
5414 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
5415 <td class='base'> $Lang ::tr{'remove'}</td>
5419 <td> <img src='/images/off.gif' alt='?OFF' /></td>
5420 <td class='base'> $Lang ::tr{'click to enable'}</td>
5421 <td> <img src='/images/media-floppy.png' alt='?FLOPPY' /></td>
5422 <td class='base'> $Lang ::tr{'download certificate'}</td>
5423 <td> <img src='/images/openvpn.png' alt='?RELOAD'/></td>
5424 <td class='base'> $Lang ::tr{'dl client arch'}</td>
5432 <table width='100%'>
5433 <form method='post'>
5434 <tr><td align='right'>
5435 <input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />
5436 <input type='submit' name='ACTION' value=' $Lang ::tr{'ovpn con stat'}' $activeonrun /></td>
5442 & Header
:: closebox
();
5446 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'certificate authorities'}" );
5448 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
5450 <th width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
5451 <th width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></th>
5452 <th width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></th>
5456 my $col1 = "bgcolor=' $color {'color22'}'" ;
5457 my $col2 = "bgcolor=' $color {'color20'}'" ;
5459 my $col3 = "bgcolor=' $color {'color22'}'" ;
5461 my $col4 = "bgcolor=' $color {'color20'}'" ;
5463 if (- f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
5464 my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem` ;
5465 $casubject =~ /Subject: (.*)[\n]/ ;
5467 $casubject =~ s
+/ Email
+, E
+;
5468 $casubject =~ s/ ST=/ S=/ ;
5471 <td class='base' $col1 > $Lang ::tr{'root certificate'}</td>
5472 <td class='base' $col1 > $casubject </td>
5473 <form method='post' name='frmrootcrta'><td width='3%' align='center' $col1 >
5474 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
5475 <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' />
5477 <form method='post' name='frmrootcrtb'><td width='3%' align='center' $col1 >
5478 <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' />
5479 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
5481 <td width='4%' $col1 > </td>
5486 # display rootcert generation buttons
5489 <td class='base' $col1 > $Lang ::tr{'root certificate'}:</td>
5490 <td class='base' $col1 > $Lang ::tr{'not present'}</td>
5491 <td colspan='3' $col1 > </td>
5497 if (- f
"${General::swroot}/ovpn/certs/servercert.pem" ) {
5498 my $hostsubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem` ;
5499 $hostsubject =~ /Subject: (.*)[\n]/ ;
5501 $hostsubject =~ s
+/ Email
+, E
+;
5502 $hostsubject =~ s/ ST=/ S=/ ;
5506 <td class='base' $col2 > $Lang ::tr{'host certificate'}</td>
5507 <td class='base' $col2 > $hostsubject </td>
5508 <form method='post' name='frmhostcrta'><td width='3%' align='center' $col2 >
5509 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
5510 <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' />
5512 <form method='post' name='frmhostcrtb'><td width='3%' align='center' $col2 >
5513 <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' />
5514 <input type='hidden' name='ACTION' value=" $Lang ::tr{'download host certificate'}" />
5516 <td width='4%' $col2 > </td>
5524 <td width='25%' class='base' $col2 > $Lang ::tr{'host certificate'}:</td>
5525 <td class='base' $col2 > $Lang ::tr{'not present'}</td>
5526 </td><td colspan='3' $col2 > </td>
5532 # Adding DH parameter to chart
5533 if (- f
"${General::swroot}/ovpn/ca/dh1024.pem" ) {
5534 my $dhsubject = `/usr/bin/openssl dhparam -text -in ${General::swroot}/ovpn/ca/dh1024.pem` ;
5535 $dhsubject =~ / (.*)[\n]/ ;
5541 <td class='base' $col3 > $Lang ::tr{'dh parameter'}</td>
5542 <td class='base' $col3 > $dhsubject </td>
5543 <form method='post' name='frmdhparam'><td width='3%' align='center' $col3 >
5544 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show dh'}' />
5545 <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' />
5547 <form method='post' name='frmdhparam'><td width='3%' align='center' $col3 >
5549 <td width='4%' $col3 > </td>
5557 <td width='25%' class='base' $col3 > $Lang ::tr{'dh parameter'}:</td>
5558 <td class='base' $col3 > $Lang ::tr{'not present'}</td>
5559 </td><td colspan='3' $col3 > </td>
5565 # Adding ta.key to chart
5566 if (- f
"${General::swroot}/ovpn/certs/ta.key" ) {
5567 my $tasubject = `/bin/cat ${General::swroot}/ovpn/certs/ta.key` ;
5568 $tasubject =~ /# (.*)[\n]/ ;
5573 <td class='base' $col4 > $Lang ::tr{'ta key'}</td>
5574 <td class='base' $col4 > $tasubject </td>
5575 <form method='post' name='frmtakey'><td width='3%' align='center' $col4 >
5576 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show tls-auth key'}' />
5577 <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' />
5579 <form method='post' name='frmtakey'><td width='3%' align='center' $col4 >
5580 <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' />
5581 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download tls-auth key'}' />
5583 <td width='4%' $col4 > </td>
5591 <td width='25%' class='base' $col4 > $Lang ::tr{'ta key'}:</td>
5592 <td class='base' $col4 > $Lang ::tr{'not present'}</td>
5593 <td colspan='3' $col4 > </td>
5599 if (! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
5600 print "<tr><td colspan='5' align='center'><form method='post'>" ;
5601 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' />" ;
5602 print "</form></td></tr> \n " ;
5605 if ( keys %cahash > 0 ) {
5606 foreach my $key ( keys %cahash ) {
5607 if (( $key + 1 ) % 2 ) {
5608 print "<tr bgcolor=' $color {'color20'}'> \n " ;
5610 print "<tr bgcolor=' $color {'color22'}'> \n " ;
5612 print "<td class='base'> $cahash { $key }[0]</td> \n " ;
5613 print "<td class='base'> $cahash { $key }[1]</td> \n " ;
5615 <form method='post' name='cafrm${key}a'><td align='center'>
5616 <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' />
5617 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
5618 <input type='hidden' name='KEY' value=' $key ' />
5620 <form method='post' name='cafrm${key}b'><td align='center'>
5621 <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' />
5622 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
5623 <input type='hidden' name='KEY' value=' $key ' />
5625 <form method='post' name='cafrm${key}c'><td align='center'>
5626 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
5627 <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' />
5628 <input type='hidden' name='KEY' value=' $key ' />
5637 # If the file contains entries, print Key to action icons
5638 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
5642 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
5643 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
5644 <td class='base'> $Lang ::tr{'show certificate'}</td>
5645 <td> <img src='/images/media-floppy.png' alt=' $Lang ::tr{'download certificate'}' /></td>
5646 <td class='base'> $Lang ::tr{'download certificate'}</td>
5657 <form method='post' enctype='multipart/form-data'>
5658 <table border='0' width='100%'>
5660 <td colspan='4'><b> $Lang ::tr{'upload ca certificate'}</b></td>
5664 <td width='10%'> $Lang ::tr{'ca name'}:</td>
5665 <td width='30%'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' align='left'></td>
5666 <td width='30%'><input type='file' name='FH' size='25'>
5667 <td width='30%'align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'upload ca certificate'}'></td>
5671 <td colspan='3'> </td>
5672 <td align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'show crl'}' /></td>
5678 <table border='0' width='100%'>
5680 <td colspan='4'><b> $Lang ::tr{'ovpn dh parameters'}</b></td>
5684 <td width='40%'> $Lang ::tr{'ovpn dh upload'}:</td>
5685 <td width='30%'><input type='file' name='FH' size='25'>
5686 <td width='30%' align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'upload dh key'}'></td>
5690 <td width='40%'> $Lang ::tr{'ovpn dh new key'}:</td>
5691 <td colspan='2' width='60%' align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'generate dh key'}' /></td>
5700 if ( $srunning eq "yes" ) {
5701 print "<div align='center'><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' disabled='disabled' /></div></form> \n " ;
5703 print "<div align='center'><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' /></div></form> \n " ;
5705 & Header
:: closebox
();
5709 & Header
:: closepage
();