home *** CD-ROM | disk | FTP | other *** search
- // HOSTNAME.SCP - Sample Script which updates the CLIENT.NSM file so that
- // it can be used in a DHCP environment with the Control's Connect by Hostname
- // Copyright (c) 2000, Vector Networks Limited
- // All Rights Reserved
- //
- // Revision History:
- // 5.3 19-Jul-00 AB - Created.
- // 25-Jul-00 DB - Remove $INCLUDE "RINSTR.SCP" to GTCTLDIR.SCP
- // 03-Aug-00 DB - Fix the problem incrementing integers by not DIMming the
- // variables as Integers.
- // 6.0 12-Oct-00 DB - Add $INCLUDE "PARSE.SCP" and "RINSTR.SCP"
- // 13-Oct-00 DB - Move ReadLine inside Do Until EOF loop
-
- // This Script reads the Control's CLIENT.NSM file, updating the addresses of any
- // TCP/IP Clients to include the Client Name as a Hostname using the format:
- // <client_name>|<ip_address> (<client_name>)|....
-
- $INCLUDE "GTCTLFL.SCP"
- $INCLUDE "PARSE.SCP"
- $INCLUDE "RINSTR.SCP"
- $INCLUDE "TOKENS.SCP"
-
- Function Main ()
- Dim Profile as String, ControlDir as String
- Dim ClientFile as String, NewFile as String, BackupFile as String
- Dim Handle, Line, Name, SplitLine as List, IP, x, y
- Dim ChangedLines, Lines, Loc as Integer
-
- Lines = 0
- ChangedLines = 0
-
- ControlDir = GetControlDir ()
-
- // ClientFile = Trim (GetControlFile ("CLIENT.NSM", Profile))
- ClientFile = GetControlFile ("CLIENT.NSM", Profile)
-
- Print "Target Client file: ", ClientFile
-
- Loc = RInStr (ClientFile, "\")
- NewFile = Left (ClientFile, Loc) + "client.new"
- BackupFile = Left (ClientFile, Loc) + "client.old"
-
- Print "Control directory: ", ControlDir
- Print "Temporary file: ", NewFile
- Print "Backup file name: ", BackupFile
-
- Handle = Open (ClientFile, FILE_READ)
-
- If Handle !=0 Then
- Print "Reading file " + ClientFile + "..."
- Print "File handle: ", Handle
-
- If FileExists (NewFile) then
- Print "Overwriting file ", NewFile
- Handle2 = Open (NewFile, FILE_OVERWRITE)
- Else
- Print "Creating file ", NewFile
- Handle2 = Open (NewFile, FILE_CREATE)
- Endif
-
- If Handle2 !=0 Then
- Print "File handle: ", Handle2
-
- do until EOF(Handle)
- Line = ReadLine (Handle)
- Lines = Lines + 1
- Print "Line ", Lines, " <", Line, ">"
-
- If Trim (Line) != "" Then
- SplitLine = TokenList (Line, "|")
- If Items (SplitLine) < 5 Then
- Print "ERROR: Insufficient tokens found in line ", Lines, ":"
- For Each Token in SplitLine
- Print Token
- Next
- Exit Function
- Endif
-
- Name = GetItem (SplitLine, 1)
- IP = GetItem (SplitLine, 2)
- Trans = GetItem (SplitLine, 3)
- Loc = GetItem (SplitLine, 4)
- Net = GetItem (SplitLine, 5)
-
- If Trans = "2" AND Loc = "0" AND Net = "Local" AND InStr (IP, " (", IGNORECASE) = 0 then
- Print "Correcting: ", Name, " Address: ", IP
- IP = IP + " (" + Name + ")"
- Print "New address: ", IP
- ChangedLines = ChangedLines + 1
- Else
- Print "Skipping Client: ", Name
- Endif
-
- Line = Name + "|" + IP
-
- y = Items (SplitLine)
- For x = 3 to y
- Line = Line + "|" + GetItem (SplitLine, x)
- Next
-
- WriteLine Handle2, Line
- Endif
- Loop
-
- Close (Handle2)
- Endif
-
- Close (Handle)
-
- If FileExists (BackupFile) then Delete (BackupFile)
- If Rename (ClientFile, BackupFile) then
- Rename (NewFile, ClientFile)
- Endif
- Endif
-
- Print "Summary"
- Print Lines, " lines processed"
- Print ChangedLines, " lines changed"
- End Function
-