static OtherResult HttpAddDomain(HttpContext context) { string domainName = context.GetQueryTextParameter("DomainName"); if (SettingHost.ServiceSetting.Aliases.ContainsKey(domainName)) { return(new Status409Result()); } var domain = DomainSetting.CreateEmpty(); if (SettingHost.ServiceSetting.Domains.TryAdd(domainName, domain)) { SettingHost.SaveSetting(); return(new Status200Result <DomainRecord>(new DomainRecord { DomainName = domainName, ManagementKey = domain.ManagementKey })); } else { return(new Status409Result()); } }
static OtherResult HttpAddGlobalManagementEnabledHost(HttpContext context) { var hostName = context.GetQueryTextParameter("HostName"); if (SettingHost.ServiceSetting.GlobalManagementEnabledHosts.Count == 0) { var currentHost = context.GetHost(); if (string.Equals(hostName, currentHost, StringComparison.OrdinalIgnoreCase)) { SettingHost.ServiceSetting.GlobalManagementEnabledHosts.Add(hostName); SettingHost.SaveSetting(); return(new Status204Result()); } else { return(new Status406Result()); } } else if (SettingHost.ServiceSetting.GlobalManagementEnabledHosts.Add(hostName)) { SettingHost.SaveSetting(); return(new Status204Result()); } else { return(new Status409Result()); } }
static OtherResult HttpUpdateGlobalDefaultTarget(HttpContext context) { var target = context.GetQueryTextParameter("Target"); var permanent = context.GetQueryBooleanParameter("Permanent"); var queryProcess = context.GetQueryBooleanParameter("QueryProcess"); SettingHost.ServiceSetting.DefaultTarget.Update(target, permanent, queryProcess); SettingHost.SaveSetting(); return(new Status200Result <RedirectTarget>(SettingHost.ServiceSetting.DefaultTarget)); }
static OtherResult HttpRemoveAlias(HttpContext context) { string alias = context.GetQueryTextParameter("Alias"); if (SettingHost.ServiceSetting.Aliases.Remove(alias)) { SettingHost.SaveSetting(); return(new Status204Result()); } else { return(new Status410Result()); } }
static OtherResult HttpRemoveDomain(HttpContext context) { string domainName = context.GetQueryTextParameter("DomainName"); if (SettingHost.ServiceSetting.Domains.Remove(domainName)) { SettingHost.SaveSetting(); return(new Status204Result()); } else { return(new Status410Result()); } }
static OtherResult HttpRemoveRedirect(HttpContext context, DomainSetting domain) { var address = context.GetQueryTextParameter("Address"); if (domain.Redirects.Remove(address)) { SettingHost.SaveSetting(); return(new Status204Result()); } else { return(new Status410Result()); } }
static OtherResult HttpUpdateGlobalManagementKey(HttpContext context) { var key = context.GetQueryTextParameter("Key"); if (key == SettingHost.ServiceSetting.GlobalManagementKey) { return(new Status204Result()); } else { SettingHost.ServiceSetting.GlobalManagementKey = key; SettingHost.SaveSetting(); return(new Status200Result(key, "text/plain")); } }
static OtherResult HttpUpdateDomainManagementKey(HttpContext context, DomainSetting domain) { var key = context.GetQueryTextParameter("Key"); if (key == domain.ManagementKey) { return(new Status204Result()); } else { domain.ManagementKey = key; SettingHost.SaveSetting(); return(new Status200Result(key, "text/plain")); } }
static OtherResult HttpUpdateAlias(HttpContext context) { string alias = context.GetQueryTextParameter("Alias"); string target = context.GetQueryTextParameter("Target"); string newAlias = context.GetQueryTextParameter("NewAlias"); if (newAlias != null && newAlias != alias) { //Change alias key if (SettingHost.ServiceSetting.Domains.ContainsKey(newAlias) || SettingHost.ServiceSetting.Aliases.ContainsKey(newAlias)) { return(new Status409Result()); } else if (SettingHost.ServiceSetting.Aliases.Remove(alias)) { SettingHost.ServiceSetting.Aliases[newAlias] = target; SettingHost.SaveSetting(); return(new Status200Result <AliasRecord>(new AliasRecord { Alias = newAlias, Target = target })); } else { return(new Status410Result()); } } else if (SettingHost.ServiceSetting.Aliases.TryUpdate(alias, target)) { SettingHost.SaveSetting(); return(new Status200Result <AliasRecord>(new AliasRecord { Alias = alias, Target = target })); } else { return(new Status410Result()); } }
static OtherResult HttpAddRedirect(HttpContext context, DomainSetting domain) { var address = context.GetQueryTextParameter("Address"); var target = context.GetQueryTextParameter("Target"); var permanent = context.GetQueryBooleanParameter("Permanent"); var queryProcess = context.GetQueryBooleanParameter("QueryProcess"); var redirect = RedirectTarget.Create(target, permanent, queryProcess); if (domain.Redirects.TryAdd(address, redirect)) { SettingHost.SaveSetting(); return(new Status200Result <RedirectTargetWithAddress>(new RedirectTargetWithAddress(address, redirect))); } else { return(new Status409Result()); } }
static OtherResult HttpUpdateIgnoreCaseWhenMatching(HttpContext context, DomainSetting domain) { var ignoreCase = context.GetQueryBooleanParameter("IgnoreCase"); if (ignoreCase == domain.IgnoreCaseWhenMatching) { return(new Status204Result()); } var result = domain.UpdateIgnoreCaseWhenMatching(ignoreCase); SettingHost.SaveSetting(); if (result) { return(new Status205Result()); } else { return(new Status204Result()); } }
static OtherResult HttpRemoveGlobalManagementEnabledHost(HttpContext context) { var hostName = context.GetQueryTextParameter("HostName"); if (SettingHost.ServiceSetting.GlobalManagementEnabledHosts.Count == 1) { var currentHost = context.GetHost(); if (string.Equals(hostName, currentHost, StringComparison.OrdinalIgnoreCase)) //The last one must be the currentHost, or this method will not be called. { SettingHost.ServiceSetting.GlobalManagementEnabledHosts.Clear(); SettingHost.SaveSetting(); return(new Status204Result()); } else { return(new Status410Result()); } } else if (SettingHost.ServiceSetting.GlobalManagementEnabledHosts.Count == 0) { return(new Status410Result()); } else // Count > 1 { var currentHost = context.GetHost(); if (string.Equals(hostName, currentHost, StringComparison.OrdinalIgnoreCase)) { return(new Status406Result()); } else if (SettingHost.ServiceSetting.GlobalManagementEnabledHosts.Remove(hostName)) { SettingHost.SaveSetting(); return(new Status204Result()); } else { return(new Status410Result()); } } }
static OtherResult HttpUpdateRedirect(HttpContext context, DomainSetting domain) { var address = context.GetQueryTextParameter("Address"); var newAddress = context.GetQueryOptionalTextParameter("NewAddress"); var target = context.GetQueryTextParameter("Target"); var permanent = context.GetQueryBooleanParameter("Permanent"); var queryProcess = context.GetQueryBooleanParameter("QueryProcess"); if (newAddress != null && newAddress != address) { //Change domain name if (domain.Redirects.ContainsKey(newAddress)) { return(new Status409Result()); } else if (domain.Redirects.Remove(address)) { var redirect = RedirectTarget.Create(target, permanent, queryProcess); domain.Redirects.Add(newAddress, redirect); SettingHost.SaveSetting(); return(new Status200Result <RedirectTargetWithAddress>(new RedirectTargetWithAddress(address, redirect))); } else { return(new Status410Result()); } } else if (domain.Redirects.TryGetValue(address, out RedirectTarget redirect)) { redirect.Update(target, permanent, queryProcess); SettingHost.SaveSetting(); return(new Status200Result <RedirectTargetWithAddress>(new RedirectTargetWithAddress(address, redirect))); } else { return(new Status410Result()); } }
static OtherResult HttpAddAlias(HttpContext context) { string alias = context.GetQueryTextParameter("Alias"); string target = context.GetQueryTextParameter("Target"); if (SettingHost.ServiceSetting.Domains.ContainsKey(alias)) { return(new Status409Result()); } if (SettingHost.ServiceSetting.Aliases.TryAdd(alias, target)) { SettingHost.SaveSetting(); return(new Status200Result <AliasRecord>(new AliasRecord { Alias = alias, Target = target })); } else { return(new Status409Result()); } }