| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Message and Spam Filter Plugin - Filtering Functions |
| 5 | * |
| 6 | * @copyright 1999-2014 The SquirrelMail Project Team |
| 7 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 8 | * @version $Id$ |
| 9 | * @package plugins |
| 10 | * @subpackage filters |
| 11 | */ |
| 12 | |
| 13 | // TODO: This plugin has an issue that seems to corrupt folder cache for subfolders of INBOX |
| 14 | /** |
| 15 | * do not allow to call this file directly |
| 16 | */ |
| 17 | if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE__) { |
| 18 | header("Location: ../../src/login.php"); |
| 19 | die(); |
| 20 | } |
| 21 | |
| 22 | /** load globals */ |
| 23 | global $UseSeparateImapConnection, |
| 24 | $AllowSpamFilters, $SpamFilters_YourHop, $SpamFilters_ShowCommercial, |
| 25 | $SpamFilters_DNScache, $SpamFilters_BulkQuery, $SpamFilters_SharedCache, |
| 26 | $SpamFilters_CacheTTL; |
| 27 | |
| 28 | /** |
| 29 | * load required functions. Plugin depends on IMAP functions and they are not |
| 30 | * loaded in src/webmail.php |
| 31 | */ |
| 32 | include_once (SM_PATH . 'functions/imap.php'); |
| 33 | |
| 34 | /** load default config */ |
| 35 | if (file_exists(SM_PATH . 'plugins/filters/config_default.php')) { |
| 36 | include_once (SM_PATH . 'plugins/filters/config_default.php'); |
| 37 | } else { |
| 38 | // default config was removed. |
| 39 | $UseSeparateImapConnection = false; |
| 40 | $AllowSpamFilters = true; |
| 41 | $SpamFilters_YourHop = ' '; |
| 42 | $SpamFilters_ShowCommercial = false; |
| 43 | $SpamFilters_DNScache = array(); |
| 44 | $SpamFilters_BulkQuery = ''; |
| 45 | $SpamFilters_SharedCache = true; |
| 46 | $SpamFilters_CacheTTL = 7200; |
| 47 | } |
| 48 | |
| 49 | if (file_exists(SM_PATH . 'config/filters_config.php')) { |
| 50 | include_once (SM_PATH . 'config/filters_config.php'); |
| 51 | } elseif (file_exists(SM_PATH . 'plugins/filters/config.php')) { |
| 52 | include_once (SM_PATH . 'plugins/filters/config.php'); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Register option blocks |
| 57 | * @access private |
| 58 | */ |
| 59 | function filters_optpage_register_block() { |
| 60 | global $optpage_blocks, $AllowSpamFilters; |
| 61 | |
| 62 | $optpage_blocks[] = array( |
| 63 | 'name' => _("Message Filters"), |
| 64 | 'url' => SM_PATH . 'plugins/filters/options.php', |
| 65 | 'desc' => _("Filtering enables messages with different criteria to be automatically filtered into different folders for easier organization."), |
| 66 | 'js' => false |
| 67 | ); |
| 68 | |
| 69 | if ($AllowSpamFilters) { |
| 70 | $optpage_blocks[] = array( |
| 71 | 'name' => _("SPAM Filters"), |
| 72 | 'url' => SM_PATH . 'plugins/filters/spamoptions.php', |
| 73 | 'desc' => _("SPAM filters allow you to select from various DNS based blacklists to detect junk email in your INBOX and move it to another folder (like Trash)."), |
| 74 | 'js' => false |
| 75 | ); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /* Receive the status of the folder and do something with it */ |
| 80 | function filters_folder_status($statusarr) { |
| 81 | |
| 82 | global $filter_inbox_count; |
| 83 | if (empty($filter_inbox_count)) $filter_inbox_count=0; |
| 84 | |
| 85 | if ($statusarr['MAILBOX'] == 'INBOX') |
| 86 | { |
| 87 | if (!empty($statusarr['MESSAGES'])) $filter_inbox_count=$statusarr['MESSAGES']; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Saves the DNS Cache to disk |
| 93 | * @access private |
| 94 | */ |
| 95 | function filters_SaveCache () { |
| 96 | global $data_dir, $SpamFilters_DNScache; |
| 97 | |
| 98 | if (file_exists($data_dir . '/dnscache')) { |
| 99 | $fp = fopen($data_dir . '/dnscache', 'r'); |
| 100 | } else { |
| 101 | $fp = false; |
| 102 | } |
| 103 | if ($fp) { |
| 104 | flock($fp,LOCK_EX); |
| 105 | } else { |
| 106 | $fp = fopen($data_dir . '/dnscache', 'w+'); |
| 107 | fclose($fp); |
| 108 | $fp = fopen($data_dir . '/dnscache', 'r'); |
| 109 | flock($fp,LOCK_EX); |
| 110 | } |
| 111 | $fp1 = fopen($data_dir . '/dnscache', 'w+'); |
| 112 | |
| 113 | foreach ($SpamFilters_DNScache as $Key=> $Value) { |
| 114 | $tstr = $Key . ',' . $Value['L'] . ',' . $Value['T'] . "\n"; |
| 115 | fputs ($fp1, $tstr); |
| 116 | } |
| 117 | fclose($fp1); |
| 118 | flock($fp,LOCK_UN); |
| 119 | fclose($fp); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Loads the DNS Cache from disk |
| 124 | * @access private |
| 125 | */ |
| 126 | function filters_LoadCache () { |
| 127 | global $data_dir, $SpamFilters_DNScache; |
| 128 | |
| 129 | if (file_exists($data_dir . '/dnscache')) { |
| 130 | $SpamFilters_DNScache = array(); |
| 131 | if ($fp = fopen ($data_dir . '/dnscache', 'r')) { |
| 132 | flock($fp,LOCK_SH); |
| 133 | while ($data = fgetcsv($fp,1024)) { |
| 134 | if ($data[2] > time()) { |
| 135 | $SpamFilters_DNScache[$data[0]]['L'] = $data[1]; |
| 136 | $SpamFilters_DNScache[$data[0]]['T'] = $data[2]; |
| 137 | } |
| 138 | } |
| 139 | flock($fp,LOCK_UN); |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Uses the BulkQuery executable to query all the RBLs at once |
| 146 | * @param array $filters Array of SPAM Filters |
| 147 | * @param array $IPs Array of IP Addresses |
| 148 | * @access private |
| 149 | */ |
| 150 | function filters_bulkquery($filters, $IPs) { |
| 151 | global $attachment_dir, $username, |
| 152 | $SpamFilters_DNScache, $SpamFilters_BulkQuery, |
| 153 | $SpamFilters_CacheTTL; |
| 154 | |
| 155 | if (count($IPs) > 0) { |
| 156 | $rbls = array(); |
| 157 | foreach ($filters as $key => $value) { |
| 158 | if ($filters[$key]['enabled']) { |
| 159 | if ($filters[$key]['dns']) { |
| 160 | $rbls[$filters[$key]['dns']] = true; |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | $bqfil = $attachment_dir . $username . '-bq.in'; |
| 166 | $fp = fopen($bqfil, 'w'); |
| 167 | fputs ($fp, $SpamFilters_CacheTTL . "\n"); |
| 168 | foreach ($rbls as $key => $value) { |
| 169 | fputs ($fp, '.' . $key . "\n"); |
| 170 | } |
| 171 | fputs ($fp, "----------\n"); |
| 172 | foreach ($IPs as $key => $value) { |
| 173 | fputs ($fp, $key . "\n"); |
| 174 | } |
| 175 | fclose ($fp); |
| 176 | $bqout = array(); |
| 177 | exec ($SpamFilters_BulkQuery . ' < ' . $bqfil, $bqout); |
| 178 | foreach ($bqout as $value) { |
| 179 | $Chunks = explode(',', $value); |
| 180 | $SpamFilters_DNScache[$Chunks[0]]['L'] = $Chunks[1]; |
| 181 | $SpamFilters_DNScache[$Chunks[0]]['T'] = $Chunks[2] + time(); |
| 182 | } |
| 183 | unlink($bqfil); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Starts the filtering process |
| 189 | * @param array $hook_args (since 1.5.2) do hook arguments. Is used to check |
| 190 | * hook name, array key = 0. |
| 191 | * @access private |
| 192 | */ |
| 193 | function start_filters($hook_args) { |
| 194 | global $imapServerAddress, $imapPort, $imap_stream_options, $imap_stream, |
| 195 | $imapConnection, $UseSeparateImapConnection, $AllowSpamFilters, |
| 196 | $filter_inbox_count, $username; |
| 197 | |
| 198 | // if there were filtering errors previously during |
| 199 | // this login session, we won't try again |
| 200 | sqgetGlobalVar('filters_error', $filters_error, SQ_SESSION, FALSE); |
| 201 | if ($filters_error) |
| 202 | return; |
| 203 | |
| 204 | /** |
| 205 | * check hook that calls filtering. If filters are called by right_main_after_header, |
| 206 | * do filtering only when we are in INBOX folder. |
| 207 | */ |
| 208 | if ($hook_args[0]=='right_main_after_header' && |
| 209 | (sqgetGlobalVar('mailbox',$mailbox,SQ_FORM) && $mailbox!='INBOX')) { |
| 210 | return; |
| 211 | } |
| 212 | |
| 213 | $filters = load_filters(); |
| 214 | |
| 215 | // No point running spam filters if there aren't any to run // |
| 216 | if ($AllowSpamFilters) { |
| 217 | $spamfilters = load_spam_filters(); |
| 218 | |
| 219 | $AllowSpamFilters = false; |
| 220 | foreach($spamfilters as $value) { |
| 221 | if ($value['enabled'] == SMPREF_ON) { |
| 222 | $AllowSpamFilters = true; |
| 223 | break; |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | // No user filters, and no spam filters, no need to continue // |
| 229 | if (!$AllowSpamFilters && empty($filters)) { |
| 230 | return; |
| 231 | } |
| 232 | |
| 233 | |
| 234 | // Detect if we have already connected to IMAP or not. |
| 235 | // Also check if we are forced to use a separate IMAP connection |
| 236 | if ((!isset($imap_stream) && !isset($imapConnection)) || |
| 237 | $UseSeparateImapConnection ) { |
| 238 | $stream = sqimap_login($username, false, $imapServerAddress, |
| 239 | $imapPort, 10, $imap_stream_options); |
| 240 | $previously_connected = false; |
| 241 | } else if (isset($imapConnection)) { |
| 242 | $stream = $imapConnection; |
| 243 | $previously_connected = true; |
| 244 | } else { |
| 245 | $previously_connected = true; |
| 246 | $stream = $imap_stream; |
| 247 | } |
| 248 | |
| 249 | if (!isset($filter_inbox_count)) { |
| 250 | $aStatus = sqimap_status_messages ($stream, 'INBOX', array('MESSAGES')); |
| 251 | if (!empty($aStatus['MESSAGES'])) { |
| 252 | $filter_inbox_count=$aStatus['MESSAGES']; |
| 253 | } else { |
| 254 | $filter_inbox_count=0; |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | if ($filter_inbox_count > 0) { |
| 259 | sqimap_mailbox_select($stream, 'INBOX'); |
| 260 | // Filter spam from inbox before we sort them into folders |
| 261 | if ($AllowSpamFilters) { |
| 262 | spam_filters($stream); |
| 263 | } |
| 264 | |
| 265 | // Sort into folders |
| 266 | user_filters($stream); |
| 267 | } |
| 268 | |
| 269 | if (!$previously_connected) { |
| 270 | sqimap_logout($stream); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * Does the loop through each filter |
| 276 | * @param stream imap_stream the stream to read from |
| 277 | * @access private |
| 278 | */ |
| 279 | function user_filters($imap_stream) { |
| 280 | global $data_dir, $username; |
| 281 | $filters = load_filters(); |
| 282 | if (! $filters) return; |
| 283 | $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan'); |
| 284 | |
| 285 | $expunge = false; |
| 286 | // For every rule |
| 287 | for ($i=0, $num = count($filters); $i < $num; $i++) { |
| 288 | // If it is the "combo" rule |
| 289 | if ($filters[$i]['where'] == 'To or Cc') { |
| 290 | /* |
| 291 | * If it's "TO OR CC", we have to do two searches, one for TO |
| 292 | * and the other for CC. |
| 293 | */ |
| 294 | $expunge = filter_search_and_delete($imap_stream, 'TO', |
| 295 | $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge); |
| 296 | $expunge = filter_search_and_delete($imap_stream, 'CC', |
| 297 | $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge); |
| 298 | } else if ($filters[$i]['where'] == 'Header and Body') { |
| 299 | $expunge = filter_search_and_delete($imap_stream, 'TEXT', |
| 300 | $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge); |
| 301 | } else if ($filters[$i]['where'] == 'Message Body') { |
| 302 | $expunge = filter_search_and_delete($imap_stream, 'BODY', |
| 303 | $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge); |
| 304 | } else { |
| 305 | /* |
| 306 | * If it's a normal TO, CC, SUBJECT, or FROM, then handle it |
| 307 | * normally. |
| 308 | */ |
| 309 | $expunge = filter_search_and_delete($imap_stream, $filters[$i]['where'], |
| 310 | $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge); |
| 311 | } |
| 312 | } |
| 313 | // Clean out the mailbox whether or not auto_expunge is on |
| 314 | // That way it looks like it was redirected properly |
| 315 | if ($expunge) { |
| 316 | sqimap_mailbox_expunge($imap_stream, 'INBOX'); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | /** |
| 321 | * Creates and runs the IMAP command to filter messages |
| 322 | * @param string $imap_stream TODO: Document this parameter |
| 323 | * @param string $where Which part of the message to search (TO, CC, SUBJECT, etc...) |
| 324 | * @param string $what String to search for |
| 325 | * @param string $where_to Folder it will move to |
| 326 | * @param string $user_scan Whether to search all or just unseen |
| 327 | * @param string $should_expunge |
| 328 | * @access private |
| 329 | */ |
| 330 | function filter_search_and_delete($imap_stream, $where, $what, $where_to, $user_scan, |
| 331 | $should_expunge) { |
| 332 | global $languages, $squirrelmail_language, $allow_charset_search, $imap_server_type; |
| 333 | |
| 334 | //TODO: make use of new mailbox cache. See mailbox_display.phpinfo |
| 335 | |
| 336 | if (strtolower($where_to) == 'inbox') { |
| 337 | return array(); |
| 338 | } |
| 339 | |
| 340 | if ($user_scan == 'new') { |
| 341 | $category = 'UNSEEN'; |
| 342 | } else { |
| 343 | $category = 'ALL'; |
| 344 | } |
| 345 | $category .= ' UNDELETED'; |
| 346 | |
| 347 | if ($allow_charset_search && |
| 348 | isset($languages[$squirrelmail_language]['CHARSET']) && |
| 349 | $languages[$squirrelmail_language]['CHARSET']) { |
| 350 | $search_str = 'SEARCH CHARSET ' |
| 351 | . strtoupper($languages[$squirrelmail_language]['CHARSET']) |
| 352 | . ' ' . $category; |
| 353 | } else { |
| 354 | $search_str = 'SEARCH CHARSET US-ASCII ' . $category; |
| 355 | } |
| 356 | if ($where == 'Header') { |
| 357 | $what = explode(':', $what); |
| 358 | $where = strtoupper($where); |
| 359 | $where = trim($where . ' ' . $what[0]); |
| 360 | $what = addslashes(trim($what[1])); |
| 361 | } |
| 362 | |
| 363 | // see comments in squirrelmail sqimap_search function |
| 364 | if ($imap_server_type == 'macosx' || $imap_server_type == 'hmailserver') { |
| 365 | $search_str .= ' ' . $where . ' ' . $what; |
| 366 | /* read data back from IMAP */ |
| 367 | $read = sqimap_run_command($imap_stream, $search_str, true, $response, $message, TRUE); |
| 368 | } else { |
| 369 | $search_str .= ' ' . $where . ' {' . strlen($what) . "}"; |
| 370 | $sid = sqimap_session_id(true); |
| 371 | fputs ($imap_stream, $sid . ' ' . $search_str . "\r\n"); |
| 372 | $read2 = sqimap_fgets($imap_stream); |
| 373 | # server should respond with Ready for argument, then we will send search text |
| 374 | #echo "RR2 $read2<br>"; |
| 375 | fputs ($imap_stream, "$what\r\n"); |
| 376 | #echo "SS $what<br>"; |
| 377 | $read2 = sqimap_fgets($imap_stream); |
| 378 | #echo "RR2 $read2<br>"; |
| 379 | $read[]=$read2; |
| 380 | $read3 = sqimap_fgets($imap_stream); |
| 381 | #echo "RR3 $read3<br>"; |
| 382 | list($rtag,$response,$message)=explode(' ',$read3,3); |
| 383 | ## $read2 = sqimap_retrieve_imap_response($imap_stream, $sid, true, |
| 384 | ## $response, $message, $search_str, false, true, false); |
| 385 | #echo "RR2 $read2 / RESPONSE $response<br>"; |
| 386 | } |
| 387 | |
| 388 | if (isset($read[0])) { |
| 389 | $ids = array(); |
| 390 | for ($i = 0, $iCnt = count($read); $i < $iCnt; ++$i) { |
| 391 | if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) { |
| 392 | $ids += explode(' ', trim($regs[1])); |
| 393 | } |
| 394 | } |
| 395 | if ($response == 'OK' && count($ids)) { |
| 396 | if (sqimap_mailbox_exists($imap_stream, $where_to)) { |
| 397 | if (!sqimap_msgs_list_move ($imap_stream, $ids, $where_to, false)) { |
| 398 | // if errors occurred, don't try to filter again during this session |
| 399 | sqsession_register(TRUE, 'filters_error'); |
| 400 | global $color; |
| 401 | error_box(_("A problem occurred filtering messages. Check filter settings and account quota if applicable. Filtering is disabled for the remainder of this login session."), $color); |
| 402 | } |
| 403 | |
| 404 | // expunge even in the case of errors, in case some |
| 405 | // messages were filtered before the error happened |
| 406 | $should_expunge = true; |
| 407 | } |
| 408 | } elseif ($response != 'OK') { |
| 409 | $query = $search_str . "\r\n".$what ."\r\n"; |
| 410 | if ($response == 'NO') { |
| 411 | if (strpos($message,'BADCHARSET') !== false || |
| 412 | strpos($message,'character') !== false) { |
| 413 | sqm_trigger_imap_error('SQM_IMAP_BADCHARSET',$query, $response, $message); |
| 414 | } else { |
| 415 | sqm_trigger_imap_error('SQM_IMAP_ERROR',$query, $response, $message); |
| 416 | } |
| 417 | } else { |
| 418 | sqm_trigger_imap_error('SQM_IMAP_ERROR',$query, $response, $message); |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | return $should_expunge; |
| 423 | } |
| 424 | |
| 425 | /** |
| 426 | * Loops through all the Received Headers to find IP Addresses |
| 427 | * @param stream imap_stream the stream to read from |
| 428 | * @access private |
| 429 | */ |
| 430 | function spam_filters($imap_stream) { |
| 431 | global $data_dir, $username; |
| 432 | global $SpamFilters_YourHop; |
| 433 | global $SpamFilters_DNScache; |
| 434 | global $SpamFilters_SharedCache; |
| 435 | global $SpamFilters_BulkQuery; |
| 436 | global $SpamFilters_CacheTTL; |
| 437 | |
| 438 | $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan'); |
| 439 | $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder'); |
| 440 | $filters = load_spam_filters(); |
| 441 | |
| 442 | if ($SpamFilters_SharedCache) { |
| 443 | filters_LoadCache(); |
| 444 | } |
| 445 | |
| 446 | $run = false; |
| 447 | |
| 448 | foreach ($filters as $Value) { |
| 449 | if ($Value['enabled']) { |
| 450 | $run = true; |
| 451 | break; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | // short-circuit |
| 456 | if (!$run) { |
| 457 | return; |
| 458 | } |
| 459 | |
| 460 | // Ask for a big list of all "Received" headers in the inbox with |
| 461 | // flags for each message. Kinda big. |
| 462 | |
| 463 | if ($filters_spam_scan == 'new') { |
| 464 | $search_array = array(); |
| 465 | $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true, $response, $message, TRUE); |
| 466 | if (isset($read[0])) { |
| 467 | for ($i = 0, $iCnt = count($read); $i < $iCnt; ++$i) { |
| 468 | if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) { |
| 469 | $search_array = explode(' ', trim($regs[1])); |
| 470 | break; |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 | if ($filters_spam_scan == 'new' && count($search_array)) { |
| 476 | $headers = sqimap_get_small_header_list ($imap_stream, $search_array, array('Received'),array()); |
| 477 | } else if ($filters_spam_scan != 'new') { |
| 478 | $headers = sqimap_get_small_header_list ($imap_stream, null , array('Received'),array()); |
| 479 | } else { |
| 480 | return; |
| 481 | } |
| 482 | if (!count($headers)) { |
| 483 | return; |
| 484 | } |
| 485 | $bulkquery = (strlen($SpamFilters_BulkQuery) > 0 ? true : false); |
| 486 | $IPs = array(); |
| 487 | $aSpamIds = array(); |
| 488 | foreach ($headers as $id => $aValue) { |
| 489 | if (isset($aValue['UID'])) { |
| 490 | $MsgNum = $aValue['UID']; |
| 491 | } else { |
| 492 | $MsgNum = $id; |
| 493 | } |
| 494 | // Look through all of the Received headers for IP addresses |
| 495 | if (isset($aValue['RECEIVED'])) { |
| 496 | foreach ($aValue['RECEIVED'] as $received) { |
| 497 | // Check to see if this line is the right "Received from" line |
| 498 | // to check |
| 499 | |
| 500 | // $aValue['Received'] is an array with all the received lines. |
| 501 | // We should check them from bottom to top and only check the first 2. |
| 502 | // Currently we check only the header where $SpamFilters_YourHop in occures |
| 503 | |
| 504 | if (is_int(strpos($received, $SpamFilters_YourHop))) { |
| 505 | if (preg_match('/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/',$received,$aMatch)) { |
| 506 | $isspam = false; |
| 507 | if (filters_spam_check_site($aMatch[1],$aMatch[2],$aMatch[3],$aMatch[4],$filters)) { |
| 508 | $aSpamIds[] = $MsgNum; |
| 509 | $isspam = true; |
| 510 | } |
| 511 | |
| 512 | if ($bulkquery) { |
| 513 | array_shift($aMatch); |
| 514 | $IP = explode('.', $aMatch); |
| 515 | foreach ($filters as $key => $value) { |
| 516 | if ($filters[$key]['enabled'] && $filters[$key]['dns']) { |
| 517 | if (strlen($SpamFilters_DNScache[$IP.'.'.$filters[$key]['dns']]) == 0) { |
| 518 | $IPs[$IP] = true; |
| 519 | break; |
| 520 | } |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | // If we've checked one IP and YourHop is |
| 525 | // just a space |
| 526 | if ($SpamFilters_YourHop == ' ' || $isspam) { |
| 527 | break; // don't check any more |
| 528 | } |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | } |
| 534 | // Lookie! It's spam! Yum! |
| 535 | if (count($aSpamIds) && sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) { |
| 536 | if (!sqimap_msgs_list_move($imap_stream, $aSpamIds, $filters_spam_folder)) { |
| 537 | // if errors occurred, don't try to filter again during this session |
| 538 | sqsession_register(TRUE, 'filters_error'); |
| 539 | global $color; |
| 540 | error_box(_("A problem occurred filtering messages. Check filter settings and account quota if applicable. Filtering is disabled for the remainder of this login session."), $color); |
| 541 | } |
| 542 | |
| 543 | // expunge even in the case of errors, in case some |
| 544 | // messages were filtered before the error happened |
| 545 | sqimap_mailbox_expunge($imap_stream, 'INBOX'); |
| 546 | } |
| 547 | |
| 548 | if ($bulkquery && count($IPs)) { |
| 549 | filters_bulkquery($filters, $IPs); |
| 550 | } |
| 551 | |
| 552 | if ($SpamFilters_SharedCache) { |
| 553 | filters_SaveCache(); |
| 554 | } else { |
| 555 | sqsession_register($SpamFilters_DNScache, 'SpamFilters_DNScache'); |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * Does the loop through each enabled filter for the specified IP address. |
| 561 | * IP format: $a.$b.$c.$d |
| 562 | * @param int $a First subset of IP |
| 563 | * @param int $b Second subset of IP |
| 564 | * @param int $c Third subset of IP |
| 565 | * @param int $d Forth subset of IP |
| 566 | * @param array $filters The Spam Filters |
| 567 | * @return boolean Whether the IP is Spam |
| 568 | * @access private |
| 569 | */ |
| 570 | function filters_spam_check_site($a, $b, $c, $d, &$filters) { |
| 571 | global $SpamFilters_DNScache, $SpamFilters_CacheTTL; |
| 572 | foreach ($filters as $key => $value) { |
| 573 | if ($filters[$key]['enabled']) { |
| 574 | if ($filters[$key]['dns']) { |
| 575 | |
| 576 | /** |
| 577 | * RFC allows . on end of hostname to force domain lookup to |
| 578 | * not use search domain from resolv.conf, i.e. to ensure |
| 579 | * search domain isn't used if no hostname is found |
| 580 | */ |
| 581 | $filter_revip = $d . '.' . $c . '.' . $b . '.' . $a . '.' . |
| 582 | $filters[$key]['dns'] . '.'; |
| 583 | |
| 584 | if(!isset($SpamFilters_DNScache[$filter_revip]['L'])) |
| 585 | $SpamFilters_DNScache[$filter_revip]['L'] = ''; |
| 586 | |
| 587 | if(!isset($SpamFilters_DNScache[$filter_revip]['T'])) |
| 588 | $SpamFilters_DNScache[$filter_revip]['T'] = ''; |
| 589 | |
| 590 | if (strlen($SpamFilters_DNScache[$filter_revip]['L']) == 0) { |
| 591 | $SpamFilters_DNScache[$filter_revip]['L'] = |
| 592 | gethostbyname($filter_revip); |
| 593 | $SpamFilters_DNScache[$filter_revip]['T'] = |
| 594 | time() + $SpamFilters_CacheTTL; |
| 595 | } |
| 596 | |
| 597 | /** |
| 598 | * gethostbyname returns ip if resolved, or returns original |
| 599 | * host supplied to function if there is no resolution |
| 600 | */ |
| 601 | if ($SpamFilters_DNScache[$filter_revip]['L'] != $filter_revip) { |
| 602 | return 1; |
| 603 | } |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | return 0; |
| 608 | } |
| 609 | |
| 610 | /** |
| 611 | * Loads the filters from the user preferences |
| 612 | * @return array All the user filters |
| 613 | * @access private |
| 614 | */ |
| 615 | function load_filters() { |
| 616 | global $data_dir, $username; |
| 617 | |
| 618 | $filters = array(); |
| 619 | for ($i = 0; $fltr = getPref($data_dir, $username, 'filter' . $i); $i++) { |
| 620 | $ary = explode(',', $fltr); |
| 621 | $filters[$i]['where'] = $ary[0]; |
| 622 | $filters[$i]['what'] = str_replace('###COMMA###', ',', $ary[1]); |
| 623 | $filters[$i]['folder'] = $ary[2]; |
| 624 | } |
| 625 | return $filters; |
| 626 | } |
| 627 | |
| 628 | /** |
| 629 | * Loads the Spam Filters and checks the preferences for the enabled status |
| 630 | * @return array All the spam filters |
| 631 | * @access private |
| 632 | */ |
| 633 | function load_spam_filters() { |
| 634 | global $data_dir, $username, $SpamFilters_ShowCommercial; |
| 635 | |
| 636 | if ($SpamFilters_ShowCommercial) { |
| 637 | $filters['MAPS RBL']['prefname'] = 'filters_spam_maps_rbl'; |
| 638 | $filters['MAPS RBL']['name'] = 'MAPS Realtime Blackhole List'; |
| 639 | $filters['MAPS RBL']['link'] = 'http://www.mail-abuse.org/rbl/'; |
| 640 | $filters['MAPS RBL']['dns'] = 'blackholes.mail-abuse.org'; |
| 641 | $filters['MAPS RBL']['result'] = '127.0.0.2'; |
| 642 | $filters['MAPS RBL']['comment'] = |
| 643 | _("COMMERCIAL - This list contains servers that are verified spam senders. It is a pretty reliable list to scan spam from."); |
| 644 | |
| 645 | $filters['MAPS RSS']['prefname'] = 'filters_spam_maps_rss'; |
| 646 | $filters['MAPS RSS']['name'] = 'MAPS Relay Spam Stopper'; |
| 647 | $filters['MAPS RSS']['link'] = 'http://www.mail-abuse.org/rss/'; |
| 648 | $filters['MAPS RSS']['dns'] = 'relays.mail-abuse.org'; |
| 649 | $filters['MAPS RSS']['result'] = '127.0.0.2'; |
| 650 | $filters['MAPS RSS']['comment'] = |
| 651 | _("COMMERCIAL - Servers that are configured (or misconfigured) to allow spam to be relayed through their system will be banned with this. Another good one to use."); |
| 652 | |
| 653 | $filters['MAPS DUL']['prefname'] = 'filters_spam_maps_dul'; |
| 654 | $filters['MAPS DUL']['name'] = 'MAPS Dial-Up List'; |
| 655 | $filters['MAPS DUL']['link'] = 'http://www.mail-abuse.org/dul/'; |
| 656 | $filters['MAPS DUL']['dns'] = 'dialups.mail-abuse.org'; |
| 657 | $filters['MAPS DUL']['result'] = '127.0.0.3'; |
| 658 | $filters['MAPS DUL']['comment'] = |
| 659 | _("COMMERCIAL - Dial-up users are often filtered out since they should use their ISP's mail servers to send mail. Spammers typically get a dial-up account and send spam directly from there."); |
| 660 | |
| 661 | $filters['MAPS RBLplus-RBL']['prefname'] = 'filters_spam_maps_rblplus_rbl'; |
| 662 | $filters['MAPS RBLplus-RBL']['name'] = 'MAPS RBL+ RBL List'; |
| 663 | $filters['MAPS RBLplus-RBL']['link'] = 'http://www.mail-abuse.org/'; |
| 664 | $filters['MAPS RBLplus-RBL']['dns'] = 'rbl-plus.mail-abuse.org'; |
| 665 | $filters['MAPS RBLplus-RBL']['result'] = '127.0.0.2'; |
| 666 | $filters['MAPS RBLplus-RBL']['comment'] = |
| 667 | _("COMMERCIAL - RBL+ Blackhole entries."); |
| 668 | |
| 669 | $filters['MAPS RBLplus-RSS']['prefname'] = 'filters_spam_maps_rblplus_rss'; |
| 670 | $filters['MAPS RBLplus-RSS']['name'] = 'MAPS RBL+ List RSS entries'; |
| 671 | $filters['MAPS RBLplus-RSS']['link'] = 'http://www.mail-abuse.org/'; |
| 672 | $filters['MAPS RBLplus-RSS']['dns'] = 'rbl-plus.mail-abuse.org'; |
| 673 | $filters['MAPS RBLplus-RSS']['result'] = '127.0.0.2'; |
| 674 | $filters['MAPS RBLplus-RSS']['comment'] = |
| 675 | _("COMMERCIAL - RBL+ OpenRelay entries."); |
| 676 | |
| 677 | $filters['MAPS RBLplus-DUL']['prefname'] = 'filters_spam_maps_rblplus_dul'; |
| 678 | $filters['MAPS RBLplus-DUL']['name'] = 'MAPS RBL+ List DUL entries'; |
| 679 | $filters['MAPS RBLplus-DUL']['link'] = 'http://www.mail-abuse.org/'; |
| 680 | $filters['MAPS RBLplus-DUL']['dns'] = 'rbl-plus.mail-abuse.org'; |
| 681 | $filters['MAPS RBLplus-DUL']['result'] = '127.0.0.3'; |
| 682 | $filters['MAPS RBLplus-DUL']['comment'] = |
| 683 | _("COMMERCIAL - RBL+ Dial-up entries."); |
| 684 | } |
| 685 | |
| 686 | $filters['FiveTen Direct']['prefname'] = 'filters_spam_fiveten_src'; |
| 687 | $filters['FiveTen Direct']['name'] = 'Five-Ten-sg.com Direct SPAM Sources'; |
| 688 | $filters['FiveTen Direct']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
| 689 | $filters['FiveTen Direct']['dns'] = 'blackholes.five-ten-sg.com'; |
| 690 | $filters['FiveTen Direct']['result'] = '127.0.0.2'; |
| 691 | $filters['FiveTen Direct']['comment'] = |
| 692 | _("FREE - Five-Ten-sg.com - Direct SPAM sources."); |
| 693 | |
| 694 | $filters['FiveTen DUL']['prefname'] = 'filters_spam_fiveten_dul'; |
| 695 | $filters['FiveTen DUL']['name'] = 'Five-Ten-sg.com DUL Lists'; |
| 696 | $filters['FiveTen DUL']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
| 697 | $filters['FiveTen DUL']['dns'] = 'blackholes.five-ten-sg.com'; |
| 698 | $filters['FiveTen DUL']['result'] = '127.0.0.3'; |
| 699 | $filters['FiveTen DUL']['comment'] = |
| 700 | _("FREE - Five-Ten-sg.com - Dial-up lists - includes some DSL IPs."); |
| 701 | |
| 702 | $filters['FiveTen Unc. OptIn']['prefname'] = 'filters_spam_fiveten_oi'; |
| 703 | $filters['FiveTen Unc. OptIn']['name'] = 'Five-Ten-sg.com Unconfirmed OptIn Lists'; |
| 704 | $filters['FiveTen Unc. OptIn']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
| 705 | $filters['FiveTen Unc. OptIn']['dns'] = 'blackholes.five-ten-sg.com'; |
| 706 | $filters['FiveTen Unc. OptIn']['result'] = '127.0.0.4'; |
| 707 | $filters['FiveTen Unc. OptIn']['comment'] = |
| 708 | _("FREE - Five-Ten-sg.com - Bulk mailers that do not use confirmed opt-in."); |
| 709 | |
| 710 | $filters['FiveTen Others']['prefname'] = 'filters_spam_fiveten_oth'; |
| 711 | $filters['FiveTen Others']['name'] = 'Five-Ten-sg.com Other Misc. Servers'; |
| 712 | $filters['FiveTen Others']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
| 713 | $filters['FiveTen Others']['dns'] = 'blackholes.five-ten-sg.com'; |
| 714 | $filters['FiveTen Others']['result'] = '127.0.0.5'; |
| 715 | $filters['FiveTen Others']['comment'] = |
| 716 | _("FREE - Five-Ten-sg.com - Other misc. servers."); |
| 717 | |
| 718 | $filters['FiveTen Single Stage']['prefname'] = 'filters_spam_fiveten_ss'; |
| 719 | $filters['FiveTen Single Stage']['name'] = 'Five-Ten-sg.com Single Stage Servers'; |
| 720 | $filters['FiveTen Single Stage']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
| 721 | $filters['FiveTen Single Stage']['dns'] = 'blackholes.five-ten-sg.com'; |
| 722 | $filters['FiveTen Single Stage']['result'] = '127.0.0.6'; |
| 723 | $filters['FiveTen Single Stage']['comment'] = |
| 724 | _("FREE - Five-Ten-sg.com - Single Stage servers."); |
| 725 | |
| 726 | $filters['FiveTen SPAM Support']['prefname'] = 'filters_spam_fiveten_supp'; |
| 727 | $filters['FiveTen SPAM Support']['name'] = 'Five-Ten-sg.com SPAM Support Servers'; |
| 728 | $filters['FiveTen SPAM Support']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
| 729 | $filters['FiveTen SPAM Support']['dns'] = 'blackholes.five-ten-sg.com'; |
| 730 | $filters['FiveTen SPAM Support']['result'] = '127.0.0.7'; |
| 731 | $filters['FiveTen SPAM Support']['comment'] = |
| 732 | _("FREE - Five-Ten-sg.com - SPAM Support servers."); |
| 733 | |
| 734 | $filters['FiveTen Web forms']['prefname'] = 'filters_spam_fiveten_wf'; |
| 735 | $filters['FiveTen Web forms']['name'] = 'Five-Ten-sg.com Web Form IPs'; |
| 736 | $filters['FiveTen Web forms']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
| 737 | $filters['FiveTen Web forms']['dns'] = 'blackholes.five-ten-sg.com'; |
| 738 | $filters['FiveTen Web forms']['result'] = '127.0.0.8'; |
| 739 | $filters['FiveTen Web forms']['comment'] = |
| 740 | _("FREE - Five-Ten-sg.com - Web Form IPs."); |
| 741 | |
| 742 | $filters['Dorkslayers']['prefname'] = 'filters_spam_dorks'; |
| 743 | $filters['Dorkslayers']['name'] = 'Dorkslayers Lists'; |
| 744 | $filters['Dorkslayers']['link'] = 'http://www.dorkslayers.com'; |
| 745 | $filters['Dorkslayers']['dns'] = 'orbs.dorkslayers.com'; |
| 746 | $filters['Dorkslayers']['result'] = '127.0.0.2'; |
| 747 | $filters['Dorkslayers']['comment'] = |
| 748 | _("FREE - Dorkslayers appears to include only really bad open relays outside the US to avoid being sued. Interestingly enough, their website recommends you NOT use their service."); |
| 749 | |
| 750 | $filters['SPAMhaus']['prefname'] = 'filters_spam_spamhaus'; |
| 751 | $filters['SPAMhaus']['name'] = 'SPAMhaus Lists'; |
| 752 | $filters['SPAMhaus']['link'] = 'http://www.spamhaus.org'; |
| 753 | $filters['SPAMhaus']['dns'] = 'sbl.spamhaus.org'; |
| 754 | $filters['SPAMhaus']['result'] = '127.0.0.2'; |
| 755 | $filters['SPAMhaus']['comment'] = |
| 756 | _("FREE - SPAMhaus - A list of well-known SPAM sources."); |
| 757 | |
| 758 | $filters['SPAMcop']['prefname'] = 'filters_spam_spamcop'; |
| 759 | $filters['SPAMcop']['name'] = 'SPAM Cop Lists'; |
| 760 | $filters['SPAMcop']['link'] = 'http://spamcop.net/bl.shtml'; |
| 761 | $filters['SPAMcop']['dns'] = 'bl.spamcop.net'; |
| 762 | $filters['SPAMcop']['result'] = '127.0.0.2'; |
| 763 | $filters['SPAMcop']['comment'] = |
| 764 | _("FREE, for now - SpamCop - An interesting solution that lists servers that have a very high spam to legit email ratio (85 percent or more)."); |
| 765 | |
| 766 | $filters['dev.null.dk']['prefname'] = 'filters_spam_devnull'; |
| 767 | $filters['dev.null.dk']['name'] = 'dev.null.dk Lists'; |
| 768 | $filters['dev.null.dk']['link'] = 'http://dev.null.dk/'; |
| 769 | $filters['dev.null.dk']['dns'] = 'dev.null.dk'; |
| 770 | $filters['dev.null.dk']['result'] = '127.0.0.2'; |
| 771 | $filters['dev.null.dk']['comment'] = |
| 772 | _("FREE - dev.null.dk - I don't have any detailed info on this list."); |
| 773 | |
| 774 | $filters['visi.com']['prefname'] = 'filters_spam_visi'; |
| 775 | $filters['visi.com']['name'] = 'visi.com Relay Stop List'; |
| 776 | $filters['visi.com']['link'] = 'http://relays.visi.com'; |
| 777 | $filters['visi.com']['dns'] = 'relays.visi.com'; |
| 778 | $filters['visi.com']['result'] = '127.0.0.2'; |
| 779 | $filters['visi.com']['comment'] = |
| 780 | _("FREE - visi.com - Relay Stop List. Very conservative OpenRelay List."); |
| 781 | |
| 782 | $filters['ahbl.org Open Relays']['prefname'] = 'filters_spam_2mb_or'; |
| 783 | $filters['ahbl.org Open Relays']['name'] = 'ahbl.org Open Relays List'; |
| 784 | $filters['ahbl.org Open Relays']['link'] = 'http://www.ahbl.org/'; |
| 785 | $filters['ahbl.org Open Relays']['dns'] = 'dnsbl.ahbl.org'; |
| 786 | $filters['ahbl.org Open Relays']['result'] = '127.0.0.2'; |
| 787 | $filters['ahbl.org Open Relays']['comment'] = |
| 788 | _("FREE - ahbl.org Open Relays - Another list of Open Relays."); |
| 789 | |
| 790 | $filters['ahbl.org SPAM Source']['prefname'] = 'filters_spam_2mb_ss'; |
| 791 | $filters['ahbl.org SPAM Source']['name'] = 'ahbl.org SPAM Source List'; |
| 792 | $filters['ahbl.org SPAM Source']['link'] = 'http://www.ahbl.org/'; |
| 793 | $filters['ahbl.org SPAM Source']['dns'] = 'dnsbl.ahbl.org'; |
| 794 | $filters['ahbl.org SPAM Source']['result'] = '127.0.0.4'; |
| 795 | $filters['ahbl.org SPAM Source']['comment'] = |
| 796 | _("FREE - ahbl.org SPAM Source - List of Direct SPAM Sources."); |
| 797 | |
| 798 | $filters['ahbl.org SPAM ISPs']['prefname'] = 'filters_spam_2mb_isp'; |
| 799 | $filters['ahbl.org SPAM ISPs']['name'] = 'ahbl.org SPAM-friendly ISP List'; |
| 800 | $filters['ahbl.org SPAM ISPs']['link'] = 'http://www.ahbl.org/'; |
| 801 | $filters['ahbl.org SPAM ISPs']['dns'] = 'dnsbl.ahbl.org'; |
| 802 | $filters['ahbl.org SPAM ISPs']['result'] = '127.0.0.7'; |
| 803 | $filters['ahbl.org SPAM ISPs']['comment'] = |
| 804 | _("FREE - ahbl.org SPAM ISPs - List of SPAM-friendly ISPs."); |
| 805 | |
| 806 | $filters['Leadmon DUL']['prefname'] = 'filters_spam_lm_dul'; |
| 807 | $filters['Leadmon DUL']['name'] = 'Leadmon.net DUL List'; |
| 808 | $filters['Leadmon DUL']['link'] = 'http://www.leadmon.net/spamguard/'; |
| 809 | $filters['Leadmon DUL']['dns'] = 'spamguard.leadmon.net'; |
| 810 | $filters['Leadmon DUL']['result'] = '127.0.0.2'; |
| 811 | $filters['Leadmon DUL']['comment'] = |
| 812 | _("FREE - Leadmon DUL - Another list of Dial-up or otherwise dynamically assigned IPs."); |
| 813 | |
| 814 | $filters['Leadmon SPAM Source']['prefname'] = 'filters_spam_lm_ss'; |
| 815 | $filters['Leadmon SPAM Source']['name'] = 'Leadmon.net SPAM Source List'; |
| 816 | $filters['Leadmon SPAM Source']['link'] = 'http://www.leadmon.net/spamguard/'; |
| 817 | $filters['Leadmon SPAM Source']['dns'] = 'spamguard.leadmon.net'; |
| 818 | $filters['Leadmon SPAM Source']['result'] = '127.0.0.3'; |
| 819 | $filters['Leadmon SPAM Source']['comment'] = |
| 820 | _("FREE - Leadmon SPAM Source - List of IPs Leadmon.net has received SPAM directly from."); |
| 821 | |
| 822 | $filters['Leadmon Bulk Mailers']['prefname'] = 'filters_spam_lm_bm'; |
| 823 | $filters['Leadmon Bulk Mailers']['name'] = 'Leadmon.net Bulk Mailers List'; |
| 824 | $filters['Leadmon Bulk Mailers']['link'] = 'http://www.leadmon.net/spamguard/'; |
| 825 | $filters['Leadmon Bulk Mailers']['dns'] = 'spamguard.leadmon.net'; |
| 826 | $filters['Leadmon Bulk Mailers']['result'] = '127.0.0.4'; |
| 827 | $filters['Leadmon Bulk Mailers']['comment'] = |
| 828 | _("FREE - Leadmon Bulk Mailers - Bulk mailers that do not require confirmed opt-in or that have allowed known spammers to become clients and abuse their services."); |
| 829 | |
| 830 | $filters['Leadmon Open Relays']['prefname'] = 'filters_spam_lm_or'; |
| 831 | $filters['Leadmon Open Relays']['name'] = 'Leadmon.net Open Relays List'; |
| 832 | $filters['Leadmon Open Relays']['link'] = 'http://www.leadmon.net/spamguard/'; |
| 833 | $filters['Leadmon Open Relays']['dns'] = 'spamguard.leadmon.net'; |
| 834 | $filters['Leadmon Open Relays']['result'] = '127.0.0.5'; |
| 835 | $filters['Leadmon Open Relays']['comment'] = |
| 836 | _("FREE - Leadmon Open Relays - Single Stage Open Relays that are not listed on other active RBLs."); |
| 837 | |
| 838 | $filters['Leadmon Multi-stage']['prefname'] = 'filters_spam_lm_ms'; |
| 839 | $filters['Leadmon Multi-stage']['name'] = 'Leadmon.net Multi-Stage Relay List'; |
| 840 | $filters['Leadmon Multi-stage']['link'] = 'http://www.leadmon.net/spamguard/'; |
| 841 | $filters['Leadmon Multi-stage']['dns'] = 'spamguard.leadmon.net'; |
| 842 | $filters['Leadmon Multi-stage']['result'] = '127.0.0.6'; |
| 843 | $filters['Leadmon Multi-stage']['comment'] = |
| 844 | _("FREE - Leadmon Multi-stage - Multi-Stage Open Relays that are not listed on other active RBLs and that have sent SPAM to Leadmon.net."); |
| 845 | |
| 846 | $filters['Leadmon SpamBlock']['prefname'] = 'filters_spam_lm_sb'; |
| 847 | $filters['Leadmon SpamBlock']['name'] = 'Leadmon.net SpamBlock Sites List'; |
| 848 | $filters['Leadmon SpamBlock']['link'] = 'http://www.leadmon.net/spamguard/'; |
| 849 | $filters['Leadmon SpamBlock']['dns'] = 'spamguard.leadmon.net'; |
| 850 | $filters['Leadmon SpamBlock']['result'] = '127.0.0.7'; |
| 851 | $filters['Leadmon SpamBlock']['comment'] = |
| 852 | _("FREE - Leadmon SpamBlock - Sites on this listing have sent Leadmon.net direct SPAM from IPs in netblocks where the entire block has no DNS mappings. It's a list of BLOCKS of IPs being used by people who have SPAMmed Leadmon.net."); |
| 853 | |
| 854 | $filters['NJABL Open Relays']['prefname'] = 'filters_spam_njabl_or'; |
| 855 | $filters['NJABL Open Relays']['name'] = 'NJABL Open Relay/Direct Spam Source List'; |
| 856 | $filters['NJABL Open Relays']['link'] = 'http://www.njabl.org/'; |
| 857 | $filters['NJABL Open Relays']['dns'] = 'dnsbl.njabl.org'; |
| 858 | $filters['NJABL Open Relays']['result'] = '127.0.0.2'; |
| 859 | $filters['NJABL Open Relays']['comment'] = |
| 860 | _("FREE, for now - Not Just Another Blacklist - Both Open Relays and Direct SPAM Sources."); |
| 861 | |
| 862 | $filters['NJABL DUL']['prefname'] = 'filters_spam_njabl_dul'; |
| 863 | $filters['NJABL DUL']['name'] = 'NJABL Dial-ups List'; |
| 864 | $filters['NJABL DUL']['link'] = 'http://www.njabl.org/'; |
| 865 | $filters['NJABL DUL']['dns'] = 'dnsbl.njabl.org'; |
| 866 | $filters['NJABL DUL']['result'] = '127.0.0.3'; |
| 867 | $filters['NJABL DUL']['comment'] = |
| 868 | _("FREE, for now - Not Just Another Blacklist - Dial-up IPs."); |
| 869 | |
| 870 | foreach ($filters as $Key => $Value) { |
| 871 | $filters[$Key]['enabled'] = (bool)getPref($data_dir, $username, $filters[$Key]['prefname']); |
| 872 | } |
| 873 | |
| 874 | return $filters; |
| 875 | } |
| 876 | |
| 877 | /** |
| 878 | * Removes a User filter |
| 879 | * @param int $id ID of the filter to remove |
| 880 | * @access private |
| 881 | */ |
| 882 | function remove_filter ($id) { |
| 883 | global $data_dir, $username; |
| 884 | |
| 885 | while ($nextFilter = getPref($data_dir, $username, 'filter' . ($id + 1))) { |
| 886 | setPref($data_dir, $username, 'filter' . $id, $nextFilter); |
| 887 | $id ++; |
| 888 | } |
| 889 | |
| 890 | removePref($data_dir, $username, 'filter' . $id); |
| 891 | } |
| 892 | |
| 893 | /** |
| 894 | * Swaps two filters |
| 895 | * @param int $id1 ID of first filter to swap |
| 896 | * @param int $id2 ID of second filter to swap |
| 897 | * @access private |
| 898 | */ |
| 899 | function filter_swap($id1, $id2) { |
| 900 | global $data_dir, $username; |
| 901 | |
| 902 | $FirstFilter = getPref($data_dir, $username, 'filter' . $id1); |
| 903 | $SecondFilter = getPref($data_dir, $username, 'filter' . $id2); |
| 904 | |
| 905 | if ($FirstFilter && $SecondFilter) { |
| 906 | setPref($data_dir, $username, 'filter' . $id2, $FirstFilter); |
| 907 | setPref($data_dir, $username, 'filter' . $id1, $SecondFilter); |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | /** |
| 912 | * This updates the filter rules when renaming or deleting folders |
| 913 | * @param array $args |
| 914 | * @access private |
| 915 | */ |
| 916 | function update_for_folder ($args) { |
| 917 | $old_folder = $args[0]; |
| 918 | $new_folder = $args[2]; |
| 919 | $action = $args[1]; |
| 920 | global $data_dir, $username; |
| 921 | $filters = array(); |
| 922 | $filters = load_filters(); |
| 923 | $filter_count = count($filters); |
| 924 | $p = 0; |
| 925 | for ($i = 0; $i < $filter_count; $i++) { |
| 926 | if (!empty($filters)) { |
| 927 | if ($old_folder == $filters[$i]['folder']) { |
| 928 | if ($action == 'rename') { |
| 929 | $filters[$i]['folder'] = $new_folder; |
| 930 | setPref($data_dir, $username, 'filter'.$i, |
| 931 | $filters[$i]['where'].','.$filters[$i]['what'].','.$new_folder); |
| 932 | } |
| 933 | elseif ($action == 'delete') { |
| 934 | remove_filter($p); |
| 935 | $p = $p-1; |
| 936 | } |
| 937 | } |
| 938 | $p++; |
| 939 | } |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | /** |
| 944 | * Display formated error message |
| 945 | * @param string $string text message |
| 946 | * @return string html formated text message |
| 947 | * @access private |
| 948 | */ |
| 949 | function do_error($string) { |
| 950 | global $color; |
| 951 | echo "<p align=\"center\"><font color=\"$color[2]\">"; |
| 952 | echo $string; |
| 953 | echo "</font></p>\n"; |
| 954 | } |