From ad3e2b88bf7d5ead87f43e2d741fbae7126f48e0 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 21 Feb 2019 11:19:38 +0100 Subject: [PATCH] Minor fixes Wiz.Discovery Former-commit-id: 750cd3ab1902ed3eda9806aa9b505d5e4a1175be --- pandora_console/godmode/servers/discovery.php | 48 +++- .../godmode/wizards/ConsoleTasks.class.php | 133 +++++++++++ .../godmode/wizards/HostDevices.class.php | 218 +++++++++--------- pandora_console/include/styles/discovery.css | 8 + .../include/styles/hostdevices.css | 3 + 5 files changed, 298 insertions(+), 112 deletions(-) create mode 100644 pandora_console/godmode/wizards/ConsoleTasks.class.php create mode 100644 pandora_console/include/styles/hostdevices.css diff --git a/pandora_console/godmode/servers/discovery.php b/pandora_console/godmode/servers/discovery.php index 1ac048a9ed..261cdd0696 100755 --- a/pandora_console/godmode/servers/discovery.php +++ b/pandora_console/godmode/servers/discovery.php @@ -19,10 +19,11 @@ ui_print_page_header(__('Discover'), '', false, '', true); /** - * Undocumented function + * Mask class names. * - * @param [type] $str - * @return void + * @param string $str Wiz parameter. + * + * @return string Classname. */ function get_wiz_class($str) { @@ -39,6 +40,9 @@ function get_wiz_class($str) case 'app': return 'Applications'; + case 'ctask': + return 'ConsoleTasks'; + default: // Ignore. return null; @@ -46,6 +50,31 @@ function get_wiz_class($str) } +/** + * Aux. function to compare classpath names. + * + * @param string $a Classpath A. + * @param string $b Classpath B. + * + * @return string Matching one. + */ +function cl_load_cmp($a, $b) +{ + $str_a = basename($a, '.class.php'); + $str_b = basename($b, '.class.php'); + if ($str_a == $str_b) { + return 0; + } + + if ($str_a < $str_b) { + return -1; + } + + return 1; + +} + + /* * CLASS LOADER. */ @@ -79,8 +108,13 @@ if (enterprise_installed() === true) { } } +// Combine class paths. $classes = array_merge($classes, $enterprise_classes); +// Sort output. +uasort($classes, 'cl_load_cmp'); + +// Check user action. $wiz_in_use = get_parameter('wiz', null); $page = get_parameter('page', 0); @@ -110,7 +144,13 @@ if ($classname_selected === null) { foreach ($classes as $classpath) { $classname = basename($classpath, '.class.php'); $obj = new $classname(); - $wiz_data[] = $obj->load(); + + // DiscoveryTaskList must be first button. + if ($classname == 'DiscoveryTaskList') { + array_unshift($wiz_data, $obj->load()); + } else { + $wiz_data[] = $obj->load(); + } } Wizard::printBigButtonsList($wiz_data); diff --git a/pandora_console/godmode/wizards/ConsoleTasks.class.php b/pandora_console/godmode/wizards/ConsoleTasks.class.php new file mode 100644 index 0000000000..9c9e060fdf --- /dev/null +++ b/pandora_console/godmode/wizards/ConsoleTasks.class.php @@ -0,0 +1,133 @@ +setBreadcrum([]); + + $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=ctask' + ); + + return $this; + } + + + /** + * Implements run method. + * + * @return mixed Returns null if wizard is ongoing. Result if done. + */ + public function run() + { + global $config; + + // Load styles. + parent::run(); + echo 'hola'; + + for ($i = 0; $i < $this->MAXPAGES; $i++) { + $breadcrum[] = [ + 'link' => 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=app&mode=vmware&page='.$i.'&task='.$this->task['id_rt'], + 'label' => $this->label.' '.$this->pageLabels[$i], + 'selected' => (($i == $this->page) ? 1 : 0), + ]; + } + + if ($this->page < $this->MAXPAGES) { + // Avoid to print header out of wizard. + $this->prepareBreadcrum($breadcrum); + $this->printHeader(); + } + + $this->printGoBackButton(); + return null; + + } + + + /** + * Implements load method. + * + * @return mixed Skeleton for button. + */ + public function load() + { + return [ + 'icon' => $this->icon, + 'label' => $this->label, + 'url' => $this->url, + + ]; + } + + +} diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index d9765cf5c2..b7a41afa58 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -38,6 +38,24 @@ enterprise_include('include/class/CSVImportAgents.class.php'); class HostDevices extends Wizard { + /** + * Number of pages to control breadcrum. + * + * @var integer + */ + public $maxPagesNetScan = 2; + + /** + * Labels for breadcrum. + * + * @var array + */ + public $pageLabelsNetScan = [ + 'NetScan definition', + 'NetScan features', + + ]; + /** * Stores all needed parameters to create a recon task. * @@ -92,16 +110,6 @@ class HostDevices extends Wizard $mode = get_parameter('mode', null); if ($mode === null) { - $this->prepareBreadcrum( - [ - [ - 'link' => $this->url.'&wiz=hd', - 'label' => __('    Host & devices'), - ], - ] - ); - - $this->printHeader(); $this->printBigButtonsList( [ [ @@ -123,62 +131,12 @@ class HostDevices extends Wizard if (enterprise_installed()) { if ($mode == 'importcsv') { - $this->prepareBreadcrum( - [ - [ - 'link' => $this->url.'&wiz=hd', - 'label' => __('    Host & devices'), - ], - [ - 'link' => $this->url.'&wiz=hd&mode=importcsv', - 'label' => __('      Import CSV'), - ], - ] - ); - $this->printHeader(); $csv_importer = new CSVImportAgents($this->page, $this->breadcrum); return $csv_importer->runCSV(); } } if ($mode == 'netscan') { - if ($this->page != 2) { - // Do not paint breadcrum in last page. Redirected. - $this->prepareBreadcrum( - [ - [ - 'link' => $this->url.'&wiz=hd', - 'label' => __('    Host & devices'), - ], - [ - 'link' => $this->url.'&wiz=hd&mode=netscan', - 'label' => __('      Net scan definition'), - ], - ] - ); - - if ($this->page == 1) { - $this->prepareBreadcrum( - [ - [ - 'link' => $this->url.'&wiz=hd', - 'label' => __('    Host & devices'), - ], - [ - 'link' => $this->url.'&wiz=hd&mode=netscan', - 'label' => __('      Net scan definition'), - ], - [ - 'link' => $this->url.'&wiz=hd&mode=netscan&page=1', - 'label' => __('      Net scan features'), - ], - ] - ); - } - - $this->printHeader(); - } - return $this->runNetScan(); } @@ -257,53 +215,77 @@ class HostDevices extends Wizard } } - 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 - ); + 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 (users_is_admin() !== true && check_acl( + $config['id_usuario'], + $this->task['id_group'], + 'PM' + ) !== true + ) { + $this->msg = __('You have no access to edit this task.'); + return false; + } } else { - // Update. - db_process_sql_update( - 'trecon_task', - $this->task, - ['id_rt' => $this->task['id_rt']] - ); + 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; @@ -408,7 +390,6 @@ class HostDevices extends Wizard } return false; - } @@ -478,6 +459,25 @@ class HostDevices extends Wizard return null; } + $task_url = ''; + if (isset($this->task['id_rt'])) { + $task_url = '&task='.$this->task['id_rt']; + } + + 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); + $this->printHeader(); + } + if (isset($this->page) === true && $this->page != 0 && isset($this->task['id_rt']) === false @@ -698,7 +698,9 @@ $("select#interval_manual_defined").change(function() { // XXX: Could be improved validating inputs before continue (JS) // Print NetScan page 0. $this->printForm($form); - $this->printGoBackButton(); + $this->printGoBackButton( + $this->url.'&page='.($this->page - 1).$task_url + ); } } diff --git a/pandora_console/include/styles/discovery.css b/pandora_console/include/styles/discovery.css index aebb0a3d0d..2bc41163b6 100644 --- a/pandora_console/include/styles/discovery.css +++ b/pandora_console/include/styles/discovery.css @@ -94,3 +94,11 @@ div.data_container:hover { .arrow_box.selected:before { border-left-color: #82b92e; } +.arrow_box { + display: inline-block; + position: relative; + padding: 14px; + margin-left: 20px; + margin-bottom: 10px; + padding-left: 3em; +} diff --git a/pandora_console/include/styles/hostdevices.css b/pandora_console/include/styles/hostdevices.css new file mode 100644 index 0000000000..461327705e --- /dev/null +++ b/pandora_console/include/styles/hostdevices.css @@ -0,0 +1,3 @@ +/* + * TODO: This may be at hostdevices.css + */