ea01c2d0dc8615d94140587067d8ad84f8c491b0
[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, $imapPort, 10);
237 $previously_connected = false;
238 } else if (isset($imapConnection)) {
239 $stream = $imapConnection;
240 $previously_connected = true;
241 } else {
242 $previously_connected = true;
243 $stream = $imap_stream;
244 }
245
246 if (!isset($filter_inbox_count)) {
247 $aStatus = sqimap_status_messages ($stream, 'INBOX', array('MESSAGES'));
248 if (!empty($aStatus['MESSAGES'])) {
249 $filter_inbox_count=$aStatus['MESSAGES'];
250 } else {
251 $filter_inbox_count=0;
252 }
253 }
254
255 if ($filter_inbox_count > 0) {
256 sqimap_mailbox_select($stream, 'INBOX');
257 // Filter spam from inbox before we sort them into folders
258 if ($AllowSpamFilters) {
259 spam_filters($stream);
260 }
261
262 // Sort into folders
263 user_filters($stream);
264 }
265
266 if (!$previously_connected) {
267 sqimap_logout($stream);
268 }
269 }
270
271 /**
272 * Does the loop through each filter
273 * @param stream imap_stream the stream to read from
274 * @access private
275 */
276 function user_filters($imap_stream) {
277 global $data_dir, $username;
278 $filters = load_filters();
279 if (! $filters) return;
280 $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
281
282 $expunge = false;
283 // For every rule
284 for ($i=0, $num = count($filters); $i < $num; $i++) {
285 // If it is the "combo" rule
286 if ($filters[$i]['where'] == 'To or Cc') {
287 /*
288 * If it's "TO OR CC", we have to do two searches, one for TO
289 * and the other for CC.
290 */
291 $expunge = filter_search_and_delete($imap_stream, 'TO',
292 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
293 $expunge = filter_search_and_delete($imap_stream, 'CC',
294 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
295 } else if ($filters[$i]['where'] == 'Header and Body') {
296 $expunge = filter_search_and_delete($imap_stream, 'TEXT',
297 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
298 } else if ($filters[$i]['where'] == 'Message Body') {
299 $expunge = filter_search_and_delete($imap_stream, 'BODY',
300 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
301 } else {
302 /*
303 * If it's a normal TO, CC, SUBJECT, or FROM, then handle it
304 * normally.
305 */
306 $expunge = filter_search_and_delete($imap_stream, $filters[$i]['where'],
307 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
308 }
309 }
310 // Clean out the mailbox whether or not auto_expunge is on
311 // That way it looks like it was redirected properly
312 if ($expunge) {
313 sqimap_mailbox_expunge($imap_stream, 'INBOX');
314 }
315 }
316
317 /**
318 * Creates and runs the IMAP command to filter messages
319 * @param string $where Which part of the message to search (TO, CC, SUBJECT, etc...)
320 * @param string $what String to search for
321 * @param string $where_to Folder it will move to
322 * @param string $user_scan Whether to search all or just unseen
323 * @param string $should_expunge
324 * @param boolean $where Which part of location to search
325 * @access private
326 */
327 function filter_search_and_delete($imap_stream, $where, $what, $where_to, $user_scan,
328 $should_expunge) {
329 global $languages, $squirrelmail_language, $allow_charset_search, $imap_server_type;
330
331 if (strtolower($where_to) == 'inbox') {
332 return array();
333 }
334
335 if ($user_scan == 'new') {
336 $category = 'UNSEEN';
337 } else {
338 $category = 'ALL';
339 }
340 $category .= ' UNDELETED';
341
342 if ($allow_charset_search &&
343 isset($languages[$squirrelmail_language]['CHARSET']) &&
344 $languages[$squirrelmail_language]['CHARSET']) {
345 $search_str = 'SEARCH CHARSET '
346 . strtoupper($languages[$squirrelmail_language]['CHARSET'])
347 . ' ' . $category;
348 } else {
349 $search_str = 'SEARCH CHARSET US-ASCII ' . $category;
350 }
351 if ($where == 'Header') {
352 $what = explode(':', $what);
353 $where = trim($where . ' ' . $what[0]);
354 $what = addslashes(trim($what[1]));
355 }
356
357 // see comments in squirrelmail sqimap_search function
358 if ($imap_server_type == 'macosx' || $imap_server_type == 'hmailserver') {
359 $search_str .= ' ' . $where . ' ' . $what;
360 } else {
361 $search_str .= ' ' . $where . ' {' . strlen($what) . "}\r\n"
362 . $what;
363 }
364
365 /* read data back from IMAP */
366 $read = sqimap_run_command($imap_stream, $search_str, true, $response, $message, TRUE);
367 if (isset($read[0])) {
368 $ids = array();
369 for ($i = 0, $iCnt = count($read); $i < $iCnt; ++$i) {
370 if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) {
371 $ids = preg_split("/ /", trim($regs[1]));
372 break;
373 }
374 }
375 if ($response == 'OK' && count($ids)) {
376 if (sqimap_mailbox_exists($imap_stream, $where_to)) {
377 $should_expunge = true;
378 sqimap_msgs_list_move ($imap_stream, $ids, $where_to, false);
379 }
380 }
381 }
382 return $should_expunge;
383 }
384
385 /**
386 * Loops through all the Received Headers to find IP Addresses
387 * @param stream imap_stream the stream to read from
388 * @access private
389 */
390 function spam_filters($imap_stream) {
391 global $data_dir, $username;
392 global $SpamFilters_YourHop;
393 global $SpamFilters_DNScache;
394 global $SpamFilters_SharedCache;
395 global $SpamFilters_BulkQuery;
396 global $SpamFilters_CacheTTL;
397
398 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
399 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
400 $filters = load_spam_filters();
401
402 if ($SpamFilters_SharedCache) {
403 filters_LoadCache();
404 }
405
406 $run = false;
407
408 foreach ($filters as $Key => $Value) {
409 if ($Value['enabled']) {
410 $run = true;
411 break;
412 }
413 }
414
415 // short-circuit
416 if (!$run) {
417 return;
418 }
419
420 // Ask for a big list of all "Received" headers in the inbox with
421 // flags for each message. Kinda big.
422
423 if ($filters_spam_scan == 'new') {
424 $search_array = array();
425 $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true, $response, $message, TRUE);
426 if (isset($read[0])) {
427 for ($i = 0, $iCnt = count($read); $i < $iCnt; ++$i) {
428 if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) {
429 $search_array = preg_split("/ /", trim($regs[1]));
430 break;
431 }
432 }
433 }
434 }
435 if ($filters_spam_scan == 'new' && count($search_array)) {
436 $headers = sqimap_get_small_header_list ($imap_stream, $search_array, array('Received'),array());
437 } else if ($filters_spam_scan != 'new') {
438 $headers = sqimap_get_small_header_list ($imap_stream, null , array('Received'),array());
439 } else {
440 return;
441 }
442 if (!count($headers)) {
443 return;
444 }
445 $bulkquery = (strlen($SpamFilters_BulkQuery) > 0 ? true : false);
446 $IPs = array();
447 $aSpamIds = array();
448 foreach ($headers as $id => $aValue) {
449 if (isset($aValue['UID'])) {
450 $MsgNum = $aValue['UID'];
451 } else {
452 $MsgNum = $id;
453 }
454 // Look through all of the Received headers for IP addresses
455 if (isset($aValue['RECEIVED'])) {
456 foreach ($aValue['RECEIVED'] as $received) {
457 // Check to see if this line is the right "Received from" line
458 // to check
459
460 // $aValue['Received'] is an array with all the received lines.
461 // We should check them from bottom to top and only check the first 2.
462 // Currently we check only the header where $SpamFilters_YourHop in occures
463
464 if (is_int(strpos($received, $SpamFilters_YourHop))) {
465 if (preg_match('/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/',$received,$aMatch)) {
466 $isspam = false;
467 if (filters_spam_check_site($aMatch[1],$aMatch[2],$aMatch[3],$aMatch[4],$filters)) {
468 $aSpamIds[] = $MsgNum;
469 $isspam = true;
470 }
471 if ($bulkquery) {
472 array_shift($aMatch);
473 $IP = explode('.',$aMatch);
474 foreach ($filters as $key => $value) {
475 if ($filters[$key]['enabled'] && $filters[$key]['dns']) {
476 if (strlen($SpamFilters_DNScache[$IP.'.'.$filters[$key]['dns']]) == 0) {
477 $IPs[$IP] = true;
478 break;
479 }
480 }
481 }
482 }
483 // If we've checked one IP and YourHop is
484 // just a space
485 if ($SpamFilters_YourHop == ' ' || $isspam) {
486 break; // don't check any more
487 }
488 }
489 }
490 }
491 }
492 }
493 // Lookie! It's spam! Yum!
494 if (count($aSpamIds) && sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) {
495 sqimap_msgs_list_move ($imap_stream, $aSpamIds, $filters_spam_folder);
496 sqimap_mailbox_expunge($imap_stream, 'INBOX');
497 }
498
499 if ($bulkquery && count($IPs)) {
500 filters_bulkquery($filters, $IPs);
501 }
502
503 if ($SpamFilters_SharedCache) {
504 filters_SaveCache();
505 } else {
506 sqsession_register($SpamFilters_DNScache, 'SpamFilters_DNScache');
507 }
508 }
509
510 /**
511 * Does the loop through each enabled filter for the specified IP address.
512 * IP format: $a.$b.$c.$d
513 * @param int $a First subset of IP
514 * @param int $b Second subset of IP
515 * @param int $c Third subset of IP
516 * @param int $d Forth subset of IP
517 * @param array $filters The Spam Filters
518 * @return boolean Whether the IP is Spam
519 * @access private
520 */
521 function filters_spam_check_site($a, $b, $c, $d, &$filters) {
522 global $SpamFilters_DNScache, $SpamFilters_CacheTTL;
523 foreach ($filters as $key => $value) {
524 if ($filters[$key]['enabled']) {
525 if ($filters[$key]['dns']) {
526 $filter_revip = $d . '.' . $c . '.' . $b . '.' . $a . '.' .
527 $filters[$key]['dns'];
528
529 if(!isset($SpamFilters_DNScache[$filter_revip]['L']))
530 $SpamFilters_DNScache[$filter_revip]['L'] = '';
531
532 if(!isset($SpamFilters_DNScache[$filter_revip]['T']))
533 $SpamFilters_DNScache[$filter_revip]['T'] = '';
534
535 if (strlen($SpamFilters_DNScache[$filter_revip]['L']) == 0) {
536 $SpamFilters_DNScache[$filter_revip]['L'] =
537 gethostbyname($filter_revip);
538 $SpamFilters_DNScache[$filter_revip]['T'] =
539 time() + $SpamFilters_CacheTTL;
540 }
541 if ($SpamFilters_DNScache[$filter_revip]['L'] ==
542 $filters[$key]['result']) {
543 return 1;
544 }
545 }
546 }
547 }
548 return 0;
549 }
550
551 /**
552 * Loads the filters from the user preferences
553 * @return array All the user filters
554 * @access private
555 */
556 function load_filters() {
557 global $data_dir, $username;
558
559 $filters = array();
560 for ($i = 0; $fltr = getPref($data_dir, $username, 'filter' . $i); $i++) {
561 $ary = explode(',', $fltr);
562 $filters[$i]['where'] = $ary[0];
563 $filters[$i]['what'] = $ary[1];
564 $filters[$i]['folder'] = $ary[2];
565 }
566 return $filters;
567 }
568
569 /**
570 * Loads the Spam Filters and checks the preferences for the enabled status
571 * @return array All the spam filters
572 * @access private
573 */
574 function load_spam_filters() {
575 global $data_dir, $username, $SpamFilters_ShowCommercial;
576
577 if ($SpamFilters_ShowCommercial) {
578 $filters['MAPS RBL']['prefname'] = 'filters_spam_maps_rbl';
579 $filters['MAPS RBL']['name'] = 'MAPS Realtime Blackhole List';
580 $filters['MAPS RBL']['link'] = 'http://www.mail-abuse.org/rbl/';
581 $filters['MAPS RBL']['dns'] = 'blackholes.mail-abuse.org';
582 $filters['MAPS RBL']['result'] = '127.0.0.2';
583 $filters['MAPS RBL']['comment'] =
584 _("COMMERCIAL - This list contains servers that are verified spam senders. It is a pretty reliable list to scan spam from.");
585
586 $filters['MAPS RSS']['prefname'] = 'filters_spam_maps_rss';
587 $filters['MAPS RSS']['name'] = 'MAPS Relay Spam Stopper';
588 $filters['MAPS RSS']['link'] = 'http://www.mail-abuse.org/rss/';
589 $filters['MAPS RSS']['dns'] = 'relays.mail-abuse.org';
590 $filters['MAPS RSS']['result'] = '127.0.0.2';
591 $filters['MAPS RSS']['comment'] =
592 _("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.");
593
594 $filters['MAPS DUL']['prefname'] = 'filters_spam_maps_dul';
595 $filters['MAPS DUL']['name'] = 'MAPS Dial-Up List';
596 $filters['MAPS DUL']['link'] = 'http://www.mail-abuse.org/dul/';
597 $filters['MAPS DUL']['dns'] = 'dialups.mail-abuse.org';
598 $filters['MAPS DUL']['result'] = '127.0.0.3';
599 $filters['MAPS DUL']['comment'] =
600 _("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.");
601
602 $filters['MAPS RBLplus-RBL']['prefname'] = 'filters_spam_maps_rblplus_rbl';
603 $filters['MAPS RBLplus-RBL']['name'] = 'MAPS RBL+ RBL List';
604 $filters['MAPS RBLplus-RBL']['link'] = 'http://www.mail-abuse.org/';
605 $filters['MAPS RBLplus-RBL']['dns'] = 'rbl-plus.mail-abuse.org';
606 $filters['MAPS RBLplus-RBL']['result'] = '127.0.0.2';
607 $filters['MAPS RBLplus-RBL']['comment'] =
608 _("COMMERCIAL - RBL+ Blackhole entries.");
609
610 $filters['MAPS RBLplus-RSS']['prefname'] = 'filters_spam_maps_rblplus_rss';
611 $filters['MAPS RBLplus-RSS']['name'] = 'MAPS RBL+ List RSS entries';
612 $filters['MAPS RBLplus-RSS']['link'] = 'http://www.mail-abuse.org/';
613 $filters['MAPS RBLplus-RSS']['dns'] = 'rbl-plus.mail-abuse.org';
614 $filters['MAPS RBLplus-RSS']['result'] = '127.0.0.2';
615 $filters['MAPS RBLplus-RSS']['comment'] =
616 _("COMMERCIAL - RBL+ OpenRelay entries.");
617
618 $filters['MAPS RBLplus-DUL']['prefname'] = 'filters_spam_maps_rblplus_dul';
619 $filters['MAPS RBLplus-DUL']['name'] = 'MAPS RBL+ List DUL entries';
620 $filters['MAPS RBLplus-DUL']['link'] = 'http://www.mail-abuse.org/';
621 $filters['MAPS RBLplus-DUL']['dns'] = 'rbl-plus.mail-abuse.org';
622 $filters['MAPS RBLplus-DUL']['result'] = '127.0.0.3';
623 $filters['MAPS RBLplus-DUL']['comment'] =
624 _("COMMERCIAL - RBL+ Dial-up entries.");
625 }
626
627 $filters['ORDB']['prefname'] = 'filters_spam_ordb';
628 $filters['ORDB']['name'] = 'Open Relay Database List';
629 $filters['ORDB']['link'] = 'http://www.ordb.org/';
630 $filters['ORDB']['dns'] = 'relays.ordb.org';
631 $filters['ORDB']['result'] = '127.0.0.2';
632 $filters['ORDB']['comment'] =
633 _("FREE - ORDB was born when ORBS went off the air. It seems to have fewer false positives than ORBS did though.");
634
635 $filters['FiveTen Direct']['prefname'] = 'filters_spam_fiveten_src';
636 $filters['FiveTen Direct']['name'] = 'Five-Ten-sg.com Direct SPAM Sources';
637 $filters['FiveTen Direct']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
638 $filters['FiveTen Direct']['dns'] = 'blackholes.five-ten-sg.com';
639 $filters['FiveTen Direct']['result'] = '127.0.0.2';
640 $filters['FiveTen Direct']['comment'] =
641 _("FREE - Five-Ten-sg.com - Direct SPAM sources.");
642
643 $filters['FiveTen DUL']['prefname'] = 'filters_spam_fiveten_dul';
644 $filters['FiveTen DUL']['name'] = 'Five-Ten-sg.com DUL Lists';
645 $filters['FiveTen DUL']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
646 $filters['FiveTen DUL']['dns'] = 'blackholes.five-ten-sg.com';
647 $filters['FiveTen DUL']['result'] = '127.0.0.3';
648 $filters['FiveTen DUL']['comment'] =
649 _("FREE - Five-Ten-sg.com - Dial-up lists - includes some DSL IPs.");
650
651 $filters['FiveTen Unc. OptIn']['prefname'] = 'filters_spam_fiveten_oi';
652 $filters['FiveTen Unc. OptIn']['name'] = 'Five-Ten-sg.com Unconfirmed OptIn Lists';
653 $filters['FiveTen Unc. OptIn']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
654 $filters['FiveTen Unc. OptIn']['dns'] = 'blackholes.five-ten-sg.com';
655 $filters['FiveTen Unc. OptIn']['result'] = '127.0.0.4';
656 $filters['FiveTen Unc. OptIn']['comment'] =
657 _("FREE - Five-Ten-sg.com - Bulk mailers that do not use confirmed opt-in.");
658
659 $filters['FiveTen Others']['prefname'] = 'filters_spam_fiveten_oth';
660 $filters['FiveTen Others']['name'] = 'Five-Ten-sg.com Other Misc. Servers';
661 $filters['FiveTen Others']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
662 $filters['FiveTen Others']['dns'] = 'blackholes.five-ten-sg.com';
663 $filters['FiveTen Others']['result'] = '127.0.0.5';
664 $filters['FiveTen Others']['comment'] =
665 _("FREE - Five-Ten-sg.com - Other misc. servers.");
666
667 $filters['FiveTen Single Stage']['prefname'] = 'filters_spam_fiveten_ss';
668 $filters['FiveTen Single Stage']['name'] = 'Five-Ten-sg.com Single Stage Servers';
669 $filters['FiveTen Single Stage']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
670 $filters['FiveTen Single Stage']['dns'] = 'blackholes.five-ten-sg.com';
671 $filters['FiveTen Single Stage']['result'] = '127.0.0.6';
672 $filters['FiveTen Single Stage']['comment'] =
673 _("FREE - Five-Ten-sg.com - Single Stage servers.");
674
675 $filters['FiveTen SPAM Support']['prefname'] = 'filters_spam_fiveten_supp';
676 $filters['FiveTen SPAM Support']['name'] = 'Five-Ten-sg.com SPAM Support Servers';
677 $filters['FiveTen SPAM Support']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
678 $filters['FiveTen SPAM Support']['dns'] = 'blackholes.five-ten-sg.com';
679 $filters['FiveTen SPAM Support']['result'] = '127.0.0.7';
680 $filters['FiveTen SPAM Support']['comment'] =
681 _("FREE - Five-Ten-sg.com - SPAM Support servers.");
682
683 $filters['FiveTen Web forms']['prefname'] = 'filters_spam_fiveten_wf';
684 $filters['FiveTen Web forms']['name'] = 'Five-Ten-sg.com Web Form IPs';
685 $filters['FiveTen Web forms']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
686 $filters['FiveTen Web forms']['dns'] = 'blackholes.five-ten-sg.com';
687 $filters['FiveTen Web forms']['result'] = '127.0.0.8';
688 $filters['FiveTen Web forms']['comment'] =
689 _("FREE - Five-Ten-sg.com - Web Form IPs.");
690
691 $filters['Dorkslayers']['prefname'] = 'filters_spam_dorks';
692 $filters['Dorkslayers']['name'] = 'Dorkslayers Lists';
693 $filters['Dorkslayers']['link'] = 'http://www.dorkslayers.com';
694 $filters['Dorkslayers']['dns'] = 'orbs.dorkslayers.com';
695 $filters['Dorkslayers']['result'] = '127.0.0.2';
696 $filters['Dorkslayers']['comment'] =
697 _("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.");
698
699 $filters['SPAMhaus']['prefname'] = 'filters_spam_spamhaus';
700 $filters['SPAMhaus']['name'] = 'SPAMhaus Lists';
701 $filters['SPAMhaus']['link'] = 'http://www.spamhaus.org';
702 $filters['SPAMhaus']['dns'] = 'sbl.spamhaus.org';
703 $filters['SPAMhaus']['result'] = '127.0.0.6';
704 $filters['SPAMhaus']['comment'] =
705 _("FREE - SPAMhaus - A list of well-known SPAM sources.");
706
707 $filters['SPAMcop']['prefname'] = 'filters_spam_spamcop';
708 $filters['SPAMcop']['name'] = 'SPAM Cop Lists';
709 $filters['SPAMcop']['link'] = 'http://spamcop.net/bl.shtml';
710 $filters['SPAMcop']['dns'] = 'bl.spamcop.net';
711 $filters['SPAMcop']['result'] = '127.0.0.2';
712 $filters['SPAMcop']['comment'] =
713 _("FREE, for now - SpamCop - An interesting solution that lists servers that have a very high spam to legit email ratio (85 percent or more).");
714
715 $filters['dev.null.dk']['prefname'] = 'filters_spam_devnull';
716 $filters['dev.null.dk']['name'] = 'dev.null.dk Lists';
717 $filters['dev.null.dk']['link'] = 'http://dev.null.dk/';
718 $filters['dev.null.dk']['dns'] = 'dev.null.dk';
719 $filters['dev.null.dk']['result'] = '127.0.0.2';
720 $filters['dev.null.dk']['comment'] =
721 _("FREE - dev.null.dk - I don't have any detailed info on this list.");
722
723 $filters['visi.com']['prefname'] = 'filters_spam_visi';
724 $filters['visi.com']['name'] = 'visi.com Relay Stop List';
725 $filters['visi.com']['link'] = 'http://relays.visi.com';
726 $filters['visi.com']['dns'] = 'relays.visi.com';
727 $filters['visi.com']['result'] = '127.0.0.2';
728 $filters['visi.com']['comment'] =
729 _("FREE - visi.com - Relay Stop List. Very conservative OpenRelay List.");
730
731 $filters['ahbl.org Open Relays']['prefname'] = 'filters_spam_2mb_or';
732 $filters['ahbl.org Open Relays']['name'] = 'ahbl.org Open Relays List';
733 $filters['ahbl.org Open Relays']['link'] = 'http://www.ahbl.org/';
734 $filters['ahbl.org Open Relays']['dns'] = 'dnsbl.ahbl.org';
735 $filters['ahbl.org Open Relays']['result'] = '127.0.0.2';
736 $filters['ahbl.org Open Relays']['comment'] =
737 _("FREE - ahbl.org Open Relays - Another list of Open Relays.");
738
739 $filters['ahbl.org SPAM Source']['prefname'] = 'filters_spam_2mb_ss';
740 $filters['ahbl.org SPAM Source']['name'] = 'ahbl.org SPAM Source List';
741 $filters['ahbl.org SPAM Source']['link'] = 'http://www.ahbl.org/';
742 $filters['ahbl.org SPAM Source']['dns'] = 'dnsbl.ahbl.org';
743 $filters['ahbl.org SPAM Source']['result'] = '127.0.0.4';
744 $filters['ahbl.org SPAM Source']['comment'] =
745 _("FREE - ahbl.org SPAM Source - List of Direct SPAM Sources.");
746
747 $filters['ahbl.org SPAM ISPs']['prefname'] = 'filters_spam_2mb_isp';
748 $filters['ahbl.org SPAM ISPs']['name'] = 'ahbl.org SPAM-friendly ISP List';
749 $filters['ahbl.org SPAM ISPs']['link'] = 'http://www.ahbl.org/';
750 $filters['ahbl.org SPAM ISPs']['dns'] = 'dnsbl.ahbl.org';
751 $filters['ahbl.org SPAM ISPs']['result'] = '127.0.0.7';
752 $filters['ahbl.org SPAM ISPs']['comment'] =
753 _("FREE - ahbl.org SPAM ISPs - List of SPAM-friendly ISPs.");
754
755 $filters['Leadmon DUL']['prefname'] = 'filters_spam_lm_dul';
756 $filters['Leadmon DUL']['name'] = 'Leadmon.net DUL List';
757 $filters['Leadmon DUL']['link'] = 'http://www.leadmon.net/spamguard/';
758 $filters['Leadmon DUL']['dns'] = 'spamguard.leadmon.net';
759 $filters['Leadmon DUL']['result'] = '127.0.0.2';
760 $filters['Leadmon DUL']['comment'] =
761 _("FREE - Leadmon DUL - Another list of Dial-up or otherwise dynamically assigned IPs.");
762
763 $filters['Leadmon SPAM Source']['prefname'] = 'filters_spam_lm_ss';
764 $filters['Leadmon SPAM Source']['name'] = 'Leadmon.net SPAM Source List';
765 $filters['Leadmon SPAM Source']['link'] = 'http://www.leadmon.net/spamguard/';
766 $filters['Leadmon SPAM Source']['dns'] = 'spamguard.leadmon.net';
767 $filters['Leadmon SPAM Source']['result'] = '127.0.0.3';
768 $filters['Leadmon SPAM Source']['comment'] =
769 _("FREE - Leadmon SPAM Source - List of IPs Leadmon.net has received SPAM directly from.");
770
771 $filters['Leadmon Bulk Mailers']['prefname'] = 'filters_spam_lm_bm';
772 $filters['Leadmon Bulk Mailers']['name'] = 'Leadmon.net Bulk Mailers List';
773 $filters['Leadmon Bulk Mailers']['link'] = 'http://www.leadmon.net/spamguard/';
774 $filters['Leadmon Bulk Mailers']['dns'] = 'spamguard.leadmon.net';
775 $filters['Leadmon Bulk Mailers']['result'] = '127.0.0.4';
776 $filters['Leadmon Bulk Mailers']['comment'] =
777 _("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.");
778
779 $filters['Leadmon Open Relays']['prefname'] = 'filters_spam_lm_or';
780 $filters['Leadmon Open Relays']['name'] = 'Leadmon.net Open Relays List';
781 $filters['Leadmon Open Relays']['link'] = 'http://www.leadmon.net/spamguard/';
782 $filters['Leadmon Open Relays']['dns'] = 'spamguard.leadmon.net';
783 $filters['Leadmon Open Relays']['result'] = '127.0.0.5';
784 $filters['Leadmon Open Relays']['comment'] =
785 _("FREE - Leadmon Open Relays - Single Stage Open Relays that are not listed on other active RBLs.");
786
787 $filters['Leadmon Multi-stage']['prefname'] = 'filters_spam_lm_ms';
788 $filters['Leadmon Multi-stage']['name'] = 'Leadmon.net Multi-Stage Relay List';
789 $filters['Leadmon Multi-stage']['link'] = 'http://www.leadmon.net/spamguard/';
790 $filters['Leadmon Multi-stage']['dns'] = 'spamguard.leadmon.net';
791 $filters['Leadmon Multi-stage']['result'] = '127.0.0.6';
792 $filters['Leadmon Multi-stage']['comment'] =
793 _("FREE - Leadmon Multi-stage - Multi-Stage Open Relays that are not listed on other active RBLs and that have sent SPAM to Leadmon.net.");
794
795 $filters['Leadmon SpamBlock']['prefname'] = 'filters_spam_lm_sb';
796 $filters['Leadmon SpamBlock']['name'] = 'Leadmon.net SpamBlock Sites List';
797 $filters['Leadmon SpamBlock']['link'] = 'http://www.leadmon.net/spamguard/';
798 $filters['Leadmon SpamBlock']['dns'] = 'spamguard.leadmon.net';
799 $filters['Leadmon SpamBlock']['result'] = '127.0.0.7';
800 $filters['Leadmon SpamBlock']['comment'] =
801 _("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.");
802
803 $filters['NJABL Open Relays']['prefname'] = 'filters_spam_njabl_or';
804 $filters['NJABL Open Relays']['name'] = 'NJABL Open Relay/Direct Spam Source List';
805 $filters['NJABL Open Relays']['link'] = 'http://www.njabl.org/';
806 $filters['NJABL Open Relays']['dns'] = 'dnsbl.njabl.org';
807 $filters['NJABL Open Relays']['result'] = '127.0.0.2';
808 $filters['NJABL Open Relays']['comment'] =
809 _("FREE, for now - Not Just Another Blacklist - Both Open Relays and Direct SPAM Sources.");
810
811 $filters['NJABL DUL']['prefname'] = 'filters_spam_njabl_dul';
812 $filters['NJABL DUL']['name'] = 'NJABL Dial-ups List';
813 $filters['NJABL DUL']['link'] = 'http://www.njabl.org/';
814 $filters['NJABL DUL']['dns'] = 'dnsbl.njabl.org';
815 $filters['NJABL DUL']['result'] = '127.0.0.3';
816 $filters['NJABL DUL']['comment'] =
817 _("FREE, for now - Not Just Another Blacklist - Dial-up IPs.");
818
819 $filters['Conf DSBL.ORG Relay']['prefname'] = 'filters_spam_dsbl_conf_ss';
820 $filters['Conf DSBL.ORG Relay']['name'] = 'DSBL.org Confirmed Relay List';
821 $filters['Conf DSBL.ORG Relay']['link'] = 'http://www.dsbl.org/';
822 $filters['Conf DSBL.ORG Relay']['dns'] = 'list.dsbl.org';
823 $filters['Conf DSBL.ORG Relay']['result'] = '127.0.0.2';
824 $filters['Conf DSBL.ORG Relay']['comment'] =
825 _("FREE - Distributed Sender Boycott List - Confirmed Relays");
826
827 $filters['Conf DSBL.ORG Multi-Stage']['prefname'] = 'filters_spam_dsbl_conf_ms';
828 $filters['Conf DSBL.ORG Multi-Stage']['name'] = 'DSBL.org Confirmed Multi-Stage Relay List';
829 $filters['Conf DSBL.ORG Multi-Stage']['link'] = 'http://www.dsbl.org/';
830 $filters['Conf DSBL.ORG Multi-Stage']['dns'] = 'multihop.dsbl.org';
831 $filters['Conf DSBL.ORG Multi-Stage']['result'] = '127.0.0.2';
832 $filters['Conf DSBL.ORG Multi-Stage']['comment'] =
833 _("FREE - Distributed Sender Boycott List - Confirmed Multi-stage Relays");
834
835 $filters['UN-Conf DSBL.ORG']['prefname'] = 'filters_spam_dsbl_unc';
836 $filters['UN-Conf DSBL.ORG']['name'] = 'DSBL.org UN-Confirmed Relay List';
837 $filters['UN-Conf DSBL.ORG']['link'] = 'http://www.dsbl.org/';
838 $filters['UN-Conf DSBL.ORG']['dns'] = 'unconfirmed.dsbl.org';
839 $filters['UN-Conf DSBL.ORG']['result'] = '127.0.0.2';
840 $filters['UN-Conf DSBL.ORG']['comment'] =
841 _("FREE - Distributed Sender Boycott List - UN-Confirmed Relays");
842
843 foreach ($filters as $Key => $Value) {
844 $filters[$Key]['enabled'] = 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 }
929
930 ?>