mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
Merge branch 'ent-5575-wizard-de-modulos-y-recon-by-steps' of brutus.artica.es:artica/pandorafms into ent-5575-wizard-de-modulos-y-recon-by-steps
This commit is contained in:
commit
451cdf2ca1
@ -11,7 +11,7 @@ CREATE TABLE `tdiscovery_tmp_agents` (
|
|||||||
`label` varchar(600) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
|
`label` varchar(600) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
|
||||||
`data` text,
|
`data` text,
|
||||||
`review_date` datetime DEFAULT NULL,
|
`review_date` datetime DEFAULT NULL,
|
||||||
`created` int(1) unsigned NOT NULL DEFAULT '0',
|
`created` datetime DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `id_rt` (`id_rt`),
|
KEY `id_rt` (`id_rt`),
|
||||||
INDEX `label` (`label`),
|
INDEX `label` (`label`),
|
||||||
|
@ -1677,7 +1677,7 @@ CREATE TABLE `tdiscovery_tmp_agents` (
|
|||||||
`label` varchar(600) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
|
`label` varchar(600) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
|
||||||
`data` text,
|
`data` text,
|
||||||
`review_date` datetime DEFAULT NULL,
|
`review_date` datetime DEFAULT NULL,
|
||||||
`created` int(1) unsigned NOT NULL DEFAULT '0',
|
`created` datetime DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `id_rt` (`id_rt`),
|
KEY `id_rt` (`id_rt`),
|
||||||
INDEX `label` (`label`),
|
INDEX `label` (`label`),
|
||||||
|
@ -123,8 +123,9 @@ class DiscoveryTaskList extends HTML
|
|||||||
}
|
}
|
||||||
|
|
||||||
$force_run = (bool) get_parameter('force_run');
|
$force_run = (bool) get_parameter('force_run');
|
||||||
if ($force_run === true) {
|
$force = (bool) get_parameter('force');
|
||||||
return $this->forceConsoleTask();
|
if ($force_run === true || $force === true) {
|
||||||
|
return $this->forceTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
$delete_console_task = (bool) get_parameter('delete_console_task');
|
$delete_console_task = (bool) get_parameter('delete_console_task');
|
||||||
@ -241,7 +242,7 @@ class DiscoveryTaskList extends HTML
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function forceConsoleTask()
|
public function forceTask()
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
@ -256,12 +257,46 @@ class DiscoveryTaskList extends HTML
|
|||||||
|
|
||||||
$id_console_task = (int) get_parameter('id_console_task');
|
$id_console_task = (int) get_parameter('id_console_task');
|
||||||
|
|
||||||
if ($id_console_task !== null) {
|
if ($id_console_task != null) {
|
||||||
|
// --------------------------------
|
||||||
|
// FORCE A CONSOLE TASK
|
||||||
|
// --------------------------------
|
||||||
enterprise_hook('cron_task_run', [$id_console_task, true]);
|
enterprise_hook('cron_task_run', [$id_console_task, true]);
|
||||||
// Trick to avoid double execution.
|
// Trick to avoid double execution.
|
||||||
header('Location: '.$this->url);
|
header('Location: '.$this->url);
|
||||||
|
} else {
|
||||||
|
// --------------------------------
|
||||||
|
// FORCE A RECON TASK
|
||||||
|
// --------------------------------
|
||||||
|
if (check_acl($config['id_user'], 0, 'AW')) {
|
||||||
|
if (isset($_GET['force'])) {
|
||||||
|
$id = (int) get_parameter_get('force', 0);
|
||||||
|
// Schedule execution.
|
||||||
|
$direct_report = db_get_value(
|
||||||
|
'direct_report',
|
||||||
|
'trecon_task',
|
||||||
|
'id_rt',
|
||||||
|
$id
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($direct_report != DISCOVERY_STANDARD) {
|
||||||
|
// Force re-scan for supervised tasks.
|
||||||
|
$direct_report = DISCOVERY_SEARCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db_process_sql_update(
|
||||||
|
'trecon_task',
|
||||||
|
[
|
||||||
|
'utimestamp' => 0,
|
||||||
|
'status' => 1,
|
||||||
|
'direct_report' => $direct_report,
|
||||||
|
],
|
||||||
|
['id_rt' => $id]
|
||||||
|
);
|
||||||
|
header('Location: '.$this->url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -334,28 +369,7 @@ class DiscoveryTaskList extends HTML
|
|||||||
include_once $config['homedir'].'/include/functions_servers.php';
|
include_once $config['homedir'].'/include/functions_servers.php';
|
||||||
include_once $config['homedir'].'/include/functions_network_profiles.php';
|
include_once $config['homedir'].'/include/functions_network_profiles.php';
|
||||||
|
|
||||||
$modules_server = 0;
|
|
||||||
$total_modules = 0;
|
|
||||||
$total_modules_data = 0;
|
|
||||||
|
|
||||||
// --------------------------------
|
|
||||||
// FORCE A RECON TASK
|
|
||||||
// --------------------------------
|
|
||||||
if (check_acl($config['id_user'], 0, 'AW')) {
|
|
||||||
if (isset($_GET['force'])) {
|
|
||||||
$id = (int) get_parameter_get('force', 0);
|
|
||||||
servers_force_recon_task($id);
|
|
||||||
header(
|
|
||||||
'Location: '.ui_get_full_url(
|
|
||||||
'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$recon_tasks = db_get_all_rows_sql('SELECT * FROM trecon_task');
|
$recon_tasks = db_get_all_rows_sql('SELECT * FROM trecon_task');
|
||||||
$user_groups = implode(',', array_keys(users_get_groups()));
|
|
||||||
|
|
||||||
// Show network tasks for Recon Server.
|
// Show network tasks for Recon Server.
|
||||||
if ($recon_tasks === false) {
|
if ($recon_tasks === false) {
|
||||||
$recon_tasks = [];
|
$recon_tasks = [];
|
||||||
@ -512,14 +526,22 @@ class DiscoveryTaskList extends HTML
|
|||||||
if ($task['direct_report'] == 1) {
|
if ($task['direct_report'] == 1) {
|
||||||
if ($task['status'] <= 0) {
|
if ($task['status'] <= 0) {
|
||||||
$data[5] = __('Done');
|
$data[5] = __('Done');
|
||||||
|
} else if ($task['utimestamp'] == 0
|
||||||
|
&& empty($task['summary'])
|
||||||
|
) {
|
||||||
|
$data[5] = __('Not started');
|
||||||
} else {
|
} else {
|
||||||
$data[5] = __('Pending');
|
$data[5] = __('Pending');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($task['status'] <= 0) {
|
if ($task['status'] <= 0 && $task['utimestamp'] > 0) {
|
||||||
$data[5] = '<span class="link review" onclick="show_review('.$task['id_rt'].',\''.$task['name'].'\')">';
|
$data[5] = '<span class="link review" onclick="show_review('.$task['id_rt'].',\''.$task['name'].'\')">';
|
||||||
$data[5] .= __('Review');
|
$data[5] .= __('Review');
|
||||||
$data[5] .= '</span>';
|
$data[5] .= '</span>';
|
||||||
|
} else if ($task['utimestamp'] == 0
|
||||||
|
&& empty($task['summary'])
|
||||||
|
) {
|
||||||
|
$data[5] = __('Not started');
|
||||||
} else {
|
} else {
|
||||||
$data[5] = __('Searching');
|
$data[5] = __('Searching');
|
||||||
}
|
}
|
||||||
@ -636,7 +658,7 @@ class DiscoveryTaskList extends HTML
|
|||||||
'data' => [
|
'data' => [
|
||||||
'wiz' => 'tasklist',
|
'wiz' => 'tasklist',
|
||||||
'id' => $task['id_rt'],
|
'id' => $task['id_rt'],
|
||||||
'method' => 'task_progress',
|
'method' => 'taskProgress',
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -842,10 +864,11 @@ class DiscoveryTaskList extends HTML
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function task_progress()
|
public function taskProgress()
|
||||||
{
|
{
|
||||||
if (!is_ajax()) {
|
if (!is_ajax()) {
|
||||||
return '';
|
echo json_encode(['error' => true]);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$id_task = get_parameter('id', 0);
|
$id_task = get_parameter('id', 0);
|
||||||
@ -871,11 +894,11 @@ class DiscoveryTaskList extends HTML
|
|||||||
*
|
*
|
||||||
* @return string Charts in HTML.
|
* @return string Charts in HTML.
|
||||||
*/
|
*/
|
||||||
private function progress_task_graph($task)
|
private function progressTaskGraph($task)
|
||||||
{
|
{
|
||||||
$result .= '<div style="display: flex;">';
|
$result .= '<div style="display: flex;">';
|
||||||
$result .= '<div style="width: 100%; text-align: center; margin-top: 40px;">';
|
$result .= '<div class="subtitle">';
|
||||||
$result .= '<span style="font-size: 1.9em; font-family: "lato-bolder", "Open Sans", sans-serif !important;">'._('Overall Progress').'</span>';
|
$result .= '<span>'._('Overall Progress').'</span>';
|
||||||
|
|
||||||
$result .= '<div style="margin-top: 25px;">';
|
$result .= '<div style="margin-top: 25px;">';
|
||||||
$result .= progress_circular_bar(
|
$result .= progress_circular_bar(
|
||||||
@ -928,8 +951,8 @@ class DiscoveryTaskList extends HTML
|
|||||||
}
|
}
|
||||||
|
|
||||||
$result .= '</div>';
|
$result .= '</div>';
|
||||||
$result .= '<div style="width: 100%; text-align: center; margin-top: 40px;">';
|
$result .= '<div class="subtitle">';
|
||||||
$result .= '<span style="font-size: 1.9em; font-family: "lato-bolder", "Open Sans", sans-serif !important;">'.$str.' ';
|
$result .= '<span>'.$str.' ';
|
||||||
if (!empty($str)) {
|
if (!empty($str)) {
|
||||||
$result .= $task['stats']['c_network_name'];
|
$result .= $task['stats']['c_network_name'];
|
||||||
}
|
}
|
||||||
@ -964,7 +987,7 @@ class DiscoveryTaskList extends HTML
|
|||||||
*
|
*
|
||||||
* @return html code with summary.
|
* @return html code with summary.
|
||||||
*/
|
*/
|
||||||
private function progress_task_summary($task)
|
private function progressTaskSummary($task)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
include_once $config['homedir'].'/include/graphs/functions_d3.php';
|
include_once $config['homedir'].'/include/graphs/functions_d3.php';
|
||||||
@ -975,6 +998,10 @@ class DiscoveryTaskList extends HTML
|
|||||||
|
|
||||||
$output = '';
|
$output = '';
|
||||||
|
|
||||||
|
if (is_array($task['stats']) === false) {
|
||||||
|
$task['stats'] = json_decode($task['summary'], true);
|
||||||
|
}
|
||||||
|
|
||||||
if (is_array($task['stats'])) {
|
if (is_array($task['stats'])) {
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$table = new StdClasS();
|
$table = new StdClasS();
|
||||||
@ -1010,7 +1037,7 @@ class DiscoveryTaskList extends HTML
|
|||||||
$table->data[$i][1] .= $task['stats']['summary']['WMI'];
|
$table->data[$i][1] .= $task['stats']['summary']['WMI'];
|
||||||
$table->data[$i++][1] .= '</span>';
|
$table->data[$i++][1] .= '</span>';
|
||||||
|
|
||||||
$output = '<div style="margin-top: 40px; text-align: center;"><span style="font-size: 1.9em; font-family: "lato-bolder", "Open Sans", sans-serif !important;">'.__('Summary').'</span></div>';
|
$output = '<div class="subtitle"><span>'.__('Summary').'</span></div>';
|
||||||
$output .= html_print_table($table, true).'</div>';
|
$output .= html_print_table($table, true).'</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1023,7 +1050,7 @@ class DiscoveryTaskList extends HTML
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function progress_task_discovery()
|
public function progressTaskDiscovery()
|
||||||
{
|
{
|
||||||
if (!is_ajax()) {
|
if (!is_ajax()) {
|
||||||
return;
|
return;
|
||||||
@ -1038,8 +1065,7 @@ class DiscoveryTaskList extends HTML
|
|||||||
|
|
||||||
$task = db_get_row('trecon_task', 'id_rt', $id_task);
|
$task = db_get_row('trecon_task', 'id_rt', $id_task);
|
||||||
$task['stats'] = json_decode($task['summary'], true);
|
$task['stats'] = json_decode($task['summary'], true);
|
||||||
$global_progress = $task['status'];
|
$summary = $this->progressTaskSummary($task);
|
||||||
$summary = $this->progress_task_summary($task);
|
|
||||||
|
|
||||||
$output = '';
|
$output = '';
|
||||||
|
|
||||||
@ -1059,7 +1085,7 @@ class DiscoveryTaskList extends HTML
|
|||||||
true
|
true
|
||||||
).'</div>';
|
).'</div>';
|
||||||
} else {
|
} else {
|
||||||
$output .= $this->progress_task_graph($task);
|
$output .= $this->progressTaskGraph($task);
|
||||||
}
|
}
|
||||||
|
|
||||||
$output .= $summary;
|
$output .= $summary;
|
||||||
@ -1073,7 +1099,7 @@ class DiscoveryTaskList extends HTML
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function task_showmap()
|
public function taskShowmap()
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
include_once $config['homedir'].'/include/class/NetworkMap.class.php';
|
include_once $config['homedir'].'/include/class/NetworkMap.class.php';
|
||||||
@ -1095,7 +1121,7 @@ class DiscoveryTaskList extends HTML
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function show_task_review()
|
public function showTaskReview()
|
||||||
{
|
{
|
||||||
$id_task = get_parameter('id', 0);
|
$id_task = get_parameter('id', 0);
|
||||||
if ($id_task <= 0) {
|
if ($id_task <= 0) {
|
||||||
@ -1103,43 +1129,107 @@ class DiscoveryTaskList extends HTML
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$task = db_get_row('tdiscovery_tmp_agents', 'id_rt', $id_task);
|
$task_data = db_get_all_rows_filter(
|
||||||
|
'tdiscovery_tmp_agents',
|
||||||
|
['id_rt' => $id_task]
|
||||||
|
);
|
||||||
|
$task = db_get_row('trecon_task', 'id_rt', $id_task);
|
||||||
|
|
||||||
if (is_array($task)) {
|
$simple_data = [];
|
||||||
$data = json_decode(base64_decode($task['data']), true);
|
if (is_array($task_data)) {
|
||||||
$simple_data = array_reduce(
|
foreach ($task_data as $agent) {
|
||||||
$data,
|
$data = json_decode(base64_decode($agent['data']), true);
|
||||||
function ($carry, $item) {
|
|
||||||
$id = $item['agent']['nombre'];
|
if (is_array($data) === false) {
|
||||||
$carry[] = [
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $data['agent']['nombre'];
|
||||||
|
|
||||||
|
// Partial.
|
||||||
|
$tmp = [
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
'name' => $item['agent']['nombre'],
|
'name' => $id,
|
||||||
|
'checked' => $data['agent']['checked'],
|
||||||
];
|
];
|
||||||
|
|
||||||
$childs = array_reduce(
|
$agent_id = $data['agent']['agent_id'];
|
||||||
$item['modules'],
|
if (empty($agent_id)) {
|
||||||
function ($c, $i) use ($id) {
|
$agent_id = agents_get_agent_id($id, true);
|
||||||
$c[] = [
|
}
|
||||||
'name' => $i['name'],
|
|
||||||
'id' => $id.'-'.$i['name'],
|
if ($agent_id > 0) {
|
||||||
|
$tmp['disabled'] = 1;
|
||||||
|
$tmp['checked'] = 1;
|
||||||
|
$tmp['agent_id'] = $agent_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store.
|
||||||
|
$simple_data[] = $tmp;
|
||||||
|
|
||||||
|
if (is_array($data['modules'])) {
|
||||||
|
$simple_data = array_merge(
|
||||||
|
$simple_data,
|
||||||
|
array_reduce(
|
||||||
|
$data['modules'],
|
||||||
|
function ($carry, $item) use ($id, $agent_id) {
|
||||||
|
if ($item['name'] == 'Host Alive') {
|
||||||
|
return $carry;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tmp = [
|
||||||
|
'name' => $item['name'],
|
||||||
|
'id' => $id.'-'.$item['name'],
|
||||||
'pid' => $id,
|
'pid' => $id,
|
||||||
|
'checked' => $item['checked'],
|
||||||
];
|
];
|
||||||
return $c;
|
|
||||||
},
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
$carry = array_merge(
|
|
||||||
$carry,
|
|
||||||
$childs
|
|
||||||
);
|
|
||||||
|
|
||||||
|
$agentmodule_id = $item['agentmodule_id'];
|
||||||
|
if (empty($agentmodule_id)) {
|
||||||
|
$agentmodule_id = modules_get_agentmodule_id(
|
||||||
|
io_safe_input($item['name']),
|
||||||
|
$agent_id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($agentmodule_id > 0) {
|
||||||
|
$tmp['disabled'] = 1;
|
||||||
|
$tmp['checked'] = 1;
|
||||||
|
$tmp['module_id'] = $agentmodule_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$carry[] = $tmp;
|
||||||
return $carry;
|
return $carry;
|
||||||
},
|
},
|
||||||
[]
|
[]
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '<div>';
|
||||||
|
echo $this->progressTaskSummary($task);
|
||||||
|
echo '</div>';
|
||||||
|
echo '<div class="subtitle">';
|
||||||
|
echo '<span>';
|
||||||
|
echo __('Please select devices to be monitored');
|
||||||
|
echo '</span><div class="manage">';
|
||||||
|
echo '<button onclick="$(\'.sim-tree li a\').each(function(){simTree_tree.doCheck($(this), false); simTree_tree.clickNode($(this));});">';
|
||||||
|
echo __('select all');
|
||||||
|
echo '</button>';
|
||||||
|
echo '<button onclick="$(\'.sim-tree li a\').each(function(){simTree_tree.doCheck($(this), true); simTree_tree.clickNode($(this));});">';
|
||||||
|
echo __('deselect all');
|
||||||
|
echo '</button>';
|
||||||
|
echo '</div>';
|
||||||
|
echo '</div>';
|
||||||
|
|
||||||
|
echo '<form id="review">';
|
||||||
echo '<div id="tree"></div>';
|
echo '<div id="tree"></div>';
|
||||||
echo parent::printTree('tree', $simple_data);
|
echo parent::printTree(
|
||||||
|
'tree',
|
||||||
|
$simple_data
|
||||||
|
);
|
||||||
|
echo '</form>';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1150,7 +1240,7 @@ class DiscoveryTaskList extends HTML
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function parse_task_review()
|
public function parseTaskReview()
|
||||||
{
|
{
|
||||||
$id_task = get_parameter('id', 0);
|
$id_task = get_parameter('id', 0);
|
||||||
if ($id_task <= 0) {
|
if ($id_task <= 0) {
|
||||||
@ -1158,7 +1248,102 @@ class DiscoveryTaskList extends HTML
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$out = obhd($_REQUEST);
|
$ids = [];
|
||||||
|
$selection = io_safe_output(get_parameter('tree-data-tree', ''));
|
||||||
|
if (empty($selection) === false) {
|
||||||
|
$selection = json_decode($selection, true);
|
||||||
|
$ids = array_reduce(
|
||||||
|
$selection,
|
||||||
|
function ($carry, $item) {
|
||||||
|
$carry[] = $item['id'];
|
||||||
|
return $carry;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$task_data = db_get_all_rows_filter(
|
||||||
|
'tdiscovery_tmp_agents',
|
||||||
|
['id_rt' => $id_task]
|
||||||
|
);
|
||||||
|
|
||||||
|
$summary = [];
|
||||||
|
if (is_array($ids)) {
|
||||||
|
foreach ($task_data as $row) {
|
||||||
|
$data = json_decode(base64_decode($row['data']), true);
|
||||||
|
|
||||||
|
if (is_array($data)) {
|
||||||
|
// Analize each agent.
|
||||||
|
$agent_name = $data['agent']['nombre'];
|
||||||
|
if (in_array($agent_name, $ids)) {
|
||||||
|
if ($data['agent']['checked'] != 1) {
|
||||||
|
$summary[] = '<li class="added">'.$agent_name.'</li>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['agent']['checked'] = 1;
|
||||||
|
} else {
|
||||||
|
if ($data['agent']['checked'] == 1) {
|
||||||
|
$summary[] = '<li class="removed">'.__('Removed').' '.$agent_name.'</li>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['agent']['checked'] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modules.
|
||||||
|
if (is_array($data['modules'])) {
|
||||||
|
$n_modules = count($data['modules']);
|
||||||
|
for ($i = 0; $i < $n_modules; $i++) {
|
||||||
|
$module_name = $data['modules'][$i]['name'];
|
||||||
|
if (in_array($agent_name.'-'.$module_name, $ids)) {
|
||||||
|
if ($data['modules'][$i]['checked'] != 1) {
|
||||||
|
$summary[] = '<li class="added">'.$agent_name.' - '.$module_name.'</li>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['modules'][$i]['checked'] = 1;
|
||||||
|
} else {
|
||||||
|
if ($data['modules'][$i]['checked'] == 1) {
|
||||||
|
$summary[] = '<li class="removed">'.__('Removed').' '.$agent_name.' - '.$module_name.'</li>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['modules'][$i]['checked'] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update data.
|
||||||
|
db_process_sql_update(
|
||||||
|
'tdiscovery_tmp_agents',
|
||||||
|
[
|
||||||
|
'data' => base64_encode(json_encode($data)),
|
||||||
|
'review_date' => date('Y-m-d H:i:s'),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id_rt' => $id_task,
|
||||||
|
'label' => $agent_name,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($summary)) {
|
||||||
|
$out .= __('No changes');
|
||||||
|
} else {
|
||||||
|
// Schedule execution.
|
||||||
|
db_process_sql_update(
|
||||||
|
'trecon_task',
|
||||||
|
[
|
||||||
|
'utimestamp' => 0,
|
||||||
|
'status' => 1,
|
||||||
|
'direct_report' => DISCOVERY_RESULTS,
|
||||||
|
],
|
||||||
|
['id_rt' => $id_task]
|
||||||
|
);
|
||||||
|
|
||||||
|
$out .= __('Summary');
|
||||||
|
$out .= '<ul>';
|
||||||
|
$out .= join('', $summary);
|
||||||
|
$out .= '</ul>';
|
||||||
|
}
|
||||||
|
|
||||||
echo json_encode(
|
echo json_encode(
|
||||||
['result' => $out]
|
['result' => $out]
|
||||||
|
@ -38,7 +38,7 @@ class HTML
|
|||||||
/**
|
/**
|
||||||
* Breadcrum
|
* Breadcrum
|
||||||
*
|
*
|
||||||
* @var array.
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $breadcrum;
|
public $breadcrum;
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ class HTML
|
|||||||
/**
|
/**
|
||||||
* Add an element to breadcrum array.
|
* Add an element to breadcrum array.
|
||||||
*
|
*
|
||||||
* @param string $breads Elements to add to breadcrum.
|
* @param array $breads Elements to add to breadcrum.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@ -335,6 +335,27 @@ class HTML
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return formatted html for error handler.
|
||||||
|
*
|
||||||
|
* @param string $message Error mesage.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function error($message)
|
||||||
|
{
|
||||||
|
if (is_ajax()) {
|
||||||
|
echo json_encode(
|
||||||
|
[
|
||||||
|
'error' => ui_print_error_message($message, '', true),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return ui_print_error_message($message, '', true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print input using functions html lib.
|
* Print input using functions html lib.
|
||||||
*
|
*
|
||||||
@ -1003,28 +1024,64 @@ class HTML
|
|||||||
/**
|
/**
|
||||||
* Returns a n-dimensional array (data) into a html tree structure.
|
* Returns a n-dimensional array (data) into a html tree structure.
|
||||||
*
|
*
|
||||||
|
* Advanced documentation:
|
||||||
|
* https://www.jqueryscript.net/other/Checkable-Hierarchical-Tree.html
|
||||||
|
*
|
||||||
* @param string $target Target DOM id.
|
* @param string $target Target DOM id.
|
||||||
* @param array $data N-dimensional array.
|
* @param array $data N-dimensional array.
|
||||||
* @param string $callback Callback function.
|
* @param string $onclick Onclick function.
|
||||||
|
* @param string $onchange Onchange function.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function printTree($target, $data, $callback='')
|
public static function printTree(
|
||||||
{
|
$target,
|
||||||
|
$data,
|
||||||
|
$onclick='',
|
||||||
|
$onchange=''
|
||||||
|
) {
|
||||||
ui_require_css_file('simTree');
|
ui_require_css_file('simTree');
|
||||||
ui_require_javascript_file('simTree');
|
ui_require_javascript_file('simTree');
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SAMPLE SELECT ALL.
|
||||||
|
*
|
||||||
|
* echo '<div class="subtitle">';
|
||||||
|
* echo '<span>';
|
||||||
|
* echo __('Please select devices to be monitored');
|
||||||
|
* echo '</span><div class="manage">';
|
||||||
|
* echo '<button onclick="$(\'.sim-tree li a\').each(function(){simTree_tree.doCheck($(this), false); simTree_tree.clickNode($(this));});">';
|
||||||
|
* echo __('select all');
|
||||||
|
* echo '</button>';
|
||||||
|
* echo '<button onclick="$(\'.sim-tree li a\').each(function(){simTree_tree.doCheck($(this), true); simTree_tree.clickNode($(this));});">';
|
||||||
|
* echo __('deselect all');
|
||||||
|
* echo '</button>';
|
||||||
|
* echo '</div>';
|
||||||
|
* echo '</div>';
|
||||||
|
*
|
||||||
|
* END SAMPLE SELECT ALL.
|
||||||
|
*/
|
||||||
|
|
||||||
$output = '
|
$output = '
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
var simTree_'.$target.';
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
simTree({
|
simTree_'.$target.' = simTree({
|
||||||
el: $('.$target.'),
|
el: $('.$target.'),
|
||||||
data: '.json_encode($data).',
|
data: '.json_encode($data).',
|
||||||
onClick: function (item) {'.$callback.';},
|
onClick: function (item) {'.$onclick.';},
|
||||||
|
onChange: function (item) {
|
||||||
|
'.$onchange.';
|
||||||
|
$("#tree-data-'.$target.'").val(JSON.stringify(this.sels));
|
||||||
|
},
|
||||||
check: true,
|
check: true,
|
||||||
linkParent: true
|
linkParent: true
|
||||||
});
|
});
|
||||||
|
$("#'.$target.'").append(
|
||||||
|
\'<input type="hidden" id="tree-data-'.$target.'" name="tree-data-'.$target.'">\'
|
||||||
|
);
|
||||||
|
|
||||||
|
$("#tree-data-'.$target.'").val(JSON.stringify(simTree_'.$target.'.sels));
|
||||||
});
|
});
|
||||||
</script>';
|
</script>';
|
||||||
|
|
||||||
|
@ -597,6 +597,11 @@ define('DISCOVERY_DEPLOY_AGENTS', 9);
|
|||||||
define('DISCOVERY_APP_SAP', 10);
|
define('DISCOVERY_APP_SAP', 10);
|
||||||
|
|
||||||
|
|
||||||
|
// Force task build tmp results.
|
||||||
|
define('DISCOVERY_SEARCH', 0);
|
||||||
|
define('DISCOVERY_STANDARD', 1);
|
||||||
|
define('DISCOVERY_RESULTS', 2);
|
||||||
|
|
||||||
// Discovery types matching definition.
|
// Discovery types matching definition.
|
||||||
define('DISCOVERY_SCRIPT_HOSTDEVICES_CUSTOM', 0);
|
define('DISCOVERY_SCRIPT_HOSTDEVICES_CUSTOM', 0);
|
||||||
// Standard applications.
|
// Standard applications.
|
||||||
|
@ -66,7 +66,7 @@ function fetchTaskList(id, callback) {
|
|||||||
data: {
|
data: {
|
||||||
page: "godmode/servers/discovery",
|
page: "godmode/servers/discovery",
|
||||||
wiz: "tasklist",
|
wiz: "tasklist",
|
||||||
method: "progress_task_discovery",
|
method: "progressTaskDiscovery",
|
||||||
id: id
|
id: id
|
||||||
},
|
},
|
||||||
type: "POST",
|
type: "POST",
|
||||||
@ -100,7 +100,7 @@ function show_map(id, name) {
|
|||||||
data: {
|
data: {
|
||||||
page: "godmode/servers/discovery",
|
page: "godmode/servers/discovery",
|
||||||
wiz: "tasklist",
|
wiz: "tasklist",
|
||||||
method: "task_showmap",
|
method: "taskShowmap",
|
||||||
id: id
|
id: id
|
||||||
},
|
},
|
||||||
type: "POST",
|
type: "POST",
|
||||||
@ -157,6 +157,7 @@ function show_review(id, name) {
|
|||||||
of: window,
|
of: window,
|
||||||
collision: "fit"
|
collision: "fit"
|
||||||
},
|
},
|
||||||
|
maxHeight: 400,
|
||||||
title: title,
|
title: title,
|
||||||
buttons: [
|
buttons: [
|
||||||
{
|
{
|
||||||
@ -166,9 +167,8 @@ function show_review(id, name) {
|
|||||||
click: function(e) {
|
click: function(e) {
|
||||||
if (!failed) {
|
if (!failed) {
|
||||||
$(".ui-dialog-content").dialog("close");
|
$(".ui-dialog-content").dialog("close");
|
||||||
$(".info").hide();
|
$("#task_review").empty();
|
||||||
cleanupDOM();
|
location.reload();
|
||||||
dt_keystore.draw(false);
|
|
||||||
} else {
|
} else {
|
||||||
$(this).dialog("close");
|
$(this).dialog("close");
|
||||||
}
|
}
|
||||||
@ -189,11 +189,12 @@ function show_review(id, name) {
|
|||||||
],
|
],
|
||||||
onshow: {
|
onshow: {
|
||||||
page: "godmode/servers/discovery",
|
page: "godmode/servers/discovery",
|
||||||
method: "show_task_review"
|
method: "showTaskReview",
|
||||||
|
maxHeight: 800
|
||||||
},
|
},
|
||||||
onsubmit: {
|
onsubmit: {
|
||||||
page: "godmode/servers/discovery",
|
page: "godmode/servers/discovery",
|
||||||
method: "parse_task_review"
|
method: "parseTaskReview"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -335,6 +335,12 @@ function load_modal(settings) {
|
|||||||
? settings.onshow.maxHeight
|
? settings.onshow.maxHeight
|
||||||
: "auto",
|
: "auto",
|
||||||
overlay: settings.modal.overlay,
|
overlay: settings.modal.overlay,
|
||||||
|
position: {
|
||||||
|
my: "top+20%",
|
||||||
|
at: "top",
|
||||||
|
of: window,
|
||||||
|
collision: "fit"
|
||||||
|
},
|
||||||
buttons: required_buttons,
|
buttons: required_buttons,
|
||||||
closeOnEscape: true,
|
closeOnEscape: true,
|
||||||
open: function() {
|
open: function() {
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
/**
|
||||||
|
* IMPORTANT. Official plugin does not allow string ids
|
||||||
|
* This modificated one yes.
|
||||||
|
*/
|
||||||
!(function(e) {
|
!(function(e) {
|
||||||
var t = {};
|
var t = {};
|
||||||
function i(s) {
|
function i(s) {
|
||||||
@ -373,7 +377,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
expandNode: function(e) {
|
expandNode: function(e) {
|
||||||
var t = e.addClass ? e : this.$el.find("[data-id=" + e + "]"),
|
var t = e.addClass ? e : this.$el.find("[data-id='" + e + "']"),
|
||||||
i = t.data("data"),
|
i = t.data("data"),
|
||||||
s = i[this.options.response.pid],
|
s = i[this.options.response.pid],
|
||||||
n = t.children(".sim-tree-spread"),
|
n = t.children(".sim-tree-spread"),
|
||||||
@ -392,7 +396,7 @@
|
|||||||
$.isArray(i) &&
|
$.isArray(i) &&
|
||||||
(this.options.check || (i = [i[0]]),
|
(this.options.check || (i = [i[0]]),
|
||||||
$.each(i, function(e, i) {
|
$.each(i, function(e, i) {
|
||||||
var a = t.$el.find("[data-id=" + i + "]"),
|
var a = t.$el.find("[data-id='" + i + "']"),
|
||||||
r = a.children("a"),
|
r = a.children("a"),
|
||||||
d = r.children(".sim-tree-checkbox"),
|
d = r.children(".sim-tree-checkbox"),
|
||||||
o = a.data("data");
|
o = a.data("data");
|
||||||
@ -415,7 +419,7 @@
|
|||||||
("string" != typeof i && "number" != typeof i) || (i = [i]),
|
("string" != typeof i && "number" != typeof i) || (i = [i]),
|
||||||
$.isArray(i) &&
|
$.isArray(i) &&
|
||||||
$.each(i, function(e, i) {
|
$.each(i, function(e, i) {
|
||||||
var s = t.$el.find("[data-id=" + i + "]");
|
var s = t.$el.find("[data-id='" + i + "']");
|
||||||
s.addClass("disabled");
|
s.addClass("disabled");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -36,6 +36,48 @@ ul.progress_task_discovery {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.subtitle {
|
||||||
|
width: 100%;
|
||||||
|
margin-top: 40px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.subtitle span {
|
||||||
|
font-size: 1.9em;
|
||||||
|
font-family: "lato-bolder", "Open Sans", sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.subtitle div.manage {
|
||||||
|
text-align: center;
|
||||||
|
padding-top: 2em;
|
||||||
|
padding-bottom: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.subtitle div.manage button {
|
||||||
|
font-size: 1.2em;
|
||||||
|
font-family: "lato", "Open Sans", sans-serif;
|
||||||
|
display: inline-block;
|
||||||
|
padding: 5px;
|
||||||
|
margin-right: 1em;
|
||||||
|
cursor: pointer;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
#msg ul li {
|
||||||
|
margin-left: 3em;
|
||||||
|
}
|
||||||
|
|
||||||
|
li.added {
|
||||||
|
list-style: url("../../images/header_ready.png");
|
||||||
|
}
|
||||||
|
li.removed {
|
||||||
|
list-style: url("../../images/header_down.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
#msg ul {
|
||||||
|
list-style: url("../../images/header_ready.png");
|
||||||
|
}
|
||||||
|
|
||||||
ul.progress_task_discovery li span {
|
ul.progress_task_discovery li span {
|
||||||
font-size: 9pt;
|
font-size: 9pt;
|
||||||
margin-left: 20px;
|
margin-left: 20px;
|
||||||
|
@ -819,7 +819,7 @@ CREATE TABLE `tdiscovery_tmp_agents` (
|
|||||||
`label` varchar(600) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
|
`label` varchar(600) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
|
||||||
`data` text,
|
`data` text,
|
||||||
`review_date` datetime DEFAULT NULL,
|
`review_date` datetime DEFAULT NULL,
|
||||||
`created` int(1) unsigned NOT NULL DEFAULT '0',
|
`created` datetime DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `id_rt` (`id_rt`),
|
KEY `id_rt` (`id_rt`),
|
||||||
INDEX `label` (`label`),
|
INDEX `label` (`label`),
|
||||||
|
@ -3266,7 +3266,7 @@ sub pandora_create_agent ($$$$$$$$$$;$$$$$$$$$$) {
|
|||||||
$agent_mode = 1 unless defined($agent_mode);
|
$agent_mode = 1 unless defined($agent_mode);
|
||||||
$alias = $agent_name unless defined($alias);
|
$alias = $agent_name unless defined($alias);
|
||||||
|
|
||||||
$description = "Created by $server_name" unless ($description ne '');
|
$description = "Created by $server_name" unless (defined($description) && $description ne '');
|
||||||
my ($columns, $values) = db_insert_get_values ({ 'nombre' => safe_input($agent_name),
|
my ($columns, $values) = db_insert_get_values ({ 'nombre' => safe_input($agent_name),
|
||||||
'direccion' => $address,
|
'direccion' => $address,
|
||||||
'comentarios' => $description,
|
'comentarios' => $description,
|
||||||
|
@ -61,6 +61,8 @@ use constant {
|
|||||||
STEP_AFT => 2,
|
STEP_AFT => 2,
|
||||||
STEP_TRACEROUTE => 3,
|
STEP_TRACEROUTE => 3,
|
||||||
STEP_GATEWAY => 4,
|
STEP_GATEWAY => 4,
|
||||||
|
STEP_MONITORING => 5,
|
||||||
|
STEP_APPLY => 6,
|
||||||
STEP_STATISTICS => 1,
|
STEP_STATISTICS => 1,
|
||||||
STEP_APP_SCAN => 2,
|
STEP_APP_SCAN => 2,
|
||||||
STEP_CUSTOM_QUERIES => 3,
|
STEP_CUSTOM_QUERIES => 3,
|
||||||
@ -75,6 +77,9 @@ use constant {
|
|||||||
DISCOVERY_CLOUD_AZURE_COMPUTE => 8,
|
DISCOVERY_CLOUD_AZURE_COMPUTE => 8,
|
||||||
DISCOVERY_DEPLOY_AGENTS => 9,
|
DISCOVERY_DEPLOY_AGENTS => 9,
|
||||||
DISCOVERY_APP_SAP => 10,
|
DISCOVERY_APP_SAP => 10,
|
||||||
|
DISCOVERY_SEARCH => 0,
|
||||||
|
DISCOVERY_STANDARD => 1,
|
||||||
|
DISCOVERY_RESULTS => 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
@ -449,6 +454,14 @@ sub PandoraFMS::Recon::Base::create_network_profile_modules($$$) {
|
|||||||
# ICMP
|
# ICMP
|
||||||
#
|
#
|
||||||
|
|
||||||
|
use Data::Dumper;
|
||||||
|
$Data::Dumper::Sortkeys = 1;
|
||||||
|
|
||||||
|
print Dumper($device);
|
||||||
|
print Dumper($self->{'task_data'});
|
||||||
|
|
||||||
|
die();
|
||||||
|
|
||||||
return if empty($self->{'id_network_profile'});
|
return if empty($self->{'id_network_profile'});
|
||||||
|
|
||||||
my @templates = split /,/, $self->{'id_network_profile'};
|
my @templates = split /,/, $self->{'id_network_profile'};
|
||||||
@ -478,7 +491,12 @@ sub PandoraFMS::Recon::Base::create_network_profile_modules($$$) {
|
|||||||
$component->{'plugin_user'} = $self->{'snmp_auth_user'};
|
$component->{'plugin_user'} = $self->{'snmp_auth_user'};
|
||||||
$component->{'plugin_pass'} = $self->{'snmp_auth_pass'};
|
$component->{'plugin_pass'} = $self->{'snmp_auth_pass'};
|
||||||
|
|
||||||
pandora_create_module_from_network_component($self->{'pa_config'}, $component, $agent_id, $self->{'dbh'});
|
pandora_create_module_from_network_component(
|
||||||
|
$self->{'pa_config'},
|
||||||
|
$component,
|
||||||
|
$agent_id,
|
||||||
|
$self->{'dbh'}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -488,8 +506,19 @@ sub PandoraFMS::Recon::Base::create_network_profile_modules($$$) {
|
|||||||
sub PandoraFMS::Recon::Base::report_scanned_agents($) {
|
sub PandoraFMS::Recon::Base::report_scanned_agents($) {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
|
my $force_creation = 0;
|
||||||
|
|
||||||
if (defined($self->{'task_data'}{'direct_report'})
|
if (defined($self->{'task_data'}{'direct_report'})
|
||||||
&& $self->{'task_data'}{'direct_report'} eq "2"
|
&& $self->{'task_data'}{'direct_report'} == DISCOVERY_STANDARD
|
||||||
|
) {
|
||||||
|
$force_creation = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Creation
|
||||||
|
#
|
||||||
|
if(defined($self->{'task_data'}{'direct_report'})
|
||||||
|
&& $self->{'task_data'}{'direct_report'} == DISCOVERY_RESULTS
|
||||||
) {
|
) {
|
||||||
# Load cache.
|
# Load cache.
|
||||||
my @rows = get_db_rows(
|
my @rows = get_db_rows(
|
||||||
@ -498,25 +527,155 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($) {
|
|||||||
$self->{'task_data'}{'id_rt'}
|
$self->{'task_data'}{'id_rt'}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
my @agents;
|
||||||
|
|
||||||
|
my $progress = 0;
|
||||||
|
my $step = 100.00 / scalar @rows;
|
||||||
foreach my $row (@rows) {
|
foreach my $row (@rows) {
|
||||||
|
$progress += $step;
|
||||||
|
$self->call('update_progress', $progress);
|
||||||
|
|
||||||
my $name = safe_output($row->{'label'});
|
my $name = safe_output($row->{'label'});
|
||||||
my $data;
|
my $data;
|
||||||
eval {
|
eval {
|
||||||
|
local $SIG{__DIE__};
|
||||||
$data = decode_json(decode_base64($row->{'data'}));
|
$data = decode_json(decode_base64($row->{'data'}));
|
||||||
};
|
};
|
||||||
|
if ($@) {
|
||||||
|
$self->call('message', "ERROR JSON: $@", 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Register target agent if enabled.
|
||||||
|
if (is_enabled($data->{'agent'}{'checked'})
|
||||||
|
|| $force_creation
|
||||||
|
) {
|
||||||
|
my $parent_id;
|
||||||
|
my $os_id = $self->guess_os($data->{'agent'}{'direccion'});
|
||||||
|
|
||||||
|
$self->call('message', "Agent accepted: ".$data->{'agent'}{'nombre'}, 5);
|
||||||
|
|
||||||
|
# Agent creation.
|
||||||
|
my $agent_id = $data->{'agent'}{'agent_id'};
|
||||||
|
my $agent_learning = 1;
|
||||||
|
|
||||||
|
if (!defined($agent_id) || $agent_id == 0) {
|
||||||
|
$agent_id = pandora_create_agent(
|
||||||
|
$self->{'pa_config'}, $self->{'servername'}, $data->{'agent'}{'nombre'},
|
||||||
|
$data->{'agent'}{'direccion'}, $self->{'task_data'}{'group_id'}, $parent_id,
|
||||||
|
$os_id, $data->{'agent'}->{'description'},
|
||||||
|
$data->{'agent'}{'interval'}, $self->{'dbh'},
|
||||||
|
$data->{'agent'}{'timezone_offset'}
|
||||||
|
);
|
||||||
|
|
||||||
|
$data->{'agent'}{'agent_id'} = $agent_id;
|
||||||
|
$agent_learning = 1;
|
||||||
|
} else {
|
||||||
|
$agent_learning = get_db_value(
|
||||||
|
$self->{'dbh'},
|
||||||
|
'SELECT modo FROM tagente WHERE id_agente = ?',
|
||||||
|
$agent_id
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
$self->call('message', "Agent id: ".$data->{'agent'}{'agent_id'}, 5);
|
||||||
|
|
||||||
|
# Create selected modules.
|
||||||
|
if(ref($data->{'modules'}) eq "ARRAY") {
|
||||||
|
for (my $i=0; $i < scalar @{$data->{'modules'}}; $i++) {
|
||||||
|
my $module = $data->{'modules'}[$i];
|
||||||
|
|
||||||
|
# Do not create any modules if the agent is not in learning mode.
|
||||||
|
next unless ($agent_learning == 1);
|
||||||
|
|
||||||
|
# Host alive is always being created.
|
||||||
|
if ($module->{'name'} ne 'Host Alive') {
|
||||||
|
next unless (is_enabled($module->{'checked'}) || $force_creation);
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->call('message', "[$agent_id] Module: ".$module->{'name'}, 5);
|
||||||
|
|
||||||
|
my $agentmodule_id = $module->{'agentmodule_id'};
|
||||||
|
if (!defined($agentmodule_id) || $agentmodule_id == 0) {
|
||||||
|
# Create module.
|
||||||
|
$agentmodule_id = pandora_create_module_from_hash(
|
||||||
|
$self->{'pa_config'},
|
||||||
|
{
|
||||||
|
'id_tipo_modulo' => get_module_id($self->{'dbh'}, $module->{'type'}),
|
||||||
|
'id_modulo' => $module->{'id_modulo'},
|
||||||
|
'nombre' => safe_input($module->{'name'}),
|
||||||
|
'descripcion' => '',
|
||||||
|
'id_agente' => $agent_id,
|
||||||
|
'ip_target' => $data->{'agent'}{'direccion'}
|
||||||
|
},
|
||||||
|
$self->{'dbh'}
|
||||||
|
);
|
||||||
|
|
||||||
# Store.
|
# Store.
|
||||||
$self->{'agents_found'}{$name} = $data;
|
$data->{'modules'}[$i]{'agentmodule_id'} = $agentmodule_id;
|
||||||
|
|
||||||
|
$self->call(
|
||||||
|
'message',
|
||||||
|
"[$agent_id] Module: ".$module->{'name'}." ID: $agentmodule_id",
|
||||||
|
5
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $encoded;
|
||||||
|
eval {
|
||||||
|
local $SIG{__DIE__};
|
||||||
|
$encoded = encode_base64(
|
||||||
|
encode_json($data)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
# Update.
|
||||||
|
db_do(
|
||||||
|
$self->{'dbh'},
|
||||||
|
'UPDATE tdiscovery_tmp_agents SET `data` = ? '
|
||||||
|
.'WHERE `id_rt` = ? AND `label` = ?',
|
||||||
|
$encoded,
|
||||||
|
$self->{'task_data'}{'id_rt'},
|
||||||
|
$name
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# Data creation finished.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Cleanup previous results.
|
||||||
|
#
|
||||||
|
db_do(
|
||||||
|
$self->{'dbh'},
|
||||||
|
'DELETE FROM tdiscovery_tmp_agents '
|
||||||
|
.'WHERE `id_rt` = ?',
|
||||||
|
$self->{'task_data'}{'id_rt'}
|
||||||
|
);
|
||||||
|
|
||||||
|
#
|
||||||
|
# Store and review.
|
||||||
|
#
|
||||||
|
|
||||||
|
my @hosts = keys %{$self->{'agents_found'}};
|
||||||
|
$self->{'step'} = STEP_APPLY;
|
||||||
|
my ($progress, $step) = (90, 10.0 / scalar(@hosts)); # From 90% to 100%.
|
||||||
foreach my $label (keys %{$self->{'agents_found'}}) {
|
foreach my $label (keys %{$self->{'agents_found'}}) {
|
||||||
if (!is_enabled($self->{'direct_report'})) {
|
$self->call('update_progress', $progress);
|
||||||
|
$progress += $step;
|
||||||
# Store temporally. Wait user approval.
|
# Store temporally. Wait user approval.
|
||||||
my $encoded;
|
my $encoded;
|
||||||
eval {
|
eval {
|
||||||
local $SIG{__DIE__};
|
local $SIG{__DIE__};
|
||||||
$encoded = encode_base64(encode_json($self->{'agents_found'}));
|
$encoded = encode_base64(
|
||||||
|
encode_json($self->{'agents_found'}->{$label})
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
my $id = get_db_value(
|
my $id = get_db_value(
|
||||||
@ -551,10 +710,31 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($) {
|
|||||||
safe_input($label),
|
safe_input($label),
|
||||||
$encoded
|
$encoded
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
# Create agents.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Apply monitoring templates selected to detected agents.
|
||||||
|
################################################################################
|
||||||
|
sub PandoraFMS::Recon::Base::apply_monitoring($) {
|
||||||
|
my ($self) = @_;
|
||||||
|
|
||||||
|
my @hosts = keys %{$self->{'agents_found'}};
|
||||||
|
|
||||||
|
$self->{'step'} = STEP_MONITORING;
|
||||||
|
# From 80% to 90%.
|
||||||
|
my ($progress, $step) = (80, 10.0 / scalar(@hosts));
|
||||||
|
|
||||||
|
use Data::Dumper;
|
||||||
|
print Dumper($self->{'task_data'});
|
||||||
|
|
||||||
|
foreach my $label (keys %{$self->{'agents_found'}}) {
|
||||||
|
$self->call('update_progress', $progress);
|
||||||
|
$progress += $step;
|
||||||
|
print ">> $label\n";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
@ -22,6 +22,8 @@ use constant {
|
|||||||
STEP_AFT => 2,
|
STEP_AFT => 2,
|
||||||
STEP_TRACEROUTE => 3,
|
STEP_TRACEROUTE => 3,
|
||||||
STEP_GATEWAY => 4,
|
STEP_GATEWAY => 4,
|
||||||
|
STEP_MONITORING => 5,
|
||||||
|
STEP_APPLY => 6,
|
||||||
STEP_STATISTICS => 1,
|
STEP_STATISTICS => 1,
|
||||||
STEP_APP_SCAN => 2,
|
STEP_APP_SCAN => 2,
|
||||||
STEP_CUSTOM_QUERIES => 3,
|
STEP_CUSTOM_QUERIES => 3,
|
||||||
@ -36,6 +38,9 @@ use constant {
|
|||||||
DISCOVERY_CLOUD_AZURE_COMPUTE => 8,
|
DISCOVERY_CLOUD_AZURE_COMPUTE => 8,
|
||||||
DISCOVERY_DEPLOY_AGENTS => 9,
|
DISCOVERY_DEPLOY_AGENTS => 9,
|
||||||
DISCOVERY_APP_SAP => 10,
|
DISCOVERY_APP_SAP => 10,
|
||||||
|
DISCOVERY_SEARCH => 0,
|
||||||
|
DISCOVERY_STANDARD => 1,
|
||||||
|
DISCOVERY_RESULTS => 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
# $DEVNULL
|
# $DEVNULL
|
||||||
@ -405,7 +410,7 @@ sub icmp_discovery($$) {
|
|||||||
'ip_target' => $addr,
|
'ip_target' => $addr,
|
||||||
'name' => "Host Alive",
|
'name' => "Host Alive",
|
||||||
'description' => '',
|
'description' => '',
|
||||||
'type' => 'generic_data',
|
'type' => 'remote_icmp_proc',
|
||||||
'id_modulo' => 2,
|
'id_modulo' => 2,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -1386,7 +1391,7 @@ sub scan_subnet($) {
|
|||||||
my $host_block_size = $self->{'block_size'};
|
my $host_block_size = $self->{'block_size'};
|
||||||
|
|
||||||
# The first 50% of the recon task approx.
|
# The first 50% of the recon task approx.
|
||||||
my $step = 40.0 / scalar(@subnets) / (($total_hosts / $host_block_size)+1);
|
my $step = 25.0 / scalar(@subnets) / (($total_hosts / $host_block_size)+1);
|
||||||
my $subnet_step = 50.0 / (($total_hosts / $host_block_size)+1);
|
my $subnet_step = 50.0 / (($total_hosts / $host_block_size)+1);
|
||||||
|
|
||||||
for (my $block_index=0;
|
for (my $block_index=0;
|
||||||
@ -1435,7 +1440,7 @@ sub scan_subnet($) {
|
|||||||
$self->call('update_progress', ceil($progress));
|
$self->call('update_progress', ceil($progress));
|
||||||
|
|
||||||
$total_hosts = scalar keys %hosts_alive;
|
$total_hosts = scalar keys %hosts_alive;
|
||||||
$step = 40.0 / scalar(@subnets) / $total_hosts;
|
$step = 25.0 / scalar(@subnets) / $total_hosts;
|
||||||
$subnet_step = 50.0 / $total_hosts;
|
$subnet_step = 50.0 / $total_hosts;
|
||||||
foreach my $addr (keys %hosts_alive) {
|
foreach my $addr (keys %hosts_alive) {
|
||||||
# Increase self summary.alive hosts.
|
# Increase self summary.alive hosts.
|
||||||
@ -1806,14 +1811,19 @@ sub scan($) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(defined($self->{'task_data'}{'direct_report'})
|
if(defined($self->{'task_data'}{'direct_report'})
|
||||||
&& $self->{'task_data'}{'direct_report'} eq "2"
|
&& $self->{'task_data'}{'direct_report'} == DISCOVERY_RESULTS
|
||||||
) {
|
) {
|
||||||
# Use Cached results.
|
# Use Cached results.
|
||||||
return $self->call('report_scanned_agents');
|
$self->call('report_scanned_agents');
|
||||||
|
|
||||||
|
# Done!
|
||||||
|
$self->{'step'} = '';
|
||||||
|
$self->call('update_progress', -1);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Find devices.
|
# Find devices.
|
||||||
$self->call('message', "[1/4] Scanning the network...", 3);
|
$self->call('message', "[1/6] Scanning the network...", 3);
|
||||||
$self->{'step'} = STEP_SCANNING;
|
$self->{'step'} = STEP_SCANNING;
|
||||||
$self->call('update_progress', $progress);
|
$self->call('update_progress', $progress);
|
||||||
|
|
||||||
@ -1829,9 +1839,9 @@ sub scan($) {
|
|||||||
$self->call('delete_connections');
|
$self->call('delete_connections');
|
||||||
|
|
||||||
# Connectivity from address forwarding tables.
|
# Connectivity from address forwarding tables.
|
||||||
$self->call('message', "[2/4] Finding address forwarding table connectivity...", 3);
|
$self->call('message', "[2/6] Finding address forwarding table connectivity...", 3);
|
||||||
$self->{'step'} = STEP_AFT;
|
$self->{'step'} = STEP_AFT;
|
||||||
($progress, $step) = (80, 8.0 / scalar(@hosts)); # From 50% to 70%.
|
($progress, $step) = (50, 10.0 / scalar(@hosts)); # From 50% to 60%.
|
||||||
for (my $i = 0; defined($hosts[$i]); $i++) {
|
for (my $i = 0; defined($hosts[$i]); $i++) {
|
||||||
$self->call('update_progress', $progress);
|
$self->call('update_progress', $progress);
|
||||||
$progress += $step;
|
$progress += $step;
|
||||||
@ -1839,9 +1849,9 @@ sub scan($) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Connect hosts that are still unconnected using traceroute.
|
# Connect hosts that are still unconnected using traceroute.
|
||||||
$self->call('message', "[3/4] Finding traceroute connectivity.", 3);
|
$self->call('message', "[3/6] Finding traceroute connectivity.", 3);
|
||||||
$self->{'step'} = STEP_TRACEROUTE;
|
$self->{'step'} = STEP_TRACEROUTE;
|
||||||
($progress, $step) = (88, 8.0 / scalar(@hosts)); # From 70% to 90%.
|
($progress, $step) = (60, 10.0 / scalar(@hosts)); # From 60% to 70%.
|
||||||
foreach my $host (@hosts) {
|
foreach my $host (@hosts) {
|
||||||
$self->call('update_progress', $progress);
|
$self->call('update_progress', $progress);
|
||||||
$progress += $step;
|
$progress += $step;
|
||||||
@ -1850,9 +1860,9 @@ sub scan($) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Connect hosts that are still unconnected using known gateways.
|
# Connect hosts that are still unconnected using known gateways.
|
||||||
$self->call('message', "[4/4] Finding host to gateway connectivity.", 3);
|
$self->call('message', "[4/6] Finding host to gateway connectivity.", 3);
|
||||||
$self->{'step'} = STEP_GATEWAY;
|
$self->{'step'} = STEP_GATEWAY;
|
||||||
($progress, $step) = (94, 6.0 / scalar(@hosts)); # From 70% to 90%.
|
($progress, $step) = (70, 10.0 / scalar(@hosts)); # From 70% to 80%.
|
||||||
$self->get_routes(); # Update the route cache.
|
$self->get_routes(); # Update the route cache.
|
||||||
foreach my $host (@hosts) {
|
foreach my $host (@hosts) {
|
||||||
$self->call('update_progress', $progress);
|
$self->call('update_progress', $progress);
|
||||||
@ -1862,9 +1872,9 @@ sub scan($) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Done!
|
# Apply monitoring templates
|
||||||
$self->{'step'} = '';
|
$self->call('message', "[5/6] Applying monitoring.", 3);
|
||||||
$self->call('update_progress', -1);
|
$self->call('apply_monitoring', $self);
|
||||||
|
|
||||||
# Print debug information on found devices.
|
# Print debug information on found devices.
|
||||||
$self->call('message', "[Summary]", 3);
|
$self->call('message', "[Summary]", 3);
|
||||||
@ -1882,9 +1892,15 @@ sub scan($) {
|
|||||||
$self->call('message', $dev_info, 3);
|
$self->call('message', $dev_info, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Apply monitoring templates
|
||||||
|
$self->call('message', "[6/6] Process results.", 3);
|
||||||
# Send agent information to Database (Discovery) or XML (satellite.).
|
# Send agent information to Database (Discovery) or XML (satellite.).
|
||||||
$self->call('report_scanned_agents', $self->{'agents_found'});
|
$self->call('report_scanned_agents', $self->{'agents_found'});
|
||||||
|
|
||||||
|
# Done!
|
||||||
|
$self->{'step'} = '';
|
||||||
|
$self->call('update_progress', -1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
Loading…
x
Reference in New Issue
Block a user