a0943ff02999c83e0434eb39928c6bd0b5ee600f
[squirrelmail.git] / plugins / filters / filters.php
1 <?php
2
3 /**
4 * Message and Spam Filter Plugin
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This plugin filters your inbox into different folders based upon given
10 * criteria. It is most useful for people who are subscibed to mailing lists
11 * to help organize their messages. The argument stands that filtering is
12 * not the place of the client, which is why this has been made a plugin for
13 * SquirrelMail. You may be better off using products such as Sieve or
14 * Procmail to do your filtering so it happens even when SquirrelMail isn't
15 * running.
16 *
17 * If you need help with this, or see improvements that can be made, please
18 * email me directly at the address above. I definately welcome suggestions
19 * and comments. This plugin, as is the case with all SquirrelMail plugins,
20 * is not directly supported by the developers. Please come to me off the
21 * mailing list if you have trouble with it.
22 *
23 * Also view plugins/README.plugins for more information.
24 *
25 * $Id$
26 */
27
28
29 function filters_SaveCache () {
30 global $data_dir, $SpamFilters_DNScache;
31
32 if (file_exists($data_dir . "/dnscache")) {
33 $fp = fopen($data_dir . "/dnscache", "r");
34 } else {
35 $fp = false;
36 }
37 if ($fp) {
38 flock($fp,LOCK_EX);
39 } else {
40 $fp = fopen($data_dir . "/dnscache", "w+");
41 fclose($fp);
42 $fp = fopen($data_dir . "/dnscache", "r");
43 flock($fp,LOCK_EX);
44 }
45 $fp1=fopen($data_dir . "/dnscache", "w+");
46
47 foreach ($SpamFilters_DNScache as $Key=> $Value) {
48 $tstr = $Key . ',' . $Value['L'] . ',' . $Value['T'] . "\n";
49 fputs ($fp1, $tstr);
50 }
51 fclose($fp1);
52 flock($fp,LOCK_UN);
53 fclose($fp);
54 }
55
56
57 function filters_LoadCache () {
58 global $data_dir, $SpamFilters_DNScache;
59
60 if (file_exists($data_dir . "/dnscache")) {
61 $SpamFilters_DNScache = array();
62 if ($fp = fopen ($data_dir . "/dnscache", "r")) {
63 flock($fp,LOCK_SH);
64 while ($data=fgetcsv($fp,1024)) {
65 if ($data[2] > time()) {
66 $SpamFilters_DNScache[$data[0]]['L'] = $data[1];
67 $SpamFilters_DNScache[$data[0]]['T'] = $data[2];
68 }
69 }
70
71 flock($fp,LOCK_UN);
72 }
73 }
74 }
75
76 function filters_bulkquery($filters_spam_scan, $filters, $read) {
77 global $SpamFilters_YourHop, $attachment_dir, $username,
78 $SpamFilters_DNScache, $SpamFilters_BulkQuery,
79 $SpamFilters_CacheTTL;
80
81 $IPs = array();
82 $i = 0;
83 while ($i < count($read)) {
84 // EIMS will give funky results
85 $Chunks = explode(' ', $read[$i]);
86 if ($Chunks[0] != '*') {
87 $i ++;
88 continue;
89 }
90 $MsgNum = $Chunks[1];
91
92 $i ++;
93
94 // Look through all of the Received headers for IP addresses
95 // Stop when I get ")" on a line
96 // Stop if I get "*" on a line (don't advance)
97 // and above all, stop if $i is bigger than the total # of lines
98 while (($i < count($read)) &&
99 ($read[$i][0] != ')' && $read[$i][0] != '*' &&
100 $read[$i][0] != "\n")) {
101 // Check to see if this line is the right "Received from" line
102 // to check
103 if (is_int(strpos($read[$i], $SpamFilters_YourHop))) {
104 $read[$i] = ereg_replace('[^0-9\.]', ' ', $read[$i]);
105 $elements = explode(' ', $read[$i]);
106 foreach ($elements as $value) {
107 if ($value != '' &&
108 ereg('[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}',
109 $value, $regs)) {
110 $Chunks = explode('.', $value);
111 $IP = $Chunks[3] . '.' . $Chunks[2] . '.' .
112 $Chunks[1] . '.' . $Chunks[0];
113 foreach ($filters as $key => $value) {
114 if ($filters[$key]['enabled'] &&
115 $filters[$key]['dns']) {
116 if (strlen($SpamFilters_DNScache[$IP.'.'.$filters[$key]['dns']]) == 0) {
117 $IPs[$IP] = true;
118 break;
119 }
120 }
121 }
122 // If we've checked one IP and YourHop is
123 // just a space
124 if ($SpamFilters_YourHop == ' ') {
125 break; // don't check any more
126 }
127 }
128 }
129 }
130 $i ++;
131 }
132 }
133
134 if (count($IPs) > 0) {
135 $rbls = array();
136 foreach ($filters as $key => $value) {
137 if ($filters[$key]['enabled']) {
138 if ($filters[$key]['dns']) {
139 $rbls[$filters[$key]['dns']] = true;
140 }
141 }
142 }
143
144 $bqfil = $attachment_dir . $username . "-bq.in";
145 $fp = fopen($bqfil, "w");
146 fputs ($fp, $SpamFilters_CacheTTL . "\n");
147 foreach ($rbls as $key => $value) {
148 fputs ($fp, "." . $key . "\n");
149 }
150 fputs ($fp, "----------\n");
151 foreach ($IPs as $key => $value) {
152 fputs ($fp, $key . "\n");
153 }
154 fclose ($fp);
155 $bqout = array();
156 exec ($SpamFilters_BulkQuery . " < " . $bqfil, $bqout);
157 foreach ($bqout as $value) {
158 $Chunks = explode(',', $value);
159 $SpamFilters_DNScache[$Chunks[0]]['L'] = $Chunks[1];
160 $SpamFilters_DNScache[$Chunks[0]]['T'] = $Chunks[2] + time();
161 }
162 unlink($bqfil);
163 }
164 }
165
166 function start_filters() {
167 global $mailbox, $username, $key, $imapServerAddress, $imapPort, $imap,
168 $imap_general, $filters, $imap_stream, $imapConnection,
169 $UseSeparateImapConnection, $AllowSpamFilters;
170
171 # if ($mailbox == 'INBOX') {
172 // Detect if we have already connected to IMAP or not.
173 // Also check if we are forced to use a separate IMAP connection
174 if ((!isset($imap_stream) && !isset($imapConnection)) ||
175 $UseSeparateImapConnection) {
176 $stream = sqimap_login($username, $key, $imapServerAddress,
177 $imapPort, 10);
178 $previously_connected = false;
179 } elseif (isset($imapConnection)) {
180 $stream = $imapConnection;
181 $previously_connected = true;
182 } else {
183 $previously_connected = true;
184 $stream = $imap_stream;
185 }
186
187 if (sqimap_get_num_messages($stream, 'INBOX') > 0) {
188 // Filter spam from inbox before we sort them into folders
189 if ($AllowSpamFilters) {
190 spam_filters($stream);
191 }
192
193 // Sort into folders
194 user_filters($stream);
195 }
196
197 if (!$previously_connected) {
198 sqimap_logout($stream);
199 }
200 # }
201 }
202
203
204 function user_filters($imap_stream) {
205 global $data_dir, $username;
206 $filters = load_filters();
207 if (! $filters) return;
208 $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
209
210 sqimap_mailbox_select($imap_stream, 'INBOX');
211 $id = array();
212 // For every rule
213 for ($i=0; $i < count($filters); $i++) {
214 // If it is the "combo" rule
215 if ($filters[$i]['where'] == 'To or Cc') {
216 /*
217 * If it's "TO OR CC", we have to do two searches, one for TO
218 * and the other for CC.
219 */
220 $id = filter_search_and_delete($imap_stream, 'TO',
221 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $id);
222 $id = filter_search_and_delete($imap_stream, 'CC',
223 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $id);
224 } else {
225 /*
226 * If it's a normal TO, CC, SUBJECT, or FROM, then handle it
227 * normally.
228 */
229 $id = filter_search_and_delete($imap_stream, $filters[$i]['where'],
230 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan);
231 }
232 }
233 // Clean out the mailbox whether or not auto_expunge is on
234 // That way it looks like it was redirected properly
235 if (count($id)) {
236 sqimap_mailbox_expunge($imap_stream, 'INBOX');
237 }
238 }
239
240 function filter_search_and_delete($imap, $where, $what, $where_to, $user_scan, $del_id)
241 {
242 global $languages, $squirrelmail_language, $allow_charset_search, $uid_support;
243 if ($user_scan == 'new') {
244 $category = 'UNSEEN';
245 } else {
246 $category = 'ALL';
247 }
248
249 if ($allow_charset_search && isset($languages[$squirrelmail_language]['CHARSET']) &&
250 $languages[$squirrelmail_language]['CHARSET']) {
251 $search_str = "SEARCH CHARSET "
252 . strtoupper($languages[$squirrelmail_language]['CHARSET'])
253 . ' ' . $category . ' ';
254 } else {
255 $search_str = 'SEARCH CHARSET US-ASCII ' . $category . ' ';
256 }
257 if ($where == "Header") {
258 $what = explode(':', $what);
259 $where = trim($where . ' ' . $what[0]);
260 $what = addslashes(trim($what[1]));
261 }
262
263 /* read data back from IMAP */
264 $read = sqimap_run_command($imap, $search_str, true, $reponse, $message, $uid_support);
265
266 // This may have problems with EIMS due to it being goofy
267
268 for ($r=0; $r < count($read) &&
269 substr($read[$r], 0, 8) != '* SEARCH'; $r++) {}
270 if ($response == 'OK') {
271 $ids = explode(' ', $read[$r]);
272 if (sqimap_mailbox_exists($imap, $where_to)) {
273 for ($j=2; $j < count($ids); $j++) {
274 $id = trim($ids[$j]);
275 $del_id[] = $id;
276 sqimap_messages_copy ($imap, $id, $id, $where_to);
277 sqimap_messages_flag ($imap, $id, $id, 'Deleted',false);
278 }
279 }
280 }
281 return $del_id;
282 }
283
284 // These are the spam filters
285 function spam_filters($imap_stream) {
286 global $data_dir, $username, $uid_support;
287 global $SpamFilters_YourHop;
288 global $SpamFilters_DNScache;
289 global $SpamFilters_SharedCache;
290 global $SpamFilters_BulkQuery;
291
292 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
293 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
294 $filters = load_spam_filters();
295
296 if ($SpamFilters_SharedCache) {
297 filters_LoadCache();
298 }
299
300 $run = 0;
301
302 foreach ($filters as $Key=> $Value) {
303 if ($Value['enabled']) {
304 $run ++;
305 }
306 }
307
308 // short-circuit
309 if ($run == 0) {
310 return;
311 }
312
313 sqimap_mailbox_select($imap_stream, 'INBOX');
314
315 // Ask for a big list of all "Received" headers in the inbox with
316 // flags for each message. Kinda big.
317 if ($filters_spam_scan != 'new') {
318 $read = sqimap_run_command($imap_stream, 'FETCH 1:* (FLAGS BODY.PEEK[HEADER.FIELDS ' .
319 '(RECEIVED)])', true, $reponse, $message, $uid_support);
320 } else {
321 $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true, $reponse, $message, $uid_support);
322 if ($response != 'OK' || trim($read[0]) == '* SEARCH') {
323 $read = sqimap_run_command($imap_stream, 'FETCH 1:* (FLAGS BODY.PEEK[HEADER.FIELDS ' .
324 '(RECEIVED)])', true, $reponse, $message, $uid_support);
325 } else {
326 $read[0] = trim($read[0]);
327 $i = 0;
328 $imap_query = $sid.' FETCH ';
329 $Chunks = explode(' ', $read[0]);
330 for ($i=2; $i < (count($Chunks)-1) ; $i++) {
331 $imap_query .= $Chunks[$i].',';
332 }
333 $imap_query .= $Chunks[count($Chunks)-1];
334 $imap_query .= ' (FLAGS BODY.PEEK[HEADER.FIELDS ';
335 $imap_query .= '(RECEIVED)])';//\r\n";
336 $read = sqimap_run_command($imap_stream,$imap_query, true, $reponse, $message, $uid_support);
337 }
338 }
339
340 if (isset($response) && $response != 'OK') {
341 return;
342 }
343
344 if (strlen($SpamFilters_BulkQuery) > 0) {
345 filters_bulkquery($filters_spam_scan, $filters, $read);
346 }
347
348 $i = 0;
349 while ($i < count($read)) {
350 // EIMS will give funky results
351 $Chunks = explode(' ', $read[$i]);
352 if ($Chunks[0] != '*') {
353 $i ++;
354 continue;
355 }
356 $MsgNum = $Chunks[1];
357
358 $IPs = array();
359 $i ++;
360 $IsSpam = 0;
361
362 // Look through all of the Received headers for IP addresses
363 // Stop when I get ")" on a line
364 // Stop if I get "*" on a line (don't advance)
365 // and above all, stop if $i is bigger than the total # of lines
366 while (($i < count($read)) &&
367 ($read[$i][0] != ')' && $read[$i][0] != '*' &&
368 $read[$i][0] != "\n") && (! $IsSpam)) {
369 // Check to see if this line is the right "Received from" line
370 // to check
371 if (is_int(strpos($read[$i], $SpamFilters_YourHop))) {
372
373 // short-circuit and skip work if we don't scan this one
374 $read[$i] = ereg_replace('[^0-9\.]', ' ', $read[$i]);
375 $elements = explode(' ', $read[$i]);
376 foreach ($elements as $value) {
377 if ($value != '' &&
378 ereg('[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}',
379 $value, $regs)) {
380 $Chunks = explode('.', $value);
381 if (filters_spam_check_site($Chunks[0],
382 $Chunks[1], $Chunks[2], $Chunks[3],
383 $filters)) {
384 $IsSpam ++;
385 break; // no sense in checking more IPs
386 }
387 // If we've checked one IP and YourHop is
388 // just a space
389 if ($SpamFilters_YourHop == ' ') {
390 break; // don't check any more
391 }
392 }
393 }
394 }
395 $i ++;
396 }
397
398 // Lookie! It's spam! Yum!
399 if ($IsSpam) {
400 if (sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) {
401 sqimap_messages_copy ($imap_stream, $MsgNum, $MsgNum,
402 $filters_spam_folder);
403 sqimap_messages_flag ($imap_stream, $MsgNum, $MsgNum,
404 'Deleted', false);
405 }
406 } else {
407 }
408 }
409
410 sqimap_mailbox_expunge($imap_stream, 'INBOX');
411
412 if ($SpamFilters_SharedCache) {
413 filters_SaveCache();
414 } else {
415 session_register('SpamFilters_DNScache');
416 }
417
418 }
419
420
421 // Does the loop through each enabled filter for the specified IP address.
422 // IP format: $a.$b.$c.$d
423 function filters_spam_check_site($a, $b, $c, $d, &$filters) {
424 global $SpamFilters_DNScache, $SpamFilters_CacheTTL;
425 foreach ($filters as $key => $value) {
426 if ($filters[$key]['enabled']) {
427 if ($filters[$key]['dns']) {
428 $filter_revip = $d . '.' . $c . '.' . $b . '.' . $a . '.' .
429 $filters[$key]['dns'];
430 if (strlen($SpamFilters_DNScache[$filter_revip]['L']) == 0) {
431 $SpamFilters_DNScache[$filter_revip]['L'] =
432 gethostbyname($filter_revip);
433 $SpamFilters_DNScache[$filter_revip]['T'] =
434 time() + $SpamFilters_CacheTTL;
435 }
436 if ($SpamFilters_DNScache[$filter_revip]['L'] ==
437 $filters[$key]['result']) {
438 return 1;
439 }
440 }
441 }
442 }
443 return 0;
444 }
445
446 function load_filters() {
447 global $data_dir, $username;
448
449 $filters = array();
450 for ($i=0; $fltr = getPref($data_dir, $username, 'filter' . $i); $i++) {
451 $ary = explode(',', $fltr);
452 $filters[$i]['where'] = $ary[0];
453 $filters[$i]['what'] = $ary[1];
454 $filters[$i]['folder'] = $ary[2];
455 }
456 return $filters;
457 }
458
459 function load_spam_filters() {
460 global $data_dir, $username, $SpamFilters_ShowCommercial;
461
462 if ($SpamFilters_ShowCommercial) {
463 $filters['MAPS RBL']['prefname'] = 'filters_spam_maps_rbl';
464 $filters['MAPS RBL']['name'] = 'MAPS Realtime Blackhole List';
465 $filters['MAPS RBL']['link'] = 'http://www.mail-abuse.org/rbl/';
466 $filters['MAPS RBL']['dns'] = 'blackholes.mail-abuse.org';
467 $filters['MAPS RBL']['result'] = '127.0.0.2';
468 $filters['MAPS RBL']['comment'] =
469 _("COMMERCIAL - This list contains servers that are verified spam senders. It is a pretty reliable list to scan spam from.");
470
471 $filters['MAPS RSS']['prefname'] = 'filters_spam_maps_rss';
472 $filters['MAPS RSS']['name'] = 'MAPS Relay Spam Stopper';
473 $filters['MAPS RSS']['link'] = 'http://www.mail-abuse.org/rss/';
474 $filters['MAPS RSS']['dns'] = 'relays.mail-abuse.org';
475 $filters['MAPS RSS']['result'] = '127.0.0.2';
476 $filters['MAPS RSS']['comment'] =
477 _("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.");
478
479 $filters['MAPS DUL']['prefname'] = 'filters_spam_maps_dul';
480 $filters['MAPS DUL']['name'] = 'MAPS Dial-Up List';
481 $filters['MAPS DUL']['link'] = 'http://www.mail-abuse.org/dul/';
482 $filters['MAPS DUL']['dns'] = 'dialups.mail-abuse.org';
483 $filters['MAPS DUL']['result'] = '127.0.0.3';
484 $filters['MAPS DUL']['comment'] =
485 _("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.");
486
487 $filters['MAPS RBLplus-RBL']['prefname'] = 'filters_spam_maps_rblplus_rbl';
488 $filters['MAPS RBLplus-RBL']['name'] = 'MAPS RBL+ RBL List';
489 $filters['MAPS RBLplus-RBL']['link'] = 'http://www.mail-abuse.org/';
490 $filters['MAPS RBLplus-RBL']['dns'] = 'rbl-plus.mail-abuse.org';
491 $filters['MAPS RBLplus-RBL']['result'] = '127.0.0.2';
492 $filters['MAPS RBLplus-RBL']['comment'] =
493 _("COMMERCIAL - RBL+ Blackhole entries.");
494
495 $filters['MAPS RBLplus-RSS']['prefname'] = 'filters_spam_maps_rblplus_rss';
496 $filters['MAPS RBLplus-RSS']['name'] = 'MAPS RBL+ List RSS entries';
497 $filters['MAPS RBLplus-RSS']['link'] = 'http://www.mail-abuse.org/';
498 $filters['MAPS RBLplus-RSS']['dns'] = 'rbl-plus.mail-abuse.org';
499 $filters['MAPS RBLplus-RSS']['result'] = '127.0.0.2';
500 $filters['MAPS RBLplus-RSS']['comment'] =
501 _("COMMERCIAL - RBL+ OpenRelay entries.");
502
503 $filters['MAPS RBLplus-DUL']['prefname'] = 'filters_spam_maps_rblplus_dul';
504 $filters['MAPS RBLplus-DUL']['name'] = 'MAPS RBL+ List DUL entries';
505 $filters['MAPS RBLplus-DUL']['link'] = 'http://www.mail-abuse.org/';
506 $filters['MAPS RBLplus-DUL']['dns'] = 'rbl-plus.mail-abuse.org';
507 $filters['MAPS RBLplus-DUL']['result'] = '127.0.0.3';
508 $filters['MAPS RBLplus-DUL']['comment'] =
509 _("COMMERCIAL - RBL+ Dial-up entries.");
510 }
511
512 $filters['Osirusoft Relays']['prefname'] = 'filters_spam_maps_osirusoft_relay';
513 $filters['Osirusoft Relays']['name'] = 'Osirusoft Relay List';
514 $filters['Osirusoft Relays']['link'] = 'http://relays.osirusoft.com/';
515 $filters['Osirusoft Relays']['dns'] = 'relays.osirusoft.com';
516 $filters['Osirusoft Relays']['result'] = '127.0.0.2';
517 $filters['Osirusoft Relays']['comment'] =
518 _("FREE - Osirusoft Relays - Osirusofts list of verified open relays. Seems to include servers used by abuse@uunet.net auto-replies too.");
519
520 $filters['Osirusoft DUL']['prefname'] = 'filters_spam_maps_osirusoft_dul';
521 $filters['Osirusoft DUL']['name'] = 'Osirusoft Dialup List';
522 $filters['Osirusoft DUL']['link'] = 'http://relays.osirusoft.com/';
523 $filters['Osirusoft DUL']['dns'] = 'relays.osirusoft.com';
524 $filters['Osirusoft DUL']['result'] = '127.0.0.3';
525 $filters['Osirusoft DUL']['comment'] =
526 _("FREE - Osirusoft Dialups - Osirusofts Dialup Spam Source list.");
527
528 $filters['Osirusoft Spam Source']['prefname'] = 'filters_spam_maps_osirusoft_rc';
529 $filters['Osirusoft Spam Source']['name'] = 'Osirusoft Confirmed Spam Source List';
530 $filters['Osirusoft Spam Source']['link'] = 'http://relays.osirusoft.com/';
531 $filters['Osirusoft Spam Source']['dns'] = 'relays.osirusoft.com';
532 $filters['Osirusoft Spam Source']['result'] = '127.0.0.4';
533 $filters['Osirusoft Spam Source']['comment'] =
534 _("FREE - Osirusoft Confirmed Spam Source - Sites that continually spam and have been manually added after multiple nominations. Use with caution. Seems to catch abuse auto-replies from some ISPs.");
535
536 $filters['Osirusoft Smart Host']['prefname'] = 'filters_spam_maps_osirusoft_sh';
537 $filters['Osirusoft Smart Host']['name'] = 'Osirusoft Smart Host List';
538 $filters['Osirusoft Smart Host']['link'] = 'http://relays.osirusoft.com/';
539 $filters['Osirusoft Smart Host']['dns'] = 'relays.osirusoft.com';
540 $filters['Osirusoft Smart Host']['result'] = '127.0.0.5';
541 $filters['Osirusoft Smart Host']['comment'] =
542 _("FREE - Osirusoft Smart Hosts - List of hosts that are secure but relay for other mail servers that are not secure.");
543
544 $filters['Osirusoft SPAMware']['prefname'] = 'filters_spam_maps_osirusoft_ss';
545 $filters['Osirusoft SPAMware']['name'] = 'Osirusoft Spamware Developers List';
546 $filters['Osirusoft SPAMware']['link'] = 'http://relays.osirusoft.com/';
547 $filters['Osirusoft SPAMware']['dns'] = 'relays.osirusoft.com';
548 $filters['Osirusoft SPAMware']['result'] = '127.0.0.6';
549 $filters['Osirusoft SPAMware']['comment'] =
550 _("FREE - Osirusoft Spamware Developers - It is believed that these are IP ranges of companies that are known to produce spam software. Seems to catch abuse auto-replies from some ISPs.");
551
552 $filters['Osirusoft Unc. OptIn']['prefname'] = 'filters_spam_maps_osirusoft_sl';
553 $filters['Osirusoft Unc. OptIn']['name'] = 'Osirusoft Unconfirmed OptIn Server List';
554 $filters['Osirusoft Unc. OptIn']['link'] = 'http://relays.osirusoft.com/';
555 $filters['Osirusoft Unc. OptIn']['dns'] = 'relays.osirusoft.com';
556 $filters['Osirusoft Unc. OptIn']['result'] = '127.0.0.7';
557 $filters['Osirusoft Unc. OptIn']['comment'] =
558 _("FREE - Osirusoft Unconfirmed OptIn Servers - List of listservers that opt users in without confirmation.");
559
560 $filters['Osirusoft Insecure Formmail']['prefname'] = 'filters_spam_maps_osirusoft_fm';
561 $filters['Osirusoft Insecure Formmail']['name'] = 'Osirusoft Insecure formmail.cvi Script List';
562 $filters['Osirusoft Insecure Formmail']['link'] = 'http://relays.osirusoft.com/';
563 $filters['Osirusoft Insecure Formmail']['dns'] = 'relays.osirusoft.com';
564 $filters['Osirusoft Insecure Formmail']['result'] = '127.0.0.8';
565 $filters['Osirusoft Insecure Formmail']['comment'] =
566 _("FREE - Osirusoft Insecure formmail.cgi scripts - List of insecure formmail.cgi scripts. (planned).");
567
568 $filters['Osirusoft Open Proxy']['prefname'] = 'filters_spam_maps_osirusoft_op';
569 $filters['Osirusoft Open Proxy']['name'] = 'Osirusoft Open Proxy Server List';
570 $filters['Osirusoft Open Proxy']['link'] = 'http://relays.osirusoft.com/';
571 $filters['Osirusoft Open Proxy']['dns'] = 'relays.osirusoft.com';
572 $filters['Osirusoft Open Proxy']['result'] = '127.0.0.9';
573 $filters['Osirusoft Open Proxy']['comment'] =
574 _("FREE - Osirusoft Open Proxy Servers - List of Open Proxy Servers.");
575
576 $filters['ORDB']['prefname'] = 'filters_spam_ordb';
577 $filters['ORDB']['name'] = 'Open Relay Database List';
578 $filters['ORDB']['link'] = 'http://www.ordb.org/';
579 $filters['ORDB']['dns'] = 'relays.ordb.org';
580 $filters['ORDB']['result'] = '127.0.0.2';
581 $filters['ORDB']['comment'] =
582 _("FREE - ORDB was born when ORBS went off the air. It seems to have fewer false positives than ORBS did though.");
583
584 $filters['FiveTen Direct']['prefname'] = 'filters_spam_fiveten_src';
585 $filters['FiveTen Direct']['name'] = 'Five-Ten-sg.com Direct SPAM Sources';
586 $filters['FiveTen Direct']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
587 $filters['FiveTen Direct']['dns'] = 'blackholes.five-ten-sg.com';
588 $filters['FiveTen Direct']['result'] = '127.0.0.2';
589 $filters['FiveTen Direct']['comment'] =
590 _("FREE - Five-Ten-sg.com - Direct SPAM sources.");
591
592 $filters['FiveTen DUL']['prefname'] = 'filters_spam_fiveten_dul';
593 $filters['FiveTen DUL']['name'] = 'Five-Ten-sg.com DUL Lists';
594 $filters['FiveTen DUL']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
595 $filters['FiveTen DUL']['dns'] = 'blackholes.five-ten-sg.com';
596 $filters['FiveTen DUL']['result'] = '127.0.0.3';
597 $filters['FiveTen DUL']['comment'] =
598 _("FREE - Five-Ten-sg.com - Dial-up lists - includes some DSL IPs.");
599
600 $filters['FiveTen Unc. OptIn']['prefname'] = 'filters_spam_fiveten_oi';
601 $filters['FiveTen Unc. OptIn']['name'] = 'Five-Ten-sg.com Unconfirmed OptIn Lists';
602 $filters['FiveTen Unc. OptIn']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
603 $filters['FiveTen Unc. OptIn']['dns'] = 'blackholes.five-ten-sg.com';
604 $filters['FiveTen Unc. OptIn']['result'] = '127.0.0.4';
605 $filters['FiveTen Unc. OptIn']['comment'] =
606 _("FREE - Five-Ten-sg.com - Bulk mailers that do not use confirmed opt-in.");
607
608 $filters['FiveTen Others']['prefname'] = 'filters_spam_fiveten_oth';
609 $filters['FiveTen Others']['name'] = 'Five-Ten-sg.com Other Misc. Servers';
610 $filters['FiveTen Others']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
611 $filters['FiveTen Others']['dns'] = 'blackholes.five-ten-sg.com';
612 $filters['FiveTen Others']['result'] = '127.0.0.5';
613 $filters['FiveTen Others']['comment'] =
614 _("FREE - Five-Ten-sg.com - Other misc. servers.");
615
616 $filters['FiveTen Single Stage']['prefname'] = 'filters_spam_fiveten_ss';
617 $filters['FiveTen Single Stage']['name'] = 'Five-Ten-sg.com Single Stage Servers';
618 $filters['FiveTen Single Stage']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
619 $filters['FiveTen Single Stage']['dns'] = 'blackholes.five-ten-sg.com';
620 $filters['FiveTen Single Stage']['result'] = '127.0.0.6';
621 $filters['FiveTen Single Stage']['comment'] =
622 _("FREE - Five-Ten-sg.com - Single Stage servers.");
623
624 $filters['FiveTen SPAM Support']['prefname'] = 'filters_spam_fiveten_supp';
625 $filters['FiveTen SPAM Support']['name'] = 'Five-Ten-sg.com SPAM Support Servers';
626 $filters['FiveTen SPAM Support']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
627 $filters['FiveTen SPAM Support']['dns'] = 'blackholes.five-ten-sg.com';
628 $filters['FiveTen SPAM Support']['result'] = '127.0.0.7';
629 $filters['FiveTen SPAM Support']['comment'] =
630 _("FREE - Five-Ten-sg.com - SPAM Support servers.");
631
632 $filters['FiveTen Web forms']['prefname'] = 'filters_spam_fiveten_wf';
633 $filters['FiveTen Web forms']['name'] = 'Five-Ten-sg.com Web Form IPs';
634 $filters['FiveTen Web forms']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
635 $filters['FiveTen Web forms']['dns'] = 'blackholes.five-ten-sg.com';
636 $filters['FiveTen Web forms']['result'] = '127.0.0.8';
637 $filters['FiveTen Web forms']['comment'] =
638 _("FREE - Five-Ten-sg.com - Web Form IPs.");
639
640 $filters['Dorkslayers']['prefname'] = 'filters_spam_dorks';
641 $filters['Dorkslayers']['name'] = 'Dorkslayers Lists';
642 $filters['Dorkslayers']['link'] = 'http://www.dorkslayers.com';
643 $filters['Dorkslayers']['dns'] = 'orbs.dorkslayers.com';
644 $filters['Dorkslayers']['result'] = '127.0.0.2';
645 $filters['Dorkslayers']['comment'] =
646 _("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.");
647
648 $filters['SPAMhaus']['prefname'] = 'filters_spam_spamhaus';
649 $filters['SPAMhaus']['name'] = 'SPAMhaus Lists';
650 $filters['SPAMhaus']['link'] = 'http://www.spamhaus.org';
651 $filters['SPAMhaus']['dns'] = 'sbl.spamhaus.org';
652 $filters['SPAMhaus']['result'] = '127.0.0.6';
653 $filters['SPAMhaus']['comment'] =
654 _("FREE - SPAMhaus - A list of well-known SPAM sources.");
655
656 $filters['SPAMcop']['prefname'] = 'filters_spam_spamcop';
657 $filters['SPAMcop']['name'] = 'SPAM Cop Lists';
658 $filters['SPAMcop']['link'] = 'http://spamcop.net/bl.shtml';
659 $filters['SPAMcop']['dns'] = 'bl.spamcop.net';
660 $filters['SPAMcop']['result'] = '127.0.0.2';
661 $filters['SPAMcop']['comment'] =
662 _("FREE, for now - SPAMCOP - An interesting solution that lists servers that have a very high spam to legit email ratio (85% or more).");
663
664 $filters['dev.null.dk']['prefname'] = 'filters_spam_devnull';
665 $filters['dev.null.dk']['name'] = 'dev.null.dk Lists';
666 $filters['dev.null.dk']['link'] = 'http://dev.null.dk/';
667 $filters['dev.null.dk']['dns'] = 'dev.null.dk';
668 $filters['dev.null.dk']['result'] = '127.0.0.2';
669 $filters['dev.null.dk']['comment'] =
670 _("FREE - dev.null.dk - I don't have any detailed info on this list.");
671
672 $filters['visi.com']['prefname'] = 'filters_spam_visi';
673 $filters['visi.com']['name'] = 'visi.com Relay Stop List';
674 $filters['visi.com']['link'] = 'http://relays.visi.com';
675 $filters['visi.com']['dns'] = 'relays.visi.com';
676 $filters['visi.com']['result'] = '127.0.0.2';
677 $filters['visi.com']['comment'] =
678 _("FREE - visi.com - Relay Stop List. Very conservative OpenRelay List.");
679
680 $filters['2mbit.com Open Relays']['prefname'] = 'filters_spam_2mb_or';
681 $filters['2mbit.com Open Relays']['name'] = '2mbit.com Open Relays List';
682 $filters['2mbit.com Open Relays']['link'] = 'http://www.2mbit.com/sbl.php';
683 $filters['2mbit.com Open Relays']['dns'] = 'blackholes.2mbit.com';
684 $filters['2mbit.com Open Relays']['result'] = '127.0.0.2';
685 $filters['2mbit.com Open Relays']['comment'] =
686 _("FREE - 2mbit.com Open Relays - Another list of Open Relays.");
687
688 $filters['2mbit.com SPAM Source']['prefname'] = 'filters_spam_2mb_ss';
689 $filters['2mbit.com SPAM Source']['name'] = '2mbit.com SPAM Source List';
690 $filters['2mbit.com SPAM Source']['link'] = 'http://www.2mbit.com/sbl.php';
691 $filters['2mbit.com SPAM Source']['dns'] = 'blackholes.2mbit.com';
692 $filters['2mbit.com SPAM Source']['result'] = '127.0.0.4';
693 $filters['2mbit.com SPAM Source']['comment'] =
694 _("FREE - 2mbit.com SPAM Source - List of Direct SPAM Sources.");
695
696 $filters['2mbit.com SPAM ISPs']['prefname'] = 'filters_spam_2mb_isp';
697 $filters['2mbit.com SPAM ISPs']['name'] = '2mbit.com SPAM-friendly ISP List';
698 $filters['2mbit.com SPAM ISPs']['link'] = 'http://www.2mbit.com/sbl.php';
699 $filters['2mbit.com SPAM ISPs']['dns'] = 'blackholes.2mbit.com';
700 $filters['2mbit.com SPAM ISPs']['result'] = '127.0.0.10';
701 $filters['2mbit.com SPAM ISPs']['comment'] =
702 _("FREE - 2mbit.com SPAM ISPs - List of SPAM-friendly ISPs.");
703
704 $filters['Leadmon DUL']['prefname'] = 'filters_spam_lm_dul';
705 $filters['Leadmon DUL']['name'] = 'Leadmon.net DUL List';
706 $filters['Leadmon DUL']['link'] = 'http://www.leadmon.net/spamguard/';
707 $filters['Leadmon DUL']['dns'] = 'spamguard.leadmon.net';
708 $filters['Leadmon DUL']['result'] = '127.0.0.2';
709 $filters['Leadmon DUL']['comment'] =
710 _("FREE - Leadmon DUL - Another list of Dial-up or otherwise dynamically assigned IPs.");
711
712 $filters['Leadmon SPAM Source']['prefname'] = 'filters_spam_lm_ss';
713 $filters['Leadmon SPAM Source']['name'] = 'Leadmon.net SPAM Source List';
714 $filters['Leadmon SPAM Source']['link'] = 'http://www.leadmon.net/spamguard/';
715 $filters['Leadmon SPAM Source']['dns'] = 'spamguard.leadmon.net';
716 $filters['Leadmon SPAM Source']['result'] = '127.0.0.3';
717 $filters['Leadmon SPAM Source']['comment'] =
718 _("FREE - Leadmon SPAM Source - List of IPs Leadmon.net has received SPAM directly from.");
719
720 $filters['Leadmon Bulk Mailers']['prefname'] = 'filters_spam_lm_bm';
721 $filters['Leadmon Bulk Mailers']['name'] = 'Leadmon.net Bulk Mailers List';
722 $filters['Leadmon Bulk Mailers']['link'] = 'http://www.leadmon.net/spamguard/';
723 $filters['Leadmon Bulk Mailers']['dns'] = 'spamguard.leadmon.net';
724 $filters['Leadmon Bulk Mailers']['result'] = '127.0.0.4';
725 $filters['Leadmon Bulk Mailers']['comment'] =
726 _("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.");
727
728 $filters['Leadmon Open Relays']['prefname'] = 'filters_spam_lm_or';
729 $filters['Leadmon Open Relays']['name'] = 'Leadmon.net Open Relays List';
730 $filters['Leadmon Open Relays']['link'] = 'http://www.leadmon.net/spamguard/';
731 $filters['Leadmon Open Relays']['dns'] = 'spamguard.leadmon.net';
732 $filters['Leadmon Open Relays']['result'] = '127.0.0.5';
733 $filters['Leadmon Open Relays']['comment'] =
734 _("FREE - Leadmon Open Relays - Single Stage Open Relays that are not listed on other active RBLs.");
735
736 $filters['Leadmon Multi-stage']['prefname'] = 'filters_spam_lm_ms';
737 $filters['Leadmon Multi-stage']['name'] = 'Leadmon.net Multi-Stage Relay List';
738 $filters['Leadmon Multi-stage']['link'] = 'http://www.leadmon.net/spamguard/';
739 $filters['Leadmon Multi-stage']['dns'] = 'spamguard.leadmon.net';
740 $filters['Leadmon Multi-stage']['result'] = '127.0.0.6';
741 $filters['Leadmon Multi-stage']['comment'] =
742 _("FREE - Leadmon Multi-stage - Multi-Stage Open Relays that are not listed on other active RBLs and that have sent SPAM to Leadmon.net.");
743
744 $filters['Leadmon SpamBlock']['prefname'] = 'filters_spam_lm_sb';
745 $filters['Leadmon SpamBlock']['name'] = 'Leadmon.net SpamBlock Sites List';
746 $filters['Leadmon SpamBlock']['link'] = 'http://www.leadmon.net/spamguard/';
747 $filters['Leadmon SpamBlock']['dns'] = 'spamguard.leadmon.net';
748 $filters['Leadmon SpamBlock']['result'] = '127.0.0.7';
749 $filters['Leadmon SpamBlock']['comment'] =
750 _("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.");
751
752 $filters['NJABL Open Relays']['prefname'] = 'filters_spam_njabl_or';
753 $filters['NJABL Open Relays']['name'] = 'NJABL Open Relay/Direct Spam Source List';
754 $filters['NJABL Open Relays']['link'] = 'http://www.njabl.org/';
755 $filters['NJABL Open Relays']['dns'] = 'dnsbl.njabl.org';
756 $filters['NJABL Open Relays']['result'] = '127.0.0.2';
757 $filters['NJABL Open Relays']['comment'] =
758 _("FREE, for now - Not Just Another Blacklist - Both Open Relays and Direct SPAM Sources.");
759
760 $filters['NJABL DUL']['prefname'] = 'filters_spam_njabl_dul';
761 $filters['NJABL DUL']['name'] = 'NJABL Dial-ups List';
762 $filters['NJABL DUL']['link'] = 'http://www.njabl.org/';
763 $filters['NJABL DUL']['dns'] = 'dnsbl.njabl.org';
764 $filters['NJABL DUL']['result'] = '127.0.0.3';
765 $filters['NJABL DUL']['comment'] =
766 _("FREE, for now - Not Just Another Blacklist - Dial-up IPs.");
767
768 $filters['Conf DSBL.ORG Relay']['prefname'] = 'filters_spam_dsbl_conf_ss';
769 $filters['Conf DSBL.ORG Relay']['name'] = 'DSBL.org Confirmed Relay List';
770 $filters['Conf DSBL.ORG Relay']['link'] = 'http://www.dsbl.org/';
771 $filters['Conf DSBL.ORG Relay']['dns'] = 'list.dsbl.org';
772 $filters['Conf DSBL.ORG Relay']['result'] = '127.0.0.2';
773 $filters['Conf DSBL.ORG Relay']['comment'] =
774 _("FREE - Distributed Sender Boycott List - Confirmed Relays");
775
776 $filters['Conf DSBL.ORG Multi-Stage']['prefname'] = 'filters_spam_dsbl_conf_ms';
777 $filters['Conf DSBL.ORG Multi-Stage']['name'] = 'DSBL.org Confirmed Multi-Stage Relay List';
778 $filters['Conf DSBL.ORG Multi-Stage']['link'] = 'http://www.dsbl.org/';
779 $filters['Conf DSBL.ORG Multi-Stage']['dns'] = 'multihop.dsbl.org';
780 $filters['Conf DSBL.ORG Multi-Stage']['result'] = '127.0.0.2';
781 $filters['Conf DSBL.ORG Multi-Stage']['comment'] =
782 _("FREE - Distributed Sender Boycott List - Confirmed Multi-stage Relays");
783
784 $filters['UN-Conf DSBL.ORG']['prefname'] = 'filters_spam_dsbl_unc';
785 $filters['UN-Conf DSBL.ORG']['name'] = 'DSBL.org UN-Confirmed Relay List';
786 $filters['UN-Conf DSBL.ORG']['link'] = 'http://www.dsbl.org/';
787 $filters['UN-Conf DSBL.ORG']['dns'] = 'unconfirmed.dsbl.org';
788 $filters['UN-Conf DSBL.ORG']['result'] = '127.0.0.2';
789 $filters['UN-Conf DSBL.ORG']['comment'] =
790 _("FREE - Distributed Sender Boycott List - UN-Confirmed Relays");
791
792 foreach ($filters as $Key => $Value) {
793 $filters[$Key]['enabled'] = getPref($data_dir, $username,
794 $filters[$Key]['prefname']);
795 }
796
797 return $filters;
798 }
799
800 function remove_filter ($id) {
801 global $data_dir, $username;
802
803 while ($nextFilter = getPref($data_dir, $username, 'filter' .
804 ($id + 1))) {
805 setPref($data_dir, $username, 'filter' . $id, $nextFilter);
806 $id ++;
807 }
808
809 removePref($data_dir, $username, 'filter' . $id);
810 }
811
812 function filter_swap($id1, $id2) {
813 global $data_dir, $username;
814
815 $FirstFilter = getPref($data_dir, $username, 'filter' . $id1);
816 $SecondFilter = getPref($data_dir, $username, 'filter' . $id2);
817
818 if ($FirstFilter && $SecondFilter) {
819 setPref($data_dir, $username, 'filter' . $id2, $FirstFilter);
820 setPref($data_dir, $username, 'filter' . $id1, $SecondFilter);
821 }
822 }
823
824 /* This update the filter rules when
825 renaming or deleting folders */
826 function update_for_folder ($args) {
827 $old_folder = $args[0];
828 $new_folder = $args[2];
829 $action = $args[1];
830 global $plugins, $data_dir, $username;
831 $filters = array();
832 $filters = load_filters();
833 $filter_count = count($filters);
834 $p = 0;
835 for ($i=0;$i<$filter_count;$i++) {
836 if (!empty($filters)) {
837 if ($old_folder == $filters[$i]['folder']) {
838 if ($action == 'rename') {
839 $filters[$i]['folder'] = $new_folder;
840 setPref($data_dir, $username, 'filter'.$i,
841 $filters[$i]['where'].','.$filters[$i]['what'].','.$new_folder);
842 }
843 elseif ($action == 'delete') {
844 remove_filter($p);
845 $p = $p-1;
846 }
847 }
848 $p++;
849 }
850 }
851 }
852 ?>