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