2012-02-10 Miguel de Dios <miguel.dedios@artica.es>

* * extensions/module_groups.php, include/functions_modules.php,
	godmode/agentes/module_manager_editor_prediction.php: cleaned
	source code style.

	* godmode/agentes/configurar_agente.php: cleaned source code style and fixed
	the duplication of module.
	
	* include/functions_agents.php: fixed the get modules into function
	"agents_get_modules", before the function return ever the policy modules
	without apply filter.
	
	Fixes: #3482260



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5554 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2012-02-10 13:23:12 +00:00
parent 4df70f23d7
commit 0a9f2ccda4
6 changed files with 82 additions and 47 deletions

View File

@ -1,3 +1,18 @@
2012-02-10 Miguel de Dios <miguel.dedios@artica.es>
* * extensions/module_groups.php, include/functions_modules.php,
godmode/agentes/module_manager_editor_prediction.php: cleaned
source code style.
* godmode/agentes/configurar_agente.php: cleaned source code style and fixed
the duplication of module.
* include/functions_agents.php: fixed the get modules into function
"agents_get_modules", before the function return ever the policy modules
without apply filter.
Fixes: #3482260
2012-02-10 Dario Rodriguez <dario.rodriguez@artica.es> 2012-02-10 Dario Rodriguez <dario.rodriguez@artica.es>
* include/functions_groups.php: Added links to different sections with * include/functions_groups.php: Added links to different sections with

View File

