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