Apache/DNAT.pm

filter: Statementstmt 18.7% 9 / 48 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 50.0% 3 / 6 Podpod 0.0% 0 / 3 totaltotal 13.3% 12 / 90 CC 12 SCAR 32.0
CC
12
Cov
12%
directory_bounce
42.0
handler
20.0
UnPort
20.0
CRAP 24.4
« Net/DNAT.pm ↑ Summary
1 package Apache::DNAT;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Socket qw(sockaddr_in inet_aton inet_ntoa);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶eval q{use Apache::Connection; use Apache::Constants qw(DECLINED OK MOVED);};
Subroutine BEGIN: called CC=1 SCAR=1.2
6  
7 sub handler {
8 0 ▶ my $r = shift;
Subroutine handler: not called CC=4 SCAR=30.0
Pod undocumented
9 0 my $c = $r->connection;
10 0 my $old_remote_addr = $c->remote_addr;
11 0 my ($old_port, $old_addr) = sockaddr_in($old_remote_addr);
12 0 $old_addr = inet_ntoa $old_addr;
13 0 ▶ if ($old_addr =~ /^(127|10|192.168|172\.(1[6-9]|2\d|3[01]))\./) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old_addr =~ /^(127|10|192.168|172\.(1[6-9]|2\d|3[01]))\./) 0 0 0
14 # Martian IP so it is safe
15 0 my $headers = $r->headers_in;
16 0 my $new_addr = $headers->{"remote-addr"};
17 0 my $new_port = $headers->{"remote-port"};
18 0 ▶ if ($new_addr && $new_port) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_addr and $new_port) 0 0 0
Condition0%0/3
$new_addr and $new_port
!ll&&!rl&&r
000
MC/DC0%0/2
$new_addr and $new_port
$new_addr $new_port
Truth table0%0/3
A and B
A= $new_addrB= $new_port
ABresult
0X0
100
111
19 0 delete $headers->{"remote-addr"};
20 0 delete $headers->{"remote-port"};
21 0 $c->remote_addr(scalar sockaddr_in($new_port, inet_aton($new_addr)));
22 0 $c->remote_ip($new_addr);
23 }
24 }
25  
26 # Now pretend like I didn't do anything.
27 0 return DECLINED();
28 }
29  
30  
31 sub UnPort {
32 0 ▶ my $r = shift;
Subroutine UnPort: not called CC=4 SCAR=30.0
Pod undocumented
33 0 my $type = $r->content_type;
34 0 ▶ if ($type && $type eq "httpd/unix-directory") {
Branch: 1 branch
BranchTrueFalseTotal
if ($type and $type eq "httpd/unix-directory") 0 0 0
Condition0%0/3
$type and $type eq "httpd/unix-directory"
!ll&&!rl&&r
000
MC/DC0%0/2
$type and $type eq "httpd/unix-directory"
$type $type eq "httpd/unix-directory"
Truth table0%0/3
A and B
A= $typeB= $type eq "httpd/unix-directory"
ABresult
0X0
100
111
35 0 my $path = $r->uri;
36 0 ▶ if ($path !~ m%/$%) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path =~ m[/$]) 0 0 0
37 # Make sure the non-canonical bouncer routine runs
38 0 $r->handler("perl-script");
39 0 $r->push_handlers(PerlHandler => \&directory_bounce);
40 }
41 }
42 0 return OK();
43 }
44  
45 sub directory_bounce {
46 0 ▶ my $r = shift;
Subroutine directory_bounce: not called CC=6 SCAR=37.4
Pod undocumented
47 0 ▶ my $proto = $r->subprocess_env("https")?"https":"http";
Branch: 1 branch
BranchTrueFalseTotal
$r->subprocess_env('https') ? : 0 0 0
48 0 ▶ my $host = $r->header_in("host") || $r->hostname || $r->server->server_hostname;
Condition0%0/6
$r->header_in('host') || $r->hostname || $r->server->server_hostname
l!l&&r!l&&!r
000
$r->header_in("host") or $r->hostname
l!l&&r!l&&!r
000
MC/DC0%0/3
$r->header_in('host') || $r->hostname || $r->server->server_hostname
$r->header_in("host") $r->hostname $r->server->server_hostname
Truth table0%0/4
A or B || C
A= $r->header_in("host")B= $r->hostnameC= $r->server->server_hostname
ABCresult
1XX1
01X1
0011
0000
49 0 my $path = $r->uri;
50 0 my $query = $r->args;
51  
52 0 my $url = "$proto://$host$path/";
53 0 ▶ $url .= "?$query" if length $query;
Branch: 1 branch
BranchTrueFalseTotal
if length $query 0 0 0
54  
55 0 $r->status(MOVED());
56 0 $r->content_type("text/html");
57 0 $r->header_out(Location => $url);
58 0 $r->send_http_header;
59  
60 0 ▶ return OK() if $r->header_only;
Branch: 1 branch
BranchTrueFalseTotal
if $r->header_only 0 0 0
61 0 $r->print("Moved <a href=$url>here</a>\n");
62 0 return OK();
63 }
64  
65 1 1;
66 __END__
« Net/DNAT.pm ↑ Summary