Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New script: LDAP DIT #30

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions ldap-dit.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#! /usr/pkg/bin/perl

#====================================================================
# Script to convert CSV or LDIF into LDIF
#
# Copyright (C) Marc Baudoin
# Copyright (C) LTB-project.org
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# GPL License: http://www.gnu.org/licenses/gpl.txt
#
#====================================================================

use strict;
use warnings;

use Tree::Simple;

my $directory = undef;
my $apex = undef;

while (<>) {
if ( my ($dn) = /^dn: (.+)$/ ) {
if ( not defined($directory) ) {
$directory->{$dn} = Tree::Simple->new($dn);
$apex = $dn;
}
else {
my ( $first, $next ) = $dn =~ /^([^,]+),(.+)$/;
$directory->{$dn} = Tree::Simple->new( $dn, $directory->{$next} );
}
}
}

my $depth = -1;
my @aff_vert = ();

print "$apex\n";

$directory->{$apex}->traverse(
sub {
my ($element) = @_;
my $tag = $element->getNodeValue();
$depth = $element->getDepth();
if ( $depth != 0 ) {
foreach my $p ( 0 .. $depth - 1 ) {
if ( $aff_vert[$p] ) {
print '| ';
}
else {
print ' ';
}
}
}
print '+-- ' . $tag . "($depth)" . "\n";

if ( not $element->isLeaf() ) {
$aff_vert[$depth] = 1 if $element->isFirstChild();
$aff_vert[$depth] = 0 if $element->isLastChild();
}
}
);