]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/ovpnmain.cgi
2 # based on SmoothWall and IPCop CGIs
4 # This code is distributed under the terms of the GPL
5 # Main idea from zeroconcept
6 # ZERNINA-VERSION:0.9.4i
7 # (c) 2007 Ufuk Altinkaynak
11 use CGI qw
/:standard/ ;
14 use File
:: Temp qw
/ tempfile tempdir / ;
16 use Archive
:: Zip
qw(:ERROR_CODES :CONSTANTS) ;
17 require '/var/ipfire/general-functions.pl' ;
18 require "${General::swroot}/lang.pl" ;
19 require "${General::swroot}/header.pl" ;
20 require "${General::swroot}/countries.pl" ;
22 # enable only the following on debugging purpose
24 #use CGI::Carp 'fatalsToBrowser';
25 #workaround to suppress a warning when a variable is used only once
26 my @dummy = ( ${ Header
:: colourgreen
} );
30 my %mainsettings = ();
31 & General
:: readhash
( "${General::swroot}/main/settings" , \
%mainsettings );
32 & General
:: readhash
( "/srv/web/ipfire/html/themes/" . $mainsettings { 'THEME' }. "/include/colors.txt" , \
%color );
37 ### Initialize variables
47 my $errormessage = '' ;
49 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%netsettings );
50 $cgiparams { 'ENABLED' } = 'off' ;
51 $cgiparams { 'ENABLED_BLUE' } = 'off' ;
52 $cgiparams { 'ENABLED_ORANGE' } = 'off' ;
53 $cgiparams { 'EDIT_ADVANCED' } = 'off' ;
54 $cgiparams { 'NAT' } = 'off' ;
55 $cgiparams { 'COMPRESSION' } = 'off' ;
56 $cgiparams { 'ONLY_PROPOSED' } = 'off' ;
57 $cgiparams { 'ACTION' } = '' ;
58 $cgiparams { 'CA_NAME' } = '' ;
59 $cgiparams { 'DHCP_DOMAIN' } = '' ;
60 $cgiparams { 'DHCP_DNS' } = '' ;
61 $cgiparams { 'DHCP_WINS' } = '' ;
62 $cgiparams { 'DCOMPLZO' } = 'off' ;
63 & Header
:: getcgihash
( \
%cgiparams , { 'wantfile' => 1 , 'filevar' => 'FH' });
65 # prepare openvpn config file
71 if ( $netsettings { 'CONFIG_TYPE' } == 2 ) { return 1 ;}
72 if ( $netsettings { 'CONFIG_TYPE' } == 4 ) { return 1 ;}
78 if ( $netsettings { 'CONFIG_TYPE' } == 3 ) { return 1 ;}
79 if ( $netsettings { 'CONFIG_TYPE' } == 4 ) { return 1 ;}
87 while ( abs ( $bytesize ) >= 1024 ){
88 $bytesize = $bytesize / 1024 ;
93 my @units = ( "Bytes" , "KB" , "MB" , "GB" , "TB" , "PB" , "EB" );
94 my $newsize =( int ( $bytesize * 100 + 0.5 ))/ 100 ;
95 return ( " $newsize $units [ $i ]" );
100 unless ( $hostname ) { return "No hostname" };
101 my $res = new Net
:: DNS
:: Resolver
;
102 my $query = $res -> search ( " $hostname " );
104 foreach my $rr ( $query -> answer ) {
105 ## Potential bug - we are only looking at A records:
106 return 0 if $rr -> type eq "A" ;
109 return $res -> errorstring ;
115 if ( open ( FILE
, ">${General::swroot}/ovpn/certs/serial" )) {
119 if ( open ( FILE
, ">${General::swroot}/ovpn/certs/index.txt" )) {
123 unlink ( "${General::swroot}/ovpn/certs/index.txt.old" );
124 unlink ( "${General::swroot}/ovpn/certs/serial.old" );
125 unlink ( "${General::swroot}/ovpn/certs/01.pem" );
128 sub newcleanssldatabase
130 if (! - s
"${General::swroot}/ovpn/certs/serial" ) {
131 open ( FILE
, ">${General::swroot}(ovpn/certs/serial" );
135 if (! - s
">${General::swroot}/ovpn/certs/index.txt" ) {
136 system ( "touch ${General::swroot}/ovpn/certs/index.txt" );
138 unlink ( "${General::swroot}/ovpn/certs/index.txt.old" );
139 unlink ( "${General::swroot}/ovpn/certs/serial.old" );
144 if ( open ( FILE
, "${General::swroot}/ovpn/certs/serial.old" )) {
145 my $hexvalue = < FILE
>;
148 unlink ( "${General::swroot}/ovpn/certs/ $hexvalue .pem" );
153 my $KEY2 = $_ [ 0 ]; # key2
154 my $SRC_PORT = $_ [ 1 ]; # src_port
155 my $PROTOCOL = $_ [ 2 ]; # protocol
156 my $SRC_IP = $_ [ 3 ]; # sourceip
158 my $pfwfilename = "${General::swroot}/portfw/config" ;
159 open ( FILE
, $pfwfilename ) or die 'Unable to open config file.' ;
160 my @pfwcurrent = < FILE
>;
162 my $pfwkey1 = 0 ; # used for finding last sequence number used
163 foreach my $pfwline ( @pfwcurrent )
165 my @pfwtemp = split ( /\,/ , $pfwline );
168 if ( $KEY2 eq "0" ){ # if key2 is 0 then it is a portfw addition
169 if ( $SRC_PORT eq $pfwtemp [ 3 ] &&
170 $PROTOCOL eq $pfwtemp [ 2 ] &&
171 $SRC_IP eq $pfwtemp [ 7 ])
173 $errormessage = " $Lang ::tr{'source port in use'} $SRC_PORT " ;
175 # Check if key2 = 0, if it is then it is a port forward entry and we want the sequence number
176 if ( $pfwtemp [ 1 ] eq "0" ) {
177 $pfwkey1 = $pfwtemp [ 0 ];
179 # Darren Critchley - Duplicate or overlapping Port range check
180 if ( $pfwtemp [ 1 ] eq "0" &&
181 $PROTOCOL eq $pfwtemp [ 2 ] &&
182 $SRC_IP eq $pfwtemp [ 7 ] &&
185 & portchecks
( $SRC_PORT , $pfwtemp [ 5 ]);
186 # &portchecks($pfwtemp[3], $pfwtemp[5]);
187 # &portchecks($pfwtemp[3], $SRC_IP);
191 # $errormessage="$KEY2 $SRC_PORT $PROTOCOL $SRC_IP";
198 my $portrange1 = $_ [ 0 ]; # New port range
199 my $portrange2 = $_ [ 1 ]; # existing port range
200 my @tempr1 = split ( /\:/ , $portrange1 );
201 my @tempr2 = split ( /\:/ , $portrange2 );
203 unless (& checkportinc
( $tempr1 [ 0 ], $portrange2 )){ return 0 ;}
204 unless (& checkportinc
( $tempr1 [ 1 ], $portrange2 )){ return 0 ;}
206 unless (& checkportinc
( $tempr2 [ 0 ], $portrange1 )){ return 0 ;}
207 unless (& checkportinc
( $tempr2 [ 1 ], $portrange1 )){ return 0 ;}
209 return 1 ; # Everything checks out!
212 # Darren Critchley - we want to make sure that a port entry is not within an already existing range
215 my $port1 = $_ [ 0 ]; # Port
216 my $portrange2 = $_ [ 1 ]; # Port range
217 my @tempr1 = split ( /\:/ , $portrange2 );
219 if ( $port1 < $tempr1 [ 0 ] || $port1 > $tempr1 [ 1 ]) {
225 # Darren Critchley - Duplicate or overlapping Port range check
228 my $p1 = $_ [ 0 ]; # New port range
229 my $p2 = $_ [ 1 ]; # existing port range
231 our ( $prtrange1 , $prtrange2 );
233 # if (m/:/ && $prtrange1 == 1) { # comparing two port ranges
234 # unless (&checkportoverlap($p1,$p2)) {
235 # $errormessage = "$Lang::tr{'source port overlaps'} $p1";
238 if ( m/:/ && $prtrange1 == 0 && $errormessage eq '' ) { # compare one port to a range
239 unless (& checkportinc
( $p2 , $p1 )) {
240 $errormessage = " $Lang ::tr{'srcprt within existing'} $p1 " ;
244 if (! m/:/ && $prtrange1 == 1 && $errormessage eq '' ) { # compare one port to a range
245 unless (& checkportinc
( $p1 , $p2 )) {
246 $errormessage = " $Lang ::tr{'srcprt range overlaps'} $p2 " ;
252 # Darren Critchley - certain ports are reserved for IPFire
253 # TCP 67,68,81,222,445
255 # Params passed in -> port, rangeyn, protocol
258 # port 67 and 68 same for tcp and udp, don't bother putting in an array
260 my @tcp_reserved = ( 81 , 222 , 445 );
261 my $prt = $_ [ 0 ]; # the port or range
262 my $ryn = $_ [ 1 ]; # tells us whether or not it is a port range
263 my $prot = $_ [ 2 ]; # protocol
264 my $srcdst = $_ [ 3 ]; # source or destination
265 if ( $ryn ) { # disect port range
266 if ( $srcdst eq "src" ) {
267 $msg = " $Lang ::tr{'rsvd src port overlap'}" ;
269 $msg = " $Lang ::tr{'rsvd dst port overlap'}" ;
271 my @tmprng = split ( /\:/ , $prt );
272 unless ( 67 < $tmprng [ 0 ] || 67 > $tmprng [ 1 ]) { $errormessage = " $msg 67" ; return ; }
273 unless ( 68 < $tmprng [ 0 ] || 68 > $tmprng [ 1 ]) { $errormessage = " $msg 68" ; return ; }
274 if ( $prot eq "tcp" ) {
275 foreach my $prange ( @tcp_reserved ) {
276 unless ( $prange < $tmprng [ 0 ] || $prange > $tmprng [ 1 ]) { $errormessage = " $msg $prange " ; return ; }
280 if ( $srcdst eq "src" ) {
281 $msg = " $Lang ::tr{'reserved src port'}" ;
283 $msg = " $Lang ::tr{'reserved dst port'}" ;
285 if ( $prt == 67 ) { $errormessage = " $msg 67" ; return ; }
286 if ( $prt == 68 ) { $errormessage = " $msg 68" ; return ; }
287 if ( $prot eq "tcp" ) {
288 foreach my $prange ( @tcp_reserved ) {
289 if ( $prange == $prt ) { $errormessage = " $msg $prange " ; return ; }
296 sub writeserverconf
{
297 my %sovpnsettings = ();
298 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%sovpnsettings );
300 open ( CONF
, ">${General::swroot}/ovpn/server.conf" ) or die "Unable to open ${General::swroot}/ovpn/server.conf: $!" ;
302 print CONF
"#OpenVPN Server conf \n " ;
304 print CONF
"daemon openvpnserver \n " ;
305 print CONF
"writepid /var/run/openvpn.pid \n " ;
306 print CONF
"#DAN prepare ZERINA for listening on blue and orange \n " ;
307 print CONF
";local $sovpnsettings {'VPN_IP'} \n " ;
308 print CONF
"dev $sovpnsettings {'DDEVICE'} \n " ;
309 print CONF
" $sovpnsettings {'DDEVICE'}-mtu $sovpnsettings {'DMTU'} \n " ;
310 print CONF
"proto $sovpnsettings {'DPROTOCOL'} \n " ;
311 print CONF
"port $sovpnsettings {'DDEST_PORT'} \n " ;
312 print CONF
"tls-server \n " ;
313 print CONF
"ca /var/ipfire/ovpn/ca/cacert.pem \n " ;
314 print CONF
"cert /var/ipfire/ovpn/certs/servercert.pem \n " ;
315 print CONF
"key /var/ipfire/ovpn/certs/serverkey.pem \n " ;
316 print CONF
"dh /var/ipfire/ovpn/ca/dh1024.pem \n " ;
317 my @tempovpnsubnet = split ( "\/" , $sovpnsettings { 'DOVPN_SUBNET' });
318 print CONF
"server $tempovpnsubnet [0] $tempovpnsubnet [1] \n " ;
319 print CONF
"push \" route $netsettings {'GREEN_NETADDRESS'} $netsettings {'GREEN_NETMASK'} \"\n " ;
320 if ( $sovpnsettings { CLIENT2CLIENT
} eq 'on' ) {
321 print CONF
"client-to-client \n " ;
323 if ( $sovpnsettings { KEEPALIVE_1
} > 0 && $sovpnsettings { KEEPALIVE_2
} > 0 ) {
324 print CONF
"keepalive $sovpnsettings {'KEEPALIVE_1'} $sovpnsettings {'KEEPALIVE_2'} \n " ;
326 print CONF
"status-version 1 \n " ;
327 print CONF
"status /var/log/ovpnserver.log 30 \n " ;
328 print CONF
"cipher $sovpnsettings {DCIPHER} \n " ;
329 if ( $sovpnsettings { DCOMPLZO
} eq 'on' ) {
330 print CONF
"comp-lzo \n " ;
332 if ( $sovpnsettings { REDIRECT_GW_DEF1
} eq 'on' ) {
333 print CONF
"push \" redirect-gateway def1 \"\n " ;
335 if ( $sovpnsettings { DHCP_DOMAIN
} ne '' ) {
336 print CONF
"push \" dhcp-option DOMAIN $sovpnsettings {DHCP_DOMAIN} \"\n " ;
339 if ( $sovpnsettings { DHCP_DNS
} ne '' ) {
340 print CONF
"push \" dhcp-option DNS $sovpnsettings {DHCP_DNS} \"\n " ;
343 if ( $sovpnsettings { DHCP_WINS
} ne '' ) {
344 print CONF
"push \" dhcp-option WINS $sovpnsettings {DHCP_WINS} \"\n " ;
347 if ( $sovpnsettings { DHCP_WINS
} eq '' ) {
348 print CONF
"max-clients 100 \n " ;
351 if ( $sovpnsettings { DHCP_WINS
} ne '' ) {
352 print CONF
"max-clients $sovpnsettings {MAX_CLIENTS} \n " ;
354 print CONF
"tls-verify /var/ipfire/ovpn/verify \n " ;
355 print CONF
"crl-verify /var/ipfire/ovpn/crls/cacrl.pem \n " ;
356 print CONF
"user nobody \n " ;
357 print CONF
"group nobody \n " ;
358 print CONF
"persist-key \n " ;
359 print CONF
"persist-tun \n " ;
360 if ( $sovpnsettings { LOG_VERB
} ne '' ) {
361 print CONF
"verb $sovpnsettings {LOG_VERB} \n " ;
363 print CONF
"verb 3 \n " ;
371 if ( open ( FILE
, ">/var/log/ovpnserver.log" )) {
379 #hier die refresh page
380 if ( - e
"${General::swroot}/ovpn/gencanow" ) {
382 $refresh = "<meta http-equiv='refresh' content='15;' />" ;
383 & Header
:: showhttpheaders
();
384 & Header
:: openpage
( $Lang :: tr
{ 'OVPN' }, 1 , $refresh );
385 & Header
:: openbigbox
( '100%' , 'center' );
386 & Header
:: openbox
( '100%' , 'left' , " $Lang ::tr{'generate root/host certificates'}:" );
387 print "<tr> \n <td align='center'><img src='/images/clock.gif' alt='' /></td> \n " ;
388 print "<td colspan='2'><font color='red'>Please be patient this realy can take some time on older hardware...</font></td></tr> \n " ;
390 & Header
:: closebigbox
();
391 & Header
:: closepage
();
394 ##hier die refresh page
398 ### OpenVPN Server Control
400 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'start ovpn server' } ||
401 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'stop ovpn server' } ||
402 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart ovpn server' }) {
403 #start openvpn server
404 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'start ovpn server' }){
406 system ( '/usr/local/bin/openvpnctrl' , '-s' );
409 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'stop ovpn server' }){
410 system ( '/usr/local/bin/openvpnctrl' , '-k' );
413 # #restart openvpn server
414 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart ovpn server' }){
415 #workarund, till SIGHUP also works when running as nobody
416 system ( '/usr/local/bin/openvpnctrl' , '-r' );
422 ### Save Advanced options
425 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save-adv-options' }) {
426 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
427 #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too,
428 #DAN this value has to leave.
429 #new settings for daemon
430 $vpnsettings { 'LOG_VERB' } = $cgiparams { 'LOG_VERB' };
431 $vpnsettings { 'KEEPALIVE_1' } = $cgiparams { 'KEEPALIVE_1' };
432 $vpnsettings { 'KEEPALIVE_2' } = $cgiparams { 'KEEPALIVE_2' };
433 $vpnsettings { 'MAX_CLIENTS' } = $cgiparams { 'MAX_CLIENTS' };
434 $vpnsettings { 'REDIRECT_GW_DEF1' } = $cgiparams { 'REDIRECT_GW_DEF1' };
435 $vpnsettings { 'CLIENT2CLIENT' } = $cgiparams { 'CLIENT2CLIENT' };
436 $vpnsettings { 'DHCP_DOMAIN' } = $cgiparams { 'DHCP_DOMAIN' };
437 $vpnsettings { 'DHCP_DNS' } = $cgiparams { 'DHCP_DNS' };
438 $vpnsettings { 'DHCP_WINS' } = $cgiparams { 'DHCP_WINS' };
440 if ( $cgiparams { 'DHCP_DOMAIN' } ne '' ){
441 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_DOMAIN' }) || & General
:: validip
( $cgiparams { 'DHCP_DOMAIN' })) {
442 $errormessage = $Lang :: tr
{ 'invalid input for dhcp domain' };
446 if ( $cgiparams { 'DHCP_DNS' } ne '' ){
447 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_DNS' }) || & General
:: validip
( $cgiparams { 'DHCP_DNS' })) {
448 $errormessage = $Lang :: tr
{ 'invalid input for dhcp dns' };
452 if ( $cgiparams { 'DHCP_WINS' } ne '' ){
453 unless (& General
:: validfqdn
( $cgiparams { 'DHCP_WINS' }) || & General
:: validip
( $cgiparams { 'DHCP_WINS' })) {
454 $errormessage = $Lang :: tr
{ 'invalid input for dhcp wins' };
458 if (( length ( $cgiparams { 'MAX_CLIENTS' }) == 0 ) || (( $cgiparams { 'MAX_CLIENTS' }) < 1 ) || (( $cgiparams { 'MAX_CLIENTS' }) > 255 )) {
459 $errormessage = $Lang :: tr
{ 'invalid input for max clients' };
462 if ( $cgiparams { 'KEEPALIVE_1' } ne '' ) {
463 if ( $cgiparams { 'KEEPALIVE_1' } !~ /^[0-9]+$/ ) {
464 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 1' };
468 if ( $cgiparams { 'KEEPALIVE_2' } ne '' ){
469 if ( $cgiparams { 'KEEPALIVE_2' } !~ /^[0-9]+$/ ) {
470 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 2' };
474 if ( $cgiparams { 'KEEPALIVE_2' } < ( $cgiparams { 'KEEPALIVE_1' } * 2 )){
475 $errormessage = $Lang :: tr
{ 'invalid input for keepalive 1:2' };
479 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
480 & writeserverconf
(); #hier ok
487 ### Save main settings
489 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'TYPE' } eq '' && $cgiparams { 'KEY' } eq '' ) {
490 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
491 #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too,
492 #DAN this value has to leave.
493 if ( $cgiparams { 'ENABLED' } eq 'on' ){
494 unless (& General
:: validfqdn
( $cgiparams { 'VPN_IP' }) || & General
:: validip
( $cgiparams { 'VPN_IP' })) {
495 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
499 if ( $cgiparams { 'ENABLED' } eq 'on' ){
500 & disallowreserved
( $cgiparams { 'DDEST_PORT' }, 0 , $cgiparams { 'DPROTOCOL' }, "dest" );
502 if ( $errormessage ) { goto SETTINGS_ERROR
; }
505 if ( $cgiparams { 'ENABLED' } eq 'on' ){
506 & checkportfw
( 0 , $cgiparams { 'DDEST_PORT' }, $cgiparams { 'DPROTOCOL' }, '0.0.0.0' );
509 if ( $errormessage ) { goto SETTINGS_ERROR
; }
511 if (! & General
:: validipandmask
( $cgiparams { 'DOVPN_SUBNET' })) {
512 $errormessage = $Lang :: tr
{ 'ovpn subnet is invalid' };
515 my @tmpovpnsubnet = split ( "\/" , $cgiparams { 'DOVPN_SUBNET' });
517 if (& General
:: IpInSubnet
( $netsettings { 'RED_ADDRESS' },
518 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
519 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire RED Network $netsettings {'RED_ADDRESS'}" ;
523 if (& General
:: IpInSubnet
( $netsettings { 'GREEN_ADDRESS' },
524 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
525 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Green Network $netsettings {'GREEN_ADDRESS'}" ;
529 if (& General
:: IpInSubnet
( $netsettings { 'BLUE_ADDRESS' },
530 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
531 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Blue Network $netsettings {'BLUE_ADDRESS'}" ;
535 if (& General
:: IpInSubnet
( $netsettings { 'ORANGE_ADDRESS' },
536 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
537 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire Orange Network $netsettings {'ORANGE_ADDRESS'}" ;
540 open ( ALIASES
, "${General::swroot}/ethernet/aliases" ) or die 'Unable to open aliases file.' ;
544 my @tempalias = split ( /\,/ , $_ );
545 if ( $tempalias [ 1 ] eq 'on' ) {
546 if (& General
:: IpInSubnet
( $tempalias [ 0 ] ,
547 $tmpovpnsubnet [ 0 ], $tmpovpnsubnet [ 1 ])) {
548 $errormessage = " $Lang ::tr{'ovpn subnet overlap'} IPFire alias entry $tempalias [0]" ;
553 if ( $errormessage ne '' ){
556 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
557 $errormessage = $Lang :: tr
{ 'invalid input' };
560 if (( length ( $cgiparams { 'DMTU' })== 0 ) || (( $cgiparams { 'DMTU' }) < 1000 )) {
561 $errormessage = $Lang :: tr
{ 'invalid mtu input' };
565 unless (& General
:: validport
( $cgiparams { 'DDEST_PORT' })) {
566 $errormessage = $Lang :: tr
{ 'invalid port' };
569 $vpnsettings { 'ENABLED_BLUE' } = $cgiparams { 'ENABLED_BLUE' };
570 $vpnsettings { 'ENABLED_ORANGE' } = $cgiparams { 'ENABLED_ORANGE' };
571 $vpnsettings { 'ENABLED' } = $cgiparams { 'ENABLED' };
572 $vpnsettings { 'VPN_IP' } = $cgiparams { 'VPN_IP' };
573 #new settings for daemon
574 $vpnsettings { 'DOVPN_SUBNET' } = $cgiparams { 'DOVPN_SUBNET' };
575 $vpnsettings { 'DDEVICE' } = $cgiparams { 'DDEVICE' };
576 $vpnsettings { 'DPROTOCOL' } = $cgiparams { 'DPROTOCOL' };
577 $vpnsettings { 'DDEST_PORT' } = $cgiparams { 'DDEST_PORT' };
578 $vpnsettings { 'DMTU' } = $cgiparams { 'DMTU' };
579 $vpnsettings { 'DCOMPLZO' } = $cgiparams { 'DCOMPLZO' };
580 $vpnsettings { 'DCIPHER' } = $cgiparams { 'DCIPHER' };
581 #new settings for daemon
582 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
583 & writeserverconf
(); #hier ok
588 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'reset' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
590 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
592 foreach my $key ( keys %confighash ) {
593 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
594 delete $confighash { $cgiparams { ' $key ' }};
597 while ( $file = glob ( "${General::swroot}/ovpn/ca/*" )) {
600 while ( $file = glob ( "${General::swroot}/ovpn/certs/*" )) {
603 while ( $file = glob ( "${General::swroot}/ovpn/crls/*" )) {
607 if ( open ( FILE
, ">${General::swroot}/ovpn/caconfig" )) {
611 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
616 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'reset' }) {
617 & Header
:: showhttpheaders
();
618 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
619 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
620 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'are you sure' });
622 <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' />
623 <tr><td align='center'>
624 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
625 $Lang ::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}
626 <tr><td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'reset'}' />
627 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td></tr>
632 & Header
:: closebigbox
();
633 & Header
:: closepage
();
637 ### Upload CA Certificate
639 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload ca certificate' }) {
640 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
642 if ( $cgiparams { 'CA_NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
643 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
647 if ( length ( $cgiparams { 'CA_NAME' }) > 60 ) {
648 $errormessage = $Lang :: tr
{ 'name too long' };
652 if ( $cgiparams { 'CA_NAME' } eq 'ca' ) {
653 $errormessage = $Lang :: tr
{ 'name is invalid' };
654 goto UPLOAD_CA_ERROR
;
657 # Check if there is no other entry with this name
658 foreach my $key ( keys %cahash ) {
659 if ( $cahash { $key }[ 0 ] eq $cgiparams { 'CA_NAME' }) {
660 $errormessage = $Lang :: tr
{ 'a ca certificate with this name already exists' };
665 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
666 $errormessage = $Lang :: tr
{ 'there was no file upload' };
669 # Move uploaded ca to a temporary file
670 ( my $fh , my $filename ) = tempfile
( );
671 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
675 my $temp = `/usr/bin/openssl x509 -text -in $filename ` ;
676 if ( $temp !~ /CA:TRUE/i ) {
677 $errormessage = $Lang :: tr
{ 'not a valid ca certificate' };
681 move
( $filename , "${General::swroot}/ovpn/ca/ $cgiparams {'CA_NAME'}cert.pem" );
683 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
689 my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/ $cgiparams {'CA_NAME'}cert.pem` ;
690 $casubject =~ /Subject: (.*)[\n]/ ;
692 $casubject =~ s
+/ Email
+, E
+;
693 $casubject =~ s/ ST=/ S=/ ;
694 $casubject = & Header
:: cleanhtml
( $casubject );
696 my $key = & General
:: findhasharraykey
( \
%cahash );
697 $cahash { $key }[ 0 ] = $cgiparams { 'CA_NAME' };
698 $cahash { $key }[ 1 ] = $casubject ;
699 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
700 # system('/usr/local/bin/ipsecctrl', 'R');
705 ### Display ca certificate
707 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show ca certificate' }) {
708 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
710 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
711 & Header
:: showhttpheaders
();
712 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
713 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
714 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'ca certificate'}:" );
715 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
716 $output = & Header
:: cleanhtml
( $output , "y" );
717 print "<pre> $output </pre> \n " ;
719 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
720 & Header
:: closebigbox
();
721 & Header
:: closepage
();
724 $errormessage = $Lang :: tr
{ 'invalid key' };
728 ### Download ca certificate
730 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download ca certificate' }) {
731 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
733 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
734 print "Content-Type: application/octet-stream \r\n " ;
735 print "Content-Disposition: filename= $cahash { $cgiparams {'KEY'}}[0]cert.pem \r\n\r\n " ;
736 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem` ;
739 $errormessage = $Lang :: tr
{ 'invalid key' };
743 ### Remove ca certificate (step 2)
745 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' } && $cgiparams { 'AREUSURE' } eq 'yes' ) {
746 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
747 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
749 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
750 foreach my $key ( keys %confighash ) {
751 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` ;
752 if ( $test =~ /: OK/ ) {
754 # if ($vpnsettings{'ENABLED'} eq 'on' ||
755 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
756 # system('/usr/local/bin/ipsecctrl', 'D', $key);
758 unlink ( "${General::swroot}/ovpn//certs/ $confighash { $key }[1]cert.pem" );
759 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $key }[1].p12" );
760 delete $confighash { $key };
761 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
762 # &writeipsecfiles();
765 unlink ( "${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
766 delete $cahash { $cgiparams { 'KEY' }};
767 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
768 # system('/usr/local/bin/ipsecctrl', 'R');
770 $errormessage = $Lang :: tr
{ 'invalid key' };
773 ### Remove ca certificate (step 1)
775 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove ca certificate' }) {
776 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
777 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
779 my $assignedcerts = 0 ;
780 if ( - f
"${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" ) {
781 foreach my $key ( keys %confighash ) {
782 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` ;
783 if ( $test =~ /: OK/ ) {
787 if ( $assignedcerts ) {
788 & Header
:: showhttpheaders
();
789 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
790 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
791 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'are you sure' });
793 <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' />
794 <input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />
795 <tr><td align='center'>
796 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>: $assignedcerts
797 $Lang ::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}
798 <tr><td align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
799 <input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></td></tr>
804 & Header
:: closebigbox
();
805 & Header
:: closepage
();
808 unlink ( "${General::swroot}/ovpn/ca/ $cahash { $cgiparams {'KEY'}}[0]cert.pem" );
809 delete $cahash { $cgiparams { 'KEY' }};
810 & General
:: writehasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
811 # system('/usr/local/bin/ipsecctrl', 'R');
814 $errormessage = $Lang :: tr
{ 'invalid key' };
818 ### Display root certificate
820 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' } ||
821 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show host certificate' }) {
823 & Header
:: showhttpheaders
();
824 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
825 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
826 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show root certificate' }) {
827 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'root certificate'}:" );
828 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem` ;
830 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'host certificate'}:" );
831 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem` ;
833 $output = & Header
:: cleanhtml
( $output , "y" );
834 print "<pre> $output </pre> \n " ;
836 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
837 & Header
:: closebigbox
();
838 & Header
:: closepage
();
842 ### Download root certificate
844 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download root certificate' }) {
845 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
846 print "Content-Type: application/octet-stream \r\n " ;
847 print "Content-Disposition: filename=cacert.pem \r\n\r\n " ;
848 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/cacert.pem` ;
853 ### Download host certificate
855 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download host certificate' }) {
856 if ( - f
"${General::swroot}/ovpn/certs/servercert.pem" ) {
857 print "Content-Type: application/octet-stream \r\n " ;
858 print "Content-Disposition: filename=servercert.pem \r\n\r\n " ;
859 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/certs/servercert.pem` ;
863 ### Form for generating a root certificate
865 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'generate root/host certificates' } ||
866 $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
868 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
869 if (- f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
870 $errormessage = $Lang :: tr
{ 'valid root certificate already exists' };
871 $cgiparams { 'ACTION' } = '' ;
875 if (( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) && - e
"${General::swroot}/red/active" ) {
876 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
877 my $ipaddr = < IPADDR
>;
880 $cgiparams { 'ROOTCERT_HOSTNAME' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
881 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ) {
882 $cgiparams { 'ROOTCERT_HOSTNAME' } = $ipaddr ;
885 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'upload p12 file' }) {
887 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
888 $errormessage = $Lang :: tr
{ 'there was no file upload' };
892 # Move uploaded certificate request to a temporary file
893 ( my $fh , my $filename ) = tempfile
( );
894 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
899 # Create a temporary dirctory
900 my $tempdir = tempdir
( CLEANUP
=> 1 );
902 # Extract the CA certificate from the file
903 my $pid = open ( OPENSSL
, "|-" );
904 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
906 if ( $cgiparams { 'P12_PASS' } ne '' ) {
907 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
911 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
916 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-cacerts' , '-nokeys' ,
918 '-out' , " $tempdir /cacert.pem" )) {
919 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
925 # Extract the Host certificate from the file
926 $pid = open ( OPENSSL
, "|-" );
927 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
929 if ( $cgiparams { 'P12_PASS' } ne '' ) {
930 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
934 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
939 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-clcerts' , '-nokeys' ,
941 '-out' , " $tempdir /hostcert.pem" )) {
942 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
948 # Extract the Host key from the file
949 $pid = open ( OPENSSL
, "|-" );
950 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
952 if ( $cgiparams { 'P12_PASS' } ne '' ) {
953 print OPENSSL
" $cgiparams {'P12_PASS'} \n " ;
957 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
962 unless ( exec ( '/usr/bin/openssl' , 'pkcs12' , '-nocerts' ,
965 '-out' , " $tempdir /serverkey.pem" )) {
966 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
972 move
( " $tempdir /cacert.pem" , "${General::swroot}/ovpn/ca/cacert.pem" );
974 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
976 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
977 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
978 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
982 move
( " $tempdir /hostcert.pem" , "${General::swroot}/ovpn/certs/servercert.pem" );
984 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
986 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
987 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
988 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
992 move
( " $tempdir /serverkey.pem" , "${General::swroot}/ovpn/certs/serverkey.pem" );
994 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
996 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
997 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
998 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1002 goto ROOTCERT_SUCCESS
;
1004 } elsif ( $cgiparams { 'ROOTCERT_COUNTRY' } ne '' ) {
1006 # Validate input since the form was submitted
1007 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } eq '' ){
1008 $errormessage = $Lang :: tr
{ 'organization cant be empty' };
1009 goto ROOTCERT_ERROR
;
1011 if ( length ( $cgiparams { 'ROOTCERT_ORGANIZATION' }) > 60 ) {
1012 $errormessage = $Lang :: tr
{ 'organization too long' };
1013 goto ROOTCERT_ERROR
;
1015 if ( $cgiparams { 'ROOTCERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1016 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
1017 goto ROOTCERT_ERROR
;
1019 if ( $cgiparams { 'ROOTCERT_HOSTNAME' } eq '' ){
1020 $errormessage = $Lang :: tr
{ 'hostname cant be empty' };
1021 goto ROOTCERT_ERROR
;
1023 unless (& General
:: validfqdn
( $cgiparams { 'ROOTCERT_HOSTNAME' }) || & General
:: validip
( $cgiparams { 'ROOTCERT_HOSTNAME' })) {
1024 $errormessage = $Lang :: tr
{ 'invalid input for hostname' };
1025 goto ROOTCERT_ERROR
;
1027 if ( $cgiparams { 'ROOTCERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'ROOTCERT_EMAIL' }))) {
1028 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
1029 goto ROOTCERT_ERROR
;
1031 if ( length ( $cgiparams { 'ROOTCERT_EMAIL' }) > 40 ) {
1032 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
1033 goto ROOTCERT_ERROR
;
1035 if ( $cgiparams { 'ROOTCERT_OU' } ne '' && $cgiparams { 'ROOTCERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1036 $errormessage = $Lang :: tr
{ 'invalid input for department' };
1037 goto ROOTCERT_ERROR
;
1039 if ( $cgiparams { 'ROOTCERT_CITY' } ne '' && $cgiparams { 'ROOTCERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1040 $errormessage = $Lang :: tr
{ 'invalid input for city' };
1041 goto ROOTCERT_ERROR
;
1043 if ( $cgiparams { 'ROOTCERT_STATE' } ne '' && $cgiparams { 'ROOTCERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
1044 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
1045 goto ROOTCERT_ERROR
;
1047 if ( $cgiparams { 'ROOTCERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
1048 $errormessage = $Lang :: tr
{ 'invalid input for country' };
1049 goto ROOTCERT_ERROR
;
1052 # Copy the cgisettings to vpnsettings and save the configfile
1053 $vpnsettings { 'ROOTCERT_ORGANIZATION' } = $cgiparams { 'ROOTCERT_ORGANIZATION' };
1054 $vpnsettings { 'ROOTCERT_HOSTNAME' } = $cgiparams { 'ROOTCERT_HOSTNAME' };
1055 $vpnsettings { 'ROOTCERT_EMAIL' } = $cgiparams { 'ROOTCERT_EMAIL' };
1056 $vpnsettings { 'ROOTCERT_OU' } = $cgiparams { 'ROOTCERT_OU' };
1057 $vpnsettings { 'ROOTCERT_CITY' } = $cgiparams { 'ROOTCERT_CITY' };
1058 $vpnsettings { 'ROOTCERT_STATE' } = $cgiparams { 'ROOTCERT_STATE' };
1059 $vpnsettings { 'ROOTCERT_COUNTRY' } = $cgiparams { 'ROOTCERT_COUNTRY' };
1060 & General
:: writehash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1062 # Replace empty strings with a .
1063 ( my $ou = $cgiparams { 'ROOTCERT_OU' }) =~ s/^\s*$/\./ ;
1064 ( my $city = $cgiparams { 'ROOTCERT_CITY' }) =~ s/^\s*$/\./ ;
1065 ( my $state = $cgiparams { 'ROOTCERT_STATE' }) =~ s/^\s*$/\./ ;
1068 #system ('/bin/touch', "${General::swroot}/ovpn/gencanow");
1070 # Create the CA certificate
1071 my $pid = open ( OPENSSL
, "|-" );
1072 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1073 if ( $pid ) { # parent
1074 print OPENSSL
" $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1075 print OPENSSL
" $state \n " ;
1076 print OPENSSL
" $city \n " ;
1077 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1078 print OPENSSL
" $ou \n " ;
1079 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} CA \n " ;
1080 print OPENSSL
" $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1083 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1084 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1085 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1086 goto ROOTCERT_ERROR
;
1089 unless ( exec ( '/usr/bin/openssl' , 'req' , '-x509' , '-nodes' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
1090 '-days' , '999999' , '-newkey' , 'rsa:2048' ,
1091 '-keyout' , "${General::swroot}/ovpn/ca/cakey.pem" ,
1092 '-out' , "${General::swroot}/ovpn/ca/cacert.pem" ,
1093 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
1094 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1095 goto ROOTCERT_ERROR
;
1099 # Create the Host certificate request
1100 $pid = open ( OPENSSL
, "|-" );
1101 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto ROOTCERT_ERROR
;};
1102 if ( $pid ) { # parent
1103 print OPENSSL
" $cgiparams {'ROOTCERT_COUNTRY'} \n " ;
1104 print OPENSSL
" $state \n " ;
1105 print OPENSSL
" $city \n " ;
1106 print OPENSSL
" $cgiparams {'ROOTCERT_ORGANIZATION'} \n " ;
1107 print OPENSSL
" $ou \n " ;
1108 print OPENSSL
" $cgiparams {'ROOTCERT_HOSTNAME'} \n " ;
1109 print OPENSSL
" $cgiparams {'ROOTCERT_EMAIL'} \n " ;
1110 print OPENSSL
". \n " ;
1111 print OPENSSL
". \n " ;
1114 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1115 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1116 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1117 goto ROOTCERT_ERROR
;
1120 unless ( exec ( '/usr/bin/openssl' , 'req' , '-nodes' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
1121 '-newkey' , 'rsa:1024' ,
1122 '-keyout' , "${General::swroot}/ovpn/certs/serverkey.pem" ,
1123 '-out' , "${General::swroot}/ovpn/certs/serverreq.pem" ,
1124 '-extensions' , 'server' ,
1125 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
1126 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
1127 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1128 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1129 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1130 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1131 goto ROOTCERT_ERROR
;
1135 # Sign the host certificate request
1136 system ( '/usr/bin/openssl' , 'ca' , '-days' , '999999' ,
1137 '-batch' , '-notext' ,
1138 '-in' , "${General::swroot}/ovpn/certs/serverreq.pem" ,
1139 '-out' , "${General::swroot}/ovpn/certs/servercert.pem" ,
1140 '-extensions' , 'server' ,
1141 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
1143 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1144 unlink ( "${General::swroot}/ovpn/ca/cakey.pem" );
1145 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1146 unlink ( "${General::swroot}/ovpn/serverkey.pem" );
1147 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1148 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1149 & newcleanssldatabase
();
1150 goto ROOTCERT_ERROR
;
1152 unlink ( "${General::swroot}/ovpn/certs/serverreq.pem" );
1153 & deletebackupcert
();
1156 # Create an empty CRL
1157 system ( '/usr/bin/openssl' , 'ca' , '-gencrl' ,
1158 '-out' , "${General::swroot}/ovpn/crls/cacrl.pem" ,
1159 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
1161 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1162 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1163 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1164 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1165 unlink ( "${General::swroot}/ovpn/crls/cacrl.pem" );
1166 & cleanssldatabase
();
1167 goto ROOTCERT_ERROR
;
1169 # &cleanssldatabase();
1171 # Create Diffie Hellmann Parameter
1172 system ( '/usr/bin/openssl' , 'dhparam' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
1173 '-out' , "${General::swroot}/ovpn/ca/dh1024.pem" ,
1176 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1177 unlink ( "${General::swroot}/ovpn/certs/serverkey.pem" );
1178 unlink ( "${General::swroot}/ovpn/certs/servercert.pem" );
1179 unlink ( "${General::swroot}/ovpn/ca/cacert.pem" );
1180 unlink ( "${General::swroot}/ovpn/crls/cacrl.pem" );
1181 unlink ( "${General::swroot}/ovpn/ca/dh1024.pem" );
1182 & cleanssldatabase
();
1183 goto ROOTCERT_ERROR
;
1185 # &cleanssldatabase();
1187 goto ROOTCERT_SUCCESS
;
1190 if ( $cgiparams { 'ACTION' } ne '' ) {
1191 & Header
:: showhttpheaders
();
1192 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1193 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1194 if ( $errormessage ) {
1195 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
1196 print "<class name='base'> $errormessage " ;
1197 print " </class>" ;
1198 & Header
:: closebox
();
1200 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'generate root/host certificates'}:" );
1202 <form method='post' enctype='multipart/form-data'>
1203 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1204 <tr><td width='30%' class='base'> $Lang ::tr{'organization name'}:</td>
1205 <td width='35%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value=' $cgiparams {'ROOTCERT_ORGANIZATION'}' size='32' /></td>
1206 <td width='35%' colspan='2'> </td></tr>
1207 <tr><td class='base'> $Lang ::tr{'ipfires hostname'}:</td>
1208 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value=' $cgiparams {'ROOTCERT_HOSTNAME'}' size='32' /></td>
1209 <td colspan='2'> </td></tr>
1210 <tr><td class='base'> $Lang ::tr{'your e-mail'}: <img src='/blob.gif' alt'*' /></td>
1211 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value=' $cgiparams {'ROOTCERT_EMAIL'}' size='32' /></td>
1212 <td colspan='2'> </td></tr>
1213 <tr><td class='base'> $Lang ::tr{'your department'}: <img src='/blob.gif' alt'*' /></td>
1214 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value=' $cgiparams {'ROOTCERT_OU'}' size='32' /></td>
1215 <td colspan='2'> </td></tr>
1216 <tr><td class='base'> $Lang ::tr{'city'}: <img src='/blob.gif' alt'*' /></td>
1217 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value=' $cgiparams {'ROOTCERT_CITY'}' size='32' /></td>
1218 <td colspan='2'> </td></tr>
1219 <tr><td class='base'> $Lang ::tr{'state or province'}: <img src='/blob.gif' alt'*' /></td>
1220 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value=' $cgiparams {'ROOTCERT_STATE'}' size='32' /></td>
1221 <td colspan='2'> </td></tr>
1222 <tr><td class='base'> $Lang ::tr{'country'}:</td>
1223 <td class='base'><select name='ROOTCERT_COUNTRY'>
1227 foreach my $country ( sort keys %{ Countries
:: countries
}) {
1228 print "<option value=' $Countries ::countries{ $country }'" ;
1229 if ( $Countries :: countries
{ $country } eq $cgiparams { 'ROOTCERT_COUNTRY' } ) {
1230 print " selected='selected'" ;
1232 print "> $country </option>" ;
1236 <td colspan='2'> </td></tr>
1238 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' /></td>
1239 <td> </td><td> </td></tr>
1240 <tr><td class='base' colspan='4' align='left'>
1241 <img src='/blob.gif' valign='top' alt='*' /> $Lang ::tr{'this field may be blank'}</td></tr>
1242 <tr><td class='base' colspan='4' align='left'>
1243 <b><font color='${Header::colourred}'> $Lang ::tr{'capswarning'}</font></b>:
1244 $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'}
1246 <tr><td colspan='4' bgcolor='#000000'><img src='/images/null.gif' width='1' height='1' border='0' /></td></tr>
1247 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'upload p12 file'}:</td>
1248 <td nowrap='nowrap'><input type='file' name='FH' size='32'></td>
1249 <td colspan='2'> </td></tr>
1250 <tr><td class='base'> $Lang ::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' ></td>
1251 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value=' $cgiparams {'P12_PASS'}' size='32' /></td>
1252 <td colspan='2'> </td></tr>
1254 <td><input type='submit' name='ACTION' value=' $Lang ::tr{'upload p12 file'}' /></td>
1255 <td colspan='2'> </td></tr>
1256 <tr><td class='base' colspan='4' align='left'>
1257 <img src='/blob.gif' valign='top' al='*' > $Lang ::tr{'this field may be blank'}</td></tr>
1261 & Header
:: closebox
();
1263 & Header
:: closebigbox
();
1264 & Header
:: closepage
();
1269 system ( "chmod 600 ${General::swroot}/ovpn/certs/serverkey.pem" );
1270 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1271 # $vpnsettings{'ENABLE_BLUE'} eq 'on') {
1272 # system('/usr/local/bin/ipsecctrl', 'S');
1276 ### Enable/Disable connection
1278 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1280 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1281 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1283 if ( $confighash { $cgiparams { 'KEY' }}) {
1284 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
1285 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
1286 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1287 #&writeserverconf();
1288 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1289 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
1290 # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
1293 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
1294 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1295 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
1296 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
1298 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1299 #&writeserverconf();
1302 $errormessage = $Lang :: tr
{ 'invalid key' };
1306 ### Download OpenVPN client package
1308 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'dl client arch' }) {
1309 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1310 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1312 my $clientovpn = '' ;
1314 my $tempdir = tempdir
( CLEANUP
=> 1 );
1315 my $zippath = " $tempdir /" ;
1316 my $zipname = " $confighash { $cgiparams {'KEY'}}[1]-TO-IPFire.zip" ;
1317 my $zippathname = " $zippath $zipname " ;
1318 $clientovpn = " $confighash { $cgiparams {'KEY'}}[1]-TO-IPFire.ovpn" ;
1319 open ( CLIENTCONF
, "> $tempdir / $clientovpn " ) or die "Unable to open tempfile: $!" ;
1320 flock CLIENTCONF
, 2 ;
1322 my $zip = Archive
:: Zip
-> new ();
1324 print CLIENTCONF
"#OpenVPN Server conf \r\n " ;
1325 print CLIENTCONF
"tls-client \r\n " ;
1326 print CLIENTCONF
"client \r\n " ;
1327 print CLIENTCONF
"dev $vpnsettings {'DDEVICE'} \r\n " ;
1328 print CLIENTCONF
"proto $vpnsettings {'DPROTOCOL'} \r\n " ;
1329 print CLIENTCONF
" $vpnsettings {'DDEVICE'}-mtu $vpnsettings {'DMTU'} \r\n " ;
1330 if ( $vpnsettings { 'ENABLED' } eq 'on' ){
1331 print CLIENTCONF
"remote $vpnsettings {'VPN_IP'} $vpnsettings {'DDEST_PORT'} \r\n " ;
1332 if ( $vpnsettings { 'ENABLED_BLUE' } eq 'on' && (& haveBlueNet
())){
1333 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Blue interface \r\n " ;
1334 print CLIENTCONF
";remote $netsettings {'BLUE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
1336 if ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
1337 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Orange interface \r\n " ;
1338 print CLIENTCONF
";remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
1340 } elsif ( $vpnsettings { 'ENABLED_BLUE' } eq 'on' && (& haveBlueNet
())){
1341 print CLIENTCONF
"remote $netsettings {'BLUE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
1342 if ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
1343 print CLIENTCONF
"#Coment the above line and uncoment the next line, if you want to connect on the Orange interface \r\n " ;
1344 print CLIENTCONF
";remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
1346 } elsif ( $vpnsettings { 'ENABLED_ORANGE' } eq 'on' && (& haveOrangeNet
())){
1347 print CLIENTCONF
"remote $netsettings {'ORANGE_ADDRESS'} $vpnsettings {'DDEST_PORT'} \r\n " ;
1350 if ( $confighash { $cgiparams { 'KEY' }}[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" ) {
1351 print CLIENTCONF
"pkcs12 $confighash { $cgiparams {'KEY'}}[1].p12 \r\n " ;
1352 $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 " ;
1354 print CLIENTCONF
"ca cacert.pem \r\n " ;
1355 print CLIENTCONF
"cert $confighash { $cgiparams {'KEY'}}[1]cert.pem \r\n " ;
1356 print CLIENTCONF
"key $confighash { $cgiparams {'KEY'}}[1].key \r\n " ;
1357 $zip -> addFile ( "${General::swroot}/ovpn/ca/cacert.pem" , "cacert.pem" ) or die "Can't add file cacert.pem \n " ;
1358 $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 " ;
1360 print CLIENTCONF
"cipher $vpnsettings {DCIPHER} \r\n " ;
1361 if ( $vpnsettings { DCOMPLZO
} eq 'on' ) {
1362 print CLIENTCONF
"comp-lzo \r\n " ;
1364 print CLIENTCONF
"verb 3 \r\n " ;
1365 print CLIENTCONF
"ns-cert-type server \r\n " ;
1367 $zip -> addFile ( " $tempdir / $clientovpn " , $clientovpn ) or die "Can't add file $clientovpn \n " ;
1368 my $status = $zip -> writeToFileNamed ( $zippathname );
1370 open ( DLFILE
, "< $zippathname " ) or die "Unable to open $zippathname : $!" ;
1371 @fileholder = < DLFILE
>;
1372 print "Content-Type:application/x-download \n " ;
1373 print "Content-Disposition:attachment;filename= $zipname \n\n " ;
1378 ### Remove connection
1380 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
1381 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1382 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1384 if ( $confighash { $cgiparams { 'KEY' }}) {
1385 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1386 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
1387 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
1390 my $temp = `/usr/bin/openssl ca -revoke ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf` ;
1391 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1392 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1393 delete $confighash { $cgiparams { 'KEY' }};
1394 my $temp2 = `/usr/bin/openssl ca -gencrl -out ${General::swroot}/ovpn/crls/cacrl.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf` ;
1395 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1396 #&writeserverconf();
1398 $errormessage = $Lang :: tr
{ 'invalid key' };
1401 ### Download PKCS12 file
1403 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download pkcs12 file' }) {
1404 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1406 print "Content-Disposition: filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . ".p12 \r\n " ;
1407 print "Content-Type: application/octet-stream \r\n\r\n " ;
1408 print `/bin/cat ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12` ;
1412 ### Display certificate
1414 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show certificate' }) {
1415 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1417 if ( - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1418 & Header
:: showhttpheaders
();
1419 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1420 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1421 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'certificate'}:" );
1422 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1423 $output = & Header
:: cleanhtml
( $output , "y" );
1424 print "<pre> $output </pre> \n " ;
1425 & Header
:: closebox
();
1426 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1427 & Header
:: closebigbox
();
1428 & Header
:: closepage
();
1432 ### Display Certificate Revoke List
1434 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'show crl' }) {
1435 # &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1437 if ( - f
"${General::swroot}/ovpn/crls/cacrl.pem" ) {
1438 & Header
:: showhttpheaders
();
1439 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1440 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1441 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'crl'}:" );
1442 my $output = `/usr/bin/openssl crl -text -noout -in ${General::swroot}/ovpn/crls/cacrl.pem` ;
1443 $output = & Header
:: cleanhtml
( $output , "y" );
1444 print "<pre> $output </pre> \n " ;
1445 & Header
:: closebox
();
1446 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1447 & Header
:: closebigbox
();
1448 & Header
:: closepage
();
1453 ### Advanced Server Settings
1456 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'advanced server' }) {
1460 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%cgiparams );
1462 # if ($cgiparams{'CLIENT2CLIENT'} eq '') {
1463 # $cgiparams{'CLIENT2CLIENT'} = 'on';
1466 if ( $cgiparams { 'MAX_CLIENTS' } eq '' ) {
1467 $cgiparams { 'MAX_CLIENTS' } = '100' ;
1470 if ( $cgiparams { 'KEEPALIVE_1' } eq '' ) {
1471 $cgiparams { 'KEEPALIVE_1' } = '10' ;
1473 if ( $cgiparams { 'KEEPALIVE_2' } eq '' ) {
1474 $cgiparams { 'KEEPALIVE_2' } = '60' ;
1476 if ( $cgiparams { 'LOG_VERB' } eq '' ) {
1477 $cgiparams { 'LOG_VERB' } = '3' ;
1479 $checked { 'CLIENT2CLIENT' }{ 'off' } = '' ;
1480 $checked { 'CLIENT2CLIENT' }{ 'on' } = '' ;
1481 $checked { 'CLIENT2CLIENT' }{ $cgiparams { 'CLIENT2CLIENT' }} = 'CHECKED' ;
1482 $checked { 'REDIRECT_GW_DEF1' }{ 'off' } = '' ;
1483 $checked { 'REDIRECT_GW_DEF1' }{ 'on' } = '' ;
1484 $checked { 'REDIRECT_GW_DEF1' }{ $cgiparams { 'REDIRECT_GW_DEF1' }} = 'CHECKED' ;
1485 $selected { 'LOG_VERB' }{ '1' } = '' ;
1486 $selected { 'LOG_VERB' }{ '2' } = '' ;
1487 $selected { 'LOG_VERB' }{ '3' } = '' ;
1488 $selected { 'LOG_VERB' }{ '4' } = '' ;
1489 $selected { 'LOG_VERB' }{ '5' } = '' ;
1490 $selected { 'LOG_VERB' }{ '6' } = '' ;
1491 $selected { 'LOG_VERB' }{ '7' } = '' ;
1492 $selected { 'LOG_VERB' }{ '8' } = '' ;
1493 $selected { 'LOG_VERB' }{ '9' } = '' ;
1494 $selected { 'LOG_VERB' }{ '10' } = '' ;
1495 $selected { 'LOG_VERB' }{ '11' } = '' ;
1496 $selected { 'LOG_VERB' }{ '0' } = '' ;
1497 $selected { 'LOG_VERB' }{ $cgiparams { 'LOG_VERB' }} = 'SELECTED' ;
1499 & Header
:: showhttpheaders
();
1500 & Header
:: openpage
( $Lang :: tr
{ 'status ovpn' }, 1 , '' );
1501 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
1502 if ( $errormessage ) {
1503 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
1504 print "<class name='base'> $errormessage \n " ;
1505 print " </class> \n " ;
1506 & Header
:: closebox
();
1508 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'advanced server' });
1510 <form method='post' enctype='multipart/form-data'>
1511 <table width='100%'>
1513 <td colspan='4'><b> $Lang ::tr{'dhcp-options'}</b></td>
1516 <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
1519 <td class='base'>Domain</td>
1520 <td><input type='TEXT' name='DHCP_DOMAIN' value=' $cgiparams {'DHCP_DOMAIN'}' size='30' /></td>
1523 <td class='base'>DNS</td>
1524 <td><input type='TEXT' name='DHCP_DNS' value=' $cgiparams {'DHCP_DNS'}' size='30' /></td>
1527 <td class='base'>WINS</td>
1528 <td><input type='TEXT' name='DHCP_WINS' value=' $cgiparams {'DHCP_WINS'}' size='30' /></td>
1532 <table width='100%'>
1534 <td class'base'><b> $Lang ::tr{'misc-options'}</b></td>
1537 <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
1540 <td class='base'>Client-To-Client</td>
1541 <td><input type='checkbox' name='CLIENT2CLIENT' $checked {'CLIENT2CLIENT'}{'on'} /></td>
1544 <td class='base'>Redirect-Gateway def1</td>
1545 <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked {'REDIRECT_GW_DEF1'}{'on'} /></td>
1548 <td class='base'>Max-Clients</td>
1549 <td><input type='text' name='MAX_CLIENTS' value=' $cgiparams {'MAX_CLIENTS'}' size='30' /></td>
1551 <td class='base'>Keppalive (ping/ping-restart)</td>
1552 <td><input type='TEXT' name='KEEPALIVE_1' value=' $cgiparams {'KEEPALIVE_1'}' size='30' /></td>
1553 <td><input type='TEXT' name='KEEPALIVE_2' value=' $cgiparams {'KEEPALIVE_2'}' size='30' /></td>
1557 <table width='100%'>
1559 <td class'base'><b> $Lang ::tr{'log-options'}</b></td>
1562 <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
1565 <tr><td class='base'>VERB</td>
1566 <td><select name='LOG_VERB'><option value='1' $selected {'LOG_VERB'}{'1'}>1</option>
1567 <option value='2' $selected {'LOG_VERB'}{'2'}>2</option>
1568 <option value='3' $selected {'LOG_VERB'}{'3'}>3</option>
1569 <option value='4' $selected {'LOG_VERB'}{'4'}>4</option>
1570 <option value='5' $selected {'LOG_VERB'}{'5'}>5</option>
1571 <option value='6' $selected {'LOG_VERB'}{'6'}>6</option>
1572 <option value='7' $selected {'LOG_VERB'}{'7'}>7</option>
1573 <option value='8' $selected {'LOG_VERB'}{'8'}>8</option>
1574 <option value='9' $selected {'LOG_VERB'}{'9'}>9</option>
1575 <option value='10' $selected {'LOG_VERB'}{'10'}>10</option>
1576 <option value='11' $selected {'LOG_VERB'}{'11'}>11</option>
1577 <option value='0' $selected {'LOG_VERB'}{'0'}>0</option></select></td>
1580 <table width='100%'>
1583 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save-adv-options'}' /></td>
1584 <td allign='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'cancel-adv-options'}' /></td>
1592 & Header
:: closebox
();
1593 # print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
1594 & Header
:: closebigbox
();
1595 & Header
:: closepage
();
1599 ### Openvpn Connections Statistics
1601 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'ovpn con stat' }) {
1602 & Header
:: showhttpheaders
();
1603 & Header
:: openpage
( $Lang :: tr
{ 'ovpn con stat' }, 1 , '' );
1604 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1605 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'ovpn con stat' });
1608 # <td><b>$Lang::tr{'protocol'}</b></td>
1609 # protocol temp removed
1611 <table width='100%' border='0' cellpadding='2' cellspacing='0'>
1613 <td><b> $Lang ::tr{'common name'}</b></td>
1614 <td><b> $Lang ::tr{'real address'}</b></td>
1615 <td><b> $Lang ::tr{'virtual address'}</b></td>
1616 <td><b> $Lang ::tr{'loged in at'}</b></td>
1617 <td><b> $Lang ::tr{'bytes sent'}</b></td>
1618 <td><b> $Lang ::tr{'bytes received'}</b></td>
1619 <td><b> $Lang ::tr{'last activity'}</b></td>
1623 my $filename = "/var/log/ovpnserver.log" ;
1624 open ( FILE
, $filename ) or die 'Unable to open config file.' ;
1625 my @current = < FILE
>;
1634 my %userlookup = ();
1635 foreach my $line ( @current )
1638 if ( $line =~ /^Updated,(.+)/ ){
1639 @match = split ( /^Updated,(.+)/ , $line );
1640 $status = $match [ 1 ];
1643 if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ ) {
1644 @match = split ( m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ , $line );
1645 if ( $match [ 1 ] ne "Common Name" ) {
1647 $userlookup { $match [ 2 ]} = $uid ;
1648 $users [ $uid ]{ 'CommonName' } = $match [ 1 ];
1649 $users [ $uid ]{ 'RealAddress' } = $match [ 2 ];
1650 $users [ $uid ]{ 'BytesReceived' } = & sizeformat
( $match [ 3 ]);
1651 $users [ $uid ]{ 'BytesSent' } = & sizeformat
( $match [ 4 ]);
1652 $users [ $uid ]{ 'Since' } = $match [ 5 ];
1653 $users [ $uid ]{ 'Proto' } = $proto ;
1657 if ( $line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/ ) {
1658 @match = split ( m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/ , $line );
1659 if ( $match [ 1 ] ne "Virtual Address" ) {
1660 $address = $match [ 3 ];
1661 #find the uid in the lookup table
1662 $uid = $userlookup { $address };
1663 $users [ $uid ]{ 'VirtualAddress' } = $match [ 1 ];
1664 $users [ $uid ]{ 'LastRef' } = $match [ 4 ];
1670 for ( my $idx = 1 ; $idx <= $user2 ; $idx ++){
1672 print "<tr bgcolor=' $color {'color20'}'> \n " ;
1674 print "<tr bgcolor=' $color {'color22'}'> \n " ;
1676 print "<td align='left'> $users [ $idx -1]{'CommonName'}</td>" ;
1677 print "<td align='left'> $users [ $idx -1]{'RealAddress'}</td>" ;
1678 print "<td align='left'> $users [ $idx -1]{'VirtualAddress'}</td>" ;
1679 print "<td align='left'> $users [ $idx -1]{'Since'}</td>" ;
1680 print "<td align='left'> $users [ $idx -1]{'BytesSent'}</td>" ;
1681 print "<td align='left'> $users [ $idx -1]{'BytesReceived'}</td>" ;
1682 print "<td align='left'> $users [ $idx -1]{'LastRef'}</td>" ;
1683 # print "<td align='left'>$users[$idx-1]{'Proto'}</td>";
1689 <table width='100%' border='0' cellpadding='2' cellspacing='0'>
1694 <tr><td align='center' > $Lang ::tr{'the statistics were last updated at'} <b> $status </b></td></tr>
1698 & Header
:: closebox
();
1699 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'> $Lang ::tr{'back'}</a></div>" ;
1700 & Header
:: closebigbox
();
1701 & Header
:: closepage
();
1705 ### Download Certificate
1707 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'download certificate' }) {
1708 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1710 if ( - f
"${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" ) {
1711 print "Content-Disposition: filename=" . $confighash { $cgiparams { 'KEY' }}[ 1 ] . "cert.pem \r\n " ;
1712 print "Content-Type: application/octet-stream \r\n\r\n " ;
1713 print `/bin/cat ${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem` ;
1718 ### Enable/Disable connection
1720 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'toggle enable disable' }) {
1722 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1723 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1725 if ( $confighash { $cgiparams { 'KEY' }}) {
1726 if ( $confighash { $cgiparams { 'KEY' }}[ 0 ] eq 'off' ) {
1727 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'on' ;
1728 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1729 #&writeserverconf();
1730 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1731 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
1732 # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
1735 $confighash { $cgiparams { 'KEY' }}[ 0 ] = 'off' ;
1736 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1737 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
1738 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
1740 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1741 #&writeserverconf();
1744 $errormessage = $Lang :: tr
{ 'invalid key' };
1748 ### Restart connection
1750 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'restart' }) {
1751 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1752 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1754 if ( $confighash { $cgiparams { 'KEY' }}) {
1755 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1756 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
1757 # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
1760 $errormessage = $Lang :: tr
{ 'invalid key' };
1764 ### Remove connection
1766 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'remove' }) {
1767 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1768 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1770 if ( $confighash { $cgiparams { 'KEY' }}) {
1771 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1772 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
1773 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
1775 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1]cert.pem" );
1776 unlink ( "${General::swroot}/ovpn/certs/ $confighash { $cgiparams {'KEY'}}[1].p12" );
1777 delete $confighash { $cgiparams { 'KEY' }};
1778 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1779 #&writeserverconf();
1781 $errormessage = $Lang :: tr
{ 'invalid key' };
1786 ### Choose between adding a host-net or net-net connection
1788 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' } && $cgiparams { 'TYPE' } eq '' ) {
1789 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1790 & Header
:: showhttpheaders
();
1791 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
1792 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , '' );
1793 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'connection type' });
1795 <b> $Lang ::tr{'connection type'}:</b><br />
1796 <table><form method='post'>
1797 <tr><td><input type='radio' name='TYPE' value='host' checked /></td>
1798 <td class='base'> $Lang ::tr{'host to net vpn'}</td></tr>
1799 <tr><td><input type='radio' name='TYPE' value='net' disabled='disabled' /></td>
1800 <td class='base'> $Lang ::tr{'net to net vpn'}</td></tr>
1801 <tr><td align='center' colspan='2'><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td></tr>
1805 & Header
:: closebox
();
1806 & Header
:: closebigbox
();
1807 & Header
:: closepage
();
1810 ### Adding a new connection
1812 } elsif (( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'add' }) ||
1813 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) ||
1814 ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' } && $cgiparams { 'ADVANCED' } eq '' )) {
1816 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%vpnsettings );
1817 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
1818 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
1820 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'edit' }) {
1821 if (! $confighash { $cgiparams { 'KEY' }}[ 0 ]) {
1822 $errormessage = $Lang :: tr
{ 'invalid key' };
1825 $cgiparams { 'ENABLED' } = $confighash { $cgiparams { 'KEY' }}[ 0 ];
1826 $cgiparams { 'NAME' } = $confighash { $cgiparams { 'KEY' }}[ 1 ];
1827 $cgiparams { 'TYPE' } = $confighash { $cgiparams { 'KEY' }}[ 3 ];
1828 $cgiparams { 'AUTH' } = $confighash { $cgiparams { 'KEY' }}[ 4 ];
1829 $cgiparams { 'PSK' } = $confighash { $cgiparams { 'KEY' }}[ 5 ];
1830 $cgiparams { 'SIDE' } = $confighash { $cgiparams { 'KEY' }}[ 6 ];
1831 $cgiparams { 'LOCAL_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 8 ];
1832 $cgiparams { 'REMOTE' } = $confighash { $cgiparams { 'KEY' }}[ 10 ];
1833 $cgiparams { 'REMOTE_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 11 ];
1834 $cgiparams { 'REMARK' } = $confighash { $cgiparams { 'KEY' }}[ 25 ];
1835 $cgiparams { 'INTERFACE' } = $confighash { $cgiparams { 'KEY' }}[ 26 ];
1837 $cgiparams { 'OVPN_SUBNET' } = $confighash { $cgiparams { 'KEY' }}[ 27 ];
1838 $cgiparams { 'PROTOCOL' } = $confighash { $cgiparams { 'KEY' }}[ 28 ];
1839 $cgiparams { 'DEST_PORT' } = $confighash { $cgiparams { 'KEY' }}[ 29 ];
1840 $cgiparams { 'COMPLZO' } = $confighash { $cgiparams { 'KEY' }}[ 30 ];
1841 $cgiparams { 'MTU' } = $confighash { $cgiparams { 'KEY' }}[ 31 ];
1843 #ab hiere error uebernehmen
1844 } elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
1845 $cgiparams { 'REMARK' } = & Header
:: cleanhtml
( $cgiparams { 'REMARK' });
1846 if ( $cgiparams { 'TYPE' } !~ /^(host|net)$/ ) {
1847 $errormessage = $Lang :: tr
{ 'connection type is invalid' };
1852 if ( $cgiparams { 'NAME' } !~ /^[a-zA-Z0-9]+$/ ) {
1853 $errormessage = $Lang :: tr
{ 'name must only contain characters' };
1857 if ( $cgiparams { 'NAME' } =~ /^(host|01|block|private|clear|packetdefault)$/ ) {
1858 $errormessage = $Lang :: tr
{ 'name is invalid' };
1862 if ( length ( $cgiparams { 'NAME' }) > 60 ) {
1863 $errormessage = $Lang :: tr
{ 'name too long' };
1867 # if (($cgiparams{'TYPE'} eq 'net') && ($cgiparams{'SIDE'} !~ /^(left|right)$/)) {
1868 # $errormessage = $Lang::tr{'ipfire side is invalid'};
1869 # goto VPNCONF_ERROR;
1872 # Check if there is no other entry with this name
1873 if (! $cgiparams { 'KEY' }) {
1874 foreach my $key ( keys %confighash ) {
1875 if ( $confighash { $key }[ 1 ] eq $cgiparams { 'NAME' }) {
1876 $errormessage = $Lang :: tr
{ 'a connection with this name already exists' };
1882 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! $cgiparams { 'REMOTE' })) {
1883 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1887 if ( $cgiparams { 'REMOTE' }) {
1888 if (! & General
:: validip
( $cgiparams { 'REMOTE' })) {
1889 if (! & General
:: validfqdn
( $cgiparams { 'REMOTE' })) {
1890 $errormessage = $Lang :: tr
{ 'invalid input for remote host/ip' };
1893 if (& valid_dns_host
( $cgiparams { 'REMOTE' })) {
1894 $warnmessage = " $Lang ::tr{'check vpn lr'} $cgiparams {'REMOTE'}. $Lang ::tr{'dns check failed'}" ;
1899 if ( $cgiparams { 'TYPE' } ne 'host' ) {
1900 unless (& General
:: validipandmask
( $cgiparams { 'LOCAL_SUBNET' })) {
1901 $errormessage = $Lang :: tr
{ 'local subnet is invalid' };
1902 goto VPNCONF_ERROR
;}
1904 # Check if there is no other entry without IP-address and PSK
1905 if ( $cgiparams { 'REMOTE' } eq '' ) {
1906 foreach my $key ( keys %confighash ) {
1907 if (( $cgiparams { 'KEY' } ne $key ) &&
1908 ( $confighash { $key }[ 4 ] eq 'psk' || $cgiparams { 'AUTH' } eq 'psk' ) &&
1909 $confighash { $key }[ 10 ] eq '' ) {
1910 $errormessage = $Lang :: tr
{ 'you can only define one roadwarrior connection when using pre-shared key authentication' };
1915 if (( $cgiparams { 'TYPE' } eq 'net' ) && (! & General
:: validipandmask
( $cgiparams { 'REMOTE_SUBNET' }))) {
1916 $errormessage = $Lang :: tr
{ 'remote subnet is invalid' };
1920 if ( $cgiparams { 'ENABLED' } !~ /^(on|off)$/ ) {
1921 $errormessage = $Lang :: tr
{ 'invalid input' };
1924 if ( $cgiparams { 'EDIT_ADVANCED' } !~ /^(on|off)$/ ) {
1925 $errormessage = $Lang :: tr
{ 'invalid input' };
1930 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
1931 # if (! length($cgiparams{'PSK'}) ) {
1932 # $errormessage = $Lang::tr{'pre-shared key is too short'};
1933 # goto VPNCONF_ERROR;
1935 # if ($cgiparams{'PSK'} =~ /['",&]/) {
1936 # $errormessage = $Lang::tr{'invalid characters found in pre-shared key'};
1937 # goto VPNCONF_ERROR;
1939 } elsif ( $cgiparams { 'AUTH' } eq 'certreq' ) {
1940 if ( $cgiparams { 'KEY' }) {
1941 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1944 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1945 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1949 # Move uploaded certificate request to a temporary file
1950 ( my $fh , my $filename ) = tempfile
( );
1951 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
1956 # Sign the certificate request and move it
1957 # Sign the host certificate request
1958 system ( '/usr/bin/openssl' , 'ca' , '-days' , '999999' ,
1959 '-batch' , '-notext' ,
1961 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
1962 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
1964 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
1966 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
1967 & newcleanssldatabase
();
1971 & deletebackupcert
();
1974 my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem` ;
1975 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
1977 $temp =~ s
+/ Email
+, E
+;
1978 $temp =~ s/ ST=/ S=/ ;
1979 $cgiparams { 'CERT_NAME' } = $temp ;
1980 $cgiparams { 'CERT_NAME' } =~ s/,//g ;
1981 $cgiparams { 'CERT_NAME' } =~ s/\'//g ;
1982 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
1983 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
1986 } elsif ( $cgiparams { 'AUTH' } eq 'certfile' ) {
1987 if ( $cgiparams { 'KEY' }) {
1988 $errormessage = $Lang :: tr
{ 'cant change certificates' };
1991 if ( ref ( $cgiparams { 'FH' }) ne 'Fh' ) {
1992 $errormessage = $Lang :: tr
{ 'there was no file upload' };
1995 # Move uploaded certificate to a temporary file
1996 ( my $fh , my $filename ) = tempfile
( );
1997 if ( copy
( $cgiparams { 'FH' }, $fh ) != 1 ) {
2002 # Verify the certificate has a valid CA and move it
2004 my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/cacert.pem $filename ` ;
2005 if ( $test =~ /: OK/ ) {
2008 foreach my $key ( keys %cahash ) {
2009 $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/ $cahash { $key }[0]cert.pem $filename ` ;
2010 if ( $test =~ /: OK/ ) {
2016 $errormessage = $Lang :: tr
{ 'certificate does not have a valid ca associated with it' };
2020 move
( $filename , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
2022 $errormessage = " $Lang ::tr{'certificate file move failed'}: $!" ;
2028 my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem` ;
2029 $temp =~ /Subject:.*CN=(.*)[\n]/ ;
2031 $temp =~ s
+/ Email
+, E
+;
2032 $temp =~ s/ ST=/ S=/ ;
2033 $cgiparams { 'CERT_NAME' } = $temp ;
2034 $cgiparams { 'CERT_NAME' } =~ s/,//g ;
2035 $cgiparams { 'CERT_NAME' } =~ s/\'//g ;
2036 if ( $cgiparams { 'CERT_NAME' } eq '' ) {
2037 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
2038 $errormessage = $Lang :: tr
{ 'could not retrieve common name from certificate' };
2041 } elsif ( $cgiparams { 'AUTH' } eq 'certgen' ) {
2042 if ( $cgiparams { 'KEY' }) {
2043 $errormessage = $Lang :: tr
{ 'cant change certificates' };
2046 # Validate input since the form was submitted
2047 if ( length ( $cgiparams { 'CERT_NAME' }) > 60 ) {
2048 $errormessage = $Lang :: tr
{ 'name too long' };
2051 if ( $cgiparams { 'CERT_NAME' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
2052 $errormessage = $Lang :: tr
{ 'invalid input for name' };
2055 if ( $cgiparams { 'CERT_EMAIL' } ne '' && (! & General
:: validemail
( $cgiparams { 'CERT_EMAIL' }))) {
2056 $errormessage = $Lang :: tr
{ 'invalid input for e-mail address' };
2059 if ( length ( $cgiparams { 'CERT_EMAIL' }) > 40 ) {
2060 $errormessage = $Lang :: tr
{ 'e-mail address too long' };
2063 if ( $cgiparams { 'CERT_OU' } ne '' && $cgiparams { 'CERT_OU' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
2064 $errormessage = $Lang :: tr
{ 'invalid input for department' };
2067 if ( length ( $cgiparams { 'CERT_ORGANIZATION' }) > 60 ) {
2068 $errormessage = $Lang :: tr
{ 'organization too long' };
2071 if ( $cgiparams { 'CERT_ORGANIZATION' } !~ /^[a-zA-Z0-9 ,\.\-_]+$/ ) {
2072 $errormessage = $Lang :: tr
{ 'invalid input for organization' };
2075 if ( $cgiparams { 'CERT_CITY' } ne '' && $cgiparams { 'CERT_CITY' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
2076 $errormessage = $Lang :: tr
{ 'invalid input for city' };
2079 if ( $cgiparams { 'CERT_STATE' } ne '' && $cgiparams { 'CERT_STATE' } !~ /^[a-zA-Z0-9 ,\.\-_]*$/ ) {
2080 $errormessage = $Lang :: tr
{ 'invalid input for state or province' };
2083 if ( $cgiparams { 'CERT_COUNTRY' } !~ /^[A-Z]*$/ ) {
2084 $errormessage = $Lang :: tr
{ 'invalid input for country' };
2087 if ( $cgiparams { 'CERT_PASS1' } ne '' && $cgiparams { 'CERT_PASS2' } ne '' ){
2088 if ( length ( $cgiparams { 'CERT_PASS1' }) < 5 ) {
2089 $errormessage = $Lang :: tr
{ 'password too short' };
2093 if ( $cgiparams { 'CERT_PASS1' } ne $cgiparams { 'CERT_PASS2' }) {
2094 $errormessage = $Lang :: tr
{ 'passwords do not match' };
2098 # Replace empty strings with a .
2099 ( my $ou = $cgiparams { 'CERT_OU' }) =~ s/^\s*$/\./ ;
2100 ( my $city = $cgiparams { 'CERT_CITY' }) =~ s/^\s*$/\./ ;
2101 ( my $state = $cgiparams { 'CERT_STATE' }) =~ s/^\s*$/\./ ;
2103 # Create the Host certificate request client
2104 my $pid = open ( OPENSSL
, "|-" );
2105 $SIG { ALRM
} = sub { $errormessage = $Lang :: tr
{ 'broken pipe' }; goto VPNCONF_ERROR
;};
2106 if ( $pid ) { # parent
2107 print OPENSSL
" $cgiparams {'CERT_COUNTRY'} \n " ;
2108 print OPENSSL
" $state \n " ;
2109 print OPENSSL
" $city \n " ;
2110 print OPENSSL
" $cgiparams {'CERT_ORGANIZATION'} \n " ;
2111 print OPENSSL
" $ou \n " ;
2112 print OPENSSL
" $cgiparams {'CERT_NAME'} \n " ;
2113 print OPENSSL
" $cgiparams {'CERT_EMAIL'} \n " ;
2114 print OPENSSL
". \n " ;
2115 print OPENSSL
". \n " ;
2118 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
2119 unlink ( "${General::swroot}ovpn/certs/ $cgiparams {'NAME'}key.pem" );
2120 unlink ( "${General::swroot}ovpn/certs/ $cgiparams {'NAME'}req.pem" );
2124 unless ( exec ( '/usr/bin/openssl' , 'req' , '-nodes' , '-rand' , '/proc/interrupts:/proc/net/rt_cache' ,
2125 '-newkey' , 'rsa:1024' ,
2126 '-keyout' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" ,
2127 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" ,
2128 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
2129 $errormessage = " $Lang ::tr{'cant start openssl'}: $!" ;
2130 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
2131 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
2136 # Sign the host certificate request
2137 system ( '/usr/bin/openssl' , 'ca' , '-days' , '999999' ,
2138 '-batch' , '-notext' ,
2139 '-in' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" ,
2140 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
2141 '-config' , "${General::swroot}/ovpn/openssl/ovpn.cnf" );
2143 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
2144 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
2145 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
2146 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
2147 & newcleanssldatabase
();
2150 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}req.pem" );
2151 & deletebackupcert
();
2154 # Create the pkcs12 file
2155 system ( '/usr/bin/openssl' , 'pkcs12' , '-export' ,
2156 '-inkey' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" ,
2157 '-in' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" ,
2158 '-name' , $cgiparams { 'NAME' },
2159 '-passout' , "pass: $cgiparams {'CERT_PASS1'}" ,
2160 '-certfile' , "${General::swroot}/ovpn/ca/cacert.pem" ,
2161 '-caname' , " $vpnsettings {'ROOTCERT_ORGANIZATION'} CA" ,
2162 '-out' , "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12" );
2164 $errormessage = " $Lang ::tr{'openssl produced an error'}: $?" ;
2165 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
2166 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}cert.pem" );
2167 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}.p12" );
2170 unlink ( "${General::swroot}/ovpn/certs/ $cgiparams {'NAME'}key.pem" );
2172 } elsif ( $cgiparams { 'AUTH' } eq 'cert' ) {
2173 ; # Nothing, just editing
2175 $errormessage = $Lang :: tr
{ 'invalid input for authentication method' };
2179 # Check if there is no other entry with this common name
2180 if ((! $cgiparams { 'KEY' }) && ( $cgiparams { 'AUTH' } ne 'psk' )) {
2181 foreach my $key ( keys %confighash ) {
2182 if ( $confighash { $key }[ 2 ] eq $cgiparams { 'CERT_NAME' }) {
2183 $errormessage = $Lang :: tr
{ 'a connection with this common name already exists' };
2190 my $key = $cgiparams { 'KEY' };
2192 $key = & General
:: findhasharraykey
( \
%confighash );
2193 foreach my $i ( 0 .. 31 ) { $confighash { $key }[ $i ] = "" ;}
2195 $confighash { $key }[ 0 ] = $cgiparams { 'ENABLED' };
2196 $confighash { $key }[ 1 ] = $cgiparams { 'NAME' };
2197 if ((! $cgiparams { 'KEY' }) && $cgiparams { 'AUTH' } ne 'psk' ) {
2198 $confighash { $key }[ 2 ] = $cgiparams { 'CERT_NAME' };
2200 $confighash { $key }[ 3 ] = $cgiparams { 'TYPE' };
2201 if ( $cgiparams { 'AUTH' } eq 'psk' ) {
2202 $confighash { $key }[ 4 ] = 'psk' ;
2203 $confighash { $key }[ 5 ] = $cgiparams { 'PSK' };
2205 $confighash { $key }[ 4 ] = 'cert' ;
2207 if ( $cgiparams { 'TYPE' } eq 'net' ) {
2208 $confighash { $key }[ 6 ] = $cgiparams { 'SIDE' };
2209 $confighash { $key }[ 11 ] = $cgiparams { 'REMOTE_SUBNET' };
2211 $confighash { $key }[ 8 ] = $cgiparams { 'LOCAL_SUBNET' };
2212 $confighash { $key }[ 10 ] = $cgiparams { 'REMOTE' };
2213 $confighash { $key }[ 25 ] = $cgiparams { 'REMARK' };
2214 $confighash { $key }[ 26 ] = $cgiparams { 'INTERFACE' };
2216 $confighash { $key }[ 27 ] = $cgiparams { 'OVPN_SUBNET' };
2217 $confighash { $key }[ 28 ] = $cgiparams { 'PROTOCOL' };
2218 $confighash { $key }[ 29 ] = $cgiparams { 'DEST_PORT' };
2219 $confighash { $key }[ 30 ] = $cgiparams { 'COMPLZO' };
2220 $confighash { $key }[ 31 ] = $cgiparams { 'MTU' };
2222 & General
:: writehasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2223 if ( $cgiparams { 'EDIT_ADVANCED' } eq 'on' ) {
2224 $cgiparams { 'KEY' } = $key ;
2225 $cgiparams { 'ACTION' } = $Lang :: tr
{ 'advanced' };
2229 $cgiparams { 'ENABLED' } = 'on' ;
2230 $cgiparams { 'SIDE' } = 'left' ;
2231 if ( ! - f
"${General::swroot}/ovpn/ca/cakey.pem" ) {
2232 $cgiparams { 'AUTH' } = 'psk' ;
2233 } elsif ( ! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
2234 $cgiparams { 'AUTH' } = 'certfile' ;
2236 $cgiparams { 'AUTH' } = 'certgen' ;
2238 $cgiparams { 'LOCAL_SUBNET' } = " $netsettings {'GREEN_NETADDRESS'}/ $netsettings {'GREEN_NETMASK'}" ;
2239 $cgiparams { 'CERT_ORGANIZATION' } = $vpnsettings { 'ROOTCERT_ORGANIZATION' };
2240 $cgiparams { 'CERT_CITY' } = $vpnsettings { 'ROOTCERT_CITY' };
2241 $cgiparams { 'CERT_STATE' } = $vpnsettings { 'ROOTCERT_STATE' };
2242 $cgiparams { 'CERT_COUNTRY' } = $vpnsettings { 'ROOTCERT_COUNTRY' };
2246 $checked { 'ENABLED' }{ 'off' } = '' ;
2247 $checked { 'ENABLED' }{ 'on' } = '' ;
2248 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = 'CHECKED' ;
2249 $checked { 'ENABLED_BLUE' }{ 'off' } = '' ;
2250 $checked { 'ENABLED_BLUE' }{ 'on' } = '' ;
2251 $checked { 'ENABLED_BLUE' }{ $cgiparams { 'ENABLED_BLUE' }} = 'CHECKED' ;
2252 $checked { 'ENABLED_ORANGE' }{ 'off' } = '' ;
2253 $checked { 'ENABLED_ORANGE' }{ 'on' } = '' ;
2254 $checked { 'ENABLED_ORANGE' }{ $cgiparams { 'ENABLED_ORANGE' }} = 'CHECKED' ;
2257 $checked { 'EDIT_ADVANCED' }{ 'off' } = '' ;
2258 $checked { 'EDIT_ADVANCED' }{ 'on' } = '' ;
2259 $checked { 'EDIT_ADVANCED' }{ $cgiparams { 'EDIT_ADVANCED' }} = 'CHECKED' ;
2261 $selected { 'SIDE' }{ 'server' } = '' ;
2262 $selected { 'SIDE' }{ 'client' } = '' ;
2263 $selected { 'SIDE' }{ $cgiparams { 'SIDE' }} = 'SELECTED' ;
2265 $checked { 'AUTH' }{ 'psk' } = '' ;
2266 $checked { 'AUTH' }{ 'certreq' } = '' ;
2267 $checked { 'AUTH' }{ 'certgen' } = '' ;
2268 $checked { 'AUTH' }{ 'certfile' } = '' ;
2269 $checked { 'AUTH' }{ $cgiparams { 'AUTH' }} = 'CHECKED' ;
2271 $selected { 'INTERFACE' }{ $cgiparams { 'INTERFACE' }} = 'SELECTED' ;
2273 $checked { 'COMPLZO' }{ 'off' } = '' ;
2274 $checked { 'COMPLZO' }{ 'on' } = '' ;
2275 $checked { 'COMPLZO' }{ $cgiparams { 'COMPLZO' }} = 'CHECKED' ;
2279 & Header
:: showhttpheaders
();
2280 & Header
:: openpage
( $Lang :: tr
{ 'vpn configuration main' }, 1 , '' );
2281 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
2282 if ( $errormessage ) {
2283 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
2284 print "<class name='base'> $errormessage " ;
2285 print " </class>" ;
2286 & Header
:: closebox
();
2290 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'warning messages'}:" );
2291 print "<class name='base'> $warnmessage " ;
2292 print " </class>" ;
2293 & Header
:: closebox
();
2296 print "<form method='post' enctype='multipart/form-data'>" ;
2297 print "<input type='hidden' name='TYPE' value=' $cgiparams {'TYPE'}' />" ;
2299 if ( $cgiparams { 'KEY' }) {
2300 print "<input type='hidden' name='KEY' value=' $cgiparams {'KEY'}' />" ;
2301 print "<input type='hidden' name='AUTH' value=' $cgiparams {'AUTH'}' />" ;
2304 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'connection'}:" );
2305 print "<table width='100%'> \n " ;
2306 print "<tr><td width='25%' class='boldbase'> $Lang ::tr{'name'}:</td>" ;
2307 if ( $cgiparams { 'TYPE' } eq 'host' ) {
2308 if ( $cgiparams { 'KEY' }) {
2309 print "<td width='35%' class='base'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /> $cgiparams {'NAME'}</td> \n " ;
2311 print "<td width='35%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' maxlength='20' size='30' /></td>" ;
2313 # print "<tr><td>$Lang::tr{'interface'}</td>";
2314 # print "<td><select name='INTERFACE'>";
2315 # print "<option value='RED' $selected{'INTERFACE'}{'RED'}>RED</option>";
2316 # if ($netsettings{'BLUE_DEV'} ne '') {
2317 # print "<option value='BLUE' $selected{'INTERFACE'}{'BLUE'}>BLUE</option>";
2319 # print "<option value='GREEN' $selected{'INTERFACE'}{'GREEN'}>GREEN</option>";
2320 # print "<option value='ORANGE' $selected{'INTERFACE'}{'ORANGE'}>ORANGE</option>";
2321 # print "</select></td></tr>";
2324 print "<input type='hidden' name='INTERFACE' value='red' />" ;
2325 if ( $cgiparams { 'KEY' }) {
2326 print "<td width='25%' class='base' nowrap='nowrap'><input type='hidden' name='NAME' value=' $cgiparams {'NAME'}' /> $cgiparams {'NAME'}</td>" ;
2328 print "<td width='25%'><input type='text' name='NAME' value=' $cgiparams {'NAME'}' maxlength='20' /></td>" ;
2331 <td width='25%'> </td>
2332 <td width='25%'> </td></tr>
2333 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'Act as'}</td>
2334 <td><select name='SIDE'><option value='server' $selected {'SIDE'}{'server'}>OpenVPN Server</option>
2335 <option value='client' $selected {'SIDE'}{'client'}>OpenVPN Client</option></select></td>
2336 <td class='boldbase'> $Lang ::tr{'remote host/ip'}:</td>
2337 <td><input type='TEXT' name='REMOTE' value=' $cgiparams {'REMOTE'}' /></td></tr>
2338 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'local subnet'}</td>
2339 <td><input type='TEXT' name='LOCAL_SUBNET' value=' $cgiparams {'LOCAL_SUBNET'}' /></td>
2340 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'remote subnet'}</td>
2341 <td><input type='text' name='REMOTE_SUBNET' value=' $cgiparams {'REMOTE_SUBNET'}' /></td></tr>
2343 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn subnet'}</td>
2344 <td><input type='TEXT' name='OVPN_SUBNET' value=' $cgiparams {'OVPN_SUBNET'}' /></td></tr>
2345 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td>
2346 <td><select name='PROTOCOL'><option value='udp' $selected {'PROTOCOL'}{'udp'}>UDP</option>
2347 <option value='tcp' $selected {'PROTOCOL'}{'tcp'}>TCP</option></select></td>
2348 <td class='boldbase'> $Lang ::tr{'destination port'}:</td>
2349 <td><input type='TEXT' name='DEST_PORT' value=' $cgiparams {'DEST_PORT'}' size='5' /></td></tr>
2350 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'}</td>
2351 <td><input type='checkbox' name='COMPLZO' $checked {'COMPLZO'}{'on'} /></td>
2352 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'} <img src='/blob.gif' /></td>
2353 <td> <input type='TEXT' name='MTU' VALUE=' $cgiparams {'MTU'}'size='5' /></TD>
2359 print "<tr><td class='boldbase'> $Lang ::tr{'remark title'} <img src='/blob.gif' /></td>" ;
2360 print "<td colspan='3'><input type='text' name='REMARK' value=' $cgiparams {'REMARK'}' size='55' maxlength='50' /></td></tr>" ;
2362 # if ($cgiparams{'TYPE'} eq 'net') {
2363 print "<tr><td> $Lang ::tr{'enabled'} <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td> \n " ;
2365 # if ($cgiparams{'KEY'}) {
2366 # print "<td colspan='3'> </td></tr></table>";
2368 # print "<td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked{'EDIT_ADVANCED'}{'on'} /> $Lang::tr{'edit advanced settings when done'}</tr></table>";
2371 print "<td colspan='3'> </td></tr></table>" ;
2376 & Header
:: closebox
();
2378 if ( $cgiparams { 'KEY' } && $cgiparams { 'AUTH' } eq 'psk' ) {
2379 # &Header::openbox('100%', 'LEFT', $Lang::tr{'authentication'});
2381 # <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2382 # <tr><td class='base' width='50%'>$Lang::tr{'use a pre-shared key'}</td>
2383 # <td class='base' width='50%'><input type='text' name='PSK' size='30' value='$cgiparams{'PSK'}' /></td></tr>
2387 # &Header::closebox();
2388 } elsif (! $cgiparams { 'KEY' }) {
2390 my $cakeydisabled = '' ;
2391 my $cacrtdisabled = '' ;
2392 if ( ! - f
"${General::swroot}/ovpn/ca/cakey.pem" ) { $cakeydisabled = "disabled='disabled'" } else { $cakeydisabled = "" };
2393 if ( ! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) { $cacrtdisabled = "disabled='disabled'" } else { $cacrtdisabled = "" };
2394 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'authentication' });
2396 <table width='100%' cellpadding='0' cellspacing='5' border='0'>
2397 <tr><td colspan='3' bgcolor='#000000'><img src='/images/null.gif' width='1' height='1' border='0' /></td></tr>
2398 <tr><td><input type='radio' name='AUTH' value='certreq' $checked {'AUTH'}{'certreq'} $cakeydisabled /></td>
2399 <td class='base'> $Lang ::tr{'upload a certificate request'}</td>
2400 <td class='base' rowspan='2'><input type='file' name='FH' size='30' $cacrtdisabled ></td></tr>
2401 <tr><td><input type='radio' name='AUTH' value='certfile' $checked {'AUTH'}{'certfile'} $cacrtdisabled /></td>
2402 <td class='base'> $Lang ::tr{'upload a certificate'}</td></tr>
2403 <tr><td colspan='3' bgcolor='#000000'><img src='/images/null.gif' width='1' height='1' BORDER='0' /></td></tr>
2404 <tr><td><input type='radio' name='AUTH' value='certgen' $checked {'AUTH'}{'certgen'} $cakeydisabled /></td>
2405 <td class='base'> $Lang ::tr{'generate a certificate'}</td><td> </td></tr>
2407 <td class='base'> $Lang ::tr{'users fullname or system hostname'}:</td>
2408 <td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value=' $cgiparams {'CERT_NAME'}' SIZE='32' $cakeydisabled /></td></tr>
2410 <td class='base'> $Lang ::tr{'users email'}: <img src='/blob.gif' /></td>
2411 <td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value=' $cgiparams {'CERT_EMAIL'}' SIZE='32' $cakeydisabled /></td></tr>
2413 <td class='base'> $Lang ::tr{'users department'}: <img src='/blob.gif' /></td>
2414 <td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value=' $cgiparams {'CERT_OU'}' SIZE='32' $cakeydisabled /></td></tr>
2416 <td class='base'> $Lang ::tr{'organization name'}: <img src='/blob.gif' /></td>
2417 <td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value=' $cgiparams {'CERT_ORGANIZATION'}' SIZE='32' $cakeydisabled /></td></tr>
2419 <td class='base'> $Lang ::tr{'city'}: <img src='/blob.gif'></td>
2420 <td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value=' $cgiparams {'CERT_CITY'}' SIZE='32' $cakeydisabled /></td></tr>
2422 <td class='base'> $Lang ::tr{'state or province'}: <img src='/blob.gif' /></td>
2423 <td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value=' $cgiparams {'CERT_STATE'}' SIZE='32' $cakeydisabled /></td></tr>
2425 <td class='base'> $Lang ::tr{'country'}:</td>
2426 <td class='base'><select name='CERT_COUNTRY' $cakeydisabled >
2430 foreach my $country ( sort keys %{ Countries
:: countries
}) {
2431 print "<option value=' $Countries ::countries{ $country }'" ;
2432 if ( $Countries :: countries
{ $country } eq $cgiparams { 'CERT_COUNTRY' } ) {
2433 print " selected='selected'" ;
2435 print "> $country </option>" ;
2440 <td class='base'> $Lang ::tr{'pkcs12 file password'}:</td>
2441 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value=' $cgiparams {'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr>
2442 <tr><td> </td><td class='base'> $Lang ::tr{'pkcs12 file password'}:<BR>( $Lang ::tr{'confirmation'})</td>
2443 <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value=' $cgiparams {'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr>
2447 & Header
:: closebox
();
2450 print "<div align='center'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' />" ;
2451 if ( $cgiparams { 'KEY' }) {
2452 # print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />";
2454 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'cancel'}' /></div></form>" ;
2455 & Header
:: closebigbox
();
2456 & Header
:: closepage
();
2464 ### Default status page
2469 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%cgiparams );
2470 & General
:: readhasharray
( "${General::swroot}/ovpn/caconfig" , \
%cahash );
2471 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
2473 my @status = `/bin/cat /var/log/ovpnserver.log` ;
2475 if ( $cgiparams { 'VPN_IP' } eq '' && - e
"${General::swroot}/red/active" ) {
2476 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
2477 my $ipaddr = < IPADDR
>;
2480 $cgiparams { 'VPN_IP' } = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
2481 if ( $cgiparams { 'VPN_IP' } eq '' ) {
2482 $cgiparams { 'VPN_IP' } = $ipaddr ;
2488 if ( $cgiparams { 'DCIPHER' } eq '' ) {
2489 $cgiparams { 'DCIPHER' } = 'BF-CBC' ;
2491 # if ($cgiparams{'DCOMPLZO'} eq '') {
2492 # $cgiparams{'DCOMPLZO'} = 'on';
2494 if ( $cgiparams { 'DDEST_PORT' } eq '' ) {
2495 $cgiparams { 'DDEST_PORT' } = '1194' ;
2497 if ( $cgiparams { 'DMTU' } eq '' ) {
2498 $cgiparams { 'DMTU' } = '1400' ;
2500 if ( $cgiparams { 'DOVPN_SUBNET' } eq '' ) {
2501 $cgiparams { 'DOVPN_SUBNET' } = '10.' . int ( rand ( 256 )) . '.' . int ( rand ( 256 )) . '.0/255.255.255.0' ;
2504 $checked { 'ENABLED' }{ 'off' } = '' ;
2505 $checked { 'ENABLED' }{ 'on' } = '' ;
2506 $checked { 'ENABLED' }{ $cgiparams { 'ENABLED' }} = 'CHECKED' ;
2507 $checked { 'ENABLED_BLUE' }{ 'off' } = '' ;
2508 $checked { 'ENABLED_BLUE' }{ 'on' } = '' ;
2509 $checked { 'ENABLED_BLUE' }{ $cgiparams { 'ENABLED_BLUE' }} = 'CHECKED' ;
2510 $checked { 'ENABLED_ORANGE' }{ 'off' } = '' ;
2511 $checked { 'ENABLED_ORANGE' }{ 'on' } = '' ;
2512 $checked { 'ENABLED_ORANGE' }{ $cgiparams { 'ENABLED_ORANGE' }} = 'CHECKED' ;
2516 $selected { 'DDEVICE' }{ 'tun' } = '' ;
2517 $selected { 'DDEVICE' }{ 'tap' } = '' ;
2518 $selected { 'DDEVICE' }{ $cgiparams { 'DDEVICE' }} = 'SELECTED' ;
2520 $selected { 'DPROTOCOL' }{ 'udp' } = '' ;
2521 $selected { 'DPROTOCOL' }{ 'tcp' } = '' ;
2522 $selected { 'DPROTOCOL' }{ $cgiparams { 'DPROTOCOL' }} = 'SELECTED' ;
2524 $selected { 'DCIPHER' }{ 'DES-CBC' } = '' ;
2525 $selected { 'DCIPHER' }{ 'DES-EDE-CBC' } = '' ;
2526 $selected { 'DCIPHER' }{ 'DES-EDE3-CBC' } = '' ;
2527 $selected { 'DCIPHER' }{ 'DESX-CBC' } = '' ;
2528 $selected { 'DCIPHER' }{ 'RC2-CBC' } = '' ;
2529 $selected { 'DCIPHER' }{ 'RC2-40-CBC' } = '' ;
2530 $selected { 'DCIPHER' }{ 'RC2-64-CBC' } = '' ;
2531 $selected { 'DCIPHER' }{ 'BF-CBC' } = '' ;
2532 $selected { 'DCIPHER' }{ 'CAST5-CBC' } = '' ;
2533 $selected { 'DCIPHER' }{ 'AES-128-CBC' } = '' ;
2534 $selected { 'DCIPHER' }{ 'AES-192-CBC' } = '' ;
2535 $selected { 'DCIPHER' }{ 'AES-256-CBC' } = '' ;
2536 $selected { 'DCIPHER' }{ $cgiparams { 'DCIPHER' }} = 'SELECTED' ;
2537 $checked { 'DCOMPLZO' }{ 'off' } = '' ;
2538 $checked { 'DCOMPLZO' }{ 'on' } = '' ;
2539 $checked { 'DCOMPLZO' }{ $cgiparams { 'DCOMPLZO' }} = 'CHECKED' ;
2542 & Header
:: showhttpheaders
();
2543 & Header
:: openpage
( $Lang :: tr
{ 'status ovpn' }, 1 , '' );
2544 & Header
:: openbigbox
( '100%' , 'LEFT' , '' , $errormessage );
2546 if ( $errormessage ) {
2547 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'error messages' });
2548 print "<class name='base'> $errormessage \n " ;
2549 print " </class> \n " ;
2550 & Header
:: closebox
();
2553 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>" ;
2554 my $srunning = "no" ;
2555 my $activeonrun = "" ;
2556 if ( - e
"/var/run/openvpn.pid" ){
2557 $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>" ;
2561 $activeonrun = "disabled='disabled'" ;
2563 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'global settings' });
2564 print "<div align='center'><strong>ZERINA-0.9.4i</strong></div>" ;
2566 <table width='100%'>
2567 <form method='post'>
2568 <td width='25%'> </td>
2569 <td width='25%'> </td>
2570 <td width='25%'> </td></tr>
2571 <tr><td class='boldbase'> $Lang ::tr{'ovpn server status'}</td>
2572 <td align='left'> $sactive </td>
2573 <tr><td class='boldbase'> $Lang ::tr{'ovpn on red'}</td>
2574 <td><input type='checkbox' name='ENABLED' $checked {'ENABLED'}{'on'} /></td>
2577 if (& haveBlueNet
()) {
2578 print "<tr><td class='boldbase'> $Lang ::tr{'ovpn on blue'}</td>" ;
2579 print "<td><input type='checkbox' name='ENABLED_BLUE' $checked {'ENABLED_BLUE'}{'on'} /></td>" ;
2581 if (& haveOrangeNet
()) {
2582 print "<tr><td class='boldbase'> $Lang ::tr{'ovpn on orange'}</td>" ;
2583 print "<td><input type='checkbox' name='ENABLED_ORANGE' $checked {'ENABLED_ORANGE'}{'on'} /></td>" ;
2586 <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>
2587 <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>
2588 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'ovpn device'}</td>
2589 <td><select name='DDEVICE' ><option value='tun' $selected {'DDEVICE'}{'tun'}>TUN</option>
2590 <option value='tap' $selected {'DDEVICE'}{'tap'}>TAP</option></select></td>
2591 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'protocol'}</td>
2592 <td><select name='DPROTOCOL'><option value='udp' $selected {'DPROTOCOL'}{'udp'}>UDP</option>
2593 <option value='tcp' $selected {'DPROTOCOL'}{'tcp'}>TCP</option></select></td>
2594 <td class='boldbase'> $Lang ::tr{'destination port'}:</td>
2595 <td><input type='TEXT' name='DDEST_PORT' value=' $cgiparams {'DDEST_PORT'}' size='5' /></td></tr>
2596 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'MTU'} </td>
2597 <td> <input type='TEXT' name='DMTU' VALUE=' $cgiparams {'DMTU'}'size='5' /></TD>
2598 <tr><td class='boldbase' nowrap='nowrap'> $Lang ::tr{'comp-lzo'}</td>
2599 <td><input type='checkbox' name='DCOMPLZO' $checked {'DCOMPLZO'}{'on'} /></td>
2600 <td class='boldbase' nowrap='nowrap'> $Lang ::tr{'cipher'}</td>
2601 <td><select name='DCIPHER'><option value='DES-CBC' $selected {'DCIPHER'}{'DES-CBC'}>DES-CBC</option>
2602 <option value='DES-EDE-CBC' $selected {'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC</option>
2603 <option value='DES-EDE3-CBC' $selected {'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC</option>
2604 <option value='DESX-CBC' $selected {'DCIPHER'}{'DESX-CBC'}>DESX-CBC</option>
2605 <option value='RC2-CBC' $selected {'DCIPHER'}{'RC2-CBC'}>RC2-CBC</option>
2606 <option value='RC2-40-CBC' $selected {'DCIPHER'}{'RC2-40-CBC'}>RC2-40-CBC</option>
2607 <option value='RC2-64-CBC' $selected {'DCIPHER'}{'RC2-64-CBC'}>RC2-64-CBC</option>
2608 <option value='BF-CBC' $selected {'DCIPHER'}{'BF-CBC'}>BF-CBC</option>
2609 <option value='CAST5-CBC' $selected {'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC</option>
2610 <option value='AES-128-CBC' $selected {'DCIPHER'}{'AES-128-CBC'}>AES-128-CBC</option>
2611 <option value='AES-192-CBC' $selected {'DCIPHER'}{'AES-192-CBC'}>AES-192-CBC</option>
2612 <option value='AES-256-CBC' $selected {'DCIPHER'}{'AES-256-CBC'}>AES-256-CBC</option></select></td>
2616 if ( $srunning eq "yes" ) {
2617 print "<tr><td align='left'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' disabled='disabled' /></td>" ;
2618 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'advanced server'}' disabled='disabled'/></td>" ;
2619 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'stop ovpn server'}' /></td>" ;
2620 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'restart ovpn server'}' /></td></tr>" ;
2622 print "<tr><td align='left'><input type='submit' name='ACTION' value=' $Lang ::tr{'save'}' /></td>" ;
2623 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'advanced server'}' /></td>" ;
2624 if (( - e
"${General::swroot}/ovpn/ca/cacert.pem" &&
2625 - e
"${General::swroot}/ovpn/ca/dh1024.pem" &&
2626 - e
"${General::swroot}/ovpn/certs/servercert.pem" &&
2627 - e
"${General::swroot}/ovpn/certs/serverkey.pem" ) &&
2628 (( $cgiparams { 'ENABLED' } eq 'on' ) ||
2629 ( $cgiparams { 'ENABLED_BLUE' } eq 'on' ) ||
2630 ( $cgiparams { 'ENABLED_ORANGE' } eq 'on' ))){
2631 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'start ovpn server'}' /></td>" ;
2632 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'restart ovpn server'}' /></td></tr>" ;
2634 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'start ovpn server'}' disabled='disabled' /></td>" ;
2635 print "<td><input type='submit' name='ACTION' value=' $Lang ::tr{'restart ovpn server'}' disabled='disabled' /></td></tr>" ;
2638 print "</form></table>" ;
2639 & Header
:: closebox
();
2640 & Header
:: openbox
( '100%' , 'LEFT' , " $Lang ::tr{'certificate authorities'}:" );
2642 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
2644 <td width='25%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></td>
2645 <td width='65%' class='boldbase' align='center'><b> $Lang ::tr{'subject'}</b></td>
2646 <td width='10%' class='boldbase' colspan='3' align='center'><b> $Lang ::tr{'action'}</b></td>
2650 if (- f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
2651 my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem` ;
2652 $casubject =~ /Subject: (.*)[\n]/ ;
2654 $casubject =~ s
+/ Email
+, E
+;
2655 $casubject =~ s/ ST=/ S=/ ;
2658 <tr bgcolor=' $color {'color22'}'>
2659 <td class='base'> $Lang ::tr{'root certificate'}</td>
2660 <td class='base'> $casubject </td>
2661 <form method='post' name='frmrootcrta'><td width='3%' align='center'>
2662 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show root certificate'}' />
2663 <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' />
2665 <form method='post' name='frmrootcrtb'><td width='3%' align='center'>
2666 <input type='image' name=' $Lang ::tr{'download root certificate'}' src='/images/floppy.gif' alt=' $Lang ::tr{'download root certificate'}' title=' $Lang ::tr{'download root certificate'}' border='0' />
2667 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download root certificate'}' />
2669 <td width='4%'> </td></tr>
2673 # display rootcert generation buttons
2675 <tr bgcolor=' $color {'color22'}'>
2676 <td class='base'> $Lang ::tr{'root certificate'}:</td>
2677 <td class='base'> $Lang ::tr{'not present'}</td>
2678 <td colspan='3'> </td></tr>
2683 if (- f
"${General::swroot}/ovpn/certs/servercert.pem" ) {
2684 my $hostsubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem` ;
2685 $hostsubject =~ /Subject: (.*)[\n]/ ;
2687 $hostsubject =~ s
+/ Email
+, E
+;
2688 $hostsubject =~ s/ ST=/ S=/ ;
2691 <tr bgcolor=' $color {'color20'}'>
2692 <td class='base'> $Lang ::tr{'host certificate'}</td>
2693 <td class='base'> $hostsubject </td>
2694 <form method='post' name='frmhostcrta'><td width='3%' align='center'>
2695 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show host certificate'}' />
2696 <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' />
2698 <form method='post' name='frmhostcrtb'><td width='3%' align='center'>
2699 <input type='image' name=' $Lang ::tr{'download host certificate'}' src='/images/floppy.gif' alt=' $Lang ::tr{'download host certificate'}' title=' $Lang ::tr{'download host certificate'}' border='0' />
2700 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download host certificate'}' />
2702 <td width='4%'> </td></tr>
2708 <tr bgcolor=' $color {'color20'}'>
2709 <td width='25%' class='base'> $Lang ::tr{'host certificate'}:</td>
2710 <td class='base'> $Lang ::tr{'not present'}</td>
2711 </td><td colspan='3'> </td></tr>
2716 if (! - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
2717 print "<tr><td colspan='5' align='center'><form method='post'>" ;
2718 print "<input type='submit' name='ACTION' value=' $Lang ::tr{'generate root/host certificates'}' />" ;
2719 print "</form></td></tr> \n " ;
2722 if ( keys %cahash > 0 ) {
2723 foreach my $key ( keys %cahash ) {
2724 if (( $key + 1 ) % 2 ) {
2725 print "<tr bgcolor=' $color {'color20'}'> \n " ;
2727 print "<tr bgcolor=' $color {'color22'}'> \n " ;
2729 print "<td class='base'> $cahash { $key }[0]</td> \n " ;
2730 print "<td class='base'> $cahash { $key }[1]</td> \n " ;
2732 <form method='post' name='cafrm${key}a'><td align='center'>
2733 <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' />
2734 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show ca certificate'}' />
2735 <input type='hidden' name='KEY' value=' $key ' />
2737 <form method='post' name='cafrm${key}b'><td align='center'>
2738 <input type='image' name=' $Lang ::tr{'download ca certificate'}' src='/images/floppy.gif' alt=' $Lang ::tr{'download ca certificate'}' title=' $Lang ::tr{'download ca certificate'}' border='0' />
2739 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download ca certificate'}' />
2740 <input type='hidden' name='KEY' value=' $key ' />
2742 <form method='post' name='cafrm${key}c'><td align='center'>
2743 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove ca certificate'}' />
2744 <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' />
2745 <input type='hidden' name='KEY' value=' $key ' />
2754 # If the file contains entries, print Key to action icons
2755 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
2759 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
2760 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
2761 <td class='base'> $Lang ::tr{'show certificate'}</td>
2762 <td> <img src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' /></td>
2763 <td class='base'> $Lang ::tr{'download certificate'}</td>
2770 <form method='post' enctype='multipart/form-data'>
2771 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
2772 <tr><td class='base' nowrap='nowrap'> $Lang ::tr{'ca name'}:</td>
2773 <td nowrap='nowrap'><input type='text' name='CA_NAME' value=' $cgiparams {'CA_NAME'}' size='15' />
2774 <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td>
2775 <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>
2776 </tr></table></form>
2780 & Header
:: closebox
();
2781 if ( $srunning eq "yes" ) {
2782 print "<div align='center'><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'reset'}' disabled='disabled' /></div></form> \n " ;
2784 print "<div align='center'><form method='post'><input type='submit' name='ACTION' value=' $Lang ::tr{'reset'}' /></div></form> \n " ;
2786 if ( - f
"${General::swroot}/ovpn/ca/cacert.pem" ) {
2787 & Header
:: openbox
( '100%' , 'LEFT' , $Lang :: tr
{ 'Client status and controlc' });
2789 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
2791 <td width='10%' class='boldbase' align='center'><b> $Lang ::tr{'name'}</b></td>
2792 <td width='15%' class='boldbase' align='center'><b> $Lang ::tr{'type'}</b></td>
2793 <td width='18%' class='boldbase' align='center'><b> $Lang ::tr{'common name'}</b></td>
2794 <td width='17%' class='boldbase' align='center'><b> $Lang ::tr{'valid till'}</b></td>
2795 <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>
2796 <td width='10%' class='boldbase' align='center'><b> $Lang ::tr{'status'}</b></td>
2797 <td width='5%' class='boldbase' colspan='6' align='center'><b> $Lang ::tr{'action'}</b></td>
2803 foreach my $key ( keys %confighash ) {
2804 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
2807 print "<tr bgcolor=' $color {'color20'}'> \n " ;
2809 print "<tr bgcolor=' $color {'color22'}'> \n " ;
2811 print "<td align='center' nowrap='nowrap'> $confighash { $key }[1]</td>" ;
2812 print "<td align='center' nowrap='nowrap'>" . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ")</td>" ;
2813 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
2814 print "<td align='left' nowrap='nowrap'> $confighash { $key }[2]</td>" ;
2816 print "<td align='left'> </td>" ;
2818 my $cavalid = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/ $confighash { $key }[1]cert.pem` ;
2819 $cavalid =~ /Not After : (.*)[\n]/ ;
2821 print "<td align='center'> $cavalid </td>" ;
2822 print "<td align='center'> $confighash { $key }[25]</td>" ;
2823 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>" ;
2824 if ( $confighash { $key }[ 0 ] eq 'off' ) {
2825 $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>" ;
2829 foreach my $line ( @status ) {
2831 if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ ) {
2832 @match = split ( m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ , $line );
2833 if ( $match [ 1 ] ne "Common Name" ) {
2837 if ( $cn eq " $confighash { $key }[2]" ) {
2838 $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>" ;
2843 my $disable_clientdl = "disabled='disabled'" ;
2844 if (( $cgiparams { 'ENABLED' } eq 'on' ) ||
2845 ( $cgiparams { 'ENABLED_BLUE' } eq 'on' ) ||
2846 ( $cgiparams { 'ENABLED_ORANGE' } eq 'on' )){
2847 $disable_clientdl = "" ;
2850 <td align='center'> $active </td>
2852 <form method='post' name='frm${key}a'><td align='center'>
2853 <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' />
2854 <input type='hidden' name='ACTION' value=' $Lang ::tr{'dl client arch'}' $disable_clientdl />
2855 <input type='hidden' name='KEY' value=' $key ' $disable_clientdl />
2859 if ( $confighash { $key }[ 4 ] eq 'cert' ) {
2861 <form method='post' name='frm${key}b'><td align='center'>
2862 <input type='image' name=' $Lang ::tr{'show certificate'}' src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' title=' $Lang ::tr{'show certificate'}' border='0' />
2863 <input type='hidden' name='ACTION' value=' $Lang ::tr{'show certificate'}' />
2864 <input type='hidden' name='KEY' value=' $key ' />
2868 print "<td> </td>" ;
2870 if ( $confighash { $key }[ 4 ] eq 'cert' && - f
"${General::swroot}/ovpn/certs/ $confighash { $key }[1].p12" ) {
2872 <form method='post' name='frm${key}c'><td align='center'>
2873 <input type='image' name=' $Lang ::tr{'download pkcs12 file'}' src='/images/floppy.gif' alt=' $Lang ::tr{'download pkcs12 file'}' title=' $Lang ::tr{'download pkcs12 file'}' border='0' />
2874 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download pkcs12 file'}' />
2875 <input type='hidden' name='KEY' value=' $key ' />
2878 ; } elsif ( $confighash { $key }[ 4 ] eq 'cert' ) {
2880 <form method='post' name='frm${key}c'><td align='center'>
2881 <input type='image' name=' $Lang ::tr{'download certificate'}' src='/images/floppy.gif' alt=' $Lang ::tr{'download certificate'}' title=' $Lang ::tr{'download certificate'}' border='0' />
2882 <input type='hidden' name='ACTION' value=' $Lang ::tr{'download certificate'}' />
2883 <input type='hidden' name='KEY' value=' $key ' />
2887 print "<td> </td>" ;
2890 <form method='post' name='frm${key}d'><td align='center'>
2891 <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' />
2892 <input type='hidden' name='ACTION' value=' $Lang ::tr{'toggle enable disable'}' />
2893 <input type='hidden' name='KEY' value=' $key ' />
2896 <form method='post' name='frm${key}e'><td align='center'>
2897 <input type='hidden' name='ACTION' value=' $Lang ::tr{'edit'}' />
2898 <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'/>
2899 <input type='hidden' name='KEY' value=' $key ' />
2901 <form method='post' name='frm${key}f'><td align='center'>
2902 <input type='hidden' name='ACTION' value=' $Lang ::tr{'remove'}' />
2903 <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' />
2904 <input type='hidden' name='KEY' value=' $key ' />
2913 # If the config file contains entries, print Key to action icons
2918 <td class='boldbase'> <b> $Lang ::tr{'legend'}:</b></td>
2919 <td> <img src='/images/on.gif' alt=' $Lang ::tr{'click to disable'}' /></td>
2920 <td class='base'> $Lang ::tr{'click to disable'}</td>
2921 <td> <img src='/images/info.gif' alt=' $Lang ::tr{'show certificate'}' /></td>
2922 <td class='base'> $Lang ::tr{'show certificate'}</td>
2923 <td> <img src='/images/edit.gif' alt=' $Lang ::tr{'edit'}' /></td>
2924 <td class='base'> $Lang ::tr{'edit'}</td>
2925 <td> <img src='/images/delete.gif' alt=' $Lang ::tr{'remove'}' /></td>
2926 <td class='base'> $Lang ::tr{'remove'}</td>
2930 <td> <img src='/images/off.gif' alt='?OFF' /></td>
2931 <td class='base'> $Lang ::tr{'click to enable'}</td>
2932 <td> <img src='/images/floppy.gif' alt='?FLOPPY' /></td>
2933 <td class='base'> $Lang ::tr{'download certificate'}</td>
2934 <td> <img src='/images/openvpn.png' alt='?RELOAD'/></td>
2935 <td class='base'> $Lang ::tr{'dl client arch'}</td>
2943 <table width='100%'>
2944 <form method='post'>
2945 <tr><td width='50%' ><input type='submit' name='ACTION' value=' $Lang ::tr{'add'}' /></td>
2946 <td width='50%' ><input type='submit' name='ACTION' value=' $Lang ::tr{'ovpn con stat'}' $activeonrun /></td></tr>
2951 & Header
:: closebox
();
2953 & Header
:: closepage
();