📄 ch19.htm
字号:
<BR>
#<BR>
# ID# checks out okay, so add on PID info and store in %input
<BR>
#<BR>
$input{'id'} = $temp_id . ".$$";<BR>
<BR>
}<BR>
<BR>
#<BR>
# determine whether or not the current user is ChatMaster<BR>
#<BR>
if ( ($input{'handle'} eq $cmpswd ) && (!($input{'id'}
=~ /ChatMaster/)) ) {<BR>
$cmmode = 1;<BR>
} elsif ( ($input{'handle'} eq 'ChatMaster' ) && <BR>
($input{'id'} =~ /ChatMaster/) ) {<BR>
$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>
$input{'handle'} = 'ChatMaster';<BR>
$id = $input{'id'};<BR>
if (!($id =~ /ChatMaster/)) {<BR>
substr($input{'id'},$[,0)
= 'ChatMaster.';<BR>
}<BR>
foreach ( @userdata ) {<BR>
@field = split(/\t/);<BR>
if (!($field[0] =~ /ChatMaster/))
{<BR>
if ( $field[0]
eq $id ) {<BR>
substr($_,$[,0)
= 'ChatMaster.';<BR>
}<BR>
}<BR>
}<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' ) && <BR>
(!($input{'id'} =~ /ChatMaster/)) ) {<BR>
&chatmaster_error;<BR>
}<BR>
<BR>
#<BR>
# the following line traps forms being submitted from invalid
locations<BR>
#<BR>
&print_error if ( (!($refer =~ /$baseurl/)) && defined($input{'handle'})
);<BR>
<BR>
#<BR>
# If HTML is disallowed, go to the remove_html section... except
for<BR>
# the ChatMaster<BR>
#<BR>
&remove_html if ( (!($html)) && (!($cmmode)) );<BR>
<BR>
&print_header;<BR>
&print_form;<BR>
&update_stack if $input{'comments'} ne '';<BR>
&print_stack;<BR>
&print_footer;<BR>
<BR>
&update_datafile;<BR>
<BR>
exit 0;<BR>
<BR>
sub print_error {<BR>
print <<END;<BR>
<HTML><HEAD><TITLE>Invalid Submission</TITLE></HEAD>
<BR>
<BODY><BR>
<P><BR>
The URL of the page which submitted the form which has this CGI
program<BR>
as its action was not valid. Please go to<BR>
<A HREF=$baseurl/$progname>$baseurl/$progname</A>
to <BR>
legally access this CGI program.<BR>
</BODY></HTML><BR>
END<BR>
exit 1;<BR>
}<BR>
<BR>
sub chatmaster_error {<BR>
print <<END;<BR>
<HTML><HEAD><TITLE>Invalid use of ChatMaster</TITLE></HEAD>
<BR>
<BODY><BR>
<P><BR>
An attempt was made to access ChatMaster mode illegally.<BR>
</BODY></HTML><BR>
END<BR>
exit 1;<BR>
}<BR>
<BR>
sub id_conflict_error {<BR>
print <<END;<BR>
<HTML><HEAD><TITLE>Multiple Login Sessions not
allowed</TITLE></HEAD><BR>
<BODY><BR>
<P><BR>
You may only possess one login session at a time.<BR>
<P><BR>
It is (just a little) possible that someone else is using your
exact data<BR>
port information right now. If this is the case, you'll
have to wait for<BR>
them to finish their session in this chat room.<BR>
</BODY></HTML><BR>
END<BR>
exit 1;<BR>
}<BR>
<BR>
sub remove_html {<BR>
<BR>
#<BR>
# removes all characters between < and >, inclusive<BR>
# ( or, between < and EOL or line beginning and > )<BR>
#<BR>
foreach ( keys %input ) {<BR>
$input{$_} =~ s/<([^>]|\n)*>//g;
<BR>
}<BR>
}<BR>
<BR>
sub print_header {<BR>
<BR>
print <<END;<BR>
<HTML><BR>
<HEAD><TITLE>Richard's More Impressive Chat Room</TITLE></HEAD>
<BR>
<BODY><BR>
<CENTER><BR>
<P><FONT SIZE=+2><B><BR>
My Second Chat Room<BR>
</B></FONT><BR>
<BR><BR><BR>
<FONT SIZE=-1><B><I><BR>
This chat room has more features than its predecessor. Enjoy!
<BR>
</I></B></FONT><BR>
</CENTER><BR>
<BR><HR><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>
if (!(defined($input{'id'}))) {<BR>
$input{'handle'} = 'Put your
handle here!';<BR>
}<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>
if ( (!($cmmode)) && ($input{'id'} =~
/ChatMaster/) ) {<BR>
substr($input{'id'},$[,11)
= '';<BR>
}<BR>
foreach ( @userdata ) {<BR>
substr($_,$[,11) = '' if $_
=~ /ChatMaster/;<BR>
}<BR>
<BR>
print "<FORM METHOD=POST ACTION=$baseurl/$progname>\n";
<BR>
<BR>
foreach ( @userdata ) {<BR>
@field = split(/\t/);<BR>
undef($check);<BR>
if ($field[0] ne $input{'id'}
) {<BR>
$check =
' chECKED' if &blocked($field[0]);<BR>
print "<INPUT
TYPE=checkbox NAME=block VALUE=$field[0]$check>";<BR>
print "
<FONT SIZE=-1><I>block $field[1]</I></FONT><BR>\n";
<BR>
}<BR>
}<BR>
<BR>
print <<END;<BR>
<PRE><BR>
<B>Name :</B> <INPUT TYPE="text"
SIZE=40 NAME="handle" MAXLENGTH="40" <BR>
VALUE="$input{'handle'}"><BR>
<INPUT TYPE="hidden" NAME="id" VALUE="$input{'id'}">
<BR>
<A NAME="Comments"><B>Comments :</B>
<BR>
<TEXTAREA NAME="comments" ROWS=3 COLS=50></TEXTAREA></A>
<BR>
To: <SELECT NAME="post_to"><BR>
<OPTION VALUE="everyone">Everyone</OPTION>
<BR>
END<BR>
foreach ( @userdata ) {<BR>
@field = split(/\t/);<BR>
if ( $field[0] ne $input{'id'}
) {<BR>
print "<OPTION
VALUE=\"$field[0]\">$field[1]</OPTION>\n";
<BR>
}<BR>
}<BR>
print "</SELECT>\n";<BR>
print <<END;<BR>
</PRE><BR>
<BR><BR>
<INPUT TYPE="submit" VALUE="Submit Comments
or Update Room"><BR>
<INPUT TYPE="reset" VALUE="Clear Form">
<BR>
</FORM><BR>
END<BR>
print "Current time: $time\n";<BR>
}<BR>
<BR>
sub print_stack {<BR>
<BR>
$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>
chop(@posts = `ls -1t newposts/*_post`);<BR>
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. Also, skip posting
if it's not<BR>
# "addressed" to this user.<BR>
#<BR>
@field = split(/\_/);<BR>
if ( $field[2] ne 'everyone'
) {<BR>
next if
$field[2] ne $input{'id'}; # skip if not for my ID#<BR>
}<BR>
next if &blocked($field[0]);
# if blocked, skip this posting<BR>
next if &cm_blocked($field[0]);
# if blocked, skip this posting<BR>
<BR>
#<BR>
# prints valid entries, clears old ones from the stack<BR>
#<BR>
if ( $printed_lines < $maxlines
) {<BR>
open(POST,$_);
<BR>
while (
$this_line = <POST> ) {<BR>
print
$this_line;<BR>
$printed_lines++;
<BR>
}<BR>
close(POST);
<BR>
} else {<BR>
system("rm
$_"); # clear old entries from the stack<BR>
}<BR>
}<BR>
}<BR>
<BR>
sub update_stack {<BR>
<BR>
$post_name = $input{'id'} . '_to_' . $input{'post_to'}
. '_post';<BR>
$id_snippet = substr($input{'id'},-2,2);<BR>
open(POST,"> newposts/$post_name");
<BR>
<BR>
# allows users to control line breaks without access to HTML by
simply<BR>
# hitting ENTER in the comments textarea<BR>
$input{'comments'} =~ s/\cM\n/<BR>\n/g;
<BR>
<BR>
print POST <<END;<BR>
<HR><BR>
<!-- $input{'handle'} --><BR>
<!-- ID#: $input{'id'} --><BR>
<TABLE WIDTH=100%><TR><TD ALIGN=LEFT VALIGN=CENTER>
<BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -