PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/banned_emails.php

https://gitlab.com/kingcody/Mods-for-HESK
PHP | 343 lines | 228 code | 53 blank | 62 comment | 30 complexity | 649a23ff19544a34bfd35d062faa1199 MD5 | raw file
  1. <?php
  2. /*******************************************************************************
  3. * Title: Help Desk Software HESK
  4. * Version: 2.6.7 from 18th April 2016
  5. * Author: Klemen Stirn
  6. * Website: http://www.hesk.com
  7. ********************************************************************************
  8. * COPYRIGHT AND TRADEMARK NOTICE
  9. * Copyright 2005-2015 Klemen Stirn. All Rights Reserved.
  10. * HESK is a registered trademark of Klemen Stirn.
  11. * The HESK may be used and modified free of charge by anyone
  12. * AS LONG AS COPYRIGHT NOTICES AND ALL THE COMMENTS REMAIN INTACT.
  13. * By using this code you agree to indemnify Klemen Stirn from any
  14. * liability that might arise from it's use.
  15. * Selling the code for this program, in part or full, without prior
  16. * written consent is expressly forbidden.
  17. * Using this code, in part or full, to create derivate work,
  18. * new scripts or products is expressly forbidden. Obtain permission
  19. * before redistributing this software over the Internet or in
  20. * any other medium. In all cases copyright and header must remain intact.
  21. * This Copyright is in full effect in any country that has International
  22. * Trade Agreements with the United States of America or
  23. * with the European Union.
  24. * Removing any of the copyright notices without purchasing a license
  25. * is expressly forbidden. To remove HESK copyright notice you must purchase
  26. * a license for this script. For more information on how to obtain
  27. * a license please visit the page below:
  28. * https://www.hesk.com/buy.php
  29. *******************************************************************************/
  30. define('IN_SCRIPT', 1);
  31. define('HESK_PATH', '../');
  32. define('PAGE_TITLE', 'ADMIN_TOOLS');
  33. /* Get all the required files and functions */
  34. require(HESK_PATH . 'hesk_settings.inc.php');
  35. require(HESK_PATH . 'inc/common.inc.php');
  36. require(HESK_PATH . 'inc/admin_functions.inc.php');
  37. hesk_load_database_functions();
  38. hesk_session_start();
  39. hesk_dbConnect();
  40. hesk_isLoggedIn();
  41. /* Check permissions for this feature */
  42. hesk_checkPermission('can_ban_emails');
  43. $can_unban = hesk_checkPermission('can_unban_emails', 0);
  44. // Define required constants
  45. define('LOAD_TABS', 1);
  46. // What should we do?
  47. if ($action = hesk_REQUEST('a')) {
  48. if (defined('HESK_DEMO')) {
  49. hesk_process_messages($hesklang['ddemo'], 'banned_emails.php', 'NOTICE');
  50. } elseif ($action == 'ban') {
  51. ban_email();
  52. } elseif ($action == 'unban' && $can_unban) {
  53. unban_email();
  54. }
  55. }
  56. /* Print header */
  57. require_once(HESK_PATH . 'inc/headerAdmin.inc.php');
  58. /* Print main manage users page */
  59. require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
  60. ?>
  61. <div class="row pad-down-20">
  62. <ul class="nav nav-tabs" role="tablist">
  63. <li role="presentation" class="active">
  64. <a href="#"><?php echo $hesklang['banemail']; ?> <i class="fa fa-question-circle settingsquestionmark"
  65. onclick="javascript:alert('<?php echo hesk_makeJsString($hesklang['banemail_intro']); ?>')"></i></a>
  66. </li>
  67. <?php
  68. // Show a link to banned_ips.php if user has permission to do so
  69. if (hesk_checkPermission('can_ban_ips', 0)) {
  70. echo '
  71. <li role="presentation">
  72. <a title="' . $hesklang['banip'] . '" href="banned_ips.php">' . $hesklang['banip'] . '</a>
  73. </li>';
  74. }
  75. // Show a link to status_message.php if user has permission to do so
  76. if (hesk_checkPermission('can_service_msg', 0)) {
  77. echo '
  78. <li role="presentation">
  79. <a title="' . $hesklang['sm_title'] . '" href="service_messages.php">' . $hesklang['sm_title'] . '</a>
  80. </li>';
  81. }
  82. // Show a link to email tpl management if user has permission to do so
  83. if (hesk_checkPermission('can_man_email_tpl', 0)) {
  84. echo '
  85. <li role="presentation">
  86. <a title="' . $hesklang['email_templates'] . '" href="manage_email_templates.php">' . $hesklang['email_templates'] . '</a>
  87. </li>
  88. ';
  89. }
  90. if (hesk_checkPermission('can_man_ticket_statuses', 0)) {
  91. echo '
  92. <li role="presentation">
  93. <a title="' . $hesklang['statuses'] . '" href="manage_statuses.php">' . $hesklang['statuses'] . '</a>
  94. </li>
  95. ';
  96. }
  97. ?>
  98. </ul>
  99. <div class="tab-content summaryList tabPadding">
  100. <script language="javascript" type="text/javascript"><!--
  101. function confirm_delete() {
  102. if (confirm('<?php echo hesk_makeJsString($hesklang['delban_confirm']); ?>')) {
  103. return true;
  104. }
  105. else {
  106. return false;
  107. }
  108. }
  109. //-->
  110. </script>
  111. <div class="row">
  112. <div class="col-md-8">
  113. <br><br>
  114. <?php
  115. /* This will handle error, success and notice messages */
  116. hesk_handle_messages();
  117. ?>
  118. <form action="banned_emails.php" method="post" name="form1" role="form" class="form-horizontal" data-toggle="validator">
  119. <div class="form-group">
  120. <label for="text" class="col-sm-3 control-label"><?php echo $hesklang['bananemail']; ?></label>
  121. <div class="col-sm-9">
  122. <input type="text" class="form-control" name="email" size="30" maxlength="255" data-error="<?php echo htmlspecialchars($hesklang['enterbanemail']); ?>"
  123. placeholder="<?php echo htmlspecialchars($hesklang['email']); ?>" required>
  124. <input type="hidden" name="token" value="<?php hesk_token_echo(); ?>"/>
  125. <input type="hidden" name="a" value="ban"/>
  126. <div class="help-block with-errors"></div>
  127. </div>
  128. </div>
  129. <div class="form-group">
  130. <div class="col-sm-9 col-sm-offset-3">
  131. <input type="submit" value="<?php echo $hesklang['savebanemail']; ?>"
  132. class="btn btn-default">
  133. </div>
  134. </div>
  135. </form>
  136. </div>
  137. <div class="col-md-4">
  138. <h6 class="bold"><?php echo $hesklang['banex']; ?></h6>
  139. <div class="footerWithBorder blankSpace"></div>
  140. <b>john@email.com</b><br/>
  141. <b>@domain.com</b>
  142. </div>
  143. </div>
  144. <div class="row">
  145. <?php
  146. // Get banned emails from database
  147. $res = hesk_dbQuery('SELECT * FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'banned_emails` ORDER BY `email` ASC');
  148. $num = hesk_dbNumRows($res);
  149. echo '<h4>' . $hesklang['eperm'] . '</h4>';
  150. if ($num < 1) {
  151. echo '<p>' . $hesklang['no_banemails'] . '</p>';
  152. } else {
  153. // List of staff
  154. if (!isset($admins)) {
  155. $admins = array();
  156. $res2 = hesk_dbQuery("SELECT `id`,`name` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users`");
  157. while ($row = hesk_dbFetchAssoc($res2)) {
  158. $admins[$row['id']] = $row['name'];
  159. }
  160. }
  161. ?>
  162. <table class="table table-hover">
  163. <thead>
  164. <tr>
  165. <th><?php echo $hesklang['email']; ?></th>
  166. <th><?php echo $hesklang['banby']; ?></th>
  167. <th><?php echo $hesklang['date']; ?></th>
  168. <?php
  169. if ($can_unban) {
  170. ?>
  171. <th><?php echo $hesklang['opt']; ?></th>
  172. <?php
  173. }
  174. ?>
  175. </tr>
  176. </thead>
  177. <tbody>
  178. <?php
  179. while ($ban = hesk_dbFetchAssoc($res)) {
  180. $color = '';
  181. if (isset($_SESSION['ban_email']['id']) && $ban['id'] == $_SESSION['ban_email']['id']) {
  182. $color = 'success';
  183. unset($_SESSION['ban_email']['id']);
  184. }
  185. echo '
  186. <tr>
  187. <td class="' . $color . ' text-left">' . $ban['email'] . '</td>
  188. <td class="' . $color . ' text-left">' . (isset($admins[$ban['banned_by']]) ? $admins[$ban['banned_by']] : $hesklang['e_udel']) . '</td>
  189. <td class="' . $color . ' text-left">' . $ban['dt'] . '</td>
  190. ';
  191. if ($can_unban) {
  192. echo '
  193. <td class="' . $color . ' text-left">
  194. <a href="banned_emails.php?a=unban&amp;id=' . $ban['id'] . '&amp;token=' . hesk_token_echo(0) . '" onclick="return confirm_delete();">
  195. <i class="fa fa-times red font-size-16p" data-toggle="tooltip" data-placement="top" data-original-title="' . $hesklang['delban'] . '"></i>
  196. </a>
  197. </td>
  198. ';
  199. }
  200. echo '</tr>';
  201. } // End while
  202. ?>
  203. </tbody>
  204. </table>
  205. <div align="center">
  206. <table border="0" cellspacing="1" cellpadding="3" class="white" width="100%">
  207. <?php
  208. ?>
  209. </table>
  210. </div>
  211. <?php
  212. }
  213. ?>
  214. </div>
  215. </div>
  216. </div>
  217. <?php
  218. require_once(HESK_PATH . 'inc/footer.inc.php');
  219. exit();
  220. /*** START FUNCTIONS ***/
  221. function ban_email()
  222. {
  223. global $hesk_settings, $hesklang;
  224. // A security check
  225. hesk_token_check();
  226. // Get the email
  227. $email = strtolower(hesk_input(hesk_REQUEST('email')));
  228. // Nothing entered?
  229. if (!strlen($email)) {
  230. hesk_process_messages($hesklang['enterbanemail'], 'banned_emails.php');
  231. }
  232. // Only allow one email to be entered
  233. $email = ($index = strpos($email, ',')) ? substr($email, 0, $index) : $email;
  234. $email = ($index = strpos($email, ';')) ? substr($email, 0, $index) : $email;
  235. // Validate email address
  236. $hesk_settings['multi_eml'] = 0;
  237. if (!hesk_validateEmail($email, '', 0) && !verify_email_domain($email)) {
  238. hesk_process_messages($hesklang['validbanemail'], 'banned_emails.php');
  239. }
  240. // Redirect either to banned emails or ticket page from now on
  241. $redirect_to = ($trackingID = hesk_cleanID()) ? 'admin_ticket.php?track=' . $trackingID . '&Refresh=' . mt_rand(10000, 99999) : 'banned_emails.php';
  242. // Prevent duplicate rows
  243. if ($_SESSION['ban_email']['id'] = hesk_isBannedEmail($email)) {
  244. hesk_process_messages(sprintf($hesklang['emailbanexists'], $email), $redirect_to, 'NOTICE');
  245. }
  246. // Insert the email address into database
  247. hesk_dbQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "banned_emails` (`email`,`banned_by`) VALUES ('" . hesk_dbEscape($email) . "','" . intval($_SESSION['id']) . "')");
  248. // Remember email that got banned
  249. $_SESSION['ban_email']['id'] = hesk_dbInsertID();
  250. // Show success
  251. hesk_process_messages(sprintf($hesklang['email_banned'], $email), $redirect_to, 'SUCCESS');
  252. } // End ban_email()
  253. function unban_email()
  254. {
  255. global $hesk_settings, $hesklang;
  256. // A security check
  257. hesk_token_check();
  258. // Delete from bans
  259. hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "banned_emails` WHERE `id`=" . intval(hesk_GET('id')) . " LIMIT 1");
  260. // Redirect either to banned emails or ticket page from now on
  261. $redirect_to = ($trackingID = hesk_cleanID()) ? 'admin_ticket.php?track=' . $trackingID . '&Refresh=' . mt_rand(10000, 99999) : 'banned_emails.php';
  262. // Show success
  263. hesk_process_messages($hesklang['email_unbanned'], $redirect_to, 'SUCCESS');
  264. } // End unban_email()
  265. function verify_email_domain($domain)
  266. {
  267. // Does it start with an @?
  268. $atIndex = strrpos($domain, "@");
  269. if ($atIndex !== 0) {
  270. return false;
  271. }
  272. // Get the domain and domain length
  273. $domain = substr($domain, 1);
  274. $domainLen = strlen($domain);
  275. // Check domain part length
  276. if ($domainLen < 1 || $domainLen > 254) {
  277. return false;
  278. }
  279. // Check domain part characters
  280. if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) {
  281. return false;
  282. }
  283. // Domain part mustn't have two consecutive dots
  284. if (strpos($domain, '..') !== false) {
  285. return false;
  286. }
  287. // All OK
  288. return true;
  289. } // END verify_email_domain()
  290. ?>