From 023239ac4e08632ee7d318ce08e120b8a9734b4a Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Sat, 15 Jun 2013 01:37:11 +0200 Subject: [PATCH] =?UTF-8?q?[wiki/auth]=20Deux=20modules,=20un=20pour=20la?= =?UTF-8?q?=20zone=20crans,=20un=20pour=20la=20cat=C3=A9gorie=20page=20pub?= =?UTF-8?q?lique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wiki/auth/categorie_public.py | 41 ++++++++++++++++++++++++++++ wiki/auth/ip_range.py | 51 +++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 wiki/auth/categorie_public.py create mode 100644 wiki/auth/ip_range.py diff --git a/wiki/auth/categorie_public.py b/wiki/auth/categorie_public.py new file mode 100644 index 00000000..6a62070c --- /dev/null +++ b/wiki/auth/categorie_public.py @@ -0,0 +1,41 @@ +# -*- coding: iso-8859-1 -*- +""" + MoinMoin - CAS authentication + + Jasig CAS (see http://www.jasig.org/cas) authentication module. + + @copyright: 2012 MoinMoin:RichardLiao + @license: GNU GPL, see COPYING for details. +""" + +import sys +import os +import time, re +import urlparse +import urllib, urllib2 +from netaddr import IPNetwork, IPAddress + +from MoinMoin import log +logging = log.getLogger(__name__) + +from MoinMoin.auth import BaseAuth +from MoinMoin import user, wikiutil +from MoinMoin.Page import Page +from anonymous_user import AnonymousAuth + +class PublicCategories(AnonymousAuth): + name = 'PublicCategories' + + def __init__(self, pub_cats=[], auth_username="Connexion"): + AnonymousAuth.__init__(self, auth_username=auth_username) + self.pub_cats=pub_cats + + def can_view(self, request): + p = urlparse.urlparse(request.url) + categories = Page(request, p.path[1:]).getCategories(request) + + for cat in self.pub_cats: + if cat in categories: + return True + return False + diff --git a/wiki/auth/ip_range.py b/wiki/auth/ip_range.py new file mode 100644 index 00000000..40473709 --- /dev/null +++ b/wiki/auth/ip_range.py @@ -0,0 +1,51 @@ +# -*- coding: iso-8859-1 -*- +""" + MoinMoin - CAS authentication + + Jasig CAS (see http://www.jasig.org/cas) authentication module. + + @copyright: 2012 MoinMoin:RichardLiao + @license: GNU GPL, see COPYING for details. +""" + +import urlparse +from netaddr import IPNetwork, IPAddress + +from MoinMoin.auth import BaseAuth +from MoinMoin import user +from anonymous_user import AnonymousAuth + +class IpRange(AnonymousAuth): + name = 'IpRange' + + def __init__(self, auth_username="Connexion", local_nets=[], actions=[], actions_msg={}): + AnonymousAuth.__init__(self, auth_username=auth_username) + self.local_nets = local_nets; + self.actions = actions + self.actions_msg=actions_msg + + def can_view(self, request): + try: + for net in self.local_nets: + if IPAddress(request.remote_addr) in IPNetwork(net): + return True + except: + pass + return False + + def request(self, request, user_obj, **kw): + user_obj, cont = AnonymousAuth.request(self, request, user_obj, **kw) + if user_obj and not user_obj.valid: + # Are we trying to do a protected action (eg newaccount) + action = request.args.get("action", "") + if action in self.actions: + if action in self.actions_msg.keys(): + request.theme.add_msg(self.actions_msg[action]) + p = urlparse.urlparse(request.url) + url = urlparse.urlunparse(('https', p.netloc, p.path, "", "", "")) + request.http_redirect(url) + return user_obj, True + + return user_obj, False + +