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