I've been trying to do this all day, and this is it...I'm jumping off
my roof [well, back porch]...no, don't try to stop me...I'll do it...I
SWEAR!!!!
Ok, so enough levity. Really, this time, I'm trying to hack together a
variation of smbgw found here, http://dexy.mine.nu/smbgw/. Got alot
done, and would like to "pretty up" the script, and how it checks for
uploading files, so this is what I have:
// handle file uploads
if(isset($_FILE S["upload"])) {
$upload_tmp=$_F ILES["upload"]["tmp_name"];
$upload_name=$_ FILES["upload"]["name"];
//clear these out from the last submit
$file_name = "";
$result = "";
// a long laundry list of forbidden file types for upload
$ext_array = array(
"app","asp","as x","bat","bas", "chm","exe","ht m",
"html","com","s cr","pif","js", "vbs","chm","cm d",
"cpl","crt","cs h","fxp","hta", "inf","ins","is p",
"ksh","lnk","md a","mde","mdt", "mdw","mdz","ms c",
"msi","msp","ms t","ops","pcd", "prf","reg","sc f",
"sct","url","vs d","vss","vst", "vsw","worm ");
$file_name = trim($upload_na me);
$extension = GetFileExtentio n($file_name); // <--- my function
// first check for a file name
if (!$file_name) {
$result = "You must supply a file to upload. Try again.";
echo "<SCRIPT LANGUAGE=\"Java Script\">"
. "alert (\""
. $result
. "\")"
. "</script>";
} else {
// check extentions and if they match, don't allow it
foreach ($ext_array as $value) {
if ($value == $extension) {
$invalid_extens ion = True;
}
}
// what to do if file extention fails or passes
if ($invalid_exten sion) {
$result = "The file you are trying to upload is not allowed.";
echo "<SCRIPT LANGUAGE=\"Java Script\">"
. "alert (\""
. $result
. "\")"
. "</script>";
} else {
// check to see if it exists
exec("$smbclien t "
. escapeshellarg( $share_path) . " "
. escapeshellarg( $password)
. " -U " . escapeshellarg( $user)
. " -D " . escapeshellarg( $dir)
. " -d0 -c ls | grep $upload_name", $file);
// get file name
$file = trim(substr($fi le[0], 0, -39));
if ( $file == $upload_name ) {
echo "<SCRIPT LANGUAGE=\"Java Script\">
function getInfo() {
doyou = confirm(\"This file already exists! Do you want to
continue? (OK = Yes Cancel = No)\");
if (doyou == true) {
return true
}
else {
return false
}
}
</script>";
}
//finally upload the file
shell_exec("$sm bclient "
. escapeshellarg( $share_path) . " "
. escapeshellarg( $password)
. " -U " . escapeshellarg( $user)
. " -D " . escapeshellarg( $dir)
. " -d0 -c "
. escapeshellarg( "put \"" . $upload_tmp . "\" \"" . $upload_name .
"\""));
}
}
}
It all works, but I'm having trouble with the javascript bit. Maybe I
should just echo the results, but I like the pop-up factor. It's
inconsistent, probably since on first submittal of a file that exists,
the javascript isn't written, and then it appears to upload the file
anyway, then of course the script is on the page at this point, and
next upload test fires the code.
So the question is, besides being a NOOB at this, should I just drop
the javascript and echo?
Thanks for anyone who picks through this crap.
JC
my roof [well, back porch]...no, don't try to stop me...I'll do it...I
SWEAR!!!!
Ok, so enough levity. Really, this time, I'm trying to hack together a
variation of smbgw found here, http://dexy.mine.nu/smbgw/. Got alot
done, and would like to "pretty up" the script, and how it checks for
uploading files, so this is what I have:
// handle file uploads
if(isset($_FILE S["upload"])) {
$upload_tmp=$_F ILES["upload"]["tmp_name"];
$upload_name=$_ FILES["upload"]["name"];
//clear these out from the last submit
$file_name = "";
$result = "";
// a long laundry list of forbidden file types for upload
$ext_array = array(
"app","asp","as x","bat","bas", "chm","exe","ht m",
"html","com","s cr","pif","js", "vbs","chm","cm d",
"cpl","crt","cs h","fxp","hta", "inf","ins","is p",
"ksh","lnk","md a","mde","mdt", "mdw","mdz","ms c",
"msi","msp","ms t","ops","pcd", "prf","reg","sc f",
"sct","url","vs d","vss","vst", "vsw","worm ");
$file_name = trim($upload_na me);
$extension = GetFileExtentio n($file_name); // <--- my function
// first check for a file name
if (!$file_name) {
$result = "You must supply a file to upload. Try again.";
echo "<SCRIPT LANGUAGE=\"Java Script\">"
. "alert (\""
. $result
. "\")"
. "</script>";
} else {
// check extentions and if they match, don't allow it
foreach ($ext_array as $value) {
if ($value == $extension) {
$invalid_extens ion = True;
}
}
// what to do if file extention fails or passes
if ($invalid_exten sion) {
$result = "The file you are trying to upload is not allowed.";
echo "<SCRIPT LANGUAGE=\"Java Script\">"
. "alert (\""
. $result
. "\")"
. "</script>";
} else {
// check to see if it exists
exec("$smbclien t "
. escapeshellarg( $share_path) . " "
. escapeshellarg( $password)
. " -U " . escapeshellarg( $user)
. " -D " . escapeshellarg( $dir)
. " -d0 -c ls | grep $upload_name", $file);
// get file name
$file = trim(substr($fi le[0], 0, -39));
if ( $file == $upload_name ) {
echo "<SCRIPT LANGUAGE=\"Java Script\">
function getInfo() {
doyou = confirm(\"This file already exists! Do you want to
continue? (OK = Yes Cancel = No)\");
if (doyou == true) {
return true
}
else {
return false
}
}
</script>";
}
//finally upload the file
shell_exec("$sm bclient "
. escapeshellarg( $share_path) . " "
. escapeshellarg( $password)
. " -U " . escapeshellarg( $user)
. " -D " . escapeshellarg( $dir)
. " -d0 -c "
. escapeshellarg( "put \"" . $upload_tmp . "\" \"" . $upload_name .
"\""));
}
}
}
It all works, but I'm having trouble with the javascript bit. Maybe I
should just echo the results, but I like the pop-up factor. It's
inconsistent, probably since on first submittal of a file that exists,
the javascript isn't written, and then it appears to upload the file
anyway, then of course the script is on the page at this point, and
next upload test fires the code.
So the question is, besides being a NOOB at this, should I just drop
the javascript and echo?
Thanks for anyone who picks through this crap.
JC
Comment