Wip cluster view

This commit is contained in:
fbsanchez 2020-05-21 19:28:24 +02:00
parent 523212afb8
commit b0e8287c61
4 changed files with 92 additions and 96 deletions

View File

@ -551,6 +551,13 @@ if (check_login()) {
include_once $config['homedir'].'/include/functions_tags.php'; include_once $config['homedir'].'/include/functions_tags.php';
include_once $config['homedir'].'/include/functions_clippy.php'; include_once $config['homedir'].'/include/functions_clippy.php';
// Disable module edition in cluster module list.
$cluster_view = (bool) preg_match(
'/operation\/cluster\/cluster/',
$_SERVER['HTTP_REFERER']
);
$agent_a = check_acl($config['id_user'], 0, 'AR'); $agent_a = check_acl($config['id_user'], 0, 'AR');
$agent_w = check_acl($config['id_user'], 0, 'AW'); $agent_w = check_acl($config['id_user'], 0, 'AW');
$access = ($agent_a == true) ? 'AR' : (($agent_w == true) ? 'AW' : 'AR'); $access = ($agent_a == true) ? 'AR' : (($agent_w == true) ? 'AW' : 'AR');
@ -962,7 +969,9 @@ if (check_login()) {
$data[2] = servers_show_type($module['id_modulo']).' '; $data[2] = servers_show_type($module['id_modulo']).' ';
if (check_acl($config['id_user'], $id_grupo, 'AW')) { if (check_acl($config['id_user'], $id_grupo, 'AW')
&& $cluster_view === false
) {
$data[2] .= '<a href="index.php?sec=gagente&amp;sec2=godmode/agentes/configurar_agente&amp;id_agente='.$id_agente.'&amp;tab=module&amp;id_agent_module='.$module['id_agente_modulo'].'&amp;edit_module='.$module['id_modulo'].'">'.html_print_image('images/config.png', true, ['alt' => '0', 'border' => '', 'title' => __('Edit'), 'class' => 'action_button_img']).'</a>'; $data[2] .= '<a href="index.php?sec=gagente&amp;sec2=godmode/agentes/configurar_agente&amp;id_agente='.$id_agente.'&amp;tab=module&amp;id_agent_module='.$module['id_agente_modulo'].'&amp;edit_module='.$module['id_modulo'].'">'.html_print_image('images/config.png', true, ['alt' => '0', 'border' => '', 'title' => __('Edit'), 'class' => 'action_button_img']).'</a>';
} }

View File

@ -514,6 +514,8 @@ class NetworkMap
*/ */
public function createMap() public function createMap()
{ {
global $config;
// If exists, load from DB. // If exists, load from DB.
if ($this->idMap) { if ($this->idMap) {
$this->loadMap(); $this->loadMap();
@ -1025,13 +1027,17 @@ class NetworkMap
// Handmade ones. // Handmade ones.
// Add also parent relationship. // Add also parent relationship.
if (isset($node['id_parent'])) { if (isset($node['id_parent'])) {
$parent_id = $node['id_parent']; $parent_id = NODE_AGENT.'_'.$node['id_parent'];
$parent_node = $this->nodes[$parent_id]['id_node'];
if ((int) $parent_id >= 0) { if ($parent_node === null) {
$parent_node = $this->getNodeData( $parent_id = NODE_MODULE.'_'.$node['id_parent'];
(int) $parent_id, $parent_node = $this->nodes[$parent_id]['id_node'];
'id_node' }
);
if ($parent_node === null) {
$parent_id = NODE_GENERIC.'_'.$node['id_parent'];
$parent_node = $this->nodes[$parent_id]['id_node'];
} }
// Store relationship. // Store relationship.
@ -1130,6 +1136,7 @@ class NetworkMap
$map_filter = $this->mapOptions['map_filter']; $map_filter = $this->mapOptions['map_filter'];
$nooverlap = $this->mapOptions['nooverlap']; $nooverlap = $this->mapOptions['nooverlap'];
$zoom = $this->mapOptions['zoom']; $zoom = $this->mapOptions['zoom'];
$layout = $this->mapOptions['layout'];
if (isset($this->mapOptions['width']) if (isset($this->mapOptions['width'])
&& isset($this->mapOptions['height']) && isset($this->mapOptions['height'])
@ -1152,7 +1159,7 @@ class NetworkMap
$size = $size_x.','.$size_y; $size = $size_x.','.$size_y;
if ($size_canvas === null) { if ($this->mapOptions['size_canvas'] !== null) {
$size = ($this->mapOptions['size_canvas']['x'] / 100); $size = ($this->mapOptions['size_canvas']['x'] / 100);
$size .= ','.($this->mapOptions['size_canvas']['y'] / 100); $size .= ','.($this->mapOptions['size_canvas']['y'] / 100);
} }
@ -1274,12 +1281,7 @@ class NetworkMap
$radius /= GRAPHVIZ_CONVERSION_FACTOR; $radius /= GRAPHVIZ_CONVERSION_FACTOR;
if (is_array($label)) { if (is_array($label)) {
$label = array_reduce( $label = join('', $label);
function ($carry, $item) {
$carry .= $item;
return $carry;
}
);
} }
if (strlen($label) > 16) { if (strlen($label) > 16) {
@ -1295,7 +1297,7 @@ class NetworkMap
// retrieve X,Y positions from graphviz no for personalization. // retrieve X,Y positions from graphviz no for personalization.
$dot_str = $data['id_node'].' [ parent="'.$data['id_parent'].'"'; $dot_str = $data['id_node'].' [ parent="'.$data['id_parent'].'"';
$dot_str .= ', color="'.$color.'", fontsize='.$font_size; $dot_str .= ', color="'.$color.'", fontsize='.$font_size;
$dot_str .= ', shape="doublecircle"'.$url_node_link; $dot_str .= ', shape="doublecircle"'.$data['url_node_link'];
$dot_str .= ', style="filled", fixedsize=true, width='.$radius; $dot_str .= ', style="filled", fixedsize=true, width='.$radius;
$dot_str .= ', height='.$radius.', label="'.$label.'"]'."\n"; $dot_str .= ', height='.$radius.', label="'.$label.'"]'."\n";
@ -1596,6 +1598,7 @@ class NetworkMap
global $config; global $config;
$return = []; $return = [];
$count_item_holding_area = 0;
foreach ($nodes as $node) { foreach ($nodes as $node) {
$item = []; $item = [];
$item['id'] = $node['id']; $item['id'] = $node['id'];
@ -1669,8 +1672,11 @@ class NetworkMap
default: default:
foreach ($source_data as $k => $v) { foreach ($source_data as $k => $v) {
$node[$k] = $v; $node[$k] = $v;
$item[$k] = $v;
} }
$item['id_agent'] = $node['id_agente'];
if (!empty($node['text'])) { if (!empty($node['text'])) {
$node['style']['label'] = $node['text']; $node['style']['label'] = $node['text'];
} else { } else {
@ -2193,6 +2199,7 @@ class NetworkMap
$nodes = []; $nodes = [];
$relations = []; $relations = [];
foreach ($content as $key => $line) { foreach ($content as $key => $line) {
// Reduce blank spaces. // Reduce blank spaces.
$line = preg_replace('/\ +/', ' ', $line); $line = preg_replace('/\ +/', ' ', $line);
@ -2232,12 +2239,12 @@ class NetworkMap
} }
$relations[] = [ $relations[] = [
'id_parent' => $target_node['id_node'], 'id_parent' => $fields[1],
'parent_type' => NODE_GENERIC, 'parent_type' => NODE_GENERIC,
'id_parent_source_data' => $mod_rel['module_b'], 'id_parent_source_data' => $fields[3],
'id_child' => $node['id_node'], 'id_child' => $fields[2],
'child_type' => NODE_GENERIC, 'child_type' => NODE_GENERIC,
'id_child_source_data' => $mod_rel['module_a'], 'id_child_source_data' => null,
]; ];
} }
} }
@ -2268,11 +2275,11 @@ class NetworkMap
case 'WIN32': case 'WIN32':
case 'WINNT': case 'WINNT':
case 'Windows': case 'Windows':
$filename_dot = sys_get_temp_dir()."\\networkmap_".$filter; $filename_dot = sys_get_temp_dir()."\\networkmap_".$this->filter;
break; break;
default: default:
$filename_dot = sys_get_temp_dir().'/networkmap_'.$filter; $filename_dot = sys_get_temp_dir().'/networkmap_'.$this->filter;
break; break;
} }
@ -2395,36 +2402,6 @@ class NetworkMap
} }
/**
* Returns the most representative ID based on the tipe of node received.
*
* @param array $node Source data.
*
* @return integer Source id.
*/
private function auxGetIdByType($node)
{
if (!is_array($node)) {
return 0;
}
switch ($to_source['node_type']) {
case NODE_MODULE:
return $node['id_agente_modulo'];
case NODE_AGENT:
return $node['id_agente'];
case NODE_GENERIC:
return $node['id_node'];
case NODE_PANDORA:
default:
return 0;
}
}
/** /**
* Generates a nodes - relationships array using graphviz dot * Generates a nodes - relationships array using graphviz dot
* schema and stores nodes&relations into $this->graph. * schema and stores nodes&relations into $this->graph.
@ -2551,6 +2528,7 @@ class NetworkMap
$node_tmp['id_agent'] = $source['id_agente']; $node_tmp['id_agent'] = $source['id_agente'];
$node_tmp['id_module'] = $source['id_agente_modulo']; $node_tmp['id_module'] = $source['id_agente_modulo'];
$node_tmp['source_data'] = $source['id_source']; $node_tmp['source_data'] = $source['id_source'];
$node_tmp['image'] = $source['image'];
break; break;
} }
@ -3314,9 +3292,11 @@ class NetworkMap
/** /**
* Loads advanced map controller (JS). * Loads advanced map controller (JS).
* *
* @param boolean $return Dumps to output if false.
*
* @return string HTML code for advanced controller. * @return string HTML code for advanced controller.
*/ */
public function loadController() public function loadController(?bool $return=true)
{ {
$output = ''; $output = '';
@ -3514,6 +3494,8 @@ class NetworkMap
{ {
global $config; global $config;
$networkmap = $this->map;
// ACL. // ACL.
$networkmap_read = check_acl( $networkmap_read = check_acl(
$config['id_user'], $config['id_user'],

View File

@ -19,3 +19,7 @@
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
.w100p.modules {
min-width: 985px;
}

View File

@ -1404,63 +1404,64 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($;$) {
$self->call('message', "Storing results", 6); $self->call('message', "Storing results", 6);
my @hosts = keys %{$self->{'agents_found'}}; my @hosts = keys %{$self->{'agents_found'}};
$self->{'step'} = STEP_PROCESSING; $self->{'step'} = STEP_PROCESSING;
my ($progress, $step) = (90, 10.0 / scalar(@hosts)); # From 90% to 100%. if ((scalar (@hosts)) > 0) {
my ($progress, $step) = (90, 10.0 / scalar(@hosts)); # From 90% to 100%.
foreach my $addr (keys %{$self->{'agents_found'}}) { foreach my $addr (keys %{$self->{'agents_found'}}) {
my $label = $self->{'agents_found'}->{$addr}{'agent'}{'nombre'}; my $label = $self->{'agents_found'}->{$addr}{'agent'}{'nombre'};
next if is_empty($label); next if is_empty($label);
# Retrieve target agent OS version. # Retrieve target agent OS version.
$self->{'agents_found'}->{$addr}{'agent'}{'id_os'} = $self->guess_os($addr); $self->{'agents_found'}->{$addr}{'agent'}{'id_os'} = $self->guess_os($addr);
$self->call('update_progress', $progress); $self->call('update_progress', $progress);
$progress += $step; $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( $encoded = encode_base64(
p_encode_json($self->{'pa_config'}, $self->{'agents_found'}->{$addr}) p_encode_json($self->{'pa_config'}, $self->{'agents_found'}->{$addr})
); );
}; };
my $id = get_db_value( my $id = get_db_value(
$self->{'dbh'},
'SELECT id FROM tdiscovery_tmp_agents WHERE id_rt = ? AND label = ?',
$self->{'task_data'}{'id_rt'},
safe_input($label)
);
if (defined($id)) {
# Already defined.
$self->{'agents_found'}{$addr}{'id'} = $id;
db_do(
$self->{'dbh'}, $self->{'dbh'},
'UPDATE tdiscovery_tmp_agents SET `data` = ? ' 'SELECT id FROM tdiscovery_tmp_agents WHERE id_rt = ? AND label = ?',
.'WHERE `id_rt` = ? AND `label` = ?',
$encoded,
$self->{'task_data'}{'id_rt'}, $self->{'task_data'}{'id_rt'},
safe_input($label) safe_input($label)
); );
next;
if (defined($id)) {
# Already defined.
$self->{'agents_found'}{$addr}{'id'} = $id;
db_do(
$self->{'dbh'},
'UPDATE tdiscovery_tmp_agents SET `data` = ? '
.'WHERE `id_rt` = ? AND `label` = ?',
$encoded,
$self->{'task_data'}{'id_rt'},
safe_input($label)
);
next;
}
# Insert.
$self->{'agents_found'}{$addr}{'id'} = db_insert(
$self->{'dbh'},
'id',
'INSERT INTO tdiscovery_tmp_agents (`id_rt`,`label`,`data`,`created`) '
.'VALUES (?, ?, ?, now())',
$self->{'task_data'}{'id_rt'},
safe_input($label),
$encoded
);
} }
# Insert.
$self->{'agents_found'}{$addr}{'id'} = db_insert(
$self->{'dbh'},
'id',
'INSERT INTO tdiscovery_tmp_agents (`id_rt`,`label`,`data`,`created`) '
.'VALUES (?, ?, ?, now())',
$self->{'task_data'}{'id_rt'},
safe_input($label),
$encoded
);
} }
if(defined($self->{'task_data'}{'review_mode'}) if(defined($self->{'task_data'}{'review_mode'})
&& $self->{'task_data'}{'review_mode'} == DISCOVERY_REVIEW && $self->{'task_data'}{'review_mode'} == DISCOVERY_REVIEW
) { ) {