From 2f881e3d80f70b94dd2bf407e7be3bd5f346109c Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Sun, 16 Apr 2017 01:42:22 -0500 Subject: [PATCH] improve callback serial number regex (#6435) Adds S/N and Serial Num/number --- includes/callback.php | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/includes/callback.php b/includes/callback.php index 5039f648dc..9dbb3c58d5 100644 --- a/includes/callback.php +++ b/includes/callback.php @@ -85,19 +85,16 @@ if ($enabled == 1) { }, $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']); + $sn_patterns = array('/[A-Z]/', '/[a-z]/', '/[0-9]/'); + $sn_replacements = array('A', 'a', '0'); + $entry['sysDescr'] = preg_replace_callback( + '/((s\/?n|serial num(ber)?)[:=]? ?)([a-z0-9.\-]{4,16})/i', + function ($matches) use ($sn_patterns, $sn_replacements) { + return $matches[1] . preg_replace($sn_patterns, $sn_replacements, $matches[4]); + }, + $entry['sysDescr'] + ); + return $entry; }, $device_info);