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