You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.8 KiB
96 lines
2.8 KiB
13 years ago
|
#!/usr/bin/perl -w
|
||
|
|
||
|
package esmith;
|
||
|
|
||
|
use strict;
|
||
|
use Errno;
|
||
|
use esmith::ConfigDB;
|
||
|
use esmith::AccountsDB;
|
||
|
use esmith::util;
|
||
|
use Net::LDAP;
|
||
|
use File::Temp;
|
||
|
|
||
|
my $c = esmith::ConfigDB->open_ro;
|
||
|
my $a = esmith::AccountsDB->open_ro;
|
||
|
|
||
|
my $ldapauth = $c->get('ldap')->prop('Authentication') || 'disabled';
|
||
|
my $x = 0; # exit value
|
||
|
|
||
|
my $l = $c->get('ldap');
|
||
|
my $status = $l->prop('status') || "disabled";
|
||
|
unless ($status eq "enabled" )
|
||
|
{
|
||
|
warn "Not running action script $0, LDAP service not enabled!\n";
|
||
|
exit(0);
|
||
|
}
|
||
|
|
||
|
my $domain = $c->get('DomainName')
|
||
|
|| die("Couldn't determine domain name");
|
||
|
$domain = $domain->value;
|
||
|
|
||
|
my @accounts;
|
||
|
my $account;
|
||
|
my $event = shift || die "Event name is missing\n";
|
||
|
if ($event eq 'ldap-update' or
|
||
|
$event eq 'bootstrap-ldap-save')
|
||
|
{
|
||
|
@accounts = ($a->users);
|
||
|
push(@accounts, $a->get('admin'));
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
my @name = @ARGV;
|
||
|
die "Account name argument missing." unless scalar (@name) >= 1;
|
||
|
|
||
|
foreach my $name (@name)
|
||
|
{
|
||
|
$account = $a->get($name);
|
||
|
die "Account $name not found.\n" unless defined $account;
|
||
|
|
||
|
push @accounts, $account;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
foreach my $acc (@accounts){
|
||
|
my $user = $acc->key;
|
||
|
my $postalcode = $acc->prop('PostalCode') || '';
|
||
|
my $mobile = $acc->prop('Mobile') || '';
|
||
|
my $extension = $acc->prop('Extension') || '';
|
||
|
my $fax = $acc->prop('Fax') || '';
|
||
|
my $function1 = $acc->prop('Function1') || '';
|
||
|
my $function2 = $acc->prop('Function2') || '';
|
||
|
my $function3 = $acc->prop('Function3') || '';
|
||
|
my $function4 = $acc->prop('Function4') || '';
|
||
|
my $initials = $acc->prop('Initials') || '';
|
||
|
my $dshell = $acc->prop('DesktopShell') || '';
|
||
|
my $preferredemail = $acc->prop('PreferredEmail') || '';
|
||
|
$preferredemail = "$user\@$domain" if ($preferredemail eq '');
|
||
|
|
||
|
my $tmpattr = File::Temp->new();
|
||
|
print $tmpattr "postalCode: $postalcode\n";
|
||
|
print $tmpattr "mobile: $mobile\n";
|
||
|
print $tmpattr "extensionNumber: $extension\n";
|
||
|
print $tmpattr "facsimileTelephoneNumber: $fax\n";
|
||
|
print $tmpattr "title: $function1\n" if ($function1 ne '');
|
||
|
print $tmpattr "title: $function2\n" if ($function2 ne '');
|
||
|
print $tmpattr "title: $function3\n" if ($function3 ne '');
|
||
|
print $tmpattr "title: $function4\n" if ($function4 ne '');
|
||
|
# remove the emplyeeType attr if all 4 functions are empty
|
||
|
if ($function1 eq '' &&
|
||
|
$function2 eq '' &&
|
||
|
$function3 eq '' &&
|
||
|
$function4 eq ''){
|
||
|
print $tmpattr "title: \n";
|
||
|
}
|
||
|
print $tmpattr "initials: $initials\n";
|
||
|
print $tmpattr "desktopLoginShell: $dshell\n";
|
||
|
print $tmpattr "preferredMail: $preferredemail\n";
|
||
|
$tmpattr->flush();
|
||
|
|
||
|
system("/usr/sbin/cpu", "usermod", "-a", "$tmpattr", $user) == 0
|
||
|
or ( $x = $ldapauth ne 'enabled' ? $x : 255, warn "Failed to modify ldap informations for account $user.\n" );
|
||
|
undef $tmpattr;
|
||
|
}
|
||
|
|
||
|
exit ($x);
|