This file is indexed.

/usr/share/squirrelmail/plugins/squirrel_logger/functions.php is in squirrelmail-logger 2.3.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
<?php

/**
  * SquirrelMail Squirrel Logger Plugin
  *
  * Copyright (c) 2005-2011 Paul Lesniewski <paul@squirrelmail.org>
  * Copyright (c) 2002-2003 Pat Winn <ptwinn@velocibyte.com>
  * Copyright (c) 2001-2004 Ron Chinn <ron@squeaksoft.com>
  *
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  * @package plugins
  * @subpackage squirrel_logger
  *
  */


/**
  * Load configuration file
  *
  * @param boolean $silent When TRUE, does not display any errors, simply
  *                        returns FALSE (OPTIONAL; default = FALSE)
  *
  * @return boolean TRUE when the configuration file was loaded correctly,
  *                 FALSE when $quiet is turned on and there was an error
  *                 loading the configuration file (if there was an error
  *                 and $quiet is turned off, program execution will be
  *                 halted after an error is shown on-screen).
  *
  */
function sl_get_config($quiet=FALSE)
{

   // I don't think we should try to load the default/example
   // file; this plugin has too many system-specific and/or
   // sensitive aspects to try to make a misconfigured plugin work.
   //
   if (!@include_once(SM_PATH . 'config/config_squirrel_logger.php'))
      if (!@include_once(SM_PATH . 'plugins/squirrel_logger/config.php'))
      {
         if ($quiet)
            return FALSE;

         echo 'ERROR: can\'t load squirrel_logger config file';
         exit(1);
      }

   return TRUE;

}



/**   
  * Validate that this plugin is configured correctly
  *
  * @return boolean Whether or not there was a
  *                 configuration error for this plugin.
  *
  */
function squirrel_logger_check_configuration_do()
{

   global $sl_log_events, $sl_logs;


   if (!sl_get_config(TRUE))
   {
      do_err('Squirrel Logger plugin is missing its main configuration file', FALSE);
      return TRUE;
   }


   // check for questionable logger events
   //
   foreach ($sl_logs as $log => $allowed_events)
   {
   
      foreach ($allowed_events as $event => $message)
      {
         if (!in_array($event, $sl_log_events))
            do_err('Squirrel Logger plugin is configured to log the "' . $event . '" event in $sl_logs, but that event is not enabled in $sl_log_events', FALSE);
      }


      // make sure the log type is known
      //
      if ($log != 'FILE' && $log != 'SQL' && strpos($log, 'SYSTEM') !== 0)
      {
         do_err('Squirrel Logger plugin is configured to use an unknown log type "' . $log . '" in $sl_logs', FALSE);
         return TRUE;
      }

   }


   // only need to do this pre-1.5.2, as 1.5.2 will make this
   // check for us automatically
   //
   if (!check_sm_version(1, 5, 2))
   {

      // try to find Compatibility, and then that it is v2.0.10+
      //
      if (function_exists('check_plugin_version')
       && check_plugin_version('compatibility', 2, 0, 10, TRUE))
         return FALSE;


      // something went wrong
      //
      do_err('Squirrel Logger plugin requires the Compatibility plugin version 2.0.10+', FALSE);
      return TRUE;

   }

   return FALSE;

}



/**
  * Get date formatted in local or GMT time
  *
  * @param string $format Date format string
  * @param int $timestamp Time to be formatted
  *
  */
function sldate($format, $timestamp)
{

   global $sl_use_GMT;
   sl_get_config();

   if ($sl_use_GMT)
      return gmdate($format, $timestamp);
   else
      return date($format, $timestamp);
}



/**
  * Log user logins
  *
  */
