Merge branch 'ent-7564-no-funciona-correctamente-buscador-politicas' into 'develop'

Fixed some errors and fixed issue finding policies

Closes pandora_enterprise#7564

See merge request artica/pandorafms!4149
This commit is contained in:
Daniel Rodriguez 2021-08-03 06:46:32 +00:00
commit 871f6102f1
2 changed files with 55 additions and 24 deletions

View File

@ -195,8 +195,10 @@ if ($searchAgents) {
t1.comentarios COLLATE utf8_general_ci LIKE '%%".$stringSearchSQL."%%' OR
t1.id_agente = $aux";
if (count($id) >= 2) {
for ($i = 1; $i < count($id); $i++) {
$idCount = count($id);
if ($idCount >= 2) {
for ($i = 1; $i < $idCount; $i++) {
$aux = $id[$i]['id_agent'];
$search_sql .= " OR t1.id_agente = $aux";
}

View File

@ -1,24 +1,39 @@
<?php
/**
* Data getter for policies searching
*
* @category Operation
* @package Pandora FMS
* @subpackage Community
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
* Please see http://pandorafms.org for full contribution list
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation for version 2.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ============================================================================
*/
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; version 2
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Get global data.
global $config;
enterprise_include_once('include/functions_policies.php');
$searchpolicies = (bool) check_acl($config['id_user'], 0, 'AW');
$searchpolicies = check_acl($config['id_user'], 0, 'AW');
if (!$searchpolicies) {
if ($searchpolicies === false) {
$totalPolicies = 0;
return;
}
@ -38,6 +53,7 @@ switch ($sortField) {
case 'id':
switch ($sort) {
case 'up':
default:
$selectpolicieIDUp = $selected;
$order = [
'field' => 'id',
@ -58,6 +74,7 @@ switch ($sortField) {
case 'name':
switch ($sort) {
case 'up':
default:
$selectNameUp = $selected;
$order = [
'field' => 'name',
@ -78,6 +95,7 @@ switch ($sortField) {
case 'description':
switch ($sort) {
case 'up':
default:
$selectId_groupUp = $selected;
$order = [
'field' => 'description',
@ -98,6 +116,7 @@ switch ($sortField) {
case 'last_contact':
switch ($sort) {
case 'up':
default:
$selectId_groupUp = $selected;
$order = [
'field' => 'last_connect',
@ -118,6 +137,7 @@ switch ($sortField) {
case 'id_group':
switch ($sort) {
case 'up':
default:
$selectId_groupUp = $selected;
$order = [
'field' => 'last_connect',
@ -138,6 +158,7 @@ switch ($sortField) {
case 'status':
switch ($sort) {
case 'up':
default:
$selectStatusUp = $selected;
$order = [
'field' => 'is_admin',
@ -174,11 +195,12 @@ switch ($sortField) {
break;
}
if ($searchpolicies) {
if ($searchpolicies === true) {
/*
We take the user groups to get policies that meet the requirements of the search
and which the user have permission on this groups
*/
$user_groups = users_get_groups($config['id_user'], 'AR', false);
$id_user_groups = array_keys($user_groups);
$id_user_groups_str = implode(',', $id_user_groups);
@ -186,7 +208,15 @@ if ($searchpolicies) {
$sql = "SELECT id, name, description, id_group, status
FROM tpolicies
WHERE name LIKE '$stringSearchSQL'
AND id_group IN ($id_user_groups_str)";
AND
(id_group IN ($id_user_groups_str)
OR 1 = (
SELECT is_admin
FROM tusuario
WHERE id_user = 'admin'
)
)
";
}
@ -194,11 +224,10 @@ if ($searchpolicies) {
$policies = db_process_sql($sql);
if ($policies !== false) {
$totalPolicies = count($policies);
if ($only_count) {
if ($only_count === true) {
unset($policies);
}
} else {