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

* general/logon_ok.php, godmode/db/db_event.php,
	godmode/db/db_purge.php, include/functions_config.php,
	include/functions_ui.php, include/functions_netflow.php,
	include/functions.php, include/constants.php,
	include/functions_graph.php,
	operation/agentes/estado_ultimopaquete.php: clean source code style
	and kill some unicorns and magical numbers.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6788 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2012-07-18 13:25:51 +00:00
parent 469abc72fe
commit 5da06e0448
11 changed files with 789 additions and 754 deletions

View File

@ -1,3 +1,13 @@
2012-07-18 Miguel de Dios <miguel.dedios@artica.es>
* general/logon_ok.php, godmode/db/db_event.php,
godmode/db/db_purge.php, include/functions_config.php,
include/functions_ui.php, include/functions_netflow.php,
include/functions.php, include/constants.php,
include/functions_graph.php,
operation/agentes/estado_ultimopaquete.php: clean source code style
and kill some unicorns and magical numbers.
2012-07-18 Miguel de Dios <miguel.dedios@artica.es> 2012-07-18 Miguel de Dios <miguel.dedios@artica.es>
* include/javascript/pandora.js, include/functions_agents.php, * include/javascript/pandora.js, include/functions_agents.php,

View File

@ -180,19 +180,19 @@ switch ($config["dbtype"]) {
case "mysql": case "mysql":
$sql = sprintf ("SELECT id_usuario,accion,fecha,ip_origen,descripcion $sql = sprintf ("SELECT id_usuario,accion,fecha,ip_origen,descripcion
FROM tsesion FROM tsesion
WHERE (`utimestamp` > UNIX_TIMESTAMP(NOW()) - 604800) WHERE (`utimestamp` > UNIX_TIMESTAMP(NOW()) - " . SECONDS_1WEEK . ")
AND `id_usuario` = '%s' ORDER BY `utimestamp` DESC LIMIT 10", $config["id_user"]); AND `id_usuario` = '%s' ORDER BY `utimestamp` DESC LIMIT 10", $config["id_user"]);
break; break;
case "postgresql": case "postgresql":
$sql = sprintf ("SELECT \"id_usuario\", accion, fecha, \"ip_origen\", descripcion $sql = sprintf ("SELECT \"id_usuario\", accion, fecha, \"ip_origen\", descripcion
FROM tsesion FROM tsesion
WHERE (\"utimestamp\" > ceil(date_part('epoch', CURRENT_TIMESTAMP)) - 604800) WHERE (\"utimestamp\" > ceil(date_part('epoch', CURRENT_TIMESTAMP)) - " . SECONDS_1WEEK . ")
AND \"id_usuario\" = '%s' ORDER BY \"utimestamp\" DESC LIMIT 10", $config["id_user"]); AND \"id_usuario\" = '%s' ORDER BY \"utimestamp\" DESC LIMIT 10", $config["id_user"]);
break; break;
case "oracle": case "oracle":
$sql = sprintf ("SELECT id_usuario, accion, fecha, ip_origen, descripcion $sql = sprintf ("SELECT id_usuario, accion, fecha, ip_origen, descripcion
FROM tsesion FROM tsesion
WHERE ((utimestamp > ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) - 604800) WHERE ((utimestamp > ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (" . SECONDS_1DAY . ")) - " . SECONDS_1WEEK . ")
AND id_usuario = '%s') AND rownum <= 10 ORDER BY utimestamp DESC", $config["id_user"]); AND id_usuario = '%s') AND rownum <= 10 ORDER BY utimestamp DESC", $config["id_user"]);
break; break;
} }
@ -230,4 +230,4 @@ echo "<div style='width:100%; overflow-x:auto;'>";
html_print_table ($table); html_print_table ($table);
echo "</div>"; echo "</div>";
echo "</div>"; // activity echo "</div>"; // activity
?> ?>

View File

@ -71,12 +71,12 @@ echo '<table width="98%" cellpadding="4" cellspacing="4" class="databox">
$time = get_system_time (); $time = get_system_time ();
$fields = array (); $fields = array ();
$fields[$time - 7776000] = __('Purge event data over 90 days'); $fields[$time - SECONDS_3MONTHS] = __('Purge event data over 90 days');
$fields[$time - 2592000] = __('Purge event data over 30 days'); $fields[$time - SECONDS_1MONTH] = __('Purge event data over 30 days');
$fields[$time - 1209600] = __('Purge event data over 14 days'); $fields[$time - SECONDS_2WEEK] = __('Purge event data over 14 days');
$fields[$time - 604800] = __('Purge event data over 7 days'); $fields[$time - SECONDS_1WEEK] = __('Purge event data over 7 days');
$fields[$time - 259200] = __('Purge event data over 3 days'); $fields[$time - (SECONDS_1WEEK * 3)] = __('Purge event data over 3 days');
$fields[$time - 86400] = __('Purge event data over 1 day'); $fields[$time - SECONDS_1DAY] = __('Purge event data over 1 day');
$fields[$time] = __('Purge all event data'); $fields[$time] = __('Purge all event data');
html_print_select ($fields, "date_purge", '', '', '', '0', false, false, false, "w255"); html_print_select ($fields, "date_purge", '', '', '', '0', false, false, false, "w255");

View File

