fusionpbx/app/gswave/index.php

202 lines
7.8 KiB
PHP
Raw Normal View History

2018-08-08 16:27:48 +02:00
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
2023-05-28 07:06:45 +02:00
Portions created by the Initial Developer are Copyright (C) 2008-2023
2018-08-08 16:27:48 +02:00
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
2022-10-11 00:35:14 +02:00
//includes files
Use magic constant dir (#6711) * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ to load only functions.php * replace spaces with tab character * update dirname command to use levels instead of nesting * use magic constant __DIR__ * update dirname command to use levels instead of nesting * Update access_control_edit.php * Update access_control_import.php * Update access_controls.php * Update dnd.php * Update access_controls_reload.php * Update call_center_agents.php * Update call_center_agents.php * Update fax_queue.php * Update login.php * Update pdo.php * Update pdo_vm.php * Update switch.php * Update index.php * Update css.php * Update v_mailto.php * Update fax_to_email.php --------- Co-authored-by: FusionPBX <markjcrane@gmail.com>
2023-06-15 19:28:23 +02:00
require_once dirname(__DIR__, 2) . "/resources/require.php";
2018-08-08 16:27:48 +02:00
require_once "resources/check_auth.php";
//check permissions
2019-08-23 20:09:25 +02:00
if (permission_exists('gswave_view')) {
2018-08-08 16:27:48 +02:00
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//verify the id is as uuid then set as a variable
2023-05-28 07:06:45 +02:00
if (!empty($_GET['id']) && is_uuid($_GET['id'])) {
2018-08-08 16:27:48 +02:00
$extension_uuid = $_GET['id'];
}
//get the extension(s)
2019-11-05 21:44:59 +01:00
if (permission_exists('extension_edit')) {
//admin user
$sql = "select * from v_extensions ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and enabled = 'true' ";
2023-07-14 05:32:25 +02:00
$sql .= "and extension_type = 'default' ";
2019-11-05 21:44:59 +01:00
$sql .= "order by extension asc ";
}
else {
//normal user
$sql = "select e.* ";
$sql .= "from v_extensions as e, ";
$sql .= "v_extension_users as eu ";
$sql .= "where e.extension_uuid = eu.extension_uuid ";
$sql .= "and eu.user_uuid = :user_uuid ";
2019-11-05 21:44:59 +01:00
$sql .= "and e.domain_uuid = :domain_uuid ";
$sql .= "and e.enabled = 'true' ";
2023-07-14 05:32:25 +02:00
$sql .= "and e.extension_type = 'default' ";
2019-11-05 21:44:59 +01:00
$sql .= "order by e.extension asc ";
$parameters['user_uuid'] = $_SESSION['user']['user_uuid'];
}
2019-08-09 15:06:16 +02:00
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$extensions = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
2018-08-08 16:27:48 +02:00
2023-05-28 07:06:45 +02:00
if (!empty($extension_uuid) && is_uuid($extension_uuid) && !empty($extensions)) {
//loop through get selected extension
2023-05-28 07:06:45 +02:00
if (!empty($extensions)) {
foreach ($extensions as $extension) {
if ($extension['extension_uuid'] == $extension_uuid) {
$field = $extension;
break;
}
}
}
//get the username
$username = $field['extension'];
if (isset($field['number_alias']) && !empty($field['number_alias'])) {
$username = $field['number_alias'];
}
//build the xml
$xml = "<?xml version='1.0' encoding='utf-8'?>";
$xml .= "<AccountConfig version='1'>";
$xml .= "<Account>";
$xml .= "<RegisterServer>".$_SESSION['domain_name']."</RegisterServer>";
//$xml .= "<OutboundServer>".$_SESSION['domain_name']."</OutboundServer>";
//$xml .= "<SecOutboundServer>".$_SESSION['domain_name']."</SecOutboundServer>";
$xml .= "<OutboundServer>".$_SESSION['domain_name'].":".$_SESSION['provision']['line_sip_port']['numeric']."</OutboundServer>";
$xml .= "<SecOutboundServer>".$_SESSION['domain_name'].":".$_SESSION['provision']['line_sip_port']['numeric']."</SecOutboundServer>";
$xml .= "<UserID>".$username."</UserID>";
$xml .= "<AuthID>".$username."</AuthID>";
$xml .= "<AuthPass>".$field['password']."</AuthPass>";
$xml .= "<AccountName>".$username."</AccountName>";
$xml .= "<DisplayName>".$username."</DisplayName>";
$xml .= "<Dialplan>{x+|*x+|*++}</Dialplan>";
$xml .= "<RandomPort>0</RandomPort>";
$xml .= "<Voicemail>*97</Voicemail>";
$xml .= "</Account>";
$xml .= "</AccountConfig>";
$qr_data = $xml;
2018-08-08 16:27:48 +02:00
}
//debian
//apt install qrencode
2020-02-03 18:40:33 +01:00
//include the header
2020-01-06 19:45:14 +01:00
$document['title'] = $text['title-gswave'];
2018-08-08 16:27:48 +02:00
require_once "resources/header.php";
//show the content
echo "<form name='frm' id='frm' method='get'>\n";
2020-02-03 18:40:33 +01:00
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['title-gswave']."</b></div>\n";
echo " <div class='actions'>\n";
2024-02-07 05:31:29 +01:00
echo " <a href='https://play.google.com/store/apps/details?id=com.grandstream.ucm' target='_blank'><img src='/app/gswave/resources/images/google_play.png' style='width: auto; height: 30px;' /></a>";
2023-05-28 07:06:45 +02:00
echo " <a href='https://apps.apple.com/us/app/grandstream-wave/id1523254549' target='_blank'><img src='/app/gswave/resources/images/apple_app_store.png' style='width: auto; height: 30px;' /></a>";
2020-02-03 18:40:33 +01:00
//echo button::create(['type'=>'button','label'=>'Website','icon'=>'globe','style='margin-left: 15px;','link'=>'http://www.grandstream.com/products/ip-voice-telephony/softphone-app/product/grandstream-wave']);
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
echo $text['title_description-gswave']."\n";
echo "<br /><br />\n";
echo "<div style='text-align: center; white-space: nowrap; margin: 10px 0 40px 0;'>";
echo $text['label-extension']."<br />\n";
echo "<select name='id' class='formfld' onchange='this.form.submit();'>\n";
echo " <option value='' >".$text['label-select']."...</option>\n";
if (is_array($extensions) && @sizeof($extensions) != 0) {
2020-02-03 18:40:33 +01:00
foreach ($extensions as $row) {
$selected = !empty($extension_uuid) && $row['extension_uuid'] == $extension_uuid ? "selected='selected'" : null;
2020-02-03 18:40:33 +01:00
echo " <option value='".escape($row['extension_uuid'])."' ".$selected.">".escape($row['extension'])." ".escape($row['number_alias'])." ".escape($row['description'])."</option>\n";
}
2018-08-08 16:27:48 +02:00
}
2020-02-03 18:40:33 +01:00
echo "</select>\n";
echo "</form>\n";
echo "<br>\n";
2018-08-08 16:27:48 +02:00
//stream the file
2023-05-28 07:06:45 +02:00
if (!empty($extension_uuid) && is_uuid($extension_uuid)) {
$xml = html_entity_decode($xml, ENT_QUOTES, 'UTF-8');
2018-08-30 09:26:49 +02:00
2020-02-03 18:40:33 +01:00
require_once 'resources/qr_code/QRErrorCorrectLevel.php';
require_once 'resources/qr_code/QRCode.php';
require_once 'resources/qr_code/QRCodeImage.php';
2018-08-30 09:26:49 +02:00
try {
$code = new QRCode (- 1, QRErrorCorrectLevel::H);
$code->addData($xml);
$code->make();
$img = new QRCodeImage ($code, $width=420, $height=420, $quality=50);
$img->draw();
$image = $img->getImage();
$img->finish();
}
catch (Exception $error) {
echo $error;
}
2018-08-08 16:27:48 +02:00
}
//html image
2023-05-28 07:06:45 +02:00
if (!empty($extension_uuid) && is_uuid($extension_uuid)) {
echo "<img src=\"data:image/jpeg;base64,".base64_encode($image)."\" style='margin-top: 30px; padding: 5px; background: white; max-width: 100%;'>\n";
//qr data preview
if (permission_exists('gswave_xml_view')) {
echo "<br><br><br>\n";
echo "<button id='btn_show_qr_data' type='button' class='btn btn-link' onclick=\"$('#qr_data').show(); $(this).hide(); $('#btn_hide_qr_data').show();\">Show QR Code Data</button>\n";
echo "<button id='btn_hide_qr_data' type='button' class='btn btn-link' style='display: none;' onclick=\"$('#qr_data').hide(); $(this).hide(); $('#btn_show_qr_data').show();\">Hide QR Code Data</button><br>\n";
echo "<textarea id='qr_data' spellcheck='false' readonly='readonly' style='margin: 20px auto; border: 1px solid ".($_SESSION['theme']['table_row_border_color']['text'] ?? '#c5d1e5')."; padding: 20px; width: 100%; max-width: 600px; height: 350px; overflow: auto; font-family: monospace; font-size: 12px; background-color: ".($_SESSION['theme']['table_row_background_color_light']['text'] ?? '#fff')."; color: ".($_SESSION['theme']['table_row_text_color']['text'] ?? '#000')."; display: none;'>\n";
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = true;
$dom->formatOutput = true;
$dom->loadXML($qr_data);
echo $dom->saveXML();
echo "</textarea>\n";
}
2018-08-08 16:27:48 +02:00
}
2020-02-03 18:40:33 +01:00
echo "</div>\n";
2018-08-08 16:27:48 +02:00
//add the footer
require_once "resources/footer.php";
2023-07-14 05:32:25 +02:00
?>