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