App-Waf
view release on metacpan or search on metacpan
lib/App/Waf.pm view on Meta::CPAN
my $result = shift;
my ( $mcount, %rawlog );
my $count = 0;
for ( keys %{$result} ) {
my ( %ip, %requrl, %status, %siteurl );
next if $result->{$_} eq "";
$rawlog{$_} .= $result->{$_};
my @seclogs = split /\n/ms, $result->{$_};
for (@seclogs) {
$count++;
print "DEBUG\:: count()\::IN $_\n" if $DEBUG;
my ( $ip, $requrl, $status, $siteurl ) = (split)[ 0, 6, 8, 10 ];
$ip{$ip}++ if $ip;
$requrl{$requrl}++ if $requrl;
$status{$status}++ if $status;
$siteurl{$siteurl}++ if $siteurl;
print
"DEBUG\:: count()\::OUT $ip\=>$ip{$ip} $requrl\=>$requrl{$requrl} $status\=>$status{$status} $siteurl\=>$siteurl{$siteurl} \n"
if $DEBUG;
}
$mcount->{$_} = [ $count, \%ip, \%requrl, \%status, \%siteurl ];
}
return $mcount, \%rawlog;
}
sub scarlog1 {
my ( $patter, $lines ) = @_;
my %result;
my $code = 'for(@{$lines}) {';
$code .= 'if (m#';
$code .= qr($patter);
$code .= '#) {$result{' . q($patter) . '}.=$_}}';
eval $code;
die "Error ---: $@\n Code:\n$code\n" if ($@);
#print "DEBUG scarlog1 :: OUT :: $_: $result{$_}\n" for(keys %result);
return \%result;
}
sub iptabBan {
# must be root user;
# å¿
é¡»rootç¨æ·æå¯ä»¥æä½iptablesï¼å½ç¶ä¹å¿
é¡»æiptablesæå¡è·å¨ç
my $IP = shift;
my $ips = `/sbin/iptables-save`;
my @ipsline = split /\n/sm, $ips;
my $dist = 0;
for (@ipsline) {
$dist = 1 if ( /$IP/ and /INPUT/ and /DROP/ );
}
unless ($dist) {
`/sbin/iptables -I INPUT -s $IP -j DROP`;
my $btime = localtime( time() );
print "$btime :band $IP \n";
}
else {
print "band alread!\n";
}
}
sub nginxBan {
my $btime = localtime( time() );
my ( $ip, $conf, $pid ) = @_;
my $bid = 0;
open my $nFD, "<", $conf or die("Can not open the file!$!\n");
while (<$nFD>) {
print "DEBUG ::nginxBan :: $conf IN $_" if $DEBUG;
$bid = 1 if /$ip/;
}
close $nFD;
unless ($bid) {
print "$btime,banip $ip\n";
print $nFD "deny $ip\;\n";
$pid = `cat $pid`;
chomp $pid;
`/usr/bin/kill -HUP $pid`;
}
}
=head1 AUTHOR
ORANGE, C<< <bollwarm at ijz.me> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-app-waf at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-Waf>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc App::Waf
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker (report bugs here)
( run in 1.181 second using v1.01-cache-2.11-cpan-140bd7fdf52 )