Exemplo n.º 1
0
        public static string GetServerAlias()
        {
            List <string> serverAliases = new List <string>();

            // Get the Site name
            string siteName = System.Web.Hosting.HostingEnvironment.SiteName;

            // Get the sites section from the AppPool.config
            Microsoft.Web.Administration.ConfigurationSection sitesSection =
                Microsoft.Web.Administration.WebConfigurationManager.GetSection(null, null, "system.applicationHost/sites");

            foreach (Microsoft.Web.Administration.ConfigurationElement site in sitesSection.GetCollection())
            {
                // Find the right Site
                if (String.Equals((string)site["name"], siteName, StringComparison.OrdinalIgnoreCase))
                {
                    // For each binding see if they are http based and return the port and protocol
                    foreach (Microsoft.Web.Administration.ConfigurationElement binding in site.GetCollection("bindings"))
                    {
                        string protocol    = (string)binding["protocol"];
                        string bindingInfo = (string)binding["bindingInformation"];

                        if (protocol.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                        {
                            string[] parts = bindingInfo.Split(':');
                            if (parts.Length == 3)
                            {
                                serverAliases.AddRange(parts[2].Split(','));
                            }
                        }
                    }
                }
            }
            return(string.Join(",", serverAliases));
        }
Exemplo n.º 2
0
        public static IEnumerable <KeyValuePair <string, Uri> > GetBindings(HttpContext context)
        {
            // Get the Site name
            string siteName = System.Web.Hosting.HostingEnvironment.SiteName;

            // Get the sites section from the AppPool.config
            Microsoft.Web.Administration.ConfigurationSection sitesSection =
                Microsoft.Web.Administration.WebConfigurationManager.GetSection(null, null, "system.applicationHost/sites");

            foreach (Microsoft.Web.Administration.ConfigurationElement site in sitesSection.GetCollection())
            {
                // Find the right Site
                if (String.Equals((string)site["name"], siteName, StringComparison.OrdinalIgnoreCase))
                {
                    // For each binding see if they are http based and return the port and protocol
                    foreach (Microsoft.Web.Administration.ConfigurationElement binding in site.GetCollection("bindings"))
                    {
                        string protocol    = (string)binding["protocol"];
                        string bindingInfo = (string)binding["bindingInformation"];

                        if (protocol.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                        {
                            string[] parts = bindingInfo.Split(':');
                            if (parts.Length == 3)
                            {
                                string port = parts[1];
                                string host = parts[0];
                                if (host == "*")
                                {
                                    host = "localhost";
                                }
                                if (parts[2] != string.Empty)
                                {
                                    host = parts[2];
                                }
                                KeyValuePair <string, Uri> reply;
                                try { reply = new KeyValuePair <string, Uri>(protocol, new Uri(protocol + "://" + host + ":" + port + "/")); }
                                catch (Exception ex) { throw new ApplicationException("Cannot create uri from " + protocol + "://" + host + ":" + port + "/"); }
                                yield return(reply);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);

            string targetDir  = Context.Parameters[Arguments.TargetDir].TrimEnd('\\');
            string configFile = Path.Combine(targetDir, Assembly.GetExecutingAssembly().Location + ".config");

            System.Configuration.ConfigurationFileMap fileMap = new ConfigurationFileMap(configFile);
            System.Configuration.Configuration        config  = System.Configuration.ConfigurationManager.OpenMappedMachineConfiguration(fileMap);

            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(delegate(object sender, ResolveEventArgs args)
            {
                return(Assembly.LoadFile(Path.Combine(targetDir, args.Name + ".dll")));
            });

            UhuruSection section = (UhuruSection)config.GetSection("uhuru");

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.BaseDir]))
            {
                section.DEA.BaseDir = Context.Parameters[Arguments.BaseDir];
            }

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.EnforceUlimit]))
            {
                section.DEA.EnforceUsageLimit = Convert.ToBoolean(Context.Parameters[Arguments.EnforceUlimit], CultureInfo.InvariantCulture);
            }

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.FilerPort]))
            {
                int port = Convert.ToInt32(Context.Parameters[Arguments.FilerPort], CultureInfo.InvariantCulture);
                section.DEA.FilerPort = port;
                FirewallTools.OpenPort(port, "DEA FileServer");
            }

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.StatusPort]))
            {
                int port = Convert.ToInt32(Context.Parameters[Arguments.StatusPort], CultureInfo.InvariantCulture);
                section.DEA.StatusPort = port;
                FirewallTools.OpenPort(port, "DEA Status");
            }

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.HeartBeatInterval]))
            {
                section.DEA.HeartbeatIntervalMs = Convert.ToInt32(Context.Parameters[Arguments.HeartBeatInterval], CultureInfo.InvariantCulture);
            }

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.LocalRoute]))
            {
                section.DEA.LocalRoute = Context.Parameters[Arguments.LocalRoute];
            }
            else
            {
                string ip = string.Empty;
                foreach (IPAddress address in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
                {
                    if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        ip = address.ToString();
                        break;
                    }
                }

                section.DEA.LocalRoute = ip;
            }

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.MaxMemory]))
            {
                section.DEA.MaxMemoryMB = Convert.ToInt32(Context.Parameters[Arguments.MaxMemory], CultureInfo.InvariantCulture);
            }

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.MessageBus]))
            {
                section.DEA.MessageBus = Context.Parameters[Arguments.MessageBus];
            }

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.MultiTenant]))
            {
                section.DEA.Multitenant = Convert.ToBoolean(Context.Parameters[Arguments.MultiTenant], CultureInfo.InvariantCulture);
            }

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.Secure]))
            {
                section.DEA.Secure = Convert.ToBoolean(Context.Parameters[Arguments.Secure], CultureInfo.InvariantCulture);
            }

            section.Service = null;
            config.Save();

            using (Microsoft.Web.Administration.ServerManager serverManager = new Microsoft.Web.Administration.ServerManager())
            {
                Microsoft.Web.Administration.Configuration authenticationConfig = serverManager.GetApplicationHostConfiguration();

                Microsoft.Web.Administration.ConfigurationSection anonymousAuthenticationSection = authenticationConfig.GetSection("system.webServer/security/authentication/anonymousAuthentication");
                anonymousAuthenticationSection["enabled"]     = true;
                anonymousAuthenticationSection["userName"]    = string.Empty;
                anonymousAuthenticationSection["password"]    = string.Empty;
                anonymousAuthenticationSection["logonMethod"] = @"ClearText";

                serverManager.CommitChanges();
            }

            Registry.LocalMachine.CreateSubKey(@"System\CurrentControlSet\Services\Inetinfo\Parameters").SetValue("DoDirMonitoringForUNC", 1, RegistryValueKind.DWord);
        }