X-Git-Url: http://git.ipfire.org/?p=people%2Fteissler%2Fipfire-2.x.git;a=blobdiff_plain;f=html%2Fcgi-bin%2Ffwhosts.cgi;h=d7a519a3797db44078ca783735811817b951a485;hp=fd1da8a7a359970c719d7f371828d6c80864379f;hb=2e99ab8bf8a1dc79d1c411281bd82a19acf1c9dc;hpb=05612a544bf60d233704be5995241d2354dbde91 diff --git a/html/cgi-bin/fwhosts.cgi b/html/cgi-bin/fwhosts.cgi index fd1da8a7a..d7a519a37 100755 --- a/html/cgi-bin/fwhosts.cgi +++ b/html/cgi-bin/fwhosts.cgi @@ -26,6 +26,7 @@ use strict; # enable only the following on debugging purpose use warnings; +use Sort::Naturally; use CGI::Carp 'fatalsToBrowser'; no warnings 'uninitialized'; require '/var/ipfire/general-functions.pl'; @@ -79,6 +80,24 @@ unless (-e $configsrvgrp) { system("touch $configsrvgrp"); } &Header::openpage($Lang::tr{'fwhost hosts'}, 1, ''); &Header::openbigbox('100%', 'center'); +#### JAVA SCRIPT #### +print< + \$(document).ready(function() { + // Automatically select radio buttons when corresponding + // dropdown menu changes. + \$("select").change(function() { + var id = \$(this).attr("name"); + //When using SNAT or DNAT, check "USE NAT" Checkbox + if ( id === 'snat' || id === 'dnat') { + \$('#USE_NAT').prop('checked', true); + } + \$('#' + id).prop("checked", true); + }); + }); + +END + ## ACTION #### if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwdfw reread'}) { @@ -372,8 +391,7 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' ) } &addnet; &viewtablenet; - }else - { + }else { &addnet; &viewtablenet; } @@ -455,7 +473,6 @@ if ($fwhostsettings{'ACTION'} eq 'savehost') foreach my $key (sort keys %customgrp){ if($customgrp{$key}[2] eq $fwhostsettings{'orgname'}){ $customgrp{$key}[2]=$fwhostsettings{'HOSTNAME'}; - last; } } &General::writehasharray("$configgrp", \%customgrp); @@ -669,7 +686,7 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp') }elsif($updcounter eq 'host'){ foreach my $key (keys %customhost) { if ($customhost{$key}[0] eq $fwhostsettings{'CUST_SRC_HOST'}){ - $customhost{$key}[4]=$customhost{$key}[3]+1; + $customhost{$key}[4]=$customhost{$key}[4]+1; } } &General::writehasharray("$confighost", \%customhost); @@ -723,6 +740,10 @@ if ($fwhostsettings{'ACTION'} eq 'saveservicegrp') &General::readhasharray("$configsrvgrp", \%customservicegrp ); &General::readhasharray("$configsrv", \%customservice ); $errormessage=&checkservicegroup; + #check remark + if ($fwhostsettings{'SRVGRP_REMARK'} ne '' && !&validremark($fwhostsettings{'SRVGRP_REMARK'})){ + $errormessage=$Lang::tr{'fwhost err remark'}; + } if (!$errormessage){ #on first save, we have to enter a dummy value if ($fwhostsettings{'CUST_SRV'} eq ''){ @@ -864,7 +885,7 @@ if ($fwhostsettings{'ACTION'} eq 'deletegrphost') &General::readhasharray("$confignet", \%customnetwork); foreach my $key1 (keys %customnetwork){ if ($customnetwork{$key1}[0] eq $customgrp{$key}[2]){ - $customnetwork{$key1}[3] = $customnetwork{$key1}[3]-1; + $customnetwork{$key1}[4] = $customnetwork{$key1}[4]-1; last; } } @@ -967,7 +988,6 @@ if ($fwhostsettings{'ACTION'} eq 'delgrpservice') &General::writehasharray("$configsrvgrp", \%customservicegrp); &rules; if ($fwhostsettings{'updatesrvgrp'} eq 'on'){ - #$fwhostsettings{'updatesrvgrp'}='on'; $fwhostsettings{'SRVGRP_NAME'}=$grpname; $fwhostsettings{'SRVGRP_REMARK'}=$grpremark; } @@ -1005,17 +1025,14 @@ if ($fwhostsettings{'ACTION'} eq 'changegrpremark') if ($fwhostsettings{'oldrem'} ne $fwhostsettings{'newrem'} && (&validremark($fwhostsettings{'newrem'}) || $fwhostsettings{'newrem'} eq '')){ foreach my $key (sort keys %customgrp) { - #$customgrp{$key}[1]=~ s/\|/,/g; if($customgrp{$key}[0] eq $fwhostsettings{'grp'} && $customgrp{$key}[1] eq $fwhostsettings{'oldrem'}) { - #$fwhostsettings{'newrem'}=~ s/,/\|/g; $customgrp{$key}[1]=''; $customgrp{$key}[1]=$fwhostsettings{'newrem'}; } } &General::writehasharray("$configgrp", \%customgrp); $fwhostsettings{'update'}='on'; - #$fwhostsettings{'newrem'}=~ s/\|/,/g; $fwhostsettings{'remark'}=$fwhostsettings{'newrem'}; }else{ $errormessage=$Lang::tr{'fwhost err remark'}; @@ -1033,17 +1050,14 @@ if ($fwhostsettings{'ACTION'} eq 'changesrvgrpremark') if ($fwhostsettings{'oldsrvrem'} ne $fwhostsettings{'newsrvrem'} && (&validremark($fwhostsettings{'newsrvrem'}) || $fwhostsettings{'newsrvrem'} eq '')){ foreach my $key (sort keys %customservicegrp) { - #$customservicegrp{$key}[1]=~ s/\|/,/g; if($customservicegrp{$key}[0] eq $fwhostsettings{'srvgrp'} && $customservicegrp{$key}[1] eq $fwhostsettings{'oldsrvrem'}) { - #$fwhostsettings{'newsrvrem'}=~ s/,/|/g; $customservicegrp{$key}[1]=''; $customservicegrp{$key}[1]=$fwhostsettings{'newsrvrem'}; } } &General::writehasharray("$configsrvgrp", \%customservicegrp); $fwhostsettings{'updatesrvgrp'}='on'; - #$fwhostsettings{'newsrvrem'}=~ s/\|/,/g; $fwhostsettings{'SRVGRP_REMARK'}=$fwhostsettings{'newsrvrem'}; }else{ $errormessage=$Lang::tr{'fwhost err remark'}; @@ -1064,14 +1078,15 @@ if($fwhostsettings{'ACTION'} eq '') sub showmenu { if (-f "${General::swroot}/forward/reread"){ - print "
$Lang::tr{'fwhost reread'}


