2014-07-30 Miguel de Dios <miguel.dedios@artica.es>

* godmode/servers/manage_recontask.php,
	godmode/servers/manage_recontask_form.php,
	include/functions_treeview.php, include/ajax/module.php,
	include/functions_reporting.php, include/db/postgresql.php,
	include/functions_servers.php, operation/agentes/estado_agente.php,
	operation/tree.php: tiny fixes for the improve
	the support of postgreSQL databases.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@10365 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2014-07-30 14:29:44 +00:00
parent 8e60ec9d58
commit 30c9e1a9ef
10 changed files with 282 additions and 98 deletions

View File

@ -1,3 +1,13 @@
2014-07-30 Miguel de Dios <miguel.dedios@artica.es>
* godmode/servers/manage_recontask.php,
godmode/servers/manage_recontask_form.php,
include/functions_treeview.php, include/ajax/module.php,
include/functions_reporting.php, include/db/postgresql.php,
include/functions_servers.php, operation/agentes/estado_agente.php,
operation/tree.php: tiny fixes for the improve
the support of postgreSQL databases.
2014-07-29 Miguel de Dios <miguel.dedios@artica.es> 2014-07-29 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_graph.php, include/functions_reporting.php, * include/functions_graph.php, include/functions_reporting.php,

View File

