//---------------------------------------------------------------------------- // // Copyright (C) 2008 Intel Corporation // // File: GeneralInfoSample.cpp // // Contents: Sample code for an Intel� AMT Network client. // //---------------------------------------------------------------------------- #include "GeneralInfoSample.h" #include "GeneralInfoFlow.h" #include "CommonDefinitions.h" #include "CmdLineArguments.h" // Include from CIM Framework #include "CimOpenWsmanClient.h" #include using namespace std; using namespace Intel::Manageability::Exceptions; using namespace Intel::Manageability::Cim::Typed; using namespace Intel::WSManagement; 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 general arguments 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, ""); #if defined (_WIN32) || defined (_WIN64) format.AddArg(CMD_KRB, false, false, false, ""); #endif 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, ""); // Add the sample-specific options arguments format.AddArg(GET_HOST_NAME, false, false, true, GET_HOST_NAME_DESCRIPTION); format.AddArg(GET_ADMIN_ACL_STATUS, false, false, true, GET_ADMIN_ACL_STATUS_DESCRIPTION); format.AddArg(GET_ADMIN_NET_ACL_STATUS, false, false, true, GET_ADMIN_NET_ACL_STATUS_DESCRIPTION); format.AddArg(GET_CODE_VERSIONS, false, false, true, GET_CODE_VERSIONS_DESCRIPTION); format.AddArg(GET_PROVISIONING_MODE, false, false, true, GET_PROVISIONING_MODE_DESCRIPTION); format.AddArg(GET_PROVISIONING_STATE, false, false, true, GET_PROVISIONING_STATE_DESCRIPTION); format.AddArg(GET_PASSWORD_MODEL, false, false, true, GET_PASSWORD_MODEL_DESCRIPTION); format.AddArg(GET_ENABLED_INTERFACES, false, false, true, GET_ENABLED_INTERFACES_DESCRIPTION); format.AddArg(GET_SECURITY_PARAMETERS, false, false, true, GET_SECURITY_PARAMETERS_DESCRIPTION); format.AddArg(GET_CONFIG_SERVER_INFO, false, false, true, GET_CONFIG_SERVER_INFO_DESCRIPTION); format.AddArg(GET_CORE_VERSION, false, false, true, GET_CORE_VERSION_DESCRIPTION); format.AddArg(GET_AUDIT_PROVISIONING_RECORD, false, false, true, GET_AUDIT_PROVISIONING_RECORD_DESCRIPTION); format.AddArg(GET_RPIVACY_LEVEL, false, false, true, GET_PRIVACY_LEVEL_DESCRIPTION); if (argc == 1) { cout << format.CreateUsage(argv[0]); return status; } try { CmdLineArguments cmdLineArguments; cmdLineArguments.Parse(argc, argv, format, false); string userRequest = cmdLineArguments.GetSelectedOptionName(); // Check if there are no selected option if(userRequest == "") { throw CmdLineException("Could not find a value for the option."); } CimOpenWsmanClient wsmanClient( cmdLineArguments.GetArgValue(CMD_HOST), cmdLineArguments.ArgExists(CMD_TLS) ? AMT_SECURE_PORT : AMT_UNSECURE_PORT, cmdLineArguments.ArgExists(CMD_TLS), #if defined (_WIN32) || defined (_WIN64) cmdLineArguments.ArgExists(CMD_KRB) ? KERBEROS : DIGEST, #else DIGEST, #endif 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)); if (format.CompareStringCaseSensitive(userRequest, GET_RPIVACY_LEVEL) == true) { // Get the privacy level GetPrivacyLevel(&wsmanClient); } else if (format.CompareStringCaseSensitive(userRequest, GET_AUDIT_PROVISIONING_RECORD) == true) { // Get Audit Provisioning Record GetAuditProvisioningRecord(&wsmanClient); } else if (format.CompareStringCaseSensitive(userRequest, GET_HOST_NAME) == true) { // Get Host Name GetHostName(&wsmanClient); } else if (format.CompareStringCaseSensitive(userRequest, GET_ADMIN_ACL_STATUS) == true) { // Get Admin Acl Status GetAdminAclStatus(&wsmanClient); } else if (format.CompareStringCaseSensitive(userRequest, GET_ADMIN_NET_ACL_STATUS) == true) { // Get Admin Net Acl Status GetAdminNetAclStatus(&wsmanClient); } else if (format.CompareStringCaseSensitive(userRequest, GET_CODE_VERSIONS) == true) { // Get Code Versions GetCodeVersions(&wsmanClient); } else if (format.CompareStringCaseSensitive(userRequest, GET_PROVISIONING_MODE) == true) { // Get Provisioning Mode GetProvisioningMode(&wsmanClient); } else if (format.CompareStringCaseSensitive(userRequest, GET_PROVISIONING_STATE) == true) { // Get Provisioning State GetProvisioningState(&wsmanClient); } else if (format.CompareStringCaseSensitive(userRequest, GET_PASSWORD_MODEL) == true) { // Get Password Model GetPasswordModel(&wsmanClient); } else if (format.CompareStringCaseSensitive(userRequest, GET_ENABLED_INTERFACES) == true) { // Get Enabled interfaces GetEnabledInterfaces(&wsmanClient); } else if (format.CompareStringCaseSensitive(userRequest, GET_SECURITY_PARAMETERS) == true) { // Get Security Parameters GetSecurityParameters(&wsmanClient); } else if (format.CompareStringCaseSensitive(userRequest, GET_CONFIG_SERVER_INFO) == true) { // Get Config server info GetConfigServerInfo(&wsmanClient); } else if (format.CompareStringCaseSensitive(userRequest, GET_CORE_VERSION) == true) { // Get Core Version GetCoreVersion(&wsmanClient); } } catch (CimException& exp) { cerr << "--------------------CimException--------------------" << endl; cerr << exp.what() << endl;; status = PTSDK_STATUS_NETWORK_ERROR; } catch (ConversionException &exp) { cerr << "--------------------ConversionException--------------------" << endl; cerr << exp.what() << endl;; status = PTSDK_STATUS_NETWORK_ERROR; } catch (CmdLineException &exp) { cerr << "--------------------CmdLineException--------------------" << endl; cerr << exp.what() << endl;; cerr << endl << format.CreateUsage(argv[0]); status = PTSDK_STATUS_NETWORK_ERROR; } catch (WSManException &exp) { cerr << "--------------------WSManException--------------------" << 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 (const exception &exp) { cerr << "--------------------std::exception--------------------" << endl; cerr << exp.what() << endl;; status = PTSDK_STATUS_NETWORK_ERROR; } return status; }