Allow scheduled downloads in Usermin

This commit is contained in:
Jamie Cameron
2008-06-16 03:25:30 +00:00
parent e9c0439d57
commit a112fa3206
6 changed files with 29 additions and 14 deletions

View File

@@ -32,7 +32,13 @@ sub create_atjob
local @tm = localtime($_[1]);
local $date = sprintf "%2.2d:%2.2d %d.%d.%d",
$tm[2], $tm[1], $tm[3], $tm[4]+1, $tm[5]+1900;
&open_execute_command(AT, "su \"$_[0]\" -c \"cd $_[3] ; at $date\" >/dev/null 2>&1", 0);
local $cmd = "cd ".quotemeta($_[3])." ; at $date";
local @uinfo = getpwnam($_[0]);
if ($uinfo[2] != $<) {
# Only SU if we are not already the user
$cmd = &command_as_user($_[0], 0, $cmd);
}
&open_execute_command(AT, "$cmd >/dev/null 2>&1", 0);
print AT $_[2];
close(AT);
&additional_log('exec', undef, "su \"$_[0]\" -c \"cd $_[3] ; at $date\"");
@@ -41,6 +47,6 @@ close(AT);
# delete_atjob(id)
sub delete_atjob
{
&system_logged("atrm \"$_[0]\" >/dev/null 2>&1");
&system_logged("atrm ".quotemeta($_[0])." >/dev/null 2>&1");
}

View File

@@ -33,7 +33,13 @@ sub create_atjob
{
local @tm = localtime($_[1]);
local $date = strftime "%H:%M %b %d", @tm;
&open_execute_command(AT, "su \"$_[0]\" -c \"cd $_[3] ; at $date\"", 0);
local $cmd = "cd ".quotemeta($_[3])." ; at $date";
local @uinfo = getpwnam($_[0]);
if ($uinfo[2] != $<) {
# Only SU if we are not already the user
$cmd = &command_as_user($_[0], 0, $cmd);
}
&open_execute_command(AT, "$cmd >/dev/null 2>&1", 0);
print AT $_[2];
close(AT);
&additional_log('exec', undef, "su \"$_[0]\" -c \"cd $_[3] ; at $date\"");
@@ -42,6 +48,6 @@ close(AT);
# delete_atjob(id)
sub delete_atjob
{
&system_logged("at -r \"$_[0]\"");
&system_logged("at -r ".quotemeta($_[0]));
}

View File

@@ -33,11 +33,11 @@ sub create_atjob
local @tm = localtime($_[1]);
local $date = sprintf "%2.2d:%2.2d %d.%d.%d",
$tm[2], $tm[1], $tm[3], $tm[4]+1, $tm[5]+1900;
local $cmd = "cd $_[3]; at $date";
local $cmd = "cd ".quotemeta($_[3])." ; at $date";
local @uinfo = getpwnam($_[0]);
if ($uinfo[2] != $<) {
# Only SU if we are not already the user
$cmd = "su \"$_[0]\" -c \"$cmd\"";
$cmd = &command_as_user($_[0], 0, $cmd);
}
&open_execute_command(AT, "$cmd >/dev/null 2>&1", 0);
print AT $_[2];
@@ -48,6 +48,6 @@ close(AT);
# delete_atjob(id)
sub delete_atjob
{
&system_logged("atrm \"$_[0]\" >/dev/null 2>&1");
&system_logged("atrm ".quotemeta($_[0])." >/dev/null 2>&1");
}

View File

@@ -34,13 +34,13 @@ sub create_atjob
{
local @tm = localtime($_[1]);
local $date = strftime "%H:%M %b %d", @tm;
local $cmd = "cd $_[3]; at $date";
local $cmd = "cd ".quotemeta($_[3])." ; at $date";
local @uinfo = getpwnam($_[0]);
if ($uinfo[2] != $<) {
# Only SU if we are not already the user
$cmd = "su \"$_[0]\" -c \"$cmd\"";
$cmd = &command_as_user($_[0], 0, $cmd);
}
&open_execute_command(AT, "$cmd ; at $date\"", 0);
&open_execute_command(AT, "$cmd >/dev/null 2>&1", 0);
print AT $_[2];
close(AT);
&additional_log('exec', undef, $cmd);
@@ -49,6 +49,6 @@ close(AT);
# delete_atjob(id)
sub delete_atjob
{
&system_logged("atrm \"$_[0]\"");
&system_logged("atrm ".quotemeta($_[0]));
}

View File

@@ -126,8 +126,11 @@ if ($in{'bg'} && $can_background) {
&clean_environment();
$ENV{'REMOTE_USER'} = $remote_user; # For usermin
$ENV{'BASE_REMOTE_USER'} = $base_remote_user;
&at::create_atjob("root", $download{'time'},
"$atjob_cmd $download{'id'}", "/");
&at::create_atjob(
$module_info{'usermin'} ? $remote_user : "root",
$download{'time'},
"$atjob_cmd $download{'id'}",
"/");
&reset_environment();
}
}

View File

@@ -14,7 +14,7 @@ if ($module_info{'usermin'}) {
$can_upload = $config{'upload'};
$can_download = $config{'download'};
$can_fetch = $config{'fetch'};
$can_schedule = 0;
$can_schedule = $config{'background'} && &foreign_check("at");
$can_background = $config{'background'};
if ($config{'home_only'}) {
@can_dirs = ( &resolve_links($remote_user_info[7]),