From 13b32003b37c8dbf155cfba75ed830ed761281af Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Thu, 16 May 2019 11:37:48 +0200 Subject: [PATCH] save changes ticket 3937 Former-commit-id: 264c0fed3ddcf7c34796af0a3c2bd4d48a6763bb --- .../godmode/wizards/HostDevices.class.php | 266 +++++++++--------- .../godmode/wizards/Wizard.main.php | 167 ++++++++++- .../include/class/CustomNetScan.class.php | 4 +- 3 files changed, 290 insertions(+), 147 deletions(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index cd7f52f0df..c6ee1b1c6b 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -594,106 +594,120 @@ class HostDevices extends Wizard if (isset($this->page) === false || $this->page == 0 ) { - // Comment input - $comment_input = '
'; + $form = []; - $comment_input .= $this->printInput( - [ - 'name' => 'comment', - 'rows' => 1, - 'columns' => 1, - 'value' => $this->task['description'], - 'type' => 'textarea', - 'size' => 25, - 'class' => 'discovery_textarea_input', - 'return' => true, - ] - ); + $str = __('Next'); - // Task input - $taskname_input_label = '
'; + if (isset($this->task['id_rt']) === true) { + $str = __('Update and continue'); + } - $taskname_input = $this->printInput( - [ - 'name' => 'taskname', - 'value' => $this->task['name'], - 'type' => 'text', - 'size' => 25, - 'class' => 'discovery_full_width_input', - ] - ); - - // Network input - $network_input_label .= '
'.ui_print_help_tip(__('You can specify several networks, separated by commas, for example: 192.168.50.0/24,192.168.60.0/24'), true).'
'; - - $network_input = $this->printInput( - [ - 'name' => 'network', - 'value' => $this->task['subnet'], - 'type' => 'text', - 'size' => 25, - 'class' => 'discovery_full_width_input', - ] - ); - - // Discovery server input - $discovery_server_select_label = '
'.ui_print_help_tip(__('You must select a Discovery Server to run the Task, otherwise the Recon Task will never run'), true).'
'; - - $discovery_server_select = $this->printInput( - [ - 'type' => 'select_from_sql', - 'sql' => sprintf( - 'SELECT id_server, name - FROM tserver - WHERE server_type = %d - ORDER BY name', - SERVER_TYPE_DISCOVERY - ), - 'name' => 'id_recon_server', - 'selected' => $this->task['id_recon_server'], - 'return' => true, - 'style' => 'width: 100%', - ] - ); - - // Interval input + // Interval and schedules. $interv_manual = 0; if ((int) $this->task['interval_sweep'] == 0) { $interv_manual = 1; } - $interval_input_label = '
'.ui_print_help_tip(__('Manual interval means that it will run only on demand.'), true).'
'; - - $interval_input = $this->printInput( - [ - 'type' => 'select', - 'selected' => $interv_manual, - 'fields' => [ - 0 => __('Defined'), - 1 => __('Manual'), + $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, + ], ], - 'name' => 'interval_manual_defined', - 'return' => true, - 'style' => 'float: right;', - ] - ); + '1' => '
'.html_print_image('images/wizard/netscan_green.png', true, ['title' => __('Close')], false).'
', + '2' => [ + 'label' => ''.__('Interval').':'.ui_print_help_tip( + __('Manual interval means that it will be executed only On-demand'), + true + ), + 'arguments' => [ + 'type' => 'select', + 'selected' => $interv_manual, + 'fields' => [ + 0 => __('Defined'), + 1 => __('Manual'), + ], + 'name' => 'interval_manual_defined', + 'return' => true, + ], + 'extra' => ''.html_print_extended_select_for_time( + 'interval', + $this->task['interval_sweep'], + '', + '', + '0', + false, + true, + false, + false + ).ui_print_help_tip( + __('The minimum recomended interval for Recon Task is 5 minutes'), + true + ).'', - $interval_input_extra = ''.html_print_extended_select_for_time( - 'interval', - $this->task['interval_sweep'], - '', - '', - '0', - false, - true, - false, - false - ).ui_print_help_tip( - __('The minimum recomended interval for Recon Task is 5 minutes'), - true - ).''; + ], + ], + ]; - // Group select + $form['rows'][0]['columns'][1] = [ + 'width' => '40%', + 'padding-right' => '12%', + 'padding-left' => '5%', + 'inputs' => [ + '0' => [ + 'label' => ''.__('Task name').':', + 'arguments' => [ + 'name' => 'taskname', + 'value' => $this->task['name'], + 'type' => 'text', + 'size' => 25, + 'class' => 'discovery_full_width_input', + ], + ], + '1' => [ + 'label' => ''.__('Discovery server').':'.ui_print_help_tip( + __('You must select a Discovery Server to run the Task, otherwise the Recon Task will never run'), + true + ), + 'arguments' => [ + 'type' => 'select_from_sql', + 'sql' => sprintf( + 'SELECT id_server, name + FROM tserver + WHERE server_type = %d + ORDER BY name', + SERVER_TYPE_DISCOVERY + ), + 'name' => 'id_recon_server', + 'style' => 'width: 100%;', + 'selected' => $this->task['id_recon_server'], + 'return' => true, + ], + ], + '2' => [ + 'label' => ''.__('Network').':'.ui_print_help_tip( + __('You can specify several networks, separated by commas, for example: 192.168.50.0/24,192.168.60.0/24'), + true + ), + 'arguments' => [ + 'name' => 'network', + 'value' => $this->task['subnet'], + 'type' => 'text', + 'size' => 25, + 'class' => 'discovery_full_width_input', + ], + ], + ], + ]; + + // Group select (custom for this section) $group_select = '
'; $group_select .= $this->printInput( @@ -710,22 +724,41 @@ class HostDevices extends Wizard ] ); - if (isset($this->task['id_rt']) === true) { - // Propagate ID - $task_hidden = $this->printInput( - [ - 'name' => 'task', - 'value' => $this->task['id_rt'], - 'type' => 'hidden', - ] - ); - } + $form['rows'][0]['columns'][2] = [ + 'width' => '30%', + 'inputs' => ['0' => $group_select], + ]; + + $form['rows'][1]['style'] = 'style de row'; + $form['rows'][1]['columns'][0] = [ + 'padding-right' => '0', + 'inputs' => [ + '0' => [ + 'label' => ''.__('Comment').':', + 'arguments' => [ + 'name' => 'comment', + 'rows' => 1, + 'columns' => 1, + 'value' => $this->task['description'], + 'type' => 'textarea', + 'size' => 25, + 'class' => 'discovery_textarea_input', + 'return' => true, + ], + ], + ], + ]; $task_url = ''; if (isset($this->task['id_rt'])) { $task_url = '&task='.$this->task['id_rt']; } + $form['form'] = [ + 'method' => 'POST', + 'action' => $this->url.'&mode=netscan&page='.($this->page + 1).$task_url, + ]; + // Default. $interval = 600; $unit = 60; @@ -734,34 +767,7 @@ class HostDevices extends Wizard $unit = $this->getTimeUnit($interval); } - // XXX: Could be improved validating inputs before continue (JS) - // Print NetScan page 0. - // $this->printForm($form); - echo '
'; - echo $task_hidden; - - echo '
-
-
'.'
'.html_print_image('images/wizard/netscan_green.png', true, ['title' => __('Close')], false).'
'.'
'.$interval_input_label.'
'.$interval_input.'
'.$interval_input_extra.'
'.'
- -
-
'.$taskname_input_label.'
'.$taskname_input.'
'.'
'.$discovery_server_select_label.$discovery_server_select.'
'.'
'.$network_input_label.'
'.$network_input.'
'.'
'.'
'.$group_select.'
'.'
'.'
-
- '.$comment_input.' -
-
'.'
'; - - $str = __('Next'); - - if (isset($this->task['id_rt']) === true) { - $str = __('Update and continue'); - } - - echo '
'.html_print_submit_button($str, 'submit', false, 'class="sub next"', true).'
'; - echo '
'; - - echo ''; + $this->printFormAsGrid($form); } } @@ -870,7 +876,7 @@ class HostDevices extends Wizard 'action' => $this->url.'&mode=netscan&page='.($this->page + 1).'&task='.$this->task['id_rt'], ]; - $this->printForm($form, false, true); + $this->printFormAsList($form); } if ($this->page == 2) { diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index dab50570f9..c05bbcf6b8 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -572,14 +572,14 @@ class Wizard /** - * Print a block of inputs. + * Print a block of inputs with grid format. * * @param array $input Definition of target block to be printed. * @param boolean $return Return as string or direct output. * * @return string HTML content. */ - public function printBlock(array $input, bool $return=false) + public function printBlockAsGrid(array $input, bool $return=false) { $output = ''; if ($input['hidden'] == 1) { @@ -597,7 +597,69 @@ class Wizard $output .= '
  • '; $output .= '
  • '; + } else { + if ($input['arguments']['type'] != 'hidden') { + $output .= '
    '; + $output .= '
    '; + $output .= $input['label']; + $output .= '
    '; + if ($input['arguments']['type'] == 'text') { + $output .= '
    '; + $output .= $this->printInput($input['arguments']); + $output .= '
    '; + } else { + $output .= $this->printInput($input['arguments']); + } + + // Allow dynamic content. + $output .= $input['extra']; + $output .= '
    '; + } else { + $output .= $this->printInput($input['arguments']); + // Allow dynamic content. + $output .= $input['extra']; + } + } + + if ($return === false) { + echo $output; + } + + return $output; + } + + + /** + * Print a block of inputs as a list element. + * + * @param array $input Definition of target block to be printed. + * @param boolean $return Return as string or direct output. + * + * @return string HTML content. + */ + public function printBlockAsList(array $input, bool $return=false) + { + $output = ''; + if ($input['hidden'] == 1) { + $class = ' hidden'; + } else { + $class = ''; + } + + if (isset($input['class']) === true) { + $class = $input['class'].$class; + } + + if (is_array($input['block_content']) === true) { + // Print independent block of inputs. + $output .= '
  • '; + $output .= '
  • '; @@ -625,17 +687,19 @@ class Wizard /** - * Print a form. + * Print a form as a grid of inputs. * * @param array $data Definition of target form to be printed. * @param boolean $return Return as string or direct output. * * @return string HTML code. */ - public function printForm(array $data, bool $return=false, bool $print_white_box=false) + public function printFormAsGrid(array $data, bool $return=false) { $form = $data['form']; - $inputs = $data['inputs']; + + $rows = $data['rows']; + $js = $data['js']; $cb_function = $data['cb_function']; $cb_args = $data['cb_args']; @@ -661,26 +725,99 @@ class Wizard $output_submit = ''; $output = ''; - if ($print_white_box === true) { - $output .= '
    '; + $output .= '
    '; + + foreach ($rows as $row) { + $output .= '
    '; + + foreach ($row['columns'] as $column) { + $width = isset($column['width']) ? 'width: '.$column['width'].';' : 'width: 100%;'; + $padding_left = isset($column['padding-left']) ? 'padding-left: '.$column['padding-left'].';' : 'padding-left: 0;'; + $padding_right = isset($column['padding-right']) ? 'padding-right: '.$column['padding-right'].';' : 'padding-right: 0;'; + $extra_styles = isset($column['style']) ? $column['style'] : ''; + + $output .= '
    '; + + foreach ($column['inputs'] as $input) { + if (is_array($input)) { + if ($input['arguments']['type'] != 'submit') { + $output .= $this->printBlockAsGrid($input, true); + } else { + $output_submit .= $this->printBlockAsGrid($input, true); + } + } else { + $output .= $input; + } + } + + $output .= '
    '; + } + + $output .= '
    '; } + $output .= '
    '; + + $output .= ''; + $output .= ''; + $output .= ''; + + if ($return === false) { + echo $output; + } + + return $output_head.$output; + + } + + + /** + * Print a form as a list. + * + * @param array $data Definition of target form to be printed. + * @param boolean $return Return as string or direct output. + * + * @return string HTML code. + */ + public function printFormAsList(array $data, bool $return=false) + { + $form = $data['form']; + $inputs = $data['inputs']; + $js = $data['js']; + $cb_function = $data['cb_function']; + $cb_args = $data['cb_args']; + + $output_head = '
    '; + + if ($return === false) { + echo $output_head; + } + + try { + if (isset($cb_function) === true) { + call_user_func_array( + $cb_function, + (isset($cb_args) === true) ? $cb_args : [] + ); + } + } catch (Exception $e) { + error_log('Error executing wizard callback: ', $e->getMessage()); + } + + $output = '
    '; $output .= '
      '; foreach ($inputs as $input) { if ($input['arguments']['type'] != 'submit') { - $output .= $this->printBlock($input, true); + $output .= $this->printBlockAsList($input, true); } else { - $output_submit .= $this->printBlock($input, true); + $output_submit .= $this->printBlockAsList($input, true); } } $output .= '
    '; - - if ($print_white_box === true) { - $output .= '
    '; - } - + $output .= '
    '; $output .= ''; $output .= ''; $output .= ''; diff --git a/pandora_console/include/class/CustomNetScan.class.php b/pandora_console/include/class/CustomNetScan.class.php index dc28a696e7..c8450e9ea3 100644 --- a/pandora_console/include/class/CustomNetScan.class.php +++ b/pandora_console/include/class/CustomNetScan.class.php @@ -594,7 +594,7 @@ class CustomNetScan extends Wizard // XXX: Could be improved validating inputs before continue (JS) // Print NetScan page 0. - $this->printForm($form, false, true); + $this->printFormAsList($form); } } @@ -742,7 +742,7 @@ class CustomNetScan extends Wizard get_explanation_recon_script($(this).val(), "'.$id_task.'", "'.$url_ajax.'"); })'.$change; - $this->printForm($form, false, true); + $this->printFormAsList($form); } if (isset($this->page) === true && $this->page === 2) {