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