Export (0) Print
Expand All

Link Translation in ISA Server 2004

The Web pages sent back to external clients from published Web servers may contain links that include internal names of hosts. Because the names of these protected hosts are not resolved for external clients, these links are broken. Also, sending the internal names of hosts to external clients exposes these names to potential hackers. To overcome these problems, Microsoft® Internet Security and Acceleration (ISA) Server includes a Web filter called Link Translation Filter. When enabled, this Web filter performs link translation according to a default set of rules, or according to a user-defined dictionary that maps strings containing internal host names to strings containing publicly resolvable host names for the applicable Web publishing rule, if the type of message body specified in the Content-Type header of the response is included in one of the translatable content type sets specified for the rule. By default, link translation is applied only to the content types included in the HTML Documents content type set, although other content type sets can be specified. This setting is global for all Web publishing rules. Note that ISA Server performs link translation only on strings that are specified in UCS Transformation Format 8 (UTF-8) format in HTML documents.

Enabling and Disabling Link Translation

Script Listing: LinkTranslation_Enable.vbs

Managing the Translatable Content Type Sets

Script Listing: LinkTranslation_EditContentTypes.vbs

Managing Link Translation Dictionaries

Script Listing: Link Translation_EditDictionary.vbs

The Microsoft Visual Basic® Scripting Edition (VBScript) code in LinkTranslation_Enable.vbs (listed below) retrieves the configuration of the Web publishing rule specified by the user. Then, depending on the action specified by the user, the script enables or disables link translation for the rule by setting the TranslateLinks property of the Web publishing rule to True or False, or indicates whether link translation is enabled for the rule on the basis of the value of the TranslateLinks property.

Usage:Cscript LinkTranslation_Enable.vbs  Action RuleName

Action specifies one of the following actions:

  • Enable. Enable link translation for the specified Web publishing rule.
  • Disable. Disable link translation for the specified Web publishing rule.
  • Status. Get the link translation status for the specified Web publishing rule.

RuleName specifies the Web publishing rule.

To enable link translation for a specified Web publishing rule
  1. Define a constant for the error that is expected if the Web publishing rule specified cannot be found, and a constant for the enumeration value needed for determining that the policy rule specified is a Web publishing rule.

  2. Declare an FPCPolicyRule object.

  3. Call a subprocedure that retrieves the Web publishing rule having the name passed to it by performing the following steps:

    • Create an instance of the FPC COM object, which provides access to the other ISA Server administration COM objects.
    • Declare an FPCPolicyRules collection and get a reference to the existing policy rules collection.
    • Get a reference to the specified policy rule and verify that it is a Web publishing rule using its Type property. If the rule is not a Web publishing rule, notify the user and skip the remaining steps of this procedure.
  4. If the TranslateLinks property of the Web publishing rule is not set to True, set this property to True and call Save on the FPCPolicyRule object to save the change.

To disable link translation for a specified Web publishing rule
  1. Perform steps 1 through 3 of the procedure for enabling link translation.

  2. If the TranslateLinks property of the Web publishing rule is not set to False, set this property to False and call Save on the FPCPolicyRule object to save the change.

To get the link translation status for a specified Web publishing rule
  1. Perform steps 1 through 3 of the procedure for enabling link translation.

  2. Retrieve the value of the TranslateLinks property of the Web publishing rule and display a message indicating whether link translation is enabled or disabled based on the value retrieved.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' Copyright (c) Microsoft Corporation. All rights reserved.

' THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE

' RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE

' USER. USE AND REDISTRIBUTION OF THIS CODE, WITH OR WITHOUT MODIFICATION, IS

' HEREBY PERMITTED.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' This script retrieves the configuration of the Web publishing rule specified

' by the user. Then, depending on the action specified by the user, the script

' enables or disables link translation for the rule by setting the

' TranslateLinks property of the Web publishing rule to True or False, or

' indicates whether link translation is enabled for the rule on the basis of

