diff options
author | Vicent Guardiola <vguardiola@mandriva.com> | 2004-01-20 15:35:54 +0000 |
---|---|---|
committer | Vicent Guardiola <vguardiola@mandriva.com> | 2004-01-20 15:35:54 +0000 |
commit | 2c420e97e1ffc3047e294f5185168cb8d9d39b66 (patch) | |
tree | 85097c1434a19731e17a0a48fffee0d6e65f2357 /ldap_wizard | |
parent | 0cefc424e999ccc5432b36ada1c6afd28d65fe70 (diff) | |
download | drakwizard-2c420e97e1ffc3047e294f5185168cb8d9d39b66.tar drakwizard-2c420e97e1ffc3047e294f5185168cb8d9d39b66.tar.gz drakwizard-2c420e97e1ffc3047e294f5185168cb8d9d39b66.tar.bz2 drakwizard-2c420e97e1ffc3047e294f5185168cb8d9d39b66.tar.xz drakwizard-2c420e97e1ffc3047e294f5185168cb8d9d39b66.zip |
Wizard LDAP
Diffstat (limited to 'ldap_wizard')
-rw-r--r-- | ldap_wizard/ldap.pm | 277 |
1 files changed, 277 insertions, 0 deletions
diff --git a/ldap_wizard/ldap.pm b/ldap_wizard/ldap.pm new file mode 100644 index 00000000..7c4c9ce6 --- /dev/null +++ b/ldap_wizard/ldap.pm @@ -0,0 +1,277 @@ +#!/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; +use 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', + uidnb => '', + guinb => '', + container => 'ou=users,dc=people.', + 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" + }; + +my %level = ( + 1 => N("Server - Set configuration of Ldap server"), + 2 => N("Add - add entry in Ldap server"), + ); + +$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_user_posix'; + } + }, + data => [ + { + label => N("wich operation on LDAP:"), val => \$o->{var}{wiz_level}, list => [ keys %level ], format => sub { $level{$_[0]} } }, + ], + next => 'setldap', + }, + add_user_posix => { + 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("Login shell:"), val => \$o->{var}{lshell} }, + { + label => N("uid number:"), val => \$o->{var}{uidnb} }, + { + label => N("Group ID:"), val => \$o->{var}{Guidnb} }, + { + label => N("Container:"), val => $o->{var}{container} . $DC }, + ], + post => \&test_add, + next => 'summaryadd', + }, + setldap => { + name => N('Ldap RootDSE') . "\n\n" . N('example:') . "\n" . N('obelx.nux.com') . "\n\n" . N('will be in ldap config:') . "\n" . N('dc=obelx,dc=nux,dc=com') . "\n\n" . N('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}{cn} }, + { + label => N("Last Name:"), fixed_val => \$o->{var}{sn} }, + { + label => N("User Name:"), fixed_val => \$o->{var}{uid} }, + { + label => N("Password:"), fixed_val => \$o->{var}{uidpass} }, + { + label => N("Home directory:"), fixed_val => \$o->{var}{uid} }, + { + label => N("Login shell:"), 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_user_posix', + }, + 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_user_posix', + }, + error_nb => { + name => N('Error') . "\n\n" . N('Please Should be a number'), + next => 'add_user_posix', + }, + 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 { + 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; |