@ -204,6 +204,7 @@ if (isset($_GET["create"])) {
if (($id_recon_script == 'NULL') && preg_match("/[0-9]+.+[0-9]+.+[0-9]+.+[0-9]+\/+[0-9]/", $network)) if (($id_recon_script == 'NULL') && preg_match("/[0-9]+.+[0-9]+.+[0-9]+.+[0-9]+\/+[0-9]/", $network))
{ {
$result = db_process_sql_insert('trecon_task', $values); $result = db_process_sql_insert('trecon_task', $values);
$reason = __("Network provided is not correct"); $reason = __("Network provided is not correct");
} }
elseif ($id_recon_script != 'NULL') { elseif ($id_recon_script != 'NULL') {
@ -215,8 +216,9 @@ if (isset($_GET["create"])) {
$result = false; $result = false;
} }
} }
else else {
$result = false; $result = false;
}
if ($result !== false) { if ($result !== false) {
ui_print_success_message(__('Successfully created recon task')); ui_print_success_message(__('Successfully created recon task'));

View File

@ -23,6 +23,14 @@ include_once($config['homedir'] . "/include/functions_ui.php");
enterprise_include_once ('include/functions_metaconsole.php'); enterprise_include_once ('include/functions_metaconsole.php');
$get_plugin_macros = get_parameter('get_plugin_macros'); $get_plugin_macros = get_parameter('get_plugin_macros');
$search_modules = get_parameter('search_modules');
$get_module_detail = get_parameter ('get_module_detail', 0);
$get_module_autocomplete_input = (bool) get_parameter('get_module_autocomplete_input');
$add_module_relation = (bool) get_parameter('add_module_relation');
$remove_module_relation = (bool) get_parameter('remove_module_relation');
$change_module_relation_updates = (bool) get_parameter('change_module_relation_updates');
$get_id_tag = (bool) get_parameter('get_id_tag', 0);
if ($get_plugin_macros) { if ($get_plugin_macros) {
$id_plugin = get_parameter('id_plugin', 0); $id_plugin = get_parameter('id_plugin', 0);
@ -37,7 +45,7 @@ if ($get_plugin_macros) {
return; return;
} }
$search_modules = get_parameter('search_modules');
if ($search_modules) { if ($search_modules) {
$id_agents = json_decode(io_safe_output(get_parameter('id_agents'))); $id_agents = json_decode(io_safe_output(get_parameter('id_agents')));
$filter = get_parameter('q', '') . '%'; $filter = get_parameter('q', '') . '%';
@ -56,7 +64,6 @@ if ($search_modules) {
return; return;
} }
$get_module_detail = get_parameter ('get_module_detail', 0);
if ($get_module_detail) { if ($get_module_detail) {
@ -131,15 +138,16 @@ if ($get_module_detail) {
html_print_table($formtable); html_print_table($formtable);
$moduletype_name = modules_get_moduletype_name (modules_get_agentmodule_type ($module_id)); $moduletype_name = modules_get_moduletype_name(
modules_get_agentmodule_type($module_id));
$offset = (int) get_parameter("offset"); $offset = (int) get_parameter("offset");
$block_size = (int) $config["block_size"]; $block_size = (int) $config["block_size"];
$columns = array (); $columns = array ();
$datetime_from = strtotime ($date_from.' '.$time_from); $datetime_from = strtotime ($date_from . ' ' . $time_from);
$datetime_to = strtotime ($date_to.' '.$time_to); $datetime_to = strtotime ($date_to . ' ' . $time_to);
if ($moduletype_name == "log4x") { if ($moduletype_name == "log4x") {
$table->width = "100%"; $table->width = "100%";
@ -337,7 +345,7 @@ if ($get_module_detail) {
return; return;
} }
$get_module_autocomplete_input = (bool) get_parameter('get_module_autocomplete_input');
if ($get_module_autocomplete_input) { if ($get_module_autocomplete_input) {
$id_agent = (int) get_parameter("id_agent"); $id_agent = (int) get_parameter("id_agent");
@ -350,7 +358,7 @@ if ($get_module_autocomplete_input) {
return; return;
} }
$add_module_relation = (bool) get_parameter('add_module_relation');
if ($add_module_relation) { if ($add_module_relation) {
$result = false; $result = false;
$id_module_a = (int) get_parameter("id_module_a"); $id_module_a = (int) get_parameter("id_module_a");
@ -384,7 +392,7 @@ if ($add_module_relation) {
return; return;
} }
$remove_module_relation = (bool) get_parameter('remove_module_relation');
if ($remove_module_relation) { if ($remove_module_relation) {
$id_relation = (int) get_parameter("id_relation"); $id_relation = (int) get_parameter("id_relation");
if ($id_relation > 0) { if ($id_relation > 0) {
@ -395,23 +403,25 @@ if ($remove_module_relation) {
return; return;
} }
$change_module_relation_updates = (bool) get_parameter('change_module_relation_updates');
if ($change_module_relation_updates) { if ($change_module_relation_updates) {
$id_relation = (int) get_parameter("id_relation"); $id_relation = (int) get_parameter("id_relation");
if ($id_relation > 0) { if ($id_relation > 0) {
$result = (bool) modules_change_relation_lock($id_relation); $result = (bool) modules_change_relation_lock($id_relation);
} }
echo json_encode($result); echo json_encode($result);
return; return;
} }
$get_id_tag = (bool) get_parameter('get_id_tag', 0);
if ($get_id_tag) { if ($get_id_tag) {
$tag_name = get_parameter('tag_name'); $tag_name = get_parameter('tag_name');
if ($tag_name) { if ($tag_name) {
$tag_id = db_get_value('id_tag', 'ttag', 'name', $tag_name); $tag_id = db_get_value('id_tag', 'ttag', 'name', $tag_name);
} else { }
else {
$tag_id = 0; $tag_id = 0;
} }

View File

@ -332,6 +332,9 @@ function postgresql_db_process_sql_insert($table, $values) {
else if (is_float ($value) || is_double ($value)) { else if (is_float ($value) || is_double ($value)) {
$values_str .= sprintf("%f", $value); $values_str .= sprintf("%f", $value);
} }
elseif (is_string($value) && (strtoupper($value) === 'NULL')) {
$values_str .= "NULL";
}
else { else {
$values_str .= sprintf("'%s'", $value); $values_str .= sprintf("'%s'", $value);
} }
@ -346,6 +349,7 @@ function postgresql_db_process_sql_insert($table, $values) {
$query .= ' VALUES (' . $values_str . ')'; $query .= ' VALUES (' . $values_str . ')';
return db_process_sql($query, 'insert_id'); return db_process_sql($query, 'insert_id');
} }

View File

@ -961,7 +961,9 @@ function reporting_get_stats_servers($tiny = true) {
$tdata[0] = html_print_image('images/network.png', true, array('title' => __('Network modules'), 'width' => '25px')); $tdata[0] = html_print_image('images/network.png', true, array('title' => __('Network modules'), 'width' => '25px'));
$tdata[1] = '<span class="big_data">' . format_numeric($server_performance ["total_network_modules"]) . '</span>'; $tdata[1] = '<span class="big_data">' . format_numeric($server_performance ["total_network_modules"]) . '</span>';
$tdata[2] = '<span class="med_data">' . format_numeric($server_performance ["network_modules_rate"], 2) . '</span>'; $tdata[2] = '<span class="med_data">' .
format_numeric($server_performance ["network_modules_rate"], 2) .
'</span>';
$tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec </span>'; $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec </span>';
$table_srv->rowclass[] = ''; $table_srv->rowclass[] = '';

View File

@ -79,6 +79,8 @@ function servers_get_performance () {
$data["avg_interval_remote_modules"] = array(); $data["avg_interval_remote_modules"] = array();
$data["avg_interval_local_modules"] = 0; $data["avg_interval_local_modules"] = 0;
$data["local_modules_rate"] = 0; $data["local_modules_rate"] = 0;
$data["network_modules_rate"] = 0;
if ($config["realtimestats"] == 1) { if ($config["realtimestats"] == 1) {
$counts = db_get_all_rows_sql ("SELECT tagente_modulo.id_modulo, COUNT(tagente_modulo.id_agente_modulo) modules $counts = db_get_all_rows_sql ("SELECT tagente_modulo.id_modulo, COUNT(tagente_modulo.id_agente_modulo) modules

View File

@ -468,11 +468,19 @@ function treeview_printTree($type) {
echo '<table class="databox" style="width:98%">'; echo '<table class="databox" style="width:98%">';
echo '<tr><td style="width:50%" valign="top">'; echo '<tr><td style="width:50%" valign="top">';
if (! defined ('METACONSOLE')) { if (! defined ('METACONSOLE')) {
$list = treeview_getData ($type); $list = treeview_getData ($type);
} }
else { else {
$servers = db_get_all_rows_sql ("SELECT * FROM tmetaconsole_setup WHERE disabled = 0"); $servers = db_get_all_rows_sql ("
SELECT *
FROM tmetaconsole_setup
WHERE disabled = 0");
if ($servers === false) { if ($servers === false) {
$servers = array(); $servers = array();
} }
@ -502,6 +510,8 @@ function treeview_printTree($type) {
metaconsole_restore_db(); metaconsole_restore_db();
} }
if ($list === false) { if ($list === false) {
ui_print_error_message(__('There aren\'t agents in this agrupation')); ui_print_error_message(__('There aren\'t agents in this agrupation'));
echo '</td></tr>'; echo '</td></tr>';
@ -548,14 +558,20 @@ function treeview_printTree($type) {
echo $img . $item['_iconImg_'] ."&nbsp;" . __($item['_name_']) . ' ('; echo $img . $item['_iconImg_'] ."&nbsp;" . __($item['_name_']) . ' (';
$counts_info = array('total_count' => $item['_num_ok_'] + $item['_num_critical_'] + $item['_num_warning_'] + $item['_num_unknown_'], $counts_info = array(
'total_count' => $item['_num_ok_'] +
$item['_num_critical_'] +
$item['_num_warning_'] +
$item['_num_unknown_'],
'normal_count' => $item['_num_ok_'], 'normal_count' => $item['_num_ok_'],
'critical_count' => $item['_num_critical_'], 'critical_count' => $item['_num_critical_'],
'warning_count' => $item['_num_warning_'], 'warning_count' => $item['_num_warning_'],
'unknown_count' => $item['_num_unknown_']); 'unknown_count' => $item['_num_unknown_']);
reporting_tiny_stats($counts_info, false, $type); reporting_tiny_stats($counts_info, false, $type);
echo ') '. "</a>"; echo ') '. "</a>";
echo "<div hiddenDiv='1' loadDiv='0' style='margin: 0px; padding: 0px;' class='tree_view' id='tree_div_" . $type . "_" . $id . "'></div>"; echo "<div hiddenDiv='1' loadDiv='0' style='margin: 0px; padding: 0px;' class='tree_view' id='tree_div_" . $type . "_" . $id . "'></div>";
@ -581,7 +597,11 @@ function treeview_getData ($type) {
$avariableGroups = users_get_groups (); $avariableGroups = users_get_groups ();
//Get all groups with agents //Get all groups with agents
$full_groups = db_get_all_rows_sql("SELECT DISTINCT id_grupo FROM tagente WHERE total_count > 0"); $full_groups = db_get_all_rows_sql("
SELECT DISTINCT id_grupo
FROM tagente
WHERE total_count > 0");
if ($full_groups === false) { if ($full_groups === false) {
return array (); return array ();
} }
@ -607,7 +627,10 @@ function treeview_getData ($type) {
switch ($select_status) { switch ($select_status) {
case NORMAL: case NORMAL:
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 . '"');
$num_ok = groups_agent_ok($id_group); $num_ok = groups_agent_ok($id_group);
@ -619,7 +642,10 @@ function treeview_getData ($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 . '"');
$num_warning = groups_agent_warning($id_group); $num_warning = groups_agent_warning($id_group);
@ -629,7 +655,10 @@ function treeview_getData ($type) {
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 . '"');
$num_critical = groups_agent_critical($id_group); $num_critical = groups_agent_critical($id_group);
@ -639,7 +668,10 @@ function treeview_getData ($type) {
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 . '"');
$num_unknown = groups_agent_unknown($id_group); $num_unknown = groups_agent_unknown($id_group);
@ -656,17 +688,42 @@ function treeview_getData ($type) {
} }
if ($search_free != '') { if ($search_free != '') {
$sql_search = " AND id_grupo IN (SELECT id_grupo FROM tagente switch ($config['dbtype']) {
case "mysql":
$sql_search = " AND id_grupo IN (
SELECT id_grupo
FROM tagente
WHERE tagente.nombre COLLATE utf8_general_ci LIKE '%$search_free%')"; WHERE tagente.nombre COLLATE utf8_general_ci LIKE '%$search_free%')";
break;
case "postgresql":
$sql_search = " AND id_grupo IN (
SELECT id_grupo
FROM tagente
WHERE tagente.nombre LIKE '%$search_free%')";
break;
case "oracle":
$sql_search = " AND id_grupo IN (
SELECT id_grupo
FROM tagente
WHERE tagente.nombre COLLATE utf8_general_ci LIKE '%$search_free%')";
break;
}
} }
else { else {
$sql_search =''; $sql_search ='';
} }
$order_collate = "";
switch ($config['dbtype']) {
case "mysql":
$order_collate = "COLLATE utf8_general_ci";
break;
}
switch ($type) { switch ($type) {
case 'os': case 'os':
$sql = agents_get_agents(array ( $sql = agents_get_agents(array (
'order' => 'nombre COLLATE utf8_general_ci ASC', 'order' => 'nombre ' . $order_collate . ' ASC',
'disabled' => 0, 'disabled' => 0,
'status' => $select_status, 'status' => $select_status,
'search' => $sql_search), 'search' => $sql_search),
@ -676,7 +733,9 @@ function treeview_getData ($type) {
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);
@ -692,17 +751,31 @@ function treeview_getData ($type) {
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
$list = db_get_all_rows_sql("
SELECT *
FROM tgrupo
WHERE nombre IN (" . $stringAvariableGroups . ") $sql_search
ORDER BY nombre COLLATE utf8_general_ci ASC");
break;
case "postgresql": case "postgresql":
$list = db_get_all_rows_sql("SELECT * FROM tgrupo WHERE nombre IN (" . $stringAvariableGroups . ") $sql_search ORDER BY nombre COLLATE utf8_general_ci ASC"); $list = db_get_all_rows_sql("
SELECT *
FROM tgrupo
WHERE nombre IN (" . $stringAvariableGroups . ") $sql_search
ORDER BY nombre ASC");
break; break;
case "oracle": case "oracle":
$list = db_get_all_rows_sql("SELECT * FROM tgrupo WHERE dbms_lob.substr(nombre,4000,1) IN (" . $stringAvariableGroups . ") ORDER BY nombre COLLATE utf8_general_ci ASC"); $list = db_get_all_rows_sql("
SELECT *
FROM tgrupo
WHERE dbms_lob.substr(nombre,4000,1) IN (" . $stringAvariableGroups . ")
ORDER BY nombre COLLATE utf8_general_ci ASC");
break; break;
} }
break; break;
case 'module_group': case 'module_group':
$sql = agents_get_agents(array ( $sql = agents_get_agents(array (
'order' => 'nombre COLLATE utf8_general_ci ASC', 'order' => 'nombre ' . $order_collate . ' ASC',
'disabled' => 0, 'disabled' => 0,
'status' => $select_status, 'status' => $select_status,
'search' => $sql_search), 'search' => $sql_search),
@ -714,8 +787,13 @@ function treeview_getData ($type) {
// Skip agents without modules // Skip agents without modules
$sql .= ' AND tagente.total_count>0'; $sql .= ' AND tagente.total_count>0';
$sql_module_groups = sprintf("SELECT * FROM tmodule_group $sql_module_groups = sprintf("
WHERE id_mg IN (SELECT id_module_group FROM tagente_modulo WHERE id_agente IN (%s))", $sql); SELECT *
FROM tmodule_group
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);
@ -734,7 +812,8 @@ function treeview_getData ($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, FROM tpolicies, tpolicy_modules,
tagente_estado, tagente, tagente_modulo tagente_estado, tagente, tagente_modulo
WHERE WHERE
@ -825,7 +904,7 @@ function treeview_getData ($type) {
tagente.id_grupo IN ($groups) AND tagente.id_grupo IN ($groups) AND
tagente.disabled = 0 AND tagente.disabled = 0 AND
tagente_modulo.disabled = 0 tagente_modulo.disabled = 0
ORDER BY tpolicies.name COLLATE utf8_general_ci ASC"); ORDER BY tpolicies.name ' . $order_collate . ' ASC");
$element = 0; $element = 0;
switch ($select_status) { switch ($select_status) {
@ -889,8 +968,28 @@ function treeview_getData ($type) {
} }
if ($search_free != '') { if ($search_free != '') {
$sql_search = " AND t1.id_agente IN (SELECT id_agente FROM tagente switch ($config['dbtype']) {
case "mysql":
$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%')";
break;
case "postgresql":
$sql_search = " AND t1.id_agente IN (
SELECT id_agente
FROM tagente
WHERE nombre LIKE '%$search_free%')";
break;
case "oracle":
$sql_search = " AND t1.id_agente IN (
SELECT id_agente
FROM tagente
WHERE nombre COLLATE utf8_general_ci LIKE '%$search_free%')";
break;
}
} }
else { else {
$sql_search = ''; $sql_search = '';
@ -899,7 +998,8 @@ function treeview_getData ($type) {
if ($select_status != -1) if ($select_status != -1)
$sql_search .= " AND estado = " . $select_status . " "; $sql_search .= " AND estado = " . $select_status . " ";
$sql_search .= tags_get_acl_tags($config['id_user'], 0, 'AR', 'module_condition', 'AND', 't1'); $sql_search .= tags_get_acl_tags(
$config['id_user'], 0, 'AR', 'module_condition', 'AND', 't1');
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
@ -950,15 +1050,16 @@ function treeview_getData ($type) {
$search_sql = sprintf(" AND tagente.nombre COLLATE utf8_general_ci LIKE '%%%s%%'", $search_free); $search_sql = sprintf(" AND tagente.nombre COLLATE utf8_general_ci LIKE '%%%s%%'", $search_free);
} }
$sql = "SELECT DISTINCT ttag.name $sql = "
SELECT DISTINCT ttag.name
FROM ttag, ttag_module, tagente, tagente_modulo FROM ttag, ttag_module, tagente, tagente_modulo
WHERE ttag.id_tag = ttag_module.id_tag WHERE ttag.id_tag = ttag_module.id_tag
AND tagente.id_agente = tagente_modulo.id_agente AND tagente.id_agente = tagente_modulo.id_agente
AND tagente.disabled = 0 AND tagente.disabled = 0
AND ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo" . AND ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo" .
$search_sql . $search_sql .
$user_tags_sql . $user_tags_sql . "
" ORDER BY ttag.name COLLATE utf8_general_ci ASC"; ORDER BY ttag.name ' . $order_collate . ' ASC";
$list = db_get_all_rows_sql($sql); $list = db_get_all_rows_sql($sql);
break; break;
@ -1054,6 +1155,13 @@ function treeview_getFirstBranchSQL ($type, $id, $avariableGroupsIds, $statusSel
return false; return false;
} }
$order_collate = "";
switch ($config['dbtype']) {
case "mysql":
$order_collate = "COLLATE utf8_general_ci";
break;
}
//TODO CHANGE POLICY ACL FOR TAG ACL //TODO CHANGE POLICY ACL FOR TAG ACL
$extra_sql = ''; $extra_sql = '';
if ($extra_sql != '') { if ($extra_sql != '') {
@ -1062,7 +1170,18 @@ function treeview_getFirstBranchSQL ($type, $id, $avariableGroupsIds, $statusSel
$groups_sql = implode(', ', $avariableGroupsIds); $groups_sql = implode(', ', $avariableGroupsIds);
if ($search_free != '') { if ($search_free != '') {
switch ($config['dbtype']) {
case "mysql":
$search_sql = " AND tagente.nombre COLLATE utf8_general_ci LIKE '%$search_free%'"; $search_sql = " AND tagente.nombre COLLATE utf8_general_ci LIKE '%$search_free%'";
break;
case "postgresql":
$search_sql = " AND tagente.nombre LIKE '%$search_free%'";
break;
case "oracle":
$search_sql = " AND tagente.nombre COLLATE utf8_general_ci LIKE '%$search_free%'";
break;
}
} }
else { else {
$search_sql = ''; $search_sql = '';
@ -1085,7 +1204,7 @@ function treeview_getFirstBranchSQL ($type, $id, $avariableGroupsIds, $statusSel
'search' => $search_sql), 'search' => $search_sql),
array ('*'), array ('*'),
'AR', 'AR',
array('field' => 'nombre COLLATE utf8_general_ci', 'order' => ' ASC'), array('field' => 'nombre ' . $order_collate, 'order' => ' ASC'),
true); true);
break; break;
case 'os': case 'os':
@ -1097,7 +1216,7 @@ function treeview_getFirstBranchSQL ($type, $id, $avariableGroupsIds, $statusSel
'search' => $search_sql), 'search' => $search_sql),
array ('*'), array ('*'),
'AR', 'AR',
array('field' => 'nombre COLLATE utf8_general_ci', 'order' => ' ASC'), array('field' => 'nombre ' . $order_collate, 'order' => ' ASC'),
true); true);
break; break;
case 'module_group': case 'module_group':
@ -1117,7 +1236,7 @@ function treeview_getFirstBranchSQL ($type, $id, $avariableGroupsIds, $statusSel
FROM tagente_modulo FROM tagente_modulo
WHERE id_module_group = ' . $id . ')'; WHERE id_module_group = ' . $id . ')';
$sql .= 'ORDER BY nombre COLLATE utf8_general_ci ASC'; $sql .= 'ORDER BY nombre ' . $order_collate . ' ASC';
break; break;
case 'policies': case 'policies':
@ -1144,7 +1263,7 @@ function treeview_getFirstBranchSQL ($type, $id, $avariableGroupsIds, $statusSel
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) {
@ -1152,11 +1271,12 @@ function treeview_getFirstBranchSQL ($type, $id, $avariableGroupsIds, $statusSel
// 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)";
} }
$sql .= 'ORDER BY nombre COLLATE utf8_general_ci ASC'; $sql .= 'ORDER BY nombre ' . $order_collate . ' ASC';
break; break;
case 'module': case 'module':
@ -1188,7 +1308,7 @@ function treeview_getFirstBranchSQL ($type, $id, $avariableGroupsIds, $statusSel
) )
', $name); ', $name);
$sql .= 'ORDER BY nombre COLLATE utf8_general_ci ASC'; $sql .= 'ORDER BY nombre ' . $order_collate . ' ASC';
break; break;
case 'tag': case 'tag':
@ -1219,7 +1339,8 @@ function treeview_getFirstBranchSQL ($type, $id, $avariableGroupsIds, $statusSel
$sql .= ' AND tagente.disabled = 0'. $search_sql; $sql .= ' AND tagente.disabled = 0'. $search_sql;
$sql .= ' GROUP BY tagente.id_agente ORDER BY tagente.nombre COLLATE utf8_general_ci ASC'; $sql .= ' GROUP BY tagente.id_agente
ORDER BY tagente.nombre ' . $order_collate . ' ASC';
break; break;
} }
@ -1234,25 +1355,36 @@ function treeview_getFirstBranchSQL ($type, $id, $avariableGroupsIds, $statusSel
// Get SQL for the second tree branch // Get SQL for the second tree branch
function treeview_getSecondBranchSQL ($fatherType, $id, $id_father) { function treeview_getSecondBranchSQL ($fatherType, $id, $id_father) {
global $config; global $config;
$order_collate = "";
switch ($config['dbtype']) {
case "mysql":
$order_collate = "COLLATE utf8_general_ci";
break;
}
switch ($fatherType) { switch ($fatherType) {
case 'group': case 'group':
$sql = 'SELECT * $sql = 'SELECT *
FROM tagente_modulo AS t1 FROM tagente_modulo AS t1
INNER JOIN tagente_estado AS t2 ON t1.id_agente_modulo = t2.id_agente_modulo INNER JOIN tagente_estado AS t2
ON t1.id_agente_modulo = t2.id_agente_modulo
WHERE t1.id_agente = ' . $id; WHERE t1.id_agente = ' . $id;
$sql .= tags_get_acl_tags($config['id_user'], 0, 'AR', 'module_condition', 'AND', 't1'); $sql .= tags_get_acl_tags($config['id_user'], 0, 'AR', 'module_condition', 'AND', 't1');
break; break;
case 'os': case 'os':
$sql = 'SELECT * $sql = 'SELECT *
FROM tagente_modulo AS t1 FROM tagente_modulo AS t1
INNER JOIN tagente_estado AS t2 ON t1.id_agente_modulo = t2.id_agente_modulo INNER JOIN tagente_estado AS t2
ON t1.id_agente_modulo = t2.id_agente_modulo
WHERE t1.id_agente = ' . $id; WHERE t1.id_agente = ' . $id;
$sql .= tags_get_acl_tags($config['id_user'], 0, 'AR', 'module_condition', 'AND', 't1'); $sql .= tags_get_acl_tags($config['id_user'], 0, 'AR', 'module_condition', 'AND', 't1');
break; break;
case 'module_group': case 'module_group':
$sql = 'SELECT * $sql = 'SELECT *
FROM tagente_modulo AS t1 FROM tagente_modulo AS t1
INNER JOIN tagente_estado AS t2 ON t1.id_agente_modulo = t2.id_agente_modulo INNER JOIN tagente_estado AS t2
ON t1.id_agente_modulo = t2.id_agente_modulo
WHERE t1.id_agente = ' . $id . ' AND id_module_group = ' . $id_father; WHERE t1.id_agente = ' . $id . ' AND id_module_group = ' . $id_father;
$sql .= tags_get_acl_tags($config['id_user'], 0, 'AR', 'module_condition', 'AND', 't1'); $sql .= tags_get_acl_tags($config['id_user'], 0, 'AR', 'module_condition', 'AND', 't1');
break; break;
@ -1275,7 +1407,9 @@ function treeview_getSecondBranchSQL ($fatherType, $id, $id_father) {
$symbols = ' !"#$%&\'()*+,./:;<=>?@[\\]^{|}~'; $symbols = ' !"#$%&\'()*+,./:;<=>?@[\\]^{|}~';
$name = $id_father; $name = $id_father;
for ($i = 0; $i < strlen($symbols); $i++) { for ($i = 0; $i < strlen($symbols); $i++) {
$name = str_replace('_articapandora_'.ord(substr($symbols, $i, 1)).'_pandoraartica_', substr($symbols, $i, 1), $name); $name = str_replace('_articapandora_' .
ord(substr($symbols, $i, 1)) .'_pandoraartica_',
substr($symbols, $i, 1), $name);
} }
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
@ -1316,7 +1450,8 @@ function treeview_getSecondBranchSQL ($fatherType, $id, $id_father) {
} }
// This line checks for initializated modules or (non-initialized) asyncronous modules // This line checks for initializated modules or (non-initialized) asyncronous modules
$sql .= ' AND disabled = 0 AND (utimestamp > 0 OR id_tipo_modulo IN (21,22,23)) ORDER BY nombre COLLATE utf8_general_ci ASC'; $sql .= ' AND disabled = 0 AND (utimestamp > 0 OR id_tipo_modulo IN (21,22,23))
ORDER BY nombre ' . $order_collate . ' ASC';
return $sql; return $sql;
} }
?> ?>

View File

@ -227,7 +227,7 @@ $order = null;
$order_collation = ""; $order_collation = "";
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
$order_collation = " COLLATE utf8_general_ci"; $order_collation = "COLLATE utf8_general_ci";
break; break;
case "postgresql": case "postgresql":
case "oracle": case "oracle":

View File

@ -139,7 +139,8 @@ if (is_ajax ())
} }
$avariableGroups = users_get_groups(); $avariableGroups = users_get_groups();
$avariableGroupsIds = array_keys($avariableGroups); $avariableGroupsIds = array_keys($avariableGroups);
$sql = treeview_getFirstBranchSQL ($type, $id, $avariableGroupsIds, $statusSel, $search_free); $sql = treeview_getFirstBranchSQL ($type, $id,
$avariableGroupsIds, $statusSel, $search_free);
if ($sql === false) { if ($sql === false) {
$server_rows = array (); $server_rows = array ();
} }
@ -525,10 +526,16 @@ else {
} }
$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");
$tags_tab = array('text' => "<a href='index.php?&sec=monitoring&sec2=operation/tree&refr=0&sort_by=tag&pure=$pure'>" $tags_tab = array('text' => "<a href='index.php?&sec=monitoring&sec2=operation/tree&refr=0&sort_by=tag&pure=$pure'>"
. html_print_image ("images/tag.png", true, array ("title" => __('Tags'))) . "</a>", 'active' => $activeTab == "tag"); . html_print_image("images/tag.png",
true,
array("title" => __('Tags'))) . "</a>",
'active' => $activeTab == "tag");
switch ($activeTab) { switch ($activeTab) {
case 'group': case 'group':
@ -553,7 +560,10 @@ switch ($activeTab) {
if (! defined ('METACONSOLE')) { if (! defined ('METACONSOLE')) {
$onheader = array('tag' => $tags_tab, 'os' => $os_tab, 'group' => $group_tab, 'module_group' => $module_group_tab, 'policies' => $policies_tab, 'module' => $module_tab); $onheader = array('tag' => $tags_tab, 'os' => $os_tab, 'group' => $group_tab, 'module_group' => $module_group_tab, 'policies' => $policies_tab, 'module' => $module_tab);
ui_print_page_header (__('Tree view')." - ".__('Sort the agents by ') .$order, "images/extensions.png", false, "", false, $onheader); ui_print_page_header(
__('Tree view') . " - " . __('Sort the agents by ') . $order,
"images/extensions.png",
false, "", false, $onheader);
} }
else { else {
@ -584,9 +594,11 @@ else {
$subsections['group'] = $group_tab; $subsections['group'] = $group_tab;
if($config['enable_tags_tree']) { if ($config['enable_tags_tree']) {
$tags_tab = array('text' => "<a href='index.php?&sec=monitoring&sec2=operation/tree&refr=0&tab=tag&pure=$pure'>" $tags_tab = array(
. html_print_image ("images/tag.png", true, array ("title" => __('Tags'))) . "</a>", 'active' => $activeTab == "tag"); 'text' => "<a href='index.php?&sec=monitoring&sec2=operation/tree&refr=0&tab=tag&pure=$pure'>" .
html_print_image ("images/tag.png", true, array ("title" => __('Tags'))) . "</a>",
'active' => $activeTab == "tag");
$subsections['tag'] = $tags_tab; $subsections['tag'] = $tags_tab;
} }
@ -649,6 +661,7 @@ ui_require_javascript_file('pandora_modules');
treeview_printTree($activeTab); treeview_printTree($activeTab);
enterprise_hook('close_meta_frame'); enterprise_hook('close_meta_frame');
ui_include_time_picker(); ui_include_time_picker();
@ -672,9 +685,13 @@ ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascri
* id_father int use in js and ajax php, its useful when you have a two subtrees with same agent for diferent each one * 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, server_name) { function loadSubTree(type, div_id, less_branchs, id_father, server_name) {
hiddenDiv = $('#tree_div'+id_father+'_'+type+'_'+div_id).attr('hiddenDiv'); hiddenDiv = $('#tree_div' + id_father + '_' + type + '_' + div_id)
loadDiv = $('#tree_div'+id_father+'_'+type+'_'+div_id).attr('loadDiv'); .attr('hiddenDiv');
pos = parseInt($('#tree_image'+id_father+'_'+type+'_'+div_id).attr('pos_tree')); 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 has yet ajax request running
if (loadDiv == 2) if (loadDiv == 2)
@ -683,8 +700,10 @@ ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascri
if (loadDiv == 0) { if (loadDiv == 0) {
//Put an spinner to simulate loading process //Put an spinner to simulate loading process
$('#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)
$('#tree_div'+id_father+'_'+type+'_'+div_id).show('normal'); .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); $('#tree_div'+id_father+'_'+type+'_'+div_id).attr('loadDiv', 2);
$.ajax({ $.ajax({