Commit 20fdeea8d95de16ae162a99b6324186cd74b5ad6

Authored by megan_w
1 parent 3cfd1245

KTS-3384

"CLONE -How-To restrict "export" (SUP-841)"
In Progress. Fixed the cleanup of the tmp files.

Committed by: Megan Watson
Reviewed by: Conrad Vermeulen




git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/branches/3.5.2c-Release-Branch@8514 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/foldermanagement/compressionArchiveUtil.inc.php
... ... @@ -52,30 +52,42 @@ class ZipFolder {
52 52  
53 53 /**
54 54 * Constructor
  55 + *
  56 + * @param string $sZipFileName The name of the zip file - gets ignored at the moment.
  57 + * @param string $exportCode The code to use if a zip file has already been created.
55 58 */
56   - function ZipFolder($sZipFileName) {
  59 + function ZipFolder($sZipFileName, $exportCode = null) {
57 60 $this->oKTConfig =& KTConfig::getSingleton();
58 61 $this->oStorage =& KTStorageManagerUtil::getSingleton();
59 62  
60 63 $this->sOutputEncoding = $this->oKTConfig->get('export/encoding', 'UTF-8');
61   -
  64 +
62 65 $this->sPattern = "[\*|\%|\\\|\/|\<|\>|\+|\:|\?|\||\'|\"]";
63 66 $this->sFolderPattern = "[\*|\%|\<|\>|\+|\:|\?|\||\'|\"]";
64 67  
65   - $sBasedir = $this->oKTConfig->get("urls/tmpDirectory");
66   - $sTmpPath = tempnam($sBasedir, 'kt_compress_zip');
  68 + // If the export code exists then a temp zip directory has already been created
  69 + if(!empty($exportCode)){
  70 + $aData = KTUtil::arrayGet($_SESSION['zipcompression'], $exportCode);
  71 +
  72 + if(!empty($aData)){
  73 + $sTmpPath = $aData['dir'];
  74 + }
  75 + }else {
  76 + $sBasedir = $this->oKTConfig->get("urls/tmpDirectory");
  77 + $sTmpPath = tempnam($sBasedir, 'kt_compress_zip');
  78 +
  79 + unlink($sTmpPath);
  80 + mkdir($sTmpPath, 0755);
  81 + }
67 82  
68   - unlink($sTmpPath);
69   - mkdir($sTmpPath, 0700);
70   -
71   - // Hard coding the zip file name - else it doesn't download properly
  83 + // Hard coding the zip file name.
  84 + // It normally uses the folder name but if there are special characters in the name then it doesn't download properly.
72 85 $sZipFileName = 'kt_zip';
73 86  
74 87 $this->sTmpPath = $sTmpPath;
75 88 $this->sZipFileName = $sZipFileName;
76 89 $this->aPaths = array();
77 90  
78   -
79 91 $aReplace = array(
80 92 "[" => "[[]",
81 93 " " => "[ ]",
... ... @@ -182,8 +194,8 @@ class ZipFolder {
182 194 putenv("LANG=$loc");
183 195 putenv("LANGUAGE=$loc");
184 196 $loc = setlocale(LC_ALL, $loc);
185   -
186   -
  197 +
  198 +
187 199  
188 200 $sManifest = sprintf("%s/%s", $this->sTmpPath, "MANIFEST");
189 201 file_put_contents($sManifest, join("\n", $this->aPaths));
... ... @@ -193,7 +205,7 @@ class ZipFolder {
193 205 $aCmd = array($sZipCommand, "-r", $sZipFile, ".", "-i@MANIFEST");
194 206 $sOldPath = getcwd();
195 207 chdir($this->sTmpPath);
196   -
  208 +
197 209 // Note that the popen means that pexec will return a file descriptor
198 210 $aOptions = array('popen' => 'r');
199 211 $fh = KTUtil::pexec($aCmd, $aOptions);
... ... @@ -222,10 +234,10 @@ class ZipFolder {
222 234 $sExportCode = KTUtil::randomString();
223 235 $_SESSION['zipcompression'][$sExportCode] = array(
224 236 'file' => $sZipFile,
225   - 'dir' => $this->oZip->sTmpPath,
  237 + 'dir' => $this->sTmpPath,
226 238 );
227 239 $_SESSION['zipcompression']['exportcode'] = $sExportCode;
228   -
  240 +
229 241 $this->sZipFile = $sZipFile;
230 242 return $sExportCode;
231 243 }
... ... @@ -251,7 +263,7 @@ class ZipFolder {
251 263 if (!file_exists($sZipFile)) {
252 264 return PEAR::raiseError(_kt('The ZIP file can only be downloaded once - if you cancel the download, you will need to reload the page.'));
253 265 }
254   -
  266 +
255 267 header("Content-Type: application/zip; charset=utf-8");
256 268 header("Content-Length: ". filesize($sZipFile));
257 269 header("Content-Disposition: attachment; filename=\"" . $this->sZipFileName . ".zip" . "\"");
... ... @@ -259,8 +271,7 @@ class ZipFolder {
259 271 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
260 272 header("Cache-Control: must-revalidate");
261 273 readfile($sZipFile);
262   - $sTmpDir = $sTmpPath;
263   - KTUtil::deleteDirectory($sTmpDir);
  274 + KTUtil::deleteDirectory($sTmpPath);
264 275 return true;
265 276 }
266 277  
... ...
plugins/ktcore/KTBulkActions.php
... ... @@ -719,7 +719,7 @@ class KTBrowseBulkExportAction extends KTBulkAction {
719 719 $sCode = $this->oValidator->validateString($_REQUEST['exportcode']);
720 720  
721 721 $folderName = $this->oFolder->getName();
722   - $this->oZip = new ZipFolder($folderName);
  722 + $this->oZip = new ZipFolder($folderName, $sCode);
723 723  
724 724 $res = $this->oZip->downloadZipFile($sCode);
725 725  
... ...