' the value of the TranslateLinks property.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 

Option Explicit

 

'

' Define a constant for the expected error.

'

const Error_FileNotFound = &H80070002

const fpcPolicyRuleWebPublishing = 2

 

Main WScript.Arguments

 

Sub Main(args)

    Dim ruleName

    Dim action

 

    If(2 <> args.Count) Then

        Usage()

    End If

 

    action = LCase(args(0))

    ruleName = args(1)

    Select Case action

        Case "enable":

            EnableLinkTranslation ruleName, True

        Case "disable":

            EnableLinkTranslation ruleName, False

        Case "status":

            GetLinkTranslationStatus ruleName

        Case Else

            Usage()

    End Select

End Sub

 

'

' Enable/disable link translation for the specified Web publishing rule.

'

Sub EnableLinkTranslation(ruleName, fEnableLT)

    Dim wpRule     ' An FPCPolicyRule object

    Dim Status     ' A string

 

    If(fEnableLT) Then

        Status = "enabled"

    Else

        Status = "disabled"

    End If

 

    Set wpRule = GetWebPublishingRule(ruleName)

    If (wpRule.WebPublishingProperties.TranslateLinks <> fEnableLT) Then

        wpRule.WebPublishingProperties.TranslateLinks = fEnableLT

        wpRule.Save

        WScript.Echo "Link translation has been " & Status & "."

    Else

        WScript.Echo "Link translation is already " & Status & "."

    End If

End Sub

 

'

' Display the status of link translation for the specified Web Publishing rule.

'

Sub GetLinkTranslationStatus(ruleName)

    Dim wpRule     ' An FPCPolicyRule object

    Dim Status     ' A string

 

    Set wpRule = GetWebPublishingRule(ruleName)

    If(wpRule.WebPublishingProperties.TranslateLinks = True) Then

        Status = "enabled"

    Else

        Status = "disabled"

    End If

    WScript.Echo "Link translation is " & Status _

        & " for the Web publishing rule " & wpRule.Name & "."

End Sub

 

'

' Get a Web publishing rule by name.

'

Function GetWebPublishingRule(ruleName)

    Dim root       ' The FPCLib.FPC root object

    Dim rules      ' An FPCPolicyRules collection

    Dim errorCode, errorDescript

 

    Set root = WScript.CreateObject("FPC.Root")

    Set rules = root.GetContainingArray.ArrayPolicy.PolicyRules

 

    On Error Resume Next

    Set GetWebPublishingRule = rules.Item(ruleName)

    Select Case err.Number

        Case Error_FileNotFound:

            WScript.Echo "The Web publishing rule " & ruleName _

                & " does not exist."

            WScript.Quit

        Case 0:

            ' OK

        Case Else

            err.Raise err.Number,, err.Description

    End Select

    On error goto 0

 

    If wpRule.Type <> fpcPolicyRuleWebPublishing Then

        WScript.Echo "The policy rule " & ruleName _

            & " is not a Web publishing rule."

        WScript.Quit

    End If

End Function

 

Sub Usage()

    WScript.Echo "Usage:" & VbCrLf _

        & "  " & WScript.ScriptName & " Action RuleName" & VbCrLf _

        & "" & VbCrLf _

        & "    Action:" & VbCrLf _

        & "      Enable  - Enable link translation for the specified rule." _

                 & VbCrLf _

        & "      Disable - Enable link translation for the specified rule." _

                 & VbCrLf _

        & "      Status  - Get the link translation status " _

                 & "for the specified rule." & VbCrLf

    WScript.Quit

End Sub

When link translation is enabled, ISA Server checks the Content-Type header of the response to determine whether link translation should be applied to the body of the message. The names of content type sets, which contain lists of strings corresponding to Content-Type headers, can be specified in a specific parameters set associated with Link Translation Filter. By default, the following content type sets are available for specifying translatable content types:

  • Application
  • Application Data Files
  • Audio
  • Compressed Files
  • Documents
  • HTML Documents
  • Images
  • Macro Documents
  • Text
  • Video
  • VRML

