Former-commit-id: c3b0b6f56ff0591f8c5839d61144bbb72ddd7033
This commit is contained in:
fbsanchez 2019-02-14 10:56:25 +01:00
parent 10a37c313c
commit 0db88817a9
4 changed files with 300 additions and 88 deletions

View File

@ -1,11 +1,11 @@
<?php
require_once __DIR__.'/Wizard.interface.php';
require_once __DIR__.'/Wizard.main.php';
/**
* Undocumented class
*/
class HostDevices implements Wizard
class HostDevices extends Wizard
{
/**
@ -15,18 +15,53 @@ class HostDevices implements Wizard
*/
public $values = [];
/**
* Undocumented variable
*
* @var [type]
*/
public $result;
/**
* Undocumented variable
*
* @var [type]
*/
public $id;
/**
* Undocumented variable
*
* @var [type]
*/
public $msg;
/**
* Undocumented variable
*
* @var [type]
*/
public $icon;
/**
* Undocumented variable
*
* @var [type]
*/
public $label;
/**
* Undocumented variable
*
* @var [type]
*/
public $url;
/**
* Undocumented variable
*
* @var [type]
*/
public $page;
@ -105,7 +140,7 @@ class HostDevices implements Wizard
}
// extra methods
// Extra methods.
/**
@ -333,9 +368,9 @@ class HostDevices implements Wizard
$snmp3_security_level = '';
$id_network_profile = 0;
$id_os = -1;
// Any
// Any.
$recon_ports = '';
// Any
// Any.
$field1 = '';
$field2 = '';
$field3 = '';
@ -508,7 +543,7 @@ class HostDevices implements Wizard
true
).' '.ui_print_help_tip(__('Choose if the discovery of a new system creates an incident or not.'), true);
// snmp_enabled.
// Snmp_enabled.
$table->data[11][0] = '<b>'.__('SNMP enabled');
$table->data[11][1] = html_print_checkbox('snmp_enabled', 1, $snmp_enabled, true);
@ -673,99 +708,99 @@ class HostDevices implements Wizard
echo '</form>';
ui_require_javascript_file('pandora_modules');
?>
<script type="text/javascript">
/* <![CDATA[ */
$(document).ready (function () {
$a = `
<script type="text/javascript">
/* <![CDATA[ */
$(document).ready (function () {
});
});
var xhrManager = function () {
var manager = {};
var xhrManager = function () {
var manager = {};
manager.tasks = [];
manager.tasks = [];
manager.addTask = function (xhr) {
manager.addTask = function (xhr) {
manager.tasks.push(xhr);
}
}
manager.stopTasks = function () {
manager.stopTasks = function () {
while (manager.tasks.length > 0)
manager.tasks.pop().abort();
}
}
return manager;
};
return manager;
};
var taskManager = new xhrManager();
var taskManager = new xhrManager();
$('select#interval_manual_defined').change(function() {
if ($("#interval_manual_defined").val() == 1) {
$('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 {
}
else {
$('#interval_manual_container').show();
$('#text-interval_text').val(10);
$('#hidden-interval').val(600);
$('#interval_units').val(60);
}
}).change();
}
}).change();
$('select#id_recon_script').change(function() {
if ($('select#mode').val() == 'recon_script')
$('select#id_recon_script').change(function() {
if ($('select#mode').val() == 'recon_script')
get_explanation_recon_script($(this).val());
});
});
$('select#snmp_version').change(function () {
if (this.value == "3") {
$('select#snmp_version').change(function () {
if (this.value == "3") {
$(".recon_v3").show();
$("input[name=active_snmp_v3]").val(1);
$("input[name=snmp_community]").attr("disabled", true);
$("input[name=vlan_enabled]").removeAttr("checked");
$("input[name=vlan_enabled]").attr("disabled", true);
}
else {
}
else {
$(".recon_v3").hide();
$("input[name=active_snmp_v3]").val(0);
$("input[name=snmp_community]").removeAttr('disabled');
$("input[name=vlan_enabled]").removeAttr('disabled');
}
});
}
});
$('select#mode').change(function() {
var type = $(this).val();
if (type == 'recon_script') {
$('select#mode').change(function() {
var type = $(this).val();
if (type == 'recon_script') {
$(".recon_script").show();
$(".network_sweep").hide();
get_explanation_recon_script($("#id_recon_script").val());
}
else if (type == 'network_sweep') {
}
else if (type == 'network_sweep') {
$(".recon_script").hide();
$(".network_sweep").show();
$('.macro_field').remove();
$('select#snmp_version').trigger('change');
}
}).change();
}
}).change();
function get_explanation_recon_script (id) {
// Stop old ajax tasks
taskManager.stopTasks();
function get_explanation_recon_script (id) {
// Stop old ajax tasks
taskManager.stopTasks();
// Show the spinners
$("#textarea_explanation").hide();
$("#spinner_layout").show();
// Show the spinners
$("#textarea_explanation").hide();
$("#spinner_layout").show();
var xhr = jQuery.ajax ({
var xhr = jQuery.ajax ({
data: {
'page': 'godmode/servers/manage_recontask_form',
'get_explanation': 1,
'id': id,
'id_rt': <?php echo json_encode((int) $id_rt); ?>
'id_rt': `.json_encode((int) $id_rt).`
},
url: "<?php echo $config['homeurl']; ?>ajax.php",
url: "`.$config['homeurl'].`ajax.php",
type: 'POST',
dataType: 'text',
complete: function (xhr, textStatus) {
@ -778,21 +813,21 @@ function get_explanation_recon_script (id) {
error: function (xhr, textStatus, errorThrown) {
console.log(errorThrown);
}
});
taskManager.addTask(xhr);
});
taskManager.addTask(xhr);
// Delete all the macro fields
$('.macro_field').remove();
$("#spinner_recon_script").show();
// Delete all the macro fields
$('.macro_field').remove();
$("#spinner_recon_script").show();
var xhr = jQuery.ajax ({
var xhr = jQuery.ajax ({
data: {
'page': 'godmode/servers/manage_recontask_form',
'get_recon_script_macros': 1,
'id': id,
'id_rt': <?php echo json_encode((int) $id_rt); ?>
'id_rt': `.json_encode((int) $id_rt).`
},
url: "<?php echo $config['homeurl']; ?>ajax.php",
url: "`.$config['homeurl'].`ajax.php",
type: 'POST',
dataType: 'json',
complete: function (xhr, textStatus) {
@ -813,22 +848,17 @@ function get_explanation_recon_script (id) {
error: function (xhr, textStatus, errorThrown) {
console.log(errorThrown);
}
});
taskManager.addTask(xhr);
}
});
taskManager.addTask(xhr);
}
</script>
<?php
return null;
/*
Page 4, last.
return [
</script>`;
echo $a;
return [
'result' => $this->result,
'id' => $this->id,
'msg' => $this->msg,
];
*/
];
}

