csis-ldap-nab2api.awk
Generated on Tue Dec 05 17:39:06 Eastern Standard Time 2006 from csis-ldap-nab2api.awk
# Program: CSIS-LDAP-NAB2API.AWK
# Purpose: Convert a Novell Addressbook file (pulled from CSIS LDAP server) to a GWAPI file (users only)
# Author: Bob Jonkman <bjonkman@sobac.com>
# Copyright 2008 Bob Jonkman and/or SOBAC Microcomputer Services
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Date: 22 October 2004
# Note: This AWK script has been specially constructed for Children's Services LDAP output
# Output file format: Standard GW API tagged-field format.
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)
FS = "" ;
OFS = "" ;
ORS = "" ;
FIELD_SEPARATOR = "," ;
FIELD_DELIMITER = "\"" ;
RECORD_SEPARATOR = "\n";
# Input file format:
tag = 01 ;
Name = 02 ;
EMailType = 03 ;
EMailAddress = 04;
Comments = 05;
FaxNumber = 06;
UserID = 07;
Department = 08;
FirstName = 09;
LastName = 10;
PhoneNumber = 11;
City = 12;
State = 13;
Country = 14;
Title = 15;
HomePhoneNumber = 16;
CellularPhoneNumber = 17;
Mailstop = 18;
# Output the API file headers
print("WPC-API= 1.2; \n");
print("Header-Char= T50; \n");
print("Msg-Type= ADMIN; \n");
print("\n");
}
NR != 1 { # Ignore the first record (field names)
parsecsv($0,fields);
if((match(fields[LastName],"[[:digit:]]") == 0) && fields[LastName] != "") # Skip records with a numeric digit in LastName or a blank LastName
{
# CSIS LDAP returns a blank UserID, so we construct our own
ObjectID = substr(fields[EMailAddress],1,index(fields[EMailAddress],"@")-1) ;
if(ObjectID != "") # Skip records with blank ObjectID
{
ObjectID = ObjectID "-" POSTOFFICE; # Construct ObjectID with POSTOFFICE namespace to avoid duplicates in GW system
# Location info is in subfields 2-* of the Mailstop field, delimited by "$"
Location = "";
numfields = split(fields[Mailstop],L,"$");
for(i = 2; i <= numfields ; i++)
Location = Location L[i] ", "; # Concatenate Location field
print("DS-User=\n");
print(" Operation= Add;\n");
print(" Domain= " DOMAIN ";\n");
print(" Post-Office= " POSTOFFICE ";\n");
print(" Object= " ObjectID ";\n");
print(" Visibility= System;\n");
print(" Last-Name= " substr(fields[LastName] ,1,40) ";\n");
print(" First-Name= " substr(fields[FirstName] ,1,32) ";\n");
print(" Phone= " substr(fields[PhoneNumber] ,1,32) ";\n");
print(" Fax= " substr(fields[FaxNumber] ,1,32) ";\n");
print(" Department= " DEPARTMENT ";\n");
print(" Title= " substr(fields[Title] ,1,32) ";\n");
print(" User-Def-1= " substr(Location ,1,128) ";\n"); # Mailstop (Location)
print(" User-Def-2= " DIVISION ";\n");
print(" User-Def-3= " substr(fields[CellularPhoneNumber],1,128) ";\n");
print(" User-Def-7= " substr(fields[Department] ,1,128) ";\n"); # Section
print(" Gw-Alias=\n");
print(" Type= gwia;\n");
print(" External-Name= " fields[EMailAddress] ";\n");
print(" ;\n");
print(" Group=\n");
print(" Group-Domain= COTPRI;\n");
print(" Group-Post-Office= COTADM;\n");
print(" Group-Name= " DistList ";\n");
# print(" Participation= Primary;\n");
print(" ;\n");
print(";\n");
print("\n");
} # if(ObjectID != "")
} # if(fields[LastName] != "")
}
END { print("\n-END- \n") # Output the API file footer
}
# EOF: CSIS-LDAP-NAB2API.AWK
1 files processed.