From a9c29eb4748900095f6e3cdc893f009cb616e0c0 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Mon, 4 Mar 2013 14:41:26 +0000 Subject: [PATCH] 2013-03-04 Miguel de Dios * godmode/setup/setup_netflow.php, include/help/ja/help_snmp_trap_types.php, include/functions_extensions.php, include/functions_snmp_browser.php, include/functions_events.php, include/functions_api.php: improved the code style. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7772 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 8 + .../godmode/setup/setup_netflow.php | 2 +- pandora_console/include/functions_api.php | 232 ++++++++++-------- pandora_console/include/functions_events.php | 2 +- .../include/functions_extensions.php | 9 +- .../include/functions_snmp_browser.php | 16 +- .../include/help/ja/help_snmp_trap_types.php | 14 +- 7 files changed, 161 insertions(+), 122 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index d8ad5027d9..4362d773db 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2013-03-04 Miguel de Dios + + * godmode/setup/setup_netflow.php, + include/help/ja/help_snmp_trap_types.php, + include/functions_extensions.php, + include/functions_snmp_browser.php, include/functions_events.php, + include/functions_api.php: improved the code style. + 2013-03-04 Miguel de Dios * godmode/reporting/reporting_builder.item_editor.php, diff --git a/pandora_console/godmode/setup/setup_netflow.php b/pandora_console/godmode/setup/setup_netflow.php index 62f281025a..39b4cc75c5 100644 --- a/pandora_console/godmode/setup/setup_netflow.php +++ b/pandora_console/godmode/setup/setup_netflow.php @@ -59,7 +59,7 @@ $table->data[6][1] = __('Yes').'   '.html_print_radio_button ('ne $table->data[6][1] .= __('No').'   '.html_print_radio_button ('netflow_disable_custom_lvfilters', 0, '', $config["netflow_disable_custom_lvfilters"], true).'  '; $table->data[7][0] = '' . __('Netflow max lifetime') . ''.ui_print_help_tip (__("Sets the maximum lifetime for netflow data in days."), true); $table->data[7][1] = html_print_input_text ('netflow_max_lifetime', $config['netflow_max_lifetime'], false, 50, 200, true); - + echo '
'; html_print_table ($table); diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index f9da675aa8..c73ed716ed 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -770,35 +770,39 @@ function api_set_new_agent($thrash1, $thrash2, $other, $thrash3) { * @param boolean $display_front Flag to display custom field in agent's operation view */ function api_set_create_custom_field($t1, $t2, $other, $returnType) { - - if ($other['type'] == 'string') { - returnError('error_parameter', 'Error in the parameters.'); - return; - } else if ($other['type'] == 'array') { - - $name = ""; - - if ($other['data'][0] != '') { - $name = $other['data'][0]; - } else { - returnError('error_parameter', 'Custom field name required'); - return; - } - - $display_front = 0; - - if ($other['data'][1] != '') { - $display_front = $other['data'][1]; - } else { - returnError('error_parameter', 'Custom field display flag required'); - return; - } - $result = db_process_sql_insert('tagent_custom_fields', array('name' => $name, 'display_on_front' => $display_front)); - - $data['type'] = "string"; - $data["data"] = $result; - returnData("string", $data); + if ($other['type'] == 'string') { + returnError('error_parameter', 'Error in the parameters.'); + return; + } + else if ($other['type'] == 'array') { + + $name = ""; + + if ($other['data'][0] != '') { + $name = $other['data'][0]; + } + else { + returnError('error_parameter', 'Custom field name required'); + return; + } + + $display_front = 0; + + if ($other['data'][1] != '') { + $display_front = $other['data'][1]; + } + else { + returnError('error_parameter', 'Custom field display flag required'); + return; + } + + $result = db_process_sql_insert('tagent_custom_fields', + array('name' => $name, 'display_on_front' => $display_front)); + + $data['type'] = "string"; + $data["data"] = $result; + returnData("string", $data); } } @@ -5372,10 +5376,10 @@ function api_set_new_note_incident($id, $id2, $other, $thrash2) { function api_set_disable_module ($agent_name, $module_name, $thrast3, $thrash4) { $id_agent = agents_get_agent_id($agent_name); $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', array('id_agente' => $id_agent, 'nombre' => $module_name)); - - $result = modules_change_disabled($id_agent_module, 1); - - if($result === NOERR) { + + $result = modules_change_disabled($id_agent_module, 1); + + if ($result === NOERR) { returnData('string', array('type' => 'string', 'data' => __('Correct module disable'))); } else { @@ -5396,10 +5400,10 @@ function api_set_disable_module ($agent_name, $module_name, $thrast3, $thrash4) function api_set_enable_module ($agent_name, $module_name, $thrast3, $thrash4) { $id_agent = agents_get_agent_id($agent_name); $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', array('id_agente' => $id_agent, 'nombre' => $module_name)); - - $result = modules_change_disabled($id_agent_module, 1); - - if($result === NOERR) { + + $result = modules_change_disabled($id_agent_module, 1); + + if ($result === NOERR) { returnData('string', array('type' => 'string', 'data' => __('Correct module enable'))); } else { @@ -5420,12 +5424,15 @@ function api_set_enable_module ($agent_name, $module_name, $thrast3, $thrash4) { */ function api_set_disable_alert ($agent_name, $module_name, $template_name, $thrash4) { - + $id_agent = agents_get_agent_id($agent_name); $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', array('id_agente' => $id_agent, 'nombre' => $module_name)); - $id_template = db_get_value_filter('id', 'talert_templates', array('name' => $template_name["data"])); - - db_process_sql("UPDATE talert_template_modules SET disabled = 1 WHERE id_agent_module = $id_agent_module AND id_alert_template = $id_template"); + $id_template = db_get_value_filter('id', 'talert_templates', array('name' => $template_name["data"])); + + db_process_sql("UPDATE talert_template_modules + SET disabled = 1 + WHERE id_agent_module = $id_agent_module AND id_alert_template = $id_template"); + returnData('string', array('type' => 'string', 'data' => "Correct alert disable")); } @@ -5441,12 +5448,15 @@ function api_set_disable_alert ($agent_name, $module_name, $template_name, $thra */ function api_set_enable_alert ($agent_name, $module_name, $template_name, $thrash4) { - + $id_agent = agents_get_agent_id($agent_name); $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', array('id_agente' => $id_agent, 'nombre' => $module_name)); - $id_template = db_get_value_filter('id', 'talert_templates', array('name' => $template_name["data"])); - - db_process_sql("UPDATE talert_template_modules SET disabled = 0 WHERE id_agent_module = $id_agent_module AND id_alert_template = $id_template"); + $id_template = db_get_value_filter('id', 'talert_templates', array('name' => $template_name["data"])); + + db_process_sql("UPDATE talert_template_modules + SET disabled = 0 + WHERE id_agent_module = $id_agent_module AND id_alert_template = $id_template"); + returnData('string', array('type' => 'string', 'data' => "Correct alert enable")); } @@ -5462,11 +5472,14 @@ function api_set_enable_alert ($agent_name, $module_name, $template_name, $thras */ function api_set_disable_module_alerts ($agent_name, $module_name, $thrash3, $thrash4) { - + $id_agent = agents_get_agent_id($agent_name); $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', array('id_agente' => $id_agent, 'nombre' => $module_name)); - - db_process_sql("UPDATE talert_template_modules SET disabled = 1 WHERE id_agent_module = $id_agent_module"); + + db_process_sql("UPDATE talert_template_modules + SET disabled = 1 + WHERE id_agent_module = $id_agent_module"); + returnData('string', array('type' => 'string', 'data' => "Correct alerts disable")); } @@ -5482,11 +5495,14 @@ function api_set_disable_module_alerts ($agent_name, $module_name, $thrash3, $th */ function api_set_enable_module_alerts ($agent_name, $module_name, $thrash3, $thrash4) { - + $id_agent = agents_get_agent_id($agent_name); $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', array('id_agente' => $id_agent, 'nombre' => $module_name)); - - db_process_sql("UPDATE talert_template_modules SET disabled = 0 WHERE id_agent_module = $id_agent_module"); + + db_process_sql("UPDATE talert_template_modules + SET disabled = 0 + WHERE id_agent_module = $id_agent_module"); + returnData('string', array('type' => 'string', 'data' => "Correct alerts enable")); } @@ -5525,12 +5541,13 @@ function get_tags($thrash1, $thrash2, $other, $returnType, $user_in_db) { **/ // http://localhost/pandora_console/include/api.php?op=get&op2=total_modules&id=1&apipass=1234&user=admin&pass=pandora function api_get_total_modules($id_group, $trash1, $trash2, $returnType) { - - $sql = "SELECT COUNT(*) FROM tagente_modulo - WHERE id_module_group=$id_group"; - + + $sql = "SELECT COUNT(*) + FROM tagente_modulo + WHERE id_module_group=$id_group"; + $total = db_get_value_sql($sql); - + $data = array('type' => 'string', 'data' => $total); returnData($returnType, $data); @@ -5544,10 +5561,12 @@ function api_get_total_modules($id_group, $trash1, $trash2, $returnType) { **/ // http://localhost/pandora_console/include/api.php?op=get&op2=total_agents&id=2&apipass=1234&user=admin&pass=pandora function api_get_total_agents($id_group, $trash1, $trash2, $returnType) { - - $sql = sprintf('SELECT COUNT(*) FROM tagente WHERE id_grupo=%d AND disabled=0', $id_group); + + $sql = sprintf('SELECT COUNT(*) + FROM tagente + WHERE id_grupo=%d AND disabled=0', $id_group); $total_agents = db_get_value_sql($sql); - + $data = array('type' => 'string', 'data' => $total_agents); returnData($returnType, $data); } @@ -5561,14 +5580,16 @@ function api_get_total_agents($id_group, $trash1, $trash2, $returnType) { // http://localhost/pandora_console/include/api.php?op=get&op2=agent_name&id=1&apipass=1234&user=admin&pass=pandora function api_get_agent_name($id_agent, $trash1, $trash2, $returnType) { - $sql = sprintf('SELECT nombre FROM tagente WHERE id_agente = %d', $id_agent); - $value = db_get_value_sql($sql); + $sql = sprintf('SELECT nombre + FROM tagente + WHERE id_agente = %d', $id_agent); + $value = db_get_value_sql($sql); if ($value === false) { returnError('id_not_found', $returnType); } $data = array('type' => 'string', 'data' => $value); - + returnData($returnType, $data); } @@ -5594,14 +5615,16 @@ function api_get_module_name($id_module, $trash1, $trash2, $returnType) { // http://localhost/pandora_console/include/api.php?op=get&op2=alert_action_by_group&id=3&id2=1&apipass=1234&user=admin&pass=pandora function api_get_alert_action_by_group($id_group, $id_action, $trash2, $returnType) { - - $sql = "SELECT SUM(internal_counter) FROM talert_template_modules - WHERE id_alert_template IN - (SELECT id FROM talert_templates - WHERE id_group=$id_group AND id_alert_action = $id_action)"; - + + $sql = "SELECT SUM(internal_counter) + FROM talert_template_modules + WHERE id_alert_template IN + (SELECT id + FROM talert_templates + WHERE id_group=$id_group AND id_alert_action = $id_action)"; + $value = db_get_value_sql($sql); - + if ($value === false) { returnError('data_not_found', $returnType); } @@ -5616,25 +5639,19 @@ function api_get_alert_action_by_group($id_group, $id_action, $trash2, $returnTy // http://localhost/pandora_console/include/api.php?op=get&op2=event_info&id=58&apipass=1234&user=admin&pass=pandora function api_get_event_info($id_event, $trash1, $trash, $returnType) { - + $sql = "SELECT * FROM tevento WHERE id_evento=$id_event"; $event_data = db_get_row_sql($sql); $i = 0; foreach ($event_data as $key => $data) { -/* - if ($i == 0) - $result = $data; - else - $result .= ';'.$data; -*/ if ($i == 0) $result = $key.': '.$data.'
'; else $result .= $key.': '.$data.'
'; $i++; } - + $data = array('type' => 'string', 'data' => $result); returnData($returnType, $data); @@ -5643,7 +5660,7 @@ function api_get_event_info($id_event, $trash1, $trash, $returnType) { //http://127.0.0.1/pandora_console/include/api.php?op=set&op2=create_event&id=name_event&other=2|system|3|admin|2|1|10|0|comments||Pandora||critical_inst|warning_inst|unknown_inst|other&other_mode=url_encode_separator_|&apipass=1234&user=admin&pass=pandora function api_set_create_event($id, $trash1, $other, $returnType) { - + if ($other['type'] == 'string') { returnError('error_parameter', 'Error in the parameters.'); return; @@ -5651,87 +5668,100 @@ function api_set_create_event($id, $trash1, $other, $returnType) { else if ($other['type'] == 'array') { $values = array(); - + if ($other['data'][0] != '') { - $values['event'] = $other['data'][0]; - } else { - returnError('error_parameter', 'Event text required.'); - return; + $values['event'] = $other['data'][0]; + } + else { + returnError('error_parameter', 'Event text required.'); + return; } if ($other['data'][1] != '') { $values['id_grupo'] = $other['data'][1]; - } else { + } + else { returnError('error_parameter', 'Group ID required.'); return; } - + if ($other['data'][2] != '') { $values['id_agente'] = $other['data'][2]; - } else { - returnError('error_parameter', 'Agent ID required.'); - return; - } + } + else { + returnError('error_parameter', 'Agent ID required.'); + return; + } if ($other['data'][3] != '') { $values['status'] = $other['data'][3]; - } else { + } + else { $values['status'] = 0; - } + } - $values['id_usuario'] = $other['data'][4]; + $values['id_usuario'] = $other['data'][4]; if ($other['data'][5] != '') { $values['event_type'] = $other['data'][5]; - } else { + } + else { $values['event_type'] = "unknown"; } if ($other['data'][6] != '') { $values['priority'] = $other['data'][6]; - } else { + } + else { $values['priority'] = 0; } if ($other['data'][7] != '') { $values['id_agentmodule'] = $other['data'][7]; - } else { + } + else { $value['id_agentemodule'] = 0; } if ($other['data'][8] != '') { $values['id_alert_am'] = $other['data'][8]; - } else { + } + else { $values['id_alert_am'] = 0; } if ($other['data'][9] != '') { $values['critical_instructions'] = $other['data'][9]; - } else { + } + else { $values['critical_instructions'] = ''; } if ($other['data'][10] != '') { $values['warning_instructions'] = $other['data'][10]; - } else { + } + else { $values['warning_instructions'] = ''; } if ($other['data'][11] != '') { $values['unknown_instructions'] = $other['data'][11]; - } else { + } + else { $values['unknown_instructions'] = ''; } if ($other['data'][14] != '') { $values['source'] = $other['data'][14]; - } else { + } + else { $values['source'] = "Pandora"; } if ($other['data'][15] != '') { $values['tags'] = $other['data'][15]; - } else { + } + else { $values['tags'] = ""; } @@ -5740,7 +5770,7 @@ function api_set_create_event($id, $trash1, $other, $returnType) { $values['priority'], $value['id_agentemodule'], $values['id_alert_am'], $values['critical_instructions'], $values['warning_instructions'], $values['unknown_instructions'], $values['source'], $values['tags']); - + if ($other['data'][12] != '') { //user comments if ($return !== false) { //event successfully created $user_comment = $other['data'][12]; diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index aa4d8b1afd..12cb18fbf6 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -2204,7 +2204,7 @@ function events_page_comments ($event) { $table_comments->data[] = $data; } - if (tags_check_acl ($config['id_user'], $event['id_grupo'], "EW", $event['clean_tags']) || tags_check_acl ($config['id_user'], $event['id_grupo'], "EM", $event['clean_tags'])) { + if (tags_check_acl ($config['id_user'], $event['id_grupo'], "EW", $event['clean_tags']) || tags_check_acl ($config['id_user'], $event['id_grupo'], "EM", $event['clean_tags'])) { $comments_form = '
'.html_print_textarea("comment", 3, 10, '', 'style="min-height: 15px; width: 100%;"', true); $comments_form .= '
'.html_print_button(__('Add comment'),'comment_button',false,'event_comment();','class="sub next"',true).'

'; } diff --git a/pandora_console/include/functions_extensions.php b/pandora_console/include/functions_extensions.php index cbc7e872e5..80e0f0c3b6 100644 --- a/pandora_console/include/functions_extensions.php +++ b/pandora_console/include/functions_extensions.php @@ -329,9 +329,10 @@ function extensions_add_godmode_menu_option ($name, $acl, $fatherId = null, $ico global $config; global $extension_file; - /* $config['extension_file'] is set in extensions_load_extensions(), since that function must - be called before any function the extension call, we are sure it will - be set. */ + /* + $config['extension_file'] is set in extensions_load_extensions(), + since that function must be called before any function the extension + call, we are sure it will be set. */ $option_menu['acl'] = $acl; $option_menu['name'] = $name; $extension = &$config['extensions'][$extension_file]; @@ -381,7 +382,7 @@ function extensions_add_opemode_tab_agent($tabId, $tabName, $tabIcon, $tabFuncti $extension['extension_ope_tab']['name'] = $tabName; $extension['extension_ope_tab']['icon'] = $tabIcon; $extension['extension_ope_tab']['function'] = $tabFunction; - $extension['extension_ope_tab']['version'] = $version; + $extension['extension_ope_tab']['version'] = $version; } /** diff --git a/pandora_console/include/functions_snmp_browser.php b/pandora_console/include/functions_snmp_browser.php index 118f547656..06e3652583 100644 --- a/pandora_console/include/functions_snmp_browser.php +++ b/pandora_console/include/functions_snmp_browser.php @@ -369,12 +369,12 @@ function snmp_browser_print_oid ($oid = array(), $custom_action = '', $return = * */ function snmp_browser_print_container ($return = false, $width = '95%', $height = '500px', $display = '') { - + // Target selection $table->width = '100%'; $table->size = array (); $table->data = array (); - + // String search_string $table->data[0][0] = ''.__('Target IP').''; $table->data[0][1] = html_print_input_text ('target_ip', '', '', 25, 0, true); @@ -391,7 +391,7 @@ function snmp_browser_print_container ($return = false, $width = '95%', $height $table->data[1][4] .= ' ' . '' . html_print_image ("images/go_previous.png", true, array ('title' => __('Previous match'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchPrevMatch();')) . ''; $table->data[1][4] .= ' ' . '' . html_print_image ("images/go_next.png", true, array ('title' => __('Next match'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchNextMatch();')) . ''; $table->data[1][4] .= ' ' . '' . html_print_image ("images/go_last.png", true, array ('title' => __('Last match'), 'style' => 'vertical-align: middle;', 'onclick' => 'searchLastMatch();')) . ''; - + // This extra div that can be handled by jquery's dialog $output = '
'; $output .= '
'; @@ -401,16 +401,16 @@ function snmp_browser_print_container ($return = false, $width = '95%', $height $output .= '
'; $output .= html_print_button(__('Browse'), 'browse', false, 'snmpBrowse()', 'class="sub upd"', true); $output .= '
'; - + // SNMP tree container $output .= '
'; - $output .= html_print_input_hidden ('search_count', 0, true); - $output .= html_print_input_hidden ('search_index', -1, true); - + $output .= html_print_input_hidden ('search_count', 0, true); + $output .= html_print_input_hidden ('search_index', -1, true); + // Save some variables for javascript functions $output .= html_print_input_hidden ('ajax_url', ui_get_full_url("ajax.php"), true); $output .= html_print_input_hidden ('search_matches_translation', __("Search matches"), true); - + $output .= ''; $output .= ''; $output .= '
'; diff --git a/pandora_console/include/help/ja/help_snmp_trap_types.php b/pandora_console/include/help/ja/help_snmp_trap_types.php index d011203a70..c85854926e 100755 --- a/pandora_console/include/help/ja/help_snmp_trap_types.php +++ b/pandora_console/include/help/ja/help_snmp_trap_types.php @@ -5,11 +5,11 @@ ?>

トラップのタイプ

    -
  • Cold start (0): エージェントが(再)起動したことを示します。
  • -
  • Warm start (1): エージェントの設定が変更されたことを示します。
  • -
  • Link down (2): ネットワークインタフェースがダウンしたことを示します。
  • -
  • Link up (3): ネットワークインタフェースがアップしたことを示します。
  • -
  • Authentication failure (4): エージェントが許可されていない発信元からのリクエストを受けたことを示します。(通常はコミュニティで制限されています)
  • -
  • EGP neighbor loss (5): EGP プロトコルを利用しているルータで、隣接ホストとの通信が切れたことを示します。
  • -
  • Enterprise (6): このカテゴリに含まれるものは、ベンダー独自のトラップです。
  • +
  • Cold start (0): エージェントが(再)起動したことを示します。
  • +
  • Warm start (1): エージェントの設定が変更されたことを示します。
  • +
  • Link down (2): ネットワークインタフェースがダウンしたことを示します。
  • +
  • Link up (3): ネットワークインタフェースがアップしたことを示します。
  • +
  • Authentication failure (4): エージェントが許可されていない発信元からのリクエストを受けたことを示します。(通常はコミュニティで制限されています)
  • +
  • EGP neighbor loss (5): EGP プロトコルを利用しているルータで、隣接ホストとの通信が切れたことを示します。
  • +
  • Enterprise (6): このカテゴリに含まれるものは、ベンダー独自のトラップです。