csis-ldif2api.awk
Generated on Tue Dec 05 17:39:05 Eastern Standard Time 2006 from csis-ldif2api.awk
# Program : CSIS-LDIF2API.AWK
# Purpose : Convert LDIF file created by LDAPSEARCH.EXE into an API file for use by GWAPI
# with modifications especially for CSIS (Children's Services)
# Date : 11 July 2005
# Author : Bob Jonkman
function unfold( currentline) { currentline = $0 ;
getline ;
while(substr($0,1,1) ~ "[[:space:]]")
{
currentline = currentline substr($0,2) ;
getline ;
}
return(currentline) ;
}
BEGIN { DOMAIN = "INTERNET";
POSTOFFICE = "CSIS";
DEPARTMENT = "Community & Neighbourhood Servic"; # (GWAPI field length max = 32 char)
DIVISION = "Children's Services"; # (GWAPI field length max = 128 char)
DistList = "COT-CNS-CHS Childrens Services"; # (DIVISION stripped of punctuation)
# Output the API file headers
print("WPC-API= 1.2; ");
print("Header-Char= T50; ");
print("Msg-Type= ADMIN; ");
print("");
}
(1) {
delete record ;
while ($0 != "")
{
delete field ;
line = unfold() ; # Ensure we've got the whole multi-line record
fieldnameendpos = index(line,":")
field[1] = substr(line,1,fieldnameendpos-1)
field[2] = substr(line,fieldnameendpos+1)
# split(line, field, ":") ; # this may result in more than two fields if data contains a colon
# print("##### DEBUG ##### field[1]= " field[1]);
# print("##### DEBUG ##### field[2]= " field[2]);
record[field[1]] = ltrim(field[2]) ;
}
if((match(record["sn"],"[[:digit:]]") == 0) && record["sn"] != "") # Skip records with a numeric digit in LastName or a blank LastName
{
ObjectID = record["uid"] "-" POSTOFFICE ; # Construct ObjectID with POSTOFFICE namespace to avoid duplicates in GW system
# Location info is in subfields the postaladdress field, delimited by "$"
Location = "";
numfields = split(record["postaladdress"],L,"$");
for(i = 1; i <= numfields ; i++)
{
if(L[i] != "Children's Services Division") # Don't include redundant info
Location = Location L[i] ", "; # Concatenate Location field
}
# print("##### DEBUG ##### " FNR " EOR");
print("DS-USER=") ;
print(" Operation= Add;" ) ;
print(" Domain= " DOMAIN ";" ) ;
print(" Post-Office= " POSTOFFICE ";" ) ;
print(" Object= " ObjectID ";" ) ;
print(" Visibility= System;" ) ;
print(" Last-Name= " substr(record["sn"] ,1,40) ";" ) ;
print(" First-Name= " substr(record["givenname"] ,1,32) ";" ) ;
print(" Phone= " substr(record["telephonenumber"] ,1,32) ";" ) ;
print(" Fax= " substr(record["facsimiletelephonenumber"] ,1,32) ";" ) ;
print(" Department= " DEPARTMENT ";" ) ; # Department
print(" Title= " substr(record["title"] ,1,32) ";" ) ;
print(" User-Def-1= " substr(Location ,1,128) ";" ) ; # Mailstop (Location)
print(" User-Def-2= " DIVISION ";" ) ; # Division
print(" User-Def-3= " substr(record["mobile"] ,1,128) ";" ) ; # Mobile (Cel Phone)
print(" User-Def-4= " substr(record["pager"] ,1,128) ";" ) ; # Pager
print(" User-Def-7= " substr(record["ou"] ,1,128) ";" ) ; # Section
print(" Gw-Alias=" ) ;
print(" Type= gwia;" ) ;
print(" External-Name= " record["mail"] ";" ) ;
print(" ;" ) ;
print(" Group=");
print(" Group-Domain= COTPRI;");
print(" Group-Post-Office= COTADM;");
print(" Group-Name= " DistList ";");
print(" ;");
print(";");
print("") ;
}
}
END { print("-END- ") # Output the API file footer
}
# EOF: LDIF2API.AWK
1 files processed.