#!/usr/bin/perl -w #********************************************************************************************************************************** # ATTENTION: THIS FILE HEADER MUST REMAIN INTACT. DO NOT DELETE OR MODIFY THIS FILE HEADER. # # Name: uu_upload.pl # Link: http://uber-uploader.sourceforge.net/ # Revision: 5.0 # Date: 17/03/2007 6:25PM # Initial Developer: Peter Schmandra # Description: Upload files to a temp dir based on Session-id, transfer files to upload dir and output results or redirect. # # Credits: # I would like to thank the following people who helped create # and improve Uber-Uploader by providing code, ideas, insperation, # bug fixes and valuable feedback. If you feel you should be included # in this list, please post a message in the 'Open Discussion' # forum of the Uber-Uploader project page requesting a contributor credit. # # Contributor: Art Bogdanov www.sibsoft.net/xupload.html # Contributor: Bill www.rebootconcepts.com # Contributor: Cedric www.fsharp.fr # Contributor: Detlev Richter # Contributor: Erik Guilfoyle # Contributor: Feyyaz Oezdemir # Contributor: Jeroen Soeters # Contributor: Kim Steinhaug # Contributor: Klaus Karcher # Contributor: Nico Hawley-Weld # Contributor: Raditha Dissanyake www.raditha.com/megaupload/ # Contributor: Tolriq # Contributor: Tore B. Krudtaa # # Licence: # The contents of this file are subject to the Mozilla Public # License Version 1.1 (the "License"); you may not use this file # except in compliance with the License. You may obtain a copy of # the License at http://www.mozilla.org/MPL/ # # Software distributed under the License is distributed on an "AS # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or # implied. See the License for the specific language governing # rights and limitations under the License. # #********************************************************************************************************************************** my $THIS_VERSION = "5.0"; # Version of this driver my $start_time = time(); # Timestamp of the start of the upload # Makes %ENV safer $ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin'; delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; use strict; use lib qw(.); # Add current directory to list of valid paths #use CGI::Carp 'fatalsToBrowser'; # Dump fatal errors to screen use CGI qw(:cgi); # Load the CGI.pm module use uu_lib; # Load the uu_lib.pm module ############################################################### # The following possible query string formats are assumed # # 1. ?tmp_sid=some_sid_number&config_file=some_config_file_name # 2 ?tmp_sid=some_sid_number # 3. ?cmd=about # 4. ?cmd=debug&config_file=some_config_file_name # 5. ?cmd=debug ############################################################### my %query_string = parse_query_string($ENV{'QUERY_STRING'}); # Check for tainted sid if(exists($query_string{'tmp_sid'})){ if($query_string{'tmp_sid'} !~ m/(\w{32})/){ &kak("ERROR<\/font>: Invalid session-id
\n", 1, __LINE__); } else{ $query_string{'tmp_sid'} = $1; } } # Check for tainted config file name if(exists($query_string{'config_file'})){ if($query_string{'config_file'} !~ m/(\w{5,32})/){ &kak("ERROR<\/font>: Invalid config file name
\n", 1, __LINE__); } else{ $query_string{'config_file'} = $1; } } # Check for tainted command if(exists($query_string{'cmd'})){ if($query_string{'cmd'} ne 'about' && $query_string{'cmd'} ne 'debug'){ &kak("ERROR<\/font>: Invalid command
\n", 1, __LINE__); } } # Make sure cmd or tmp_sid was passed but not both if(!exists($query_string{'cmd'}) && !exists($query_string{'tmp_sid'})){ &kak("ERROR<\/font>: Invalid parameters
\n", 1, __LINE__); } if(exists($query_string{'cmd'}) && exists($query_string{'tmp_sid'})){ &kak("ERROR<\/font>: Conflicting parameters
\n", 1, __LINE__); } ####################################################################################################### # Attempt to load the config file that was passed to the script if multi configs is enabled. If no # config file name was passed to the script, load the default config file 'uu_default_config.pm' ####################################################################################################### if(exists($query_string{'config_file'}) && $MULTI_CONFIGS_ENABLED){ my $config_file = $query_string{'config_file'}; unless(eval "use $config_file"){ if($@){ &kak("ERROR<\/font>: Failed to load config file $config_file.pm
\n", 1, __LINE__); } } } elsif(exists($query_string{'config_file'}) && !$MULTI_CONFIGS_ENABLED){ &kak("ERROR<\/font>: Multi Config files disabled
\n", 1, __LINE__); } else{ unless(eval "use uu_default_config"){ if($@){ &kak("ERROR<\/font>: Failed to load config file uu_default_config.pm
\n", 1, __LINE__); } } } # Process 'about' or 'debug' command if(exists($query_string{'cmd'}) && $query_string{'cmd'} eq 'about'){ &kak("UBER UPLOADER VERSION<\/u>
UBER UPLOADER VERSION = " . $UBER_VERSION . "<\/b>
UU_UPLOAD = " . $THIS_VERSION . "<\/b>
\n", 1, __LINE__); } elsif(exists($query_string{'cmd'}) && $query_string{'cmd'} eq 'debug' && !$DEBUG_ENABLED){ &kak("UBER UPLOADER CGI SETTINGS<\/b><\/u>
DEBUG = disabled<\/b>
\n", 1, __LINE__); } elsif(exists($query_string{'cmd'}) && $query_string{'cmd'} eq 'debug' && $DEBUG_ENABLED){ &debug(); } my $tmp_sid = $query_string{'tmp_sid'}; # Assign session-id my $sleep_time = 1; # Seconds to wait before upload proceeds (for small file uploads) my %uploaded_files = (); # Hash with all the uploaded file names my $temp_dir_sid = $main::config->{temp_dir} . $tmp_sid; # Append Session-id to upload temp directory my $flength_file = $temp_dir_sid . '/flength'; # Flength file is used to store the size of the upload in bytes my $unique_dir; # Unique upload directory name umask(0); $|++; # Force auto flush of output buffer $SIG{HUP} = 'IGNORE'; # Ignore sig hup local $SIG{__DIE__} = \&cleanup; # User has pressed stop during upload so deal with it $CGI::POST_MAX = $main::config->{max_upload}; # Set the max post value # Create temp directory if it does not exist if(!-d $main::config->{temp_dir}){ mkdir($main::config->{temp_dir}, 0777) or &kak("ERROR: Failed to mkdir $main::config->{temp_dir}: $!", 1, __LINE__); } # Create a temp directory based on Session-id if(!-d $temp_dir_sid){ mkdir($temp_dir_sid, 0777) or &kak("ERROR: Failed to mkdir $temp_dir_sid: $!", 1, __LINE__); } else{ &deldir($temp_dir_sid); mkdir($temp_dir_sid, 0777) or &kak("ERROR: Failed to mkdir $temp_dir_sid: $!", 1, __LINE__); } # Prepare the flength file for writing open(FLENGTH, ">" , "$flength_file") or &kak("ERROR: Failed to open $temp_dir_sid/flength: $!", 1, __LINE__); if($ENV{'CONTENT_LENGTH'} > $main::config->{max_upload}){ # If file size exceeds maximum write error to flength file and exit my $max_size = &format_bytes($main::config->{max_upload}, 99); print FLENGTH "ERROR: Maximum upload size of $max_size exceeded"; close(FLENGTH); chmod 0666, $flength_file; &kak("ERROR: Maximum upload size of $max_size exceeded.

