diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index e5c272f700..9abfa5dea8 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,13 @@ +2012-07-30 Miguel de Dios + + * godmode/agentes/module_manager_editor_plugin.php, + godmode/agentes/module_manager_editor_network.php, + godmode/agentes/module_manager_editor_wmi.php, + godmode/alerts/alert_list.php, godmode/menu.php, + godmode/snmpconsole/snmp_filters.php, godmode/tag/edit_tag.php, + include/functions_alerts.php, include/functions_html.php, + pandoradb.sql, index.php: cleaned source code style. + 2012-07-30 Hirofumi Kosaka * operation/reporting/graph_viewer.php: replace 'Period' with diff --git a/pandora_console/godmode/agentes/module_manager_editor_network.php b/pandora_console/godmode/agentes/module_manager_editor_network.php index a2e15043fa..4198389255 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_network.php +++ b/pandora_console/godmode/agentes/module_manager_editor_network.php @@ -20,9 +20,7 @@ $disabledTextBecauseInPolicy = ''; $page = get_parameter('page', ''); if (strstr($page, "policy_modules") === false) { if ($config['enterprise_installed']) { - $disabledBecauseInPolicy = policies_is_module_in_policy($id_agent_module) && policies_is_module_linked($id_agent_module); - } else $disabledBecauseInPolicy = false; @@ -59,9 +57,7 @@ $data = array (); $data[0] = __('SNMP community'); $adopt = false; if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK && isset($id_agent_module)) { - $adopt = policies_is_module_adopt($id_agent_module); - } if (!$adopt) { $data[1] = html_print_input_text ('snmp_community', $snmp_community, '', 15, 60, true, $disabledBecauseInPolicy); @@ -75,7 +71,8 @@ $data[2] = _('SNMP version'); if ($id_module_type >= 15 && $id_module_type <= 18) { $data[3] = html_print_select ($snmp_versions, 'snmp_version', $snmp_version, '', '', '', true, false, false, '', $disabledBecauseInPolicy); -} else { +} +else { $data[3] = html_print_select ($snmp_versions, 'snmp_version', 0, '', '', '', true, false, false, '', $disabledBecauseInPolicy); } @@ -221,11 +218,11 @@ $(document).ready (function () { function () { $(this).css ("width", "auto"); $(this).css ("min-width", "180px"); - }); + }); $("#id_module_type").blur (function () { $(this).css ("width", "180px"); - }); + }); }); - + \ No newline at end of file diff --git a/pandora_console/godmode/agentes/module_manager_editor_plugin.php b/pandora_console/godmode/agentes/module_manager_editor_plugin.php index 5f1ebc1234..b50f30cb85 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_plugin.php +++ b/pandora_console/godmode/agentes/module_manager_editor_plugin.php @@ -32,7 +32,8 @@ define ('ID_NETWORK_COMPONENT_TYPE', 4); if (empty ($update_module_id)) { /* Function in module_manager_editor_common.php */ add_component_selection (ID_NETWORK_COMPONENT_TYPE); -} else { +} +else { /* TODO: Print network component if available */ } @@ -44,11 +45,12 @@ $data[1] = html_print_select_from_sql ('SELECT id, name FROM tplugin ORDER BY na 'id_plugin', $id_plugin, 'changePluginSelect();', __('None'), 0, true, false, false, $disabledBecauseInPolicy); $table_simple->colspan['plugin_1'][2] = 2; -if (!empty($id_plugin)){ +if (!empty($id_plugin)) { $preload = db_get_sql ("SELECT description FROM tplugin WHERE id = $id_plugin"); $preload = io_safe_output ($preload); $preload = str_replace ("\n", "
", $preload); -} else { +} +else { $preload = ""; } diff --git a/pandora_console/godmode/agentes/module_manager_editor_wmi.php b/pandora_console/godmode/agentes/module_manager_editor_wmi.php index ac2a596203..9047b94c8a 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_wmi.php +++ b/pandora_console/godmode/agentes/module_manager_editor_wmi.php @@ -33,7 +33,8 @@ define ('ID_NETWORK_COMPONENT_TYPE', 6); if (empty ($update_module_id)) { /* Function in module_manager_editor_common.php */ add_component_selection (ID_NETWORK_COMPONENT_TYPE); -} else { +} +else { /* TODO: Print network component if available */ } diff --git a/pandora_console/godmode/alerts/alert_list.php b/pandora_console/godmode/alerts/alert_list.php index 501d5378b9..27f873d724 100644 --- a/pandora_console/godmode/alerts/alert_list.php +++ b/pandora_console/godmode/alerts/alert_list.php @@ -71,26 +71,34 @@ if ($create_alert) { FROM talert_template_modules WHERE id_agent_module = " . $id_agent_module . " AND id_alert_template = " . $id_alert_template) > 0) { - $messageAction = ui_print_result_message (false, '', __('Already added'), '', true); + + $messageAction = ui_print_result_message (false, '', + __('Already added'), '', true); } else { $id = alerts_create_alert_agent_module ($id_agent_module, $id_alert_template); - - $alert_template_name = db_get_value ("name", "talert_templates","id", $id_alert_template); - $module_name = db_get_value ("nombre", "tagente_modulo","id_agente_modulo", $id_agent_module); - $agent_name = agents_get_name (db_get_value ("id_agente", "tagente_modulo","id_agente_modulo", $id_agent_module)); + + $alert_template_name = db_get_value ("name", + "talert_templates","id", $id_alert_template); + $module_name = db_get_value ("nombre", + "tagente_modulo","id_agente_modulo", $id_agent_module); + $agent_name = agents_get_name (db_get_value ("id_agente", + "tagente_modulo","id_agente_modulo", $id_agent_module)); // Audit the creation only when the alert creation is correct - if($id) { + if ($id) { db_pandora_audit("Alert management", - "Added alert '$alert_template_name' for module '$module_name' in agent '$agent_name'", false, false, 'ID: ' . $id); + "Added alert '$alert_template_name' for module '$module_name' in agent '$agent_name'", + false, false, 'ID: ' . $id); } else { db_pandora_audit("Alert management", "Fail Added alert '$alert_template_name' for module '$module_name' in agent '$agent_name'"); } - - $messageAction = ui_print_result_message ($id, __('Successfully created'), __('Could not be created'), '', true); + + $messageAction = ui_print_result_message ($id, + __('Successfully created'), __('Could not be created'), '', true); + if ($id !== false) { $action_select = get_parameter('action_select'); @@ -98,7 +106,8 @@ if ($create_alert) { $values = array(); $values['fires_min'] = get_parameter ('fires_min'); $values['fires_max'] = get_parameter ('fires_max'); - $values['module_action_threshold'] = (int) get_parameter ('module_action_threshold'); + $values['module_action_threshold'] = + (int)get_parameter ('module_action_threshold'); alerts_add_alert_agent_module_action ($id, $action_select, $values); } diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index 27bf54b547..efea920ed0 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -267,8 +267,8 @@ if (check_acl ($config['id_user'], 0, "PM")) { if ($extension['godmode_menu']["fatherId"] == '') { $sub[$extmenu["sec2"]]["text"] = $extmenu["name"]; $sub[$extmenu["sec2"]]["refr"] = 0; - } else { - + } + else { if (array_key_exists('fatherId',$extmenu)) { if (strlen($extmenu['fatherId']) > 0) { $menu_godmode[$extmenu['fatherId']]['sub'][$extmenu['sec2']]["text"] = __($extmenu['name']); @@ -279,7 +279,7 @@ if (check_acl ($config['id_user'], 0, "PM")) { else{ $menu_godmode[$extmenu['fatherId']]['sub'][$extmenu['sec2']]["refr"] = 60; } - } + } $menu_godmode[$extmenu['fatherId']]['sub'][$extmenu['sec2']]["icon"] = $extmenu['icon']; $menu_godmode[$extmenu['fatherId']]['sub'][$extmenu['sec2']]["sec"] = 'gextensions'; $menu_godmode[$extmenu['fatherId']]['sub'][$extmenu['sec2']]["extension"] = true; @@ -290,10 +290,10 @@ if (check_acl ($config['id_user'], 0, "PM")) { } } } - + $menu_godmode["gextensions"]["sub"] = $sub; } } menu_print_menu ($menu_godmode); -?> +?> \ No newline at end of file diff --git a/pandora_console/godmode/snmpconsole/snmp_filters.php b/pandora_console/godmode/snmpconsole/snmp_filters.php index 4d111a76bf..4419120e73 100644 --- a/pandora_console/godmode/snmpconsole/snmp_filters.php +++ b/pandora_console/godmode/snmpconsole/snmp_filters.php @@ -101,13 +101,15 @@ if ($edit_filter > -2) { echo '
'; if ($edit_filter > -1) { html_print_submit_button (__('Update'), 'submit_button', false, 'class="sub upd"'); - } else { + } + else { html_print_submit_button (__('Create'), 'submit_button', false, 'class="sub upd"'); } echo '
'; echo ''; // Overview -} else { +} +else { $result = db_get_all_rows_in_table ("tsnmp_filter"); if ($result === false) { $result = array (); @@ -122,24 +124,24 @@ if ($edit_filter > -2) { $table->width = "98%"; $table->class= "databox"; $table->align = array (); - + $table->head[0] = __('Description'); $table->head[1] = __('Filter'); $table->head[2] = __('Action'); $table->size[2] = "50px"; $table->align[2] = 'center'; - + foreach ($result as $row) { $data = array (); $data[0] = '' . $row['description'] . ''; $data[1] = $row['filter']; $data[2] = '' . - html_print_image("images/config.png", true, array("border" => '0', "alt" => __('Update'))) . '' . - '  ' . - html_print_image("images/cross.png", true, array("border" => '0', "alt" => __('Delete'))) . ''; + html_print_image("images/config.png", true, array("border" => '0', "alt" => __('Update'))) . '' . + '  ' . + html_print_image("images/cross.png", true, array("border" => '0', "alt" => __('Delete'))) . ''; array_push ($table->data, $data); } - + if (!empty ($table->data)) { html_print_table ($table); } @@ -151,5 +153,4 @@ if ($edit_filter > -2) { html_print_submit_button (__('Create'), 'submit_button', false, 'class="sub next"'); echo ''; } - -?> +?> \ No newline at end of file diff --git a/pandora_console/godmode/tag/edit_tag.php b/pandora_console/godmode/tag/edit_tag.php index 858b74d473..a4ded69963 100644 --- a/pandora_console/godmode/tag/edit_tag.php +++ b/pandora_console/godmode/tag/edit_tag.php @@ -66,7 +66,8 @@ if ($update_tag && $id_tag != 0) { if ($result === false) { db_pandora_audit("Tag management", "Fail try to update tag #$id_tag"); echo '

'.__('Error updating tag').'

'; - } else { + } + else { db_pandora_audit("Tag management", "Update tag #$id_tag"); echo '

'.__('Successfully updated tag').'

'; } @@ -74,7 +75,7 @@ if ($update_tag && $id_tag != 0) { // Create tag: creates a new tag if ($create_tag) { - + $return_create = true; // Erase comma characters on tag name @@ -89,13 +90,14 @@ if ($create_tag) { $return_create = false; if ($data['name'] != '') $return_create = tags_create_tag ($data); - + if ($return_create === false) { db_pandora_audit("Tag management", "Fail try to create tag"); echo '

'.__('Error creating tag').'

'; $action = "new"; // If create action ends successfully then current action is update - } else { + } + else { db_pandora_audit("Tag management", "Create tag #$return_create"); echo '

'.__('Successfully created tag').'

'; $id_tag = $return_create; @@ -116,7 +118,7 @@ else { $description_tag = ""; $url_tag = ""; } - + // Create/Update tag form echo '
'; diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 9ffdc9c2f6..fc73aac882 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -270,15 +270,15 @@ function alerts_clone_alert_action ($id_alert_action) { $id_alert_action = safe_int ($id_alert_action, 1); if (empty ($id_alert_action)) return false; - + $action = alerts_get_alert_action($id_alert_action); if (empty ($action)) return false; - - unset($action['id']); - return alerts_create_alert_action ($action['name']." ".__('copy'), $action['id_alert_command'], $action); + unset($action['id']); + + return alerts_create_alert_action ($action['name']." ".__('copy'), $action['id_alert_command'], $action); } /** @@ -323,7 +323,7 @@ function alerts_get_alert_actions ($only_names = true, $acl = false) { * false in case of empty result */ function alerts_get_alert_actions_filter ($only_names = true, $filter = false) { - + if (!$filter) $all_actions = db_get_all_rows_in_table ('talert_actions'); elseif (is_string($filter)) @@ -370,7 +370,8 @@ function alerts_get_alert_action ($id_alert_action) { * false in case of empty result */ function alerts_get_alert_action_alert_command_id ($id_alert_action) { - return db_get_value ('id_alert_command', 'talert_actions', 'id', $id_alert_action); + return db_get_value ('id_alert_command', 'talert_actions', + 'id', $id_alert_action); } /** @@ -383,6 +384,7 @@ function alerts_get_alert_action_alert_command_id ($id_alert_action) { */ function alerts_get_alert_action_alert_command ($id_alert_action) { $id_command = alerts_get_alert_action_alert_command_id ($id_alert_action); + return alerts_get_alert_command ($id_command); } @@ -453,7 +455,7 @@ function alerts_get_alert_templates_types () { $types['unknown'] = __('Unknown status'); $types['onchange'] = __('On Change'); $types['always'] = __('Always'); - + return $types; } @@ -466,8 +468,10 @@ function alerts_get_alert_templates_types () { */ function alerts_get_alert_templates_type_name ($type) { $types = alerts_get_alert_templates_types (); + if (! isset ($type[$type])) return __('Unknown'); + return $types[$type]; } @@ -508,6 +512,7 @@ function alerts_create_alert_template ($name, $type, $values = false) { */ function alerts_update_alert_template ($id_alert_template, $values) { $id_alert_template = safe_int ($id_alert_template, 1); + if (empty ($id_alert_template)) return false; if (! is_array ($values)) @@ -527,6 +532,7 @@ function alerts_update_alert_template ($id_alert_template, $values) { */ function alerts_delete_alert_template ($id_alert_template) { $id_alert_template = safe_int ($id_alert_template, 1); + if (empty ($id_alert_template)) return false; @@ -558,19 +564,25 @@ function alerts_get_alert_template ($id_alert_template) { $id_alert_template = safe_int ($id_alert_template, 1); if (empty ($id_alert_template)) return false; - + switch ($config['dbtype']){ case "mysql": case "postgresql": return db_get_row ('talert_templates', 'id', $id_alert_template); break; case "oracle": - $fields_select = db_get_all_rows_sql('SELECT column_name FROM user_tab_columns WHERE table_name = \'TALERT_TEMPLATES\' AND column_name NOT IN (\'TIME_FROM\',\'TIME_TO\')'); + $fields_select = db_get_all_rows_sql('SELECT column_name + FROM user_tab_columns + WHERE table_name = \'TALERT_TEMPLATES\' + AND column_name NOT IN (\'TIME_FROM\',\'TIME_TO\')'); foreach ($fields_select as $field_select){ - $select_field[] = $field_select['column_name']; + $select_field[] = $field_select['column_name']; } $select_stmt = implode(',', $select_field); - return db_get_row_sql("SELECT $select_stmt, to_char(time_from, 'hh24:mi:ss') as time_from, to_char(time_to, 'hh24:mi:ss') as time_to FROM talert_templates"); + return db_get_row_sql("SELECT $select_stmt, + to_char(time_from, 'hh24:mi:ss') AS time_from, + to_char(time_to, 'hh24:mi:ss') AS time_to + FROM talert_templates"); break; } } @@ -650,6 +662,7 @@ function alerts_get_alert_template_type ($id_alert_template) { */ function alerts_get_alert_template_type_name ($id_alert_template) { $type = alerts_get_alert_template_type ($id_alert_template); + return alerts_get_alert_templates_type_name ($type); } @@ -728,13 +741,16 @@ function alerts_get_alert_template_time_to ($id_alert_template) { */ function alerts_get_alert_template_weekdays ($id_alert_template) { $alert = alerts_get_alert_template ($id_alert_template); + if ($alert === false) return false; + $retval = array (); - $days = array ('monday', 'tuesday', 'wednesday', 'thursday', 'friday', - 'saturday', 'sunday'); + $days = array ('monday', 'tuesday', 'wednesday', 'thursday', + 'friday', 'saturday', 'sunday'); foreach ($days as $day) $retval[$day] = (bool) $alert[$day]; + return $retval; } @@ -780,8 +796,10 @@ function alerts_get_alert_template_field3_recovery ($id_alert_template) { */ function alerts_duplicate_alert_template ($id_alert_template) { $template = alerts_get_alert_template ($id_alert_template); + if ($template === false) return false; + $name = __('Copy of').' '.$template['name']; $type = $template['type']; @@ -849,13 +867,15 @@ function alerts_update_alert_agent_module ($id_alert_agent_module, $values) { function alerts_delete_alert_agent_module ($id_alert_agent_module, $filter = false) { if (empty ($id_alert_agent_module) && ! is_array ($filter)) return false; + if (! is_array ($filter)) $filter = array (); if ($id_alert_agent_module) $filter['id'] = $id_alert_agent_module; if ($id_alert_agent_module !== false) { - $idAlertCompunds = db_get_all_rows_sql('SELECT id_alert_compound + $idAlertCompunds = db_get_all_rows_sql(' + SELECT id_alert_compound FROM talert_compound_elements WHERE id_alert_template_module = ' . $id_alert_agent_module); @@ -865,6 +885,12 @@ function alerts_delete_alert_agent_module ($id_alert_agent_module, $filter = fal } } + /* + The deletion of actions from talert_template_module_actions, + it is automatily because the data base this table have + a foreing key and delete on cascade. + */ + return (@db_process_sql_delete ('talert_template_modules', $filter)) !== false; } @@ -879,6 +905,7 @@ function alerts_delete_alert_agent_module ($id_alert_agent_module, $filter = fal */ function alerts_get_alert_agent_module ($id_alert_agent_module) { $id_alert_agent_module = safe_int ($id_alert_agent_module, 0); + if (empty ($id_alert_agent_module)) return false; @@ -918,13 +945,13 @@ function alerts_get_alerts_agent_module ($id_agent_module, $disabled = false, $f */ function alerts_get_alerts_module_name ($id_agent_module, $disabled = false) { $id_alert_agent_module = safe_int ($id_agent_module, 0); - - $sql = sprintf ('SELECT a.id, b.name - FROM talert_template_modules as a, talert_templates as b - WHERE a.id=b.id AND a.id_agent_module = %d AND a.disabled = %d', - $id_agent_module, (int)$disabled); - return db_process_sql($sql); + $sql = sprintf ('SELECT a.id, b.name + FROM talert_template_modules AS a, talert_templates AS b + WHERE a.id=b.id AND a.id_agent_module = %d AND a.disabled = %d', + $id_agent_module, (int)$disabled); + + return db_process_sql($sql); } @@ -937,6 +964,7 @@ function alerts_get_alerts_module_name ($id_agent_module, $disabled = false) { */ function alerts_get_alert_agent_module_disabled ($id_alert_agent_module) { $id_alert_agent_module = safe_int ($id_alert_agent_module, 0); + return db_get_value ('disabled', 'talert_template_modules', 'id', $id_alert_agent_module); } @@ -950,6 +978,7 @@ function alerts_get_alert_agent_module_disabled ($id_alert_agent_module) { */ function alerts_agent_module_force_execution ($id_alert_agent_module) { $id_alert_agent_module = safe_int ($id_alert_agent_module, 0); + return (@db_process_sql_update ('talert_template_modules', array ('force_execution' => 1), array ('id' => $id_alert_agent_module))) !== false; @@ -965,6 +994,7 @@ function alerts_agent_module_force_execution ($id_alert_agent_module) { */ function alerts_agent_module_disable ($id_alert_agent_module, $disabled) { $id_alert_agent_module = safe_int ($id_alert_agent_module, 0); + return (@db_process_sql_update ('talert_template_modules', array ('disabled' => (bool) $disabled), array ('id' => $id_alert_agent_module))) !== false; @@ -980,6 +1010,7 @@ function alerts_agent_module_disable ($id_alert_agent_module, $disabled) { */ function alerts_agent_module_standby ($id_alert_agent_module, $standby) { $id_alert_agent_module = safe_int ($id_alert_agent_module, 0); + return (@db_process_sql_update ('talert_template_modules', array ('standby' => (bool) $standby), array ('id' => $id_alert_agent_module))) !== false; @@ -994,6 +1025,7 @@ function alerts_agent_module_standby ($id_alert_agent_module, $standby) { */ function alerts_get_alerts_agent_module_last_fired ($id_alert_agent_module) { $id_alert_agent_module = safe_int ($id_alert_agent_module, 1); + return db_get_value ('last_fired', 'talert_template_modules', 'id', $id_alert_agent_module); } @@ -1009,7 +1041,7 @@ function alerts_get_alerts_agent_module_last_fired ($id_alert_agent_module) { */ function alerts_add_alert_agent_module_action ($id_alert_template_module, $id_alert_action, $options = false) { global $config; - + if (empty ($id_alert_template_module)) return false; if (empty ($id_alert_action)) @@ -1029,18 +1061,22 @@ function alerts_add_alert_agent_module_action ($id_alert_template_module, $id_al if (isset ($options['fires_min'])) $min = (int) $options['fires_min']; if (isset ($options['module_action_threshold'])) - $values['module_action_threshold'] = (int) $options['module_action_threshold']; + $values['module_action_threshold'] = + (int) $options['module_action_threshold']; $values['fires_max'] = max ($max, $min); $values['fires_min'] = min ($max, $min); } + switch ($config["dbtype"]) { case "mysql": - case "postgresql": - return (@db_process_sql_insert ('talert_template_module_actions', $values)) !== false; + case "postgresql": + return (@db_process_sql_insert( + 'talert_template_module_actions', $values)) !== false; break; case "oracle": - return (@db_process_sql_insert ('talert_template_module_actions', $values, false)) !== false; + return (@db_process_sql_insert( + 'talert_template_module_actions', $values, false)) !== false; break; } } @@ -1083,6 +1119,7 @@ function alerts_get_alert_agent_module_actions ($id_alert_agent_module, $fields array ('id_alert_template_module' => $id_alert_agent_module), $fields); } + if ($actions === false) return array (); if ($fields !== false) @@ -1112,8 +1149,9 @@ function alerts_get_alert_agent_module_actions ($id_alert_agent_module, $fields */ function alerts_validate_alert_agent_module ($id_alert_agent_module, $noACLs = false) { global $config; + include_once ("include/functions_events.php"); - + $alerts = safe_int ($id_alert_agent_module, 1); if (empty ($alerts)) { @@ -1164,7 +1202,7 @@ function alerts_validate_alert_agent_module ($id_alert_agent_module, $noACLs = f */ function alerts_copy_alert_module_to_module ($id_agent_alert, $id_destiny_module) { global $config; - + $alert = alerts_get_alert_agent_module ($id_agent_alert); if ($alert === false) return false; @@ -1183,15 +1221,19 @@ function alerts_copy_alert_module_to_module ($id_agent_alert, $id_destiny_module switch ($config["dbtype"]) { case "mysql": case "postgresql": - $id_new_alert = @db_process_sql_insert ('talert_template_modules', $new_alert); + $id_new_alert = @db_process_sql_insert ( + 'talert_template_modules', $new_alert); break; case "oracle": - $id_new_alert = @db_process_sql_insert ('talert_template_modules', $new_alert, false); + $id_new_alert = @db_process_sql_insert ( + 'talert_template_modules', $new_alert, false); break; } + if ($id_new_alert === false) { return false; } + $actions = alerts_get_alert_agent_module_actions ($id_agent_alert); if (empty ($actions)) return $id_new_alert; @@ -1227,7 +1269,7 @@ function alerts_compound_threshold_values () { */ function alerts_compound_operations () { $operations = array (); - + $operations['OR'] = 'OR'; $operations['AND'] = 'AND'; $operations['XOR'] = 'XOR'; @@ -1249,7 +1291,7 @@ function alerts_compound_operations () { */ function alerts_create_alert_compound ($name, $id_agent, $values = false) { global $config; - + if (empty ($name)) return false; if (! is_array ($values)) @@ -1257,7 +1299,7 @@ function alerts_create_alert_compound ($name, $id_agent, $values = false) { $values['name'] = $name; $values['id_agent'] = (int) $id_agent; - switch($config['dbtype']){ + switch ($config['dbtype']) { case "oracle": $values['field3_recovery'] = ' '; break; @@ -1276,6 +1318,7 @@ function alerts_create_alert_compound ($name, $id_agent, $values = false) { */ function alerts_update_alert_compound ($id_alert_compound, $values) { $id_alert_compound = safe_int ($id_alert_compound); + if (empty ($id_alert_compound)) return false; if (! is_array ($values)) @@ -1348,7 +1391,7 @@ function alerts_get_alert_compounds ($filter = false, $fields = false) { */ function alerts_get_alert_compound ($id_alert_compound) { global $config; - + switch ($config['dbtype']){ case "mysql": case "postgresql": @@ -1405,7 +1448,8 @@ function alerts_get_alert_compound_actions ($id_alert_compound, $fields = false) * @return Name of the alert compound or false is something goes wrong. */ function alerts_get_alert_compound_name ($id_alert_compound) { - return (string) db_get_value ('name', 'talert_compound', 'id', $id_alert_compound); + return (string) db_get_value ('name', 'talert_compound', 'id', + $id_alert_compound); } /** @@ -1464,7 +1508,7 @@ function alerts_add_alert_compound_action ($id_alert_compound, $id_alert_action, function alerts_delete_alert_compound_action ($id_alert_compound_action) { if (empty ($id_alert_compound_action)) return false; - + return (@db_process_sql_delete ('talert_compound_actions', array ('id' => $id_alert_compound_action))) !== false; } @@ -1540,8 +1584,10 @@ function alerts_validate_alert_compound ($id_alert_compound) { */ function alerts_delete_alert_compound ($id_alert_compound) { $id_alert_compound = safe_int ($id_alert_compound, 1); + if (empty ($id_alert_compound)) return false; + return (@db_process_sql_delete ('talert_compound', array ('id' => $id_alert_compound))) !== false; } @@ -1561,6 +1607,7 @@ function alerts_get_agents_with_alert_template ($id_alert_template, $id_group, $ if (empty ($id_alert_template)) return false; + if (! is_array ($filter)) $filter = array (); $filter[] = 'tagente_modulo.id_agente_modulo = talert_template_modules.id_agent_module'; @@ -1624,15 +1671,16 @@ function get_agent_alert_fired ($id_agent, $id_alert, $period, $date = 0) { if (empty ($date)) { $date = get_system_time (); } - + $datelimit = $date - $period; - + $sql = sprintf ('SELECT timestamp FROM tevento - WHERE id_agente = %d AND utimestamp > %d AND utimestamp <= %d + WHERE id_agente = %d AND utimestamp > %d + AND utimestamp <= %d AND id_alert_am = %d ORDER BY timestamp DESC', $id_agent, $datelimit, $date, $id_alert); - + return db_get_all_rows_sql ($sql); } @@ -1654,15 +1702,16 @@ function get_module_alert_fired ($id_agent_module, $id_alert, $period, $date = 0 if (empty ($date)) { $date = get_system_time (); } - + $datelimit = $date - $period; - + $sql = sprintf ('SELECT timestamp FROM tevento - WHERE id_agentmodule = %d AND utimestamp > %d AND utimestamp <= %d + WHERE id_agentmodule = %d AND utimestamp > %d + AND utimestamp <= %d AND id_alert_am = %d ORDER BY timestamp DESC', $id_agent_module, $datelimit, $date, $id_alert); - + return db_get_all_rows_sql ($sql); } @@ -1680,7 +1729,7 @@ function get_alert_fires_in_period ($id_alert_module, $period, $date = 0) { if (!$date) $date = get_system_time (); - + $datelimit = $date - $period; switch ($config["dbtype"]) { @@ -1719,17 +1768,17 @@ function get_alert_fires_in_period ($id_alert_module, $period, $date = 0) { */ function get_group_alerts ($id_group) { global $config; - + require_once ($config["homedir"].'/include/functions_agents.php'); - + $alerts = array (); $agents = agents_get_group_agents ($id_group, false, "none"); - + foreach ($agents as $agent_id => $agent_name) { $agent_alerts = agents_get_alerts ($agent_id); $alerts = array_merge ($alerts, $agent_alerts); } - + return $alerts; } @@ -1745,12 +1794,13 @@ function get_group_alerts ($id_group) { */ function get_alerts_fired ($alerts, $period = 0, $date = 0) { if (! $date) - $date = get_system_time (); + $date = get_system_time (); + $datelimit = $date - $period; - + $alerts_fired = array (); $agents = array (); - + foreach ($alerts as $alert) { if (isset($alert['id'])) { $fires = get_alert_fires_in_period ($alert['id'], $period, $date); @@ -1760,6 +1810,7 @@ function get_alerts_fired ($alerts, $period = 0, $date = 0) { $alerts_fired[$alert['id']] = $fires; } } + return $alerts_fired; } @@ -1774,7 +1825,7 @@ function get_alerts_fired ($alerts, $period = 0, $date = 0) { */ function get_alert_last_fire_timestamp_in_period ($id_alert_module, $period, $date = 0) { global $config; - + if ($date == 0) { $date = get_system_time (); } @@ -1819,11 +1870,12 @@ function alerts_create_alert_special_day ($date, $same_day, $values = false) { return false; if (empty ($same_day)) return false; + if (! is_array ($values)) $values = array (); $values['date'] = $date; $values['same_day'] = $same_day; - + return @db_process_sql_insert ('talert_special_days', $values); } @@ -1837,11 +1889,12 @@ function alerts_create_alert_special_day ($date, $same_day, $values = false) { */ function alerts_update_alert_special_day ($id_special_day, $values) { $id_special_day = safe_int ($id_special_day, 1); + if (empty ($id_special_day)) return false; if (! is_array ($values)) return false; - + return (@db_process_sql_update ('talert_special_days', $values, array ('id' => $id_special_day))) !== false; @@ -1856,9 +1909,10 @@ function alerts_update_alert_special_day ($id_special_day, $values) { */ function alerts_delete_alert_special_day ($id_special_day) { $id_special_day = safe_int ($id_special_day, 1); + if (empty ($id_special_day)) return false; - + return (@db_process_sql_delete ('talert_special_days', array ('id' => $id_special_day))) !== false; } @@ -1872,10 +1926,10 @@ function alerts_delete_alert_special_day ($id_special_day) { */ function alerts_get_alert_special_day ($id_special_day) { $id_special_day = safe_int ($id_special_day, 1); + if (empty ($id_special_day)) return false; - + return db_get_row ('talert_special_days', 'id', $id_special_day); } - -?> +?> \ No newline at end of file diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index f098fc84af..ba53f47db0 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -116,7 +116,8 @@ function html_print_select_style ($fields, $name, $selected = '', $style='', $sc //If duplicate names exist, it will start numbering. Otherwise it won't if (isset ($idcounter[$name])) { $idcounter[$name]++; - } else { + } + else { $idcounter[$name] = 0; } @@ -881,7 +882,8 @@ function html_print_table (&$table, $return = false) { foreach ($table->valign as $key => $aa) { if ($aa) { $valign[$key] = ' vertical-align:'. $aa.';'; - } else { + } + else { $valign[$key] = ''; } } @@ -1309,9 +1311,7 @@ function html_print_image ($src, $return = false, $options = false, $return_src if (!isset ($options["alt"]) && isset ($options["title"])) { $options["alt"] = io_safe_input_html($options["title"]); //Set alt to title if it's not set - }// elseif (!isset ($options["alt"])) { - // $options["alt"] = ""; - //} + } if (!empty ($style)) { $output .= 'style="'.$style.'" '; @@ -1548,4 +1548,4 @@ function html_print_autocomplete_modules($name = 'module', $default = '', $id_ag echo $output; } } -?> +?> \ No newline at end of file diff --git a/pandora_console/index.php b/pandora_console/index.php index 44e3be33d2..d3e8485a06 100644 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -297,7 +297,8 @@ elseif (! isset ($config['id_user']) && isset ($_GET["login"])) { db_pandora_audit("Logon Failed", "Invalid login: ".$nick, $nick); while (@ob_end_flush ()); exit (""); - } else { + } + else { require_once ('general/login_page.php'); db_pandora_audit("Logon Failed", "Invalid login: ".$nick, $nick); while (@ob_end_flush ()); @@ -502,7 +503,8 @@ else { if (!file_exists ($file)) { unset($_GET['sec2']); require('general/logon_ok.php'); - } else { + } + else { require($file); } } diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index c0faaf23e1..707cc60656 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -17,117 +17,134 @@ -- PLEASE NO NOT USE MULTILINE COMMENTS -- Because Pandora Installer don't understand them -- and fails creating database !!! --- ----------------------------------------------------------- --- Pandora FMS official tables for 3.2 version -- --- ----------------------------------------------------------- +-- ----------------------------------------------------- +-- Table `taddress` +-- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `taddress` ( - `id_a` int(10) unsigned NOT NULL auto_increment, - `ip` varchar(60) NOT NULL default '', - `ip_pack` int(10) unsigned NOT NULL default '0', - PRIMARY KEY (`id_a`), - KEY `ip` (`ip`) + `id_a` int(10) unsigned NOT NULL auto_increment, + `ip` varchar(60) NOT NULL default '', + `ip_pack` int(10) unsigned NOT NULL default '0', + PRIMARY KEY (`id_a`), + KEY `ip` (`ip`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - +-- ----------------------------------------------------- +-- Table `taddress_agent` +-- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `taddress_agent` ( - `id_ag` bigint(20) unsigned NOT NULL auto_increment, - `id_a` bigint(20) unsigned NOT NULL default '0', - `id_agent` mediumint(8) unsigned NOT NULL default '0', - PRIMARY KEY (`id_ag`) + `id_ag` bigint(20) unsigned NOT NULL auto_increment, + `id_a` bigint(20) unsigned NOT NULL default '0', + `id_agent` mediumint(8) unsigned NOT NULL default '0', + PRIMARY KEY (`id_ag`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - +-- ----------------------------------------------------- +-- Table `tagente` +-- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `tagente` ( - `id_agente` int(10) unsigned NOT NULL auto_increment, - `nombre` varchar(600) BINARY NOT NULL default '', - `direccion` varchar(100) default NULL, - `comentarios` varchar(255) default '', - `id_grupo` int(10) unsigned NOT NULL default '0', - `ultimo_contacto` datetime NOT NULL default '1970-01-01 00:00:00', - `modo` tinyint(1) NOT NULL default '0', - `intervalo` int(11) unsigned NOT NULL default '300', - `id_os` int(10) unsigned default '0', - `os_version` varchar(100) default '', - `agent_version` varchar(100) default '', - `ultimo_contacto_remoto` datetime default '1970-01-01 00:00:00', - `disabled` tinyint(2) NOT NULL default '0', - `id_parent` int(10) unsigned default '0', - `custom_id` varchar(255) default '', - `server_name` varchar(100) default '', - `cascade_protection` tinyint(2) NOT NULL default '0', - `timezone_offset` TINYINT(2) NULL DEFAULT '0' COMMENT 'nuber of hours of diference with the server timezone' , - `icon_path` VARCHAR(127) NULL DEFAULT NULL COMMENT 'path in the server to the image of the icon representing the agent' , - `update_gis_data` TINYINT(1) NOT NULL DEFAULT '1' COMMENT 'set it to one to update the position data (altitude, longitude, latitude) when getting information from the agent or to 0 to keep the last value and don\'t update it' , - `url_address` mediumtext NULL, - PRIMARY KEY (`id_agente`), - KEY `nombre` (`nombre`), - KEY `direccion` (`direccion`), - KEY `disabled` (`disabled`), - KEY `id_grupo` (`id_grupo`) + `id_agente` int(10) unsigned NOT NULL auto_increment, + `nombre` varchar(600) BINARY NOT NULL default '', + `direccion` varchar(100) default NULL, + `comentarios` varchar(255) default '', + `id_grupo` int(10) unsigned NOT NULL default '0', + `ultimo_contacto` datetime NOT NULL default '1970-01-01 00:00:00', + `modo` tinyint(1) NOT NULL default '0', + `intervalo` int(11) unsigned NOT NULL default '300', + `id_os` int(10) unsigned default '0', + `os_version` varchar(100) default '', + `agent_version` varchar(100) default '', + `ultimo_contacto_remoto` datetime default '1970-01-01 00:00:00', + `disabled` tinyint(2) NOT NULL default '0', + `id_parent` int(10) unsigned default '0', + `custom_id` varchar(255) default '', + `server_name` varchar(100) default '', + `cascade_protection` tinyint(2) NOT NULL default '0', + `timezone_offset` TINYINT(2) NULL DEFAULT '0' COMMENT 'nuber of hours of diference with the server timezone' , + `icon_path` VARCHAR(127) NULL DEFAULT NULL COMMENT 'path in the server to the image of the icon representing the agent' , + `update_gis_data` TINYINT(1) NOT NULL DEFAULT '1' COMMENT 'set it to one to update the position data (altitude, longitude, latitude) when getting information from the agent or to 0 to keep the last value and do not update it' , + `url_address` mediumtext NULL, + PRIMARY KEY (`id_agente`), + KEY `nombre` (`nombre`), + KEY `direccion` (`direccion`), + KEY `disabled` (`disabled`), + KEY `id_grupo` (`id_grupo`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; +-- ----------------------------------------------------- +-- Table `tagente_datos` +-- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `tagente_datos` ( - `id_agente_modulo` int(10) unsigned NOT NULL default '0', - `datos` double(18,2) default NULL, - `utimestamp` bigint(20) default '0', - KEY `data_index1` (`id_agente_modulo`), - KEY `idx_utimestamp` USING BTREE (`utimestamp`) + `id_agente_modulo` int(10) unsigned NOT NULL default '0', + `datos` double(18,2) default NULL, + `utimestamp` bigint(20) default '0', + KEY `data_index1` (`id_agente_modulo`), + KEY `idx_utimestamp` USING BTREE (`utimestamp`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; +-- ----------------------------------------------------- +-- Table `tagente_datos_inc` +-- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `tagente_datos_inc` ( - `id_adi` int(10) unsigned NOT NULL auto_increment, - `id_agente_modulo` int(10) unsigned NOT NULL default '0', - `datos` double(18,2) default NULL, - `utimestamp` int(20) unsigned default '0', - PRIMARY KEY (`id_adi`), - KEY `data_inc_index_1` (`id_agente_modulo`) + `id_adi` int(10) unsigned NOT NULL auto_increment, + `id_agente_modulo` int(10) unsigned NOT NULL default '0', + `datos` double(18,2) default NULL, + `utimestamp` int(20) unsigned default '0', + PRIMARY KEY (`id_adi`), + KEY `data_inc_index_1` (`id_agente_modulo`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - +-- ----------------------------------------------------- +-- Table `tagente_datos_string` +-- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `tagente_datos_string` ( - `id_agente_modulo` int(10) unsigned NOT NULL default '0', - `datos` text NOT NULL, - `utimestamp` int(20) unsigned NOT NULL default 0, - KEY `data_string_index_1` (`id_agente_modulo`), - KEY `idx_utimestamp` USING BTREE (`utimestamp`) + `id_agente_modulo` int(10) unsigned NOT NULL default '0', + `datos` text NOT NULL, + `utimestamp` int(20) unsigned NOT NULL default 0, + KEY `data_string_index_1` (`id_agente_modulo`), + KEY `idx_utimestamp` USING BTREE (`utimestamp`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- ----------------------------------------------------- +-- Table `tagente_datos_log4x` +-- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `tagente_datos_log4x` ( - `id_tagente_datos_log4x` bigint(20) unsigned NOT NULL auto_increment, - `id_agente_modulo` int(10) unsigned NOT NULL default '0', - - `severity` text NOT NULL, - `message` text NOT NULL, - `stacktrace` text NOT NULL, - - `utimestamp` int(20) unsigned NOT NULL default 0, - PRIMARY KEY (`id_tagente_datos_log4x`), - KEY `data_log4x_index_1` (`id_agente_modulo`) + `id_tagente_datos_log4x` bigint(20) unsigned NOT NULL auto_increment, + `id_agente_modulo` int(10) unsigned NOT NULL default '0', + + `severity` text NOT NULL, + `message` text NOT NULL, + `stacktrace` text NOT NULL, + + `utimestamp` int(20) unsigned NOT NULL default 0, + PRIMARY KEY (`id_tagente_datos_log4x`), + KEY `data_log4x_index_1` (`id_agente_modulo`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- delete "cambio" not used anymore +-- ----------------------------------------------------- +-- Table `tagente_estado` +-- ----------------------------------------------------- CREATE TABLE `tagente_estado` ( - `id_agente_estado` int(10) unsigned NOT NULL auto_increment, - `id_agente_modulo` int(10) NOT NULL default '0', - `datos` text NOT NULL, - `timestamp` datetime NOT NULL default '1970-01-01 00:00:00', - `estado` int(4) NOT NULL default '0', - `id_agente` int(10) NOT NULL default '0', - `last_try` datetime default NULL, - `utimestamp` bigint(20) NOT NULL default '0', - `current_interval` int(8) unsigned NOT NULL default '0', - `running_by` smallint(4) unsigned default '0', - `last_execution_try` bigint(20) NOT NULL default '0', - `status_changes` tinyint(4) default 0, - `last_status` tinyint(4) default 0, - PRIMARY KEY (`id_agente_estado`), - KEY `status_index_1` (`id_agente_modulo`), - KEY `idx_agente` (`id_agente`), - KEY `idx_status` (`estado`), - KEY `current_interval` (`current_interval`), - KEY `running_by` (`running_by`), - KEY `last_execution_try` (`last_execution_try`) + `id_agente_estado` int(10) unsigned NOT NULL auto_increment, + `id_agente_modulo` int(10) NOT NULL default '0', + `datos` text NOT NULL, + `timestamp` datetime NOT NULL default '1970-01-01 00:00:00', + `estado` int(4) NOT NULL default '0', + `id_agente` int(10) NOT NULL default '0', + `last_try` datetime default NULL, + `utimestamp` bigint(20) NOT NULL default '0', + `current_interval` int(8) unsigned NOT NULL default '0', + `running_by` smallint(4) unsigned default '0', + `last_execution_try` bigint(20) NOT NULL default '0', + `status_changes` tinyint(4) default 0, + `last_status` tinyint(4) default 0, + PRIMARY KEY (`id_agente_estado`), + KEY `status_index_1` (`id_agente_modulo`), + KEY `idx_agente` (`id_agente`), + KEY `idx_status` (`estado`), + KEY `current_interval` (`current_interval`), + KEY `running_by` (`running_by`), + KEY `last_execution_try` (`last_execution_try`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- Probably last_execution_try index is not useful and loads more than benefits @@ -849,7 +866,7 @@ CREATE TABLE IF NOT EXISTS `treport` ( `first_page` MEDIUMTEXT, `footer` MEDIUMTEXT, `custom_font` varchar(200) default NULL, - `id_template` INTEGER UNSIGNED DEFAULT 0, + `id_template` INTEGER UNSIGNED DEFAULT 0, PRIMARY KEY(`id_report`) ) ENGINE = InnoDB DEFAULT CHARSET=utf8;