All the files
This commit is contained in:
46
bin/parserfilter-tester
Executable file
46
bin/parserfilter-tester
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use Getopt::Long;
|
||||
use My::parser::stats;
|
||||
my $module;
|
||||
my @modules = ('ssh','dovecot','exim','apache','gitea_ssh');
|
||||
my $program = $0;
|
||||
GetOptions ("module=s" => \$module); #Only test one module
|
||||
unless($module) {
|
||||
print 'No module specified, use argument --module=(ssh|dovecot|exim|apache|gitea_ssh)'."\n";
|
||||
exit;
|
||||
}
|
||||
my @matches = grep { /$module/ } @modules;
|
||||
unless(@matches) {
|
||||
print 'Unsupported module '.$module.' specified, use argument --module=(ssh|dovecot|exim|apache|gitea_ssh)'."\n";
|
||||
exit;
|
||||
}
|
||||
print "Please paste a line to parse here:\n";
|
||||
my $frompipe = <STDIN>;
|
||||
chomp($frompipe); #One line is fine for us, user may fuck up, but we're good..
|
||||
my $parser = &load($module);
|
||||
my $result = $parser->parser($frompipe);
|
||||
if($result->{'retval'}) {
|
||||
print 'Parser said: '.$result->{'retmsg'}."\n";
|
||||
print 'Regarded as a hostile action'."\n" if($result->{'hostile'});
|
||||
print 'Host: '.$result->{'host'}."\n";
|
||||
} else {
|
||||
print 'Parser found no match'."\n";
|
||||
}
|
||||
|
||||
sub load {
|
||||
my $parser = shift;
|
||||
my $filename = 'My/parser/'.$parser.'_parser.pm';
|
||||
my $newclass;
|
||||
eval {
|
||||
require $filename;
|
||||
my $classname = 'My::parser::'.$parser.'_parser';
|
||||
$newclass = $classname->new || die "Failed to load parser for $parser";
|
||||
} or do {
|
||||
my $e = $@;
|
||||
print 'Could not load parser '.$module.' from file '.$filename.': '.$e."\n";
|
||||
exit;
|
||||
};
|
||||
return $newclass;
|
||||
}
|
||||
Reference in New Issue
Block a user