Change device_mac_address to device_address

This commit is contained in:
markjcrane
2023-06-29 23:40:11 -06:00
parent 49648e6655
commit 53779d50d3
14 changed files with 3077 additions and 3064 deletions

View File

@@ -28,21 +28,21 @@
if ($domains_processed == 1) {
//normalize the mac address
$sql = "select device_uuid, device_mac_address ";
$sql = "select device_uuid, device_address ";
$sql .= "from v_devices ";
$sql .= "where (device_mac_address like '%-%' or device_mac_address like '%:%') ";
$sql .= "where (device_address like '%-%' or device_address like '%:%') ";
$database = new database;
$result = $database->select($sql, null, 'all');
if (is_array($result) && @sizeof($result) != 0) {
foreach ($result as $row) {
//define update values
$device_uuid = $row["device_uuid"];
$device_mac_address = $row["device_mac_address"];
$device_mac_address = strtolower($device_mac_address);
$device_mac_address = preg_replace('#[^a-fA-F0-9./]#', '', $device_mac_address);
$device_address = $row["device_address"];
$device_address = strtolower($device_address);
$device_address = preg_replace('#[^a-fA-F0-9./]#', '', $device_address);
//build update array
$array['devices'][0]['device_uuid'] = $device_uuid;
$array['devices'][0]['device_mac_address'] = $device_mac_address;
$array['devices'][0]['device_address'] = $device_address;
//grant temporary permissions
$p = new permissions;
$p->add('device_add', 'temp');

View File

@@ -38,18 +38,23 @@
$device_template = '';
//define PHP variables from the HTTP values
$mac = $_REQUEST['mac'];
if (isset($_REQUEST['mac'])) {
$device_address = $_REQUEST['mac'];
}
if (isset($_REQUEST['address'])) {
$device_address = $_REQUEST['address'];
}
$file = $_REQUEST['file'];
$ext = $_REQUEST['ext'];
//if (!empty($_REQUEST['template'])) {
// $device_template = $_REQUEST['template'];
//}
//get the mac address for Cisco 79xx in the URL as &name=SEP000000000000
if (empty($mac)) {
//get the device address for Cisco 79xx in the URL as &name=SEP000000000000
if (empty($device_address)) {
$name = $_REQUEST['name'];
if (substr($name, 0, 3) == "SEP") {
$mac = strtolower(substr($name, 3, 12));
$device_address = strtolower(substr($name, 3, 12));
unset($name);
}
}
@@ -57,12 +62,12 @@
// Escence make request based on UserID for Memory keys
// The file name is fixed to `Account1_Extern.xml`.
// (Account1 is the first account you register)
if (empty($mac) && !empty($ext)) {
if (empty($device_address) && !empty($ext)) {
$domain_array = explode(":", $_SERVER["HTTP_HOST"]);
$domain_name = $domain_array[0];
$device = device_by_ext($ext, $domain_name);
if ($device !== false && ($device['device_vendor'] == 'escene' || $device['device_vendor'] == 'grandstream')) {
$mac = $device['device_mac_address'];
$device_address = $device['device_address'];
}
}
@@ -81,71 +86,71 @@
exit;
}
//check alternate MAC source
if (empty($mac)) {
//check alternate device address source
if (empty($device_address)) {
//set the http user agent
//$_SERVER['HTTP_USER_AGENT'] = "Yealink SIP-T38G 38.70.0.125 00:15:65:00:00:00";
//$_SERVER['HTTP_USER_AGENT'] = "Yealink SIP-T56A 58.80.0.25 001565f429a4";
//Yealink: 17 digit mac appended to the user agent, so check for a space exactly 17 digits before the end.
if (strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,7)) == "yealink" || strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,5)) == "vp530") {
if (strstr(substr($_SERVER['HTTP_USER_AGENT'],-4), ':')) { //remove colons if they exist
$mac = substr($_SERVER['HTTP_USER_AGENT'],-17);
$mac = preg_replace("#[^a-fA-F0-9./]#", "", $mac);
$device_address = substr($_SERVER['HTTP_USER_AGENT'],-17);
$device_address = preg_replace("#[^a-fA-F0-9./]#", "", $device_address);
} else { //take mac as is - fixes T5X series
$mac = substr($_SERVER['HTTP_USER_AGENT'],-12);
$device_address = substr($_SERVER['HTTP_USER_AGENT'],-12);
}
}
//HTek: $_SERVER['HTTP_USER_AGENT'] = "Htek UC926 2.0.4.2 00:1f:c1:00:00:00"
if (substr($_SERVER['HTTP_USER_AGENT'],0,4) == "Htek") {
$mac = substr($_SERVER['HTTP_USER_AGENT'],-17);
$mac = preg_replace("#[^a-fA-F0-9./]#", "", $mac);
$device_address = substr($_SERVER['HTTP_USER_AGENT'],-17);
$device_address = preg_replace("#[^a-fA-F0-9./]#", "", $device_address);
}
//Panasonic: $_SERVER['HTTP_USER_AGENT'] = "Panasonic_KX-UT670/01.022 (0080f000000)"
if (substr($_SERVER['HTTP_USER_AGENT'],0,9) == "Panasonic") {
$mac = substr($_SERVER['HTTP_USER_AGENT'],-14);
$mac = preg_replace("#[^a-fA-F0-9./]#", "", $mac);
$device_address = substr($_SERVER['HTTP_USER_AGENT'],-14);
$device_address = preg_replace("#[^a-fA-F0-9./]#", "", $device_address);
}
//Grandstream: $_SERVER['HTTP_USER_AGENT'] = "Grandstream Model HW GXP2135 SW 1.0.7.97 DevId 000b828aa872"
if (substr($_SERVER['HTTP_USER_AGENT'],0,11) == "Grandstream") {
$mac = substr($_SERVER['HTTP_USER_AGENT'],-12);
$mac = preg_replace("#[^a-fA-F0-9./]#", "", $mac);
$device_address = substr($_SERVER['HTTP_USER_AGENT'],-12);
$device_address = preg_replace("#[^a-fA-F0-9./]#", "", $device_address);
}
//Audiocodes: $_SERVER['HTTP_USER_AGENT'] = "AUDC-IPPhone/2.2.8.61 (440HDG-Rev0; 00908F602AAC)"
if (substr($_SERVER['HTTP_USER_AGENT'],0,12) == "AUDC-IPPhone") {
$mac = substr($_SERVER['HTTP_USER_AGENT'],-13);
$mac = preg_replace("#[^a-fA-F0-9./]#", "", $mac);
$device_address = substr($_SERVER['HTTP_USER_AGENT'],-13);
$device_address = preg_replace("#[^a-fA-F0-9./]#", "", $device_address);
}
//Aastra: $_SERVER['HTTP_USER_AGENT'] = "Aastra6731i MAC:00-08-5D-29-4C-6B V:3.3.1.4365-SIP"
if (substr($_SERVER['HTTP_USER_AGENT'],0,6) == "Aastra") {
preg_match("/MAC:([A-F0-9-]{17})/", $_SERVER['HTTP_USER_AGENT'], $matches);
$mac = $matches[1];
$mac = preg_replace("#[^a-fA-F0-9./]#", "", $mac);
$device_address = $matches[1];
$device_address = preg_replace("#[^a-fA-F0-9./]#", "", $device_address);
}
//Flyingvoice: $_SERVER['HTTP_USER_AGENT'] = "Flyingvoice FIP13G V0.6.24 00:21:F2:22:AE:F1"
if (strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,11)) == "flyingvoice") {
$mac = substr($_SERVER['HTTP_USER_AGENT'],-17);
$mac = preg_replace("#[^a-fA-F0-9./]#", "", $mac);
$device_address = substr($_SERVER['HTTP_USER_AGENT'],-17);
$device_address = preg_replace("#[^a-fA-F0-9./]#", "", $device_address);
}
}
//prepare the mac address
if (isset($mac)) {
//normalize the mac address to lower case
$mac = strtolower($mac);
//replace all non hexadecimal values and validate the mac address
$mac = preg_replace("#[^a-fA-F0-9./]#", "", $mac);
if (strlen($mac) != 12) {
echo "invalid mac address";
exit;
}
//prepare the device address
if (isset($device_address)) {
//normalize the device address to lower case
$device_address = strtolower($device_address);
//replace all non hexadecimal values and validate the device address
$device_address = preg_replace("#[^a-fA-F0-9./]#", "", $device_address);
//if (strlen($device_address) != 12) {
// echo "invalid mac address";
// exit;
//}
}
//get the domain_uuid, domain_name, device_name and device_vendor
$sql = "select d.device_uuid, d.domain_uuid, d.device_vendor, n.domain_name ";
$sql .= "from v_devices as d, v_domains as n ";
$sql .= "where device_mac_address = :mac ";
$sql .= "where device_address = :device_address ";
$sql .= "and d.domain_uuid = n.domain_uuid; ";
$parameters['mac'] = $mac;
$parameters['device_address'] = $device_address;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (is_array($row)) {
@@ -267,22 +272,22 @@
//check if provisioning has been enabled
if ($provision["enabled"] != "true") {
syslog(LOG_WARNING, '['.$_SERVER['REMOTE_ADDR']."] provision attempt but provisioning is not enabled for ".check_str($_REQUEST['mac']));
syslog(LOG_WARNING, '['.$_SERVER['REMOTE_ADDR']."] provision attempt but provisioning is not enabled for ".escape($_REQUEST['mac']));
http_error('404');
}
//send a request to a remote server to validate the MAC address and secret
if (!empty($_SERVER['auth_server'])) {
$result = send_http_request($_SERVER['auth_server'], 'mac='.check_str($_REQUEST['mac']).'&secret='.check_str($_REQUEST['secret']));
$result = send_http_request($_SERVER['auth_server'], 'mac='.url_encode($_REQUEST['mac']).'&secret='.url_encode($_REQUEST['secret']));
if ($result == "false") {
syslog(LOG_WARNING, '['.$_SERVER['REMOTE_ADDR']."] provision attempt but the remote auth server said no for ".check_str($_REQUEST['mac']));
syslog(LOG_WARNING, '['.$_SERVER['REMOTE_ADDR']."] provision attempt but the remote auth server said no for ".escape($_REQUEST['mac']));
http_error('404');
}
}
//use the mac address to get the vendor
//use the device address to get the vendor
if (empty($device_vendor)) {
$device_vendor = device::get_vendor($mac);
$device_vendor = device::get_vendor($device_address);
}
//keep backwards compatibility
@@ -300,7 +305,7 @@
}
}
if (!$found) {
syslog(LOG_WARNING, '['.$_SERVER['REMOTE_ADDR']."] provision attempt but failed CIDR check for ".check_str($_REQUEST['mac']));
syslog(LOG_WARNING, '['.$_SERVER['REMOTE_ADDR']."] provision attempt but failed CIDR check for ".escape($_REQUEST['mac']));
http_error('404');
}
}
@@ -429,18 +434,18 @@
//output template to string for header processing
$prov = new provision;
$prov->domain_uuid = $domain_uuid;
$prov->mac = $mac;
$prov->device_address = $device_address;
$prov->file = $file;
$file_contents = $prov->render();
//deliver the customized config over HTTP/HTTPS
//need to make sure content-type is correct
if ($_REQUEST['content_type'] == 'application/octet-stream') {
//format the mac address and
$mac = $prov->format_mac($mac, $device_vendor);
//format the device address and
$device_address_formatted = $prov->format_address($device_address, $device_vendor);
//replace the variable name with the value
$file_name = str_replace("{\$mac}", $mac, $file);
$file_name = str_replace("{\$device_address}", $device_address_formatted, $file);
//set the headers
header('Content-Description: File Transfer');

View File

@@ -31,7 +31,7 @@
public $domain_uuid;
public $domain_name;
public $template_dir;
public $mac;
public $device_address;
public function __construct() {
//set the default template directory
@@ -82,9 +82,9 @@
}
}
//normalize the mac address
if (isset($this->mac)) {
$this->mac = strtolower(preg_replace('#[^a-fA-F0-9./]#', '', $this->mac));
//normalize the device address
if (isset($this->device_address)) {
$this->device_address = strtolower(preg_replace('#[^a-fA-F0-9./]#', '', $this->device_address));
}
}
@@ -92,14 +92,14 @@
return $this->domain_uuid;
}
//define the function which checks to see if the mac address exists in devices
private function mac_exists($mac) {
//normalize the mac address
$mac = strtolower(preg_replace('#[^a-fA-F0-9./]#', '', $mac));
//check in the devices table for a specific mac address
//define the function which checks to see if the device address exists in devices
private function device_exists($device_address) {
//normalize the device address
$device_address = strtolower(preg_replace('#[^a-fA-F0-9./]#', '', $device_address));
//check in the devices table for a specific device address
$sql = "select count(*) from v_devices ";
$sql .= "where device_mac_address = :mac ";
$parameters['mac'] = $mac;
$sql .= "where device_address = :device_address ";
$parameters['device_address'] = $device_address;
$database = new database;
$num_rows = $database->select($sql, $parameters, 'column');
if ($num_rows > 0) {
@@ -111,44 +111,44 @@
unset($sql, $parameters, $num_rows);
}
//set the mac address in the correct format for the specific vendor
public function format_mac($mac, $vendor) {
//set the device address in the correct format for the specific vendor
public function format_address($device_address, $vendor) {
switch (strtolower($vendor)) {
case "algo":
return strtoupper($mac);
return strtoupper($device_address);
break;
case "aastra":
return strtoupper($mac);
return strtoupper($device_address);
break;
case "cisco":
return strtoupper($mac);
return strtoupper($device_address);
break;
case "linksys":
return strtolower($mac);
return strtolower($device_address);
break;
case "mitel":
return strtoupper($mac);
return strtoupper($device_address);
break;
case "polycom":
return strtolower($mac);
return strtolower($device_address);
break;
case "snom":
return strtolower($mac);
return strtolower($device_address);
break;
case "escene":
return strtolower($mac);
return strtolower($device_address);
break;
case "grandstream":
return strtolower($mac);
return strtolower($device_address);
break;
case "yealink":
return strtolower($mac);
return strtolower($device_address);
break;
case "gigaset":
return strtoupper($mac);
return strtoupper($device_address);
break;
default:
return strtolower($mac);
return strtolower($device_address);
}
}
@@ -257,11 +257,11 @@
$domain_uuid = $this->domain_uuid;
$device_template = $this->device_template;
$template_dir = $this->template_dir;
$mac = $this->mac;
$device_address = $this->device_address;
$file = $this->file;
//set the mac address to lower case to be consistent with the database
$mac = strtolower($mac);
//set the device address to lower case to be consistent with the database
$device_address = strtolower($device_address);
//get the device template
//if (!empty($_REQUEST['template'])) {
@@ -296,7 +296,8 @@
elseif (is_array($val) && !is_uuid($val['uuid'])) { $value = $val; }
if (isset($value)) {
$value = str_replace('${domain_name}', $domain_name, $value);
$value = str_replace('${mac_address}', $mac, $value);
$value = str_replace('${mac_address}', $device_address, $value);
$value = str_replace('${device_address}', $device_address, $value);
$provision[$key] = $value;
}
unset($value);
@@ -308,18 +309,18 @@
$provision["http_auth_password"] = $_SESSION['provision']["http_auth_password"][0];
}
//check to see if the mac_address exists in devices
//check to see if the device_address exists in devices
//if (empty($_REQUEST['user_id']) || empty($_REQUEST['userid'])) {
if ($this->mac_exists($mac)) {
if ($this->device_exists($device_address)) {
//get the device_template
$sql = "select * from v_devices ";
$sql .= "where device_mac_address = :mac_address ";
$sql .= "where device_address = :device_address ";
if ($provision['http_domain_filter'] == "true") {
$sql .= "and domain_uuid=:domain_uuid ";
$parameters['domain_uuid'] = $domain_uuid;
}
$parameters['mac_address'] = $mac;
$parameters['device_address'] = $device_address;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
unset($parameters);
@@ -340,9 +341,9 @@
//register that we have seen the device
$sql = "update v_devices ";
$sql .= "set device_provisioned_date = :device_provisioned_date, device_provisioned_method = :device_provisioned_method, device_provisioned_ip = :device_provisioned_ip, device_provisioned_agent = :device_provisioned_agent ";
$sql .= "where domain_uuid = :domain_uuid and device_mac_address = :device_mac_address ";
$sql .= "where domain_uuid = :domain_uuid and device_address = :device_address ";
$parameters['domain_uuid'] = $domain_uuid;
$parameters['device_mac_address'] = strtolower($mac);
$parameters['device_address'] = strtolower($device_address);
$parameters['device_provisioned_date'] = 'now()';
$parameters['device_provisioned_method'] = (isset($_SERVER["HTTPS"]) ? 'https' : 'http');
$parameters['device_provisioned_ip'] = $_SERVER['REMOTE_ADDR'];
@@ -521,7 +522,7 @@
}
unset($templates);
//mac address does not exist in the table so add it
//device address does not exist in the table so add it
if ($_SESSION['provision']['auto_insert_enabled']['boolean'] == "true" && is_uuid($domain_uuid)) {
//get a new primary key
@@ -531,7 +532,7 @@
$x = 0;
$array['devices'][$x]['domain_uuid'] = $domain_uuid;
$array['devices'][$x]['device_uuid'] = $device_uuid;
$array['devices'][$x]['device_mac_address'] = $mac;
$array['devices'][$x]['device_address'] = $device_address;
$array['devices'][$x]['device_vendor'] = $device_vendor;
$array['devices'][$x]['device_enabled'] = 'true';
$array['devices'][$x]['device_template'] = $device_template;
@@ -665,8 +666,8 @@
//replace the variables in the template in the future loop through all the line numbers to do a replace for each possible line number
//create a mac address with back slashes for backwards compatability
$mac_dash = substr($mac, 0,2).'-'.substr($mac, 2,2).'-'.substr($mac, 4,2).'-'.substr($mac, 6,2).'-'.substr($mac, 8,2).'-'.substr($mac, 10,2);
//create a device address with back slashes for backwards compatability
//$address_dash = substr($device_address, 0,2).'-'.substr($device_address, 2,2).'-'.substr($device_address, 4,2).'-'.substr($device_address, 6,2).'-'.substr($device_address, 8,2).'-'.substr($device_address, 10,2);
//get the provisioning information
if (is_uuid($device_uuid)) {
@@ -1110,8 +1111,8 @@
}
}
//set the mac address in the correct format
$mac = $this->format_mac($mac, $device_vendor);
//set the device address in the correct format
$device_address = $this->format_address($device_address, $device_vendor);
// set date/time for versioning provisioning templates
if (!empty($_SESSION['provision']['version_format']['text'])) {
@@ -1122,8 +1123,10 @@
}
//replace the variables in the template in the future loop through all the line numbers to do a replace for each possible line number
$view->assign("mac" , $mac);
$view->assign("time" , $time);
$view->assign("device_address", $device_address);
$view->assign("address", $device_address);
$view->assign("mac", $device_address);
$view->assign("time", $time);
$view->assign("label", $device_label);
$view->assign("device_label", $device_label);
$view->assign("firmware_version", $device_firmware_version);
@@ -1131,12 +1134,12 @@
$view->assign("project_path", PROJECT_PATH);
$view->assign("server1_address", $server1_address);
$view->assign("proxy1_address", $proxy1_address);
$view->assign("user_id",$user_id);
$view->assign("password",$password);
$view->assign("template",$device_template);
$view->assign("location",$device_location);
$view->assign("device_location",$device_location);
$view->assign("microtime",microtime(true));
$view->assign("user_id", $user_id);
$view->assign("password", $password);
$view->assign("template", $device_template);
$view->assign("location", $device_location);
$view->assign("device_location", $device_location);
$view->assign("microtime", microtime(true));
//personal ldap password
global $laddr_salt;
@@ -1188,6 +1191,9 @@
//if $file is not provided then look for a default file that exists
if (empty($file)) {
if (file_exists($template_dir."/".$device_template ."/{\$address}")) {
$file = "{\$address}";
}
if (file_exists($template_dir."/".$device_template ."/{\$mac}")) {
$file = "{\$mac}";
}
@@ -1223,7 +1229,7 @@
if ($_SESSION['provision']['debug']['boolean'] == 'true') {
$tmp_file = "/tmp/provisioning_log.txt";
$fh = fopen($tmp_file, 'w') or die("can't open file");
$tmp_string = $mac."\n";
$tmp_string = $device_address."\n";
fwrite($fh, $tmp_string);
fclose($fh);
}
@@ -1267,7 +1273,7 @@
//get the values from the database and set as variables
$domain_uuid = $row["domain_uuid"];
$device_uuid = $row["device_uuid"];
$device_mac_address = $row["device_mac_address"];
$device_address = $row["device_address"];
$device_label = $row["device_label"];
$device_vendor = strtolower($row["device_vendor"]);
$device_model = $row["device_model"];
@@ -1314,14 +1320,15 @@
//configure device object
$this->domain_uuid = $domain_uuid;
$this->mac = $device_mac_address;
$this->device_address = $device_address;
$this->file = $file_name;
//format the mac address
$mac = $this->format_mac($device_mac_address, $device_vendor);
//format the device address
$address_formatted = $this->format_address($device_address, $device_vendor);
//replace {$mac} in the file name
$file_name = str_replace("{\$mac}", $mac, $file_name);
$file_name = str_replace("{\$mac}", $address_formatted, $file_name);
$file_name = str_replace("{\$address}", $address_formatted, $file_name);
//render and write configuration to file
$provision_dir_array = explode(";", $provision["path"]);

View File

@@ -1,10 +1,10 @@
<?php
function device_by_mac($mac) {
function device_by_mac($device_address) {
$sql = "select * from v_devices ";
$sql .= "where device_mac_address = :mac ";
$sql .= "where device_address = :device_address ";
$sql .= "and device_enabled = 'true' ";
$parameters['mac'] = $mac;
$parameters['device_address'] = $device_address;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
return is_array($row) && @sizeof($row) != 0 ? $row : false;