setBreadcrum([]); $this->access = 'AW'; $this->task = []; $this->msg = $msg; $this->icon = $icon; $this->label = $label; $this->page = $page; $this->url = ui_get_full_url( 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=hd' ); return $this; } /** * Checks if environment is ready, * returns array * icon: icon to be displayed * label: label to be displayed * * @return array With data. **/ public function load() { global $config; // Check access. check_login(); if (! $this->aclMulticheck('AW|PM')) { return false; } return [ 'icon' => $this->icon, 'label' => $this->label, 'url' => $this->url, ]; } /** * Run wizard manager. * * @return mixed Returns null if wizard is ongoing. Result if done. */ public function run() { global $config; // Load styles. parent::run(); $mode = get_parameter('mode', null); if ($mode === null) { $buttons = []; if (check_acl($config['id_user'], 0, $this->access)) { $buttons[] = [ 'url' => $this->url.'&mode=netscan', 'icon' => 'images/wizard/netscan.png', 'label' => __('Net Scan'), ]; if (enterprise_installed()) { $buttons[] = [ 'url' => $this->url.'&mode=importcsv', 'icon' => ENTERPRISE_DIR.'/images/wizard/csv.png', 'label' => __('Import CSV'), ]; $buttons[] = [ 'url' => $this->url.'&mode=deploy', 'icon' => ENTERPRISE_DIR.'/images/wizard/deployment.png', 'label' => __('Agent deployment'), ]; } $buttons[] = [ 'url' => $this->url.'&mode=customnetscan', 'icon' => '/images/wizard/customnetscan.png', 'label' => __('Custom NetScan'), ]; } if (check_acl($config['id_user'], 0, 'PM')) { $buttons[] = [ 'url' => $this->url.'&mode=managenetscanscripts', 'icon' => '/images/wizard/managenetscanscripts.png', 'label' => __('Manage NetScan scripts'), ]; } $this->prepareBreadcrum( [ [ 'link' => ui_get_full_url( 'index.php?sec=gservers&sec2=godmode/servers/discovery' ), 'label' => __('Discovery'), ], [ 'link' => ui_get_full_url( 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=hd' ), 'label' => __('Host & Devices'), 'selected' => true, ], ], true ); ui_print_page_header( __('Host & devices'), '', false, '', true, '', false, '', GENERIC_SIZE_TEXT, '', $this->printHeader(true) ); $this->printBigButtonsList($buttons); return; } if (enterprise_installed()) { if ($mode === 'importcsv') { $csv_importer = new CSVImportAgents( $this->page, $this->breadcrum ); return $csv_importer->runCSV(); } if ($mode === 'deploy') { $deployObject = new DeploymentCenter( $this->page, $this->breadcrum ); return $deployObject->run(); } } if ($mode === 'customnetscan') { $customnetscan_importer = new CustomNetScan( $this->page, $this->breadcrum ); return $customnetscan_importer->runCustomNetScan(); } if ($mode === 'managenetscanscripts') { $managenetscanscript_importer = new ManageNetScanScripts( $this->page, $this->breadcrum ); return $managenetscanscript_importer->runManageNetScanScript(); } if ($mode == 'netscan') { return $this->runNetScan(); } return null; } // Extra methods. /** * Retrieves and validates information given by user in NetScan wizard. * * @return boolean Data OK or not. */ public function parseNetScan() { if ($this->page == 0) { // Check if we're updating a task. $task_id = get_parameter('task', null); if (isset($task_id) === true) { // We're updating this task. $task = db_get_row( 'trecon_task', 'id_rt', $task_id ); if ($task !== false) { $this->task = $task; } } return true; } // Validate response from page 0. No, not a bug, we're always 1 page // from 'validation' page. if ($this->page == 1) { $task_id = get_parameter('task', null); $taskname = get_parameter('taskname', ''); $comment = get_parameter('comment', ''); $server_id = get_parameter('id_recon_server', ''); $network = get_parameter('network', ''); $id_group = get_parameter('id_group', ''); $interval = get_parameter('interval', 0); if (isset($task_id) === true) { // We're updating this task. $task = db_get_row( 'trecon_task', 'id_rt', $task_id ); if ($task !== false) { $this->task = $task; } } else if (isset($taskname) === true && isset($network) === true ) { // Avoid double creation. $task = db_get_row_filter( 'trecon_task', [ 'name' => $taskname, 'subnet' => $network, ] ); if ($task !== false) { $this->task = $task; $this->msg = __('This network scan task has been already defined. Please edit it or create a new one.'); return false; } } if ($task_id !== null && $taskname == null && $server_id == null && $id_group == null && $server == null && $datacenter == '' && $user == '' && $pass == '' && $encrypt == null && $interval == 0 ) { // Default values, no data received. // User is accesing directly to this page. if (check_acl( $config['id_usuario'], $this->task['id_group'], $this->access ) != true ) { $this->msg = __('You have no access to edit this task.'); return false; } } else { if (isset($this->task['id_rt']) === false) { // Disabled 2 Implies wizard non finished. $this->task['disabled'] = 2; } if ($taskname == '') { $this->msg = __('You must provide a task name.'); return false; } if ($server_id == '') { $this->msg = __('You must select a Discovery Server.'); return false; } if ($network == '') { // XXX: Could be improved validating provided network. $this->msg = __('You must provide a valid network.'); return false; } if ($id_group == '') { $this->msg = __('You must select a valid group.'); return false; } // Assign fields. $this->task['name'] = $taskname; $this->task['description'] = $comment; $this->task['subnet'] = $network; $this->task['id_recon_server'] = $server_id; $this->task['id_group'] = $id_group; $this->task['interval_sweep'] = $interval; if (isset($this->task['id_rt']) === false) { // Create. $this->task['id_rt'] = db_process_sql_insert( 'trecon_task', $this->task ); } else { // Update. db_process_sql_update( 'trecon_task', $this->task, ['id_rt' => $this->task['id_rt']] ); } } return true; } // Validate response from page 1. if ($this->page == 2) { $id_rt = get_parameter('task', -1); $task = db_get_row( 'trecon_task', 'id_rt', $id_rt ); if ($task !== false) { $this->task = $task; } else { $this->msg = __('Failed to find network scan task.'); return false; } $id_network_profile = get_parameter('id_network_profile', null); $autoconf_enabled = get_parameter_switch( 'autoconfiguration_enabled' ); $snmp_enabled = get_parameter_switch('snmp_enabled'); $os_detect = get_parameter_switch('os_detect'); $parent_detection = get_parameter_switch('parent_detection'); $parent_recursion = get_parameter_switch('parent_recursion'); $vlan_enabled = get_parameter_switch('vlan_enabled'); $wmi_enabled = get_parameter_switch('wmi_enabled'); $resolve_names = get_parameter_switch('resolve_names'); $snmp_version = get_parameter('snmp_version', null); $community = get_parameter('community', null); $snmp_context = get_parameter('snmp_context', null); $snmp_auth_user = get_parameter('snmp_auth_user', null); $snmp_auth_pass = get_parameter('snmp_auth_pass', null); $snmp_privacy_method = get_parameter('snmp_privacy_method', null); $snmp_privacy_pass = get_parameter('snmp_privacy_pass', null); $snmp_auth_method = get_parameter('snmp_auth_method', null); $snmp_security_level = get_parameter('snmp_security_level', null); $auth_strings = get_parameter('auth_strings', null); if ($snmp_version == 3) { $this->task['snmp_community'] = $snmp_context; } else { $this->task['snmp_community'] = $community; } $this->task['autoconfiguration_enabled'] = $autoconf_enabled; $this->task['id_network_profile'] = $id_network_profile; $this->task['snmp_enabled'] = $snmp_enabled; $this->task['os_detect'] = $os_detect; $this->task['parent_detection'] = $parent_detection; $this->task['parent_recursion'] = $parent_recursion; $this->task['vlan_enabled'] = $vlan_enabled; $this->task['wmi_enabled'] = $wmi_enabled; $this->task['resolve_names'] = $resolve_names; $this->task['snmp_version'] = $snmp_version; $this->task['snmp_auth_user'] = $snmp_auth_user; $this->task['snmp_auth_pass'] = $snmp_auth_pass; $this->task['snmp_privacy_method'] = $snmp_privacy_method; $this->task['snmp_privacy_pass'] = $snmp_privacy_pass; $this->task['snmp_auth_method'] = $snmp_auth_method; $this->task['snmp_security_level'] = $snmp_security_level; $this->task['auth_strings'] = $auth_strings; if ($this->task['disabled'] == 2) { // Wizard finished. $this->task['disabled'] = 0; } // Update. $res = db_process_sql_update( 'trecon_task', $this->task, ['id_rt' => $this->task['id_rt']] ); return true; } if ($this->page == 3) { // Wizard ended. Load data and return control to Discovery. $id_rt = get_parameter('task', -1); $task = db_get_row( 'trecon_task', 'id_rt', $id_rt ); if ($task !== false) { $this->task = $task; } else { $this->msg = __('Failed to find network scan task.'); return false; } return true; } return false; } /** * Undocumented function * * @return void */ public function runNetScan() { global $config; check_login(); if (! check_acl($config['id_user'], 0, $this->access)) { db_pandora_audit( 'ACL Violation', 'Trying to access Agent Management' ); include 'general/noaccess.php'; return; } if ($this->parseNetScan() === false) { // Error. ui_print_error_message( $this->msg ); $form = [ 'form' => [ 'method' => 'POST', 'action' => $this->url.'&mode=netscan&page='.($this->page - 1).'&task='.$this->task['id_rt'], ], 'inputs' => [ [ 'arguments' => [ 'type' => 'hidden', 'name' => 'task', 'value' => $this->task['id_rt'], ], ], [ 'arguments' => [ 'name' => 'submit', 'label' => __('Go back'), 'type' => 'submit', 'attributes' => 'class="sub cancel"', 'return' => true, ], ], ], ]; // Check ACL. If user is not able to manage target task, // redirect him to main page. if (check_acl( $config['id_usuario'], $this->task['id_group'], $this->access ) != true ) { $form['form']['action'] = $this->url.'&mode=netscan&page='.($this->page - 1); } $this->printForm($form); return null; } $task_url = ''; if (isset($this->task['id_rt'])) { $task_url = '&task='.$this->task['id_rt']; } $breadcrum = [ [ 'link' => 'index.php?sec=gservers&sec2=godmode/servers/discovery', 'label' => 'Discovery', ], [ 'link' => 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=hd', 'label' => __($this->label), ], ]; for ($i = 0; $i < $this->maxPagesNetScan; $i++) { $breadcrum[] = [ 'link' => 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=hd&mode=netscan&page='.$i.$task_url, 'label' => $this->pageLabelsNetScan[$i], 'selected' => (($i == $this->page) ? 1 : 0), ]; } if ($this->page < $this->maxPagesNetScan) { // Avoid to print header out of wizard. $this->prepareBreadcrum($breadcrum); ui_print_page_header( __('NetScan'), '', false, '', true, '', false, '', GENERIC_SIZE_TEXT, '', $this->printHeader(true) ); } if (isset($this->page) === true && $this->page != 0 && isset($this->task['id_rt']) === false ) { // Error. ui_print_error_message( __('Internal error, please re-run this wizard.') ); $form = [ 'form' => [ 'method' => 'POST', 'action' => $this->url.'&mode=netscan&page=0', ], 'inputs' => [ [ 'arguments' => [ 'type' => 'hidden', 'name' => 'page', 'value' => 0, ], ], [ 'arguments' => [ 'name' => 'submit', 'label' => __('Go back'), 'type' => 'submit', 'attributes' => 'class="sub cancel"', 'return' => true, ], ], ], ]; $this->printForm($form); return null; } // -------------------------------. // Page 0. wizard starts HERE. // -------------------------------. if (isset($this->page) === true || $this->page == 0) { if (isset($this->page) === false || $this->page == 0 ) { $form = []; $str = __('Next'); if (isset($this->task['id_rt']) === true) { $str = __('Update and continue'); } // Interval and schedules. $interv_manual = 0; if ((int) $this->task['interval_sweep'] == 0) { $interv_manual = 1; } $form['rows'][0]['new_form_block'] = true; $form['rows'][0]['columns'][0] = [ 'width' => '30%', 'style' => 'padding: 9px;', 'inputs' => [ '0' => [ 'arguments' => [ 'name' => 'submit', 'label' => $str, 'type' => 'submit', 'attributes' => 'class="sub next"', 'return' => true, ], ], '1' => '