}
}
if (!$errormessage){
- &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
- if ($fwdfwsettings{'nobase'} ne 'on'){
- &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
- }
- if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
- &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
- }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
- &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
- }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
- &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
- }
if($fwdfwsettings{'nosave2'} ne 'on'){
&saverule(\%configinputfw,$configinput);
}
}
#increase counters
if (!$errormessage){
- &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
- &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
- if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
- &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
- }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
- &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
- }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
- &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
- }
- if ($fwdfwsettings{'nobase'} eq 'on'){
- &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
- }
if ($fwdfwsettings{'nosave2'} ne 'on'){
&saverule(\%configoutgoingfw,$configoutgoing);
}
}
#increase counters
if (!$errormessage){
- &checkcounter($fwdfwsettings{'oldgrp1a'},$fwdfwsettings{'oldgrp1b'},$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
- &checkcounter($fwdfwsettings{'oldgrp2a'},$fwdfwsettings{'oldgrp2b'},$fwdfwsettings{'grp2'},$fwdfwsettings{$fwdfwsettings{'grp2'}});
- if($fwdfwsettings{'oldusesrv'} eq '' && $fwdfwsettings{'USESRV'} eq 'ON'){
- &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
- }elsif ($fwdfwsettings{'USESRV'} eq '' && $fwdfwsettings{'oldusesrv'} eq 'ON') {
- &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},0,0);
- }elsif ($fwdfwsettings{'oldusesrv'} eq $fwdfwsettings{'USESRV'} && $fwdfwsettings{'oldgrp3b'} ne $fwdfwsettings{$fwdfwsettings{'grp3'}} && $fwdfwsettings{'updatefwrule'} eq 'on'){
- &checkcounter($fwdfwsettings{'oldgrp3a'},$fwdfwsettings{'oldgrp3b'},$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
- }
- if ($fwdfwsettings{'nobase'} eq 'on'){
- &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
- }
if ($fwdfwsettings{'nosave2'} ne 'on'){
&saverule(\%configfwdfw,$configfwdfw);
}
$fwdfwsettings{'config'}=$oldchain;
$fwdfwsettings{'nobase'}='on';
&deleterule;
- &checkcounter(0,0,$fwdfwsettings{'grp1'},$fwdfwsettings{$fwdfwsettings{'grp1'}});
- &checkcounter(0,0,$fwdfwsettings{'grp3'},$fwdfwsettings{$fwdfwsettings{'grp3'}});
}
sub checksource
{
$fwdfwsettings{'ICMP_TYPES'}='';
}
}
-sub checkcounter
-{
- my ($base1,$val1,$base2,$val2) = @_;
-
- if($base1 eq 'cust_net_src' || $base1 eq 'cust_net_tgt'){
- &dec_counter($confignet,\%customnetwork,$val1);
- }elsif($base1 eq 'cust_host_src' || $base1 eq 'cust_host_tgt'){
- &dec_counter($confighost,\%customhost,$val1);
- }elsif($base1 eq 'cust_grp_src' || $base1 eq 'cust_grp_tgt'){
- &dec_counter($configgrp,\%customgrp,$val1);
- }elsif($base1 eq 'cust_srv'){
- &dec_counter($configsrv,\%customservice,$val1);
- }elsif($base1 eq 'cust_srvgrp'){
- &dec_counter($configsrvgrp,\%customservicegrp,$val1);
- }
-
- if($base2 eq 'cust_net_src' || $base2 eq 'cust_net_tgt'){
- &inc_counter($confignet,\%customnetwork,$val2);
- }elsif($base2 eq 'cust_host_src' || $base2 eq 'cust_host_tgt'){
- &inc_counter($confighost,\%customhost,$val2);
- }elsif($base2 eq 'cust_grp_src' || $base2 eq 'cust_grp_tgt'){
- &inc_counter($configgrp,\%customgrp,$val2);
- }elsif($base2 eq 'cust_srv'){
- &inc_counter($configsrv,\%customservice,$val2);
- }elsif($base2 eq 'cust_srvgrp'){
- &inc_counter($configsrvgrp,\%customservicegrp,$val2);
- }
-}
sub checkvpn
{
my $ip=shift;
my %delhash=();
&General::readhasharray($fwdfwsettings{'config'}, \%delhash);
foreach my $key (sort {$a <=> $b} keys %delhash){
- if ($key == $fwdfwsettings{'key'}){
- #check hosts/net and groups
- &checkcounter($delhash{$key}[3],$delhash{$key}[4],,);
- &checkcounter($delhash{$key}[5],$delhash{$key}[6],,);
- #check services and groups
- if ($delhash{$key}[11] eq 'ON'){
- &checkcounter($delhash{$key}[14],$delhash{$key}[15],,);
- }
- }
if ($key >= $fwdfwsettings{'key'}) {
my $next = $key + 1;
if (exists $delhash{$next}) {
&General::writehasharray("$configfwdfw", \%configfwdfw);
&General::firewall_config_changed();
}
-sub dec_counter
-{
- my $config=shift;
- my %hash=%{(shift)};
- my $val=shift;
- my $pos;
- &General::readhasharray($config, \%hash);
- foreach my $key (sort { uc($hash{$a}[0]) cmp uc($hash{$b}[0]) } keys %hash){
- if($hash{$key}[0] eq $val){
- $pos=$#{$hash{$key}};
- $hash{$key}[$pos] = $hash{$key}[$pos]-1;
- }
- }
- &General::writehasharray($config, \%hash);
-}
sub error
{
if ($errormessage) {
return 0;}
return 1;
}
-
-sub viewtablerule {
+sub viewtablerule
+{
&General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
&viewtablenew(\%configfwdfw, $configfwdfw, $Lang::tr{'firewall rules'});
&viewtablenew(\%configinputfw, $configinput, $Lang::tr{'external access'});
&viewtablenew(\%configoutgoingfw, $configoutgoing, $Lang::tr{'outgoing firewall'});
}
-
sub viewtablenew
{
my $hash=shift;
my %ipsecsettings=();
my %fwfwd=();
my %fwinp=();
+my %fwout=();
my %ovpnsettings=();
my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp";
my $fwconfigfwd = "${General::swroot}/firewall/config";
my $fwconfiginp = "${General::swroot}/firewall/input";
+my $fwconfigout = "${General::swroot}/firewall/outgoing";
my $configovpn = "${General::swroot}/ovpn/settings";
my $tdcolor='';
my $configipsecrw = "${General::swroot}/vpn/settings";
my $count=0;
my $needrules=0;
$errormessage=&checkports(\%customservice);
+ if ($fwhostsettings{'oldsrvname'} ne $fwhostsettings{'SRV_NAME'} && !&checkgroup($fwhostsettings{'SRV_NAME'})){
+ $errormessage=$Lang::tr{'fwhost err grpexist'};
+ }
if (!$errormessage){
&General::readhasharray("$configsrv", \%customservice);
foreach my $key (keys %customservice)
{
if ($customservice{$key}[0] eq $fwhostsettings{'oldsrvname'})
{
- $count=$customservice{$key}[4];
delete $customservice{$key};
&General::writehasharray("$configsrv", \%customservice);
last;
$customservice{$key1}[1] = $fwhostsettings{'SRV_PORT'};
$customservice{$key1}[2] = $fwhostsettings{'PROT'};
$customservice{$key1}[3] = $fwhostsettings{'ICMP_TYPES'};
- $customservice{$key1}[4] = $count;
&General::writehasharray("$configsrv", \%customservice);
#check if we need to update firewallrules
if ($fwhostsettings{'SRV_NAME'} ne $fwhostsettings{'oldsrvname'}){
}
&General::writehasharray("$fwconfiginp", \%fwinp);
}
+ if ( ! -z $fwconfigout ){
+ &General::readhasharray("$fwconfigout", \%fwout);
+ foreach my $line (sort keys %fwout){
+ if ($fwout{$line}[15] eq $fwhostsettings{'oldsrvname'}){
+ $fwout{$line}[15] = $fwhostsettings{'SRV_NAME'};
+ }
+ }
+ &General::writehasharray("$fwconfigout", \%fwout);
+ }
#check if we need to update groups
&General::readhasharray("$configsrvgrp", \%customservicegrp);
foreach my $key (sort keys %customservicegrp){
$fwhostsettings{'PROT'} = '';
$fwhostsettings{'ICMP'} = '';
$fwhostsettings{'oldsrvicmp'} = '';
+ $fwhostsettings{'updatesrv'} = '';
}else{
$fwhostsettings{'SRV_NAME'} = $fwhostsettings{'oldsrvname'};
$fwhostsettings{'SRV_PORT'} = $fwhostsettings{'oldsrvport'};
$fwhostsettings{'ICMP'} = $fwhostsettings{'oldsrvicmp'};
$fwhostsettings{'updatesrv'}= 'on';
}
- $fwhostsettings{'updatesrv'} = '';
if($needrules eq 'on'){
&General::firewall_config_changed();
}
#check name
if (!&validhostname($grp)){$errormessage.=$Lang::tr{'fwhost err name'};}
#check existing name
- if (!checkgroup(\%customgrp,$grp) && $fwhostsettings{'update'} ne 'on'){$errormessage.=$Lang::tr{'fwhost err grpexist'};}
+ if (!&checkgroup($grp) && $fwhostsettings{'update'} ne 'on'){$errormessage.=$Lang::tr{'fwhost err grpexist'};}
#check remark
if ($rem ne '' && !&validremark($rem) && $fwhostsettings{'update'} ne 'on'){
$errormessage.=$Lang::tr{'fwhost err remark'};
{
my $ICMP;
&General::readhasharray("$configsrv", \%customservice );
+ &General::readhasharray("$configgrp", \%customgrp);
$errormessage=&checkports(\%customservice);
if ($fwhostsettings{'PROT'} eq 'ICMP'){
&General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
}
}
if($ICMP eq ''){$ICMP=$fwhostsettings{'ICMP_TYPES'};}
- if ($fwhostsettings{'PROT'} ne 'ICMP'){$ICMP='';}
+ if ($fwhostsettings{'PROT'} ne 'ICMP'){$ICMP='BLANK';}
+ #Check if a group with the same name already exists
+ if (!&checkgroup($fwhostsettings{'SRV_NAME'})){
+ $errormessage = $Lang::tr{'fwhost err grpexist'};
+ }
if (!$errormessage){
my $key = &General::findhasharraykey (\%customservice);
foreach my $i (0 .. 4) { $customservice{$key}[$i] = "";}
$customservice{$key}[1] = $fwhostsettings{'SRV_PORT'};
$customservice{$key}[2] = $fwhostsettings{'PROT'};
$customservice{$key}[3] = $ICMP;
- $customservice{$key}[4] = 0;
&General::writehasharray("$configsrv", \%customservice );
#reset fields
$fwhostsettings{'SRV_NAME'}='';
if ($fwhostsettings{'SRVGRP_REMARK'} ne '' && !&validremark($fwhostsettings{'SRVGRP_REMARK'})){
$errormessage .= $Lang::tr{'fwhost err remark'};
}
+ #Check if there is already a service with the same name
+ if(!&checkservice($fwhostsettings{'SRVGRP_NAME'})){
+ $errormessage .= $Lang::tr{'fwhost err srv exists'};
+ }
if (!$errormessage){
#on first save, we have to enter a dummy value
if ($fwhostsettings{'CUST_SRV'} eq ''){
{
$customservicegrp{$key}[1]='';
$customservicegrp{$key}[1]=$fwhostsettings{'SRVGRP_REMARK'};
- }
- }
- }
- #get count used
- foreach my $key (keys %customservicegrp)
- {
- if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'})
- {
- $count=$customservicegrp{$key}[3];
- last;
- }
- }
- if ($count eq '' ){$count='0';}
-
- foreach my $key (sort keys %customservice){
- if($customservice{$key}[0] eq $fwhostsettings{'CUST_SRV'}){
- $port=$customservice{$key}[1];
- $prot=$customservice{$key}[2];
- $customservice{$key}[4]++;
+ }
}
}
- &General::writehasharray("$configsrv", \%customservice );
my $key = &General::findhasharraykey (\%customservicegrp);
- foreach my $i (0 .. 3) { $customservice{$key}[$i] = "";}
+ foreach my $i (0 .. 2) { $customservice{$key}[$i] = "";}
$customservicegrp{$key}[0] = $fwhostsettings{'SRVGRP_NAME'};
$customservicegrp{$key}[1] = $fwhostsettings{'SRVGRP_REMARK'};
$customservicegrp{$key}[2] = $fwhostsettings{'CUST_SRV'};
- $customservicegrp{$key}[3] = $count;
&General::writehasharray("$configsrvgrp", \%customservicegrp );
$fwhostsettings{'updatesrvgrp'}='on';
}
&General::readhasharray("$configsrv", \%customservice);
foreach my $key (keys %customservice) {
if($customservice{$key}[0] eq $fwhostsettings{'SRV_NAME'}){
- #&deletefromgrp($customhost{$key}[0],$configgrp);
delete $customservice{$key};
&General::writehasharray("$configsrv", \%customservice);
last;
&General::readhasharray("$configsrvgrp", \%customservicegrp);
&General::readhasharray("$configsrv", \%customservice);
foreach my $key (keys %customservicegrp){
- if($customservicegrp{$key}[0].",".$customservicegrp{$key}[1].",".$customservicegrp{$key}[2].",".$customservicegrp{$key}[3] eq $fwhostsettings{'delsrvfromgrp'})
+ if($customservicegrp{$key}[0].",".$customservicegrp{$key}[1].",".$customservicegrp{$key}[2] eq $fwhostsettings{'delsrvfromgrp'})
{
#decrease count from source service
foreach my $key1 (sort keys %customservice){
sub viewtableservice
{
my $count=0;
+ my $srvcount;
if(! -z "$configsrv")
{
&Header::openbox('100%', 'left', $Lang::tr{'fwhost services'});
&General::readhasharray("$configsrv", \%customservice);
+ &General::readhasharray("$configsrvgrp", \%customservicegrp);
+ &General::readhasharray("$fwconfigfwd", \%fwfwd);
+ &General::readhasharray("$fwconfiginp", \%fwinp);
+ &General::readhasharray("$fwconfigout", \%fwout);
print<<END;
<table width='100%' border='0' cellspacing='0'>
<tr><td align='center'><b>$Lang::tr{'fwhost srv_name'}</b></td><td align='center'><b>$Lang::tr{'fwhost prot'}</b></td><td align='center'><b>$Lang::tr{'fwhost port'}</b></td><td align='center'><b>ICMP</b></td><td align='center'><b>$Lang::tr{'fwhost used'}</b></td><td></td><td width='3%'></td></tr>
print<<END;
<td>$customservice{$key}[0]</td><td align='center'>$customservice{$key}[2]</td><td align='center'>$customservice{$key}[1]</td><td align='center'>
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<<END;
- </td><td align='center'>$customservice{$key}[4]x</td>
+ </td><td align='center'>$srvcount x</td>
<td width='1%'><form method='post'><input type='image' src='/images/edit.gif' align='middle' alt=$Lang::tr{'edit'} title=$Lang::tr{'edit'} /><input type='hidden' name='ACTION' value='editservice' />
<input type='hidden' name='SRV_NAME' value='$customservice{$key}[0]' />
<input type='hidden' name='SRV_PORT' value='$customservice{$key}[1]' />
<input type='hidden' name='PROT' value='$customservice{$key}[2]' />
<input type='hidden' name='ICMP' value='$customservice{$key}[3]' /></form></td>
END
- if ($customservice{$key}[4] eq '0')
+ if ($srvcount eq '0')
{
print"<td width='1%'><form method='post'><input type='image' src='/images/delete.gif' align='middle' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} /><input type='hidden' name='ACTION' value='delservice' /><input type='hidden' name='SRV_NAME' value='$customservice{$key}[0]'></td></tr></form>";
}else{
my $port;
my $protocol;
my $delflag;
+ my $grpcount=0;
if (! -z $configsrvgrp){
&Header::openbox('100%', 'left', $Lang::tr{'fwhost cust srvgrp'});
&General::readhasharray("$configsrvgrp", \%customservicegrp);
&General::readhasharray("$configsrv", \%customservice);
+ &General::readhasharray("$fwconfigfwd", \%fwfwd);
+ &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){
$count++;
if ($helper ne $customservicegrp{$key}[0]){
+ #Get used groupcounter
+ $grpcount=&getsrvcount($customservicegrp{$key}[0]);
$delflag=0;
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])
if($count >=2){print"</table>";}
print "<br><b><u>$grpname</u></b> ";
print "<b>$Lang::tr{'remark'}:</b> $remark " if ($remark ne '');
- print " <b>$Lang::tr{'used'}:</b> $customservicegrp{$key}[3]x";
- if($customservicegrp{$key}[3] == '0')
+ print " <b>$Lang::tr{'used'}:</b> $grpcount x";
+ if($grpcount == '0')
{
print"<form method='post' style='display:inline'><input type='image' src='/images/delete.gif' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} align='right' /><input type='hidden' name='SRVGRP_NAME' value='$grpname' ><input type='hidden' name='ACTION' value='delservicegrp'></form>";
}
}
print"<input type='hidden' name='ACTION' value='delgrpservice'><input type='hidden' name='updatesrvgrp' value='$fwhostsettings{'updatesrvgrp'}'>";
if($protocol eq 'TCP' || $protocol eq 'UDP' || $protocol eq 'ICMP'){
- print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$customservicegrp{$key}[2],$customservicegrp{$key}[3]'></form></td></tr>";
+ print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$customservicegrp{$key}[2]'></form></td></tr>";
}else{
- print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$protocol,$customservicegrp{$key}[3]'></form></td></tr>";
+ print "<input type='hidden' name='delsrvfromgrp' value='$grpname,$remark,$protocol'></form></td></tr>";
}
$helper=$customservicegrp{$key}[0];
}
}
sub checkgroup
{
- my %hash=%{(shift)};
+ &General::readhasharray("$configsrvgrp", \%customservicegrp );
my $name=shift;
- foreach my $key (keys %hash) {
- if($hash{$key}[0] eq $name){
+ foreach my $key (keys %customservicegrp) {
+ if($customservicegrp{$key}[0] eq $name){
+ return 0;
+ }
+ }
+ return 1;
+}
+sub checkservice
+{
+ &General::readhasharray("$configsrv", \%customservice );
+ my $name=shift;
+ foreach my $key (keys %customservice) {
+ if($customservice{$key}[0] eq $name){
return 0;
}
}
return "$network" if ($val eq $defaultNetworks{$network}{'NAME'});
}
}
+sub getsrvcount
+{
+ my $searchstring=shift;
+ my $srvcounter=0;
+ #Count services used in servicegroups
+ foreach my $key (keys %customservicegrp) {
+ if($customservicegrp{$key}[2] eq $searchstring){
+ $srvcounter++;
+ }
+ }
+ #Count services used in firewall - config
+ foreach my $key1 (keys %fwfwd) {
+ if($fwfwd{$key1}[15] eq $searchstring){
+ $srvcounter++;
+ }
+ }
+ #Count services used in firewall - input
+ foreach my $key2 (keys %fwinp) {
+ if($fwinp{$key2}[15] eq $searchstring){
+ $srvcounter++;
+ }
+ }
+ #Count services used in firewall - outgoing
+ foreach my $key3 (keys %fwout) {
+ if($fwout{$key3}[15] eq $searchstring){
+ $srvcounter++;
+ }
+ }
+ return $srvcounter;
+}
sub deletefromgrp
{
my $target=shift;