]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/blacklist_functions.php
Rewrote reset and some extensions:
[mailer.git] / inc / libs / blacklist_functions.php
index 92e0b2b4d134d0bf1d2d35128943d1de1edfff10..05803c8c2793cb4aef11661d9e3bac2f14b96c44 100644 (file)
@@ -40,40 +40,39 @@ if (!defined('__SECURITY')) {
        die();
 } // END - if
 
-// Inserts a given email (pattern) in blacklist if not found
-function insertEmailInBlacklist ($email, $id) {
-       // Is this feature turned on and is the URL not there?
-       if (!isEmailBlacklistEnabled()) {
-               // Not enabled, then please don't call this function
-               reportBug(__FUNCTION__, __LINE__, 'URL blacklisting is disabled, email=' . $email . ',id=' . $id);
-       } elseif (!isEmailBlacklisted($email)) {
-               // Did not find a record so we can add it... :)
-               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_blacklist` (`data`, `pool_id`, `type`) VALUES ('%s', %s, 'EMAIL')",
-                       array(
-                               $email,
-                               $id
-                       ), __FUNCTION__, __LINE__);
-       } // END - if
-}
-
-// Checks whether given email is blacklisted
-function isEmailBlacklisted ($email) {
+// Checks whether given data is blacklisted
+function isGenericBlacklisted ($type, $data) {
        // Mark it as not listed by default
        $listed = FALSE;
 
        // Is black-listing enbaled?
-       if (!isEmailBlacklistEnabled()) {
+       if (!isGenericBlacklistEnabled($type)) {
                // No, then all emails are not in this list
                return FALSE;
-       } elseif (!isset($GLOBALS['blacklist_data']['email'][$email])) {
+       } elseif (!isset($GLOBALS['blacklist_data'][$type][$data])) {
                // Check black-list for given email
-               $result = SQL_QUERY_ESC("SELECT UNIX_TIMESTAMP(`added`) AS `added` FROM `{?_MYSQL_PREFIX?}_blacklist` WHERE '%s' REGEXP `data` AND `type`='EMAIL' LIMIT 1",
-                       array($email), __FUNCTION__, __LINE__);
+               $result = SQL_QUERY_ESC("SELECT
+       `id`,
+       `data`,
+       `pool_id`,
+       `provider`,
+       `type`,
+       UNIX_TIMESTAMP(`added`) AS `added`
+FROM
+       `{?_MYSQL_PREFIX?}_blacklist`
+WHERE
+       '%s' REGEXP `data` AND
+       `type`='%s'
+LIMIT 1",
+                       array(
+                               $data,
+                               strtoupper($type)
+                       ), __FUNCTION__, __LINE__);
 
                // Is there an entry?
                if (SQL_NUMROWS($result) == 1) {
                        // Jupp, we got one listed
-                       $GLOBALS['blacklist_data']['email'][$email] = SQL_FETCHARRAY($result);
+                       $GLOBALS['blacklist_data'][$type][$data] = SQL_FETCHARRAY($result);
 
                        // Mark it as listed
                        $listed = TRUE;
@@ -90,60 +89,76 @@ function isEmailBlacklisted ($email) {
        return $listed;
 }
 
+// Inserts a given email (pattern) in blacklist if not found
+function insertEmailInBlacklist ($email, $provider = 'BLACKLIST') {
+       // Call inner function
+       insertGenericInBlacklist ('email', $email, NULL, $provider);
+}
+
+// Inserts a given URL in blacklist if not found
+function insertUrlInBlacklist ($url, $poolId, $provider = 'BLACKLIST') {
+       // Call inner function
+       insertGenericInBlacklist ('url', $url, $poolId, $provider);
+}
+
 // Inserts a given URL in blacklist if not found
-function insertUrlInBlacklist ($url, $id) {
+function insertGenericInBlacklist ($type, $data, $poolId = NULL, $provider = 'BLACKLIST') {
        // Is this feature turned on and is the URL not there?
-       if (!isUrlBlacklistEnabled()) {
+       if (!isGenericBlacklistEnabled($type)) {
                // Not enabled, then please don't call this function
-               reportBug(__FUNCTION__, __LINE__, 'URL blacklisting is disabled, url=' . $url . ',id=' . $id);
-       } elseif (!isUrlBlacklisted($url)) {
+               reportBug(__FUNCTION__, __LINE__, 'Blacklisting of type ' . $type . ' is disabled, data=' . $data . ',poolId=' . convertZeroToNull($poolId));
+       } elseif (!isUrlBlacklisted($data)) {
                // Did not find a record so we can add it... :)
-               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_blacklist` (`data`, `pool_id`, `type`) VALUES ('%s', %s, 'URL')",
-                       array(
-                               $url,
-                               $id
-                       ), __FUNCTION__, __LINE__);
+               SQL_QUERY_ESC("INSERT INTO
+       `{?_MYSQL_PREFIX?}_blacklist`
+(
+       `data`,
+       `pool_id`,
+       `provider`,
+       `type`
+) VALUES (
+       '%s',
+       %s,
+       '%s',
+       '%s'
+)",
+               array(
+                       $data,
+                       convertZeroToNull($poolId),
+                       $provider,
+                       strtoupper($type)
+               ), __FUNCTION__, __LINE__);
        } // END - if
 }
 
+// Checks whether given email is blacklisted
+function isEmailBlacklisted ($email) {
+       // Call inner function
+       return isGenericBlacklisted('email', $email);
+}
+
 // Checks whether given URL is blacklisted
 function isUrlBlacklisted ($url) {
-       // Mark it as not listed by default
-       $listed = FALSE;
-
-       // Is black-listing enbaled?
-       if (!isUrlBlacklistEnabled()) {
-               // No, then all URLs are not in this list
-               return FALSE;
-       } elseif (!isset($GLOBALS['blacklist_data']['url'][$url])) {
-               // Check black-list for given URL
-               $result = SQL_QUERY_ESC("SELECT UNIX_TIMESTAMP(`added`) AS `added`, `pool_id` FROM `{?_MYSQL_PREFIX?}_blacklist` WHERE `data`='%s' AND `type`='URL' LIMIT 1",
-                       array($url), __FUNCTION__, __LINE__);
-
-               // Is there an entry?
-               if (SQL_NUMROWS($result) == 1) {
-                       // Jupp, we got one listed
-                       $GLOBALS['blacklist_data']['url'][$url] = SQL_FETCHARRAY($result);
-
-                       // Mark it as listed
-                       $listed = TRUE;
-               } // END - if
-
-               // Free result
-               SQL_FREERESULT($result);
-       } else {
-               // Is found in cache -> black-listed
-               $listed = TRUE;
-       }
-
-       // Return result
-       return $listed;
+       // Call inner function
+       return isGenericBlacklisted('url', $email);
 }
 
 // ----------------------------------------------------------------------------
 //                      Configuration wrapper functions
 // ----------------------------------------------------------------------------
 
+// Generic wrapper
+function isGenericBlacklistEnabled ($type) {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = (getConfig($type . '_blacklist') == 'Y');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
 // Wrapper to check if url_blacklist is enabled
 function isUrlBlacklistEnabled () {
        // Is there cache?