#!/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 "../adminhtml.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";
$file = "mail.txt";
&html_start;
if ($in{'action'} eq "Подписать") {&subscribe}
if ($in{'action'} eq "Удалить") {&unsubscribe}
if ($in{'action'} eq "Отправить") {&send}
if ($in{'pwd'} ne "$adminpwd") {&adminerror}
if ($in{'pwd'} eq "$adminpwd") {&adminform}
sub adminerror
{
print qq~
&nbsp; <h3 align="center"><font color="#8E7CCD" size="3">
Вход в центр администрирования</font></h3>
<form method="POST" action="$cgiurl/admincap.cgi">
<input type="hidden" name="step" value="stat">
<div align="center"><center><table border=0>
<tr><td>Логин:</td><td><input name="admin"></td></tr>
<tr><td>Пароль:</td><td><input type="password" name="pwd"></td></tr>
<tr><td colspan=2><p align="center">
<input type="submit" value="В о й т и"></p>
</td></tr></table></center></div></form><br><br><p align="center">
<font color="#800000"><b><br>
</b></font><b><br><br><br>
~;
&html_end;
exit;
}
#### Форма отправки ####
sub adminform
{
$number=0;
open(LIST,"$file");
if ($flock eq "1")
{flock(LIST, 2);}
@addresses=<LIST>;
print LIST "$number\n";
close(LIST);
$number = push(@addresses);
print qq~
<center><table width=95%><td align=center>
<br>В настоящее время <font color=red>$number</font> e-mail адресов в списке.
~;
open(LIST,"archiv/log.txt");
if ($flock eq "1")
{flock(LIST, 2); }
@entries=<LIST>;
close(LIST);
@entries = reverse(@entries);
foreach $entry(@entries)
{
print "<option>$entry\n";
$x++;
}
print qq~
<form method=post><input type="hidden" name="admin" value="$in{'admin'}">
<input type="hidden" name="pwd" value="$in{'pwd'}">
Тема:<input type=text name=subject><BR><BR>Сообщение:<BR>
<textarea name=message rows=12 cols=50></textarea><BR><BR>
<input type=submit name=action value=Отправить><input type=reset value=Очистить name=>
</FORM><BR><form method=post><input type=text name=address>
<input type="hidden" name="admin" value="$in{'admin'}">
<input type="hidden" name="pwd" value="$in{'pwd'}">
<input type=submit name=action value=Подписать><br><TABLE><TR><TD>
<form method=post><select name=address size=6>
~;
@addresses = sort(@addresses);
foreach $member(@addresses)
{
print qq~
<option>$member
~;
$x++;
}
print qq~
</select></TD></TR><TR><TD><CENTER><input type="hidden" name="admin" value="$in{'admin'}">
<input type="hidden" name="pwd" value="$in{'pwd'}"><input type=submit name=action value=Удалить>
</CENTER></TD></TR></TABLE></form></form><BR></td></table></body></html>
~;
}
#### Заносим новый адрес в базу ####
sub subscribe
{
open(LIST,"$file");
@addresses=<LIST>;
close(LIST);
foreach $member(@addresses)
{
chomp($member);
if ($in{'address'} eq $member){
print qq~
<br><br>Адрес <font color=red>$in{'address'}</font> уже есть в базе.<br><br>
<br><br><br><br><br><br><br><br><br><br>
~;
&html_end;
exit;}
}
push (@addresses,$in{'address'});
open(LIST,">>$file");
if ($flock eq "1")
{flock(LIST, 2); }
print LIST "$in{'address'}\n";
close(LIST);
print qq~
<br><br>E-mail адрес <font color=red>$in{'address'}</font> успешно внесен в список
<br><br><br><br><br><br><br><br><br><br><br><br>
~;
&html_end;
exit;
}
#### Удаляем адрес ####
sub unsubscribe
{
open(LIST,"$file");
@addresses=<LIST>;
close(LIST);$x=0;
foreach $member(@addresses)
{
chomp($member);
$member=~ s/^\s+//;
$member=~ s/\s+$//;
if ($in{'address'} eq $member){&deletemember}
$x++;
}
print qq~
<br><br>Адреса <font color=red>$in{'address'}</font> нет в базе.<br><br><br><br>
<br><br><br><br><br><br><br><br><br><br>
~;
&html_end;
exit;
}
sub deletemember
{
@addresses[$x]="";
open(LIST,">$file");
foreach $member(@addresses)
{
chomp($member);
$member=~ s/^\s+//;
$member=~ s/\s+$//;
unless($member eq "")
{print LIST "$member\n";}
}
print qq~
<br><br>Адрес <font color=red>$in{'address'}</font> был успешно удален.
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>
~;
&html_end;
exit;
}
#### Отправляем письма ####
sub send
{
open(LIST,"$file");
@addresses=<LIST>;
close(LIST);
foreach $member(@addresses)
{
chomp($member);
open (MAIL, "|$mailprog -t");
if ($html eq "1") {print MAIL "Content-type:text/html\n";}
print MAIL "From: $adminmail\n";
print MAIL "To: $member\n";
print MAIL "Subject: $in{'subject'}\n\n";
print MAIL "$in{'message'}\n\n";
close (MAIL);
}
print qq~
<br><br>Ваше сообщение успешно отправлено.<br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br>
~;
&html_end;
exit;
}
&html_end;







































