| 1 | ## no critic (Modules::RequireExplicitPackage) | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package OCS::Client; | ||||||||||||||||||||||||||||
| 4 | # ABSTRACT: simple interface to OCS's SOAP API | ||||||||||||||||||||||||||||
| 5 | 1 | $OCS::Client::VERSION = '0.013'; | |||||||||||||||||||||||||||
| 6 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use SOAP::Lite; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use XML::Entities; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use XML::Simple; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | our %ACCOUNT_INFO; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 0 | my ($class, $url, $user, $pass, @args) = @_; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | my $uri = URI->new($url); | |||||||||||||||||||||||||||
| 23 | 0 | $uri->path("/Apache/Ocsinventory/Interface"); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | my $proxy = URI->new($url); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | my $userinfo; | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | $userinfo = $user if $user; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | $userinfo .= ':' if $user && $pass; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$user and $pass
MC/DC0%0/2
$user and $pass
$user
$pass
Truth table0%0/3
A and B
A= $userB= $pass
| |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | $userinfo .= $pass if $pass; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | $proxy->userinfo($userinfo) if $userinfo; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | $proxy->path("/ocsinterface"); | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | my $self = { soap => SOAP::Lite->uri($uri->as_string)->proxy($proxy->as_string, @args) }; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | return bless $self, $class; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub get_computers_V1 { | ||||||||||||||||||||||||||
|
Subroutine
get_computers_V1: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 43 | 0 | my %request = ( | |||||||||||||||||||||||||||
| 44 | engine => 'FIRST', | ||||||||||||||||||||||||||||
| 45 | asking_for => 'INVENTORY', | ||||||||||||||||||||||||||||
| 46 | checksum => 0x01FFFF, | ||||||||||||||||||||||||||||
| 47 | wanted => 0x000003, | ||||||||||||||||||||||||||||
| 48 | offset => 0, | ||||||||||||||||||||||||||||
| 49 | @args, | ||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | my $request = "<REQUEST>\n"; | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | while (my ($tag, $value) = each %request) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | $request .= " <\U$tag\E>$value</\U$tag\E>\n"; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 0 | $request .= "</REQUEST>\n"; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | my $som = $self->{soap}->get_computers_V1($request); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | croak "ERROR: ", XML::Entities::decode('all', $som->fault->{faultstring}) | ||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if $som->fault; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | my @computers = $som->paramsall; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # peel of the <COMPUTERS> tag of @computers | ||||||||||||||||||||||||||||
| 66 | 0 | shift @computers; | |||||||||||||||||||||||||||
| 67 | 0 | pop @computers; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | return map {XMLin($_, ForceArray => [qw/DRIVES NETWORKS PRINTERS SOFTWARES STORAGES VIDEOS/])} @computers; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub computer_iterator { | ||||||||||||||||||||||||||
|
Subroutine
computer_iterator: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 0 | my ($self, %request) = @_; | |||||||||||||||||||||||||||
| 75 | 0 | my @computers; | |||||||||||||||||||||||||||
| 76 | 0 | my $offset = 0; | |||||||||||||||||||||||||||
| 77 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | unless (@computers) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | @computers = $self->get_computers_V1(%request, offset => $offset); | |||||||||||||||||||||||||||
| 80 | 0 | ++$offset; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 0 | return shift @computers; | |||||||||||||||||||||||||||
| 83 | 0 | }; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub prune { | ||||||||||||||||||||||||||
|
Subroutine
prune: not called CC=17 SCAR=57.2
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | 0 | my ($computer) = @_; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | foreach (my ($key, $accountinfo) = each %{$computer->{ACCOUNTINFO}}) { | |||||||||||||||||||||||||||
| 91 | 0 | my %myinfo; | |||||||||||||||||||||||||||
| 92 | 0 | foreach my $info (grep {exists $_->{content}} @$accountinfo) { | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ($info->{Name} =~ /^fields_(\d+)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if (exists $ACCOUNT_INFO{$1}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | $myinfo{$ACCOUNT_INFO{$1}} = $info->{content}; | |||||||||||||||||||||||||||
| 96 | } else { | ||||||||||||||||||||||||||||
| 97 | 0 | carp "Skipping unknown ACCOUNTINFO field for $key: ($info->{Name} => $info->{content})"; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } else { | ||||||||||||||||||||||||||||
| 100 | 0 | $myinfo{$info->{Name}} = $info->{content}; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | delete $myinfo{'UA Username'}; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | $computer->{ACCOUNTINFO}{$key} = \%myinfo; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if (exists $computer->{DRIVES}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | foreach my $drive (@{$computer->{DRIVES}}) { | |||||||||||||||||||||||||||
| 111 | 0 | ▶ | $drive->{ORDER} = (ref $drive->{VOLUMN} ? '' : $drive->{VOLUMN}) . (ref $drive->{LETTER} ? '' : $drive->{LETTER}); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 112 | 0 | $drive->{ORDER} =~ s@:/$@:@; | |||||||||||||||||||||||||||
| 113 | 0 | delete @{$drive}{qw/CREATEDATE FREE LETTER NUMFILES VOLUMN/}; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 0 | $computer->{DRIVES} = [sort {$a->{ORDER} cmp $b->{ORDER}} grep {$_->{TYPE} !~ /removable/i} @{$computer->{DRIVES}}]; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if (exists $computer->{HARDWARE}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | delete @{$computer->{HARDWARE}}{qw/FIDELITY LASTCOME IPADDR IPSRC LASTDATE PROCESSORS QUALITY USERID SWAP/}; | |||||||||||||||||||||||||||
| 120 | 0 | $computer->{HARDWARE}{DESCRIPTION} =~ s@^([^/]+)/\d\d-\d\d-\d\d \d\d:\d\d:\d\d$@$1@; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if (exists $computer->{NETWORKS}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | foreach my $net (@{$computer->{NETWORKS}}) { | |||||||||||||||||||||||||||
| 125 | 0 | delete @{$net}{qw/SPEED STATUS/}; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if (exists $computer->{PRINTERS}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 0 | $computer->{PRINTERS} = [sort {$a->{NAME} cmp $b->{NAME}} @{$computer->{PRINTERS}}]; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | # Of the software we only keep the name and the version | ||||||||||||||||||||||||||||
| 134 | 0 | ▶ | if (exists $computer->{SOFTWARES}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 0 | $computer->{SOFTWARES} = {map {($_->{NAME} => $_->{VERSION})} @{$computer->{SOFTWARES}}}; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if (exists $computer->{STORAGES}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 0 | $computer->{STORAGES} = [grep {$_->{TYPE} !~ /removable/i} @{$computer->{STORAGES}}]; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if (exists $computer->{VIDEOS}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 0 | foreach my $video (@{$computer->{VIDEOS}}) { | |||||||||||||||||||||||||||
| 144 | 0 | delete @{$video}{qw/RESOLUTION/}; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | return $computer; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 1 | ▶ | use constant { ## no critic (ValuesAndExpressions::ProhibitConstantPragma) | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 153 | # CHECKSUM constants | ||||||||||||||||||||||||||||
| 154 | 1 | 'HARDWARE' => 0x00001, | |||||||||||||||||||||||||||
| 155 | 'BIOS' => 0x00002, | ||||||||||||||||||||||||||||
| 156 | 'MEMORY_SLOTS' => 0x00004, | ||||||||||||||||||||||||||||
| 157 | 'SYSTEM_SLOTS' => 0x00008, | ||||||||||||||||||||||||||||
| 158 | 'REGISTRY' => 0x00010, | ||||||||||||||||||||||||||||
| 159 | 'SYSTEM_CONTROLLERS' => 0x00020, | ||||||||||||||||||||||||||||
| 160 | 'MONITORS' => 0x00040, | ||||||||||||||||||||||||||||
| 161 | 'SYSTEM_PORTS' => 0x00080, | ||||||||||||||||||||||||||||
| 162 | 'STORAGE_PERIPHERALS' => 0x00100, | ||||||||||||||||||||||||||||
| 163 | 'LOGICAL_DRIVES' => 0x00200, | ||||||||||||||||||||||||||||
| 164 | 'INPUT_DEVICES' => 0x00400, | ||||||||||||||||||||||||||||
| 165 | 'MODEMS' => 0x00800, | ||||||||||||||||||||||||||||
| 166 | 'NETWORK_ADAPTERS' => 0x01000, | ||||||||||||||||||||||||||||
| 167 | 'PRINTERS' => 0x02000, | ||||||||||||||||||||||||||||
| 168 | 'SOUND_ADAPTERS' => 0x04000, | ||||||||||||||||||||||||||||
| 169 | 'VIDEO_ADAPTERS' => 0x08000, | ||||||||||||||||||||||||||||
| 170 | 'SOFTWARE' => 0x10000, | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | # WANTED constants | ||||||||||||||||||||||||||||
| 173 | 'ACOUNTINFO' => 0x00001, | ||||||||||||||||||||||||||||
| 174 | 'DICO_SOFT' => 0x00002, | ||||||||||||||||||||||||||||
| 175 | 1 | }; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 1 | 1; # End of OCS::Client | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | __END__ | ||||||||||||||||||||||||||||