##############!/usr/bin/perl
#This is the 'uploader.cgi' script.
#####################################
## \n";
print "The following filenames are found in directory \"$in{'filedirname'}\": \n";
&listfilenames_ok;
}
sub return {
print "Location: $ENV{'DOCUMENT_URI'}\n\n";
}
sub check_url_referer {
$referral_cnt = @valid;
if ($referral_cnt > 0) {
foreach $referer (@valid) {
if ($ENV{'HTTP_REFERER'} =~ /$referer/i) {
$good_ref = "yes";
last;
}
}
if ($good_ref ne "yes") {
&go_away;
}
}
}
sub error_password {
&set_content_type;
print " You didn't supply a valid password. Please check and enter again. You did not select a valid command. Please check and try again. Request denied. You are attempting to access our server using an unauthorized form. Please check your input and try again. If the problem repeats, please contact your Webmaster.##
require 'cgi-lib2.pl';
# Indicate if your server O/S is Unix/Linux or Windows NT
# Set to "unix" if Unix or Linux; set to "nt" if Windows NT
$serverOS = "unix";
# This parameter defines what character set you want the Web
# browser to be set to when viewing your Html pages.
# Default is "". Chinese GB = "gb2312". Chinese Big5 = "Big5".
$charset = "us-ascii";
# Supervisor Password.
$superpwd = "whatever";
# Full pathname of directory (parent) which is 1 level higher than
# the "file upload" directory (directory storing the uploaded files).
# This directory must be resided in a Html directory
# Create this directory manually if it is not already existed.
# Use chmod command to set this directory to writable, i.e. 0777.
# The last "/" character is significant.
#I have refered this $parent_dir to the password file/files,(but no help).
$parent_dir="/home/virtual/site71/fst/var/www/html/uploads/mp3/";
$return_url="http://www.mysite.net/";
@valid=('http://www.mysite.net/uploads/MP3Upload.html');
###################################################################
# Parse Form Contents
&ReadParse;
if ($ENV{'REQUEST_METHOD'} ne 'POST') {
&error_not_a_command;
}
$| = 1;
# Validate & execute command according to Action Type
unless (
($in{'action'} eq "uploadfile") ||
($in{'action'} eq "listfilenames")) {
&error_not_a_command;
}
if ($in{'action'} eq "uploadfile") {&uploadfile}
if ($in{'action'} eq "listfilenames") {&listfilenames}
exit;
sub uploadfile {
&check_url_referer;
if ($in{'pwd'} ne $superpwd) {
&error_password;
}
if (!$in{'sourcefile'}) {
&error_uploadfile;
}
if (!$in{'filedirname'}) {
&error_no_upload_directory;
}
if ($in{'filedirname'} =~ /[^a-z0-9A-Z]+/) {
&error_invalid_directory_name;
}
if ($in{'maxfilesize'}) {
$maxfilesize = $in{'maxfilesize'};
}
\n";
$count = 0;
foreach $fitem (@files) {
$fitem_pathname = "$list_dir" . "/" . "$fitem";
if (-e $fitem_pathname) {
if (-d $fitem_pathname) {next;}
$count++;
print " $fitem
\n";
}
}
if ($count == 0) {
print " Sorry, nothing found!!
\n";
}
print "
Please check your input and try again. Directory name must contain alphanumeric characters only.
\n"; print "