logo

cve-client

CLI-based client / toolbox for CVE.org
commit: 94ff768380a9d6d204b0b11404474b7d7567e546
parent eedb01f8d8c84b944ec948e029f75e181c8777fd
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sat,  2 Oct 2021 22:38:19 +0200

Perl tidy

Diffstat:

A.perltidyrc1+
Mcve-client.pl60++++++++++++++++++++++++++++++++----------------------------
2 files changed, 33 insertions(+), 28 deletions(-)

diff --git a/.perltidyrc b/.perltidyrc @@ -0,0 +1 @@ +-b -t -i=4 -et=4 -pt=2 -bt=2 -ce -utf8 diff --git a/cve-client.pl b/cve-client.pl @@ -4,7 +4,7 @@ # SPDX-License-Identifier: AGPL-3.0-only use strict; use utf8; -no warnings; # Wide Character… +no warnings; # Wide Character… use Getopt::Std; use LWP::UserAgent; @@ -12,7 +12,7 @@ use JSON::MaybeXS; my $json = JSON::MaybeXS->new(utf8 => 1); -my %options=(); +my %options = (); sub usage { print "usage: ap-fetch.pl [-r|-j] <CVE-ID>\n"; @@ -25,36 +25,37 @@ sub usage { sub print_cve { my ($object, $cve_id) = @_; - print "CVE ID: ", $cve_id, "\n\n"; - if($object->{'data_version'} != "4.0") { - print "Warning: Got unknown CVE format \"", $object->{'data_version'}, "\"\n"; + if ($object->{'data_version'} != "4.0") { + print "Warning: Got unknown CVE format \"", $object->{'data_version'}, + "\"\n"; } - if($object->{'CVE_data_meta'}->{'ID'} != $cve_id) { - print "Warning: Got ", $object->{'CVE_data_meta'}->{'ID'}, " instead of ", $cve_id, "\n"; + if ($object->{'CVE_data_meta'}->{'ID'} != $cve_id) { + print "Warning: Got ", $object->{'CVE_data_meta'}->{'ID'}, + " instead of ", $cve_id, "\n"; } - if($object->{'description'}->{'description_data'}) { + if ($object->{'description'}->{'description_data'}) { my $descs = $object->{'description'}->{'description_data'}; - foreach(@{$descs}) { - print "Description Language: ", $_->{'lang'}, "\n"; - print "Description: «\n", $_->{'value'}, "\n»\n"; + foreach (@{$descs}) { + print "Description Language: ", $_->{'lang'}, "\n"; + print "Description: «\n", $_->{'value'}, "\n»\n"; } } else { print "Warning: No CVE description could be found!"; } - if($object->{'references'}->{'reference_data'}) { + if ($object->{'references'}->{'reference_data'}) { my $refs = $object->{'references'}->{'reference_data'}; - foreach(@{$refs}) { + foreach (@{$refs}) { print "Reference Source: ", $_->{'refsource'}, "\n"; - print "- Name: ", $_->{'name'}, "\n" if $_->{'name'}; - print "- URL: ", $_->{'url'}, "\n" if $_->{'url'}; - print "\n" + print "- Name: ", $_->{'name'}, "\n" if $_->{'name'}; + print "- URL: ", $_->{'url'}, "\n" if $_->{'url'}; + print "\n"; } } else { print "Warning: No CVE references could be found!"; @@ -63,24 +64,27 @@ sub print_cve { sub fetch_cve { my ($cve_id) = @_; - my $url = 'https://www.cve.org/api/?action=getCveById&cveId='.$cve_id; + my $url = 'https://www.cve.org/api/?action=getCveById&cveId=' . $cve_id; + #print "Fetching: ", $url, "\n"; my $ua = LWP::UserAgent->new; $ua->agent("CVE-Client fetch <https://hacktivis.me/git/cve-client/>"); my $req = HTTP::Request->new(GET => $url); + #$req->header('Accept' => 'application/json'); - + my $res = $ua->request($req); - - if($res->is_success) { - my $content_type = $res->header("Content-Type"); + + if ($res->is_success) { + my $content_type = $res->header("Content-Type"); my $content_match = 'application/json'; - - if($content_type == $content_match) { - if(defined $options{r}) { + + if ($content_type == $content_match) { + if (defined $options{r}) { print $res->content; - } elsif(defined $options{j}) { - open(my $pipe_out, '|-', 'jq .') or die "Couldn't open a pipe into jq: $!"; + } elsif (defined $options{j}) { + open(my $pipe_out, '|-', 'jq .') + or die "Couldn't open a pipe into jq: $!"; print $pipe_out $res->content; } else { my $object = $json->decode($res->content); @@ -96,9 +100,9 @@ sub fetch_cve { getopts("rj", \%options); -if($#ARGV != 0) { usage; } +if ($#ARGV != 0) { usage; } -if($ARGV[0] =~ /^CVE-\d{4}-\d+$/) { +if ($ARGV[0] =~ /^CVE-\d{4}-\d+$/) { fetch_cve($ARGV[0]); } else { usage();