Subversion Repositories cms

Compare Revisions

Ignore whitespace Rev 5 → Rev 6

/trunk/bin/squid_redirector
9,9 → 9,15
# Prima bozza di redirector per squid
#
 
# utilizzo "C" per maggiore velocità
my $C_LANG=1;
 
# set gid
$)=getgrnam('cms');
$) == getgrnam('cms') or die "Don't change group 'cms'";
$(=getgrnam('cms');
#print STDERR `id`;
#exit;
$( == getgrnam('cms') or die "Don't change group 'cms'";
 
$0="squid_redirector $$";
$|=1;
27,6 → 33,7
 
sub My_exit{
my($sig) = @_;
$Shared || $Shared->shunlock();
print LOG "$$ Close with signal $sig\n";
close LOG;
exit 1;
36,30 → 43,104
 
# apro la share
use IPC::Shareable;
my $glue = 'CMS0';
my $glue = 'CMSa';
my %options = (
create => 1,
exclusive => 0,
mode => 0660,
destroy => 0,
size => 50000,
);
my %SHARED;
tie %SHARED, 'IPC::Shareable', $glue, { %options } or die "client: tie failed\n";
$Shared = tie %SHARED, 'IPC::Shareable', $glue, { %options } or die "client: tie failed\n";
 
# log attuale contenuto
foreach $key (keys %SHARED){
print LOG "$$ host $key\n";
use Data::Dumper;
print STDERR Dumper(\%SHARED);
 
# test con caricamento elenco multo lungo
if(0){
$Shared->shlock();
print STDERR "Start long write ...";
for(my $I=1; $I <= 10000; $I++){
$SHARED{"Key_$I"}=1;
}
$Shared->shunlock();
print STDERR "end\n";
}
 
# log attuale contenuto
#foreach $key (keys %SHARED){
# print LOG "$$ host $key\n";
#}
 
# $SHARED{'test.leader.it'}=1;
# $SHARED{'www.google.com'}=1;
 
if($C_LANG){
use Inline C => <<'END_C';
 
// cerca le stringhe contenute in LIST (separate da " " o "\n") in URL
int TestStr( char* LIST, char* URL){
char* WORD;
char EOL;
while(*LIST){
// tolgo blank iniziali
while(*LIST == ' ' || *LIST == '\n'){
LIST++;
}
WORD=LIST;
//cerco la fine della parola
while(*LIST && *LIST != ' ' && *LIST != '\n'){
LIST++;
}
if(*LIST){
EOL=*LIST;
*LIST='\0';
// verifico se la parola è contenuta nella URL
if(strstr(URL, WORD) == NULL){
return 1;
}
*LIST=EOL;
LIST++;
}else{
// verifico se la parola è contenuta nella URL
if(strstr(URL, WORD) == NULL){
return 1;
}
}
}
}
END_C
}
 
############################################################### LOOP
while (defined ($_=<STDIN>)){
WORD:
while (defined ($_=<STDIN>)){
chomp;
my($url, $ip_fqdn, $ident, $method) = split;
$url = 'none' if !$url;
my $host = lc $url;
 
# test presenza elenco parole in $host
if($C_LANG){
if(TestStr($SHARED{WordList}, $host)){
$url = "301:http://www.leader.it/'";
print STDOUT "$url\n";
next WORD;
}
}else{
my $W = $SHARED{Words};
@Words = @$W;
foreach my $word (@$Words){
###print STDERR "test $word in $host: ".index($host, $word)."\n";
if(index($host, $word) >= 0){
$url = "301:http://www.leader.it/'";
print STDOUT "$url\n";
next WORD;
}
}
}
$host =~ s|.*//([\w\.]+)/.*|$1|;
if($host =~ m|^http://-/(.*)$|){
print LOG "$$ redir command $1\n";