Your upload has failed.
", 1, __LINE__); } else{ # Write total upload size in bytes to flength file print FLENGTH $ENV{'CONTENT_LENGTH'}; close(FLENGTH); chmod 0666, $flength_file; } # Let progress bar get some info (for small file uploads) sleep($sleep_time); # Tell CGI.pm to use our directory based on Session-id if($TempFile::TMPDIRECTORY){ $TempFile::TMPDIRECTORY = $temp_dir_sid; } elsif($CGITempFile::TMPDIRECTORY){ $CGITempFile::TMPDIRECTORY = $temp_dir_sid; } else{ &kak("ERROR: Failed to assign CGI temp directory", 1, __LINE__); } my $query = new CGI; #################################################################################################################### # The upload is complete at this point, so you can now access any post values. eg. $query->param("some_post_value"); #################################################################################################################### ################################################################################################################### # IF you are modifying the upload directory with a post value, it may be done here. # # Note: Making modifications based on posted input may be unsafe. Make sure your posted input is safe! # # You must override the $main::config->{upload_dir} value # If you are linking to the file you must also override the $main::config->{path_to_upload} value # # eg. $main::config->{upload_dir} .= $query->param("employee_num") . '/'; # eg. $main::config->{path_to_upload} .= $query->param("employee_num") . '/'; ################################################################################################################### # Create a unique directory inside the upload directory if config setting 'unique_upload_dir' is enabled if($main::config->{unique_upload_dir}){ $unique_dir = generate_random_string($main::config->{unique_upload_dir_length}); $main::config->{upload_dir} .= $unique_dir . '/'; if($main::config->{link_to_upload}){ $main::config->{path_to_upload} .= $unique_dir . '/'; } } # Create upload directory if it does not exist if(!-d $main::config->{upload_dir}){ mkdir($main::config->{upload_dir}, 0777) or &kak("ERROR: Failed to mkdir $main::config->{upload_dir}: $!", 1, __LINE__); } # If we are using rename, make sure it's the same disk or mount if($main::config->{create_files_by_rename}){ my $dev_temp_dir = (stat($main::config->{temp_dir}))[0]; my $dev_upload_dir = (stat($main::config->{upload_dir}))[0]; # We have have two disks so use copy instead (can't rename across disks/mounts) if($dev_temp_dir != $dev_upload_dir){ $main::config->{create_files_by_rename} = 0; } } # Start processing the uploaded files for my $upload_key (keys %{$query->{'.tmpfiles'}}){ # Get uploaded file name $query->{'.tmpfiles'}->{$upload_key}->{info}->{'Content-Disposition'} =~ / filename="([^"]*)"/; my $file_name = $1; # Get the filed name eg. 'upfile_0' $query->{'.tmpfiles'}->{$upload_key}->{info}->{'Content-Disposition'} =~ / name="([^"]*)"/; my $field_name = $1; # Get the upload file handle my $upload_filehandle = $query->upload($field_name); # Get the CGI temp file name my $tmp_filename = $query->tmpFileName($upload_filehandle); # Strip extra path info from the file (IE). Note: Will likely cause problems with foreign languages like chinese $file_name =~ s/.*[\/\\](.*)/$1/; # Normalize file name Note: Will cause problems with foreign languages like chinese if($main::config->{normalize_file_names}){ $file_name = &normalize_filename($file_name, $main::config->{normalize_file_delimiter}, $main::config->{normalize_file_length}); } # Get the file extention my ($f_name, $file_extension) = ($file_name =~ /(.*)\.(.+)/); ######################################################################################################## # IF you are modifying the file name with a post value, it may be done here. # # Note: Making modifications based on posted input may be unsafe. Make sure your posted input is safe! # # eg. $file_name = $f_name . "_" . $query->param("employee_num") . $file_extension; ######################################################################################################## ################################################################################################################################################# # IF you want to filter file uploads by disallowed AND allowed extensions, change the following line to use the allow extensions config setting. # eg. if((-s $tmp_filename) && ($file_extention !~ m/^$main::config->{disallow_extensions}$/i) && ($file_extention =~ m/^$main::config->{allowed_extensions}$/i)){ ################################################################################################################################################################# # Do not process zero length files or files with illegal extensions if((-s $tmp_filename) && ($file_extension !~ m/^$main::config->{disallow_extensions}$/i)){ # Create a unique filename if config setting 'unique_filename' is enabled if($main::config->{unique_file_name}){ my $unique_file_name = generate_random_string($main::config->{unique_file_name_length}); $unique_file_name = $unique_file_name . "." . $file_extension; $file_name = $unique_file_name; } # Check for an existing file and rename if it already exists if(!$main::config->{overwrite_existing_files}){ $file_name = &rename_filename($file_name, 1); } my $upload_file_path = $main::config->{upload_dir} . $file_name; if($main::config->{create_files_by_rename}){ # Create uploaded files by rename (fast) close($upload_filehandle); rename($tmp_filename, $upload_file_path) or warn("Cannot rename from $tmp_filename to $upload_file_path: $!"); } else{ # Create uploaded files by copy (slow but works across disks and mounts) open(UPLOADFILE, ">" , "$upload_file_path"); binmode UPLOADFILE; while(<$upload_filehandle>){ print UPLOADFILE; } close(UPLOADFILE); close($upload_filehandle); } chmod 0666, $upload_file_path; } # Record the upload file info $uploaded_files{$file_name}{$field_name} = 0; } # Delete the temp directory based on session-id and everything in it &deldir($temp_dir_sid); # Redirect to php page if redirect enabled else display results if($main::config->{redirect_after_upload}){ my $param_file_path = $main::config->{temp_dir} . $tmp_sid . ".params"; my @names = $query->param; # We are re-directing so write a session-id.param file with all the post values open PARAMS, ">$param_file_path" or &display_results_through_cgi(); binmode PARAMS; # Write post values to param file (we do not write the files names at this point) foreach my $key (@names){ my $post_value = $query->param($key); $post_value =~ s/(\r\n|\n|\r)/~NWLN~/g; $post_value =~ s/=/~EQLS~/g; if($post_value ne "" && $key !~ m/^upfile_/){ print PARAMS "$key=$post_value\n"; } } # Write some config settings to the param file print PARAMS "upload_dir=$main::config->{upload_dir}\n"; print PARAMS "link_to_upload=$main::config->{link_to_upload}\n"; print PARAMS "delete_param_file=$main::config->{delete_param_file}\n"; # If we want a direct link and or an email link, we need to pass the path_to_upload setting if($main::config->{link_to_upload} || ($main::config->{send_email_on_upload} && $main::config->{link_to_upload_in_email})){ print PARAMS "path_to_upload=$main::config->{path_to_upload}\n"; } # If 'unique_upload_dir' config setting is enabled pass the info if($main::config->{unique_upload_dir}){ print PARAMS "unique_upload_dir=$main::config->{unique_upload_dir}\n"; print PARAMS "unique_dir=$unique_dir\n"; } # If email on upload, write all the email info to param file if($main::config->{send_email_on_upload}){ print PARAMS "send_email_on_upload=1\n"; print PARAMS "link_to_upload_in_email=$main::config->{link_to_upload_in_email}\n"; print PARAMS "email_subject=$main::config->{email_subject}\n"; print PARAMS "html_email_support=$main::config->{html_email_support}\n"; print PARAMS "to_email_address=$main::config->{to_email_address}\n"; print PARAMS "from_email_address=$main::config->{from_email_address}\n"; } else{ print PARAMS "send_email_on_upload=0\n"; } # Write upload file names to param file for my $file_name (keys %uploaded_files){ for my $upload_slot (keys %{$uploaded_files{$file_name}}){ print PARAMS "$upload_slot=$file_name\n"; } } # Write start and end upload time to param file print PARAMS "start_time=$start_time\n"; print PARAMS "end_time=" . time() . "\n"; close(PARAMS); chmod 0666, $param_file_path; # Append random string so finished page does not cache my $redirect_url = $main::config->{redirect_url}; $redirect_url .= "?rnd_id=" . &generate_random_string(8); # Force 'redirect_using_location' if user does not have a javascript capable browser or using embedded_upload_results if($query->param('no_script') || $query->param('embedded_upload_results') == 1){ $main::config->{redirect_using_js_html} = 0; $main::config->{redirect_using_location} = 1; } # Perform Redirect if($main::config->{redirect_using_js_html}){ &kak("
{temp_dir}\">
", 1, __LINE__); } else{ ############################################################################################################## # If you are using one of the following redirect methods, the 'tmp_sid' and 'temp_dir' setting will be passed # in the address bar. If you do not want the path to the temp dir passed in the address bar simply remove it # from the redirect and hard-code the $temp_dir value in the uploader_finished.php page. # # eg. $redirect_url .= "&tmp_sid=$tmp_sid"; ############################################################################################################### # Append the session-id and path to the temp dir to the redirect url. $redirect_url .= "&tmp_sid=$tmp_sid&temp_dir=$main::config->{temp_dir}"; if($main::config->{redirect_using_html}){ print "content-type:text/html; charset=utf-8\n\n"; print ""; } elsif($main::config->{redirect_using_js}){ &kak("", 1, __LINE__); } elsif($main::config->{redirect_using_location}){ # Uncomment next line if using Webstar V # print "HTTP/1.1 302 Redirection\n"; print "Location: $redirect_url\n\n"; } } } else{ # We are not redirecting so dump upload results to screen using CGI &display_results_through_cgi(); } exit; ######################################################### START SUBROUTINES ################################################### ######################################## # Delete the temp dir based on tmp_sid ######################################## sub cleanup{ deldir($temp_dir_sid); } ##################################### # Display upload results through cgi ##################################### sub display_results_through_cgi{ &confirm_upload(); &display_results(); } ##################################################### # Confirm uploaded file exist and get size file size ##################################################### sub confirm_upload{ for my $file_name (keys %uploaded_files){ for my $upload_slot ( keys %{ $uploaded_files{$file_name} } ){ my $path_to_file = $main::config->{upload_dir} . $file_name; if(-e $path_to_file && -f $path_to_file){ $uploaded_files{$file_name}{$upload_slot} = -s $path_to_file; } } } } #################################### # Format the upload result and exit #################################### sub display_results{ my ($upload_result, $email_file_list, $bg_col, $buffer, $js_code) = (); my $i = 0; if(defined($query->param('embedded_upload_results')) && $query->param('embedded_upload_results') == 1){ $upload_result .= "\n"; } $upload_result .= "\n"; $upload_result .= " \n"; $upload_result .= " \n"; $upload_result .= " \n"; # Loop over the file names creating table elements for my $file_name (keys %uploaded_files){ if($i%2){ $bg_col = 'cccccc'; } else{ $bg_col = 'dddddd'; } for my $upload_slot ( keys %{ $uploaded_files{$file_name} } ){ if($uploaded_files{$file_name}{$upload_slot} > 0){ my $file_size = &format_bytes($uploaded_files{$file_name}{$upload_slot}, 99); if($main::config->{link_to_upload}){ $upload_result .= "
  UPLOADED FILE NAME    UPLOADED FILE SIZE  
{path_to_upload}$file_name\" TARGET=\"_blank\">$file_name<\/td>$file_size<\/td><\/tr>\n"; } else{ $upload_result .= "
 $file_name <\/td>$file_size<\/td><\/tr>\n"; } if($main::config->{link_to_upload_in_email}){ $email_file_list .= "File Name: $main::config->{path_to_upload}$file_name File Size: $file_size\n"; } else{ if($main::config->{unique_upload_dir}){ $email_file_list .= "File Name: $unique_dir/$file_name File Size: $file_size\n"; } else{ $email_file_list .= "File Name: $file_name File Size: $file_size\n"; } } } else{ $upload_result .= "
 $file_name <\/td>Failed To Upload<\/font><\/td><\/tr>\n"; $email_file_list .= "File Name: $file_name File Size: Failed To Upload !\n"; } } $i++; } $upload_result .= "
\n"; $upload_result .= "
\n"; if($main::config->{send_email_on_upload}){ &email_upload_results($email_file_list); } &kak($upload_result, 1, __LINE__); } ########################################## # Send an email with the upload results. ########################################## sub email_upload_results{ my $file_list = shift; my $path_to_sendmail = "/usr/sbin/sendmail -t"; my $message; my ($ssec, $smin, $shour, $smday, $smon, $syear, $swday, $syday, $sisdst) = localtime($start_time); my $end_time = time(); my ($esec, $emin, $ehour, $emday, $emon, $eyear, $ewday, $eyday, $eisdst) = localtime($end_time); my @abbr = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); $eyear += 1900; $syear += 1900; if(open(SENDMAIL, "|$path_to_sendmail")){ print SENDMAIL "From:" . $main::config->{from_email_address} . "\n"; print SENDMAIL "To:" . $main::config->{to_email_address} . "\n"; print SENDMAIL "Subject:" . $main::config->{email_subject} . "\n"; if($main::config->{html_email_support}){ print SENDMAIL 'Content-type: text/html; charset=utf-8; format=flowed' . "\r\n"; } else{ print SENDMAIL 'Content-type: text/plain; charset=utf-8; format=flowed' . "\r\n"; } $message = "\nStart Upload: " . $abbr[$smon] . " " . $smday . ", " . $syear . ", " . $shour . ":" . $smin . ":" . $ssec . "\n"; $message .= "End Upload: " . $abbr[$emon] . " " . $emday . ", " . $eyear . ", " . $ehour . ":" . $emin . ":" . $esec . "\n"; $message .= "SID: ". $tmp_sid . "\n"; $message .= "Remote IP: " . $ENV{'REMOTE_ADDR'} . "\n"; $message .= "Browser: " . $ENV{'HTTP_USER_AGENT'} . "\n\n"; $message .= $file_list; print SENDMAIL $message; close(SENDMAIL); } else{ warn("Failed to open sendmail $!"); } } #################################################### # formatBytes($file_size, 99) mixed file sizes # formatBytes($file_size, 0) KB file sizes # formatBytes($file_size, 1) MB file sizes etc #################################################### sub format_bytes{ my $bytes = shift; my $byte_format = shift; my $byte_size = 1024; my $i = 0; my @byte_type = (" KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"); $bytes /= $byte_size; if($byte_format == 99 || $byte_format > 7){ while($bytes > $byte_size){ $bytes /= $byte_size; $i++; } } else{ while($i < $byte_format){ $bytes /= $byte_size; $i++; } } $bytes = sprintf("%1.2f", $bytes); $bytes .= $byte_type[$i]; return $bytes; } ##################################################################### # Print config, driver settings and 'Environment Variables' to screen ##################################################################### sub debug{ my ($msg, $temp_dir_state, $upload_dir_state) = (); if(!-d $main::config->{temp_dir}){ $temp_dir_state = "$main::config->{temp_dir}<\/font>"; } else{ $temp_dir_state = "$main::config->{temp_dir}<\/font>"; } if(!-d $main::config->{upload_dir}){ $upload_dir_state = "$main::config->{upload_dir}<\/font>"; } else{ $upload_dir_state = "$main::config->{upload_dir}<\/font>"; } $msg .= "UBER UPLOADER CONFIG SETTINGS<\/b><\/u>
\n"; $msg .= "CONFIG_FILE = $main::config->{config_file_name}<\/b>
\n"; $msg .= "UBER UPLOADER VERSION = $UBER_VERSION<\/b>
\n"; $msg .= "UU_UPLOAD = $THIS_VERSION<\/b>
\n"; if($MULTI_CONFIGS_ENABLED){ $msg .= "MULTI_CONFIGS_ENABLED = enabled<\/b>
\n"; } else{ $msg .= "MULTI_CONFIGS_ENABLED = disabled<\/b>
\n"; } $msg .= "TEMP_DIR = $temp_dir_state<\/b>
\n"; $msg .= "UPLOAD_DIR = $upload_dir_state<\/b>
\n"; $msg .= "MAX_UPLOAD = " . format_bytes($main::config->{max_upload}, 99) . "<\/b>
\n"; $msg .= "GET_DATA_SPEED = $main::config->{get_data_speed}<\/b>
\n"; if($main::config->{cedric_progress_bar}){ $msg .= "CEDRIC_PROGRESS_BAR = enabled<\/b>
\n"; } else{ $msg .= "CEDRIC_PROGRESS_BAR = disabled<\/b>
\n"; } if($main::config->{unique_upload_dir}){ $msg .= "UNIQUE_UPLOAD_DIR = enabled<\/b>
\n"; $msg .= "UNIQUE_UPLOAD_DIR_LENGTH = $main::config->{unique_upload_dir_length} chars<\/b>
\n"; } else{ $msg .= "UNIQUE_UPLOAD_DIR = disabled<\/b>
\n"; } if($main::config->{unique_file_name}){ $msg .= "UNIQUE_FILE_NAME = enabled<\/b>
\n"; $msg .= "UNIQUE_FILE_NAME_LENGTH = $main::config->{unique_file_name_length} chars<\/b>
\n"; } else{ $msg .= "UNIQUE_FILE_NAME = disabled<\/b>
\n"; } if($main::config->{create_files_by_rename}){ $msg .= "CREATE_FILES_BY_RENAME = enabled<\/b>
\n"; } else{ $msg .= "CREATE_FILES_BY_RENAME = disabled<\/b>
\n"; } if($main::config->{overwrite_existing_files}){ $msg .= "OVERWRITE_EXISTING_FILES = enabled<\/b>
\n"; } else{ $msg .= "OVERWRITE_EXISTING_FILES = disabled<\/b>
\n"; } if($main::config->{normalize_file_names}){ $msg .= "NORMALIZE_FILE_NAMES = enabled<\/b>
\n"; } else{ $msg .= "NORMALIZE_FILE_NAMES = disabled<\/b>
\n"; } if($main::config->{normalize_file_names}){ $msg .= "NORMALIZE_FILE_LENGTH = $main::config->{normalize_file_length} chars<\/b>
\n"; } if($main::config->{normalize_file_names}){ $msg .= "NORMALIZE_FILE_DELIMITER = $main::config->{normalize_file_delimiter}<\/b>
\n"; } if($main::config->{delete_param_file}){ $msg .= "DELETE_PARAM_FILE = enabled<\/b>
\n"; } else{ $msg .= "DELETE_PARAM_FILE = disabled<\/b>
\n"; } if($main::config->{link_to_upload}){ $msg .= "LINK_TO_UPLOAD = enabled<\/b>
\n"; $msg .= "PATH_TO_UPLOAD = {path_to_upload}\">$main::config->{path_to_upload}
\n"; } else{ $msg .= "LINK_TO_UPLOAD = disabled<\/b>
\n"; } if($main::config->{send_email_on_upload}){ $msg .= "SEND_EMAIL_ON_UPLOAD = {to_email_address}?subject=Uber Uploader Email Test\">enabled<\/b>
\n"; $msg .= "EMAIL_SUBJECT = $main::config->{email_subject}<\/b>
\n"; if($main::config->{html_email_support}){ $msg .= "HTML_EMAIL_SUPPORT = enabled<\/b>
\n"; } else{ $msg .= "HTML_EMAIL_SUPPORT = disabled<\/b>
\n"; } if($main::config->{link_to_upload_in_email}){ $msg .= "LINK_TO_UPLOAD_IN_EMAIL = enabled<\/b>
\n"; } else{ $msg .= "LINK_TO_UPLOAD_IN_EMAIL = disabled<\/b>
\n"; } } else{ $msg .= "SEND_EMAIL_ON_UPLOAD = disabled<\/b>
\n"; } if($main::config->{redirect_after_upload}){ $msg .= "REDIRECT_AFTER_UPLOAD = enabled<\/b>
\n"; if($main::config->{redirect_using_js_html}){ $msg .= "REDIRECT_USING_JS_HTML = enabled<\/b>
\n"; } else{ $msg .= "REDIRECT_USING_JS_HTML = disabled<\/b>
\n"; } if($main::config->{redirect_using_html}){ $msg .= "REDIRECT_USING_HTML = enabled<\/b>
\n"; } else{ $msg .= "REDIRECT_USING_HTML = disabled<\/b>
\n"; } if($main::config->{redirect_using_js}){ $msg .= "REDIRECT_USING_JS = enabled<\/b>
\n"; } else{ $msg .= "REDIRECT_USING_JS = disabled<\/b>
\n"; } if($main::config->{redirect_using_location}){ $msg .= "REDIRECT_USING_LOCATION = enabled<\/b>
\n"; } else{ $msg .= "REDIRECT_USING_LOCATION = disabled<\/b>
\n"; } $msg .= "REDIRECT_URL = {redirect_url}?cmd=about\">$main::config->{redirect_url}<\/a>
\n"; } else{ $msg .= "REDIRECT_AFTER_UPLOAD = disabled<\/b>
\n"; } $msg .= "
ENVIRONMENT VARIABLES<\/b><\/u>
\n"; foreach my $key (sort keys(%ENV)){ $msg .= "$key = $ENV{$key}<\/b>
\n"; } &kak($msg, 1, __LINE__); } ############################################ # Rename uploaded file if it already exists ############################################ sub rename_filename{ my $file_name = shift; my $count = shift; my $path_to_file = $main::config->{upload_dir} . $file_name; if(-e $path_to_file && -f $path_to_file){ if($file_name =~ /(.*)_(\d*)\.(.*)/){ # Already renamed so count on $count = $2 + 1 ; $file_name =~ s/(.*)_(\d*)\.(.*)/$1_$count\.$3/; } else{ # not renamed so start counting $file_name =~ s/(.*)\.(.*)/$1_$count\.$2/; } &rename_filename($file_name, $count); } else{ return $file_name; } } ####################### # Normalize file name ###################### sub normalize_filename{ my $file_name = shift; my $delimiter = shift; my $max_file_length = shift; #$file_name =~ s/\s+//g; if(length($file_name) > $max_file_length){ $file_name = substr($file_name, length($file_name) - $max_file_length); } $file_name =~ s/[^a-zA-Z0-9\_\ \.\-]/$delimiter/g; return $file_name; } ######################### # Generate Randon String ######################### sub generate_random_string{ my $length_of_randomstring = shift; my @chars=('a'..'z','A'..'Z','0'..'9'); my $random_string; for(my $i = 0; $i < $length_of_randomstring; $i++){ $random_string .= $chars[int(rand(58))]; } return $random_string; }