diff --git a/Site5/Pages/v5/Init/Default.aspx b/Site5/Pages/v5/Init/Default.aspx index 2862b7a0..b1db0488 100644 --- a/Site5/Pages/v5/Init/Default.aspx +++ b/Site5/Pages/v5/Init/Default.aspx @@ -96,11 +96,11 @@ var textBoxes; var loop; var fieldContents; + var hostName = $('#<%=this.TextServerName.ClientID %>').val(); + var hostAddress = $('#<%=this.TextServerAddress.ClientID %>').val(); if (stepNumber == 1) { // Validate Hostname, Host Address - var hostName = $('#<%=this.TextServerName.ClientID %>').val(); - var hostAddress = $('#<%=this.TextServerAddress.ClientID %>').val(); if (hostName && hostName.length > 0 && hostAddress && hostAddress.length > 0) { $.ajax({ @@ -175,13 +175,27 @@ if (isValid) { DisableNext(); // block Next during synchro call - it may take a while - // also, won't get re-enabled no matter the outcome - $('#<%=this.ButtonTestCredentials.ClientID %>').click(); + // also, won't get re-enabled no matter the outcome + alert('calling now'); $.ajax({ type: "POST", - url: "Default.aspx/TestDatabasePermissions", - data: "{}", + url: "Default.aspx/FirstCredentialsTest", + data: "{" + + "'readDatabase':'" + $('#<%=this.TextCredentialsReadDatabase.ClientID %>').val() + "',"+ + "'readServer':'" + $('#<%=this.TextCredentialsReadServer.ClientID %>').val() + "',"+ + "'readUser':'" + $('#<%=this.TextCredentialsReadUser.ClientID %>').val() + "',"+ + "'readPassword':'" + $('#<%=this.TextCredentialsReadPassword.ClientID %>').val() + "',"+ + "'writeDatabase':'" + $('#<%=this.TextCredentialsWriteDatabase.ClientID %>').val() + "',"+ + "'writeServer':'" + $('#<%=this.TextCredentialsWriteServer.ClientID %>').val() + "',"+ + "'writeUser':'" + $('#<%=this.TextCredentialsWriteUser.ClientID %>').val() + "',"+ + "'writePassword':'" + $('#<%=this.TextCredentialsWritePassword.ClientID %>').val() + "',"+ + "'adminDatabase':'" + $('#<%=this.TextCredentialsAdminDatabase.ClientID %>').val() + "',"+ + "'adminServer':'" + $('#<%=this.TextCredentialsAdminServer.ClientID %>').val() + "',"+ + "'adminUser':'" + $('#<%=this.TextCredentialsAdminUser.ClientID %>').val() + "',"+ + "'adminPassword':'" + $('#<%=this.TextCredentialsAdminPassword.ClientID %>').val() + "',"+ + "'serverName':'" + hostName + "'," + + "'ipAddress':'" + hostAddress +"'}", contentType: "application/json; charset=utf-8", dataType: "json", async: false, // blocks until function returns - race conditions otherwise @@ -205,7 +219,6 @@ $('#DivProgressDatabase').progressbar({ value: 0, max: 100 }); setTimeout('updateInitProgressBar();', 1000); setTimeout('updateInitProgressMessage();', 1500); - $('#<%=this.ButtonInitDatabase.ClientID %>').click(); beginInitDatabase(); DisableNext(); } @@ -401,7 +414,7 @@ $.ajax({ type: "POST", - url: "Default.aspx/TestDatabasePermissions", + url: "Default.aspx/RecheckDatabasePermissions", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", @@ -574,48 +587,36 @@
diff --git a/Site5/Pages/v5/Init/Default.aspx.cs b/Site5/Pages/v5/Init/Default.aspx.cs index e78ce7ee..a2d57313 100644 --- a/Site5/Pages/v5/Init/Default.aspx.cs +++ b/Site5/Pages/v5/Init/Default.aspx.cs @@ -184,57 +184,29 @@ public partial class Pages_v5_Init_Default : System.Web.UI.Page return _buildIdentity; } - protected void ButtonInitDatabase_Click(object sender, EventArgs args) + [WebMethod] + static public PermissionsAnalysis FirstCredentialsTest + (string readDatabase, string readServer, string readUser, string readPassword, + string writeDatabase, string writeServer, string writeUser, string writePassword, + string adminDatabase, string adminServer, string adminUser, string adminPassword, + string serverName, string ipAddress) { - // 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))) + if (!(VerifyHostName(serverName) && VerifyHostAddress(ipAddress))) { if (!System.Diagnostics.Debugger.IsAttached) { - return; // Probable hack attempt - fail silently - } - } - - if (_testReadCredentials == null) - { - throw new InvalidOperationException("Can't init database before it has been tested - invalid state"); - } - - // Store database credentials - - SwarmDb.Configuration.Set( - new SwarmDb.Configuration( - _testReadCredentials, - _testWriteCredentials, - _testAdminCredentials)); - } - - protected void ButtonTestCredentials_Click(object sender, EventArgs args) - { - // 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))) - { - if (!System.Diagnostics.Debugger.IsAttached) - { - return; // Probable hack attempt - fail silently + return null; // Probable hack attempt - fail silently } } _testReadCredentials = new SwarmDb.Credentials( - this.TextCredentialsReadDatabase.Text, - new SwarmDb.ServerSet(this.TextCredentialsReadServer.Text), - this.TextCredentialsReadUser.Text, - this.TextCredentialsReadPassword.Text); - _testWriteCredentials = new SwarmDb.Credentials(this.TextCredentialsWriteDatabase.Text, - new SwarmDb.ServerSet(this.TextCredentialsWriteServer.Text), - this.TextCredentialsWriteUser.Text, - this.TextCredentialsWritePassword.Text); - _testAdminCredentials = new SwarmDb.Credentials(this.TextCredentialsAdminDatabase.Text, - new SwarmDb.ServerSet(this.TextCredentialsAdminServer.Text), - this.TextCredentialsAdminUser.Text, - this.TextCredentialsAdminPassword.Text); + readDatabase, new SwarmDb.ServerSet(readServer), readUser, readPassword); + _testWriteCredentials = new SwarmDb.Credentials( + writeDatabase, new SwarmDb.ServerSet(writeServer), writeUser, writePassword); + _testAdminCredentials = new SwarmDb.Credentials( + adminDatabase, new SwarmDb.ServerSet(adminServer), adminUser, adminPassword); + + return RecheckDatabasePermissions(); // Subsequent tests only call this function } private static SwarmDb.Credentials _testReadCredentials; @@ -252,7 +224,7 @@ public partial class Pages_v5_Init_Default : System.Web.UI.Page [WebMethod(true)] - public static PermissionsAnalysis TestDatabasePermissions() + public static PermissionsAnalysis RecheckDatabasePermissions() { while (_testReadCredentials == null || _testWriteCredentials == null || _testAdminCredentials == null) { @@ -372,6 +344,14 @@ public partial class Pages_v5_Init_Default : System.Web.UI.Page throw new InvalidOperationException("Cannot re-initialize database"); } + // Store database credentials + + SwarmDb.Configuration.Set( + new SwarmDb.Configuration( + _testReadCredentials, + _testWriteCredentials, + _testAdminCredentials)); + // Start an async thread that does all the work, then return Thread initThread = new Thread(InitDatabaseThread);