function sl_log_login_do() 
{

   global $login_username, $sl_log_events, 
          $domain, $only_log_domains, $skip_domains;
   sl_get_config();


   if (!in_array('LOGIN', $sl_log_events) 
    || (isset($only_log_domains['LOGIN']) && is_array($only_log_domains['LOGIN']) 
        && !empty($only_log_domains['LOGIN']) && !in_array($domain, $only_log_domains['LOGIN']))
    || (isset($skip_domains['LOGIN']) && is_array($skip_domains['LOGIN']) 
        && !empty($skip_domains['LOGIN']) && in_array($domain, $skip_domains['LOGIN'])))
      return;


//TODO: is $login_username correct when called before vlogin decyphers it?
//TODO: is $login_username correct when called before login_alias changes it?
//TODO: is $login_username correct when called before password_forget changes it?
//TODO: what about $domain??
//            these seem to work OK at least as long as this plugin 
//            comes after those... haven't yet tried the converse
   sl_logit('LOGIN', '', $login_username);
//$log_str = "Successful webmail login from " . $ip_str . " by " . $login_username . ".";

}



/**
  * Log user logouts
  *
  */
function sl_log_logout_do() 
{

   global $sl_log_events,
          $domain, $only_log_domains, $skip_domains;
   sl_get_config();


   // check for timeout_user plugin - did user time out?
   //
   $event = 'LOGOUT';
   if (sqgetGlobalVar('timeout', $timeout, SQ_FORM)
    || sqgetGlobalVar('timeout_immediate', $timeout_immediate, SQ_FORM))
      $event = 'TIMEOUT';


   if (!in_array($event, $sl_log_events)
    || (isset($only_log_domains[$event]) && is_array($only_log_domains[$event])
        && !empty($only_log_domains[$event]) && !in_array($domain, $only_log_domains[$event]))
    || (isset($skip_domains[$event]) && is_array($skip_domains[$event])
        && !empty($skip_domains[$event]) && in_array($domain, $skip_domains[$event])))
      return;


   sl_logit($event);
//$log_str = "Webmail session timed out for " . $username . " from " . $ip_str . ".";
//$log_str = "Webmail user " . $username . " from " . $ip_str . " logged out.";

}



/**
  * Log user login errors
  *
  */
function sl_log_login_error_do($args) 
{

   global $login_username, $sl_log_events,
          $domain, $only_log_domains, $skip_domains;
   sl_get_config();


   if (!in_array('LOGIN_ERROR', $sl_log_events)
    || (isset($only_log_domains['LOGIN_ERROR']) && is_array($only_log_domains['LOGIN_ERROR'])
        && !empty($only_log_domains['LOGIN_ERROR']) && !in_array($domain, $only_log_domains['LOGIN_ERROR']))
    || (isset($skip_domains['LOGIN_ERROR']) && is_array($skip_domains['LOGIN_ERROR'])
        && !empty($skip_domains['LOGIN_ERROR']) && in_array($domain, $skip_domains['LOGIN_ERROR'])))
      return;


//TODO: is $login_username correct here when using vlogin, login_alias, or pwd_forget??
//            these seem to work OK at least as long as this plugin 
//            comes after those... haven't yet tried the converse
   $message = $args[1];
   sl_logit('LOGIN_ERROR', $message, $login_username);
//$log_str = "Failed webmail login from " . $ip_str . " by " . $login_username . ".";

}



/**
  * Log user errors
  *
  */
function sl_log_error_do($args) 
{

   global $sl_log_events, $reporting_error_for_squirrel_logger,
          $domain, $only_log_domains, $skip_domains;
   sl_get_config();


   if ($reporting_error_for_squirrel_logger
    || !in_array('ERROR', $sl_log_events)
    || (isset($only_log_domains['ERROR']) && is_array($only_log_domains['ERROR'])
        && !empty($only_log_domains['ERROR']) && !in_array($domain, $only_log_domains['ERROR']))
    || (isset($skip_domains['ERROR']) && is_array($skip_domains['ERROR'])
        && !empty($skip_domains['ERROR']) && in_array($domain, $skip_domains['ERROR'])))
      return;


   $message = $args;
   sl_logit('ERROR', $message);
//$log_str = "Failed webmail login from " . $ip_str . " by " . $login_username . ".";

}



/**
  * Monitor mails being sent, watching for possible mass mailings (spam)
  *
  */
