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