2012-07-18 Miguel de Dios <miguel.dedios@artica.es>

* extensions/resource_registration.php,
	extensions/update_manager/lib/libupdate_manager.php,
	extensions/plugin_registration.php,
	operation/incidents/incident.php,
	mobile/operation/agents/monitor_status.php,
	mobile/operation/agents/view_agents.php: cleaned source code style.

	* operation/tree.php: improve the code for to set more readble.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6789 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2012-07-18 14:31:58 +00:00
parent 5da06e0448
commit 50cd6e1033
8 changed files with 515 additions and 501 deletions

View File

@ -1,3 +1,14 @@
2012-07-18 Miguel de Dios <miguel.dedios@artica.es>
* extensions/resource_registration.php,
extensions/update_manager/lib/libupdate_manager.php,
extensions/plugin_registration.php,
operation/incidents/incident.php,
mobile/operation/agents/monitor_status.php,
mobile/operation/agents/view_agents.php: cleaned source code style.
* operation/tree.php: improve the code for to set more readble.
2012-07-18 Miguel de Dios <miguel.dedios@artica.es> 2012-07-18 Miguel de Dios <miguel.dedios@artica.es>
* general/logon_ok.php, godmode/db/db_event.php, * general/logon_ok.php, godmode/db/db_event.php,

View File

@ -105,7 +105,8 @@ class MonitorStatus {
$sqlStatus = " AND tagente_estado.estado = 3"; $sqlStatus = " AND tagente_estado.estado = 3";
} }
elseif ($status == 5) { //Not init elseif ($status == 5) { //Not init
$sqlStatus = " AND tagente_estado.utimestamp = 0 AND tagente_modulo.id_tipo_modulo NOT IN (21,22,23,100)"; $sqlStatus = " AND tagente_estado.utimestamp = 0
AND tagente_modulo.id_tipo_modulo NOT IN (21,22,23,100)";
} }

View File

