Trees | Indices | Help |
---|
|
1 # -*- Mode: Python; test-case-name: flumotion.test.test_bouncers_ipbouncer -*- 2 # vi:si:et:sw=4:sts=4:ts=4 3 # 4 # Flumotion - a streaming media server 5 # Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com). 6 # All rights reserved. 7 8 # This file may be distributed and/or modified under the terms of 9 # the GNU General Public License version 2 as published by 10 # the Free Software Foundation. 11 # This file is distributed without any warranty; without even the implied 12 # warranty of merchantability or fitness for a particular purpose. 13 # See "LICENSE.GPL" in the source distribution for more information. 14 15 # Licensees having purchased or holding a valid Flumotion Advanced 16 # Streaming Server license may use this file in accordance with the 17 # Flumotion Advanced Streaming Server Commercial License Agreement. 18 # See "LICENSE.Flumotion" in the source distribution for more information. 19 20 # Headers in this file shall remain intact. 21 22 """ 23 A bouncer that authenticates based on the IP address of the remote side, 24 as seen by the bouncer. 25 """ 26 27 from flumotion.common import keycards, messages, errors, log, netutils 28 from flumotion.common.i18n import N_, gettexter 29 from flumotion.component.bouncers.algorithms import base 30 31 __all__ = ['IPBouncerAlgorithm'] 32 __version__ = "$Rev$" 33 T_ = gettexter() 34 3537 38 logCategory = 'ip-bouncer' 39 volatile = False 40 438645 self.props = self.args['properties'] 46 self.deny_default = self.props.get('deny-default', True) 47 48 self.allows = netutils.RoutingTable() 49 self.denies = netutils.RoutingTable() 50 for p, t in (('allow', self.allows), ('deny', self.denies)): 51 for s in self.props.get(p, []): 52 try: 53 ip, mask = s.split('/') 54 t.addSubnet(True, ip, int(mask)) 55 except Exception, e: 56 m = messages.Error( 57 T_(N_("Invalid value for property %r: %s"), p, s), 58 log.getExceptionMessage(e), 59 mid='match-type') 60 component.addMessage(m) 61 raise errors.ComponentSetupHandledError()6264 ip = keycard.getData()['address'] 65 self.debug('authenticating keycard from requester %s', ip) 66 67 if ip is None: 68 self.warning('could not get address of remote') 69 allowed = False 70 elif self.deny_default: 71 allowed = (self.allows.route(ip) 72 and not self.denies.route(ip)) 73 else: 74 allowed = (self.allows.route(ip) 75 or not self.denies.route(ip)) 76 77 if not allowed: 78 self.info('denied login from ip address %s', 79 keycard.address) 80 return None 81 else: 82 keycard.state = keycards.AUTHENTICATED 83 self.debug('allowed login from ip address %s', 84 keycard.address) 85 return keycard
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Fri Jun 17 13:30:45 2011 | http://epydoc.sourceforge.net |