Jump to content

Matt's WWWBoard Version 2.0 ALPHA 2.1


Sluggo
 Share

Recommended Posts

Hi allI'm playing with a modified version of Matt's WWWBoard script [Version 2.0 ALPHA 2.1] that includes an e-mail notification to the Administrator and my question is this:What would it take to have the poster's Host info and Agent string (such as the example below) included with the Admin e-mails ?

Host: (owl-187c7e4k.xxx.xxxxxxx.xxx)Browser: (Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0))

Note: The above Host info has been edited for this post.I know that the info is available, but I don't know how/where to call for it and include it in the Admin e-mails.Thanks I hope :)

Link to comment
Share on other sites

  • 2 weeks later...

Umm, I don't know perl. Why hasn't anyone aswered this thred who does? In php, to et the user's IP, you would use a variable called $_SERVER['REMOTE_ADDR']; and I think REMOTE_ADDR is something your server tells PHP so it shouldn't be very different in Perl. To get the userage string in php, use the variable $_SERVER['HTTP_USER_AGENT']; again it shouldn't be very differnt in Perl.

Link to comment
Share on other sites

Hi nilsonOK, using your lead I was able to get the Browser info in the Admin e-mail using this: print MAIL "Browser Info: $browser [$ENV{'HTTP_USER_AGENT'}]\n";The IP Number was already in there with this: print MAIL "Posted From: $host $ENV{'REMOTE_HOST'} [$ENV{'REMOTE_ADDR'}]\n";However, I'm striking out with the Host info, any thoughts ??Thanks

Link to comment
Share on other sites

Dave PCPitstop

Usually, reverse DNS lookups are not turned on for a server because they are very expensive to do. That means REMOTE_ADDR and REMOTE_HOST usually have the same value, the IP address. Since you only need the host for this particular situation, it's definitely not worth turning on reverse lookups. There is probably some Perl module you can get to do the lookups, or just look them up yourself at a place like GeekTools when you get the email.

Link to comment
Share on other sites

Hi Dave & all

Usually, reverse DNS lookups are not turned on for a server because they are very expensive to do. That means REMOTE_ADDR and REMOTE_HOST usually have the same value, the IP address.
OK, that most likely explains why I'm having trouble getting it to print.
Since you only need the host for this particular situation, it's definitely not worth turning on reverse lookups. There is probably some Perl module you can get to do the lookups, or just look them up yourself at a place like http://www.geektools.com/whois.php  when you get the email.
There currently is a log file that logs info for each post (up to an adjustable number of posts) created by a usrlog.sub plugin which does report the Host info that I would like to be included in the Admin e-mails so that the log file can be eliminated and all info for that particular post kept/reported in the Admin e-mails. All of the other info contained in the log file (Name, time, post ID number, IP info) is redundant because that's all in the Admin e-mails now.This is the usrlog.sub file
######################################################################### File: usrlog.sub                                                                 ## Type: Plugin For wwwboard.pl To Log User Information    ########################################################################## ********************* DO NOT REMOVE THIS BLOCK ********************* ########################################################################## ********************** Start Of Configuration ********************** ## Location of log file$log_file    = "log.txt";# Max entries of logs in log file using 7 lines per post# Example: 700 entries equals 100 posts$max_entries = 700;# Number of spaces to indent new entries (All logs will be indented# equally. Use 0 for no indent on logs.$indent      = 5;# *********************** End Of Configuration *********************** #use Socket;ini_log(); # Initiate Logging...sub ini_log {    # Get User Information    $browser = $ENV{'HTTP_USER_AGENT'};    $ip      = $ENV{'REMOTE_ADDR'};    @digits  = split(/\./, $ip);    $address = pack("C4", @digits);    $host    = gethostbyaddr($address, AF_INET); # Needed by socket        # Get log file    @logs = ();    if (open (LOGS, $log_file)) {             @logs = <LOGS>;             chomp(@logs);        close (LOGS);                if ($logs[0] ne "Test Forum Log") {           $logs[0] = "Test Forum Log";        }    } else {        open (MKLOG, ">$log_file") || die $!;             flock(MKLOG,2);             print MKLOG "Test Forum Log";        close (MKLOG);                $logs[0] = "Test Forum Log";    }        # Trim Log File    if ($#logs+1 => $max_entries) {       for ($trim = $max_entries; $trim <= $#logs; $trim++) {           undef $logs[$trim];       }    }        $indent = " " x $indent; # Format indentation        open (WRITE_LOG, ">$log_file") || die $!;         flock(WRITE_LOG,2);         foreach $log (@logs) {            if ($log eq "Test Forum Log") {               print WRITE_LOG "Test Forum Log\n\n";               print WRITE_LOG "$indent Message-id: ($num)\n";               print WRITE_LOG "$indent Time: ($date)\n";               print WRITE_LOG "$indent Subject: ($subject)\n";               print WRITE_LOG "$indent Name: ($name\n";               print WRITE_LOG "$indent IP Number: ($ip)\n";               print WRITE_LOG "$indent Host: ($host)\n";               print WRITE_LOG "$indent Browser: ($browser)\n";            } else {                print WRITE_LOG "$log\n";            }         }    close (WRITE_LOG);}

