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