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