Metabrik-Repository
view release on metacpan or search on metacpan
lib/Metabrik/Database/Cvesearch.pm view on Meta::CPAN
};
}
#
# https://github.com/cve-search/cve-search
#
sub brik_use_properties {
my $self = shift;
my $global_datadir = defined($self->global) && $self->global->datadir
|| defined($ENV{HOME}) && $ENV{HOME}."/metabrik"
|| '/tmp/metabrik';
my $repo = $global_datadir."/devel-git/cve-search";
return {
attributes_default => {
repo => $repo,
},
};
}
sub install {
my $self = shift;
$self->SUPER::install(@_) or return;
my $url = 'https://github.com/cve-search/cve-search';
my $dg = Metabrik::Devel::Git->new_from_brik_init($self) or return;
my $repo = $self->repo;
if (-d $repo) {
$repo = $dg->update($url) or return;
}
else {
$repo = $dg->clone($url) or return;
}
$self->sudo_execute('pip3 install -r '.$repo.'/requirements.txt') or return;
return 1;
}
sub init_database {
my $self = shift;
my $repo = $self->repo;
for my $this (
'sbin/db_mgmt.py -p', 'sbin/db_mgmt_cpe_dictionary.py', 'sbin/db_updater.py -c'
) {
my $cmd = $repo.'/'.$this;
$self->log->verbose("init_database: cmd [$cmd]");
$self->execute($cmd);
}
return 1;
}
sub update_database {
my $self = shift;
my $repo = $self->repo;
for my $this ('sbin/db_updater.py -v') {
my $cmd = $repo.'/'.$this;
$self->execute($cmd);
}
return 1;
}
sub repopulate_database {
my $self = shift;
my $repo = $self->repo;
for my $this ('sbin/db_updater.py -v -f') {
my $cmd = $repo.'/'.$this;
$self->execute($cmd);
}
return 1;
}
#
# run database::cvesearch cpe_search cisco:ios:12.4
#
sub cpe_search {
my $self = shift;
my ($cpe) = @_;
$self->brik_help_run_undef_arg('cpe_search', $cpe) or return;
my $repo = $self->repo;
my $cmd = $repo.'/bin/search.py -o json -p '.$cpe;
my $json = $self->capture($cmd) or return;
if (@$json <= 0 || (@$json == 1 && $json->[0] eq 'undef')) {
return $self->log->error("search_cpe: invalid response: ".join('', @$json));
}
my $sj = Metabrik::String::Json->new_from_brik_init($self) or return;
my @results = ();
for my $this (@$json) {
my $r = $sj->decode($this) or next;
push @results, $r;
}
return \@results;
}
#
# run database::cvesearch cve_search CVE-2010-3333
#
sub cve_search {
my $self = shift;
my ($cve) = @_;
( run in 0.598 second using v1.01-cache-2.11-cpan-39bf76dae61 )