save changes ticket 3937

Former-commit-id: 264c0fed3ddcf7c34796af0a3c2bd4d48a6763bb
This commit is contained in:
alejandro-campos 2019-05-16 11:37:48 +02:00
parent 874f4764ea
commit 13b32003b3
3 changed files with 290 additions and 147 deletions

View File

@ -594,106 +594,120 @@ class HostDevices extends Wizard
if (isset($this->page) === false
|| $this->page == 0
) {
// Comment input
$comment_input = '<div class="label_select"><label>'.__('Comment').':</label></div>';
$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 = '<div class="label_select"><label>'.__('Task name').':</label></div>';
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 .= '<div class="label_select discovery_label_hint"><label>'.__('Network').':</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).'</div>';
$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 = '<div class="label_select discovery_label_hint"><label>'.__('Discovery server').':</label>'.ui_print_help_tip(__('You must select a Discovery Server to run the Task, otherwise the Recon Task will never run'), true).'</div>';
$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 = '<div class="label_select discovery_label_hint" style="padding-top: 6px;"><label>'.__('Interval').':</label>'.ui_print_help_tip(__('Manual interval means that it will run only on demand.'), true).'</div>';
$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' => '<div style="height: 50%; margin-bottom: 35px;">'.html_print_image('images/wizard/netscan_green.png', true, ['title' => __('Close')], false).'</div>',
'2' => [
'label' => '<b>'.__('Interval').':</b>'.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' => '<span id="interval_manual_container">'.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
).'</span>',
$interval_input_extra = '<span id="interval_manual_container">'.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
).'</span>';
],
],
];
// Group select
$form['rows'][0]['columns'][1] = [
'width' => '40%',
'padding-right' => '12%',
'padding-left' => '5%',
'inputs' => [
'0' => [
'label' => '<b>'.__('Task name').':</b>',
'arguments' => [
'name' => 'taskname',
'value' => $this->task['name'],
'type' => 'text',
'size' => 25,
'class' => 'discovery_full_width_input',
],
],
'1' => [
'label' => '<b>'.__('Discovery server').':</b>'.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' => '<b>'.__('Network').':</b>'.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 = '<div class="label_select"><label>'.__('Group').':</label></div>';
$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' => '<b>'.__('Comment').':</b>',
'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 '<form action="'.$this->url.'&mode=netscan&page='.($this->page + 1).$task_url.'" method="POST">';
echo $task_hidden;
echo '<div class="white_box">
<div class="edit_discovery_info" style="margin-bottom: 15px;">
<div style="width: 25%; padding: 9px;">'.'<div style="height: 50%; margin-bottom: 35px;">'.html_print_image('images/wizard/netscan_green.png', true, ['title' => __('Close')], false).'</div>'.'<div class="edit_discovery_input"><div style="display: flex;">'.$interval_input_label.'<div style="margin-left: 15 px; width: 50%;">'.$interval_input.'</div></div>'.$interval_input_extra.'</div>'.'</div>
<div style="width: 40%; padding-left: 5%; padding-right: 12%;">
<div class="edit_discovery_input">'.$taskname_input_label.'<div class="discovery_text_input">'.$taskname_input.'</div></div>'.'<div class="edit_discovery_input discovery_select_input">'.$discovery_server_select_label.$discovery_server_select.'<div class="discovery_hint"></div></div>'.'<div class="edit_discovery_input">'.$network_input_label.'<div class="discovery_text_input">'.$network_input.'</div></div>'.'</div>'.'<div style="width: 35%;">'.$group_select.'</div>'.'</div>'.'<div class="edit_discovery_info">
<div style="width: 100%;">
'.$comment_input.'
</div>
</div>'.'</div>';
$str = __('Next');
if (isset($this->task['id_rt']) === true) {
$str = __('Update and continue');
}
echo '<div class="action-buttons" style="width: 100%; margin-top: 10px;">'.html_print_submit_button($str, 'submit', false, 'class="sub next"', true).'</div>';
echo '</form>';
echo '<script>
$form['js'] = '
$("select#interval_manual_defined").change(function() {
if ($("#interval_manual_defined").val() == 1) {
$("#interval_manual_container").hide();
@ -774,9 +780,9 @@ class HostDevices extends Wizard
$("#hidden-interval").val('.$interval.');
$("#interval_units").val('.$unit.');
}
}).change();
}).change();';
</script>';
$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) {

View File

@ -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 .= '<li id="'.$input['block_id'].'" class="'.$class.'">';
$output .= '<ul class="wizard">';
foreach ($input['block_content'] as $input) {
$output .= $this->printBlock($input, $return);
$output .= $this->printBlockAsGrid($input, $return);
}
$output .= '</ul></li>';
} else {
if ($input['arguments']['type'] != 'hidden') {
$output .= '<div class="edit_discovery_input">';
$output .= '<div class="label_select">';
$output .= $input['label'];
$output .= '</div>';
if ($input['arguments']['type'] == 'text') {
$output .= '<div class="discovery_text_input">';
$output .= $this->printInput($input['arguments']);
$output .= '</div>';
} else {
$output .= $this->printInput($input['arguments']);
}
// Allow dynamic content.
$output .= $input['extra'];
$output .= '</div>';
} 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 .= '<li id="'.$input['block_id'].'" class="'.$class.'">';
$output .= '<ul class="wizard">';
foreach ($input['block_content'] as $input) {
$output .= $this->printBlockAsList($input, $return);
}
$output .= '</ul></li>';
@ -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 .= '<div class="white_box">';
$output .= '<div class="white_box">';
foreach ($rows as $row) {
$output .= '<div class="edit_discovery_info" style="'.$row['style'].'">';
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 .= '<div style="'.$width.$padding_left.$padding_right.$extra_styles.'">';
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 .= '</div>';
}
$output .= '</div>';
}
$output .= '</div>';
$output .= '<ul class="wizard">'.$output_submit.'</ul>';
$output .= '</form>';
$output .= '<script>'.$js.'</script>';
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 = '<form enctype="'.$form['enctype'].'" action="'.$form['action'].'" method="'.$form['method'];
$output_head .= '" '.$form['extra'].'>';
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 = '<div class="white_box">';
$output .= '<ul class="wizard">';
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 .= '</ul>';
if ($print_white_box === true) {
$output .= '</div>';
}
$output .= '</div>';
$output .= '<ul class="wizard">'.$output_submit.'</ul>';
$output .= '</form>';
$output .= '<script>'.$js.'</script>';

View File

@ -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) {