54
« am: 12. Dezember 2011, 08:08:56 »
Also ich probiere mir hier dran die Finger wund
Ich hätte das ganze ja noch mal in Perl aber da steh ich genauso vor den Böhmischen Dörfern
#!/usr/bin/perl
#
# Version vom 10.12.03
#
# perl V 5.6.1 oder groesser notwendig
#
#
use strict;
use CGI qw(:standart);
use CGI::Carp qw(fatalsToBrowser);
use Fcntl qw(:DEFAULT);
use vars qw($lastError);
my $q = CGI->new();
print "Content-Type: text/html\n\n";
#read input parameters
my $username = $q->param("username");
my $firstname = $q->param("firstname");
my $telephone = $q->param("telephone");
my $zipcode = $q->param("zipcode");
my $areacode = $q->param("areacode");
my $country = $q->param("country");
my $street = $q->param("street");
my $town = $q->param("town");
my $email = $q->param("email");
my $fax = $q->param("fax");
my $link = $q->param("link");
my $category = $q->param("category");
my $subcategory = $q->param("subcategory");
my $categoryID = $q->param("categoryID");
my $subcategoryID = $q->param("subcategoryID");
my $adverttype = $q->param("adverttype");
my $busitype = $q->param("busitype");
my $advertheader = $q->param("advertheader");
my $advertbody = $q->param("advertbody");
my $adults_only = $q->param("adults_only");
my $advertID = $q->param("advertID");
my $action = $q->param("action");
my $xml = $q->param("xml");
# Get the current time.
my($date) = scalar(localtime());
# Append the data to a file.
open(F, ">>tester.txt");
print F "From $0 at $date\n";
#for $key (keys %CGI) {
# print F "$key => $CGI{$key}\n";
#}
print F "Name: $username \n";
print F "Vorname: $firstname \n";
print F "Telefon: $telephone \n";
print F "PLZ: $zipcode \n";
print F "Vorwahl: $areacode \n";
print F "Land-Vorwahl: $country \n";
print F "Strasse: $street \n";
print F "Stadt: $town \n";
print F "Email: $email \n";
print F "Fax: $fax \n";
print F "URL: $link \n";
print F "Kategorie: $category \n";
print F "Unterkategorie: $subcategory \n";
print F "KategorieID: $categoryID \n";
print F "SubkategorieID: $subcategoryID \n";
print F "Suchen-Bieten: $adverttype \n";
print F "Privat-Gesch: $busitype \n";
print F "Anzeigenkopf: $advertheader \n";
print F "Anzeigentext: $advertbody \n";
print F "Nur für Erwachsene: $adults_only \n";
print F "ID der Anzeige: $advertID \n";
print F "Action: $action \n";
print F "XML-String: $xml \n";
close(F);
#print "<pre>\n";
receiveAdsImage($q) or die ("FATAL: receiveAdsImage fatal error: ".defined($lastError)?$lastError:$!."\n");
my $resHash;
$resHash->{'duration'} = escapeString('30');
$resHash->{'link'} = escapeString('http://www.test.de');
$resHash->{'comment'} = escapeString('Anzeigenschleuder - Test: dieses Skript erhalten die Maerkte im Mitglied-Bereich unter: cgi-submission -> test.cgi');
printXMLResponce($resHash);
#print "</pre>\n";
exit;
#recieve and store advert image file if exist
sub receiveAdsImage {
my($query) = @_;
$lastError = undef;
unless (defined($query->param('asimage')) && ($query->param('asimage') !~ /^\w*$/)) {
return 1;
} else {
#T print $query->param('asimage')."<br>\n";
my $file = $query->upload('asimage');
my $fileinfo = $query->uploadInfo($file);
my $fileext;
#determine file name as transmitted (full path may be included)
my $filename = getFileName($file,$query->uploadInfo($file)->{'Content-Disposition'});
#determine file extension
if ($filename =~ /\.(jpg|jpeg|gif|png)$/i) {
$fileext = lc($1);
} else {
$lastError = "Falscher Typ der Bild-Datei. Nur jpeg (jpg), png, gif sind erlaubt.";
return;
}
#genertate random file name
#my $fileID = generateID(10);
my $advertID = $q->param("advertID");
my $fileID = "pic-$advertID";
#compose complete file name with random name and determined extension
my $storeFile = "$fileID.$fileext";
#Tprint "Size $storeFile= $filesize\n<br>";
if (!$file && $query->cgi_error) {
$lastError = "Fehler beim Holen der Bild-Datei im CGI.";
return;
}
if (not sysopen FILE, "$storeFile", O_EXCL | O_CREAT | O_WRONLY, 0600) {
$lastError = "Fehler bei der Erzeugung der Bild-Datei. ($!)";
return;
} else {
my $buffer = "";
my $BUFFER_1K = 1024;
my ($fsize,$rsize) = (0,0);
binmode FILE;
while (($rsize = read ($file, $buffer, $BUFFER_1K))) {
print FILE $buffer or return; #print("Fehler beim Schreiben der Bild-Datei. ($!)\n");
$fsize += $rsize;
}
close FILE;
# print ("Store image file (name=$storeFile,size = $fsize)\n");
return 2;
}
}
}
#Used in receiveAdsImage function
sub getFileName {
my ($cginame, $disp) = @_;
my $name;
if ($disp =~ /filename\=\"(.+)\"/) {
$name = ($1);
} else {
$name = $cginame;
}
return $name;
}
#generate random string $idSize chars length
sub generateID {
my $idSize = shift;
$idSize = 8 if not defined($idSize);
my @chars = ("A".."Z","a".."z",1..9);
return join("", @chars[ map{rand @chars} (1..$idSize) ]);
}
sub escapeString {
my $res = shift;
$res =~ s/\&/\&/g;
$res =~ s/\</\</g;
$res =~ s/\>/\>/g;
$res =~ s/\"/\"/g;
$res =~ s/\'/\'/g;
return $res;
}
sub printXMLResponce {
$resHash = shift;
print <<HTMLTEXT;
<?xml version="1.0" encoding="ISO-8859-1"?>
<advertreturn>
<advertduration>$resHash->{'duration'}</advertduration>
<advertlink>$resHash->{'link'}</advertlink>
<comment>$resHash->{'comment'}</comment>
</advertreturn>
HTMLTEXT
}