2008-02-04 15:15:52 -05:00
|
|
|
# Copyright (C) 2007 Red Hat
|
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
|
# modify it under the terms of the GNU General Public License as
|
|
|
|
|
# published by the Free Software Foundation; version 2 only
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
#
|
|
|
|
|
|
2007-11-12 14:19:05 -05:00
|
|
|
import os
|
|
|
|
|
from pickle import dumps, loads
|
|
|
|
|
from base64 import b64encode, b64decode
|
|
|
|
|
import copy
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
from ipacontroller import IPAController
|
|
|
|
|
from ipa.entity import utf8_encode_values
|
|
|
|
|
from ipa import ipaerror
|
2007-11-16 12:59:32 -05:00
|
|
|
import ipa.entity
|
2007-11-12 14:19:05 -05:00
|
|
|
import ipagui.forms.ipapolicy
|
2007-12-04 13:18:37 -05:00
|
|
|
from ipagui.helpers import ipahelper
|
2007-11-12 14:19:05 -05:00
|
|
|
|
|
|
|
|
import ldap.dn
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
ipapolicy_edit_form = ipagui.forms.ipapolicy.IPAPolicyForm()
|
|
|
|
|
|
|
|
|
|
class IPAPolicyController(IPAController):
|
|
|
|
|
|
|
|
|
|
@expose()
|
2007-11-14 10:49:03 -05:00
|
|
|
@identity.require(identity.in_group("admins"))
|
2007-11-12 14:19:05 -05:00
|
|
|
def index(self):
|
|
|
|
|
raise turbogears.redirect("/ipapolicy/show")
|
|
|
|
|
|
|
|
|
|
@expose("ipagui.templates.ipapolicyshow")
|
2007-11-14 10:49:03 -05:00
|
|
|
@identity.require(identity.in_group("admins"))
|
2007-11-12 14:19:05 -05:00
|
|
|
def show(self, tg_errors=None):
|
|
|
|
|
"""Displays the one policy page"""
|
2007-11-16 12:59:32 -05:00
|
|
|
client = self.get_ipaclient()
|
|
|
|
|
config = client.get_ipa_config()
|
|
|
|
|
ipapolicy = config.toDict()
|
|
|
|
|
|
|
|
|
|
ppolicy = client.get_password_policy()
|
|
|
|
|
password = ppolicy.toDict()
|
2007-11-12 14:19:05 -05:00
|
|
|
|
2007-11-16 12:59:32 -05:00
|
|
|
return dict(ipapolicy=ipapolicy,password=password,fields=ipagui.forms.ipapolicy.IPAPolicyFields())
|
2007-11-12 14:19:05 -05:00
|
|
|
|
|
|
|
|
@expose("ipagui.templates.ipapolicyedit")
|
2007-11-14 10:49:03 -05:00
|
|
|
@identity.require(identity.in_group("admins"))
|
2007-11-12 14:19:05 -05:00
|
|
|
def edit(self, tg_errors=None):
|
|
|
|
|
"""Displays the edit IPA policy form"""
|
|
|
|
|
if tg_errors:
|
|
|
|
|
turbogears.flash("There were validation errors.<br/>" +
|
|
|
|
|
"Please see the messages below for details.")
|
|
|
|
|
|
|
|
|
|
try:
|
2007-11-16 12:59:32 -05:00
|
|
|
client = self.get_ipaclient()
|
|
|
|
|
config = client.get_ipa_config()
|
|
|
|
|
ipapolicy_dict = config.toDict()
|
|
|
|
|
|
|
|
|
|
ppolicy = client.get_password_policy()
|
|
|
|
|
password_dict = ppolicy.toDict()
|
|
|
|
|
|
|
|
|
|
# store a copy of the original policy for the update later
|
|
|
|
|
ipapolicy_data = b64encode(dumps(ipapolicy_dict))
|
|
|
|
|
ipapolicy_dict['ipapolicy_orig'] = ipapolicy_data
|
|
|
|
|
|
|
|
|
|
# store a copy of the original policy for the update later
|
|
|
|
|
password_data = b64encode(dumps(password_dict))
|
|
|
|
|
password_dict['password_orig'] = password_data
|
|
|
|
|
|
|
|
|
|
# Combine the 2 dicts to make the form easier
|
|
|
|
|
ipapolicy_dict.update(password_dict)
|
|
|
|
|
|
2007-12-04 13:18:37 -05:00
|
|
|
# Load potential multi-valued fields
|
2008-02-21 11:09:53 -05:00
|
|
|
if isinstance(ipapolicy_dict.get('ipauserobjectclasses',''), basestring):
|
2007-12-04 13:18:37 -05:00
|
|
|
ipapolicy_dict['ipauserobjectclasses'] = [ipapolicy_dict.get('ipauserobjectclasses')]
|
|
|
|
|
ipapolicy_dict['userobjectclasses'] = ipahelper.setup_mv_fields(ipapolicy_dict.get('ipauserobjectclasses'), 'ipauserobjectclasses')
|
|
|
|
|
|
2008-02-21 11:09:53 -05:00
|
|
|
if isinstance(ipapolicy_dict.get('ipagroupobjectclasses',''), basestring):
|
2007-12-04 13:18:37 -05:00
|
|
|
ipapolicy_dict['ipagroupobjectclasses'] = [ipapolicy_dict.get('ipagroupobjectclasses')]
|
|
|
|
|
ipapolicy_dict['groupobjectclasses'] = ipahelper.setup_mv_fields(ipapolicy_dict.get('ipagroupobjectclasses'), 'ipagroupobjectclasses')
|
|
|
|
|
|
2007-11-12 14:19:05 -05:00
|
|
|
return dict(form=ipapolicy_edit_form, ipapolicy=ipapolicy_dict)
|
|
|
|
|
except ipaerror.IPAError, e:
|
|
|
|
|
turbogears.flash("IPA Policy edit failed: " + str(e) + "<br/>" + str(e.detail))
|
2007-11-16 12:59:32 -05:00
|
|
|
raise turbogears.redirect('/ipapolicy/show')
|
2007-11-12 14:19:05 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@expose()
|
2007-11-14 10:49:03 -05:00
|
|
|
@identity.require(identity.in_group("admins"))
|
2007-11-12 14:19:05 -05:00
|
|
|
def update(self, **kw):
|
|
|
|
|
"""Display delegate page"""
|
|
|
|
|
self.restrict_post()
|
|
|
|
|
client = self.get_ipaclient()
|
|
|
|
|
|
|
|
|
|
if kw.get('submit', '').startswith('Cancel'):
|
|
|
|
|
turbogears.flash("Edit policy cancelled")
|
|
|
|
|
raise turbogears.redirect('/ipapolicy/show')
|
|
|
|
|
|
2007-12-04 13:18:37 -05:00
|
|
|
# Fix incoming multi-valued fields we created for the form
|
|
|
|
|
kw = ipahelper.fix_incoming_fields(kw, 'ipauserobjectclasses', 'userobjectclasses')
|
|
|
|
|
kw = ipahelper.fix_incoming_fields(kw, 'ipagroupobjectclasses', 'groupobjectclasses')
|
|
|
|
|
|
2007-11-12 14:19:05 -05:00
|
|
|
tg_errors, kw = self.ipapolicyupdatevalidate(**kw)
|
|
|
|
|
if tg_errors:
|
|
|
|
|
turbogears.flash("There were validation errors.<br/>" +
|
|
|
|
|
"Please see the messages below for details.")
|
|
|
|
|
return dict(form=ipapolicy_edit_form, ipapolicy=kw,
|
|
|
|
|
tg_template='ipagui.templates.ipapolicyedit')
|
|
|
|
|
|
2007-11-16 12:59:32 -05:00
|
|
|
policy_modified = False
|
|
|
|
|
password_modified = False
|
2007-11-12 14:19:05 -05:00
|
|
|
|
2007-11-16 12:59:32 -05:00
|
|
|
try:
|
|
|
|
|
orig_ipapolicy_dict = loads(b64decode(kw.get('ipapolicy_orig')))
|
|
|
|
|
orig_password_dict = loads(b64decode(kw.get('password_orig')))
|
|
|
|
|
|
|
|
|
|
new_ipapolicy = ipa.entity.Entity(orig_ipapolicy_dict)
|
|
|
|
|
new_password = ipa.entity.Entity(orig_password_dict)
|
2007-11-30 13:27:33 -05:00
|
|
|
|
2008-02-18 17:41:58 -05:00
|
|
|
if str(new_ipapolicy.getValues('ipasearchtimelimit')) != str(kw.get('ipasearchtimelimit')):
|
2007-11-16 12:59:32 -05:00
|
|
|
policy_modified = True
|
|
|
|
|
new_ipapolicy.setValue('ipasearchtimelimit', kw.get('ipasearchtimelimit'))
|
2008-02-18 17:41:58 -05:00
|
|
|
if str(new_ipapolicy.getValues('ipasearchrecordslimit')) != str(kw.get('ipasearchrecordslimit')):
|
2007-11-16 12:59:32 -05:00
|
|
|
policy_modified = True
|
|
|
|
|
new_ipapolicy.setValue('ipasearchrecordslimit', kw.get('ipasearchrecordslimit'))
|
2008-02-18 17:41:58 -05:00
|
|
|
if new_ipapolicy.getValues('ipausersearchfields') != kw.get('ipausersearchfields'):
|
2007-11-16 12:59:32 -05:00
|
|
|
policy_modified = True
|
|
|
|
|
new_ipapolicy.setValue('ipausersearchfields', kw.get('ipausersearchfields'))
|
2008-02-18 17:41:58 -05:00
|
|
|
if new_ipapolicy.getValues('ipagroupsearchfields') != kw.get('ipagroupsearchfields'):
|
2007-11-16 12:59:32 -05:00
|
|
|
policy_modified = True
|
|
|
|
|
new_ipapolicy.setValue('ipagroupsearchfields', kw.get('ipagroupsearchfields'))
|
2008-02-18 17:41:58 -05:00
|
|
|
if str(new_ipapolicy.getValues('ipapwdexpadvnotify')) != str(kw.get('ipapwdexpadvnotify')):
|
2007-11-16 12:59:32 -05:00
|
|
|
policy_modified = True
|
|
|
|
|
new_ipapolicy.setValue('ipapwdexpadvnotify', kw.get('ipapwdexpadvnotify'))
|
2008-02-18 17:41:58 -05:00
|
|
|
if str(new_ipapolicy.getValues('ipamaxusernamelength')) != str(kw.get('ipamaxusernamelength')):
|
2007-11-16 12:59:32 -05:00
|
|
|
policy_modified = True
|
|
|
|
|
new_ipapolicy.setValue('ipamaxusernamelength', kw.get('ipamaxusernamelength'))
|
2008-02-18 17:41:58 -05:00
|
|
|
if new_ipapolicy.getValues('ipahomesrootdir') != kw.get('ipahomesrootdir'):
|
2007-11-16 12:59:32 -05:00
|
|
|
policy_modified = True
|
|
|
|
|
new_ipapolicy.setValue('ipahomesrootdir', kw.get('ipahomesrootdir'))
|
2008-02-18 17:41:58 -05:00
|
|
|
if new_ipapolicy.getValues('ipadefaultloginshell') != kw.get('ipadefaultloginshell'):
|
2007-11-16 12:59:32 -05:00
|
|
|
policy_modified = True
|
|
|
|
|
new_ipapolicy.setValue('ipadefaultloginshell', kw.get('ipadefaultloginshell'))
|
2008-02-18 17:41:58 -05:00
|
|
|
if new_ipapolicy.getValues('ipadefaultprimarygroup') != kw.get('ipadefaultprimarygroup'):
|
2007-11-16 12:59:32 -05:00
|
|
|
policy_modified = True
|
|
|
|
|
new_ipapolicy.setValue('ipadefaultprimarygroup', kw.get('ipadefaultprimarygroup'))
|
2008-02-18 17:41:58 -05:00
|
|
|
if new_ipapolicy.getValues('ipauserobjectclasses') != kw.get('ipauserobjectclasses'):
|
2007-12-04 13:18:37 -05:00
|
|
|
policy_modified = True
|
|
|
|
|
new_ipapolicy.setValue('ipauserobjectclasses', kw.get('ipauserobjectclasses'))
|
2008-02-18 17:41:58 -05:00
|
|
|
if new_ipapolicy.getValues('ipagroupobjectclasses') != kw.get('ipagroupobjectclasses'):
|
2007-12-04 13:18:37 -05:00
|
|
|
policy_modified = True
|
|
|
|
|
new_ipapolicy.setValue('ipagroupobjectclasses', kw.get('ipagroupobjectclasses'))
|
2008-02-18 17:41:58 -05:00
|
|
|
if new_ipapolicy.getValues('ipadefaultemaildomain') != kw.get('ipadefaultemaildomain'):
|
2007-12-10 11:53:00 -05:00
|
|
|
policy_modified = True
|
|
|
|
|
new_ipapolicy.setValue('ipadefaultemaildomain', kw.get('ipadefaultemaildomain'))
|
2007-11-16 12:59:32 -05:00
|
|
|
|
|
|
|
|
if policy_modified:
|
|
|
|
|
rv = client.update_ipa_config(new_ipapolicy)
|
|
|
|
|
|
|
|
|
|
# Now check the password policy for updates
|
2008-02-18 17:41:58 -05:00
|
|
|
if str(new_password.getValues('krbmaxpwdlife')) != str(kw.get('krbmaxpwdlife')):
|
2007-11-16 12:59:32 -05:00
|
|
|
password_modified = True
|
|
|
|
|
new_password.setValue('krbmaxpwdlife', str(kw.get('krbmaxpwdlife')))
|
2008-02-18 17:41:58 -05:00
|
|
|
if str(new_password.getValues('krbminpwdlife')) != str(kw.get('krbminpwdlife')):
|
2007-11-16 12:59:32 -05:00
|
|
|
password_modified = True
|
|
|
|
|
new_password.setValue('krbminpwdlife', str(kw.get('krbminpwdlife')))
|
2008-02-18 17:41:58 -05:00
|
|
|
if str(new_password.getValues('krbpwdhistorylength')) != str(kw.get('krbpwdhistorylength')):
|
2007-11-16 12:59:32 -05:00
|
|
|
password_modified = True
|
|
|
|
|
new_password.setValue('krbpwdhistorylength', str(kw.get('krbpwdhistorylength')))
|
2008-02-18 17:41:58 -05:00
|
|
|
if str(new_password.getValues('krbpwdmindiffchars')) != str(kw.get('krbpwdmindiffchars')):
|
2007-11-16 12:59:32 -05:00
|
|
|
password_modified = True
|
|
|
|
|
new_password.setValue('krbpwdmindiffchars', str(kw.get('krbpwdmindiffchars')))
|
2008-02-18 17:41:58 -05:00
|
|
|
if str(new_password.getValues('krbpwdminlength')) != str(kw.get('krbpwdminlength')):
|
2007-11-16 12:59:32 -05:00
|
|
|
password_modified = True
|
|
|
|
|
new_password.setValue('krbpwdminlength', str(kw.get('krbpwdminlength')))
|
|
|
|
|
if password_modified:
|
|
|
|
|
rv = client.update_password_policy(new_password)
|
2007-11-12 14:19:05 -05:00
|
|
|
|
|
|
|
|
turbogears.flash("IPA Policy updated")
|
|
|
|
|
raise turbogears.redirect('/ipapolicy/show')
|
2007-11-16 12:59:32 -05:00
|
|
|
except ipaerror.IPAError, e:
|
2008-03-25 09:48:23 -04:00
|
|
|
turbogears.flash("Policy update failed: " + str(e) + "<br/>" + e.detail[0].get('desc','') + ". " + e.detail[0].get('info',''))
|
2007-11-16 12:59:32 -05:00
|
|
|
return dict(form=ipapolicy_edit_form, ipapolicy=kw,
|
|
|
|
|
tg_template='ipagui.templates.ipapolicyedit')
|
2007-11-12 14:19:05 -05:00
|
|
|
|
|
|
|
|
@validate(form=ipapolicy_edit_form)
|
|
|
|
|
@identity.require(identity.not_anonymous())
|
|
|
|
|
def ipapolicyupdatevalidate(self, tg_errors=None, **kw):
|
|
|
|
|
return tg_errors, kw
|