Merge pull request #26 from leechristensen/master

updated InternetSettings to newer output format
master
Lee Christensen 2020-05-28 20:01:32 -07:00 committed by GitHub
commit 8096cbfaf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 104 additions and 76 deletions

View File

@ -21,41 +21,33 @@ namespace Seatbelt.Commands.Windows
public override IEnumerable<CommandDTOBase?> Execute(string[] args) public override IEnumerable<CommandDTOBase?> Execute(string[] args)
{ {
WriteHost(" Hive Key : Value\n"); var result = new InternetSettingsDTO();
// lists user/system internet settings, including default proxy info
var proxySettings = RegistryUtil.GetValues(RegistryHive.CurrentUser, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
if ((proxySettings != null) && (proxySettings.Count != 0)) // lists user/system internet settings, including default proxy info
{ var keyPath = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
var proxySettings = RegistryUtil.GetValues(RegistryHive.CurrentUser, keyPath);
foreach (var kvp in proxySettings) foreach (var kvp in proxySettings)
{ {
yield return new InternetSettingsDTO() result.GeneralSettings.Add(new InternetSettingsKey(
{ "HKCU",
Hive = "HKCU", keyPath,
Key = kvp.Key, kvp.Key,
Value = kvp.Value.ToString() kvp.Value.ToString(),
}; null));
}
} }
WriteHost(); keyPath = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
var proxySettings2 = RegistryUtil.GetValues(RegistryHive.LocalMachine, keyPath);
var proxySettings2 = RegistryUtil.GetValues(RegistryHive.LocalMachine, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
if ((proxySettings2 != null) && (proxySettings2.Count != 0))
{
foreach (var kvp in proxySettings2) foreach (var kvp in proxySettings2)
{ {
yield return new InternetSettingsDTO() result.GeneralSettings.Add(new InternetSettingsKey(
{ "HKLM",
Hive = "HKLM", keyPath,
Key = kvp.Key, kvp.Key,
Value = kvp.Value.ToString() kvp.Value.ToString(),
}; null));
}
} }
WriteHost("");
// List user/system internet settings for zonemapkey (local, trusted, etc.) : // List user/system internet settings for zonemapkey (local, trusted, etc.) :
// 1 = Intranet zone sites on your local network. // 1 = Intranet zone sites on your local network.
@ -63,49 +55,40 @@ namespace Seatbelt.Commands.Windows
// 3 = Internet zone sites that are on the Internet. // 3 = Internet zone sites that are on the Internet.
// 4 = Restricted Sites zone sites that have been specifically added to your restricted sites. // 4 = Restricted Sites zone sites that have been specifically added to your restricted sites.
WriteHost(" Hive Key : Value\n");
IDictionary<string, string> zoneMapKeys = new Dictionary<string, string>() IDictionary<string, string> zoneMapKeys = new Dictionary<string, string>()
{ {
{"0", "My Computer" }, {"0", "My Computer" },
{"1", "Local Intranet Zone"}, {"1", "Local Intranet Zone"},
{"2", "Trusted sites Zone"}, {"2", "Trusted Sites Zone"},
{"3", "Internet Zone"}, {"3", "Internet Zone"},
{"4", "Restricted Sites Zone"} {"4", "Restricted Sites Zone"}
}; };
var zoneMapKey = RegistryUtil.GetValues(RegistryHive.LocalMachine, @"Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMapKey"); keyPath = @"Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMapKey";
if ((zoneMapKey != null) && (zoneMapKey.Count != 0)) var zoneMapKey = RegistryUtil.GetValues(RegistryHive.LocalMachine, keyPath);
foreach (var kvp in zoneMapKey.AsEnumerable())
{ {
foreach (var kvp in zoneMapKey) result.ZoneMaps.Add(new InternetSettingsKey(
{ "HKLM",
yield return new InternetSettingsDTO() keyPath,
{ kvp.Key,
Hive = "HKLM", kvp.Value.ToString(),
Key = kvp.Key, zoneMapKeys.AsEnumerable().Single(l => l.Key == kvp.Value.ToString()).Value
Value = zoneMapKeys.AsEnumerable().Single(l => l.Key == kvp.Value.ToString()).Value ));
};
}
} }
WriteHost(""); var zoneMapKey2 = RegistryUtil.GetValues(RegistryHive.CurrentUser, keyPath);
foreach (var kvp in zoneMapKey2.AsQueryable())
var zoneMapKey2 = RegistryUtil.GetValues(RegistryHive.CurrentUser, @"Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMapKey");
if ((zoneMapKey2 != null) && (zoneMapKey2.Count != 0))
{ {
foreach (var kvp in zoneMapKey2) result.ZoneMaps.Add(new InternetSettingsKey(
{ "HKCU",
yield return new InternetSettingsDTO() keyPath,
{ kvp.Key,
Hive = "HKCU", kvp.Value.ToString(),
Key = kvp.Key, zoneMapKeys.AsEnumerable().Single(l => l.Key == kvp.Value.ToString()).Value
Value = zoneMapKeys.AsEnumerable().Single(l => l.Key == kvp.Value.ToString()).Value ));
};
} }
}
WriteHost("");
// List Zones settings with automatic logons // List Zones settings with automatic logons
@ -120,7 +103,6 @@ namespace Seatbelt.Commands.Windows
* 0x00030000 Anonymous logon * 0x00030000 Anonymous logon
**/ **/
WriteHost("Zone settings");
IDictionary<uint, string> zoneAuthSettings = new Dictionary<uint, string>() IDictionary<uint, string> zoneAuthSettings = new Dictionary<uint, string>()
{ {
{0x00000000, "Automatically logon with current username and password"}, {0x00000000, "Automatically logon with current username and password"},
@ -131,21 +113,48 @@ namespace Seatbelt.Commands.Windows
for (int i = 0; i <= 4; i++) for (int i = 0; i <= 4; i++)
{ {
var zoneSettings = RegistryUtil.GetDwordValue(RegistryHive.LocalMachine, @"Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\" + i.ToString(), "1A00"); keyPath = @"Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\" + i;
if (zoneSettings != null) var authSetting = RegistryUtil.GetDwordValue(RegistryHive.LocalMachine, keyPath, "1A00");
if (authSetting != null)
{ {
WriteHost(zoneMapKeys.AsEnumerable().Single(l => l.Key == i.ToString()).Value + "\tSettings: " + zoneAuthSettings.AsEnumerable().Single(l => l.Key == zoneSettings).Value); var zone = zoneMapKeys.AsEnumerable().Single(l => l.Key == i.ToString()).Value;
var authSettingStr = zoneAuthSettings.AsEnumerable().Single(l => l.Key == authSetting).Value;
result.ZoneAuthSettings.Add(new InternetSettingsKey(
"HKLM",
keyPath,
"1A00",
authSetting.ToString(),
$"{zone} : {authSettingStr}"
));
} }
} }
yield return result;
}
internal class InternetSettingsKey
{
public InternetSettingsKey(string hive, string path, string valueName, string value, string? interpretation)
{
Hive = hive;
Path = path;
ValueName = valueName;
Value = value;
Interpretation = interpretation;
}
public string Hive { get; }
public string Path { get; }
public string ValueName { get; }
public string Value { get; }
public string? Interpretation { get; }
} }
internal class InternetSettingsDTO : CommandDTOBase internal class InternetSettingsDTO : CommandDTOBase
{ {
public string Hive { get; set; } public List<InternetSettingsKey> GeneralSettings { get; set; } = new List<InternetSettingsKey>();
public List<InternetSettingsKey> ZoneMaps { get; set; } = new List<InternetSettingsKey>();
public string Key { get; set; } public List<InternetSettingsKey> ZoneAuthSettings { get; set; } = new List<InternetSettingsKey>();
public string Value { get; set; }
} }
[CommandOutputType(typeof(InternetSettingsDTO))] [CommandOutputType(typeof(InternetSettingsDTO))]
@ -159,7 +168,29 @@ namespace Seatbelt.Commands.Windows
{ {
var dto = (InternetSettingsDTO)result; var dto = (InternetSettingsDTO)result;
WriteLine(" {0} {1,30} : {2}", dto.Hive, dto.Key, dto.Value); WriteLine("General Settings");
WriteLine(" {0} {1,30} : {2}\n", "Hive", "Key", "Value");
foreach (var i in dto.GeneralSettings)
{
WriteLine(" {0} {1,30} : {2}", "HKCU", i.ValueName, i.Value);
}
WriteLine("\nURLs by Zone");
if(dto.ZoneMaps.Count == 0)
WriteLine(" No URLs configured");
foreach (var i in dto.ZoneMaps)
{
WriteLine(" {0} {1,-30} : {2}", i.Hive, i.ValueName, i.Interpretation);
}
WriteLine("\nZone Auth Settings");
foreach (var i in dto.ZoneAuthSettings)
{
WriteLine($" {i.Interpretation}");
}
} }
} }
} }

View File

@ -19,9 +19,6 @@ namespace Seatbelt.Output.Formatters
protected void Write(string str) => _textWriter.Write(str); protected void Write(string str) => _textWriter.Write(str);
protected void WriteLine() => _textWriter.WriteLine(); protected void WriteLine() => _textWriter.WriteLine();
protected void WriteLine(string str) => _textWriter.WriteLine(str); protected void WriteLine(string str) => _textWriter.WriteLine(str);
protected void WriteLine(string format, object? arg0) => _textWriter.WriteLine(format, arg0);
protected void WriteLine(string format, object? arg0, object? arg1) => _textWriter.WriteLine(format, arg0, arg1);
protected void WriteLine(string format, object arg0, object arg1, object arg2) => _textWriter.WriteLine(format, arg0, arg1, arg2);
protected void WriteLine(string format, params object?[] args) => _textWriter.WriteLine(format, args); protected void WriteLine(string format, params object?[] args) => _textWriter.WriteLine(format, args);
} }
} }

View File

@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Seatbelt</RootNamespace> <RootNamespace>Seatbelt</RootNamespace>
<AssemblyName>Seatbelt</AssemblyName> <AssemblyName>Seatbelt</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<PublishUrl>publish\</PublishUrl> <PublishUrl>publish\</PublishUrl>
<Install>true</Install> <Install>true</Install>

View File

@ -1,3 +1,3 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration> <startup><supportedRuntime version="v2.0.50727"/></startup></configuration>