include('user_inc.htm'); include('driveBrick_inc.htm'); define('dirLocation',"/home/embedded/library/UDS/autolevel/"); $diskSpace = disk_free_space("/home/embedded/library/UDS"); error_log("Free Diskspace for Firmware upload is: ". $diskSpace ); if ($_SERVER[REQUEST_METHOD] == "POST") { $operation = $_POST['operation']; // Required to support the operation in progress dialog. $operationInProgress = true; $status = new ReturnStatus(); if( $operation == "upload" ) { $tmp_name = $_FILES['brickUpdate']['tmp_name']; error_log("The drive brick firmware file has been uploaded, verify and find the type."); if( is_uploaded_file($_FILES['brickUpdate']['tmp_name'] )) { if( !file_exists(dirLocation) ) { error_log("Creating directory:".dirLocation); mkdir(dirLocation); } $image_info = get_brick_image_info($user,$tmp_name); error_log("image_info = ". print_r(image_info, true)); //error_log("...Sled image brand:".$image_info->brand); //error_log("...Sled image type:".$image_info->type); //error_log("...Sled image interface type:".$image_info->interface_type); // // insure that images are only uploaded for installed drive types // // build unqiue array of drive types // error_log("getting all drive types for image upload check ..."); $drives = get_all_drives($user, $sortCriteria); $utypes=array(); foreach($drives as $drive) { if( $drive->interfaceType == "Fibre" ) { error_log("===>drive_>vendor = ". $drive->vendor); error_log("===>drive_>driveType = ". $drive->driveType); error_log("===>drive_>interfaceType = ". $drive->interfaceType); error_log("utypes[$drive->vendor][$drive->driveType] = ". $utypes[$drive->vendor][$drive->driveType] ); $utypes[$drive->vendor][$drive->driveType] = $drive->interfaceType; } } $typeExists=FALSE; if( isset($utypes[$image_info->brand]) ) { error_log("\n Brand matched"); if( isset($utypes[$image_info->brand][$typeMap[$image_info->type]][$ifMap[$image_info->interface_type]]) ) { error_log("\n second key exists"); if( $ifMap[$image_info->interface_type] == "Fibre" ) { error_log("\n third match exists"); $typeExists=TRUE; } } } if( !$typeExists ) { error_log("Did not find a drive for this type of image: DISALLOW."); $status->setErrorCode("4608"); print $status->out_complete(); return; } error_log("Found a drive for this type of image: ALLOW."); $fileName=$image_info->brand."_".$image_info->type."_".$image_info->interface_type.".DRV"; $newLocation=dirLocation.$fileName; error_log("New brick image file name:".$newLocation); if(move_uploaded_file($_FILES['brickUpdate']['tmp_name'],$newLocation)) { error_log("file move successful"); } } else { if (is_null($_FILES['brickUpdate']) ) { error_log("The file is too big, brickUpdate is NULL"); $status->setErrorCode("4109"); } else { switch ($HTTP_POST_FILES['brickUpdate']['error']) { case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form error_log("The file you are trying to upload is too big."); $status->setErrorCode("4109"); break; case 3: //uploaded file was only partially uploaded error_log("The file you are trying upload was only partially uploaded."); $status->setErrorCode("4110"); break; case 4: //no file was uploaded error_log("You must select an image for upload."); $status->setErrorCode("4111"); break; default: error_log("There was a problem with your upload."); $status->setErrorCode("4108"); break; } } } } else if( $operation == "remove" ) { error_log("Removing drive brick firmware files"); $removeFiles=$_POST['removeList']; error_log("remove files:".$removeFiles); $removeList=explode(":",$removeFiles); foreach($removeList as $file) { error_log("file: ".$file); error_log("path: ".dirLocation); $removePath=dirLocation.$file; error_log("Removing file: ".$removePath); @unlink($removePath); } error_log("Removing done"); } else { error_log("Unknown operation type!"); } print $status->out_complete(); return; } ?>