Change tab size

This commit is contained in:
rf 2023-04-26 08:54:42 -06:00
parent b488b784bc
commit b876d94eaa
2 changed files with 63 additions and 63 deletions

View file

@ -3,7 +3,7 @@
-iob # Ignore old breakpoints -iob # Ignore old breakpoints
-l=120 # 120 characters per line -l=120 # 120 characters per line
-mbl=2 # No more than 2 blank lines -mbl=2 # No more than 2 blank lines
-i=2 # Indentation is 2 columns -i=5 # Indentation is 2 columns
-ci=2 # Continuation indentation is 2 columns -ci=2 # Continuation indentation is 2 columns
-vt=0 # Less vertical tightness -vt=0 # Less vertical tightness
-pt=2 # High parenthesis tightness -pt=2 # High parenthesis tightness

View file

@ -35,71 +35,71 @@ $log->color(1);
# Forward logs to STDERR or STDOUT while also writing to the `sakisafe.log` file. # Forward logs to STDERR or STDOUT while also writing to the `sakisafe.log` file.
$log->on( $log->on(
message => sub ($l, $level, @lines) { message => sub ($l, $level, @lines) {
my $time = time; my $time = time;
my ($s, $m, $h, $day, $month, $year) = localtime time; my ($s, $m, $h, $day, $month, $year) = localtime time;
$time = sprintf( $time = sprintf(
'%04d-%02d-%02d %02d:%02d:%08.5f', '%04d-%02d-%02d %02d:%02d:%08.5f',
$year + 1900, $year + 1900,
$month + 1, $day, $h, $m, "$s." . ((split '.', $time)[1] // 0) $month + 1, $day, $h, $m, "$s." . ((split '.', $time)[1] // 0)
); );
my $log_to_print = '[' . $time . '] ' . '[' . $level . '] ' . join(' ', @lines); my $log_to_print = '[' . $time . '] ' . '[' . $level . '] ' . join(' ', @lines);
if ($level eq 'trace' || $level eq 'info') { if ($level eq 'trace' || $level eq 'info') {
say $log_to_print; say $log_to_print;
} }
else { else {
print \*STDERR, $log_to_print . "\n"; print \*STDERR, $log_to_print . "\n";
} }
} }
); );
# Function to handle file uploads # Function to handle file uploads
sub handle_file { sub handle_file {
my $c = shift; my $c = shift;
my $filedata = $c->param("file"); my $filedata = $c->param("file");
if ($filedata->size > $MAX_SIZE) { if ($filedata->size > $MAX_SIZE) {
return $c->render(text => "Max upload size: $MAX_SIZE", status => 400); return $c->render(text => "Max upload size: $MAX_SIZE", status => 400);
} }
if (List::MoreUtils::any { $c->tx->remote_address } uniq @BANNED) { if (List::MoreUtils::any { $c->tx->remote_address } uniq @BANNED) {
$log->info("Attempt to upload by banned IP: " . $c->tx->remote_address); $log->info("Attempt to upload by banned IP: " . $c->tx->remote_address);
$c->render( $c->render(
text => "Hi! Seems like the server admin added your IP address to the banned IP array." text => "Hi! Seems like the server admin added your IP address to the banned IP array."
. "As the developer of sakisafe, I can't do anything.", . "As the developer of sakisafe, I can't do anything.",
status => 403 status => 403
); );
return; return;
} }
# Generate random string for the directory # Generate random string for the directory
my @chars = ('0' .. '9', 'a' .. 'Z'); my @chars = ('0' .. '9', 'a' .. 'Z');
$dirname .= $chars[rand @chars] for 1 .. 5; $dirname .= $chars[rand @chars] for 1 .. 5;
my $filename = $filedata->filename; my $filename = $filedata->filename;
$log->warn("sakisafe warning: could not create directory: $ERRNO") unless mkdir("f/" . $dirname); $log->warn("sakisafe warning: could not create directory: $ERRNO") unless mkdir("f/" . $dirname);
$filename .= ".txt" if $filename eq "-"; $filename .= ".txt" if $filename eq "-";
# TODO: get whether the server is http or https # TODO: get whether the server is http or https
# There's a CGI ENV variable for that. # There's a CGI ENV variable for that.
my $host = $c->req->url->to_abs->host; my $host = $c->req->url->to_abs->host;
my $ua = $c->req->headers->user_agent; my $ua = $c->req->headers->user_agent;
$filedata->move_to("f/" . $dirname . "/" . $filename); $filedata->move_to("f/" . $dirname . "/" . $filename);
$link = "http://$host/f/$dirname/$filename"; $link = "http://$host/f/$dirname/$filename";
$c->stash(link => $link, host => $host, dirname => $dirname); $c->stash(link => $link, host => $host, dirname => $dirname);
$c->res->headers->header('Location' => "$link" . $filename); $c->res->headers->header('Location' => "$link" . $filename);
# Only give the link to curl, html template for others. # Only give the link to curl, html template for others.
if ($ua =~ m/curl/) { if ($ua =~ m/curl/) {
$c->render(text => $link . "\n", status => 201,); $c->render(text => $link . "\n", status => 201,);
$dirname = ""; $dirname = "";
} }
else { else {
$c->render(template => 'file', status => 201,); $c->render(template => 'file', status => 201,);
} }
$log->info($c->tx->remote_address . " " . $dirname . "/" . $filename); $log->info($c->tx->remote_address . " " . $dirname . "/" . $filename);
$dirname = ""; $dirname = "";
} }
# Function to log uploaded files # Function to log uploaded files
@ -110,15 +110,15 @@ post '/' => sub ($c) { handle_file($c) };
# Allow files to be downloaded. # Allow files to be downloaded.
get '/f/:dir/#name' => sub ($c) { get '/f/:dir/#name' => sub ($c) {
my $dir = $c->param("dir"); my $dir = $c->param("dir");
my $file = $c->param("name"); my $file = $c->param("name");
my $ext = $file; my $ext = $file;
$ext =~ s/.*\.//; $ext =~ s/.*\.//;
my $path = "f/" . $dir . "/" . $file; my $path = "f/" . $dir . "/" . $file;
#carp "sakisafe warning: could not get file: $ERRNO" unless #carp "sakisafe warning: could not get file: $ERRNO" unless
$c->render(text => "file not found", status => 404) unless -e $path; $c->render(text => "file not found", status => 404) unless -e $path;
$c->render_file(filepath => $path, format => $ext, content_disposition => 'inline'); $c->render_file(filepath => $path, format => $ext, content_disposition => 'inline');
}; };
app->log($log); app->log($log);