| 1 | package PAGI::App::GoldenCage; | ||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | $PAGI::App::GoldenCage::VERSION = '0.002'; | |||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use v5.18; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Net::Async::HTTP; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Future::AsyncAwait; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Gzip::Faster; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use UUID qw(uuid4); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use HTML::Entities qw(encode_entities); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||
| 12 | # Hell, rationality itself - the exalted Human ability to reason - hadn’t | ||||||||||||||||||||||||||||||||||||||||
| 13 | # evolved in the pursuit of truth but simply to win arguments, to gain control: | ||||||||||||||||||||||||||||||||||||||||
| 14 | # to bend others, by means logical or sophistic, to your will. | ||||||||||||||||||||||||||||||||||||||||
| 15 | # -- Peter Watts, Echopraxia | ||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use constant FOUNTAIN_URL => 'https://RNSAFFN.com/poison2/'; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use constant PAGE_HTML => <<HTML =~ s{[\t\v]}{}gr; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 19 | <html> | ||||||||||||||||||||||||||||||||||||||||
| 20 | <head> | ||||||||||||||||||||||||||||||||||||||||
| 21 | <meta charset="UTF-8"> | ||||||||||||||||||||||||||||||||||||||||
| 22 | <title>GC code preview</title> | ||||||||||||||||||||||||||||||||||||||||
| 23 | </head> | ||||||||||||||||||||||||||||||||||||||||
| 24 | <body> | ||||||||||||||||||||||||||||||||||||||||
| 25 | <pre><code>%s</code></pre> | ||||||||||||||||||||||||||||||||||||||||
| 26 | <p><a href="%s">Next snippet</a></p> | ||||||||||||||||||||||||||||||||||||||||
| 27 | </body> | ||||||||||||||||||||||||||||||||||||||||
| 28 | </html> | ||||||||||||||||||||||||||||||||||||||||
| 29 | HTML | ||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||
| 31 | sub new | ||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=16.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||
| 35 | return bless { | ||||||||||||||||||||||||||||||||||||||||
| 36 | ua => $args{ua} // Net::Async::HTTP->new, | ||||||||||||||||||||||||||||||||||||||||
| 37 | fountain_url => $args{fountain_url} // FOUNTAIN_URL, | ||||||||||||||||||||||||||||||||||||||||
| 38 | base_url => $args{base_url} // '', | ||||||||||||||||||||||||||||||||||||||||
| 39 | logger => $args{logger}, | ||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | }, $class; | ||||||||||||||||||||||||||||||||||||||
|
Condition42%3/7
$args{"ua"} // "Net::Async::HTTP"->new
$args{"fountain_url"} // "https://RNSAFFN.com/poison2/"
$args{"base_url"} // ""
MC/DC0%0/2
$args{"ua"} // "Net::Async::HTTP"->new
$args{"ua"}
"Net::Async::HTTP"->new
MC/DC0%0/1
$args{"fountain_url"} // "https://RNSAFFN.com/poison2/"
$args{"fountain_url"}
MC/DC0%0/1
$args{"base_url"} // ""
$args{"base_url"}
Truth table33%1/3
A // B
A= $args{"ua"}B= "Net::Async::HTTP"->new
Truth table50%1/2
A
A= $args{"fountain_url"}
Truth table50%1/2
A
A= $args{"base_url"}
| |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||
| 43 | sub ua | ||||||||||||||||||||||||||||||||||||||||
| 44 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
ua: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 45 | 3 | return $_[0]->{ua}; | |||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||
| 48 | sub fountain_url | ||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
fountain_url: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | return $_[0]->{fountain_url}; | |||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||
| 53 | sub base_url | ||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
base_url: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | return $_[0]->{base_url}; | |||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||
| 58 | sub logger | ||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
logger: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | return $_[0]->{logger}; | |||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||
| 63 | sub generate_link | ||||||||||||||||||||||||||||||||||||||||
| 64 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_link: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||
| 67 | 3 | return $self->base_url . '/' . uuid4; | |||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||
| 70 | async sub call | ||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
call: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | my ($self, $scope, $receive, $send) = @_; | |||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | ▶ | die "Unsupported scope type: $scope->{type}" if $scope->{type} ne 'http'; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | my $response = await $self->ua->do_request(uri => $self->fountain_url); | |||||||||||||||||||||||||||||||||||||||
| 77 | 2 | ▶ | die sprintf 'Error fetching response from the fountain: [%s] %s', ( | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 78 | $response->code, | ||||||||||||||||||||||||||||||||||||||||
| 79 | $response->content | ||||||||||||||||||||||||||||||||||||||||
| 80 | ) unless $response->is_success; | ||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | my $poisoned = $response->content; | |||||||||||||||||||||||||||||||||||||||
| 83 | 2 | ▶ | if (lc($response->header('Content-Encoding') // '') eq 'gzip') { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$response->header("Content-Encoding") // ""
MC/DC100%1/1
$response->header("Content-Encoding") // ""
$response->header("Content-Encoding")
Truth table100%2/2
A
A= $response->header("Content-Encoding")
| |||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | $poisoned = gunzip $poisoned; | |||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | my $html = sprintf PAGE_HTML, encode_entities($poisoned, '<>&"'), $self->generate_link; | |||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | await $send->( | |||||||||||||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||||||||||||||
| 91 | type => 'http.response.start', | ||||||||||||||||||||||||||||||||||||||||
| 92 | status => 200, | ||||||||||||||||||||||||||||||||||||||||
| 93 | headers => [ | ||||||||||||||||||||||||||||||||||||||||
| 94 | ['content-type', 'text/html'], | ||||||||||||||||||||||||||||||||||||||||
| 95 | ['content-length', length $html], | ||||||||||||||||||||||||||||||||||||||||
| 96 | ], | ||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||
| 100 | 2 | await $send->({type => 'http.response.body', body => $html, more => 0}); | |||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | ▶ | if (my $logger = $self->logger) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | $logger->(length $poisoned); | |||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | } | |||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||
| 107 | sub to_app | ||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_app: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | my $loop = IO::Async::Loop->new; | |||||||||||||||||||||||||||||||||||||||
| 112 | 1 | $loop->add($self->ua); | |||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | ▶ | return sub { $self->call(@_) }; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||
| 119 | __END__ | ||||||||||||||||||||||||||||||||||||||||