-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
IsapiCgiRestrictionFeature.cs
230 lines (191 loc) · 6.73 KB
/
IsapiCgiRestrictionFeature.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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// Copyright (c) Lex Li. All rights reserved.
//
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
/*
* Created by SharpDevelop.
* User: lextm
* Time: 11:06 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
namespace JexusManager.Features.IsapiCgiRestriction
{
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Forms;
using JexusManager.Properties;
using JexusManager.Services;
using Microsoft.Web.Administration;
using Microsoft.Web.Management.Client;
using Microsoft.Web.Management.Client.Win32;
using Module = Microsoft.Web.Management.Client.Module;
/// <summary>
/// Description of DefaultDocumentFeature.
/// </summary>
internal class IsapiCgiRestrictionFeature : FeatureBase<IsapiCgiRestrictionItem>
{
private sealed class FeatureTaskList : DefaultTaskList
{
private readonly IsapiCgiRestrictionFeature _owner;
public FeatureTaskList(IsapiCgiRestrictionFeature owner)
{
_owner = owner;
}
public override ICollection GetTaskItems()
{
var result = new ArrayList();
result.Add(new MethodTaskItem("Add", "Add...", string.Empty).SetUsage());
if (_owner.SelectedItem != null)
{
result.Add(MethodTaskItem.CreateSeparator().SetUsage());
if (_owner.SelectedItem.Allowed)
{
result.Add(new MethodTaskItem("Deny", "Deny...", string.Empty).SetUsage());
}
else
{
result.Add(new MethodTaskItem("Allow", "Allow...", string.Empty).SetUsage());
}
result.Add(new MethodTaskItem("Edit", "Edit...", string.Empty).SetUsage());
result.Add(RemoveTaskItem);
}
result.Add(MethodTaskItem.CreateSeparator().SetUsage());
result.Add(new MethodTaskItem("Set", "Edit Feature Settings...", string.Empty).SetUsage());
return result.ToArray(typeof(TaskItem)) as TaskItem[];
}
[Obfuscation(Exclude = true)]
public void Add()
{
_owner.Add();
}
[Obfuscation(Exclude = true)]
public override void Remove()
{
_owner.Remove();
}
[Obfuscation(Exclude = true)]
public void Edit()
{
_owner.Edit();
}
[Obfuscation(Exclude = true)]
public void Set()
{
_owner.Set();
}
[Obfuscation(Exclude = true)]
public void Deny()
{
_owner.Deny();
}
[Obfuscation(Exclude = true)]
public void Allow()
{
_owner.Allow();
}
}
public IsapiCgiRestrictionFeature(Module module)
: base(module)
{
}
protected static readonly Version FxVersion10 = new Version("1.0");
protected static readonly Version FxVersion11 = new Version("1.1");
protected static readonly Version FxVersion20 = new Version("2.0");
protected static readonly Version FxVersionNotRequired = new Version();
private FeatureTaskList _taskList;
public TaskList GetTaskList()
{
return _taskList ?? (_taskList = new FeatureTaskList(this));
}
public void Load()
{
LoadItems();
}
protected override ConfigurationElementCollection GetCollection(IConfigurationService service)
{
ConfigurationSection section = service.GetSection("system.webServer/security/isapiCgiRestriction", null, false);
return section.GetCollection();
}
public void Add()
{
using var dialog = new NewRestrictionDialog(Module, null, this);
if (dialog.ShowDialog() != DialogResult.OK)
{
return;
}
AddItem(dialog.Item);
}
public void Deny()
{
SetAllowed(false);
}
public void Allow()
{
SetAllowed(true);
}
private void SetAllowed(bool allowed)
{
SelectedItem.Allowed = allowed;
SelectedItem.Apply();
var service = (IConfigurationService)GetService(typeof(IConfigurationService));
service.ServerManager.CommitChanges();
OnSettingsSaved();
}
public void Set()
{
var service = (IConfigurationService)GetService(typeof(IConfigurationService));
var section = service.GetSection("system.webServer/security/isapiCgiRestriction");
using (var dialog = new SettingsDialog(Module, section, this))
{
if (dialog.ShowDialog() != DialogResult.OK)
{
return;
}
}
service.ServerManager.CommitChanges();
OnSettingsSaved();
}
public void Remove()
{
var dialog = (IManagementUIService)GetService(typeof(IManagementUIService));
if (
dialog.ShowMessage("Are you sure that you want to remove the selected restriction?", "Confirm Remove",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) !=
DialogResult.Yes)
{
return;
}
RemoveItem();
}
public void Edit()
{
using var dialog = new NewRestrictionDialog(Module, SelectedItem, this);
if (dialog.ShowDialog() != DialogResult.OK)
{
return;
}
EditItem(dialog.Item);
}
protected override void OnSettingsSaved()
{
IsapiCgiRestrictionSettingsUpdated?.Invoke();
}
public virtual bool ShowHelp()
{
DialogHelper.ProcessStart("http://go.microsoft.com/fwlink/?LinkId=210515");
return false;
}
public IsapiCgiRestrictionSettingsSavedEventHandler IsapiCgiRestrictionSettingsUpdated { get; set; }
public string Description { get; }
public virtual Version MinimumFrameworkVersion
{
get { return FxVersionNotRequired; }
}
public string Name
{
get { return "ISAPI and CGI Restrictions"; }
}
}
}