diff --git a/Seatbelt/Commands/Windows/InternetSettingsCommand.cs b/Seatbelt/Commands/Windows/InternetSettingsCommand.cs index c76c6d8..6b7f2f7 100644 --- a/Seatbelt/Commands/Windows/InternetSettingsCommand.cs +++ b/Seatbelt/Commands/Windows/InternetSettingsCommand.cs @@ -21,41 +21,33 @@ namespace Seatbelt.Commands.Windows public override IEnumerable 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)) + 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() - { - Hive = "HKCU", - Key = kvp.Key, - Value = kvp.Value.ToString() - }; - } + result.GeneralSettings.Add(new InternetSettingsKey( + "HKCU", + keyPath, + kvp.Key, + kvp.Value.ToString(), + null)); } - WriteHost(); - - var proxySettings2 = RegistryUtil.GetValues(RegistryHive.LocalMachine, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"); - - if ((proxySettings2 != null) && (proxySettings2.Count != 0)) - { - foreach (var kvp in proxySettings2) - { - yield return new InternetSettingsDTO() - { - Hive = "HKLM", - Key = kvp.Key, - Value = kvp.Value.ToString() - }; - } + keyPath = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"; + var proxySettings2 = RegistryUtil.GetValues(RegistryHive.LocalMachine, keyPath); + foreach (var kvp in proxySettings2) + { + result.GeneralSettings.Add(new InternetSettingsKey( + "HKLM", + keyPath, + kvp.Key, + kvp.Value.ToString(), + null)); } - WriteHost(""); // List user/system internet settings for zonemapkey (local, trusted, etc.) : // 1 = Intranet zone – sites on your local network. @@ -63,50 +55,41 @@ namespace Seatbelt.Commands.Windows // 3 = Internet zone – sites that are on the Internet. // 4 = Restricted Sites zone – sites that have been specifically added to your restricted sites. - WriteHost(" Hive Key : Value\n"); IDictionary zoneMapKeys = new Dictionary() { {"0", "My Computer" }, {"1", "Local Intranet Zone"}, - {"2", "Trusted sites Zone"}, + {"2", "Trusted Sites Zone"}, {"3", "Internet Zone"}, {"4", "Restricted Sites Zone"} }; - var zoneMapKey = RegistryUtil.GetValues(RegistryHive.LocalMachine, @"Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMapKey"); - if ((zoneMapKey != null) && (zoneMapKey.Count != 0)) + keyPath = @"Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMapKey"; + var zoneMapKey = RegistryUtil.GetValues(RegistryHive.LocalMachine, keyPath); + foreach (var kvp in zoneMapKey.AsEnumerable()) { - foreach (var kvp in zoneMapKey) - { - yield return new InternetSettingsDTO() - { - Hive = "HKLM", - Key = kvp.Key, - Value = zoneMapKeys.AsEnumerable().Single(l => l.Key == kvp.Value.ToString()).Value - }; - } + result.ZoneMaps.Add(new InternetSettingsKey( + "HKLM", + keyPath, + kvp.Key, + kvp.Value.ToString(), + zoneMapKeys.AsEnumerable().Single(l => l.Key == kvp.Value.ToString()).Value + )); } - WriteHost(""); - - var zoneMapKey2 = RegistryUtil.GetValues(RegistryHive.CurrentUser, @"Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMapKey"); - - if ((zoneMapKey2 != null) && (zoneMapKey2.Count != 0)) + var zoneMapKey2 = RegistryUtil.GetValues(RegistryHive.CurrentUser, keyPath); + foreach (var kvp in zoneMapKey2.AsQueryable()) { - foreach (var kvp in zoneMapKey2) - { - yield return new InternetSettingsDTO() - { - Hive = "HKCU", - Key = kvp.Key, - Value = zoneMapKeys.AsEnumerable().Single(l => l.Key == kvp.Value.ToString()).Value - }; - } + result.ZoneMaps.Add(new InternetSettingsKey( + "HKCU", + keyPath, + kvp.Key, + kvp.Value.ToString(), + zoneMapKeys.AsEnumerable().Single(l => l.Key == kvp.Value.ToString()).Value + )); } - WriteHost(""); - // List Zones settings with automatic logons /** @@ -120,7 +103,6 @@ namespace Seatbelt.Commands.Windows * 0x00030000 Anonymous logon **/ - WriteHost("Zone settings"); IDictionary zoneAuthSettings = new Dictionary() { {0x00000000, "Automatically logon with current username and password"}, @@ -131,21 +113,48 @@ namespace Seatbelt.Commands.Windows for (int i = 0; i <= 4; i++) { - var zoneSettings = RegistryUtil.GetDwordValue(RegistryHive.LocalMachine, @"Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\" + i.ToString(), "1A00"); - if (zoneSettings != null) + keyPath = @"Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\" + i; + 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 { - public string Hive { get; set; } - - public string Key { get; set; } - - public string Value { get; set; } + public List GeneralSettings { get; set; } = new List(); + public List ZoneMaps { get; set; } = new List(); + public List ZoneAuthSettings { get; set; } = new List(); } [CommandOutputType(typeof(InternetSettingsDTO))] @@ -159,9 +168,31 @@ namespace Seatbelt.Commands.Windows { 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}"); + } + } } } -} +} #nullable enable \ No newline at end of file diff --git a/Seatbelt/Output/Formatters/TextFormatterBase.cs b/Seatbelt/Output/Formatters/TextFormatterBase.cs index 9127091..eb77f20 100644 --- a/Seatbelt/Output/Formatters/TextFormatterBase.cs +++ b/Seatbelt/Output/Formatters/TextFormatterBase.cs @@ -19,9 +19,6 @@ namespace Seatbelt.Output.Formatters protected void Write(string str) => _textWriter.Write(str); protected void WriteLine() => _textWriter.WriteLine(); 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); } } diff --git a/Seatbelt/Seatbelt.csproj b/Seatbelt/Seatbelt.csproj index c0362e4..232c9ec 100755 --- a/Seatbelt/Seatbelt.csproj +++ b/Seatbelt/Seatbelt.csproj @@ -9,7 +9,7 @@ Properties Seatbelt Seatbelt - v4.0 + v3.5 512 publish\ true diff --git a/Seatbelt/app.config b/Seatbelt/app.config index fcd0c93..cf7e7ab 100644 --- a/Seatbelt/app.config +++ b/Seatbelt/app.config @@ -1,3 +1,3 @@ - - - + + +