Skip to content

Commit

Permalink
Added MIME types and stuff so the browser is able to show the file [e…
Browse files Browse the repository at this point in the history
…xperimental]
  • Loading branch information
rfc-2549 committed Dec 30, 2022
1 parent 2d9e3fc commit e8f03c4
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions http/sakisafe.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

use Mojolicious::Lite -signatures;
use Mojolicious::Routes::Pattern;

use List::MoreUtils qw(any uniq);
use MIME::Types;
use v5.36;
plugin 'RenderFile';


my $MAX_SIZE = 1024 * 1024 * 100;

my @BANNED = qw(); # Add banned IP addresses here
Expand All @@ -30,7 +32,7 @@ sub handle_file {
status => 400
);
}
if ( $c->tx->remote_address ~~ @BANNED ) {
if ( any { /$c->tx->remote_address/ } uniq @BANNED ) {
$c->render(
text =>
"Hi! Seems like the server admin added your IP address to the banned IP array." .
Expand Down Expand Up @@ -70,7 +72,12 @@ sub handle_file {
my $captures = $c->req->url;
$captures =~ s/^.//;
my $filerender = Mojolicious::Plugin::RenderFile->new;
$c->render_file( filepath => $captures );
my ($ext) = $captures =~ /(\.[^.]+)$/;
print $ext;
$c->render_file( filepath => $captures,
format => $ext,
content_disposition => 'inline'
);
};

app->max_request_size( 1024 * 1024 * 100 );
Expand Down

0 comments on commit e8f03c4

Please sign in to comment.