#!/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;}
$root="$ENV{'DOCUMENT_ROOT'}/cgi-bin";
@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 qq~
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<body bgcolor=#E0E0E0>
~;
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(URLS,"./urls/urls.pl");
if ($flock eq "1")
{flock(URLS, 2);}
@sites = <URLS>;
close(URLS);chomp(@sites);
ALL: foreach (@sites){
($id_url,$status,$http,$serf,$auto,$maxday,$ipday,$cat) = split(/\|/,$_);
($Uid,$URLid) = split(/_/,$id_url);
if($status ne '1'){next ALL}
if($userid eq $Uid){next ALL}
open(STAT,"./users/$Uid/stat.user");
if ($flock eq "1")
{flock(STAT, 2);}
@stat=<STAT>;
close(STAT);chomp(@stat);
if($stat[1] <= 0){next ALL}
if($serf ne '1'){next ALL}
# Читаем из базы пользователя
open(SITES,"./urls/$Uid.urls");
if ($flock eq "1")
{flock(SITES, 2);}
@urls = <SITES>;
close(SITES);
chomp(@urls);
foreach (@urls){
($id_url,$title,$targ,$showed,$inserf,$inauto,$log) = split(/\|/,$_);
($Uid,$URLids) = split(/_/,$id_url);
if($URLid eq $URLids){
($dl,$lip)=split(/\+/,$log);
if($dl eq $today && $maxday > 0 && $ipday > 0){
@ip=split(/\,/,$lip);
$allip=$#ip;
$allip++;
$uniqip=0;
IP: foreach (@ip){
($nuip,$tip)=split(/=/,$_);
if($ENV{'REMOTE_ADDR'} eq $nuip){$uniqip++}}
if($uniqip >= $ipday or $allip >= $maxday){next ALL}}
if($maxday <= 0){next ALL}
$http2=$http;$ok='1';$url2=$id_url;
last ALL;
}}}
if($ok eq '1'){
$user=$in{'user'};
$rnd=rand;
# Создаем временный файл
open H,">./users/$userid/serf.temp";
print H "$rnd\n";
close(H);
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}}
print qq~
<script language="Javascript">
setTimeout('add_point()', 30000);
function add_point(){
var objDate = new Date();
var pointpic = new Image;
var string = "ok_r.cgi?user=$in{'user'}&url=$url2&rnd=$rnd";
pointpic.src = string;
}
</script>
<script language="Javascript">
parent.main.location.href = "$http2";
var entered = new Date()
function track()
{var now = new Date()
var seconds = 30 - Math.floor((now.getTime() - entered.getTime()) / 1000)
document.p.s.value='Ждите... '+seconds +' сек';
if (seconds <=0) {
document.p.s.value="Далее >>>";
}
var timeID= setTimeout("track()",1000)}
</script>
<script language=JavaScript>
t=0;function change(){t=1;}function check(){if (t==0){
document.write('<body bgcolor="#E0E0E0"><p align="center"><font size="5" color="red">Просмотр с отключенной графикой считается накруткой системы!!!</font></p>');
alert('Для работы Вам необходимо включить загрузку графики в Вашем браузере.');}}</script>
<body onLoad="track(); check();" >
<body onload=track() LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>

<table bgcolor="#E0E0E0" width=98% height=70 border=0 cellspacing="0" cellpadding="0" height=70>
<tr><td width="170" align="left">
<center></center><form method="post" name="p" action="serf.cgi">
<p align="center">
<input type="hidden" name="user" value="$in{'user'}"><font color="#E0E0E0" size="1">.<br>
</font><INPUT alt="Далее" style="background-color: transparent; cursor: hand; height: 24; width: 140; font-size: 14pt; border-style: none; border-width: 2px" type=submit value="Ждите 30 сек..." name="s">
<br></form></td><td align="center" width="110">
<a href="$http2" target=_blank><font face="Verdana" size="1"><span style="letter-spacing: 0">Перейти&nbsp;
на&nbsp; сайт <font color="#000080">(новое окно)</font></span><br>
</font></a><a HREF="javascript:" onclick="SB1 = window.open('bansite.cgi?user=$in{'user'}&url=$url2&site=$http2','SB1','width=290,height=100');"><font face="Verdana" size="1">Блокировать
сайт<br></font></a></td><td valign="top" align="right">$banserf
</td></tr></table><img src=$imgurl/t.gif  onload="change();">
~;
}else{
print qq~
<script language="JavaScript">
function track2() {
parent.main.location.href = "$htmlurl/stop.htm";
}
</script>
<body onload=track2() LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
~;
}
print qq~</body></html>
~;

