<?php
/*
* printers
* By George Vieira <hide@address.com>
* (c) 2005
*
*/
function plugin_init_printers()
{
global $plugin_hooks;
$plugin_hooks["maintable_tunneldata_processing"]["printers"] = "printers_get_print_history";
$plugin_hooks["maintable_tunnelinfotitle"]["printers"] = "printers_display_printers_title";
$plugin_hooks["maintable_tunnelinfodata"]["printers"] = "printers_display_printers_info";
$plugin_hooks["maintable_plugin_action_frame"]["printers"] = "printers_display_printer_log";
}
function printers_display_printers_title()
{
echo "<TH width='44' height=20 noWrap scope=col><FONT class=datasheetField> Printing</FONT></TH>";
}
function printers_display_printers_info( $id )
{
echo "<TD noWrap height=20 bgcolor=".$id["printcolor"]."><FONT class=datasheetField> <a href=javascript:serveradmin_popUp('?mod=plugins&action=printstat&id=".$id['id']."',700,300)>".$id['printcheck']."</a></FONT></TD>";
}
function printers_get_print_history()
{
global $tunnel;
$lines = explode("\n",trim(shell_exec("rsh -l georgev 10.10.0.30 \"cat /tmp/smbprint-*.log\"")));
$linenumber=0;
// Set unknown printer HTML as default
foreach( $tunnel as $key => $tuntemp )
{
$tunnel[$key]["printcheck"] = "<img src='images/printerunknown.gif' alt='Printer Status Unknown\nPossibly Prints Through Another Network Printer' title='Printer Status Unknown\nPossibly Prints Through Another Network Printer' border=0>";
$tunnel[$key]["printcolor"] = "#fffff7";
}
while ( $linenumber <= count($lines) )
{
if ( is_integer(strpos($lines[$linenumber],"-----------")) )
{
// New printer found
$username = substr($lines[$linenumber],0, strpos($lines[$linenumber], "-----"));
$printcheck = "";
$id = printerplugin_printers_findid( $username );
$linenumber += 1;
// Collect New printer data until it gets to the next printer.
while( !is_integer(strpos($lines[$linenumber],"-----------")) and $linenumber <= count($lines) )
{
$printcheck .= $lines[$linenumber] . "<br>";
$linenumber += 1;
}
if ( $id )
{
// Set Data to Tunnel
$tunnel[$id]["printdata"]=$printcheck;
if (stristr($printcheck ,"putting file - as stdin"))
{
$tunnel[$id]["printcheck"] = "<img src=images/printerok.gif alt='Last Print Request Sent Without Problems' title='Last Print Request Sent Without Problems' border=0>";
$tunnel[$id]["printcolor"] = "#c0ffc0";
}
elseif (stristr($printcheck ,"ERRSRV - 2242"))
{
$tunnel[$id]["printcheck"] = "<img src=images/printerdenied.gif alt=\"User Account Password Expired\nSet user accounts password to never expire.\" title=\"User Account Password Expired\nSet user accounts password to never expire.\" border=0>";
$tunnel[$id]["printcolor"] = "#ffc0c0";
}
elseif (stristr($printcheck ,"ERRnosuchshare"))
{
$tunnel[$id]["printcheck"] = "<img src=images/printerdenied.gif alt=\"Wrong or Missing Sharename\nPrinter Share Name Does Not Exist?\" title=\"Wrong or Missing Sharename\nPrinter Share Name Does Not Exist?\" border=0>";
$tunnel[$id]["printcolor"] = "#ffc0c0";
}
elseif (stristr($printcheck ,"ERRnoaccess"))
{
$tunnel[$id]["printcheck"] = "<img src=images/printerdenied.gif alt=\"Access Denied\nUser Account Does Not Exist?\" title=\"Access Denied\nUser Account Does Not Exist?\" border=0></a>";
$tunnel[$id]["printcolor"] = "#ffc0c0";
}
elseif (stristr($printcheck ,"ERRSRV - 2242"))
{
$tunnel[$id]["printcheck"] = "<img src=images/userexpire.gif alt=\"User Password Expired\nPossibly User jbasespooler login Is Not Set To NEVER EXPIRE\" title=\"User Password Expired\nPossibly User jbasespooler login Is Not Set To NEVER EXPIRE\" border=0></a>";
$tunnel[$id]["printcolor"] ="#ffc0c0";
}
elseif (stristr($printcheck ,"timeout connecting"))
{
$tunnel[$id]["printcheck"] = "<img src=images/printertimeout.gif alt=\"Ping Time Out\nAt Last Print Time,\nUsers Connection Could've Been Slow Or Conguested\" title=\"Ping Time Out\nAt Last Print Time,\nUsers Connection Could've Been Slow Or Conguested\" border=0></a>";
$tunnel[$id]["printcolor"] = "#f0f0c0";
}
elseif ($printcheck = "\n")
{
$tunnel[$id]["printcheck"] = "<img src=images/printerunknown.gif alt=\"Printer Status Unknown\nPossibly Prints Through Another Network Printer\" title=\"Printer Status Unknown\nPossibly Prints Through Another Network Printer\" border=0></a>";
$tunnel[$id]["printcolor"] = "#FBB757";
}
}
else
$linenumber++;
}
else
$linenumber++;
}
}
function printerplugin_printers_findid( $username )
{
global $tunnel;
foreach ( $tunnel as $key => $value )
{
if ( $value[TUNNEL_USERNAME] == $username )
return $key;
}
}
function printers_display_printer_log( $blank )
{
global $tunnel;
// Collect all tunnel data
get_tunnel_data();
$id = $_GET['id'];
?>
<table class="color-tabletrim" border="0" cellpadding="2" cellspacing="1" width="100%">
<tr class="color-tableheader">
<td background="images/dialogtop.gif" height="20" width="100%"><strong class="titlerev"> <? echo $tunnel[$id][TUNNEL_USERNAME]; ?> - Last Print</strong></td>
</tr>
<tr>
<td></td>
</tr>
<tr class="c" scope="row">
<td height="20" nowrap="nowrap"><font class="datasheetField"><? echo $tunnel[$id]['printdata']; ?></td>
</tr>
<tr class="color-tableheader">
<td background="images/dialogtop.gif" height="20" width="100%"><strong class="titlerev"> <? echo $tunnel[$id][TUNNEL_USERNAME]; ?> - Last Successful Print </strong></td>
</tr>
<tr class="c" scope="row">
<td><font class="datasheetField">Something else here.</font></td>
</tr>
</table>
<?
}
function printerplugin_printers_version()
{
return '1.0';
}
?>