By default, link translation is applied only to the content types included in the HTML Documents content type set.

The VBScript code in LinkTranslation_EditContentTypes.vbs retrieves the collection of vendor parameters sets associated with Link Translation Filter. Then, depending on the action specified by the user, the script reverts to the default list of translatable content types (the content types included in the HTML Documents content type set) by clearing all the translatable content type sets specified in the vendor parameters set that defines the translatable content type sets, displays the current list of translatable content type sets defined in the AllNames property of this vendor parameters set, or sets the list of translatable content type sets.

Usage:[Cscript] LinkTranslation_EditContentTypes.vbs  Action [ContentTypes]

Action specifies one of the following actions:

  • List. List current translatable content type sets.
  • Default. Reset to default translatable content types.
  • SetTypes. Set the specified translatable content type sets (space-delimited list).

ContentTypes specifies the content type set.

Example:

LinkTranslation_EditContentTypes.vbs SetTypes “HTML Documents” Video

To list the current translatable content type sets
  1. Define constants for the GUID of Link Translation Filter ({9DEEF135-75DB-4aab-B2AC-314FBC98EF14}) and for the GUID of the vendor parameters set that specifies the translatable content type sets ({E4FA56DB-7A77-4d13-B421-6641DF2D1AF0}).

  2. Create an instance of the FPC COM object, which provides access to the other ISA Server administration COM objects.

  3. Get a reference to the FPCVendorParametersSets collection associated with Link Translation Filter.

  4. Get a reference to the FPCVendorParametersSet object that specifies the translatable content type sets.

  5. If the parameters set specifying the translatable content type sets exists, retrieve the names of the parameters, which specify the translatable content type sets, and display them. If the parameters set specifying the translatable content type sets does not exist, display a message indicating that only the default content types will be used.

To reset to the default translatable content types
  1. Perform steps 1 through 3 of the procedure for listing the current translatable content type sets.

  2. Call the Remove method of the FPCVendorParametersSets collection with the GUID of the parameters set that specifies the translatable content type sets.

  3. If the parameters set that specifies the translatable content type sets is successfully removed, call Save on the FPCVendorParametersSets collection to save the changes.

To set to the translatable content type sets
  1. Perform steps 1 through 3 of the procedure for listing the current translatable content type sets.

  2. Call the Remove method of the vendor parameters sets collection with the GUID of the parameters set that specifies the translatable content type sets to remove this parameters set if it exists.

  3. Call the Add method of the vendor parameters sets collection with the first parameters set to the GUID of the parameters set that specifies the translatable content type sets to create a new empty parameters set for the translatable content type sets.

  4. In a For loop, for each translatable content type set that was specified in the command line, call the Value property of the parameters set defining the translatable content type sets to add a parameter whose name is set to the name of the translatable content type set and whose value is set to 1.

  5. Call Save on the FPCVendorParametersSets collection to save the changes.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' Copyright (c) Microsoft Corporation. All rights reserved.

' THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE

' RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE

' USER. USE AND REDISTRIBUTION OF THIS CODE, WITH OR WITHOUT MODIFICATION, IS

' HEREBY PERMITTED.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' This script retrieves the collection of vendor parameters sets associated with

' Link Translation Filter. Then, depending on the action specified by the user,

' the script reverts to the default translatable content type set (HTML

' Documents) by clearing all the translatable content type sets specified in the

' vendor parameters set that contains the translatable content type sets,

' displays the current list of translatable content type sets defined in the

' AllNames property of the vendor parameters set, or sets the list of

' translatable content type sets.

'

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 

Option Explicit

'

' Define constants for the GUIDs of Link Translation Filter and the vendor

' parameters set that specifies the translatable content type sets.

'

Const LTFGUID = "{9DEEF135-75DB-4aab-B2AC-314FBC98EF14}"

