From 6ecb3acc5144aea80821a11bbb5ca715e2e9bdac Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Wed, 1 Mar 2017 04:23:38 -0600 Subject: [PATCH] Improve stats data scrubbing (#6041) Include Darwin (OSX) in the Linux hostname scrubbing, add underscores too. Way more generic serial number replacement. Preserves the format of the serial number, but removes the data. --- includes/callback.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) 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);