mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-27 07:44:35 +02:00
2007-03-06 Sancho Lerena <slerena@artica.es>
* 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 :-) git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@389 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
4f827de5f0
commit
f5f53e4a95
@ -1,3 +1,12 @@
|
|||||||
|
2007-03-06 Sancho Lerena <slerena@artica.es>
|
||||||
|
|
||||||
|
* 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 <slerena@artica.es>
|
2007-03-02 Sancho Lerena <slerena@artica.es>
|
||||||
|
|
||||||
* Massive commit. Updated almost every file for agent
|
* Massive commit. Updated almost every file for agent
|
||||||
|
@ -391,6 +391,8 @@ if ((isset($_POST["update_module"])) || (isset($_POST["insert_module"]))) {
|
|||||||
if (isset($_POST["module_interval"]))
|
if (isset($_POST["module_interval"]))
|
||||||
$module_interval = entrada_limpia($_POST["module_interval"]);
|
$module_interval = entrada_limpia($_POST["module_interval"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MODULE UPDATE
|
// MODULE UPDATE
|
||||||
// =================
|
// =================
|
||||||
if ((isset($_POST["update_module"])) && (!isset($_POST["oid"]))){ // if modified something
|
if ((isset($_POST["update_module"])) && (!isset($_POST["oid"]))){ // if modified something
|
||||||
|
@ -97,7 +97,7 @@ function type_change()
|
|||||||
document.modulo.modulo_min.style.background="#ddd";
|
document.modulo.modulo_min.style.background="#ddd";
|
||||||
document.modulo.modulo_min.disabled=true;
|
document.modulo.modulo_min.disabled=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// type 12 - UDP
|
// type 12 - UDP
|
||||||
if (document.modulo.tipo.value == 12){
|
if (document.modulo.tipo.value == 12){
|
||||||
document.modulo.snmp_oid.style.background="#ddd";
|
document.modulo.snmp_oid.style.background="#ddd";
|
||||||
@ -212,24 +212,19 @@ if ( $creacion_agente != 1) {
|
|||||||
echo "<div class='nf'>No modules</div>";
|
echo "<div class='nf'>No modules</div>";
|
||||||
|
|
||||||
}
|
}
|
||||||
// ====================================================================================
|
|
||||||
// Module Creation / Update form
|
|
||||||
// ====================================================================================
|
|
||||||
else {
|
|
||||||
|
|
||||||
echo '<form name="modulo" method="post" action="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=module&id_agente='.$id_agente.'">';
|
echo '<form name="modulo" method="post" action="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=module&id_agente='.$id_agente.'">';
|
||||||
if ($update_module == "1"){
|
if ($update_module == "1"){
|
||||||
echo '<input type="hidden" name="update_module" value=1>';
|
echo '<input type="hidden" name="update_module" value=1>';
|
||||||
echo '<input type="hidden" name="id_agente_modulo" value="'.$id_agente_modulo.'">';
|
echo '<input type="hidden" name="id_agente_modulo" value="'.$id_agente_modulo.'">';
|
||||||
}
|
}
|
||||||
else { // Create
|
else { // Create
|
||||||
echo '<input type="hidden" name="insert_module" value=1>';
|
echo '<input type="hidden" name="insert_module" value=1>';
|
||||||
// Default values for new modules
|
// Default values for new modules
|
||||||
if ($ip_target == ""){
|
if ($ip_target == ""){
|
||||||
$ip_target = $direccion_agente;
|
$ip_target = $direccion_agente;
|
||||||
$snmp_community = "public";
|
$snmp_community = "public";
|
||||||
$module_interval = $intervalo;
|
$module_interval = $intervalo;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,131 +31,18 @@ function midebug($var, $mesg){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
// audit_db, update audit log
|
// array_in
|
||||||
// ---------------------------------------------------------------
|
// Search "item" in a given array, return 1 if exists, 0 if not
|
||||||
|
|
||||||
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
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
|
|
||||||
function check_alert_fired($id_agente){
|
function array_in($exampleArray, $item){
|
||||||
require("config.php");
|
$result = 0;
|
||||||
$query1="SELECT * FROM tagente_modulo WHERE id_agente ='".$id_agente."'";
|
foreach ($exampleArray as $key => $value){
|
||||||
$rowdup=mysql_query($query1);
|
if ($value == $item){
|
||||||
while ($data=mysql_fetch_array($rowdup)){
|
$result = 1;
|
||||||
$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;
|
return $result;
|
||||||
}
|
|
||||||
} else { return 0 ; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,6 +70,38 @@ function give_acl($id_user, $id_group, $access){
|
|||||||
return $result;
|
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
|
// Returns profile given ID
|
||||||
@ -527,6 +559,20 @@ function dame_so_icon($id){
|
|||||||
return $pro;
|
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)
|
// Returns Admin value (0 no admin, 1 admin)
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
@ -540,6 +586,87 @@ function dame_admin($id){
|
|||||||
return $admin;
|
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
|
// 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 $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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user