"; + print "
    $Lang::tr{'fwhost reread'}

"; } &Header::openbox('100%', 'left',$Lang::tr{'fwhost menu'}); + print "$Lang::tr{'fwhost welcome'}"; print<
- - -
+

+ + +

END &Header::closebox(); @@ -1085,20 +1100,20 @@ sub addnet $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'}; $fwhostsettings{'orgnetremark'}=$fwhostsettings{'NETREMARK'}; print<
- $Lang::tr{'name'}: - $Lang::tr{'fwhost netaddress'}: - $Lang::tr{'netmask'}: + + + + - + END if ($fwhostsettings{'ACTION'} eq 'editnet' || $fwhostsettings{'error'} eq 'on') { - print ""; }else{ print "
$Lang::tr{'name'}:
$Lang::tr{'fwhost netaddress'}:
$Lang::tr{'netmask'}:
$Lang::tr{'remark'}:




"; + print ""; } - print "
"; + print "
"; &Header::closebox(); } sub addhost @@ -1109,12 +1124,11 @@ sub addhost $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'}; $fwhostsettings{'orgremark'}=$fwhostsettings{'HOSTREMARK'}; print<
- $Lang::tr{'name'}: - IP/MAC: + + + - - + END if ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'} eq 'on') @@ -1122,9 +1136,9 @@ END print "
$Lang::tr{'name'}:
IP/MAC:
$Lang::tr{'remark'}:


$Lang::tr{'fwhost attention'}
$Lang::tr{'fwhost macwarn'}


"; }else{ - print " "; + print " "; } - print "
"; + print "
"; &Header::closebox(); } sub addgrp @@ -1150,8 +1164,8 @@ sub addgrp my $rem=$fwhostsettings{'remark'}; if ($fwhostsettings{'update'} eq ''){ print<
- $Lang::tr{'fwhost addgrpname'} + +
$Lang::tr{'fwhost addgrpname'}
$Lang::tr{'remark'}:


END @@ -1169,27 +1183,35 @@ END + END } my $count=0; - foreach my $key (sort {$a <=> $b} keys %customnetwork) { + foreach my $key (sort {ncmp($a,$b)} keys %customnetwork) { if ($fwhostsettings{'ACTION'} eq 'editnet' && $fwhostsettings{'HOSTNAME'} eq $customnetwork{$key}[0]) { print" "; }elsif ($count % 2) @@ -1379,8 +1401,9 @@ END { print" "; } + my $colnet="$customnetwork{$key}[1]/".&General::subtocidr($customnetwork{$key}[2]); + print""; print<$customnetwork{$key}[0]"; }else{ - print""; + print""; } $count++; } @@ -1413,26 +1436,26 @@ sub viewtablehost }else{ print< - + END } my $count=0; - foreach my $key (sort { uc($customhost{$a}[0]) cmp uc($customhost{$b}[0])|| $a <=> $b } keys %customhost) { + foreach my $key (sort { ncmp ($customhost{$a}[0],$customhost{$b}[0])} keys %customhost) { if ( ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'}) && $fwhostsettings{'HOSTNAME'} eq $customhost{$key}[0]) { print" "; }elsif ($count % 2){ print" ";} else{ print" ";} my ($ip,$sub)=split(/\//,$customhost{$key}[2]); $customhost{$key}[4]=~s/\s+//g; + print""; print<
$customhost{$key}[0]
- + END if($customhost{$key}[4] == '0') { @@ -1467,11 +1490,11 @@ sub viewtablegrp { print "
$Lang::tr{'fwhost empty'}"; }else{ - foreach my $key (sort { uc($customgrp{$a}[0]) cmp uc($customgrp{$b}[0]) } sort { uc($customgrp{$a}[2]) cmp uc($customgrp{$b}[2]) } keys %customgrp){ + foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp ($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){ $count++; if ($helper ne $customgrp{$key}[0]){ $delflag='0'; - foreach my $key1 (sort { uc($customgrp{$a}[0]) cmp uc($customgrp{$b}[0]) } sort { uc($customgrp{$a}[2]) cmp uc($customgrp{$b}[2]) } keys %customgrp){ + foreach my $key1 (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){ if ($customgrp{$key}[0] eq $customgrp{$key1}[0]) { $delflag++; @@ -1484,8 +1507,8 @@ sub viewtablegrp if ($customgrp{$key}[2] eq "none"){$customgrp{$key}[2]=$Lang::tr{'fwhost empty'};} $grpname=$customgrp{$key}[0]; $remark="$customgrp{$key}[1]"; - if($count >=2){print"
- "; if (! -z $confignet){ - print""; } if (! -z $confighost){ - print""; @@ -1199,15 +1221,15 @@ END print" + - + +
$Lang::tr{'fwhost stdnet'}
$Lang::tr{'fwhost stdnet'}
$Lang::tr{'fwhost cust net'}
$Lang::tr{'fwhost cust net'}
$Lang::tr{'fwhost cust addr'}
$Lang::tr{'fwhost cust addr'}
"; #OVPN networks if (! -z $configccdnet){ - print""; } #OVPN clients - foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost) + foreach my $key (sort { ncmp($ccdhost{$a}[0],$ccdhost{$b}[0]) } keys %ccdhost) { if ($ccdhost{$key}[33] ne ''){ print"";} #OVPN n2n networks - foreach my $key (sort { uc($ccdhost{$a}[0]) cmp uc($ccdhost{$b}[0]) } keys %ccdhost) { + foreach my $key (sort { ncmp($ccdhost{$a}[1],$ccdhost{$b}[1]) } keys %ccdhost) { if($ccdhost{$key}[3] eq 'net'){ - print"";} #IPsec networks - foreach my $key (sort { uc($ipsecconf{$a}[0]) cmp uc($ipsecconf{$b}[0]) } keys %ipsecconf) { + foreach my $key (sort { ncmp($ipsecconf{$a}[0],$ipsecconf{$b}[0]) } keys %ipsecconf) { if ($ipsecconf{$key}[3] eq 'net'){ - print"
$Lang::tr{'fwhost ccdnet'}$Lang::tr{'fwhost ccdnet'}
$Lang::tr{'fwhost ccdhost'}
$Lang::tr{'fwhost ovpn_n2n'}$Lang::tr{'fwhost ovpn_n2n'}
$Lang::tr{'fwhost ipsec net'}$Lang::tr{'fwhost ipsec net'}"; - print"
"; + print"
"; &Header::closebox(); } sub addservice { &error; &showmenu; - &Header::openbox('100%', 'left', $Lang::tr{'fwhost newservice'}); + &Header::openbox('100%', 'left', $Lang::tr{'fwhost addservice'}); if ($fwhostsettings{'updatesrv'} eq 'on') { $fwhostsettings{'oldsrvname'} = $fwhostsettings{'SRV_NAME'}; @@ -1255,7 +1277,7 @@ sub addservice } print<
-
$Lang::tr{'fwhost srv_name'}:
$Lang::tr{'fwhost srv_name'}:
$Lang::tr{'fwhost prot'}:
$Lang::tr{'fwhost port'}:
$Lang::tr{'fwhost port'}:


END @@ -1310,12 +1332,12 @@ sub addservicegrp &hint; &error; &showmenu; - &Header::openbox('100%', 'left', $Lang::tr{'fwhost newservicegrp'}); + &Header::openbox('100%', 'left', $Lang::tr{'fwhost addservicegrp'}); $fwhostsettings{'oldsrvgrpremark'}=$fwhostsettings{'SRVGRP_REMARK'}; if ($fwhostsettings{'updatesrvgrp'} eq ''){ print< -
$Lang::tr{'fwhost addgrpname'}
$Lang::tr{'fwhost addgrpname'}
$Lang::tr{'remark'}:


@@ -1335,7 +1357,7 @@ END
$Lang::tr{'fwhost cust service'}
$Lang::tr{'name'}$Lang::tr{'fwhost netaddress'}$Lang::tr{'netmask'}$Lang::tr{'remark'}$Lang::tr{'used'}
$Lang::tr{'name'}$Lang::tr{'fwhost netaddress'}$Lang::tr{'remark'}$Lang::tr{'used'}
$customnetwork{$key}[0]".&Header::colorize($colnet)."$customnetwork{$key}[3]$customnetwork{$key}[4]x$customnetwork{$key}[1]$customnetwork{$key}[2]$customnetwork{$key}[3]$customnetwork{$key}[4]x @@ -1393,7 +1416,7 @@ END { print"
$Lang::tr{'name'}$Lang::tr{'fwhost ip_mac'}$Lang::tr{'remark'}$Lang::tr{'used'}
$Lang::tr{'name'}$Lang::tr{'fwhost ip_mac'}$Lang::tr{'remark'}$Lang::tr{'used'}
$customhost{$key}[0]".&Header::colorize($ip)."$customhost{$key}[3]$customhost{$key}[4]x$ip$customhost{$key}[3]$customhost{$key}[4]x + -
";} - print "
$grpname    "; + if($count gt 2){ print"";} + print "
$grpname   "; print " $Lang::tr{'remark'}:  $remark   " if ($remark ne ''); print "$Lang::tr{'used'}: $customgrp{$key}[4]x"; if($customgrp{$key}[4] == '0') @@ -1512,9 +1535,11 @@ sub viewtablegrp print "$customgrp{$key}[2]"; } if ($ip eq '' && $customgrp{$key}[2] ne $Lang::tr{'fwhost empty'}){ - print "$Lang::tr{'fwhost deleted'}$customgrp{$key}[3]
"; + print "$Lang::tr{'fwhost deleted'}$customgrp{$key}[3]"; }else{ - print"$ip$customgrp{$key}[3]"; + my ($colip,$colsub) = split("/",$ip); + $ip="$colip/".&General::subtocidr($colsub) if ($colsub); + print"".&Header::colorize($ip)."$customgrp{$key}[3]"; } if ($delflag > '1' && $ip ne ''){ print""; @@ -1540,9 +1565,9 @@ sub viewtableservice &General::readhasharray("$configsrv", \%customservice); print< - $Lang::tr{'fwhost srv_name'}$Lang::tr{'fwhost prot'}$Lang::tr{'fwhost port'}ICMP$Lang::tr{'fwhost used'} + $Lang::tr{'fwhost srv_name'}$Lang::tr{'fwhost prot'}$Lang::tr{'fwhost port'}ICMP$Lang::tr{'fwhost used'} END - foreach my $key (sort { uc($customservice{$a}[0]) cmp uc($customservice{$b}[0])|| $a <=> $b } keys %customservice) + foreach my $key (sort { ncmp($customservice{$a}[0],$customservice{$b}[0])} keys %customservice) { $count++; if ( ($fwhostsettings{'updatesrv'} eq 'on' || $fwhostsettings{'error'}) && $fwhostsettings{'SRV_NAME'} eq $customservice{$key}[0]) { @@ -1585,11 +1610,11 @@ sub viewtableservicegrp &General::readhasharray("$configsrvgrp", \%customservicegrp); &General::readhasharray("$configsrv", \%customservice); my $number= keys %customservicegrp; - foreach my $key (sort { uc($customservicegrp{$a}[0]) cmp uc($customservicegrp{$b}[0])|| $a <=> $b } keys %customservicegrp){ + foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } keys %customservicegrp){ $count++; if ($helper ne $customservicegrp{$key}[0]){ $delflag=0; - foreach my $key1 (sort { uc($customservicegrp{$a}[0]) cmp uc($customservicegrp{$b}[0]) } sort { uc($customservicegrp{$a}[2]) cmp uc($customservicegrp{$b}[2]) } keys %customservicegrp){ + foreach my $key1 (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) } keys %customservicegrp){ if ($customservicegrp{$key}[0] eq $customservicegrp{$key1}[0]) { $delflag++; @@ -1606,9 +1631,9 @@ sub viewtableservicegrp } $remark="$customservicegrp{$key}[1]"; if($count >=2){print"";} - print "
$grpname     "; - print "$Lang::tr{'remark'}:  $remark " if ($remark ne ''); - print "  $Lang::tr{'used'}: $customservicegrp{$key}[3]x"; + print "
$grpname    "; + print "$Lang::tr{'remark'}:  $remark " if ($remark ne ''); + print "  $Lang::tr{'used'}: $customservicegrp{$key}[3]x"; if($customservicegrp{$key}[3] == '0') { print""; @@ -1668,7 +1693,6 @@ sub checkip } sub checksubnet { - my %hash=%{(shift)}; &General::readhasharray("$confignet", \%hash); foreach my $key (keys %hash) { @@ -1907,7 +1931,8 @@ sub getipforgroup if ($type eq 'Custom Host'){ foreach my $key (keys %customhost) { if ($customhost{$key}[0] eq $name){ - return $customhost{$key}[2]; + my ($ip,$sub) = split("/",$customhost{$key}[2]); + return $ip; } } }