@ -43,25 +43,19 @@ echo '<h4>'.__('Get data from agent').'</h4>';
// All data (now) // All data (now)
$time["all"] = get_system_time (); $time["all"] = get_system_time ();
// 1 day ago // 1 day ago
$time["1day"] = $time["all"]-86400; $time["1day"] = $time["all"] - SECONDS_1DAY;
// 3 days ago // 3 days ago
$time["3day"] = $time["all"] - 259200; $time["3day"] = $time["all"] - SECONDS_1DAY * 3;
// 1 week ago // 1 week ago
$time["1week"] = $time["all"] - 604800; $time["1week"] = $time["all"] - SECONDS_1WEEK;
// 2 weeks ago // 2 weeks ago
$time["2week"] = $time["all"] - 1209600; $time["2week"] = $time["all"] - SECONDS_1WEEK * 2;
// 1 month ago // 1 month ago
$time["1month"] = $time["all"] - 2592000; $time["1month"] = $time["all"] - SECONDS_1MONTH;
// Three months ago // Three months ago
$time["3month"] = $time["all"] - 7776000; $time["3month"] = $time["all"] - SECONDS_3MONTHS;
//Init data //Init data
$data["1day"] = 0; $data["1day"] = 0;
$data["3day"] = 0; $data["3day"] = 0;
@ -102,7 +96,7 @@ if (isset($_POST["purgedb"])) {
$errors++; $errors++;
else else
$affected += $result; $affected += $result;
if ($errors == 0) { if ($errors == 0) {
$result = db_process_sql_delete('tagente_datos_inc', array('id_agente_modulo' => $row["id_agente_modulo"], 'utimestamp' => '< ' . $from_date)); $result = db_process_sql_delete('tagente_datos_inc', array('id_agente_modulo' => $row["id_agente_modulo"], 'utimestamp' => '< ' . $from_date));
@ -134,10 +128,11 @@ if (isset($_POST["purgedb"])) {
} }
else { else {
db_process_sql_commit (); db_process_sql_commit ();
echo __('Total records deleted: ') . $affected; echo __('Total records deleted: ') . $affected;
} }
} else { }
else {
//All agents //All agents
echo __('Deleting records for all agents'); echo __('Deleting records for all agents');
flush (); flush ();
@ -166,7 +161,8 @@ echo '</noscript><br />';
if ($id_agent > 0) { if ($id_agent > 0) {
$title = __('Information on agent %s in the database', agents_get_name ($id_agent)); $title = __('Information on agent %s in the database', agents_get_name ($id_agent));
} else { }
else {
$title = __('Information on all agents in the database'); $title = __('Information on all agents in the database');
} }
@ -182,13 +178,13 @@ else {
$query = ""; $query = "";
} }
$data["1day"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["1day"], $query)); $data["1day"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["1day"], $query));
$data["3day"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["3day"], $query)); $data["3day"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["3day"], $query));
$data["1week"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["1week"], $query)); $data["1week"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["1week"], $query));
$data["2week"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["2week"], $query)); $data["2week"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["2week"], $query));
$data["1month"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["1month"], $query)); $data["1month"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["1month"], $query));
$data["3month"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["3month"], $query)); $data["3month"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["3month"], $query));
$data["total"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE 1=1 %s", $query)); $data["total"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE 1=1 %s", $query));
$data["1day"] += db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_inc WHERE utimestamp > %d %s", $time["1day"], $query)); $data["1day"] += db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_inc WHERE utimestamp > %d %s", $time["1day"], $query));
$data["3day"] += db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_inc WHERE utimestamp > %d %s", $time["3day"], $query)); $data["3day"] += db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_inc WHERE utimestamp > %d %s", $time["3day"], $query));

View File

@ -167,6 +167,12 @@ define('SERVICE_STATUS_UNKNOW', -1);
define('SERVICE_STATUS_NORMAL', 0); define('SERVICE_STATUS_NORMAL', 0);
define('SERVICE_STATUS_CRITICAL', 1); define('SERVICE_STATUS_CRITICAL', 1);
define('SERVICE_STATUS_WARNING', 2); define('SERVICE_STATUS_WARNING', 2);
//Default weights
define('SERVICE_WEIGHT_CRITICAL', 1);
define('SERVICE_WEIGHT_WARNING', 0.5);
define('SERVICE_ELEMENT_WEIGHT_CRITICAL', 1);
define('SERVICE_ELEMENT_WEIGHT_WARNING', 0.5);
define('SERVICE_ELEMENT_WEIGHT_OK', 0);

View File

