#sample custom addons #$allowchghost=1; sub postprint { print "Activation:Activate? De-activate? "; } sub postchange { #can test for a custom attribute and perform action my ($cn,$rest)=split(',',param('dn')); $cn=~/^cn=(.*?) +(.*?)( +|\(|$)/i; my $first=$1; my $last=$2; return if (!$mailhost || !param('activate')); &activate_aliases($first,$last,param('ldapuid'),param('activate'),$mailhost); } sub postcreate { my ($cn,$rest)=split(',',param('dn')); $cn=~/^cn=(.*?) +(.*?)( +|\(|$)/i; my $first=$1; my $last=$2; return if (!$mailhost || !param('activate')); &activate_aliases($first,$last,param('ldapuid'),param('activate'),$mailhost); } sub postdelete { my ($cn,$rest)=split(',',param('dn')); $cn=~/^cn=(.*?) +(.*?)( +|\(|$)/i; my $first=$1; my $last=$2; return if (!$mailhost); &activate_aliases($first,$last,param('ldapuid'),'deactivate',$mailhost); } #this function simply creates aliases for each uid in the format of # first_last@domain and first.last@domain for legacy mail address support # and returns the array for addition into ldap sub postaddmulti { my ($att,@multivals)=@_; if ($att eq 'alternatemailaddress') { my $first=param('givenname'); my $last=param('sn'); my $uid=param('ldapuid'); push(@multivals,$first.".".$last."\@".$maildomain); push(@multivals,$first."_".$last."\@".$maildomain); } return @multivals; } #this function allows attributes to be preset when creating a new user account #this only affects attributes in @ldappersonatts sub postaddentry { my ($att,$value)=@_; my $maildropatt="maildrop"; #set maildrop to a default value if we have a mailhost if ($att eq $maildropatt) { my $mailhost=param($mailhostatt) if (defined param($mailhostatt)); my $maildrop=param('ldapuid')."\@".$mailhost if $mailhost; $value= $maildrop if ($maildropatt && $maildrop && !$value); } return $value; } sub activate_aliases { my ($first,$last,$uid,$mode,$server)=@_; if (!$first && !$last) {return;} if (!$mode || !$uid || !$server ) { return;} if ($mode=~/deactivate/i) { $mode='delete'; } else { $mode='add'; } $last=~s/'//g; $first=~s/ +/_/g; $last=~s/ +/_/g; $uid=~s/ +//g; my $result=`/etc/ldap/doimap '$first' '$last' '$uid' $mode $server`; print "Activate Results: $result
"; } sub modify_aliases { my ($uid,@aliases,$server,%ldapmod)=@_; if (!$uid || !$server) {return;} my $result=`/etc/ldap/doaliases \'blank\' \'$uid\@$server\' delete`; while (@aliases) { my $alias=shift (@aliases); if ($alias eq '') {my $mode='delete';} $result=`/etc/ldap/doaliases \'$alias\' \'$uid\@$server\' $mode`; print "Modify alias results: $result
"; } } 1;