296 lines
9.4 KiB
C#
296 lines
9.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Intel.Management.Wsman;
|
|
|
|
namespace Intel.Management.PSModule.Amt
|
|
{
|
|
class KVMService : SettingsContainer
|
|
{
|
|
public KVMService(DriveItem parent) :
|
|
base("KVM", parent)
|
|
{
|
|
}
|
|
|
|
public override void GetChildItems(ChildWriter writer)
|
|
{
|
|
IWsmanConnection conn = ((AmtRootService)GetRoot()).Connection;
|
|
|
|
_settingsObj=null;
|
|
_refToSettings=null;
|
|
|
|
IWsmanEnumeration colObj = conn.ExecQuery("SELECT * FROM CIM_KVMRedirectionSAP");
|
|
foreach (IWsmanItem item in colObj)
|
|
{
|
|
|
|
// KVM access point found so the system is KVM capabile
|
|
if (item.Object.GetProperty("Name").ToString().Equals("KVM Redirection Service Access Point"))
|
|
{
|
|
|
|
// original string state = item.Object.GetProperty("EnabledState").ToString();
|
|
string state = null;
|
|
state = item.Object.GetProperty("EnabledState").ToString();
|
|
|
|
writer.Add(new KvmEnabled(state, this));
|
|
|
|
|
|
_refToSettings = conn.NewReference("IPS_KVMRedirectionSettingData");
|
|
_refToSettings.AddSelector("InstanceID", "Intel(r) KVM Redirection Settings");
|
|
_settingsObj = _refToSettings.Get();
|
|
|
|
writer.Add(new KvmBIOSEnabled(this));
|
|
writer.Add(new KvmOptIn(this));
|
|
writer.Add(new OptInTimeout(this));
|
|
writer.Add(new SessionTimeout(this));
|
|
writer.Add(new ValueMapSetting("DefaultScreen", ValueList.DefaultScreen, this));
|
|
writer.Add(new StringSetting("RFBPassword", this));
|
|
writer.Add(new StandardPort(this));
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EnableSAP(string state)
|
|
{
|
|
|
|
|
|
IWsmanConnection conn = ((AmtRootService)GetRoot()).Connection;
|
|
IManagedReference kvmRef = conn.NewReference("CIM_KVMRedirectionSAP");
|
|
kvmRef.AddSelector("Name", "KVM Redirection Service Access Point");
|
|
|
|
IManagedInstance inputObj = kvmRef.CreateMethodInput("RequestStateChange");
|
|
inputObj.SetProperty("RequestedState", state);
|
|
|
|
IManagedInstance outObj = kvmRef.InvokeMethod(inputObj);
|
|
string result = outObj.GetProperty("ReturnValue").ToString();
|
|
if (result.Equals("5"))
|
|
AmtException.ThrowInvokeError(outObj, "Invalid Parameter");
|
|
else if (result.Equals("32806"))
|
|
AmtException.ThrowInvokeError(outObj, "Flash write limit exceeded");
|
|
else if (result.Equals("34843"))
|
|
AmtException.ThrowInvokeError(outObj, "Audit log failure");
|
|
}
|
|
|
|
|
|
class RFBPassword : SettingsItem
|
|
{
|
|
public RFBPassword(SettingsContainer parent)
|
|
: base("RFBPassword", parent)
|
|
{
|
|
int sec = int.Parse(parent.GetSetting("OptInPolicyTimeout"));
|
|
_value = string.Empty;
|
|
|
|
}
|
|
|
|
public override void SetItem(object values, DriveProvider provider)
|
|
{
|
|
KVMService service = _parent as KVMService;
|
|
|
|
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();
|
|
}
|
|
|
|
service.SetSetting("RFBPassword", password);
|
|
|
|
|
|
|
|
_value = string.Empty;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class OptInTimeout : SettingsItem
|
|
{
|
|
|
|
public OptInTimeout(SettingsContainer parent)
|
|
: base("ConsentDisplayTimeout", parent)
|
|
{
|
|
int sec = 0;
|
|
if (!int.TryParse(parent.GetSetting("OptInPolicyTimeout"), out sec))
|
|
{
|
|
//Failed
|
|
_value = "Error Loading Value";
|
|
}
|
|
else
|
|
{
|
|
// int sec = int.Parse(parent.GetSetting("OptInPolicyTimeout"));
|
|
_value = new TimeSpan(0, 0, sec);
|
|
}
|
|
|
|
}
|
|
|
|
public override void SetItem(object values, DriveProvider provider)
|
|
{
|
|
KVMService service = _parent as KVMService;
|
|
|
|
TimeSpan span = TimeSpan.Parse(values.ToString());
|
|
service.SetSetting("OptInPolicyTimeout", span.TotalSeconds.ToString());
|
|
|
|
_value = span;
|
|
}
|
|
}
|
|
|
|
|
|
class SessionTimeout : SettingsItem
|
|
{
|
|
|
|
public SessionTimeout(SettingsContainer parent)
|
|
: base("SessionTimeout", parent)
|
|
{
|
|
// int min = int.Parse(parent.GetSetting("SessionTimeout"));
|
|
//_value = new TimeSpan(0, min, 0);
|
|
|
|
int min = 0;
|
|
if (!int.TryParse(parent.GetSetting("SessionTimeout"), out min))
|
|
{
|
|
//Failed
|
|
_value = "Error Loading Value";
|
|
}
|
|
else
|
|
{
|
|
// int sec = int.Parse(parent.GetSetting("OptInPolicyTimeout"));
|
|
_value = new TimeSpan(0, min, 0);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public override void SetItem(object values, DriveProvider provider)
|
|
{
|
|
KVMService service = _parent as KVMService;
|
|
TimeSpan span = TimeSpan.Parse(values.ToString());
|
|
|
|
service.SetSetting("SessionTimeout", span.TotalMinutes.ToString());
|
|
_value = span;
|
|
|
|
}
|
|
}
|
|
|
|
class StandardPort : SettingsItem
|
|
{
|
|
|
|
public StandardPort(SettingsContainer parent)
|
|
: base("UseStandardPort", parent)
|
|
{
|
|
bool val = false;
|
|
if (!bool.TryParse(parent.GetSetting("Is5900PortEnabled"), out val))
|
|
{
|
|
//Failed
|
|
_value = "Error Loading Value";
|
|
}
|
|
else
|
|
{
|
|
_value = val;
|
|
}
|
|
|
|
//_value = bool.Parse(parent.GetSetting("Is5900PortEnabled"));
|
|
|
|
}
|
|
|
|
public override void SetItem(object values, DriveProvider provider)
|
|
{
|
|
KVMService service = _parent as KVMService;
|
|
service.SetSetting("Is5900PortEnabled",values.ToString().ToLower());
|
|
_value = bool.Parse(values.ToString());
|
|
}
|
|
}
|
|
|
|
class KvmOptIn : SettingsItem
|
|
{
|
|
public KvmOptIn( SettingsContainer parent)
|
|
: base("ConsentRequired", parent)
|
|
{
|
|
bool val = false;
|
|
if (!bool.TryParse(parent.GetSetting("OptInPolicy"), out val))
|
|
{
|
|
//Failed
|
|
_value = "Error Loading Value";
|
|
}
|
|
else
|
|
{
|
|
_value = val;
|
|
}
|
|
// _value = bool.Parse(parent.GetSetting("OptInPolicy"));
|
|
}
|
|
|
|
public override void SetItem(object values, DriveProvider provider)
|
|
{
|
|
KVMService service = _parent as KVMService;
|
|
|
|
service.SetSetting("OptInPolicy",values.ToString().ToLower());
|
|
_value = bool.Parse(values.ToString().ToLower());
|
|
}
|
|
}
|
|
|
|
class KvmBIOSEnabled : SettingsItem
|
|
{
|
|
public KvmBIOSEnabled(SettingsContainer parent)
|
|
: base("EnabledByMEBx", parent)
|
|
{
|
|
bool val = false;
|
|
if (!bool.TryParse(parent.GetSetting("EnabledByMEBx"), out val))
|
|
{
|
|
//Failed
|
|
_value = "Error Loading Value";
|
|
}
|
|
else
|
|
{
|
|
_value = val;
|
|
}
|
|
//_value = bool.Parse(parent.GetSetting("EnabledByMEBx"));
|
|
}
|
|
}
|
|
|
|
class KvmEnabled : SettingsItem
|
|
{
|
|
public KvmEnabled(string state, SettingsContainer parent)
|
|
: base("AccessPointEnabled",parent)
|
|
{
|
|
if (state != null)
|
|
{
|
|
_value = state.Equals("2") || state.Equals("6");
|
|
}
|
|
else
|
|
{
|
|
_value = "Error loading value";
|
|
}
|
|
}
|
|
|
|
public override void SetItem(object values, DriveProvider provider)
|
|
{
|
|
KVMService service = _parent as KVMService;
|
|
bool changeTo = bool.Parse(values.ToString());
|
|
if (changeTo)
|
|
service.EnableSAP("2");
|
|
else
|
|
service.EnableSAP("3");
|
|
|
|
_value = changeTo;
|
|
}
|
|
}
|
|
|
|
}// end KVMService
|
|
}
|