private void btnSelect_Click(object sender, EventArgs e) { var dialog = new SelectPoolDialog(txtPool.Text, _application.Server); if (dialog.ShowDialog() != DialogResult.OK) { return; } txtPool.Text = dialog.Selected.Name; }
private void BtnChooseClick(object sender, EventArgs e) { var dialog = new SelectPoolDialog(txtPool.Text, _collection.Parent); if (dialog.ShowDialog() != DialogResult.OK) { return; } txtPool.Text = dialog.Selected.Name; }
public NewSiteDialog(IServiceProvider serviceProvider, SiteCollection collection) : base(serviceProvider) { InitializeComponent(); cbType.SelectedIndex = 0; if (collection == null) { throw new InvalidOperationException("null collection"); } if (collection.Parent == null) { throw new InvalidOperationException("null server for site collection"); } btnBrowse.Visible = collection.Parent.IsLocalhost; txtPool.Text = collection.Parent.ApplicationDefaults.ApplicationPoolName; btnChoose.Enabled = collection.Parent.Mode != WorkingMode.Jexus; txtHost.Text = collection.Parent.Mode == WorkingMode.IisExpress ? "localhost" : string.Empty; DialogHelper.LoadAddresses(cbAddress); if (!collection.Parent.SupportsSni) { cbSniRequired.Enabled = false; } var container = new CompositeDisposable(); FormClosed += (sender, args) => container.Dispose(); container.Add( Observable.FromEventPattern <EventArgs>(cbType, "SelectedIndexChanged") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { txtPort.Text = cbType.Text == "http" ? "80" : "443"; txtCertificates.Visible = cbType.SelectedIndex == 1; cbSniRequired.Visible = cbType.SelectedIndex == 1; cbCertificates.Visible = cbType.SelectedIndex == 1; btnSelect.Visible = cbType.SelectedIndex == 1; btnView.Visible = cbType.SelectedIndex == 1; })); container.Add( Observable.FromEventPattern <EventArgs>(btnBrowse, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { DialogHelper.ShowBrowseDialog(txtPath); })); container.Add( Observable.FromEventPattern <EventArgs>(btnOK, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { foreach (var ch in SiteCollection.InvalidSiteNameCharacters()) { if (txtName.Text.Contains(ch)) { MessageBox.Show("The site name cannot contain the following characters: '\\, /, ?, ;, :, @, &, =, +, $, ,, |, \", <, >'.", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } foreach (var ch in SiteCollection.InvalidSiteNameCharactersJexus()) { if (txtName.Text.Contains(ch) || txtName.Text.StartsWith("~")) { MessageBox.Show("The site name cannot contain the following characters: '~, '.", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } if (!collection.Parent.Verify(txtPath.Text)) { MessageBox.Show("The specified directory does not exist on the server.", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (!IPEndPointIsValid(out IPAddress address, out int port)) { return; } var invalid = "\"/\\[]:|<>+=;,?*$%#@{}^`".ToCharArray(); foreach (var ch in invalid) { if (txtHost.Text.Contains(ch)) { MessageBox.Show("The specified host name is incorrect. The host name must use a valid host name format and cannot contain the following characters: \"/\\[]:|<>+=;,?*$%#@{}^`. Example: www.contoso.com.", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } if (collection.Parent.Mode == WorkingMode.IisExpress) { if (txtHost.Text != "localhost") { MessageBox.Show( "The specific host name is not recommended for IIS Express. The host name should be localhost.", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } long largestId = 0; foreach (Site site in collection) { if (site.Id > largestId) { largestId = site.Id; } } largestId++; NewSite = new Site(collection) { Name = txtName.Text, Id = largestId }; var host = txtHost.Text.DisplayToHost(); var info = cbType.Text == "https" ? (CertificateInfo)cbCertificates.SelectedItem : null; var binding = new Binding( cbType.Text, string.Format("{0}:{1}:{2}", address.AddressToDisplay(), port, host.HostToDisplay()), info?.Certificate.GetCertHash() ?? new byte[0], info?.Store, cbSniRequired.Checked ? SslFlags.Sni : SslFlags.None, NewSite.Bindings); if (collection.FindDuplicate(binding, null, null) != false) { var result = MessageBox.Show(string.Format("The binding '{0}' is assigned to another site. If you assign the same binding to this site, you will only be able to start one of the sites. Are you sure that you want to add this duplicate binding?", binding), Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result != DialogResult.Yes) { collection.Remove(NewSite); return; } } if (collection.Parent.Mode == WorkingMode.IisExpress) { var result = binding.FixCertificateMapping(info?.Certificate); if (!string.IsNullOrEmpty(result)) { collection.Remove(NewSite); MessageBox.Show(string.Format("The binding '{0}' is invalid: {1}", binding, result), Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } var app = NewSite.Applications.Add(Application.RootPath, txtPath.Text); app.Name = string.Empty; app.ApplicationPoolName = txtPool.Text; NewSite.Bindings.Add(binding); DialogResult = DialogResult.OK; })); var certificatesSelected = Observable.FromEventPattern <EventArgs>(cbCertificates, "SelectedIndexChanged"); container.Add( certificatesSelected .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { btnView.Enabled = cbCertificates.SelectedIndex > 0; })); container.Add( Observable.FromEventPattern <EventArgs>(txtName, "TextChanged") .Merge(Observable.FromEventPattern <EventArgs>(txtPath, "TextChanged")) .Merge(Observable.FromEventPattern <EventArgs>(txtPort, "TextChanged")) .Merge(Observable.FromEventPattern <EventArgs>(cbAddress, "TextChanged")) .Merge(certificatesSelected) .Sample(TimeSpan.FromSeconds(1)) .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { if (Helper.IsRunningOnMono()) { return; } var toElevate = IPEndPointIsValid(out IPAddress address, out int port, false) ? BindingUtility.Verify(cbType.Text, cbAddress.Text, txtPort.Text, cbCertificates.SelectedItem as CertificateInfo) : false; btnOK.Enabled = toElevate != null && !string.IsNullOrWhiteSpace(txtName.Text) && !string.IsNullOrWhiteSpace(txtPath.Text); if (!toElevate.HasValue || !toElevate.Value) { NativeMethods.RemoveShieldFromButton(btnOK); } else { NativeMethods.TryAddShieldToButton(btnOK); } })); container.Add( Observable.FromEventPattern <EventArgs>(btnView, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { var info = (CertificateInfo)cbCertificates.SelectedItem; DialogHelper.DisplayCertificate(info.Certificate, this.Handle); })); container.Add( Observable.FromEventPattern <EventArgs>(btnChoose, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { var dialog = new SelectPoolDialog(txtPool.Text, collection.Parent); if (dialog.ShowDialog() != DialogResult.OK) { return; } txtPool.Text = dialog.Selected.Name; })); }
public NewApplicationDialog(IServiceProvider serviceProvider, Site site, string parentPath, string pool, Application existing) : base(serviceProvider) { InitializeComponent(); txtSite.Text = site.Name; txtPath.Text = parentPath; btnBrowse.Visible = site.Server.IsLocalhost; btnSelect.Enabled = site.Server.Mode != WorkingMode.Jexus; _site = site; _parentPath = parentPath; Application = existing; Text = Application == null ? "Add Application" : "Edit Application"; txtAlias.ReadOnly = Application != null; if (Application == null) { // TODO: test if IIS does this txtPool.Text = pool; } else { txtAlias.Text = Application.Name ?? Application.Path.PathToName(); txtPool.Text = Application.ApplicationPoolName; foreach (VirtualDirectory directory in Application.VirtualDirectories) { if (directory.Path == Application.Path) { txtPhysicalPath.Text = directory.PhysicalPath; } } } var container = new CompositeDisposable(); FormClosed += (sender, args) => container.Dispose(); container.Add( Observable.FromEventPattern <EventArgs>(btnBrowse, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { DialogHelper.ShowBrowseDialog(txtPhysicalPath); })); container.Add( Observable.FromEventPattern <EventArgs>(txtAlias, "TextChanged") .Merge(Observable.FromEventPattern <EventArgs>(txtPhysicalPath, "TextChanged")) .Sample(TimeSpan.FromSeconds(1)) .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { btnOK.Enabled = !string.IsNullOrWhiteSpace(txtAlias.Text) && !string.IsNullOrWhiteSpace(txtPhysicalPath.Text); })); container.Add( Observable.FromEventPattern <EventArgs>(btnOK, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { foreach (var ch in ApplicationCollection.InvalidApplicationPathCharacters()) { if (txtAlias.Text.Contains(ch.ToString(CultureInfo.InvariantCulture))) { MessageBox.Show("The application path cannot contain the following characters: \\, ?, ;, :, @, &, =, +, $, ,, |, \", <, >, *.", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } foreach (var ch in SiteCollection.InvalidSiteNameCharactersJexus()) { if (txtAlias.Text.Contains(ch.ToString(CultureInfo.InvariantCulture))) { MessageBox.Show("The site name cannot contain the following characters: ' '.", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } if (!_site.Server.Verify(txtPhysicalPath.Text)) { MessageBox.Show("The specified directory does not exist on the server.", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (Application == null) { Application = new Application(_site.Applications) { Name = txtAlias.Text, ApplicationPoolName = txtPool.Text }; Application.Path = string.Format("{0}/{1}", _parentPath.TrimEnd('/'), Application.Name); Application.Load(Application.Path, txtPhysicalPath.Text); Application.Parent.Add(Application); } else { foreach (VirtualDirectory directory in Application.VirtualDirectories) { if (directory.Path == Application.Path) { directory.PhysicalPath = txtPhysicalPath.Text; } } } DialogResult = DialogResult.OK; })); container.Add( Observable.FromEventPattern <EventArgs>(btnSelect, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { var dialog = new SelectPoolDialog(txtPool.Text, _site.Server); if (dialog.ShowDialog() != DialogResult.OK) { return; } txtPool.Text = dialog.Selected.Name; if (Application != null) { Application.ApplicationPoolName = dialog.Selected.Name; } })); }
public EditSiteDialog(IServiceProvider serviceProvider, Application application) : base(serviceProvider) { InitializeComponent(); _application = application; txtPool.Text = application.ApplicationPoolName; txtAlias.Text = application.Site.Name; txtPhysicalPath.Text = application.PhysicalPath; btnBrowse.Visible = application.Server.IsLocalhost; btnSelect.Enabled = application.Server.Mode != WorkingMode.Jexus; var container = new CompositeDisposable(); FormClosed += (sender, args) => container.Dispose(); container.Add( Observable.FromEventPattern <EventArgs>(btnOK, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { if (!_application.Server.Verify(txtPhysicalPath.Text)) { MessageBox.Show("The specified directory does not exist on the server.", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } _application.PhysicalPath = txtPhysicalPath.Text; _application.ApplicationPoolName = txtPool.Text; _application.Server.CommitChanges(); DialogResult = DialogResult.OK; })); container.Add( Observable.FromEventPattern <EventArgs>(txtPhysicalPath, "TextChanged") .Merge(Observable.FromEventPattern <EventArgs>(txtPool, "TextChanged")) .Sample(TimeSpan.FromSeconds(1)) .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { btnOK.Enabled = !string.IsNullOrWhiteSpace(txtPhysicalPath.Text); })); container.Add( Observable.FromEventPattern <EventArgs>(btnBrowse, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { DialogHelper.ShowBrowseDialog(txtPhysicalPath); })); container.Add( Observable.FromEventPattern <EventArgs>(btnSelect, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { var dialog = new SelectPoolDialog(txtPool.Text, _application.Server); if (dialog.ShowDialog() != DialogResult.OK) { return; } txtPool.Text = dialog.Selected.Name; })); }
public NewApplicationDialog(IServiceProvider serviceProvider, Site site, string parentPath, string pool, Application existing) : base(serviceProvider) { InitializeComponent(); txtSite.Text = site.Name; txtPath.Text = parentPath; btnBrowse.Visible = site.Server.IsLocalhost; btnSelect.Enabled = site.Server.Mode != WorkingMode.Jexus; _site = site; _parentPath = parentPath; Application = existing; Text = Application == null ? "Add Application" : "Edit Application"; txtAlias.ReadOnly = Application != null; if (Application == null) { // TODO: test if IIS does this txtPool.Text = pool; } else { txtAlias.Text = Application.Name ?? Application.Path.PathToName(); txtPool.Text = Application.ApplicationPoolName; foreach (VirtualDirectory directory in Application.VirtualDirectories) { if (directory.Path == Application.Path) { txtPhysicalPath.Text = directory.PhysicalPath; } } RefreshButton(); } var item = new ConnectAsItem(Application?.VirtualDirectories[0]); var container = new CompositeDisposable(); FormClosed += (sender, args) => container.Dispose(); container.Add( Observable.FromEventPattern <EventArgs>(btnBrowse, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { DialogHelper.ShowBrowseDialog(txtPhysicalPath, null); })); container.Add( Observable.FromEventPattern <EventArgs>(txtAlias, "TextChanged") .Merge(Observable.FromEventPattern <EventArgs>(txtPhysicalPath, "TextChanged")) .Sample(TimeSpan.FromSeconds(1)) .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { RefreshButton(); })); container.Add( Observable.FromEventPattern <EventArgs>(btnOK, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { foreach (var ch in ApplicationCollection.InvalidApplicationPathCharacters()) { if (txtAlias.Text.Contains(ch.ToString(CultureInfo.InvariantCulture))) { MessageBox.Show("The application path cannot contain the following characters: \\, ?, ;, :, @, &, =, +, $, ,, |, \", <, >, *.", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } foreach (var ch in SiteCollection.InvalidSiteNameCharactersJexus()) { if (txtAlias.Text.Contains(ch.ToString(CultureInfo.InvariantCulture))) { MessageBox.Show("The site name cannot contain the following characters: ' '.", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } if (!_site.Server.Verify(txtPhysicalPath.Text, site.Applications[0].GetActualExecutable())) { MessageBox.Show("The specified directory does not exist on the server.", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (Application == null) { string path = string.Format("{0}/{1}", _parentPath.TrimEnd('/'), txtAlias.Text); foreach (VirtualDirectory virtualDirectory in _site.Applications[0].VirtualDirectories) { if (string.Equals(virtualDirectory.Path, path, StringComparison.OrdinalIgnoreCase)) { ShowMessage("This virtual directory already exists.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } } foreach (Application application in _site.Applications) { if (string.Equals(path, application.Path)) { ShowMessage("An application with this virtual path already exists.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } } Application = _site.Applications.Add(path, txtPhysicalPath.Text); Application.Name = txtAlias.Text; Application.ApplicationPoolName = txtPool.Text; item.Element = Application.VirtualDirectories[0]; item.Apply(); } else { foreach (VirtualDirectory directory in Application.VirtualDirectories) { if (directory.Path == Application.Path) { directory.PhysicalPath = txtPhysicalPath.Text; } } } DialogResult = DialogResult.OK; })); container.Add( Observable.FromEventPattern <EventArgs>(btnSelect, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { var dialog = new SelectPoolDialog(txtPool.Text, _site.Server); if (dialog.ShowDialog() != DialogResult.OK) { return; } txtPool.Text = dialog.Selected.Name; if (Application != null) { Application.ApplicationPoolName = dialog.Selected.Name; } })); container.Add( Observable.FromEventPattern <EventArgs>(btnConnect, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { var dialog = new ConnectAsDialog(ServiceProvider, item); if (dialog.ShowDialog() != DialogResult.OK) { return; } item.Apply(); txtConnectAs.Text = string.IsNullOrEmpty(item.UserName) ? "Pass-through authentication" : $"connect as '{item.UserName}'"; RefreshButton(); })); txtConnectAs.Text = string.IsNullOrEmpty(item.UserName) ? "Pass-through authentication" : $"connect as '{item.UserName}'"; }
public EditSiteDialog(IServiceProvider serviceProvider, Application application) : base(serviceProvider) { InitializeComponent(); _application = application; txtPool.Text = application.ApplicationPoolName; txtAlias.Text = application.Site.Name; txtPhysicalPath.Text = application.PhysicalPath; btnBrowse.Visible = application.Server.IsLocalhost; btnSelect.Enabled = application.Server.Mode != WorkingMode.Jexus; RefreshButton(); var container = new CompositeDisposable(); FormClosed += (sender, args) => container.Dispose(); container.Add( Observable.FromEventPattern <EventArgs>(btnOK, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { if (!_application.Server.Verify(txtPhysicalPath.Text, _application.GetActualExecutable())) { MessageBox.Show("The specified directory does not exist on the server.", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } _application.PhysicalPath = txtPhysicalPath.Text; _application.ApplicationPoolName = txtPool.Text; _application.Server.CommitChanges(); DialogResult = DialogResult.OK; })); container.Add( Observable.FromEventPattern <EventArgs>(txtPhysicalPath, "TextChanged") .Merge(Observable.FromEventPattern <EventArgs>(txtPool, "TextChanged")) .Sample(TimeSpan.FromSeconds(1)) .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { RefreshButton(); })); container.Add( Observable.FromEventPattern <EventArgs>(btnBrowse, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { DialogHelper.ShowBrowseDialog(txtPhysicalPath, _application.GetActualExecutable()); })); container.Add( Observable.FromEventPattern <EventArgs>(btnSelect, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { using var dialog = new SelectPoolDialog(txtPool.Text, _application.Server); if (dialog.ShowDialog() != DialogResult.OK) { return; } txtPool.Text = dialog.Selected.Name; })); container.Add( Observable.FromEventPattern <EventArgs>(btnConnect, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { var item = new ConnectAsItem(_application.VirtualDirectories[0]); using (var dialog = new ConnectAsDialog(ServiceProvider, item)) { if (dialog.ShowDialog() != DialogResult.OK) { return; } } item.Apply(); txtConnectAs.Text = string.IsNullOrEmpty(application.VirtualDirectories[0].UserName) ? "Pass-through authentication" : $"connect as '{application.VirtualDirectories[0].UserName}'"; RefreshButton(); })); txtConnectAs.Text = string.IsNullOrEmpty(application.VirtualDirectories[0].UserName) ? "Pass-through authentication" : $"connect as '{application.VirtualDirectories[0].UserName}'"; }