GetApplicationHostConfiguration() public method

public GetApplicationHostConfiguration ( ) : Configuration
return Configuration
Esempio n. 1
0
        public static void Install(UdpInstallerOptions options)
        {
            if (options.ListenerAdapterChecked)
            {
                WebAdmin.ServerManager sm = new WebAdmin.ServerManager();
                WebAdmin.Configuration wasConfiguration = sm.GetApplicationHostConfiguration();
                WebAdmin.ConfigurationSection section = wasConfiguration.GetSection(ListenerAdapterPath);
                WebAdmin.ConfigurationElementCollection listenerAdaptersCollection = section.GetCollection();
                WebAdmin.ConfigurationElement element = listenerAdaptersCollection.CreateElement();
                element.GetAttribute("name").Value = UdpConstants.Scheme;
                element.GetAttribute("identity").Value = WindowsIdentity.GetCurrent().User.Value;
                listenerAdaptersCollection.Add(element);
                sm.CommitChanges();
                wasConfiguration = null;
                sm = null;
            }

            if (options.ProtocolHandlerChecked)
            {
                Configuration rootWebConfig = GetRootWebConfiguration();
                ProtocolsSection section = (ProtocolsSection)rootWebConfig.GetSection(ProtocolsPath);
                ProtocolElement element = new ProtocolElement(UdpConstants.Scheme);
                
                element.ProcessHandlerType = typeof(UdpProcessProtocolHandler).AssemblyQualifiedName;
                element.AppDomainHandlerType = typeof(UdpAppDomainProtocolHandler).AssemblyQualifiedName;
                element.Validate = false;

                section.Protocols.Add(element);
                rootWebConfig.Save();
            }
        }
Esempio n. 2
0
        public static void Install(UdpInstallerOptions options)
        {
            if (options.ListenerAdapterChecked)
            {
                WebAdmin.ServerManager                  sm = new WebAdmin.ServerManager();
                WebAdmin.Configuration                  wasConfiguration           = sm.GetApplicationHostConfiguration();
                WebAdmin.ConfigurationSection           section                    = wasConfiguration.GetSection(ListenerAdapterPath);
                WebAdmin.ConfigurationElementCollection listenerAdaptersCollection = section.GetCollection();
                WebAdmin.ConfigurationElement           element                    = listenerAdaptersCollection.CreateElement();
                element.GetAttribute("name").Value     = UdpConstants.Scheme;
                element.GetAttribute("identity").Value = WindowsIdentity.GetCurrent().User.Value;
                listenerAdaptersCollection.Add(element);
                sm.CommitChanges();
                wasConfiguration = null;
                sm = null;
            }

            if (options.ProtocolHandlerChecked)
            {
                Configuration    rootWebConfig = GetRootWebConfiguration();
                ProtocolsSection section       = (ProtocolsSection)rootWebConfig.GetSection(ProtocolsPath);
                ProtocolElement  element       = new ProtocolElement(UdpConstants.Scheme);

                element.ProcessHandlerType   = typeof(UdpProcessProtocolHandler).AssemblyQualifiedName;
                element.AppDomainHandlerType = typeof(UdpAppDomainProtocolHandler).AssemblyQualifiedName;
                element.Validate             = false;

                section.Protocols.Add(element);
                rootWebConfig.Save();
            }
        }