@ -28,7 +28,7 @@ if (is_ajax ()) {
$data = false; $data = false;
if ($get_info_alert_module_group) { if ($get_info_alert_module_group) {
$agents = agents_get_group_agents($id_agent_group); $agents = agents_get_group_agents($id_agent_group);
if (!empty($agents)) { if (!empty($agents)) {
$alerts = agents_get_alerts_simple(array_keys($agents)); $alerts = agents_get_alerts_simple(array_keys($agents));
foreach ($alerts as $alert) { foreach ($alerts as $alert) {
@ -128,7 +128,7 @@ function mainModuleGroups() {
ui_print_page_header (__("Combined table of agent group and module group"), "images/brick.png", false, "", false, ''); ui_print_page_header (__("Combined table of agent group and module group"), "images/brick.png", false, "", false, '');
echo "<p>" . __("This table shows in columns the modules group and in rows agents group. The cell shows all modules") . "</p>"; echo "<p>" . __("This table shows in columns the modules group and in rows agents group. The cell shows all modules") . "</p>";
$agentGroups = users_get_groups ($config['id_user'], "AR", false); $agentGroups = users_get_groups ($config['id_user'], "AR", false);
$modelGroups = users_get_all_model_groups(); $modelGroups = users_get_all_model_groups();
@ -164,17 +164,17 @@ function mainModuleGroups() {
foreach ($modelGroups as $idModelGroup => $modelGroup) { foreach ($modelGroups as $idModelGroup => $modelGroup) {
$query = sprintf($sql,$idAgentGroup, $idModelGroup); $query = sprintf($sql,$idAgentGroup, $idModelGroup);
$rowsDB = db_get_all_rows_sql ($query); $rowsDB = db_get_all_rows_sql ($query);
$agents = agents_get_group_agents($idAgentGroup); $agents = agents_get_group_agents($idAgentGroup);
if (!empty($agents)) { if (!empty($agents)) {
$alerts = agents_get_alerts_simple(array_keys($agents)); $alerts = agents_get_alerts_simple(array_keys($agents));
foreach ($alerts as $alert) { foreach ($alerts as $alert) {
$module = db_get_row_filter('tagente_modulo', array('id_agente_modulo' => $alert['id_agent_module'])); $module = db_get_row_filter('tagente_modulo', array('id_agente_modulo' => $alert['id_agent_module']));
if ($idModelGroup == $module['id_module_group']) { if ($idModelGroup == $module['id_module_group']) {
if ($alert["times_fired"] > 0) { if ($alert["times_fired"] > 0) {
$fired = true; $fired = true;
@ -182,7 +182,7 @@ function mainModuleGroups() {
} }
} }
} }
$states = array(); $states = array();
if ($rowsDB !== false) { if ($rowsDB !== false) {
foreach ($rowsDB as $rowDB) { foreach ($rowsDB as $rowDB) {
@ -191,7 +191,6 @@ function mainModuleGroups() {
} }
$count = 0; $count = 0;
foreach ($states as $idState => $state) { foreach ($states as $idState => $state) {
$count += $state; $count += $state;
} }

View File

@ -253,7 +253,7 @@ if ($id_agente) {
if($tab == 'alert') if($tab == 'alert')
$alerttab['active'] = true; $alerttab['active'] = true;
else else
$alerttab['active'] = false; $alerttab['active'] = false;
/* Template tab */ /* Template tab */
$templatetab['text'] = '<a href="index.php?sec=gagente&amp;sec2=godmode/agentes/configurar_agente&amp;tab=template&amp;id_agente='.$id_agente.'">' $templatetab['text'] = '<a href="index.php?sec=gagente&amp;sec2=godmode/agentes/configurar_agente&amp;tab=template&amp;id_agente='.$id_agente.'">'
@ -608,7 +608,8 @@ if ($id_agente) {
$update_module = (bool) get_parameter ('update_module'); $update_module = (bool) get_parameter ('update_module');
$create_module = (bool) get_parameter ('create_module'); $create_module = (bool) get_parameter ('create_module');
$delete_module = (bool) get_parameter ('delete_module'); $delete_module = (bool) get_parameter ('delete_module');
$duplicate_module = (bool) get_parameter ('duplicate_module'); //It is the id_agent_module to duplicate
$duplicate_module = (int) get_parameter ('duplicate_module');
$edit_module = (bool) get_parameter ('edit_module'); $edit_module = (bool) get_parameter ('edit_module');
// GET DATA for MODULE UPDATE OR MODULE INSERT // GET DATA for MODULE UPDATE OR MODULE INSERT
@ -996,11 +997,26 @@ if ($delete_module) { // DELETE agent module !
// MODULE DUPLICATION // MODULE DUPLICATION
// ================= // =================
if ($duplicate_module) { // DUPLICATE agent module ! if (!empty($duplicate_module)) { // DUPLICATE agent module !
$id_duplicate_module = (int) get_parameter_get ("duplicate_module",0); $id_duplicate_module = $duplicate_module;
$original_name = modules_get_agentmodule_name($id_duplicate_module);
$copy_name = __('copy of') . ' ' . $original_name;
$cont = 0;
$exists = true;
while($exists) {
$exists = (bool)db_get_value ('id_agente_modulo', 'tagente_modulo',
'nombre', $copy_name);
if ($exists) {
$cont++;
$copy_name = __('copy of') . ' ' . $original_name
. ' (' . $cont . ')';
}
}
$result = modules_copy_agent_module_to_agent ($id_duplicate_module, $result = modules_copy_agent_module_to_agent ($id_duplicate_module,
modules_get_agentmodule_agent($id_duplicate_module), modules_get_agentmodule_agent($id_duplicate_module), $copy_name);
io_safe_input(__('copy of').' '.modules_get_agentmodule_name($id_duplicate_module)));
$agent = db_get_row ('tagente', 'id_agente', $id_agente); $agent = db_get_row ('tagente', 'id_agente', $id_agente);

View File

@ -30,7 +30,7 @@ $is_synthetic = false;
$is_synthetic_avg = false; $is_synthetic_avg = false;
$is_netflow = false; $is_netflow = false;
$ops = false; $ops = false;
if ($row !== false && is_array($row)) { if ($row !== false && is_array($row)) {
$prediction_module = $row['prediction_module']; $prediction_module = $row['prediction_module'];
$custom_integer_2 = $row ['custom_integer_2']; $custom_integer_2 = $row ['custom_integer_2'];
// Services are an Enterprise feature. // Services are an Enterprise feature.

View File

@ -170,10 +170,10 @@ function agents_get_alerts_simple ($id_agent = false, $filter = '', $options = f
else { else {
$id_agent = (array) $id_agent; $id_agent = (array) $id_agent;
$id_modules = array_keys (agents_get_modules ($id_agent, false, array('delete_pending' => 0))); $id_modules = array_keys (agents_get_modules ($id_agent, false, array('delete_pending' => 0)));
if (empty ($id_modules)) if (empty ($id_modules))
return array (); return array ();
$subQuery = implode (",", $id_modules); $subQuery = implode (",", $id_modules);
} }
@ -186,7 +186,7 @@ function agents_get_alerts_simple ($id_agent = false, $filter = '', $options = f
$orderbyText = sprintf("ORDER BY %s", $orderby); $orderbyText = sprintf("ORDER BY %s", $orderby);
} }
} }
$selectText = 'talert_template_modules.*, t2.nombre AS agent_module_name, t3.nombre AS agent_name, t4.name AS template_name'; $selectText = 'talert_template_modules.*, t2.nombre AS agent_module_name, t3.nombre AS agent_name, t4.name AS template_name';
if ($count !== false) { if ($count !== false) {
$selectText = 'COUNT(talert_template_modules.id) AS count'; $selectText = 'COUNT(talert_template_modules.id) AS count';
@ -198,7 +198,7 @@ function agents_get_alerts_simple ($id_agent = false, $filter = '', $options = f
}else if ($extra_sql != '') { }else if ($extra_sql != '') {
$extra_sql .= ' OR '; $extra_sql .= ' OR ';
} }
$sql = sprintf ("SELECT %s $sql = sprintf ("SELECT %s
FROM talert_template_modules FROM talert_template_modules
INNER JOIN tagente_modulo t2 INNER JOIN tagente_modulo t2
@ -209,7 +209,7 @@ function agents_get_alerts_simple ($id_agent = false, $filter = '', $options = f
ON talert_template_modules.id_alert_template = t4.id ON talert_template_modules.id_alert_template = t4.id
WHERE (%s id_agent_module in (%s)) %s %s %s", WHERE (%s id_agent_module in (%s)) %s %s %s",
$selectText, $extra_sql, $subQuery, $where, $filter, $orderbyText); $selectText, $extra_sql, $subQuery, $where, $filter, $orderbyText);
$alerts = db_get_all_rows_sql ($sql); $alerts = db_get_all_rows_sql ($sql);
if ($alerts === false) if ($alerts === false)
@ -510,7 +510,7 @@ function agents_get_agents ($filter = false, $fields = false, $access = 'AR', $o
$agents = oracle_recode_query ($sql, $set, 'AND', false); $agents = oracle_recode_query ($sql, $set, 'AND', false);
break; break;
} }
return $agents; return $agents;
} }
@ -969,7 +969,7 @@ function agents_get_group_agents ($id_group = 0, $search = false, $case = "lower
enterprise_include_once ('include/functions_policies.php'); enterprise_include_once ('include/functions_policies.php');
if ($extra_access && $all_groups){ //if you have all group, search extra policies. if ($extra_access && $all_groups) { //if you have all group, search extra policies.
$extra_sql = enterprise_hook('policies_get_agents_sql_condition'); $extra_sql = enterprise_hook('policies_get_agents_sql_condition');
if ($extra_sql === ENTERPRISE_NOT_HOOK) { if ($extra_sql === ENTERPRISE_NOT_HOOK) {
$extra_sql = ''; $extra_sql = '';
@ -1070,18 +1070,20 @@ function agents_get_modules ($id_agent = null, $details = false, $filter = false
$id_agent = safe_int ($id_agent, 1); $id_agent = safe_int ($id_agent, 1);
} }
$extra_sql = ''; $policy_sql = '';
if ($id_agent != 0){ if ($id_agent != 0){
$extra_sql = enterprise_hook('policies_get_modules_sql_condition', array($id_agent, '', false)); $extra_policy_sql = enterprise_hook('policies_get_modules_sql_condition', array($id_agent));
if ($extra_sql === ENTERPRISE_NOT_HOOK) { if ($policy_sql === ENTERPRISE_NOT_HOOK) {
$extra_sql = ''; $policy_sql = '';
}else if ($extra_sql != '') { }
$extra_sql .= ' OR '; else if ($policy_sql != '') {
//It is AND instead OR, because It is necesary apply the filter.
$policy_sql = ' OR ' . $policy_sql;
} }
} }
$userGroups = users_get_groups($config['id_user'], 'AR', false); $userGroups = users_get_groups($config['id_user'], 'AR', false);
if(empty($userGroups)) { if(empty($userGroups)) {
return array(); return array();
} }
@ -1111,6 +1113,7 @@ function agents_get_modules ($id_agent = null, $details = false, $filter = false
FROM tperfil WHERE agent_view = 1 FROM tperfil WHERE agent_view = 1
) )
) )
" . $policy_sql . "
)"; )";
if (! empty ($id_agent)) { if (! empty ($id_agent)) {
@ -1199,15 +1202,15 @@ function agents_get_modules ($id_agent = null, $details = false, $filter = false
else { else {
if ($config['dbtype'] == 'oracle'){ if ($config['dbtype'] == 'oracle'){
$details_new = array(); $details_new = array();
if (is_array($details)){ if (is_array($details)) {
foreach ($details as $detail){ foreach ($details as $detail) {
if ($detail == 'nombre') if ($detail == 'nombre')
$details_new[] = 'dbms_lob.substr(nombre,4000,1) as nombre'; $details_new[] = 'dbms_lob.substr(nombre,4000,1) as nombre';
else else
$details_new[] = $detail; $details_new[] = $detail;
} }
} }
else{ else {
if ($details == 'nombre') if ($details == 'nombre')
$details_new = 'dbms_lob.substr(nombre,4000,1) as nombre'; $details_new = 'dbms_lob.substr(nombre,4000,1) as nombre';
else else
@ -1227,25 +1230,23 @@ function agents_get_modules ($id_agent = null, $details = false, $filter = false
case "postgresql": case "postgresql":
$sql = sprintf ('SELECT %s%s $sql = sprintf ('SELECT %s%s
FROM tagente_modulo WHERE FROM tagente_modulo WHERE
%s (%s) %s
ORDER BY nombre', ORDER BY nombre',
($details != '*' && $indexed) ? 'id_agente_modulo,' : '', ($details != '*' && $indexed) ? 'id_agente_modulo,' : '',
io_safe_output(implode (",", (array) $details)), io_safe_output(implode (",", (array) $details)),
$extra_sql,
$where); $where);
break; break;
case "oracle": case "oracle":
$sql = sprintf ('SELECT %s%s $sql = sprintf ('SELECT %s%s
FROM tagente_modulo WHERE FROM tagente_modulo WHERE
%s (%s) %s
ORDER BY dbms_lob.substr(nombre, 4000, 1)', ORDER BY dbms_lob.substr(nombre, 4000, 1)',
($details != '*' && $indexed) ? 'id_agente_modulo,' : '', ($details != '*' && $indexed) ? 'id_agente_modulo,' : '',
io_safe_output(implode (",", (array) $details)), io_safe_output(implode (",", (array) $details)),
$extra_sql,
$where); $where);
break; break;
} }
$result = db_get_all_rows_sql ($sql); $result = db_get_all_rows_sql ($sql);
if (empty ($result)) { if (empty ($result)) {
@ -1261,7 +1262,8 @@ function agents_get_modules ($id_agent = null, $details = false, $filter = false
if (is_array ($details) || $details == '*') { if (is_array ($details) || $details == '*') {
//Just stack the information in array by ID //Just stack the information in array by ID
$modules[$module['id_agente_modulo']] = $module; $modules[$module['id_agente_modulo']] = $module;
} else { }
else {
$modules[$module['id_agente_modulo']] = $module[$details]; $modules[$module['id_agente_modulo']] = $module[$details];
} }
} }

View File

@ -50,10 +50,10 @@ function modules_copy_agent_module_to_agent ($id_agent_module, $id_destiny_agent
if (! empty ($modules)) if (! empty ($modules))
return array_pop (array_keys ($modules)); return array_pop (array_keys ($modules));
$modulesDisabled = agents_get_modules ($id_destiny_agent, false, $modulesDisabled = agents_get_modules ($id_destiny_agent, false,
array ('nombre' => $module['nombre'], 'disabled' => true)); array ('nombre' => $module['nombre'], 'disabled' => true));
if (!empty($modulesDisabled)) { if (!empty($modulesDisabled)) {
//the foreach have only one loop but extract the array index, and it's id_agente_modulo //the foreach have only one loop but extract the array index, and it's id_agente_modulo
foreach ($modulesDisabled as $id => $garbage) { foreach ($modulesDisabled as $id => $garbage) {
@ -68,7 +68,7 @@ function modules_copy_agent_module_to_agent ($id_agent_module, $id_destiny_agent
db_process_sql_update('tagente_modulo', array('disabled' => false, 'delete_pending' => false), db_process_sql_update('tagente_modulo', array('disabled' => false, 'delete_pending' => false),
array('id_agente_modulo' => $id_module, 'disabled' => true), 'AND', false); array('id_agente_modulo' => $id_module, 'disabled' => true), 'AND', false);
break; break;
} }
} }
$values = array (); $values = array ();
@ -104,14 +104,16 @@ function modules_copy_agent_module_to_agent ($id_agent_module, $id_destiny_agent
unset ($new_module[$i]); unset ($new_module[$i]);
/* Unset original agent module id */ /* Unset original agent module id */
unset ($new_module['id_agente_modulo']); unset ($new_module['id_agente_modulo']);
switch ($config['dbtype']) { switch ($config['dbtype']) {
case "mysql": case "mysql":
case "postgresql": case "postgresql":
$id_new_module = db_process_sql_insert ('tagente_modulo', $new_module); $id_new_module = db_process_sql_insert ('tagente_modulo',
$new_module);
break; break;
case "oracle": case "oracle":
$id_new_module = db_process_sql_insert ('tagente_modulo', $new_module, false); $id_new_module = db_process_sql_insert ('tagente_modulo',
$new_module, false);
break; break;
} }
if ($id_new_module === false) { if ($id_new_module === false) {
@ -589,7 +591,8 @@ function modules_get_type_icon ($id_type) {
* @return int The id of the agent of given agent module * @return int The id of the agent of given agent module
*/ */
function modules_get_agentmodule_agent ($id_agentmodule) { function modules_get_agentmodule_agent ($id_agentmodule) {
return (int) db_get_value ('id_agente', 'tagente_modulo', 'id_agente_modulo', (int) $id_agentmodule); return (int) db_get_value ('id_agente', 'tagente_modulo',
'id_agente_modulo', (int) $id_agentmodule);
} }
/** /**