使用php把tac_plus的log从mysql中读取出来

2011年4月1日 | 分类: Linux | 标签: , , ,

上篇文章说了把tac_plus的日志存到mysql中,现在说下怎么读取出来并在网页上体现出来,对于编程,前边说过了,一点不会,我写的就是最简单的页面,如果有谁改进了,一定要发给我啊。

因为access的log意义不太大,所以只写了acct的,一共有三个文件:index.php(主页面),acctlog.php(显示数据的主要页面),search.php(搜索框)。设置index.php的目的是怕数据太多,显示的时候太慢。

1.index.php

<html>
<head>
<title>Tacacs+ Log Analysis Tool</title>
</head>
<center>
<br>
<br>
<br>
<body>
<font size=”12″ face=”arial black”>
Tacacs+ Accounting
</font>
</body>
<br>
<br>
<?php
include(“search.php”);
?>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<font size=”2″ color=”#005AB5″>
Copyright By MIS
</font>
</body>
</center>
</html>
2.acctlog.php

<html>
<head>
<title>Tacacs+ Log Analysis Tool</title>
</head>
<center>
<br>
<br>
<br>
    <h1>Tacacs+ Accounting</h1>
</body>
<br>
<?php
include(“search.php”);
?>
<?php
$link=mysql_connect(“localhost”,”root”,”abcd.1234″);
mysql_select_db(“test”, $link);
$date = $_POST["date"];
$name = $_POST["name"];
$ip = $_POST["ip"];
$q = “SELECT * FROM acct where date like ‘$date%’ and username like ‘$name%’ and serverip like ‘$ip%’”;
mysql_query(“SET NAMES GB2312″);
$rs = mysql_query($q, $link);
if(!$rs){die(“Valid result!”);}
?>
<center><table width=100% cellspacing=0 cellpadding=3 border=1>
<center>
                        <tr>
                                <td>Date</td>
                                <td>Time</td>
                                <td>ServerIP</td>
                                <td>Username</td>
                                <td>TTY</td>
                                <td>ClientIP</td>
                                <td>Status</td>
                                <td>TaskID</td>
                                <td>Service</td>
                                <td>Privilege</td>
                                <td>Information</td>
                        </tr>
</center>
<?php
while($row = mysql_fetch_row($rs))
{
?>
<center>
                                <tr>
                                        <td><?=$row[1]?></td>
                                        <td><?=$row[2]?></td>
                                        <td><?=$row[3]?></td>
                                        <td><?=$row[4]?></td>
                                        <td><?=$row[5]?></td>
                                        <td><?=$row[6]?></td>
                                        <td><?=$row[7]?></td>
                                        <td><?=$row[8]?></td>
                                        <td><?=$row[9]?></td>
                                        <td><?=$row[10]=$row[10]!=”"?$row[10]:”-”?></td>
                                        <td><?=$row[11]=trim($row[11])!=”"?$row[11]:”-”?></td>
                                </tr>
</center>
<?php
}
?>
</table>
<br>
<br>
<br>
<body>Copyright By MIS</body>
</center>
3.search.php

<html>
<head>
<title>Tacacs+ Log Analysis Tool</title>
</head>
<center>
<br>
<br>
<body>
<form action=”acctlog.php” method=”post”>
<font face=”dotum”>
Date: <input type=”text” name=”date”/>
Username: <input type=”text” name=”name” />
ServerIP: <input type=”test” name=”ip” />
<input type=”submit” value=”Search”/>
</font>
</form>
</center>
</body>
</html>

Written by an6097

目前还没有任何评论.
注意: 评论者允许使用'@user空格'的方式将自己的评论通知另外评论者。例如, ABC是本文的评论者之一,则使用'@ABC '(不包括单引号)将会自动将您的评论发送给ABC。使用'@all ',将会将评论发送给之前所有其它评论者。请务必注意user必须和评论者名相匹配(大小写一致)。