BlueCoat-SGOS
view release on metacpan or search on metacpan
lib/BlueCoat/SGOS.pm view on Meta::CPAN
package BlueCoat::SGOS;
use strict;
use warnings;
use Data::Dumper;
use Date::Parse;
use LWP::UserAgent;
require HTTP::Request;
use HTTP::Request::Common qw/POST/;
our %_URL = (
'archconf_expanded' => '/archconf_expanded.txt',
'contentfilter_status' => '/ContentFilter/Status',
'sysinfo' => '/SYSINFO',
'send_command' =>
'/Secure/Local/console/install_upload_action/cli_post_setup.txt'
);
our %defaults = (
'appliancehost' => 'proxy',
'applianceport' => 8082,
'applianceusername' => 'admin',
'appliancepassword' => 'password',
'applianceconnectmode' => 'https',
'debuglevel' => 0,
);
=head1 NAME
BlueCoat::SGOS - A module to interact with Blue Coat SGOS-based devices.
=head1 VERSION
Version 1.05
=cut
our $VERSION = '1.05';
=head1 SYNOPSIS
This module interacts with Blue Coat SGOS-based devices. Right
now, this is limited to parsing of the 'sysinfo' data from the
device.
use strict; #always!
use BlueCoat::SGOS;
my $bc = BlueCoat::SGOS->new(
'appliancehost' => 'swg.example.com',
'applianceport' => 8082,
'applianceuser' => 'admin',
'appliancepassword' => 'password'
);
$bc->get_sysinfo();
$bc->parse_sysinfo();
# or from a file
my $bc = BlueCoat::SGOS->new();
$bc->get_sysinfo_from_file('/path/to/file.sysinfo');
$bc->parse_sysinfo();
# or from a data structure
# in this case, $sysinfodata already contains sysinfo data
my $bc = BlueCoat::SGOS->new();
$bc->get_sysinfo_from_data($sysinfodata);
$bc->parse_sysinfo();
my $sysinfodata = $bc->{'sgos_sysinfo'};
my $sgosversion = $bc->{'sgosversion'};
lib/BlueCoat/SGOS.pm view on Meta::CPAN
$self->{'_applianceusername'} = $args{'applianceusername'};
$self->{'_appliancepassword'} = $args{'appliancepassword'};
$self->{'_applianceconnectmode'} = $args{'applianceconnectmode'};
$self->{'_debuglevel'} = $args{'debuglevel'};
if ( $self->{'_appliancehost'}
&& $self->{'_applianceport'}
&& $self->{'_applianceconnectmode'}
&& $self->{'_applianceusername'}
&& $self->{'_appliancepassword'}) {
if ($self->{'_applianceconnectmode'} eq 'https') {
$self->{'_applianceurlbase'} =
q#https://#
. $self->{'_appliancehost'} . q#:#
. $self->{'_applianceport'};
}
elsif ($self->{'_applianceconnectmode'} eq 'http') {
$self->{'_applianceurlbase'} =
q#http://#
. $self->{'_appliancehost'} . q#:#
. $self->{'_applianceport'};
}
}
return $self;
}
sub _create_ua {
my $self = shift;
$self->{'_lwpua'} = LWP::UserAgent->new();
$self->{'_lwpua'}->agent("BlueCoat-SGOS/$VERSION");
$self->{'_lwpua'}->ssl_opts(
'SSL_verify_mode' => 0,
'verify_hostname' => 0,
);
}
=head2 get_sysinfo
Takes no parameters, but instead fetches the sysinfo from the
appliance specified in the constructor.
$bc->get_sysinfo();
=cut
sub get_sysinfo {
my $self = shift;
if ($self->{'_debuglevel'} > 0) {
print 'URLBASE=' . $self->{'_applianceurlbase'} . "\n";
print 'Getting '
. $self->{'_applianceurlbase'}
. $_URL{'sysinfo'} . "\n";
}
if (!defined($self->{'_lwpua'})) {
$self->_create_ua();
}
my $request =
HTTP::Request->new('GET',
$self->{'_applianceurlbase'} . $_URL{'sysinfo'});
$request->authorization_basic($self->{'_applianceusername'},
$self->{'_appliancepassword'});
my $response = $self->{'_lwpua'}->request($request);
if ($response->is_error) {
return 0;
}
else {
$self->{'sgos_sysinfo'} = $response->content;
$self->{'sgos_sysinfo'} =~ s/\r\n/\n/gi;
if ($self->{'_debuglevel'} > 0) {
print 'status=' . $response->status_line . "\n";
}
}
if ($self->{'sgos_sysinfo'}) {
return 1;
}
else {
return 0;
}
}
=head2 get_sysinfo_from_file
Takes one parameter: the filename of a sysinfo file on the disk. Use this
instead of logging in over the network.
$bc->get_sysinfo_from_file('sysinfo.filename.here');
=cut
sub get_sysinfo_from_file {
my $self = shift;
my $filename = shift;
if ($self->{'_debuglevel'} > 0) {
print "sub:get_sysinfo_from_file, filename=$filename\n";
}
if (-f $filename) {
open my $FSDFLKFJ, q{<} , $filename;
# slurp
{
local $/ = undef;
$self->{'sgos_sysinfo'} = <$FSDFLKFJ>;
$self->{'sgos_sysinfo'} =~ s/\r\n/\n/gi;
}
close $FSDFLKFJ;
if ($self->{'sgos_sysinfo'}) {
return 1;
}
else {
return 0;
}
}
else {
# no filename specified
return 0;
( run in 0.838 second using v1.01-cache-2.11-cpan-acf6aa7dc9e )