comparison MoinMoin/util/abuse.py @ 6066:68092d872ecc

add page name to abuse log
author 'Karl O. Pinc' <kop@meme.com>
date Thu, 04 Sep 2014 14:09:28 -0500
parents bbbfb024a967
children 2e0530a78920
comparison
equal deleted inserted replaced
6065:bbbfb024a967 6066:68092d872ecc
12 12
13 from MoinMoin import log 13 from MoinMoin import log
14 logging = log.getLogger(__name__) 14 logging = log.getLogger(__name__)
15 15
16 16
17 def log_attempt(system, success, request=None, username=None): 17 def log_attempt(system, success, request=None, username=None, page=None):
18 """ 18 """
19 log attempts to use <system>, log success / failure / username / ip 19 log attempts to use <system>, log success / failure / username / ip
20 20
21 @param system: some string telling about the system that was used, e.g. 21 @param system: some string telling about the system that was used, e.g.
22 "auth: login" or "textcha" 22 "auth: login" or "textcha"
23 @param success: whether the attempt was successful 23 @param success: whether the attempt was successful
24 @param request: request object (optional, to determine remote's ip address) 24 @param request: request object (optional, to determine remote's ip address)
25 @param username: user's name (optional, if None: determined from request) 25 @param username: user's name (optional, if None: determined from request)
26 @param page: name of the page (optional)
26 """ 27 """
27 if username is None: 28 if username is None:
28 if request and hasattr(request, 'user') and request.user.valid: 29 if request and hasattr(request, 'user') and request.user.valid:
29 username = request.user.name 30 username = request.user.name
30 else: 31 else:
31 username = u'anonymous' 32 username = u'anonymous'
32 level = (logging.WARNING, logging.INFO)[success] 33 level = (logging.WARNING, logging.INFO)[success]
33 msg = """%s status: %s username: "%s" ip: %s""" 34 msg = """%s status: %s username: "%s" ip: %s page: %s"""
34 status = ("failure", "success")[success] 35 status = ("failure", "success")[success]
35 ip = request and request.remote_addr or 'unknown' 36 ip = request and request.remote_addr or 'unknown'
36 logging.log(level, msg, system, status, username, ip) 37 logging.log(level, msg, system, status, username, ip, page)