]>
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 $routes_push_file = "${General::swroot}/ovpn/routes_push" ;
81 unless (- e
$routes_push_file ) { system ( "touch $routes_push_file " ); }
83 & Header
:: getcgihash
( \
%cgiparams , { 'wantfile' => 1 , 'filevar' => 'FH' });
85 # prepare openvpn config file
91 if ( $netsettings { 'CONFIG_TYPE' } == 2 ) { return 1 ;}
92 if ( $netsettings { 'CONFIG_TYPE' } == 4 ) { return 1 ;}
98 if ( $netsettings { 'CONFIG_TYPE' } == 3 ) { return 1 ;}
99 if ( $netsettings { 'CONFIG_TYPE' } == 4 ) { return 1 ;}
104 my $bytesize = shift ;
107 while ( abs ( $bytesize ) >= 1024 ){
108 $bytesize = $bytesize / 1024 ;
113 my @units = ( "Bytes" , "KB" , "MB" , "GB" , "TB" , "PB" , "EB" );
114 my $newsize =( int ( $bytesize * 100 + 0.5 ))/ 100 ;
115 return ( " $newsize $units [ $i ]" );
119 my $hostname = $_ [ 0 ];
120 unless ( $hostname ) { return "No hostname" };
121 my $res = new Net
:: DNS
:: Resolver
;
122 my $query = $res -> search ( " $hostname " );
124 foreach my $rr ( $query -> answer ) {
125 ## Potential bug - we are only looking at A records:
126 return 0 if $rr -> type eq "A" ;
129 return $res -> errorstring ;
135 if ( open ( FILE
, ">${General::swroot}/ovpn/certs/serial" )) {
139 if ( open ( FILE
, ">${General::swroot}/ovpn/certs/index.txt" )) {
143 unlink ( "${General::swroot}/ovpn/certs/index.txt.old" );
144 unlink ( "${General::swroot}/ovpn/certs/serial.old" );
145 unlink ( "${General::swroot}/ovpn/certs/01.pem" );
148 sub newcleanssldatabase
150 if (! - s
"${General::swroot}/ovpn/certs/serial" ) {
151 open ( FILE
, ">${General::swroot}(ovpn/certs/serial" );
155 if (! - s
">${General::swroot}/ovpn/certs/index.txt" ) {
156 system ( "touch ${General::swroot}/ovpn/certs/index.txt" );
158 unlink ( "${General::swroot}/ovpn/certs/index.txt.old" );
159 unlink ( "${General::swroot}/ovpn/certs/serial.old" );
164 if ( open ( FILE
, "${General::swroot}/ovpn/certs/serial.old" )) {
165 my $hexvalue = < FILE
>;
168 unlink ( "${General::swroot}/ovpn/certs/ $hexvalue .pem" );
173 my $KEY2 = $_ [ 0 ]; # key2
174 my $SRC_PORT = $_ [ 1 ]; # src_port
175 my $PROTOCOL = $_ [ 2 ]; # protocol
176 my $SRC_IP = $_ [ 3 ]; # sourceip
178 my $pfwfilename = "${General::swroot}/portfw/config" ;
179 open ( FILE
, $pfwfilename ) or die 'Unable to open config file.' ;
180 my @pfwcurrent = < FILE
>;
182 my $pfwkey1 = 0 ; # used for finding last sequence number used
183 foreach my $pfwline ( @pfwcurrent )
185 my @pfwtemp = split ( /\,/ , $pfwline );
188 if ( $KEY2 eq "0" ){ # if key2 is 0 then it is a portfw addition
189 if ( $SRC_PORT eq $pfwtemp [ 3 ] &&
190 $PROTOCOL eq $pfwtemp [ 2 ] &&
191 $SRC_IP eq $pfwtemp [ 7 ])
193 $errormessage = " $Lang ::tr{'source port in use'} $SRC_PORT " ;
195 # Check if key2 = 0, if it is then it is a port forward entry and we want the sequence number
196 if ( $pfwtemp [ 1 ] eq "0" ) {
197 $pfwkey1 = $pfwtemp [ 0 ];
199 # Darren Critchley - Duplicate or overlapping Port range check
200 if ( $pfwtemp [ 1 ] eq "0" &&
201 $PROTOCOL eq $pfwtemp [ 2 ] &&
202 $SRC_IP eq $pfwtemp [ 7 ] &&
205 & portchecks
( $SRC_PORT , $pfwtemp [ 5 ]);
206 # &portchecks($pfwtemp[3], $pfwtemp[5]);
207 # &portchecks($pfwtemp[3], $SRC_IP);
211 # $errormessage="$KEY2 $SRC_PORT $PROTOCOL $SRC_IP";
218 my $portrange1 = $_ [ 0 ]; # New port range
219 my $portrange2 = $_ [ 1 ]; # existing port range
220 my @tempr1 = split ( /\:/ , $portrange1 );
221 my @tempr2 = split ( /\:/ , $portrange2 );
223 unless (& checkportinc
( $tempr1 [ 0 ], $portrange2 )){ return 0 ;}
224 unless (& checkportinc
( $tempr1 [ 1 ], $portrange2 )){ return 0 ;}
226 unless (& checkportinc
( $tempr2 [ 0 ], $portrange1 )){ return 0 ;}
227 unless (& checkportinc
( $tempr2 [ 1 ], $portrange1 )){ return 0 ;}
229 return 1 ; # Everything checks out!
232 # Darren Critchley - we want to make sure that a port entry is not within an already existing range
235 my $port1 = $_ [ 0 ]; # Port
236 my $portrange2 = $_ [ 1 ]; # Port range
237 my @tempr1 = split ( /\:/ , $portrange2 );
239 if ( $port1 < $tempr1 [ 0 ] || $port1 > $tempr1 [ 1 ]) {
245 # Darren Critchley - Duplicate or overlapping Port range check
248 my $p1 = $_ [ 0 ]; # New port range
249 my $p2 = $_ [ 1 ]; # existing port range
251 our ( $prtrange1 , $prtrange2 );
253 # if (m/:/ && $prtrange1 == 1) { # comparing two port ranges
254 # unless (&checkportoverlap($p1,$p2)) {
255 # $errormessage = "$Lang::tr{'source port overlaps'} $p1";
258 if ( m/:/ && $prtrange1 == 0 && $errormessage eq '' ) { # compare one port to a range
259 unless (& checkportinc
( $p2 , $p1 )) {
260 $errormessage = " $Lang ::tr{'srcprt within existing'} $p1 " ;
264 if (! m/:/ && $prtrange1 == 1 && $errormessage eq '' ) { # compare one port to a range
265 unless (& checkportinc
( $p1 , $p2 )) {
266 $errormessage = " $Lang ::tr{'srcprt range overlaps'} $p2 " ;
272 # Darren Critchley - certain ports are reserved for IPFire
273 # TCP 67,68,81,222,445
275 # Params passed in -> port, rangeyn, protocol
278 # port 67 and 68 same for tcp and udp, don't bother putting in an array
280 my @tcp_reserved = ( 81 , 222 , 445 );
281 my $prt = $_ [ 0 ]; # the port or range
282 my $ryn = $_ [ 1 ]; # tells us whether or not it is a port range
283 my $prot = $_ [ 2 ]; # protocol
284 my $srcdst = $_ [ 3 ]; # source or destination
285 if ( $ryn ) { # disect port range
286 if ( $srcdst eq "src" ) {
287 $msg = " $Lang ::tr{'rsvd src port overlap'}" ;
289 $msg = " $Lang ::tr{'rsvd dst port overlap'}" ;
291 my @tmprng = split ( /\:/ , $prt );
292 unless ( 67 < $tmprng [ 0 ] || 67 > $tmprng [ 1 ]) { $errormessage = " $msg 67" ; return ; }
293 unless ( 68 < $tmprng [ 0 ] || 68 > $tmprng [ 1 ]) { $errormessage = " $msg 68" ; return ; }
294 if ( $prot eq "tcp" ) {
295 foreach my $prange ( @tcp_reserved ) {
296 unless ( $prange < $tmprng [ 0 ] || $prange > $tmprng [ 1 ]) { $errormessage = " $msg $prange " ; return ; }
300 if ( $srcdst eq "src" ) {
301 $msg = " $Lang ::tr{'reserved src port'}" ;
303 $msg = " $Lang ::tr{'reserved dst port'}" ;
305 if ( $prt == 67 ) { $errormessage = " $msg 67" ; return ; }
306 if ( $prt == 68 ) { $errormessage = " $msg 68" ; return ; }
307 if ( $prot eq "tcp" ) {
308 foreach my $prange ( @tcp_reserved ) {
309 if ( $prange == $prt ) { $errormessage = " $msg $prange " ; return ; }
317 sub writeserverconf
{
318 my %sovpnsettings = ();
320 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%sovpnsettings );
323 open ( CONF
, ">${General::swroot}/ovpn/server.conf" ) or die "Unable to open ${General::swroot}/ovpn/server.conf: $!" ;
325 print CONF
"#OpenVPN Server conf \n " ;
327 print CONF
"daemon openvpnserver \n " ;
328 print CONF
"writepid /var/run/openvpn.pid \n " ;
329 print CONF
"#DAN prepare OpenVPN for listening on blue and orange \n " ;
330 print CONF
";local $sovpnsettings {'VPN_IP'} \n " ;
331 print CONF
"dev $sovpnsettings {'DDEVICE'} \n " ;
332 print CONF
" $sovpnsettings {'DDEVICE'}-mtu $sovpnsettings {'DMTU'} \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
"tls-server \n " ;
338 print CONF
"ca /var/ipfire/ovpn/ca/cacert.pem \n " ;
339 print CONF
"cert /var/ipfire/ovpn/certs/servercert.pem \n " ;
340 print CONF
"key /var/ipfire/ovpn/certs/serverkey.pem \n " ;
341 print CONF
"dh /var/ipfire/ovpn/ca/dh1024.pem \n " ;
342 my @tempovpnsubnet = split ( "\/" , $sovpnsettings { 'DOVPN_SUBNET' });
343 print CONF
"server $tempovpnsubnet [0] $tempovpnsubnet [1] \n " ;
344 print CONF
"push \" route $netsettings {'GREEN_NETADDRESS'} $netsettings {'GREEN_NETMASK'} \"\n " ;
346 if ( $vpnsettings { 'ROUTES_PUSH' } ne '' ) {
347 @temp = split ( /\n/ , $vpnsettings { 'ROUTES_PUSH' });
350 @tempovpnsubnet = split ( "\/" ,& General
:: ipcidr2msk
( $_ ));
351 print CONF
"push \" route " . $tempovpnsubnet [ 0 ]. " " . $tempovpnsubnet [ 1 ] . " \"\n " ;
355 if ( $sovpnsettings { CLIENT2CLIENT
} eq 'on' ) {
356 print CONF
"client-to-client \n " ;
358 if ( $sovpnsettings { MSSFIX
} eq 'on' ) {
359 print CONF
"mssfix \n " ;
361 if ( $sovpnsettings { FRAGMENT
} ne '' && $sovpnsettings { 'DPROTOCOL' } ne 'tcp' ) {
362 print CONF
"fragment $sovpnsettings {'FRAGMENT'} \n " ;
364 if ( $sovpnsettings { KEEPALIVE_1
} > 0 && $sovpnsettings { KEEPALIVE_2
} > 0 ) {
365 print CONF
"keepalive $sovpnsettings {'KEEPALIVE_1'} $sovpnsettings {'KEEPALIVE_2'} \n " ;
367 print CONF
"status-version 1 \n " ;
368 print CONF
"status /var/log/ovpnserver.log 30 \n " ;
369 print CONF
"cipher $sovpnsettings {DCIPHER} \n " ;
370 if ( $sovpnsettings { DCOMPLZO
} eq 'on' ) {
371 print CONF
"comp-lzo \n " ;
373 if ( $sovpnsettings { REDIRECT_GW_DEF1
} eq 'on' ) {
374 print CONF
"push \" redirect-gateway def1 \"\n " ;
376 if ( $sovpnsettings { DHCP_DOMAIN
} ne '' ) {
377 print CONF
"push \" dhcp-option DOMAIN $sovpnsettings {DHCP_DOMAIN} \"\n " ;
380 if ( $sovpnsettings { DHCP_DNS
} ne '' ) {
381 print CONF
"push \" dhcp-option DNS $sovpnsettings {DHCP_DNS} \"\n " ;
384 if ( $sovpnsettings { DHCP_WINS
} ne '' ) {
385 print CONF
"push \" dhcp-option WINS $sovpnsettings {DHCP_WINS} \"\n " ;
388 if ( $sovpnsettings { DHCP_WINS
} eq '' ) {
389 print CONF
"max-clients 100 \n " ;
391 if ( $sovpnsettings { DHCP_WINS
} ne '' ) {
392 print CONF
"max-clients $sovpnsettings {MAX_CLIENTS} \n " ;
394 print CONF
"tls-verify /var/ipfire/ovpn/verify \n " ;
395 print CONF
"crl-verify /var/ipfire/ovpn/crls/cacrl.pem \n " ;
396 print CONF
"user nobody \n " ;
397 print CONF
"group nobody \n " ;
398 print CONF
"persist-key \n " ;
399 print CONF
"persist-tun \n " ;
400 if ( $sovpnsettings { LOG_VERB
} ne '' ) {
401 print CONF
"verb $sovpnsettings {LOG_VERB} \n " ;
403 print CONF
"verb 3 \n " ;
411 if ( open ( FILE
, ">/var/log/ovpnserver.log" )) {
425 my $ipdotmask = $_ [ 0 ];
426 if (& General
:: validip
( $ipdotmask )) { return 0 ; }
427 if (!( $ipdotmask =~ /^(.*?)\/ (.* ?
)$/)) { }
429 if (( $mask =~ /\./ )) { return 0 ; }
433 # -------------------------------------------------------------------
435 sub write_routepushfile
437 open ( FILE
, "> $routes_push_file " );
439 if ( $vpnsettings { 'ROUTES_PUSH' } ne '' ) {
440 print FILE
$vpnsettings { 'ROUTES_PUSH' };
445 sub read_routepushfile
447 if (- e
" $routes_push_file " ) {
448 open ( FILE
, " $routes_push_file " );
449 delete $vpnsettings { 'ROUTES_PUSH' };
450 while (< FILE
>) { $vpnsettings { 'ROUTES_PUSH' } .= $_ };
452 $cgiparams { 'ROUTES_PUSH' } = $vpnsettings { 'ROUTES_PUSH' };
457 #hier die refresh page
458 if ( - e
"${General::swroot}/ovpn/gencanow" ) {
460 $refresh = "<meta http-equiv='refresh' content='15;' />" ;
461 & Header
:: showhttpheaders
();
462 & Header
:: openpage
( $Lang :: tr
{ 'OVPN' }, 1 , $refresh );
463 & Header
:: openbigbox
( '100%' , 'center' );
464 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
465 print "<tr> \n <td align='center'><img src='/images/clock.gif' alt='' /></td> \n " ;
466 print "<td colspan='2'><font color='red'>Please be patient this realy can take some time on older hardware...</font></td></tr> \n " ;
468 & Header
:: closebigbox
();
469 & Header
:: closepage
();
472 ##hier die refresh page
476 ### OpenVPN Server Control
478 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'start ovpn server' } ||
479 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'stop ovpn server' } ||
480 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart ovpn server' }) {
481 #start openvpn server
482 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'start ovpn server' }){
484 system ( '/usr/local/bin/openvpnctrl' , '-s' );
487 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'stop ovpn server' }){
488 system ( '/usr/local/bin/openvpnctrl' , '-k' );
491 # #restart openvpn server
492 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart ovpn server' }){
493 #workarund, till SIGHUP also works when running as nobody
494 system ( '/usr/local/bin/openvpnctrl' , '-r' );
500 ### Save Advanced options
503 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save-adv-options' }) {
504 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
505 #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too,
506 #DAN this value has to leave.
507 #new settings for daemon
508 $vpnsettings { 'LOG_VERB' } = $cgiparams { 'LOG_VERB' };
509 $vpnsettings { 'KEEPALIVE_1' } = $cgiparams { 'KEEPALIVE_1' };
510 $vpnsettings { 'KEEPALIVE_2' } = $cgiparams { 'KEEPALIVE_2' };
511 $vpnsettings { 'MAX_CLIENTS' } = $cgiparams { 'MAX_CLIENTS' };
512 $vpnsettings { 'REDIRECT_GW_DEF1' } = $cgiparams { 'REDIRECT_GW_DEF1' };
513 $vpnsettings { 'CLIENT2CLIENT' } = $cgiparams { 'CLIENT2CLIENT' };
514 $vpnsettings { 'DHCP_DOMAIN' } = $cgiparams { 'DHCP_DOMAIN' };
515 $vpnsettings { 'DHCP_DNS' } = $cgiparams { 'DHCP_DNS' };
516 $vpnsettings { 'DHCP_WINS' } = $cgiparams { 'DHCP_WINS' };
517 $vpnsettings { 'ROUTES_PUSH' } = $cgiparams { 'ROUTES_PUSH' };
520 if ( $cgiparams { 'FRAGMENT' } eq '' ) {
521 delete $vpnsettings { 'FRAGMENT' };
523 if ( $cgiparams { 'FRAGMENT' } !~ /^[0-9]+$/ ) {
524 $errormessage = "Incorrect value, please insert only numbers." ;
527 $vpnsettings { 'FRAGMENT' } = $cgiparams { 'FRAGMENT' };
530 if ( $cgiparams { 'MSSFIX' } ne 'on' ) {
531 delete $vpnsettings { 'MSSFIX' };
533 $vpnsettings { 'MSSFIX' } = $cgiparams { 'MSSFIX' };
535 if ( $cgiparams { 'DHCP_DOMAIN' } ne '' ){
536 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_DOMAIN' }) || & General
:: validip
( $cgiparams { 'DHCP_DOMAIN' })) {
537 $errormessage = $Lang :: tr
{ 'invalid input for dhcp domain' };
541 if ( $cgiparams { 'DHCP_DNS' } ne '' ){
542 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_DNS' }) || & General
:: validip
( $cgiparams { 'DHCP_DNS' })) {
543 $errormessage = $Lang :: tr
{ 'invalid input for dhcp dns' };
547 if ( $cgiparams { 'DHCP_WINS' } ne '' ){
548 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_WINS' }) || & General
:: validip
( $cgiparams { 'DHCP_WINS' })) {
549 $errormessage = $Lang :: tr
{ 'invalid input for dhcp wins' };
553 if ( $cgiparams { 'ROUTES_PUSH' } ne '' ){
554 @temp = split ( /\n/ , $cgiparams { 'ROUTES_PUSH' });
555 undef $vpnsettings { 'ROUTES_PUSH' };
558 s/^\s+//g ; s/\s+$//g ;
561 unless (& General
:: validipandmask
( $_ )) {
562 $errormessage = $Lang :: tr
{ 'ovpn errmsg invalid ip or mask' };
565 my ( $ip , $cidr ) = split ( "\/" ,& General
:: ipcidr2msk
( $_ ));
566 if ( $ip eq $netsettings { 'GREEN_NETADDRESS' } && $cidr eq $netsettings { 'GREEN_NETMASK' }) {
567 $errormessage = $Lang :: tr
{ 'ovpn errmsg green already pushed' };
570 $vpnsettings { 'ROUTES_PUSH' } .= $_ . " \n " ;
573 & write_routepushfile
;
574 undef $vpnsettings { 'ROUTES_PUSH' };
576 if (( length ( $cgiparams { 'MAX_CLIENTS' }) == 0 ) || (( $cgiparams { 'MAX_CLIENTS' }) < 1 ) || (( $cgiparams { 'MAX_CLIENTS' }) > 255 )) {
577 $errormessage = $Lang :: tr
{ 'invalid input for max clients' };
580 if ( $cgiparams { 'KEEPALIVE_1' } ne '' ) {
581 if ( $cgiparams { 'KEEPALIVE_1' } !~ /^[0-9]+$/ ) {
582 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 1' };
586 if ( $cgiparams { 'KEEPALIVE_2' } ne '' ){
587 if ( $cgiparams { 'KEEPALIVE_2' } !~ /^[0-9]+$/ ) {
588 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 2' };
592 if ( $cgiparams { 'KEEPALIVE_2' } < ( $cgiparams { 'KEEPALIVE_1' } * 2 )){
593 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 1:2' };
597 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
598 & writeserverconf
(); #hier ok
605 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq 'net' && $cgiparams { 'SIDE' } eq 'server' )
608 my @remsubnet = split ( /\/ /, $cgiparams { 'REMOTE_SUBNET' });
609 my @ovsubnettemp = split ( /\./ , $cgiparams { 'OVPN_SUBNET' });
610 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
613 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
614 unless (- d
"${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" , 0770 or die "Unable to create dir $!" ;}
616 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: $!" ;
619 print SERVERCONF
"# IPFire n2n Open VPN Server Config by ummeegge und m.a.d \n " ;
620 print SERVERCONF
" \n " ;
621 print SERVERCONF
"# User Security \n " ;
622 print SERVERCONF
"user nobody \n " ;
623 print SERVERCONF
"group nobody \n " ;
624 print SERVERCONF
"persist-tun \n " ;
625 print SERVERCONF
"persist-key \n " ;
626 print SERVERCONF
"script-security 2 \n " ;
627 print SERVERCONF
"# IP/DNS for remote Server Gateway \n " ;
628 print SERVERCONF
"remote $cgiparams {'REMOTE'} \n " ;
629 print SERVERCONF
"float \n " ;
630 print SERVERCONF
"# IP adresses of the VPN Subnet \n " ;
631 print SERVERCONF
"ifconfig $ovsubnet .1 $ovsubnet .2 \n " ;
632 print SERVERCONF
"# Client Gateway Network \n " ;
633 print SERVERCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
634 print SERVERCONF
"# tun Device \n " ;
635 print SERVERCONF
"dev tun \n " ;
636 print SERVERCONF
"# Port and Protokol \n " ;
637 print SERVERCONF
"port $cgiparams {'DEST_PORT'} \n " ;
639 if ( $cgiparams { 'PROTOCOL' } eq 'tcp' ) {
640 print SERVERCONF
"proto tcp-server \n " ;
641 print SERVERCONF
"# Packet size \n " ;
642 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1400' } else { $tunmtu = $cgiparams { 'MTU' }};
643 print SERVERCONF
"tun-mtu $tunmtu \n " ;
646 if ( $cgiparams { 'PROTOCOL' } eq 'udp' ) {
647 print SERVERCONF
"proto udp \n " ;
648 print SERVERCONF
"# Paketsize \n " ;
649 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1500' } else { $tunmtu = $cgiparams { 'MTU' }};
650 print SERVERCONF
"tun-mtu $tunmtu \n " ;
651 if ( $cgiparams { 'FRAGMENT' } ne '' ) { print SERVERCONF
"fragment $cgiparams {'FRAGMENT'} \n " ;}
652 if ( $cgiparams { 'MSSFIX' } eq 'on' ) { print SERVERCONF
"mssfix \n " ; };
654 print SERVERCONF
"# Auth. Server \n " ;
655 print SERVERCONF
"tls-server \n " ;
656 print SERVERCONF
"ca ${General::swroot}/ovpn/ca/cacert.pem \n " ;
657 print SERVERCONF
"cert ${General::swroot}/ovpn/certs/servercert.pem \n " ;
658 print SERVERCONF
"key ${General::swroot}/ovpn/certs/serverkey.pem \n " ;
659 print SERVERCONF
"dh ${General::swroot}/ovpn/ca/dh1024.pem \n " ;
660 print SERVERCONF
"# Cipher \n " ;
661 print SERVERCONF
"cipher AES-256-CBC \n " ;
662 if ( $cgiparams { 'COMPLZO' } eq 'on' ) {
663 print SERVERCONF
"# Enable Compression \n " ;
664 print SERVERCONF
"comp-lzo \r\n " ;
666 print SERVERCONF
"# Debug Level \n " ;
667 print SERVERCONF
"verb 3 \n " ;
668 print SERVERCONF
"# Tunnel check \n " ;
669 print SERVERCONF
"keepalive 10 60 \n " ;
670 print SERVERCONF
"# Start as daemon \n " ;
671 print SERVERCONF
"daemon $cgiparams {'NAME'}n2n \n " ;
672 print SERVERCONF
"writepid /var/run/ $cgiparams {'NAME'}n2n.pid \n " ;
673 print SERVERCONF
"# Activate Management Interface and Port \n " ;
674 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) { print SERVERCONF
"management localhost $cgiparams {'DEST_PORT'} \n " }
675 else { print SERVERCONF
"management localhost $cgiparams {'OVPN_MGMT'} \n " };
684 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq 'net' && $cgiparams { 'SIDE' } eq 'client' )
686 my @ovsubnettemp = split ( /\./ , $cgiparams { 'OVPN_SUBNET' });
687 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
688 my @remsubnet = split ( /\/ /, $cgiparams { 'REMOTE_SUBNET' });
691 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
692 unless (- d
"${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" , 0770 or die "Unable to create dir $!" ;}
694 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: $!" ;
697 print CLIENTCONF
"# IPFire rewritten n2n Open VPN Client Config by ummeegge und m.a.d \n " ;
698 print CLIENTCONF
"# \n " ;
699 print CLIENTCONF
"# User Security \n " ;
700 print CLIENTCONF
"user nobody \n " ;
701 print CLIENTCONF
"group nobody \n " ;
702 print CLIENTCONF
"persist-tun \n " ;
703 print CLIENTCONF
"persist-key \n " ;
704 print CLIENTCONF
"script-security 2 \n " ;
705 print CLIENTCONF
"# IP/DNS for remote Server Gateway \n " ;
706 print CLIENTCONF
"remote $cgiparams {'REMOTE'} \n " ;
707 print CLIENTCONF
"float \n " ;
708 print CLIENTCONF
"# IP adresses of the VPN Subnet \n " ;
709 print CLIENTCONF
"ifconfig $ovsubnet .2 $ovsubnet .1 \n " ;
710 print CLIENTCONF
"# Server Gateway Network \n " ;
711 print CLIENTCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
712 print CLIENTCONF
"# tun Device \n " ;
713 print CLIENTCONF
"dev tun \n " ;
714 print CLIENTCONF
"# Port and Protokol \n " ;
715 print CLIENTCONF
"port $cgiparams {'DEST_PORT'} \n " ;
717 if ( $cgiparams { 'PROTOCOL' } eq 'tcp' ) {
718 print CLIENTCONF
"proto tcp-client \n " ;
719 print CLIENTCONF
"# Packet size \n " ;
720 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1400' } else { $tunmtu = $cgiparams { 'MTU' }};
721 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
724 if ( $cgiparams { 'PROTOCOL' } eq 'udp' ) {
725 print CLIENTCONF
"proto udp \n " ;
726 print CLIENTCONF
"# Paketsize \n " ;
727 if ( $cgiparams { 'MTU' } eq '' ) { $tunmtu = '1500' } else { $tunmtu = $cgiparams { 'MTU' }};
728 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
729 if ( $cgiparams { 'FRAGMENT' } ne '' ) { print CLIENTCONF
"fragment $cgiparams {'FRAGMENT'} \n " ;}
730 if ( $cgiparams { 'MSSFIX' } eq 'on' ) { print CLIENTCONF
"mssfix \n " ; };
733 print CLIENTCONF
"ns-cert-type server \n " ;
734 print CLIENTCONF
"# Auth. Client \n " ;
735 print CLIENTCONF
"tls-client \n " ;
736 print CLIENTCONF
"# Cipher \n " ;
737 print CLIENTCONF
"cipher AES-256-CBC \n " ;
738 print CLIENTCONF
"pkcs12 ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12 \r\n " ;
739 if ( $cgiparams { 'COMPLZO' } eq 'on' ) {
740 print CLIENTCONF
"# Enable Compression \n " ;
741 print CLIENTCONF
"comp-lzo \r\n " ;
743 print CLIENTCONF
"# Debug Level \n " ;
744 print CLIENTCONF
"verb 3 \n " ;
745 print CLIENTCONF
"# Tunnel check \n " ;
746 print CLIENTCONF
"keepalive 10 60 \n " ;
747 print CLIENTCONF
"# Start as daemon \n " ;
748 print CLIENTCONF
"daemon $cgiparams {'NAME'}n2n \n " ;
749 print CLIENTCONF
"writepid /var/run/ $cgiparams {'NAME'}n2n.pid \n " ;
750 print CLIENTCONF
"# Activate Management Interface and Port \n " ;
751 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) { print CLIENTCONF
"management localhost $cgiparams {'DEST_PORT'} \n " }
752 else { print CLIENTCONF
"management localhost $cgiparams {'OVPN_MGMT'} \n " };
758 ### Save main settings
762 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
763 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
764 #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too,
765 #DAN this value has to leave.
766 if ( $cgiparams { 'ENABLED' } eq 'on' ){
767 unless (& General
:: validfqdn
( $cgiparams { 'VPN_IP' }) || & General
:: validip
( $cgiparams { 'VPN_IP' })) {
768 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
772 if ( $cgiparams { 'ENABLED' } eq 'on' ){
773 & disallowreserved
( $cgiparams { 'DDEST_PORT' }, 0 , $cgiparams { 'DPROTOCOL' }, "dest" );
775 if ( $errormessage ) { goto SETTINGS_ERROR
; }
778 if ( $cgiparams { 'ENABLED' } eq 'on' ){
779 & checkportfw
( 0 , $cgiparams { 'DDEST_PORT' }, $cgiparams { 'DPROTOCOL' }, '0.0.0.0' );
782 if ( $errormessage ) { goto SETTINGS_ERROR
; }
784 if (! & General
:: validipandmask
( $cgiparams { 'DOVPN_SUBNET' })) {
785 $errormessage = $Lang :: tr
{ 'ovpn subnet is invalid' };
788 my @tmpovpnsubnet = split ( "\/" , $cgiparams { 'DOVPN_SUBNET' });
790 if (& General
:: IpInSubnet
( $netsettings { 'RED_ADDRESS' },
791 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
792 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire RED Network $netsettings {'RED_ADDRESS'}" ;
796 if (& General
:: IpInSubnet
( $netsettings { 'GREEN_ADDRESS' },
797 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
798 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Green Network $netsettings {'GREEN_ADDRESS'}" ;
802 if (& General
:: IpInSubnet
( $netsettings { 'BLUE_ADDRESS' },
803 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
804 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Blue Network $netsettings {'BLUE_ADDRESS'}" ;
808 if (& General
:: IpInSubnet
( $netsettings { 'ORANGE_ADDRESS' },
809 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
810 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Orange Network $netsettings {'ORANGE_ADDRESS'}" ;
813 open ( ALIASES
, "${General::swroot}/ethernet/aliases" ) or die 'Unable to open aliases file.' ;
817 my @tempalias = split ( /\,/ , $_ );
818 if ( $tempalias [ 1 ] eq 'on' ) {
819 if (& General
:: IpInSubnet
( $tempalias [ 0 ] ,
820 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
821 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire alias entry $tempalias [0]" ;
826 if ( $errormessage ne '' ){
829 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
830 $errormessage = $Lang :: tr
{ 'invalid input' };
833 if (( length ( $cgiparams { 'DMTU' })== 0 ) || (( $cgiparams { 'DMTU' }) < 1000 )) {
834 $errormessage = $Lang :: tr
{ 'invalid mtu input' };
838 unless (& General
:: validport
( $cgiparams { 'DDEST_PORT' })) {
839 $errormessage = $Lang :: tr
{ 'invalid port' };
842 $vpnsettings { 'ENABLED_BLUE' } = $cgiparams { 'ENABLED_BLUE' };
843 $vpnsettings { 'ENABLED_ORANGE' } = $cgiparams { 'ENABLED_ORANGE' };
844 $vpnsettings { 'ENABLED' } = $cgiparams { 'ENABLED' };
845 $vpnsettings { 'VPN_IP' } = $cgiparams { 'VPN_IP' };
846 #new settings for daemon
847 $vpnsettings { 'DOVPN_SUBNET' } = $cgiparams { 'DOVPN_SUBNET' };
848 $vpnsettings { 'DDEVICE' } = $cgiparams { 'DDEVICE' };
849 $vpnsettings { 'DPROTOCOL' } = $cgiparams { 'DPROTOCOL' };
850 $vpnsettings { 'DDEST_PORT' } = $cgiparams { 'DDEST_PORT' };
851 $vpnsettings { 'DMTU' } = $cgiparams { 'DMTU' };
852 $vpnsettings { 'DCOMPLZO' } = $cgiparams { 'DCOMPLZO' };
853 $vpnsettings { 'DCIPHER' } = $cgiparams { 'DCIPHER' };
856 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" );}
857 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" );}
858 if ( $vpnsettings { 'ENABLED' } eq 'on' ) { system ( "touch ${General::swroot}/ovpn/enable 2>/dev/null" );} else { system ( "unlink ${General::swroot}/ovpn/enable 2>/dev/null" );}
859 #new settings for daemon
860 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
861 & writeserverconf
(); #hier ok
866 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'reset' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
868 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
870 foreach my $key ( keys %confighash ) {
871 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
872 delete $confighash { $cgiparams { ' $key ' }};
875 while ( $file = glob ( "${General::swroot}/ovpn/ca/*" )) {
878 while ( $file = glob ( "${General::swroot}/ovpn/certs/*" )) {
881 while ( $file = glob ( "${General::swroot}/ovpn/crls/*" )) {
885 if ( open ( FILE
, ">${General::swroot}/ovpn/caconfig" )) {
889 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
894 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'reset' }) {
895 & Header
:: showhttpheaders
();
896 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
897 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
898 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'are you sure' });
900 <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' />
901 <tr><td align='center'>
902 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
903 $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}
904 <tr><td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'reset'}' />
905 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td></tr>
910 & Header
:: closebigbox
();
911 & Header
:: closepage
();
915 ### Upload CA Certificate
917 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
918 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
920 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
921 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
925 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
926 $errormessage = $Lang :: tr
{ 'name too long' };
930 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
931 $errormessage = $Lang :: tr
{ 'name is invalid' };
932 goto UPLOAD_CA_ERROR
;
935 # Check if there is no other entry with this name
936 foreach my $key ( keys %cahash ) {
937 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
938 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
943 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
944 $errormessage = $Lang :: tr
{ 'there was no file upload' };
947 # Move uploaded ca to a temporary file
948 ( my $fh , my $filename ) = tempfile
( );
949 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
953 my $temp = `/usr/bin/openssl x509 -text -in $filename ` ;
954 if ( $temp !~ /CA:TRUE/i ) {
955 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
959 move
( $filename , "${General::swroot}/ovpn/ca/ $cgiparams {'CA_NAME'}cert.pem" );
961 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
967 my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/ $cgiparams {'CA_NAME'}cert.pem` ;
968 $casubject =~ /Subject: (.*)[\n]/ ;
970 $casubject =~ s
+/ Email
+, E
+;
971 $casubject =~ s/ ST=/ S=/ ;
972 $casubject = & Header
:: cleanhtml
( $casubject );
974 my $key = & General
:: findhasharraykey
( \
%cahash );
975 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
976 $cahash { $key }[ 1 ] = $casubject ;
977 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
978 # system('/usr/local/bin/ipsecctrl', 'R');
983 ### Display ca certificate
985 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
986 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
988 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
989 & Header
:: showhttpheaders
();
990 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
991 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
992 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'ca certificate'}:" );
993 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
994 $output = & Header
:: cleanhtml
( $output , "y" );
995 print "<pre> $output </pre> \n " ;
997 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
998 & Header
:: closebigbox
();
999 & Header
:: closepage
();
1002 $errormessage = $Lang :: tr
{ 'invalid key' };
1006 ### Download ca certificate
1008 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
1009 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1011 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1012 print "Content-Type: application/octet-stream \r\n " ;
1013 print "Content-Disposition: filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
1014 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
1017 $errormessage = $Lang :: tr
{ 'invalid key' };
1021 ### Remove ca certificate (step 2)
1023 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
1024 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1025 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1027 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1028 foreach my $key ( keys %confighash ) {
1029 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` ;
1030 if ( $test =~ /: OK/ ) {
1032 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1033 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
1034 # system('/usr/local/bin/ipsecctrl', 'D', $key);
1036 unlink ( "${General::swroot}/ovpn//certs/ $confighash { $key }[1]cert.pem" );
1037 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $key }[1].p12" );
1038 delete $confighash { $key };
1039 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1040 # &writeipsecfiles();
1043 unlink ( "${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
1044 delete $cahash { $cgiparams { 'KEY' }};
1045 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1046 # system('/usr/local/bin/ipsecctrl', 'R');
1048 $errormessage = $Lang :: tr
{ 'invalid key' };
1051 ### Remove ca certificate (step 1)
1053 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
1054 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1055 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1057 my $assignedcerts = 0 ;
1058 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
1059 foreach my $key ( keys %confighash ) {
1060 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` ;
1061 if ( $test =~ /: OK/ ) {
1065 if ( $assignedcerts ) {
1066 & Header
:: showhttpheaders
();
1067 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1068 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
1069 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'are you sure' });
1071 <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' />
1072 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
1073 <tr><td align='center'>
1074 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>: $assignedcerts
1075 $Lang ::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}
1076 <tr><td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
1077 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td></tr>
1081 & Header
:: closebox
();
1082 & Header
:: closebigbox
();
1083 & Header
:: closepage
();
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');
1092 $errormessage = $Lang :: tr
{ 'invalid key' };
1096 ### Display root certificate
1098 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
1099 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
1101 & Header
:: showhttpheaders
();
1102 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1103 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1104 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
1105 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'root certificate'}:" );
1106 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem` ;
1108 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'host certificate'}:" );
1109 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem` ;
1111 $output = & Header
:: cleanhtml
( $output , "y" );
1112 print "<pre> $output </pre> \n " ;
1113 & Header
:: closebox
();
1114 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1115 & Header
:: closebigbox
();
1116 & Header
:: closepage
();
1120 ### Download root certificate
1122 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
1123 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
1124 print "Content-Type: application/octet-stream \r\n " ;
1125 print "Content-Disposition: filename=cacert.pem \r\n\r\n " ;
1126 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/cacert.pem` ;
1131 ### Download host certificate
1133 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
1134 if ( - f
"${General::swroot}/ovpn/certs/servercert.pem" ) {
1135 print "Content-Type: application/octet-stream \r\n " ;
1136 print "Content-Disposition: filename=servercert.pem \r\n\r\n " ;
1137 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/certs/servercert.pem` ;
1141 ### Form for generating a root certificate
1143 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
1144 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
1146 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1147 if (- f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
1148 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
1149 $cgiparams { 'ACTION' } = '' ;
1150 goto ROOTCERT_ERROR
;
1153 if (( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) && - e
"${General::swroot}/red/active" ) {
1154 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
1155 my $ipaddr = < IPADDR
>;
1158 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
1159 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
1160 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
1163 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
1165 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1166 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1167 goto ROOTCERT_ERROR
;
1170 # Move uploaded certificate request to a temporary file
1171 ( my $fh , my $filename ) = tempfile
( );
1172 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1174 goto ROOTCERT_ERROR
;
1177 # Create a temporary dirctory
1178 my $tempdir = tempdir
( CLEANUP
=> 1 );
1180 # Extract the CA certificate from the file
1181 my $pid = open ( OPENSSL
, "|-" );
1182 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1183 if ( $pid ) { # parent
1184 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1185 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1189 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1191 goto ROOTCERT_ERROR
;
1194 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-cacerts' , '-nokeys' ,
1196 '-out' , " $tempdir /cacert.pem" )) {
1197 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1199 goto ROOTCERT_ERROR
;
1203 # Extract the Host certificate from the file
1204 $pid = open ( OPENSSL
, "|-" );
1205 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1206 if ( $pid ) { # parent
1207 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1208 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1212 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1214 goto ROOTCERT_ERROR
;
1217 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-clcerts' , '-nokeys' ,
1219 '-out' , " $tempdir /hostcert.pem" )) {
1220 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1222 goto ROOTCERT_ERROR
;
1226 # Extract the Host key from the file
1227 $pid = open ( OPENSSL
, "|-" );
1228 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1229 if ( $pid ) { # parent
1230 if ( $cgiparams { 'P12_PASS' } ne '' ) {
1231 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
1235 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1237 goto ROOTCERT_ERROR
;
1240 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-nocerts' ,
1243 '-out' , " $tempdir /serverkey.pem" )) {
1244 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1246 goto ROOTCERT_ERROR
;
1250 move
( " $tempdir /cacert.pem" , "${General::swroot}/ovpn/ca/cacert.pem" );
1252 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1254 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1255 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1256 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1257 goto ROOTCERT_ERROR
;
1260 move
( " $tempdir /hostcert.pem" , "${General::swroot}/ovpn/certs/servercert.pem" );
1262 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1264 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1265 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1266 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1267 goto ROOTCERT_ERROR
;
1270 move
( " $tempdir /serverkey.pem" , "${General::swroot}/ovpn/certs/serverkey.pem" );
1272 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
1274 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1275 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1276 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1277 goto ROOTCERT_ERROR
;
1280 goto ROOTCERT_SUCCESS
;
1282 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
1284 # Validate input since the form was submitted
1285 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
1286 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
1287 goto ROOTCERT_ERROR
;
1289 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
1290 $errormessage = $Lang :: tr
{ 'organization too long' };
1291 goto ROOTCERT_ERROR
;
1293 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1294 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1295 goto ROOTCERT_ERROR
;
1297 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
1298 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
1299 goto ROOTCERT_ERROR
;
1301 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
1302 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
1303 goto ROOTCERT_ERROR
;
1305 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
1306 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1307 goto ROOTCERT_ERROR
;
1309 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
1310 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1311 goto ROOTCERT_ERROR
;
1313 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1314 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1315 goto ROOTCERT_ERROR
;
1317 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1318 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1319 goto ROOTCERT_ERROR
;
1321 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1322 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1323 goto ROOTCERT_ERROR
;
1325 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1326 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1327 goto ROOTCERT_ERROR
;
1330 # Copy the cgisettings to vpnsettings and save the configfile
1331 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
1332 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
1333 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
1334 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
1335 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
1336 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
1337 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
1338 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1340 # Replace empty strings with a .
1341 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
1342 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
1343 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
1346 #system ('/bin/touch', "${General::swroot}/ovpn/gencanow");
1348 # Create the CA certificate
1349 my $pid = open ( OPENSSL
, "|-" );
1350 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1351 if ( $pid ) { # parent
1352 print OPENSSL
" $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1353 print OPENSSL
" $state \n " ;
1354 print OPENSSL
" $city \n " ;
1355 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1356 print OPENSSL
" $ou \n " ;
1357 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
1358 print OPENSSL
" $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1361 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1362 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1363 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1364 goto ROOTCERT_ERROR
;
1367 unless ( exec ( '/usr/bin/openssl' , 'req' , '-x509' , '-nodes' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
1368 '-days' , '999999' , '-newkey' , 'rsa:2048' ,
1369 '-keyout' , "${General::swroot}/ovpn/ca/cakey.pem" ,
1370 '-out' , "${General::swroot}/ovpn/ca/cacert.pem" ,
1371 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
1372 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1373 goto ROOTCERT_ERROR
;
1377 # Create the Host certificate request
1378 $pid = open ( OPENSSL
, "|-" );
1379 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1380 if ( $pid ) { # parent
1381 print OPENSSL
" $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1382 print OPENSSL
" $state \n " ;
1383 print OPENSSL
" $city \n " ;
1384 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1385 print OPENSSL
" $ou \n " ;
1386 print OPENSSL
" $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
1387 print OPENSSL
" $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1388 print OPENSSL
". \n " ;
1389 print OPENSSL
". \n " ;
1392 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1393 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1394 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1395 goto ROOTCERT_ERROR
;
1398 unless ( exec ( '/usr/bin/openssl' , 'req' , '-nodes' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
1399 '-newkey' , 'rsa:1024' ,
1400 '-keyout' , "${General::swroot}/ovpn/certs/serverkey.pem" ,
1401 '-out' , "${General::swroot}/ovpn/certs/serverreq.pem" ,
1402 '-extensions' , 'server' ,
1403 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
1404 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1405 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1406 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1407 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1408 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1409 goto ROOTCERT_ERROR
;
1413 # Sign the host certificate request
1414 system ( '/usr/bin/openssl' , 'ca' , '-days' , '999999' ,
1415 '-batch' , '-notext' ,
1416 '-in' , "${General::swroot}/ovpn/certs/serverreq.pem" ,
1417 '-out' , "${General::swroot}/ovpn/certs/servercert.pem" ,
1418 '-extensions' , 'server' ,
1419 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
1421 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1422 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1423 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1424 unlink ( "${General::swroot}/ovpn/serverkey.pem" );
1425 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1426 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1427 & newcleanssldatabase
();
1428 goto ROOTCERT_ERROR
;
1430 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1431 & deletebackupcert
();
1434 # Create an empty CRL
1435 system ( '/usr/bin/openssl' , 'ca' , '-gencrl' ,
1436 '-out' , "${General::swroot}/ovpn/crls/cacrl.pem" ,
1437 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
1439 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1440 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1441 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1442 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1443 unlink ( "${General::swroot}/ovpn/crls/cacrl.pem" );
1444 & cleanssldatabase
();
1445 goto ROOTCERT_ERROR
;
1447 # &cleanssldatabase();
1449 # Create Diffie Hellmann Parameter
1450 system ( '/usr/bin/openssl' , 'dhparam' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
1451 '-out' , "${General::swroot}/ovpn/ca/dh1024.pem" ,
1454 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1455 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1456 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1457 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1458 unlink ( "${General::swroot}/ovpn/crls/cacrl.pem" );
1459 unlink ( "${General::swroot}/ovpn/ca/dh1024.pem" );
1460 & cleanssldatabase
();
1461 goto ROOTCERT_ERROR
;
1463 # &cleanssldatabase();
1465 goto ROOTCERT_SUCCESS
;
1468 if ( $cgiparams { 'ACTION' } ne '' ) {
1469 & Header
:: showhttpheaders
();
1470 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1471 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1472 if ( $errormessage ) {
1473 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
1474 print "<class name='base'> $errormessage " ;
1475 print " </class>" ;
1476 & Header
:: closebox
();
1478 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'generate root/host certificates'}:" );
1480 <form method='post' enctype='multipart/form-data'>
1481 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1482 <tr><td width='30%' class='base'> $Lang ::tr{'organization name'}:</td>
1483 <td width='35%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td>
1484 <td width='35%' colspan='2'> </td></tr>
1485 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}:</td>
1486 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td>
1487 <td colspan='2'> </td></tr>
1488 <tr><td class='base'> $Lang ::tr{'your e-mail'}: <img src='/blob.gif' alt'*' /></td>
1489 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td>
1490 <td colspan='2'> </td></tr>
1491 <tr><td class='base'> $Lang ::tr{'your department'}: <img src='/blob.gif' alt'*' /></td>
1492 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td>
1493 <td colspan='2'> </td></tr>
1494 <tr><td class='base'> $Lang ::tr{'city'}: <img src='/blob.gif' alt'*' /></td>
1495 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td>
1496 <td colspan='2'> </td></tr>
1497 <tr><td class='base'> $Lang ::tr{'state or province'}: <img src='/blob.gif' alt'*' /></td>
1498 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td>
1499 <td colspan='2'> </td></tr>
1500 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1501 <td class='base'><select name='ROOTCERT_COUNTRY'>
1505 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1506 print "<option value=' $Countries ::countries{ $country }'" ;
1507 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1508 print " selected='selected'" ;
1510 print "> $country </option>" ;
1514 <td colspan='2'> </td></tr>
1516 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /></td>
1517 <td> </td><td> </td></tr>
1518 <tr><td class='base' colspan='4' align='left'>
1519 <img src='/blob.gif' valign='top' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
1520 <tr><td class='base' colspan='4' align='left'>
1521 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1522 $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'}
1524 <tr><td colspan='4' bgcolor='#000000'><img src='/images/null.gif' width='1' height='1' border='0' /></td></tr>
1525 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}:</td>
1526 <td nowrap='nowrap'><input type='file' name='FH' size='32'></td>
1527 <td colspan='2'> </td></tr>
1528 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' ></td>
1529 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td>
1530 <td colspan='2'> </td></tr>
1532 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td>
1533 <td colspan='2'> </td></tr>
1534 <tr><td class='base' colspan='4' align='left'>
1535 <img src='/blob.gif' valign='top' al='*' > $Lang ::tr{'this field may be blank'}</td></tr>
1539 & Header
:: closebox
();
1541 & Header
:: closebigbox
();
1542 & Header
:: closepage
();
1547 system ( "chmod 600 ${General::swroot}/ovpn/certs/serverkey.pem" );
1548 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1549 # $vpnsettings{'ENABLE_BLUE'} eq 'on') {
1550 # system('/usr/local/bin/ipsecctrl', 'S');
1554 ### Enable/Disable connection
1561 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1563 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1564 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1565 # my $n2nactive = '';
1566 my $n2nactive = `/bin/ps ax|grep $confighash { $cgiparams {'KEY'}}[1]|grep -v grep|awk \' {print \ $1 } \' ` ;
1568 if ( $confighash { $cgiparams { 'KEY' }}) {
1571 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
1572 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
1573 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1575 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
1576 system ( '/usr/local/bin/openvpnctrl' , '-sn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
1581 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
1582 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1584 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
1585 if ( $n2nactive ne '' ){
1586 system ( '/usr/local/bin/openvpnctrl' , '-kn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
1590 $errormessage = $Lang :: tr
{ 'invalid key' };
1596 ### Download OpenVPN client package
1600 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'dl client arch' }) {
1601 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1602 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1604 my $clientovpn = '' ;
1606 my $tempdir = tempdir
( CLEANUP
=> 1 );
1607 my $zippath = " $tempdir /" ;
1613 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ){
1615 my $zipname = " $confighash { $cgiparams {'KEY'}}[1]-Client.zip" ;
1616 my $zippathname = " $zippath $zipname " ;
1617 $clientovpn = " $confighash { $cgiparams {'KEY'}}[1].conf" ;
1618 my @ovsubnettemp = split ( /\./ , $confighash { $cgiparams { 'KEY' }}[ 27 ]);
1619 my $ovsubnet = " $ovsubnettemp [0]. $ovsubnettemp [1]. $ovsubnettemp [2]" ;
1621 my @remsubnet = split ( /\/ /, $confighash { $cgiparams { 'KEY' }}[ 8 ]);
1622 my $n2nfragment = '' ;
1624 open ( CLIENTCONF
, "> $tempdir / $clientovpn " ) or die "Unable to open tempfile: $!" ;
1625 flock CLIENTCONF
, 2 ;
1627 my $zip = Archive
:: Zip
-> new ();
1628 print CLIENTCONF
"# IPFire n2n Open VPN Client Config by ummeegge und m.a.d \n " ;
1629 print CLIENTCONF
"# \n " ;
1630 print CLIENTCONF
"# User Security \n " ;
1631 print CLIENTCONF
"user nobody \n " ;
1632 print CLIENTCONF
"group nobody \n " ;
1633 print CLIENTCONF
"persist-tun \n " ;
1634 print CLIENTCONF
"persist-key \n " ;
1635 print CLIENTCONF
"script-security 2 \n " ;
1636 print CLIENTCONF
"# IP/DNS for remote Server Gateway \n " ;
1637 print CLIENTCONF
"remote $vpnsettings {'VPN_IP'} \n " ;
1638 print CLIENTCONF
"float \n " ;
1639 print CLIENTCONF
"# IP adresses of the VPN Subnet \n " ;
1640 print CLIENTCONF
"ifconfig $ovsubnet .2 $ovsubnet .1 \n " ;
1641 print CLIENTCONF
"# Server Gateway Network \n " ;
1642 print CLIENTCONF
"route $remsubnet [0] $remsubnet [1] \n " ;
1643 print CLIENTCONF
"# tun Device \n " ;
1644 print CLIENTCONF
"dev $vpnsettings {'DDEVICE'} \n " ;
1645 print CLIENTCONF
"# Port and Protokoll \n " ;
1646 print CLIENTCONF
"port $confighash { $cgiparams {'KEY'}}[29] \n " ;
1648 if ( $confighash { $cgiparams { 'KEY' }}[ 28 ] eq 'tcp' ) {
1649 print CLIENTCONF
"proto tcp-client \n " ;
1650 print CLIENTCONF
"# Packet size \n " ;
1651 if ( $confighash { $cgiparams { 'KEY' }}[ 31 ] eq '' ) { $tunmtu = '1400' } else { $tunmtu = $confighash { $cgiparams { 'KEY' }}[ 31 ]};
1652 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
1655 if ( $confighash { $cgiparams { 'KEY' }}[ 28 ] eq 'udp' ) {
1656 print CLIENTCONF
"proto udp \n " ;
1657 print CLIENTCONF
"# Paketsize \n " ;
1658 if ( $confighash { $cgiparams { 'KEY' }}[ 31 ] eq '' ) { $tunmtu = '1500' } else { $tunmtu = $confighash { $cgiparams { 'KEY' }}[ 31 ]};
1659 print CLIENTCONF
"tun-mtu $tunmtu \n " ;
1660 if ( $confighash { $cgiparams { 'KEY' }}[ 24 ] ne '' ) { print CLIENTCONF
"fragment $confighash { $cgiparams {'KEY'}}[24] \n " ;}
1661 if ( $confighash { $cgiparams { 'KEY' }}[ 23 ] eq 'on' ) { print CLIENTCONF
"mssfix \n " ;}
1663 print CLIENTCONF
"ns-cert-type server \n " ;
1664 print CLIENTCONF
"# Auth. Client \n " ;
1665 print CLIENTCONF
"tls-client \n " ;
1666 print CLIENTCONF
"# Cipher \n " ;
1667 print CLIENTCONF
"cipher AES-256-CBC \n " ;
1668 if ( $confighash { $cgiparams { 'KEY' }}[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ) {
1669 print CLIENTCONF
"pkcs12 ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12 \r\n " ;
1670 $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 " ;
1672 if ( $confighash { $cgiparams { 'KEY' }}[ 30 ] eq 'on' ) {
1673 print CLIENTCONF
"# Enable Compression \n " ;
1674 print CLIENTCONF
"comp-lzo \r\n " ;
1676 print CLIENTCONF
"# Debug Level \n " ;
1677 print CLIENTCONF
"verb 3 \n " ;
1678 print CLIENTCONF
"# Tunnel check \n " ;
1679 print CLIENTCONF
"keepalive 10 60 \n " ;
1680 print CLIENTCONF
"# Start as daemon \n " ;
1681 print CLIENTCONF
"daemon $confighash { $cgiparams {'KEY'}}[1]n2n \n " ;
1682 print CLIENTCONF
"writepid /var/run/ $confighash { $cgiparams {'KEY'}}[1]n2n.pid \n " ;
1683 print CLIENTCONF
"# Activate Management Interface and Port \n " ;
1684 if ( $confighash { $cgiparams { 'KEY' }}[ 22 ] eq '' ) { print CLIENTCONF
"management localhost $confighash { $cgiparams {'KEY'}}[29] \n " }
1685 else { print CLIENTCONF
"management localhost $confighash { $cgiparams {'KEY'}}[22] \n " };
1686 print CLIENTCONF
"# remsub $confighash { $cgiparams {'KEY'}}[11] \n " ;
1691 $zip -> addFile ( " $tempdir / $clientovpn " , $clientovpn ) or die "Can't add file $clientovpn \n " ;
1692 my $status = $zip -> writeToFileNamed ( $zippathname );
1694 open ( DLFILE
, "< $zippathname " ) or die "Unable to open $zippathname : $!" ;
1695 @fileholder = < DLFILE
>;
1696 print "Content-Type:application/x-download \n " ;
1697 print "Content-Disposition:attachment;filename= $zipname \n\n " ;
1703 my $zipname = " $confighash { $cgiparams {'KEY'}}[1]-TO-IPFire.zip" ;
1704 my $zippathname = " $zippath $zipname " ;
1705 $clientovpn = " $confighash { $cgiparams {'KEY'}}[1]-TO-IPFire.ovpn" ;
1711 open ( CLIENTCONF
, "> $tempdir / $clientovpn " ) or die "Unable to open tempfile: $!" ;
1712 flock CLIENTCONF
, 2 ;
1714 my $zip = Archive
:: Zip
-> new ();
1716 print CLIENTCONF
"#OpenVPN Server conf \r\n " ;
1717 print CLIENTCONF
"tls-client \r\n " ;
1718 print CLIENTCONF
"client \r\n " ;
1719 print CLIENTCONF
"dev $vpnsettings {'DDEVICE'} \r\n " ;
1720 print CLIENTCONF
"proto $vpnsettings {'DPROTOCOL'} \r\n " ;
1721 print CLIENTCONF
" $vpnsettings {'DDEVICE'}-mtu $vpnsettings {'DMTU'} \r\n " ;
1722 if ( $vpnsettings { 'ENABLED' } eq 'on' ){
1723 print CLIENTCONF
"remote $vpnsettings {'VPN_IP'} $vpnsettings {'DDEST_PORT'} \r\n " ;
1724 if ( $vpnsettings { 'ENABLED_BLUE' } eq 'on' && (& haveBlueNet
())){
1725 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Blue interface \r\n " ;
1726 print CLIENTCONF
";remote $netsettings {'BLUE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
1728 if ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
1729 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Orange interface \r\n " ;
1730 print CLIENTCONF
";remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
1732 } elsif ( $vpnsettings { 'ENABLED_BLUE' } eq 'on' && (& haveBlueNet
())){
1733 print CLIENTCONF
"remote $netsettings {'BLUE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
1734 if ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
1735 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Orange interface \r\n " ;
1736 print CLIENTCONF
";remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
1738 } elsif ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
1739 print CLIENTCONF
"remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
1742 if ( $confighash { $cgiparams { 'KEY' }}[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ) {
1743 print CLIENTCONF
"pkcs12 $confighash { $cgiparams {'KEY'}}[1].p12 \r\n " ;
1744 $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 " ;
1746 print CLIENTCONF
"ca cacert.pem \r\n " ;
1747 print CLIENTCONF
"cert $confighash { $cgiparams {'KEY'}}[1]cert.pem \r\n " ;
1748 print CLIENTCONF
"key $confighash { $cgiparams {'KEY'}}[1].key \r\n " ;
1749 $zip -> addFile ( "${General::swroot}/ovpn/ca/cacert.pem" , "cacert.pem" ) or die "Can't add file cacert.pem \n " ;
1750 $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 " ;
1752 print CLIENTCONF
"cipher $vpnsettings {DCIPHER} \r\n " ;
1753 if ( $vpnsettings { DCOMPLZO
} eq 'on' ) {
1754 print CLIENTCONF
"comp-lzo \r\n " ;
1756 print CLIENTCONF
"verb 3 \r\n " ;
1757 print CLIENTCONF
"ns-cert-type server \r\n " ;
1758 print CLIENTCONF
"tls-remote $vpnsettings {ROOTCERT_HOSTNAME} \r\n " ;
1759 if ( $vpnsettings { MSSFIX
} eq 'on' ) {
1760 print CLIENTCONF
"mssfix \r\n " ;
1762 if ( $vpnsettings { FRAGMENT
} ne '' && $vpnsettings { DPROTOCOL
} ne 'tcp' ) {
1763 print CLIENTCONF
"fragment $vpnsettings {'FRAGMENT'} \r\n " ;
1767 $zip -> addFile ( " $tempdir / $clientovpn " , $clientovpn ) or die "Can't add file $clientovpn \n " ;
1768 my $status = $zip -> writeToFileNamed ( $zippathname );
1770 open ( DLFILE
, "< $zippathname " ) or die "Unable to open $zippathname : $!" ;
1771 @fileholder = < DLFILE
>;
1772 print "Content-Type:application/x-download \n " ;
1773 print "Content-Disposition:attachment;filename= $zipname \n\n " ;
1781 ### Remove connection
1785 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
1786 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1787 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1789 if ( $confighash { $cgiparams { 'KEY' }}) {
1790 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1791 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
1792 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
1795 my $temp = `/usr/bin/openssl ca -revoke ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf` ;
1801 if ( $confighash { $cgiparams { 'KEY' }}[ 3 ] eq 'net' ) {
1803 my $conffile = glob ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]/ $confighash { $cgiparams {'KEY'}}[1].conf" );
1804 my $certfile = glob ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1805 unlink ( $certfile ) or die "Removing $certfile fail: $!" ;
1806 unlink ( $conffile ) or die "Removing $conffile fail: $!" ;
1807 rmdir ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]" ) || die "Kann Verzeichnis nicht loeschen: $!" ;
1811 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1812 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1813 delete $confighash { $cgiparams { 'KEY' }};
1814 my $temp2 = `/usr/bin/openssl ca -gencrl -out ${General::swroot}/ovpn/crls/cacrl.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf` ;
1815 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1816 #&writeserverconf();
1818 $errormessage = $Lang :: tr
{ 'invalid key' };
1823 ### Download PKCS12 file
1825 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
1826 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1828 print "Content-Disposition: filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
1829 print "Content-Type: application/octet-stream \r\n\r\n " ;
1830 print `/bin/cat ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12` ;
1834 ### Display certificate
1836 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
1837 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1839 if ( - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1840 & Header
:: showhttpheaders
();
1841 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1842 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1843 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'certificate'}:" );
1844 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1845 $output = & Header
:: cleanhtml
( $output , "y" );
1846 print "<pre> $output </pre> \n " ;
1847 & Header
:: closebox
();
1848 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1849 & Header
:: closebigbox
();
1850 & Header
:: closepage
();
1854 ### Display Certificate Revoke List
1856 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show crl' }) {
1857 # &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1859 if ( - f
"${General::swroot}/ovpn/crls/cacrl.pem" ) {
1860 & Header
:: showhttpheaders
();
1861 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1862 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1863 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'crl'}:" );
1864 my $output = `/usr/bin/openssl crl -text -noout -in ${General::swroot}/ovpn/crls/cacrl.pem` ;
1865 $output = & Header
:: cleanhtml
( $output , "y" );
1866 print "<pre> $output </pre> \n " ;
1867 & Header
:: closebox
();
1868 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1869 & Header
:: closebigbox
();
1870 & Header
:: closepage
();
1875 ### Advanced Server Settings
1878 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced server' }) {
1882 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%cgiparams );
1885 # if ($cgiparams{'CLIENT2CLIENT'} eq '') {
1886 # $cgiparams{'CLIENT2CLIENT'} = 'on';
1889 if ( $cgiparams { 'MAX_CLIENTS' } eq '' ) {
1890 $cgiparams { 'MAX_CLIENTS' } = '100' ;
1893 if ( $cgiparams { 'KEEPALIVE_1' } eq '' ) {
1894 $cgiparams { 'KEEPALIVE_1' } = '10' ;
1896 if ( $cgiparams { 'KEEPALIVE_2' } eq '' ) {
1897 $cgiparams { 'KEEPALIVE_2' } = '60' ;
1899 if ( $cgiparams { 'LOG_VERB' } eq '' ) {
1900 $cgiparams { 'LOG_VERB' } = '3' ;
1902 $checked { 'CLIENT2CLIENT' }{ 'off' } = '' ;
1903 $checked { 'CLIENT2CLIENT' }{ 'on' } = '' ;
1904 $checked { 'CLIENT2CLIENT' }{ $cgiparams { 'CLIENT2CLIENT' }} = 'CHECKED' ;
1905 $checked { 'REDIRECT_GW_DEF1' }{ 'off' } = '' ;
1906 $checked { 'REDIRECT_GW_DEF1' }{ 'on' } = '' ;
1907 $checked { 'REDIRECT_GW_DEF1' }{ $cgiparams { 'REDIRECT_GW_DEF1' }} = 'CHECKED' ;
1908 $selected { 'ENGINES' }{ $cgiparams { 'ENGINES' }} = 'SELECTED' ;
1909 $checked { 'MSSFIX' }{ 'off' } = '' ;
1910 $checked { 'MSSFIX' }{ 'on' } = '' ;
1911 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
1912 $selected { 'LOG_VERB' }{ '1' } = '' ;
1913 $selected { 'LOG_VERB' }{ '2' } = '' ;
1914 $selected { 'LOG_VERB' }{ '3' } = '' ;
1915 $selected { 'LOG_VERB' }{ '4' } = '' ;
1916 $selected { 'LOG_VERB' }{ '5' } = '' ;
1917 $selected { 'LOG_VERB' }{ '6' } = '' ;
1918 $selected { 'LOG_VERB' }{ '7' } = '' ;
1919 $selected { 'LOG_VERB' }{ '8' } = '' ;
1920 $selected { 'LOG_VERB' }{ '9' } = '' ;
1921 $selected { 'LOG_VERB' }{ '10' } = '' ;
1922 $selected { 'LOG_VERB' }{ '11' } = '' ;
1923 $selected { 'LOG_VERB' }{ '0' } = '' ;
1924 $selected { 'LOG_VERB' }{ $cgiparams { 'LOG_VERB' }} = 'SELECTED' ;
1928 & Header
:: showhttpheaders
();
1929 & Header
:: openpage
( $Lang :: tr
{ 'status ovpn' }, 1 , '' );
1930 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
1931 if ( $errormessage ) {
1932 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
1933 print "<class name='base'> $errormessage \n " ;
1934 print " </class> \n " ;
1935 & Header
:: closebox
();
1937 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'advanced server' });
1939 <form method='post' enctype='multipart/form-data'>
1940 <table width='100%'>
1942 <td colspan='4'><b> $Lang ::tr{'dhcp-options'}</b></td>
1945 <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
1948 <td class='base'>Domain</td>
1949 <td><input type='TEXT' name='DHCP_DOMAIN' value=' $cgiparams {'DHCP_DOMAIN'}' size='30' /></td>
1952 <td class='base'>DNS</td>
1953 <td><input type='TEXT' name='DHCP_DNS' value=' $cgiparams {'DHCP_DNS'}' size='30' /></td>
1956 <td class='base'>WINS</td>
1957 <td><input type='TEXT' name='DHCP_WINS' value=' $cgiparams {'DHCP_WINS'}' size='30' /></td>
1960 <td colspan='4'><b> $Lang ::tr{'ovpn routes push options'}</b></td>
1963 <td class='base'> $Lang ::tr{'ovpn routes push'}</td>
1965 <textarea name='ROUTES_PUSH' cols='26' rows='6' wrap='off'>
1969 if ( $cgiparams { 'ROUTES_PUSH' } ne '' )
1971 print $cgiparams { 'ROUTES_PUSH' };
1980 <table width='100%'>
1982 <td class'base'><b> $Lang ::tr{'misc-options'}</b></td>
1985 <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='50%'></td>
1988 <td class='base'>Client-To-Client</td>
1989 <td><input type='checkbox' name='CLIENT2CLIENT' $checked {'CLIENT2CLIENT'}{'on'} /></td>
1992 <td class='base'>Redirect-Gateway def1</td>
1993 <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked {'REDIRECT_GW_DEF1'}{'on'} /></td>
1996 <td class='base'>Max-Clients</td>
1997 <td><input type='text' name='MAX_CLIENTS' value=' $cgiparams {'MAX_CLIENTS'}' size='10' /></td>
2000 <td class='base'>Keppalive <br />
2001 (ping/ping-restart)</td>
2002 <td><input type='TEXT' name='KEEPALIVE_1' value=' $cgiparams {'KEEPALIVE_1'}' size='10' /></td>
2003 <td><input type='TEXT' name='KEEPALIVE_2' value=' $cgiparams {'KEEPALIVE_2'}' size='10' /></td>
2006 <td class='base'>fragment <br></td>
2007 <td><input type='TEXT' name='FRAGMENT' value=' $cgiparams {'FRAGMENT'}' size='10' /></td>
2008 <td>Default: <span class="base">1300</span></td>
2011 <td class='base'>mssfix</td>
2012 <td><input type='checkbox' name='MSSFIX' $checked {'MSSFIX'}{'on'} /></td>
2013 <td>Default: on</td>
2019 <table width='100%'>
2021 <td class'base'><b>Crypto-Engines</b></td>
2024 <td width='15%'></td> <td width='30%'> </td><td width='25%'> </td><td width='30%'></td>
2026 <tr><td class='base'>Engines:</td>
2027 <td><select name='ENGINES'><option value="none" $selected {'ENGINES'}{'none'}>none</option>
2028 <option value="cryptodev" $selected {'ENGINES'}{'cryptodev'}>cryptodev</option>
2029 <option value="padlock" $selected {'ENGINES'}{'padlock'}>padlock</option>
2035 <table width='100%'>
2037 <td class'base'><b> $Lang ::tr{'log-options'}</b></td>
2040 <td width='15%'></td> <td width='30%'> </td><td width='25%'> </td><td width='30%'></td>
2043 <tr><td class='base'>VERB</td>
2044 <td><select name='LOG_VERB'><option value='1' $selected {'LOG_VERB'}{'1'}>1</option>
2045 <option value='2' $selected {'LOG_VERB'}{'2'}>2</option>
2046 <option value='3' $selected {'LOG_VERB'}{'3'}>3</option>
2047 <option value='4' $selected {'LOG_VERB'}{'4'}>4</option>
2048 <option value='5' $selected {'LOG_VERB'}{'5'}>5</option>
2049 <option value='6' $selected {'LOG_VERB'}{'6'}>6</option>
2050 <option value='7' $selected {'LOG_VERB'}{'7'}>7</option>
2051 <option value='8' $selected {'LOG_VERB'}{'8'}>8</option>
2052 <option value='9' $selected {'LOG_VERB'}{'9'}>9</option>
2053 <option value='10' $selected {'LOG_VERB'}{'10'}>10</option>
2054 <option value='11' $selected {'LOG_VERB'}{'11'}>11</option>
2055 <option value='0' $selected {'LOG_VERB'}{'0'}>0</option></select></td>
2058 <table width='100%'>
2061 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save-adv-options'}' /></td>
2062 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'cancel-adv-options'}' /></td>
2070 & Header
:: closebox
();
2071 # print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
2072 & Header
:: closebigbox
();
2073 & Header
:: closepage
();
2077 ### Openvpn Connections Statistics
2079 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ovpn con stat' }) {
2080 & Header
:: showhttpheaders
();
2081 & Header
:: openpage
( $Lang :: tr
{ 'ovpn con stat' }, 1 , '' );
2082 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2083 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ovpn con stat' });
2086 # <td><b>$Lang::tr{'protocol'}</b></td>
2087 # protocol temp removed
2089 <table width='100%' border='0' cellpadding='2' cellspacing='0'>
2091 <td><b> $Lang ::tr{'common name'}</b></td>
2092 <td><b> $Lang ::tr{'real address'}</b></td>
2093 <td><b> $Lang ::tr{'virtual address'}</b></td>
2094 <td><b> $Lang ::tr{'loged in at'}</b></td>
2095 <td><b> $Lang ::tr{'bytes sent'}</b></td>
2096 <td><b> $Lang ::tr{'bytes received'}</b></td>
2097 <td><b> $Lang ::tr{'last activity'}</b></td>
2101 my $filename = "/var/log/ovpnserver.log" ;
2102 open ( FILE
, $filename ) or die 'Unable to open config file.' ;
2103 my @current = < FILE
>;
2112 my %userlookup = ();
2113 foreach my $line ( @current )
2116 if ( $line =~ /^Updated,(.+)/ ){
2117 @match = split ( /^Updated,(.+)/ , $line );
2118 $status = $match [ 1 ];
2121 if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ ) {
2122 @match = split ( m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ , $line );
2123 if ( $match [ 1 ] ne "Common Name" ) {
2125 $userlookup { $match [ 2 ]} = $uid ;
2126 $users [ $uid ]{ 'CommonName' } = $match [ 1 ];
2127 $users [ $uid ]{ 'RealAddress' } = $match [ 2 ];
2128 $users [ $uid ]{ 'BytesReceived' } = & sizeformat
( $match [ 3 ]);
2129 $users [ $uid ]{ 'BytesSent' } = & sizeformat
( $match [ 4 ]);
2130 $users [ $uid ]{ 'Since' } = $match [ 5 ];
2131 $users [ $uid ]{ 'Proto' } = $proto ;
2135 if ( $line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/ ) {
2136 @match = split ( m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/ , $line );
2137 if ( $match [ 1 ] ne "Virtual Address" ) {
2138 $address = $match [ 3 ];
2139 #find the uid in the lookup table
2140 $uid = $userlookup { $address };
2141 $users [ $uid ]{ 'VirtualAddress' } = $match [ 1 ];
2142 $users [ $uid ]{ 'LastRef' } = $match [ 4 ];
2148 for ( my $idx = 1 ; $idx <= $user2 ; $idx ++){
2150 print "<tr bgcolor=' $color {'color20'}'> \n " ;
2152 print "<tr bgcolor=' $color {'color22'}'> \n " ;
2154 print "<td align='left'> $users [ $idx -1]{'CommonName'}</td>" ;
2155 print "<td align='left'> $users [ $idx -1]{'RealAddress'}</td>" ;
2156 print "<td align='left'> $users [ $idx -1]{'VirtualAddress'}</td>" ;
2157 print "<td align='left'> $users [ $idx -1]{'Since'}</td>" ;
2158 print "<td align='left'> $users [ $idx -1]{'BytesSent'}</td>" ;
2159 print "<td align='left'> $users [ $idx -1]{'BytesReceived'}</td>" ;
2160 print "<td align='left'> $users [ $idx -1]{'LastRef'}</td>" ;
2161 # print "<td align='left'>$users[$idx-1]{'Proto'}</td>";
2167 <table width='100%' border='0' cellpadding='2' cellspacing='0'>
2172 <tr><td align='center' > $Lang ::tr{'the statistics were last updated at'} <b> $status </b></td></tr>
2176 & Header
:: closebox
();
2177 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2178 & Header
:: closebigbox
();
2179 & Header
:: closepage
();
2183 ### Download Certificate
2185 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
2186 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2188 if ( - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
2189 print "Content-Disposition: filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \r\n " ;
2190 print "Content-Type: application/octet-stream \r\n\r\n " ;
2191 print `/bin/cat ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
2196 ### Enable/Disable connection
2199 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
2201 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2202 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2204 if ( $confighash { $cgiparams { 'KEY' }}) {
2205 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
2206 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
2207 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2208 #&writeserverconf();
2209 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2210 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2211 # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
2214 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
2215 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2216 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2217 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
2219 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2220 #&writeserverconf();
2223 $errormessage = $Lang :: tr
{ 'invalid key' };
2227 ### Restart connection
2229 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
2230 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2231 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2233 if ( $confighash { $cgiparams { 'KEY' }}) {
2234 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2235 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2236 # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
2239 $errormessage = $Lang :: tr
{ 'invalid key' };
2243 ### Remove connection
2245 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
2246 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2247 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2249 if ( $confighash { $cgiparams { 'KEY' }}) {
2250 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2251 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2252 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
2254 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
2255 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
2256 delete $confighash { $cgiparams { 'KEY' }};
2257 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2258 #&writeserverconf();
2260 $errormessage = $Lang :: tr
{ 'invalid key' };
2265 ### Choose between adding a host-net or net-net connection
2272 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
2273 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2274 & Header
:: showhttpheaders
();
2275 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
2276 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
2277 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'connection type' });
2279 if ( - s
"${General::swroot}/ovpn/settings" ) {
2282 <b> $Lang ::tr{'connection type'}:</b><br />
2283 <table><form method='post' ENCTYPE="multipart/form-data">
2284 <tr><td><input type='radio' name='TYPE' value='host' checked /></td>
2285 <td class='base'> $Lang ::tr{'host to net vpn'}</td></tr>
2286 <tr><td><input type='radio' name='TYPE' value='net' /></td>
2287 <td class='base'> $Lang ::tr{'net to net vpn'}</td></tr>
2288 <tr><td><input type='radio' name='TYPE' value='net2net' /></td>
2289 <td class='base'> $Lang ::tr{'net to net vpn'} (Upload Client Package)</td></tr>
2290 <tr><td> </td><td class='base'><input type='file' name='FH' size='30'></td></tr>
2291 <tr><td> </td><td>Import Connection Name <img src='/blob.gif' /></td></tr>
2292 <tr><td> </td><td class='base'><input type='text' name='n2nname' size='30'><td class='base'>Default : Client Packagename</td></td></tr>
2293 <tr><td colspan='3'><hr /></td></tr>
2294 <tr><td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td></tr>
2295 <tr><td> </td></tr>
2296 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
2303 <b> $Lang ::tr{'connection type'}:</b><br />
2304 <table><form method='post' ENCTYPE="multipart/form-data">
2305 <tr><td><input type='radio' name='TYPE' value='host' checked /></td> <td class='base'> $Lang ::tr{'host to net vpn'}</td></tr>
2306 <tr><td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td></tr>
2313 & Header
:: closebox
();
2314 & Header
:: closebigbox
();
2315 & Header
:: closepage
();
2322 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) && ( $cgiparams { 'TYPE' } eq 'net2net' )){
2326 my $uplconffilename = '' ;
2327 my $uplconffilename2 = '' ;
2328 my $uplp12name = '' ;
2329 my $uplp12name2 = '' ;
2336 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2338 # Check if a file is uploaded
2340 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
2341 $errormessage = $Lang :: tr
{ 'there was no file upload' };
2345 # Move uploaded IPfire n2n package to temporary file
2347 ( my $fh , my $filename ) = tempfile
( );
2348 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
2353 my $zip = Archive
:: Zip
-> new ();
2354 my $zipName = $filename ;
2355 my $status = $zip -> read ( $zipName );
2356 if ( $status != AZ_OK
) {
2357 $errormessage = "Read of $zipName failed \n " ;
2361 my $tempdir = tempdir
( CLEANUP
=> 1 );
2362 my @files = $zip -> memberNames ();
2364 $zip -> extractMemberWithoutPaths ( $_ , " $tempdir / $_ " );
2366 my $countfiles = @files ;
2368 # Check if we have not more then 2 files
2370 if ( $countfiles == 2 ){
2372 if ( $_ =~ /.conf$/ ){
2373 $uplconffilename = $_ ;
2375 if ( $_ =~ /.p12$/ ){
2379 if (( $uplconffilename eq '' ) || ( $uplp12name eq '' )){
2380 $errormessage = "Either no *.conf or no *.p12 file found \n " ;
2384 open ( FILE
, " $tempdir / $uplconffilename " ) or die 'Unable to open*.conf file' ;
2385 @firen2nconf = < FILE
>;
2387 chomp ( @firen2nconf );
2391 $errormessage = "Filecount does not match only 2 files are allowed \n " ;
2399 if ( $cgiparams { 'n2nname' } ne '' ){
2401 $uplconffilename2 = " $cgiparams {'n2nname'}.conf" ;
2402 $uplp12name2 = " $cgiparams {'n2nname'}.p12" ;
2403 $n2nname [ 0 ] = $cgiparams { 'n2nname' };
2404 my @n2nname2 = split ( /\./ , $uplconffilename );
2405 $n2nname2 [ 0 ] =~ s/\n|\r//g ;
2406 my $input1 = "${General::swroot}/ovpn/certs/ $uplp12name " ;
2407 my $output1 = "${General::swroot}/ovpn/certs/ $uplp12name2 " ;
2408 my $input2 = " $n2nname2 [0]n2n" ;
2409 my $output2 = " $n2nname [0]n2n" ;
2410 my $filename = " $tempdir / $uplconffilename " ;
2411 open ( FILE
, "< $filename " ) or die 'Unable to open config file.' ;
2412 my @current = < FILE
>;
2414 foreach ( @current ) { s/$input1/$output1/g ;}
2415 foreach ( @current ) { s/$input2/$output2/g ;}
2416 open ( OUT
, "> $filename " ) || die 'Unable to open config file.' ;
2421 $uplconffilename2 = $uplconffilename ;
2422 $uplp12name2 = $uplp12name ;
2423 @n2nname = split ( /\./ , $uplconffilename );
2424 $n2nname [ 0 ] =~ s/\n|\r//g ;
2426 unless (- d
"${General::swroot}/ovpn/n2nconf/" ){ mkdir "${General::swroot}/ovpn/n2nconf" , 0755 or die "Unable to create dir $!" ;}
2427 unless (- d
"${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ){ mkdir "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" , 0770 or die "Unable to create dir $!" ;}
2429 move
( " $tempdir / $uplconffilename " , "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $uplconffilename2 " );
2432 $errormessage = "*.conf move failed: $!" ;
2437 move
( " $tempdir / $uplp12name " , "${General::swroot}/ovpn/certs/ $uplp12name2 " );
2438 chmod 0600 , "${General::swroot}/ovpn/certs/ $uplp12name " ;
2441 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
2449 my @n2nproto2 = split ( / / , ( grep { /^proto/ } @firen2nconf )[ 0 ]);
2450 my @n2nproto = split ( /-/ , $n2nproto2 [ 1 ]);
2451 my @n2nport = split ( / / , ( grep { /^port/ } @firen2nconf )[ 0 ]);
2452 my @n2ntunmtu = split ( / / , ( grep { /^tun-mtu/ } @firen2nconf )[ 0 ]);
2453 my @n2ncomplzo = grep { /^comp-lzo/ } @firen2nconf ;
2454 if ( $n2ncomplzo [ 0 ] =~ /comp-lzo/ ){ $complzoactive = "on" ;} else { $complzoactive = "off" ;}
2455 my @n2nmssfix = grep { /^mssfix/ } @firen2nconf ;
2456 if ( $n2nmssfix [ 0 ] =~ /mssfix/ ){ $mssfixactive = "on" ;} else { $mssfixactive = "off" ;}
2457 #my @n2nmssfix = split(/ /, (grep { /^mssfix/ } @firen2nconf)[0]);
2458 my @n2nfragment = split ( / / , ( grep { /^fragment/ } @firen2nconf )[ 0 ]);
2459 my @n2nremote = split ( / / , ( grep { /^remote/ } @firen2nconf )[ 0 ]);
2460 my @n2novpnsuball = split ( / / , ( grep { /^ifconfig/ } @firen2nconf )[ 0 ]);
2461 my @n2novpnsub = split ( /\./ , $n2novpnsuball [ 1 ]);
2462 my @n2nremsub = split ( / / , ( grep { /^route/ } @firen2nconf )[ 0 ]);
2463 my @n2nmgmt = split ( / / , ( grep { /^management/ } @firen2nconf )[ 0 ]);
2464 my @n2nlocalsub = split ( / / , ( grep { /^# remsub/ } @firen2nconf )[ 0 ]);
2468 # m.a.d delete CR and LF from arrays for this chomp doesnt work
2471 $n2nremote [ 1 ] =~ s/\n|\r//g ;
2472 $n2novpnsub [ 0 ] =~ s/\n|\r//g ;
2473 $n2novpnsub [ 1 ] =~ s/\n|\r//g ;
2474 $n2novpnsub [ 2 ] =~ s/\n|\r//g ;
2475 $n2nproto [ 0 ] =~ s/\n|\r//g ;
2476 $n2nport [ 1 ] =~ s/\n|\r//g ;
2477 $n2ntunmtu [ 1 ] =~ s/\n|\r//g ;
2478 $n2nremsub [ 1 ] =~ s/\n|\r//g ;
2479 $n2nremsub [ 2 ] =~ s/\n|\r//g ;
2480 $n2nlocalsub [ 2 ] =~ s/\n|\r//g ;
2481 $n2nfragment [ 1 ] =~ s/\n|\r//g ;
2482 $n2nmgmt [ 2 ] =~ s/\n|\r//g ;
2483 chomp ( $complzoactive );
2484 chomp ( $mssfixactive );
2491 # Check if there is no other entry with this name
2494 foreach my $dkey ( keys %confighash ) {
2495 if ( $confighash { $dkey }[ 1 ] eq $n2nname [ 0 ]) {
2496 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
2497 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
2498 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
2499 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
2505 # Check if OpenVPN Subnet is valid
2508 foreach my $dkey ( keys %confighash ) {
2509 if ( $confighash { $dkey }[ 27 ] eq " $n2novpnsub [0]. $n2novpnsub [1]. $n2novpnsub [2].0/255.255.255.0" ) {
2510 $errormessage = 'The OpenVPN Subnet is already in use' ;
2511 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
2512 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
2513 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
2519 # Check im Dest Port is vaild
2522 foreach my $dkey ( keys %confighash ) {
2523 if ( $confighash { $dkey }[ 29 ] eq $n2nport [ 1 ] ) {
2524 $errormessage = 'The OpenVPN Port is already in use' ;
2525 unlink ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]/ $n2nname [0].conf" ) or die "Removing Configfile fail: $!" ;
2526 unlink ( "${General::swroot}/ovpn/certs/ $n2nname [0].p12" ) or die "Removing Certfile fail: $!" ;
2527 rmdir ( "${General::swroot}/ovpn/n2nconf/ $n2nname [0]" ) || die "Removing Directory fail: $!" ;
2534 $key = & General
:: findhasharraykey
( \
%confighash );
2536 foreach my $i ( 0 .. 31 ) { $confighash { $key }[ $i ] = "" ;}
2537 $confighash { $key }[ 0 ] = 'off' ;
2538 $confighash { $key }[ 1 ] = $n2nname [ 0 ];
2539 $confighash { $key }[ 2 ] = $n2nname [ 0 ];
2540 $confighash { $key }[ 3 ] = 'net' ;
2541 $confighash { $key }[ 4 ] = 'cert' ;
2542 $confighash { $key }[ 6 ] = 'client' ;
2543 $confighash { $key }[ 8 ] = $n2nlocalsub [ 2 ];
2544 $confighash { $key }[ 10 ] = $n2nremote [ 1 ];
2545 $confighash { $key }[ 11 ] = " $n2nremsub [1]/ $n2nremsub [2]" ;
2546 $confighash { $key }[ 22 ] = $n2nmgmt [ 2 ];
2547 $confighash { $key }[ 23 ] = $mssfixactive ;
2548 $confighash { $key }[ 24 ] = $n2nfragment [ 1 ];
2549 $confighash { $key }[ 25 ] = 'IPFire n2n Client' ;
2550 $confighash { $key }[ 26 ] = 'red' ;
2551 $confighash { $key }[ 27 ] = " $n2novpnsub [0]. $n2novpnsub [1]. $n2novpnsub [2].0/255.255.255.0" ;
2552 $confighash { $key }[ 28 ] = $n2nproto [ 0 ];
2553 $confighash { $key }[ 29 ] = $n2nport [ 1 ];
2554 $confighash { $key }[ 30 ] = $complzoactive ;
2555 $confighash { $key }[ 31 ] = $n2ntunmtu [ 1 ];
2558 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2562 & Header
:: showhttpheaders
();
2563 & Header
:: openpage
( 'Validate imported configuration' , 1 , '' );
2564 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
2565 if ( $errormessage ) {
2566 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
2567 print "<class name='base'> $errormessage " ;
2568 print " </class>" ;
2569 & Header
:: closebox
();
2573 & Header
:: openbox
( '100%' , 'LEFT' , 'import ipfire net2net config' );
2575 if ( $errormessage eq '' ){
2577 <!-- ipfire net2net config gui -->
2578 <table width='100%'>
2579 <tr><td width='25%'> </td><td width='25%'> </td></tr>
2580 <tr><td class='boldbase'> $Lang ::tr{'name'}:</td><td><b> $n2nname [0]</b></td></tr>
2581 <tr><td> </td><td> </td></tr>
2582 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'Act as'}</td><td><b> $confighash { $key }[6]</b></td></tr>
2583 <tr><td class='boldbase' nowrap='nowrap'>Remote Host </td><td><b> $confighash { $key }[10]</b></td></tr>
2584 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'}</td><td><b> $confighash { $key }[8]</b></td></tr>
2585 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'}</td><td><b> $confighash { $key }[11]</b></td></tr>
2586 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn subnet'}</td><td><b> $confighash { $key }[27]</b></td></tr>
2587 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td><td><b> $confighash { $key }[28]</b></td></tr>
2588 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'destination port'}:</td><td><b> $confighash { $key }[29]</b></td></tr>
2589 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'}</td><td><b> $confighash { $key }[30]</b></td></tr>
2590 <tr><td class='boldbase' nowrap='nowrap'>MSSFIX </td><td><b> $confighash { $key }[23]</b></td></tr>
2591 <tr><td class='boldbase' nowrap='nowrap'>Fragment </td><td><b> $confighash { $key }[24]</b></td></tr>
2592 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'}</td><td><b> $confighash { $key }[31]</b></td></tr>
2593 <tr><td class='boldbase' nowrap='nowrap'>Management Port </td><td><b> $confighash { $key }[22]</b></td></tr>
2594 <tr><td> </td><td> </td></tr>
2598 & Header
:: closebox
();
2601 if ( $errormessage ) {
2602 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
2604 print "<div align='center'><form method='post' ENCTYPE='multipart/form-data'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' />" ;
2605 print "<input type='hidden' name='TYPE' value='net2netakn' />" ;
2606 print "<input type='hidden' name='KEY' value=' $key ' />" ;
2607 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
2609 & Header
:: closebigbox
();
2610 & Header
:: closepage
();
2615 ### Accept IPFire n2n Package Settings
2618 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) && ( $cgiparams { 'TYPE' } eq 'net2netakn' )){
2621 ### Discard and Rollback IPFire n2n Package Settings
2624 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'cancel' }) && ( $cgiparams { 'TYPE' } eq 'net2netakn' )){
2626 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2628 if ( $confighash { $cgiparams { 'KEY' }}) {
2630 my $conffile = glob ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]/ $confighash { $cgiparams {'KEY'}}[1].conf" );
2631 my $certfile = glob ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
2632 unlink ( $certfile ) or die "Removing $certfile fail: $!" ;
2633 unlink ( $conffile ) or die "Removing $conffile fail: $!" ;
2634 rmdir ( "${General::swroot}/ovpn/n2nconf/ $confighash { $cgiparams {'KEY'}}[1]" ) || die "Kann Verzeichnis nicht loeschen: $!" ;
2635 delete $confighash { $cgiparams { 'KEY' }};
2636 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2639 $errormessage = $Lang :: tr
{ 'invalid key' };
2649 ### Adding a new connection
2651 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
2652 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
2653 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
2655 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
2656 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
2657 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2659 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
2660 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
2661 $errormessage = $Lang :: tr
{ 'invalid key' };
2664 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
2665 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
2666 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
2667 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
2668 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
2669 $cgiparams { 'SIDE' } = $confighash { $cgiparams { 'KEY' }}[ 6 ];
2670 $cgiparams { 'LOCAL_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 8 ];
2671 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
2672 $cgiparams { 'REMOTE_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 11 ];
2673 # n2n m.a.d new fields
2674 $cgiparams { 'OVPN_MGMT' } = $confighash { $cgiparams { 'KEY' }}[ 22 ];
2675 $cgiparams { 'MSSFIX' } = $confighash { $cgiparams { 'KEY' }}[ 23 ];
2676 $cgiparams { 'FRAGMENT' } = $confighash { $cgiparams { 'KEY' }}[ 24 ];
2677 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
2678 $cgiparams { 'INTERFACE' } = $confighash { $cgiparams { 'KEY' }}[ 26 ];
2680 $cgiparams { 'OVPN_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
2681 $cgiparams { 'PROTOCOL' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
2682 $cgiparams { 'DEST_PORT' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
2683 $cgiparams { 'COMPLZO' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
2684 $cgiparams { 'MTU' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
2687 #ab hiere error uebernehmen
2689 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
2690 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
2692 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
2693 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
2694 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2695 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2696 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2702 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
2703 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
2704 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2705 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2706 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2711 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
2712 $errormessage = $Lang :: tr
{ 'name is invalid' };
2713 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2714 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2715 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2720 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
2721 $errormessage = $Lang :: tr
{ 'name too long' };
2722 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2723 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2724 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2733 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2735 if ( $cgiparams { 'DEST_PORT' } eq $vpnsettings { 'DDEST_PORT' }) {
2736 $errormessage = $Lang :: tr
{ 'openvpn destination port used' };
2737 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2738 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2742 if ( $cgiparams { 'DEST_PORT' } eq '' ) {
2743 $errormessage = $Lang :: tr
{ 'openvpn destination port used' };
2744 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2745 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2749 if ( $cgiparams { 'OVPN_SUBNET' } eq $vpnsettings { 'DOVPN_SUBNET' }) {
2750 $errormessage = $Lang :: tr
{ 'openvpn subnet is used' };
2751 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2752 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2756 if (( $cgiparams { 'PROTOCOL' } eq 'tcp' ) && ( $cgiparams { 'MSSFIX' } eq 'on' )) {
2757 $errormessage = $Lang :: tr
{ 'openvpn mssfix allowed with udp' };
2758 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2759 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2763 if (( $cgiparams { 'PROTOCOL' } eq 'tcp' ) && ( $cgiparams { 'FRAGMENT' } ne '' )) {
2764 $errormessage = $Lang :: tr
{ 'openvpn fragment allowed with udp' };
2765 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2766 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2770 if ( & validdotmask
( $cgiparams { 'LOCAL_SUBNET' })) {
2771 $errormessage = $Lang :: tr
{ 'openvpn prefix local subnet' };
2772 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2773 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2777 if ( & validdotmask
( $cgiparams { 'OVPN_SUBNET' })) {
2778 $errormessage = $Lang :: tr
{ 'openvpn prefix openvpn subnet' };
2779 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2780 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2784 if ( & validdotmask
( $cgiparams { 'REMOTE_SUBNET' })) {
2785 $errormessage = $Lang :: tr
{ 'openvpn prefix remote subnet' };
2786 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2787 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2791 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) {
2792 $cgiparams { 'OVPN_MGMT' } = $cgiparams { 'DEST_PORT' };
2797 # if (($cgiparams{'TYPE'} eq 'net') && ($cgiparams{'SIDE'} !~ /^(left|right)$/)) {
2798 # $errormessage = $Lang::tr{'ipfire side is invalid'};
2799 # goto VPNCONF_ERROR;
2802 # Check if there is no other entry with this name
2803 if (! $cgiparams { 'KEY' }) {
2804 foreach my $key ( keys %confighash ) {
2805 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
2806 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
2807 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2808 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2809 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2816 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! $cgiparams { 'REMOTE' })) {
2817 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
2818 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2819 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2820 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2825 if ( $cgiparams { 'REMOTE' }) {
2826 if (! & General
:: validip
( $cgiparams { 'REMOTE' })) {
2827 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
2828 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
2829 if ( $cgiparams { 'TYPE' } eq 'net' ) {
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 (& valid_dns_host
( $cgiparams { 'REMOTE' })) {
2836 $warnmessage = " $Lang ::tr{'check vpn lr'} $cgiparams {'REMOTE'}. $Lang ::tr{'dns check failed'}" ;
2837 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2844 if ( $cgiparams { 'TYPE' } ne 'host' ) {
2845 unless (& General
:: validipandmask
( $cgiparams { 'LOCAL_SUBNET' })) {
2846 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
2847 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2848 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2849 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2851 goto VPNCONF_ERROR
;}
2853 # Check if there is no other entry without IP-address and PSK
2854 if ( $cgiparams { 'REMOTE' } eq '' ) {
2855 foreach my $key ( keys %confighash ) {
2856 if (( $cgiparams { 'KEY' } ne $key ) &&
2857 ( $confighash { $key }[ 4 ] eq 'psk' || $cgiparams { 'AUTH' } eq 'psk' ) &&
2858 $confighash { $key }[ 10 ] eq '' ) {
2859 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
2864 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! & General
:: validipandmask
( $cgiparams { 'REMOTE_SUBNET' }))) {
2865 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
2866 unlink ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}/ $cgiparams {'NAME'}.conf" ) or die "Removing Configfile fail: $!" ;
2867 rmdir ( "${General::swroot}/ovpn/n2nconf/ $cgiparams {'NAME'}" ) || die "Removing Directory fail: $!" ;
2871 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
2872 $errormessage = $Lang :: tr
{ 'invalid input' };
2875 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
2876 $errormessage = $Lang :: tr
{ 'invalid input' };
2881 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
2882 # if (! length($cgiparams{'PSK'}) ) {
2883 # $errormessage = $Lang::tr{'pre-shared key is too short'};
2884 # goto VPNCONF_ERROR;
2886 # if ($cgiparams{'PSK'} =~ /['",&]/) {
2887 # $errormessage = $Lang::tr{'invalid characters found in pre-shared key'};
2888 # goto VPNCONF_ERROR;
2890 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
2891 if ( $cgiparams { 'KEY' }) {
2892 $errormessage = $Lang :: tr
{ 'cant change certificates' };
2895 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
2896 $errormessage = $Lang :: tr
{ 'there was no file upload' };
2900 # Move uploaded certificate request to a temporary file
2901 ( my $fh , my $filename ) = tempfile
( );
2902 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
2907 # Sign the certificate request and move it
2908 # Sign the host certificate request
2909 system ( '/usr/bin/openssl' , 'ca' , '-days' , '999999' ,
2910 '-batch' , '-notext' ,
2912 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
2913 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
2915 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
2917 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
2918 & newcleanssldatabase
();
2922 & deletebackupcert
();
2925 my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem` ;
2926 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
2928 $temp =~ s
+/ Email
+, E
+;
2929 $temp =~ s/ ST=/ S=/ ;
2930 $cgiparams { 'CERT_NAME' } = $temp ;
2931 $cgiparams { 'CERT_NAME' } =~ s/,//g ;
2932 $cgiparams { 'CERT_NAME' } =~ s/\'//g ;
2933 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
2934 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
2937 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
2938 if ( $cgiparams { 'KEY' }) {
2939 $errormessage = $Lang :: tr
{ 'cant change certificates' };
2942 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
2943 $errormessage = $Lang :: tr
{ 'there was no file upload' };
2946 # Move uploaded certificate to a temporary file
2947 ( my $fh , my $filename ) = tempfile
( );
2948 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
2953 # Verify the certificate has a valid CA and move it
2955 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/cacert.pem $filename ` ;
2956 if ( $test =~ /: OK/ ) {
2959 foreach my $key ( keys %cahash ) {
2960 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/ $cahash { $key }[0]cert.pem $filename ` ;
2961 if ( $test =~ /: OK/ ) {
2967 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
2971 move
( $filename , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
2973 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
2979 my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem` ;
2980 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
2982 $temp =~ s
+/ Email
+, E
+;
2983 $temp =~ s/ ST=/ S=/ ;
2984 $cgiparams { 'CERT_NAME' } = $temp ;
2985 $cgiparams { 'CERT_NAME' } =~ s/,//g ;
2986 $cgiparams { 'CERT_NAME' } =~ s/\'//g ;
2987 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
2988 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
2989 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
2992 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
2993 if ( $cgiparams { 'KEY' }) {
2994 $errormessage = $Lang :: tr
{ 'cant change certificates' };
2997 # Validate input since the form was submitted
2998 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
2999 $errormessage = $Lang :: tr
{ 'name too long' };
3002 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
3003 $errormessage = $Lang :: tr
{ 'invalid input for name' };
3006 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
3007 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
3010 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
3011 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
3014 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
3015 $errormessage = $Lang :: tr
{ 'invalid input for department' };
3018 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
3019 $errormessage = $Lang :: tr
{ 'organization too long' };
3022 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
3023 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
3026 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
3027 $errormessage = $Lang :: tr
{ 'invalid input for city' };
3030 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
3031 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
3034 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
3035 $errormessage = $Lang :: tr
{ 'invalid input for country' };
3038 if ( $cgiparams { 'CERT_PASS1' } ne '' && $cgiparams { 'CERT_PASS2' } ne '' ){
3039 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
3040 $errormessage = $Lang :: tr
{ 'password too short' };
3044 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
3045 $errormessage = $Lang :: tr
{ 'passwords do not match' };
3049 # Replace empty strings with a .
3050 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
3051 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
3052 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
3054 # Create the Host certificate request client
3055 my $pid = open ( OPENSSL
, "|-" );
3056 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto VPNCONF_ERROR
;};
3057 if ( $pid ) { # parent
3058 print OPENSSL
" $cgiparams {'CERT_COUNTRY'} \n " ;
3059 print OPENSSL
" $state \n " ;
3060 print OPENSSL
" $city \n " ;
3061 print OPENSSL
" $cgiparams {'CERT_ORGANIZATION'} \n " ;
3062 print OPENSSL
" $ou \n " ;
3063 print OPENSSL
" $cgiparams {'CERT_NAME'} \n " ;
3064 print OPENSSL
" $cgiparams {'CERT_EMAIL'} \n " ;
3065 print OPENSSL
". \n " ;
3066 print OPENSSL
". \n " ;
3069 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
3070 unlink ( "${General::swroot}ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3071 unlink ( "${General::swroot}ovpn/certs/ $cgiparams {'NAME'}req.pem" );
3075 unless ( exec ( '/usr/bin/openssl' , 'req' , '-nodes' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
3076 '-newkey' , 'rsa:1024' ,
3077 '-keyout' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" ,
3078 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" ,
3079 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
3080 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
3081 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3082 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
3087 # Sign the host certificate request
3088 system ( '/usr/bin/openssl' , 'ca' , '-days' , '999999' ,
3089 '-batch' , '-notext' ,
3090 '-in' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" ,
3091 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
3092 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
3094 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
3095 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3096 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
3097 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3098 & newcleanssldatabase
();
3101 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
3102 & deletebackupcert
();
3105 # Create the pkcs12 file
3106 system ( '/usr/bin/openssl' , 'pkcs12' , '-export' ,
3107 '-inkey' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" ,
3108 '-in' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
3109 '-name' , $cgiparams { 'NAME' },
3110 '-passout' , "pass: $cgiparams {'CERT_PASS1'}" ,
3111 '-certfile' , "${General::swroot}/ovpn/ca/cacert.pem" ,
3112 '-caname' , " $vpnsettings {'ROOTCERT_ORGANIZATION'} CA" ,
3113 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12" );
3115 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
3116 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3117 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
3118 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12" );
3121 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
3123 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
3124 ; # Nothing, just editing
3126 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
3130 # Check if there is no other entry with this common name
3131 if ((! $cgiparams { 'KEY' }) && ( $cgiparams { 'AUTH' } ne 'psk' )) {
3132 foreach my $key ( keys %confighash ) {
3133 if ( $confighash { $key }[ 2 ] eq $cgiparams { 'CERT_NAME' }) {
3134 $errormessage = $Lang :: tr
{ 'a connection with this common name already exists' };
3141 my $key = $cgiparams { 'KEY' };
3143 $key = & General
:: findhasharraykey
( \
%confighash );
3144 foreach my $i ( 0 .. 31 ) { $confighash { $key }[ $i ] = "" ;}
3146 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
3147 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
3148 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
3149 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
3151 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
3152 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
3153 $confighash { $key }[ 4 ] = 'psk' ;
3154 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
3156 $confighash { $key }[ 4 ] = 'cert' ;
3158 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3159 $confighash { $key }[ 6 ] = $cgiparams { 'SIDE' };
3160 $confighash { $key }[ 11 ] = $cgiparams { 'REMOTE_SUBNET' };
3162 $confighash { $key }[ 8 ] = $cgiparams { 'LOCAL_SUBNET' };
3163 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
3164 if ( $cgiparams { 'OVPN_MGMT' } eq '' ) {
3165 $confighash { $key }[ 22 ] = $confighash { $key }[ 29 ];
3167 $confighash { $key }[ 22 ] = $cgiparams { 'OVPN_MGMT' };
3169 $confighash { $key }[ 23 ] = $cgiparams { 'MSSFIX' };
3170 $confighash { $key }[ 24 ] = $cgiparams { 'FRAGMENT' };
3171 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
3172 $confighash { $key }[ 26 ] = $cgiparams { 'INTERFACE' };
3174 $confighash { $key }[ 27 ] = $cgiparams { 'OVPN_SUBNET' };
3175 $confighash { $key }[ 28 ] = $cgiparams { 'PROTOCOL' };
3176 $confighash { $key }[ 29 ] = $cgiparams { 'DEST_PORT' };
3177 $confighash { $key }[ 30 ] = $cgiparams { 'COMPLZO' };
3178 $confighash { $key }[ 31 ] = $cgiparams { 'MTU' };
3180 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3186 if ( $cgiparams { 'TYPE' } eq 'net' ) {
3188 if (- e
"/var/run/ $confighash { $key }[1]n2n.pid" ) {
3189 system ( '/usr/local/bin/openvpnctrl' , '-kn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
3191 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3192 my $key = $cgiparams { 'KEY' };
3194 $key = & General
:: findhasharraykey
( \
%confighash );
3195 foreach my $i ( 0 .. 31 ) { $confighash { $key }[ $i ] = "" ;}
3197 $confighash { $key }[ 0 ] = 'on' ;
3198 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3200 system ( '/usr/local/bin/openvpnctrl' , '-sn2n' , $confighash { $cgiparams { 'KEY' }}[ 1 ]);
3208 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
3209 $cgiparams { 'KEY' } = $key ;
3210 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
3214 $cgiparams { 'ENABLED' } = 'on' ;
3218 $cgiparams { 'MSSFIX' } = 'on' ;
3219 $cgiparams { 'FRAGMENT' } = '1300' ;
3223 $cgiparams { 'SIDE' } = 'left' ;
3224 if ( ! - f
"${General::swroot}/ovpn/ca/cakey.pem" ) {
3225 $cgiparams { 'AUTH' } = 'psk' ;
3226 } elsif ( ! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
3227 $cgiparams { 'AUTH' } = 'certfile' ;
3229 $cgiparams { 'AUTH' } = 'certgen' ;
3231 $cgiparams { 'LOCAL_SUBNET' } = " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" ;
3232 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
3233 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
3234 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
3235 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
3239 $checked { 'ENABLED' }{ 'off' } = '' ;
3240 $checked { 'ENABLED' }{ 'on' } = '' ;
3241 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = 'CHECKED' ;
3242 $checked { 'ENABLED_BLUE' }{ 'off' } = '' ;
3243 $checked { 'ENABLED_BLUE' }{ 'on' } = '' ;
3244 $checked { 'ENABLED_BLUE' }{ $cgiparams { 'ENABLED_BLUE' }} = 'CHECKED' ;
3245 $checked { 'ENABLED_ORANGE' }{ 'off' } = '' ;
3246 $checked { 'ENABLED_ORANGE' }{ 'on' } = '' ;
3247 $checked { 'ENABLED_ORANGE' }{ $cgiparams { 'ENABLED_ORANGE' }} = 'CHECKED' ;
3250 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
3251 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
3252 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = 'CHECKED' ;
3254 $selected { 'SIDE' }{ 'server' } = '' ;
3255 $selected { 'SIDE' }{ 'client' } = '' ;
3256 $selected { 'SIDE' }{ $cgiparams { 'SIDE' }} = 'SELECTED' ;
3258 $selected { 'PROTOCOL' }{ 'udp' } = '' ;
3259 $selected { 'PROTOCOL' }{ 'tcp' } = '' ;
3260 $selected { 'PROTOCOL' }{ $cgiparams { 'PROTOCOL' }} = 'SELECTED' ;
3263 $checked { 'AUTH' }{ 'psk' } = '' ;
3264 $checked { 'AUTH' }{ 'certreq' } = '' ;
3265 $checked { 'AUTH' }{ 'certgen' } = '' ;
3266 $checked { 'AUTH' }{ 'certfile' } = '' ;
3267 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = 'CHECKED' ;
3269 $selected { 'INTERFACE' }{ $cgiparams { 'INTERFACE' }} = 'SELECTED' ;
3271 $checked { 'COMPLZO' }{ 'off' } = '' ;
3272 $checked { 'COMPLZO' }{ 'on' } = '' ;
3273 $checked { 'COMPLZO' }{ $cgiparams { 'COMPLZO' }} = 'CHECKED' ;
3275 $checked { 'MSSFIX' }{ 'off' } = '' ;
3276 $checked { 'MSSFIX' }{ 'on' } = '' ;
3277 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
3281 & Header
:: showhttpheaders
();
3282 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
3283 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
3284 if ( $errormessage ) {
3285 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
3286 print "<class name='base'> $errormessage " ;
3287 print " </class>" ;
3288 & Header
:: closebox
();
3292 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'warning messages'}:" );
3293 print "<class name='base'> $warnmessage " ;
3294 print " </class>" ;
3295 & Header
:: closebox
();
3298 print "<form method='post' enctype='multipart/form-data'>" ;
3299 print "<input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />" ;
3301 if ( $cgiparams { 'KEY' }) {
3302 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
3303 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
3306 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'connection'}:" );
3307 print "<table width='100%'> \n " ;
3308 print "<tr><td width='25%' class='boldbase'> $Lang ::tr{'name'}:</td>" ;
3309 if ( $cgiparams { 'TYPE' } eq 'host' ) {
3310 if ( $cgiparams { 'KEY' }) {
3311 print "<td width='35%' class='base'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /> $cgiparams {'NAME'}</td> \n " ;
3313 print "<td width='35%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' maxlength='20' size='30' /></td>" ;
3315 # print "<tr><td>$Lang::tr{'interface'}</td>";
3316 # print "<td><select name='INTERFACE'>";
3317 # print "<option value='RED' $selected{'INTERFACE'}{'RED'}>RED</option>";
3318 # if ($netsettings{'BLUE_DEV'} ne '') {
3319 # print "<option value='BLUE' $selected{'INTERFACE'}{'BLUE'}>BLUE</option>";
3321 # print "<option value='GREEN' $selected{'INTERFACE'}{'GREEN'}>GREEN</option>";
3322 # print "<option value='ORANGE' $selected{'INTERFACE'}{'ORANGE'}>ORANGE</option>";
3323 # print "</select></td></tr>";
3326 print "<input type='hidden' name='INTERFACE' value='red' />" ;
3327 if ( $cgiparams { 'KEY' }) {
3328 print "<td width='25%' class='base' nowrap='nowrap'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /> $cgiparams {'NAME'}</td>" ;
3330 print "<td width='25%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' maxlength='20' /></td>" ;
3333 <td width='25%'> </td>
3334 <td width='25%'> </td></tr>
3335 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'Act as'}</td>
3336 <td><select name='SIDE'><option value='server' $selected {'SIDE'}{'server'}> $Lang ::tr{'openvpn server'}</option>
3337 <option value='client' $selected {'SIDE'}{'client'}> $Lang ::tr{'openvpn client'}</option></select></td>
3338 <td class='boldbase'> $Lang ::tr{'remote host/ip'}:</td>
3339 <td><input type='TEXT' name='REMOTE' value=' $cgiparams {'REMOTE'}' /></td></tr>
3340 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'}</td>
3341 <td><input type='TEXT' name='LOCAL_SUBNET' value=' $cgiparams {'LOCAL_SUBNET'}' /></td>
3342 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'}</td>
3343 <td><input type='text' name='REMOTE_SUBNET' value=' $cgiparams {'REMOTE_SUBNET'}' /></td></tr>
3344 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn subnet'}</td>
3345 <td><input type='TEXT' name='OVPN_SUBNET' value=' $cgiparams {'OVPN_SUBNET'}' /></td></tr>
3346 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td>
3348 <td><select name='PROTOCOL'><option value='udp' $selected {'PROTOCOL'}{'udp'}>UDP</option>
3349 <option value='tcp' $selected {'PROTOCOL'}{'tcp'}>TCP</option></select></td>
3351 <td class='boldbase'> $Lang ::tr{'destination port'}:</td>
3352 <td><input type='TEXT' name='DEST_PORT' value=' $cgiparams {'DEST_PORT'}' size='5' /></td></tr>
3353 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'} <img src='/blob.gif'</td>
3354 <td><input type='checkbox' name='COMPLZO' $checked {'COMPLZO'}{'on'} /></td>
3356 <tr><td class='boldbase' nowrap='nowrap'>mssfix <img src='/blob.gif' /></td>
3357 <td><input type='checkbox' name='MSSFIX' $checked {'MSSFIX'}{'on'} /></td>
3358 <td> $Lang ::tr{'openvpn default'}: <span class="base">on</span></td>
3360 <tr><td class='boldbase' nowrap='nowrap'>fragment <img src='/blob.gif' /></td>
3361 <td><input type='TEXT' name='FRAGMENT' VALUE=' $cgiparams {'FRAGMENT'}'size='5' /></td>
3362 <td> $Lang ::tr{'openvpn default'}: <span class="base">1300</span></td>
3364 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'} <img src='/blob.gif' /></td>
3365 <td> <input type='TEXT' name='MTU' VALUE=' $cgiparams {'MTU'}'size='5' /></td>
3366 <td colspan='2'> $Lang ::tr{'openvpn default'}: udp/tcp <span class="base">1500/1400</span></td>
3368 <tr><td class='boldbase' nowrap='nowrap'>Management Port <img src='/blob.gif' /></td>
3369 <td> <input type='TEXT' name='OVPN_MGMT' VALUE=' $cgiparams {'OVPN_MGMT'}'size='5' /></td>
3370 <td colspan='2'> $Lang ::tr{'openvpn default'}: <span class="base"> $Lang ::tr{'destination port'}</span></td>
3376 print "<tr><td class='boldbase'> $Lang ::tr{'remark title'} <img src='/blob.gif' /></td>" ;
3377 print "<td colspan='3'><input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' size='55' maxlength='50' /></td></tr>" ;
3379 if ( $cgiparams { 'TYPE' } eq 'host' ) {
3381 print "<tr><td> $Lang ::tr{'enabled'} <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td> \n " ;
3384 # if ($cgiparams{'KEY'}) {
3385 # print "<td colspan='3'> </td></tr></table>";
3387 # print "<td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked{'EDIT_ADVANCED'}{'on'} /> $Lang::tr{'edit advanced settings when done'}</tr></table>";
3390 print "<td colspan='3'> </td></tr></table>" ;
3395 & Header
:: closebox
();
3397 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
3398 # &Header::openbox('100%', 'LEFT', $Lang::tr{'authentication'});
3400 # <table width='100%' cellpadding='0' cellspacing='5' border='0'>
3401 # <tr><td class='base' width='50%'>$Lang::tr{'use a pre-shared key'}</td>
3402 # <td class='base' width='50%'><input type='text' name='PSK' size='30' value='$cgiparams{'PSK'}' /></td></tr>
3406 # &Header::closebox();
3407 } elsif (! $cgiparams { 'KEY' }) {
3409 my $cakeydisabled = '' ;
3410 my $cacrtdisabled = '' ;
3411 if ( ! - f
"${General::swroot}/ovpn/ca/cakey.pem" ) { $cakeydisabled = "disabled='disabled'" } else { $cakeydisabled = "" };
3412 if ( ! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) { $cacrtdisabled = "disabled='disabled'" } else { $cacrtdisabled = "" };
3413 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'authentication' });
3416 if ( $cgiparams { 'TYPE' } eq 'host' ) {
3419 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
3421 <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>
3422 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td><td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
3423 <tr><td colspan='3'> </td></tr>
3424 <tr><td colspan='3'><hr /></td></tr>
3425 <tr><td colspan='3'> </td></tr>
3426 <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>
3427 <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>
3428 <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>
3429 <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>
3430 <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>
3431 <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>
3432 <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>
3433 <tr><td> </td><td class='base'> $Lang ::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
3444 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
3446 <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>
3447 <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>
3448 <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>
3449 <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>
3450 <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>
3451 <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>
3452 <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>
3453 <tr><td> </td><td class='base'> $Lang ::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
3465 foreach my $country ( sort keys %{ Countries
:: countries
}) {
3466 print "<option value=' $Countries ::countries{ $country }'" ;
3467 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
3468 print " selected='selected'" ;
3470 print "> $country </option>" ;
3476 if ( $cgiparams { 'TYPE' } eq 'host' ) {
3480 <td> </td><td class='base'> $Lang ::tr{'valid till'} (days):</td>
3481 <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value=' $cgiparams {'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr>
3483 <td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
3484 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
3485 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'}:<BR>( $Lang ::tr{'confirmation'})</td>
3486 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
3487 <tr><td colspan='3'> </td></tr>
3488 <tr><td colspan='3'><hr /></td></tr>
3489 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
3495 <tr><td> </td><td> </td><td> </td></tr>
3496 <tr><td> </td><td> </td><td> </td></tr>
3497 <tr><td colspan='3'><hr /></td></tr>
3498 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
3508 & Header
:: closebox
();
3511 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
3512 if ( $cgiparams { 'KEY' }) {
3513 # print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />";
3515 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
3516 & Header
:: closebigbox
();
3517 & Header
:: closepage
();
3525 ### Default status page
3530 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%cgiparams );
3531 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
3532 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
3534 my @status = `/bin/cat /var/log/ovpnserver.log` ;
3536 if ( $cgiparams { 'VPN_IP' } eq '' && - e
"${General::swroot}/red/active" ) {
3537 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
3538 my $ipaddr = < IPADDR
>;
3541 $cgiparams { 'VPN_IP' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
3542 if ( $cgiparams { 'VPN_IP' } eq '' ) {
3543 $cgiparams { 'VPN_IP' } = $ipaddr ;
3549 if ( $cgiparams { 'DCIPHER' } eq '' ) {
3550 $cgiparams { 'DCIPHER' } = 'BF-CBC' ;
3552 # if ($cgiparams{'DCOMPLZO'} eq '') {
3553 # $cgiparams{'DCOMPLZO'} = 'on';
3555 if ( $cgiparams { 'DDEST_PORT' } eq '' ) {
3556 $cgiparams { 'DDEST_PORT' } = '1194' ;
3558 if ( $cgiparams { 'DMTU' } eq '' ) {
3559 $cgiparams { 'DMTU' } = '1400' ;
3561 if ( $cgiparams { 'DOVPN_SUBNET' } eq '' ) {
3562 $cgiparams { 'DOVPN_SUBNET' } = '10.' . int ( rand ( 256 )) . '.' . int ( rand ( 256 )) . '.0/255.255.255.0' ;
3565 $checked { 'ENABLED' }{ 'off' } = '' ;
3566 $checked { 'ENABLED' }{ 'on' } = '' ;
3567 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = 'CHECKED' ;
3568 $checked { 'ENABLED_BLUE' }{ 'off' } = '' ;
3569 $checked { 'ENABLED_BLUE' }{ 'on' } = '' ;
3570 $checked { 'ENABLED_BLUE' }{ $cgiparams { 'ENABLED_BLUE' }} = 'CHECKED' ;
3571 $checked { 'ENABLED_ORANGE' }{ 'off' } = '' ;
3572 $checked { 'ENABLED_ORANGE' }{ 'on' } = '' ;
3573 $checked { 'ENABLED_ORANGE' }{ $cgiparams { 'ENABLED_ORANGE' }} = 'CHECKED' ;
3574 $selected { 'DDEVICE' }{ 'tun' } = '' ;
3575 $selected { 'DDEVICE' }{ 'tap' } = '' ;
3576 $selected { 'DDEVICE' }{ $cgiparams { 'DDEVICE' }} = 'SELECTED' ;
3578 $selected { 'DPROTOCOL' }{ 'udp' } = '' ;
3579 $selected { 'DPROTOCOL' }{ 'tcp' } = '' ;
3580 $selected { 'DPROTOCOL' }{ $cgiparams { 'DPROTOCOL' }} = 'SELECTED' ;
3582 $selected { 'DCIPHER' }{ 'DES-CBC' } = '' ;
3583 $selected { 'DCIPHER' }{ 'DES-EDE-CBC' } = '' ;
3584 $selected { 'DCIPHER' }{ 'DES-EDE3-CBC' } = '' ;
3585 $selected { 'DCIPHER' }{ 'DESX-CBC' } = '' ;
3586 $selected { 'DCIPHER' }{ 'RC2-CBC' } = '' ;
3587 $selected { 'DCIPHER' }{ 'RC2-40-CBC' } = '' ;
3588 $selected { 'DCIPHER' }{ 'RC2-64-CBC' } = '' ;
3589 $selected { 'DCIPHER' }{ 'BF-CBC' } = '' ;
3590 $selected { 'DCIPHER' }{ 'CAST5-CBC' } = '' ;
3591 $selected { 'DCIPHER' }{ 'AES-128-CBC' } = '' ;
3592 $selected { 'DCIPHER' }{ 'AES-192-CBC' } = '' ;
3593 $selected { 'DCIPHER' }{ 'AES-256-CBC' } = '' ;
3594 $selected { 'DCIPHER' }{ $cgiparams { 'DCIPHER' }} = 'SELECTED' ;
3595 $checked { 'DCOMPLZO' }{ 'off' } = '' ;
3596 $checked { 'DCOMPLZO' }{ 'on' } = '' ;
3597 $checked { 'DCOMPLZO' }{ $cgiparams { 'DCOMPLZO' }} = 'CHECKED' ;
3599 $checked { 'MSSFIX' }{ 'off' } = '' ;
3600 $checked { 'MSSFIX' }{ 'on' } = '' ;
3601 $checked { 'MSSFIX' }{ $cgiparams { 'MSSFIX' }} = 'CHECKED' ;
3603 & Header
:: showhttpheaders
();
3604 & Header
:: openpage
( $Lang :: tr
{ 'status ovpn' }, 1 , '' );
3605 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
3607 if ( $errormessage ) {
3608 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
3609 print "<class name='base'> $errormessage \n " ;
3610 print " </class> \n " ;
3611 & Header
:: closebox
();
3614 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>" ;
3615 my $srunning = "no" ;
3616 my $activeonrun = "" ;
3617 if ( - e
"/var/run/openvpn.pid" ){
3618 $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>" ;
3622 $activeonrun = "disabled='disabled'" ;
3624 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'global settings' });
3626 <table width='100%'>
3627 <form method='post'>
3628 <td width='25%'> </td>
3629 <td width='25%'> </td>
3630 <td width='25%'> </td></tr>
3631 <tr><td class='boldbase'> $Lang ::tr{'ovpn server status'}</td>
3632 <td align='left'> $sactive </td>
3633 <tr><td class='boldbase'> $Lang ::tr{'ovpn on red'}</td>
3634 <td><input type='checkbox' name='ENABLED' $checked {'ENABLED'}{'on'} /></td>
3637 if (& haveBlueNet
()) {
3638 print "<tr><td class='boldbase'> $Lang ::tr{'ovpn on blue'}</td>" ;
3639 print "<td><input type='checkbox' name='ENABLED_BLUE' $checked {'ENABLED_BLUE'}{'on'} /></td>" ;
3641 if (& haveOrangeNet
()) {
3642 print "<tr><td class='boldbase'> $Lang ::tr{'ovpn on orange'}</td>" ;
3643 print "<td><input type='checkbox' name='ENABLED_ORANGE' $checked {'ENABLED_ORANGE'}{'on'} /></td>" ;
3646 <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>
3647 <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>
3648 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn device'}</td>
3649 <td><select name='DDEVICE' ><option value='tun' $selected {'DDEVICE'}{'tun'}>TUN</option>
3650 <!-- this is still not working
3651 <option value='tap' $selected {'DDEVICE'}{'tap'}>TAP</option></select>--> </td>
3652 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td>
3653 <td><select name='DPROTOCOL'><option value='udp' $selected {'DPROTOCOL'}{'udp'}>UDP</option>
3654 <option value='tcp' $selected {'DPROTOCOL'}{'tcp'}>TCP</option></select></td>
3655 <td class='boldbase'> $Lang ::tr{'destination port'}:</td>
3656 <td><input type='TEXT' name='DDEST_PORT' value=' $cgiparams {'DDEST_PORT'}' size='5' /></td></tr>
3657 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'} </td>
3658 <td> <input type='TEXT' name='DMTU' VALUE=' $cgiparams {'DMTU'}'size='5' /></TD>
3659 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'}</td>
3660 <td><input type='checkbox' name='DCOMPLZO' $checked {'DCOMPLZO'}{'on'} /></td>
3661 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'cipher'}</td>
3662 <td><select name='DCIPHER'><option value='DES-CBC' $selected {'DCIPHER'}{'DES-CBC'}>DES-CBC</option>
3663 <option value='DES-EDE-CBC' $selected {'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC</option>
3664 <option value='DES-EDE3-CBC' $selected {'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC</option>
3665 <option value='DESX-CBC' $selected {'DCIPHER'}{'DESX-CBC'}>DESX-CBC</option>
3666 <option value='RC2-CBC' $selected {'DCIPHER'}{'RC2-CBC'}>RC2-CBC</option>
3667 <option value='RC2-40-CBC' $selected {'DCIPHER'}{'RC2-40-CBC'}>RC2-40-CBC</option>
3668 <option value='RC2-64-CBC' $selected {'DCIPHER'}{'RC2-64-CBC'}>RC2-64-CBC</option>
3669 <option value='BF-CBC' $selected {'DCIPHER'}{'BF-CBC'}>BF-CBC</option>
3670 <option value='CAST5-CBC' $selected {'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC</option>
3671 <option value='AES-128-CBC' $selected {'DCIPHER'}{'AES-128-CBC'}>AES-128-CBC</option>
3672 <option value='AES-192-CBC' $selected {'DCIPHER'}{'AES-192-CBC'}>AES-192-CBC</option>
3673 <option value='AES-256-CBC' $selected {'DCIPHER'}{'AES-256-CBC'}>AES-256-CBC</option></select></td>
3677 if ( $srunning eq "yes" ) {
3678 print "<tr><td align='left'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' disabled='disabled' /></td>" ;
3679 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'advanced server'}' disabled='disabled'/></td>" ;
3680 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'stop ovpn server'}' /></td>" ;
3681 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'restart ovpn server'}' /></td></tr>" ;
3683 print "<tr><td align='left'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' /></td>" ;
3684 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'advanced server'}' /></td>" ;
3685 if (( - e
"${General::swroot}/ovpn/ca/cacert.pem" &&
3686 - e
"${General::swroot}/ovpn/ca/dh1024.pem" &&
3687 - e
"${General::swroot}/ovpn/certs/servercert.pem" &&
3688 - e
"${General::swroot}/ovpn/certs/serverkey.pem" ) &&
3689 (( $cgiparams { 'ENABLED' } eq 'on' ) ||
3690 ( $cgiparams { 'ENABLED_BLUE' } eq 'on' ) ||
3691 ( $cgiparams { 'ENABLED_ORANGE' } eq 'on' ))){
3692 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'start ovpn server'}' /></td>" ;
3693 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'restart ovpn server'}' /></td></tr>" ;
3695 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'start ovpn server'}' disabled='disabled' /></td>" ;
3696 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'restart ovpn server'}' disabled='disabled' /></td></tr>" ;
3699 print "</form></table>" ;
3700 & Header
:: closebox
();
3701 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'certificate authorities'}:" );
3703 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
3705 <td width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></td>
3706 <td width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></td>
3707 <td width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></td>
3711 if (- f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
3712 my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem` ;
3713 $casubject =~ /Subject: (.*)[\n]/ ;
3715 $casubject =~ s
+/ Email
+, E
+;
3716 $casubject =~ s/ ST=/ S=/ ;
3719 <tr bgcolor=' $color {'color22'}'>
3720 <td class='base'> $Lang ::tr{'root certificate'}</td>
3721 <td class='base'> $casubject </td>
3722 <form method='post' name='frmrootcrta'><td width='3%' align='center'>
3723 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
3724 <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' />
3726 <form method='post' name='frmrootcrtb'><td width='3%' align='center'>
3727 <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' />
3728 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
3730 <td width='4%'> </td></tr>
3734 # display rootcert generation buttons
3736 <tr bgcolor=' $color {'color22'}'>
3737 <td class='base'> $Lang ::tr{'root certificate'}:</td>
3738 <td class='base'> $Lang ::tr{'not present'}</td>
3739 <td colspan='3'> </td></tr>
3744 if (- f
"${General::swroot}/ovpn/certs/servercert.pem" ) {
3745 my $hostsubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem` ;
3746 $hostsubject =~ /Subject: (.*)[\n]/ ;
3748 $hostsubject =~ s
+/ Email
+, E
+;
3749 $hostsubject =~ s/ ST=/ S=/ ;
3752 <tr bgcolor=' $color {'color20'}'>
3753 <td class='base'> $Lang ::tr{'host certificate'}</td>
3754 <td class='base'> $hostsubject </td>
3755 <form method='post' name='frmhostcrta'><td width='3%' align='center'>
3756 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
3757 <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' />
3759 <form method='post' name='frmhostcrtb'><td width='3%' align='center'>
3760 <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' />
3761 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download host certificate'}' />
3763 <td width='4%'> </td></tr>
3769 <tr bgcolor=' $color {'color20'}'>
3770 <td width='25%' class='base'> $Lang ::tr{'host certificate'}:</td>
3771 <td class='base'> $Lang ::tr{'not present'}</td>
3772 </td><td colspan='3'> </td></tr>
3777 if (! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
3778 print "<tr><td colspan='5' align='center'><form method='post'>" ;
3779 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' />" ;
3780 print "</form></td></tr> \n " ;
3783 if ( keys %cahash > 0 ) {
3784 foreach my $key ( keys %cahash ) {
3785 if (( $key + 1 ) % 2 ) {
3786 print "<tr bgcolor=' $color {'color20'}'> \n " ;
3788 print "<tr bgcolor=' $color {'color22'}'> \n " ;
3790 print "<td class='base'> $cahash { $key }[0]</td> \n " ;
3791 print "<td class='base'> $cahash { $key }[1]</td> \n " ;
3793 <form method='post' name='cafrm${key}a'><td align='center'>
3794 <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' />
3795 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
3796 <input type='hidden' name='KEY' value=' $key ' />
3798 <form method='post' name='cafrm${key}b'><td align='center'>
3799 <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' />
3800 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
3801 <input type='hidden' name='KEY' value=' $key ' />
3803 <form method='post' name='cafrm${key}c'><td align='center'>
3804 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
3805 <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' />
3806 <input type='hidden' name='KEY' value=' $key ' />
3815 # If the file contains entries, print Key to action icons
3816 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
3820 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
3821 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
3822 <td class='base'> $Lang ::tr{'show certificate'}</td>
3823 <td> <img src='/images/media-floppy.png' alt=' $Lang ::tr{'download certificate'}' /></td>
3824 <td class='base'> $Lang ::tr{'download certificate'}</td>
3831 <form method='post' enctype='multipart/form-data'>
3832 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
3833 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'ca name'}:</td>
3834 <td nowrap='nowrap'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' />
3835 <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td>
3836 <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>
3837 </tr></table></form>
3841 & Header
:: closebox
();
3842 if ( $srunning eq "yes" ) {
3843 print "<div align='center'><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'reset'}' disabled='disabled' /></div></form> \n " ;
3845 print "<div align='center'><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'reset'}' /></div></form> \n " ;
3847 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
3851 #<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>
3854 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'Client status and controlc' });
3858 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
3860 <td width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></td>
3861 <td width='15%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></td>
3862 <td width='18%' class='boldbase' align='center'><b> $Lang ::tr{'common name'}</b></td>
3863 <td width='22%' class='boldbase' align='center'><b> $Lang ::tr{'valid till'}</b></td>
3864 <td width='20%' class='boldbase' align='center'><b> $Lang ::tr{'remark'}</b></td>
3865 <td width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></td>
3866 <td width='5%' class='boldbase' colspan='6' align='center'><b> $Lang ::tr{'action'}</b></td>
3872 foreach my $key ( keys %confighash ) {
3873 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
3876 print "<tr bgcolor=' $color {'color20'}'> \n " ;
3878 print "<tr bgcolor=' $color {'color22'}'> \n " ;
3880 print "<td align='center' nowrap='nowrap'> $confighash { $key }[1]</td>" ;
3881 print "<td align='center' nowrap='nowrap'>" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ")</td>" ;
3882 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
3883 print "<td align='left' nowrap='nowrap'> $confighash { $key }[2]</td>" ;
3885 print "<td align='left'> </td>" ;
3887 my $cavalid = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $confighash { $key }[1]cert.pem` ;
3888 $cavalid =~ /Not After : (.*)[\n]/ ;
3890 print "<td align='center'> $cavalid </td>" ;
3891 print "<td align='center'> $confighash { $key }[25]</td>" ;
3893 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>" ;
3895 if ( $confighash { $key }[ 0 ] eq 'off' ) {
3896 $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>" ;
3903 if ( $confighash { $key }[ 3 ] eq 'net' ) {
3905 if (- e
"/var/run/ $confighash { $key }[1]n2n.pid" ) {
3908 my $tport = $confighash { $key }[ 22 ];
3909 my $tnet = new Net
:: Telnet
( Timeout
=> 5 , Errmode
=> 'return' , Port
=> $tport );
3911 $tnet -> open ( '127.0.0.1' );
3912 @output = $tnet -> cmd ( String
=> 'state' , Prompt
=> '/(END.* \n |ERROR:.* \n )/' );
3913 @tustate = split ( /\,/ , $output [ 1 ]);
3915 #CONNECTING -- OpenVPN's initial state.
3916 #WAIT -- (Client only) Waiting for initial response from server.
3917 #AUTH -- (Client only) Authenticating with server.
3918 #GET_CONFIG -- (Client only) Downloading configuration options from server.
3919 #ASSIGN_IP -- Assigning IP address to virtual network interface.
3920 #ADD_ROUTES -- Adding routes to system.
3921 #CONNECTED -- Initialization Sequence Completed.
3922 #RECONNECTING -- A restart has occurred.
3923 #EXITING -- A graceful exit is in progress.
3926 if ( $tustate [ 1 ] eq 'CONNECTED' ) {
3927 $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>" ;
3929 $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>" ;
3937 foreach my $line ( @status ) {
3939 if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ ) {
3940 @match = split ( m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ , $line );
3941 if ( $match [ 1 ] ne "Common Name" ) {
3945 if ( $cn eq " $confighash { $key }[2]" ) {
3946 $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>" ;
3955 my $disable_clientdl = "disabled='disabled'" ;
3956 if (( $cgiparams { 'ENABLED' } eq 'on' ) ||
3957 ( $cgiparams { 'ENABLED_BLUE' } eq 'on' ) ||
3958 ( $cgiparams { 'ENABLED_ORANGE' } eq 'on' )){
3959 $disable_clientdl = "" ;
3962 <td align='center'> $active </td>
3964 <form method='post' name='frm${key}a'><td align='center'>
3965 <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' />
3966 <input type='hidden' name='ACTION' value=' $Lang ::tr{'dl client arch'}' $disable_clientdl />
3967 <input type='hidden' name='KEY' value=' $key ' $disable_clientdl />
3971 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
3973 <form method='post' name='frm${key}b'><td align='center'>
3974 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' border='0' />
3975 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
3976 <input type='hidden' name='KEY' value=' $key ' />
3980 print "<td> </td>" ;
3982 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $key }[1].p12" ) {
3984 <form method='post' name='frm${key}c'><td align='center'>
3985 <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' />
3986 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
3987 <input type='hidden' name='KEY' value=' $key ' />
3990 ; } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
3992 <form method='post' name='frm${key}c'><td align='center'>
3993 <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' />
3994 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
3995 <input type='hidden' name='KEY' value=' $key ' />
3999 print "<td> </td>" ;
4002 <form method='post' name='frm${key}d'><td align='center'>
4003 <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' />
4004 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
4005 <input type='hidden' name='KEY' value=' $key ' />
4008 <form method='post' name='frm${key}e'><td align='center'>
4009 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
4010 <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'/>
4011 <input type='hidden' name='KEY' value=' $key ' />
4013 <form method='post' name='frm${key}f'><td align='center'>
4014 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
4015 <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' />
4016 <input type='hidden' name='KEY' value=' $key ' />
4025 # If the config file contains entries, print Key to action icons
4030 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
4031 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
4032 <td class='base'> $Lang ::tr{'click to disable'}</td>
4033 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
4034 <td class='base'> $Lang ::tr{'show certificate'}</td>
4035 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
4036 <td class='base'> $Lang ::tr{'edit'}</td>
4037 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
4038 <td class='base'> $Lang ::tr{'remove'}</td>
4042 <td> <img src='/images/off.gif' alt='?OFF' /></td>
4043 <td class='base'> $Lang ::tr{'click to enable'}</td>
4044 <td> <img src='/images/media-floppy.png' alt='?FLOPPY' /></td>
4045 <td class='base'> $Lang ::tr{'download certificate'}</td>
4046 <td> <img src='/images/openvpn.png' alt='?RELOAD'/></td>
4047 <td class='base'> $Lang ::tr{'dl client arch'}</td>
4055 <table width='100%'>
4056 <form method='post'>
4057 <tr><td width='50%' ><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td>
4058 <td width='50%' ><input type='submit' name='ACTION' value=' $Lang ::tr{'ovpn con stat'}' $activeonrun /></td></tr>
4063 & Header
:: closebox
();
4065 & Header
:: closepage
();