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 ed1c79730c
commit 08cf7253f8
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 = '';
} }
@ -261,152 +261,137 @@ if (is_ajax ())
//Skip agents which only have not init modules //Skip agents which only have not init modules
$search_sql .= " AND id_agente NOT IN (SELECT tagente_estado.id_agente FROM $search_sql .= " 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)";
$sql = agents_get_agents(array ( $sql = agents_get_agents(array (
'order' => 'nombre COLLATE utf8_general_ci ASC', 'order' => 'nombre COLLATE utf8_general_ci ASC',
'id_grupo' => $id, 'id_grupo' => $id,
'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':
//Skip agents which only have not init modules //Skip agents which only have not init modules
$search_sql .= " AND id_agente NOT IN (SELECT tagente_estado.id_agente FROM $search_sql .= " 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)";
$sql = agents_get_agents(array ( $sql = agents_get_agents(array (
'order' => 'nombre COLLATE utf8_general_ci ASC', 'order' => 'nombre COLLATE utf8_general_ci ASC',
'id_os' => $id, 'id_os' => $id,
'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':
//Skip agents which only have not init modules //Skip agents which only have not init modules
$search_sql .= " AND id_agente NOT IN (SELECT tagente_estado.id_agente FROM tagente_estado $search_sql .= " AND id_agente NOT IN (SELECT tagente_estado.id_agente FROM tagente_estado
WHERE id_agente_modulo IN WHERE id_agente_modulo IN
(SELECT id_agente_modulo FROM tagente_modulo (SELECT id_agente_modulo FROM tagente_modulo
WHERE id_module_group = $id) WHERE id_module_group = $id)
GROUP BY id_agente HAVING SUM(utimestamp) = 0)"; GROUP BY id_agente HAVING SUM(utimestamp) = 0)";
$sql = agents_get_agents(array ( $sql = agents_get_agents(array (
'order' => 'nombre COLLATE utf8_general_ci ASC', 'order' => 'nombre COLLATE utf8_general_ci ASC',
'disabled' => 0, 'disabled' => 0,
'status' => $statusSel, 'status' => $statusSel,
'search' => $search_sql), 'search' => $search_sql),
array ('*'),
array ('*'), 'AR',
'AR', false,
false, true);
true);
// Skip agents without modules // Skip agents without modules
$sql .= ' AND id_agente IN $sql .= ' AND id_agente IN
(SELECT tagente.id_agente (SELECT tagente.id_agente
FROM tagente, tagente_modulo FROM tagente, tagente_modulo
WHERE tagente.id_agente = tagente_modulo.id_agente WHERE tagente.id_agente = tagente_modulo.id_agente
AND id_module_group = ' . $id . ' AND tagente.disabled = 0 AND id_module_group = ' . $id . ' AND tagente.disabled = 0
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':
$sql = agents_get_agents(array ( $sql = agents_get_agents(array (
'order' => 'nombre COLLATE utf8_general_ci ASC', 'order' => 'nombre COLLATE utf8_general_ci ASC',
'disabled' => 0, 'disabled' => 0,
'search' => $search_sql), 'search' => $search_sql),
array ('*'), array ('*'),
'AR', 'AR',
false, false,
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
FROM tagente, tagente_modulo, tagente_estado, tpolicy_modules FROM tagente, tagente_modulo, tagente_estado, tpolicy_modules
WHERE tagente.id_agente = tagente_modulo.id_agente WHERE tagente.id_agente = tagente_modulo.id_agente
AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND tagente_modulo.id_policy_module = tpolicy_modules.id AND tagente_modulo.id_policy_module = tpolicy_modules.id
AND tagente.disabled = 0 AND tagente.disabled = 0
AND tagente_modulo.disabled = 0 AND tagente_modulo.disabled = 0
AND tagente_estado.utimestamp != 0 AND tagente_estado.utimestamp != 0
AND tagente_modulo.id_policy_module != 0 AND tagente_modulo.id_policy_module != 0
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) {
// If status filter is NORMAL add void agents // If status filter is NORMAL add void agents
$sql .= " UNION SELECT * FROM tagente $sql .= " UNION SELECT * FROM tagente
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 " "
//example: //example:
// "Load_articapandora_32_pandoraartica_Average" // "Load_articapandora_32_pandoraartica_Average"
//result -> "Load Average" // result -> "Load Average"
$name = str_replace(array('_articapandora_'.ord(' ').'_pandoraartica_', '_articapandora_'.ord('#').'_pandoraartica_','_articapandora_'.ord('/').'_pandoraartica_'),array(' ','#','/'),$id); $name = str_replace(array('_articapandora_'.ord(' ').'_pandoraartica_', '_articapandora_'.ord('#').'_pandoraartica_','_articapandora_'.ord('/').'_pandoraartica_'),array(' ','#','/'),$id);
$name = io_safe_input($name); $name = io_safe_input($name);
$sql = agents_get_agents(array ( $sql = agents_get_agents(array (
'order' => 'nombre COLLATE utf8_general_ci ASC', 'order' => 'nombre COLLATE utf8_general_ci ASC',
'disabled' => 0, 'disabled' => 0,
'status' => $statusSel, 'status' => $statusSel,
'search' => $search_sql), 'search' => $search_sql),
array ('*'),
'AR',
false,
true);
array ('*'),
'AR',
false,
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";
@ -441,8 +426,8 @@ if (is_ajax ())
$agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]); $agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]);
$agent_info["status_img"] = agetns_tree_view_status_img ($agent_info["monitor_critical"], $agent_info["status_img"] = agetns_tree_view_status_img ($agent_info["monitor_critical"],
$agent_info["monitor_warning"], $agent_info["monitor_warning"],
$agent_info["monitor_unknown"]); $agent_info["monitor_unknown"]);
//Count all modules //Count all modules
$agent_info["modules"] = $agent_info["monitor_critical"] + $agent_info["monitor_warning"] + $agent_info["monitor_unknown"] + $agent_info["monitor_normal"]; $agent_info["modules"] = $agent_info["monitor_critical"] + $agent_info["monitor_warning"] + $agent_info["monitor_unknown"] + $agent_info["monitor_normal"];
@ -467,8 +452,8 @@ if (is_ajax ())
$agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]); $agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]);
$agent_info["status_img"] = agetns_tree_view_status_img ($agent_info["monitor_critical"], $agent_info["status_img"] = agetns_tree_view_status_img ($agent_info["monitor_critical"],
$agent_info["monitor_warning"], $agent_info["monitor_warning"],
$agent_info["monitor_unknown"]); $agent_info["monitor_unknown"]);
//Count all modules //Count all modules
$agent_info["modules"] = $agent_info["monitor_critical"] + $agent_info["monitor_warning"] + $agent_info["monitor_unknown"] + $agent_info["monitor_normal"]; $agent_info["modules"] = $agent_info["monitor_critical"] + $agent_info["monitor_warning"] + $agent_info["monitor_unknown"] + $agent_info["monitor_normal"];
@ -484,8 +469,8 @@ if (is_ajax ())
$agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]); $agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]);
$agent_info["status_img"] = agetns_tree_view_status_img ($agent_info["monitor_critical"], $agent_info["status_img"] = agetns_tree_view_status_img ($agent_info["monitor_critical"],
$agent_info["monitor_warning"], $agent_info["monitor_warning"],
$agent_info["monitor_unknown"]); $agent_info["monitor_unknown"]);
//Count all modules //Count all modules
$agent_info["modules"] = $agent_info["monitor_critical"] + $agent_info["monitor_warning"] + $agent_info["monitor_unknown"] + $agent_info["monitor_normal"]; $agent_info["modules"] = $agent_info["monitor_critical"] + $agent_info["monitor_warning"] + $agent_info["monitor_unknown"] + $agent_info["monitor_normal"];
@ -503,8 +488,8 @@ if (is_ajax ())
$agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]); $agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]);
$agent_info["status_img"] = agetns_tree_view_status_img ($agent_info["monitor_critical"], $agent_info["status_img"] = agetns_tree_view_status_img ($agent_info["monitor_critical"],
$agent_info["monitor_warning"], $agent_info["monitor_warning"],
$agent_info["monitor_unknown"]); $agent_info["monitor_unknown"]);
//Count all modules //Count all modules
$agent_info["modules"] = $agent_info["monitor_critical"] + $agent_info["monitor_warning"] + $agent_info["monitor_unknown"] + $agent_info["monitor_normal"]; $agent_info["modules"] = $agent_info["monitor_critical"] + $agent_info["monitor_warning"] + $agent_info["monitor_unknown"] + $agent_info["monitor_normal"];
@ -522,8 +507,8 @@ if (is_ajax ())
$agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]); $agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]);
$agent_info["status_img"] = agetns_tree_view_status_img ($agent_info["monitor_critical"], $agent_info["status_img"] = agetns_tree_view_status_img ($agent_info["monitor_critical"],
$agent_info["monitor_warning"], $agent_info["monitor_warning"],
$agent_info["monitor_unknown"]); $agent_info["monitor_unknown"]);
//Count all modules //Count all modules
$agent_info["modules"] = $agent_info["monitor_critical"] + $agent_info["monitor_warning"] + $agent_info["monitor_unknown"] + $agent_info["monitor_normal"]; $agent_info["modules"] = $agent_info["monitor_critical"] + $agent_info["monitor_warning"] + $agent_info["monitor_unknown"] + $agent_info["monitor_normal"];
@ -706,7 +691,7 @@ if (is_ajax ())
$new = true; $new = true;
$count = 0; $count = 0;
echo "<ul style='margin: 0; padding: 0;'>\n"; echo "<ul style='margin: 0; padding: 0;'>\n";
while($row = db_get_all_row_by_steps_sql($new, $result, $sql)) { while ($row = db_get_all_row_by_steps_sql($new, $result, $sql)) {
$new = false; $new = false;
$count++; $count++;
echo "<li style='margin: 0; padding: 0;'><span style='min-width: 300px; display: inline-block;'>"; echo "<li style='margin: 0; padding: 0;'><span style='min-width: 300px; display: inline-block;'>";
@ -800,9 +785,7 @@ if (is_ajax ())
break; break;
} }
return; return;
} }
@ -827,17 +810,21 @@ 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
WHERE disabled = 0 tagente_estado.utimestamp != 0
AND id_agente NOT IN (SELECT tagente.id_agente UNION
FROM tagente, tagente_modulo SELECT tagente.id_grupo
WHERE tagente.id_agente = tagente_modulo.id_agente FROM tagente
AND tagente.disabled = 0 WHERE disabled = 0
AND tagente_modulo.disabled = 0 AND id_agente NOT IN (SELECT tagente.id_agente
group by tagente.id_agente FROM tagente, tagente_modulo
having COUNT(*) > 0)"); WHERE tagente.id_agente = tagente_modulo.id_agente
AND tagente.disabled = 0
AND tagente_modulo.disabled = 0
group by tagente.id_agente
having COUNT(*) > 0)");
$fgroups = array(); $fgroups = array();
@ -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
@ -920,8 +900,9 @@ 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,29 +910,27 @@ 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
tagente_estado GROUP BY id_agente HAVING SUM(utimestamp) = 0)"; tagente_estado GROUP BY id_agente HAVING SUM(utimestamp) = 0)";
$sql = agents_get_agents(array ( $sql = agents_get_agents(array (
'order' => 'nombre COLLATE utf8_general_ci ASC', 'order' => 'nombre COLLATE utf8_general_ci ASC',
'disabled' => 0, 'disabled' => 0,
'status' => $select_status, 'status' => $select_status,
'search' => $sql_search), 'search' => $sql_search),
array ('tagente.id_os'), array ('tagente.id_os'),
'AR', 'AR',
false, false,
true); true);
$sql_os = sprintf("SELECT * FROM tconfig_os WHERE id_os IN (%s)", $sql); $sql_os = sprintf("SELECT * FROM tconfig_os WHERE id_os IN (%s)", $sql);
$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,37 +950,33 @@ 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)";
$sql = agents_get_agents(array ( $sql = agents_get_agents(array (
'order' => 'nombre COLLATE utf8_general_ci ASC', 'order' => 'nombre COLLATE utf8_general_ci ASC',
'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, true);
true);
// Skip agents without modules // Skip agents without modules
$sql .= ' AND id_agente IN $sql .= ' AND id_agente IN
(SELECT tagente.id_agente (SELECT tagente.id_agente
FROM tagente, tagente_modulo FROM tagente, tagente_modulo
WHERE tagente.id_agente = tagente_modulo.id_agente WHERE tagente.id_agente = tagente_modulo.id_agente
AND tagente.disabled = 0 AND tagente.disabled = 0
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)';
$sql_module_groups = sprintf("SELECT * FROM tmodule_group $sql_module_groups = sprintf("SELECT * FROM tmodule_group
WHERE id_mg IN (SELECT id_module_group FROM tagente_modulo WHERE id_agente IN (%s))", $sql); WHERE id_mg IN (SELECT id_module_group FROM tagente_modulo WHERE id_agente IN (%s))", $sql);
$list = db_get_all_rows_sql($sql_module_groups); $list = db_get_all_rows_sql($sql_module_groups);
@ -1010,10 +985,9 @@ function printTree_($type) {
$list = array(); $list = array();
} }
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,19 +1140,18 @@ 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;
} }
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 { }
$sql_search = ''; else {
$sql_search = '';
} }
if ($select_status != -1) if ($select_status != -1)
@ -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>';
} }
} }
@ -1302,23 +1303,24 @@ $img_style = array ("class" => "top", "width" => 16);
$activeTab = get_parameter('sort_by','group'); $activeTab = get_parameter('sort_by','group');
$os_tab = array('text' => "<a href='index.php?sec=estado&sec2=operation/tree&refr=0&sort_by=os'>" $os_tab = array('text' => "<a href='index.php?sec=estado&sec2=operation/tree&refr=0&sort_by=os'>"
. html_print_image ("images/computer.png", true, array ("title" => __('OS'))) . "</a>", 'active' => $activeTab == "os"); . html_print_image ("images/computer.png", true, array ("title" => __('OS'))) . "</a>", 'active' => $activeTab == "os");
$group_tab = array('text' => "<a href='index.php?sec=estado&sec2=operation/tree&refr=0&sort_by=group'>" $group_tab = array('text' => "<a href='index.php?sec=estado&sec2=operation/tree&refr=0&sort_by=group'>"
. html_print_image ("images/group.png", true, array ("title" => __('Groups'))) . "</a>", 'active' => $activeTab == "group"); . html_print_image ("images/group.png", true, array ("title" => __('Groups'))) . "</a>", 'active' => $activeTab == "group");
$module_group_tab = array('text' => "<a href='index.php?sec=estado&sec2=operation/tree&refr=0&sort_by=module_group'>" $module_group_tab = array('text' => "<a href='index.php?sec=estado&sec2=operation/tree&refr=0&sort_by=module_group'>"
. html_print_image ("images/agents_group.png", true, array ("title" => __('Module groups'))) . "</a>", 'active' => $activeTab == "module_group"); . html_print_image ("images/agents_group.png", true, array ("title" => __('Module groups'))) . "</a>", 'active' => $activeTab == "module_group");
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 = '';
} }
$module_tab = array('text' => "<a href='index.php?extension_in_menu=estado&sec=estado&sec2=operation/tree&refr=0&sort_by=module'>" $module_tab = array('text' => "<a href='index.php?extension_in_menu=estado&sec=estado&sec2=operation/tree&refr=0&sort_by=module'>"
. html_print_image ("images/brick.png", true, array ("title" => __('Modules'))) . "</a>", 'active' => $activeTab == "module"); . html_print_image ("images/brick.png", true, array ("title" => __('Modules'))) . "</a>", 'active' => $activeTab == "module");
$onheader = array('os' => $os_tab, 'group' => $group_tab, 'module_group' => $module_group_tab, 'policies' => $policies_tab, 'module' => $module_tab); $onheader = array('os' => $os_tab, 'group' => $group_tab, 'module_group' => $module_group_tab, 'policies' => $policies_tab, 'module' => $module_tab);
@ -1377,140 +1379,140 @@ 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),
* change the [+] or [-] image (with same more or less div id) of tree and anime (for show or hide)
* the div with id "div[id_father]_[type]_[div_id]"
*
* type string use in js and ajax php
* div_id int use in js and ajax php
* less_branchs int use in ajax php as binary structure 0b00, 0b01, 0b10 and 0b11
* id_father int use in js and ajax php, its useful when you have a two subtrees with same agent for diferent each one
*/
function loadSubTree(type, div_id, less_branchs, id_father) {
hiddenDiv = $('#tree_div'+id_father+'_'+type+'_'+div_id).attr('hiddenDiv');
loadDiv = $('#tree_div'+id_father+'_'+type+'_'+div_id).attr('loadDiv');
pos = parseInt($('#tree_image'+id_father+'_'+type+'_'+div_id).attr('pos_tree'));
//If has yet ajax request running /**
if (loadDiv == 2) * loadSubTree asincronous load ajax the agents or modules (pass type, id to search and binary structure of branch),
return; * change the [+] or [-] image (with same more or less div id) of tree and anime (for show or hide)
* the div with id "div[id_father]_[type]_[div_id]"
*
* type string use in js and ajax php
* div_id int use in js and ajax php
* less_branchs int use in ajax php as binary structure 0b00, 0b01, 0b10 and 0b11
* id_father int use in js and ajax php, its useful when you have a two subtrees with same agent for diferent each one
*/
function loadSubTree(type, div_id, less_branchs, id_father) {
hiddenDiv = $('#tree_div'+id_father+'_'+type+'_'+div_id).attr('hiddenDiv');
loadDiv = $('#tree_div'+id_father+'_'+type+'_'+div_id).attr('loadDiv');
pos = parseInt($('#tree_image'+id_father+'_'+type+'_'+div_id).attr('pos_tree'));
if (loadDiv == 0) { //If has yet ajax request running
if (loadDiv == 2)
return;
//Put an spinner to simulate loading process if (loadDiv == 0) {
$('#tree_div'+id_father+'_'+type+'_'+div_id).html("<img style='padding-top:10px;padding-bottom:10px;padding-left:20px;' src=images/spinner.gif>");
$('#tree_div'+id_father+'_'+type+'_'+div_id).show('normal');
$('#tree_div'+id_father+'_'+type+'_'+div_id).attr('loadDiv', 2); //Put an spinner to simulate loading process
$.ajax({ $('#tree_div'+id_father+'_'+type+'_'+div_id).html("<img style='padding-top:10px;padding-bottom:10px;padding-left:20px;' src=images/spinner.gif>");
type: "POST", $('#tree_div'+id_father+'_'+type+'_'+div_id).show('normal');
url: "ajax.php",
data: "page=<?php echo $_GET['sec2']; ?>&ajax_treeview=1&type=" +
type + "&id=" + div_id + "&less_branchs=" + less_branchs + "&id_father=" + id_father + "&status=" + status + "&search_free=" + search_free,
success: function(msg){
if (msg.length != 0) {
$('#tree_div'+id_father+'_'+type+'_'+div_id).hide();
$('#tree_div'+id_father+'_'+type+'_'+div_id).html(msg);
$('#tree_div'+id_father+'_'+type+'_'+div_id).show('normal');
//change image of tree [+] to [-] $('#tree_div'+id_father+'_'+type+'_'+div_id).attr('loadDiv', 2);
switch (pos) {
case 0:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/first_expanded.png');
break;
case 1:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/one_expanded.png');
break;
case 2:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/expanded.png');
break;
case 3:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/last_expanded.png');
break;
}
$('#tree_div'+id_father+'_'+type+'_'+div_id).attr('hiddendiv',0);
$('#tree_div'+id_father+'_'+type+'_'+div_id).attr('loadDiv', 1);
}
}
});
}
else {
if (hiddenDiv == 0) {
$('#tree_div'+id_father+'_'+type+'_'+div_id).hide('normal');
$('#tree_div'+id_father+'_'+type+'_'+div_id).attr('hiddenDiv',1);
//change image of tree [-] to [+]
switch (pos) {
case 0:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/first_closed.png');
break;
case 1:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/one_closed.png');
break;
case 2:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/closed.png');
break;
case 3:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/last_closed.png');
break;
}
}
else {
//change image of tree [+] to [-]
switch (pos) {
case 0:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/first_expanded.png');
break;
case 1:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/one_expanded.png');
break;
case 2:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/expanded.png');
break;
case 3:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/last_expanded.png');
break;
}
$('#tree_div'+id_father+'_'+type+'_'+div_id).show('normal');
$('#tree_div'+id_father+'_'+type+'_'+div_id).attr('hiddenDiv',0);
}
}
}
function changeStatus(newStatus) {
status = newStatus;
//reset all subtree
$(".tree_view").each(
function(i) {
$(this).attr('loadDiv', 0);
$(this).attr('hiddenDiv',1);
$(this).hide();
}
);
//clean all subtree
$(".tree_view").each(
function(i) {
$(this).html('');
}
);
}
function loadTable(type, div_id, less_branchs, id_father) {
id_agent = div_id;
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "ajax.php", url: "ajax.php",
data: "page=<?php echo $_GET['sec2']; ?>&printTable=1&id_agente=" + data: "page=<?php echo $_GET['sec2']; ?>&ajax_treeview=1&type=" +
id_agent, success: function(data){ type + "&id=" + div_id + "&less_branchs=" + less_branchs + "&id_father=" + id_father + "&status=" + status + "&search_free=" + search_free,
$('#cont').html(data); success: function(msg){
if (msg.length != 0) {
$('#tree_div'+id_father+'_'+type+'_'+div_id).hide();
$('#tree_div'+id_father+'_'+type+'_'+div_id).html(msg);
$('#tree_div'+id_father+'_'+type+'_'+div_id).show('normal');
//change image of tree [+] to [-]
switch (pos) {
case 0:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/first_expanded.png');
break;
case 1:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/one_expanded.png');
break;
case 2:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/expanded.png');
break;
case 3:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/last_expanded.png');
break;
}
$('#tree_div'+id_father+'_'+type+'_'+div_id).attr('hiddendiv',0);
$('#tree_div'+id_father+'_'+type+'_'+div_id).attr('loadDiv', 1);
}
} }
}); });
}
else {
if (hiddenDiv == 0) {
$('#tree_div'+id_father+'_'+type+'_'+div_id).hide('normal');
$('#tree_div'+id_father+'_'+type+'_'+div_id).attr('hiddenDiv',1);
loadSubTree(type, div_id, less_branchs, id_father); //change image of tree [-] to [+]
switch (pos) {
case 0:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/first_closed.png');
break;
case 1:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/one_closed.png');
break;
case 2:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/closed.png');
break;
case 3:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/last_closed.png');
break;
}
}
else {
//change image of tree [+] to [-]
switch (pos) {
case 0:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/first_expanded.png');
break;
case 1:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/one_expanded.png');
break;
case 2:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/expanded.png');
break;
case 3:
$('#tree_image'+id_father+'_'+type+'_'+div_id).attr('src','operation/tree/last_expanded.png');
break;
}
$('#tree_div'+id_father+'_'+type+'_'+div_id).show('normal');
$('#tree_div'+id_father+'_'+type+'_'+div_id).attr('hiddenDiv',0);
}
}
}
function changeStatus(newStatus) {
status = newStatus;
//reset all subtree
$(".tree_view").each(
function(i) {
$(this).attr('loadDiv', 0);
$(this).attr('hiddenDiv',1);
$(this).hide();
}
);
//clean all subtree
$(".tree_view").each(
function(i) {
$(this).html('');
}
);
}
function loadTable(type, div_id, less_branchs, id_father) {
id_agent = div_id;
$.ajax({
type: "POST",
url: "ajax.php",
data: "page=<?php echo $_GET['sec2']; ?>&printTable=1&id_agente=" +
id_agent, success: function(data){
$('#cont').html(data);
}
});
loadSubTree(type, div_id, less_branchs, id_father);
} }
</script> </script>