#!/usr/bin/perl use Date::Calc qw(:all); use Net::SMTP; ($year,$month,$day) = Today(); ($hour,$min,$sec) = Now(); my $server = $ARGV[0]; my $ldapdc = $ARGV[1]; my $ldpass = $ARGV[2]; system("ldapsearch -x -LL -H $server -b $ldapdc -s sub -D cn=admin,$ldapdc -w $ldpass \"(birthDate=*)\" cn mail birthDate > /tmp/birthday.tmp"); open BDAY, ") { if($line =~ /^dn:/) { $user = $line; } if($line =~ /^cn:/) { ($bday{$user}{"NAME"}) = ($line =~ /cn: (.*)/); } if($line =~ /^mail:/) { ($bday{$user}{"MAIL"}) = ($line =~ /mail: (.*)/); } if($line =~ /^birthDate:/) { ($bday{$user}{"BDAY"}{"YEAR"}, $bday{$user}{"BDAY"}{"MONTH"}, $bday{$user}{"BDAY"}{"DAY"}) = ($line =~ /birthDate: (\d\d\d\d)-(\d\d)-(\d\d).*/); $bday{$user}{"AGE"} = ($year - $bday{$user}{"BDAY"}{"YEAR"}); $bday{$user}{"TLEFT"} = Delta_Days($year, $month, $day, $year, $bday{$user}{"BDAY"}{"MONTH"}, $bday{$user}{"BDAY"}{"DAY"}); } } foreach $user (keys %bday) { if ($bday{$user}{"TLEFT"}==7 || $bday{$user}{"TLEFT"}==-358) { &bdayMail($bday{$user}{"NAME"},$bday{$user}{"MAIL"},$bday{$user}{"AGE"},"Der Geburtstag von " . $bday{$user}{"NAME"} . " naht!", $bday{$user}{"BDAY"}{"DAY"} . "." . $bday{$user}{"BDAY"}{"MONTH"}); } if ($bday{$user}{"TLEFT"}==0) { &bdayMail($bday{$user}{"NAME"},$bday{$user}{"MAIL"},$bday{$user}{"AGE"},"Heute hat " . $bday{$user}{"NAME"} . " Geburtstag!", $bday{$user}{"BDAY"}{"DAY"} . "." . $bday{$user}{"BDAY"}{"MONTH"}); } } system("rm /tmp/birthday.tmp"); sub bdayMail { $smtp = Net::SMTP->new('localhost') or die "Can't connect SMTP localhost!\n"; $recp{'post@gunnarwrobel.de'}{"NAME"} = "Gunnar"; $date = sprintf("%.3s, %02d %.3s %d %d:%d:%d +0200", Day_of_Week_to_Text(Day_of_Week($year,$month,$day)), $day, Month_to_Text($month), $year,$hour,$min,$sec); foreach $localname (keys %recp) { $mail = 'From: Birthday Skript ' . "\n"; $mail .= "To: " . $recp{$localname}{"NAME"} . " <" . $localname .">\n"; $mail .= "Date: " . $date . "\n"; $mail .= "Subject: " . $_[3] . "\n\n"; $mail .= "Am " . $_[4] . " wird " . $_[0] . " " . $_[2] . " Jahre alt.\n\n"; if (!$_[1] eq "") { $mail .= "Falls Du eine Mail schreiben moechtest: " . $_[1] . "\n"; } $smtp->mail('system@gunnarwrobel.de'); $smtp->to($localname); $smtp->data(); $smtp->datasend($mail); $smtp->dataend(); $smtp->quit; } }