Const TranslatableContentTypeSetsGUID = "{E4FA56DB-7A77-4d13-B421-6641DF2D1AF0}"

Const Error_FileNotFound = &H80070002

 

Main WScript.Arguments

 

Sub Main(args)

    Dim root       ' The FPCLib.FPC root object

    Dim vpSets     ' An FPCVendorParametersSets collection

 

    If(0 = args.Count) Then

        Usage()

    End If

 

    Set root = WScript.CreateObject("FPC.Root")

    Set vpSets = _

    root.GetContainingArray.Extensions.WebFilters(LTFGUID).VendorParametersSets

 

    Select Case LCase(args(0))

        Case "list":

            ListTranslatableContentTypeSets vpSets

        Case "default":

            ' Clear the list of translatable content type sets.

            RemoveFromVPSs vpSets, TranslatableContentTypeSetsGUID

            WScript.Echo "Using the default translatable content types..."

        Case "settypes":

            If(args.Count < 2) Then

                Usage()

            End If

            SetTranslatableContentTypeSets vpSets, args

        Case Else

            Usage()

    End Select

End Sub

 

 

'

' Display the current translatable content type sets.

'

Sub ListTranslatableContentTypeSets(vpSets)

    Dim vpSet     ' An FPCVendorParametersSet object

    Dim errorCode, errorDescript, contentTypeSets, contentTypeSet

 

    On Error Resume Next

    Set vpSet = vpSets(TranslatableContentTypeSetsGUID)

    errorCode = err.Number

    errorDescript = err.Description

    On Error GoTo 0

 

    Select Case errorCode

        Case 0

            contentTypeSets = ""

            For Each contentTypeSet in vpSet.AllNames

                contentTypeSets = contentTypeSets & " " & contentTypeSet

            Next

            WScript.Echo "Translatable content type sets: " & contentTypeSets

        Case Error_FileNotFound:

            WScript.Echo "Using the default translatable content types only..."

        Case Else

            err.Raise errorCode,, errorDescript

    End Select

End Sub

 

 

'

' Set specific translatable content type sets.

'

Sub SetTranslatableContentTypeSets(vpSets, contentTypeSets)

    Dim vpSet     ' An FPCVendorParametersSet object

    Dim first, contentTypeSet

 

    RemoveFromVPSs vpSets, TranslatableContentTypeSetsGUID

    Set vpSet = vpSets.Add(TranslatableContentTypeSetsGUID, False)

 

    first = True

    For Each contentTypeSet In contentTypeSets

        If(first) Then

            first = False    ' Skip the first command-line parameter.

        Else

            vpSet.Value(contentTypeSet) = 1

        End If

    Next

    vpSets.Save

    ListTranslatableContentTypeSets vpSets

End Sub

 

 

'

' Remove the specified VendorParametersSet from VendorParametersSets collection.

'

sub RemoveFromVPSs(vpSets, setName)

    Dim errorCode, errorDescript

 

    On Error Resume Next

    vpSets.Remove setName

    errorCode = err.Number

    errorDescript = err.Description

    On Error GoTo 0

 

    Select Case errorCode

        Case 0:

            vpSets.Save

        Case Error_FileNotFound:

            ' Ignore the error. The object has already been removed.

        Case Else

            err.Raise errorCode,,errorDescript

    End Select

End Sub

 

sub Usage()

    Dim usageText

    usageText = "Usage:" & vbCrLf _

        & vbCrLf  _

        & "  " & wscript.ScriptName & " Action [Content Type Sets]" & vbCrLf _

        & vbCrLf  _

        & "    Action:"  & vbCrLf _

        & "       List     - List current translatable content type sets." _

                  & vbCrLf _

        & "       Default  - Reset to default translatable content types."  _

                  & vbCrLf _

        & "       SetTypes - Set the specified translatable content type sets" _

                  & " (space-delimited list)."  & vbCrLf _

        & vbCrLf  _

        & "    Example:"  & vbCrLf _

        & "       " & wscript.ScriptName & " SetTypes Application" _

                  & " ""HTML Documents"""  & vbCrLf

 

    WScript.Echo usageText

    WScript.Quit

End Sub

Each Web publishing rule can have its own link translation dictionary, which is defined in a specific vendor parameters set associated with it. Each entry in a dictionary is a pair of strings consisting of a string containing a host name that is used internally and a string containing a host name that can be resolved externally. The internal string is specified as the name of a parameter, and the external string is specified as its value.

The VBScript code in LinkTranslation_EditDictionary.vbs lets the user manage the link translation dictionaries for Web publishing rules. Depending on the action specified by the user, this script lists the link translation dictionaries of all Web publishing rules, lists all the internal/external pairs contained in the dictionary for the specified Web publishing rule, removes the specified entry from the dictionary for the specified rule, removes the entire dictionary for the specified rule, and adds an internal/external pair of strings to the dictionary for the specified rule.

Usage:LinkTranslation_EditDictionary.vbs Action [RuleName] [IntString] [ExtString]

Action specifies one of the following actions:

  • ListAll. List dictionaries for all Web publishing rules.
  • List. List dictionary for the specified rule.
  • Clear. Clear all entries from the link translation dictionary for the specified rule.
  • Add. Add an entry defined by InternalString and ExternalString to the dictionary of the specified rule.
  • RemoveEntry. Remove the entry for InternalString from the dictionary of the specified rule.

RuleName specifies the Web publishing rule.

IntString specifies a string containing a host name that is used internally.

ExtString specifies a string containing a host name that can be resolved externally.

To list the dictionaries for all Web publishing rules
  1. Define a constant for the GUID of a vendor parameters set that defines a link translation dictionary ({3563FFF5-DF93-40eb-ABC3-D24B5F14D8AA}) and a constant for the enumeration value for indicating that a policy rule is a Web publishing rule.

  2. Create an instance of the FPC COM object, which provides access to the other ISA Server administration COM objects.

  3. Declare an FPCPolicyRules collection and an FPCPolicyRule object.

  4. Get a reference to the existing policy rules collection.

  5. In a For loop, for each rule in the policy rules collection, use the Type property to determine whether it is a Web publishing rule. If the policy rule is a Web publishing rule, call a subprocedure that lists the entries in its link translation dictionary by performing the following steps:

    • Declare an FPCVendorParametersSets collection and an FPCVendorParametersSet object.
    • Get a reference to the FPCVendorParametersSets collection of the rule.
    • Try to get a reference to the FPCVendorParametersSet object that defines a link translation dictionary in the collection.
    • If a reference is obtained to a link translation dictionary that is not empty, in a For loop, display each name (internal string) retrieved from the AllNames property followed by the corresponding external string, which is obtained by calling the Value property with the parameter set to the internal string.
To list the dictionary for a specified Web publishing rule
  1. Perform steps 1 through 4 of the procedure for listing the dictionaries for all Web publishing rules.

  2. Retrieve the name of the specified Web publishing rule from the second command-line argument.

  3. Get a reference to the specified policy rule and verify that it is a Web publishing rule using its Type property. If the rule is not a Web publishing rule, notify the user and skip the remaining steps of this procedure.

  4. Call the subprocedure described in Step 5 of the procedure for listing the dictionaries for all Web publishing rules to display the entries in the rule’s link translation dictionary.

To clear all entries from the link translation dictionary for a specified rule
  1. Perform steps 1 through 4 of the procedure for listing the dictionaries for all Web publishing rules.

  2. Retrieve the name of the specified Web publishing rule from the second command-line argument.

  3. Get a reference to the specified policy rule and verify that it is a Web publishing rule using its Type property. If the rule is not a Web publishing rule, notify the user and skip the remaining steps of this procedure.

  4. Declare an FPCVendorParametersSets collection and an FPCVendorParametersSet object.

  5. Get a reference to the FPCVendorParametersSets collection of the rule.

  6. Call the Remove method of the FPCVendorParametersSets collection with the parameters set to the GUID of a parameters set that defines the link translation dictionary to remove this parameters set if it exists.

  7. If the link translation dictionary is successfully removed, call Save on the FPCVendorParametersSets collection to save the changes.

