//====================================================================================
// OCS INVENTORY REPORTS
// Copyleft Pierre LEMMET 2006
// Web: http://ocsinventory.sourceforge.net
//
// This code is open source and may be copied and modified as long as the source
// code is always made freely available.
// Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
//====================================================================================
//Modified on 08/01/2006
?>
set_time_limit(0);
printEnTete($l->g(434));
if( isset($_POST["nom"]) ) {
$verifN = "SELECT fileid FROM download_available WHERE name='".$_POST["nom"]."'";
$resN = mysql_query( $verifN, $_SESSION["readServer"] ) or die(mysql_error());
if( mysql_num_rows( $resN ) == 0 ) {
$fSize = @filesize( $_FILES["fichier"]["tmp_name"]);
if( $fSize <= 0 && ! $_POST["command"]) {
echo "";
die("");
}
foreach( $_POST as $key=>$val ) {
$_POST[ $key ] = stripslashes( $val );
$_SESSION[ "down_" . $key ] = stripslashes( $val );
}
foreach( $_FILES["fichier"] as $key=>$val )
$_SESSION[ "down_" . $key ] = $val;
if( $fSize ) {
$size = $_FILES["fichier"]["size"];
$id = time();
if( $_POST["digest_algo"] == "SHA1" )
$digest = sha1_file($_FILES["fichier"]["tmp_name"],true);
else
$digest = md5_file($_FILES["fichier"]["tmp_name"]);
if( $_POST["digest_encod"] == "Base64" )
$digest = base64_encode( $digest );
$digName = $_POST["digest_algo"]. " / ".$_POST["digest_encod"];
if( ! @mkdir( $_SERVER["DOCUMENT_ROOT"]."/download/".$id)) {
echo "
ERROR: can't write in ".$_SERVER["DOCUMENT_ROOT"]."/download/ folder, please refresh when corrected";
die("");
}
//TODO: catcher
copy( $_FILES["fichier"]["tmp_name"], $_SERVER["DOCUMENT_ROOT"]."/download/".$id."/tmp" );
?>
if( round($size) > 1024 ) { ?>
}
die("");
}
else {
$id = time();
if( ! @mkdir( $_SERVER["DOCUMENT_ROOT"]."/download/".$id)) {
echo "ERROR: can't write in ".$_SERVER["DOCUMENT_ROOT"]."/download/ folder, please refresh when corrected";
die("");
}
?>
flush();
die("");
}
}
else {
echo "
".$l->g(551)."";
}
}
else if( isset( $_POST["nbfrags"] ) ) {
//fragmenter
$fname = $_SERVER["DOCUMENT_ROOT"]."/download/".$_POST["id"]."/tmp";
if( $size = @filesize( $fname )) {
$handle = fopen ( $fname, "rb");
$read = 0;
for( $i=1; $i<$_POST["nbfrags"]; $i++ ) {
$contents = fread ($handle, $size / $_POST["nbfrags"] );
$read += strlen( $contents );
$handfrag = fopen( $_SERVER["DOCUMENT_ROOT"]."/download/".$_POST["id"]."/".$_POST["id"]."-".$i, "w+b" );
fwrite( $handfrag, $contents );
fclose( $handfrag );
//echo "FRAG ".$i." lu ".strlen( $contents ). " (en tout " .$read.")
";
}
$contents = fread ($handle, $size - $read);
$read += strlen( $contents );
$handfrag = fopen( $_SERVER["DOCUMENT_ROOT"]."/download/".$_POST["id"]."/".$_POST["id"]."-".$i, "w+b" );
fwrite( $handfrag, $contents );
fclose( $handfrag );
fclose ($handle);
unlink( $_SERVER["DOCUMENT_ROOT"]."/download/".$_POST["id"]."/tmp" );
}
//creation info
$info = "\n";
$handinfo = fopen( $_SERVER["DOCUMENT_ROOT"]."/download/".$_POST["id"]."/info", "w+" );
fwrite( $handinfo, $info );
fclose( $handinfo );
mysql_query( "DELETE FROM download_available WHERE FILEID='".$_POST["id"]."'", $_SESSION["writeServer"]);
$req = "INSERT INTO download_available(FILEID, NAME, PRIORITY, FRAGMENTS, SIZE, OSNAME, COMMENT) VALUES
( '".$_POST["id"]."', '".addslashes($_SESSION["down_nom"])."','".$_SESSION["down_priority"]."', '".$_POST["nbfrags"]."',
'".$size."', '".$_SESSION["down_os"]."', '' )";
mysql_query( $req, $_SESSION["writeServer"] );
echo mysql_error();
echo "
".$l->g(437)." ".$_SERVER["DOCUMENT_ROOT"]."/download/".$_POST["id"]."
";
unset( $_POST["nbfrags"] );
//vider session
//die();
}
?>