From 86cbecc9a0632a870af0e0fd564ebeaaf2517a19 Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Thu, 26 Mar 2020 09:04:10 +0100 Subject: [PATCH] WIP: PEN form near to clear --- pandora_console/godmode/menu.php | 22 +-- .../modules/private_enterprise_numbers.php | 137 ++++++++++++++++++ .../include/ajax/wizardSetup.ajax.php | 131 +++++++++++++++++ .../include/class/ConfigPEN.class.php | 83 +++++++---- 4 files changed, 337 insertions(+), 36 deletions(-) create mode 100644 pandora_console/godmode/modules/private_enterprise_numbers.php create mode 100644 pandora_console/include/ajax/wizardSetup.ajax.php diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index 8720225fec..9291a12336 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -140,18 +140,18 @@ if (check_acl($config['id_user'], 0, 'PM')) { $sub['godmode/modules/manage_network_components']['text'] = __('Remote components'); $sub['godmode/modules/manage_network_components']['id'] = 'Network components'; enterprise_hook('components_submenu'); - $sub['godmode/modules/configuration_wizard_setup']['text'] = __('Wizard Setup'); - $sub['godmode/modules/configuration_wizard_setup']['id'] = 'Wizard Setup'; - $sub['godmode/modules/configuration_wizard_setup']['type'] = 'direct'; - $sub['godmode/modules/configuration_wizard_setup']['subtype'] = 'nolink'; + $sub['configuration_wizard_setup']['text'] = __('Wizard Setup'); + $sub['configuration_wizard_setup']['id'] = 'Wizard Setup'; + $sub['configuration_wizard_setup']['type'] = 'direct'; + $sub['configuration_wizard_setup']['subtype'] = 'nolink'; $sub2 = []; - $sub2['private_enterprise_numbers']['text'] = __('Private Enterprise Numbers'); - $sub2['private_enterprise_numbers']['id'] = 'Private Enterprise Numbers'; - $sub2['SNMP_modules']['text'] = __('SNMP Modules'); - $sub2['SNMP_modules']['id'] = 'SNMP Modules'; - $sub2['WMI_modules']['text'] = __('WMI Modules'); - $sub2['WMI_modules']['id'] = 'WMI Modules'; - $sub['godmode/modules/configuration_wizard_setup']['sub2'] = $sub2; + $sub2['godmode/modules/private_enterprise_numbers']['text'] = __('Private Enterprise Numbers'); + $sub2['godmode/modules/private_enterprise_numbers']['id'] = 'Private Enterprise Numbers'; + $sub2['godmode/modules/SNMP_modules']['text'] = __('SNMP Modules'); + $sub2['godmode/modules/SNMP_modules']['id'] = 'SNMP Modules'; + $sub2['godmode/modules/WMI_modules']['text'] = __('WMI Modules'); + $sub2['godmode/modules/WMI_modules']['id'] = 'WMI Modules'; + $sub['configuration_wizard_setup']['sub2'] = $sub2; $sub['godmode/modules/manage_block_templates']['text'] = __('Module blocks'); $sub['godmode/modules/manage_block_templates']['id'] = 'Module blocks'; $sub['godmode/modules/manage_network_templates']['text'] = __('Module templates (legacy)'); diff --git a/pandora_console/godmode/modules/private_enterprise_numbers.php b/pandora_console/godmode/modules/private_enterprise_numbers.php new file mode 100644 index 0000000000..71cc7b1dc4 --- /dev/null +++ b/pandora_console/godmode/modules/private_enterprise_numbers.php @@ -0,0 +1,137 @@ +run(); +} catch (Exception $ex) { + ui_print_error_message(__('Something went wrong. Please, take a look in the Pandora FMS log')); + echo '[PEN Configuration]'.$ex->getMessage(); +} +?> + diff --git a/pandora_console/include/ajax/wizardSetup.ajax.php b/pandora_console/include/ajax/wizardSetup.ajax.php new file mode 100644 index 0000000000..c8c296d922 --- /dev/null +++ b/pandora_console/include/ajax/wizardSetup.ajax.php @@ -0,0 +1,131 @@ + $pen_id_np, + 'pen' => $pen_number, + 'manufacturer' => $pen_manufacturer, + 'description' => $pen_description, + ] + ); + if ($work === false) { + $output = ui_print_error_message(__('Error inserting new PEN')); + } else { + $output = $configPEN->createMainTable(); + } + } else { + $output = ui_print_error_message(sprintf(__('The PEN %s exists already'), $pen_number)); + } + break; + + // Update one record. + case 'update': + if ($actual_pen['pen'] != $pen_number + || $actual_pen['manufacturer'] != $pen_manufacturer + || $actual_pen['description'] != $pen_description + ) { + $work = db_process_sql_update( + 'tpen', + [ + 'pen' => $pen_number, + 'manufacturer' => $pen_manufacturer, + 'description' => $pen_description, + ], + ['pen' => $pen_number] + ); + + if ($work === false) { + $output = ui_print_error_message(__('Error updating data')); + } else { + $output = ui_print_success_message(__('PEN updated in DB')); + } + } else { + $output = ui_print_error_message(__('No changes applied')); + } + break; + + // Delete one record. + case 'delete': + if ($actual_pen != false) { + db_process_sql_delete( + 'tpen', + ['pen' => $pen_number] + ); + $output = $configPEN->createMainTable(); + } else { + $output = ui_print_error_message(__('Something goes wrong. Please, retry')); + } + break; + + default: + // Nothing to do. + break; +} + +// Return data. +return $output; diff --git a/pandora_console/include/class/ConfigPEN.class.php b/pandora_console/include/class/ConfigPEN.class.php index e88aab56d9..bf3c799e0f 100644 --- a/pandora_console/include/class/ConfigPEN.class.php +++ b/pandora_console/include/class/ConfigPEN.class.php @@ -36,9 +36,9 @@ class ConfigPEN extends HTML { /** - * Undocumented variable + * URL Base * - * @var [type] + * @var string */ private $baseUrl; @@ -58,15 +58,16 @@ class ConfigPEN extends HTML 'ACL Violation', 'Trying to access event viewer' ); - - if (is_ajax()) { + /* + if (is_ajax()) { echo json_encode(['error' => 'noaccess']); - } - + } + */ include 'general/noaccess.php'; exit; } + $this->offset = ''; $this->baseUrl = 'index.php?sec=configuration_wizard_setup&sec2=godmode/modules/private_enterprise_numbers'; } @@ -117,36 +118,47 @@ class ConfigPEN extends HTML $this->printHeader(true) ); - $this->createMainTable(); + // Definition for AJAX. + html_print_input_hidden( + 'ajax_file', + ui_get_full_url('ajax.php', false, false, false) + ); + // Allow message area. + html_print_div(['id' => 'message_show_area']); + // Prints the main table. + html_print_div( + [ + 'id' => 'main_table_area', + 'content' => $this->createMainTable(), + ] + ); } /** - * Undocumented function + * Create the main table with the PENs info * - * @return void + * @return string Return entire the table */ - private function createMainTable() + public function createMainTable() { global $config; // Get the count of PENs. $countPENs = db_get_value( 'count(*)', - 'tnetwork_profile' + 'tpen' ); // Get all the data. $resultPENs = db_get_all_rows_filter( - 'tnetwork_profile', + 'tpen', [ 'order' => 'id_np', 'limit' => $config['block_size'], ] ); - hd($resultPENs); - ui_pagination($countPENs, false, $this->offset); // Create the table with Module Block list. $table = new StdClasS(); @@ -181,15 +193,15 @@ class ConfigPEN extends HTML foreach ($resultPENs as $row) { $data = []; - $data[0] = html_print_checkbox_extended('delete_multiple[]', $row['id_np'], false, false, '', 'class="check_delete"', true); - $data[1] = ''.$row['id_np'].''; - $data[2] = ''.$row['name'].''; - $data[3] = ''.ui_print_truncate_text(io_safe_output($row['description']), 'description', true, true, true, '[…]').''; - $table->cellclass[][3] = 'action_buttons'; + $data[0] = html_print_checkbox_extended('delete_multiple[]', $row['pen'], false, false, '', 'class="check_delete"', true); + $data[1] = ''.$row['pen'].''; + $data[2] = ''.$row['manufacturer'].''; + $data[3] = ''.ui_print_truncate_text(io_safe_output($row['description']), 'description', true, true, true, '[…]').''; + $table->cellclass[][4] = 'action_buttons'; $data[4] = html_print_input_image( - 'edit_pen_'.$row['id_np'].'_', + 'edit_pen_', 'images/edit.png', - $row['id_np'], + $row['pen'], 'max-width: 27px;', true, [ @@ -198,22 +210,43 @@ class ConfigPEN extends HTML ] ); $data[4] .= html_print_input_image( - 'delete_pen_'.$row['id_np'].'_', + 'delete_pen_', 'images/cross.png', - $row['id_np'], + $row['pen'], '', true, [ 'title' => 'Delete PEN', - 'onclick' => 'if (!confirm(\''.__('Are you sure?').'\')) return false;', + 'onclick' => 'if (confirm(\''.__('Are you sure?').'\')) deletePEN(event);', ] ); array_push($table->data, $data); } - html_print_table($table); + // Last line for adding new PENs. + $data = []; + $data[0] = ''; + $data[1] = html_print_input_text('pen_number', '', '', 10, 255, true); + $data[2] = html_print_input_text('pen_manufacturer', '', '', 30, 255, true); + $data[3] = html_print_input_text('pen_description', '', '', 80, 255, true); + $table->cellclass[][4] = 'action_buttons'; + $data[4] = html_print_input_image( + 'add_new_pen', + 'images/add_mc.png', + '', + 'margin: 0 auto; display: block;', + true, + [ + 'title' => 'Add new PEN', + 'onclick' => 'javascript:addNewPEN()', + ] + ); + // Add last line. + array_push($table->data, $data); + // Return the entire table. + return html_print_table($table, true); }