Fork of FusionPBX but with LDAP kinda working
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
7.6 KiB

2 years ago
2 years ago
2 years ago
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <markjcrane@fusionpbx.com>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2020
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <markjcrane@fusionpbx.com>
  20. */
  21. //includes
  22. require_once "root.php";
  23. require_once "resources/require.php";
  24. require_once "resources/check_auth.php";
  25. //check permissions
  26. if (permission_exists('gswave_view')) {
  27. //access granted
  28. }
  29. else {
  30. echo "access denied";
  31. exit;
  32. }
  33. //add multi-lingual support
  34. $language = new text;
  35. $text = $language->get();
  36. //verify the id is as uuid then set as a variable
  37. if (is_uuid($_GET['id'])) {
  38. $extension_uuid = $_GET['id'];
  39. }
  40. //get the extension(s)
  41. if (permission_exists('extension_edit')) {
  42. //admin user
  43. $sql = "select * from v_extensions ";
  44. $sql .= "where domain_uuid = :domain_uuid ";
  45. $sql .= "and enabled = 'true' ";
  46. $sql .= "order by extension asc ";
  47. }
  48. else {
  49. //normal user
  50. $sql = "select e.* ";
  51. $sql .= "from v_extensions as e, ";
  52. $sql .= "v_extension_users as eu ";
  53. $sql .= "where e.extension_uuid = eu.extension_uuid ";
  54. $sql .= "and eu.user_uuid = :user_uuid ";
  55. $sql .= "and e.domain_uuid = :domain_uuid ";
  56. $sql .= "and e.enabled = 'true' ";
  57. $sql .= "order by e.extension asc ";
  58. $parameters['user_uuid'] = $_SESSION['user']['user_uuid'];
  59. }
  60. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  61. $database = new database;
  62. $extensions = $database->select($sql, $parameters, 'all');
  63. unset($sql, $parameters);
  64. if (is_uuid($extension_uuid) && is_array($extensions) && @sizeof($extensions) != 0) {
  65. //loop through get selected extension
  66. if (is_array($extensions) && @sizeof($extensions) != 0) {
  67. foreach ($extensions as $extension) {
  68. if ($extension['extension_uuid'] == $extension_uuid) {
  69. $field = $extension;
  70. break;
  71. }
  72. }
  73. }
  74. //get the username
  75. $username = $field['extension'];
  76. if (isset($field['number_alias']) && strlen($field['number_alias']) > 0) {
  77. $username = $field['number_alias'];
  78. }
  79. //build the xml
  80. $xml = "<?xml version='1.0' encoding='utf-8'?>";
  81. $xml .= "<AccountConfig version='1'>";
  82. $xml .= "<Account>";
  83. $xml .= "<RegisterServer>".$_SESSION['domain_name']."</RegisterServer>";
  84. //$xml .= "<OutboundServer>".$_SESSION['domain_name']."</OutboundServer>";
  85. //$xml .= "<SecOutboundServer>".$_SESSION['domain_name']."</SecOutboundServer>";
  86. $xml .= "<OutboundServer>".$_SESSION['domain_name'].":".$_SESSION['provision']['line_sip_port']['numeric']."</OutboundServer>";
  87. $xml .= "<SecOutboundServer>".$_SESSION['domain_name'].":".$_SESSION['provision']['line_sip_port']['numeric']."</SecOutboundServer>";
  88. $xml .= "<UserID>".$username."</UserID>";
  89. $xml .= "<AuthID>".$username."</AuthID>";
  90. $xml .= "<AuthPass>".$field['password']."</AuthPass>";
  91. $xml .= "<AccountName>".$username."</AccountName>";
  92. $xml .= "<DisplayName>".$username."</DisplayName>";
  93. $xml .= "<Dialplan>{x+|*x+|*++}</Dialplan>";
  94. $xml .= "<RandomPort>0</RandomPort>";
  95. $xml .= "<Voicemail>*97</Voicemail>";
  96. $xml .= "</Account>";
  97. $xml .= "</AccountConfig>";
  98. $ldapxml = "<?xml version='1.0' encoding='utf-8'?>";
  99. $ldapxml .= "<LdapConfig version='1'>";
  100. $ldapxml .= "<Server>".$_SESSION["ldap"]["qr_server"]["text"])."</Server>";
  101. $ldapxml .= "<Port>".$_SESSION["ldap"]["qr_port"]["text"]."</Port>";
  102. $ldapxml .= "<Path>".$_SESSION["ldap"]["qr_path"]["text"]."</Port>";
  103. $ldapxml .= "<Name>".$_SESSION["ldap"]["qr_username"]["text"])."</Name>";
  104. $ldapxml .= "<Secret>".$_SESSION["ldap"]["qr_password"]["text"]."</Secret>";
  105. $ldapxml .= "<FilterNum>".$_SESSION["ldap"]["qr_filternum"]["text"]."</FilterNum>";
  106. $ldapxml .= "<FilterName>".$_SESSION["ldap"]["qr_filtername"]["text"]."</FilterName>";
  107. $ldapxml .= "<Version>".$_SESSION["ldap"]["qr_ldap_version"]["numeric"]."</Version>";
  108. $ldapxml .= "<NamePro>".$_SESSION["ldap"]["qr_name_attribute"]["text"]."</NamePro>";
  109. $ldapxml .= "<NumPro>".$_SESSION["ldap"]["qr_num_attribute"]["text"]."</NumPro>";
  110. $ldapxml .= "<DisplayName>".$_SESSION["ldap"]["qr_display_name"]["text"]."</DisplayName>";
  111. $ldapxml .= "</LdapConfig>"
  112. // Use Default settings to set these
  113. }
  114. //yea i will have to go and recycle this aswell to make it generate the ldap code aswell
  115. //debian
  116. //apt install qrencode
  117. //include the header
  118. $document['title'] = $text['title-gswave'];
  119. require_once "resources/header.php";
  120. //show the content
  121. echo "<form name='frm' id='frm' method='get'>\n";
  122. echo "<div class='action_bar' id='action_bar'>\n";
  123. echo " <div class='heading'><b>".$text['title-gswave']."</b></div>\n";
  124. echo " <div class='actions'>\n";
  125. echo " <a href='https://play.google.com/store/apps/details?id=com.grandstream.wave' target='_blank'><img src='/app/gswave/resources/images/google_play.png' style='width: auto; height: 30px;' /></a>";
  126. echo " <a href='https://itunes.apple.com/us/app/grandstream-wave/id1029274043?ls=1&mt=8' target='_blank'><img src='/app/gswave/resources/images/apple_app_store.png' style='width: auto; height: 30px;' /></a>";
  127. //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']);
  128. echo " </div>\n";
  129. echo " <div style='clear: both;'></div>\n";
  130. echo "</div>\n";
  131. echo $text['title_description-gswave']."\n";
  132. echo "<br /><br />\n";
  133. echo "<div style='text-align: center; white-space: nowrap; margin: 10px 0 40px 0;'>";
  134. echo $text['label-extension']."<br />\n";
  135. echo "<select name='id' class='formfld' onchange='this.form.submit();'>\n";
  136. echo " <option value='' >".$text['label-select']."...</option>\n";
  137. if (is_array($extensions) && @sizeof($extensions) != 0) {
  138. foreach ($extensions as $row) {
  139. $selected = $row['extension_uuid'] == $extension_uuid ? "selected='selected'" : null;
  140. echo " <option value='".escape($row['extension_uuid'])."' ".$selected.">".escape($row['extension'])." ".escape($row['number_alias'])." ".escape($row['description'])."</option>\n";
  141. }
  142. }
  143. echo "</select>\n";
  144. echo "</form>\n";
  145. echo "<br>\n";
  146. //stream the file
  147. if (is_uuid($extension_uuid)) {
  148. $xml = html_entity_decode( $xml, ENT_QUOTES, 'UTF-8' );
  149. require_once 'resources/qr_code/QRErrorCorrectLevel.php';
  150. require_once 'resources/qr_code/QRCode.php';
  151. require_once 'resources/qr_code/QRCodeImage.php';
  152. try {
  153. $code = new QRCode (- 1, QRErrorCorrectLevel::H);
  154. $code->addData($xml);
  155. $code->make();
  156. $img = new QRCodeImage ($code, $width=420, $height=420, $quality=50);
  157. $img->draw();
  158. $image = $img->getImage();
  159. $img->finish();
  160. }
  161. catch (Exception $error) {
  162. echo $error;
  163. }
  164. }
  165. //html image
  166. if (is_uuid($extension_uuid)) {
  167. echo "<img src=\"data:image/jpeg;base64,".base64_encode($image)."\" style='margin-top: 30px; padding: 5px; background: white; max-width: 100%;'>\n";
  168. }
  169. echo "</div>\n";
  170. //add the footer
  171. require_once "resources/footer.php";
  172. ?>