Title: Syslog query

Hello,

I made this little php page, for querying mysql syslog.

If you want, you could make a modification on jffnms menu for calling directly this page.

Any suggestion are appreciate.

Thanks you.
V.

Syslog_query.php

---------------- START CUT HERE ------------------
<?
// V. 1.4
// [EMAIL PROTECTED] or [EMAIL PROTECTED]
//
// there are not bugs free, i need some help on refresh page/query, multiple select on ip address
// i'm sorry if the are some var in italian language
//
// syslog_query.php
//
// START

$jffnms_init_classes = 1;
include("auth.php");
adm_header("Syslog");
?>

<h1>SYSLOG</h1>

<?
if (empty($page)) $page=1;                      // defaul page
if (empty($Num_Righe)) $Num_Righe=50;           // Defaul row/page
if (empty($search)) $search="%";                // default search string
?>

<center>
<form action="" method=GET>

<?

// MAIN CONNECTION
$name_server="localhost";
$name_db="JFFNMS";

$inizio=($page-1)*$Num_Righe;

$connessione = mysql_connect($name_server,$dbuser,$dbpass) or die ("Could not connect to MySQL");
$database = mysql_select_db($name_db,$connessione) or die ("Could not select database");


//QUERY list

$sql1 = "SELECT id,date,message,host FROM syslog WHERE (message LIKE '$message%') AND (host like '%$search%') ORDER BY date desc" or die ("Could not connect to database");

$sql2 = "SELECT '             ' as message1 union all SELECT distinct message as message1 from syslog ORDER BY message1" or die ("Could not connect to database");

$sql3 = "SELECT COUNT(*) as cont FROM syslog WHERE (message LIKE '$message%') AND (host like '%$search%')" or die ("Could not connect to database");

if ($Num_Righe<>"ALL") $sql1 .= " LIMIT $inizio,$Num_Righe";   // LIMIT search row/page

$tutto = mysql_query($sql1,$connessione);
$tutto2 = mysql_query($sql2,$connessione);
$tutto3 = mysql_query($sql3,$connessione);


//SEARCH STRING
echo "<small>Search message:</small><input name='search' type='text' size=20 maxlength='20' />";



//IP FILTER
echo "<small> Host filter:</small><select name ='message' size=1>";
while ($valori2=mysql_fetch_array($tutto2)) {
for ($i=0;$i< mysql_num_fields($tutto2);$i++)  echo "<option value=$valori2[$i]>$valori2[$i]</option>";
        }
echo "</select>";



//Option ROW/PAGE
echo "<small> Row:</small><select name='Num_Righe' size=1>";
echo "<option value='50' selected>50</option>";
echo "<option value='100'>100</option>";
echo "<option value='200'>200</option>";
echo "<option value='500'>500</option>";
echo "<option value='ALL'>ALL</option>";
echo "</select>";


//calcolo numero pagine
while ($valori3=mysql_fetch_array($tutto3)) {
$num_page = (int) (($valori3[0] / $Num_Righe)+1);
$num_righe = $valori3[0];
}


//funzione per non oltrepassare il numero massimo delle pagine
$page_bk = $page -1 ;
$page_fw = $page +1 ;

if ($page_fw>=$num_page) $page_fw=$num_page;

?>


&nbsp;&nbsp;<input type=submit>
<br><br>
<a href=''><< </a><a href=''>Pag.-</a> <a href=''>Pag.+</a><a href=''> >></a>

<?

// Draw table with query

echo "<table border=1 align=center width=100%>";
echo "<tr style='font-weight:bold;'>";
echo "<td width=4%>ID</td>";
echo "<td width=7%>DATE</td>";
echo "<td width=6%>IP</td>";
echo "<td width=83%>MESSAGE</td>";
echo "</tr>";
while ($valori=mysql_fetch_array($tutto)) {

echo "<tr>";

for($i=0;$i< mysql_num_fields($tutto);$i++) echo "<td>$valori[$i]</td>" ;

echo "</tr>";}
echo "</table>";

echo "$page of $num_page <br>";
echo "Return row: $num_righe <br>";

mysql_free_result($tutto);
mysql_close($connessione);

?>

---------------------- END CUT HERE ------------------------------





::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Valentino PEMONI
Produzione & Infrastrutture
Information Technology

ARVAL Italia
E-mail: [EMAIL PROTECTED]
TEL: +39 055 7595.421
FAX: +39 055 7376.121
WEB : www.arval.it
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Reply via email to