void AclPopulateHosts(HttpConfigUrlAclEntry entry) { this.aclHostname.Items.Clear(); this.aclHostname.Items.Add("+"); this.aclHostname.SelectedIndex = 0; this.aclHostname.Items.Add("*"); this.aclHostname.Items.Add("localhost"); string computer = Environment.GetEnvironmentVariable("COMPUTERNAME"); if (!string.IsNullOrEmpty(computer)) { computer = computer.ToLowerInvariant(); this.aclHostname.Items.Add(computer); string domain = Environment.GetEnvironmentVariable("USERDNSDOMAIN"); if (!string.IsNullOrEmpty(domain)) { domain = domain.ToLowerInvariant(); this.aclHostname.Items.Add(computer + "." + domain); } } if (entry != null) { if (!this.aclHostname.Items.Contains(entry.Host)) { this.aclHostname.Items.Add(entry.Host); } this.aclHostname.SelectedItem = entry.Host; } }
HttpConfigUrlAclEntry AclFindCurrentEntry() { if (this.aclTab.SelectedTab == this.aclListTab) { return(this.aclList.SelectedItem as HttpConfigUrlAclEntry); } TreeNode node = this.aclTree.SelectedNode; if (node == null) { return(null); } for (;;) // walk up { HttpConfigUrlAclEntry entry = node.Tag as HttpConfigUrlAclEntry; if (entry != null) { return(entry); } node = node.Parent; if (node == null) { break; } } node = this.aclTree.SelectedNode; for (;;) // walk down { if (node.Nodes.Count != 1) { break; } node = node.FirstNode; HttpConfigUrlAclEntry entry = node.Tag as HttpConfigUrlAclEntry; if (entry != null) { return(entry); } } return(null); }
private void aclDelete_Click(object sender, EventArgs e) { HttpConfigUrlAclEntry entry = AclFindCurrentEntry(); if (entry != null) { DialogResult result = MessageBox.Show("Are you sure you want to delete the following UrlAcl?\r\n\r\n" + entry.UriPrefix, "Confirm Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { try { entry.Delete(); } catch (Win32Exception exception) { MessageBox.Show("An error occurred while attempting to delete, the error message was:\r\n\r\n" + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } Reload(); }
void AclPopulate() { HttpConfigUrlAclEntry entry = AclFindCurrentEntry(); if (entry != null) { this.aclEdit.Enabled = true; this.aclSsl.Checked = entry.Uri.Scheme == Uri.UriSchemeHttps; AclPopulateHosts(entry); this.aclPort.Text = entry.Uri.Port.ToString(); this.aclPath.Text = entry.Uri.AbsolutePath; this.aclAccounts.Items.Clear(); foreach (NTAccount account in entry.Accounts) { this.aclAccounts.Items.Add(account.Value); } } else { this.aclEdit.Enabled = false; AclClear(); } }
private void aclEdit_Click(object sender, EventArgs e) { aclEditedEntry = AclFindCurrentEntry(); AclSetEditing(true); }
private void aclCancel_Click(object sender, EventArgs e) { aclEditedEntry = null; AclPopulate(); AclSetEditing(false); }
private void aclApply_Click(object sender, EventArgs e) { string urlPrefix = (this.aclSsl.Checked ? Uri.UriSchemeHttps : Uri.UriSchemeHttp) + "://" + this.aclHostname.Text; ushort port; if (!string.IsNullOrEmpty(this.aclPort.Text)) { port = ushort.Parse(this.aclPort.Text); } else { port = this.aclSsl.Checked ? (ushort)443 : (ushort)80; } urlPrefix += ":" + port.ToString(); string path = this.aclPath.Text; if (string.IsNullOrEmpty(path) || path[0] != '/') { path = '/' + path; } if (path[path.Length - 1] != '/') { path += '/'; } urlPrefix += path; string sddl = "D:"; foreach (string account in this.aclAccounts.Items) { SecurityIdentifier sid = new NTAccount(account).Translate(typeof(SecurityIdentifier)) as SecurityIdentifier; sddl += "(A;;GX;;;" + sid.Value + ")"; } bool deleted = false; if (aclEditedEntry != null) { try { aclEditedEntry.Delete(); deleted = true; } catch (Win32Exception exception) { DialogResult result = MessageBox.Show("An error occurred while attempting to perform the requested change. The error message was:\r\n\r\n" + exception.Message, "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); if (result == DialogResult.Abort) { Reload(); } if (result != DialogResult.Ignore) { return; } } } HttpConfigUrlAclEntry entry = new HttpConfigUrlAclEntry(urlPrefix, sddl); try { entry.Create(); } catch (Win32Exception exception) { DialogResult result = MessageBox.Show("An error occurred while attempting to perform the requested change. The error message was:\r\n\r\n" + exception.Message, "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); if (result == DialogResult.Abort) { Reload(); } if (result != DialogResult.Ignore) { return; } if (deleted && aclEditedEntry != null) { try { aclEditedEntry.Create(); } catch (Win32Exception) { } } } aclEditedEntry = null; Reload(); }