2012-04-26 Miguel de Dios <miguel.dedios@artica.es>

* include/functions_db.php, operation/agentes/exportdata.php:
	cleaned source code style.
	
	* include/functions_api.php: fixed prevent the empty string in the
	status into the search events.
	
	MERGED FROM 4.0.2




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6182 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2012-04-26 10:03:53 +00:00
parent 933282e041
commit b2dbe16678
4 changed files with 52 additions and 41 deletions

View File

@ -1,3 +1,13 @@
2012-04-26 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_db.php, operation/agentes/exportdata.php:
cleaned source code style.
* include/functions_api.php: fixed prevent the empty string in the
status into the search events.
MERGED FROM 4.0.2
2012-04-26 Vanessa Gil <vanessa.gil@artica.es> 2012-04-26 Vanessa Gil <vanessa.gil@artica.es>
* godmode/reporting/reporting_builder.list_items.php: Added sort column. * godmode/reporting/reporting_builder.list_items.php: Added sort column.

View File

@ -176,7 +176,7 @@ function isInACL($ip) {
return false; return false;
} }
//-------------------------DEFINED OPERATIONS FUNCTIONS------------------------- //-------------------------DEFINED OPERATIONS FUNCTIONS-----------------
function get_groups($thrash1, $thrash2, $other, $returnType, $user_in_db) { function get_groups($thrash1, $thrash2, $other, $returnType, $user_in_db) {
if ($other['type'] == 'string') { if ($other['type'] == 'string') {
if ($other['data'] != '') { if ($other['data'] != '') {
@ -3687,25 +3687,25 @@ function set_update_user($id, $thrash2, $other, $thrash3) {
*/ */
function set_enable_disable_user ($id, $thrash2, $other, $thrash3) { function set_enable_disable_user ($id, $thrash2, $other, $thrash3) {
if ($id == ""){ if ($id == ""){
returnError('error_enable_disable_user', 'Error enable/disable user. Id_user cannot be left blank.'); returnError('error_enable_disable_user', 'Error enable/disable user. Id_user cannot be left blank.');
return; return;
} }
if ($other['data'][0] != "0" and $other['data'][0] != "1"){ if ($other['data'][0] != "0" and $other['data'][0] != "1"){
returnError('error_enable_disable_user', 'Error enable/disable user. Enable/disable value cannot be left blank.'); returnError('error_enable_disable_user', 'Error enable/disable user. Enable/disable value cannot be left blank.');
return; return;
} }
if (users_get_user_by_id($id) == false){ if (users_get_user_by_id($id) == false){
returnError('error_enable_disable_user', 'Error enable/disable user. The user doesn\'t exists.'); returnError('error_enable_disable_user', 'Error enable/disable user. The user doesn\'t exists.');
return; return;
} }
$result = users_disable($id, $other['data'][0]); $result = users_disable($id, $other['data'][0]);
if (is_error($result)) { if (is_error($result)) {
// TODO: Improve the error returning more info // TODO: Improve the error returning more info
returnError('error_create_network_module', __('Error in user enabling/disabling.')); returnError('error_create_network_module', __('Error in user enabling/disabling.'));
@ -3723,7 +3723,7 @@ function set_enable_disable_user ($id, $thrash2, $other, $thrash3) {
function otherParameter2Filter($other, $array = false) { function otherParameter2Filter($other, $array = false) {
$filter = array(); $filter = array();
if (($other['data'][1] != null) && ($other['data'][1] != -1) && ($other['data'][1] != '')) { if (($other['data'][1] != null) && ($other['data'][1] != -1) && ($other['data'][1] != '')) {
$filter['criticity'] = $other['data'][1]; $filter['criticity'] = $other['data'][1];
} }
@ -3790,7 +3790,11 @@ function otherParameter2Filter($other, $array = false) {
$filter['estado'] = $other['data'][8]; $filter['estado'] = $other['data'][8];
} }
else { else {
$filterString .= ' AND estado = ' . $other[8]; $estado = (int)$other[8];
if ($estado >= 0) {
$filterString .= ' AND estado = ' . $estado;
}
} }
} }
@ -4504,7 +4508,8 @@ function get_events__with_user($trash1, $trash2, $other, $returnType, $user_in_d
$sql_post .= " AND event_type LIKE '%$event_type%' "; $sql_post .= " AND event_type LIKE '%$event_type%' ";
} }
elseif ($event_type == "not_normal") { elseif ($event_type == "not_normal") {
$sql_post .= " AND event_type LIKE '%warning%' OR event_type LIKE '%critical%' OR event_type LIKE '%unknown%' "; $sql_post .= " AND event_type LIKE '%warning%'
OR event_type LIKE '%critical%' OR event_type LIKE '%unknown%' ";
} }
else { else {
$sql_post .= " AND event_type = '".$event_type."'"; $sql_post .= " AND event_type = '".$event_type."'";
@ -4564,10 +4569,8 @@ function get_events__with_user($trash1, $trash2, $other, $returnType, $user_in_d
(SELECT t1.nombre FROM tagente AS t1 WHERE t1.id_agente = tevento.id_agente) AS agent_name, (SELECT t1.nombre FROM tagente AS t1 WHERE t1.id_agente = tevento.id_agente) AS agent_name,
(SELECT t2.nombre FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_name, (SELECT t2.nombre FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_name,
(SELECT t2.icon FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_icon (SELECT t2.icon FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_icon
FROM tevento" . FROM tevento
//FOR THE TEST THE API IN THE ANDROID WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC LIMIT ".$offset.",".$pagination;
// " WHERE 1=1 ".$sql_post." ORDER BY id_evento ASC LIMIT ".$offset.",".$pagination;
" WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC LIMIT ".$offset.",".$pagination;
} }
break; break;
case "postgresql": case "postgresql":
@ -4599,7 +4602,7 @@ function get_events__with_user($trash1, $trash2, $other, $returnType, $user_in_d
case "mysql": case "mysql":
db_process_sql ('SET group_concat_max_len = 9999999'); db_process_sql ('SET group_concat_max_len = 9999999');
$sql = "SELECT *, MAX(id_evento) AS id_evento, GROUP_CONCAT(DISTINCT user_comment SEPARATOR '') AS user_comment, $sql = "SELECT *, MAX(id_evento) AS id_evento, GROUP_CONCAT(DISTINCT user_comment SEPARATOR '') AS user_comment,
MIN(estado) AS min_estado, MAX(estado) AS max_estado, COUNT(*) AS event_rep, MAX(utimestamp) AS timestamp_rep MIN(estado) AS min_estado, MAX(estado) AS max_estado, COUNT(*) AS event_rep, MAX(utimestamp) AS timestamp_rep
FROM tevento FROM tevento
WHERE 1=1 ".$sql_post." WHERE 1=1 ".$sql_post."
GROUP BY evento, id_agentmodule GROUP BY evento, id_agentmodule
@ -4607,7 +4610,7 @@ function get_events__with_user($trash1, $trash2, $other, $returnType, $user_in_d
break; break;
case "postgresql": case "postgresql":
$sql = "SELECT *, MAX(id_evento) AS id_evento, array_to_string(array_agg(DISTINCT user_comment), '') AS user_comment, $sql = "SELECT *, MAX(id_evento) AS id_evento, array_to_string(array_agg(DISTINCT user_comment), '') AS user_comment,
MIN(estado) AS min_estado, MAX(estado) AS max_estado, COUNT(*) AS event_rep, MAX(utimestamp) AS timestamp_rep MIN(estado) AS min_estado, MAX(estado) AS max_estado, COUNT(*) AS event_rep, MAX(utimestamp) AS timestamp_rep
FROM tevento FROM tevento
WHERE 1=1 ".$sql_post." WHERE 1=1 ".$sql_post."
GROUP BY evento, id_agentmodule GROUP BY evento, id_agentmodule

View File

@ -24,7 +24,7 @@ include_once($config['homedir'] . "/include/functions_groups.php");
include_once($config['homedir'] . "/include/functions_agents.php"); include_once($config['homedir'] . "/include/functions_agents.php");
include_once($config['homedir'] . "/include/functions_modules.php"); include_once($config['homedir'] . "/include/functions_modules.php");
include_once($config['homedir'] . "/include/functions_alerts.php"); include_once($config['homedir'] . "/include/functions_alerts.php");
include_once($config['homedir'] . '/include/functions_users.php'); include_once($config['homedir'] . "/include/functions_users.php");
function db_select_engine() { function db_select_engine() {
global $config; global $config;
@ -44,7 +44,7 @@ function db_select_engine() {
function db_connect($host = null, $db = null, $user = null, $pass = null, $history = null, $port = null) { function db_connect($host = null, $db = null, $user = null, $pass = null, $history = null, $port = null) {
global $config; global $config;
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
return mysql_connect_db($host, $db, $user, $pass, $history, $port); return mysql_connect_db($host, $db, $user, $pass, $history, $port);
@ -74,7 +74,7 @@ function db_connect($host = null, $db = null, $user = null, $pass = null, $histo
*/ */
function db_escape_string_sql($string) { function db_escape_string_sql($string) {
global $config; global $config;
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
return mysql_escape_string_sql($string); return mysql_escape_string_sql($string);
@ -101,11 +101,10 @@ function db_escape_string_sql($string) {
*/ */
function db_pandora_audit($accion, $descripcion, $user_id = false, $ip = false, $info = '') { function db_pandora_audit($accion, $descripcion, $user_id = false, $ip = false, $info = '') {
global $config; global $config;
if ($ip !== false) { if ($ip !== false) {
if (isset($config["remote_addr"])) { if (isset($config["remote_addr"])) {
$ip = $config["remote_addr"]; $ip = $config["remote_addr"];
} }
else { else {
if ($_SERVER['REMOTE_ADDR']) { if ($_SERVER['REMOTE_ADDR']) {
@ -116,7 +115,7 @@ function db_pandora_audit($accion, $descripcion, $user_id = false, $ip = false,
} }
} }
} }
if ($user_id !== false) { if ($user_id !== false) {
$id = $user_id; $id = $user_id;
} }
@ -126,10 +125,10 @@ function db_pandora_audit($accion, $descripcion, $user_id = false, $ip = false,
} }
else $id = 0; else $id = 0;
} }
$accion = io_safe_input($accion); $accion = io_safe_input($accion);
$descripcion = io_safe_input($descripcion); $descripcion = io_safe_input($descripcion);
switch ($config['dbtype']){ switch ($config['dbtype']){
case "mysql": case "mysql":
case "postgresql": case "postgresql":
@ -145,15 +144,16 @@ function db_pandora_audit($accion, $descripcion, $user_id = false, $ip = false,
'accion' => $accion, 'accion' => $accion,
'ip_origen' => $ip, 'ip_origen' => $ip,
'descripcion' => $descripcion, 'descripcion' => $descripcion,
'fecha' => '#to_date(\'' . date('Y-m-d H:i:s') . '\',\'YYYY-MM-DD HH24:MI:SS\')', 'fecha' => '#to_date(\'' . date('Y-m-d H:i:s') .
'\',\'YYYY-MM-DD HH24:MI:SS\')',
'utimestamp' => time()); 'utimestamp' => time());
break; break;
} }
$id_audit = db_process_sql_insert('tsesion', $values); $id_audit = db_process_sql_insert('tsesion', $values);
enterprise_include_once('include/functions_audit.php'); enterprise_include_once('include/functions_audit.php');
enterprise_hook('audit_pandora_enterprise', array($id_audit, $info)); enterprise_hook('audit_pandora_enterprise', array($id_audit, $info));
return $id_audit; return $id_audit;
} }
@ -167,7 +167,7 @@ function db_pandora_audit($accion, $descripcion, $user_id = false, $ip = false,
*/ */
function db_logon ($id_user, $ip) { function db_logon ($id_user, $ip) {
db_pandora_audit("Logon", "Logged in", $id_user, $ip); db_pandora_audit("Logon", "Logged in", $id_user, $ip);
// Update last registry of user to set last logon. How do we audit when the user was created then? // Update last registry of user to set last logon. How do we audit when the user was created then?
process_user_contact ($id_user); process_user_contact ($id_user);
} }
@ -196,7 +196,7 @@ $sql_cache = array ('saved' => 0);
*/ */
function db_get_value($field, $table, $field_search = 1, $condition = 1, $search_history_db = false) { function db_get_value($field, $table, $field_search = 1, $condition = 1, $search_history_db = false) {
global $config; global $config;
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
return mysql_db_get_value($field, $table, $field_search, $condition, $search_history_db); return mysql_db_get_value($field, $table, $field_search, $condition, $search_history_db);
@ -237,7 +237,7 @@ function db_get_value($field, $table, $field_search = 1, $condition = 1, $search
*/ */
function db_get_value_filter ($field, $table, $filter, $where_join = 'AND') { function db_get_value_filter ($field, $table, $filter, $where_join = 'AND') {
global $config; global $config;
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
return mysql_db_get_value_filter($field, $table, $filter, $where_join); return mysql_db_get_value_filter($field, $table, $filter, $where_join);
@ -261,7 +261,7 @@ function db_get_value_filter ($field, $table, $filter, $where_join = 'AND') {
*/ */
function db_get_value_sql($sql) { function db_get_value_sql($sql) {
global $config; global $config;
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
return mysql_db_get_value_sql($sql); return mysql_db_get_value_sql($sql);
@ -284,7 +284,7 @@ function db_get_value_sql($sql) {
*/ */
function db_get_row_sql($sql, $search_history_db = false) { function db_get_row_sql($sql, $search_history_db = false) {
global $config; global $config;
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
return mysql_db_get_row_sql($sql, $search_history_db); return mysql_db_get_row_sql($sql, $search_history_db);
@ -314,7 +314,7 @@ function db_get_row_sql($sql, $search_history_db = false) {
*/ */
function db_get_row ($table, $field_search, $condition, $fields = false) { function db_get_row ($table, $field_search, $condition, $fields = false) {
global $config; global $config;
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
return mysql_db_get_row($table, $field_search, $condition, $fields); return mysql_db_get_row($table, $field_search, $condition, $fields);
@ -354,7 +354,7 @@ function db_get_row ($table, $field_search, $condition, $fields = false) {
*/ */
function db_get_row_filter($table, $filter, $fields = false, $where_join = 'AND') { function db_get_row_filter($table, $filter, $fields = false, $where_join = 'AND') {
global $config; global $config;
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
return mysql_db_get_row_filter($table, $filter, $fields, $where_join); return mysql_db_get_row_filter($table, $filter, $fields, $where_join);
@ -379,10 +379,10 @@ function db_get_row_filter($table, $filter, $fields = false, $where_join = 'AND'
function db_get_sql ($sql, $field = 0, $search_history_db = false) { function db_get_sql ($sql, $field = 0, $search_history_db = false) {
$result = db_get_all_rows_sql ($sql, $search_history_db); $result = db_get_all_rows_sql ($sql, $search_history_db);
if($result === false) if($result === false)
return false; return false;
$ax = 0; $ax = 0;
foreach ($result[0] as $f){ foreach ($result[0] as $f){
if ($field == $ax) if ($field == $ax)
@ -403,7 +403,7 @@ function db_get_sql ($sql, $field = 0, $search_history_db = false) {
*/ */
function db_get_all_rows_sql($sql, $search_history_db = false, $cache = true) { function db_get_all_rows_sql($sql, $search_history_db = false, $cache = true) {
global $config; global $config;
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
return mysql_db_get_all_rows_sql($sql, $search_history_db, $cache); return mysql_db_get_all_rows_sql($sql, $search_history_db, $cache);

View File

@ -212,7 +212,6 @@ if (!empty ($export_btn) && !empty ($module)) {
switch ($export_type) { switch ($export_type) {
case "data": case "data":
case "avg": case "avg":
// Show header // Show header
echo $datastart; echo $datastart;
@ -287,7 +286,7 @@ elseif (!empty ($export_btn) && empty ($module)) {
if (empty($export_btn)) { if (empty($export_btn)) {
echo '<form method="post" action="index.php?sec=reporting&amp;sec2=operation/agentes/exportdata" name="export_form">'; echo '<form method="post" action="index.php?sec=reporting&amp;sec2=operation/agentes/exportdata" name="export_form">';
$table->width = '98%'; $table->width = '98%';
$table->border = 0; $table->border = 0;
$table->cellspacing = 3; $table->cellspacing = 3;
@ -315,7 +314,6 @@ if (empty($export_btn)) {
$agents = array (); $agents = array ();
$rows = agents_get_agents ($filter, false, 'AR'); $rows = agents_get_agents ($filter, false, 'AR');
if ($rows == null) $rows = array(); if ($rows == null) $rows = array();
foreach ($rows as $row) { foreach ($rows as $row) {
$agents[$row['id_agente']] = $row['nombre']; $agents[$row['id_agente']] = $row['nombre'];