943,900 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 990
  • Perl RSS
Jun 17th, 2009
0

simple scripting question, CGI log

Expand Post »
hello, i use a simple log script on my site.. very basic..
i would like to modify it, and am having issues..
here is what i would like...
i would like to be able to have it filter out certian HOST names.. but not exact.. say for instance, i dont want it logging yahoo slurp.. the host name changes, but always ends in yahoo.com
so, i would like to filter out djfdk.388338.djdk.yahoo.com
and i would like to be able to add more than one, a list of filtered hosts, not IP's, that will not be logged..
so, i would like to change the $me var, to host, but not exact host, just domain (like i stated earlier) and then to create a list, by coma.
thanks a bunch
pj

here is the script:
perl Syntax (Toggle Plain Text)
  1. #!/usr/bin/perl
  2.  
  3. $me = "38.117.78.220";
  4. $log = "/home/to/my/log.html";
  5.  
  6. #############################
  7.  
  8. if (!$ENV{'REMOTE_HOST'}) {my @subnet_numbers = split (/\./, $ENV{'REMOTE_ADDR'});
  9. $ENV{'REMOTE_HOST'} = gethostbyaddr(pack("C4", @subnet_numbers), 2) || $ENV{'REMOTE_ADDR'};
  10. }
  11.  
  12. $ippjrey = $ENV{'REMOTE_ADDR'};
  13. $hostpjrey = $ENV{'REMOTE_HOST'};
  14. $privatepjrey = $ENV{'HTTP_X_FORWARDED_FOR'};
  15.  
  16. $getdate = `date +"%A %B %d, %Y, %r"`;
  17. chop ($getdate);
  18.  
  19.  
  20. if ($ENV{'REMOTE_ADDR'} eq $me) {
  21. open (LOG, "$log");
  22. @lines = <LOG>;
  23. close (LOG);
  24. print "Content-type: text/html\n\n";
  25. open (LOG, ">$log");
  26. print LOG @lines;
  27. close (LOG);
  28.  
  29.  
  30.  
  31. }
  32.  
  33. else {
  34.  
  35. open (LOG, "$log");
  36. @lines = <LOG>;
  37. close (LOG);
  38. print "Content-type: text/html\n\n";
  39. open (LOG, ">$log");
  40. print LOG " [ <font size=-2 face=Verdana, Arial><B>Time:</B> $getdate ] </font>- \n";
  41. print LOG " [ <font size=-2 face=Verdana, Arial><B>With:</B> $ENV{'HTTP_USER_AGENT'} ]<BR></font>\n";
  42. print LOG " [ <font size=-2 face=Verdana, Arial color=red><B>Host: $ippjrey/$hostpjrey || [ $privatepjrey ] </B>]</font>\n";
  43. print LOG " [ <font size=-2 face=Verdana><B>From:</B> <font color=blue><A HREF=$ENV{'HTTP_REFERER'}>$ENV{'HTTP_REFERER'}</font></A></font>]<BR>\n";
  44. print LOG " [ <font size=-2 face=Verdana><B>Pages:</B> $here $ENV{'DOCUMENT_URI'} ]<BR><BR></font>\n\n";
  45. print LOG @lines;
  46.  
  47. close (LOG);
  48.  
  49.  
  50.  
  51. }
  52. exit;
Last edited by Tekmaven; Jun 18th, 2009 at 5:22 pm. Reason: Code Tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
pjrey is offline Offline
50 posts
since Sep 2008
Jun 19th, 2009
0

Re: simple scripting question, CGI log

anyone??
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
pjrey is offline Offline
50 posts
since Sep 2008
Jun 19th, 2009
0

Re: simple scripting question, CGI log

Sorry, I have read your question three times and I can't understand what you want to do.
Last edited by KevinADC; Jun 19th, 2009 at 2:48 am.
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
Jun 20th, 2009
0

Re: simple scripting question, CGI log

Hey dude
Let me repharse ur question, Sorry if i understood wrong

If log is having
aaa.ccc.ddd.eee.Yahoo.com
dfsdfsdsdf.gmail.com

Then u like to have
only yahoo.com
gmail.com

is this u are looking for ?
Reputation Points: 10
Solved Threads: 6
Light Poster
msvinaykumar is offline Offline
48 posts
since May 2006
Jun 26th, 2009
0

Re: simple scripting question, CGI log

So I'm assuming you are looking for things that "end with" such and such,

that being the case a simple regular expression might do?

if ($line =~ m/yahoo.com/i)
{
if ($line =! m/^(www.|http:\/\/).yahoo.com/i)
{
print $line . "\n";
}

That line will basically take and do a search on anything containing
yahoo.com (case insensitive) then if it doesn't start with, www.yahoo.com, or http://yahoo.com
print the line out.

I'm not sure if that helps, hope it does
Reputation Points: 11
Solved Threads: 5
Junior Poster in Training
onaclov2000 is offline Offline
57 posts
since Jun 2008
Mar 19th, 2010
0
Re: simple scripting question, CGI log
thanks, ill give it a try (major delay, i know.. never got the notification that you posted back)

thanks!
pj
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
pjrey is offline Offline
50 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: update NEWS portion on website via EMAIL?
Next Thread in Perl Forum Timeline: Perl Script to Pull out rows containing longer names





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC