Gossamer Forum
Home : Products : DBMan : Customization :

Dirty Word MOD

Quote Reply
Dirty Word MOD
Hi All.

I've been working with the Dirty Word MOD.
And I've got it working very good.

However, I would like to add it to another script I have.

I tried adding the entire section to the cgi file I was working with. (I just cut it from both the 'cfg' file, and the 'cgi' file.)

I then changed the [$col] to [$msg].
msg is the field name for my other scripts form field.

Well, needless to say... it wasn't that easy... and it doesn't work.

Could anybody explain what all I need to do to add this cool feature to another cgi script?

As Always, Thanks!
JbA

------------------
John B. Abela
Owner, 4CM
www.4cm.com/
support@4cm.com

Presently working on:
www.humbee.com/buzz/

Quote Reply
Re: Dirty Word MOD In reply to
Hi Eliot!

Thanks for the help!

I did as you stated.
I got two errors, fixed one.
I posted the other one at:
http://www.gossamer-threads.com/...um8/HTML/001033.html because I've tried all I could think of!

Again, Thanks! Eliot!

JbA
Quote Reply
Re: Dirty Word MOD In reply to
I have implemented a similar Block Bad Words Mod in my add.cgi script in LINKS. Here is what I have done:

1) Add the following array in the configuration section of your script:

Code:
# Dirty Word Censor
@dirty_words = ('badword1','badword2','badword3');

2) Then I added the following codes in your script where you have users add information (add these codes above the "success" call):

Code:
$bwords = $in{'Field'};
foreach $bwords (@dirty_words) {
if ($in{'Field'} =~ /$bwords/i) {
&site_html_add_failure (qq| <font face="Verdana" size="2">Your entry has been rejected due to use of the following bad words: <b><font color="ff0000">$bwords</font></b>.</font><br>|);
return;
}
}

Replace Field with your field name or variable.

If you have multiple fields, copy the codes above for each field. Sorry that I do not have to clean up the codes and put the fields into [col] or a hash.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
* Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
* Search Forums!
* Say NO to Duplicate Threads. :)
----------------------








Quote Reply
Re: Dirty Word MOD In reply to
Hi Eliot.

I know this is going to be way off-topic... but I've tried what you suggested, and even spent little while trying to get it working.

I just don't seem to understand this good enough yet! (guess I need to get me a good cgi book!)

Well, here is the complete script that I'm trying to add the 'dirty word' mod into.

Code:
#!/usr/local/bin/perl
#
# Oneliner
#
# Copyright (c) Stefan Pettersson 2000
#
# You may not redistribute this script, but it's free to use.
#
# Version History:
# v0.9 2000-01-26 - Initial public beta version.
#
# For further information see:
# http://www.stefan-pettersson.nu/scripts/
#
##############################################################################

# Filename to write the messages to. This file is then included by a HTML page.
$filename = '/export/www/humbee/humbee/oneliner/oneliners_incl.html';

# How many message should be displayed at once
$number_of_rows = 8;

# How the date and time will be displayed
$dateformat = '[monthnameshort] [day], [hour0]:[min0] [ampm]';

# Names of weekdays
@daynames = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday);

# Names of months
@monthnames = qw(January February March April May June July August September October November December);

# Background color of the entered messages, specified in hex as in HTML
$bgcolor = '#000000';

# Font tag to use for date
$font_date = '<font face="tahoma, verdana, arial, geneva" size=1 color="#4FE59D">';

# Font tag to use for the actual message
$font_msg = '<font face="tahoma, verdana, arial, geneva" size=1 color="#EFEF80">';

# Font tag to use for the nickname
$font_who = '<font face="tahoma, verdana, arial, geneva" size=1 color="#EF80EF">';

# You do not need to modify anything below this line.

##############################################################################

&ReadParse;

if ($in{'who'} ne "" && $in{'msg'} ne "") {

if (-e $filename) {
open(FILE, $filename) &#0124; &#0124; die $!;
@lines = <FILE>;
close(FILE);
}

open(F, ">$filename") &#0124; &#0124; die &PrintErrorPage("Can't write to file '$filename'\n");
print F '<tr bgcolor="' . $bgcolor . '">';
print F '<td align=left nowrap>' . $font_date . &GetDateString . '</font></td>';
print F '<td align=left nowrap>'.$font_msg . $in{'msg'} . '</font></td>';
print F '<td align=right nowrap>'.$font_who . $in{'who'} . '</font></td>';
print F "</tr>\n";

for ($i = 0; $i < $number_of_rows - 1; $i++) {
print F $lines[$i];
}

close(F);
}

print "Location: $ENV{'HTTP_REFERER'}\n\n";

exit;

##############################################################################

sub GetDateString {
my $formatstring = $dateformat;
my %datestr;
my ($sec, $min, $hour, $day, $month, $year, $weekday) = localtime($^T);

$datestr{'sec'} = $sec;
$datestr{'sec0'} = sprintf("%02d", $sec);

$datestr{'min'} = $min;
$datestr{'min0'} = sprintf("%02d", $min);

$datestr{'hour24'} = $hour;
$datestr{'hour240'} = sprintf("%02d", $hour);

$datestr{'ampm'} = ($hour > 12) ? 'pm' : 'am';

$hour -= 12 if $hour > 12;
$hour = 12 if ($hour == 0);

$datestr{'hour'} = $hour;
$datestr{'hour0'} = sprintf("%02d", $hour);

$datestr{'day'} = $day;
$datestr{'day0'} = sprintf("%02d", $day);

$datestr{'dayname'} = $daynames[$weekday];
$datestr{'daynameshort'} = substr($daynames[$weekday], 0, 3);

$datestr{'month'} = $month + 1;
$datestr{'month0'} = sprintf("%02d", $month + 1);
$datestr{'monthname'} = $monthnames[$month];
$datestr{'monthnameshort'} = substr($monthnames[$month], 0, 3);

$datestr{'year'} = 1900 + $year;
$datestr{'shortyear'} = sprintf("%02d", $year % 100);

while ($formatstring =~ /\[([^\]]+)\]/) {
my $tag = $1;
$formatstring =~ s/\[$tag\]/$datestr{$tag}/;
}

return $formatstring;
}

##############################################################################

sub ReadParse {
my $buf, @pairs;

if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buf, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buf);
}

foreach (@pairs) {
local($key, $val) = split(/=/);

$key =~ tr/+/ /;
$val =~ tr/+/ /;

$key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$val =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

# Strip dangerous characters, removes HTML and SSI for example
$val =~ s/<([^>]|\n)*>//g; # Strip SSI and HTML

$in{$key} = $val;
}
}

##############################################################################

sub PrintErrorPage {
print "Content-type: text/html\n\n";

print "<html><head><title>Script error!</title></head><body>";
print "<b>Script error!</b><p>\n";
print $_[0];
print "</body></html>";
}

And here is the .shtml file:

Code:
<table cellpadding=1 cellspacing=0 border=0 bgcolor="#303030"><tr><td>
<table cellpadding=2 cellspacing=0 border=0 bgcolor="#000000">
<form action="../oneliner.cgi" method=POST>
<tr bgcolor="#1a1a1a">
<td colspan=3 align=center>
<font face="tahoma, verdana, arial, geneva" size=1>
<b>Oneliners</b> - Created By: <a href="http://www.stefan-pettersson.nu/scripts/" target="_blank">Stefan</a>!
</font>
</td>
</tr>
<!--#include virtual="oneliners_incl.html"-->
<tr bgcolor="#1a1a1a">
<td colspan=3 valign="middle">
<font face="tahoma, verdana, arial, geneva" size=1>
msg: <input type="text" name="msg" maxlength=120 size=30 style="font-family:tahoma,verdana;font-size:10px">
who: <input type="text" name="who" maxlength=10 size=7 style="font-family:tahoma,verdana;font-size:10px">
<input type="submit" value="leave msg" style="font-family:tahoma,verdana;font-size:10px">
</font>
</td>
</tr>
</form>
</table>
</td></tr></table>

If you wouldn't mind spending a few seconds pointing out what I need to do.. it would definatly be a leason in cgi for me! (and a big yeehaa! too!)

Later.
JbA
Quote Reply
Re: Dirty Word MOD In reply to
Yea...This is WAY OFF Topic and you should really post Threads like this in the Perl/CGI Forum. And it is not a cgi book you need, BUT a Perl book. Perl is the foundation of CGI scripts. Learn Perl first!

From the codes you posted, you have not even tried putting the codes I posted. Okay, here we go again..are you paying attention??????????


1) Put the following codes in the top section of your script where all the configuration variables are located:

Code:
# Dirty Word Censor
@dirty_words = ('badword1','badword2','badword3');

2) Create a sub-routine called sub submit_success. It should look like the following:

Code:
sub submit_success
#-------------------------------------------
# Submits data

open(DB, ">$filename") or die &PrintErrorPage("Can't write to file '$filename'\n");
print DB '<tr bgcolor="' . $bgcolor . '">';
print DB '<td align=left nowrap>' . $font_date . &GetDateString . '</font></td>';
print DB '<td align=left nowrap>'.$font_msg . $in{'msg'} . '</font></td>';
print DB '<td align=right nowrap>'.$font_who . $in{'who'} . '</font></td>';
print DB "</tr>\n";
for ($i = 0; $i < $number_of_rows - 1; $i++) {
print DB $lines[$i];
}

close(DB);
}
&thank_you;
exit;
}

3) Create a new sub-routine called sub submit_error and it should look like the following:

Code:
sub submit_error {
#--------------------------------------------
# Error Message

print "Content-type: text/html\n\n";
print qq|
<html>
<head>
<title>Submission Error</title>
</head>
<body bgcolor="ffffff">
<center><h1>
Submission Error
</h1></center>
<br>
You have posted inappropriate language in one of the fields. Use your back button in your browser to fill out the form again.
</body>
</html>
|;
}

4) Then change the following codes:

Code:
if ($in{'who'} ne "" && $in{'msg'} ne "") {

if (-e $filename) {
open(FILE, $filename) | | die $!;
@lines = <FILE>;
close(FILE);
}

open(F, ">$filename") | | die &PrintErrorPage("Can't write to file '$filename'\n");
print F '<tr bgcolor="' . $bgcolor . '">';
print F '<td align=left nowrap>' . $font_date . &GetDateString . '</font></td>';
print F '<td align=left nowrap>'.$font_msg . $in{'msg'} . '</font></td>';
print F '<td align=right nowrap>'.$font_who . $in{'who'} . '</font></td>';
print F "</tr>\n";

for ($i = 0; $i < $number_of_rows - 1; $i++) {
print F $lines[$i];
}

close(F);
}

print "Location: $ENV{'HTTP_REFERER'}\n\n";

exit;

to the FOLLOWING codes:

Code:
$bwords = $in{'who'};
$bwords2 = $in{'msg'};
foreach $bwords (@dirty_words) {
if ($in{'who'} =~ / $bwords/i) {
&submit_error;
return;
}
}
foreach $bwords2 (@dirty_words) {
if ($in{'msg'} =~ / $bwords2/i) {
&submit_error;
return;
}
}
if ($in{'who'} ne "" && $in{'msg'} ne "") {

if (-e $filename) {
open(FILE, $filename) | | die $!;
@lines = <FILE>;
close(FILE);
}
&submit_success;
}

5) Create another sub-routine, called sub thank_you:

Code:
sub thank_you {
#--------------------------------------------
# Error Message

print "Content-type: text/html\n\n";
print qq|
<html>
<head>
<title>Thank you!</title>
</head>
<body bgcolor="ffffff">
<center><h1>
Thank you!
</h1></center>
<br>
Thank you for submitting your message.
</body>
</html>
|;
}

Hope this works and helps.

If not, please post further messages in the Perl/CGI Forum (and reference this Thread in your new Thread).

Regards,






------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
* Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
* Search Forums!
* Say NO to Duplicate Threads. :)
----------------------