public static void SetSampleWeb35StoreAndTrust(Configuration.Store store, int pollInterval, string trust)
 {
     XDocument doc = null;
     using (var stream = File.OpenText(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName +
                       "\\RequestReduce.SampleWeb35\\web.config"))
     {
         doc = XDocument.Load(stream);
     }
     doc.Element("configuration").Element("RequestReduce").SetAttributeValue("contentStore", store.ToString());
     doc.Element("configuration").Element("RequestReduce").SetAttributeValue("storePollInterval", pollInterval.ToString());
     doc.Element("configuration").Element("system.web").Element("trust").SetAttributeValue("level", trust);
     Recycle35Pool();
     doc.Save(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName +
                       "\\RequestReduce.SampleWeb35\\web.config");
 }
Example #2
0
 private static void SetHttpRedirectElement(bool enableChecked, string destination, bool enableExactDestination, bool enableChildOnly, string httpResponseStatus, Configuration config)
 {
     ConfigurationSection httpRedirectSection = config.GetSection("system.webServer/httpRedirect");
     httpRedirectSection["enabled"] = enableChecked;
     httpRedirectSection["destination"] = destination;
     httpRedirectSection["exactDestination"] = enableExactDestination;
     httpRedirectSection["childOnly"] = enableChildOnly;
     if (httpResponseStatus == "已找到(302)")
     {
         httpRedirectSection["httpResponseStatus"] = "Found";
     }
     else if (httpResponseStatus == "永久(301)")
     {
         httpRedirectSection["httpResponseStatus"] = "Permanent";
     }
     else
     {
         httpRedirectSection["httpResponseStatus"] = "Temporary";
     }
 }
        public static string ResetPhysicalContentDirectoryAndConfigureStore(Configuration.Store store, int poleInterval)
        {
            var poolRecycled = false;
            var rrFolder = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName + "\\RequestReduce.SampleWeb\\RRContent";
            if (Directory.Exists(rrFolder))
            {
                RecyclePool();
                poolRecycled = true;
                try
                {
                    RecyclePool();
                    Directory.Delete(rrFolder, true);
                }
                catch (IOException)
                {
                    Thread.Sleep(100);
                    Directory.Delete(rrFolder, true);
                }
                while (Directory.Exists(rrFolder))
                    Thread.Sleep(0);
            }

            XDocument doc = null;
            using (var stream = File.OpenText(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName +
                              "\\RequestReduce.SampleWeb\\web.config"))
            {
                doc = XDocument.Load(stream);
            }
            var cs = doc.Element("configuration").Element("RequestReduce").Attribute("contentStore");
            if (cs == null || cs.Value.ToLower() != store.ToString().ToLower())
            {
                doc.Element("configuration").Element("RequestReduce").SetAttributeValue("contentStore", store.ToString());
                doc.Element("configuration").Element("RequestReduce").SetAttributeValue("storePollInterval", poleInterval.ToString());
                if (!poolRecycled)
                    RecyclePool();
                doc.Save(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName +
                                  "\\RequestReduce.SampleWeb\\web.config");
            }
            return rrFolder;
        }
Example #4
0
        private static void RegisterZooPhpHandlers(string siteId, string[] engineNames, Configuration appConfig)
        {
            // set up zoo php handler if php engine was enabled
            string enabledPhpEngine = string.Empty;
            foreach (string engineName in engineNames)
            {
                if (engineName.StartsWith("php", StringComparison.OrdinalIgnoreCase))
                {
                    enabledPhpEngine = engineName;
                }
            }

            if (!string.IsNullOrEmpty(enabledPhpEngine))
            {
                ConfigurationSection handlers = appConfig.GetSection("system.webServer/handlers", siteId);
                ConfigurationElementCollection handlerCollection = handlers.GetCollection();

                // remove native php handlers
                /*
                    ConfigurationElement removePhp53 = handlerCollection.CreateElement("remove");
                    removePhp53.SetAttributeValue("name", "PHP53_via_FastCGI");
                    handlerCollection.Add(removePhp53);

                    ConfigurationElement removePhp = handlerCollection.CreateElement("remove");
                    removePhp.SetAttributeValue("name", "PHP_via_FastCGI");
                    handlerCollection.Add(removePhp);
                    */

                // search native php handlers
                /*
                    List<ConfigurationElement> elementsToRemove = new List<ConfigurationElement>();
                    foreach (ConfigurationElement el in handlerCollection)
                    {
                        string name = el.GetAttributeValue("name") as string;
                        if (!string.IsNullOrEmpty(name))
                        {
                            if (string.Equals(name, "PHP_via_FastCGI", StringComparison.OrdinalIgnoreCase)
                                ||
                                string.Equals(name, "PHP53_via_FastCGI", StringComparison.OrdinalIgnoreCase)
                            )
                            {
                                elementsToRemove.Add(el);
                            }
                        }
                    }

                    foreach (ConfigurationElement element in elementsToRemove)
                    {
                        //handlerCollection.Remove(element);
                    }
                    */


                // check zoo handlers exists
                List<ConfigurationElement> zooPhpHandlersToRemove = new List<ConfigurationElement>();
                foreach (ConfigurationElement el in handlerCollection)
                {
                    string name = el.GetAttributeValue("name") as string;
                    if (!string.IsNullOrEmpty(name))
                    {
                        if (name.StartsWith("php.", StringComparison.OrdinalIgnoreCase))
                        {
                            string scriptProcessor = el.GetAttributeValue("scriptProcessor") as string;
                            if (!string.IsNullOrEmpty(scriptProcessor))
                            {
                                zooPhpHandlersToRemove.Add(el);
                            }
                        }
                    }
                }

                // remove existing zoo php handlers
                foreach (ConfigurationElement element in zooPhpHandlersToRemove)
                {
                    handlerCollection.Remove(element);
                }

                // add zoo php handlers
                ConfigurationElement zooPhpX86 = handlerCollection.CreateElement();
                zooPhpX86.SetAttributeValue("name", "php.pipe#x86");
                zooPhpX86.SetAttributeValue("scriptProcessor", enabledPhpEngine);
                zooPhpX86.SetAttributeValue("path", "*.php");
                zooPhpX86.SetAttributeValue("verb", "*");
                zooPhpX86.SetAttributeValue("modules", "HeliconZoo_x86");
                zooPhpX86.SetAttributeValue("preCondition", "bitness32");
                zooPhpX86.SetAttributeValue("resourceType", "Unspecified");
                zooPhpX86.SetAttributeValue("requireAccess", "Script");
                handlerCollection.AddAt(0, zooPhpX86);

                ConfigurationElement zooPhpX64 = handlerCollection.CreateElement();
                zooPhpX64.SetAttributeValue("name", "php.pipe#x64");
                zooPhpX64.SetAttributeValue("scriptProcessor", enabledPhpEngine);
                zooPhpX64.SetAttributeValue("path", "*.php");
                zooPhpX64.SetAttributeValue("verb", "*");
                zooPhpX64.SetAttributeValue("modules", "HeliconZoo_x64");
                zooPhpX64.SetAttributeValue("preCondition", "bitness64");
                zooPhpX64.SetAttributeValue("resourceType", "Unspecified");
                zooPhpX64.SetAttributeValue("requireAccess", "Script");
                handlerCollection.AddAt(1, zooPhpX64);

                // process index.php as default document
                ConfigurationSection defaultDocument = appConfig.GetSection("system.webServer/defaultDocument", siteId);
                RegisterPhpDefaultDocument(defaultDocument);
            }
        }
 private static ConfigurationSection EnableIisClientCertificateMappingAuthentication(Configuration config, string siteName)
 {
     var iisClientCertificateMappingAuthenticationSection = config.GetSection("system.webServer/security/authentication/iisClientCertificateMappingAuthentication", siteName);
     iisClientCertificateMappingAuthenticationSection["enabled"] = true;
     return iisClientCertificateMappingAuthenticationSection;
 }
 private static void ConfigureAccessSection(Configuration config, string siteName)
 {
     var accessSection = config.GetSection("system.webServer/security/access", siteName);
     accessSection["sslFlags"] = @"Ssl,SslNegotiateCert,SslRequireCert";
 }
        public Configuration GetWebConfiguration()
        {
            if (_configuration != null)
            {
                return _configuration;
            }

            string root = null;
            foreach (VirtualDirectory child in VirtualDirectories)
            {
                if (child.Path == VirtualDirectory.RootPath)
                {
                    root = child.PhysicalPath;
                    break;
                }
            }

            if (this.IsRoot())
            {
                var server = Server.GetConfigurationCache().FileContext;
                if (root == null)
                {
                    var site = new Configuration(new FileContext(Server, null, server, Site.Name, false, false, this.Server.ReadOnly, (Entity as IXmlLineInfo).LineNumber));
                    return (_configuration = site);
                }
                else
                {
                    var physicalPath = Server.GetPhysicalPath(root);
                    var siteFile = System.IO.Path.Combine(physicalPath,
                        "web.config").ExpandIisExpressEnvironmentVariables();
                    Server.CleanSiteFile(siteFile);

                    // TODO: test ACL to set ReadOnly.
                    var site = new Configuration(new FileContext(Server, siteFile, server, Site.Name, false, false, this.Server.ReadOnly));
                    return (_configuration = site);
                }
            }

            string start = null;
            Configuration parent = null;
            while (parent == null)
            {
                var parentPath = (start ?? Path).GetParentPath();
                foreach (Application app in Site.Applications)
                {
                    if (app.Path != parentPath)
                    {
                        continue;
                    }

                    parent = app.GetWebConfiguration();
                    break;
                }

                if (start == parentPath)
                {
                    break;
                }

                start = parentPath;
            }

            if (root == null)
            {
                var app = new Configuration(new FileContext(Server, null, parent?.FileContext, Site.Name, false, false, this.Server.ReadOnly, (Entity as IXmlLineInfo).LineNumber));
                return (_configuration = app);
            }

            var fullPath = Site.Name + Path;
            var appFile = System.IO.Path.Combine(root, "web.config");
            // TODO: test ACL to set ReadOnly.
            return (_configuration = new Configuration(new FileContext(Server, appFile, parent?.FileContext, fullPath, false, false, this.Server.ReadOnly)));
        }
 private static void SetAuthPropertiesForSite(Configuration config, ref Site site)
 {
     foreach (string authType in AuthTypes)
     {
         var authSection = config.GetSection(string.Format(AuthenticationSection, authType), site.SiteName);
         if ((bool)authSection[EnabledPropertyName])
         {
             switch (authType)
             {
                 case AnonymousAuth:
                     site.EnabledAuthType = EnabledAuthenticationType.Anonymous;
                     return;
                 case WindowsAuth:
                     site.EnabledAuthType = EnabledAuthenticationType.Windows;
                     return;
                 case BasicAuth:
                     site.EnabledAuthType = EnabledAuthenticationType.Basic;
                     return;
                 case ClientServerAuth:
                     site.EnabledAuthType = EnabledAuthenticationType.ClientCertificate;
                     return;
                 case IISClientServerMappingAuth:
                     site.EnabledAuthType = EnabledAuthenticationType.IisClientCertificate;
                     return;
                 case DigestAuth:
                     site.EnabledAuthType = EnabledAuthenticationType.Digest;
                     return;
             }
         }
     }
 }
        private bool HasDelegationSection(Configuration adminConfig)
        {
            // try to get delegation section in config file (C:\Windows\system32\inetsrv\config\administration.config)
            try
            {
                adminConfig.GetSection("system.webServer/management/delegation");
            }
            catch (Exception ex)
            {
                /* skip */
                return false;
            }

            return true;
        }
        private void Initialize()
        {
            if (this.Initialized)
            {
                return;
            }

            this.Initialized = true;
            PreInitialize();
            var machineConfig = Helper.IsRunningOnMono()
                ? "/Library/Frameworks/Mono.framework/Versions/Current/etc/mono/4.5/machine.config"
                : Path.Combine(
                                    Environment.GetFolderPath(Environment.SpecialFolder.Windows),
                                    "Microsoft.NET",
                                    IntPtr.Size == 2 ? "Framework" : "Framework64",
                                    "v4.0.30319",
                                    "config",
                                    "machine.config");
            var machine =
                new Configuration(
                    new FileContext(
                        this,
                        machineConfig,
                        null,
                        null,
                        false,
                        true,
                        true));
            var webConfig = Helper.IsRunningOnMono()
                ? "/Library/Frameworks/Mono.framework/Versions/Current/etc/mono/4.5/web.config"
                : Path.Combine(
                                Environment.GetFolderPath(Environment.SpecialFolder.Windows),
                                "Microsoft.NET",
                                IntPtr.Size == 2 ? "Framework" : "Framework64",
                                "v4.0.30319",
                                "config",
                                "web.config");
            var web =
                new Configuration(
                    new FileContext(
                        this,
                        webConfig,
                        machine.FileContext,
                        null,
                        false,
                        true,
                        true));

            _applicationHost =
                new Configuration(
                new FileContext(this, this.FileName, web.FileContext, null, true, false, this.ReadOnly));

            this.LoadCache();

            var poolSection = _applicationHost.GetSection("system.applicationHost/applicationPools");
            _applicationPoolDefaults =
                new ApplicationPoolDefaults(poolSection.GetChildElement("applicationPoolDefaults"), poolSection);
            this.ApplicationPoolCollection = new ApplicationPoolCollection(poolSection, this);
            var siteSection = _applicationHost.GetSection("system.applicationHost/sites");
            _siteDefaults = new SiteDefaults(siteSection.GetChildElement("siteDefaults"), siteSection);
            _applicationDefaults = new ApplicationDefaults(
                siteSection.GetChildElement("applicationDefaults"),
                siteSection);
            _virtualDirectoryDefaults =
                new VirtualDirectoryDefaults(siteSection.GetChildElement("virtualDirectoryDefaults"), siteSection);
            this.SiteCollection = new SiteCollection(siteSection, this);

            PostInitialize();
        }
 private void LoadCache()
 {
     // IMPORTANT: force to reload clean elements from file.
     _cleanHost = null;
     _cleanHost =
         new Configuration(
         new FileContext(this, this.FileName, _applicationHost.FileContext.Parent, null, true, false, false));
 }