|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +# |
| 4 | +# ---------------------------------------------------------------------------- |
| 5 | +# "THE CLUB-MATE LICENSE" (Revision 23): |
| 6 | +# Some guys from the c3pb.de wrote this file. As long as you retain this notice you |
| 7 | +# can do whatever you want with this stuff. If you meet some of us some day, and you think |
| 8 | +# this stuff is worth it, you can buy use a club-mate in return. |
| 9 | +# ---------------------------------------------------------------------------- |
| 10 | +# |
| 11 | + |
| 12 | + |
| 13 | +#NlxMQjDG |
| 14 | + |
| 15 | +import os |
| 16 | +import cherrypy |
| 17 | +import ConfigParser |
| 18 | + |
| 19 | +import cherrypy.lib.auth_basic |
| 20 | + |
| 21 | +from jumpages.admin import Admin |
| 22 | + |
| 23 | +from jinja2 import Environment, PackageLoader |
| 24 | + |
| 25 | +#This will create a template environment with the default settings |
| 26 | +#and a loader that looks up the templates in the templates folder |
| 27 | +#inside the yourapplication python package. |
| 28 | +env = Environment(loader=PackageLoader('jum', 'templates')) |
| 29 | + |
| 30 | +from ldaphelper import LdapConn |
| 31 | + |
| 32 | + |
| 33 | +class Root(object): |
| 34 | + @cherrypy.expose |
| 35 | + def index(self): |
| 36 | + template = env.get_template('index.html') |
| 37 | + return template.render(title='JUM') |
| 38 | + |
| 39 | + |
| 40 | +def authAdmin(realm,user,password): |
| 41 | + print "auth admin" |
| 42 | + return True |
| 43 | + |
| 44 | +def authMember(realm,user,password): |
| 45 | + print "auth member" |
| 46 | + return True |
| 47 | +# print realm,user,password |
| 48 | +# return ldapConn.hasAccess(user,password) |
| 49 | + |
| 50 | + |
| 51 | +def main(): |
| 52 | + config = ConfigParser.RawConfigParser() |
| 53 | + config.read('jum.cfg') |
| 54 | + |
| 55 | + ldap_server = config.get("jum", "ldap_server") |
| 56 | + people_basedn = config.get("jum", "people_basedn") |
| 57 | + groups_basedn = config.get("jum", "groups_basedn") |
| 58 | + admin_dn = config.get("jum", "admin_dn") |
| 59 | + admin_pw = config.get("jum", "admin_pw") |
| 60 | + |
| 61 | + #create globally shared ldapConnection |
| 62 | + global ldapConn |
| 63 | + ldapConn = LdapConn(ldap_server,people_basedn,groups_basedn,admin_dn,admin_pw) |
| 64 | + |
| 65 | + # Some global configuration; note that this could be moved into a |
| 66 | + # configuration file |
| 67 | + cherrypy.config.update({ |
| 68 | + 'tools.encode.on': True, 'tools.encode.encoding': 'utf-8', |
| 69 | + 'tools.decode.on': True, |
| 70 | + 'tools.trailing_slash.on': True, |
| 71 | + 'tools.staticdir.root': os.path.abspath(os.path.dirname(__file__)), |
| 72 | + |
| 73 | + }) |
| 74 | + |
| 75 | + rootconf = { |
| 76 | + '/static': { |
| 77 | + 'tools.staticdir.on': True, |
| 78 | + 'tools.staticdir.dir': 'static' |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + adminconf = { |
| 83 | + '/': {'tools.auth_basic.on': True, |
| 84 | + 'tools.auth_basic.realm': 'Admins only', |
| 85 | + 'tools.auth_basic.checkpassword': authAdmin, |
| 86 | + }, |
| 87 | + } |
| 88 | + |
| 89 | + memberconf = { |
| 90 | + '/': {'tools.auth_basic.on': True, |
| 91 | + 'tools.auth_basic.realm': 'Members', |
| 92 | + 'tools.auth_basic.checkpassword': authMember, |
| 93 | + }, |
| 94 | + } |
| 95 | + |
| 96 | + cherrypy.tree.mount(Root(),"/",rootconf) |
| 97 | + cherrypy.tree.mount(Admin(env),"/admin",adminconf) |
| 98 | + cherrypy.tree.mount(Member(),"/member",memberconf) |
| 99 | + |
| 100 | + cherrypy.engine.start() |
| 101 | + cherrypy.engine.block() |
| 102 | + |
| 103 | +if __name__ == '__main__': |
| 104 | + main() |
0 commit comments