-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGeoblockModuleServiceProxy .cs
99 lines (88 loc) · 3.88 KB
/
GeoblockModuleServiceProxy .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
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
#nullable disable
/* GeoblockModuleServiceProxy.cs
*
* Copyright (C) 2009 Triple IT. All Rights Reserved.
* Author: Frank Lippes, Modified for IIS 10 (.Net 4.6) by RvdH
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/
using Microsoft.Web.Management.Client;
using Microsoft.Web.Management.Server;
using System.Collections;
using System.Collections.Generic;
namespace IISGeoIP2blockModule
{
/// <summary>
/// Uses the module service at the server to get and update the geoblock configuration
/// </summary>
public class GeoblockModuleServiceProxy : ModuleServiceProxy
{
/// <summary>
/// Gets the geoblock configuration from the module service
/// </summary>
/// <returns>The geoblock configuration</returns>
public GeoblockConfiguration GetGeoblockConfiguration()
{
PropertyBag config = (PropertyBag)Invoke("GetGeoblockConfiguration");
GeoblockConfiguration result = new GeoblockConfiguration();
result.Enabled = (bool)config[0];
result.DenyAction = (string)config[1];
result.GeoIpFilepath = (string)config[2];
result.VerifyAll = (bool)config[3];
result.AllowedMode = (bool)config[4];
result.SelectedCountryCodes = new List<Country>();
ArrayList countries = (ArrayList)config[5];
foreach (PropertyBag item in countries)
{
result.SelectedCountryCodes.Add(new Country((string)item[0], null));
}
result.ExceptionRules = new List<ExceptionRule>();
ArrayList exceptionRules = (ArrayList)config[6];
foreach (PropertyBag item in exceptionRules)
{
result.ExceptionRules.Add(new ExceptionRule((bool)item[0], (string)item[1], (string)item[2]));
}
return result;
}
/// <summary>
/// Updates the geoblock configuration using the module service
/// </summary>
/// <param name="updatedGeoblockConfiguration">The new geoblock configuration</param>
public void UpdateGeoblockConfiguration(GeoblockConfiguration updatedGeoblockConfiguration)
{
PropertyBag config = new PropertyBag();
config.Add(0, updatedGeoblockConfiguration.Enabled);
config.Add(1, updatedGeoblockConfiguration.DenyAction);
config.Add(2, updatedGeoblockConfiguration.GeoIpFilepath);
config.Add(3, updatedGeoblockConfiguration.VerifyAll);
config.Add(4, updatedGeoblockConfiguration.AllowedMode);
ArrayList countries = new ArrayList();
foreach (Country country in updatedGeoblockConfiguration.SelectedCountryCodes)
{
PropertyBag item = new PropertyBag();
item.Add(0, country.CountryCode);
countries.Add(item);
}
config.Add(5, countries);
ArrayList exceptionRules = new ArrayList();
foreach (ExceptionRule exceptionRule in updatedGeoblockConfiguration.ExceptionRules)
{
PropertyBag item = new PropertyBag();
item.Add(0, exceptionRule.AllowedMode);
item.Add(1, exceptionRule.IpAddress);
item.Add(2, exceptionRule.Mask);
exceptionRules.Add(item);
}
config.Add(6, exceptionRules);
Invoke("UpdateGeoblockConfiguration", config);
}
}
}