Changeset 2834

Show
Ignore:
Timestamp:
11/28/07 06:14:29 (8 months ago)
Author:
dalius
Message:

Added possibility to specify IP address mask for IP check. Similar issue exists in original Trac authentication methods: http://trac.edgewall.org/ticket/3211

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • authopenidplugin/0.11/authopenid/authopenid.py

    r2833 r2834  
    3636from openid import sreg 
    3737 
     38import socket 
     39import struct 
     40 
    3841class AuthOpenIdPlugin(Component): 
    3942 
     
    5053         """Whether the IP address of the user should be checked for 
    5154         authentication (''since 0.9'').""") 
     55    check_ip_mask = Option('trac', 'check_auth_ip_mask', '255.255.255.0', 
     56            """What mask should be applied to user address.""") 
     57 
     58    def _get_masked_address(self, address): 
     59        mask = struct.unpack('>L', socket.inet_aton(self.check_ip_mask))[0] 
     60        address = struct.unpack('>L', socket.inet_aton(address))[0] 
     61        return socket.inet_ntoa(struct.pack('>L', address & mask)) 
    5262 
    5363    def __init__(self): 
     
    275285            cursor.execute("INSERT INTO auth_cookie (cookie,name,ipnr,time) " 
    276286                           "VALUES (%s, %s, %s, %s)", (cookie, remote_user, 
    277                            req.remote_addr, int(time.time()))) 
     287                           self._get_masked_address(req.remote_addr), int(time.time()))) 
    278288            db.commit() 
    279289 
     
    363373            cursor.execute("SELECT name FROM auth_cookie " 
    364374                           "WHERE cookie=%s AND ipnr=%s", 
    365                            (cookie.value, req.remote_addr)) 
     375                           (cookie.value, self._get_masked_address(req.remote_addr))) 
    366376        else: 
    367377            cursor.execute("SELECT name FROM auth_cookie WHERE cookie=%s",