From 591c7055e942fbd0728ef75424220210b12af5cf Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Thu, 20 Jan 2022 09:29:16 +0100 Subject: [PATCH] - Add configuration opption --- FraudCapturer/Configuration/BlockConfigSet.cs | 10 ++- FraudCapturer/Configuration/Configurator.cs | 68 ++++++++++++++++--- FraudCapturer/Program.cs | 18 ++++- 3 files changed, 84 insertions(+), 12 deletions(-) diff --git a/FraudCapturer/Configuration/BlockConfigSet.cs b/FraudCapturer/Configuration/BlockConfigSet.cs index 4e2b952..719fe53 100644 --- a/FraudCapturer/Configuration/BlockConfigSet.cs +++ b/FraudCapturer/Configuration/BlockConfigSet.cs @@ -9,7 +9,11 @@ internal class BlockConfigSet BlockIfVpn = blockIfVpn; } - public bool BlockIfNotProxy { get; } - public bool BlockIfProxy { get; } - public bool BlockIfVpn { get; } + public BlockConfigSet() + { + } + + public bool BlockIfNotProxy { get; set; } + public bool BlockIfProxy { get; set; } + public bool BlockIfVpn { get; set; } } \ No newline at end of file diff --git a/FraudCapturer/Configuration/Configurator.cs b/FraudCapturer/Configuration/Configurator.cs index 19ab305..dd81117 100644 --- a/FraudCapturer/Configuration/Configurator.cs +++ b/FraudCapturer/Configuration/Configurator.cs @@ -1,11 +1,63 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace FraudCapturer.Configuration; +namespace FraudCapturer.Configuration; internal class Configurator { -} + public BlockConfig GetConfig() + { + BlockConfig blockConfig = new BlockConfig(); + + Console.WriteLine("Configuration:"); + Console.WriteLine(); + + Console.WriteLine("High risk rules (>=66%):"); + Console.WriteLine("----------------------------------------------------"); + blockConfig.HighRiskSet = GetBlockConfigSetFromConsole(true, true, true); + + Console.WriteLine("High medium rules (>33% & <66%):"); + Console.WriteLine("----------------------------------------------------"); + blockConfig.MeduimRiskSet = GetBlockConfigSetFromConsole(false, true, true); + + Console.WriteLine("High low rules (<=33%):"); + Console.WriteLine("----------------------------------------------------"); + blockConfig.LowRiskSet = GetBlockConfigSetFromConsole(false, true, false); + + return blockConfig; + } + + private BlockConfigSet GetBlockConfigSetFromConsole(bool ifNotProxyDefault, bool ifproxyDefault, bool ifVpnDeault) + { + BlockConfigSet blockConfigSet = new BlockConfigSet(); + Console.WriteLine($"Block if no Proxy detected {GetDefaultHintString(ifNotProxyDefault)}:"); + blockConfigSet.BlockIfNotProxy = GetBoolValueFromConsole(ifNotProxyDefault); + + Console.WriteLine($"Block if Proxy detected {GetDefaultHintString(ifproxyDefault)}:"); + blockConfigSet.BlockIfProxy = GetBoolValueFromConsole(ifproxyDefault); + + Console.WriteLine($"Block if VPN detected {GetDefaultHintString(ifVpnDeault)}:"); + blockConfigSet.BlockIfVpn = GetBoolValueFromConsole(ifVpnDeault); + + return blockConfigSet; + } + + private bool GetBoolValueFromConsole(bool defaultValue) + { + string input = Console.ReadLine() ?? string.Empty; + + if (string.IsNullOrWhiteSpace(input)) + { + return defaultValue; + } + + while (input.ToLower() != "y" && input.ToLower() != "n") + { + input = Console.ReadLine() ?? string.Empty; + } + + return input.ToLower() == "y"; + } + + private string GetDefaultHintString(bool defaultValue) + { + return defaultValue ? "[Y/n]" : "[y/N]"; + } +} \ No newline at end of file diff --git a/FraudCapturer/Program.cs b/FraudCapturer/Program.cs index 8c6e509..3389f2b 100644 --- a/FraudCapturer/Program.cs +++ b/FraudCapturer/Program.cs @@ -9,6 +9,7 @@ using Stone_Red_Utilities.ConsoleExtentions; using System.Collections.Concurrent; using System.Net; +using System.Text.Json; namespace FraudCapturer; @@ -17,6 +18,7 @@ public class Program public const string AppName = "FraudCapturer"; public const string AppUrl = "https://github.com/Stone-Red-Code/FraudCapturer"; public const string IpStorePath = "ipAdresses.txt"; + public const string ConfigStorePath = "config.txt"; private static DateTime lastCacheClear; private static string lastDomain = string.Empty; @@ -39,7 +41,16 @@ public class Program // Retrieve the device list CaptureDeviceList devices = CaptureDeviceList.Instance; - if (string.IsNullOrWhiteSpace(args.FirstOrDefault())) + if (args.FirstOrDefault() == "config") + { + blockConfig = new Configurator().GetConfig(); + string jsonConfig = JsonSerializer.Serialize(blockConfig); + File.WriteAllText(ConfigStorePath, jsonConfig); + + Console.WriteLine("-- Configuration saved!"); + return; + } + else if (string.IsNullOrWhiteSpace(args.FirstOrDefault())) { ConsoleExt.WriteLine("No proxycheck api key provided! You are limited to 100 IP checks per day. Get one for free at proxycheck.io.", ConsoleColor.Red); Console.WriteLine(); @@ -49,6 +60,11 @@ public class Program IpHelper.ProxycheckApiKey = args.FirstOrDefault(); } + if (File.Exists(ConfigStorePath)) + { + blockConfig = JsonSerializer.Deserialize(File.ReadAllText(ConfigStorePath)) ?? new BlockConfig(); + } + // If no devices were found print an error if (devices.Count < 1) {