Add QR code for linphone. Use a PHP QR library. Format the device address

This commit is contained in:
markjcrane 2023-07-03 08:26:19 -06:00
parent 255b1773ae
commit 63bb9b6e81
1 changed files with 130 additions and 72 deletions

View File

@ -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 "</script>";
}
//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 version='1.0' encoding='utf-8'?>";
$xml .= "<AccountConfig version='1'>";
$xml .= "<Account>";
$xml .= "<RegisterServer>".$row['server_address']."</RegisterServer>";
$xml .= "<OutboundServer>".$outbound_proxy_primary.":".$row['sip_port']."</OutboundServer>";
$xml .= "<SecOutboundServer>".$outbound_proxy_secondary.":".$row['sip_port']."</SecOutboundServer>";
$xml .= "<UserID>".$row['user_id']."</UserID>";
$xml .= "<AuthID>".$row['auth_id']."</AuthID>";
$xml .= "<AuthPass>".$row['password']."</AuthPass>";
$xml .= "<AccountName>".$row['user_id']."</AccountName>";
$xml .= "<DisplayName>".$row['display_name']."</DisplayName>";
$xml .= "<Dialplan>{x+|*x+|*++}</Dialplan>";
$xml .= "<RandomPort>0</RandomPort>";
$xml .= "<Voicemail>*97</Voicemail>";
$xml .= "</Account>";
$xml .= "</AccountConfig>";
//build content for grandstream wave
if ($device_template == "grandstream/wave") {
$content = "<?xml version='1.0' encoding='utf-8'?>";
$content .= "<AccountConfig version='1'>";
$content .= "<Account>";
$content .= "<RegisterServer>".$row['server_address']."</RegisterServer>";
$content .= "<OutboundServer>".$outbound_proxy_primary.":".$row['sip_port']."</OutboundServer>";
$content .= "<SecOutboundServer>".$outbound_proxy_secondary.":".$row['sip_port']."</SecOutboundServer>";
$content .= "<UserID>".$row['user_id']."</UserID>";
$content .= "<AuthID>".$row['auth_id']."</AuthID>";
$content .= "<AuthPass>".$row['password']."</AuthPass>";
$content .= "<AccountName>".$row['user_id']."</AccountName>";
$content .= "<DisplayName>".$row['display_name']."</DisplayName>";
$content .= "<Dialplan>{x+|*x+|*++}</Dialplan>";
$content .= "<RandomPort>0</RandomPort>";
$content .= "<Voicemail>*97</Voicemail>";
$content .= "</Account>";
$content .= "</AccountConfig>";
}
//qr code generation
$_GET['type'] = "text";
echo "<input type='hidden' id='qr_card' value=\"".escape($xml)."\">";
echo "<style>";
echo " #qr_code_container {";
echo " z-index: 999999; ";
echo " position: absolute; ";
echo " left: 0px; ";
echo " top: 0px; ";
echo " right: 0px; ";
echo " bottom: 0px; ";
echo " text-align: center; ";
echo " vertical-align: middle;";
echo " }";
echo " #qr_code {";
echo " display: block; ";
echo " width: 650px; ";
echo " height: 650px; ";
echo " -webkit-box-shadow: 0px 1px 20px #888; ";
echo " -moz-box-shadow: 0px 1px 20px #888; ";
echo " box-shadow: 0px 1px 20px #888;";
echo " }";
echo "</style>";
echo "<script src='".PROJECT_PATH."/resources/jquery/jquery-qrcode.min.js'></script>";
echo "<script language='JavaScript' type='text/javascript'>";
echo " $(document).ready(function() {";
echo " $(window).on('load', function() {";
echo " $('#qr_code').qrcode({ ";
echo " render: 'canvas', ";
echo " minVersion: 6, ";
echo " maxVersion: 40, ";
echo " ecLevel: 'H', ";
echo " size: 650, ";
echo " radius: 0.2, ";
echo " quiet: 6, ";
echo " background: '#fff', ";
echo " mode: ".$mode.", ";
echo " mSize: 0.2, ";
echo " mPosX: 0.5, ";
echo " mPosY: 0.5, ";
echo " image: $('#img-buffer')[0], ";
echo " text: document.getElementById('qr_card').value ";
echo " });";
echo " });";
echo " });";
echo "</script>";
//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 "<script>\n";
echo "\n";
echo " function fade_in(id) {\n";
echo " var image_container = document.getElementById(id);\n";
echo " image_container.style.opacity = '1';\n";
echo " image_container.style.zIndex = '999999';\n";
echo " image_container.style.display = 'block';\n";
echo " }\n";
echo "\n";
echo " function fade_out(id) {\n";
echo " var image_container = document.getElementById(id);\n";
echo " image_container.style.opacity = '0';\n";
echo " image_container.style.zIndex = '0';\n";
echo " setTimeout(display_none, 1000);\n";
echo " }\n";
echo "\n";
echo " function display_none() {\n";
echo " var image_container = document.getElementById('image-container');\n";
echo " image_container.style.display = 'none';\n";
echo " }\n";
echo "\n";
echo "</script>\n";
echo "\n";
echo "<style>\n";
echo "\n";
echo " #image-container {\n";
echo " z-index: = 0;\n";
echo " position: absolute;\n";
echo " top: 50%;\n";
echo " left: 50%;\n";
echo " transform: translate(-50%, -50%);\n";
echo " opacity: 0;\n";
echo " transition: opacity 1s;\n";
echo " display: none;\n";
echo " }\n";
echo "\n";
echo " #qr_code {\n";
echo " width: 650px;\n";
echo " height: 650px;\n";
echo " -webkit-box-shadow: 0px 1px 20px #888;\n";
echo " -moz-box-shadow: 0px 1px 20px #888;\n";
echo " box-shadow: 0px 1px 20px #888;\n";
echo " }\n";
echo "\n";
echo " img {\n";
echo " border: 100px solid white;\n";
echo " max-width: 100%;\n";
echo " max-height: 100%;\n";
echo " }\n";
echo "\n";
echo "</style>";
echo "<div id='image-container' onclick=\"fade_out('image-container');\">\n";
echo " <img id='qr_code' src=\"data:image/jpeg;base64,".base64_encode($image)."\">\n";
echo "</div>\n";
}
/*
if (isset($_SESSION['theme']['qr_image'])) {
echo "<img id='img-buffer' src='".$_SESSION["theme"]["qr_image"]["text"]."' style='display: none;'>";
}
else {
echo "<img id='img-buffer' src='".PROJECT_PATH."/themes/".$_SESSION["domain"]["template"]["name"]."/images/qr_code.png' style='display: none;'>";
}
*/
}
//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 "</td>\n";
echo "<td class='vtable' width='70%' align='left'>\n";
if (permission_exists('device_address')) {
echo " <input class='formfld' type='text' name='device_address' id='device_address' style='width: 235px;' maxlength='36' value=\"".escape($device_address ?? '')."\"/>\n";
echo " <input class='formfld' type='text' name='device_address' id='device_address' style='width: 245px;' maxlength='36' value=\"".escape(format_device_address($device_address ?? ''))."\"/>\n";
echo "<br />\n";
echo $text['description-device_address']."\n";
}
else {
echo escape($device_address ?? '');
echo escape(format_device_address($device_address ?? ''));
}
echo " <div style='display: none;' id='duplicate_mac_response'></div>\n";
echo " ".escape($device_provisioned_ip ?? '')." (<a href='http://".escape($device_provisioned_ip ?? '')."' target='_blank'>http</a>|<a href='https://".escape($device_provisioned_ip ?? '')."' target='_blank'>https</a>)\n";
@ -1139,7 +1197,7 @@
echo " <select class='formfld' name='device_lines[".$x."][line_number]'>\n";
echo " <option value=''></option>\n";
for ($n = 1; $n <=99; $n++) {
echo " <option value='$n' ".($row['line_number'] == "$n" ? $selected:"").">$n</option>\n";
echo " <option value='$n' ".($row['line_number'] == "$n" ? $selected:"").">$n</option>\n";
}
echo " </select>\n";
echo " </td>\n";
@ -1961,4 +2019,4 @@
//show the footer
require_once "resources/footer.php";
?>
?>