Improvements to GeoIP guesser
This commit is contained in:
@@ -47,6 +47,7 @@ namespace Swarmops.Logic.Cache
|
||||
_cache.Remove (guidString);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void ConditionalGarbageCollect()
|
||||
{
|
||||
|
||||
@@ -40,10 +40,10 @@ namespace Swarmops.Logic.Support
|
||||
public static string GetRemoteIPAddressChain()
|
||||
{
|
||||
string forwardedIps =
|
||||
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
|
||||
HttpContext.Current.Request.Headers ["X-Forwarded-For"];
|
||||
|
||||
string directIp =
|
||||
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
|
||||
string directIp =
|
||||
HttpContext.Current.Request.UserHostAddress; // may be IPv4 or IPv6
|
||||
|
||||
string result = directIp;
|
||||
|
||||
@@ -59,7 +59,9 @@ namespace Swarmops.Logic.Support
|
||||
// ReSharper disable once InconsistentNaming -- IPAddress is the canonical writing
|
||||
public static string GetMostLikelyRemoteIPAddress()
|
||||
{
|
||||
// All of this can be faked trivially by the client, so you can't rely on it for any kind of security.
|
||||
// All of this can be faked trivially by the client, so we can't rely on it for any kind of security.
|
||||
// While it is possible to set up a server environment that strips out such fakes, doing so should not
|
||||
// be a requirement for running Swarmops.
|
||||
|
||||
string forwardedIps =
|
||||
HttpContext.Current.Request.Headers["X-Forwarded-For"];
|
||||
|
||||
@@ -20,5 +20,6 @@ namespace Swarmops.Logic.Support.LogEntries
|
||||
/// </summary>
|
||||
public DateTime DateTime { get; set; }
|
||||
public int ActingPersonId { get; set; }
|
||||
public string ActingIPAddress { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Swarmops.Logic.Swarm;
|
||||
using Swarmops.Logic.Support;
|
||||
|
||||
namespace Swarmops.Logic.Support.LogEntries
|
||||
{
|
||||
@@ -21,6 +23,10 @@ namespace Swarmops.Logic.Support.LogEntries
|
||||
DateTime = System.DateTime.UtcNow;
|
||||
ParticipationId = participation.Identity;
|
||||
ActingPersonId = actingPerson.Identity;
|
||||
if (HttpContext.Current != null)
|
||||
{
|
||||
ActingIPAddress = SupportFunctions.GetRemoteIPAddressChain();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace Swarmops.Logic.Support
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Persistence Key
|
||||
{
|
||||
get { return new Persistence(); }
|
||||
|
||||
+2
-2
@@ -36,6 +36,8 @@
|
||||
|
||||
string[] rewriteCandidates =
|
||||
{
|
||||
"{0}/Dashboard.aspx", // for dev.swarmops.com -- Dashboard overrides Default in root, if it exists
|
||||
"{0}Dashboard.aspx", // for dev.swarmops.com/ -- Dashboard overrides Default in root, if it exists
|
||||
"{0}/Default.aspx", // for dev.swarmops.com
|
||||
"{0}Default.aspx", // for dev.swarmops.com/
|
||||
"{0}.aspx", // for dev.swarmops.com/Security/Login
|
||||
@@ -60,8 +62,6 @@
|
||||
{
|
||||
// Set default roles (none)
|
||||
|
||||
string[] userRoles = new string[0];
|
||||
|
||||
// ----------- SET ROLES -----------
|
||||
|
||||
// Determine logged-on user (FormsAuthentication)
|
||||
|
||||
@@ -134,16 +134,14 @@
|
||||
SwarmopsJS.ajaxCall("/Pages/v5/Public/Signup.aspx/GuessCountry", {}, function(result) {
|
||||
if (result.Success && result.DisplayMessage.length > 0) {
|
||||
$('#<%=this.DropCountries.ClientID%>').val(result.DisplayMessage);
|
||||
UpdatePostalPrefix('XX', result.DisplayMessage);
|
||||
} else {
|
||||
// No dice for some reason - initialize postal codes with default lookup
|
||||
// (the change-of-field in the success scenario triggers this in that case)
|
||||
UpdatePostalPrefix('XX', $('#<%= DropCountries.ClientID %>').val());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
$('#<%= TextPostal.ClientID %>').on('input', function () {
|
||||
if (CheckPostalCode()) {
|
||||
if ($('#<%= TextPostal.ClientID %>').val().length == postalCodeLength) {
|
||||
@@ -622,7 +620,7 @@
|
||||
<asp:Label ID="LabelDateOfBirth" runat="server" /><br />
|
||||
<asp:Label ID="LabelLegalGender" runat="server" /><br />
|
||||
</div>
|
||||
<div class="entryFieldsAdmin">
|
||||
<div class="entryFieldsAdmin" style="width:204px">
|
||||
<asp:TextBox runat="server" ID="TextName" />​<br/>
|
||||
<asp:DropDownList runat="server" ID="DropCountries"/>​<br/>
|
||||
<asp:TextBox runat="server" ID="TextMail" />​<br/>
|
||||
|
||||
@@ -20,6 +20,7 @@ using Swarmops.Logic.Structure;
|
||||
using Swarmops.Logic.Support;
|
||||
using Swarmops.Logic.Support.LogEntries;
|
||||
using Swarmops.Logic.Swarm;
|
||||
using Swarmops.Logic.Cache;
|
||||
|
||||
namespace Swarmops.Frontend.Pages.Public
|
||||
{
|
||||
@@ -299,18 +300,27 @@ namespace Swarmops.Frontend.Pages.Public
|
||||
{
|
||||
string ipAddress = Logic.Support.SupportFunctions.GetMostLikelyRemoteIPAddress();
|
||||
|
||||
NGeoIP.RawData rawData = (NGeoIP.RawData) GuidCache.Get(ipAddress);
|
||||
|
||||
Persistence.Key["DebugData"] = HttpContext.Current.Request.ToRaw();
|
||||
|
||||
NGeoIP.Request request = new Request()
|
||||
if (rawData == null)
|
||||
{
|
||||
Format = Format.Json,
|
||||
IP = ipAddress
|
||||
};
|
||||
NGeoClient client = new NGeoClient (request);
|
||||
NGeoIP.RawData rawData = client.Execute();
|
||||
NGeoIP.Request request = new Request()
|
||||
{
|
||||
Format = Format.Json,
|
||||
IP = ipAddress
|
||||
};
|
||||
NGeoClient client = new NGeoClient(request);
|
||||
rawData = client.Execute();
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty (rawData.CountryCode))
|
||||
{
|
||||
// Successful lookup
|
||||
|
||||
GuidCache.Set(ipAddress, rawData); // store lookup results in cache for later
|
||||
|
||||
return new AjaxCallResult {Success = true, DisplayMessage = rawData.CountryCode};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user