--- cacti-0.8.5/lib/snmp.php 2004-02-03 01:21:08.000000000 -0500 +++ cacti-0.8.6/lib/snmp.php 2004-02-24 23:38:58.000000000 -0500 @@ -24,7 +24,16 @@ +-------------------------------------------------------------------------+ */ -define ("REGEXP_SNMP_TRIM", "(hex|counter(32|64)|gauge|gauge(32|64)|float|ipaddress|string|integer):"); +define("REGEXP_SNMP_TRIM", "(hex|counter(32|64)|gauge|gauge(32|64)|float|ipaddress|string|integer):"); + +/* we must use an apostrophe to escape community names under Unix in case the user uses +characters that the shell might interpret. the ucd-snmp binaries on Windows flip out when +you do this, but are perfectly happy with a quotation mark. */ +if ($config["cacti_server_os"] == "unix") { + define("SNMP_ESCAPE_CHARACTER", "'"); +}else{ + define("SNMP_ESCAPE_CHARACTER", "\""); +} function cacti_snmp_get($hostname, $community, $oid, $version, $username, $password, $port = 161, $timeout = 1000) { global $config; @@ -40,9 +49,9 @@ $timeout = ceil($timeout / 1000); if ($version == "1") { - $snmp_auth = (read_config_option("snmp_version") == "ucd-snmp") ? "'$community'" : "-c '$community'"; /* v1/v2 - community string */ + $snmp_auth = (read_config_option("snmp_version") == "ucd-snmp") ? SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER : "-c " . SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER; /* v1/v2 - community string */ }elseif ($version == "2") { - $snmp_auth = (read_config_option("snmp_version") == "ucd-snmp") ? "'$community'" : "-c '$community'"; /* v1/v2 - community string */ + $snmp_auth = (read_config_option("snmp_version") == "ucd-snmp") ? SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER : "-c " . SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER; /* v1/v2 - community string */ $version = "2c"; /* ucd/net snmp prefers this over '2' */ }elseif ($version == "3") { $snmp_auth = "-u $username -X $password"; /* v3 - username/password */ @@ -83,9 +92,9 @@ $timeout = ceil($timeout / 1000); if ($version == "1") { - $snmp_auth = (read_config_option("snmp_version") == "ucd-snmp") ? "'$community'" : "-c '$community'"; /* v1/v2 - community string */ + $snmp_auth = (read_config_option("snmp_version") == "ucd-snmp") ? SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER : "-c " . SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER; /* v1/v2 - community string */ }elseif ($version == "2") { - $snmp_auth = (read_config_option("snmp_version") == "ucd-snmp") ? "'$community'" : "-c '$community'"; /* v1/v2 - community string */ + $snmp_auth = (read_config_option("snmp_version") == "ucd-snmp") ? SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER : "-c " . SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER; /* v1/v2 - community string */ $version = "2c"; /* ucd/net snmp prefers this over '2' */ }elseif ($version == "3") { $snmp_auth = "-u $username -X $password"; /* v3 - username/password */