mirror of
https://github.com/Stone-Red-Code/FraudCapturer.git
synced 2026-09-04 09:06:06 +02:00
- Add configuration opption
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
@@ -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]";
|
||||
}
|
||||
}
|
||||
@@ -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<BlockConfig>(File.ReadAllText(ConfigStorePath)) ?? new BlockConfig();
|
||||
}
|
||||
|
||||
// If no devices were found print an error
|
||||
if (devices.Count < 1)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user