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