2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 01/21/2013 *
4 * =================== Last change: 01/21/2013 *
6 * -------------------------------------------------------------------- *
7 * File : blacklist_functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Functions for ext- *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Funktionen fuer ext- *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2012 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
43 // Inserts a given email (pattern) in blacklist if not found
44 function insertEmailInBlacklist ($email, $id) {
45 // Is this feature turned on and is the URL not there?
46 if (!isEmailBlacklistEnabled()) {
47 // Not enabled, then please don't call this function
48 reportBug(__FUNCTION__, __LINE__, 'URL blacklisting is disabled, email=' . $email . ',id=' . $id);
49 } elseif (!isEmailBlacklisted($email)) {
50 // Did not find a record so we can add it... :)
51 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_blacklist` (`data`, `pool_id`, `type`) VALUES ('%s', %s, 'EMAIL')",
55 ), __FUNCTION__, __LINE__);
59 // Checks whether given email is blacklisted
60 function isEmailBlacklisted ($email) {
61 // Mark it as not listed by default
64 // Is black-listing enbaled?
65 if (!isEmailBlacklistEnabled()) {
66 // No, then all emails are not in this list
68 } elseif (!isset($GLOBALS['blacklist_data']['email'][$email])) {
69 // Check black-list for given email
70 $result = SQL_QUERY_ESC("SELECT UNIX_TIMESTAMP(`added`) AS `added` FROM `{?_MYSQL_PREFIX?}_blacklist` WHERE '%s' REGEXP `data` AND `type`='EMAIL' LIMIT 1",
71 array($email), __FUNCTION__, __LINE__);
74 if (SQL_NUMROWS($result) == 1) {
75 // Jupp, we got one listed
76 $GLOBALS['blacklist_data']['email'][$email] = SQL_FETCHARRAY($result);
83 SQL_FREERESULT($result);
85 // Is found in cache -> black-listed
93 // Inserts a given URL in blacklist if not found
94 function insertUrlInBlacklist ($url, $id) {
95 // Is this feature turned on and is the URL not there?
96 if (!isUrlBlacklistEnabled()) {
97 // Not enabled, then please don't call this function
98 reportBug(__FUNCTION__, __LINE__, 'URL blacklisting is disabled, url=' . $url . ',id=' . $id);
99 } elseif (!isUrlBlacklisted($url)) {
100 // Did not find a record so we can add it... :)
101 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_blacklist` (`data`, `pool_id`, `type`) VALUES ('%s', %s, 'URL')",
105 ), __FUNCTION__, __LINE__);
109 // Checks whether given URL is blacklisted
110 function isUrlBlacklisted ($url) {
111 // Mark it as not listed by default
114 // Is black-listing enbaled?
115 if (!isUrlBlacklistEnabled()) {
116 // No, then all URLs are not in this list
118 } elseif (!isset($GLOBALS['blacklist_data']['url'][$url])) {
119 // Check black-list for given URL
120 $result = SQL_QUERY_ESC("SELECT UNIX_TIMESTAMP(`added`) AS `added`, `pool_id` FROM `{?_MYSQL_PREFIX?}_blacklist` WHERE `data`='%s' AND `type`='URL' LIMIT 1",
121 array($url), __FUNCTION__, __LINE__);
123 // Is there an entry?
124 if (SQL_NUMROWS($result) == 1) {
125 // Jupp, we got one listed
126 $GLOBALS['blacklist_data']['url'][$url] = SQL_FETCHARRAY($result);
133 SQL_FREERESULT($result);
135 // Is found in cache -> black-listed
143 // ----------------------------------------------------------------------------
144 // Configuration wrapper functions
145 // ----------------------------------------------------------------------------
147 // Wrapper to check if url_blacklist is enabled
148 function isUrlBlacklistEnabled () {
150 if (!isset($GLOBALS[__FUNCTION__])) {
152 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
156 return $GLOBALS[__FUNCTION__];
159 // Wrapper to check if email_blacklist is enabled
160 function isEmailBlacklistEnabled () {
162 if (!isset($GLOBALS[__FUNCTION__])) {
164 $GLOBALS[__FUNCTION__] = (getConfig('email_blacklist') == 'Y');
168 return $GLOBALS[__FUNCTION__];