protected override void Initialize(object navigationData) { base.Initialize(navigationData); var service = (IConfigurationService)GetService(typeof(IConfigurationService)); pictureBox1.Image = service.Scope.GetImage(); _feature = new IpSecurityFeature(Module); _feature.IpSecuritySettingsUpdated = InitializeListPage; _feature.Load(); }
public DynamicDialog(IServiceProvider serviceProvider, ConfigurationSection section, IpSecurityFeature feature) : base(serviceProvider) { InitializeComponent(); var concurrent = section.ChildElements["denyByConcurrentRequests"]; cbConcurrent.Checked = (bool)concurrent["enabled"]; txtConcurrent.Text = concurrent["maxConcurrentRequests"].ToString(); var rate = section.ChildElements["denyByRequestRate"]; cbInterval.Checked = (bool)rate["enabled"]; txtNumer.Text = rate["maxRequests"].ToString(); txtPeriod.Text = rate["requestIntervalInMilliseconds"].ToString(); cbLogging.Checked = (bool)section["enableLoggingOnlyMode"]; var container = new CompositeDisposable(); FormClosed += (sender, args) => container.Dispose(); var load = Observable.FromEventPattern <EventArgs>(this, "Load"); container.Add( Observable.FromEventPattern <EventArgs>(cbInterval, "CheckedChanged") .Merge(load) .Sample(TimeSpan.FromSeconds(1)) .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { txtPeriod.Enabled = txtNumer.Enabled = cbInterval.Checked; })); container.Add( Observable.FromEventPattern <EventArgs>(cbConcurrent, "CheckedChanged") .Merge(load) .Sample(TimeSpan.FromSeconds(1)) .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { txtConcurrent.Enabled = cbConcurrent.Checked; })); container.Add( Observable.FromEventPattern <EventArgs>(btnOK, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { uint result; if (!uint.TryParse(txtConcurrent.Text, out result)) { ShowMessage( "Input string was not in a correct format", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } concurrent["enabled"] = cbConcurrent.Checked; concurrent["maxConcurrentRequests"] = result; rate["enabled"] = cbInterval.Checked; if (!uint.TryParse(txtNumer.Text, out result)) { // TODO: show validator error. ShowMessage( "Input string was not in a correct format", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } rate["maxRequests"] = result; if (!uint.TryParse(txtNumer.Text, out result)) { // TODO: show validator error. ShowMessage( "Input string was not in a correct format", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } rate["requestIntervalInMilliseconds"] = result; section["enableLoggingOnlyMode"] = cbLogging.Checked; DialogResult = DialogResult.OK; })); container.Add( Observable.FromEventPattern <CancelEventArgs>(this, "HelpButtonClicked") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(EnvironmentVariableTarget => { feature.ShowHelp(); })); }
public NewRestrictionDialog(IServiceProvider serviceProvider, bool allowed, IpSecurityFeature feature) : base(serviceProvider) { InitializeComponent(); Text = allowed ? "Add Allow Restriction Rule" : "Add Deny Restriction Rule"; txtDescription.Text = allowed ? "Allow access for the following IP address or domain name:" : "Deny access for the following IP address or domain name:"; var container = new CompositeDisposable(); FormClosed += (sender, args) => container.Dispose(); container.Add( Observable.FromEventPattern <EventArgs>(rbAddress, "CheckedChanged") .Merge(Observable.FromEventPattern <EventArgs>(rbRange, "CheckedChanged")) .Sample(TimeSpan.FromSeconds(1)) .Subscribe(evt => { txtAddress.Enabled = rbAddress.Checked; txtRange.Enabled = rbRange.Checked; txtMask.Enabled = rbRange.Checked; })); container.Add( Observable.FromEventPattern <EventArgs>(btnOK, "Click") .Subscribe(evt => { if (rbAddress.Checked) { IPAddress result; var passed = IPAddress.TryParse(txtAddress.Text, out result); if (!passed) { MessageBox.Show(string.Format("'{0}' is an invalid IP address.", txtAddress.Text), Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } Item = new IpSecurityItem(null); Item.Address = txtAddress.Text; Item.Mask = string.Empty; Item.Allowed = allowed; if (feature.Items.Any(item => item.Match(Item))) { ShowMessage( "A restriction for this domain name or IP address already exists.", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } DialogResult = DialogResult.OK; return; } IPAddress result1; var passed1 = IPAddress.TryParse(txtRange.Text, out result1); if (!passed1) { ShowMessage( string.Format("'{0}' is an invalid IP address.", txtRange.Text), MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } var passed2 = IPAddress.TryParse(txtMask.Text, out result1); if (!passed2) { int value; var passed3 = int.TryParse(txtMask.Text, out value); if (!passed3 || (result1.AddressFamily == AddressFamily.InterNetwork && (value < 0 || value > 32)) || (result1.AddressFamily == AddressFamily.InterNetworkV6 && (value < 0 || value > 128))) { ShowMessage( string.Format( "'{0}' is an invalid subnet mask. It must be a valid IP address or an integer value between 0-32 for IPv4 ad 0-128 for IPv6.", txtMask.Text), MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } } Item = new IpSecurityItem(null); Item.Address = txtRange.Text; Item.Mask = txtMask.Text; Item.Allowed = allowed; if (feature.Items.Any(item => item.Match(Item))) { ShowMessage( "A restriction for this domain name or IP address already exists.", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } DialogResult = DialogResult.OK; })); }
public SetRestrictionsDialog(IServiceProvider serviceProvider, ConfigurationSection section, IpSecurityFeature feature) : base(serviceProvider) { InitializeComponent(); cbDomain.Checked = (bool)section["enableReverseDns"]; cbAccess.SelectedIndex = (bool)section["allowUnlisted"] ? 0 : 1; cbProxy.Enabled = section.Schema.AttributeSchemas["enabled"] != null; if (cbProxy.Enabled) { cbProxy.Checked = (bool)section["enableProxyMode"]; } cbAction.Enabled = section.Schema.AttributeSchemas["denyAction"] != null; if (cbAction.Enabled) { var action = (long)section["denyAction"]; if (action == 0L) { cbAction.SelectedIndex = 0; } else if (action == 401L) { cbAction.SelectedIndex = 1; } else if (action == 403L) { cbAction.SelectedIndex = 2; } else { cbAction.SelectedIndex = 3; } } var container = new CompositeDisposable(); FormClosed += (sender, args) => container.Dispose(); container.Add( Observable.FromEventPattern <EventArgs>(btnOK, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { section["enableReverseDns"] = cbDomain.Checked; section["allowUnlisted"] = cbAccess.SelectedIndex == 0; if (cbProxy.Enabled) { section["enableProxyMode"] = cbProxy.Checked; } if (cbAction.Enabled) { if (cbAction.SelectedIndex == 0) { section["denyAction"] = 0L; } else if (cbAction.SelectedIndex == 1) { section["denyAction"] = 401L; } else if (cbAction.SelectedIndex == 2) { section["denyAction"] = 403L; } else { section["denyAction"] = 404L; } } DialogResult = DialogResult.OK; })); container.Add( Observable.FromEventPattern <CancelEventArgs>(this, "HelpButtonClicked") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(EnvironmentVariableTarget => { feature.ShowHelp(); })); }
public FeatureTaskList(IpSecurityFeature owner) { _owner = owner; }