Newsgroup: it.comp.www.php
Titolo: Text to HTML

I've just installed PHP and Apache on Win2k Pro which is setup as a syslog
server. It receives a syslog file from my Cisco PIX firewall every night. I
can view the syslogs at the Win2k workstation, but I would like to use a PHP
script that would convert the log file (which is in text format), to HTML
format.
Can someone help me get started?
Carlton Whitmore


To transform a text in HTML, you can use PHP built-in functions, like 
nl2br(string $text) that changes all the new-line (\n) to a <BR> tag, 
and htmlentities(string $text) that transform all recognizable HTML 
things in the correct way (like all '<' becomes '&lt;'). So when you 
read the text using fopen() and fgets(), you can simply put out all 
using nl2br(htmlentities($text)).
Bye
Andrea



Yes. Post a single line from the log, and the HTML of how you would
like it.
Service free until February 15th, 2002 ;-)))
It could also be interesting to install MySQL, and store everything
in a database, so as to obtain statistics on which networks are the
most frisky, which exploits the most attempted, and possibly assign
a Dork of the Year prize to those morons who try to smuggle in some
clever exploit which will only work on Abraham Lincoln's own ZyXEL.
Leonardo

 wrote in message
news:dsp06us0plcj60fdp...@4ax.com...


 wrote in message
news:dsp06us0plcj60fdp...@4ax.com...


(
ip115.advocacyinc.org
) /80 flags SYN
Okay. So if foo.txt is the text file generated by syslogd, we could...
oh, well, we wouldn't even need PHP, all you need is good old "sed"...
but PHP offers some more thrills. So here we go... sorry for the lousy
indentation, but I had to back-transfer it from a Unix server, and cut
and paste doesn't seem to work well under such conditions.
Since you didn't supply a HTML template, I improvised. The results are
not exactly fit for kids. Modifications should be easy.
 
$cisco = "cisco.txt";
// Some useful regexps
$DATE='([0-1][0-9]-[0-3][0-9]-20[0-9][0-9])';
$TIME="([0-2][0-9]:[0-5][0-9]:[0-5][0-9])";
$PREC="([A-Z0-9a-z]*\\.[A-Z0-9a-z]*)";
$IP="([0-9]*\\.[0-9]*\\.[0-9]*\\.[0-9]*)"; // Simplistic :-(
$PIXD="(%PIX-[0-9]-[0-9]*)";
$ALRT="([^:]*)";
$TEXT="([^\\(\\/\\)]+)";
$N="([0-9]+)";
$FQDN="$IP \\($TEXT\\)";
// The big daddy
$LOG="/^$DATE $TIME $PREC $IP $PIXD: $ALRT from $FQDN \\/$N to $FQDN
\\/$N $TEXT/";
print "<TABLE WIDTH=\"100%\" BORDER=1 CELLSPACING=0 CELLPADDING=1>";
$fp = fopen($cisco, "r");// Open and read
while(!feof($fp))
{
$td=array(); for ($i=0;$i<20;$i++) $td[]='<TD>';
$g = fgets($fp, 1024); // Read line
if (preg_match($LOG, $g, $pix))
{// Parse line
// Special code for pix vector handling here, e.g.
switch($pix[5])
{
case '%PIX-2-106007':
$td[5]='<TD BGCOLOR="#C0C0C0">';
break;
}
if ($pix[8]=='Unresolved')
$td[8]='<TD BGCOLOR="#FFC0C0">';
else
$td[8]='<TD BGCOLOR="#C0FFC0">';
///////
// THE ACTUAL PRINT (da stuff)
print "<TR>\n";
for ($fld=1; $fld < 14; $fld++)
{
	print "\t$td[$fld]<TT>$pix[$fld]</TT></TD>\n";
	// Wrap after six fields unless you have a 2800x1800
	// LCD monitor
	if ($fld == 6)
		print "</TR>\n<TR>\n";
}
print "</TR>\n";
}
else
print "<TR BGCOLOR=\"red\"><TD COLSPAN=13><TT>$g</TT></TD></TR>\n";
}
fclose($fp);
print "</TABLE>";
Leonardo