Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://www.sao.ru/cats/~satr/perl/perl_8.shtml
Äàòà èçìåíåíèÿ: Sat Jun 24 18:06:10 2000
Äàòà èíäåêñèðîâàíèÿ: Tue Oct 2 01:16:06 2012
Êîäèðîâêà: koi8-r

Ïîèñêîâûå ñëîâà: solar eclipse
Ñïèñîê ðàññûëêè íîâîñòåé

Ñïèñîê ðàññûëêè íîâîñòåé

Ïîìèìî ãîñòåâîé êíèãè îñíîâíûì àòðèáóòîì ñåðüåçíîãî Web-óçëà ÿâëÿåòñÿ ñïèñîê ðàññûëêè íîâîñòåé. Perl-ïðîãðàììà äëÿ âûïîëíåíèÿ ðàññûëêè äîâîëüíî ïðîñòà, ïðè æåëàíèè åå ìîæíî íåñêîëüêî óëó÷øèòü, äîáàâèâ íîâûå âîçìîæíîñòè (ñì. ëèñòèíã 9).

Ïðè ñîçäàíèè Web-óçëà, îðèåíòèðîâàííîãî êàê íà ðóññêîÿçû÷íûõ, òàê è íà àíãëîÿçû÷íûõ ïîñåòèòåëåé, â ïðîãðàììå ïðåäóñìîòðåíà âîçìîæíîñòü âûäà÷è ñîîáùåíèé â ñîîòâåòñòâóþùåì âèäå. Îñíîâíàÿ ôîðìà (ðèñ. 3) â çàâèñèìîñòè îò ÿçûêà óçëà äîëæíà îáÿçàòåëüíî ñîäåðæàòü ïîëå:

 

èëè


äëÿ ðàñïîçíàâàíèÿ ÿçûêà âûäà÷è ñîîáùåíèé.

×òîáû îáëåã÷èòü ðàçáîð ïðîãðàììû ðàññûëêè íîâîñòåé, â íåé ðàññòàâëåíû êîììåíòàðèè.

Ëèñòèíã 9. Ñïèñîê ðàññûëêè íîâîñòåé

#!/usr/local/bin/perl
############################
# SCRIPT: POSTER.CGI       #
# (c) Michael Yevdokimov   #
############################

require ‘cgi_lib.pl’;

$PathList=”../mlist”; #ôèçè÷åñêèé ïóòü ê êàòàëîãó ñ áàçîé ïîñåòèòåëåé
$PathNews=”../mnews”; #ôèçè÷åñêèé ïóòü ê êàòàëîãó ñ äîêóìåíòîì äëÿ ïîñûëêè
$ReturnPage=”index.html” #ñòðàíèöà, ê êîòîðîé íóæíî áóäåò âîçâðàòèòüñÿ

$mail_prog=”/usr/sbin/sendmail”; #ôèçè÷åñêèé àäðåñ ê ïî÷òîâîé ïðîãðàììå
$Title=”News List”; #çàãîëîâîê ñïèñêà ðàññûëêè
$From=”maillist\@mysite.ru”; #àäðåñ ñïèñêà ðàññûëêè
$Website=”www.mysite.ru”; #èñòî÷íèê ñïèñêà ðàññûëêè äëÿ Subject
# Method Detection and Decoding
&Parse_Data;  # äåêîäèðîâàòü äàííûå èç ôîðìû / URL

$Lang=$CGI{‘lang’};  # òèï ÿçûêà (Ðóñ/Àíãë) 
$User=$CGI{‘user_name’}; # èìÿ ïîñåòèòåëÿ
$Email=$CGI{‘user_email’}; # email ïîñåòèòåëÿ
$Flag=$CGI{‘flag’}; # ôëàã äëÿ ïðîâåðêè íåêîòîðûõ óñëîâèé â ïðîãðàììå
$Command=$CGI{‘command’}; # ñ÷èòàòü êîìàíäó (send èëè ‘’)

if ($Lang eq ‘english’) {
	$db=”userbase.eng”; # áàçà ñ èíîñòðàííûìè ïîäïèñ÷èêàìè
        $nf=”news.eng” # àíãëèéñêàÿ ”ïîñûëêà” (îáû÷íûé TXT)
} else {
        if ($Lang eq ‘russian’) {
        	$db=”userbase.rus”; ” ñ ðîññèéñêèìè ïîäïèñ÷èêàìè
		$nf=”news.rus”; ðóññêàÿ ”ïîñûëêà” (îáû÷íûé TXT)
        } else {
		&Print_Head; # àíàëîãè÷íî print ”Content-type:text/html\n\n”;
		print ”

ATTENTION! ERROR OCCURED!

\n”; print ”PRESS [BACK] TO RETURN!\n”; exit(0); } } if ($Command eq ‘send’) { # ïðîâåðêà òîé ñàìîé êîìàíäû if ($db eq ‘userbase.eng’) { #Post English News &Post_News($User,$Email); } else { #Post Russian News &Post_News($User,$Email); } } #Ïðîâåðèòü çíà÷åíèå àòðèáóòà flag if ($Flag eq ‘eng_yes’) { # åñëè èíôîðìàöèÿ âåðíà &Check_Email; # âûçâàòü ïîäïðîãðàììó ïðîâåðêè ââåäåííîãî email &Add_Record($Path,$db); # äîáàâèòü çàïèñü â ñîîòâåò. áàçó &Print_Head; print ”Your records were added to database

\n”; print ”Click here to return...\n”; exit(0); } else { if ($Flag eq ‘rus_yes’) { &Check_Email; &Add_Record; &Print_Head; print ”Âàøè äàííûå çàíåñåíû â áàçó äàííûõ

\n”; print ”Íàæìèòå çäåñü äëÿ âîçâðàòà...\n”; exit(0); } else { } } # âûâåñòè ôîðìó ïîäòâåðæäåíèÿ ïðàâèëüíîñòè ââåäåííîé èíôîðìàöèè if ($db eq ‘userbase.eng’) { #Àíãëèéñêèé âàðèàíò ôîðìû &Print_Head; print ”

News List Registration

\n”; print ”
\n”;
  print ”
\n”; print ”
\n”; print ” Your Name:
\n”; print ”Your Email:
\n”; # äîáàâëÿåì â ôîðìó ñêðûòîå ïîëå flag, çíà÷åíèå êîòîðîãî ïðîâåðÿåòñÿ # ýòîé ïðîãðàììîé: åñëè flag ðàâåí îäíîìó èç äâóõ óêàçàííûõ çäåñü # çíà÷åíèé, òî âûïîëíÿåòñÿ ïîäïðîãðàììà äîáàâëåíèÿ ïîëüçîâàòåëÿ â ÁÄ print ”
\n”; print ” ”; print ”
\n”; print ”
\n”; print ”
\n”; } else { #Ðóññêèé âàðèàíò ôîðìû &Print_Head; print ”

Ðåãèñòðàöèÿ â ñïèñêå ðàññûëêè íîâîñòåé

\n”; print ”
\n”;
  print ”
\n”; print ”
\n”; print ” Âàøå èìÿ:
\n”; print ”Âàø Email:
\n”; # äîáàâëÿåì ñêðûòîå ïîëå flag (ñì. îïèñàíèå âûøå) print ”
\n”; print ” ”; print ”
\n”; print ”
\n”; print ”
\n”; } sub Add_Record { # ïîäïðîãðàììà çàïèñè ïîñåòèòåëåé â ÁÄ open (UB, ”>>$PathList/$db”) || die (”Error during adding a record $!”); print UB join (”::”, ”$User”, ”$Email”), ”\n”; close (UB); } sub Post_News { # ïîäïðîãðàììà ðàññûëêè íîâîñòåé #Îòêðûòü UB - áàçó ïîëüçîâàòåëåé open (UB, ”$PathList/$db”) || die (”Error during reading file $!”); while () { $line=$_; ($User, $Email) = split (/::/, $line); #Íàïðàâèòü âûâîä íà ”email” open (MAIL, ”|$mail_prog $Email”); print MAIL ”From: $From\n”; print MAIL ”Reply-to: $From\n”; print MAIL ”Subject: $Title from $Website\n”; print MAIL ”\n\n”; print MAIL ”Dear $User,\n\n”; #Îòêðûâàåì ôàéë íîâîñòåé è ñ÷èòûâàåì èç íåãî äàííûå open (NF, ”$PathNews/$nf”) || die (”Error during reading file $!”); while () { print MAIL ”$_”; # íàïðàâëÿåì ñ÷èòàííûå äàííûå íà email } close (NF); # print MAIL ”\n\nThis script was created by Michael Yevdokimov\n”; print MAIL ”Developer’s website: http://www.basicnet.sonnet.ru\n”; print MAIL ”\n\n”; close (MAIL); } close (UB); &Print_Head; print ”PRESS [BACK] TO RETURN!\n”; exit(0); } sub Check_Email { # ïîäïðîãðàììà ïðîâåðêè ïðàâèëüíîñòè ââåäåííîãî email &Err_Msg; if ($Email !~ /.+\@.+\..+/) { &Print_Head; &Err_Msg; print ”$ErrMsg\n”; #print ”Location: $ENV{‘HTTP_REFERER’}\n\n”; exit(0); } #exit(0); } sub Err_Msg { # ôóíêöèÿ âûâîäà ñîîáùåíèÿ îá îøèáêå â email if ($Lang eq ‘english’) { $ErrMsg=”ATTENTION! ERROR OCCURED!

\n Email: $Email which you have entered is incorrect!

\n PRESS [BACK] TO RETURN\n”; return $ErrMsg; } else { $ErrMsg=”ÂÍÈÌÀÍÈÅ! ÂÎÇÍÈÊËÀ ÎØÈÁÊÀ!

\n Email: $Email, êîòîðûé âû ââåëè íåïðàâèëåí!

\n ÍÀÆÌÈÒÅ [BACK] ÄËß ÂÎÇÂÐÀÒÀ\n”; return $ErrMsg; } }

Íàçàä | Ñîäåðæàíèå | Âïåðåä