Skip to content

Commit fb4dc8f

Browse files
committed
hello world!
Signed-off-by: Matthias Grawinkel <[email protected]>
0 parents  commit fb4dc8f

15 files changed

+388
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
notes
2+
um.cfg
3+
*.pyc

.project

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>jum2</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.python.pydev.PyDevBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.python.pydev.pythonNature</nature>
16+
</natures>
17+
</projectDescription>

.pydevproject

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<?eclipse-pydev version="1.0"?>
3+
4+
<pydev_project>
5+
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
6+
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.6</pydev_property>
7+
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
8+
<path>/jum2/src</path>
9+
</pydev_pathproperty>
10+
</pydev_project>

README

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Ldap user management:
2+
requires jinja2 (included), cherrypy(3.2x, included) and ldap python packages
3+
4+
5+
{% ... %} : used to execute statements such as for-loops or assign values
6+
{{ ... }} : prints the result of the expression to the template.
7+
{# ... #} : comment out the content
8+
9+
10+
11+
Authorization:
12+
13+
basic auth against the ldap:
14+
contains two methods to separate /member/ and /admin/ authentication realms

src/jum.py

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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()

src/jumpages/__init__.py

Whitespace-only changes.

src/jumpages/admin.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#
2+
# ----------------------------------------------------------------------------
3+
# "THE CLUB-MATE LICENSE" (Revision 23):
4+
# Some guys from the c3pb.de wrote this file. As long as you retain this notice you
5+
# can do whatever you want with this stuff. If you meet some of us some day, and you think
6+
# this stuff is worth it, you can buy use a club-mate in return.
7+
# ----------------------------------------------------------------------------
8+
#
9+
10+
import cherrypy
11+
12+
class Admin():
13+
'''
14+
This class contains all pages for /admin/**
15+
'''
16+
17+
@cherrypy.expose
18+
def index(self):
19+
template = self.env.get_template('admin.index.html')
20+
return template.render(title='Admin only area')
21+
22+
def __init__(self,env,ldapConn):
23+
'''
24+
Constructor
25+
'''
26+
self.env = env
27+
self.ldapConn = ldapConn
28+

src/jumpages/member.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# ----------------------------------------------------------------------------
3+
# "THE CLUB-MATE LICENSE" (Revision 23):
4+
# Some guys from the c3pb.de wrote this file. As long as you retain this notice you
5+
# can do whatever you want with this stuff. If you meet some of us some day, and you think
6+
# this stuff is worth it, you can buy use a club-mate in return.
7+
# ----------------------------------------------------------------------------
8+
#
9+
10+
import cherrypy
11+
12+
class Member():
13+
'''
14+
This class contains all pages for /member/**
15+
'''
16+
17+
def __init__(self,env,ldapConn):
18+
'''
19+
Constructor
20+
'''
21+
self.env = env
22+
self.ldapConn = ldapConn
23+
24+
25+
@cherrypy.expose
26+
def index(self):
27+
print cherrypy.request.login
28+
allusers = self.ldapConn.get_users()
29+
template = self.env.get_template('user.index.html')
30+
return template.render(users=allusers, title='users list')
31+
32+
@cherrypy.expose
33+
def view(self,username):
34+
print "view username=%s" % (username)
35+
return "wheee"

src/ldaphelper.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#
2+
# ----------------------------------------------------------------------------
3+
# "THE CLUB-MATE LICENSE" (Revision 23):
4+
# Some guys from the c3pb.de wrote this file. As long as you retain this notice you
5+
# can do whatever you want with this stuff. If we meet some of us some day, and you think
6+
# this stuff is worth it, you can buy use a club-mate in return
7+
# ----------------------------------------------------------------------------
8+
#
9+
10+
import ldap
11+
12+
13+
class LdapConn:
14+
# ldapcon = None
15+
16+
def __init__(self,ldap_server,people_basedn,groups_basedn,admin_dn,admin_pw):
17+
self.ldap_server = ldap_server
18+
self.people_basedn = people_basedn
19+
self.groups_basedn = groups_basedn
20+
self.ldapcon = ldap.initialize(ldap_server)
21+
self.ldapcon.simple_bind_s( admin_dn, admin_pw )
22+
23+
def get_users(self):
24+
25+
filter = '(objectclass=person)'
26+
attrs = ['uid', 'cn', 'sn', 'mail']
27+
users = self.ldapcon.search_s( self.people_basedn, ldap.SCOPE_SUBTREE, filter, attrs )
28+
return users
29+
30+
def hasAccess(self,username,password):
31+
32+
try:
33+
# con = ldap.initialize(server)
34+
user_dn = self.people_basedn.format(USERNAME=username) #{"USERNAME" : username})
35+
print user_dn
36+
self.ldapcon.bind_s(user_dn, password)
37+
print "user authenticated"
38+
return True
39+
except ldap.INVALID_CREDENTIALS:
40+
print "Username or password is incorrect."
41+
return False
42+
# finally:
43+
# con.unbind()

src/static/style.css

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
body {
2+
color: black; background-color: white;
3+
font-size: 100.01%;
4+
font-family: Helvetica,Arial,sans-serif;
5+
margin: 0; padding: 1em;
6+
min-width: 41em; /* Mindestbreite verhindert Umbruch und Anzeigefehler in modernen Browsern */
7+
}
8+
9+
h1 {
10+
font-size: 1.5em;
11+
margin: 0 0 0.7em; padding: 0.3em;
12+
text-align: center;
13+
background-color: #D8DFEA;
14+
border: 2px ridge silver;
15+
}
16+
17+
div#navigation {
18+
font-size: 0.83em;
19+
float: left; width: 18em;
20+
margin: 0 0 1.2em; padding: 0;
21+
border: 1px dashed silver;
22+
}
23+
ul#navigation li {
24+
list-style: none;
25+
margin: 0; padding: 0.5em;
26+
}
27+
ul#navigation a {
28+
display: block;
29+
padding: 0.2em;
30+
font-weight: bold;
31+
}
32+
ul#navigation a:link {
33+
color: black; background-color: #eee;
34+
}
35+
ul#navigation a:visited {
36+
color: #666; background-color: #eee;
37+
}
38+
ul#navigation a:hover {
39+
color: black; background-color: white;
40+
}
41+
ul#navigation a:active {
42+
color: white; background-color: gray;
43+
}
44+
45+
46+
div#content {
47+
margin: 0 0 1em 16em;
48+
padding: 0 1em;
49+
border: 1px dashed silver;
50+
}
51+
52+
div#content h2 {
53+
font-size: 1.2em;
54+
margin: 0.2em 0;
55+
}
56+
div#content p {
57+
font-size: 1em;
58+
margin: 1em 0;
59+
}
60+
61+
p#content {
62+
clear: both;
63+
font-size: 0.9em;
64+
margin: 0; padding: 0.1em;
65+
text-align: center;
66+
background-color: #D8DFEA; border: 1px solid silver;
67+
}

