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