#!/usr/bin/perl -w # Quick script to draw an org chart from LDAP using the "manager" attribute # Copyright (c) 2010 Bitcube Ltd. Written by Adrian Bridgett my $version = "1.0"; use strict; use Getopt::Std; sub usage() { print < (title, manager) getopts("hlp",\%options); usage() if defined ($options{h}); parse_file(\%person); print_graph(\%person, defined($options{l})); } sub parse_file($) { my ($person) = (@_); my $dn; while (<>) { /^dn: uid=([^,]*)/ && do { $dn = $1 }; /^manager: uid=([^,]*)/ && do { $$person{$dn}{manager} = $1 }; /^(title|cn): (.*)/ && do { $$person{$dn}{$1} = $2 }; /^memberOf: cn=(.*),o=Example/ && do { $$person{$dn}{group} = $1 }; } } sub print_graph($$) { my ($person,$landscape) = @_; my ($rankdir,$lq,$rq) = $landscape ? ("BT","{","}") : ("RL","",""); print < \"$d{manager}\";\n"; } } print "}\n"; } main;