mirror of
https://github.com/netbirdio/plugins.git
synced 2026-05-22 18:44:07 -07:00
MVC, change __items to iterateItems(), closes https://github.com/opnsense/core/issues/2670
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -44,7 +44,7 @@ $wol = new Wol();
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($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;}'");?>
|
||||
<tr>
|
||||
<td><?= !empty((string)$wolent->descr) ? $wolent->descr : gettext('Unnamed entry') ?><br/><?= $wolent->mac ?></td>
|
||||
@@ -61,7 +61,7 @@ $wol = new Wol();
|
||||
</tr>
|
||||
<?php
|
||||
endforeach;
|
||||
if (count($wol->wolentry->__items) == 0):?>
|
||||
if (count($wol->wolentry->iterateItems()) == 0):?>
|
||||
<tr>
|
||||
<td colspan="4" ><?=gettext("No saved WoL addresses");?></td>
|
||||
</tr>
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user