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,30 +52,42 @@ class ZipFolder {
52 52
53 /** 53 /**
54 * Constructor 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 $this->oKTConfig =& KTConfig::getSingleton(); 60 $this->oKTConfig =& KTConfig::getSingleton();
58 $this->oStorage =& KTStorageManagerUtil::getSingleton(); 61 $this->oStorage =& KTStorageManagerUtil::getSingleton();
59 62
60 $this->sOutputEncoding = $this->oKTConfig->get('export/encoding', 'UTF-8'); 63 $this->sOutputEncoding = $this->oKTConfig->get('export/encoding', 'UTF-8');
61 - 64 +
62 $this->sPattern = "[\*|\%|\\\|\/|\<|\>|\+|\:|\?|\||\'|\"]"; 65 $this->sPattern = "[\*|\%|\\\|\/|\<|\>|\+|\:|\?|\||\'|\"]";
63 $this->sFolderPattern = "[\*|\%|\<|\>|\+|\:|\?|\||\'|\"]"; 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 $sZipFileName = 'kt_zip'; 85 $sZipFileName = 'kt_zip';
73 86
74 $this->sTmpPath = $sTmpPath; 87 $this->sTmpPath = $sTmpPath;
75 $this->sZipFileName = $sZipFileName; 88 $this->sZipFileName = $sZipFileName;
76 $this->aPaths = array(); 89 $this->aPaths = array();
77 90
78 -  
79 $aReplace = array( 91 $aReplace = array(
80 "[" => "[[]", 92 "[" => "[[]",
81 " " => "[ ]", 93 " " => "[ ]",
@@ -182,8 +194,8 @@ class ZipFolder { @@ -182,8 +194,8 @@ class ZipFolder {
182 putenv("LANG=$loc"); 194 putenv("LANG=$loc");
183 putenv("LANGUAGE=$loc"); 195 putenv("LANGUAGE=$loc");
184 $loc = setlocale(LC_ALL, $loc); 196 $loc = setlocale(LC_ALL, $loc);
185 -  
186 - 197 +
  198 +
187 199
188 $sManifest = sprintf("%s/%s", $this->sTmpPath, "MANIFEST"); 200 $sManifest = sprintf("%s/%s", $this->sTmpPath, "MANIFEST");
189 file_put_contents($sManifest, join("\n", $this->aPaths)); 201 file_put_contents($sManifest, join("\n", $this->aPaths));
@@ -193,7 +205,7 @@ class ZipFolder { @@ -193,7 +205,7 @@ class ZipFolder {
193 $aCmd = array($sZipCommand, "-r", $sZipFile, ".", "-i@MANIFEST"); 205 $aCmd = array($sZipCommand, "-r", $sZipFile, ".", "-i@MANIFEST");
194 $sOldPath = getcwd(); 206 $sOldPath = getcwd();
195 chdir($this->sTmpPath); 207 chdir($this->sTmpPath);
196 - 208 +
197 // Note that the popen means that pexec will return a file descriptor 209 // Note that the popen means that pexec will return a file descriptor
198 $aOptions = array('popen' => 'r'); 210 $aOptions = array('popen' => 'r');
199 $fh = KTUtil::pexec($aCmd, $aOptions); 211 $fh = KTUtil::pexec($aCmd, $aOptions);
@@ -222,10 +234,10 @@ class ZipFolder { @@ -222,10 +234,10 @@ class ZipFolder {
222 $sExportCode = KTUtil::randomString(); 234 $sExportCode = KTUtil::randomString();
223 $_SESSION['zipcompression'][$sExportCode] = array( 235 $_SESSION['zipcompression'][$sExportCode] = array(
224 'file' => $sZipFile, 236 'file' => $sZipFile,
225 - 'dir' => $this->oZip->sTmpPath, 237 + 'dir' => $this->sTmpPath,
226 ); 238 );
227 $_SESSION['zipcompression']['exportcode'] = $sExportCode; 239 $_SESSION['zipcompression']['exportcode'] = $sExportCode;
228 - 240 +
229 $this->sZipFile = $sZipFile; 241 $this->sZipFile = $sZipFile;
230 return $sExportCode; 242 return $sExportCode;
231 } 243 }
@@ -251,7 +263,7 @@ class ZipFolder { @@ -251,7 +263,7 @@ class ZipFolder {
251 if (!file_exists($sZipFile)) { 263 if (!file_exists($sZipFile)) {
252 return PEAR::raiseError(_kt('The ZIP file can only be downloaded once - if you cancel the download, you will need to reload the page.')); 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 header("Content-Type: application/zip; charset=utf-8"); 267 header("Content-Type: application/zip; charset=utf-8");
256 header("Content-Length: ". filesize($sZipFile)); 268 header("Content-Length: ". filesize($sZipFile));
257 header("Content-Disposition: attachment; filename=\"" . $this->sZipFileName . ".zip" . "\""); 269 header("Content-Disposition: attachment; filename=\"" . $this->sZipFileName . ".zip" . "\"");
@@ -259,8 +271,7 @@ class ZipFolder { @@ -259,8 +271,7 @@ class ZipFolder {
259 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 271 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
260 header("Cache-Control: must-revalidate"); 272 header("Cache-Control: must-revalidate");
261 readfile($sZipFile); 273 readfile($sZipFile);
262 - $sTmpDir = $sTmpPath;  
263 - KTUtil::deleteDirectory($sTmpDir); 274 + KTUtil::deleteDirectory($sTmpPath);
264 return true; 275 return true;
265 } 276 }
266 277
plugins/ktcore/KTBulkActions.php
@@ -719,7 +719,7 @@ class KTBrowseBulkExportAction extends KTBulkAction { @@ -719,7 +719,7 @@ class KTBrowseBulkExportAction extends KTBulkAction {
719 $sCode = $this->oValidator->validateString($_REQUEST['exportcode']); 719 $sCode = $this->oValidator->validateString($_REQUEST['exportcode']);
720 720
721 $folderName = $this->oFolder->getName(); 721 $folderName = $this->oFolder->getName();
722 - $this->oZip = new ZipFolder($folderName); 722 + $this->oZip = new ZipFolder($folderName, $sCode);
723 723
724 $res = $this->oZip->downloadZipFile($sCode); 724 $res = $this->oZip->downloadZipFile($sCode);
725 725