function sl_monitor_present_msgs_do($args)
{

   $delimiter = '@';


   global $draft, $sl_mass_mail_limit, $domain,
          $sl_log_events, $only_log_domains, $skip_domains;


   // don't monitor drafts
   //
   if (!empty($draft)) return;


   sl_get_config();


   if (!in_array('MASS_MAILING', $sl_log_events)
    || (isset($only_log_domains['MASS_MAILING']) && is_array($only_log_domains['MASS_MAILING'])
        && !empty($only_log_domains['MASS_MAILING']) && !in_array($domain, $only_log_domains['MASS_MAILING']))
    || (isset($skip_domains['MASS_MAILING']) && is_array($skip_domains['MASS_MAILING'])
        && !empty($skip_domains['MASS_MAILING']) && in_array($domain, $skip_domains['MASS_MAILING'])))
      return;


   // grab TO, CC, and BCC fields from message
   //
   if (check_sm_version(1, 5, 2))
      $message = $args;
   else
      $message = $args[1];
   $toList = array();
   $ccList = array();
   $bccList = array();
   $replyToList = array();
   $fromList = array();

   foreach ($message->rfc822_header->to as $recip)
      $toList[] = $recip->mailbox . $delimiter . $recip->host;
   foreach ($message->rfc822_header->cc as $recip)
      $ccList[] = $recip->mailbox . $delimiter . $recip->host;
   foreach ($message->rfc822_header->bcc as $recip)
      $bccList[] = $recip->mailbox . $delimiter . $recip->host;
   foreach ($message->rfc822_header->reply_to as $sender)
      $replyToList[] = $sender->mailbox . $delimiter . $sender->host;
   foreach ($message->rfc822_header->from as $sender)
      $fromList[] = $sender->mailbox . $delimiter . $sender->host;


   // too many recipients?  log it and possibly send alert
   //
   $total_recips = sizeof($toList) + sizeof($ccList) + sizeof($bccList);
   if ($total_recips >= $sl_mass_mail_limit)
   {

      global $username, $sl_log_mass_mailing_show_recipients, 
             $sl_log_mass_mailing_show_message_body, $body,
             $sl_log_mass_mailing_show_subject,
             $sl_log_mass_mailing_show_from,
             $sl_log_mass_mailing_show_reply_to,
             $sl_dateformat, $sl_namelookups, $subject;
      $msg = 'Total ' . $total_recips . ' recipients';


      $address_delim = ', ';


      if ($sl_log_mass_mailing_show_recipients)
      {
         $msg .= ' (TO: ' . implode($address_delim, $toList) . ')';
         $msg .= ' (CC: ' . implode($address_delim, $ccList) . ')';
         $msg .= ' (BCC: ' . implode($address_delim, $bccList) . ')';
      }

      if ($sl_log_mass_mailing_show_from)
         $msg .= ' (FROM: ' . implode($address_delim, $fromList) . ')';

      if ($sl_log_mass_mailing_show_reply_to)
         $msg .= ' (REPLY-TO: ' . implode($address_delim, $replyToList) . ')';

      if ($sl_log_mass_mailing_show_subject)
         $msg .= ' (SUBJECT: ' . $subject . ')';

      if ($sl_log_mass_mailing_show_message_body)
         $msg .= ' (BODY: ' . $body . ')';


      sl_logit('MASS_MAILING', $msg);

   }

}



/**
  * Monitor mails when they are sent
  *
  */
