--- /dev/null
+#!/usr/bin/env perl
+#===============================================================================
+# FILE: generate-ldapbase.pl
+#
+# USAGE: ./generate-ldapbase.pl
+#
+# DESCRIPTION: Generates entries for ldap for schools (one entry per class)
+#
+# REQUIREMENTS: hosts file from ansible, containing fields nom, abbrv, mdp and
+# num for each school server
+# AUTHOR: Thomas vO (Ville de Grenoble), thomasvo@grenoble.fr
+# VERSION: 0.1
+# CREATED: 21/10/2015 11:27:34
+# REVISION: ---
+#===============================================================================
+
+use strict;
+use warnings;
+use utf8;
+use Data::Dumper;
+
+### params
+my $hostfile = '/home/thomasvo/code/ansible-ecoles/hosts';
+my $OUTDIR = '/home/thomasvo/code/ansible-ecoles/files/ldap/';
+
+###### Do not edit below this line, unless you know what you do ;) ######
+### some vars
+my $line;
+### struct school :
+#for each school -> ( name => nom, abbrv => abbrv, pwd => mdp, num => num )
+my $schools = {};
+
+### reads hostfile, and get all hosts with their parameters
+sub read_hostfile () {
+ open my $source, "<", $hostfile;
+ my ($name, $abbrv, $pwd, $num);
+ while (defined ($line = <$source>)) {
+ $line =~ m/.*?nom=(\S+).*?abbrv=(\S+)\s+mdp=(\S+)\s+num=(\d+)/;
+ ($name, $abbrv, $pwd, $num) = ($1, $2, $3, $4);
+ next if (not defined $name);
+ $schools->{"$name"} = {
+ abbrv => $abbrv,
+ pwd => $pwd,
+ num => $num,
+ };
+ }
+ close $source;
+}
+
+### for each host, creates one ldif containing 30 class logins, writing these
+### files in OUTDIR
+sub write_ldifs () {
+ foreach my $s (keys %{$schools}) {
+ open my $ldif, ">", $OUTDIR.'alim-ldap-'.$schools->{$s}->{abbrv}.'.ldif';
+ for (my $i = 1; $i <= 30; $i ++) {
+ my $login = $schools->{$s}->{abbrv}.$i;
+ my $uid = (10+$schools->{$s}->{num})*1000+$i;
+ my $gid = (10+$schools->{$s}->{num})*1000;
+ my $pwd = $schools->{$s}->{pwd}.$i;
+ printf $ldif ("dn: uid=%s,ou=utilisateurs,dc=ecole,dc=grenoble,dc=fr\n", $login);
+ printf $ldif ("objectClass: top\n");
+ printf $ldif ("objectClass: person\n");
+ printf $ldif ("objectClass: inetOrgPerson\n");
+ printf $ldif ("objectClass: posixAccount\n");
+ printf $ldif ("objectClass: shadowAccount\n");
+ printf $ldif ("uid: %s\n", $login);
+ printf $ldif ("cn: %s Classe %s\n", $s, $i);
+ printf $ldif ("sn: %s Classe %s\n", $s, $i);
+ printf $ldif ("homeDirectory: /home/%s\n", $login);
+ printf $ldif ("uidNumber: %s\n", $uid);
+ printf $ldif ("gidNumber: %s\n", $gid);
+ printf $ldif ("userPassword: %s\n", $pwd);
+ printf $ldif ("loginShell: /bin/bash\n\n");
+ }
+ close $ldif;
+ }
+}
+
+###
+read_hostfile();
+#print Dumper($schools);
+write_ldifs();
+
+### some internals
+my $version = '0.1';
+my $copyright = '2015';
+sub printversion {
+ print "This is generate-ldapbase.pl, version $version\n";
+ print "\t Copyright $copyright Thomas van Oudenhove, Ville de Grenoble\n";
+}
+
+sub printhelp {
+ printversion();
+ print "You may want to have a look at `perldoc generate-ldapbase.pl`.\n";
+}
+
+__END__
+
+=pod
+
+=head1 generate-ldapbase.pl Documentation
+
+=head2 NAME
+
+generate-ldapbase.pl -- generates ldif files
+
+=head2 SYNOPSIS
+
+generate-ldapbase.pl
+
+generate-ldapbase.pl [--version]
+
+generate-ldapbase.pl [--help]
+
+=head2 DESCRIPTION
+
+This program generates some entries in a ldif file for each school which is in a hosts file. It's strongly related to the ansible playbooks used in the project ansible-ecole (L<https://adullact.net/projects/ansible-ecole/>).
+
+You need to edit this file and fix the paths in the first lines (params).
+
+=head2 OPTIONS
+
+=over 1
+
+=item B<--version>: displays version information.
+
+=item B<--help>: displays help as a summary of options.
+
+=back
+
+=head2 BUGS
+
+None yet identified.
+
+=head2 HISTORY
+
+This program was first released in 2015. I needed it to generate many ldap entries.
+
+=head3 Changelog
+
+=over
+
+=item v0.1: first version
+
+=back
+
+=head2 AUTHORS
+
+I<generate-ldapbase.pl> is a program by Thomas van Oudenhove (L<thomasvo_AT_grenoble_DOT_fr>). Feel free to contact him for features requests or bugs.
+
+=cut
+