|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
  
 
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 #  | 
| 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # (c) Jan Gehring   | 
| 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 #  | 
| 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 NAME  | 
| 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Rex::Logger - Logging Module  | 
| 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 DESCRIPTION  | 
| 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 This module is the logging module. You can define custom logformats.  | 
| 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 SYNOPSIS  | 
| 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
  $Rex::Logger::format = '[%D] %s';  | 
| 
16
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
  # will output something like  | 
| 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
  # [2012-04-12 18:35:12] Installing package vim  | 
| 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
  $Rex::Logger::format = '%h - %D - %s';  | 
| 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
  # will output something like  | 
| 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
  # srv001 - 2012-04-12 18:35:12 - Installing package vim  | 
| 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
23
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 VARIABLES  | 
| 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
25
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =over 4  | 
| 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
29
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package Rex::Logger;  | 
| 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
31
 | 
106
 | 
 
 | 
 
 | 
  
106
  
 | 
 
 | 
1330
 | 
 use v5.12.5;  | 
| 
 
 | 
106
 | 
 
 | 
 
 | 
 
 | 
 
 | 
417
 | 
    | 
| 
32
 | 
106
 | 
 
 | 
 
 | 
  
106
  
 | 
 
 | 
652
 | 
 use warnings;  | 
| 
 
 | 
106
 | 
 
 | 
 
 | 
 
 | 
 
 | 
176
 | 
    | 
| 
 
 | 
106
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4430
 | 
    | 
| 
33
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
34
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $VERSION = '1.14.3'; # VERSION  | 
| 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
36
 | 
106
 | 
 
 | 
 
 | 
  
106
  
 | 
 
 | 
24882
 | 
 use English qw(-no_match_vars);  | 
| 
 
 | 
106
 | 
 
 | 
 
 | 
 
 | 
 
 | 
180999
 | 
    | 
| 
 
 | 
106
 | 
 
 | 
 
 | 
 
 | 
 
 | 
801
 | 
    | 
| 
37
 | 
106
 | 
 
 | 
 
 | 
  
106
  
 | 
 
 | 
104474
 | 
 use Term::ANSIColor;  | 
| 
 
 | 
106
 | 
 
 | 
 
 | 
 
 | 
 
 | 
882718
 | 
    | 
| 
 
 | 
106
 | 
 
 | 
 
 | 
 
 | 
 
 | 
7699
 | 
    | 
| 
38
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
39
 | 
106
 | 
 
 | 
 
 | 
  
106
  
 | 
 
 | 
67770
 | 
 use if $OSNAME eq 'MSWin32', 'Win32::Console::ANSI';  | 
| 
 
 | 
106
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1483
 | 
    | 
| 
 
 | 
106
 | 
 
 | 
 
 | 
 
 | 
 
 | 
683
 | 
    | 
| 
40
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
41
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $no_color = 0;  | 
| 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
43
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 my $has_syslog = 0;  | 
| 
44
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 my $log_fh;  | 
| 
45
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
46
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =item $debug  | 
| 
47
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
48
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Setting this variable to 1 will enable debug logging.  | 
| 
49
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
  $Rex::Logger::debug = 1;  | 
| 
51
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
53
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
54
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $debug = 0;  | 
| 
55
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
56
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =item $silent  | 
| 
57
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
58
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 If you set this variable to 1 nothing will be logged.  | 
| 
59
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
60
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
  $Rex::Logger::silent = 1;  | 
