⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch19.htm

📁 CGI programming is the hottest stuff to look out for in this book
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<BR>
#<BR>
# ID# checks out okay, so add on PID info and store in %input
<BR>
#<BR>
&nbsp;&nbsp;&nbsp;$input{'id'} = $temp_id . &quot;.$$&quot;;<BR>
<BR>
}<BR>
<BR>
#<BR>
# determine whether or not the current user is ChatMaster<BR>
#<BR>
if ( ($input{'handle'} eq $cmpswd ) &amp;&amp; (!($input{'id'}
=~ /ChatMaster/)) ) {<BR>
&nbsp;&nbsp;&nbsp;$cmmode = 1;<BR>
} elsif ( ($input{'handle'} eq 'ChatMaster' ) &amp;&amp; <BR>
($input{'id'} =~ /ChatMaster/) ) {<BR>
&nbsp;&nbsp;&nbsp;$cmmode = 1;<BR>
}<BR>
<BR>
#<BR>
# if the current user is the chatmaster, adjust user's ID# in
both <BR>
# $input{'id'} variable and in the @userdata array<BR>
#<BR>
if ($cmmode) {<BR>
&nbsp;&nbsp;&nbsp;$input{'handle'} = 'ChatMaster';<BR>
&nbsp;&nbsp;&nbsp;$id = $input{'id'};<BR>
&nbsp;&nbsp;&nbsp;if (!($id =~ /ChatMaster/)) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;substr($input{'id'},$[,0)
= 'ChatMaster.';<BR>
&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;foreach ( @userdata ) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@field = split(/\t/);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!($field[0] =~ /ChatMaster/))
{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( $field[0]
eq $id ) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;substr($_,$[,0)
= 'ChatMaster.';<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;}<BR>
}<BR>
<BR>
#<BR>
# Give an error message if someone tries to be ChatMaster without
the<BR>
# correct password<BR>
#<BR>
if ( ($input{'handle'} eq 'ChatMaster' ) &amp;&amp; <BR>
(!($input{'id'} =~ /ChatMaster/)) ) {<BR>
&nbsp;&nbsp;&nbsp;&amp;chatmaster_error;<BR>
}<BR>
<BR>
#<BR>
# the following line traps forms being submitted from invalid
locations<BR>
#<BR>
&amp;print_error if ( (!($refer =~ /$baseurl/)) &amp;&amp; defined($input{'handle'})
);<BR>
<BR>
#<BR>
# If HTML is disallowed, go to the remove_html section... except
for<BR>
# the ChatMaster<BR>
#<BR>
&amp;remove_html if ( (!($html)) &amp;&amp; (!($cmmode)) );<BR>
<BR>
&amp;print_header;<BR>
&amp;print_form;<BR>
&amp;update_stack if $input{'comments'} ne '';<BR>
&amp;print_stack;<BR>
&amp;print_footer;<BR>
<BR>
&amp;update_datafile;<BR>
<BR>
exit 0;<BR>
<BR>
sub print_error {<BR>
&nbsp;&nbsp;&nbsp;print &lt;&lt;END;<BR>
&lt;HTML&gt;&lt;HEAD&gt;&lt;TITLE&gt;Invalid Submission&lt;/TITLE&gt;&lt;/HEAD&gt;
<BR>
&lt;BODY&gt;<BR>
&lt;P&gt;<BR>
The URL of the page which submitted the form which has this CGI
program<BR>
as its action was not valid.&nbsp;&nbsp;Please go to<BR>
&lt;A HREF=$baseurl/$progname&gt;$baseurl/$progname&lt;/A&gt;
to <BR>
legally access this CGI program.<BR>
&lt;/BODY&gt;&lt;/HTML&gt;<BR>
END<BR>
&nbsp;&nbsp;&nbsp;exit 1;<BR>
}<BR>
<BR>
sub chatmaster_error {<BR>
&nbsp;&nbsp;&nbsp;print &lt;&lt;END;<BR>
&lt;HTML&gt;&lt;HEAD&gt;&lt;TITLE&gt;Invalid use of ChatMaster&lt;/TITLE&gt;&lt;/HEAD&gt;
<BR>
&lt;BODY&gt;<BR>
&lt;P&gt;<BR>
An attempt was made to access ChatMaster mode illegally.<BR>
&lt;/BODY&gt;&lt;/HTML&gt;<BR>
END<BR>
&nbsp;&nbsp;&nbsp;exit 1;<BR>
}<BR>
<BR>
sub id_conflict_error {<BR>
&nbsp;&nbsp;&nbsp;print &lt;&lt;END;<BR>
&lt;HTML&gt;&lt;HEAD&gt;&lt;TITLE&gt;Multiple Login Sessions not
allowed&lt;/TITLE&gt;&lt;/HEAD&gt;<BR>
&lt;BODY&gt;<BR>
&lt;P&gt;<BR>
You may only possess one login session at a time.<BR>
&lt;P&gt;<BR>
It is (just a little) possible that someone else is using your
exact data<BR>
port information right now.&nbsp;&nbsp;If this is the case, you'll
have to wait for<BR>
them to finish their session in this chat room.<BR>
&lt;/BODY&gt;&lt;/HTML&gt;<BR>
END<BR>
&nbsp;&nbsp;&nbsp;exit 1;<BR>
}<BR>
<BR>
sub remove_html {<BR>
<BR>
#<BR>
# removes all characters between &lt; and &gt;, inclusive<BR>
# ( or, between &lt; and EOL or line beginning and &gt; )<BR>
#<BR>
&nbsp;&nbsp;&nbsp;foreach ( keys %input ) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$input{$_} =~ s/&lt;([^&gt;]|\n)*&gt;//g;
<BR>
&nbsp;&nbsp;&nbsp;}<BR>
}<BR>
<BR>
sub print_header {<BR>
<BR>
&nbsp;&nbsp;&nbsp;print &lt;&lt;END;<BR>
&lt;HTML&gt;<BR>
&lt;HEAD&gt;&lt;TITLE&gt;Richard's More Impressive Chat Room&lt;/TITLE&gt;&lt;/HEAD&gt;
<BR>
&lt;BODY&gt;<BR>
&lt;CENTER&gt;<BR>
&lt;P&gt;&lt;FONT SIZE=+2&gt;&lt;B&gt;<BR>
My Second Chat Room<BR>
&lt;/B&gt;&lt;/FONT&gt;<BR>
&lt;BR&gt;&lt;BR&gt;<BR>
&lt;FONT SIZE=-1&gt;&lt;B&gt;&lt;I&gt;<BR>
This chat room has more features than its predecessor.&nbsp;&nbsp;Enjoy!
<BR>
&lt;/I&gt;&lt;/B&gt;&lt;/FONT&gt;<BR>
&lt;/CENTER&gt;<BR>
&lt;BR&gt;&lt;HR&gt;<BR>
END<BR>
<BR>
}<BR>
<BR>
sub print_form {<BR>
<BR>
#<BR>
# if this is the first access of a chatting session, create the
ID#<BR>
# and put a message into the handle string<BR>
#<BR>
&nbsp;&nbsp;&nbsp;if (!(defined($input{'id'}))) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$input{'handle'} = 'Put your
handle here!';<BR>
&nbsp;&nbsp;&nbsp;}<BR>
<BR>
#<BR>
# if the ChatMaster has left ChatMaster mode, strip the special
string<BR>
# from the ID# in both $input{'id'} and in the @userdata array
<BR>
#<BR>
&nbsp;&nbsp;&nbsp;if ( (!($cmmode)) &amp;&amp; ($input{'id'} =~
/ChatMaster/) ) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;substr($input{'id'},$[,11)
= '';<BR>
&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;foreach ( @userdata ) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;substr($_,$[,11) = '' if $_
=~ /ChatMaster/;<BR>
&nbsp;&nbsp;&nbsp;}<BR>
<BR>
&nbsp;&nbsp;&nbsp;print &quot;&lt;FORM METHOD=POST ACTION=$baseurl/$progname&gt;\n&quot;;
<BR>
<BR>
&nbsp;&nbsp;&nbsp;foreach ( @userdata ) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@field = split(/\t/);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;undef($check);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($field[0] ne $input{'id'}
) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$check =
' chECKED' if &amp;blocked($field[0]);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;&lt;INPUT
TYPE=checkbox NAME=block VALUE=$field[0]$check&gt;&quot;;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;
&lt;FONT SIZE=-1&gt;&lt;I&gt;block $field[1]&lt;/I&gt;&lt;/FONT&gt;&lt;BR&gt;\n&quot;;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;}<BR>
<BR>
&nbsp;&nbsp;&nbsp;print &lt;&lt;END;<BR>
&lt;PRE&gt;<BR>
&lt;B&gt;Name&nbsp;&nbsp;&nbsp;&nbsp; :&lt;/B&gt; &lt;INPUT TYPE=&quot;text&quot;
SIZE=40 NAME=&quot;handle&quot; MAXLENGTH=&quot;40&quot; <BR>
VALUE=&quot;$input{'handle'}&quot;&gt;<BR>
&lt;INPUT TYPE=&quot;hidden&quot; NAME=&quot;id&quot; VALUE=&quot;$input{'id'}&quot;&gt;
<BR>
&lt;A NAME=&quot;Comments&quot;&gt;&lt;B&gt;Comments :&lt;/B&gt;
<BR>
&lt;TEXTAREA NAME=&quot;comments&quot; ROWS=3 COLS=50&gt;&lt;/TEXTAREA&gt;&lt;/A&gt;
<BR>
To: &lt;SELECT NAME=&quot;post_to&quot;&gt;<BR>
&lt;OPTION VALUE=&quot;everyone&quot;&gt;Everyone&lt;/OPTION&gt;
<BR>
END<BR>
&nbsp;&nbsp;&nbsp;foreach ( @userdata ) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@field = split(/\t/);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( $field[0] ne $input{'id'}
) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;&lt;OPTION
VALUE=\&quot;$field[0]\&quot;&gt;$field[1]&lt;/OPTION&gt;\n&quot;;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;print &quot;&lt;/SELECT&gt;\n&quot;;<BR>
&nbsp;&nbsp;&nbsp;print &lt;&lt;END;<BR>
&lt;/PRE&gt;<BR>
&lt;BR&gt;<BR>
&lt;INPUT TYPE=&quot;submit&quot; VALUE=&quot;Submit Comments
or Update Room&quot;&gt;<BR>
&lt;INPUT TYPE=&quot;reset&quot; VALUE=&quot;Clear Form&quot;&gt;
<BR>
&lt;/FORM&gt;<BR>
END<BR>
&nbsp;&nbsp;&nbsp;print &quot;Current time: $time\n&quot;;<BR>
}<BR>
<BR>
sub print_stack {<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;$printed_lines = 0;<BR>
<BR>
#<BR>
# referring to the newposts/ directory, ls -1t *_posts will force
a 1 column<BR>
# output, organized most recent file to least recent, of all .post
entries<BR>
#<BR>
&nbsp;&nbsp;&nbsp;chop(@posts = `ls -1t newposts/*_post`);<BR>
&nbsp;&nbsp;&nbsp;foreach ( @posts ) {<BR>
<BR>
#<BR>
# Reclaim ID# from filename and test to see if that ID# is blocked
by either<BR>
# the current user or the chatmaster.&nbsp;&nbsp;Also, skip posting
if it's not<BR>
# &quot;addressed&quot; to this user.<BR>
#<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@field = split(/\_/);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( $field[2] ne 'everyone'
) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;next if
$field[2] ne $input{'id'}; # skip if not for my ID#<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;next if &amp;blocked($field[0]);
# if blocked, skip this posting<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;next if &amp;cm_blocked($field[0]);
# if blocked, skip this posting<BR>
<BR>
#<BR>
# prints valid entries, clears old ones from the stack<BR>
#<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( $printed_lines &lt; $maxlines
) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;open(POST,$_);
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while (
$this_line = &lt;POST&gt; ) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print
$this_line;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$printed_lines++;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;close(POST);
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;system(&quot;rm
$_&quot;); # clear old entries from the stack<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;}<BR>
}<BR>
<BR>
sub update_stack {<BR>
<BR>
&nbsp;&nbsp;&nbsp;$post_name = $input{'id'} . '_to_' . $input{'post_to'}
. '_post';<BR>
&nbsp;&nbsp;&nbsp;$id_snippet = substr($input{'id'},-2,2);<BR>
&nbsp;&nbsp;&nbsp;open(POST,&quot;&gt; newposts/$post_name&quot;);
<BR>
<BR>
# allows users to control line breaks without access to HTML by
simply<BR>
# hitting ENTER in the comments textarea<BR>
&nbsp;&nbsp;&nbsp;$input{'comments'} =~ s/\cM\n/&lt;BR&gt;\n/g;
<BR>
<BR>
&nbsp;&nbsp;&nbsp;print POST &lt;&lt;END;<BR>
&lt;HR&gt;<BR>
&lt;!-- $input{'handle'} --&gt;<BR>
&lt;!-- ID#: $input{'id'} --&gt;<BR>
&lt;TABLE WIDTH=100%&gt;&lt;TR&gt;&lt;TD ALIGN=LEFT VALIGN=CENTER&gt;
<BR>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -