WIP: H&D merge

Former-commit-id: d53f7d5abed5cfc8d45e6a42bfd52089ff463ff3
This commit is contained in:
fbsanchez 2019-02-14 17:14:01 +01:00
parent 0d7ea0d056
commit 7df9d4f78b
4 changed files with 344 additions and 32 deletions

View File

@ -27,13 +27,6 @@ class HostDevices extends Wizard
*/
public $result;
/**
* Undocumented variable
*
* @var [type]
*/
public $id;
/**
* Undocumented variable
*
@ -69,6 +62,13 @@ class HostDevices extends Wizard
*/
public $page;
/**
* Stores all needed parameters to create a recon task.
*
* @var array
*/
public $task;
/**
* Undocumented function.
@ -88,7 +88,7 @@ class HostDevices extends Wizard
) {
$this->setBreadcrum([]);
$this->id = null;
$this->task = [];
$this->msg = $msg;
$this->icon = $icon;
$this->label = $label;
@ -488,21 +488,7 @@ class HostDevices extends Wizard
'action' => '#',
];
$form['js'] = '
$("select#interval_manual_defined").change(function() {
if ($("#interval_manual_defined").val() == 1) {
$("#interval_manual_container").hide();
$("#text-interval_text").val(0);
$("#hidden-interval").val(0);
}
else {
$("#interval_manual_container").show();
$("#text-interval_text").val(10);
$("#hidden-interval").val(600);
$("#interval_units").val(60);
}
}).change();';
// XXX: Could be improved validating inputs before continue (JS)
// Print NetScan page 0.
$this->printForm($form);
}
@ -510,7 +496,268 @@ class HostDevices extends Wizard
if ($this->page == 1) {
// Page 1.
echo 'page 1!';
$form = [];
// Hidden, id_rt.
$form['inputs'][] = [
'arguments' => [
'name' => 'task',
'value' => $this->task['id_rt'],
'type' => 'hidden',
'return' => true,
],
];
// Hidden, page.
$form['inputs'][] = [
'arguments' => [
'name' => 'page',
'value' => ($this->page + 1),
'type' => 'hidden',
'return' => true,
],
];
$form['inputs'][] = [
'extra' => '<p>Please, configure task <b>'.io_safe_output($this->task['name']).'</b></p>',
];
// Input: Module template.
$form['inputs'][] = [
'label' => __('Module template'),
'arguments' => [
'name' => 'id_network_profile',
'type' => 'select_from_sql',
'sql' => 'SELECT id_np, name
FROM tnetwork_profile
ORDER BY name',
'return' => true,
],
];
// Feature configuration.
// Input: Module template.
$form['inputs'][] = [
'label' => __('SNMP enabled'),
'arguments' => [
'name' => 'snmp_enabled',
'type' => 'switch',
'return' => true,
'onclick' => "\$('#snmp_extra').toggle();",
],
];
// SNMP CONFIGURATION.
$form['inputs'][] = [
'hidden' => 1,
'block_id' => 'snmp_extra',
'block_content' => [
'label' => __('SNMP version'),
'arguments' => [
'name' => 'auth_strings',
'fields' => [
'1' => 'v. 1',
'2c' => 'v. 2c',
'3' => 'v. 3',
],
'type' => 'select',
'script' => "\$('#snmp_options_v'+this.value).toggle()",
'return' => true,
],
],
];
$form['inputs'][] = [
'hidden' => 1,
'block_id' => 'snmp_options_v1',
'block_content' => [
'label' => __('Community'),
'arguments' => [
'name' => 'community',
'type' => 'text',
'size' => 25,
'return' => true,
],
],
];
// Input: WMI enabled.
$form['inputs'][] = [
'label' => __('WMI enabled'),
'arguments' => [
'name' => 'wmi_enabled',
'type' => 'switch',
'return' => true,
'onclick' => "\$('#wmi_extra').toggle();",
],
];
// WMI CONFIGURATION.
$form['inputs'][] = [
'label' => __('WMI Auth. strings'),
'hidden' => 1,
'id' => 'wmi_extra',
'arguments' => [
'name' => 'auth_strings',
'type' => 'text',
'return' => true,
],
];
// Input: Module template.
$form['inputs'][] = [
'label' => __('OS detection'),
'arguments' => [
'name' => 'os_detect',
'type' => 'switch',
'return' => true,
],
];
// Input: Name resolution.
$form['inputs'][] = [
'label' => __('Name resolution'),
'arguments' => [
'name' => 'resolve_names',
'type' => 'switch',
'return' => true,
],
];
// Input: Parent detection.
$form['inputs'][] = [
'label' => __('Parent detection'),
'arguments' => [
'name' => 'parent_detection',
'type' => 'switch',
'return' => true,
],
];
// Input: VLAN enabled.
$form['inputs'][] = [
'label' => __('VLAN enabled'),
'arguments' => [
'name' => 'os_detect',
'type' => 'switch',
'return' => true,
],
];
// Submit button.
$form['inputs'][] = [
'arguments' => [
'name' => 'submit',
'label' => __('Next'),
'type' => 'submit',
'attributes' => 'class="sub next"',
'return' => true,
],
];
$form['form'] = [
'method' => 'POST',
'action' => '#',
];
$this->printForm($form);
}
if ($this->page == 2) {
// Interval and schedules.
$interv_manual = 0;
if ((int) $interval == 0) {
$interv_manual = 1;
}
$form['inputs'][] = [
'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',
$interval,
'',
'',
'0',
false,
true,
false,
false
).ui_print_help_tip(
__('The minimum recomended interval for Recon Task is 5 minutes'),
true
).'</span>',
];
// Hidden, id_rt.
$form['inputs'][] = [
'arguments' => [
'name' => 'task',
'value' => $this->task['id_rt'],
'type' => 'hidden',
'return' => true,
],
];
// Hidden, page.
$form['inputs'][] = [
'arguments' => [
'name' => 'page',
'value' => ($this->page + 1),
'type' => 'hidden',
'return' => true,
],
];
// Submit button.
$form['inputs'][] = [
'arguments' => [
'name' => 'submit',
'label' => __('Next'),
'type' => 'submit',
'attributes' => 'class="sub next"',
'return' => true,
],
];
$form['form'] = [
'method' => 'POST',
'action' => '#',
];
$form['js'] = '
$("select#interval_manual_defined").change(function() {
if ($("#interval_manual_defined").val() == 1) {
$("#interval_manual_container").hide();
$("#text-interval_text").val(0);
$("#hidden-interval").val(0);
}
else {
$("#interval_manual_container").show();
$("#text-interval_text").val(10);
$("#hidden-interval").val(600);
$("#interval_units").val(60);
}
}).change();';
$this->printForm($form);
}
if ($this->page == 100) {

View File

@ -95,7 +95,7 @@ class Wizard
*
* @return string HTML code for desired input.
*/
public function printInput(array $data)
public function printInput($data)
{
if (is_array($data) === false) {
return '';
@ -286,6 +286,20 @@ class Wizard
((isset($data['return']) === true) ? $data['return'] : false)
);
case 'checkbox':
return html_print_checkbox(
$data['name'],
$data['value'],
((isset($data['checked']) === true) ? $data['checked'] : false),
((isset($data['return']) === true) ? $data['return'] : false),
((isset($data['disabled']) === true) ? $data['disabled'] : false),
((isset($data['script']) === true) ? $data['script'] : ''),
((isset($data['disabled_hidden']) === true) ? $data['disabled_hidden'] : false)
);
case 'switch':
return html_print_switch($data);
default:
// Ignore.
break;
@ -295,10 +309,60 @@ class Wizard
}
/**
* Print a block of inputs.
*
* @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)
{
$output = '';
if ($input['hidden'] == 1) {
$class = ' class="hidden"';
} else {
$class = '';
}
if (is_array($input['block_content']) === true) {
// Print independent block of inputs.
$output .= '<li id="'.$input['block_id'].'" '.$class.'>';
$output .= '<ul class="wizard">';
foreach ($input['block_content'] as $input) {
$output .= $this->printBlock($input, $return);
}
$output .= '</ul></li>';
} else {
if ($input['arguments']['type'] != 'hidden') {
$output .= '<li id="'.$input['id'].'" '.$class.'>';
$output .= '<label>'.$input['label'].'</label>';
$output .= $this->printInput($input['arguments']);
// Allow dynamic content.
$output .= $input['extra'];
$output .= '</li>';
} else {
$output .= $this->printInput($input['arguments']);
// Allow dynamic content.
$output .= $input['extra'];
}
}
if ($return === false) {
echo $output;
}
return $output;
}
/**
* Print a form.
*
* @param array $data Definition of target form to be printed.
* @param array $data Definition of target form to be printed.
* @param boolean $return Return as string or direct output.
*
* @return string HTML code.
*/
@ -314,11 +378,7 @@ class Wizard
$output .= '<ul class="wizard">';
foreach ($inputs as $input) {
$output .= '<li><label>'.$input['label'].'</label>';
$output .= $this->printInput($input['arguments']);
// Allow dynamic content.
$output .= $input['extra'];
$output .= '</li>';
$output .= $this->printBlock($input, true);
}
$output .= '</ul>';

View File

@ -3016,6 +3016,7 @@ function html_print_switch($attributes=[])
'id',
'class',
'name',
'onclick',
];
foreach ($valid_attrs as $va) {
if (!isset($attributes[$va])) {

View File

@ -5,7 +5,11 @@ ul.wizard li {
padding: 10px;
}
ul.wizard li > label {
ul.wizard li > label:not(.p-switch) {
width: 250px;
display: inline-block;
}
.hidden {
display: none;
}