function sl_monitor_sent_msgs_do($args)
{

   $delimiter = '@';


   // if the message was not sent, don't log it
   //
   if (!$args[0]) return;


   global $domain, $only_log_domains, $skip_domains,
          $sl_log_events, $sl_log_outgoing_messages_show_from,
          $sl_log_outgoing_messages_show_reply_to,
          $sl_log_outgoing_messages_show_subject,
          $sl_log_outgoing_messages_show_recipients,
          $sl_log_outgoing_messages_show_message_body;
   sl_get_config();


   if (!in_array('OUTGOING_MAIL', $sl_log_events)
    || (isset($only_log_domains['OUTGOING_MAIL']) && is_array($only_log_domains['OUTGOING_MAIL'])
        && !empty($only_log_domains['OUTGOING_MAIL']) && !in_array($domain, $only_log_domains['OUTGOING_MAIL']))
    || (isset($skip_domains['OUTGOING_MAIL']) && is_array($skip_domains['OUTGOING_MAIL'])
        && !empty($skip_domains['OUTGOING_MAIL']) && in_array($domain, $skip_domains['OUTGOING_MAIL'])))
      return;


   // grab TO, CC, and BCC fields from message
   //
   if (check_sm_version(1, 5, 2))
      $message = $args[1];
   else
      $message = $args[2];
   $toList = array();
   $ccList = array();
   $bccList = array();
   $replyToList = array();
   $fromList = array();

   foreach ($message->rfc822_header->to as $recip)
      $toList[] = $recip->mailbox . $delimiter . $recip->host;
   foreach ($message->rfc822_header->cc as $recip)
      $ccList[] = $recip->mailbox . $delimiter . $recip->host;
   foreach ($message->rfc822_header->bcc as $recip)
      $bccList[] = $recip->mailbox . $delimiter . $recip->host;
   foreach ($message->rfc822_header->reply_to as $sender)
      $replyToList[] = $sender->mailbox . $delimiter . $sender->host;
   foreach ($message->rfc822_header->from as $sender)
      $fromList[] = $sender->mailbox . $delimiter . $sender->host;


   // have to remove < and > because otherwise the message ID
   // will get removed entirely by the strip_tags() call in
   // sl_logit()
   //
   if (!empty($message->rfc822_header->message_id))
   {
      $msg = 'Message-ID: ' . str_replace(array('<', '>'), '', $message->rfc822_header->message_id);
      //$msg = 'Message-ID: ' . strtr($message->rfc822_header->message_id, '<>', '()');
   }
   else
   {
      $msg = 'Message-ID: unavailable';
   }


   $address_delim = ', ';


   if ($sl_log_outgoing_messages_show_recipients)
   {
      $msg .= ' (TO: ' . implode($address_delim, $toList) . ')';
      $msg .= ' (CC: ' . implode($address_delim, $ccList) . ')';
      $msg .= ' (BCC: ' . implode($address_delim, $bccList) . ')';
   }

   if ($sl_log_outgoing_messages_show_from)
      $msg .= ' (FROM: ' . implode($address_delim, $fromList) . ')';

   if ($sl_log_outgoing_messages_show_reply_to)
      $msg .= ' (REPLY-TO: ' . implode($address_delim, $replyToList) . ')';

global $body, $subject;
   if ($sl_log_outgoing_messages_show_subject)
      $msg .= ' (SUBJECT: ' . $subject . ')';
      ///$msg .= ' (SUBJECT: ' . $message->subject . ')';

   if ($sl_log_outgoing_messages_show_message_body)
      $msg .= ' (BODY: ' . $body . ')';
      ///$msg .= ' (BODY: ' . $message->body_part . ')';


   sl_logit('OUTGOING_MAIL', $msg);

}



/** 
  * Build log fields and send off to be logged
  *
  * Custom event types are acceptable as long as they are enabled
  * in the configuration file.
  *
  * @param string $event The event type
  * @param string $message The log message - note that any HTML
  *                        tags will be removed (optional; default = empty)
  * @param string $user Override for username (if not given,
  *                     will use the SquirrelMail user found
  *                     in SESSION.  (optional; default = empty)
  *
  */
function sl_logit($event, $message='', $user='')
{

   global $sl_namelookups, $sl_dateformat, $username, $domain;
   sl_get_config();


   // construct log fields
   //
   if (empty($user)) $user = $username;

   $timestamp = time();
   $date_str = sldate($sl_dateformat, $timestamp);

   if (!sqgetGlobalVar('REMOTE_ADDR', $user_address, SQ_SERVER))
      $user_address = '';

   if ($sl_namelookups)
      $user_address .= ' (' . gethostbyaddr($user_address) . ')';


   // remove HTML from message and bring multiline into one line
   //
   $message = strip_tags(preg_replace("/(\r\n|\n|\r)+/", ' ', $message));


   // send off to be logged
   //
   sl_send_to_log($event, $timestamp, $date_str, $user, $domain, $user_address, $message);

}



