コード例 #1
0
ファイル: atomgen.py プロジェクト: xakon/dwiki
def get_feedmax(context):
    if 'feed-max-size' not in context:
        return defFeedMax
    if 'feed-max-size-ips' not in context:
        return context['feed-max-size']
    sip = context['remote-ip']
    fmax = context['feed-max-size']
    if httputil.matchIP(sip, context['feed-max-size-ips']):
        return fmax
    return defFeedMax
コード例 #2
0
ファイル: atomgen.py プロジェクト: siebenmann/dwiki
def get_feedmax(context):
	if 'feed-max-size' not in context:
		return defFeedMax
	if 'feed-max-size-ips' not in context:
		return context['feed-max-size']
	sip = context['remote-ip']
	fmax = context['feed-max-size']
	if httputil.matchIP(sip, context['feed-max-size-ips']):
			return fmax
	return defFeedMax
コード例 #3
0
def IpKiller(next, logger, reqdata, environ):
	cfg = get_cfg(environ)
	ipl = cfg['banned-ips']
	sip = environ.get('REMOTE_ADDR', '')
	# no remote IP means immediate kill
	if not sip or httputil.matchIP(sip, ipl):
		logger.warn("banned IP denied access")
		return httputil.genError("disallowed", 403)
	else:
		return next(logger, reqdata, environ)
コード例 #4
0
def IpCommentKiller(next, logger, reqdata, environ):
	if reqdata['view'] != 'writecomment':
		return next(logger, reqdata, environ)
	cfg = get_cfg(environ)
	ipl = cfg['banned-comment-ips']
	sip = environ.get('REMOTE_ADDR', '')
	if not sip or httputil.matchIP(sip, ipl):
		logger.warn("banned comment IP denied access")
		return httputil.genError("disallowed", 403)
	else:
		return next(logger, reqdata, environ)
コード例 #5
0
def is_cacheable_request(cfg, reqdata, environ):
	"""Cacheable requests must be GET or HEAD requests with
	a path and without cookies or view parameters. Also, it
	must not be an Atom feed request that runs into
	feed-max-size-ips"""
	if environ['REQUEST_METHOD'] not in ('GET', 'HEAD') or \
	   environ.get('HTTP_COOKIE', '') or \
	   'view-dict' in reqdata or 'query' not in reqdata:
		return False

	# We cannot serve Atom requests out of a cache at all if
	# this request would hit the feed-max-size-ips feature.
	if 'feed-max-size-ips' in cfg and \
	   reqdata['view'] in ('atom', 'atomcomments', 'rss2') and \
	   httputil.matchIP(reqdata['remote-ip'],
			    cfg['feed-max-size-ips']):
		return False

	# Is cacheable.
	return True