I'm having problems with the output values returned by some scripts because cacti is interpreting them as hexadecimal values.
Example:
is_hex.php
Code: Select all
<?php
function is_hexadecimal($hexstr) {
$hexstr = trim($hexstr);
$i = 0;
$length = strlen($hexstr);
while ($i < $length) {
$part = substr($hexstr,$i,2);
$i += 2;
if (!preg_match('/[a-fA-F0-9]/', $part)) {
return false;
} elseif ($i < $length) {
if (substr($hexstr,$i,1) != ":") {
return false;
}elseif ($i + 1 == $length) {
return false;
}
$i++;
}else{
$i++;
}
}
return true;
}
if ( is_hexadecimal($_SERVER["argv"][1]) ) {
echo "Is hexadecimal!\n";
} else {
echo "Not hexadecimal!\n";
}
?>
Code: Select all
$ php is_hex.php "jc:1"
Is hexadecimal!
Code: Select all
$ php is_hex.php "zf:5y:2"
Is hexadecimal!
Thank you!
PS: The function is_hexadecimal is inside cacti/site/lib/functions.php
PS2: Fixed this by replacing the regex with ^[a-fA-F0-9]{2}$. I would still like to know if this is really a bug or if by changing this I'm messing with something else..