/** 
  * Dispatch fields to be logged to the registered log types
  *
  * Also sends alerts if needed.
  *
  * Custom event types are acceptable as long as they are enabled
  * in the configuration file.
  *
  * @param string $event The event type
  * @param int $timestamp The date and time of the event
  * @param string $date_str A formatted, humyn-readable version of 
  *                         the $timestamp
  * @param string $user The user that triggered the event (optional; 
  *                     default = empty)
  * @param string $dom The user's domain (optional; default = empty)
  * @param string $remote_addr The user's IP and/or hostname 
  *                            information (optional; default = empty)
  * @param string $message The log message (optional; deafult = empty)
  *
  */
function sl_send_to_log($event, $timestamp, $date_str, $user='', $dom='', $remote_addr='', $message='')
{

   global $sl_logs, $sl_send_alerts, $sl_alert_to, $sl_alert_cc, 
          $sl_alert_bcc, $sl_alert_subject_template;
   sl_get_config();



   // find empty parameters
   //
   if (empty($user)) $user = 'N/A';
   if (empty($dom)) $dom = 'N/A';
   if (empty($remote_addr)) $remote_addr = 'N/A';



   // send message to each log type that is enabled
   //
   foreach ($sl_logs as $log => $allowed_events)
   {
   
      // skip if the current event not logged for any log type
      //
      if (!in_array($event, array_keys($allowed_events))) continue;


      // construct full log message 
      //
      $full_message = str_replace(array('%1', '%2', '%3', '%4', '%5', '%6', '%7'), 
                                  array($event, $user, $dom, $remote_addr, 
                                        $timestamp, $date_str, $message), 
                                  $allowed_events[$event]);


      if ($log == 'FILE')
      {
         sl_log_to_file($full_message);
      }

      else if ($log == 'SQL')
      {
         include_once(SM_PATH . 'plugins/squirrel_logger/database_functions.php');

         // note that in this case, $full_message will just be the revised event name
         sl_log_to_db($full_message, $user, $dom, $remote_addr, $timestamp, $message);
      }

      else if (strpos($log, 'SYSTEM') === 0)
      {
         sl_log_to_system_log($log, $full_message);
      }

   }



   // send alerts if needed
   //
   if (in_array($event, array_keys($sl_send_alerts)))
   {

      // construct full log message 
      //
      $body = str_replace(array('%1', '%2', '%3', '%4', '%5', '%6', '%7'), 
                          array($event, $user, $dom, $remote_addr, 
                                $timestamp, $date_str, $message), 
                          $sl_send_alerts[$event]);


      include_once(SM_PATH . 'plugins/squirrel_logger/alert_functions.php');


      // collect recipients
      //
      if (!empty($sl_alert_to[$event]))
         $to = $sl_alert_to[$event];
      else
         $to = '';

      if (!empty($sl_alert_cc[$event]))
         $cc = $sl_alert_cc[$event];
      else
         $cc = '';

      if (!empty($sl_alert_bcc[$event]))
         $bcc = $sl_alert_bcc[$event];
      else
         $bcc = '';


      // build subject
      //
      $subject = str_replace(array('%1', '%2'), array($event, $user), 
                             $sl_alert_subject_template);


      // send it
      //
      sl_send_alert($body, $subject, $to, $cc, $bcc);

   }

}



/**
  * Log a message to a file
  *
  * @param string $message The log message
  *
  */
function sl_log_to_file($message)
{

   global $sl_logfile;
   sl_get_config();


   // write final message to file
   //
   if ($FILE = @fopen($sl_logfile, 'ab'))
   {
      @fwrite($FILE, $message);
//      @fwrite($FILE, $message, 8192);
      fclose($FILE);
   }

}



/**
  * Log a message to the system log
  *
  * @param string $log     The details that specify the
  *                        log facility, priority, ident,
  *                        options, etc.
  * @param string $message The message to be logged
  *
  */
