diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index f8a92e0f6e..e78a5d6ac4 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,14 @@ +2010-08-31 Sergio Martin + + * operation/search_agents.php + operation/search_graphs.php + operation/search_alerts.php + operation/search_reports.php + operation/search_maps.php + operation/search_results.php + operation/search_users.php: Restructured and fixed + ACLs in the global search for bug 3053592 + 2010-08-30 Sergio Martin * operation/agentes/alerts_status.php: Fixed the diff --git a/pandora_console/operation/search_agents.php b/pandora_console/operation/search_agents.php new file mode 100755 index 0000000000..e4dd49624b --- /dev/null +++ b/pandora_console/operation/search_agents.php @@ -0,0 +1,225 @@ + 'nombre', 'order' => 'ASC'); + break; + case 'down': + $selectNameDown = $selected; + $order = array('field' => 'nombre', 'order' => 'DESC'); + break; + } + break; + case 'os': + switch ($sort) { + case 'up': + $selectOsUp = $selected; + $order = array('field' => 'id_os', 'order' => 'ASC'); + break; + case 'down': + $selectOsDown = $selected; + $order = array('field' => 'id_os', 'order' => 'DESC'); + break; + } + break; + case 'interval': + switch ($sort) { + case 'up': + $selectIntervalUp = $selected; + $order = array('field' => 'intervalo', 'order' => 'ASC'); + break; + case 'down': + $selectIntervalDown = $selected; + $order = array('field' => 'intervalo', 'order' => 'DESC'); + break; + } + break; + case 'group': + switch ($sort) { + case 'up': + $selectGroupUp = $selected; + $order = array('field' => 'id_grupo', 'order' => 'ASC'); + break; + case 'down': + $selectGroupDown = $selected; + $order = array('field' => 'id_grupo', 'order' => 'DESC'); + break; + } + break; + case 'last_contact': + switch ($sort) { + case 'up': + $selectLastContactUp = $selected; + $order = array('field' => 'ultimo_contacto', 'order' => 'ASC'); + break; + case 'down': + $selectLastContactDown = $selected; + $order = array('field' => 'ultimo_contacto', 'order' => 'DESC'); + break; + } + break; + default: + $selectNameUp = $selected; + $selectNameDown = ''; + $selectOsUp = ''; + $selectOsDown = ''; + $selectIntervalUp = ''; + $selectIntervalDown = ''; + $selectGroupUp = ''; + $selectGroupDown = ''; + $selectLastContactUp = ''; + $selectLastContactDown = ''; + $order = array('field' => 'nombre', 'order' => 'ASC'); + break; +} + +$agents = false; +if ($searchAgents) { + $sql = "SELECT id_agente, tagente.nombre, tagente.id_os, tagente.intervalo, tagente.id_grupo, tagente.disabled + FROM tagente + INNER JOIN tgrupo + ON tgrupo.id_grupo = tagente.id_grupo + WHERE tagente.nombre COLLATE utf8_general_ci LIKE '%" . $stringSearchSQL . "%' OR + tgrupo.nombre LIKE '%" . $stringSearchSQL . "%' + ORDER BY " . $order['field'] . " " . $order['order'] . " + LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0); + $agents = process_sql($sql); + + if($agents !== false) { + // ACLs check + $agents_id = array(); + foreach($agents as $key => $agent){ + if (!give_acl ($config["id_user"], $agent["id_grupo"], "AR")) { + unset($agents[$key]); + } else { + $agents_id[] = $agent["id_agente"]; + } + } + + if(!$agents_id) { + $agent_condition = ""; + }else { + // Condition with the visible agents + $agent_condition = " AND id_agente IN (".implode(',',$agents_id).")"; + } + + $sql = "SELECT count(id_agente) AS count + FROM tagente + INNER JOIN tgrupo + ON tgrupo.id_grupo = tagente.id_grupo + WHERE (tagente.nombre COLLATE utf8_general_ci LIKE '%" . $stringSearchSQL . "%' OR + tgrupo.nombre LIKE '%" . $stringSearchSQL . "%')".$agent_condition; + $totalAgents = get_db_row_sql($sql); + + $totalAgents = $totalAgents['count']; + } +} + + +if (!$agents) { + echo "
" . __("Zero results found") . "
\n"; +} +else { + $table->cellpadding = 4; + $table->cellspacing = 4; + $table->width = "98%"; + $table->class = "databox"; + + $table->head = array (); + $table->head[0] = __('Agent') . ' ' . + '' . + ''; + $table->head[1] = __('OS'). ' ' . + '' . + ''; + $table->head[2] = __('Interval'). ' ' . + '' . + ''; + $table->head[3] = __('Group'). ' ' . + '' . + ''; + $table->head[4] = __('Modules'); + $table->head[5] = __('Status'); + $table->head[6] = __('Alerts'); + $table->head[7] = __('Last contact'). ' ' . + '' . + ''; + + $table->align = array (); + $table->align[0] = "left"; + $table->align[1] = "center"; + $table->align[2] = "center"; + $table->align[3] = "center"; + $table->align[4] = "center"; + $table->align[5] = "center"; + $table->align[6] = "center"; + $table->align[7] = "right"; + + $table->data = array (); + + foreach ($agents as $agent) { + $agent_info = get_agent_module_info ($agent["id_agente"]); + + $modulesCell = ''. $agent_info["modules"] . ''; + if ($agent_info["monitor_normal"] > 0) + $modulesCell .= ' : '.$agent_info["monitor_normal"].''; + if ($agent_info["monitor_warning"] > 0) + $modulesCell .= ' : '.$agent_info["monitor_warning"].''; + if ($agent_info["monitor_critical"] > 0) + $modulesCell .= ' : '.$agent_info["monitor_critical"].''; + if ($agent_info["monitor_unknown"] > 0) + $modulesCell .= ' : '.$agent_info["monitor_unknown"].''; + + if ($agent['disabled']) { + $cellName = "" . print_agent_name ($agent["id_agente"], true, "upper") .print_help_tip(__('Disabled'), true) . ""; + } + else { + $cellName = print_agent_name ($agent["id_agente"], true, "upper"); + } + + array_push($table->data, array( + $cellName, + print_os_icon ($agent["id_os"], false, true), + $agent['intervalo'], + print_group_icon ($agent["id_grupo"], true), + $modulesCell, + $agent_info["status_img"], + $agent_info["alert_img"], + print_timestamp ($agent_info["last_contact"], true))); + } + + echo "
";pagination ($totalAgents); + print_table ($table); unset($table); + pagination ($totalAgents); +} +?> diff --git a/pandora_console/operation/search_alerts.php b/pandora_console/operation/search_alerts.php new file mode 100755 index 0000000000..09f15d229c --- /dev/null +++ b/pandora_console/operation/search_alerts.php @@ -0,0 +1,220 @@ + 'disabled', 'order' => 'ASC'); + break; + case 'down': + $selectAgentDown = $selected; + $order = array('field' => 'disabled', 'order' => 'DESC'); + break; + } + break; + case 'agent': + switch ($sort) { + case 'up': + $selectAgentUp = $selected; + $order = array('field' => 'agent_name', 'order' => 'ASC'); + break; + case 'down': + $selectAgentDown = $selected; + $order = array('field' => 'agent_name', 'order' => 'DESC'); + break; + } + break; + case 'module': + switch ($sort) { + case 'up': + $selectModuleUp = $selected; + $order = array('field' => 'module_name', 'order' => 'ASC'); + break; + case 'down': + $selectModuleDown = $selected; + $order = array('field' => 'module_name', 'order' => 'DESC'); + break; + } + break; + case 'template': + switch ($sort) { + case 'up': + $selectTemplateUp = $selected; + $order = array('field' => 'template_name', 'order' => 'ASC'); + break; + case 'down': + $selectTemplateDown = $selected; + $order = array('field' => 'template_name', 'order' => 'DESC'); + break; + } + break; + default: + $selectDisabledUp = ''; + $selectDisabledDown = ''; + $selectAgentUp = $selected; + $selectAgentDown = ''; + $selectModuleUp = ''; + $selectModuleDown = ''; + $selectTemplateUp = ''; + $selectTemplateDown = ''; + + $order = array('field' => 'agent_name', 'order' => 'ASC'); + break; +} + +$alerts = false; + +if($searchAlerts) { + $agents = array_keys(get_group_agents(array_keys(get_user_groups($config["id_user"], 'AR', false)))); + + /*$whereAlerts = ' AND (t2.nombre LIKE "%'.$stringSearchSQL.'%" OR t3.nombre LIKE "%'.$stringSearchSQL.'%" + OR t4.name LIKE "%'.$stringSearchSQL.'%") ';*/ + + $whereAlerts = false; + $alertsraw = get_agent_alerts_simple ($agents, "all_enabled", array('offset' => get_parameter ('offset',0), 'limit' => $config['block_size'], 'order' => $order['field'] . " " . $order['order']), $whereAlerts); + + $stringSearchPHP = substr($stringSearchSQL,1,strlen($stringSearchSQL)-2); + + $alerts = array(); + foreach($alertsraw as $key => $alert){ + $finded = false; + $alerts[$key]['disabled'] = $alert['disabled']; + $alerts[$key]['id_agente'] = get_agentmodule_agent($alert['id_agent_module']); + $alerts[$key]['agent_name'] = $alert['agent_name']; + $alerts[$key]['module_name'] = $alert['agent_module_name']; + $alerts[$key]['template_name'] = $alert['template_name']; + $actions = get_alert_agent_module_actions($alert['id']); + + // Check substring into agent, module, template and action names + if(strpos($alert['agent_name'], $stringSearchPHP) !== false) { + $finded = true; + } + + if(!$finded) { + if(strpos($alert['agent_module_name'], $stringSearchPHP) !== false) { + $finded = true; + } + } + + if(!$finded) { + if(strpos($alert['template_name'], $stringSearchPHP) !== false) { + $finded = true; + } + } + + foreach($actions as $action) { + $actions_name[] = $action['name']; + + if(!$finded) { + if(strpos($action['name'], $stringSearchPHP) !== false) { + $finded = true; + } + } + } + + $alerts[$key]['actions'] = implode(',',$actions_name); + + if(!$finded) { + unset($alerts[$key]); + } + } + + $totalAlerts = count($alerts); +} + +if ($alerts === false || $totalAlerts == 0) { + echo "
" . __("Zero results found") . "
\n"; +} +else { + $table->cellpadding = 4; + $table->cellspacing = 4; + $table->width = "98%"; + $table->class = "databox"; + + $table->head = array (); + $table->head[0] = '' . ' ' . + '' . + ''; + $table->head[1] = __('Agent') . ' ' . + '' . + ''; + $table->head[2] = __('Module') . ' ' . + '' . + ''; + $table->head[3] = __('Template') . ' ' . + '' . + ''; + $table->head[4] = __('Action'); + + $table->align = array (); + $table->align[0] = "center"; + $table->align[1] = "left"; + $table->align[2] = "left"; + $table->align[3] = "left"; + $table->align[4] = "left"; + + $table->valign = array (); + $table->valign[0] = "top"; + $table->valign[1] = "top"; + $table->valign[2] = "top"; + $table->valign[3] = "top"; + $table->valign[4] = "top"; + + $table->data = array (); + foreach ($alerts as $alert) { + if ($alert['disabled']) + $disabledCell = print_image ('images/lightbulb_off.png', true, array('title' => 'disable', 'alt' => 'disable')); + else + $disabledCell = print_image ('images/lightbulb.png', true, array('alt' => 'enable', 'title' => 'enable')); + + $actionCell = ''; + if (strlen($alert["actions"]) > 0) { + $arrayActions = explode(',', $alert["actions"]); + $actionCell = ''; + } + + + array_push($table->data, array( + $disabledCell, + print_agent_name ($alert["id_agente"], true, "upper"), + $alert["module_name"], + $alert["template_name"],$actionCell + )); + } + + echo "
";pagination ($totalAlerts); + print_table ($table); unset($table); + pagination ($totalAlerts); +} +?> diff --git a/pandora_console/operation/search_graphs.php b/pandora_console/operation/search_graphs.php new file mode 100755 index 0000000000..ca763ec1d6 --- /dev/null +++ b/pandora_console/operation/search_graphs.php @@ -0,0 +1,84 @@ +1"; + }else { + $graphs_condition = " AND id_graph IN (".implode(',',$usergraphs_id).")"; + } + + $sql = "SELECT id_graph, name, description FROM tgraph WHERE (name LIKE '%" . $stringSearchSQL . "%' OR description LIKE '%" . $stringSearchSQL . "%')".$graphs_condition. + " LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0); + $graphs = process_sql($sql); + + if($graphs !== false) { + $sql = "SELECT COUNT(id_graph) AS count FROM tgraph WHERE name LIKE '%" . $stringSearchSQL . "%' OR description LIKE '%" . $stringSearchSQL . "%'"; + $totalGraphs = get_db_row_sql($sql); + $totalGraphs = $totalGraphs['count']; + } +} + +if ($graphs === false) { + echo "
" . __("Zero results found") . "
\n"; +} +else { + $table->cellpadding = 4; + $table->cellspacing = 4; + $table->width = "98%"; + $table->class = "databox"; + + $table->head = array (); + $table->head[0] = __('Graph name'); + $table->head[1] = __('Description'); + + $table->data = array (); + foreach ($graphs as $graph) { + array_push($table->data, array( + "" . $graph['name'] . "", + $graph['description'] + )); + } + + echo "
";pagination ($totalGraphs); + print_table ($table); unset($table); + pagination ($totalGraphs); +} + +switch ($searchTab) { + case 'agents': + require_once('search_agents.php'); + break; + case 'users': + require_once('search_users.php'); + break; + case 'alerts': + require_once('search_alerts.php'); + break; +} +?> diff --git a/pandora_console/operation/search_maps.php b/pandora_console/operation/search_maps.php new file mode 100755 index 0000000000..b1338f6f7e --- /dev/null +++ b/pandora_console/operation/search_maps.php @@ -0,0 +1,82 @@ + $map) { + if (!give_acl ($config["id_user"], $map["id_group"], "AR")) { + unset($maps[$key]); + }else { + $maps_id[] = $map['id']; + } + } + + if(!$maps_id) { + $maps_condition = ""; + }else { + // Condition with the visible agents + $maps_condition = " AND id IN (\"".implode('","',$maps_id)."\")"; + } + + $sql = "SELECT COUNT(id) AS count FROM tlayout WHERE name LIKE '%" . $stringSearchSQL . "%'".$maps_condition; + $totalMaps = get_db_row_sql($sql); + $totalMaps = $totalMaps['count']; + } +} + +if ($maps === false) { + echo "
" . __("Zero results found") . "
\n"; +} +else { + $table->cellpadding = 4; + $table->cellspacing = 4; + $table->width = "98%"; + $table->class = "databox"; + + $table->head = array (); + $table->head[0] = __('Name'); + $table->head[1] = __('Group'); + $table->head[2] = __('Elements'); + + $table->align = array (); + $table->align[1] = "center"; + $table->align[2] = "center"; + + $table->data = array (); + foreach ($maps as $map) { + array_push($table->data, array( + "" . $map['name'] . "", + print_group_icon ($layout["id_group"], true) . " " . get_group_name ($layout["id_group"]), + $map['count'] + )); + } + + echo "
";pagination ($totalMaps); + print_table ($table); unset($table); + pagination ($totalMaps); +} +?> diff --git a/pandora_console/operation/search_reports.php b/pandora_console/operation/search_reports.php new file mode 100755 index 0000000000..322b032cdb --- /dev/null +++ b/pandora_console/operation/search_reports.php @@ -0,0 +1,97 @@ +1"; +}else { + $reports_condition = " AND id_report IN (".implode(',',$userreports_id).")"; +} + +$reports = false; + +if($searchReports) { + $sql = "SELECT id_report, name, description FROM treport WHERE name LIKE '%" . $stringSearchSQL . "%'".$reports_condition. + " LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0); + $reports = process_sql($sql); + + $sql = "SELECT COUNT(id_report) AS count FROM treport WHERE name LIKE '%" . $stringSearchSQL . "%'"; + $totalReports = get_db_row_sql($sql); + $totalReports = $totalReports['count']; +} + +if ($reports === false) { + echo "
" . __("Zero results found") . "
\n"; +} +else { + $table->cellpadding = 4; + $table->cellspacing = 4; + $table->width = "98%"; + $table->class = "databox"; + + $table->head = array (); + $table->head[0] = __('Report name'); + $table->head[1] = __('Description'); + $table->head[2] = __('HTML'); + $table->head[3] = __('XML'); + enterprise_hook ('load_custom_reporting_1'); + + $table->align = array (); + $table->align[2] = "center"; + $table->align[3] = "center"; + $table->align[4] = "center"; + + $table->data = array (); + foreach ($reports as $report) { + if($linkReport) { + $reportstring = "" . $report['name'] . ""; + } else { + $reportstring = $report['name']; + } + $data = array( + $reportstring, + $report['description'], + '', + '' + ); + enterprise_hook ('load_custom_reporting_2'); + + array_push($table->data, $data); + } + + echo "
";pagination ($totalReports); + print_table ($table); unset($table); + pagination ($totalReports); +} +?> diff --git a/pandora_console/operation/search_results.php b/pandora_console/operation/search_results.php index ae8f779e1a..74cc0a665e 100644 --- a/pandora_console/operation/search_results.php +++ b/pandora_console/operation/search_results.php @@ -2,7 +2,7 @@ // Pandora FMS - http://pandorafms.com // ================================================== -// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas +// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -18,24 +18,29 @@ require_once ("include/functions_reporting.php"); // Load enterprise extensions enterprise_include ('operation/reporting/custom_reporting.php'); -$searchGraphs = $searchAgents = (check_acl ($config['id_user'], 0, "AW") || check_acl ($config['id_user'], 0, "AR")); -$linkEditUser = check_acl ($config['id_user'], 0, "UM"); -$searchMaps = give_acl ($config["id_user"], 0, "AR"); +$searchAgents = $searchAlerts = check_acl($config['id_user'], 0, "AR"); +$searchUsers = check_acl($config['id_user'], 0, "UM"); +$searchMaps = $searchReports = $searchGraphs = check_acl($config["id_user"], 0, "IR"); $arrayKeywords = explode(' ', $config['search_keywords']); $temp = array(); foreach($arrayKeywords as $keyword) - array_push($temp, "%" . $keyword . "%"); + array_push($temp, "%" . safe_input($keyword) . "%"); $stringSearchSQL = implode(" ",$temp); -if ($config['search_category'] == "all") $searchTab = "agents"; -else $searchTab = $config['search_category']; +if ($config['search_category'] == "all") + $searchTab = "agents"; +else + $searchTab = $config['search_category']; //INI SECURITY ACL -if ((!$searchAgents) && ($searchTab == 'agents')) $searchTab = "users"; - -if ((!$searchGraphs) && ($searchTab == 'graphs')) $searchTab = "users"; -if ((!$searchMaps) && ($searchTab == 'maps')) $searchTab = "users"; +if((!$searchAgents && !$searchUsers && !$searchMaps) || + (!$searchUsers && $searchTab == 'users') || + (!$searchAgents && ($searchTab == 'agents' || $searchTab == 'alerts')) || + (!$searchGraphs && ($searchTab == 'graphs' || $searchTab == 'maps' || $searchTab == 'reports'))){ + + $searchTab = ""; +} //END SECURITY ACL $offset = get_parameter ('offset',0); @@ -44,785 +49,73 @@ $order = null; $sortField = get_parameter('sort_field'); $sort = get_parameter('sort', 'none'); $selected = 'border: 1px solid black;'; + +if($searchAgents) { + $agents_tab = array('text' => "" + . print_image ("images/bricks.png", true, array ("title" => __('Agents'))) . "", 'active' => $searchTab == "agents"); +}else { + $agents_tab = ''; +} + +if($searchUsers) { + $users_tab = array('text' => "" + . print_image ("images/group.png", true, array ("title" => __('Users'))) . "", 'active' => $searchTab == "users"); +}else { + $users_tab = ''; +} + +if($searchAlerts) { + $alerts_tab = array('text' => "" + . print_image ("images/god2.png", true, array ("title" => __('Alerts'))) . "", 'active' => $searchTab == "alerts"); +}else { + $alerts_tab = ''; +} + +if($searchGraphs) { + $graphs_tab = array('text' => "" + . print_image ("images/chart_curve.png", true, array ("title" => __('Graphs'))) . "", 'active' => $searchTab == "graphs"); +}else { + $graphs_tab = ''; +} + +if($searchReports) { + $reports_tab = array('text' => "" + . print_image ("images/reporting.png", true, array ("title" => __('Reports'))) . "", 'active' => $searchTab == "reports"); +}else { + $reports_tab = ''; +} + +if($searchMaps) { + $maps_tab = array('text' => "" + . print_image ("images/camera.png", true, array ("title" => __('Maps'))) . "", 'active' => $searchTab == "maps"); +}else { + $maps_tab = ''; +} + +$onheader = array('agents' => $agents_tab, 'users' => $users_tab, + 'alerts' => $alerts_tab, 'graphs' => $graphs_tab, + 'reports' => $reports_tab, 'maps' => $maps_tab); + +print_page_header (__("Search").": \"".$config['search_keywords']."\"", "images/zoom.png", false, "", false, $onheader); + switch ($searchTab) { case 'agents': - $selectNameUp = ''; - $selectNameDown = ''; - $selectOsUp = ''; - $selectOsDown = ''; - $selectIntervalUp = ''; - $selectIntervalDown = ''; - $selectGroupUp = ''; - $selectGroupDown = ''; - $selectLastContactUp = ''; - $selectLastContactDown = ''; - - switch ($sortField) { - case 'name': - switch ($sort) { - case 'up': - $selectNameUp = $selected; - $order = array('field' => 'nombre', 'order' => 'ASC'); - break; - case 'down': - $selectNameDown = $selected; - $order = array('field' => 'nombre', 'order' => 'DESC'); - break; - } - break; - case 'os': - switch ($sort) { - case 'up': - $selectOsUp = $selected; - $order = array('field' => 'id_os', 'order' => 'ASC'); - break; - case 'down': - $selectOsDown = $selected; - $order = array('field' => 'id_os', 'order' => 'DESC'); - break; - } - break; - case 'interval': - switch ($sort) { - case 'up': - $selectIntervalUp = $selected; - $order = array('field' => 'intervalo', 'order' => 'ASC'); - break; - case 'down': - $selectIntervalDown = $selected; - $order = array('field' => 'intervalo', 'order' => 'DESC'); - break; - } - break; - case 'group': - switch ($sort) { - case 'up': - $selectGroupUp = $selected; - $order = array('field' => 'id_grupo', 'order' => 'ASC'); - break; - case 'down': - $selectGroupDown = $selected; - $order = array('field' => 'id_grupo', 'order' => 'DESC'); - break; - } - break; - case 'last_contact': - switch ($sort) { - case 'up': - $selectLastContactUp = $selected; - $order = array('field' => 'ultimo_contacto', 'order' => 'ASC'); - break; - case 'down': - $selectLastContactDown = $selected; - $order = array('field' => 'ultimo_contacto', 'order' => 'DESC'); - break; - } - break; - default: - $selectNameUp = $selected; - $selectNameDown = ''; - $selectOsUp = ''; - $selectOsDown = ''; - $selectIntervalUp = ''; - $selectIntervalDown = ''; - $selectGroupUp = ''; - $selectGroupDown = ''; - $selectLastContactUp = ''; - $selectLastContactDown = ''; - $order = array('field' => 'nombre', 'order' => 'ASC'); - break; - } + require_once('search_agents.php'); break; case 'users': - $selectUserIDUp = ''; - $selectUserIDDown = ''; - $selectNameUp = ''; - $selectNameDown = ''; - $selectEmailUp = ''; - $selectEmailDown = ''; - $selectLastContactUp = ''; - $selectLastContactDown = ''; - $selectProfileUp = ''; - $selectProfileDown = ''; - - switch ($sortField) { - case 'id_user': - switch ($sort) { - case 'up': - $selectUserIDUp = $selected; - $order = array('field' => 'id_user', 'order' => 'ASC'); - break; - case 'down': - $selectUserIDDown = $selected; - $order = array('field' => 'id_user', 'order' => 'DESC'); - break; - } - break; - case 'name': - switch ($sort) { - case 'up': - $selectNameUp = $selected; - $order = array('field' => 'fullname', 'order' => 'ASC'); - break; - case 'down': - $selectNameDown = $selected; - $order = array('field' => 'fullname', 'order' => 'DESC'); - break; - } - break; - case 'email': - switch ($sort) { - case 'up': - $selectLastContactUp = $selected; - $order = array('field' => 'email', 'order' => 'ASC'); - break; - case 'down': - $selectEmailDown = $selected; - $order = array('field' => 'email', 'order' => 'DESC'); - break; - } - break; - case 'last_contact': - switch ($sort) { - case 'up': - $selectLastContactUp = $selected; - $order = array('field' => 'last_connect', 'order' => 'ASC'); - break; - case 'down': - $selectLastContactDown = $selected; - $order = array('field' => 'last_connect', 'order' => 'DESC'); - break; - } - break; - case 'last_contact': - switch ($sort) { - case 'up': - $selectLastContactUp = $selected; - $order = array('field' => 'last_connect', 'order' => 'ASC'); - break; - case 'down': - $selectLastContactDown = $selected; - $order = array('field' => 'last_connect', 'order' => 'DESC'); - break; - } - break; - case 'profile': - switch ($sort) { - case 'up': - $selectProfileUp = $selected; - $order = array('field' => 'is_admin', 'order' => 'ASC'); - break; - case 'down': - $selectProfileDown = $selected; - $order = array('field' => 'is_admin', 'order' => 'DESC'); - break; - } - break; - default: - $selectUserIDUp = $selected; - $selectUserIDDown = ''; - $selectNameUp = ''; - $selectNameDown = ''; - $selectEmailUp = ''; - $selectEmailDown = ''; - $selectLastContactUp = ''; - $selectLastContactDown = ''; - $selectProfileUp = ''; - $selectProfileDown = ''; - - $order = array('field' => 'id_user', 'order' => 'ASC'); - break; - } + require_once('search_users.php'); + break; + case 'alerts': + require_once('search_alerts.php'); + break; + case 'graphs': + require_once('search_graphs.php'); + break; + case 'reports': + require_once('search_reports.php'); + break; + case 'maps': + require_once('search_maps.php'); break; - case 'alerts': - $selectDisabledUp = ''; - $selectDisabledDown = ''; - $selectAgentUp = ''; - $selectAgentDown = ''; - $selectModuleUp = ''; - $selectModuleDown = ''; - $selectTemplateUp = ''; - $selectTemplateDown = ''; - switch ($sortField) { - case 'disabled': - switch ($sort) { - case 'up': - $selectAgentUp = $selected; - $order = array('field' => 'disabled', 'order' => 'ASC'); - break; - case 'down': - $selectAgentDown = $selected; - $order = array('field' => 'disabled', 'order' => 'DESC'); - break; - } - break; - case 'agent': - switch ($sort) { - case 'up': - $selectAgentUp = $selected; - $order = array('field' => 'agent_name', 'order' => 'ASC'); - break; - case 'down': - $selectAgentDown = $selected; - $order = array('field' => 'agent_name', 'order' => 'DESC'); - break; - } - break; - case 'module': - switch ($sort) { - case 'up': - $selectModuleUp = $selected; - $order = array('field' => 'module_name', 'order' => 'ASC'); - break; - case 'down': - $selectModuleDown = $selected; - $order = array('field' => 'module_name', 'order' => 'DESC'); - break; - } - break; - case 'template': - switch ($sort) { - case 'up': - $selectTemplateUp = $selected; - $order = array('field' => 'template_name', 'order' => 'ASC'); - break; - case 'down': - $selectTemplateDown = $selected; - $order = array('field' => 'template_name', 'order' => 'DESC'); - break; - } - break; - default: - $selectDisabledUp = ''; - $selectDisabledDown = ''; - $selectAgentUp = $selected; - $selectAgentDown = ''; - $selectModuleUp = ''; - $selectModuleDown = ''; - $selectTemplateUp = ''; - $selectTemplateDown = ''; - - $order = array('field' => 'agent_name', 'order' => 'ASC'); - break; - } - break; -} - -$agents = false; -if ($searchTab == 'agents') { - if ($searchAgents) { - $sql = "SELECT id_agente, tagente.nombre, tagente.id_os, tagente.intervalo, tagente.id_grupo, tagente.disabled - FROM tagente - INNER JOIN tgrupo - ON tgrupo.id_grupo = tagente.id_grupo - WHERE tagente.nombre COLLATE utf8_general_ci LIKE '%" . $stringSearchSQL . "%' OR - tgrupo.nombre LIKE '%" . $stringSearchSQL . "%' - ORDER BY " . $order['field'] . " " . $order['order'] . " - LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0); - $agents = process_sql($sql); - - $sql = "SELECT count(id_agente) AS count - FROM tagente - INNER JOIN tgrupo - ON tgrupo.id_grupo = tagente.id_grupo - WHERE tagente.nombre COLLATE utf8_general_ci LIKE '%" . $stringSearchSQL . "%' OR - tgrupo.nombre LIKE '%" . $stringSearchSQL . "%'"; - $totalAgents = get_db_row_sql($sql); - - $totalAgents = $totalAgents['count']; - } -} - -$users = false; -if ($searchTab == 'users') { - $sql = "SELECT id_user, fullname, firstname, lastname, middlename, email, last_connect, is_admin, comments FROM tusuario - WHERE fullname LIKE '%" . $stringSearchSQL . "%' OR - firstname LIKE '%" . $stringSearchSQL . "%' OR - lastname LIKE '%" . $stringSearchSQL . "%' OR - middlename LIKE '%" . $stringSearchSQL . "%' OR - email LIKE '%" . $stringSearchSQL . "%' - ORDER BY " . $order['field'] . " " . $order['order'] . " - LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0); - $users = process_sql($sql); - - $sql = "SELECT COUNT(id_user) AS count FROM tusuario - WHERE fullname LIKE '%" . $stringSearchSQL . "%' OR - firstname LIKE '%" . $stringSearchSQL . "%' OR - lastname LIKE '%" . $stringSearchSQL . "%' OR - middlename LIKE '%" . $stringSearchSQL . "%' OR - email LIKE '%" . $stringSearchSQL . "%'"; - $totalUsers = get_db_row_sql($sql); - - $totalUsers = $totalUsers['count']; -} - -$alerts = false; -if ($searchTab == 'alerts') { - $sql = "SELECT t1.disabled, t3.id_agente, t3.nombre AS agent_name, t2.nombre AS module_name, t4.name AS template_name, - (SELECT GROUP_CONCAT(t6.name) - FROM talert_template_module_actions AS t5 - INNER JOIN talert_actions AS t6 ON t6.id = t5.id_alert_action - WHERE t5.id_alert_template_module = t1.id) AS actions - FROM talert_template_modules AS t1 - INNER JOIN tagente_modulo AS t2 - ON t1.id_agent_module = t2.id_agente_modulo - INNER JOIN tagente AS t3 - ON t2.id_agente = t3.id_agente - INNER JOIN talert_templates AS t4 - ON t1.id_alert_template = t4.id - ORDER BY " . $order['field'] . " " . $order['order'] . " - LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0); - $alerts = process_sql($sql); - - $sql = "SELECT COUNT(t1.id) AS count - FROM talert_template_modules AS t1 - INNER JOIN tagente_modulo AS t2 - ON t1.id_agent_module = t2.id_agente_modulo - INNER JOIN tagente AS t3 - ON t2.id_agente = t3.id_agente - INNER JOIN talert_templates AS t4 - ON t1.id_alert_template = t4.id"; - $totalAlerts = get_db_row_sql($sql); - $totalAlerts = $totalAlerts['count']; - -} - -$graphs = false; -if ($searchTab == 'graphs') { - if ($searchGraphs) { - $sql = "SELECT id_graph, name, description FROM tgraph WHERE name LIKE '%" . $stringSearchSQL . "%' OR description LIKE '%" . $stringSearchSQL . "%' - LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0); - $graphs = process_sql($sql); - - $sql = "SELECT COUNT(id_graph) AS count FROM tgraph WHERE name LIKE '%" . $stringSearchSQL . "%' OR description LIKE '%" . $stringSearchSQL . "%'"; - $totalGraphs = get_db_row_sql($sql); - $totalGraphs = $totalGraphs['count']; - } -} - -$reports = false; -if (($config['search_category'] == 'all') || ($config['search_category'] == 'reports')) { - $sql = "SELECT id_report, name, description FROM treport WHERE name LIKE '%" . $stringSearchSQL . "%' - LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0); - $reports = process_sql($sql); - - $sql = "SELECT COUNT(id_report) AS count FROM treport WHERE name LIKE '%" . $stringSearchSQL . "%'"; - $totalReports = get_db_row_sql($sql); - $totalReports = $totalReports['count']; -} - -$maps = false; -if (($config['search_category'] == 'all') || ($config['search_category'] == 'maps')) { - if ($searchMaps) { - $sql = "SELECT t1.id, t1.name, t1.id_group, - (SELECT COUNT(*) FROM tlayout_data AS t2 WHERE t2.id_layout = t1.id) AS count - FROM tlayout AS t1 WHERE t1.name LIKE '%" . $stringSearchSQL . "%' - LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0); - $maps = process_sql($sql); - - $sql = "SELECT COUNT(id) AS count FROM tlayout WHERE name LIKE '%" . $stringSearchSQL . "%'"; - $totalMaps = get_db_row_sql($sql); - $totalMaps = $totalMaps['count']; - } -} - -///////// INI MENU AND TABS ///////////// - -$img_style = array ("class" => "top", "width" => 16); - -echo " -"; -echo "
"; - -///////// END MENU AND TABS ///////////// - -if (($agents === false) && ($users === false) && ($alerts === false) && ($graphs === false) - && ($reports === false) && ($maps === false)) { - echo "
" . __("Zero results found") . "
\n"; -} -else { - if ($agents !== false) { - - $table->cellpadding = 4; - $table->cellspacing = 4; - $table->width = "98%"; - $table->class = "databox"; - - $table->head = array (); - $table->head[0] = __('Agent') . ' ' . - '' . - ''; - $table->head[1] = __('OS'). ' ' . - '' . - ''; - $table->head[2] = __('Interval'). ' ' . - '' . - ''; - $table->head[3] = __('Group'). ' ' . - '' . - ''; - $table->head[4] = __('Modules'); - $table->head[5] = __('Status'); - $table->head[6] = __('Alerts'); - $table->head[7] = __('Last contact'). ' ' . - '' . - ''; - - $table->align = array (); - $table->align[0] = "left"; - $table->align[1] = "center"; - $table->align[2] = "center"; - $table->align[3] = "center"; - $table->align[4] = "center"; - $table->align[5] = "center"; - $table->align[6] = "center"; - $table->align[7] = "right"; - - $table->data = array (); - - foreach ($agents as $agent) { - $agent_info = get_agent_module_info ($agent["id_agente"]); - - $modulesCell = ''. $agent_info["modules"] . ''; - if ($agent_info["monitor_normal"] > 0) - $modulesCell .= ' : '.$agent_info["monitor_normal"].''; - if ($agent_info["monitor_warning"] > 0) - $modulesCell .= ' : '.$agent_info["monitor_warning"].''; - if ($agent_info["monitor_critical"] > 0) - $modulesCell .= ' : '.$agent_info["monitor_critical"].''; - if ($agent_info["monitor_unknown"] > 0) - $modulesCell .= ' : '.$agent_info["monitor_unknown"].''; - - if ($agent['disabled']) { - $cellName = "" . print_agent_name ($agent["id_agente"], true, "upper") .print_help_tip(__('Disabled'), true) . ""; - } - else { - $cellName = print_agent_name ($agent["id_agente"], true, "upper"); - } - - array_push($table->data, array( - $cellName, - print_os_icon ($agent["id_os"], false, true), - $agent['intervalo'], - print_group_icon ($agent["id_grupo"], true), - $modulesCell, - $agent_info["status_img"], - $agent_info["alert_img"], - print_timestamp ($agent_info["last_contact"], true))); - } - - echo "
";pagination ($totalAgents); - print_table ($table); unset($table); - pagination ($totalAgents); - } - - if ($users !== false) { - $table->cellpadding = 4; - $table->cellspacing = 4; - $table->width = "98%"; - $table->class = "databox"; - - $table->head = array (); - $table->head[0] = __('User ID') . ' ' . - '' . - ''; - $table->head[1] = __('Name') . ' ' . - '' . - ''; - $table->head[2] = __('Email') . ' ' . - '' . - ''; - $table->head[3] = __('Last contact') . ' ' . - '' . - ''; - $table->head[4] = __('Profile') . ' ' . - '' . - ''; - $table->head[5] = __('Description'); - - $table->data = array (); - - foreach ($users as $user) { - if ($linkEditUser) - $userIDCell = "" . $user['id_user'] . ""; - else - $userIDCell = $user['id_user']; - - if ($user["is_admin"]) { - $profileCell = print_image ("images/user_suit.png", true, - array ("alt" => __('Admin'), - "title" => __('Administrator'))).' '; - } else { - $profileCell = print_image ("images/user_green.png", true, - array ("alt" => __('User'), - "title" => __('Standard User'))).' '; - } - $profileCell .= ''; - $result = get_db_all_rows_field_filter ("tusuario_perfil", "id_usuario", $user['id_user']); - if ($result !== false) { - foreach ($result as $row) { - $profileCell .= get_profile_name ($row["id_perfil"]); - $profileCell .= " / "; - $profileCell .= get_group_name ($row["id_grupo"]); - $profileCell .= "
"; - } - } else { - $profileCell .= __('The user doesn\'t have any assigned profile/group'); - } - $profileCell .= "
"; - - array_push($table->data, array( - $userIDCell, - $user['fullname'], - "" . $user['email'] . "", - print_timestamp ($user["last_connect"], true), - $profileCell, - $user['comments'])); - } - - echo "
";pagination ($totalUsers); - print_table ($table); unset($table); - pagination ($totalUsers); - } - - if ($alerts !== false) { - $table->cellpadding = 4; - $table->cellspacing = 4; - $table->width = "98%"; - $table->class = "databox"; - - $table->head = array (); - $table->head[0] = '' . ' ' . - '' . - ''; - $table->head[1] = __('Agent') . ' ' . - '' . - ''; - $table->head[2] = __('Module') . ' ' . - '' . - ''; - $table->head[3] = __('Template') . ' ' . - '' . - ''; - $table->head[4] = __('Action'); - - $table->align = array (); - $table->align[0] = "center"; - $table->align[1] = "left"; - $table->align[2] = "left"; - $table->align[3] = "left"; - $table->align[4] = "left"; - - $table->valign = array (); - $table->valign[0] = "top"; - $table->valign[1] = "top"; - $table->valign[2] = "top"; - $table->valign[3] = "top"; - $table->valign[4] = "top"; - - $table->data = array (); - foreach ($alerts as $alert) { - if ($alert['disabled']) - $disabledCell = print_image ('images/lightbulb_off.png', true, array('title' => 'disable', 'alt' => 'disable')); - else - $disabledCell = print_image ('images/lightbulb.png', true, array('alt' => 'enable', 'title' => 'enable')); - - $actionCell = ''; - if (strlen($alert["actions"]) > 0) { - $arrayActions = explode(',', $alert["actions"]); - $actionCell = ''; - } - - - array_push($table->data, array( - $disabledCell, - print_agent_name ($alert["id_agente"], true, "upper"), - $alert["module_name"], - $alert["template_name"],$actionCell - )); - } - - echo "
";pagination ($totalAlerts); - print_table ($table); unset($table); - pagination ($totalAlerts); - } - - if ($graphs !== false) { - $table->cellpadding = 4; - $table->cellspacing = 4; - $table->width = "98%"; - $table->class = "databox"; - - $table->head = array (); - $table->head[0] = __('Graph name'); - $table->head[1] = __('Description'); - - - $table->align = array (); - $table->align[1] = "center"; - $table->align[2] = "center"; - - $table->data = array (); - foreach ($graphs as $graph) { - array_push($table->data, array( - "" . $graph['name'] . "", - $graph['description'] - )); - } - - echo "
";pagination ($totalGraphs); - print_table ($table); unset($table); - pagination ($totalGraphs); - } - - if ($reports !== false) { - $table->cellpadding = 4; - $table->cellspacing = 4; - $table->width = "98%"; - $table->class = "databox"; - - $table->head = array (); - $table->head[0] = __('Report name'); - $table->head[1] = __('Description'); - $table->head[2] = __('HTML'); - $table->head[3] = __('XML'); - enterprise_hook ('load_custom_reporting_1'); - - $table->align = array (); - $table->align[0] = "center"; - $table->align[1] = "center"; - $table->align[2] = "center"; - $table->align[3] = "center"; - - $table->data = array (); - foreach ($reports as $report) { - - $data = array( - "" . - $report['name'] . "", - $report['description'], - '', - '' - ); - enterprise_hook ('load_custom_reporting_2'); - - array_push($table->data, $data); - } - - echo "
";pagination ($totalReports); - print_table ($table); unset($table); - pagination ($totalReports); - } - - if ($maps !== false) { - $table->cellpadding = 4; - $table->cellspacing = 4; - $table->width = "98%"; - $table->class = "databox"; - - $table->head = array (); - $table->head[0] = __('Name'); - $table->head[1] = __('Group'); - $table->head[2] = __('Elements'); - - $table->align = array (); - $table->align[0] = "center"; - $table->align[1] = "center"; - $table->align[2] = "center"; - - $table->data = array (); - foreach ($maps as $map) { - array_push($table->data, array( - "" . $map['name'] . "", - print_group_icon ($layout["id_group"], true) . " " . get_group_name ($layout["id_group"]), - $map['count'] - )); - } - - echo "
";pagination ($totalMaps); - print_table ($table); unset($table); - pagination ($totalMaps); - } } ?> diff --git a/pandora_console/operation/search_users.php b/pandora_console/operation/search_users.php new file mode 100755 index 0000000000..3736054b76 --- /dev/null +++ b/pandora_console/operation/search_users.php @@ -0,0 +1,233 @@ + 'id_user', 'order' => 'ASC'); + break; + case 'down': + $selectUserIDDown = $selected; + $order = array('field' => 'id_user', 'order' => 'DESC'); + break; + } + break; + case 'name': + switch ($sort) { + case 'up': + $selectNameUp = $selected; + $order = array('field' => 'fullname', 'order' => 'ASC'); + break; + case 'down': + $selectNameDown = $selected; + $order = array('field' => 'fullname', 'order' => 'DESC'); + break; + } + break; + case 'email': + switch ($sort) { + case 'up': + $selectLastContactUp = $selected; + $order = array('field' => 'email', 'order' => 'ASC'); + break; + case 'down': + $selectEmailDown = $selected; + $order = array('field' => 'email', 'order' => 'DESC'); + break; + } + break; + case 'last_contact': + switch ($sort) { + case 'up': + $selectLastContactUp = $selected; + $order = array('field' => 'last_connect', 'order' => 'ASC'); + break; + case 'down': + $selectLastContactDown = $selected; + $order = array('field' => 'last_connect', 'order' => 'DESC'); + break; + } + break; + case 'last_contact': + switch ($sort) { + case 'up': + $selectLastContactUp = $selected; + $order = array('field' => 'last_connect', 'order' => 'ASC'); + break; + case 'down': + $selectLastContactDown = $selected; + $order = array('field' => 'last_connect', 'order' => 'DESC'); + break; + } + break; + case 'profile': + switch ($sort) { + case 'up': + $selectProfileUp = $selected; + $order = array('field' => 'is_admin', 'order' => 'ASC'); + break; + case 'down': + $selectProfileDown = $selected; + $order = array('field' => 'is_admin', 'order' => 'DESC'); + break; + } + break; + default: + $selectUserIDUp = $selected; + $selectUserIDDown = ''; + $selectNameUp = ''; + $selectNameDown = ''; + $selectEmailUp = ''; + $selectEmailDown = ''; + $selectLastContactUp = ''; + $selectLastContactDown = ''; + $selectProfileUp = ''; + $selectProfileDown = ''; + + $order = array('field' => 'id_user', 'order' => 'ASC'); + break; +} + +$users = false; +if ($searchUsers) { + $sql = "SELECT id_user, fullname, firstname, lastname, middlename, email, last_connect, is_admin, comments FROM tusuario + WHERE fullname LIKE '%" . $stringSearchSQL . "%' OR + firstname LIKE '%" . $stringSearchSQL . "%' OR + lastname LIKE '%" . $stringSearchSQL . "%' OR + middlename LIKE '%" . $stringSearchSQL . "%' OR + email LIKE '%" . $stringSearchSQL . "%' + ORDER BY " . $order['field'] . " " . $order['order'] . " + LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0); + $users = process_sql($sql); + + if($users !== false) { + //Check ACLs + $users_id = array(); + foreach($users as $key => $user){ + if (!check_acl ($config["id_user"], get_user_groups ($user["id_user"]), "UM") && $config["id_user"] != $user["id_user"]) { + unset($users[$key]); + } else { + $users_id[] = $user["id_user"]; + } + } + + if(!$users_id) { + $user_condition = ""; + }else { + // Condition with the visible agents + $user_condition = " AND id_user IN (\"".implode('","',$users_id)."\")"; + } + + $sql = "SELECT COUNT(id_user) AS count FROM tusuario + WHERE (fullname LIKE '%" . $stringSearchSQL . "%' OR + firstname LIKE '%" . $stringSearchSQL . "%' OR + lastname LIKE '%" . $stringSearchSQL . "%' OR + middlename LIKE '%" . $stringSearchSQL . "%' OR + email LIKE '%" . $stringSearchSQL . "%')".$user_condition; + $totalUsers = get_db_row_sql($sql); + + $totalUsers = $totalUsers['count']; + } +} + +if (!$users) { + echo "
" . __("Zero results found") . "
\n"; +} +else { + $table->cellpadding = 4; + $table->cellspacing = 4; + $table->width = "98%"; + $table->class = "databox"; + + $table->align = array (); + $table->align[4] = "center"; + + $table->head = array (); + $table->head[0] = __('User ID') . ' ' . + '' . + ''; + $table->head[1] = __('Name') . ' ' . + '' . + ''; + $table->head[2] = __('Email') . ' ' . + '' . + ''; + $table->head[3] = __('Last contact') . ' ' . + '' . + ''; + $table->head[4] = __('Profile') . ' ' . + '' . + ''; + $table->head[5] = __('Description'); + + $table->data = array (); + + foreach ($users as $user) { + $userIDCell = "" . $user['id_user'] . ""; + + if ($user["is_admin"]) { + $profileCell = print_image ("images/user_suit.png", true, + array ("alt" => __('Admin'), + "title" => __('Administrator'))).' '; + } else { + $profileCell = print_image ("images/user_green.png", true, + array ("alt" => __('User'), + "title" => __('Standard User'))).' '; + } + $profileCell .= ''; + $result = get_db_all_rows_field_filter ("tusuario_perfil", "id_usuario", $user['id_user']); + if ($result !== false) { + foreach ($result as $row) { + $profileCell .= get_profile_name ($row["id_perfil"]); + $profileCell .= " / "; + $profileCell .= get_group_name ($row["id_grupo"]); + $profileCell .= "
"; + } + } else { + $profileCell .= __('The user doesn\'t have any assigned profile/group'); + } + $profileCell .= "
"; + + array_push($table->data, array( + $userIDCell, + $user['fullname'], + "" . $user['email'] . "", + print_timestamp ($user["last_connect"], true), + $profileCell, + $user['comments'])); + } + + echo "
";pagination ($totalUsers); + print_table ($table); unset($table); + pagination ($totalUsers); +} +?>