2007-10-08 11:54:13 -05:00
|
|
|
import os
|
2007-10-17 18:45:20 -05:00
|
|
|
import logging
|
2007-10-08 11:54:13 -05:00
|
|
|
|
2007-10-04 19:10:18 -05:00
|
|
|
import cherrypy
|
|
|
|
import turbogears
|
|
|
|
from turbogears import controllers, expose, flash
|
|
|
|
from turbogears import validators, validate
|
|
|
|
from turbogears import widgets, paginate
|
|
|
|
from turbogears import error_handler
|
|
|
|
from turbogears import identity
|
|
|
|
|
2007-10-08 11:54:13 -05:00
|
|
|
import ipa.ipaclient
|
0000-12-31 18:09:24 -05:50
|
|
|
from ipaserver import funcs
|
2007-10-08 11:54:13 -05:00
|
|
|
import ipa.config
|
|
|
|
|
2007-10-17 18:45:20 -05:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2007-10-08 11:54:13 -05:00
|
|
|
ipa.config.init_config()
|
|
|
|
|
2007-10-04 19:10:18 -05:00
|
|
|
class IPAController(controllers.Controller):
|
|
|
|
def restrict_post(self):
|
|
|
|
if cherrypy.request.method != "POST":
|
|
|
|
turbogears.flash("This method only accepts posts")
|
|
|
|
raise turbogears.redirect("/")
|
|
|
|
|
2007-10-08 11:54:13 -05:00
|
|
|
def get_ipaclient(self):
|
0000-12-31 18:09:24 -05:50
|
|
|
transport = funcs.IPAServer()
|
|
|
|
client = ipa.ipaclient.IPAClient(transport)
|
2007-10-08 11:54:13 -05:00
|
|
|
client.set_krbccache(os.environ["KRB5CCNAME"])
|
|
|
|
return client
|
|
|
|
|
2007-10-04 19:10:18 -05:00
|
|
|
def utf8_encode(self, value):
|
|
|
|
if value != None:
|
|
|
|
value = value.encode('utf-8')
|
|
|
|
return value
|
|
|
|
|
|
|
|
def sort_group_member(self, a, b):
|
|
|
|
"""Comparator function used for sorting group members."""
|
|
|
|
if a.getValue('uid') and b.getValue('uid'):
|
2007-10-17 15:42:45 -05:00
|
|
|
if a.getValue('sn') == b.getValue('sn'):
|
|
|
|
if a.getValue('givenName') == b.getValue('givenName'):
|
2007-10-04 19:10:18 -05:00
|
|
|
if a.getValue('uid') == b.getValue('uid'):
|
|
|
|
return 0
|
|
|
|
elif a.getValue('uid') < b.getValue('uid'):
|
|
|
|
return -1
|
|
|
|
else:
|
|
|
|
return 1
|
2007-10-17 15:42:45 -05:00
|
|
|
elif a.getValue('givenName') < b.getValue('givenName'):
|
2007-10-04 19:10:18 -05:00
|
|
|
return -1
|
|
|
|
else:
|
|
|
|
return 1
|
2007-10-17 15:42:45 -05:00
|
|
|
elif a.getValue('sn') < b.getValue('sn'):
|
2007-10-04 19:10:18 -05:00
|
|
|
return -1
|
|
|
|
else:
|
|
|
|
return 1
|
|
|
|
elif a.getValue('uid'):
|
|
|
|
return -1
|
|
|
|
elif b.getValue('uid'):
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
if a.getValue('cn') == b.getValue('cn'):
|
|
|
|
return 0
|
|
|
|
elif a.getValue('cn') < b.getValue('cn'):
|
|
|
|
return -1
|
|
|
|
else:
|
|
|
|
return 1
|
|
|
|
|
|
|
|
def sort_by_cn(self, a, b):
|
|
|
|
"""Comparator function used for sorting groups."""
|
|
|
|
if a.getValue('cn') == b.getValue('cn'):
|
|
|
|
return 0
|
|
|
|
elif a.getValue('cn') < b.getValue('cn'):
|
|
|
|
return -1
|
|
|
|
else:
|
|
|
|
return 1
|