From 6157e3bf4c26d9a739a49c70a1c1532041d736ae Mon Sep 17 00:00:00 2001 From: zarzuelo Date: Tue, 14 Aug 2012 12:52:29 +0000 Subject: [PATCH] 2012-08-14 Sergio Martin * include/javascript/pandora_modules.js include/ajax/module.php pandoradb.sql pandoradb.postgreSQL.sql pandoradb.oracle.sql extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql godmode/agentes/module_manager_editor_plugin.php godmode/agentes/configurar_agente.php godmode/servers/plugin.php godmode/modules/manage_network_components.php godmode/modules/manage_network_components_form_plugin.php: Change all the manage plugins form adding the dynamic macros in this side. Change the network components form to put the macro fields in this side. * operation/users/user_edit.php: Change the "Flash chart" string by "Interactive chart" git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6859 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 21 ++ .../pandoradb_migrate_4.0.x_to_5.0.mysql.sql | 7 + .../pandoradb_migrate_4.0.x_to_5.0.oracle.sql | 6 + ...doradb_migrate_4.0.x_to_5.0.postgreSQL.sql | 6 + .../godmode/agentes/configurar_agente.php | 22 +- .../agentes/module_manager_editor_plugin.php | 38 ++- .../modules/manage_network_components.php | 33 +-- .../manage_network_components_form_plugin.php | 102 ++------ pandora_console/godmode/servers/plugin.php | 244 ++++++++++++++---- pandora_console/include/ajax/module.php | 15 +- .../include/javascript/pandora_modules.js | 81 ++++++ pandora_console/operation/users/user_edit.php | 2 +- pandora_console/pandoradb.oracle.sql | 4 +- pandora_console/pandoradb.postgreSQL.sql | 4 +- pandora_console/pandoradb.sql | 2 + 15 files changed, 420 insertions(+), 167 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index f46d1e43d1..e38d91f075 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,24 @@ +2012-08-14 Sergio Martin + + * include/javascript/pandora_modules.js + include/ajax/module.php + pandoradb.sql + pandoradb.postgreSQL.sql + pandoradb.oracle.sql + extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql + extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql + extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql + godmode/agentes/module_manager_editor_plugin.php + godmode/agentes/configurar_agente.php + godmode/servers/plugin.php + godmode/modules/manage_network_components.php + godmode/modules/manage_network_components_form_plugin.php: Change all the + manage plugins form adding the dynamic macros in this side. Change the + network components form to put the macro fields in this side. + + * operation/users/user_edit.php: Change the "Flash chart" string + by "Interactive chart" + 2012-08-10 Sergio Martin * include/functions_api.php: Force the static graphs in the diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql index 1a49a5e499..e939cd906c 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql @@ -277,3 +277,10 @@ ALTER TABLE tagente_modulo ADD `macros` text; -- ----------------------------------------------------- ALTER TABLE tusuario ADD `metaconsole_access` enum('basic','advanced','custom','all','only_console') default 'only_console'; + +-- ----------------------------------------------------- +-- Table `tplugin` +-- ----------------------------------------------------- + +ALTER TABLE tplugin ADD `macros` text; +ALTER TABLE tplugin ADD `parameters` text; diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql index 94da955ef1..ea60277399 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql @@ -282,3 +282,9 @@ ALTER TABLE tagente_modulo ADD (macros CLOB default ''); ALTER TABLE tusuario ADD (metaconsole_access VARCHAR2(100) default 'only_console' NOT NULL); ALTER TABLE tusuario ADD CONSTRAINT t_usuario_metaconsole_access_cons CHECK (metaconsole_access IN ('basic','advanced','custom','all','only_console')); +-- ----------------------------------------------------- +-- Table `tplugin` +-- ----------------------------------------------------- + +ALTER TABLE tplugin ADD (macros CLOB default ''); +ALTER TABLE tplugin ADD (parameters CLOB default ''); diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql index 7f9305b60f..b0d2dea709 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql @@ -272,3 +272,9 @@ ALTER TABLE "tagente_modulo" ADD COLUMN "macros" TEXT default ''; CREATE TYPE type_tusuario_metaconsole_access AS ENUM ('basic','advanced','custom','all','only_console'); ALTER TABLE "tusuario" ADD COLUMN "metaconsole_access" type_tusuario_metaconsole_access default 'only_console'; +-- ----------------------------------------------------- +-- Table `tplugin` +-- ----------------------------------------------------- + +ALTER TABLE "tplugin" ADD COLUMN "macros" TEXT default ''; +ALTER TABLE "tplugin" ADD COLUMN "parameters" TEXT default ''; diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index ebd234d142..39abcfcacc 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -21,6 +21,7 @@ enterprise_include ('godmode/agentes/configurar_agente.php'); enterprise_include ('include/functions_policies.php'); enterprise_include ('include/functions_modules.php'); include_once($config['homedir'] . "/include/functions_agents.php"); +ui_require_javascript_file('encode_decode_base64'); check_login (); @@ -123,6 +124,7 @@ $unit = ""; $id_tag = array(); $tab_description = ''; $url_description = ''; +$macros = ''; $create_agent = (bool) get_parameter ('create_agent'); @@ -145,7 +147,6 @@ if ($create_agent) { $update_gis_data = (int) get_parameter_post("update_gis_data", 0); $url_description = (string) get_parameter("url_description"); - $fields = db_get_all_fields_in_table('tagent_custom_fields'); if ($fields === false) $fields = array(); @@ -670,6 +671,19 @@ if ($update_module || $create_module) { $custom_integer_1 = (int) get_parameter ('prediction_module'); $custom_integer_2 = (int) get_parameter ('custom_integer_2'); + // Get macros + $macros = (string) get_parameter ('macros'); + + if(!empty($macros)) { + $macros = json_decode(base64_decode($macros), true); + + foreach($macros as $k => $m) { + $macros[$k]['value'] = get_parameter($m['macro'], ''); + } + + $macros = json_encode($macros); + } + // Services are an enterprise feature, // so we got the parameters using this function. @@ -776,7 +790,8 @@ if ($update_module) { 'custom_integer_1' => $custom_integer_1, 'custom_integer_2' => $custom_integer_2, 'min_ff_event' => $ff_event, - 'unit' => $unit); + 'unit' => $unit, + 'macros' => $macros); if ($prediction_module == 3 && $serialize_ops == '') { $result = false; @@ -883,7 +898,8 @@ if ($create_module) { 'custom_integer_1' => $custom_integer_1, 'custom_integer_2' => $custom_integer_2, 'min_ff_event' => $ff_event, - 'unit' => $unit); + 'unit' => $unit, + 'macros' => $macros); if($prediction_module == 3 && $serialize_ops == '') { $id_agent_module = false; diff --git a/pandora_console/godmode/agentes/module_manager_editor_plugin.php b/pandora_console/godmode/agentes/module_manager_editor_plugin.php index b50f30cb85..1aa9ff1b9c 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_plugin.php +++ b/pandora_console/godmode/agentes/module_manager_editor_plugin.php @@ -15,6 +15,8 @@ enterprise_include_once('include/functions_policies.php'); +$macros = $module['macros']; + $disabledBecauseInPolicy = false; $disabledTextBecauseInPolicy = ''; $page = get_parameter('page', ''); @@ -43,6 +45,8 @@ $data = array (); $data[0] = __('Plugin'); $data[1] = html_print_select_from_sql ('SELECT id, name FROM tplugin ORDER BY name', 'id_plugin', $id_plugin, 'changePluginSelect();', __('None'), 0, true, false, false, $disabledBecauseInPolicy); +// Store the macros in base64 into a hidden control to move between pages +$data[1] .= html_print_input_hidden('macros',base64_encode($macros),true); $table_simple->colspan['plugin_1'][2] = 2; if (!empty($id_plugin)) { @@ -75,17 +79,37 @@ $data[3] = html_print_input_password ('plugin_pass', $plugin_pass, '', 15, 60, t push_table_simple ($data, 'plugin_2'); +// A hidden "model row" to clone it from javascript to add fields dynamicly $data = array (); -$data[0] = __('Plugin parameters'); -$data[0] .= ui_print_help_icon ('plugin_parameters', true); -$data[1] = html_print_input_text ('plugin_parameter', $plugin_parameter, '', 255, '', true, $disabledBecauseInPolicy); -$table_simple->colspan['plugin_3'][1] = 3; +$data[0] = 'macro_desc'; +$data[0] .= ui_print_help_tip ('macro_help', true); +$data[1] = html_print_input_text ('macro_name', 'macro_value', '', 15, 60, true); +$table_simple->colspan['macro_field'][1] = 3; +$table_simple->rowstyle['macro_field'] = 'display:none'; + +push_table_simple ($data, 'macro_field'); + +// If there are $macros, we create the form fields +if(!empty($macros)) { + $macros = json_decode($macros, true); + + foreach($macros as $k => $m) { + $data = array (); + $data[0] = $m['desc']; + if(!empty($m['help'])) { + $data[0] .= ui_print_help_tip ($m['help'], true); + } + $data[1] = html_print_input_text($m['macro'], $m['value'], '', 15, 60, true); + $table_simple->colspan['macro'.$m['macro']][1] = 3; + $table_simple->rowclass['macro'.$m['macro']] = 'macro_field'; + + push_table_simple ($data, 'macro'.$m['macro']); + } +} -push_table_simple ($data, 'plugin_3'); ?> diff --git a/pandora_console/godmode/modules/manage_network_components.php b/pandora_console/godmode/modules/manage_network_components.php index d30aac4507..9a56094135 100644 --- a/pandora_console/godmode/modules/manage_network_components.php +++ b/pandora_console/godmode/modules/manage_network_components.php @@ -47,27 +47,18 @@ $plugin_user = (string) get_parameter ('plugin_user'); $plugin_pass = (string) get_parameter ('plugin_pass'); $plugin_parameter = (string) get_parameter ('plugin_parameter'); -$i = 1; -$macros = array(); -while(1) { - $macro = (string)get_parameter ('field'.$i.'_macro'); - if($macro == '') { - break; +$macros = (string) get_parameter ('macros'); + +if(!empty($macros)) { + $macros = json_decode(base64_decode($macros), true); + + foreach($macros as $k => $m) { + $macros[$k]['value'] = get_parameter($m['macro'], ''); } - - $desc = (string)get_parameter ('field'.$i.'_desc'); - $help = (string)get_parameter ('field'.$i.'_help'); - $value = (string)get_parameter ('field'.$i.'_value'); - $macros[$i]['macro'] = $macro; - $macros[$i]['desc'] = $desc; - $macros[$i]['help'] = $help; - $macros[$i]['value'] = $value; - $i++; + $macros = json_encode($macros); } -$macros = json_encode($macros); - $max_timeout = (int) get_parameter ('max_timeout'); $id_modulo = (int) get_parameter ('id_component_type'); $id_plugin = (int) get_parameter ('id_plugin'); @@ -167,7 +158,8 @@ if ($create_component) { 'post_process' => $post_process, 'unit' => $unit, 'wizard_level' => $wizard_level, - 'only_metaconsole' => $only_metaconsole)); + 'only_metaconsole' => $only_metaconsole, + 'macros' => $macros)); } else { $id = ''; @@ -238,7 +230,8 @@ if ($update_component) { 'post_process' => $post_process, 'unit' => $unit, 'wizard_level' => $wizard_level, - 'only_metaconsole' => $only_metaconsole)); + 'only_metaconsole' => $only_metaconsole, + 'macros' => $macros)); } else { $result = ''; @@ -469,4 +462,4 @@ function check_all_checkboxes() { $(".check_delete").attr('checked', false); } } - \ No newline at end of file + diff --git a/pandora_console/godmode/modules/manage_network_components_form_plugin.php b/pandora_console/godmode/modules/manage_network_components_form_plugin.php index 42e1449860..5c848c93fa 100644 --- a/pandora_console/godmode/modules/manage_network_components_form_plugin.php +++ b/pandora_console/godmode/modules/manage_network_components_form_plugin.php @@ -30,8 +30,11 @@ push_table_row ($data, 'plugin_0'); $data = array (); $data[0] = __('Plugin'); $data[1] = html_print_select_from_sql ('SELECT id, name FROM tplugin ORDER BY name', - 'id_plugin', $id_plugin, '', __('None'), 0, true, false, false); -$table->colspan['plugin_1'][1] = 3; + 'id_plugin', $id_plugin, 'javascript: load_plugin_macros_fields(\'network_component-macro\')', __('None'), 0, true, false, false); +// Store the macros in base64 into a hidden control to move between pages +$data[1] .= html_print_input_hidden('macros',base64_encode($macros),true); +$data[2] = __('Post process') . ' ' . ui_print_help_icon ('postprocess', true); +$data[3] = html_print_input_text ('post_process', $post_process, '', 12, 25, true); push_table_row ($data, 'plugin_1'); @@ -43,88 +46,33 @@ $data[3] = html_print_input_password ('plugin_pass', $plugin_pass, '', 15, 60, t push_table_row ($data, 'plugin_2'); +// A hidden "model row" to clone it from javascript to add fields dynamicly $data = array (); -$data[0] = __('Plugin parameters'); -$data[0] .= ui_print_help_icon ('plugin_parameters', true); -$data[1] = html_print_input_text ('plugin_parameter', $plugin_parameter, '', 30, 255, true); -$data[2] = __('Post process') . ' ' . ui_print_help_icon ('postprocess', true); -$data[3] = html_print_input_text ('post_process', $post_process, '', 12, 25, true); +$data[0] = 'macro_desc'; +$data[0] .= ui_print_help_tip ('macro_help', true); +$data[1] = html_print_input_text ('macro_name', 'macro_value', '', 15, 60, true); +$table->colspan['macro_field'][1] = 3; +$table->rowstyle['macro_field'] = 'display:none'; -push_table_row ($data, 'plugin_3'); +push_table_row ($data, 'macro_field'); -// Dynamic macros -$data = array (); -$data[0] = __('Plugin macros'); -$data[0] .= ui_print_help_icon ('plugin', true); -$data[1] = $data[2] = $data[3] = ''; +// If there are $macros, we create the form fields +if(!empty($macros)) { + $macros = json_decode($macros, true); -push_table_row ($data, 'plugin_4'); + foreach($macros as $k => $m) { + $data = array (); + $data[0] = $m['desc']; + if(!empty($m['help'])) { + $data[0] .= ui_print_help_tip ($m['help'], true); + } + $data[1] = html_print_input_text($m['macro'], $m['value'], '', 15, 60, true); + $table->colspan['macro'.$m['macro']][1] = 3; + $table->rowclass['macro'.$m['macro']] = 'macro_field'; -$macros = json_decode($macros,true); -// The next row number is plugin_5 -$next_name_number = 5; -$i = 1; -while(1) { - // Always print at least one macro - if((!isset($macros[$i]) || $macros[$i]['desc'] == '') && $i > 1) { - break; + push_table_row ($data, 'macro'.$m['macro']); } - $macro_desc_name = 'field'.$i.'_desc'; - $macro_desc_value = ''; - $macro_help_name = 'field'.$i.'_help'; - $macro_help_value = ''; - $macro_value_name = 'field'.$i.'_value'; - $macro_value_value = ''; - $macro_name_name = 'field'.$i.'_macro'; - $macro_name = '_field'.$i.'_'; - - if(isset($macros[$i]['desc'])) { - $macro_desc_value = $macros[$i]['desc']; - } - - if(isset($macros[$i]['help'])) { - $macro_help_value = $macros[$i]['help']; - } - - if(isset($macros[$i]['value'])) { - $macro_value_value = $macros[$i]['value']; - } - - $data = array (); - $data[0] = sprintf(__('Macro %s description'),$macro_name); - $data[0] .= html_print_input_hidden($macro_name_name, $macro_name, true); - $data[1] = html_print_input_text ($macro_desc_name, $macro_desc_value, '', 30, 255, true); - $data[2] = sprintf(__('Macro %s default value'),$macro_name); - $data[3] = html_print_input_text ($macro_value_name, $macro_value_value, '', 30, 255, true); - - push_table_row ($data, 'plugin_'.$next_name_number); - $next_name_number++; - - $table->colspan['plugin_'.$next_name_number][1] = 2; - - $data = array (); - $data[0] = sprintf(__('Macro %s help'),$macro_name); - $data[1] = html_print_input_text ($macro_help_name, $macro_help_value, '', 100, 255, true); - - push_table_row ($data, 'plugin_'.$next_name_number); - $next_name_number++; - $i++; } -$table->colspan['plugin_n'][2] = 2; - -$data = array (); -$data[0] = ''; -$data[1] = __('Add macro').' '.html_print_image('images/add.png',true).''; -$data[1] .= ''; -$data[1] .= ''; -$delete_macro_style = ''; -if($i <= 2) { - $delete_macro_style = 'display:none;'; -} -$data[2] = ''; - -push_table_row ($data, 'plugin_n'); - ?> diff --git a/pandora_console/godmode/servers/plugin.php b/pandora_console/godmode/servers/plugin.php index e4bc939c44..5ede55a93c 100644 --- a/pandora_console/godmode/servers/plugin.php +++ b/pandora_console/godmode/servers/plugin.php @@ -48,22 +48,19 @@ if ($view != "") { $form_description = $plugin["description"]; $form_max_timeout = $plugin ["max_timeout"]; $form_execute = $plugin ["execute"]; - $form_net_dst_opt = $plugin ["net_dst_opt"]; - $form_net_port_opt = $plugin ["net_port_opt"]; - $form_user_opt = $plugin ["user_opt"]; - $form_pass_opt = $plugin ["pass_opt"]; $form_plugin_type = $plugin ["plugin_type"]; + $macros = $plugin ["macros"]; + $parameters = $plugin ["parameters"]; } if ($create != "") { $form_name = ""; $form_description = ""; $form_max_timeout = ""; $form_execute = ""; - $form_net_dst_opt = ""; - $form_net_port_opt = ""; - $form_user_opt = ""; - $form_pass_opt = ""; $form_plugin_type = 0; + $form_parameters = ""; + $macros = ""; + $parameters = ""; } // SHOW THE FORM @@ -84,49 +81,137 @@ if (($create != "") OR ($view != "")) { else echo "
"; - echo ''; + $table->width = '98%'; + $table->id = 'table-form'; + $table->class = 'databox_color'; + $table->style = array (); + $table->style[0] = 'font-weight: bold'; + $table->style[2] = 'font-weight: bold'; + $table->data = array (); + + $data = array(); + $data[0] = __('Name'); + $data[1] = ''; + $table->colspan['plugin_name'][1] = 3; + $table->data['plugin_name'] = $data; - echo ''; - echo ''; - - echo ''; - echo ''; - - echo ''; - echo ''; - echo ''; + $data = array(); + $data[0] = __('Description'); + $data[1] = ''; + $table->colspan['plugin_desc'][1] = 3; + $table->data['plugin_desc'] = $data; - echo ''; - echo ''; + echo '
'.__('General').''; + html_print_table($table); + echo '
'; - echo ''; - echo ''; + $table->data = array(); + + $data = array(); + $data[0] = __('Plugin command'); + $data[1] = ''; + $table->data['plugin_command'] = $data; + $data = array(); + $data[0] = __('Plug-in parameters').ui_print_help_icon ('plugin_parameters', true); + $data[1] = ''; + $table->data['plugin_parameters'] = $data; - echo ''; - echo ''; + $data = array(); + $data[0] = __('Command preview'); + $data[1] = '
'; + $table->data['plugin_preview'] = $data; + + echo '
'.__('Command').''; + html_print_table($table); + echo '
'; + + $data = array(); - echo ''; - echo ''; + $table->data = array (); - echo ''; - echo ''; + $macros = json_decode($macros,true); + + // The next row number is plugin_9 + $next_name_number = 9; + $i = 1; + while(1) { + // Always print at least one macro + if((!isset($macros[$i]) || $macros[$i]['desc'] == '') && $i > 1) { + break; + } + $macro_desc_name = 'field'.$i.'_desc'; + $macro_desc_value = ''; + $macro_help_name = 'field'.$i.'_help'; + $macro_help_value = ''; + $macro_value_name = 'field'.$i.'_value'; + $macro_value_value = ''; + $macro_name_name = 'field'.$i.'_macro'; + $macro_name = '_field'.$i.'_'; + + if(isset($macros[$i]['desc'])) { + $macro_desc_value = $macros[$i]['desc']; + } + + if(isset($macros[$i]['help'])) { + $macro_help_value = $macros[$i]['help']; + } + + if(isset($macros[$i]['value'])) { + $macro_value_value = $macros[$i]['value']; + } + + $datam = array (); + $datam[0] = __('Description')." ($macro_name)"; + $datam[0] .= html_print_input_hidden($macro_name_name, $macro_name, true); + $datam[1] = html_print_input_text ($macro_desc_name, $macro_desc_value, '', 30, 255, true); + $datam[2] = __('Default value')." ($macro_name)"; + $datam[3] = html_print_input_text_extended ($macro_value_name, $macro_value_value, 'text-'.$macro_value_name, '', 30, 255, false, '', "class='command_component'", true); + + $table->data['plugin_'.$next_name_number] = $datam; + + $next_name_number++; + + $table->colspan['plugin_'.$next_name_number][1] = 3; + + $datam = array (); + $datam[0] = __('Help')." ($macro_name)


"; + $datam[1] = html_print_input_text ($macro_help_name, $macro_help_value, '', 100, 255, true)."


"; + + $table->data['plugin_'.$next_name_number] = $datam; + $next_name_number++; + $i++; + } + + $datam = array (); + $datam[0] = ''.__('Add macro').''.html_print_image('images/add.png',true).''; + $datam[0] .= ''; + $datam[0] .= ''; + $delete_macro_style = ''; + if($i <= 2) { + $delete_macro_style = 'display:none;'; + } + $datam[2] = ''; + + $table->colspan['plugin_action'][0] = 2; + $table->rowstyle['plugin_action'] = 'text-align:center'; + $table->colspan['plugin_action'][2] = 2; + $table->data['plugin_action'] = $datam; + + echo '
'.__('Parameters macros').ui_print_help_icon ('macros', true).''; + html_print_table($table); + echo '
'; - echo '
'.__('Name') . ''; - echo '
'.__('Plugin command') . ''; - echo '
'.__('Plugin type') . ''; + $data = array(); + $data[0] = __('Plugin type'); $fields[0]= __("Standard"); $fields[1]= __("Nagios"); - html_print_select ($fields, "form_plugin_type", $form_plugin_type); + $data[1] = html_print_select ($fields, "form_plugin_type", $form_plugin_type, '', '', 0, true); + $data[2] = __('Max. timeout'); + $data[3] = ''; + $data[3] = html_print_extended_select_for_time ('form_max_timeout', $form_max_timeout, '', '', '0', false, true); + $table->data['plugin_type_timeout'] = $data; - echo '
'.__('Max. timeout') . ''; - echo '
'.__('IP address option') . ''; - echo '
'.__('Port option') . ''; - echo '
'.__('User option') . ''; - echo '
'.__('Password option') . ''; - echo '
'.__('Description').'
'; echo ''; echo '
'; @@ -150,22 +235,39 @@ else { $plugin_description = get_parameter ("form_description", ""); $plugin_max_timeout = get_parameter ("form_max_timeout", ""); $plugin_execute = get_parameter ("form_execute", ""); - $plugin_net_dst_opt = get_parameter ("form_net_dst_opt", ""); - $plugin_net_port_opt = get_parameter ("form_net_port_opt", ""); - $plugin_user_opt = get_parameter ("form_user_opt", ""); - $plugin_pass_opt = get_parameter ("form_pass_opt", ""); $plugin_plugin_type = get_parameter ("form_plugin_type", "0"); - + $parameters = get_parameter ("form_parameters", ""); + + // Get macros + $i = 1; + $macros = array(); + while(1) { + $macro = (string)get_parameter ('field'.$i.'_macro'); + if($macro == '') { + break; + } + + $desc = (string)get_parameter ('field'.$i.'_desc'); + $help = (string)get_parameter ('field'.$i.'_help'); + $value = (string)get_parameter ('field'.$i.'_value'); + + $macros[$i]['macro'] = $macro; + $macros[$i]['desc'] = $desc; + $macros[$i]['help'] = $help; + $macros[$i]['value'] = $value; + $i++; + } + + $macros = json_encode($macros); + $values = array( 'name' => $plugin_name, 'description' => $plugin_description, 'max_timeout' => $plugin_max_timeout, 'execute' => $plugin_execute, - 'net_dst_opt' => $plugin_net_dst_opt, - 'net_port_opt' => $plugin_net_port_opt, - 'user_opt' => $plugin_user_opt, 'plugin_type' => $plugin_plugin_type, - 'pass_opt' => $plugin_pass_opt); + 'parameters' => $parameters, + 'macros' => $macros); $result = false; if ($values['name'] != '' && $values['execute'] != '') @@ -185,21 +287,14 @@ else { $plugin_description = get_parameter ("form_description", ""); $plugin_max_timeout = get_parameter ("form_max_timeout", ""); $plugin_execute = get_parameter ("form_execute", ""); - $plugin_net_dst_opt = get_parameter ("form_net_dst_opt", ""); - $plugin_net_port_opt = get_parameter ("form_net_port_opt", ""); - $plugin_user_opt = get_parameter ("form_user_opt", ""); - $plugin_pass_opt = get_parameter ("form_pass_opt", ""); $plugin_plugin_type = get_parameter ("form_plugin_type", "0"); + $plugin_parameters = get_parameter ("form_parameters", "0"); $values = array( 'name' => $plugin_name, 'description' => $plugin_description, 'max_timeout' => $plugin_max_timeout, 'execute' => $plugin_execute, - 'net_dst_opt' => $plugin_net_dst_opt, - 'net_port_opt' => $plugin_net_port_opt, - 'user_opt' => $plugin_user_opt, - 'pass_opt' => $plugin_pass_opt, 'plugin_type' => $plugin_plugin_type); $result = false; @@ -280,4 +375,39 @@ else { echo "
"; } +ui_require_javascript_file('pandora_modules'); + ?> + + diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index a82dc92f4c..0de55e5a8e 100644 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -32,4 +32,17 @@ if ($search_modules) { echo io_safe_output($module) . "\n"; } } -?> \ No newline at end of file + +$get_plugin_macros = get_parameter('get_plugin_macros'); +if($get_plugin_macros) { + $plugin_macros = db_get_value('macros','tplugin','id',get_parameter('id_plugin',0)); + + $macros = array(); + + $macros['base64'] = base64_encode($plugin_macros); + $macros['array'] = json_decode($plugin_macros,true); + + echo json_encode($macros); +} + +?> diff --git a/pandora_console/include/javascript/pandora_modules.js b/pandora_console/include/javascript/pandora_modules.js index be2de905a0..d5abd77a12 100644 --- a/pandora_console/include/javascript/pandora_modules.js +++ b/pandora_console/include/javascript/pandora_modules.js @@ -188,6 +188,21 @@ function configure_modules_form () { $("#component_loading").hide (); $("#id_module_type").change (); + // Delete macro fields + $('.macro_field').remove(); + + $('#hidden-macros').val(''); + + // If exist macros, load the fields + if(data["macros"] != '') { + $('#hidden-macros').val(Base64.encode(data["macros"])); + + var obj = jQuery.parseJSON(data["macros"]); + $.each(obj, function(k,macro) { + add_macro_field(macro, 'simple-macro'); + }); + } + if (data["type"] >= 15 && data["type"] <= 18) { $("#snmp_version option[value="+data["tcp_send"]+"]").select(1); $("#text-snmp3_auth_user").val(data["plugin_user"]); @@ -499,3 +514,69 @@ function new_macro(prefix) { } +function add_macro_field(macro, row_model_id) { + var macro_desc = macro['desc']; + var macro_help = macro['help']; + var macro_macro = macro['macro']; + var macro_value = macro['value']; + + var row_id = row_model_id + macro_macro; + + var $macro_field = $('#'+ row_model_id +'_field').clone(true); + + // Change attributes to be unique and with identificable class + $macro_field.attr('id',row_id); + $macro_field.attr('class','macro_field'); + + // Assign values + $macro_field.insertAfter('#'+ row_model_id +'_field'); + + // Change the label + if(macro_help == '') { + $('#'+row_id).children().eq(0).html(macro_desc); + } + else { + var field_desc = $('#'+row_id).children().eq(0).html(); + field_desc = field_desc.replace('macro_desc',macro_desc); + field_desc = field_desc.replace('macro_help',macro_help); + $('#'+row_id).children().eq(0).html(field_desc); + } + + // Change the text box id and value + $('#'+row_id).children().eq(1).children().attr('id','text-'+macro_macro); + $('#'+row_id).children().eq(1).children().attr('name',macro_macro); + $('#'+row_id).children().eq(1).children().val(macro_value); + + + $('#'+row_id).show(); +} + +function load_plugin_macros_fields(row_model_id) { + // Get plugin macros when selected and load macros fields + var id_plugin = $('#id_plugin').val(); + + var params = []; + params.push("page=include/ajax/module"); + params.push("get_plugin_macros=1"); + params.push("id_plugin="+id_plugin); + jQuery.ajax ({ + data: params.join ("&"), + type: 'POST', + url: action="ajax.php", + async: false, + timeout: 10000, + dataType: 'json', + success: function (data) { + // Delete all the macro fields + $('.macro_field').remove(); + + if(data['array'] != null) { + $('#hidden-macros').val(data['base64']); + jQuery.each (data['array'], function (i, macro) { + add_macro_field(macro, row_model_id); + }); + } + } + }); +} + diff --git a/pandora_console/operation/users/user_edit.php b/pandora_console/operation/users/user_edit.php index a444574143..0fbcc35f7a 100644 --- a/pandora_console/operation/users/user_edit.php +++ b/pandora_console/operation/users/user_edit.php @@ -239,7 +239,7 @@ if (count($usr_groups) > 1){ } } -echo ''.__('Flash charts').''; +echo ''.__('Interactive charts') . ui_print_help_tip(__('Whether to use Javascript or static PNG graphs'), true).''; $values = array(-1 => __('Default'),1 => __('Yes'),0 => __('No')); echo html_print_select($values, 'flash_charts', $user_info["flash_chart"], '', '', -1, true, false, false); echo ''.__('Block size for pagination'). ui_print_help_tip(__('If checkbox is clicked then block size global configuration is used'), true) . ''; diff --git a/pandora_console/pandoradb.oracle.sql b/pandora_console/pandoradb.oracle.sql index 3f7e12520f..b470ee8b95 100644 --- a/pandora_console/pandoradb.oracle.sql +++ b/pandora_console/pandoradb.oracle.sql @@ -1104,7 +1104,9 @@ CREATE TABLE tplugin ( net_port_opt VARCHAR2(50) default '', user_opt VARCHAR2(50) default '', pass_opt VARCHAR2(50) default '', - plugin_type NUMBER(5, 0) default 0 NOT NULL + plugin_type NUMBER(5, 0) default 0 NOT NULL, + macros CLOB default '', + parameters CLOB default '' ); CREATE SEQUENCE tplugin_s INCREMENT BY 1 START WITH 1; diff --git a/pandora_console/pandoradb.postgreSQL.sql b/pandora_console/pandoradb.postgreSQL.sql index 63e95092da..a56210d80d 100644 --- a/pandora_console/pandoradb.postgreSQL.sql +++ b/pandora_console/pandoradb.postgreSQL.sql @@ -880,7 +880,9 @@ CREATE TABLE "tplugin" ( "net_port_opt" varchar(50) default '', "user_opt" varchar(50) default '', "pass_opt" varchar(50) default '', - "plugin_type" SMALLINT NOT NULL default 0 + "plugin_type" SMALLINT NOT NULL default 0, + "macros" TEXT default '', + "parameters" TEXT default '' ); CREATE TABLE "tmodule" ( diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 707cc60656..46193c0f93 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -989,6 +989,8 @@ CREATE TABLE IF NOT EXISTS `tplugin` ( `user_opt` varchar(50) default '', `pass_opt` varchar(50) default '', `plugin_type` int(2) UNSIGNED NOT NULL default 0, + `macros` text, + `parameters` text, PRIMARY KEY(`id`) ) ENGINE = InnoDB DEFAULT CHARSET=utf8;