line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::SecurityCenter::API::Scan; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
752
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
52
|
|
4
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
31
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
8
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
82
|
|
7
|
2
|
|
|
2
|
|
8
|
use parent 'Net::SecurityCenter::Base'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
7
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
102
|
use Net::SecurityCenter::Utils qw(:all); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2424
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.310'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $common_template = { |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
id => { |
16
|
|
|
|
|
|
|
required => 1, |
17
|
|
|
|
|
|
|
allow => qr/^\d+$/, |
18
|
|
|
|
|
|
|
messages => { |
19
|
|
|
|
|
|
|
required => 'Scan ID is required', |
20
|
|
|
|
|
|
|
allow => 'Invalid Scan ID', |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
}, |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
filter => { |
25
|
|
|
|
|
|
|
allow => [ 'usable', 'manageable' ] |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
fields => { |
29
|
|
|
|
|
|
|
filter => \&sc_filter_array_to_string, |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
35
|
|
|
|
|
|
|
# METHODS |
36
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub add { |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
0
|
1
|
0
|
my ( $self, %args ) = @_; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $single_id_filter = sub { |
43
|
0
|
|
|
0
|
|
0
|
return { 'id' => $_[0] }; |
44
|
0
|
|
|
|
|
0
|
}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $array_ids_filter = sub { |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
0
|
|
0
|
my $data = []; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
0
|
foreach my $id ( @{ $_[0] } ) { |
|
0
|
|
|
|
|
0
|
|
51
|
0
|
|
|
|
|
0
|
push( @{$data}, { 'id' => $id } ); |
|
0
|
|
|
|
|
0
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
return $data; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
0
|
}; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $report_filter = sub { |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
0
|
|
0
|
my $data = []; |
61
|
0
|
|
|
|
|
0
|
my $report_types = [ 'cumulative', 'patched', 'individual', 'lce', 'archive', 'mobile' ]; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
0
|
require Params::Check; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
0
|
foreach my $id ( keys %{ $_[0] } ) { |
|
0
|
|
|
|
|
0
|
|
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
0
|
my $type = $_[0]->{$id}; |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
0
|
if ( !Params::Check::allow( $type, @{$report_types} ) ) { |
|
0
|
|
|
|
|
0
|
|
70
|
0
|
|
|
|
|
0
|
croak( "Invalid 'reports ($type) value (allowed values: " . join( ', ', @{$report_types} ) . ')' ); |
|
0
|
|
|
|
|
0
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
0
|
push( @{$data}, { 'id' => $id, 'reportSource' => $type } ); |
|
0
|
|
|
|
|
0
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
0
|
return $data; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
0
|
}; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $tmpl = { |
82
|
|
|
|
|
|
|
name => { |
83
|
|
|
|
|
|
|
required => 1, |
84
|
|
|
|
|
|
|
errors => { required => 'Specify scan name' } |
85
|
|
|
|
|
|
|
}, |
86
|
|
|
|
|
|
|
description => {}, |
87
|
|
|
|
|
|
|
targets => { |
88
|
|
|
|
|
|
|
filter => \&sc_filter_array_to_string, |
89
|
|
|
|
|
|
|
remap => 'ipList' |
90
|
|
|
|
|
|
|
}, |
91
|
|
|
|
|
|
|
assets => { |
92
|
|
|
|
|
|
|
filter => \&$array_ids_filter, |
93
|
|
|
|
|
|
|
}, |
94
|
|
|
|
|
|
|
zone => { |
95
|
|
|
|
|
|
|
allow => qr/\d+/, |
96
|
|
|
|
|
|
|
errors => { allow => 'Invalid Scan Zone ID' }, |
97
|
|
|
|
|
|
|
filter => \&$single_id_filter |
98
|
|
|
|
|
|
|
}, |
99
|
|
|
|
|
|
|
policy => { |
100
|
|
|
|
|
|
|
allow => qr/\d+/, |
101
|
|
|
|
|
|
|
errors => { allow => 'Invalid Policy ID' }, |
102
|
|
|
|
|
|
|
filter => \&$single_id_filter |
103
|
|
|
|
|
|
|
}, |
104
|
|
|
|
|
|
|
plugin => { |
105
|
|
|
|
|
|
|
allow => qr/\d+/, |
106
|
|
|
|
|
|
|
errors => { allow => 'Invalid Plugin ID' }, |
107
|
|
|
|
|
|
|
filter => \&$single_id_filter |
108
|
|
|
|
|
|
|
}, |
109
|
|
|
|
|
|
|
repository => { |
110
|
|
|
|
|
|
|
allow => qr/\d+/, |
111
|
|
|
|
|
|
|
errors => { allow => 'Invalid Repository ID' }, |
112
|
|
|
|
|
|
|
filter => \&$single_id_filter |
113
|
|
|
|
|
|
|
}, |
114
|
|
|
|
|
|
|
credentials => { |
115
|
|
|
|
|
|
|
filter => \&$array_ids_filter, |
116
|
|
|
|
|
|
|
}, |
117
|
|
|
|
|
|
|
max_time => { |
118
|
|
|
|
|
|
|
allow => qr/\d+/, |
119
|
|
|
|
|
|
|
remap => 'maxScanTime' |
120
|
|
|
|
|
|
|
}, |
121
|
|
|
|
|
|
|
email_on_launch => { |
122
|
|
|
|
|
|
|
remap => 'emailOnLaunch', |
123
|
|
|
|
|
|
|
filter => \&sc_filter_int_to_bool, |
124
|
|
|
|
|
|
|
allow => qr/\d/, |
125
|
|
|
|
|
|
|
}, |
126
|
|
|
|
|
|
|
email_on_finish => { |
127
|
|
|
|
|
|
|
remap => 'emailOnFinish', |
128
|
|
|
|
|
|
|
filter => \&sc_filter_int_to_bool, |
129
|
|
|
|
|
|
|
allow => qr/\d/, |
130
|
|
|
|
|
|
|
}, |
131
|
|
|
|
|
|
|
dhcp_tracking => { |
132
|
|
|
|
|
|
|
remap => 'dhcpTracking', |
133
|
|
|
|
|
|
|
filter => \&sc_filter_int_to_bool, |
134
|
|
|
|
|
|
|
allow => qr/\d/, |
135
|
|
|
|
|
|
|
}, |
136
|
|
|
|
|
|
|
reports => { |
137
|
|
|
|
|
|
|
filter => \&$report_filter, |
138
|
|
|
|
|
|
|
}, |
139
|
|
|
|
|
|
|
type => { |
140
|
|
|
|
|
|
|
allow => [ 'plugin', 'policy' ] |
141
|
|
|
|
|
|
|
}, |
142
|
|
|
|
|
|
|
timeout => { |
143
|
|
|
|
|
|
|
allow => [ 'discard', 'import', 'rollover' ], |
144
|
|
|
|
|
|
|
remap => 'timeoutAction', |
145
|
|
|
|
|
|
|
}, |
146
|
|
|
|
|
|
|
schedule => { |
147
|
|
|
|
|
|
|
filter => sub { |
148
|
0
|
|
|
0
|
|
0
|
return sc_schedule( %{ $_[0] } ); |
|
0
|
|
|
|
|
0
|
|
149
|
|
|
|
|
|
|
}, |
150
|
|
|
|
|
|
|
}, |
151
|
0
|
|
|
|
|
0
|
rollover => { |
152
|
|
|
|
|
|
|
allow => [ 'nextDay', 'template' ], |
153
|
|
|
|
|
|
|
remap => 'rolloverType', |
154
|
|
|
|
|
|
|
}, |
155
|
|
|
|
|
|
|
scan_vhost => { |
156
|
|
|
|
|
|
|
remap => 'scanningVirtualHosts' |
157
|
|
|
|
|
|
|
}, |
158
|
|
|
|
|
|
|
}; |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
0
|
my $params = sc_check_params( $tmpl, \%args ); |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
croak('"policy" and "plugin" are not allowed in same time') |
163
|
0
|
0
|
0
|
|
|
0
|
if ( defined( $params->{'policy'} ) && defined( $params->{'plugin'} ) ); |
164
|
|
|
|
|
|
|
|
165
|
0
|
0
|
|
|
|
0
|
if ( !defined( $params->{'type'} ) ) { |
166
|
0
|
0
|
|
|
|
0
|
$params->{'type'} = ( $params->{'policy'} ) ? 'policy' : 'plugin'; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
0
|
my $result = $self->client->post( '/scan', $params ); |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
# Return the Scan Result ID for schedule=now scans |
172
|
0
|
0
|
|
|
|
0
|
if ( defined( $result->{'scanResultID'} ) ) { |
173
|
0
|
|
|
|
|
0
|
return $result->{'scanResultID'}; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
# Return the Scan ID |
177
|
0
|
0
|
|
|
|
0
|
if ( defined( $result->{'id'} ) ) { |
178
|
0
|
|
|
|
|
0
|
return $result->{'id'}; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub execute { |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
0
|
1
|
0
|
my ( $self, %params ) = @_; |
188
|
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
0
|
$params{'schedule'} = { 'type' => 'now' }; |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
0
|
return $self->add(%params); |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub launch { |
198
|
|
|
|
|
|
|
|
199
|
1
|
|
|
1
|
1
|
3
|
my ( $self, %args ) = @_; |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
my $tmpl = { |
202
|
|
|
|
|
|
|
diagnostic_target => { remap => 'diagnosticTarget' }, |
203
|
|
|
|
|
|
|
diagnostic_password => { remap => 'diagnosticPassword' }, |
204
|
1
|
|
|
|
|
7
|
id => $common_template->{'id'}, |
205
|
|
|
|
|
|
|
}; |
206
|
|
|
|
|
|
|
|
207
|
1
|
|
|
|
|
4
|
my $params = sc_check_params( $tmpl, \%args ); |
208
|
1
|
|
|
|
|
3
|
my $scan_id = delete( $params->{'id'} ); |
209
|
1
|
|
|
|
|
3
|
my $result = $self->client->post( "/scan/$scan_id/launch", $params ); |
210
|
|
|
|
|
|
|
|
211
|
1
|
50
|
|
|
|
5
|
if ( !defined( $result->{'scanResult'}->{'id'} ) ) { |
212
|
0
|
|
|
|
|
0
|
croak('Invalid response from SecurityCenter'); # TODO |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
1
|
|
|
|
|
9
|
return $result->{'scanResult'}->{'id'}; |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub list { |
222
|
|
|
|
|
|
|
|
223
|
1
|
|
|
1
|
1
|
4
|
my ( $self, %args ) = @_; |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
my $tmpl = { |
226
|
|
|
|
|
|
|
fields => $common_template->{'fields'}, |
227
|
1
|
|
|
|
|
6
|
filter => $common_template->{'filter'}, |
228
|
|
|
|
|
|
|
raw => {}, |
229
|
|
|
|
|
|
|
}; |
230
|
|
|
|
|
|
|
|
231
|
1
|
|
|
|
|
5
|
my $params = sc_check_params( $tmpl, \%args ); |
232
|
1
|
|
|
|
|
3
|
my $raw = delete( $params->{'raw'} ); |
233
|
1
|
|
|
|
|
12
|
my $scans = $self->client->get( '/scan', $params ); |
234
|
|
|
|
|
|
|
|
235
|
1
|
50
|
|
|
|
5
|
return if ( !$scans ); |
236
|
|
|
|
|
|
|
|
237
|
1
|
50
|
|
|
|
4
|
if ($raw) { |
238
|
0
|
0
|
|
|
|
0
|
return wantarray ? @{$scans} : $scans; |
|
0
|
|
|
|
|
0
|
|
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
1
|
50
|
|
|
|
6
|
return wantarray ? @{ sc_merge($scans) } : sc_merge($scans); |
|
0
|
|
|
|
|
0
|
|
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
sub get { |
247
|
|
|
|
|
|
|
|
248
|
1
|
|
|
1
|
0
|
3
|
my ( $self, %args ) = @_; |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
my $tmpl = { |
251
|
|
|
|
|
|
|
fields => $common_template->{'fields'}, |
252
|
1
|
|
|
|
|
4
|
id => $common_template->{'id'}, |
253
|
|
|
|
|
|
|
}; |
254
|
|
|
|
|
|
|
|
255
|
1
|
|
|
|
|
4
|
my $params = sc_check_params( $tmpl, \%args ); |
256
|
1
|
|
|
|
|
3
|
my $scan_id = delete( $params->{'id'} ); |
257
|
1
|
|
|
|
|
2
|
my $raw = delete( $params->{'raw'} ); |
258
|
1
|
|
|
|
|
4
|
my $scan = $self->client->get( "/scan/$scan_id", $params ); |
259
|
|
|
|
|
|
|
|
260
|
1
|
50
|
|
|
|
4
|
return if ( !$scan ); |
261
|
1
|
50
|
|
|
|
6
|
return $scan if ($scan); |
262
|
0
|
|
|
|
|
|
return sc_normalize_hash($scan); |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
sub delete { |
269
|
|
|
|
|
|
|
|
270
|
0
|
|
|
0
|
1
|
|
my ( $self, %args ) = @_; |
271
|
|
|
|
|
|
|
|
272
|
0
|
|
|
|
|
|
my $tmpl = { id => $common_template->{'id'}, }; |
273
|
|
|
|
|
|
|
|
274
|
0
|
|
|
|
|
|
my $params = sc_check_params( $tmpl, \%args ); |
275
|
0
|
|
|
|
|
|
my $scan_id = delete( $params->{'id'} ); |
276
|
|
|
|
|
|
|
|
277
|
0
|
|
|
|
|
|
return $self->client->delete("/scan/$scan_id"); # TODO |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
1; |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
__END__ |