From 9350297f18fd8820d461d8d18e372a9f650d66ca Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Tue, 26 Jun 2018 17:30:11 +0200 Subject: [PATCH] Firewall/Alias, add list countries action, for https://github.com/opnsense/core/issues/1858 --- .../OPNsense/Firewall/Api/AliasController.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Firewall/Api/AliasController.php b/src/opnsense/mvc/app/controllers/OPNsense/Firewall/Api/AliasController.php index 71455eff2..27db9d206 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Firewall/Api/AliasController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Firewall/Api/AliasController.php @@ -113,4 +113,39 @@ class AliasController extends ApiMutableModelControllerBase { return $this->toggleBase("aliases.aliases", $uuid); } + + /** + * list countries and regions + * @return array indexed by country code + */ + public function listCountriesAction() + { + $result = array(); + + 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) != '#') { + $result[substr($line, 0, 2)] = array( + "name" => trim(substr($line, 2, 9999)), + "region" => null + ); + } + } + 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]]['region'] = explode('/', $line[2])[0]; + } + } + return $result; + } }