public static function storeUploadedFile($filename, $release, $target, $userid = 0, &$warnings = null) { $output = ""; if (!file_exists($filename)) { return "Could not find uploaded package file"; } //Check if release is not in production $state = $release->getCommRepoState()->name; if (strtolower($state) === "production") { return "Current release is in production. No uploads are permitted"; } //Check if file type can be managed $ftype = self::getFileType($filename); if ($ftype === false) { return "Unsupported file type"; } //Check if file type is valid for the specified target if (self::isSupportedArtifactType($target, $ftype) === false) { return "File type " . $ftype . " is not supported for this release"; } //Retrieve package information to check architecture $info = true; //in case of generic tar packages if ($ftype == "rpm") { $info = RepositoryPackage::getRpmInfo($filename); } else { if ($ftype == "deb") { $info = RepositoryPackage::getDebInfo($filename); } else { if ($ftype == "gzip") { $info = RepositoryPackage::getGzipInfo($filename); } } } if ($info === false || count($info) === 0) { return "Cannot retrieve " . $ftype . " package information"; } $fileexists = RepositoryFS::fileExists(basename($filename), $release, $target, $release->getSoftwareId(), $info["type"]); if ($fileexists == true) { return "File with the same name already uploaded for this release"; } //Retrieve or create POA release $poa = Repository::createPoa($release, $target, $userid, $output); if ($poa === false) { return $output; } $poaid = $poa->id; //retriev destination path $storagepath = RepositoryFS::getStoragePath($error); $storagepath = $storagepath === false ? "" : $storagepath; $poapath = RepositoryFS::getDatabankForPoa($poa, $release->getSoftwareId(), $output, true); if ($poapath === false) { $info["pkgfilepath"] = ""; } else { $poarelpath = str_replace($storagepath, "", $poapath); $info["pkgfilepath"] = $poarelpath . $info["type"] . DIRECTORY_SEPARATOR; $poa->poaPath = $info["pkgfilepath"]; $poa->save(); } //Check if file already exists in POA release $exists = Repository::hasPOAPackage($poaid, $info); if ($exists === false) { //Save POA Release package $pkg = Repository::createPoaPackage($poaid, $info, $userid, $output); //Calculate package version indexing upon package creation success if ($pkg !== false) { RepositoryBackend::calculatePackageVersionIndex($pkg); } } else { //Update POA release package $pkg = Repository::updatePoaPackage($exists, $info, $output); } if ($pkg === false) { return $output; } //move POA Release package to databank RepositoryFS::makePath($poapath . $info["type"] . DIRECTORY_SEPARATOR); if (copy($filename, $storagepath . $info["pkgfilepath"] . $info["filename"])) { unlink($filename); } $archname = $target->getArch()->name; $archname = strtolower($archname); return $pkg->id; }
public function downloadAction() { ini_set("zlib.output_compression", "off"); ob_clean(); ob_get_clean(); $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $id = $this->_getParam("id"); if ($_SERVER["Repository_Enabled"] !== 'true' || is_numeric($id) == false || $_SERVER['REQUEST_METHOD'] != "GET") { header("Status: 404 Not Found"); return; } $mime = "application/octet-stream"; $url = RepositoryFS::getPackageDatabankUrl($id, $mime); if ($url === false || file_exists($url) === false) { header("Status: 404 Not Found"); return; } $filename = basename($url); ob_start(); ob_get_clean(); header('Content-Description: File Transfer'); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); header("Expires: 0"); header("Content-type: " . $mime); header("Content-length: " . filesize($url)); header("Content-Transfer-Encoding: binary"); header("Content-disposition: attachement;filename=\"" . urlencode($filename) . "\""); ob_clean(); flush(); $file = @fopen($url, 'rb'); if ($file) { @fpassthru($file); } exit; }