Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unusual Guest Book 1

Status
Not open for further replies.

usakjw

Programmer
Sep 8, 2005
47
US
I want to have a guest book on my site. However I want to be able to have an unknown to the public page, and possibly pass word protected, where I can delete entries from the guest book if I want to. I realize that this will take at least two seperate scripts.

I am a VB programmer. However I know very little on CGI and understand even less. If somebody can point me in the right direction I would greatly appreciate it

Thank you

KJW
 
Hi

Yes, some checkboxes could be used too, but I'm abit command line oriented, so I like typing. (-:

While sending mail is the most common way of abuse, usually there are some limitations, which could mean quite a lot. For example sending mails is allowed only through their Perl modules. I think you must check their documentation or ask the support. And the same for the authentication problem too. If HTTP authentication is not allowed, then we will think to other solution.

Feherke.
 
feherke

I got the Password authentication to work. My hosting company had their own method for creating the .htpasswd file.

I can use my own scripts to send E-mail or what ever. Although if I wish I can also use their scripts. Their scripts are what I want.

I have two scripts that use send MAIL, that I got from other sources, and they both work. So I know I'm doing something else wrong.

Thank You

KJW
 
print MAIL "Name: $guestbook('fname') $guestbook('lname')\n";
print MAIL "Age: $guestbook('age') Precint: $guestbook('precint')\n";
print MAIL "Comments: $guestbook('comments')\n\n";

I do receive the e-mail. However the above information is not in it.

I did have the send MAIL in with the following code. However I got the same result as above, an empty e-mail, I also received one e-mail for each entry in the guest book at the time.

open FIL,"<$book";
while (@mes=split /\t/,<FIL>)
{
print "<p><b>Name:</b> <i>$mes[2]</i> ( ".(localtime $mes[0])." ) :
<br><b>Age:</b> <i>$mes[4]</i> <b>Precint:</b> <i>$mes[5]</i>
<br><b>Comments:</b> <i>$mes[6]</i>
<br></p>";
}

close FIL;

KJW
 
Hi

What is that [tt][highlight #EEFFFF]$guestbook('fname')[/highlight][/tt] ? Because in [tt]perl[/tt] could be one of this :
[ul]
[li][tt][highlight #EEFFFF]$guestbook[red]{[/red]'fname'[red]}[/red][/highlight][/tt] - hash element reference[/li]
[li][tt][highlight #EEFFFF][red]&[/red]guestbook('fname')[/highlight][/tt] - function call[/li]
[/ul]

Feherke.
 
guestbook is the name of the form
fname is the input for first name
lname is the input for last name
age is the age of the signer
precint is the precint they live in
comments is their comments

I realize that I'm propbery going about this wrong but it is the only way I know how

KJW
 
Hi

No, I asked about it's type. Because you prefaced it with a dollar sign and put it's argument/index between parentheses. I showed the two possible correct usages, but from that messed syntax I can not guess the actual type of that guestbook thing.

Anyway, I think it must be a hash, so try to change the parentheses to braces : [tt][highlight #DDFFFF]$guestbook[red]{[/red]'fname'[red]}[/red][/highlight][/tt], and so on for the rest.

Feherke.
 
Your are right I thougt I had the {}. I did not realize I had the () instead. I maid the change and still get the same empty email.

KJW
 
Hi

Is any documentation of that mailer script available on the net ? I think there should be some steps before that [tt][highlight #DDFFFF]print MAIL ...[/highlight][/tt], which are missing in your implementation.

Feherke.
 
This the entire code that I want to use to sent the email:
I use it on two other forms and it works perfectly.
I got this code out of a book called CGI Programming 101.
Their is a web site Note that I do get the last two lines of the print MAIL.
Which are:
The above information is a new entry in your guest book
If you deem this entry unappropriate, you may delete it here:
How ever the above information the first lin talks about is what I do not recieve.

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$guestbook{$name} = $value;
}

#Format and send the E-mail
#Where is E-mail Program
$mailprog = '/usr/lib/sendmail';

#Who gets E-mail
$recipient = 'kevin@lyndatyler.com';

#Who is the mail from
$from = $mes{email};
$reply = $mes{email};

#Open mail program or dienice
open (MAIL, "|$mailprog -t") or dienice("Can't find Mail Program!!\n");

print MAIL "From: $from\n";
print MAIL "Reply-To: $reply\n";

print MAIL "To: $recipient\n";

print MAIL "Subject: New Guest Book Entry\n";

print MAIL "Name: $guestbook{'fname'} $guestbook{'lname'}\n";
print MAIL "Age: $guestbook{'age'} Precint: $guestbook{'precint'}\n";
print MAIL "Comments: $guestbook{'comments'}\n\n";

print MAIL "The above information is a new entry in your guest book\n";
print MAIL "If you deem this entry unappropriate, you may delete it here:
close (MAIL);

KJW
 
Hi

That script does not check the REQUEST_METHOD, simply assumes that is POST. But is not POST, is GET. ( Due to the used SSI inclusion must be GET, because the CGI script does not receive the POST data this way. If you want, I rewrite it without SSI. ) Beside this, neighter the QUERY_STRING is available, only QUERY_STRING_UNESCAPED, which is abit altered, so your mail script will not deal with it successfully.

As I can see, the problem could be solved by taking the values from the %mes hash : [tt][highlight #DDFFFF]$[red]mes[/red]{'fname'}[/highlight][/tt] and so on.

Feherke.
 
I guess if you are willing to rewrite it, that will probperply be the easiest thing to do. Because I have no idea what the QUERY_STRING or the QUERY_STRING_UNESCAPED are. Nor do I have any idea how to identify the method as GET or POST.

I guess learning CGI is going to be harder than I expected.

KJW
 
Hi

Is just abit of HTTP and CGI.
[ul]
[li][tt][blue]GET[/blue][/tt] - form data sent with this method is available in the [tt]QUERY_STRING[/tt] variable[/li]
[li][tt][blue]POST[/blue][/tt] - form data sent with this method is available in the standard input[/li]
[li][tt][blue]REQUEST_METHOD[/blue][/tt] - name of the method used to send from data, could be [tt]GET[/tt] or [tt]POST[/tt][/li]
[li][tt][blue]QUERY_STRING[/blue][/tt] - form data sent with [GET] method, URL encoded[/li]
[li][tt][blue]QUERY_STRING_UNESCAPED[/blue][/tt] - the same as [tt]QUERY_STRING[/tt] but available only for SSI, kind of URL decoded[/li]
[/ul]
Before running a CGI script, the webserver set some environment variables to pass information to the script. You already saw them listed by env.pl, discussed previously. ( If you call it alone, not included with SSI, the list is readable. )

Ok, I think will be better to rewrite it. At that time I did not thinked to compatibility with the most of CGI examples available in script archives.

Feherke.
 
Hi

I rewrote your guestbook. It is much robust and flexible, but without SSI you will have more work to beautify it. Although I tried to apply your design.

I changed the data file structure too. This version will not remove physically the rejected comments, just mark them. This make possible to reaccept an accidentally rejected comment. Later comments coming from the same IP as a rejected one, will not be listed until explicit accept.

Regarding your implementation of the mail sender script I found finally the bug. The mail was composed entirely as the input of the [tt]sendmail[/tt] program. This way you must signal the end of the header with an empty line. See the two new line characters at the end of the last header line, the one with the Subject, in the original script.

( Note : file will be removed after awhile. )

Feherke.
 
feherke,

You are awesome. Thank you much. I know get the e-mal the way I want it! I only wish I had another way to thank you other than saying it here and giving you two votes.

Thank You again

KJW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top