Added XFF header processing. Untested, for lack of proxy.

prebuild-update
Diva Canto 2010-09-03 17:18:53 -07:00
parent 107052b23d
commit 8fc68c6d98
6 changed files with 49 additions and 3 deletions

View File

@ -28,6 +28,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Net.Sockets;
@ -737,6 +738,7 @@ namespace OpenSim.Framework.Servers.HttpServer
if (methodWasFound)
{
xmlRprcRequest.Params.Add(request.Url); // Param[2]
xmlRprcRequest.Params.Add(request.Headers.Get("X-Forwarded-For")); // Param[3]
try
{

View File

@ -1495,5 +1495,33 @@ namespace OpenSim.Framework
}
}
/// <summary>
/// Gets the client IP address
/// </summary>
/// <param name="xff"></param>
/// <returns></returns>
public static IPEndPoint GetClientIPFromXFF(string xff)
{
if (xff == string.Empty)
return null;
string[] parts = xff.Split(new char[] { ',' });
if (parts.Length > 0)
{
try
{
return new IPEndPoint(IPAddress.Parse(parts[0]), 0);
}
catch (Exception e)
{
m_log.WarnFormat("[UTIL]: Exception parsing XFF header {0}: {1}", xff, e.Message);
}
}
return null;
}
}
}

View File

@ -52,15 +52,24 @@ namespace OpenSim.Server.Handlers.Login
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private ILoginService m_LocalService;
private bool m_Proxy;
public LLLoginHandlers(ILoginService service)
public LLLoginHandlers(ILoginService service, bool hasProxy)
{
m_LocalService = service;
m_Proxy = hasProxy;
}
public XmlRpcResponse HandleXMLRPCLogin(XmlRpcRequest request, IPEndPoint remoteClient)
{
Hashtable requestData = (Hashtable)request.Params[0];
if (m_Proxy && request.Params[3] != null)
{
IPEndPoint ep = Util.GetClientIPFromXFF((string)request.Params[3]);
if (ep != null)
// Bang!
remoteClient = ep;
}
if (requestData != null)
{
@ -189,6 +198,7 @@ namespace OpenSim.Server.Handlers.Login
return map;
}
}
}

View File

@ -43,6 +43,7 @@ namespace OpenSim.Server.Handlers.Login
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private ILoginService m_LoginService;
private bool m_Proxy;
public LLLoginServiceInConnector(IConfigSource config, IHttpServer server, IScene scene) :
base(config, server, String.Empty)
@ -81,12 +82,14 @@ namespace OpenSim.Server.Handlers.Login
if (loginService == string.Empty)
throw new Exception(String.Format("No LocalServiceModule for LoginService in config file"));
m_Proxy = serverConfig.GetBoolean("HasProxy", false);
return loginService;
}
private void InitializeHandlers(IHttpServer server)
{
LLLoginHandlers loginHandlers = new LLLoginHandlers(m_LoginService);
LLLoginHandlers loginHandlers = new LLLoginHandlers(m_LoginService, m_Proxy);
server.AddXmlRPCHandler("login_to_simulator", loginHandlers.HandleXMLRPCLogin, false);
server.AddXmlRPCHandler("set_login_level", loginHandlers.HandleXMLRPCSetLoginLevel, false);
server.SetDefaultLLSDHandler(loginHandlers.HandleLLSDLogin);

View File

@ -104,7 +104,7 @@ namespace OpenSim.Services.LLLoginService
m_GatekeeperURL = m_LoginServerConfig.GetString("GatekeeperURI", string.Empty);
m_MapTileURL = m_LoginServerConfig.GetString("MapTileURL", string.Empty);
m_SearchURL = m_LoginServerConfig.GetString("SearchURL", string.Empty);
// These are required; the others aren't
if (accountService == string.Empty || authService == string.Empty)
throw new Exception("LoginService is missing service specifications");

View File

@ -147,6 +147,9 @@ ServiceConnectors = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector,8003
WelcomeMessage = "Welcome, Avatar!"
AllowRemoteSetLoginLevel = "false"
; If you run this login server behind a proxy, set this to true
; HasProxy = true
; Defaults for the users, if none is specified in the useraccounts table entry (ServiceURLs)
; CHANGE THIS
HomeURI = "http://127.0.0.1:8002"