Skip to content

Commit

Permalink
firewall: take first region for country, not last
Browse files Browse the repository at this point in the history
  • Loading branch information
fichtner committed Jan 27, 2018
1 parent cbcb9da commit 7ebd5fc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/www/firewall_aliases_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ function geoip_countries()
foreach (explode("\n", file_get_contents('/usr/local/opnsense/contrib/tzdata/iso3166.tab')) as $line) {
$line = trim($line);
if (strlen($line) > 3 && substr($line, 0, 1) != '#') {
$code = substr($line, 0, 2);
$name = trim(substr($line, 2, 9999));
$result[$code] = $name;
$code = substr($line, 0, 2);
$name = trim(substr($line, 2, 9999));
$result[$code] = $name;
}
}
uasort($result, function($a, $b) {return strcasecmp($a, $b);});
Expand All @@ -112,7 +112,9 @@ function geoip_regions()
if (empty($line[2]) || strpos($line[2], '/') === false) {
continue;
}
$result[$line[0]] = explode('/', $line[2])[0];
if (empty($result[$line[0]])) {
$result[$line[0]] = explode('/', $line[2])[0];
}
}
return $result;
}
Expand Down

4 comments on commit 7ebd5fc

@fichtner
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AdSchellevis as per IRC, this bug seems to be back :(

@AdSchellevis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fichtner that doesn't sound very logical, this

foreach (explode("\n", file_get_contents('/usr/local/opnsense/contrib/tzdata/zone.tab')) as $line) {
if (strlen($line) > 0 && substr($line, 0, 1) == '#' ) {
continue;
}
$line = explode("\t", $line);
if (empty($line[0]) || strlen($line[0]) != 2) {
continue;
}
if (empty($line[2]) || strpos($line[2], '/') === false) {
continue;
}
if (empty($result[$line[0]])) {
$result[$line[0]] = explode('/', $line[2])[0];
}

is the same as
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Firewall/Api/AliasController.php#L173-L187

What's the test case?

@fichtner
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

United States is in Pacific, not America.

@AdSchellevis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fichtner ok, that's weird, first in the file is America, last is Pacific. I can fix it, bit don't know why this would have worked before:

https://github.com/opnsense/core/blob/master/contrib/tzdata/zone.tab#L403-L431

Please sign in to comment.