X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=html%2Fcgi-bin%2Ffwhosts.cgi;h=049233c43c181554a95f7277380dc575ef277b6a;hb=4d81e0f3812fc272b2515a631a2e98c4ae76a42b;hp=7fb05de39146c1de50b216184eb42c91d7e24896;hpb=7d5e022df4b37f157f8528cbce892e273f1b4836;p=people%2Fteissler%2Fipfire-2.x.git diff --git a/html/cgi-bin/fwhosts.cgi b/html/cgi-bin/fwhosts.cgi old mode 100755 new mode 100644 index 7fb05de39..049233c43 --- a/html/cgi-bin/fwhosts.cgi +++ b/html/cgi-bin/fwhosts.cgi @@ -48,7 +48,7 @@ my %fwfwd=(); my %fwinp=(); my %fwout=(); my %ovpnsettings=(); - +my %netsettings=(); my $errormessage; my $hint; @@ -80,11 +80,11 @@ unless (-e $configsrvgrp) { system("touch $configsrvgrp"); } &General::readhash("$configovpn", \%ovpnsettings); &General::readhasharray("$configipsec", \%ipsecconf); &General::readhash("$configipsecrw", \%ipsecsettings); - +&General::readhash("/var/ipfire/ethernet/settings", \%netsettings); &Header::getcgihash(\%fwhostsettings); &Header::showhttpheaders(); -&Header::openpage($Lang::tr{'fwhost hosts'}, 1, ''); +&Header::openpage($Lang::tr{'fwhost menu'}, 1, ''); &Header::openbigbox('100%', 'center'); #### JAVA SCRIPT #### @@ -111,6 +111,12 @@ print< END @@ -233,20 +239,12 @@ if ($fwhostsettings{'ACTION'} eq 'updateservice') foreach my $key (sort keys %customservicegrp){ if($customservicegrp{$key}[2] eq $fwhostsettings{'oldsrvname'}){ $customservicegrp{$key}[2] = $fwhostsettings{'SRV_NAME'}; + &checkrulereload($customservicegrp{$key}[0]); } } &General::writehasharray("$configsrvgrp", \%customservicegrp); - $needrules='on'; - } - if($count gt 0 && $fwhostsettings{'oldsrvport'} ne $fwhostsettings{'SRV_PORT'} ){ - $needrules='on'; - } - if($count gt 0 && $fwhostsettings{'oldsrvprot'} ne $fwhostsettings{'PROT'} ){ - $needrules='on'; - } - if($count gt 0 && $fwhostsettings{'oldsrvicmp'} ne $fwhostsettings{'ICMP'} ){ - $needrules='on'; } + &checkrulereload($fwhostsettings{'SRV_NAME'}); $fwhostsettings{'SRV_NAME'} = ''; $fwhostsettings{'SRV_PORT'} = ''; $fwhostsettings{'PROT'} = ''; @@ -260,15 +258,11 @@ if ($fwhostsettings{'ACTION'} eq 'updateservice') $fwhostsettings{'ICMP'} = $fwhostsettings{'oldsrvicmp'}; $fwhostsettings{'updatesrv'}= 'on'; } - if($needrules eq 'on'){ - &General::firewall_config_changed(); - } &addservice; } # save if ($fwhostsettings{'ACTION'} eq 'savenet' ) { - my $count=0; my $needrules=0; if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};} #check if all fields are set @@ -342,7 +336,6 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' ) $customnetwork{$key}[1] = $fwhostsettings{'orgip'} ; $customnetwork{$key}[2] = $fwhostsettings{'orgsub'}; $customnetwork{$key}[3] = $fwhostsettings{'orgnetremark'}; - $customnetwork{$key}[4] = $fwhostsettings{'count'}; &General::writehasharray("$confignet", \%customnetwork); undef %customnetwork; } @@ -353,7 +346,6 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' ) if ($fwhostsettings{'update'} == '0'){ foreach my $key (keys %customnetwork) { if($customnetwork{$key}[0] eq $fwhostsettings{'orgname'}){ - $count=$customnetwork{$key}[4]; delete $customnetwork{$key}; last; } @@ -363,9 +355,8 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' ) #get count if actualize is 'on' if($fwhostsettings{'actualize'} eq 'on'){ $fwhostsettings{'actualize'} = ''; - $count=$fwhostsettings{'count'}; #check if we need to reload rules - if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'} && $count gt '0'){ + if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'}){ $needrules='on'; } if ($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){ @@ -403,7 +394,7 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' ) } } my $key = &General::findhasharraykey (\%customnetwork); - foreach my $i (0 .. 4) { $customnetwork{$key}[$i] = "";} + foreach my $i (0 .. 3) { $customnetwork{$key}[$i] = "";} $fwhostsettings{'SUBNET'} = &General::iporsubtocidr($fwhostsettings{'SUBNET'}); $customnetwork{$key}[0] = $fwhostsettings{'HOSTNAME'}; #convert ip when leading '0' in byte @@ -411,9 +402,7 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' ) $fwhostsettings{'IP'} =&General::dec2ip($fwhostsettings{'IP'}); $customnetwork{$key}[1] = &General::getnetworkip($fwhostsettings{'IP'},$fwhostsettings{'SUBNET'}) ; $customnetwork{$key}[2] = &General::iporsubtodec($fwhostsettings{'SUBNET'}) ; - if($fwhostsettings{'newnet'} eq 'on'){$count=0;} $customnetwork{$key}[3] = $fwhostsettings{'NETREMARK'}; - $customnetwork{$key}[4] = $count; &General::writehasharray("$confignet", \%customnetwork); $fwhostsettings{'IP'}=$fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'}); undef %customnetwork; @@ -435,7 +424,6 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' ) } if ($fwhostsettings{'ACTION'} eq 'savehost') { - my $count=0; my $needrules=0; if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};} $fwhostsettings{'SUBNET'}='32'; @@ -483,7 +471,7 @@ if ($fwhostsettings{'ACTION'} eq 'savehost') if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newhost'} ne 'on' && $errormessage){ $fwhostsettings{'actualize'} = ''; my $key = &General::findhasharraykey (\%customhost); - foreach my $i (0 .. 4) { $customhost{$key}[$i] = "";} + foreach my $i (0 .. 3) { $customhost{$key}[$i] = "";} $customhost{$key}[0] = $fwhostsettings{'orgname'} ; $customhost{$key}[1] = $fwhostsettings{'type'} ; if($customhost{$key}[1] eq 'ip'){ @@ -492,15 +480,13 @@ if ($fwhostsettings{'ACTION'} eq 'savehost') $customhost{$key}[2] = $fwhostsettings{'orgip'}; } $customhost{$key}[3] = $fwhostsettings{'orgremark'}; - $customhost{$key}[4] = $fwhostsettings{'count'}; &General::writehasharray("$confighost", \%customhost); undef %customhost; } if (!$errormessage){ #get count if host was edited if($fwhostsettings{'actualize'} eq 'on'){ - $count=$fwhostsettings{'count'}; - if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'} && $count gt '0' ){ + if($fwhostsettings{'orgip'} ne $fwhostsettings{'IP'}){ $needrules='on'; } if($fwhostsettings{'orgname'} ne $fwhostsettings{'HOSTNAME'}){ @@ -537,7 +523,7 @@ if ($fwhostsettings{'ACTION'} eq 'savehost') } } my $key = &General::findhasharraykey (\%customhost); - foreach my $i (0 .. 4) { $customhost{$key}[$i] = "";} + foreach my $i (0 .. 3) { $customhost{$key}[$i] = "";} $customhost{$key}[0] = $fwhostsettings{'HOSTNAME'} ; $customhost{$key}[1] = $fwhostsettings{'type'} ; if ($fwhostsettings{'type'} eq 'ip'){ @@ -548,9 +534,7 @@ if ($fwhostsettings{'ACTION'} eq 'savehost') }else{ $customhost{$key}[2] = $fwhostsettings{'IP'}; } - if($fwhostsettings{'newhost'} eq 'on'){$count=0;} $customhost{$key}[3] = $fwhostsettings{'HOSTREMARK'}; - $customhost{$key}[4] =$count; &General::writehasharray("$confighost", \%customhost); undef %customhost; $fwhostsettings{'HOSTNAME'}=''; @@ -571,7 +555,7 @@ if ($fwhostsettings{'ACTION'} eq 'savehost') } if ($fwhostsettings{'ACTION'} eq 'savegrp') { - my $grp=$fwhostsettings{'grp_name'};; + my $grp=$fwhostsettings{'grp_name'}; my $rem=$fwhostsettings{'remark'}; my $count; my $type; @@ -581,6 +565,9 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp') &General::readhasharray("$configgrp", \%customgrp); &General::readhasharray("$confignet", \%customnetwork); &General::readhasharray("$confighost", \%customhost); + &General::readhasharray("$fwconfigfwd", \%fwfwd); + &General::readhasharray("$fwconfiginp", \%fwinp); + &General::readhasharray("$fwconfigout", \%fwout); #check name if (!&validhostname($grp)){$errormessage.=$Lang::tr{'fwhost err name'};} #check existing name @@ -685,17 +672,6 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp') } &General::writehasharray("$configgrp", \%customgrp); &General::readhasharray("$configgrp", \%customgrp); - #get count used - foreach my $key (keys %customgrp) - { - if($customgrp{$key}[0] eq $grp) - { - $count=$customgrp{$key}[4]; - last; - } - } - if ($count eq '' ){$count='0';} - #create array with new lines foreach my $line (@target){ push (@newgrp,"$grp,$rem,$line"); @@ -703,36 +679,21 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp') #append new entries my $key = &General::findhasharraykey (\%customgrp); foreach my $line (@newgrp){ - foreach my $i (0 .. 4) { $customgrp{$key}[$i] = "";} + foreach my $i (0 .. 3) { $customgrp{$key}[$i] = "";} my ($a,$b,$c,$d) = split (",",$line); $customgrp{$key}[0] = $a; $customgrp{$key}[1] = $b; $customgrp{$key}[2] = $c; $customgrp{$key}[3] = $type; - $customgrp{$key}[4] = $count; } &General::writehasharray("$configgrp", \%customgrp); #update counter in Host/Net - if($updcounter eq 'net'){ - foreach my $key (keys %customnetwork) { - if($customnetwork{$key}[0] eq $fwhostsettings{'CUST_SRC_NET'}){ - $customnetwork{$key}[4] = $customnetwork{$key}[4]+1; - last; - } - } - &General::writehasharray("$confignet", \%customnetwork); - }elsif($updcounter eq 'host'){ - foreach my $key (keys %customhost) { - if ($customhost{$key}[0] eq $fwhostsettings{'CUST_SRC_HOST'}){ - $customhost{$key}[4]=$customhost{$key}[4]+1; - } - } - &General::writehasharray("$confighost", \%customhost); - } $fwhostsettings{'update'}='on'; } #check if ruleupdate is needed - if($count > 0 ) + my $netgrpcount=0; + $netgrpcount=&getnetcount($grp); + if($netgrpcount > 0 ) { &General::firewall_config_changed(); } @@ -779,7 +740,6 @@ if ($fwhostsettings{'ACTION'} eq 'saveservicegrp') { my $prot; my $port; - my $count=0; my $tcpcounter=0; my $udpcounter=0; &General::readhasharray("$configsrvgrp", \%customservicegrp ); @@ -820,7 +780,7 @@ if ($fwhostsettings{'ACTION'} eq 'saveservicegrp') } #on update, we have to delete the dummy entry foreach my $key (keys %customservicegrp){ - if ($customservicegrp{$key}[2] eq 'none'){ + if ($customservicegrp{$key}[2] eq 'none' && $customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'}){ delete $customservicegrp{$key}; last; } @@ -846,9 +806,7 @@ if ($fwhostsettings{'ACTION'} eq 'saveservicegrp') &General::writehasharray("$configsrvgrp", \%customservicegrp ); $fwhostsettings{'updatesrvgrp'}='on'; } - if ($count gt 0){ - &General::firewall_config_changed(); - } + &checkrulereload($fwhostsettings{'SRVGRP_NAME'}); &addservicegrp; &viewtableservicegrp; } @@ -935,33 +893,22 @@ if ($fwhostsettings{'ACTION'} eq 'deletegrphost') &General::readhasharray("$configgrp", \%customgrp); foreach my $key (keys %customgrp){ if($customgrp{$key}[0].",".$customgrp{$key}[1].",".$customgrp{$key}[2].",".$customgrp{$key}[3] eq $fwhostsettings{'delhost'}){ - #decrease count from source host/net - if ($customgrp{$key}[3] eq 'Custom Network'){ - &General::readhasharray("$confignet", \%customnetwork); - foreach my $key1 (keys %customnetwork){ - if ($customnetwork{$key1}[0] eq $customgrp{$key}[2]){ - $customnetwork{$key1}[4] = $customnetwork{$key1}[4]-1; - last; - } - } - &General::writehasharray("$confignet", \%customnetwork); - } - if ($customgrp{$key}[3] eq 'Custom Host'){ - &General::readhasharray("$confighost", \%customhost); - foreach my $key1 (keys %customhost){ - if ($customhost{$key1}[0] eq $customgrp{$key}[2]){ - $customhost{$key1}[4] = $customhost{$key1}[4]-1; - last; - } - } - &General::writehasharray("$confighost", \%customhost); - } $grpname=$customgrp{$key}[0]; $grpremark=$customgrp{$key}[1]; - delete $customgrp{$key}; + #check if we delete the last entry, then generate dummy + if ($fwhostsettings{'last'} eq 'on'){ + $customgrp{$key}[1] = ''; + $customgrp{$key}[2] = 'none'; + $customgrp{$key}[3] = ''; + $fwhostsettings{'last'}=''; + last; + }else{ + delete $customgrp{$key}; + } } } &General::writehasharray("$configgrp", \%customgrp); + &General::firewall_config_changed(); if ($fwhostsettings{'grpcnt'} > 0){ &General::firewall_config_changed(); } @@ -1024,23 +971,20 @@ if ($fwhostsettings{'ACTION'} eq 'delgrpservice') my $grpname; my $grpremark; &General::readhasharray("$configsrvgrp", \%customservicegrp); - &General::readhasharray("$configsrv", \%customservice); foreach my $key (keys %customservicegrp){ if($customservicegrp{$key}[0].",".$customservicegrp{$key}[1].",".$customservicegrp{$key}[2] eq $fwhostsettings{'delsrvfromgrp'}) { - #decrease count from source service - foreach my $key1 (sort keys %customservice){ - if($customservice{$key1}[0] eq $customservicegrp{$key}[2]){ - $customservice{$key1}[4]--; - last; - } - } $grpname=$customservicegrp{$key}[0]; $grpremark=$customservicegrp{$key}[1]; - delete $customservicegrp{$key}; + if($fwhostsettings{'last'} eq 'on'){ + $customservicegrp{$key}[2] = 'none'; + $fwhostsettings{'last'} = ''; + last; + }else{ + delete $customservicegrp{$key}; + } } } - &General::writehasharray("$configsrv", \%customservice); &General::writehasharray("$configsrvgrp", \%customservicegrp); &General::firewall_config_changed(); if ($fwhostsettings{'updatesrvgrp'} eq 'on'){ @@ -1049,7 +993,6 @@ if ($fwhostsettings{'ACTION'} eq 'delgrpservice') } &addservicegrp; &viewtableservicegrp; - } if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwhost newnet'}) { @@ -1128,6 +1071,52 @@ if ($fwhostsettings{'ACTION'} eq 'changesrvgrpremark') &addservicegrp; &viewtableservicegrp; } +if ($fwhostsettings{'ACTION'} eq 'changesrvgrpname') +{ + &General::readhasharray("$configsrvgrp", \%customservicegrp ); + if ($fwhostsettings{'oldsrvgrpname'} ne $fwhostsettings{'srvgrp'}){ + #Check new groupname + if (!&validhostname($fwhostsettings{'srvgrp'})){ + $errormessage.=$Lang::tr{'fwhost err name'}."
"; + } + if (!$errormessage){ + #Rename group in customservicegroup + foreach my $key (keys %customservicegrp) { + if($customservicegrp{$key}[0] eq $fwhostsettings{'oldsrvgrpname'}){ + $customservicegrp{$key}[0]=$fwhostsettings{'srvgrp'}; + } + } + &General::writehasharray("$configsrvgrp", \%customservicegrp ); + #change name in FW Rules + &changenameinfw($fwhostsettings{'oldsrvgrpname'},$fwhostsettings{'srvgrp'},15); + } + } + &addservicegrp; + &viewtableservicegrp; +} +if ($fwhostsettings{'ACTION'} eq 'changegrpname') +{ + &General::readhasharray("$configgrp", \%customgrp ); + if ($fwhostsettings{'oldgrpname'} ne $fwhostsettings{'grp'}){ + #Check new groupname + if (!&validhostname($fwhostsettings{'grp'})){ + $errormessage.=$Lang::tr{'fwhost err name'}."
"; + } + if (!$errormessage){ + #Rename group in customservicegroup + foreach my $key (keys %customgrp) { + if($customgrp{$key}[0] eq $fwhostsettings{'oldgrpname'}){ + $customgrp{$key}[0]=$fwhostsettings{'grp'}; + } + } + &General::writehasharray("$configgrp", \%customgrp ); + #change name in FW Rules + &changenameinfw($fwhostsettings{'oldgrpname'},$fwhostsettings{'grp'},6); + } + } + &addgrp; + &viewtablegrp; +} ### VIEW ### if($fwhostsettings{'ACTION'} eq '') { @@ -1135,13 +1124,13 @@ if($fwhostsettings{'ACTION'} eq '') } ### FUNCTIONS ### sub showmenu { - &Header::openbox('100%', 'left',$Lang::tr{'fwhost menu'}); + &Header::openbox('100%', 'left',); print "$Lang::tr{'fwhost welcome'}"; print<
-

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



