This is a script that publish the netwatch status on a web page.
Please note that I have not taken any action to secure these scripts, so dont publish them on external webservers
Please note that I have not taken any action to secure these scripts, so dont publish them on external webservers
Needed
- webserver with php and mysql
- ros 3.16 (Works on earlier versions too, but I used that version...)
Netwatch Code
The netwatch code for up :
The netwatch code for down :
Important
Codice:
/tool fetch mode=http address=www.yourpage.no src-path=("/net_status.php?router=1&status=1&time=" \
Codice:
.[/system clock get time]."%20".[/system clock get date]) dst-path="/netwatch" port=80 \
Codice:
host=www.yourpage.no
The netwatch code for down :
Codice:
/tool fetch mode=http address=www.yourpage.no src-path=("/net_status.php?router=1&status=2&time=" \
Codice:
.[/system clock get time]."%20".[/system clock get date]) dst-path="/netwatch" port=80 \
Codice:
host=www.yourpage.no
Important
Note the following php string options :
router=1 the id of the router in the database- (you have to change this value in the up/down script based on the id of the router in the database, if you dont, it will only update data for 1 router)
status=1 (or 2) status 1 means router is up, status 2 means router is down time <- time and date for action
Database setup
Make a database called 'netwatch' and a table called 'netwatch'
Make the following fields : id (Int,auto,index), name (varchar), status (int), time (varchar)
Now insert a couple of routers in the database, you only have to fill in the 'name' field, the others will be filled later automatically.
The database connection script: (databaseconfig.php)
databaseconfig.php
php script for accepting values: (net_status.php)
net_status.php
The final display script
display.php
Codice:
<?php
Codice:
$conn = mysql_connect("localhost", "username", "password") or die(mysql_error());
Codice:
$db=mysql_select_db("netwatch") or die(mysql_error());
Codice:
?>
php script for accepting values: (net_status.php)
net_status.php
Codice:
<?php
Codice:
/**
Codice:
* @author bent ole fosse
Codice:
*
Codice:
*/
Codice:
include "databaseconfig.php";
Codice:
//get data from header
Codice:
$router=$_GET['router'];
Codice:
$status=$_GET['status'];
Codice:
$time=$_GET['time'];
Codice:
$query="UPDATE netwatch SET status='".$status."', time='".$time."' WHERE id='".$router."'";
Codice:
$result=mysql_query($query)or die(mysql_error());
Codice:
echo "done";
Codice:
?>
The final display script
display.php
Codice:
<?php
Codice:
/**
Codice:
* @author bent ole fosse
Codice:
*
Codice:
*/
Codice:
include "databaseconfig.php";
Codice:
$query="SELECT * FROM netwatch";
Codice:
$result=mysql_query($query)or die(mysql_error());
Codice:
$num=mysql_numrows($result);
Codice:
echo "<table width=800>";
Codice:
echo "<tr><td align=left>Router</td><td>Time</td><td>Status</td></tr>";
Codice:
echo "<tr><td align=left>";
Codice:
for ($i=0; $i<$num; $i++)
Codice:
{
Codice:
if (mysql_result($result,$i,"status")=="1")
Codice:
{
Codice:
echo "<font color=#04B404>".mysql_result($result,$i,"name")."</font><br>";
Codice:
}else{
Codice:
echo "<font color=#FF0000>".mysql_result($result,$i,"name")."</font><br>";
Codice:
}
Codice:
}
Codice:
echo "</td><td>";
Codice:
for ($i=0; $i<$num; $i++)
Codice:
{
Codice:
if (mysql_result($result,$i,"status")=="1")
Codice:
{
Codice:
echo "<font color=#04B404>".mysql_result($result,$i,"time")."</font><br>";
Codice:
}else{
Codice:
echo "<font color=#FF0000>".mysql_result($result,$i,"time")."</font><br>";
Codice:
}
Codice:
}
Codice:
echo "</td><td>";
Codice:
for ($i=0; $i<$num; $i++)
Codice:
{
Codice:
if (mysql_result($result,$i,"status")=="1")
Codice:
{
Codice:
echo "<font color=#04B404>Up</font><br>";
Codice:
}else{
Codice:
echo "<font color=#FF0000>Down</font><br>";
Codice:
}
Codice:
}
Codice:
echo "</td></tr>";
Codice:
echo "<tr><td colspan=3><center>Hopefully this works ok...</center></td></tr>";
Codice:
echo "</table>";
Codice:
?>