# yratit - yogurtrat png UPLOAD script
# Derived from Upload script by Erik Möller - moeller AT scireview DOT de - public domain
#
# Then run the script on the command line using
#
# $ perl upload.pl dirname
#
# where dirname/ is the name of a directory containing the files to
# be uploaded. After uploading the bbcode will be returned to stdout.
#
# Don't edit below unless you know what you're doing.
# We need these libraries. They should be part of a standard Perl
# distribution.
use LWP::Simple;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
use Encode qw(encode);
use warnings;
$docstring="Please read yratit.pl for documentation.\n";
my $dir=$ARGV[0] or die "Syntax: perl yratit.pl directory\n$docstring";
# Make Unix style path
$dir=~s|\\|/|gi;
# Remove trailing slashes
$sep=$/; $/="/"; chomp($dir); $/=$sep;
my $browser=LWP::UserAgent->new();
my @ns_headers = (
'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20041107 Firefox/1. 0',
'Accept' => 'image/gif, image/x-xbitmap, image/jpeg,
image/pjpeg, image/png, */*',
'Accept-Charset' => 'iso-8859-1,*,utf-8',
'Accept-Language' => 'en-US',
);
opendir(DIR, "$dir");
my @flist = readdir(DIR);
my $linecount = 0;
foreach $file(@flist) {
if ($file =~ /png$/ || $file =~ /PNG$/ || $file =~ /jpg$/ ||$file =~ /JPG$/) {
print "Uploading $file to yogurtrat.\n";
uploadfile:
$ecfile=encode('utf8',$file);
if($ecfile ne $file) {
symlink("$file","$dir/$ecfile");
}
$response=$browser->post("http://public.yogurtrat.com/index2.php",
@ns_headers,Content_Type=>'form-data',Content=>
[
userfile=>["$dir/$ecfile"],
upload=>"Upload",
]);
if($response->code!=302 && $response->code!=200) {
print "Upload failed! Will try again. Output was:\n";
print $response->as_string;
goto uploadfile;
} else {
print "Uploaded successfully.\n";
my @data = split /\n/, $response->as_string;
foreach $line(@data) {
if ($line =~ /BBCode/) {
$line =~ s/.*value=\"//;
$line =~ s/\".*//;
if($linecount == 0) {
push @bbcode,$line;
$linecount++;
} else {
push @bbcode,$line . "\n";
$linecount = 0;
}
}
}
}
}
}
print "Everything seems to be OK, printing to $dir/bbcode.txt and console now.\n";
open(BBCODE,">$dir/bbcode.txt") or die "Could not write file.\n";
print BBCODE @bbcode;
print @bbcode;