Allow scheduled downloads in Usermin
authorJamie Cameron <jcameron@webmin.com>
Mon, 16 Jun 2008 03:25:30 +0000 (03:25 +0000)
committerJamie Cameron <jcameron@webmin.com>
Mon, 16 Jun 2008 03:25:30 +0000 (03:25 +0000)
at/freebsd-lib.pl
at/irix-lib.pl
at/linux-lib.pl
at/solaris-lib.pl
updown/download.cgi
updown/updown-lib.pl

index fa3ba5a..6f1219f 100644 (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");
 }
 
index 9248c1a..8e3a4bf 100644 (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]));
 }
 
index 63391f4..ac2f49c 100644 (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");
 }
 
index 88bba08..f1304b0 100644 (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]));
 }
 
index 4c150a0..d74740d 100755 (executable)
@@ -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();
                        }
                }
index 96d9834..aeafca9 100644 (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]),