229f774d74921ff529ebd23b3a6a4e6a4964bd39
[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, $show_num=false,
313 array('Received'),array());
314 } else if ($filters_spam_scan != 'new') {
315 $headers = sqimap_get_small_header_list ($imap_stream,false, '*', array('Received'),array());
316 } else {
317 return;
318 }
319 if (!count($headers)) {
320 return;
321 }
322 $bulkquery = (strlen($SpamFilters_BulkQuery) > 0 ? true : false);
323 $IPs = array();
324 $aSpamIds = array();
325 foreach ($headers as $id => $aValue) {
326 if (isset($aValue['UID'])) {
327 $MsgNum = $aValue['UID'];
328 } else {
329 $MsgNum = $id;
330 }
331 // Look through all of the Received headers for IP addresses
332 if (isset($aValue['RECEIVED'])) {
333 foreach ($aValue['RECEIVED'] as $received) {
334 // Check to see if this line is the right "Received from" line
335 // to check
336
337 // $aValue['Received'] is an array with all the received lines.
338 // We should check them from bottom to top and only check the first 2.
339 // Currently we check only the header where $SpamFilters_YourHop in occures
340
341 if (is_int(strpos($received, $SpamFilters_YourHop))) {
342 if (preg_match('/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/',$received,$aMatch)) {
343 $isspam = false;
344 if (filters_spam_check_site($aMatch[1],$aMatch[2],$aMatch[3],$aMatch[4],$filters)) {
345 $aSpamIds[] = $MsgNum;
346 $isspam = true;
347 }
348 if ($bulkquery) {
349 array_shift($aMatch);
350 $IP = explode('.',$aMatch);
351 foreach ($filters as $key => $value) {
352 if ($filters[$key]['enabled'] && $filters[$key]['dns']) {
353 if (strlen($SpamFilters_DNScache[$IP.'.'.$filters[$key]['dns']]) == 0) {
354 $IPs[$IP] = true;
355 break;
356 }
357 }
358 }
359 }
360 // If we've checked one IP and YourHop is
361 // just a space
362 if ($SpamFilters_YourHop == ' ' || $isspam) {
363 break; // don't check any more
364 }
365 }
366 }
367 }
368 }
369 }
370 // Lookie! It's spam! Yum!
371 if (count($aSpamIds) && sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) {
372 sqimap_msgs_list_move ($imap_stream, $aSpamIds, $filters_spam_folder);
373 sqimap_mailbox_expunge($imap_stream, 'INBOX');
374 }
375
376 if ($bulkquery && count($IPs)) {
377 filters_bulkquery($filters, $IPs);
378 }
379
380 if ($SpamFilters_SharedCache) {
381 filters_SaveCache();
382 } else {
383 sqsession_register($SpamFilters_DNScache, 'SpamFilters_DNScache');
384 }
385 }
386
387 /**
388 * FIXME: Undocumented function
389 * Does the loop through each enabled filter for the specified IP address.
390 * IP format: $a.$b.$c.$d
391 * @access private
392 */
393 function filters_spam_check_site($a, $b, $c, $d, &$filters) {
394 global $SpamFilters_DNScache, $SpamFilters_CacheTTL;
395 foreach ($filters as $key => $value) {
396 if ($filters[$key]['enabled']) {
397 if ($filters[$key]['dns']) {
398 $filter_revip = $d . '.' . $c . '.' . $b . '.' . $a . '.' .
399 $filters[$key]['dns'];
400
401 if(!isset($SpamFilters_DNScache[$filter_revip]['L']))
402 $SpamFilters_DNScache[$filter_revip]['L'] = '';
403
404 if(!isset($SpamFilters_DNScache[$filter_revip]['T']))
405 $SpamFilters_DNScache[$filter_revip]['T'] = '';
406
407 if (strlen($SpamFilters_DNScache[$filter_revip]['L']) == 0) {
408 $SpamFilters_DNScache[$filter_revip]['L'] =
409 gethostbyname($filter_revip);
410 $SpamFilters_DNScache[$filter_revip]['T'] =
411 time() + $SpamFilters_CacheTTL;
412 }
413 if ($SpamFilters_DNScache[$filter_revip]['L'] ==
414 $filters[$key]['result']) {
415 return 1;
416 }
417 }
418 }
419 }
420 return 0;
421 }
422
423 /**
424 * FIXME: Undocumented function
425 * @access private
426 */
427 function load_filters() {
428 global $data_dir, $username;
429
430 $filters = array();
431 for ($i=0; $fltr = getPref($data_dir, $username, 'filter' . $i); $i++) {
432 $ary = explode(',', $fltr);
433 $filters[$i]['where'] = $ary[0];
434 $filters[$i]['what'] = $ary[1];
435 $filters[$i]['folder'] = $ary[2];
436 }
437 return $filters;
438 }
439
440 /**
441 * FIXME: Undocumented function
442 * @access private
443 */
444 function load_spam_filters() {
445 global $data_dir, $username, $SpamFilters_ShowCommercial;
446
447 if ($SpamFilters_ShowCommercial) {
448 $filters['MAPS RBL']['prefname'] = 'filters_spam_maps_rbl';
449 $filters['MAPS RBL']['name'] = 'MAPS Realtime Blackhole List';
450 $filters['MAPS RBL']['link'] = 'http://www.mail-abuse.org/rbl/';
451 $filters['MAPS RBL']['dns'] = 'blackholes.mail-abuse.org';
452 $filters['MAPS RBL']['result'] = '127.0.0.2';
453 $filters['MAPS RBL']['comment'] =
454 _("COMMERCIAL - This list contains servers that are verified spam senders. It is a pretty reliable list to scan spam from.");
455
456 $filters['MAPS RSS']['prefname'] = 'filters_spam_maps_rss';
457 $filters['MAPS RSS']['name'] = 'MAPS Relay Spam Stopper';
458 $filters['MAPS RSS']['link'] = 'http://www.mail-abuse.org/rss/';
459 $filters['MAPS RSS']['dns'] = 'relays.mail-abuse.org';
460 $filters['MAPS RSS']['result'] = '127.0.0.2';
461 $filters['MAPS RSS']['comment'] =
462 _("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.");
463
464 $filters['MAPS DUL']['prefname'] = 'filters_spam_maps_dul';
465 $filters['MAPS DUL']['name'] = 'MAPS Dial-Up List';
466 $filters['MAPS DUL']['link'] = 'http://www.mail-abuse.org/dul/';
467 $filters['MAPS DUL']['dns'] = 'dialups.mail-abuse.org';
468 $filters['MAPS DUL']['result'] = '127.0.0.3';
469 $filters['MAPS DUL']['comment'] =
470 _("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.");
471
472 $filters['MAPS RBLplus-RBL']['prefname'] = 'filters_spam_maps_rblplus_rbl';
473 $filters['MAPS RBLplus-RBL']['name'] = 'MAPS RBL+ RBL List';
474 $filters['MAPS RBLplus-RBL']['link'] = 'http://www.mail-abuse.org/';
475 $filters['MAPS RBLplus-RBL']['dns'] = 'rbl-plus.mail-abuse.org';
476 $filters['MAPS RBLplus-RBL']['result'] = '127.0.0.2';
477 $filters['MAPS RBLplus-RBL']['comment'] =
478 _("COMMERCIAL - RBL+ Blackhole entries.");
479
480 $filters['MAPS RBLplus-RSS']['prefname'] = 'filters_spam_maps_rblplus_rss';
481 $filters['MAPS RBLplus-RSS']['name'] = 'MAPS RBL+ List RSS entries';
482 $filters['MAPS RBLplus-RSS']['link'] = 'http://www.mail-abuse.org/';
483 $filters['MAPS RBLplus-RSS']['dns'] = 'rbl-plus.mail-abuse.org';
484 $filters['MAPS RBLplus-RSS']['result'] = '127.0.0.2';
485 $filters['MAPS RBLplus-RSS']['comment'] =
486 _("COMMERCIAL - RBL+ OpenRelay entries.");
487
488 $filters['MAPS RBLplus-DUL']['prefname'] = 'filters_spam_maps_rblplus_dul';
489 $filters['MAPS RBLplus-DUL']['name'] = 'MAPS RBL+ List DUL entries';
490 $filters['MAPS RBLplus-DUL']['link'] = 'http://www.mail-abuse.org/';
491 $filters['MAPS RBLplus-DUL']['dns'] = 'rbl-plus.mail-abuse.org';
492 $filters['MAPS RBLplus-DUL']['result'] = '127.0.0.3';
493 $filters['MAPS RBLplus-DUL']['comment'] =
494 _("COMMERCIAL - RBL+ Dial-up entries.");
495 }
496
497 $filters['ORDB']['prefname'] = 'filters_spam_ordb';
498 $filters['ORDB']['name'] = 'Open Relay Database List';
499 $filters['ORDB']['link'] = 'http://www.ordb.org/';
500 $filters['ORDB']['dns'] = 'relays.ordb.org';
501 $filters['ORDB']['result'] = '127.0.0.2';
502 $filters['ORDB']['comment'] =
503 _("FREE - ORDB was born when ORBS went off the air. It seems to have fewer false positives than ORBS did though.");
504
505 $filters['FiveTen Direct']['prefname'] = 'filters_spam_fiveten_src';
506 $filters['FiveTen Direct']['name'] = 'Five-Ten-sg.com Direct SPAM Sources';
507 $filters['FiveTen Direct']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
508 $filters['FiveTen Direct']['dns'] = 'blackholes.five-ten-sg.com';
509 $filters['FiveTen Direct']['result'] = '127.0.0.2';
510 $filters['FiveTen Direct']['comment'] =
511 _("FREE - Five-Ten-sg.com - Direct SPAM sources.");
512
513 $filters['FiveTen DUL']['prefname'] = 'filters_spam_fiveten_dul';
514 $filters['FiveTen DUL']['name'] = 'Five-Ten-sg.com DUL Lists';
515 $filters['FiveTen DUL']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
516 $filters['FiveTen DUL']['dns'] = 'blackholes.five-ten-sg.com';
517 $filters['FiveTen DUL']['result'] = '127.0.0.3';
518 $filters['FiveTen DUL']['comment'] =
519 _("FREE - Five-Ten-sg.com - Dial-up lists - includes some DSL IPs.");
520
521 $filters['FiveTen Unc. OptIn']['prefname'] = 'filters_spam_fiveten_oi';
522 $filters['FiveTen Unc. OptIn']['name'] = 'Five-Ten-sg.com Unconfirmed OptIn Lists';
523 $filters['FiveTen Unc. OptIn']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
524 $filters['FiveTen Unc. OptIn']['dns'] = 'blackholes.five-ten-sg.com';
525 $filters['FiveTen Unc. OptIn']['result'] = '127.0.0.4';
526 $filters['FiveTen Unc. OptIn']['comment'] =
527 _("FREE - Five-Ten-sg.com - Bulk mailers that do not use confirmed opt-in.");
528
529 $filters['FiveTen Others']['prefname'] = 'filters_spam_fiveten_oth';
530 $filters['FiveTen Others']['name'] = 'Five-Ten-sg.com Other Misc. Servers';
531 $filters['FiveTen Others']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
532 $filters['FiveTen Others']['dns'] = 'blackholes.five-ten-sg.com';
533 $filters['FiveTen Others']['result'] = '127.0.0.5';
534 $filters['FiveTen Others']['comment'] =
535 _("FREE - Five-Ten-sg.com - Other misc. servers.");
536
537 $filters['FiveTen Single Stage']['prefname'] = 'filters_spam_fiveten_ss';
538 $filters['FiveTen Single Stage']['name'] = 'Five-Ten-sg.com Single Stage Servers';
539 $filters['FiveTen Single Stage']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
540 $filters['FiveTen Single Stage']['dns'] = 'blackholes.five-ten-sg.com';
541 $filters['FiveTen Single Stage']['result'] = '127.0.0.6';
542 $filters['FiveTen Single Stage']['comment'] =
543 _("FREE - Five-Ten-sg.com - Single Stage servers.");
544
545 $filters['FiveTen SPAM Support']['prefname'] = 'filters_spam_fiveten_supp';
546 $filters['FiveTen SPAM Support']['name'] = 'Five-Ten-sg.com SPAM Support Servers';
547 $filters['FiveTen SPAM Support']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
548 $filters['FiveTen SPAM Support']['dns'] = 'blackholes.five-ten-sg.com';
549 $filters['FiveTen SPAM Support']['result'] = '127.0.0.7';
550 $filters['FiveTen SPAM Support']['comment'] =
551 _("FREE - Five-Ten-sg.com - SPAM Support servers.");
552
553 $filters['FiveTen Web forms']['prefname'] = 'filters_spam_fiveten_wf';
554 $filters['FiveTen Web forms']['name'] = 'Five-Ten-sg.com Web Form IPs';
555 $filters['FiveTen Web forms']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
556 $filters['FiveTen Web forms']['dns'] = 'blackholes.five-ten-sg.com';
557 $filters['FiveTen Web forms']['result'] = '127.0.0.8';
558 $filters['FiveTen Web forms']['comment'] =
559 _("FREE - Five-Ten-sg.com - Web Form IPs.");
560
561 $filters['Dorkslayers']['prefname'] = 'filters_spam_dorks';
562 $filters['Dorkslayers']['name'] = 'Dorkslayers Lists';
563 $filters['Dorkslayers']['link'] = 'http://www.dorkslayers.com';
564 $filters['Dorkslayers']['dns'] = 'orbs.dorkslayers.com';
565 $filters['Dorkslayers']['result'] = '127.0.0.2';
566 $filters['Dorkslayers']['comment'] =
567 _("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.");
568
569 $filters['SPAMhaus']['prefname'] = 'filters_spam_spamhaus';
570 $filters['SPAMhaus']['name'] = 'SPAMhaus Lists';
571 $filters['SPAMhaus']['link'] = 'http://www.spamhaus.org';
572 $filters['SPAMhaus']['dns'] = 'sbl.spamhaus.org';
573 $filters['SPAMhaus']['result'] = '127.0.0.6';
574 $filters['SPAMhaus']['comment'] =
575 _("FREE - SPAMhaus - A list of well-known SPAM sources.");
576
577 $filters['SPAMcop']['prefname'] = 'filters_spam_spamcop';
578 $filters['SPAMcop']['name'] = 'SPAM Cop Lists';
579 $filters['SPAMcop']['link'] = 'http://spamcop.net/bl.shtml';
580 $filters['SPAMcop']['dns'] = 'bl.spamcop.net';
581 $filters['SPAMcop']['result'] = '127.0.0.2';
582 $filters['SPAMcop']['comment'] =
583 _("FREE, for now - SPAMCOP - An interesting solution that lists servers that have a very high spam to legit email ratio (85 percent or more).");
584
585 $filters['dev.null.dk']['prefname'] = 'filters_spam_devnull';
586 $filters['dev.null.dk']['name'] = 'dev.null.dk Lists';
587 $filters['dev.null.dk']['link'] = 'http://dev.null.dk/';
588 $filters['dev.null.dk']['dns'] = 'dev.null.dk';
589 $filters['dev.null.dk']['result'] = '127.0.0.2';
590 $filters['dev.null.dk']['comment'] =
591 _("FREE - dev.null.dk - I don't have any detailed info on this list.");
592
593 $filters['visi.com']['prefname'] = 'filters_spam_visi';
594 $filters['visi.com']['name'] = 'visi.com Relay Stop List';
595 $filters['visi.com']['link'] = 'http://relays.visi.com';
596 $filters['visi.com']['dns'] = 'relays.visi.com';
597 $filters['visi.com']['result'] = '127.0.0.2';
598 $filters['visi.com']['comment'] =
599 _("FREE - visi.com - Relay Stop List. Very conservative OpenRelay List.");
600
601 $filters['ahbl.org Open Relays']['prefname'] = 'filters_spam_2mb_or';
602 $filters['ahbl.org Open Relays']['name'] = 'ahbl.org Open Relays List';
603 $filters['ahbl.org Open Relays']['link'] = 'http://www.ahbl.org/';
604 $filters['ahbl.org Open Relays']['dns'] = 'dnsbl.ahbl.org';
605 $filters['ahbl.org Open Relays']['result'] = '127.0.0.2';
606 $filters['ahbl.org Open Relays']['comment'] =
607 _("FREE - ahbl.org Open Relays - Another list of Open Relays.");
608
609 $filters['ahbl.org SPAM Source']['prefname'] = 'filters_spam_2mb_ss';
610 $filters['ahbl.org SPAM Source']['name'] = 'ahbl.org SPAM Source List';
611 $filters['ahbl.org SPAM Source']['link'] = 'http://www.ahbl.org/';
612 $filters['ahbl.org SPAM Source']['dns'] = 'dnsbl.ahbl.org';
613 $filters['ahbl.org SPAM Source']['result'] = '127.0.0.4';
614 $filters['ahbl.org SPAM Source']['comment'] =
615 _("FREE - ahbl.org SPAM Source - List of Direct SPAM Sources.");
616
617 $filters['ahbl.org SPAM ISPs']['prefname'] = 'filters_spam_2mb_isp';
618 $filters['ahbl.org SPAM ISPs']['name'] = 'ahbl.org SPAM-friendly ISP List';
619 $filters['ahbl.org SPAM ISPs']['link'] = 'http://www.ahbl.org/';
620 $filters['ahbl.org SPAM ISPs']['dns'] = 'dnsbl.ahbl.org';
621 $filters['ahbl.org SPAM ISPs']['result'] = '127.0.0.7';
622 $filters['ahbl.org SPAM ISPs']['comment'] =
623 _("FREE - ahbl.org SPAM ISPs - List of SPAM-friendly ISPs.");
624
625 $filters['Leadmon DUL']['prefname'] = 'filters_spam_lm_dul';
626 $filters['Leadmon DUL']['name'] = 'Leadmon.net DUL List';
627 $filters['Leadmon DUL']['link'] = 'http://www.leadmon.net/spamguard/';
628 $filters['Leadmon DUL']['dns'] = 'spamguard.leadmon.net';
629 $filters['Leadmon DUL']['result'] = '127.0.0.2';
630 $filters['Leadmon DUL']['comment'] =
631 _("FREE - Leadmon DUL - Another list of Dial-up or otherwise dynamically assigned IPs.");
632
633 $filters['Leadmon SPAM Source']['prefname'] = 'filters_spam_lm_ss';
634 $filters['Leadmon SPAM Source']['name'] = 'Leadmon.net SPAM Source List';
635 $filters['Leadmon SPAM Source']['link'] = 'http://www.leadmon.net/spamguard/';
636 $filters['Leadmon SPAM Source']['dns'] = 'spamguard.leadmon.net';
637 $filters['Leadmon SPAM Source']['result'] = '127.0.0.3';
638 $filters['Leadmon SPAM Source']['comment'] =
639 _("FREE - Leadmon SPAM Source - List of IPs Leadmon.net has received SPAM directly from.");
640
641 $filters['Leadmon Bulk Mailers']['prefname'] = 'filters_spam_lm_bm';
642 $filters['Leadmon Bulk Mailers']['name'] = 'Leadmon.net Bulk Mailers List';
643 $filters['Leadmon Bulk Mailers']['link'] = 'http://www.leadmon.net/spamguard/';
644 $filters['Leadmon Bulk Mailers']['dns'] = 'spamguard.leadmon.net';
645 $filters['Leadmon Bulk Mailers']['result'] = '127.0.0.4';
646 $filters['Leadmon Bulk Mailers']['comment'] =
647 _("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.");
648
649 $filters['Leadmon Open Relays']['prefname'] = 'filters_spam_lm_or';
650 $filters['Leadmon Open Relays']['name'] = 'Leadmon.net Open Relays List';
651 $filters['Leadmon Open Relays']['link'] = 'http://www.leadmon.net/spamguard/';
652 $filters['Leadmon Open Relays']['dns'] = 'spamguard.leadmon.net';
653 $filters['Leadmon Open Relays']['result'] = '127.0.0.5';
654 $filters['Leadmon Open Relays']['comment'] =
655 _("FREE - Leadmon Open Relays - Single Stage Open Relays that are not listed on other active RBLs.");
656
657 $filters['Leadmon Multi-stage']['prefname'] = 'filters_spam_lm_ms';
658 $filters['Leadmon Multi-stage']['name'] = 'Leadmon.net Multi-Stage Relay List';
659 $filters['Leadmon Multi-stage']['link'] = 'http://www.leadmon.net/spamguard/';
660 $filters['Leadmon Multi-stage']['dns'] = 'spamguard.leadmon.net';
661 $filters['Leadmon Multi-stage']['result'] = '127.0.0.6';
662 $filters['Leadmon Multi-stage']['comment'] =
663 _("FREE - Leadmon Multi-stage - Multi-Stage Open Relays that are not listed on other active RBLs and that have sent SPAM to Leadmon.net.");
664
665 $filters['Leadmon SpamBlock']['prefname'] = 'filters_spam_lm_sb';
666 $filters['Leadmon SpamBlock']['name'] = 'Leadmon.net SpamBlock Sites List';
667 $filters['Leadmon SpamBlock']['link'] = 'http://www.leadmon.net/spamguard/';
668 $filters['Leadmon SpamBlock']['dns'] = 'spamguard.leadmon.net';
669 $filters['Leadmon SpamBlock']['result'] = '127.0.0.7';
670 $filters['Leadmon SpamBlock']['comment'] =
671 _("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.");
672
673 $filters['NJABL Open Relays']['prefname'] = 'filters_spam_njabl_or';
674 $filters['NJABL Open Relays']['name'] = 'NJABL Open Relay/Direct Spam Source List';
675 $filters['NJABL Open Relays']['link'] = 'http://www.njabl.org/';
676 $filters['NJABL Open Relays']['dns'] = 'dnsbl.njabl.org';
677 $filters['NJABL Open Relays']['result'] = '127.0.0.2';
678 $filters['NJABL Open Relays']['comment'] =
679 _("FREE, for now - Not Just Another Blacklist - Both Open Relays and Direct SPAM Sources.");
680
681 $filters['NJABL DUL']['prefname'] = 'filters_spam_njabl_dul';
682 $filters['NJABL DUL']['name'] = 'NJABL Dial-ups List';
683 $filters['NJABL DUL']['link'] = 'http://www.njabl.org/';
684 $filters['NJABL DUL']['dns'] = 'dnsbl.njabl.org';
685 $filters['NJABL DUL']['result'] = '127.0.0.3';
686 $filters['NJABL DUL']['comment'] =
687 _("FREE, for now - Not Just Another Blacklist - Dial-up IPs.");
688
689 $filters['Conf DSBL.ORG Relay']['prefname'] = 'filters_spam_dsbl_conf_ss';
690 $filters['Conf DSBL.ORG Relay']['name'] = 'DSBL.org Confirmed Relay List';
691 $filters['Conf DSBL.ORG Relay']['link'] = 'http://www.dsbl.org/';
692 $filters['Conf DSBL.ORG Relay']['dns'] = 'list.dsbl.org';
693 $filters['Conf DSBL.ORG Relay']['result'] = '127.0.0.2';
694 $filters['Conf DSBL.ORG Relay']['comment'] =
695 _("FREE - Distributed Sender Boycott List - Confirmed Relays");
696
697 $filters['Conf DSBL.ORG Multi-Stage']['prefname'] = 'filters_spam_dsbl_conf_ms';
698 $filters['Conf DSBL.ORG Multi-Stage']['name'] = 'DSBL.org Confirmed Multi-Stage Relay List';
699 $filters['Conf DSBL.ORG Multi-Stage']['link'] = 'http://www.dsbl.org/';
700 $filters['Conf DSBL.ORG Multi-Stage']['dns'] = 'multihop.dsbl.org';
701 $filters['Conf DSBL.ORG Multi-Stage']['result'] = '127.0.0.2';
702 $filters['Conf DSBL.ORG Multi-Stage']['comment'] =
703 _("FREE - Distributed Sender Boycott List - Confirmed Multi-stage Relays");
704
705 $filters['UN-Conf DSBL.ORG']['prefname'] = 'filters_spam_dsbl_unc';
706 $filters['UN-Conf DSBL.ORG']['name'] = 'DSBL.org UN-Confirmed Relay List';
707 $filters['UN-Conf DSBL.ORG']['link'] = 'http://www.dsbl.org/';
708 $filters['UN-Conf DSBL.ORG']['dns'] = 'unconfirmed.dsbl.org';
709 $filters['UN-Conf DSBL.ORG']['result'] = '127.0.0.2';
710 $filters['UN-Conf DSBL.ORG']['comment'] =
711 _("FREE - Distributed Sender Boycott List - UN-Confirmed Relays");
712
713 foreach ($filters as $Key => $Value) {
714 $filters[$Key]['enabled'] = getPref($data_dir, $username,
715 $filters[$Key]['prefname']);
716 }
717
718 return $filters;
719 }
720
721 /**
722 * FIXME: Undocumented function
723 * @access private
724 */
725 function remove_filter ($id) {
726 global $data_dir, $username;
727
728 while ($nextFilter = getPref($data_dir, $username, 'filter' .
729 ($id + 1))) {
730 setPref($data_dir, $username, 'filter' . $id, $nextFilter);
731 $id ++;
732 }
733
734 removePref($data_dir, $username, 'filter' . $id);
735 }
736
737 /**
738 * FIXME: Undocumented function
739 * @access private
740 */
741 function filter_swap($id1, $id2) {
742 global $data_dir, $username;
743
744 $FirstFilter = getPref($data_dir, $username, 'filter' . $id1);
745 $SecondFilter = getPref($data_dir, $username, 'filter' . $id2);
746
747 if ($FirstFilter && $SecondFilter) {
748 setPref($data_dir, $username, 'filter' . $id2, $FirstFilter);
749 setPref($data_dir, $username, 'filter' . $id1, $SecondFilter);
750 }
751 }
752
753 /**
754 * This update the filter rules when renaming or deleting folders
755 * @param array $args
756 * @access private
757 */
758 function update_for_folder ($args) {
759 $old_folder = $args[0];
760 $new_folder = $args[2];
761 $action = $args[1];
762 global $plugins, $data_dir, $username;
763 $filters = array();
764 $filters = load_filters();
765 $filter_count = count($filters);
766 $p = 0;
767 for ($i=0;$i<$filter_count;$i++) {
768 if (!empty($filters)) {
769 if ($old_folder == $filters[$i]['folder']) {
770 if ($action == 'rename') {
771 $filters[$i]['folder'] = $new_folder;
772 setPref($data_dir, $username, 'filter'.$i,
773 $filters[$i]['where'].','.$filters[$i]['what'].','.$new_folder);
774 }
775 elseif ($action == 'delete') {
776 remove_filter($p);
777 $p = $p-1;
778 }
779 }
780 $p++;
781 }
782 }
783 }
784
785 /**
786 * Display formated error message
787 * @param string $string text message
788 * @return string html formated text message
789 * @access private
790 */
791 function do_error($string) {
792 global $color;
793 echo "<p align=\"center\"><font color=\"$color[2]\">";
794 echo $string;
795 echo "</font></p>\n";
796 }
797 ?>