283 lines
13 KiB
C#
283 lines
13 KiB
C#
//----------------------------------------------------------------------------
|
|
//
|
|
// Copyright (c) Intel Corporation, 2012-2014 All Rights Reserved.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Security.Cryptography;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using Intel.Manageability;
|
|
using Intel.Manageability.Exceptions;
|
|
using Intel.Manageability.RemoteAccess;
|
|
|
|
namespace RemoteAccessSample
|
|
{
|
|
class RemoteAccessFunctionality
|
|
{
|
|
private const string LEAF_CERT = @"..\..\LeafCert.p12";
|
|
|
|
#region - Create Trigers -
|
|
|
|
public static void CreateUserInitiatedTrigger(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
using (X509Certificate2 certificate = new X509Certificate2(LEAF_CERT, "q", X509KeyStorageFlags.Exportable))
|
|
{
|
|
MPS mps = new MPS("bbb.intel.com", 16992, certificate, "yyyy");
|
|
UserInitiatedTrigger userInitiatedTrigger = new UserInitiatedTrigger(100, UserInitiatedPermission.EnableAll);
|
|
MPSPair pair = new MPSPair(mps);
|
|
MPSList mpsList = new MPSList(pair, null);
|
|
amt.RemoteAccess.CreateTrigger(userInitiatedTrigger, mpsList);
|
|
}
|
|
Console.WriteLine("\n CreateUserInitiatedTrigger succeeded\n");
|
|
}
|
|
catch (RemoteAccessManageabiltyException ex)
|
|
{
|
|
PrintException("CreateUserInitiatedTrigger", ex);
|
|
}
|
|
catch (CryptographicException ex)
|
|
{
|
|
throw new CryptographicException("Certificate error: " + ex.Message);
|
|
}
|
|
}
|
|
|
|
public static void CreateAlertTrigger(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
MPS primaryMps = new MPS("192.168.14.15", 16992, "admin", "P@ssw0rd", "yyyy");
|
|
MPS secondaryMps = new MPS("aaa.intel.com", 16992, "admin", "P@ssw0rd", string.Empty);
|
|
MPSPair pair = new MPSPair(primaryMps, secondaryMps);
|
|
MPSList mpsList = new MPSList(pair, null);
|
|
AlertTrigger alertTrigger = new AlertTrigger(0);
|
|
amt.RemoteAccess.CreateTrigger(alertTrigger, mpsList);
|
|
Console.WriteLine("\n CreateAlertTrigger succeeded\n");
|
|
}
|
|
catch (RemoteAccessManageabiltyException ex)
|
|
{
|
|
PrintException("CreateAlertTrigger", ex);
|
|
}
|
|
}
|
|
|
|
public static void CreatePeriodicTrigger(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
PeriodicTrigger periodicTrigger = new PeriodicTrigger(15, new DailyInterval(5, 20));
|
|
MPS primaryExternalMps = new MPS("192.168.14.15", 16992, "admin", "P@ssw0rd", "yyyy");
|
|
MPS primaryInternalMps = new MPS("internal1.intel.com", 16992, "admin", "P@ssw0rd", "yyyy");
|
|
MPSPair external = new MPSPair(primaryExternalMps);
|
|
MPSPair internalP = new MPSPair(primaryInternalMps);
|
|
amt.RemoteAccess.CreateTrigger(periodicTrigger, external, internalP);
|
|
|
|
Console.WriteLine("\n CreatePeriodicTrigger succeeded\n");
|
|
}
|
|
catch (RemoteAccessManageabiltyException ex)
|
|
{
|
|
PrintException("CreatePeriodicTrigger", ex);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region - Triggers and MPSs details -
|
|
|
|
public static void GetUserInitiatedTriggerDetails(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
UserInitiatedTrigger userInitiatedTrigger;
|
|
amt.RemoteAccess.GetTriggerDetails(out userInitiatedTrigger);
|
|
Console.WriteLine("\n\nTriger Details:");
|
|
Console.WriteLine("----------------");
|
|
Console.WriteLine("TunnelLifeTime: " + userInitiatedTrigger.TunnelLifeTime);
|
|
Console.WriteLine("Permissions: " + userInitiatedTrigger.UserInitiatedPermission);
|
|
Console.WriteLine("External MPSs Address: " + (string.IsNullOrEmpty(userInitiatedTrigger.MPServersAddress[0]) == true ? "" : (userInitiatedTrigger.MPServersAddress[0]) + " ") + (string.IsNullOrEmpty(userInitiatedTrigger.MPServersAddress[1]) == true ? "" : userInitiatedTrigger.MPServersAddress[1]));
|
|
Console.WriteLine("Internal MPSs Address: " + (string.IsNullOrEmpty(userInitiatedTrigger.InternalMPServersAddress[0]) == true ? "" : (userInitiatedTrigger.InternalMPServersAddress[0]) + " ") + (string.IsNullOrEmpty(userInitiatedTrigger.InternalMPServersAddress[1]) == true ? "" : userInitiatedTrigger.InternalMPServersAddress[1]));
|
|
Console.WriteLine("\n\n\nGetUserInitiatedTriggerDetails succeeded\n");
|
|
}
|
|
catch (RemoteAccessManageabiltyException ex)
|
|
{
|
|
PrintException("GetUserInitiatedTriggerDetails", ex);
|
|
}
|
|
}
|
|
|
|
public static void GetAlertTriggerDetails(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
AlertTrigger alertTrigger;
|
|
amt.RemoteAccess.GetTriggerDetails(out alertTrigger);
|
|
Console.WriteLine("\n\nTriger Details:");
|
|
Console.WriteLine("----------------");
|
|
Console.WriteLine("TunnelLifeTime: " + alertTrigger.TunnelLifeTime);
|
|
Console.WriteLine("External MPSs Address: " + (string.IsNullOrEmpty(alertTrigger.MPServersAddress[0]) == true ? "" : (alertTrigger.MPServersAddress[0]) + " ") + (string.IsNullOrEmpty(alertTrigger.MPServersAddress[1]) == true ? "" : alertTrigger.MPServersAddress[1]));
|
|
Console.WriteLine("Internal MPSs Address: " + (string.IsNullOrEmpty(alertTrigger.InternalMPServersAddress[0]) == true ? "" : (alertTrigger.InternalMPServersAddress[0]) + " ") + (string.IsNullOrEmpty(alertTrigger.InternalMPServersAddress[1]) == true ? "" : alertTrigger.InternalMPServersAddress[1]));
|
|
Console.WriteLine("\n\n\nGetAlertTriggerDetails succeeded\n");
|
|
}
|
|
catch (RemoteAccessManageabiltyException ex)
|
|
{
|
|
PrintException("GetAlertTriggerDetails", ex);
|
|
}
|
|
}
|
|
|
|
public static void GetPeriodicTriggerDetails(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
PeriodicTrigger periodicTrigger;
|
|
amt.RemoteAccess.GetTriggerDetails(out periodicTrigger);
|
|
Console.WriteLine("\n\nTriger Details:");
|
|
Console.WriteLine("----------------");
|
|
string interval = periodicTrigger.DailyInterval == null
|
|
? periodicTrigger.PeriodicInterval.Value.TotalMinutes + " minutes"
|
|
: "day at " + periodicTrigger.DailyInterval.Value.Hour + ":" +
|
|
periodicTrigger.DailyInterval.Value.Minutes;
|
|
Console.WriteLine("Interval: Every " + interval);
|
|
Console.WriteLine("TunnelLifeTime: " + periodicTrigger.TunnelLifeTime);
|
|
Console.WriteLine("External MPSs Address: " + (string.IsNullOrEmpty(periodicTrigger.MPServersAddress[0]) == true ? "" : (periodicTrigger.MPServersAddress[0]) + " ") + (string.IsNullOrEmpty(periodicTrigger.MPServersAddress[1]) == true ? "" : periodicTrigger.MPServersAddress[1]));
|
|
Console.WriteLine("Internal MPSs Address: " + (string.IsNullOrEmpty(periodicTrigger.InternalMPServersAddress[0]) == true ? "" : (periodicTrigger.InternalMPServersAddress[0]) + " ") + (string.IsNullOrEmpty(periodicTrigger.InternalMPServersAddress[1]) == true ? "" : periodicTrigger.InternalMPServersAddress[1]));
|
|
Console.WriteLine("\n\n\nGetPeriodicTriggerDetails succeeded\n");
|
|
}
|
|
catch (RemoteAccessManageabiltyException ex)
|
|
{
|
|
PrintException("GetPeriodicTriggerDetails", ex);
|
|
}
|
|
}
|
|
|
|
public static void GetAllTriggersDetails(IAMTInstance amt)
|
|
{
|
|
|
|
try
|
|
{
|
|
List<Trigger> triggersCollection = amt.RemoteAccess.GetAllTriggersDetails();
|
|
Console.WriteLine("\n\nTrigers Details:");
|
|
Console.WriteLine("----------------");
|
|
foreach (Trigger triggerItem in triggersCollection)
|
|
{
|
|
Console.WriteLine("TrigerType: " + triggerItem.TriggerType.ToString());
|
|
Console.WriteLine("TunnelLifeTime: " + triggerItem.TunnelLifeTime);
|
|
Console.WriteLine("External MPSs Address: " + (string.IsNullOrEmpty(triggerItem.MPServersAddress[0]) == true ? "" : (triggerItem.MPServersAddress[0]) + " ") + (string.IsNullOrEmpty(triggerItem.MPServersAddress[1]) == true ? "" : triggerItem.MPServersAddress[1]));
|
|
Console.WriteLine("Internal MPSs Address: " + (string.IsNullOrEmpty(triggerItem.InternalMPServersAddress[0]) == true ? "" : (triggerItem.InternalMPServersAddress[0]) + " ") + (string.IsNullOrEmpty(triggerItem.InternalMPServersAddress[1]) == true ? "" : triggerItem.InternalMPServersAddress[1]));
|
|
}
|
|
Console.WriteLine("\n\n\nGetAllTriggersDetails succeeded\n");
|
|
}
|
|
catch (RemoteAccessManageabiltyException ex)
|
|
{
|
|
PrintException("GetAllTriggersDetails", ex);
|
|
}
|
|
}
|
|
|
|
public static void GetMPSDetails(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
MPS mps = amt.RemoteAccess.GetMPSDetails("aaa.intel.com");
|
|
Console.WriteLine("\n\nDetails of the requested MPS:");
|
|
Console.WriteLine("----------------");
|
|
|
|
Console.WriteLine("Address: " + mps.Address + " Port: " + mps.Port + " UserName: " + mps.Username);
|
|
|
|
Console.WriteLine("\n\nGet selected MPS details succeeded\n");
|
|
}
|
|
catch (RemoteAccessManageabiltyException ex)
|
|
{
|
|
PrintException("GetMPSDetails", ex);
|
|
}
|
|
}
|
|
|
|
public static void GetAllMPSsDetails(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
List<MPS> mpsCollection = amt.RemoteAccess.GetAllMPSsDetails();
|
|
Console.WriteLine("\n\nMPSs Details:");
|
|
Console.WriteLine("----------------");
|
|
foreach (MPS mpsItem in mpsCollection)
|
|
{
|
|
Console.WriteLine("Address: " + mpsItem.Address + " Port: " + mpsItem.Port + " UserName: " + mpsItem.Username);
|
|
}
|
|
Console.WriteLine("\n\nGet all MPSs details succeeded\n");
|
|
}
|
|
catch (RemoteAccessManageabiltyException ex)
|
|
{
|
|
PrintException("GetAllMPSsDetails", ex);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region -Remove Triggers -
|
|
|
|
public static void RemoveTrigger(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
amt.RemoteAccess.RemoveTrigger(TriggerType.Alert);
|
|
Console.WriteLine("\n\nRemove trigger succeeded\n");
|
|
}
|
|
catch (RemoteAccessManageabiltyException ex)
|
|
{
|
|
PrintException("RemoveTrigger", ex);
|
|
}
|
|
}
|
|
|
|
public static void RemoveAllTriggers(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
amt.RemoteAccess.RemoveAllTriggers();
|
|
Console.WriteLine("\n\nRemove all triggers succeeded\n");
|
|
}
|
|
catch (RemoteAccessManageabiltyException ex)
|
|
{
|
|
PrintException("RemoveAllTriggers", ex);
|
|
}
|
|
}
|
|
|
|
public static void UpdateMPS(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
amt.RemoteAccess.UpdateMPS(new MPS("bbb.intel.com", 16997, "admin", "P@ssw0rd", string.Empty));
|
|
Console.WriteLine("\n\nUpdate MPS succeeded\n");
|
|
}
|
|
catch (RemoteAccessManageabiltyException ex)
|
|
{
|
|
PrintException("UpdateMPS", ex);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
public static void CloseRemoteAccessConnection(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
amt.RemoteAccess.CloseRemoteAccessConnection();
|
|
Console.WriteLine("\n\nClose remote access connection succeeded\n");
|
|
}
|
|
catch (RemoteAccessManageabiltyException ex)
|
|
{
|
|
PrintException("CloseRemoteAccessConnection", ex);
|
|
}
|
|
}
|
|
|
|
static void PrintException(string methodName, RemoteAccessManageabiltyException ex)
|
|
{
|
|
Console.WriteLine(methodName + " throw: " + ex.Message);
|
|
Console.WriteLine("Details:");
|
|
Console.WriteLine("========");
|
|
Console.WriteLine("\t- Machine Origin : {0}", ex.MachineOrigin);
|
|
Console.WriteLine("\t- HLAPI Source Function: {0}", ex.Source);
|
|
if (ex.PT_STATUS != null)
|
|
Console.WriteLine("\t- Return Value : {0}", ex.PT_STATUS);
|
|
if (ex.Tip != string.Empty)
|
|
Console.WriteLine("\t- Counsel : {0}", ex.Tip);
|
|
}
|
|
}
|
|
}
|