| 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
| |||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$new_addr and $new_port
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
| |||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$type and $type eq "httpd/unix-directory"
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"
| |||||||||||||||||||||||||||||||||||
| 35 | 0 | my $path = $r->uri; | |||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if ($path !~ m%/$%) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
$r->header_in("host") or $r->hostname
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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 61 | 0 | $r->print("Moved <a href=$url>here</a>\n"); | |||||||||||||||||||||||||||||||||
| 62 | 0 | return OK(); | |||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||
| 65 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||||||||||||||||||