Modified index
This commit is contained in:
parent
d9afa6076a
commit
20b30be2f5
2 changed files with 57 additions and 37 deletions
|
@ -40,10 +40,9 @@ print "<!DOCTYPE html>
|
||||||
<input type='file' name='file' size='30'>
|
<input type='file' name='file' size='30'>
|
||||||
<input type='submit' value='upload'>
|
<input type='submit' value='upload'>
|
||||||
</form>
|
</form>
|
||||||
<a href='https://codeberg.org/qorg11/lainsafe'>star me</a>
|
<a href='https://github.com/dimethyltriptamine/lainsafe'>star me</a>
|
||||||
<h2>Terminal usage</h2>
|
<h2>Terminal usage</h2>
|
||||||
<p>I recommend using lainsafecli to upload files to lainsafe, however, there is more than one way to do it.</p>
|
<p>I recommend using clainsafecli to upload files to lainsafe, however, there is more than one way to do it.</p>
|
||||||
<code>curl -F 'file=@1605388889.png' $ENV{HTTP_HOST}$ENV{REQUEST_URI}</code><br/>
|
<code>curl -F 'file=@1605388889.png' $ENV{HTTP_HOST}$ENV{REQUEST_URI}</code><br/>
|
||||||
print $disk_free . available from . $disk_size . total;
|
|
||||||
</body>
|
</body>
|
||||||
</html>";
|
</html>";
|
||||||
|
|
|
@ -20,6 +20,7 @@ use Time::HiRes qw(gettimeofday);
|
||||||
my $q = CGI->new;
|
my $q = CGI->new;
|
||||||
|
|
||||||
my $filename = $q->param('file');
|
my $filename = $q->param('file');
|
||||||
|
my $url = $q->param('url');
|
||||||
|
|
||||||
my $upload_dir = "files/";
|
my $upload_dir = "files/";
|
||||||
print $q->header();
|
print $q->header();
|
||||||
|
@ -30,55 +31,75 @@ $size = $ENV{CONTENT_LENGTH};
|
||||||
|
|
||||||
our $MAX_SIZE = 1024*1024*100; # Change for your size
|
our $MAX_SIZE = 1024*1024*100; # Change for your size
|
||||||
our $MAX_SIZE_MB = $MAX_SIZE / 1024 / 1024; # Don't change this
|
our $MAX_SIZE_MB = $MAX_SIZE / 1024 / 1024; # Don't change this
|
||||||
|
|
||||||
our @not_allowed_extensions = qw(sh out exe);
|
our @not_allowed_extensions = qw(sh out exe);
|
||||||
|
|
||||||
|
# do something better
|
||||||
|
if ($url ne "") {
|
||||||
|
goto url_shorter;
|
||||||
|
}
|
||||||
|
|
||||||
if ($filename eq "" || $ENV{REQUEST_METHOD} eq "GET") {
|
if ($filename eq "" || $ENV{REQUEST_METHOD} eq "GET") {
|
||||||
print("What are you looking for?");
|
print("What are you looking for?");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($size > $MAX_SIZE) {
|
if ($filename) {
|
||||||
print("Max size for a file is $MAX_SIZE_MB MBs");
|
if ($size > $MAX_SIZE) {
|
||||||
exit;
|
print("Max size for a file is $MAX_SIZE_MB MBs");
|
||||||
}
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
my @chars = ("A"..."z","a"..."z");
|
my @chars = ("A"..."z","a"..."z");
|
||||||
my $dirname;
|
my $dirname;
|
||||||
my $extension = $filename;
|
my $extension = $filename;
|
||||||
|
|
||||||
$dirname .= $chars[rand @chars] for 1..8;
|
$dirname .= $chars[rand @chars] for 1..8;
|
||||||
$extension =~ s/.*\.//;
|
$extension =~ s/.*\.//;
|
||||||
$filename .= ".notcgi" if $extension eq "cgi";
|
$filename .= ".notcgi" if $extension eq "cgi";
|
||||||
|
|
||||||
mkdir("$upload_dir/$dirname");
|
mkdir("$upload_dir/$dirname");
|
||||||
my $upload_filehandle = $q->upload("file");
|
my $upload_filehandle = $q->upload("file");
|
||||||
|
|
||||||
# onion urls will be http
|
# onion urls will be http
|
||||||
my $prot = length $ENV{HTTPS} ? "https" : "http";
|
my $prot = length $ENV{HTTPS} ? "https" : "http";
|
||||||
|
|
||||||
my $allowed_extension = 1;
|
my $allowed_extension = 1;
|
||||||
|
|
||||||
foreach (@not_allowed_extensions) {
|
foreach (@not_allowed_extensions) {
|
||||||
if ($filename =~ /\.$_$/i) {
|
if ($filename =~ /\.$_$/i) {
|
||||||
$allowed_extension = 0;
|
$allowed_extension = 0;
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($allowed_extension) {
|
if ($allowed_extension) {
|
||||||
|
|
||||||
open(FILE,">$upload_dir/$dirname/$filename");
|
open(FILE,">$upload_dir/$dirname/$filename");
|
||||||
binmode(FILE);
|
binmode(FILE);
|
||||||
|
|
||||||
while (<$upload_filehandle>) {
|
while (<$upload_filehandle>) {
|
||||||
print FILE;
|
print FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
close FILE;
|
close FILE;
|
||||||
$filename =~ s/ /%20/g;
|
$filename =~ s/ /%20/g;
|
||||||
print $prot. "://" . $ENV{HTTP_HOST} . "/$upload_dir$dirname/$filename";
|
print $prot. "://" . $ENV{HTTP_HOST} . "/$upload_dir$dirname/$filename";
|
||||||
} else {
|
} else {
|
||||||
print "The file extension .$extension is not allowed in this instance.";
|
print "The file extension .$extension is not allowed in this instance.";
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
} elsif ($url != "" && !$filename) {
|
||||||
|
url_shorter:
|
||||||
|
my $template = "<meta http-equiv='Refresh' content='0; url='$url'/>";
|
||||||
|
|
||||||
|
my @chars = ("A"..."z","a"..."z");
|
||||||
|
my $dirname;
|
||||||
|
$dirname .= $chars[rand @chars] for 1..8;
|
||||||
|
mkdir($dirname);
|
||||||
|
open(my $fh, ">$dirname/index.html");
|
||||||
|
print $fh $template;
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue