#!/usr/bin/perl ######################################## # WOnews v3.0 # сделано 2001 WOscripts # http://www.woscripts.com # wo@womail.net # ######################################## # VARIABLES # ######################################## my $filename="wonews.cgi"; # Имя скрипта my $datafd="data"; # каталог для хранения данных my $datafile="data.data"; # Путь к файлу-базе ######################################## #--------------------------------------- use strict; use CGI qw(:standard); use CGI::Carp qw/fatalsToBrowser/; use locale; use vars qw($date $convert $timet $weekd $timeoffset $html_output $body $timeoffset @news_view); $|=1; #--------------------------------------- # **************** Default Vars ******************* my($ff)="$datafd/setup.data"; open(FILE, "<$ff"); my $config=; close(FILE); my($file_url,$sys,$maxmess,$template,$max_show,$timeoffset)=split(/\|/, $config); # ************************************************* # *************** Set defoult vars **************** unless (-e "$datafd/setup.data") { if (! -e $datafd) { mkdir("data", 0777) || die("Cant create data - dir ", $!); } open(FILE,">$datafd/setup.data") || die("Can't create data-file $datafd/setup.data ",$!); print FILE "http://$ENV{'HTTP_HOST'}$ENV{'SCRIPT_NAME'}|UNIX|1000|wonews.htmlt|10|1|"; close(FILE); chmod(0660,"$datafd/setup.data"); print "Location: $filename\n\n"; } # ---------------------------------------------------- if (! -e "$datafd/template.data" || param('act') eq "defaultt") { open(TL, ">$datafd/template.data") || die("Can't create template-file $datafd/template.data ",$!); my $fill_in = qq~
[*TIME*] [*WEEK_DAY*]
[*NEWS*]
~; print TL "$fill_in"; close(TL); chmod(0660,"$datafd/template.data"); } # ************************************************************ if (param('password')) { &cookies; } if (param('level') eq "setup") { setup(); } if (param('act') eq "safe_setup") { safe_setup(); } if (param('view') eq "view") { &view; exit; } if (param('act') eq "archive") { &archive; exit; } if (param('act') eq "del") { &deleted; } if (param('act') eq "edit") { &editpre; exit; } if (param('edit_end')) { &edit_end; } if (param('news')) { exist_file("$datafd/$datafile"); &timed; my $mess=param('message'); $mess=~s/\r\n/ /g; $mess=~s/\|/\\/g; $mess=~s/\"/"/g; $mess=~s/\'/"/g; if (length($mess)<=5 || length($mess)>=$maxmess) { $body.= qq~

ОШИБКА - пожалуйста введите правильное количество символов
не меньше 6 и не больше $maxmess.

Вернуться на главную страницу >>

>$datafd/$datafile") or die("Can not open data file ",$!); if ($sys ne "NT") { flock(FILE, 2); } my $tt=time; print FILE "$tt|$mess|$date|$weekd|\n"; close(FILE); $body.= qq~

Новости за $date были успешно добавлены.

Вернуться на главную страницу >>

Установки

~; open (FILE, "<$datafd/$datafile") or exist_file("$datafd/$datafile"); my @lines=; close(FILE); foreach(reverse @lines) { my @mas=split(/\|/, $_); chomp(@mas); $body.= qq~
$mas[2] | $mas[3]

<edit> | <delete>

$mas[1]

~; } &show_html_output; } # ************************** CHECK FILE ******************************* sub exist_file { my($file)=@_; unless (-e $file) { open(FILE,">$file") || die("Can't create data-file",$!); close(FILE); chmod(0666,$file); } } # ************************** TIME ********************************** sub timed { my($sec,$min,$hours,$mday,$month,$year,$wday,$yday,$isdst)=localtime(time+(3600*$timeoffset)); $month=$month+1; if ($min < 10) {$min="0$min";} if ($hours < 10) {$hours="0$hours";} if ($sec < 10) {$sec="0$sec";} if ($mday < 10) {$mday="0$mday";} if ($month <10) {$month="0$month";} my @days = qw(Воскресенье Понедельник Вторник Среда Четверг Пятница Суббота); $year=2000+($year-100); $year=substr($year,2); $timet="$hours:$min"; $date="$mday/$month/$year"; $weekd=$days[$wday]; return ($date,$timet); } # **************************** DELETE ****************************** sub deleted { my $id=param('id'); open (FILE, "<$datafd/$datafile"); my @lines=; close (FILE); open (DFILE, ">$datafd/$datafile"); if ($sys ne "NT") { flock(DFILE, 2); } foreach (@lines) { my @mas=split(/\|/, $_); if ($id eq "$mas[0]") { print DFILE ""; } else { print DFILE "$_"; } } close(DFILE); } # ********************************* EDIT PREVIEW *************************** sub editpre { my $id=param('id'); open (FILE, "<$datafd/$datafile"); my @lines=; close (FILE); foreach (@lines) { my @mas=split(/\|/, $_); chomp(@mas); if ($id eq "$mas[0]") { $body.= qq~
~; } } &show_html_output; } # **************************** EDIT END ****************************** sub edit_end { my $id=param('id'); my $mess=param('text'); $mess=~s/\r\n/ /g; $mess=~s/\|/\\/g; $mess=~s/\"/"/g; $mess=~s/\'/"/g; my $date=param('date'); my $weekd=param('weekd'); open (FILE, "<$datafd/$datafile"); my @lines=; close (FILE); open (EFILE, ">$datafd/$datafile"); if ($sys ne "NT") { flock(EFILE, 2); } foreach (@lines) { my @mas=split(/\|/, $_); if ($id eq "$mas[0]") { print EFILE "$id|$mess|$date|$weekd|\n"; } else { print EFILE "$_"; } } close(EFILE); } # ++++++++++++++++++++++++++++++++++++ VIEW ++++++++++++++++++++++++ sub view { open (FILE, "<$datafd/$datafile"); my @lines=; my $i; close(FILE); my $rr=scalar(@lines); if ($rr < $max_show) { $max_show=$rr; } print "Content-type: text/html\n\n"; for($i=$rr-1; $i>=$rr-$max_show; $i--) #(reverse @lines) { my @mas=split(/\|/, $lines[$i]); chomp(@mas); open (TFILE, "<$datafd/template.data") or die("Can't open template file to read ",$!); while () { $convert.=$_; } close (TFILE); $convert=~s/\[\*NEWS\*\]/$mas[1]/g; $convert=~s/\[\*TIME\*\]/$mas[2]/g; $convert=~s/\[\*WEEK_DAY\*\]/$mas[3]/g; } print "$convert\n"; if ($rr > $max_show) { print qq~

