This commit is contained in:
Daniel Cebrian 2023-10-06 14:43:54 +02:00
parent 44c654cdb4
commit f48e83da01
5 changed files with 92 additions and 10 deletions

View File

@ -82,11 +82,19 @@ class Element
$this->interval = 0; $this->interval = 0;
$this->title = __('Default element'); $this->title = __('Default element');
$this->ajaxController = $ajax_controller; $this->ajaxController = $ajax_controller;
$agent = agents_get_agents(['nombre' => 'pandora.internals']); // Without ACL.
if (is_array($agent) === true && count($agent) > 0) { $agent = db_get_row('tagente', 'nombre', 'pandora.internals', '*');
$this->monitoringAgent = $agent[0]; if (is_array($agent) === true) {
$this->monitoringAgent = $agent;
} }
/*
// With ACL.
$agent = agents_get_agents(['nombre' => 'pandora.internals']);
if (is_array($agent) === true && count($agent) > 0) {
$this->monitoringAgent = $agent[0];
}
*/
} }

View File

@ -139,7 +139,18 @@ class Agents extends Element
$start = get_parameter('start', 0); $start = get_parameter('start', 0);
$length = get_parameter('length', $config['block_size']); $length = get_parameter('length', $config['block_size']);
$pagination = ''; $pagination = '';
$order = '';
$id_groups = array_keys(users_get_groups($config['id_user'], 'AR', false));
if (in_array(0, $id_groups) === false) {
foreach ($id_groups as $key => $id_group) {
if ((bool) check_acl_restricted_all($config['id_user'], $id_group, 'AR') === false) {
unset($id_groups[$key]);
}
}
}
$id_groups = implode(',', $id_groups);
try { try {
ob_start(); ob_start();
@ -169,8 +180,10 @@ class Agents extends Element
SELECT gr.id_grupo, count(*) AS total SELECT gr.id_grupo, count(*) AS total
FROM tagente a LEFT JOIN tagent_secondary_group g ON g.id_agent = a.id_agente FROM tagente a LEFT JOIN tagent_secondary_group g ON g.id_agent = a.id_agente
LEFT JOIN tgrupo gr ON gr.id_grupo = a.id_grupo LEFT JOIN tgrupo gr ON gr.id_grupo = a.id_grupo
WHERE a.id_grupo IN ('.$id_groups.') OR g.id_group IN ('.$id_groups.')
GROUP BY a.id_grupo ORDER BY total DESC LIMIT 20 GROUP BY a.id_grupo ORDER BY total DESC LIMIT 20
) top_groups ON top_groups.id_grupo = gr.id_grupo ) top_groups ON top_groups.id_grupo = gr.id_grupo
WHERE a.id_grupo IN ('.$id_groups.') OR g.id_group IN ('.$id_groups.')
GROUP BY a.id_grupo GROUP BY a.id_grupo
ORDER BY total DESC ORDER BY total DESC
%s', %s',
@ -193,8 +206,10 @@ class Agents extends Element
SELECT gr.id_grupo, count(*) AS total SELECT gr.id_grupo, count(*) AS total
FROM tagente a LEFT JOIN tagent_secondary_group g ON g.id_agent = a.id_agente FROM tagente a LEFT JOIN tagent_secondary_group g ON g.id_agent = a.id_agente
LEFT JOIN tgrupo gr ON gr.id_grupo = a.id_grupo LEFT JOIN tgrupo gr ON gr.id_grupo = a.id_grupo
WHERE a.id_grupo IN ('.$id_groups.') OR g.id_group IN ('.$id_groups.')
GROUP BY a.id_grupo ORDER BY total DESC LIMIT 20 GROUP BY a.id_grupo ORDER BY total DESC LIMIT 20
) top_groups ON top_groups.id_grupo = gr.id_grupo ) top_groups ON top_groups.id_grupo = gr.id_grupo
WHERE a.id_grupo IN ('.$id_groups.') OR g.id_group IN ('.$id_groups.')
GROUP BY a.id_grupo GROUP BY a.id_grupo
ORDER BY total DESC'; ORDER BY total DESC';
@ -214,7 +229,7 @@ class Agents extends Element
return json_encode(['error' => $e->getMessage()]); return json_encode(['error' => $e->getMessage()]);
} }
json_decode($response); return json_decode($response);
if (json_last_error() === JSON_ERROR_NONE) { if (json_last_error() === JSON_ERROR_NONE) {
return $response; return $response;
} else { } else {
@ -235,9 +250,25 @@ class Agents extends Element
*/ */
public function getOperatingSystemGraph():string public function getOperatingSystemGraph():string
{ {
global $config;
$id_groups = array_keys(users_get_groups($config['id_user'], 'AR', false));
if (in_array(0, $id_groups) === false) {
foreach ($id_groups as $key => $id_group) {
if ((bool) check_acl_restricted_all($config['id_user'], $id_group, 'AR') === false) {
unset($id_groups[$key]);
}
}
}
$id_groups = implode(',', $id_groups);
$sql = 'SELECT name, count(*) AS total $sql = 'SELECT name, count(*) AS total
FROM tagente a FROM tagente a
LEFT JOIN tagent_secondary_group g ON g.id_agent = a.id_agente
LEFT JOIN tgrupo gr ON gr.id_grupo = a.id_grupo
LEFT JOIN tconfig_os os ON os.id_os = a.id_os LEFT JOIN tconfig_os os ON os.id_os = a.id_os
WHERE a.id_grupo IN ('.$id_groups.') OR g.id_group IN ('.$id_groups.')
GROUP BY a.id_os GROUP BY a.id_os
ORDER BY total DESC'; ORDER BY total DESC';
$rows = db_process_sql($sql); $rows = db_process_sql($sql);

View File

@ -329,4 +329,17 @@ class Database extends Element
} }
/**
* Check if user can manage database
*
* @return boolean
*/
public function checkAcl():bool
{
global $config;
$db_m = (bool) check_acl($config['id_user'], 0, 'DM');
return $db_m;
}
} }

