#!/usr/bin/perl
#############################################################
##            ExchangeVisits    Version  3.00              ##
##            February 2003  Ust-Nera  Russia              ##
##            All rights  ScriptZaWM&RuScript              ##
##            Web  http://www.script.zawm.biz              ##
##            Support scripts script@zawm.biz              ##
#############################################################
require "config.pl";
if($ENV{'REQUEST_METHOD'} eq 'GET'){$query=$ENV{'QUERY_STRING'}}
elsif($ENV{'REQUEST_METHOD'} eq 'POST'){sysread(STDIN,$query,$ENV{'CONTENT_LENGTH'})}
@formfields=split(/&/,$query);
sub urldecode{
local($val)=@_;
$val=~s/\+/ /g;
$val=~s/%([0-9a-hA-H]{2})/pack('C',hex($1))/ge;
return $val;}
foreach (@formfields){chomp($_);
($f_n,$f_v)=split(/=/,$_);
$f_n=&urldecode($f_n);
$f_v=&urldecode($f_v);
if($f_n eq 'move'){push(@td,$f_v)}else{$in{$f_n}=$f_v}
$in{$f_n}=$f_v;}
@month = ("01", "02", "03", "04", "05", "06", "07",
"08", "09", "10", "11", "12");
($Seconds, $Minutes, $Hours, $DayInMonth, $Month, $ShortYear, $DayOfWeek,
$DayOfYear, $IsDST) = localtime(time);
$Year = $ShortYear + 1900;$Year=~s/^..//;
$Date = "$DayInMonth.$month[$Month].$Year<time>$Hours:$Minutes:$Seconds";
$today = "$DayInMonth.$month[$Month].$Year";
print "Content-Type: text/html; charset=windows-1251\n\n";
open(PWD,"userdat.pl");
if ($flock eq "1")
{flock(PWD, 2);}
@users = <PWD>;
close(PWD);chomp(@users);
foreach (@users){
($login,$pwd,$id,$status,$dr,$dc) = split(/\|/,$_);
if($in{'user'} eq $login){$userid=$id}}
# Проверка временного файла
open H,"./users/$userid/serf.temp";
@temp = <H>;
close(H); chomp(@temp);
if($in{'rnd'} ne $temp[0]){
print "<p><font color=red><b>Накрутка!<br>Пользователь: $in{'user'}<br>IP-адрес: $ENV{REMOTE_ADDR}<br><font color=blue>Отправка данных администрации успешно выполнена.</b></font></p>";
exit;
}
# Конец
open(PWD,"userdat.pl");
if ($flock eq "1")
{flock(PWD, 2);}
@users = <PWD>;
close(PWD);chomp(@users);
foreach (@users){
($login,$pwd,$id,$status,$dr,$dc) = split(/\|/,$_);
if($in{'user'} eq $login){$userid=$id}}
open(ROT,"./system/config.pl");
if ($flock eq "1")
{flock(ROT, 2);}
@rotation = <ROT>;
close(ROT);chomp(@rotation);
open(USERSTAT,"./users/$userid/stat.user");
if ($flock eq "1")
{flock(USERSTAT, 2);}
@userstat = <USERSTAT>;
close(USERSTAT);chomp(@userstat);
$userstat[1] = $userstat[1] + $rotation[1];
$userstat[2]++;
$userstat[3]++;
($d8,$n8)=split(/\|/,$userstat[8]);
if($d8 eq $today){$n8++;$userstat[8]="$d8|$n8"}else{$userstat[8]="$today|1"}
($d9,$n9)=split(/\|/,$userstat[9]);
if($d9 eq $today){$n9++;$userstat[9]="$d9|$n9"}else{$userstat[9]="$today|1"}
open(USERSTAT,">./users/$userid/stat.user");
if ($flock eq "1")
{flock(USERSTAT, 2);}
foreach (@userstat){
print USERSTAT "$_\n"}
close(USERSTAT);
open(REF,"./users/$userstat[0]/stat.user");
if ($flock eq "1")
{flock(REF, 2);}
@ref1 = <REF>;
close(REF);chomp(@ref1);
$toref1=($rotation[1]/100)*$rotation[3];
$ref1[1]=$ref1[1]+$toref1;
$ref1[14]=$ref1[14]+$toref1;
open(REF,">./users/$userstat[0]/stat.user");
if ($flock eq "1")
{flock(REF, 2);}
foreach (@ref1){
print REF "$_\n"}
if ($flock eq "1")
{flock(REF, 2);}
close(REF);
open(REF,"./users/$ref1[0]/stat.user");
if ($flock eq "1")
{flock(REF, 2);}
@ref2 = <REF>;
close(REF);chomp(@ref2);
$toref2=($rotation[1]/100)*$rotation[4];
$ref2[1]=$ref2[1]+$toref2;
$ref2[16]=$ref2[16]+$toref2;
open(REF,">./users/$ref1[0]/stat.user");
if ($flock eq "1")
{flock(REF, 2);}
foreach (@ref2){
print REF "$_\n"}
close(REF);
open(REF,"./users/$ref2[0]/stat.user");
if ($flock eq "1")
{flock(REF, 2);}
@ref3 = <REF>;
close(REF);chomp(@ref3);
$toref3=($rotation[1]/100)*$rotation[5];
$ref3[1]=$ref3[1]+$toref3;
$ref3[18]=$ref3[18]+$toref3;
open(REF,">./users/$ref2[0]/stat.user");
if ($flock eq "1")
{flock(REF, 2);}
foreach (@ref3){
print REF "$_\n"}
close(REF);
open(SYS,"./system/sysstat.pl");
if ($flock eq "1")
{flock(SYS, 2);}
@sys = <SYS>;
close(SYS);chomp(@sys);
$creditserf = -(1 - $rotation[1] - ($rotation[1]/100 * $rotation[3]) - ($rotation[1]/100 * $rotation[4]) - ($rotation[1]/100 * $rotation[5]));
$sys[0]=$sys[0]+$creditserf;
$sys[1]=$sys[1]+$creditserf;
$sys[2]=$sys[2]+$creditserf;
($sd6,$sn6)=split(/\|/,$sys[6]);
if($sd6 eq $today){$sn6=$sn6+$creditserf;$sys[6]="$sd6|$sn6"}else{$sys[6]="$today|$creditserf"}
($sd7,$sn7)=split(/\|/,$sys[7]);
if($sd7 eq $today){$sn7=$sn7+$creditserf;$sys[7]="$sd7|$sn7"}else{$sys[7]="$today|$creditserf"}
$sys[11]++;
($sd12,$sn12)=split(/\|/,$sys[12]);
if($sd12 eq $today){$sn12++;$sys[12]="$sd12|$sn12"}else{$sys[12]="$today|1"}
open (LOCK, "./system/sysstat.lock");
if ($flock eq "1")
{flock(LOCK, 2);}
@lock = <LOCK>;
close (LOCK);
chomp(@lock);
if ($lock[0]=='1') {
open (LOCK, ">./system/sysstat.lock");
if ($flock eq "1")
{flock(LOCK, 2);}
print LOCK "0";
close (LOCK);
open(SYS,">./system/sysstat.pl");
if ($flock eq "1")
{flock(SYS, 2);}
foreach (@sys){
print SYS "$_\n"}
close(SYS);}
open (LOCK, ">./system/sysstat.lock");
if ($flock eq "1")
{flock(LOCK, 2);}
print LOCK "1";
close (LOCK);
($vlad,$urlid)=split(/_/,$in{'url'});
open(PUB,"./users/$vlad/stat.user");
if ($flock eq "1")
{flock(PUB, 2);}
@publisher = <PUB>;
close(PUB);chomp(@publisher);
$publisher[1]--;
$publisher[5]++;
$publisher[6]++;
open (LOCKPUB, "./users/$vlad/stat.lock");
if ($flock eq "1")
{flock(LOCKPUB, 2);}
@lockpub = <LOCKPUB>;
close (LOCKPUB);
chomp(@lockpub);
if ($lockpub[0]=='1') {
open (LOCKPUB, ">./users/$vlad/stat.lock");
if ($flock eq "1")
{flock(LOCKPUB, 2);}
print LOCKPUB "0";
close (LOCKPUB);
open(PUB,">./users/$vlad/stat.user");
if ($flock eq "1")
{flock(PUB, 2);}
foreach (@publisher){
print PUB "$_\n"}
close(PUB);}
open (LOCKPUB, ">./users/$vlad/stat.lock");
if ($flock eq "1")
{flock(LOCKPUB, 2);}
print LOCKPUB "1";
close (LOCKPUB);
open (LOCKURLS, "./urls/$vlad.lock");
@lockurls = <LOCKURLS>;
close (LOCKURLS);
chomp(@lockurls);
if ($lockurls[0]=='1') {
open (LOCKURLS, ">./urls/$vlad.lock");
if ($flock eq "1")
{flock(LOCKURLS, 2);}
print LOCKURLS "0";
close (LOCKURLS);
open(URLS,"./urls/$vlad.urls");
@sites = <URLS>;
close(URLS);chomp(@sites);
open(URLS,">./urls/$vlad.urls");
if ($flock eq "1")
{flock(URLS, 2);}
foreach (@sites){
($id_url,$title,$targ,$showed,$inserf,$inauto,$log) = split(/\|/,$_);
if($id_url eq $in{'url'}){
$showed++;
$inserf++;
($dl,$lip)=split(/\+/,$log);
if($dl eq $today){$lip="$lip,$ENV{'REMOTE_ADDR'}=1";$log="$dl+$lip"}else{$log="$today+$ENV{'REMOTE_ADDR'}=1"}
print URLS "$id_url|$title|$targ|$showed|$inserf|$inauto|$log\n";
}else{print URLS "$_\n"}
}}
close(URLS);
open (LOCKURLS, ">./urls/$vlad.lock");
print LOCKURLS "1";
close (LOCKURLS);
# Обнуляем временный файл с записью случайного числа
$rnd=rand;
open H,">./users/$userid/serf.temp";
print H "$rnd\n";
close(H);
print "Content-Type: image/gif\n\n";

