648 lines
22 KiB
C#
648 lines
22 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Intel.Management.Wsman;
|
|
|
|
namespace Intel.Management.PSModule.Amt
|
|
{
|
|
class EtcService : DriveContainer
|
|
{
|
|
|
|
public EtcService(DriveItem parent)
|
|
: base("Etc", parent)
|
|
{
|
|
}
|
|
|
|
public override void GetChildItems(ChildWriter writer)
|
|
{
|
|
writer.Add(new ClockService(this));
|
|
writer.Add(new CodeVersions(this));
|
|
writer.Add(new Hosts(this));
|
|
writer.Add(new Networking(this));
|
|
writer.Add(new Networks(this));
|
|
writer.Add(new PowerPolicy(this));
|
|
writer.Add(new Protocols(this));
|
|
writer.Add(new RegisteredProfiles(this));
|
|
writer.Add(new Services(this));
|
|
|
|
}
|
|
|
|
public override object GetReturnObject()
|
|
{
|
|
return new NameValuePairItem(Name, Value);
|
|
}
|
|
|
|
|
|
class Hosts : SettingsContainer
|
|
{
|
|
public Hosts(DriveItem parent)
|
|
: base("Hosts", parent)
|
|
{
|
|
}
|
|
|
|
public override void GetChildItems(ChildWriter writer)
|
|
{
|
|
_refToSettings = ((AmtRootService)GetRoot()).AmtGeneralSettingsRef;
|
|
_settingsObj = _refToSettings.Get();
|
|
|
|
writer.Add(new StringSetting("HostName",this));
|
|
writer.Add(new StringSetting("DomainName", this));
|
|
|
|
if (HasSetting("HostOSFQDN"))
|
|
writer.Add(new StringSetting("HostOSFQDN", this));
|
|
|
|
if (HasSetting("SharedFQDN"))
|
|
writer.Add(new BooleanSetting("SharedFQDN", this));
|
|
}
|
|
|
|
public override object GetReturnObject()
|
|
{
|
|
return new NameValuePairItem(Name, Value);
|
|
}
|
|
}
|
|
|
|
class PowerSchemeItem : DriveEntry
|
|
{
|
|
public PowerSchemeItem(Guid scheme,DriveItem item)
|
|
: base("ActiveScheme",scheme,item)
|
|
{
|
|
}
|
|
|
|
|
|
public override void SetItem(object values, DriveProvider provider)
|
|
{
|
|
IWsmanConnection conn = ((AmtRootService)GetRoot()).Connection;
|
|
Guid inputGuid = Guid.Empty;
|
|
|
|
if (values is Guid)
|
|
{
|
|
inputGuid = (Guid)values;
|
|
}
|
|
else if (values is String)
|
|
{
|
|
inputGuid = new Guid(values.ToString());
|
|
}
|
|
|
|
bool bFound = false;
|
|
|
|
foreach (IWsmanItem item in conn.ExecQuery("SELECT * FROM AMT_SystemPowerScheme"))
|
|
{
|
|
byte[] data = Convert.FromBase64String(item.Object.GetProperty("SchemeGUID").ToString());
|
|
Guid guid = new Guid(data);
|
|
if (guid.Equals(inputGuid))
|
|
{
|
|
bFound = true;
|
|
IManagedReference refToScheme = conn.NewReference("AMT_SystemPowerScheme");
|
|
refToScheme.AddSelector("InstanceID",item.Object.GetProperty("InstanceID").ToString());
|
|
refToScheme.AddSelector("SchemeGUID",item.Object.GetProperty("SchemeGUID").ToString());
|
|
|
|
IManagedInstance inputObject = refToScheme.CreateMethodInput("SetPowerScheme");
|
|
IManagedInstance outObj = refToScheme.InvokeMethod(inputObject);
|
|
|
|
switch (outObj.GetProperty("ReturnValue").ToString())
|
|
{
|
|
|
|
case "0":
|
|
_value = guid;
|
|
break;
|
|
case "1":
|
|
throw new WsmanInvokeException("Internal Error");
|
|
case "38":
|
|
throw new WsmanInvokeException("Flash write limit exceeded");
|
|
case "2075":
|
|
throw new WsmanInvokeException("Audit Failed");
|
|
default:
|
|
throw new WsmanInvokeException("AMT error " + outObj.GetProperty("ReturnValue").ToString());
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!bFound)
|
|
throw new ArgumentOutOfRangeException("Scheme not supported");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
class PowerPolicy : SettingsContainer
|
|
{
|
|
public PowerPolicy(DriveItem parent)
|
|
: base("PowerPolicy", parent)
|
|
{
|
|
_refToSettings = ((AmtRootService)GetRoot()).AmtGeneralSettingsRef;
|
|
}
|
|
|
|
|
|
public override void GetChildItems(ChildWriter writer)
|
|
{
|
|
_settingsObj = _refToSettings.Get();
|
|
|
|
List<DriveEntry> list = new List<DriveEntry>();
|
|
foreach (IWsmanItem item in _refToSettings.Connection.ExecQuery("SELECT * FROM AMT_SystemPowerScheme"))
|
|
{
|
|
byte[] data = Convert.FromBase64String(item.Object.GetProperty("SchemeGUID").ToString());
|
|
|
|
DriveEntry entry = new DriveEntry(item.Object.GetProperty("Description").ToString(),
|
|
new Guid(data),this);
|
|
|
|
|
|
list.Add(entry);
|
|
}
|
|
|
|
|
|
|
|
foreach (IWsmanItem item in _refToSettings.Connection.ExecQuery("SELECT * FROM CIM_ElementSettingData"))
|
|
{
|
|
IManagedReference refToData = item.Object.GetProperty("SettingData").Ref;
|
|
bool isCurrent = item.Object.GetProperty("IsCurrent").ToString().Equals("1");
|
|
|
|
if (refToData.SimpleName.Equals("AMT_SystemPowerScheme") && isCurrent)
|
|
{
|
|
IManagedInstance refToScheme = refToData.Get();
|
|
byte[] data = Convert.FromBase64String(refToScheme.GetProperty("SchemeGUID").ToString());
|
|
Guid guid = new Guid(data);
|
|
|
|
writer.Add(new PowerSchemeItem(guid,this));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
writer.Add(new UIntSetting("IdleWakeTimeout", this));
|
|
|
|
writer.Add(new DriveContainer("Schemes",list.ToArray(), this));
|
|
|
|
}
|
|
|
|
public override object GetReturnObject()
|
|
{
|
|
return new NameValuePairItem(Name, Value);
|
|
}
|
|
}
|
|
|
|
class Digest :DriveContainer
|
|
{
|
|
public Digest(DriveItem parent)
|
|
: base("Digest", parent)
|
|
{
|
|
|
|
}
|
|
|
|
public override void GetChildItems(ChildWriter writer)
|
|
{
|
|
IManagedReference refToSettings = ((AmtRootService)GetRoot()).AmtGeneralSettingsRef;
|
|
IManagedInstance settingsObj = refToSettings.Get();
|
|
|
|
writer.Add(new DriveEntry("Realm", settingsObj.GetProperty("DigestRealm").ToString(), this));
|
|
}
|
|
|
|
public override object GetReturnObject()
|
|
{
|
|
return new NameValuePairItem(Name, Value);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
class Networking : SettingsContainer
|
|
{
|
|
public Networking(DriveItem parent)
|
|
: base("Networking", parent)
|
|
{
|
|
_refToSettings = ((AmtRootService)GetRoot()).AmtGeneralSettingsRef;
|
|
}
|
|
|
|
public override void GetChildItems(ChildWriter writer)
|
|
{
|
|
_settingsObj = _refToSettings.Get();
|
|
|
|
if (HasSetting("DHCPv6ConfigurationTimeout"))
|
|
writer.Add(new TimespanSetting("DHCPv6ConfigurationTimeout",TimespanUnits.Seconds,this));
|
|
|
|
|
|
if (HasSetting("DDNSPeriodicUpdateInterval"))
|
|
writer.Add(new TimespanSetting("DDNSPeriodicUpdateInterval", TimespanUnits.minutes,this));
|
|
if (HasSetting("DDNSTTL"))
|
|
writer.Add(new TimespanSetting("DDNSTTL",TimespanUnits.Seconds, this));
|
|
if (HasSetting("DDNSUpdateEnabled"))
|
|
writer.Add(new BooleanSetting("DDNSUpdateEnabled",this));
|
|
|
|
|
|
|
|
if (HasSetting("NetworkInterfaceEnabled"))
|
|
writer.Add(new BooleanSetting("NetworkInterfaceEnabled",this));
|
|
|
|
|
|
writer.Add(new BooleanSetting("PingResponseEnabled",this));
|
|
|
|
if (HasSetting("PreferredAddressFamily"))
|
|
writer.Add(new ValueMapSetting("PreferredAddressFamily",ValueList.PreferredAddressFamily, this));
|
|
|
|
if (HasSetting("PresenceNotificationInterval"))
|
|
writer.Add(new TimespanSetting("PresenceNotificationInterval", TimespanUnits.minutes, this));
|
|
|
|
|
|
if (HasSetting("PrivacyLevel"))
|
|
writer.Add(new ValueMapSetting("PrivacyLevel", ValueList.PrivacyLevel, this));
|
|
|
|
if (HasSetting("RmcpPingResponseEnabled"))
|
|
writer.Add(new BooleanSetting("RmcpPingResponseEnabled",this));
|
|
|
|
writer.Add(new BooleanSetting("WsmanOnlyMode",this));
|
|
}
|
|
|
|
public override object GetReturnObject()
|
|
{
|
|
return new NameValuePairItem(Name, Value);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
class CodeVersions : DriveContainer
|
|
{
|
|
public CodeVersions(DriveItem parent)
|
|
: base("CodeVersions", parent)
|
|
{
|
|
}
|
|
|
|
public override void GetChildItems(ChildWriter writer)
|
|
{
|
|
EtcService service = (EtcService)_parent;
|
|
IWsmanConnection conn = ((AmtRootService)GetRoot()).Connection;
|
|
|
|
IWsmanEnumeration colObj = conn.ExecQuery("SELECT * FROM CIM_SoftwareIdentity");
|
|
|
|
foreach (IWsmanItem item in colObj)
|
|
{
|
|
|
|
switch (item.Object.GetProperty("InstanceID").ToString())
|
|
{
|
|
|
|
case "AMT":
|
|
case "AMTApps":
|
|
case "AMT FW Core Version":
|
|
case "Netstack":
|
|
case "Recovery Version":
|
|
case "Flash":
|
|
|
|
writer.Add(new DriveEntry(item.Object.GetProperty("InstanceID").ToString(),
|
|
new Intel.Management.Mei.MeVersionInfo(item.Object.GetProperty("VersionString").ToString()), this));
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
writer.Add(new DriveEntry(item.Object.GetProperty("InstanceID").ToString(),
|
|
item.Object.GetProperty("VersionString").ToString(), this));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override object GetReturnObject()
|
|
{
|
|
return new NameValuePairItem(Name, Value);
|
|
}
|
|
} // End CodeVersions Class
|
|
|
|
class KerberosDriveItem : SettingsItem
|
|
{
|
|
|
|
public KerberosDriveItem(bool enabledState,SettingsContainer parent)
|
|
: base("Enabled", parent)
|
|
{
|
|
_value = enabledState;
|
|
}
|
|
|
|
|
|
public override void SetItem(object values, DriveProvider provider)
|
|
{
|
|
|
|
Kerberos settings = (Kerberos)_parent;
|
|
|
|
|
|
settings.SetSetting("EncryptionAlgorithm", "0");
|
|
settings.SetSetting("KeyVersion", "3");
|
|
|
|
|
|
|
|
settings.SetSetting("KrbEnabled", values.ToString().ToLower());
|
|
|
|
settings.Apply();
|
|
|
|
_parent.Clear();
|
|
|
|
|
|
}
|
|
|
|
public override object GetReturnObject()
|
|
{
|
|
return new NameValuePairItem(Name, Value);
|
|
}
|
|
} // End KerberosDriveItem Class
|
|
|
|
|
|
class KerberosKey : SettingsItem
|
|
{
|
|
public KerberosKey(SettingsContainer parent)
|
|
: base("MasterKey",parent)
|
|
{
|
|
_value = string.Empty;
|
|
}
|
|
|
|
public override void SetItem(object values, DriveProvider provider)
|
|
{
|
|
Kerberos settings = (Kerberos)_parent;
|
|
|
|
|
|
string password=null;
|
|
|
|
if (values == null)
|
|
{
|
|
provider.Host.UI.Write("Enter password: ");
|
|
password = CredentialManager.GetStringFromSecureString(provider.Host.UI.ReadLineAsSecureString());
|
|
|
|
}
|
|
else if (values is System.Security.SecureString)
|
|
{
|
|
password = CredentialManager.GetStringFromSecureString(values as System.Security.SecureString);
|
|
}
|
|
else if (values is string)
|
|
{
|
|
password = values.ToString();
|
|
}
|
|
|
|
string hash = Convert.ToBase64String(MD4.ComputeHash(Encoding.Unicode.GetBytes(password)));
|
|
settings.SetSetting("MasterKey", hash);
|
|
settings.Apply();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class Kerberos : SettingsContainer
|
|
{
|
|
|
|
public Kerberos(DriveItem parent)
|
|
: base("Kerberos",parent)
|
|
{
|
|
}
|
|
|
|
|
|
public override void Update()
|
|
{
|
|
// only enable will update the container
|
|
}
|
|
|
|
public void Apply()
|
|
{
|
|
_refToSettings.Put(_settingsObj);
|
|
}
|
|
|
|
public override void GetChildItems(ChildWriter writer)
|
|
{
|
|
IWsmanConnection conn = ((AmtRootService)GetRoot()).Connection;
|
|
_refToSettings = conn.NewReference("SELECT * FROM AMT_KerberosSettingData WHERE InstanceID='Intel (r) AMT: Kerberos Settings'");
|
|
|
|
|
|
_settingsObj = _refToSettings.Get();
|
|
|
|
bool enabledState = bool.Parse(_settingsObj.GetProperty("KrbEnabled").ToString());
|
|
|
|
writer.Add(new KerberosDriveItem(enabledState,this));
|
|
|
|
writer.Add(new KerberosKey(this));
|
|
|
|
|
|
if (!HasSetting("MaximumClockTolerance"))
|
|
{
|
|
SetSetting("MaximumClockTolerance", "5");
|
|
}
|
|
|
|
writer.Add(new UIntSetting("MaximumClockTolerance", this));
|
|
|
|
writer.Add(new OptionalStringSetting("RealmName", this));
|
|
|
|
}
|
|
|
|
public override object GetReturnObject()
|
|
{
|
|
return new NameValuePairItem(Name, Value);
|
|
}
|
|
}
|
|
|
|
|
|
class EthernetSettings : SettingsContainer
|
|
{
|
|
public EthernetSettings(IManagedInstance settingObj, DriveItem parent)
|
|
: base(settingObj.GetProperty("InstanceID").ToString(), parent)
|
|
{
|
|
_settingsObj = settingObj;
|
|
_refToSettings = settingObj.Connection.NewReference(settingObj.ResourceUri);
|
|
_refToSettings.AddSelector("InstanceID", settingObj.GetProperty("InstanceID").ToString());
|
|
|
|
}
|
|
|
|
|
|
public override void GetChildItems(ChildWriter writer)
|
|
{
|
|
|
|
if (HasSetting("VLANTag"))
|
|
writer.Add(new UIntSetting("VLANTag", this));
|
|
|
|
if (HasSetting("SharedMAC"))
|
|
writer.Add(new BooleanSetting("SharedMAC", this));
|
|
|
|
if (HasSetting("MACAddress"))
|
|
writer.Add(new StringSetting("MACAddress", this));
|
|
|
|
|
|
if (HasSetting("LinkIsUp"))
|
|
writer.Add(new BooleanSetting("LinkIsUp", this));
|
|
|
|
|
|
writer.Add(new ValueMapsSetting("LinkPolicy", ValueList.LinkPolicy, this));
|
|
|
|
|
|
if (HasSetting("LinkPreference"))
|
|
writer.Add(new ValueMapSetting("LinkPreference", ValueList.LinkControl, this));
|
|
|
|
if (HasSetting("LinkControl"))
|
|
writer.Add(new ValueMapSetting("LinkControl", ValueList.LinkControl, this));
|
|
|
|
if (HasSetting("SharedStaticIp"))
|
|
writer.Add(new BooleanSetting("SharedStaticIp", this));
|
|
|
|
if (HasSetting("SharedDynamicIP"))
|
|
writer.Add(new BooleanSetting("SharedStaticIp", this));
|
|
|
|
if (HasSetting("IpSyncEnabled"))
|
|
writer.Add(new BooleanSetting("IpSyncEnabled", this));
|
|
|
|
if (HasSetting("DHCPEnabled"))
|
|
writer.Add(new BooleanSetting("DHCPEnabled", this));
|
|
|
|
if (HasSetting("IPAddress"))
|
|
writer.Add(new StringSetting("IPAddress", this));
|
|
|
|
if (HasSetting("SubnetMask"))
|
|
writer.Add(new StringSetting("SubnetMask", this));
|
|
|
|
if (HasSetting("DefaultGateway"))
|
|
writer.Add(new StringSetting("DefaultGateway", this));
|
|
|
|
if (HasSetting("PrimaryDNS"))
|
|
writer.Add(new StringSetting("PrimaryDNS", this));
|
|
|
|
if (HasSetting("SecondaryDNS"))
|
|
writer.Add(new StringSetting("SecondaryDNS", this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Networks : DriveContainer
|
|
{
|
|
public Networks(DriveItem parent)
|
|
: base("Networks", parent)
|
|
{
|
|
}
|
|
|
|
public override void GetChildItems(ChildWriter writer)
|
|
{
|
|
|
|
IWsmanConnection conn = ((AmtRootService)GetRoot()).Connection;
|
|
foreach (IWsmanItem item in conn.ExecQuery("SELECT * FROM AMT_EthernetPortSettings"))
|
|
{
|
|
writer.Add(new EthernetSettings(item.Object, this));
|
|
}
|
|
}
|
|
|
|
|
|
public override object GetReturnObject()
|
|
{
|
|
return new NameValuePairItem(Name, Value);
|
|
}
|
|
}
|
|
|
|
class Protocols : DriveContainer
|
|
{
|
|
public Protocols(DriveItem parent)
|
|
: base("Protocol", parent)
|
|
{
|
|
}
|
|
|
|
public override void GetChildItems(ChildWriter writer)
|
|
{
|
|
writer.Add(new Digest(this));
|
|
writer.Add(new Kerberos(this));
|
|
writer.Add(new TLSService(this));
|
|
writer.Add(new Wired8021xService(this));
|
|
writer.Add(new WirelessService(this));
|
|
}
|
|
|
|
public override object GetReturnObject()
|
|
{
|
|
return new NameValuePairItem(Name, Value);
|
|
}
|
|
} // End Protocols Container
|
|
|
|
|
|
class RegisteredProfiles : DriveContainer
|
|
{
|
|
public RegisteredProfiles(DriveItem parent)
|
|
: base("RegisteredProfiles", parent)
|
|
{
|
|
}
|
|
|
|
public override void GetChildItems(ChildWriter writer)
|
|
{
|
|
IWsmanConnection conn = ((AmtRootService)GetRoot()).Connection;
|
|
foreach (IWsmanItem item in conn.ExecQuery("SELECT * FROM CIM_RegisteredProfile"))
|
|
{
|
|
string name = item.Object.GetProperty("RegisteredName").ToString();
|
|
string version = item.Object.GetProperty("RegisteredVersion").ToString();
|
|
|
|
writer.Add(new DriveEntry(name, version, this));
|
|
}
|
|
}
|
|
|
|
public override object GetReturnObject()
|
|
{
|
|
return new NameValuePairItem(Name, Value);
|
|
}
|
|
} // End Protocols Container
|
|
|
|
|
|
class WebUIService : DriveItem
|
|
{
|
|
|
|
public WebUIService(DriveItem parent)
|
|
: base("WebUI",null,parent)
|
|
{
|
|
IWsmanConnection conn = ((AmtRootService)GetRoot()).Connection;
|
|
IManagedReference refToServcie = conn.NewReference("AMT_WebUIService");
|
|
IManagedInstance service = refToServcie.Get();
|
|
string state = service.GetProperty("EnabledState").ToString();
|
|
_value = state.Equals("2") || state.Equals("6");
|
|
}
|
|
|
|
public override void SetItem(object values, DriveProvider provider)
|
|
{
|
|
bool changeTo = bool.Parse(values.ToString());
|
|
{
|
|
IWsmanConnection conn = ((AmtRootService)GetRoot()).Connection;
|
|
IManagedReference refToService = conn.NewReference("AMT_WebUIService");
|
|
IManagedInstance inputObj = refToService.CreateMethodInput("RequestStateChange");
|
|
|
|
if (changeTo)
|
|
inputObj.SetProperty("RequestedState", "2");
|
|
else
|
|
inputObj.SetProperty("RequestedState", "3");
|
|
IManagedInstance outObj = refToService.InvokeMethod(inputObj);
|
|
if (!outObj.GetProperty("ReturnValue").ToString().Equals("0"))
|
|
AmtException.ThrowInvokeError(outObj);
|
|
else
|
|
_value = changeTo;
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public override object GetReturnObject()
|
|
{
|
|
return new NameValuePairItem(Name, Value);
|
|
}
|
|
}
|
|
|
|
class Services : DriveContainer
|
|
{
|
|
public Services(DriveItem parent)
|
|
: base("Services", parent)
|
|
{
|
|
}
|
|
|
|
public override void GetChildItems(ChildWriter writer)
|
|
{
|
|
|
|
writer.Add(new WebUIService(this));
|
|
}
|
|
|
|
|
|
} // End Protocols Container
|
|
|
|
} //End EtcSerivce Class
|
|
} //End namespace
|
|
|