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