/usr/bin/fusioninventory-injector is in fusioninventory-agent 1:2.3.10.1-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | #!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
use strict;
use warnings;
use Compress::Zlib;
use English qw(-no_match_vars);
use Fcntl qw(:flock);
use Getopt::Long;
use LWP::UserAgent;
use Pod::Usage;
my $options = {
useragent => 'FusionInventory-Injector'
};
GetOptions(
$options,
'help|h',
'directory|d=s',
'file|f=s',
'url|u=s',
'useragent=s',
'remove|r',
'verbose|v',
'stdin',
);
$OUTPUT_AUTOFLUSH = 1;
pod2usage(-verbose => 0, -exitstatus => 0) if $options->{help};
if ($options->{stdin}) {
loadstdin();
} elsif ($options->{file}) {
loadfile($options->{file});
} elsif ($options->{directory}) {
loaddirectory($options->{directory});
} else {
pod2usage();
}
exit(0);
sub loadfile {
my ($file) = @_;
die "file $file does not exist" unless -f $file;
die "file $file is not readable" unless -r $file;
print "Loading $file..." if $options->{verbose};
open (my $handle, '<', $file) or die "can't open file $file: $ERRNO\n";
## no critic (ProhibitBitwise)
flock ($handle, LOCK_EX | LOCK_NB) or die "can't lock file $file: $ERRNO\n";
local $RS;
my $content = <$handle>;
close $handle or die "Can't close file $file: $ERRNO\n";
my $success = sendContent($content);
if ($success && $options->{remove}) {
unlink $file or warn "Can't remove $file: $ERRNO\n"
}
}
sub loaddirectory {
my ($directory) = @_;
die "directory $directory does not exist" unless -d $directory;
die "directory $directory is not readable" unless -r $directory;
opendir (my $handle, $directory)
or die "can't open directory $directory: $ERRNO\n";
foreach my $file (readdir($handle)) {
loadfile("$directory/$file") if $file =~ /\.ocs$/;
}
closedir $handle;
}
sub loadstdin {
my $content;
undef $RS;
$content = <STDIN>;
sendContent($content);
}
sub sendContent {
my $content = shift;
my $ua = LWP::UserAgent->new(
agent => $options->{useragent},
parse_head => 0, # No need to parse HTML
keep_alive => 1,
requests_redirectable => ['POST', 'GET', 'HEAD']
);
my $request = HTTP::Request->new( POST => $options->{url} );
$request->header(
'Pragma' => 'no-cache',
'Content-type', 'Application/x-compress'
);
if (uncompress($content)) {
$content = uncompress($content);
}
$request->content(compress($content));
my $res = $ua->request($request);
if ($options->{verbose}) {
print $res->is_success() ?
"OK\n" : "ERROR: " . $res->status_line() . "\n";
}
return $res->is_success();
}
__END__
=head1 NAME
fusioninventory-injector - A tool to push inventory in an OCS Inventory or compatible server.
=head1 SYNOPSIS
fusioninventory-injector [options] [--file <file>|--directory <directory>|--stdin]
Options:
-h --help this menu
-d --directory load every .ocs files from a directory
-f --file load a speficic file
-u --url server URL
-r --remove remove succesfuly injected files
-v --verbose verbose mode
--stdin read data from STDIN
Examples:
fusioninventory-injector -v -f /tmp/toto-2010-09-10-11-42-22.ocs --url https://login:pw@server/ocsinventory
=head1 DESCRIPTION
This tool can be used to test your server, do benchmark or push inventory from
off-line machine.
|