Armadito-Agent

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

	if ( $constant_definition !~ /^([A-Z0-9_]+) =/ ) {
		return "";
	}

	return $1;
}

sub updateConstants {
	my ($self) = @_;

	my @constants = split( /\n/, $self->SUPER::constants(@_) );

	foreach my $constant_definition (@constants) {
		my $constant = parseConstantDefinition($constant_definition);

		if ( $constant ne ""
			&& defined( $Variables{$constant} ) )
		{
			$constant_definition = "$constant = $Variables{$constant}";
		}
	}

Makefile.PL  view on Meta::CPAN

		setLinuxVariables();
	}

	overrideVariablesWithArgs($self);

	return updateConstants($self);
}

sub install {
	my ($self) = @_;
	my $install = $self->SUPER::install(@_);

	$install =~ s/install :: pure_install doc_install/install :: pure_install config_install data_install/;
	$install =~ s/install :: all pure_install doc_install/install :: all pure_install config_install data_install/;
	$install =~ s/.*\.packlist \\\n//g;

	if ( $OSNAME eq "MSWin32" ) {
		$install .= getWin32Install();
	}
	else {
		$install .= getLinuxInstall();

Makefile.PL  view on Meta::CPAN

	if [ -f $(SYSCONFDIR)/' . $conf_file . ' ]; then \
	    install -m 644 etc/' . $conf_file . ' $(SYSCONFDIR)/' . $conf_file . '.new; \
	else \
	    install -m 644 etc/' . $conf_file . ' $(SYSCONFDIR)/' . $conf_file . '; \
	fi';
}

# ensure binaries get modified to use configured directories (on Unix only)
sub installbin {
	my ($self) = @_;
	my $installbin = $self->SUPER::installbin(@_);

	return $installbin if $OSNAME eq 'MSWin32';

	$installbin =~ s|\t\$\(FIXIN\) (.*)\n|\t\$(FIXIN) $1\n\t\$(FINALIZE) $1\n|g;

	$installbin .= <<'EOF';
FINALIZE = $(ABSPERLRUN) -pi \
    -e 's|use lib .*|use lib "$(DATADIR)/lib";|;' \
    -e 's|confdir => .*|confdir => "$(SYSCONFDIR)",|;' \
    -e 's|datadir => .*|datadir => "$(DATADIR)",|;' \

lib/Armadito/Agent/Antivirus/Armadito.pm  view on Meta::CPAN

package Armadito::Agent::Antivirus::Armadito;

use strict;
use warnings;
use base 'Armadito::Agent::Antivirus';
use Armadito::Agent::HTTP::Client::ArmaditoAV;

sub new {
	my ( $class, %params ) = @_;

	my $self = $class->SUPER::new(%params);

	$self->{name}    = "Armadito";
	$self->{version} = $self->getVersion();

	return $self;
}

sub getJobj {
	my ($self) = @_;

lib/Armadito/Agent/Antivirus/Armadito/Task/Alerts.pm  view on Meta::CPAN

package Armadito::Agent::Antivirus::Armadito::Task::Alerts;

use strict;
use warnings;
use base 'Armadito::Agent::Task::Alerts';

sub run {
	my ( $self, %params ) = @_;

	$self = $self->SUPER::run(%params);

	# TODO : Parse::Syslog or Win32::Eventlog

	return $self;
}

1;

__END__

lib/Armadito/Agent/Antivirus/Armadito/Task/Scan.pm  view on Meta::CPAN


sub getScanAPIMessage {
	my ($self) = @_;

	return "{ 'path' : '" . $self->{job}->{obj}->{scan_path} . "' }";
}

sub run {
	my ( $self, %params ) = @_;

	$self = $self->SUPER::run(%params);

	$self->{logger}->info("Armadito Scan launched.");
	$self->{av_client} = Armadito::Agent::HTTP::Client::ArmaditoAV->new( taskobj => $self );
	$self->{av_client}->register();

	my $response = $self->{av_client}->sendRequest(
		"url"   => $self->{av_client}->{server_url} . "/api/scan",
		message => $self->getScanAPIMessage(),
		method  => "POST"
	);

lib/Armadito/Agent/Antivirus/Armadito/Task/State.pm  view on Meta::CPAN

package Armadito::Agent::Antivirus::Armadito::Task::State;

use strict;
use warnings;
use base 'Armadito::Agent::Task::State';

sub run {
	my ( $self, %params ) = @_;

	$self = $self->SUPER::run(%params);
	$self->{av_client} = Armadito::Agent::HTTP::Client::ArmaditoAV->new( taskobj => $self );
	$self->{av_client}->register();

	my $response = $self->{av_client}->sendRequest(
		"url"  => $self->{av_client}->{server_url} . "/api/status",
		method => "GET"
	);

	die "Unable to get AV status with ArmaditoAV api."
		if ( !$response->is_success() );

lib/Armadito/Agent/Antivirus/Eset.pm  view on Meta::CPAN


use strict;
use warnings;
use base 'Armadito::Agent::Antivirus';
use Try::Tiny;
use IPC::System::Simple qw(capture);

sub new {
	my ( $class, %params ) = @_;

	my $self = $class->SUPER::new(%params);

	$self->{name}         = "Eset";
	$self->{scancli_path} = $self->getScanCliPath();
	$self->{version}      = $self->getVersion();

	return $self;
}

sub getJobj {
	my ($self) = @_;

lib/Armadito/Agent/Antivirus/Eset/Task/Alerts.pm  view on Meta::CPAN

	my $pattern = 'timestamp="(.*?)".*?name="(.*?)", virus="(.*?)", action="(.*?)", info="(.*?)",';
	$parser->addPattern( "alerts", $pattern, $labels );
	$parser->addExclusionPattern(', avstatus="not scanned"');
	$parser->run( $logs, '\n' );

	return $parser->getResults();
}

sub run {
	my ( $self, %params ) = @_;
	$self = $self->SUPER::run(%params);

	my $eset_logs = $self->_getSystemLogs();
	if ( $eset_logs eq "" ) {
		$self->{logger}->info("No alerts found.");
		return $self;
	}

	my $alerts   = $self->_parseLogs($eset_logs);
	my $n_alerts = @{ $alerts->{alerts} };
	$self->{logger}->info( $n_alerts . " alert(s) found." );

lib/Armadito/Agent/Antivirus/Eset/Task/Scan.pm  view on Meta::CPAN

	$parser->addPattern( 'alerts', $pattern, $labels );

	$parser->run( $output, '\n' );

	return $parser->getResults();
}

sub run {
	my ( $self, %params ) = @_;

	$self = $self->SUPER::run(%params);

	my $bin_path     = $self->{agent}->{antivirus}->{scancli_path};
	my $scan_path    = $self->{job}->{obj}->{scan_path};
	my $scan_options = $self->{job}->{obj}->{scan_options};

	my $output = capture( [ 0, 1, 10, 50 ], $bin_path . " " . $scan_options . " " . $scan_path );
	$self->{logger}->debug2($output);

	my $results = $self->_parseScanOutput($output);
	$results->{start_time}       = "";

lib/Armadito/Agent/Antivirus/Eset/Task/State.pm  view on Meta::CPAN

	my $data_filepath = "/var/opt/eset/esets/lib/data/data.txt";
	my $data = readFile( filepath => $data_filepath );

	$parser->run( $data, '\n' );
	return $parser->getResults();
}

sub run {
	my ( $self, %params ) = @_;

	$self = $self->SUPER::run(%params);

	my $dbinfo = $self->_getDatabasesInfo();

	$self->_sendToGLPI($dbinfo);
}

1;

__END__

lib/Armadito/Agent/Antivirus/Kaspersky.pm  view on Meta::CPAN


use strict;
use warnings;
use base 'Armadito::Agent::Antivirus';
use UNIVERSAL::require;
use English qw(-no_match_vars);

sub new {
	my ( $class, %params ) = @_;

	my $self = $class->SUPER::new(%params);

	$self->{name}         = "Kaspersky";
	$self->{program_path} = $self->getProgramPath();
	$self->{scancli_path} = $self->{program_path} . "\\avp.com";
	$self->{version}      = $self->getVersion();

	return $self;
}

sub getJobj {

lib/Armadito/Agent/Antivirus/Kaspersky/Task/AVConfig.pm  view on Meta::CPAN

use base 'Armadito::Agent::Task::AVConfig';
use IPC::System::Simple qw(capture $EXITVAL EXIT_ANY);
use Armadito::Agent::Tools::File qw(rmFile);
use Armadito::Agent::Tools qw(getOSTempDir);
use XML::LibXML;
use Data::Dumper;

sub run {
	my ( $self, %params ) = @_;

	$self = $self->SUPER::run(%params);

	my $export_path = getOSTempDir() . "exported_settings.xml";
	rmFile( filepath => $export_path );

	if ( $self->_exportSettings($export_path) == 0 ) {
		$self->_parseSettings($export_path);
		$self->_sendToGLPI();
	}
}

lib/Armadito/Agent/Antivirus/Kaspersky/Task/Alerts.pm  view on Meta::CPAN

package Armadito::Agent::Antivirus::Kaspersky::Task::Alerts;

use strict;
use warnings;
use base 'Armadito::Agent::Task::Alerts';

sub run {
	my ( $self, %params ) = @_;

	$self = $self->SUPER::run(%params);

	my $osclass = $self->{agent}->{antivirus}->getOSClass();
	my $alerts = { alerts => $osclass->getAlerts() };

	my $n_alerts = @{ $alerts->{alerts} };
	$self->{logger}->info( $n_alerts . " alert(s) found." );

	$self->_sendAlerts($alerts);
}

lib/Armadito/Agent/Antivirus/Kaspersky/Task/Scan.pm  view on Meta::CPAN


sub LocalToTimestamp {
	my ($match) = @_;

	return iso8601ToUnixTimestamp( $match, "Local" );
}

sub run {
	my ( $self, %params ) = @_;

	$self = $self->SUPER::run(%params);

	my $bin_path     = $self->{agent}->{antivirus}->{scancli_path};
	my $scan_path    = $self->{job}->{obj}->{scan_path};
	my $scan_options = $self->{job}->{obj}->{scan_options};

	my $cmdline = "\"" . $bin_path . "\" SCAN \"" . $scan_path . "\" " . $scan_options;
	my $output = capture( EXIT_ANY, $cmdline );
	$self->{logger}->info($output);
	$self->{logger}->info( "Program exited with " . $EXITVAL . "\n" );

lib/Armadito/Agent/Antivirus/Kaspersky/Task/State.pm  view on Meta::CPAN


use strict;
use warnings;
use base 'Armadito::Agent::Task::State';
use Armadito::Agent::Tools::File qw(readFile);
use XML::LibXML;
use Time::Local;

sub run {
	my ( $self, %params ) = @_;
	$self = $self->SUPER::run(%params);

	$self->{data} = {
		dbinfo    => {},
		avdetails => []
	};

	$self->_parseUpdateIndex();
	$self->_parseProfilesFile();
	$self->_sendToGLPI( $self->{data} );
}

lib/Armadito/Agent/HTTP/Client/ArmaditoAV.pm  view on Meta::CPAN

use Armadito::Agent::HTTP::Client::ArmaditoAV::Event;
use Armadito::Agent::HTTP::Client::ArmaditoAV::Event::DetectionEvent;
use Armadito::Agent::HTTP::Client::ArmaditoAV::Event::OnDemandCompletedEvent;
use Armadito::Agent::HTTP::Client::ArmaditoAV::Event::OnDemandProgressEvent;
use Armadito::Agent::HTTP::Client::ArmaditoAV::Event::StatusEvent;

my @supported_events = ( "DetectionEvent", "OnDemandCompletedEvent", "OnDemandProgressEvent", "StatusEvent" );

sub new {
	my ( $class, %params ) = @_;
	my $self = $class->SUPER::new(%params);

	$self->{taskobj}    = $params{taskobj};
	$self->{server_url} = "http://localhost:8888";

	return $self;
}

sub _prepareURL {
	my ( $self, %params ) = @_;

lib/Armadito/Agent/HTTP/Client/ArmaditoAV/Event/DetectionEvent.pm  view on Meta::CPAN

package Armadito::Agent::HTTP::Client::ArmaditoAV::Event::DetectionEvent;

use strict;
use warnings;
use base 'Armadito::Agent::HTTP::Client::ArmaditoAV::Event';

sub new {
	my ( $class, %params ) = @_;

	my $self = $class->SUPER::new(%params);

	return $self;
}

sub run {
	my ( $self, %params ) = @_;

	return $self;
}
1;

lib/Armadito/Agent/HTTP/Client/ArmaditoAV/Event/OnDemandCompletedEvent.pm  view on Meta::CPAN

use strict;
use warnings;
use base 'Armadito::Agent::HTTP::Client::ArmaditoAV::Event';

use JSON;
use Armadito::Agent::Tools::Security qw(isANumber);

sub new {
	my ( $class, %params ) = @_;

	my $self = $class->SUPER::new(%params);

	# TODO: Add more validation
	die "Invalid total_malware_count."    if !isANumber( $self->{jobj}->{total_malware_count} );
	die "Invalid total_suspicious_count." if !isANumber( $self->{jobj}->{total_suspicious_count} );
	die "Invalid total_scanned_count."    if !isANumber( $self->{jobj}->{total_scanned_count} );

	$self->{jobj}->{malware_count}    = $self->{jobj}->{total_malware_count};
	$self->{jobj}->{suspicious_count} = $self->{jobj}->{total_suspicious_count};
	$self->{jobj}->{scanned_count}    = $self->{jobj}->{total_scanned_count};

lib/Armadito/Agent/HTTP/Client/ArmaditoAV/Event/OnDemandProgressEvent.pm  view on Meta::CPAN


use strict;
use warnings;
use base 'Armadito::Agent::HTTP::Client::ArmaditoAV::Event';

use Armadito::Agent::Tools::Security qw(isANumber);

sub new {
	my ( $class, %params ) = @_;

	my $self = $class->SUPER::new(%params);

	# TODO: Add more validation
	die "Invalid malware_count."    if !isANumber( $self->{jobj}->{malware_count} );
	die "Invalid suspicious_count." if !isANumber( $self->{jobj}->{suspicious_count} );
	die "Invalid scanned_count."    if !isANumber( $self->{jobj}->{scanned_count} );

	return $self;
}

sub run {

lib/Armadito/Agent/HTTP/Client/ArmaditoAV/Event/StatusEvent.pm  view on Meta::CPAN

package Armadito::Agent::HTTP::Client::ArmaditoAV::Event::StatusEvent;

use strict;
use warnings;
use base 'Armadito::Agent::HTTP::Client::ArmaditoAV::Event';
use JSON;

sub new {
	my ( $class, %params ) = @_;

	my $self = $class->SUPER::new(%params);

	return $self;
}

sub _sendToGLPI {
	my ( $self, $message ) = @_;

	my $response = $self->{taskobj}->{glpi_client}->sendRequest(
		"url"   => $self->{taskobj}->{agent}->{config}->{server}[0] . "/api/states",
		message => $message,

lib/Armadito/Agent/HTTP/Client/ArmaditoGLPI.pm  view on Meta::CPAN

use HTTP::Request;
use HTTP::Request::Common qw{ POST };
use UNIVERSAL::require;
use URI;
use Encode;
use Data::Dumper;
use URI::Escape;

sub new {
	my ( $class, %params ) = @_;
	my $self = $class->SUPER::new(%params);

	return $self;
}

sub _prepareVal {
	my ( $self, $val ) = @_;

	return '' unless length($val);

	# forbid too long argument.

lib/Armadito/Agent/Scheduler/Cron.pm  view on Meta::CPAN

		. abs_path($0)
		. " -t \""
		. $task->{name} . "\" "
		. $task->{args} . " " . ">>"
		. $self->{config}->{logfile}[0] . ' 2>&1' . "\n";
}

sub run {
	my ( $self, %params ) = @_;

	$self = $self->SUPER::run(%params);
	$self->_loadConf();
	$self->_updateCronTab();

	return $self;
}

1;

__END__

lib/Armadito/Agent/Scheduler/Win32Native.pm  view on Meta::CPAN

	my $existing_tasks = $self->_getExistingTasks();

	foreach ( @{ $existing_tasks->{tasks} } ) {
		$self->_deleteExistingTask($_);
	}
}

sub run {
	my ( $self, %params ) = @_;

	$self = $self->SUPER::run(%params);
	$self->_loadConf();
	$self->_deleteExistingTasks();
	$self->_createAllTasks();

	return $self;
}

1;

__END__

lib/Armadito/Agent/Task/AVConfig.pm  view on Meta::CPAN


use strict;
use warnings;
use base 'Armadito::Agent::Task';
use JSON;
use Data::Dumper;

sub new {
	my ( $class, %params ) = @_;

	my $self = $class->SUPER::new(%params);

	if ( $params{debug} ) {
		$self->{debug} = 1;
	}

	my $task = {
		name      => "AVConfig",
		antivirus => $self->{agent}->{antivirus}->getJobj()
	};

lib/Armadito/Agent/Task/Alerts.pm  view on Meta::CPAN


use strict;
use warnings;
use base 'Armadito::Agent::Task';
use JSON;
use Data::Dumper;

sub new {
	my ( $class, %params ) = @_;

	my $self = $class->SUPER::new(%params);

	if ( $params{debug} ) {
		$self->{debug} = 1;
	}

	my $task = {
		name      => "Alerts",
		antivirus => $self->{agent}->{antivirus}->getJobj()
	};

lib/Armadito/Agent/Task/Enrollment.pm  view on Meta::CPAN

use strict;
use warnings;
use base 'Armadito::Agent::Task';
use Armadito::Agent::Tools::File qw( readFile );
use Data::Dumper;
use JSON;

sub new {
	my ( $class, %params ) = @_;

	my $self = $class->SUPER::new(%params);

	if ( $params{debug} ) {
		$self->{debug} = 1;
	}

	my $task = {
		name      => "Enrollment",
		antivirus => $self->{agent}->{antivirus}->getJobj()
	};

	$self->{jobj}->{task} = $task;

	return $self;
}

sub run {
	my ( $self, %params ) = @_;

	$self = $self->SUPER::run(%params);

	$self->_setEnrollmentKey();

	my $json_text = to_json( $self->{jobj} );
	print $json_text. "\n";

	my $response = $self->{glpi_client}->sendRequest(
		"url"   => $self->{agent}->{config}->{server}[0] . "/api/agents",
		message => $json_text,
		method  => "POST"

lib/Armadito/Agent/Task/Getjobs.pm  view on Meta::CPAN

use warnings;
use base 'Armadito::Agent::Task';

use Armadito::Agent::Storage;
use Data::Dumper;
use JSON;

sub new {
	my ( $class, %params ) = @_;

	my $self = $class->SUPER::new(%params);

	if ( $params{debug} ) {
		$self->{debug} = 1;
	}

	my $task = {
		name      => "Getjobs",
		antivirus => $self->{agent}->{antivirus}->getJobj()
	};

lib/Armadito/Agent/Task/Getjobs.pm  view on Meta::CPAN

	$self->{logger}->info( "Error Response : " . $response->content() );
	my $obj = from_json( $response->content(), { utf8 => 1 } );
	$self->{logger}->error( Dumper($obj) );

	return $self;
}

sub run {
	my ( $self, %params ) = @_;

	$self = $self->SUPER::run(%params);

	my $response = $self->{glpi_client}->sendRequest(
		"url" => $self->{agent}->{config}->{server}[0] . "/api/jobs",
		args  => {
			antivirus => $self->{jobj}->{task}->{antivirus}->{name},
			agent_id  => $self->{jobj}->{agent_id}
		},
		method => "GET"
	);

lib/Armadito/Agent/Task/Runjobs.pm  view on Meta::CPAN


use Armadito::Agent::Storage;
use Data::Dumper;
use MIME::Base64;
use Try::Tiny;
use JSON;

sub new {
	my ( $class, %params ) = @_;

	my $self = $class->SUPER::new(%params);

	if ( $params{debug} ) {
		$self->{debug} = 1;
	}

	my $task = {
		name      => "Runjobs",
		antivirus => $self->{agent}->{antivirus}->getJobj()
	};

lib/Armadito/Agent/Task/Runjobs.pm  view on Meta::CPAN

	$self->{logger}->info( "Error Response : " . $response->content() );
	my $obj = from_json( $response->content(), { utf8 => 1 } );
	$self->{logger}->error( Dumper($obj) );

	return $self;
}

sub run {
	my ( $self, %params ) = @_;

	$self = $self->SUPER::run(%params);
	$self = $self->_getStoredJobs();
	$self = $self->_sortJobsByPriority();
	$self = $self->_runJobs();

	return $self;
}

sub _runJob {
	my ( $self, $job ) = @_;
	my $config     = ();

lib/Armadito/Agent/Task/Scan.pm  view on Meta::CPAN

use warnings;
use base 'Armadito::Agent::Task';

use MIME::Base64;
use Data::Dumper;
use JSON;

sub new {
	my ( $class, %params ) = @_;

	my $self = $class->SUPER::new(%params);

	if ( $params{debug} ) {
		$self->{debug} = 1;
	}

	my $task = {
		name      => "Scan",
		antivirus => $self->{agent}->{antivirus}->getJobj()
	};

lib/Armadito/Agent/Task/Scheduler.pm  view on Meta::CPAN

use warnings;
use base 'Armadito::Agent::Task';

use MIME::Base64;
use Data::Dumper;
use JSON;

sub new {
	my ( $class, %params ) = @_;

	my $self = $class->SUPER::new(%params);

	if ( $params{debug} ) {
		$self->{debug} = 1;
	}

	my $task = {
		name      => "Scheduler",
		antivirus => $self->{agent}->{antivirus}->getJobj()
	};

lib/Armadito/Agent/Task/State.pm  view on Meta::CPAN

use strict;
use warnings;
use base 'Armadito::Agent::Task';

use Data::Dumper;
use JSON;

sub new {
	my ( $class, %params ) = @_;

	my $self = $class->SUPER::new(%params);

	if ( $params{debug} ) {
		$self->{debug} = 1;
	}

	my $task = {
		name      => "State",
		antivirus => $self->{agent}->{antivirus}->getJobj()
	};



( run in 0.628 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )