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