src/templates/admin.index.html

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{% extends "template.html" %}
2+
{% block title %}{{ title }}{% endblock %}
3+
4+
{% block content %}
5+
<h1>Admin Area</h1>
6+
{% endblock %}
7+
8+

src/templates/index.html

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{% extends "template.html" %}
2+
{% block title %}{{title}}{% endblock %}
3+
4+
{% block content %}
5+
<h1>C3PB User Management</h1>
6+
Login as: <a href="/member">member</a> / <a href="/admin">admin</a>
7+
{% endblock %}

src/templates/template.html

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2+
"http://www.w3.org/TR/html4/strict.dtd">
3+
<html>
4+
<head>
5+
<title>{% block title %}{% endblock %}</title>
6+
<link rel="stylesheet" type="text/css" href="/static/style.css" type="text/css"></link>
7+
8+
{# http://www.favicon.cc/?action=icon&file_id=32641 Creative Commons based new hacker favicon #}
9+
<link href="data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAbUlEQVRIx82UOw4AIAhDrfEczt7fA+riZgxY8NPRwND2IdpQeKTELgIAML/v2olWBznXWgq/D7YCrwToCrzIMVdgFZ2AVlJV1xJYwUpD6JXA8Qoke/9BqL1vr7llAtofzjo3QXg7geNXIOk5hB3kjHms8LC50QAAAABJRU5ErkJggg==" rel="icon" type="image/x-icon" />
10+
11+
</head>
12+
<body>
13+
14+
<div id="navigation">
15+
<ul>
16+
<li><a href="/users">List Users</a></li>
17+
<li><a href="/groups">List Groups</a></li>
18+
</ul>
19+
</div>
20+
21+
<div id="content">
22+
{% block content %}{% endblock %}
23+
24+
</div>
25+
26+
<p id="footer">C3PB User Management</p>
27+
28+
</body>
29+
</html>

src/templates/user.index.html

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% extends "template.html" %}
2+
{% block title %}List of all Users{% endblock %}
3+
4+
{% block content %}
5+
<h1>All Users</h1>
6+
7+
<ul>
8+
{% for user in users %}
9+
<li><a href="{{ user }}">asdf</a></li>
10+
{% endfor %}
11+
</ul>
12+
{% endblock %}
13+
14+

0 commit comments

Comments
 (0)