diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 1469bfacf2..74a5918317 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,12 @@ +2007-03-06 Sancho Lerena + + * include/functions*.php: Some reorganization, moved some funtions + from functions.php. Added recursive functions to implement group + hiearchy (group_belong_group, agent_belong_group). + + * godmode/agentes/module_manager.php, configurar_agente.php: + Module edition/add now works :-) + 2007-03-02 Sancho Lerena * Massive commit. Updated almost every file for agent diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 2f7799b1f8..927b772b91 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -391,6 +391,8 @@ if ((isset($_POST["update_module"])) || (isset($_POST["insert_module"]))) { if (isset($_POST["module_interval"])) $module_interval = entrada_limpia($_POST["module_interval"]); } + + // MODULE UPDATE // ================= if ((isset($_POST["update_module"])) && (!isset($_POST["oid"]))){ // if modified something diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php index db5ceda261..8030004743 100644 --- a/pandora_console/godmode/agentes/module_manager.php +++ b/pandora_console/godmode/agentes/module_manager.php @@ -97,7 +97,7 @@ function type_change() document.modulo.modulo_min.style.background="#ddd"; document.modulo.modulo_min.disabled=true; } - + // type 12 - UDP if (document.modulo.tipo.value == 12){ document.modulo.snmp_oid.style.background="#ddd"; @@ -212,24 +212,19 @@ if ( $creacion_agente != 1) { echo "
No modules
"; } -// ==================================================================================== -// Module Creation / Update form -// ==================================================================================== -else { - echo '
'; - if ($update_module == "1"){ - echo ''; - echo ''; - } - else { // Create - echo ''; - // Default values for new modules - if ($ip_target == ""){ - $ip_target = $direccion_agente; - $snmp_community = "public"; - $module_interval = $intervalo; - } +echo ''; +if ($update_module == "1"){ + echo ''; + echo ''; +} +else { // Create + echo ''; + // Default values for new modules + if ($ip_target == ""){ + $ip_target = $direccion_agente; + $snmp_community = "public"; + $module_interval = $intervalo; } } diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 5988790341..0e074bfd33 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -31,131 +31,18 @@ function midebug($var, $mesg){ } // --------------------------------------------------------------- -// audit_db, update audit log -// --------------------------------------------------------------- - -function audit_db($id,$ip,$accion,$descripcion){ - require("config.php"); - $today=date('Y-m-d H:i:s'); - $sql1='INSERT INTO tsesion (ID_usuario, accion, fecha, IP_origen,descripcion) VALUES ("'.$id.'","'.$accion.'","'.$today.'","'.$ip.'","'.$descripcion.'")'; - $result=mysql_query($sql1); -} - - -// --------------------------------------------------------------- -// logon_db, update entry in logon audit -// --------------------------------------------------------------- - -function logon_db($id,$ip){ - require("config.php"); - audit_db($id,$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); -} - -// --------------------------------------------------------------- -// logoff_db, also adds audit log -// --------------------------------------------------------------- - -function logoff_db($id,$ip){ - require("config.php"); - audit_db($id,$ip,"Logoff","Logged out"); -} - -// --------------------------------------------------------------- -// Return email of a user given ID -// --------------------------------------------------------------- - -function dame_email($id){ - require("config.php"); - $query1="SELECT * FROM tusuario WHERE id_usuario =".$id; - $resq1=mysql_query($query1); - $rowdup=mysql_fetch_array($resq1); - $nombre=$rowdup["direccion"]; - return $nombre; -} - - -// --------------------------------------------------------------- -// Gives error message and stops execution if user -//doesn't have an open session and this session is from an valid user -// --------------------------------------------------------------- - -function comprueba_login() { - if (isset($_SESSION["id_usuario"])){ - $id = $_SESSION["id_usuario"]; - require("config.php"); - $query1="SELECT * FROM tusuario WHERE id_usuario = '".$id."'"; - $resq1=mysql_query($query1); - $rowdup=mysql_fetch_array($resq1); - $nombre=$rowdup["id_usuario"]; - if ( $id == $nombre ){ - return 0 ; - } - } - require("general/noaccess.php"); - return 1; -} - -// --------------------------------------------------------------- -// Gives error message and stops execution if user -//doesn't have an open session and this session is from an administrator -// --------------------------------------------------------------- - -function comprueba_admin() { - if (isset($_SESSION["id_usuario"])){ - $iduser=$_SESSION['id_usuario']; - if (dame_admin($iduser)==1){ - $id = $_SESSION["id_usuario"]; - require("config.php"); - $query1="SELECT * FROM tusuario WHERE id_usuario = '".$id."'"; - $resq1=mysql_query($query1); - $rowdup=mysql_fetch_array($resq1); - $nombre=$rowdup["id_usuario"]; - $nivel=$rowdup["nivel"]; - if (( $id == $nombre) and ($nivel ==1)) - return 0; - } - } - require("../general/no_access.php"); - return 1; -} - -// --------------------------------------------------------------- -// Returns number of alerts fired by this agent +// array_in +// Search "item" in a given array, return 1 if exists, 0 if not // --------------------------------------------------------------- -function check_alert_fired($id_agente){ - require("config.php"); - $query1="SELECT * FROM tagente_modulo WHERE id_agente ='".$id_agente."'"; - $rowdup=mysql_query($query1); - while ($data=mysql_fetch_array($rowdup)){ - $query2="SELECT COUNT(*) FROM talerta_agente_modulo WHERE times_fired > 0 AND id_agente_modulo =".$data["id_agente_modulo"]; - $rowdup2=mysql_query($query2); - $data2=mysql_fetch_array($rowdup2); - if ($data2[0] > 0) - return 1; - } - return 0; -} - -// --------------------------------------------------------------- -// 0 if it doesn't exist, 1 if it does, when given email -// --------------------------------------------------------------- - -function existe($id){ - require("config.php"); - $query1="SELECT * FROM tusuario WHERE id_usuario = '".$id."'"; - $resq1=mysql_query($query1); - if ($resq1 != 0) { - if ($rowdup=mysql_fetch_array($resq1)){ - return 1; +function array_in($exampleArray, $item){ + $result = 0; + foreach ($exampleArray as $key => $value){ + if ($value == $item){ + $result = 1; } - else { - return 0; - } - } else { return 0 ; } + } + return $result; } diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index cd00ddba1a..fd4946647a 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -70,6 +70,38 @@ function give_acl($id_user, $id_group, $access){ return $result; } +// --------------------------------------------------------------- +// audit_db, update audit log +// --------------------------------------------------------------- + +function audit_db($id,$ip,$accion,$descripcion){ + require("config.php"); + $today=date('Y-m-d H:i:s'); + $sql1='INSERT INTO tsesion (ID_usuario, accion, fecha, IP_origen,descripcion) VALUES ("'.$id.'","'.$accion.'","'.$today.'","'.$ip.'","'.$descripcion.'")'; + $result=mysql_query($sql1); +} + + +// --------------------------------------------------------------- +// logon_db, update entry in logon audit +// --------------------------------------------------------------- + +function logon_db($id,$ip){ + require("config.php"); + audit_db($id,$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); +} + +// --------------------------------------------------------------- +// logoff_db, also adds audit log +// --------------------------------------------------------------- + +function logoff_db($id,$ip){ + require("config.php"); + audit_db($id,$ip,"Logoff","Logged out"); +} // --------------------------------------------------------------- // Returns profile given ID @@ -527,6 +559,20 @@ function dame_so_icon($id){ return $pro; } +// --------------------------------------------------------------- +// Return email of a user given ID +// --------------------------------------------------------------- + +function dame_email($id){ + require("config.php"); + $query1="SELECT * FROM tusuario WHERE id_usuario =".$id; + $resq1=mysql_query($query1); + $rowdup=mysql_fetch_array($resq1); + $nombre=$rowdup["direccion"]; + return $nombre; +} + + // --------------------------------------------------------------- // Returns Admin value (0 no admin, 1 admin) // --------------------------------------------------------------- @@ -540,6 +586,87 @@ function dame_admin($id){ return $admin; } +// --------------------------------------------------------------- +// Gives error message and stops execution if user +//doesn't have an open session and this session is from an valid user +// --------------------------------------------------------------- + +function comprueba_login() { + if (isset($_SESSION["id_usuario"])){ + $id = $_SESSION["id_usuario"]; + require("config.php"); + $query1="SELECT * FROM tusuario WHERE id_usuario = '".$id."'"; + $resq1=mysql_query($query1); + $rowdup=mysql_fetch_array($resq1); + $nombre=$rowdup["id_usuario"]; + if ( $id == $nombre ){ + return 0 ; + } + } + require("general/noaccess.php"); + return 1; +} + +// --------------------------------------------------------------- +// Gives error message and stops execution if user +//doesn't have an open session and this session is from an administrator +// --------------------------------------------------------------- + +function comprueba_admin() { + if (isset($_SESSION["id_usuario"])){ + $iduser=$_SESSION['id_usuario']; + if (dame_admin($iduser)==1){ + $id = $_SESSION["id_usuario"]; + require("config.php"); + $query1="SELECT * FROM tusuario WHERE id_usuario = '".$id."'"; + $resq1=mysql_query($query1); + $rowdup=mysql_fetch_array($resq1); + $nombre=$rowdup["id_usuario"]; + $nivel=$rowdup["nivel"]; + if (( $id == $nombre) and ($nivel ==1)) + return 0; + } + } + require("../general/no_access.php"); + return 1; +} + + +// --------------------------------------------------------------- +// Returns number of alerts fired by this agent +// --------------------------------------------------------------- + +function check_alert_fired($id_agente){ + require("config.php"); + $query1="SELECT * FROM tagente_modulo WHERE id_agente ='".$id_agente."'"; + $rowdup=mysql_query($query1); + while ($data=mysql_fetch_array($rowdup)){ + $query2="SELECT COUNT(*) FROM talerta_agente_modulo WHERE times_fired > 0 AND id_agente_modulo =".$data["id_agente_modulo"]; + $rowdup2=mysql_query($query2); + $data2=mysql_fetch_array($rowdup2); + if ($data2[0] > 0) + return 1; + } + return 0; +} + +// --------------------------------------------------------------- +// 0 if it doesn't exist, 1 if it does, when given email +// --------------------------------------------------------------- + +function existe($id){ + require("config.php"); + $query1="SELECT * FROM tusuario WHERE id_usuario = '".$id."'"; + $resq1=mysql_query($query1); + if ($resq1 != 0) { + if ($rowdup=mysql_fetch_array($resq1)){ + return 1; + } + else { + return 0; + } + } else { return 0 ; } +} // --------------------------------------------------------------- // event_insert - Insert event in eventable, using Id_grupo, Id_agente and Evento @@ -669,4 +796,56 @@ function show_icon_type($id_tipo){ return $pro; } +// --------------------------------------------------------------- +// Return all childs groups of a given id_group inside array $child +// --------------------------------------------------------------- + +function give_groupchild($id_group, &$child){ + // Conexion con la base Datos + $query1="select * from tgrupo where parent = ".$id_group; + $resq1=mysql_query($query1); + while ($resq1 != NULL && $rowdup=mysql_fetch_array($resq1)){ + $child[]=$rowdup["id_grupo"]; + } +} + +// --------------------------------------------------------------- +// Return true (1) if agent belongs to given group or one of this childs +// --------------------------------------------------------------- + +function agent_belong_group($id_agent, $id_group){ + // Conexion con la base Datos + $child[] = ""; + $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 true (1) if given group (a) belongs to given groupset +// --------------------------------------------------------------- + +function group_belong_group($id_group_a, $id_groupset){ + // Conexion con la base Datos + $childgroup[] = ""; + if ($id_group_a == $id_groupset) + return 1; + give_groupchild($id_groupset, $childgroup); + foreach ($childgroup as $key => $value){ + if (($value != $id_groupset) AND + (group_belong_group($id_group_a, $value) == 1)) + return 1; + } + if (array_in ($childgroup, $id_group_a) == 1) + return 1; + else + return 0; +} + + ?>