Handle hostnames with upper-case letters
[webmin.git] / at / linux-lib.pl
1 # linux-lib.pl
2
3 sub list_atjobs
4 {
5 local @rv;
6 opendir(DIR, $config{'at_dir'});
7 while($f = readdir(DIR)) {
8         local $p = "$config{'at_dir'}/$f";
9         if ($f =~ /^a(\S{5})(\S+)$/) {
10                 local @st = stat($p);
11                 local $job = { 'id' => hex($1),
12                                'date' => hex($2) * 60,
13                                'user' => scalar(getpwuid($st[4])),
14                                'created' => $st[9] };
15                 open(FILE, $p);
16                 while(<FILE>) {
17                         $job->{'cmd'} .= $_;
18                         }
19                 close(FILE);
20                 $job->{'realcmd'} = $job->{'cmd'};
21                 $job->{'realcmd'} =~ s/^[\000-\177]+cd\s+(\S+)\s+\|\|\s+{\n.*\n.*\n.*\n//;
22                 $job->{'realcmd'} =~ s/\$\{SHELL:.*\n\n?//;
23                 push(@rv, $job);
24                 }
25         }
26 closedir(DIR);
27 return @rv;
28 }
29
30 # create_atjob(user, time, commands, directory, send-email)
31 sub create_atjob
32 {
33 local @tm = localtime($_[1]);
34 local $date = sprintf "%2.2d:%2.2d %d.%d.%d",
35                 $tm[2], $tm[1], $tm[3], $tm[4]+1, $tm[5]+1900;
36 local $mailflag = $_[4] ? "-m" : "";
37 local $cmd = "cd ".quotemeta($_[3])." ; at $mailflag $date";
38 local @uinfo = getpwnam($_[0]);
39 if ($uinfo[2] != $<) {
40         # Only SU if we are not already the user
41         $cmd = &command_as_user($_[0], 0, $cmd);
42         }
43 &open_execute_command(AT, "$cmd >/dev/null 2>&1", 0);
44 print AT $_[2];
45 close(AT);
46 &additional_log('exec', undef, $cmd);
47 }
48
49 # delete_atjob(id)
50 sub delete_atjob
51 {
52 &system_logged("atrm ".quotemeta($_[0])." >/dev/null 2>&1");
53 }
54