Esempio n. 3
0
        public override bool OnStart()
        {
            try
            {
                Trace.Listeners.Add(new DiagnosticMonitorTraceListener());
                Trace.TraceInformation("Starting Gateway");

                // Enable IIS Reverse Proxy
                using (ServerManager server = new ServerManager())
                {
                    var proxySection = server.GetApplicationHostConfiguration().GetSection("system.webServer/proxy");
                    proxySection.SetAttributeValue("enabled", true);
                    server.CommitChanges();
                    Trace.TraceInformation("Enabled Reverse Proxy");

                    // Patch web.config rewrite rules
                    string serviceStem = RoleEnvironment.GetConfigurationSettingValue("Gateway.ServiceStem");
                    if (!String.Equals(serviceStem, "nuget.org", StringComparison.OrdinalIgnoreCase))
                    {
                        RewriteStem(server, serviceStem);
                    }
                    server.CommitChanges();
                }

                return base.OnStart();
            }
            catch (Exception ex)
            {
                Trace.TraceError("Error starting gateway: {0}", ex.ToString());
                throw;
            }
        }
        private static void CreateReWriteRule(string serverFarm)
        {
            using (var serverManager = new ServerManager())
            {
                var config = serverManager.GetApplicationHostConfiguration();
                var globalRulesSection = config.GetSection("system.webServer/rewrite/globalRules");
                var globalRulesCollection = globalRulesSection.GetCollection();

                var ruleElement = globalRulesCollection.CreateElement("rule");
                ruleElement["name"] = serverFarm;
                ruleElement["patternSyntax"] = @"Wildcard";
                ruleElement["stopProcessing"] = true;

                var matchElement = ruleElement.GetChildElement("match");
                matchElement["url"] = @"*";
                matchElement["ignoreCase"] = false;

                var actionElement = ruleElement.GetChildElement("action");
                actionElement["type"] = @"Rewrite";
                actionElement["url"] = string.Concat(@"http://", serverFarm, @"/{R:0}");
                globalRulesCollection.Add(ruleElement);

                serverManager.CommitChanges();
            }
        }
        public static void AddServers(string farmName, IPEndPoint[] endpoints)
        {
            using (var serverManager = new ServerManager())
            {
                var config = serverManager.GetApplicationHostConfiguration();
                var webFarmsSection = config.GetSection("webFarms");
                var webFarmsCollection = webFarmsSection.GetCollection();
                var webFarmElement = FindElement(webFarmsCollection, "webFarm", "name", farmName);
                if (webFarmElement == null) throw new InvalidOperationException("Element not found!");

                var webFarmCollection = webFarmElement.GetCollection();
                foreach (var endpoint in endpoints)
                {
                    var server = FindElement(webFarmCollection, "server", "address", endpoint.Address.ToString());
                    if (null != server)
                    {
                        // server already exists
                        continue;
                    }

                    var serverElement = webFarmCollection.CreateElement("server");
                    serverElement["address"] = endpoint.Address.ToString();

                    var applicationRequestRoutingElement = serverElement.GetChildElement("applicationRequestRouting");
                    applicationRequestRoutingElement["httpPort"] = endpoint.Port;
                    webFarmCollection.Add(serverElement);
                }
                serverManager.CommitChanges();
            }
        }
        public static ConfigurationElement GetOrCreateFarm(string farmName)
        {
            using (var serverManager = new ServerManager())
            {
                var config = serverManager.GetApplicationHostConfiguration();
                var webFarmsSection = config.GetSection("webFarms");
                var webFarmsCollection = webFarmsSection.GetCollection();

                var el = FindElement(webFarmsCollection, "webFarm", "name", farmName);
                if (null != el)
                {
                    return el;
                }

                var webFarmElement = webFarmsCollection.CreateElement("webFarm");
                webFarmElement["name"] = farmName;
                webFarmsCollection.Add(webFarmElement);

                var applicationRequestRoutingElement = webFarmElement.GetChildElement("applicationRequestRouting");

                var affinityElement = applicationRequestRoutingElement.GetChildElement("affinity");
                affinityElement["useCookie"] = true;

                serverManager.CommitChanges();

                CreateReWriteRule(farmName);

                return webFarmElement;
            }
        }
        public void Initialize()
        {
            if (_configurationProvider.IsEmulated())
            {
                return;
            }

            // Instantiate the IIS ServerManager
            using (var serverManager = new ServerManager())
            {
                Microsoft.Web.Administration.Configuration applicationConfig = serverManager.GetApplicationHostConfiguration();
                ConfigurationSection httpLoggingSection = applicationConfig.GetSection("system.webServer/httpLogging");

                httpLoggingSection["selectiveLogging"] = @"LogAll";
                httpLoggingSection["dontLog"] = false;

                ConfigurationSection sitesSection = applicationConfig.GetSection("system.applicationHost/sites");
                ConfigurationElement siteElement = sitesSection.GetCollection().Single();
                ConfigurationElement logFileElement = siteElement.GetChildElement("logFile");

                logFileElement["logFormat"] = "W3C";
                logFileElement["period"] = "Hourly";
                logFileElement["enabled"] = true;
                logFileElement["logExtFileFlags"] =
                    "BytesRecv,BytesSent,ClientIP,ComputerName,Cookie,Date,Host,HttpStatus,HttpSubStatus,Method,ProtocolVersion,Referer,ServerIP,ServerPort,SiteName,Time,TimeTaken,UriQuery,UriStem,UserAgent,UserName,Win32Status";

                serverManager.CommitChanges();
            }
        }
Esempio n. 8
0
        public void CreateWebDavRule(string organizationId, string folder, WebDavFolderRule rule)
        {
            using (ServerManager serverManager = new ServerManager())
            {
                Configuration config = serverManager.GetApplicationHostConfiguration();

                ConfigurationSection authoringRulesSection = config.GetSection("system.webServer/webdav/authoringRules", string.Format("{0}/{1}/{2}", _Setting.Domain, organizationId, folder));

                ConfigurationElementCollection authoringRulesCollection = authoringRulesSection.GetCollection();

                ConfigurationElement addElement = authoringRulesCollection.CreateElement("add");

                if (rule.Users.Any())
                {
                    addElement["users"] = string.Join(", ", rule.Users.Select(x => x.ToString()).ToArray());
                }

                if (rule.Roles.Any())
                {
                    addElement["roles"] = string.Join(", ", rule.Roles.Select(x => x.ToString()).ToArray());
                }

                if (rule.Pathes.Any())
                {
                    addElement["path"] = string.Join(", ", rule.Pathes.ToArray());
                }

                addElement["access"] = rule.AccessRights;
                authoringRulesCollection.Add(addElement);

                serverManager.CommitChanges();
            }
        }
Esempio n. 9
0
        public static void Uninstall(UdpInstallerOptions options)
        {
            if (options.ListenerAdapterChecked)
            {
                WebAdmin.ServerManager                  sm = new WebAdmin.ServerManager();
                WebAdmin.Configuration                  wasConfiguration           = sm.GetApplicationHostConfiguration();
                WebAdmin.ConfigurationSection           section                    = wasConfiguration.GetSection(ListenerAdapterPath);
                WebAdmin.ConfigurationElementCollection listenerAdaptersCollection = section.GetCollection();

                for (int i = 0; i < listenerAdaptersCollection.Count; i++)
                {
                    WebAdmin.ConfigurationElement element = listenerAdaptersCollection[i];

                    if (string.Compare((string)element.GetAttribute("name").Value,
                                       UdpConstants.Scheme, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        listenerAdaptersCollection.RemoveAt(i);
                    }
                }

                sm.CommitChanges();
                wasConfiguration = null;
                sm = null;
            }

            if (options.ProtocolHandlerChecked)
            {
                Configuration    rootWebConfig = GetRootWebConfiguration();
                ProtocolsSection section       = (ProtocolsSection)rootWebConfig.GetSection(ProtocolsPath);
                section.Protocols.Remove(UdpConstants.Scheme);
                rootWebConfig.Save();
            }
        }
Esempio n. 10
0
        public void Initialize()
        {
            if (_configurationProvider.IsEmulated())
            {
                return;
            }

            // Instantiate the IIS ServerManager
            using (var serverManager = new ServerManager())
            {
                // Disable idle timeout & set queue length to 5000
                serverManager.ApplicationPoolDefaults.ProcessModel.IdleTimeout = TimeSpan.Zero;
                serverManager.ApplicationPoolDefaults.QueueLength = 5000;

                // Server runtime configuration
                Microsoft.Web.Administration.Configuration applicationConfig = serverManager.GetApplicationHostConfiguration();

                // Server runtime settings
                // http://www.iis.net/configreference/system.webserver/serverruntime
                ConfigurationSection serverRuntimeSection = applicationConfig.GetSection("system.webServer/serverRuntime", "");
                serverRuntimeSection["enabled"] = true;
                serverRuntimeSection["frequentHitThreshold"] = 1;
                serverRuntimeSection["frequentHitTimePeriod"] = TimeSpan.Parse("00:00:10");

                // Compression settings
                // http://www.iis.net/configreference/system.webserver/httpcompression
                ConfigurationSection httpCompressionSection = applicationConfig.GetSection("system.webServer/httpCompression");
                httpCompressionSection["noCompressionForHttp10"] = false;
                httpCompressionSection["noCompressionForProxies"] = false;
                ConfigurationElementCollection dynamicTypesCollection = httpCompressionSection.GetCollection("dynamicTypes");

                ConfigurationElement addElement = dynamicTypesCollection.CreateElement("add");
                addElement["mimeType"] = @"application/json";
                addElement["enabled"] = true;
                try
                {
                    dynamicTypesCollection.Add(addElement);
                }
                catch (COMException)
                {
                    // add json element already exists
                }

                addElement = dynamicTypesCollection.CreateElement("add");
                addElement["mimeType"] = @"application/xml";
                addElement["enabled"] = true;
                try
                {
                    dynamicTypesCollection.Add(addElement);
                }
                catch (COMException)
                {
                    // add xml element already exists
                }

                // Commit the changes
                serverManager.CommitChanges();
            }
        }
        public void GetAuthenticationSettings(ServerManager srvman, WebVirtualDirectory virtualDir)
        {
			var config = srvman.GetApplicationHostConfiguration();
			//
			var section = config.GetSection(Constants.BasicAuthenticationSection, virtualDir.FullQualifiedPath);
			//
			virtualDir.EnableBasicAuthentication = Convert.ToBoolean(section.GetAttributeValue(EnabledAttribute));
        }
        public PropertyBag GetAuthenticationSettings(ServerManager srvman, string siteId)
        {
            PropertyBag bag = new PropertyBag();
			var config = srvman.GetApplicationHostConfiguration();
			//
			var section = config.GetSection(Constants.WindowsAuthenticationSection, siteId);
			//
			bag[AuthenticationGlobals.IsLocked] = section.IsLocked;
			bag[AuthenticationGlobals.Enabled] = Convert.ToBoolean(section.GetAttributeValue(EnabledAttribute));
            return bag;
        }
Esempio n. 13
0
        /// <summary>
        /// Creates an ftp virtual directory on the "fileService" ftp site.
        /// </summary>
        /// <param name="siteName">The name of the new ftp site.</param>
        /// <param name="directory">The target physical path of the virtual directory.</param>
        /// <param name="port">The port.</param>
        public static void CreateFtpSite(string siteName, string directory, int port)
        {
            using (ServerManager serverManager = new ServerManager())
            {
                Configuration config = serverManager.GetApplicationHostConfiguration();

                ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites");

                ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();

                ConfigurationElement siteElement = sitesCollection.CreateElement("site");
                siteElement["name"] = siteName;
                siteElement["id"] = port;

                ConfigurationElementCollection bindingsCollection = siteElement.GetCollection("bindings");

                ConfigurationElement bindingElement = bindingsCollection.CreateElement("binding");
                bindingElement["protocol"] = @"ftp";
                bindingElement["bindingInformation"] = string.Format(CultureInfo.InvariantCulture, @"*:{0}:", port);
                bindingsCollection.Add(bindingElement);

                ConfigurationElement ftpServerElement = siteElement.GetChildElement("ftpServer");

                ConfigurationElement securityElement = ftpServerElement.GetChildElement("security");

                ConfigurationElement sslElement = securityElement.GetChildElement("ssl");
                sslElement["controlChannelPolicy"] = "SslAllow";
                sslElement["dataChannelPolicy"] = "SslAllow";

                ConfigurationElement authenticationElement = securityElement.GetChildElement("authentication");

                ConfigurationElement basicAuthenticationElement = authenticationElement.GetChildElement("basicAuthentication");
                basicAuthenticationElement["enabled"] = true;

                ConfigurationElementCollection siteCollection = siteElement.GetCollection();

                ConfigurationElement applicationElement = siteCollection.CreateElement("application");
                applicationElement["path"] = @"/";

                ConfigurationElementCollection applicationCollection = applicationElement.GetCollection();

                ConfigurationElement virtualDirectoryElement = applicationCollection.CreateElement("virtualDirectory");
                virtualDirectoryElement["path"] = @"/";
                virtualDirectoryElement["physicalPath"] = new DirectoryInfo(directory).FullName;
                applicationCollection.Add(virtualDirectoryElement);
                siteCollection.Add(applicationElement);
                sitesCollection.Add(siteElement);

                serverManager.CommitChanges();
            }

            Uhuru.Utilities.FirewallTools.OpenPort(port, string.Format(CultureInfo.InvariantCulture, "FTP_{0}", siteName));
        }
Esempio n. 14
0
        private void ProtectSite(IIS.ServerManager iis, string siteName)
        {
            var config = iis.GetApplicationHostConfiguration();

            var anonymousAuthSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", siteName);

            anonymousAuthSection.SetAttributeValue("enabled", false);

            var basicAuthSection = config.GetSection("system.webServer/security/authentication/basicAuthentication", siteName);

            basicAuthSection.SetAttributeValue("enabled", true);
        }
		public PropertyBag GetClassicAspSettings(ServerManager srvman, string siteId)
        {
			var config = srvman.GetApplicationHostConfiguration();
			//
			var aspSection = config.GetSection(SectionName, siteId);
			//
			PropertyBag bag = new PropertyBag();
			//
			bag[ClassicAspGlobals.EnableParentPaths] = Convert.ToBoolean(aspSection.GetAttributeValue(EnableParentPathsAttribute));
			//
			return bag;
        }
 public PropertyBag GetSettings(ServerManager srvman, string siteId)
 {
     var config = srvman.GetApplicationHostConfiguration();
     //
     var section = config.GetSection(Constants.CompressionSection, siteId);
     //
     PropertyBag bag = new PropertyBag();
     //
     bag[CompressionGlobals.DynamicCompression] = Convert.ToBoolean(section.GetAttributeValue(DynamicCompression));
     bag[CompressionGlobals.StaticCompression] = Convert.ToBoolean(section.GetAttributeValue(StaticCompression));
     //
     return bag;
 }
		public PropertyBag GetAuthenticationSettings(ServerManager srvman, string siteId)
        {
			var config = srvman.GetApplicationHostConfiguration();
			//
			var section = config.GetSection(Constants.AnonymousAuthenticationSection, siteId);
			//
			PropertyBag bag = new PropertyBag();
			//
			bag[AuthenticationGlobals.AnonymousAuthenticationUserName] = Convert.ToString(section.GetAttributeValue(UserNameAttribute));
			bag[AuthenticationGlobals.AnonymousAuthenticationPassword] = Convert.ToString(section.GetAttributeValue(PasswordAttribute));
			bag[AuthenticationGlobals.Enabled] = Convert.ToBoolean(section.GetAttributeValue(EnabledAttribute));
			bag[AuthenticationGlobals.IsLocked] = section.IsLocked;
			//
			return bag;
        }
Esempio n. 18
0
        private static void EnsureDefaultDocument(IIS.ServerManager iis)
        {
            Configuration        applicationHostConfiguration = iis.GetApplicationHostConfiguration();
            ConfigurationSection defaultDocumentSection       = applicationHostConfiguration.GetSection("system.webServer/defaultDocument");

            ConfigurationElementCollection filesCollection = defaultDocumentSection.GetCollection("files");

            if (!filesCollection.Any(ConfigurationElementContainsHostingStart))
            {
                ConfigurationElement addElement = filesCollection.CreateElement("add");

                addElement["value"] = HostingStartHtml;
                filesCollection.Add(addElement);

                iis.CommitChanges();
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Adds the user access.
        /// </summary>
        /// <param name="siteName">Name of the site.</param>
        /// <param name="user">The user.</param>
        public static void AddUserAccess(string siteName, string user)
        {
            using (ServerManager serverManager = new ServerManager())
            {
                Configuration config = serverManager.GetApplicationHostConfiguration();

                ConfigurationElementCollection authorization = config.GetSection("system.ftpServer/security/authorization", siteName).GetCollection();
                ConfigurationElement newAuthorization = authorization.CreateElement("add");
                newAuthorization["accessType"] = "Allow";
                newAuthorization["users"] = user;
                newAuthorization["permissions"] = "Read, Write";

                authorization.Add(newAuthorization);

                serverManager.CommitChanges();
            }
        }
Esempio n. 20
0
        public static void CreateFtpUser(string configurationPath, string username, string password)
        {
            ManagementUserInfo userInfo = ManagementAuthentication.CreateUser(username, password);
            ManagementAuthorization.Grant(userInfo.Name, configurationPath, false);

            using (ServerManager serverManager = new ServerManager())
            {
                Configuration config = serverManager.GetApplicationHostConfiguration();
                ConfigurationSection authorizationSection = config.GetSection("system.ftpServer/security/authorization", configurationPath);

                ConfigurationElementCollection authorizationCollection = authorizationSection.GetCollection();
                ConfigurationElement addElement = authorizationCollection.CreateElement("add");
                addElement["accessType"] = @"Allow";
                addElement["users"] = username;
                addElement["permissions"] = @"Read, Write";
                authorizationCollection.Add(addElement);
                serverManager.CommitChanges();
            }
        }
        public SettingPair[] GetExtensionsInstalled(ServerManager srvman)
        {
            var settings = new List<SettingPair>();
			var config = srvman.GetApplicationHostConfiguration();

            var handlersSection = (HandlersSection) config.GetSection(Constants.HandlersSection, typeof (HandlersSection));

            var executalbesToLookFor = new[]
            {
                // Perl
                new KeyValuePair<string, string>(Constants.PerlPathSetting, "\\perl.exe"),
                // Php
                new KeyValuePair<string, string>(Constants.Php4PathSetting, "\\php.exe"),
                new KeyValuePair<string, string>(Constants.PhpPathSetting, "\\php-cgi.exe"),
                // Classic ASP
                new KeyValuePair<string, string>(Constants.AspPathSetting, @"\inetsrv\asp.dll"),
                // ASP.NET
                new KeyValuePair<string, string>(Constants.AspNet11PathSetting, @"\Framework\v1.1.4322\aspnet_isapi.dll"),
                new KeyValuePair<string, string>(Constants.AspNet20PathSetting, @"\Framework\v2.0.50727\aspnet_isapi.dll"),
                new KeyValuePair<string, string>(Constants.AspNet40PathSetting, @"\Framework\v4.0.30319\aspnet_isapi.dll"),
                // ASP.NET x64
                new KeyValuePair<string, string>(Constants.AspNet20x64PathSetting, @"\Framework64\v2.0.50727\aspnet_isapi.dll"),
                new KeyValuePair<string, string>(Constants.AspNet40x64PathSetting, @"\Framework64\v4.0.30319\aspnet_isapi.dll"),
            };

            foreach (var handler in handlersSection.Handlers)
            {
                foreach (var valuePair in executalbesToLookFor)
                {
                    var key = valuePair.Key;
                    if (handler.ScriptProcessor.EndsWith(valuePair.Value) && !settings.Exists(s => s.Name == key))
                    {
						settings.Add(new SettingPair{Name = valuePair.Key, Value = handler.ScriptProcessor});
                    }
                }
            }

            return settings.ToArray();
        }
Esempio n. 22
0
        public void SetWebCosoleEnabled(bool enabled)
        {
            using (var srvman = new ServerManager())
            {
                Configuration appConfig = srvman.GetApplicationHostConfiguration();

                ConfigurationSection heliconZooServer = appConfig.GetSection("system.webServer/heliconZooServer");

                ConfigurationElement switchboard = heliconZooServer.GetChildElement("switchboard");
                ConfigurationElementCollection switchboardCollection = switchboard.GetCollection();

                bool found = false;
                foreach (ConfigurationElement switchboardElement in switchboardCollection)
                {
                    if ((string)switchboardElement.GetAttributeValue("name") == "console")
                    {
                        SetSwitchBoardValue(switchboardElement, enabled);
                        
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    ConfigurationElement element = switchboardCollection.CreateElement();
                    element.SetAttributeValue("name", "console");
                    SetSwitchBoardValue(element, enabled);
                    switchboardCollection.Add(element);
                }

                srvman.CommitChanges();
            }
        }
Esempio n. 23
0
        public bool IsWebCosoleEnabled()
        {
            bool isEnginesEnabled = true;

            using (var srvman = new ServerManager())
            {
                Configuration appConfig = srvman.GetApplicationHostConfiguration();

                ConfigurationSection heliconZooServer = appConfig.GetSection("system.webServer/heliconZooServer");

                //switchboard
                ConfigurationElement switchboard = heliconZooServer.GetChildElement("switchboard");
                ConfigurationElementCollection switchboardCollection = switchboard.GetCollection();


                foreach (ConfigurationElement switchboardElement in switchboardCollection)
                {
                    if ((string)switchboardElement.GetAttributeValue("name") == "console")
                    {
                        isEnginesEnabled = GetSwitchBoardValue(switchboardElement);
                        break;
                    }
                }
            }

            return isEnginesEnabled;
        }
Esempio n. 24
0
        public void SetEnabledEnginesForSite(string siteId, string[] engineNames)
        {
            if (string.IsNullOrEmpty(siteId))
            {
                return;
            }

            using (var srvman = new ServerManager())
            {
                Configuration appConfig = srvman.GetApplicationHostConfiguration();
                ConfigurationSection zooServer = appConfig.GetSection("system.webServer/heliconZooServer", siteId);
                ConfigurationElement switchboard = zooServer.GetChildElement("switchboard");
                ConfigurationElementCollection switchboardCollection = switchboard.GetCollection();

                switchboardCollection.Clear();

                // first disable all engines if "*" is not present in input engineNames
                if (!engineNames.Contains("*"))
                {
                    ConfigurationElement elementDisableAll = switchboardCollection.CreateElement();
                    elementDisableAll.SetAttributeValue("name", "*");
                    SetSwitchBoardValue(elementDisableAll, false);
                    switchboardCollection.Add(elementDisableAll);
                }

                foreach (string engineName in engineNames)
                {
                    ConfigurationElement element = switchboardCollection.CreateElement();
                    element.SetAttributeValue("name", engineName);
                    SetSwitchBoardValue(element, true);
                    switchboardCollection.Add(element);
                }

                RegisterZooPhpHandlers(siteId, engineNames, appConfig);

                srvman.CommitChanges();
            }

        }
Esempio n. 25
0
        public string[] GetEnabledEnginesForSite(string siteId)
        {
            if (string.IsNullOrEmpty(siteId))
            {
                return new string[0];
            }

            List<string> engines = new List<string>();

            using (var srvman = new ServerManager())
            {
                Configuration appConfig = srvman.GetApplicationHostConfiguration();
                ConfigurationSection zooServer;
                try
                {
                    zooServer = appConfig.GetSection("system.webServer/heliconZooServer", siteId);
                }
                catch(Exception)
                {
                    // heliconZooServer is not found
                    // looks like zoo is not installed
                    return engines.ToArray();

                }
                ConfigurationElement switchboard = zooServer.GetChildElement("switchboard");
                ConfigurationElementCollection switchboardCollection = switchboard.GetCollection();

                foreach (ConfigurationElement element in switchboardCollection)
                {
                    
                    bool isEnabled = GetSwitchBoardValue(element);
                    if (isEnabled)
                    {
                        engines.Add(element.GetAttributeValue("name").ToString());
                    }
                }
            }

            return engines.ToArray();
        }
Esempio n. 26
0
        public void SetEngines(HeliconZooEngine[] userEngines)
        {
            // Write to applicationHost.config

            using (var srvman = new ServerManager())
            {

                Configuration appConfig = srvman.GetApplicationHostConfiguration();

                
                ConfigurationSection heliconZooServer = appConfig.GetSection("system.webServer/heliconZooServer");
                ConfigurationElement engines = heliconZooServer.GetChildElement("userEngines");
                ConfigurationElementCollection enginesCollection = engines.GetCollection();
                enginesCollection.Clear();


                ConfigurationElement switchboard = heliconZooServer.GetChildElement("switchboard");
                ConfigurationElementCollection switchboardCollection = switchboard.GetCollection();
                switchboardCollection.Clear();
                
                
              
                foreach(HeliconZooEngine item in userEngines)
                {
                    if (item.isUserEngine)
                    {
                        ConfigurationElement engine = enginesCollection.CreateElement();
                        ConvertHeliconZooEngineToElement(item, engine);
                        enginesCollection.Add(engine);
                    }

                
                }

                srvman.CommitChanges();
            }
        }
Esempio n. 27
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.ForceHttpSharing]))
            {
                section.DEA.ForceHttpSharing = Convert.ToBoolean(Context.Parameters[Arguments.ForceHttpSharing], CultureInfo.InvariantCulture);
            }

            if (!string.IsNullOrEmpty(Context.Parameters[Arguments.HeartBeatInterval]))
            {
                section.DEA.HeartbeatInterval = 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.MaxMemory = 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 (ServerManager serverManager = new 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();
            }
        }
Esempio n. 28
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="mgr"></param>
 /// <param name="result"></param>
 /// <param name="doUpdate">true: do the update; false: just verify it</param>
 private void ConfigureAuthentication(ServerManager mgr, DeploymentResult result, bool doUpdate)
 {
     if(AuthenticationToSet != null && AuthenticationToSet.Count > 0) {
       Configuration config = mgr.GetApplicationHostConfiguration();
       foreach(var item in AuthenticationToSet) {
          ConfigurationSection section = config.GetSection("system.webServer/security/authentication/" + item.Key, WebsiteName + "/" + VirtualDirectoryPath);// settings.WFSiteName + "/" + settings.WFDirectoryName
          if(section == null) { result.AddError(String.Format(@"authentication type '{0}' not found!", item.Key)); } else {
             if(doUpdate) {
                LogCoarseGrain("[iis7] Setting authentication for application '{0}': '{1}' from '{2}' to '{3}'", VirtualDirectoryPath, item.Key, section["enabled"], item.Value);
                section["enabled"] = item.Value;
             }
          }
       }
        }
 }
Esempio n. 29
0
            public static ConfigurationElement GetWebFarm(string name)
            {
                using (var serverManager = new ServerManager())
                {
                    Configuration config = serverManager.GetApplicationHostConfiguration();

                    ConfigurationSection section = config.GetSection("webFarms");
                    ConfigurationElementCollection farms = section.GetCollection();

                    return farms.FirstOrDefault(f => f.GetAttributeValue("name").ToString() == name);
                }
            }
Esempio n. 30
0
            public static void DeleteWebFarm(string name)
            {
                using (var serverManager = new ServerManager())
                {
                    Configuration config = serverManager.GetApplicationHostConfiguration();

                    ConfigurationSection section = config.GetSection("webFarms");
                    ConfigurationElementCollection farms = section.GetCollection();

                    ConfigurationElement farm = farms.FirstOrDefault(f => f.GetAttributeValue("name").ToString() == name);

                    if (farm != null)
                    {
                        farms.Remove(farm);
                        serverManager.CommitChanges();
                    }
                }
            }
Esempio n. 31
0
        public HeliconZooEngine[] GetEngines()
        {
            // Read applicationHost.config

            List<HeliconZooEngine> result = new List<HeliconZooEngine>();

            using (var srvman = new ServerManager())
            {
                Configuration appConfig = srvman.GetApplicationHostConfiguration();

                ConfigurationSection heliconZooServer;
                try
                {
                    heliconZooServer = appConfig.GetSection("system.webServer/heliconZooServer");
                }
                catch(Exception)
                {
                    // heliconZooServer is not found
                    // looks like zoo is not installed
                    return result.ToArray();
                }

                ConfigurationElement engines = heliconZooServer.GetChildElement("engines");
                ConfigurationElementCollection enginesCollection = engines.GetCollection();

                //switchboard
                ConfigurationElement switchboard = heliconZooServer.GetChildElement("switchboard");
                ConfigurationElementCollection switchboardCollection = switchboard.GetCollection();


                bool switchboardDisabledDefault = true;
                foreach (ConfigurationElement switchboardElement in switchboardCollection)
                {
                    if ((string)switchboardElement.GetAttributeValue("name") == "*")
                    {
                        bool isEnabled = GetSwitchBoardValue(switchboardElement);

                        switchboardDisabledDefault =  !isEnabled ;
                        break;
                    }
                }

                //main engines

                foreach (ConfigurationElement item in enginesCollection)
                {
                    HeliconZooEngine newItem = ConvertElementToHeliconZooEngine(item);
                    newItem.disabled = switchboardDisabledDefault;
                    result.Add(newItem);
                }


                //userEngines

                ConfigurationElement userEngines = heliconZooServer.GetChildElement("userEngines");
                ConfigurationElementCollection userEnginesCollection = userEngines.GetCollection();
                foreach (ConfigurationElement item in userEnginesCollection)
                {
                    HeliconZooEngine newItem = ConvertElementToHeliconZooEngine(item);

                    //remove if exists
                    HeliconZooEngine serverItem = Collection_GetHeliconZooEngineByName(result, newItem.name);
                    if (serverItem != null)
                    {
                        result.Remove(serverItem);
                    }

                    //override settings
                    newItem.isUserEngine = true;
                    newItem.disabled = switchboardDisabledDefault;
                    result.Add(newItem);
                }


                //Web console
                HeliconZooEngine webConsole = new HeliconZooEngine
                    {
                        displayName = "Web console", 
                        name = "console"
                        
                    };

                result.Add(webConsole);

              

                foreach (ConfigurationElement switchboardElement in switchboardCollection)
                {
                    HeliconZooEngine item = Collection_GetHeliconZooEngineByName(result, (string)switchboardElement.GetAttributeValue("name"));
                    if (item != null)
                    {
                        bool isEnabled = GetSwitchBoardValue(switchboardElement);
                        item.disabled = !isEnabled;
                    }
                    else
                    {
                       //default value
                        //item.disabled = !switchboardEnabledDefaults;
                    }
                    
                }


            }

            return result.ToArray();
        }
Esempio n. 32
0
 public static void SetAnonyousUserToProcessId()
 {
     var mgr = new ServerManager();
     try
     {
         var config = mgr.GetApplicationHostConfiguration();
         var section = config.GetSection("system.webServer/security/authentication/anonymousAuthentication");
         section.SetAttributeValue("userName", "");
         section.RawAttributes.Remove("password");
     }
     catch (Exception ex)
     {
         Console.WriteLine("Removing anonymous user entry failed. Reason: {0}", ex.Message);
     }
     mgr.CommitChanges();
 }
Esempio n. 33
0
        private static void EnsureDefaultDocument(ServerManager iis)
        {
            IIS.Configuration applicationHostConfiguration = iis.GetApplicationHostConfiguration();
            IIS.ConfigurationSection defaultDocumentSection = applicationHostConfiguration.GetSection("system.webServer/defaultDocument");

            IIS.ConfigurationElementCollection filesCollection = defaultDocumentSection.GetCollection("files");

            if (filesCollection.Any(ConfigurationElementContainsHostingStart))
                return;

            IIS.ConfigurationElement addElement = filesCollection.CreateElement("add");
            addElement["value"] = HostingStartHtml;
            filesCollection.Add(addElement);

            iis.CommitChanges();
        }
        public override bool OnStart()
        {
            try
            {
                using (var server = new ServerManager())
                {
                    const string site = "Web";

                    var siteName = string.Format("{0}_{1}", RoleEnvironment.CurrentRoleInstance.Id, site);
                    var config = server.GetApplicationHostConfiguration();
                    ConfigureAccessSection(config, siteName);

                    var iisClientCertificateMappingAuthenticationSection = EnableIisClientCertificateMappingAuthentication(config, siteName);
                    ConfigureManyToOneMappings(iisClientCertificateMappingAuthenticationSection);
                    ConfigureOneToOneMappings(iisClientCertificateMappingAuthenticationSection);

                    server.CommitChanges();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                // handle error here
            }

            return base.OnStart();
        }