#!/usr/bin/perl # for grepping around in irc logs # by 31d1 djbidi@gmail.com # v0.1 use strict; use URI::Escape; # user variables # path to logfile (may need to be in a non-hidden folder) my $file = "/home/username/irclogs/channel/#channel.log"; # a nice greeting my $greeting = "Welcome to the #channel webgrepper:"; # max results so people dont waste your computer searching for . my $max_results = 20000; # input my $qs=$ENV{'QUERY_STRING'}; $qs = uri_unescape("$qs"); # crappy attempt to avoid hax; $qs =~ s/\///g; # to allow form input $qs =~ s/^=//; my $i = 1; my $j = 1; # print range of lines if ($qs =~ /^(\d+),(\d+)$/) { print "Content-type: text/plain\n\n"; my $begin = $1; my $end = $2; if (($end - $begin) > $max_results ) { print "max is $max_results lines at a time, ok?"; die; } open F, "< $file"; while () { if (($i >= $begin) && ($i <= $end)) { print "$_"; $i++; } else { $i++; } } close F; die; # print lines matching query } elsif ($qs) { print "Content-type: text/plain\n\n"; open F, "< $file"; while () { if ($_ =~ /$qs/i) { my $k = ($i + 20); print "[$i]\n$_\n"; $i++; $j++; if ($j > $max_results) { print "\n...\n\nsearch truncated at $max_results results, refine your search maybe?"; die; } } else { $i++; } } close F; die; # help } else { print "Content-type: text/html\n\n"; print <
$greeting

	enter <regex> to return matching lines
	examples:
		poop  (lines that contain "poop")
		ham\$  (lines that end with "ham")

	results each come with a [<line number>]
	enter <begin line>,<end line> to see specific lines
	examples:
		3556,3570 (from line 3556 to 3570)
		1,1       (first line only) 
	
	tips:
		* try nick[^>] to omit most lines that's just them talking
		* to pass a # symbol, add %23 to the url where you want it 
		* that = sign in the url doesn't need to be there
EOF }