2012-10-11 Miguel de Dios <miguel.dedios@artica.es>

* include/ajax/networkmap.ajax.php: added the code for the
	metaconsole in the call "get_networkmap_summary" and added the
	call "get_networkmap_summary_pandora_server" for the tooltips in
	the metaconsole networkmap in the pandoras children nodes.
	
	* include/functions_agents.php: improve the execution time and
	cleaned the code for the function "agents_get_modules".




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7067 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2012-10-11 10:20:37 +00:00
parent 73bb12d30a
commit 55fe5262bc
3 changed files with 131 additions and 41 deletions

View File

@ -1,3 +1,13 @@
2012-10-11 Miguel de Dios <miguel.dedios@artica.es>
* include/ajax/networkmap.ajax.php: added the code for the
metaconsole in the call "get_networkmap_summary" and added the
call "get_networkmap_summary_pandora_server" for the tooltips in
the metaconsole networkmap in the pandoras children nodes.
* include/functions_agents.php: improve the execution time and
cleaned the code for the function "agents_get_modules".
2012-10-11 Junichi Satoh <junichi@rworks.jp>
* include/help/ja/help_response_parameters.php,

View File

@ -28,6 +28,9 @@ if (! check_acl ($config['id_user'], 0, "IR")) {
$action = get_parameter('action');
//error_reporting(E_ALL);
//ini_set("display_errors", 1);
switch($action) {
case 'get_networkmap_summary':
$stats = get_parameter('stats', array());
@ -55,18 +58,45 @@ switch($action) {
}
if (isset($stats['agents'])) {
$summary .= count($stats['agents']) .
" x " . html_print_image($hack_metaconsole . 'images/bricks.png',true) .
' ' . __('Agents') . "<br>";
// TODO: GET STATUS OF THE AGENTS AND ADD IT TO SUMMARY
//~ $status_agents = array();
//~ foreach($stats['agents'] as $id_agent) {
//~ $st = agents_get_status($id_agent);
//~ if(!isset($status_agents[$st])) {
//~ $status_agents[$st] = 0;
//~ }
//~ $status_agents[$st] ++;
//~ }
if ($metaconsole) {
include_once ('include/functions_reporting.php');
$servers = db_get_all_rows_sql ("SELECT *
FROM tmetaconsole_setup");
if ($servers === false)
$servers = array();
$total_agents = 0;
foreach ($servers as $server) {
// If connection was good then retrieve all data server
if (metaconsole_load_external_db ($server)) {
$connection = true;
}
else {
$connection = false;
}
if ($connection)
$data = reporting_get_group_stats();
metaconsole_restore_db();
$total_agents += $data["total_agents"];
}
$total_agents = format_numeric($total_agents);
$summary .= $total_agents .
" x " . html_print_image($hack_metaconsole . 'images/bricks.png',true) .
' ' . __('Agents') . "<br>";
}
else {
$summary .= count($stats['agents']) .
" x " . html_print_image($hack_metaconsole . 'images/bricks.png',true) .
' ' . __('Agents') . "<br>";
}
}
if (isset($stats['modules'])) {
@ -74,9 +104,64 @@ switch($action) {
$summary .= count($stats['modules'])." x ".html_print_image('images/brick.png',true).' '.__('Modules')."<br>";
}
echo '<h3>'.__('Map summary').'</h3><strong>'.$summary.'</strong>';
break;
case 'get_networkmap_summary_pandora_server':
$id_server = (int)get_parameter('id_server', 0);
$stats = get_parameter('stats', array());
$stats = json_decode(base64_decode($stats),true);
$metaconsole = (bool)get_parameter('metaconsole', false);
$hack_metaconsole = '';
if ($metaconsole) {
$hack_metaconsole = '../../';
}
$summary = '<br>';
if (isset($stats['agents'])) {
if ($metaconsole) {
include_once ('include/functions_reporting.php');
$servers = db_get_all_rows_sql ("SELECT *
FROM tmetaconsole_setup
WHERE id = " . $id_server);
if ($servers === false)
$servers = array();
$total_agents = 0;
foreach ($servers as $server) {
// If connection was good then retrieve all data server
if (metaconsole_load_external_db ($server)) {
$connection = true;
}
else {
$connection = false;
}
if ($connection)
$data = reporting_get_group_stats();
metaconsole_restore_db();
$total_agents += $data["total_agents"];
}
$total_agents = format_numeric($total_agents);
$summary .= $total_agents .
" x " . html_print_image($hack_metaconsole . 'images/bricks.png',true) .
' ' . __('Agents') . "<br>";
}
else {
$summary .= count($stats['agents']) .
" x " . html_print_image($hack_metaconsole . 'images/bricks.png',true) .
' ' . __('Agents') . "<br>";
}
}
echo '<h3>'.__('Map summary').'</h3><strong>'.$summary.'</strong>';
break;
}
?>
?>

View File

@ -1097,22 +1097,23 @@ function agents_get_group_agents ($id_group = 0, $search = false, $case = "lower
function agents_get_modules ($id_agent = null, $details = false, $filter = false, $indexed = true, $get_not_init_modules = true, $noACLs = false) {
global $config;
// TODO: Clean extra_sql
$policy_sql = '';
$userGroups = users_get_groups($config['id_user'], 'AR', false);
if (empty($userGroups)) {
return array();
}
$id_userGroups = $id_groups = array_keys($groups);
// =================================================================
// When there is not a agent id. Get a agents of groups that the
// user can read the agents.
// =================================================================
if ($id_agent === null) {
//Extract the agents of group user.
$groups = users_get_groups(false, 'AR', false);
if(empty($groups)) {
return array();
}
$id_groups = array_keys($groups);
$sql = "SELECT id_agente FROM tagente WHERE id_grupo IN (" . implode(',', $id_groups) . ")";
$sql = "SELECT id_agente
FROM tagente
WHERE id_grupo IN (" . implode(',', $id_groups) . ")";
$id_agent = db_get_all_rows_sql($sql);
if($id_agent == false) {
if ($id_agent == false) {
$id_agent = array();
}
@ -1123,18 +1124,13 @@ function agents_get_modules ($id_agent = null, $details = false, $filter = false
$id_agent = $temp;
}
// =================================================================
// Fixed strange values. Only array of ids or id as int
// =================================================================
if (!is_array($id_agent)) {
$id_agent = safe_int ($id_agent, 1);
}
$userGroups = users_get_groups($config['id_user'], 'AR', false);
if(empty($userGroups)) {
return array();
}
$id_userGroups = array_keys($userGroups);
$where = "(
1 = (
SELECT is_admin
@ -1158,13 +1154,12 @@ function agents_get_modules ($id_agent = null, $details = false, $filter = false
FROM tperfil WHERE agent_view = 1
)
)
" . $policy_sql . "
)";
if (! empty ($id_agent)) {
$where .= sprintf (' AND id_agente IN (%s)', implode (",", (array) $id_agent));
}
$where .= ' AND delete_pending = 0 ';
if (! empty ($filter)) {
@ -1181,7 +1176,7 @@ function agents_get_modules ($id_agent = null, $details = false, $filter = false
}
if ($value[0] == '%') {
switch ($config['dbtype']){
switch ($config['dbtype']) {
case "mysql":
case "postgresql":
array_push ($fields, $field.' LIKE "'.$value.'"');
@ -1195,7 +1190,7 @@ function agents_get_modules ($id_agent = null, $details = false, $filter = false
array_push($fields, $field.' <> ' . substr($value, 2));
}
else if (substr($value, -1) == '%') {
switch ($config['dbtype']){
switch ($config['dbtype']) {
case "mysql":
case "postgresql":
array_push ($fields, $field.' LIKE "'.$value.'"');
@ -1206,7 +1201,7 @@ function agents_get_modules ($id_agent = null, $details = false, $filter = false
}
}
//else if (strstr($value, '666=666', true) == '') {
else if (strncmp($value, '666=666', 7) == 0){
else if (strncmp($value, '666=666', 7) == 0) {
switch ($config['dbtype']) {
case "mysql":
case "postgresql":
@ -1245,7 +1240,7 @@ function agents_get_modules ($id_agent = null, $details = false, $filter = false
$details = "nombre";
}
else {
if ($config['dbtype'] == 'oracle'){
if ($config['dbtype'] == 'oracle') {
$details_new = array();
if (is_array($details)) {
foreach ($details as $detail) {