Changeset 59dfb4 in indico


Ignore:
Timestamp:
03/17/11 12:33:15 (2 years ago)
Author:
Pedro Ferreira <jose.pedro.ferreira@…>
Branches:
master, burotel, hello-world-walkthrough, ipv6, v0.98-series, v0.98.2, v0.98.3, v0.98b1, v0.98b2, v0.99, 051b2622c51afb171a1dedb46a0df4fbb0cbd02e, d9941f8582b36b24821a11ea5ba16fda6a457fb1
Children:
1f0b21
Parents:
c45d407
git-author:
Pedro Ferreira <jose.pedro.ferreira@…> (03/17/11 12:32:27)
git-committer:
Pedro Ferreira <jose.pedro.ferreira@…> (03/17/11 12:33:15)
Message:

[FIX] getHostIP() now called by services

Location:
indico
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • indico/MaKaC/accessControl.py

    r1125a6 r59dfb4  
    2727from MaKaC.common.contextManager import ContextManager 
    2828from MaKaC.plugins import Observable 
    29  
     29from MaKaC.common.logger import Logger 
    3030 
    3131class AccessController( Persistent, Observable ): 
     
    9292            #return self._fatherProtection 
    9393        except: 
     94            Logger.get('accessController').exception('_getFatherProtection') 
    9495            self._fatherProtection = 0 
    9596            return 0 
  • indico/MaKaC/services/implementation/base.py

    r6328a5 r59dfb4  
    153153    """ 
    154154 
    155     def __init__(self, params, remoteHost, session, req=None): 
     155    def __init__(self, params, session, req): 
    156156        """ 
    157157        Constructor.  Initializes provate variables 
    158158        @param req: HTTP Request provided by the previous layer 
    159159        """ 
    160         RequestHandlerBase.__init__(self) 
    161         self._req = req 
     160        RequestHandlerBase.__init__(self, req) 
    162161        self._params = params 
    163162        self._requestStarted = False 
     
    165164        # Fill in the aw instance with the current information 
    166165        self._aw = AccessWrapper() 
    167         self._aw.setIP(remoteHost) 
     166        self._aw.setIP(self.getHostIP()) 
    168167        self._aw.setSession(session) 
    169168        self._aw.setUser(session.getUser()) 
  • indico/MaKaC/services/interface/rpc/process.py

    r380f86 r59dfb4  
    1616from MaKaC.services.interface.rpc.common import RequestError 
    1717from MaKaC.services.interface.rpc.common import ProcessError 
     18 
    1819 
    1920def lookupHandler(method): 
     
    4243    return handler 
    4344 
     45 
    4446def processRequest(method, params, req): 
    4547    # lookup handler 
     
    4850    # invoke handler 
    4951    if hasattr(handler, "process"): 
    50         result = handler(params, req.get_remote_host(), getSession(req), req).process() 
     52        result = handler(params, getSession(req), req).process() 
    5153    else: 
    52         result = handler(params, req.get_remote_host(), getSession(req), req) 
     54        result = handler(params, getSession(req), req) 
    5355 
    5456    return result 
  • indico/MaKaC/webinterface/rh/base.py

    r6328a5 r59dfb4  
    6363from MaKaC.plugins.base import OldObservable 
    6464 
     65 
    6566class RequestHandlerBase(OldObservable): 
    6667 
     
    6869    _currentRH = None 
    6970 
    70     def __init__( self ): 
     71    def __init__(self, req): 
     72 
     73        # attention: not thread-safe 
    7174        RequestHandlerBase._currentRH = self 
     75 
     76        if req == None: 
     77            raise Exception("Request object not initialised") 
     78        self._req = req 
    7279 
    7380    def _checkProtection( self ): 
     
    118125        from MaKaC import i18n 
    119126        i18n.install('messages', lang, unicode=True) 
     127 
     128    def getHostIP(self): 
     129        import socket 
     130 
     131        host = str(self._req.get_remote_host(apache.REMOTE_NOLOOKUP)) 
     132 
     133        try: 
     134            hostIP = socket.gethostbyname(host) 
     135            minfo = info.HelperMaKaCInfo.getMaKaCInfoInstance() 
     136            if minfo.useProxy(): 
     137                # if we're behind a proxy, use X-Forwarded-For 
     138                xff = self._req.headers_in.get("X-Forwarded-For",hostIP).split(", ")[-1] 
     139                return socket.gethostbyname(xff) 
     140            else: 
     141                return hostIP 
     142        except socket.gaierror, e: 
     143            # in case host resolution fails 
     144            raise HostnameResolveError("Error resolving host '%s' : %s" % (host, e)) 
     145 
     146 
    120147 
    121148 
     
    169196                    current rh. 
    170197        """ 
    171         RequestHandlerBase.__init__(self) 
    172         if req == None: 
    173             raise Exception("Request object not initialised") 
    174         self._req = req 
     198        RequestHandlerBase.__init__(self, req) 
    175199        self._requestStarted = False 
    176200        self._websession = None 
     
    188212 
    189213    # Methods ============================================================= 
    190  
    191     def getHostIP(self): 
    192         import socket 
    193  
    194         host = str(self._req.get_remote_host(apache.REMOTE_NOLOOKUP)) 
    195  
    196         try: 
    197             hostIP = socket.gethostbyname(host) 
    198             minfo = info.HelperMaKaCInfo.getMaKaCInfoInstance() 
    199             if minfo.useProxy(): 
    200                 # if we're behind a proxy, use X-Forwarded-For 
    201                 xff = self._req.headers_in.get("X-Forwarded-For",hostIP).split(", ")[-1] 
    202                 return socket.gethostbyname(xff) 
    203             else: 
    204                 return hostIP 
    205         except socket.gaierror, e: 
    206             # in case host resolution fails 
    207             raise HostnameResolveError("Error resolving host '%s' : %s" % (host, e)) 
    208  
    209214 
    210215    def getTarget( self ): 
  • indico/web/wsgi/indico_wsgi_handler.py

    rb3f0d5 r59dfb4  
    285285        self.__errors = environ['wsgi.errors'] 
    286286        self.__headers_in = table([]) 
     287 
    287288        for key, value in environ.iteritems(): 
    288289            if key.startswith('HTTP_'): 
     
    292293        if environ.get('CONTENT_TYPE'): 
    293294            self.__headers_in['content-type'] = environ['CONTENT_TYPE'] 
     295 
    294296        ## HTTP headers variables 
    295297        ## We might want to add some other fields in the future 
Note: See TracChangeset for help on using the changeset viewer.