From deb4318cd99c27b90ca806b63358d330121c9778 Mon Sep 17 00:00:00 2001 From: Rawley <75388349+rawleyfowler@users.noreply.github.com> Date: Mon, 13 Mar 2023 13:18:46 +0000 Subject: [PATCH] Add Makefile.PL and allow banned IP's to be derived from a file (#21) * added perl makefile * fixup gitignore and eval --- .gitignore | 11 +++++++++++ http/Makefile.PL | 17 +++++++++++++++++ http/sakisafe.pl | 12 ++++++------ 3 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 http/Makefile.PL diff --git a/.gitignore b/.gitignore index f0bf8f0..9c2ec04 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,14 @@ obj/ .clangd .depend http/f/* +blib/ +pm_to_blib +Makefile +Makefile.old +MANIFEST* +!MANIFEST.SKIP +META.*/ +MYMETA.* +pm_to_blib +sakisafe.log +f/ diff --git a/http/Makefile.PL b/http/Makefile.PL new file mode 100644 index 0000000..cb476f4 --- /dev/null +++ b/http/Makefile.PL @@ -0,0 +1,17 @@ +use v5.36; + +use ExtUtils::MakeMaker; + +WriteMakefile( + NAME => 'sakisafe', + PREREQ_PM => { + "Mojolicious" => 0, + "List::MoreUtils" => 0, + "Term::ANSIColor" => 0, + "MIME::Types" => 0, + "Path::Tiny" => 0, + "Mojolicious::Plugin::RenderFile" => 0, + "Mojolicious::Routes::Pattern" => 0 + }, + EXE_FILES => ['sakisafe.pl'] +); diff --git a/http/sakisafe.pl b/http/sakisafe.pl index 0f86595..54b287c 100755 --- a/http/sakisafe.pl +++ b/http/sakisafe.pl @@ -9,21 +9,20 @@ use Carp; use Term::ANSIColor; use English; use MIME::Types; +use Path::Tiny; use warnings; use experimental 'signatures'; use feature 'say'; plugin 'RenderFile'; # OpenBSD promises. -my $openbsd = 0; -$openbsd = 1 if $^O eq "openbsd"; -pledge("stdio cpath rpath wpath inet flock fattr") if $openbsd; +pledge("stdio cpath rpath wpath inet flock fattr") if $^O eq "openbsd"; # 100 MBs my $MAX_SIZE = 1024 * 1024 * 100; -my @BANNED = qw(); # Add banned IP addresses here +my @BANNED = eval { path('banned.txt')->slurp_utf8 } or qw(); # Add banned IP addresses here my $dirname; my $link; @@ -46,6 +45,7 @@ sub handle_file { status => 400 ); } + if ( List::MoreUtils::any { /$c->tx->remote_address/ } uniq @BANNED ) { $c->render( text => @@ -119,8 +119,8 @@ get '/f/:dir/#name' => sub ($c) { content_disposition => 'inline' ); -} -; +}; + app->max_request_size( 1024 * 1024 * 100 ); post '/upload' => sub ($c) { handle_file($c) };