\n";
echo "| \n";
- echo " ".$text['label-device_mac_address']."\n";
+ echo " ".$text['label-device_address']."\n";
echo " | \n";
echo "\n";
- if (permission_exists('device_mac_address')) {
- echo " \n";
+ if (permission_exists('device_address')) {
+ echo " \n";
echo " \n";
- echo $text['description-device_mac_address']."\n";
+ echo $text['description-device_address']."\n";
}
else {
- echo escape($device_mac_address ?? '');
+ echo escape($device_address ?? '');
}
echo " \n";
echo " ".escape($device_provisioned_ip ?? '')." (http|https)\n";
@@ -1794,7 +1794,7 @@
echo " | \n";
$label = $device_alternate[0]['device_label'];
if (empty($label)) { $label = $device_alternate[0]['device_description']; }
- if (empty($label)) { $label = $device_alternate[0]['device_mac_address']; }
+ if (empty($label)) { $label = $device_alternate[0]['device_address']; }
echo " \n";
echo " \n";
echo " | ".escape($label)." | ";
diff --git a/app/devices/device_imports.php b/app/devices/device_imports.php
index a2a16fda1..f76de89c0 100644
--- a/app/devices/device_imports.php
+++ b/app/devices/device_imports.php
@@ -1,564 +1,564 @@
-
- Portions created by the Initial Developer are Copyright (C) 2018-2023
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
- Mark J Crane
-*/
-
-//includes files
- require_once dirname(__DIR__, 2) . "/resources/require.php";
- require_once "resources/check_auth.php";
-
-//check permissions
- if (permission_exists('device_add')) {
- //access granted
- }
- else {
- echo "access denied";
- exit;
- }
-
-//add multi-lingual support
- $language = new text;
- $text = $language->get();
-
-//built in str_getcsv requires PHP 5.3 or higher, this function can be used to reproduct the functionality but requirs PHP 5.1.0 or higher
- if (!function_exists('str_getcsv')) {
- function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") {
- $fp = fopen("php://memory", 'r+');
- fputs($fp, $input);
- rewind($fp);
- $data = fgetcsv($fp, null, $delimiter, $enclosure, $escape);
- fclose($fp);
- return $data;
- }
- }
-
-//set the max php execution time
- ini_set('max_execution_time',7200);
-
-//get the http get values and set them as php variables
- $action = $_POST["action"] ?? null;
- $from_row = $_POST["from_row"] ?? null;
- $delimiter = $_POST["data_delimiter"] ?? null;
- $enclosure = $_POST["data_enclosure"] ?? null;
-
-//save the data to the csv file
- if (isset($_POST['data'])) {
- $file = $_SESSION['server']['temp']['dir']."/devices-".$_SESSION['domain_name'].".csv";
- if (file_put_contents($file, $_POST['data'])) {
- $_SESSION['file'] = $file;
- }
- }
-
-//copy the csv file
- //$_POST['submit'] == "Upload" &&
- if (!empty($_FILES['ulfile']['tmp_name']) && is_uploaded_file($_FILES['ulfile']['tmp_name']) && permission_exists('device_import')) {
- if ($_POST['type'] == 'csv') {
- $file = $_SESSION['server']['temp']['dir']."/devices-".$_SESSION['domain_name'].".csv";
- if (move_uploaded_file($_FILES['ulfile']['tmp_name'], $file)) {
- $_SESSION['file'] = $file;
- }
- }
- }
-
-//get the schema
- if (!empty($delimiter) && file_exists($_SESSION['file'] ?? '')) {
- //get the first line
- $line = fgets(fopen($_SESSION['file'], 'r'));
- $line_fields = explode($delimiter, $line);
-
- //get the schema
- $x = 0;
- include "app/devices/app_config.php";
- $i = 0;
- foreach ($apps[0]['db'] as $table) {
- //get the table name and parent name
- $table_name = $table["table"]['name'];
- $parent_name = $table["table"]['parent'];
-
- //remove the v_ table prefix
- if (substr($table_name, 0, 2) == 'v_') {
- $table_name = substr($table_name, 2);
- }
- if (substr($parent_name, 0, 2) == 'v_') {
- $parent_name = substr($parent_name, 2);
- }
-
- //filter for specific tables and build the schema array
- if ($table_name == "devices" || $table_name == "device_lines" ||
- $table_name == "device_keys" || $table_name == "device_settings") {
- $schema[$i]['table'] = $table_name;
- $schema[$i]['parent'] = $parent_name;
- foreach ($table['fields'] as $row) {
- if (empty($row['deprecated']) || $row['deprecated'] !== 'true') {
- if (is_array($row['name'])) {
- $field_name = $row['name']['text'];
- }
- else {
- $field_name = $row['name'];
- }
- $schema[$i]['fields'][] = $field_name;
- }
- }
- $i++;
- }
- }
-
- $i++;
- $schema[$i]['table'] = 'devices';
- $schema[$i]['parent'] = '';
- $schema[$i]['fields'][] = 'username';
- }
-
-//match the column names to the field names
- if (!empty($delimiter) && file_exists($_SESSION['file'] ?? '') && $action != 'import') {
-
- //validate the token
- $token = new token;
- if (!$token->validate($_SERVER['PHP_SELF'])) {
- message::add($text['message-invalid_token'],'negative');
- header('Location: device_imports.php');
- exit;
- }
-
- //create token
- $object = new token;
- $token = $object->create($_SERVER['PHP_SELF']);
-
- //include header
- $document['title'] = $text['title-device_import'];
- require_once "resources/header.php";
-
- //form to match the fields to the column names
- echo "\n";
-
- require_once "resources/footer.php";
-
- //normalize the column names
- //$line = strtolower($line);
- //$line = str_replace("-", "_", $line);
- //$line = str_replace($delimiter."title".$delimiter, $delimiter."contact_title".$delimiter, $line);
- //$line = str_replace("firstname", "name_given", $line);
- //$line = str_replace("lastname", "name_family", $line);
- //$line = str_replace("company", "organization", $line);
- //$line = str_replace("company", "contact_email", $line);
-
- //end the script
- exit;
- }
-
-//get the parent table
- function get_parent($schema,$table_name) {
- foreach ($schema as $row) {
- if ($row['table'] == $table_name) {
- return $row['parent'];
- }
- }
- }
-
-//upload the csv
- if (file_exists($_SESSION['file'] ?? '') && $action == 'import') {
-
- //validate the token
- $token = new token;
- if (!$token->validate($_SERVER['PHP_SELF'])) {
- message::add($text['message-invalid_token'],'negative');
- header('Location: device_imports.php');
- exit;
- }
-
- //user selected fields
- $fields = $_POST['fields'];
-
- //set the domain_uuid
- $domain_uuid = $_SESSION['domain_uuid'];
-
- //open the database
- $database = new database;
- $database->app_name = 'devices';
- $database->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e';
-
- //get the users
- $sql = "select * from v_users where domain_uuid = :domain_uuid ";
- $parameters['domain_uuid'] = $domain_uuid;
- $users = $database->select($sql, $parameters, 'all');
- unset($sql, $parameters);
-
- //get the contents of the csv file and convert them into an array
- $handle = @fopen($_SESSION['file'], "r");
- if ($handle) {
- //set the starting identifiers
- $row_id = 0;
- $row_number = 1;
-
- //loop through the array
- while (($line = fgets($handle, 4096)) !== false) {
- if ($from_row <= $row_number) {
- //format the data
- $y = 0;
- foreach ($fields as $key => $value) {
- //get the line
- $result = str_getcsv($line, $delimiter, $enclosure);
-
- //get the table and field name
- $field_array = explode(".",$value);
- $table_name = $field_array[0];
- $field_name = $field_array[1];
- //echo "value: $value \n";
- //echo "table_name: $table_name \n";
- //echo "field_name: $field_name \n";
-
- //get the parent table name
- $parent = get_parent($schema, $table_name);
-
- //count the field names
- if (isset($field_count[$table_name][$field_name])) {
- $field_count[$table_name][$field_name]++;
- }
- else {
- $field_count[$table_name][$field_name] = 0;
- }
-
- //set the ordinal ID
- $id = $field_count[$table_name][$field_name];
-
- //remove formatting from the phone number
- if ($field_name == "phone_number") {
- $result[$key] = preg_replace('{\D}', '', $result[$key]);
- }
-
- //normalize the MAC address
- if ($field_name == "device_mac_address") {
- $result[$key] = strtolower($result[$key]);
- $result[$key] = preg_replace('#[^a-fA-F0-9./]#', '', $result[$key]);
- }
-
- //build the data array
- if (!empty($table_name)) {
- if (empty($parent)) {
- if ($field_name != "username") {
- $array[$table_name][$row_id]['domain_uuid'] = $domain_uuid;
- $array[$table_name][$row_id][$field_name] = $result[$key];
- }
- }
- else {
- $array[$parent][$row_id][$table_name][$id]['domain_uuid'] = $domain_uuid;
- $array[$parent][$row_id][$table_name][$id][$field_name] = $result[$key];
- }
-
- if ($field_name == "username") {
- foreach ($users as $field) {
- if ($field['username'] == $result[$key]) {
- $array[$parent][$table_name][$id]['device_user_uuid'] = $field['user_uuid'];
- }
- }
- }
- }
- }
-
- // Do not duplicate MAC addresses, get the device UUID from the database and set it in the array
- if (isset($array['devices']) && !isset($array['devices'][$row_id]['device_uuid']) &&
- isset($array['devices'][$row_id]['device_mac_address'])) {
- $sql = "SELECT device_uuid, domain_uuid FROM v_devices ";
- $sql .= "WHERE device_mac_address = :mac ";
- $parameters['mac'] = $array['devices'][$row_id]['device_mac_address'];
- $row = $database->select($sql, $parameters, 'row');
- if (is_array($row)) {
- // Validate that the hit we got is for the same domain, if not add a message stating the fact
- if ($array['devices'][$row_id]['domain_uuid'] == $row['domain_uuid']) {
- $array['devices'][$row_id]['device_uuid'] = $row['device_uuid'];
- } else {
- // Maybe add in a better new message stating that it was found in a different domain?
- message::add($text['message-duplicate'] . ": " . $parameters['mac']);
- unset($array['devices'][$row_id]);
- }
- }
- unset($sql, $parameters);
- }
-
- //debug information
- //view_array($field_count);
-
- //process a chunk of the array
- if ($row_id === 1000) {
-
- //remove sub table data if it doesn't have more details than domain_uuid an device_uuid
- $x = 0;
- foreach ($array['devices'] as $row) {
- //remove empty device keys
- if (isset($row['device_keys'])) {
- $y = 0;
- foreach ($row['device_keys'] as &$sub_row) {
- if (count($sub_row) == 2) {
- unset($array['devices'][$x]['device_keys']);
- }
- $y++;
- }
- }
-
- //remove empty device lines
- if (isset($row['device_lines'])) {
- $y = 0;
- foreach ($row['device_lines'] as &$sub_row) {
- if (count($sub_row) == 2) {
- unset($array['devices'][$x]['device_lines']);
- }
- $y++;
- }
- }
-
- //increment device id
- $x++;
- }
-
- //save to the data
- $database->save($array);
- //$message = $database->message;
-
- //clear the array
- unset($array);
-
- //set the row id back to 0
- $row_id = 0;
- }
-
- } //if ($from_row <= $row_id)
- unset($field_count);
- $row_number++;
- $row_id++;
- } //end while
- fclose($handle);
-
- //remove sub table data if it doesn't have more details than domain_uuid an device_uuid
- $x = 0;
- foreach ($array['devices'] as $row) {
- //remove empty device keys
- if (isset($row['device_keys'])) {
- $y = 0;
- foreach ($row['device_keys'] as &$sub_row) {
- if (count($sub_row) == 2) {
- unset($array['devices'][$x]['device_keys']);
- }
- $y++;
- }
- }
-
- //remove empty device lines
- if (isset($row['device_lines'])) {
- $y = 0;
- foreach ($row['device_lines'] as &$sub_row) {
- if (count($sub_row) == 2) {
- unset($array['devices'][$x]['device_lines']);
- }
- $y++;
- }
- }
-
- //increment device id
- $x++;
- }
-
- //debug info
- //view_array($array);
-
- //save to the data
- if (is_array($array)) {
- $database->save($array);
- //$message = $database->message;
- //view_array($message);
- }
-
- if (!empty($_SESSION['provision']['path']['text'])) {
- $prov = new provision;
- $prov->domain_uuid = $domain_uuid;
- $response = $prov->write();
- }
-
- //send the redirect header
- header("Location: devices.php");
- return;
- }
- }
-
-//create token
- $object = new token;
- $token = $object->create($_SERVER['PHP_SELF']);
-
-//include the header
- $document['title'] = $text['title-device_import'];
- require_once "resources/header.php";
-
-//show content
- echo "";
-
-//include the footer
- require_once "resources/footer.php";
-
-?>
+
+ Portions created by the Initial Developer are Copyright (C) 2018-2023
+ the Initial Developer. All Rights Reserved.
+
+ Contributor(s):
+ Mark J Crane
+*/
+
+//includes files
+ require_once dirname(__DIR__, 2) . "/resources/require.php";
+ require_once "resources/check_auth.php";
+
+//check permissions
+ if (permission_exists('device_add')) {
+ //access granted
+ }
+ else {
+ echo "access denied";
+ exit;
+ }
+
+//add multi-lingual support
+ $language = new text;
+ $text = $language->get();
+
+//built in str_getcsv requires PHP 5.3 or higher, this function can be used to reproduct the functionality but requirs PHP 5.1.0 or higher
+ if (!function_exists('str_getcsv')) {
+ function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") {
+ $fp = fopen("php://memory", 'r+');
+ fputs($fp, $input);
+ rewind($fp);
+ $data = fgetcsv($fp, null, $delimiter, $enclosure, $escape);
+ fclose($fp);
+ return $data;
+ }
+ }
+
+//set the max php execution time
+ ini_set('max_execution_time',7200);
+
+//get the http get values and set them as php variables
+ $action = $_POST["action"] ?? null;
+ $from_row = $_POST["from_row"] ?? null;
+ $delimiter = $_POST["data_delimiter"] ?? null;
+ $enclosure = $_POST["data_enclosure"] ?? null;
+
+//save the data to the csv file
+ if (isset($_POST['data'])) {
+ $file = $_SESSION['server']['temp']['dir']."/devices-".$_SESSION['domain_name'].".csv";
+ if (file_put_contents($file, $_POST['data'])) {
+ $_SESSION['file'] = $file;
+ }
+ }
+
+//copy the csv file
+ //$_POST['submit'] == "Upload" &&
+ if (!empty($_FILES['ulfile']['tmp_name']) && is_uploaded_file($_FILES['ulfile']['tmp_name']) && permission_exists('device_import')) {
+ if ($_POST['type'] == 'csv') {
+ $file = $_SESSION['server']['temp']['dir']."/devices-".$_SESSION['domain_name'].".csv";
+ if (move_uploaded_file($_FILES['ulfile']['tmp_name'], $file)) {
+ $_SESSION['file'] = $file;
+ }
+ }
+ }
+
+//get the schema
+ if (!empty($delimiter) && file_exists($_SESSION['file'] ?? '')) {
+ //get the first line
+ $line = fgets(fopen($_SESSION['file'], 'r'));
+ $line_fields = explode($delimiter, $line);
+
+ //get the schema
+ $x = 0;
+ include "app/devices/app_config.php";
+ $i = 0;
+ foreach ($apps[0]['db'] as $table) {
+ //get the table name and parent name
+ $table_name = $table["table"]['name'];
+ $parent_name = $table["table"]['parent'];
+
+ //remove the v_ table prefix
+ if (substr($table_name, 0, 2) == 'v_') {
+ $table_name = substr($table_name, 2);
+ }
+ if (substr($parent_name, 0, 2) == 'v_') {
+ $parent_name = substr($parent_name, 2);
+ }
+
+ //filter for specific tables and build the schema array
+ if ($table_name == "devices" || $table_name == "device_lines" ||
+ $table_name == "device_keys" || $table_name == "device_settings") {
+ $schema[$i]['table'] = $table_name;
+ $schema[$i]['parent'] = $parent_name;
+ foreach ($table['fields'] as $row) {
+ if (empty($row['deprecated']) || $row['deprecated'] !== 'true') {
+ if (is_array($row['name'])) {
+ $field_name = $row['name']['text'];
+ }
+ else {
+ $field_name = $row['name'];
+ }
+ $schema[$i]['fields'][] = $field_name;
+ }
+ }
+ $i++;
+ }
+ }
+
+ $i++;
+ $schema[$i]['table'] = 'devices';
+ $schema[$i]['parent'] = '';
+ $schema[$i]['fields'][] = 'username';
+ }
+
+//match the column names to the field names
+ if (!empty($delimiter) && file_exists($_SESSION['file'] ?? '') && $action != 'import') {
+
+ //validate the token
+ $token = new token;
+ if (!$token->validate($_SERVER['PHP_SELF'])) {
+ message::add($text['message-invalid_token'],'negative');
+ header('Location: device_imports.php');
+ exit;
+ }
+
+ //create token
+ $object = new token;
+ $token = $object->create($_SERVER['PHP_SELF']);
+
+ //include header
+ $document['title'] = $text['title-device_import'];
+ require_once "resources/header.php";
+
+ //form to match the fields to the column names
+ echo "\n";
+
+ require_once "resources/footer.php";
+
+ //normalize the column names
+ //$line = strtolower($line);
+ //$line = str_replace("-", "_", $line);
+ //$line = str_replace($delimiter."title".$delimiter, $delimiter."contact_title".$delimiter, $line);
+ //$line = str_replace("firstname", "name_given", $line);
+ //$line = str_replace("lastname", "name_family", $line);
+ //$line = str_replace("company", "organization", $line);
+ //$line = str_replace("company", "contact_email", $line);
+
+ //end the script
+ exit;
+ }
+
+//get the parent table
+ function get_parent($schema,$table_name) {
+ foreach ($schema as $row) {
+ if ($row['table'] == $table_name) {
+ return $row['parent'];
+ }
+ }
+ }
+
+//upload the csv
+ if (file_exists($_SESSION['file'] ?? '') && $action == 'import') {
+
+ //validate the token
+ $token = new token;
+ if (!$token->validate($_SERVER['PHP_SELF'])) {
+ message::add($text['message-invalid_token'],'negative');
+ header('Location: device_imports.php');
+ exit;
+ }
+
+ //user selected fields
+ $fields = $_POST['fields'];
+
+ //set the domain_uuid
+ $domain_uuid = $_SESSION['domain_uuid'];
+
+ //open the database
+ $database = new database;
+ $database->app_name = 'devices';
+ $database->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e';
+
+ //get the users
+ $sql = "select * from v_users where domain_uuid = :domain_uuid ";
+ $parameters['domain_uuid'] = $domain_uuid;
+ $users = $database->select($sql, $parameters, 'all');
+ unset($sql, $parameters);
+
+ //get the contents of the csv file and convert them into an array
+ $handle = @fopen($_SESSION['file'], "r");
+ if ($handle) {
+ //set the starting identifiers
+ $row_id = 0;
+ $row_number = 1;
+
+ //loop through the array
+ while (($line = fgets($handle, 4096)) !== false) {
+ if ($from_row <= $row_number) {
+ //format the data
+ $y = 0;
+ foreach ($fields as $key => $value) {
+ //get the line
+ $result = str_getcsv($line, $delimiter, $enclosure);
+
+ //get the table and field name
+ $field_array = explode(".",$value);
+ $table_name = $field_array[0];
+ $field_name = $field_array[1];
+ //echo "value: $value \n";
+ //echo "table_name: $table_name \n";
+ //echo "field_name: $field_name \n";
+
+ //get the parent table name
+ $parent = get_parent($schema, $table_name);
+
+ //count the field names
+ if (isset($field_count[$table_name][$field_name])) {
+ $field_count[$table_name][$field_name]++;
+ }
+ else {
+ $field_count[$table_name][$field_name] = 0;
+ }
+
+ //set the ordinal ID
+ $id = $field_count[$table_name][$field_name];
+
+ //remove formatting from the phone number
+ if ($field_name == "phone_number") {
+ $result[$key] = preg_replace('{\D}', '', $result[$key]);
+ }
+
+ //normalize the device address
+ if ($field_name == "device_address") {
+ $result[$key] = strtolower($result[$key]);
+ $result[$key] = preg_replace('#[^a-fA-F0-9./]#', '', $result[$key]);
+ }
+
+ //build the data array
+ if (!empty($table_name)) {
+ if (empty($parent)) {
+ if ($field_name != "username") {
+ $array[$table_name][$row_id]['domain_uuid'] = $domain_uuid;
+ $array[$table_name][$row_id][$field_name] = $result[$key];
+ }
+ }
+ else {
+ $array[$parent][$row_id][$table_name][$id]['domain_uuid'] = $domain_uuid;
+ $array[$parent][$row_id][$table_name][$id][$field_name] = $result[$key];
+ }
+
+ if ($field_name == "username") {
+ foreach ($users as $field) {
+ if ($field['username'] == $result[$key]) {
+ $array[$parent][$table_name][$id]['device_user_uuid'] = $field['user_uuid'];
+ }
+ }
+ }
+ }
+ }
+
+ // Do not duplicate device addresses, get the device UUID from the database and set it in the array
+ if (isset($array['devices']) && !isset($array['devices'][$row_id]['device_uuid']) &&
+ isset($array['devices'][$row_id]['device_address'])) {
+ $sql = "SELECT device_uuid, domain_uuid FROM v_devices ";
+ $sql .= "WHERE device_address = :mac ";
+ $parameters['mac'] = $array['devices'][$row_id]['device_address'];
+ $row = $database->select($sql, $parameters, 'row');
+ if (is_array($row)) {
+ // Validate that the hit we got is for the same domain, if not add a message stating the fact
+ if ($array['devices'][$row_id]['domain_uuid'] == $row['domain_uuid']) {
+ $array['devices'][$row_id]['device_uuid'] = $row['device_uuid'];
+ } else {
+ // Maybe add in a better new message stating that it was found in a different domain?
+ message::add($text['message-duplicate'] . ": " . $parameters['mac']);
+ unset($array['devices'][$row_id]);
+ }
+ }
+ unset($sql, $parameters);
+ }
+
+ //debug information
+ //view_array($field_count);
+
+ //process a chunk of the array
+ if ($row_id === 1000) {
+
+ //remove sub table data if it doesn't have more details than domain_uuid an device_uuid
+ $x = 0;
+ foreach ($array['devices'] as $row) {
+ //remove empty device keys
+ if (isset($row['device_keys'])) {
+ $y = 0;
+ foreach ($row['device_keys'] as &$sub_row) {
+ if (count($sub_row) == 2) {
+ unset($array['devices'][$x]['device_keys']);
+ }
+ $y++;
+ }
+ }
+
+ //remove empty device lines
+ if (isset($row['device_lines'])) {
+ $y = 0;
+ foreach ($row['device_lines'] as &$sub_row) {
+ if (count($sub_row) == 2) {
+ unset($array['devices'][$x]['device_lines']);
+ }
+ $y++;
+ }
+ }
+
+ //increment device id
+ $x++;
+ }
+
+ //save to the data
+ $database->save($array);
+ //$message = $database->message;
+
+ //clear the array
+ unset($array);
+
+ //set the row id back to 0
+ $row_id = 0;
+ }
+
+ } //if ($from_row <= $row_id)
+ unset($field_count);
+ $row_number++;
+ $row_id++;
+ } //end while
+ fclose($handle);
+
+ //remove sub table data if it doesn't have more details than domain_uuid an device_uuid
+ $x = 0;
+ foreach ($array['devices'] as $row) {
+ //remove empty device keys
+ if (isset($row['device_keys'])) {
+ $y = 0;
+ foreach ($row['device_keys'] as &$sub_row) {
+ if (count($sub_row) == 2) {
+ unset($array['devices'][$x]['device_keys']);
+ }
+ $y++;
+ }
+ }
+
+ //remove empty device lines
+ if (isset($row['device_lines'])) {
+ $y = 0;
+ foreach ($row['device_lines'] as &$sub_row) {
+ if (count($sub_row) == 2) {
+ unset($array['devices'][$x]['device_lines']);
+ }
+ $y++;
+ }
+ }
+
+ //increment device id
+ $x++;
+ }
+
+ //debug info
+ //view_array($array);
+
+ //save to the data
+ if (is_array($array)) {
+ $database->save($array);
+ //$message = $database->message;
+ //view_array($message);
+ }
+
+ if (!empty($_SESSION['provision']['path']['text'])) {
+ $prov = new provision;
+ $prov->domain_uuid = $domain_uuid;
+ $response = $prov->write();
+ }
+
+ //send the redirect header
+ header("Location: devices.php");
+ return;
+ }
+ }
+
+//create token
+ $object = new token;
+ $token = $object->create($_SERVER['PHP_SELF']);
+
+//include the header
+ $document['title'] = $text['title-device_import'];
+ require_once "resources/header.php";
+
+//show content
+ echo "";
+
+//include the footer
+ require_once "resources/footer.php";
+
+?>
diff --git a/app/devices/devices.php b/app/devices/devices.php
index 520825591..894378d93 100644
--- a/app/devices/devices.php
+++ b/app/devices/devices.php
@@ -126,7 +126,7 @@
}
if (!empty($search)) {
$sql .= "(";
- $sql .= " lower(d.device_mac_address) like :search ";
+ $sql .= " lower(d.device_address) like :search ";
$sql .= " or lower(d.device_label) like :search ";
$sql .= " or lower(d.device_vendor) like :search ";
$sql .= " or lower(d.device_enabled) like :search ";
@@ -212,7 +212,7 @@
}
if (!empty($search)) {
$sql .= "and (";
- $sql .= " lower(d.device_mac_address) like :search ";
+ $sql .= " lower(d.device_address) like :search ";
$sql .= " or lower(d.device_label) like :search ";
$sql .= " or lower(d.device_vendor) like :search ";
$sql .= " or lower(d.device_enabled) like :search ";
@@ -361,7 +361,7 @@
if (!empty($_GET['show']) && $_GET['show'] == "all" && permission_exists('device_all')) {
echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, null, null, $param);
}
- echo th_order_by('device_mac_address', $text['label-device_mac_address'], $order_by, $order, null, null, $param ?? null);
+ echo th_order_by('device_address', $text['label-device_address'], $order_by, $order, null, null, $param ?? null);
echo th_order_by('device_label', $text['label-device_label'], $order_by, $order, null, null, $param ?? null);
if ($device_alternate) {
echo th_order_by('device_template', $text['label-device_uuid_alternate'], $order_by, $order, null, null, $param ?? null);
@@ -413,7 +413,7 @@
echo " ".escape($_SESSION['domains'][$row['domain_uuid']]['domain_name'])." | \n";
}
echo " ";
- echo permission_exists('device_edit') ? "".escape(format_mac($row['device_mac_address']))."" : escape(format_mac($row['device_mac_address']));
+ echo permission_exists('device_edit') ? "".escape(format_device_address($row['device_address']))."" : escape(format_device_address($row['device_address']));
echo " | \n";
echo " ".escape($row['device_label'])." | \n";
if ($device_alternate) {
diff --git a/app/extensions/app_languages.php b/app/extensions/app_languages.php
index 630d131d5..10341b3f9 100644
--- a/app/extensions/app_languages.php
+++ b/app/extensions/app_languages.php
@@ -1687,29 +1687,29 @@ $text['label-device_template']['zh-cn'] = "模板";
$text['label-device_template']['ja-jp'] = "レンプレート";
$text['label-device_template']['ko-kr'] = "주형";
-$text['label-device_mac_address']['en-us'] = "MAC Address";
-$text['label-device_mac_address']['en-gb'] = "MAC Address";
-$text['label-device_mac_address']['ar-eg'] = "العنوان الرئيسي";
-$text['label-device_mac_address']['de-at'] = "MAC Adresse";
-$text['label-device_mac_address']['de-ch'] = "MAC Adresse";
-$text['label-device_mac_address']['de-de'] = "MAC Adresse";
-$text['label-device_mac_address']['es-cl'] = "Mac dirección";
-$text['label-device_mac_address']['es-mx'] = "Mac dirección";
-$text['label-device_mac_address']['fr-ca'] = "Adresse MAC";
-$text['label-device_mac_address']['fr-fr'] = "Adresse MAC";
-$text['label-device_mac_address']['he-il'] = "כתובת MAC";
-$text['label-device_mac_address']['it-it'] = "MAC Address";
-$text['label-device_mac_address']['nl-nl'] = "MAC-Adres";
-$text['label-device_mac_address']['pl-pl'] = "Adres MAC";
-$text['label-device_mac_address']['pt-br'] = "Endereço MAC";
-$text['label-device_mac_address']['pt-pt'] = "Endereço MAC";
-$text['label-device_mac_address']['ro-ro'] = "Adresa mac";
-$text['label-device_mac_address']['ru-ru'] = "MAC Адреса";
-$text['label-device_mac_address']['sv-se'] = "MAC-adress";
-$text['label-device_mac_address']['uk-ua'] = "Адреса MAC";
-$text['label-device_mac_address']['zh-cn'] = "MAC地址";
-$text['label-device_mac_address']['ja-jp'] = "Macアドレス";
-$text['label-device_mac_address']['ko-kr'] = "MAC 주소";
+$text['label-device_address']['en-us'] = "Address";
+$text['label-device_address']['en-gb'] = "Address";
+$text['label-device_address']['ar-eg'] = "العنوان الرئيسي";
+$text['label-device_address']['de-at'] = "Adresse";
+$text['label-device_address']['de-ch'] = "Adresse";
+$text['label-device_address']['de-de'] = "Adresse";
+$text['label-device_address']['es-cl'] = "dirección";
+$text['label-device_address']['es-mx'] = "dirección";
+$text['label-device_address']['fr-ca'] = "Adresse";
+$text['label-device_address']['fr-fr'] = "Adresse";
+$text['label-device_address']['he-il'] = "כתובת";
+$text['label-device_address']['it-it'] = "Address";
+$text['label-device_address']['nl-nl'] = "Adres";
+$text['label-device_address']['pl-pl'] = "Adres";
+$text['label-device_address']['pt-br'] = "Endereço";
+$text['label-device_address']['pt-pt'] = "Endereço";
+$text['label-device_address']['ro-ro'] = "Adresa";
+$text['label-device_address']['ru-ru'] = "Адреса";
+$text['label-device_address']['sv-se'] = "adress";
+$text['label-device_address']['uk-ua'] = "Адреса";
+$text['label-device_address']['zh-cn'] = "地址";
+$text['label-device_address']['ja-jp'] = "アドレス";
+$text['label-device_address']['ko-kr'] = "주소";
$text['label-description']['en-us'] = "Description";
$text['label-description']['en-gb'] = "Description";
diff --git a/app/extensions/extension_edit.php b/app/extensions/extension_edit.php
index 4766f6d83..f8022f697 100644
--- a/app/extensions/extension_edit.php
+++ b/app/extensions/extension_edit.php
@@ -172,20 +172,20 @@
//device provisioning variables
if (is_array($_POST["devices"]) && @sizeof($_POST["devices"]) != 0) {
foreach ($_POST["devices"] as $d => $device) {
- $device_mac_address = strtolower($device["device_mac_address"]);
- $device_mac_address = preg_replace('#[^a-fA-F0-9./]#', '', $device_mac_address);
+ $device_address = strtolower($device["device_address"]);
+ $device_address = preg_replace('#[^a-fA-F0-9./]#', '', $device_address);
$line_numbers[$d] = $device["line_number"];
- $device_mac_addresses[$d] = $device_mac_address;
+ $device_addresses[$d] = $device_address;
$device_templates[$d] = $device["device_template"];
}
}
//get or set the device_uuid
- if (!empty($device_mac_addresses) && is_array($device_mac_addresses) && @sizeof($device_mac_addresses) != 0) {
- foreach ($device_mac_addresses as $d => $device_mac_address) {
- $device_mac_address = strtolower($device_mac_address);
- $device_mac_address = preg_replace('#[^a-fA-F0-9./]#', '', $device_mac_address);
+ if (!empty($device_addresses) && is_array($device_addresses) && @sizeof($device_addresses) != 0) {
+ foreach ($device_addresses as $d => $device_address) {
+ $device_address = strtolower($device_address);
+ $device_address = preg_replace('#[^a-fA-F0-9./]#', '', $device_address);
$sql = "select ";
$sql .= "d1.device_uuid, ";
@@ -196,8 +196,8 @@
$sql .= "v_domains as d2 ";
$sql .= "where ";
$sql .= "d1.domain_uuid = d2.domain_uuid and ";
- $sql .= "d1.device_mac_address = :device_mac_address ";
- $parameters['device_mac_address'] = $device_mac_address;
+ $sql .= "d1.device_address = :device_address ";
+ $parameters['device_address'] = $device_address;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (is_array($row)) {
@@ -520,9 +520,9 @@
}
//assign the device to the extension(s)
- if (is_array($device_mac_addresses) && @sizeof($device_mac_addresses) != 0) {
- foreach ($device_mac_addresses as $d => $device_mac_address) {
- if (is_mac($device_mac_address)) {
+ if (is_array($device_addresses) && @sizeof($device_addresses) != 0) {
+ foreach ($device_addresses as $d => $device_address) {
+ if (!emtpy($device_address)) {
//get the device vendor
if (isset($device_templates[$d])) {
//use the the template to get the vendor
@@ -530,8 +530,8 @@
$device_vendor = $template_array[0];
}
else {
- //use the mac address to get the vendor
- $device_vendor = device::get_vendor($device_mac_address);
+ //use the device address to get the vendor
+ $device_vendor = device::get_vendor($device_address);
}
//determine the name
@@ -592,10 +592,10 @@
}
//build the devices array
- if ($device_unique && $device_mac_address != '000000000000') {
+ if ($device_unique && $device_address != '000000000000') {
$array["devices"][$j]["device_uuid"] = $device_uuids[$d];
$array["devices"][$j]["domain_uuid"] = $_SESSION['domain_uuid'];
- $array["devices"][$j]["device_mac_address"] = $device_mac_address;
+ $array["devices"][$j]["device_address"] = $device_address;
$array["devices"][$j]["device_label"] = $extension;
if (!empty($device_vendor)) {
$array["devices"][$j]["device_vendor"] = $device_vendor;
@@ -898,12 +898,12 @@
}
//get the device lines
- $sql = "select d.device_mac_address, d.device_template, d.device_description, l.device_line_uuid, l.device_uuid, l.line_number ";
+ $sql = "select d.device_address, d.device_template, d.device_description, l.device_line_uuid, l.device_uuid, l.line_number ";
$sql .= "from v_device_lines as l, v_devices as d ";
$sql .= "where (l.user_id = :user_id_1 or l.user_id = :user_id_2)";
$sql .= "and l.domain_uuid = :domain_uuid ";
$sql .= "and l.device_uuid = d.device_uuid ";
- $sql .= "order by l.line_number, d.device_mac_address asc ";
+ $sql .= "order by l.line_number, d.device_address asc ";
$parameters['user_id_1'] = $extension ?? null;
$parameters['user_id_2'] = $number_alias ?? null;
$parameters['domain_uuid'] = $domain_uuid;
@@ -914,7 +914,7 @@
//get the devices
$sql = "select * from v_devices ";
$sql .= "where domain_uuid = :domain_uuid ";
- $sql .= "order by device_mac_address asc ";
+ $sql .= "order by device_address asc ";
$parameters['domain_uuid'] = $domain_uuid;
$database = new database;
$devices = $database->select($sql, $parameters, 'all');
@@ -1252,7 +1252,7 @@
echo " ".$text['label-line']." \n";
echo " \n";
echo " \n";
- echo " ".$text['label-device_mac_address']." \n";
+ echo " ".$text['label-device_address']." \n";
echo " | \n";
echo " \n";
echo " ".$text['label-device_template']." \n";
@@ -1264,10 +1264,10 @@
if ($action == 'update') {
if (is_array($device_lines) && @sizeof($device_lines) != 0) {
foreach ($device_lines as $row) {
- $device_mac_address = format_mac($row['device_mac_address']);
+ $device_address = format_device_address($row['device_address']);
echo " | \n";
echo " | ".escape($row['line_number'])." | \n";
- echo " ".escape($device_mac_address)." | \n";
+ echo " ".escape($device_address)." | \n";
echo " ".escape($row['device_template'])." | \n";
//echo " ".$row['device_description']." | \n";
echo " \n";
@@ -1295,49 +1295,49 @@
?>
\n";
+ echo " \n";
- echo " \n";
+ echo " \n";
echo " | \n";
echo " \n";
echo " \n";
diff --git a/app/provision/app_defaults.php b/app/provision/app_defaults.php
index 211235abd..7c0dcc1ed 100644
--- a/app/provision/app_defaults.php
+++ b/app/provision/app_defaults.php
@@ -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');
diff --git a/app/provision/index.php b/app/provision/index.php
index 6054e483b..1bab4c09b 100644
--- a/app/provision/index.php
+++ b/app/provision/index.php
@@ -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');
diff --git a/app/provision/resources/classes/provision.php b/app/provision/resources/classes/provision.php
index 121954f23..0023701aa 100644
--- a/app/provision/resources/classes/provision.php
+++ b/app/provision/resources/classes/provision.php
@@ -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"]);
diff --git a/app/provision/resources/functions/device_by.php b/app/provision/resources/functions/device_by.php
index 0290d6bf6..91a97883b 100644
--- a/app/provision/resources/functions/device_by.php
+++ b/app/provision/resources/functions/device_by.php
@@ -1,10 +1,10 @@
select($sql, $parameters, 'row');
return is_array($row) && @sizeof($row) != 0 ? $row : false;
diff --git a/resources/functions.php b/resources/functions.php
index 3a4b195a0..775d00f33 100644
--- a/resources/functions.php
+++ b/resources/functions.php
@@ -1,2215 +1,2216 @@
-
- Portions created by the Initial Developer are Copyright (C) 2008-2022
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
- Mark J Crane
- Luis Daniel Lucio Quiroz
-*/
-
- if (!function_exists('mb_strtoupper')) {
- function mb_strtoupper($string) {
- return strtoupper($string);
- }
- }
-
- if (!function_exists('check_float')) {
- function check_float($string) {
- $string = str_replace(",",".",$string ?? '');
- return trim($string);
- }
- }
-
- if (!function_exists('check_str')) {
- function check_str($string, $trim = true) {
- global $db_type, $db;
- //when code in db is urlencoded the ' does not need to be modified
- if ($db_type == "sqlite") {
- if (function_exists('sqlite_escape_string')) {
- $string = sqlite_escape_string($string);
- }
- else {
- $string = str_replace("'","''",$string);
- }
- }
- if ($db_type == "pgsql") {
- $string = str_replace("'","''",$string);
- }
- if ($db_type == "mysql") {
- if(function_exists('mysql_real_escape_string')){
- $tmp_str = mysql_real_escape_string($string);
- }
- else {
- $tmp_str = mysqli_real_escape_string($db, $string);
- }
- if (!empty($tmp_str)) {
- $string = $tmp_str;
- }
- else {
- $search = array("\x00", "\n", "\r", "\\", "'", "\"", "\x1a");
- $replace = array("\\x00", "\\n", "\\r", "\\\\" ,"\'", "\\\"", "\\\x1a");
- $string = str_replace($search, $replace, $string);
- }
- }
- $string = ($trim) ? trim($string) : $string;
- return $string;
- }
- }
-
- if (!function_exists('check_sql')) {
- function check_sql($string) {
- return trim($string); //remove white space
- }
- }
-
- if (!function_exists('check_cidr')) {
- function check_cidr($cidr, $ip_address) {
- if (isset($cidr) && !empty($cidr)) {
- list ($subnet, $mask) = explode ('/', $cidr);
- return ( ip2long ($ip_address) & ~((1 << (32 - $mask)) - 1) ) == ip2long ($subnet);
- }
- else {
- return false;
- }
- }
- }
-
- if (!function_exists('fix_postback')) {
- function fix_postback($post_array) {
- foreach ($post_array as $index => $value) {
- if (is_array($value)) { fix_postback($value); }
- else {
- $value = str_replace('"', """, $value);
- $value = str_replace("'", "'", $value);
- $post_array[$index] = $value;
- }
- }
- return $post_array;
- }
- }
-
- if (!function_exists('uuid')) {
- function uuid() {
- $uuid = null;
- if (PHP_OS === 'FreeBSD') {
- $uuid = trim(shell_exec("uuid -v 4"));
- if (is_uuid($uuid)) {
- return $uuid;
- }
- else {
- echo "Please install the following package.\n";
- echo "pkg install ossp-uuid\n";
- exit;
- }
- }
- if (PHP_OS === 'Linux') {
- $uuid = trim(file_get_contents('/proc/sys/kernel/random/uuid'));
- if (is_uuid($uuid)) {
- return $uuid;
- }
- else {
- $uuid = trim(shell_exec("uuidgen"));
- if (is_uuid($uuid)) {
- return $uuid;
- }
- else {
- echo "Please install the uuidgen.\n";
- exit;
- }
- }
- }
- if ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') && function_exists('com_create_guid')) {
- $uuid = trim(com_create_guid(), '{}');
- if (is_uuid($uuid)) {
- return $uuid;
- }
- else {
- echo "The com_create_guid() function failed to create a uuid.\n";
- exit;
- }
- }
- }
- }
-
- if (!function_exists('is_uuid')) {
- function is_uuid($uuid) {
- if (gettype($uuid) == 'string') {
- $regex = '/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i';
- return preg_match($regex, $uuid);
- }
- return false;
- }
- }
-
- if (!function_exists('is_xml')) {
- function is_xml($string) {
- $pattern = '/^<\?xml(?:\s+[^>]+\s*)?\?>\s*<(\w+)>.*<\/\1>\s*$/s';
- return preg_match($pattern, $string) === 1;
- }
- }
-
- if (!function_exists('recursive_copy')) {
- if (file_exists('/bin/cp')) {
- function recursive_copy($source, $destination, $options = '') {
- if (strtoupper(substr(PHP_OS, 0, 3)) === 'SUN') {
- //copy -R recursive, preserve attributes for SUN
- $cmd = 'cp -Rp '.$source.'/* '.$destination;
- }
- else {
- //copy -R recursive, -L follow symbolic links, -p preserve attributes for other Posix systemss
- $cmd = 'cp -RLp '.$options.' '.$source.'/* '.$destination;
- }
- exec ($cmd);
- }
- }
- elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
- function recursive_copy($source, $destination, $options = '') {
- $source = normalize_path_to_os($source);
- $destination = normalize_path_to_os($destination);
- exec("xcopy /E /Y \"$source\" \"$destination\"");
- }
- }
- else {
- function recursive_copy($source, $destination, $options = '') {
- $dir = opendir($source);
- if (!$dir) {
- throw new Exception("recursive_copy() source directory '".$source."' does not exist.");
- }
- if (!is_dir($destination)) {
- if (!mkdir($destination,02770,true)) {
- throw new Exception("recursive_copy() failed to create destination directory '".$destination."'");
- }
- }
- while(false !== ( $file = readdir($dir)) ) {
- if (( $file != '.' ) && ( $file != '..' )) {
- if ( is_dir($source . '/' . $file) ) {
- recursive_copy($source . '/' . $file,$destination . '/' . $file);
- }
- else {
- copy($source . '/' . $file,$destination . '/' . $file);
- }
- }
- }
- closedir($dir);
- }
- }
- }
-
- if (!function_exists('recursive_delete')) {
- if (file_exists('/usr/bin/find')) {
- function recursive_delete($directory) {
- if (isset($directory) && strlen($directory) > 8) {
- exec('/usr/bin/find '.$directory.'/* -name "*" -delete');
- //exec('rm -Rf '.$directory.'/*');
- clearstatcache();
- }
- }
- }
- elseif (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
- function recursive_delete($directory) {
- $directory = normalize_path_to_os($directory);
- //$this->write_debug("del /S /F /Q \"$dir\"");
- exec("del /S /F /Q \"$directory\"");
- clearstatcache();
- }
- }
- else {
- function recursive_delete($directory) {
- foreach (glob($directory) as $file) {
- if (is_dir($file)) {
- //$this->write_debug("rm dir: ".$file);
- recursive_delete("$file/*");
- rmdir($file);
- }
- else {
- //$this->write_debug("delete file: ".$file);
- unlink($file);
- }
- }
- clearstatcache();
- }
- }
- }
-
- if (!function_exists('if_group')) {
- function if_group($group) {
- //set default false
- $result = false;
- //search for the permission
- if (count($_SESSION["groups"]) > 0) {
- foreach($_SESSION["groups"] as $row) {
- if ($row['group_name'] == $group) {
- $result = true;
- break;
- }
- }
- }
- //return the result
- return $result;
- }
- }
-
- if (!function_exists('permission_exists')) {
- function permission_exists($permission, $operator = 'or') {
- //set default
- $result = false;
- //permissions exist
- if (is_array($_SESSION["permissions"]) && @sizeof($_SESSION['permissions']) != 0) {
- //array
- if (is_array($permission) && @sizeof($permission) != 0) {
- if ($operator == 'and') {
- $exists_all = true;
- foreach ($permission as $perm) {
- if ($_SESSION["permissions"][$permission] != true) {
- $exists_all = false;
- break;
- }
- }
- $result = $exists_all;
- }
- else {
- $exists_one = false;
- foreach ($permission as $perm) {
- if (isset($_SESSION["permissions"][$perm]) && $_SESSION["permissions"][$perm] != true) {
- $exists_one = true;
- break;
- }
- }
- $result = $exists_one;
- }
- }
- //single
- else {
- if (isset($_SESSION["permissions"][$permission]) && $_SESSION["permissions"][$permission] == true) {
- $result = true;
- }
- }
- }
- //return the result
- return $result;
- }
- }
-
- if (!function_exists('if_group_member')) {
- function if_group_member($group_members, $group) {
- if (stripos($group_members, "||".$group."||") === false) {
- return false; //group does not exist
- }
- else {
- return true; //group exists
- }
- }
- }
-
- if (!function_exists('superadmin_list')) {
- function superadmin_list() {
- global $domain_uuid;
- $sql = "select * from v_user_groups ";
- $sql .= "where group_name = 'superadmin' ";
- $database = new database;
- $result = $database->select($sql, null, 'all');
- $superadmin_list = "||";
- if (is_array($result) && @sizeof($result) != 0) {
- foreach ($result as $field) {
- //get the list of superadmins
- $superadmin_list .= $field['user_uuid']."||";
- }
- }
- unset($sql, $result, $field);
- return $superadmin_list;
- }
- }
-
- if (!function_exists('if_superadmin')) {
- function if_superadmin($superadmin_list, $user_uuid) {
- if (stripos($superadmin_list, "||".$user_uuid."||") === false) {
- return false;
- }
- else {
- return true; //user_uuid exists
- }
- }
- }
-
- if (!function_exists('html_select_other')) {
- function html_select_other($table_name, $field_name, $sql_where_optional, $field_current_value, $sql_order_by = null, $label_other = 'Other...') {
- //html select other: build a select box from distinct items in db with option for other
- global $domain_uuid;
- $table_name = preg_replace("#[^a-zA-Z0-9_]#", "", $table_name);
- $field_name = preg_replace("#[^a-zA-Z0-9_]#", "", $field_name);
-
- $html = "";
-
- return $html;
- }
- }
-
- if (!function_exists('html_select')) {
- function html_select($table_name, $field_name, $sql_where_optional, $field_current_value, $field_value = '', $style = '', $on_change = '') {
- //html select: build a select box from distinct items in db
- global $domain_uuid;
-
- $table_name = preg_replace("#[^a-zA-Z0-9_]#", "", $table_name);
- $field_name = preg_replace("#[^a-zA-Z0-9_]#", "", $field_name);
- $field_value = preg_replace("#[^a-zA-Z0-9_]#", "", $field_value);
-
- if (!empty($field_value)) {
- $html .= " |