85 |
rodolico |
1 |
#! /usr/bin/env perl
|
|
|
2 |
|
|
|
3 |
# Program: save_local
|
|
|
4 |
# Copyright (C) 2016 R. W. Rodolico
|
|
|
5 |
#
|
|
|
6 |
# Description
|
|
|
7 |
# Script will upload file passed on STDIN to URL defined in $server
|
|
|
8 |
# using variable name $urlVarName.
|
|
|
9 |
# Filename may also be passed on command line
|
|
|
10 |
# It assumes the remote server will return the exact contents which
|
|
|
11 |
# is then used to compare to what was sent
|
|
|
12 |
# It will return the following codes
|
|
|
13 |
# 0 - success
|
|
|
14 |
# 1 - Could not find LWP::Simple module
|
|
|
15 |
# 2 - file not passed on STDIN
|
|
|
16 |
# 3 - Contents returned by server do not match our local copy
|
|
|
17 |
# 4 - URL call returned a "not found" error
|
|
|
18 |
# 5 - no key given for report contents
|
|
|
19 |
# 6 - no key given for report date
|
|
|
20 |
# 7 - no key given for hostname
|
|
|
21 |
# 8 - no key given for client
|
|
|
22 |
# 9 - no key given for serial number
|
|
|
23 |
#
|
|
|
24 |
# This program is free software: you can redistribute it and/or modify
|
|
|
25 |
# it under the terms of the GNU General Public License as published by
|
|
|
26 |
# the Free Software Foundation, either version 3 of the License, or
|
|
|
27 |
# (at your option) any later version.
|
|
|
28 |
#
|
|
|
29 |
# This program is distributed in the hope that it will be useful,
|
|
|
30 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
31 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
32 |
# GNU General Public License for more details.
|
|
|
33 |
#
|
|
|
34 |
# You should have received a copy of the GNU General Public License
|
|
|
35 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
36 |
|
|
|
37 |
use warnings;
|
|
|
38 |
use strict;
|
|
|
39 |
|
|
|
40 |
our $VERSION = '1.0';
|
|
|
41 |
|
|
|
42 |
use Data::Dumper;
|
|
|
43 |
|
|
|
44 |
sub writeFile {
|
|
|
45 |
my ( $filename, $contents ) = @_;
|
|
|
46 |
if ( open FILE,">$filename" ) {
|
|
|
47 |
print FILE $contents;
|
|
|
48 |
close FILE;
|
|
|
49 |
} else {
|
|
|
50 |
print "Could not write to $filename: $!";
|
|
|
51 |
return 0;
|
|
|
52 |
}
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
sub filename {
|
|
|
56 |
my $dirname = shift;
|
|
|
57 |
$dirname = '/tmp' unless $dirname;
|
|
|
58 |
return "$dirname/" . time . '.sysinfo';
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
sub doit {
|
|
|
62 |
my ( $parameters, $message ) = @_;
|
|
|
63 |
$$parameters{'output directory'} = '/tmp' unless $$parameters{'output directory'};
|
|
|
64 |
|
|
|
65 |
&writeFile( &filename( $$parameters{'output directory'} ), $message ); # make a backup copy of the report
|
|
|
66 |
return 1;
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
1;
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
#
|