EaseFilter Demo Project
FilterRuleForm.cs
Go to the documentation of this file.
1 //
3 // (C) Copyright 2012 EaseFilter Technologies Inc.
4 // All Rights Reserved
5 //
6 // This software is part of a licensed software product and may
7 // only be used or copied in accordance with the terms of that license.
8 //
10 
11 using System;
12 using System.Collections.Generic;
13 using System.ComponentModel;
14 using System.Data;
15 using System.Drawing;
16 using System.Linq;
17 using System.Text;
18 using System.Windows.Forms;
19 
20 namespace EaseFilter.CommonObjects
21 {
22  public partial class FilterRuleForm : Form
23  {
24  public FilterRuleForm(FilterRule filterRule)
25  {
26  InitializeComponent();
27 
28  textBox_IncludeFilterMask.Text = filterRule.IncludeFileFilterMask;
29  textBox_ExcludeFilterMask.Text = filterRule.ExcludeFileFilterMasks;
30  textBox_FileAccessFlags.Text = filterRule.AccessFlag.ToString();
31  textBox_PassPhrase.Text = filterRule.EncryptionPassPhrase;
32  textBox_SelectedEvents.Text = filterRule.EventType.ToString();
33  textBox_HiddenFilterMask.Text = filterRule.HiddenFileFilterMasks;
34  textBox_IncludePID.Text = filterRule.IncludeProcessIds;
35  textBox_ExcludePID.Text = filterRule.ExcludeProcessIds;
36  textBox_ExcludeProcessNames.Text = filterRule.ExcludeProcessNames;
37  textBox_IncludeProcessNames.Text = filterRule.IncludeProcessNames;
38  textBox_ExcludeUserNames.Text = filterRule.ExcludeUserNames;
39  textBox_IncludeUserNames.Text = filterRule.IncludeUserNames;
40  textBox_MonitorIO.Text = filterRule.MonitorIO.ToString();
41  textBox_ControlIO.Text = filterRule.ControlIO.ToString();
42 
43  if (GlobalConfig.filterType == FilterAPI.FilterType.FILE_SYSTEM_MONITOR)
44  {
45  groupBox_AccessControl.Visible = false;
46  }
47  else
48  {
49  SetCheckBoxValue();
50  }
51  }
52 
53 
54  private void SetCheckBoxValue()
55  {
56 
57  uint accessFlags = uint.Parse(textBox_FileAccessFlags.Text);
58 
59  if ((accessFlags & (uint)FilterAPI.AccessFlag.FILE_ENCRYPTION_RULE) > 0 && textBox_PassPhrase.Text.Length > 0 )
60  {
61  checkBox_Encryption.Checked = true;
62  textBox_PassPhrase.ReadOnly = false;
63  }
64  else
65  {
66  checkBox_Encryption.Checked = false;
67  }
68 
69  if ((accessFlags & (uint)FilterAPI.AccessFlag.ALLOW_FILE_ACCESS_FROM_NETWORK) > 0)
70  {
71  checkBox_AllowRemoteAccess.Checked = true;
72  }
73  else
74  {
75  checkBox_AllowRemoteAccess.Checked = false;
76  }
77 
78  if ((accessFlags & (uint)FilterAPI.AccessFlag.ALLOW_FILE_DELETE) > 0)
79  {
80  checkBox_AllowDelete.Checked = true;
81  }
82  else
83  {
84  checkBox_AllowDelete.Checked = false;
85  }
86 
87  if ((accessFlags & (uint)FilterAPI.AccessFlag.ALLOW_FILE_RENAME) > 0)
88  {
89  checkBox_AllowRename.Checked = true;
90  }
91  else
92  {
93  checkBox_AllowRename.Checked = false;
94  }
95 
96  if ((accessFlags & (uint)FilterAPI.AccessFlag.ALLOW_WRITE_ACCESS) > 0
97  && (accessFlags & (uint)FilterAPI.AccessFlag.ALLOW_SET_INFORMATION) > 0)
98  {
99  checkBox_AllowChange.Checked = true;
100  }
101  else
102  {
103  checkBox_AllowChange.Checked = false;
104  }
105 
106  if ((accessFlags & (uint)FilterAPI.AccessFlag.ALLOW_OPEN_WITH_CREATE_OR_OVERWRITE_ACCESS) > 0)
107  {
108  checkBox_AllowNewFileCreation.Checked = true;
109  }
110  else
111  {
112  checkBox_AllowNewFileCreation.Checked = false;
113  }
114 
115  }
116 
117  private void button_FileAccessFlags_Click(object sender, EventArgs e)
118  {
119  OptionForm optionForm = new OptionForm(OptionForm.OptionType.Access_Flag, textBox_FileAccessFlags.Text);
120 
121  if (optionForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
122  {
123  textBox_FileAccessFlags.Text = optionForm.AccessFlags.ToString();
124  SetCheckBoxValue();
125  }
126  }
127 
128 
129  private void button_SaveFilter_Click(object sender, EventArgs e)
130  {
131  if (textBox_IncludeFilterMask.Text.Trim().Length == 0)
132  {
133  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
134  MessageBox.Show("The include filter mask can't be empty.", "Add Filter Rule", MessageBoxButtons.OK, MessageBoxIcon.Error);
135  return;
136  }
137 
138  //include filter mask must be unique, but it can have multiple exclude filter masks associate to the same include filter mask.
139  string encryptionPassPhrase = string.Empty;
140  uint accessFlags = uint.Parse(textBox_FileAccessFlags.Text);
141 
142  if (checkBox_Encryption.Checked)
143  {
144  encryptionPassPhrase = textBox_PassPhrase.Text;
145 
146  //enable encryption for this filter rule.
147  accessFlags = accessFlags|(uint)FilterAPI.AccessFlag.FILE_ENCRYPTION_RULE;
148  }
149 
150  if (textBox_HiddenFilterMask.Text.Trim().Length > 0)
151  {
152  //enable hidden filter mask for this filter rule.
153  accessFlags = accessFlags | (uint)FilterAPI.AccessFlag.HIDE_FILES_IN_DIRECTORY_BROWSING;
154  }
155 
156  FilterRule filterRule = new FilterRule();
157  filterRule.IncludeFileFilterMask = textBox_IncludeFilterMask.Text;
158  filterRule.ExcludeFileFilterMasks = textBox_ExcludeFilterMask.Text;
159  filterRule.EncryptionPassPhrase = encryptionPassPhrase;
160  filterRule.IncludeProcessNames = textBox_IncludeProcessNames.Text;
161  filterRule.ExcludeProcessNames = textBox_ExcludeProcessNames.Text;
162  filterRule.IncludeUserNames = textBox_IncludeUserNames.Text;
163  filterRule.ExcludeUserNames = textBox_ExcludeUserNames.Text;
164  filterRule.IncludeProcessIds = textBox_IncludePID.Text;
165  filterRule.ExcludeProcessIds = textBox_ExcludePID.Text;
166  filterRule.HiddenFileFilterMasks = textBox_HiddenFilterMask.Text;
167  filterRule.AccessFlag = accessFlags;
168  filterRule.EventType = uint.Parse(textBox_SelectedEvents.Text);
169  filterRule.MonitorIO = uint.Parse(textBox_MonitorIO.Text);
170  filterRule.ControlIO = uint.Parse(textBox_ControlIO.Text);
171  GlobalConfig.AddFilterRule(filterRule);
172 
173  this.Close();
174  }
175 
176  private void checkBox_Encryption_CheckedChanged(object sender, EventArgs e)
177  {
178  uint accessFlags = uint.Parse(textBox_FileAccessFlags.Text);
179 
180  if (checkBox_Encryption.Checked)
181  {
182  textBox_PassPhrase.ReadOnly = false;
183  accessFlags = accessFlags | ((uint)FilterAPI.AccessFlag.FILE_ENCRYPTION_RULE);
184  }
185  else
186  {
187  textBox_PassPhrase.ReadOnly = true;
188  accessFlags = accessFlags & ((uint)~FilterAPI.AccessFlag.FILE_ENCRYPTION_RULE);
189  }
190 
191  textBox_FileAccessFlags.Text = accessFlags.ToString();
192  }
193 
194  private void checkBox_AllowDelete_CheckedChanged(object sender, EventArgs e)
195  {
196 
197  uint accessFlags = uint.Parse(textBox_FileAccessFlags.Text);
198 
199  if (!checkBox_AllowDelete.Checked)
200  {
201  accessFlags = accessFlags & ((uint)~FilterAPI.AccessFlag.ALLOW_FILE_DELETE);
202  }
203  else
204  {
205  accessFlags = accessFlags | ((uint)FilterAPI.AccessFlag.ALLOW_FILE_DELETE);
206  }
207 
208  textBox_FileAccessFlags.Text = accessFlags.ToString();
209  }
210 
211  private void checkBox_AllowChange_CheckedChanged(object sender, EventArgs e)
212  {
213  uint accessFlags = uint.Parse(textBox_FileAccessFlags.Text);
214  if (!checkBox_AllowChange.Checked)
215  {
216  accessFlags = accessFlags & ((uint)~FilterAPI.AccessFlag.ALLOW_WRITE_ACCESS) & ((uint)~FilterAPI.AccessFlag.ALLOW_SET_INFORMATION);
217  }
218  else
219  {
220  accessFlags = accessFlags | ((uint)FilterAPI.AccessFlag.ALLOW_WRITE_ACCESS) | ((uint)FilterAPI.AccessFlag.ALLOW_SET_INFORMATION);
221  }
222 
223  textBox_FileAccessFlags.Text = accessFlags.ToString();
224  }
225 
226  private void checkBox_AllowRename_CheckedChanged(object sender, EventArgs e)
227  {
228  uint accessFlags = uint.Parse(textBox_FileAccessFlags.Text);
229 
230  if (!checkBox_AllowRename.Checked)
231  {
232  accessFlags = accessFlags & ((uint)~FilterAPI.AccessFlag.ALLOW_FILE_RENAME);
233  }
234  else
235  {
236  accessFlags = accessFlags | ((uint)FilterAPI.AccessFlag.ALLOW_FILE_RENAME);
237  }
238 
239  textBox_FileAccessFlags.Text = accessFlags.ToString();
240  }
241 
242  private void checkBox_AllowRemoteAccess_CheckedChanged(object sender, EventArgs e)
243  {
244  uint accessFlags = uint.Parse(textBox_FileAccessFlags.Text);
245 
246  if (!checkBox_AllowRemoteAccess.Checked)
247  {
248  accessFlags = accessFlags & ((uint)~FilterAPI.AccessFlag.ALLOW_FILE_ACCESS_FROM_NETWORK);
249  }
250  else
251  {
252  accessFlags = accessFlags | ((uint)FilterAPI.AccessFlag.ALLOW_FILE_ACCESS_FROM_NETWORK);
253  }
254 
255  textBox_FileAccessFlags.Text = accessFlags.ToString();
256  }
257 
258  private void checkBox_AllowNewFileCreation_CheckedChanged(object sender, EventArgs e)
259  {
260  uint accessFlags = uint.Parse(textBox_FileAccessFlags.Text);
261 
262  if (!checkBox_AllowNewFileCreation.Checked)
263  {
264  accessFlags = accessFlags & ((uint)~FilterAPI.AccessFlag.ALLOW_OPEN_WITH_CREATE_OR_OVERWRITE_ACCESS);
265  }
266  else
267  {
268  accessFlags = accessFlags | ((uint)FilterAPI.AccessFlag.ALLOW_OPEN_WITH_CREATE_OR_OVERWRITE_ACCESS);
269  }
270 
271  textBox_FileAccessFlags.Text = accessFlags.ToString();
272  }
273 
274  private void checkBox_DisplayPassword_CheckedChanged(object sender, EventArgs e)
275  {
276  if (checkBox_DisplayPassword.Checked)
277  {
278  textBox_PassPhrase.UseSystemPasswordChar = false;
279  }
280  else
281  {
282  textBox_PassPhrase.UseSystemPasswordChar = true;
283  }
284  }
285 
286  private void button_SelectIncludePID_Click(object sender, EventArgs e)
287  {
288 
289  OptionForm optionForm = new OptionForm(OptionForm.OptionType.ProccessId, textBox_IncludePID.Text);
290 
291  if (optionForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
292  {
293  textBox_IncludePID.Text = optionForm.ProcessId;
294  }
295  }
296 
297  private void button_SelectExcludePID_Click(object sender, EventArgs e)
298  {
299 
300  OptionForm optionForm = new OptionForm(OptionForm.OptionType.ProccessId, textBox_ExcludePID.Text);
301 
302  if (optionForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
303  {
304  textBox_ExcludePID.Text = optionForm.ProcessId;
305  }
306  }
307 
308  private void button_SelectedEvents_Click(object sender, EventArgs e)
309  {
310  OptionForm optionForm = new OptionForm(OptionForm.OptionType.EventNotification, textBox_SelectedEvents.Text);
311 
312  if (optionForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
313  {
314  textBox_SelectedEvents.Text = optionForm.EventNotification.ToString();
315  }
316  }
317 
318  private void button_RegisterMonitorIO_Click(object sender, EventArgs e)
319  {
320  OptionForm optionForm = new OptionForm(OptionForm.OptionType.Register_Request, textBox_MonitorIO.Text,true);
321 
322  if (optionForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
323  {
324  textBox_MonitorIO.Text = optionForm.RequestRegistration.ToString();
325  }
326  }
327 
328  private void button_RegisterControlIO_Click(object sender, EventArgs e)
329  {
330  OptionForm optionForm = new OptionForm(OptionForm.OptionType.Register_Request, textBox_ControlIO.Text);
331 
332  if (optionForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
333  {
334  textBox_ControlIO.Text = optionForm.RequestRegistration.ToString();
335  }
336  }
337 
338  }
339 }
static bool AddFilterRule(FilterRule newRule)
uint EventType
The register the file I/O events
uint ControlIO
register control I/O requests, the filter driver will block and wait for the response.
static FilterAPI.FilterType filterType
Definition: GlobalConfig.cs:79
uint MonitorIO
register monitor I/O requests

Social Network


Services Overview

Architect, implement and test file system filter drivers for a wide range of functionality. We can offer several levels of assistance to meet your specific.

Contact Us

You are welcome to contact us for salse or partnership.

Sales: sales@easefilter.com
Support: support@easefilter.com
Info: info@easefilter.com