home *** CD-ROM | disk | FTP | other *** search
- // GTGROUP.SCP - Sample Script which reads from GROUP.NSM
- // Copyright (c) 2001-2002, Vector Networks Limited.
- // All Rights Reserved
- //
- // Revision History:
- // 7.0 20-Mar-02 DB - Separated from GRPFLUPD.SCP.
-
- // GetGroup is used to retrieve full details of all Clients in a named Group
- // from the Known Clients Group file, GROUP.NSM, returning the results
- // in a list. There are no built-in functions to do this directly apart from
- // GetClientsInGroup, and that does not return full details (i.e. the network).
- //
- // The GROUP.NSM file is in the following format:-
- // GroupName|Description|Members
- // Client1Name|Address|Transport|Location|LocationName
- //
- // Groups are separated by a blank line. We distinguish the various lines
- // using their length and number of tokens.
- //
- // The Client details line matches the equivalent data in CLIENT.NSM, though
- // it is a subset of that information.
-
- Function GetGroup (Group as String, Profile as String) as List
- Dim GroupName as String, GroupFile as String, Line as String
- Dim Handle, Lines, Tokens, GroupList as List, SplitLine as List
- Dim CurrentGroup as String, ClientCount
-
- // Initialise counter variables
-
- ClientCount = 0
-
- If Len (Group) > 0 Then
- Print "Searching for Group : ", Group
-
- // Now, we look it up in the GROUP.NSM file.
-
- GroupFile = GetControlFile ("GROUP.NSM", Profile)
-
- If (FileExists (GroupFile)) Then
- Handle = Open (GroupFile, FILE_READ)
-
- If Handle !=0 Then
- Print "Reading file " + GroupFile + "..."
- Print "File handle: ", Handle
-
- Lines = 0
-
- Do Until EOF (Handle)
- Line = ReadLine (Handle)
- Lines = Lines + 1
- Print "Line ", Lines, " <", Line, ">"
-
- If Trim (Line) != "" Then
- SplitLine = TokenList (Line, "|")
- If Items (SplitLine) = 3 Then
- CurrentGroup = GetItem (SplitLine, 1)
- If (ClientCount) > 0 Then
- Print "End of Group : ", Group
- Exit Do
- Else
- Print "Reading Group : ", CurrentGroup
- Endif
- Endif
- If Items (SplitLine) > 4 Then
- If (CurrentGroup = Group) Then
- Print "Adding : ", Line
- AddItem (GroupList, Line)
- ClientCount = ClientCount + 1
- Else
- Print "Skipping : ", Line
- Endif
- Endif
- Else
- Print "Skipping blank line"
- Endif
- Loop
-
- Print "Summary"
- Print Lines, " lines processed"
- If (ClientCount > 0) Then
- Print "Group : ", Group, " contains ", Items (GroupList), " Clients."
- Else
- Print "Group : ", Group, " was not found or contains no Clients."
- Endif
- Close (Handle)
- Endif
- Else
- Print "ERROR: Unable to open Group file : ", GroupFile
- Endif
- Else
- // No Group name provided
- Endif
-
- GetGroup = GroupList
- End Function
-