| 
61
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
62
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
63
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
64
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $silent = 0;  | 
| 
65
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
66
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =item $format  | 
| 
67
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 You can define the logging format with the following parameters.  | 
| 
69
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
70
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 %D - Appends the current date yyyy-mm-dd HH:mm:ss  | 
| 
71
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
72
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 %h - The target host  | 
| 
73
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
74
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 %p - The pid of the running process  | 
| 
75
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
76
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 %l - Loglevel (INFO or DEBUG)  | 
| 
77
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
78
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 %s - The Logstring  | 
| 
79
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
80
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Default is: [%D] %l - %s  | 
| 
81
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
82
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
83
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
84
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $format = "[%D] %l - %s";  | 
| 
85
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
86
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 my $log_opened = 0;  | 
| 
87
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
88
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub init {  | 
| 
89
 | 
76
 | 
  
100
  
 | 
 
 | 
  
76
  
 | 
  
0
  
 | 
1954
 | 
   return if $silent;  | 
| 
90
 | 
73
 | 
 
 | 
 
 | 
 
 | 
 
 | 
989
 | 
   eval {  | 
| 
91
 | 
73
 | 
  
100
  
 | 
  
 66
  
 | 
 
 | 
 
 | 
2533
 | 
     die  | 
| 
92
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       if ( Rex::Config->get_log_filename || !Rex::Config->get_log_facility );  | 
| 
93
 | 
50
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
2360
 | 
     die if ( $OSNAME =~ m/^MSWin/ );  | 
| 
94
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
95
 | 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2772
 | 
     Sys::Syslog->use;  | 
| 
96
 | 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
584
 | 
     openlog( "rex", "ndelay,pid", Rex::Config->get_log_facility );  | 
| 
97
 | 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
13007
 | 
     $has_syslog = 1;  | 
| 
98
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   };  | 
| 
99
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
100
 | 
73
 | 
 
 | 
 
 | 
 
 | 
 
 | 
366
 | 
   $log_opened = 1;  | 
| 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
102
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
103
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub info {  | 
| 
104
 | 
91
 | 
 
 | 
 
 | 
  
91
  
 | 
  
0
  
 | 
623
 | 
   my ( $msg, $type ) = @_;  | 
| 
105
 | 
91
 | 
 
 | 
 
 | 
 
 | 
 
 | 
766
 | 
   my $color = 'green';  | 
| 
106
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
107
 | 
91
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
555
 | 
   if ( defined($type) ) {  | 
| 
108
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   CHECK_COLOR: {  | 
| 
109
 | 
36
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
79
 | 
       $type eq 'warn'  && do { $color = 'yellow'; last CHECK_COLOR; };  | 
| 
 
 | 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
134
 | 
    | 
| 
 
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
53
 | 
    | 
| 
 
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
42
 | 
    | 
| 
110
 | 
22
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
83
 | 
       $type eq 'error' && do { $color = 'red';    last CHECK_COLOR; };  | 
| 
 
 | 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
65
 | 
    | 
| 
 
 | 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
55
 | 
    | 
| 
111
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
112
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
113
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
114
 | 
91
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
635
 | 
   return if $silent;  | 
| 
115
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
116
 | 
87
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
508
 | 
   if ( defined($type) ) {  | 
| 
117
 | 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
231
 | 
     $msg = format_string( $msg, uc($type) );  | 
| 
118
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
119
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   else {  | 
| 
120
 | 
51
 | 
 
 | 
 
 | 
 
 | 
 
 | 
764
 | 
     $msg = format_string( $msg, "INFO" );  | 
| 
121
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
122
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
123
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   # workaround for windows Sys::Syslog behaviour on forks  | 
| 
124
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   # see: #6  | 
| 
125
 | 
87
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
353
 | 
   unless ($log_opened) {  | 
| 
126
 | 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
189
 | 
     init();  | 
| 
127
 | 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
77
 | 
     $log_opened = 2;  | 
| 
128
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
129
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
130
 | 
87
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
282
 | 
   if ($has_syslog) {  | 
| 
131
 | 
66
 | 
 
 | 
 
 | 
 
 | 
 
 | 
379
 | 
     syslog( "info", $msg );  | 
| 
132
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
133
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
134
 | 
87
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
15743
 | 
   if ( Rex::Config->get_log_filename() ) {  | 
| 
135
 | 
21
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
59
 | 
     open( $log_fh, ">>", Rex::Config->get_log_filename() ) or die($OS_ERROR);  | 
| 
136
 | 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
170
 | 
     flock( $log_fh, 2 );  | 
| 
137
 | 
21
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
56
 | 
     print {$log_fh} "$msg\n" if ($log_fh);  | 
| 
 
 | 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
168
 | 
    | 
| 
138
 | 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
500
 | 
     close($log_fh);  | 
| 
139
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
140
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
141
 | 
87
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
421
 | 
   if ($no_color) {  | 
| 
142
 | 
18
 | 
  
 50
  
 | 
  
 33
  
 | 
 
 | 
 
 | 
290
 | 
     print STDERR "$msg\n"  | 
| 
 
 | 
 
 | 
 
 | 
  
  0
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
 
 | 
 
 | 
 
 | 
  
 33
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
 
 | 
 
 | 
 
 | 
  
 33
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
143
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       if (  | 
| 
144
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       (  | 
| 
145
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
            ( defined $::QUIET && $::QUIET == 2 )  | 
| 
146
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         && ( defined $type && $type ne 'info' )  | 
| 
147
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       )  | 
| 
148
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       || !defined $::QUIET  | 
| 
149
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       );  | 
| 
150
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
151
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   else {  | 
| 
152
 | 
69
 | 
  
 50
  
 | 
  
 33
  
 | 
 
 | 
 
 | 
1197
 | 
     print STDERR colored( [$color], "$msg\n" )  | 
| 
 
 | 
 
 | 
 
 | 
  
  0
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
 
 | 
 
 | 
 
 | 
  
 33
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
 
 | 
 
 | 
 
 | 
  
 33
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
153
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       if (  | 
| 
154
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       (  | 
| 
155
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
            ( defined $::QUIET && $::QUIET == 2 )  | 
| 
156
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         && ( defined $type && $type ne 'info' )  | 
| 
157
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       )  | 
| 
158
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       || !defined $::QUIET  | 
| 
159
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       );  | 
| 
160
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
161
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
162
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   # workaround for windows Sys::Syslog behaviour on forks  | 
| 
163
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   # see: #6  | 
| 
164
 | 
87
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
422
 | 
   if ( $log_opened == 2 ) {  | 
| 
165
 | 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
115
 | 
     &shutdown();  | 
| 
166
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
167
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
168
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
169
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub debug {  | 
| 
170
 | 
6540
 | 
 
 | 
 
 | 
  
6540
  
 | 
  
0
  
 | 
41020
 | 
   my ($msg) = @_;  | 
| 
171
 | 
6540
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
15559
 | 
   return if $silent;  | 
| 
172
 | 
6404
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
17351
 | 
   return unless $debug;  | 
| 
173
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
174
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
   $msg = format_string( $msg, "DEBUG" );  | 
| 
175
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
176
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   # workaround for windows Sys::Syslog behaviour on forks  | 
| 
177
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   # see: #6  | 
| 
178
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
5
 | 
   unless ($log_opened) {  | 
| 
179
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
     init();  | 
| 
180
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3
 | 
     $log_opened = 2;  | 
| 
181
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
182
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
183
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
5
 | 
   if ($has_syslog) {  | 
| 
184
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     syslog( "debug", $msg );  | 
| 
185
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
186
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
187
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
3
 | 
   if ( Rex::Config->get_log_filename() ) {  | 
| 
188
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
5
 | 
     open( $log_fh, ">>", Rex::Config->get_log_filename() ) or die($OS_ERROR);  | 
| 
189
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
16
 | 
     flock( $log_fh, 2 );  | 
| 
190
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
7
 | 
     print {$log_fh} "$msg\n" if ($log_fh);  | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
11
 | 
    | 
| 
191
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
39
 | 
     close($log_fh);  | 
| 
192
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
193
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
194
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
8
 | 
   if ($no_color) {  | 
| 
195
 | 
  
0
  
 | 
  
  0
  
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     print STDERR "$msg\n" unless ($::QUIET);  | 
| 
196
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
197
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   else {  | 
| 
198
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
5
 | 
     print STDERR colored( ['red'], "$msg\n" ) unless ($::QUIET);  | 
| 
199
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
200
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
201
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   # workaround for windows Sys::Syslog behaviour on forks  | 
| 
202
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   # see: #6  | 
| 
203
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
5
 | 
   if ( $log_opened == 2 ) {  | 
| 
204
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
     &shutdown();  | 
| 
205
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
206
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
207
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
208
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub get_timestamp {  | 
| 
209
 | 
89
 | 
 
 | 
 
 | 
  
89
  
 | 
  
0
  
 | 
4379
 | 
   my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =  | 
| 
210
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     localtime(time);  | 
| 
211
 | 
89
 | 
 
 | 
 
 | 
 
 | 
 
 | 
393
 | 
   $mon++;  | 
| 
212
 | 
89
 | 
 
 | 
 
 | 
 
 | 
 
 | 
265
 | 
   $year += 1900;  | 
| 
213
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
214
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   return  | 
| 
215
 | 
89
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1127
 | 
       "$year-"  | 
| 
216
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     . sprintf( "%02i", $mon ) . "-"  | 
| 
217
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     . sprintf( "%02i", $mday ) . " "  | 
| 
218
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     . sprintf( "%02i", $hour ) . ":"  | 
| 
219
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     . sprintf( "%02i", $min ) . ":"  | 
| 
220
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     . sprintf( "%02i", $sec );  | 
| 
221
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
222
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
223
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub shutdown {  | 
| 
224
 | 
75
 | 
  
100
  
 | 
 
 | 
  
75
  
 | 
  
0
  
 | 
964
 | 
   return if $silent;  | 
| 
225
 | 
72
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
246
 | 
   return unless $log_opened;  | 
| 
226
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
227
 | 
71
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
229
 | 
   if ($has_syslog) {  | 
| 
228
 | 
48
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1460
 | 
     closelog();  | 
| 
229
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
230
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   else {  | 
| 
231
 | 
23
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
44
 | 
     close($log_fh) if $log_fh;  | 
| 
232
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
233
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
234
 | 
71
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3330
 | 
   $log_opened = 0;  | 
| 
235
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
236
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
237
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
238
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub format_string {  | 
| 
239
 | 
89
 | 
 
 | 
 
 | 
  
89
  
 | 
  
0
  
 | 
449
 | 
   my ( $s, $level ) = @_;  | 
| 
240
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
241
 | 
89
 | 
 
 | 
 
 | 
 
 | 
 
 | 
587
 | 
   my $date = get_timestamp;  | 
| 
242
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   my $host =  | 
| 
243
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
        Rex::get_current_connection()  | 
| 
244
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     && Rex::get_current_connection()->{conn}->server  | 
| 
245
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     ? Rex::get_current_connection()->{conn}->server  | 
| 
246
 | 
89
 | 
  
 50
  
 | 
  
 33
  
 | 
 
 | 
 
 | 
947
 | 
     : "";  | 
| 
247
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
248
 | 
89
 | 
 
 | 
 
 | 
 
 | 
 
 | 
608
 | 
   my $line = $format;  | 
| 
249
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
250
 | 
89
 | 
 
 | 
 
 | 
 
 | 
 
 | 
833
 | 
   $line =~ s/\%D/$date/gms;  | 
| 
251
 | 
89
 | 
 
 | 
 
 | 
 
 | 
 
 | 
271
 | 
   $line =~ s/\%h/$host/gms;  | 
| 
252
 | 
89
 | 
 
 | 
 
 | 
 
 | 
 
 | 
827
 | 
   $line =~ s/\%s/$s/gms;  | 
| 
253
 | 
89
 | 
 
 | 
 
 | 
 
 | 
 
 | 
473
 | 
   $line =~ s/\%l/$level/gms;  | 
| 
254
 | 
89
 | 
 
 | 
 
 | 
 
 | 
 
 | 
372
 | 
   $line =~ s/\%p/$PID/gms;  | 
| 
255
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
256
 | 
89
 | 
 
 | 
 
 | 
 
 | 
 
 | 
295
 | 
   return $line;  | 
| 
257
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
258
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
259
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub masq {  | 
| 
260
 | 
75
 | 
 
 | 
 
 | 
  
75
  
 | 
  
0
  
 | 
1224
 | 
   my ( $format, @params ) = @_;  | 
| 
261
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
262
 | 
75
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
398
 | 
   return $format if scalar @params == 0;  | 
| 
263
 | 
75
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
240
 | 
   return $format if scalar( grep { defined } @params ) == 0;  | 
| 
 
 | 
75
 | 
 
 | 
 
 | 
 
 | 
 
 | 
432
 | 
    | 
| 
264
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
265
 | 
41
 | 
  
 50
  
 | 
  
 33
  
 | 
 
 | 
 
 | 
469
 | 
   if ( exists $ENV{REX_DEBUG_INSECURE} && $ENV{REX_DEBUG_INSECURE} eq "1" ) {  | 
| 
266
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     return sprintf( $format, @params );  | 
| 
267
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   }  | 
| 
268
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
269
 | 
41
 | 
 
 | 
 
 | 
 
 | 
 
 | 
310
 | 
   return sprintf( $format, ("**********") x @params );  | 
| 
270
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
271
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
272
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =back  | 
| 
273
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
274
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
275
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
276
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  |