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.

255 lines
9.1 KiB

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-2021
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <markjcrane@fusionpbx.com>
  20. James Rose <james.o.rose@gmail.com>
  21. */
  22. //includes
  23. include "root.php";
  24. require_once "resources/require.php";
  25. require_once "resources/check_auth.php";
  26. require_once "resources/functions/object_to_array.php";
  27. require_once "resources/functions/parse_message.php";
  28. //check permissions
  29. if (permission_exists('fax_inbox_view')) {
  30. //access granted
  31. }
  32. else {
  33. echo "access denied";
  34. exit;
  35. }
  36. //add multi-lingual support
  37. $language = new text;
  38. $text = $language->get();
  39. //get submitted id
  40. $fax_uuid = $_GET["id"];
  41. //get fax server uuid, set connection parameters
  42. if (is_uuid($fax_uuid)) {
  43. if (permission_exists('fax_extension_view')) {
  44. //show all fax extensions
  45. $sql = "select * from v_fax ";
  46. $sql .= "where domain_uuid = :domain_uuid ";
  47. $sql .= "and fax_uuid = :fax_uuid ";
  48. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  49. $parameters['fax_uuid'] = $fax_uuid;
  50. }
  51. else {
  52. //show only assigned fax extensions
  53. $sql = "select * from v_fax as f, v_fax_users as u ";
  54. $sql .= "where f.fax_uuid = u.fax_uuid ";
  55. $sql .= "and f.domain_uuid = :domain_uuid ";
  56. $sql .= "and f.fax_uuid = :fax_uuid ";
  57. $sql .= "and u.user_uuid = :user_uuid ";
  58. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  59. $parameters['fax_uuid'] = $fax_uuid;
  60. $parameters['user_uuid'] = $_SESSION['user_uuid'];
  61. }
  62. $database = new database;
  63. $row = $database->select($sql, $parameters, 'row');
  64. if (is_array($row) && @sizeof($row) != 0) {
  65. $fax_name = $row["fax_name"];
  66. $fax_extension = $row["fax_extension"];
  67. $fax_email_connection_type = $row["fax_email_connection_type"];
  68. $fax_email_connection_host = $row["fax_email_connection_host"];
  69. $fax_email_connection_port = $row["fax_email_connection_port"];
  70. $fax_email_connection_security = $row["fax_email_connection_security"];
  71. $fax_email_connection_validate = $row["fax_email_connection_validate"];
  72. $fax_email_connection_username = $row["fax_email_connection_username"];
  73. $fax_email_connection_password = $row["fax_email_connection_password"];
  74. $fax_email_connection_mailbox = $row["fax_email_connection_mailbox"];
  75. $fax_email_inbound_subject_tag = $row["fax_email_inbound_subject_tag"];
  76. }
  77. else {
  78. if (!permission_exists('fax_extension_view')) {
  79. echo "access denied";
  80. exit;
  81. }
  82. }
  83. unset($sql, $parameters, $row);
  84. // make connection
  85. $fax_email_connection = "{".$fax_email_connection_host.":".$fax_email_connection_port."/".$fax_email_connection_type;
  86. $fax_email_connection .= ($fax_email_connection_security != '') ? "/".$fax_email_connection_security : "/notls";
  87. $fax_email_connection .= "/".(($fax_email_connection_validate == 'false') ? "no" : null)."validate-cert";
  88. $fax_email_connection .= "}".$fax_email_connection_mailbox;
  89. if (!$connection = imap_open($fax_email_connection, $fax_email_connection_username, $fax_email_connection_password)) {
  90. message::add($text['message-cannot_connect']."(".imap_last_error().")", 'neative');
  91. header("Location: fax.php");
  92. exit;
  93. }
  94. }
  95. else {
  96. header("Location: fax.php");
  97. exit;
  98. }
  99. //message action
  100. if ($_GET['email_id'] != '') {
  101. $email_id = $_GET['email_id'];
  102. //download attachment
  103. if (isset($_GET['download'])) {
  104. $message = parse_message($connection, $email_id, FT_UID);
  105. $attachment = $message['attachments'][0];
  106. if ($attachment) {
  107. $file_type = pathinfo($attachment['name'], PATHINFO_EXTENSION);
  108. switch ($file_type) {
  109. case "pdf" : header("Content-Type: application/pdf"); break;
  110. case "tif" : header("Contet-Type: image/tiff"); break;
  111. }
  112. header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  113. header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // date in the past
  114. header("Content-Length: ".$attachment['size']);
  115. $browser = $_SERVER["HTTP_USER_AGENT"];
  116. if (preg_match("/MSIE 5.5/", $browser) || preg_match("/MSIE 6.0/", $browser)) {
  117. header("Content-Disposition: filename=\"".$attachment['name']."\"");
  118. }
  119. else {
  120. header("Content-Disposition: attachment; filename=\"".$attachment['name']."\"");
  121. }
  122. header("Content-Transfer-Encoding: binary");
  123. echo $attachment['data'];
  124. exit;
  125. }
  126. else{
  127. //redirect user
  128. message::add($text['message-download_failed'], 'negative');
  129. header("Location: ?id=".$fax_uuid);
  130. exit;
  131. }
  132. }
  133. //delete email
  134. if (isset($_GET['delete']) && permission_exists('fax_inbox_delete')) {
  135. $message = parse_message($connection, $email_id, FT_UID);
  136. $attachment = $message['attachments'][0];
  137. if (imap_delete($connection, $email_id, FT_UID)) {
  138. if (imap_expunge($connection)) {
  139. //clean up local inbox copy
  140. $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name'];
  141. @unlink($fax_dir.'/'.$fax_extension.'/inbox/'.$attachment['name']);
  142. //redirect user
  143. message::add($text['message-delete']);
  144. header("Location: ?id=".$fax_uuid);
  145. exit;
  146. }
  147. }
  148. else {
  149. //redirect user
  150. message::add($text['message-delete_failed'], 'negative');
  151. header("Location: ?id=".$fax_uuid);
  152. exit;
  153. }
  154. }
  155. else {
  156. //redirect user
  157. message::add($text['message-delete_failed'], 'negative');
  158. header("Location: ?id=".$fax_uuid);
  159. exit;
  160. }
  161. }
  162. //get emails
  163. $emails = imap_search($connection, "SUBJECT \"".$fax_email_inbound_subject_tag."\"", SE_UID);
  164. //show the header
  165. require_once "resources/header.php";
  166. //set the row styles
  167. $row_style["0"] = "row_style0";
  168. $row_style["1"] = "row_style1";
  169. //show the inbox
  170. $c = 0;
  171. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  172. echo " <tr>\n";
  173. echo " <td align='left' valign='top'>\n";
  174. echo " <b>".$text['header-inbox'].": <span style='color: #000;'>".$fax_name." (".$fax_extension.")</span></b>\n";
  175. echo " </td>\n";
  176. echo " <td width='70%' align='right' valign='top'>\n";
  177. echo " <input type='button' class='btn' alt='".$text['button-back']."' onclick=\"window.location='fax.php';\" value='".$text['button-back']."'>\n";
  178. echo " <input type='button' class='btn' alt='".$text['button-refresh']."' onclick=\"document.location.reload();\" value='".$text['button-refresh']."'>\n";
  179. echo " </td>\n";
  180. echo " </tr>\n";
  181. echo "</table>\n";
  182. echo "<br><br>\n";
  183. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  184. echo " <tr>\n";
  185. echo " <th>".$text['label-fax_caller_id_name']."</th>\n";
  186. echo " <th>".$text['label-fax_caller_id_number']."</th>\n";
  187. echo " <th>".$text['table-file']."</th>\n";
  188. echo " <th>".$text['label-email_size']."</th>\n";
  189. echo " <th>".$text['label-email_received']."</th>\n";
  190. if (permission_exists('fax_inbox_delete')) {
  191. echo " <td style='width: 25px;' class='list_control_icons'>&nbsp;</td>\n";
  192. }
  193. echo " </tr>";
  194. if (is_array($emails) && @sizeof($emails) != 0) {
  195. rsort($emails); // most recent on top
  196. foreach ($emails as $email_id) {
  197. $metadata = object_to_array(imap_fetch_overview($connection, $email_id, FT_UID));
  198. $message = parse_message($connection, $email_id, FT_UID);
  199. $attachment = $message['attachments'][0];
  200. $file_name = $attachment['name'];
  201. $caller_id_name = substr($file_name, 0, strpos($file_name, '-'));
  202. $caller_id_number = (is_numeric($caller_id_name)) ? format_phone((int) $caller_id_name) : null;
  203. echo " <tr ".(($metadata[0]['seen'] == 0) ? "style='font-weight: bold;'" : null).">\n";
  204. echo " <td valign='top' class='".$row_style[$c]."'>".$caller_id_name."</td>\n";
  205. echo " <td valign='top' class='".$row_style[$c]."'>".$caller_id_number."</td>\n";
  206. echo " <td valign='top' class='".$row_style[$c]."'><a href='?id=".$fax_uuid."&email_id=".$email_id."&download'>".$file_name."</a></td>\n";
  207. echo " <td valign='top' class='".$row_style[$c]."'>".byte_convert($attachment['size'])."</td>\n";
  208. echo " <td valign='top' class='".$row_style[$c]."'>".$metadata[0]['date']."</td>\n";
  209. if (permission_exists('fax_inbox_delete')) {
  210. echo " <td style='width: 25px;' class='list_control_icons'><a href='?id=".$fax_uuid."&email_id=".$email_id."&delete' onclick=\"return confirm('".$text['confirm-delete']."')\">".$v_link_label_delete."</a></td>\n";
  211. }
  212. echo " </tr>\n";
  213. $c = ($c) ? 0 : 1;
  214. }
  215. }
  216. else {
  217. echo "<tr valign='top'>\n";
  218. echo " <td colspan='4' style='text-align: center;'><br><br>".$text['message-no_faxes_found']."<br><br></td>\n";
  219. echo "</tr>\n";
  220. }
  221. echo "</table>";
  222. echo "<br><br>";
  223. //close the connection
  224. imap_close($connection);
  225. //show the footer
  226. require_once "resources/footer.php";
  227. ?>