#!/usr/bin/perl
#############################################################
# In Hits der Topliste auswerten
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Autor: Helmut Walter
# E-Mail: webmaster@inspire-net.de
# Webseite: http://www.inspire-world.de
#############################################################
use CGI::Carp qw(fatalsToBrowser);
# Dateiflock
use Fcntl qw(:DEFAULT :flock);
use CGI qw(:standard);
use CGI;
use DBI;
$object = new CGI;
@names = $object->param();
%FORM = map {$_ => $object->param($_)} $object->param();
$| = 1;
# Name des Programms
$progname = "in.cgi";
use lib "routinen/module/";
use Archive::FRWtools;
# Benoetigte Dateien einbinden
require "setup/setup.pl";
require "setup/extraconfig.pl";
require "routinen/module/scriptlibrary.pl";
$votequery = hextostring($ENV{QUERY_STRING});
($queryfirst, $querylast) = split(/&/, $votequery);
($tlform, $tl) = split(/=/, $queryfirst);
($voteform, $vote) = split(/=/, $querylast);
# Toplisten ID
$tl = datensaver($tl);
$tl =~ s/[^0-9]//g;
# Toplisteneintrags ID
$vote = datensaver($vote);
$vote =~ s/[^0-9]//g;
##############################################################
# Cookie
$tlvotecookie = cookie("$tl$vote");
($votedentry,$toplistnumber) = split(/\|/, $tlvotecookie);
##############################################################
if($ENV{'HTTP_X_FORWARDED_FOR'} ne ""){
$user_ip = $ENV{'HTTP_X_FORWARDED_FOR'};
} else {
$user_ip = $ENV{'REMOTE_ADDR'};
}
&verbinden;
$betreiberlogolink = qq~~;
##########################################################################
# Pruefung ob Toplisten ID vorhanden
my $members = $prefix . "members";
my $tlcheck = 0;
my $querycheck = "SELECT COUNT(*) as total FROM $members WHERE id ='$tl'";
$sth = $dbh->prepare($querycheck);
$sth->execute or die DBI->errstr;
($total) = $sth->fetchrow();
$sth->finish;
# und Fehler ausgebe wenn TL nicht gefunden
if ($total != 1) {
print "Content-type: text/html\n\n";
print "
Topliste nicht gefunden!
";
exit;
}
##########################################################################
# Konfigurationsdaten holen
my $konfiguration = $prefix . "konfiguration";
my $sth = $dbh->prepare("SELECT mem_id, sperrtime, toptitel, gateway, reset FROM $konfiguration WHERE mem_id = '$tl'");
my $isc = $sth->execute or die DBI->errstr;
@confdata = $sth->fetchrow_array();
# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# conf_id mem_id toptitel maxlist sperrtime maxbanner gateway sotm reset renew mailnew fschalt mbwidth mbheight regeln implinktext implink
$sth->finish; # Fertig
##########################################################################
# Toplistentabellenbreitenkonfiguration
require "$htmlpfad/tl/$confdata[0]/daten/tabbreite.pl";
# Toplisten IN/OUT auf 0 setzen
$akttime = datumsroutine("HI");
@tlrestime = FRWtools::DateialsZeile("$htmlpfad/tl/$tl/daten/reset.txt");
if ($akttime > $tlrestime[0]) {
$toplistendaten = $prefix . "toplisten";
$sth = $dbh->prepare("UPDATE $toplistendaten SET hitin = '0', hitout = '0' WHERE inhaber_id = '$tl'");
$sth->execute or die DBI->errstr;
$sth->finish;
# Resetzeit neu schreiben in Datei
$rtag_sek = 86400 * $confdata[4];
$reset_sekn = $akttime + $rtag_sek;
FRWtools::writelinie("$reset_sekn", "$htmlpfad/tl/$tl/daten/reset.txt");
# Counter auf 0 setzen
FRWtools::writelinie("0", "$htmlpfad/tl/$tl/daten/counter.txt");
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# Aufrufparameter der Haupt und Modulroutinen
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
$subaufrufparameter = $FORM{'aktion'};
if (($subaufrufparameter eq '' && $subaufrufroutine eq '')) {
&tlv;
} elsif (($subaufrufparameter ne '' && $subaufrufroutine eq '')) {
&$subaufrufparameter;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
sub tlv {
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# Voten ohne Gateway Seite anzuzeigen
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
if ($confdata[3] == 0) {
@ignorieren = ("");
$aktuellezeit = datumsroutine("HI");
open(ANTICHEAT, "+>>$htmlpfad/tl/$tl/daten/timeout.txt");
flock(ANTICHEAT,2);
seek(ANTICHEAT,0,0);
@eintraege = ;
seek(ANTICHEAT,0,0);
truncate(ANTICHEAT,0);
$zaehlen = 1;
$ignorieren = 0;
foreach (@ignorieren){
if ($user_ip eq $_){
$zaehlen = 0;
$ignorieren = 1;
}
}
print ANTICHEAT "$user_ip|$vote|$tl|$aktuellezeit\n" if (!$ignorieren);
foreach $cheatline (@eintraege){
$cheatline =~ s/[\n\r]//g;
($uip,$uv,$tln,$zeit) = split(/\|/, $cheatline);
if ($aktuellezeit - $zeit <= $confdata[1] * 60 * 60 && $uip ne $user_ip && $uv ne $vote){
print ANTICHEAT "$cheatline\n";
}
if ($aktuellezeit - $zeit <= $confdata[1] * 60 * 60 && $uip eq $user_ip && $uv eq $vote){
$venr = $uv;
$zaehlen = 0;
}
}
flock(ANTICHEAT,8);
close(ANTICHEAT);
if ($tlvotecookie ne "") {
$zaehlen = 0;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
if ($zaehlen != 0){
# Toplisteneintrag um 1 erhoehen
$toplistendaten = $prefix . "toplisten";
$sth = $dbh->prepare("UPDATE $toplistendaten SET hitin = hitin + 1 WHERE toplist_id = '$vote'");
$sth->execute or die DBI->errstr;
$sth->finish;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# Cookie setzen
$addcokkietime = $confdata[1] * 60 * 60;
$ende_cookdate = datumsroutine("EI","0","$addcokkietime");
print "Set-Cookie: $tl$vote=$vote|$tl; expires=$ende_cookdate \n";
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# Weiterleiten zur Topliste
$zq = $zaehlen == 1 ? "?ok" : '';
print "Location: $htmlverz/tl/$tl/index.html$zq\n\n";
exit;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# Voten mit Gateway Seite
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
} elsif ($confdata[3] == 1) {
$sektionstitel = "Voting abgeben";
&Headerout;
# Seitenheader ausgeben# ###########################################
my @head = FRWtools::DateialsArray("$htmlpfad/tl/$tl/daten/header.txt");
my $hedat = join('', @head);
$userheadercode = $hedat;
$tltitle = $sektionstitel;
$tlidcss = "$htmlverz/tl/$tl/$tl";
print tparser("$cgipfad/toplisttemplates/header.html");
# Seitenheader ausgeben #############################################
$backtotoplist = qq~Topliste ohne Voten aufrufen~;
print qq~
";
# Footer ausgeben ###################################################
my @foot = FRWtools::DateialsArray("$htmlpfad/tl/$tl/daten/footer.txt");
my $fodat = join('', @foot);
$userfootercode = $fodat;
print tparser("$cgipfad/toplisttemplates/footer.html");
# Footer ausgeben ###################################################
} # ende elsif
} # ende sub
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# Voten mit Gateway Seite
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
sub mv {
my $tl = datensaver($FORM{'tl'});
my $vote = datensaver($FORM{'vote'});
$tl =~ s/[^0-9]//g;
$vote =~ s/[^0-9]//g;
@ignorieren = ("");
$aktuellezeit = datumsroutine("HI");
open(ANTICHEAT, "+>>$htmlpfad/tl/$tl/daten/timeout.txt");
flock(ANTICHEAT,2);
seek(ANTICHEAT,0,0);
@eintraege = ;
seek(ANTICHEAT,0,0);
truncate(ANTICHEAT,0);
$zaehlen = 1;
$ignorieren = 0;
foreach (@ignorieren){
if ($user_ip eq $_){
$zaehlen = 0;
$ignorieren = 1;
}
}
print ANTICHEAT "$user_ip|$vote|$tl|$aktuellezeit\n" if (!$ignorieren);
foreach $cheatline (@eintraege){
$cheatline =~ s/[\n\r]//g;
($uip,$uv,$tln,$zeit) = split(/\|/, $cheatline);
if ($aktuellezeit - $zeit <= $confdata[1] * 60 * 60 && $uip ne $user_ip && $uv ne $vote){
print ANTICHEAT "$cheatline\n";
}
if ($aktuellezeit - $zeit <= $confdata[1] * 60 * 60 && $uip eq $user_ip && $uv eq $vote){
$venr = $uv;
$zaehlen = 0;
}
}
flock(ANTICHEAT,8);
close(ANTICHEAT);
if ($tlvotecookie ne "") {
$zaehlen = 0;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
if ($zaehlen != 0){
# Toplisteneintrag um 1 erhoehen
$toplistendaten = $prefix . "toplisten";
$sth = $dbh->prepare("UPDATE $toplistendaten SET hitin = hitin + 1 WHERE toplist_id = '$vote'");
$sth->execute or die DBI->errstr;
$sth->finish;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# Cookie setzen
$addcokkietime = $confdata[1] * 60 * 60;
$ende_cookdate = datumsroutine("EI","0","$addcokkietime");
print "Set-Cookie: $tl$vote=$vote|$tl; expires=$ende_cookdate \n";
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# Weiterleiten zur Topliste
$zq = $zaehlen == 1 ? "?ok" : '';
print "Location: $htmlverz/tl/$tl/index.html$zq\n\n";
exit;
}
$dbh->disconnect;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# Stingtohex & Hextostring
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
sub hextostring {
my(@out) = split(/(\w\w)/,$_[0]);
my @out2;
my $out;
foreach (@out) {
push (@out2,$_) if($_);
}
foreach (@out2) {
$out .= pack("C",hex($_));
}
return $out;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #