2013-03-11 Miguel de Dios <miguel.dedios@artica.es>

* include/functions_tags.php: fixed the function
	"tags_get_acl_tags_module_condition" when the user profile is in
	the all group.
	
	* include/functions_reporting.php, include/functions_alerts.php,
	operation/agentes/estado_monitores.php: improve the code style.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7826 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2013-03-11 13:57:41 +00:00
parent 3bd61d3c01
commit c715ec8231
5 changed files with 55 additions and 34 deletions

View File

@ -1,3 +1,12 @@
2013-03-11 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_tags.php: fixed the function
"tags_get_acl_tags_module_condition" when the user profile is in
the all group.
* include/functions_reporting.php, include/functions_alerts.php,
operation/agentes/estado_monitores.php: improve the code style.
2013-03-11 Miguel de Dios <miguel.dedios@artica.es> 2013-03-11 Miguel de Dios <miguel.dedios@artica.es>
* godmode/agentes/module_manager_editor_common.php: show only the * godmode/agentes/module_manager_editor_common.php: show only the

View File

@ -1167,7 +1167,7 @@ function alerts_validate_alert_agent_module ($id_alert_agent_module, $noACLs = f
$warning_instructions = db_get_value('warning_instructions', 'tagente_modulo', 'id_agente_modulo', $agent_id); $warning_instructions = db_get_value('warning_instructions', 'tagente_modulo', 'id_agente_modulo', $agent_id);
$unknown_instructions = db_get_value('unknown_instructions', 'tagente_modulo', 'id_agente_modulo', $agent_id); $unknown_instructions = db_get_value('unknown_instructions', 'tagente_modulo', 'id_agente_modulo', $agent_id);
if (!$noACLs){ if (!$noACLs) {
if (! check_acl ($config['id_user'], $group_id, "AW")) { if (! check_acl ($config['id_user'], $group_id, "AW")) {
continue; continue;
} }

View File

@ -647,6 +647,7 @@ function tags_get_tags_formatted ($tags_array, $get_url = true) {
function tags_get_acl_tags($id_user, $id_group, $access = 'AR', $return_mode = 'module_condition', $query_prefix = '', $query_table = '') { function tags_get_acl_tags($id_user, $id_group, $access = 'AR', $return_mode = 'module_condition', $query_prefix = '', $query_table = '') {
global $config; global $config;
if($id_user == false) { if($id_user == false) {
$id_user = $config['id_user']; $id_user = $config['id_user'];
} }
@ -663,23 +664,23 @@ function tags_get_acl_tags($id_user, $id_group, $access = 'AR', $return_mode = '
} }
} }
if((string)$id_group === "0") { if ((string)$id_group === "0") {
$id_group = array_keys(users_get_groups($id_user, $access, false)); $id_group = array_keys(users_get_groups($id_user, $access, false));
if(empty($id_group)) { if (empty($id_group)) {
return ERR_WRONG_PARAMETERS; return ERR_WRONG_PARAMETERS;
} }
} }
elseif(empty($id_group)) { elseif (empty($id_group)) {
return ERR_WRONG_PARAMETERS; return ERR_WRONG_PARAMETERS;
} }
elseif(!is_array($id_group)) { elseif (!is_array($id_group)) {
$id_group = (array) $id_group; $id_group = (array) $id_group;
} }
$acl_column = get_acl_column($access); $acl_column = get_acl_column($access);
if(empty($acl_column)) { if (empty($acl_column)) {
return ERR_WRONG_PARAMETERS; return ERR_WRONG_PARAMETERS;
} }
@ -693,7 +694,7 @@ function tags_get_acl_tags($id_user, $id_group, $access = 'AR', $return_mode = '
$tags = db_get_all_rows_sql($query); $tags = db_get_all_rows_sql($query);
// If not profiles returned, the user havent acl permissions // If not profiles returned, the user havent acl permissions
if(empty($tags)) { if (empty($tags)) {
return ERR_ACL; return ERR_ACL;
} }
@ -701,11 +702,11 @@ function tags_get_acl_tags($id_user, $id_group, $access = 'AR', $return_mode = '
$non_restriction_groups = array(); $non_restriction_groups = array();
$acltags = array(); $acltags = array();
foreach($tags as $tagsone) { foreach ($tags as $tagsone) {
if(empty($tagsone['tags'])) { if (empty($tagsone['tags'])) {
// If there arent tags restriction in all groups (group 0), return no condition // If there arent tags restriction in all groups (group 0), return no condition
if($tagsone['id_grupo'] == 0) { if ($tagsone['id_grupo'] == 0) {
switch($return_mode) { switch ($return_mode) {
case 'data': case 'data':
return array(); return array();
break; break;
@ -722,7 +723,7 @@ function tags_get_acl_tags($id_user, $id_group, $access = 'AR', $return_mode = '
$tags_array = explode(',',$tagsone['tags']); $tags_array = explode(',',$tagsone['tags']);
if(!isset($acltags[$tagsone['id_grupo']])) { if (!isset($acltags[$tagsone['id_grupo']])) {
$acltags[$tagsone['id_grupo']] = $tags_array; $acltags[$tagsone['id_grupo']] = $tags_array;
} }
else { else {
@ -731,13 +732,13 @@ function tags_get_acl_tags($id_user, $id_group, $access = 'AR', $return_mode = '
} }
// Delete the groups without tag restrictions from the acl tags array // Delete the groups without tag restrictions from the acl tags array
foreach($non_restriction_groups as $nrgroup) { foreach ($non_restriction_groups as $nrgroup) {
if(isset($acltags[$nrgroup])) { if (isset($acltags[$nrgroup])) {
unset($acltags[$nrgroup]); unset($acltags[$nrgroup]);
} }
} }
switch($return_mode) { switch ($return_mode) {
case 'data': case 'data':
// Stop here and return the array // Stop here and return the array
return $acltags; return $acltags;
@ -745,7 +746,7 @@ function tags_get_acl_tags($id_user, $id_group, $access = 'AR', $return_mode = '
case 'module_condition': case 'module_condition':
// Return the condition of the tags for tagente_modulo table // Return the condition of the tags for tagente_modulo table
$condition = tags_get_acl_tags_module_condition($acltags, $query_table); $condition = tags_get_acl_tags_module_condition($acltags, $query_table);
if(!empty($condition)) { if (!empty($condition)) {
return " $query_prefix ".$condition; return " $query_prefix ".$condition;
} }
break; break;
@ -771,25 +772,34 @@ function tags_get_acl_tags($id_user, $id_group, $access = 'AR', $return_mode = '
*/ */
function tags_get_acl_tags_module_condition($acltags, $modules_table = '') { function tags_get_acl_tags_module_condition($acltags, $modules_table = '') {
if(!empty($modules_table)) { if (!empty($modules_table)) {
$modules_table .= '.'; $modules_table .= '.';
} }
$condition = ''; $condition = '';
foreach($acltags as $group_id => $group_tags) { foreach ($acltags as $group_id => $group_tags) {
if($condition != '') { if ($condition != '') {
$condition .= ' OR '; $condition .= ' OR ';
} }
// Group condition (The module belongs to an agent of the group X) // Group condition (The module belongs to an agent of the group X)
if (!array_key_exists(0, array_keys($acltags))) {
$group_condition = sprintf('%sid_agente IN (SELECT id_agente FROM tagente WHERE id_grupo = %d)', $modules_table, $group_id); $group_condition = sprintf('%sid_agente IN (SELECT id_agente FROM tagente WHERE id_grupo = %d)', $modules_table, $group_id);
}
else {
//Avoid the user profiles with all group access.
$group_condition = " 1 = 1 ";
}
// Tags condition (The module has at least one of the restricted tags) // Tags condition (The module has at least one of the restricted tags)
$tags_condition = sprintf('%sid_agente_modulo IN (SELECT id_agente_modulo FROM ttag_module WHERE id_tag IN (%s))', $modules_table, implode(',',$group_tags)); $tags_condition = sprintf('%sid_agente_modulo IN (SELECT id_agente_modulo FROM ttag_module WHERE id_tag IN (%s))', $modules_table, implode(',',$group_tags));
$condition .= "($group_condition AND \n$tags_condition)\n"; $condition .= "($group_condition AND \n$tags_condition)\n";
} }
if(!empty($condition)) { //Avoid the user profiles with all group access.
//if (!empty($condition)) {
if (!empty($condition) &&
!array_key_exists(0, array_keys($acltags))) {
$condition = sprintf("\n((%s) OR %sid_agente NOT IN (SELECT id_agente FROM tagente WHERE id_grupo IN (%s)))", $condition, $modules_table, implode(',',array_keys($acltags))); $condition = sprintf("\n((%s) OR %sid_agente NOT IN (SELECT id_agente FROM tagente WHERE id_grupo IN (%s)))", $condition, $modules_table, implode(',',array_keys($acltags)));
} }

View File

@ -152,7 +152,8 @@ switch ($config["dbtype"]) {
break; break;
} }
$tags_sql = tags_get_acl_tags($config['id_user'], $agent['id_grupo'], 'AR', 'module_condition', 'AND', 'tagente_modulo'); $tags_sql = tags_get_acl_tags($config['id_user'],
$agent['id_grupo'], 'AR', 'module_condition', 'AND', 'tagente_modulo');
$status_filter_monitor = (int)get_parameter('status_filter_monitor', -1); $status_filter_monitor = (int)get_parameter('status_filter_monitor', -1);
$status_text_monitor = get_parameter('status_text_monitor', ''); $status_text_monitor = get_parameter('status_text_monitor', '');
@ -565,7 +566,8 @@ foreach ($modules as $module) {
</script> </script>
<?php <?php
echo "<h4 style='padding-top:0px !important;'>".__('Full list of monitors')."</h4>"; echo "<h4 style='padding-top:0px !important;'>" .
__('Full list of monitors') . "</h4>";
print_form_filter_monitors($status_filter_monitor, $status_text_monitor); print_form_filter_monitors($status_filter_monitor, $status_text_monitor);
if (empty ($table->data)) { if (empty ($table->data)) {