156 lines
5.4 KiB
C++
156 lines
5.4 KiB
C++
//----------------------------------------------------------------------------
|
||
//
|
||
// Copyright (C) 2008 Intel Corporation
|
||
//
|
||
// File: RemoteAccessAdminSample.cpp
|
||
//
|
||
// Contents: Sample code for an Intel<65> AMT Network client.
|
||
//
|
||
//----------------------------------------------------------------------------
|
||
#include "RemoteAccessAdminSample.h"
|
||
#include "RemoteAccessAdminFlow.h"
|
||
#include "CommonDefinitions.h"
|
||
#include "CmdLineArguments.h"
|
||
#include "LogicException.h"
|
||
|
||
// Include from CIM Framework
|
||
#include "CimOpenWsmanClient.h"
|
||
|
||
#include <Windows.h>
|
||
|
||
using namespace std;
|
||
using namespace Intel::Manageability::Exceptions;
|
||
using namespace Intel::Manageability::Cim::Typed;
|
||
using namespace Intel::WSManagement;
|
||
using namespace ExceptionNamespace;
|
||
|
||
|
||
int main(int argc, char* argv[])
|
||
{
|
||
// set default dll lookup directory to system
|
||
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32);
|
||
|
||
PT_STATUS status = PT_STATUS_SUCCESS;
|
||
|
||
CmdLineArguments::Format format;
|
||
|
||
// Add the sample-specific options arguments
|
||
format.AddArg(CMD_ADMIN_MPSERVER, false, false, true, DESCRIPTION_ADMIN_MPSERVER);
|
||
format.AddArg(CMD_ADMIN_POLICY, false, false, true, DESCRIPTION_ADMIN_POLICY);
|
||
format.AddArg(CMD_ADMIN_USER_INTERFACE, false, false, true, DESCRIPTION_ADMIN_USER_INTERFACE);
|
||
format.AddArg(CMD_API_TEST, false, false, true, DESCRIPTION_API_TEST);
|
||
format.AddArg(CMD_CLEAN_SAMPLE, false, false, true, DESCRIPTION_CLEAN_SAMPLE);
|
||
|
||
// Add the general arguments
|
||
format.AddArg(CMD_VERBOSE, false, false, false, "");
|
||
format.AddArg(CMD_USER, true, false, false, "");
|
||
format.AddArg(CMD_PASS, true, false, false, "");
|
||
format.AddArg(CMD_CERT_NAME, true, false, false, "");
|
||
format.AddArg(CMD_HOST, true, true, false, "");
|
||
format.AddArg(CMD_TLS, false, false, false, "");
|
||
format.AddArg(CMD_KRB, false, false, false, "");
|
||
format.AddArg(CMD_PROXY, true, false, false, "");
|
||
format.AddArg(CMD_PROXY_USERNAME, true, false, false, "");
|
||
format.AddArg(CMD_PROXY_PASS, true, false, false, "");
|
||
format.AddArg(CMD_ACCEPT_SELF_CIGNED_CERT, false, false, false, "");
|
||
|
||
if (argc == 1)
|
||
{
|
||
cout << format.CreateUsage(argv[0]);
|
||
return status;
|
||
}
|
||
|
||
try
|
||
{
|
||
CmdLineArguments cmdLineArguments;
|
||
cmdLineArguments.Parse(argc, argv, format);
|
||
CimOpenWsmanClient wsmanClient( cmdLineArguments.GetArgValue(CMD_HOST),
|
||
cmdLineArguments.ArgExists(CMD_TLS) ? AMT_SECURE_PORT : AMT_UNSECURE_PORT,
|
||
cmdLineArguments.ArgExists(CMD_TLS),
|
||
cmdLineArguments.ArgExists(CMD_KRB) ? KERBEROS : DIGEST,
|
||
cmdLineArguments.GetArgValue(CMD_USER),
|
||
cmdLineArguments.GetArgValue(CMD_PASS),
|
||
cmdLineArguments.ArgExists(CMD_PROXY) ? cmdLineArguments.GetArgValue(CMD_PROXY): "",
|
||
cmdLineArguments.ArgExists(CMD_PROXY_USERNAME) ? cmdLineArguments.GetArgValue(CMD_PROXY_USERNAME): "",
|
||
cmdLineArguments.ArgExists(CMD_PROXY_PASS) ? cmdLineArguments.GetArgValue(CMD_PROXY_PASS): "",
|
||
false, // Local certificate store
|
||
cmdLineArguments.ArgExists(CMD_CERT_NAME) ? cmdLineArguments.GetArgValue(CMD_CERT_NAME): "",
|
||
cmdLineArguments.ArgExists(CMD_LOCAL) ? OID_LOCAL : OID_REMOTE,
|
||
cmdLineArguments.ArgExists(CMD_ACCEPT_SELF_CIGNED_CERT));
|
||
|
||
bool verbose = cmdLineArguments.ArgExists(CMD_VERBOSE);
|
||
string userRequest = cmdLineArguments.GetSelectedOptionName();
|
||
|
||
if (format.CompareStringCaseSensitive(userRequest, CMD_ADMIN_MPSERVER) == true)
|
||
{
|
||
ManipulateMpServers(&wsmanClient, verbose);
|
||
}
|
||
else if (format.CompareStringCaseSensitive(userRequest, CMD_ADMIN_POLICY) == true)
|
||
{
|
||
ManipulatRemoteAccessPolicies(&wsmanClient, verbose);
|
||
}
|
||
else if (format.CompareStringCaseSensitive(userRequest, CMD_ADMIN_USER_INTERFACE) == true)
|
||
{
|
||
ManipulateUserInterface(&wsmanClient, verbose);
|
||
}
|
||
else if (format.CompareStringCaseSensitive(userRequest, CMD_CLEAN_SAMPLE) == true)
|
||
{
|
||
CleanupSample(&wsmanClient, verbose);
|
||
}
|
||
else if (format.CompareStringCaseSensitive(userRequest, CMD_API_TEST) == true)
|
||
{
|
||
APITest(&wsmanClient, verbose);
|
||
}
|
||
else
|
||
{
|
||
throw CmdLineException("Could not find a value for the option.");
|
||
}
|
||
}
|
||
|
||
catch (CimException& exp)
|
||
{
|
||
cerr << endl << "--------------------CimException--------------------" << endl;
|
||
cerr << exp.what() << endl;;
|
||
status = PTSDK_STATUS_NETWORK_ERROR;
|
||
}
|
||
catch (ConversionException &exp)
|
||
{
|
||
cerr << endl << "--------------------ConversionException--------------------" << endl;
|
||
cerr << exp.what() << endl;;
|
||
status = PTSDK_STATUS_NETWORK_ERROR;
|
||
}
|
||
catch (CmdLineException &exp)
|
||
{
|
||
cerr << endl << "--------------------CmdLineException--------------------" << endl;
|
||
cerr << exp.what() << endl;;
|
||
status = PTSDK_STATUS_NETWORK_ERROR;
|
||
cerr << endl << format.CreateUsage(argv[0]);
|
||
}
|
||
catch (WSManException &exp)
|
||
{
|
||
cerr << endl << "--------------------GeneralWsmanException--------------------" << endl;
|
||
cerr << "Exception string error: " << exp.what() << endl;
|
||
status = PTSDK_STATUS_NETWORK_ERROR;
|
||
}
|
||
catch (HTTPException &exp)
|
||
{
|
||
cerr << endl << "--------------------HTTPException--------------------" << endl;
|
||
cerr << "Exception string error: " << exp.what() << endl;
|
||
status = PTSDK_STATUS_NETWORK_ERROR;
|
||
}
|
||
catch (LogicException &exp)
|
||
{
|
||
cerr << endl << "--------------------LogicException--------------------" << endl;
|
||
cerr << exp.getDetail();
|
||
if(exp.getErr() != 0)
|
||
cerr << "; Return Value: " << exp.getErr();
|
||
cerr<<endl;
|
||
}
|
||
catch (const exception &exp)
|
||
{
|
||
cerr << endl << "--------------------std::exception--------------------" << endl;
|
||
cerr << exp.what() << endl;
|
||
status = PTSDK_STATUS_NETWORK_ERROR;
|
||
}
|
||
return status;
|
||
} |