'******************************************************************************
' 	               INTEL CORPORATION PROPRIETARY INFORMATION
'   This software is supplied under the terms of a license agreement or
'  nondisclosure agreement with Intel Corporation and may not be copied 
'   or disclosed except in accordance with the terms of that agreement. 
'   Copyright (c) 2000-2003 Intel Corporation. All Rights Reserved. 
'******************************************************************************
Public ServerIPAddress
Public HeartBeatEnable
Public SelectedAdapter
Public SNMPCommunity
Public OsHangWatchdogEnable
Public EnableAllRemoteCtrlFunctions 
Public ComputerName
Public UserName
Public Password

' Enables these if using the wscript engine. Also uncomment them at the end of the file
'<job id="main">
'	<script language="VBScript">
		Dim Services
		Dim MyObject
		Dim ObjWbemObjectSet

		' Set values that will be used in this script
		' Set the system to connect to, if connecting from remote
		ComputerName=""

		' Set the User name and Password to login, if connecting from remote
		UserName=""
		Password=""
	
		' Set this value to your management console IP address
		ServerIPAddress="143.186.252.100"

		' Set this value to True to enable Heartbeat sending
		HeartBeatEnable = True

		' Set this value to the SNMP community string
		SNMPCommunity="public"
	

		' set this value to "" for adapter auto selection 
		SelectedAdapter=""
		
		' set this value to True to enable OS Hang Watchdog
		OsHangWatchdogEnable = False

		' set this value to True to enable all Remote Control Functions
		EnableAllRemoteCtrlFunctions = False
		
		WScript.Echo "Running Script to configure Intel ASF"	
		
		'
		'Connect to system	
		'
		Connect_Server()
		If IsObject(Services) = False Then
			WScript.Echo "Exiting VBScript"
			WScript.Quit
		End If
		
		'
		'Get Intel ASF WMI Object and set configuration data
		'
		Get_Object()
		If IsObject(MyObject) = False Then
			WScript.Echo "Exiting VBScript"
			WScript.Quit
		End If
		
		'
		'to debug: uncomment the next line to read configured data and display it.
		'
		Refresh_Data()
		'
		'Exit the script
		'
		WScript.Echo "Exiting Script"
		
		'****************************************************************************
		'SUB ROUTINES USED IN THE SCRIPT
		'****************************************************************************
		'****************************************************************************
		' This subroutine connects to the local host
		'****************************************************************************
		Sub Connect_Server()
			On Error Resume Next

			WScript.Echo ("Connecting to Local System system.")
			Set Services = CreateObject("Wbemscripting.SWbemLocator").ConnectServer(ComputerName, "root\cimv2", UserName, Password)
			If (IsObject(Services) = False) Then
				WScript.Echo Err.Description
				Exit Sub
			End If
			
			Services.Security_.ImpersonationLevel =  3  'impersonate
			Services.Security_.AuthenticationLevel = 4  'packet
			
			WScript.Echo "Connected"
		End Sub
		
		
		'****************************************************************************
		'This sub routine creates an intance of CIM class that models Intel ASF 
		'Alert Sending Device. The routine then sets the ASD parameters (alert destination,
		'enable heartbeats, enable OS hang watchdog, selected adapter, SNMP community and
		'enabled remote control functions) 
		'****************************************************************************
		Sub Get_Object()
			On Error Resume Next

			set ObjWbemObjectSet = Services.InstancesOf("IA_ASF_OOBAlertService")
			set MyObject = ObjWbemObjectSet.Item("IA_ASF_OOBAlertService.Name='Intel ASF OOB Alert Service'")
			If IsObject(MyObject) = False Then
					WScript.Echo "Intel ASF Alert Service is not present in the system" 
					Exit Sub
			End If
			
			Wscript.echo "Got ASF Object"

			' Set values
			MyObject.DestinationAddress = ServerIPAddress
			MyObject.EnablePresenceHeartbeats = HeartBeatEnable
			MyObject.SelectedAdapter=SelectedAdapter
			MyObject.SNMP_Community = SNMPCommunity

			if IsArray(MyObject.SupportedFunctions) then
				' Remote control functions
				if EnableAllRemoteCtrlFunctions = True Then
	
					' first, disable all the currently enabled functions
					for i=0 to UBound (MyObject.EnabledFunctions)
						MyObject.EnabledFunctions(i) = ""
					next								
	
					' enable all supported functions
					for i=0 to UBound (MyObject.SupportedFunctions)
						Wscript.echo "Enabling function " & ": " & MyObject.SupportedFunctions(i)
						MyObject.EnabledFunctions(i) = MyObject.SupportedFunctions(i)				
					next				
	
				Else
					' disable all functions
					for i=0 to UBound(MyObject.EnabledFunctions)
						Wscript.echo "Disabling function " & ": " & MyObject.EnabledFunctions(i)
						MyObject.EnabledFunctions(i) = ""
					next	
								
				End if			
			End If

			MyObject.Enable = True
			MyObject.Put_

			Wscript.echo "Put ASF Object"
		
			' for OS hang Watchdog, use the watchdog class
			set ObjWbemObjectSet = Services.InstancesOf("IA_ASF_WatchDog")
			set MyObject = ObjWbemObjectSet.Item("IA_ASF_WatchDog.DeviceID='Intel ASF OOB Alert Service WatchDog'")
			If IsObject(MyObject) = False Then
				WScript.Echo "Intel ASF Alert Service Watchdog is not present in the system" 
				Exit Sub
			End If
			MyObject.WatchdogEnable =  OsHangWatchdogEnable
			MyObject.Put_

		End Sub
	
		
		'****************************************************************************
		'This sub routine creates an instance of CIM class that models Intel ASF 
		'Alert Sending Device. Routine reads the current configuration and displays
		'status of ASF
		'****************************************************************************
		Sub Refresh_Data()	
			set ObjWbemObjectSet = Services.InstancesOf("IA_ASF_OOBAlertService")
			set MyObject = ObjWbemObjectSet.Item("IA_ASF_OOBAlertService.Name='Intel ASF OOB Alert Service'")
			If ( MyObject.SafeMode) Then
				Dim Answer
				Answer = MsgBox ("ASF Agent is in SAFE MODE!" &Chr(13) & MyObject.ReasonForSafeMode, 16, "Intel ASF Configuration")
				Exit Sub
			Else
				WScript.Echo "ASF Configured"
			End If
			WScript.Echo "Server IP address: " & MyObject.DestinationAddress
			WScript.Echo "Adapter IP Address: " & MyObject.IPAddress	
			WScript.Echo "System ID: " & MyObject.SystemID	
		End Sub
					
'	</script>
'</job>