#!/usr/bin/perl -w #******************************************************************************* # Name : p4abuse.pl # # Author : Tony Smith # # Date : 7th September 2000 # # Description : Script to parse a Perforce log file looking for # examples of client abuse. Currently looks for # the following potential abuses: # # 1. Client used by more than one user # 2. Client used from more than on IP address. # # No output is produced if no abuse is detected. # # If no files are passed on the command line, then # input is read from stdin so this script may be # used in a pipeline. # # In order for this to work, the Perforce log file # must have been written by a server which was # started with the -vserver=1 command line flag. # #******************************************************************************* use Carp; use strict; use vars qw( %CLIENTS ); sub croaksyntax() { print("\n\nUsage: p4abuse.pl [p4.log...]\n\n"); exit(0); } #******************************************************************************* #* Start of main functionality #******************************************************************************* while ( <> ) { if ( /(\S+)\@(\S+) (\d+\.\d+\.\d+\.\d+)/ ) { if ( ! defined( $CLIENTS{$2} ) ) { $CLIENTS{$2} = {}; $CLIENTS{$2}->{'users'} = {}; $CLIENTS{$2}->{'ips'} = {}; } $CLIENTS{$2}->{'users'}->{$1} = 1; $CLIENTS{$2}->{'ips'}->{$3} = 1; } } my $count; foreach my $client (sort keys %CLIENTS) { $count = scalar( keys %{$CLIENTS{$client}->{'users'}}); if ( $count > 1 ) { print("Client $client has been used by $count users\n"); foreach my $user ( sort keys %{$CLIENTS{$client}->{'users'}} ) { print("\t$user\n"); } print("\n"); } $count = scalar( keys %{$CLIENTS{$client}->{'ips'}}); if ( $count > 1 ) { print("Client $client has been used from $count hosts\n"); foreach my $ip ( sort keys %{$CLIENTS{$client}->{'ips'}} ) { print("\t$ip\n"); } print("\n"); } }