From e34ab252237778d53614217fd609b5c44e9383ff Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Mon, 21 Mar 2016 08:25:22 +0100 Subject: [PATCH] Added Force-SSL switch to System Settings --- Site5/Pages/v5/Admin/OrgSettings.aspx | 2 +- Site5/Pages/v5/Admin/SystemSettings.aspx | 91 ++++++++++++++++++++- Site5/Pages/v5/Admin/SystemSettings.aspx.cs | 61 ++++++++++++++ Site5/Pages/v5/Public/Initialize.aspx.cs | 20 ----- 4 files changed, 152 insertions(+), 22 deletions(-) diff --git a/Site5/Pages/v5/Admin/OrgSettings.aspx b/Site5/Pages/v5/Admin/OrgSettings.aspx index 782927ab..56202021 100644 --- a/Site5/Pages/v5/Admin/OrgSettings.aspx +++ b/Site5/Pages/v5/Admin/OrgSettings.aspx @@ -5,11 +5,11 @@ <%@ Register tagPrefix="Swarmops5" tagName="AjaxTextBox" src="~/Controls/v5/Base/AjaxTextBox.ascx" %> - + + + +
+
+

System Behavior

+
+

+
+ +

diff --git a/Site5/Pages/v5/Admin/SystemSettings.aspx.cs b/Site5/Pages/v5/Admin/SystemSettings.aspx.cs index b3032771..7bd70633 100644 --- a/Site5/Pages/v5/Admin/SystemSettings.aspx.cs +++ b/Site5/Pages/v5/Admin/SystemSettings.aspx.cs @@ -145,6 +145,54 @@ namespace Swarmops.Frontend.Pages.v5.Admin this.LabelWebsocketPortClient.Text = Resources.Pages.Admin.SystemSettings_WebsocketPortClient; } + + + [WebMethod] + public static InitialSystemData GetInitialData() + { + InitialSystemData result = new InitialSystemData(); + AuthenticationData authData = GetAuthenticationDataAndCulture(); + Organization org = authData.CurrentOrganization; + + if (org == null || authData.CurrentUser == null) + { + return result; // just... don't + } + + result.RequireSsl = SystemSettings.RequireSsl; + + return result; + } + + + [WebMethod] + public static CallResult SwitchToggled(string switchName, bool switchValue) + { + AuthenticationData authData = GetAuthenticationDataAndCulture(); + + if (authData.CurrentOrganization == null || authData.CurrentUser == null) + { + return null; // just don't... don't anything, actually + } + + CallResult result = new CallResult(); + result.Success = true; + result.DisplayMessage = string.Empty; + + switch (switchName) + { + case "RequireSsl": + + SystemSettings.RequireSsl = switchValue; + break; + default: + throw new NotImplementedException(); + } + + return result; + } + + [WebMethod] static public AjaxTextBox.CallbackResult StoreCallback(string newValue, string cookie) { @@ -282,6 +330,19 @@ namespace Swarmops.Frontend.Pages.v5.Admin } + + public class CallResult + { + public bool Success { get; set; } + public string OpResult { get; set; } + public string DisplayMessage { get; set; } + } + + + public class InitialSystemData + { + public bool RequireSsl; + } } } \ No newline at end of file diff --git a/Site5/Pages/v5/Public/Initialize.aspx.cs b/Site5/Pages/v5/Public/Initialize.aspx.cs index cf299e30..67dddc10 100644 --- a/Site5/Pages/v5/Public/Initialize.aspx.cs +++ b/Site5/Pages/v5/Public/Initialize.aspx.cs @@ -409,8 +409,6 @@ namespace Swarmops.Frontend.Pages.v5.Public /// public static void InitDatabaseThread() { - SwarmopsLog.DebugLog("Initializing Database"); - // Ignore the session object, that method of sharing data didn't work, but a static variable did. _initProgress = 1; @@ -443,8 +441,6 @@ namespace Swarmops.Frontend.Pages.v5.Public Persistence.Key["SwarmopsInstallationId"] = Guid.NewGuid().ToString(); - SwarmopsLog.DebugLog(" - creating currencies"); - _initProgress = 4; _initMessage = "Initializing currencies..."; @@ -555,7 +551,6 @@ namespace Swarmops.Frontend.Pages.v5.Public { // Use initMessage to push info about what went wrong to the user - SwarmopsLog.DebugLog (failedException.ToString()); _initMessage = failedException.ToString(); } @@ -694,8 +689,6 @@ namespace Swarmops.Frontend.Pages.v5.Public try { - SwarmopsLog.DebugLog (String.Format ("Creating first user: '{0}', '{1}', '{2}'", name, mail, password)); - Person personOne = null; bool personOneExists = false; @@ -729,18 +722,12 @@ namespace Swarmops.Frontend.Pages.v5.Public throw new InvalidOperationException ("Cannot run initialization processes again when initialized."); } - SwarmopsLog.DebugLog ("- person one did not exist, creating"); - Person newPerson = Person.Create (name, mail, password, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, DateTime.MinValue, PersonGender.Unknown); - SwarmopsLog.DebugLog ("- adding participation in Sandbox"); - newPerson.AddParticipation (Organization.Sandbox, DateTime.MaxValue); // Add membership in Sandbox - SwarmopsLog.DebugLog ("- creating positions"); - // Initialize staffing to System and Sandbox with the new user Positions.CreateSysadminPositions(); @@ -748,7 +735,6 @@ namespace Swarmops.Frontend.Pages.v5.Public } catch (Exception e) { - SwarmopsLog.DebugLog (e.ToString()); throw; } @@ -757,8 +743,6 @@ namespace Swarmops.Frontend.Pages.v5.Public protected void ButtonLogin_Click (object sender, EventArgs args) { - SwarmopsLog.DebugLog("ButtonLogin_Click"); - // Check the host names and addresses again as a security measure - after all, we can be called from outside our intended script if (!(VerifyHostName (this.TextServerName.Text) && VerifyHostAddress (this.TextServerAddress.Text))) @@ -786,13 +770,9 @@ namespace Swarmops.Frontend.Pages.v5.Public // Get authenticated person - SwarmopsLog.DebugLog (" - before calling Authenticate"); - Person expectedPersonOne = Authentication.Authenticate ("1", this.TextFirstUserPassword1.Text); - SwarmopsLog.DebugLog(" - after calling Authenticate"); - if (expectedPersonOne != null) { Authority firstAuthority = Authority.FromLogin(expectedPersonOne, Organization.Sandbox);