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 HttpGetRedirects(HttpContext context, DomainSetting domain) { return(new Status200Result <List <RedirectTargetWithAddress> >( domain.Redirects.Select(i => new RedirectTargetWithAddress(i.Key, i.Value)) .OrderBy(i => i.Address, domain.IgnoreCaseWhenMatching ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal) .ToList())); }
static OtherResult HttpUpdateDomainDefaultTarget(HttpContext context, DomainSetting domain) { var target = context.GetQueryTextParameter("Target"); var permanent = context.GetQueryBooleanParameter("Permanent"); var queryProcess = context.GetQueryBooleanParameter("QueryProcess"); domain.DefaultTarget.Update(target, permanent, queryProcess); SettingHost.SaveSetting(); return(new Status200Result <RedirectTarget>(domain.DefaultTarget)); }
static OtherResult HttpGetDomainSetting(HttpContext context, DomainSetting domain) { return(new Status200Result <PerDomainSetting>(new PerDomainSetting { DefaultTarget = domain.DefaultTarget, ManagementKey = domain.ManagementKey, IgnoreCaseWhenMatching = domain.IgnoreCaseWhenMatching //, //IsHttps = context.Request.IsHttps })); }
public static DomainSetting CreateEmpty(string managementKey = DefaultManagementKey) { var item = new DomainSetting { ManagementKey = managementKey, DefaultTarget = RedirectTarget.CreateEmpty(), IgnoreCaseWhenMatching = true, Redirects = new Dictionary <string, RedirectTarget>(StringComparer.OrdinalIgnoreCase) }; return(item); }
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 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")); } }
public static DomainSetting CreateDefaultRecord() { var item = new DomainSetting { ManagementKey = DefaultManagementKey, DefaultTarget = RedirectTarget.CreateDefault(), IgnoreCaseWhenMatching = true, Redirects = new Dictionary <string, RedirectTarget>(StringComparer.OrdinalIgnoreCase) { [RedirectTarget.DefaultRecordKey] = RedirectTarget.CreateDefaultRecord(), [RedirectTarget.DefaultRecordKey2] = RedirectTarget.CreateDefaultRecord2() } }; return(item); }
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()); } }
public static ServiceSetting CreateDefault() { var item = new ServiceSetting { //KestrelUrl = "http://localhost:40020", EnableStaticFiles = true, PreferXForwardedHost = true, DefaultTarget = RedirectTarget.CreateDefault(), GlobalManagementKey = DefaultGlobalManagementKey, GlobalManagementEnabledHosts = new HashSet <string>(StringComparer.OrdinalIgnoreCase), Domains = new Dictionary <string, DomainSetting>(StringComparer.OrdinalIgnoreCase) { [DomainSetting.DefaultRecordKey] = DomainSetting.CreateDefaultRecord() }, Aliases = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { ["localhost:8088"] = "localhost" } }; return(item); }
public static OtherResult DomainManage(HttpContext context, DomainSetting domain) { var verb = context.GetQueryOptionalTextParameter("Verb"); if (verb != null && verbs.TryGetValue(verb, out var process)) { return(process(context, domain)); } else { #if DEBUG string data = File.ReadAllText(HtmlFileName); #else if (!html.TryGetTarget(out var data)) { data = File.ReadAllText(HtmlFileName); html.SetTarget(data); } #endif return(new Status200Result(data, "text/html")); } }
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()); } }