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