@ -235,7 +235,6 @@ if (is_ajax ())
case 'module_group': case 'module_group':
case 'policies': case 'policies':
case 'module': case 'module':
$avariableGroups = users_get_groups(); $avariableGroups = users_get_groups();
$avariableGroupsIds = array_keys($avariableGroups); $avariableGroupsIds = array_keys($avariableGroups);
@ -250,7 +249,8 @@ if (is_ajax ())
if ($search_free != '') { if ($search_free != '') {
$search_sql = " AND nombre COLLATE utf8_general_ci LIKE '%$search_free%'"; $search_sql = " AND nombre COLLATE utf8_general_ci LIKE '%$search_free%'";
} else { }
else {
$search_sql = ''; $search_sql = '';
} }
@ -269,12 +269,10 @@ if (is_ajax ())
'disabled' => 0, 'disabled' => 0,
'status' => $statusSel, 'status' => $statusSel,
'search' => $search_sql), 'search' => $search_sql),
array ('*'), array ('*'),
'AR', 'AR',
false, false,
true); true);
break; break;
case 'os': case 'os':
@ -290,12 +288,10 @@ if (is_ajax ())
'disabled' => 0, 'disabled' => 0,
'status' => $statusSel, 'status' => $statusSel,
'search' => $search_sql), 'search' => $search_sql),
array ('*'), array ('*'),
'AR', 'AR',
false, false,
true); true);
break; break;
case 'module_group': case 'module_group':
@ -312,7 +308,6 @@ if (is_ajax ())
'disabled' => 0, 'disabled' => 0,
'status' => $statusSel, 'status' => $statusSel,
'search' => $search_sql), 'search' => $search_sql),
array ('*'), array ('*'),
'AR', 'AR',
false, false,
@ -327,7 +322,6 @@ if (is_ajax ())
AND tagente_modulo.disabled = 0 AND tagente_modulo.disabled = 0
group by tagente.id_agente group by tagente.id_agente
having COUNT(*) > 0)'; having COUNT(*) > 0)';
break; break;
case 'policies': case 'policies':
@ -342,7 +336,6 @@ if (is_ajax ())
true); true);
if ($id != 0) { if ($id != 0) {
// Skip agents without modules // Skip agents without modules
$sql .= ' AND tagente.id_agente IN $sql .= ' AND tagente.id_agente IN
(SELECT tagente.id_agente (SELECT tagente.id_agente
@ -357,7 +350,6 @@ if (is_ajax ())
AND tpolicy_modules.id_policy = ' . $id . ' AND tpolicy_modules.id_policy = ' . $id . '
group by tagente.id_agente group by tagente.id_agente
having COUNT(*) > 0)'; having COUNT(*) > 0)';
} }
else if ($statusSel == 0) { else if ($statusSel == 0) {
@ -366,11 +358,7 @@ if (is_ajax ())
WHERE tagente.disabled = 0 WHERE tagente.disabled = 0
AND tagente.id_agente NOT IN (SELECT tagente_estado.id_agente AND tagente.id_agente NOT IN (SELECT tagente_estado.id_agente
FROM tagente_estado)"; FROM tagente_estado)";
} }
break; break;
case 'module': case 'module':
//Replace separator token "articapandora_32_pandoraartica_" for " " //Replace separator token "articapandora_32_pandoraartica_" for " "
@ -392,21 +380,18 @@ if (is_ajax ())
'AR', 'AR',
false, false,
true); true);
$sql .= sprintf('AND id_agente IN ( $sql .= sprintf('AND id_agente IN (
SELECT id_agente SELECT id_agente
FROM tagente_modulo FROM tagente_modulo
WHERE nombre = \'%s\' AND disabled = 0 WHERE nombre = \'%s\' AND disabled = 0
) )
', $name); ', $name);
break; break;
} }
$sql .= ' AND tagente.disabled = 0'. $search_sql; $sql .= ' AND tagente.disabled = 0'. $search_sql;
$countRows = db_get_num_rows($sql); $countRows = db_get_num_rows($sql);
} }
if ($countRows === 0) { if ($countRows === 0) {
echo "<ul style='margin: 0; padding: 0;'>\n"; echo "<ul style='margin: 0; padding: 0;'>\n";
@ -800,9 +785,7 @@ if (is_ajax ())
break; break;
} }
return; return;
} }
@ -827,9 +810,13 @@ function printTree_($type) {
$avariableGroups = users_get_groups (); //db_get_all_rows_in_table('tgrupo', 'nombre'); $avariableGroups = users_get_groups (); //db_get_all_rows_in_table('tgrupo', 'nombre');
//Get all groups with agents //Get all groups with agents
$full_groups = db_get_all_rows_sql("SELECT DISTINCT tagente.id_grupo FROM tagente, tagente_estado WHERE $full_groups = db_get_all_rows_sql("SELECT DISTINCT tagente.id_grupo
tagente.id_agente = tagente_estado.id_agente AND tagente_estado.utimestamp != 0 FROM tagente, tagente_estado
UNION SELECT tagente.id_grupo FROM tagente WHERE tagente.id_agente = tagente_estado.id_agente AND
tagente_estado.utimestamp != 0
UNION
SELECT tagente.id_grupo
FROM tagente
WHERE disabled = 0 WHERE disabled = 0
AND id_agente NOT IN (SELECT tagente.id_agente AND id_agente NOT IN (SELECT tagente.id_agente
FROM tagente, tagente_modulo FROM tagente, tagente_modulo
@ -870,9 +857,7 @@ function printTree_($type) {
} }
break; break;
case WARNING: case WARNING:
foreach ($avariableGroups as $group_name) { foreach ($avariableGroups as $group_name) {
$id_group = db_get_value_sql('SELECT id_grupo FROM tgrupo where nombre ="' . $group_name . '"'); $id_group = db_get_value_sql('SELECT id_grupo FROM tgrupo where nombre ="' . $group_name . '"');
@ -882,9 +867,7 @@ function printTree_($type) {
unset($avariableGroups[$id_group]); unset($avariableGroups[$id_group]);
} }
break; break;
case CRITICAL: case CRITICAL:
foreach ($avariableGroups as $group_name) { foreach ($avariableGroups as $group_name) {
$id_group = db_get_value_sql('SELECT id_grupo FROM tgrupo where nombre ="' . $group_name . '"'); $id_group = db_get_value_sql('SELECT id_grupo FROM tgrupo where nombre ="' . $group_name . '"');
@ -894,9 +877,7 @@ function printTree_($type) {
unset($avariableGroups[$id_group]); unset($avariableGroups[$id_group]);
} }
break; break;
case UNKNOWN: case UNKNOWN:
foreach ($avariableGroups as $group_name) { foreach ($avariableGroups as $group_name) {
$id_group = db_get_value_sql('SELECT id_grupo FROM tgrupo where nombre ="' . $group_name . '"'); $id_group = db_get_value_sql('SELECT id_grupo FROM tgrupo where nombre ="' . $group_name . '"');
@ -906,7 +887,6 @@ function printTree_($type) {
unset($avariableGroups[$id_group]); unset($avariableGroups[$id_group]);
} }
break; break;
} }
// If there are not groups display error and return // If there are not groups display error and return
@ -921,7 +901,8 @@ function printTree_($type) {
if ($search_free != '') { if ($search_free != '') {
$sql_search = " AND id_grupo IN (SELECT id_grupo FROM tagente $sql_search = " AND id_grupo IN (SELECT id_grupo FROM tagente
WHERE nombre COLLATE utf8_general_ci LIKE '%$search_free%')"; WHERE nombre COLLATE utf8_general_ci LIKE '%$search_free%')";
} else { }
else {
$sql_search =''; $sql_search ='';
} }
@ -929,7 +910,6 @@ function printTree_($type) {
switch ($type) { switch ($type) {
default: default:
case 'os': case 'os':
//Skip agent with all modules in not init status //Skip agent with all modules in not init status
$sql_search .= " AND id_agente NOT IN (SELECT tagente_estado.id_agente FROM $sql_search .= " AND id_agente NOT IN (SELECT tagente_estado.id_agente FROM
@ -951,7 +931,6 @@ function printTree_($type) {
$list = db_get_all_rows_sql($sql_os); $list = db_get_all_rows_sql($sql_os);
break; break;
case 'group': case 'group':
$stringAvariableGroups = ( $stringAvariableGroups = (
implode(', ', implode(', ',
@ -971,11 +950,8 @@ function printTree_($type) {
break; break;
} }
break; break;
case 'module_group': case 'module_group':
//Skip agents which only have not init modules //Skip agents which only have not init modules
$sql_search .= " AND id_agente NOT IN (SELECT tagente_estado.id_agente FROM $sql_search .= " AND id_agente NOT IN (SELECT tagente_estado.id_agente FROM
tagente_estado GROUP BY id_agente HAVING SUM(utimestamp) = 0)"; tagente_estado GROUP BY id_agente HAVING SUM(utimestamp) = 0)";
@ -984,7 +960,6 @@ function printTree_($type) {
'disabled' => 0, 'disabled' => 0,
'status' => $select_status, 'status' => $select_status,
'search' => $sql_search), 'search' => $sql_search),
array ('id_agente'), array ('id_agente'),
'AR', 'AR',
false, false,
@ -1013,7 +988,6 @@ function printTree_($type) {
array_push($list, array('id_mg' => 0, 'name' => 'Not assigned')); array_push($list, array('id_mg' => 0, 'name' => 'Not assigned'));
break; break;
case 'policies': case 'policies':
$avariableGroups = users_get_groups (); $avariableGroups = users_get_groups ();
@ -1021,11 +995,21 @@ function printTree_($type) {
$groups = implode(',',$groups_id); $groups = implode(',',$groups_id);
if ($search_free != '') { if ($search_free != '') {
$sql = "SELECT DISTINCT tpolicies.id, tpolicies.name
$sql = "SELECT DISTINCT tpolicies.id, tpolicies.name FROM tpolicies, tpolicy_modules, tagente_estado, tagente, tagente_modulo WHERE FROM tpolicies, tpolicy_modules,
tagente.id_agente = tagente_estado.id_agente AND tagente_modulo.id_agente = tagente_estado.id_agente AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_estado, tagente, tagente_modulo
tagente_estado.utimestamp != 0 AND tagente_modulo.id_policy_module != 0 AND tpolicy_modules.id = tagente_modulo.id_policy_module AND tpolicies.id = tpolicy_modules.id_policy AND WHERE
tagente.id_grupo IN ($groups) AND tagente.nombre LIKE '%$search_free%' AND tagente.disabled = 0 AND tagente_modulo.disabled = 0"; tagente.id_agente = tagente_estado.id_agente AND
tagente_modulo.id_agente = tagente_estado.id_agente AND
tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND
tagente_estado.utimestamp != 0 AND
tagente_modulo.id_policy_module != 0 AND
tpolicy_modules.id = tagente_modulo.id_policy_module AND
tpolicies.id = tpolicy_modules.id_policy AND
tagente.id_grupo IN ($groups) AND
tagente.nombre LIKE '%$search_free%' AND
tagente.disabled = 0 AND
tagente_modulo.disabled = 0";
$list = db_get_all_rows_sql($sql); $list = db_get_all_rows_sql($sql);
@ -1084,12 +1068,23 @@ function printTree_($type) {
$list = array(); $list = array();
array_push($list, array('id' => 0, 'name' => 'No policy')); array_push($list, array('id' => 0, 'name' => 'No policy'));
} else { }
else {
$list = db_get_all_rows_sql("SELECT DISTINCT tpolicies.id, tpolicies.name FROM tpolicies, tpolicy_modules, tagente_estado, tagente, tagente_modulo WHERE $list = db_get_all_rows_sql("SELECT DISTINCT tpolicies.id,
tagente.id_agente = tagente_estado.id_agente AND tagente_modulo.id_agente = tagente_estado.id_agente AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tpolicies.name
tagente_estado.utimestamp != 0 AND tagente_modulo.id_policy_module != 0 AND tpolicy_modules.id = tagente_modulo.id_policy_module AND tpolicies.id = tpolicy_modules.id_policy AND FROM tpolicies, tpolicy_modules, tagente_estado,
tagente.id_grupo IN ($groups) AND tagente.disabled = 0 AND tagente_modulo.disabled = 0"); tagente, tagente_modulo
WHERE
tagente.id_agente = tagente_estado.id_agente AND
tagente_modulo.id_agente = tagente_estado.id_agente AND
tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND
tagente_estado.utimestamp != 0 AND
tagente_modulo.id_policy_module != 0 AND
tpolicy_modules.id = tagente_modulo.id_policy_module AND
tpolicies.id = tpolicy_modules.id_policy AND
tagente.id_grupo IN ($groups) AND
tagente.disabled = 0 AND
tagente_modulo.disabled = 0");
$element = 0; $element = 0;
switch ($select_status) { switch ($select_status) {
@ -1145,9 +1140,7 @@ function printTree_($type) {
array_push($list, array('id' => 0, 'name' => 'No policy')); array_push($list, array('id' => 0, 'name' => 'No policy'));
} }
break; break;
case 'module': case 'module':
$avariableGroupsIds = implode(',',array_keys($avariableGroups)); $avariableGroupsIds = implode(',',array_keys($avariableGroups));
if($avariableGroupsIds == ''){ if($avariableGroupsIds == ''){
$avariableGroupsIds == -1; $avariableGroupsIds == -1;
@ -1156,7 +1149,8 @@ function printTree_($type) {
if ($search_free != '') { if ($search_free != '') {
$sql_search = " AND t1.id_agente IN (SELECT id_agente FROM tagente $sql_search = " AND t1.id_agente IN (SELECT id_agente FROM tagente
WHERE nombre COLLATE utf8_general_ci LIKE '%$search_free%')"; WHERE nombre COLLATE utf8_general_ci LIKE '%$search_free%')";
} else { }
else {
$sql_search = ''; $sql_search = '';
} }
@ -1167,22 +1161,33 @@ function printTree_($type) {
case "mysql": case "mysql":
case "postgresql": case "postgresql":
$list = db_get_all_rows_sql('SELECT t1.nombre $list = db_get_all_rows_sql('SELECT t1.nombre
FROM tagente_modulo t1, tagente t2, tagente_estado t3 FROM tagente_modulo t1, tagente t2,
WHERE t1.id_agente = t2.id_agente AND t1.id_agente_modulo = t3.id_agente_modulo tagente_estado t3
AND t2.disabled = 0 AND t1.disabled = 0 WHERE t1.id_agente = t2.id_agente AND
AND t3.utimestamp !=0 AND t2.id_grupo in (' . $avariableGroupsIds . ')' .$sql_search.' t1.id_agente_modulo = t3.id_agente_modulo AND
t2.disabled = 0 AND t1.disabled = 0 AND
t3.utimestamp !=0 AND
t2.id_grupo in (' . $avariableGroupsIds . ')' .
$sql_search.'
GROUP BY t1.nombre ORDER BY t1.nombre'); GROUP BY t1.nombre ORDER BY t1.nombre');
break; break;
case "oracle": case "oracle":
$list = db_get_all_rows_sql('SELECT dbms_lob.substr(t1.nombre,4000,1) as nombre $list = db_get_all_rows_sql('
FROM tagente_modulo t1, tagente t2, tagente_estado t3 SELECT dbms_lob.substr(t1.nombre,4000,1) as nombre
WHERE t1.id_agente = t2.id_agente AND t2.id_grupo in (' . $avariableGroupsIds . ') AND t1.id_agente_modulo = t3.id_agente_modulo FROM tagente_modulo t1, tagente t2,
AND t2.disabled = 0 AND t1.disabled = 0 AND t3.utimestamp !=0 GROUP BY dbms_lob.substr(t1.nombre,4000,1) ORDER BY dbms_lob.substr(t1.nombre,4000,1) ASC'); tagente_estado t3
WHERE t1.id_agente = t2.id_agente AND
t2.id_grupo in (' . $avariableGroupsIds . ') AND
t1.id_agente_modulo = t3.id_agente_modulo AND
t2.disabled = 0 AND
t1.disabled = 0 AND
t3.utimestamp !=0
GROUP BY dbms_lob.substr(t1.nombre,4000,1)
ORDER BY dbms_lob.substr(t1.nombre,4000,1) ASC');
break; break;
} }
break; break;
} }
if ($list === false) { if ($list === false) {
@ -1279,14 +1284,10 @@ function printTree_($type) {
echo "</ul>\n"; echo "</ul>\n";
echo '</td>'; echo '</td>';
echo '<td style="width:38%" valign="top">'; echo '<td style="width:38%" valign="top">';
echo '<div id="cont">'; echo '<div id="cont">&nbsp;</div>';
echo '&nbsp;';
echo'</div>';
echo '</td></tr>'; echo '</td></tr>';
echo '</table>'; echo '</table>';
} }
} }
@ -1313,7 +1314,8 @@ $module_group_tab = array('text' => "<a href='index.php?sec=estado&sec2=operatio
if ($enterpriseEnable) { if ($enterpriseEnable) {
$policies_tab = array('text' => "<a href='index.php?sec=estado&sec2=operation/tree&refr=0&sort_by=policies'>" $policies_tab = array('text' => "<a href='index.php?sec=estado&sec2=operation/tree&refr=0&sort_by=policies'>"
. html_print_image ("images/policies.png", true, array ("title" => __('Policies'))) . "</a>", 'active' => $activeTab == "policies"); . html_print_image ("images/policies.png", true, array ("title" => __('Policies'))) . "</a>", 'active' => $activeTab == "policies");
} else { }
else {
$policies_tab = ''; $policies_tab = '';
} }
@ -1377,6 +1379,7 @@ printTree_($activeTab);
var status = $('#status').val(); var status = $('#status').val();
var search_free = $('#text-search_free').val(); var search_free = $('#text-search_free').val();
/** /**
* loadSubTree asincronous load ajax the agents or modules (pass type, id to search and binary structure of branch), * loadSubTree asincronous load ajax the agents or modules (pass type, id to search and binary structure of branch),
* change the [+] or [-] image (with same more or less div id) of tree and anime (for show or hide) * change the [+] or [-] image (with same more or less div id) of tree and anime (for show or hide)
@ -1513,4 +1516,3 @@ printTree_($activeTab);
loadSubTree(type, div_id, less_branchs, id_father); loadSubTree(type, div_id, less_branchs, id_father);
} }
</script> </script>