public CommonReturnValue AddJsFile(string name) { if (string.IsNullOrWhiteSpace(name) || name.IndexOfAny(System.IO.Path.GetInvalidFileNameChars()) >= 0) { return(CommonReturnValue.UserError("Filenames may not be empty or contain special characters. Valid characters include A to Z and 0 to 9.")); } if (this.JsFiles == null) { this.JsFiles = new List <JsFile>(); } if (!name.ToLower().Trim().EndsWith(".js")) { name = name.Trim() + ".js"; } var existing = this.JsFiles.FirstOrDefault(f => f.Filename.ToLower() == name.ToLower()); if (existing != null) { return(CommonReturnValue.UserError($"The output file '{name}' already exists against this data source.")); } var jsfile = new JsFile(); jsfile.Filename = name; jsfile.Id = ShortId.Generate(); this.JsFiles.Add(jsfile); return(CommonReturnValue.Success()); }
public CommonReturnValue DeleteRule(string ruleId) { var existingRule = this.Rules.FirstOrDefault(r => r?.Id?.Equals(ruleId, StringComparison.Ordinal) ?? false); if (existingRule == null) { return(CommonReturnValue.UserError("The specified rule was not found.")); } this.Rules.Remove(existingRule); return(CommonReturnValue.Success()); }
public CommonReturnValue DeleteEndpoint(string name) { var existing = this.Endpoints.FirstOrDefault(ep => ep.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); if (existing == null) { return(CommonReturnValue.UserError($"The endpoint '{name}' does not exists on the datasource '{this.Name}'")); } this.Endpoints.Remove(existing); return(CommonReturnValue.Success()); }
public CommonReturnValue MayAccessDbSource(string referer, string jsDALApiKey) { if (jsDALApiKey != null) { // TODO: test against some list if (jsDALApiKey.Equals("C50AEA64-951C-45F4-AF8D-539929ACD9EF", StringComparison.OrdinalIgnoreCase)) { return(CommonReturnValue.Success()); } } if (referer != null && referer.Equals("$WEB SOCKETS$")) { return(CommonReturnValue.Success()); } if (this.WhitelistedDomainsCsv == null) { return(CommonReturnValue.UserError("No access list exists.")); } //var referer = req.Headers["Referer"].FirstOrDefault(); var whitelistedIPs = this.WhitelistedDomainsCsv.Split(','); if (referer != null) { if (System.Uri.TryCreate(referer, UriKind.RelativeOrAbsolute, out var refererUri)) { foreach (string en in whitelistedIPs) { if (en.Equals(refererUri.Host, StringComparison.OrdinalIgnoreCase)) { return(CommonReturnValue.Success()); } else if (en.StartsWith("*.")) // wildcard sub-domain { var tld = refererUri.Host.Substring(refererUri.Host.IndexOf(".") + 1); if (en.Substring(2).Equals(tld, StringComparison.OrdinalIgnoreCase)) { return(CommonReturnValue.Success()); } } } } } return(CommonReturnValue.UserError($"The host ({ referer }) is not allowed to access this resource.")); }
public bool GetEndpoint(string name, out Endpoint endpoint, out CommonReturnValue resp) // TODO: Review use of CommonReturnValue here { resp = null; endpoint = this.Endpoints.FirstOrDefault(ep => ep.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); if (endpoint == null) { resp = CommonReturnValue.UserError($"The endpoint '{name}' does not exists on the datasource '{this.Name}'"); } else { resp = CommonReturnValue.Success(); } return(endpoint != null); }
public CommonReturnValue Update(string name, string jsNamespace, int?defaultRuleMode) { if (string.IsNullOrWhiteSpace(name) || name.IndexOfAny(System.IO.Path.GetInvalidFileNameChars()) >= 0) { return(CommonReturnValue.UserError("Application names may not be empty or contain special characters. Valid characters include A to Z and 0 to 9.")); } if (!defaultRuleMode.HasValue) { return(CommonReturnValue.UserError("Please specify the default rule mode.")); } this.Name = name; this.JsNamespace = jsNamespace; this.DefaultRuleMode = defaultRuleMode.Value; return(CommonReturnValue.Success()); }
public CommonReturnValue UpdateEndpoint(string oldName, string newName) { if (string.IsNullOrWhiteSpace(newName)) { return(CommonReturnValue.UserError("Please specify a valid endpoint name.")); } var existing = this.Endpoints.FirstOrDefault(ep => ep.Name.Equals(oldName, StringComparison.OrdinalIgnoreCase)); if (existing == null) { return(CommonReturnValue.UserError($"The endpoint '{oldName}' does not exists on the datasource '{this.Name}'")); } newName = newName.Trim(); existing.Name = newName; return(CommonReturnValue.Success()); }
public CommonReturnValue AddRule(RuleType ruleType, string txt) { BaseRule rule = null; switch (ruleType) // TODO: Check for duplicated rules? { case RuleType.Schema: rule = new SchemaRule(txt); break; case RuleType.Specific: { rule = SpecificRule.FromFullname(txt); } break; case RuleType.Regex: { try { var regexTest = new Regex(txt); } catch (Exception ex) { return(CommonReturnValue.UserError("Invalid regex pattern: " + ex.ToString())); } rule = new RegexRule(txt); break; } default: throw new Exception($"Unsupported rule type: ${ruleType}"); } rule.Id = ShortId.Generate(useNumbers: true, useSpecial: true, length: 6); this.Rules.Add(rule); return(CommonReturnValue.Success()); }
public CommonReturnValue AddEndpoint(string name) { if (string.IsNullOrWhiteSpace(name)) { return(CommonReturnValue.UserError("Please specify a valid endpoint name.")); } name = name.Trim(); if (this.Endpoints.FirstOrDefault(ep => ep.Name.Equals(name, StringComparison.OrdinalIgnoreCase)) != null) { return(CommonReturnValue.UserError($"An endpoint with the name '{name}' already exists on the current data source.")); } var newEP = new Endpoint() { Name = name }; newEP.UpdateParentReferences(this); this.Endpoints.Add(newEP); return(CommonReturnValue.Success()); }
public CommonReturnValue UpdatePluginList(dynamic pluginList) { var oldList = this.Plugins; if (oldList == null) { oldList = new List <string>(); } this.Plugins = new List <string>(); if (pluginList == null) { return(CommonReturnValue.Success()); } foreach (Newtonsoft.Json.Linq.JObject p in pluginList) { bool included = (bool)p["Included"]; Guid g = (Guid)p["Guid"]; if (included) { this.Plugins.Add(g.ToString()); } } ; var newlyEnabled = this.Plugins.Where(p => oldList.FirstOrDefault(x => x.Equals(p, StringComparison.OrdinalIgnoreCase)) == null).Select(g => g.ToLower()); var disabled = oldList.Where(p => this.Plugins.FirstOrDefault(x => x.Equals(p, StringComparison.OrdinalIgnoreCase)) == null).Select(g => g.ToLower()); var ret = PluginLoader.Instance.PluginAssemblies .SelectMany(a => a.Plugins, (pa, plugin) => new { PluginAssembly = pa, PluginInfo = plugin }) .Where(p => p.PluginInfo.Type == PluginType.BackgroundThread || p.PluginInfo.Type == PluginType.ServerMethod) .ToList(); var startList = ret.Where(p => newlyEnabled.Contains(p.PluginInfo.Guid.ToString().ToLower())); var stopList = ret.Where(p => disabled.Contains(p.PluginInfo.Guid.ToString().ToLower())); // START { foreach (var item in startList) { if (item.PluginInfo.Type == PluginType.BackgroundThread) { BackgroundThreadPluginManager.Instance.Register(item.PluginInfo); } else if (item.PluginInfo.Type == PluginType.ServerMethod) { ServerMethodManager.Register(item.PluginAssembly.InstanceId, item.PluginInfo); } } } // STOP { foreach (var item in stopList) { if (item.PluginInfo.Type == PluginType.BackgroundThread) { // TODO: Implement a stop and call for specific EP! BackgroundThreadPluginManager.Instance.StopForApp(this, item.PluginInfo); //BackgroundThreadPluginManager.Instance.Register(item.PluginInfo); } else if (item.PluginInfo.Type == PluginType.ServerMethod) { //ServerMethodManager.Register(item.PluginAssembly.InstanceId, item.PluginInfo); } } } return(CommonReturnValue.Success()); }