\n";
} else {
while (!feof($fp)) {
$data .= fgets($fp, 128);
}
fclose($fp);
}
if (!function_exists('str_contains')) {
function str_contains($haystack, $needle): bool {
if ( is_string($haystack) && is_string($needle) ) {
return '' === $needle || false !== strpos($haystack, $needle);
} else {
return false;
}
}
}
$ips = json_decode(file_get_contents("./ips.host"), TRUE);
$ar = explode("\n", $data);
$checkNodes = array();
$data = "";
foreach ($ar as &$value) {
$ip = explode('"', $value)[1];
if (filter_var($ip, FILTER_VALIDATE_IP && !isset($ips[$ip]))) {
$ips[$ip] = "NULL";
}
if (!str_contains($value, 'HNA') && !str_contains($value, 'diamond')) {
if (str_contains($value, 'label')) {
$dr = explode('];', $value);
$val = explode('"', explode('label="', $value)[1])[0];
if ($val < 0.98) { $color = "blue"; $pwidth = 1; }
if ($val > 0.99) { $color = "green"; $pwidth = 2.5; }
if ($val > 3.00) { $color = "yellow";$pwidth = 2.5; }
if ($val > 4.00) { $color = "orange"; $pwidth = 3.5; }
if ($val > 6.00) { $color = "red"; $pwidth = 5; }
if ($val == "INFINITE") { $color = "red"; $pwidth = 8; }
//$dr[0] = "10.166.72.127" -> "10.138.41.208"[label="0.100"];
$da = explode('"', $dr[0]);
if (!isset($checkNodes[$da[3]."-".$da[1]])) {
$data .= $dr[0].', penwidth='.$pwidth.' color="'.$color.'"];'."\n";
$checkNodes[$da[1]."-".$da[3]] = "TRUE";
} else {
$data .= $dr[0].', penwidth='.$pwidth.' color="'.$color.'"];'."\n";
}
} else {
$data .= $value."\n";
}
}
}
foreach ($ips as $key => $value) {
if(filter_var($ips[$key], FILTER_VALIDATE_IP) || $ips[$key] == "NULL") {
$ips[$key] = gethostbyaddr($key);
}
$data = str_replace($key, $ips[$key], $data);
}
file_put_contents("./ips.host", json_encode($ips));
//print_r($checkNodes);
echo $data;
?>