line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# api::bluecoat Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Api::Bluecoat; |
7
|
1
|
|
|
1
|
|
639
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik::Client::Rest); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
426
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable rest) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
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
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
39
|
0
|
|
|
|
|
|
my ($uri) = @_; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
0
|
|
|
|
$uri ||= $self->uri; |
42
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('category', $uri) or return; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# If there is neither http:// nor ftp://, we add http:// |
45
|
0
|
0
|
|
|
|
|
if ($uri !~ m{^(?:http|ftp)://}) { |
46
|
0
|
|
|
|
|
|
$uri =~ s{^}{http://}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
$self->log->verbose("category: checking URI [$uri]"); |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
my $r = $self->post({ url => $uri }, 'http://sitereview.bluecoat.com/rest/categorization') |
52
|
|
|
|
|
|
|
or return; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $content = $r->{content}; |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
my $sj = Metabrik::String::Json->new_from_brik_init($self) or return; |
57
|
0
|
0
|
|
|
|
|
my $decode = $sj->decode($content) or return; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Example: Suspicious |
60
|
0
|
0
|
|
|
|
|
if (exists($decode->{categorization})) { |
61
|
0
|
|
|
|
|
|
my $category = $decode->{categorization}; |
62
|
0
|
|
|
|
|
|
$category =~ s/^.*>(.+?)<.*?$/$1/; |
63
|
0
|
0
|
|
|
|
|
if (! $category) { |
64
|
0
|
|
|
|
|
|
$self->log->warning("category: categorization not found in string"); |
65
|
0
|
|
|
|
|
|
$decode = $decode->{categorization}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
else { |
68
|
0
|
|
|
|
|
|
$decode = $category; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
else { |
72
|
0
|
|
|
|
|
|
$self->log->warning("category: categorization key not found in hash"); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
return $decode; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |