gwconv.awk
Generated on Tue Dec 05 17:39:06 Eastern Standard Time 2006 from gwconv.awk
# Program : GWCONV.AWK
# Purpose : Create USER, GROUP and RESOURCE lists from a -GET-DIRECTORY- API command output
# 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 : 13 April 2006
# Notes : USER headers: Domain
# Post-Office
# Object
# Last-Name
# First-Name
# Phone
# Fax
# Department
# Title
# Visibility
# Network-ID
# Account-ID
# User-Def-1
# User-Def-2
# User-Def-3
# User-Def-4
# User-Def-5
# User-Def-6
# User-Def-7
# User-Def-8
# User-Def-9
# User-Def-10
# Expire-Date
# Description
# : GROUP headers: Domain
# Post-Office
# Object
# Visibility
# Expire-Date
# Description
# Member-Domain
# Member-Post-Office
# Member-Object
# Member-Object-Type
# Member-Last-Name
# Member-First-Name
# Member-Participation
# : RESOURCE headers: Domain
# Post-Office
# Object
# Owner
# Last-Name
# First-Name
# Visibility
# Type
# Phone
# Expire-Date
# Description
function getapirec(rawline,returnarray ) {
rawline = trim($0)
# print("##### DEBUG ##### getapirec NR= " NR, " $0= " $0)
keywordseparatorindex = index(rawline,KEYWORD_SEPARATOR)
keyword = trim(substr(rawline,1,keywordseparatorindex-1))
returnarray[keyword] = trim(substr(rawline,keywordseparatorindex+1))
while(substr(rawline,length(rawline),1) != RECORD_SEPARATOR)
{
getline
rawline = trim($0)
returnarray[keyword] = returnarray[keyword] " " rawline
# print("##### DEBUG ##### loop NR= " NR, " returnarray[keyword]= " returnarray[keyword], " $0= " $0)
}
returnarray[keyword] = rtrim(substr(returnarray[keyword],1,length(returnarray[keyword])-1)) # Remove trailing spaces and RECORD_SEPARATOR
return(keyword)
}
BEGIN { OFS = ","
RECORD_SEPARATOR = ";" # semi-colon defined by API spec, pg 43
KEYWORD_SEPARATOR = "=" # keyword separator - pg 43
COMMENT_MARKER = "#" # hash defined by API spec pg 50
userfile = "USERS.CSV"
groupfile = "GROUPLIST.CSV"
grpmembfile = "GROUPMEMB.CSV"
resourcefile = "RESOURCES.CSV"
print("Domain,Post-Office,Object,Last-Name,First-Name,Phone,Fax,Department,Title,Visibility,Network-ID,Account-ID,User-Def-1,User-Def-2,User-Def-3,User-Def-4,User-Def-5,User-Def-6,User-Def-7,User-Def-8,User-Def-9,User-Def-10,Expire-Date,Description") > userfile
print("Domain,Post-Office,Object,Visibility,Expire-Date,Description,Member-Domain,Member-Post-Office,Member-Object,Member-Object-Type,Member-Last-Name,Member-First-Name,Member-Participation") > groupfile
print("This is to be the Group Membership file") > grpmembfile
print("Domain,Post-Office,Object,Owner,Last-Name,First-Name,Visibility,Type,Phone,Expire-Date,Description") > resourcefile
}
!(NR % 10000) { print("NR= " NR, "USERS= " usercount, " GROUPS= " groupcount, " RESOURCES= " resourcecount) > "/dev/stderr" # Progress indicator
}
FNR == 1 { wpcapikeyword = getapirec($0,wpcapi)
print(wpcapikeyword)
if ( wpcapikeyword != "WPC-API")
{ print(FILENAME " is not an API file") > "/dev/stderr"
nextfile
}
}
/Msg-Type/ { print(getapirec($0,msgtype))
if(msgtype["Msg-Type"] != "ADMIN")
{ print(FILENAME " is not Msg-Type=ADMIN but " msgtype["Msg-Type"]) > "/dev/stderr"
nextfile
}
}
(substr($0,1,1) == COMMENT_MARKER) { print(NR, $0)
next # read next input line (ignore comments)
}
/DS\-User/ {
# print("##### DEBUG ##### " NR, $0)
delete record
getline
trimline = trim($0)
while(trimline != RECORD_SEPARATOR)
{
userkeyword[getapirec(trimline,record)]++ # Get record, count keyword
getline
trimline = trim($0)
}
usercount++
print(printcsv(record["Domain"]),printcsv(record["Post-Office"]),printcsv(record["Object"]),printcsv(record["Last-Name"]),printcsv(record["First-Name"]),printcsv(record["Phone"]),printcsv(record["Fax"]),printcsv(record["Department"]),printcsv(record["Title"]),printcsv(record["Visibility"]),printcsv(record["Network-ID"]),printcsv(record["Account-ID"]),printcsv(record["User-Def-1"]),printcsv(record["User-Def-2"]),printcsv(record["User-Def-3"]),printcsv(record["User-Def-4"]),printcsv(record["User-Def-5"]),printcsv(record["User-Def-6"]),printcsv(record["User-Def-7"]),printcsv(record["User-Def-8"]),printcsv(record["User-Def-9"]),printcsv(record["User-Def-10"]),printcsv(record["Expire-Date"]),printcsv(record["Description"])) > userfile
}
/DS\-Group/ { delete record
getline
trimline = trim($0)
while (trimline != RECORD_SEPARATOR)
{
groupkeyword[getapirec(trimline,record)]++ # Get record, count keyword
getline
trimline = trim($0)
}
groupcount++
print(printcsv(record["Domain"]),printcsv(record["Post-Office"]),printcsv(record["Object"]),printcsv(record["Visibility"]),printcsv(record["Expire-Date"]),printcsv(record["Description"]),printcsv(record["Member-Domain"]),printcsv(record["Member-Post-Office"]),printcsv(record["Member-Object"]),printcsv(record["Member-Object-Type"]),printcsv(record["Member-Last-Name"]),printcsv(record["Member-First-Name"]),printcsv(record["Member-Participation"])) > groupfile
}
/DS\-Resource/ {
delete record
getline
trimline = trim($0)
while(trimline != RECORD_SEPARATOR)
{
resourcekeyword[getapirec(trimline,record)]++ # Get record, count keyword
getline
trimline = trim($0)
}
resourcecount++
print(printcsv(record["Domain"]),printcsv(record["Post-Office"]),printcsv(record["Object"]),printcsv(record["Owner"]),printcsv(record["Last-Name"]),printcsv(record["First-Name"]),printcsv(record["Visibility"]),printcsv(record["Type"]),printcsv(record["Phone"]),printcsv(record["Expire-Date"]),printcsv(record["Description"])) > resourcefile
}
END { print("=====")
print("User Keywords:")
for (i in userkeyword)
print(i, userkeyword[i])
print("")
print("Group Keywords:")
for (i in groupkeyword)
print(i, groupkeyword[i])
print("")
print("Resource Keywords:")
for (i in resourcekeyword)
print(i, resourcekeyword[i])
print("")
}
1 files processed.