summaryrefslogtreecommitdiff
path: root/localinformuser
blob: 22a182f4eb0a3ea0eaf3fab63b15b0202fb05385 (plain)
  1. #!/usr/bin/perl -wT
  2. use strict;
  3. use LWP::Simple;
  4. use User::pwent;
  5. use User::grent;
  6. use Mail::Sendmail;
  7. sub getmailbody($;$) {
  8. my $info = shift;
  9. my $lang = shift || 'en';
  10. my $baseurl = "http://support.kaospilot.no/";
  11. my $url = $baseurl . $info . "/email." . $lang . ".txt";
  12. my $mailbody = get($url) || die "Couldn't get email content from <$url>.";
  13. return ($mailbody);
  14. }
  15. sub getuserinfo($) {
  16. my $username = shift;
  17. my $pw = getpwnam($username) || die "Username \"$username\" does not exist.";
  18. my ($fullname, $office, $workphone, $homephone, $other) = split /\s*,\s*/, $pw->gecos;
  19. my @addresshints;
  20. if (defined($other)) {
  21. @addresshints = grep {/^([\.[:alnum:]_-]+|\+)?@([\.[:alnum:]_-]+)?$/} split /\s+/, $other;
  22. }
  23. return ($fullname, @addresshints);
  24. }
  25. my $mailbody = getmailbody("intro", "da");
  26. while (my $username = shift @ARGV) {
  27. my ($fullname, @addresses) = getuserinfo($username);
  28. my $localaddress = "$username\@users.kaospilot.no";
  29. my %mail = (
  30. To => join(", ", grep {/^[\.[:alnum:]_-]+@[\.[:alnum:]_-]+\.[[:alnum:]_-]+$/} @addresses),
  31. Cc => $username . '@users.kaospilot.no',
  32. From => 'jonas@kaospilot.no',
  33. Bcc => 'hostmaster@kaospilot.no',
  34. 'Reply-to' => 'tech@lists.kaospilot.no',
  35. Subject => "Din konto ved kaospilot.no",
  36. 'Content-Type' => 'text/plain; charset="UTF-8"'
  37. );
  38. $mail{'body'} = $mailbody;
  39. $mail{'body'} =~ s/<fullname>/$fullname/g;
  40. $mail{'body'} =~ s/<username>/$username/g;
  41. $mail{'body'} =~ s/<addresses>/$localaddress/g;
  42. $mail{'body'} =~ s/<me>/Jonas Smedegaard/g;
  43. sendmail(%mail) or do {
  44. warn 'Error sending request: ' . $Mail::Sendmail::error;
  45. }
  46. #DEBUG warn "Request forwarded to Mailman. Log says:\n", $Mail::Sendmail::log;
  47. }
  48. __END__
  49. my $valid_email = '/^[+_A-Za-z0-9-]+(\.[+_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[_A-Za-z0-9-]+)$/';
  50. # Mail functions require this for tainted mode
  51. $ENV{PATH} = '/tmp';
  52. my ($from, $mailname, $action, $subject, $infostring, $errors);
  53. warn $ARGV[0];