HEX
Server: Apache
System: Windows NT MAGNETO-ARM 10.0 build 22000 (Windows 10) AMD64
User: Michel (0)
PHP: 7.4.7
Disabled: NONE
Upload Files
File: C:/Windows/OEM/Environment.wsf
<package>
    <?component error="true" debug="true" ?>
    <comment>
    Reads the OVF environment.
    </comment>
    <component id="Environment">
        <registration
            progid="WaGuest.Environment"
            description=""
            version="1.0.0.0"
            clsid="{428E043E-C0F2-4565-BE36-2A21462E2E16}"/>
      
        <public>
            <property name="WScript" />
            <property name="SettingsFilePath" />
            <method name="Initialize">
                <parameters name="configSetDirectory" />
            </method>
            <method name="GetOSDParameters" />
            <method name="GetPlatformProvisioningParameters" />
        </public>

        <object id="FSO" progid="Scripting.FileSystemObject" />

        <script language="VBScript" src="Utility.vbs" />

        <script language="VBScript">

            Dim g_Trace
            Dim oTraceEvent
            Dim environmentDoc
            Dim cachedEnvironmentConfigPath : cachedEnvironmentConfigPath = FSO.BuildPath(FSO.GetSpecialFolder(0), "Panther\ovf-env.xml")
        
            Sub Initialize(configSetDirectory)
                Set g_Trace = GetScriptObject(Me.WScript, "Tracing.wsf", "TraceSource")
                g_Trace.Name = "Environment"

                Dim cacheConfiguration : cacheConfiguration = True

                configSetDirectory = configSetDirectory & "\"
                SettingsFilePath = FSO.BuildPath(configSetDirectory, "ovf-env.xml")

                ' Use ovf-env from ISO when it exists. Otherwise default to Panther directory
                If Not FSO.FileExists(SettingsFilePath) Then
                    SettingsFilePath = cachedEnvironmentConfigPath
                    cacheConfiguration = False
                End If

                Set environmentDoc = CreateObject("Microsoft.XMLDOM")
                environmentDoc.setProperty "SelectionNamespaces", _
                    "xmlns:oe='http://schemas.dmtf.org/ovf/environment/1' " & _
                    "xmlns:wa='http://schemas.microsoft.com/windowsazure' " & _
                    "xmlns:rdfe='http://schemas.microsoft.com/2009/05/WindowsAzure/ServiceManagement' "

                If Not environmentDoc.Load(SettingsFilePath) Then
                    Err.Raise vbObjectError + 1, "Environment.wsf", "Unable to load environment file from " & SettingsFilePath
                Else
                    Set oTraceEvent = g_Trace.CreateEvent("INFO")
                    With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("Initialize"))
                        .Text = "ovf-env.xml loaded from " & SettingsFilePath
                    End With
                    g_Trace.TraceEvent oTraceEvent
                End If

                If cacheConfiguration = True Then
                    CacheEnvironmentConfiguration
                End If
            End Sub

            Function GetOSDParameters()
                Set GetOSDParameters = GetOSDParametersInternal(environmentDoc)
            End Function

            Private Function GetOSDParametersInternal(envDoc)
                Dim objParams

                Set objParams = envDoc.selectSingleNode("oe:Environment/wa:ProvisioningSection/rdfe:OSDParameters")
                If Not (objParams is Nothing) Then
                    ' M1 code
                    Set GetOSDParametersInternal = objParams
                    Exit Function
                End If

                Set objParams = envDoc.selectSingleNode("oe:Environment/wa:ProvisioningSection/wa:WindowsProvisioningConfigurationSet")
                If objParams is Nothing Then
                    Err.Raise vbObjectError + 2, "Environment.wsf", "Unable to find WindowsProvisioningConfigurationSet in environment file"
                    Exit Function
                End If

                Set oTraceEvent = g_Trace.CreateEvent("INFO")
                With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("WindowsProvisioningConfigurationSet"))
                    With .appendChild(oTraceEvent.ownerDocument.createElement("ComputerName"))
                        .Text = objParams.selectSingleNode("wa:ComputerName").text
                    End With
                    With .appendChild(oTraceEvent.ownerDocument.createElement("AdminPassword"))
                        .Text = "*SENSITIVE*DATA*DELETED*"
                    End With
                    If Not (objParams.selectSingleNode("wa:ResetPasswordOnFirstLogon") is Nothing) Then
                        With .appendChild(oTraceEvent.ownerDocument.createElement("ResetPasswordOnFirstLogon"))
                            .Text = objParams.selectSingleNode("wa:ResetPasswordOnFirstLogon").text
                        End With
                    End If
                    If Not (objParams.selectSingleNode("wa:TimeZone") is Nothing) Then
                        With .appendChild(oTraceEvent.ownerDocument.createElement("TimeZone"))
                            .Text = objParams.selectSingleNode("wa:TimeZone").text
                        End With
                    End If
                End With
                g_Trace.TraceEvent oTraceEvent

                Set GetOSDParametersInternal = objParams
            End Function

            Function GetPlatformProvisioningParameters()
                Set GetPlatformProvisioningParameters = GetPlatformProvisioningParametersInternal(environmentDoc)
            End Function

            Private Function GetPlatformProvisioningParametersInternal(envDoc)
                Set objParams = envDoc.selectSingleNode("oe:Environment/wa:PlatformSettingsSection/wa:PlatformSettings")
                If objParams is Nothing Then
                    Err.Raise vbObjectError + 3, "Environment.wsf", "Unable to find PlatformSettings in environment file" 
                    Exit Function
                End If

                Set GetPlatformProvisioningParametersInternal = objParams
            End Function

            Sub CacheEnvironmentConfiguration
                Dim xslt   : Set xslt   = CreateObject("Msxml2.XSLTemplate.6.0")
                Dim xslDoc : Set xslDoc = CreateObject("Msxml2.FreeThreadedDOMDocument.6.0")
                Dim xmlDoc : Set xmlDoc = CreateObject("Msxml2.DOMDocument.6.0")
                Dim envDoc : Set envDoc = CreateObject("Msxml2.DOMDocument.6.0")
                Dim xslProc, filePath, file
                
                xslDoc.Async = False
                xslDoc.setProperty "SelectionNamespaces", _
                    "xmlns:oe='http://schemas.dmtf.org/ovf/environment/1' " & _
                    "xmlns:wa='http://schemas.microsoft.com/windowsazure' " & _
                    "xmlns:rdfe='http://schemas.microsoft.com/2009/05/WindowsAzure/ServiceManagement' "
                xslDoc.Load FSO.BuildPath(FSO.GetSpecialFolder(0), "OEM\ovf-env.xml.xslt")
                If xslDoc.ParseError.ErrorCode <> 0 Then
                    Err.Raise vbObjectError + 4, "Environment.wsf",  xslDoc.ParseError.Reason
                    Exit Sub
                End If
                Set xslt.Stylesheet = xslDoc

                xmlDoc.Async = False
                xmlDoc.setProperty "SelectionNamespaces", _
                    "xmlns:oe='http://schemas.dmtf.org/ovf/environment/1' " & _
                    "xmlns:wa='http://schemas.microsoft.com/windowsazure' " & _
                    "xmlns:rdfe='http://schemas.microsoft.com/2009/05/WindowsAzure/ServiceManagement' "
                xmlDoc.LoadXML("<?xml version=""1.0"" encoding=""utf-8""?>" & _
                                "<Environment " & _
                                " xmlns=""http://schemas.dmtf.org/ovf/environment/1""" & _
                                " xmlns:oe=""http://schemas.dmtf.org/ovf/environment/1""" & _
                                " xmlns:wa=""http://schemas.microsoft.com/windowsazure""" & _
                                " xmlns:xml=""http://www.w3.org/XML/1998/namespace""" & _
                                " xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">" & _
                                "  <wa:ProvisioningSection>" & _
                                "    <wa:Version>1.0</wa:Version>" & _
                                "    <WindowsProvisioningConfigurationSet xmlns=""http://schemas.microsoft.com/windowsazure"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"">" & _
                                "      <!-- PARAMETERIZED -->" & _
                                "    </WindowsProvisioningConfigurationSet>" & _
                                "  </wa:ProvisioningSection>" & _
                                "  <wa:PlatformSettingsSection>" & _
                                "    <wa:Version>1.0</wa:Version>" & _
                                "    <PlatformSettings xmlns=""http://schemas.microsoft.com/windowsazure"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"">" & _
                                "      <!-- PARAMETERIZED -->" & _
                                "    </PlatformSettings>" & _
                                "  </wa:PlatformSettingsSection>" & _
                                "</Environment>")
                If xmlDoc.ParseError.ErrorCode <> 0 Then
                    Err.Raise vbObjectError + 5, "Environment.wsf", xmlDoc.ParseError.Reason
                    Exit Sub
                End If

                envDoc.Async = False
                envDoc.setProperty "SelectionNamespaces", _
                    "xmlns:oe='http://schemas.dmtf.org/ovf/environment/1' " & _
                    "xmlns:wa='http://schemas.microsoft.com/windowsazure' " & _
                    "xmlns:rdfe='http://schemas.microsoft.com/2009/05/WindowsAzure/ServiceManagement' "
                envDoc.LoadXML(environmentDoc.xml)
                If envDoc.ParseError.ErrorCode <> 0 Then
                    Err.Raise vbObjectError + 6, "Environment.wsf", envDoc.ParseError.Reason
                    Exit Sub
                End If

                Set xslProc = xslt.CreateProcessor()
                xslProc.Input = xmlDoc
                xslProc.AddParameter "OSDParameters", GetOSDParametersInternal(envDoc)
                xslProc.AddParameter "PlatformParameters", GetPlatformProvisioningParametersInternal(envDoc)
                xslProc.Transform()

                On Error Resume Next
                filePath = cachedEnvironmentConfigPath
                Set file = FSO.CreateTextFile(filePath, True, True)
                file.Write xslProc.Output
                file.Close
                
                If Err.Number <> 0 Then
                    Err.Raise vbObjectError + 7, "Environment.wsf", "Failed to cache environment configurations"
                End If
            End Sub
        </script>
    </component>
</package>