]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/ovpnmain.cgi
dec27b722c68587c2c96552391f352de09168119
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2013 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 76
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 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%netsettings );
74 $cgiparams { 'ENABLED' } = 'off' ;
75 $cgiparams { 'ENABLED_BLUE' } = 'off' ;
76 $cgiparams { 'ENABLED_ORANGE' } = 'off' ;
77 $cgiparams { 'EDIT_ADVANCED' } = 'off' ;
78 $cgiparams { 'NAT' } = 'off' ;
79 $cgiparams { 'COMPRESSION' } = 'off' ;
80 $cgiparams { 'ONLY_PROPOSED' } = 'off' ;
81 $cgiparams { 'ACTION' } = '' ;
82 $cgiparams { 'CA_NAME' } = '' ;
83 $cgiparams { 'DH_NAME' } = 'dh1024.pem' ;
84 $cgiparams { 'DHLENGHT' } = '' ;
85 $cgiparams { 'DHCP_DOMAIN' } = '' ;
86 $cgiparams { 'DHCP_DNS' } = '' ;
87 $cgiparams { 'DHCP_WINS' } = '' ;
88 $cgiparams { 'ROUTES_PUSH' } = '' ;
89 $cgiparams { 'DCOMPLZO' } = 'off' ;
90 $cgiparams { 'MSSFIX' } = '' ;
91 $cgiparams { 'number' } = '' ;
92 $cgiparams { 'PMTU_DISCOVERY' } = '' ;
93 $cgiparams { 'DAUTH' } = '' ;
94 $cgiparams { 'DCIPHER' } = '' ;
95 $routes_push_file = "${General::swroot}/ovpn/routes_push" ;
96 unless (- e
$routes_push_file ) { system ( "touch $routes_push_file " ); }
97 unless (- e
"${General::swroot}/ovpn/ccd.conf" ) { system ( "touch ${General::swroot}/ovpn/ccd.conf" ); }
98 unless (- e
"${General::swroot}/ovpn/ccdroute" ) { system ( "touch ${General::swroot}/ovpn/ccdroute" ); }
99 unless (- e
"${General::swroot}/ovpn/ccdroute2" ) { system ( "touch ${General::swroot}/ovpn/ccdroute2" ); }
101 & Header
:: getcgihash
( \
%cgiparams , { 'wantfile' => 1 , 'filevar' => 'FH' });
103 # prepare openvpn config file
109 if ( $netsettings { 'CONFIG_TYPE' } == 2 ) { return 1 ;}
110 if ( $netsettings { 'CONFIG_TYPE' } == 4 ) { return 1 ;}
116 if ( $netsettings { 'CONFIG_TYPE' } == 3 ) { return 1 ;}
117 if ( $netsettings { 'CONFIG_TYPE' } == 4 ) { return 1 ;}
122 my $bytesize = shift ;
125 while ( abs ( $bytesize ) >= 1024 ){
126 $bytesize = $bytesize / 1024 ;
131 my @units = ( "Bytes" , "KB" , "MB" , "GB" , "TB" , "PB" , "EB" );
132 my $newsize =( int ( $bytesize * 100 + 0.5 ))/ 100 ;
133 return ( " $newsize $units [ $i ]" );
138 if ( open ( FILE
, ">${General::swroot}/ovpn/certs/serial" )) {
142 if ( open ( FILE
, ">${General::swroot}/ovpn/certs/index.txt" )) {
146 unlink ( "${General::swroot}/ovpn/certs/index.txt.old" );
147 unlink ( "${General::swroot}/ovpn/certs/serial.old" );
148 unlink ( "${General::swroot}/ovpn/certs/01.pem" );
151 sub newcleanssldatabase
153 if (! - s
"${General::swroot}/ovpn/certs/serial" ) {
154 open ( FILE
, ">${General::swroot}(ovpn/certs/serial" );
158 if (! - s
">${General::swroot}/ovpn/certs/index.txt" ) {
159 system ( "touch ${General::swroot}/ovpn/certs/index.txt" );
161 unlink ( "${General::swroot}/ovpn/certs/index.txt.old" );
162 unlink ( "${General::swroot}/ovpn/certs/serial.old" );
167 if ( open ( FILE
, "${General::swroot}/ovpn/certs/serial.old" )) {
168 my $hexvalue = < FILE
>;
171 unlink ( "${General::swroot}/ovpn/certs/ $hexvalue .pem" );
178 my $confignat = "${General::swroot}/firewall/config" ;
180 & General
:: readhasharray
( $confignat , \
%natconfig );
181 foreach my $key ( sort keys %natconfig ){
182 my @portarray = split ( /\|/ , $natconfig { $key }[ 30 ]);
183 foreach my $value ( @portarray ){
185 my ( $a , $b ) = split ( ":" , $value );
186 if ( $DPROT eq $natconfig { $key }[ 12 ] && $DPORT gt $a && $DPORT lt $b ){
187 $errormessage = " $Lang ::tr{'source port in use'} $DPORT " ;
190 if ( $DPROT eq $natconfig { $key }[ 12 ] && $DPORT eq $value ){
191 $errormessage = " $Lang ::tr{'source port in use'} $DPORT " ;
201 my $portrange1 = $_ [ 0 ]; # New port range
202 my $portrange2 = $_ [ 1 ]; # existing port range
203 my @tempr1 = split ( /\:/ , $portrange1 );
204 my @tempr2 = split ( /\:/ , $portrange2 );
206 unless (& checkportinc
( $tempr1 [ 0 ], $portrange2 )){ return 0 ;}
207 unless (& checkportinc
( $tempr1 [ 1 ], $portrange2 )){ return 0 ;}
209 unless (& checkportinc
( $tempr2 [ 0 ], $portrange1 )){ return 0 ;}
210 unless (& checkportinc
( $tempr2 [ 1 ], $portrange1 )){ return 0 ;}
212 return 1 ; # Everything checks out!
215 # Darren Critchley - we want to make sure that a port entry is not within an already existing range
218 my $port1 = $_ [ 0 ]; # Port
219 my $portrange2 = $_ [ 1 ]; # Port range
220 my @tempr1 = split ( /\:/ , $portrange2 );
222 if ( $port1 < $tempr1 [ 0 ] || $port1 > $tempr1 [ 1 ]) {
230 sub writeserverconf
{
231 my %sovpnsettings = ();
233 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%sovpnsettings );
236 open ( CONF
, ">${General::swroot}/ovpn/server.conf" ) or die "Unable to open ${General::swroot}/ovpn/server.conf: $!" ;
238 print CONF
"#OpenVPN Server conf \n " ;
240 print CONF
"daemon openvpnserver \n " ;
241 print CONF
"writepid /var/run/openvpn.pid \n " ;
242 print CONF
"#DAN prepare OpenVPN for listening on blue and orange \n " ;
243 print CONF
";local $sovpnsettings {'VPN_IP'} \n " ;
244 print CONF
"dev $sovpnsettings {'DDEVICE'} \n " ;
245 print CONF
"proto $sovpnsettings {'DPROTOCOL'} \n " ;
246 print CONF
"port $sovpnsettings {'DDEST_PORT'} \n " ;
247 print CONF
"script-security 3 system \n " ;
248 print CONF
"ifconfig-pool-persist /var/ipfire/ovpn/ovpn-leases.db 3600 \n " ;
249 print CONF
"client-config-dir /var/ipfire/ovpn/ccd \n " ;
250 print CONF
"tls-server \n " ;
251 print CONF
"ca ${General::swroot}/ovpn/ca/cacert.pem \n " ;
252 print CONF
"cert ${General::swroot}/ovpn/certs/servercert.pem \n " ;
253 print CONF
"key ${General::swroot}/ovpn/certs/serverkey.pem \n " ;
254 print CONF
"dh ${General::swroot}/ovpn/ca/dh1024.pem \n " ;
255 my @tempovpnsubnet = split ( "\/" , $sovpnsettings { 'DOVPN_SUBNET' });
256 print CONF
"server $tempovpnsubnet [0] $tempovpnsubnet [1] \n " ;
257 #print CONF "push \"route $netsettings{'GREEN_NETADDRESS'} $netsettings{'GREEN_NETMASK'}\"\n";
259 # Check if we are using mssfix, fragment or mtu-disc and set the corretct mtu of 1500.
260 # If we doesn't use one of them, we can use the configured mtu value.
261 if ( $sovpnsettings { 'MSSFIX' } eq 'on' )
262 { print CONF
" $sovpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
263 elsif ( $sovpnsettings { 'FRAGMENT' } ne '' && $sovpnsettings { 'DPROTOCOL' } ne 'tcp' )
264 { print CONF
" $sovpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
265 elsif (( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'yes' ) ||
266 ( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
267 ( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'no' ))
268 { print CONF
" $sovpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
270 { print CONF
" $sovpnsettings {'DDEVICE'}-mtu $sovpnsettings {'DMTU'} \n " ; }
272 if ( $vpnsettings { 'ROUTES_PUSH' } ne '' ) {
273 @temp = split ( /\n/ , $vpnsettings { 'ROUTES_PUSH' });
276 @tempovpnsubnet = split ( "\/" ,& General
:: ipcidr2msk
( $_ ));
277 print CONF
"push \" route " . $tempovpnsubnet [ 0 ]. " " . $tempovpnsubnet [ 1 ] . " \"\n " ;
282 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
283 foreach my $key ( keys %ccdconfhash ) {
284 my $a = $ccdconfhash { $key }[ 1 ];
285 my ( $b , $c ) = split ( /\/ /, $a );
286 print CONF
"route $b " .& General
:: cidrtosub
( $c ). " \n " ;
289 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
290 foreach my $key ( keys %ccdroutehash ) {
291 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}){
292 my ( $a , $b )= split ( /\/ /, $ccdroutehash { $key }[ $i ]);
293 print CONF
"route $a $b \n " ;
298 if ( $sovpnsettings { CLIENT2CLIENT
} eq 'on' ) {
299 print CONF
"client-to-client \n " ;
301 if ( $sovpnsettings { MSSFIX
} eq 'on' ) {
302 print CONF
"mssfix \n " ;
304 if ( $sovpnsettings { FRAGMENT
} ne '' && $sovpnsettings { 'DPROTOCOL' } ne 'tcp' ) {
305 print CONF
"fragment $sovpnsettings {'FRAGMENT'} \n " ;
308 # Check if a valid operating mode has been choosen and use it.
309 if (( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'yes' ) ||
310 ( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
311 ( $sovpnsettings { 'PMTU_DISCOVERY' } eq 'no' )) {
312 print CONF
"mtu-disc $sovpnsettings {'PMTU_DISCOVERY'} \n " ;
315 if ( $sovpnsettings { KEEPALIVE_1
} > 0 && $sovpnsettings { KEEPALIVE_2
} > 0 ) {
316 print CONF
"keepalive $sovpnsettings {'KEEPALIVE_1'} $sovpnsettings {'KEEPALIVE_2'} \n " ;
318 print CONF
"status-version 1 \n " ;
319 print CONF
"status /var/log/ovpnserver.log 30 \n " ;
320 print CONF
"cipher $sovpnsettings {DCIPHER} \n " ;
321 if ( $sovpnsettings { 'DAUTH' } eq '' ) {
324 print CONF
"auth $sovpnsettings {'DAUTH'} \n " ;
326 if ( $sovpnsettings { DCOMPLZO
} eq 'on' ) {
327 print CONF
"comp-lzo \n " ;
329 if ( $sovpnsettings { REDIRECT_GW_DEF1
} eq 'on' ) {
330 print CONF
"push \" redirect-gateway def1 \"\n " ;
332 if ( $sovpnsettings { DHCP_DOMAIN
} ne '' ) {
333 print CONF
"push \" dhcp-option DOMAIN $sovpnsettings {DHCP_DOMAIN} \"\n " ;
336 if ( $sovpnsettings { DHCP_DNS
} ne '' ) {
337 print CONF
"push \" dhcp-option DNS $sovpnsettings {DHCP_DNS} \"\n " ;
340 if ( $sovpnsettings { DHCP_WINS
} ne '' ) {
341 print CONF
"push \" dhcp-option WINS $sovpnsettings {DHCP_WINS} \"\n " ;
344 if ( $sovpnsettings { DHCP_WINS
} eq '' ) {
345 print CONF
"max-clients 100 \n " ;
347 if ( $sovpnsettings { DHCP_WINS
} ne '' ) {
348 print CONF
"max-clients $sovpnsettings {MAX_CLIENTS} \n " ;
350 print CONF
"tls-verify /usr/lib/openvpn/verify \n " ;
351 print CONF
"crl-verify /var/ipfire/ovpn/crls/cacrl.pem \n " ;
352 print CONF
"user nobody \n " ;
353 print CONF
"group nobody \n " ;
354 print CONF
"persist-key \n " ;
355 print CONF
"persist-tun \n " ;
356 if ( $sovpnsettings { LOG_VERB
} ne '' ) {
357 print CONF
"verb $sovpnsettings {LOG_VERB} \n " ;
359 print CONF
"verb 3 \n " ;
367 if ( open ( FILE
, ">/var/log/ovpnserver.log" )) {
377 my %ccdconfhash = ();
379 my $ccdnetname = $_ [ 0 ];
380 if (- f
"${General::swroot}/ovpn/ovpnconfig" ){
381 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
382 foreach my $key ( keys %ccdhash ) {
383 if ( $ccdhash { $key }[ 32 ] eq $ccdnetname ) {
384 $errormessage = $Lang :: tr
{ 'ccd err hostinnet' };
389 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
390 foreach my $key ( keys %ccdconfhash ) {
391 if ( $ccdconfhash { $key }[ 0 ] eq $ccdnetname ){
392 delete $ccdconfhash { $key };
395 & General
:: writehasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
417 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err name' }. "<br>" ;
421 if (!& General
:: validhostname
( $ccdname ))
423 $errormessage = $Lang :: tr
{ 'ccd err invalidname' };
427 ( $ccdip , $subcidr ) = split ( /\/ /, $ccdnet );
428 $subcidr =& General
:: iporsubtocidr
( $subcidr );
432 $errormessage = $Lang :: tr
{ 'ccd err invalidnet' };
436 if (!& General
:: validipandmask
( $ccdnet )){
437 $errormessage = $Lang :: tr
{ 'ccd err invalidnet' };
441 $errormessage =& General
:: checksubnets
( $ccdname , $ccdnet );
444 if (! $errormessage ) {
446 $baseaddress =& General
:: getnetworkip
( $ccdip , $subcidr );
447 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
448 my $key = & General
:: findhasharraykey
( \
%ccdconfhash );
449 foreach my $i ( 0 .. 1 ) { $ccdconfhash { $key }[ $i ] = "" ;}
450 $ccdconfhash { $key }[ 0 ] = $ccdname ;
451 $ccdconfhash { $key }[ 1 ] = $baseaddress . "/" . $subcidr ;
452 & General
:: writehasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
454 $cgiparams { 'ccdname' }= '' ;
455 $cgiparams { 'ccdsubnet' }= '' ;
467 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
468 foreach my $key ( keys %ccdconfhash ) {
469 if ( $ccdconfhash { $key }[ 0 ] eq $oldname ) {
470 foreach my $key1 ( keys %ccdconfhash ) {
471 if ( $ccdconfhash { $key1 }[ 0 ] eq $newname ){
472 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err netadrexist' };
475 $ccdconfhash { $key }[ 0 ]= $newname ;
476 & General
:: writehasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
483 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
484 foreach my $key ( keys %ccdhash ) {
485 if ( $ccdhash { $key }[ 32 ] eq $oldname ) {
486 $ccdhash { $key }[ 32 ]= $newname ;
487 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
496 my $ccdnetwork = $_ [ 0 ];
499 @octets = split ( "\/" , $ccdnetwork );
500 @subnet = split /\./ , & General
:: cidrtosub
( $octets [ 1 ]);
513 my ( $ip1 , $ip2 , $ip3 , $ip4 )= split /\./ , $ipin ;
521 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
522 $iprange [ 0 ]= $ip1 . "." . $ip2 . "." . $ip3 . "." .( $ip4 + 2 );
523 for ( my $i = 1 ; $i <= $count ; $i ++) {
524 my $tmpip = $iprange [ $i - 1 ];
526 $iprange [ $i ]= & General
:: getnextip
( $tmpip , 4 );
529 foreach my $key ( keys %ccdhash ) {
531 foreach my $tmp ( @iprange ){
532 my ( $net , $sub ) = split ( /\/ /, $ccdhash { $key }[ 33 ]);
534 if ( $hasip ne $ccdhash { $key }[ 33 ] ){
535 splice ( @iprange , $r , 1 );
547 my ( $ccdip , $subcidr ) = split ( "/" , $_ [ 0 ]);
549 my @allccdips =& getccdadresses
( $ccdip , $subcidr ,& ccdmaxclients
( $ccdip . "/" . $subcidr ), $tz );
550 print "<select name=' $boxname ' STYLE='font-family : arial; font-size : 9pt; width:130px;' >" ;
551 foreach ( @allccdips ) {
554 print "<option value=' $ip ' " ;
555 if ( $ip eq $cgiparams { $boxname } ){
558 print "> $ip </option>" ;
568 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%ccdhash );
569 foreach my $key ( keys %ccdhash ) {
570 if ( $ccdhash { $key }[ 32 ] eq $name ){ $i ++;}
575 sub check_routes_push
578 my ( $ip , $cidr ) = split ( /\/ /, $val );
579 ##check for existing routes in routes_push
580 if (- e
"${General::swroot}/ovpn/routes_push" ) {
581 open ( FILE
, "${General::swroot}/ovpn/routes_push" );
585 my ( $ip2 , $cidr2 ) = split ( /\/ /, " $_ " );
586 my $val2 = $ip2 . "/" .& General
:: iporsubtodec
( $cidr2 );
592 if (& General
:: IpInSubnet
( $ip , $ip2 ,& General
:: iporsubtodec
( $cidr2 ))){
605 my ( $ip , $cidr ) = split ( /\/ /, $val );
606 #check for existing routes in ccdroute
607 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
608 foreach my $key ( keys %ccdroutehash ) {
609 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}) {
610 if (& General
:: iporsubtodec
( $val ) eq $ccdroutehash { $key }[ $i ] && $ccdroutehash { $key }[ 0 ] ne $cgiparams { 'NAME' }){
613 my ( $ip2 , $cidr2 ) = split ( /\/ /, $ccdroutehash { $key }[ $i ]);
615 if (& General
:: IpInSubnet
( $ip , $ip2 , $cidr2 )&& $ccdroutehash { $key }[ 0 ] ne $cgiparams { 'NAME' } ){
626 my ( $ip , $cidr ) = split ( /\/ /, $val );
627 #check for existing routes in ccdroute
628 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
629 foreach my $key ( keys %ccdconfhash ) {
630 if (& General
:: iporsubtocidr
( $val ) eq $ccdconfhash { $key }[ 1 ]){
633 my ( $ip2 , $cidr2 ) = split ( /\/ /, $ccdconfhash { $key }[ 1 ]);
635 if (& General
:: IpInSubnet
( $ip , $ip2 ,& General
:: cidrtosub
( $cidr2 ))){
649 my $ipdotmask = $_ [ 0 ];
650 if (& General
:: validip
( $ipdotmask )) { return 0 ; }
651 if (!( $ipdotmask =~ /^(.*?)\/ (.* ?
)$/)) { }
653 if (( $mask =~ /\./ )) { return 0 ; }
657 # -------------------------------------------------------------------
659 sub write_routepushfile
661 open ( FILE
, "> $routes_push_file " );
663 if ( $vpnsettings { 'ROUTES_PUSH' } ne '' ) {
664 print FILE
$vpnsettings { 'ROUTES_PUSH' };
669 sub read_routepushfile
671 if (- e
" $routes_push_file " ) {
672 open ( FILE
, " $routes_push_file " );
673 delete $vpnsettings { 'ROUTES_PUSH' };
674 while (< FILE
>) { $vpnsettings { 'ROUTES_PUSH' } .= $_ };
676 $cgiparams { 'ROUTES_PUSH' } = $vpnsettings { 'ROUTES_PUSH' };
682 #hier die refresh page
683 if ( - e
"${General::swroot}/ovpn/gencanow" ) {
685 $refresh = "<meta http-equiv='refresh' content='15;' />" ;
686 & Header
:: showhttpheaders
();
687 & Header
:: openpage
( $Lang :: tr
{ 'OVPN' }, 1 , $refresh );
688 & Header
:: openbigbox
( '100%' , 'center' );
689 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
690 print "<tr> \n <td align='center'><img src='/images/clock.gif' alt='' /></td> \n " ;
691 print "<td colspan='2'><font color='red'>Please be patient this realy can take some time on older hardware...</font></td></tr> \n " ;
693 & Header
:: closebigbox
();
694 & Header
:: closepage
();
697 ##hier die refresh page
701 ### OpenVPN Server Control
703 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'start ovpn server' } ||
704 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'stop ovpn server' } ||
705 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart ovpn server' }) {
706 #start openvpn server
707 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'start ovpn server' }){
709 system ( '/usr/local/bin/openvpnctrl' , '-s' );
712 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'stop ovpn server' }){
713 system ( '/usr/local/bin/openvpnctrl' , '-k' );
716 # #restart openvpn server
717 # if ($cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}){
718 #workarund, till SIGHUP also works when running as nobody
719 # system('/usr/local/bin/openvpnctrl', '-r');
725 ### Save Advanced options
728 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save-adv-options' }) {
729 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
730 #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too,
731 #DAN this value has to leave.
732 #new settings for daemon
733 $vpnsettings { 'LOG_VERB' } = $cgiparams { 'LOG_VERB' };
734 $vpnsettings { 'KEEPALIVE_1' } = $cgiparams { 'KEEPALIVE_1' };
735 $vpnsettings { 'KEEPALIVE_2' } = $cgiparams { 'KEEPALIVE_2' };
736 $vpnsettings { 'MAX_CLIENTS' } = $cgiparams { 'MAX_CLIENTS' };
737 $vpnsettings { 'REDIRECT_GW_DEF1' } = $cgiparams { 'REDIRECT_GW_DEF1' };
738 $vpnsettings { 'CLIENT2CLIENT' } = $cgiparams { 'CLIENT2CLIENT' };
739 $vpnsettings { 'DHCP_DOMAIN' } = $cgiparams { 'DHCP_DOMAIN' };
740 $vpnsettings { 'DHCP_DNS' } = $cgiparams { 'DHCP_DNS' };
741 $vpnsettings { 'DHCP_WINS' } = $cgiparams { 'DHCP_WINS' };
742 $vpnsettings { 'ROUTES_PUSH' } = $cgiparams { 'ROUTES_PUSH' };
743 $vpnsettings { 'PMTU_DISCOVERY' } = $cgiparams { 'PMTU_DISCOVERY' };
744 $vpnsettings { 'DAUTH' } = $cgiparams { 'DAUTH' };
747 if ( $cgiparams { 'FRAGMENT' } eq '' ) {
748 delete $vpnsettings { 'FRAGMENT' };
750 if ( $cgiparams { 'FRAGMENT' } !~ /^[0-9]+$/ ) {
751 $errormessage = "Incorrect value, please insert only numbers." ;
754 $vpnsettings { 'FRAGMENT' } = $cgiparams { 'FRAGMENT' };
757 if ( $cgiparams { 'MSSFIX' } ne 'on' ) {
758 delete $vpnsettings { 'MSSFIX' };
760 $vpnsettings { 'MSSFIX' } = $cgiparams { 'MSSFIX' };
763 if (( $cgiparams { 'PMTU_DISCOVERY' } eq 'yes' ) ||
764 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
765 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'no' )) {
767 if (( $cgiparams { 'MSSFIX' } eq 'on' ) || ( $cgiparams { 'FRAGMENT' } ne '' )) {
768 $errormessage = $Lang :: tr
{ 'ovpn mtu-disc with mssfix or fragment' };
773 if ( $cgiparams { 'DHCP_DOMAIN' } ne '' ){
774 unless (& General
:: validdomainname
( $cgiparams { 'DHCP_DOMAIN' }) || & General
:: validip
( $cgiparams { 'DHCP_DOMAIN' })) {
775 $errormessage = $Lang :: tr
{ 'invalid input for dhcp domain' };
779 if ( $cgiparams { 'DHCP_DNS' } ne '' ){
780 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_DNS' }) || & General
:: validip
( $cgiparams { 'DHCP_DNS' })) {
781 $errormessage = $Lang :: tr
{ 'invalid input for dhcp dns' };
785 if ( $cgiparams { 'DHCP_WINS' } ne '' ){
786 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_WINS' }) || & General
:: validip
( $cgiparams { 'DHCP_WINS' })) {
787 $errormessage = $Lang :: tr
{ 'invalid input for dhcp wins' };
791 if ( $cgiparams { 'ROUTES_PUSH' } ne '' ){
792 @temp = split ( /\n/ , $cgiparams { 'ROUTES_PUSH' });
793 undef $vpnsettings { 'ROUTES_PUSH' };
795 foreach my $tmpip ( @temp )
797 s/^\s+//g ; s/\s+$//g ;
802 unless (& General
:: validipandmask
( $tmpip )) {
803 $errormessage = " $tmpip " . $Lang :: tr
{ 'ovpn errmsg invalid ip or mask' };
806 my ( $ip , $cidr ) = split ( "\/" ,& General
:: ipcidr2msk
( $tmpip ));
808 if ( $ip eq $netsettings { 'GREEN_NETADDRESS' } && $cidr eq $netsettings { 'GREEN_NETMASK' }) {
809 $errormessage = $Lang :: tr
{ 'ovpn errmsg green already pushed' };
814 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
815 foreach my $key ( keys %ccdroutehash ) {
816 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}) {
817 if ( $ip . "/" . $cidr eq $ccdroutehash { $key }[ $i ] ){
818 $errormessage = "Route $ip \/ $cidr " . $Lang :: tr
{ 'ccd err inuse' }. " $ccdroutehash { $key }[0]" ;
821 my ( $ip2 , $cidr2 ) = split ( /\/ /, $ccdroutehash { $key }[ $i ]);
822 if (& General
:: IpInSubnet
( $ip , $ip2 , $cidr2 )){
823 $errormessage = "Route $ip \/ $cidr " . $Lang :: tr
{ 'ccd err inuse' }. " $ccdroutehash { $key }[0]" ;
831 $vpnsettings { 'ROUTES_PUSH' } .= $tmpip . " \n " ;
834 & write_routepushfile
;
835 undef $vpnsettings { 'ROUTES_PUSH' };
838 undef $vpnsettings { 'ROUTES_PUSH' };
839 & write_routepushfile
;
841 if (( length ( $cgiparams { 'MAX_CLIENTS' }) == 0 ) || (( $cgiparams { 'MAX_CLIENTS' }) < 1 ) || (( $cgiparams { 'MAX_CLIENTS' }) > 255 )) {
842 $errormessage = $Lang :: tr
{ 'invalid input for max clients' };
845 if ( $cgiparams { 'KEEPALIVE_1' } ne '' ) {
846 if ( $cgiparams { 'KEEPALIVE_1' } !~ /^[0-9]+$/ ) {
847 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 1' };
851 if ( $cgiparams { 'KEEPALIVE_2' } ne '' ){
852 if ( $cgiparams { 'KEEPALIVE_2' } !~ /^[0-9]+$/ ) {
853 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 2' };
857 if ( $cgiparams { 'KEEPALIVE_2' } < ( $cgiparams { 'KEEPALIVE_1' } * 2 )){
858 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 1:2' };
862 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
863 & writeserverconf
(); #hier ok
870 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq 'net' && $cgiparams { 'SIDE' } eq 'server' )
873 my @remsubnet = split ( /\/ /, $cgiparams { 'REMOTE_SUBNET' });
874 my @ovsubnettemp = split ( /\./ , $cgiparams { 'OVPN_SUBNET' });
875 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
878 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
879 unless (- d
"${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" , 0770 or die "Unable to create dir $!" ;}
881 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: $!" ;
884 print SERVERCONF
"# IPFire n2n Open VPN Server Config by ummeegge und m.a.d \n " ;
885 print SERVERCONF
" \n " ;
886 print SERVERCONF
"# User Security \n " ;
887 print SERVERCONF
"user nobody \n " ;
888 print SERVERCONF
"group nobody \n " ;
889 print SERVERCONF
"persist-tun \n " ;
890 print SERVERCONF
"persist-key \n " ;
891 print SERVERCONF
"script-security 2 \n " ;
892 print SERVERCONF
"# IP/DNS for remote Server Gateway \n " ;
894 if ( $cgiparams { 'REMOTE' } ne '' ) {
895 print SERVERCONF
"remote $cgiparams {'REMOTE'} \n " ;
898 print SERVERCONF
"float \n " ;
899 print SERVERCONF
"# IP adresses of the VPN Subnet \n " ;
900 print SERVERCONF
"ifconfig $ovsubnet .1 $ovsubnet .2 \n " ;
901 print SERVERCONF
"# Client Gateway Network \n " ;
902 print SERVERCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
903 print SERVERCONF
"# tun Device \n " ;
904 print SERVERCONF
"dev tun \n " ;
905 print SERVERCONF
"# Port and Protokol \n " ;
906 print SERVERCONF
"port $cgiparams {'DEST_PORT'} \n " ;
908 if ( $cgiparams { 'PROTOCOL' } eq 'tcp' ) {
909 print SERVERCONF
"proto tcp-server \n " ;
910 print SERVERCONF
"# Packet size \n " ;
911 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1400' } else { $tunmtu = $cgiparams { 'MTU' }};
912 print SERVERCONF
"tun-mtu $tunmtu \n " ;
915 if ( $cgiparams { 'PROTOCOL' } eq 'udp' ) {
916 print SERVERCONF
"proto udp \n " ;
917 print SERVERCONF
"# Paketsize \n " ;
918 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1500' } else { $tunmtu = $cgiparams { 'MTU' }};
919 print SERVERCONF
"tun-mtu $tunmtu \n " ;
920 if ( $cgiparams { 'FRAGMENT' } ne '' ) { print SERVERCONF
"fragment $cgiparams {'FRAGMENT'} \n " ;}
921 if ( $cgiparams { 'MSSFIX' } eq 'on' ) { print SERVERCONF
"mssfix \n " ; };
924 # Check if a valid operating mode has been choosen and use it.
925 if (( $cgiparams { 'PMTU_DISCOVERY' } eq 'yes' ) ||
926 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
927 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'no' )) {
928 if (( $cgiparams { 'MSSFIX' } ne 'on' ) || ( $cgiparams { 'FRAGMENT' } eq '' )) {
929 if ( $cgiparams { 'MTU' } eq '1500' ) {
930 print SERVERCONF
"mtu-disc $cgiparams {'PMTU_DISCOVERY'} \n " ;
934 print SERVERCONF
"# Auth. Server \n " ;
935 print SERVERCONF
"tls-server \n " ;
936 print SERVERCONF
"ca ${General::swroot}/ovpn/ca/cacert.pem \n " ;
937 print SERVERCONF
"cert ${General::swroot}/ovpn/certs/servercert.pem \n " ;
938 print SERVERCONF
"key ${General::swroot}/ovpn/certs/serverkey.pem \n " ;
939 print SERVERCONF
"dh ${General::swroot}/ovpn/ca/dh1024.pem \n " ;
940 print SERVERCONF
"# Cipher \n " ;
941 print SERVERCONF
"cipher $cgiparams {'DCIPHER'} \n " ;
942 print SERVERCONF
"# HMAC algorithm \n " ;
943 print SERVERCONF
"auth $cgiparams {'DAUTH'} \n " ;
944 if ( $cgiparams { 'COMPLZO' } eq 'on' ) {
945 print SERVERCONF
"# Enable Compression \n " ;
946 print SERVERCONF
"comp-lzo \r\n " ;
948 print SERVERCONF
"# Debug Level \n " ;
949 print SERVERCONF
"verb 3 \n " ;
950 print SERVERCONF
"# Tunnel check \n " ;
951 print SERVERCONF
"keepalive 10 60 \n " ;
952 print SERVERCONF
"# Start as daemon \n " ;
953 print SERVERCONF
"daemon $cgiparams {'NAME'}n2n \n " ;
954 print SERVERCONF
"writepid /var/run/ $cgiparams {'NAME'}n2n.pid \n " ;
955 print SERVERCONF
"# Activate Management Interface and Port \n " ;
956 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) { print SERVERCONF
"management localhost $cgiparams {'DEST_PORT'} \n " }
957 else { print SERVERCONF
"management localhost $cgiparams {'OVPN_MGMT'} \n " };
966 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq 'net' && $cgiparams { 'SIDE' } eq 'client' )
969 my @ovsubnettemp = split ( /\./ , $cgiparams { 'OVPN_SUBNET' });
970 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
971 my @remsubnet = split ( /\/ /, $cgiparams { 'REMOTE_SUBNET' });
974 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
975 unless (- d
"${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" , 0770 or die "Unable to create dir $!" ;}
977 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: $!" ;
980 print CLIENTCONF
"# IPFire rewritten n2n Open VPN Client Config by ummeegge und m.a.d \n " ;
981 print CLIENTCONF
"# \n " ;
982 print CLIENTCONF
"# User Security \n " ;
983 print CLIENTCONF
"user nobody \n " ;
984 print CLIENTCONF
"group nobody \n " ;
985 print CLIENTCONF
"persist-tun \n " ;
986 print CLIENTCONF
"persist-key \n " ;
987 print CLIENTCONF
"script-security 2 \n " ;
988 print CLIENTCONF
"# IP/DNS for remote Server Gateway \n " ;
989 print CLIENTCONF
"remote $cgiparams {'REMOTE'} \n " ;
990 print CLIENTCONF
"float \n " ;
991 print CLIENTCONF
"# IP adresses of the VPN Subnet \n " ;
992 print CLIENTCONF
"ifconfig $ovsubnet .2 $ovsubnet .1 \n " ;
993 print CLIENTCONF
"# Server Gateway Network \n " ;
994 print CLIENTCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
995 print CLIENTCONF
"# tun Device \n " ;
996 print CLIENTCONF
"dev tun \n " ;
997 print CLIENTCONF
"# Port and Protokol \n " ;
998 print CLIENTCONF
"port $cgiparams {'DEST_PORT'} \n " ;
1000 if ( $cgiparams { 'PROTOCOL' } eq 'tcp' ) {
1001 print CLIENTCONF
"proto tcp-client \n " ;
1002 print CLIENTCONF
"# Packet size \n " ;
1003 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1400' } else { $tunmtu = $cgiparams { 'MTU' }};
1004 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
1007 if ( $cgiparams { 'PROTOCOL' } eq 'udp' ) {
1008 print CLIENTCONF
"proto udp \n " ;
1009 print CLIENTCONF
"# Paketsize \n " ;
1010 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1500' } else { $tunmtu = $cgiparams { 'MTU' }};
1011 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
1012 if ( $cgiparams { 'FRAGMENT' } ne '' ) { print CLIENTCONF
"fragment $cgiparams {'FRAGMENT'} \n " ;}
1013 if ( $cgiparams { 'MSSFIX' } eq 'on' ) { print CLIENTCONF
"mssfix \n " ; };
1016 # Check if a valid operating mode has been choosen and use it.
1017 if (( $cgiparams { 'PMTU_DISCOVERY' } eq 'yes' ) ||
1018 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
1019 ( $cgiparams { 'PMTU_DISCOVERY' } eq 'no' )) {
1020 if (( $cgiparams { 'MSSFIX' } ne 'on' ) || ( $cgiparams { 'FRAGMENT' } eq '' )) {
1021 if ( $cgiparams { 'MTU' } eq '1500' ) {
1022 print CLIENTCONF
"mtu-disc $cgiparams {'PMTU_DISCOVERY'} \n " ;
1027 print CLIENTCONF
"ns-cert-type server \n " ;
1028 print CLIENTCONF
"# Auth. Client \n " ;
1029 print CLIENTCONF
"tls-client \n " ;
1030 print CLIENTCONF
"# Cipher \n " ;
1031 print CLIENTCONF
"cipher $cgiparams {'DCIPHER'} \n " ;
1032 print CLIENTCONF
"# HMAC algorithm \n " ;
1033 print CLIENTCONF
"auth $cgiparams {'DAUTH'} \n " ;
1034 print CLIENTCONF
"pkcs12 ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12 \r\n " ;
1035 if ( $cgiparams { 'COMPLZO' } eq 'on' ) {
1036 print CLIENTCONF
"# Enable Compression \n " ;
1037 print CLIENTCONF
"comp-lzo \r\n " ;
1039 print CLIENTCONF
"# Debug Level \n " ;
1040 print CLIENTCONF
"verb 3 \n " ;
1041 print CLIENTCONF
"# Tunnel check \n " ;
1042 print CLIENTCONF
"keepalive 10 60 \n " ;
1043 print CLIENTCONF
"# Start as daemon \n " ;
1044 print CLIENTCONF
"daemon $cgiparams {'NAME'}n2n \n " ;
1045 print CLIENTCONF
"writepid /var/run/ $cgiparams {'NAME'}n2n.pid \n " ;
1046 print CLIENTCONF
"# Activate Management Interface and Port \n " ;
1047 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) { print CLIENTCONF
"management localhost $cgiparams {'DEST_PORT'} \n " }
1048 else { print CLIENTCONF
"management localhost $cgiparams {'OVPN_MGMT'} \n " };
1054 ### Save main settings
1058 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
1059 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1060 #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too,
1061 #DAN this value has to leave.
1062 if ( $cgiparams { 'ENABLED' } eq 'on' ){
1063 unless (& General
:: validfqdn
( $cgiparams { 'VPN_IP' }) || & General
:: validip
( $cgiparams { 'VPN_IP' })) {
1064 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
1065 goto SETTINGS_ERROR
;
1068 if ( $errormessage ) { goto SETTINGS_ERROR
; }
1070 if ( $cgiparams { 'ENABLED' } eq 'on' ){
1071 & checkportfw
( $cgiparams { 'DDEST_PORT' }, $cgiparams { 'DPROTOCOL' });
1073 if ( $errormessage ) { goto SETTINGS_ERROR
; }
1075 if (! & General
:: validipandmask
( $cgiparams { 'DOVPN_SUBNET' })) {
1076 $errormessage = $Lang :: tr
{ 'ovpn subnet is invalid' };
1077 goto SETTINGS_ERROR
;
1079 my @tmpovpnsubnet = split ( "\/" , $cgiparams { 'DOVPN_SUBNET' });
1081 if (& General
:: IpInSubnet
( $netsettings { 'RED_ADDRESS' },
1082 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1083 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire RED Network $netsettings {'RED_ADDRESS'}" ;
1084 goto SETTINGS_ERROR
;
1087 if (& General
:: IpInSubnet
( $netsettings { 'GREEN_ADDRESS' },
1088 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1089 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Green Network $netsettings {'GREEN_ADDRESS'}" ;
1090 goto SETTINGS_ERROR
;
1093 if (& General
:: IpInSubnet
( $netsettings { 'BLUE_ADDRESS' },
1094 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1095 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Blue Network $netsettings {'BLUE_ADDRESS'}" ;
1096 goto SETTINGS_ERROR
;
1099 if (& General
:: IpInSubnet
( $netsettings { 'ORANGE_ADDRESS' },
1100 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1101 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Orange Network $netsettings {'ORANGE_ADDRESS'}" ;
1102 goto SETTINGS_ERROR
;
1104 open ( ALIASES
, "${General::swroot}/ethernet/aliases" ) or die 'Unable to open aliases file.' ;
1108 my @tempalias = split ( /\,/ , $_ );
1109 if ( $tempalias [ 1 ] eq 'on' ) {
1110 if (& General
:: IpInSubnet
( $tempalias [ 0 ] ,
1111 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
1112 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire alias entry $tempalias [0]" ;
1117 if ( $errormessage ne '' ){
1118 goto SETTINGS_ERROR
;
1120 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
1121 $errormessage = $Lang :: tr
{ 'invalid input' };
1122 goto SETTINGS_ERROR
;
1124 if (( length ( $cgiparams { 'DMTU' })== 0 ) || (( $cgiparams { 'DMTU' }) < 1000 )) {
1125 $errormessage = $Lang :: tr
{ 'invalid mtu input' };
1126 goto SETTINGS_ERROR
;
1129 unless (& General
:: validport
( $cgiparams { 'DDEST_PORT' })) {
1130 $errormessage = $Lang :: tr
{ 'invalid port' };
1131 goto SETTINGS_ERROR
;
1134 $vpnsettings { 'ENABLED_BLUE' } = $cgiparams { 'ENABLED_BLUE' };
1135 $vpnsettings { 'ENABLED_ORANGE' } = $cgiparams { 'ENABLED_ORANGE' };
1136 $vpnsettings { 'ENABLED' } = $cgiparams { 'ENABLED' };
1137 $vpnsettings { 'VPN_IP' } = $cgiparams { 'VPN_IP' };
1138 #new settings for daemon
1139 $vpnsettings { 'DOVPN_SUBNET' } = $cgiparams { 'DOVPN_SUBNET' };
1140 $vpnsettings { 'DDEVICE' } = $cgiparams { 'DDEVICE' };
1141 $vpnsettings { 'DPROTOCOL' } = $cgiparams { 'DPROTOCOL' };
1142 $vpnsettings { 'DDEST_PORT' } = $cgiparams { 'DDEST_PORT' };
1143 $vpnsettings { 'DMTU' } = $cgiparams { 'DMTU' };
1144 $vpnsettings { 'DCOMPLZO' } = $cgiparams { 'DCOMPLZO' };
1145 $vpnsettings { 'DCIPHER' } = $cgiparams { 'DCIPHER' };
1148 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" );}
1149 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" );}
1150 if ( $vpnsettings { 'ENABLED' } eq 'on' ) { system ( "touch ${General::swroot}/ovpn/enable 2>/dev/null" );} else { system ( "unlink ${General::swroot}/ovpn/enable 2>/dev/null" );}
1151 #new settings for daemon
1152 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1153 & writeserverconf
(); #hier ok
1156 ### Reset all step 2
1158 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
1160 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1162 foreach my $key ( keys %confighash ) {
1163 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
1164 delete $confighash { $cgiparams { ' $key ' }};
1167 while ( $file = glob ( "${General::swroot}/ovpn/ca/*" )) {
1170 while ( $file = glob ( "${General::swroot}/ovpn/certs/*" )) {
1173 while ( $file = glob ( "${General::swroot}/ovpn/crls/*" )) {
1176 & cleanssldatabase
();
1177 if ( open ( FILE
, ">${General::swroot}/ovpn/caconfig" )) {
1181 if ( open ( FILE
, ">${General::swroot}/ovpn/ccdroute" )) {
1185 if ( open ( FILE
, ">${General::swroot}/ovpn/ccdroute2" )) {
1189 while ( $file = glob ( "${General::swroot}/ovpn/ccd/*" )) {
1192 if ( open ( FILE
, ">${General::swroot}/ovpn/ovpn-leases.db" )) {
1196 if ( open ( FILE
, ">${General::swroot}/ovpn/ovpnconfig" )) {
1200 while ( $file = glob ( "${General::swroot}/ovpn/n2nconf/*" )) {
1201 system ( "rm -rf $file " )
1204 ### Reset all step 1
1206 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove x509' }) {
1207 & Header
:: showhttpheaders
();
1208 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
1209 & Header
:: openbigbox
( '100%' , 'left' , '' , '' );
1210 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'are you sure' });
1212 <form method='post'>
1213 <table width='100%'>
1216 <input type='hidden' name='AREUSURE' value='yes' />
1217 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1218 $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}</td>
1221 <td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' />
1222 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td>
1228 & Header
:: closebox
();
1229 & Header
:: closebigbox
();
1230 & Header
:: closepage
();
1234 ### Generate DH key step 2
1236 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate dh key' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
1237 # Delete if old key exists
1238 if (- f
"${General::swroot}/ovpn/ca/ $cgiparams {'DH_NAME'}" ) {
1239 unlink "${General::swroot}/ovpn/ca/ $cgiparams {'DH_NAME'}" ;
1241 # Create Diffie Hellmann Parameter
1242 system ( '/usr/bin/openssl' , 'dhparam' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
1243 '-out' , "${General::swroot}/ovpn/ca/dh1024.pem" , " $cgiparams {'DHLENGHT'}" );
1245 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1246 unlink ( "${General::swroot}/ovpn/ca/dh1024.pem" );
1250 ### Generate DH key step 1
1252 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate dh key' }) {
1253 & Header
:: showhttpheaders
();
1254 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
1255 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1256 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'gen dh'}:" );
1258 <table width='100%'>
1260 <td width='15%'> </td> <td width='15%'></td> <td width='65%'></td>
1263 <td class='base'> $Lang ::tr{'ovpn dh'}:</td>
1265 <form method='post'><input type='hidden' name='AREUSURE' value='yes' />
1266 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
1267 <select name='DHLENGHT'>
1268 <option value='1024' $selected {'DHLENGHT'}{'1024'}>1024 $Lang ::tr{'bit'}</option>
1269 <option value='2048' $selected {'DHLENGHT'}{'2048'}>2048 $Lang ::tr{'bit'}</option>
1270 <option value='3072' $selected {'DHLENGHT'}{'3072'}>3072 $Lang ::tr{'bit'}</option>
1271 <option value='4096' $selected {'DHLENGHT'}{'4096'}>4096 $Lang ::tr{'bit'}</option>
1275 <tr><td colspan='4'><br></td></tr>
1277 <table width='100%'>
1279 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}:</font></b>
1280 $Lang ::tr{'dh key warn'}
1284 <td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'generate dh key'}' /></td>
1291 & Header
:: closebox
();
1292 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1293 & Header
:: closebigbox
();
1294 & Header
:: closepage
();
1300 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload dh key' }) {
1301 if ( $cgiparams { 'DH_NAME' } !~ /dh1024.pem/ ) {
1302 $errormessage = $Lang :: tr
{ 'dh name is invalid' };
1303 goto UPLOADCA_ERROR
;
1305 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1306 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1307 goto UPLOADCA_ERROR
;
1309 # Move uploaded dh key to a temporary file
1310 ( my $fh , my $filename ) = tempfile
( );
1311 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1313 goto UPLOADCA_ERROR
;
1315 my $temp = `/usr/bin/openssl dhparam -text -in $filename ` ;
1316 if ( $temp !~ /DH Parameters: \((1024|2048|3072|4096) bit\)/ ) {
1317 $errormessage = $Lang :: tr
{ 'not a valid dh key' };
1319 goto UPLOADCA_ERROR
;
1321 # Delete if old key exists
1322 if (- f
"${General::swroot}/ovpn/ca/ $cgiparams {'DH_NAME'}" ) {
1323 unlink "${General::swroot}/ovpn/ca/ $cgiparams {'DH_NAME'}" ;
1325 move
( $filename , "${General::swroot}/ovpn/ca/ $cgiparams {'DH_NAME'}" );
1327 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1329 goto UPLOADCA_ERROR
;
1334 ### Upload CA Certificate
1336 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
1337 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1339 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
1340 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
1341 goto UPLOADCA_ERROR
;
1344 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
1345 $errormessage = $Lang :: tr
{ 'name too long' };
1349 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
1350 $errormessage = $Lang :: tr
{ 'name is invalid' };
1351 goto UPLOADCA_ERROR
;
1354 # Check if there is no other entry with this name
1355 foreach my $key ( keys %cahash ) {
1356 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
1357 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
1358 goto UPLOADCA_ERROR
;
1362 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1363 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1364 goto UPLOADCA_ERROR
;
1366 # Move uploaded ca to a temporary file
1367 ( my $fh , my $filename ) = tempfile
( );
1368 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1370 goto UPLOADCA_ERROR
;
1372 my $temp = `/usr/bin/openssl x509 -text -in $filename ` ;
1373 if ( $temp !~ /CA:TRUE/i ) {
1374 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
1376 goto UPLOADCA_ERROR
;
1378 move
( $filename , "${General::swroot}/ovpn/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1380 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1382 goto UPLOADCA_ERROR
;
1386 my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/ $cgiparams {'CA_NAME'}cert.pem` ;
1387 $casubject =~ /Subject: (.*)[\n]/ ;
1389 $casubject =~ s
+/ Email
+, E
+;
1390 $casubject =~ s/ ST=/ S=/ ;
1391 $casubject = & Header
:: cleanhtml
( $casubject );
1393 my $key = & General
:: findhasharraykey
( \
%cahash );
1394 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
1395 $cahash { $key }[ 1 ] = $casubject ;
1396 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1397 # system('/usr/local/bin/ipsecctrl', 'R');
1402 ### Display ca certificate
1404 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
1405 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1407 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1408 & Header
:: showhttpheaders
();
1409 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
1410 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
1411 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'ca certificate'}:" );
1412 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
1413 $output = & Header
:: cleanhtml
( $output , "y" );
1414 print "<pre> $output </pre> \n " ;
1415 & Header
:: closebox
();
1416 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1417 & Header
:: closebigbox
();
1418 & Header
:: closepage
();
1421 $errormessage = $Lang :: tr
{ 'invalid key' };
1425 ### Download ca certificate
1427 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
1428 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1430 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1431 print "Content-Type: application/octet-stream \r\n " ;
1432 print "Content-Disposition: filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
1433 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
1436 $errormessage = $Lang :: tr
{ 'invalid key' };
1440 ### Remove ca certificate (step 2)
1442 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
1443 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1444 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1446 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1447 foreach my $key ( keys %confighash ) {
1448 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` ;
1449 if ( $test =~ /: OK/ ) {
1451 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1452 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
1453 # system('/usr/local/bin/ipsecctrl', 'D', $key);
1455 unlink ( "${General::swroot}/ovpn//certs/ $confighash { $key }[1]cert.pem" );
1456 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $key }[1].p12" );
1457 delete $confighash { $key };
1458 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1459 # &writeipsecfiles();
1462 unlink ( "${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
1463 delete $cahash { $cgiparams { 'KEY' }};
1464 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1465 # system('/usr/local/bin/ipsecctrl', 'R');
1467 $errormessage = $Lang :: tr
{ 'invalid key' };
1470 ### Remove ca certificate (step 1)
1472 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
1473 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1474 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1476 my $assignedcerts = 0 ;
1477 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1478 foreach my $key ( keys %confighash ) {
1479 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` ;
1480 if ( $test =~ /: OK/ ) {
1484 if ( $assignedcerts ) {
1485 & Header
:: showhttpheaders
();
1486 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
1487 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
1488 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'are you sure' });
1490 <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' />
1491 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
1492 <tr><td align='center'>
1493 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>: $assignedcerts
1494 $Lang ::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}
1495 <tr><td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
1496 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td></tr>
1500 & Header
:: closebox
();
1501 & Header
:: closebigbox
();
1502 & Header
:: closepage
();
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');
1511 $errormessage = $Lang :: tr
{ 'invalid key' };
1515 ### Display root certificate
1517 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
1518 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
1520 & Header
:: showhttpheaders
();
1521 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
1522 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1523 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
1524 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'root certificate'}:" );
1525 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem` ;
1527 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'host certificate'}:" );
1528 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem` ;
1530 $output = & Header
:: cleanhtml
( $output , "y" );
1531 print "<pre> $output </pre> \n " ;
1532 & Header
:: closebox
();
1533 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1534 & Header
:: closebigbox
();
1535 & Header
:: closepage
();
1539 ### Download root certificate
1541 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
1542 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
1543 print "Content-Type: application/octet-stream \r\n " ;
1544 print "Content-Disposition: filename=cacert.pem \r\n\r\n " ;
1545 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/cacert.pem` ;
1550 ### Download host certificate
1552 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
1553 if ( - f
"${General::swroot}/ovpn/certs/servercert.pem" ) {
1554 print "Content-Type: application/octet-stream \r\n " ;
1555 print "Content-Disposition: filename=servercert.pem \r\n\r\n " ;
1556 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/certs/servercert.pem` ;
1560 ### Form for generating a root certificate
1562 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
1563 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
1565 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1566 if (- f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
1567 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
1568 $cgiparams { 'ACTION' } = '' ;
1569 goto ROOTCERT_ERROR
;
1572 if (( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) && - e
"${General::swroot}/red/active" ) {
1573 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
1574 my $ipaddr = < IPADDR
>;
1577 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
1578 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
1579 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
1582 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
1584 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1585 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1586 goto ROOTCERT_ERROR
;
1589 # Move uploaded certificate request to a temporary file
1590 ( my $fh , my $filename ) = tempfile
( );
1591 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1593 goto ROOTCERT_ERROR
;
1596 # Create a temporary dirctory
1597 my $tempdir = tempdir
( CLEANUP
=> 1 );
1599 # Extract the CA certificate from the file
1600 my $pid = open ( OPENSSL
, "|-" );
1601 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1602 if ( $pid ) { # parent
1603 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1604 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1608 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1610 goto ROOTCERT_ERROR
;
1613 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-cacerts' , '-nokeys' ,
1615 '-out' , " $tempdir /cacert.pem" )) {
1616 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1618 goto ROOTCERT_ERROR
;
1622 # Extract the Host certificate from the file
1623 $pid = open ( OPENSSL
, "|-" );
1624 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1625 if ( $pid ) { # parent
1626 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1627 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1631 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1633 goto ROOTCERT_ERROR
;
1636 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-clcerts' , '-nokeys' ,
1638 '-out' , " $tempdir /hostcert.pem" )) {
1639 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1641 goto ROOTCERT_ERROR
;
1645 # Extract the Host key from the file
1646 $pid = open ( OPENSSL
, "|-" );
1647 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1648 if ( $pid ) { # parent
1649 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1650 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1654 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1656 goto ROOTCERT_ERROR
;
1659 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-nocerts' ,
1662 '-out' , " $tempdir /serverkey.pem" )) {
1663 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1665 goto ROOTCERT_ERROR
;
1669 move
( " $tempdir /cacert.pem" , "${General::swroot}/ovpn/ca/cacert.pem" );
1671 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1673 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1674 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1675 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1676 goto ROOTCERT_ERROR
;
1679 move
( " $tempdir /hostcert.pem" , "${General::swroot}/ovpn/certs/servercert.pem" );
1681 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1683 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1684 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1685 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1686 goto ROOTCERT_ERROR
;
1689 move
( " $tempdir /serverkey.pem" , "${General::swroot}/ovpn/certs/serverkey.pem" );
1691 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1693 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1694 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1695 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1696 goto ROOTCERT_ERROR
;
1699 goto ROOTCERT_SUCCESS
;
1701 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
1703 # Validate input since the form was submitted
1704 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
1705 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
1706 goto ROOTCERT_ERROR
;
1708 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
1709 $errormessage = $Lang :: tr
{ 'organization too long' };
1710 goto ROOTCERT_ERROR
;
1712 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1713 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1714 goto ROOTCERT_ERROR
;
1716 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
1717 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
1718 goto ROOTCERT_ERROR
;
1720 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
1721 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
1722 goto ROOTCERT_ERROR
;
1724 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
1725 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1726 goto ROOTCERT_ERROR
;
1728 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
1729 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1730 goto ROOTCERT_ERROR
;
1732 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1733 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1734 goto ROOTCERT_ERROR
;
1736 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1737 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1738 goto ROOTCERT_ERROR
;
1740 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1741 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1742 goto ROOTCERT_ERROR
;
1744 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1745 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1746 goto ROOTCERT_ERROR
;
1749 # Copy the cgisettings to vpnsettings and save the configfile
1750 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
1751 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
1752 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
1753 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
1754 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
1755 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
1756 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
1757 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1759 # Replace empty strings with a .
1760 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
1761 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
1762 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
1765 #system ('/bin/touch', "${General::swroot}/ovpn/gencanow");
1767 # Create the CA certificate
1768 my $pid = open ( OPENSSL
, "|-" );
1769 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1770 if ( $pid ) { # parent
1771 print OPENSSL
" $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1772 print OPENSSL
" $state \n " ;
1773 print OPENSSL
" $city \n " ;
1774 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1775 print OPENSSL
" $ou \n " ;
1776 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
1777 print OPENSSL
" $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1780 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1781 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1782 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1783 goto ROOTCERT_ERROR
;
1786 unless ( exec ( '/usr/bin/openssl' , 'req' , '-x509' , '-nodes' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
1787 '-days' , '999999' , '-newkey' , 'rsa:4096' ,
1788 '-keyout' , "${General::swroot}/ovpn/ca/cakey.pem" ,
1789 '-out' , "${General::swroot}/ovpn/ca/cacert.pem" ,
1790 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
1791 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1792 goto ROOTCERT_ERROR
;
1796 # Create the Host certificate request
1797 $pid = open ( OPENSSL
, "|-" );
1798 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1799 if ( $pid ) { # parent
1800 print OPENSSL
" $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1801 print OPENSSL
" $state \n " ;
1802 print OPENSSL
" $city \n " ;
1803 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1804 print OPENSSL
" $ou \n " ;
1805 print OPENSSL
" $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
1806 print OPENSSL
" $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1807 print OPENSSL
". \n " ;
1808 print OPENSSL
". \n " ;
1811 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1812 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1813 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1814 goto ROOTCERT_ERROR
;
1817 unless ( exec ( '/usr/bin/openssl' , 'req' , '-nodes' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
1818 '-newkey' , 'rsa:2048' ,
1819 '-keyout' , "${General::swroot}/ovpn/certs/serverkey.pem" ,
1820 '-out' , "${General::swroot}/ovpn/certs/serverreq.pem" ,
1821 '-extensions' , 'server' ,
1822 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
1823 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1824 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1825 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1826 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1827 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1828 goto ROOTCERT_ERROR
;
1832 # Sign the host certificate request
1833 system ( '/usr/bin/openssl' , 'ca' , '-days' , '999999' ,
1834 '-batch' , '-notext' ,
1835 '-in' , "${General::swroot}/ovpn/certs/serverreq.pem" ,
1836 '-out' , "${General::swroot}/ovpn/certs/servercert.pem" ,
1837 '-extensions' , 'server' ,
1838 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
1840 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1841 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1842 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1843 unlink ( "${General::swroot}/ovpn/serverkey.pem" );
1844 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1845 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1846 & newcleanssldatabase
();
1847 goto ROOTCERT_ERROR
;
1849 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1850 & deletebackupcert
();
1853 # Create an empty CRL
1854 system ( '/usr/bin/openssl' , 'ca' , '-gencrl' ,
1855 '-out' , "${General::swroot}/ovpn/crls/cacrl.pem" ,
1856 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
1858 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1859 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1860 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1861 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1862 unlink ( "${General::swroot}/ovpn/crls/cacrl.pem" );
1863 & cleanssldatabase
();
1864 goto ROOTCERT_ERROR
;
1866 # &cleanssldatabase();
1868 # Create Diffie Hellmann Parameter
1869 system ( '/usr/bin/openssl' , 'dhparam' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
1870 '-out' , "${General::swroot}/ovpn/ca/dh1024.pem" , " $cgiparams {'DHLENGHT'}" );
1872 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1873 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1874 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1875 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1876 unlink ( "${General::swroot}/ovpn/crls/cacrl.pem" );
1877 unlink ( "${General::swroot}/ovpn/ca/dh1024.pem" );
1878 & cleanssldatabase
();
1879 goto ROOTCERT_ERROR
;
1881 # &cleanssldatabase();
1883 goto ROOTCERT_SUCCESS
;
1886 if ( $cgiparams { 'ACTION' } ne '' ) {
1887 & Header
:: showhttpheaders
();
1888 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
1889 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1890 if ( $errormessage ) {
1891 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
1892 print "<class name='base'> $errormessage " ;
1893 print " </class>" ;
1894 & Header
:: closebox
();
1896 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'generate root/host certificates'}:" );
1898 <form method='post' enctype='multipart/form-data'>
1899 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1900 <tr><td width='30%' class='base'> $Lang ::tr{'organization name'}:</td>
1901 <td width='35%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td>
1902 <td width='35%' colspan='2'> </td></tr>
1903 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}:</td>
1904 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td>
1905 <td colspan='2'> </td></tr>
1906 <tr><td class='base'> $Lang ::tr{'your e-mail'}: <img src='/blob.gif' alt'*' /></td>
1907 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td>
1908 <td colspan='2'> </td></tr>
1909 <tr><td class='base'> $Lang ::tr{'your department'}: <img src='/blob.gif' alt'*' /></td>
1910 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td>
1911 <td colspan='2'> </td></tr>
1912 <tr><td class='base'> $Lang ::tr{'city'}: <img src='/blob.gif' alt'*' /></td>
1913 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td>
1914 <td colspan='2'> </td></tr>
1915 <tr><td class='base'> $Lang ::tr{'state or province'}: <img src='/blob.gif' alt'*' /></td>
1916 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td>
1917 <td colspan='2'> </td></tr>
1918 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1919 <td class='base'><select name='ROOTCERT_COUNTRY'>
1923 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1924 print "<option value=' $Countries ::countries{ $country }'" ;
1925 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1926 print " selected='selected'" ;
1928 print "> $country </option>" ;
1932 <tr><td class='base'> $Lang ::tr{'ovpn dh'}:</td>
1933 <td class='base'><select name='DHLENGHT'>
1934 <option value='1024' $selected {'DHLENGHT'}{'1024'}>1024 $Lang ::tr{'bit'}</option>
1935 <option value='2048' $selected {'DHLENGHT'}{'2048'}>2048 $Lang ::tr{'bit'}</option>
1936 <option value='3072' $selected {'DHLENGHT'}{'3072'}>3072 $Lang ::tr{'bit'}</option>
1937 <option value='4096' $selected {'DHLENGHT'}{'4096'}>4096 $Lang ::tr{'bit'}</option>
1943 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /></td>
1944 <td> </td><td> </td></tr>
1945 <tr><td class='base' colspan='4' align='left'>
1946 <img src='/blob.gif' valign='top' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
1947 <tr><td colspan='4'><br><br></td></tr>
1948 <tr><td class='base' colspan='4' align='center'>
1949 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}:</font></b>
1950 $Lang ::tr{'ovpn generating the root and host certificates'}
1953 <tr><td class='base' colspan='4' align='center'>
1954 $Lang ::tr{'dh key warn'}
1958 <tr><td colspan='4'><hr></td></tr>
1959 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}:</td>
1960 <td nowrap='nowrap'><input type='file' name='FH' size='32'></td>
1961 <td colspan='2'> </td></tr>
1962 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' ></td>
1963 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td>
1964 <td colspan='2'> </td></tr>
1966 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td>
1967 <td colspan='2'> </td></tr>
1968 <tr><td class='base' colspan='4' align='left'>
1969 <img src='/blob.gif' valign='top' al='*' > $Lang ::tr{'this field may be blank'}</td>
1974 & Header
:: closebox
();
1975 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1976 & Header
:: closebigbox
();
1977 & Header
:: closepage
();
1982 system ( "chmod 600 ${General::swroot}/ovpn/certs/serverkey.pem" );
1983 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1984 # $vpnsettings{'ENABLE_BLUE'} eq 'on') {
1985 # system('/usr/local/bin/ipsecctrl', 'S');
1989 ### Enable/Disable connection
1996 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1998 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1999 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2000 # my $n2nactive = '';
2001 my $n2nactive = `/bin/ps ax|grep $confighash { $cgiparams {'KEY'}}[1]|grep -v grep|awk \' {print \ $1 } \' ` ;
2003 if ( $confighash { $cgiparams { 'KEY' }}) {
2004 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
2005 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
2006 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2008 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
2009 system ( '/usr/local/bin/openvpnctrl' , '-sn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
2013 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
2014 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2016 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
2017 if ( $n2nactive ne '' ){
2018 system ( '/usr/local/bin/openvpnctrl' , '-kn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
2022 $errormessage = $Lang :: tr
{ 'invalid key' };
2028 ### Download OpenVPN client package
2032 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'dl client arch' }) {
2033 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2034 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2036 my $clientovpn = '' ;
2038 my $tempdir = tempdir
( CLEANUP
=> 1 );
2039 my $zippath = " $tempdir /" ;
2045 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
2047 my $zipname = " $confighash { $cgiparams {'KEY'}}[1]-Client.zip" ;
2048 my $zippathname = " $zippath $zipname " ;
2049 $clientovpn = " $confighash { $cgiparams {'KEY'}}[1].conf" ;
2050 my @ovsubnettemp = split ( /\./ , $confighash { $cgiparams { 'KEY' }}[ 27 ]);
2051 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
2053 my @remsubnet = split ( /\/ /, $confighash { $cgiparams { 'KEY' }}[ 8 ]);
2054 my $n2nfragment = '' ;
2056 open ( CLIENTCONF
, "> $tempdir / $clientovpn " ) or die "Unable to open tempfile: $!" ;
2057 flock CLIENTCONF
, 2 ;
2059 my $zip = Archive
:: Zip
-> new ();
2060 print CLIENTCONF
"# IPFire n2n Open VPN Client Config by ummeegge und m.a.d \n " ;
2061 print CLIENTCONF
"# \n " ;
2062 print CLIENTCONF
"# User Security \n " ;
2063 print CLIENTCONF
"user nobody \n " ;
2064 print CLIENTCONF
"group nobody \n " ;
2065 print CLIENTCONF
"persist-tun \n " ;
2066 print CLIENTCONF
"persist-key \n " ;
2067 print CLIENTCONF
"script-security 2 \n " ;
2068 print CLIENTCONF
"# IP/DNS for remote Server Gateway \n " ;
2069 print CLIENTCONF
"remote $vpnsettings {'VPN_IP'} \n " ;
2070 print CLIENTCONF
"float \n " ;
2071 print CLIENTCONF
"# IP adresses of the VPN Subnet \n " ;
2072 print CLIENTCONF
"ifconfig $ovsubnet .2 $ovsubnet .1 \n " ;
2073 print CLIENTCONF
"# Server Gateway Network \n " ;
2074 print CLIENTCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
2075 print CLIENTCONF
"# tun Device \n " ;
2076 print CLIENTCONF
"dev $vpnsettings {'DDEVICE'} \n " ;
2077 print CLIENTCONF
"# Port and Protokoll \n " ;
2078 print CLIENTCONF
"port $confighash { $cgiparams {'KEY'}}[29] \n " ;
2080 if ( $confighash { $cgiparams { 'KEY' }}[ 28 ] eq 'tcp' ) {
2081 print CLIENTCONF
"proto tcp-client \n " ;
2082 print CLIENTCONF
"# Packet size \n " ;
2083 if ( $confighash { $cgiparams { 'KEY' }}[ 31 ] eq '' ) { $tunmtu = '1400' } else { $tunmtu = $confighash { $cgiparams { 'KEY' }}[ 31 ]};
2084 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
2087 if ( $confighash { $cgiparams { 'KEY' }}[ 28 ] eq 'udp' ) {
2088 print CLIENTCONF
"proto udp \n " ;
2089 print CLIENTCONF
"# Paketsize \n " ;
2090 if ( $confighash { $cgiparams { 'KEY' }}[ 31 ] eq '' ) { $tunmtu = '1500' } else { $tunmtu = $confighash { $cgiparams { 'KEY' }}[ 31 ]};
2091 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
2092 if ( $confighash { $cgiparams { 'KEY' }}[ 24 ] ne '' ) { print CLIENTCONF
"fragment $confighash { $cgiparams {'KEY'}}[24] \n " ;}
2093 if ( $confighash { $cgiparams { 'KEY' }}[ 23 ] eq 'on' ) { print CLIENTCONF
"mssfix \n " ;}
2095 if (( $confighash { $cgiparams { 'KEY' }}[ 38 ] eq 'yes' ) ||
2096 ( $confighash { $cgiparams { 'KEY' }}[ 38 ] eq 'maybe' ) ||
2097 ( $confighash { $cgiparams { 'KEY' }}[ 38 ] eq 'no' )) {
2098 if (( $confighash { $cgiparams { 'KEY' }}[ 23 ] ne 'on' ) || ( $confighash { $cgiparams { 'KEY' }}[ 24 ] eq '' )) {
2099 if ( $tunmtu eq '1500' ) {
2100 print CLIENTCONF
"mtu-disc $confighash { $cgiparams {'KEY'}}[38] \n " ;
2104 print CLIENTCONF
"ns-cert-type server \n " ;
2105 print CLIENTCONF
"# Auth. Client \n " ;
2106 print CLIENTCONF
"tls-client \n " ;
2107 print CLIENTCONF
"# Cipher \n " ;
2108 print CLIENTCONF
"cipher $confighash { $cgiparams {'KEY'}}[40] \n " ;
2109 print CLIENTCONF
"# HMAC algorithm \n " ;
2110 print CLIENTCONF
"auth $confighash { $cgiparams {'KEY'}}[39] \n " ;
2111 if ( $confighash { $cgiparams { 'KEY' }}[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ) {
2112 print CLIENTCONF
"pkcs12 ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12 \r\n " ;
2113 $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 " ;
2115 if ( $confighash { $cgiparams { 'KEY' }}[ 30 ] eq 'on' ) {
2116 print CLIENTCONF
"# Enable Compression \n " ;
2117 print CLIENTCONF
"comp-lzo \r\n " ;
2119 print CLIENTCONF
"# Debug Level \n " ;
2120 print CLIENTCONF
"verb 3 \n " ;
2121 print CLIENTCONF
"# Tunnel check \n " ;
2122 print CLIENTCONF
"keepalive 10 60 \n " ;
2123 print CLIENTCONF
"# Start as daemon \n " ;
2124 print CLIENTCONF
"daemon $confighash { $cgiparams {'KEY'}}[1]n2n \n " ;
2125 print CLIENTCONF
"writepid /var/run/ $confighash { $cgiparams {'KEY'}}[1]n2n.pid \n " ;
2126 print CLIENTCONF
"# Activate Management Interface and Port \n " ;
2127 if ( $confighash { $cgiparams { 'KEY' }}[ 22 ] eq '' ) { print CLIENTCONF
"management localhost $confighash { $cgiparams {'KEY'}}[29] \n " }
2128 else { print CLIENTCONF
"management localhost $confighash { $cgiparams {'KEY'}}[22] \n " };
2129 print CLIENTCONF
"# remsub $confighash { $cgiparams {'KEY'}}[11] \n " ;
2134 $zip -> addFile ( " $tempdir / $clientovpn " , $clientovpn ) or die "Can't add file $clientovpn \n " ;
2135 my $status = $zip -> writeToFileNamed ( $zippathname );
2137 open ( DLFILE
, "< $zippathname " ) or die "Unable to open $zippathname : $!" ;
2138 @fileholder = < DLFILE
>;
2139 print "Content-Type:application/x-download \n " ;
2140 print "Content-Disposition:attachment;filename= $zipname \n\n " ;
2146 my $zipname = " $confighash { $cgiparams {'KEY'}}[1]-TO-IPFire.zip" ;
2147 my $zippathname = " $zippath $zipname " ;
2148 $clientovpn = " $confighash { $cgiparams {'KEY'}}[1]-TO-IPFire.ovpn" ;
2154 open ( CLIENTCONF
, "> $tempdir / $clientovpn " ) or die "Unable to open tempfile: $!" ;
2155 flock CLIENTCONF
, 2 ;
2157 my $zip = Archive
:: Zip
-> new ();
2159 print CLIENTCONF
"#OpenVPN Client conf \r\n " ;
2160 print CLIENTCONF
"tls-client \r\n " ;
2161 print CLIENTCONF
"client \r\n " ;
2162 print CLIENTCONF
"nobind \r\n " ;
2163 print CLIENTCONF
"dev $vpnsettings {'DDEVICE'} \r\n " ;
2164 print CLIENTCONF
"proto $vpnsettings {'DPROTOCOL'} \r\n " ;
2166 # Check if we are using fragment, mssfix or mtu-disc and set MTU to 1500
2167 # or use configured value.
2168 if ( $vpnsettings { FRAGMENT
} ne '' && $vpnsettings { DPROTOCOL
} ne 'tcp' )
2169 { print CLIENTCONF
" $vpnsettings {'DDEVICE'}-mtu 1500 \r\n " ; }
2170 elsif ( $vpnsettings { MSSFIX
} eq 'on' )
2171 { print CLIENTCONF
" $vpnsettings {'DDEVICE'}-mtu 1500 \r\n " ; }
2172 elsif (( $vpnsettings { 'PMTU_DISCOVERY' } eq 'yes' ) ||
2173 ( $vpnsettings { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
2174 ( $vpnsettings { 'PMTU_DISCOVERY' } eq 'no' ))
2175 { print CLIENTCONF
" $vpnsettings {'DDEVICE'}-mtu 1500 \r\n " ; }
2177 { print CLIENTCONF
" $vpnsettings {'DDEVICE'}-mtu $vpnsettings {'DMTU'} \r\n " ; }
2179 if ( $vpnsettings { 'ENABLED' } eq 'on' ){
2180 print CLIENTCONF
"remote $vpnsettings {'VPN_IP'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2181 if ( $vpnsettings { 'ENABLED_BLUE' } eq 'on' && (& haveBlueNet
())){
2182 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Blue interface \r\n " ;
2183 print CLIENTCONF
";remote $netsettings {'BLUE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2185 if ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
2186 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Orange interface \r\n " ;
2187 print CLIENTCONF
";remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2189 } elsif ( $vpnsettings { 'ENABLED_BLUE' } eq 'on' && (& haveBlueNet
())){
2190 print CLIENTCONF
"remote $netsettings {'BLUE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2191 if ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
2192 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Orange interface \r\n " ;
2193 print CLIENTCONF
";remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2195 } elsif ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
2196 print CLIENTCONF
"remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
2199 if ( $confighash { $cgiparams { 'KEY' }}[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ) {
2200 print CLIENTCONF
"pkcs12 $confighash { $cgiparams {'KEY'}}[1].p12 \r\n " ;
2201 $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 " ;
2203 print CLIENTCONF
"ca cacert.pem \r\n " ;
2204 print CLIENTCONF
"cert $confighash { $cgiparams {'KEY'}}[1]cert.pem \r\n " ;
2205 print CLIENTCONF
"key $confighash { $cgiparams {'KEY'}}[1].key \r\n " ;
2206 $zip -> addFile ( "${General::swroot}/ovpn/ca/cacert.pem" , "cacert.pem" ) or die "Can't add file cacert.pem \n " ;
2207 $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 " ;
2209 print CLIENTCONF
"cipher $vpnsettings {DCIPHER} \r\n " ;
2210 if ( $vpnsettings { 'DAUTH' } eq '' ) {
2211 print CLIENTCONF
"" ;
2213 print CLIENTCONF
"auth $vpnsettings {'DAUTH'} \r\n " ;
2215 if ( $vpnsettings { DCOMPLZO
} eq 'on' ) {
2216 print CLIENTCONF
"comp-lzo \r\n " ;
2218 print CLIENTCONF
"verb 3 \r\n " ;
2219 print CLIENTCONF
"ns-cert-type server \r\n " ;
2220 print CLIENTCONF
"tls-remote $vpnsettings {ROOTCERT_HOSTNAME} \r\n " ;
2221 if ( $vpnsettings { MSSFIX
} eq 'on' ) {
2222 print CLIENTCONF
"mssfix \r\n " ;
2224 if ( $vpnsettings { FRAGMENT
} ne '' && $vpnsettings { DPROTOCOL
} ne 'tcp' ) {
2225 print CLIENTCONF
"fragment $vpnsettings {'FRAGMENT'} \r\n " ;
2228 # Check if a valid operating mode has been choosen and use it.
2229 if (( $vpnsettings { 'PMTU_DISCOVERY' } eq 'yes' ) ||
2230 ( $vpnsettings { 'PMTU_DISCOVERY' } eq 'maybe' ) ||
2231 ( $vpnsettings { 'PMTU_DISCOVERY' } eq 'no' )) {
2232 if (( $vpnsettings { MSSFIX
} ne 'on' ) || ( $vpnsettings { FRAGMENT
} eq '' )) {
2233 print CLIENTCONF
"mtu-disc $vpnsettings {'PMTU_DISCOVERY'} \r\n " ;
2238 $zip -> addFile ( " $tempdir / $clientovpn " , $clientovpn ) or die "Can't add file $clientovpn \n " ;
2239 my $status = $zip -> writeToFileNamed ( $zippathname );
2241 open ( DLFILE
, "< $zippathname " ) or die "Unable to open $zippathname : $!" ;
2242 @fileholder = < DLFILE
>;
2243 print "Content-Type:application/x-download \n " ;
2244 print "Content-Disposition:attachment;filename= $zipname \n\n " ;
2252 ### Remove connection
2256 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
2257 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2258 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2260 if ( $confighash { $cgiparams { 'KEY' }}) {
2261 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2262 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2263 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
2266 my $temp = `/usr/bin/openssl ca -revoke ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf` ;
2272 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ) {
2273 my $conffile = glob ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]/ $confighash { $cgiparams {'KEY'}}[1].conf" );
2274 my $certfile = glob ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
2278 if (- e
"${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]" ) {
2279 rmdir ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]" ) || die "Kann Verzeichnis nicht loeschen: $!" ;
2283 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
2284 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
2286 # A.Marx CCD delete ccd files and routes
2289 if (- f
"${General::swroot}/ovpn/ccd/ $confighash { $cgiparams {'KEY'}}[2]" )
2291 unlink "${General::swroot}/ovpn/ccd/ $confighash { $cgiparams {'KEY'}}[2]" ;
2294 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
2295 foreach my $key ( keys %ccdroutehash ) {
2296 if ( $ccdroutehash { $key }[ 0 ] eq $confighash { $cgiparams { 'KEY' }}[ 1 ]){
2297 delete $ccdroutehash { $key };
2300 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
2302 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
2303 foreach my $key ( keys %ccdroute2hash ) {
2304 if ( $ccdroute2hash { $key }[ 0 ] eq $confighash { $cgiparams { 'KEY' }}[ 1 ]){
2305 delete $ccdroute2hash { $key };
2308 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
2315 delete $confighash { $cgiparams { 'KEY' }};
2316 my $temp2 = `/usr/bin/openssl ca -gencrl -out ${General::swroot}/ovpn/crls/cacrl.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf` ;
2317 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2319 #&writeserverconf();
2321 $errormessage = $Lang :: tr
{ 'invalid key' };
2324 & General
:: firewall_reload
();
2327 ### Download PKCS12 file
2329 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
2330 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2332 print "Content-Disposition: filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
2333 print "Content-Type: application/octet-stream \r\n\r\n " ;
2334 print `/bin/cat ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12` ;
2338 ### Display certificate
2340 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
2341 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2343 if ( - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
2344 & Header
:: showhttpheaders
();
2345 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
2346 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2347 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'certificate'}:" );
2348 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
2349 $output = & Header
:: cleanhtml
( $output , "y" );
2350 print "<pre> $output </pre> \n " ;
2351 & Header
:: closebox
();
2352 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2353 & Header
:: closebigbox
();
2354 & Header
:: closepage
();
2359 ### Display Diffie-Hellman key
2361 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show dh' }) {
2363 if (! - e
"${General::swroot}/ovpn/ca/dh1024.pem" ) {
2364 $errormessage = $Lang :: tr
{ 'not present' };
2366 & Header
:: showhttpheaders
();
2367 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
2368 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2369 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'dh'}:" );
2370 my $output = `/usr/bin/openssl dhparam -text -in ${General::swroot}/ovpn/ca/dh1024.pem` ;
2371 $output = & Header
:: cleanhtml
( $output , "y" );
2372 print "<pre> $output </pre> \n " ;
2373 & Header
:: closebox
();
2374 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2375 & Header
:: closebigbox
();
2376 & Header
:: closepage
();
2381 ### Display Certificate Revoke List
2383 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show crl' }) {
2384 # &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2386 if (! - e
"${General::swroot}/ovpn/crls/cacrl.pem" ) {
2387 $errormessage = $Lang :: tr
{ 'not present' };
2389 & Header
:: showhttpheaders
();
2390 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
2391 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2392 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'crl'}:" );
2393 my $output = `/usr/bin/openssl crl -text -noout -in ${General::swroot}/ovpn/crls/cacrl.pem` ;
2394 $output = & Header
:: cleanhtml
( $output , "y" );
2395 print "<pre> $output </pre> \n " ;
2396 & Header
:: closebox
();
2397 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2398 & Header
:: closebigbox
();
2399 & Header
:: closepage
();
2404 ### Advanced Server Settings
2407 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced server' }) {
2412 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%cgiparams );
2416 # if ($cgiparams{'CLIENT2CLIENT'} eq '') {
2417 # $cgiparams{'CLIENT2CLIENT'} = 'on';
2420 if ( $cgiparams { 'MAX_CLIENTS' } eq '' ) {
2421 $cgiparams { 'MAX_CLIENTS' } = '100' ;
2423 if ( $cgiparams { 'KEEPALIVE_1' } eq '' ) {
2424 $cgiparams { 'KEEPALIVE_1' } = '10' ;
2426 if ( $cgiparams { 'KEEPALIVE_2' } eq '' ) {
2427 $cgiparams { 'KEEPALIVE_2' } = '60' ;
2429 if ( $cgiparams { 'LOG_VERB' } eq '' ) {
2430 $cgiparams { 'LOG_VERB' } = '3' ;
2432 if ( $cgiparams { 'PMTU_DISCOVERY' } eq '' ) {
2433 $cgiparams { 'PMTU_DISCOVERY' } = 'off' ;
2435 if ( $cgiparams { 'DAUTH' } eq '' ) {
2436 $cgiparams { 'DAUTH' } = 'SHA1' ;
2438 $checked { 'CLIENT2CLIENT' }{ 'off' } = '' ;
2439 $checked { 'CLIENT2CLIENT' }{ 'on' } = '' ;
2440 $checked { 'CLIENT2CLIENT' }{ $cgiparams { 'CLIENT2CLIENT' }} = 'CHECKED' ;
2441 $checked { 'REDIRECT_GW_DEF1' }{ 'off' } = '' ;
2442 $checked { 'REDIRECT_GW_DEF1' }{ 'on' } = '' ;
2443 $checked { 'REDIRECT_GW_DEF1' }{ $cgiparams { 'REDIRECT_GW_DEF1' }} = 'CHECKED' ;
2444 $checked { 'MSSFIX' }{ 'off' } = '' ;
2445 $checked { 'MSSFIX' }{ 'on' } = '' ;
2446 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
2447 $checked { 'PMTU_DISCOVERY' }{ $cgiparams { 'PMTU_DISCOVERY' }} = 'checked= \' checked \' ' ;
2448 $selected { 'LOG_VERB' }{ '1' } = '' ;
2449 $selected { 'LOG_VERB' }{ '2' } = '' ;
2450 $selected { 'LOG_VERB' }{ '3' } = '' ;
2451 $selected { 'LOG_VERB' }{ '4' } = '' ;
2452 $selected { 'LOG_VERB' }{ '5' } = '' ;
2453 $selected { 'LOG_VERB' }{ '6' } = '' ;
2454 $selected { 'LOG_VERB' }{ '7' } = '' ;
2455 $selected { 'LOG_VERB' }{ '8' } = '' ;
2456 $selected { 'LOG_VERB' }{ '9' } = '' ;
2457 $selected { 'LOG_VERB' }{ '10' } = '' ;
2458 $selected { 'LOG_VERB' }{ '11' } = '' ;
2459 $selected { 'LOG_VERB' }{ '0' } = '' ;
2460 $selected { 'LOG_VERB' }{ $cgiparams { 'LOG_VERB' }} = 'SELECTED' ;
2461 $selected { 'DAUTH' }{ 'whirlpool' } = '' ;
2462 $selected { 'DAUTH' }{ 'SHA512' } = '' ;
2463 $selected { 'DAUTH' }{ 'SHA384' } = '' ;
2464 $selected { 'DAUTH' }{ 'SHA256' } = '' ;
2465 $selected { 'DAUTH' }{ 'ecdsa-with-SHA1' } = '' ;
2466 $selected { 'DAUTH' }{ 'SHA1' } = '' ;
2467 $selected { 'DAUTH' }{ $cgiparams { 'DAUTH' }} = 'SELECTED' ;
2469 & Header
:: showhttpheaders
();
2470 & Header
:: openpage
( $Lang :: tr
{ 'status ovpn' }, 1 , '' );
2471 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
2472 if ( $errormessage ) {
2473 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
2474 print "<class name='base'> $errormessage \n " ;
2475 print " </class> \n " ;
2476 & Header
:: closebox
();
2478 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'advanced server' });
2480 <form method='post' enctype='multipart/form-data'>
2481 <table width='100%' border='0'>
2483 <td colspan='4'><b> $Lang ::tr{'dhcp-options'}</b></td>
2486 <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
2489 <td class='base'>Domain</td>
2490 <td><input type='TEXT' name='DHCP_DOMAIN' value=' $cgiparams {'DHCP_DOMAIN'}' size='30' /></td>
2493 <td class='base'>DNS</td>
2494 <td><input type='TEXT' name='DHCP_DNS' value=' $cgiparams {'DHCP_DNS'}' size='30' /></td>
2497 <td class='base'>WINS</td>
2498 <td><input type='TEXT' name='DHCP_WINS' value=' $cgiparams {'DHCP_WINS'}' size='30' /></td>
2501 <td colspan='4'><b> $Lang ::tr{'ovpn routes push options'}</b></td>
2504 <td class='base'> $Lang ::tr{'ovpn routes push'}</td>
2506 <textarea name='ROUTES_PUSH' cols='26' rows='6' wrap='off'>
2510 if ( $cgiparams { 'ROUTES_PUSH' } ne '' )
2512 print $cgiparams { 'ROUTES_PUSH' };
2521 <table width='100%'>
2523 <td class'base'><b> $Lang ::tr{'misc-options'}</b></td>
2526 <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='15%'></td><td width='35%'></td>
2529 <td class='base'>Client-To-Client</td>
2530 <td><input type='checkbox' name='CLIENT2CLIENT' $checked {'CLIENT2CLIENT'}{'on'} /></td>
2533 <td class='base'>Redirect-Gateway def1</td>
2534 <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked {'REDIRECT_GW_DEF1'}{'on'} /></td>
2537 <td class='base'>Max-Clients</td>
2538 <td><input type='text' name='MAX_CLIENTS' value=' $cgiparams {'MAX_CLIENTS'}' size='10' /></td>
2541 <td class='base'>Keepalive <br />
2542 (ping/ping-restart)</td>
2543 <td><input type='TEXT' name='KEEPALIVE_1' value=' $cgiparams {'KEEPALIVE_1'}' size='10' /></td>
2544 <td><input type='TEXT' name='KEEPALIVE_2' value=' $cgiparams {'KEEPALIVE_2'}' size='10' /></td>
2547 <td class='base'>fragment <br></td>
2548 <td><input type='TEXT' name='FRAGMENT' value=' $cgiparams {'FRAGMENT'}' size='10' /></td>
2551 <td class='base'>mssfix</td>
2552 <td><input type='checkbox' name='MSSFIX' $checked {'MSSFIX'}{'on'} /></td>
2553 <td> $Lang ::tr{'openvpn default'}: on</td>
2556 <td class='base'> $Lang ::tr{'ovpn mtu-disc'}</td>
2557 <td><input type='radio' name='PMTU_DISCOVERY' value='yes' $checked {'PMTU_DISCOVERY'}{'yes'} /> $Lang ::tr{'ovpn mtu-disc yes'}</td>
2558 <td><input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked {'PMTU_DISCOVERY'}{'maybe'} /> $Lang ::tr{'ovpn mtu-disc maybe'}</td>
2559 <td><input type='radio' name='PMTU_DISCOVERY' value='no' $checked {'PMTU_DISCOVERY'}{'no'} /> $Lang ::tr{'ovpn mtu-disc no'}</td>
2560 <td><input type='radio' name='PMTU_DISCOVERY' value='off' $checked {'PMTU_DISCOVERY'}{'off'} /> $Lang ::tr{'ovpn mtu-disc off'}</td>
2565 <table width='100%'>
2567 <td class'base'><b> $Lang ::tr{'log-options'}</b></td>
2570 <td width='20%'></td> <td width='30%'> </td><td width='25%'> </td><td width='25%'></td>
2573 <tr><td class='base'>VERB</td>
2574 <td><select name='LOG_VERB'>
2575 <option value='0' $selected {'LOG_VERB'}{'0'}>0</option>
2576 <option value='1' $selected {'LOG_VERB'}{'1'}>1</option>
2577 <option value='2' $selected {'LOG_VERB'}{'2'}>2</option>
2578 <option value='3' $selected {'LOG_VERB'}{'3'}>3</option>
2579 <option value='4' $selected {'LOG_VERB'}{'4'}>4</option>
2580 <option value='5' $selected {'LOG_VERB'}{'5'}>5</option>
2581 <option value='6' $selected {'LOG_VERB'}{'6'}>6</option>
2582 <option value='7' $selected {'LOG_VERB'}{'7'}>7</option>
2583 <option value='8' $selected {'LOG_VERB'}{'8'}>8</option>
2584 <option value='9' $selected {'LOG_VERB'}{'9'}>9</option>
2585 <option value='10' $selected {'LOG_VERB'}{'10'}>10</option>
2586 <option value='11' $selected {'LOG_VERB'}{'11'}>11</option>
2593 <table width='100%'>
2595 <td class'base'><b> $Lang ::tr{'ovpn crypt options'}</b></td>
2598 <td width='20%'></td> <td width='30%'> </td><td width='25%'> </td><td width='25%'></td>
2600 <tr><td class='base'> $Lang ::tr{'ovpn ha'}</td>
2601 <td><select name='DAUTH'>
2602 <option value='whirlpool' $selected {'DAUTH'}{'whirlpool'}>Whirlpool (512 $Lang ::tr{'bit'})</option>
2603 <option value='SHA512' $selected {'DAUTH'}{'SHA512'}>SHA2 (512 $Lang ::tr{'bit'})</option>
2604 <option value='SHA384' $selected {'DAUTH'}{'SHA384'}>SHA2 (384 $Lang ::tr{'bit'})</option>
2605 <option value='SHA256' $selected {'DAUTH'}{'SHA256'}>SHA2 (256 $Lang ::tr{'bit'})</option>
2606 <option value='ecdsa-with-SHA1' $selected {'DAUTH'}{'ecdsa-with-SHA1'}>ECDSA-SHA1 (160 $Lang ::tr{'bit'})</option>
2607 <option value='SHA1' $selected {'DAUTH'}{'SHA1'}>SHA1 (160 $Lang ::tr{'bit'})</option>
2610 <td>Default: <span class="base">SHA1 (160 $Lang ::tr{'bit'})</span></td>
2615 if ( - e
"/var/run/openvpn.pid" ){
2616 print " <br><b><font color='#990000'> $Lang ::tr{'attention'}:</b></font><br>
2617 $Lang ::tr{'server restart'}<br><br>
2620 <table width='100%'>
2623 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save-adv-options'}' disabled='disabled' /></td>
2624 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'cancel-adv-options'}' /></td>
2636 <table width='100%'>
2639 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save-adv-options'}' /></td>
2640 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'cancel-adv-options'}' /></td>
2648 & Header
:: closebox
();
2649 # print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
2650 & Header
:: closebigbox
();
2651 & Header
:: closepage
();
2655 # A.Marx CCD Add,delete or edit CCD net
2657 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ccd net' } ||
2658 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ccd add' } ||
2659 $cgiparams { 'ACTION' } eq "kill" ||
2660 $cgiparams { 'ACTION' } eq "edit" ||
2661 $cgiparams { 'ACTION' } eq 'editsave' ){
2662 & Header
:: showhttpheaders
();
2663 & Header
:: openpage
( $Lang :: tr
{ 'ccd net' }, 1 , '' );
2664 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2666 if ( $cgiparams { 'ACTION' } eq "kill" ){
2667 & delccdnet
( $cgiparams { 'net' });
2670 if ( $cgiparams { 'ACTION' } eq 'editsave' ){
2671 my ( $a , $b ) = split ( /\|/ , $cgiparams { 'ccdname' });
2672 if ( $a ne $b ){ & modccdnet
( $a , $b );}
2673 $cgiparams { 'ccdname' }= '' ;
2674 $cgiparams { 'ccdsubnet' }= '' ;
2677 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ccd add' }) {
2678 & addccdnet
( $cgiparams { 'ccdname' }, $cgiparams { 'ccdsubnet' });
2680 if ( $errormessage ) {
2681 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
2682 print "<class name='base'> $errormessage " ;
2683 print " </class>" ;
2684 & Header
:: closebox
();
2686 if ( $cgiparams { 'ACTION' } eq "edit" ){
2688 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd modify' });
2691 <table width='100%' border='0'>
2692 <tr><form method='post'>
2693 <td width='10%' nowrap='nowrap'> $Lang ::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value=' $cgiparams {'ccdname'}' /></td>
2694 <td width='8%'> $Lang ::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value=' $cgiparams {'ccdsubnet'}' readonly='readonly' /></td></tr>
2695 <tr><td colspan='4' align='right'><hr><input type='submit' value=' $Lang ::tr{'save'}' /><input type='hidden' name='ACTION' value='editsave'/>
2696 <input type='hidden' name='ccdname' value=' $cgiparams {'ccdname'}'/><input type='submit' value=' $Lang ::tr{'cancel'}' />
2701 & Header
:: closebox
();
2703 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd net' } );
2705 <table width='100%' border='0' cellpadding='0' cellspacing='1'>
2707 <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>
2712 if (! - e
"/var/run/openvpn.pid" ){
2713 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd add' });
2715 <table width='100%' border='0'>
2716 <tr><form method='post'>
2717 <td colspan='4'> $Lang ::tr{'ccd hint'}<br><br></td></tr>
2719 <td width='10%' nowrap='nwrap'> $Lang ::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value=' $cgiparams {'ccdname'}' /></td>
2720 <td width='8%'> $Lang ::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value=' $cgiparams {'ccdsubnet'}' /></td></tr>
2721 <tr><td colspan=4><hr /></td></tr><tr>
2722 <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>
2726 & Header
:: closebox
();
2728 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ccd net' } );
2729 if ( - e
"/var/run/openvpn.pid" ){
2730 print "<b> $Lang ::tr{'attention'}:</b><br>" ;
2731 print " $Lang ::tr{'ccd noaddnet'}<br><hr>" ;
2735 <table width='100%' cellpadding='0' cellspacing='1'>
2737 <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>
2742 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
2745 foreach my $key ( sort { uc ( $ccdconfhash { $a }[ 0 ]) cmp uc ( $ccdconfhash { $b }[ 0 ]) } keys %ccdconfhash ) {
2746 @ccdconf =( $ccdconfhash { $key }[ 0 ], $ccdconfhash { $key }[ 1 ]);
2748 my $ccdhosts = & hostsinnet
( $ccdconf [ 0 ]);
2749 if ( $count % 2 ){ print " <tr bgcolor=' $color {'color22'}'>" ;}
2750 else { print " <tr bgcolor=' $color {'color20'}'>" ;}
2751 print "<td> $ccdconf [0]</td><td align='center'> $ccdconf [1]</td><td align='center'> $ccdhosts /" .(& ccdmaxclients
( $ccdconf [ 1 ])+ 1 ). "</td><td>" ;
2753 <form method='post' />
2754 <input type='image' src='/images/edit.gif' align='middle' alt=' $Lang ::tr{'edit'}' title=' $Lang ::tr{'edit'}' />
2755 <input type='hidden' name='ACTION' value='edit'/>
2756 <input type='hidden' name='ccdname' value=' $ccdconf [0]' />
2757 <input type='hidden' name='ccdsubnet' value=' $ccdconf [1]' />
2759 <form method='post' />
2760 <td><input type='hidden' name='ACTION' value='kill'/>
2761 <input type='hidden' name='number' value=' $count ' />
2762 <input type='hidden' name='net' value=' $ccdconf [0]' />
2763 <input type='image' src='/images/delete.gif' align='middle' alt=' $Lang ::tr{'remove'}' title=' $Lang ::tr{'remove'}' /></form></td></tr>
2767 print "</table></form>" ;
2768 & Header
:: closebox
();
2769 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2770 & Header
:: closebigbox
();
2771 & Header
:: closepage
();
2777 ### Openvpn Connections Statistics
2779 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ovpn con stat' }) {
2780 & Header
:: showhttpheaders
();
2781 & Header
:: openpage
( $Lang :: tr
{ 'ovpn con stat' }, 1 , '' );
2782 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2783 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ovpn con stat' });
2786 # <td><b>$Lang::tr{'protocol'}</b></td>
2787 # protocol temp removed
2789 <table width='100%' cellpadding='2' cellspacing='0' class='tbl'>
2791 <th><b> $Lang ::tr{'common name'}</b></th>
2792 <th><b> $Lang ::tr{'real address'}</b></th>
2793 <th><b> $Lang ::tr{'virtual address'}</b></th>
2794 <th><b> $Lang ::tr{'loged in at'}</b></th>
2795 <th><b> $Lang ::tr{'bytes sent'}</b></th>
2796 <th><b> $Lang ::tr{'bytes received'}</b></th>
2797 <th><b> $Lang ::tr{'last activity'}</b></th>
2801 my $filename = "/var/log/ovpnserver.log" ;
2802 open ( FILE
, $filename ) or die 'Unable to open config file.' ;
2803 my @current = < FILE
>;
2812 my %userlookup = ();
2813 foreach my $line ( @current )
2816 if ( $line =~ /^Updated,(.+)/ ){
2817 @match = split ( /^Updated,(.+)/ , $line );
2818 $status = $match [ 1 ];
2821 if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ ) {
2822 @match = split ( m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ , $line );
2823 if ( $match [ 1 ] ne "Common Name" ) {
2825 $userlookup { $match [ 2 ]} = $uid ;
2826 $users [ $uid ]{ 'CommonName' } = $match [ 1 ];
2827 $users [ $uid ]{ 'RealAddress' } = $match [ 2 ];
2828 $users [ $uid ]{ 'BytesReceived' } = & sizeformat
( $match [ 3 ]);
2829 $users [ $uid ]{ 'BytesSent' } = & sizeformat
( $match [ 4 ]);
2830 $users [ $uid ]{ 'Since' } = $match [ 5 ];
2831 $users [ $uid ]{ 'Proto' } = $proto ;
2835 if ( $line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/ ) {
2836 @match = split ( m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/ , $line );
2837 if ( $match [ 1 ] ne "Virtual Address" ) {
2838 $address = $match [ 3 ];
2839 #find the uid in the lookup table
2840 $uid = $userlookup { $address };
2841 $users [ $uid ]{ 'VirtualAddress' } = $match [ 1 ];
2842 $users [ $uid ]{ 'LastRef' } = $match [ 4 ];
2848 for ( my $idx = 1 ; $idx <= $user2 ; $idx ++){
2851 $col = "bgcolor=' $color {'color22'}'" ;
2854 $col = "bgcolor=' $color {'color20'}'" ;
2856 print "<td align='left' $col > $users [ $idx -1]{'CommonName'}</td>" ;
2857 print "<td align='left' $col > $users [ $idx -1]{'RealAddress'}</td>" ;
2858 print "<td align='left' $col > $users [ $idx -1]{'VirtualAddress'}</td>" ;
2859 print "<td align='left' $col > $users [ $idx -1]{'Since'}</td>" ;
2860 print "<td align='left' $col > $users [ $idx -1]{'BytesSent'}</td>" ;
2861 print "<td align='left' $col > $users [ $idx -1]{'BytesReceived'}</td>" ;
2862 print "<td align='left' $col > $users [ $idx -1]{'LastRef'}</td>" ;
2868 <table width='100%' border='0' cellpadding='2' cellspacing='0'>
2873 <tr><td align='center' > $Lang ::tr{'the statistics were last updated at'} <b> $status </b></td></tr>
2877 & Header
:: closebox
();
2878 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2879 & Header
:: closebigbox
();
2880 & Header
:: closepage
();
2884 ### Download Certificate
2886 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
2887 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2889 if ( - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
2890 print "Content-Disposition: filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \r\n " ;
2891 print "Content-Type: application/octet-stream \r\n\r\n " ;
2892 print `/bin/cat ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
2897 ### Enable/Disable connection
2900 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
2902 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2903 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2905 if ( $confighash { $cgiparams { 'KEY' }}) {
2906 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
2907 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
2908 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2909 #&writeserverconf();
2910 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2911 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2912 # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
2915 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
2916 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2917 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2918 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
2920 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2921 #&writeserverconf();
2924 $errormessage = $Lang :: tr
{ 'invalid key' };
2928 ### Restart connection
2930 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
2931 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2932 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2934 if ( $confighash { $cgiparams { 'KEY' }}) {
2935 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2936 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2937 # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
2940 $errormessage = $Lang :: tr
{ 'invalid key' };
2944 ### Remove connection
2946 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
2947 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2948 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2950 if ( $confighash { $cgiparams { 'KEY' }}) {
2951 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2952 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2953 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
2955 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
2956 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
2957 delete $confighash { $cgiparams { 'KEY' }};
2958 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2959 #&writeserverconf();
2961 $errormessage = $Lang :: tr
{ 'invalid key' };
2966 ### Choose between adding a host-net or net-net connection
2973 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
2974 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2975 & Header
:: showhttpheaders
();
2976 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
2977 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2978 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'connection type' });
2980 if ( - s
"${General::swroot}/ovpn/settings" ) {
2983 <b> $Lang ::tr{'connection type'}:</b><br />
2984 <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data">
2985 <tr><td><input type='radio' name='TYPE' value='host' checked /></td>
2986 <td class='base'> $Lang ::tr{'host to net vpn'}</td></tr>
2987 <tr><td><input type='radio' name='TYPE' value='net' /></td>
2988 <td class='base'> $Lang ::tr{'net to net vpn'}</td></tr>
2989 <tr><td><input type='radio' name='TYPE' value='net2net' /></td>
2990 <td class='base'> $Lang ::tr{'net to net vpn'} (Upload Client Package)</td></tr>
2991 <tr><td> </td><td class='base'><input type='file' name='FH' size='30'></td></tr>
2992 <tr><td> </td><td>Import Connection Name <img src='/blob.gif' /></td></tr>
2993 <tr><td> </td><td class='base'><input type='text' name='n2nname' size='30'> $Lang ::tr{'openvpn default'}: Client Packagename</td></tr>
2994 <tr><td colspan='3'><hr /></td></tr>
2995 <tr><td align='right' colspan='3'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td></tr>
2996 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
3004 <b> $Lang ::tr{'connection type'}:</b><br />
3005 <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data">
3006 <tr><td><input type='radio' name='TYPE' value='host' checked /></td> <td class='base'> $Lang ::tr{'host to net vpn'}</td></tr>
3007 <tr><td align='right' colspan'3'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td></tr>
3014 & Header
:: closebox
();
3015 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
3016 & Header
:: closebigbox
();
3017 & Header
:: closepage
();
3024 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) && ( $cgiparams { 'TYPE' } eq 'net2net' )){
3028 my $uplconffilename = '' ;
3029 my $uplconffilename2 = '' ;
3030 my $uplp12name = '' ;
3031 my $uplp12name2 = '' ;
3038 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3040 # Check if a file is uploaded
3042 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
3043 $errormessage = $Lang :: tr
{ 'there was no file upload' };
3047 # Move uploaded IPfire n2n package to temporary file
3049 ( my $fh , my $filename ) = tempfile
( );
3050 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
3055 my $zip = Archive
:: Zip
-> new ();
3056 my $zipName = $filename ;
3057 my $status = $zip -> read ( $zipName );
3058 if ( $status != AZ_OK
) {
3059 $errormessage = "Read of $zipName failed \n " ;
3063 my $tempdir = tempdir
( CLEANUP
=> 1 );
3064 my @files = $zip -> memberNames ();
3066 $zip -> extractMemberWithoutPaths ( $_ , " $tempdir / $_ " );
3068 my $countfiles = @files ;
3070 # Check if we have not more then 2 files
3072 if ( $countfiles == 2 ){
3074 if ( $_ =~ /.conf$/ ){
3075 $uplconffilename = $_ ;
3077 if ( $_ =~ /.p12$/ ){
3081 if (( $uplconffilename eq '' ) || ( $uplp12name eq '' )){
3082 $errormessage = "Either no *.conf or no *.p12 file found \n " ;
3086 open ( FILE
, " $tempdir / $uplconffilename " ) or die 'Unable to open*.conf file' ;
3087 @firen2nconf = < FILE
>;
3089 chomp ( @firen2nconf );
3093 $errormessage = "Filecount does not match only 2 files are allowed \n " ;
3101 if ( $cgiparams { 'n2nname' } ne '' ){
3103 $uplconffilename2 = " $cgiparams {'n2nname'}.conf" ;
3104 $uplp12name2 = " $cgiparams {'n2nname'}.p12" ;
3105 $n2nname [ 0 ] = $cgiparams { 'n2nname' };
3106 my @n2nname2 = split ( /\./ , $uplconffilename );
3107 $n2nname2 [ 0 ] =~ s/\n|\r//g ;
3108 my $input1 = "${General::swroot}/ovpn/certs/ $uplp12name " ;
3109 my $output1 = "${General::swroot}/ovpn/certs/ $uplp12name2 " ;
3110 my $input2 = " $n2nname2 [0]n2n" ;
3111 my $output2 = " $n2nname [0]n2n" ;
3112 my $filename = " $tempdir / $uplconffilename " ;
3113 open ( FILE
, "< $filename " ) or die 'Unable to open config file.' ;
3114 my @current = < FILE
>;
3116 foreach ( @current ) { s/$input1/$output1/g ;}
3117 foreach ( @current ) { s/$input2/$output2/g ;}
3118 open ( OUT
, "> $filename " ) || die 'Unable to open config file.' ;
3123 $uplconffilename2 = $uplconffilename ;
3124 $uplp12name2 = $uplp12name ;
3125 @n2nname = split ( /\./ , $uplconffilename );
3126 $n2nname [ 0 ] =~ s/\n|\r//g ;
3128 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
3129 unless (- d
"${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" , 0770 or die "Unable to create dir $!" ;}
3131 move
( " $tempdir / $uplconffilename " , "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $uplconffilename2 " );
3134 $errormessage = "*.conf move failed: $!" ;
3139 move
( " $tempdir / $uplp12name " , "${General::swroot}/ovpn/certs/ $uplp12name2 " );
3140 chmod 0600 , "${General::swroot}/ovpn/certs/ $uplp12name " ;
3143 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
3152 my @n2nmtudisc = split ( / / , ( grep { /^mtu-disc/ } @firen2nconf )[ 0 ]);
3153 my @n2nproto2 = split ( / / , ( grep { /^proto/ } @firen2nconf )[ 0 ]);
3154 my @n2nproto = split ( /-/ , $n2nproto2 [ 1 ]);
3155 my @n2nport = split ( / / , ( grep { /^port/ } @firen2nconf )[ 0 ]);
3156 my @n2ntunmtu = split ( / / , ( grep { /^tun-mtu/ } @firen2nconf )[ 0 ]);
3157 my @n2ncomplzo = grep { /^comp-lzo/ } @firen2nconf ;
3158 if ( $n2ncomplzo [ 0 ] =~ /comp-lzo/ ){ $complzoactive = "on" ;} else { $complzoactive = "off" ;}
3159 my @n2nmssfix = grep { /^mssfix/ } @firen2nconf ;
3160 if ( $n2nmssfix [ 0 ] =~ /mssfix/ ){ $mssfixactive = "on" ;} else { $mssfixactive = "off" ;}
3161 #my @n2nmssfix = split(/ /, (grep { /^mssfix/ } @firen2nconf)[0]);
3162 my @n2nfragment = split ( / / , ( grep { /^fragment/ } @firen2nconf )[ 0 ]);
3163 my @n2nremote = split ( / / , ( grep { /^remote/ } @firen2nconf )[ 0 ]);
3164 my @n2novpnsuball = split ( / / , ( grep { /^ifconfig/ } @firen2nconf )[ 0 ]);
3165 my @n2novpnsub = split ( /\./ , $n2novpnsuball [ 1 ]);
3166 my @n2nremsub = split ( / / , ( grep { /^route/ } @firen2nconf )[ 0 ]);
3167 my @n2nmgmt = split ( / / , ( grep { /^management/ } @firen2nconf )[ 0 ]);
3168 my @n2nlocalsub = split ( / / , ( grep { /^# remsub/ } @firen2nconf )[ 0 ]);
3169 my @n2ncipher = split ( / / , ( grep { /^cipher/ } @firen2nconf )[ 0 ]);
3170 my @n2nauth = split ( / / , ( grep { /^auth/ } @firen2nconf )[ 0 ]);
3174 # m.a.d delete CR and LF from arrays for this chomp doesnt work
3177 $n2nremote [ 1 ] =~ s/\n|\r//g ;
3178 $n2novpnsub [ 0 ] =~ s/\n|\r//g ;
3179 $n2novpnsub [ 1 ] =~ s/\n|\r//g ;
3180 $n2novpnsub [ 2 ] =~ s/\n|\r//g ;
3181 $n2nproto [ 0 ] =~ s/\n|\r//g ;
3182 $n2nport [ 1 ] =~ s/\n|\r//g ;
3183 $n2ntunmtu [ 1 ] =~ s/\n|\r//g ;
3184 $n2nremsub [ 1 ] =~ s/\n|\r//g ;
3185 $n2nremsub [ 2 ] =~ s/\n|\r//g ;
3186 $n2nlocalsub [ 2 ] =~ s/\n|\r//g ;
3187 $n2nfragment [ 1 ] =~ s/\n|\r//g ;
3188 $n2nmgmt [ 2 ] =~ s/\n|\r//g ;
3189 $n2nmtudisc [ 1 ] =~ s/\n|\r//g ;
3190 $n2ncipher [ 1 ] =~ s/\n|\r//g ;
3191 $n2nauth [ 1 ] =~ s/\n|\r//g ;
3192 chomp ( $complzoactive );
3193 chomp ( $mssfixactive );
3200 # Check if there is no other entry with this name
3203 foreach my $dkey ( keys %confighash ) {
3204 if ( $confighash { $dkey }[ 1 ] eq $n2nname [ 0 ]) {
3205 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
3206 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
3207 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
3208 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
3214 # Check if OpenVPN Subnet is valid
3217 foreach my $dkey ( keys %confighash ) {
3218 if ( $confighash { $dkey }[ 27 ] eq " $n2novpnsub [0]. $n2novpnsub [1]. $n2novpnsub [2].0/255.255.255.0" ) {
3219 $errormessage = 'The OpenVPN Subnet is already in use' ;
3220 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
3221 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
3222 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
3228 # Check if Dest Port is vaild
3231 foreach my $dkey ( keys %confighash ) {
3232 if ( $confighash { $dkey }[ 29 ] eq $n2nport [ 1 ] ) {
3233 $errormessage = 'The OpenVPN Port is already in use' ;
3234 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
3235 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
3236 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
3243 $key = & General
:: findhasharraykey
( \
%confighash );
3245 foreach my $i ( 0 .. 41 ) { $confighash { $key }[ $i ] = "" ;}
3247 $confighash { $key }[ 0 ] = 'off' ;
3248 $confighash { $key }[ 1 ] = $n2nname [ 0 ];
3249 $confighash { $key }[ 2 ] = $n2nname [ 0 ];
3250 $confighash { $key }[ 3 ] = 'net' ;
3251 $confighash { $key }[ 4 ] = 'cert' ;
3252 $confighash { $key }[ 6 ] = 'client' ;
3253 $confighash { $key }[ 8 ] = $n2nlocalsub [ 2 ];
3254 $confighash { $key }[ 10 ] = $n2nremote [ 1 ];
3255 $confighash { $key }[ 11 ] = " $n2nremsub [1]/ $n2nremsub [2]" ;
3256 $confighash { $key }[ 22 ] = $n2nmgmt [ 2 ];
3257 $confighash { $key }[ 23 ] = $mssfixactive ;
3258 $confighash { $key }[ 24 ] = $n2nfragment [ 1 ];
3259 $confighash { $key }[ 25 ] = 'IPFire n2n Client' ;
3260 $confighash { $key }[ 26 ] = 'red' ;
3261 $confighash { $key }[ 27 ] = " $n2novpnsub [0]. $n2novpnsub [1]. $n2novpnsub [2].0/255.255.255.0" ;
3262 $confighash { $key }[ 28 ] = $n2nproto [ 0 ];
3263 $confighash { $key }[ 29 ] = $n2nport [ 1 ];
3264 $confighash { $key }[ 30 ] = $complzoactive ;
3265 $confighash { $key }[ 31 ] = $n2ntunmtu [ 1 ];
3266 $confighash { $key }[ 38 ] = $n2nmtudisc [ 1 ];
3267 $confighash { $key }[ 39 ] = $n2nauth [ 1 ];
3268 $confighash { $key }[ 40 ] = $n2ncipher [ 1 ];
3270 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3274 & Header
:: showhttpheaders
();
3275 & Header
:: openpage
( 'Validate imported configuration' , 1 , '' );
3276 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
3277 if ( $errormessage ) {
3278 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
3279 print "<class name='base'> $errormessage " ;
3280 print " </class>" ;
3281 & Header
:: closebox
();
3285 & Header
:: openbox
( '100%' , 'LEFT' , 'import ipfire net2net config' );
3287 if ( $errormessage eq '' ){
3289 <!-- ipfire net2net config gui -->
3290 <table width='100%'>
3291 <tr><td width='25%'> </td><td width='25%'> </td></tr>
3292 <tr><td class='boldbase'> $Lang ::tr{'name'}:</td><td><b> $n2nname [0]</b></td></tr>
3293 <tr><td> </td><td> </td></tr>
3294 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'Act as'}</td><td><b> $confighash { $key }[6]</b></td></tr>
3295 <tr><td class='boldbase' nowrap='nowrap'>Remote Host </td><td><b> $confighash { $key }[10]</b></td></tr>
3296 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'}</td><td><b> $confighash { $key }[8]</b></td></tr>
3297 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'}:</td><td><b> $confighash { $key }[11]</b></td></tr>
3298 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn subnet'}</td><td><b> $confighash { $key }[27]</b></td></tr>
3299 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td><td><b> $confighash { $key }[28]</b></td></tr>
3300 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'destination port'}:</td><td><b> $confighash { $key }[29]</b></td></tr>
3301 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'}</td><td><b> $confighash { $key }[30]</b></td></tr>
3302 <tr><td class='boldbase' nowrap='nowrap'>MSSFIX:</td><td><b> $confighash { $key }[23]</b></td></tr>
3303 <tr><td class='boldbase' nowrap='nowrap'>Fragment:</td><td><b> $confighash { $key }[24]</b></td></tr>
3304 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'}</td><td><b> $confighash { $key }[31]</b></td></tr>
3305 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn mtu-disc'}:</td><td><b> $confighash { $key }[38]</b></td></tr>
3306 <tr><td class='boldbase' nowrap='nowrap'>Management Port:</td><td><b> $confighash { $key }[22]</b></td></tr>
3307 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn hmac'}:</td><td><b> $confighash { $key }[39]</b></td></tr>
3308 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'cipher'}</td><td><b> $confighash { $key }[40]</b></td></tr>
3309 <tr><td> </td><td> </td></tr>
3313 & Header
:: closebox
();
3316 if ( $errormessage ) {
3317 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
3319 print "<div align='center'><form method='post' ENCTYPE='multipart/form-data'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />" ;
3320 print "<input type='hidden' name='TYPE' value='net2netakn' />" ;
3321 print "<input type='hidden' name='KEY' value=' $key ' />" ;
3322 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
3324 & Header
:: closebigbox
();
3325 & Header
:: closepage
();
3330 ### Accept IPFire n2n Package Settings
3333 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) && ( $cgiparams { 'TYPE' } eq 'net2netakn' )){
3336 ### Discard and Rollback IPFire n2n Package Settings
3339 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'cancel' }) && ( $cgiparams { 'TYPE' } eq 'net2netakn' )){
3341 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3343 if ( $confighash { $cgiparams { 'KEY' }}) {
3345 my $conffile = glob ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]/ $confighash { $cgiparams {'KEY'}}[1].conf" );
3346 my $certfile = glob ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
3347 unlink ( $certfile ) or die "Removing $certfile fail: $!" ;
3348 unlink ( $conffile ) or die "Removing $conffile fail: $!" ;
3349 rmdir ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]" ) || die "Kann Verzeichnis nicht loeschen: $!" ;
3350 delete $confighash { $cgiparams { 'KEY' }};
3351 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3354 $errormessage = $Lang :: tr
{ 'invalid key' };
3364 ### Adding a new connection
3366 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
3367 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
3368 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
3370 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
3371 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
3372 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3374 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
3375 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
3376 $errormessage = $Lang :: tr
{ 'invalid key' };
3379 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
3380 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
3381 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
3382 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
3383 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
3384 $cgiparams { 'SIDE' } = $confighash { $cgiparams { 'KEY' }}[ 6 ];
3385 $cgiparams { 'LOCAL_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 8 ];
3386 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
3387 $cgiparams { 'REMOTE_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 11 ];
3388 $cgiparams { 'OVPN_MGMT' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
3389 $cgiparams { 'MSSFIX' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
3390 $cgiparams { 'FRAGMENT' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
3391 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
3392 $cgiparams { 'INTERFACE' } = $confighash { $cgiparams { 'KEY' }}[ 26 ];
3393 $cgiparams { 'OVPN_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
3394 $cgiparams { 'PROTOCOL' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
3395 $cgiparams { 'DEST_PORT' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
3396 $cgiparams { 'COMPLZO' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
3397 $cgiparams { 'MTU' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
3398 $cgiparams { 'CHECK1' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
3399 $name = $cgiparams { 'CHECK1' } ;
3400 $cgiparams { $name } = $confighash { $cgiparams { 'KEY' }}[ 33 ];
3401 $cgiparams { 'RG' } = $confighash { $cgiparams { 'KEY' }}[ 34 ];
3402 $cgiparams { 'CCD_DNS1' } = $confighash { $cgiparams { 'KEY' }}[ 35 ];
3403 $cgiparams { 'CCD_DNS2' } = $confighash { $cgiparams { 'KEY' }}[ 36 ];
3404 $cgiparams { 'CCD_WINS' } = $confighash { $cgiparams { 'KEY' }}[ 37 ];
3405 $cgiparams { 'PMTU_DISCOVERY' } = $confighash { $cgiparams { 'KEY' }}[ 38 ];
3406 $cgiparams { 'DAUTH' } = $confighash { $cgiparams { 'KEY' }}[ 39 ];
3407 $cgiparams { 'DCIPHER' } = $confighash { $cgiparams { 'KEY' }}[ 40 ];
3408 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
3409 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
3411 #A.Marx CCD check iroute field and convert it to decimal
3412 if ( $cgiparams { 'TYPE' } eq 'host' ) {
3414 my %ccdroutehash =();
3418 if ( $cgiparams { 'IR' } ne '' ){
3419 @temp = split ( " \n " , $cgiparams { 'IR' });
3420 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3422 foreach my $key ( keys %ccdroutehash ) {
3423 if ( $ccdroutehash { $key }[ 0 ] eq $cgiparams { 'NAME' }) {
3425 delete $ccdroutehash { $key };
3427 $keypoint = & General
:: findhasharraykey
( \
%ccdroutehash );
3430 $ccdroutehash { $keypoint }[ 0 ]= $cgiparams { 'NAME' };
3433 foreach $val ( @temp ){
3436 #check if iroute exists in ccdroute or if new iroute is part of an existing one
3437 foreach my $key ( keys %ccdroutehash ) {
3438 foreach my $oldiroute ( 1 .. $ #{$ccdroutehash{$key}}){
3439 if ( $ccdroutehash { $key }[ $oldiroute ] eq " $val " ) {
3440 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err irouteexist' };
3443 my ( $ip1 , $cidr1 ) = split ( /\/ /, $val );
3444 $ip1 = & General
:: getnetworkip
( $ip1 ,& General
:: iporsubtocidr
( $cidr1 ));
3445 my ( $ip2 , $cidr2 ) = split ( /\/ /, $ccdroutehash { $key }[ $oldiroute ]);
3446 if (& General
:: IpInSubnet
( $ip1 , $ip2 , $cidr2 )){
3447 $errormessage = $errormessage . $Lang :: tr
{ 'ccd err irouteexist' };
3453 if (!& General
:: validipandmask
( $val )){
3454 $errormessage = $errormessage . "Route " . $Lang :: tr
{ 'ccd invalid' }. " ( $val )" ;
3457 ( $ip , $cidr ) = split ( /\/ /, $val );
3458 $ip =& General
:: getnetworkip
( $ip ,& General
:: iporsubtocidr
( $cidr ));
3459 $cidr =& General
:: iporsubtodec
( $cidr );
3460 $ccdroutehash { $keypoint }[ $i ] = $ip . "/" . $cidr ;
3464 #check for existing network IP's
3465 if (& General
:: IpInSubnet
( $ip , $netsettings { GREEN_NETADDRESS
}, $netsettings { GREEN_NETMASK
}) && $netsettings { GREEN_NETADDRESS
} ne '0.0.0.0' )
3467 $errormessage = $Lang :: tr
{ 'ccd err green' };
3469 } elsif (& General
:: IpInSubnet
( $ip , $netsettings { RED_NETADDRESS
}, $netsettings { RED_NETMASK
}) && $netsettings { RED_NETADDRESS
} ne '0.0.0.0' )
3471 $errormessage = $Lang :: tr
{ 'ccd err red' };
3473 } elsif (& General
:: IpInSubnet
( $ip , $netsettings { BLUE_NETADDRESS
}, $netsettings { BLUE_NETMASK
}) && $netsettings { BLUE_NETADDRESS
} ne '0.0.0.0' && $netsettings { BLUE_NETADDRESS
} gt '' )
3475 $errormessage = $Lang :: tr
{ 'ccd err blue' };
3477 } elsif (& General
:: IpInSubnet
( $ip , $netsettings { ORANGE_NETADDRESS
}, $netsettings { ORANGE_NETMASK
}) && $netsettings { ORANGE_NETADDRESS
} ne '0.0.0.0' && $netsettings { ORANGE_NETADDRESS
} gt '' )
3479 $errormessage = $Lang :: tr
{ 'ccd err orange' };
3483 if (& General
:: validipandmask
( $val )){
3484 $ccdroutehash { $keypoint }[ $i ] = $ip . "/" . $cidr ;
3486 $errormessage = $errormessage . "Route " . $Lang :: tr
{ 'ccd invalid' }. " ( $ip / $cidr )" ;
3491 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3494 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3495 foreach my $key ( keys %ccdroutehash ) {
3496 if ( $ccdroutehash { $key }[ 0 ] eq $cgiparams { 'NAME' }) {
3497 delete $ccdroutehash { $key };
3498 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3504 #check route field and convert it to decimal
3507 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
3509 foreach my $key ( keys %ccdroute2hash ) {
3510 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }) {
3512 delete $ccdroute2hash { $key };
3514 $keypoint = & General
:: findhasharraykey
( \
%ccdroute2hash );
3515 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
3519 $ccdroute2hash { $keypoint }[ 0 ]= $cgiparams { 'NAME' };
3520 if ( $cgiparams { 'IFROUTE' } eq '' ){ $cgiparams { 'IFROUTE' } = $Lang :: tr
{ 'ccd none' };}
3521 @temp = split ( /\|/ , $cgiparams { 'IFROUTE' });
3523 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%ownnet );
3524 foreach $val ( @temp ){
3527 if ( $val eq $Lang :: tr
{ 'green' })
3529 $val = $ownnet { GREEN_NETADDRESS
}. "/" . $ownnet { GREEN_NETMASK
};
3531 if ( $val eq $Lang :: tr
{ 'blue' })
3533 $val = $ownnet { BLUE_NETADDRESS
}. "/" . $ownnet { BLUE_NETMASK
};
3535 if ( $val eq $Lang :: tr
{ 'orange' })
3537 $val = $ownnet { ORANGE_NETADDRESS
}. "/" . $ownnet { ORANGE_NETMASK
};
3539 my ( $ip , $cidr ) = split ( /\/ /, $val );
3541 if ( $val ne $Lang :: tr
{ 'ccd none' })
3543 if (! & check_routes_push
( $val )){ $errormessage = $errormessage . "Route $val " . $Lang :: tr
{ 'ccd err routeovpn2' }. " ( $val )" ; goto VPNCONF_ERROR
;}
3544 if (! & check_ccdroute
( $val )){ $errormessage = $errormessage . "<br>Route $val " . $Lang :: tr
{ 'ccd err inuse' }. " ( $val )" ; goto VPNCONF_ERROR
;}
3545 if (! & check_ccdconf
( $val )){ $errormessage = $errormessage . "<br>Route $val " . $Lang :: tr
{ 'ccd err routeovpn' }. " ( $val )" ; goto VPNCONF_ERROR
;}
3546 if (& General
:: validipandmask
( $val )){
3547 $val = $ip . "/" .& General
:: iporsubtodec
( $cidr );
3548 $ccdroute2hash { $keypoint }[ $i ] = $val ;
3550 $errormessage = $errormessage . "Route " . $Lang :: tr
{ 'ccd invalid' }. " ( $val )" ;
3554 $ccdroute2hash { $keypoint }[ $i ]= '' ;
3558 & General
:: writehasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
3561 if ( $cgiparams { 'CCD_DNS1' } ne '' && ! & General
:: validip
( $cgiparams { 'CCD_DNS1' })) {
3562 $errormessage = $errormessage . "<br>" . $Lang :: tr
{ 'invalid input for dhcp dns' }. " 1" ;
3566 if ( $cgiparams { 'CCD_DNS2' } ne '' && ! & General
:: validip
( $cgiparams { 'CCD_DNS2' })) {
3567 $errormessage = $errormessage . "<br>" . $Lang :: tr
{ 'invalid input for dhcp dns' }. " 2" ;
3571 if ( $cgiparams { 'CCD_WINS' } ne '' && ! & General
:: validip
( $cgiparams { 'CCD_WINS' })) {
3572 $errormessage = $errormessage . "<br>" . $Lang :: tr
{ 'invalid input for dhcp wins' };
3580 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
3581 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
3582 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3583 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3584 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3590 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
3591 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
3592 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3593 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3594 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3599 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
3600 $errormessage = $Lang :: tr
{ 'name is invalid' };
3601 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3602 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3603 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3608 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
3609 $errormessage = $Lang :: tr
{ 'name too long' };
3610 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3611 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3612 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3621 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3622 if ( $cgiparams { 'DEST_PORT' } eq $vpnsettings { 'DDEST_PORT' }) {
3623 $errormessage = $Lang :: tr
{ 'openvpn destination port used' };
3624 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3625 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3629 foreach my $key ( sort keys %confighash ){
3630 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 ])){
3631 $errormessage = $Lang :: tr
{ 'openvpn destination port used' };
3632 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3633 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3637 if ( $cgiparams { 'DEST_PORT' } eq '' ) {
3638 $errormessage = $Lang :: tr
{ 'invalid port' };
3639 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3640 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3644 # Check if the input for the transfer net is valid.
3645 if (!& General
:: validipandmask
( $cgiparams { 'OVPN_SUBNET' })){
3646 $errormessage = $Lang :: tr
{ 'ccd err invalidnet' };
3647 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3648 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3652 if ( $cgiparams { 'OVPN_SUBNET' } eq $vpnsettings { 'DOVPN_SUBNET' }) {
3653 $errormessage = $Lang :: tr
{ 'openvpn subnet is used' };
3654 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3655 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3659 if (( $cgiparams { 'PROTOCOL' } eq 'tcp' ) && ( $cgiparams { 'MSSFIX' } eq 'on' )) {
3660 $errormessage = $Lang :: tr
{ 'openvpn mssfix allowed with udp' };
3661 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3662 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3666 if (( $cgiparams { 'PROTOCOL' } eq 'tcp' ) && ( $cgiparams { 'FRAGMENT' } ne '' )) {
3667 $errormessage = $Lang :: tr
{ 'openvpn fragment allowed with udp' };
3668 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3669 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3673 if ( $cgiparams { 'PMTU_DISCOVERY' } ne 'off' ) {
3674 if (( $cgiparams { 'FRAGMENT' } ne '' ) || ( $cgiparams { 'MSSFIX' } eq 'on' )) {
3675 $errormessage = $Lang :: tr
{ 'ovpn mtu-disc with mssfix or fragment' };
3676 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3677 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3682 if (( $cgiparams { 'PMTU_DISCOVERY' } ne 'off' ) && ( $cgiparams { 'MTU' } ne '1500' )) {
3683 $errormessage = $Lang :: tr
{ 'ovpn mtu-disc and mtu not 1500' };
3684 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3685 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3689 if ( & validdotmask
( $cgiparams { 'LOCAL_SUBNET' })) {
3690 $errormessage = $Lang :: tr
{ 'openvpn prefix local subnet' };
3691 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3692 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3696 if ( & validdotmask
( $cgiparams { 'OVPN_SUBNET' })) {
3697 $errormessage = $Lang :: tr
{ 'openvpn prefix openvpn subnet' };
3698 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3699 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3703 if ( & validdotmask
( $cgiparams { 'REMOTE_SUBNET' })) {
3704 $errormessage = $Lang :: tr
{ 'openvpn prefix remote subnet' };
3705 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3706 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3710 if ( $cgiparams { 'DEST_PORT' } <= 1023 ) {
3711 $errormessage = $Lang :: tr
{ 'ovpn port in root range' };
3712 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3713 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3717 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) {
3718 $cgiparams { 'OVPN_MGMT' } = $cgiparams { 'DEST_PORT' };
3721 if ( $cgiparams { 'OVPN_MGMT' } <= 1023 ) {
3722 $errormessage = $Lang :: tr
{ 'ovpn mgmt in root range' };
3723 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3724 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3727 #Check if remote subnet is used elsewhere
3728 my ( $n2nip , $n2nsub )= split ( "/" , $cgiparams { 'REMOTE_SUBNET' });
3729 $warnmessage =& General
:: checksubnets
( '' , $n2nip , 'ovpn' );
3731 $warnmessage = $Lang :: tr
{ 'remote subnet' }. " ( $cgiparams {'REMOTE_SUBNET'}) <br>" . $warnmessage ;
3736 # if (($cgiparams{'TYPE'} eq 'net') && ($cgiparams{'SIDE'} !~ /^(left|right)$/)) {
3737 # $errormessage = $Lang::tr{'ipfire side is invalid'};
3738 # goto VPNCONF_ERROR;
3741 # Check if there is no other entry with this name
3742 if (! $cgiparams { 'KEY' }) {
3743 foreach my $key ( keys %confighash ) {
3744 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
3745 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
3746 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3747 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3748 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3755 # Check if a remote host/IP has been set for the client.
3756 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3757 if ( $cgiparams { 'SIDE' } ne 'server' && $cgiparams { 'REMOTE' } eq '' ) {
3758 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
3760 # Check if this is a N2N connection and drop temporary config.
3761 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3762 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3767 # Check if a remote host/IP has been configured - the field can be empty on the server side.
3768 if ( $cgiparams { 'REMOTE' } ne '' ) {
3769 # Check if the given IP is valid - otherwise check if it is a valid domain.
3770 if (! & General
:: validip
( $cgiparams { 'REMOTE' })) {
3771 # Check for a valid domain.
3772 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
3773 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
3775 # Check if this is a N2N connection and drop temporary config.
3776 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3777 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3785 if ( $cgiparams { 'TYPE' } ne 'host' ) {
3786 unless (& General
:: validipandmask
( $cgiparams { 'LOCAL_SUBNET' })) {
3787 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
3788 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3789 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3790 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3792 goto VPNCONF_ERROR
;}
3794 # Check if there is no other entry without IP-address and PSK
3795 if ( $cgiparams { 'REMOTE' } eq '' ) {
3796 foreach my $key ( keys %confighash ) {
3797 if (( $cgiparams { 'KEY' } ne $key ) &&
3798 ( $confighash { $key }[ 4 ] eq 'psk' || $cgiparams { 'AUTH' } eq 'psk' ) &&
3799 $confighash { $key }[ 10 ] eq '' ) {
3800 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
3805 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! & General
:: validipandmask
( $cgiparams { 'REMOTE_SUBNET' }))) {
3806 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
3807 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3808 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3812 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
3813 $errormessage = $Lang :: tr
{ 'invalid input' };
3816 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
3817 $errormessage = $Lang :: tr
{ 'invalid input' };
3822 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
3823 # if (! length($cgiparams{'PSK'}) ) {
3824 # $errormessage = $Lang::tr{'pre-shared key is too short'};
3825 # goto VPNCONF_ERROR;
3827 # if ($cgiparams{'PSK'} =~ /['",&]/) {
3828 # $errormessage = $Lang::tr{'invalid characters found in pre-shared key'};
3829 # goto VPNCONF_ERROR;
3831 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
3832 if ( $cgiparams { 'KEY' }) {
3833 $errormessage = $Lang :: tr
{ 'cant change certificates' };
3836 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
3837 $errormessage = $Lang :: tr
{ 'there was no file upload' };
3841 # Move uploaded certificate request to a temporary file
3842 ( my $fh , my $filename ) = tempfile
( );
3843 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
3848 # Sign the certificate request and move it
3849 # Sign the host certificate request
3850 system ( '/usr/bin/openssl' , 'ca' , '-days' , " $cgiparams {'DAYS_VALID'}" ,
3851 '-batch' , '-notext' ,
3853 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
3854 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
3856 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
3858 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3859 & newcleanssldatabase
();
3863 & deletebackupcert
();
3866 my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem` ;
3867 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
3869 $temp =~ s
+/ Email
+, E
+;
3870 $temp =~ s/ ST=/ S=/ ;
3871 $cgiparams { 'CERT_NAME' } = $temp ;
3872 $cgiparams { 'CERT_NAME' } =~ s/,//g ;
3873 $cgiparams { 'CERT_NAME' } =~ s/\'//g ;
3874 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
3875 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
3878 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
3879 if ( $cgiparams { 'KEY' }) {
3880 $errormessage = $Lang :: tr
{ 'cant change certificates' };
3883 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
3884 $errormessage = $Lang :: tr
{ 'there was no file upload' };
3887 # Move uploaded certificate to a temporary file
3888 ( my $fh , my $filename ) = tempfile
( );
3889 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
3894 # Verify the certificate has a valid CA and move it
3896 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/cacert.pem $filename ` ;
3897 if ( $test =~ /: OK/ ) {
3900 foreach my $key ( keys %cahash ) {
3901 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/ $cahash { $key }[0]cert.pem $filename ` ;
3902 if ( $test =~ /: OK/ ) {
3908 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
3912 move
( $filename , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3914 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
3920 my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem` ;
3921 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
3923 $temp =~ s
+/ Email
+, E
+;
3924 $temp =~ s/ ST=/ S=/ ;
3925 $cgiparams { 'CERT_NAME' } = $temp ;
3926 $cgiparams { 'CERT_NAME' } =~ s/,//g ;
3927 $cgiparams { 'CERT_NAME' } =~ s/\'//g ;
3928 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
3929 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3930 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
3933 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
3934 if ( $cgiparams { 'KEY' }) {
3935 $errormessage = $Lang :: tr
{ 'cant change certificates' };
3938 # Validate input since the form was submitted
3939 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
3940 $errormessage = $Lang :: tr
{ 'name too long' };
3943 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
3944 $errormessage = $Lang :: tr
{ 'invalid input for name' };
3945 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
3946 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
3949 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
3950 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
3953 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
3954 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
3957 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
3958 $errormessage = $Lang :: tr
{ 'invalid input for department' };
3961 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
3962 $errormessage = $Lang :: tr
{ 'organization too long' };
3965 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
3966 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
3969 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
3970 $errormessage = $Lang :: tr
{ 'invalid input for city' };
3973 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
3974 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
3977 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
3978 $errormessage = $Lang :: tr
{ 'invalid input for country' };
3981 if ( $cgiparams { 'CERT_PASS1' } ne '' && $cgiparams { 'CERT_PASS2' } ne '' ){
3982 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
3983 $errormessage = $Lang :: tr
{ 'password too short' };
3987 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
3988 $errormessage = $Lang :: tr
{ 'passwords do not match' };
3992 # Replace empty strings with a .
3993 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
3994 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
3995 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
3997 # Create the Host certificate request client
3998 my $pid = open ( OPENSSL
, "|-" );
3999 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto VPNCONF_ERROR
;};
4000 if ( $pid ) { # parent
4001 print OPENSSL
" $cgiparams {'CERT_COUNTRY'} \n " ;
4002 print OPENSSL
" $state \n " ;
4003 print OPENSSL
" $city \n " ;
4004 print OPENSSL
" $cgiparams {'CERT_ORGANIZATION'} \n " ;
4005 print OPENSSL
" $ou \n " ;
4006 print OPENSSL
" $cgiparams {'CERT_NAME'} \n " ;
4007 print OPENSSL
" $cgiparams {'CERT_EMAIL'} \n " ;
4008 print OPENSSL
". \n " ;
4009 print OPENSSL
". \n " ;
4012 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
4013 unlink ( "${General::swroot}ovpn/certs/ $cgiparams {'NAME'}key.pem" );
4014 unlink ( "${General::swroot}ovpn/certs/ $cgiparams {'NAME'}req.pem" );
4018 unless ( exec ( '/usr/bin/openssl' , 'req' , '-nodes' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
4019 '-newkey' , 'rsa:2048' ,
4020 '-keyout' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" ,
4021 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" ,
4022 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
4023 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
4024 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
4025 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
4030 # Sign the host certificate request
4031 system ( '/usr/bin/openssl' , 'ca' , '-days' , " $cgiparams {'DAYS_VALID'}" ,
4032 '-batch' , '-notext' ,
4033 '-in' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" ,
4034 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
4035 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
4037 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
4038 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
4039 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
4040 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
4041 & newcleanssldatabase
();
4044 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
4045 & deletebackupcert
();
4048 # Create the pkcs12 file
4049 system ( '/usr/bin/openssl' , 'pkcs12' , '-export' ,
4050 '-inkey' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" ,
4051 '-in' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
4052 '-name' , $cgiparams { 'NAME' },
4053 '-passout' , "pass: $cgiparams {'CERT_PASS1'}" ,
4054 '-certfile' , "${General::swroot}/ovpn/ca/cacert.pem" ,
4055 '-caname' , " $vpnsettings {'ROOTCERT_ORGANIZATION'} CA" ,
4056 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12" );
4058 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
4059 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
4060 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
4061 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12" );
4064 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
4066 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
4067 ; # Nothing, just editing
4069 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
4073 # Check if there is no other entry with this common name
4074 if ((! $cgiparams { 'KEY' }) && ( $cgiparams { 'AUTH' } ne 'psk' )) {
4075 foreach my $key ( keys %confighash ) {
4076 if ( $confighash { $key }[ 2 ] eq $cgiparams { 'CERT_NAME' }) {
4077 $errormessage = $Lang :: tr
{ 'a connection with this common name already exists' };
4084 my $key = $cgiparams { 'KEY' };
4087 $key = & General
:: findhasharraykey
( \
%confighash );
4088 foreach my $i ( 0 .. 41 ) { $confighash { $key }[ $i ] = "" ;}
4090 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
4091 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
4092 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
4093 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
4096 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
4097 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
4098 $confighash { $key }[ 4 ] = 'psk' ;
4099 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
4101 $confighash { $key }[ 4 ] = 'cert' ;
4103 if ( $cgiparams { 'TYPE' } eq 'net' ) {
4104 $confighash { $key }[ 6 ] = $cgiparams { 'SIDE' };
4105 $confighash { $key }[ 11 ] = $cgiparams { 'REMOTE_SUBNET' };
4107 $confighash { $key }[ 8 ] = $cgiparams { 'LOCAL_SUBNET' };
4108 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
4109 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) {
4110 $confighash { $key }[ 22 ] = $confighash { $key }[ 29 ];
4112 $confighash { $key }[ 22 ] = $cgiparams { 'OVPN_MGMT' };
4114 $confighash { $key }[ 23 ] = $cgiparams { 'MSSFIX' };
4115 $confighash { $key }[ 24 ] = $cgiparams { 'FRAGMENT' };
4116 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
4117 $confighash { $key }[ 26 ] = $cgiparams { 'INTERFACE' };
4119 $confighash { $key }[ 27 ] = $cgiparams { 'OVPN_SUBNET' };
4120 $confighash { $key }[ 28 ] = $cgiparams { 'PROTOCOL' };
4121 $confighash { $key }[ 29 ] = $cgiparams { 'DEST_PORT' };
4122 $confighash { $key }[ 30 ] = $cgiparams { 'COMPLZO' };
4123 $confighash { $key }[ 31 ] = $cgiparams { 'MTU' };
4124 $confighash { $key }[ 32 ] = $cgiparams { 'CHECK1' };
4125 $name = $cgiparams { 'CHECK1' };
4126 $confighash { $key }[ 33 ] = $cgiparams { $name };
4127 $confighash { $key }[ 34 ] = $cgiparams { 'RG' };
4128 $confighash { $key }[ 35 ] = $cgiparams { 'CCD_DNS1' };
4129 $confighash { $key }[ 36 ] = $cgiparams { 'CCD_DNS2' };
4130 $confighash { $key }[ 37 ] = $cgiparams { 'CCD_WINS' };
4131 $confighash { $key }[ 38 ] = $cgiparams { 'PMTU_DISCOVERY' };
4132 $confighash { $key }[ 39 ] = $cgiparams { 'DAUTH' };
4133 $confighash { $key }[ 40 ] = $cgiparams { 'DCIPHER' };
4135 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
4137 if ( $cgiparams { 'CHECK1' } ){
4139 my ( $ccdip , $ccdsub )= split "/" , $cgiparams { $name };
4140 my ( $a , $b , $c , $d ) = split ( /\./ , $ccdip );
4141 if ( - e
"${General::swroot}/ovpn/ccd/ $confighash { $key }[2]" ){
4142 unlink "${General::swroot}/ovpn/ccd/ $cgiparams {'CERT_NAME'}" ;
4144 open ( CCDRWCONF
, '>' , "${General::swroot}/ovpn/ccd/ $confighash { $key }[2]" ) or die "Unable to create clientconfigfile $!" ;
4145 print CCDRWCONF
"# OpenVPN clientconfig from ccd extension by Copymaster# \n\n " ;
4146 if ( $cgiparams { 'CHECK1' } eq 'dynamic' ){
4147 print CCDRWCONF
"#This client uses the dynamic pool \n " ;
4149 print CCDRWCONF
"#Ip address client and server \n " ;
4150 print CCDRWCONF
"ifconfig-push $ccdip " .& General
:: getlastip
( $ccdip , 1 ). " \n " ;
4152 if ( $confighash { $key }[ 34 ] eq 'on' ){
4153 print CCDRWCONF
" \n #Redirect Gateway: \n #All IP traffic is redirected through the vpn \n " ;
4154 print CCDRWCONF
"push redirect-gateway \n " ;
4156 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
4157 if ( $cgiparams { 'IR' } ne '' ){
4158 print CCDRWCONF
" \n #Client routes these networks (behind Client) \n " ;
4159 foreach my $key ( keys %ccdroutehash ){
4160 if ( $ccdroutehash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4161 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}){
4162 my ( $a , $b )= split ( /\/ /, $ccdroutehash { $key }[ $i ]);
4163 print CCDRWCONF
"iroute $a $b \n " ;
4168 if ( $cgiparams { 'IFROUTE' } eq $Lang :: tr
{ 'ccd none' } ){ $cgiparams { 'IFROUTE' }= '' ;}
4169 if ( $cgiparams { 'IFROUTE' } ne '' ){
4170 print CCDRWCONF
" \n #Client gets routes to these networks (behind IPFire) \n " ;
4171 foreach my $key ( keys %ccdroute2hash ){
4172 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4173 foreach my $i ( 1 .. $ #{$ccdroute2hash{$key}}){
4174 if ( $ccdroute2hash { $key }[ $i ] eq $Lang :: tr
{ 'blue' }){
4176 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%blue );
4177 print CCDRWCONF
"push \" route $blue {BLUE_ADDRESS} $blue {BLUE_NETMASK} \n " ;
4178 } elsif ( $ccdroute2hash { $key }[ $i ] eq $Lang :: tr
{ 'orange' }){
4180 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%orange );
4181 print CCDRWCONF
"push \" route $orange {ORANGE_ADDRESS} $orange {ORANGE_NETMASK} \n " ;
4183 my ( $a , $b )= split ( /\/ /, $ccdroute2hash { $key }[ $i ]);
4184 print CCDRWCONF
"push \" route $a $b \"\n " ;
4190 if (( $cgiparams { 'CCD_DNS1' } eq '' ) && ( $cgiparams { 'CCD_DNS1' } ne '' )){ $cgiparams { 'CCD_DNS1' } = $cgiparams { 'CCD_DNS2' }; $cgiparams { 'CCD_DNS2' }= '' ;}
4191 if ( $cgiparams { 'CCD_DNS1' } ne '' ){
4192 print CCDRWCONF
" \n #Client gets these nameservers \n " ;
4193 print CCDRWCONF
"push \" dhcp-option DNS $cgiparams {'CCD_DNS1'} \" \n " ;
4195 if ( $cgiparams { 'CCD_DNS2' } ne '' ){
4196 print CCDRWCONF
"push \" dhcp-option DNS $cgiparams {'CCD_DNS2'} \" \n " ;
4198 if ( $cgiparams { 'CCD_WINS' } ne '' ){
4199 print CCDRWCONF
" \n #Client gets this WINS server \n " ;
4200 print CCDRWCONF
"push \" dhcp-option WINS $cgiparams {'CCD_WINS'} \" \n " ;
4209 if ( $cgiparams { 'TYPE' } eq 'net' ) {
4211 if (- e
"/var/run/ $confighash { $key }[1]n2n.pid" ) {
4212 system ( '/usr/local/bin/openvpnctrl' , '-kn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
4214 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
4215 my $key = $cgiparams { 'KEY' };
4217 $key = & General
:: findhasharraykey
( \
%confighash );
4218 foreach my $i ( 0 .. 31 ) { $confighash { $key }[ $i ] = "" ;}
4220 $confighash { $key }[ 0 ] = 'on' ;
4221 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
4223 system ( '/usr/local/bin/openvpnctrl' , '-sn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
4231 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
4232 $cgiparams { 'KEY' } = $key ;
4233 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
4237 $cgiparams { 'ENABLED' } = 'on' ;
4241 $cgiparams { 'MSSFIX' } = 'on' ;
4242 $cgiparams { 'FRAGMENT' } = '1300' ;
4243 $cgiparams { 'PMTU_DISCOVERY' } = 'off' ;
4244 $cgiparams { 'DAUTH' } = 'SHA1' ;
4248 $cgiparams { 'SIDE' } = 'left' ;
4249 if ( ! - f
"${General::swroot}/ovpn/ca/cakey.pem" ) {
4250 $cgiparams { 'AUTH' } = 'psk' ;
4251 } elsif ( ! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
4252 $cgiparams { 'AUTH' } = 'certfile' ;
4254 $cgiparams { 'AUTH' } = 'certgen' ;
4256 $cgiparams { 'LOCAL_SUBNET' } = " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" ;
4257 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
4258 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
4259 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
4260 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
4264 $checked { 'ENABLED' }{ 'off' } = '' ;
4265 $checked { 'ENABLED' }{ 'on' } = '' ;
4266 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = 'CHECKED' ;
4267 $checked { 'ENABLED_BLUE' }{ 'off' } = '' ;
4268 $checked { 'ENABLED_BLUE' }{ 'on' } = '' ;
4269 $checked { 'ENABLED_BLUE' }{ $cgiparams { 'ENABLED_BLUE' }} = 'CHECKED' ;
4270 $checked { 'ENABLED_ORANGE' }{ 'off' } = '' ;
4271 $checked { 'ENABLED_ORANGE' }{ 'on' } = '' ;
4272 $checked { 'ENABLED_ORANGE' }{ $cgiparams { 'ENABLED_ORANGE' }} = 'CHECKED' ;
4275 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
4276 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
4277 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = 'CHECKED' ;
4279 $selected { 'SIDE' }{ 'server' } = '' ;
4280 $selected { 'SIDE' }{ 'client' } = '' ;
4281 $selected { 'SIDE' }{ $cgiparams { 'SIDE' }} = 'SELECTED' ;
4283 $selected { 'PROTOCOL' }{ 'udp' } = '' ;
4284 $selected { 'PROTOCOL' }{ 'tcp' } = '' ;
4285 $selected { 'PROTOCOL' }{ $cgiparams { 'PROTOCOL' }} = 'SELECTED' ;
4288 $checked { 'AUTH' }{ 'psk' } = '' ;
4289 $checked { 'AUTH' }{ 'certreq' } = '' ;
4290 $checked { 'AUTH' }{ 'certgen' } = '' ;
4291 $checked { 'AUTH' }{ 'certfile' } = '' ;
4292 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = 'CHECKED' ;
4294 $selected { 'INTERFACE' }{ $cgiparams { 'INTERFACE' }} = 'SELECTED' ;
4296 $checked { 'COMPLZO' }{ 'off' } = '' ;
4297 $checked { 'COMPLZO' }{ 'on' } = '' ;
4298 $checked { 'COMPLZO' }{ $cgiparams { 'COMPLZO' }} = 'CHECKED' ;
4300 $checked { 'MSSFIX' }{ 'off' } = '' ;
4301 $checked { 'MSSFIX' }{ 'on' } = '' ;
4302 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
4304 if ( $cgiparams { 'PMTU_DISCOVERY' } eq '' ) {
4305 $cgiparams { 'PMTU_DISCOVERY' } = 'off' ;
4307 $checked { 'PMTU_DISCOVERY' }{ $cgiparams { 'PMTU_DISCOVERY' }} = 'checked= \' checked \' ' ;
4309 $selected { 'DAUTH' }{ 'whirlpool' } = '' ;
4310 $selected { 'DAUTH' }{ 'SHA512' } = '' ;
4311 $selected { 'DAUTH' }{ 'SHA384' } = '' ;
4312 $selected { 'DAUTH' }{ 'SHA256' } = '' ;
4313 $selected { 'DAUTH' }{ 'ecdsa-with-SHA1' } = '' ;
4314 $selected { 'DAUTH' }{ 'SHA1' } = '' ;
4315 $selected { 'DAUTH' }{ $cgiparams { 'DAUTH' }} = 'SELECTED' ;
4317 $selected { 'DCIPHER' }{ 'CAMELLIA-256-CBC' } = '' ;
4318 $selected { 'DCIPHER' }{ 'CAMELLIA-192-CBC' } = '' ;
4319 $selected { 'DCIPHER' }{ 'CAMELLIA-128-CBC' } = '' ;
4320 $selected { 'DCIPHER' }{ 'AES-256-CBC' } = '' ;
4321 $selected { 'DCIPHER' }{ 'AES-192-CBC' } = '' ;
4322 $selected { 'DCIPHER' }{ 'AES-128-CBC' } = '' ;
4323 $selected { 'DCIPHER' }{ 'DESX-CBC' } = '' ;
4324 $selected { 'DCIPHER' }{ 'SEED-CBC' } = '' ;
4325 $selected { 'DCIPHER' }{ 'DES-EDE3-CBC' } = '' ;
4326 $selected { 'DCIPHER' }{ 'DES-EDE-CBC' } = '' ;
4327 $selected { 'DCIPHER' }{ 'CAST5-CBC' } = '' ;
4328 $selected { 'DCIPHER' }{ 'BF-CBC' } = '' ;
4329 $selected { 'DCIPHER' }{ 'RC2-CBC' } = '' ;
4330 $selected { 'DCIPHER' }{ 'DES-CBC' } = '' ;
4331 $selected { 'DCIPHER' }{ 'RC2-64-CBC' } = '' ;
4332 $selected { 'DCIPHER' }{ 'RC2-40-CBC' } = '' ;
4333 $selected { 'DCIPHER' }{ $cgiparams { 'DCIPHER' }} = 'SELECTED' ;
4336 & Header
:: showhttpheaders
();
4337 & Header
:: openpage
( $Lang :: tr
{ 'ovpn' }, 1 , '' );
4338 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
4339 if ( $errormessage ) {
4340 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
4341 print "<class name='base'> $errormessage " ;
4342 print " </class>" ;
4343 & Header
:: closebox
();
4347 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'warning messages'}:" );
4348 print "<class name='base'> $warnmessage " ;
4349 print " </class>" ;
4350 & Header
:: closebox
();
4353 print "<form method='post' enctype='multipart/form-data'>" ;
4354 print "<input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />" ;
4356 if ( $cgiparams { 'KEY' }) {
4357 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
4358 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
4361 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'connection'}:" );
4362 print "<table width='100%' border='0'> \n " ;
4364 print "<tr><td width='14%' class='boldbase'> $Lang ::tr{'name'}: </td>" ;
4366 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4367 if ( $cgiparams { 'KEY' }) {
4368 print "<td width='35%' class='base'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /> $cgiparams {'NAME'}</td>" ;
4370 print "<td width='35%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' maxlength='20' size='30' /></td>" ;
4372 # print "<tr><td>$Lang::tr{'interface'}</td>";
4373 # print "<td><select name='INTERFACE'>";
4374 # print "<option value='RED' $selected{'INTERFACE'}{'RED'}>RED</option>";
4375 # if ($netsettings{'BLUE_DEV'} ne '') {
4376 # print "<option value='BLUE' $selected{'INTERFACE'}{'BLUE'}>BLUE</option>";
4378 # print "<option value='GREEN' $selected{'INTERFACE'}{'GREEN'}>GREEN</option>";
4379 # print "<option value='ORANGE' $selected{'INTERFACE'}{'ORANGE'}>ORANGE</option>";
4380 # print "</select></td></tr>";
4383 print "<input type='hidden' name='INTERFACE' value='red' />" ;
4384 if ( $cgiparams { 'KEY' }) {
4385 print "<td width='25%' class='base' nowrap='nowrap'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /> $cgiparams {'NAME'}</td>" ;
4387 print "<td width='25%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' maxlength='20' /></td>" ;
4391 <td width='25%'> </td>
4392 <td width='25%'> </td></tr>
4394 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'Act as'}</td>
4395 <td><select name='SIDE'><option value='server' $selected {'SIDE'}{'server'}> $Lang ::tr{'openvpn server'}</option>
4396 <option value='client' $selected {'SIDE'}{'client'}> $Lang ::tr{'openvpn client'}</option></select></td>
4398 <td class='boldbase'> $Lang ::tr{'remote host/ip'}:</td>
4399 <td><input type='TEXT' name='REMOTE' value=' $cgiparams {'REMOTE'}' /></td></tr>
4401 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'}</td>
4402 <td><input type='TEXT' name='LOCAL_SUBNET' value=' $cgiparams {'LOCAL_SUBNET'}' /></td>
4404 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'}</td>
4405 <td><input type='text' name='REMOTE_SUBNET' value=' $cgiparams {'REMOTE_SUBNET'}' /></td></tr>
4407 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn subnet'}</td>
4408 <td><input type='TEXT' name='OVPN_SUBNET' value=' $cgiparams {'OVPN_SUBNET'}' /></td>
4410 <td class='boldbase'> $Lang ::tr{'destination port'}:</td>
4411 <td><input type='TEXT' name='DEST_PORT' value=' $cgiparams {'DEST_PORT'}' size='5' /></td>
4413 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td>
4414 <td><select name='PROTOCOL'><option value='udp' $selected {'PROTOCOL'}{'udp'}>UDP</option>
4415 <option value='tcp' $selected {'PROTOCOL'}{'tcp'}>TCP</option></select></td>
4417 <td class='boldbase' nowrap='nowrap'>Management Port ( $Lang ::tr{'openvpn default'}: <span class="base"> $Lang ::tr{'destination port'}): <img src='/blob.gif' /></td>
4418 <td> <input type='TEXT' name='OVPN_MGMT' VALUE=' $cgiparams {'OVPN_MGMT'}'size='5' /></td>
4421 <tr><td class='boldbase'> $Lang ::tr{'cipher'}</td>
4422 <td><select name='DCIPHER'>
4423 <option value='CAMELLIA-256-CBC' $selected {'DCIPHER'}{'CAMELLIA-256-CBC'}>CAMELLIA-CBC (256 $Lang ::tr{'bit'})</option>
4424 <option value='CAMELLIA-192-CBC' $selected {'DCIPHER'}{'CAMELLIA-192-CBC'}>CAMELLIA-CBC (196 $Lang ::tr{'bit'})</option>
4425 <option value='CAMELLIA-128-CBC' $selected {'DCIPHER'}{'CAMELLIA-128-CBC'}>CAMELLIA-CBC (128 $Lang ::tr{'bit'})</option>
4426 <option value='AES-256-CBC' $selected {'DCIPHER'}{'AES-256-CBC'}>AES-CBC (256 $Lang ::tr{'bit'})</option>
4427 <option value='AES-192-CBC' $selected {'DCIPHER'}{'AES-192-CBC'}>AES-CBC (192 $Lang ::tr{'bit'})</option>
4428 <option value='AES-128-CBC' $selected {'DCIPHER'}{'AES-128-CBC'}>AES-CBC (128 $Lang ::tr{'bit'})</option>
4429 <option value='DES-EDE3-CBC' $selected {'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC (192 $Lang ::tr{'bit'})</option>
4430 <option value='DESX-CBC' $selected {'DCIPHER'}{'DESX-CBC'}>DESX-CBC (192 $Lang ::tr{'bit'})</option>
4431 <option value='SEED-CBC' $selected {'DCIPHER'}{'SEED-CBC'}>SEED-CBC (128 $Lang ::tr{'bit'})</option>
4432 <option value='DES-EDE-CBC' $selected {'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC (128 $Lang ::tr{'bit'})</option>
4433 <option value='BF-CBC' $selected {'DCIPHER'}{'BF-CBC'}>BF-CBC (128 $Lang ::tr{'bit'})</option>
4434 <option value='CAST5-CBC' $selected {'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC (128 $Lang ::tr{'bit'})</option>
4435 <option value='RC2-CBC' $selected {'DCIPHER'}{'RC2-CBC'}>RC2-CBC (128 $Lang ::tr{'bit'})</option>
4436 <option value='DES-CBC' $selected {'DCIPHER'}{'DES-CBC'}>DES-CBC (64 $Lang ::tr{'bit'} not recommended)</option>
4437 <option value='RC2-64-CBC' $selected {'DCIPHER'}{'RC2-64-CBC'}>RC2-CBC (64 $Lang ::tr{'bit'} not recommended)</option>
4438 <option value='RC2-40-CBC' $selected {'DCIPHER'}{'RC2-40-CBC'}>RC2-CBC (40 $Lang ::tr{'bit'} not recommended)</option>
4442 <td class='boldbase'> $Lang ::tr{'ovpn ha'}:</td>
4443 <td><select name='DAUTH'>
4444 <option value='whirlpool' $selected {'DAUTH'}{'whirlpool'}>Whirlpool (512 $Lang ::tr{'bit'})</option>
4445 <option value='SHA512' $selected {'DAUTH'}{'SHA512'}>SHA2 (512 $Lang ::tr{'bit'})</option>
4446 <option value='SHA384' $selected {'DAUTH'}{'SHA384'}>SHA2 (384 $Lang ::tr{'bit'})</option>
4447 <option value='SHA256' $selected {'DAUTH'}{'SHA256'}>SHA2 (256 $Lang ::tr{'bit'})</option>
4448 <option value='ecdsa-with-SHA1' $selected {'DAUTH'}{'ecdsa-with-SHA1'}>ECDSA-SHA1 (160 $Lang ::tr{'bit'})</option>
4449 <option value='SHA1' $selected {'DAUTH'}{'SHA1'}>SHA1 (160 $Lang ::tr{'bit'} Default)</option>
4454 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'} <img src='/blob.gif' /></td>
4455 <td> <input type='TEXT' name='MTU' VALUE=' $cgiparams {'MTU'}'size='5' /></td>
4456 <td colspan='2'> $Lang ::tr{'openvpn default'}: udp/tcp <span class="base">1500/1400</span></td>
4458 <tr><td class='boldbase' nowrap='nowrap'>fragment: <img src='/blob.gif' /></td>
4459 <td><input type='TEXT' name='FRAGMENT' VALUE=' $cgiparams {'FRAGMENT'}'size='5' /></td>
4460 <td> $Lang ::tr{'openvpn default'}: <span class="base">1300</span></td>
4462 <tr><td class='boldbase' nowrap='nowrap'>mssfix: <img src='/blob.gif' /></td>
4463 <td><input type='checkbox' name='MSSFIX' $checked {'MSSFIX'}{'on'} /></td>
4464 <td> $Lang ::tr{'openvpn default'}: <span class="base">on</span></td>
4466 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'} <img src='/blob.gif'</td>
4467 <td><input type='checkbox' name='COMPLZO' $checked {'COMPLZO'}{'on'} /></td>
4470 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn mtu-disc'}:</td>
4472 <input type='radio' name='PMTU_DISCOVERY' value='yes' $checked {'PMTU_DISCOVERY'}{'yes'} /> $Lang ::tr{'ovpn mtu-disc yes'}
4473 <input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked {'PMTU_DISCOVERY'}{'maybe'} /> $Lang ::tr{'ovpn mtu-disc maybe'}
4474 <input type='radio' name='PMTU_DISCOVERY' value='no' $checked {'PMTU_DISCOVERY'}{'no'} /> $Lang ::tr{'ovpn mtu-disc no'}
4475 <input type='radio' name='PMTU_DISCOVERY' value='off' $checked {'PMTU_DISCOVERY'}{'off'} /> $Lang ::tr{'ovpn mtu-disc off'}
4483 print "<tr><td class='boldbase'> $Lang ::tr{'remark title'} <img src='/blob.gif' /></td>" ;
4484 print "<td colspan='3'><input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' size='55' maxlength='50' /></td></tr></table>" ;
4486 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4487 print "<tr><td> $Lang ::tr{'enabled'} <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>" ;
4490 print "</tr></table><br><br>" ;
4491 #A.Marx CCD new client
4492 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4493 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>" ;
4496 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnnet );
4497 $vpnip = $vpnnet { 'DOVPN_SUBNET' };
4498 & General
:: readhasharray
( "${General::swroot}/ovpn/ccd.conf" , \
%ccdconfhash );
4502 $checked { 'check1' }{ 'off' } = '' ;
4503 $checked { 'check1' }{ 'on' } = '' ;
4504 $checked { 'check1' }{ $cgiparams { 'CHECK1' }} = 'CHECKED' ;
4505 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%'>" ;
4506 print "</td></tr></table><br><br>" ;
4507 my $name = $cgiparams { 'CHECK1' };
4508 $checked { 'RG' }{ $cgiparams { 'RG' }} = 'CHECKED' ;
4510 if (! - z
"${General::swroot}/ovpn/ccd.conf" ){
4511 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>" ;
4512 foreach my $key ( sort { uc ( $ccdconfhash { $a }[ 0 ]) cmp uc ( $ccdconfhash { $b }[ 0 ]) } keys %ccdconfhash ) {
4514 @ccdconf =( $ccdconfhash { $key }[ 0 ], $ccdconfhash { $key }[ 1 ]);
4515 if ( $count % 2 ){ print "<tr bgcolor=' $color {'color22'}'>" ;} else { print "<tr bgcolor=' $color {'color20'}'>" ;}
4516 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%'>" ;
4517 & fillselectbox
( $ccdconf [ 1 ], $ccdconf [ 0 ], $cgiparams { $name });
4520 print "</table><br><br><hr><br><br>" ;
4524 & Header
:: closebox
();
4525 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
4527 } elsif (! $cgiparams { 'KEY' }) {
4531 my $cakeydisabled = '' ;
4532 my $cacrtdisabled = '' ;
4533 if ( ! - f
"${General::swroot}/ovpn/ca/cakey.pem" ) { $cakeydisabled = "disabled='disabled'" } else { $cakeydisabled = "" };
4534 if ( ! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) { $cacrtdisabled = "disabled='disabled'" } else { $cacrtdisabled = "" };
4536 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'authentication' });
4539 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4542 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
4544 <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>
4545 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td><td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
4546 <tr><td colspan='3'> </td></tr>
4547 <tr><td colspan='3'><hr /></td></tr>
4548 <tr><td colspan='3'> </td></tr>
4549 <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>
4550 <tr><td> </td><td class='base'> $Lang ::tr{'users fullname or system hostname'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' SIZE='32' $cakeydisabled /></td></tr>
4551 <tr><td> </td><td class='base'> $Lang ::tr{'users email'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' SIZE='32' $cakeydisabled /></td></tr>
4552 <tr><td> </td><td class='base'> $Lang ::tr{'users department'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' SIZE='32' $cakeydisabled /></td></tr>
4553 <tr><td> </td><td class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' SIZE='32' $cakeydisabled /></td></tr>
4554 <tr><td> </td><td class='base'> $Lang ::tr{'city'}: <img src='/blob.gif'></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' SIZE='32' $cakeydisabled /></td></tr>
4555 <tr><td> </td><td class='base'> $Lang ::tr{'state or province'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' SIZE='32' $cakeydisabled /></td></tr>
4556 <tr><td> </td><td class='base'> $Lang ::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
4567 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
4569 <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>
4570 <tr><td> </td><td class='base'> $Lang ::tr{'users fullname or system hostname'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' SIZE='32' $cakeydisabled /></td></tr>
4571 <tr><td> </td><td class='base'> $Lang ::tr{'users email'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' SIZE='32' $cakeydisabled /></td></tr>
4572 <tr><td> </td><td class='base'> $Lang ::tr{'users department'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' SIZE='32' $cakeydisabled /></td></tr>
4573 <tr><td> </td><td class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' SIZE='32' $cakeydisabled /></td></tr>
4574 <tr><td> </td><td class='base'> $Lang ::tr{'city'}: <img src='/blob.gif'></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' SIZE='32' $cakeydisabled /></td></tr>
4575 <tr><td> </td><td class='base'> $Lang ::tr{'state or province'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' SIZE='32' $cakeydisabled /></td></tr>
4576 <tr><td> </td><td class='base'> $Lang ::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
4588 foreach my $country ( sort keys %{ Countries
:: countries
}) {
4589 print "<option value=' $Countries ::countries{ $country }'" ;
4590 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
4591 print " selected='selected'" ;
4593 print "> $country </option>" ;
4599 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4603 <td> </td><td class='base'> $Lang ::tr{'valid till'} (days):</td>
4604 <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value=' $cgiparams {'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr>
4606 <td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
4607 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
4608 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'}:<br>( $Lang ::tr{'confirmation'})</td>
4609 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
4610 <tr><td colspan='3'> </td></tr>
4611 <tr><td colspan='3'><hr /></td></tr>
4612 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
4618 <tr><td> </td><td> </td><td> </td></tr>
4619 <tr><td> </td><td> </td><td> </td></tr>
4620 <tr><td colspan='3'><hr /></td></tr>
4621 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
4631 & Header
:: closebox
();
4635 #A.Marx CCD new client
4636 if ( $cgiparams { 'TYPE' } eq 'host' ) {
4638 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'ccd client options'}:" );
4642 <table border='0' width='100%'>
4643 <tr><td width='20%'>Redirect Gateway:</td><td colspan='3'><input type='checkbox' name='RG' $checked {'RG'}{'on'} /></td></tr>
4644 <tr><td colspan='4'><b><br> $Lang ::tr{'ccd routes'}</b></td></tr>
4645 <tr><td colspan='4'> </td></tr>
4646 <tr><td valign='top'> $Lang ::tr{'ccd iroute'}</td><td align='left' width='30%'><textarea name='IR' cols='26' rows='6' wrap='off'>
4649 if ( $cgiparams { 'IR' } ne '' ){
4650 print $cgiparams { 'IR' };
4652 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute" , \
%ccdroutehash );
4653 foreach my $key ( keys %ccdroutehash ) {
4654 if ( $cgiparams { 'NAME' } eq $ccdroutehash { $key }[ 0 ]){
4655 foreach my $i ( 1 .. $ #{$ccdroutehash{$key}}) {
4656 if ( $ccdroutehash { $key }[ $i ] ne '' ){
4657 print $ccdroutehash { $key }[ $i ]. " \n " ;
4659 $cgiparams { 'IR' } .= $ccdroutehash { $key }[ $i ];
4666 </textarea></td><td valign='top' colspan='2'> $Lang ::tr{'ccd iroutehint'}</td></tr>
4667 <tr><td colspan='4'><br></td></tr>
4668 <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>
4682 open ( FILE
, "${General::swroot}/main/routing" ) ;
4685 & General
:: readhasharray
( "${General::swroot}/ovpn/ccdroute2" , \
%ccdroute2hash );
4687 foreach my $key ( keys %ccdroute2hash ) {
4688 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4689 if ( $ccdroute2hash { $key }[ 1 ] eq '' ){
4696 print "<option> $Lang ::tr{'ccd none'}</option>" ;
4698 print "<option selected> $Lang ::tr{'ccd none'}</option>" ;
4700 #check if static routes are defined for client
4701 foreach my $line ( @current ) {
4703 $line =~ s/\s*$//g ; # remove newline
4704 @temp = split ( /\,/ , $line );
4705 $temp [ 1 ] = '' unless defined $temp [ 1 ]; # not always populated
4706 my ( $a , $b ) = split ( /\/ /, $temp [ 1 ]);
4707 $temp [ 1 ] = $a . "/" .& General
:: iporsubtocidr
( $b );
4708 foreach my $key ( keys %ccdroute2hash ) {
4709 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4710 foreach my $i ( 1 .. $ #{$ccdroute2hash{$key}}) {
4711 if ( $ccdroute2hash { $key }[ $i ] eq $a . "/" .& General
:: iporsubtodec
( $b )){
4717 if ( $set == '1' && $#temp != - 1 ){ print "<option selected> $temp [1]</option>" ; $set = 0 ;} elsif ( $set == '0' && $#temp != - 1 ){ print "<option> $temp [1]</option>" ;}
4719 #check if green,blue,orange are defined for client
4720 foreach my $key ( keys %ccdroute2hash ) {
4721 if ( $ccdroute2hash { $key }[ 0 ] eq $cgiparams { 'NAME' }){
4723 foreach my $i ( 1 .. $ #{$ccdroute2hash{$key}}) {
4724 if ( $ccdroute2hash { $key }[ $i ] eq $netsettings { 'GREEN_NETADDRESS' }. "/" .& General
:: iporsubtodec
( $netsettings { 'GREEN_NETMASK' })){
4727 if (& haveBlueNet
()){
4728 if ( $ccdroute2hash { $key }[ $i ] eq $netsettings { 'BLUE_NETADDRESS' }. "/" .& General
:: iporsubtodec
( $netsettings { 'BLUE_NETMASK' })) {
4732 if (& haveOrangeNet
()){
4733 if ( $ccdroute2hash { $key }[ $i ] eq $netsettings { 'ORANGE_NETADDRESS' }. "/" .& General
:: iporsubtodec
( $netsettings { 'ORANGE_NETMASK' }) ) {
4740 if (& haveBlueNet
() && $selblue == '1' ){ print "<option selected> $Lang ::tr{'blue'}</option>" ; $selblue = 0 ;} elsif (& haveBlueNet
() && $selblue == '0' ){ print "<option> $Lang ::tr{'blue'}</option>" ;}
4741 if (& haveOrangeNet
() && $selorange == '1' ){ print "<option selected> $Lang ::tr{'orange'}</option>" ; $selorange = 0 ;} elsif (& haveOrangeNet
() && $selorange == '0' ){ print "<option> $Lang ::tr{'orange'}</option>" ;}
4742 if ( $selgreen == '1' || $other == '0' ){ print "<option selected> $Lang ::tr{'green'}</option>" ; $set = 0 ;} else { print "<option> $Lang ::tr{'green'}</option>" ;};
4745 </select></td><td valign='top'>DNS1:</td><td valign='top'><input type='TEXT' name='CCD_DNS1' value=' $cgiparams {'CCD_DNS1'}' size='30' /></td></tr>
4746 <tr valign='top'><td>DNS2:</td><td><input type='TEXT' name='CCD_DNS2' value=' $cgiparams {'CCD_DNS2'}' size='30' /></td></tr>
4747 <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>
4751 & Header
:: closebox
();
4753 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
4754 if ( $cgiparams { 'KEY' }) {
4755 # print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />";
4757 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
4758 & Header
:: closebigbox
();
4759 & Header
:: closepage
();
4767 ### Default status page
4772 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%cgiparams );
4773 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
4774 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
4776 my @status = `/bin/cat /var/log/ovpnserver.log` ;
4778 if ( $cgiparams { 'VPN_IP' } eq '' && - e
"${General::swroot}/red/active" ) {
4779 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
4780 my $ipaddr = < IPADDR
>;
4783 $cgiparams { 'VPN_IP' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
4784 if ( $cgiparams { 'VPN_IP' } eq '' ) {
4785 $cgiparams { 'VPN_IP' } = $ipaddr ;
4791 if ( $cgiparams { 'DCIPHER' } eq '' ) {
4792 $cgiparams { 'DCIPHER' } = 'AES-256-CBC' ;
4794 if ( $cgiparams { 'DDEST_PORT' } eq '' ) {
4795 $cgiparams { 'DDEST_PORT' } = '1194' ;
4797 if ( $cgiparams { 'DMTU' } eq '' ) {
4798 $cgiparams { 'DMTU' } = '1400' ;
4800 if ( $cgiparams { 'MSSFIX' } eq '' ) {
4801 $cgiparams { 'MSSFIX' } = 'off' ;
4803 if ( $cgiparams { 'DAUTH' } eq '' ) {
4804 $cgiparams { 'DAUTH' } = 'SHA1' ;
4806 if ( $cgiparams { 'DOVPN_SUBNET' } eq '' ) {
4807 $cgiparams { 'DOVPN_SUBNET' } = '10.' . int ( rand ( 256 )) . '.' . int ( rand ( 256 )) . '.0/255.255.255.0' ;
4809 $checked { 'ENABLED' }{ 'off' } = '' ;
4810 $checked { 'ENABLED' }{ 'on' } = '' ;
4811 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = 'CHECKED' ;
4812 $checked { 'ENABLED_BLUE' }{ 'off' } = '' ;
4813 $checked { 'ENABLED_BLUE' }{ 'on' } = '' ;
4814 $checked { 'ENABLED_BLUE' }{ $cgiparams { 'ENABLED_BLUE' }} = 'CHECKED' ;
4815 $checked { 'ENABLED_ORANGE' }{ 'off' } = '' ;
4816 $checked { 'ENABLED_ORANGE' }{ 'on' } = '' ;
4817 $checked { 'ENABLED_ORANGE' }{ $cgiparams { 'ENABLED_ORANGE' }} = 'CHECKED' ;
4818 $selected { 'DDEVICE' }{ 'tun' } = '' ;
4819 $selected { 'DDEVICE' }{ 'tap' } = '' ;
4820 $selected { 'DDEVICE' }{ $cgiparams { 'DDEVICE' }} = 'SELECTED' ;
4822 $selected { 'DPROTOCOL' }{ 'udp' } = '' ;
4823 $selected { 'DPROTOCOL' }{ 'tcp' } = '' ;
4824 $selected { 'DPROTOCOL' }{ $cgiparams { 'DPROTOCOL' }} = 'SELECTED' ;
4826 $selected { 'DCIPHER' }{ 'CAMELLIA-256-CBC' } = '' ;
4827 $selected { 'DCIPHER' }{ 'CAMELLIA-192-CBC' } = '' ;
4828 $selected { 'DCIPHER' }{ 'CAMELLIA-128-CBC' } = '' ;
4829 $selected { 'DCIPHER' }{ 'AES-256-CBC' } = '' ;
4830 $selected { 'DCIPHER' }{ 'AES-192-CBC' } = '' ;
4831 $selected { 'DCIPHER' }{ 'AES-128-CBC' } = '' ;
4832 $selected { 'DCIPHER' }{ 'DES-EDE3-CBC' } = '' ;
4833 $selected { 'DCIPHER' }{ 'DESX-CBC' } = '' ;
4834 $selected { 'DCIPHER' }{ 'SEED-CBC' } = '' ;
4835 $selected { 'DCIPHER' }{ 'DES-EDE-CBC' } = '' ;
4836 $selected { 'DCIPHER' }{ 'CAST5-CBC' } = '' ;
4837 $selected { 'DCIPHER' }{ 'BF-CBC' } = '' ;
4838 $selected { 'DCIPHER' }{ 'RC2-CBC' } = '' ;
4839 $selected { 'DCIPHER' }{ 'DES-CBC' } = '' ;
4840 $selected { 'DCIPHER' }{ 'RC2-64-CBC' } = '' ;
4841 $selected { 'DCIPHER' }{ 'RC2-40-CBC' } = '' ;
4842 $selected { 'DCIPHER' }{ $cgiparams { 'DCIPHER' }} = 'SELECTED' ;
4844 $selected { 'DAUTH' }{ 'whirlpool' } = '' ;
4845 $selected { 'DAUTH' }{ 'SHA512' } = '' ;
4846 $selected { 'DAUTH' }{ 'SHA384' } = '' ;
4847 $selected { 'DAUTH' }{ 'SHA256' } = '' ;
4848 $selected { 'DAUTH' }{ 'ecdsa-with-SHA1' } = '' ;
4849 $selected { 'DAUTH' }{ 'SHA1' } = '' ;
4850 $selected { 'DAUTH' }{ $cgiparams { 'DAUTH' }} = 'SELECTED' ;
4852 $checked { 'DCOMPLZO' }{ 'off' } = '' ;
4853 $checked { 'DCOMPLZO' }{ 'on' } = '' ;
4854 $checked { 'DCOMPLZO' }{ $cgiparams { 'DCOMPLZO' }} = 'CHECKED' ;
4857 $checked { 'MSSFIX' }{ 'off' } = '' ;
4858 $checked { 'MSSFIX' }{ 'on' } = '' ;
4859 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
4861 & Header
:: showhttpheaders
();
4862 & Header
:: openpage
( $Lang :: tr
{ 'status ovpn' }, 1 , '' );
4863 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
4865 if ( $errormessage ) {
4866 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
4867 print "<class name='base'> $errormessage \n " ;
4868 print " </class> \n " ;
4869 & Header
:: closebox
();
4873 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'warning messages' });
4874 print " $warnmessage <br>" ;
4875 print " $Lang ::tr{'fwdfw warn1'}<br>" ;
4876 & Header
:: closebox
();
4877 print "<center><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'ok'}' style='width: 5em;'></form>" ;
4878 & Header
:: closepage
();
4882 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>" ;
4883 my $srunning = "no" ;
4884 my $activeonrun = "" ;
4885 if ( - e
"/var/run/openvpn.pid" ){
4886 $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>" ;
4890 $activeonrun = "disabled='disabled'" ;
4892 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'global settings' });
4894 <table width='100%' border='0'>
4895 <form method='post'>
4896 <td width='25%'> </td>
4897 <td width='25%'> </td>
4898 <td width='25%'> </td></tr>
4899 <tr><td class='boldbase'> $Lang ::tr{'ovpn server status'}</td>
4900 <td align='left'> $sactive </td>
4901 <tr><td class='boldbase'> $Lang ::tr{'ovpn on red'}</td>
4902 <td><input type='checkbox' name='ENABLED' $checked {'ENABLED'}{'on'} /></td>
4905 if (& haveBlueNet
()) {
4906 print "<tr><td class='boldbase'> $Lang ::tr{'ovpn on blue'}</td>" ;
4907 print "<td><input type='checkbox' name='ENABLED_BLUE' $checked {'ENABLED_BLUE'}{'on'} /></td>" ;
4909 if (& haveOrangeNet
()) {
4910 print "<tr><td class='boldbase'> $Lang ::tr{'ovpn on orange'}</td>" ;
4911 print "<td><input type='checkbox' name='ENABLED_ORANGE' $checked {'ENABLED_ORANGE'}{'on'} /></td>" ;
4914 <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>
4915 <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>
4916 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn device'}</td>
4917 <td><select name='DDEVICE' ><option value='tun' $selected {'DDEVICE'}{'tun'}>TUN</option>
4918 <!-- this is still not working
4919 <option value='tap' $selected {'DDEVICE'}{'tap'}>TAP</option></select>--> </td>
4920 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td>
4921 <td><select name='DPROTOCOL'><option value='udp' $selected {'DPROTOCOL'}{'udp'}>UDP</option>
4922 <option value='tcp' $selected {'DPROTOCOL'}{'tcp'}>TCP</option></select></td>
4923 <td class='boldbase'> $Lang ::tr{'destination port'}:</td>
4924 <td><input type='TEXT' name='DDEST_PORT' value=' $cgiparams {'DDEST_PORT'}' size='5' /></td></tr>
4925 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'} </td>
4926 <td> <input type='TEXT' name='DMTU' VALUE=' $cgiparams {'DMTU'}'size='5' /></td>
4927 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'cipher'}</td>
4928 <td><select name='DCIPHER'>
4929 <option value='CAMELLIA-256-CBC' $selected {'DCIPHER'}{'CAMELLIA-256-CBC'}>CAMELLIA-CBC (256 $Lang ::tr{'bit'})</option>
4930 <option value='CAMELLIA-192-CBC' $selected {'DCIPHER'}{'CAMELLIA-192-CBC'}>CAMELLIA-CBC (196 $Lang ::tr{'bit'})</option>
4931 <option value='CAMELLIA-128-CBC' $selected {'DCIPHER'}{'CAMELLIA-128-CBC'}>CAMELLIA-CBC (128 $Lang ::tr{'bit'})</option>
4932 <option value='AES-256-CBC' $selected {'DCIPHER'}{'AES-256-CBC'}>AES-CBC (256 $Lang ::tr{'bit'})</option>
4933 <option value='AES-192-CBC' $selected {'DCIPHER'}{'AES-192-CBC'}>AES-CBC (192 $Lang ::tr{'bit'})</option>
4934 <option value='AES-128-CBC' $selected {'DCIPHER'}{'AES-128-CBC'}>AES-CBC (128 $Lang ::tr{'bit'})</option>
4935 <option value='DES-EDE3-CBC' $selected {'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC (192 $Lang ::tr{'bit'})</option>
4936 <option value='DESX-CBC' $selected {'DCIPHER'}{'DESX-CBC'}>DESX-CBC (192 $Lang ::tr{'bit'})</option>
4937 <option value='SEED-CBC' $selected {'DCIPHER'}{'SEED-CBC'}>SEED-CBC (128 $Lang ::tr{'bit'})</option>
4938 <option value='DES-EDE-CBC' $selected {'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC (128 $Lang ::tr{'bit'})</option>
4939 <option value='BF-CBC' $selected {'DCIPHER'}{'BF-CBC'}>BF-CBC (128 $Lang ::tr{'bit'})</option>
4940 <option value='CAST5-CBC' $selected {'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC (128 $Lang ::tr{'bit'})</option>
4941 <option value='RC2-CBC' $selected {'DCIPHER'}{'RC2-CBC'}>RC2-CBC (128 $Lang ::tr{'bit'})</option>
4942 <option value='DES-CBC' $selected {'DCIPHER'}{'DES-CBC'}>DES-CBC (64 $Lang ::tr{'bit'} not recommended)</option>
4943 <option value='RC2-64-CBC' $selected {'DCIPHER'}{'RC2-64-CBC'}>RC2-CBC (64 $Lang ::tr{'bit'} not recommended)</option>
4944 <option value='RC2-40-CBC' $selected {'DCIPHER'}{'RC2-40-CBC'}>RC2-CBC (40 $Lang ::tr{'bit'} not recommended)</option>
4947 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'}</td>
4948 <td><input type='checkbox' name='DCOMPLZO' $checked {'DCOMPLZO'}{'on'} /></td>
4950 <tr><td colspan='4'><br><br></td></tr>
4954 if ( $srunning eq "yes" ) {
4955 print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' disabled='disabled' />" ;
4956 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'ccd net'}' />" ;
4957 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced server'}' />" ;
4958 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'stop ovpn server'}' /></td></tr>" ;
4960 print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
4961 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'ccd net'}' />" ;
4962 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'advanced server'}' />" ;
4963 if (( - e
"${General::swroot}/ovpn/ca/cacert.pem" &&
4964 - e
"${General::swroot}/ovpn/ca/dh1024.pem" &&
4965 - e
"${General::swroot}/ovpn/certs/servercert.pem" &&
4966 - e
"${General::swroot}/ovpn/certs/serverkey.pem" ) &&
4967 (( $cgiparams { 'ENABLED' } eq 'on' ) ||
4968 ( $cgiparams { 'ENABLED_BLUE' } eq 'on' ) ||
4969 ( $cgiparams { 'ENABLED_ORANGE' } eq 'on' ))){
4970 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'start ovpn server'}' /></td></tr>" ;
4972 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'start ovpn server'}' disabled='disabled' /></td></tr>" ;
4975 print "</form></table>" ;
4976 & Header
:: closebox
();
4978 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
4981 #<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>
4984 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'connection status and controlc' });
4988 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
4990 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
4991 <th width='15%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></th>
4992 <th width='22%' class='boldbase' align='center'><b> $Lang ::tr{'network'}</b></th>
4993 <th width='20%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></th>
4994 <th width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></th>
4995 <th width='5%' class='boldbase' colspan='6' align='center'><b> $Lang ::tr{'action'}</b></th>
5002 foreach my $key ( sort { ncmp
( $confighash { $a }[ 1 ], $confighash { $b }[ 1 ]) } keys %confighash ) {
5003 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
5006 $col = "bgcolor=' $color {'color20'}'" ;
5009 $col = "bgcolor=' $color {'color22'}'" ;
5011 print "<td align='center' nowrap='nowrap' $col > $confighash { $key }[1]</td>" ;
5012 print "<td align='center' nowrap='nowrap' $col >" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ")</td>" ;
5013 #if ($confighash{$key}[4] eq 'cert') {
5014 #print "<td align='left' nowrap='nowrap'>$confighash{$key}[2]</td>";
5016 #print "<td align='left'> </td>";
5018 my $cavalid = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $confighash { $key }[1]cert.pem` ;
5019 $cavalid =~ /Not After : (.*)[\n]/ ;
5021 if ( $confighash { $key }[ 32 ] eq "" && $confighash { $key }[ 3 ] eq 'net' ){ $confighash { $key }[ 32 ]= "net-2-net" ;}
5022 if ( $confighash { $key }[ 32 ] eq "" && $confighash { $key }[ 3 ] eq 'host' ){ $confighash { $key }[ 32 ]= "dynamic" ;}
5023 print "<td align='center' $col > $confighash { $key }[32]</td>" ;
5024 print "<td align='center' $col > $confighash { $key }[25]</td>" ;
5025 $col1 = "bgcolor='${Header::colourred}'" ;
5026 my $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
5028 if ( $confighash { $key }[ 0 ] eq 'off' ) {
5029 $col1 = "bgcolor='${Header::colourblue}'" ;
5030 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b>" ;
5037 if ( $confighash { $key }[ 3 ] eq 'net' ) {
5039 if (- e
"/var/run/ $confighash { $key }[1]n2n.pid" ) {
5042 my $tport = $confighash { $key }[ 22 ];
5043 my $tnet = new Net
:: Telnet
( Timeout
=> 5 , Errmode
=> 'return' , Port
=> $tport );
5045 $tnet -> open ( '127.0.0.1' );
5046 @output = $tnet -> cmd ( String
=> 'state' , Prompt
=> '/(END.* \n |ERROR:.* \n )/' );
5047 @tustate = split ( /\,/ , $output [ 1 ]);
5049 #CONNECTING -- OpenVPN's initial state.
5050 #WAIT -- (Client only) Waiting for initial response from server.
5051 #AUTH -- (Client only) Authenticating with server.
5052 #GET_CONFIG -- (Client only) Downloading configuration options from server.
5053 #ASSIGN_IP -- Assigning IP address to virtual network interface.
5054 #ADD_ROUTES -- Adding routes to system.
5055 #CONNECTED -- Initialization Sequence Completed.
5056 #RECONNECTING -- A restart has occurred.
5057 #EXITING -- A graceful exit is in progress.
5060 if ( $tustate [ 1 ] eq 'CONNECTED' ) {
5061 $col1 = "bgcolor='${Header::colourgreen}'" ;
5062 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b>" ;
5064 $col1 = "bgcolor='${Header::colourred}'" ;
5065 $active = "<b><font color='#FFFFFF'> $tustate [1]</font></b>" ;
5073 foreach my $line ( @status ) {
5075 if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ ) {
5076 @match = split ( m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ , $line );
5077 if ( $match [ 1 ] ne "Common Name" ) {
5081 if ( $cn eq " $confighash { $key }[2]" ) {
5082 $col1 = "bgcolor='${Header::colourgreen}'" ;
5083 $active = "<b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b>" ;
5092 <td align='center' $col1 > $active </td>
5094 <form method='post' name='frm${key}a'><td align='center' $col >
5095 <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' />
5096 <input type='hidden' name='ACTION' value=' $Lang ::tr{'dl client arch'}' />
5097 <input type='hidden' name='KEY' value=' $key ' />
5101 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
5103 <form method='post' name='frm${key}b'><td align='center' $col >
5104 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' border='0' />
5105 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
5106 <input type='hidden' name='KEY' value=' $key ' />
5110 print "<td> </td>" ;
5112 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $key }[1].p12" ) {
5114 <form method='post' name='frm${key}c'><td align='center' $col >
5115 <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' />
5116 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
5117 <input type='hidden' name='KEY' value=' $key ' />
5120 ; } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
5122 <form method='post' name='frm${key}c'><td align='center' $col >
5123 <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' />
5124 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
5125 <input type='hidden' name='KEY' value=' $key ' />
5129 print "<td> </td>" ;
5132 <form method='post' name='frm${key}d'><td align='center' $col >
5133 <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' />
5134 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
5135 <input type='hidden' name='KEY' value=' $key ' />
5138 <form method='post' name='frm${key}e'><td align='center' $col >
5139 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
5140 <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'/>
5141 <input type='hidden' name='KEY' value=' $key ' />
5143 <form method='post' name='frm${key}f'><td align='center' $col >
5144 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
5145 <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' />
5146 <input type='hidden' name='KEY' value=' $key ' />
5155 # If the config file contains entries, print Key to action icons
5160 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
5161 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
5162 <td class='base'> $Lang ::tr{'click to disable'}</td>
5163 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
5164 <td class='base'> $Lang ::tr{'show certificate'}</td>
5165 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
5166 <td class='base'> $Lang ::tr{'edit'}</td>
5167 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
5168 <td class='base'> $Lang ::tr{'remove'}</td>
5172 <td> <img src='/images/off.gif' alt='?OFF' /></td>
5173 <td class='base'> $Lang ::tr{'click to enable'}</td>
5174 <td> <img src='/images/media-floppy.png' alt='?FLOPPY' /></td>
5175 <td class='base'> $Lang ::tr{'download certificate'}</td>
5176 <td> <img src='/images/openvpn.png' alt='?RELOAD'/></td>
5177 <td class='base'> $Lang ::tr{'dl client arch'}</td>
5185 <table width='100%'>
5186 <form method='post'>
5187 <tr><td align='right'>
5188 <input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />
5189 <input type='submit' name='ACTION' value=' $Lang ::tr{'ovpn con stat'}' $activeonrun /></td>
5195 & Header
:: closebox
();
5197 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'certificate authorities'}" );
5199 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
5201 <th width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></th>
5202 <th width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></th>
5203 <th width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></th>
5207 my $col1 = "bgcolor=' $color {'color22'}'" ;
5208 my $col2 = "bgcolor=' $color {'color20'}'" ;
5209 if (- f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
5210 my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem` ;
5211 $casubject =~ /Subject: (.*)[\n]/ ;
5213 $casubject =~ s
+/ Email
+, E
+;
5214 $casubject =~ s/ ST=/ S=/ ;
5217 <td class='base' $col1 > $Lang ::tr{'root certificate'}</td>
5218 <td class='base' $col1 > $casubject </td>
5219 <form method='post' name='frmrootcrta'><td width='3%' align='center' $col1 >
5220 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
5221 <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' />
5223 <form method='post' name='frmrootcrtb'><td width='3%' align='center' $col1 >
5224 <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' />
5225 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
5227 <td width='4%' $col1 > </td></tr>
5231 # display rootcert generation buttons
5234 <td class='base' $col1 > $Lang ::tr{'root certificate'}:</td>
5235 <td class='base' $col1 > $Lang ::tr{'not present'}</td>
5236 <td colspan='3' $col1 > </td></tr>
5241 if (- f
"${General::swroot}/ovpn/certs/servercert.pem" ) {
5242 my $hostsubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem` ;
5243 $hostsubject =~ /Subject: (.*)[\n]/ ;
5245 $hostsubject =~ s
+/ Email
+, E
+;
5246 $hostsubject =~ s/ ST=/ S=/ ;
5250 <td class='base' $col2 > $Lang ::tr{'host certificate'}</td>
5251 <td class='base' $col2 > $hostsubject </td>
5252 <form method='post' name='frmhostcrta'><td width='3%' align='center' $col2 >
5253 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
5254 <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' />
5256 <form method='post' name='frmhostcrtb'><td width='3%' align='center' $col2 >
5257 <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' />
5258 <input type='hidden' name='ACTION' value=" $Lang ::tr{'download host certificate'}" />
5260 <td width='4%' $col2 > </td></tr>
5267 <td width='25%' class='base' $col2 > $Lang ::tr{'host certificate'}:</td>
5268 <td class='base' $col2 > $Lang ::tr{'not present'}</td>
5269 </td><td colspan='3' $col2 > </td></tr>
5274 if (! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
5275 print "<tr><td colspan='5' align='center'><form method='post'>" ;
5276 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' />" ;
5277 print "</form></td></tr> \n " ;
5280 if ( keys %cahash > 0 ) {
5281 foreach my $key ( keys %cahash ) {
5282 if (( $key + 1 ) % 2 ) {
5283 print "<tr bgcolor=' $color {'color20'}'> \n " ;
5285 print "<tr bgcolor=' $color {'color22'}'> \n " ;
5287 print "<td class='base'> $cahash { $key }[0]</td> \n " ;
5288 print "<td class='base'> $cahash { $key }[1]</td> \n " ;
5290 <form method='post' name='cafrm${key}a'><td align='center'>
5291 <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' />
5292 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
5293 <input type='hidden' name='KEY' value=' $key ' />
5295 <form method='post' name='cafrm${key}b'><td align='center'>
5296 <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' />
5297 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
5298 <input type='hidden' name='KEY' value=' $key ' />
5300 <form method='post' name='cafrm${key}c'><td align='center'>
5301 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
5302 <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' />
5303 <input type='hidden' name='KEY' value=' $key ' />
5312 # If the file contains entries, print Key to action icons
5313 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
5317 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
5318 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
5319 <td class='base'> $Lang ::tr{'show certificate'}</td>
5320 <td> <img src='/images/media-floppy.png' alt=' $Lang ::tr{'download certificate'}' /></td>
5321 <td class='base'> $Lang ::tr{'download certificate'}</td>
5330 <form method='post' enctype='multipart/form-data'>
5331 <table width='100%' border='0'cellspacing='1' cellpadding='0'>
5333 <td class='base' nowrap='nowrap'> $Lang ::tr{'ca name'}:</td>
5334 <td nowrap='nowrap'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' align='left'/></td>
5335 <td nowrap='nowrap'><input type='file' name='FH' size='25' />
5336 <td nowrap='nowrap' align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'upload ca certificate'}' /></td>
5340 <td class='base' nowrap='nowrap'> $Lang ::tr{'ovpn dh name'}:</td>
5341 <td nowrap='nowrap'><input type='text' name='DH_NAME' value=' $cgiparams {'DH_NAME'}' size='15' align='left'/></td>
5342 <td nowrap='nowrap'><input type='file' name='FH' size='25' />
5343 <td nowrap='nowrap' align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'upload dh key'}' /></td>
5345 <tr><td colspan='4'><br></td></tr>
5347 <td nowrap='nowrap'><input type='submit' name='ACTION' value=' $Lang ::tr{'generate dh key'}' /></td>
5348 <td colspan='4' align='right'><input type='submit' name='ACTION' value=' $Lang ::tr{'show dh'}' /></td>
5352 <td colspan='4' align='right' width='80%'><input type='submit' name='ACTION' value=' $Lang ::tr{'show crl'}' /></td>
5358 if ( $srunning eq "yes" ) {
5359 print "<div align='center'><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' disabled='disabled' /></div></form> \n " ;
5361 print "<div align='center'><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove x509'}' /></div></form> \n " ;
5363 & Header
:: closebox
();
5367 & Header
:: closepage
();