X-Git-Url: http://git.ipfire.org/?p=people%2Fteissler%2Fipfire-2.x.git;a=blobdiff_plain;f=html%2Fcgi-bin%2Ffwhosts.cgi;h=face57b32c642d9ef840ec7290a59b68602d1138;hp=89b2a9321f91d124304c3835dfd13230076f2ee6;hb=12dcfbbdbe38f8b81a3969f70516511ec779d011;hpb=85dc70c746cd8fe0b602c0e98f2cc4b2232507ec diff --git a/html/cgi-bin/fwhosts.cgi b/html/cgi-bin/fwhosts.cgi index 89b2a9321..face57b32 100755 --- a/html/cgi-bin/fwhosts.cgi +++ b/html/cgi-bin/fwhosts.cgi @@ -108,7 +108,6 @@ if ($fwhostsettings{'ACTION'} eq 'updatehost') { if($customhost{$key}[0] eq $fwhostsettings{'orgname'}) { - $fwhostsettings{'orgname'} = $customhost{$key}[0]; if ($customhost{$key}[1] eq 'ip'){ ($ip,$subnet) = split (/\//,$customhost{$key}[2]); }else{ @@ -117,21 +116,21 @@ if ($fwhostsettings{'ACTION'} eq 'updatehost') $fwhostsettings{'orgip'} = $ip; $fwhostsettings{'count'} = $customhost{$key}[3]; delete $customhost{$key}; + &General::writehasharray("$confighost", \%customhost); } } - &General::writehasharray("$confighost", \%customhost); - - - $fwhostsettings{'actualize'} = 'on'; + if($fwhostsettings{'orgip'}){ $fwhostsettings{'ACTION'} = 'savehost'; + }else{ + $fwhostsettings{'ACTION'} = $Lang::tr{'fwhost newhost'}; + } } if ($fwhostsettings{'ACTION'} eq 'updateservice') { my $count=0; my $needrules=0; $errormessage=&checkports(\%customservice); - if (!$errormessage){ &General::readhasharray("$configsrv", \%customservice); foreach my $key (keys %customservice) @@ -155,30 +154,54 @@ if ($fwhostsettings{'ACTION'} eq 'updateservice') $customservice{$key1}[3] = $fwhostsettings{'ICMP_TYPES'}; $customservice{$key1}[4] = $count; &General::writehasharray("$configsrv", \%customservice); - if($fwhostsettings{'updatesrv'} eq 'on'){ - if($count gt 0 && $fwhostsettings{'oldsrvport'} ne $fwhostsettings{'SRV_PORT'} ){ - $needrules='on'; + #check if we need to update firewallrules + if ($fwhostsettings{'SRV_NAME'} ne $fwhostsettings{'oldsrvname'}){ + if ( ! -z $fwconfigfwd ){ + &General::readhasharray("$fwconfigfwd", \%fwfwd); + foreach my $key (sort keys %fwfwd){ + if ($fwfwd{$key}[15] eq $fwhostsettings{'oldsrvname'}){ + $fwfwd{$key}[15] = $fwhostsettings{'SRV_NAME'}; + } + } + &General::writehasharray("$fwconfigfwd", \%fwfwd); + } + if ( ! -z $fwconfiginp ){ + &General::readhasharray("$fwconfiginp", \%fwinp); + foreach my $line (sort keys %fwinp){ + if ($fwfwd{$line}[15] eq $fwhostsettings{'oldsrvname'}){ + $fwfwd{$line}[15] = $fwhostsettings{'SRV_NAME'}; + } + } + &General::writehasharray("$fwconfiginp", \%fwinp); } - if($count gt 0 && $fwhostsettings{'oldsrvprot'} ne $fwhostsettings{'PROT'} ){ - $needrules='on'; + #check if we need to update groups + &General::readhasharray("$configsrvgrp", \%customservicegrp); + foreach my $key (sort keys %customservicegrp){ + if($customservicegrp{$key}[2] eq $fwhostsettings{'oldsrvname'}){ + $customservicegrp{$key}[2] = $fwhostsettings{'SRV_NAME'}; + } } + &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'; } $fwhostsettings{'SRV_NAME'} = ''; $fwhostsettings{'SRV_PORT'} = ''; $fwhostsettings{'PROT'} = ''; - }else{ $fwhostsettings{'SRV_NAME'} = $fwhostsettings{'oldsrvname'}; $fwhostsettings{'SRV_PORT'} = $fwhostsettings{'oldsrvport'}; $fwhostsettings{'PROT'} = $fwhostsettings{'oldsrvprot'}; $fwhostsettings{'updatesrv'}= 'on'; } - if($needrules eq 'on'){ - $errormessage="reread!"; &rules; } - &addservice; } # save @@ -187,7 +210,6 @@ 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 if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '') { @@ -207,7 +229,6 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' ) if(&General::iporsubtocidr($fwhostsettings{'SUBNET'}) eq '32') { $errormessage=$errormessage.$Lang::tr{'fwhost err sub32'}; - } if($fwhostsettings{'error'} ne 'on'){ #check if we use one of ipfire's networks (green,orange,blue) @@ -240,14 +261,12 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' ) if (!$errormessage){ &plausicheck("editnet"); } - #check if network ip is part of an already used one if(&checksubnet(\%customnetwork)) { $errormessage=$errormessage.$Lang::tr{'fwhost err partofnet'}; $fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'}; } - if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newnet'} ne 'on' && $errormessage) { $fwhostsettings{'actualize'} = ''; @@ -260,7 +279,6 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' ) &General::writehasharray("$confignet", \%customnetwork); undef %customnetwork; } - if (!$errormessage){ &General::readhasharray("$confignet", \%customnetwork); if ($fwhostsettings{'ACTION'} eq 'updatenet'){ @@ -345,23 +363,19 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' ) &viewtablenet; } } - } if ($fwhostsettings{'ACTION'} eq 'savehost') { my $count=0; my $needrules=0; if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};} - $fwhostsettings{'SUBNET'}='32'; - #check if all fields are set if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '') { $errormessage=$errormessage.$Lang::tr{'fwhost err empty'}; $fwhostsettings{'ACTION'} = 'edithost'; }else{ - if($fwhostsettings{'type'} eq 'ip' && $fwhostsettings{'IP'}=~/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/){ $fwhostsettings{'type'} = 'mac'; }elsif($fwhostsettings{'type'} eq 'mac' && $fwhostsettings{'IP'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){ @@ -374,13 +388,11 @@ if ($fwhostsettings{'ACTION'} eq 'savehost') $fwhostsettings{'type'} = ''; $errormessage=$Lang::tr{'fwhost err ipmac'}; } - if($fwhostsettings{'type'} eq 'mac' ) { if ($fwhostsettings{'IP'}!~/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/ ) { $errormessage=$Lang::tr{'fwhost err mac'}; - } } #CHECK IP-PART @@ -392,7 +404,6 @@ if ($fwhostsettings{'ACTION'} eq 'savehost') $errormessage.=$errormessage.$Lang::tr{'fwhost err ip'}; $fwhostsettings{'error'}='on'; } - }elsif(rindex($fwhostsettings{'IP'},'/') ne '-1' ){ $errormessage=$errormessage.$Lang::tr{'fwhost err ipwithsub'}; $fwhostsettings{'error'}='on'; @@ -403,14 +414,10 @@ if ($fwhostsettings{'ACTION'} eq 'savehost') $errormessage=$Lang::tr{'fwhost err hostip'}; } } - - - #only check plausi when no error till now if (!$errormessage){ &plausicheck("edithost"); } - if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newhost'} ne 'on' && $errormessage){ $fwhostsettings{'actualize'} = ''; my $key = &General::findhasharraykey (\%customhost); @@ -425,9 +432,7 @@ if ($fwhostsettings{'ACTION'} eq 'savehost') $customhost{$key}[3] = $fwhostsettings{'count'}; &General::writehasharray("$confighost", \%customhost); undef %customhost; - } - if (!$errormessage){ #get count if host was edited if($fwhostsettings{'actualize'} eq 'on'){ @@ -484,8 +489,6 @@ if ($fwhostsettings{'ACTION'} eq 'savehost') if($fwhostsettings{'newhost'} eq 'on'){$count=0;} $customhost{$key}[3] = $count; &General::writehasharray("$confighost", \%customhost); - - #$fwhostsettings{'IP'} = $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'}); undef %customhost; $fwhostsettings{'HOSTNAME'}=''; $fwhostsettings{'IP'}=''; @@ -500,9 +503,7 @@ if ($fwhostsettings{'ACTION'} eq 'savehost') &addhost; &viewtablehost; } - } - } if ($fwhostsettings{'ACTION'} eq 'savegrp') { @@ -517,9 +518,7 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp') &General::readhasharray("$confignet", \%customnetwork); &General::readhasharray("$confighost", \%customhost); $grp=$fwhostsettings{'grp_name'}; - - if (!&General::validhostname($grp)){$errormessage=$errormessage.$Lang::tr{'fwhost err name'};} - + if (!&validhostname($grp)){$errormessage=$errormessage.$Lang::tr{'fwhost err name'};} ###check standard networks if ($fwhostsettings{'grp2'} eq 'std_net'){ @target=$fwhostsettings{'DEFAULT_SRC_ADR'}; @@ -570,7 +569,6 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp') $fwhostsettings{'grp_name'}=''; $fwhostsettings{'remark'}=''; } - #get address from IPSEC HOST if ($fwhostsettings{'grp2'} eq 'ipsec_host' && $fwhostsettings{'IPSEC_HOST'} ne ''){ @target=$fwhostsettings{'IPSEC_HOST'}; @@ -589,7 +587,6 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp') $fwhostsettings{'grp_name'}=''; $fwhostsettings{'remark'}=''; } - #check if host/net exists in grp my $test="$grp,$fwhostsettings{'oldremark'},@target"; foreach my $key (keys %customgrp) { @@ -599,7 +596,6 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp') $fwhostsettings{'update'} = 'on'; } } - if (!$errormessage){ #on first save, we have an empty @target, so fill it with nothing my $targetvalues=@target; @@ -607,7 +603,6 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp') @target=$Lang::tr{'fwhost empty'}; } #on update, we have to delete the dummy entry - foreach my $key (keys %customgrp){ if ($customgrp{$key}[0] eq $grp && $customgrp{$key}[2] eq $Lang::tr{'fwhost empty'}){ delete $customgrp{$key}; @@ -616,21 +611,6 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp') } &General::writehasharray("$configgrp", \%customgrp); &General::readhasharray("$configgrp", \%customgrp); - - - - #check if remark has also changed - if ($fwhostsettings{'remark'} ne $fwhostsettings{'oldremark'} && $fwhostsettings{'update'} eq 'on') - { - foreach my $key (keys %customgrp) - { - if($customgrp{$key}[0] eq $grp && $customgrp{$key}[1] eq $fwhostsettings{'oldremark'}) - { - $customgrp{$key}[1]=''; - $customgrp{$key}[1]=$rem; - } - } - } #get count used foreach my $key (keys %customgrp) { @@ -658,7 +638,6 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp') $customgrp{$key}[4] = $count; } &General::writehasharray("$configgrp", \%customgrp); - #update counter in Host/Net if($updcounter eq 'net'){ foreach my $key (keys %customnetwork) { @@ -676,13 +655,11 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp') } &General::writehasharray("$confighost", \%customhost); } - $fwhostsettings{'update'}='on'; - } - if ($fwhostsettings{'remark'} ne $fwhostsettings{'oldremark'} && $errormessage) + if ($fwhostsettings{'remark'} ne $fwhostsettings{'oldremark'} ) { - foreach my $key (keys %customgrp) + foreach my $key (sort keys %customgrp) { if($customgrp{$key}[0] eq $grp && $customgrp{$key}[1] eq $fwhostsettings{'oldremark'}) { @@ -690,9 +667,8 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp') $customgrp{$key}[1]=$rem; } } - &General::writehasharray("$configsrvgrp", \%customservicegrp); + &General::writehasharray("$configgrp", \%customgrp); $errormessage=''; - $hint=$Lang::tr{'fwhost changeremark'}; $fwhostsettings{'update'}='on'; } #check if ruleupdate is needed @@ -702,15 +678,12 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp') } &addgrp; &viewtablegrp; - } if ($fwhostsettings{'ACTION'} eq 'saveservice') { my $ICMP; - &General::readhasharray("$configsrv", \%customservice ); $errormessage=&checkports(\%customservice); - if ($fwhostsettings{'PROT'} eq 'ICMP'){ &General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes); foreach my $key (keys %icmptypes){ @@ -721,7 +694,6 @@ if ($fwhostsettings{'ACTION'} eq 'saveservice') } if($ICMP eq ''){$ICMP='BLANK';} if (!$errormessage){ - my $key = &General::findhasharraykey (\%customservice); foreach my $i (0 .. 4) { $customservice{$key}[$i] = "";} $customservice{$key}[0] = $fwhostsettings{'SRV_NAME'}; @@ -735,11 +707,8 @@ if ($fwhostsettings{'ACTION'} eq 'saveservice') $fwhostsettings{'SRV_PORT'}=''; $fwhostsettings{'PROT'}=''; $fwhostsettings{'ICMP_TYPES'}=''; - } - &addservice; - } if ($fwhostsettings{'ACTION'} eq 'saveservicegrp') { @@ -748,13 +717,10 @@ if ($fwhostsettings{'ACTION'} eq 'saveservicegrp') my $count=0; &General::readhasharray("$configsrvgrp", \%customservicegrp ); &General::readhasharray("$configsrv", \%customservice ); - $errormessage=&checkservicegroup; - if (!$errormessage){ #on first save, we have to enter a dummy value if ($fwhostsettings{'CUST_SRV'} eq ''){$fwhostsettings{'CUST_SRV'}=$Lang::tr{'fwhost empty'};} - #on update, we have to delete the dummy entry foreach my $key (keys %customservicegrp){ if ($customservicegrp{$key}[2] eq $Lang::tr{'fwhost empty'}){ @@ -780,7 +746,7 @@ if ($fwhostsettings{'ACTION'} eq 'saveservicegrp') { if($customservicegrp{$key}[0] eq $fwhostsettings{'SRVGRP_NAME'}) { - $count=$customservicegrp{$key}[5]; + $count=$customservicegrp{$key}[3]; last; } } @@ -794,15 +760,12 @@ if ($fwhostsettings{'ACTION'} eq 'saveservicegrp') } } &General::writehasharray("$configsrv", \%customservice ); - my $key = &General::findhasharraykey (\%customservicegrp); foreach my $i (0 .. 3) { $customservice{$key}[$i] = "";} $customservicegrp{$key}[0] = $fwhostsettings{'SRVGRP_NAME'}; $customservicegrp{$key}[1] = $fwhostsettings{'SRVGRP_REMARK'}; $customservicegrp{$key}[2] = $fwhostsettings{'CUST_SRV'}; - $customservicegrp{$key}[3] = $port; - $customservicegrp{$key}[4] = $prot; - $customservicegrp{$key}[5] = $count; + $customservicegrp{$key}[3] = $count; &General::writehasharray("$configsrvgrp", \%customservicegrp ); $fwhostsettings{'updatesrvgrp'}='on'; } @@ -895,7 +858,6 @@ if ($fwhostsettings{'ACTION'} eq 'delhost') } &addhost; &viewtablehost; - } if ($fwhostsettings{'ACTION'} eq 'deletegrphost') { @@ -1313,7 +1275,7 @@ END