Handle hostnames with upper-case letters
[webmin.git] / cron / useradmin_update.pl
1
2 do 'cron-lib.pl';
3
4 # useradmin_create_user(&details)
5 sub useradmin_create_user
6 {
7 }
8
9 # useradmin_delete_user(&details)
10 # Delete this user's cron file
11 sub useradmin_delete_user
12 {
13 &lock_file("$config{'cron_dir'}/$_[0]->{'user'}");
14 unlink("$config{'cron_dir'}/$_[0]->{'user'}");
15 &unlock_file("$config{'cron_dir'}/$_[0]->{'user'}");
16 }
17
18 # useradmin_modify_user(&details, &old)
19 sub useradmin_modify_user
20 {
21 # If a user's login name has changed, update all his Cron jobs
22 if ($_[0]->{'user'} ne $_[0]->{'olduser'}) {
23         if (-r "$config{'cron_dir'}/$_[0]->{'olduser'}") {
24                 &rename_logged("$config{'cron_dir'}/$_[0]->{'olduser'}",
25                                "$config{'cron_dir'}/$_[0]->{'user'}");
26                 }
27         foreach $j (&list_cron_jobs()) {
28                 if ($j->{'user'} eq $_[0]->{'olduser'}) {
29                         &lock_file($j->{'file'});
30                         $j->{'user'} = $_[0]->{'user'};
31                         &change_cron_job($j);
32                         &unlock_file($j->{'file'});
33                         }
34                 }
35         }
36
37 # If the user's home has changed, update all Cron job paths
38 if ($_[1] && $_[1]->{'home'} ne '/' && $_[0]->{'home'} ne $_[1]->{'home'}) {
39         foreach $j (&list_cron_jobs()) {
40                 if ($j->{'user'} eq $_[0]->{'user'}) {
41                         if ($j->{'command'} =~
42                             s/$_[1]->{'home'}/$_[0]->{'home'}/g) {
43                                 &lock_file($j->{'file'});
44                                 &change_cron_job($j);
45                                 &unlock_file($j->{'file'});
46                                 }
47                         }
48                 }
49         }
50 }
51
52 1;
53