Files
Compose-Files/Backups/Miker/.trash/Information WebTele AD Integration Documentation.md
T
2026-07-20 09:23:17 -04:00

133 KiB
Raw Blame History

US Customs and Border Protection
 
 
Active Directory System Interfaces for Directory Updates
 
 
 
 
  
                                                       
Restrictions on Disclosure and Use of Data
This document includes data that shall not be disclosed by the Government and shall not be duplicated, used, or disclosed in whole or in part --- for any purpose other than to support the deployment of Microsoft Exchange at Customs and Border Protection.
 
 
 

 
REVISION HISTORY
 

Date Ver Description Author
8/15/2007 .9 Initial Draft Rob Craig
2/22/2008 1.0 First Release Rob Craig
4/16/2008 1.1 Updated to reflect new DHS Update Script Rob Craig

 
 
  
TABLE OF CONTENTS
 
1.     Overview
1.1.      Global Address List Directory Information
1.2.      DHS Directory Synchronization
2.     GLobal address list directory information
2.1.      Components
2.1.1.       WebTELE
2.1.2.       Data Reporter
2.1.3.       Integration Scripts
2.1.4.       Active Directory
2.2.      Data Flow
3.     DHS Directory synchronization
3.1.      Components
3.2.      Process Flow
3.3.      Troubleshooting Individual Email Address Assignment
3.4.      Resetting a User's DHS Address
4.     WEBTELE INTEGRATION script Version 1.X
5.     OSC Directory integration script Version 2.X
 
 
 
1.              Overview
Active Directory has replaced other network directory and authentication systems and is currently the enterprise system of record for access to common network and application resources within the Bureau of Customs and Border Protection.  In order to keep this information as current and accurate as possible, Active Directory has multiple interfaces for updating and providing information to and from other systems internal and external to CBP.  The following interfaces are addressed in this document:
 
1.1.         Global Address List Directory Information
Based on CBP Policy, the mainframe personnel system of record within CBP is TELE and WebTELE (where WebTELE is the web interface application integrated with TELE).  Information contained in TELE includes individual's contact information, title, and organization code.  In order to provide this information to Outlook users, an integration process has been developed to populate Active Directory with this information.  This process is described in this document

1.2.         DHS Directory Synchronization
CBP shares a common Global Address List (GAL) with other DHS components.  This process is maintained by the US Coast Guard.  Nightly, CBP provides a complete directory "push" to USCG OSC for the following processes to run:
 

  • Assignment of "DHS E-mail Addresses" to CBP personnel (e.g., joe.a.anyuser@dhs.gov), and
  • Propagation of CBP contact information out to the other components to populate their respective GAL

2.              GLobal address list directory information
In order for users of Outlook to view contact properties about users in the GAL, a synchronization process runs to populate data from TELE to Active Directory.  This is run approximately daily and is described in more detail in this section.
 
2.1.         Components
There are several components of the integration between WebTELE and Active Directory.  These include:
 

  • WebTELE, which reflects the mainframe dataset on each CBP government employee, and many, if not most, contractor personnel.
  • Data Reporter, which is the tool used to extract the "TELE.txt" file from WebTELE;
  • The ADTELEUpdate.VBS script, which is a custom-developed ADSI (Active Directory Systems Integration) script used to compare the contents of the TELE.txt file with the information in Active Directory, and, as needed, update Active Directory.
  • Active Directory, which is the enterprise network directory system containing user information on all CBP users authorized to access network resources.

 
Each of these elements is discussed in more detail below.
2.1.1.  WebTELE
WebTELE is the web-enabled interface to an instance of TELE.  It is accessible from CBPNet, and it is built on a WebSphere platform against a DB2 backend.  It is the primary method for users to access and update their contact data.
2.1.2.  Data Reporter
Data Reporter is a light-weight application that interfaces with various database types in order to extract and produce data reports in a variety of user-defined formats.  The instance of Data Reporter used for this integration runs against production databases on the TSOE mainframe.  It runs under Production Management's control (as job name KAITELEX) every 24 hours at approximately 10 pm EST.  The output file is FTP'ed down to NWG-EXVS-A-001 to the D:\FTP Data directory as "TELE.TXT" file overwriting the file from the previous output.  The job supplies FTP credentials to NWG-EXVS-A-001 which are contained in the job.
 
Currently the job is configured to pull only those users with an organization two-letter alpha of "CU" (for Customs).  As of the date on this documentation, approximately 52,000 records are pulled for each job.  This should represent all government employees at CBP with at least a Limited BI, but this does not necessarily include all or most contract staff.
2.1.3.  Integration Scripts
 

  • LaunchTELE.cmd. This is a task run from the NT Scheduler (currently scheduled to run at 2:00 am Mon Fri).  It launches the following two tasks (in this order):
  • FileSCRUB.vbs.  This Visual Basic script has one purpose:  to open the TELE.TXT file (the output from Data Reporter) using Windows Notepad and save and close the file.  This has the effect of removing some unwanted characters that exist in some of the WebTELE records.  Specifically, the characters are 00 "low-value" mainframe characters which appear as extended ASCII character 255 in the text file.  These characters disrupt the data mapping process in those records which contain these characters (roughly 5-10% of all records in WebTELE).  Opening and saving the file in Notepad replaces those characters with a simple space which is all that is needed for the process to continue correctly.
  • ADUpdatev1_0.vbs.  After the file has been scrubbed, the main update script runs.  This is a VB ADSI script which runs within the default domain (ad.cbp.dhs.gov).  It is described in more detail below.

 
