Handle hostnames with upper-case letters
[webmin.git] / majordomo / useradmin_update.pl
1
2 do 'majordomo-lib.pl';
3 $conf = &get_config();
4 @lists = &list_lists($conf);
5
6 # useradmin_create_user(&details)
7 # Add a user to the mailing list
8 sub useradmin_create_user
9 {
10 foreach $l (@lists) {
11         if ($config{"sync_$l"}) {
12                 local $dom = $config{"shost_$l"};
13                 $dom = &get_system_hostname() if (!$dom);
14                 local $list = &get_list($l, $conf);
15                 local $pass = &find_value("admin_passwd",
16                            &get_list_config($list->{'config'}));
17                 &lock_file($list->{'members'});
18                 open(WRAPPER, "|$config{'program_dir'}/wrapper majordomo");
19                 print WRAPPER "From: $_[0]->{'user'}\@$dom\n\n";
20                 print WRAPPER "approve $pass subscribe $l ",
21                               "$_[0]->{'user'}\@$dom\n\n";
22                 close(WRAPPER);
23                 sleep(1);
24                 &unlock_file($list->{'members'});
25                 }
26         }
27 }
28
29 # useradmin_delete_user(&details)
30 # Delete a user from the mailing list
31 sub useradmin_delete_user
32 {
33 foreach $l (@lists) {
34         if ($config{"sync_$l"}) {
35                 local $dom = $config{"shost_$l"};
36                 $dom = &get_system_hostname() if (!$dom);
37                 local $list = &get_list($l, $conf);
38                 local $pass = &find_value("admin_passwd",
39                            &get_list_config($list->{'config'}));
40                 &lock_file($list->{'members'});
41                 open(WRAPPER, "|$config{'program_dir'}/wrapper majordomo");
42                 print WRAPPER "From: $_[0]->{'user'}\@$dom\n\n";
43                 print WRAPPER "approve $pass unsubscribe $l ",
44                               "$_[0]->{'user'}\@$dom\n\n";
45                 close(WRAPPER);
46                 sleep(1);
47                 &unlock_file($list->{'members'});
48                 }
49         }
50 }
51
52 # useradmin_modify_user(&details)
53 # Does nothing
54 sub useradmin_modify_user
55 {
56 return if ($_[0]->{'user'} eq $_[0]->{'olduser'} || !$_[0]->{'olduser'});
57 foreach $l (@lists) {
58         if ($config{"sync_$l"}) {
59                 # Directly update the subscription list, if the user is on it
60                 local $dom = $config{"shost_$l"};
61                 $dom = &get_system_hostname() if (!$dom);
62                 local $list = &get_list($l, $conf);
63                 &lock_file($list->{'members'});
64                 local $lref = &read_file_lines($list->{'members'});
65                 local ($i, $found);
66                 for($i=0; $i<@$lref; $i++) {
67                         if ($lref->[$i] eq "$_[0]->{'olduser'}\@$dom") {
68                                 $lref->[$i] = "$_[0]->{'user'}\@$dom";
69                                 $found++;
70                                 }
71                         }
72                 &flush_file_lines() if ($found);
73                 &unlock_file($list->{'members'});
74                 }
75         }
76
77 }
78
79 1;
80