head 1.1;
access;
symbols;
locks; strict;
comment @# @;
1.1
date 94.03.12.00.59.25; author paul; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial revision
@
text
@#!/usr/bin/perl
#
# aliasassign - assign aliases
#
# assumes first field is alias
#
# usage: aliasassign config [files]
#
# Copyright (c) 1985 Corporation for Research and Educational Networking
# Copyright (c) 1988 University of Illinois Board of Trustees, Steven
# Dorner, and Paul Pomes
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the Corporation for
# Research and Educational Networking (CREN), the University of
# Illinois at Urbana, and their contributors.
# 4. Neither the name of CREN, the University nor the names of their
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE TRUSTEES AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE TRUSTEES OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# @@(#)$Id$
if ($#ARGV<0)
{print STDERR "Usage: aliasassign prod.cnf [files]\n";exit 1;}
#
# find the numbers of the name and alias fields
$anum = -1;
$nnum = -1;
$lnum = -1;
$config=shift;
open (CONFIG,$config) || die "$config: $!\n";
while (<CONFIG>)
{
if (/:name:/) {($nnum)=(split(':'))[0];}
elsif (/:alias:/) {($anum)=(split(':'))[0];}
elsif (/:email:/) {($enum)=(split(':'))[0];}
elsif (/:locked:/) {($lnum)=(split(':'))[0];}
elsif (/:type:/) {($tnum)=(split(':'))[0];}
}
close(CONFIG);
#
# collect all the defined aliases
$aliases{""} = 1;
while (<>)
{
chop;
($alias,$rest) = split(/[\t]/,$_,2);
$alias =~ s/[0-9]*://;
$alias =~ tr/A-Z/a-z/;
if ($alias eq "~~~~") {last;} # marker for no alias
$aliases{$alias} = 1;
if ($rest =~ /\t$tnum:[ ]*person/o)
{
print "$rest\t$anum:$alias\n";
}
}
$_ .= "\n";
#
# now, assign new ones
do
{
chop;
($email = $_) =~ s/.*\t$enum:([^\t]*).*/$1/;
$email =~ s/\\n.*//;
$email =~ tr/A-Z/a-z/;
$email = "" if ($email =~ /uicvmc/);
$email =~ s/[@@%=_].*//;
$email = "" if ($email =~ /[0-9]/);
$email =~ tr/ \-a-z//cd;
while ($email ne "" && length($email) > 8)
{
chop($email);
}
$email = "" if (length($email) < 3);
s/[^\t]*\t//; # strip alias
($name = $_) =~ s/.*\t$nnum:([^\t]*).*/$1/; # grab name
$name =~ tr/ a-z//cd; # delete illegal alias characters
@@frags = split(" ",$name); # break into components
# <first name>-<last name>. Set to null if over 8.
$Nalias0 = $#frags>0 ? $frags[1] . "-" . $frags[0] : "";
$Nalias0 = "" if (length($Nalias0 > 8));
# <last name> iff 3 or more characters. Chopped to 8 if over that.
$Nalias1 = length($frags[0]) > 2 ? $frags[0] : "";
# <last name> iff 3 or more characters. Remove last vowel until less than 8.
$Nalias2 = length($frags[0]) > 2 ? $frags[0] : "";
# <first initial>-<last name>. If over 8, remove '-'. If still over,
# chop to 8.
$Nalias3 = $#frags>0 ? substr($frags[1],0,1) . "-" . $frags[0] : $name;
# <first initial><middle initial>-<last name>. If over 8, remove '-'.
# If still over, chop to 8.
$Nalias4 = $#frags>1 ? substr($frags[1],0,1) . substr($frags[2],0,1) . "-" . $frags[0] : "";
# <first initial>-<last name> iff 3 or more characters. If over 8, remove
# '-'. If still over, remove last vowel until less than 8.
$Nalias5 = $#frags>0 ? substr($frags[1],0,1) . "-" . $frags[0] : $name;
# <first initial><middle initial>-<last name> iff 3 or more characters.
# If over 8, remove '-'. If still over, remove last vowel until less than 8.
$Nalias6 = $#frags>1 ? substr($frags[1],0,1) . substr($frags[2],0,1) . "-" . $frags[0] : "";
# For hypenated first names, e.g., lee-jen, use lj. Otherwise as
# <first initial><middle initial>-<last name> iff 3 or more characters.
# If over 8, remove '-'. If still over, remove last vowel until less than 8.
if ($#frags>0 && $frags[1] =~ /-/)
{
$Nalias7 = substr($frags[1],0,1) . substr($frags[1],index($frags[1], "-")+1,1) . "-" . $frags[0];
} else
{
$Nalias7 = "";
}
$sequence = "";
for(;;)
{
# Chop to length if over 8
while (length($Nalias1) > 8)
{
chop($Nalias1);
}
# Remove last vowel if over 8. If no more vowels, chop to 8.
while ((length($Nalias2)+length($sequence)) > 8)
{
$Temp = reverse($Nalias2);
$Temp =~ s/[aeiou]+//;
last if (length($Temp) == length($Nalias2));
$Nalias2 = reverse($Temp);
}
while ((length($Nalias2)+length($sequence)) > 8)
{
chop($Nalias2);
}
# If over 8, remove '-'. If still too long, chop to length.
while ((length($Nalias3)+length($sequence)) > 8)
{
if (!($Nalias3 =~ s/-//))
{
chop($Nalias3);
}
}
# If over 8, remove '-'. If still too long, chop to length.
while ($Nalias4 ne "" && length($Nalias4)+length($sequence) > 8)
{
if (!($Nalias4 =~ s/-//))
{
chop($Nalias4);
}
}
# If over 8, remove '-'. If still too long, remove last vowel.
# If no more vowels, chop to 8.
while (($i = length($Nalias5)+length($sequence)) > 8)
{
if (!($Nalias5 =~ s/-//))
{
$Temp = reverse($Nalias5);
$Temp =~ s/[aeiou]+//;
last if (length($Temp) == length($Nalias5));
$Nalias5 = reverse($Temp);
}
}
while ((length($Nalias5)+length($sequence)) > 8)
{
chop($Nalias5);
}
# If over 8, remove '-'. If still too long, remove last vowel.
# If no more vowels, chop to 8.
if ($Nalias6 ne "")
{
if (!($Nalias6 =~ s/-//))
{
while (($i = length($Nalias6)+length($sequence)) > 8)
{
$Temp = reverse($Nalias6);
$Temp =~ s/[aeiou]+//;
last if (length($Temp) == length($Nalias6));
$Nalias6 = reverse($Temp);
}
}
}
while ($Nalias6 ne "" && (length($Nalias6)+length($sequence)) > 8)
{
chop($Nalias6);
}
# Chop to length if over 8
while (length($Nalias7) > 8)
{
chop($Nalias7);
}
# Now see if any are available.
if ($email ne "" && $aliases{$email} eq "" && $BadKeys{$email} ne "1")
{
$alias = $email;
$aliases{$alias} = 1;
last;
}
else { $email = "";}
if ($Nalias0 ne "" && $aliases{$Nalias0} eq "" && $BadKeys{$Nalias0} ne "1")
{
$alias = $Nalias0;
$aliases{$alias} = 1;
last;
}
if ($Nalias1 ne "" && $aliases{$Nalias1} eq "" && $BadKeys{$Nalias1} ne "1") {
$alias = $Nalias1;
$aliases{$alias} = 1;
last;
}
if ($Nalias2 ne "" && $aliases{$Nalias2} eq "" && $BadKeys{$Nalias2} ne "1") {
$alias = $Nalias2;
$aliases{$alias} = 1;
last;
}
if ($Nalias3 ne "" && $aliases{$Nalias3} eq "" && $BadKeys{$Nalias3} ne "1") {
$alias = $Nalias3;
$aliases{$alias} = 1;
last;
}
if ($Nalias4 ne "" && $aliases{$Nalias4} eq "" && $BadKeys{$Nalias4} ne "1") {
$alias = $Nalias4;
$aliases{$alias} = 1;
last;
}
if ($Nalias5 ne "" && $aliases{$Nalias5.$sequence} eq "" && $BadKeys{$Nalias5.$sequence} ne "1") {
$alias = $Nalias5.$sequence;
$aliases{$alias} = 1;
last;
}
if ($Nalias6 ne "" && $aliases{$Nalias6.$sequence} eq "" && $BadKeys{$Nalias6.$sequence} ne "1") {
$alias = $Nalias6.$sequence;
$aliases{$alias} = 1;
last;
}
if ($Nalias7 ne "" && $aliases{$Nalias7.$sequence} eq "" && $BadKeys{$Nalias7.$sequence} ne "1") {
$alias = $Nalias7.$sequence;
$aliases{$alias} = 1;
last;
}
if ($Nalias1 ne "" && $aliases{$Nalias1} eq "" && $BadKeys{$Nalias1} ne "1") {
$alias = $Nalias1;
$aliases{$alias} = 1;
last;
}
if ($Nalias2 ne "" && $aliases{$Nalias2} eq "" && $BadKeys{$Nalias2} ne "1") {
$alias = $Nalias2;
$aliases{$alias} = 1;
last;
}
$sequence++;
}
print "$anum:$alias\t$_\t$lnum:$Date\n";
}
while (<>);
@