| 1 | package WebService::AbuseIPDB::Category; | ||||||||||||||||||||
| 2 | # | ||||||||||||||||||||
| 3 | #=============================================================================== | ||||||||||||||||||||
| 4 | # | ||||||||||||||||||||
| 5 | # FILE: Category.pm | ||||||||||||||||||||
| 6 | # | ||||||||||||||||||||
| 7 | # DESCRIPTION: Category class | ||||||||||||||||||||
| 8 | # | ||||||||||||||||||||
| 9 | # AUTHOR: Pete Houston (pete), cpan@openstrike.co.uk | ||||||||||||||||||||
| 10 | # ORGANIZATION: Openstrike | ||||||||||||||||||||
| 11 | # CREATED: 16/08/19 17:02:49 | ||||||||||||||||||||
| 12 | #=============================================================================== | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 3 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | 3 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 3 | ▶ | use WebService::AbuseIPDB; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 3 | our $VERSION = $WebService::AbuseIPDB::VERSION; | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 3 | my %by_id = ( | |||||||||||||||||||
| 24 | 1 => 'DNS Compromise', | ||||||||||||||||||||
| 25 | 2 => 'DNS Poisoning', | ||||||||||||||||||||
| 26 | 3 => 'Fraud Orders', | ||||||||||||||||||||
| 27 | 4 => 'DDoS Attack', | ||||||||||||||||||||
| 28 | 5 => 'FTP Brute-Force', | ||||||||||||||||||||
| 29 | 6 => 'Ping of Death', | ||||||||||||||||||||
| 30 | 7 => 'Phishing', | ||||||||||||||||||||
| 31 | 8 => 'Fraud VoIP', | ||||||||||||||||||||
| 32 | 9 => 'Open Proxy', | ||||||||||||||||||||
| 33 | 10 => 'Web Spam', | ||||||||||||||||||||
| 34 | 11 => 'Email Spam', | ||||||||||||||||||||
| 35 | 12 => 'Blog Spam', | ||||||||||||||||||||
| 36 | 13 => 'VPN IP', | ||||||||||||||||||||
| 37 | 14 => 'Port Scan', | ||||||||||||||||||||
| 38 | 15 => 'Hacking', | ||||||||||||||||||||
| 39 | 16 => 'SQL Injection', | ||||||||||||||||||||
| 40 | 17 => 'Spoofing', | ||||||||||||||||||||
| 41 | 18 => 'Brute-Force', | ||||||||||||||||||||
| 42 | 19 => 'Bad Web Bot', | ||||||||||||||||||||
| 43 | 20 => 'Exploited Host', | ||||||||||||||||||||
| 44 | 21 => 'Web App Attack', | ||||||||||||||||||||
| 45 | 22 => 'SSH', | ||||||||||||||||||||
| 46 | 23 => 'IoT Targeted', | ||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 3 | my %by_name; | |||||||||||||||||||
| 50 | 3 | $by_name{$by_id{$_}} = $_ for keys %by_id; | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | sub new { | ||||||||||||||||||||
| 53 | 78 | ▶ | my ($class, $cat) = @_; | ||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 54 | 78 | my $self; | |||||||||||||||||||
| 55 | 78 | ▶ | unless (defined $cat) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 1 | carp "'new' requires an argument"; | |||||||||||||||||||
| 57 | 1 | return; | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | 77 | ▶ | if ($by_id{$cat}) { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 60 | 27 | $self = { id => $cat, name => $by_id{$cat} }; | |||||||||||||||||||
| 61 | } elsif ($by_name{$cat}) { | ||||||||||||||||||||
| 62 | 23 | $self = { id => $by_name{$cat}, name => $cat }; | |||||||||||||||||||
| 63 | ▶ | } elsif (blessed ($cat) && $cat->isa ($class)) { | |||||||||||||||||||
|
Condition100%3/3
builtin::blessed($cat) and $cat->isa($class)
MC/DC100%2/2
builtin::blessed($cat) and $cat->isa($class)
builtin::blessed($cat)
$cat->isa($class)
Truth table100%3/3
A and B
A= builtin::blessed($cat)B= $cat->isa($class)
| |||||||||||||||||||||
| 64 | 23 | return $cat; | |||||||||||||||||||
| 65 | } else { | ||||||||||||||||||||
| 66 | 4 | carp "'$cat' is not a valid category identifier"; | |||||||||||||||||||
| 67 | 4 | return; | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | 50 | bless ($self, $class); | |||||||||||||||||||
| 70 | 50 | return $self; | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | # Accessors | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 50 | ▶ | sub id { return shift->{id} }; | ||||||||||||||||||
|
Subroutine
id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 76 | 92 | ▶ | sub name { return shift->{name} }; | ||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 3 | 1; | |||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | __END__ | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | =pod | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | =encoding utf8 | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | =head1 NAME | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | WebService::AbuseIPDB::Category - Category names and numbers for | ||||||||||||||||||||
| 89 | WebService::AbuseIPDB | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | =head1 SYNOPSIS | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | use WebService::AbuseIPDB::Category; | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | my $cat = WebService::AbuseIPDB::Category->new (18); | ||||||||||||||||||||
| 96 | print $cat->name; | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | $cat = WebService::AbuseIPDB::Category->new ('Web App Attack'); | ||||||||||||||||||||
| 99 | print $cat->id; | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | =head1 DESCRIPTION | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | This class stores a list of category IDs and names for use with | ||||||||||||||||||||
| 104 | L<WebService::AbuseIPDB>. | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | =head2 METHODS | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | =head2 new | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | my $catobj = WebService::AbuseIPDB::Category->new ($category) | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | The constructor takes one argument which is the category to be | ||||||||||||||||||||
| 113 | instantiated. This should be either the number of the category or the | ||||||||||||||||||||
| 114 | name of the category. If called with an existing category object it will | ||||||||||||||||||||
| 115 | return that same object as a no-op. If you would prefer a copy of the | ||||||||||||||||||||
| 116 | object then call it with the name or number instead. eg. | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | my $catcopy = WebService::AbuseIPDB::Category->new ($catobj->id) | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | =head2 id | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | my $id = $catobj->id; | ||||||||||||||||||||
| 123 | printf "%i\n", $id; | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | A method for returning the numerical ID of the category. | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | =head2 name | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | my $name = $catobj->name; | ||||||||||||||||||||
| 130 | printf "%s\n", $name; | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | A method for returning the name of the category. | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | =head1 AUTHOR | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | Pete Houston, C<< <cpan at openstrike.co.uk> >> | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | =head1 SEE ALSO | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | L<WebService::AbuseIPDB>, L<https://www.abuseipdb.com/categories> | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | =head1 LICENCE AND COPYRIGHT | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | Copyright © 2020 Pete Houston | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||
| 147 | it under the terms of the GNU General Public License as published by | ||||||||||||||||||||
| 148 | the Free Software Foundation; version 2 dated June, 1991 or at your option | ||||||||||||||||||||
| 149 | any later version. | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | This program is distributed in the hope that it will be useful, | ||||||||||||||||||||
| 152 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||
| 153 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||
| 154 | GNU General Public License for more details. | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | A copy of the GNU General Public License is available in the source tree; | ||||||||||||||||||||
| 157 | if not, write to the Free Software Foundation, Inc., | ||||||||||||||||||||
| 158 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | =cut | ||||||||||||||||||||