/
WOWFilter.pm
49 lines (40 loc) · 1.1 KB
/
WOWFilter.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package WOWFilter;
use File::Stat;
use base qw( HTTP::Proxy::BodyFilter );
# add the ability to replace roots and have conjugation, etc work out
# note for starters these over correct for the propaganda
my $techniquesfile = "techniques.pl";
$techniques = {};
$lastupdated = "";
sub update {
print "Updating rules\n";
my $c = `cat "$techniquesfile"`;
$techniques = eval $c;
my $stat = new File::Stat($techniquesfile);
$lastupdated = $stat->mtime;
}
sub load_techniques {
if (! $lastupdated) {
update();
} else {
# check whether the file is newer
my $stat = new File::Stat($techniquesfile);
if ($stat->mtime > $lastupdated) {
update();
}
}
}
sub filter {
my ( $self, $dataref, $message, $protocol, $buffer ) = @_;
load_techniques();
# do not get items that are in html, extract the html first, like links etc
foreach my $technique (keys %$techniques) {
# print "$technique\n";
foreach my $key (keys %{$techniques->{$technique}}) {
# print "\t$key\n";
my $value = $techniques->{$technique}->{$key};
$$dataref =~ s/$key/$value/ig;
}
}
}
1;