Api/Bluecoat.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Api/Abuseipdb.pm ↑ Summary Api/Cvesearch.pm »
1 #
2 # $Id$
3 #
4 # api::bluecoat Brik
5 #
6 package Metabrik::Api::Bluecoat;
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base qw(Metabrik::Client::Rest);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub brik_properties {
13 return {
14 revision => '$Revision$',
15 tags => [ qw(unstable rest) ],
16 author => 'GomoR <GomoR[at]metabrik.org>',
17 license => 'http://opensource.org/licenses/BSD-3-Clause',
18 attributes => {
19 output_mode => [ qw(json|xml) ],
20 },
21 attributes_default => {
22 uri => 'https://localhost:8089',
23 username => 'admin',
24 ssl_verify => 0,
25 output_mode => 'json',
26 },
27 commands => {
28 category => [ qw(uri) ],
29 },
30 require_modules => {
31 'Metabrik::String::Json' => [ ],
32 'Metabrik::String::Xml' => [ ],
33 },
34 };
35 }
36  
37 sub category {
38 my $self = shift;
39 my ($uri) = @_;
40  
41 $uri ||= $self->uri;
42 $self->brik_help_run_undef_arg('category', $uri) or return;
43  
44 # If there is neither http:// nor ftp://, we add http://
45 if ($uri !~ m{^(?:http|ftp)://}) {
46 $uri =~ s{^}{http://};
47 }
48  
49 $self->log->verbose("category: checking URI [$uri]");
50  
51 my $r = $self->post({ url => $uri }, 'http://sitereview.bluecoat.com/rest/categorization')
52 or return;
53  
54 my $content = $r->{content};
55  
56 my $sj = Metabrik::String::Json->new_from_brik_init($self) or return;
57 my $decode = $sj->decode($content) or return;
58  
59 # Example: <a href=\"javascript:showPopupWindow('catdesc.jsp?catnum=92')\">Suspicious</a>
60 if (exists($decode->{categorization})) {
61 my $category = $decode->{categorization};
62 $category =~ s/^.*>(.+?)<.*?$/$1/;
63 if (! $category) {
64 $self->log->warning("category: categorization not found in string");
65 $decode = $decode->{categorization};
66 }
67 else {
68 $decode = $category;
69 }
70 }
71 else {
72 $self->log->warning("category: categorization key not found in hash");
73 }
74  
75 return $decode;
76 }
77  
78 1;
79  
80 __END__
« Api/Abuseipdb.pm ↑ Summary Api/Cvesearch.pm »