rem
stringlengths 0
322k
| add
stringlengths 0
2.05M
| context
stringlengths 8
228k
|
---|---|---|
raise exceptions.LicornRuntimeException, "The group %s doesn't exist." % name | raise exceptions.LicornRuntimeException( "The group '%s' doesn't exist." % name) | def is_system_group(name): """ Return true if group is system. """ try: return GroupsController.is_system_gid(GroupsController.name_to_gid(name)) except KeyError: raise exceptions.LicornRuntimeException, "The group %s doesn't exist." % name |
raise exceptions.LicornRuntimeException, "The group `%s' doesn't exist." % name | raise exceptions.LicornRuntimeException( "The group '%s' doesn't exist." % name) | def is_standard_group(name): """ Return true if group is system. """ try: return GroupsController.is_standard_gid(GroupsController.name_to_gid(name)) except KeyError: raise exceptions.LicornRuntimeException, "The group `%s' doesn't exist." % name |
raise exceptions.LicornRuntimeException, "The group `%s' doesn't exist." % name | raise exceptions.LicornRuntimeException( "The group '%s' doesn't exist." % name) | def is_empty_group(name): try: return GroupsController.is_empty_gid(GroupsController.name_to_gid(name)) except KeyError: raise exceptions.LicornRuntimeException, "The group `%s' doesn't exist." % name |
raise exceptions.LicornRuntimeError('''Can't build a valid UNIX group name (got %s, which doesn't verify %s) with the string you provided "%s".''' % (groupname, hlstr.regex['group_name'], inputname) ) | raise exceptions.LicornRuntimeError( '''Can't build a valid UNIX group name (got %s, ''' '''which doesn't verify %s) with the string you ''' '''provided "%s".''' % ( groupname, hlstr.regex['group_name'], inputname) ) | def make_name(inputname): """ Make a valid login from user's firstname and lastname.""" |
members = groups.all_members(name) | members = list(groups.all_members(name)) | def view(uri, http_user, name): """Prepare a group view to be printed.""" users.reload() groups.reload() title = _("Details of group %s") % name data = w.page_body_start(uri, http_user, ctxtnav, title) u = users.users g = groups.groups # TODO: should we forbid system group view ? why not ? # As of now, this is harmless and I don't see any reason # apart from obfuscation which is not acceptable. # Anyway, to see a system group, user must forge an URL. try: group = g[groups.name_to_gid(name)] members = groups.all_members(name) if members != []: members.sort() members_html = ''' <h2>%s</h2> <div style="text-align:left;">%s</div> <table class="group_members"> <tr> <th><strong>%s</strong></th> <th><strong>%s</strong></th> <th><strong>%s</strong></th> </tr> ''' % ( _('Members'), _('(ordered by login)'), _('Full Name'), _('Identifier'), _('UID') ) def user_line(login): uid = users.login_to_uid(login) return '''<tr> <td>%s</td> <td>%s</td> <td>%s</td> </tr>''' % ( u[uid]['gecos'], login, uid ) members_html += "\n".join(map(user_line, members)) + '</table>' else: members_html = "<h2>%s</h2>" % _('No members in this group.') if not groups.is_system_group(name): resps = groups.all_members(configuration.groups.resp_prefix + name) if resps != []: resps.sort() resps_html = ''' <h2>%s</h2> <div style="text-align:left;">%s</div> <table class="group_members"> <tr> <th><strong>%s</strong></th> <th><strong>%s</strong></th> <th><strong>%s</strong></th> </tr> %s </table> ''' % ( _('Responsibles'), _('(ordered by login)'), _('Full Name'), _('Identifier'), _('UID'), "\n".join(map(user_line, resps)) ) else: resps_html = "<h2>%s</h2>" % \ _('No responsibles for this group.') guests = \ groups.all_members(configuration.groups.guest_prefix + name) if guests != []: guests.sort() guests_html = ''' <h2>%s</h2> <div style="text-align:left;">%s</div> <table class="group_members"> <tr> <th><strong>%s</strong></th> <th><strong>%s</strong></th> <th><strong>%s</strong></th> </tr> %s </table> ''' % ( _('Guests'), _('(ordered by login)'), _('Full Name'), _('Identifier'), _('UID'), "\n".join(map(user_line, guests)) ) else: guests_html = "<h2>%s</h2>" % _('No guests in this group.') else: resps_html = guests_html = '' form_name = "group_print_form" data += ''' <div id="details"> <form name="%s" id="%s" action="/groups/view/%s" method="post"> <table id="user_account"> <tr><td><strong>%s</strong><br />%s</td> <td class="not_modifiable">%d</td></tr> <tr><td><strong>%s</strong><br />%s</td> <td class="not_modifiable">%s</td></tr> <tr><td colspan="2" class="double_selector">%s</td></tr> <tr><td colspan="2" class="double_selector">%s</td></tr> <tr><td colspan="2" class="double_selector">%s</td></tr> <tr> <td>%s</td> <td class="right">%s</td> </tr> </table> </form> </div> ''' % ( form_name, form_name, name, _('GID'), _('immutable'), group['gidNumber'], _('Name'), _('immutable'), name, members_html, resps_html, guests_html, w.button(_('<< Go back'), "/groups/list", accesskey=_('B')), w.submit('print', _('Print') + ' >>', onClick="javascript:window.print(); return false;", accesskey=_('P')) ) except exceptions.LicornException, e: data += w.error(_("Group %s doesn't exist (%s, %s)!") % ( name, "group = g[groups.name_to_gid(name)]", e)) return (w.HTTP_TYPE_TEXT, w.page(title, data + w.page_body_end())) |
resps = groups.all_members(configuration.groups.resp_prefix + name) | resps = list( groups.all_members(configuration.groups.resp_prefix + name)) | def user_line(login): uid = users.login_to_uid(login) return '''<tr> <td>%s</td> <td>%s</td> <td>%s</td> </tr>''' % ( u[uid]['gecos'], login, uid ) |
guests = \ groups.all_members(configuration.groups.guest_prefix + name) | guests = list( groups.all_members(configuration.groups.guest_prefix + name)) | def user_line(login): uid = users.login_to_uid(login) return '''<tr> <td>%s</td> <td>%s</td> <td>%s</td> </tr>''' % ( u[uid]['gecos'], login, uid ) |
dest = g[groups.name_to_gid(gname)]['memberUid'][:] | dest = list(g[groups.name_to_gid(gname)]['memberUid']) | def edit(uri, http_user, name): """Edit a group.""" users.reload() groups.reload() u = users.users g = groups.groups title = _("Editing group %s") % name data = w.page_body_start(uri, http_user, ctxtnav, title, False) try: group = g[groups.name_to_gid(name)] sys = groups.is_system_group(name) dbl_lists = {} if sys: groups_filters_lists_ids = ( (name, ( _('Manage members'), _('Users not yet members'), _('Current members') ), 'members' ), (configuration.groups.resp_prefix + name, None, ' ' ), (configuration.groups.guest_prefix + name, None, ' ' ) ) else: groups_filters_lists_ids = ( (name, [_('Manage members'), _('Users not yet members'), _('Current members')], 'members'), (configuration.groups.resp_prefix + name, [_('Manage responsibles'), _('Users not yet responsibles'), _('Current responsibles')], 'resps'), (configuration.groups.guest_prefix + name, [_('Manage guests'), _('Users not yet guests'), _('Current guests')], 'guests') ) for (gname, titles, id) in groups_filters_lists_ids: if titles is None: dbl_lists[gname] = id else: users.Select(users.FILTER_STANDARD) dest = g[groups.name_to_gid(gname)]['memberUid'][:] source = [ u[uid]['login'] for uid in users.filtered_users ] for current in g[groups.name_to_gid(gname)]['memberUid']: try: source.remove(current) except ValueError: dest.remove(current) dest.sort() source.sort() dbl_lists[gname] = w.doubleListBox(titles, id, source, dest) def descr(desc, system): return w.input('description', desc, size=30, maxlength=256, accesskey='D') def skel(cur_skel, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Skeleton'), w.select('skel', configuration.users.skels, cur_skel, func = os.path.basename)) def permissive(perm, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Permissive shared dir?'), w.checkbox('permissive', "True", "Oui", checked = perm )) form_name = "group_edit_form" data += '''<div id="edit_form"> |
dest = g[groups.name_to_gid(gname)]['members'][:] | dest = g[groups.name_to_gid(gname)]['memberUid'][:] | def edit(uri, http_user, name): """Edit a group.""" users.reload() groups.reload() u = users.users g = groups.groups title = _("Editing group %s") % name data = w.page_body_start(uri, http_user, ctxtnav, title, False) try: group = g[groups.name_to_gid(name)] sys = groups.is_system_group(name) dbl_lists = {} if sys: groups_filters_lists_ids = ( (name, ( _('Manage members'), _('Users not yet members'), _('Current members') ), 'members' ), (configuration.groups.resp_prefix + name, None, ' ' ), (configuration.groups.guest_prefix + name, None, ' ' ) ) else: groups_filters_lists_ids = ( (name, [_('Manage members'), _('Users not yet members'), _('Current members')], 'members'), (configuration.groups.resp_prefix + name, [_('Manage responsibles'), _('Users not yet responsibles'), _('Current responsibles')], 'resps'), (configuration.groups.guest_prefix + name, [_('Manage guests'), _('Users not yet guests'), _('Current guests')], 'guests') ) for (gname, titles, id) in groups_filters_lists_ids: if titles is None: dbl_lists[gname] = id else: users.Select(users.FILTER_STANDARD) dest = g[groups.name_to_gid(gname)]['members'][:] source = [ u[uid]['login'] for uid in users.filtered_users ] for current in g[groups.name_to_gid(gname)]['members']: try: source.remove(current) except ValueError: dest.remove(current) dest.sort() source.sort() dbl_lists[gname] = w.doubleListBox(titles, id, source, dest) def descr(desc, system): return w.input('description', desc, size=30, maxlength=256, accesskey='D') def skel(cur_skel, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Skeleton'), w.select('skel', configuration.users.skels, cur_skel, func = os.path.basename)) def permissive(perm, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Permissive shared dir?'), w.checkbox('permissive', "True", "Oui", checked = perm )) form_name = "group_edit_form" data += '''<div id="edit_form"> |
for current in g[groups.name_to_gid(gname)]['members']: | for current in g[groups.name_to_gid(gname)]['memberUid']: | def edit(uri, http_user, name): """Edit a group.""" users.reload() groups.reload() u = users.users g = groups.groups title = _("Editing group %s") % name data = w.page_body_start(uri, http_user, ctxtnav, title, False) try: group = g[groups.name_to_gid(name)] sys = groups.is_system_group(name) dbl_lists = {} if sys: groups_filters_lists_ids = ( (name, ( _('Manage members'), _('Users not yet members'), _('Current members') ), 'members' ), (configuration.groups.resp_prefix + name, None, ' ' ), (configuration.groups.guest_prefix + name, None, ' ' ) ) else: groups_filters_lists_ids = ( (name, [_('Manage members'), _('Users not yet members'), _('Current members')], 'members'), (configuration.groups.resp_prefix + name, [_('Manage responsibles'), _('Users not yet responsibles'), _('Current responsibles')], 'resps'), (configuration.groups.guest_prefix + name, [_('Manage guests'), _('Users not yet guests'), _('Current guests')], 'guests') ) for (gname, titles, id) in groups_filters_lists_ids: if titles is None: dbl_lists[gname] = id else: users.Select(users.FILTER_STANDARD) dest = g[groups.name_to_gid(gname)]['members'][:] source = [ u[uid]['login'] for uid in users.filtered_users ] for current in g[groups.name_to_gid(gname)]['members']: try: source.remove(current) except ValueError: dest.remove(current) dest.sort() source.sort() dbl_lists[gname] = w.doubleListBox(titles, id, source, dest) def descr(desc, system): return w.input('description', desc, size=30, maxlength=256, accesskey='D') def skel(cur_skel, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Skeleton'), w.select('skel', configuration.users.skels, cur_skel, func = os.path.basename)) def permissive(perm, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Permissive shared dir?'), w.checkbox('permissive', "True", "Oui", checked = perm )) form_name = "group_edit_form" data += '''<div id="edit_form"> |
skel(group['skel'], sys), | skel(group['groupSkel'], sys), | def permissive(perm, system): |
'skel' : group['skel'] + name, | 'skel' : group['groupSkel'] + name, | def main(uri, http_user, sort = "name", order = "asc"): """List all groups and provileges on the system, displaying them in a nice HTML page. """ start = time.time() users.reload() groups.reload() #profiles.reload() g = groups.groups users.Select(users.FILTER_STANDARD) tgroups = {} totals = {} title = _('Groups') data = w.page_body_start(uri, http_user, ctxtnav, title) if order == "asc": reverseorder = "desc" else: reverseorder = "asc" data += '<table>\n <tr>\n' sortcols = ( ('', '', False), ("name", _("Name"), True), ("description", _("Description"), True), ("skel", _("Skeleton"), True), ("permissive", _("Perm."), True), ('members', _("Members"), False), ("resps", _("Responsibles"), False), ("guests", _("Guests"), False) ) for (column, name, can_sort) in sortcols: if can_sort: if column == sort: data += ''' <th><img src="/images/sort_%s.gif" alt="%s" />  <a href="/groups/list/%s/%s" title="%s">%s</a> </th>\n''' % (order, _('%s order') % order, column, reverseorder, _('Click to sort in reverse order.'), name) else: data += ''' <th><a href="/groups/list/%s/asc" title="%s">%s</a></th>\n''' % (column, _('Click to sort on this column.'), name) else: data += ' <th>%s</th>\n' % name data += ' </tr>\n' for (filter, filter_name) in ( (groups.FILTER_STANDARD, _('Groups')), (groups.FILTER_PRIVILEGED, _("Privileges")) ): tgroups = {} ordered = {} totals[filter_name] = 0 groups.Select(filter) for gid in groups.filtered_groups: group = groups.groups[gid] name = group['name'] tgroups[gid] = { 'name' : name, 'description' : group['description'] + name, 'skel' : group['skel'] + name, 'permissive' : str(group['permissive']) + name } totals[filter_name] += 1 # index on the column choosen for sorting, and keep trace of the uid # to find account data back after ordering. ordered[hlstr.validate_name(tgroups[gid][sort])] = gid tgroups[gid]['members'] = [] for member in groups.groups[gid]['members']: if not users.is_system_login(member): tgroups[gid]['members'].append( users.users[users.login_to_uid(member)]) if not groups.is_system_gid(gid): for prefix in ( configuration.groups.resp_prefix, configuration.groups.guest_prefix): tgroups[gid][prefix + 'members'] = [] for member in \ groups.groups[groups.name_to_gid( prefix + name)]['members']: if not users.is_system_login(member): tgroups[gid][prefix + 'members'].append( users.users[users.login_to_uid(member)]) gkeys = ordered.keys() gkeys.sort() if order == "desc": gkeys.reverse() def html_build_group(index, tgroups = tgroups ): gid = ordered[index] name = g[gid]['name'] html_data = ''' <tr class="userdata"> <td class="nopadding"> <a href="/groups/view/%s" title="%s" class="view-entry"> <span class="view-entry"> </span> </a> </td> <td class="group_name"> <a href="/groups/edit/%s" title="%s" class="edit-entry">%s</a> </td> <td class="group_name"> <a href="/groups/edit/%s" title="%s" class="edit-entry">%s</a> </td> <td class="right"> <a href="/groups/edit/%s">%s</a> </td> ''' % ( name, _('''View the group details, its parameters, members, responsibles and guests. From there you can print all group-related informations.'''), name, g[gid]['description'], name, name, g[gid]['description'], g[gid]['description'], name, g[gid]['skel']) if groups.is_system_gid(gid): html_data += '<td> </td>' else: if g[gid]['permissive']: html_data += ''' <td class="user_action_center"> <a href="/groups/lock/%s" title="%s"> <img src="/images/16x16/unlocked.png" alt="%s"/></a> </td> ''' % (name, _('''Shared group directory is currently ''' '''<strong>permissive</strong>. Click to deactivate ''' '''permissiveness.'''), _('Group is currently permissive.')) else: html_data += ''' <td class="user_action_center"> <a href="/groups/unlock/%s" title="%s"> <img src="/images/16x16/locked.png" alt="%s"/></a> </td> ''' % (name, _('''Shared group directory is currently <strong>NOT</strong> permissive. Click ti activate permissiveness.'''), _('Group is NOT permissive.')) for (keyname, text) in ( ('members', _('Current members')), ('rsp-members', _('Current responsibles')), ('gst-members', _('Current guests')) ): if tgroups[gid].has_key(keyname): accounts = {} uordered = {} for member in tgroups[gid][keyname]: uid = member['uidNumber'] accounts[uid] = { 'login': member['login'], 'gecos': member['gecos'], 'gecos_sort': member['gecos'] + member['login'] } uordered[hlstr.validate_name( accounts[uid]['gecos_sort'], aggressive=True)] = uid memberkeys = uordered.keys() memberkeys.sort() mbdata = '''<table><tr><th>%s</th><th>%s</th> <th>%s</th></tr>\n''' % (_('Full Name'), _('Identifier'), _('UID')) for member in memberkeys: uid = uordered[member] mbdata += '''<tr><td>%s</td><td>%s</td> <td>%d</td></tr>\n''' % (accounts[uid]['gecos'], accounts[uid]['login'], uid) mbdata += '</table>' nb = len(tgroups[gid][keyname]) if nb == 0: html_data += '''<td class="right faded">%s</td>\n''' % \ _('none') else: html_data += '''<td class="right"> <a class="nounder" title="<h4>%s</h4><br />%s"> <strong>%d</strong> <img src="/images/16x16/details-light.png" alt="%s" /></a></td>\n''' % (text, mbdata, nb, _('See %s of group %s.') % (text, name)) else: html_data += '''<td> </td>\n''' if groups.is_system_gid(gid): html_data += '<td colspan="1"> </td></tr>\n' else: html_data += ''' <!-- TODO: implement skel reapplying for all users of curent group <td class="user_action"> <a href="/users/skel/%s" title="%s" class="reapply-skel"> <span class="reapply-skel"> </span> </a> </td> --> <td class="user_action"> <a href="/groups/delete/%s" title="%s" class="delete-entry"> <span class="delete-entry"> </span> </a> </td> </tr> ''' % (name, _('''This will rebuild his/her desktop from scratch, with defaults icons and so on. <br /><br />The user must be disconnected for the operation to be completely successfull.'''), name, _('''Definitely remove this group from system.''')) return html_data data += '<tr><td class="group_class" colspan="8">%s</td></tr>\n%s' % ( filter_name, ''.join(map(html_build_group, gkeys))) def print_totals(totals): output = "" for total in totals: if totals[total] != 0: output += ''' <tr class="list_total"> <td colspan="6" class="total_left">%s</td> <td colspan="6" class="total_right">%d</td> </tr> ''' % (_('number of <strong>%s</strong>:') % total, totals[total]) return output data += ''' <tr> <td colspan="6"> </td></tr> %s <tr class="list_total"> <td colspan="6" class="total_left"><strong>%s</strong></td> <td colspan="6" class="total_right">%d</td> </tr> |
tgroups[gid]['members'] = [] for member in groups.groups[gid]['members']: | tgroups[gid]['memberUid'] = [] for member in groups.groups[gid]['memberUid']: | def main(uri, http_user, sort = "name", order = "asc"): """List all groups and provileges on the system, displaying them in a nice HTML page. """ start = time.time() users.reload() groups.reload() #profiles.reload() g = groups.groups users.Select(users.FILTER_STANDARD) tgroups = {} totals = {} title = _('Groups') data = w.page_body_start(uri, http_user, ctxtnav, title) if order == "asc": reverseorder = "desc" else: reverseorder = "asc" data += '<table>\n <tr>\n' sortcols = ( ('', '', False), ("name", _("Name"), True), ("description", _("Description"), True), ("skel", _("Skeleton"), True), ("permissive", _("Perm."), True), ('members', _("Members"), False), ("resps", _("Responsibles"), False), ("guests", _("Guests"), False) ) for (column, name, can_sort) in sortcols: if can_sort: if column == sort: data += ''' <th><img src="/images/sort_%s.gif" alt="%s" />  <a href="/groups/list/%s/%s" title="%s">%s</a> </th>\n''' % (order, _('%s order') % order, column, reverseorder, _('Click to sort in reverse order.'), name) else: data += ''' <th><a href="/groups/list/%s/asc" title="%s">%s</a></th>\n''' % (column, _('Click to sort on this column.'), name) else: data += ' <th>%s</th>\n' % name data += ' </tr>\n' for (filter, filter_name) in ( (groups.FILTER_STANDARD, _('Groups')), (groups.FILTER_PRIVILEGED, _("Privileges")) ): tgroups = {} ordered = {} totals[filter_name] = 0 groups.Select(filter) for gid in groups.filtered_groups: group = groups.groups[gid] name = group['name'] tgroups[gid] = { 'name' : name, 'description' : group['description'] + name, 'skel' : group['skel'] + name, 'permissive' : str(group['permissive']) + name } totals[filter_name] += 1 # index on the column choosen for sorting, and keep trace of the uid # to find account data back after ordering. ordered[hlstr.validate_name(tgroups[gid][sort])] = gid tgroups[gid]['members'] = [] for member in groups.groups[gid]['members']: if not users.is_system_login(member): tgroups[gid]['members'].append( users.users[users.login_to_uid(member)]) if not groups.is_system_gid(gid): for prefix in ( configuration.groups.resp_prefix, configuration.groups.guest_prefix): tgroups[gid][prefix + 'members'] = [] for member in \ groups.groups[groups.name_to_gid( prefix + name)]['members']: if not users.is_system_login(member): tgroups[gid][prefix + 'members'].append( users.users[users.login_to_uid(member)]) gkeys = ordered.keys() gkeys.sort() if order == "desc": gkeys.reverse() def html_build_group(index, tgroups = tgroups ): gid = ordered[index] name = g[gid]['name'] html_data = ''' <tr class="userdata"> <td class="nopadding"> <a href="/groups/view/%s" title="%s" class="view-entry"> <span class="view-entry"> </span> </a> </td> <td class="group_name"> <a href="/groups/edit/%s" title="%s" class="edit-entry">%s</a> </td> <td class="group_name"> <a href="/groups/edit/%s" title="%s" class="edit-entry">%s</a> </td> <td class="right"> <a href="/groups/edit/%s">%s</a> </td> ''' % ( name, _('''View the group details, its parameters, members, responsibles and guests. From there you can print all group-related informations.'''), name, g[gid]['description'], name, name, g[gid]['description'], g[gid]['description'], name, g[gid]['skel']) if groups.is_system_gid(gid): html_data += '<td> </td>' else: if g[gid]['permissive']: html_data += ''' <td class="user_action_center"> <a href="/groups/lock/%s" title="%s"> <img src="/images/16x16/unlocked.png" alt="%s"/></a> </td> ''' % (name, _('''Shared group directory is currently ''' '''<strong>permissive</strong>. Click to deactivate ''' '''permissiveness.'''), _('Group is currently permissive.')) else: html_data += ''' <td class="user_action_center"> <a href="/groups/unlock/%s" title="%s"> <img src="/images/16x16/locked.png" alt="%s"/></a> </td> ''' % (name, _('''Shared group directory is currently <strong>NOT</strong> permissive. Click ti activate permissiveness.'''), _('Group is NOT permissive.')) for (keyname, text) in ( ('members', _('Current members')), ('rsp-members', _('Current responsibles')), ('gst-members', _('Current guests')) ): if tgroups[gid].has_key(keyname): accounts = {} uordered = {} for member in tgroups[gid][keyname]: uid = member['uidNumber'] accounts[uid] = { 'login': member['login'], 'gecos': member['gecos'], 'gecos_sort': member['gecos'] + member['login'] } uordered[hlstr.validate_name( accounts[uid]['gecos_sort'], aggressive=True)] = uid memberkeys = uordered.keys() memberkeys.sort() mbdata = '''<table><tr><th>%s</th><th>%s</th> <th>%s</th></tr>\n''' % (_('Full Name'), _('Identifier'), _('UID')) for member in memberkeys: uid = uordered[member] mbdata += '''<tr><td>%s</td><td>%s</td> <td>%d</td></tr>\n''' % (accounts[uid]['gecos'], accounts[uid]['login'], uid) mbdata += '</table>' nb = len(tgroups[gid][keyname]) if nb == 0: html_data += '''<td class="right faded">%s</td>\n''' % \ _('none') else: html_data += '''<td class="right"> <a class="nounder" title="<h4>%s</h4><br />%s"> <strong>%d</strong> <img src="/images/16x16/details-light.png" alt="%s" /></a></td>\n''' % (text, mbdata, nb, _('See %s of group %s.') % (text, name)) else: html_data += '''<td> </td>\n''' if groups.is_system_gid(gid): html_data += '<td colspan="1"> </td></tr>\n' else: html_data += ''' <!-- TODO: implement skel reapplying for all users of curent group <td class="user_action"> <a href="/users/skel/%s" title="%s" class="reapply-skel"> <span class="reapply-skel"> </span> </a> </td> --> <td class="user_action"> <a href="/groups/delete/%s" title="%s" class="delete-entry"> <span class="delete-entry"> </span> </a> </td> </tr> ''' % (name, _('''This will rebuild his/her desktop from scratch, with defaults icons and so on. <br /><br />The user must be disconnected for the operation to be completely successfull.'''), name, _('''Definitely remove this group from system.''')) return html_data data += '<tr><td class="group_class" colspan="8">%s</td></tr>\n%s' % ( filter_name, ''.join(map(html_build_group, gkeys))) def print_totals(totals): output = "" for total in totals: if totals[total] != 0: output += ''' <tr class="list_total"> <td colspan="6" class="total_left">%s</td> <td colspan="6" class="total_right">%d</td> </tr> ''' % (_('number of <strong>%s</strong>:') % total, totals[total]) return output data += ''' <tr> <td colspan="6"> </td></tr> %s <tr class="list_total"> <td colspan="6" class="total_left"><strong>%s</strong></td> <td colspan="6" class="total_right">%d</td> </tr> |
tgroups[gid]['members'].append( | tgroups[gid]['memberUid'].append( | def main(uri, http_user, sort = "name", order = "asc"): """List all groups and provileges on the system, displaying them in a nice HTML page. """ start = time.time() users.reload() groups.reload() #profiles.reload() g = groups.groups users.Select(users.FILTER_STANDARD) tgroups = {} totals = {} title = _('Groups') data = w.page_body_start(uri, http_user, ctxtnav, title) if order == "asc": reverseorder = "desc" else: reverseorder = "asc" data += '<table>\n <tr>\n' sortcols = ( ('', '', False), ("name", _("Name"), True), ("description", _("Description"), True), ("skel", _("Skeleton"), True), ("permissive", _("Perm."), True), ('members', _("Members"), False), ("resps", _("Responsibles"), False), ("guests", _("Guests"), False) ) for (column, name, can_sort) in sortcols: if can_sort: if column == sort: data += ''' <th><img src="/images/sort_%s.gif" alt="%s" />  <a href="/groups/list/%s/%s" title="%s">%s</a> </th>\n''' % (order, _('%s order') % order, column, reverseorder, _('Click to sort in reverse order.'), name) else: data += ''' <th><a href="/groups/list/%s/asc" title="%s">%s</a></th>\n''' % (column, _('Click to sort on this column.'), name) else: data += ' <th>%s</th>\n' % name data += ' </tr>\n' for (filter, filter_name) in ( (groups.FILTER_STANDARD, _('Groups')), (groups.FILTER_PRIVILEGED, _("Privileges")) ): tgroups = {} ordered = {} totals[filter_name] = 0 groups.Select(filter) for gid in groups.filtered_groups: group = groups.groups[gid] name = group['name'] tgroups[gid] = { 'name' : name, 'description' : group['description'] + name, 'skel' : group['skel'] + name, 'permissive' : str(group['permissive']) + name } totals[filter_name] += 1 # index on the column choosen for sorting, and keep trace of the uid # to find account data back after ordering. ordered[hlstr.validate_name(tgroups[gid][sort])] = gid tgroups[gid]['members'] = [] for member in groups.groups[gid]['members']: if not users.is_system_login(member): tgroups[gid]['members'].append( users.users[users.login_to_uid(member)]) if not groups.is_system_gid(gid): for prefix in ( configuration.groups.resp_prefix, configuration.groups.guest_prefix): tgroups[gid][prefix + 'members'] = [] for member in \ groups.groups[groups.name_to_gid( prefix + name)]['members']: if not users.is_system_login(member): tgroups[gid][prefix + 'members'].append( users.users[users.login_to_uid(member)]) gkeys = ordered.keys() gkeys.sort() if order == "desc": gkeys.reverse() def html_build_group(index, tgroups = tgroups ): gid = ordered[index] name = g[gid]['name'] html_data = ''' <tr class="userdata"> <td class="nopadding"> <a href="/groups/view/%s" title="%s" class="view-entry"> <span class="view-entry"> </span> </a> </td> <td class="group_name"> <a href="/groups/edit/%s" title="%s" class="edit-entry">%s</a> </td> <td class="group_name"> <a href="/groups/edit/%s" title="%s" class="edit-entry">%s</a> </td> <td class="right"> <a href="/groups/edit/%s">%s</a> </td> ''' % ( name, _('''View the group details, its parameters, members, responsibles and guests. From there you can print all group-related informations.'''), name, g[gid]['description'], name, name, g[gid]['description'], g[gid]['description'], name, g[gid]['skel']) if groups.is_system_gid(gid): html_data += '<td> </td>' else: if g[gid]['permissive']: html_data += ''' <td class="user_action_center"> <a href="/groups/lock/%s" title="%s"> <img src="/images/16x16/unlocked.png" alt="%s"/></a> </td> ''' % (name, _('''Shared group directory is currently ''' '''<strong>permissive</strong>. Click to deactivate ''' '''permissiveness.'''), _('Group is currently permissive.')) else: html_data += ''' <td class="user_action_center"> <a href="/groups/unlock/%s" title="%s"> <img src="/images/16x16/locked.png" alt="%s"/></a> </td> ''' % (name, _('''Shared group directory is currently <strong>NOT</strong> permissive. Click ti activate permissiveness.'''), _('Group is NOT permissive.')) for (keyname, text) in ( ('members', _('Current members')), ('rsp-members', _('Current responsibles')), ('gst-members', _('Current guests')) ): if tgroups[gid].has_key(keyname): accounts = {} uordered = {} for member in tgroups[gid][keyname]: uid = member['uidNumber'] accounts[uid] = { 'login': member['login'], 'gecos': member['gecos'], 'gecos_sort': member['gecos'] + member['login'] } uordered[hlstr.validate_name( accounts[uid]['gecos_sort'], aggressive=True)] = uid memberkeys = uordered.keys() memberkeys.sort() mbdata = '''<table><tr><th>%s</th><th>%s</th> <th>%s</th></tr>\n''' % (_('Full Name'), _('Identifier'), _('UID')) for member in memberkeys: uid = uordered[member] mbdata += '''<tr><td>%s</td><td>%s</td> <td>%d</td></tr>\n''' % (accounts[uid]['gecos'], accounts[uid]['login'], uid) mbdata += '</table>' nb = len(tgroups[gid][keyname]) if nb == 0: html_data += '''<td class="right faded">%s</td>\n''' % \ _('none') else: html_data += '''<td class="right"> <a class="nounder" title="<h4>%s</h4><br />%s"> <strong>%d</strong> <img src="/images/16x16/details-light.png" alt="%s" /></a></td>\n''' % (text, mbdata, nb, _('See %s of group %s.') % (text, name)) else: html_data += '''<td> </td>\n''' if groups.is_system_gid(gid): html_data += '<td colspan="1"> </td></tr>\n' else: html_data += ''' <!-- TODO: implement skel reapplying for all users of curent group <td class="user_action"> <a href="/users/skel/%s" title="%s" class="reapply-skel"> <span class="reapply-skel"> </span> </a> </td> --> <td class="user_action"> <a href="/groups/delete/%s" title="%s" class="delete-entry"> <span class="delete-entry"> </span> </a> </td> </tr> ''' % (name, _('''This will rebuild his/her desktop from scratch, with defaults icons and so on. <br /><br />The user must be disconnected for the operation to be completely successfull.'''), name, _('''Definitely remove this group from system.''')) return html_data data += '<tr><td class="group_class" colspan="8">%s</td></tr>\n%s' % ( filter_name, ''.join(map(html_build_group, gkeys))) def print_totals(totals): output = "" for total in totals: if totals[total] != 0: output += ''' <tr class="list_total"> <td colspan="6" class="total_left">%s</td> <td colspan="6" class="total_right">%d</td> </tr> ''' % (_('number of <strong>%s</strong>:') % total, totals[total]) return output data += ''' <tr> <td colspan="6"> </td></tr> %s <tr class="list_total"> <td colspan="6" class="total_left"><strong>%s</strong></td> <td colspan="6" class="total_right">%d</td> </tr> |
prefix + name)]['members']: | prefix + name)]['memberUid']: | def main(uri, http_user, sort = "name", order = "asc"): """List all groups and provileges on the system, displaying them in a nice HTML page. """ start = time.time() users.reload() groups.reload() #profiles.reload() g = groups.groups users.Select(users.FILTER_STANDARD) tgroups = {} totals = {} title = _('Groups') data = w.page_body_start(uri, http_user, ctxtnav, title) if order == "asc": reverseorder = "desc" else: reverseorder = "asc" data += '<table>\n <tr>\n' sortcols = ( ('', '', False), ("name", _("Name"), True), ("description", _("Description"), True), ("skel", _("Skeleton"), True), ("permissive", _("Perm."), True), ('members', _("Members"), False), ("resps", _("Responsibles"), False), ("guests", _("Guests"), False) ) for (column, name, can_sort) in sortcols: if can_sort: if column == sort: data += ''' <th><img src="/images/sort_%s.gif" alt="%s" />  <a href="/groups/list/%s/%s" title="%s">%s</a> </th>\n''' % (order, _('%s order') % order, column, reverseorder, _('Click to sort in reverse order.'), name) else: data += ''' <th><a href="/groups/list/%s/asc" title="%s">%s</a></th>\n''' % (column, _('Click to sort on this column.'), name) else: data += ' <th>%s</th>\n' % name data += ' </tr>\n' for (filter, filter_name) in ( (groups.FILTER_STANDARD, _('Groups')), (groups.FILTER_PRIVILEGED, _("Privileges")) ): tgroups = {} ordered = {} totals[filter_name] = 0 groups.Select(filter) for gid in groups.filtered_groups: group = groups.groups[gid] name = group['name'] tgroups[gid] = { 'name' : name, 'description' : group['description'] + name, 'skel' : group['skel'] + name, 'permissive' : str(group['permissive']) + name } totals[filter_name] += 1 # index on the column choosen for sorting, and keep trace of the uid # to find account data back after ordering. ordered[hlstr.validate_name(tgroups[gid][sort])] = gid tgroups[gid]['members'] = [] for member in groups.groups[gid]['members']: if not users.is_system_login(member): tgroups[gid]['members'].append( users.users[users.login_to_uid(member)]) if not groups.is_system_gid(gid): for prefix in ( configuration.groups.resp_prefix, configuration.groups.guest_prefix): tgroups[gid][prefix + 'members'] = [] for member in \ groups.groups[groups.name_to_gid( prefix + name)]['members']: if not users.is_system_login(member): tgroups[gid][prefix + 'members'].append( users.users[users.login_to_uid(member)]) gkeys = ordered.keys() gkeys.sort() if order == "desc": gkeys.reverse() def html_build_group(index, tgroups = tgroups ): gid = ordered[index] name = g[gid]['name'] html_data = ''' <tr class="userdata"> <td class="nopadding"> <a href="/groups/view/%s" title="%s" class="view-entry"> <span class="view-entry"> </span> </a> </td> <td class="group_name"> <a href="/groups/edit/%s" title="%s" class="edit-entry">%s</a> </td> <td class="group_name"> <a href="/groups/edit/%s" title="%s" class="edit-entry">%s</a> </td> <td class="right"> <a href="/groups/edit/%s">%s</a> </td> ''' % ( name, _('''View the group details, its parameters, members, responsibles and guests. From there you can print all group-related informations.'''), name, g[gid]['description'], name, name, g[gid]['description'], g[gid]['description'], name, g[gid]['skel']) if groups.is_system_gid(gid): html_data += '<td> </td>' else: if g[gid]['permissive']: html_data += ''' <td class="user_action_center"> <a href="/groups/lock/%s" title="%s"> <img src="/images/16x16/unlocked.png" alt="%s"/></a> </td> ''' % (name, _('''Shared group directory is currently ''' '''<strong>permissive</strong>. Click to deactivate ''' '''permissiveness.'''), _('Group is currently permissive.')) else: html_data += ''' <td class="user_action_center"> <a href="/groups/unlock/%s" title="%s"> <img src="/images/16x16/locked.png" alt="%s"/></a> </td> ''' % (name, _('''Shared group directory is currently <strong>NOT</strong> permissive. Click ti activate permissiveness.'''), _('Group is NOT permissive.')) for (keyname, text) in ( ('members', _('Current members')), ('rsp-members', _('Current responsibles')), ('gst-members', _('Current guests')) ): if tgroups[gid].has_key(keyname): accounts = {} uordered = {} for member in tgroups[gid][keyname]: uid = member['uidNumber'] accounts[uid] = { 'login': member['login'], 'gecos': member['gecos'], 'gecos_sort': member['gecos'] + member['login'] } uordered[hlstr.validate_name( accounts[uid]['gecos_sort'], aggressive=True)] = uid memberkeys = uordered.keys() memberkeys.sort() mbdata = '''<table><tr><th>%s</th><th>%s</th> <th>%s</th></tr>\n''' % (_('Full Name'), _('Identifier'), _('UID')) for member in memberkeys: uid = uordered[member] mbdata += '''<tr><td>%s</td><td>%s</td> <td>%d</td></tr>\n''' % (accounts[uid]['gecos'], accounts[uid]['login'], uid) mbdata += '</table>' nb = len(tgroups[gid][keyname]) if nb == 0: html_data += '''<td class="right faded">%s</td>\n''' % \ _('none') else: html_data += '''<td class="right"> <a class="nounder" title="<h4>%s</h4><br />%s"> <strong>%d</strong> <img src="/images/16x16/details-light.png" alt="%s" /></a></td>\n''' % (text, mbdata, nb, _('See %s of group %s.') % (text, name)) else: html_data += '''<td> </td>\n''' if groups.is_system_gid(gid): html_data += '<td colspan="1"> </td></tr>\n' else: html_data += ''' <!-- TODO: implement skel reapplying for all users of curent group <td class="user_action"> <a href="/users/skel/%s" title="%s" class="reapply-skel"> <span class="reapply-skel"> </span> </a> </td> --> <td class="user_action"> <a href="/groups/delete/%s" title="%s" class="delete-entry"> <span class="delete-entry"> </span> </a> </td> </tr> ''' % (name, _('''This will rebuild his/her desktop from scratch, with defaults icons and so on. <br /><br />The user must be disconnected for the operation to be completely successfull.'''), name, _('''Definitely remove this group from system.''')) return html_data data += '<tr><td class="group_class" colspan="8">%s</td></tr>\n%s' % ( filter_name, ''.join(map(html_build_group, gkeys))) def print_totals(totals): output = "" for total in totals: if totals[total] != 0: output += ''' <tr class="list_total"> <td colspan="6" class="total_left">%s</td> <td colspan="6" class="total_right">%d</td> </tr> ''' % (_('number of <strong>%s</strong>:') % total, totals[total]) return output data += ''' <tr> <td colspan="6"> </td></tr> %s <tr class="list_total"> <td colspan="6" class="total_left"><strong>%s</strong></td> <td colspan="6" class="total_right">%d</td> </tr> |
name, g[gid]['skel']) | name, g[gid]['groupSkel']) | def html_build_group(index, tgroups = tgroups ): gid = ordered[index] name = g[gid]['name'] html_data = ''' |
assert ltrace('ldap', '| __init__().') | assert ltrace('ldap', '| __init__()') | def __init__(self, configuration, users=None, groups=None, warnings=True): """ Init the LDAP backend instance. """ |
assert ltrace('ldap', '> initialize().') | assert ltrace('ldap', '> initialize()') | def initialize(self, enabled=True): """ try to start it without any tests (it should work if it's installed) and become available. If that fails, try to guess a little and help user resolving issue. else, just fail miserably. |
assert ltrace('ldap', '< initialize() %s.' % self.available) | assert ltrace('ldap', '< initialize(%s)' % self.available) | def initialize(self, enabled=True): """ try to start it without any tests (it should work if it's installed) and become available. If that fails, try to guess a little and help user resolving issue. else, just fail miserably. |
test_integrated_help() test_regexes() save_state(1, state_type='context') | if get_state(state_type='context') == 0: test_integrated_help() test_regexes() save_state(1, state_type='context') ctx_will_change = True else: logging.notice('Skipping context %s' % stylize(ST_NAME, "std")) ctx_will_change = False | def to_be_implemented(): """ TO BE DONE ! # # Profiles # # doit planter pour le groupe log_and_exec $ADD profile --name=profileA --group=a # doit planter pour le groupe kjsdqsdf log_and_exec $ADD profile --name=profileB --group=b --comment="le profil b" --shell=/bin/bash --quota=26 --groups=cdrom,kjsdqsdf,audio --skeldir=/etc/skel && exit 1 # doit planter pour le skel pas un répertoire, pour le groupe jfgdghf log_and_exec $MOD profile --name=profileA --rename=theprofile --rename-primary-group=theprofile --comment=modify --shell=/bin/sh --skel=/etc/power --quota=10 --add-groups=cdrom,remote,qsdfgkh --del-groups=cdrom,jfgdghf log_and_exec $DEL profile --name=profileB --del-users --no-archive log_and_exec $DEL profile --name=profileeD log_and_exec $MOD profile --name=profileeC --not-permissive log_and_exec $ADD profile --name=theprofile log_and_exec $MOD profile --name=theprofile --skel=/etc/doesntexist } """ pass |
ScenarioTest.reinit() | if get_state(state_type='scenarii') == 0 or ctx_will_change == True: ScenarioTest.reinit() | def to_be_implemented(): """ TO BE DONE ! # # Profiles # # doit planter pour le groupe log_and_exec $ADD profile --name=profileA --group=a # doit planter pour le groupe kjsdqsdf log_and_exec $ADD profile --name=profileB --group=b --comment="le profil b" --shell=/bin/bash --quota=26 --groups=cdrom,kjsdqsdf,audio --skeldir=/etc/skel && exit 1 # doit planter pour le skel pas un répertoire, pour le groupe jfgdghf log_and_exec $MOD profile --name=profileA --rename=theprofile --rename-primary-group=theprofile --comment=modify --shell=/bin/sh --skel=/etc/power --quota=10 --add-groups=cdrom,remote,qsdfgkh --del-groups=cdrom,jfgdghf log_and_exec $DEL profile --name=profileB --del-users --no-archive log_and_exec $DEL profile --name=profileeD log_and_exec $MOD profile --name=profileeC --not-permissive log_and_exec $ADD profile --name=theprofile log_and_exec $MOD profile --name=theprofile --skel=/etc/doesntexist } """ pass |
ctx_will_change = True | def to_be_implemented(): """ TO BE DONE ! # # Profiles # # doit planter pour le groupe log_and_exec $ADD profile --name=profileA --group=a # doit planter pour le groupe kjsdqsdf log_and_exec $ADD profile --name=profileB --group=b --comment="le profil b" --shell=/bin/bash --quota=26 --groups=cdrom,kjsdqsdf,audio --skeldir=/etc/skel && exit 1 # doit planter pour le skel pas un répertoire, pour le groupe jfgdghf log_and_exec $MOD profile --name=profileA --rename=theprofile --rename-primary-group=theprofile --comment=modify --shell=/bin/sh --skel=/etc/power --quota=10 --add-groups=cdrom,remote,qsdfgkh --del-groups=cdrom,jfgdghf log_and_exec $DEL profile --name=profileB --del-users --no-archive log_and_exec $DEL profile --name=profileeD log_and_exec $MOD profile --name=profileeC --not-permissive log_and_exec $ADD profile --name=theprofile log_and_exec $MOD profile --name=theprofile --skel=/etc/doesntexist } """ pass |
|
users = UGBackend.users action = users[uid]['action'] login = users[uid]['login'] | user = UGBackend.users[uid].copy() action = user['action'] login = user['login'] | def save_user(self, uid): """ Save one user in the LDAP backend. If updating, the entry will be dropped prior of insertion. """ |
ltrace('ldap', 'password: %s.' % (users[uid]['userPassword'])) | def save_user(self, uid): """ Save one user in the LDAP backend. If updating, the entry will be dropped prior of insertion. """ |
|
users[uid]['userPassword'] = \ '{SHA}' + encodestring(users[uid]['userPassword']).strip() | user['userPassword'] = \ '{SHA}' + encodestring(user['userPassword']).strip() | def save_user(self, uid): """ Save one user in the LDAP backend. If updating, the entry will be dropped prior of insertion. """ |
modifyModlist(old_entry, users[uid], | modifyModlist(old_entry, user, | def save_user(self, uid): """ Save one user in the LDAP backend. If updating, the entry will be dropped prior of insertion. """ |
old_entry, users[uid], ignore_list, ignore_oldexistent=1)) | old_entry, user, ignore_list, ignore_oldexistent=1)) | def save_user(self, uid): """ Save one user in the LDAP backend. If updating, the entry will be dropped prior of insertion. """ |
users[uid]['cn'] = login users[uid]['objectClass'] = [ | user['cn'] = login user['objectClass'] = [ | def save_user(self, uid): """ Save one user in the LDAP backend. If updating, the entry will be dropped prior of insertion. """ |
users[uid]['sn'] = users[uid]['gecos'] | user['sn'] = user['gecos'] | def save_user(self, uid): """ Save one user in the LDAP backend. If updating, the entry will be dropped prior of insertion. """ |
addModlist(users[uid], ignore_list))) | addModlist(user, ignore_list))) | def save_user(self, uid): """ Save one user in the LDAP backend. If updating, the entry will be dropped prior of insertion. """ |
addModlist(users[uid], ignore_list)) | addModlist(user, ignore_list)) | def save_user(self, uid): """ Save one user in the LDAP backend. If updating, the entry will be dropped prior of insertion. """ |
users[uid]['action'] = None | UGBackend.users[uid]['action'] = None | def save_user(self, uid): """ Save one user in the LDAP backend. If updating, the entry will be dropped prior of insertion. """ |
groups = UGBackend.groups action = groups[gid]['action'] name = groups[gid]['name'] | group = UGBackend.groups[gid].copy() action = group['action'] name = group['name'] | def save_group(self, gid): """ Save one group in the LDAP backend. If updating, the entry will be dropped prior of insertion. """ |
old_entry, groups[gid], ignore_list, ignore_oldexistent=1)) | old_entry, group, ignore_list, ignore_oldexistent=1)) | def save_group(self, gid): """ Save one group in the LDAP backend. If updating, the entry will be dropped prior of insertion. """ |
groups[gid]['cn'] = name groups[gid]['objectClass'] = [ | group['cn'] = name group['objectClass'] = [ | def save_group(self, gid): """ Save one group in the LDAP backend. If updating, the entry will be dropped prior of insertion. """ |
addModlist(groups[gid], ignore_list)) | addModlist(group, ignore_list)) | def save_group(self, gid): """ Save one group in the LDAP backend. If updating, the entry will be dropped prior of insertion. """ |
groups[gid]['action'] = None | UGBackend.groups[gid]['action'] = None | def save_group(self, gid): """ Save one group in the LDAP backend. If updating, the entry will be dropped prior of insertion. """ |
users.AddUser(lastname, firstname, password, opts.primary_group, opts.profile, opts.skel, login, gecos, False) | users.AddUser(lastname, firstname, password, primary_group=opts.primary_group, profile=opts.profile, skel=opts.skel, login=login, gecos=gecos, system=opts.system, batch=False) | def add_user(): """ Add a user account on the system. """ if opts.firstname is None: firstname = None else: firstname = unicode(opts.firstname) if opts.lastname is None: lastname = None else: lastname = unicode(opts.lastname) if opts.gecos is None: gecos = None else: gecos = unicode(opts.gecos) if opts.password is None: password = None else: password = unicode(opts.password) for login in opts.login.split(','): if login != '': try: users.AddUser(lastname, firstname, password, opts.primary_group, opts.profile, opts.skel, login, gecos, False) except exceptions.AlreadyExistsException: logging.warning('User %s already exists on the system.' % login) |
logging.warning("%s is not a privilege." % \ | logging.warning('''group %s can't be promoted as privilege, ''' '''it is not a system group.''' % \ | def append(self, privilege): """ Set append like: no doubles.""" try: self.index(privilege) except ValueError: from licorn.core.users import UsersController from licorn.core.groups import GroupsController |
logging.warning('''privilege %s is already not present in the ''' | logging.info('''privilege %s is already not present in the ''' | def remove(self, privilege): """ Remove without throw of exception """ try: list.remove(self, privilege) except ValueError: logging.warning('''privilege %s is already not present in the ''' '''whitelist, skipped.''' % \ styles.stylize(styles.ST_NAME, privilege)) |
if UsersController.is_system_uid(uid): | if uid > self.configuration.users.system_uid_min \ and uid < self.configuration.users.system_uid_max: | def check_uid(uid, minimal=minimal, batch=batch, auto_answer=auto_answer): |
else: logging.progress("Checking user %s..." % \ | elif self.is_standard_uid(uid): logging.progress("Checking standard account %s..." % \ | def check_uid(uid, minimal=minimal, batch=batch, auto_answer=auto_answer): |
return all_went_ok | else: login = self.uid_to_login(uid) logging.info('''Skipped reserved system account %s ''' '''(we don't check them at all).''' % styles.stylize(styles.ST_NAME, login)) return all_went_ok | def check_uid(uid, minimal=minimal, batch=batch, auto_answer=auto_answer): |
'backends'])[1].split('\n') if 'U' in line ] | 'backends'])[0].split('\n') if 'U' in line ] | def __init__(self, name, directory_scenarii, clean_func, state_file, cmd_display_func): self.name=name self.list_scenario = [] self.selected_scenario = [] self.directory_scenarii=directory_scenarii self.clean_system=clean_func self.cmd_display_func = cmd_display_func self.state_file=state_file # save the current context to restaure it at the end of the testsuite backends = [ line for line in process.execute(['get', 'config', 'backends'])[1].split('\n') if 'U' in line ] reduce(lambda x,y: x if y == '' else y, backends) self.user_context = backends[0].split('(')[0] self.current_context=self.user_context |
elif b.can_be_enabled(): b.initialize() b.check(batch, auto_answer) | elif b.name in self.available_backends: self.available_backends[b.name].check(batch, auto_answer) | def check_backends(self, batch=False, auto_answer=None): """ check all enabled backends, except the 'prefered', which is one of the enabled anyway. |
if pingers > 25: | if pingers > 50: | def check_directive_daemon_threads(self): """ check the pingers number for correctness. """ assert ltrace('configuration', '| check_directive_daemon_threads()') |
stylize(ST_ , 'licornd.threads.pool_members'))) | stylize(ST_COMMENT, 'licornd.threads.pool_members'))) | def check_directive_daemon_threads(self): """ check the pingers number for correctness. """ assert ltrace('configuration', '| check_directive_daemon_threads()') |
tmp_user_dict['shadowInactive'] = 99999 tmp_user_dict['shadowWarning'] = '' | tmp_user_dict['shadowInactive'] = '' tmp_user_dict['shadowWarning'] = 7 | def AddUser(self, lastname = None, firstname = None, password = None, primary_group=None, profile=None, skel=None, login=None, gecos=None, system = False, batch=False): """Add a user and return his/her (uid, login, pass).""" |
def execute(cmd, verbose=False): | def execute(cmd, verbose=verbose): | def execute(cmd, verbose=False): if verbose: logging.notice('running %s.' % ' '.join(cmd)) p4 = Popen(cmd, shell=False, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) output = p4.stdout.read() retcode = p4.wait() if verbose: sys.stderr.write(output) return output, retcode |
term_columns = term_size()[1] separator = '--------8<--------' * (term_columns/18) | def RunCommand(self, cmdnum, batch=False): |
|
os.system('sudo rm -rf %s/* %s/*' % (configuration.home_backup_dir, configuration.home_archive_dir)) | execute([ 'sudo', 'rm', '-rf', '%s/*' % configuration.home_backup_dir, '%s/*' % configuration.home_archive_dir ]) execute(ADD + ['group', '--system', 'acl,admins,remotessh,licorn-wmi']) | def clean_system(): """ Remove all stuff to make the system clean, testsuite-wise.""" test_message('''cleaning system from previous runs.''') # delete them first in case of a previous failed testsuite run. # don't check exit codes or such, this will be done later. for argument in ( ['user', '''toto,tutu,tata,titi,test,utilisager.normal,''' \ '''test.responsibilly,utilicateur.accentue,user_test,''' \ '''GRP-ACL-user''', '--no-archive'], ['profile', '--group=utilisagers', '--del-users', '--no-archive'], ['profile', '--group=responsibilisateurs', '--del-users', '--no-archive'], ['group', '''test_users_A,test_users_B,groupeA,B-Group_Test,''' \ '''groupe_a_skel,ACL_tests,MOD_tests,SYSTEM-test,SKEL-tests,''' \ '''ARCHIVES-test,group_test,GRP-ACL-test'''], ): execute(DEL + argument) os.system('sudo rm -rf %s/* %s/*' % (configuration.home_backup_dir, configuration.home_archive_dir)) test_message('''system cleaned from previous testsuite runs.''') |
execute(['chk', 'config', '-avvb']) | execute(['sudo', 'chk', 'config', '-avvb']) | def make_backups(mode): """Make backup of important system files before messing them up ;-) """ # this is mandatory, else there could be some inconsistencies following # backend (de)activation, and backup comparison could fail (false-negative) # because of this. execute(['chk', 'config', '-avvb']) if mode == 'unix': for file in system_files: if os.path.exists('/etc/%s' % file): execute([ 'sudo', 'cp', '-f', '/etc/%s' % file, '/tmp/%s.bak.%s' % (file.replace('/', '_'), bkp_ext)]) elif mode == 'ldap': execute(['sudo', 'slapcat', '-l', '/tmp/backup.1.ldif']) else: logging.error('backup mode not understood.') test_message('''made backups of system config files.''') |
'%s/%s/out.txt' % (self.base_path, cmdnum), | tmpfilename2 if gz_file else '%s/%s/out.txt' % (self.base_path, cmdnum), | def RunCommand(self, cmdnum, batch=False): |
profile.add_option("--group", "--name", | profile.add_option("--name", action="store", type="string", dest="name", default = None, help="specify profile to modify by its name (%s)." % styles.stylize(styles.ST_IMPORTANT, "one of --name or --group is required")) profile.add_option("--group", | def mod_profile_parse_arguments(app): usage_text = "\n\t%s profile --group=<nom> [--name=<nouveau_nom>] [--rename-group=<nouveau_nom>]\n" % styles.stylize(styles.ST_APPNAME, "%prog") \ + "\t\t[--comment=<nouveau_commentaire>] [--shell=<nouveau_shell>] [--skel=<nouveau_skel>]\n" \ + "\t\t[--quota=<nouveau_quota>] [--add-groups=<groupes>] [--del-groups=<groupes>]\n" \ + "\t%s profile <--apply-groups|--apply-skel|--apply-all> [--force]\n" % styles.stylize(styles.ST_APPNAME, "%prog") \ + "\t\t[--to-users=<user1[[,user2][,...]]>] [--to-groups=<group1[[,group2][,...]]>]\n" \ + "\t\t[--to-all] [--to-members] [--no-instant-apply] [--no-sync]" parser = OptionParser(usage = usage_text, version = __build_version_string(app)) # common behaviour group parser.add_option_group(__common_behaviour_group(app, parser, 'mod_profile')) profile = OptionGroup(parser, styles.stylize(styles.ST_OPTION, "Modify profile options ")) profile.add_option("--group", "--name", action="store", type="string", dest="group", default = None, help="specify profile to modify by its primary group (%s)." % styles.stylize(styles.ST_IMPORTANT, "required")) profile.add_option("--rename", action="store", type="string", dest="newname", default = None, help="specify profile's name") profile.add_option("--rename-group", action="store", type="string", dest="newgroup", default = None, help="Rename primary group.") profile.add_option("--description", action="store", type="string", dest="description", default = None, help="Change profile's description.") profile.add_option("--shell", action="store", type="string", dest="newshell", default = None, help="Change profile shell (defaults to %s if you specify --shell without argument)" % styles.stylize(styles.ST_DEFAULT, configuration.users.default_shell)) profile.add_option("--quota", action="store", type="int", dest="newquota", default = None, help="Change profile's user quota (in Mb, defaults to %s if you specify --quota without argument)." % styles.stylize(styles.ST_DEFAULT, "1024")) profile.add_option("--skel", action="store", type="string", dest="newskel", default = None, help="Change profile skel (specify a skel dir as an absolute pathname, defaults to %s if you give --skel without argument)." % styles.stylize(styles.ST_DEFAULT, configuration.users.default_skel)) profile.add_option("--add-groups", action="store", type="string", dest="groups_to_add", default = None, help="Add one or more group(s) to default memberships of profile (separate groups with commas without spaces).") profile.add_option("--del-groups", action="store", type="string", dest="groups_to_del", default = None, help="Delete one or more group(s) from default memberships of profile (separate groups with commas without spaces).") profile.add_option("--apply-groups", action="store_true", dest="apply_groups", default = False, help="Re-apply only the default group memberships of the profile.") profile.add_option("--apply-skel", action="store_true", dest="apply_skel", default = False, help="Re-apply only the skel of the profile.") profile.add_option("--apply-all", action="store_true", dest="apply_all_attributes", default = False, help="Re-apply all the profile's attributes (groups and skel).") profile.add_option("--to-users", action="store", type="string", dest="apply_to_users", default = None, help="Re-apply to specific users accounts (separate them with commas without spaces).") profile.add_option("--to-groups", action="store", type="string", dest="apply_to_groups", default = None, help="Re-apply to all members of one or more groups (separate groups with commas without spaces). You can mix --to-users and --to-groups.") profile.add_option("--to-members", action="store_true", dest="apply_to_members", default = False, help="Re-apply to all users members of the profile.") profile.add_option("--to-all", action="store_true", dest="apply_to_all_accounts", default = None, help="Re-apply to all user accounts on the system (LENGHTY operation !).") profile.add_option("--no-instant-apply", action="store_false", dest="instant_apply", default = True, help="Don't apply group addition/deletion instantly to all members of the modified profile (%s; use this only if you know what you're doing)." % styles.stylize(styles.ST_IMPORTANT, "this is not recommended")) profile.add_option("--no-sync", action="store_true", dest="no_sync", default = False, help="Commit changes only after all modifications.") parser.add_option_group(profile) return (parser.parse_args()) |
help="specify profile to modify by its primary group (%s)." % styles.stylize(styles.ST_IMPORTANT, "required")) | help="specify profile to modify by its primary group (%s)." % styles.stylize(styles.ST_IMPORTANT, "one of --name or --group is required")) | def mod_profile_parse_arguments(app): usage_text = "\n\t%s profile --group=<nom> [--name=<nouveau_nom>] [--rename-group=<nouveau_nom>]\n" % styles.stylize(styles.ST_APPNAME, "%prog") \ + "\t\t[--comment=<nouveau_commentaire>] [--shell=<nouveau_shell>] [--skel=<nouveau_skel>]\n" \ + "\t\t[--quota=<nouveau_quota>] [--add-groups=<groupes>] [--del-groups=<groupes>]\n" \ + "\t%s profile <--apply-groups|--apply-skel|--apply-all> [--force]\n" % styles.stylize(styles.ST_APPNAME, "%prog") \ + "\t\t[--to-users=<user1[[,user2][,...]]>] [--to-groups=<group1[[,group2][,...]]>]\n" \ + "\t\t[--to-all] [--to-members] [--no-instant-apply] [--no-sync]" parser = OptionParser(usage = usage_text, version = __build_version_string(app)) # common behaviour group parser.add_option_group(__common_behaviour_group(app, parser, 'mod_profile')) profile = OptionGroup(parser, styles.stylize(styles.ST_OPTION, "Modify profile options ")) profile.add_option("--group", "--name", action="store", type="string", dest="group", default = None, help="specify profile to modify by its primary group (%s)." % styles.stylize(styles.ST_IMPORTANT, "required")) profile.add_option("--rename", action="store", type="string", dest="newname", default = None, help="specify profile's name") profile.add_option("--rename-group", action="store", type="string", dest="newgroup", default = None, help="Rename primary group.") profile.add_option("--description", action="store", type="string", dest="description", default = None, help="Change profile's description.") profile.add_option("--shell", action="store", type="string", dest="newshell", default = None, help="Change profile shell (defaults to %s if you specify --shell without argument)" % styles.stylize(styles.ST_DEFAULT, configuration.users.default_shell)) profile.add_option("--quota", action="store", type="int", dest="newquota", default = None, help="Change profile's user quota (in Mb, defaults to %s if you specify --quota without argument)." % styles.stylize(styles.ST_DEFAULT, "1024")) profile.add_option("--skel", action="store", type="string", dest="newskel", default = None, help="Change profile skel (specify a skel dir as an absolute pathname, defaults to %s if you give --skel without argument)." % styles.stylize(styles.ST_DEFAULT, configuration.users.default_skel)) profile.add_option("--add-groups", action="store", type="string", dest="groups_to_add", default = None, help="Add one or more group(s) to default memberships of profile (separate groups with commas without spaces).") profile.add_option("--del-groups", action="store", type="string", dest="groups_to_del", default = None, help="Delete one or more group(s) from default memberships of profile (separate groups with commas without spaces).") profile.add_option("--apply-groups", action="store_true", dest="apply_groups", default = False, help="Re-apply only the default group memberships of the profile.") profile.add_option("--apply-skel", action="store_true", dest="apply_skel", default = False, help="Re-apply only the skel of the profile.") profile.add_option("--apply-all", action="store_true", dest="apply_all_attributes", default = False, help="Re-apply all the profile's attributes (groups and skel).") profile.add_option("--to-users", action="store", type="string", dest="apply_to_users", default = None, help="Re-apply to specific users accounts (separate them with commas without spaces).") profile.add_option("--to-groups", action="store", type="string", dest="apply_to_groups", default = None, help="Re-apply to all members of one or more groups (separate groups with commas without spaces). You can mix --to-users and --to-groups.") profile.add_option("--to-members", action="store_true", dest="apply_to_members", default = False, help="Re-apply to all users members of the profile.") profile.add_option("--to-all", action="store_true", dest="apply_to_all_accounts", default = None, help="Re-apply to all user accounts on the system (LENGHTY operation !).") profile.add_option("--no-instant-apply", action="store_false", dest="instant_apply", default = True, help="Don't apply group addition/deletion instantly to all members of the modified profile (%s; use this only if you know what you're doing)." % styles.stylize(styles.ST_IMPORTANT, "this is not recommended")) profile.add_option("--no-sync", action="store_true", dest="no_sync", default = False, help="Commit changes only after all modifications.") parser.add_option_group(profile) return (parser.parse_args()) |
if user['shadowExpire'] == '': | if 'shadowExpire' in user and user['shadowExpire'] == '': | def save_User(self, uid, mode): """ Save one user in the LDAP backend. If updating, the entry will be dropped prior of insertion. """ |
if user['shadowFlag'] == '': | if 'shadowFlag' in user and user['shadowFlag'] == '': | def save_User(self, uid, mode): """ Save one user in the LDAP backend. If updating, the entry will be dropped prior of insertion. """ |
if user['shadowInactive'] == '': | if 'shadowInactive' in user and user['shadowInactive'] == '': | def save_User(self, uid, mode): """ Save one user in the LDAP backend. If updating, the entry will be dropped prior of insertion. """ |
groups = GroupsController(self.configuration) | users = UsersController(self.configuration) groups = GroupsController(self.configuration, users) | def append(self, privilege): """ Set append like: no doubles.""" try: self.index(privilege) except ValueError: from licorn.core.groups import GroupsController groups = GroupsController(self.configuration) if groups.is_system_group(privilege): list.append(self, privilege) else: logging.warning("%s is not a privilege." % \ styles.stylize(styles.ST_NAME, privilege)) else: logging.info("privilege %s already whitelisted, skipped." % \ styles.stylize(styles.ST_NAME, privilege)) |
return (w.HTTP_TYPE_TEXT, w.minipage(w.lbox('''%s <div class="vspacer"></div> | return (w.HTTP_TYPE_TEXT, w.minipage(w.lbox(''' <div style="line-height: 1.5em; padding-bottom:20px">%s</div> | def reboot(uri, http_user, sure = False): if sure: return (w.HTTP_TYPE_TEXT, w.minipage(w.lbox('''<div class="vspacer"></div>%s''' % \ _('Rebooting…')))) else: return (w.HTTP_TYPE_TEXT, w.minipage(w.lbox('''%s <div class="vspacer"></div> <table class="lbox-table"> <tr> <td> <form name="reboot_form" id="reboot_form" action="/server/reboot/sure" method="get"> <a href="/server/reboot/sure" params="lightwindow_form=reboot_form,''' '''lightwindow_width=320,lightwindow_height=140" class="lightwindow_action" rel="submitForm"> <button>%s</button> </a> </form> </td> <td> <a href="#" class="lightwindow_action" rel="deactivate"> <button>%s</button></a> </td> </tr> </table> ''' % ( _('Sure you want to reboot the %s server?') % configuration.app_name, _('YES'), _('NO'))))) |
from licorn.core import groups as allgroups if allusers is None: from licorn.core import users as allusers | from licorn.core.groups import GroupsController allgroups = GroupsController(allusers.configuration, allusers) | def check_dirs_and_contents_perms_and_acls(dirs_infos, batch = False, auto_answer = None, allgroups = None, allusers = None): """ Check if a dir exists, else create it and apply ACLs on it eventually. dirs_infos should be a n-tuple of dicts, composed like this: { 'path' : string, 'type' : stat.S_IF???, # what type the "path" should be 'user' : 'owner', # the name, not the uid 'group' : 'group', # the name too, 'exclude' : [ ... ], # dirs and files inside 'path' to be excluded from search) *and* 'mode' : chmod_mode (INT), # always use 00600 for example, not just 600, else it won't work. 'content_mode': another int, # mode for files inside 'path' *or* 'access_acl' : string, 'default_acl': string, 'content_acl': string, } if mode and content_mode are present, ACL will be deleted from path and its contents, *_acl will not be used and not be checked (Posix mode and posix1e ACLs are mutually exclusive). when content_mode is present, it will be applyed on regular files inside 'path'. 'mode' will be applyed on dirs inside 'path'. When checking ACLs, default_acl will be applyed on dirs as access *and* default acl. 'default_acl' will be applyed on dirs inside 'path', and 'content_acl' will be checked against files inside 'path'. TODO: 'default_acl' should be checked against files inside 'path', modulo the mask change from 'rwx' to 'rw-', which will should automagically imply "effective" ACLs computed on the fly. """ if allgroups is None: from licorn.core import groups as allgroups if allusers is None: from licorn.core import users as allusers def check_one_dir_and_acl(dir_info, batch = batch, auto_answer = auto_answer): all_went_ok = True #logging.debug('checking %s' % styles.stylize(styles.ST_PATH, dir_info['path'])) try: if dir_info.has_key('user') and dir_info['user'] != '': uid = allusers.login_to_uid(dir_info['user']) else: uid = -1 if dir_info.has_key('group') and dir_info['group'] != '': gid = allgroups.name_to_gid(dir_info['group']) else: gid = -1 except KeyError, e: raise exceptions.LicornRuntimeError("You just encountered a programmer bug. Get in touch with [email protected] (was: %s)." % e) except exceptions.LicornRuntimeException, e: raise exceptions.LicornRuntimeError("The uid/gid you want to check against does not exist on this system ! This shouldn't happen and is probably a programmer/packager bug. Get in touch with [email protected] (was: %s)." % e) try: logging.progress("Checking dir %s..." % styles.stylize(styles.ST_PATH, dir_info['path'])) dirstat = os.lstat(dir_info['path']) except OSError, e: if e.errno == 13: raise exceptions.InsufficientPermissionsError(str(e)) elif e.errno == 2: warn_message = "Directory %s does not exist." % styles.stylize(styles.ST_PATH, dir_info['path']) if batch or logging.ask_for_repair(warn_message, auto_answer): os.mkdir(dir_info['path']) dirstat = os.lstat(dir_info['path']) batch = True logging.info("Created dir %s." % styles.stylize(styles.ST_PATH, dir_info['path'])) else: # we cannot continue if dir does not exist. raise exceptions.LicornCheckError("Can't continue checks for directory %s (was: %s)." % (dir_info['path'], e) ) else: # FIXME: do more things to recover from more system errors... raise e if ( dirstat.st_mode & 0170000 ) != S_IFDIR: warn_message = logging.SWKN_DIR_IS_NOT_A_DIR % styles.stylize(styles.ST_PATH, dir_info['path']) if batch or logging.ask_for_repair(warn_message, auto_answer): os.unlink(dir_info['path']) os.mkdir(dir_info['path']) dirstat = os.lstat(dir_info['path']) batch = True logging.info("Created dir %s." % styles.stylize(styles.ST_PATH, dir_info['path'])) else: raise exceptions.LicornCheckError("Can't continue checks for directory %s (was: %s)." % (dir_info['path'], e) ) if dir_info.has_key('mode'): logging.progress("Checking %s's posix perms..." % styles.stylize(styles.ST_PATH, dir_info['path'])) all_went_ok &= check_posix_ugid_and_perms(dir_info['path'], uid, gid, dir_info['mode'], batch, auto_answer, allgroups, allusers) if dir_info.has_key('content_mode'): # check the contents of the dir (existing files and directories, except the ones which # are excluded), only if the content_acl is set, else skip content check. all_went_ok &= check_posix_dir_contents(dir_info, uid, gid, batch, auto_answer) else: logging.progress("Checking %s's ACLs..." % styles.stylize(styles.ST_PATH, dir_info['path'])) # check uid/gid, but don't check the perms (thus -1) because ACLs overrride them. all_went_ok &= check_posix_ugid_and_perms(dir_info['path'], uid, gid, -1, batch, auto_answer, allgroups, allusers) all_went_ok &= check_posix1e_acl(dir_info['path'], False, dir_info['access_acl'], dir_info['default_acl'], batch, auto_answer) if dir_info.has_key('content_acl'): # this hack is needed to use check_posix_dir_contents() to check only uid/gid (not perms) dir_info['mode'] = -1 dir_info['content_mode' ] = -1 # check the contents of the dir (existing files and directories, except the ones which # are excluded), only if "content_acl" is set, else skip content check. all_went_ok &= check_posix_dir_contents(dir_info, uid, gid, batch, auto_answer, allgroups, allusers) all_went_ok &= check_posix1e_dir_contents(dir_info, batch, auto_answer) return all_went_ok if dirs_infos: if reduce(pyutils.keep_false, map(check_one_dir_and_acl, dirs_infos)) is False: return False else: return True else: raise exceptions.BadArgumentError("You must pass some dirs (through dirs_infos) to check as arguments !") |
from licorn.core import groups as allgroups if allusers is None: from licorn.core import users as allusers | from licorn.core.groups import GroupsController allgroups = GroupsController(allusers.configuration, allusers) | def check_posix_ugid_and_perms(onpath, uid = -1, gid = -1, perms = -1, batch = False, auto_answer = None, allgroups = None, allusers = None): """Check if some path has some desired perms, repair if told to do so.""" if onpath in ("", None): raise exceptions.BadArgumentError("The path you want to check perms on must not be empty !") if allgroups is None: from licorn.core import groups as allgroups if allusers is None: from licorn.core import users as allusers all_went_ok = True logging.progress("Checking posix uid/gid/perms of %s." % styles.stylize(styles.ST_PATH, onpath)) try: pathstat = os.lstat(onpath) except OSError, e: if e.errno == 2: # causes of this error: # - this is a race condition: the dir/file has been deleted between the minifind() # and the check_*() call. Don't blow out on this. # - when we explicitely want to check a path which does not exist because it has not # been created yet (eg: ~/.dmrc on a brand new user account). return True else: raise e # if one or both of the uid or gid are empty, don't check it, use the # current one present in the file meta-data. if uid == -1: uid = pathstat.st_uid try: desired_login = allusers.users[ uid ]['login'] except KeyError: desired_login = str(uid) else: desired_login = allusers.users[ uid ]['login'] if gid == -1: gid = pathstat.st_gid try: desired_group = allgroups.groups[ gid ]['name'] except KeyError: desired_group = str(gid) else: desired_group = allgroups.groups[ gid ]['name'] if pathstat.st_uid != uid or pathstat.st_gid != gid: try: current_login = allusers.users[ pathstat.st_uid ]['login'] except KeyError: current_login = str(pathstat.st_uid) try: current_group = allgroups.groups[ pathstat.st_gid ]['name'] except KeyError: current_group = str(pathstat.st_gid) warn_message = logging.SWKN_DIR_BAD_OWNERSHIP \ % ( styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, current_login), styles.stylize(styles.ST_BAD, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group), ) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chown(onpath, uid, gid) logging.info("Changed owner of %s from %s:%s to %s:%s." % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_UGID, current_login), styles.stylize(styles.ST_UGID, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group))) else: all_went_ok = False if perms == -1: # stop here, we just wanted to check uid/gid return all_went_ok if has_extended_acl(onpath): # if an ACL is present, this could be what is borking the Unix mode. # an ACL is present if it has a mask, else it is just standard posix # perms expressed in the ACL grammar. No mask == Not an ACL. #logging.debug2("pathacl = %s, perms = %s (%s)." % (str(pathacl), perms2str(perms, acl_form = True), str(pathacl).find("mask::"))) warn_message = "An ACL is present on %s, but it should not." % styles.stylize(styles.ST_PATH, onpath) if batch or logging.ask_for_repair(warn_message, auto_answer): posix1e.ACL(text="").applyto(str(onpath)) if pathstat.st_mode & 0170000 == S_IFDIR: posix1e.ACL(text="").applyto(str(onpath), posix1e.ACL_TYPE_DEFAULT) logging.info("Deleted ACL from %s." % styles.stylize(styles.ST_PATH, onpath)) # redo the stat, to get the current posix mode. pathstat = os.lstat(onpath) # enter batch mode: if there was an ACL, the std posix perms will be false in 99% # of the cases, because the ACL has modified the group perms with the mask content. # Thus, don't bother the administrator with another question, just correct the posix perms. # # As perms check is the only thing left to do in this function after the present ACL check, # setting batch to True locally here won't accidentally batch other checks. batch = True else: all_went_ok = False # now that we are sure that there isn't any ACLs on the file/dir, continue checking. mode = pathstat.st_mode & 07777 #logging.debug2("Comparing desired %d and current %d on %s." % (perms, mode, onpath)) if perms != mode: mode_txt = perms2str(mode) perms_txt = perms2str(perms) warn_message = logging.SWKN_INVALID_MODE % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, mode_txt), styles.stylize(styles.ST_ACL, perms_txt)) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chmod(onpath, perms) logging.info("Applyed perms %s on %s." % (styles.stylize(styles.ST_ACL, perms_txt), styles.stylize(styles.ST_PATH, onpath))) else: all_went_ok = False return all_went_ok |
desired_login = allusers.users[ uid ]['login'] | desired_login = allusers[uid]['login'] | def check_posix_ugid_and_perms(onpath, uid = -1, gid = -1, perms = -1, batch = False, auto_answer = None, allgroups = None, allusers = None): """Check if some path has some desired perms, repair if told to do so.""" if onpath in ("", None): raise exceptions.BadArgumentError("The path you want to check perms on must not be empty !") if allgroups is None: from licorn.core import groups as allgroups if allusers is None: from licorn.core import users as allusers all_went_ok = True logging.progress("Checking posix uid/gid/perms of %s." % styles.stylize(styles.ST_PATH, onpath)) try: pathstat = os.lstat(onpath) except OSError, e: if e.errno == 2: # causes of this error: # - this is a race condition: the dir/file has been deleted between the minifind() # and the check_*() call. Don't blow out on this. # - when we explicitely want to check a path which does not exist because it has not # been created yet (eg: ~/.dmrc on a brand new user account). return True else: raise e # if one or both of the uid or gid are empty, don't check it, use the # current one present in the file meta-data. if uid == -1: uid = pathstat.st_uid try: desired_login = allusers.users[ uid ]['login'] except KeyError: desired_login = str(uid) else: desired_login = allusers.users[ uid ]['login'] if gid == -1: gid = pathstat.st_gid try: desired_group = allgroups.groups[ gid ]['name'] except KeyError: desired_group = str(gid) else: desired_group = allgroups.groups[ gid ]['name'] if pathstat.st_uid != uid or pathstat.st_gid != gid: try: current_login = allusers.users[ pathstat.st_uid ]['login'] except KeyError: current_login = str(pathstat.st_uid) try: current_group = allgroups.groups[ pathstat.st_gid ]['name'] except KeyError: current_group = str(pathstat.st_gid) warn_message = logging.SWKN_DIR_BAD_OWNERSHIP \ % ( styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, current_login), styles.stylize(styles.ST_BAD, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group), ) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chown(onpath, uid, gid) logging.info("Changed owner of %s from %s:%s to %s:%s." % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_UGID, current_login), styles.stylize(styles.ST_UGID, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group))) else: all_went_ok = False if perms == -1: # stop here, we just wanted to check uid/gid return all_went_ok if has_extended_acl(onpath): # if an ACL is present, this could be what is borking the Unix mode. # an ACL is present if it has a mask, else it is just standard posix # perms expressed in the ACL grammar. No mask == Not an ACL. #logging.debug2("pathacl = %s, perms = %s (%s)." % (str(pathacl), perms2str(perms, acl_form = True), str(pathacl).find("mask::"))) warn_message = "An ACL is present on %s, but it should not." % styles.stylize(styles.ST_PATH, onpath) if batch or logging.ask_for_repair(warn_message, auto_answer): posix1e.ACL(text="").applyto(str(onpath)) if pathstat.st_mode & 0170000 == S_IFDIR: posix1e.ACL(text="").applyto(str(onpath), posix1e.ACL_TYPE_DEFAULT) logging.info("Deleted ACL from %s." % styles.stylize(styles.ST_PATH, onpath)) # redo the stat, to get the current posix mode. pathstat = os.lstat(onpath) # enter batch mode: if there was an ACL, the std posix perms will be false in 99% # of the cases, because the ACL has modified the group perms with the mask content. # Thus, don't bother the administrator with another question, just correct the posix perms. # # As perms check is the only thing left to do in this function after the present ACL check, # setting batch to True locally here won't accidentally batch other checks. batch = True else: all_went_ok = False # now that we are sure that there isn't any ACLs on the file/dir, continue checking. mode = pathstat.st_mode & 07777 #logging.debug2("Comparing desired %d and current %d on %s." % (perms, mode, onpath)) if perms != mode: mode_txt = perms2str(mode) perms_txt = perms2str(perms) warn_message = logging.SWKN_INVALID_MODE % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, mode_txt), styles.stylize(styles.ST_ACL, perms_txt)) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chmod(onpath, perms) logging.info("Applyed perms %s on %s." % (styles.stylize(styles.ST_ACL, perms_txt), styles.stylize(styles.ST_PATH, onpath))) else: all_went_ok = False return all_went_ok |
desired_group = allgroups.groups[ gid ]['name'] | desired_group = allgroups[gid]['name'] | def check_posix_ugid_and_perms(onpath, uid = -1, gid = -1, perms = -1, batch = False, auto_answer = None, allgroups = None, allusers = None): """Check if some path has some desired perms, repair if told to do so.""" if onpath in ("", None): raise exceptions.BadArgumentError("The path you want to check perms on must not be empty !") if allgroups is None: from licorn.core import groups as allgroups if allusers is None: from licorn.core import users as allusers all_went_ok = True logging.progress("Checking posix uid/gid/perms of %s." % styles.stylize(styles.ST_PATH, onpath)) try: pathstat = os.lstat(onpath) except OSError, e: if e.errno == 2: # causes of this error: # - this is a race condition: the dir/file has been deleted between the minifind() # and the check_*() call. Don't blow out on this. # - when we explicitely want to check a path which does not exist because it has not # been created yet (eg: ~/.dmrc on a brand new user account). return True else: raise e # if one or both of the uid or gid are empty, don't check it, use the # current one present in the file meta-data. if uid == -1: uid = pathstat.st_uid try: desired_login = allusers.users[ uid ]['login'] except KeyError: desired_login = str(uid) else: desired_login = allusers.users[ uid ]['login'] if gid == -1: gid = pathstat.st_gid try: desired_group = allgroups.groups[ gid ]['name'] except KeyError: desired_group = str(gid) else: desired_group = allgroups.groups[ gid ]['name'] if pathstat.st_uid != uid or pathstat.st_gid != gid: try: current_login = allusers.users[ pathstat.st_uid ]['login'] except KeyError: current_login = str(pathstat.st_uid) try: current_group = allgroups.groups[ pathstat.st_gid ]['name'] except KeyError: current_group = str(pathstat.st_gid) warn_message = logging.SWKN_DIR_BAD_OWNERSHIP \ % ( styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, current_login), styles.stylize(styles.ST_BAD, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group), ) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chown(onpath, uid, gid) logging.info("Changed owner of %s from %s:%s to %s:%s." % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_UGID, current_login), styles.stylize(styles.ST_UGID, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group))) else: all_went_ok = False if perms == -1: # stop here, we just wanted to check uid/gid return all_went_ok if has_extended_acl(onpath): # if an ACL is present, this could be what is borking the Unix mode. # an ACL is present if it has a mask, else it is just standard posix # perms expressed in the ACL grammar. No mask == Not an ACL. #logging.debug2("pathacl = %s, perms = %s (%s)." % (str(pathacl), perms2str(perms, acl_form = True), str(pathacl).find("mask::"))) warn_message = "An ACL is present on %s, but it should not." % styles.stylize(styles.ST_PATH, onpath) if batch or logging.ask_for_repair(warn_message, auto_answer): posix1e.ACL(text="").applyto(str(onpath)) if pathstat.st_mode & 0170000 == S_IFDIR: posix1e.ACL(text="").applyto(str(onpath), posix1e.ACL_TYPE_DEFAULT) logging.info("Deleted ACL from %s." % styles.stylize(styles.ST_PATH, onpath)) # redo the stat, to get the current posix mode. pathstat = os.lstat(onpath) # enter batch mode: if there was an ACL, the std posix perms will be false in 99% # of the cases, because the ACL has modified the group perms with the mask content. # Thus, don't bother the administrator with another question, just correct the posix perms. # # As perms check is the only thing left to do in this function after the present ACL check, # setting batch to True locally here won't accidentally batch other checks. batch = True else: all_went_ok = False # now that we are sure that there isn't any ACLs on the file/dir, continue checking. mode = pathstat.st_mode & 07777 #logging.debug2("Comparing desired %d and current %d on %s." % (perms, mode, onpath)) if perms != mode: mode_txt = perms2str(mode) perms_txt = perms2str(perms) warn_message = logging.SWKN_INVALID_MODE % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, mode_txt), styles.stylize(styles.ST_ACL, perms_txt)) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chmod(onpath, perms) logging.info("Applyed perms %s on %s." % (styles.stylize(styles.ST_ACL, perms_txt), styles.stylize(styles.ST_PATH, onpath))) else: all_went_ok = False return all_went_ok |
current_login = allusers.users[ pathstat.st_uid ]['login'] | current_login = allusers[pathstat.st_uid]['login'] | def check_posix_ugid_and_perms(onpath, uid = -1, gid = -1, perms = -1, batch = False, auto_answer = None, allgroups = None, allusers = None): """Check if some path has some desired perms, repair if told to do so.""" if onpath in ("", None): raise exceptions.BadArgumentError("The path you want to check perms on must not be empty !") if allgroups is None: from licorn.core import groups as allgroups if allusers is None: from licorn.core import users as allusers all_went_ok = True logging.progress("Checking posix uid/gid/perms of %s." % styles.stylize(styles.ST_PATH, onpath)) try: pathstat = os.lstat(onpath) except OSError, e: if e.errno == 2: # causes of this error: # - this is a race condition: the dir/file has been deleted between the minifind() # and the check_*() call. Don't blow out on this. # - when we explicitely want to check a path which does not exist because it has not # been created yet (eg: ~/.dmrc on a brand new user account). return True else: raise e # if one or both of the uid or gid are empty, don't check it, use the # current one present in the file meta-data. if uid == -1: uid = pathstat.st_uid try: desired_login = allusers.users[ uid ]['login'] except KeyError: desired_login = str(uid) else: desired_login = allusers.users[ uid ]['login'] if gid == -1: gid = pathstat.st_gid try: desired_group = allgroups.groups[ gid ]['name'] except KeyError: desired_group = str(gid) else: desired_group = allgroups.groups[ gid ]['name'] if pathstat.st_uid != uid or pathstat.st_gid != gid: try: current_login = allusers.users[ pathstat.st_uid ]['login'] except KeyError: current_login = str(pathstat.st_uid) try: current_group = allgroups.groups[ pathstat.st_gid ]['name'] except KeyError: current_group = str(pathstat.st_gid) warn_message = logging.SWKN_DIR_BAD_OWNERSHIP \ % ( styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, current_login), styles.stylize(styles.ST_BAD, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group), ) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chown(onpath, uid, gid) logging.info("Changed owner of %s from %s:%s to %s:%s." % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_UGID, current_login), styles.stylize(styles.ST_UGID, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group))) else: all_went_ok = False if perms == -1: # stop here, we just wanted to check uid/gid return all_went_ok if has_extended_acl(onpath): # if an ACL is present, this could be what is borking the Unix mode. # an ACL is present if it has a mask, else it is just standard posix # perms expressed in the ACL grammar. No mask == Not an ACL. #logging.debug2("pathacl = %s, perms = %s (%s)." % (str(pathacl), perms2str(perms, acl_form = True), str(pathacl).find("mask::"))) warn_message = "An ACL is present on %s, but it should not." % styles.stylize(styles.ST_PATH, onpath) if batch or logging.ask_for_repair(warn_message, auto_answer): posix1e.ACL(text="").applyto(str(onpath)) if pathstat.st_mode & 0170000 == S_IFDIR: posix1e.ACL(text="").applyto(str(onpath), posix1e.ACL_TYPE_DEFAULT) logging.info("Deleted ACL from %s." % styles.stylize(styles.ST_PATH, onpath)) # redo the stat, to get the current posix mode. pathstat = os.lstat(onpath) # enter batch mode: if there was an ACL, the std posix perms will be false in 99% # of the cases, because the ACL has modified the group perms with the mask content. # Thus, don't bother the administrator with another question, just correct the posix perms. # # As perms check is the only thing left to do in this function after the present ACL check, # setting batch to True locally here won't accidentally batch other checks. batch = True else: all_went_ok = False # now that we are sure that there isn't any ACLs on the file/dir, continue checking. mode = pathstat.st_mode & 07777 #logging.debug2("Comparing desired %d and current %d on %s." % (perms, mode, onpath)) if perms != mode: mode_txt = perms2str(mode) perms_txt = perms2str(perms) warn_message = logging.SWKN_INVALID_MODE % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, mode_txt), styles.stylize(styles.ST_ACL, perms_txt)) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chmod(onpath, perms) logging.info("Applyed perms %s on %s." % (styles.stylize(styles.ST_ACL, perms_txt), styles.stylize(styles.ST_PATH, onpath))) else: all_went_ok = False return all_went_ok |
current_group = allgroups.groups[ pathstat.st_gid ]['name'] | current_group = allgroups[pathstat.st_gid]['name'] | def check_posix_ugid_and_perms(onpath, uid = -1, gid = -1, perms = -1, batch = False, auto_answer = None, allgroups = None, allusers = None): """Check if some path has some desired perms, repair if told to do so.""" if onpath in ("", None): raise exceptions.BadArgumentError("The path you want to check perms on must not be empty !") if allgroups is None: from licorn.core import groups as allgroups if allusers is None: from licorn.core import users as allusers all_went_ok = True logging.progress("Checking posix uid/gid/perms of %s." % styles.stylize(styles.ST_PATH, onpath)) try: pathstat = os.lstat(onpath) except OSError, e: if e.errno == 2: # causes of this error: # - this is a race condition: the dir/file has been deleted between the minifind() # and the check_*() call. Don't blow out on this. # - when we explicitely want to check a path which does not exist because it has not # been created yet (eg: ~/.dmrc on a brand new user account). return True else: raise e # if one or both of the uid or gid are empty, don't check it, use the # current one present in the file meta-data. if uid == -1: uid = pathstat.st_uid try: desired_login = allusers.users[ uid ]['login'] except KeyError: desired_login = str(uid) else: desired_login = allusers.users[ uid ]['login'] if gid == -1: gid = pathstat.st_gid try: desired_group = allgroups.groups[ gid ]['name'] except KeyError: desired_group = str(gid) else: desired_group = allgroups.groups[ gid ]['name'] if pathstat.st_uid != uid or pathstat.st_gid != gid: try: current_login = allusers.users[ pathstat.st_uid ]['login'] except KeyError: current_login = str(pathstat.st_uid) try: current_group = allgroups.groups[ pathstat.st_gid ]['name'] except KeyError: current_group = str(pathstat.st_gid) warn_message = logging.SWKN_DIR_BAD_OWNERSHIP \ % ( styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, current_login), styles.stylize(styles.ST_BAD, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group), ) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chown(onpath, uid, gid) logging.info("Changed owner of %s from %s:%s to %s:%s." % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_UGID, current_login), styles.stylize(styles.ST_UGID, current_group), styles.stylize(styles.ST_UGID, desired_login), styles.stylize(styles.ST_UGID, desired_group))) else: all_went_ok = False if perms == -1: # stop here, we just wanted to check uid/gid return all_went_ok if has_extended_acl(onpath): # if an ACL is present, this could be what is borking the Unix mode. # an ACL is present if it has a mask, else it is just standard posix # perms expressed in the ACL grammar. No mask == Not an ACL. #logging.debug2("pathacl = %s, perms = %s (%s)." % (str(pathacl), perms2str(perms, acl_form = True), str(pathacl).find("mask::"))) warn_message = "An ACL is present on %s, but it should not." % styles.stylize(styles.ST_PATH, onpath) if batch or logging.ask_for_repair(warn_message, auto_answer): posix1e.ACL(text="").applyto(str(onpath)) if pathstat.st_mode & 0170000 == S_IFDIR: posix1e.ACL(text="").applyto(str(onpath), posix1e.ACL_TYPE_DEFAULT) logging.info("Deleted ACL from %s." % styles.stylize(styles.ST_PATH, onpath)) # redo the stat, to get the current posix mode. pathstat = os.lstat(onpath) # enter batch mode: if there was an ACL, the std posix perms will be false in 99% # of the cases, because the ACL has modified the group perms with the mask content. # Thus, don't bother the administrator with another question, just correct the posix perms. # # As perms check is the only thing left to do in this function after the present ACL check, # setting batch to True locally here won't accidentally batch other checks. batch = True else: all_went_ok = False # now that we are sure that there isn't any ACLs on the file/dir, continue checking. mode = pathstat.st_mode & 07777 #logging.debug2("Comparing desired %d and current %d on %s." % (perms, mode, onpath)) if perms != mode: mode_txt = perms2str(mode) perms_txt = perms2str(perms) warn_message = logging.SWKN_INVALID_MODE % (styles.stylize(styles.ST_PATH, onpath), styles.stylize(styles.ST_BAD, mode_txt), styles.stylize(styles.ST_ACL, perms_txt)) if batch or logging.ask_for_repair(warn_message, auto_answer): os.chmod(onpath, perms) logging.info("Applyed perms %s on %s." % (styles.stylize(styles.ST_ACL, perms_txt), styles.stylize(styles.ST_PATH, onpath))) else: all_went_ok = False return all_went_ok |
to_remove.append(member) | to_remove.add(member) | def load_groups(self): """ Load groups from /etc/{group,gshadow} and /etc/licorn/group. """ |
except (OSError, IOerror), e: | except (OSError, IOError), e: | def CleanUp(self): """This is a sort of destructor. Clean-up before being deleted...""" |
logging.info(logging.SYSG_CREATED_GROUP % styles.stylize(styles.ST_NAME, name)) | logging.info(logging.SYSG_CREATED_GROUP % \ styles.stylize(styles.ST_NAME, name)) | def AddGroup(self, name, gid=None, description="", groupSkel="", system=False, permissive=False, batch=False, force=False): """ Add an Licorn group (the group + the responsible group + the shared dir + permissions). """ |
dir_info.dirs_perm = "%s,g:%s:rw-,%s,%s" % \ | dir_info.dirs_perm = ("%s,g:%s:rw-,%s,%s" % \ | def generate_dir_info(self, user_info=None, dir_info_base=None): """ generate a FsapiObject from the rule. This object will be understandable by fsapi """ acl=self.acl |
LMC.configuration.acls.file_acl_mask) | LMC.configuration.acls.file_acl_mask)).replace( '@UX','x').replace('@GX','x') | def generate_dir_info(self, user_info=None, dir_info_base=None): """ generate a FsapiObject from the rule. This object will be understandable by fsapi """ acl=self.acl |
def shutdown(uri, http_user, hostname=None, sure=False, warn_users=True, yes=None): | def shutdown(uri, http_user, hostname=None, sure=False, warn_users=True, yes=None, configuration=None, machines=None, **kwargs): | def shutdown(uri, http_user, hostname=None, sure=False, warn_users=True, yes=None): """ Export machine list.""" # submit button; forget it. del yes title = _("Shutdown machine %s") % hostname data = w.page_body_start(uri, http_user, ctxtnav, title) if not sure: description = _('''Are you sure you want to remotely shutdown ''' '''machine %s?''') % hostname form_options = w.checkbox("warn_users", "True", '<strong>' + _("Warn connected user(s) before shuting system down.") + '</strong>', True) data += w.question(_("Please confirm operation"), description, yes_values = [ _("Shutdown") + ' >>', "/machines/shutdown/%s/sure" % hostname, "S" ], no_values = [ '<< ' + _("Cancel"), "/machines/list", "N" ], form_options = form_options) data += '</div><!-- end main -->' return (w.HTTP_TYPE_TEXT, w.page(title, data)) else: # we are sure, do it ! command = [ 'sudo', 'mod', 'machines', '--shutdown', '--no-colors' ] if warn_users: command.extend([ '--warn-users' ]) else: command.extend([ '--dont-warn-users' ]) command.extend([ '--hostname', hostname ]) return w.run(command, successfull_redirect, w.page(title, data + '%s' + w.page_body_end()), _('''Failed to shutdown machine %s!''' % hostname)) |
active=None, warn_users=None, admin=None, yes=None): | active=None, warn_users=None, admin=None, yes=None, configuration=None, machines=None, **kwargs): | def massshutdown(uri, http_user, sure=False, asleep=None, idle=None, active=None, warn_users=None, admin=None, yes=None): """ Export machine list.""" # submit button; forget it. del yes title = _("Massive shutdown") data = w.page_body_start(uri, http_user, ctxtnav, title) if not sure: description = _('''You can shutdown all currently running and/or idle''' ''' machines. This is a quite dangerous operation, because users''' ''' will be disconnected, and there is a potential to loose ''' '''unsaved work on idle machines (users are not in front of''' ''' them, they won't notice the system is shuting down.<br />''' '''<br />Systems will be shut down <strong>ONE minute</strong> ''' '''after validation.''') form_options = '%s<br />%s<br />%s<br />%s<br /><br />%s' % ( w.checkbox("active", "True", _("Shutdown <strong>active</strong> machines"), True), w.checkbox("idle", "True", _("Shutdown <strong>idle</strong> machines"), True), w.checkbox("asleep", "True", _("Shutdown <strong>asleep</strong> machines"), True), w.checkbox("admin", "True", _("Shutdown the <strong>administrator</strong> machine too<br/>(the one currently connected to the WMI)."), False), w.checkbox("warn_users", "True", '<strong>' + _("Warn connected users before shuting systems down.") + '</strong>', True) ) data += w.question(_("Choose machines to shutdown"), description, yes_values = [ _("Shutdown") + ' >>', "/machines/massshutdown/sure", "S" ], no_values = [ '<< ' + _("Cancel"), "/machines/list", "N" ], form_options = form_options) data += '</div><!-- end main -->' return (w.HTTP_TYPE_TEXT, w.page(title, data)) else: # we are sure, do it ! command = [ 'sudo', 'mod', 'machines', '--shutdown', '--no-colors' ] for option, argument in ( (asleep, '--asleep'), (idle, '--idle'), (active, '--active'), # not implemented yet #(no_admin, '--admin'), (warn_users, '--warn-users') ): if option: command.extend([argument]) return w.run(command, successfull_redirect, w.page(title, data + '%s' + w.page_body_end()), _('''Failed to shutdown one or more machines!''')) |
def energyprefs(uri, http_user): | def energyprefs(uri, http_user, configuration=None, machines=None, **kwargs): | def energyprefs(uri, http_user): """ Export machine list.""" # submit button; forget it. del yes title = _("Energy saving policies") if type == "": description = _('''CSV file-format is used by spreadsheets and most ''' '''systems which offer import functionnalities. XML file-format is a ''' '''modern exchange format, used in soma applications which respect ''' '''interoperability constraints.<br /><br />When you submit this ''' '''form, your web browser will automatically offer you to download ''' '''and save the export-file (it won't be displayed). When you're ''' '''done, please click the “back” button of your browser.''') form_options = \ _("Which file format do you want the machines list to be exported to? %s") \ % w.select("type", [ "CSV", "XML"]) data += w.question(_("Please choose file format for export list"), description, yes_values = [ _("Export >>"), "/machines/export", "E" ], no_values = [ _("<< Cancel"), "/machines/list", "N" ], form_options = form_options) data += '</div><!-- end main -->' return (w.HTTP_TYPE_TEXT, w.page(title, data)) else: machines.Select(machines.FILTER_STANDARD) if type == "CSV": data = machines.ExportCSV() else: data = machines.ExportXML() return w.HTTP_TYPE_DOWNLOAD, (type, data) |
def export(uri, http_user, type = "", yes = None): | def export(uri, http_user, type = "", yes=None, configuration=None, machines=None, **kwargs): | def export(uri, http_user, type = "", yes = None): """ Export machine list.""" # submit button; forget it. del yes return (w.HTTP_TYPE_TEXT, "not implemented yet.") title = _("Export machines list") data = '''<div id="banner"> %s %s</div> %s <div id="main"> %s <div id="content"> <h1>%s</h1>''' % ( w.backto(), w.metanav(http_user), w.menu(uri), ctxtnav(), title) if type == "": description = _('''CSV file-format is used by spreadsheets and most ''' '''systems which offer import functionnalities. XML file-format is a ''' '''modern exchange format, used in soma applications which respect ''' '''interoperability constraints.<br /><br />When you submit this ''' '''form, your web browser will automatically offer you to download ''' '''and save the export-file (it won't be displayed). When you're ''' '''done, please click the “back” button of your browser.''') form_options = \ _("Which file format do you want the machines list to be exported to? %s") \ % w.select("type", [ "CSV", "XML"]) data += w.question(_("Please choose file format for export list"), description, yes_values = [ _("Export >>"), "/machines/export", "E" ], no_values = [ _("<< Cancel"), "/machines/list", "N" ], form_options = form_options) data += '</div><!-- end main -->' return (w.HTTP_TYPE_TEXT, w.page(title, data)) else: machines.Select(machines.FILTER_STANDARD) if type == "CSV": data = machines.ExportCSV() else: data = machines.ExportXML() return w.HTTP_TYPE_DOWNLOAD, (type, data) |
def forget(uri, http_user, hostname, sure=False, yes=None): | def forget(uri, http_user, hostname, sure=False, yes=None, configuration=None, machines=None, **kwargs): | def forget(uri, http_user, hostname, sure=False, yes=None): """remove machine account.""" # form submit button, forget it. del yes return (w.HTTP_TYPE_TEXT, "not implemented yet.") title = _("Remove machine %s's record") % hostname if protected_user(hostname): return w.forgery_error(title) data = w.page_body_start(uri, http_user, ctxtnav, title) if not sure: data += w.question( _("Are you sure you want to remove record for machine <strong>%s</strong>?") \ % hostname, _('''User's <strong>personnal data</strong> (his/her HOME dir) ''' '''will be <strong>archived</strong> in directory <code>%s</code>''' ''' and members of group <strong>%s</strong> will be able to ''' ''' access it to operate an eventual recover.<br />However, you ''' '''can decide to permanently remove it.''') % ( configuration.home_archive_dir, configuration.defaults.admin_group), yes_values = \ [ _("Remove >>"), "/machines/delete/%s/sure" % hostname, _("R") ], no_values = \ [ _("<< Cancel"), "/machines/list", _("C") ], form_options = w.checkbox("no_archive", "True", _("Definitely remove record data (no archiving)."), checked = False) ) return (w.HTTP_TYPE_TEXT, w.page(title, data + w.page_body_end())) else: # we are sure, do it ! command = [ 'sudo', 'del', 'machine', '--quiet', '--no-colors', '--hostname', hostname ] if no_archive: command.extend(['--no-archive']) return w.run(command, successfull_redirect, w.page(title, data + '%s' + w.page_body_end()), _('''Failed to remove record <strong>%s</strong>!''') % hostname) |
def new(uri, http_user): | def new(uri, http_user, configuration=None, machines=None, **kwargs): | def new(uri, http_user): """Generate a form to create a new machine on the system.""" return (w.HTTP_TYPE_TEXT, "not implemented yet.") title = _("New machine record") data = w.page_body_start(uri, http_user, ctxtnav, title, False) def profile_input(): #TODO: To be rewritten ? return """ <tr> <td><strong>%s</strong></td> <td class="right"> |
create = None ): | create=None, configuration=None, machines=None, **kwargs): | def create(uri, http_user, loginShell, password, password_confirm, profile=None, hostname="", gecos="", firstname="", lastname="", standard_groups_dest=[], privileged_groups_dest=[], responsible_groups_dest=[], guest_groups_dest=[], standard_groups_source=[], privileged_groups_source=[], responsible_groups_source=[], guest_groups_source=[], create = None ): # forget it; useless del create return (w.HTTP_TYPE_TEXT, "not implemented yet.") title = _("New machine record %s") % hostname data = w.page_body_start(uri, http_user, ctxtnav, title, False) if password != password_confirm: return (w.HTTP_TYPE_TEXT, w.page(title, data + w.error(_("Passwords do not match!%s") % rewind))) if len(password) < configuration.users.min_passwd_size: return (w.HTTP_TYPE_TEXT, w.page(title, data + w.error(_("Password must be at least %d characters long!%s")\ % (configuration.users.min_passwd_size, rewind)))) command = [ "sudo", "add", "machine", '--quiet', '--no-colors', '--password', password ] if firstname != '' and lastname != '': command.extend(['--firstname', firstname, '--lastname', lastname]) if gecos != '': command.extend(['--gecos', gecos]) # TODO: set a default profile (see issue #6) if profile != None: command.extend([ "--profile", profile ]) if hostname != "": command.extend([ "--hostname", hostname ]) else: # TODO: Idem, "gecos" should be tested against emptyness command.extend([ '--hostname', hlstr.validate_name(gecos).replace('_', '.').rstrip('.') ]) (rettype, retdata) = w.run(command, successfull_redirect, w.page(title, data + '%s' + w.page_body_end()), _('''Failed to create record <strong>%s</strong>!''') % hostname) if rettype == w.HTTP_TYPE_TEXT: return (rettype, retdata) # else: continue the creation by adding groups… command = [ "sudo", "mod", "machine", '--quiet', "--no-colors", "--hostname", hostname, "--shell", loginShell ] add_groups = ','.join(__merge_multi_select( standard_groups_dest, privileged_groups_dest, responsible_groups_dest, guest_groups_dest)) if add_groups != "": command.extend([ '--add-groups', add_groups ]) return w.run(command, successfull_redirect, w.page(title, data + '%s' + w.page_body_end()), _('''Failed to add machine <strong>%s</strong> to requested groups/privileges/responsibilities/invitations!''') % hostname) |
def edit(uri, http_user, hostname): | def edit(uri, http_user, hostname, configuration=None, machines=None, **kwargs): | def edit(uri, http_user, hostname): """Edit an machine record, based on hostname.""" return (w.HTTP_TYPE_TEXT, "not implemented yet.") title = _("Edit %s's record") % hostname if protected_user(hostname): return w.forgery_error(title) data = w.page_body_start(uri, http_user, ctxtnav, title, False) try: machine = machines.machines[machines.hostname_to_mid(hostname)] try: profile = \ profiles.profiles[ groups.groups[machine['gidNumber']]['name'] ]['name'] except KeyError: profile = _("Standard account") dbl_lists = {} for filter, titles, id in groups_filters_lists_ids: dest = list(machine['groups'].copy()) source = [ groups.groups[gid]['name'] \ for gid in groups.Select(filter) ] for current in dest[:]: try: source.remove(current) except ValueError: dest.remove(current) dest.sort() source.sort() dbl_lists[filter] = w.doubleListBox(titles, id, source, dest) form_name = "user_edit_form" data += '''<div id="edit_form"> |
record = None): | record=None, configuration=None, machines=None, **kwargs): | def record(uri, http_user, hostname, loginShell=None, password = "", password_confirm = "", firstname = "", lastname = "", gecos = "", standard_groups_source = [], standard_groups_dest = [], privileged_groups_source = [], privileged_groups_dest = [], responsible_groups_source = [], responsible_groups_dest = [], guest_groups_source = [], guest_groups_dest = [], record = None): """Record machine changes.""" # submit button. forget it. del record return (w.HTTP_TYPE_TEXT, "not implemented yet.") title = _("Modification of %s's record") % hostname if protected_user(hostname): return w.forgery_error(title) data = w.page_body_start(uri, http_user, ctxtnav, title, False) command = [ "sudo", "mod", "machine", '--quiet', "--no-colors", "--hostname", hostname, "--shell", loginShell ] if password != "": if password != password_confirm: return (w.HTTP_TYPE_TEXT, w.page(title, data + w.error(_("Passwords do not match!%s") % rewind))) if len(password) < configuration.users.min_passwd_size: return (w.HTTP_TYPE_TEXT, w.page(title, data + w.error( _("The password --%s-- must be at least %d characters long!%s")\ % (password, configuration.users.min_passwd_size, rewind)))) command.extend([ '--password', password ]) command.extend( [ "--gecos", gecos ] ) add_groups = ','.join(__merge_multi_select( standard_groups_dest, privileged_groups_dest, responsible_groups_dest, guest_groups_dest)) del_groups = ','.join(__merge_multi_select( standard_groups_source, privileged_groups_source, responsible_groups_source, guest_groups_source)) if add_groups != "": command.extend([ '--add-groups', add_groups ]) if del_groups != "": command.extend(['--del-groups', del_groups ]) return w.run(command, successfull_redirect, w.page(title, data + '%s' + w.page_body_end()), _('''Failed to modify one or more parameters of record <strong>%s</strong>!''') % hostname) |
def main(uri, http_user, sort = "hostname", order = "asc"): | def main(uri, http_user, sort="hostname", order="asc", configuration=None, machines=None, **kwargs): | def main(uri, http_user, sort = "hostname", order = "asc"): """ display all machines in a nice HTML page. """ start = time.time() m = machines.machines accounts = {} ordered = {} totals = { _('managed'): 0, _('floating'): 0 } title = _("Machines") data = w.page_body_start(uri, http_user, ctxtnav, title) if order == "asc": reverseorder = "desc" else: reverseorder = "asc" data += '<table>\n <tr>' for (sortcolumn, sortname) in ( ("status", _("Status")), ("hostname", _("Host name")), ("ip", _("IP address")), ("ether", _("Hardware address")), ("expiry", _("Expiry")), ("managed", _("Managed")) ): if sortcolumn == sort: data += ''' <th><img src="/images/sort_%s.gif" alt="%s order image" />  <a href="/machines/list/%s/%s" title="%s">%s</a> </th>\n''' % (order, order, sortcolumn, reverseorder, _("Click to sort in reverse order."), sortname) else: data += ''' <th> <a href="/machines/list/%s/asc" title="%s">%s</a> </th>\n''' % (sortcolumn, _("Click to sort on this column."), sortname) data += ' </tr>\n' def html_build_compact(index, accounts = accounts): mid = ordered[index] hostname = m[mid]['hostname'] edit = 'machine %s (IP %s)' % (hostname, m[mid]['ip']) if m[mid]['managed']: totals[_('managed')] += 1 else: totals[_('floating')] += 1 power_statuses = { host_status.UNKNOWN: (None, 'unknown', _('''Host %s is in an unknown state. Nothing is possible. ''' '''Please wait for a reconnection.''')), host_status.OFFLINE: (None, 'offline', _('''Host %s is offline, and cannot be powered on from here,''' '''Only from the machine itself.''')), host_status.ASLEEP: ('shutdown', 'asleep', _('Shutdown the machine %s')), host_status.IDLE: ('shutdown', 'idle', _('Shutdown the machine %s')), host_status.ACTIVE: ('shutdown', 'active', _('Shutdown the machine %s')), } status = m[mid]['status'] if power_statuses[status][0]: html_data = ''' <tr class="userdata"> <!-- STATUS --> <td class="user_action_center"> <a href="/machines/%s/%s" title="%s" class="%s"> <span class="delete-entry"> </span></a> </td>''' % ( power_statuses[status][0], hostname, power_statuses[status][2] % hostname, power_statuses[status][1] ) else: html_data = ''' <tr class="userdata"> <!-- STATUS --> <td class="user_action_center"> <span class="%s" title="%s"> </span> </td>''' % ( power_statuses[status][1], power_statuses[status][2] % hostname) html_data += ''' <!-- HOSTNAME --> <td class="paddedright"> <a href="/machines/edit/%s" title="%s" class="edit-entry">%s%s</a> </td> <!-- IP --> <td class="paddedright"> <a href="/machines/edit/%s" title="%s" class="edit-entry">%s</a> </td> <!-- ETHER --> <td class="paddedright"> <a href="/machines/edit/%s" title="%s" class="edit-entry">%s</a> </td> <!-- EXPIRY --> <td class="paddedright"> <a href="/machines/edit/%s" title="%s" class="edit-entry">%s</a> </td> ''' % ( hostname, edit, hostname, ''' <img src='/images/16x16/alt.png' alt='%s' />''' % _('This machine is an ALT® client.') if machines.is_alt(mid) else '', hostname, edit, m[mid]['ip'], hostname, edit, m[mid]['ether'], hostname, edit, format_time_delta( float(m[mid]['expiry']) - time.time(), use_neg=True) \ if m[mid]['expiry'] else '-' ) if m[mid]['managed']: html_data += ''' <!-- MANAGED --> <td class="user_action_center"> <a href="/machines/unmanage/%s" title="%s" class="managed"> <span class="delete-entry"> </span></a> </td> ''' % (hostname, _("""Unmanage machine (remove it from """ """configuration, in order to allow it to be managed by """ """another server.""")) else: html_data += ''' <!-- UNMANAGED --> <td class="user_action_center"> <a href="/machines/manage/%s" title="%s" class="floating"> <span class="delete-entry"> </span></a> </td> ''' % (hostname, _("""Manage machine (fix its IP address and """ """configure various aspects of the client).""")) return html_data for mid in machines.keys(): machine = m[mid] hostname = machine['hostname'] # we add the hostname to gecosValue and lockedValue to be sure to obtain # unique values. This prevents problems with empty or non-unique GECOS # and when sorting on locked status (accounts would be overwritten and # lost because sorting must be done on unique values). accounts[mid] = { 'status' : str(machine['status']) + hostname, 'hostname': hostname, 'ip' : machine['ip'], 'ether' : machine['ether'], 'expiry' : machine['expiry'], 'managed' : str(machine['managed']) + hostname } # index on the column choosen for sorting, and keep trace of the mid # to find account data back after ordering. ordered[hlstr.validate_name(accounts[mid][sort])] = mid memberkeys = ordered.keys() memberkeys.sort() if order == "desc": memberkeys.reverse() data += ''.join(map(html_build_compact, memberkeys)) def print_totals(totals): output = "" for total in totals: if totals[total] != 0: output += ''' <tr class="list_total"> <td colspan="5" class="total_left">%s</td> <td class="total_right">%d</td> </tr> ''' % (_("number of <strong>%s</strong> machines:") % total, totals[total]) return output data += ''' <tr> <td colspan="5"> </td></tr> %s <tr class="list_total"> <td colspan="5" class="total_left">%s</td> <td class="total_right">%d</td> </tr> |
groups_filters_lists_ids = ( (name, ( _('Manage members'), _('Users not yet members'), _('Current members') ), 'members' ), (configuration.groups.resp_prefix + name, None, '& (configuration.groups.guest_prefix + name, None, '& ) | groups_filters_lists_ids = [ (name, [ _('Manage members'), _('Users not yet members'), _('Current members') ], 'members' ) ] | def edit(uri, http_user, name): """Edit a group.""" users.reload() groups.reload() u = users.users g = groups.groups title = _("Editing group %s") % name data = w.page_body_start(uri, http_user, ctxtnav, title, False) try: group = g[groups.name_to_gid(name)] sys = groups.is_system_group(name) dbl_lists = {} if sys: groups_filters_lists_ids = ( (name, ( _('Manage members'), _('Users not yet members'), _('Current members') ), 'members' ), (configuration.groups.resp_prefix + name, None, ' ' ), (configuration.groups.guest_prefix + name, None, ' ' ) ) else: groups_filters_lists_ids = ( (name, [_('Manage members'), _('Users not yet members'), _('Current members')], 'members'), (configuration.groups.resp_prefix + name, [_('Manage responsibles'), _('Users not yet responsibles'), _('Current responsibles')], 'resps'), (configuration.groups.guest_prefix + name, [_('Manage guests'), _('Users not yet guests'), _('Current guests')], 'guests') ) for (gname, titles, id) in groups_filters_lists_ids: if titles is None: dbl_lists[gname] = id else: users.Select(users.FILTER_STANDARD) dest = list(g[groups.name_to_gid(gname)]['memberUid']) source = [ u[uid]['login'] for uid in users.filtered_users ] for current in g[groups.name_to_gid(gname)]['memberUid']: try: source.remove(current) except ValueError: dest.remove(current) dest.sort() source.sort() dbl_lists[gname] = w.doubleListBox(titles, id, source, dest) def descr(desc, system): return w.input('description', desc, size=30, maxlength=256, accesskey='D') def skel(cur_skel, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Skeleton'), w.select('skel', configuration.users.skels, cur_skel, func = os.path.basename)) def permissive(perm, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Permissive shared dir?'), w.checkbox('permissive', "True", "Oui", checked = perm )) form_name = "group_edit_form" data += '''<div id="edit_form"> |
dest = list(g[groups.name_to_gid(gname)]['memberUid']) | dest = list(group['memberUid']) | def edit(uri, http_user, name): """Edit a group.""" users.reload() groups.reload() u = users.users g = groups.groups title = _("Editing group %s") % name data = w.page_body_start(uri, http_user, ctxtnav, title, False) try: group = g[groups.name_to_gid(name)] sys = groups.is_system_group(name) dbl_lists = {} if sys: groups_filters_lists_ids = ( (name, ( _('Manage members'), _('Users not yet members'), _('Current members') ), 'members' ), (configuration.groups.resp_prefix + name, None, ' ' ), (configuration.groups.guest_prefix + name, None, ' ' ) ) else: groups_filters_lists_ids = ( (name, [_('Manage members'), _('Users not yet members'), _('Current members')], 'members'), (configuration.groups.resp_prefix + name, [_('Manage responsibles'), _('Users not yet responsibles'), _('Current responsibles')], 'resps'), (configuration.groups.guest_prefix + name, [_('Manage guests'), _('Users not yet guests'), _('Current guests')], 'guests') ) for (gname, titles, id) in groups_filters_lists_ids: if titles is None: dbl_lists[gname] = id else: users.Select(users.FILTER_STANDARD) dest = list(g[groups.name_to_gid(gname)]['memberUid']) source = [ u[uid]['login'] for uid in users.filtered_users ] for current in g[groups.name_to_gid(gname)]['memberUid']: try: source.remove(current) except ValueError: dest.remove(current) dest.sort() source.sort() dbl_lists[gname] = w.doubleListBox(titles, id, source, dest) def descr(desc, system): return w.input('description', desc, size=30, maxlength=256, accesskey='D') def skel(cur_skel, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Skeleton'), w.select('skel', configuration.users.skels, cur_skel, func = os.path.basename)) def permissive(perm, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Permissive shared dir?'), w.checkbox('permissive', "True", "Oui", checked = perm )) form_name = "group_edit_form" data += '''<div id="edit_form"> |
for current in g[groups.name_to_gid(gname)]['memberUid']: try: source.remove(current) except ValueError: dest.remove(current) | for current in group['memberUid']: try: source.remove(current) except ValueError: dest.remove(current) | def edit(uri, http_user, name): """Edit a group.""" users.reload() groups.reload() u = users.users g = groups.groups title = _("Editing group %s") % name data = w.page_body_start(uri, http_user, ctxtnav, title, False) try: group = g[groups.name_to_gid(name)] sys = groups.is_system_group(name) dbl_lists = {} if sys: groups_filters_lists_ids = ( (name, ( _('Manage members'), _('Users not yet members'), _('Current members') ), 'members' ), (configuration.groups.resp_prefix + name, None, ' ' ), (configuration.groups.guest_prefix + name, None, ' ' ) ) else: groups_filters_lists_ids = ( (name, [_('Manage members'), _('Users not yet members'), _('Current members')], 'members'), (configuration.groups.resp_prefix + name, [_('Manage responsibles'), _('Users not yet responsibles'), _('Current responsibles')], 'resps'), (configuration.groups.guest_prefix + name, [_('Manage guests'), _('Users not yet guests'), _('Current guests')], 'guests') ) for (gname, titles, id) in groups_filters_lists_ids: if titles is None: dbl_lists[gname] = id else: users.Select(users.FILTER_STANDARD) dest = list(g[groups.name_to_gid(gname)]['memberUid']) source = [ u[uid]['login'] for uid in users.filtered_users ] for current in g[groups.name_to_gid(gname)]['memberUid']: try: source.remove(current) except ValueError: dest.remove(current) dest.sort() source.sort() dbl_lists[gname] = w.doubleListBox(titles, id, source, dest) def descr(desc, system): return w.input('description', desc, size=30, maxlength=256, accesskey='D') def skel(cur_skel, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Skeleton'), w.select('skel', configuration.users.skels, cur_skel, func = os.path.basename)) def permissive(perm, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Permissive shared dir?'), w.checkbox('permissive', "True", "Oui", checked = perm )) form_name = "group_edit_form" data += '''<div id="edit_form"> |
if system: return '' else: return ''' | return '' if system else \ ''' | def skel(cur_skel, system): if system: return '' else: return ''' <tr> <td><strong>%s</strong></td> <td class="right">%s</td> </tr> ''' % (_('Skeleton'), w.select('skel', configuration.users.skels, cur_skel, func = os.path.basename)) |
if system: return '' else: return ''' | return '' if system else \ ''' | def permissive(perm, system): |
<h2 class="accordion_toggle">≫ %s</h2> <div class="accordion_content">%s</div> <h2 class="accordion_toggle">≫ %s</h2> <div class="accordion_content">%s</div> | %s | def permissive(perm, system): |
_('Group responsibles'), dbl_lists[configuration.groups.resp_prefix+name], _('Group guests'), dbl_lists[configuration.groups.guest_prefix+name], | data_rsp_gst, | def permissive(perm, system): |
for member in groups.groups[gid]['memberUid']: | for member in group['memberUid']: | def main(uri, http_user, sort = "name", order = "asc"): """List all groups and provileges on the system, displaying them in a nice HTML page. """ start = time.time() users.reload() groups.reload() #profiles.reload() g = groups.groups users.Select(users.FILTER_STANDARD) tgroups = {} totals = {} title = _('Groups') data = w.page_body_start(uri, http_user, ctxtnav, title) if order == "asc": reverseorder = "desc" else: reverseorder = "asc" data += '<table>\n <tr>\n' sortcols = ( ('', '', False), ("name", _("Name"), True), ("description", _("Description"), True), ("skel", _("Skeleton"), True), ("permissive", _("Perm."), True), ('members', _("Members"), False), ("resps", _("Responsibles"), False), ("guests", _("Guests"), False) ) for (column, name, can_sort) in sortcols: if can_sort: if column == sort: data += ''' <th><img src="/images/sort_%s.gif" alt="%s" />  <a href="/groups/list/%s/%s" title="%s">%s</a> </th>\n''' % (order, _('%s order') % order, column, reverseorder, _('Click to sort in reverse order.'), name) else: data += ''' <th><a href="/groups/list/%s/asc" title="%s">%s</a></th>\n''' % (column, _('Click to sort on this column.'), name) else: data += ' <th>%s</th>\n' % name data += ' </tr>\n' for (filter, filter_name) in ( (groups.FILTER_STANDARD, _('Groups')), (groups.FILTER_PRIVILEGED, _("Privileges")) ): tgroups = {} ordered = {} totals[filter_name] = 0 groups.Select(filter) for gid in groups.filtered_groups: group = groups.groups[gid] name = group['name'] tgroups[gid] = { 'name' : name, 'description' : group['description'] + name, 'skel' : group['groupSkel'] + name, 'permissive' : str(group['permissive']) + name } totals[filter_name] += 1 # index on the column choosen for sorting, and keep trace of the uid # to find account data back after ordering. ordered[hlstr.validate_name(tgroups[gid][sort])] = gid tgroups[gid]['memberUid'] = [] for member in groups.groups[gid]['memberUid']: if not users.is_system_login(member): tgroups[gid]['memberUid'].append( users.users[users.login_to_uid(member)]) if not groups.is_system_gid(gid): for prefix in ( configuration.groups.resp_prefix, configuration.groups.guest_prefix): tgroups[gid][prefix + 'members'] = [] for member in \ groups.groups[groups.name_to_gid( prefix + name)]['memberUid']: if not users.is_system_login(member): tgroups[gid][prefix + 'members'].append( users.users[users.login_to_uid(member)]) gkeys = ordered.keys() gkeys.sort() if order == "desc": gkeys.reverse() def html_build_group(index, tgroups = tgroups ): gid = ordered[index] name = g[gid]['name'] html_data = ''' <tr class="userdata"> <td class="nopadding"> <a href="/groups/view/%s" title="%s" class="view-entry"> <span class="view-entry"> </span> </a> </td> <td class="group_name"> <a href="/groups/edit/%s" title="%s" class="edit-entry">%s</a> </td> <td class="group_name"> <a href="/groups/edit/%s" title="%s" class="edit-entry">%s</a> </td> <td class="right"> <a href="/groups/edit/%s">%s</a> </td> ''' % ( name, _('''View the group details, its parameters, members, responsibles and guests. From there you can print all group-related informations.'''), name, g[gid]['description'], name, name, g[gid]['description'], g[gid]['description'], name, g[gid]['groupSkel']) if groups.is_system_gid(gid): html_data += '<td> </td>' else: if g[gid]['permissive']: html_data += ''' <td class="user_action_center"> <a href="/groups/lock/%s" title="%s"> <img src="/images/16x16/unlocked.png" alt="%s"/></a> </td> ''' % (name, _('''Shared group directory is currently ''' '''<strong>permissive</strong>. Click to deactivate ''' '''permissiveness.'''), _('Group is currently permissive.')) else: html_data += ''' <td class="user_action_center"> <a href="/groups/unlock/%s" title="%s"> <img src="/images/16x16/locked.png" alt="%s"/></a> </td> ''' % (name, _('''Shared group directory is currently <strong>NOT</strong> permissive. Click ti activate permissiveness.'''), _('Group is NOT permissive.')) for (keyname, text) in ( ('members', _('Current members')), ('rsp-members', _('Current responsibles')), ('gst-members', _('Current guests')) ): if tgroups[gid].has_key(keyname): accounts = {} uordered = {} for member in tgroups[gid][keyname]: uid = member['uidNumber'] accounts[uid] = { 'login': member['login'], 'gecos': member['gecos'], 'gecos_sort': member['gecos'] + member['login'] } uordered[hlstr.validate_name( accounts[uid]['gecos_sort'], aggressive=True)] = uid memberkeys = uordered.keys() memberkeys.sort() mbdata = '''<table><tr><th>%s</th><th>%s</th> <th>%s</th></tr>\n''' % (_('Full Name'), _('Identifier'), _('UID')) for member in memberkeys: uid = uordered[member] mbdata += '''<tr><td>%s</td><td>%s</td> <td>%d</td></tr>\n''' % (accounts[uid]['gecos'], accounts[uid]['login'], uid) mbdata += '</table>' nb = len(tgroups[gid][keyname]) if nb == 0: html_data += '''<td class="right faded">%s</td>\n''' % \ _('none') else: html_data += '''<td class="right"> <a class="nounder" title="<h4>%s</h4><br />%s"> <strong>%d</strong> <img src="/images/16x16/details-light.png" alt="%s" /></a></td>\n''' % (text, mbdata, nb, _('See %s of group %s.') % (text, name)) else: html_data += '''<td> </td>\n''' if groups.is_system_gid(gid): html_data += '<td colspan="1"> </td></tr>\n' else: html_data += ''' <!-- TODO: implement skel reapplying for all users of curent group <td class="user_action"> <a href="/users/skel/%s" title="%s" class="reapply-skel"> <span class="reapply-skel"> </span> </a> </td> --> <td class="user_action"> <a href="/groups/delete/%s" title="%s" class="delete-entry"> <span class="delete-entry"> </span> </a> </td> </tr> ''' % (name, _('''This will rebuild his/her desktop from scratch, with defaults icons and so on. <br /><br />The user must be disconnected for the operation to be completely successfull.'''), name, _('''Definitely remove this group from system.''')) return html_data data += '<tr><td class="group_class" colspan="8">%s</td></tr>\n%s' % ( filter_name, ''.join(map(html_build_group, gkeys))) def print_totals(totals): output = "" for total in totals: if totals[total] != 0: output += ''' <tr class="list_total"> <td colspan="6" class="total_left">%s</td> <td colspan="6" class="total_right">%d</td> </tr> ''' % (_('number of <strong>%s</strong>:') % total, totals[total]) return output data += ''' <tr> <td colspan="6"> </td></tr> %s <tr class="list_total"> <td colspan="6" class="total_left"><strong>%s</strong></td> <td colspan="6" class="total_right">%d</td> </tr> |
tgroups[gid][prefix + 'members'] = [] | tgroups[gid][prefix + 'memberUid'] = [] | def main(uri, http_user, sort = "name", order = "asc"): """List all groups and provileges on the system, displaying them in a nice HTML page. """ start = time.time() users.reload() groups.reload() #profiles.reload() g = groups.groups users.Select(users.FILTER_STANDARD) tgroups = {} totals = {} title = _('Groups') data = w.page_body_start(uri, http_user, ctxtnav, title) if order == "asc": reverseorder = "desc" else: reverseorder = "asc" data += '<table>\n <tr>\n' sortcols = ( ('', '', False), ("name", _("Name"), True), ("description", _("Description"), True), ("skel", _("Skeleton"), True), ("permissive", _("Perm."), True), ('members', _("Members"), False), ("resps", _("Responsibles"), False), ("guests", _("Guests"), False) ) for (column, name, can_sort) in sortcols: if can_sort: if column == sort: data += ''' <th><img src="/images/sort_%s.gif" alt="%s" />  <a href="/groups/list/%s/%s" title="%s">%s</a> </th>\n''' % (order, _('%s order') % order, column, reverseorder, _('Click to sort in reverse order.'), name) else: data += ''' <th><a href="/groups/list/%s/asc" title="%s">%s</a></th>\n''' % (column, _('Click to sort on this column.'), name) else: data += ' <th>%s</th>\n' % name data += ' </tr>\n' for (filter, filter_name) in ( (groups.FILTER_STANDARD, _('Groups')), (groups.FILTER_PRIVILEGED, _("Privileges")) ): tgroups = {} ordered = {} totals[filter_name] = 0 groups.Select(filter) for gid in groups.filtered_groups: group = groups.groups[gid] name = group['name'] tgroups[gid] = { 'name' : name, 'description' : group['description'] + name, 'skel' : group['groupSkel'] + name, 'permissive' : str(group['permissive']) + name } totals[filter_name] += 1 # index on the column choosen for sorting, and keep trace of the uid # to find account data back after ordering. ordered[hlstr.validate_name(tgroups[gid][sort])] = gid tgroups[gid]['memberUid'] = [] for member in groups.groups[gid]['memberUid']: if not users.is_system_login(member): tgroups[gid]['memberUid'].append( users.users[users.login_to_uid(member)]) if not groups.is_system_gid(gid): for prefix in ( configuration.groups.resp_prefix, configuration.groups.guest_prefix): tgroups[gid][prefix + 'members'] = [] for member in \ groups.groups[groups.name_to_gid( prefix + name)]['memberUid']: if not users.is_system_login(member): tgroups[gid][prefix + 'members'].append( users.users[users.login_to_uid(member)]) gkeys = ordered.keys() gkeys.sort() if order == "desc": gkeys.reverse() def html_build_group(index, tgroups = tgroups ): gid = ordered[index] name = g[gid]['name'] html_data = ''' <tr class="userdata"> <td class="nopadding"> <a href="/groups/view/%s" title="%s" class="view-entry"> <span class="view-entry"> </span> </a> </td> <td class="group_name"> <a href="/groups/edit/%s" title="%s" class="edit-entry">%s</a> </td> <td class="group_name"> <a href="/groups/edit/%s" title="%s" class="edit-entry">%s</a> </td> <td class="right"> <a href="/groups/edit/%s">%s</a> </td> ''' % ( name, _('''View the group details, its parameters, members, responsibles and guests. From there you can print all group-related informations.'''), name, g[gid]['description'], name, name, g[gid]['description'], g[gid]['description'], name, g[gid]['groupSkel']) if groups.is_system_gid(gid): html_data += '<td> </td>' else: if g[gid]['permissive']: html_data += ''' <td class="user_action_center"> <a href="/groups/lock/%s" title="%s"> <img src="/images/16x16/unlocked.png" alt="%s"/></a> </td> ''' % (name, _('''Shared group directory is currently ''' '''<strong>permissive</strong>. Click to deactivate ''' '''permissiveness.'''), _('Group is currently permissive.')) else: html_data += ''' <td class="user_action_center"> <a href="/groups/unlock/%s" title="%s"> <img src="/images/16x16/locked.png" alt="%s"/></a> </td> ''' % (name, _('''Shared group directory is currently <strong>NOT</strong> permissive. Click ti activate permissiveness.'''), _('Group is NOT permissive.')) for (keyname, text) in ( ('members', _('Current members')), ('rsp-members', _('Current responsibles')), ('gst-members', _('Current guests')) ): if tgroups[gid].has_key(keyname): accounts = {} uordered = {} for member in tgroups[gid][keyname]: uid = member['uidNumber'] accounts[uid] = { 'login': member['login'], 'gecos': member['gecos'], 'gecos_sort': member['gecos'] + member['login'] } uordered[hlstr.validate_name( accounts[uid]['gecos_sort'], aggressive=True)] = uid memberkeys = uordered.keys() memberkeys.sort() mbdata = '''<table><tr><th>%s</th><th>%s</th> <th>%s</th></tr>\n''' % (_('Full Name'), _('Identifier'), _('UID')) for member in memberkeys: uid = uordered[member] mbdata += '''<tr><td>%s</td><td>%s</td> <td>%d</td></tr>\n''' % (accounts[uid]['gecos'], accounts[uid]['login'], uid) mbdata += '</table>' nb = len(tgroups[gid][keyname]) if nb == 0: html_data += '''<td class="right faded">%s</td>\n''' % \ _('none') else: html_data += '''<td class="right"> <a class="nounder" title="<h4>%s</h4><br />%s"> <strong>%d</strong> <img src="/images/16x16/details-light.png" alt="%s" /></a></td>\n''' % (text, mbdata, nb, _('See %s of group %s.') % (text, name)) else: html_data += '''<td> </td>\n''' if groups.is_system_gid(gid): html_data += '<td colspan="1"> </td></tr>\n' else: html_data += ''' <!-- TODO: implement skel reapplying for all users of curent group <td class="user_action"> <a href="/users/skel/%s" title="%s" class="reapply-skel"> <span class="reapply-skel"> </span> </a> </td> --> <td class="user_action"> <a href="/groups/delete/%s" title="%s" class="delete-entry"> <span class="delete-entry"> </span> </a> </td> </tr> ''' % (name, _('''This will rebuild his/her desktop from scratch, with defaults icons and so on. <br /><br />The user must be disconnected for the operation to be completely successfull.'''), name, _('''Definitely remove this group from system.''')) return html_data data += '<tr><td class="group_class" colspan="8">%s</td></tr>\n%s' % ( filter_name, ''.join(map(html_build_group, gkeys))) def print_totals(totals): output = "" for total in totals: if totals[total] != 0: output += ''' <tr class="list_total"> <td colspan="6" class="total_left">%s</td> <td colspan="6" class="total_right">%d</td> </tr> ''' % (_('number of <strong>%s</strong>:') % total, totals[total]) return output data += ''' <tr> <td colspan="6"> </td></tr> %s <tr class="list_total"> <td colspan="6" class="total_left"><strong>%s</strong></td> <td colspan="6" class="total_right">%d</td> </tr> |
tgroups[gid][prefix + 'members'].append( | tgroups[gid][prefix + 'memberUid'].append( | def main(uri, http_user, sort = "name", order = "asc"): """List all groups and provileges on the system, displaying them in a nice HTML page. """ start = time.time() users.reload() groups.reload() #profiles.reload() g = groups.groups users.Select(users.FILTER_STANDARD) tgroups = {} totals = {} title = _('Groups') data = w.page_body_start(uri, http_user, ctxtnav, title) if order == "asc": reverseorder = "desc" else: reverseorder = "asc" data += '<table>\n <tr>\n' sortcols = ( ('', '', False), ("name", _("Name"), True), ("description", _("Description"), True), ("skel", _("Skeleton"), True), ("permissive", _("Perm."), True), ('members', _("Members"), False), ("resps", _("Responsibles"), False), ("guests", _("Guests"), False) ) for (column, name, can_sort) in sortcols: if can_sort: if column == sort: data += ''' <th><img src="/images/sort_%s.gif" alt="%s" />  <a href="/groups/list/%s/%s" title="%s">%s</a> </th>\n''' % (order, _('%s order') % order, column, reverseorder, _('Click to sort in reverse order.'), name) else: data += ''' <th><a href="/groups/list/%s/asc" title="%s">%s</a></th>\n''' % (column, _('Click to sort on this column.'), name) else: data += ' <th>%s</th>\n' % name data += ' </tr>\n' for (filter, filter_name) in ( (groups.FILTER_STANDARD, _('Groups')), (groups.FILTER_PRIVILEGED, _("Privileges")) ): tgroups = {} ordered = {} totals[filter_name] = 0 groups.Select(filter) for gid in groups.filtered_groups: group = groups.groups[gid] name = group['name'] tgroups[gid] = { 'name' : name, 'description' : group['description'] + name, 'skel' : group['groupSkel'] + name, 'permissive' : str(group['permissive']) + name } totals[filter_name] += 1 # index on the column choosen for sorting, and keep trace of the uid # to find account data back after ordering. ordered[hlstr.validate_name(tgroups[gid][sort])] = gid tgroups[gid]['memberUid'] = [] for member in groups.groups[gid]['memberUid']: if not users.is_system_login(member): tgroups[gid]['memberUid'].append( users.users[users.login_to_uid(member)]) if not groups.is_system_gid(gid): for prefix in ( configuration.groups.resp_prefix, configuration.groups.guest_prefix): tgroups[gid][prefix + 'members'] = [] for member in \ groups.groups[groups.name_to_gid( prefix + name)]['memberUid']: if not users.is_system_login(member): tgroups[gid][prefix + 'members'].append( users.users[users.login_to_uid(member)]) gkeys = ordered.keys() gkeys.sort() if order == "desc": gkeys.reverse() def html_build_group(index, tgroups = tgroups ): gid = ordered[index] name = g[gid]['name'] html_data = ''' <tr class="userdata"> <td class="nopadding"> <a href="/groups/view/%s" title="%s" class="view-entry"> <span class="view-entry"> </span> </a> </td> <td class="group_name"> <a href="/groups/edit/%s" title="%s" class="edit-entry">%s</a> </td> <td class="group_name"> <a href="/groups/edit/%s" title="%s" class="edit-entry">%s</a> </td> <td class="right"> <a href="/groups/edit/%s">%s</a> </td> ''' % ( name, _('''View the group details, its parameters, members, responsibles and guests. From there you can print all group-related informations.'''), name, g[gid]['description'], name, name, g[gid]['description'], g[gid]['description'], name, g[gid]['groupSkel']) if groups.is_system_gid(gid): html_data += '<td> </td>' else: if g[gid]['permissive']: html_data += ''' <td class="user_action_center"> <a href="/groups/lock/%s" title="%s"> <img src="/images/16x16/unlocked.png" alt="%s"/></a> </td> ''' % (name, _('''Shared group directory is currently ''' '''<strong>permissive</strong>. Click to deactivate ''' '''permissiveness.'''), _('Group is currently permissive.')) else: html_data += ''' <td class="user_action_center"> <a href="/groups/unlock/%s" title="%s"> <img src="/images/16x16/locked.png" alt="%s"/></a> </td> ''' % (name, _('''Shared group directory is currently <strong>NOT</strong> permissive. Click ti activate permissiveness.'''), _('Group is NOT permissive.')) for (keyname, text) in ( ('members', _('Current members')), ('rsp-members', _('Current responsibles')), ('gst-members', _('Current guests')) ): if tgroups[gid].has_key(keyname): accounts = {} uordered = {} for member in tgroups[gid][keyname]: uid = member['uidNumber'] accounts[uid] = { 'login': member['login'], 'gecos': member['gecos'], 'gecos_sort': member['gecos'] + member['login'] } uordered[hlstr.validate_name( accounts[uid]['gecos_sort'], aggressive=True)] = uid memberkeys = uordered.keys() memberkeys.sort() mbdata = '''<table><tr><th>%s</th><th>%s</th> <th>%s</th></tr>\n''' % (_('Full Name'), _('Identifier'), _('UID')) for member in memberkeys: uid = uordered[member] mbdata += '''<tr><td>%s</td><td>%s</td> <td>%d</td></tr>\n''' % (accounts[uid]['gecos'], accounts[uid]['login'], uid) mbdata += '</table>' nb = len(tgroups[gid][keyname]) if nb == 0: html_data += '''<td class="right faded">%s</td>\n''' % \ _('none') else: html_data += '''<td class="right"> <a class="nounder" title="<h4>%s</h4><br />%s"> <strong>%d</strong> <img src="/images/16x16/details-light.png" alt="%s" /></a></td>\n''' % (text, mbdata, nb, _('See %s of group %s.') % (text, name)) else: html_data += '''<td> </td>\n''' if groups.is_system_gid(gid): html_data += '<td colspan="1"> </td></tr>\n' else: html_data += ''' <!-- TODO: implement skel reapplying for all users of curent group <td class="user_action"> <a href="/users/skel/%s" title="%s" class="reapply-skel"> <span class="reapply-skel"> </span> </a> </td> --> <td class="user_action"> <a href="/groups/delete/%s" title="%s" class="delete-entry"> <span class="delete-entry"> </span> </a> </td> </tr> ''' % (name, _('''This will rebuild his/her desktop from scratch, with defaults icons and so on. <br /><br />The user must be disconnected for the operation to be completely successfull.'''), name, _('''Definitely remove this group from system.''')) return html_data data += '<tr><td class="group_class" colspan="8">%s</td></tr>\n%s' % ( filter_name, ''.join(map(html_build_group, gkeys))) def print_totals(totals): output = "" for total in totals: if totals[total] != 0: output += ''' <tr class="list_total"> <td colspan="6" class="total_left">%s</td> <td colspan="6" class="total_right">%d</td> </tr> ''' % (_('number of <strong>%s</strong>:') % total, totals[total]) return output data += ''' <tr> <td colspan="6"> </td></tr> %s <tr class="list_total"> <td colspan="6" class="total_left"><strong>%s</strong></td> <td colspan="6" class="total_right">%d</td> </tr> |
('members', _('Current members')), ('rsp-members', _('Current responsibles')), ('gst-members', _('Current guests')) ): | ('memberUid', _('Current members')), ('rsp-memberUid', _('Current responsibles')), ('gst-memberUid', _('Current guests')) ): | def html_build_group(index, tgroups = tgroups ): gid = ordered[index] name = g[gid]['name'] html_data = ''' |
if prim_memb != []: | if prim_memb != set(): | def DeleteGroup(self, name, del_users, no_archive, bygid = None, batch=False): """ Delete an Licorn group """ if name is None and bygid is None: raise exceptions.BadArgumentError, "You must specify a name or a GID." |
return GroupsController.is_standard_gid(gid) and GroupsController.groups[gid]['memberUid'] == [] | return GroupsController.is_standard_gid(gid) and GroupsController.groups[gid]['memberUid'] == set() | def is_empty_gid(gid): return GroupsController.is_standard_gid(gid) and GroupsController.groups[gid]['memberUid'] == [] |
(LMC.users.Select(filters.STD), LMC.users.confirm_uid), (LMC.users.Select(filters.SYSUNRSTR), LMC.users.confirm_uid) | (LMC.users.Select(filters.STD), lambda x: x), (LMC.users.Select(filters.SYSUNRSTR), lambda x: x) | def del_user(self, opts, args): """ delete a user account. """ include_id_lists=[ (opts.login, LMC.users.login_to_uid), (opts.uid, LMC.users.confirm_uid) ] exclude_id_lists=[ (opts.exclude, LMC.users.guess_identifier), (opts.exclude_login, LMC.users.login_to_uid), (opts.exclude_uid, LMC.users.confirm_uid), ([os.getuid()], LMC.users.confirm_uid) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to delete all users ?', auto_answer=opts.auto_answer) or not opts.non_interactive)): include_id_lists.extend([ (LMC.users.Select(filters.STD), LMC.users.confirm_uid), (LMC.users.Select(filters.SYSUNRSTR), LMC.users.confirm_uid) ]) uids_to_del = self.select(LMC.users, 'user', args=args, include_id_lists=include_id_lists, exclude_id_lists=exclude_id_lists) |
(LMC.groups.Select(filters.STD), LMC.groups.confirm_gid), (LMC.groups.Select(filters.SYSUNRSTR), LMC.groups.confirm_gid) | (LMC.groups.Select(filters.STD), lambda x: x), (LMC.groups.Select(filters.SYSUNRSTR), lambda x: x) | def del_group(self, opts, args): """ delete an Licorn group. """ selection = filters.NONE if opts.empty: selection = filters.EMPTY include_id_lists=[ (opts.name, LMC.groups.name_to_gid), (opts.gid, LMC.groups.confirm_gid), ] exclude_id_lists = [ (opts.exclude, LMC.groups.guess_identifier), (opts.exclude_group, LMC.groups.name_to_gid), (opts.exclude_gid, LMC.groups.confirm_gid) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to delete all groups ?', auto_answer=opts.auto_answer) or not opts.non_interactive)): include_id_lists.extend([ (LMC.groups.Select(filters.STD), LMC.groups.confirm_gid), (LMC.groups.Select(filters.SYSUNRSTR), LMC.groups.confirm_gid) ]) gids_to_del = self.select(LMC.groups, 'group', args, include_id_lists=include_id_lists, exclude_id_lists = exclude_id_lists, default_selection=selection) for gid in gids_to_del: if opts.non_interactive or opts.batch or opts.force or \ logging.ask_for_repair('''Delete group %s ?''' % stylize( ST_LOGIN,LMC.groups.gid_to_name(gid)), auto_answer=opts.auto_answer): LMC.groups.DeleteGroup(gid=gid, del_users=opts.del_users, no_archive=opts.no_archive) #logging.notice("Deleting group : %s" % LMC.groups.gid_to_name(gid)) |
(LMC.profiles.Select(filters.ALL), LMC.profiles.guess_identifier) | (LMC.profiles.Select(filters.ALL), lambda x: x) | def del_profile(self, opts, args): """ Delete a system wide User profile. """ include_id_lists=[ (opts.name, LMC.profiles.name_to_group), (opts.group, LMC.profiles.confirm_group) ] exclude_id_lists=[ (opts.exclude, LMC.profiles.guess_identifier) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to delete all profiles ?', opts.auto_answer) \ or not opts.non_interactive) ): include_id_lists.extend([ (LMC.profiles.Select(filters.ALL), LMC.profiles.guess_identifier) ]) |
'Are you sure you want to delete all users ?', | 'Are you sure you want to delete all privileges?', | def del_privilege(self, opts, args): if opts.privileges_to_remove is None and len(args) == 2: opts.privileges_to_remove = args[1] include_priv_lists=[ (opts.privileges_to_remove, LMC.privileges.confirm_privilege), ] exclude_priv_lists=[ (opts.exclude, LMC.privileges.confirm_privilege), ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to delete all users ?', auto_answer=opts.auto_answer) or not opts.non_interactive)): include_priv_lists.extend([ (LMC.privileges.Select(filters.ALL), LMC.privileges.confirm_privilege), ]) privs_to_del = self.select(LMC.privileges, 'privilege',args=args, include_id_lists=include_priv_lists, exclude_id_lists=exclude_priv_lists) |
(LMC.privileges.Select(filters.ALL), LMC.privileges.confirm_privilege), | (LMC.privileges.Select(filters.ALL), lambda x: x), | def del_privilege(self, opts, args): if opts.privileges_to_remove is None and len(args) == 2: opts.privileges_to_remove = args[1] include_priv_lists=[ (opts.privileges_to_remove, LMC.privileges.confirm_privilege), ] exclude_priv_lists=[ (opts.exclude, LMC.privileges.confirm_privilege), ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to delete all users ?', auto_answer=opts.auto_answer) or not opts.non_interactive)): include_priv_lists.extend([ (LMC.privileges.Select(filters.ALL), LMC.privileges.confirm_privilege), ]) privs_to_del = self.select(LMC.privileges, 'privilege',args=args, include_id_lists=include_priv_lists, exclude_id_lists=exclude_priv_lists) |
(LMC.groups.Select(filters.STD), LMC.groups.confirm_gid), (LMC.groups.Select(filters.SYSUNRSTR), LMC.groups.confirm_gid) | (LMC.groups.Select(filters.STD), lambda x: x), (LMC.groups.Select(filters.SYSUNRSTR), lambda x: x) | def mod_group(self, opts, args): """ Modify a group. """ include_id_lists=[ (opts.name, LMC.groups.name_to_gid), (opts.gid, LMC.groups.confirm_gid) ] exclude_id_lists = [ (opts.exclude, LMC.groups.guess_identifier), (opts.exclude_group, LMC.groups.name_to_gid), (opts.exclude_gid, LMC.groups.confirm_gid) ] if opts.all and ( ( # NOTE TO THE READER: don't event try to simplify these conditions, # or the order the tests: they just MATTER. Read the tests in pure # english to undestand them and why the order is important. opts.non_interactive and opts.force) or opts.batch \ or (opts.non_interactive and logging.ask_for_repair( 'Are you sure you want to modify all groups ?', auto_answer=opts.auto_answer) or not opts.non_interactive) ): include_id_lists.extend([ (LMC.groups.Select(filters.STD), LMC.groups.confirm_gid), (LMC.groups.Select(filters.SYSUNRSTR), LMC.groups.confirm_gid) ]) gids_to_mod = self.select(LMC.groups, 'group', args, include_id_lists=include_id_lists, exclude_id_lists=exclude_id_lists) |
Subsets and Splits