#!/usr/local/bin/perl # index.cgi # Display a list of all cron jobs, with the username and command for each one require './cron-lib.pl'; &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1); # Make sure cron is installed (very likely!) if ($config{'single_file'} && !-r $config{'single_file'}) { $err = &text('index_esingle', "$config{'single_file'}"); } if ($config{'cron_get_command'} =~ /^(\S+)/ && !&has_command("$1")) { $err = &text('index_ecmd', "$1"); } if ($err) { print $err,"
\n"; &ui_print_footer("/", $text{'index'}); exit; } # Work out which users can be viewed map { $ucan{$_}++ } split(/\s+/, $access{'users'}); @jobs = &list_cron_jobs(); @ulist = &unique(map { $_->{'user'} } @jobs); if ($access{'mode'} == 1) { @ulist = grep { $ucan{$_} } @ulist; } elsif ($access{'mode'} == 2) { @ulist = grep { !$ucan{$_} } @ulist; } elsif ($access{'mode'} == 3) { @ulist = ( $remote_user ); } elsif ($access{'mode'} == 4) { @ulist = grep { local @u = getpwnam($_); (!$access{'uidmin'} || $u[2] >= $access{'uidmin'}) && (!$access{'uidmax'} || $u[2] <= $access{'uidmax'}) } @ulist; } elsif ($access{'mode'} == 5) { @ulist = grep { local @u = getpwnam($_); $u[3] == $access{'users'} } @ulist; } if ($config{'show_run'}) { &foreign_require("proc", "proc-lib.pl"); @procs = &proc::list_processes(); } # Work out creation links @crlinks = ( ); if ($access{'create'}) { push(@crlinks, "$text{'index_create'}"); push(@crlinks, "$text{'index_ecreate'}") if ($env_support); } if ($config{cron_allow_file} && $config{cron_deny_file} && $access{'allow'}) { push(@crlinks, "$text{'index_allow'}"); } # Show cron jobs by user $single_file = !&supports_users() || !(@ulist != 1 || $access{'mode'} != 3); @links = ( &select_all_link("d"), &select_invert_link("d"), @crlinks ); foreach $u (@ulist) { if (!$config{'single_file'}) { # Get the Unix user's real name if ((@uinfo = getpwnam($u)) && $uinfo[5] =~ /\S/) { $uname = "$u ($uinfo[5])"; } else { $uname = $u; } } @jlist = grep { $_->{'user'} eq $u } @jobs; @plist = (); for($i=0; $i<@jlist; $i++) { local $rpd = &is_run_parts($jlist[$i]->{'command'}); local @exp = $rpd ? &expand_run_parts($rpd) : (); if (!$rpd || @exp) { push(@plist, [ $jlist[$i], \@exp ]); } } for($i=0; $i<@plist; $i++) { local $job = $plist[$i]->[0]; &convert_range($job); &convert_comment($job); local @exp = @{$plist[$i]->[1]}; local $idx = $job->{'index'}; if (!$donehead) { print &ui_form_start("delete_jobs.cgi", "post"); print &ui_links_row(\@links); print "
| $text{'index_user'} | \n"; } print "$text{'index_active'} | \n"; if ($access{'command'}) { print "$text{'index_command'} | \n"; } if (!$access{'command'} || $config{'show_time'} || $userconfig{'show_time'}) { print "$text{'index_when'} | \n"; } if ($config{'show_comment'} || $userconfig{'show_comment'}) { print "$text{'index_comment'} | \n"; } if ($config{'show_run'}) { print "$text{'index_run'} | \n"; } if ($access{'move'}) { print "$text{'index_move'} | \n"; } print "|||||
| ", scalar(@plist); print &html_escape($uname); print " | \n"; } print "",&ui_checkbox("d", $idx)," | \n"; printf "%s | \n", $job->{'active'} ? $text{'yes'} : "$text{'no'}"; $donelink = 0; if ($job->{'name'}) { # An environment variable - show the name only print "", "$text{'index_env'} ", "$job->{'name'} = $job->{'value'} | \n"; $donelink = 1; } elsif (@exp && $access{'command'}) { # A multi-part command @exp = map { &html_escape($_) } @exp; print "",
join(" ",@exp)," | \n";
$donelink = 1;
}
elsif ($access{'command'}) {
# A simple command
local $max = $config{'max_len'} || 10000;
local ($cmd, $input) =
&extract_input($job->{'command'});
$cmd =
length($cmd) > $max ?
&html_escape(substr($cmd, 0, $max))." ..." :
$cmd !~ /\S/ ? "BLANK" : &html_escape($cmd);
print "$cmd | \n"; $donelink = 1; } # Show cron time if (!$access{'command'} || $config{'show_time'} || $userconfig{'show_time'}) { $when = &when_text($job, 1); if ($job->{'name'}) { print "$when | \n"; } else { print "$when | \n"; } } # Show comment if ($config{'show_comment'} || $userconfig{'show_comment'}) { print "",($job->{'comment'} || " ")," | \n";
}
# Show running indicator
if ($config{'show_run'}) {
print "";
if ($job->{'name'}) {
# An environment variable
print " \n"; } else { # Try to find the process local $proc = &find_cron_process($job, \@procs); $txt = $proc ? "$text{'yes'}" : $text{'no'}; if ($config{'show_run'} == 2 && ($access{'kill'} || !$proc)) { $lnk = $proc ? "kill_cron.cgi?idx=$idx" : "exec_cron.cgi?idx=$idx&bg=1"; print "$txt"; } else { print $txt; } } print " | \n";
}
# Show mover buttons
local $prv = $i > 0 ? $plist[$i-1]->[0] : undef;
local $nxt = $i != $#plist ? $plist[$i+1]->[0] : undef;
if ($access{'move'}) {
print "";
if ($prv && $prv->{'file'} eq $job->{'file'} &&
($job->{'type'} == 0 || $job->{'type'} == 3)) {
print "",
" ";
}
else {
print " ";
}
if ($nxt && $nxt->{'file'} eq $job->{'file'} &&
($job->{'type'} == 0 || $job->{'type'} == 3)) {
print "",
" ";
}
else {
print " ";
}
print " | \n";
}
print "
\n" : $access{'mode'} ? "$text{'index_none2'}
\n" : "$text{'index_none'}
\n"; print &ui_links_row(\@crlinks); } if ($donehead) { print &ui_form_end([ [ "delete", $text{'index_delete'} ], [ "disable", $text{'index_disable'} ], [ "enable", $text{'index_enable'} ] ]); } &ui_print_footer("/", $text{'index'});