| 1 | package Net::SecurityCenter::API::Scan; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use parent 'Net::SecurityCenter::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Net::SecurityCenter::Utils qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | our $VERSION = '0.310'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | 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 | ▶ | my ( $self, %args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
add: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | my $single_id_filter = sub { | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | return { 'id' => $_[0] }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 44 | 0 | }; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | my $array_ids_filter = sub { | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my $data = []; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | foreach my $id ( @{ $_[0] } ) { | |||||||||||||||||||||||||||
| 51 | 0 | push( @{$data}, { 'id' => $id } ); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | return $data; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | }; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | my $report_filter = sub { | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my $data = []; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 61 | 0 | my $report_types = [ 'cumulative', 'patched', 'individual', 'lce', 'archive', 'mobile' ]; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | require Params::Check; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | foreach my $id ( keys %{ $_[0] } ) { | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | my $type = $_[0]->{$id}; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ( !Params::Check::allow( $type, @{$report_types} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | croak( "Invalid 'reports ($type) value (allowed values: " . join( ', ', @{$report_types} ) . ')' ); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | push( @{$data}, { 'id' => $id, 'reportSource' => $type } ); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | return $data; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 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 | ▶ | return sc_schedule( %{ $_[0] } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 149 | }, | ||||||||||||||||||||||||||||
| 150 | }, | ||||||||||||||||||||||||||||
| 151 | 0 | rollover => { | |||||||||||||||||||||||||||
| 152 | allow => [ 'nextDay', 'template' ], | ||||||||||||||||||||||||||||
| 153 | remap => 'rolloverType', | ||||||||||||||||||||||||||||
| 154 | }, | ||||||||||||||||||||||||||||
| 155 | scan_vhost => { | ||||||||||||||||||||||||||||
| 156 | remap => 'scanningVirtualHosts' | ||||||||||||||||||||||||||||
| 157 | }, | ||||||||||||||||||||||||||||
| 158 | }; | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | my $params = sc_check_params( $tmpl, \%args ); | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | croak('"policy" and "plugin" are not allowed in same time') | ||||||||||||||||||||||||||||
| 163 | 0 | ▶ | if ( defined( $params->{'policy'} ) && defined( $params->{'plugin'} ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $params->{"policy"} and defined $params->{"plugin"}
MC/DC0%0/2
defined $params->{"policy"} and defined $params->{"plugin"}
defined $params->{"policy"}
defined $params->{"plugin"}
Truth table0%0/3
A and B
A= defined $params->{"policy"}B= defined $params->{"plugin"}
| |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | if ( !defined( $params->{'type'} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 0 | ▶ | $params->{'type'} = ( $params->{'policy'} ) ? 'policy' : 'plugin'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | my $result = $self->client->post( '/scan', $params ); | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | # Return the Scan Result ID for schedule=now scans | ||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if ( defined( $result->{'scanResultID'} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 0 | return $result->{'scanResultID'}; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | # Return the Scan ID | ||||||||||||||||||||||||||||
| 177 | 0 | ▶ | if ( defined( $result->{'id'} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | 0 | return $result->{'id'}; | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | sub execute { | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 0 | ▶ | my ( $self, %params ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 0 | $params{'schedule'} = { 'type' => 'now' }; | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | return $self->add(%params); | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | sub launch { | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 1 | ▶ | my ( $self, %args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
launch: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | my $tmpl = { | ||||||||||||||||||||||||||||
| 202 | diagnostic_target => { remap => 'diagnosticTarget' }, | ||||||||||||||||||||||||||||
| 203 | diagnostic_password => { remap => 'diagnosticPassword' }, | ||||||||||||||||||||||||||||
| 204 | 1 | id => $common_template->{'id'}, | |||||||||||||||||||||||||||
| 205 | }; | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 1 | my $params = sc_check_params( $tmpl, \%args ); | |||||||||||||||||||||||||||
| 208 | 1 | my $scan_id = delete( $params->{'id'} ); | |||||||||||||||||||||||||||
| 209 | 1 | my $result = $self->client->post( "/scan/$scan_id/launch", $params ); | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 1 | ▶ | if ( !defined( $result->{'scanResult'}->{'id'} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | 0 | croak('Invalid response from SecurityCenter'); # TODO | |||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 1 | return $result->{'scanResult'}->{'id'}; | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | sub list { | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 1 | ▶ | my ( $self, %args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
list: called CC=5 SCAR=19.3
Pod
documented
| |||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | my $tmpl = { | ||||||||||||||||||||||||||||
| 226 | fields => $common_template->{'fields'}, | ||||||||||||||||||||||||||||
| 227 | 1 | filter => $common_template->{'filter'}, | |||||||||||||||||||||||||||
| 228 | raw => {}, | ||||||||||||||||||||||||||||
| 229 | }; | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 1 | my $params = sc_check_params( $tmpl, \%args ); | |||||||||||||||||||||||||||
| 232 | 1 | my $raw = delete( $params->{'raw'} ); | |||||||||||||||||||||||||||
| 233 | 1 | my $scans = $self->client->get( '/scan', $params ); | |||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 1 | ▶ | return if ( !$scans ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 1 | ▶ | if ($raw) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 0 | ▶ | return wantarray ? @{$scans} : $scans; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 1 | ▶ | return wantarray ? @{ sc_merge($scans) } : sc_merge($scans); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | sub get { | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | 1 | ▶ | my ( $self, %args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | my $tmpl = { | ||||||||||||||||||||||||||||
| 251 | fields => $common_template->{'fields'}, | ||||||||||||||||||||||||||||
| 252 | 1 | id => $common_template->{'id'}, | |||||||||||||||||||||||||||
| 253 | }; | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 1 | my $params = sc_check_params( $tmpl, \%args ); | |||||||||||||||||||||||||||
| 256 | 1 | my $scan_id = delete( $params->{'id'} ); | |||||||||||||||||||||||||||
| 257 | 1 | my $raw = delete( $params->{'raw'} ); | |||||||||||||||||||||||||||
| 258 | 1 | my $scan = $self->client->get( "/scan/$scan_id", $params ); | |||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 1 | ▶ | return if ( !$scan ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 261 | 1 | ▶ | return $scan if ($scan); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | 0 | return sc_normalize_hash($scan); | |||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | sub delete { | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 0 | ▶ | my ( $self, %args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 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 | 2 | 1; | |||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | __END__ | ||||||||||||||||||||||||||||