firewall.cgi: Rework to use location-functions.pl

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
This commit is contained in:
Stefan Schantl
2020-06-12 19:31:41 +02:00
parent 006e3c6c31
commit 10ef824bb7

View File

@@ -35,7 +35,7 @@ require '/var/ipfire/general-functions.pl';
require '/var/ipfire/network-functions.pl'; require '/var/ipfire/network-functions.pl';
require "${General::swroot}/lang.pl"; require "${General::swroot}/lang.pl";
require "${General::swroot}/header.pl"; require "${General::swroot}/header.pl";
require "${General::swroot}/geoip-functions.pl"; require "${General::swroot}/location-functions.pl";
require "/usr/lib/firewall/firewall-lib.pl"; require "/usr/lib/firewall/firewall-lib.pl";
unless (-d "${General::swroot}/firewall") { system("mkdir ${General::swroot}/firewall"); } unless (-d "${General::swroot}/firewall") { system("mkdir ${General::swroot}/firewall"); }
@@ -50,7 +50,7 @@ my %defaultNetworks=();
my %netsettings=(); my %netsettings=();
my %customhost=(); my %customhost=();
my %customgrp=(); my %customgrp=();
my %customgeoipgrp=(); my %customlocationgrp=();
my %customnetworks=(); my %customnetworks=();
my %customservice=(); my %customservice=();
my %customservicegrp=(); my %customservicegrp=();
@@ -78,7 +78,7 @@ my $color;
my $confignet = "${General::swroot}/fwhosts/customnetworks"; my $confignet = "${General::swroot}/fwhosts/customnetworks";
my $confighost = "${General::swroot}/fwhosts/customhosts"; my $confighost = "${General::swroot}/fwhosts/customhosts";
my $configgrp = "${General::swroot}/fwhosts/customgroups"; my $configgrp = "${General::swroot}/fwhosts/customgroups";
my $configgeoipgrp = "${General::swroot}/fwhosts/customgeoipgrp"; my $configlocationgrp = "${General::swroot}/fwhosts/customlocationgrp";
my $configsrv = "${General::swroot}/fwhosts/customservices"; my $configsrv = "${General::swroot}/fwhosts/customservices";
my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp"; my $configsrvgrp = "${General::swroot}/fwhosts/customservicegrp";
my $configccdnet = "${General::swroot}/ovpn/ccd.conf"; my $configccdnet = "${General::swroot}/ovpn/ccd.conf";
@@ -1071,41 +1071,41 @@ END
} }
print"</select></td>"; print"</select></td>";
} }
# geoip locations / groups. # Locations / groups.
my @geoip_locations = &fwlib::get_geoip_locations(); my @locations = &fwlib::get_locations();
print "<tr>\n"; print "<tr>\n";
print "<td valign='top'><input type='radio' name='$grp' id='cust_geoip_$srctgt' value='cust_geoip_$srctgt' $checked{$grp}{'cust_geoip_'.$srctgt}></td>\n"; print "<td valign='top'><input type='radio' name='$grp' id='cust_location_$srctgt' value='cust_location_$srctgt' $checked{$grp}{'cust_location_'.$srctgt}></td>\n";
print "<td>$Lang::tr{'geoip'}</td>\n"; print "<td>$Lang::tr{'location'}</td>\n";
print "<td align='right'><select name='cust_geoip_$srctgt' style='width:200px;'>\n"; print "<td align='right'><select name='cust_location_$srctgt' style='width:200px;'>\n";
# Add GeoIP groups to dropdown. # Add Location groups to dropdown.
if (!-z $configgeoipgrp) { if (!-z $configlocationgrp) {
print "<optgroup label='$Lang::tr{'fwhost cust geoipgroup'}'>\n"; print "<optgroup label='$Lang::tr{'fwhost cust locationgroup'}'>\n";
foreach my $key (sort { ncmp($customgeoipgrp{$a}[0],$customgeoipgrp{$b}[0]) } keys %customgeoipgrp) { foreach my $key (sort { ncmp($customlocationgrp{$a}[0],$customlocationgrp{$b}[0]) } keys %customlocationgrp) {
my $selected; my $selected;
# Generate stored value for select detection. # Generate stored value for select detection.
my $stored = join(':', "group",$customgeoipgrp{$key}[0]); my $stored = join(':', "group",$customlocationgrp{$key}[0]);
# Only show a group once and group with elements. # Only show a group once and group with elements.
if($helper ne $customgeoipgrp{$key}[0] && $customgeoipgrp{$key}[2] ne 'none') { if($helper ne $customlocationgrp{$key}[0] && $customlocationgrp{$key}[2] ne 'none') {
# Mark current entry as selected. # Mark current entry as selected.
if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $stored) { if ($fwdfwsettings{$fwdfwsettings{$grp}} eq $stored) {
$selected = "selected='selected'"; $selected = "selected='selected'";
} }
print"<option $selected value='group:$customgeoipgrp{$key}[0]'>$customgeoipgrp{$key}[0]</option>\n"; print"<option $selected value='group:$customlocationgrp{$key}[0]'>$customlocationgrp{$key}[0]</option>\n";
} }
$helper=$customgeoipgrp{$key}[0]; $helper=$customlocationgrp{$key}[0];
} }
print "</optgroup>\n"; print "</optgroup>\n";
} }
# Add locations. # Add locations.
print "<optgroup label='$Lang::tr{'fwhost cust geoiplocation'}'>\n"; print "<optgroup label='$Lang::tr{'fwhost cust location'}'>\n";
foreach my $location (@geoip_locations) { foreach my $location (@locations) {
# Get country name. # Get country name.
my $country_name = &GeoIP::get_full_country_name($location); my $country_name = &Location::Functions::get_full_country_name($location);
# Mark current entry as selected. # Mark current entry as selected.
my $selected; my $selected;
@@ -1116,7 +1116,7 @@ END
} }
print "</optgroup>\n"; print "</optgroup>\n";
# Close GeoIP dropdown. # Close Locations dropdown.
print "</select></td>\n"; print "</select></td>\n";
#End left table. start right table (vpn) #End left table. start right table (vpn)
@@ -1476,7 +1476,7 @@ sub newrule
&General::readhasharray("$confighost", \%customhost); &General::readhasharray("$confighost", \%customhost);
&General::readhasharray("$configccdhost", \%ccdhost); &General::readhasharray("$configccdhost", \%ccdhost);
&General::readhasharray("$configgrp", \%customgrp); &General::readhasharray("$configgrp", \%customgrp);
&General::readhasharray("$configgeoipgrp", \%customgeoipgrp); &General::readhasharray("$configlocationgrp", \%customlocationgrp);
&General::readhasharray("$configipsec", \%ipsecconf); &General::readhasharray("$configipsec", \%ipsecconf);
&General::get_aliases(\%aliases); &General::get_aliases(\%aliases);
my %checked=(); my %checked=();
@@ -2611,12 +2611,12 @@ END
}else{ }else{
print $$hash{$key}[4]; print $$hash{$key}[4];
} }
}elsif ($$hash{$key}[3] eq 'cust_geoip_src') { }elsif ($$hash{$key}[3] eq 'cust_location_src') {
my ($split1,$split2) = split(":", $$hash{$key}[4]); my ($split1,$split2) = split(":", $$hash{$key}[4]);
if ($split2) { if ($split2) {
print "$split2\n"; print "$split2\n";
}else{ }else{
print "$Lang::tr{'geoip'}: $$hash{$key}[4]\n"; print "$Lang::tr{'location'}: $$hash{$key}[4]\n";
} }
}elsif ($$hash{$key}[4] eq 'RED1'){ }elsif ($$hash{$key}[4] eq 'RED1'){
print "$ipfireiface $Lang::tr{'fwdfw red'}"; print "$ipfireiface $Lang::tr{'fwdfw red'}";
@@ -2699,12 +2699,12 @@ END
}else{ }else{
print $$hash{$key}[6]; print $$hash{$key}[6];
} }
}elsif ($$hash{$key}[5] eq 'cust_geoip_tgt') { }elsif ($$hash{$key}[5] eq 'cust_location_tgt') {
my ($split1,$split2) = split(":", $$hash{$key}[6]); my ($split1,$split2) = split(":", $$hash{$key}[6]);
if ($split2) { if ($split2) {
print "$split2\n"; print "$split2\n";
}else{ }else{
print "$Lang::tr{'geoip'}: $$hash{$key}[6]\n"; print "$Lang::tr{'location'}: $$hash{$key}[6]\n";
} }
}elsif ($$hash{$key}[5] eq 'tgt_addr'){ }elsif ($$hash{$key}[5] eq 'tgt_addr'){
my ($split1,$split2) = split("/",$$hash{$key}[6]); my ($split1,$split2) = split("/",$$hash{$key}[6]);