This commit is contained in:
(≧◡≦) 2023-02-12 13:29:44 +01:00
parent f52dcbb721
commit dcea6b2a24
No known key found for this signature in database
GPG key ID: B39C0BCEE94A4A89

View file

@ -4,12 +4,14 @@
use if $^O eq "openbsd", OpenBSD::Pledge, qw(pledge);
use Mojolicious::Lite -signatures;
use Mojolicious::Routes::Pattern;
use List::MoreUtils qw(any uniq);
use List::MoreUtils qw(uniq);
use Carp;
use Term::ANSIColor;
use English;
use MIME::Types;
use warnings;
use experimental 'signatures';
use feature 'say';
plugin 'RenderFile';
@ -17,7 +19,6 @@ plugin 'RenderFile';
my $openbsd = 0;
$openbsd = 1 if $^O eq "openbsd";
pledge("stdio cpath rpath wpath inet flock fattr") if $openbsd;
use strict;
my $MAX_SIZE = 1024 * 1024 * 100;
@ -25,6 +26,8 @@ my @BANNED = qw(); # Add banned IP addresses here
my $dirname;
my $host;
mkdir "f";
# Function to handle file uploads
sub logger ( $level, $address, $message ) {
@ -42,7 +45,7 @@ sub handle_file {
status => 400
);
}
if ( any { /$c->tx->remote_address/ } uniq @BANNED ) {
if ( List::MoreUtils::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." .
@ -80,15 +83,14 @@ post '/' => sub ($c) { handle_file($c) };
# Allow files to be downloaded.
get '/f/:dir/:name' => sub ($c) {
my $captures = $c->req->url;
$captures =~ s/^.//;
my $filerender = Mojolicious::Plugin::RenderFile->new;
my $ext = $captures;
get '/f/:dir/#name' => sub ($c) {
my $dir = $c->param("dir");
my $file = $c->param("name");
print $dir, $file . "\n";
my $ext = $file;
$ext =~ s/.*\.//;
carp(color("bold yellow"), "sakisafe warning: could not get file: $ERRNO", color("reset")) unless
$c->render_file( filepath => $captures,
format => $ext,
$c->render_file( filepath => "f/".$dir . "/" . $file,
format => 'jpg',
content_disposition => 'inline'
);
};
@ -107,8 +109,8 @@ app->start;
__DATA__
@@ index.html.ep
<!DOCTYPE html>
<html lang="en">
<!DOCTYPE html>
<html lang="en">
<head>
<title>sakisafe</title>
<link rel="stylesheet" type="text/css" href="index.css"/>
@ -133,4 +135,4 @@ __DATA__
</form>
</div>
</body>
</html>
</html>