function sl_log_to_system_log($log, $message)
{

   global $sl_fail_silently, $sl_use_GMT;
   sl_get_config();


   // $log_details will potentially have these elements:
   // "SYSTEM" (fixed), priority, facility, ident, options
   //
   $log_details = explode(':', $log, 5);
   if (empty($log_details[1]))
      $log_details[1] = LOG_INFO;
   else
      eval('$log_details[1] = ' . $log_details[1] . ';'); // change from string to (integer) constant


   // if we have no openlog() details, then don't use it
   //
   if (sizeof($log_details) == 2)
   {
      syslog($log_details[1], $message);
      return;
   }


   // make sure we have default facility
   //
   if (empty($log_details[2]))
      $facility = LOG_SYSLOG;
   else
      eval('$facility = ' . $log_details[2] . ';'); // change from string to (integer) constant


   // make sure we have default ident
   //
   if (empty($log_details[3]))
      $log_details[3] = 0;


   // make sure we have default options
   //
   if (empty($log_details[4]))
      $options = 0;
   else
      eval('$options = ' . $log_details[4] . ';'); // change from string to (integer) constant


   // note that the use of sq_call_function_suppress_errors()
   // requires SM 1.4.12, SM 1.5.2 or Compatibility 2.0.10
   //
   $result = sq_call_function_suppress_errors('openlog', array($log_details[3], $options, $facility));
   if (!$result)
      if ($sl_fail_silently)
         return;
      else
      {

         if (empty($log_details[2])) $log_details[2] = '<not defined>';
         if (empty($log_details[3])) $log_details[3] = '<not defined>';
         if (empty($log_details[4])) $log_details[4] = '<not defined>';
         sl_error('ERROR: cannot open system log facility ' . $log_details[2] . ' with ident ' . $log_details[3] . ' and options ' . $log_details[4]);
         exit;

      }


   // now we can log, but make sure to obey timezone setting
   //
   if ($sl_use_GMT)
   {
      $saved_timezone = getenv('TZ');
      putenv('TZ=UTC');
      sq_call_function_suppress_errors('syslog', array($log_details[1], $message));
      sq_call_function_suppress_errors('closelog');
      putenv('TZ=' . $saved_timezone);
   }
   else
   {
      sq_call_function_suppress_errors('syslog', array($log_details[1], $message));
      sq_call_function_suppress_errors('closelog');
   }

}



/**
  * Print out unexpected error
  *
  * Program execution usually should halt after calling this function
  *
  * @param string $msg The error message
  *
  */
function sl_error($msg)
{

   // don't get caught in a loop of trying to re-report errors of errors!
   //
   global $color, $reporting_error_for_squirrel_logger, $oTemplate;
   $reporting_error_for_squirrel_logger = 1;

   if (check_sm_version (1, 5, 2) && !is_object($oTemplate))
      sl_finish_sm_init();

   $ret = plain_error_message($msg, $color);
   if (check_sm_version (1, 5, 2))
   {
      echo $ret;
      global $oTemplate;
      $oTemplate->display('footer.tpl');
   }

}



/**
  * Finish SquirrelMail initialization tasks just enough to be
  * able to display an error when one occurs before output is
  * otherwise expected.
  *
  */
function sl_finish_sm_init()
{

   if (check_sm_version(1, 5, 2))
   {
      include_once(SM_PATH . 'functions/display_messages.php' );
      include_once(SM_PATH . 'functions/page_header.php');
      include_once(SM_PATH . 'functions/html.php');
      global $sTemplateID, $oTemplate, $squirrelmail_language;
      $sTemplateID = Template::get_default_template_set();
      $oTemplate = Template::construct_template($sTemplateID);
      set_up_language($squirrelmail_language, true);

      return;
   }


return;
//NOTE: The following are copied from another function in the same_ip plugin that does the same thing, except that it appears to need the following because the error message is i18n-ized, whereas in Squirrel Logger, it is not.  However, I am keeping the following just in case I change that fact.


   if (check_sm_version(1, 5, 0))
   {
      include_once(SM_PATH . 'include/load_prefs.php');

      return;
   }


   if (check_sm_version(1, 4, 0))
   {
      // the following line is only needed because webmail.php
      // doesn't include validate.php; argh!
      //
      include_once(SM_PATH . 'functions/i18n.php');


      include_once(SM_PATH . 'functions/display_messages.php');

      return;
   }

}