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