2008-06-18 Esteban Sanchez <estebans@artica.es>

* functions.php: Added documentation to all the functions in JavaDoc
        format, which is an facto-standard. Deleted unused functions. Improved
        the code of some functions. Tab and blankspaces style correction.
        Replaced old lang_label with lang_string(). Some functions to print
        selects were replaced with a functio to get an array with all the
        possible values so the caller will use print_select() with them.

        * godmode/agentes/agent_manager.php: Use print_select() instead of
        deleted function.

        * godmode/agentes/alert_manager_editor.php: Use print_select() instead
        of deleted function. Use print_checkbox(). Style correction

        * godmode/reporting/map_builder.php, operation/agentes/ver_agente.php,
        operation/messages/message.php,
        operation/reporting/reporting_viewer_pdf.php:
        Replaced deleted functions with their equivalents.

        * include/functions_db.php: Documented some functions, some work is
        still required. Added get_reports() to get all the reports a user can
        see. Deleted unused functions. Replaced deleted functions with their
        equivalents. Added get_db_row_sql(), get_previous_data(). Fixed errors
        when calculating average, max, min and sum values of an agent module.

        * include/functions_reporting.php: Fixed errors when calculating SLA.

        * operation/events/events.php: Tab and blankspaces correction.
        Replaced form_priority with print_select(). Style correction.

        * operation/reporting/custom_reporting.php: Show all the reports a
        user can see. Use Pandora functions.

        * operation/reporting/reporting_viewer.php: Show unknown label if SLA
        can not be calculated.

        * operation/snmpconsole/snmp_alert.php: Avoid an extra indentation
        level by using check_login() properly. Tab and blankspaces correction.

        * index.php, operation/users/user_edit.php: Adopted to renamed
        function.

        * godmode/db/db_sanity.php, reporting/fgraph.php: Style correction.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@881 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Esteban Sanchez 2008-06-19 09:01:12 +00:00
parent b6e45a9d99
commit f42b3c6003
18 changed files with 1788 additions and 1581 deletions

View File

