-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGeoblockConfiguration.cs
More file actions
163 lines (144 loc) · 4.69 KB
/
GeoblockConfiguration.cs
File metadata and controls
163 lines (144 loc) · 4.69 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#nullable disable
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using Microsoft.Web.Management.Server;
namespace IISGeoIP2blockModule
{
/// <summary>
/// Wraps around the ConfigurationSection.
/// </summary>
public class GeoblockConfiguration
{
/// <summary>
/// Creates a geoblock configuration instance
/// </summary>
public GeoblockConfiguration() { }
/// <summary>
/// Specifies whether or not the module is enabled
/// </summary>
public bool Enabled { get; set; }
/// <summary>
/// Specifies whether or not if a proxy in HTTP_X_FORWARDED_FOR should be ignored if previous checked ip matches
/// </summary>
public bool VerifyAll { get; set; }
/// <summary>
/// Specifies the Deny Action Type
/// </summary>
public string DenyAction { get; set; }
/// <summary>
/// Points to the GeoIP.dat file
/// </summary>
public string GeoIpFilepath { get; set; }
/// <summary>
/// Whether the selected country codes are allowed or not
/// </summary>
public bool AllowedMode { get; set; }
/// <summary>
/// A collection that holds the selected country codes
/// </summary>
public List<Country> SelectedCountryCodes { get; set; }
/// <summary>
/// A collection that holds the exception rules
/// </summary>
public List<ExceptionRule> ExceptionRules { get; set; }
}
/// <summary>
/// Used to hold a country item
/// </summary>
public class Country
{
/// <summary>
/// The country code of this item
/// </summary>
public string CountryCode { get; set; }
/// <summary>
/// The country name corresponding to the country code
/// </summary>
public string CountryName { get; set; }
/// <summary>
/// Creates a new Country
/// </summary>
/// <param name="countryCode">The country code</param>
/// <param name="country">The corresponding country name</param>
public Country(string countryCode, string country)
{
this.CountryCode = countryCode;
this.CountryName = country;
}
/// <summary>
/// Returns the textual representation of the country
/// </summary>
/// <returns>The textual representation of the country</returns>
public override string ToString()
{
return CountryName + " (" + CountryCode + ")";
}
}
/// <summary>
/// Used to hold an exception rule item.
/// </summary>
public class ExceptionRule
{
/// <summary>
/// The mode of this exception rule
/// </summary>
public bool AllowedMode { get; set; }
/// <summary>
/// The ip address of this exception rule
/// </summary>
public string IpAddress { get; set; }
/// <summary>
/// The mask of this exception rule
/// </summary>
public string Mask { get; set; }
/// <summary>
/// Creates a new exception rule
/// </summary>
/// <param name="allowedMode">The mode of the exception rule</param>
/// <param name="ipAddress">The ip address of the exception rule</param>
/// <param name="mask">The mask of the exception rule</param>
public ExceptionRule(bool allowedMode, string ipAddress, string mask)
{
this.AllowedMode = allowedMode;
this.IpAddress = ipAddress;
this.Mask = mask;
}
/// <summary>
/// The textual representation of the alowed mode
/// </summary>
public string Mode
{
get
{
if (this.AllowedMode)
return "Allow";
else
return "Deny";
}
}
/// <summary>
/// The textual representation of the ip address and subnet mask
/// </summary>
public string Requestor
{
get
{
string result = this.IpAddress;
if (!String.IsNullOrEmpty(this.Mask))
{
result += " (" + this.Mask + ")";
}
return result;
}
}
/// <summary>
/// Returns the textual representation of the exception rule
/// </summary>
/// <returns>The textual representation of the exception rule</returns>
public override string ToString()
{
return this.Mode + " " + this.Requestor;
}
}
}