diff --git a/includes/callback.php b/includes/callback.php index 853a39423c..0462461fcb 100644 --- a/includes/callback.php +++ b/includes/callback.php @@ -79,8 +79,25 @@ if ($enabled == 1) { // sanitize sysDescr $device_info = array_map(function ($entry) { - $entry['sysDescr'] = preg_replace('/^Linux [A-Za-z\-0-9\.]+ (?=[0-9\.]{5,9})/', 'Linux hostname ', $entry['sysDescr']); - $entry['sysDescr'] = preg_replace('/ SN: [A-Z0-9]{12}/', ' SN: 0A0A0A0A0A0A ', $entry['sysDescr']); + // remove hostnames from linux and macosx + $entry['sysDescr'] = preg_replace_callback('/^(Linux |Darwin )[A-Za-z0-9._\-]+ ([0-9.]{5,9})/', function ($matches) { + return $matches[1] . 'hostname ' .$matches[2]; + }, $entry['sysDescr']); + + // wipe serial numbers, preserve the format + $entry['sysDescr'] = preg_replace_callback('/(SN[:=]? ?)([A-Za-z0-9.\-]{4,16})/', function ($matches) { + $patterns = array( + '/[A-Z]/', + '/[a-z]/', + '/[0-9]/' + ); + $replacements = array( + 'A', + 'a', + '0' + ); + return $matches[1] . preg_replace($patterns, $replacements, $matches[2]); + }, $entry['sysDescr']); return $entry; }, $device_info);