Rewrote all async ASP.Net calls in Init to jQuery $.ajax() instead; works in dev environment now (again); deploying to Mono staging
This commit is contained in:
@@ -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 @@
|
||||
</div>
|
||||
<div id="DivDatabaseWritable" style="display:none">
|
||||
<h2>Connect to database</h2>
|
||||
<p>Before you fill this in, you will need to have created a database on a MySQL server that this web server can access, and set up user accounts that can access it. For security reasons, we <strong>require</strong> having three separate accounts - one for reading (SELECT permissions only), one for writing (SELECT and EXECUTE), and one for admin. All three accounts also need SELECT permissions on the mysql database.</p>
|
||||
<p>Before you fill this in, you will need to have created a database on a MySQL server that this web server can access, and set up user accounts that can access it. For security reasons, we <strong>require</strong> having three separate accounts - one for reading (SELECT permissions only), one for writing (SELECT and EXECUTE), and one for admin. All three accounts also need SELECT permissions on the mysql database.</p>
|
||||
|
||||
<div class="entryLabelsAdmin" style="width:120px">
|
||||
<br/>
|
||||
Database<br />
|
||||
Server<br />
|
||||
User<br/>
|
||||
Password
|
||||
</div>
|
||||
<div class="entryFieldsAdmin" style="width:80px">
|
||||
<strong>Read access</strong><br/>
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsReadDatabase" runat="server" /> <br />
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsReadServer" runat="server" /> <br />
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsReadUser" runat="server" /> <br />
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsReadPassword" TextMode="Password" runat="server" /> <br />
|
||||
</div>
|
||||
<div class="entryFieldsAdmin" style="width:80px;margin-left:10px">
|
||||
<strong>Write access</strong><br/>
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsWriteDatabase" runat="server" /> <br />
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsWriteServer" runat="server" /> <br />
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsWriteUser" runat="server" /> <br />
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsWritePassword" TextMode="Password" runat="server" /> <br />
|
||||
</div>
|
||||
<div class="entryFieldsAdmin" style="width:80px;margin-left:10px">
|
||||
<strong>Admin access</strong><br/>
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsAdminDatabase" runat="server" /> <br />
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsAdminServer" runat="server" /> <br />
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsAdminUser" runat="server" /> <br />
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsAdminPassword" TextMode="Password" runat="server" /> <br />
|
||||
</div>
|
||||
<div style="display:none">
|
||||
<asp:UpdatePanel runat="server" ID="UpdateFinished" UpdateMode="Conditional">
|
||||
<ContentTemplate>
|
||||
<asp:Button ID="ButtonInitDatabase" OnClick="ButtonInitDatabase_Click" runat="server" Text="You should not see this button" />
|
||||
<asp:Button ID="ButtonTestCredentials" OnClick="ButtonTestCredentials_Click" runat="server" Text="You should not see this button" />
|
||||
</ContentTemplate>
|
||||
<Triggers>
|
||||
<asp:AsyncPostBackTrigger ControlID="ButtonInitDatabase" />
|
||||
<asp:AsyncPostBackTrigger ControlID="ButtonTestCredentials" />
|
||||
</Triggers>
|
||||
</asp:UpdatePanel>
|
||||
</div>
|
||||
<div class="entryLabelsAdmin" style="width:120px">
|
||||
<br/>
|
||||
Database<br />
|
||||
Server<br />
|
||||
User<br/>
|
||||
Password
|
||||
</div>
|
||||
<div class="entryFieldsAdmin" style="width:80px">
|
||||
<strong>Read access</strong><br/>
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsReadDatabase" runat="server" /> <br />
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsReadServer" runat="server" /> <br />
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsReadUser" runat="server" /> <br />
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsReadPassword" TextMode="Password" runat="server" /> <br />
|
||||
</div>
|
||||
<div class="entryFieldsAdmin" style="width:80px;margin-left:10px">
|
||||
<strong>Write access</strong><br/>
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsWriteDatabase" runat="server" /> <br />
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsWriteServer" runat="server" /> <br />
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsWriteUser" runat="server" /> <br />
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsWritePassword" TextMode="Password" runat="server" /> <br />
|
||||
</div>
|
||||
<div class="entryFieldsAdmin" style="width:80px;margin-left:10px">
|
||||
<strong>Admin access</strong><br/>
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsAdminDatabase" runat="server" /> <br />
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsAdminServer" runat="server" /> <br />
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsAdminUser" runat="server" /> <br />
|
||||
<asp:TextBox CssClass="textinput" ID="TextCredentialsAdminPassword" TextMode="Password" runat="server" /> <br />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="step-3">
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user