#!/perl/5.00502/bin/MSWin32-x86-object/perl -w
$board_name = "Конференция журнала ЭКО";
$rev_messages = 0;
$change_smiles = 1;
$pat = "/inetpub/wwwroot/eco/cgi-bin/";
%forums = (
"001", "Экономика предприятий",
"002", "Деловая культура",
"003", "Бизнес, управление",
"004", "Прогнозы, статистика",
"005", "Менеджмент",
"006", "Социальные отношения",
"007", "Другое",
);
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s///g;
$value =~ s/<([^>]|\n)*>//g;
$FORM{$name} = $value;
}
$temp=$ENV{'QUERY_STRING'};
@pairs=split(/&/,$temp);
foreach $item(@pairs) {
($key,$content)=split (/=/,$item,2);
$content=~tr/+/ /;
$content=~ s/%(..)/pack("c",hex($1))/ge;
$FORM{$key}=$content;
}
($s,$m,$h,$d,$mn,$y) = (localtime)[0..5];
$y+=1900;
$mn++;
if ($s < 10) {
$s = "0$s";
}
if ($m < 10) {
$m = "0$m";
}
if ($h < 10) {
$h = "0$h";
}
if ($mn < 10) {
$mn = "0$mn";
}
$time_post = "$d.$mn.$y в $h:$m:$s";
if($FORM{'action'} eq 'show_topics') {&show_topics;}
if($FORM{'action'} eq 'make_topic') {&make_topic;}
if($FORM{'action'} eq 'view_topic') {&view_topic;}
if($FORM{'action'} eq 'register') {®ister;}
if($FORM{'action'} eq 'register_try') {®_apply;}
if($FORM{'action'} eq 'install') {&install;}
if($FORM{'action'} eq 'reply_message') {&reply_message;}
if($FORM{'action'} eq 'change_profile') {&change_profile;}
else {&show_themes;}
$copyright = "";
sub show_themes {
print ("Content-Type: text/html\n\n");
open(HEAD,"/inetpub/wwwroot/eco/cgi-bin/header.txt");
@head =
;
close(HEAD);
foreach (@head) {
print $_;
}
print "[ регистрация ] [ ваши данные ] [ faq ]
\n";
print "\n";
print " | Название раздела | Топиков в разделе |
\n";
foreach $file (keys %forums) {
$res = "/inetpub/wwwroot/eco/cgi-bin/voprosy/" . "$file.txt";
open(TOPICS, $res);
#open(TOPICS,"$file.txt");
@topics = ;
close(TOPICS);
$top_q = @topics;
print " | $forums{$file} | $top_q |
\n"; #top_q
}
print "
\n";
print "
$copyright";
open(FOOT,"/inetpub/wwwroot/eco/cgi-bin/footer.txt");
@foot = ;
close(FOOT);
foreach (@foot) {
print $_;
}
exit;
}
sub show_topics {
$res = "/inetpub/wwwroot/eco/cgi-bin/voprosy/" . "$FORM{'theme'}.txt";
open(TOPICS, $res);
@topics = ;
close(TOPICS);
@topics = reverse(@topics);
$top_q = @topics;
print ("Content-Type: text/html\n\n");
open(HEAD,"/inetpub/wwwroot/eco/cgi-bin/header.txt");
@head = ;
close(HEAD);
foreach (@head) {
print $_;
}
# print "Всего сообщений: $top_q
\n";
print " Раздел \"$forums{$FORM{'theme'}}\". Всего сообщений: $top_q
\n";
print "\n";
print "Тема сообщения | Автор | Ответов | Последнее изменение |
\n";
foreach $topic (@topics) {
@topic_params = split(/\|\|/,$topic);
print "$topic_params[1] | ";
if($topic_params[6] ne '') {
print "$topic_params[2]";
}
else {
print "$topic_params[2]";
}
print " | $topic_params[3] | $topic_params[4] |
\n";
}
print "
\n";
print "\n
$copyright";
open(FOOT,"/inetpub/wwwroot/eco/cgi-bin/footer.txt");
@foot = ;
close(FOOT);
foreach (@foot) {
print $_;
}
exit;
}
sub make_topic {
✓
chdir("/inetpub/wwwroot/eco/cgi-bin/users");
open(USER_NAME,"$FORM{'name'}.pl");
@data = ;
chomp($data[4]);
chomp($data[1]);
if ($data[4] eq $FORM{'email'}) {
$FORM{'email'} = $data[1];
}
chdir("../");
$res = "/inetpub/wwwroot/eco/cgi-bin/voprosy/" . "$FORM{'theme'}.txt";
open(TOPICS, $res);
@topics_array = ;
close(TOPICS);
$topics = @topics_array + 1;
$res = "/inetpub/wwwroot/eco/cgi-bin/voprosy/" . "$FORM{'theme'}.txt";
open(TOPICS,">> $res");
print TOPICS "||$FORM{'topic'}||$FORM{'name'}||0||$time_post||board.pl?action=view_topic\&topic=$topics\&theme=$FORM{'theme'}||$FORM{'email'}||\n";
close(TOPICS);
$FORM{'message'} =~ s/\n/
/g;
$res = "$FORM{'theme'}/$topics";
open(TOPIC,"> $res");
print TOPIC "||$FORM{'topic'}||$FORM{'name'}||1||$time_post||$FORM{'message'}||$FORM{'email'}||\n";
close(TOPIC);
print ("Content-Type: text/html\n\n");
open(HEAD,"/inetpub/wwwroot/eco/cgi-bin/header.txt");
@head = ;
close(HEAD);
foreach (@head) {
print $_;
}
print "\n";
print "Тема
$FORM{'topic'} была добавлена вами $time_post\n в раздел $forums{$FORM{'theme'}}
$copyright";
print"
Назад\n";
print "
\n";
open(FOOT,"/inetpub/wwwroot/eco/cgi-bin/footer.txt");
@foot = ;
close(FOOT);
foreach (@foot) {
print $_;
}
exit;
}
sub view_topic {
$res = "/inetpub/wwwroot/eco/cgi-bin/" . "$FORM{'theme'}" . "/" . "$FORM{'topic'}";
open(TOPIC, $res);
@messages = ;
close(TOPIC);
$prev = $FORM{'topic'} - 1;
$next = $FORM{'topic'} + 1;
print ("Content-Type: text/html\n\n");
open(HEAD,"/inetpub/wwwroot/eco/cgi-bin/header.txt");
@head = ;
close(HEAD);
foreach (@head) {
print $_;
}
$replies = @messages - 1;
(undef,$topic_name,undef,undef,$last_change,undef,undef,undef) = split(/\|\|/,$messages[-1]);
(undef,undef,$name_author,undef,undef,undef,$author_email,undef) = split(/\|\|/,$messages[0]);
$topic = $FORM{'topic'};
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "| << | home | >> |
\n";
print " | \n";
print "\n";
if ($rev_messages) { @messages = reverse(@messages); }
foreach $message (@messages) {
&change_smiles if $change_smiles = 1;
(undef,undef,$name,undef,$date,$message,$email,undef) = split(/\|\|/,$message);
print "\n";
print "\n";
print "";
if ($email ne '') {
print "$name";
}
else {
print $name;
}
print " ( $date ) | \n";
print "[наверх]\n";
print " | \n";
print " \n";
print " $message
| \n";
print " \n";
}
print " |
\n
$copyright";
open(FOOT,"/inetpub/wwwroot/eco/cgi-bin/footer.txt");
@foot = ;
close(FOOT);
foreach (@foot) {
print $_;
}
exit;
}
sub register {
print ("Content-Type: text/html\n\n");
open(HEAD,"/inetpub/wwwroot/eco/cgi-bin/header.txt");
@head = ;
close(HEAD);
foreach (@head) {
print $_;
}
print "Регистрация
\n";
print "\n";
print "\n* - обязательные для заполнения поля.
$copyright";
open(FOOT,"/inetpub/wwwroot/eco/cgi-bin/footer.txt");
@foot = ;
close(FOOT);
foreach (@foot) {
print $_;
}
exit;
}
sub reg_apply {
chdir("/inetpub/wwwroot/eco/cgi-bin/users");
if (!(-e "$FORM{'name'}.pl")) {
open(USER_PROFILE,">$FORM{'name'}.pl");
print USER_PROFILE "$FORM{'name'}\n";
print USER_PROFILE "$FORM{'email'}\n";
print USER_PROFILE "$FORM{'homepage'}\n";
print USER_PROFILE "$FORM{'icq'}\n";
print USER_PROFILE "$FORM{'password'}\n";
print USER_PROFILE "$FORM{'interests'}\n";
print USER_PROFILE "$FORM{'place'}\n";
close(USER_PROFILE);
}
chdir("../");
print ("Content-Type: text/html\n\n");
open(HEAD,"/inetpub/wwwroot/eco/cgi-bin/header.txt");
@head = ;
close(HEAD);
foreach (@head) {
print $_;
}
print "\n";
print "Вы успешно зарегистрировались. Ваше имя:
$FORM{'name'}, пароль:
$FORM{'password'}\n
$copyright";
print"
Назад\n";
print "
\n";
open(FOOT,"/inetpub/wwwroot/eco/cgi-bin/footer.txt");
@foot = ;
close(FOOT);
foreach (@foot) {
print $_;
}
exit;
}
sub change_profile {
if (!($FORM{'step'})) {
print ("Content-Type: text/html\n\n");
open(HEAD,"/inetpub/wwwroot/eco/cgi-bin/header.txt");
@head = ;
close(HEAD);
foreach (@head) {
print $_;
}
print "Введите ваше имя и пароль
\n";
print "\n";
print "\n* - обязательные для заполнения поля.
$copyright";
open(FOOT,"/inetpub/wwwroot/eco/cgi-bin/footer.txt");
@foot = ;
close(FOOT);
foreach (@foot) {
print $_;
}
exit;
}
elsif($FORM{'step'} eq '2') {
open(USER_PROFILE,"users/$FORM{'name'}.pl");
@data = ;
close(USER_PROFILE);
chomp($data[4]);
if($FORM{'password'} ne $data[4]) {&error('Неправельный пароль');}
print ("Content-Type: text/html\n\n");
open(HEAD,"/inetpub/wwwroot/eco/cgi-bin/header.txt");
@head = ;
close(HEAD);
foreach (@head) {
print $_;
}
print "Измените данные
\n";
print "\n";
print "\n* - обязательные для заполнения поля.
$copyright";
open(FOOT,"/inetpub/wwwroot/eco/cgi-bin/footer.txt");
@foot = ;
close(FOOT);
foreach (@foot) {
print $_;
}
exit;
}
elsif ($FORM{'step'} eq '3') {
chdir("/inetpub/wwwroot/eco/cgi-bin/users");
open(USER_PROFILE,">$FORM{'name'}.pl");
print USER_PROFILE "$FORM{'name'}\n";
print USER_PROFILE "$FORM{'email'}\n";
print USER_PROFILE "$FORM{'homepage'}\n";
print USER_PROFILE "$FORM{'icq'}\n";
print USER_PROFILE "$FORM{'password'}\n";
print USER_PROFILE "$FORM{'interests'}\n";
print USER_PROFILE "$FORM{'place'}\n";
close(USER_PROFILE);
chdir("../");
print ("Content-Type: text/html\n\n");
open(HEAD,"/inetpub/wwwroot/eco/cgi-bin/header.txt");
@head = ;
close(HEAD);
foreach (@head) {
print $_;
}
print "Вы успешно изменили данные. Ваше имя: $FORM{'name'}, пароль: $FORM{'password'}\n
$copyright";
print" Назад\n";
open(FOOT,"/inetpub/wwwroot/eco/cgi-bin/footer.txt");
@foot = ;
close(FOOT);
foreach (@foot) {
print $_;
}
exit;
}
else {exit;}
}
sub install {
if($FORM{'password'} eq $password) {
foreach $key (keys(%forums)) {
mkdir($key,0777);
}
mkdir("users",0777);
print ("Content-Type: text/html\n\n");
print "Инсталяция закончена.";
}
exit;
}
sub reply_message {
✓
chdir("/inetpub/wwwroot/eco/cgi-bin/users");
open(USER_NAME,"$FORM{'name'}.pl");
@data = ;
chomp($data[4]);
chomp($data[1]);
if ($data[4] eq $FORM{'email'}) {
$FORM{'email'} = $data[1];
}
chdir("../");
$res = "/inetpub/wwwroot/eco/cgi-bin/voprosy/" . "$FORM{'theme'}.txt";
open(TOPICS,"+< $res ");
#flock(TOPICS,2);
@topics = ;
$topic = $FORM{'topic'};
@topic_params = split(/\|\|/,$topics[$topic - 1]);
$topic_params[3]++;
$topic_params[4] = $time_post;
$topic_name = $topic_params[1];
$topics[$topic - 1] = join("||",@topic_params);
seek (TOPICS, 0, 0);
truncate (TOPICS,0);
print TOPICS @topics;
close(TOPICS);
$FORM{'message'} =~ s/\n/
/g;
open(TOPIC,">> $FORM{'theme'}/$topic");
print TOPIC "||$topic_name||$FORM{'name'}||1||$time_post||$FORM{'message'}||$FORM{'email'}||\n";
close(TOPIC);
print ("Content-Type: text/html\n\n");
open(HEAD,"/inetpub/wwwroot/eco/cgi-bin/header.txt");
@head = ;
close(HEAD);
foreach (@head) {
print $_;
}
print "\n";
print "Ответ на тему
$topic_name был добавлен вами $time_post\n
$copyright";
print"
Назад\n";
print "
\n";
open(FOOT,"/inetpub/wwwroot/eco/cgi-bin/footer.txt");
@foot = ;
close(FOOT);
foreach (@foot) {
print $_;
}
exit;
}
sub change_smiles {
$message =~ s/:[\)]+//g;
$message =~ s/:\(//g;
$message =~ s/\:D//g;
$message =~ s/\;[\)]+//g;
$message =~ s/\:o//g;
}
sub check {
if ($FORM{'name'} ne '') {
$name = $FORM{'name'};
$name =~ s/"//g;
$name =~ s//g;
$name =~ s/>//g;
$name =~ s/\&//g;
$FORM{'name'} = $name;
}
else {$FORM{'name'} = '[Аноним]';}
if ($FORM{'topic'} ne '') {
$topic = "$FORM{'topic'}";
$topic =~ s/\&/\&\;/g;
$topic =~ s/"/\"\;/g;
$FORM{'topic'} = $topic;
}
else {
&error('Вы не ввели тему.');
}
if (!($FORM{'message'} ne '')) {
&error('Вы не ввели текст сообщения.');
}
}
sub error {
$err = $_[0];
print ("Content-Type: text/html\n\n");
print "\n";
print "\n";
print "$board_name ошибка\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "$err\n
$copyright";
print "\n";
print "\n";
print "\n";
exit;
}