The basic logic of ADUpdate1_0.vbs is as follows:  It loads the TELE.TXT into an array one line at a time and performs an LDAP search for the user based on Hash ID.  Upon a match, it cycles through a series of attributes and compares them to the contents of the array.  It updates or deletes the value in the AD user object based on the comparison and logs any changes in a log file (telechanges.log).  Finally, it sends an email confirmation upon completion describing how many records were checked, how many AD matches were found, how many records were updated, and how many total attributes were modified.  The attributes updates in this version are as follows:
 

  • Government or Contractor status
  • Title
  • Office Number (e.g., Suite or Room number)
  • Street Address
  • City / State / Zip / Country
  • Telephone Number
  • Fax Number
  • Organization Code
  • Department (down to the office level for example, "Office of Field Operations, Office of Border Patrol, Office of Information Technology, etc.)

 
Within the script there is a constant (maxChanges) that "throttles" the number of user records that will be changed during any one execution of the script.  This number is iterated once each time a change has to be made to a user object (whether that user object has 1 or 5 changes does not matter, only that the specific record was updated in some way).  Once the maxChanges value is reached, the routine is ended and no more changes will be made until the script is executed again.
 
There are two purposes for this throttle:
 

  1. To minimize a load of "bad data" into Active Directory should the TELE.TXT file contain bad or corrupted data; and
  2. To prevent updating a large enough portion of the Global Address List (GAL) during any 24 hour period which may prompt a large number of full Offline Address Book downloads across the network.

 
Currently maxChanges is normally set to 2000 which means that no more than 2000 user objects will have their records updated during any single run (normally within a 24 hour period).  When the directory is stable, this number is more than sufficient to run through the complete TELE.TXT file and ensure everyone's record is checked for updates.  If for some reason there are a lot of directory changes since the last run, it is possible that it could take several days running the process before all changes have been included and the directory stabilizes.
 
The following example helps illustrate this:  currently there are over 52,000 records in the TELE.TX output.  If everyone needed to have their record updated with some information, it would take at least 26 days (26 x 2000 changed records per day) to update the entire directory and stabilize.  In the first 25 days of processing, the LAST 2000 records (alphabetically arranged by Hash ID) would not have their user account checked or updated at all.  In this example, it would be best to set the value of maxChanges to a higher value to speed through this process more quickly.  It is difficult to determine a "safe value," but 5,000 would likely be well within that zone.

2.1.4.  Active Directory
Active Directory is the primary network authentication system for users and applications within CBP.  All CBP employees and contract staff needing access to resources on the network and with a limited Background Investigation should have a user object in Active Directory.  This user object has many attributes, some of which are related to the contact information updated by this process (i.e., Telephone, City, Title, etc.).
2.2.         Data Flow
 
 
 
 
 
 
3.              DHS Directory synchronization
The DHS Directory Synchronization process is necessary for the following:
 

  1. To assign users a DHS or external E-mail address in the format joe.a.anyuser@dhs.gov; and
  2. To propagate CBP contact information to the other DHS components.

 
There are several components required for this functionality to work properly.  These are listed in section 3.1 below.
 
3.1.         Components
The following components are required for the OSC Directory Synchronization to work properly.
 

  • LDIFDE Query and Filter.  There are two queries: one for users and one for groups.  The filter is defined in the bat files (CBP_DirExport.bat and CBP_DirExportGROUPS.bat). The actual LDIF query syntax is listed below.  The query is designed to only export AD user objects if they meet the following criteria:

    • For USERS:

      • Have an Exchange mailbox (no AD-only accounts)
      • Do not have "No DHS Sync" in extensionAttribute8
    • For GROUPS (including query-based distribution groups):

      • Have "DHS Sync" in extensionAttribute8.  Groups by default are NOT sent up to DHS unless they have this value in extensionAttribute8.
  • Reformat and Upload Script.  In order to get the output into the format required by OSC, a reformatting script runs against every line from the LDIFDE output.  It performs the following tasks:

    • Changes the Distinguished Name value to a generic OU value.
    • Changes group object type labels so that they appear to be user objects with a last name (sn attribute).
    • FTP's the resulting file (export.dir) with the proper FTP credentials to (insert FTP commands)
  • Download Script.  Following the upload, a script is used to download the log file from the previous evening.  This is used for troubleshooting purposes.

  • Log file.  This is the actual file downloaded from OSC (uscs-01-exch2n.log).

  • DHS Address Download. In order to keep track of user's DHS addresses, there is a script used to update extensionAttribute10 with the user's current DHS address.

 
The LDIF filter syntax for USERs is:
 
ldifde -f GALExportFile.ldf -s nwg-addc-a-005 -r "(&(&(& (mailnickname=) (| (&(objectCategory=person)(objectClass=user)(! extensionAttribute8=No DHS)(|(homeMDB=)(msExchHomeServerName=))) ))))" -l "objectclass,dn,cn,givenName,Initials,Sn,DisplayName,Mail,ExtensionAttribute9,StreetAddress,l,St,PostalCode,co,Title,TelephoneNumber,PhysicalDeliveryOfficeName"
 
The LDIF filter syntax for GROUPs is:
 
ldifde -f GALExportFileGROUPS.ldf -s nwg-addc-a-005 -r "(&(objectClass=Group)(mail=)(extensionAttribute8=DHS Sync))" -l "objectclass,dn,cn,name,DisplayName,Mail"
3.2.         Process Flow
These scripts run on NWG-EXVS-A-001 server in the D:\DirectoryUpload directory, although they could run successfully from any AD server provided they are in D:\DirectoryUpload.  The process is as follows:
 

  1. A scheduled task (currently at 10 pm each night) on NWG-EXVS-A-001 kicks off the following script: GALUploadv2.vbs located in D:\Directory Upload
  2. That script kicks of a ldifde export defined in CBP_DirExport.bat which produces a directory export output file called: GALExportFile.ldf.  This is an export of users.
  3. The script then kicks off a ldifde export defined in CBP_DirExportGROUPS.bat.  This is an export of Groups to include Query Based Distribution Groups into the file: GALExportFileGROUPS.ldf.
  4. The script then appends the contents of GALExportFileGROUPS.ldf to GALExportFile.ldf.
  5. The GALUploadv2.vbs script then scrubs GALExportFile.ldf to replace certain values and creates a file ready for upload.  This new file is called: export.dir
  6. GALUploadv2.vbs then FTP's the export.dir file to OSC.
  7. Finally, the script downloads the OSC log file from the previous evening's run.  This file is called:  uscs-01-exch2n.log.  It is also emailed to the CBP Postmaster account.

 
During this whole process a log file tracks the process.  The log file is:  GALExport.log
 
NOTE: If this process ever needs to be kicked off manually, it can be done by navigating to the following directory on NWG-EXVS-A-001 D:\DirectoryUpload and double-clicking on the following file:  GALUploadv2-1.vbs (or whatever the latest version is).
3.3.         Troubleshooting Individual Email Address Assignment
There are several cases where a user or other object may not properly propagate to OSC and may not successfully receive an email address.  The following items should be checked on the user's user object in Active Directory:
 

  1. Is the object a mailbox-enabled user or Group object in Active Directory (this includes group mailboxes) or a mail-enabled distribution group?  Only these types of AD objects are synchronized with Active Directory.

  2. Check the object's Custom attributes.

    1. Does extensionAttribute10 have a value?  This should be the DHS address.  If not, then the object is not receiving a DHS address.
    2. Check extensionAttribute8.  Is there a "No DHS" or "No DHS Sync" in extensionAttribute8?  If so, then the object will not synchronize with OSC.  If this is incorrect, remove the value from extensionAttribute8.  The object should synchronize that evening.
    3. If the object is a Distribution or Query-Based Distribution Group, then extensionAttribute8 must have "DHS Sync" or it will not be sent to OSC.
    4. Check extensionAttribute9 for a "GOVERNMENT" or a "CONTRACTOR" value.  Strictly speaking this value does not HAVE to be here, as OSC will assume "GOVERNMENT," but ensure the user has the proper value in extensionAttribute9.
  3. Ensure that there are no periods in the user object's name fields, to include first name, middle initial, or last name.  This will cause the creation of the "local LAN alias" value at DHS to fail.  For example:

    1. The user's last name in Active Directory is "SMITH JR." instead of "SMITH JR" (or "SMITHJR")
    2. The user's middle initial contains a period such as "A." instead of "A"
    3. The user's full name has a period in it such as "SMITH, JOHN A." instead of "SMITH, JOHN A" (strictly speaking this should not be an issue for OSC, but it does not comply with CBP standard).
    4. Use the Active Directory "rename" task to correct any of these issues.
  4. Check Lotus Notes email address versus Active Directory email address (NOTE:  This only applies to troubleshooting following the immediate conversion to Active Directory data synchronization).  If the email address in Lotus Notes is different than the value in Active Directory, OSC will treat the user as a new user and assign a new DHS address to that user.  For example:  User John A. Smith's email address is listed in Lotus Notes as JOHN.SMITH@CBP.DHS.GOV while his actual email address in Active Directory is JOHN.A.SMITH@CBP.DHS.GOV.  In this case, John Smith will receive a new DHS address as a new user once the conversion to Active Directory synchronization takes place.  Correcting this situation will require opening a help ticket with OSC.

 
The day following corrections to a user's account, check the user object and extensionAttribute10 to verify that the user received a DHS email address.  This can also be validated against the DHS White Pages.  If the user has received an improper DHS address (i.e., they lost their original email address because they fell out of synchronization), a help desk ticket should be opened with OSC.
 
3.4.         Resetting a User's DHS Address
If a user needs to have their DHS address reassigned, the process is as follows (note that this does not apply to GROUPS):
 

  1. (This is the only part of the process that requires an administrator to perform an action.  The rest of the steps are automated.)  In the USER'S Active Directory object go to Exchange Advanced tab and click on Custom Attributes.  Make extensionAttribute8 "No DHS Sync Reset" as illustrated below.

  2. That evening, the object will NOT be exported to OSC, and the user will not have a DHS address associated with their internal CBP email address.

  3. The next morning, a script will run which will update the user object to reflect no DHS address in extensionAttribute10 (to show that the user does not have a DHS address) and extensionAttribute8 will say that a reset is pending:

  4. That evening the user object will go to DHS as part of the export and should get assigned a new DHS address based on the format FN.MI.LN@DHS.GOV.

  5. The next morning the same script will update extensionAttribute8 on the user object to reflect that the DHS address was reset and extensionAttribute10 will reflect that DHS address.

 
Resetting the address of a Group is still a manual process.  An administrator should remove the "DHS Sync" from extensionAttribute8.  The next day the administrator should add "DHS Sync" back into extensionAttribute8.  This process will be automated in the near future.
 
 
4.              WEBTELE INTEGRATION script Version 1.X
CONST ForReading=1
CONST ForAppending=8
Const ADS_PROPERTY_CLEAR = 1
Const ADS_PROPERTY_UPDATE = 2
Const ADS_PROPERTY_APPEND = 3
Const ADS_PROPERTY_DELETE = 4
 
 
On Error Resume Next
 
set conn = createobject("ADODB.Connection")
set com = createobject("ADODB.Command")
Set iAdRootDSE = GetObject("LDAP://RootDSE")
 
strDefaultNamingContext = iAdRootDSE.Get("defaultNamingContext")
Conn.Provider = "ADsDSOObject"
 
Conn.Open "ADs Provider"
 
svcQuery = "<LDAP://" & strDefaultNamingContext & _
">;(&(mailnickname=EFB60MN)(objectClass=user));cn,name,objectSID"
 
'MsgBox svcQuery
 
Com.ActiveConnection = Conn
Com.CommandText = svcQuery
Set Rs = Com.Execute
 
Dim strTeleFile, strADMissing, dtFileDate, objTeleFile, objLogFile, arrayTele, inputLine, strDN, strDNSearch
Dim strLogFileName, intChangeCounter, intPersonChange, blnPersonChange, intTotalRecords, intTotalMatches, intADMissing
Dim intCountry
Dim maxChanges
 
'ADMINISTRATOR SWITCHES******************
 
'Use to set maximum number of changes
maxChanges = 1000
'Use to determine whether to update Department: 1 = Yes; 0 = No
bnlDeptUpdate=0
 
'********************************************************************************************************
 
strTelefile = "D:\FTP Data\TELE.TXT"
strLogFileName = "D:\FTP Data\teleChanges.log"
strADMissing = "D:\FTP Data\ADMissing.txt"
 
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFSOlog=CreateObject("Scripting.FileSystemObject")
Set objFSOADMissing=CreateObject("Scripting.FileSystemObject")
 
Set objTeleFile=ObjFSO.OpenTextFile(strTelefile, ForReading)
Set objLogFile=ObjFSOlog.OpenTextFile(strLogFileName, ForAppending)
Set objADMissingFile=ObjFSOADMissing.OpenTextFile(strADMissing, ForAppending)
 
objLogFile.WriteLine Now & ": Started Processing"
 
intChangeCounter = 0
intPersonChange = 0
 
Do Until objTeleFile.AtEndOfStream
If intPersonChange = maxChanges Then Exit Do
 
            intTotalRecords = intTotalRecords + 1
            blnPersonChange = 0
 
            inputLine=objTeleFile.ReadLine
 
            arrayTele=Split(inputLine,"=")
 
            'MsgBox "Hash: " & RTrim(arrayTele(0)) & " " & RTrim(arrayTele(1)) & " " & RTrim(arrayTele(8))
 
            svcQuery = "<LDAP://" & strDefaultNamingContext & _
            ">;(&(samAccountName=" & RTrim(arrayTele(0)) & ")(objectClass=user));cn, distinguishedName"
 
            'MsgBox svcQuery
 
            Com.ActiveConnection = Conn
            Com.CommandText = svcQuery
            Set Rs = Com.Execute
 
            'MsgBox Rs.Recordcount
 
            If Rs.Recordcount = 0 Then
                        If RTrim(arrayTele(17)) = "CU" Then
                                    objADMissingFile.WriteLine Now & ", " & RTrim(arrayTele(0)) & ", " & RTrim(arrayTele(5)) & ", " & RTrim(arrayTele(4)) & " " & RTrim(arrayTele(3)) & ", " & RTrim(arrayTele(2))
                        End If
                        intADMissing=intADMissing + 1
 
            Else
                        intTotalMatches=intTotalMatches+1
                        strDN=rs.fields("cn")                
                        'wscript.echo strDN
                        strDN=rs.fields("distinguishedName")
                        'wscript.echo strDN
                        'MsgBox "strDN: " & strDNSearch
 
                        'GET USER OBJECT FROM AD
                        Set objUser = GetObject ("LDAP://" & strDN)
 
'************************************************************************************************************
'CHECK FOR NEED TO CHANGE TO GOVERNMENT
                        If RTrim(arrayTele(1)) = "Y" Then
                                    If objUser.extensionAttribute9 = "CONTRACTOR" Then
                                                objUser.Put "extensionAttribute9","GOVERNMENT"
                                                objUser.SetInfo
                                                'Update log file
                                                objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Updated STATUS: GOVERNMENT"
                                                intChangeCounter=intChangeCounter + 1
                                                blnPersonChange = 1                           
                                    End If
                                    'CHECK IF BLANK
                                    If objUser.extensionAttribute9 = "" Then
                                                objUser.Put "extensionAttribute9","GOVERNMENT"
                                                objUser.SetInfo
                                                'Update log file
                                                objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Updated STATUS: GOVERNMENT"
                                                intChangeCounter=intChangeCounter + 1
                                                blnPersonChange = 1                                       
                                    End If
 
                        End If
 
'************************************************************************************************************
 
'************************************************************************************************************
'CHECK FOR NEED TO CHANGE TO CONTRACTOR
                        If RTrim(arrayTele(1))="N" Then
                                    If objUser.extensionAttribute9 = "GOVERNMENT" Then
                                                objUser.Put "extensionAttribute9","CONTRACTOR"
                                                objUser.SetInfo
                                                'Update log file
                                                objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Updated STATUS: CONTRACTOR"
                                                intChangeCounter=intChangeCounter + 1
                                                blnPersonChange = 1                                       
                                    End If
                                    'CHECK IF BLANK
                                    If objUser.extensionAttribute9 = "" Then
                                                objUser.Put "extensionAttribute9","CONTRACTOR"
                                                objUser.SetInfo
                                                'Update log file
                                                objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Updated STATUS: CONTRACTOR"
                                                intChangeCounter=intChangeCounter + 1
                                                blnPersonChange = 1                                       
                                    End If
 
                        End If
 
'************************************************************************************************************
                       
'************************************************************************************************************
'CHECK FOR TITLE CHANGE
                        If arrayTele(6)="                                      " Then
                                    Dim strTitle
                                    strTitle = ""
                                    If strtTitle <> objUser.title Then
                                                objUser.PutEx ADS_PROPERTY_CLEAR, "title", 0
                                                objUser.SetInfo
                                                'Update log file
                                                objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Deleted Title"
                                                intChangeCounter=intChangeCounter + 1
                                                blnPersonChange = 1
                                                'Set person change counter
                                    End if
                       
                        Else
                                    If RTrim(arrayTele(6)) <> objUser.title Then
                                                'MsgBox "Title Needs to Change! " & objUser.userName
                                                'Delete if Null Value
                                                If RTrim(arrayTele(6)) = "" Then
                                                            objUser.PutEx ADS_PROPERTY_CLEAR, "title", 0
                                                            objUser.SetInfo
                                                End If
                                                objUser.Put "title",RTrim(arrayTele(6))
                                                objUser.SetInfo
                                                'Update log file
                                                objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Updated Title: " & RTrim(arrayTele(6))
                                                intChangeCounter=intChangeCounter + 1
                                                blnPersonChange = 1
                                                'Set person change counter
                                    End If
                        End If
 
 
'************************************************************************************************************
 
'************************************************************************************************************
'CHECK FOR OFFICE CHANGE
                        If arrayTele(7)="        " Then
                                    Dim strOffice
                                    strOffice = ""
                                    If strtOffice <> objUser.physicalDeliveryOfficeName Then
                                                objUser.PutEx ADS_PROPERTY_CLEAR, "physicalDeliveryOfficeName", 0
                                                objUser.SetInfo
                                                'Update log file
                                                objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Deleted Office"
                                                intChangeCounter=intChangeCounter + 1
                                                blnPersonChange = 1
                                                'Set person change counter
                                    End if
                       
                        Else
                                    If RTrim(arrayTele(7)) <> objUser.physicalDeliveryOfficeName Then
                                                'MsgBox "Office Needs to Change! "& objUser.userName
                                                'Delete if Null Value
                                                If RTrim(arrayTele(7)) = "" Then
                                                            objUser.PutEx ADS_PROPERTY_CLEAR, "physicalDeliveryOfficeName", 0
                                                            objUser.SetInfo
                                                End If
                                                objUser.Put "physicalDeliveryOfficeName",RTrim(arrayTele(7))
                                                objUser.SetInfo
                                                'Update log file
                                                objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Updated Office: " & RTrim(arrayTele(7))
                                                intChangeCounter=intChangeCounter + 1
                                                blnPersonChange = 1
                                                'Set person change counter
                                    End If
                        End If
 
 
'************************************************************************************************************
 
'************************************************************************************************************
'Check for PHONE NUMBER CHANGE
 
                        If arrayTele(8)="   -   -    " Then
                                    strTelephone = ""
                                    If strTelephone <> objUser.telephoneNumber Then
                                                'Delete if Null Value
                                                objUser.PutEx ADS_PROPERTY_CLEAR, "telephoneNumber", 0
                                                objUser.SetInfo
                                                objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Deleted Telephone"
                                                intChangeCounter=intChangeCounter + 1
                                                blnPersonChange = 1
                                    End If
 
                        Else
                       
                                    strTelephone = RTrim(arrayTele(8))
                                    If RTrim(arrayTele(9)) <> "" Then strTelephone = strTelephone & " x" & RTrim(arrayTele(9))
                                    If strTelephone <> objUser.telephoneNumber Then
                                                'Delete if Null Value
                                                If strTelephone = "" Then
                                                            objUser.PutEx ADS_PROPERTY_CLEAR, "telephoneNumber", 0
                                                            objUser.SetInfo
                                                End If
                                                'MsgBox "Phone number needs to Change!"
                                                objUser.Put "telephoneNumber",strTelephone
                                                objUser.SetInfo
                                                objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Updated Telephone: " & strTelephone
                                                intChangeCounter=intChangeCounter + 1
                                                blnPersonChange = 1
                                                'Set person change counter
                                    End If
                        End If
 
 
'************************************************************************************************************
 
'************************************************************************************************************
'CHECK FOR CHANGE IN ADDRESS:  Need to check if ADDR1 or ADDR2 Changed
 
                        If arrayTele(10) = "UNKNOWN                                 " Then
                                    Dim strAddress
                                    strAddress = ""
                                                If strAddress <> objUser.streetAddress Then                           
                                                            'Delete if Null Value
                                                            objUser.PutEx ADS_PROPERTY_CLEAR, "streetAddress", 0
                                                            objUser.SetInfo
                                                            objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Deleted Address"
                                                            intChangeCounter=intChangeCounter + 1
                                                            blnPersonChange = 1
                                                            'Set person change counter
                                                End If
 
                        Else
 
                                    strAddress = RTrim(arrayTele(10))
 
                                    If IsNUll(arrayTele(11)) Then
                                                strAddress=strAddress
                                    Else
                                                If RTrim(arrayTele(11)) <> "" Then
                                                            Dim strAddress2
                                                            strAddress2 = RTrim(arrayTele(11))
                                                            strAddress = strAddress & chr(13) & chr(10) & strAddress2
                                                End If
                                    End If
                                    If strAddress <> objUser.streetAddress Then
                                                'MsgBox "Address needs to Change!"                           
                                                'Delete if Null Value
                                                If strAddress = "" Then
                                                            objUser.PutEx ADS_PROPERTY_CLEAR, "streetAddress", 0
                                                            objUser.SetInfo
                                                End If
                                                objUser.Put "streetAddress",strAddress
                                                objUser.SetInfo
                                                objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Updated Address: " & strAddress
                                                intChangeCounter=intChangeCounter + 1
                                                blnPersonChange = 1
                                                'Set person change counter      
 
                                    End If
                        strAddress=""
                        End If
 
'************************************************************************************************************
 
'************************************************************************************************************                       
'CHECK CITY
                        If arrayTele(12)="                    " Then
                                    Dim strCity
                                    strCity = ""
                                                If strCity <> objUser.l Then                              
                                                            'Delete if Null Value
                                                            objUser.PutEx ADS_PROPERTY_CLEAR, "l", 0
                                                            objUser.SetInfo
                                                            objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Deleted City"
                                                            intChangeCounter=intChangeCounter + 1
                                                            blnPersonChange = 1
                                                            'Set person change counter
                                                End If
 
                        Else                
                                    'MsgBox "AD City: " & objUser.l & "; and TeleCity: " & RTrim(arrayTele(12))
                                    If RTrim(arrayTele(12)) <> objUser.l Then
                                                'MsgBox "City Needs to Change! "& objUser.cn
                                                'Delete if Null Value
                                                If RTrim(arrayTele(12)) = "" Then
                                                            objUser.PutEx ADS_PROPERTY_CLEAR, "l", 0
                                                            objUser.SetInfo
                                                End If
                                                objUser.Put "l",RTrim(arrayTele(12))
                                                objUser.SetInfo
                                                'Update log file
                                                objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Updated City: " & RTrim(arrayTele(12))
                                                intChangeCounter=intChangeCounter + 1
                                                blnPersonChange = 1
                                                'Set person change counter
                                    End If
           
                        End If
 
 
'************************************************************************************************************
 
'************************************************************************************************************
'CHECK STATE
 
 
                        If arrayTele(13)="  " Then
                                    Dim strSt
                                    strSt = ""
                                                If strSt <> objUser.st Then                               
                                                            'Delete if Null Value
                                                            objUser.PutEx ADS_PROPERTY_CLEAR, "st", 0
                                                            objUser.SetInfo
                                                            objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Deleted State"
                                                            intChangeCounter=intChangeCounter + 1
                                                            blnPersonChange = 1
                                                            'Set person change counter
                                                End If
                        Else
                                    If RTrim(arrayTele(13)) <> objUser.st Then
                                                'MsgBox "State Needs to Change! " & objUser.cn
                                                'Delete if Null Value
                                                If RTrim(arrayTele(13)) = "" Then
                                                            objUser.PutEx ADS_PROPERTY_CLEAR, "st", 0
                                                            objUser.SetInfo
                                                End If
                                                objUser.Put "st",RTrim(arrayTele(13))
                                                objUser.SetInfo
                                                'Update log file
                                                objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Updated State: " & RTrim(arrayTele(13))
                                                intChangeCounter=intChangeCounter + 1
                                                blnPersonChange = 1
                                                'Set person change counter
                                    End If
           
                        End If
 
 
'************************************************************************************************************
 
'************************************************************************************************************
'CHECK COUNTRY
                        Dim strCountry
                        If arrayTele(14)="  " Then
                                    strCountry = ""
                                    If strCountry <> objUser.c Then
                                                'Delete if Null Value
                                                objUser.PutEx ADS_PROPERTY_CLEAR, "c", 0
                                                objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Deleted Country"
                                                intChangeCounter=intChangeCounter + 1
                                                blnPersonChange = 1
                                                'Set person change counter
                                    End If
                        Else
                                    If RTrim(arrayTele(14)) <> objUser.c Then
                                                Dim strCO
                                                Dim strCC
                                                strCountry=""
                                                'MsgBox "Country Needs to Change!"
                                                strCountry = RTrim(arrayTele(14))
                                               
                                                Select Case strCountry
                                                            Case strCountry="US"
                                                                        strCO="United States"
                                                                        strCC="840"
                                                            Case strCountry="CA"
                                                                        strCO="Canada"
                                                                        strCC="124"
                                                            Case strCountry="UK"
                                                                        strCountry="GB"
                                                                        strCO="United Kingdom"
                                                                        strCc="826"
                                                            Case strCountry="CN"
                                                                        strCO="China"
                                                                        strCc="156"
                                                            Case strCountry="NL"
                                                                        strCO="Netherlands"
                                                                        strCc="528"
                                                            Case strCountry="DE"
                                                                        strCO="Germany"
                                                                        strCc="276"                                                     
                                                            Case strCountry="IE"
                                                                        strCO="Ireland"
                                                                        strCc="372"
                                                            Case strCountry="MX"
                                                                        strCO="Mexico"
                                                                        strCc="484"
                                                            Case strCountry="IT"
                                                                        strCO="Italy"
                                                                        strCc="380"                                                     
                                                            Case strCountry="BS"
                                                                        strCO="Bahamas"
                                                                        strCc="44"
                                                            Case strCountry="BM"
                                                                        strCO="Bermuda"
                                                                        strCc="60"
                                                            Case strCountry="AW"
                                                                        strCO="Aruba"
                                                                        strCc="533"
                                                            Case strCountry="DO"
                                                                        strCO="Dominican Republic"
                                                                        strCc="214"
                                                            Case strCountry="SG"
                                                                        strCO="Singapore"
                                                                        strCC="702"
                                                            Case strCountry="JP"
                                                                        strCO="Japan"
                                                                        strCC="392"
                                                            Case strCountry="GR"
                                                                        strCO="Greece"
                                                                        strCC="300"
                                                            Case Else
                                                                        'strCountry="US"
                                                                        'strCO="United States"
                                                                        'strCC="840"
                                                End Select
 
                                                            objUser.Put "c",strCountry
                                                            objUser.Put "co",strCO
                                                            objUser.Put "countryCode",strCC
                                                            objUser.SetInfo
                                                            'Update log file
                                                            objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Updated COUNTRY: " & RTrim(arrayTele(14))
                                                            intChangeCounter=intChangeCounter + 1
                                                            blnPersonChange = 1
                                                            'Set person change counter
 
                                    End If
           
                        End If
 
 
'************************************************************************************************************
 
'************************************************************************************************************
'CHECK ZIP
 
                        If arrayTele(15) = "         " Then
                                    Dim strZIP
                                    strZIP = ""
                                                If strZIP <> objUser.postalCode Then                           
                                                            'Delete if Null Value
                                                            objUser.PutEx ADS_PROPERTY_CLEAR, "postalCode", 0
                                                            objUser.SetInfo
                                                            objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Deleted ZIP"
                                                            intChangeCounter=intChangeCounter + 1
                                                            blnPersonChange = 1
                                                            'Set person change counter
                                                End If
 
                        Else
                                    If RTrim(arrayTele(15)) <> objUser.postalCode Then
                                                'MsgBox "ZIP Needs to Change! " & objUser.cn
                                                'Delete if Null Value
                                                If RTrim(arrayTele(15)) = "" Then
                                                            objUser.PutEx ADS_PROPERTY_CLEAR, "postalCode", 0
                                                            objUser.SetInfo
                                                End If
                                                objUser.Put "postalCode",RTrim(arrayTele(15))
                                                objUser.SetInfo
                                                'Update log file
                                                objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Updated ZIP: " & RTrim(arrayTele(15))
                                                intChangeCounter=intChangeCounter + 1
                                                blnPersonChange = 1
                                                'Set person change counter
                                    End If
                        End If
 
'************************************************************************************************************
 
 
'************************************************************************************************************
'CHECK FAX
                        If arrayTele(18)="                    " Then
                                    Dim strFax
                                    strFax = ""
                                                If strFax <> objUser.facsimileTelephoneNumber Then                          
                                                            'Delete if Null Value
                                                            objUser.PutEx ADS_PROPERTY_CLEAR, "facsimileTelephoneNumber", 0
                                                            objUser.SetInfo
                                                            objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Deleted FAX"
                                                            intChangeCounter=intChangeCounter + 1
                                                            blnPersonChange = 1
                                                            'Set person change counter
                                                End If
                        Else
                                    If RTrim(arrayTele(18)) <> objUser.facsimileTelephoneNumber Then
                                                'MsgBox "FAX Needs to Change! " & objUser.cn
                                                'Delete if Null Value
                                                If RTrim(arrayTele(18)) = "" Then
                                                            objUser.PutEx ADS_PROPERTY_CLEAR, "facsimileTelephoneNumber", 0
                                                            objUser.SetInfo
                                                End If
                                                objUser.Put "facsimileTelephoneNumber",RTrim(arrayTele(18))
                                                objUser.SetInfo
                                                'Update log file
                                                objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Updated FAX: " & RTrim(arrayTele(18))
                                                intChangeCounter=intChangeCounter + 1
                                                blnPersonChange = 1
                                                'Set person change counter
                                    End If  
                        End If
 
 
'************************************************************************************************************
 
'************************************************************************************************************
'MAKE COMPANY CBP
                        Dim strCompany
                        strCompany= "CBP"
                        If objUser.company <> strCompany Then
                                    objUser.Put "company", strCompany
                                    objUser.SetInfo
                                    objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Updated Company"
                        End If
 
 
'************************************************************************************************************
                       
'************************************************************************************************************
'CHECK MOBILE - CURRENTLY DISABLED
                        'If IsNull(arrayTele(19)) Then
                        '           Dim strMobile
                        '           strMobile = ""
                        '           If strMobile <> objUser.Mobile Then                             
                        '                       'Delete if Null Value
                        '                       objUser.PutEx ADS_PROPERTY_CLEAR, "Mobile", 0
                        '                       objUser.SetInfo
                        '                       objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Deleted Mobile"
                        '                       intChangeCounter=intChangeCounter + 1
                        '                       blnPersonChange = 1
                        '                       'Set person change counter
                        '           End If
 
                        'Else
                                    'If RTrim(arrayTele(19)) <> objUser.mobile Then
                                                'MsgBox "Mobile Needs to Change!"
                                                'Delete if Null Value
                                                'If RTrim(arrayTele(19)) = "" Then
                                                            'objUser.PutEx ADS_PROPERTY_CLEAR, "mobile", 0
                                                            'objUser.SetInfo
                                                'End If
                                                'objUser.Put "mobile",RTrim(arrayTele(19))
                                                'objUser.SetInfo
                                                'Update log file
                                                'objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Updated Mobile: " & RTrim(arrayTele(19))
                                                'intChangeCounter=intChangeCounter + 1
                                                'blnPersonChange = 1
                                                'Set person change counter
                                    'End If
                        'End If
 
 
'************************************************************************************************************
 
'************************************************************************************************************
'CHECK Org Code
                        If IsNull(arrayTele(16)) Then
                                    Dim strOrgCode
                                    strOrgCode = ""
                                                If strOrgCode <> objUser.extensionAttribute4 Then                              
                                                            'Delete if Null Value
                                                            objUser.PutEx ADS_PROPERTY_CLEAR, "extensionAttribute4", 0
                                                            objUser.SetInfo
                                                            objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Deleted ORG CODE"
                                                            intChangeCounter=intChangeCounter + 1
                                                            blnPersonChange = 1
                                                            'Set person change counter
                                                End If
                        Else
                                    If RTrim(arrayTele(16)) <> objUser.extensionAttribute4 Then
                                                'MsgBox "FAX Needs to Change! " & objUser.cn
                                                'Delete if Null Value
                                                If RTrim(arrayTele(16)) = "" Then
                                                            objUser.PutEx ADS_PROPERTY_CLEAR, "extensionAttribute4", 0
                                                            objUser.SetInfo
                                                End If
                                                objUser.Put "extensionAttribute4",RTrim(arrayTele(16))
                                                objUser.SetInfo
                                                'Update log file
                                                objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Updated ORG CODE: " & RTrim(arrayTele(16))
                                                intChangeCounter=intChangeCounter + 1
                                                blnPersonChange = 1
                                                'Set person change counter
                                    End If  
                        End If
 
'************************************************************************************************************
 
'************************************************************************************************************
'CHECK DEPARTMENT
                        If bnlDeptUpdate=1 Then                      
                                    Dim strDepartmentCode1
                                    Dim strDepartmentCode
                                    Dim strTeleDept
                                    Dim strDepartment
                       
 
                                    strDepartmentCode1=objUser.extensionAttribute4
                                    strDepartmentCode=Left(strDepartmentCode1,2)
                                    'MsgBox strDepartmentCode
                                    'strDepartmentCode1=CStr(strDepartmentCode)
                                    Select Case strDepartmentCode
                                                            Case "01"
                                                                        strTeleDept="OFFICE OF THE COMMISSIONER"
                                                            Case "02"
                                                                        strTeleDept="OFFICE OF THE CHIEF COUNSEL"
                                                            Case "04"
                                                                        strTeleDept="OFFICE OF INVESTIGATIONS"                                                           
                                                            Case "07"
                                                                        strTeleDept="OFC OF INTERNAL AFFAIRS"
                                                            Case "08"
                                                                        strTeleDept="OFC INTRNTNL AFFRS & TRD RLTS"
                                                            Case "11"
                                                                        strTeleDept="OFFICE OF HUMAN RESOURCES MGMT"
                                                            Case "12"
                                                                        strTeleDept="OFFICE OF CONGRESSIONAL AFFAIR"
                                                            Case "13"
                                                                        strTeleDept="OFFICE OF FIELD OPERATIONS"
                                                                        'MsgBox strTeleDept
                                                            Case "16"
                                                                        strTeleDept="OFFICE OF FINANCE (CFO)"
                                                            Case "18"
                                                                        strTeleDept="OFFICE OF TRAINING/DEVELOPMENT"
                                                            Case "19"
                                                                        strTeleDept="OFFICE OF PUBLIC AFFAIRS"
                                                            Case "22"
                                                                        strTeleDept="AC, CBP AIR AND MARINE"
                                                            Case "23"
                                                                        strTeleDept="OIT"
                                                            Case "24"
                                                                        strTeleDept="OFFICE OF INTERNATIONAL TRADE"
                                                            Case "80"
                                                                        strTeleDept="OFC OF ASSET FORFEITURE MGT"
                                                            Case "95"
                                                                        strTeleDept="OFFICE OF BORDER PATROL"
                                                            Case Else
                                                                        strTeleDept=""
                                    End Select
                                                'MsgBox strTeleDept               
 
                                                If strTeleDept <> objUser.department Then                              
                                                            objUser.Put "department", strTeleDept
                                                            objUser.SetInfo
                                                            objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Updated DEPT: " & strTeleDept
                                                            intChangeCounter=intChangeCounter + 1
                                                            blnPersonChange = 1
                                                            'Set person change counter
                                                End If
                        End If
'************************************************************************************************************
 
 
'************************************************************************************************************
'CHECK Update Date
                        If IsNull(arrayTele(20)) Then
                                    Dim strUpdateDate
                                    strUpdateDate = ""
                                                If strUpdateDate <> objUser.extensionAttribute2 Then                          
                                                            'Delete if Null Value
                                                            objUser.PutEx ADS_PROPERTY_CLEAR, "extensionAttribute2", 0
                                                            objUser.SetInfo
                                                            objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Deleted UPDATE DATE"
                                                            intChangeCounter=intChangeCounter + 1
                                                            blnPersonChange = 1
                                                            'Set person change counter
                                                End If
                        Else
                                    If RTrim(arrayTele(20)) <> objUser.extensionAttribute2 Then
                                                'MsgBox "Update Date Needs to Change! " & objUser.cn
                                                'Delete if Null Value
                                                If RTrim(arrayTele(20)) = "" Then
                                                            objUser.PutEx ADS_PROPERTY_CLEAR, "extensionAttribute2", 0
                                                            objUser.SetInfo
                                                End If
                                                objUser.Put "extensionAttribute2",RTrim(arrayTele(20))
                                                objUser.SetInfo
                                                'Update log file
                                                objLogFile.WriteLine Now & ": " & RTrim(arrayTele(0)) & ": Updated UPDATE DATE: " & RTrim(arrayTele(20))
                                                intChangeCounter=intChangeCounter + 1
                                                blnPersonChange = 1
                                                'Set person change counter
                                    End If  
                        End If
 
'************************************************************************************************************
'If user record changed then count toward max changes.
                        If blnPersonChange = 1 Then
                                    intPersonChange=intPersonChange + 1
                        End If
'************************************************************************************************************
 
            End If
 
'************************************************************************************************************
 
Loop
 
            objLogFile.WriteLine Now & ": " & "Total Records Changed = " & intPersonChange & "; Total Changes: " & intChangeCounter & " Total Records: " & intTotalRecords & " Total Matches: " & intTotalMatches
'           MsgBox "Total Records Changed = " & intPersonChange & "; Total Changes: " & intChangeCounter & " Total Records: " & intTotalRecords & " Total Matches: " & intTotalMatches
 
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "DIRECTORY CHANGES SUMMARY for " & NOW
objMessage.From = "postmaster@cbp.dhs.gov"
objMessage.To = "rob.craig@cbp.dhs.gov"
objMessage.TextBody = "Records Checked:" & intTotalRecords & "; AD Matches:" & intTotalMatches & "; Records Changed: " & intPersonChange & "; Total Changes: " & intChangeCounter & "; Missing: " & intADMissing
objMessage.Send
 
 
            objTeleFile.Close
            objLogFile.Close
            objADMissingFile.Close
            Set ObjFSOlog = Nothing
            Set ObjFSOADMissing = Nothing
            set fso = nothing
            set conn = nothing
            set com = nothing
 
 
5.              OSC Directory integration script Version 2.X
 
 
'Global Address List Export
'Darren Castro, Northrop-Grumman, ITSG 2/1/2007
'Modified for CBP by ROB CRAIG on 12/1/2007
'
'The purpose of this script is to read the Global Address List Active Directory and export that list to OSC Environment.
'The search script will execute as follows:
 
'Create a LOG file.
'An event description will be written to the log file as each sequence is completed.
'An event description will be written to the log file as DN sequence is completed.
 
'Execute the LDIFDE DOS command to create the initial export file.
'Write event to LOG file.
 
'Create a new (empty) export file.
'Write event to LOG file.
 
'Open LDIF data file and read each LINE.
'If LINE begins with DN then Parse DN and create new DN
'Write new DN to export file.
'Write event to LOG file.
 
'If LINE does not begin with DN then write LINE to export file.
'Continue with each LINE until End Of File.
'Write EOF event to LOG file.
 
'Transfer the export file to OSC.
'Write event to LOG file.
 
Option Explicit
 
Dim strGALLogFile, strMaintMode, strGALExportFile, strGALUploadFile, strGALGroupsFile, strOLDLine, strTextLine, strNEWDN, strDownLoadSuccess
Dim strFTPServerIP, strFTPUserName, strFTPPassword, strNewClass, blnstrNewClass, strNewExtensionAttribute9, intGroups, strCN
Dim UserCount, SkipLine
Dim arrDN
Dim objGALLogFile, objGALExportFile, objGALUploadFile, objGALGroupsFile 'File Names Created/Read/Modified
Dim objfso 'FileSystemObject
Dim WshShell 'Windows Scripting Host Shell (DOS) Operations
 
Const ForAppending = 8
Const ForReading = 1
 
UserCount = 0
SkipLine = 0
 
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
'*************************************************************************************
strMaintMode = 0 'Script DeBug/Maintenance Mode 1=Echo Messages 0=Do Not Echo Messages
'*************************************************************************************
 
If strMaintMode=1 Then On Error Resume Next
If strMaintMode=1 Then Wscript.Echo "DeBug/Maintenance Mode ON"
If strMaintMode=1 Then Wscript.Echo "Go"
 
'********************************************************************************************************************************
strGALLogFile="D:\DirectoryUpload\GALExport.log"      'Name of LOG file
strGALExportFile="D:\DirectoryUpload\GALExportFile.ldf"          'Name of LDIF file to READ.  This file name must be SAME as file name in CBP_DirExport.bat
strGALUploadFile="D:\DirectoryUpload\export.dir"         'Name of (modified) file to create/upload to OSC
strGALGroupsFile="D:\DirectoryUpload\GALExportFileGROUPS.ldf" 'Name of Groups File
'********************************************************************************************************************************
 
If strMaintMode=1 Then Wscript.Echo "strGALLogFile: " & strGALLogFile
 
'Create a LOG file
Set objGALLogFile = objFSO.CreateTextFile(strGALLogFile)
objGALLogFile.Close
 
If strMaintMode=1 Then Wscript.Echo "LogFile created: " & strGALLogFile
 
If objFSO.FileExists(strGALLogFile) Then
'Write log event LOG file created
Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
            objGALLogFile.Write (NOW & " Log File: " & strGALLogFile & " created." & VBCrLF)
                        objGALLogFile.Close
Else
'Create Log File Failed - End Script       
WScript.quit
End If
 
If objFSO.FileExists("D:\DirectoryUpload\CBP_DirExport.bat") Then
'Write log LDIF Batch file found.
Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
            objGALLogFile.Write (NOW & " LDIFDE batch file: " & "D:\DirectoryUpload\CBP_DirExport.bat" & " found." & VBCrLF)
                        objGALLogFile.Close
Else
'Write log LDIF Batch file NOT found. End Script
Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
            objGALLogFile.Write (NOW & " LDIFDE batch file: " & "D:\DirectoryUpload\CBP_DirExport.bat" & " NOT found." & VBCrLF)
            objGALLogFile.Write (NOW & " Script Abortedted.")
                        objGALLogFile.Close
WScript.quit
End If
 
'Execute LDIFDE DOS command to create initial export file.
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.run "D:\DirectoryUpload\CBP_DirExport.bat", 1, true 'Run the batch file to execute LDIFDE
 
If objFSO.FileExists(strGALExportFile) Then
'Write log event LDIF Export file created
Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
            objGALLogFile.Write (NOW & " " & "Export file: " & strGALExportFile & " created." & VBCrLF)
                        objGALLogFile.Close
Else
'Write log event LDIF Export file NOT created
Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
            objGALLogFile.Write (NOW & " " & "Export file: " & strGALExportFile & " NOT created." & VBCrLF)
            objGALLogFile.Write (NOW & " Script Aborted.")
                        objGALLogFile.Close   
WScript.Quit
 
End If
 
'NEW
 
'1. Create Groups File
'2. Read one line at a time from CBP_DIRExportGroups.bat and Append to strGALExportFile
'3. Write to log file number of entries appended
'4. Close file
 
 
'1. Execute LDIFDE DOS command to create GROUPS export file
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.run "D:\DirectoryUpload\CBP_DirExportGROUPS.bat", 1, true 'Run the batch file to execute LDIFDE
 
'LOG Creation of File
If objFSO.FileExists(strGALGroupsFile) Then
'Write log event LDIF Export file created
Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
            objGALLogFile.Write (NOW & " " & "Export file: " & strGALGroupsFile & " created." & VBCrLF)
                        objGALLogFile.Close
Else
'Write log event LDIF Export file NOT created
Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
            objGALLogFile.Write (NOW & " " & "Export file: " & strGALGroupsFile & " NOT created." & VBCrLF)
            objGALLogFile.Write (NOW & " Script Aborted.")
                        objGALLogFile.Close   
WScript.Quit
 
End If
 
'2. Read line by line from strGALGroupsFile and write to strGALExportFile
 
 
set objGALGroupsFile = objFSO.OpenTextFile(strGALGroupsFile, 1)
Set objGALExportFile = objFSO.OpenTextFile(strGALExportFile, ForAppending, True)
Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
 
Do Until objGALGroupsFile.AtEndOfStream
            strTextLine = objGALGroupsFile.ReadLine
            If intGroups=0 Then
                        intGroups=intGroups+1
            Else
                        If Instr(strTextLine, "dn:") Then
                                    intGroups = intGroups + 1
                        Else
                                    If Instr(strTextLine, "cn:") Then
                                                strCN=Mid(strTextLine,4)
                                    End If
 
                        End If
                        If Instr(strTextLine, "cn:") Then
                                    objGALExportFile.Write (strTextLine & VBCrLF)
                                    objGALExportFile.Write ("sn:" & strCN & VBCrLF)
                        Else
                                    objGALExportFile.Write (strTextLine & VBCrLF)
                        End If
            End If
 
Loop
intGroups = intGroups-1
 
'3. Log Groups created
objGALLogFile.Write (NOW & " " & intGroups & " Groups Written.")
'4. CLose Files
objGALLogFile.Close
objGALGroupsFile.Close
objGALExportFile.Close
 
 
'NEW
 
'Create Upload File
Set objGALUploadFile = objFSO.CreateTextFile(strGALUploadFile)
objGALUploadFile.Close
 
If strMaintMode=1 Then Wscript.Echo "UploadFile created: " & strGALUploadFile
 
If objFSO.FileExists(strGALUploadFile) Then
'Write log event Upload file created
Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
            objGALLogFile.Write (NOW & " Upload File: " & strGALUploadFile & " created. " & VBCrLF)
                        objGALLogFile.Close
Else
'Write log event Upload file NOT created
Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
            objGALLogFile.Write (NOW & " Upload File: " & strGALUploadFile & " NOT created.  Script Aborted. " & VBCrLF)
                        objGALLogFile.Close
WScript.Quit
End If
           
'Open LDIF Export file
Set objGALExportFile = objFSO.OpenTextFile(strGALExportFile, 1)
 
'Write log event Opening LDIF Export file for processing
Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
objGALLogFile.Write (NOW & " Open " & strGALExportFile & " for proccessing" & VBCrLF)
'objGALLogFile.Close
Set objGALUploadFile = objFSO.OpenTextFile(strGALUploadFile, ForAppending, True)
 
 
Do Until objGALExportFile.AtEndOfStream
    strOLDLine = objGALExportFile.ReadLine
                        If InStr(strOLDLine, "SystemMailbox") Then
                                    'Write log event SystemMailbox will not be uploaded.
                        'Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
                        objGALLogFile.Write (NOW & " " & strOLDLine & " account will not be uploaded." & VBCrLF)
                                    'objGALLogFile.Close
                                    SkipLine=1
                        Else If StrOLDLine = "" Then
                                    SkipLine=0
                        End If
                        End If
                       
                        If SkipLine=0 Then                   
                        If strOLDLine <> "" Then
                                                            If InStr(strOLDLine, "dn:") Then
                                                            'Write log event processing old DN:
                                                            'Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
                                                            objGALLogFile.Write (NOW & " Processing OLD " & strOLDLine & VBCrLF)
                                                                        'objGALLogFile.Close
                                                                       
                                                                        'PARSE THE LINE NAME INFO
                                                                                    arrDN = split(strOLDLine, ",")
 
                                                                                    If InStr(arrDN(1), "OU=") Then
                                                                                                strNEWDN = arrDN(0) & ",DC=CBPexch,DC=CBP,DC=dhs,DC=gov"
                                                                                    Else
                                                                                                strNEWDN = arrDN(0) & "," & arrDN(1) & ",DC=CBPexch,DC=CBP,DC=dhs,DC=gov"
                                                                                    End If                                                     
                       
                                                                        'Write line to GALUploadFile
                                                                                    If UserCount>0 Then
                                                                                                'Set objGALUploadFile = objFSO.OpenTextFile(strGALUploadFile, ForAppending, True)
                                                                                                objGALUploadFile.Write (VBCrLF)
                                                                                                'objGALUploadFile.Close
                                                                                    End If
                                                           
                                                                        'Set objGALUploadFile = objFSO.OpenTextFile(strGALUploadFile, ForAppending, True)
                                                                        objGALUploadFile.Write (strNEWDN & VBCrLF)
                                                                        'objGALUploadFile.Close
                                                                                                                                               
                                                                        'WRITE DN: & NAME INFO & OCCONUS DOM INFO TO GALLogfile as an event
                                                                        'Write log event processed NEW DN:
                                                                        'Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
                                                                        objGALLogFile.Write (NOW & " Processed NEW " & strNEWDN & VBCrLF)
                                                                        'objGALLogFile.Close
           
                                                                        UserCount=UserCount+1
                                                                                   
                                                            Else
                                                                        'CHECK TO SEE IF OBJECTCLASS=GROUP or msExchDynamicDistributionList
 
                                                                        If InStr(strOldLine, "objectClass: msExch") Then
                                                                                    'CHANGE TO:  "objectClass: user"
                                                                                    strNewClass = "objectClass: user"
                                                                                    'WRITE LOG EVENT CHANGING OBJECT CLASS:
                                                                                    'Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
                                                                                    objGALLogFile.Write (NOW & " Processing OLD " & strOLDLine & VBCrLF)
                                                                                    'objGALLogFile.Close
                                                                       
                                                                                    If UserCount>0 Then
                                                                                                'Set objGALUploadFile = objFSO.OpenTextFile(strGALUploadFile, ForAppending, True)
                                                                                                'objGALUploadFile.Write (VBCrLF)
                                                                                                'objGALUploadFile.Close
                                                                                    End If
                                                           
                                                                                    'Set objGALUploadFile = objFSO.OpenTextFile(strGALUploadFile, ForAppending, True)
                                                                                    objGALUploadFile.Write (strNewClass & VBCrLF)
                                                                                    'objGALUploadFile.Close
                                                                         
                                                                                    'Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
                                                                                    objGALLogFile.Write (NOW & " Processed NEW Class " & strNewClass & VBCrLF)
                                                                                    'objGALLogFile.Close
                                                                                    blnstrNewClass = 1
                                                                        End If
 
                                                                        If InStr(strOLDLine, "objectClass: group") Then
                                                                                    'CHANGE TO:  "objectClass: user"
                                                                                    strNewClass = "objectClass: user"
                                                                                    'WRITE LOG EVENT CHANGING OBJECT CLASS:
                                                                                    'Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
                                                                                    objGALLogFile.Write (NOW & " Processing OLD " & strOLDLine & VBCrLF)
                                                                                    'objGALLogFile.Close
                                                                       
                                                                                    If UserCount>0 Then
                                                                                                'Set objGALUploadFile = objFSO.OpenTextFile(strGALUploadFile, ForAppending, True)
                                                                                                'objGALUploadFile.Write (VBCrLF)
                                                                                                'objGALUploadFile.Close
                                                                                    End If
                                                           
                                                                                    'Set objGALUploadFile = objFSO.OpenTextFile(strGALUploadFile, ForAppending, True)
                                                                                    objGALUploadFile.Write (strNewClass & VBCrLF)
                                                                                    'objGALUploadFile.Close
                                                                         
                                                                                    'Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
                                                                                    objGALLogFile.Write (NOW & " Processed NEW Class " & strNewClass & VBCrLF)
                                                                                    'objGALLogFile.Close
                                                                                    blnstrNewClass = 1
 
                                                                        Else
                                                                                    If InStr(strOLDLine, "extensionAttribute9: CONTRACTOR") Then
                                                                                                'CHANGE TO:  "extensionAttribute9: CTR"
                                                                                                strNewExtensionAttribute9="extensionAttribute9: CTR"
                                                                                                objGALUploadFile.Write (strNewExtensionAttribute9 & VBCrLF)
                                                                                                objGALLogFile.Write (NOW & " Changing to: " & strNewExtensionAttribute9 & VBCrLF)
                                                                                                blnstrNewClass = 1
 
                                                                                    End If
 
                                                                        End If
 
 
                                                                        'Write line to GALUploadFile
                                                                        If blnstrNewClass = 0 Then
                                                                                    'Set objGALUploadFile = objFSO.OpenTextFile(strGALUploadFile, ForAppending, True)
                                                                                    objGALUploadFile.Write (strOLDLine & VBCrLF)
                                                                                    'objGALUploadFile.Close
                                                                        End If
                                                                        blnstrNewClass = 0
 
                                                                       
                                                            End If
                                                           
 
                        End If
            End If
Loop
 
 
objGALExportFile.Close
objGALLogFile.Close
objGALUploadFile.Close
'Write log event Closing LDIF Export file processing complete
Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
objGALLogFile.Write (NOW & " Closing " & strGALExportFile & " proccessing completed" & VBCrLF)
objGALLogFile.Write (NOW & " " & UserCount & " Users Processed" & VBCrLF)
objGALLogFile.Close
 
'BEGIN FTP
'Find Upload File
If objFSO.FileExists(strGALUploadFile) Then
'Write log event Upload file found
Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
            objGALLogFile.Write (NOW & " " & "Upload file: " & strGALUploadFile & " found." & VBCrLF)
                        objGALLogFile.Close
Else
'Write log event GAL Upload file NOT found
Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
            objGALLogFile.Write (NOW & " " & "Upload file: " & strGALExportFile & " NOT found." & VBCrLF)
            objGALLogFile.Write (NOW & " Script Aborted.")
                        objGALLogFile.Close   
WScript.Quit
End If
 
'
'Execute FTP DOS command to upload file.
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "ftp -s:D:\DirectoryUpload\FTPUploadDirectory.txt", 1, True 'FTP PUT the Upload File
 
'Write log FTP command to Upload file completed.
Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
            objGALLogFile.Write (NOW & " " & "Attempted to upload " & strGALUploadFile & VBCrLF)
                        objGALLogFile.Close
 
'Execute FTP DOS command to get OSC log file.
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "ftp -s:D:\DirectoryUpload\FTPGetOSCLog.txt", 1, True 'FTP GET the Log File
 
'Write log FTP command to Download OSC log file completed.
If objFSO.FileExists("D:\DirectoryUpload\uscs-01-exch2n.log") Then
Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
            objGALLogFile.Write (NOW & " OSC log file: " & "D:\DirectoryUpload\uscs-01-exch2n.log" & " downloaded." & VBCrLF)
            strDownLoadSuccess = "Log File successfully downloaded. "    
            objGALLogFile.Close
Else
'Write OSC NOT found. End Script
Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
            objGALLogFile.Write (NOW & " OSC Log File: " & "D:\DirectoryUpload\uscs-01-exch2n.log" & " NOT downloaded." & VBCrLF)
                        objGALLogFile.Write (NOW & " Script Aborted.")
                        strDownLoadSuccess="Log File NOT DOWNLOADED. "
                        objGALLogFile.Close
End If
 
Set objGALLogFile = objFSO.OpenTextFile(strGALLogFile, ForAppending, True)
            objGALLogFile.Write (NOW & " Script Completed.")
                        objGALLogFile.Close
 
'
*****************************************
'Cycle through log file to identify status from DHS
 
If objFSO.FileExists("D:\DirectoryUpload\uscs-01-exch2n.log") Then
 
            Dim strDHSStatus, strOSCLogfile, strInputLine
            Dim strInputLine1, strInputLine2, strInputLine3, strInputLine4, strInputLine5, strInputLine6
            Dim objOSCLogFile
 
            strOSCLogfile = "D:\DirectoryUpload\uscs-01-exch2n.log"
 
            'Cycle through file until the line is found:
 
            Set objOSCLogFile=ObjFSO.OpenTextFile(strOSCLogfile, ForReading)
 
            Do Until objOSCLogFile.AtEndOfStream
                        strInputLine=objOSCLogFile.ReadLine
 
                        If Instr(strInputLine, "Dirsync Statistics") Then
                                    strInputLine1 = strInputLine
                        End If
                       
                        If Instr(strInputLine, "Start time:") Then
                                    strInputLine2 = strInputLine
                        End If
 
                        If Instr(strInputLine, "End time:") Then
                                    strInputLine3 = strInputLine
                        End If
 
                        If Instr(strInputLine, "X500 adds:") Then
                                    strInputLine4 = strInputLine
                        End If
 
                        If Instr(strInputLine, "Lan entries") Then
                                    strInputLine5 = strInputLine
                        End If
 
                        If Instr(strInputLine, "Informational messages:") Then
                                    strInputLine6 = strInputLine
                        End If
 
            Loop
 
            strDHSStatus = strInputLine1 & VBCrLF & strInputLine2 & VBCrLF & strInputLine3 & VBCrLF & strInputLine4 & VBCrLF & strInputLine5 & VBCrLF & strInputLine6
 
'12-12-2007. 0:58:31 DHSExch2000toX500-21764: (uscs-01-exch2n) Dirsync Statistics:
'12-12-2007. 0:58:31 DHSExch2000toX500-21764: (uscs-01-exch2n) -- Start time: 12-12-2007. 0:51:21
'12-12-2007. 0:58:31 DHSExch2000toX500-21764: (uscs-01-exch2n) -- End time: 12-12-2007. 0:58:31
'12-12-2007. 0:58:31 DHSExch2000toX500-21764: (uscs-01-exch2n) -- X500 adds: 104, X500 deletes: 11, X500 modifies: 6, X500 nochange: 59394
'12-12-2007. 0:58:31 DHSExch2000toX500-21764: (uscs-01-exch2n) -- Lan entries not processed: 473
'12-12-2007. 0:58:31 DHSExch2000toX500-21764: (uscs-01-exch2n) -- Informational messages: 74
 
Else
            'File Not Found -- Error!
            strDHSStatus = "No log file found!"       
 
End If
 
'*************************************************************************************
 
'*************************************************************************************
'Send EMAIL of STATUS to ADMINISTRATOR
Dim objMessage
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Directory Upload Status for: " & NOW
objMessage.From = "cbppostmaster@cbp.dhs.gov"
objMessage.To = "rob.craig@cbp.dhs.gov"
objMessage.TextBody = "Status: " & strDownLoadSuccess & UserCount & " Records Uploaded." & VBCrLF & strDHSStatus
objMessage.Send
'*************************************************************************************
 
 
 
If strMaintMode=1 Then Wscript.Echo "Stop" > From <https://uconnect.cbpnet.cbp.dhs.gov/sites/OIT/edme/edco/dco/osg/WSG%20Wiki/WebTele%20AD%20Integration%20Documentation.aspx>