* Mon May 12 2025 Brian Read <brianr@koozali.org> 11.0.0-1.sme
- Adding SM2 panel [SME: 13004] - Upgrade to phpsysinfo 3.4.4 - Add code to delete inline styles and add css to make it look better. - version saved / built uses the static version, which means no drops downs and choices.
This commit is contained in:
@@ -1,25 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* SNMPPInfo Plugin
|
||||
*
|
||||
* PHP version 5
|
||||
* SNMPPInfo Plugin, which displays printers info via SNMP
|
||||
*
|
||||
* @category PHP
|
||||
* @package PSI_Plugin_SNMPPInfo
|
||||
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
|
||||
* @copyright 2011 phpSysInfo
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
|
||||
* @version SVN: $Id: class.snmppinfo.inc.php 661 2012-08-27 11:26:39Z namiltd $
|
||||
* @link http://phpsysinfo.sourceforge.net
|
||||
*/
|
||||
/**
|
||||
* SNMPPInfo Plugin, which displays battery state
|
||||
*
|
||||
* @category PHP
|
||||
* @package PSI_Plugin_SNMPPInfo
|
||||
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
|
||||
* @copyright 2011 phpSysInfo
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
|
||||
* @version $Id: class.snmppinfo.inc.php 661 2012-08-27 11:26:39Z namiltd $
|
||||
* @link http://phpsysinfo.sourceforge.net
|
||||
*/
|
||||
@@ -54,23 +41,32 @@ class SNMPPInfo extends PSI_Plugin
|
||||
$printers = array(PSI_PLUGIN_SNMPPINFO_DEVICES);
|
||||
}
|
||||
foreach ($printers as $printer) {
|
||||
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 ".$printer." .1.3.6.1.2.1.1.5", $buffer, PSI_DEBUG);
|
||||
if (strlen(trim($buffer)) > 0) {
|
||||
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$printer." .1.3.6.1.2.1.1.5", $buffer, PSI_DEBUG);
|
||||
if (strlen($buffer) > 0) {
|
||||
$this->_filecontent[$printer] = $buffer;
|
||||
|
||||
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 ".$printer." .1.3.6.1.2.1.43.11.1.1", $buffer2, PSI_DEBUG);
|
||||
if (strlen(trim($buffer2)) > 0) {
|
||||
$this->_filecontent[$printer] = $this->_filecontent[$printer]."\n".$buffer2;
|
||||
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$printer." .1.3.6.1.4.1.367.3.2.1.2.24.1.1", $buffer1, false);
|
||||
if (strlen($buffer1) > 0) {
|
||||
$this->_filecontent[$printer] .= "\n".$buffer1;
|
||||
}
|
||||
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 ".$printer." .1.3.6.1.2.1.43.18.1.1", $buffer3, PSI_DEBUG);
|
||||
if (strlen(trim($buffer3)) > 0) {
|
||||
$this->_filecontent[$printer] = $this->_filecontent[$printer]."\n".$buffer3;
|
||||
|
||||
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$printer." .1.3.6.1.2.1.43.11.1.1", $buffer2, PSI_DEBUG);
|
||||
if (strlen($buffer2) > 0) {
|
||||
$this->_filecontent[$printer] .= "\n".$buffer2;
|
||||
}
|
||||
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$printer." .1.3.6.1.2.1.43.18.1.1", $buffer3, PSI_DEBUG);
|
||||
if (strlen($buffer3) > 0) {
|
||||
$this->_filecontent[$printer] .= "\n".$buffer3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case 'php-snmp':
|
||||
if (!extension_loaded("snmp")) {
|
||||
$this->global_error->addError("Requirements error", "SNMPPInfo plugin requires the snmp extension to php in order to work properly");
|
||||
break;
|
||||
}
|
||||
snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
|
||||
snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
|
||||
if (defined('PSI_PLUGIN_SNMPPINFO_DEVICES') && is_string(PSI_PLUGIN_SNMPPINFO_DEVICES)) {
|
||||
@@ -85,7 +81,7 @@ class SNMPPInfo extends PSI_Plugin
|
||||
$old_err_rep = error_reporting();
|
||||
error_reporting(E_ERROR); /* fatal errors only */
|
||||
}
|
||||
$bufferarr=snmprealwalk($printer, "public", ".1.3.6.1.2.1.1.5", 1000000, 1);
|
||||
$bufferarr=snmprealwalk($printer, "public", ".1.3.6.1.2.1.1.5", 1000000 * PSI_SNMP_TIMEOUT_INT, PSI_SNMP_RETRY_INT);
|
||||
if (! PSI_DEBUG) {
|
||||
error_reporting($old_err_rep); /* restore error level */
|
||||
set_error_handler('errorHandlerPsi'); /* restore error handler */
|
||||
@@ -93,22 +89,20 @@ class SNMPPInfo extends PSI_Plugin
|
||||
if (! empty($bufferarr)) {
|
||||
$buffer="";
|
||||
foreach ($bufferarr as $id=>$string) {
|
||||
$buffer=$buffer.$id." = ".$string."\n";
|
||||
$buffer .= $id." = ".$string."\n";
|
||||
}
|
||||
|
||||
if (! PSI_DEBUG) {
|
||||
restore_error_handler(); /* default error handler */
|
||||
$old_err_rep = error_reporting();
|
||||
error_reporting(E_ERROR); /* fatal errors only */
|
||||
}
|
||||
$bufferarr2=snmprealwalk($printer, "public", ".1.3.6.1.2.1.43.11.1.1", 1000000, 1);
|
||||
if (! PSI_DEBUG) {
|
||||
error_reporting($old_err_rep); /* restore error level */
|
||||
set_error_handler('errorHandlerPsi'); /* restore error handler */
|
||||
}
|
||||
if (! empty($bufferarr2)) {
|
||||
foreach ($bufferarr2 as $id=>$string) {
|
||||
$buffer=$buffer.$id." = ".$string."\n";
|
||||
restore_error_handler(); /* default error handler */
|
||||
$old_err_rep = error_reporting();
|
||||
error_reporting(E_ERROR); /* fatal errors only */
|
||||
|
||||
$bufferarr1=snmprealwalk($printer, "public", ".1.3.6.1.4.1.367.3.2.1.2.24.1.1", 1000000 * PSI_SNMP_TIMEOUT_INT, PSI_SNMP_RETRY_INT);
|
||||
|
||||
error_reporting($old_err_rep); /* restore error level */
|
||||
set_error_handler('errorHandlerPsi'); /* restore error handler */
|
||||
if (! empty($bufferarr1)) {
|
||||
foreach ($bufferarr1 as $id=>$string) {
|
||||
$buffer .= $id." = ".$string."\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,14 +111,30 @@ class SNMPPInfo extends PSI_Plugin
|
||||
$old_err_rep = error_reporting();
|
||||
error_reporting(E_ERROR); /* fatal errors only */
|
||||
}
|
||||
$bufferarr3=snmprealwalk($printer, "public", ".1.3.6.1.2.1.43.18.1.1", 1000000, 1);
|
||||
$bufferarr2=snmprealwalk($printer, "public", ".1.3.6.1.2.1.43.11.1.1", 1000000 * PSI_SNMP_TIMEOUT_INT, PSI_SNMP_RETRY_INT);
|
||||
if (! PSI_DEBUG) {
|
||||
error_reporting($old_err_rep); /* restore error level */
|
||||
set_error_handler('errorHandlerPsi'); /* restore error handler */
|
||||
}
|
||||
if (! empty($bufferarr2)) {
|
||||
foreach ($bufferarr2 as $id=>$string) {
|
||||
$buffer .= $id." = ".$string."\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (! PSI_DEBUG) {
|
||||
restore_error_handler(); /* default error handler */
|
||||
$old_err_rep = error_reporting();
|
||||
error_reporting(E_ERROR); /* fatal errors only */
|
||||
}
|
||||
$bufferarr3=snmprealwalk($printer, "public", ".1.3.6.1.2.1.43.18.1.1", 1000000 * PSI_SNMP_TIMEOUT_INT, PSI_SNMP_RETRY_INT);
|
||||
if (! PSI_DEBUG) {
|
||||
error_reporting($old_err_rep); /* restore error level */
|
||||
set_error_handler('errorHandlerPsi'); /* restore error handler */
|
||||
}
|
||||
if (! empty($bufferarr3)) {
|
||||
foreach ($bufferarr3 as $id=>$string) {
|
||||
$buffer=$buffer.$id." = ".$string."\n";
|
||||
$buffer .= $id." = ".$string."\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +144,7 @@ class SNMPPInfo extends PSI_Plugin
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case 'data':
|
||||
if (defined('PSI_PLUGIN_SNMPPINFO_DEVICES') && is_string(PSI_PLUGIN_SNMPPINFO_DEVICES)) {
|
||||
if (preg_match(ARRAY_EXP, PSI_PLUGIN_SNMPPINFO_DEVICES)) {
|
||||
@@ -145,7 +155,7 @@ class SNMPPInfo extends PSI_Plugin
|
||||
$pn=0;
|
||||
foreach ($printers as $printer) {
|
||||
$buffer="";
|
||||
if (CommonFunctions::rfts(APP_ROOT."/data/snmppinfo{$pn}.txt", $buffer) && !empty($buffer)) {
|
||||
if (CommonFunctions::rftsdata("snmppinfo{$pn}.tmp", $buffer) && !empty($buffer)) {
|
||||
$this->_filecontent[$printer] = $buffer;
|
||||
}
|
||||
$pn++;
|
||||
@@ -153,8 +163,7 @@ class SNMPPInfo extends PSI_Plugin
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$this->global_error->addError("switch(PSI_PLUGIN_SNMPPINFO_ACCESS)", "Bad SNMPPInfo configuration in phpsysinfo.ini");
|
||||
break;
|
||||
$this->global_error->addConfigError("__construct()", "[snmppinfo] ACCESS");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,28 +179,44 @@ class SNMPPInfo extends PSI_Plugin
|
||||
return;
|
||||
}
|
||||
foreach ($this->_filecontent as $printer=>$result) {
|
||||
$result = preg_replace('/End of MIB\r?\n/', '', $result);
|
||||
$result = preg_replace('/\s\r?\n([^\.])/', ' $1', $result);
|
||||
$lines = preg_split('/\r?\n/', $result);
|
||||
foreach ($lines as $line) {
|
||||
if (preg_match('/^(.+) = Hex-STRING:\s(.+)/', $line, $linetmp)) {
|
||||
$hexchars = explode(" ", trim($linetmp[2]));
|
||||
$newstring = "";
|
||||
foreach ($hexchars as $hexchar) {
|
||||
$hexint = hexdec($hexchar);
|
||||
if (($hexint<32) || ($hexint>126)) {
|
||||
$newstring .= ".";
|
||||
} else {
|
||||
$newstring .= chr($hexint);
|
||||
}
|
||||
}
|
||||
if ($newstring!=="") {
|
||||
$line = $linetmp[1]." = STRING: ".$newstring;
|
||||
}
|
||||
}
|
||||
if (preg_match('/^\.1\.3\.6\.1\.2\.1\.43\.11\.1\.1\.6\.1\.(.*) = STRING:\s(.*)/', $line, $data)) {
|
||||
$this->_result[$printer][$data[1]]['prtMarkerSuppliesDescription']=trim($data[2], "\"");
|
||||
}
|
||||
if (preg_match('/^\.1\.3\.6\.1\.2\.1\.43\.11\.1\.1\.7\.1\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
|
||||
} elseif (preg_match('/^\.1\.3\.6\.1\.2\.1\.43\.11\.1\.1\.7\.1\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
|
||||
$this->_result[$printer][$data[1]]['prtMarkerSuppliesSupplyUnit']=$data[2];
|
||||
}
|
||||
if (preg_match('/^\.1\.3\.6\.1\.2\.1\.43\.11\.1\.1\.8\.1\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
|
||||
} elseif (preg_match('/^\.1\.3\.6\.1\.2\.1\.43\.11\.1\.1\.8\.1\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
|
||||
$this->_result[$printer][$data[1]]['prtMarkerSuppliesMaxCapacity']=$data[2];
|
||||
}
|
||||
if (preg_match('/^\.1\.3\.6\.1\.2\.1\.43\.11\.1\.1\.9\.1\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
|
||||
} elseif (preg_match('/^\.1\.3\.6\.1\.2\.1\.43\.11\.1\.1\.9\.1\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
|
||||
$this->_result[$printer][$data[1]]['prtMarkerSuppliesLevel']=$data[2];
|
||||
}
|
||||
if (preg_match('/^\.1\.3\.6\.1\.2\.1\.1\.5\.0 = STRING:\s(.*)/', $line, $data)) {
|
||||
$this->_result[$printer][0]['prtMarkerSuppliesDescription']=trim($data[1], "\"");;
|
||||
}
|
||||
if (preg_match('/^\.1\.3\.6\.1\.2\.1\.43\.18\.1\.1\.8\.1\.(.*) = STRING:\s(.*)/', $line, $data)) {
|
||||
} elseif (preg_match('/^\.1\.3\.6\.1\.2\.1\.1\.5\.0 = STRING:\s(.*)/', $line, $data)) {
|
||||
$this->_result[$printer][0]['prtMarkerSuppliesDescription']=trim($data[1], "\"");
|
||||
} elseif (preg_match('/^\.1\.3\.6\.1\.2\.1\.43\.18\.1\.1\.8\.1\.(.*) = STRING:\s(.*)/', $line, $data)) {
|
||||
$this->_result[$printer][99][$data[1]]["message"]=trim($data[2], "\"");
|
||||
}
|
||||
if (preg_match('/^\.1\.3\.6\.1\.2\.1\.43\.18\.1\.1\.2\.1\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
|
||||
} elseif (preg_match('/^\.1\.3\.6\.1\.2\.1\.43\.18\.1\.1\.2\.1\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
|
||||
$this->_result[$printer][99][$data[1]]["severity"]=$data[2];
|
||||
|
||||
} elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.367\.3\.2\.1\.2\.24\.1\.1\.2\.(.*) = STRING:\s(.*)/', $line, $data)) {
|
||||
$this->_result[$printer][$data[1]]['prtMarkerSuppliesDescriptionRicoh']=trim($data[2], "\"");
|
||||
} elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.367\.3\.2\.1\.2\.24\.1\.1\.5\.(.*) = INTEGER:\s(.*)/', $line, $data)) {
|
||||
$this->_result[$printer][$data[1]]['prtMarkerSuppliesLevelRicoh']=$data[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -207,8 +232,15 @@ class SNMPPInfo extends PSI_Plugin
|
||||
foreach ($this->_result as $printer=>$markersupplies_item) {
|
||||
$xmlsnmppinfo_printer = $this->xml->addChild("Printer");
|
||||
$xmlsnmppinfo_printer->addAttribute("Device", $printer);
|
||||
foreach ($markersupplies_item as $marker=>$snmppinfo_item) {
|
||||
if (isset($markersupplies_item[1]) &&
|
||||
isset($markersupplies_item[1]['prtMarkerSuppliesDescriptionRicoh']) &&
|
||||
isset($markersupplies_item[1]['prtMarkerSuppliesLevelRicoh'])) {
|
||||
$ricoh = true;
|
||||
} else {
|
||||
$ricoh = false;
|
||||
}
|
||||
|
||||
foreach ($markersupplies_item as $marker=>$snmppinfo_item) {
|
||||
if ($marker==0) {
|
||||
$xmlsnmppinfo_printer->addAttribute("Name", $snmppinfo_item['prtMarkerSuppliesDescription']);
|
||||
} elseif ($marker==99) {
|
||||
@@ -220,16 +252,23 @@ class SNMPPInfo extends PSI_Plugin
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$xmlsnmppinfo = $xmlsnmppinfo_printer->addChild("MarkerSupplies");
|
||||
if ($ricoh) {
|
||||
if (isset($snmppinfo_item['prtMarkerSuppliesDescriptionRicoh'])) {
|
||||
$xmlsnmppinfo = $xmlsnmppinfo_printer->addChild("MarkerSupplies");
|
||||
|
||||
if (isset($snmppinfo_item['prtMarkerSuppliesDescription']))
|
||||
$xmlsnmppinfo->addAttribute("Description", $snmppinfo_item['prtMarkerSuppliesDescription']);
|
||||
else
|
||||
$xmlsnmppinfo->addAttribute("Description", ""); /* empty on some devices */
|
||||
$xmlsnmppinfo->addAttribute("Description", $snmppinfo_item['prtMarkerSuppliesDescriptionRicoh']);
|
||||
$xmlsnmppinfo->addAttribute("SupplyUnit", "19");
|
||||
$xmlsnmppinfo->addAttribute("MaxCapacity", "100");
|
||||
$xmlsnmppinfo->addAttribute("Level", isset($snmppinfo_item['prtMarkerSuppliesLevelRicoh']) ? $snmppinfo_item['prtMarkerSuppliesLevelRicoh'] : "");
|
||||
}
|
||||
} else {
|
||||
$xmlsnmppinfo = $xmlsnmppinfo_printer->addChild("MarkerSupplies");
|
||||
|
||||
$xmlsnmppinfo->addAttribute("SupplyUnit", $snmppinfo_item['prtMarkerSuppliesSupplyUnit']);
|
||||
$xmlsnmppinfo->addAttribute("MaxCapacity", $snmppinfo_item['prtMarkerSuppliesMaxCapacity']);
|
||||
$xmlsnmppinfo->addAttribute("Level", $snmppinfo_item['prtMarkerSuppliesLevel']);
|
||||
$xmlsnmppinfo->addAttribute("Description", isset($snmppinfo_item['prtMarkerSuppliesDescription']) ? $snmppinfo_item['prtMarkerSuppliesDescription'] : "");
|
||||
$xmlsnmppinfo->addAttribute("SupplyUnit", isset($snmppinfo_item['prtMarkerSuppliesSupplyUnit']) ? $snmppinfo_item['prtMarkerSuppliesSupplyUnit'] : "");
|
||||
$xmlsnmppinfo->addAttribute("MaxCapacity", isset($snmppinfo_item['prtMarkerSuppliesMaxCapacity']) ? $snmppinfo_item['prtMarkerSuppliesMaxCapacity'] : "");
|
||||
$xmlsnmppinfo->addAttribute("Level", isset($snmppinfo_item['prtMarkerSuppliesLevel']) ? $snmppinfo_item['prtMarkerSuppliesLevel'] : "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user