R
Robin
what I'm trying to do is get this bbs.cgi to work better. So when someone
types in spaces as their name it will work to reply to them and on the
"Reply to..." screen will actually stop showing the %A or whatever it is,
what is that btw? Any help would be great.
#!/usr/bin/perl
#bbs v.1.1.4
#Copyright Robin - (e-mail address removed)
require ('lib.cgi');
&data_cgivars;
$" = "";
$, = "";
&begin;
if ($PARAMS{'action'} eq "reply" && $PARAMS{'name'} ne "" && $PARAMS{'name'}
ne "post")
{ &reply; exit; }
if ($PARAMS{'action'} eq "replied")
{ &reply; &post (1); }
&post;
sub begin
{
mkdir ("BBSFILES/", 0755) if (! -e "BBSFILES/");
}
sub post
{
my ($action) = @_;
if ($action)
{
&mainoutput ("Your reply has been posted");
exit;
}
if ($FORM{'submit'})
{
if ($FORM{'name'} && $FORM{'email'} && $FORM{'post'} && $FORM{'name1'} !~
/\./ && $FORM{'name'} !~ /<.*>/ && $FORM{'email'} !~ /<.*>/ && $FORM{'post'}
!~ /<.*>/ && $FORM{'name'} !~ /^\s*$/ && $FORM{'email'} !~ /^\s*$/ &&
$FORM{'post'} !~ /^\s*$/)
{
if (-e "BBSFILES/$FORM{'name'}.post")
{
&mainoutput ("Name already in use.");
exit;
}
open (DBASE, ">>dbase.txt");
print DBASE ("$FORM{'name'}\n");
close (DBASE);
open (POSTFILE, ">>BBSFILES/$FORM{'name'}.post");
print POSTFILE ("Name - $FORM{'name'}<br>Email - $FORM{'email'}<br>Post -
<br>$FORM{'post'}<br>[ <a
href=\"$0?action=reply&name=$FORM{'name'}\">Reply</a> ]<br><br>\n");
close (POSTFILE);
&mainoutput ("Your post has been posted");
}
else
{
&mainoutput ("Error! You did not fill out all of the fields or you used
HTML tags which are invalid for this system or you used a period on your
name field which is also invalid. Please try again.");
}
}
elsif (! $FORM{'submit'})
{
&mainoutput ("Welcome to the BBS");
}
}
sub reply
{
if ($FORM{'submit1'})
{
if ($FORM{'name1'} && $FORM{'email1'} && $FORM{'post1'} && $FORM{'name1'}
!~ /\./ && $FORM{'name1'} !~ /<.*>/ && $FORM{'email1'} !~ /<.*>/ &&
$FORM{'post1'} !~ /<.*>/ && $FORM{'name1'} !~ /^\s*$/ && $FORM{'email1'} !~
/^\s*$/ && $FORM{'post1'} !~ /^\s*$/)
{
if (-e "BBSFILES/$FORM{'name1'}.$PARAMS{'name'}")
{
print ("Content-type:text/html\n\n");
print ("Name already in use.");
exit;
}
open (POSTFILE, ">>BBSFILES/$FORM{'name1'}.$PARAMS{'name'}");
print POSTFILE ("<BLOCKQUOTE>Name - $FORM{'name1'}<br>Email -
$FORM{'email1'}<br>Post - <br>$FORM{'post1'}<br></BLOCKQUOTE>\n");
close (POSTFILE);
}
else
{
print ("Content-type:text/html\n\n");
print ("Error! You did not fill out all of the fields or you used HTML
tags which are invalid for this system or you used a period on your name
field which is also invalid. Please try again.");
exit;
}
}
else
{
&replyoutput ("Reply to $PARAMS{'name'}");
exit;
}
sub replyoutput
{
my ($replyoutput) = @_;
print ("Content-type:text/html\n\n");
print <<END;
<html><body>
<b>BBS</b> - $replyoutput
<form name="form2" method="post"
action="$0?action=replied&name=$PARAMS{'name'}">
<p>Name:
<br>
<input name="name1" type="text" id="name">
</p>
<p>Email:
<br>
<input name="email1" type="text" id="email">
</p>
<p>Your Post:</p>
<p>
<textarea name="post1" cols="30" rows="6" id="post"></textarea>
</p>
<input name="submit1" type="submit" id="submit" value="Submit">
<input type="reset" name="Submit2" value="Reset">
</form>
<hr>
</body></html>
END
}
}
sub mainoutput
{
my ($output) = @_;
print ("Content-type:text/html\n\n");
print <<END;
<html><body>
<b>BBS</b> - $output
<form name="form1" method="post" action="bbs.cgi">
<p>Name:
<br>
<input name="name" type="text" id="name">
</p>
<p>Email:
<br>
<input name="email" type="text" id="email">
</p>
<p>Your Post:</p>
<p>
<textarea name="post" cols="30" rows="6" id="post"></textarea>
</p>
<p>
<input name="submit" type="submit" id="submit" value="Submit">
<input type="reset" name="Submit2" value="Reset">
</p>
</form>
<p><hr></p>
<b>Current Posts - Most recent are on bottom:</b><br><br>
END
opendir (BBSFILES, "BBSFILES/");
@files = readdir (BBSFILES);
closedir (BBSFILES);
chomp (@files);
foreach $tmp (@files)
{
if ($tmp ne "." && $tmp ne "..")
{
open (FILE, "BBSFILES/$tmp") || die "can't open file $!.";
@file = <FILE>;
close (FILE);
@file2 = split (/\./, $tmp);
#print @file2;
if ($file2[1] eq "post")
{
opendir (BBSFILES, "BBSFILES/");
@files1 = readdir (BBSFILES);
closedir (BBSFILES);
chomp (@files1);
print (@file);
print ("<b>Replies:</b><BR><br>");
foreach $tmp2 (@files1)
{
open (FILE, "BBSFILES/$tmp2") || die "can't open file $!.";
@secfile = <FILE>;
close (FILE);
@secfilesecs = split (/\./, $tmp2);
#print @secfilesecs;
if ($secfilesecs[1] eq $file2[0])
{
print (@secfile);
}
else
{
next;
}
}
}
else
{
next;
}
}
}
print ("</body></html>");
}
types in spaces as their name it will work to reply to them and on the
"Reply to..." screen will actually stop showing the %A or whatever it is,
what is that btw? Any help would be great.
#!/usr/bin/perl
#bbs v.1.1.4
#Copyright Robin - (e-mail address removed)
require ('lib.cgi');
&data_cgivars;
$" = "";
$, = "";
&begin;
if ($PARAMS{'action'} eq "reply" && $PARAMS{'name'} ne "" && $PARAMS{'name'}
ne "post")
{ &reply; exit; }
if ($PARAMS{'action'} eq "replied")
{ &reply; &post (1); }
&post;
sub begin
{
mkdir ("BBSFILES/", 0755) if (! -e "BBSFILES/");
}
sub post
{
my ($action) = @_;
if ($action)
{
&mainoutput ("Your reply has been posted");
exit;
}
if ($FORM{'submit'})
{
if ($FORM{'name'} && $FORM{'email'} && $FORM{'post'} && $FORM{'name1'} !~
/\./ && $FORM{'name'} !~ /<.*>/ && $FORM{'email'} !~ /<.*>/ && $FORM{'post'}
!~ /<.*>/ && $FORM{'name'} !~ /^\s*$/ && $FORM{'email'} !~ /^\s*$/ &&
$FORM{'post'} !~ /^\s*$/)
{
if (-e "BBSFILES/$FORM{'name'}.post")
{
&mainoutput ("Name already in use.");
exit;
}
open (DBASE, ">>dbase.txt");
print DBASE ("$FORM{'name'}\n");
close (DBASE);
open (POSTFILE, ">>BBSFILES/$FORM{'name'}.post");
print POSTFILE ("Name - $FORM{'name'}<br>Email - $FORM{'email'}<br>Post -
<br>$FORM{'post'}<br>[ <a
href=\"$0?action=reply&name=$FORM{'name'}\">Reply</a> ]<br><br>\n");
close (POSTFILE);
&mainoutput ("Your post has been posted");
}
else
{
&mainoutput ("Error! You did not fill out all of the fields or you used
HTML tags which are invalid for this system or you used a period on your
name field which is also invalid. Please try again.");
}
}
elsif (! $FORM{'submit'})
{
&mainoutput ("Welcome to the BBS");
}
}
sub reply
{
if ($FORM{'submit1'})
{
if ($FORM{'name1'} && $FORM{'email1'} && $FORM{'post1'} && $FORM{'name1'}
!~ /\./ && $FORM{'name1'} !~ /<.*>/ && $FORM{'email1'} !~ /<.*>/ &&
$FORM{'post1'} !~ /<.*>/ && $FORM{'name1'} !~ /^\s*$/ && $FORM{'email1'} !~
/^\s*$/ && $FORM{'post1'} !~ /^\s*$/)
{
if (-e "BBSFILES/$FORM{'name1'}.$PARAMS{'name'}")
{
print ("Content-type:text/html\n\n");
print ("Name already in use.");
exit;
}
open (POSTFILE, ">>BBSFILES/$FORM{'name1'}.$PARAMS{'name'}");
print POSTFILE ("<BLOCKQUOTE>Name - $FORM{'name1'}<br>Email -
$FORM{'email1'}<br>Post - <br>$FORM{'post1'}<br></BLOCKQUOTE>\n");
close (POSTFILE);
}
else
{
print ("Content-type:text/html\n\n");
print ("Error! You did not fill out all of the fields or you used HTML
tags which are invalid for this system or you used a period on your name
field which is also invalid. Please try again.");
exit;
}
}
else
{
&replyoutput ("Reply to $PARAMS{'name'}");
exit;
}
sub replyoutput
{
my ($replyoutput) = @_;
print ("Content-type:text/html\n\n");
print <<END;
<html><body>
<b>BBS</b> - $replyoutput
<form name="form2" method="post"
action="$0?action=replied&name=$PARAMS{'name'}">
<p>Name:
<br>
<input name="name1" type="text" id="name">
</p>
<p>Email:
<br>
<input name="email1" type="text" id="email">
</p>
<p>Your Post:</p>
<p>
<textarea name="post1" cols="30" rows="6" id="post"></textarea>
</p>
<input name="submit1" type="submit" id="submit" value="Submit">
<input type="reset" name="Submit2" value="Reset">
</form>
<hr>
</body></html>
END
}
}
sub mainoutput
{
my ($output) = @_;
print ("Content-type:text/html\n\n");
print <<END;
<html><body>
<b>BBS</b> - $output
<form name="form1" method="post" action="bbs.cgi">
<p>Name:
<br>
<input name="name" type="text" id="name">
</p>
<p>Email:
<br>
<input name="email" type="text" id="email">
</p>
<p>Your Post:</p>
<p>
<textarea name="post" cols="30" rows="6" id="post"></textarea>
</p>
<p>
<input name="submit" type="submit" id="submit" value="Submit">
<input type="reset" name="Submit2" value="Reset">
</p>
</form>
<p><hr></p>
<b>Current Posts - Most recent are on bottom:</b><br><br>
END
opendir (BBSFILES, "BBSFILES/");
@files = readdir (BBSFILES);
closedir (BBSFILES);
chomp (@files);
foreach $tmp (@files)
{
if ($tmp ne "." && $tmp ne "..")
{
open (FILE, "BBSFILES/$tmp") || die "can't open file $!.";
@file = <FILE>;
close (FILE);
@file2 = split (/\./, $tmp);
#print @file2;
if ($file2[1] eq "post")
{
opendir (BBSFILES, "BBSFILES/");
@files1 = readdir (BBSFILES);
closedir (BBSFILES);
chomp (@files1);
print (@file);
print ("<b>Replies:</b><BR><br>");
foreach $tmp2 (@files1)
{
open (FILE, "BBSFILES/$tmp2") || die "can't open file $!.";
@secfile = <FILE>;
close (FILE);
@secfilesecs = split (/\./, $tmp2);
#print @secfilesecs;
if ($secfilesecs[1] eq $file2[0])
{
print (@secfile);
}
else
{
next;
}
}
}
else
{
next;
}
}
}
print ("</body></html>");
}