#!/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";
require "allhtml.pl";
print "Content-Type: text/html\n\n";
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=~/^d/ && $f_v ne '1'){$f_v = 0}
if($f_n eq 'move'){push(@td,$f_v)}else{$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";
$today = "$DayInMonth.$month[$Month].$Year";
########## Удаление сайта ##########
### Шаг 1 - Запрос подтверждения ###
if($in{'action'} eq ""){
print qq~
<title>Блокировка сайта</title><body bgcolor="#E8E8E8"><p align="center">
Заблокировать к показу сайт<br>$in{'site'}</p>
<center><table border="0" cellpadding="0" cellspacing="0"><tr><td align="right">
<form method="POST"><INPUT TYPE=HIDDEN NAME="action" VALUE="yes">
<INPUT TYPE=HIDDEN NAME="url" VALUE="$in{'url'}">
<INPUT TYPE=HIDDEN NAME="user" VALUE="$in{'user'}">
<INPUT TYPE=HIDDEN NAME="site" VALUE="$in{'site'}">
<p align="center"><input type="submit" value="    Да   " name="yes"></p>
</form></td><td width="3"></td><td align="left"><form method="POST">
<INPUT TYPE=HIDDEN NAME="action" VALUE="no">
<p><input type="submit" value="  Нет  " name="no"></p></form></td></tr></table></center>
~;}
### ШАГ 2 - Подтверждение ###
if($in{'action'} eq 'yes'){
open(URLS,"./urls/urls.pl");
if ($flock eq "1")
{flock(URLS, 2);}
@sitesconf = <URLS>;
close(URLS);
chomp(@sitesconf);
open (LOCK, "./urls/urls.lock");
if ($flock eq "1")
{flock(LOCK, 2);}
@lock = <LOCK>;
close (LOCK);
chomp(@lock);
if ($lock[0]=='1') {
open (LOCK, ">./urls/urls.lock");
if ($flock eq "1")
{flock(LOCK, 2);}
print LOCK "0";
close (LOCK);
open(URLS,">./urls/urls.pl");
if ($flock eq "1")
{flock(URLS, 2);}
foreach (@sitesconf){
($id_url,$status,$http,$serf,$auto,$maxday,$ipday,$cat) = split(/\|/,$_);
if($in{'url'} eq $id_url){
$sf=$serf;
$aut=$auto;
$maxd=$maxday;
$ipd=$ipday;
$ct=$cat;
# Изменяем в базе
print URLS "$in{'url'}|0|$in{'site'}|$sf|$aut|$maxd|$ipd|$ct|\n";
}else{print URLS "$_\n"}}
close(URLS);
}
open (LOCK, ">./urls/urls.lock");
if ($flock eq "1")
{flock(LOCK, 2);}
print LOCK "1";
close (LOCK);





print qq~
<title>Блокировка сайта</title><body bgcolor="#E8E8E8"><p align="center">
Сайт<br>$in{'site'}<br>заблокирован к показу.<br>
<a href="javascript:window.close();"><font size="2" color="#008080">закрыть окно</font></a>
~;
}
### ШАГ 2 - Отказ ###
if($in{'action'} eq 'no'){
print qq~
<SCRIPT language=JavaScript>
window.close();
</SCRIPT>
~;
}


