Revision 0d75a0b6
Added by Marc Dequènes over 15 years ago
- ID 0d75a0b69e66109ca47b906c5d44044bc48dbb88
bin/shadowwalker | ||
---|---|---|
end
|
||
cmdparser.add_command(cmd)
|
||
|
||
def display_tree(tree, level)
|
||
tree.keys.sort.each do |key|
|
||
str = ""
|
||
str += " " + "| " * (level -1) + "+-- " if level > 0
|
||
str += "<#{key}>"
|
||
puts str
|
||
|
||
display_tree(tree[key], level + 1) if tree[key]
|
||
end
|
||
end
|
||
|
||
cmd = CmdParse::Command.new('tree', false)
|
||
cmd.short_desc = "show skeleton objects tree"
|
||
cmd.set_execution_block do |args|
|
||
puts "Tree:"
|
||
|
||
base_dn = ActiveLdap::DistinguishedName.parse(LdapShadows::LdapObject.base)
|
||
|
||
gconfig = ldapctl.get_global_config()
|
||
if gconfig.has_key?(:tree_objects)
|
||
tree = {}
|
||
|
||
gconfig[:tree_objects].each do |obj_hdl|
|
||
obj_klass = ldapctl.find_klass(obj_hdl)
|
||
raise "object '#{obj_hdl}' not defined" unless obj_klass
|
||
|
||
obj_klass.find(:all).each do |obj|
|
||
ptree = tree
|
||
pdn = nil
|
||
(obj.dn_obj - base_dn).to_s.split(',').reverse.each do |pdn|
|
||
ptree[pdn] = {} unless ptree.has_key?(pdn)
|
||
ptree = ptree[pdn]
|
||
end
|
||
ptree = nil
|
||
end
|
||
end
|
||
tree = {base_dn => tree}
|
||
|
||
display_tree(tree, 0)
|
||
end
|
||
end
|
||
cmdparser.add_command(cmd)
|
||
|
||
cmdparser.parse
|
||
|
conf/ldap_shadows/test.conf | ||
---|---|---|
---
|
||
presentation:
|
||
hidden_attributes: ['objectClass', 'userPassword']
|
||
tree_objects: ['ou', 'entity']
|
||
objects:
|
||
bot:
|
||
mapping:
|
||
... | ... | |
object: entity
|
||
foreign_key: founder
|
||
primary_key: dn
|
||
ou:
|
||
mapping:
|
||
dn_attribute: ou
|
||
prefix: ''
|
||
classes: ['organizationalUnit']
|
||
# no sort_by means sort by DN
|
||
presentation:
|
||
name_attribute: dn
|
||
aspects:
|
||
mail:
|
||
mapping:
|
lib/ldap_shadows/object.rb | ||
---|---|---|
|
||
def human_name
|
||
[self.class.presentation[:name_attribute], 'displayName', 'cn'].each do |attr|
|
||
if self.has_attribute?(attr) and self.attribute_present?(attr)
|
||
name = self[attr].is_a?(Array) ? self[attr][0] : self[attr]
|
||
if attr == 'dn' or (self.has_attribute?(attr) and self.attribute_present?(attr))
|
||
val = self.send(attr)
|
||
name = val.is_a?(Array) ? val[0] : val
|
||
return name.strip
|
||
end
|
||
end
|
Also available in: Unified diff
[evol] added tree view