#!/usr/bin/perl
##################################################
# Upload v1.0 for News Pro						 # 
# By Russ Mckendrick							 # 
# Email: russ@rock-city.co.uk					 # 
# Web:   www.rock-city.co.uk					 #
# You may have to change the top line to point	 #
# to your path to perl		  					 #
##################################################

require 'nplib.pl';

# Read in the News Pro Settings
open(NPCFG, 'nsettings.cgi');
while (<NPCFG>) {
($varname, $varvalue) = split(/``x/, $_);
$varvalue =~ s/^\s+//;
$varvalue =~ s/\s+$//;
$varvalue =~ s/\n//g;
$NPConfig{$varname} = $varvalue;
}
close(NPCFG);

# Upload The Files
use CGI; 
$onnum = 1;
while ($onnum != 11) {
$req = new CGI;
$file = $req->param("FILE$onnum");
$dir = $req->param("THEDIR");
if ($file ne "") {
my $fileName = $file; 
$fileName =~ s!^.*(\\|\/)!!; 
$newmain = $fileName;
if ($NPConfig{'AllowAll'} ne "yes") {
if (lc(substr($newmain,length($newmain) - 4,4)) ne $NPConfig{'TheExt'}){
$filenotgood = "yes";
}
}
if ($filenotgood ne "yes") {
open (OUTFILE, ">$dir/$fileName");
binmode(OUTFILE);
print "$dir/$fileName<br>";
while (my $bytesread = read($file, my $buffer, 1024)) {
print OUTFILE $buffer;
}
close (OUTFILE); 
}
}
$onnum++;
}

print "Content-type: text/html\n";
print "Location:$ENV{HTTP_REFERER}\n\n";	
