forked from open-amt-cloud-toolkit/rpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.cpp
371 lines (297 loc) · 8.57 KB
/
info.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/*********************************************************************
* Copyright (c) Intel Corporation 2019 - 2020
* SPDX-License-Identifier: Apache-2.0
**********************************************************************/
#include "info.h"
#include <iostream>
#include <string>
#include <iomanip>
#include "commands.h"
#include "utils.h"
#include "network.h"
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::setfill(' ') << std::setw(PADDING - name.size()) << ": ";
int char_count = 1;
for (unsigned char tmp : value)
{
(hex) ? std::cout << std::setfill('0') << std::setw(2) << std::hex << (unsigned int)tmp
: std::cout << std::dec << (unsigned int)tmp;
if (char_count++ < value.size())
{
std::cout << delimeter;
}
}
std::cout << std::endl;
}
void out_text(const std::string name, const std::string value)
{
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::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)
{
std::cout << name << std::setfill(' ') << std::setw(PADDING - name.size()) << ": " << std::endl;
for (std::string tmp : value)
{
std::cout << tmp << std::endl;
}
}
bool info_get_version()
{
std::string tmp;
if (!cmd_get_version(tmp)) return false;
out_text("Version", tmp);
return true;
}
bool info_get_build_number()
{
std::string tmp;
if (!cmd_get_build_number(tmp)) return false;
out_text("Build Number", tmp);
return true;
}
bool info_get_sku()
{
std::string tmp;
if (!cmd_get_sku(tmp)) return false;
out_text("SKU", tmp);
return true;
}
bool info_get_uuid()
{
std::string uuid_string;
std::vector<unsigned char> tmp;
if (!cmd_get_uuid(tmp)) return false;
if (!util_format_uuid(tmp, uuid_string)) return false;
out_text("UUID", uuid_string);
return true;
}
bool info_get_control_mode()
{
int tmp;
if (!cmd_get_control_mode(tmp)) return false;
std::string control_mode;
if (tmp == 0) control_mode = "pre-provisioning state";
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);
return true;
}
bool info_get_dns_suffix()
{
std::string tmp;
if (!cmd_get_dns_suffix(tmp)) return false;
out_text("DNS Suffix", tmp);
tmp = net_get_dns();
out_text("DNS Suffix (OS)", tmp);
return true;
}
bool info_get_fqdn()
{
fqdn_settings fqdn;
if (cmd_get_fqdn(fqdn))
{
out_text("FQDN", fqdn.fqdn);
}
std::string tmp;
std::string dns;
tmp = net_get_hostname();
out_text("Hostname (OS)", 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(hash_entries)) return false;
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;
}
bool info_get_all()
{
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_fqdn = info_get_fqdn();
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_fqdn && 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;
tmp.is_enabled = false;
tmp.link_status = false;
tmp.dhcp_enabled = false;
tmp.dhcp_mode = 0;
tmp.ip_address.clear();
tmp.mac_address.clear();
bool hasWired = cmd_get_lan_interface_settings(tmp);
if (hasWired)
{
out_text("LAN Inteface", "wired");
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, ':');
}
tmp.is_enabled = false;
tmp.link_status = false;
tmp.dhcp_enabled = false;
tmp.dhcp_mode = 0;
tmp.ip_address.clear();
tmp.mac_address.clear();
bool hasWireless = cmd_get_lan_interface_settings(tmp, false);
if (hasWireless)
{
out_text("LAN Inteface", "wireless");
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, ':');
}
if (hasWired || hasWireless)
{
return true;
}
return false;
}
bool info_get(const std::string info)
{
if (info.compare("ver") == 0)
{
return info_get_version();
}
else if (info.compare("bld") == 0)
{
return info_get_build_number();
}
else if (info.compare("sku") == 0)
{
return info_get_sku();
}
else if (info.compare("uuid") == 0)
{
return info_get_uuid();
}
else if (info.compare("mode") == 0)
{
return info_get_control_mode();
}
else if (info.compare("dns") == 0)
{
return info_get_dns_suffix();
}
else if (info.compare("fqdn") == 0)
{
return info_get_fqdn();
}
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();
}
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("fqdn") == 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;
}