public HandlersListViewItem(HandlersItem item, HandlersPage page) : base(item.Name) { this.Item = item; _page = page; this.SubItems.Add(new ListViewSubItem(this, item.Path)); this.SubItems.Add(new ListViewSubItem(this, item.GetState(page._feature.AccessPolicy))); this.SubItems.Add(new ListViewSubItem(this, item.PathType)); this.SubItems.Add(new ListViewSubItem(this, item.TypeString)); this.SubItems.Add(new ListViewSubItem(this, item.Flag)); }
public NewScriptMapDialog(IServiceProvider serviceProvider, HandlersItem existing, HandlersFeature feature) : base(serviceProvider) { InitializeComponent(); Text = existing == null ? "Add Script Map" : "Edit Script Map"; txtName.ReadOnly = existing != null; _feature = feature; Item = existing ?? new HandlersItem(null); if (existing == null) { Item.Modules = "IsapiModule"; } else { txtExecutable.Text = Item.ScriptProcessor; txtName.Text = Item.Name; txtPath.Text = Item.Path; } var container = new CompositeDisposable(); FormClosed += (sender, args) => container.Dispose(); container.Add( Observable.FromEventPattern <EventArgs>(btnOK, "Click") .Subscribe(evt => { Item.ScriptProcessor = txtExecutable.Text; Item.Name = txtName.Text; Item.Path = txtPath.Text; if (!txtName.ReadOnly && _feature.Items.Any(item => item.Match(Item))) { ShowMessage( "A handler with this name already exists.", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } DialogResult = DialogResult.OK; })); container.Add( Observable.FromEventPattern <EventArgs>(txtName, "TextChanged") .Merge(Observable.FromEventPattern <EventArgs>(txtExecutable, "TextChanged")) .Merge(Observable.FromEventPattern <EventArgs>(txtPath, "TextChanged")) .Sample(TimeSpan.FromSeconds(1)) .Subscribe(evt => { btnOK.Enabled = !string.IsNullOrWhiteSpace(txtName.Text) && !string.IsNullOrWhiteSpace(txtExecutable.Text) && !string.IsNullOrWhiteSpace(txtPath.Text); })); container.Add( Observable.FromEventPattern <EventArgs>(btnRestrictions, "Click") .Subscribe(evt => { var dialog = new RestrictionsDialog(ServiceProvider, Item); if (dialog.ShowDialog() != DialogResult.OK) { return; } })); container.Add( Observable.FromEventPattern <EventArgs>(btnBrowse, "Click") .Subscribe(evt => { DialogHelper.ShowBrowseDialog(txtExecutable); })); }
public NewMappingDialog(IServiceProvider serviceProvider, HandlersItem existing, HandlersFeature feature) : base(serviceProvider) { InitializeComponent(); Text = existing == null ? "Add Module Mapping" : "Edit Module Mapping"; txtName.ReadOnly = existing != null; _feature = feature; Item = existing ?? new HandlersItem(null); var modules = new ModulesFeature((Module)serviceProvider); modules.Load(); foreach (var module in modules.Items.Where(module => !module.IsManaged).OrderBy(module => module.Name)) { txtModule.Items.Add(module.Name); } if (existing != null) { txtExecutable.Text = Item.ScriptProcessor; txtModule.Text = Item.Modules; txtName.Text = Item.Name; txtPath.Text = Item.Path; } var container = new CompositeDisposable(); FormClosed += (sender, args) => container.Dispose(); container.Add( Observable.FromEventPattern <EventArgs>(btnOK, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { Item.ScriptProcessor = txtExecutable.Text; Item.Modules = txtModule.Text; Item.Name = txtName.Text; Item.Path = txtPath.Text; if (!txtName.ReadOnly) { if (_feature.Items.Any(item => item.Match(Item))) { ShowMessage( "A handler with this name already exists.", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } if (txtModule.Text == "FastCgiModule") { var result = ShowMessage( "Do you want to create a FastCGI application for this executable? Click \"Yes\" to add the entry to the FastCGI collection and to enable this executable to run as a FastCGI application.", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); if (result == DialogResult.Yes) { var fastCgi = new FastCgiFeature((Module)ServiceProvider); if (fastCgi.Items.All(item => item.Path != txtExecutable.Text)) { fastCgi.AddItem(new FastCgiItem(null) { Path = txtExecutable.Text }); } } } if (!string.IsNullOrWhiteSpace(txtExecutable.Text) && !File.Exists(txtExecutable.Text)) { ShowMessage( "The specific executable does not exist on the server.", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } } DialogResult = DialogResult.OK; })); container.Add( Observable.FromEventPattern <EventArgs>(txtName, "TextChanged") .Merge(Observable.FromEventPattern <EventArgs>(txtExecutable, "TextChanged")) .Merge(Observable.FromEventPattern <EventArgs>(txtPath, "TextChanged")) .Sample(TimeSpan.FromSeconds(1)) .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { btnOK.Enabled = !string.IsNullOrWhiteSpace(txtName.Text) && !string.IsNullOrWhiteSpace(txtModule.Text) && !string.IsNullOrWhiteSpace(txtPath.Text); })); container.Add( Observable.FromEventPattern <EventArgs>(btnRestrictions, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { var dialog = new RestrictionsDialog(ServiceProvider, Item); if (dialog.ShowDialog() != DialogResult.OK) { return; } })); container.Add( Observable.FromEventPattern <EventArgs>(btnBrowse, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { DialogHelper.ShowFileDialog(txtExecutable, "|*.dll||*.exe"); })); }
public NewMappingDialog(IServiceProvider serviceProvider, HandlersItem existing, HandlersFeature feature) : base(serviceProvider) { InitializeComponent(); Text = existing == null ? "Add Module Mapping" : "Edit Module Mapping"; txtName.ReadOnly = existing != null; _feature = feature; Item = existing ?? new HandlersItem(null); var modules = new ModulesFeature((Module)serviceProvider); modules.Load(); foreach (var module in modules.Items.Where(module => !module.IsManaged).OrderBy(module => module.Name)) { txtModule.Items.Add(module.Name); } if (existing != null) { txtExecutable.Text = Item.ScriptProcessor; txtModule.Text = Item.Modules; txtName.Text = Item.Name; txtPath.Text = Item.Path; } var container = new CompositeDisposable(); FormClosed += (sender, args) => container.Dispose(); container.Add( Observable.FromEventPattern <EventArgs>(btnOK, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { Item.ScriptProcessor = txtExecutable.Text; Item.Modules = txtModule.Text; Item.Name = txtName.Text; Item.Path = txtPath.Text; if ((txtModule.Text == "FastCgiModule" || txtModule.Text == "CgiModule") && !string.Equals(Path.GetExtension(Item.ScriptProcessor), ".exe", StringComparison.OrdinalIgnoreCase)) { ShowMessage("The executable specified for the CgiModule or the FastCgiModule should be a .exe file."); return; } if (!txtName.ReadOnly) { if (_feature.Items.Any(item => item.Match(Item))) { ShowMessage( "A handler with this name already exists.", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } var path = txtExecutable.Text; string arguments = string.Empty; var index = path.IndexOf('|'); if (index > -1) { arguments = path.Substring(index + 1); path = path.Substring(0, index); } if (!string.IsNullOrWhiteSpace(path)) { var ext = Path.GetExtension(path); if (!string.Equals(ext, ".dll", StringComparison.OrdinalIgnoreCase) && !string.Equals(ext, ".exe", StringComparison.OrdinalIgnoreCase)) { // TODO: test path with spaces case. ShowMessage("The specific executable for the handler must be a .dll or .exe file. If the path to the script processor (only in the case of a .exe file) has spaces, use double quotation marks to specify the executable.", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); return; } if (!File.Exists(path)) { ShowMessage( "The specific executable does not exist on the server.", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } } if (txtModule.Text == "FastCgiModule") { // IMPORTANT: it is IIS Manager behavior to prompt before verifying duplicate items. var result = ShowMessage( "Do you want to create a FastCGI application for this executable? Click \"Yes\" to add the entry to the FastCGI collection and to enable this executable to run as a FastCGI application.", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); if (result == DialogResult.Yes) { var fastCgi = new FastCgiFeature((Module)ServiceProvider); fastCgi.Load(); if (fastCgi.Items.All(item => item.Path != path && item.Arguments != arguments)) { fastCgi.AddItem(new FastCgiItem(null) { Path = path, Arguments = arguments }); } } } } try { if (txtModule.Text != "FastCgiModule" && txtModule.Text != "CgiModule") { var bit32Condition = "bitness32"; var bit64Condition = "bitness64"; var bit32 = DialogHelper.GetImageArchitecture(txtExecutable.Text); if (bit32 && !Item.PreConditions.Contains(bit32Condition)) { Item.PreConditions.Add(bit32Condition); } else if (!bit32 && !Item.PreConditions.Contains(bit64Condition)) { Item.PreConditions.Add(bit64Condition); } } } catch (Exception) { ShowMessage( "The specific executable is invalid.", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } DialogResult = DialogResult.OK; })); container.Add( Observable.FromEventPattern <EventArgs>(txtName, "TextChanged") .Merge(Observable.FromEventPattern <EventArgs>(txtExecutable, "TextChanged")) .Merge(Observable.FromEventPattern <EventArgs>(txtPath, "TextChanged")) .Sample(TimeSpan.FromSeconds(0.5)) .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { btnOK.Enabled = !string.IsNullOrWhiteSpace(txtName.Text) && !string.IsNullOrWhiteSpace(txtModule.Text) && !string.IsNullOrWhiteSpace(txtPath.Text); })); container.Add( Observable.FromEventPattern <EventArgs>(btnRestrictions, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { var dialog = new RestrictionsDialog(ServiceProvider, Item); if (dialog.ShowDialog() != DialogResult.OK) { return; } })); container.Add( Observable.FromEventPattern <EventArgs>(btnBrowse, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { DialogHelper.ShowOpenFileDialog(txtExecutable, "(*.dll)|*.dll|(*.exe)|*.exe", null); })); }
public NewHandlerDialog(IServiceProvider serviceProvider, HandlersItem existing, HandlersFeature feature) : base(serviceProvider) { InitializeComponent(); Text = existing == null ? "Add Managed Handler" : "Edit Managed Handler"; txtName.ReadOnly = existing != null; _feature = feature; Item = existing ?? new HandlersItem(null); if (existing != null) { txtType.Text = Item.Type; txtName.Text = Item.Name; txtPath.Text = Item.Path; } var container = new CompositeDisposable(); FormClosed += (sender, args) => container.Dispose(); container.Add( Observable.FromEventPattern <EventArgs>(btnOK, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { Item.Type = txtType.Text; Item.Name = txtName.Text; Item.Path = txtPath.Text; if (!txtName.ReadOnly && _feature.Items.Any(item => item.Match(Item))) { ShowMessage( "A handler with this name already exists.", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } DialogResult = DialogResult.OK; })); container.Add( Observable.FromEventPattern <EventArgs>(txtName, "TextChanged") .Merge(Observable.FromEventPattern <EventArgs>(txtType, "TextChanged")) .Merge(Observable.FromEventPattern <EventArgs>(txtPath, "TextChanged")) .Sample(TimeSpan.FromSeconds(1)) .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { btnOK.Enabled = !string.IsNullOrWhiteSpace(txtName.Text) && !string.IsNullOrWhiteSpace(txtType.Text) && !string.IsNullOrWhiteSpace(txtPath.Text); })); container.Add( Observable.FromEventPattern <EventArgs>(btnRestrictions, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { var dialog = new RestrictionsDialog(ServiceProvider, Item); if (dialog.ShowDialog() != DialogResult.OK) { return; } })); }
public RestrictionsDialog(IServiceProvider serviceProvider, HandlersItem item) : base(serviceProvider) { InitializeComponent(); cbInvoke.Checked = item.ResourceType != 3L; rbFile.Checked = item.ResourceType == 0L; rbFolder.Checked = item.ResourceType == 1L; rbEither.Checked = item.ResourceType == 2L; rbNone.Checked = item.RequireAccess == 0L; rbRead.Checked = item.RequireAccess == 1L; rbWrite.Checked = item.RequireAccess == 2L; rbScript.Checked = item.RequireAccess == 3L; rbExecute.Checked = item.RequireAccess == 4L; rbAllVerbs.Checked = item.Verb == "*"; rbSelectedVerbs.Checked = !rbAllVerbs.Checked; if (rbSelectedVerbs.Checked) { txtVerbs.Text = item.Verb; } var container = new CompositeDisposable(); FormClosed += (sender, args) => container.Dispose(); container.Add( Observable.FromEventPattern <EventArgs>(btnOK, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { if (!cbInvoke.Checked) { item.ResourceType = 3L; } else if (rbFile.Checked) { item.ResourceType = 0L; } else if (rbFolder.Checked) { item.ResourceType = 1L; } else if (rbEither.Checked) { item.ResourceType = 2L; } if (rbNone.Checked) { item.RequireAccess = 0L; } else if (rbRead.Checked) { item.RequireAccess = 1L; } else if (rbWrite.Checked) { item.RequireAccess = 2L; } else if (rbScript.Checked) { item.RequireAccess = 3L; } else if (rbExecute.Checked) { item.RequireAccess = 4L; } if (rbAllVerbs.Checked) { item.Verb = "*"; } else if (rbSelectedVerbs.Checked) { item.Verb = txtVerbs.Text; } DialogResult = DialogResult.OK; })); container.Add( Observable.FromEventPattern <EventArgs>(cbInvoke, "CheckedChanged") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { rbFile.Enabled = rbFolder.Enabled = rbEither.Enabled = cbInvoke.Checked; })); container.Add( Observable.FromEventPattern <EventArgs>(rbSelectedVerbs, "CheckedChanged") .Merge(Observable.FromEventPattern <EventArgs>(rbAllVerbs, "CheckedChanged")) .Sample(TimeSpan.FromSeconds(1)) .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { txtVerbs.Enabled = rbSelectedVerbs.Checked; })); }