line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Qualys; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
59096
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
121638
|
|
|
2
|
|
|
|
|
70
|
|
5
|
2
|
|
|
2
|
|
20
|
use HTTP::Request; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
51
|
|
6
|
2
|
|
|
2
|
|
12
|
use vars qw(@ISA $VERSION); |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
200
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
@ISA = qw(LWP::UserAgent); |
9
|
|
|
|
|
|
|
$VERSION = 0.05; |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
12
|
use constant SERVER => 'qualysapi.qualys.com'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
132
|
|
12
|
2
|
|
|
2
|
|
9
|
use constant API_PATH => '/msp/'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
80
|
|
13
|
2
|
|
|
2
|
|
8
|
use constant CONNECTION => 'https://'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1712
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
2
|
|
|
2
|
1
|
26
|
my ($class,$self) = shift; |
17
|
2
|
|
|
|
|
23
|
$self = LWP::UserAgent->new(@_); |
18
|
2
|
|
33
|
|
|
8689
|
$class = ref($class) || $class; |
19
|
2
|
|
|
|
|
8
|
$self->{QUALYS_SERVER} = SERVER; |
20
|
2
|
|
|
|
|
11
|
$self->{QUALYS_URI} = CONNECTION.SERVER.API_PATH; |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
9
|
bless ($self,$class); |
23
|
2
|
|
|
|
|
9
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Dealing with API attributes |
27
|
|
|
|
|
|
|
#AUTOLOAD will dynamically generate the attribute functions when called |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub AUTOLOAD { |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
2
|
|
608
|
(my $attr = our $AUTOLOAD) =~ s{^.*::}{}; |
32
|
2
|
50
|
0
|
|
|
10
|
warn __PACKAGE__.': ->'.$attr.'() method not defined!' && return unless $attr =~ /[^A-Z]/; # skip DESTROY and all-cap methods |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
*$AUTOLOAD = sub { |
35
|
2
|
|
|
2
|
|
2
|
my $self = shift; |
36
|
2
|
50
|
|
|
|
16
|
$self->{QUALYS_ATTRIBUTES}{lc $attr} = shift if(@_); |
37
|
2
|
|
|
|
|
12
|
return $self->{QUALYS_ATTRIBUTES}{lc $attr}; |
38
|
2
|
|
|
|
|
12
|
}; |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
8
|
goto &$AUTOLOAD; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub attribs { |
46
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
47
|
2
|
|
|
|
|
4
|
my $attr = shift; #hashref |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
8
|
while(my($att,$val) = each (%$attr)) |
|
3
|
|
|
|
|
14
|
|
50
|
|
|
|
|
|
|
{$self->{QUALYS_ATTRIBUTES}{lc($att)} = $val;} |
51
|
|
|
|
|
|
|
|
52
|
2
|
|
|
|
|
8
|
$self->{QUALYS_ATTRIBUTES}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
1
|
1
|
4
|
sub clear_attribs { $_[0]->{QUALYS_ATTRIBUTES} = {};} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub connect_to { |
58
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
59
|
0
|
|
|
|
|
0
|
my $script = shift; |
60
|
0
|
|
|
|
|
0
|
my @all_opts = (); |
61
|
0
|
|
|
|
|
0
|
my $attribs = $self->{QUALYS_ATTRIBUTES}; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
0
|
if( index(lc($script),'.php') < 1) |
|
0
|
|
|
|
|
0
|
|
64
|
|
|
|
|
|
|
{warn "Script name must end in '.php' not $script";} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
0
|
while(my($k,$v) = each (%$attribs) ) {push @all_opts, $k.'='.$v;} |
|
0
|
|
|
|
|
0
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
{ |
70
|
0
|
|
|
|
|
0
|
my $api_url = $self->api_path().$script.'?'.(join '&',@all_opts); |
|
0
|
|
|
|
|
0
|
|
71
|
0
|
|
|
|
|
0
|
my $request = HTTP::Request->new(GET => $api_url); |
72
|
0
|
0
|
|
|
|
0
|
$self->pr_status("URI = $api_url") if($self->debug); |
73
|
0
|
|
|
|
|
0
|
my $response = $self->request($request); |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
0
|
$response->is_success or die "$api_url: ",$response->message,"\n"; |
76
|
0
|
|
|
|
|
0
|
return $response->content; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
}#scope block |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
1
|
50
|
|
1
|
1
|
11
|
sub api_path {return $_[0]->{QUALYS_URI} = $_[1] ? $_[1] : $_[0]->{QUALYS_URI};} |
86
|
1
|
50
|
|
1
|
1
|
789
|
sub server {return $_[0]->{QUALYS_SERVER} = $_[1] ? $_[1] : $_[0]->{QUALYS_SERVER};} |
87
|
1
|
50
|
|
1
|
1
|
9
|
sub userid {return $_[0]->{QUALYS_USER} = $_[1] ? $_[1] : $_[0]->{QUALYS_USER};} |
88
|
1
|
50
|
|
1
|
1
|
9
|
sub passwd {return $_[0]->{QUALYS_PASS} = $_[1] ? $_[1] : $_[0]->{QUALYS_PASS};} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub get_basic_credentials { |
91
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
92
|
0
|
|
|
|
|
|
my $realm = shift; |
93
|
0
|
0
|
|
|
|
|
$self->pr_status("Basic Authentication: '$realm'") if($self->debug); |
94
|
0
|
0
|
|
|
|
|
if($self->{QUALYS_USER} eq ''){$self->pr_status("No QualysAPI username provided");} |
|
0
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
if($self->{QUALYS_PASS} eq ''){$self->pr_status("No QualysAPI password provided");} |
|
0
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
return ($self->{QUALYS_USER},$self->{QUALYS_PASS}); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |