Added input to select upload Unix user
authorJamie Cameron <jcameron@webmin.com>
Fri, 18 May 2007 05:20:28 +0000 (05:20 +0000)
committerJamie Cameron <jcameron@webmin.com>
Fri, 18 May 2007 05:20:28 +0000 (05:20 +0000)
file/CHANGELOG
file/file-lib.pl
file/index.cgi
file/lang/en
file/upform.cgi
file/upload.cgi
file/upload2.cgi

index dc57bec..049a149 100644 (file)
@@ -35,3 +35,4 @@ Replaced the HTMLarea widget for editing .html files with Xinha.
 When editing an HTML file, the <head> section is preserved.
 Added a link in the HTML editor window to swich to plain text mode.
 Files in the right-hand list are now sorted case-insensitively.
+When uploading a file, you can now select which Unix user it gets uploaded as.
index c394133..d7bc305 100644 (file)
@@ -62,6 +62,7 @@ if ($module_info{'usermin'}) {
        $canperms = 1;
        $canusers = 1;
        $contents = 1;
+       $running_as_root = 0;
        }
 else {
        # Webmin gets the list of allowed directories from the ACL
@@ -98,6 +99,7 @@ else {
        $canperms = $access{'noperms'} ? 0 : 1;
        $canusers = $access{'nousers'} ? 0 : 1;
        $contents = $access{'contents'};
+       $running_as_root = !$access{'uid'};
        }
 %disallowed_buttons = map { $_, 1 } @disallowed_buttons;
 
@@ -157,12 +159,15 @@ return join("\t", $dp, $type,
                  $st[9], $f ? "" : $islink && !$rl ? "???" : $rl);
 }
 
-# switch_acl_uid()
+# switch_acl_uid([user])
 sub switch_acl_uid
 {
-if (!$module_info{'usermin'} && $access{'uid'}) {
-       local @u = $access{'uid'} < 0 ? getpwnam($remote_user)
-                                     : getpwuid($access{'uid'});
+local ($user) = @_;
+return if ($module_info{'usermin'});   # Always already switched
+local @u = $user ? getpwnam($user) :
+          $access{'uid'} < 0 ? getpwnam($remote_user) :
+                               getpwuid($access{'uid'});
+if ($u[2]) {
        @u || &error($text{'switch_euser'});
        $( = $u[3]; $) = "$u[3] ".join(" ", $u[3], &other_groups($u[0]));
        ($>, $<) = ($u[2], $u[2]);
index f426cb6..39114e8 100755 (executable)
@@ -84,7 +84,7 @@ print <<EOF;
 <script>
 function upload(dir)
 {
-open("upform.cgi?dir="+escape(dir)+"&trust=$trust", "upload", "toolbar=no,menubar=no,scrollbar=no,width=450,height=200");
+open("upform.cgi?dir="+escape(dir)+"&trust=$trust", "upload", "toolbar=no,menubar=no,scrollbar=no,width=550,height=230");
 }
 function htmledit(file, dir)
 {
index ec5cc4e..6e9e15c 100644 (file)
@@ -189,12 +189,14 @@ upload_ok=Upload
 upload_conv=Convert DOS newlines?
 upload_efile=No file selected to upload.
 upload_edir=Upload directory does not exist.
+upload_euser=Selected user does not exist.
 upload_eperm=You are not allowed to create $1
 upload_ewrite=Failed to write to $1 : $2.
 upload_already=The file $1 already exists. Are you sure that you want to overwrite it?
 upload_elink=Cannot upload to a symbolic link
 upload_zip=Uncompress ZIP or TAR file?
 upload_yes=Yes, then delete
+upload_user=Upload as user
 
 find_eaccess=You are not allowed to access $1
 find_eexist=$1 does not exist in $2
index d319930..ec5ff36 100755 (executable)
@@ -21,11 +21,13 @@ print &ui_table_row($text{'upload_dir'},
                    &ui_submit($text{'upload_ok'}));
 
 if ($dostounix == 1) {
+       # Do DOS conversion?
        print &ui_table_row($text{'upload_conv'},
                            &ui_yesno_radio("dos", 0));
        }
 
 if ($unarchive == 1) {
+       # Unzip file?
        print &ui_table_row($text{'upload_zip'},
                            &ui_radio("zip", 0,
                                [ [ 2, $text{'upload_yes'} ],
@@ -33,6 +35,12 @@ if ($unarchive == 1) {
                                  [ 0, $text{'no'} ] ]));
        }
 
+if ($running_as_root) {
+       # Upload as user
+       print &ui_table_row($text{'upload_user'},
+                           &ui_user_textbox("user", "root"));
+       }
+
 print &ui_table_end();
 print &ui_form_end();
 &popup_footer();
index 00cd977..d32afbc 100755 (executable)
@@ -16,13 +16,16 @@ if (!$in{'file_filename'}) {
 elsif (!-d $realdir) {
        print "<p><b>$text{'upload_edir'}</b><p>\n";
        }
+elsif ($running_as_root && !defined(getpwnam($in{'user'}))) {
+       print "<p><b>$text{'upload_euser'}</b><p>\n";
+       }
 else {
        $in{'file_filename'} =~ /([^\\\/]+)$/;
        $path = "$in{'dir'}/$1";
        $realpath = "$realdir/$1";
        if (-e $realpath) {
                # File exists .. ask the user if he is sure
-               &switch_acl_uid();
+               &switch_acl_uid($running_as_root ? $in{'user'} : undef);
                $temp = &tempname();
                &open_tempfile(TEMP, ">$temp");
                if ($dostounix == 1 && $in{'dos'}) {
@@ -35,14 +38,11 @@ else {
                        print "<input type=hidden name=$i value='",
                                &html_escape($prein{$i}),"'>\n";
                        }
-               print "<input type=hidden name=dir value='",
-                       &html_escape($in{'dir'}),"'>\n";
-               print "<input type=hidden name=path value='",
-                       &html_escape($path),"'>\n";
-               print "<input type=hidden name=temp value='",
-                       &html_escape($temp),"'>\n";
-               print "<input type=hidden name=zip value='",
-                       &html_escape($in{'zip'}),"'>\n";
+               print &ui_hidden("dir", $in{'dir'});
+               print &ui_hidden("path", $path);
+               print &ui_hidden("temp", $temp);
+               print &ui_hidden("zip", $in{'zip'});
+               print &ui_hidden("user", $in{'user'});
                print "<center>\n";
                print &text('upload_already', "<tt>$path</tt>"),"<p>\n";
                print "<input type=submit name=yes value='$text{'yes'}'>\n";
@@ -52,7 +52,7 @@ else {
        else {
                # Go ahread and do it!
                &webmin_log("upload", undef, $path);
-               &switch_acl_uid();
+               &switch_acl_uid($running_as_root ? $in{'user'} : undef);
                if ($access{'ro'} || !&can_access($path)) {
                        print "<p><b>",&text('upload_eperm', $path),"</b><p>\n";
                        }
index a01fec2..849921a 100755 (executable)
@@ -10,7 +10,7 @@ $disallowed_buttons{'upload'} && &error($text{'ebutton'});
 if ($in{'yes'}) {
        # Put it in place, overwriting any other file
        &webmin_log("upload", undef, $in{'path'});
-       &switch_acl_uid();
+       &switch_acl_uid($running_as_root ? $in{'user'} : undef);
        if ($access{'ro'} || !&can_access($in{'path'})) {
                print "<p><b>",&text('upload_eperm', $in{'path'}),"</b><p>\n";
                }