@ -1,16 +1,60 @@
2008-06-18 Esteban Sanchez <estebans@artica.es>
* functions.php: Added documentation to all the functions in JavaDoc
format, which is an facto-standard. Deleted unused functions. Improved
the code of some functions. Tab and blankspaces style correction.
Replaced old lang_label with lang_string(). Some functions to print
selects were replaced with a functio to get an array with all the
possible values so the caller will use print_select() with them.
* godmode/agentes/agent_manager.php: Use print_select() instead of
deleted function.
* godmode/agentes/alert_manager_editor.php: Use print_select() instead
of deleted function. Use print_checkbox(). Style correction
* godmode/reporting/map_builder.php, operation/agentes/ver_agente.php,
operation/messages/message.php,
operation/reporting/reporting_viewer_pdf.php:
Replaced deleted functions with their equivalents.
* include/functions_db.php: Documented some functions, some work is
still required. Added get_reports() to get all the reports a user can
see. Deleted unused functions. Replaced deleted functions with their
equivalents. Added get_db_row_sql(), get_previous_data(). Fixed errors
when calculating average, max, min and sum values of an agent module.
* include/functions_reporting.php: Fixed errors when calculating SLA.
* operation/events/events.php: Tab and blankspaces correction.
Replaced form_priority with print_select(). Style correction.
* operation/reporting/custom_reporting.php: Show all the reports a
user can see. Use Pandora functions.
* operation/reporting/reporting_viewer.php: Show unknown label if SLA
can not be calculated.
* operation/snmpconsole/snmp_alert.php: Avoid an extra indentation
level by using check_login() properly. Tab and blankspaces correction.
* index.php, operation/users/user_edit.php: Adopted to renamed
function.
* godmode/db/db_sanity.php, reporting/fgraph.php: Style correction.
2008-06-18 Sancho Lerena <slerena@gmail.com>
* pandoradbdata_13_to_20.sql: prototype. not functional.
* operation/events/export_csv.php: Event export to CSV. Support
passed filters.
* operation/events/export_csv.php: Event export to CSV. Support passed
filters.
* images/networkmap/*.png: Updated icons for network map.
* godmode/menu.php,
* godmode/db/db_sanity.php: New sanity tool for database in interactive
mode using console (ported from pandora_db.pl).
* godmode/menu.php, godmode/db/db_sanity.php: New sanity tool for
database in interactive mode using console (ported from
pandora_db.pl).
* reporting/fgraph.php: Added graphs for string data types. Fixed
event by agent/module graph for system events.
@ -22,7 +66,7 @@
* godmode/agentes/agent_manager.php,
godmode/agentes/modificar_agente.php: Delete of remote configuration
when delete an agent and manually, by user.
when delete an agent and manually, by user..
* operation/servers/view_server_detail.php: Added refresh option and
fixed layout.

View File

@ -70,7 +70,7 @@ echo '<td class="datos"><b>'.$lang_label["agent_name"].'</b></td>
<td class="datos">
<input type="text" name="agente" size=30 value="'.$nombre_agente.'">';
if ((isset($id_agente)) && ($id_agente != "")){
if (isset ($id_agente) && $id_agente != "") {
echo "
<a href='index.php?sec=estado&
sec2=operation/agentes/ver_agente&id_agente=".$id_agente."'>
@ -110,11 +110,12 @@ if ($create_agent != 1){
echo '<tr><td class="datos"><b>'.lang_string ("Parent").'</b>';
echo '<td class="datos">';
if ($create_agent != 1) {
form_agent_combo ($id_parent, "id_parent");
print_select_from_sql ('SELECT id_agente, nombre FROM tagente',
'id_parent', $id_agente, '', '', '');
} else {
print_select_from_sql ('SELECT id_agente, nombre FROM tagente',
'id_parent', 0, '', 'None', '0');
}
else
form_agent_combo (0, "id_parent");
echo '<tr><td class="datos"><b>'.$lang_label["group"].'</b>';
echo '<td class="datos"><select name="grupo" class="w130">';

View File

@ -1,5 +1,4 @@
<?PHP
<?php
// Pandora FMS - the Free Monitoring System
// ========================================
@ -72,10 +71,10 @@ echo '<td class="datos3">';
echo lang_string ("Priority");
echo '<td class="datos3">';
if (isset($alert_priority)){
if (! isset($alert_priority)) {
$alert_priority = 3; // Warning by default
}
echo form_priority ($alert_priority, "alert_priority");
print_select (get_priorities (), "alert_priority", $alert_priority, '', '', '');
// Alert type
echo '<tr><td class="datos">';
@ -233,27 +232,25 @@ echo "</select>";
echo "<tr><td class='datos'>".lang_string ("Days of week");
echo "<td class='datos' colspan=4>";
echo lang_string("Mon");
echo form_render_check ("alert_d1", $alert_d1);
print_checkbox ("alert_d1", 1, $alert_d1);
echo "&nbsp;&nbsp;";
echo lang_string("Tue");
echo form_render_check ("alert_d2", $alert_d2);
print_checkbox ("alert_d2", 1, $alert_d2);
echo "&nbsp;&nbsp;";
echo lang_string("Wed");
echo form_render_check ("alert_d3", $alert_d3);
print_checkbox ("alert_d3", 1, $alert_d3);
echo "&nbsp;&nbsp;";
echo lang_string("Thu");
echo form_render_check ("alert_d4", $alert_d4);
print_checkbox ("alert_d4", 1, $alert_d4);
echo "&nbsp;&nbsp;";
echo lang_string("Fri");
echo form_render_check ("alert_d5", $alert_d5);
print_checkbox ("alert_d5", 1, $alert_d5);
echo "&nbsp;&nbsp;";
echo lang_string("Sat");
echo form_render_check ("alert_d6", $alert_d6);
print_checkbox ("alert_d6", 1, $alert_d6);
echo "&nbsp;&nbsp;";
echo lang_string("Sun");
echo form_render_check ("alert_d7", $alert_d7);
print_checkbox ("alert_d7", 1, $alert_d7);
// Field2 Recovery
echo '<tr><td class="datos2">'.lang_string ("Field #2 (Rec)");
@ -404,7 +401,4 @@ if (($form_alerttype == "combined") AND ($update_alert != -1)){
}
echo "</table>";
}
?>

View File

@ -62,18 +62,17 @@ if ($sanity == 1){
mysql_query($query3);
}
}
}
elseif ($sanity == 2){
} elseif ($sanity == 2) {
echo "<h3>".lang_string("Deleting non-init data")."</h2>";
$query1 = "SELECT * FROM tagente_estado WHERE utimestamp = 0";
$result = mysql_query ($query1);
while ($row = mysql_fetch_array ($result)) {
$id_agente_modulo = $row[1];
$query0 = "DELETE FROM tagente_modulo WHERE id_agente_modulo = $id_agente_modulo";
$query1 = "DELETE FROM tagente_estado WHERE id_agente_modulo = $id_agente_modulo";
echo "Deleting non init module $id_agente_modulo <br>";
mysql_query($query0);
mysql_query($query1);
$sql = "DELETE FROM tagente_modulo WHERE id_agente_modulo = $id_agente_modulo";
mysql_query ($sql);
$sql = "DELETE FROM tagente_estado WHERE id_agente_modulo = $id_agente_modulo";
mysql_query ($sql);
}
}

View File

@ -1,4 +1,4 @@
<?PHP
<?php
// Pandora FMS - the Free monitoring system
// ========================================
@ -91,12 +91,12 @@ if (isset($_GET["update_module"])){
include ("general/noaccess.php");
exit;
}
$pos_x = give_parameter_post ("pos_x",0);
$pos_y = give_parameter_post ("pos_y",0);
$my_height = give_parameter_post ("height");
$my_width = give_parameter_post ("width");
$my_label = give_parameter_post ("label");
$my_image = give_parameter_post ("image");
$pos_x = get_parameter ("pos_x",0);
$pos_y = get_parameter ("pos_y",0);
$my_height = get_parameter ("height");
$my_width = get_parameter ("width");
$my_label = get_parameter ("label");
$my_image = get_parameter ("image");
$sql = "UPDATE tlayout_data SET
pos_x = '$pos_x',
@ -125,21 +125,21 @@ if (isset($_GET["add_module"])){
include ("general/noaccess.php");
exit;
}
$my_id_map = give_parameter_post ("id_map",0);
$my_id_agent = give_parameter_post ("id_agent",0);
$my_id_module = give_parameter_post ("id_module",0);
$my_period = give_parameter_post ("period",3600);
$my_type = give_parameter_post ("type",0);
$my_pos_x = give_parameter_post ("pos_x",0);
$my_pos_y = give_parameter_post ("pos_y",0);
$my_height = give_parameter_post ("height");
$my_width = give_parameter_post ("width");
$my_label = give_parameter_post ("label");
$my_image = give_parameter_post ("image");
$my_map_linked = give_parameter_post ("map_linked");
$my_parent_item = give_parameter_post ("parent_item");
$my_label_color = give_parameter_post ("label_color","");
$my_link_color = give_parameter_post ("link_color",0);
$my_id_map = get_parameter ("id_map",0);
$my_id_agent = get_parameter ("id_agent",0);
$my_id_module = get_parameter ("id_module",0);
$my_period = get_parameter ("period",3600);
$my_type = get_parameter ("type",0);
$my_pos_x = get_parameter ("pos_x",0);
$my_pos_y = get_parameter ("pos_y",0);
$my_height = get_parameter ("height");
$my_width = get_parameter ("width");
$my_label = get_parameter ("label");
$my_image = get_parameter ("image");
$my_map_linked = get_parameter ("map_linked");
$my_parent_item = get_parameter ("parent_item");
$my_label_color = get_parameter ("label_color","");
$my_link_color = get_parameter ("link_color",0);
$sql = "INSERT INTO tlayout_data (id_layout, pos_x, pos_y, height, width, label, image, type, period, id_agente_modulo, id_layout_linked, parent_item, label_color, no_link_color) VALUES ('$my_id_map', '$my_pos_x', '$my_pos_y', '$my_height', '$my_width', '$my_label', '$my_image', '$my_type', '$my_period', '$my_id_module', '$my_map_linked', '$my_parent_item', '$my_label_color', '$my_link_color')";
if ($res=mysql_query($sql))
$result = "<h3 class=suc>".$lang_label["create_ok"]."</h3>";

File diff suppressed because it is too large Load Diff

View File

@ -14,6 +14,13 @@
// GNU General Public License for more details.
/**
* Check if login session variables are set.
*
* It will stop the execution if those variables were not set
*
* @return 0 on success
*/
function check_login () {
global $config;
if (!isset($config["homedir"])){
@ -36,12 +43,27 @@ function check_login() {
exit;
}
// ---------------------------------------------------------------
// give_acl ()
// Main Function to get access to resources
// Return 0 if no access, > 0 if access
// ---------------------------------------------------------------
/**
* Check access privileges to resources
*
* Access can be:
* IR - Incident Read
* IW - Incident Write
* IM - Incident Management
* AR - Agent Read
* AW - Agent Write
* LW - Alert Write
* UM - User Management
* DM - DB Management
* LM - Alert Management
* PM - Pandora Management
*
* @param id_user User id to check
* @param id_group Agents group id to check access
* @param access Access privilege to check
*
* @return 1 if the user has privileges, 0 if not.
*/
function give_acl ($id_user, $id_group, $access) {
// IF user is level = 1 then always return 1
// Access can be:
@ -64,8 +86,7 @@ function give_acl($id_user, $id_group, $access){
$res=mysql_query($query1);
$row=mysql_fetch_array($res);
if ($row["nivel"] == 1)
$result = 1;
else {
return 1;
if ($id_group == 0) // Group doesnt matter, any group, for check permission to do at least an action in a group
$query1="SELECT * FROM tusuario_perfil WHERE id_usuario = '".$id_user."'"; // GroupID = 0, group doesnt matter (use with caution!)
else
@ -79,29 +100,62 @@ function give_acl($id_user, $id_group, $access){
$resq2=mysql_query($query2);
if ($rowq2=mysql_fetch_array($resq2)){
switch ($access) {
case "IR": $result = $result + $rowq2["incident_view"]; break;
case "IW": $result = $result + $rowq2["incident_edit"]; break;
case "IM": $result = $result + $rowq2["incident_management"]; break;
case "AR": $result = $result + $rowq2["agent_view"]; break;
case "AW": $result = $result + $rowq2["agent_edit"]; break;
case "LW": $result = $result + $rowq2["alert_edit"]; break;
case "LM": $result = $result + $rowq2["alert_management"]; break;
case "PM": $result = $result + $rowq2["pandora_management"]; break;
case "DM": $result = $result + $rowq2["db_management"]; break;
case "UM": $result = $result + $rowq2["user_management"]; break;
case "IR":
$result = $result + $rowq2["incident_view"];
break;
case "IW":
$result = $result + $rowq2["incident_edit"];
break;
case "IM":
$result = $result + $rowq2["incident_management"];
break;
case "AR":
$result = $result + $rowq2["agent_view"];
break;
case "AW":
$result = $result + $rowq2["agent_edit"];
break;
case "LW":
$result = $result + $rowq2["alert_edit"];
break;
case "LM":
$result = $result + $rowq2["alert_management"];
break;
case "PM":
$result = $result + $rowq2["pandora_management"];
break;
case "DM":
$result = $result + $rowq2["db_management"];
break;
case "UM":
$result = $result + $rowq2["user_management"];
break;
}
}
}
} // else
if ($result > 1)
$result = 1;
return $result;
}
// ---------------------------------------------------------------
// audit_db, update audit log
// ---------------------------------------------------------------
/**
* Adds an audit log entry.
*
* @param id User id that makes the incident
* @param ip Client IP who makes the incident
* @param accion Action description
* @param descripcion Long action description
*/
function audit_db ($id, $ip, $accion, $descripcion){
require("config.php");
$today=date('Y-m-d H:i:s');
@ -110,32 +164,38 @@ function audit_db ($id, $ip, $accion, $descripcion){
$result=mysql_query($sql1);
}
// ---------------------------------------------------------------
// logon_db, update entry in logon audit
// ---------------------------------------------------------------
function logon_db($id,$ip){
/**
* Log in a user into Pandora.
*
* @param id_user User id
* @param ip Client user IP address.
*/
function logon_db ($id_user, $ip) {
require ("config.php");
audit_db($id,$ip,"Logon","Logged in");
audit_db ($id_user, $ip, "Logon", "Logged in");
// Update last registry of user to get last logon
$sql2='UPDATE tusuario fecha_registro = $today WHERE id_usuario = "$id"';
$result=mysql_query($sql2);
$sql = 'UPDATE tusuario fecha_registro = $today WHERE id_usuario = "$id_user"';
$result = mysql_query ($sql);
}
// ---------------------------------------------------------------
// logoff_db, also adds audit log
// ---------------------------------------------------------------
function logoff_db($id,$ip){
/**
* Log out a user into Pandora.
*
* @param id_user User id
* @param ip Client user IP address.
*/
function logoff_db ($id_user, $ip) {
require ("config.php");
audit_db($id,$ip,"Logoff","Logged out");
audit_db ($id_user, $ip, "Logoff", "Logged out");
}
// ---------------------------------------------------------------
// Returns profile given ID
// ---------------------------------------------------------------
/**
* Get profile name from id.
*
* @param id_profile Id profile in tperfil
*
* @return Profile name of the given id
*/
function dame_perfil ($id_profile) {
return (string) get_db_value ('name', 'tperfil', 'id_perfil', (int) $id_profile);
}
@ -210,107 +270,142 @@ function get_alerts_in_agent ($id_agent) {
return array_merge ($simple_alerts, $combined_alerts);
}
// ---------------------------------------------------------------
// Returns group given ID
// ---------------------------------------------------------------
/**
* Get a list of the reports the user can view.
*
* A user can view a report by two ways:
* - The user created the report (id_user field in treport)
* - The report is not private and the user has reading privileges on
* the group associated to the report
*
* @param $id_user User id to get the reports.
*
* @return An array with all the reports the user can view.
*/
function get_reports ($id_user) {
$user_reports = array ();
$all_reports = get_db_all_rows_in_table ('treport');
if (sizeof ($all_reports) == 0) {
return $user_reports;
}
foreach ($all_reports as $report) {
/* The report is private and it does not belong to the user */
if ($report['private'] && $report['id_user'] != $id_user)
continue;
/* Check ACL privileges on report group */
if (! give_acl ($id_user, $report['id_group'], 'AR'))
continue;
array_push ($user_reports, $report);
}
return $user_reports;
}
/**
* Get group name from group.
*
* @param id_group Id group to get the name.
*
* @return The name of the given group
*/
function dame_grupo ($id_group) {
return (string) get_db_value ('nombre', 'tgrupo', 'id_grupo', (int) $id_group);
}
// ---------------------------------------------------------------
// Returns icon name given group ID
// ---------------------------------------------------------------
/**
* Get group icon from group.
*
* @param id_group Id group to get the icon
*
* @return Icon path of the given group
*/
function dame_grupo_icono ($id_group) {
return (string) get_db_value ('icon', 'tgrupo', 'id_grupo', (int) $id_group);
}
// ---------------------------------------------------------------
// Return agent id given name of agent
// ---------------------------------------------------------------
/**
* Get agent id from an agent name.
*
* @param agent_name Agent name to get its id.
*
* @return Id from the agent of the given name.
*/
function dame_agente_id ($agent_name) {
return (int) get_db_value ('id_agente', 'tagente', 'nombre', $agent_name);
}
// ---------------------------------------------------------------
// Returns userid given name an note id
// ---------------------------------------------------------------
/**
* Get user id of a note.
*
* @param id_note Note id.
*
* @return User id of the given note.
*/
function give_note_author ($id_note) {
return (int) get_db_value ('id_usuario', 'tnota', 'id_nota', (int) $id_note);
}
// ---------------------------------------------------------------
// Returns agent id given name of agent
// ---------------------------------------------------------------
function dame_agente_modulo_id ($id_agente, $id_tipomodulo, $nombre) {
$sql = sprintf ('SELECT id_agente_modulo FROM tagente_modulo
WHERE id_agente = %d
AND id_tipo_modulo = %d AND nombre = "%s"',
$id_agent, $id_tipomodulo, $nombre);
return get_db_sql ($sql);
}
// ---------------------------------------------------------------
// Returns event description given it's id
// ---------------------------------------------------------------
/**
* Get description of an event.
*
* @param id_event Event id.
*
* @return Description of the given event.
*/
function return_event_description ($id_event) {
return (string) get_db_value ('evento', 'tevento', 'id_evento', (int) $id_event);
}
// ---------------------------------------------------------------
// Return ID_Group from an event given as id_event
// ---------------------------------------------------------------
/**
* Get group id of an event.
*
* @param id_event Event id
*
* @return Group id of the given event.
*/
function gime_idgroup_from_idevent ($id_event) {
return (int) get_db_value ('id_grupo', 'tevento', 'id_evento', (int) $id_event);
}
// ---------------------------------------------------------------
// Return module id given name of module type
// ---------------------------------------------------------------
function dame_module_id ($nombre){
return (int) get_db_value ('id_tipo', 'ttipo_modulo', 'nombre', $nombre);
}
// ---------------------------------------------------------------
// Returns agent name when given its ID
// ---------------------------------------------------------------
/**
* Get name of an agent.
*
* @param id_agente Agent id.
*
* @return Name of the given agent.
*/
function dame_nombre_agente ($id_agente) {
return (string) get_db_value ('nombre', 'tagente', 'id_agente', (int) $id_agente);
}
// ---------------------------------------------------------------
// Returns password (HASH) given user_id
// ---------------------------------------------------------------
function dame_password ($id_usuario) {
/**
* Get password of an user.
*
* @param id_usuario User id.
*
* @return Password of an user.
*/
function get_user_password ($id_usuario) {
return (string) get_db_value ('password', 'tusuario', 'id_usuario', (int) $id_usuario);
}
// ---------------------------------------------------------------
// Returns name of an alert given ID
// ---------------------------------------------------------------
/**
* Get name of an alert
*
* @param id_alert Alert id.
*
* @return Name of the alert.
*/
function dame_nombre_alerta ($id_alert) {
return (string) get_db_value ('nombre', 'talerta', 'id_alerta', (int) $id_alert);
}
// ---------------------------------------------------------------
// Returns name of a modules group
// ---------------------------------------------------------------
/**
* Get name of a module group.
*
* @param id_module_group Module group id.
*
* @return Name of the given module group.
*/
function dame_nombre_grupomodulo ($id_module_group) {
return (string) get_db_value ('name', 'tmodule_group', 'id_mg', (int) $id_module_group);
}
@ -922,11 +1017,7 @@ function agent_belong_group($id_agent, $id_group){
$child[] = $id_group;
give_groupchild ($id_group, $child);
$id_agent_group = give_group_id ($id_agent);
if (array_in($child,$id_agent_group)==1){
return 1;
} else {
return 0;
}
return in_array ($child, $id_agent_group);
}
// ---------------------------------------------------------------
@ -944,10 +1035,7 @@ function group_belong_group($id_group_a, $id_groupset){
(group_belong_group($id_group_a, $value) == 1))
return 1;
}
if (array_in ($childgroup, $id_group_a) == 1)
return 1;
else
return 0;
return in_array ($childgroup, $id_group_a);
}
// ---------------------------------------------------------------
@ -1161,6 +1249,18 @@ function give_db_value ($field, $table, $field_search, $condition) {
return get_db_value ($field, $table, $field_search, $condition);
}
function get_db_row_sql ($sql) {
$result = mysql_query ($sql);
if (! $result) {
echo '<strong>Error:</strong> get_db_row("'.$sql.'") :'. mysql_error ().'<br />';
return NULL;
}
if ($row = mysql_fetch_array ($result))
return $row;
return NULL;
}
function get_db_row ($table, $field_search, $condition) {
global $config;
@ -1173,15 +1273,7 @@ function get_db_row ($table, $field_search, $condition) {
$sql = sprintf ('SELECT * FROM %s WHERE %s = "%s"', $table, $field_search, $condition);
}
$result = mysql_query ($sql);
if (! $result) {
echo '<strong>Error:</strong> get_db_row("'.$sql.'") :'. mysql_error ().'<br />';
return NULL;
}
if ($row = mysql_fetch_array ($result))
return $row;
return NULL;
return get_db_row_sql ($sql);
}
// ---------------------------------------------------------------
@ -1376,48 +1468,91 @@ function return_coordinate_y_layoutdata ($id_layoutdata){
return (0);
}
/**
* Get the previous data to the timestamp provided.
*
* It's useful to know the first value of a module in an interval,
* since it will be the last value in the
*
* @param $id_agent_module Agent module id to look.
* @param $utimestamp The timestamp to look backwards from and get the data.
*
* @return The row of tagente_datos of the last period. NULL if there were no data.
*/
function get_previous_data ($id_agent_module, $utimestamp) {
$sql = sprintf ('SELECT * FROM tagente_datos
WHERE id_agente_modulo = %d
AND utimestamp <= %d
ORDER by utimestamp DESC LIMIT 1',
$id_agent_module, $utimestamp);
return get_db_row_sql ($sql);
}
function return_moduledata_avg_value ($id_agent_module, $period, $date = 0) {
if (! $date)
$date = time ();
$datelimit = $date - $period; // limit date
$id_agent = get_db_value ("id_agente", "tagente_modulo", "id_agente_modulo", $id_agent_module);
$sql = sprintf ("SELECT AVG(datos) FROM tagente_datos
WHERE id_agente = %d AND id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d",
$id_agent, $id_agent_module, $datelimit, $date);
return (float) get_db_sql ($sql);
$datelimit = $date - $period;
$sql = sprintf ("SELECT SUM(datos), COUNT(*) FROM tagente_datos
WHERE id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d
ORDER BY utimestamp ASC",
$id_agent_module, $datelimit, $date);
$values = get_db_row_sql ($sql);
$sum = (float) $values[0];
$total = (int) $values[1];
/* Get also the previous data before the selected interval. */
$previous_data = get_previous_data ($id_agent_module, $datelimit);
if ($previous_data)
return ($previous_data['datos'] + $sum) / ($total + 1);
return $sum / $total;
}
function return_moduledata_max_value ($id_agent_module, $period, $date = 0) {
if (! $date)
$date = time ();
$datelimit = $date - $period; // limit date
$id_agent = get_db_value ("id_agente", "tagente_modulo", "id_agente_modulo", $id_agent_module);
$datelimit = $date - $period;
$sql = sprintf ("SELECT MAX(datos) FROM tagente_datos
WHERE id_agente = %d AND id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d",
$id_agent, $id_agent_module, $datelimit, $date);
return (float) get_db_sql ($sql);
WHERE id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d
ORDER BY utimestamp ASC",
$id_agent_module, $datelimit, $date);
$max = (float) get_db_sql ($sql);
/* Get also the previous report before the selected interval. */
$previous_data = get_previous_data ($id_agent_module, $datelimit);
if ($previous_data)
return max ($previous_data['datos'], $max);
return max ($previous_data, $max);
}
function return_moduledata_min_value ($id_agent_module, $period, $date = 0) {
if (! $date)
$date = time ();
$datelimit = $date - $period; // limit date
$id_agent = get_db_value ("id_agente", "tagente_modulo", "id_agente_modulo", $id_agent_module);
$datelimit = $date - $period;
$sql = sprintf ("SELECT MIN(datos) FROM tagente_datos
WHERE id_agente = %d AND id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d",
$id_agent, $id_agent_module, $datelimit, $date);
return (float) get_db_sql ($sql);
WHERE id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d
ORDER BY utimestamp ASC",
$id_agent_module, $datelimit, $date);
$min = (float) get_db_sql ($sql);
/* Get also the previous data before the selected interval. */
$previous_data = get_previous_data ($id_agent_module, $datelimit);
if ($previous_data)
return min ($previous_data['datos'], $min);
return $min;
}
function return_moduledata_sum_value ($id_agent_module, $period, $date = 0) {
if (! $date)
$date = time ();
$datelimit = $date - $period; // limit date
$agent_module = get_db_row ('tagente_modulo', 'id_agente_modulo', $id_agent_module);
$module_name = get_db_value ('nombre', 'ttipo_modulo', 'id_tipo', $agent_module['id_tipo_modulo']);
if (is_module_data_string ($module_name)) {
@ -1427,10 +1562,17 @@ function return_moduledata_sum_value ($id_agent_module, $period, $date = 0) {
// Get the whole interval of data
$sql = sprintf ('SELECT * FROM tagente_datos
WHERE id_agente = %d AND id_agente_modulo = %d
WHERE id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d',
$agent_module['id_agente'], $id_agent_module, $datelimit, $date);
$id_agent_module, $datelimit, $date);
$datas = get_db_all_rows_sqlfree ($sql);
/* Get also the previous data before the selected interval. */
$previous_data = get_previous_data ($id_agent_module, $datelimit);
if ($previous_data) {
/* Add data to the beginning */
array_unshift ($datas, $previous_data);
}
$last_data = "";
$total_badtime = 0;
$interval_begin = 0;
@ -1496,8 +1638,8 @@ function show_alert_row_mini ($id_combined_alert){
global $lang_label;
$color=1;
$sql_com = "SELECT talerta_agente_modulo.*, tcompound_alert.operation FROM talerta_agente_modulo, tcompound_alert WHERE tcompound_alert.id_aam = talerta_agente_modulo.id_aam AND tcompound_alert.id = ".$id_combined_alert;
$result_com = mysql_query ($sql_com);
$sql = "SELECT talerta_agente_modulo.*, tcompound_alert.operation FROM talerta_agente_modulo, tcompound_alert WHERE tcompound_alert.id_aam = talerta_agente_modulo.id_aam AND tcompound_alert.id = ".$id_combined_alert;
$result = mysql_query ($sql);
echo "<table width=400 cellpadding=2 cellspacing=2 class='databox'>";
echo "<th>".lang_string("Name");
echo "<th>".lang_string("Oper");
@ -1509,7 +1651,7 @@ function show_alert_row_mini ($id_combined_alert){
echo "<th>".lang_string("MinMax.Al");
echo "<th>".lang_string("Days");
echo "<th>".lang_string("Fired");
while ($row2=mysql_fetch_array($result_com)){
while ($row2 = mysql_fetch_array ($result)) {
if ($color == 1) {
$tdcolor = "datos";
@ -1599,6 +1741,7 @@ function show_alert_row_mini ($id_combined_alert){
}
echo "</table>";
}
function smal_event_table ($filter = "", $limit = 10, $width = 440) {
global $config;
global $lang_label;
@ -1608,12 +1751,12 @@ function smal_event_table ($filter = "", $limit = 10, $width=440){
echo "<tr>";
echo "<th colspan=6>".lang_string("Latest events");
echo "<tr>";
echo "<td class='datos3 f9'>".lang_string ("St")."</th>";
echo "<td class='datos3 f9'>".lang_string ("Type")."</th>";
echo "<td class='datos3 f9'>".$lang_label["event_name"]."</th>";
echo "<td class='datos3 f9'>".$lang_label["agent_name"]."</th>";
echo "<td class='datos3 f9'>".$lang_label["id_user"]."</th>";
echo "<td class='datos3 f9'>".$lang_label["timestamp"]."</th>";
echo "<th class='datos3 f9'>".lang_string ("St")."</th>";
echo "<th class='datos3 f9'>".lang_string ("Type")."</th>";
echo "<th class='datos3 f9'>".$lang_label["event_name"]."</th>";
echo "<th class='datos3 f9'>".$lang_label["agent_name"]."</th>";
echo "<th class='datos3 f9'>".$lang_label["id_user"]."</th>";
echo "<th class='datos3 f9'>".$lang_label["timestamp"]."</th>";
$result2=mysql_query($sql2);
while ($row2=mysql_fetch_array($result2)){
$id_grupo = $row2["id_grupo"];
@ -1671,9 +1814,6 @@ function smal_event_table ($filter = "", $limit = 10, $width=440){
break;
case "recon_host_detected";
echo "<img src='images/network.png'>";
break;
case "new_agent":
echo "<img src='images/wand.png'>";
break;
}

View File

@ -22,37 +22,58 @@ function return_module_SLA ($id_agent_module, $period, $min_value, $max_value, $
$date = time ();
$datelimit = $date - $period; // limit date
$id_agent = give_db_value ('id_agente', 'tagente_modulo', 'id_agente_modulo', $id_agent_module);
// Get the whole interval of data
/* Get all the data in the interval */
$sql = sprintf ('SELECT * FROM tagente_datos
WHERE id_agente = %d AND id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d',
AND utimestamp > %d AND utimestamp <= %d
ORDER BY utimestamp ASC',
$id_agent, $id_agent_module, $datelimit, $date);
$result = mysql_query ($sql);
$datas = get_db_all_rows_sqlfree ($sql);
$last_data = "";
$total_badtime = 0;
$interval_begin = 0;
$interval_last = 0;
$interval_last = $date;
$previous_data_timestamp = 0;
if (! $result) {
return 100;
/* Get also the previous data before the selected interval. */
$previous_data = get_previous_data ($id_agent_module, $datelimit);
if ($previous_data) {
/* Add data to the beginning */
array_unshift ($datas, $previous_data);
$previous_data_timestamp = $previous_data['utimestamp'];
}
while ($row = mysql_fetch_array ($result)) {
if ( ($row["datos"] > $max_value) || ($row["datos"] < $min_value)) {
if (sizeof ($datas) == 0) {
return false;
}
foreach ($datas as $data) {
if ($data["datos"] > $max_value || $data["datos"] < $min_value) {
if ($interval_begin == 0) {
$interval_begin = $row["utimestamp"];
$interval_begin = $data["utimestamp"];
}
} elseif ($interval_begin != 0) {
// Here ends interval with data outside valid values,
// Need to add this time to counter
$interval_last = $row["utimestamp"];
$interval_last = $data["utimestamp"];
$temp_time = $interval_last - $interval_begin;
$total_badtime = $total_badtime + $temp_time;
$total_badtime += $temp_time;
$interval_begin = 0;
$interval_last = 0;
}
}
/* Check the last interval, if any */
if ($interval_begin != 0) {
/* The last time was the time of the previous data in the
interval. That means that in all the interval, the data was
not between the expected values, so the SLA is zero. */
if ($interval_begin = $previous_data_timestamp)
return 0;
$total_badtime += $interval_last - $interval_begin;
}
$result = 100 - ($total_badtime / $period) * 100;
return $result;
return max ($result, 0);
}
function general_stats ( $id_user, $id_group = 0) {

View File

@ -193,13 +193,15 @@ require "include/functions_db.php";
}
$pagina = "";
if (isset ($_GET["sec2"])){
$sec2 = parametro_limpio ($_GET["sec2"]);
$sec2 = get_parameter_get ('sec2');
$sec2 = parameter_extra_clean ($sec2);
$pagina = $sec2;
} else
$sec2 = "";
if (isset ($_GET["sec"])){
$sec = parametro_limpio ($_GET["sec"]);
$sec = get_parameter_get ('sec');
$sec = parameter_extra_clean ($sec);
$pagina = $sec2;
}
else

View File

@ -53,7 +53,7 @@ if (comprueba_login() == 0) {
if (give_acl($id_usuario, $id_grupo, "AR")==1){
// Check for validate alert request
$validate_alert = give_parameter_get ("validate_alert");
$validate_alert = get_parameter ("validate_alert");
if ($validate_alert != ""){
if (give_acl($id_usuario, $id_grupo, "AW")==1){
$alert_row = get_db_row ("talerta_agente_modulo", "id_aam", $validate_alert);

View File

@ -18,20 +18,16 @@
<script language="JavaScript" type="text/javascript">
<!--
function CheckAll()
{
for (var i=0;i<document.eventtable.elements.length;i++)
{
function CheckAll () {
for (var i = 0; i < document.eventtable.elements.length; i++) {
var e = document.eventtable.elements[i];
if (e.type == 'checkbox' && e.name != 'allbox')
e.checked = 1;
}
}
function OpConfirm(text, conf)
{
for (var i=0;i<document.pageform.elements.length;i++)
{
function OpConfirm (text, conf) {
for (var i = 0; i < document.pageform.elements.length; i++) {
var e = document.pageform.elements[i];
if (e.type == 'checkbox' && e.name != 'allbox' && e.checked == 1) {
if (conf) {
@ -224,7 +220,8 @@ echo "<tr>";
// Severity
echo "<td>".lang_string ("Severity")."</td>";
echo "<td>";
echo form_priority ($severity, "severity", 1);
print_select (get_priorities (), "severity", $severity, '', 'all', '-1');
// Status
echo "<td>".lang_string ("Event status")."</td>";

View File

@ -60,17 +60,17 @@ $resultado3=mysql_query($sql3);
if (isset($_GET["nuevo_mensaje"])){
// Create message
$usuario_destino = give_parameter_post ("u_destino");
$subject = give_parameter_post ("subject");
$mensaje = give_parameter_post ("mensaje");
$usuario_destino = get_parameter ("u_destino");
$subject = get_parameter ("subject");
$mensaje = get_parameter ("mensaje");
create_message($iduser, $usuario_destino, $subject, $mensaje);
}
if (isset($_GET["nuevo_mensaje_g"])){
// Create message to groups
$grupo_destino = give_parameter_post ("g_destino");
$subject = give_parameter_post ("subject");
$mensaje = give_parameter_post ("mensaje");
$grupo_destino = get_parameter ("g_destino");
$subject = get_parameter ("subject");
$mensaje = get_parameter ("mensaje");
$sql= 'SELECT id_usuario FROM tusuario_perfil WHERE id_grupo ='. $grupo_destino;
$result = mysql_query($sql);

View File

@ -29,48 +29,38 @@ if (comprueba_login() != 0) {
//echo "SLA for Tato: %".return_module_SLA (50, 604800, 1, 1);
echo "<h2>".$lang_label["reporting"]." &gt; ";
echo $lang_label["custom_reporting"]."</h2>";
echo "<h2>".lang_string ('reporting')." &gt; ";
echo lang_string ('custom_reporting')."</h2>";
$color=1;
$sql="SELECT * FROM treport";
$res=mysql_query($sql);
if (mysql_num_rows($res)) {
echo "<table width='580' cellpadding=4 cellpadding=4 class='databox'>";
echo "<tr>
<th>".$lang_label["report_name"]."</th>
<th>".$lang_label["description"]."</th>
<th>HTML</th>
<th>PDF</th>
</tr>";
$reports = get_reports ($config['id_user']);
while ($row = mysql_fetch_array($res)){
if (($row["private"]==0) || ($row["id_user"] == $id_user)){
// Calculate table line color
if ($color == 1){
$tdcolor = "datos";
$color = 0;
}
else {
$tdcolor = "datos2";
$color = 1;
}
echo "<tr>";
echo "<td valign='top' class='$tdcolor'>".$row["name"]."</td>";
echo "<td class='$tdcolor'>".$row["description"]."</td>";
$id_report = $row["id_report"];
echo "<td valign='middle' class='$tdcolor' align='center'>
<a href='index.php?sec=reporting&sec2=operation/reporting/reporting_viewer&id=$id_report'>
<img src='images/reporting.png'></a>
</td>";
echo "<td valign='middle' class='$tdcolor' align='center'><a target='_new' href='operation/reporting/reporting_viewer_pdf.php?id=$id_report&rtype=general'><img src='images/pdf.png'></a></td>'";
echo "</tr>";
}
}
echo "</table>";
} else {
if (sizeof ($reports) == 0) {
echo "<div class='nf'>".$lang_label["no_reporting_def"]."</div>";
return;
}
$table->width = '580px';
$table->head = array ();
$table->head[0] = lang_string ('report_name');
$table->head[1] = lang_string ('description');
$table->head[2] = lang_string ('HTML');
$table->head[3] = lang_string ('PDF');
$table->align = array ();
$table->align[2] = 'center';
$table->align[3] = 'center';
$table->data = array ();
foreach ($reports as $report) {
$data = array ();
$data[0] = $report['name'];
$data[1] = $report['description'];
$data[2] = '<a href="index.php?sec=reporting&sec2=operation/reporting/reporting_viewer&id='.$report['id_report'].'">
<img src="images/reporting.png"></a>';
$data[3] = '<a href="operation/reporting/reporting_viewer_pdf.php?id='.$report['id_report'].'&rtype=general"
target="_new"><img src="images/pdf.png"></a>';
array_push ($table->data, $data);
}
print_table ($table);
?>

View File

@ -184,7 +184,8 @@ foreach ($contents as $content) {
$n = array_push ($table->data, $data);
$table->rowclass[$n - 1] = 'datos3';
$slas = get_db_all_rows_field_filter ('treport_content_sla_combined', 'id_report_content', $content['id_rc']);
$slas = get_db_all_rows_field_filter ('treport_content_sla_combined',
'id_report_content', $content['id_rc']);
if (sizeof ($slas) == 0) {
$data = array ();
$table->colspan[$n][0] = 3;
@ -193,21 +194,28 @@ foreach ($contents as $content) {
}
foreach ($slas as $sla) {
$data = array ();
$sla_result = format_numeric (return_module_SLA ($sla['id_agent_module'], $content['period'],
$sla['sla_min'], $sla['sla_max'], $datetime));
$table->colspan[$n][0] = 2;
$table->data[0] = '<span style="font-size: 0.6em">';
$table->data[0] .= lang_string ('sla_max')." : ".$sla['sla_max']."<br>";
$table->data[0] .= lang_string ('sla_min')." : ".$sla['sla_min']."<br>";
$table->data[0] .= lang_string ('sla_limit')." : ".$sla['sla_limit']."<br>";
$table->data[0] .= "</span>";
if ($sla_result >= $sla['sla_limit'])
$table->data[1] = "<span style='font: bold 3em Arial, Sans-serif; color: #000000;'>";
$table->colspan[$n][0] = 2;
$data[0] = '<span style="font-size: 0.6em">';
$data[0] .= lang_string ('sla_max')." : ".$sla['sla_max']."<br>";
$data[0] .= lang_string ('sla_min')." : ".$sla['sla_min']."<br>";
$data[0] .= lang_string ('sla_limit')." : ".$sla['sla_limit']."<br>";
$data[0] .= "</span>";
$sla_value = return_module_SLA ($sla['id_agent_module'], $content['period'],
$sla['sla_min'], $sla['sla_max'], $datetime);
if ($sla_value === false) {
$data[1] = '<span style="font: bold 3em Arial, Sans-serif; color: #0000FF;">';
$data[1] .= lang_string ('unknown');
} else {
if ($sla_value >= $sla['sla_limit'])
$data[1] = '<span style="font: bold 3em Arial, Sans-serif; color: #000000;">';
else
$table->data[1] = "<span style='font: bold 3em Arial, Sans-serif; color: #ff0000;'>";
$table->data[1] .= $sla_result. " %";
$table->data[1] .= "</span>";
$data[1] = '<span style="font: bold 3em Arial, Sans-serif; color: #ff0000;">';
$data[1] .= format_numeric ($sla_value). " %";
}
$data[1] .= "</span>";
$n = array_push ($table->data, $data);
}

View File

@ -51,7 +51,7 @@ if ((give_acl($id_user,0,"AR") != 1 ) AND (dame_admin($id_user)!=1)) {
}
$id_report = give_parameter_get ( 'id', $default = "");
$id_report = get_parameter ('id');
if ($id_report == ""){
audit_db($id_user,$REMOTE_ADDR, "HACK Attempt","Trying to access graph viewer withoud ID");
include ("general/noaccess.php");

View File

@ -20,7 +20,10 @@
// Load global vars
require("include/config.php");
if (give_acl($id_user, 0, "LW")==1) {
if (! give_acl($id_user, 0, "LW")) {
audit_db($id_user,$REMOTE_ADDR, "ACL Violation","Trying to access SNMP Alert Management");
require ("general/noaccess.php");
}
// Variable init
$view_alert=1;
$alert_add = 0;
@ -208,8 +211,7 @@ if (give_acl($id_user, 0, "LW")==1) {
if ($time_threshold != ""){
echo "<option value='".$time_threshold."'>".human_time_description($time_threshold)."</option>";
}
echo '
<option value=300>5 Min.</option>
echo '<option value=300>5 Min.</option>
<option value=600>10 Min.</option>
<option value=900>15 Min.</option>
<option value=1800>30 Min.</option>
@ -355,11 +357,6 @@ if (give_acl($id_user, 0, "LW")==1) {
echo "</form>";
} // End of view snmp alert
}
} else {
audit_db($id_user,$REMOTE_ADDR, "ACL Violation","Trying to access SNMP Alert Management");
require ("general/noaccess.php");
}
?>
<tr>
</table>

View File

@ -61,7 +61,7 @@ if (comprueba_login() == 0) {
//echo "<br>DEBUG for ".$nombre;
//echo "<br>Comments:".$comentarios;
$comentarios = entrada_limpia($_POST["comentarios"]);
if (dame_password($nombre)!=$pass1){
if (get_user_password($nombre)!=$pass1){
// Only when change password
$pass1=md5($pass1);
$sql = "UPDATE tusuario SET nombre_real = '".$nombre_real."', password = '".$pass1."', telefono ='".$telefono."', direccion ='".$direccion." ', comentarios = '".$comentarios."' WHERE id_usuario = '".$nombre."'";

View File

@ -1363,7 +1363,6 @@ function graph_event_module ($width = 300, $height = 200, $id_agent) {
}
}
$max_items = 6;
// Take only the first x items
if (sizeof($data) >= $max_items) {