simple scripting question, CGI log

Reply

Join Date: Sep 2008
Posts: 8
Reputation: pjrey is an unknown quantity at this point 
Solved Threads: 0
pjrey pjrey is offline Offline
Newbie Poster

simple scripting question, CGI log

 
0
  #1
Jun 17th, 2009
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:
  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
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 8
Reputation: pjrey is an unknown quantity at this point 
Solved Threads: 0
pjrey pjrey is offline Offline
Newbie Poster

Re: simple scripting question, CGI log

 
0
  #2
Jun 19th, 2009
anyone??
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: simple scripting question, CGI log

 
0
  #3
Jun 19th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 38
Reputation: msvinaykumar is an unknown quantity at this point 
Solved Threads: 2
msvinaykumar msvinaykumar is offline Offline
Light Poster

Re: simple scripting question, CGI log

 
0
  #4
Jun 20th, 2009
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 ?
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 49
Reputation: onaclov2000 is an unknown quantity at this point 
Solved Threads: 5
onaclov2000 onaclov2000 is offline Offline
Light Poster

Re: simple scripting question, CGI log

 
0
  #5
Jun 26th, 2009
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Perl Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC