Removed spaces from end of SEARCH string, UW doesn't like them.
[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, $id);
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 &&
250 isset($languages[$squirrelmail_language]['CHARSET']) &&
251 $languages[$squirrelmail_language]['CHARSET']) {
252 $search_str = 'SEARCH CHARSET '
253 . strtoupper($languages[$squirrelmail_language]['CHARSET'])
254 . ' ' . $category;
255 } else {
256 $search_str = 'SEARCH CHARSET US-ASCII ' . $category;
257 }
258 if ($where == "Header") {
259 $what = explode(':', $what);
260 $where = trim($where . ' ' . $what[0]);
261 $what = addslashes(trim($what[1]));
262 }
263
264 /* read data back from IMAP */
265 $read = sqimap_run_command($imap, $search_str, true, $reponse, $message, $uid_support);
266
267 // This may have problems with EIMS due to it being goofy
268
269 for ($r=0; $r < count($read) &&
270 substr($read[$r], 0, 8) != '* SEARCH'; $r++) {}
271 if ($response == 'OK') {
272 $ids = explode(' ', $read[$r]);
273 if (sqimap_mailbox_exists($imap, $where_to)) {
274 for ($j=2; $j < count($ids); $j++) {
275 $id = trim($ids[$j]);
276 $del_id[] = $id;
277 sqimap_messages_copy ($imap, $id, $id, $where_to);
278 sqimap_messages_flag ($imap, $id, $id, 'Deleted',false);
279 }
280 }
281 }
282 return $del_id;
283 }
284
285 // These are the spam filters
286 function spam_filters($imap_stream) {
287 global $data_dir, $username, $uid_support;
288 global $SpamFilters_YourHop;
289 global $SpamFilters_DNScache;
290 global $SpamFilters_SharedCache;
291 global $SpamFilters_BulkQuery;
292
293 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
294 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
295 $filters = load_spam_filters();
296
297 if ($SpamFilters_SharedCache) {
298 filters_LoadCache();
299 }
300
301 $run = 0;
302
303 foreach ($filters as $Key=> $Value) {
304 if ($Value['enabled']) {
305 $run ++;
306 }
307 }
308
309 // short-circuit
310 if ($run == 0) {
311 return;
312 }
313
314 sqimap_mailbox_select($imap_stream, 'INBOX');
315
316 // Ask for a big list of all "Received" headers in the inbox with
317 // flags for each message. Kinda big.
318 if ($filters_spam_scan != 'new') {
319 $read = sqimap_run_command($imap_stream, 'FETCH 1:* (FLAGS BODY.PEEK[HEADER.FIELDS ' .
320 '(RECEIVED)])', true, $reponse, $message, $uid_support);
321 } else {
322 $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true, $reponse, $message, $uid_support);
323 if ($response != 'OK' || trim($read[0]) == '* SEARCH') {
324 $read = sqimap_run_command($imap_stream, 'FETCH 1:* (FLAGS BODY.PEEK[HEADER.FIELDS ' .
325 '(RECEIVED)])', true, $reponse, $message, $uid_support);
326 } else {
327 $read[0] = trim($read[0]);
328 $i = 0;
329 $imap_query = $sid.' FETCH ';
330 $Chunks = explode(' ', $read[0]);
331 for ($i=2; $i < (count($Chunks)-1) ; $i++) {
332 $imap_query .= $Chunks[$i].',';
333 }
334 $imap_query .= $Chunks[count($Chunks)-1];
335 $imap_query .= ' (FLAGS BODY.PEEK[HEADER.FIELDS ';
336 $imap_query .= '(RECEIVED)])';//\r\n";
337 $read = sqimap_run_command($imap_stream,$imap_query, true, $reponse, $message, $uid_support);
338 }
339 }
340
341 if (isset($response) && $response != 'OK') {
342 return;
343 }
344
345 if (strlen($SpamFilters_BulkQuery) > 0) {
346 filters_bulkquery($filters_spam_scan, $filters, $read);
347 }
348
349 $i = 0;
350 while ($i < count($read)) {
351 // EIMS will give funky results
352 $Chunks = explode(' ', $read[$i]);
353 if ($Chunks[0] != '*') {
354 $i ++;
355 continue;
356 }
357 $MsgNum = $Chunks[1];
358
359 $IPs = array();
360 $i ++;
361 $IsSpam = 0;
362
363 // Look through all of the Received headers for IP addresses
364 // Stop when I get ")" on a line
365 // Stop if I get "*" on a line (don't advance)
366 // and above all, stop if $i is bigger than the total # of lines
367 while (($i < count($read)) &&
368 ($read[$i][0] != ')' && $read[$i][0] != '*' &&
369 $read[$i][0] != "\n") && (! $IsSpam)) {
370 // Check to see if this line is the right "Received from" line
371 // to check
372 if (is_int(strpos($read[$i], $SpamFilters_YourHop))) {
373
374 // short-circuit and skip work if we don't scan this one
375 $read[$i] = ereg_replace('[^0-9\.]', ' ', $read[$i]);
376 $elements = explode(' ', $read[$i]);
377 foreach ($elements as $value) {
378 if ($value != '' &&
379 ereg('[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}',
380 $value, $regs)) {
381 $Chunks = explode('.', $value);
382 if (filters_spam_check_site($Chunks[0],
383 $Chunks[1], $Chunks[2], $Chunks[3],
384 $filters)) {
385 $IsSpam ++;
386 break; // no sense in checking more IPs
387 }
388 // If we've checked one IP and YourHop is
389 // just a space
390 if ($SpamFilters_YourHop == ' ') {
391 break; // don't check any more
392 }
393 }
394 }
395 }
396 $i ++;
397 }
398
399 // Lookie! It's spam! Yum!
400 if ($IsSpam) {
401 if (sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) {
402 sqimap_messages_copy ($imap_stream, $MsgNum, $MsgNum,
403 $filters_spam_folder);
404 sqimap_messages_flag ($imap_stream, $MsgNum, $MsgNum,
405 'Deleted', false);
406 }
407 } else {
408 }
409 }
410
411 sqimap_mailbox_expunge($imap_stream, 'INBOX');
412
413 if ($SpamFilters_SharedCache) {
414 filters_SaveCache();
415 } else {
416 session_register('SpamFilters_DNScache');
417 }
418
419 }
420
421
422 // Does the loop through each enabled filter for the specified IP address.
423 // IP format: $a.$b.$c.$d
424 function filters_spam_check_site($a, $b, $c, $d, &$filters) {
425 global $SpamFilters_DNScache, $SpamFilters_CacheTTL;
426 foreach ($filters as $key => $value) {
427 if ($filters[$key]['enabled']) {
428 if ($filters[$key]['dns']) {
429 $filter_revip = $d . '.' . $c . '.' . $b . '.' . $a . '.' .
430 $filters[$key]['dns'];
431 if (strlen($SpamFilters_DNScache[$filter_revip]['L']) == 0) {
432 $SpamFilters_DNScache[$filter_revip]['L'] =
433 gethostbyname($filter_revip);
434 $SpamFilters_DNScache[$filter_revip]['T'] =
435 time() + $SpamFilters_CacheTTL;
436 }
437 if ($SpamFilters_DNScache[$filter_revip]['L'] ==
438 $filters[$key]['result']) {
439 return 1;
440 }
441 }
442 }
443 }
444 return 0;
445 }
446
447 function load_filters() {
448 global $data_dir, $username;
449
450 $filters = array();
451 for ($i=0; $fltr = getPref($data_dir, $username, 'filter' . $i); $i++) {
452 $ary = explode(',', $fltr);
453 $filters[$i]['where'] = $ary[0];
454 $filters[$i]['what'] = $ary[1];
455 $filters[$i]['folder'] = $ary[2];
456 }
457 return $filters;
458 }
459
460 function load_spam_filters() {
461 global $data_dir, $username, $SpamFilters_ShowCommercial;
462
463 if ($SpamFilters_ShowCommercial) {
464 $filters['MAPS RBL']['prefname'] = 'filters_spam_maps_rbl';
465 $filters['MAPS RBL']['name'] = 'MAPS Realtime Blackhole List';
466 $filters['MAPS RBL']['link'] = 'http://www.mail-abuse.org/rbl/';
467 $filters['MAPS RBL']['dns'] = 'blackholes.mail-abuse.org';
468 $filters['MAPS RBL']['result'] = '127.0.0.2';
469 $filters['MAPS RBL']['comment'] =
470 _("COMMERCIAL - This list contains servers that are verified spam senders. It is a pretty reliable list to scan spam from.");
471
472 $filters['MAPS RSS']['prefname'] = 'filters_spam_maps_rss';
473 $filters['MAPS RSS']['name'] = 'MAPS Relay Spam Stopper';
474 $filters['MAPS RSS']['link'] = 'http://www.mail-abuse.org/rss/';
475 $filters['MAPS RSS']['dns'] = 'relays.mail-abuse.org';
476 $filters['MAPS RSS']['result'] = '127.0.0.2';
477 $filters['MAPS RSS']['comment'] =
478 _("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.");
479
480 $filters['MAPS DUL']['prefname'] = 'filters_spam_maps_dul';
481 $filters['MAPS DUL']['name'] = 'MAPS Dial-Up List';
482 $filters['MAPS DUL']['link'] = 'http://www.mail-abuse.org/dul/';
483 $filters['MAPS DUL']['dns'] = 'dialups.mail-abuse.org';
484 $filters['MAPS DUL']['result'] = '127.0.0.3';
485 $filters['MAPS DUL']['comment'] =
486 _("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.");
487
488 $filters['MAPS RBLplus-RBL']['prefname'] = 'filters_spam_maps_rblplus_rbl';
489 $filters['MAPS RBLplus-RBL']['name'] = 'MAPS RBL+ RBL List';
490 $filters['MAPS RBLplus-RBL']['link'] = 'http://www.mail-abuse.org/';
491 $filters['MAPS RBLplus-RBL']['dns'] = 'rbl-plus.mail-abuse.org';
492 $filters['MAPS RBLplus-RBL']['result'] = '127.0.0.2';
493 $filters['MAPS RBLplus-RBL']['comment'] =
494 _("COMMERCIAL - RBL+ Blackhole entries.");
495
496 $filters['MAPS RBLplus-RSS']['prefname'] = 'filters_spam_maps_rblplus_rss';
497 $filters['MAPS RBLplus-RSS']['name'] = 'MAPS RBL+ List RSS entries';
498 $filters['MAPS RBLplus-RSS']['link'] = 'http://www.mail-abuse.org/';
499 $filters['MAPS RBLplus-RSS']['dns'] = 'rbl-plus.mail-abuse.org';
500 $filters['MAPS RBLplus-RSS']['result'] = '127.0.0.2';
501 $filters['MAPS RBLplus-RSS']['comment'] =
502 _("COMMERCIAL - RBL+ OpenRelay entries.");
503
504 $filters['MAPS RBLplus-DUL']['prefname'] = 'filters_spam_maps_rblplus_dul';
505 $filters['MAPS RBLplus-DUL']['name'] = 'MAPS RBL+ List DUL entries';
506 $filters['MAPS RBLplus-DUL']['link'] = 'http://www.mail-abuse.org/';
507 $filters['MAPS RBLplus-DUL']['dns'] = 'rbl-plus.mail-abuse.org';
508 $filters['MAPS RBLplus-DUL']['result'] = '127.0.0.3';
509 $filters['MAPS RBLplus-DUL']['comment'] =
510 _("COMMERCIAL - RBL+ Dial-up entries.");
511 }
512
513 $filters['Osirusoft Relays']['prefname'] = 'filters_spam_maps_osirusoft_relay';
514 $filters['Osirusoft Relays']['name'] = 'Osirusoft Relay List';
515 $filters['Osirusoft Relays']['link'] = 'http://relays.osirusoft.com/';
516 $filters['Osirusoft Relays']['dns'] = 'relays.osirusoft.com';
517 $filters['Osirusoft Relays']['result'] = '127.0.0.2';
518 $filters['Osirusoft Relays']['comment'] =
519 _("FREE - Osirusoft Relays - Osirusofts list of verified open relays. Seems to include servers used by abuse@uunet.net auto-replies too.");
520
521 $filters['Osirusoft DUL']['prefname'] = 'filters_spam_maps_osirusoft_dul';
522 $filters['Osirusoft DUL']['name'] = 'Osirusoft Dialup List';
523 $filters['Osirusoft DUL']['link'] = 'http://relays.osirusoft.com/';
524 $filters['Osirusoft DUL']['dns'] = 'relays.osirusoft.com';
525 $filters['Osirusoft DUL']['result'] = '127.0.0.3';
526 $filters['Osirusoft DUL']['comment'] =
527 _("FREE - Osirusoft Dialups - Osirusofts Dialup Spam Source list.");
528
529 $filters['Osirusoft Spam Source']['prefname'] = 'filters_spam_maps_osirusoft_rc';
530 $filters['Osirusoft Spam Source']['name'] = 'Osirusoft Confirmed Spam Source List';
531 $filters['Osirusoft Spam Source']['link'] = 'http://relays.osirusoft.com/';
532 $filters['Osirusoft Spam Source']['dns'] = 'relays.osirusoft.com';
533 $filters['Osirusoft Spam Source']['result'] = '127.0.0.4';
534 $filters['Osirusoft Spam Source']['comment'] =
535 _("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.");
536
537 $filters['Osirusoft Smart Host']['prefname'] = 'filters_spam_maps_osirusoft_sh';
538 $filters['Osirusoft Smart Host']['name'] = 'Osirusoft Smart Host List';
539 $filters['Osirusoft Smart Host']['link'] = 'http://relays.osirusoft.com/';
540 $filters['Osirusoft Smart Host']['dns'] = 'relays.osirusoft.com';
541 $filters['Osirusoft Smart Host']['result'] = '127.0.0.5';
542 $filters['Osirusoft Smart Host']['comment'] =
543 _("FREE - Osirusoft Smart Hosts - List of hosts that are secure but relay for other mail servers that are not secure.");
544
545 $filters['Osirusoft SPAMware']['prefname'] = 'filters_spam_maps_osirusoft_ss';
546 $filters['Osirusoft SPAMware']['name'] = 'Osirusoft Spamware Developers List';
547 $filters['Osirusoft SPAMware']['link'] = 'http://relays.osirusoft.com/';
548 $filters['Osirusoft SPAMware']['dns'] = 'relays.osirusoft.com';
549 $filters['Osirusoft SPAMware']['result'] = '127.0.0.6';
550 $filters['Osirusoft SPAMware']['comment'] =
551 _("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.");
552
553 $filters['Osirusoft Unc. OptIn']['prefname'] = 'filters_spam_maps_osirusoft_sl';
554 $filters['Osirusoft Unc. OptIn']['name'] = 'Osirusoft Unconfirmed OptIn Server List';
555 $filters['Osirusoft Unc. OptIn']['link'] = 'http://relays.osirusoft.com/';
556 $filters['Osirusoft Unc. OptIn']['dns'] = 'relays.osirusoft.com';
557 $filters['Osirusoft Unc. OptIn']['result'] = '127.0.0.7';
558 $filters['Osirusoft Unc. OptIn']['comment'] =
559 _("FREE - Osirusoft Unconfirmed OptIn Servers - List of listservers that opt users in without confirmation.");
560
561 $filters['Osirusoft Insecure Formmail']['prefname'] = 'filters_spam_maps_osirusoft_fm';
562 $filters['Osirusoft Insecure Formmail']['name'] = 'Osirusoft Insecure formmail.cvi Script List';
563 $filters['Osirusoft Insecure Formmail']['link'] = 'http://relays.osirusoft.com/';
564 $filters['Osirusoft Insecure Formmail']['dns'] = 'relays.osirusoft.com';
565 $filters['Osirusoft Insecure Formmail']['result'] = '127.0.0.8';
566 $filters['Osirusoft Insecure Formmail']['comment'] =
567 _("FREE - Osirusoft Insecure formmail.cgi scripts - List of insecure formmail.cgi scripts. (planned).");
568
569 $filters['Osirusoft Open Proxy']['prefname'] = 'filters_spam_maps_osirusoft_op';
570 $filters['Osirusoft Open Proxy']['name'] = 'Osirusoft Open Proxy Server List';
571 $filters['Osirusoft Open Proxy']['link'] = 'http://relays.osirusoft.com/';
572 $filters['Osirusoft Open Proxy']['dns'] = 'relays.osirusoft.com';
573 $filters['Osirusoft Open Proxy']['result'] = '127.0.0.9';
574 $filters['Osirusoft Open Proxy']['comment'] =
575 _("FREE - Osirusoft Open Proxy Servers - List of Open Proxy Servers.");
576
577 $filters['ORDB']['prefname'] = 'filters_spam_ordb';
578 $filters['ORDB']['name'] = 'Open Relay Database List';
579 $filters['ORDB']['link'] = 'http://www.ordb.org/';
580 $filters['ORDB']['dns'] = 'relays.ordb.org';
581 $filters['ORDB']['result'] = '127.0.0.2';
582 $filters['ORDB']['comment'] =
583 _("FREE - ORDB was born when ORBS went off the air. It seems to have fewer false positives than ORBS did though.");
584
585 $filters['FiveTen Direct']['prefname'] = 'filters_spam_fiveten_src';
586 $filters['FiveTen Direct']['name'] = 'Five-Ten-sg.com Direct SPAM Sources';
587 $filters['FiveTen Direct']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
588 $filters['FiveTen Direct']['dns'] = 'blackholes.five-ten-sg.com';
589 $filters['FiveTen Direct']['result'] = '127.0.0.2';
590 $filters['FiveTen Direct']['comment'] =
591 _("FREE - Five-Ten-sg.com - Direct SPAM sources.");
592
593 $filters['FiveTen DUL']['prefname'] = 'filters_spam_fiveten_dul';
594 $filters['FiveTen DUL']['name'] = 'Five-Ten-sg.com DUL Lists';
595 $filters['FiveTen DUL']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
596 $filters['FiveTen DUL']['dns'] = 'blackholes.five-ten-sg.com';
597 $filters['FiveTen DUL']['result'] = '127.0.0.3';
598 $filters['FiveTen DUL']['comment'] =
599 _("FREE - Five-Ten-sg.com - Dial-up lists - includes some DSL IPs.");
600
601 $filters['FiveTen Unc. OptIn']['prefname'] = 'filters_spam_fiveten_oi';
602 $filters['FiveTen Unc. OptIn']['name'] = 'Five-Ten-sg.com Unconfirmed OptIn Lists';
603 $filters['FiveTen Unc. OptIn']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
604 $filters['FiveTen Unc. OptIn']['dns'] = 'blackholes.five-ten-sg.com';
605 $filters['FiveTen Unc. OptIn']['result'] = '127.0.0.4';
606 $filters['FiveTen Unc. OptIn']['comment'] =
607 _("FREE - Five-Ten-sg.com - Bulk mailers that do not use confirmed opt-in.");
608
609 $filters['FiveTen Others']['prefname'] = 'filters_spam_fiveten_oth';
610 $filters['FiveTen Others']['name'] = 'Five-Ten-sg.com Other Misc. Servers';
611 $filters['FiveTen Others']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
612 $filters['FiveTen Others']['dns'] = 'blackholes.five-ten-sg.com';
613 $filters['FiveTen Others']['result'] = '127.0.0.5';
614 $filters['FiveTen Others']['comment'] =
615 _("FREE - Five-Ten-sg.com - Other misc. servers.");
616
617 $filters['FiveTen Single Stage']['prefname'] = 'filters_spam_fiveten_ss';
618 $filters['FiveTen Single Stage']['name'] = 'Five-Ten-sg.com Single Stage Servers';
619 $filters['FiveTen Single Stage']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
620 $filters['FiveTen Single Stage']['dns'] = 'blackholes.five-ten-sg.com';
621 $filters['FiveTen Single Stage']['result'] = '127.0.0.6';
622 $filters['FiveTen Single Stage']['comment'] =
623 _("FREE - Five-Ten-sg.com - Single Stage servers.");
624
625 $filters['FiveTen SPAM Support']['prefname'] = 'filters_spam_fiveten_supp';
626 $filters['FiveTen SPAM Support']['name'] = 'Five-Ten-sg.com SPAM Support Servers';
627 $filters['FiveTen SPAM Support']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
628 $filters['FiveTen SPAM Support']['dns'] = 'blackholes.five-ten-sg.com';
629 $filters['FiveTen SPAM Support']['result'] = '127.0.0.7';
630 $filters['FiveTen SPAM Support']['comment'] =
631 _("FREE - Five-Ten-sg.com - SPAM Support servers.");
632
633 $filters['FiveTen Web forms']['prefname'] = 'filters_spam_fiveten_wf';
634 $filters['FiveTen Web forms']['name'] = 'Five-Ten-sg.com Web Form IPs';
635 $filters['FiveTen Web forms']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
636 $filters['FiveTen Web forms']['dns'] = 'blackholes.five-ten-sg.com';
637 $filters['FiveTen Web forms']['result'] = '127.0.0.8';
638 $filters['FiveTen Web forms']['comment'] =
639 _("FREE - Five-Ten-sg.com - Web Form IPs.");
640
641 $filters['Dorkslayers']['prefname'] = 'filters_spam_dorks';
642 $filters['Dorkslayers']['name'] = 'Dorkslayers Lists';
643 $filters['Dorkslayers']['link'] = 'http://www.dorkslayers.com';
644 $filters['Dorkslayers']['dns'] = 'orbs.dorkslayers.com';
645 $filters['Dorkslayers']['result'] = '127.0.0.2';
646 $filters['Dorkslayers']['comment'] =
647 _("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.");
648
649 $filters['SPAMhaus']['prefname'] = 'filters_spam_spamhaus';
650 $filters['SPAMhaus']['name'] = 'SPAMhaus Lists';
651 $filters['SPAMhaus']['link'] = 'http://www.spamhaus.org';
652 $filters['SPAMhaus']['dns'] = 'sbl.spamhaus.org';
653 $filters['SPAMhaus']['result'] = '127.0.0.6';
654 $filters['SPAMhaus']['comment'] =
655 _("FREE - SPAMhaus - A list of well-known SPAM sources.");
656
657 $filters['SPAMcop']['prefname'] = 'filters_spam_spamcop';
658 $filters['SPAMcop']['name'] = 'SPAM Cop Lists';
659 $filters['SPAMcop']['link'] = 'http://spamcop.net/bl.shtml';
660 $filters['SPAMcop']['dns'] = 'bl.spamcop.net';
661 $filters['SPAMcop']['result'] = '127.0.0.2';
662 $filters['SPAMcop']['comment'] =
663 _("FREE, for now - SPAMCOP - An interesting solution that lists servers that have a very high spam to legit email ratio (85% or more).");
664
665 $filters['dev.null.dk']['prefname'] = 'filters_spam_devnull';
666 $filters['dev.null.dk']['name'] = 'dev.null.dk Lists';
667 $filters['dev.null.dk']['link'] = 'http://dev.null.dk/';
668 $filters['dev.null.dk']['dns'] = 'dev.null.dk';
669 $filters['dev.null.dk']['result'] = '127.0.0.2';
670 $filters['dev.null.dk']['comment'] =
671 _("FREE - dev.null.dk - I don't have any detailed info on this list.");
672
673 $filters['visi.com']['prefname'] = 'filters_spam_visi';
674 $filters['visi.com']['name'] = 'visi.com Relay Stop List';
675 $filters['visi.com']['link'] = 'http://relays.visi.com';
676 $filters['visi.com']['dns'] = 'relays.visi.com';
677 $filters['visi.com']['result'] = '127.0.0.2';
678 $filters['visi.com']['comment'] =
679 _("FREE - visi.com - Relay Stop List. Very conservative OpenRelay List.");
680
681 $filters['2mbit.com Open Relays']['prefname'] = 'filters_spam_2mb_or';
682 $filters['2mbit.com Open Relays']['name'] = '2mbit.com Open Relays List';
683 $filters['2mbit.com Open Relays']['link'] = 'http://www.2mbit.com/sbl.php';
684 $filters['2mbit.com Open Relays']['dns'] = 'blackholes.2mbit.com';
685 $filters['2mbit.com Open Relays']['result'] = '127.0.0.2';
686 $filters['2mbit.com Open Relays']['comment'] =
687 _("FREE - 2mbit.com Open Relays - Another list of Open Relays.");
688
689 $filters['2mbit.com SPAM Source']['prefname'] = 'filters_spam_2mb_ss';
690 $filters['2mbit.com SPAM Source']['name'] = '2mbit.com SPAM Source List';
691 $filters['2mbit.com SPAM Source']['link'] = 'http://www.2mbit.com/sbl.php';
692 $filters['2mbit.com SPAM Source']['dns'] = 'blackholes.2mbit.com';
693 $filters['2mbit.com SPAM Source']['result'] = '127.0.0.4';
694 $filters['2mbit.com SPAM Source']['comment'] =
695 _("FREE - 2mbit.com SPAM Source - List of Direct SPAM Sources.");
696
697 $filters['2mbit.com SPAM ISPs']['prefname'] = 'filters_spam_2mb_isp';
698 $filters['2mbit.com SPAM ISPs']['name'] = '2mbit.com SPAM-friendly ISP List';
699 $filters['2mbit.com SPAM ISPs']['link'] = 'http://www.2mbit.com/sbl.php';
700 $filters['2mbit.com SPAM ISPs']['dns'] = 'blackholes.2mbit.com';
701 $filters['2mbit.com SPAM ISPs']['result'] = '127.0.0.10';
702 $filters['2mbit.com SPAM ISPs']['comment'] =
703 _("FREE - 2mbit.com SPAM ISPs - List of SPAM-friendly ISPs.");
704
705 $filters['Leadmon DUL']['prefname'] = 'filters_spam_lm_dul';
706 $filters['Leadmon DUL']['name'] = 'Leadmon.net DUL List';
707 $filters['Leadmon DUL']['link'] = 'http://www.leadmon.net/spamguard/';
708 $filters['Leadmon DUL']['dns'] = 'spamguard.leadmon.net';
709 $filters['Leadmon DUL']['result'] = '127.0.0.2';
710 $filters['Leadmon DUL']['comment'] =
711 _("FREE - Leadmon DUL - Another list of Dial-up or otherwise dynamically assigned IPs.");
712
713 $filters['Leadmon SPAM Source']['prefname'] = 'filters_spam_lm_ss';
714 $filters['Leadmon SPAM Source']['name'] = 'Leadmon.net SPAM Source List';
715 $filters['Leadmon SPAM Source']['link'] = 'http://www.leadmon.net/spamguard/';
716 $filters['Leadmon SPAM Source']['dns'] = 'spamguard.leadmon.net';
717 $filters['Leadmon SPAM Source']['result'] = '127.0.0.3';
718 $filters['Leadmon SPAM Source']['comment'] =
719 _("FREE - Leadmon SPAM Source - List of IPs Leadmon.net has received SPAM directly from.");
720
721 $filters['Leadmon Bulk Mailers']['prefname'] = 'filters_spam_lm_bm';
722 $filters['Leadmon Bulk Mailers']['name'] = 'Leadmon.net Bulk Mailers List';
723 $filters['Leadmon Bulk Mailers']['link'] = 'http://www.leadmon.net/spamguard/';
724 $filters['Leadmon Bulk Mailers']['dns'] = 'spamguard.leadmon.net';
725 $filters['Leadmon Bulk Mailers']['result'] = '127.0.0.4';
726 $filters['Leadmon Bulk Mailers']['comment'] =
727 _("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.");
728
729 $filters['Leadmon Open Relays']['prefname'] = 'filters_spam_lm_or';
730 $filters['Leadmon Open Relays']['name'] = 'Leadmon.net Open Relays List';
731 $filters['Leadmon Open Relays']['link'] = 'http://www.leadmon.net/spamguard/';
732 $filters['Leadmon Open Relays']['dns'] = 'spamguard.leadmon.net';
733 $filters['Leadmon Open Relays']['result'] = '127.0.0.5';
734 $filters['Leadmon Open Relays']['comment'] =
735 _("FREE - Leadmon Open Relays - Single Stage Open Relays that are not listed on other active RBLs.");
736
737 $filters['Leadmon Multi-stage']['prefname'] = 'filters_spam_lm_ms';
738 $filters['Leadmon Multi-stage']['name'] = 'Leadmon.net Multi-Stage Relay List';
739 $filters['Leadmon Multi-stage']['link'] = 'http://www.leadmon.net/spamguard/';
740 $filters['Leadmon Multi-stage']['dns'] = 'spamguard.leadmon.net';
741 $filters['Leadmon Multi-stage']['result'] = '127.0.0.6';
742 $filters['Leadmon Multi-stage']['comment'] =
743 _("FREE - Leadmon Multi-stage - Multi-Stage Open Relays that are not listed on other active RBLs and that have sent SPAM to Leadmon.net.");
744
745 $filters['Leadmon SpamBlock']['prefname'] = 'filters_spam_lm_sb';
746 $filters['Leadmon SpamBlock']['name'] = 'Leadmon.net SpamBlock Sites List';
747 $filters['Leadmon SpamBlock']['link'] = 'http://www.leadmon.net/spamguard/';
748 $filters['Leadmon SpamBlock']['dns'] = 'spamguard.leadmon.net';
749 $filters['Leadmon SpamBlock']['result'] = '127.0.0.7';
750 $filters['Leadmon SpamBlock']['comment'] =
751 _("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.");
752
753 $filters['NJABL Open Relays']['prefname'] = 'filters_spam_njabl_or';
754 $filters['NJABL Open Relays']['name'] = 'NJABL Open Relay/Direct Spam Source List';
755 $filters['NJABL Open Relays']['link'] = 'http://www.njabl.org/';
756 $filters['NJABL Open Relays']['dns'] = 'dnsbl.njabl.org';
757 $filters['NJABL Open Relays']['result'] = '127.0.0.2';
758 $filters['NJABL Open Relays']['comment'] =
759 _("FREE, for now - Not Just Another Blacklist - Both Open Relays and Direct SPAM Sources.");
760
761 $filters['NJABL DUL']['prefname'] = 'filters_spam_njabl_dul';
762 $filters['NJABL DUL']['name'] = 'NJABL Dial-ups List';
763 $filters['NJABL DUL']['link'] = 'http://www.njabl.org/';
764 $filters['NJABL DUL']['dns'] = 'dnsbl.njabl.org';
765 $filters['NJABL DUL']['result'] = '127.0.0.3';
766 $filters['NJABL DUL']['comment'] =
767 _("FREE, for now - Not Just Another Blacklist - Dial-up IPs.");
768
769 $filters['Conf DSBL.ORG Relay']['prefname'] = 'filters_spam_dsbl_conf_ss';
770 $filters['Conf DSBL.ORG Relay']['name'] = 'DSBL.org Confirmed Relay List';
771 $filters['Conf DSBL.ORG Relay']['link'] = 'http://www.dsbl.org/';
772 $filters['Conf DSBL.ORG Relay']['dns'] = 'list.dsbl.org';
773 $filters['Conf DSBL.ORG Relay']['result'] = '127.0.0.2';
774 $filters['Conf DSBL.ORG Relay']['comment'] =
775 _("FREE - Distributed Sender Boycott List - Confirmed Relays");
776
777 $filters['Conf DSBL.ORG Multi-Stage']['prefname'] = 'filters_spam_dsbl_conf_ms';
778 $filters['Conf DSBL.ORG Multi-Stage']['name'] = 'DSBL.org Confirmed Multi-Stage Relay List';
779 $filters['Conf DSBL.ORG Multi-Stage']['link'] = 'http://www.dsbl.org/';
780 $filters['Conf DSBL.ORG Multi-Stage']['dns'] = 'multihop.dsbl.org';
781 $filters['Conf DSBL.ORG Multi-Stage']['result'] = '127.0.0.2';
782 $filters['Conf DSBL.ORG Multi-Stage']['comment'] =
783 _("FREE - Distributed Sender Boycott List - Confirmed Multi-stage Relays");
784
785 $filters['UN-Conf DSBL.ORG']['prefname'] = 'filters_spam_dsbl_unc';
786 $filters['UN-Conf DSBL.ORG']['name'] = 'DSBL.org UN-Confirmed Relay List';
787 $filters['UN-Conf DSBL.ORG']['link'] = 'http://www.dsbl.org/';
788 $filters['UN-Conf DSBL.ORG']['dns'] = 'unconfirmed.dsbl.org';
789 $filters['UN-Conf DSBL.ORG']['result'] = '127.0.0.2';
790 $filters['UN-Conf DSBL.ORG']['comment'] =
791 _("FREE - Distributed Sender Boycott List - UN-Confirmed Relays");
792
793 foreach ($filters as $Key => $Value) {
794 $filters[$Key]['enabled'] = getPref($data_dir, $username,
795 $filters[$Key]['prefname']);
796 }
797
798 return $filters;
799 }
800
801 function remove_filter ($id) {
802 global $data_dir, $username;
803
804 while ($nextFilter = getPref($data_dir, $username, 'filter' .
805 ($id + 1))) {
806 setPref($data_dir, $username, 'filter' . $id, $nextFilter);
807 $id ++;
808 }
809
810 removePref($data_dir, $username, 'filter' . $id);
811 }
812
813 function filter_swap($id1, $id2) {
814 global $data_dir, $username;
815
816 $FirstFilter = getPref($data_dir, $username, 'filter' . $id1);
817 $SecondFilter = getPref($data_dir, $username, 'filter' . $id2);
818
819 if ($FirstFilter && $SecondFilter) {
820 setPref($data_dir, $username, 'filter' . $id2, $FirstFilter);
821 setPref($data_dir, $username, 'filter' . $id1, $SecondFilter);
822 }
823 }
824
825 /* This update the filter rules when
826 renaming or deleting folders */
827 function update_for_folder ($args) {
828 $old_folder = $args[0];
829 $new_folder = $args[2];
830 $action = $args[1];
831 global $plugins, $data_dir, $username;
832 $filters = array();
833 $filters = load_filters();
834 $filter_count = count($filters);
835 $p = 0;
836 for ($i=0;$i<$filter_count;$i++) {
837 if (!empty($filters)) {
838 if ($old_folder == $filters[$i]['folder']) {
839 if ($action == 'rename') {
840 $filters[$i]['folder'] = $new_folder;
841 setPref($data_dir, $username, 'filter'.$i,
842 $filters[$i]['where'].','.$filters[$i]['what'].','.$new_folder);
843 }
844 elseif ($action == 'delete') {
845 remove_filter($p);
846 $p = $p-1;
847 }
848 }
849 $p++;
850 }
851 }
852 }
853 ?>