/// <summary> /// Harvest a web directory. /// </summary> /// <param name="webDirectoryEntry">The web directory directory entry.</param> /// <param name="webSite">The parent web site.</param> private void HarvestWebDirectory(DirectoryEntry webDirectoryEntry, IIs.WebSite webSite) { foreach (DirectoryEntry childEntry in webDirectoryEntry.Children) { switch (childEntry.SchemaClassName) { case "IIsWebDirectory": this.HarvestWebDirectory(childEntry, webSite); break; case "IIsWebVirtualDir": this.HarvestWebVirtualDir(childEntry, webSite); break; } } IIs.WebDirProperties webDirProperties = this.HarvestWebDirProperties(webDirectoryEntry); if (null != webDirProperties) { IIs.WebDir webDir = new IIs.WebDir(); int indexOfRoot = webDirectoryEntry.Path.IndexOf("Root/"); webDir.Path = webDirectoryEntry.Path.Substring(indexOfRoot + 5); webDir.AddChild(webDirProperties); webSite.AddChild(webDir); } }
/// <summary> /// Harvest a web virtual directory. /// </summary> /// <param name="webVirtualDirEntry">The web virtual directory directory entry.</param> /// <param name="webSite">The parent web site.</param> private void HarvestWebVirtualDir(DirectoryEntry webVirtualDirEntry, IIs.WebSite webSite) { IIs.WebVirtualDir webVirtualDir = new IIs.WebVirtualDir(); foreach (string propertyName in webVirtualDirEntry.Properties.PropertyNames) { PropertyValueCollection property = webVirtualDirEntry.Properties[propertyName]; PropertyValueCollection parentProperty = webVirtualDirEntry.Parent.Properties[propertyName]; if (null == parentProperty.Value || parentProperty.Value.ToString() != property.Value.ToString()) { switch (propertyName) { case "Path": webVirtualDir.Directory = (string)property.Value; break; } } } int indexOfRoot = webVirtualDirEntry.Path.IndexOf("ROOT/", StringComparison.OrdinalIgnoreCase); webVirtualDir.Alias = webVirtualDirEntry.Path.Substring(indexOfRoot + 5); IIs.WebDirProperties webDirProps = this.HarvestWebDirProperties(webVirtualDirEntry); if (webDirProps != null) { webVirtualDir.AddChild(webDirProps); } foreach (DirectoryEntry childEntry in webVirtualDirEntry.Children) { switch (childEntry.SchemaClassName) { case "IIsWebDirectory": this.HarvestWebDirectory(childEntry, webSite); break; case "IIsWebVirtualDir": this.HarvestWebVirtualDir(childEntry, webSite); break; } } webSite.AddChild(webVirtualDir); }
/// <summary> /// Decompile the IIsWebDirProperties table. /// </summary> /// <param name="table">The table to decompile.</param> private void DecompileIIsWebDirPropertiesTable(Table table) { foreach (Row row in table.Rows) { IIs.WebDirProperties webDirProperties = new IIs.WebDirProperties(); webDirProperties.Id = (string)row[0]; if (null != row[1]) { int access = (int)row[1]; if (0x1 == (access & 0x1)) { webDirProperties.Read = IIs.YesNoType.yes; } if (0x2 == (access & 0x2)) { webDirProperties.Write = IIs.YesNoType.yes; } if (0x4 == (access & 0x4)) { webDirProperties.Execute = IIs.YesNoType.yes; } if (0x200 == (access & 0x200)) { webDirProperties.Script = IIs.YesNoType.yes; } } if (null != row[2]) { int authorization = (int)row[2]; if (0x1 == (authorization & 0x1)) { webDirProperties.AnonymousAccess = IIs.YesNoType.yes; } else // set one of the properties to 'no' to force the output value to be '0' if not other attributes are set { webDirProperties.AnonymousAccess = IIs.YesNoType.no; } if (0x2 == (authorization & 0x2)) { webDirProperties.BasicAuthentication = IIs.YesNoType.yes; } if (0x4 == (authorization & 0x4)) { webDirProperties.WindowsAuthentication = IIs.YesNoType.yes; } if (0x10 == (authorization & 0x10)) { webDirProperties.DigestAuthentication = IIs.YesNoType.yes; } if (0x40 == (authorization & 0x40)) { webDirProperties.PassportAuthentication = IIs.YesNoType.yes; } } if (null != row[3]) { webDirProperties.AnonymousUser = (string)row[3]; } if (null != row[4] && 1 == (int)row[4]) { webDirProperties.IIsControlledPassword = IIs.YesNoType.yes; } if (null != row[5]) { switch ((int)row[5]) { case 0: webDirProperties.LogVisits = IIs.YesNoType.no; break; case 1: webDirProperties.LogVisits = IIs.YesNoType.yes; break; default: // TODO: warn break; } } if (null != row[6]) { switch ((int)row[6]) { case 0: webDirProperties.Index = IIs.YesNoType.no; break; case 1: webDirProperties.Index = IIs.YesNoType.yes; break; default: // TODO: warn break; } } if (null != row[7]) { webDirProperties.DefaultDocuments = (string)row[7]; } if (null != row[8]) { switch ((int)row[8]) { case 0: webDirProperties.AspDetailedError = IIs.YesNoType.no; break; case 1: webDirProperties.AspDetailedError = IIs.YesNoType.yes; break; default: // TODO: warn break; } } if (null != row[9]) { webDirProperties.HttpExpires = (string)row[9]; } if (null != row[10]) { // force the value to be a positive number webDirProperties.CacheControlMaxAge = unchecked((uint)(int)row[10]); } if (null != row[11]) { webDirProperties.CacheControlCustom = (string)row[11]; } if (null != row[12]) { switch ((int)row[8]) { case 0: webDirProperties.ClearCustomError = IIs.YesNoType.no; break; case 1: webDirProperties.ClearCustomError = IIs.YesNoType.yes; break; default: // TODO: warn break; } } if (null != row[13]) { int accessSSLFlags = (int)row[13]; if (0x8 == (accessSSLFlags & 0x8)) { webDirProperties.AccessSSL = IIs.YesNoType.yes; } if (0x20 == (accessSSLFlags & 0x20)) { webDirProperties.AccessSSLNegotiateCert = IIs.YesNoType.yes; } if (0x40 == (accessSSLFlags & 0x40)) { webDirProperties.AccessSSLRequireCert = IIs.YesNoType.yes; } if (0x80 == (accessSSLFlags & 0x80)) { webDirProperties.AccessSSLMapCert = IIs.YesNoType.yes; } if (0x100 == (accessSSLFlags & 0x100)) { webDirProperties.AccessSSL128 = IIs.YesNoType.yes; } } if (null != row[14]) { webDirProperties.AuthenticationProviders = (string)row[14]; } this.Core.RootElement.AddChild(webDirProperties); } }
/// <summary> /// Harvest a web directory's properties. /// </summary> /// <param name="directoryEntry">The web directory directory entry.</param> /// <returns>The harvested web directory's properties.</returns> private IIs.WebDirProperties HarvestWebDirProperties(DirectoryEntry directoryEntry) { bool foundProperties = false; IIs.WebDirProperties webDirProperties = new IIs.WebDirProperties(); foreach (string propertyName in directoryEntry.Properties.PropertyNames) { PropertyValueCollection property = directoryEntry.Properties[propertyName]; PropertyValueCollection parentProperty = directoryEntry.Parent.Properties[propertyName]; if (null == parentProperty.Value || parentProperty.Value.ToString() != property.Value.ToString()) { switch (propertyName) { case "AccessFlags": int access = (int)property.Value; if (0x1 == (access & 0x1)) { webDirProperties.Read = IIs.YesNoType.yes; } if (0x2 == (access & 0x2)) { webDirProperties.Write = IIs.YesNoType.yes; } if (0x4 == (access & 0x4)) { webDirProperties.Execute = IIs.YesNoType.yes; } if (0x200 == (access & 0x200)) { webDirProperties.Script = IIs.YesNoType.yes; } foundProperties = true; break; case "AuthFlags": int authorization = (int)property.Value; if (0x1 == (authorization & 0x1)) { webDirProperties.AnonymousAccess = IIs.YesNoType.yes; } if (0x2 == (authorization & 0x2)) { webDirProperties.BasicAuthentication = IIs.YesNoType.yes; } if (0x4 == (authorization & 0x4)) { webDirProperties.WindowsAuthentication = IIs.YesNoType.yes; } if (0x10 == (authorization & 0x10)) { webDirProperties.DigestAuthentication = IIs.YesNoType.yes; } if (0x40 == (authorization & 0x40)) { webDirProperties.PassportAuthentication = IIs.YesNoType.yes; } foundProperties = true; break; } } } return(foundProperties ? webDirProperties : null); }
/// <summary> /// Harvest a web directory's properties. /// </summary> /// <param name="directoryEntry">The web directory directory entry.</param> /// <returns>The harvested web directory's properties.</returns> private IIs.WebDirProperties HarvestWebDirProperties(DirectoryEntry directoryEntry) { bool foundProperties = false; IIs.WebDirProperties webDirProperties = new IIs.WebDirProperties(); // Cannot read properties for "iisadmin" site. if (String.Equals("iisadmin", directoryEntry.Name, StringComparison.OrdinalIgnoreCase) && String.Equals("ROOT", directoryEntry.Parent.Name, StringComparison.OrdinalIgnoreCase)) { return null; } foreach (string propertyName in directoryEntry.Properties.PropertyNames) { PropertyValueCollection property = directoryEntry.Properties[propertyName]; PropertyValueCollection parentProperty = directoryEntry.Parent.Properties[propertyName]; if (null == parentProperty.Value || parentProperty.Value.ToString() != property.Value.ToString()) { switch (propertyName) { case "AccessFlags": int access = (int)property.Value; if (0x1 == (access & 0x1)) { webDirProperties.Read = IIs.YesNoType.yes; } if (0x2 == (access & 0x2)) { webDirProperties.Write = IIs.YesNoType.yes; } if (0x4 == (access & 0x4)) { webDirProperties.Execute = IIs.YesNoType.yes; } if (0x200 == (access & 0x200)) { webDirProperties.Script = IIs.YesNoType.yes; } foundProperties = true; break; case "AuthFlags": int authorization = (int)property.Value; if (0x1 == (authorization & 0x1)) { webDirProperties.AnonymousAccess = IIs.YesNoType.yes; } if (0x2 == (authorization & 0x2)) { webDirProperties.BasicAuthentication = IIs.YesNoType.yes; } if (0x4 == (authorization & 0x4)) { webDirProperties.WindowsAuthentication = IIs.YesNoType.yes; } if (0x10 == (authorization & 0x10)) { webDirProperties.DigestAuthentication = IIs.YesNoType.yes; } if (0x40 == (authorization & 0x40)) { webDirProperties.PassportAuthentication = IIs.YesNoType.yes; } foundProperties = true; break; } } } return foundProperties ? webDirProperties : null; }
/// <summary> /// Harvest a web site. /// </summary> /// <param name="webSiteEntry">The web site directory entry.</param> /// <returns>The harvested web site.</returns> private IIs.WebSite HarvestWebSite(DirectoryEntry webSiteEntry) { IIs.WebSite webSite = new IIs.WebSite(); foreach (string propertyName in webSiteEntry.Properties.PropertyNames) { PropertyValueCollection property = webSiteEntry.Properties[propertyName]; PropertyValueCollection parentProperty = webSiteEntry.Parent.Properties[propertyName]; if (null == parentProperty.Value || parentProperty.Value.ToString() != property.Value.ToString()) { switch (propertyName) { case "SecureBindings": IIs.WebAddress secureWebAddress = this.HarvestBindings(propertyName, property); if (null != secureWebAddress) { webSite.AddChild(secureWebAddress); } break; case "ServerBindings": IIs.WebAddress webAddress = this.HarvestBindings(propertyName, property); if (null != webAddress) { webSite.AddChild(webAddress); } break; case "ServerComment": webSite.Description = (string)property.Value; break; } } } foreach (DirectoryEntry childEntry in webSiteEntry.Children) { switch (childEntry.SchemaClassName) { case "IIsFilters": string loadOrder = (string)childEntry.Properties["FilterLoadOrder"].Value; if (loadOrder.Length > 0) { string[] filterNames = loadOrder.Split(",".ToCharArray()); for (int i = 0; i < filterNames.Length; i++) { using (DirectoryEntry webFilterEntry = new DirectoryEntry(String.Concat(childEntry.Path, '/', filterNames[i]))) { IIs.WebFilter webFilter = this.HarvestWebFilter(webFilterEntry); webFilter.LoadOrder = (i + 1).ToString(CultureInfo.InvariantCulture); webSite.AddChild(webFilter); } } } break; case "IIsWebDirectory": this.HarvestWebDirectory(childEntry, webSite); break; case "IIsWebVirtualDir": foreach (string propertyName in childEntry.Properties.PropertyNames) { PropertyValueCollection property = childEntry.Properties[propertyName]; switch (propertyName) { case "Path": webSite.Directory = (string)property.Value; break; } } IIs.WebDirProperties webDirProps = this.HarvestWebDirProperties(childEntry); if (null != webDirProps) { webSite.AddChild(webDirProps); } foreach (DirectoryEntry child2Entry in childEntry.Children) { switch (child2Entry.SchemaClassName) { case "IIsWebDirectory": this.HarvestWebDirectory(child2Entry, webSite); break; case "IIsWebVirtualDir": this.HarvestWebVirtualDir(child2Entry, webSite); break; } } break; } } return(webSite); }