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