View File

@ -1,16 +0,0 @@
<?php
/**
* Interfaz tope gama que obliga a implementar metodos.
*/
interface Wizard
{
public function run();
public function load();
}

View File

@ -0,0 +1,198 @@
<?php
/**
* Interfaz tope gama que obliga a implementar metodos.
*/
class Wizard
{
/**
* To be overwritten.
*
* @return void
*/
public function run()
{
}
/**
* To be overwritten.
*
* @return void
*/
public function load()
{
}
/**
* Print input using functions html lib.
*
* @param array $data Input definition.
*
* @return string HTML code for desired input.
*/
public function printInput(array $data)
{
if (is_array($data) === false) {
return '';
}
switch ($data['type']) {
case 'text':
return html_print_input_text(
$data['name'],
$data['value'],
$data['alt'] = '',
$data['size'] = 50,
$data['maxlength'] = 255,
((isset($data['return']) === true) ? $data['return'] : true),
((isset($data['disabled']) === true) ? $data['disabled'] : false),
((isset($data['required']) === true) ? $data['required'] : false),
((isset($data['function']) === true) ? $data['function'] : ''),
((isset($data['class']) === true) ? $data['class'] : ''),
((isset($data['onChange']) === true) ? $data['onChange'] : ''),
((isset($data['autocomplete']) === true) ? $data['autocomplete'] : '')
);
case 'image':
return html_print_input_image(
$data['name'],
$data['src'],
$data['value'],
((isset($data['style']) === true) ? $data['style'] : ''),
((isset($data['return']) === true) ? $data['return'] : false),
((isset($data['options']) === true) ? $data['options'] : false)
);
case 'text_extended':
return html_print_input_text_extended(
$data['name'],
$data['value'],
$data['id'],
$data['alt'],
$data['size'],
$data['maxlength'],
$data['disabled'],
$data['script'],
$data['attributes'],
((isset($data['return']) === true) ? $data['return'] : false),
((isset($data['password']) === true) ? $data['password'] : false),
((isset($data['function']) === true) ? $data['function'] : '')
);
case 'password':
return html_print_input_password(
$data['name'],
$data['value'],
((isset($data['alt']) === true) ? $data['alt'] : ''),
((isset($data['size']) === true) ? $data['size'] : 50),
((isset($data['maxlength']) === true) ? $data['maxlength'] : 255),
((isset($data['return']) === true) ? $data['return'] : false),
((isset($data['disabled']) === true) ? $data['disabled'] : false),
((isset($data['required']) === true) ? $data['required'] : false),
((isset($data['class']) === true) ? $data['class'] : '')
);
case 'text':
return html_print_input_text(
$data['name'],
$data['value'],
((isset($data['alt']) === true) ? $data['alt'] : ''),
((isset($data['size']) === true) ? $data['size'] : 50),
((isset($data['maxlength']) === true) ? $data['maxlength'] : 255),
((isset($data['return']) === true) ? $data['return'] : false),
((isset($data['disabled']) === true) ? $data['disabled'] : false),
((isset($data['required']) === true) ? $data['required'] : false),
((isset($data['function']) === true) ? $data['function'] : ''),
((isset($data['class']) === true) ? $data['class'] : ''),
((isset($data['onChange']) === true) ? $data['onChange'] : ''),
((isset($data['autocomplete']) === true) ? $data['autocomplete'] : '')
);
case 'image':
return html_print_input_image(
$data['name'],
$data['src'],
$data['value'],
((isset($data['style']) === true) ? $data['style'] : ''),
((isset($data['return']) === true) ? $data['return'] : false),
((isset($data['options']) === true) ? $data['options'] : false)
);
case 'hidden':
return html_print_input_hidden(
$data['name'],
$data['value'],
((isset($data['return']) === true) ? $data['return'] : false),
((isset($data['class']) === true) ? $data['class'] : false)
);
case 'hidden_extended':
return html_print_input_hidden_extended(
$data['name'],
$data['value'],
$data['id'],
((isset($data['return']) === true) ? $data['return'] : false),
((isset($data['class']) === true) ? $data['class'] : false)
);
case 'color':
return html_print_input_color(
$data['name'],
$data['value'],
((isset($data['class']) === true) ? $data['class'] : false),
((isset($data['return']) === true) ? $data['return'] : false)
);
case 'file':
return html_print_input_file(
$data['name'],
((isset($data['return']) === true) ? $data['return'] : false),
((isset($data['options']) === true) ? $data['options'] : false)
);
default:
// Ignore.
break;
}
return '';
}
/**
* Print a form.
*
* @param array $data Definition of target form to be printed.
*
* @return void
*/
public function printForm(array $data)
{
$form = $data['form'];
$inputs = $data['inputs'];
$js = $data['js'];
$output = '<form action="'.$form['action'].'" method="'.$form['method'];
$output .= '" '.$form['extra'].'>';
$ouput .= '<ul>';
foreach ($inputs as $input) {
$output .= '<li><label>'.$input['label'].'</label>';
$output .= '<label>'.$this->printInput($input['var']).'</li>';
}
$output .= '</ul>';
$output .= '</form>';
$output .= $js;
return $output;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB