| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
=head1 NAME |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
File::OSS::Scan::Matches - store scan result about file matches |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 VERSION |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
version 0.04 |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use File::OSS::Scan::Matches; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
File::OSS::Scan::Matches->init(); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
File::OSS::Scan::Matches->add( |
|
16
|
|
|
|
|
|
|
{ |
|
17
|
|
|
|
|
|
|
'name' => $h_file->{'name'}, |
|
18
|
|
|
|
|
|
|
'path' => $h_file->{'path'}, |
|
19
|
|
|
|
|
|
|
'size' => $h_file->{'size'}, |
|
20
|
|
|
|
|
|
|
'mtime' => $h_file->{'mtime'}, |
|
21
|
|
|
|
|
|
|
}, |
|
22
|
|
|
|
|
|
|
$function_name, |
|
23
|
|
|
|
|
|
|
$certainty_level, |
|
24
|
|
|
|
|
|
|
join(' ', @$args), |
|
25
|
|
|
|
|
|
|
$message |
|
26
|
|
|
|
|
|
|
); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $matches = File::OSS::Scan::Matches->get_matches(); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
This is an internal module used by L to store scan results, |
|
33
|
|
|
|
|
|
|
and should not be called directly. |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=over 4 |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=item * L |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=back |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 AUTHOR |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Harry Wang |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Harry Wang. |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
This is free software, licensed under: |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Artistic License 1.0 |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
package File::OSS::Scan::Matches; |
|
58
|
|
|
|
|
|
|
|
|
59
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
45
|
|
|
60
|
1
|
|
|
1
|
|
6
|
use warnings FATAL => 'all'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
53
|
|
|
61
|
|
|
|
|
|
|
|
|
62
|
1
|
|
|
1
|
|
5
|
use Fatal qw( open close ); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
8
|
|
|
63
|
1
|
|
|
1
|
|
1335
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
80
|
|
|
64
|
1
|
|
|
1
|
|
6
|
use English qw( -no_match_vars ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
8
|
|
|
65
|
1
|
|
|
1
|
|
604
|
use Data::Dumper; # for debug |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
60
|
|
|
66
|
1
|
|
|
1
|
|
7
|
use JSON; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
10
|
|
|
67
|
|
|
|
|
|
|
|
|
68
|
1
|
|
|
1
|
|
159
|
use File::OSS::Scan::Constant qw(:all); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
2526
|
|
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# global var ... |
|
73
|
|
|
|
|
|
|
our $matches = undef; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub init { |
|
76
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
77
|
0
|
|
|
|
|
|
undef $matches; |
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
return SUCCESS; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub add { |
|
83
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
84
|
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
my ( $h_file, $func, $cert, $args, $msg ) |
|
86
|
|
|
|
|
|
|
= @_ or return SUCCESS; |
|
87
|
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my $key = $h_file->{'path'}; |
|
89
|
0
|
|
|
|
|
|
my $new_h_file = { |
|
90
|
|
|
|
|
|
|
'name' => $h_file->{'name'}, |
|
91
|
|
|
|
|
|
|
'size' => $h_file->{'size'}, |
|
92
|
|
|
|
|
|
|
'mtime' => $h_file->{'mtime'}, |
|
93
|
|
|
|
|
|
|
}; |
|
94
|
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
$matches->{$key} = $new_h_file |
|
96
|
|
|
|
|
|
|
if ( not exists $matches->{$key} ); |
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
push @{$matches->{$key}->{'matches'}}, { |
|
|
0
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
'func' => $func, |
|
100
|
|
|
|
|
|
|
'cert' => $cert, |
|
101
|
|
|
|
|
|
|
'args' => $args, |
|
102
|
|
|
|
|
|
|
'msg' => $msg, |
|
103
|
|
|
|
|
|
|
}; |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
return SUCCESS; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub get_matches { |
|
109
|
0
|
|
|
0
|
0
|
|
my $var = $_[0] . "::matches"; |
|
110
|
0
|
|
|
|
|
|
my $fmt = $_[1]; |
|
111
|
|
|
|
|
|
|
|
|
112
|
1
|
|
|
1
|
|
10
|
no strict 'refs'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
922
|
|
|
113
|
|
|
|
|
|
|
|
|
114
|
0
|
0
|
|
|
|
|
if ( not defined $fmt ) { |
|
115
|
0
|
|
|
|
|
|
return $$var; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
else { |
|
118
|
0
|
|
|
|
|
|
my $func = __PACKAGE__ . "::__" . $fmt; |
|
119
|
|
|
|
|
|
|
|
|
120
|
0
|
0
|
|
|
|
|
if ( defined(&$func) ) { |
|
121
|
0
|
|
|
|
|
|
return &$func($$var); |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
else { |
|
124
|
0
|
|
|
|
|
|
croak "can't find function $func in " . __PACKAGE__; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub __txt { |
|
130
|
0
|
|
|
0
|
|
|
my $result = shift; |
|
131
|
0
|
|
|
|
|
|
my $ret = undef; |
|
132
|
|
|
|
|
|
|
|
|
133
|
0
|
0
|
|
|
|
|
if ( defined $result ) { |
|
134
|
0
|
|
|
|
|
|
$ret = ''; |
|
135
|
0
|
|
|
|
|
|
my $num = 1; |
|
136
|
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
foreach my $path ( sort keys %$result ) { |
|
138
|
0
|
|
|
|
|
|
my ( $matches, $mtime, $name, $size ) |
|
139
|
|
|
|
|
|
|
= @{$result->{$path}}{ |
|
140
|
0
|
|
|
|
|
|
qw/matches mtime name size/ |
|
141
|
|
|
|
|
|
|
}; |
|
142
|
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
my $mtime_stamp = localtime($mtime); |
|
144
|
0
|
|
|
|
|
|
$ret .= sprintf( "%-16s %-50s\n", "Matches \#\($num\):", $path ); |
|
145
|
0
|
|
|
|
|
|
$ret .= sprintf( "%-16s %-20s %-10s %-20s\n", "", |
|
146
|
|
|
|
|
|
|
"name:$name", "size:$size", "mtime:$mtime_stamp" ); |
|
147
|
|
|
|
|
|
|
|
|
148
|
0
|
0
|
|
|
|
|
if ( defined $matches ) { |
|
149
|
0
|
|
|
|
|
|
my $num_of_match = 1; |
|
150
|
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
foreach my $match ( @$matches ) { |
|
152
|
0
|
|
|
|
|
|
$ret .= sprintf("%-20s %-5s %-5s %-20s %-20s\n", |
|
153
|
|
|
|
|
|
|
"", "\<$num_of_match\>\.", $match->{'cert'} . '%', |
|
154
|
|
|
|
|
|
|
$match->{'func'}, $match->{'args'} ); |
|
155
|
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
$ret .= " " x 24 . "$match->{'msg'}\n"; |
|
157
|
0
|
|
|
|
|
|
$num_of_match++; |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
$num++; |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
return $ret; |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# mainly for the body content of mail |
|
169
|
|
|
|
|
|
|
sub __html { |
|
170
|
0
|
|
|
0
|
|
|
my $result = shift; |
|
171
|
0
|
|
|
|
|
|
my $ret = undef; |
|
172
|
|
|
|
|
|
|
|
|
173
|
0
|
0
|
|
|
|
|
if ( defined $result ) { |
|
174
|
0
|
|
|
|
|
|
my $num = 1; |
|
175
|
0
|
|
|
|
|
|
$ret = ''; |
|
176
|
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
foreach my $path ( sort keys %$result ) { |
|
178
|
0
|
|
|
|
|
|
my ( $matches, $mtime, $name, $size ) |
|
179
|
|
|
|
|
|
|
= @{$result->{$path}}{ |
|
180
|
0
|
|
|
|
|
|
qw/matches mtime name size/ |
|
181
|
|
|
|
|
|
|
}; |
|
182
|
|
|
|
|
|
|
|
|
183
|
0
|
|
|
|
|
|
my $mtime_stamp = localtime($mtime); |
|
184
|
0
|
|
|
|
|
|
$ret .= "\n";
|
185
|
0
|
|
|
|
|
|
$ret .= " | | (#$num) $path | $size | $mtime_stamp | \n";
|
186
|
|
|
|
|
|
|
|
|
187
|
0
|
0
|
|
|
|
|
if ( defined $matches ) { |
|
188
|
0
|
|
|
|
|
|
my $num_of_match = 1; |
|
189
|
|
|
|
|
|
|
|
|
190
|
0
|
|
|
|
|
|
foreach my $match ( @$matches ) { |
|
191
|
0
|
|
|
|
|
|
$ret .= " | \n" .
|
192
|
|
|
|
|
|
|
" | | \<$num_of_match\> | \n" .
|
193
|
|
|
|
|
|
|
" | $match->{'cert'}\% | \n" .
|
194
|
|
|
|
|
|
|
" | $match->{'func'} | \n" .
|
195
|
|
|
|
|
|
|
" | $match->{'args'} | \n" .
|
196
|
|
|
|
|
|
|
" | $match->{'msg'} | \n" .
|
197
|
|
|
|
|
|
|
" | \n";
|
198
|
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
$num_of_match++; |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
} |
|
202
|
|
|
|
|
|
|
|
|
203
|
0
|
|
|
|
|
|
$num++; |
|
204
|
|
|
|
|
|
|
} |
|
205
|
|
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
|
$ret .= " | \n"; |
|
207
|
|
|
|
|
|
|
|
|
208
|
0
|
|
|
|
|
|
my $css = join(q(), ); |
|
209
|
0
|
|
|
|
|
|
$ret = $css . "\n" . $ret; |
|
210
|
|
|
|
|
|
|
} |
|
211
|
|
|
|
|
|
|
|
|
212
|
0
|
|
|
|
|
|
return $ret; |
|
213
|
|
|
|
|
|
|
} |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub __json { |
|
216
|
0
|
|
|
0
|
|
|
my $result = shift; |
|
217
|
0
|
|
|
|
|
|
my $ret = undef; |
|
218
|
|
|
|
|
|
|
|
|
219
|
0
|
0
|
|
|
|
|
$ret = JSON::to_json( $result, { pretty => 1 } ) |
|
220
|
|
|
|
|
|
|
if ( defined $result ); |
|
221
|
|
|
|
|
|
|
|
|
222
|
0
|
|
|
|
|
|
return $ret; |
|
223
|
|
|
|
|
|
|
} |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
1; |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
__DATA__ |