Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site: GetUserIP() returns an IPv4 if present #1363

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zero-K.info/Controllers/ForumController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public ActionResult SubmitPost(
forumPostID == null && string.IsNullOrWhiteSpace(title)) return Content("Cannot post new thread with blank title");
if (string.IsNullOrWhiteSpace(text)) return Content("Please type some text :)");

var penalty = Punishment.GetActivePunishment(Global.AccountID, Request.ServerVariables["REMOTE_ADDR"], 0, x => x.BanForum);
var penalty = Punishment.GetActivePunishment(Global.AccountID, MvcApplication.GetUserIP(Request), 0, x => x.BanForum);
if (penalty != null)
{
return
Expand Down
13 changes: 11 additions & 2 deletions Zero-K.info/Global.asax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
Expand Down Expand Up @@ -102,8 +103,16 @@ protected void Application_Start()

private string GetUserIP()
{
var ip = Context.Request.ServerVariables["REMOTE_ADDR"];
return ip;
return GetUserIP(new HttpRequestWrapper(Context.Request));
}

public static string GetUserIP(HttpRequestBase request)
{
string hostname = request.ServerVariables["REMOTE_HOST"];
IPAddress[] ipv4s = Array.FindAll(Dns.GetHostEntry(hostname).AddressList,
a => a.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork);
if (ipv4s.Length > 0) return ipv4s[0].ToString();
return request.ServerVariables["REMOTE_ADDR"];
}

private void MvcApplication_Error(object sender, EventArgs e)
Expand Down