From d3f7e3d3973565534a1b4ff41af2623a4296dfad Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Thu, 29 Nov 2018 21:06:52 +0100 Subject: [PATCH] MVC, change __items to iterateItems(), closes https://github.com/opnsense/core/issues/2670 --- .../mvc/app/models/OPNsense/HAProxy/HAProxy.php | 12 ++++++------ .../models/OPNsense/HAProxy/Migrations/M2_0_0.php | 6 +++--- .../models/OPNsense/HAProxy/Migrations/M2_3_0.php | 2 +- .../controllers/OPNsense/Wol/Api/WolController.php | 3 +-- .../src/www/widgets/widgets/wake_on_lan.widget.php | 4 ++-- .../OPNsense/AcmeClient/Api/SettingsController.php | 2 +- .../app/models/OPNsense/AcmeClient/AcmeClient.php | 6 +++--- .../scripts/OPNsense/AcmeClient/certhelper.php | 4 ++-- .../scripts/tor/make_hidden_service_dirs.php | 2 +- .../OPNsense/Nginx/Api/LogsController.php | 4 ++-- .../controllers/OPNsense/Nginx/IndexController.php | 2 +- .../src/opnsense/scripts/nginx/ngx_autoblock.php | 6 +++--- www/nginx/src/opnsense/scripts/nginx/setup.php | 4 ++-- 13 files changed, 28 insertions(+), 29 deletions(-) diff --git a/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.php b/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.php index c50c36086..0e9f5277b 100644 --- a/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.php +++ b/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.php @@ -46,7 +46,7 @@ class HAProxy extends BaseModel { if ((string)$this->general->enabled === "1") { if ($checkFrontends === true) { - foreach ($this->frontends->frontend->__items as $frontend) { + foreach ($this->frontends->frontend->iterateItems() as $frontend) { if ((string)$frontend->enabled === "1") { return true; // Found a active frontend } @@ -65,7 +65,7 @@ class HAProxy extends BaseModel */ public function getByFrontendID($uuid) { - foreach ($this->frontends->frontend->__items as $frontend) { + foreach ($this->frontends->frontend->iterateItems() as $frontend) { if ((string)$uuid === (string)$frontend->getAttributes()["uuid"]) { return $frontend; } @@ -80,7 +80,7 @@ class HAProxy extends BaseModel */ public function getByBackendID($uuid) { - foreach ($this->backends->backend->__items as $backend) { + foreach ($this->backends->backend->iterateItems() as $backend) { if ((string)$uuid === (string)$backend->getAttributes()["uuid"]) { return $backend; } @@ -95,7 +95,7 @@ class HAProxy extends BaseModel */ public function getByServerID($uuid) { - foreach ($this->servers->server->__items as $server) { + foreach ($this->servers->server->iterateItems() as $server) { if ((string)$uuid === (string)$server->getAttributes()["uuid"]) { return $server; } @@ -110,7 +110,7 @@ class HAProxy extends BaseModel */ public function getByActionID($uuid) { - foreach ($this->actions->action->__items as $action) { + foreach ($this->actions->action->iterateItems() as $action) { if ((string)$uuid === (string)$action->getAttributes()["uuid"]) { return $action; } @@ -125,7 +125,7 @@ class HAProxy extends BaseModel */ public function getByAclID($uuid) { - foreach ($this->acls->acl->__items as $acl) { + foreach ($this->acls->acl->iterateItems() as $acl) { if ((string)$uuid === (string)$acl->getAttributes()["uuid"]) { return $acl; } diff --git a/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/Migrations/M2_0_0.php b/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/Migrations/M2_0_0.php index cfb31ad94..dc3560799 100644 --- a/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/Migrations/M2_0_0.php +++ b/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/Migrations/M2_0_0.php @@ -35,7 +35,7 @@ class M2_0_0 extends BaseModelMigration public function run($model) { // Migrate ACLs - foreach ($model->getNodeByReference('acls.acl')->__items as $acl) { + foreach ($model->getNodeByReference('acls.acl')->iterateItems() as $acl) { switch ((string)$acl->expression) { case 'host_starts_with': $acl->expression = 'hdr_beg'; @@ -145,7 +145,7 @@ class M2_0_0 extends BaseModelMigration } // Migrate Actions - foreach ($model->getNodeByReference('actions.action')->__items as $action) { + foreach ($model->getNodeByReference('actions.action')->iterateItems() as $action) { switch ((string)$action->type) { case 'use_backend': $action->use_backend = (string)$action->useBackend; @@ -255,7 +255,7 @@ class M2_0_0 extends BaseModelMigration } // Migrate Healthchecks - foreach ($model->getNodeByReference('healthchecks.healthcheck')->__items as $hc) { + foreach ($model->getNodeByReference('healthchecks.healthcheck')->iterateItems() as $hc) { switch ((string)$hc->type) { case 'agent': $hc->agent_port = (string)$hc->agentPort; diff --git a/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/Migrations/M2_3_0.php b/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/Migrations/M2_3_0.php index 27c6f3c0b..d4f025da5 100644 --- a/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/Migrations/M2_3_0.php +++ b/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/Migrations/M2_3_0.php @@ -35,7 +35,7 @@ class M2_3_0 extends BaseModelMigration public function run($model) { // Persistence is a separate option now. - foreach ($model->getNodeByReference('backends.backend')->__items as $backend) { + foreach ($model->getNodeByReference('backends.backend')->iterateItems() as $backend) { if (isset($backend->stickiness_pattern)) { $backend->persistence = 'sticktable'; } diff --git a/net/wol/src/opnsense/mvc/app/controllers/OPNsense/Wol/Api/WolController.php b/net/wol/src/opnsense/mvc/app/controllers/OPNsense/Wol/Api/WolController.php index 70a9dc50f..f28074cd1 100644 --- a/net/wol/src/opnsense/mvc/app/controllers/OPNsense/Wol/Api/WolController.php +++ b/net/wol/src/opnsense/mvc/app/controllers/OPNsense/Wol/Api/WolController.php @@ -94,8 +94,7 @@ class WolController extends ApiMutableModelControllerBase return array('error' => 'Must be called via POST'); } $results = array('results' => array()); - $wol = $this->getModel()->wolentry->__items; - foreach ($wol as $wolent) { + foreach ($this->getModel()->wolentry->iterateItems() as $wolent) { $result = array('mac' => (string)$wolent->mac); $this->wakeHostByNode($wolent, $result); $results['results'][] = $result; diff --git a/net/wol/src/www/widgets/widgets/wake_on_lan.widget.php b/net/wol/src/www/widgets/widgets/wake_on_lan.widget.php index 606a05a4f..38d4c2f2c 100644 --- a/net/wol/src/www/widgets/widgets/wake_on_lan.widget.php +++ b/net/wol/src/www/widgets/widgets/wake_on_lan.widget.php @@ -44,7 +44,7 @@ $wol = new Wol(); wolentry->__items as $wolent): + foreach ($wol->wolentry->iterateItems() as $wolent): $is_active = exec("/usr/sbin/arp -an |/usr/bin/grep {$wolent->mac}| /usr/bin/wc -l|/usr/bin/awk '{print $1;}'");?> descr) ? $wolent->descr : gettext('Unnamed entry') ?>
mac ?> @@ -61,7 +61,7 @@ $wol = new Wol(); wolentry->__items) == 0):?> + if (count($wol->wolentry->iterateItems()) == 0):?> diff --git a/security/acme-client/src/opnsense/mvc/app/controllers/OPNsense/AcmeClient/Api/SettingsController.php b/security/acme-client/src/opnsense/mvc/app/controllers/OPNsense/AcmeClient/Api/SettingsController.php index 3a7fdf7e1..3771b6b7e 100644 --- a/security/acme-client/src/opnsense/mvc/app/controllers/OPNsense/AcmeClient/Api/SettingsController.php +++ b/security/acme-client/src/opnsense/mvc/app/controllers/OPNsense/AcmeClient/Api/SettingsController.php @@ -309,7 +309,7 @@ class SettingsController extends ApiMutableModelControllerBase } // Ensure HAProxy frontend additions have been applied. - foreach ($mdlAcme->getNodeByReference('validations.validation')->__items as $validation) { + foreach ($mdlAcme->getNodeByReference('validations.validation')->iterateItems() as $validation) { // Find all (enabled) validation methods with HAProxy integration. if ((string)$validation->enabled == "1" and (string)$validation->method == "http01" and diff --git a/security/acme-client/src/opnsense/mvc/app/models/OPNsense/AcmeClient/AcmeClient.php b/security/acme-client/src/opnsense/mvc/app/models/OPNsense/AcmeClient/AcmeClient.php index 70427ab5c..6c19ca79f 100644 --- a/security/acme-client/src/opnsense/mvc/app/models/OPNsense/AcmeClient/AcmeClient.php +++ b/security/acme-client/src/opnsense/mvc/app/models/OPNsense/AcmeClient/AcmeClient.php @@ -45,7 +45,7 @@ class AcmeClient extends BaseModel */ public function getByCertificateID($certificateid) { - foreach ($this->certificates->certificate->__items as $certificate) { + foreach ($this->certificates->certificate->iterateItems() as $certificate) { if ((string)$certificateid === (string)$certificate->certificateid) { return $certificate; } @@ -62,7 +62,7 @@ class AcmeClient extends BaseModel { if ((string)$this->settings->enabled === "1") { if ($checkCertificates === true) { - foreach ($this->certificates->certificate->__items as $certificate) { + foreach ($this->certificates->certificate->iterateItems() as $certificate) { if ((string)$certificate->enabled == "1") { return true; // Found a active certificate } @@ -81,7 +81,7 @@ class AcmeClient extends BaseModel */ public function getByActionID($uuid) { - foreach ($this->actions->action->__items as $action) { + foreach ($this->actions->action->iterateItems() as $action) { if ((string)$uuid === (string)$action->getAttributes()["uuid"]) { return $action; } diff --git a/security/acme-client/src/opnsense/scripts/OPNsense/AcmeClient/certhelper.php b/security/acme-client/src/opnsense/scripts/OPNsense/AcmeClient/certhelper.php index 898355e2b..ba27fb519 100755 --- a/security/acme-client/src/opnsense/scripts/OPNsense/AcmeClient/certhelper.php +++ b/security/acme-client/src/opnsense/scripts/OPNsense/AcmeClient/certhelper.php @@ -140,7 +140,7 @@ function cert_action_validator($opt_cert_id) $acctRef = (string)$certObj->account; $acctObj = null; $acctref_found = false; - foreach ($modelObj->getNodeByReference('accounts.account')->__items as $node) { + foreach ($modelObj->getNodeByReference('accounts.account')->iterateItems() as $node) { if ((string)$node->getAttributes()["uuid"] == $acctRef) { $acctref_found = true; $acctObj = $node; @@ -177,7 +177,7 @@ function cert_action_validator($opt_cert_id) $valRef = (string)$certObj->validationMethod; $valObj = null; $ref_found = false; - foreach ($modelObj->getNodeByReference('validations.validation')->__items as $node) { + foreach ($modelObj->getNodeByReference('validations.validation')->iterateItems() as $node) { if ((string)$node->getAttributes()["uuid"] == $valRef) { $ref_found = true; $valObj = $node; diff --git a/security/tor/src/opnsense/scripts/tor/make_hidden_service_dirs.php b/security/tor/src/opnsense/scripts/tor/make_hidden_service_dirs.php index 58a0b6b6d..4d7090e00 100755 --- a/security/tor/src/opnsense/scripts/tor/make_hidden_service_dirs.php +++ b/security/tor/src/opnsense/scripts/tor/make_hidden_service_dirs.php @@ -35,7 +35,7 @@ require_once('tor_helper.php'); use \OPNsense\Tor\HiddenService; $services = new HiddenService(); -foreach ($services->service->__items as $service) { +foreach ($services->service->iterateItems() as $service) { $directory_name = ((string)$service->name); $hostdir = TOR_DATA_DIR . '/' . $directory_name; if (!file_exists($hostdir)) { diff --git a/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/Api/LogsController.php b/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/Api/LogsController.php index 26d16716a..dbbee6481 100644 --- a/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/Api/LogsController.php +++ b/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/Api/LogsController.php @@ -104,7 +104,7 @@ class LogsController extends ApiControllerBase private function list_vhosts() { $data = []; - foreach ($this->nginx->http_server->__items as $item) { + foreach ($this->nginx->http_server->iterateItems() as $item) { $data[] = array('id' => $item->getAttributes()['uuid'], 'server_name' => (string)$item->servername); } return $data; @@ -112,7 +112,7 @@ class LogsController extends ApiControllerBase private function list_streams() { $data = []; - foreach ($this->nginx->stream_server->__items as $item) { + foreach ($this->nginx->stream_server->iterateItems() as $item) { $data[] = array('id' => $item->getAttributes()['uuid'], 'port' => (string)$item->listen_port); } return $data; diff --git a/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/IndexController.php b/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/IndexController.php index 817c2b8f3..e3782a706 100644 --- a/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/IndexController.php +++ b/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/IndexController.php @@ -62,7 +62,7 @@ class IndexController extends \OPNsense\Base\IndexController $this->view->ipacl = $this->getForm("ipacl"); $nginx = new Nginx(); $this->view->show_naxsi_download_button = - count($nginx->custom_policy->__items) == 0 && count($nginx->naxsi_rule->__items) == 0; + count($nginx->custom_policy->iterateItems()) == 0 && count($nginx->naxsi_rule->iterateItems()) == 0; $this->view->pick('OPNsense/Nginx/index'); } diff --git a/www/nginx/src/opnsense/scripts/nginx/ngx_autoblock.php b/www/nginx/src/opnsense/scripts/nginx/ngx_autoblock.php index 0dd2d2fe6..8152dccce 100755 --- a/www/nginx/src/opnsense/scripts/nginx/ngx_autoblock.php +++ b/www/nginx/src/opnsense/scripts/nginx/ngx_autoblock.php @@ -89,7 +89,7 @@ $log_lines = $log_parser->get_result(); $model = new Alias(); $blacklist_element = null; -foreach ($model->aliases->alias->__items as $alias) { +foreach ($model->aliases->alias->iterateItems() as $alias) { if ((string)$alias->name == $autoblock_alias_name) { if ((string)$alias->type != 'external') { nginx_print_error('alias is misconfigured - exiting'); @@ -111,7 +111,7 @@ if ($blacklist_element == null) { $model = new Nginx(); $alias_ips = []; -foreach ($model->ban->__items as $entry) { +foreach ($model->ban->iterateItems() as $entry) { $alias_ips[] = (string)$entry->ip; } @@ -148,7 +148,7 @@ if ($change_required) { echo '{"status":"saved"}'; // all ips are used because the others may not be set for some reason -foreach ($model->ban->__items as $entry) { +foreach ($model->ban->iterateItems() as $entry) { add_to_blocklist($autoblock_alias_name, (string)$entry->ip); } diff --git a/www/nginx/src/opnsense/scripts/nginx/setup.php b/www/nginx/src/opnsense/scripts/nginx/setup.php index 65bdca44a..bf2ed2934 100755 --- a/www/nginx/src/opnsense/scripts/nginx/setup.php +++ b/www/nginx/src/opnsense/scripts/nginx/setup.php @@ -213,7 +213,7 @@ if (isset($nginx['upstream'])) { // export users $nginx = new Nginx(); -foreach ($nginx->userlist->__items as $user_list) { +foreach ($nginx->userlist->iterateItems() as $user_list) { $attributes = $user_list->getAttributes(); $uuid = $attributes['uuid']; $file = null; @@ -234,6 +234,6 @@ foreach ($nginx->userlist->__items as $user_list) { } } // create directories for cache -foreach ($nginx->cache_path->__items as $cache_path) { +foreach ($nginx->cache_path->iterateItems() as $cache_path) { @mkdir((string)$cache_path->path, 0755, true); }