BuzzSaw

 view release on metacpan or  search on metacpan

lib/BuzzSaw/UserClassifier.pm  view on Meta::CPAN


  # student usernames are 's' followed by 7 digits
  #
  # Assume these are typos:
  #   A double 's' to start
  #   Anything starting 's' followed by 5, 6 or more than 7 digits
  #   Exactly 7 digits (but not initial 's')
  #   
  # Also matching anything which looks like a visitor account

  if ( $username =~ m/^s{1,2}[0-9]{5}/io ||
       $username =~ m/^[0-9]{7}$/o      ||
       $username =~ m/^v[0-9][a-z]+[0-9]?$/io ) {
    return 1;
  }

  return 0;
}

sub is_root {
  my ( $self, $username ) = @_;

  # matches root, r00t, r0ot, ROOT, etc
  if ( $username =~ m/^r[o0]{2}t$/io )  {
    return 1;
  }

  return 0;
}

sub is_nonpersonal {
  my ( $self, $username ) = @_;

  if ( $self->is_person($username) || $self->looks_like_person($username) ) {
    return 0;
  }

  # Check to see if the user exists (but is not a member of the
  # 'people' group as we have already seen)

  if ( $self->is_user($username) ) {
    return 1;
  }

  # Finally check to see if it is in the nonpersonal dict

  return $self->in_nonpersonal_users($username);
}

sub mangle_username {
  my ( $self, $username ) = @_;

  $username =~ s/^@@@//;

  $username = lc $username;

  if ( $username eq 'tmp' ) {
    $username = 'temp';
  }

  my @startlike = ( 'account','admin','backup','cacti','cvs',
                    'ftp','gast','guest','mysql','nagios','oracle',
                    'postgres','shoutcast','smb','spam','support',
                    'sysadm',
                    'teamspeak','newsreaderg','data','usr','team',
                    'marketing','monitoring','svn','feedback',
                    'telnet','temp','test','web','www' );

  for my $entry (@startlike) {
    if ( index($username, $entry) == 0 ) {
      $username = $entry;
      last;
    }
  }

  return $username;
}

sub classify {
  my ( $self, $username ) = @_;

  my $user_type = 'others';

  if ( $self->is_root($username) ) {
    $user_type = 'root';
  } elsif ( $self->is_person($username) ||
            $self->looks_like_person($username) ) {
    $user_type = 'real';
  } elsif ( $self->is_nonpersonal($username) ) {
    $user_type = 'nonperson';
  }

  return $user_type;
}

1;
__END__

=head1 NAME

BuzzSaw::UserClassifier - Classifies the type of a username

=head1 VERSION

This documentation refers to BuzzSaw::UserClassifier version 0.12.0

=head1 SYNOPSIS

   my $classifier = BuzzSaw::UserClassifier->new();

   my $user = "R00t";
   my $cleaned_username = $classifier->mangle_username($user);

   my $user_type = $classifier->classify($cleaned_username);

   print "Type for $user is $user_type\n";

=head1 DESCRIPTION

The BuzzSaw project provides a suite of tools for processing log file
entries. Entries in files are parsed and filtered into a set of events



( run in 0.663 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )