Basic perl program for squid’s url_rewriter_program. You can add db connection for adapting blacklist or whitelist (text based or md5 based based,or etc.). Disable text logging!. My squid was configured with Tproxy (not chaining client ip address).
Add this line to squid conf.
use Digest::MD5 qw(md5 md5_hex md5_base64);
open(my $log, “>”, “/usr/local/squid/var/logs/url.log.txt”) || die(“Cannot open output file: $!”);
select $log; $| = 1;
select STDOUT; $| = 1;
my @parts = split;
my $url = $parts;
my $requestingip = $parts;
my $requestmethod = $parts;
my $now = localtime;
my($scheme, $authority, $path, $query, $fragment) = $url =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|;
my $md5_authority = md5_hex( $authority );
print $log “$now: URL:$url AUTHORITY:$authority MD5_AUTHORITY:$md5_authority REQIP:$requestingip REQMETHOD:$requestmethod\n”;
## can be redirected to any page but its good to tell the browser with 302 or you can just rewrite the url with squid’s error page etc