Merge branch 'ent-4099-8092-busqueda-general-politicas' into 'develop'

Ent 4099 8092 busqueda general politicas

See merge request artica/pandorafms!2479
This commit is contained in:
Daniel Rodriguez 2019-07-11 18:40:48 +02:00
commit f3060dd428
5 changed files with 327 additions and 22 deletions

View File

@ -26,6 +26,7 @@ if ($searchGraphs) {
$usergraphs_id = array_keys($usergraphs);
if (empty($usergraphs_id)) {
$totalGraphs = 0;
return;
}
@ -37,6 +38,7 @@ if ($searchGraphs) {
'id_graph',
'name',
'description',
];
$totalGraphs = (int) db_get_value_filter('COUNT(id_graph) AS count', 'tgraph', $filter);
@ -45,5 +47,7 @@ if ($searchGraphs) {
$filter['limit'] = $config['block_size'];
$filter['offset'] = (int) get_parameter('offset');
$graphs = db_get_all_rows_filter('tgraph', $filter, $columns);
} else {
$totalGraphs = 0;
}
}

View File

@ -20,6 +20,7 @@ $searchGraphs = check_acl($config['id_user'], 0, 'RR');
$searchMaps = check_acl($config['id_user'], 0, 'RR');
$searchReports = check_acl($config['id_user'], 0, 'RR');
$searchUsers = check_acl($config['id_user'], 0, 'UM');
$searchPolicies = check_acl($config['id_user'], 0, 'AW');
$searchHelps = true;
echo '<br><div style="margin:auto; width:90%; padding: 10px;">';
@ -44,8 +45,12 @@ $table->style[9] = 'font-weight: bold; text-align: center;';
$table->style[10] = 'font-weight: bold; text-align: center;';
$table->style[11] = 'font-weight: bold; text-align: center;';
$table->style[13] = 'font-weight: bold; text-align: center;';
$table->style[14] = 'font-weight: bold; text-align: center;';
$table->style[15] = 'font-weight: bold; text-align: center;';
$table->data[0][0] = html_print_image('images/agent.png', true, ['title' => __('Agents found')]);
$table->data[0][1] = "<a href='index.php?search_category=agents&keywords=".$config['search_keywords']."&head_search_keywords=Search'>".sprintf(__('%s Found'), $totalAgents).'</a>';
$table->data[0][2] = html_print_image('images/module.png', true, ['title' => __('Modules found')]);
@ -64,8 +69,10 @@ $table->data[0][10] = html_print_image('images/reporting.png', true, ['title' =>
$table->data[0][11] = "<a href='index.php?search_category=reports&keywords=".$config['search_keywords']."&head_search_keywords=Search'>".sprintf(__('%s Found'), $totalReports).'</a>';
$table->data[0][12] = html_print_image('images/visual_console_green.png', true, ['title' => __('Maps found')]);
$table->data[0][13] = "<a href='index.php?search_category=maps&keywords=".$config['search_keywords']."&head_search_keywords=Search'>".sprintf(__('%s Found'), $totalMaps).'</a>';
$table->data[0][14] = html_print_image('images/help.png', true, ['title' => __('Helps found')]);
$table->data[0][15] = "<a href='index.php?search_category=helps&keywords=".$config['search_keywords']."&head_search_keywords=Search'>".sprintf(__('%s Found'), $totalHelps).'</a>';
if (enterprise_installed()) {
$table->data[0][14] = html_print_image('images/policies.png', true, ['title' => __('Policies')]);
$table->data[0][15] = "<a href='index.php?search_category=policies&keywords=".$config['search_keywords']."&head_search_keywords=Search'>".sprintf(__('%s Found'), $totalPolicies).'</a>';
}
html_print_table($table);
@ -79,4 +86,5 @@ if ($searchAgents && $totalAgents > 0) {
).'</a>';
}
echo '</div>';

View File

@ -0,0 +1,200 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2011 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.
global $config;
enterprise_include_once('include/functions_policies.php');
$searchpolicies = check_acl($config['id'], 0, 'AW');
$selectpolicieIDUp = '';
$selectpolicieIDDown = '';
$selectNameUp = '';
$selectNameDown = '';
$selectDescriptionUp = '';
$selectDescriptionDown = '';
$selectId_groupUp = '';
$selectId_groupDown = '';
$selectStatusUp = '';
$selectStatusDown = '';
switch ($sortField) {
case 'id':
switch ($sort) {
case 'up':
$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':
$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':
$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':
$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':
$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':
$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;
}
if ($searchpolicies == 0) {
/*
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);
$sql = "SELECT id, name, description, id_group, status
FROM tpolicies
WHERE name LIKE '$stringSearchSQL'
AND id_group IN ($id_user_groups_str)";
}
$sql .= ' LIMIT '.$config['block_size'].' OFFSET '.get_parameter('offset', 0);
$policies = db_process_sql($sql);
if ($policies !== false) {
$totalPolicies = count($policies);
if ($only_count) {
unset($policies);
}
} else {
$totalPolicies = 0;
}

View File

@ -0,0 +1,90 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2011 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.
global $config;
enterprise_include_once('include/functions_policies.php');
require_once $config['homedir'].'/enterprise/include/functions_groups.php';
$searchpolicies = check_acl($config['id_user'], 0, 'AW');
if (!$policies || !$searchpolicies) {
echo "<br><div class='nf'>".__('Zero results found')."</div>\n";
} else {
$table->cellpadding = 4;
$table->cellspacing = 4;
$table->width = '98%';
$table->class = 'databox';
$table->align = [];
$table->align[4] = 'center';
$table->head = [];
// $table->head[0] = __('ID').' '.'<a href="index.php?search_category=policies&keywords='.$config['search_keywords'].'&head_search_keywords=abc&offset='.$offset.'&sort_field=id_policie&sort=up">'.html_print_image('images/sort_up.png', true, ['style' => $selectpolicieIDUp]).'</a>'.'<a href="index.php?search_category=policies&keywords='.$config['search_keywords'].'&head_search_keywords=abc&offset='.$offset.'&sort_field=id_policie&sort=down">'.html_print_image('images/sort_down.png', true, ['style' => $selectpolicieIDDown]).'</a>';
$table->head[0] = __('Name').' '.'<a href="index.php?search_category=policies&keywords='.$config['search_keywords'].'&head_search_keywords=abc&offset='.$offset.'&sort_field=name&sort=up">'.html_print_image('images/sort_up.png', true, ['style' => $selectNameUp]).'</a>'.'<a href="index.php?search_category=policies&keywords='.$config['search_keywords'].'&head_search_keywords=abc&offset='.$offset.'&sort_field=name&sort=down">'.html_print_image('images/sort_down.png', true, ['style' => $selectNameDown]).'</a>';
$table->head[1] = __('Description').' '.'<a href="index.php?search_category=policies&keywords='.$config['search_keywords'].'&head_search_keywords=abc&offset='.$offset.'&sort_field=description&sort=up">'.html_print_image('images/sort_up.png', true, ['style' => $selectDescriptionUp]).'</a>'.'<a href="index.php?search_category=policies&keywords='.$config['search_keywords'].'&head_search_keywords=abc&offset='.$offset.'&sort_field=description&sort=down">'.html_print_image('images/sort_down.png', true, ['style' => $selectDescriptionDown]).'</a>';
$table->head[2] = __('Id_group').' '.'<a href="index.php?search_category=policies&keywords='.$config['search_keywords'].'&head_search_keywords=abc&offset='.$offset.'&sort_field=last_contact&sort=up">'.html_print_image('images/sort_up.png', true, ['style' => $selectId_groupUp]).'</a>'.'<a href="index.php?search_category=policies&keywords='.$config['search_keywords'].'&head_search_keywords=abc&offset='.$offset.'&sort_field=last_contact&sort=down">'.html_print_image('images/sort_down.png', true, ['style' => $selectId_groupDown]).'</a>';
$table->head[3] = __('Status').' '.'<a href="index.php?search_category=policies&keywords='.$config['search_keywords'].'&head_search_keywords=abc&offset='.$offset.'&sort_field=status&sort=up">'.html_print_image('images/sort_up.png', true, ['style' => $selectStatusUp]).'</a>'.'<a href="index.php?search_category=policies&keywords='.$config['search_keywords'].'&head_search_keywords=abc&offset='.$offset.'&sort_field=status&sort=down">'.html_print_image('images/sort_down.png', true, ['style' => $selectstatusDown]).'</a>';
$table->data = [];
foreach ($policies as $policie) {
$policieIDCell = "<a href='?sec=gmodules&sec2=enterprise/godmode/policies/policies&id=".$policies['id']."'>".$policies['id'].'</a>';
switch ($policie['status']) {
case POLICY_UPDATED:
$status = html_print_image(
'images/policies_ok.png',
true,
['title' => __('Policy updated')]
);
break;
case POLICY_PENDING_DATABASE:
$status = html_print_image(
'images/policies_error_db.png',
true,
['title' => __('Pending update policy only database')]
);
break;
case POLICY_PENDING_ALL:
$status = html_print_image(
'images/policies_error.png',
true,
['title' => __('Pending update policy')]
);
break;
}
$url = $config['homeurl'].'/index.php?'.'sec=gmodules&'.'sec2=enterprise/godmode/policies/policies&id='.$policie['id'].'';
array_push(
$table->data,
[
// $policie['id'],
'<a href= '.$url.'>'.$policie['name'].'',
$policie['description'],
ui_print_group_icon($policie['id_group'], true),
$status,
]
);
}
$totalPolicies = count($policies);
echo '<br />';
html_print_table($table);
unset($table);
ui_pagination($totalPolicies);
}

View File

@ -18,7 +18,7 @@ require_once $config['homedir'].'/include/functions_reporting.php';
enterprise_include('operation/reporting/custom_reporting.php');
$searchAgents = $searchAlerts = $searchModules = check_acl($config['id_user'], 0, 'AR');
$searchUsers = check_acl($config['id_user'], 0, 'UM');
$searchUsers = $searchPolicies = check_acl($config['id_user'], 0, 'AW');
$searchMaps = $searchReports = $searchGraphs = check_acl($config['id_user'], 0, 'IR');
$searchMain = true;
$searchHelps = true;
@ -43,6 +43,7 @@ if ($config['search_category'] == 'all') {
// INI SECURITY ACL
if ((!$searchAgents && !$searchUsers && !$searchMaps)
|| (!$searchUsers && $searchTab == 'users')
|| (!$searchPolicies && $searchTab == 'policies')
|| (!$searchAgents && ($searchTab == 'agents' || $searchTab == 'alerts'))
|| (!$searchGraphs && ($searchTab == 'graphs' || $searchTab == 'maps' || $searchTab == 'reports'))
) {
@ -161,17 +162,17 @@ if ($searchModules) {
$modules_tab = '';
}
if ($searchHelps) {
$helps_tab = [
'text' => "<a href='index.php?search_category=helps&keywords=".$config['search_keywords']."&head_search_keywords=Search'>".html_print_image(
'images/help_w.png',
if ($searchPolicies) {
$policies_tab = [
'text' => "<a href='index.php?search_category=policies&keywords=".$config['search_keywords']."&head_search_keywords=Search'>".html_print_image(
'images/policies.png',
true,
['title' => __('Helps')]
['title' => __('Policies')]
).'</a>',
'active' => $searchTab == 'helps',
'active' => $searchTab == 'policies',
];
} else {
$helps_tab = '';
$policies_tab = '';
}
$onheader = [
@ -183,7 +184,7 @@ $onheader = [
'graphs' => $graphs_tab,
'reports' => $reports_tab,
'maps' => $maps_tab,
'helps' => $helps_tab,
'policies' => $policies_tab,
];
ui_print_page_header(
@ -212,6 +213,7 @@ switch ($searchTab) {
include_once 'search_maps.getdata.php';
include_once 'search_modules.getdata.php';
include_once 'search_helps.getdata.php';
include_once 'search_policies.getdata.php';
include_once 'search_main.php';
break;
@ -251,8 +253,9 @@ switch ($searchTab) {
include_once 'search_modules.php';
break;
case 'helps':
include_once 'search_helps.getdata.php';
include_once 'search_helps.php';
case 'policies':
include_once 'search_policies.getdata.php';
include_once 'search_policies.php';
break;
}