This is called for by these lines in the main .pl file

################################ Main Page Subroutinerequire 'usrlog.sub'; # Plugin to log user infosub main_page {  $msgfile = "$basedir/$mesgfile";  open  MAIN, "+>>$msgfile" or die "Cannot open $msgfile: $!";   flock MAIN, 2;        # wait for exclusive lock   seek  MAIN, 0, 0;     # rewind to beginning   @main = <MAIN>;       # get current content   seek  MAIN, 0, 0;     # rewind again   truncate $msgfile, 0; # empty the file         require 'usrlog.sub'; # Plugin to log user info

However that is below the Admin e-mail info section in the main .pl file, so would that be why I haven't been able to incorporate the host info sections into the main .pl file ?Is there any hope for me ?Thanks

Link to comment
Share on other sites

Dave PCPitstop

I had forgotten how easy Perl makes this. The only part you need is this: $ip = $ENV{'REMOTE_ADDR'}; @digits = split(/\./, $ip); $address = pack("C4", @digits); $host = gethostbyaddr($address, AF_INET); # Needed by socket That will take REMOTE_ADDR and give you $host. Just cut and paste that where you need it.

Link to comment
Share on other sites

Hi Dave & allWell I guess this is going to be more complicated than I thought it would be, if in fact it can be done at all for the Admin e-mail.When I read Dave's last post I thought that he had hit upon the solution for me, however after inserting the 4 lines that he mentioned:--------------------------------------------------------------------------------The only part you need is this:$ip = $ENV{'REMOTE_ADDR'};@digits = split(/\./, $ip);$address = pack("C4", @digits);$host = gethostbyaddr($address, AF_INET); # Needed by socketThat will take REMOTE_ADDR and give you $host. Just cut and paste that where you need it.--------------------------------------------------------------------------------in many different locations in the perl script for the NEWFILE section (which is where the Admin e-mail info is reported/taken from), and using this line: print MAIL "Host Info: {'$host'}\n";in the MAIL section, it still won't report anything at all in the Admin e-mail other than this:Host Info: {''}So........any other thoughts ??Thanks

Link to comment
Share on other sites

Hi all againLet me revise my intentions of concentrating on having it reported in the Admin e-mail to just having it printed/displayed in the posted message because, as with other variables, if they're able to be displayed in a message they can be used in the Admin e-mail so maybe that should be the better course of action ?In other words, once the coding is correct to allow it to be displayed somewhere, I can then use the $host in this line: print MAIL "Host Info: {'$host'}\n";as I can do with any others, No ??Just a thought.

Link to comment
Share on other sites

Work on it like an object, a module, a function, a subroutine. Yep, that's typically the best way.Your problem is strikingly similar to browser component variables and server variables in web pages (with Jscript/JavaScript or VBscript). :w00t: But Perl uses the environment variables ($env). Isn't there a way to view all of the variables? Once you figure that out, you can easily piecemeal what you want and need. $host is a variaable you made right? I would declare it near the start as a global variable verses a local or in-line variable (if these terms even make sense??).All of my work I had posted being hosted on free accounts is gone - brinkster, geocities, and haven't even checked netfirms. So I can't reference anything at the moment. I have the old work from my courses around here somewhere on a CD or in some dusty folder on another HDD.

Link to comment
Share on other sites

Hi pc-tecky & allSorry to have let a few days go by, but I had to put this on hold for a while.

Perl uses the environment variables ($env). Isn't there a way to view all of the variables? Once you figure that out, you can easily piecemeal what you want and need.$host is a variable you made right? I would declare it near the start as a global variable verses a local or in-line variable (if these terms even make sense??).
I have determined what environment variables ($env) that my server lists and I am able to have every one of them printed in the Admin e-mail by inserting the variables in the:
# Get Variablessub get_variables {

However the Hostname ($host) that I refer to which is the variable name that the log script uses:

Host: (owl-187c7e4k.xxx.xxxxxxx.xxx)

is not one of them but will be rendered/printed to the log using these lines in the log script to use the socket.pm file I believe:

use Socket;ini_log(); # Initiate Logging...sub ini_log {    # Get User Information    $browser = $ENV{'HTTP_USER_AGENT'};    $ip      = $ENV{'REMOTE_ADDR'};    @digits  = split(/\./, $ip);    $address = pack("C4", @digits);    $host    = gethostbyaddr($address, AF_INET); # Needed by socket

Note the lines that Dave PCPitstop referred to

I had forgotten how easy Perl makes this. The only part you need is this:$ip = $ENV{'REMOTE_ADDR'};@digits = split(/\./, $ip);$address = pack("C4", @digits);$host = gethostbyaddr($address, AF_INET); # Needed by socketThat will take REMOTE_ADDR and give you $host. Just cut and paste that where you need it.

However that uses the socket file and I have not been able to insert the call for the socket file in the

# Get Variablessub get_variables {

section and have it print out anywhere, either in a posted message or in the Admin e-mail, it's just ignored.So.....I guess that the question now is: Is there any way to use/call the socket file and the 4 lines that Dave PCPitstop referred to in the

# Get Variablessub get_variables {

section so that it will at least print the info in a posted message or the Admin e-mail ?Thanks

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...