Update amtinfo, usage and admin check. General code cleanup and bug fixes.

This commit is contained in:
Mudit Vats
2020-10-30 09:51:18 -07:00
parent eb42f1e89d
commit 6d2e37e7fc
13 changed files with 434 additions and 148 deletions

171
info.cpp
View File

@@ -10,13 +10,16 @@
#include "commands.h"
#include "utils.h"
void out_text(const std::string name, const std::vector<unsigned char> value, const unsigned char delimeter=' ')
const int PADDING = 25;
void out_text(const std::string name, const std::vector<unsigned char> value, const unsigned char delimeter = ' ', const bool hex = true)
{
std::cout << name << ": ";
std::cout << name << std::setfill(' ') << std::setw(PADDING - name.size()) << ": ";
int char_count = 1;
for (unsigned char tmp : value)
{
std::cout << std::setfill('0') << std::setw(2) << std::hex << (unsigned int) tmp;
(hex) ? std::cout << std::setfill('0') << std::setw(2) << std::hex << (unsigned int)tmp
: std::cout << (unsigned int)tmp;
if (char_count++ < value.size())
{
@@ -29,26 +32,23 @@ void out_text(const std::string name, const std::vector<unsigned char> value, co
void out_text(const std::string name, const std::string value)
{
std::cout << name << ": ";
std::cout << name << std::setfill(' ') << std::setw(PADDING - name.size()) << ": ";
std::cout << value;
std::cout << std::endl;
}
void out_text(const std::string name, const int value)
{
std::cout << name << ": ";
std::cout << name << std::setfill(' ') << std::setw(PADDING - name.size()) << ": ";
std::cout << value;
std::cout << std::endl;
}
void out_text(const std::string name, const std::vector<std::string> value)
{
int count = 1;
std::cout << name << std::endl;
std::cout << name << std::setfill(' ') << std::setw(PADDING - name.size()) << ": " << std::endl;
for (std::string tmp : value)
{
std::cout << std::setfill('0') << std::setw(2) << count++ << ":";
std::cout << tmp << std::endl;
}
}
@@ -70,7 +70,7 @@ bool info_get_build_number()
if (!cmd_get_build_number(tmp)) return false;
out_text("Build number", tmp);
out_text("Build Number", tmp);
return true;
}
@@ -111,7 +111,7 @@ bool info_get_control_mode()
else if (tmp == 1) control_mode = "activated in client control mode";
else if (tmp == 2) control_mode = "activated in admin control mode";
out_text("Control mode", control_mode);
out_text("Control Mode", control_mode);
return true;
}
@@ -122,29 +122,31 @@ bool info_get_dns_suffix()
if (!cmd_get_dns_suffix(tmp)) return false;
out_text("DNS suffix", tmp);
return true;
}
bool info_get_wired_mac_address()
{
std::vector<unsigned char> tmp;
if (!cmd_get_wired_mac_address(tmp)) return false;
out_text("Wired MAC address", tmp, '-');
out_text("DNS Suffix", tmp);
return true;
}
bool info_get_certificate_hashes()
{
std::vector<cert_hash_entry> hash_entries;
std::vector<std::string> tmp;
if (!cmd_get_certificate_hashes(tmp)) return false;
if (!cmd_get_certificate_hashes(hash_entries)) return false;
out_text("Certificate hashes", tmp);
for (cert_hash_entry entry : hash_entries)
{
std::string name = entry.name;
(entry.is_default) ? name += ", (Default, " : ", (Not Default, ";
(entry.is_active) ? name += "Active)" : "Not Active)";
tmp.push_back(name);
std::string algorithm = " " + entry.algorithm;
algorithm += ": " + entry.hash;
tmp.push_back(algorithm);
}
out_text("Certificate Hashes", tmp);
return true;
}
@@ -153,13 +155,99 @@ bool info_get_all()
{
std::vector<std::string> tmp;
if (info_get_version() && info_get_build_number() && info_get_sku() &&
info_get_uuid() && info_get_control_mode() && info_get_dns_suffix() &&
info_get_wired_mac_address() && info_get_certificate_hashes())
bool status_ver = info_get_version();
bool status_bld = info_get_build_number();
bool status_sku = info_get_sku();
bool status_uuid = info_get_uuid();
bool status_mode = info_get_control_mode();
bool status_dns = info_get_dns_suffix();
bool status_ras = info_get_remote_access_connection_status();
bool status_lan = info_get_lan_interface_settings();
bool status_cert = info_get_certificate_hashes();
if (status_ver && status_bld && status_sku && status_uuid && status_mode &&
status_dns && status_ras && status_lan && status_cert)
{
return true;
}
return false;
}
bool info_get_remote_access_connection_status()
{
int network_status;
int remote_status;
int remote_trigger;
std::string mps_hostname;
if (!cmd_get_remote_access_connection_status(network_status, remote_status, remote_trigger, mps_hostname)) return false;
std::string tmp;
switch (network_status)
{
case 0: tmp = "direct";
break;
case 1: tmp = "vpn";
break;
case 2: tmp = "outside enterprise";
break;
case 3:
default: tmp = "unknown";
break;
}
out_text("RAS Network", tmp);
switch (remote_status)
{
case 0: tmp = "not connected";
break;
case 1: tmp = "connecting";
break;
case 2: tmp = "connected";
break;
default: tmp = "unknown";
break;
}
out_text("RAS Remote Status", tmp);
switch (remote_trigger)
{
case 0: tmp = "user initiated";
break;
case 1: tmp = "alert";
break;
case 2: tmp = "periodic";
break;
case 3: tmp = "provisioning";
break;
default: tmp = "unknown";
break;
}
out_text("RAS Trigger", tmp);
out_text("RAS MPS Hostname", mps_hostname);
return true;
}
bool info_get_lan_interface_settings()
{
lan_interface_settings tmp;
if (!cmd_get_lan_interface_settings(tmp)) return false;
out_text("DHCP Enabled", (tmp.dhcp_enabled) ? "true" : "false");
out_text("DHCP Mode", (tmp.dhcp_mode == 1) ? "active" : "passive");
out_text("Link Status", (tmp.link_status) ? "up" : "down");
out_text("IP Address", tmp.ip_address, '.', false);
out_text("MAC Address", tmp.mac_address, ':');
return true;
}
@@ -169,7 +257,7 @@ bool info_get(const std::string info)
{
return info_get_version();
}
else if (info.compare("build") == 0)
else if (info.compare("bld") == 0)
{
return info_get_build_number();
}
@@ -189,14 +277,18 @@ bool info_get(const std::string info)
{
return info_get_dns_suffix();
}
else if (info.compare("mac") == 0)
{
return info_get_wired_mac_address();
}
else if (info.compare("cert") == 0)
{
return info_get_certificate_hashes();
}
else if (info.compare("ras") == 0)
{
return info_get_remote_access_connection_status();
}
else if (info.compare("lan") == 0)
{
return info_get_lan_interface_settings();
}
else if (info.compare("all") == 0)
{
return info_get_all();
@@ -204,3 +296,16 @@ bool info_get(const std::string info)
return false;
}
bool info_get_verify(const std::string info)
{
if ((info.compare("ver") == 0) || (info.compare("bld") == 0) || (info.compare("sku") == 0) ||
(info.compare("uuid") == 0) || (info.compare("mode") == 0) || (info.compare("dns") == 0) ||
(info.compare("cert") == 0) || (info.compare("ras") == 0) || (info.compare("lan") == 0) ||
(info.compare("all") == 0))
{
return true;
}
return false;
}