To add an entry to the link translation dictionary for a specified rule
  1. Perform steps 1 through 4 of the procedure for listing the dictionaries for all Web publishing rules.

  2. Retrieve the name of the specified Web publishing rule from the second command-line argument.

  3. Get a reference to the specified policy rule and verify that it is a Web publishing rule using its Type property. If the rule is not a Web publishing rule, notify the user and skip the remaining steps of this procedure.

  4. Declare an FPCVendorParametersSets collection and an FPCVendorParametersSet object.

  5. Get a reference to the FPCVendorParametersSets collection of the rule.

  6. Try to get a reference to the existing parameters set that defines the link translation dictionary.

  7. Call the Add method of the vendor parameters sets collection with the first parameters set to the GUID of the parameters set that defines the link translation dictionary to create a new empty parameters set for the link translation dictionary.

  8. Call the Value property of the parameters set defining the link translation dictionary to add a parameter whose name is the internal string specified in the command line and whose value is set to the external string specified in the command line.

  9. Call Save on the FPCVendorParametersSets collection to save the changes.

To remove an entry from the link translation dictionary for a specified rule
  1. Perform steps 1 through 4 of the procedure for listing the dictionaries for all Web publishing rules.

  2. Retrieve the name of the specified Web publishing rule from the second command-line argument.

  3. Get a reference to the specified policy rule and verify that it is a Web publishing rule using its Type property. If the rule is not a Web publishing rule, notify the user and skip the remaining steps of this procedure.

  4. Declare an FPCVendorParametersSets collection and an FPCVendorParametersSet object.

  5. Get a reference to the FPCVendorParametersSets collection of the rule.

  6. Try to get a reference to the existing parameters set that defines the link translation dictionary. If this parameters set does not exist, skip the remaining steps of this procedure.

  7. Call the RemoveValue method of the parameters set defining the link translation dictionary with the parameters set to the internal string specified in the command line to remove the entry specified.

  8. If the entry is successfully removed, call Save on the FPCVendorParametersSet object to save the changes.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' Copyright (c) Microsoft Corporation. All rights reserved.

' THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE

' RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE

' USER. USE AND REDISTRIBUTION OF THIS CODE, WITH OR WITHOUT MODIFICATION, IS

' HEREBY PERMITTED.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' Depending on the action specified by the user in the command line, this script

' lists the link-translation dictionaries of all Web publishing rules, lists all

' the entries defining internal-external pairs of strings in the dictionary for

' the specified Web publishing rule, removes the specified entry from the

' dictionary for the specified rule, removes the entire dictionary for the

' specified rule, adds an entry defining an internal-external pair to the

' dictionary for the specified rule.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 

Option Explicit

 

'

' Define a constant for the GUID of the vendor parameters set that defines

' a link-translation dictionary.

'

Const LinkTranslatDicGUID = "{3563FFF5-DF93-40eb-ABC3-D24B5F14D8AA}"

Const fpcPolicyRuleWebPublishing = 2

Const Error_FileNotFound = &H80070002

 

Dim root       ' The FPCLib.FPC root object

 

Main Wscript.Arguments

 

