2019-06-04 11:44:11 +02:00
|
|
|
<?php
|
2021-05-24 11:01:50 +02:00
|
|
|
/**
|
|
|
|
* Data getter for policies searching
|
|
|
|
*
|
|
|
|
* @category Operation
|
|
|
|
* @package Pandora FMS
|
|
|
|
* @subpackage Community
|
|
|
|
* @version 1.0.0
|
|
|
|
* @license See below
|
|
|
|
*
|
|
|
|
* ______ ___ _______ _______ ________
|
|
|
|
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
|
|
|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
|
|
|
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
|
|
|
*
|
|
|
|
* ============================================================================
|
2023-06-08 11:53:13 +02:00
|
|
|
* Copyright (c) 2005-2023 Pandora FMS
|
2021-05-24 11:01:50 +02:00
|
|
|
* 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.
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Get global data.
|
2019-06-04 11:44:11 +02:00
|
|
|
global $config;
|
|
|
|
|
2019-06-04 17:05:17 +02:00
|
|
|
enterprise_include_once('include/functions_policies.php');
|
2019-06-04 11:44:11 +02:00
|
|
|
|
2021-05-24 11:01:50 +02:00
|
|
|
$searchpolicies = (bool) check_acl($config['id_user'], 0, 'AW');
|
2019-06-04 11:44:11 +02:00
|
|
|
|
2021-05-24 11:01:50 +02:00
|
|
|
if ($searchpolicies === false) {
|
2019-10-02 11:27:52 +02:00
|
|
|
$totalPolicies = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-04 11:44:11 +02:00
|
|
|
$selectpolicieIDUp = '';
|
|
|
|
$selectpolicieIDDown = '';
|
|
|
|
$selectNameUp = '';
|
|
|
|
$selectNameDown = '';
|
|
|
|
$selectDescriptionUp = '';
|
|
|
|
$selectDescriptionDown = '';
|
|
|
|
$selectId_groupUp = '';
|
|
|
|
$selectId_groupDown = '';
|
|
|
|
$selectStatusUp = '';
|
|
|
|
$selectStatusDown = '';
|
|
|
|
|
|
|
|
switch ($sortField) {
|
|
|
|
case 'id':
|
|
|
|
switch ($sort) {
|
|
|
|
case 'up':
|
2021-05-24 11:01:50 +02:00
|
|
|
default:
|
2019-06-04 11:44:11 +02:00
|
|
|
$selectpolicieIDUp = $selected;
|
|
|
|
$order = [
|
|
|
|
'field' => 'id',
|
|
|
|
'order' => 'ASC',
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'down':
|
|
|
|
$selectpolicieIDDown = $selected;
|
|
|
|
$order = [
|
|
|
|
'field' => 'id',
|
|
|
|
'order' => 'DESC',
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'name':
|
|
|
|
switch ($sort) {
|
|
|
|
case 'up':
|
2021-05-24 11:01:50 +02:00
|
|
|
default:
|
2019-06-04 11:44:11 +02:00
|
|
|
$selectNameUp = $selected;
|
|
|
|
$order = [
|
|
|
|
'field' => 'name',
|
|
|
|
'order' => 'ASC',
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'down':
|
|
|
|
$selectNameDown = $selected;
|
|
|
|
$order = [
|
|
|
|
'field' => 'name',
|
|
|
|
'order' => 'DESC',
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'description':
|
|
|
|
switch ($sort) {
|
|
|
|
case 'up':
|
2021-05-24 11:01:50 +02:00
|
|
|
default:
|
2019-06-04 11:44:11 +02:00
|
|
|
$selectId_groupUp = $selected;
|
|
|
|
$order = [
|
|
|
|
'field' => 'description',
|
|
|
|
'order' => 'ASC',
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'down':
|
|
|
|
$selectDescriptionDown = $selected;
|
|
|
|
$order = [
|
|
|
|
'field' => 'description',
|
|
|
|
'order' => 'DESC',
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'last_contact':
|
|
|
|
switch ($sort) {
|
|
|
|
case 'up':
|
2021-05-24 11:01:50 +02:00
|
|
|
default:
|
2019-06-04 11:44:11 +02:00
|
|
|
$selectId_groupUp = $selected;
|
|
|
|
$order = [
|
|
|
|
'field' => 'last_connect',
|
|
|
|
'order' => 'ASC',
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'down':
|
|
|
|
$selectId_groupDown = $selected;
|
|
|
|
$order = [
|
|
|
|
'field' => 'last_connect',
|
|
|
|
'order' => 'DESC',
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'id_group':
|
|
|
|
switch ($sort) {
|
|
|
|
case 'up':
|
2021-05-24 11:01:50 +02:00
|
|
|
default:
|
2019-06-04 11:44:11 +02:00
|
|
|
$selectId_groupUp = $selected;
|
|
|
|
$order = [
|
|
|
|
'field' => 'last_connect',
|
|
|
|
'order' => 'ASC',
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'down':
|
|
|
|
$selectId_groupDown = $selected;
|
|
|
|
$order = [
|
|
|
|
'field' => 'last_connect',
|
|
|
|
'order' => 'DESC',
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'status':
|
|
|
|
switch ($sort) {
|
|
|
|
case 'up':
|
2021-05-24 11:01:50 +02:00
|
|
|
default:
|
2019-06-04 11:44:11 +02:00
|
|
|
$selectStatusUp = $selected;
|
|
|
|
$order = [
|
|
|
|
'field' => 'is_admin',
|
|
|
|
'order' => 'ASC',
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'down':
|
|
|
|
$selectStatusDown = $selected;
|
|
|
|
$order = [
|
|
|
|
'field' => 'is_admin',
|
|
|
|
'order' => 'DESC',
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$selectpolicieIDUp = $selected;
|
|
|
|
$selectpolicieIDDown = '';
|
|
|
|
$selectNameUp = '';
|
|
|
|
$selectNameDown = '';
|
|
|
|
$selectDescriptionUp = '';
|
|
|
|
$selectDescriptionDown = '';
|
|
|
|
$selectId_groupUp = '';
|
|
|
|
$selectId_groupDown = '';
|
|
|
|
$selectStatusUp = '';
|
|
|
|
$selectStatusDown = '';
|
|
|
|
|
|
|
|
$order = [
|
|
|
|
'field' => 'id',
|
|
|
|
'order' => 'ASC',
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-05-24 11:01:50 +02:00
|
|
|
if ($searchpolicies === true) {
|
2019-06-12 10:13:37 +02:00
|
|
|
/*
|
|
|
|
We take the user groups to get policies that meet the requirements of the search
|
|
|
|
and which the user have permission on this groups
|
|
|
|
*/
|
2021-05-24 11:01:50 +02:00
|
|
|
|
2023-05-24 11:52:59 +02:00
|
|
|
$user_groups = users_get_groups($config['id_user'], 'AR', true);
|
2019-06-11 16:23:42 +02:00
|
|
|
$id_user_groups = array_keys($user_groups);
|
|
|
|
$id_user_groups_str = implode(',', $id_user_groups);
|
|
|
|
|
2021-05-24 11:01:50 +02:00
|
|
|
$sql = "SELECT id, name, description, id_group, status
|
|
|
|
FROM tpolicies
|
|
|
|
WHERE name LIKE '$stringSearchSQL'
|
2021-11-04 18:07:39 +01:00
|
|
|
AND id_group IN ($id_user_groups_str)
|
2021-05-24 11:01:50 +02:00
|
|
|
";
|
2019-06-04 11:44:11 +02:00
|
|
|
}
|
|
|
|
|
2019-06-04 11:52:56 +02:00
|
|
|
|
2021-05-24 11:01:50 +02:00
|
|
|
$sql .= ' LIMIT '.$config['block_size'].' OFFSET '.get_parameter('offset', 0);
|
2019-06-04 11:44:11 +02:00
|
|
|
|
|
|
|
$policies = db_process_sql($sql);
|
|
|
|
|
|
|
|
if ($policies !== false) {
|
2019-06-11 16:23:42 +02:00
|
|
|
$totalPolicies = count($policies);
|
|
|
|
|
2021-05-24 11:01:50 +02:00
|
|
|
if ($only_count === true) {
|
2019-06-04 11:44:11 +02:00
|
|
|
unset($policies);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$totalPolicies = 0;
|
|
|
|
}
|