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 - 2016 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 // Checks whether given email is blacklisted
44 function isEmailBlacklisted ($email) {
45 // Call inner function
46 return isGenericBlacklisted('email', $email);
49 // Checks whether given IP is blacklisted
50 function isIpBlacklisted ($ip) {
51 // Call inner function
52 return isGenericBlacklisted('ip', $ip);
55 // Checks whether given URL is blacklisted
56 function isUrlBlacklisted ($url) {
57 // Call inner function
58 return isGenericBlacklisted('url', $email);
61 // Checks whether given data is blacklisted
62 function isGenericBlacklisted ($type, $data) {
63 // Mark it as not listed by default
66 // Is black-listing enbaled?
67 if (!isGenericBlacklistEnabled($type)) {
68 // No, then all emails are not in this list
70 } elseif (!isset($GLOBALS['blacklist_data'][$type][$data])) {
71 // Check black-list for given email
72 $result = sqlQueryEscaped("SELECT
78 UNIX_TIMESTAMP(`added`) AS `added`
80 `{?_MYSQL_PREFIX?}_blacklist`
82 '%s' REGEXP `data` AND
88 ), __FUNCTION__, __LINE__);
91 if (sqlNumRows($result) == 1) {
92 // Jupp, we got one listed
93 $GLOBALS['blacklist_data'][$type][$data] = sqlFetchArray($result);
100 sqlFreeResult($result);
102 // Is found in cache -> black-listed
110 // Inserts a given email (pattern) in blacklist if not found
111 function insertEmailInBlacklist ($email, $provider = 'BLACKLIST') {
112 // Call inner function
113 return insertGenericInBlacklist ('email', $email, NULL, $provider);
116 // Inserts a given IP (pattern) in blacklist if not found
117 function insertIpInBlacklist ($ip, $provider = 'BLACKLIST') {
118 // Call inner function
119 return insertGenericInBlacklist ('ip', $ip, NULL, $provider);
122 // Inserts a given URL (pattern) in blacklist if not found
123 function insertUrlInBlacklist ($url, $poolId, $provider = 'BLACKLIST') {
124 // Call inner function
125 return insertGenericInBlacklist ('url', $url, $poolId, $provider);
128 // Inserts a given URL in blacklist if not found
129 function insertGenericInBlacklist ($type, $data, $poolId = NULL, $provider = 'BLACKLIST') {
130 // Is this feature turned on and is the URL not there?
131 if (!isGenericBlacklistEnabled($type)) {
132 // Not enabled, then please don't call this function
133 reportBug(__FUNCTION__, __LINE__, 'Blacklisting of type ' . $type . ' is disabled, data=' . $data . ',poolId=' . convertZeroToNull($poolId));
134 } elseif (!isUrlBlacklisted($data)) {
135 // Did not find a record so we can add it... :)
136 sqlQueryEscaped("INSERT INTO
137 `{?_MYSQL_PREFIX?}_blacklist`
151 convertZeroToNull($poolId),
154 ), __FUNCTION__, __LINE__);
157 // Return insert id for debugging/reporting pursposes
158 return getSqlInsertId();
161 // ----------------------------------------------------------------------------
162 // Configuration wrapper functions
163 // ----------------------------------------------------------------------------
166 function isGenericBlacklistEnabled ($type) {
168 if (!isset($GLOBALS[__FUNCTION__])) {
170 $GLOBALS[__FUNCTION__] = (getConfig($type . '_blacklist') == 'Y');
174 return $GLOBALS[__FUNCTION__];
177 // Getter for url_blacklist
178 function getUrlBlacklist () {
180 if (!isset($GLOBALS[__FUNCTION__])) {
182 $GLOBALS[__FUNCTION__] = getConfig('url_blacklist');
186 return $GLOBALS[__FUNCTION__];
189 // Wrapper to check if url_blacklist is enabled
190 function isUrlBlacklistEnabled () {
192 if (!isset($GLOBALS[__FUNCTION__])) {
194 $GLOBALS[__FUNCTION__] = (getUrlBlacklist() == 'Y');
198 return $GLOBALS[__FUNCTION__];
201 // Getter for email_blacklist
202 function getEmailBlacklist () {
204 if (!isset($GLOBALS[__FUNCTION__])) {
206 $GLOBALS[__FUNCTION__] = getConfig('email_blacklist');
210 return $GLOBALS[__FUNCTION__];
213 // Wrapper to check if email_blacklist is enabled
214 function isEmailBlacklistEnabled () {
216 if (!isset($GLOBALS[__FUNCTION__])) {
218 $GLOBALS[__FUNCTION__] = (getEmailBlacklist() == 'Y');
222 return $GLOBALS[__FUNCTION__];
225 // Getter for ip_blacklist
226 function getIpBlacklist () {
228 if (!isset($GLOBALS[__FUNCTION__])) {
230 $GLOBALS[__FUNCTION__] = getConfig('ip_blacklist');
234 return $GLOBALS[__FUNCTION__];
237 // Wrapper to check if ip_blacklist is enabled
238 function isIpBlacklistEnabled () {
240 if (!isset($GLOBALS[__FUNCTION__])) {
242 $GLOBALS[__FUNCTION__] = (getIpBlacklist() == 'Y');
246 return $GLOBALS[__FUNCTION__];