#!/usr/local/bin/perl # upload.cgi # Upload a file require './file-lib.pl'; $disallowed_buttons{'upload'} && &error($text{'ebutton'}); &popup_header(); &ReadParse(\%getin, "GET"); $upid = $getin{'id'}; &ReadParseMime($upload_max, \&read_parse_mime_callback, [ $upid ]); $realdir = &unmake_chroot($in{'dir'}); if (!$in{'file_filename'}) { print "

$text{'upload_efile'}

\n"; } elsif (!-d $realdir) { print "

$text{'upload_edir'}

\n"; } elsif ($running_as_root && !defined(getpwnam($in{'user'}))) { print "

$text{'upload_euser'}

\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($running_as_root ? $in{'user'} : undef); $temp = &tempname(); &open_tempfile(TEMP, ">$temp"); if ($dostounix == 1 && $in{'dos'}) { $in{'file'} =~ s/\r\n/\n/g; } &print_tempfile(TEMP, $in{'file'}); &close_tempfile(TEMP); print "

\n"; print &ui_form_start("upload2.cgi"); foreach $i (keys %prein) { print &ui_hidden($i, $prein{$i}); } 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 &text('upload_already', "$path"),"

\n"; print &ui_form_end([ [ "yes", $text{'yes'} ], [ "no", $text{'no'} ] ]); print "\n"; print "

\n"; } else { # Go ahread and do it! &webmin_log("upload", undef, $path); &switch_acl_uid($running_as_root ? $in{'user'} : undef); if ($access{'ro'} || !&can_access($path)) { print "

",&text('upload_eperm', $path),"

\n"; } elsif (-l $path && !&must_follow($realpath)) { print "

",&text('upload_elink', $path),"

\n"; } elsif (!&open_tempfile(FILE, ">$realpath", 1)) { print "

",&text('upload_ewrite', $path, $!),"

\n"; } else { if ($dostounix == 1 && $in{'dos'}) { $in{'file'} =~ s/\r\n/\n/g; } &print_tempfile(FILE, $in{'file'}); &close_tempfile(FILE); &post_upload($path, $in{'dir'}, $in{'zip'}); } } } &popup_footer();