public GetChildElement ( string elementName ) : |
||
elementName | string | |
Результат |
public async Task LoadAsync(Application application, string file, string appName, SortedDictionary <string, List <string> > variables) { if (variables == null) { if (Credentials == null) { var rows = File.ReadAllLines(file); variables = new SortedDictionary <string, List <string> >(); foreach (var line in rows) { var index = line.IndexOf('#'); var content = index == -1 ? line : line.Substring(0, index); var parts = content.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length != 2) { continue; } var key = parts[0].Trim().ToLowerInvariant(); var value = parts[1].Trim(); if (variables.ContainsKey(key)) { variables[key].Add(value); continue; } variables.Add(key, new List <string> { value }); } } else { using (var client = GetClient()) { HttpResponseMessage response = await client.GetAsync(string.Format("api/app/get/{0}", appName)); if (response.IsSuccessStatusCode) { variables = (SortedDictionary <string, List <string> >) await response.Content.ReadAsAsync(typeof(SortedDictionary <string, List <string> >)); } } } } variables.Load(new List <string> { "false" }, "usehttps"); variables.Load(new List <string> { "*" }, "hosts", "host"); variables.Load(new List <string> { IPAddress.Any.ToString() }, "addr", "address"); variables.Load(new List <string> { "80" }, "port"); var root = variables.Load(new List <string> { "/ /var/www/default" }, "root")[0]; var split = root.IndexOf(' '); if (split == -1 || split == 0) { throw new ServerManagerException("invalid root mapping"); } var virtualDirectory = new VirtualDirectory(null, application.VirtualDirectories); virtualDirectory.Path = root.Substring(0, split); virtualDirectory.PhysicalPath = root.Substring(split + 1); application.VirtualDirectories.Add(virtualDirectory); var configuration = application.GetWebConfiguration(); var defaultDocument = configuration.GetSection("system.webServer/defaultDocument"); defaultDocument["enabled"] = true; var collection = defaultDocument.GetCollection("files"); collection.Clear(); var names = variables.Load(new List <string> { Constants.DefaultDocumentList }, "indexes", "indexs")[0]; var pageNames = names.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var name in pageNames) { var file1 = collection.CreateElement(); file1.Attributes["value"].Value = name; collection.Add(file1); } ConfigurationSection httpLoggingSection = application.Server.GetApplicationHostConfiguration().GetSection("system.webServer/httpLogging", application.Location); var dontLog = Convert.ToBoolean(variables.Load(new List <string> { "false" }, "nolog")[0]); httpLoggingSection["dontLog"] = dontLog; var ipSecuritySection = application.Server.GetApplicationHostConfiguration().GetSection("system.webServer/security/ipSecurity", application.Location); ipSecuritySection["enableReverseDns"] = false; ipSecuritySection["allowUnlisted"] = true; ConfigurationElementCollection ipSecurityCollection = ipSecuritySection.GetCollection(); ipSecurityCollection.Clear(); var deny = variables.Load(new List <string>(), "denyfrom", "ip.deny"); foreach (var denyEntry in deny) { var denyItems = denyEntry.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in denyItems) { ConfigurationElement addElement = ipSecurityCollection.CreateElement("add"); if (item.Contains("/")) { var parts = item.Split('/'); addElement["ipAddress"] = parts[0]; addElement["subnetMask"] = parts[1]; } else { addElement["ipAddress"] = item; } addElement["allowed"] = false; ipSecurityCollection.Add(addElement); } } var allow = variables.Load(new List <string>(), "allowfrom", "ip.allow"); foreach (var allowEntry in allow) { var allowItems = allowEntry.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in allowItems) { ConfigurationElement addElement = ipSecurityCollection.CreateElement("add"); if (item.Contains("/")) { var parts = item.Split('/'); addElement["ipAddress"] = parts[0]; addElement["subnetMask"] = parts[1]; } else { addElement["ipAddress"] = item; } addElement["allowed"] = true; ipSecurityCollection.Add(addElement); } } ConfigurationSection requestFilteringSection = configuration.GetSection("system.webServer/security/requestFiltering"); ConfigurationElement hiddenSegmentsElement = requestFilteringSection.ChildElements["hiddenSegments"]; ConfigurationElementCollection hiddenSegmentsCollection = hiddenSegmentsElement.GetCollection(); hiddenSegmentsCollection.Clear(); var hidden = variables.Load(new List <string> { string.Empty }, "denydirs")[0]; var hiddenItems = hidden.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in hiddenItems) { ConfigurationElement add = hiddenSegmentsCollection.CreateElement("add"); add["segment"] = item; hiddenSegmentsCollection.Add(add); } ConfigurationSection httpErrorsSection = configuration.GetSection("system.webServer/httpErrors"); ConfigurationElementCollection httpErrorsCollection = httpErrorsSection.GetCollection(); httpErrorsCollection.Clear(); Debug.Assert(variables != null, "variables != null"); if (variables.ContainsKey("nofile")) { var error = variables["nofile"][0]; ConfigurationElement errorElement = httpErrorsCollection.CreateElement("error"); errorElement["statusCode"] = 404; errorElement["subStatusCode"] = 0; errorElement["prefixLanguageFilePath"] = @"%SystemDrive%\inetpub\custerr"; errorElement["responseMode"] = "ExecuteURL"; errorElement["path"] = error; httpErrorsCollection.Add(errorElement); variables.Remove("nofile"); } var urlCompressionSection = configuration.GetSection("system.webServer/urlCompression"); urlCompressionSection["doStaticCompression"] = Convert.ToBoolean(variables.Load(new List <string> { "true" }, "usegzip")[0]); ConfigurationSection httpProtocolSection = configuration.GetSection("system.webServer/httpProtocol"); httpProtocolSection["allowKeepAlive"] = Convert.ToBoolean(variables.Load(new List <string> { "true" }, "keep_alive")[0]); ConfigurationSection rulesSection = configuration.GetSection("system.webServer/rewrite/rules"); ConfigurationElementCollection rulesCollection = rulesSection.GetCollection(); rulesCollection.Clear(); if (variables.ContainsKey("rewrite")) { var rules = variables["rewrite"]; for (int i = 0; i < rules.Count; i++) { var rule = rules[i]; ConfigurationElement ruleElement = rulesCollection.CreateElement("rule"); ruleElement["name"] = @"rule" + i; ruleElement["enabled"] = true; ruleElement["patternSyntax"] = 0; ruleElement["stopProcessing"] = false; var parts = rule.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); ConfigurationElement matchElement = ruleElement.GetChildElement("match"); matchElement["ignoreCase"] = parts[0].EndsWith("/i", StringComparison.Ordinal); matchElement["url"] = parts[0].EndsWith("/i", StringComparison.Ordinal) ? parts[0].Substring(0, parts[0].Length - 2) : parts[0]; ConfigurationElement actionElement = ruleElement.GetChildElement("action"); actionElement["type"] = 2; actionElement["url"] = parts[1]; actionElement["appendQueryString"] = true; rulesCollection.Add(ruleElement); } variables.Remove("rewrite"); } application.Extra = variables; }
private HeliconZooEngine ConvertElementToHeliconZooEngine(ConfigurationElement item) { HeliconZooEngine result = new HeliconZooEngine(); result.name = (string)item.GetAttributeValue("name"); result.displayName = (string)item.GetAttributeValue("displayName"); result.arguments = (string)item.GetAttributeValue("arguments"); result.fullPath = (string)item.GetAttributeValue("fullPath"); result.arguments = (string)item.GetAttributeValue("arguments"); result.transport = (string)item.GetAttributeValue("transport"); result.protocol = (string)item.GetAttributeValue("protocol"); result.host = (string)item.GetAttributeValue("host"); result.portLower = (long) item.GetAttributeValue("portLower"); result.portUpper = (long) item.GetAttributeValue("portUpper"); result.maxInstances = (long) item.GetAttributeValue("maxInstances"); result.minInstances = (long) item.GetAttributeValue("minInstances"); result.timeLimit = (long) item.GetAttributeValue("timeLimit"); result.gracefulShutdownTimeout = (long) item.GetAttributeValue("gracefulShutdownTimeout"); result.memoryLimit = (long) item.GetAttributeValue("memoryLimit"); List<HeliconZooEnv> envList = new List<HeliconZooEnv>(); ConfigurationElementCollection envColl = item.GetChildElement("environmentVariables").GetCollection(); foreach (ConfigurationElement el in envColl) { envList.Add(ConvertElementToHeliconZooEnv(el)); } result.environmentVariables = envList.ToArray(); // TODO: fix this result.isUserEngine = false; // TODO: disabled return result; }
private static ConfigurationElement CreateInboundGwRemoteUserRule(ConfigModel model, ConfigurationElement ruleElement) { ruleElement["name"] = model.RuleName; ruleElement["patternSyntax"] = "ECMAScript"; ruleElement["stopProcessing"] = true; var matchElement = ruleElement.GetChildElement("match"); matchElement["url"] = "(.*)"; var conditionsElement = ruleElement.GetChildElement("conditions"); var conditionsCollection = conditionsElement.GetCollection(); //Get the origin requested : var inputElement = conditionsCollection.CreateElement("add"); inputElement["input"] = "{" + ServerVariable.SERVER_VARIABLE_HTTP_HOST + "}"; inputElement["pattern"] = model.Pattern; conditionsCollection.Add(inputElement); string arrServer = Environment.ExpandEnvironmentVariables(@"%APPSETTING_WEBSITE_SITE_NAME%"); // set the server variable var variablesCollection = ruleElement.GetChildElement("serverVariables").GetCollection(); AddServerVariable(variablesCollection, ServerVariable.SERVER_VARIABLE_HTTP_X_UNPROXIED_URL, arrServer + "{R:1}"); AddServerVariable(variablesCollection, ServerVariable.SERVER_VARIABLE_HTTP_X_ORIGINAL_ACCEPT_ENCODING, "{" + ServerVariable.SERVER_VARIABLE_ACCEPT_ENCODING + "}"); AddServerVariable(variablesCollection, ServerVariable.SERVER_VARIABLE_HTTP_X_ORIGINAL_HOST, "{" + ServerVariable.SERVER_VARIABLE_HTTP_HOST + "}"); AddServerVariable(variablesCollection, ServerVariable.SERVER_VARIABLE_ACCEPT_ENCODING, ""); AddServerVariable(variablesCollection, ServerVariable.SERVER_VARIABLE_HTTP_REFERER, model.UrlRewrite + "/{R:1}"); var actionElement = ruleElement.GetChildElement("action"); actionElement["type"] = "Rewrite"; actionElement["url"] = model.UrlRewrite+"/{R:1}"; return ruleElement; }
private void ConvertHeliconZooEngineToElement(HeliconZooEngine item, ConfigurationElement engine) { engine.SetAttributeValue("name", item.name); engine.SetAttributeValue("displayName", item.displayName); engine.SetAttributeValue("arguments", item.arguments); engine.SetAttributeValue("fullPath", item.fullPath); engine.SetAttributeValue("arguments", item.arguments); engine.SetAttributeValue("transport", item.transport); engine.SetAttributeValue("protocol", item.protocol); engine.SetAttributeValue("host", item.host); engine.SetAttributeValue("portLower", item.portLower); engine.SetAttributeValue("portUpper", item.portUpper); engine.SetAttributeValue("maxInstances", item.maxInstances); engine.SetAttributeValue("minInstances", item.minInstances); engine.SetAttributeValue("timeLimit", item.timeLimit); engine.SetAttributeValue("gracefulShutdownTimeout", item.gracefulShutdownTimeout); engine.SetAttributeValue("memoryLimit", item.memoryLimit); ConfigurationElementCollection envColl = engine.GetChildElement("environmentVariables").GetCollection(); foreach(HeliconZooEnv env in item.environmentVariables) { ConfigurationElement envElement = envColl.CreateElement(); envElement.SetAttributeValue("name", env.Name); envElement.SetAttributeValue("value", env.Value); envColl.Add(envElement); } }
public override void Install(IDictionary stateSaver) { base.Install(stateSaver); string targetDir = Context.Parameters[Argument.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[Argument.Capacity])) { section.Service.Capacity = int.Parse(Context.Parameters[Argument.Capacity], CultureInfo.InvariantCulture); } if (!string.IsNullOrEmpty(Context.Parameters[Argument.BaseDir])) { section.Service.BaseDir = Context.Parameters[Argument.BaseDir]; if (!Directory.Exists(section.Service.BaseDir)) { Directory.CreateDirectory(section.Service.BaseDir); } } if (!string.IsNullOrEmpty(Context.Parameters[Argument.Index])) { section.Service.Index = int.Parse(Context.Parameters[Argument.Index], CultureInfo.InvariantCulture); } if (!string.IsNullOrEmpty(Context.Parameters[Argument.StatusPort])) { int port = Convert.ToInt32(Context.Parameters[Argument.StatusPort], CultureInfo.InvariantCulture); section.Service.StatusPort = port; if (port != 0) { FirewallTools.OpenPort(port, "FileService Status"); } } if (!string.IsNullOrEmpty(Context.Parameters[Argument.LocalDb])) { section.Service.LocalDB = Context.Parameters[Argument.LocalDb]; } if (!string.IsNullOrEmpty(Context.Parameters[Argument.LocalRoute])) { section.Service.LocalRoute = Context.Parameters[Argument.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.Service.LocalRoute = ip; } if (!string.IsNullOrEmpty(Context.Parameters[Argument.Mbus])) { section.Service.MBus = Context.Parameters[Argument.Mbus]; } if (!string.IsNullOrEmpty(Context.Parameters[Argument.MigrationNfs])) { section.Service.MigrationNFS = Context.Parameters[Argument.MigrationNfs]; } if (!string.IsNullOrEmpty(Context.Parameters[Argument.NodeId])) { section.Service.NodeId = Context.Parameters[Argument.NodeId]; } if (!string.IsNullOrEmpty(Context.Parameters[Argument.ZInterval])) { section.Service.ZInterval = int.Parse(Context.Parameters[Argument.ZInterval], CultureInfo.InvariantCulture); } if (!string.IsNullOrEmpty(Context.Parameters[Argument.Plan])) { section.Service.Plan = Context.Parameters[Argument.Plan]; } if (!string.IsNullOrEmpty(Context.Parameters[Argument.UseVhd])) { section.Service.Uhurufs.UseVHD = bool.Parse(Context.Parameters[Argument.UseVhd]); } if (!string.IsNullOrEmpty(Context.Parameters[Argument.MaxStorageSize])) { section.Service.Uhurufs.MaxStorageSize = long.Parse(Context.Parameters[Argument.MaxStorageSize], CultureInfo.InvariantCulture); } if (!string.IsNullOrEmpty(Context.Parameters[Argument.VhdFixedSize])) { section.Service.Uhurufs.VHDFixedSize = bool.Parse(Context.Parameters[Argument.VhdFixedSize]); } section.DEA = null; config.Save(); int lowPort = 5000; int highPort = 6000; using (ServerManager serverManager = new ServerManager()) { Microsoft.Web.Administration.Configuration iisConfig = serverManager.GetApplicationHostConfiguration(); Microsoft.Web.Administration.ConfigurationSection firewallSupportSection = iisConfig.GetSection("system.ftpServer/firewallSupport"); firewallSupportSection["lowDataChannelPort"] = lowPort; firewallSupportSection["highDataChannelPort"] = highPort; Microsoft.Web.Administration.ConfigurationSection sitesSection = iisConfig.GetSection("system.applicationHost/sites"); Microsoft.Web.Administration.ConfigurationElement siteDefaultsElement = sitesSection.GetChildElement("siteDefaults"); Microsoft.Web.Administration.ConfigurationElement ftpServerElement = siteDefaultsElement.GetChildElement("ftpServer"); Microsoft.Web.Administration.ConfigurationElement firewallSupportElement = ftpServerElement.GetChildElement("firewallSupport"); firewallSupportElement["externalIp4Address"] = @"0.0.0.0"; serverManager.CommitChanges(); } FirewallTools.OpenPortRange(lowPort, highPort, "UhuruFS Ports"); }