<?php
///////////////////////////////////////////////////////////////////
// pHpHp v0.1 written by Greg Lawler
// September 5 2000
// from http://www.zinkwazi.com
// Feel free to use/modify this little script.
//
// this script comes with no implied warranty.
///////////////////////////////////////////////////////////////////
//
// INSTALLATION INSTRUCTIONS
// You NEED to have SNMP compiled into your PHP for this to work!!!!
// check http://www.php.net/ for details
//
// Create a text file called printers.txt and place it in the same
// directory as phphp.php. In the printers.txt file, list each
// printer to be monitored on a separate line.
// This script has only been tested on Linux. It should work on NT
// but WILL NOT WORK ON WINDOWZ 9x because phphp uses SNMP.
// if you get errors, check http://www.php.net
// first to see how to get SNMP working on your machine.
//
// NB! you may need to change the community to match your printer's
// do this by telnetting to the printer. or change $community below
// to match your printers.
//
// i just wrote this today so expect bugs ;)
//
//////////////////////////////////////////////////////////////////////
$title = "pHpHp";
// html stuff, replace with your sites include() file
print "<HTML><HEAD><TITLE>$title</title>";
print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"60;URL=$PHP_SELF\">\n";
print "</HEAD>";
print "<BODY>";
print "<CENTER>";
print "<H3><B>$header</H3></B>";
function strip_quotes($input)
{
return (preg_replace("/\"/", "", $input) );
}
function print_test_page($target)
{
// i am still working on this
}
$printers = file("printers.txt");
$number_of_printers = count ($printers);
print "<table width=100%><tr>";
for ( $i = 0 ; $i < $number_of_printers ; $i++)
{
$timeout = '300';
$retries = '10';
$cell_bg_color = "cccccc";
$table_header_color = "cccccc";
// you may need to change the community to match your printer's
// do this by telnetting to the printer.i
$community = "public";
$status = snmpget($printers[$i], $community, ".1.3.6.1.4.1.11.2.3.9.1.1.3.0", $timeout, $retries);
$ipx_name = snmpget($printers[$i], $community, ".1.3.6.1.4.1.11.2.4.3.10.8.0", $timeout, $retries);
$sysname = snmpget($printers[$i], $community, "system.sysName.0", $timeout, $retries);
$contact = snmpget($printers[$i], $community, "system.sysContact.0", $timeout, $retries);
$location = snmpget($printers[$i], $community, "system.sysLocation.0", $timeout, $retries);
$toner = snmpget($printers[$i], $community, ".1.3.6.1.4.1.11.2.3.9.4.2.2.11.1.1.6.1.1", $timeout, $retries);
$pages_printed = snmpget($printers[$i], $community, ".1.3.6.1.2.1.43.10.2.1.4.1.1", $timeout, $retries);
$get_firmware = snmpget($printers[$i], $community, ".1.3.6.1.4.1.11.2.4.3.1.12.1.2.5", $timeout, $retries);
eregi( "REVISION: (.*)", $get_firmware, $firmware);
$get_netmask = snmpget($printers[$i], $community, ".1.3.6.1.4.1.11.2.4.3.1.12.1.2.24", $timeout, $retries);
eregi( "MASK: (.*)", $get_netmask, $netmask);
$get_gateway = snmpget($printers[$i], $community, ".1.3.6.1.4.1.11.2.4.3.1.12.1.2.25", $timeout, $retries);
eregi( "GATEWAY: (.*)", $get_gateway, $gateway);
$get_bp_server = snmpget($printers[$i], $community, ".1.3.6.1.4.1.11.2.4.3.1.12.1.2.30", $timeout, $retries);
eregi( "SERVER: (.*)", $get_bp_server, $bp_server);
$get_configby = snmpget($printers[$i], $community, ".1.3.6.1.4.1.11.2.4.3.1.12.1.2.22", $timeout, $retries);
eregi( "BY: (.*)", $get_configby, $configby);
$get_mac = snmpget($printers[$i], $community, ".1.3.6.1.4.1.11.2.4.3.1.12.1.2.6", $timeout, $retries);
eregi( ": (.*)", $get_mac, $mac);
$get_apple_name = snmpget($printers[$i], $community, ".1.3.6.1.4.1.11.2.4.3.1.12.1.2.75", $timeout, $retries);
eregi( ": (.*)", $get_apple_name, $apple_name);
if ((strip_quotes($status) == "READY") || (strip_quotes($status) == "POWERSAVE ON")) $alert = "GREEN";
else $alert = "RED";
print "<td>";
print "<table border=0 cellpadding=0 cellspacing=2>\n";
print "<tr>\n";
print "<td colspan=2 align=center bgcolor=$table_header_color>";
print strip_quotes($sysname);
print "</td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td align=center colspan=2 bgcolor=$alert>";
print strip_quotes($status);
print "</td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td bgcolor=$cell_bg_color>Pages Printed</td>\n";
print "<td bgcolor=$cell_bg_color>";
print $pages_printed;
print "</td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td bgcolor=$cell_bg_color>IPX Name</td>\n";
print "<td bgcolor=$cell_bg_color>";
print strip_quotes($ipx_name);
print "</td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td bgcolor=$cell_bg_color>Appletalk Name</td>\n";
print "<td bgcolor=$cell_bg_color>";
print strip_quotes($apple_name[1]);
print "</td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td bgcolor=$cell_bg_color>Location</td>\n";
print "<td bgcolor=$cell_bg_color>";
print strip_quotes($location);
print "</td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td bgcolor=$cell_bg_color>Net Config By</td>\n";
print "<td bgcolor=$cell_bg_color>";
print strip_quotes($configby[1]);
print "</td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td bgcolor=$cell_bg_color>DHCP Server</td>\n";
print "<td bgcolor=$cell_bg_color>";
print strip_quotes($bp_server[1]);
print "</td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td bgcolor=$cell_bg_color>IP Address</td>\n";
print "<td bgcolor=$cell_bg_color>";
print strip_quotes($printers[$i]);
print "</td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td bgcolor=$cell_bg_color>Net Mask</td>\n";
print "<td bgcolor=$cell_bg_color>";
print strip_quotes($netmask[1]);
print "</td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td bgcolor=$cell_bg_color>Gateway</td>\n";
print "<td bgcolor=$cell_bg_color>";
print strip_quotes($gateway[1]);
print "</td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td bgcolor=$cell_bg_color>MAC Address</td>\n";
print "<td bgcolor=$cell_bg_color>";
print strip_quotes($mac[1]);
print "</td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td bgcolor=$cell_bg_color>Contact</td>\n";
print "<td bgcolor=$cell_bg_color>";
print strip_quotes($contact);
print "</td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td bgcolor=$cell_bg_color>Firmware</td>\n";
print "<td bgcolor=$cell_bg_color>";
print strip_quotes($firmware[1]);
print "</td>\n";
print "</tr>\n";
print "<tr>\n";
print "<td colspan=2 bgcolor=$cell_bg_color>";
print strip_quotes($toner);
print "</td>\n";
print "</tr>\n";
print "</table>\n";
print "</td>";
}
print "</tr></table>";
// html stuff, replace with your sites include() file
print "</CENTER></BODY></HTML>";
?>