diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 23250995db..758f8e653b 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -1,7 +1,34 @@ setBreadcrum( - [ - 'Host&devices', - 'Import CSV', - ] - ); - $this->printHeader(); - return $this->runCSV(); + if (enterprise_installed()) { + if ($mode == 'importcsv') { + $this->setBreadcrum( + [ + 'Host&devices', + 'Import CSV', + ] + ); + $this->printHeader(); + $csv_importer = new CSVImportAgents($this->page, $this->breadcrum); + return $csv_importer->runCSV(); + } } if ($mode == 'netscan') { @@ -172,154 +195,6 @@ class HostDevices extends Wizard // Extra methods. - /** - * Undocumented function - * - * @return void - */ - public function runCSV() - { - global $config; - - if (!check_acl($config['id_user'], 0, 'AW')) { - db_pandora_audit( - 'ACL Violation', - 'Trying to access db status' - ); - include 'general/noaccess.php'; - return; - } - - if (!isset($this->page) || $this->page == 0) { - $this->printForm( - [ - 'form' => [ - 'action' => '#', - 'method' => 'POST', - 'enctype' => 'multipart/form-data', - ], - 'inputs' => [ - [ - 'arguments' => [ - 'type' => 'hidden', - 'name' => 'import_file', - 'value' => 1, - 'return' => true, - ], - ], - [ - 'label' => __('Upload file'), - 'arguments' => [ - 'type' => 'file', - 'name' => 'file', - 'return' => true, - ], - ], - [ - 'label' => __('Server'), - 'arguments' => [ - 'type' => 'select', - 'fields' => servers_get_names(), - 'name' => 'server', - 'return' => true, - ], - ], - [ - 'label' => __('Separator'), - 'arguments' => [ - 'type' => 'select', - 'fields' => [ - ',' => ',', - ';' => ';', - ':' => ':', - '.' => '.', - '#' => '#', - ], - 'name' => 'separator', - 'return' => true, - ], - ], - [ - 'arguments' => [ - 'name' => 'page', - 'value' => 1, - 'type' => 'hidden', - 'return' => true, - ], - ], - [ - 'arguments' => [ - 'name' => 'submit', - 'label' => __('Go'), - 'type' => 'submit', - 'attributes' => 'class="sub next"', - 'return' => true, - ], - ], - ], - ] - ); - } - - if (isset($this->page) && $this->page == 1) { - $server = get_parameter('server'); - $separator = get_parameter('separator'); - - if (isset($_FILES['file'])) { - $file_status_code = get_file_upload_status('file'); - $file_status = translate_file_upload_status($file_status_code); - - if ($file_status === true) { - $error_message = []; - $line = -1; - $file = fopen($_FILES['file']['tmp_name'], 'r'); - if (! empty($file)) { - while (($data = fgetcsv($file, 1000, $separator)) !== false) { - $result = $this->processCsvData($data, $server); - $line++; - if ($result === HDW_CSV_NOT_DATA || $result === HDW_CSV_DUPLICATED || $result === HDW_CSV_GROUP_EXISTS) { - if ($result === HDW_CSV_NOT_DATA) { - $error_message[] = __('No data or wrong separator in line ').$line.'
'; - } else if ($result === HDW_CSV_DUPLICATED) { - $error_message[] = __('Agent ').io_safe_input($data[0]).__(' duplicated').'
'; - } else { - $error_message[] = __("Id group %s in line %s doesn't exist in %s", $data[4], $line, get_product_name()).'
'; - } - - continue; - } - - ui_print_result_message( - $result !== false, - __('Created agent %s', $result['agent_name']), - __('Could not create agent %s', $result['agent_name']) - ); - } - } - - fclose($file); - - if (empty($error_message)) { - ui_print_success_message(__('File processed')); - } else { - foreach ($error_message as $msg) { - ui_print_error_message($msg); - } - } - } else { - ui_print_error_message($file_status); - } - - @unlink($_FILES['file']['tmp_name']); - } else { - ui_print_error_message(__('No input file detected')); - } - - echo $this->breadcrum[0]; - } - } - - /** * Retrieves and validates information given by user in NetScan wizard. * @@ -701,6 +576,7 @@ class HostDevices extends Wizard ], ]; + // SNMP Options pack v1. $form['inputs'][] = [ 'hidden' => 1, 'block_id' => 'snmp_options_v1', @@ -718,6 +594,42 @@ class HostDevices extends Wizard ], ]; + // SNMP Options pack v2c. + $form['inputs'][] = [ + 'hidden' => 1, + 'block_id' => 'snmp_options_v2c', + 'block_content' => [ + [ + 'label' => __('Community'), + 'arguments' => [ + 'name' => 'community', + 'type' => 'text', + 'size' => 25, + 'return' => true, + + ], + ], + ], + ]; + + // SNMP Options pack v3. + $form['inputs'][] = [ + 'hidden' => 1, + 'block_id' => 'snmp_options_v3', + 'block_content' => [ + [ + 'label' => __(''), + 'arguments' => [ + 'name' => 'community', + 'type' => 'text', + 'size' => 25, + 'return' => true, + + ], + ], + ], + ]; + // Input: WMI enabled. $form['inputs'][] = [ 'label' => __('WMI enabled'), @@ -905,62 +817,4 @@ $("select#interval_manual_defined").change(function() { } - /** - * Process the csv of agent. - * - * @param array $data Data of agent. - * @param string $server Name of server. - * - * @return array with data porcessed. - */ - private static function processCsvData($data, $server='') - { - if (empty($data) || count($data) < 5) { - return HDW_CSV_NOT_DATA; - } - - $data['network_components'] = array_slice($data, 6); - $data['agent_name'] = io_safe_input($data[0]); - $data['alias'] = io_safe_input($data[0]); - $data['ip_address'] = $data[1]; - $data['id_os'] = $data[2]; - $data['interval'] = $data[3]; - $data['id_group'] = $data[4]; - $data['comentarios'] = io_safe_input($data[5]); - - $exists = (bool) agents_get_agent_id($data['agent_name']); - if ($exists) { - return HDW_CSV_DUPLICATED; - } - - $group_exists_in_pandora = (bool) groups_get_group_by_id($data['id_group']); - if (!$group_exists_in_pandora) { - return HDW_CSV_GROUP_EXISTS; - } - - $data['id_agent'] = agents_create_agent( - $data['agent_name'], - $data['id_group'], - $data['interval'], - $data['ip_address'], - [ - 'id_os' => $data['id_os'], - 'server_name' => $server, - 'modo' => 1, - 'alias' => $data['alias'], - 'comentarios' => $data['comentarios'], - ] - ); - - foreach ($data['network_components'] as $id_network_component) { - network_components_create_module_from_network_component( - (int) $id_network_component, - $data['id_agent'] - ); - } - - return $data; - } - - } diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index c164b287b7..1a70bae362 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -13,6 +13,13 @@ class Wizard */ public $breadcrum; + /** + * Undocumented variable + * + * @var [type] + */ + public $page; + /** * Setter for breadcrum