]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/ovpnmain.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2011 IPFire Team <info@ipfire.org> #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
22 # Based on IPFireCore 55
25 use CGI qw
/:standard/ ;
30 use File
:: Temp qw
/ tempfile tempdir / ;
32 use Archive
:: Zip
qw(:ERROR_CODES :CONSTANTS) ;
33 require '/var/ipfire/general-functions.pl' ;
34 require "${General::swroot}/lang.pl" ;
35 require "${General::swroot}/header.pl" ;
36 require "${General::swroot}/countries.pl" ;
38 # enable only the following on debugging purpose
40 use CGI
:: Carp
'fatalsToBrowser' ;
41 #workaround to suppress a warning when a variable is used only once
42 my @dummy = ( ${ Header
:: colourgreen
} );
46 my %mainsettings = ();
47 & General
:: readhash
( "${General::swroot}/main/settings" , \
%mainsettings );
48 & General
:: readhash
( "/srv/web/ipfire/html/themes/" . $mainsettings { 'THEME' }. "/include/colors.txt" , \
%color );
51 ### Initialize variables
61 my $errormessage = '' ;
63 my $routes_push_file = '' ;
64 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%netsettings );
65 $cgiparams { 'ENABLED' } = 'off' ;
66 $cgiparams { 'ENABLED_BLUE' } = 'off' ;
67 $cgiparams { 'ENABLED_ORANGE' } = 'off' ;
68 $cgiparams { 'EDIT_ADVANCED' } = 'off' ;
69 $cgiparams { 'NAT' } = 'off' ;
70 $cgiparams { 'COMPRESSION' } = 'off' ;
71 $cgiparams { 'ONLY_PROPOSED' } = 'off' ;
72 $cgiparams { 'ACTION' } = '' ;
73 $cgiparams { 'CA_NAME' } = '' ;
74 $cgiparams { 'DHCP_DOMAIN' } = '' ;
75 $cgiparams { 'DHCP_DNS' } = '' ;
76 $cgiparams { 'DHCP_WINS' } = '' ;
77 $cgiparams { 'ROUTES_PUSH' } = '' ;
78 $cgiparams { 'DCOMPLZO' } = 'off' ;
79 $cgiparams { 'MSSFIX' } = '' ;
80 $cgiparams { 'PMTU_DISCOVERY' } = '' ;
81 $routes_push_file = "${General::swroot}/ovpn/routes_push" ;
82 unless (- e
$routes_push_file ) { system ( "touch $routes_push_file " ); }
84 & Header
:: getcgihash
( \
%cgiparams , { 'wantfile' => 1 , 'filevar' => 'FH' });
86 # prepare openvpn config file
92 if ( $netsettings { 'CONFIG_TYPE' } == 2 ) { return 1 ;}
93 if ( $netsettings { 'CONFIG_TYPE' } == 4 ) { return 1 ;}
99 if ( $netsettings { 'CONFIG_TYPE' } == 3 ) { return 1 ;}
100 if ( $netsettings { 'CONFIG_TYPE' } == 4 ) { return 1 ;}
105 my $bytesize = shift ;
108 while ( abs ( $bytesize ) >= 1024 ){
109 $bytesize = $bytesize / 1024 ;
114 my @units = ( "Bytes" , "KB" , "MB" , "GB" , "TB" , "PB" , "EB" );
115 my $newsize =( int ( $bytesize * 100 + 0.5 ))/ 100 ;
116 return ( " $newsize $units [ $i ]" );
120 my $hostname = $_ [ 0 ];
121 unless ( $hostname ) { return "No hostname" };
122 my $res = new Net
:: DNS
:: Resolver
;
123 my $query = $res -> search ( " $hostname " );
125 foreach my $rr ( $query -> answer ) {
126 ## Potential bug - we are only looking at A records:
127 return 0 if $rr -> type eq "A" ;
130 return $res -> errorstring ;
136 if ( open ( FILE
, ">${General::swroot}/ovpn/certs/serial" )) {
140 if ( open ( FILE
, ">${General::swroot}/ovpn/certs/index.txt" )) {
144 unlink ( "${General::swroot}/ovpn/certs/index.txt.old" );
145 unlink ( "${General::swroot}/ovpn/certs/serial.old" );
146 unlink ( "${General::swroot}/ovpn/certs/01.pem" );
149 sub newcleanssldatabase
151 if (! - s
"${General::swroot}/ovpn/certs/serial" ) {
152 open ( FILE
, ">${General::swroot}(ovpn/certs/serial" );
156 if (! - s
">${General::swroot}/ovpn/certs/index.txt" ) {
157 system ( "touch ${General::swroot}/ovpn/certs/index.txt" );
159 unlink ( "${General::swroot}/ovpn/certs/index.txt.old" );
160 unlink ( "${General::swroot}/ovpn/certs/serial.old" );
165 if ( open ( FILE
, "${General::swroot}/ovpn/certs/serial.old" )) {
166 my $hexvalue = < FILE
>;
169 unlink ( "${General::swroot}/ovpn/certs/ $hexvalue .pem" );
174 my $KEY2 = $_ [ 0 ]; # key2
175 my $SRC_PORT = $_ [ 1 ]; # src_port
176 my $PROTOCOL = $_ [ 2 ]; # protocol
177 my $SRC_IP = $_ [ 3 ]; # sourceip
179 my $pfwfilename = "${General::swroot}/portfw/config" ;
180 open ( FILE
, $pfwfilename ) or die 'Unable to open config file.' ;
181 my @pfwcurrent = < FILE
>;
183 my $pfwkey1 = 0 ; # used for finding last sequence number used
184 foreach my $pfwline ( @pfwcurrent )
186 my @pfwtemp = split ( /\,/ , $pfwline );
189 if ( $KEY2 eq "0" ){ # if key2 is 0 then it is a portfw addition
190 if ( $SRC_PORT eq $pfwtemp [ 3 ] &&
191 $PROTOCOL eq $pfwtemp [ 2 ] &&
192 $SRC_IP eq $pfwtemp [ 7 ])
194 $errormessage = " $Lang ::tr{'source port in use'} $SRC_PORT " ;
196 # Check if key2 = 0, if it is then it is a port forward entry and we want the sequence number
197 if ( $pfwtemp [ 1 ] eq "0" ) {
198 $pfwkey1 = $pfwtemp [ 0 ];
200 # Darren Critchley - Duplicate or overlapping Port range check
201 if ( $pfwtemp [ 1 ] eq "0" &&
202 $PROTOCOL eq $pfwtemp [ 2 ] &&
203 $SRC_IP eq $pfwtemp [ 7 ] &&
206 & portchecks
( $SRC_PORT , $pfwtemp [ 5 ]);
207 # &portchecks($pfwtemp[3], $pfwtemp[5]);
208 # &portchecks($pfwtemp[3], $SRC_IP);
212 # $errormessage="$KEY2 $SRC_PORT $PROTOCOL $SRC_IP";
219 my $portrange1 = $_ [ 0 ]; # New port range
220 my $portrange2 = $_ [ 1 ]; # existing port range
221 my @tempr1 = split ( /\:/ , $portrange1 );
222 my @tempr2 = split ( /\:/ , $portrange2 );
224 unless (& checkportinc
( $tempr1 [ 0 ], $portrange2 )){ return 0 ;}
225 unless (& checkportinc
( $tempr1 [ 1 ], $portrange2 )){ return 0 ;}
227 unless (& checkportinc
( $tempr2 [ 0 ], $portrange1 )){ return 0 ;}
228 unless (& checkportinc
( $tempr2 [ 1 ], $portrange1 )){ return 0 ;}
230 return 1 ; # Everything checks out!
233 # Darren Critchley - we want to make sure that a port entry is not within an already existing range
236 my $port1 = $_ [ 0 ]; # Port
237 my $portrange2 = $_ [ 1 ]; # Port range
238 my @tempr1 = split ( /\:/ , $portrange2 );
240 if ( $port1 < $tempr1 [ 0 ] || $port1 > $tempr1 [ 1 ]) {
246 # Darren Critchley - Duplicate or overlapping Port range check
249 my $p1 = $_ [ 0 ]; # New port range
250 my $p2 = $_ [ 1 ]; # existing port range
252 our ( $prtrange1 , $prtrange2 );
254 # if (m/:/ && $prtrange1 == 1) { # comparing two port ranges
255 # unless (&checkportoverlap($p1,$p2)) {
256 # $errormessage = "$Lang::tr{'source port overlaps'} $p1";
259 if ( m/:/ && $prtrange1 == 0 && $errormessage eq '' ) { # compare one port to a range
260 unless (& checkportinc
( $p2 , $p1 )) {
261 $errormessage = " $Lang ::tr{'srcprt within existing'} $p1 " ;
265 if (! m/:/ && $prtrange1 == 1 && $errormessage eq '' ) { # compare one port to a range
266 unless (& checkportinc
( $p1 , $p2 )) {
267 $errormessage = " $Lang ::tr{'srcprt range overlaps'} $p2 " ;
273 # Darren Critchley - certain ports are reserved for IPFire
274 # TCP 67,68,81,222,445
276 # Params passed in -> port, rangeyn, protocol
279 # port 67 and 68 same for tcp and udp, don't bother putting in an array
281 my @tcp_reserved = ( 81 , 222 , 445 );
282 my $prt = $_ [ 0 ]; # the port or range
283 my $ryn = $_ [ 1 ]; # tells us whether or not it is a port range
284 my $prot = $_ [ 2 ]; # protocol
285 my $srcdst = $_ [ 3 ]; # source or destination
286 if ( $ryn ) { # disect port range
287 if ( $srcdst eq "src" ) {
288 $msg = " $Lang ::tr{'rsvd src port overlap'}" ;
290 $msg = " $Lang ::tr{'rsvd dst port overlap'}" ;
292 my @tmprng = split ( /\:/ , $prt );
293 unless ( 67 < $tmprng [ 0 ] || 67 > $tmprng [ 1 ]) { $errormessage = " $msg 67" ; return ; }
294 unless ( 68 < $tmprng [ 0 ] || 68 > $tmprng [ 1 ]) { $errormessage = " $msg 68" ; return ; }
295 if ( $prot eq "tcp" ) {
296 foreach my $prange ( @tcp_reserved ) {
297 unless ( $prange < $tmprng [ 0 ] || $prange > $tmprng [ 1 ]) { $errormessage = " $msg $prange " ; return ; }
301 if ( $srcdst eq "src" ) {
302 $msg = " $Lang ::tr{'reserved src port'}" ;
304 $msg = " $Lang ::tr{'reserved dst port'}" ;
306 if ( $prt == 67 ) { $errormessage = " $msg 67" ; return ; }
307 if ( $prt == 68 ) { $errormessage = " $msg 68" ; return ; }
308 if ( $prot eq "tcp" ) {
309 foreach my $prange ( @tcp_reserved ) {
310 if ( $prange == $prt ) { $errormessage = " $msg $prange " ; return ; }
318 sub writeserverconf
{
319 my %sovpnsettings = ();
321 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%sovpnsettings );
324 open ( CONF
, ">${General::swroot}/ovpn/server.conf" ) or die "Unable to open ${General::swroot}/ovpn/server.conf: $!" ;
326 print CONF
"#OpenVPN Server conf \n " ;
328 print CONF
"daemon openvpnserver \n " ;
329 print CONF
"writepid /var/run/openvpn.pid \n " ;
330 print CONF
"#DAN prepare OpenVPN for listening on blue and orange \n " ;
331 print CONF
";local $sovpnsettings {'VPN_IP'} \n " ;
332 print CONF
"dev $sovpnsettings {'DDEVICE'} \n " ;
333 print CONF
"proto $sovpnsettings {'DPROTOCOL'} \n " ;
334 print CONF
"port $sovpnsettings {'DDEST_PORT'} \n " ;
335 print CONF
"script-security 3 system \n " ;
336 print CONF
"ifconfig-pool-persist /var/ipfire/ovpn/ovpn-leases.db 3600 \n " ;
337 print CONF
"client-config-dir /var/ipfire/ovpn/ccd \n " ;
338 print CONF
"tls-server \n " ;
339 print CONF
"ca /var/ipfire/ovpn/ca/cacert.pem \n " ;
340 print CONF
"cert /var/ipfire/ovpn/certs/servercert.pem \n " ;
341 print CONF
"key /var/ipfire/ovpn/certs/serverkey.pem \n " ;
342 print CONF
"dh /var/ipfire/ovpn/ca/dh1024.pem \n " ;
343 my @tempovpnsubnet = split ( "\/" , $sovpnsettings { 'DOVPN_SUBNET' });
344 print CONF
"server $tempovpnsubnet [0] $tempovpnsubnet [1] \n " ;
345 print CONF
"push \" route $netsettings {'GREEN_NETADDRESS'} $netsettings {'GREEN_NETMASK'} \"\n " ;
347 # Check if we are using mssfix, fragment or mtu-disc and set the corretct mtu of 1500.
348 # If we doesn't use one of them, we can use the configured mtu value.
349 if ( $sovpnsettings { 'MSSFIX' } eq 'on' )
350 { print CONF
" $sovpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
351 elsif ( $sovpnsettings { 'FRAGMENT' } ne '' && $sovpnsettings { 'DPROTOCOL' } ne 'tcp' )
352 { print CONF
" $sovpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
353 elsif ( $sovpnsettings { 'PMTU_DISCOVERY' } ne 'off' )
354 { print CONF
" $sovpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
356 { print CONF
" $sovpnsettings {'DDEVICE'}-mtu $sovpnsettings {'DMTU'} \n " ; }
358 if ( $vpnsettings { 'ROUTES_PUSH' } ne '' ) {
359 @temp = split ( /\n/ , $vpnsettings { 'ROUTES_PUSH' });
362 @tempovpnsubnet = split ( "\/" ,& General
:: ipcidr2msk
( $_ ));
363 print CONF
"push \" route " . $tempovpnsubnet [ 0 ]. " " . $tempovpnsubnet [ 1 ] . " \"\n " ;
367 if ( $sovpnsettings { CLIENT2CLIENT
} eq 'on' ) {
368 print CONF
"client-to-client \n " ;
370 if ( $sovpnsettings { MSSFIX
} eq 'on' ) {
371 print CONF
"mssfix \n " ;
373 if ( $sovpnsettings { FRAGMENT
} ne '' && $sovpnsettings { 'DPROTOCOL' } ne 'tcp' ) {
374 print CONF
"fragment $sovpnsettings {'FRAGMENT'} \n " ;
377 if ( $sovpnsettings { PMTU_DISCOVERY
} ne 'off' ) {
378 print CONF
"mtu-disc $sovpnsettings {'PMTU_DISCOVERY'} \n " ;
381 if ( $sovpnsettings { KEEPALIVE_1
} > 0 && $sovpnsettings { KEEPALIVE_2
} > 0 ) {
382 print CONF
"keepalive $sovpnsettings {'KEEPALIVE_1'} $sovpnsettings {'KEEPALIVE_2'} \n " ;
384 print CONF
"status-version 1 \n " ;
385 print CONF
"status /var/log/ovpnserver.log 30 \n " ;
386 print CONF
"cipher $sovpnsettings {DCIPHER} \n " ;
387 if ( $sovpnsettings { DCOMPLZO
} eq 'on' ) {
388 print CONF
"comp-lzo \n " ;
390 if ( $sovpnsettings { REDIRECT_GW_DEF1
} eq 'on' ) {
391 print CONF
"push \" redirect-gateway def1 \"\n " ;
393 if ( $sovpnsettings { DHCP_DOMAIN
} ne '' ) {
394 print CONF
"push \" dhcp-option DOMAIN $sovpnsettings {DHCP_DOMAIN} \"\n " ;
397 if ( $sovpnsettings { DHCP_DNS
} ne '' ) {
398 print CONF
"push \" dhcp-option DNS $sovpnsettings {DHCP_DNS} \"\n " ;
401 if ( $sovpnsettings { DHCP_WINS
} ne '' ) {
402 print CONF
"push \" dhcp-option WINS $sovpnsettings {DHCP_WINS} \"\n " ;
405 if ( $sovpnsettings { DHCP_WINS
} eq '' ) {
406 print CONF
"max-clients 100 \n " ;
408 if ( $sovpnsettings { DHCP_WINS
} ne '' ) {
409 print CONF
"max-clients $sovpnsettings {MAX_CLIENTS} \n " ;
411 print CONF
"tls-verify /var/ipfire/ovpn/verify \n " ;
412 print CONF
"crl-verify /var/ipfire/ovpn/crls/cacrl.pem \n " ;
413 print CONF
"user nobody \n " ;
414 print CONF
"group nobody \n " ;
415 print CONF
"persist-key \n " ;
416 print CONF
"persist-tun \n " ;
417 if ( $sovpnsettings { LOG_VERB
} ne '' ) {
418 print CONF
"verb $sovpnsettings {LOG_VERB} \n " ;
420 print CONF
"verb 3 \n " ;
428 if ( open ( FILE
, ">/var/log/ovpnserver.log" )) {
442 my $ipdotmask = $_ [ 0 ];
443 if (& General
:: validip
( $ipdotmask )) { return 0 ; }
444 if (!( $ipdotmask =~ /^(.*?)\/ (.* ?
)$/)) { }
446 if (( $mask =~ /\./ )) { return 0 ; }
450 # -------------------------------------------------------------------
452 sub write_routepushfile
454 open ( FILE
, "> $routes_push_file " );
456 if ( $vpnsettings { 'ROUTES_PUSH' } ne '' ) {
457 print FILE
$vpnsettings { 'ROUTES_PUSH' };
462 sub read_routepushfile
464 if (- e
" $routes_push_file " ) {
465 open ( FILE
, " $routes_push_file " );
466 delete $vpnsettings { 'ROUTES_PUSH' };
467 while (< FILE
>) { $vpnsettings { 'ROUTES_PUSH' } .= $_ };
469 $cgiparams { 'ROUTES_PUSH' } = $vpnsettings { 'ROUTES_PUSH' };
474 #hier die refresh page
475 if ( - e
"${General::swroot}/ovpn/gencanow" ) {
477 $refresh = "<meta http-equiv='refresh' content='15;' />" ;
478 & Header
:: showhttpheaders
();
479 & Header
:: openpage
( $Lang :: tr
{ 'OVPN' }, 1 , $refresh );
480 & Header
:: openbigbox
( '100%' , 'center' );
481 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
482 print "<tr> \n <td align='center'><img src='/images/clock.gif' alt='' /></td> \n " ;
483 print "<td colspan='2'><font color='red'>Please be patient this realy can take some time on older hardware...</font></td></tr> \n " ;
485 & Header
:: closebigbox
();
486 & Header
:: closepage
();
489 ##hier die refresh page
493 ### OpenVPN Server Control
495 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'start ovpn server' } ||
496 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'stop ovpn server' } ||
497 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart ovpn server' }) {
498 #start openvpn server
499 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'start ovpn server' }){
501 system ( '/usr/local/bin/openvpnctrl' , '-s' );
504 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'stop ovpn server' }){
505 system ( '/usr/local/bin/openvpnctrl' , '-k' );
508 # #restart openvpn server
509 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart ovpn server' }){
510 #workarund, till SIGHUP also works when running as nobody
511 system ( '/usr/local/bin/openvpnctrl' , '-r' );
517 ### Save Advanced options
520 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save-adv-options' }) {
521 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
522 #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too,
523 #DAN this value has to leave.
524 #new settings for daemon
525 $vpnsettings { 'LOG_VERB' } = $cgiparams { 'LOG_VERB' };
526 $vpnsettings { 'KEEPALIVE_1' } = $cgiparams { 'KEEPALIVE_1' };
527 $vpnsettings { 'KEEPALIVE_2' } = $cgiparams { 'KEEPALIVE_2' };
528 $vpnsettings { 'MAX_CLIENTS' } = $cgiparams { 'MAX_CLIENTS' };
529 $vpnsettings { 'REDIRECT_GW_DEF1' } = $cgiparams { 'REDIRECT_GW_DEF1' };
530 $vpnsettings { 'CLIENT2CLIENT' } = $cgiparams { 'CLIENT2CLIENT' };
531 $vpnsettings { 'DHCP_DOMAIN' } = $cgiparams { 'DHCP_DOMAIN' };
532 $vpnsettings { 'DHCP_DNS' } = $cgiparams { 'DHCP_DNS' };
533 $vpnsettings { 'DHCP_WINS' } = $cgiparams { 'DHCP_WINS' };
534 $vpnsettings { 'ROUTES_PUSH' } = $cgiparams { 'ROUTES_PUSH' };
535 $vpnsettings { 'PMTU_DISCOVERY' } = $cgiparams { 'PMTU_DISCOVERY' };
538 if ( $cgiparams { 'FRAGMENT' } eq '' ) {
539 delete $vpnsettings { 'FRAGMENT' };
541 if ( $cgiparams { 'FRAGMENT' } !~ /^[0-9]+$/ ) {
542 $errormessage = "Incorrect value, please insert only numbers." ;
545 $vpnsettings { 'FRAGMENT' } = $cgiparams { 'FRAGMENT' };
548 if ( $cgiparams { 'MSSFIX' } ne 'on' ) {
549 delete $vpnsettings { 'MSSFIX' };
551 $vpnsettings { 'MSSFIX' } = $cgiparams { 'MSSFIX' };
554 if ( $cgiparams { 'PMTU_DISCOVERY' } ne 'off' ) {
555 if (( $cgiparams { 'MSSFIX' } eq 'on' ) || ( $cgiparams { 'FRAGMENT' } ne '' )) {
556 $errormessage = $Lang :: tr
{ 'ovpn mtu-disc with mssfix or fragment' };
561 if ( $cgiparams { 'DHCP_DOMAIN' } ne '' ){
562 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_DOMAIN' }) || & General
:: validip
( $cgiparams { 'DHCP_DOMAIN' })) {
563 $errormessage = $Lang :: tr
{ 'invalid input for dhcp domain' };
567 if ( $cgiparams { 'DHCP_DNS' } ne '' ){
568 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_DNS' }) || & General
:: validip
( $cgiparams { 'DHCP_DNS' })) {
569 $errormessage = $Lang :: tr
{ 'invalid input for dhcp dns' };
573 if ( $cgiparams { 'DHCP_WINS' } ne '' ){
574 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_WINS' }) || & General
:: validip
( $cgiparams { 'DHCP_WINS' })) {
575 $errormessage = $Lang :: tr
{ 'invalid input for dhcp wins' };
579 if ( $cgiparams { 'ROUTES_PUSH' } ne '' ){
580 @temp = split ( /\n/ , $cgiparams { 'ROUTES_PUSH' });
581 undef $vpnsettings { 'ROUTES_PUSH' };
584 s/^\s+//g ; s/\s+$//g ;
587 unless (& General
:: validipandmask
( $_ )) {
588 $errormessage = $Lang :: tr
{ 'ovpn errmsg invalid ip or mask' };
591 my ( $ip , $cidr ) = split ( "\/" ,& General
:: ipcidr2msk
( $_ ));
592 if ( $ip eq $netsettings { 'GREEN_NETADDRESS' } && $cidr eq $netsettings { 'GREEN_NETMASK' }) {
593 $errormessage = $Lang :: tr
{ 'ovpn errmsg green already pushed' };
596 $vpnsettings { 'ROUTES_PUSH' } .= $_ . " \n " ;
599 & write_routepushfile
;
600 undef $vpnsettings { 'ROUTES_PUSH' };
603 undef $vpnsettings { 'ROUTES_PUSH' };
604 & write_routepushfile
;
606 if (( length ( $cgiparams { 'MAX_CLIENTS' }) == 0 ) || (( $cgiparams { 'MAX_CLIENTS' }) < 1 ) || (( $cgiparams { 'MAX_CLIENTS' }) > 255 )) {
607 $errormessage = $Lang :: tr
{ 'invalid input for max clients' };
610 if ( $cgiparams { 'KEEPALIVE_1' } ne '' ) {
611 if ( $cgiparams { 'KEEPALIVE_1' } !~ /^[0-9]+$/ ) {
612 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 1' };
616 if ( $cgiparams { 'KEEPALIVE_2' } ne '' ){
617 if ( $cgiparams { 'KEEPALIVE_2' } !~ /^[0-9]+$/ ) {
618 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 2' };
622 if ( $cgiparams { 'KEEPALIVE_2' } < ( $cgiparams { 'KEEPALIVE_1' } * 2 )){
623 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 1:2' };
627 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
628 & writeserverconf
(); #hier ok
635 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq 'net' && $cgiparams { 'SIDE' } eq 'server' )
638 my @remsubnet = split ( /\/ /, $cgiparams { 'REMOTE_SUBNET' });
639 my @ovsubnettemp = split ( /\./ , $cgiparams { 'OVPN_SUBNET' });
640 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
643 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
644 unless (- d
"${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" , 0770 or die "Unable to create dir $!" ;}
646 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: $!" ;
649 print SERVERCONF
"# IPFire n2n Open VPN Server Config by ummeegge und m.a.d \n " ;
650 print SERVERCONF
" \n " ;
651 print SERVERCONF
"# User Security \n " ;
652 print SERVERCONF
"user nobody \n " ;
653 print SERVERCONF
"group nobody \n " ;
654 print SERVERCONF
"persist-tun \n " ;
655 print SERVERCONF
"persist-key \n " ;
656 print SERVERCONF
"script-security 2 \n " ;
657 print SERVERCONF
"# IP/DNS for remote Server Gateway \n " ;
658 print SERVERCONF
"remote $cgiparams {'REMOTE'} \n " ;
659 print SERVERCONF
"float \n " ;
660 print SERVERCONF
"# IP adresses of the VPN Subnet \n " ;
661 print SERVERCONF
"ifconfig $ovsubnet .1 $ovsubnet .2 \n " ;
662 print SERVERCONF
"# Client Gateway Network \n " ;
663 print SERVERCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
664 print SERVERCONF
"# tun Device \n " ;
665 print SERVERCONF
"dev tun \n " ;
666 print SERVERCONF
"# Port and Protokol \n " ;
667 print SERVERCONF
"port $cgiparams {'DEST_PORT'} \n " ;
669 if ( $cgiparams { 'PROTOCOL' } eq 'tcp' ) {
670 print SERVERCONF
"proto tcp-server \n " ;
671 print SERVERCONF
"# Packet size \n " ;
672 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1400' } else { $tunmtu = $cgiparams { 'MTU' }};
673 print SERVERCONF
"tun-mtu $tunmtu \n " ;
676 if ( $cgiparams { 'PROTOCOL' } eq 'udp' ) {
677 print SERVERCONF
"proto udp \n " ;
678 print SERVERCONF
"# Paketsize \n " ;
679 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1500' } else { $tunmtu = $cgiparams { 'MTU' }};
680 print SERVERCONF
"tun-mtu $tunmtu \n " ;
681 if ( $cgiparams { 'FRAGMENT' } ne '' ) { print SERVERCONF
"fragment $cgiparams {'FRAGMENT'} \n " ;}
682 if ( $cgiparams { 'MSSFIX' } eq 'on' ) { print SERVERCONF
"mssfix \n " ; };
684 if ( $cgiparams { 'PMTU_DISCOVERY' } ne 'off' ) {
685 if (( $cgiparams { 'MSSFIX' } ne 'on' ) || ( $cgiparams { 'FRAGMENT' } eq '' )) {
686 if ( $cgiparams { 'MTU' } eq '1500' ) {
687 print SERVERCONF
"mtu-disc $cgiparams {'PMTU_DISCOVERY'} \n " ;
691 print SERVERCONF
"# Auth. Server \n " ;
692 print SERVERCONF
"tls-server \n " ;
693 print SERVERCONF
"ca ${General::swroot}/ovpn/ca/cacert.pem \n " ;
694 print SERVERCONF
"cert ${General::swroot}/ovpn/certs/servercert.pem \n " ;
695 print SERVERCONF
"key ${General::swroot}/ovpn/certs/serverkey.pem \n " ;
696 print SERVERCONF
"dh ${General::swroot}/ovpn/ca/dh1024.pem \n " ;
697 print SERVERCONF
"# Cipher \n " ;
698 print SERVERCONF
"cipher AES-256-CBC \n " ;
699 if ( $cgiparams { 'COMPLZO' } eq 'on' ) {
700 print SERVERCONF
"# Enable Compression \n " ;
701 print SERVERCONF
"comp-lzo \r\n " ;
703 print SERVERCONF
"# Debug Level \n " ;
704 print SERVERCONF
"verb 3 \n " ;
705 print SERVERCONF
"# Tunnel check \n " ;
706 print SERVERCONF
"keepalive 10 60 \n " ;
707 print SERVERCONF
"# Start as daemon \n " ;
708 print SERVERCONF
"daemon $cgiparams {'NAME'}n2n \n " ;
709 print SERVERCONF
"writepid /var/run/ $cgiparams {'NAME'}n2n.pid \n " ;
710 print SERVERCONF
"# Activate Management Interface and Port \n " ;
711 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) { print SERVERCONF
"management localhost $cgiparams {'DEST_PORT'} \n " }
712 else { print SERVERCONF
"management localhost $cgiparams {'OVPN_MGMT'} \n " };
721 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq 'net' && $cgiparams { 'SIDE' } eq 'client' )
723 my @ovsubnettemp = split ( /\./ , $cgiparams { 'OVPN_SUBNET' });
724 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
725 my @remsubnet = split ( /\/ /, $cgiparams { 'REMOTE_SUBNET' });
728 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
729 unless (- d
"${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" , 0770 or die "Unable to create dir $!" ;}
731 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: $!" ;
734 print CLIENTCONF
"# IPFire rewritten n2n Open VPN Client Config by ummeegge und m.a.d \n " ;
735 print CLIENTCONF
"# \n " ;
736 print CLIENTCONF
"# User Security \n " ;
737 print CLIENTCONF
"user nobody \n " ;
738 print CLIENTCONF
"group nobody \n " ;
739 print CLIENTCONF
"persist-tun \n " ;
740 print CLIENTCONF
"persist-key \n " ;
741 print CLIENTCONF
"script-security 2 \n " ;
742 print CLIENTCONF
"# IP/DNS for remote Server Gateway \n " ;
743 print CLIENTCONF
"remote $cgiparams {'REMOTE'} \n " ;
744 print CLIENTCONF
"float \n " ;
745 print CLIENTCONF
"# IP adresses of the VPN Subnet \n " ;
746 print CLIENTCONF
"ifconfig $ovsubnet .2 $ovsubnet .1 \n " ;
747 print CLIENTCONF
"# Server Gateway Network \n " ;
748 print CLIENTCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
749 print CLIENTCONF
"# tun Device \n " ;
750 print CLIENTCONF
"dev tun \n " ;
751 print CLIENTCONF
"# Port and Protokol \n " ;
752 print CLIENTCONF
"port $cgiparams {'DEST_PORT'} \n " ;
754 if ( $cgiparams { 'PROTOCOL' } eq 'tcp' ) {
755 print CLIENTCONF
"proto tcp-client \n " ;
756 print CLIENTCONF
"# Packet size \n " ;
757 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1400' } else { $tunmtu = $cgiparams { 'MTU' }};
758 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
761 if ( $cgiparams { 'PROTOCOL' } eq 'udp' ) {
762 print CLIENTCONF
"proto udp \n " ;
763 print CLIENTCONF
"# Paketsize \n " ;
764 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1500' } else { $tunmtu = $cgiparams { 'MTU' }};
765 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
766 if ( $cgiparams { 'FRAGMENT' } ne '' ) { print CLIENTCONF
"fragment $cgiparams {'FRAGMENT'} \n " ;}
767 if ( $cgiparams { 'MSSFIX' } eq 'on' ) { print CLIENTCONF
"mssfix \n " ; };
769 if ( $cgiparams { 'PMTU_DISCOVERY' } ne 'off' ) {
770 if (( $cgiparams { 'MSSFIX' } ne 'on' ) || ( $cgiparams { 'FRAGMENT' } eq '' )) {
771 if ( $cgiparams { 'MTU' } eq '1500' ) {
772 print CLIENTCONF
"mtu-disc $cgiparams {'PMTU_DISCOVERY'} \n " ;
776 print CLIENTCONF
"ns-cert-type server \n " ;
777 print CLIENTCONF
"# Auth. Client \n " ;
778 print CLIENTCONF
"tls-client \n " ;
779 print CLIENTCONF
"# Cipher \n " ;
780 print CLIENTCONF
"cipher AES-256-CBC \n " ;
781 print CLIENTCONF
"pkcs12 ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12 \r\n " ;
782 if ( $cgiparams { 'COMPLZO' } eq 'on' ) {
783 print CLIENTCONF
"# Enable Compression \n " ;
784 print CLIENTCONF
"comp-lzo \r\n " ;
786 print CLIENTCONF
"# Debug Level \n " ;
787 print CLIENTCONF
"verb 3 \n " ;
788 print CLIENTCONF
"# Tunnel check \n " ;
789 print CLIENTCONF
"keepalive 10 60 \n " ;
790 print CLIENTCONF
"# Start as daemon \n " ;
791 print CLIENTCONF
"daemon $cgiparams {'NAME'}n2n \n " ;
792 print CLIENTCONF
"writepid /var/run/ $cgiparams {'NAME'}n2n.pid \n " ;
793 print CLIENTCONF
"# Activate Management Interface and Port \n " ;
794 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) { print CLIENTCONF
"management localhost $cgiparams {'DEST_PORT'} \n " }
795 else { print CLIENTCONF
"management localhost $cgiparams {'OVPN_MGMT'} \n " };
801 ### Save main settings
805 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
806 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
807 #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too,
808 #DAN this value has to leave.
809 if ( $cgiparams { 'ENABLED' } eq 'on' ){
810 unless (& General
:: validfqdn
( $cgiparams { 'VPN_IP' }) || & General
:: validip
( $cgiparams { 'VPN_IP' })) {
811 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
815 if ( $cgiparams { 'ENABLED' } eq 'on' ){
816 & disallowreserved
( $cgiparams { 'DDEST_PORT' }, 0 , $cgiparams { 'DPROTOCOL' }, "dest" );
818 if ( $errormessage ) { goto SETTINGS_ERROR
; }
821 if ( $cgiparams { 'ENABLED' } eq 'on' ){
822 & checkportfw
( 0 , $cgiparams { 'DDEST_PORT' }, $cgiparams { 'DPROTOCOL' }, '0.0.0.0' );
825 if ( $errormessage ) { goto SETTINGS_ERROR
; }
827 if (! & General
:: validipandmask
( $cgiparams { 'DOVPN_SUBNET' })) {
828 $errormessage = $Lang :: tr
{ 'ovpn subnet is invalid' };
831 my @tmpovpnsubnet = split ( "\/" , $cgiparams { 'DOVPN_SUBNET' });
833 if (& General
:: IpInSubnet
( $netsettings { 'RED_ADDRESS' },
834 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
835 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire RED Network $netsettings {'RED_ADDRESS'}" ;
839 if (& General
:: IpInSubnet
( $netsettings { 'GREEN_ADDRESS' },
840 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
841 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Green Network $netsettings {'GREEN_ADDRESS'}" ;
845 if (& General
:: IpInSubnet
( $netsettings { 'BLUE_ADDRESS' },
846 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
847 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Blue Network $netsettings {'BLUE_ADDRESS'}" ;
851 if (& General
:: IpInSubnet
( $netsettings { 'ORANGE_ADDRESS' },
852 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
853 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Orange Network $netsettings {'ORANGE_ADDRESS'}" ;
856 open ( ALIASES
, "${General::swroot}/ethernet/aliases" ) or die 'Unable to open aliases file.' ;
860 my @tempalias = split ( /\,/ , $_ );
861 if ( $tempalias [ 1 ] eq 'on' ) {
862 if (& General
:: IpInSubnet
( $tempalias [ 0 ] ,
863 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
864 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire alias entry $tempalias [0]" ;
869 if ( $errormessage ne '' ){
872 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
873 $errormessage = $Lang :: tr
{ 'invalid input' };
876 if (( length ( $cgiparams { 'DMTU' })== 0 ) || (( $cgiparams { 'DMTU' }) < 1000 )) {
877 $errormessage = $Lang :: tr
{ 'invalid mtu input' };
881 unless (& General
:: validport
( $cgiparams { 'DDEST_PORT' })) {
882 $errormessage = $Lang :: tr
{ 'invalid port' };
885 $vpnsettings { 'ENABLED_BLUE' } = $cgiparams { 'ENABLED_BLUE' };
886 $vpnsettings { 'ENABLED_ORANGE' } = $cgiparams { 'ENABLED_ORANGE' };
887 $vpnsettings { 'ENABLED' } = $cgiparams { 'ENABLED' };
888 $vpnsettings { 'VPN_IP' } = $cgiparams { 'VPN_IP' };
889 #new settings for daemon
890 $vpnsettings { 'DOVPN_SUBNET' } = $cgiparams { 'DOVPN_SUBNET' };
891 $vpnsettings { 'DDEVICE' } = $cgiparams { 'DDEVICE' };
892 $vpnsettings { 'DPROTOCOL' } = $cgiparams { 'DPROTOCOL' };
893 $vpnsettings { 'DDEST_PORT' } = $cgiparams { 'DDEST_PORT' };
894 $vpnsettings { 'DMTU' } = $cgiparams { 'DMTU' };
895 $vpnsettings { 'DCOMPLZO' } = $cgiparams { 'DCOMPLZO' };
896 $vpnsettings { 'DCIPHER' } = $cgiparams { 'DCIPHER' };
899 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" );}
900 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" );}
901 if ( $vpnsettings { 'ENABLED' } eq 'on' ) { system ( "touch ${General::swroot}/ovpn/enable 2>/dev/null" );} else { system ( "unlink ${General::swroot}/ovpn/enable 2>/dev/null" );}
902 #new settings for daemon
903 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
904 & writeserverconf
(); #hier ok
909 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'reset' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
911 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
913 foreach my $key ( keys %confighash ) {
914 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
915 delete $confighash { $cgiparams { ' $key ' }};
918 while ( $file = glob ( "${General::swroot}/ovpn/ca/*" )) {
921 while ( $file = glob ( "${General::swroot}/ovpn/certs/*" )) {
924 while ( $file = glob ( "${General::swroot}/ovpn/crls/*" )) {
928 if ( open ( FILE
, ">${General::swroot}/ovpn/caconfig" )) {
932 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
937 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'reset' }) {
938 & Header
:: showhttpheaders
();
939 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
940 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
941 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'are you sure' });
943 <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' />
944 <tr><td align='center'>
945 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
946 $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}
947 <tr><td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'reset'}' />
948 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td></tr>
953 & Header
:: closebigbox
();
954 & Header
:: closepage
();
958 ### Upload CA Certificate
960 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
961 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
963 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
964 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
968 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
969 $errormessage = $Lang :: tr
{ 'name too long' };
973 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
974 $errormessage = $Lang :: tr
{ 'name is invalid' };
975 goto UPLOAD_CA_ERROR
;
978 # Check if there is no other entry with this name
979 foreach my $key ( keys %cahash ) {
980 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
981 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
986 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
987 $errormessage = $Lang :: tr
{ 'there was no file upload' };
990 # Move uploaded ca to a temporary file
991 ( my $fh , my $filename ) = tempfile
( );
992 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
996 my $temp = `/usr/bin/openssl x509 -text -in $filename ` ;
997 if ( $temp !~ /CA:TRUE/i ) {
998 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
1000 goto UPLOADCA_ERROR
;
1002 move
( $filename , "${General::swroot}/ovpn/ca/ $cgiparams {'CA_NAME'}cert.pem" );
1004 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1006 goto UPLOADCA_ERROR
;
1010 my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/ $cgiparams {'CA_NAME'}cert.pem` ;
1011 $casubject =~ /Subject: (.*)[\n]/ ;
1013 $casubject =~ s
+/ Email
+, E
+;
1014 $casubject =~ s/ ST=/ S=/ ;
1015 $casubject = & Header
:: cleanhtml
( $casubject );
1017 my $key = & General
:: findhasharraykey
( \
%cahash );
1018 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
1019 $cahash { $key }[ 1 ] = $casubject ;
1020 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1021 # system('/usr/local/bin/ipsecctrl', 'R');
1026 ### Display ca certificate
1028 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
1029 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1031 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1032 & Header
:: showhttpheaders
();
1033 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1034 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
1035 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'ca certificate'}:" );
1036 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
1037 $output = & Header
:: cleanhtml
( $output , "y" );
1038 print "<pre> $output </pre> \n " ;
1039 & Header
:: closebox
();
1040 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1041 & Header
:: closebigbox
();
1042 & Header
:: closepage
();
1045 $errormessage = $Lang :: tr
{ 'invalid key' };
1049 ### Download ca certificate
1051 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
1052 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1054 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1055 print "Content-Type: application/octet-stream \r\n " ;
1056 print "Content-Disposition: filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
1057 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
1060 $errormessage = $Lang :: tr
{ 'invalid key' };
1064 ### Remove ca certificate (step 2)
1066 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
1067 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1068 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1070 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1071 foreach my $key ( keys %confighash ) {
1072 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` ;
1073 if ( $test =~ /: OK/ ) {
1075 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1076 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
1077 # system('/usr/local/bin/ipsecctrl', 'D', $key);
1079 unlink ( "${General::swroot}/ovpn//certs/ $confighash { $key }[1]cert.pem" );
1080 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $key }[1].p12" );
1081 delete $confighash { $key };
1082 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1083 # &writeipsecfiles();
1086 unlink ( "${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
1087 delete $cahash { $cgiparams { 'KEY' }};
1088 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1089 # system('/usr/local/bin/ipsecctrl', 'R');
1091 $errormessage = $Lang :: tr
{ 'invalid key' };
1094 ### Remove ca certificate (step 1)
1096 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
1097 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1098 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1100 my $assignedcerts = 0 ;
1101 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1102 foreach my $key ( keys %confighash ) {
1103 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` ;
1104 if ( $test =~ /: OK/ ) {
1108 if ( $assignedcerts ) {
1109 & Header
:: showhttpheaders
();
1110 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1111 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
1112 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'are you sure' });
1114 <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' />
1115 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
1116 <tr><td align='center'>
1117 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>: $assignedcerts
1118 $Lang ::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}
1119 <tr><td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
1120 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td></tr>
1124 & Header
:: closebox
();
1125 & Header
:: closebigbox
();
1126 & Header
:: closepage
();
1129 unlink ( "${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
1130 delete $cahash { $cgiparams { 'KEY' }};
1131 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1132 # system('/usr/local/bin/ipsecctrl', 'R');
1135 $errormessage = $Lang :: tr
{ 'invalid key' };
1139 ### Display root certificate
1141 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
1142 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
1144 & Header
:: showhttpheaders
();
1145 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1146 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1147 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
1148 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'root certificate'}:" );
1149 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem` ;
1151 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'host certificate'}:" );
1152 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem` ;
1154 $output = & Header
:: cleanhtml
( $output , "y" );
1155 print "<pre> $output </pre> \n " ;
1156 & Header
:: closebox
();
1157 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1158 & Header
:: closebigbox
();
1159 & Header
:: closepage
();
1163 ### Download root certificate
1165 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
1166 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
1167 print "Content-Type: application/octet-stream \r\n " ;
1168 print "Content-Disposition: filename=cacert.pem \r\n\r\n " ;
1169 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/cacert.pem` ;
1174 ### Download host certificate
1176 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
1177 if ( - f
"${General::swroot}/ovpn/certs/servercert.pem" ) {
1178 print "Content-Type: application/octet-stream \r\n " ;
1179 print "Content-Disposition: filename=servercert.pem \r\n\r\n " ;
1180 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/certs/servercert.pem` ;
1184 ### Form for generating a root certificate
1186 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
1187 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
1189 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1190 if (- f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
1191 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
1192 $cgiparams { 'ACTION' } = '' ;
1193 goto ROOTCERT_ERROR
;
1196 if (( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) && - e
"${General::swroot}/red/active" ) {
1197 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
1198 my $ipaddr = < IPADDR
>;
1201 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
1202 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
1203 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
1206 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
1208 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1209 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1210 goto ROOTCERT_ERROR
;
1213 # Move uploaded certificate request to a temporary file
1214 ( my $fh , my $filename ) = tempfile
( );
1215 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1217 goto ROOTCERT_ERROR
;
1220 # Create a temporary dirctory
1221 my $tempdir = tempdir
( CLEANUP
=> 1 );
1223 # Extract the CA certificate from the file
1224 my $pid = open ( OPENSSL
, "|-" );
1225 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1226 if ( $pid ) { # parent
1227 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1228 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1232 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1234 goto ROOTCERT_ERROR
;
1237 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-cacerts' , '-nokeys' ,
1239 '-out' , " $tempdir /cacert.pem" )) {
1240 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1242 goto ROOTCERT_ERROR
;
1246 # Extract the Host certificate from the file
1247 $pid = open ( OPENSSL
, "|-" );
1248 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1249 if ( $pid ) { # parent
1250 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1251 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1255 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1257 goto ROOTCERT_ERROR
;
1260 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-clcerts' , '-nokeys' ,
1262 '-out' , " $tempdir /hostcert.pem" )) {
1263 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1265 goto ROOTCERT_ERROR
;
1269 # Extract the Host key from the file
1270 $pid = open ( OPENSSL
, "|-" );
1271 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1272 if ( $pid ) { # parent
1273 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1274 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1278 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1280 goto ROOTCERT_ERROR
;
1283 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-nocerts' ,
1286 '-out' , " $tempdir /serverkey.pem" )) {
1287 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1289 goto ROOTCERT_ERROR
;
1293 move
( " $tempdir /cacert.pem" , "${General::swroot}/ovpn/ca/cacert.pem" );
1295 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1297 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1298 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1299 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1300 goto ROOTCERT_ERROR
;
1303 move
( " $tempdir /hostcert.pem" , "${General::swroot}/ovpn/certs/servercert.pem" );
1305 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1307 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1308 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1309 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1310 goto ROOTCERT_ERROR
;
1313 move
( " $tempdir /serverkey.pem" , "${General::swroot}/ovpn/certs/serverkey.pem" );
1315 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1317 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1318 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1319 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1320 goto ROOTCERT_ERROR
;
1323 goto ROOTCERT_SUCCESS
;
1325 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
1327 # Validate input since the form was submitted
1328 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
1329 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
1330 goto ROOTCERT_ERROR
;
1332 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
1333 $errormessage = $Lang :: tr
{ 'organization too long' };
1334 goto ROOTCERT_ERROR
;
1336 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1337 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1338 goto ROOTCERT_ERROR
;
1340 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
1341 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
1342 goto ROOTCERT_ERROR
;
1344 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
1345 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
1346 goto ROOTCERT_ERROR
;
1348 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
1349 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1350 goto ROOTCERT_ERROR
;
1352 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
1353 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1354 goto ROOTCERT_ERROR
;
1356 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1357 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1358 goto ROOTCERT_ERROR
;
1360 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1361 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1362 goto ROOTCERT_ERROR
;
1364 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1365 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1366 goto ROOTCERT_ERROR
;
1368 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1369 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1370 goto ROOTCERT_ERROR
;
1373 # Copy the cgisettings to vpnsettings and save the configfile
1374 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
1375 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
1376 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
1377 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
1378 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
1379 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
1380 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
1381 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1383 # Replace empty strings with a .
1384 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
1385 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
1386 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
1389 #system ('/bin/touch', "${General::swroot}/ovpn/gencanow");
1391 # Create the CA certificate
1392 my $pid = open ( OPENSSL
, "|-" );
1393 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1394 if ( $pid ) { # parent
1395 print OPENSSL
" $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1396 print OPENSSL
" $state \n " ;
1397 print OPENSSL
" $city \n " ;
1398 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1399 print OPENSSL
" $ou \n " ;
1400 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
1401 print OPENSSL
" $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1404 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1405 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1406 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1407 goto ROOTCERT_ERROR
;
1410 unless ( exec ( '/usr/bin/openssl' , 'req' , '-x509' , '-nodes' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
1411 '-days' , '999999' , '-newkey' , 'rsa:2048' ,
1412 '-keyout' , "${General::swroot}/ovpn/ca/cakey.pem" ,
1413 '-out' , "${General::swroot}/ovpn/ca/cacert.pem" ,
1414 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
1415 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1416 goto ROOTCERT_ERROR
;
1420 # Create the Host certificate request
1421 $pid = open ( OPENSSL
, "|-" );
1422 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1423 if ( $pid ) { # parent
1424 print OPENSSL
" $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1425 print OPENSSL
" $state \n " ;
1426 print OPENSSL
" $city \n " ;
1427 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1428 print OPENSSL
" $ou \n " ;
1429 print OPENSSL
" $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
1430 print OPENSSL
" $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1431 print OPENSSL
". \n " ;
1432 print OPENSSL
". \n " ;
1435 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1436 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1437 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1438 goto ROOTCERT_ERROR
;
1441 unless ( exec ( '/usr/bin/openssl' , 'req' , '-nodes' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
1442 '-newkey' , 'rsa:1024' ,
1443 '-keyout' , "${General::swroot}/ovpn/certs/serverkey.pem" ,
1444 '-out' , "${General::swroot}/ovpn/certs/serverreq.pem" ,
1445 '-extensions' , 'server' ,
1446 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
1447 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1448 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1449 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1450 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1451 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1452 goto ROOTCERT_ERROR
;
1456 # Sign the host certificate request
1457 system ( '/usr/bin/openssl' , 'ca' , '-days' , '999999' ,
1458 '-batch' , '-notext' ,
1459 '-in' , "${General::swroot}/ovpn/certs/serverreq.pem" ,
1460 '-out' , "${General::swroot}/ovpn/certs/servercert.pem" ,
1461 '-extensions' , 'server' ,
1462 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
1464 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1465 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1466 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1467 unlink ( "${General::swroot}/ovpn/serverkey.pem" );
1468 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1469 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1470 & newcleanssldatabase
();
1471 goto ROOTCERT_ERROR
;
1473 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1474 & deletebackupcert
();
1477 # Create an empty CRL
1478 system ( '/usr/bin/openssl' , 'ca' , '-gencrl' ,
1479 '-out' , "${General::swroot}/ovpn/crls/cacrl.pem" ,
1480 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
1482 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1483 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1484 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1485 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1486 unlink ( "${General::swroot}/ovpn/crls/cacrl.pem" );
1487 & cleanssldatabase
();
1488 goto ROOTCERT_ERROR
;
1490 # &cleanssldatabase();
1492 # Create Diffie Hellmann Parameter
1493 system ( '/usr/bin/openssl' , 'dhparam' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
1494 '-out' , "${General::swroot}/ovpn/ca/dh1024.pem" ,
1497 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1498 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1499 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1500 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1501 unlink ( "${General::swroot}/ovpn/crls/cacrl.pem" );
1502 unlink ( "${General::swroot}/ovpn/ca/dh1024.pem" );
1503 & cleanssldatabase
();
1504 goto ROOTCERT_ERROR
;
1506 # &cleanssldatabase();
1508 goto ROOTCERT_SUCCESS
;
1511 if ( $cgiparams { 'ACTION' } ne '' ) {
1512 & Header
:: showhttpheaders
();
1513 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1514 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1515 if ( $errormessage ) {
1516 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
1517 print "<class name='base'> $errormessage " ;
1518 print " </class>" ;
1519 & Header
:: closebox
();
1521 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'generate root/host certificates'}:" );
1523 <form method='post' enctype='multipart/form-data'>
1524 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1525 <tr><td width='30%' class='base'> $Lang ::tr{'organization name'}:</td>
1526 <td width='35%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td>
1527 <td width='35%' colspan='2'> </td></tr>
1528 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}:</td>
1529 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td>
1530 <td colspan='2'> </td></tr>
1531 <tr><td class='base'> $Lang ::tr{'your e-mail'}: <img src='/blob.gif' alt'*' /></td>
1532 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td>
1533 <td colspan='2'> </td></tr>
1534 <tr><td class='base'> $Lang ::tr{'your department'}: <img src='/blob.gif' alt'*' /></td>
1535 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td>
1536 <td colspan='2'> </td></tr>
1537 <tr><td class='base'> $Lang ::tr{'city'}: <img src='/blob.gif' alt'*' /></td>
1538 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td>
1539 <td colspan='2'> </td></tr>
1540 <tr><td class='base'> $Lang ::tr{'state or province'}: <img src='/blob.gif' alt'*' /></td>
1541 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td>
1542 <td colspan='2'> </td></tr>
1543 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1544 <td class='base'><select name='ROOTCERT_COUNTRY'>
1548 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1549 print "<option value=' $Countries ::countries{ $country }'" ;
1550 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1551 print " selected='selected'" ;
1553 print "> $country </option>" ;
1557 <td colspan='2'> </td></tr>
1559 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /></td>
1560 <td> </td><td> </td></tr>
1561 <tr><td class='base' colspan='4' align='left'>
1562 <img src='/blob.gif' valign='top' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
1563 <tr><td class='base' colspan='4' align='left'>
1564 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1565 $Lang ::tr{'generating the root and host certificates may take a long time. it can take up to several minutes on older hardware. please be patient'}
1567 <tr><td colspan='4' bgcolor='#000000'><img src='/images/null.gif' width='1' height='1' border='0' /></td></tr>
1568 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}:</td>
1569 <td nowrap='nowrap'><input type='file' name='FH' size='32'></td>
1570 <td colspan='2'> </td></tr>
1571 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' ></td>
1572 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td>
1573 <td colspan='2'> </td></tr>
1575 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td>
1576 <td colspan='2'> </td></tr>
1577 <tr><td class='base' colspan='4' align='left'>
1578 <img src='/blob.gif' valign='top' al='*' > $Lang ::tr{'this field may be blank'}</td></tr>
1582 & Header
:: closebox
();
1584 & Header
:: closebigbox
();
1585 & Header
:: closepage
();
1590 system ( "chmod 600 ${General::swroot}/ovpn/certs/serverkey.pem" );
1591 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1592 # $vpnsettings{'ENABLE_BLUE'} eq 'on') {
1593 # system('/usr/local/bin/ipsecctrl', 'S');
1597 ### Enable/Disable connection
1604 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1606 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1607 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1608 # my $n2nactive = '';
1609 my $n2nactive = `/bin/ps ax|grep $confighash { $cgiparams {'KEY'}}[1]|grep -v grep|awk \' {print \ $1 } \' ` ;
1611 if ( $confighash { $cgiparams { 'KEY' }}) {
1614 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
1615 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
1616 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1618 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
1619 system ( '/usr/local/bin/openvpnctrl' , '-sn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
1624 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
1625 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1627 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
1628 if ( $n2nactive ne '' ){
1629 system ( '/usr/local/bin/openvpnctrl' , '-kn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
1633 $errormessage = $Lang :: tr
{ 'invalid key' };
1639 ### Download OpenVPN client package
1643 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'dl client arch' }) {
1644 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1645 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1647 my $clientovpn = '' ;
1649 my $tempdir = tempdir
( CLEANUP
=> 1 );
1650 my $zippath = " $tempdir /" ;
1656 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
1658 my $zipname = " $confighash { $cgiparams {'KEY'}}[1]-Client.zip" ;
1659 my $zippathname = " $zippath $zipname " ;
1660 $clientovpn = " $confighash { $cgiparams {'KEY'}}[1].conf" ;
1661 my @ovsubnettemp = split ( /\./ , $confighash { $cgiparams { 'KEY' }}[ 27 ]);
1662 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
1664 my @remsubnet = split ( /\/ /, $confighash { $cgiparams { 'KEY' }}[ 8 ]);
1665 my $n2nfragment = '' ;
1667 open ( CLIENTCONF
, "> $tempdir / $clientovpn " ) or die "Unable to open tempfile: $!" ;
1668 flock CLIENTCONF
, 2 ;
1670 my $zip = Archive
:: Zip
-> new ();
1671 print CLIENTCONF
"# IPFire n2n Open VPN Client Config by ummeegge und m.a.d \n " ;
1672 print CLIENTCONF
"# \n " ;
1673 print CLIENTCONF
"# User Security \n " ;
1674 print CLIENTCONF
"user nobody \n " ;
1675 print CLIENTCONF
"group nobody \n " ;
1676 print CLIENTCONF
"persist-tun \n " ;
1677 print CLIENTCONF
"persist-key \n " ;
1678 print CLIENTCONF
"script-security 2 \n " ;
1679 print CLIENTCONF
"# IP/DNS for remote Server Gateway \n " ;
1680 print CLIENTCONF
"remote $vpnsettings {'VPN_IP'} \n " ;
1681 print CLIENTCONF
"float \n " ;
1682 print CLIENTCONF
"# IP adresses of the VPN Subnet \n " ;
1683 print CLIENTCONF
"ifconfig $ovsubnet .2 $ovsubnet .1 \n " ;
1684 print CLIENTCONF
"# Server Gateway Network \n " ;
1685 print CLIENTCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
1686 print CLIENTCONF
"# tun Device \n " ;
1687 print CLIENTCONF
"dev $vpnsettings {'DDEVICE'} \n " ;
1688 print CLIENTCONF
"# Port and Protokoll \n " ;
1689 print CLIENTCONF
"port $confighash { $cgiparams {'KEY'}}[29] \n " ;
1691 if ( $confighash { $cgiparams { 'KEY' }}[ 28 ] eq 'tcp' ) {
1692 print CLIENTCONF
"proto tcp-client \n " ;
1693 print CLIENTCONF
"# Packet size \n " ;
1694 if ( $confighash { $cgiparams { 'KEY' }}[ 31 ] eq '' ) { $tunmtu = '1400' } else { $tunmtu = $confighash { $cgiparams { 'KEY' }}[ 31 ]};
1695 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
1698 if ( $confighash { $cgiparams { 'KEY' }}[ 28 ] eq 'udp' ) {
1699 print CLIENTCONF
"proto udp \n " ;
1700 print CLIENTCONF
"# Paketsize \n " ;
1701 if ( $confighash { $cgiparams { 'KEY' }}[ 31 ] eq '' ) { $tunmtu = '1500' } else { $tunmtu = $confighash { $cgiparams { 'KEY' }}[ 31 ]};
1702 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
1703 if ( $confighash { $cgiparams { 'KEY' }}[ 24 ] ne '' ) { print CLIENTCONF
"fragment $confighash { $cgiparams {'KEY'}}[24] \n " ;}
1704 if ( $confighash { $cgiparams { 'KEY' }}[ 23 ] eq 'on' ) { print CLIENTCONF
"mssfix \n " ;}
1706 if ( $confighash { $cgiparams { 'KEY' }}[ 32 ] ne 'off' ) {
1707 if (( $confighash { $cgiparams { 'KEY' }}[ 23 ] ne 'on' ) || ( $confighash { $cgiparams { 'KEY' }}[ 24 ] eq '' )) {
1708 if ( $tunmtu eq '1500' ) {
1709 print CLIENTCONF
"mtu-disc $confighash { $cgiparams {'KEY'}}[32] \n " ;
1713 print CLIENTCONF
"ns-cert-type server \n " ;
1714 print CLIENTCONF
"# Auth. Client \n " ;
1715 print CLIENTCONF
"tls-client \n " ;
1716 print CLIENTCONF
"# Cipher \n " ;
1717 print CLIENTCONF
"cipher AES-256-CBC \n " ;
1718 if ( $confighash { $cgiparams { 'KEY' }}[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ) {
1719 print CLIENTCONF
"pkcs12 ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12 \r\n " ;
1720 $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 " ;
1722 if ( $confighash { $cgiparams { 'KEY' }}[ 30 ] eq 'on' ) {
1723 print CLIENTCONF
"# Enable Compression \n " ;
1724 print CLIENTCONF
"comp-lzo \r\n " ;
1726 print CLIENTCONF
"# Debug Level \n " ;
1727 print CLIENTCONF
"verb 3 \n " ;
1728 print CLIENTCONF
"# Tunnel check \n " ;
1729 print CLIENTCONF
"keepalive 10 60 \n " ;
1730 print CLIENTCONF
"# Start as daemon \n " ;
1731 print CLIENTCONF
"daemon $confighash { $cgiparams {'KEY'}}[1]n2n \n " ;
1732 print CLIENTCONF
"writepid /var/run/ $confighash { $cgiparams {'KEY'}}[1]n2n.pid \n " ;
1733 print CLIENTCONF
"# Activate Management Interface and Port \n " ;
1734 if ( $confighash { $cgiparams { 'KEY' }}[ 22 ] eq '' ) { print CLIENTCONF
"management localhost $confighash { $cgiparams {'KEY'}}[29] \n " }
1735 else { print CLIENTCONF
"management localhost $confighash { $cgiparams {'KEY'}}[22] \n " };
1736 print CLIENTCONF
"# remsub $confighash { $cgiparams {'KEY'}}[11] \n " ;
1741 $zip -> addFile ( " $tempdir / $clientovpn " , $clientovpn ) or die "Can't add file $clientovpn \n " ;
1742 my $status = $zip -> writeToFileNamed ( $zippathname );
1744 open ( DLFILE
, "< $zippathname " ) or die "Unable to open $zippathname : $!" ;
1745 @fileholder = < DLFILE
>;
1746 print "Content-Type:application/x-download \n " ;
1747 print "Content-Disposition:attachment;filename= $zipname \n\n " ;
1753 my $zipname = " $confighash { $cgiparams {'KEY'}}[1]-TO-IPFire.zip" ;
1754 my $zippathname = " $zippath $zipname " ;
1755 $clientovpn = " $confighash { $cgiparams {'KEY'}}[1]-TO-IPFire.ovpn" ;
1761 open ( CLIENTCONF
, "> $tempdir / $clientovpn " ) or die "Unable to open tempfile: $!" ;
1762 flock CLIENTCONF
, 2 ;
1764 my $zip = Archive
:: Zip
-> new ();
1766 print CLIENTCONF
"#OpenVPN Server conf \r\n " ;
1767 print CLIENTCONF
"tls-client \r\n " ;
1768 print CLIENTCONF
"client \r\n " ;
1769 print CLIENTCONF
"dev $vpnsettings {'DDEVICE'} \r\n " ;
1770 print CLIENTCONF
"proto $vpnsettings {'DPROTOCOL'} \r\n " ;
1772 # Check if we are using fragment, mssfix or mtu-disc and set MTU to 1500
1773 # or use configured value.
1774 if ( $vpnsettings { FRAGMENT
} ne '' && $vpnsettings { DPROTOCOL
} ne 'tcp' )
1775 { print CLIENTCONF
" $vpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
1776 elsif ( $vpnsettings { MSSFIX
} eq 'on' )
1777 { print CLIENTCONF
" $vpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
1778 elsif ( $vpnsettings { PMTU_DISCOVERY
} ne 'off' )
1779 { print CLIENTCONF
" $vpnsettings {'DDEVICE'}-mtu 1500 \n " ; }
1781 { print CLIENTCONF
" $vpnsettings {'DDEVICE'}-mtu $vpnsettings {'DMTU'} \r\n " ; }
1783 if ( $vpnsettings { 'ENABLED' } eq 'on' ){
1784 print CLIENTCONF
"remote $vpnsettings {'VPN_IP'} $vpnsettings {'DDEST_PORT'} \r\n " ;
1785 if ( $vpnsettings { 'ENABLED_BLUE' } eq 'on' && (& haveBlueNet
())){
1786 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Blue interface \r\n " ;
1787 print CLIENTCONF
";remote $netsettings {'BLUE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
1789 if ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
1790 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Orange interface \r\n " ;
1791 print CLIENTCONF
";remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
1793 } elsif ( $vpnsettings { 'ENABLED_BLUE' } eq 'on' && (& haveBlueNet
())){
1794 print CLIENTCONF
"remote $netsettings {'BLUE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
1795 if ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
1796 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Orange interface \r\n " ;
1797 print CLIENTCONF
";remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
1799 } elsif ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
1800 print CLIENTCONF
"remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
1803 if ( $confighash { $cgiparams { 'KEY' }}[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ) {
1804 print CLIENTCONF
"pkcs12 $confighash { $cgiparams {'KEY'}}[1].p12 \r\n " ;
1805 $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 " ;
1807 print CLIENTCONF
"ca cacert.pem \r\n " ;
1808 print CLIENTCONF
"cert $confighash { $cgiparams {'KEY'}}[1]cert.pem \r\n " ;
1809 print CLIENTCONF
"key $confighash { $cgiparams {'KEY'}}[1].key \r\n " ;
1810 $zip -> addFile ( "${General::swroot}/ovpn/ca/cacert.pem" , "cacert.pem" ) or die "Can't add file cacert.pem \n " ;
1811 $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 " ;
1813 print CLIENTCONF
"cipher $vpnsettings {DCIPHER} \r\n " ;
1814 if ( $vpnsettings { DCOMPLZO
} eq 'on' ) {
1815 print CLIENTCONF
"comp-lzo \r\n " ;
1817 print CLIENTCONF
"verb 3 \r\n " ;
1818 print CLIENTCONF
"ns-cert-type server \r\n " ;
1819 print CLIENTCONF
"tls-remote $vpnsettings {ROOTCERT_HOSTNAME} \r\n " ;
1820 if ( $vpnsettings { MSSFIX
} eq 'on' ) {
1821 print CLIENTCONF
"mssfix \r\n " ;
1823 if ( $vpnsettings { FRAGMENT
} ne '' && $vpnsettings { DPROTOCOL
} ne 'tcp' ) {
1824 print CLIENTCONF
"fragment $vpnsettings {'FRAGMENT'} \r\n " ;
1826 if ( $vpnsettings { PMTU_DISCOVERY
} ne 'off' ) {
1827 if (( $vpnsettings { MSSFIX
} ne 'on' ) || ( $vpnsettings { FRAGMENT
} eq '' )) {
1828 print CLIENTCONF
"mtu-disc $vpnsettings {'PMTU_DISCOVERY'} \n " ;
1833 $zip -> addFile ( " $tempdir / $clientovpn " , $clientovpn ) or die "Can't add file $clientovpn \n " ;
1834 my $status = $zip -> writeToFileNamed ( $zippathname );
1836 open ( DLFILE
, "< $zippathname " ) or die "Unable to open $zippathname : $!" ;
1837 @fileholder = < DLFILE
>;
1838 print "Content-Type:application/x-download \n " ;
1839 print "Content-Disposition:attachment;filename= $zipname \n\n " ;
1847 ### Remove connection
1851 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
1852 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1853 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1855 if ( $confighash { $cgiparams { 'KEY' }}) {
1856 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1857 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
1858 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
1861 my $temp = `/usr/bin/openssl ca -revoke ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf` ;
1867 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ) {
1869 my $conffile = glob ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]/ $confighash { $cgiparams {'KEY'}}[1].conf" );
1870 my $certfile = glob ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1871 unlink ( $certfile ) or die "Removing $certfile fail: $!" ;
1872 unlink ( $conffile ) or die "Removing $conffile fail: $!" ;
1873 rmdir ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]" ) || die "Kann Verzeichnis nicht loeschen: $!" ;
1877 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1878 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1879 delete $confighash { $cgiparams { 'KEY' }};
1880 my $temp2 = `/usr/bin/openssl ca -gencrl -out ${General::swroot}/ovpn/crls/cacrl.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf` ;
1881 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1882 #&writeserverconf();
1884 $errormessage = $Lang :: tr
{ 'invalid key' };
1889 ### Download PKCS12 file
1891 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
1892 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1894 print "Content-Disposition: filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
1895 print "Content-Type: application/octet-stream \r\n\r\n " ;
1896 print `/bin/cat ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12` ;
1900 ### Display certificate
1902 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
1903 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1905 if ( - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1906 & Header
:: showhttpheaders
();
1907 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1908 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1909 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'certificate'}:" );
1910 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1911 $output = & Header
:: cleanhtml
( $output , "y" );
1912 print "<pre> $output </pre> \n " ;
1913 & Header
:: closebox
();
1914 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1915 & Header
:: closebigbox
();
1916 & Header
:: closepage
();
1920 ### Display Certificate Revoke List
1922 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show crl' }) {
1923 # &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1925 if ( - f
"${General::swroot}/ovpn/crls/cacrl.pem" ) {
1926 & Header
:: showhttpheaders
();
1927 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1928 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1929 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'crl'}:" );
1930 my $output = `/usr/bin/openssl crl -text -noout -in ${General::swroot}/ovpn/crls/cacrl.pem` ;
1931 $output = & Header
:: cleanhtml
( $output , "y" );
1932 print "<pre> $output </pre> \n " ;
1933 & Header
:: closebox
();
1934 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1935 & Header
:: closebigbox
();
1936 & Header
:: closepage
();
1941 ### Advanced Server Settings
1944 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced server' }) {
1948 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%cgiparams );
1951 # if ($cgiparams{'CLIENT2CLIENT'} eq '') {
1952 # $cgiparams{'CLIENT2CLIENT'} = 'on';
1955 if ( $cgiparams { 'MAX_CLIENTS' } eq '' ) {
1956 $cgiparams { 'MAX_CLIENTS' } = '100' ;
1958 if ( $cgiparams { 'KEEPALIVE_1' } eq '' ) {
1959 $cgiparams { 'KEEPALIVE_1' } = '10' ;
1961 if ( $cgiparams { 'KEEPALIVE_2' } eq '' ) {
1962 $cgiparams { 'KEEPALIVE_2' } = '60' ;
1964 if ( $cgiparams { 'LOG_VERB' } eq '' ) {
1965 $cgiparams { 'LOG_VERB' } = '3' ;
1967 $checked { 'CLIENT2CLIENT' }{ 'off' } = '' ;
1968 $checked { 'CLIENT2CLIENT' }{ 'on' } = '' ;
1969 $checked { 'CLIENT2CLIENT' }{ $cgiparams { 'CLIENT2CLIENT' }} = 'CHECKED' ;
1970 $checked { 'REDIRECT_GW_DEF1' }{ 'off' } = '' ;
1971 $checked { 'REDIRECT_GW_DEF1' }{ 'on' } = '' ;
1972 $checked { 'REDIRECT_GW_DEF1' }{ $cgiparams { 'REDIRECT_GW_DEF1' }} = 'CHECKED' ;
1973 $selected { 'ENGINES' }{ $cgiparams { 'ENGINES' }} = 'SELECTED' ;
1974 $checked { 'MSSFIX' }{ 'off' } = '' ;
1975 $checked { 'MSSFIX' }{ 'on' } = '' ;
1976 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
1977 $checked { 'PMTU_DISCOVERY' }{ $cgiparams { 'PMTU_DISCOVERY' }} = 'checked= \' checked \' ' ;
1978 $selected { 'LOG_VERB' }{ '1' } = '' ;
1979 $selected { 'LOG_VERB' }{ '2' } = '' ;
1980 $selected { 'LOG_VERB' }{ '3' } = '' ;
1981 $selected { 'LOG_VERB' }{ '4' } = '' ;
1982 $selected { 'LOG_VERB' }{ '5' } = '' ;
1983 $selected { 'LOG_VERB' }{ '6' } = '' ;
1984 $selected { 'LOG_VERB' }{ '7' } = '' ;
1985 $selected { 'LOG_VERB' }{ '8' } = '' ;
1986 $selected { 'LOG_VERB' }{ '9' } = '' ;
1987 $selected { 'LOG_VERB' }{ '10' } = '' ;
1988 $selected { 'LOG_VERB' }{ '11' } = '' ;
1989 $selected { 'LOG_VERB' }{ '0' } = '' ;
1990 $selected { 'LOG_VERB' }{ $cgiparams { 'LOG_VERB' }} = 'SELECTED' ;
1994 & Header
:: showhttpheaders
();
1995 & Header
:: openpage
( $Lang :: tr
{ 'status ovpn' }, 1 , '' );
1996 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
1997 if ( $errormessage ) {
1998 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
1999 print "<class name='base'> $errormessage \n " ;
2000 print " </class> \n " ;
2001 & Header
:: closebox
();
2003 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'advanced server' });
2005 <form method='post' enctype='multipart/form-data'>
2006 <table width='100%'>
2008 <td colspan='4'><b> $Lang ::tr{'dhcp-options'}</b></td>
2011 <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
2014 <td class='base'>Domain</td>
2015 <td><input type='TEXT' name='DHCP_DOMAIN' value=' $cgiparams {'DHCP_DOMAIN'}' size='30' /></td>
2018 <td class='base'>DNS</td>
2019 <td><input type='TEXT' name='DHCP_DNS' value=' $cgiparams {'DHCP_DNS'}' size='30' /></td>
2022 <td class='base'>WINS</td>
2023 <td><input type='TEXT' name='DHCP_WINS' value=' $cgiparams {'DHCP_WINS'}' size='30' /></td>
2026 <td colspan='4'><b> $Lang ::tr{'ovpn routes push options'}</b></td>
2029 <td class='base'> $Lang ::tr{'ovpn routes push'}</td>
2031 <textarea name='ROUTES_PUSH' cols='26' rows='6' wrap='off'>
2035 if ( $cgiparams { 'ROUTES_PUSH' } ne '' )
2037 print $cgiparams { 'ROUTES_PUSH' };
2046 <table width='100%'>
2048 <td class'base'><b> $Lang ::tr{'misc-options'}</b></td>
2051 <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='15%'></td><td width='35%'></td>
2054 <td class='base'>Client-To-Client</td>
2055 <td><input type='checkbox' name='CLIENT2CLIENT' $checked {'CLIENT2CLIENT'}{'on'} /></td>
2058 <td class='base'>Redirect-Gateway def1</td>
2059 <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked {'REDIRECT_GW_DEF1'}{'on'} /></td>
2062 <td class='base'>Max-Clients</td>
2063 <td><input type='text' name='MAX_CLIENTS' value=' $cgiparams {'MAX_CLIENTS'}' size='10' /></td>
2066 <td class='base'>Keppalive <br />
2067 (ping/ping-restart)</td>
2068 <td><input type='TEXT' name='KEEPALIVE_1' value=' $cgiparams {'KEEPALIVE_1'}' size='10' /></td>
2069 <td><input type='TEXT' name='KEEPALIVE_2' value=' $cgiparams {'KEEPALIVE_2'}' size='10' /></td>
2072 <td class='base'>fragment <br></td>
2073 <td><input type='TEXT' name='FRAGMENT' value=' $cgiparams {'FRAGMENT'}' size='10' /></td>
2074 <td>Default: <span class="base">1300</span></td>
2077 <td class='base'>mssfix</td>
2078 <td><input type='checkbox' name='MSSFIX' $checked {'MSSFIX'}{'on'} /></td>
2079 <td>Default: on</td>
2083 <td class='base'> $Lang ::tr{'ovpn mtu-disc'}</td>
2084 <td><input type='radio' name='PMTU_DISCOVERY' value='yes' $checked {'PMTU_DISCOVERY'}{'yes'} /> $Lang ::tr{'ovpn mtu-disc yes'}</td>
2085 <td><input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked {'PMTU_DISCOVERY'}{'maybe'} /> $Lang ::tr{'ovpn mtu-disc maybe'}</td>
2086 <td><input type='radio' name='PMTU_DISCOVERY' value='no' $checked {'PMTU_DISCOVERY'}{'no'} /> $Lang ::tr{'ovpn mtu-disc no'}</td>
2087 <td><input type='radio' name='PMTU_DISCOVERY' value='off' $checked {'PMTU_DISCOVERY'}{'off'} /> $Lang ::tr{'ovpn mtu-disc off'}</td>
2093 <table width='100%'>
2095 <td class'base'><b>Crypto-Engines</b></td>
2098 <td width='15%'></td> <td width='30%'> </td><td width='25%'> </td><td width='30%'></td>
2100 <tr><td class='base'>Engines:</td>
2101 <td><select name='ENGINES'><option value="none" $selected {'ENGINES'}{'none'}>none</option>
2102 <option value="cryptodev" $selected {'ENGINES'}{'cryptodev'}>cryptodev</option>
2103 <option value="padlock" $selected {'ENGINES'}{'padlock'}>padlock</option>
2109 <table width='100%'>
2111 <td class'base'><b> $Lang ::tr{'log-options'}</b></td>
2114 <td width='15%'></td> <td width='30%'> </td><td width='25%'> </td><td width='30%'></td>
2117 <tr><td class='base'>VERB</td>
2118 <td><select name='LOG_VERB'><option value='1' $selected {'LOG_VERB'}{'1'}>1</option>
2119 <option value='2' $selected {'LOG_VERB'}{'2'}>2</option>
2120 <option value='3' $selected {'LOG_VERB'}{'3'}>3</option>
2121 <option value='4' $selected {'LOG_VERB'}{'4'}>4</option>
2122 <option value='5' $selected {'LOG_VERB'}{'5'}>5</option>
2123 <option value='6' $selected {'LOG_VERB'}{'6'}>6</option>
2124 <option value='7' $selected {'LOG_VERB'}{'7'}>7</option>
2125 <option value='8' $selected {'LOG_VERB'}{'8'}>8</option>
2126 <option value='9' $selected {'LOG_VERB'}{'9'}>9</option>
2127 <option value='10' $selected {'LOG_VERB'}{'10'}>10</option>
2128 <option value='11' $selected {'LOG_VERB'}{'11'}>11</option>
2129 <option value='0' $selected {'LOG_VERB'}{'0'}>0</option></select></td>
2132 <table width='100%'>
2135 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save-adv-options'}' /></td>
2136 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'cancel-adv-options'}' /></td>
2144 & Header
:: closebox
();
2145 # print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
2146 & Header
:: closebigbox
();
2147 & Header
:: closepage
();
2151 ### Openvpn Connections Statistics
2153 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ovpn con stat' }) {
2154 & Header
:: showhttpheaders
();
2155 & Header
:: openpage
( $Lang :: tr
{ 'ovpn con stat' }, 1 , '' );
2156 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2157 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ovpn con stat' });
2160 # <td><b>$Lang::tr{'protocol'}</b></td>
2161 # protocol temp removed
2163 <table width='100%' border='0' cellpadding='2' cellspacing='0'>
2165 <td><b> $Lang ::tr{'common name'}</b></td>
2166 <td><b> $Lang ::tr{'real address'}</b></td>
2167 <td><b> $Lang ::tr{'virtual address'}</b></td>
2168 <td><b> $Lang ::tr{'loged in at'}</b></td>
2169 <td><b> $Lang ::tr{'bytes sent'}</b></td>
2170 <td><b> $Lang ::tr{'bytes received'}</b></td>
2171 <td><b> $Lang ::tr{'last activity'}</b></td>
2175 my $filename = "/var/log/ovpnserver.log" ;
2176 open ( FILE
, $filename ) or die 'Unable to open config file.' ;
2177 my @current = < FILE
>;
2186 my %userlookup = ();
2187 foreach my $line ( @current )
2190 if ( $line =~ /^Updated,(.+)/ ){
2191 @match = split ( /^Updated,(.+)/ , $line );
2192 $status = $match [ 1 ];
2195 if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ ) {
2196 @match = split ( m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ , $line );
2197 if ( $match [ 1 ] ne "Common Name" ) {
2199 $userlookup { $match [ 2 ]} = $uid ;
2200 $users [ $uid ]{ 'CommonName' } = $match [ 1 ];
2201 $users [ $uid ]{ 'RealAddress' } = $match [ 2 ];
2202 $users [ $uid ]{ 'BytesReceived' } = & sizeformat
( $match [ 3 ]);
2203 $users [ $uid ]{ 'BytesSent' } = & sizeformat
( $match [ 4 ]);
2204 $users [ $uid ]{ 'Since' } = $match [ 5 ];
2205 $users [ $uid ]{ 'Proto' } = $proto ;
2209 if ( $line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/ ) {
2210 @match = split ( m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/ , $line );
2211 if ( $match [ 1 ] ne "Virtual Address" ) {
2212 $address = $match [ 3 ];
2213 #find the uid in the lookup table
2214 $uid = $userlookup { $address };
2215 $users [ $uid ]{ 'VirtualAddress' } = $match [ 1 ];
2216 $users [ $uid ]{ 'LastRef' } = $match [ 4 ];
2222 for ( my $idx = 1 ; $idx <= $user2 ; $idx ++){
2224 print "<tr bgcolor=' $color {'color20'}'> \n " ;
2226 print "<tr bgcolor=' $color {'color22'}'> \n " ;
2228 print "<td align='left'> $users [ $idx -1]{'CommonName'}</td>" ;
2229 print "<td align='left'> $users [ $idx -1]{'RealAddress'}</td>" ;
2230 print "<td align='left'> $users [ $idx -1]{'VirtualAddress'}</td>" ;
2231 print "<td align='left'> $users [ $idx -1]{'Since'}</td>" ;
2232 print "<td align='left'> $users [ $idx -1]{'BytesSent'}</td>" ;
2233 print "<td align='left'> $users [ $idx -1]{'BytesReceived'}</td>" ;
2234 print "<td align='left'> $users [ $idx -1]{'LastRef'}</td>" ;
2235 # print "<td align='left'>$users[$idx-1]{'Proto'}</td>";
2241 <table width='100%' border='0' cellpadding='2' cellspacing='0'>
2246 <tr><td align='center' > $Lang ::tr{'the statistics were last updated at'} <b> $status </b></td></tr>
2250 & Header
:: closebox
();
2251 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2252 & Header
:: closebigbox
();
2253 & Header
:: closepage
();
2257 ### Download Certificate
2259 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
2260 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2262 if ( - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
2263 print "Content-Disposition: filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \r\n " ;
2264 print "Content-Type: application/octet-stream \r\n\r\n " ;
2265 print `/bin/cat ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
2270 ### Enable/Disable connection
2273 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
2275 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2276 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2278 if ( $confighash { $cgiparams { 'KEY' }}) {
2279 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
2280 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
2281 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2282 #&writeserverconf();
2283 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2284 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2285 # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
2288 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
2289 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2290 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2291 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
2293 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2294 #&writeserverconf();
2297 $errormessage = $Lang :: tr
{ 'invalid key' };
2301 ### Restart connection
2303 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
2304 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2305 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2307 if ( $confighash { $cgiparams { 'KEY' }}) {
2308 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2309 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2310 # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
2313 $errormessage = $Lang :: tr
{ 'invalid key' };
2317 ### Remove connection
2319 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
2320 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2321 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2323 if ( $confighash { $cgiparams { 'KEY' }}) {
2324 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2325 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2326 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
2328 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
2329 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
2330 delete $confighash { $cgiparams { 'KEY' }};
2331 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2332 #&writeserverconf();
2334 $errormessage = $Lang :: tr
{ 'invalid key' };
2339 ### Choose between adding a host-net or net-net connection
2346 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
2347 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2348 & Header
:: showhttpheaders
();
2349 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
2350 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2351 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'connection type' });
2353 if ( - s
"${General::swroot}/ovpn/settings" ) {
2356 <b> $Lang ::tr{'connection type'}:</b><br />
2357 <table><form method='post' ENCTYPE="multipart/form-data">
2358 <tr><td><input type='radio' name='TYPE' value='host' checked /></td>
2359 <td class='base'> $Lang ::tr{'host to net vpn'}</td></tr>
2360 <tr><td><input type='radio' name='TYPE' value='net' /></td>
2361 <td class='base'> $Lang ::tr{'net to net vpn'}</td></tr>
2362 <tr><td><input type='radio' name='TYPE' value='net2net' /></td>
2363 <td class='base'> $Lang ::tr{'net to net vpn'} (Upload Client Package)</td></tr>
2364 <tr><td> </td><td class='base'><input type='file' name='FH' size='30'></td></tr>
2365 <tr><td> </td><td>Import Connection Name <img src='/blob.gif' /></td></tr>
2366 <tr><td> </td><td class='base'><input type='text' name='n2nname' size='30'><td class='base'>Default : Client Packagename</td></td></tr>
2367 <tr><td colspan='3'><hr /></td></tr>
2368 <tr><td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td></tr>
2369 <tr><td> </td></tr>
2370 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
2377 <b> $Lang ::tr{'connection type'}:</b><br />
2378 <table><form method='post' ENCTYPE="multipart/form-data">
2379 <tr><td><input type='radio' name='TYPE' value='host' checked /></td> <td class='base'> $Lang ::tr{'host to net vpn'}</td></tr>
2380 <tr><td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td></tr>
2387 & Header
:: closebox
();
2388 & Header
:: closebigbox
();
2389 & Header
:: closepage
();
2396 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) && ( $cgiparams { 'TYPE' } eq 'net2net' )){
2400 my $uplconffilename = '' ;
2401 my $uplconffilename2 = '' ;
2402 my $uplp12name = '' ;
2403 my $uplp12name2 = '' ;
2410 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2412 # Check if a file is uploaded
2414 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
2415 $errormessage = $Lang :: tr
{ 'there was no file upload' };
2419 # Move uploaded IPfire n2n package to temporary file
2421 ( my $fh , my $filename ) = tempfile
( );
2422 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
2427 my $zip = Archive
:: Zip
-> new ();
2428 my $zipName = $filename ;
2429 my $status = $zip -> read ( $zipName );
2430 if ( $status != AZ_OK
) {
2431 $errormessage = "Read of $zipName failed \n " ;
2435 my $tempdir = tempdir
( CLEANUP
=> 1 );
2436 my @files = $zip -> memberNames ();
2438 $zip -> extractMemberWithoutPaths ( $_ , " $tempdir / $_ " );
2440 my $countfiles = @files ;
2442 # Check if we have not more then 2 files
2444 if ( $countfiles == 2 ){
2446 if ( $_ =~ /.conf$/ ){
2447 $uplconffilename = $_ ;
2449 if ( $_ =~ /.p12$/ ){
2453 if (( $uplconffilename eq '' ) || ( $uplp12name eq '' )){
2454 $errormessage = "Either no *.conf or no *.p12 file found \n " ;
2458 open ( FILE
, " $tempdir / $uplconffilename " ) or die 'Unable to open*.conf file' ;
2459 @firen2nconf = < FILE
>;
2461 chomp ( @firen2nconf );
2465 $errormessage = "Filecount does not match only 2 files are allowed \n " ;
2473 if ( $cgiparams { 'n2nname' } ne '' ){
2475 $uplconffilename2 = " $cgiparams {'n2nname'}.conf" ;
2476 $uplp12name2 = " $cgiparams {'n2nname'}.p12" ;
2477 $n2nname [ 0 ] = $cgiparams { 'n2nname' };
2478 my @n2nname2 = split ( /\./ , $uplconffilename );
2479 $n2nname2 [ 0 ] =~ s/\n|\r//g ;
2480 my $input1 = "${General::swroot}/ovpn/certs/ $uplp12name " ;
2481 my $output1 = "${General::swroot}/ovpn/certs/ $uplp12name2 " ;
2482 my $input2 = " $n2nname2 [0]n2n" ;
2483 my $output2 = " $n2nname [0]n2n" ;
2484 my $filename = " $tempdir / $uplconffilename " ;
2485 open ( FILE
, "< $filename " ) or die 'Unable to open config file.' ;
2486 my @current = < FILE
>;
2488 foreach ( @current ) { s/$input1/$output1/g ;}
2489 foreach ( @current ) { s/$input2/$output2/g ;}
2490 open ( OUT
, "> $filename " ) || die 'Unable to open config file.' ;
2495 $uplconffilename2 = $uplconffilename ;
2496 $uplp12name2 = $uplp12name ;
2497 @n2nname = split ( /\./ , $uplconffilename );
2498 $n2nname [ 0 ] =~ s/\n|\r//g ;
2500 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
2501 unless (- d
"${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" , 0770 or die "Unable to create dir $!" ;}
2503 move
( " $tempdir / $uplconffilename " , "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $uplconffilename2 " );
2506 $errormessage = "*.conf move failed: $!" ;
2511 move
( " $tempdir / $uplp12name " , "${General::swroot}/ovpn/certs/ $uplp12name2 " );
2512 chmod 0600 , "${General::swroot}/ovpn/certs/ $uplp12name " ;
2515 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
2523 my @n2nmtudisc = split ( / / , ( grep { /^mtu-disc/ } @firen2nconf )[ 0 ]);;
2524 my @n2nproto2 = split ( / / , ( grep { /^proto/ } @firen2nconf )[ 0 ]);
2525 my @n2nproto = split ( /-/ , $n2nproto2 [ 1 ]);
2526 my @n2nport = split ( / / , ( grep { /^port/ } @firen2nconf )[ 0 ]);
2527 my @n2ntunmtu = split ( / / , ( grep { /^tun-mtu/ } @firen2nconf )[ 0 ]);
2528 my @n2ncomplzo = grep { /^comp-lzo/ } @firen2nconf ;
2529 if ( $n2ncomplzo [ 0 ] =~ /comp-lzo/ ){ $complzoactive = "on" ;} else { $complzoactive = "off" ;}
2530 my @n2nmssfix = grep { /^mssfix/ } @firen2nconf ;
2531 if ( $n2nmssfix [ 0 ] =~ /mssfix/ ){ $mssfixactive = "on" ;} else { $mssfixactive = "off" ;}
2532 #my @n2nmssfix = split(/ /, (grep { /^mssfix/ } @firen2nconf)[0]);
2533 my @n2nfragment = split ( / / , ( grep { /^fragment/ } @firen2nconf )[ 0 ]);
2534 my @n2nremote = split ( / / , ( grep { /^remote/ } @firen2nconf )[ 0 ]);
2535 my @n2novpnsuball = split ( / / , ( grep { /^ifconfig/ } @firen2nconf )[ 0 ]);
2536 my @n2novpnsub = split ( /\./ , $n2novpnsuball [ 1 ]);
2537 my @n2nremsub = split ( / / , ( grep { /^route/ } @firen2nconf )[ 0 ]);
2538 my @n2nmgmt = split ( / / , ( grep { /^management/ } @firen2nconf )[ 0 ]);
2539 my @n2nlocalsub = split ( / / , ( grep { /^# remsub/ } @firen2nconf )[ 0 ]);
2543 # m.a.d delete CR and LF from arrays for this chomp doesnt work
2546 $n2nremote [ 1 ] =~ s/\n|\r//g ;
2547 $n2novpnsub [ 0 ] =~ s/\n|\r//g ;
2548 $n2novpnsub [ 1 ] =~ s/\n|\r//g ;
2549 $n2novpnsub [ 2 ] =~ s/\n|\r//g ;
2550 $n2nproto [ 0 ] =~ s/\n|\r//g ;
2551 $n2nport [ 1 ] =~ s/\n|\r//g ;
2552 $n2ntunmtu [ 1 ] =~ s/\n|\r//g ;
2553 $n2nremsub [ 1 ] =~ s/\n|\r//g ;
2554 $n2nremsub [ 2 ] =~ s/\n|\r//g ;
2555 $n2nlocalsub [ 2 ] =~ s/\n|\r//g ;
2556 $n2nfragment [ 1 ] =~ s/\n|\r//g ;
2557 $n2nmgmt [ 2 ] =~ s/\n|\r//g ;
2558 $n2nmtudisc [ 1 ] =~ s/\n|\r//g ;
2559 chomp ( $complzoactive );
2560 chomp ( $mssfixactive );
2567 # Check if there is no other entry with this name
2570 foreach my $dkey ( keys %confighash ) {
2571 if ( $confighash { $dkey }[ 1 ] eq $n2nname [ 0 ]) {
2572 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
2573 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
2574 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
2575 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
2581 # Check if OpenVPN Subnet is valid
2584 foreach my $dkey ( keys %confighash ) {
2585 if ( $confighash { $dkey }[ 27 ] eq " $n2novpnsub [0]. $n2novpnsub [1]. $n2novpnsub [2].0/255.255.255.0" ) {
2586 $errormessage = 'The OpenVPN Subnet is already in use' ;
2587 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
2588 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
2589 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
2595 # Check im Dest Port is vaild
2598 foreach my $dkey ( keys %confighash ) {
2599 if ( $confighash { $dkey }[ 29 ] eq $n2nport [ 1 ] ) {
2600 $errormessage = 'The OpenVPN Port is already in use' ;
2601 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
2602 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
2603 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
2610 $key = & General
:: findhasharraykey
( \
%confighash );
2612 foreach my $i ( 0 .. 32 ) { $confighash { $key }[ $i ] = "" ;}
2613 $confighash { $key }[ 0 ] = 'off' ;
2614 $confighash { $key }[ 1 ] = $n2nname [ 0 ];
2615 $confighash { $key }[ 2 ] = $n2nname [ 0 ];
2616 $confighash { $key }[ 3 ] = 'net' ;
2617 $confighash { $key }[ 4 ] = 'cert' ;
2618 $confighash { $key }[ 6 ] = 'client' ;
2619 $confighash { $key }[ 8 ] = $n2nlocalsub [ 2 ];
2620 $confighash { $key }[ 10 ] = $n2nremote [ 1 ];
2621 $confighash { $key }[ 11 ] = " $n2nremsub [1]/ $n2nremsub [2]" ;
2622 $confighash { $key }[ 22 ] = $n2nmgmt [ 2 ];
2623 $confighash { $key }[ 23 ] = $mssfixactive ;
2624 $confighash { $key }[ 24 ] = $n2nfragment [ 1 ];
2625 $confighash { $key }[ 25 ] = 'IPFire n2n Client' ;
2626 $confighash { $key }[ 26 ] = 'red' ;
2627 $confighash { $key }[ 27 ] = " $n2novpnsub [0]. $n2novpnsub [1]. $n2novpnsub [2].0/255.255.255.0" ;
2628 $confighash { $key }[ 28 ] = $n2nproto [ 0 ];
2629 $confighash { $key }[ 29 ] = $n2nport [ 1 ];
2630 $confighash { $key }[ 30 ] = $complzoactive ;
2631 $confighash { $key }[ 31 ] = $n2ntunmtu [ 1 ];
2632 $confighash { $key }[ 32 ] = $n2nmtudisc [ 1 ];
2635 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2639 & Header
:: showhttpheaders
();
2640 & Header
:: openpage
( 'Validate imported configuration' , 1 , '' );
2641 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
2642 if ( $errormessage ) {
2643 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
2644 print "<class name='base'> $errormessage " ;
2645 print " </class>" ;
2646 & Header
:: closebox
();
2650 & Header
:: openbox
( '100%' , 'LEFT' , 'import ipfire net2net config' );
2652 if ( $errormessage eq '' ){
2654 <!-- ipfire net2net config gui -->
2655 <table width='100%'>
2656 <tr><td width='25%'> </td><td width='25%'> </td></tr>
2657 <tr><td class='boldbase'> $Lang ::tr{'name'}:</td><td><b> $n2nname [0]</b></td></tr>
2658 <tr><td> </td><td> </td></tr>
2659 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'Act as'}</td><td><b> $confighash { $key }[6]</b></td></tr>
2660 <tr><td class='boldbase' nowrap='nowrap'>Remote Host </td><td><b> $confighash { $key }[10]</b></td></tr>
2661 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'}</td><td><b> $confighash { $key }[8]</b></td></tr>
2662 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'}</td><td><b> $confighash { $key }[11]</b></td></tr>
2663 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn subnet'}</td><td><b> $confighash { $key }[27]</b></td></tr>
2664 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td><td><b> $confighash { $key }[28]</b></td></tr>
2665 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'destination port'}:</td><td><b> $confighash { $key }[29]</b></td></tr>
2666 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'}</td><td><b> $confighash { $key }[30]</b></td></tr>
2667 <tr><td class='boldbase' nowrap='nowrap'>MSSFIX </td><td><b> $confighash { $key }[23]</b></td></tr>
2668 <tr><td class='boldbase' nowrap='nowrap'>Fragment </td><td><b> $confighash { $key }[24]</b></td></tr>
2669 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'}</td><td><b> $confighash { $key }[31]</b></td></tr>
2670 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn mtu-disc'}</td><td><b> $confighash { $key }[32]</b></td></tr>
2671 <tr><td class='boldbase' nowrap='nowrap'>Management Port </td><td><b> $confighash { $key }[22]</b></td></tr>
2672 <tr><td> </td><td> </td></tr>
2676 & Header
:: closebox
();
2679 if ( $errormessage ) {
2680 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2682 print "<div align='center'><form method='post' ENCTYPE='multipart/form-data'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />" ;
2683 print "<input type='hidden' name='TYPE' value='net2netakn' />" ;
2684 print "<input type='hidden' name='KEY' value=' $key ' />" ;
2685 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
2687 & Header
:: closebigbox
();
2688 & Header
:: closepage
();
2693 ### Accept IPFire n2n Package Settings
2696 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) && ( $cgiparams { 'TYPE' } eq 'net2netakn' )){
2699 ### Discard and Rollback IPFire n2n Package Settings
2702 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'cancel' }) && ( $cgiparams { 'TYPE' } eq 'net2netakn' )){
2704 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2706 if ( $confighash { $cgiparams { 'KEY' }}) {
2708 my $conffile = glob ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]/ $confighash { $cgiparams {'KEY'}}[1].conf" );
2709 my $certfile = glob ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
2710 unlink ( $certfile ) or die "Removing $certfile fail: $!" ;
2711 unlink ( $conffile ) or die "Removing $conffile fail: $!" ;
2712 rmdir ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]" ) || die "Kann Verzeichnis nicht loeschen: $!" ;
2713 delete $confighash { $cgiparams { 'KEY' }};
2714 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2717 $errormessage = $Lang :: tr
{ 'invalid key' };
2727 ### Adding a new connection
2729 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
2730 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
2731 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
2733 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2734 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
2735 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2737 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
2738 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
2739 $errormessage = $Lang :: tr
{ 'invalid key' };
2742 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
2743 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
2744 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
2745 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
2746 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
2747 $cgiparams { 'SIDE' } = $confighash { $cgiparams { 'KEY' }}[ 6 ];
2748 $cgiparams { 'LOCAL_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 8 ];
2749 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
2750 $cgiparams { 'REMOTE_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 11 ];
2751 # n2n m.a.d new fields
2752 $cgiparams { 'OVPN_MGMT' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
2753 $cgiparams { 'MSSFIX' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
2754 $cgiparams { 'FRAGMENT' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
2755 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
2756 $cgiparams { 'INTERFACE' } = $confighash { $cgiparams { 'KEY' }}[ 26 ];
2758 $cgiparams { 'OVPN_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
2759 $cgiparams { 'PROTOCOL' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
2760 $cgiparams { 'DEST_PORT' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
2761 $cgiparams { 'COMPLZO' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
2762 $cgiparams { 'MTU' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
2763 $cgiparams { 'PMTU_DISCOVERY' } = $confighash { $cgiparams { 'KEY' }}[ 32 ];
2766 #ab hiere error uebernehmen
2768 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
2769 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
2771 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
2772 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
2773 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2774 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2775 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2781 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
2782 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
2783 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2784 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2785 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2790 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
2791 $errormessage = $Lang :: tr
{ 'name is invalid' };
2792 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2793 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2794 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2799 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
2800 $errormessage = $Lang :: tr
{ 'name too long' };
2801 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2802 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2803 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2812 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2814 if ( $cgiparams { 'DEST_PORT' } eq $vpnsettings { 'DDEST_PORT' }) {
2815 $errormessage = $Lang :: tr
{ 'openvpn destination port used' };
2816 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2817 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2821 if ( $cgiparams { 'DEST_PORT' } eq '' ) {
2822 $errormessage = $Lang :: tr
{ 'openvpn destination port used' };
2823 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2824 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2828 if ( $cgiparams { 'OVPN_SUBNET' } eq $vpnsettings { 'DOVPN_SUBNET' }) {
2829 $errormessage = $Lang :: tr
{ 'openvpn subnet is used' };
2830 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2831 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2835 if (( $cgiparams { 'PROTOCOL' } eq 'tcp' ) && ( $cgiparams { 'MSSFIX' } eq 'on' )) {
2836 $errormessage = $Lang :: tr
{ 'openvpn mssfix allowed with udp' };
2837 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2838 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2842 if (( $cgiparams { 'PROTOCOL' } eq 'tcp' ) && ( $cgiparams { 'FRAGMENT' } ne '' )) {
2843 $errormessage = $Lang :: tr
{ 'openvpn fragment allowed with udp' };
2844 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2845 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2849 if (( $cgiparams { 'PMTU_DISCOVERY' } ne 'off' ) && ( $cgiparams { 'MTU' } ne '1500' )) {
2850 $errormessage = $Lang :: tr
{ 'ovpn mtu-disc and mtu not 1500' };
2851 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2852 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2856 if ( $cgiparams { 'PMTU_DISCOVERY' } ne 'off' ) {
2857 if (( $cgiparams { 'FRAGMENT' } ne '' ) || ( $cgiparams { 'MSSFIX' } eq 'on' )) {
2858 $errormessage = $Lang :: tr
{ 'ovpn mtu-disc with mssfix or fragment' };
2859 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2860 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2865 if ( & validdotmask
( $cgiparams { 'LOCAL_SUBNET' })) {
2866 $errormessage = $Lang :: tr
{ 'openvpn prefix local subnet' };
2867 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2868 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2872 if ( & validdotmask
( $cgiparams { 'OVPN_SUBNET' })) {
2873 $errormessage = $Lang :: tr
{ 'openvpn prefix openvpn subnet' };
2874 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2875 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2879 if ( & validdotmask
( $cgiparams { 'REMOTE_SUBNET' })) {
2880 $errormessage = $Lang :: tr
{ 'openvpn prefix remote subnet' };
2881 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2882 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2886 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) {
2887 $cgiparams { 'OVPN_MGMT' } = $cgiparams { 'DEST_PORT' };
2892 # if (($cgiparams{'TYPE'} eq 'net') && ($cgiparams{'SIDE'} !~ /^(left|right)$/)) {
2893 # $errormessage = $Lang::tr{'ipfire side is invalid'};
2894 # goto VPNCONF_ERROR;
2897 # Check if there is no other entry with this name
2898 if (! $cgiparams { 'KEY' }) {
2899 foreach my $key ( keys %confighash ) {
2900 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
2901 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
2902 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2903 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2904 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2911 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! $cgiparams { 'REMOTE' })) {
2912 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
2913 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2914 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2915 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2920 if ( $cgiparams { 'REMOTE' }) {
2921 if (! & General
:: validip
( $cgiparams { 'REMOTE' })) {
2922 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
2923 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
2924 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2925 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2926 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2930 if (& valid_dns_host
( $cgiparams { 'REMOTE' })) {
2931 $warnmessage = " $Lang ::tr{'check vpn lr'} $cgiparams {'REMOTE'}. $Lang ::tr{'dns check failed'}" ;
2932 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2939 if ( $cgiparams { 'TYPE' } ne 'host' ) {
2940 unless (& General
:: validipandmask
( $cgiparams { 'LOCAL_SUBNET' })) {
2941 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
2942 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2943 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2944 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2946 goto VPNCONF_ERROR
;}
2948 # Check if there is no other entry without IP-address and PSK
2949 if ( $cgiparams { 'REMOTE' } eq '' ) {
2950 foreach my $key ( keys %confighash ) {
2951 if (( $cgiparams { 'KEY' } ne $key ) &&
2952 ( $confighash { $key }[ 4 ] eq 'psk' || $cgiparams { 'AUTH' } eq 'psk' ) &&
2953 $confighash { $key }[ 10 ] eq '' ) {
2954 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
2959 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! & General
:: validipandmask
( $cgiparams { 'REMOTE_SUBNET' }))) {
2960 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
2961 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2962 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2966 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
2967 $errormessage = $Lang :: tr
{ 'invalid input' };
2970 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
2971 $errormessage = $Lang :: tr
{ 'invalid input' };
2976 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
2977 # if (! length($cgiparams{'PSK'}) ) {
2978 # $errormessage = $Lang::tr{'pre-shared key is too short'};
2979 # goto VPNCONF_ERROR;
2981 # if ($cgiparams{'PSK'} =~ /['",&]/) {
2982 # $errormessage = $Lang::tr{'invalid characters found in pre-shared key'};
2983 # goto VPNCONF_ERROR;
2985 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
2986 if ( $cgiparams { 'KEY' }) {
2987 $errormessage = $Lang :: tr
{ 'cant change certificates' };
2990 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
2991 $errormessage = $Lang :: tr
{ 'there was no file upload' };
2995 # Move uploaded certificate request to a temporary file
2996 ( my $fh , my $filename ) = tempfile
( );
2997 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
3002 # Sign the certificate request and move it
3003 # Sign the host certificate request
3004 system ( '/usr/bin/openssl' , 'ca' , '-days' , " $cgiparams {'DAYS_VALID'}" ,
3005 '-batch' , '-notext' ,
3007 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
3008 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
3010 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
3012 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3013 & newcleanssldatabase
();
3017 & deletebackupcert
();
3020 my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem` ;
3021 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
3023 $temp =~ s
+/ Email
+, E
+;
3024 $temp =~ s/ ST=/ S=/ ;
3025 $cgiparams { 'CERT_NAME' } = $temp ;
3026 $cgiparams { 'CERT_NAME' } =~ s/,//g ;
3027 $cgiparams { 'CERT_NAME' } =~ s/\'//g ;
3028 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
3029 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
3032 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
3033 if ( $cgiparams { 'KEY' }) {
3034 $errormessage = $Lang :: tr
{ 'cant change certificates' };
3037 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
3038 $errormessage = $Lang :: tr
{ 'there was no file upload' };
3041 # Move uploaded certificate to a temporary file
3042 ( my $fh , my $filename ) = tempfile
( );
3043 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
3048 # Verify the certificate has a valid CA and move it
3050 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/cacert.pem $filename ` ;
3051 if ( $test =~ /: OK/ ) {
3054 foreach my $key ( keys %cahash ) {
3055 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/ $cahash { $key }[0]cert.pem $filename ` ;
3056 if ( $test =~ /: OK/ ) {
3062 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
3066 move
( $filename , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3068 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
3074 my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem` ;
3075 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
3077 $temp =~ s
+/ Email
+, E
+;
3078 $temp =~ s/ ST=/ S=/ ;
3079 $cgiparams { 'CERT_NAME' } = $temp ;
3080 $cgiparams { 'CERT_NAME' } =~ s/,//g ;
3081 $cgiparams { 'CERT_NAME' } =~ s/\'//g ;
3082 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
3083 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3084 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
3087 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
3088 if ( $cgiparams { 'KEY' }) {
3089 $errormessage = $Lang :: tr
{ 'cant change certificates' };
3092 # Validate input since the form was submitted
3093 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
3094 $errormessage = $Lang :: tr
{ 'name too long' };
3097 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
3098 $errormessage = $Lang :: tr
{ 'invalid input for name' };
3101 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
3102 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
3105 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
3106 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
3109 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
3110 $errormessage = $Lang :: tr
{ 'invalid input for department' };
3113 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
3114 $errormessage = $Lang :: tr
{ 'organization too long' };
3117 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
3118 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
3121 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
3122 $errormessage = $Lang :: tr
{ 'invalid input for city' };
3125 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
3126 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
3129 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
3130 $errormessage = $Lang :: tr
{ 'invalid input for country' };
3133 if ( $cgiparams { 'CERT_PASS1' } ne '' && $cgiparams { 'CERT_PASS2' } ne '' ){
3134 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
3135 $errormessage = $Lang :: tr
{ 'password too short' };
3139 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
3140 $errormessage = $Lang :: tr
{ 'passwords do not match' };
3144 # Replace empty strings with a .
3145 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
3146 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
3147 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
3149 # Create the Host certificate request client
3150 my $pid = open ( OPENSSL
, "|-" );
3151 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto VPNCONF_ERROR
;};
3152 if ( $pid ) { # parent
3153 print OPENSSL
" $cgiparams {'CERT_COUNTRY'} \n " ;
3154 print OPENSSL
" $state \n " ;
3155 print OPENSSL
" $city \n " ;
3156 print OPENSSL
" $cgiparams {'CERT_ORGANIZATION'} \n " ;
3157 print OPENSSL
" $ou \n " ;
3158 print OPENSSL
" $cgiparams {'CERT_NAME'} \n " ;
3159 print OPENSSL
" $cgiparams {'CERT_EMAIL'} \n " ;
3160 print OPENSSL
". \n " ;
3161 print OPENSSL
". \n " ;
3164 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
3165 unlink ( "${General::swroot}ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3166 unlink ( "${General::swroot}ovpn/certs/ $cgiparams {'NAME'}req.pem" );
3170 unless ( exec ( '/usr/bin/openssl' , 'req' , '-nodes' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
3171 '-newkey' , 'rsa:1024' ,
3172 '-keyout' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" ,
3173 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" ,
3174 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
3175 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
3176 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3177 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
3182 # Sign the host certificate request
3183 system ( '/usr/bin/openssl' , 'ca' , '-days' , " $cgiparams {'DAYS_VALID'}" ,
3184 '-batch' , '-notext' ,
3185 '-in' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" ,
3186 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
3187 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
3189 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
3190 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3191 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
3192 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3193 & newcleanssldatabase
();
3196 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
3197 & deletebackupcert
();
3200 # Create the pkcs12 file
3201 system ( '/usr/bin/openssl' , 'pkcs12' , '-export' ,
3202 '-inkey' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" ,
3203 '-in' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
3204 '-name' , $cgiparams { 'NAME' },
3205 '-passout' , "pass: $cgiparams {'CERT_PASS1'}" ,
3206 '-certfile' , "${General::swroot}/ovpn/ca/cacert.pem" ,
3207 '-caname' , " $vpnsettings {'ROOTCERT_ORGANIZATION'} CA" ,
3208 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12" );
3210 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
3211 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3212 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3213 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12" );
3216 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3218 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
3219 ; # Nothing, just editing
3221 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
3225 # Check if there is no other entry with this common name
3226 if ((! $cgiparams { 'KEY' }) && ( $cgiparams { 'AUTH' } ne 'psk' )) {
3227 foreach my $key ( keys %confighash ) {
3228 if ( $confighash { $key }[ 2 ] eq $cgiparams { 'CERT_NAME' }) {
3229 $errormessage = $Lang :: tr
{ 'a connection with this common name already exists' };
3236 my $key = $cgiparams { 'KEY' };
3238 $key = & General
:: findhasharraykey
( \
%confighash );
3239 foreach my $i ( 0 .. 31 ) { $confighash { $key }[ $i ] = "" ;}
3241 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
3242 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
3243 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
3244 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
3246 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
3247 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
3248 $confighash { $key }[ 4 ] = 'psk' ;
3249 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
3251 $confighash { $key }[ 4 ] = 'cert' ;
3253 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3254 $confighash { $key }[ 6 ] = $cgiparams { 'SIDE' };
3255 $confighash { $key }[ 11 ] = $cgiparams { 'REMOTE_SUBNET' };
3257 $confighash { $key }[ 8 ] = $cgiparams { 'LOCAL_SUBNET' };
3258 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
3259 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) {
3260 $confighash { $key }[ 22 ] = $confighash { $key }[ 29 ];
3262 $confighash { $key }[ 22 ] = $cgiparams { 'OVPN_MGMT' };
3264 $confighash { $key }[ 23 ] = $cgiparams { 'MSSFIX' };
3265 $confighash { $key }[ 24 ] = $cgiparams { 'FRAGMENT' };
3266 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
3267 $confighash { $key }[ 26 ] = $cgiparams { 'INTERFACE' };
3269 $confighash { $key }[ 27 ] = $cgiparams { 'OVPN_SUBNET' };
3270 $confighash { $key }[ 28 ] = $cgiparams { 'PROTOCOL' };
3271 $confighash { $key }[ 29 ] = $cgiparams { 'DEST_PORT' };
3272 $confighash { $key }[ 30 ] = $cgiparams { 'COMPLZO' };
3273 $confighash { $key }[ 31 ] = $cgiparams { 'MTU' };
3274 $confighash { $key }[ 32 ] = $cgiparams { 'PMTU_DISCOVERY' };
3276 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3282 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3284 if (- e
"/var/run/ $confighash { $key }[1]n2n.pid" ) {
3285 system ( '/usr/local/bin/openvpnctrl' , '-kn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
3287 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3288 my $key = $cgiparams { 'KEY' };
3290 $key = & General
:: findhasharraykey
( \
%confighash );
3291 foreach my $i ( 0 .. 31 ) { $confighash { $key }[ $i ] = "" ;}
3293 $confighash { $key }[ 0 ] = 'on' ;
3294 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3296 system ( '/usr/local/bin/openvpnctrl' , '-sn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
3304 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
3305 $cgiparams { 'KEY' } = $key ;
3306 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
3310 $cgiparams { 'ENABLED' } = 'on' ;
3314 $cgiparams { 'MSSFIX' } = 'on' ;
3315 $cgiparams { 'FRAGMENT' } = '1300' ;
3319 $cgiparams { 'SIDE' } = 'left' ;
3320 if ( ! - f
"${General::swroot}/ovpn/ca/cakey.pem" ) {
3321 $cgiparams { 'AUTH' } = 'psk' ;
3322 } elsif ( ! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
3323 $cgiparams { 'AUTH' } = 'certfile' ;
3325 $cgiparams { 'AUTH' } = 'certgen' ;
3327 $cgiparams { 'LOCAL_SUBNET' } = " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" ;
3328 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
3329 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
3330 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
3331 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
3335 $checked { 'ENABLED' }{ 'off' } = '' ;
3336 $checked { 'ENABLED' }{ 'on' } = '' ;
3337 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = 'CHECKED' ;
3338 $checked { 'ENABLED_BLUE' }{ 'off' } = '' ;
3339 $checked { 'ENABLED_BLUE' }{ 'on' } = '' ;
3340 $checked { 'ENABLED_BLUE' }{ $cgiparams { 'ENABLED_BLUE' }} = 'CHECKED' ;
3341 $checked { 'ENABLED_ORANGE' }{ 'off' } = '' ;
3342 $checked { 'ENABLED_ORANGE' }{ 'on' } = '' ;
3343 $checked { 'ENABLED_ORANGE' }{ $cgiparams { 'ENABLED_ORANGE' }} = 'CHECKED' ;
3346 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
3347 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
3348 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = 'CHECKED' ;
3350 $selected { 'SIDE' }{ 'server' } = '' ;
3351 $selected { 'SIDE' }{ 'client' } = '' ;
3352 $selected { 'SIDE' }{ $cgiparams { 'SIDE' }} = 'SELECTED' ;
3354 $selected { 'PROTOCOL' }{ 'udp' } = '' ;
3355 $selected { 'PROTOCOL' }{ 'tcp' } = '' ;
3356 $selected { 'PROTOCOL' }{ $cgiparams { 'PROTOCOL' }} = 'SELECTED' ;
3359 $checked { 'AUTH' }{ 'psk' } = '' ;
3360 $checked { 'AUTH' }{ 'certreq' } = '' ;
3361 $checked { 'AUTH' }{ 'certgen' } = '' ;
3362 $checked { 'AUTH' }{ 'certfile' } = '' ;
3363 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = 'CHECKED' ;
3365 $selected { 'INTERFACE' }{ $cgiparams { 'INTERFACE' }} = 'SELECTED' ;
3367 $checked { 'COMPLZO' }{ 'off' } = '' ;
3368 $checked { 'COMPLZO' }{ 'on' } = '' ;
3369 $checked { 'COMPLZO' }{ $cgiparams { 'COMPLZO' }} = 'CHECKED' ;
3371 $checked { 'MSSFIX' }{ 'off' } = '' ;
3372 $checked { 'MSSFIX' }{ 'on' } = '' ;
3373 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
3375 $checked { 'PMTU_DISCOVERY' }{ $cgiparams { 'PMTU_DISCOVERY' }} = 'checked= \' checked \' ' ;
3379 & Header
:: showhttpheaders
();
3380 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
3381 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
3382 if ( $errormessage ) {
3383 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
3384 print "<class name='base'> $errormessage " ;
3385 print " </class>" ;
3386 & Header
:: closebox
();
3390 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'warning messages'}:" );
3391 print "<class name='base'> $warnmessage " ;
3392 print " </class>" ;
3393 & Header
:: closebox
();
3396 print "<form method='post' enctype='multipart/form-data'>" ;
3397 print "<input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />" ;
3399 if ( $cgiparams { 'KEY' }) {
3400 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
3401 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
3404 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'connection'}:" );
3405 print "<table width='100%'> \n " ;
3406 print "<tr><td width='25%' class='boldbase'> $Lang ::tr{'name'}:</td>" ;
3407 if ( $cgiparams { 'TYPE' } eq 'host' ) {
3408 if ( $cgiparams { 'KEY' }) {
3409 print "<td width='35%' class='base'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /> $cgiparams {'NAME'}</td> \n " ;
3411 print "<td width='35%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' maxlength='20' size='30' /></td>" ;
3413 # print "<tr><td>$Lang::tr{'interface'}</td>";
3414 # print "<td><select name='INTERFACE'>";
3415 # print "<option value='RED' $selected{'INTERFACE'}{'RED'}>RED</option>";
3416 # if ($netsettings{'BLUE_DEV'} ne '') {
3417 # print "<option value='BLUE' $selected{'INTERFACE'}{'BLUE'}>BLUE</option>";
3419 # print "<option value='GREEN' $selected{'INTERFACE'}{'GREEN'}>GREEN</option>";
3420 # print "<option value='ORANGE' $selected{'INTERFACE'}{'ORANGE'}>ORANGE</option>";
3421 # print "</select></td></tr>";
3424 print "<input type='hidden' name='INTERFACE' value='red' />" ;
3425 if ( $cgiparams { 'KEY' }) {
3426 print "<td width='25%' class='base' nowrap='nowrap'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /> $cgiparams {'NAME'}</td>" ;
3428 print "<td width='25%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' maxlength='20' /></td>" ;
3431 <td width='25%'> </td>
3432 <td width='25%'> </td></tr>
3433 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'Act as'}</td>
3434 <td><select name='SIDE'><option value='server' $selected {'SIDE'}{'server'}> $Lang ::tr{'openvpn server'}</option>
3435 <option value='client' $selected {'SIDE'}{'client'}> $Lang ::tr{'openvpn client'}</option></select></td>
3436 <td class='boldbase'> $Lang ::tr{'remote host/ip'}:</td>
3437 <td><input type='TEXT' name='REMOTE' value=' $cgiparams {'REMOTE'}' /></td></tr>
3438 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'}</td>
3439 <td><input type='TEXT' name='LOCAL_SUBNET' value=' $cgiparams {'LOCAL_SUBNET'}' /></td>
3440 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'}</td>
3441 <td><input type='text' name='REMOTE_SUBNET' value=' $cgiparams {'REMOTE_SUBNET'}' /></td></tr>
3442 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn subnet'}</td>
3443 <td><input type='TEXT' name='OVPN_SUBNET' value=' $cgiparams {'OVPN_SUBNET'}' /></td></tr>
3444 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td>
3446 <td><select name='PROTOCOL'><option value='udp' $selected {'PROTOCOL'}{'udp'}>UDP</option>
3447 <option value='tcp' $selected {'PROTOCOL'}{'tcp'}>TCP</option></select></td>
3449 <td class='boldbase'> $Lang ::tr{'destination port'}:</td>
3450 <td><input type='TEXT' name='DEST_PORT' value=' $cgiparams {'DEST_PORT'}' size='5' /></td></tr>
3451 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'} <img src='/blob.gif'</td>
3452 <td><input type='checkbox' name='COMPLZO' $checked {'COMPLZO'}{'on'} /></td>
3454 <tr><td class='boldbase' nowrap='nowrap'>mssfix <img src='/blob.gif' /></td>
3455 <td><input type='checkbox' name='MSSFIX' $checked {'MSSFIX'}{'on'} /></td>
3456 <td> $Lang ::tr{'openvpn default'}: <span class="base">on</span></td>
3458 <tr><td class='boldbase' nowrap='nowrap'>fragment <img src='/blob.gif' /></td>
3459 <td><input type='TEXT' name='FRAGMENT' VALUE=' $cgiparams {'FRAGMENT'}'size='5' /></td>
3460 <td> $Lang ::tr{'openvpn default'}: <span class="base">1300</span></td>
3462 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'} <img src='/blob.gif' /></td>
3463 <td> <input type='TEXT' name='MTU' VALUE=' $cgiparams {'MTU'}'size='5' /></td>
3464 <td colspan='2'> $Lang ::tr{'openvpn default'}: udp/tcp <span class="base">1500/1400</span></td>
3466 <tr><td class='boldbase' nowrap='nowrap'>Management Port <img src='/blob.gif' /></td>
3467 <td> <input type='TEXT' name='OVPN_MGMT' VALUE=' $cgiparams {'OVPN_MGMT'}'size='5' /></td>
3468 <td colspan='2'> $Lang ::tr{'openvpn default'}: <span class="base"> $Lang ::tr{'destination port'}</span></td>
3471 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn mtu-disc'}</td>
3473 <input type='radio' name='PMTU_DISCOVERY' value='yes' $checked {'PMTU_DISCOVERY'}{'yes'} /> $Lang ::tr{'ovpn mtu-disc yes'}
3474 <input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked {'PMTU_DISCOVERY'}{'maybe'} /> $Lang ::tr{'ovpn mtu-disc maybe'}
3475 <input type='radio' name='PMTU_DISCOVERY' value='no' $checked {'PMTU_DISCOVERY'}{'no'} /> $Lang ::tr{'ovpn mtu-disc no'}
3476 <input type='radio' name='PMTU_DISCOVERY' value='off' $checked {'PMTU_DISCOVERY'}{'off'} /> $Lang ::tr{'ovpn mtu-disc off'}
3484 print "<tr><td class='boldbase'> $Lang ::tr{'remark title'} <img src='/blob.gif' /></td>" ;
3485 print "<td colspan='3'><input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' size='55' maxlength='50' /></td></tr>" ;
3487 if ( $cgiparams { 'TYPE' } eq 'host' ) {
3489 print "<tr><td> $Lang ::tr{'enabled'} <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td> \n " ;
3492 # if ($cgiparams{'KEY'}) {
3493 # print "<td colspan='3'> </td></tr></table>";
3495 # print "<td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked{'EDIT_ADVANCED'}{'on'} /> $Lang::tr{'edit advanced settings when done'}</tr></table>";
3498 print "<td colspan='3'> </td></tr></table>" ;
3503 & Header
:: closebox
();
3505 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
3506 # &Header::openbox('100%', 'LEFT', $Lang::tr{'authentication'});
3508 # <table width='100%' cellpadding='0' cellspacing='5' border='0'>
3509 # <tr><td class='base' width='50%'>$Lang::tr{'use a pre-shared key'}</td>
3510 # <td class='base' width='50%'><input type='text' name='PSK' size='30' value='$cgiparams{'PSK'}' /></td></tr>
3514 # &Header::closebox();
3515 } elsif (! $cgiparams { 'KEY' }) {
3517 my $cakeydisabled = '' ;
3518 my $cacrtdisabled = '' ;
3519 if ( ! - f
"${General::swroot}/ovpn/ca/cakey.pem" ) { $cakeydisabled = "disabled='disabled'" } else { $cakeydisabled = "" };
3520 if ( ! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) { $cacrtdisabled = "disabled='disabled'" } else { $cacrtdisabled = "" };
3521 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'authentication' });
3524 if ( $cgiparams { 'TYPE' } eq 'host' ) {
3527 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
3529 <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>
3530 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td><td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
3531 <tr><td colspan='3'> </td></tr>
3532 <tr><td colspan='3'><hr /></td></tr>
3533 <tr><td colspan='3'> </td></tr>
3534 <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>
3535 <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>
3536 <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>
3537 <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>
3538 <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>
3539 <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>
3540 <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>
3541 <tr><td> </td><td class='base'> $Lang ::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
3552 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
3554 <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>
3555 <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>
3556 <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>
3557 <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>
3558 <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>
3559 <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>
3560 <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>
3561 <tr><td> </td><td class='base'> $Lang ::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
3573 foreach my $country ( sort keys %{ Countries
:: countries
}) {
3574 print "<option value=' $Countries ::countries{ $country }'" ;
3575 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
3576 print " selected='selected'" ;
3578 print "> $country </option>" ;
3584 if ( $cgiparams { 'TYPE' } eq 'host' ) {
3588 <td> </td><td class='base'> $Lang ::tr{'valid till'} (days):</td>
3589 <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value=' $cgiparams {'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr>
3591 <td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
3592 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
3593 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'}:<BR>( $Lang ::tr{'confirmation'})</td>
3594 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
3595 <tr><td colspan='3'> </td></tr>
3596 <tr><td colspan='3'><hr /></td></tr>
3597 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
3603 <tr><td> </td><td> </td><td> </td></tr>
3604 <tr><td> </td><td> </td><td> </td></tr>
3605 <tr><td colspan='3'><hr /></td></tr>
3606 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
3616 & Header
:: closebox
();
3619 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
3620 if ( $cgiparams { 'KEY' }) {
3621 # print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />";
3623 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
3624 & Header
:: closebigbox
();
3625 & Header
:: closepage
();
3633 ### Default status page
3638 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%cgiparams );
3639 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
3640 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3642 my @status = `/bin/cat /var/log/ovpnserver.log` ;
3644 if ( $cgiparams { 'VPN_IP' } eq '' && - e
"${General::swroot}/red/active" ) {
3645 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
3646 my $ipaddr = < IPADDR
>;
3649 $cgiparams { 'VPN_IP' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
3650 if ( $cgiparams { 'VPN_IP' } eq '' ) {
3651 $cgiparams { 'VPN_IP' } = $ipaddr ;
3657 if ( $cgiparams { 'DCIPHER' } eq '' ) {
3658 $cgiparams { 'DCIPHER' } = 'BF-CBC' ;
3660 # if ($cgiparams{'DCOMPLZO'} eq '') {
3661 # $cgiparams{'DCOMPLZO'} = 'on';
3663 if ( $cgiparams { 'DDEST_PORT' } eq '' ) {
3664 $cgiparams { 'DDEST_PORT' } = '1194' ;
3666 if ( $cgiparams { 'DMTU' } eq '' ) {
3667 $cgiparams { 'DMTU' } = '1400' ;
3669 if ( $cgiparams { 'DOVPN_SUBNET' } eq '' ) {
3670 $cgiparams { 'DOVPN_SUBNET' } = '10.' . int ( rand ( 256 )) . '.' . int ( rand ( 256 )) . '.0/255.255.255.0' ;
3673 $checked { 'ENABLED' }{ 'off' } = '' ;
3674 $checked { 'ENABLED' }{ 'on' } = '' ;
3675 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = 'CHECKED' ;
3676 $checked { 'ENABLED_BLUE' }{ 'off' } = '' ;
3677 $checked { 'ENABLED_BLUE' }{ 'on' } = '' ;
3678 $checked { 'ENABLED_BLUE' }{ $cgiparams { 'ENABLED_BLUE' }} = 'CHECKED' ;
3679 $checked { 'ENABLED_ORANGE' }{ 'off' } = '' ;
3680 $checked { 'ENABLED_ORANGE' }{ 'on' } = '' ;
3681 $checked { 'ENABLED_ORANGE' }{ $cgiparams { 'ENABLED_ORANGE' }} = 'CHECKED' ;
3682 $selected { 'DDEVICE' }{ 'tun' } = '' ;
3683 $selected { 'DDEVICE' }{ 'tap' } = '' ;
3684 $selected { 'DDEVICE' }{ $cgiparams { 'DDEVICE' }} = 'SELECTED' ;
3686 $selected { 'DPROTOCOL' }{ 'udp' } = '' ;
3687 $selected { 'DPROTOCOL' }{ 'tcp' } = '' ;
3688 $selected { 'DPROTOCOL' }{ $cgiparams { 'DPROTOCOL' }} = 'SELECTED' ;
3690 $selected { 'DCIPHER' }{ 'DES-CBC' } = '' ;
3691 $selected { 'DCIPHER' }{ 'DES-EDE-CBC' } = '' ;
3692 $selected { 'DCIPHER' }{ 'DES-EDE3-CBC' } = '' ;
3693 $selected { 'DCIPHER' }{ 'DESX-CBC' } = '' ;
3694 $selected { 'DCIPHER' }{ 'RC2-CBC' } = '' ;
3695 $selected { 'DCIPHER' }{ 'RC2-40-CBC' } = '' ;
3696 $selected { 'DCIPHER' }{ 'RC2-64-CBC' } = '' ;
3697 $selected { 'DCIPHER' }{ 'BF-CBC' } = '' ;
3698 $selected { 'DCIPHER' }{ 'CAST5-CBC' } = '' ;
3699 $selected { 'DCIPHER' }{ 'AES-128-CBC' } = '' ;
3700 $selected { 'DCIPHER' }{ 'AES-192-CBC' } = '' ;
3701 $selected { 'DCIPHER' }{ 'AES-256-CBC' } = '' ;
3702 $selected { 'DCIPHER' }{ $cgiparams { 'DCIPHER' }} = 'SELECTED' ;
3703 $checked { 'DCOMPLZO' }{ 'off' } = '' ;
3704 $checked { 'DCOMPLZO' }{ 'on' } = '' ;
3705 $checked { 'DCOMPLZO' }{ $cgiparams { 'DCOMPLZO' }} = 'CHECKED' ;
3707 $checked { 'MSSFIX' }{ 'off' } = '' ;
3708 $checked { 'MSSFIX' }{ 'on' } = '' ;
3709 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
3711 & Header
:: showhttpheaders
();
3712 & Header
:: openpage
( $Lang :: tr
{ 'status ovpn' }, 1 , '' );
3713 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
3715 if ( $errormessage ) {
3716 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
3717 print "<class name='base'> $errormessage \n " ;
3718 print " </class> \n " ;
3719 & Header
:: closebox
();
3722 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>" ;
3723 my $srunning = "no" ;
3724 my $activeonrun = "" ;
3725 if ( - e
"/var/run/openvpn.pid" ){
3726 $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>" ;
3730 $activeonrun = "disabled='disabled'" ;
3732 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'global settings' });
3734 <table width='100%'>
3735 <form method='post'>
3736 <td width='25%'> </td>
3737 <td width='25%'> </td>
3738 <td width='25%'> </td></tr>
3739 <tr><td class='boldbase'> $Lang ::tr{'ovpn server status'}</td>
3740 <td align='left'> $sactive </td>
3741 <tr><td class='boldbase'> $Lang ::tr{'ovpn on red'}</td>
3742 <td><input type='checkbox' name='ENABLED' $checked {'ENABLED'}{'on'} /></td>
3745 if (& haveBlueNet
()) {
3746 print "<tr><td class='boldbase'> $Lang ::tr{'ovpn on blue'}</td>" ;
3747 print "<td><input type='checkbox' name='ENABLED_BLUE' $checked {'ENABLED_BLUE'}{'on'} /></td>" ;
3749 if (& haveOrangeNet
()) {
3750 print "<tr><td class='boldbase'> $Lang ::tr{'ovpn on orange'}</td>" ;
3751 print "<td><input type='checkbox' name='ENABLED_ORANGE' $checked {'ENABLED_ORANGE'}{'on'} /></td>" ;
3754 <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>
3755 <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>
3756 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn device'}</td>
3757 <td><select name='DDEVICE' ><option value='tun' $selected {'DDEVICE'}{'tun'}>TUN</option>
3758 <!-- this is still not working
3759 <option value='tap' $selected {'DDEVICE'}{'tap'}>TAP</option></select>--> </td>
3760 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td>
3761 <td><select name='DPROTOCOL'><option value='udp' $selected {'DPROTOCOL'}{'udp'}>UDP</option>
3762 <option value='tcp' $selected {'DPROTOCOL'}{'tcp'}>TCP</option></select></td>
3763 <td class='boldbase'> $Lang ::tr{'destination port'}:</td>
3764 <td><input type='TEXT' name='DDEST_PORT' value=' $cgiparams {'DDEST_PORT'}' size='5' /></td></tr>
3765 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'} </td>
3766 <td> <input type='TEXT' name='DMTU' VALUE=' $cgiparams {'DMTU'}'size='5' /></TD>
3767 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'}</td>
3768 <td><input type='checkbox' name='DCOMPLZO' $checked {'DCOMPLZO'}{'on'} /></td>
3769 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'cipher'}</td>
3770 <td><select name='DCIPHER'><option value='DES-CBC' $selected {'DCIPHER'}{'DES-CBC'}>DES-CBC</option>
3771 <option value='DES-EDE-CBC' $selected {'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC</option>
3772 <option value='DES-EDE3-CBC' $selected {'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC</option>
3773 <option value='DESX-CBC' $selected {'DCIPHER'}{'DESX-CBC'}>DESX-CBC</option>
3774 <option value='RC2-CBC' $selected {'DCIPHER'}{'RC2-CBC'}>RC2-CBC</option>
3775 <option value='RC2-40-CBC' $selected {'DCIPHER'}{'RC2-40-CBC'}>RC2-40-CBC</option>
3776 <option value='RC2-64-CBC' $selected {'DCIPHER'}{'RC2-64-CBC'}>RC2-64-CBC</option>
3777 <option value='BF-CBC' $selected {'DCIPHER'}{'BF-CBC'}>BF-CBC</option>
3778 <option value='CAST5-CBC' $selected {'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC</option>
3779 <option value='AES-128-CBC' $selected {'DCIPHER'}{'AES-128-CBC'}>AES-128-CBC</option>
3780 <option value='AES-192-CBC' $selected {'DCIPHER'}{'AES-192-CBC'}>AES-192-CBC</option>
3781 <option value='AES-256-CBC' $selected {'DCIPHER'}{'AES-256-CBC'}>AES-256-CBC</option></select></td>
3785 if ( $srunning eq "yes" ) {
3786 print "<tr><td align='left'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' disabled='disabled' /></td>" ;
3787 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'advanced server'}' disabled='disabled'/></td>" ;
3788 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'stop ovpn server'}' /></td>" ;
3789 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'restart ovpn server'}' /></td></tr>" ;
3791 print "<tr><td align='left'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' /></td>" ;
3792 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'advanced server'}' /></td>" ;
3793 if (( - e
"${General::swroot}/ovpn/ca/cacert.pem" &&
3794 - e
"${General::swroot}/ovpn/ca/dh1024.pem" &&
3795 - e
"${General::swroot}/ovpn/certs/servercert.pem" &&
3796 - e
"${General::swroot}/ovpn/certs/serverkey.pem" ) &&
3797 (( $cgiparams { 'ENABLED' } eq 'on' ) ||
3798 ( $cgiparams { 'ENABLED_BLUE' } eq 'on' ) ||
3799 ( $cgiparams { 'ENABLED_ORANGE' } eq 'on' ))){
3800 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'start ovpn server'}' /></td>" ;
3801 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'restart ovpn server'}' /></td></tr>" ;
3803 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'start ovpn server'}' disabled='disabled' /></td>" ;
3804 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'restart ovpn server'}' disabled='disabled' /></td></tr>" ;
3807 print "</form></table>" ;
3808 & Header
:: closebox
();
3809 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'certificate authorities'}:" );
3811 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
3813 <td width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></td>
3814 <td width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></td>
3815 <td width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></td>
3819 if (- f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
3820 my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem` ;
3821 $casubject =~ /Subject: (.*)[\n]/ ;
3823 $casubject =~ s
+/ Email
+, E
+;
3824 $casubject =~ s/ ST=/ S=/ ;
3827 <tr bgcolor=' $color {'color22'}'>
3828 <td class='base'> $Lang ::tr{'root certificate'}</td>
3829 <td class='base'> $casubject </td>
3830 <form method='post' name='frmrootcrta'><td width='3%' align='center'>
3831 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
3832 <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' />
3834 <form method='post' name='frmrootcrtb'><td width='3%' align='center'>
3835 <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' />
3836 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
3838 <td width='4%'> </td></tr>
3842 # display rootcert generation buttons
3844 <tr bgcolor=' $color {'color22'}'>
3845 <td class='base'> $Lang ::tr{'root certificate'}:</td>
3846 <td class='base'> $Lang ::tr{'not present'}</td>
3847 <td colspan='3'> </td></tr>
3852 if (- f
"${General::swroot}/ovpn/certs/servercert.pem" ) {
3853 my $hostsubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem` ;
3854 $hostsubject =~ /Subject: (.*)[\n]/ ;
3856 $hostsubject =~ s
+/ Email
+, E
+;
3857 $hostsubject =~ s/ ST=/ S=/ ;
3860 <tr bgcolor=' $color {'color20'}'>
3861 <td class='base'> $Lang ::tr{'host certificate'}</td>
3862 <td class='base'> $hostsubject </td>
3863 <form method='post' name='frmhostcrta'><td width='3%' align='center'>
3864 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
3865 <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' />
3867 <form method='post' name='frmhostcrtb'><td width='3%' align='center'>
3868 <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' />
3869 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download host certificate'}' />
3871 <td width='4%'> </td></tr>
3877 <tr bgcolor=' $color {'color20'}'>
3878 <td width='25%' class='base'> $Lang ::tr{'host certificate'}:</td>
3879 <td class='base'> $Lang ::tr{'not present'}</td>
3880 </td><td colspan='3'> </td></tr>
3885 if (! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
3886 print "<tr><td colspan='5' align='center'><form method='post'>" ;
3887 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' />" ;
3888 print "</form></td></tr> \n " ;
3891 if ( keys %cahash > 0 ) {
3892 foreach my $key ( keys %cahash ) {
3893 if (( $key + 1 ) % 2 ) {
3894 print "<tr bgcolor=' $color {'color20'}'> \n " ;
3896 print "<tr bgcolor=' $color {'color22'}'> \n " ;
3898 print "<td class='base'> $cahash { $key }[0]</td> \n " ;
3899 print "<td class='base'> $cahash { $key }[1]</td> \n " ;
3901 <form method='post' name='cafrm${key}a'><td align='center'>
3902 <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' />
3903 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
3904 <input type='hidden' name='KEY' value=' $key ' />
3906 <form method='post' name='cafrm${key}b'><td align='center'>
3907 <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' />
3908 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
3909 <input type='hidden' name='KEY' value=' $key ' />
3911 <form method='post' name='cafrm${key}c'><td align='center'>
3912 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
3913 <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' />
3914 <input type='hidden' name='KEY' value=' $key ' />
3923 # If the file contains entries, print Key to action icons
3924 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
3928 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
3929 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
3930 <td class='base'> $Lang ::tr{'show certificate'}</td>
3931 <td> <img src='/images/media-floppy.png' alt=' $Lang ::tr{'download certificate'}' /></td>
3932 <td class='base'> $Lang ::tr{'download certificate'}</td>
3939 <form method='post' enctype='multipart/form-data'>
3940 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
3941 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'ca name'}:</td>
3942 <td nowrap='nowrap'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' />
3943 <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td>
3944 <td nowrap='nowrap'><input type='submit' name='ACTION' value=' $Lang ::tr{'upload ca certificate'}' /><br /><input type='submit' name='ACTION' value=' $Lang ::tr{'show crl'}' /></td>
3945 </tr></table></form>
3949 & Header
:: closebox
();
3950 if ( $srunning eq "yes" ) {
3951 print "<div align='center'><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'reset'}' disabled='disabled' /></div></form> \n " ;
3953 print "<div align='center'><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'reset'}' /></div></form> \n " ;
3955 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
3959 #<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>
3962 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'Client status and controlc' });
3966 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
3968 <td width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></td>
3969 <td width='15%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></td>
3970 <td width='18%' class='boldbase' align='center'><b> $Lang ::tr{'common name'}</b></td>
3971 <td width='22%' class='boldbase' align='center'><b> $Lang ::tr{'valid till'}</b></td>
3972 <td width='20%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></td>
3973 <td width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></td>
3974 <td width='5%' class='boldbase' colspan='6' align='center'><b> $Lang ::tr{'action'}</b></td>
3980 foreach my $key ( sort { uc ( $confighash { $a }[ 1 ]) cmp uc ( $confighash { $b }[ 1 ]) } keys %confighash ) {
3981 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
3984 print "<tr bgcolor=' $color {'color20'}'> \n " ;
3986 print "<tr bgcolor=' $color {'color22'}'> \n " ;
3988 print "<td align='center' nowrap='nowrap'> $confighash { $key }[1]</td>" ;
3989 print "<td align='center' nowrap='nowrap'>" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ")</td>" ;
3990 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
3991 print "<td align='left' nowrap='nowrap'> $confighash { $key }[2]</td>" ;
3993 print "<td align='left'> </td>" ;
3995 my $cavalid = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $confighash { $key }[1]cert.pem` ;
3996 $cavalid =~ /Not After : (.*)[\n]/ ;
3998 print "<td align='center'> $cavalid </td>" ;
3999 print "<td align='center'> $confighash { $key }[25]</td>" ;
4001 my $active = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourred}' width='100%'><tr><td align='center'><b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b></td></tr></table>" ;
4003 if ( $confighash { $key }[ 0 ] eq 'off' ) {
4004 $active = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourblue}' width='100%'><tr><td align='center'><b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b></td></tr></table>" ;
4011 if ( $confighash { $key }[ 3 ] eq 'net' ) {
4013 if (- e
"/var/run/ $confighash { $key }[1]n2n.pid" ) {
4016 my $tport = $confighash { $key }[ 22 ];
4017 my $tnet = new Net
:: Telnet
( Timeout
=> 5 , Errmode
=> 'return' , Port
=> $tport );
4019 $tnet -> open ( '127.0.0.1' );
4020 @output = $tnet -> cmd ( String
=> 'state' , Prompt
=> '/(END.* \n |ERROR:.* \n )/' );
4021 @tustate = split ( /\,/ , $output [ 1 ]);
4023 #CONNECTING -- OpenVPN's initial state.
4024 #WAIT -- (Client only) Waiting for initial response from server.
4025 #AUTH -- (Client only) Authenticating with server.
4026 #GET_CONFIG -- (Client only) Downloading configuration options from server.
4027 #ASSIGN_IP -- Assigning IP address to virtual network interface.
4028 #ADD_ROUTES -- Adding routes to system.
4029 #CONNECTED -- Initialization Sequence Completed.
4030 #RECONNECTING -- A restart has occurred.
4031 #EXITING -- A graceful exit is in progress.
4034 if ( $tustate [ 1 ] eq 'CONNECTED' ) {
4035 $active = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourgreen}' width='100%'><tr><td align='center'><b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b></tr></td></table>" ;
4037 $active = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourred}' width='100%'><tr><td align='center'><b><font color='#FFFFFF'> $tustate [1]</font></b></td></tr></table>" ;
4045 foreach my $line ( @status ) {
4047 if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ ) {
4048 @match = split ( m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ , $line );
4049 if ( $match [ 1 ] ne "Common Name" ) {
4053 if ( $cn eq " $confighash { $key }[2]" ) {
4054 $active = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourgreen}' width='100%'><tr><td align='center'><b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b></td></tr></table>" ;
4063 my $disable_clientdl = "disabled='disabled'" ;
4064 if (( $cgiparams { 'ENABLED' } eq 'on' ) ||
4065 ( $cgiparams { 'ENABLED_BLUE' } eq 'on' ) ||
4066 ( $cgiparams { 'ENABLED_ORANGE' } eq 'on' )){
4067 $disable_clientdl = "" ;
4070 <td align='center'> $active </td>
4072 <form method='post' name='frm${key}a'><td align='center'>
4073 <input type='image' name=' $Lang ::tr{'dl client arch'}' $disable_clientdl src='/images/openvpn.png' alt=' $Lang ::tr{'dl client arch'}' title=' $Lang ::tr{'dl client arch'}' border='0' />
4074 <input type='hidden' name='ACTION' value=' $Lang ::tr{'dl client arch'}' $disable_clientdl />
4075 <input type='hidden' name='KEY' value=' $key ' $disable_clientdl />
4079 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
4081 <form method='post' name='frm${key}b'><td align='center'>
4082 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' border='0' />
4083 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
4084 <input type='hidden' name='KEY' value=' $key ' />
4088 print "<td> </td>" ;
4090 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $key }[1].p12" ) {
4092 <form method='post' name='frm${key}c'><td align='center'>
4093 <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' />
4094 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
4095 <input type='hidden' name='KEY' value=' $key ' />
4098 ; } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
4100 <form method='post' name='frm${key}c'><td align='center'>
4101 <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' />
4102 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
4103 <input type='hidden' name='KEY' value=' $key ' />
4107 print "<td> </td>" ;
4110 <form method='post' name='frm${key}d'><td align='center'>
4111 <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' />
4112 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
4113 <input type='hidden' name='KEY' value=' $key ' />
4116 <form method='post' name='frm${key}e'><td align='center'>
4117 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
4118 <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'/>
4119 <input type='hidden' name='KEY' value=' $key ' />
4121 <form method='post' name='frm${key}f'><td align='center'>
4122 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
4123 <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' />
4124 <input type='hidden' name='KEY' value=' $key ' />
4133 # If the config file contains entries, print Key to action icons
4138 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
4139 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
4140 <td class='base'> $Lang ::tr{'click to disable'}</td>
4141 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
4142 <td class='base'> $Lang ::tr{'show certificate'}</td>
4143 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
4144 <td class='base'> $Lang ::tr{'edit'}</td>
4145 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
4146 <td class='base'> $Lang ::tr{'remove'}</td>
4150 <td> <img src='/images/off.gif' alt='?OFF' /></td>
4151 <td class='base'> $Lang ::tr{'click to enable'}</td>
4152 <td> <img src='/images/media-floppy.png' alt='?FLOPPY' /></td>
4153 <td class='base'> $Lang ::tr{'download certificate'}</td>
4154 <td> <img src='/images/openvpn.png' alt='?RELOAD'/></td>
4155 <td class='base'> $Lang ::tr{'dl client arch'}</td>
4163 <table width='100%'>
4164 <form method='post'>
4165 <tr><td width='50%' ><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td>
4166 <td width='50%' ><input type='submit' name='ACTION' value=' $Lang ::tr{'ovpn con stat'}' $activeonrun /></td></tr>
4171 & Header
:: closebox
();
4173 & Header
:: closepage
();