home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.science.tver.ru
/
ftp.science.tver.ru.tar
/
ftp.science.tver.ru
/
pub
/
filter_nnrpd.pl
< prev
next >
Wrap
Perl Script
|
2006-11-06
|
7KB
|
174 lines
#! /usr/bin/perl
#
# ⁿ╘╧╘ ╞╔╠╪╘╥ ╘╥┼┬╒┼╘ ╒╙╘┴╬╧╫╠┼╬╬╧╟╧ ═╧─╒╠╤ CRC32 ─╠╤ Perl.
# ⌡ ╦╧╟╧ FreeBSD ╔▌╔╘┼ ╫ ╨╧╥╘┴╚. Σ╠╤ linux ╬┼ ┌╬┴└, ╔▌╔╘┼.
use String::CRC32;
# Σ┴╠┼┼ ╦╒╙╧╦ ╔┌ ─╔╙╘╥╔┬╒╘╔╫┴ inn. ∩╙╘┴╫╪╘┼ ╦┴╦ ┼╙╘╪.
# $Id: filter_nnrpd.pl,v 1.2 2002/12/12 05:01:42 vinocur Exp $
#
# Sample perl filtering code for nnrpd hook.
#
#
# This file is loaded when nnrpd starts up. If it defines a sub named
# `filter_post', then that function will be called during processing of a
# posting. It has access to the headers of the article via the associative
# array `%hdr'. If it returns a null string then the article is accepted
# for posting. A non-null string rejects it, and the value returned is used
# in the rejection message.
#
#
# Do any initialization steps.
#
my %config = (checkincludedtext => 0,
includedcutoff => 40,
includedratio => 0.6,
quotere => '^[>:]',
antiquotere => '^[<]', # so as not to reject dict(1) output
);
#
# Sample filter
#
sub filter_post {
my $rval = "" ; # assume we'll accept.
# µ╔╠╪╘╥ ─╠╤ ╞╔─╧, ╨╧─╙╘┴╬╧╫╦┴ X_COMMENT-TO, ┌┴═┼╬┴ msgid ╬┴ ╞╔─╧█╬┘╩.
# H┴╨╔╙┴╬ ┬╠┴╟╧─┴╥╤ ß╠┼╦╙┴╬─╥╒ τ╧╘╠╔┬╒, 2:5080/1003;
# ≈╠┴─╒ ≡╠╒╓╬╔╦╧╫╒ 2:5021/19 ╔ ≤┼╥╟┼└ ≥┼╫╘╧╫╒ 2:5021/49.
# ≤╨┴╙╔┬╧ ╔═ ╧╟╥╧═╬╧┼ ╧╘ ╫╙┼╚ ╨╧╠╪┌╧╫┴╘┼╠┼╩ ╟┼╩╘┴.
#
# ≥┼┌╒╠╪╘┴╘ ╔╚ ╥┴┬╧╘┘ ╧┬╧┬▌╔╠ Yuri Kosivtsov, 2:5021/29,
# ╥┼┴╠╔┌╧╫┴╬ ╬┴ news://fido.tver.ru ╔ http://fido.tver.ru
my $grephistory = '/usr/local/news/bin/grephistory';
my $sm = '/usr/local/news/bin/sm';
# Σ┴╠┼┼ ╧╨╤╘╪ ╦┴╦┴╤-╘╧ ╞╔╟╬╤ ╔┌ ─╔╙╘╥╔┬╒╘╔╫┴
### Uncomment this next block to reject articles that have 'make money'
### in their subject, or which have a "Re: " subject, but no References:
### header, or which have an invalid From.
## if ($hdr{"Subject"} =~ /make.*money/i) {
## $rval = "Spam is not acceptable here..." ;
## } elsif ($hdr{'Subject'} =~ /^Re: /o and $hdr{'References'} eq "") {
## $rval = "Followup without References:";
## } elsif ($hdr{'From'} =~ /^\w*$/o or
## $hdr{'From'} !~ /^(.+?)\@([-\w\d]+\.)*([-\w\d]+)\.([-\w\d]{2,})$/o) {
## $rval = "From: is invalid, must be user\@[host.]domain.tld";
## }
### The next block rejects articles with too much quoted text, if the
### config hash directs it to.
if ($config{checkincludedtext}) {
my ($lines, $quoted, $antiquoted) = analyze($body);
if ($lines > $config{includedcutoff}
&& $quoted - $antiquoted > $lines * $config{includedratio}) {
$rval = "Article contains too much quoted text";
}
}
# ╦╒╙╧╦ ≡╠╒╓╬╔╦╧╫┴ ╔ ≥┼╫╘╧╫┴
# ≡╧╨┘╘╦┴ ╙╟┼╬┼╥╔╥╧╫┴╘╪ ╞╔─╧█╬┘╩ MSGID.
# ≡╥╧┬╠┼═┴ ╫ ╙╠┼─╒└▌┼═. ≡╥╔ ╟┼╩╘╧╫┴╬╔╔ ╬╪└╙╧╫ ╟┼╬┼╥╔╥╒┼╘╙╤ ═╙╟╔─
# "<┼═┼╩╠> ╬╧═┼╥". ⁿ╘╧ ╨╠╧╚╧, ╘.╦. ╨╥╔ ─╫╧╩╬╧═ (╘╥╧╩╬╧═ ╔ ╘.╨., ╫┼─╪ ╘╫╧╩
# ╟┼╩╘ ╬┼ ╧─╔╬ ╙ ╫ ╙┼╘╔ :-)) ╟┼╩╘╧╫┴╬╔╔ ═╧╟╒╘ ┬┘╘╪ ╙┬╧╔. δ╥╧═┼ ╘╧╟╧,
# ╬┼╦╧╘╧╥┘┼ ▐╔╘┴╠╦╔ ┬┼╥╒╘ ╔┌ MSGID ┴─╥┼╙ ╒┌╠┴ ╔ █╔┌┼└╘ ╧╘ ╬┼╞╔─╧█╬╧╟╧
# ╫╔─┴ ╔─┼╬╘╔╞╔╦┴╘╧╥┴. ≡╧▄╘╧═╒, ╘┼ ╨╧╠╪┌╧╫┴╘┼╠╔ ╟┼╩╘┴, ╦╧╘╧╥┘┼ ╔═┼└╘
# ╞╔─╧█╬┘┼ ┴─╥┼╙┴ (╨╧╔╬╘┘ ╔ ╬╧─┘, ╨╧ ╦┴╦╔═-╠╔┬╧ ╨╥╔▐╔╬┴═ ╨╧╠╪┌╒└▌╔═╔╙╤
# ╟┼╩╘╧═), ╨╥┼─▀╤╫╠╤└╘ ┼═┼╩╠ ╫╔─┴ Vasya_Pupkin@pX.fY.nZ.z2.fido.tver.ru.
# z2.fido.tver.ru - ▄╘╧ ═╧╩ ─╧═┼╬, ╬┼ ┌┴┬╒─╪╘┼ ┌┴═┼╬╔╘╪ ╬┴ ╙╫╧╩ :-)
# ⌠┴╦╧╩ ┼═┼╩╠ ┌┴═┼╬╤┼╘╙╤ ╬┴ MSGID ╫╔─┴ "2:Z/Y.X ╬╧═┼╥".
# σ╙╠╔ ┴─╥┼╙ ╬┼ ╙╧╧╘╫┼╘╙╘╫╒┼╘ ═┴╙╦┼, ╘╧ ╟┼╬┼╥╔╥╒┼╘╙╤ MSGID
# ╫╔─┴ "2:5021/29.100 ╬╧═┼╥", ╟─┼ 2:5021/29.100 - ┴─╥┼╙, ╬┴ ╦╧╘╧╥╧═
# ╒╙╘┴╬╧╫╠┼╬ ╟┼╩╘
# ╦╒╙╧╦ ≥┼╫╘╧╫┴
$ftn_suff = "z2.fido.tver.ru";
$tmp = $hdr{"Message-ID"};
$crc = crc32($tmp);
$modify_headers = 1;
$id = lc ($hdr{"From"}); # Lower case
if ($id =~ /^.+\@p(\d+)\.f(\d+)\.n(\d+)\.z2\.fido\.tver\.ru/) {
$p = $1;
$f = $2;
$n = $3;
$hdr{"Message-ID"} = sprintf("<%u\@p$p.f$f.n$n.$ftn_suff>", $crc);
$hdr{"X-FTN-MSGID"} = sprintf("2:$n/$f.$p %x",$crc);
} elsif ( $id =~ /^.+\@f(\d+)\.n(\d+)\.z2\.fido\.tver\.ru/) {
$f = $1;
$n = $2;
$hdr{"Message-ID"} = sprintf("<%u\@f$f.n$n.$ftn_suff>", $crc);
$hdr{"X-FTN-MSGID"} = sprintf("2:$n/$f %x",$crc);
} else {
$hdr{"Message-ID"} = sprintf("<%u\@p100.f29.n5021.$ftn_suff>",$crc);
$hdr{"X-FTN-MSGID"} = sprintf("2:5021/29.100 %x",$crc);
}
# δ╒╙╧╦ ß.τ╧╘╠╔┬┴. Σ┼╠┴┼╘ X-COMMENT-To. ∩╙╬╧╫┴╬ ╬┴ ╒╘╔╠╔╘┼
# grephistory ╔┌ inn
# σ╙╠╔ ╫ ╙╧╧┬▌┼╬╔╔ ╒╓┼ ┼╙╘╪ X-COMMENT-To, ╘╧ ╬╔▐┼╟╧ ╬┼ ╨╥╧╔╙╚╧─╔╘.
# σ╙╠╔ X-COMMENT-To ╬┼╘, ╘╧ ╨╥╧╔┌╫╧─╔╘╙╤ ╨╧╔╙╦ ╨╧ history ╔ ╧╘╘╒─┴
# ┬┼╥┼╘╙╤ ╔═╤ ╧╘╨╥┴╫╔╘┼╠╤. σ╙╠╔ ╬╔▐┼╟╧ ╬┼ ╬┴╩─┼╬╧, ╘╧ X-COMMENT-To
# ╬┼ ╫╙╘┴╫╠╤┼╘╙╤.
if ( !(($hdr{"Comment-To"} ne "") ||
($hdr{"X-Comment-To"} ne "") ||
($hdr{"X-FTN-To"} ne "") ||
($hdr{"X-Fidonet-Comment-To"} ne "") ||
($hdr{"X-Apparently-To"} ne ""))) {
my $refs = $hdr{"References"};
if( $refs ne "" ) {
my @refs = split(/ /, $refs);
my $msgid = pop @refs;
$msgid =~ s/[<>|;\s'"]//g;
my $fn=`$grephistory \'$msgid\' 2>&1`;
if( (!($fn =~ /\/dev\/null/)) &&
(!($fn =~ /Not found/)) ) {
my $orig_from = `$sm $fn`;
my @orig_from = grep(/^From:/, split(/\n/, $orig_from));
$orig_from = shift @orig_from;
$orig_from =~ s/^From:\s*//;
$orig_from =~ s/^\s*(.+[^\s])\s*<[^\s><"\(\)\@]+\@[^\s><"\(\)\@]+>\s*$/$1/;
$orig_from =~ s/^\s*<{0,1}[^\s><"\(\)\@]+\@[^\s><"\(\)\@]+>{0,1}\s*\((.+)\)\s*$/$1/;
$orig_from =~ s/^"//;
$orig_from =~ s/"$//;
$hdr{"X-Comment-To"} = $orig_from;
$modify_headers = 1;
}
}
}
return $rval;
}
# Σ┴╠┼┼ ╦╒╙╧╦ ╔┌ ─╔╙╘╥╔┬╒╘╔╫┴ inn
sub analyze {
my ($lines, $quoted, $antiquoted) = (0, 0, 0);
local $_ = shift;
do {
if ( /\G$config{quotere}/mgc ) {
$quoted++;
} elsif ( /\G$config{antiquotere}/mgc ) {
$antiquoted++;
}
} while ( /\G(.*)\n/gc && ++$lines );
return ($lines, $quoted, $antiquoted);
}