Sub Main(args)

    Dim ruleName, action

 

    If(0 = args.Count) Then

        Usage()

    End If

 

    Set root = WScript.CreateObject("FPC.Root")

    action = LCase(args(0))

 

    Select Case action

        Case "listall":

            ListAllDictionaries

        Case "list":

            If(2 > args.Count) Then

                Usage()

            End If

            ruleName = args(1)

            ListDictionary GetWebPublishingRule(ruleName)

        Case "clear":

            If(2 > args.Count) Then

                Usage()

            End If

            ruleName = args(1)

            ClearDictionary GetWebPublishingRule(ruleName)

        Case "add":

            If(4 > args.count) Then

                Usage()

            End If

            ruleName = args(1)

            AddItemToDictionary GetWebPublishingRule(ruleName), args(2), args(3)

        Case "removeentry":

            If(3 > args.Count) Then

                Usage()

            End If

            ruleName = args(1)

            RemoveEntry GetWebPublishingRule(ruleName), args(2)

        case Else

            Usage()

    End Select

End Sub

 

 

'

' List the dictionaries of all Web publishing rules.

'

Sub ListAllDictionaries()

    Dim rules     ' An FPCPolicyRules collection

    Dim rule      ' An FPCPolicyRule object

 

    Set rules = root.GetContainingArray.ArrayPolicy.PolicyRules

    For Each rule in rules

        If rule.Type = fpcPolicyRuleWebPublishing Then

            ListDictionary rule

        End If

    Next

End Sub

 

 

'

' List the content of the link-translation dictionary for the

' specified Web publishing rule.

'

Sub ListDictionary(wpRule)

    Dim vpSets    ' An FPCVendorParametersSets collection

    Dim vpSet     ' An FPCVendorParametersSet object

    Dim errorCode, errorDescript, index, name

 

    Set vpSets = wpRule.VendorParametersSets

 

    On Error Resume Next

    Set vpSet = vpSets(LinkTranslatDicGUID)

    errorCode = err.Number

    errorDescript = err.Description

    On Error GoTo 0

 

    Select Case errorCode

        Case Error_FileNotFound:

            WScript.Echo "The dictionary for the " & wpRule.Name _

            & " rule is empty or does not exist."

        Case 0:

            ' A dictionary exists for this rule.

            WScript.Echo "Dictionary for the " & wpRule.Name & " rule:"

            index = 1

            If(IsEmpty(vpSet.AllNames)) Then

                    WScript.Echo "   The dictionary is empty."

            Else

                For Each name In vpSet.AllNames

                    WScript.Echo "   " & index & ". " & name & " - " & _

                                 vpSet.Value(name)

                    index = index + 1

                Next

            End If

        Case Else:

            err.Raise errorCode,, errorDescript

 

    End Select

End Sub

 

 

'

' Remove the vendor parameters set defining the link-translation dictionary

' of the specified Web publishing rule.

'

Sub ClearDictionary(wpRule)

    Dim vpSets    ' An FPCVendorParametersSets collection

 

    Set vpSets = wpRule.VendorParametersSets

    RemoveFromVPSs vpSets, LinkTranslatDicGUID

    vpSets.Save

End Sub

 

 

'

' Remove a single entry from the dictionary (The entry name is the internal

' string).

'

Sub RemoveEntry(wpRule, name)

    Dim vpSets    ' An FPCVendorParametersSets collection

    Dim vpSet     ' An FPCVendorParametersSet object

    Dim errorCode, errorDescript

 

    ' Get the vendor parameters set defining the link-translation dictionary.

    Set vpSets = wpRule.VendorParametersSets

    On Error Resume Next

    Set vpSet = vpSets(LinkTranslatDicGUID)

    errorCode = err.Number

    errorDescript = err.Description

    On Error GoTo 0

 

    Select Case errorCode

        Case Error_FileNotFound:

            WScript.Echo "No dictionary exists for this rule."

            Exit Sub

        Case 0:

            ' OK

        Case Else

            err.Raise errorCode,, errorDescript

    End Select

 

    ' Remove the specified entry.

    '   Note: The key is case-sensitive.

    On Error Resume Next

    vpSet.RemoveValue name

    errorCode = err.Number

    errorDescript = err.Description

    On Error GoTo 0

 

    Select Case errorCode

        Case Error_FileNotFound:

            WScript.Echo "An entry for " & name _

            & " was not found in the dictionary."

        Case 0:

            vpSet.Save     ' OK, save the changes.

        Case Else

            err.Raise errorCode,, errorDescript

    End Select

