From 13025158fd05a05e8df6937a5c10ca2984518a93 Mon Sep 17 00:00:00 2001 From: Mark Crane Date: Fri, 3 Jan 2014 23:11:42 +0000 Subject: [PATCH] Add device key extension for yealink. Add a device class. --- app/devices/app_languages.php | 6 ++ app/devices/device_edit.php | 54 +++++------ app/devices/device_key_edit.php | 18 ++++ app/devices/devices.php | 8 +- app/devices/resources/classes/device.php | 111 +++++++++++++++++++++++ 5 files changed, 161 insertions(+), 36 deletions(-) create mode 100644 app/devices/resources/classes/device.php diff --git a/app/devices/app_languages.php b/app/devices/app_languages.php index 3cf2186520..391666115d 100644 --- a/app/devices/app_languages.php +++ b/app/devices/app_languages.php @@ -253,6 +253,12 @@ $text['description-device_key_value']['en-us'] = 'Enter the value.'; $text['description-device_key_value']['pt-pt'] = ''; + $text['label-device_key_extension']['en-us'] = 'Extension'; + $text['label-device_key_extension']['pt-pt'] = ''; + + $text['description-device_key_extension']['en-us'] = 'Enter the extension.'; + $text['description-device_key_extension']['pt-pt'] = ''; + $text['label-device_key_label']['en-us'] = 'Label'; $text['label-device_key_label']['pt-pt'] = ''; diff --git a/app/devices/device_edit.php b/app/devices/device_edit.php index a3947a9941..70e5cf12a7 100644 --- a/app/devices/device_edit.php +++ b/app/devices/device_edit.php @@ -41,6 +41,9 @@ require_once "resources/require.php"; $text[$key] = $value[$_SESSION['domain']['language']['code']]; } +//include the device class + require_once "app/devices/resources/classes/device.php"; + //action add or update if (isset($_REQUEST["id"])) { $action = "update"; @@ -80,6 +83,7 @@ require_once "resources/require.php"; $device_key_type = check_str($_POST["device_key_type"]); $device_key_line = check_str($_POST["device_key_line"]); $device_key_value = check_str($_POST["device_key_value"]); + $device_key_extension = check_str($_POST["device_key_extension"]); $device_key_label = check_str($_POST["device_key_label"]); //settings //$device_setting_category = check_str($_POST["device_setting_category"]); @@ -90,38 +94,9 @@ require_once "resources/require.php"; $device_setting_description = check_str($_POST["device_setting_description"]); } -//use the mac address to find the vendor +//use the mac address to get the vendor if (strlen($device_vendor) == 0) { - switch (substr($device_mac_address, 0, 6)) { - case "00085d": - $device_vendor = "aastra"; - break; - case "000e08": - $device_vendor = "linksys"; - break; - case "0004f2": - $device_vendor = "polycom"; - break; - case "00907a": - $device_vendor = "polycom"; - break; - case "001873": - $device_vendor = "cisco"; - break; - case "00045a": - $device_vendor = "linksys"; - break; - case "000625": - $device_vendor = "linksys"; - break; - case "001565": - $device_vendor = "yealink"; - break; - case "000413": - $device_vendor = "snom"; - default: - $device_vendor = ""; - } + $device_vendor = device::get_vendor($device_mac_address); } //add or update the database @@ -264,6 +239,7 @@ require_once "resources/require.php"; $sql .= "device_key_type, "; $sql .= "device_key_line, "; $sql .= "device_key_value, "; + $sql .= "device_key_extension, "; $sql .= "device_key_label "; $sql .= ")"; $sql .= " values "; @@ -276,6 +252,7 @@ require_once "resources/require.php"; $sql .= "'$device_key_type', "; $sql .= "'$device_key_line', "; $sql .= "'$device_key_value', "; + $sql .= "'$device_key_extension', "; $sql .= "'$device_key_label' "; $sql .= ")"; $db->exec(check_sql($sql)); @@ -329,7 +306,7 @@ require_once "resources/require.php"; } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) //pre-populate the form - if (count($_GET)>0 && $_POST["persistformvar"] != "true") { + if (count($_GET) > 0 && $_POST["persistformvar"] != "true") { $device_uuid = check_str($_GET["id"]); $sql = "select * from v_devices "; $sql .= "where domain_uuid = '$domain_uuid' "; @@ -354,6 +331,11 @@ require_once "resources/require.php"; unset ($prep_statement); } +//use the mac address to get the vendor + if (strlen($device_vendor) == 0) { + $device_vendor = device::get_vendor($device_mac_address); + } + //show the header require_once "resources/header.php"; @@ -565,6 +547,7 @@ require_once "resources/require.php"; echo " ".$text['label-device_key_type']."\n"; echo " ".$text['label-device_key_line']."\n"; echo " ".$text['label-device_key_value']."\n"; + echo " ".$text['label-device_key_extension']."\n"; echo " ".$text['label-device_key_label']."\n"; echo "  \n"; echo " \n"; @@ -600,6 +583,9 @@ require_once "resources/require.php"; echo " ".$row['device_key_value']." \n"; echo " \n"; echo " \n"; + echo " ".$row['device_key_extension']." \n"; + echo " \n"; + echo " \n"; echo " ".$row['device_key_label']." \n"; echo " \n"; echo " \n"; @@ -758,6 +744,10 @@ require_once "resources/require.php"; echo " \n"; echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + echo "\n"; echo " \n"; echo "\n"; diff --git a/app/devices/device_key_edit.php b/app/devices/device_key_edit.php index f54a235755..60042981db 100644 --- a/app/devices/device_key_edit.php +++ b/app/devices/device_key_edit.php @@ -61,6 +61,7 @@ else { $device_key_type = check_str($_POST["device_key_type"]); $device_key_line = check_str($_POST["device_key_line"]); $device_key_value = check_str($_POST["device_key_value"]); + $device_key_extension = check_str($_POST["device_key_extension"]); $device_key_label = check_str($_POST["device_key_label"]); } @@ -77,6 +78,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { //if (strlen($device_key_type) == 0) { $msg .= $text['message-required']." ".$text['label-device_key_type']."
\n"; } //if (strlen($device_key_line) == 0) { $msg .= $text['message-required']." ".$text['label-device_key_line']."
\n"; } //if (strlen($device_key_value) == 0) { $msg .= $text['message-required']." ".$text['label-device_key_value']."
\n"; } + //if (strlen($device_key_extension) == 0) { $msg .= $text['message-required']." ".$text['label-device_key_extension']."
\n"; } //if (strlen($device_key_label) == 0) { $msg .= $text['message-required']." ".$text['label-device_key_label']."
\n"; } if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { require_once "resources/header.php"; @@ -104,6 +106,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $sql .= "device_key_type, "; $sql .= "device_key_line, "; $sql .= "device_key_value, "; + $sql .= "device_key_extension, "; $sql .= "device_key_label "; $sql .= ")"; $sql .= "values "; @@ -115,6 +118,8 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $sql .= "'$device_key_category', "; $sql .= "'$device_key_type', "; $sql .= "'$device_key_line', "; + $sql .= "'$device_key_value', "; + $sql .= "'$device_key_extension', "; $sql .= "'$device_key_label' "; $sql .= ")"; $db->exec(check_sql($sql)); @@ -136,6 +141,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $sql .= "device_key_type = '$device_key_type', "; $sql .= "device_key_line = '$device_key_line', "; $sql .= "device_key_value = '$device_key_value', "; + $sql .= "device_key_extension = '$device_key_extension', "; $sql .= "device_key_label = '$device_key_label' "; $sql .= "where domain_uuid = '$domain_uuid' "; $sql .= "and device_key_uuid = '$device_key_uuid' "; @@ -168,6 +174,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $device_key_type = $row["device_key_type"]; $device_key_line = $row["device_key_line"]; $device_key_value = $row["device_key_value"]; + $device_key_extension = $row["device_key_extension"]; $device_key_label = $row["device_key_label"]; } unset ($prep_statement); @@ -531,6 +538,17 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { echo "\n"; echo "\n"; + echo "\n"; + echo "\n"; + echo " ".$text['label-device_key_extension'].":\n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-device_key_extension']."\n"; + echo "\n"; + echo "\n"; + echo "\n"; echo "\n"; echo " ".$text['label-device_key_label'].":\n"; diff --git a/app/devices/devices.php b/app/devices/devices.php index cc2ad47618..ae5e92dd15 100644 --- a/app/devices/devices.php +++ b/app/devices/devices.php @@ -112,8 +112,8 @@ else { //echo th_order_by('device_uuid', $text['label-device_uuid'], $order_by, $order); echo th_order_by('device_mac_address', $text['label-device_mac_address'], $order_by, $order); echo th_order_by('device_label', $text['label-device_label'], $order_by, $order); - //echo th_order_by('device_vendor', $text['label-device_vendor'], $order_by, $order); - echo th_order_by('device_model', $text['label-device_model'], $order_by, $order); + echo th_order_by('device_vendor', $text['label-device_vendor'], $order_by, $order); + //echo th_order_by('device_model', $text['label-device_model'], $order_by, $order); //echo th_order_by('device_firmware_version', $text['label-device_firmware_version'], $order_by, $order); echo th_order_by('device_provision_enable', $text['label-device_provision_enable'], $order_by, $order); echo th_order_by('device_template', $text['label-device_template'], $order_by, $order); @@ -140,8 +140,8 @@ else { //echo " ".$row['device_uuid']." \n"; echo " ".$row['device_mac_address']." \n"; echo " ".$row['device_label']." \n"; - //echo " ".$row['device_vendor']." \n"; - echo " ".$row['device_model']." \n"; + echo " ".$row['device_vendor']." \n"; + //echo " ".$row['device_model']." \n"; //echo " ".$row['device_firmware_version']." \n"; echo " ".$row['device_provision_enable']." \n"; echo " ".$row['device_template']." \n"; diff --git a/app/devices/resources/classes/device.php b/app/devices/resources/classes/device.php new file mode 100644 index 0000000000..c8ea8ab6d0 --- /dev/null +++ b/app/devices/resources/classes/device.php @@ -0,0 +1,111 @@ + + Copyright (C) 2010 + All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ +include "root.php"; + +//define the device class + class device { + public $db; + public $domain_uuid; + + public function __construct() { + //require_once "resources/classes/database.php"; + } + + public function __destruct() { + foreach ($this as $key => $value) { + unset($this->$key); + } + } + + public function get_domain_uuid() { + return $this->domain_uuid; + } + + public function get_vendor($mac){ + //use the mac address to find the vendor + $mac = preg_replace('#[^a-fA-F0-9./]#', '', $mac); + $mac = strtolower($mac); + switch (substr($mac, 0, 6)) { + case "00085d": + $device_vendor = "aastra"; + break; + case "000e08": + $device_vendor = "linksys"; + break; + case "0004f2": + $device_vendor = "polycom"; + break; + case "00907a": + $device_vendor = "polycom"; + break; + case "0080f0": + $device_vendor = "panasonic"; + break; + case "001873": + $device_vendor = "cisco"; + break; + case "a44c11": + $device_vendor = "cisco"; + break; + case "0021A0": + $device_vendor = "cisco"; + break; + case "30e4db": + $device_vendor = "cisco"; + break; + case "002155": + $device_vendor = "cisco"; + break; + case "68efbd": + $device_vendor = "cisco"; + break; + case "00045a": + $device_vendor = "linksys"; + break; + case "000625": + $device_vendor = "linksys"; + break; + case "001565": + $device_vendor = "yealink"; + break; + case "000413": + $device_vendor = "snom"; + break; + case "000b82": + $device_vendor = "grandstream"; + break; + case "00177d": + $device_vendor = "konftel"; + break; + default: + $device_vendor = ""; + } + return $device_vendor; + } + + } + +?> \ No newline at end of file