diff --git a/app/devices/device_dashboard.php b/app/devices/device_dashboard.php index 7fd5aa7c56..12d9b148c9 100644 --- a/app/devices/device_dashboard.php +++ b/app/devices/device_dashboard.php @@ -109,166 +109,176 @@ } //create a list of protected keys - device keys - foreach($device_keys as $row) { - //determine if the key is allowed - $device_key_authorized = false; - foreach($vendor_functions as $function) { - if ($function['vendor_name'] == $row['device_key_vendor'] && $function['value'] == $row['device_key_type']) { - $device_key_authorized = true; + if (is_array($device_keys)) { + foreach($device_keys as $row) { + //determine if the key is allowed + $device_key_authorized = false; + foreach($vendor_functions as $function) { + if ($function['vendor_name'] == $row['device_key_vendor'] && $function['value'] == $row['device_key_type']) { + $device_key_authorized = true; + } } - } - //add the protected keys - if (!$device_key_authorized) { - $protected_keys[$row['device_key_id']] = 'true'; - } - //add to protected - if ($row['device_key_protected'] == "true") { - $protected_keys[$row['device_key_id']] = 'true'; - } + //add the protected keys + if (!$device_key_authorized) { + $protected_keys[$row['device_key_id']] = 'true'; + } + //add to protected + if ($row['device_key_protected'] == "true") { + $protected_keys[$row['device_key_id']] = 'true'; + } + } } //create a list of protected keys - device proile keys - foreach($device_profile_keys as $row) { - //determine if the key is allowed - $device_key_authorized = false; - foreach($vendor_functions as $function) { - if ($function['vendor_name'] == $row['device_key_vendor'] && $function['value'] == $row['device_key_type']) { - $device_key_authorized = true; + if (is_array($device_profile_keys)) { + foreach($device_profile_keys as $row) { + //determine if the key is allowed + $device_key_authorized = false; + if (is_array($vendor_functions)) { + foreach($vendor_functions as $function) { + if ($function['vendor_name'] == $row['device_key_vendor'] && $function['value'] == $row['device_key_type']) { + $device_key_authorized = true; + } + } } - } - //add the protected keys - if (!$device_key_authorized) { - $protected_keys[$row['device_key_id']] = 'true'; - } + //add the protected keys + if (!$device_key_authorized) { + $protected_keys[$row['device_key_id']] = 'true'; + } + } } //remove the keys the user is not allowed to edit based on the authorized vendor keys $x=0; - foreach($_POST['device_keys'] as $row) { - //loop through the authorized vendor functions - if ($protected_keys[$row['device_key_id']] == "true") { - unset($_POST['device_keys'][$x]); - } - //increment the row id - $x++; + if (is_array($_POST['device_keys'])) { + foreach($_POST['device_keys'] as $row) { + //loop through the authorized vendor functions + if ($protected_keys[$row['device_key_id']] == "true") { + unset($_POST['device_keys'][$x]); + } + //increment the row id + $x++; + } } //add or update the device keys - foreach ($_POST['device_keys'] as &$row) { + if (is_array($_POST['device_keys'])) { + foreach ($_POST['device_keys'] as &$row) { - //validate the data - $save = true; - //if (!is_uuid($row["device_key_uuid"])) { $save = false; } - if (isset($row["device_key_id"])) { - if (!is_numeric($row["device_key_id"])) { $save = false; echo $row["device_key_id"]." id "; } - } - if (strlen($row["device_key_type"]) > 25) { $save = false; echo "type "; } - if (strlen($row["device_key_value"]) > 25) { $save = false; echo "value "; } - if (strlen($row["device_key_label"]) > 25) { $save = false; echo "label "; } - - //escape characters in the string - $device_uuid = check_str($row["device_uuid"]); - $device_key_uuid = check_str($row["device_key_uuid"]); - $device_key_id = check_str($row["device_key_id"]); - $device_key_type = check_str($row["device_key_type"]); - $device_key_line = check_str($row["device_key_line"]); - $device_key_value = check_str($row["device_key_value"]); - $device_key_label = check_str($row["device_key_label"]); - $device_key_category = check_str($row["device_key_category"]); - $device_key_vendor = check_str($row["device_key_vendor"]); - - //process the profile keys - if (strlen($row["device_profile_uuid"]) > 0) { - //get the profile key settings from the array - foreach ($device_profile_keys as &$field) { - if ($device_key_uuid == $field["device_key_uuid"]) { - $database = $field; - break; - } - } - //determine what to do with the profile key - if ($device_key_id == $database["device_key_id"] - && $device_key_value == $database["device_key_value"] - && $device_key_label == $database["device_key_label"]) { - //profile key unchanged don't save - $save = false; - } - else { - //profile key has changed remove save the settings to the device - $device_key_uuid = ''; - } - } - - //sql add or update - if (strlen($device_key_uuid) == 0) { - if (permission_exists('device_key_add') && strlen($device_key_type) > 0 && strlen($device_key_value) > 0) { - - //create the primary keys - $device_key_uuid = uuid(); - - //if the device_uuid is not in the array then get the device_uuid from the database - if (strlen($device_uuid) == 0) { - $sql = "SELECT device_uuid, device_profile_uuid FROM v_devices "; - $sql .= "WHERE device_user_uuid = '".$_SESSION['user_uuid']."' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $row = $prep_statement->fetch(PDO::FETCH_NAMED); - $device_uuid = $row['device_uuid']; - unset($row); - } - - //insert the keys - $sql = "insert into v_device_keys "; - $sql .= "("; - $sql .= "domain_uuid, "; - $sql .= "device_key_uuid, "; - $sql .= "device_uuid, "; - $sql .= "device_key_id, "; - $sql .= "device_key_type, "; - $sql .= "device_key_line, "; - $sql .= "device_key_value, "; - $sql .= "device_key_label, "; - $sql .= "device_key_category, "; - $sql .= "device_key_vendor "; - $sql .= ") "; - $sql .= "VALUES ("; - $sql .= "'".$_SESSION['domain_uuid']."', "; - $sql .= "'".$device_key_uuid."', "; - $sql .= "'".$device_uuid."', "; - $sql .= "'".$device_key_id."', "; - $sql .= "'".$device_key_type."', "; - $sql .= "'".$device_key_line."', "; - $sql .= "'".$device_key_value."', "; - $sql .= "'".$device_key_label."', "; - $sql .= "'".$device_key_category."', "; - $sql .= "'".$device_key_vendor."' "; - $sql .= ");"; - - //action add or update - $action = "add"; + //validate the data + $save = true; + //if (!is_uuid($row["device_key_uuid"])) { $save = false; } + if (isset($row["device_key_id"])) { + if (!is_numeric($row["device_key_id"])) { $save = false; echo $row["device_key_id"]." id "; } } - } - else { - //action add or update - $action = "update"; + if (strlen($row["device_key_type"]) > 25) { $save = false; echo "type "; } + if (strlen($row["device_key_value"]) > 25) { $save = false; echo "value "; } + if (strlen($row["device_key_label"]) > 25) { $save = false; echo "label "; } - //update the device keys - $sql = "update v_device_keys set "; - if (permission_exists('device_key_id')) { - $sql .= "device_key_id = '".$device_key_id."', "; + //escape characters in the string + $device_uuid = check_str($row["device_uuid"]); + $device_key_uuid = check_str($row["device_key_uuid"]); + $device_key_id = check_str($row["device_key_id"]); + $device_key_type = check_str($row["device_key_type"]); + $device_key_line = check_str($row["device_key_line"]); + $device_key_value = check_str($row["device_key_value"]); + $device_key_label = check_str($row["device_key_label"]); + $device_key_category = check_str($row["device_key_category"]); + $device_key_vendor = check_str($row["device_key_vendor"]); + + //process the profile keys + if (strlen($row["device_profile_uuid"]) > 0) { + //get the profile key settings from the array + foreach ($device_profile_keys as &$field) { + if ($device_key_uuid == $field["device_key_uuid"]) { + $database = $field; + break; + } + } + //determine what to do with the profile key + if ($device_key_id == $database["device_key_id"] + && $device_key_value == $database["device_key_value"] + && $device_key_label == $database["device_key_label"]) { + //profile key unchanged don't save + $save = false; + } + else { + //profile key has changed remove save the settings to the device + $device_key_uuid = ''; + } + } + + //sql add or update + if (strlen($device_key_uuid) == 0) { + if (permission_exists('device_key_add') && strlen($device_key_type) > 0 && strlen($device_key_value) > 0) { + + //create the primary keys + $device_key_uuid = uuid(); + + //if the device_uuid is not in the array then get the device_uuid from the database + if (strlen($device_uuid) == 0) { + $sql = "SELECT device_uuid, device_profile_uuid FROM v_devices "; + $sql .= "WHERE device_user_uuid = '".$_SESSION['user_uuid']."' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_NAMED); + $device_uuid = $row['device_uuid']; + unset($row); + } + + //insert the keys + $sql = "insert into v_device_keys "; + $sql .= "("; + $sql .= "domain_uuid, "; + $sql .= "device_key_uuid, "; + $sql .= "device_uuid, "; + $sql .= "device_key_id, "; + $sql .= "device_key_type, "; + $sql .= "device_key_line, "; + $sql .= "device_key_value, "; + $sql .= "device_key_label, "; + $sql .= "device_key_category, "; + $sql .= "device_key_vendor "; + $sql .= ") "; + $sql .= "VALUES ("; + $sql .= "'".$_SESSION['domain_uuid']."', "; + $sql .= "'".$device_key_uuid."', "; + $sql .= "'".$device_uuid."', "; + $sql .= "'".$device_key_id."', "; + $sql .= "'".$device_key_type."', "; + $sql .= "'".$device_key_line."', "; + $sql .= "'".$device_key_value."', "; + $sql .= "'".$device_key_label."', "; + $sql .= "'".$device_key_category."', "; + $sql .= "'".$device_key_vendor."' "; + $sql .= ");"; + + //action add or update + $action = "add"; } - $sql .= "device_key_type = '".$device_key_type."', "; - $sql .= "device_key_value = '".$device_key_value."', "; - $sql .= "device_key_label = '".$device_key_label."' "; - $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; - $sql .= "and device_key_uuid = '".$device_key_uuid."'; "; - } - if ($save) { - $db->exec(check_sql($sql)); - //echo "valid: ".$sql."\n"; - } - else { - //echo "invalid: ".$sql."\n"; - } + } + else { + //action add or update + $action = "update"; + + //update the device keys + $sql = "update v_device_keys set "; + if (permission_exists('device_key_id')) { + $sql .= "device_key_id = '".$device_key_id."', "; + } + $sql .= "device_key_type = '".$device_key_type."', "; + $sql .= "device_key_value = '".$device_key_value."', "; + $sql .= "device_key_label = '".$device_key_label."' "; + $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; + $sql .= "and device_key_uuid = '".$device_key_uuid."'; "; + } + if ($save) { + $db->exec(check_sql($sql)); + //echo "valid: ".$sql."\n"; + } + else { + //echo "invalid: ".$sql."\n"; + } + } } //write the provision files @@ -302,18 +312,22 @@ unset($row); //get device lines - $sql = "SELECT * from v_device_lines "; - $sql .= "WHERE device_uuid = '".$device_uuid."' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $device_lines = $prep_statement->fetchAll(PDO::FETCH_NAMED); + if (isset($device_uuid)) { + $sql = "SELECT * from v_device_lines "; + $sql .= "WHERE device_uuid = '".$device_uuid."' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $device_lines = $prep_statement->fetchAll(PDO::FETCH_NAMED); + } //get the user - foreach ($device_lines as $row) { - if ($_SESSION['domain_name'] == $row['server_address']) { - $user_id = $row['user_id']; - $server_address = $row['server_address']; - break; + if (is_array($device_lines)) { + foreach ($device_lines as $row) { + if ($_SESSION['domain_name'] == $row['server_address']) { + $user_id = $row['user_id']; + $server_address = $row['server_address']; + break; + } } } @@ -321,57 +335,63 @@ $sip_profile_name = 'internal'; //get device keys in the right order where device keys are listed after the profile keys - $sql = "SELECT * FROM v_device_keys "; - $sql .= "WHERE ("; - $sql .= "device_uuid = '".$device_uuid."' "; - if (strlen($device_profile_uuid) > 0) { - $sql .= "or device_profile_uuid = '".$device_profile_uuid."' "; - } - $sql .= ") "; - $sql .= "ORDER BY "; - $sql .= "device_key_vendor ASC, "; - $sql .= "CASE device_key_category "; - $sql .= "WHEN 'line' THEN 1 "; - $sql .= "WHEN 'memory' THEN 2 "; - $sql .= "WHEN 'programmable' THEN 3 "; - $sql .= "WHEN 'expansion' THEN 4 "; - $sql .= "ELSE 100 END, "; - if ($db_type == "mysql") { - $sql .= "device_key_id ASC "; - } - else { - $sql .= "CAST(device_key_id as numeric) ASC, "; - } - $sql .= "CASE WHEN device_uuid IS NULL THEN 0 ELSE 1 END ASC "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $keys = $prep_statement->fetchAll(PDO::FETCH_NAMED); - unset($sql,$prep_statement); - -//override profile keys with device keys - foreach($keys as $row) { - $id = $row['device_key_id']; - $device_keys[$id] = $row; - if (is_uuid($row['device_profile_uuid'])) { - $device_keys[$id]['device_key_owner'] = "profile"; + if (isset($device_uuid)) { + $sql = "SELECT * FROM v_device_keys "; + $sql .= "WHERE ("; + $sql .= "device_uuid = '".$device_uuid."' "; + if (strlen($device_profile_uuid) > 0) { + $sql .= "or device_profile_uuid = '".$device_profile_uuid."' "; + } + $sql .= ") "; + $sql .= "ORDER BY "; + $sql .= "device_key_vendor ASC, "; + $sql .= "CASE device_key_category "; + $sql .= "WHEN 'line' THEN 1 "; + $sql .= "WHEN 'memory' THEN 2 "; + $sql .= "WHEN 'programmable' THEN 3 "; + $sql .= "WHEN 'expansion' THEN 4 "; + $sql .= "ELSE 100 END, "; + if ($db_type == "mysql") { + $sql .= "device_key_id ASC "; } else { - $device_keys[$id]['device_key_owner'] = "device"; + $sql .= "CAST(device_key_id as numeric) ASC, "; } + $sql .= "CASE WHEN device_uuid IS NULL THEN 0 ELSE 1 END ASC "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $keys = $prep_statement->fetchAll(PDO::FETCH_NAMED); + unset($sql,$prep_statement); + } + +//override profile keys with device keys + if (is_array($device_keys)) { + foreach($keys as $row) { + $id = $row['device_key_id']; + $device_keys[$id] = $row; + if (is_uuid($row['device_profile_uuid'])) { + $device_keys[$id]['device_key_owner'] = "profile"; + } + else { + $device_keys[$id]['device_key_owner'] = "device"; + } + } + unset($keys); } - unset($keys); //get the vendor count and last and device information - $vendor_count = 0; - foreach($device_keys as $row) { - if ($previous_vendor != $row['device_key_vendor']) { - $previous_vendor = $row['device_key_vendor']; - $device_uuid = $row['device_uuid']; - $device_key_vendor = $row['device_key_vendor']; - $device_key_id = $row['device_key_id']; - $device_key_line = $row['device_key_line']; - $device_key_category = $row['device_key_category']; - $vendor_count++; + if (is_array($device_keys)) { + $vendor_count = 0; + foreach($device_keys as $row) { + if ($previous_vendor != $row['device_key_vendor']) { + $previous_vendor = $row['device_key_vendor']; + $device_uuid = $row['device_uuid']; + $device_key_vendor = $row['device_key_vendor']; + $device_key_id = $row['device_key_id']; + $device_key_line = $row['device_key_line']; + $device_key_category = $row['device_key_category']; + $vendor_count++; + } } } @@ -389,27 +409,31 @@ } //remove the keys the user is not allowed to edit based on the authorized vendor keys - foreach($device_keys as $row) { - //loop through the authorized vendor functions - $device_key_authorized = false; - foreach($vendor_functions as $function) { - if (strlen($row['device_key_type'] == 0)) { - $device_key_authorized = true; - } - else { - if ($function['vendor_name'] == $row['device_key_vendor'] && $function['value'] == $row['device_key_type']) { - $device_key_authorized = true; + if (is_array($device_keys)) { + foreach($device_keys as $row) { + //loop through the authorized vendor functions + $device_key_authorized = false; + if (is_array($vendor_functions)) { + foreach($vendor_functions as $function) { + if (strlen($row['device_key_type'] == 0)) { + $device_key_authorized = true; + } + else { + if ($function['vendor_name'] == $row['device_key_vendor'] && $function['value'] == $row['device_key_type']) { + $device_key_authorized = true; + } + } } } - } - //unset vendor functions the is not allowed to edit - if (!$device_key_authorized) { - unset($device_keys[$row['device_key_id']]); - } - //hide protected keys - if ($row['device_key_protected'] == "true") { - unset($device_keys[$row['device_key_id']]); - } + //unset vendor functions the is not allowed to edit + if (!$device_key_authorized) { + unset($device_keys[$row['device_key_id']]); + } + //hide protected keys + if ($row['device_key_protected'] == "true") { + unset($device_keys[$row['device_key_id']]); + } + } } //show the header @@ -437,91 +461,69 @@ if (permission_exists('device_key_edit')) { echo "
| ".$text['label-device_key_category']." | \n"; + echo "".$text['label-device_key_id']." | \n"; + if (strlen($row['device_key_vendor']) > 0) { + echo "".ucwords($row['device_key_vendor'])." | \n"; + } else { + 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 "|||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ".$text['label-device_key_category']." | \n"; - echo "".$text['label-device_key_id']." | \n"; - if (strlen($row['device_key_vendor']) > 0) { - echo "".ucwords($row['device_key_vendor'])." | \n"; - } else { - 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"; + */ - echo "\n"; - //echo " \n"; - ?> - - - - - \n"; - echo " \n"; - $previous_vendor = ''; - $i=0; - foreach ($vendor_functions as $function) { - if (strlen($row['device_key_vendor']) == 0 && $function['vendor_name'] != $previous_vendor) { - if ($i > 0) { echo " \n"; } - echo " | \n"; + //echo "\n";
+ //echo " | \n";
- echo "\n"; - echo " \n"; - echo " | \n"; + echo "\n"; + echo " \n"; + echo " | \n"; - //echo "\n"; - //echo " \n"; - //echo " | \n"; + //echo "\n"; + //echo " \n"; + //echo " | \n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo " | \n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo " | \n"; - //echo "\n"; - //echo " \n"; - //echo " | \n"; - //echo "\n"; - //if (strlen($row['device_key_uuid']) > 0) { - // if (permission_exists('device_key_delete')) { - // echo " $v_link_label_delete\n"; - // } - //} - //echo " | \n"; + //echo "\n"; + //echo " \n"; + //echo " | \n"; + //echo "\n"; + //if (strlen($row['device_key_uuid']) > 0) { + // if (permission_exists('device_key_delete')) { + // echo " $v_link_label_delete\n"; + // } + //} + //echo " | \n"; - echo "