End Sub

 

 

'

' Add an entry (internal string - external string) to the link-translation

' dictionary of the specified rule.

'

Sub AddItemToDictionary(wpRule, internalString, externalString)

    Dim vpSets    ' An FPCVendorParametersSets collection

    Dim vpSet     ' An FPCVendorParametersSet object

    Dim errorCode, errorDescript

 

    Set vpSets = wpRule.VendorParametersSets

    On Error Resume Next

    Set vpSet = vpSets(LinkTranslatDicGUID)

    errorCode = err.Number

    errorDescript = err.Description

    On Error GoTo 0

 

    Select Case errorCode

        Case Error_FileNotFound:

            ' Create the dictionary if it does not exist.

            Set vpSet = vpSets.Add(LinkTranslatDicGUID, False)

        Case 0:

            ' OK, set was found.

        Case Else

            err.Raise errorCode,, errorDescript

    End Select

 

    ' Add the internal-external entry.

    vpSet.Value(internalString) = externalString

    vpSets.Save

End Sub

 

 

'

' Retrieve the specified Web publishing rule.

'

Function GetWebPublishingRule(ruleName)

    Dim rules     ' An FPCPolicyRules collection

    Dim rule      ' An FPCPolicyRule object

    Dim errorCode, errorDescript

 

    Set rules = root.GetContainingArray.ArrayPolicy.PolicyRules

    On Error Resume Next

    Set rule = rules(ruleName)

    Select Case err.Number

        Case Error_FileNotFound:

            WScript.Echo "The " & ruleName _

            & " Web publishing rule was not found."

            Wscript.Quit

        Case 0:

            ' OK

        Case Else

            err.Raise err.Number,, err.Description

    End Select

    On Error GoTo 0

 

    If rule.Type <> fpcPolicyRuleWebPublishing Then

        WScript.Echo "The " & ruleName & " rule is not a Web publishing rule."

        Wscript.Quit

    End If

 

    Set GetWebPublishingRule = rule

 

End Function

 

 

'

' Remove the link-translation dictionary from the vendor parameters sets

' collection of the specified rule.

'

Sub RemoveFromVPSs(vpSets, setName)

    Dim errorCode, errorDescript

 

    On Error Resume Next

    vpSets.Remove setName

    errorCode = err.Number

    errorDescript = err.Description

    On Error GoTo 0

 

    Select Case errorCode

        Case 0:

            vpSets.Save                ' OK, save the changes.

        Case Error_FileNotFound:

            ' Ignore the error if the object was not found

            ' or was already removed.

        Case Else

            err.raise errorCode,,errorDescript

    End Select

End Sub

 

Sub Usage()

    Dim sUsage

 

    sUsage = "Usage:" & vbCrLf _

        & "  LinkTranslation_EditDictionary.vbs Action [RuleName] [IntString]" _

             &  " [ExtString]" & vbCrLf _

        & vbCrLf _

        & "    Action:" & vbCrLf _

        & "      ListAll     - List dictionaries for all Web publishing" _

                 & " rules." & vbCrLf _

        & "      List        - List dictionary for the specified rule." _

                 & vbCrLf _

        & "      Clear       - Clear all entries from the search-replace" _

                 & " dictionary for the specified rule." & vbCrLf _

        & "      Add         - Add an entry (internal string - external" _

                 & " string) to the dictionary of the specified rule." _

                 & vbCrLf _

        & "      RemoveEntry - Remove the entry for the specified internal" _

                 & " string from the dictionary of the specified rule." _

                 & vbCrLf _

        & vbCrLf _

        & "    RuleName: Specify the Web publishing rule. " & vbCrLf

    WScript.Echo sUsage

 

    WScript.Quit

End Sub

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft