Skip to content

Commit d228322

Browse files
committedMay 26, 2017
template for list.info, use sendmail to subscribe, use archive if exist
1 parent 10881d9 commit d228322

File tree

3 files changed

+51
-21
lines changed

3 files changed

+51
-21
lines changed
 

‎majordomo/create_list.cgi

+21-7
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,26 @@ $in{'footer'} =~ s/\r//g;
4444
&set_permissions("$ldir/$in{'name'}");
4545
&unlock_file("$ldir/$in{'name'}");
4646

47+
48+
4749
# Have majordomo create the new config file, by fooling the wrapper
4850
# into thinking it has received an email with a resend command
51+
#$lfile = "$ldir/$in{'name'}.config";
52+
#$cmd = "$wrapper_program_path resend -l $in{'name'} nobody";
53+
#open(WRAPPER, "|$cmd nobody >/dev/null 2>&1");
54+
#print WRAPPER "config $in{'name'} $in{'password'}\n\n";
55+
#close(WRAPPER);
56+
#&additional_log("exec", $cmd);
57+
#sleep(3);
58+
59+
# use provided template, majordomo provides onyl minimal needed config
4960
$lfile = "$ldir/$in{'name'}.config";
50-
$cmd = "$wrapper_program_path resend -l $in{'name'} nobody";
51-
open(WRAPPER, "|$cmd nobody >/dev/null 2>&1");
52-
print WRAPPER "config $in{'name'} $in{'password'}\n\n";
53-
close(WRAPPER);
54-
&additional_log("exec", $cmd);
55-
sleep(3);
61+
# copy listdir template to list.info, fallback copy from template.dist
62+
if ( ! -f "template/list.config") { &copy_source_dest("template/list.config.dist","template/list.config"); }
63+
if ( ! -f "template/list.config") { &error("No default template found: template/list.config"); }
64+
if ( ! -f "$lfile") { &copy_source_dest("template/list.config", $lfile); }
65+
if ( ! -f "$lfile") { &error("Could not create list config: $file"); }
66+
&set_permissions("$lfile");
5667

5768
# create the .info file
5869
&lock_file($lfile);
@@ -72,7 +83,10 @@ if (&find_value("date_info", $list) eq "yes") {
7283
# create the archive directory
7384
$adir = &perl_var_replace(&find_value("filedir", $conf), $conf);
7485
$aext = &perl_var_replace(&find_value("filedir_suffix", $conf), $conf);
75-
if ($adir && $aext) {
86+
if( -d "$adir") {
87+
$arch = "$adir/$in{'name'}";
88+
}
89+
elsif ($adir && $aext) {
7690
&lock_file("$adir/$in{'name'}$aext");
7791
mkdir("$adir/$in{'name'}$aext", 0755);
7892
&set_permissions("$adir/$in{'name'}$aext");

‎majordomo/save_members.cgi

+30-14
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,50 @@ if ($in{'update'}) {
3434
&webmin_log("members", undef, $in{'name'});
3535
}
3636
elsif ($in{'add'}) {
37-
# call majordomo to subscribe an address
37+
# call send_mail to subscribe an address
3838
$pass || &error($text{'members_esub'});
3939
$in{'addr_a'} =~ /^(\S+)\@(\S+)\.(\S+)$/ ||
4040
&error($text{'members_esubaddr'});
41-
open(WRAPPER, "|$wrapper_path majordomo");
42-
printf WRAPPER "From: %s\n\n",
43-
$owner ? $owner : $in{'addr_a'};
44-
print WRAPPER "approve $pass subscribe $in{'name'} $in{'addr_a'}\n\n";
45-
close(WRAPPER);
46-
sleep(1);
41+
$mail=sprintf("From: %s\nTo: %s\nSubject: subcribe\n\n",
42+
$owner ? $owner : $in{'addr_a'}, "majordomo");
43+
$mail .= "approve $pass subscribe $in{'name'} $in{'addr_a'}\n\n";
44+
&send_mail($mail);
4745
&unlock_file($list->{'members'});
4846
&webmin_log("subscribe", undef, $in{'name'},
4947
{ 'addr' => $in{'addr_a'} });
5048
}
5149
elsif ($in{'remove'}) {
52-
# call majordomo to unsubscribe an address
50+
# call send_mail to unsubscribe an address
5351
$pass || &error($text{'members_eunsub'});
5452
$in{'addr_r'} =~ /^(\S+)\@(\S+)\.(\S+)$/ ||
5553
&error($text{'members_eunsubaddr'});
56-
open(WRAPPER, "|$wrapper_path majordomo");
57-
printf WRAPPER "From: %s\n\n",
58-
$owner ? $owner : $in{'addr_r'};
59-
print WRAPPER "approve $pass unsubscribe $in{'name'} $in{'addr_r'}\n\n";
60-
close(WRAPPER);
61-
sleep(1);
54+
$mail=sprintf("From: %s\nTo: %s\nSubject: unsubcribe\n\n",
55+
$owner ? $owner : $in{'addr_a'}, "majordomo");
56+
$mail .= "approve $pass unsubscribe $in{'name'} $in{'addr_r'}\n\n";
57+
&send_mail($mail);
6258
&unlock_file($list->{'members'});
6359
&webmin_log("unsubscribe", undef, $in{'name'},
6460
{ 'addr' => $in{'addr_r'} });
6561
}
6662
&redirect("edit_list.cgi?name=$in{'name'}");
6763

64+
sub send_mail
65+
{
66+
local $sent,$mail=$_[0];
67+
if (!$sent) {
68+
# Try to send the email by calling sendmail -t
69+
%sconfig = &foreign_config("sendmail");
70+
$sendmail = $sconfig{'sendmail_path'} ? $sconfig{'sendmail_path'}
71+
: &has_command("sendmail");
72+
if (-x $sendmail && open(MAIL, "| $sendmail -t")) {
73+
print MAIL $mail;
74+
if (close(MAIL)) {
75+
$sent = 2;
76+
}
77+
}
78+
}
79+
80+
if (!$sent) {
81+
&error($text{'global_esendmail'}, "");
82+
}
83+
}
File renamed without changes.

0 commit comments

Comments
 (0)
Please sign in to comment.