From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexander Marx To: development@lists.ipfire.org Subject: [PATCH] BUG12265: firewall: iptables rules are being created in the wrong chain Fixes: #12265 Date: Thu, 25 Mar 2021 11:23:46 +0100 Message-ID: <20210325102346.55138-1-alexander.marx@ipfire.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============5265887888091578458==" List-Id: --===============5265887888091578458== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable When creating a rule like Source:Orange and Target:green IPfire Interface, the rule was created in the forward instead of input chain. This patch sets correct chain and additionally checks if a single target ip (when set) is one of the ipfire interface ip addresses. If this is the case, the target is automatically changed to IPFIRE interface = instead of single target ip. --- html/cgi-bin/firewall.cgi | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/html/cgi-bin/firewall.cgi b/html/cgi-bin/firewall.cgi index 532f99f91..c680eed1d 100644 --- a/html/cgi-bin/firewall.cgi +++ b/html/cgi-bin/firewall.cgi @@ -2,7 +2,7 @@ ############################################################################= ### # = # # IPFire.org - A linux based firewall = # -# Copyright (C) 2013 Alexander Marx = # +# Copyright (C) 2021 Alexander Marx = # # = # # This program is free software: you can redistribute it and/or modify = # # it under the terms of the GNU General Public License as published by = # @@ -213,6 +213,7 @@ if ($fwdfwsettings{'ACTION'} eq 'saverule') &General::readhasharray("$configfwdfw", \%configfwdfw); &General::readhasharray("$configinput", \%configinputfw); &General::readhasharray("$configoutgoing", \%configoutgoingfw); + &General::readhash("/var/ipfire/ethernet/settings", \%netsettings); my $maxkey; #Set Variables according to the JQuery code in protocol section if ($fwdfwsettings{'PROT'} eq 'TCP' || $fwdfwsettings{'PROT'} eq 'UDP') @@ -231,6 +232,19 @@ if ($fwdfwsettings{'ACTION'} eq 'saverule') { $fwdfwsettings{'USESRV'} =3D 'ON'; } + #Check if manual targetip is one of IPFire addresses + if ($fwdfwsettings{'grp2'} eq 'tgt_addr' && $fwdfwsettings{$fwdfwsettings{'= grp2'}} eq $netsettings{'GREEN_ADDRESS'}){ + $fwdfwsettings{'grp2'} =3D 'ipfire'; + $fwdfwsettings{$fwdfwsettings{'grp2'}} =3D 'GREEN'; + } + if ($fwdfwsettings{'grp2'} eq 'tgt_addr' && $fwdfwsettings{$fwdfwsettings{'= grp2'}} eq $netsettings{'ORANGE_ADDRESS'}){ + $fwdfwsettings{'grp2'} =3D 'ipfire'; + $fwdfwsettings{$fwdfwsettings{'grp2'}} =3D 'ORANGE'; + } + if ($fwdfwsettings{'grp2'} eq 'tgt_addr' && $fwdfwsettings{$fwdfwsettings{'= grp2'}} eq $netsettings{'BLUE_ADDRESS'}){ + $fwdfwsettings{'grp2'} =3D 'ipfire'; + $fwdfwsettings{$fwdfwsettings{'grp2'}} =3D 'BLUE'; + } $errormessage=3D&checksource; if(!$errormessage){&checktarget;} if(!$errormessage){&checkrule;} @@ -247,7 +261,7 @@ if ($fwdfwsettings{'ACTION'} eq 'saverule') $errormessage=3D$Lang::tr{'fwdfw err same'}; } # INPUT part - if ($fwdfwsettings{'grp2'} eq 'ipfire' && $fwdfwsettings{$fwdfwsettings{'gr= p1'}} ne 'ORANGE'){ + if ($fwdfwsettings{'grp2'} eq 'ipfire'){ $fwdfwsettings{'config'}=3D$configinput; $fwdfwsettings{'chain'} =3D 'INPUTFW'; $maxkey=3D&General::findhasharraykey(\%configinputfw); @@ -1512,7 +1526,7 @@ sub newrule $checked{'USE_NAT'}{$fwdfwsettings{'USE_NAT'}} =3D 'CHECKED'; $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} =3D 'selected'; $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} =3D 'selected'; - $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} =3D'selected'; + $selected{'ipfire tgt'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} =3D'selecte= d'; $selected{'ipfire_src'}{$fwdfwsettings{$fwdfwsettings{'grp1'}}} =3D'selecte= d'; #check if update and get values if($fwdfwsettings{'updatefwrule'} eq 'on' || $fwdfwsettings{'copyfwrule'} e= q 'on' && !$errormessage){ @@ -1526,7 +1540,7 @@ sub newrule $fwdfwsettings{'ACTIVE'} =3D $hash{$key}[2]; $fwdfwsettings{'grp1'} =3D $hash{$key}[3]; =20 $fwdfwsettings{$fwdfwsettings{'grp1'}} =3D $hash{$key}[4]; =20 - $fwdfwsettings{'grp2'} =3D $hash{$key}[5]; =20 + $fwdfwsettings{'grp2'} =3D $hash{$key}[5]; $fwdfwsettings{$fwdfwsettings{'grp2'}} =3D $hash{$key}[6]; =20 $fwdfwsettings{'USE_SRC_PORT'} =3D $hash{$key}[7]; $fwdfwsettings{'PROT'} =3D $hash{$key}[8]; @@ -1584,7 +1598,7 @@ sub newrule $checked{'RATE_LIMIT'}{$fwdfwsettings{'RATE_LIMIT'}} =3D 'CHECKED'; $selected{'TIME_FROM'}{$fwdfwsettings{'TIME_FROM'}} =3D 'selected'; $selected{'TIME_TO'}{$fwdfwsettings{'TIME_TO'}} =3D 'selected'; - $selected{'ipfire'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} =3D'selected= '; + $selected{'ipfire tgt'}{$fwdfwsettings{$fwdfwsettings{'grp2'}}} =3D'sele= cted'; $selected{'ipfire_src'}{$fwdfwsettings{$fwdfwsettings{'grp1'}}} =3D'sele= cted'; $selected{'dnat'}{$fwdfwsettings{'dnat'}} =3D'selected'; $selected{'snat'}{$fwdfwsettings{'snat'}} =3D'selected'; @@ -1753,16 +1767,16 @@ END =09 END - print"
$Lang::tr{'fwdfw targetip= '}= Firewall