-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.cs
66 lines (63 loc) · 2.5 KB
/
config.cs
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
using Microsoft.Win32;
using System;
using System.Diagnostics;
namespace adfsTorBlock
{
internal class Config
{
private const string regPath = "SOFTWARE\\ADFSTorBlock";
internal bool Enabled { get; set; }
internal bool AuditModeEnabled { get; set; }
internal bool EvaluateRisk { get; set; }
public Config()
{
try
{
RegistryKey rk = Registry.LocalMachine.OpenSubKey(regPath);
if (rk == null)
{
throw new InvalidOperationException("RegistryKeyException");
}
object oEnabled = rk.GetValue("Enabled");
if (oEnabled != null)
{
Enabled = oEnabled.ToString() == "0" ? false : true;
}
object oAuditModeEnabled = rk.GetValue("AuditModeEnabled");
if (oAuditModeEnabled != null)
{
AuditModeEnabled = oAuditModeEnabled.ToString() == "0" ? false : true;
}
object oEvaluateRisk = rk.GetValue("EvaluateRisk");
if (oEvaluateRisk != null)
{
EvaluateRisk = oEvaluateRisk.ToString() == "0" ? false : true;
}
}
catch (Exception ex)
{
Debug.WriteLine($"adfsTorBlock:{this.GetType()}:Config constructor:Exception caught: {ex}");
Debug.WriteLine($"adfsTorBlock:{this.GetType()}:Config constructor:Setting default values");
Enabled = true;
AuditModeEnabled = true;
EvaluateRisk = false;
}
}
public override string ToString() => $"Enabled: {Enabled};AuditModeEnabled: {AuditModeEnabled};EvaluateRisk: {EvaluateRisk}";
public void InitConfig()
{
Debug.WriteLine($"adfsTorBlock:{this.GetType()}:InitConfig:Enter");
Debug.WriteLine($"adfsTorBlock:{this.GetType()}:Reading Plugin Registry Configuration Configuration");
try
{
Debug.WriteLine($"adfsTorBlock:{this.GetType()}:Loading Tor Exit Nodes");
TorModule.LoadTorExitNodes();
}
catch (Exception ex)
{
Debug.WriteLine($"adfsTorBlock:{this.GetType()}: LoadTorExitNodes - Exception. {ex}");
}
Debug.WriteLine($"adfsTorBlock:{this.GetType()}:InitConfig:Exit");
}
}
}