diff --git a/app/devices/device_edit.php b/app/devices/device_edit.php index 9b54b6535f..4a02b8762f 100644 --- a/app/devices/device_edit.php +++ b/app/devices/device_edit.php @@ -44,8 +44,9 @@ $device_firmware_version = ''; $device_template =''; -//get the domain uuid +//get the domain values $domain_uuid = $_SESSION['domain_uuid'] ?? ''; + $domain_name = $_SESSION['domain_name'] ?? ''; //initialize the database object $database = database::new(); @@ -64,12 +65,12 @@ //get the total device count from the database, check the limit, if defined if ($action == 'add') { - if (!empty($_SESSION['limit']['devices']['numeric']) && $_SESSION['limit']['devices']['numeric']) { + if (!empty($settings->get('limit', 'devices', ''))) { $sql = "select count(*) from v_devices where domain_uuid = :domain_uuid "; - $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $parameters['domain_uuid'] = $domain_uuid; $total_devices = $database->select($sql, $parameters, 'column'); - if ($total_devices >= $_SESSION['limit']['devices']['numeric']) { - message::add($text['message-maximum_devices'].' '.$_SESSION['limit']['devices']['numeric'], 'negative'); + if ($total_devices >= $settings->get('limit', 'devices', '')) { + message::add($text['message-maximum_devices'].' '.$settings->get('limit', 'devices', ''), 'negative'); header('Location: devices.php'); exit; } @@ -228,14 +229,14 @@ $sql .= " and d1.device_uuid <> :device_uuid "; } $parameters['device_address'] = $device_address; - $domain_name = $database->select($sql, $parameters, 'column'); - if ($domain_name != '') { - $message = $text['message-duplicate'].(if_group("superadmin") && $_SESSION["domain_name"] != $domain_name ? ": ".$domain_name : null); + $device_domain_name = $database->select($sql, $parameters, 'column'); + if ($device_domain_name != '') { + $message = $text['message-duplicate'].($device_domain_name != $domain_name ? ": ".$device_domain_name : null); message::add($message,'negative'); header('Location: devices.php'); exit; } - unset($sql, $parameters, $domain_name); + unset($sql, $parameters, $device_domain_name); } //add or update the database @@ -304,6 +305,7 @@ $device_line_uuid = uuid(); $new_line = true; } + $array['devices'][0]['device_lines'][$y]['domain_uuid'] = $domain_uuid; $array['devices'][0]['device_lines'][$y]['device_uuid'] = $device_uuid; $array['devices'][0]['device_lines'][$y]['device_line_uuid'] = $device_line_uuid; @@ -311,23 +313,23 @@ $array['devices'][0]['device_lines'][$y]['server_address'] = $row["server_address"]; if (permission_exists('device_line_outbound_proxy_primary')) { $array['devices'][0]['device_lines'][$y]['outbound_proxy_primary'] = $row["outbound_proxy_primary"]; - } else if ($new_line && isset($_SESSION['provision']['outbound_proxy_primary'])) { - $array['devices'][0]['device_lines'][$y]['outbound_proxy_primary'] = $_SESSION['provision']['outbound_proxy_primary']['text']; + } else if ($new_line && !empty($settings->get('provision', 'outbound_proxy_primary'))) { + $array['devices'][0]['device_lines'][$y]['outbound_proxy_primary'] = $settings->get('provision', 'outbound_proxy_primary', ''); } if (permission_exists('device_line_outbound_proxy_secondary')) { $array['devices'][0]['device_lines'][$y]['outbound_proxy_secondary'] = $row["outbound_proxy_secondary"]; - } else if ($new_line && isset($_SESSION['provision']['outbound_proxy_secondary'])) { - $array['devices'][0]['device_lines'][$y]['outbound_proxy_secondary'] = $_SESSION['provision']['outbound_proxy_secondary']['text']; + } else if ($new_line && !empty($settings->get('provision', 'outbound_proxy_secondary'))) { + $array['devices'][0]['device_lines'][$y]['outbound_proxy_secondary'] = $settings->get('provision', 'outbound_proxy_secondary', ''); } if (permission_exists('device_line_server_address_primary')) { $array['devices'][0]['device_lines'][$y]['server_address_primary'] = $row["server_address_primary"]; - } else if ($new_line && isset($_SESSION['provision']['server_address_primary'])) { - $array['devices'][0]['device_lines'][$y]['server_address_primary'] = $_SESSION['provision']['server_address_primary']['text']; + } else if ($new_line && !empty($settings->get('provision', 'server_address_primary'))) { + $array['devices'][0]['device_lines'][$y]['server_address_primary'] = $settings->get('provision', 'server_address_primary', ''); } if (permission_exists('device_line_server_address_secondary')) { $array['devices'][0]['device_lines'][$y]['server_address_secondary'] = $row["server_address_secondary"]; - } else if ($new_line && isset($_SESSION['provision']['server_address_secondary'])) { - $array['devices'][0]['device_lines'][$y]['server_address_secondary'] = $_SESSION['provision']['server_address_secondary']['text']; + } else if ($new_line && !empty($settings->get('provision', 'server_address_secondary'))) { + $array['devices'][0]['device_lines'][$y]['server_address_secondary'] = $settings->get('provision', 'server_address_secondary', ''); } if (permission_exists('device_line_label')) { $array['devices'][0]['device_lines'][$y]['label'] = $row["label"]; @@ -351,7 +353,7 @@ } else { if ($action == "add") { - $array['devices'][0]['device_lines'][$y]['sip_port'] = $_SESSION['provision']['line_sip_port']['numeric']; + $array['devices'][0]['device_lines'][$y]['sip_port'] = $settings->get('provision', 'line_sip_port', '5060'); } } if (permission_exists('device_line_transport')) { @@ -359,7 +361,7 @@ } else { if ($action == "add") { - $array['devices'][0]['device_lines'][$y]['sip_transport'] = $_SESSION['provision']['line_sip_transport']['text']; + $array['devices'][0]['device_lines'][$y]['sip_transport'] = $settings->get('provision', 'line_sip_transport', 'tcp'); } } if (permission_exists('device_line_register_expires')) { @@ -367,7 +369,7 @@ } else { if ($action == "add") { - $array['devices'][0]['device_lines'][$y]['register_expires'] = $_SESSION['provision']['line_register_expires']['numeric']; + $array['devices'][0]['device_lines'][$y]['register_expires'] = $settings->get('provision', 'line_register_expires', '120'); } } $y++; @@ -480,7 +482,7 @@ } //write the provision files - if (!empty($_SESSION['provision']['path']['text'])) { + if (!empty($settings->get('provision', 'path'))) { $prov = new provision(['settings' => $settings]); $prov->domain_uuid = $domain_uuid; $response = $prov->write(); @@ -509,7 +511,6 @@ $sql = "select * from v_devices "; $sql .= "where device_uuid = :device_uuid "; $parameters['device_uuid'] = $device_uuid; - $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && @sizeof($row) != 0) { $device_address = $row["device_address"]; @@ -533,6 +534,14 @@ unset($sql, $parameters, $row); } +//get device lines + $sql = "select * "; + $sql .= "from v_domains "; + $sql .= "where domain_enabled = true "; + $sql .= "order by domain_name asc "; + $domains = $database->select($sql, null, 'all'); + unset($sql, $parameters); + //set the defaults if (empty($device_enabled)) { $device_enabled = 'true'; } @@ -563,20 +572,22 @@ } //get device lines - $sql = "select * from v_device_lines "; + $sql = "select l.*, d.domain_name "; + $sql .= "from v_device_lines as l, v_domains as d "; $sql .= "where device_uuid = :device_uuid "; + $sql .= "and l.domain_uuid = d.domain_uuid "; $sql .= "order by cast(line_number as int) asc "; $parameters['device_uuid'] = $device_uuid ?? null; - $device_lines = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); +//set the new line defaults $device_lines[$x]['line_number'] = ''; $device_lines[$x]['server_address'] = ''; - $device_lines[$x]['outbound_proxy_primary'] = $_SESSION['provision']['outbound_proxy_primary']['text'] ?? null; - $device_lines[$x]['outbound_proxy_secondary'] = $_SESSION['provision']['outbound_proxy_secondary']['text'] ?? null; - $device_lines[$x]['server_address_primary'] = $_SESSION['provision']['server_address_primary']['text'] ?? null; - $device_lines[$x]['server_address_secondary'] = $_SESSION['provision']['server_address_secondary']['text'] ?? null; + $device_lines[$x]['outbound_proxy_primary'] = $settings->get('provision', 'outbound_proxy_primary', null); + $device_lines[$x]['outbound_proxy_secondary'] = $settings->get('provision', 'outbound_proxy_secondary', null); + $device_lines[$x]['server_address_primary'] = $settings->get('provision', 'server_address_primary', null); + $device_lines[$x]['server_address_secondary'] = $settings->get('provision', 'server_address_secondary', null); $device_lines[$x]['label'] = ''; $device_lines[$x]['display_name'] = ''; $device_lines[$x]['user_id'] = ''; @@ -584,9 +595,9 @@ $device_lines[$x]['password'] = ''; $device_lines[$x]['shared_line'] = ''; $device_lines[$x]['enabled'] = ''; - $device_lines[$x]['sip_port'] = $_SESSION['provision']['line_sip_port']['numeric']; - $device_lines[$x]['sip_transport'] = $_SESSION['provision']['line_sip_transport']['text']; - $device_lines[$x]['register_expires'] = $_SESSION['provision']['line_register_expires']['numeric']; + $device_lines[$x]['sip_port'] = $settings->get('provision', 'line_sip_port', '5060'); + $device_lines[$x]['sip_transport'] = $settings->get('provision', 'line_sip_transport', 'tcp'); + $device_lines[$x]['register_expires'] = $settings->get('provision', 'line_register_expires', '120'); //get device keys $sql = "select * from v_device_keys "; @@ -612,11 +623,11 @@ //add empty device key row(s) if (!is_uuid($device_uuid)) { - $rows = $_SESSION['devices']['key_add_rows']['numeric'] ?? 1; + $rows = $settings->get('devices', 'key_add_rows', '10'); $id = 0; } else { - $rows = $_SESSION['devices']['key_edit_rows']['numeric'] ?? 1; + $rows = $settings->get('devices', 'key_edit_rows', '3'); $id = count($device_keys) + 1; } for ($x = 0; $x < $rows; $x++) { @@ -638,7 +649,6 @@ $sql .= "from v_device_vendors "; $sql .= "where enabled = 'true' "; $sql .= "order by name asc "; - $device_vendors = $database->select($sql, null, 'all'); unset($sql); @@ -662,11 +672,11 @@ //add empty device setting row(s) if (!is_uuid($device_uuid)) { - $rows = $_SESSION['devices']['setting_add_rows']['numeric'] ?? 1; + $rows = $settings->get('devices', 'key_add_rows', '10'); $id = 0; } else { - $rows = $_SESSION['devices']['setting_edit_rows']['numeric'] ?? 1; + $rows = $settings->get('devices', 'key_edit_rows', '3'); $id = count($device_settings) + 1; } for ($x = 0; $x < $rows; $x++) { @@ -694,12 +704,7 @@ //get the first device line info (found on the local server) for the provision button foreach ($device_lines as $row) { - if ( - array_key_exists($row['domain_uuid'], $_SESSION['domains']) && - $row['server_address'] == $_SESSION['domains'][$row['domain_uuid']]['domain_name'] && - !empty($row['user_id']) && - !empty($row['server_address']) - ) { + if ($row['server_address'] == $row['domain_name'] && !empty($row['user_id']) && !empty($row['server_address'])) { $user_id = $row['user_id']; $server_address = $row['server_address']; break; @@ -731,14 +736,13 @@ echo " $('#target_file').fadeOut(fade_speed);\n"; echo " document.getElementById('target_file').selectedIndex = 0;\n"; echo " }\n"; - echo " function download(d) {\n"; echo " if (d == '".$text['label-download']."') return;\n"; - if ($_SESSION['provision']['http_domain_filter']['boolean'] == "false") { - $domain_name = $_SERVER["HTTP_HOST"]; + if ($settings->get('provision', 'http_domain_filter', true)) { + $provision_domain_name = $domain_name; } else { - $domain_name = $_SESSION['domain_name']; + $provision_domain_name = $_SERVER["HTTP_HOST"]; } if (!isset($_SERVER['HTTP_PROTOCOL'])) { @@ -747,7 +751,7 @@ if ($_SERVER['HTTPS'] == 'on') { $_SERVER['HTTP_PROTOCOL'] = 'https'; } if ($_SERVER['SERVER_PORT'] == '443') { $_SERVER['HTTP_PROTOCOL'] = 'https'; } } - echo " window.location = '".$_SERVER['HTTP_PROTOCOL']."://".$domain_name.PROJECT_PATH."/app/provision/index.php?address=".escape($device_address ?? '')."&file=' + d + '&content_type=application/octet-stream';\n"; + echo " window.location = '".$_SERVER['HTTP_PROTOCOL']."://".$provision_domain_name.PROJECT_PATH."/app/provision/index.php?address=".escape($device_address ?? '')."&file=' + d + '&content_type=application/octet-stream';\n"; echo " }\n"; echo "\n"; @@ -793,16 +797,11 @@ //add the QR code if (permission_exists("device_line_password") && !empty($device_template) && $qr_code_enabled) { //set the mode - if (isset($_SESSION['theme']['qr_image'])) { - if (!empty($_SESSION['theme']['qr_image'])) { - $mode = '4'; - } - else { - $mode = '0'; - } + if (!empty($settings->get('theme', 'qr_image', ''))) { + $mode = '4'; } else { - $mode = '4'; + $mode = '0'; } //get the device line settings @@ -922,15 +921,10 @@ //build content for linphone if ($device_template == "linphone/default") { $auth_string = ''; - if ( - !empty($_SESSION['provision']['http_auth_enabled']['boolean']) && - $_SESSION['provision']['http_auth_enabled']['boolean'] == 'true' && - !empty($_SESSION['provision']['http_auth_username']['text']) && - !empty($_SESSION['provision']['http_auth_password'][0]) - ) { - $auth_string = $_SESSION['provision']['http_auth_username']['text'].':'.$_SESSION['provision']['http_auth_password'][0].'@'; + if ($settings->get('provision', 'http_auth_enabled', true) && !empty($settings->get('provision', 'http_auth_username', '')) && !empty($settings->get('provision', 'http_auth_password', ''))) { + $auth_string = $settings->get('provision', 'http_auth_username', '').':'.$settings->get('provision', 'http_auth_password', '').'@'; } - $content = "https://".$auth_string.$_SESSION['domain_name'].'/app/provision/index.php?address='.$device_address; + $content = "https://".$auth_string.$provision_domain_name.'/app/provision/index.php?address='.$device_address; } //stream the file @@ -1001,16 +995,16 @@ echo " \n"; echo "\n"; } + /* - if (isset($_SESSION['theme']['qr_image'])) { - echo ""; + if (!empty($settings->get('theme', 'qr_image', ''))) { + echo ""; } else { - echo ""; + echo ""; } */ - } //show the content @@ -1020,7 +1014,7 @@ echo "
\n"; echo "
".$text['header-device']."
\n"; echo "
\n"; - echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','link'=>'devices.php']); + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back', ''),'id'=>'btn_back','link'=>'devices.php']); if ($action == 'update') { $button_margin = 'margin-left: 15px;'; if (permission_exists("device_line_password") && $qr_code_enabled) { @@ -1038,7 +1032,7 @@ $template_dir = $prov->template_dir; $files = glob($template_dir.'/'.$device_template.'/*'); //add file buttons and the file list - echo button::create(['type'=>'button','id'=>'button_files','label'=>$text['button-files'],'icon'=>$_SESSION['theme']['button_icon_download'],'style'=>($button_margin ?? ''),'onclick'=>'show_files()']); + echo button::create(['type'=>'button','id'=>'button_files','label'=>$text['button-files'],'icon'=>$settings->get('theme', 'button_icon_download', ''),'style'=>($button_margin ?? ''),'onclick'=>'show_files()']); echo "\n"; echo " \n"; - foreach($_SESSION['provision']['server_address_primary'] as $field) { + foreach($settings->get('provision', 'server_address_primary', '') as $field) { echo " \n"; } echo " \n"; @@ -1339,10 +1333,10 @@ if (permission_exists('device_line_server_address_secondary')) { echo " \n"; - if (isset($_SESSION['provision']['server_address_secondary']) && !isset($_SESSION['provision']['server_address_secondary']['text'])) { + if (!empty($settings->get('provision', 'server_address_secondary', ''))) { echo " \n"; @@ -1355,10 +1349,10 @@ if (permission_exists('device_line_outbound_proxy_primary')) { echo " \n"; - if (isset($_SESSION['provision']['outbound_proxy_primary']) && !isset($_SESSION['provision']['outbound_proxy_primary']['text'])) { + if (!empty($settings->get('provision', 'outbound_proxy_primary', ''))) { echo " \n"; @@ -1371,10 +1365,10 @@ if (permission_exists('device_line_outbound_proxy_secondary')) { echo " \n"; - if (isset($_SESSION['provision']['outbound_proxy_secondary']) && !isset($_SESSION['provision']['outbound_proxy_secondary']['text'])) { + if (!empty($settings->get('provision', 'outbound_proxy_secondary', ''))) { echo " \n"; @@ -1495,7 +1489,7 @@ foreach($device_profiles as $row) { echo " \n"; } - echo " \n"; + echo " \n"; } else { foreach($device_profiles as $row) { @@ -1963,7 +1957,7 @@ else { echo " \n"; } - foreach ($_SESSION['domains'] as $row) { + foreach ($domains as $row) { if ($row['domain_uuid'] == $domain_uuid) { echo " \n"; } @@ -1978,7 +1972,7 @@ echo "\n"; } else { - echo " \n"; + echo " \n"; } if (permission_exists('device_enable')) { @@ -1987,7 +1981,7 @@ echo " ".$text['label-device_enabled']."\n"; echo "\n"; echo "\n"; - if (substr($_SESSION['theme']['input_toggle_style']['text'], 0, 6) == 'switch') { + if (substr($settings->get('theme', 'input_toggle_style', ''), 0, 6) == 'switch') { echo "