Skip to content

Commit

Permalink
- add XMPP ID support
Browse files Browse the repository at this point in the history
- major bug fix ... ldap user search results were not limited in number.
  in case a member had more attrs than another one and somehow contained that other users
  uid, the search result contained both users
  -> major fuckup as result
  ... issue weird and not really logical but reproducable
  ... fixed by searching a precise user DN for user attrs
  no need anyway to search the whole top tree ... but... well....
  • Loading branch information
sim0nx committed Aug 21, 2011
1 parent e2cdaea commit 722b631
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 11 deletions.
16 changes: 10 additions & 6 deletions MeMaTool/mematool/controllers/error.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import cgi

from paste.urlparser import PkgResourcesParser
from pylons import request
from pylons.controllers.util import forward
from pylons import request, url
from pylons.controllers.util import forward, redirect
from pylons.middleware import error_document_template
from webhelpers.html.builder import literal

Expand Down Expand Up @@ -40,13 +40,17 @@ def document(self):
resp = request.environ.get('pylons.original_response')
try:
content = literal(resp.body) or cgi.escape(request.GET.get('message', ''))

page = error_document_template % \
dict(prefix=request.environ.get('SCRIPT_NAME', ''),
code=cgi.escape(request.GET.get('code', str(resp.status_int))),
message=content)
except:
# resp can be None !
# @TODO do log what happened here ... not normal
redirect(url(controller='profile', action='index'))
pass
page = error_document_template % \
dict(prefix=request.environ.get('SCRIPT_NAME', ''),
code=cgi.escape(request.GET.get('code', str(resp.status_int))),
message=content)

return page

def unauthorized(self):
Expand Down
17 changes: 16 additions & 1 deletion MeMaTool/mematool/controllers/members.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ def new_f(self):
formok = False
errors.append(_('Invalid convention signer'))

if 'xmppID' in request.params and request.params['xmppID'] != '' and not re.match(regex.email, request.params['xmppID'], re.IGNORECASE):
formok = False
errors.append(_('Invalid XMPP/Jabber/GTalk ID'))



if 'userPassword' in request.params and 'userPassword2' in request.params:
if request.params['userPassword'] != request.params['userPassword2']:
Expand Down Expand Up @@ -259,7 +264,16 @@ def doEditMember(self):
else:
member.conventionSigner = request.params['conventionSigner']
elif 'conventionSigner' in vars(member) and request.params['mode'] == 'edit':
member.pgpKey = 'removed'
member.conventionSigner = 'removed'

if 'xmppID' in request.params:
if request.params['xmppID'] == '' and 'xmppID' in vars(member):
member.xmppID = 'removed'
else:
member.xmppID = request.params['xmppID']
elif 'xmppID' in vars(member) and request.params['mode'] == 'edit':
member.xmppID = 'removed'


if 'userPassword' in request.params and request.params['userPassword'] != '':
member.setPassword(request.params['userPassword'])
Expand Down Expand Up @@ -363,6 +377,7 @@ def validateMember(self):
member.phone = tm.phone
member.mobile = tm.mobile
member.mail = tm.mail
member.xmppID = tm.xmppID

member.save()
Session.delete(tm)
Expand Down
13 changes: 12 additions & 1 deletion MeMaTool/mematool/controllers/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def edit(self):
member.phone = tm.phone
member.mobile = tm.mobile
member.mail = tm.mail
member.xmppID = tm.xmppID

c.formDisabled = 'disabled'

Expand Down Expand Up @@ -140,6 +141,10 @@ def new_f(self):
formok = False
errors.append(_('Invalid e-mail address'))

if self._isParamSet('xmppID') and not self._isParamStr('xmppID', max_len=40, regex=regex.email):
formok = False
errors.append(_('Invalid XMPP/Jabber/GTalk ID'))

if self._isParamStr('userPassword') and self._isParamStr('userPassword2'):
if request.params['userPassword'] != request.params['userPassword2']:
formok = False
Expand Down Expand Up @@ -184,7 +189,8 @@ def doEdit(self):
request.params['homePostalAddress'] != m.homePostalAddress or\
('phone' in request.params and m.homePhone != '' and request.params['phone'] != m.homePhone) or\
request.params['mobile'] != m.mobile or\
request.params['mail'] != m.mail:
request.params['mail'] != m.mail or\
request.params['xmppID'] != m.xmppID:
changes = True

if changes:
Expand All @@ -199,6 +205,11 @@ def doEdit(self):
else:
tm.phone = request.params['phone']

if 'xmppID' not in request.params or (request.params['xmppID'] == '' and not m.xmppID is ''):
tm.xmppID = 'removed'
else:
tm.xmppID = request.params['xmppID']

tm.mobile = request.params['mobile']
tm.mail = request.params['mail']

Expand Down
11 changes: 9 additions & 2 deletions MeMaTool/mematool/lib/syn2cat/ldapConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ def getGroupMembers(self, group):
def getMember(self, uid):
filter = '(uid=' + uid + ')'
attrs = ['*']
basedn = 'uid=' + str(uid) + ',' + str(config.get('ldap.basedn_users'))

result = self.con.search_s( config.get('ldap.basedn_users'), ldap.SCOPE_SUBTREE, filter, attrs )
result = self.con.search_s( basedn, ldap.SCOPE_SUBTREE, filter, attrs )

if not result:
raise LookupError('No such user !')
Expand Down Expand Up @@ -291,11 +292,16 @@ def saveMember(self, member):
mod_attrs.append((ldap.MOD_REPLACE, 'pgpKey', str(member.pgpKey)))

if member.conventionSigner:
if member.pgpKey == 'removed':
if member.conventionSigner == 'removed':
mod_attrs.append((ldap.MOD_DELETE, 'conventionSigner', None))
else:
mod_attrs.append((ldap.MOD_REPLACE, 'conventionSigner', str(member.conventionSigner)))

if member.xmppID:
if member.xmppID == 'removed':
mod_attrs.append((ldap.MOD_DELETE, 'xmppID', None))
else:
mod_attrs.append((ldap.MOD_REPLACE, 'xmppID', str(member.xmppID)))

result = self.con.modify_s('uid=' + member.uid + ',' + config.get('ldap.basedn_users'), mod_attrs)

Expand All @@ -307,6 +313,7 @@ def saveMember(self, member):


def addMember(self, member):
# @TODO we don't set all possible attributes !!! fix
add_record = [
('objectclass', ['posixAccount', 'organizationalPerson', 'inetOrgPerson', 'shadowAccount', 'top', 'samsePerson', 'sambaSamAccount', 'ldapPublicKey', 'syn2catPerson']),
('uid', [member.uid.encode('ascii','ignore')]),
Expand Down
3 changes: 3 additions & 0 deletions MeMaTool/mematool/model/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Member():
homePhone = '' # phone (homePhone)
mobile = '' # mobile
mail = '' # mail
xmppID = '' # xmppID
userPassword = '' # SSHA password
sambaNTPassword = '' # NT Password
sambaSID = ''
Expand Down Expand Up @@ -95,6 +96,8 @@ def loadFromLdap(self):
self.mobile = member['mobile']
if 'mail' in member:
self.mail = member['mail']
if 'xmppID' in member:
self.xmppID = member['xmppID']
if 'sambaNTPassword' in member and member['sambaNTPassword'] != '':
self.sambaNTPassword = 'yes'
if 'sambaSID' in member and member['sambaSID'] != '':
Expand Down
3 changes: 2 additions & 1 deletion MeMaTool/mematool/model/tmpmember.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ class TmpMember(Base):
phone = Column(String(30))
mobile = Column(String(30))
mail = Column(String(255))
xmppID = Column(String(255))

def __init__(self, uidNumber):
self.id = uidNumber

def __str__(self):
return "<TmpMember('id=%d, gn=%s', sn=%s, birthDate=%s, homePostalAddress=%s, phone=%s, mobile=%s, mail=%s)>" % (self.id, self.gn, self.sn, self.birthDate, self.homePostalAddress, self.phone, self.mobile, self.mail)
return "<TmpMember('id=%d, gn=%s', sn=%s, birthDate=%s, homePostalAddress=%s, phone=%s, mobile=%s, mail=%s, xmppID=%s)>" % (self.id, self.gn, self.sn, self.birthDate, self.homePostalAddress, self.phone, self.mobile, self.mail, self.xmppID)


def save(self):
Expand Down
Binary file modified MeMaTool/mematool/public/favicon.ico
Binary file not shown.
8 changes: 8 additions & 0 deletions MeMaTool/mematool/templates/members/editMember.mako
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ def getFormVar(s, c, var):
<input type="text" name="mail" value="${getFormVar(session, c, 'mail')}" class="input text">
</td>
</tr>
<tr>
<td class="table_title">
${_('XMPP/Jabber/GTalk ID')}
</td>
<td>
<input type="text" name="xmppID" value="${getFormVar(session, c, 'xmppID')}" class="input text">
</td>
</tr>
<tr>
<td class="table_title">
${_('Login Shell')}
Expand Down
8 changes: 8 additions & 0 deletions MeMaTool/mematool/templates/profile/edit.mako
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ def getFormVar(s, c, var):
<input type="text" name="mail" value="${getFormVar(session, c, 'mail')}" class="input" ${c.formDisabled}>
</td>
</tr>
<tr>
<td class="table_title">
${_('XMPP/Jabber/GTalk ID')}
</td>
<td>
<input type="text" name="xmppID" value="${getFormVar(session, c, 'xmppID')}" class="input" ${c.formDisabled}>
</td>
</tr>
<tr>
<td class="table_title">
${_('Login Shell')}
Expand Down

0 comments on commit 722b631

Please sign in to comment.