|
Packit |
57988d |
###########################################################################
|
|
Packit |
57988d |
# $Id$
|
|
Packit |
57988d |
###########################################################################
|
|
Packit |
57988d |
# Copyright (c) 2013 Brian Masney
|
|
Packit |
57988d |
# Covered under the included MIT/X-Consortium License:
|
|
Packit |
57988d |
# http://www.opensource.org/licenses/mit-license.php
|
|
Packit |
57988d |
# Permission is hereby granted, free of charge, to any person obtaining a
|
|
Packit |
57988d |
# copy of this software and associated documentation files (the "Software"),
|
|
Packit |
57988d |
# to deal in the Software without restriction, including without limitation
|
|
Packit |
57988d |
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
Packit |
57988d |
# and/or sell copies of the Software, and to permit persons to whom the
|
|
Packit |
57988d |
# Software is furnished to do so, subject to the following conditions:
|
|
Packit |
57988d |
#
|
|
Packit |
57988d |
# The above copyright notice and this permission notice shall be included
|
|
Packit |
57988d |
# in all copies or substantial portions of the Software.
|
|
Packit |
57988d |
#
|
|
Packit |
57988d |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
Packit |
57988d |
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
Packit |
57988d |
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
Packit |
57988d |
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
Packit |
57988d |
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
Packit |
57988d |
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
Packit |
57988d |
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
Packit |
57988d |
###########################################################################
|
|
Packit |
57988d |
|
|
Packit |
57988d |
my %commands;
|
|
Packit |
57988d |
my %stages;
|
|
Packit |
57988d |
my %unknown;
|
|
Packit |
57988d |
|
|
Packit |
57988d |
while (defined($ThisLine = <STDIN>)) {
|
|
Packit |
57988d |
chomp($ThisLine);
|
|
Packit |
57988d |
|
|
Packit |
57988d |
next if $ThisLine =~ /^starting up, listening on /;
|
|
Packit |
57988d |
next if $ThisLine =~ /OPEN SESAME$/;
|
|
Packit |
57988d |
next if $ThisLine =~ /: sequence timeout /;
|
|
Packit |
57988d |
|
|
Packit |
57988d |
($name, $command) = $ThisLine =~ /^(.*?): running command: (.*)/;
|
|
Packit |
57988d |
if (defined($name)) {
|
|
Packit |
57988d |
$commands{"$name: $command"}++;
|
|
Packit |
57988d |
next;
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
|
|
Packit |
57988d |
($ip, $name, $stage) = $ThisLine =~ /^(\d+\.\d+\.\d+\.\d+): (.*?): Stage (\d+)/;
|
|
Packit |
57988d |
if (defined ($ip)) {
|
|
Packit |
57988d |
$stages{$name}{$stage}{$ip}++;
|
|
Packit |
57988d |
next;
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
|
|
Packit |
57988d |
$unknown{$ThisLine}++;
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
|
|
Packit |
57988d |
|
|
Packit |
57988d |
if (keys %stages) {
|
|
Packit |
57988d |
print "knockd stages reached\n";
|
|
Packit |
57988d |
foreach my $name (sort keys %stages) {
|
|
Packit |
57988d |
print "\t$name\n";
|
|
Packit |
57988d |
foreach my $stage (sort keys %{$stages{$name}}) {
|
|
Packit |
57988d |
print "\t\tStage $stage\n";
|
|
Packit |
57988d |
foreach my $ip (sort keys %{$stages{$name}{$stage}}) {
|
|
Packit |
57988d |
print "\t\t\tFrom $ip: " . $stages{$name}{$stage}{$ip} . " time(s)\n";
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
|
|
Packit |
57988d |
if (keys %commands) {
|
|
Packit |
57988d |
print "\n";
|
|
Packit |
57988d |
print "knockd commands executed\n";
|
|
Packit |
57988d |
foreach my $command (sort keys %commands) {
|
|
Packit |
57988d |
print "\t" . $commands{$command} . " time(s): $command\n";
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
|
|
Packit |
57988d |
if (keys %unknown) {
|
|
Packit |
57988d |
print "\n";
|
|
Packit |
57988d |
print "knockd unknown log entries\n";
|
|
Packit |
57988d |
foreach my $line (sort keys %unknown) {
|
|
Packit |
57988d |
print "\t" . $unknown{$line} . " time(s): $line\n";
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
}
|