Handle hostnames with upper-case letters
[webmin.git] / at / freebsd-lib.pl
1 # freebsd-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 =~ /^c(\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                 push(@rv, $job);
23                 }
24         }
25 closedir(DIR);
26 return @rv;
27 }
28
29 # create_atjob(user, time, commands, directory, send-mail)
30 sub create_atjob
31 {
32 local @tm = localtime($_[1]);
33 local $date = sprintf "%2.2d:%2.2d %d.%d.%d",
34                 $tm[2], $tm[1], $tm[3], $tm[4]+1, $tm[5]+1900;
35 local $mailflag = $_[4] ? "-m" : "";
36 local $cmd = "cd ".quotemeta($_[3])." ; at $mailflag $date";
37 local @uinfo = getpwnam($_[0]);
38 if ($uinfo[2] != $<) {
39         # Only SU if we are not already the user
40         $cmd = &command_as_user($_[0], 0, $cmd);
41         }
42 &open_execute_command(AT, "$cmd >/dev/null 2>&1", 0); 
43 print AT $_[2];
44 close(AT);
45 &additional_log('exec', undef, "su \"$_[0]\" -c \"cd $_[3] ; at $date\"");
46 }
47
48 # delete_atjob(id)
49 sub delete_atjob
50 {
51 &system_logged("atrm ".quotemeta($_[0])." >/dev/null 2>&1");
52 }
53