Архив >>

~; } } # ************************ SUB show_html_output ******************** sub show_html_output { my($dat); open(FILE, "<$template"); while () { $dat.=$_; } my $cook=cookie('passw'); unless ($cook) { $body=""; $body=qq~

 

~; } $dat=~s/\$POST/$body/g; print "Content-type: text/html\n\n"; print "$dat"; } # *************************** SUB Cookie **************************** sub cookies { my $named=param('name'); my $pass=param('pass'); $pass=crypt($pass, substr($pass,-1)); my $script_path=$ENV{'SCRIPT_NAME'}; open (F, "<$datafd/pass.dat"); my($line)=; close (F); my($n, $p)=split(/\|/, $line); if($named eq "$n" && $pass eq "$p") { my $cookie=cookie( -name => "passw", -value => "name=$named,password=$pass", -path => "$script_path"); # -expires => "+2y"); print header(-cookie => $cookie); print qq~ ~; exit; } else { print "Location:$filename\n\n"; exit; } } # *************************** Sub Archive ******************** sub archive { my($dat); my $body; open (FILE, "<$datafd/$datafile"); my @lines=; my $i; close(FILE); my $rr=scalar(@lines); print "Content-type: text/html\n\n"; print ("

Архив новостей


"); for($i=$rr-$max_show-1; $i>=0; $i--) #(reverse @lines) { my @mas=split(/\|/, $lines[$i]); chomp(@mas); open (TFILE, "<$datafd/template.data") or die("Can't open template file to read ",$!); while () { $convert.=$_; } close (TFILE); $convert=~s/\[\*NEWS\*\]/$mas[1]/g; $convert=~s/\[\*TIME\*\]/$mas[2]/g; $convert=~s/\[\*WEEK_DAY\*\]/$mas[3]/g; } print "$convert\n"; } # ************************* SUB Setup ************************ sub setup { my($ff)="$datafd/setup.data"; open(FILE, "<$ff"); my $config=; close(FILE); my($file_url1,$sys1,$maxmess1,$template1,$max_show1,$timeoffset1)=split(/\|/, $config); open(TL, "<$datafd/template.data") || die("Can't open template file to read ",$!); my @news_view=; close(TL); $body.= qq~
Установки
URL  к файлу скрипту
Система (UNIX/NT)
Максимальное количество символов в новости
Путь к файлу шаблону
Максимальное кол. выводимых новостей
Часовое отклонение
Вид выводимых новостей
Вернуться к стандартному виду

<< На главную >>

~; show_html_output(); exit; } # *************************** SUB safe_setup ********************** sub safe_setup { my $file_url_s=param('file_url'); my $sys_s=param('sys'); my $maxmess_s=param('maxmess'); my $template_s=param('template'); my $max_show_s=param('max_show'); my $timeoffset_s=param('timeoffset'); my $news_view_s=param('news_view'); open(FILE,">$datafd/setup.data") || die("Can't open data-file to write ",$!); if ($sys eq "UNIX") { flock(FILE,2); } print FILE "$file_url_s|$sys_s|$maxmess_s|$template_s|$max_show_s|$timeoffset_s|"; close(FILE); open (T, ">$datafd/template.data") or die("Can't open template file to write ",$!); if ($sys eq "UNIX") { flock(T,2); } print T "$news_view_s"; close(T); print "Location: $filename?level=setup\n\n"; }