From 63bb9b6e814ea584c09cafb70f66833245ce9326 Mon Sep 17 00:00:00 2001 From: markjcrane Date: Mon, 3 Jul 2023 08:26:19 -0600 Subject: [PATCH] Add QR code for linphone. Use a PHP QR library. Format the device address --- app/devices/device_edit.php | 202 +++++++++++++++++++++++------------- 1 file changed, 130 insertions(+), 72 deletions(-) diff --git a/app/devices/device_edit.php b/app/devices/device_edit.php index 939f2207b3..9610d717a8 100644 --- a/app/devices/device_edit.php +++ b/app/devices/device_edit.php @@ -97,7 +97,7 @@ $device_address = $_POST["device_address"]; } else { - $sql = "select * from v_devices "; + $sql = "select device_address from v_devices "; $sql .= "where device_uuid = :device_uuid "; $parameters['device_uuid'] = $device_uuid; $database = new database; @@ -513,7 +513,6 @@ $device_provisioned_ip = $row["device_provisioned_ip"]; $domain_uuid = $row["domain_uuid"]; $device_label = $row["device_label"]; - //$device_address = 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); $device_label = $row["device_label"]; $device_user_uuid = $row["device_user_uuid"]; $device_username = $row["device_username"]; @@ -743,8 +742,19 @@ echo ""; } +//determine whether to build the qrcode + if ($device_template == "grandstream/wave") { + $qr_code_enabled = true; + } + elseif ($device_template == "linphone/default") { + $qr_code_enabled = true; + } + else { + $qr_code_enabled = false; + } + //add the QR code - if (permission_exists("device_line_password") && !empty($device_template) && $device_template == "grandstream/wave") { + 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'])) { @@ -770,76 +780,124 @@ } $outbound_proxy_secondary = $row['outbound_proxy_secondary']; - //build the xml - $xml = ""; - $xml .= ""; - $xml .= ""; - $xml .= "".$row['server_address'].""; - $xml .= "".$outbound_proxy_primary.":".$row['sip_port'].""; - $xml .= "".$outbound_proxy_secondary.":".$row['sip_port'].""; - $xml .= "".$row['user_id'].""; - $xml .= "".$row['auth_id'].""; - $xml .= "".$row['password'].""; - $xml .= "".$row['user_id'].""; - $xml .= "".$row['display_name'].""; - $xml .= "{x+|*x+|*++}"; - $xml .= "0"; - $xml .= "*97"; - $xml .= ""; - $xml .= ""; + //build content for grandstream wave + if ($device_template == "grandstream/wave") { + $content = ""; + $content .= ""; + $content .= ""; + $content .= "".$row['server_address'].""; + $content .= "".$outbound_proxy_primary.":".$row['sip_port'].""; + $content .= "".$outbound_proxy_secondary.":".$row['sip_port'].""; + $content .= "".$row['user_id'].""; + $content .= "".$row['auth_id'].""; + $content .= "".$row['password'].""; + $content .= "".$row['user_id'].""; + $content .= "".$row['display_name'].""; + $content .= "{x+|*x+|*++}"; + $content .= "0"; + $content .= "*97"; + $content .= ""; + $content .= ""; + } - //qr code generation - $_GET['type'] = "text"; - echo ""; - echo ""; - echo ""; - echo ""; + //build content for linphone + if ($device_template == "linphone/default") { + $content = "https://".$_SESSION['domain_name'].'/app/provision/index.php?address='.$device_address; + //$content = "https://".$_SESSION['domain_name'].'/'.$device_address.'.xml'; + } + + //stream the file + if (!empty($content)) { + $xml = html_entity_decode($xml, ENT_QUOTES, 'UTF-8'); + + require_once 'resources/qr_code/QRErrorCorrectLevel.php'; + require_once 'resources/qr_code/QRCode.php'; + require_once 'resources/qr_code/QRCodeImage.php'; + + try { + $code = new QRCode (- 1, QRErrorCorrectLevel::H); + $code->addData($content); + $code->make(); + + $img = new QRCodeImage ($code, $width=420, $height=420, $quality=50); + $img->draw(); + $image = $img->getImage(); + $img->finish(); + } + catch (Exception $error) { + echo $error; + } + } + + //html image + if (!empty($content)) { + + echo "\n"; + echo "\n"; + + echo ""; + echo "
\n"; + echo " \n"; + echo "
\n"; + } + /* if (isset($_SESSION['theme']['qr_image'])) { echo ""; } else { echo ""; } + */ + + } //show the content @@ -852,8 +910,8 @@ echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','link'=>'devices.php']); if ($action == 'update') { $button_margin = 'margin-left: 15px;'; - if (permission_exists("device_line_password") && $device_template == "grandstream/wave") { - echo button::create(['type'=>'button','label'=>$text['button-qr_code'],'icon'=>'qrcode','style'=>($button_margin ?? ''),'onclick'=>"$('#qr_code_container').fadeIn(400);"]); + if (permission_exists("device_line_password") && $qr_code_enabled) { + echo button::create(['type'=>'button','label'=>$text['button-qr_code'],'icon'=>'qrcode','style'=>($button_margin ?? ''),'onclick'=>"fade_in('image-container');"]); unset($button_margin); } echo button::create(['type'=>'button','label'=>$text['button-provision'],'icon'=>'fax','style'=>($button_margin ?? ''),'link'=>PROJECT_PATH."/app/devices/cmd.php?cmd=check_sync"."&user=".urlencode($user_id ?? '')."&domain=".urlencode($server_address ?? '')."&agent=".urlencode($device_vendor)]); @@ -934,12 +992,12 @@ echo "\n"; echo "\n"; if (permission_exists('device_address')) { - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-device_address']."\n"; } else { - echo escape($device_address ?? ''); + echo escape(format_device_address($device_address ?? '')); } echo " \n"; echo " ".escape($device_provisioned_ip ?? '')." (http|https)\n"; @@ -1139,7 +1197,7 @@ echo " \n"; echo " \n"; @@ -1961,4 +2019,4 @@ //show the footer require_once "resources/footer.php"; -?> +?> \ No newline at end of file