2006-03-27 05:37:27 +02:00
|
|
|
<?php
|
|
|
|
|
2007-03-02 18:56:07 +01:00
|
|
|
// Pandora FMS - the Free monitoring system
|
|
|
|
// ========================================
|
2007-03-12 18:58:52 +01:00
|
|
|
// Copyright (c) 2004-2007 Sancho Lerena, slerena@gmail.com
|
|
|
|
// Main PHP/SQL code development and project architecture and management
|
2007-03-02 18:56:07 +01:00
|
|
|
// Copyright (c) 2004-2007 Raul Mateos Martin, raulofpandora@gmail.com
|
2007-03-12 18:58:52 +01:00
|
|
|
// CSS and some PHP additions
|
2007-03-02 18:56:07 +01:00
|
|
|
// Copyright (c) 2006-2007 Jonathan Barajas, jonathan.barajas[AT]gmail[DOT]com
|
2007-03-12 18:58:52 +01:00
|
|
|
// Javascript Active Console code.
|
|
|
|
// Copyright (c) 2006 Jose Navarro <contacto@indiseg.net>
|
|
|
|
// Additions to Pandora FMS 1.2 graph code and new XML reporting template management
|
|
|
|
// Copyright (c) 2005-2007 Artica Soluciones Tecnologicas, info@artica.es
|
|
|
|
//
|
2006-07-11 16:14:09 +02:00
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
2007-03-12 18:58:52 +01:00
|
|
|
// as published by the Free Software Foundation; version 2
|
2006-07-11 16:14:09 +02:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2006-03-27 05:37:27 +02:00
|
|
|
// ---------------------------------------------------------------
|
|
|
|
// input: var, string.
|
|
|
|
// mesg, mesage to show, var content.
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
function midebug($var, $mesg){
|
|
|
|
echo "[DEBUG (".$var."]: (".$mesg.")";
|
|
|
|
echo "<br>";
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
2007-03-06 14:18:49 +01:00
|
|
|
// array_in
|
|
|
|
// Search "item" in a given array, return 1 if exists, 0 if not
|
2006-03-27 05:37:27 +02:00
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
2007-03-06 14:18:49 +01:00
|
|
|
function array_in($exampleArray, $item){
|
|
|
|
$result = 0;
|
|
|
|
foreach ($exampleArray as $key => $value){
|
|
|
|
if ($value == $item){
|
|
|
|
$result = 1;
|
2006-03-27 05:37:27 +02:00
|
|
|
}
|
2007-03-06 14:18:49 +01:00
|
|
|
}
|
|
|
|
return $result;
|
2006-03-27 05:37:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
// parse and clear string
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
function salida_limpia ($string){
|
|
|
|
$quote_style=ENT_QUOTES;
|
|
|
|
static $trans;
|
|
|
|
if (!isset($trans)) {
|
|
|
|
$trans = get_html_translation_table(HTML_ENTITIES, $quote_style);
|
|
|
|
foreach ($trans as $key => $value)
|
|
|
|
$trans[$key] = '&#'.ord($key).';';
|
|
|
|
// dont translate the '&' in case it is part of &xxx;
|
|
|
|
$trans[chr(38)] = '&';
|
|
|
|
}
|
|
|
|
// after the initial translation, _do_ map standalone '&' into '&'
|
|
|
|
return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/","&" , strtr($string, $trans));
|
|
|
|
}
|
2007-04-11 05:12:48 +02:00
|
|
|
|
|
|
|
function clean_output_breaks ($string){
|
|
|
|
$myoutput = salida_limpia($string);
|
|
|
|
return preg_replace ('/\n/',"<br>", $myoutput);
|
|
|
|
|
2006-03-27 05:37:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
// This function reads a string and returns it "clean"
|
|
|
|
// for use in DB, againts string XSS and so on
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
function entrada_limpia ($texto){
|
|
|
|
// OJO: MagicQuotes en la configuracion de php.ini deberia estar activado y esta funcion solo deberiamos
|
|
|
|
// llamarla al entrar datos para escribir datos en la base MYSQL no al reves.
|
|
|
|
// $str = "A 'quote' is <b>bold</b>";
|
|
|
|
// Outputs: A 'quote' is <b>bold</b>
|
|
|
|
// $filtro0 = utf8_decode($texto);
|
|
|
|
$filtro1 = htmlentities($texto, ENT_QUOTES); // Primero evitamos el problema de las dobles comillas, comillas sueltas, etc.
|
|
|
|
$filtro2 = $filtro1;
|
|
|
|
// Sustituimos los caracteres siguientes ( ) : &
|
|
|
|
// $filtro2 = strtr($filtro1, array('&' => '&',':' => '58', '(' => '(', ')' => ')'));
|
|
|
|
return $filtro2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
// Esta funcion lee una cadena y la da "limpia", para su uso con
|
|
|
|
// parametros pasados a funcion de abrir fichero. Usados en sec y sec2
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
function parametro_limpio($texto){
|
|
|
|
// Metemos comprobaciones de seguridad para los includes de paginas pasados por parametro
|
2006-07-11 17:33:55 +02:00
|
|
|
// Gracias Raul (http://seclists.org/lists/incidents/2004/Jul/0034.html)
|
|
|
|
// Consiste en purgar los http:// de las cadenas
|
|
|
|
$pos = strpos($texto,"://"); // quitamos la parte "fea" de http:// o ftp:// o telnet:// :-)))
|
|
|
|
if ($pos <> 0)
|
|
|
|
$texto = substr_replace($texto,"",$pos,+3);
|
|
|
|
// limitamos la entrada de datos por parametros a 125 caracteres
|
|
|
|
$texto = substr_replace($texto,"",125);
|
|
|
|
$safe = preg_replace('/[^a-z0-9_\/]/i','',$texto);
|
|
|
|
return $safe;
|
2006-03-27 05:37:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
// Esta funcion se supone que cierra todos los tags HTML abiertos y no cerrados
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
// string closeOpenTags(string string [, string beginChar [, stringEndChar [, string CloseChar]]]);
|
|
|
|
|
|
|
|
function closeOpenTags($str, $open = "<", $close = ">", $end = "/", $tokens = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
|
|
|
{ $chars = array();
|
|
|
|
for ($i = 0; $i < strlen($tokens); $i++)
|
|
|
|
{ $chars[] = substr($tokens, $i, 1); }
|
|
|
|
|
|
|
|
$openedTags = array();
|
|
|
|
$closedTags = array();
|
|
|
|
$tag = FALSE;
|
|
|
|
$closeTag = FALSE;
|
|
|
|
$tagName = "";
|
|
|
|
|
|
|
|
for ($i = 0; $i < strlen($str); $i++)
|
|
|
|
{ $char = substr($str, $i, 1);
|
|
|
|
if ($char == $open)
|
|
|
|
{ $tag = TRUE; continue; }
|
|
|
|
if ($char == $end)
|
|
|
|
{ $closeTag = TRUE; continue; }
|
|
|
|
if ($tag && in_array($char, $chars))
|
|
|
|
{ $tagName .= $char; }
|
|
|
|
else
|
|
|
|
{if ($closeTag)
|
|
|
|
{if (isset($closedTags[$tagName]))
|
|
|
|
{ $closedTags[$tagName]++; }
|
|
|
|
else
|
|
|
|
{ $closedTags[$tagName] = 1; } }
|
|
|
|
elseif ($tag)
|
|
|
|
{if (isset($openedTags[$tagName]))
|
|
|
|
{ $openedTags[$tagName]++; }
|
|
|
|
else
|
|
|
|
{ $openedTags[$tagName] = 1; } }
|
|
|
|
$tag = FALSE; $closeTag = FALSE; $tagName = ""; }
|
|
|
|
}
|
|
|
|
|
|
|
|
while(list($tag, $count) = each($openedTags))
|
|
|
|
{
|
|
|
|
$closedTags[$tag] = isset($closedTags[$tag]) ? $closedTags[$tag] : 0;
|
|
|
|
$count -= $closedTags[$tag];
|
|
|
|
if ($count < 1) continue;
|
|
|
|
$str .= str_repeat($open.$end.$tag.$close, $count);
|
|
|
|
}
|
|
|
|
return $str;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
// Return string with time-threshold in secs, mins, days or weeks
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
function give_human_time ($int_seconds){
|
|
|
|
$key_suffix = 's';
|
|
|
|
$periods = array(
|
|
|
|
'year' => 31556926,
|
|
|
|
'month' => 2629743,
|
|
|
|
'day' => 86400,
|
|
|
|
'hour' => 3600,
|
|
|
|
'minute' => 60,
|
|
|
|
'second' => 1
|
|
|
|
);
|
|
|
|
|
|
|
|
// used to hide 0's in higher periods
|
|
|
|
$flag_hide_zero = true;
|
|
|
|
|
|
|
|
// do the loop thang
|
|
|
|
foreach( $periods as $key => $length )
|
|
|
|
{
|
|
|
|
// calculate
|
|
|
|
$temp = floor( $int_seconds / $length );
|
|
|
|
|
|
|
|
// determine if temp qualifies to be passed to output
|
|
|
|
if( !$flag_hide_zero || $temp > 0 )
|
|
|
|
{
|
|
|
|
// store in an array
|
|
|
|
$build[] = $temp.' '.$key.($temp!=1?'s':null);
|
|
|
|
|
|
|
|
// set flag to false, to allow 0's in lower periods
|
|
|
|
$flag_hide_zero = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the remainder of seconds
|
|
|
|
$int_seconds = fmod($int_seconds, $length);
|
|
|
|
}
|
|
|
|
|
|
|
|
// return output, if !empty, implode into string, else output $if_reached
|
|
|
|
return ( !empty($build)?implode(', ', $build):$if_reached );
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
// This function show a popup window using a help_id (unused)
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
function popup_help ($help_id){
|
|
|
|
echo "<a href='javascript:help_popup(".$help_id.")'>[H]</a>";
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
// no_permission () - Display no perm. access
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
function no_permission () {
|
|
|
|
require("config.php");
|
|
|
|
require ("include/languages/language_".$language_code.".php");
|
2006-10-21 18:47:26 +02:00
|
|
|
echo "<h3 class='error'>".$lang_label["no_permission_title"]."</h3>";
|
|
|
|
echo "<img src='images/noaccess.gif' width='120'><br><br>";
|
2006-03-27 05:37:27 +02:00
|
|
|
echo "<table width=550>";
|
2006-10-21 18:47:26 +02:00
|
|
|
echo "<tr><td>";
|
2006-03-27 05:37:27 +02:00
|
|
|
echo $lang_label["no_permission_text"];
|
|
|
|
echo "</table>";
|
|
|
|
echo "<tr><td><td><td><td>";
|
|
|
|
include "general/footer.php";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2006-07-01 03:48:56 +02:00
|
|
|
function list_files($directory, $stringSearch, $searchHandler, $outputHandler) {
|
|
|
|
$errorHandler = false;
|
|
|
|
$result = array();
|
|
|
|
if (! $directoryHandler = @opendir ($directory)) {
|
|
|
|
echo ("<pre>\nerror: directory \"$directory\" doesn't exist!\n</pre>\n");
|
|
|
|
return $errorHandler = true;
|
|
|
|
}
|
|
|
|
if ($searchHandler == 0) {
|
|
|
|
while (false !== ($fileName = @readdir ($directoryHandler))) {
|
|
|
|
@array_push ($result, $fileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($searchHandler == 1) {
|
|
|
|
while(false !== ($fileName = @readdir ($directoryHandler))) {
|
|
|
|
if(@substr_count ($fileName, $stringSearch) > 0) {
|
|
|
|
@array_push ($result, $fileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (($errorHandler == true) && (@count ($result) === 0)) {
|
|
|
|
echo ("<pre>\nerror: no filetype \"$fileExtension\" found!\n</pre>\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sort ($result);
|
|
|
|
if ($outputHandler == 0) {
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
if ($outputHandler == 1) {
|
|
|
|
echo ("<pre>\n");
|
|
|
|
print_r ($result);
|
|
|
|
echo ("</pre>\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-27 05:37:27 +02:00
|
|
|
function pagination ($count, $url, $offset ) {
|
|
|
|
require ("config.php");
|
|
|
|
require ("include/languages/language_".$language_code.".php");
|
|
|
|
|
|
|
|
/* URL passed render links with some parameter
|
|
|
|
&offset - Offset records passed to next page
|
|
|
|
&counter - Number of items to be blocked
|
|
|
|
Pagination needs $url to build the base URL to render links, its a base url, like
|
|
|
|
" http://pandora/index.php?sec=godmode&sec2=godmode/admin_access_logs "
|
|
|
|
|
|
|
|
*/
|
2007-02-05 18:45:14 +01:00
|
|
|
$block_limit = 15; // Visualize only $block_limit blocks
|
2006-03-27 05:37:27 +02:00
|
|
|
if ($count > $block_size){
|
|
|
|
// If exists more registers than I can put in a page, calculate index markers
|
|
|
|
$index_counter = ceil($count/$block_size); // Number of blocks of block_size with data
|
2007-02-05 18:45:14 +01:00
|
|
|
$index_page = ceil($offset/$block_size)-(ceil($block_limit/2)); // block to begin to show data;
|
|
|
|
if ($index_page < 0)
|
|
|
|
$index_page = 0;
|
2006-03-27 05:37:27 +02:00
|
|
|
|
|
|
|
// This calculate index_limit, block limit for this search.
|
|
|
|
if (($index_page + $block_limit) > $index_counter)
|
2007-02-06 16:38:29 +01:00
|
|
|
$index_limit = $index_counter;
|
2006-03-27 05:37:27 +02:00
|
|
|
else
|
|
|
|
$index_limit = $index_page + $block_limit;
|
|
|
|
|
|
|
|
// This calculate if there are more blocks than visible (more than $block_limit blocks)
|
|
|
|
if ($index_counter > $block_limit )
|
|
|
|
$paginacion_maxima = 1; // If maximum blocks ($block_limit), show only 10 and "...."
|
|
|
|
else
|
|
|
|
$paginacion_maxima = 0;
|
|
|
|
|
|
|
|
// This setup first block of query
|
|
|
|
if ( $paginacion_maxima == 1)
|
|
|
|
if ($index_page == 0)
|
|
|
|
$inicio_pag = 0;
|
|
|
|
else
|
|
|
|
$inicio_pag = $index_page;
|
|
|
|
else
|
|
|
|
$inicio_pag = 0;
|
|
|
|
|
2007-02-05 18:45:14 +01:00
|
|
|
echo "<div>";
|
|
|
|
// Show GOTO FIRST button
|
|
|
|
echo '<a href="'.$url.'&offset=0">';
|
2007-03-02 18:56:07 +01:00
|
|
|
echo "<img src='images/control_start_blue.png' class='bot'>";
|
2007-02-05 18:45:14 +01:00
|
|
|
echo "</a>";
|
|
|
|
echo " ";
|
|
|
|
// Show PREVIOUS button
|
|
|
|
if ($index_page > 0){
|
2007-02-06 16:38:29 +01:00
|
|
|
$index_page_prev= ($index_page-(floor($block_limit/2)))*$block_size;
|
2007-02-05 18:45:14 +01:00
|
|
|
if ($index_page_prev < 0)
|
|
|
|
$index_page_prev = 0;
|
2007-03-02 18:56:07 +01:00
|
|
|
echo '<a href="'.$url.'&offset='.$index_page_prev.'"><img src="images/control_rewind_blue.png" class="bot"></a>';
|
2006-03-27 05:37:27 +02:00
|
|
|
}
|
2007-03-02 18:56:07 +01:00
|
|
|
echo " ";echo " ";
|
2006-03-27 05:37:27 +02:00
|
|
|
// Draw blocks markers
|
2007-02-06 16:38:29 +01:00
|
|
|
// $i stores number of page
|
2007-02-05 18:45:14 +01:00
|
|
|
for ($i = $inicio_pag; $i < $index_limit; $i++) {
|
2006-03-27 05:37:27 +02:00
|
|
|
$inicio_bloque = ($i * $block_size);
|
|
|
|
$final_bloque = $inicio_bloque + $block_size;
|
|
|
|
if ($final_bloque > $count){ // if upper limit is beyond max, this shouldnt be possible !
|
|
|
|
$final_bloque = ($i-1)*$block_size + $count-(($i-1) * $block_size);
|
|
|
|
}
|
2007-02-05 18:45:14 +01:00
|
|
|
echo "<span>";
|
2007-02-06 16:38:29 +01:00
|
|
|
|
2006-03-27 05:37:27 +02:00
|
|
|
$inicio_bloque_fake = $inicio_bloque + 1;
|
2007-02-06 16:38:29 +01:00
|
|
|
// To Calculate last block (doesnt end with round data,
|
|
|
|
// it must be shown if not round to block limit)
|
|
|
|
echo '<a href="'.$url.'&offset='.$inicio_bloque.'">';
|
|
|
|
if ($inicio_bloque == $offset)
|
|
|
|
echo "<b>[ $i ]</b>";
|
|
|
|
else
|
|
|
|
echo "[ $i ]";
|
|
|
|
echo '</a> ';
|
|
|
|
echo "</span>";
|
|
|
|
}
|
2007-03-02 18:56:07 +01:00
|
|
|
echo " ";echo " ";
|
2007-02-06 16:38:29 +01:00
|
|
|
// Show NEXT PAGE (fast forward)
|
|
|
|
// Index_counter stores max of blocks
|
|
|
|
if (($paginacion_maxima == 1) AND (($index_counter - $i) > 0)) {
|
|
|
|
$prox_bloque = ($i+ceil($block_limit/2))*$block_size;
|
|
|
|
if ($prox_bloque > $count)
|
|
|
|
$prox_bloque = ($count -1) - $block_size;
|
|
|
|
echo '<a href="'.$url.'&offset='.$prox_bloque.'">';
|
2007-03-02 18:56:07 +01:00
|
|
|
echo "<img class='bot' src='images/control_fastforward_blue.png'></a> ";
|
2006-03-27 05:37:27 +02:00
|
|
|
$i = $index_counter;
|
|
|
|
}
|
|
|
|
// if exists more registers than i can put in a page (defined by $block_size config parameter)
|
|
|
|
// get offset for index calculation
|
2007-02-06 16:38:29 +01:00
|
|
|
// Draw "last" block link, ajust for last block will be the same
|
|
|
|
// as painted in last block (last integer block).
|
|
|
|
if (($count - $block_size) > 0){
|
|
|
|
$myoffset = floor(($count-1)/ $block_size)* $block_size;
|
2007-03-02 18:56:07 +01:00
|
|
|
echo '<a href="'.$url.'&offset='.$myoffset.'">';
|
|
|
|
echo "<img class='bot' src='images/control_end_blue.png'>";
|
2007-02-06 16:38:29 +01:00
|
|
|
echo "</a>";
|
|
|
|
}
|
2007-02-05 18:45:14 +01:00
|
|
|
// End div and layout
|
|
|
|
echo "</div>";
|
2007-02-19 08:44:07 +01:00
|
|
|
}
|
2006-03-27 05:37:27 +02:00
|
|
|
}
|
2006-12-25 19:15:57 +01:00
|
|
|
|
2007-03-12 18:58:52 +01:00
|
|
|
// Render data in a fashion way :-)
|
|
|
|
function format_numeric ( $number, $decimals=2, $dec_point=".", $thousands_sep=",") {
|
|
|
|
if ($number == 0)
|
|
|
|
return 0;
|
|
|
|
// If has decimals
|
|
|
|
if (fmod($number , 1)> 0)
|
|
|
|
return number_format ($number, 2, $dec_point, $thousands_sep);
|
|
|
|
else
|
|
|
|
return number_format ($number, 0, $dec_point, $thousands_sep);
|
|
|
|
}
|
|
|
|
|
2006-10-21 18:47:26 +02:00
|
|
|
?>
|