add custom net scan

Former-commit-id: 61df342754f17b2ecfe3ad06055e9c5b73617d03
This commit is contained in:
daniel 2019-03-06 17:14:32 +01:00
parent 40bc938000
commit d722c39393
4 changed files with 136 additions and 11 deletions

View File

@ -584,7 +584,11 @@ class DiscoveryTaskList extends Wizard
return 'wiz=ctask';
default:
return 'wiz=hd&mode=netscan';
if ($task['id_recon_script'] === null) {
return 'wiz=hd&mode=netscan';
} else {
return 'wiz=hd&mode=customnetscan';
}
}
}

View File

@ -28,7 +28,9 @@
require_once __DIR__.'/Wizard.main.php';
require_once $config['homedir'].'/include/functions_users.php';
enterprise_include('include/class/CSVImportAgents.class.php');
enterprise_include_once('include/class/CSVImportAgents.class.php');
enterprise_include_once('include/class/CustomNetScan.class.php');
enterprise_include_once('include/class/ManageNetScanScripts.class.php');
enterprise_include_once('include/functions_hostdevices.php');
/**
@ -117,12 +119,25 @@ class HostDevices extends Wizard
'icon' => 'images/wizard/netscan.png',
'label' => __('Net Scan'),
];
if (enterprise_installed()) {
$buttons[] = [
'url' => $this->url.'&mode=importcsv',
'icon' => ENTERPRISE_DIR.'/images/wizard/csv.png',
'label' => __('Import CSV'),
];
$buttons[] = [
'url' => $this->url.'&mode=customnetscan',
'icon' => ENTERPRISE_DIR.'/images/wizard/customnetscan.png',
'label' => __('Custom NetScan'),
];
$buttons[] = [
'url' => $this->url.'&mode=managenetscanscripts',
'icon' => ENTERPRISE_DIR.'/images/wizard/managenetscanscripts.png',
'label' => __('Manage NetScan scripts'),
];
}
$this->prepareBreadcrum(
@ -143,10 +158,29 @@ class HostDevices extends Wizard
}
if (enterprise_installed()) {
if ($mode == 'importcsv') {
$csv_importer = new CSVImportAgents($this->page, $this->breadcrum);
if ($mode === 'importcsv') {
$csv_importer = new CSVImportAgents(
$this->page,
$this->breadcrum
);
return $csv_importer->runCSV();
}
if ($mode === 'customnetscan') {
$customnetscan_importer = new CustomNetScan(
$this->page,
$this->breadcrum
);
return $customnetscan_importer->runCustomNetScan();
}
if ($mode === 'managenetscanscripts') {
$managenetscanscript_importer = new ManageNetScanScripts(
$this->page,
$this->breadcrum
);
return $managenetscanscript_importer->runManageNetScanScript();
}
}
if ($mode == 'netscan') {

View File

@ -572,14 +572,18 @@ class Wizard
{
$output = '';
if ($input['hidden'] == 1) {
$class = ' class="hidden"';
$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.'>';
$output .= '<li id="'.$input['block_id'].'" class="'.$class.'">';
$output .= '<ul class="wizard">';
foreach ($input['block_content'] as $input) {
$output .= $this->printBlock($input, $return);
@ -588,7 +592,7 @@ class Wizard
$output .= '</ul></li>';
} else {
if ($input['arguments']['type'] != 'hidden') {
$output .= '<li id="'.$input['id'].'" '.$class.'>';
$output .= '<li id="'.$input['id'].'" class="'.$class.'">';
$output .= '<label>'.$input['label'].'</label>';
$output .= $this->printInput($input['arguments']);
// Allow dynamic content.

View File

@ -834,12 +834,10 @@ function add_macro_field(macro, row_model_id) {
$("#" + row_id)
.children()
.eq(1)
.children()
.attr("id", "text-" + macro_macro);
$("#" + row_id)
.children()
.eq(1)
.children()
.attr("name", macro_macro);
macro_field_hide = false;
@ -859,13 +857,11 @@ function add_macro_field(macro, row_model_id) {
$("#" + row_id)
.children()
.eq(1)
.children()
.attr("type", "password");
}
$("#" + row_id)
.children()
.eq(1)
.children()
.val(macro_value);
$("#" + row_id).show();
@ -1121,3 +1117,90 @@ function delete_macro(num) {
// Do not decrease the macro counter or new macros may overlap existing ones!
}
function get_explanation_recon_script(id, id_rt, url) {
var xhrManager = function() {
var manager = {};
manager.tasks = [];
manager.addTask = function(xhr) {
manager.tasks.push(xhr);
};
manager.stopTasks = function() {
while (manager.tasks.length > 0) manager.tasks.pop().abort();
};
return manager;
};
var taskManager = new xhrManager();
// Stop old ajax tasks.
taskManager.stopTasks();
// Show the spinners.
$("#textarea_explanation").hide();
$("#spinner_layout").show();
var xhr = jQuery.ajax({
data: {
page: "enterprise/include/ajax/hostDevices.ajax",
get_explanation: 1,
id: id,
id_rt: id_rt
},
url: url,
type: "POST",
dataType: "text",
complete: function(xhr, textStatus) {
$("#spinner_layout").hide();
},
success: function(data, textStatus, xhr) {
$("#textarea_explanation").val(data);
$("#textarea_explanation").show();
},
error: function(xhr, textStatus, errorThrown) {
console.log(errorThrown);
}
});
taskManager.addTask(xhr);
// Delete all the macro fields.
$(".macro_field").remove();
$("#spinner_recon_script").show();
var xhr = jQuery.ajax({
data: {
page: "enterprise/include/ajax/hostDevices.ajax",
get_recon_script_macros: 1,
id: id,
id_rt: id_rt
},
url: url,
type: "POST",
dataType: "json",
complete: function(xhr, textStatus) {
$("#spinner_recon_script").hide();
forced_title_callback();
},
success: function(data, textStatus, xhr) {
if (data.array !== null) {
$("#hidden-macros").val(data.base64);
jQuery.each(data.array, function(i, macro) {
if (macro.desc != "") {
add_macro_field(macro, "table_recon-macro");
}
});
}
},
error: function(xhr, textStatus, errorThrown) {
console.log(errorThrown);
}
});
taskManager.addTask(xhr);
}