| 1 | package DNS::Robot; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use HTTP::Tiny; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use JSON::PP qw(encode_json decode_json); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 13 | 4 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||
| 14 | my $self = bless { | ||||||||||||||||||||||||||||||||
| 15 | base_url => $args{base_url} || 'https://dnsrobot.net/api', | ||||||||||||||||||||||||||||||||
| 16 | user_agent => $args{user_agent} || "DNS-Robot-Perl/$VERSION", | ||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | timeout => $args{timeout} || 30, | ||||||||||||||||||||||||||||||
|
Condition100%6/6
$args{'base_url'} || 'https://dnsrobot.net/api'
$args{'user_agent'} || "DNS-Robot-Perl/$DNS::Robot::VERSION"
$args{'timeout'} || 30
MC/DC100%1/1
$args{'base_url'} || 'https://dnsrobot.net/api'
$args{'base_url'}
MC/DC100%1/1
$args{'user_agent'} || "DNS-Robot-Perl/$DNS::Robot::VERSION"
$args{'user_agent'}
MC/DC100%1/1
$args{'timeout'} || 30
$args{'timeout'}
Truth table100%2/2
A
A= $args{'base_url'}
Truth table100%2/2
A
A= $args{'user_agent'}
Truth table100%2/2
A
A= $args{'timeout'}
| |||||||||||||||||||||||||||||||||
| 18 | }, $class; | ||||||||||||||||||||||||||||||||
| 19 | $self->{http} = HTTP::Tiny->new( | ||||||||||||||||||||||||||||||||
| 20 | agent => $self->{user_agent}, | ||||||||||||||||||||||||||||||||
| 21 | timeout => $self->{timeout}, | ||||||||||||||||||||||||||||||||
| 22 | 4 | ); | |||||||||||||||||||||||||||||||
| 23 | 4 | return $self; | |||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | # ── Internal helpers ── | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub _post { | ||||||||||||||||||||||||||||||
|
Subroutine
_post: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 29 | 0 | my ($self, $endpoint, $payload) = @_; | |||||||||||||||||||||||||||||||
| 30 | 0 | my $url = "$self->{base_url}/$endpoint"; | |||||||||||||||||||||||||||||||
| 31 | 0 | my $body = encode_json($payload); | |||||||||||||||||||||||||||||||
| 32 | 0 | my $res = $self->{http}->request('POST', $url, { | |||||||||||||||||||||||||||||||
| 33 | headers => { 'Content-Type' => 'application/json' }, | ||||||||||||||||||||||||||||||||
| 34 | content => $body, | ||||||||||||||||||||||||||||||||
| 35 | }); | ||||||||||||||||||||||||||||||||
| 36 | croak "DNS::Robot: HTTP $res->{status} from $endpoint" | ||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | unless $res->{success}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 38 | 0 | return decode_json($res->{content}); | |||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub _get { | ||||||||||||||||||||||||||||||
|
Subroutine
_get: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 42 | 0 | my ($self, $endpoint, $params) = @_; | |||||||||||||||||||||||||||||||
| 43 | 0 | my $query = join '&', map { "$_=" . _uri_encode($params->{$_}) } sort keys %$params; | |||||||||||||||||||||||||||||||
| 44 | 0 | my $url = "$self->{base_url}/$endpoint?$query"; | |||||||||||||||||||||||||||||||
| 45 | 0 | my $res = $self->{http}->request('GET', $url); | |||||||||||||||||||||||||||||||
| 46 | croak "DNS::Robot: HTTP $res->{status} from $endpoint" | ||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | unless $res->{success}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 48 | 0 | return decode_json($res->{content}); | |||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub _uri_encode { | ||||||||||||||||||||||||||||||
|
Subroutine
_uri_encode: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 52 | 0 | my ($str) = @_; | |||||||||||||||||||||||||||||||
| 53 | 0 | $str =~ s/([^A-Za-z0-9\-._~])/sprintf("%%%02X", ord($1))/ge; | |||||||||||||||||||||||||||||||
| 54 | 0 | return $str; | |||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | # ── Public methods ── | ||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 1 | ▶ | sub dns_lookup { | ||||||||||||||||||||||||||||||
|
Subroutine
dns_lookup: called CC=4 SCAR=21.7
Pod
documented
| |||||||||||||||||||||||||||||||||
| 60 | 1 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 61 | 1 | ▶ | croak "dns_lookup: 'domain' is required" unless $args{domain}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 62 | return $self->_post('dns-query', { | ||||||||||||||||||||||||||||||||
| 63 | domain => $args{domain}, | ||||||||||||||||||||||||||||||||
| 64 | recordType => $args{record_type} || 'A', | ||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | dnsServer => $args{dns_server} || '8.8.8.8', | ||||||||||||||||||||||||||||||
|
Condition0%0/4
$args{'record_type'} || 'A'
$args{'dns_server'} || '8.8.8.8'
MC/DC0%0/1
$args{'record_type'} || 'A'
$args{'record_type'}
MC/DC0%0/1
$args{'dns_server'} || '8.8.8.8'
$args{'dns_server'}
Truth table0%0/2
A
A= $args{'record_type'}
Truth table0%0/2
A
A= $args{'dns_server'}
| |||||||||||||||||||||||||||||||||
| 66 | }); | ||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | sub whois_lookup { | ||||||||||||||||||||||||||||||
|
Subroutine
whois_lookup: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 70 | 1 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 71 | 1 | ▶ | croak "whois_lookup: 'domain' is required" unless $args{domain}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 72 | 0 | return $self->_post('whois', { domain => $args{domain} }); | |||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | sub ssl_check { | ||||||||||||||||||||||||||||||
|
Subroutine
ssl_check: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 76 | 1 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 77 | 1 | ▶ | croak "ssl_check: 'domain' is required" unless $args{domain}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 78 | 0 | return $self->_post('ssl-certificate', { domain => $args{domain} }); | |||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | 1 | ▶ | sub spf_check { | ||||||||||||||||||||||||||||||
|
Subroutine
spf_check: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 82 | 1 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 83 | 1 | ▶ | croak "spf_check: 'domain' is required" unless $args{domain}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 84 | 0 | return $self->_post('spf-checker', { domain => $args{domain} }); | |||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | sub dkim_check { | ||||||||||||||||||||||||||||||
|
Subroutine
dkim_check: called CC=3 SCAR=17.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 88 | 1 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | croak "dkim_check: 'domain' is required" unless $args{domain}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 90 | 0 | my $payload = { domain => $args{domain} }; | |||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | $payload->{selector} = $args{selector} if $args{selector}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 92 | 0 | return $self->_post('dkim-checker', $payload); | |||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | 1 | ▶ | sub dmarc_check { | ||||||||||||||||||||||||||||||
|
Subroutine
dmarc_check: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 96 | 1 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 97 | 1 | ▶ | croak "dmarc_check: 'domain' is required" unless $args{domain}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 98 | 0 | return $self->_post('dmarc-checker', { domain => $args{domain} }); | |||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | 1 | ▶ | sub mx_lookup { | ||||||||||||||||||||||||||||||
|
Subroutine
mx_lookup: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 102 | 1 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 103 | 1 | ▶ | croak "mx_lookup: 'domain' is required" unless $args{domain}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 104 | 0 | return $self->_post('mx-lookup', { domain => $args{domain} }); | |||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | 1 | ▶ | sub ns_lookup { | ||||||||||||||||||||||||||||||
|
Subroutine
ns_lookup: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 108 | 1 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 109 | 1 | ▶ | croak "ns_lookup: 'domain' is required" unless $args{domain}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 110 | 0 | return $self->_post('ns-lookup', { domain => $args{domain} }); | |||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | 1 | ▶ | sub ip_lookup { | ||||||||||||||||||||||||||||||
|
Subroutine
ip_lookup: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 114 | 1 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 115 | 1 | ▶ | croak "ip_lookup: 'ip' is required" unless $args{ip}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 116 | 0 | return $self->_post('ip-info', { ip => $args{ip} }); | |||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | 1 | ▶ | sub http_headers { | ||||||||||||||||||||||||||||||
|
Subroutine
http_headers: called CC=3 SCAR=17.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 120 | 1 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 121 | 1 | ▶ | croak "http_headers: 'url' is required" unless $args{url}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 122 | 0 | my $url = $args{url}; | |||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | $url = "https://$url" unless $url =~ m{^https?://}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 124 | 0 | return $self->_post('http-headers', { url => $url }); | |||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | 2 | ▶ | sub port_check { | ||||||||||||||||||||||||||||||
|
Subroutine
port_check: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 128 | 2 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 129 | 2 | ▶ | croak "port_check: 'host' is required" unless $args{host}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 130 | 1 | ▶ | croak "port_check: 'port' is required" unless $args{port}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 131 | return $self->_get('port-check', { | ||||||||||||||||||||||||||||||||
| 132 | host => $args{host}, | ||||||||||||||||||||||||||||||||
| 133 | port => $args{port}, | ||||||||||||||||||||||||||||||||
| 134 | 0 | }); | |||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | 2 | 1; | |||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | __END__ | ||||||||||||||||||||||||||||||||