adding
[freeside.git] / bin / create-fetchmailrc
1 #!/usr/bin/perl -w
2 # this quick hack helps you generate/maintain .fetchmailrc files from
3 # FS::acct_snarf data.  it is run from a shellcommands export as:
4 # create-fetchmailrc $username $dir $snarf_machine1 $snarf_username1 $snarf__password1 $snarf_machine2 $snarf_username2 $snarf__password2 $snarf_machine3 $snarf_username3 $snarf__password3 $snarf_machine4 $snarf_username4 $snarf__password4 $snarf_machine5 $snarf_username5 $snarf__password5 $snarf_machine6 $snarf_username6 $snarf__password6 $snarf_machine7 $snarf_username7 $snarf__password7 $snarf_machine8 $snarf_username8 $snarf__password8 $snarf_machine9 $snarf_username9 $snarf__password9 $snarf_machine10 $snarf_username10 $snarf__password10
5
6 use strict;
7 use POSIX qw( setuid setsid );
8
9 my $header = <<END;
10 # Configuration created by create-fetchmailrc
11 set postmaster "postmaster"
12 set bouncemail
13 set no spambounce
14 set properties ""
15 set daemon 240
16 END
17
18 my $username = shift @ARGV or die "no username specified\n";
19 my $homedir  = shift @ARGV or die "no homedir specified\n";
20 my $filename = "$homedir/.fetchmailrc";
21
22 open(FETCHMAILRC, ">$filename") or die "can't open $filename: $!\n";
23 chown 0600, $filename           or die "can't chown 600 $filename: $!\n";
24 print FETCHMAILRC $header;
25
26 while ($ARGV[0]) {
27   my( $s_machine, $s_username, $s_password ) = splice( @ARGV, 0, 3 );
28   print FETCHMAILRC <<END;
29 poll $s_machine
30         user '$s_username' there with password '$s_password' is '$username' here
31 END
32 }
33
34 close FETCHMAILRC;
35
36 my $gid = scalar(getgrnam($username)) or die "can't find $username's gid\n";
37 my $uid = scalar(getpwnam($username)) or die "can't find $username's uid\n";
38
39 setgid($gid) or die "can't setgid $gid\n";
40 setuid($uid) or die "can't setuid $uid\n";
41
42 exec(qw( fetchmail -a -K --antispam "550,451" -d 180 -f ), $filename);
43 die "can't execute fetchmail: $!";
44
45
46