| 1 | package Mail::DMARC::HTTP; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | our $VERSION = '2.20261110'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use feature 'signatures'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use feature 'try'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | no warnings 'experimental::try'; ## no critic (ProhibitNoWarnings) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use parent 'Net::Server::HTTP'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use File::ShareDir; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use IO::Uncompress::Gunzip; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use JSON -convert_blessed_universally; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | our $report; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Mail::DMARC::PurePerl; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | my %mimes = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | css => 'text/css', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | html => 'text/html', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | js => 'application/javascript', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | json => 'application/json', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | sub new($class) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | return bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub dmarc_httpd( $self, $http_report ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dmarc_httpd: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | $report = $http_report; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | my $port = $report->config->{http}{port} || 8080; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$Mail::DMARC::HTTP::report->config->{'http'}{'port'} || 8080
MC/DC0%0/1
$Mail::DMARC::HTTP::report->config->{'http'}{'port'} || 8080
$Mail::DMARC::HTTP::report->config->{'http'}{'port'}
Truth table0%0/2
A
A= $Mail::DMARC::HTTP::report->config->{'http'}{'port'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my $ports = $report->config->{https}{port}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $sslkey = $report->config->{https}{ssl_key}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my $sslcrt = $report->config->{https}{ssl_crt}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | warn_unusable_post_max(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | Net::Server::HTTP->run( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | app => sub {&dmarc_dispatch}, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | port => [ $port, ( ( $ports && $sslkey && $sslcrt ) ? "$ports/ssl" : () ) ], | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/6
$ports and $sslkey and $sslcrt
$ports and $sslkey
MC/DC0%0/3
$ports and $sslkey and $sslcrt
$ports
$sslkey
$sslcrt
Truth table0%0/4
A and B and C
A= $portsB= $sslkeyC= $sslcrt
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | ipv => '*', # IPv6 if available | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ( $sslkey ? ( SSL_key_file => $sslkey ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ( $sslcrt ? ( SSL_cert_file => $sslcrt ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | log_file => 'Sys::Syslog', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | syslog_ident => 'mail_dmarc', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | syslog_facility => 'MAIL', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub dmarc_dispatch($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dmarc_dispatch: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my $path = $self->{request_info}{request_path}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ($path) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | warn "path: $path\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # Parse QUERY_STRING once here via URI (not CGI->new->Vars) to avoid | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # CGI.pm state issues in persistent Net::Server::HTTP processes. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | my %vars | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | = URI->new( 'http://x/?' . ( $ENV{QUERY_STRING} // '' ) )->query_form; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ENV{"QUERY_STRING"} // ""
MC/DC0%0/1
$ENV{"QUERY_STRING"} // ""
$ENV{"QUERY_STRING"}
Truth table0%0/2
A
A= $ENV{"QUERY_STRING"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | return report_json_report( \%vars ) if $path eq '/dmarc/json/report'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | return report_json_rr( \%vars ) if $path eq '/dmarc/json/row'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | return report_json_domains( \%vars ) if $path eq '/dmarc/json/domains'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | return serve_validator() if $path eq '/dmarc/json/validate'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my %agg = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | '/dmarc/json/summary' => 'get_summary', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | '/dmarc/json/timeseries' => 'get_timeseries', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | '/dmarc/json/sources' => 'get_sources', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | '/dmarc/json/source' => 'get_source_detail', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | return report_json_agg( $agg{$path}, \%vars ) if $agg{$path}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | return serve_file($path) if $path =~ /\.(?:js|css|html|gz)$/x; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | return serve_file('/dmarc/index.html'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 8 | ▶ | sub serve_pretty_error( $error = undef ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serve_pretty_error: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 8 | ▶ | $error ||= 'Sorry, that operation is not supported.'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$error ||= "Sorry, that operation is not supported."
MC/DC0%0/1
$error ||= "Sorry, that operation is not supported."
$error
Truth table50%1/2
A
A= $error
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 8 | return print <<"EO_ERROR" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | Content-Type: text/html | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | <p>$error</p> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | EO_ERROR | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | ▶ | sub return_json_error($err) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
return_json_error: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | #warn $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 3 | print JSON->new->utf8->encode( { err => $err } ); # to HTTP client | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 3 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 3 | return $err; # to caller | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | my $POST_MAX_DEFAULT = 10 * 1024 * 1024; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | my $BYTE_COUNT = qr/^[1-9][0-9]*$/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # 0 is not a way to lift the cap; say so rather than quietly using the default | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 9 | ▶ | sub warn_unusable_post_max() { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
warn_unusable_post_max: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 9 | my $max = $report->config->{http}{post_max}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 9 | ▶ | return if !defined $max || $max eq '' || $max =~ $BYTE_COUNT; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not defined $max or $max eq "" or $max =~ /$BYTE_COUNT/
not defined $max or $max eq ""
MC/DC100%3/3
not defined $max or $max eq "" or $max =~ /$BYTE_COUNT/
not defined $max
$max eq ""
$max =~ /$BYTE_COUNT/
Truth table100%4/4
not(A) or B or C
A= not defined $maxB= $max eq ""C= $max =~ /$BYTE_COUNT/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 6 | warn "post_max '$max' is not a byte count; using " . post_max() . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 25 | ▶ | sub post_max() { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
post_max: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 25 | ▶ | my $max = $report ? $report->config->{http}{post_max} : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 25 | ▶ | return defined $max && $max =~ $BYTE_COUNT ? $max : $POST_MAX_DEFAULT; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $max and $max =~ /$BYTE_COUNT/
MC/DC100%2/2
defined $max and $max =~ /$BYTE_COUNT/
defined $max
$max =~ /$BYTE_COUNT/
Truth table100%3/3
A and B
A= defined $maxB= $max =~ /$BYTE_COUNT/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # The client is still sending when we refuse an oversized body. Closing with | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # its bytes unread makes the kernel answer RST, which discards the error we | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # just queued, so read them off the wire and drop them. Only up to post_max | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # again: past that the caller is not worth the bandwidth and gets the reset. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 4 | ▶ | sub discard_post_body($len) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
discard_post_body: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 4 | my $max = post_max(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 4 | ▶ | return if $len > 2 * $max; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 3 | my $seen = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 3 | ▶ | while ( $seen < $len ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 3 | my $want = $len - $seen; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 3 | ▶ | my $got = read STDIN, my $chunk, $want < 65536 ? $want : 65536; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 3 | ▶ | last if !$got; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 2 | $seen += $got; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # '' when there is no body, undef when it is larger than post_max | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | ▶ | sub read_post_body() { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_post_body: called CC=6 SCAR=27.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 2 | ▶ | my ($len) = ( $ENV{CONTENT_LENGTH} // '' ) =~ /^([0-9]+)$/ or return ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$ENV{"CONTENT_LENGTH"} // ""
MC/DC0%0/1
$ENV{"CONTENT_LENGTH"} // ""
$ENV{"CONTENT_LENGTH"}
Truth table50%1/2
A
A= $ENV{"CONTENT_LENGTH"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | ▶ | if ( $len > post_max() ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 2 | discard_post_body($len); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # a short read would truncate the JSON and leave the rest of the body to be | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # parsed as the next request on a keep-alive connection | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $body = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | while ( length $body < $len ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $got = read STDIN, my $chunk, $len - length $body; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | last if !$got; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $body .= $chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | return $body; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 7 | ▶ | sub serve_validator( $post = undef, $resolver = undef ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serve_validator: called CC=9 SCAR=22.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 7 | my $too_large; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 7 | ▶ | if ( !defined $post ) { # passed in for testing | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | $post = read_post_body(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | $too_large = !defined $post; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 7 | my $json = JSON->new->utf8; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 7 | print "Content-Type: application/json\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 7 | ▶ | if ($too_large) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | return return_json_error( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 'POST data larger than post_max of ' . post_max() . ' bytes' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 6 | ▶ | if ( !$post ) { return return_json_error("missing POST data"); } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 5 | my ( $input, $dmpp, $res ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 5 | try { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 5 | $input = $json->decode($post); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | catch ($error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | return return_json_error($error); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 4 | ▶ | if ( !$input || !ref $input ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$input and ref $input
MC/DC0%0/2
$input and ref $input
$input
ref $input
Truth table33%1/3
A and B
A= $inputB= ref $input
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | return return_json_error("invalid request $post"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 4 | try { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 4 | $dmpp = Mail::DMARC::PurePerl->new(%$input); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | catch ($error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | return return_json_error($error); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 4 | ▶ | $dmpp->set_resolver($resolver) if $resolver; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 4 | try { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 4 | $res = $dmpp->validate(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | catch ($error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | return return_json_error($error); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 4 | my $return = $json->allow_blessed->convert_blessed->encode($res); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 4 | print "$return\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 4 | return $return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # The viewer's assets are a known set of plain names, so each path segment is | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # matched against what is allowed rather than checked for what is not. A | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # blacklist of traversal sequences has to anticipate every encoding that | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # survives the request parser; requiring a leading alphanumeric rejects '.', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # '..' and dotfiles outright, and leaves no way to name a directory above the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # share directory. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1 | my $SAFE_SEGMENT = qr/\A[A-Za-z0-9][A-Za-z0-9._-]*\z/x; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 11 | ▶ | sub serve_file($path) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serve_file: called CC=12 SCAR=26.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 11 | my @bits = split /\//, $path; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 11 | shift @bits; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 11 | ▶ | return serve_pretty_error("file not found") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $bits[0] or "dmarc" ne $bits[0]
MC/DC0%0/2
not $bits[0] or "dmarc" ne $bits[0]
not $bits[0]
"dmarc" ne $bits[0]
Truth table33%1/3
not(A) or B
A= not $bits[0]B= "dmarc" ne $bits[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | if ( !$bits[0] || 'dmarc' ne $bits[0] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 11 | shift @bits; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 11 | ▶ | return serve_pretty_error("no such file") if !@bits; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 11 | foreach my $bit (@bits) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 13 | ▶ | return serve_pretty_error("no such file") if $bit !~ $SAFE_SEGMENT; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 4 | $path = join '/', @bits; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 4 | my $file = $bits[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 4 | my ($extension) = ( split /\./, $file )[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 4 | ▶ | return serve_pretty_error("$extension not recognized") if !$mimes{$extension}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 3 | my $dir = "share/html"; # distribution dir | |||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 3 | ▶ | if ( !-d $dir ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | $dir = File::ShareDir::dist_dir('Mail-DMARC'); # installed loc. | |||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | $dir .= "/html"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 3 | ▶ | return serve_pretty_error("no such path") if !$dir; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 3 | ▶ | return serve_gzip("$dir/$path.gz") if -f "$dir/$path.gz"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 3 | ▶ | return serve_pretty_error("no such file") if !-f "$dir/$path"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 3 | ▶ | open my $FH, '<', "$dir/$path" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | or return serve_pretty_error("unable to read $dir/$path: $!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 3 | print "Content-Type: $mimes{$extension}\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 3 | print <$FH>; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 3 | close $FH; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | sub serve_gzip($file) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serve_gzip: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | open my $FH, '<', "$file" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | or return serve_pretty_error("unable to read $file: $!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | my $contents = do { local $/; <$FH> }; ## no critic (Local) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | close $FH; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my $decomp = substr( $file, 0, -3 ); # remove .gz suffix | |||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my ($extension) = ( split /\./, $decomp )[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # browser accepts gz encoding, serve compressed | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | if ( grep {/gzip/} $ENV{HTTP_ACCEPT_ENCODING} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my $length = length $contents; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | return print <<"EO_GZ" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | Content-Length: $length | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | Content-Type: $mimes{$extension} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | Content-Encoding: gzip | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | $contents | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | EO_GZ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | # browser doesn't support gzip, decompress and serve | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $out; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | IO::Uncompress::Gunzip::gunzip( \$contents => \$out ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | or return serve_pretty_error("unable to decompress"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | my $length = length $out; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | return print <<"EO_UNGZ" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | Content-Length: $length | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | Content-Type: $mimes{$extension} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | $out | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | EO_UNGZ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 1 | my @AGG_INT_PARAMS = qw/ since until start length /; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | my @AGG_STR_PARAMS = qw/ from_domain author source_ip sort_col /; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | # Which reports to count: those others sent us about our domains, those this | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # host is preparing to send about other people's, or both. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 1 | my %AGG_REPORT_KINDS = map { $_ => 1 } qw/ received outgoing all /; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | my $AGG_DEFAULT_DAYS = 30; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 11 | ▶ | sub agg_params($vars) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
agg_params: called CC=12 SCAR=25.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 11 | my %args; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 11 | foreach my $param (@AGG_INT_PARAMS) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 44 | ▶ | next if !defined $vars->{$param}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 9 | ▶ | next if $vars->{$param} !~ /\A-?[0-9]{1,12}\z/x; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 4 | $args{$param} = 0 + $vars->{$param}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 11 | foreach my $param (@AGG_STR_PARAMS) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 44 | ▶ | next if !defined $vars->{$param} || '' eq $vars->{$param}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $vars->{$param} or "" eq $vars->{$param}
MC/DC50%1/2
not defined $vars->{$param} or "" eq $vars->{$param}
not defined $vars->{$param}
"" eq $vars->{$param}
Truth table66%2/3
not(A) or B
A= not defined $vars->{$param}B= "" eq $vars->{$param}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 5 | ▶ | next if length $vars->{$param} > 253; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 4 | $args{$param} = $vars->{$param}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | $args{reports} = $vars->{reports} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 11 | ▶ | if defined $vars->{reports} && $AGG_REPORT_KINDS{ $vars->{reports} }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $vars->{"reports"} and $AGG_REPORT_KINDS{$vars->{"reports"}}
MC/DC0%0/2
defined $vars->{"reports"} and $AGG_REPORT_KINDS{$vars->{"reports"}}
defined $vars->{"reports"}
$AGG_REPORT_KINDS{$vars->{"reports"}}
Truth table33%1/3
A and B
A= defined $vars->{"reports"}B= $AGG_REPORT_KINDS{$vars->{"reports"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # Without a default window an unparameterized request would aggregate the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | # entire report history. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 11 | ▶ | $args{until} //= time; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{"until"} //= time
MC/DC100%1/1
$args{"until"} //= time
$args{"until"}
Truth table100%2/2
A
A= $args{"until"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 11 | ▶ | $args{since} //= $args{until} - ( $AGG_DEFAULT_DAYS * 86400 ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{"since"} //= $args{"until"} - $AGG_DEFAULT_DAYS * 86400
MC/DC100%1/1
$args{"since"} //= $args{"until"} - $AGG_DEFAULT_DAYS * 86400
$args{"since"}
Truth table100%2/2
A
A= $args{"since"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 11 | return %args; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | sub serve_json($data) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serve_json: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | print "Content-Type: application/json\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | print encode_json $data; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | sub report_json_agg( $method, $vars ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
report_json_agg: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | my $backend = $report->store->backend; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | if ( !$backend->can($method) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | print "Content-Type: application/json\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | return return_json_error("report store does not support $method"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my $data; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | try { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $data = $backend->$method( agg_params($vars) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | catch ($error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | print "Content-Type: application/json\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | return return_json_error("$error"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | return serve_json($data); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | sub report_json_domains($vars) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
report_json_domains: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my $data; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | my @args; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | push @args, reports => $vars->{reports} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | if defined $vars->{reports} && $AGG_REPORT_KINDS{ $vars->{reports} }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $vars->{"reports"} and $AGG_REPORT_KINDS{$vars->{"reports"}}
MC/DC0%0/2
defined $vars->{"reports"} and $AGG_REPORT_KINDS{$vars->{"reports"}}
defined $vars->{"reports"}
$AGG_REPORT_KINDS{$vars->{"reports"}}
Truth table0%0/3
A and B
A= defined $vars->{"reports"}B= $AGG_REPORT_KINDS{$vars->{"reports"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | try { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | $data = $report->store->backend->get_report_domains(@args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | catch ($error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | print "Content-Type: application/json\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | return return_json_error("$error"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | return serve_json($data); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | sub report_json_report($vars) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
report_json_report: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | my %args = %$vars; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | delete $args{reports} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | if defined $args{reports} && !$AGG_REPORT_KINDS{ $args{reports} }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $args{"reports"} and not $AGG_REPORT_KINDS{$args{"reports"}}
MC/DC0%0/2
defined $args{"reports"} and not $AGG_REPORT_KINDS{$args{"reports"}}
defined $args{"reports"}
not $AGG_REPORT_KINDS{$args{"reports"}}
Truth table0%0/3
A and not(B)
A= defined $args{"reports"}B= not $AGG_REPORT_KINDS{$args{"reports"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | return serve_json( $report->store->backend->get_report(%args) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | sub report_json_rr($vars) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
report_json_rr: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | return serve_json( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | $report->store->backend->get_rr( rid => $vars->{rid} ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||