View File

@ -95,10 +95,24 @@ class MonitoringElements extends Element
*/ */
public function getModuleGroupGraph():string public function getModuleGroupGraph():string
{ {
global $config;
$id_groups = array_keys(users_get_groups($config['id_user'], 'AR', false));
if (in_array(0, $id_groups) === false) {
foreach ($id_groups as $key => $id_group) {
if ((bool) check_acl_restricted_all($config['id_user'], $id_group, 'AR') === false) {
unset($id_groups[$key]);
}
}
}
$id_groups = implode(',', $id_groups);
$sql = 'SELECT name, count(*) AS total $sql = 'SELECT name, count(*) AS total
FROM tagente_modulo m FROM tagente_modulo m
LEFT JOIN tagente a on a.id_agente = m.id_agente
LEFT JOIN tagent_secondary_group gs ON gs.id_agent = a.id_agente
LEFT JOIN tmodule_group g ON g.id_mg = m.id_module_group LEFT JOIN tmodule_group g ON g.id_mg = m.id_module_group
WHERE name <> "" WHERE name <> "" AND (a.id_grupo IN ('.$id_groups.') OR gs.id_group IN ('.$id_groups.'))
GROUP BY m.id_module_group GROUP BY m.id_module_group
ORDER BY total DESC ORDER BY total DESC
LIMIT 10'; LIMIT 10';
@ -145,15 +159,29 @@ class MonitoringElements extends Element
*/ */
public function getAgentGroupsGraph():string public function getAgentGroupsGraph():string
{ {
global $config;
$id_groups = array_keys(users_get_groups($config['id_user'], 'AR', false));
if (in_array(0, $id_groups) === false) {
foreach ($id_groups as $key => $id_group) {
if ((bool) check_acl_restricted_all($config['id_user'], $id_group, 'AR') === false) {
unset($id_groups[$key]);
}
}
}
$id_groups = implode(',', $id_groups);
$sql = 'SELECT gr.nombre, count(*) + $sql = 'SELECT gr.nombre, count(*) +
IFNULL((SELECT count(*) AS total IFNULL((SELECT count(*) AS total
FROM tagente second_a FROM tagente second_a
LEFT JOIN tagent_secondary_group second_g ON second_g.id_agent = second_a.id_agente LEFT JOIN tagent_secondary_group second_g ON second_g.id_agent = second_a.id_agente
WHERE a.id_grupo = second_g.id_group WHERE a.id_grupo = second_g.id_group AND second_g.id_group IN ('.$id_groups.')
GROUP BY second_g.id_group GROUP BY second_g.id_group
), 0) AS total ), 0) AS total
FROM tagente a FROM tagente a
LEFT JOIN tgrupo gr ON gr.id_grupo = a.id_grupo LEFT JOIN tgrupo gr ON gr.id_grupo = a.id_grupo
WHERE a.id_grupo IN ('.$id_groups.')
GROUP BY a.id_grupo GROUP BY a.id_grupo
ORDER BY total DESC ORDER BY total DESC
LIMIT 10'; LIMIT 10';

View File

@ -53,7 +53,7 @@
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-7 pdd_5px"> <div class="<?php echo ($Database->checkAcl() === true) ? 'col-7 pdd_5px' : 'col-12 pdd_5px'; ?>">
<div class="container"> <div class="container">
<div class="title"> <div class="title">
<?php echo $MonitoringElements->title; ?> <?php echo $MonitoringElements->title; ?>
@ -91,6 +91,7 @@
</div> </div>
</div> </div>
<?php if ($Database->checkAcl() === true) : ?>
<div class="col-5 pdd_5px"> <div class="col-5 pdd_5px">
<div class="container" id="database"> <div class="container" id="database">
<div class="title"> <div class="title">
@ -141,6 +142,7 @@
</div> </div>
</div> </div>
<?php endif; ?>
</div> </div>
</div> </div>
<div class="col-xl-6"> <div class="col-xl-6">
@ -238,7 +240,7 @@
<div class="title br-b"> <div class="title br-b">
<?php echo $Alerts->title; ?> <?php echo $Alerts->title; ?>
</div> </div>
<div class="row"> <div class="row br-b">
<div class="col-6"> <div class="col-6">
<div class="subtitle"> <div class="subtitle">
<?php echo __('Currently triggered'); ?> <?php echo __('Currently triggered'); ?>
@ -254,7 +256,7 @@
</div> </div>
<?php if ($Alerts->checkAclUserList() === true) : ?> <?php if ($Alerts->checkAclUserList() === true) : ?>
<div id="list-users"> <div id="list-users">
<div class="subtitle link padding10 padding2 br-t"> <div class="subtitle link padding10 padding2">
<b><?php echo __('Logged in users (24 hrs)'); ?></b> <a href=""><?php echo __('More details'); ?></a> <b><?php echo __('Logged in users (24 hrs)'); ?></b> <a href=""><?php echo __('More details'); ?></a>
</div> </div>
<?php echo $Alerts->getDataTableUsers(); ?> <?php echo $Alerts->getDataTableUsers(); ?>