@ -405,6 +405,10 @@ function set_user_language() {
*/ */
function human_time_description_raw ($seconds, $exactly = false, $units = 'large') { function human_time_description_raw ($seconds, $exactly = false, $units = 'large') {
//Miguel: I think that I can kill this unicorns and magical numbers
// because this function may call without loaded the
// constants.php file.
switch ($units) { switch ($units) {
case 'large': case 'large':
$secondsString = __('seconds'); $secondsString = __('seconds');

View File

@ -295,7 +295,7 @@ function config_process_config () {
} }
if (!isset ($config["sla_period"]) || empty ($config["sla_period"])) { if (!isset ($config["sla_period"]) || empty ($config["sla_period"])) {
config_update_value ('sla_period', 604800); config_update_value ('sla_period', SECONDS_1WEEK);
} }
if (!isset ($config["prominent_time"])) { if (!isset ($config["prominent_time"])) {

File diff suppressed because it is too large Load Diff

View File

@ -35,6 +35,7 @@ function netflow_get_filters ($filter = false) {
else { else {
$filters = db_get_all_rows_filter ("tnetflow_filter", $filter); $filters = db_get_all_rows_filter ("tnetflow_filter", $filter);
} }
$return = array (); $return = array ();
if ($filters === false) { if ($filters === false) {
return $return; return $return;
@ -60,6 +61,7 @@ function netflow_get_reports ($filter = false) {
else { else {
$filters = db_get_all_rows_filter ("tnetflow_report", $filter); $filters = db_get_all_rows_filter ("tnetflow_report", $filter);
} }
$return = array (); $return = array ();
if ($filters === false) { if ($filters === false) {
return $return; return $return;
@ -126,12 +128,12 @@ function netflow_check_report_group ($id_report, $mode=false) {
* @return array A netflow filter matching id and filter. * @return array A netflow filter matching id and filter.
*/ */
function netflow_filter_get_filter ($id_sg, $filter = false, $fields = false) { function netflow_filter_get_filter ($id_sg, $filter = false, $fields = false) {
if (! is_array ($filter))
if (! is_array ($filter)) $filter = array ();
$filter = array ();
$filter['id_sg'] = (int) $id_sg;
return db_get_row_filter ('tnetflow_filter', $filter, $fields); $filter['id_sg'] = (int) $id_sg;
return db_get_row_filter ('tnetflow_filter', $filter, $fields);
} }
/** /**
@ -232,33 +234,33 @@ function netflow_stat_table ($data, $start_date, $end_date, $aggregate, $unit){
*/ */
function netflow_data_table ($data, $start_date, $end_date, $aggregate) { function netflow_data_table ($data, $start_date, $end_date, $aggregate) {
global $nfdump_date_format; global $nfdump_date_format;
$period = $end_date - $start_date; $period = $end_date - $start_date;
$start_date = date ($nfdump_date_format, $start_date); $start_date = date ($nfdump_date_format, $start_date);
$end_date = date ($nfdump_date_format, $end_date); $end_date = date ($nfdump_date_format, $end_date);
// Set the format // Set the format
if ($period <= 21600) { if ($period <= SECONDS_6HOURS) {
$time_format = 'H:i:s'; $time_format = 'H:i:s';
} }
elseif ($period < 86400) { elseif ($period < SECONDS_1DAY) {
$time_format = 'H:i'; $time_format = 'H:i';
} }
elseif ($period < 1296000) { elseif ($period < SECONDS_15DAYS) {
$time_format = 'M d H:i'; $time_format = 'M d H:i';
} }
elseif ($period < 2592000) { elseif ($period < SECONDS_1MONTH) {
$time_format = 'M d H\h'; $time_format = 'M d H\h';
} }
else { else {
$time_format = 'M d H\h'; $time_format = 'M d H\h';
} }
$values = array(); $values = array();
$table->size = array ('50%'); $table->size = array ('50%');
$table->class = 'databox'; $table->class = 'databox';
$table->data = array(); $table->data = array();
$table->head = array(); $table->head = array();
$table->head[0] = '<b>'.__('Timestamp').'</b>'; $table->head[0] = '<b>'.__('Timestamp').'</b>';
@ -271,7 +273,7 @@ function netflow_data_table ($data, $start_date, $end_date, $aggregate) {
$source_count++; $source_count++;
$j++; $j++;
} }
$i = 0; $i = 0;
foreach ($data['data'] as $timestamp => $values) { foreach ($data['data'] as $timestamp => $values) {
$table->data[$i][0] = date ($time_format, $timestamp); $table->data[$i][0] = date ($time_format, $timestamp);
@ -284,7 +286,7 @@ function netflow_data_table ($data, $start_date, $end_date, $aggregate) {
} }
$i++; $i++;
} }
html_print_table($table); html_print_table($table);
} }
@ -321,14 +323,14 @@ function netflow_is_net ($address) {
function netflow_get_data ($start_date, $end_date, $command, $unique_id, $aggregate, $max, $unit) { function netflow_get_data ($start_date, $end_date, $command, $unique_id, $aggregate, $max, $unit) {
global $nfdump_date_format; global $nfdump_date_format;
global $config; global $config;
// If there is aggregation calculate the top n // If there is aggregation calculate the top n
if ($aggregate != 'none') { if ($aggregate != 'none') {
$values['data'] = array (); $values['data'] = array ();
$values['sources'] = array (); $values['sources'] = array ();
$agg_command = $command . " -s $aggregate/$unit -n $max -t ".date($nfdump_date_format, $start_date).'-'.date($nfdump_date_format, $end_date); $agg_command = $command . " -s $aggregate/$unit -n $max -t ".date($nfdump_date_format, $start_date).'-'.date($nfdump_date_format, $end_date);
exec($agg_command, $string); exec($agg_command, $string);
foreach($string as $line){ foreach($string as $line){
if ($line=='') { if ($line=='') {
continue; continue;
@ -338,29 +340,30 @@ function netflow_get_data ($start_date, $end_date, $command, $unique_id, $aggreg
$val = explode(' ',$line); $val = explode(' ',$line);
$values['sources'][$val[4]] = 1; $values['sources'][$val[4]] = 1;
} }
} else { }
else {
$values = array (); $values = array ();
} }
// Load cache // Load cache
$cache_file = $config['attachment_store'] . '/netflow_' . $unique_id . '.cache'; $cache_file = $config['attachment_store'] . '/netflow_' . $unique_id . '.cache';
$last_timestamp = netflow_load_cache ($values, $cache_file, $start_date, $end_date, $aggregate); $last_timestamp = netflow_load_cache ($values, $cache_file, $start_date, $end_date, $aggregate);
if ($last_timestamp < $end_date) { if ($last_timestamp < $end_date) {
$last_timestamp++; $last_timestamp++;
// Execute nfdump and save its output in a temporary file // Execute nfdump and save its output in a temporary file
$temp_file = $config['attachment_store'] . '/netflow_' . $unique_id . '.tmp'; $temp_file = $config['attachment_store'] . '/netflow_' . $unique_id . '.tmp';
$command .= ' -t '.date($nfdump_date_format, $last_timestamp).'-'.date($nfdump_date_format, $end_date); $command .= ' -t '.date($nfdump_date_format, $last_timestamp).'-'.date($nfdump_date_format, $end_date);
exec("$command > $temp_file"); exec("$command > $temp_file");
// Parse data file // Parse data file
// We must parse from $start_date to avoid creating new intervals! // We must parse from $start_date to avoid creating new intervals!
netflow_parse_file ($start_date, $end_date, $temp_file, $values, $aggregate, $unit); netflow_parse_file ($start_date, $end_date, $temp_file, $values, $aggregate, $unit);
unlink ($temp_file); unlink ($temp_file);
} }
// Save cache // Save cache
if ($aggregate == 'none') { if ($aggregate == 'none') {
netflow_save_cache ($values, $cache_file); netflow_save_cache ($values, $cache_file);
@ -383,10 +386,10 @@ function netflow_get_data ($start_date, $end_date, $command, $unique_id, $aggreg
*/ */
function netflow_get_stats ($start_date, $end_date, $command, $aggregate, $max, $unit){ function netflow_get_stats ($start_date, $end_date, $command, $aggregate, $max, $unit){
global $nfdump_date_format; global $nfdump_date_format;
$command .= " -s $aggregate/$unit -n $max -t " .date($nfdump_date_format, $start_date).'-'.date($nfdump_date_format, $end_date); $command .= " -s $aggregate/$unit -n $max -t " .date($nfdump_date_format, $start_date).'-'.date($nfdump_date_format, $end_date);
exec($command, $string); exec($command, $string);
if(! is_array($string)){ if(! is_array($string)){
return array (); return array ();
} }
@ -400,7 +403,7 @@ function netflow_get_stats ($start_date, $end_date, $command, $aggregate, $max,
$line = preg_replace('/\(\s*\S+\)/','',$line); $line = preg_replace('/\(\s*\S+\)/','',$line);
$line = preg_replace('/\s+/',' ',$line); $line = preg_replace('/\s+/',' ',$line);
$val = explode(' ',$line); $val = explode(' ',$line);
$values[$i]['date'] = $val[0]; $values[$i]['date'] = $val[0];
$values[$i]['time'] = $val[1]; $values[$i]['time'] = $val[1];
@ -422,11 +425,12 @@ function netflow_get_stats ($start_date, $end_date, $command, $aggregate, $max,
default: default:
$values[$i]['data'] = $val[7]; $values[$i]['data'] = $val[7];
break; break;
} }
$i++; $i++;
} }
sort_netflow_data ($values); sort_netflow_data ($values);
return $values; return $values;
} }
@ -440,7 +444,7 @@ function netflow_get_stats ($start_date, $end_date, $command, $aggregate, $max,
*/ */
function netflow_get_command ($filter) { function netflow_get_command ($filter) {
global $config; global $config;
// Build command // Build command
$command = 'nfdump -q -N -m'; $command = 'nfdump -q -N -m';
@ -448,10 +452,10 @@ function netflow_get_command ($filter) {
if (isset($config['netflow_path']) && $config['netflow_path'] != '') { if (isset($config['netflow_path']) && $config['netflow_path'] != '') {
$command .= ' -R '.$config['netflow_path']; $command .= ' -R '.$config['netflow_path'];
} }
// Filter options // Filter options
$command .= netflow_get_filter_arguments ($filter); $command .= netflow_get_filter_arguments ($filter);
return $command; return $command;
} }
@ -464,14 +468,14 @@ function netflow_get_command ($filter) {
* *
*/ */
function netflow_get_filter_arguments ($filter) { function netflow_get_filter_arguments ($filter) {
// Advanced filter // Advanced filter
$filter_args = ''; $filter_args = '';
if ($filter['advanced_filter'] != '') { if ($filter['advanced_filter'] != '') {
$filter_args = preg_replace('/["\r\n]/','', io_safe_output ($filter['advanced_filter'])); $filter_args = preg_replace('/["\r\n]/','', io_safe_output ($filter['advanced_filter']));
return ' "(' . $filter_args . ')"'; return ' "(' . $filter_args . ')"';
} }
// Normal filter // Normal filter
if ($filter['ip_dst'] != ''){ if ($filter['ip_dst'] != ''){
$filter_args .= ' "('; $filter_args .= ' "(';
@ -483,7 +487,8 @@ function netflow_get_filter_arguments ($filter) {
if (netflow_is_net ($val_ipdst[$i]) == 0) { if (netflow_is_net ($val_ipdst[$i]) == 0) {
$filter_args .= 'dst ip '.$val_ipdst[$i]; $filter_args .= 'dst ip '.$val_ipdst[$i];
} else { }
else {
$filter_args .= 'dst net '.$val_ipdst[$i]; $filter_args .= 'dst net '.$val_ipdst[$i];
} }
} }
@ -492,7 +497,8 @@ function netflow_get_filter_arguments ($filter) {
if ($filter['ip_src'] != ''){ if ($filter['ip_src'] != ''){
if ($filter_args == '') { if ($filter_args == '') {
$filter_args .= ' "('; $filter_args .= ' "(';
} else { }
else {
$filter_args .= ' and ('; $filter_args .= ' and (';
} }
$val_ipsrc = explode(',', $filter['ip_src']); $val_ipsrc = explode(',', $filter['ip_src']);
@ -503,7 +509,8 @@ function netflow_get_filter_arguments ($filter) {
if (netflow_is_net ($val_ipsrc[$i]) == 0) { if (netflow_is_net ($val_ipsrc[$i]) == 0) {
$filter_args .= 'src ip '.$val_ipsrc[$i]; $filter_args .= 'src ip '.$val_ipsrc[$i];
} else { }
else {
$filter_args .= 'src net '.$val_ipsrc[$i]; $filter_args .= 'src net '.$val_ipsrc[$i];
} }
} }
@ -512,7 +519,8 @@ function netflow_get_filter_arguments ($filter) {
if ($filter['dst_port'] != 0) { if ($filter['dst_port'] != 0) {
if ($filter_args == '') { if ($filter_args == '') {
$filter_args .= ' "('; $filter_args .= ' "(';
} else { }
else {
$filter_args .= ' and ('; $filter_args .= ' and (';
} }
$val_dstport = explode(',', $filter['dst_port']); $val_dstport = explode(',', $filter['dst_port']);
@ -527,7 +535,8 @@ function netflow_get_filter_arguments ($filter) {
if ($filter['src_port'] != 0) { if ($filter['src_port'] != 0) {
if ($filter_args == '') { if ($filter_args == '') {
$filter_args .= ' "('; $filter_args .= ' "(';
} else { }
else {
$filter_args .= ' and ('; $filter_args .= ' and (';
} }
$val_srcport = explode(',', $filter['src_port']); $val_srcport = explode(',', $filter['src_port']);
@ -542,7 +551,7 @@ function netflow_get_filter_arguments ($filter) {
if ($filter_args != '') { if ($filter_args != '') {
$filter_args .= '"'; $filter_args .= '"';
} }
return $filter_args; return $filter_args;
} }
@ -562,21 +571,21 @@ function netflow_get_filter_arguments ($filter) {
*/ */
function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate, $unit) { function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate, $unit) {
global $config; global $config;
// Last timestamp read // Last timestamp read
$last_timestamp = $start_date; $last_timestamp = $start_date;
// Open the data file // Open the data file
$fh = @fopen ($file, "r"); $fh = @fopen ($file, "r");
if ($fh === FALSE) { if ($fh === FALSE) {
return $last_timestamp; return $last_timestamp;
} }
// Calculate the number of intervals // Calculate the number of intervals
$num_intervals = $config['graph_res'] * 50; $num_intervals = $config['graph_res'] * 50;
$period = $end_date - $start_date; $period = $end_date - $start_date;
$interval_length = (int) ($period / $num_intervals); $interval_length = (int) ($period / $num_intervals);
// Parse flow data // Parse flow data
$read_flag = 1; $read_flag = 1;
$flow = array (); $flow = array ();
@ -586,11 +595,12 @@ function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate
if ($aggregate != 'none') { if ($aggregate != 'none') {
$interval_total = array (); $interval_total = array ();
$interval_count = array (); $interval_count = array ();
} else { }
else {
$interval_total = 0; $interval_total = 0;
$interval_count = 0; $interval_count = 0;
} }
do { do {
if ($read_flag == 1) { if ($read_flag == 1) {
$read_flag = 0; $read_flag = 0;
@ -610,7 +620,7 @@ function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate
$flow['date'] = $val[0]; $flow['date'] = $val[0];
$flow['time'] = $val[1]; $flow['time'] = $val[1];
switch ($aggregate){ switch ($aggregate) {
case "proto": case "proto":
$flow['agg'] = $val[3]; $flow['agg'] = $val[3];
break; break;
@ -657,12 +667,14 @@ function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate
$interval_total[$flow['agg']] += $flow['data']; $interval_total[$flow['agg']] += $flow['data'];
$interval_count[$flow['agg']] += 1; $interval_count[$flow['agg']] += 1;
} }
} else { }
else {
$interval_total += $flow['data']; $interval_total += $flow['data'];
$interval_count += 1; $interval_count += 1;
} }
} }
} while ($read_flag == 1); }
while ($read_flag == 1);
if ($aggregate != 'none') { if ($aggregate != 'none') {
foreach ($interval_total as $agg => $val) { foreach ($interval_total as $agg => $val) {
@ -671,24 +683,26 @@ function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate
if ($interval_count[$agg] == 0) { if ($interval_count[$agg] == 0) {
continue; continue;
} }
// Read previous data for this interval // Read previous data for this interval
if (isset ($values['data'][$timestamp][$agg])) { if (isset ($values['data'][$timestamp][$agg])) {
$previous_value = $values['data'][$timestamp][$agg]; $previous_value = $values['data'][$timestamp][$agg];
} else { }
else {
$previous_value = 0; $previous_value = 0;
} }
// Calculate interval data // Calculate interval data
$values['data'][$timestamp][$agg] = (int) ($interval_total[$agg] / $interval_count[$agg]); $values['data'][$timestamp][$agg] = (int) ($interval_total[$agg] / $interval_count[$agg]);
// Average with previous data // Average with previous data
if ($previous_value != 0) { if ($previous_value != 0) {
$values['data'][$timestamp][$agg] = (int) (($values['data'][$timestamp][$agg] + $previous_data) / 2); $values['data'][$timestamp][$agg] = (int) (($values['data'][$timestamp][$agg] + $previous_data) / 2);
} }
} }
} else { }
else {
// No data for this interval // No data for this interval
if ($interval_count == 0) { if ($interval_count == 0) {
continue; continue;
@ -697,10 +711,11 @@ function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate
// Read previous data for this interval // Read previous data for this interval
if (isset ($values[$timestamp]['data'])) { if (isset ($values[$timestamp]['data'])) {
$previous_value = $values[$timestamp]['data']; $previous_value = $values[$timestamp]['data'];
} else { }
else {
$previous_value = 0; $previous_value = 0;
} }
// Calculate interval data // Calculate interval data
$values[$timestamp]['data'] = (int) ($interval_total / $interval_count); $values[$timestamp]['data'] = (int) ($interval_total / $interval_count);
@ -708,11 +723,11 @@ function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate
if ($previous_value != 0) { if ($previous_value != 0) {
$values[$timestamp]['data'] = (int) (($values[$timestamp]['data'] + $previous_value) / 2); $values[$timestamp]['data'] = (int) (($values[$timestamp]['data'] + $previous_value) / 2);
} }
} }
} }
fclose ($fh); fclose ($fh);
return $last_timestamp; return $last_timestamp;
} }
@ -725,12 +740,12 @@ function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate
* *
*/ */
function netflow_save_cache ($data, $cache_file) { function netflow_save_cache ($data, $cache_file) {
@file_put_contents ($cache_file, serialize ($data)); @file_put_contents ($cache_file, serialize ($data));
return; return;
} }
/** /**
* Load data from the specified cache file. * Load data from the specified cache file.
* *
@ -892,5 +907,4 @@ function netflow_draw_item ($start_date, $end_date, $type, $filter, $command, $f
break; break;
} }
} }
?>
?>

View File

@ -270,7 +270,8 @@ function ui_print_message ($message, $class = '', $attributes = '', $return = fa
if ($return) if ($return)
return $output; return $output;
echo $output; else
echo $output;
} }
/** /**
@ -342,7 +343,9 @@ function ui_print_result_message ($result, $good = '', $bad = '', $attributes =
if (empty ($result)) { if (empty ($result)) {
return ui_print_error_message ($bad, $attributes, $return, $tag); return ui_print_error_message ($bad, $attributes, $return, $tag);
} }
return ui_print_success_message ($good, $attributes, $return, $tag); else {
return ui_print_success_message ($good, $attributes, $return, $tag);
}
} }
/** /**
@ -472,7 +475,7 @@ function ui_print_group_icon ($id_group, $return = false, $path = "groups_small"
if($style == '') if($style == '')
$style = 'width: 16px; height: 16px;'; $style = 'width: 16px; height: 16px;';
$output = ''; $output = '';
if ($link) if ($link)
$output = '<a href="index.php?sec=estado&amp;sec2=operation/agentes/estado_agente&amp;refr=60&amp;group_id='.$id_group.'">'; $output = '<a href="index.php?sec=estado&amp;sec2=operation/agentes/estado_agente&amp;refr=60&amp;group_id='.$id_group.'">';
@ -508,7 +511,7 @@ function ui_print_group_icon_path ($id_group, $return = false, $path = "images/g
if($style == '') if($style == '')
$style = 'width: 16px; height: 16px;'; $style = 'width: 16px; height: 16px;';
$output = ''; $output = '';
if ($link) if ($link)
$output = '<a href="index.php?sec=estado&amp;sec2=operation/agentes/estado_agente&amp;refr=60&amp;group_id='.$id_group.'">'; $output = '<a href="index.php?sec=estado&amp;sec2=operation/agentes/estado_agente&amp;refr=60&amp;group_id='.$id_group.'">';
@ -823,7 +826,8 @@ function ui_print_string_substr ($string, $cutoff = 16, $return = false, $fontsi
$string2 = io_safe_output ($string); $string2 = io_safe_output ($string);
if (mb_strlen($string2, "UTF-8") > $cutoff){ if (mb_strlen($string2, "UTF-8") > $cutoff){
$string3 = "..."; $string3 = "...";
} else { }
else {
$string3 = ""; $string3 = "";
} }
@ -1298,7 +1302,8 @@ function ui_process_page_head ($string, $bitfield) {
$output .= $string; $output .= $string;
if (!empty ($config["compact_header"])) { if (!empty ($config["compact_header"])) {
$output = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $output); $output = str_replace(array("\r\n", "\r", "\n", "\t", ' ',
' ', ' '), '', $output);
} }
return $output; return $output;
@ -1315,7 +1320,8 @@ function ui_process_page_head ($string, $bitfield) {
function ui_process_page_body ($string, $bitfield) { function ui_process_page_body ($string, $bitfield) {
global $config; global $config;
if (isset ($config['ignore_callback']) && $config['ignore_callback'] == true) { if (isset ($config['ignore_callback']) &&
$config['ignore_callback'] == true) {
return; return;
} }
@ -1326,12 +1332,13 @@ function ui_process_page_body ($string, $bitfield) {
require_once ($config["homedir"]."/include/htmlawed.php"); require_once ($config["homedir"]."/include/htmlawed.php");
$htmLawedconfig = array ("valid_xhtml" => 1, "tidy" => -1); $htmLawedconfig = array ("valid_xhtml" => 1, "tidy" => -1);
$output .= htmLawed ($string, $htmLawedconfig); $output .= htmLawed ($string, $htmLawedconfig);
} else { }
else {
$output .= $string; $output .= $string;
} }
$output .= '</body>'; $output .= '</body>';
return $output; return $output;
} }
@ -1433,7 +1440,8 @@ function ui_pagination ($count, $url = false, $offset = 0, $pagination = 0, $ret
$output .= '<a class="pagination" href="'.$url.'&amp;'.$offset_name.'='.$inicio_bloque.'">'; $output .= '<a class="pagination" href="'.$url.'&amp;'.$offset_name.'='.$inicio_bloque.'">';
if ($inicio_bloque == $offset) { if ($inicio_bloque == $offset) {
$output .= "<b>[ $i ]</b>"; $output .= "<b>[ $i ]</b>";
} else { }
else {
$output .= "[ $i ]"; $output .= "[ $i ]";
} }
$output .= '</a></span>'; $output .= '</a></span>';
@ -1512,7 +1520,7 @@ function ui_debug ($var, $backtrace = true) {
unset ($traces[0]); unset ($traces[0]);
foreach ($traces as $trace) { foreach ($traces as $trace) {
$trace_id++; $trace_id++;
/* Many classes are used to allow better customization. /* Many classes are used to allow better customization.
Please, do not remove them */ Please, do not remove them */
echo '<li>'; echo '<li>';
@ -1527,7 +1535,8 @@ function ui_debug ($var, $backtrace = true) {
echo ' - <span class="filename">'; echo ' - <span class="filename">';
echo str_replace ($config['homedir'].'/', '', $trace['file']); echo str_replace ($config['homedir'].'/', '', $trace['file']);
echo ':'.$trace['line'].'</span>'; echo ':'.$trace['line'].'</span>';
} else { }
else {
echo ' - <span class="filename"><em>Unknown file</em></span>'; echo ' - <span class="filename"><em>Unknown file</em></span>';
} }
echo '<pre id="args-'.$trace_id.'" class="invisible">'; echo '<pre id="args-'.$trace_id.'" class="invisible">';
@ -1550,6 +1559,7 @@ function ui_debug ($var, $backtrace = true) {
echo '<pre class="debug">'; echo '<pre class="debug">';
print_r ($var); print_r ($var);
echo '</pre>'; echo '</pre>';
return true; return true;
} }
@ -1576,14 +1586,14 @@ function ui_print_moduletype_icon ($id_moduletype, $return = false, $relative =
if (! file_exists ($config['homedir'].'/'.$imagepath)) if (! file_exists ($config['homedir'].'/'.$imagepath))
$imagepath = ENTERPRISE_DIR.'/'.$imagepath; $imagepath = ENTERPRISE_DIR.'/'.$imagepath;
if ($options){ if ($options) {
return html_print_image ($imagepath, $return, return html_print_image ($imagepath, $return,
array ("border" => 0, array ("border" => 0,
"title" => $type["descripcion"]), false, $relative); "title" => $type["descripcion"]), false, $relative);
} }
else{ else {
return html_print_image ($imagepath, $return, return html_print_image ($imagepath, $return,
false, false, $relative); false, false, $relative);
} }
} }
@ -1599,15 +1609,15 @@ function ui_print_moduletype_icon ($id_moduletype, $return = false, $relative =
*/ */
function ui_print_module_warn_value ($max_warning, $min_warning, $str_warning, $max_critical, $min_critical, $str_critical) { function ui_print_module_warn_value ($max_warning, $min_warning, $str_warning, $max_critical, $min_critical, $str_critical) {
$data = "<span style='font-size: 8px' title='" . __("Warning") . ": " . __("Max") . $max_warning . "/" . __("Min") . $min_warning . " - " . __("Critical") . ": " . __("Max") . $max_critical . "/" . __("Min") . $min_critical . "'>"; $data = "<span style='font-size: 8px' title='" . __("Warning") . ": " . __("Max") . $max_warning . "/" . __("Min") . $min_warning . " - " . __("Critical") . ": " . __("Max") . $max_critical . "/" . __("Min") . $min_critical . "'>";
if ($max_warning != $min_warning) { if ($max_warning != $min_warning) {
$data .= format_for_graph($max_warning) ."/". format_for_graph ($min_warning); $data .= format_for_graph($max_warning) ."/". format_for_graph ($min_warning);
} else { } else {
$data .= __("N/A"); $data .= __("N/A");
} }
$data .= " - "; $data .= " - ";
if ($max_critical != $min_critical){ if ($max_critical != $min_critical){
$data .= format_for_graph($max_critical) ."/". format_for_graph ($min_critical); $data .= format_for_graph($max_critical) ."/". format_for_graph ($min_critical);
} else { } else {
@ -1672,7 +1682,7 @@ function ui_get_status_images_path () {
function ui_print_status_image ($type, $title = "", $return = false, $options = false) { function ui_print_status_image ($type, $title = "", $return = false, $options = false) {
list ($imagepath) = ui_get_status_images_path (); list ($imagepath) = ui_get_status_images_path ();
$imagepath .= "/".$type; $imagepath .= "/" . $type;
if($options === false) { if($options === false) {
$options = array(); $options = array();
@ -1749,7 +1759,7 @@ function ui_print_ui_agents_list ($options = false, $filter = false, $return = f
*/ */
function ui_get_include_contents ($filename, $params = false) { function ui_get_include_contents ($filename, $params = false) {
global $config; global $config;
ob_start (); ob_start ();
if (is_array ($params)) { if (is_array ($params)) {
@ -1760,7 +1770,7 @@ function ui_get_include_contents ($filename, $params = false) {
if (strncmp ($config["homedir"], $filename, strlen ($config["homedir"])) != 0) { if (strncmp ($config["homedir"], $filename, strlen ($config["homedir"])) != 0) {
return false; return false;
} }
$result = include ($filename); $result = include ($filename);
if ($result === false) { if ($result === false) {
ob_end_clean (); ob_end_clean ();

View File

@ -479,11 +479,11 @@ foreach ($modules as $module) {
if ($module['history_data'] == 1) { if ($module['history_data'] == 1) {
// RAW Table data // RAW Table data
echo "<td class=".$tdcolor." width=70>"; echo "<td class=".$tdcolor." width=70>";
echo "<a href='index.php?sec=estado&amp;sec2=operation/agentes/ver_agente&amp;id_agente=$id_agente&amp;tab=data_view&amp;period=2592000&amp;id=".$module["id_agente_modulo"]."'>" . html_print_image('images/data_m.png', true, array("border" => '0', "alt" => '')) . "</a>&nbsp;&nbsp;"; echo "<a href='index.php?sec=estado&amp;sec2=operation/agentes/ver_agente&amp;id_agente=$id_agente&amp;tab=data_view&amp;period=" . SECONDS_1MONTH . "&amp;id=".$module["id_agente_modulo"]."'>" . html_print_image('images/data_m.png', true, array("border" => '0', "alt" => '')) . "</a>&nbsp;&nbsp;";
echo "<a href='index.php?sec=estado&amp;sec2=operation/agentes/ver_agente&amp;id_agente=$id_agente&amp;tab=data_view&amp;period=604800&amp;id=".$module["id_agente_modulo"]."'>" . html_print_image('images/data_w.png', true, array("border" => '0', "alt" => '')) . "</a>&nbsp;&nbsp;"; echo "<a href='index.php?sec=estado&amp;sec2=operation/agentes/ver_agente&amp;id_agente=$id_agente&amp;tab=data_view&amp;period=" . SECONDS_1WEEK . "&amp;id=".$module["id_agente_modulo"]."'>" . html_print_image('images/data_w.png', true, array("border" => '0', "alt" => '')) . "</a>&nbsp;&nbsp;";
echo "<a href='index.php?sec=estado&amp;sec2=operation/agentes/ver_agente&amp;id_agente=$id_agente&amp;tab=data_view&amp;period=86400&amp;id=".$module["id_agente_modulo"]."'>" . html_print_image('images/data_d.png', true, array("border" => '0', "alt" => '')) . "</a>"; echo "<a href='index.php?sec=estado&amp;sec2=operation/agentes/ver_agente&amp;id_agente=$id_agente&amp;tab=data_view&amp;period=" . SECONDS_1DAY ."&amp;id=".$module["id_agente_modulo"]."'>" . html_print_image('images/data_d.png', true, array("border" => '0', "alt" => '')) . "</a>";
} }
else { else {
echo "<td class=".$tdcolor."></td>"; echo "<td class=".$tdcolor."></td>";
@ -494,7 +494,8 @@ foreach ($modules as $module) {
$seconds = get_system_time () - $module["utimestamp"]; $seconds = get_system_time () - $module["utimestamp"];
if ($module['id_tipo_modulo'] < 21 && $module["module_interval"] > 0 && $module["utimestamp"] > 0 && $seconds >= ($module["module_interval"] * 2)) { if ($module['id_tipo_modulo'] < 21 && $module["module_interval"] > 0 && $module["utimestamp"] > 0 && $seconds >= ($module["module_interval"] * 2)) {
echo '<span class="redb">'; echo '<span class="redb">';
} else { }
else {
echo '<span>'; echo '<span>';
} }
} }
@ -503,5 +504,4 @@ foreach ($modules as $module) {
echo "</td></tr>"; echo "</td></tr>";
} }
echo '</table>'; echo '</table>';
?> ?>