3 # Create the mailing-lists from the database
4 # Copyright 2001-2003, 2009 Roland Mas <lolando@debian.org>
5 # Copyright 2003, 2004, Christian Bayle <bayle@debian.org>
6 # Copyright 2005, INRIA (David Margery and Soraya Arias)
11 use File::Temp qw/ :mktemp /;
13 use vars qw/ $dbh $sys_lists_host $sys_users_host / ;
19 require ("/usr/share/gforge/lib/include.pl") ; # Include all the predefined functions
23 $dbh->{AutoCommit} = 0;
24 $dbh->{RaiseError} = 1;
26 my ($query, $sth, @array, @lines, $line) ;
28 $query = "SELECT mail_group_list.group_list_id,
29 mail_group_list.list_name,
31 mail_group_list.password,
32 mail_group_list.description,
33 mail_group_list.is_public
34 FROM mail_group_list, users
35 WHERE mail_group_list.status = 1
36 AND mail_group_list.list_admin = users.user_id" ; # Status = 1: list just created on the website
37 $sth = $dbh->prepare ($query) ;
39 while (my @myarray = $sth->fetchrow_array ()) {
40 push @lines, \@myarray ;
44 foreach $line (@lines) {
46 my ($group_list_id, $listname, $user_name, $password, $description, $is_public) ;
49 ($group_list_id, $listname, $user_name, $password, $description, $is_public)= @array ;
50 next if $listname eq '' ;
51 next if $listname eq '.' ;
52 next if $listname eq '..' ;
53 next if $listname !~ /^[a-z0-9\-_\.]*$/ ;
55 my $cmd = "/usr/sbin/newlist -q $listname $user_name\@$sys_users_host $password >/dev/null 2>&1" ;
56 #print "cmd = <$cmd>\n" ;
59 $query = "UPDATE mail_group_list SET status = 2 where group_list_id = group_list_id" ; # Status = 2: list created on Mailman
60 $sth = $dbh->prepare ($query) ;
64 $tmp = mktemp ("/tmp/XXXXXX") ;
65 $cmd = "/usr/lib/mailman/bin/config_list -o $tmp $listname" ;
66 #print "cmd = <$cmd>\n" ;
67 # Commented out on Matt Hope <dopey@debian.org> advice
68 # To be revised by Roland Mas
70 open CONFIG, ">>$tmp" ;
71 print CONFIG "description = \"$description\"\n" ;
72 print CONFIG "host_name = '$sys_lists_host'\n" ;
74 print CONFIG "archive_private = True\n" ;
75 print CONFIG "advertised = False\n" ;
76 print CONFIG "subscribe_policy = 3\n" ;
77 ## Reject mails sent by non-members
78 print CONFIG "generic_nonmember_action = 2\n";
79 ## Do not forward auto discard message
80 print CONFIG "forward_auto_discards = 0\n";
82 print CONFIG "archive_private = False\n" ;
83 print CONFIG "advertised = True\n" ;
84 print CONFIG "subscribe_policy = 1\n" ;
87 $cmd = "/usr/lib/mailman/bin/config_list -i $tmp $listname" ;
88 #print "cmd = <$cmd>\n" ;
92 $cmd= "/usr/lib/mailman/bin/withlist -l -r fix_url $listname -u $sys_lists_host" ;
93 #print "cmd = <$cmd>\n" ;
96 $query = "UPDATE mail_group_list SET status = 3 where group_list_id = group_list_id" ; # Status = 3: list configured on Mailman
97 $sth = $dbh->prepare ($query) ;
101 #debug "Committing." ;
105 $query = "SELECT mail_group_list.group_list_id,
106 mail_group_list.list_name,
108 mail_group_list.password,
109 mail_group_list.description,
110 mail_group_list.is_public
111 FROM mail_group_list, users
112 WHERE mail_group_list.status = 4
113 AND mail_group_list.list_admin = users.user_id" ; # Status = 4: password reset requested
114 $sth = $dbh->prepare ($query) ;
117 while (my @myarray = $sth->fetchrow_array ()) {
118 push @lines, \@myarray ;
122 foreach $line (@lines) {
124 my ($group_list_id, $listname, $user_name, $password, $description, $is_public) ;
127 ($group_list_id, $listname, $user_name, $password, $description, $is_public)= @array ;
128 next if $listname eq '' ;
129 next if $listname eq '.' ;
130 next if $listname eq '..' ;
131 next if $listname !~ /^[a-z0-9\-_\.]*$/ ;
133 my $cmd = "/usr/lib/mailman/bin/change_pw -l $listname >/dev/null 2>&1" ;
136 $query = "UPDATE mail_group_list SET status = 3 where group_list_id = group_list_id" ; # Status = 3: list configured on Mailman
137 $sth = $dbh->prepare ($query) ;
141 #debug "Committing." ;
145 # There should be a commit at the end of every block above.
146 # If there is not, then it might be symptomatic of a problem.
147 # For safety, we roll back.
152 warn "Transaction aborted because $@" ;
153 debug "Transaction aborted because $@" ;
155 debug "Please report this bug on the Debian bug-tracking system." ;
156 debug "Please include the previous messages as well to help debugging." ;
166 print STDERR "$v\n" ;