"; }else{ - print ""; - } + print ""; + } print "
"; &Header::closebox(); } @@ -1179,11 +1168,11 @@ sub addhost $fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'}; $fwhostsettings{'orgremark'}=$fwhostsettings{'HOSTREMARK'}; print< + - + END if ($fwhostsettings{'ACTION'} eq 'edithost' || $fwhostsettings{'error'} eq 'on') @@ -1215,21 +1204,41 @@ sub addgrp $checked{'check1'}{'on'} = ''; $checked{'grp2'}{$fwhostsettings{'grp2'}} = 'CHECKED'; $fwhostsettings{'oldremark'}=$fwhostsettings{'remark'}; + $fwhostsettings{'oldgrpname'}=$fwhostsettings{'grp_name'}; my $grp=$fwhostsettings{'grp_name'}; my $rem=$fwhostsettings{'remark'}; if ($fwhostsettings{'update'} eq ''){ print< - - -
$Lang::tr{'name'}:
IP/MAC:
$Lang::tr{'remark'}:


$Lang::tr{'fwhost addgrpname'}
$Lang::tr{'remark'}:


+ + + + + + + + + + + + +
$Lang::tr{'fwhost addgrpname'}
$Lang::tr{'remark'}:

END }else{ print< - $Lang::tr{'fwhost addgrpname'} - $Lang::tr{'remark'}: -
+ + + + + + + + + + + + +
$Lang::tr{'fwhost addgrpname'}
$Lang::tr{'remark'}:
+

END } if ($fwhostsettings{'update'} eq 'on'){ @@ -1237,8 +1246,16 @@ END
- - +
- -
$Lang::tr{'fwhost stdnet'} + + + "; if (! -z $confignet){ - print" + "; } if (! -z $confighost){ - print" +
+ + +
$Lang::tr{'fwhost cust net'} + + +
$Lang::tr{'fwhost cust addr'} + + +
"; #Inner table right - print"
"; + print"
"; #OVPN networks if (! -z $configccdnet){ - print" + + + + ";} print"
$Lang::tr{'fwhost ccdnet'} + $Lang::tr{'fwhost ccdnet'} + + + $Lang::tr{'fwhost ccdhost'} + $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"


"; + print"

"; } - print""; - print"
"; + print""; + print"
"; &Header::closebox(); } sub addservice @@ -1361,7 +1434,7 @@ END print<
$Lang::tr{'fwhost port'}:
- +


- +

END if ($fwhostsettings{'updatesrv'} eq 'on') @@ -1392,27 +1465,28 @@ sub addservicegrp &showmenu; &Header::openbox('100%', 'left', $Lang::tr{'fwhost addservicegrp'}); $fwhostsettings{'oldsrvgrpremark'}=$fwhostsettings{'SRVGRP_REMARK'}; + $fwhostsettings{'oldsrvgrpname'}=$fwhostsettings{'SRVGRP_NAME'}; if ($fwhostsettings{'updatesrvgrp'} eq ''){ print<
$Lang::tr{'fwhost addgrpname'}
$Lang::tr{'remark'}:



END }else{ print< -
$Lang::tr{'fwhost addgrpname'}
$Lang::tr{'remark'}:


+ + +
$Lang::tr{'fwhost addgrpname'}
$Lang::tr{'remark'}:

END } if($fwhostsettings{'updatesrvgrp'} eq 'on'){ print< - - +
$Lang::tr{'add'}
$Lang::tr{'add'}:



END } print< +
END @@ -1450,30 +1524,40 @@ sub viewtablenet if(! -z $confignet){ &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust net'}); &General::readhasharray("$confignet", \%customnetwork); + &General::readhasharray("$configgrp", \%customgrp); + &General::readhasharray("$fwconfigfwd", \%fwfwd); + &General::readhasharray("$fwconfiginp", \%fwinp); + &General::readhasharray("$fwconfigout", \%fwout); + if (!keys %customnetwork) { print "
$Lang::tr{'fwhost empty'}"; }else{ print< - $Lang::tr{'name'}$Lang::tr{'fwhost netaddress'}$Lang::tr{'remark'}$Lang::tr{'used'} + + END } my $count=0; + my $col=''; foreach my $key (sort {ncmp($a,$b)} keys %customnetwork) { if ($fwhostsettings{'ACTION'} eq 'editnet' && $fwhostsettings{'HOSTNAME'} eq $customnetwork{$key}[0]) { - print" "; + print" "; + $col="bgcolor='${Header::colouryellow}'"; }elsif ($count % 2) { - print" "; + $col="bgcolor='$color{'color20'}'"; + print" "; }else { - print" "; + $col="bgcolor='$color{'color22'}'"; + print" "; } my $colnet="$customnetwork{$key}[1]/".&General::subtocidr($customnetwork{$key}[2]); - print""; + my $netcount=&getnetcount($customnetwork{$key}[0]); + print""; print< + END - if($customnetwork{$key}[4] == '0') + if($netcount == '0') { - print""; + print""; }else{ - print""; + print""; } $count++; } @@ -1497,50 +1581,79 @@ END sub getcolor { my $c=shift; + my $sip; + my $scidr; + #Check if MAC + if (&General::validmac($c)){ return $c;} + + #Check if we got a full IP with subnet then split it + if($c =~ /^(.*?)\/(.*?)$/){ + ($sip,$scidr) = split ("/",$c); + }else{ + $sip=$c; + } + + #Now check if IP is part of ORANGE,BLUE or GREEN + if ( &General::IpInSubnet($sip,$netsettings{'ORANGE_ADDRESS'},$netsettings{'ORANGE_NETMASK'})){ + $tdcolor="$c"; + return $tdcolor; + } + if ( &General::IpInSubnet($sip,$netsettings{'GREEN_ADDRESS'},$netsettings{'GREEN_NETMASK'})){ + $tdcolor="$c"; + return $tdcolor; + } + if ( &General::IpInSubnet($sip,$netsettings{'BLUE_ADDRESS'},$netsettings{'BLUE_NETMASK'})){ + $tdcolor="$c"; + return $tdcolor; + } + #Check if IP is part of OpenVPN N2N subnet foreach my $key (sort keys %ccdhost){ if ($ccdhost{$key}[3] eq 'net'){ my ($a,$b) = split("/",$ccdhost{$key}[11]); - if (&General::IpInSubnet($c,$a,$b)){ - $tdcolor="style='color:$Header::colourovpn ;'"; + if (&General::IpInSubnet($sip,$a,$b)){ + $tdcolor="$c"; return $tdcolor; } } } + #Check if IP is part of OpenVPN dynamic subnet my ($a,$b) = split("/",$ovpnsettings{'DOVPN_SUBNET'}); - if (&General::IpInSubnet($c,$a,$b)){ - $tdcolor="style='color: $Header::colourovpn;'"; + if (&General::IpInSubnet($sip,$a,$b)){ + $tdcolor="$c"; return $tdcolor; } + #Check if IP is part of OpenVPN static subnet foreach my $key (sort keys %ccdnet){ my ($a,$b) = split("/",$ccdnet{$key}[1]); $b =&General::iporsubtodec($b); - if (&General::IpInSubnet($c,$a,$b)){ - $tdcolor="style='color: $Header::colourovpn;'"; + if (&General::IpInSubnet($sip,$a,$b)){ + $tdcolor="$c"; return $tdcolor; } } + #Check if IP is part of IPsec RW network if ($ipsecsettings{'RW_NET'} ne ''){ my ($a,$b) = split("/",$ipsecsettings{'RW_NET'}); $b=&General::iporsubtodec($b); - if (&General::IpInSubnet($c,$a,$b)){ - $tdcolor="style='color: $Header::colourvpn;'"; + if (&General::IpInSubnet($sip,$a,$b)){ + $tdcolor="$c"; return $tdcolor; } } + #Check if IP is part of a IPsec N2N network foreach my $key (sort keys %ipsecconf){ my ($a,$b) = split("/",$ipsecconf{$key}[11]); - if (&General::IpInSubnet($c,$a,$b)){ - $tdcolor="style='color: $Header::colourvpn;'"; + if (&General::IpInSubnet($sip,$a,$b)){ + $tdcolor="$c"; return $tdcolor; } } - $tdcolor=''; - return $tdcolor; + return "$c"; } sub viewtablehost { @@ -1549,26 +1662,39 @@ sub viewtablehost &General::readhasharray("$confighost", \%customhost); &General::readhasharray("$configccdnet", \%ccdnet); &General::readhasharray("$configccdhost", \%ccdhost); + &General::readhasharray("$fwconfigfwd", \%fwfwd); + &General::readhasharray("$fwconfiginp", \%fwinp); + &General::readhasharray("$fwconfigout", \%fwout); + &General::readhasharray("$configgrp", \%customgrp); if (!keys %customhost) { print "
$Lang::tr{'fwhost empty'}"; }else{ print< -
+
$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}[0]".&getcolor($colnet)."$customnetwork{$key}[3]$netcount x @@ -1481,11 +1565,11 @@ END
$Lang::tr{'name'}$Lang::tr{'fwhost ip_mac'}$Lang::tr{'remark'}$Lang::tr{'used'}
+ END } my $count=0; + my $col=''; 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" ";} + print" "; + $col="bgcolor='${Header::colouryellow}'"; + }elsif ($count % 2){ + print" "; + $col="bgcolor='$color{'color20'}'"; + }else{ + $col="bgcolor='$color{'color22'}'"; + print" "; + } my ($ip,$sub)=split(/\//,$customhost{$key}[2]); $customhost{$key}[4]=~s/\s+//g; - print""; + my $hostcount=0; + $hostcount=&gethostcount($customhost{$key}[0]); + print""; print<
+
END - if($customhost{$key}[4] == '0') + if($hostcount == '0') { - print""; + print""; }else{ - print""; + print""; } $count++; } @@ -1598,6 +1724,9 @@ sub viewtablegrp &General::readhasharray("$configccdnet", \%ccdnet); &General::readhasharray("$confighost", \%customhost); &General::readhasharray("$confignet", \%customnetwork); + &General::readhasharray("$fwconfigfwd", \%fwfwd); + &General::readhasharray("$fwconfiginp", \%fwinp); + &General::readhasharray("$fwconfigout", \%fwout); my @grp=(); my $helper=''; my $count=1; @@ -1605,10 +1734,19 @@ sub viewtablegrp my $remark; my $number; my $delflag; + my @counter; + my %hash; if (!keys %customgrp) - { + { print "
$Lang::tr{'fwhost err emptytable'}"; }else{ + #get all groups in a hash + foreach my $key (sort { ncmp($customgrp{$a}[0],$customgrp{$b}[0]) } sort { ncmp($customgrp{$a}[2],$customgrp{$b}[2]) } keys %customgrp){ + push (@counter,$customgrp{$key}[0]); + } + foreach my $key1 (@counter) { + $hash{$key1}++ ; + } 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]){ @@ -1626,42 +1764,55 @@ sub viewtablegrp if ($customgrp{$key}[2] eq "none"){$customgrp{$key}[2]=$Lang::tr{'fwhost err emptytable'};} $grpname=$customgrp{$key}[0]; $remark="$customgrp{$key}[1]"; - if($count gt 1){ print"
$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$customhost{$key}[0]".&getcolor($ip)."$customhost{$key}[3]$hostcount x @@ -1576,11 +1702,11 @@ END
";} + if($count gt 1){ print"";$count=1;} print "
$grpname   "; print " $Lang::tr{'remark'}:  $remark   " if ($remark ne ''); - print "$Lang::tr{'used'}: $customgrp{$key}[4]x"; - if($customgrp{$key}[4] == '0') + my $netgrpcount=&getnetcount($grpname); + print "$Lang::tr{'used'}: $netgrpcount x"; + if($netgrpcount == '0') { - print"
"; + print"
"; } - print"
"; - print""; + print""; + print"
Name$Lang::tr{'ip address'}$Lang::tr{'fwhost type'}
"; } - + my $col=''; if ( ($fwhostsettings{'ACTION'} eq 'editgrp' || $fwhostsettings{'update'} ne '') && $fwhostsettings{'grp_name'} eq $customgrp{$key}[0]) { - print" "; + print" "; + $col="bgcolor='${Header::colouryellow}'"; }elsif ($count %2 == 0){ - print""; + print""; + $col="bgcolor='$color{'color20'}'"; }else{ - print""; + print""; + $col="bgcolor='$color{'color22'}'"; } my $ip=&getipforgroup($customgrp{$key}[2],$customgrp{$key}[3]); - if ($ip eq ''){print"";} - print ""; + $col="bgcolor='${Header::colouryellow}'"; + } + print ""; }else{ print "$customgrp{$key}[2]"; } if ($ip eq '' && $customgrp{$key}[2] ne $Lang::tr{'fwhost err emptytable'}){ - print ""; @@ -1687,25 +1838,33 @@ sub viewtableservice &General::readhasharray("$fwconfiginp", \%fwinp); &General::readhasharray("$fwconfigout", \%fwout); print< - +
$Lang::tr{'name'}$Lang::tr{'fwhost ip_mac'}$Lang::tr{'fwhost type'}
"; + if ($ip eq ''){ + print"
"; if($customgrp{$key}[3] eq 'Standard Network'){ print &get_name($customgrp{$key}[2])."$Lang::tr{'fwhost deleted'}$customgrp{$key}[3]
"; + print "
$Lang::tr{'fwhost deleted'}$customgrp{$key}[3]"; }else{ 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""; + print"".&getcolor($ip)."$customgrp{$key}[3]"; + } + if ($delflag > 0 && $ip ne ''){ + print""; + #check if this group has only one entry + foreach my $key2 (keys %hash) { + if ($hash{$key2}<2 && $key2 eq $customgrp{$key}[0]){ + print "" ; + } + } } print"
$Lang::tr{'fwhost srv_name'}$Lang::tr{'fwhost prot'}$Lang::tr{'fwhost port'}ICMP$Lang::tr{'fwhost used'}
+ END + my $col=''; 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]) { - print" "; - }elsif ($count % 2){ print" ";}else{ print" ";} + print" "; + $col="bgcolor='${Header::colouryellow}'"; + }elsif ($count % 2){ + print" "; + $col="bgcolor='$color{'color22'}'"; + }else{ + print" "; + $col="bgcolor='$color{'color20'}'"; + } print<$customservice{$key}[0] - + "; + print""; }else{ - print""; + print""; } } print"
$Lang::tr{'fwhost srv_name'}$Lang::tr{'fwhost prot'}$Lang::tr{'fwhost port'}ICMP$Lang::tr{'fwhost used'}
$customservice{$key}[2]$customservice{$key}[1] + $customservice{$key}[0]$customservice{$key}[2]$customservice{$key}[1] END #Neuer count $srvcount=&getsrvcount($customservice{$key}[0]); if($customservice{$key}[3] eq 'All ICMP-Types'){print $Lang::tr{'fwdfw all icmp'};} elsif($customservice{$key}[3] ne 'BLANK'){print $customservice{$key}[3];} print<$srvcount x
+
$srvcount x @@ -1713,9 +1872,9 @@ END END if ($srvcount eq '0') { - print"
"; @@ -1728,10 +1887,15 @@ sub viewtableservicegrp my $grpname; my $remark; my $helper; + my $helper1; my $port; my $protocol; my $delflag; my $grpcount=0; + my $col=''; + my $lastentry=0; + my @counter; + my %hash; if (! -z $configsrvgrp){ &Header::openbox('100%', 'left', $Lang::tr{'fwhost cust srvgrp'}); &General::readhasharray("$configsrvgrp", \%customservicegrp); @@ -1740,6 +1904,12 @@ sub viewtableservicegrp &General::readhasharray("$fwconfiginp", \%fwinp); &General::readhasharray("$fwconfigout", \%fwout); my $number= keys %customservicegrp; + foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) }keys %customservicegrp){ + push (@counter,$customservicegrp{$key}[0]); + } + foreach my $key1 (@counter) { + $hash{$key1}++ ; + } foreach my $key (sort { ncmp($customservicegrp{$a}[0],$customservicegrp{$b}[0]) } sort { ncmp($customservicegrp{$a}[2],$customservicegrp{$b}[2]) }keys %customservicegrp){ $count++; if ($helper ne $customservicegrp{$key}[0]){ @@ -1757,28 +1927,36 @@ sub viewtableservicegrp } $grpname=$customservicegrp{$key}[0]; if ($customservicegrp{$key}[2] eq "none"){ - $customservicegrp{$key}[2]=$Lang::tr{'fwhost empty'}; + $customservicegrp{$key}[2]=$Lang::tr{'fwhost err emptytable'}; $port=''; $protocol=''; } $remark="$customservicegrp{$key}[1]"; - if($count >=2){print"";} + if($count >0){print"";$count=1;} print "
$grpname    "; print "$Lang::tr{'remark'}:  $remark " if ($remark ne ''); print "  $Lang::tr{'used'}: $grpcount x"; if($grpcount == '0') { - print"
"; + print"
"; } - print"
"; - print""; + print""; + print"
Name$Lang::tr{'port'}$Lang::tr{'fwhost prot'}
"; } if( $fwhostsettings{'SRVGRP_NAME'} eq $customservicegrp{$key}[0]) { - print" "; + print""; + $col="bgcolor='${Header::colouryellow}'"; }elsif ($count %2 == 0){ - print""; + print""; + $col="bgcolor='$color{'color20'}'"; }else{ - print""; + print""; + $col="bgcolor='$color{'color22'}'"; + } + #make lines yellow if it is a dummy entry + if ($customservicegrp{$key}[2] eq $Lang::tr{'fwhost err emptytable'}){ + print""; + $col="bgcolor='${Header::colouryellow}'"; } #Set fields if we use protocols in servicegroups if ($customservicegrp{$key}[2] ne 'TCP' || $customservicegrp{$key}[2] ne 'UDP' || $customservicegrp{$key}[2] ne 'ICMP'){ @@ -1790,7 +1968,7 @@ sub viewtableservicegrp if ($customservicegrp{$key}[2] eq 'IGMP'){$protocol='IGMP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IGMP";} if ($customservicegrp{$key}[2] eq 'IPIP'){$protocol='IPIP';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IPIP";} if ($customservicegrp{$key}[2] eq 'IPV6'){$protocol='IPV6';$customservicegrp{$key}[2]="$Lang::tr{'protocol'} IPv6 encapsulation";} - print ""; + print ""; foreach my $srv (sort keys %customservice){ if ($customservicegrp{$key}[2] eq $customservice{$srv}[0]){ $protocol=$customservice{$srv}[2]; @@ -1798,9 +1976,17 @@ sub viewtableservicegrp last; } } - print"
Name$Lang::tr{'port'}$Lang::tr{'fwhost prot'}
$customservicegrp{$key}[2]$customservicegrp{$key}[2]$port$protocol
"; - if ($delflag gt '1'){ - print""; + print"
$port$protocol"; + if ($delflag gt '0'){ + if ($customservicegrp{$key}[2] ne $Lang::tr{'fwhost err emptytable'}){ + print""; + } + #check if this group has only one entry + foreach my $key2 (keys %hash) { + if ($hash{$key2}<2 && $key2 eq $customservicegrp{$key}[0]){ + print "" ; + } + } } print""; if($protocol eq 'TCP' || $protocol eq 'UDP' || $protocol eq 'ICMP'){ @@ -1828,7 +2014,7 @@ sub checkname } sub checkgroup { - &General::readhasharray("$configsrvgrp", \%customservicegrp ); + &General::readhasharray("$configgrp", \%customgrp ); my $name=shift; foreach my $key (keys %customservicegrp) { if($customservicegrp{$key}[0] eq $name){ @@ -1903,6 +2089,33 @@ sub checkservicegroup } return $errormessage; } +sub checkrulereload +{ + my $search=shift; + &General::readhasharray("$fwconfigfwd", \%fwfwd); + &General::readhasharray("$fwconfiginp", \%fwinp); + &General::readhasharray("$fwconfigout", \%fwout); + + #check if service or servicegroup is used in rules + foreach my $key (keys %fwfwd){ + if($search eq $fwfwd{$key}[15]){ + &General::firewall_config_changed(); + return; + } + } + foreach my $key (keys %fwinp){ + if($search eq $fwinp{$key}[15]){ + &General::firewall_config_changed(); + return; + } + } + foreach my $key (keys %fwout){ + if($search eq $fwout{$key}[15]){ + &General::firewall_config_changed(); + return; + } + } +} sub error { if ($errormessage) { @@ -1930,6 +2143,84 @@ sub get_name return "$network" if ($val eq $defaultNetworks{$network}{'NAME'}); } } +sub gethostcount +{ + my $searchstring=shift; + my $srvcounter=0; + #Count services used in servicegroups + foreach my $key (keys %customgrp) { + if($customgrp{$key}[2] eq $searchstring){ + $srvcounter++; + } + } + #Count services used in firewall - config + foreach my $key1 (keys %fwfwd) { + if($fwfwd{$key1}[4] eq $searchstring){ + $srvcounter++; + } + if($fwfwd{$key1}[6] eq $searchstring){ + $srvcounter++; + } + } + #Count services used in firewall - input + foreach my $key2 (keys %fwinp) { + if($fwinp{$key2}[4] eq $searchstring){ + $srvcounter++; + } + if($fwinp{$key2}[6] eq $searchstring){ + $srvcounter++; + } + } + #Count services used in firewall - outgoing + foreach my $key3 (keys %fwout) { + if($fwout{$key3}[4] eq $searchstring){ + $srvcounter++; + } + if($fwout{$key3}[6] eq $searchstring){ + $srvcounter++; + } + } + return $srvcounter; +} +sub getnetcount +{ + my $searchstring=shift; + my $srvcounter=0; + #Count services used in servicegroups + foreach my $key (keys %customgrp) { + if($customgrp{$key}[2] eq $searchstring){ + $srvcounter++; + } + } + #Count services used in firewall - config + foreach my $key1 (keys %fwfwd) { + if($fwfwd{$key1}[4] eq $searchstring){ + $srvcounter++; + } + if($fwfwd{$key1}[6] eq $searchstring){ + $srvcounter++; + } + } + #Count services used in firewall - input + foreach my $key2 (keys %fwinp) { + if($fwinp{$key2}[4] eq $searchstring){ + $srvcounter++; + } + if($fwinp{$key2}[6] eq $searchstring){ + $srvcounter++; + } + } + #Count services used in firewall - outgoing + foreach my $key3 (keys %fwout) { + if($fwout{$key3}[4] eq $searchstring){ + $srvcounter++; + } + if($fwout{$key3}[6] eq $searchstring){ + $srvcounter++; + } + } + return $srvcounter; +} sub getsrvcount { my $searchstring=shift; @@ -2218,6 +2509,36 @@ sub decreaseservice &General::writehasharray("$configsrv", \%customservice); } +sub changenameinfw +{ + my $old=shift; + my $new=shift; + my $fld=shift; + &General::readhasharray("$fwconfigfwd", \%fwfwd); + &General::readhasharray("$fwconfiginp", \%fwinp); + &General::readhasharray("$fwconfigout", \%fwout); + #Rename group in Firewall-CONFIG + foreach my $key1 (keys %fwfwd) { + if($fwfwd{$key1}[$fld] eq $old){ + $fwfwd{$key1}[$fld]=$new; + } + } + &General::writehasharray("$fwconfigfwd", \%fwfwd ); + #Rename group in Firewall-INPUT + foreach my $key2 (keys %fwinp) { + if($fwinp{$key2}[$fld] eq $old){ + $fwinp{$key2}[$fld]=$new; + } + } + &General::writehasharray("$fwconfiginp", \%fwinp ); + #Rename group in Firewall-OUTGOING + foreach my $key3 (keys %fwout) { + if($fwout{$key3}[$fld] eq $old){ + $fwout{$key3}[$fld]=$new; + } + } + &General::writehasharray("$fwconfigout", \%fwout ); +} sub checkports {