#!/usr/bin/perl -w # version 0.1 # GPL like # aginies@mandrakesoft.com package MDK::Wizard::ldap; use lib qw(/usr/lib/libDrakX); use ugtk2; use strict; use fcldap; use common; use standalone; use MDK::Wizard::Varspaceval; use MDK::Wizard::Wizcommon; use Expect; require Net::LDAP; #unless ($> == 0) { # die "You are not root Exiting\n"; #} my $DC = get_dc(); my $wiz = new MDK::Wizard::Wizcommon; my $LDAPCONF = "/etc/openldap/slapd.conf"; my $HOME = "/home/"; my $IP = "192.168.100.169"; my $o = { name => 'LDAP Configuration Wizard', var => { defou => 'People', dom => 'toto.com', rootdse => 'toto.com', rootdn => 'manager', rootpass => 'secret', cn => '', sn=> '', uid => '', uidpass => '', lshell => '/bin/bash', home => '/home/', uidnb => '', guinb => '', container => '', objectclass => 'top,account,posixaccount', shadowmax => '99999', shadowmin => '-1', shadowina => '-1', shadowina => '-1', }, needed_rpm => [ 'openldap-servers', 'openldap-clients' ], defaultimage => "/usr/share/wizards/dns_wizard/images/DNS.png" }; use Data::Dumper; print Dumper($o->{var}); my %level = ( 1 => N("Server - Set configuration of LDAP server"), 2 => N("Add - add entry in LDAP server"), ); my $cn; $o->{pages} = { welcome => { name => N("LDAP configuration wizard") . "\n\n" . N("Setup a ldap server."), no_back => 1, pre => sub { $o->{var}{wiz_level} ||= 1; }, post => sub { if ($o->{var}{wiz_level} == 2) { return 'add_userposix'; } }, data => [ { label => N("which operation on LDAP:"), val => \$o->{var}{wiz_level}, list => [ keys %level ], format => sub { $level{$_[0]} } }, ], next => 'setldap', }, add_userposix => { name => N("Add data in LDAP") . "\n\n" . N("uid, guid, home directory, "), data => [ { label => N("First Name:"), val => \$o->{var}{cn} }, { label => N("Last Name:"), val => \$o->{var}{sn} }, { label => N("User Name:"), val => \$o->{var}{uid} }, { label => N("Password:"), val => \$o->{var}{uidpass} }, { label => N("Home Directory:"), val => \$o->{var}{home} }, { label => N("Login shell:"), val => \$o->{var}{lshell} }, { label => N("uid number:"), val => \$o->{var}{uidnb} }, { label => N("Group ID:"), val => \$o->{var}{guidnb} }, ], post => \&test_add, next => 'summaryadd', }, setldap => { name => N("LDAP RootDSE example: obelx.nux.com will be in ldap config: dc=obelx,dc=nux,dc=com RootDN is the manager of your ldap server."), data => [ { label => N("RootDSE"), val => \$o->{var}{rootdse} }, { label => N("RootDN"), val => \$o->{var}{rootdn} }, { label => N("Password"), val => \$o->{var}{rootpass} }, { label => N("Default OU"), val => \$o->{var}{defou} }, ], post => \&test_set, next => 'summaryset', }, summaryadd => { name => N("Ok Now add entry in LDAP"), data => [ { label => N("First Name:"), fixed_val => \$o->{var}{cn2} }, { label => N("Last Name:"), fixed_val => \$o->{var}{sn2} }, { label => N("User Name:"), fixed_val => \$o->{var}{uid2} }, { label => N("Password:"), fixed_val => \$o->{var}{uidpass} }, { label => N("Home directory:"), fixed_val => \$o->{var}{home} }, { label => N("Login shell:"), fixed_val => \$o->{var}{lshell} }, { label => N("uid number:"), fixed_val => \$o->{var}{uidnb} }, { label => N("Group ID:"), fixed_val => \$o->{var}{guidnb} }, { label => N("Container:"), fixed_val => \$o->{var}{container} }, { label => N("shadowMax:"), fixed_val => \$o->{var}{shadowmax} }, { label => N("shadowMin:"), fixed_val => \$o->{var}{shadowmin} }, { label => N("shadowWarning:"), fixed_val => \$o->{var}{shadowina} }, { label => N("shadowInactive:"), fixed_val => \$o->{var}{shadowina} }, { label => N("shadowExpire:"), fixed_val => \$o->{var}{shadowexpire} }, { label => N("objectClass:"), fixed_val => \$o->{var}{objectclass} }, ], post => \&do_it_add, next => 'endadd', }, summaryset => { name => N("Ok Now building your LDAP configuration") . "\n\n" . N("with this configuration:"), data => [ { label => N("RootDSE"), fixed_val => \$o->{var}{rootdse} }, { label => N("RootDN"), fixed_val => \$o->{var}{rootdn} }, ], post => \&do_it_setldap, next => 'end' }, error_homedir => { name => N("Error in Home directory"), next => 'add_userposix', }, error_pass => { name => N("Error, pass could not be empty"), next => 'setldap', }, error_shell => { name => N("Error in Login shell") . "\n\n" . N("Please choose a correct one"), next => 'add_userposix', }, error_nb => { name => N("Error") . "\n\n" . N("Please Should be a number"), next => 'add_userposix', }, end => { name => N("Congratulations"), data => [ { label => N("The wizard successfully configured the LDAP.") } ], no_back => 1, end => 1, next => 0 }, endadd => { name => N("Successfully add data"), data => [ { label => N("The wizard successfully add entry in ldap") } ], no_back => 1, end => 1, next => 0, }, }; sub rootdse_to_dc { my ($data) = @_; my @t = split(/\./, $data); $o->{var}{dom} = $t[0]; my $dcall = join( ',dc=', split(/\./, $data)); return $dcall; } sub test_set { $o->{var}{rootpass} or return 'error_pass'; } sub get_dc { my $DC = "dc=test,dc=com"; return $DC; } sub do_it_setldap { if (!-f $LDAPCONF) { die "no $LDAPCONF found"}; cp_af($LDAPCONF, $LDAPCONF . '.save'); if (!-f "$LDAPCONF.example") { cp_af($LDAPCONF, $LDAPCONF . '.example') }; cp_af($LDAPCONF . '.example', $LDAPCONF); my $dcall = rootdse_to_dc($o->{var}{rootdse}); print "$dcall\n"; # set suffix if (any { /^suffix/ } cat_($LDAPCONF)) { substInFile { s/suffix.*/suffix\t\"dc=$dcall\"/; } $LDAPCONF; } else { append_to_file($LDAPCONF, "suffix\t\"dc=$dcall\""); } # s/example/$dcall substInFile { s/example/dc=$dcall/g; } $LDAPCONF; # set rootdn if (any { /^rootdn/ } cat_($LDAPCONF)) { substInFile { s/rootdn.*/rootdn\t\"cn=$o->{var}{rootdn},dc=$dcall\"/; } $LDAPCONF; } else { append_to_file($LDAPCONF, "rootdn\t\"$o->{var}{rootdn},dc=$dcall\""); } # set rootpass my $cryptpass = crypt($o->{var}{rootpass}, "crypt"); if (any { /^rootpw/ } cat_($LDAPCONF)) { substInFile { s/rootpw.*/rootpw $cryptpass/; } $LDAPCONF; }else { append_to_file($LDAPCONF, "rootpw {CRYPT}$cryptpass"); } # reset premisions system("chown -R root.ldap /etc/openldap"); system("service ldap restart"); $o->{var}{rootdse} = "dc=$dcall"; create_rootdse($o); } sub test_add { # -d $o->{var}{HOME} . "/" . $o->{var}{uid} or return 'error_homedir'; $o->{var}{uidnb} =~ /\d*/ or return 'error_nb'; $o->{var}{Guidnb} =~ /\d*/ or return 'error_nb'; -f $o->{var}{lshell} or return 'error_shell'; } sub do_it_add { return if $::testing; my $dcall = rootdse_to_dc($o->{var}{rootdse}); $o->{var}{rootdse} = "dc=$dcall"; $o->{var}{rootpass} = "secret"; add_user_posix($o); } sub new { my ($class, $conf) = @_; bless { o => $o, }, $class; } 1;