-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.cgi
executable file
·51 lines (40 loc) · 1.01 KB
/
upload.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl
use CGI 'param';
use File::Copy;
use File::Basename;
sub ulog {
if (open(L, ">>$cwd/upload.log")) {
print L strftime("%F %T ", localtime()), $_[0], "\n";
close(L);
}
}
my $cwd = dirname $0;
my $cgi = basename $0;
my $filename = param("upfile");
my $fh = CGI::upload("upfile");
$filename =~ s/[\;\:\!\?\*\"\'\,\ ]/_/g;
print STDERR "Uploading $filename\n";
print "Content-type: text/plain\n";
#for (param()) {
# printf "$_: %s\n", param($_);
#}
#exit;
my $destpath="$cwd/upload";
if (-f "$destpath/$filename") {
print "Status: 403 Cannot overwrite file\n";
exit;
}
if (open OUTFILE, ">$destpath/$filename") {
while ($bytesread=read($fh,$buffer,1024)) {
print OUTFILE $buffer;
}
close OUTFILE;
print "Status: 200 Upload successful\n";
ulog "Uploaded upload/$filename";
}
else {
print "Status: 502 File copy failed: $!\n";
ulog "Failed creating upload/$filename";
}
print "\n$destpath/$filename\n";
print STDERR "\n$destpath/$filename\n";