diff options
author | Thierry Vignaud <tvignaud@mandriva.org> | 2004-07-27 10:41:44 +0000 |
---|---|---|
committer | Thierry Vignaud <tvignaud@mandriva.org> | 2004-07-27 10:41:44 +0000 |
commit | ef48e65e3a273a38f27c10eeac92d76eb12ddfdf (patch) | |
tree | fe784ae2811a1c1ceb0c8f0c310ad1d8712639e2 | |
parent | 61ab0df24705d679a32d2f738c59d2e85d7ab437 (diff) | |
download | drakwizard-ef48e65e3a273a38f27c10eeac92d76eb12ddfdf.tar drakwizard-ef48e65e3a273a38f27c10eeac92d76eb12ddfdf.tar.gz drakwizard-ef48e65e3a273a38f27c10eeac92d76eb12ddfdf.tar.bz2 drakwizard-ef48e65e3a273a38f27c10eeac92d76eb12ddfdf.tar.xz drakwizard-ef48e65e3a273a38f27c10eeac92d76eb12ddfdf.zip |
indent
-rw-r--r-- | ldap_wizard/ldap.pm | 377 |
1 files changed, 195 insertions, 182 deletions
diff --git a/ldap_wizard/ldap.pm b/ldap_wizard/ldap.pm index 624124db..57d5b052 100644 --- a/ldap_wizard/ldap.pm +++ b/ldap_wizard/ldap.pm @@ -22,35 +22,35 @@ require Net::LDAP; my $o = { -name => N("Add POSIX account"), - var => { - defou => 'ou=Users', - srv => '', - dom => 'mandrakesoft.com', - suffix => '', - rootdn => '', - rootpass => '', - rootpass2 => '', - cn => '', - sn => '', - uid => '', - uidpass => '', - lshell => '/bin/bash', - home => '/home/', - uidnb => '1004', - gidnb => '1004', - container => 'container', - objectclass => 'top,account,posixaccount', - shadowmax => '99999', - shadowmin => '-1', - plop => '', - tmp => '', - nom => '', - prenom => '', - }, - needed_rpm => [ 'squid' ], - defaultimage => "/usr/share/wizards/proxy_wizard/images/proxy.png" -}; + name => N("Add POSIX account"), + var => { + defou => 'ou=Users', + srv => '', + dom => 'mandrakesoft.com', + suffix => '', + rootdn => '', + rootpass => '', + rootpass2 => '', + cn => '', + sn => '', + uid => '', + uidpass => '', + lshell => '/bin/bash', + home => '/home/', + uidnb => '1004', + gidnb => '1004', + container => 'container', + objectclass => 'top,account,posixaccount', + shadowmax => '99999', + shadowmin => '-1', + plop => '', + tmp => '', + nom => '', + prenom => '', + }, + needed_rpm => [ 'squid' ], + defaultimage => "/usr/share/wizards/proxy_wizard/images/proxy.png" + }; @@ -64,186 +64,199 @@ my $LDAPCONF = "/etc/openldap/slapd.conf"; my $hostname = `hostname`; $o->{var}{srv} = $hostname; - if (-f $conf_file) { +if (-f $conf_file) { - my %conf = getVarsFromSh($conf_file); - $o->{var}{suffix} = $conf{suffix}; - $o->{var}{rootdn} = $conf{rootdn}; - $o->{var}{rootpass} = $conf{rootpass}; - $o->{var}{srv} = $conf{srv}; - $o->{var}{defou} = $conf{users}; + my %conf = getVarsFromSh($conf_file); + $o->{var}{suffix} = $conf{suffix}; + $o->{var}{rootdn} = $conf{rootdn}; + $o->{var}{rootpass} = $conf{rootpass}; + $o->{var}{srv} = $conf{srv}; + $o->{var}{defou} = $conf{users}; } else { - my $hostname = `hostname`; - $o->{var}{srv} = $hostname; - $o->{var}{suffix} = $ldap_suffix; + my $hostname = `hostname`; + $o->{var}{srv} = $hostname; + $o->{var}{suffix} = $ldap_suffix; } my %level = ( - 1 => N("Server - Set configuration of LDAP server"), - 2 => N("Add - Add user in LDAP server"), - ); + 1 => N("Server - Set configuration of LDAP server"), + 2 => N("Add - Add user 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_userposix'; - } - }, - data => [ - { - label => N("Your choice:") . "\n\n", val => \$o->{var}{wiz_level}, type => 'list', list => [ keys %level ], format => sub { $level{$_[0]} } }, - ], - next => 'set_srv', - }, - add_userposix => { - name => N("LDAP User Add") . "\n\n" . N("User Create in : ") . $o->{var}{defou} . "," . $o->{var}{suffix}, - data => [ - { label => N("First Name:"), val => \$o->{var}{sn} }, - { label => N("Name:"), val => \$o->{var}{cn} }, - { label => N("User Name:"), val => \$o->{var}{uid} }, - ], - next => 'password' - }, - password => { - name => N("LDAP User Password") . "\n\n" . N("Password for Users : ") . $o->{var}{cn} . $o->{var}{defou} . "," . $o->{var}{suffix}, - data => [ - { label => N("Password:):"), val => \$o->{var}{uidpass}, hidden => 1 }, - { label => N("Password (again):"), val => \$o->{var}{uidpass2}, hidden => 1 }, - ], - complete => sub { - if (!$o->{var}{uidpass}) - { - $::in->ask_warn(N("Error"), N("You must enter a password for LDAP.")); - return 1; - } - if (!($o->{var}{uidpass} eq $o->{var}{uidpass2})) - { - $::in->ask_warn(N("Error"), N("The passwords do not match")); - return 1; - } - }, + 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("Your choice:") . "\n\n", val => \$o->{var}{wiz_level}, type => 'list', list => [ keys %level ], format => sub { $level{$_[0]} } }, + ], + next => 'set_srv', + }, + add_userposix => { + name => N("LDAP User Add") . "\n\n" . N("User Create in : ") . $o->{var}{defou} . "," . $o->{var}{suffix}, + data => [ + { + label => N("First Name:"), val => \$o->{var}{sn} }, + { + label => N("Name:"), val => \$o->{var}{cn} }, + { + label => N("User Name:"), val => \$o->{var}{uid} }, + ], + next => 'password' + }, + password => { + name => N("LDAP User Password") . "\n\n" . N("Password for Users : ") . $o->{var}{cn} . $o->{var}{defou} . "," . $o->{var}{suffix}, + data => [ + { + label => N("Password:):"), val => \$o->{var}{uidpass}, hidden => 1 }, + { + label => N("Password (again):"), val => \$o->{var}{uidpass2}, hidden => 1 }, + ], + complete => sub { + if (!$o->{var}{uidpass}) { + $::in->ask_warn(N("Error"), N("You must enter a password for LDAP.")); + return 1; + } + if (!($o->{var}{uidpass} eq $o->{var}{uidpass2})) { + $::in->ask_warn(N("Error"), N("The passwords do not match")); + return 1; + } + }, - next => 'summary_add_user' - }, - - set_srv => { - name => N("Configuring LDAP"), - data => [ - { label => N("LDAP Suffix:"), val => \$o->{var}{suffix} }, - { label => N("LDAP Administrator:"), val => \$o->{var}{rootdn} }, - { label => N("LDAP Password:"), hidden => 1, val => \$o->{var}{rootpass} }, - { label => N("LDAP Password (again):"), hidden => 1, val => \$o->{var}{rootpass2} }, - ], - complete => sub { - if (!$o->{var}{suffix}) - { - $::in->ask_warn(N("Error"), N("You must enter a suffix for LDAP.")); - return 1; - } - if (!$o->{var}{rootpass}) - { - $::in->ask_warn(N("Error"), N("You must enter a password for LDAP.")); - return 1; - } - if (!($o->{var}{rootpass} eq $o->{var}{rootpass2})) - { - $::in->ask_warn(N("Error"), N("The passwords do not match")); - return 1; - } - }, - next => 'summary_set_srv', - - }, - summary_add_user => { - name => N("Confirmation de l'utilisateur a creer"), - data => [ - { label => N("Name:"), type => 'field', fixed_val => \$o->{var}{sn} }, - { label => N("Firt name:"), type => 'field', fixed_val => \$o->{var}{cn} }, - { label => N("User Name:"), type => 'field', fixed_val => \$o->{var}{uid} }, - { label => N("User:"), type => 'field', fixed_val => $o->{var}{cn} }, - ], - post => \&do_it_user_add, - next => 'endadd' - }, - summary_set_srv => { - name => N("Confirmation de l'utilisateur a creer"), - data => [ - { label => N("LDAP Suffix:"), type => 'field', val => $o->{var}{suffix} }, - ], - post => \&do_it_setldap, - next => 'end' - }, - end => { - name => N("Congratulations"), - data => [ { label => N("The wizard successfully configured the LDAP.") } ], - no_back => 1, - end => 1, - next => 0 - }, - endadd => { - name => N("Successfully added User"), - data => [ { label => N("The wizard successfully added an user in LDAP") } ], - no_back => 1, - end => 1, - next => 0, - }, - }; + next => 'summary_add_user' + }, + + set_srv => { + name => N("Configuring LDAP"), + data => [ + { + label => N("LDAP Suffix:"), val => \$o->{var}{suffix} }, + { + label => N("LDAP Administrator:"), val => \$o->{var}{rootdn} }, + { + label => N("LDAP Password:"), hidden => 1, val => \$o->{var}{rootpass} }, + { + label => N("LDAP Password (again):"), hidden => 1, val => \$o->{var}{rootpass2} }, + ], + complete => sub { + if (!$o->{var}{suffix}) { + $::in->ask_warn(N("Error"), N("You must enter a suffix for LDAP.")); + return 1; + } + if (!$o->{var}{rootpass}) { + $::in->ask_warn(N("Error"), N("You must enter a password for LDAP.")); + return 1; + } + if (!($o->{var}{rootpass} eq $o->{var}{rootpass2})) { + $::in->ask_warn(N("Error"), N("The passwords do not match")); + return 1; + } + }, + next => 'summary_set_srv', + + }, + summary_add_user => { + name => N("Confirmation de l'utilisateur a creer"), + data => [ + { + label => N("Name:"), type => 'field', fixed_val => \$o->{var}{sn} }, + { + label => N("Firt name:"), type => 'field', fixed_val => \$o->{var}{cn} }, + { + label => N("User Name:"), type => 'field', fixed_val => \$o->{var}{uid} }, + { + label => N("User:"), type => 'field', fixed_val => $o->{var}{cn} }, + ], + post => \&do_it_user_add, + next => 'endadd' + }, + summary_set_srv => { + name => N("Confirmation de l'utilisateur a creer"), + data => [ + { + label => N("LDAP Suffix:"), type => 'field', val => $o->{var}{suffix} }, + ], + post => \&do_it_setldap, + next => 'end' + }, + end => { + name => N("Congratulations"), + data => [ { label => N("The wizard successfully configured the LDAP.") } ], + no_back => 1, + end => 1, + next => 0 + }, + endadd => { + name => N("Successfully added User"), + data => [ { label => N("The wizard successfully added an user in LDAP") } ], + no_back => 1, + end => 1, + next => 0, + }, + }; sub do_it_setldap { - if (!-f $LDAPCONF) { die "no $LDAPCONF found" }; + if (!-f $LDAPCONF) { + die "no $LDAPCONF found"; + } cp_af($LDAPCONF, $LDAPCONF . '.save'); - if (!-f "$LDAPCONF.example") { cp_af($LDAPCONF, $LDAPCONF . '.example') }; + if (!-f "$LDAPCONF.example") { + cp_af($LDAPCONF, $LDAPCONF . '.example'); + } cp_af($LDAPCONF . '.example', $LDAPCONF); print "$o->{var}{suffix}\n"; -# set suffix + # set suffix if (any { /^suffix/ } cat_($LDAPCONF)) { - substInFile { - s/suffix.*/suffix\t"$o->{var}{suffix}"/; - } $LDAPCONF; + substInFile { + s/suffix.*/suffix\t"$o->{var}{suffix}"/; + } $LDAPCONF; } else { - append_to_file($LDAPCONF, qq(suffix\t"$o->{var}{suffix}")); + append_to_file($LDAPCONF, qq(suffix\t"$o->{var}{suffix}")); } -# s/example/$dcall + # s/example/$dcall substInFile { - s/example/$o->{var}{suffix}/g; + s/example/$o->{var}{suffix}/g; } $LDAPCONF; -# set rootdn + # set rootdn if (any { /^rootdn/ } cat_($LDAPCONF)) { - substInFile { - s/rootdn.*/rootdn\t"cn=$o->{var}{rootdn},$o->{var}{suffix}"/; - } $LDAPCONF; + substInFile { + s/rootdn.*/rootdn\t"cn=$o->{var}{rootdn},$o->{var}{suffix}"/; + } $LDAPCONF; } else { - append_to_file($LDAPCONF, qq(rootdn\t"$o->{var}{rootdn},$o->{var}{suffix}")); + append_to_file($LDAPCONF, qq(rootdn\t"$o->{var}{rootdn},$o->{var}{suffix}")); } -# set rootpass + # set rootpass my $cryptpass = crypt($o->{var}{rootpass}, "crypt"); if (any { /^rootpw/ } cat_($LDAPCONF)) { - substInFile { - #s/rootpw.*/rootpw $cryptpass/; - s/rootpw.*/rootpw $o->{var}{rootpass}/; - } $LDAPCONF; + substInFile { + #s/rootpw.*/rootpw $cryptpass/; + s/rootpw.*/rootpw $o->{var}{rootpass}/; + } $LDAPCONF; } else { - #append_to_file($LDAPCONF, "rootpw {CRYPT}$cryptpass"); - append_to_file($LDAPCONF, "rootpw $o->{var}{rootpass}"); + #append_to_file($LDAPCONF, "rootpw {CRYPT}$cryptpass"); + append_to_file($LDAPCONF, "rootpw $o->{var}{rootpass}"); } -# create config file in /etc/sysconfig/ldapconf + # create config file in /etc/sysconfig/ldapconf -output($conf_file, <<EOF); + output($conf_file, <<EOF); server=$o->{var}{srv} suffix=$o->{var}{suffix} rootdn=$o->{var}{rootdn} @@ -252,16 +265,16 @@ rootpass=$o->{var}{rootpass} users=$o->{var}{defou} EOF -# reset premisions + # reset premisions system("chown -R root.ldap /etc/openldap"); system("service ldap restart"); - init_ldap(); + init_ldap(); } sub init_ldap { -my $root_cn = (split('=', (split(/,/, $o->{var}{rootdn}))[0]))[1]; -my $ldap_dc = (split('=', (split(/,/, $o->{var}{suffix}))[0]))[1]; + my $root_cn = (split('=', (split(/,/, $o->{var}{rootdn}))[0]))[1]; + my $ldap_dc = (split('=', (split(/,/, $o->{var}{suffix}))[0]))[1]; my $LDAP; open($LDAP, "| ldapadd -x -D 'cn=$o->{var}{rootdn},$o->{var}{suffix}' -w $o->{var}{rootpass}"); @@ -306,15 +319,15 @@ RootLdif sub do_it_user_add { return if $::testing; - my $ldap = ldap_connect($o); - add_user($o); + my $ldap = ldap_connect($o); + add_user($o); } sub new { my ($class) = @_; bless { - o => $o, - }, $class; + o => $o, + }, $class; } 1; |