diff --git a/app/devices/cmd.php b/app/devices/cmd.php index 4e46ab13a9..8b6c206b06 100644 --- a/app/devices/cmd.php +++ b/app/devices/cmd.php @@ -46,35 +46,7 @@ else { $show = check_str($_GET['show']); $user = check_str($_GET['user']); $agent = check_str($_GET['agent']); - -//get the vendor - if (preg_replace('/^.*?(aastra).*$/i', '$1', strtolower($agent)) == "aastra") { - $vendor = "aastra"; - } - if (preg_replace('/^.*?(cisco).*$/i', '$1', strtolower($agent)) == "cisco") { - $vendor = "cisco"; - } - if (preg_replace('/^.*?(cisco\/spa).*$/i', '$1', strtolower($agent)) == "cisco/spa") { - $vendor = "cisco-spa"; - } - if (preg_replace('/^.*?(grandstream).*$/i', '$1', strtolower($agent)) == "grandstream") { - $vendor = "grandstream"; - } - if (preg_replace('/^.*?(linksys).*$/i', '$1', strtolower($agent)) == "linksys") { - $vendor = "linksys"; - } - if (preg_replace('/^.*?(polycom).*$/i', '$1', strtolower($agent)) == "polycom") { - $vendor = "polycom"; - } - if (preg_replace('/^.*?(yealink).*$/i', '$1', strtolower($agent)) == "yealink") { - $vendor = "yealink"; - } - if (preg_replace('/^.*?(vp530p).*$/i', '$1', strtolower($agent)) == "vp530p") { - $vendor = "yealink"; - } - if (preg_replace('/^.*?(snom).*$/i', '$1', strtolower($agent)) == "snom") { - $vendor = "snom"; - } + $vendor = device::get_vendor_by_agent($agent); //create the event socket connection $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); diff --git a/app/devices/resources/classes/device.php b/app/devices/resources/classes/device.php index ddc93644ba..78054517a8 100644 --- a/app/devices/resources/classes/device.php +++ b/app/devices/resources/classes/device.php @@ -113,6 +113,50 @@ include "root.php"; return $device_vendor; } + public static function get_vendor_by_agent($agent){ + if ($agent) { + $agent = strtolower($agent); + //get the vendor + if (preg_replace('/^.*?(aastra).*$/i', '$1', $agent) == "aastra") { + return "aastra"; + } + if (preg_replace('/^.*?(cisco).*$/i', '$1', $agent) == "cisco") { + return "cisco"; + } + if (preg_replace('/^.*?(cisco\/spa).*$/i', '$1', $agent) == "cisco/spa") { + return "cisco-spa"; + } + if (preg_replace('/^.*?(grandstream).*$/i', '$1', $agent) == "grandstream") { + return "grandstream"; + } + if (preg_replace('/^.*?(linksys).*$/i', '$1', $agent) == "linksys") { + return "linksys"; + } + if (preg_replace('/^.*?(polycom).*$/i', '$1', $agent) == "polycom") { + return "polycom"; + } + if (preg_replace('/^.*?(yealink).*$/i', '$1', $agent) == "yealink") { + return "yealink"; + } + if (preg_replace('/^.*?(vp530p).*$/i', '$1', $agent) == "vp530p") { + return "yealink"; + } + if (preg_replace('/^.*?(snom).*$/i', '$1', $agent) == "snom") { + return "snom"; + } + if (preg_match('/^.*?addpac.*$/i', $agent)) { + return "addpac"; + } + /*Escene use User-Agent string like `ES320VN2 v4.0 ... or `ES206 v1.0 ...` */ + if (preg_match('/^es\d\d\d.*$/i', $agent)) { + return "escene"; + } + } + + // unknown vendor + return ""; + } + public function get_template_dir() { //set the default template directory if (PHP_OS == "Linux") { diff --git a/app/registrations/cmd.php b/app/registrations/cmd.php index 6a010d125d..35dcbd99b9 100644 --- a/app/registrations/cmd.php +++ b/app/registrations/cmd.php @@ -46,35 +46,7 @@ else { $show = check_str($_GET['show']); $user = check_str($_GET['user']); $agent = check_str($_GET['agent']); - -//get the vendor - if (preg_replace('/^.*?(aastra).*$/i', '$1', strtolower($agent)) == "aastra") { - $vendor = "aastra"; - } - if (preg_replace('/^.*?(cisco).*$/i', '$1', strtolower($agent)) == "cisco") { - $vendor = "cisco"; - } - if (preg_replace('/^.*?(cisco\/spa).*$/i', '$1', strtolower($agent)) == "cisco/spa") { - $vendor = "cisco-spa"; - } - if (preg_replace('/^.*?(grandstream).*$/i', '$1', strtolower($agent)) == "grandstream") { - $vendor = "grandstream"; - } - if (preg_replace('/^.*?(linksys).*$/i', '$1', strtolower($agent)) == "linksys") { - $vendor = "linksys"; - } - if (preg_replace('/^.*?(polycom).*$/i', '$1', strtolower($agent)) == "polycom") { - $vendor = "polycom"; - } - if (preg_replace('/^.*?(yealink).*$/i', '$1', strtolower($agent)) == "yealink") { - $vendor = "yealink"; - } - if (preg_replace('/^.*?(vp530p).*$/i', '$1', strtolower($agent)) == "vp530p") { - $vendor = "yealink"; - } - if (preg_replace('/^.*?(snom).*$/i', '$1', strtolower($agent)) == "snom") { - $vendor = "snom"; - } + $vendor = device::get_vendor_by_agent($agent); //create the event socket connection $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);