Ejemplo n.º 1
0
 function copy()
 {
     global $destination;
     if (!MRights::can("copy")) {
         $this->popupError("copy");
         return;
     }
     $this->view->add2Content('<div style="display:none;">' . md5(uniqid()) . '</div>');
     $selectedFiles = $_REQUEST["selectedFiles"];
     $error = null;
     foreach ($selectedFiles as $selectedFile) {
         $basePath = $selectedFile;
         $selectedFile = _START_FOLDER . urldecode($selectedFile);
         $selectedFile = MValidate::path($selectedFile);
         $pi = pathinfo($selectedFile);
         $destinationFile = $destination . DS . $pi["basename"];
         if (file_exists($destinationFile)) {
             $error .= MText::_("file") . " <b>" . $pi["basename"] . "</b> " . MText::_("already_exists") . "<br>";
         } else {
             if (MFile::isDir($selectedFile)) {
                 $error .= MText::_("folder") . " <b>" . $basePath . "</b> " . MText::_("nofoldercopy") . "<br>";
             } else {
                 MFile::copy($selectedFile, $destinationFile);
             }
         }
     }
     if ($error) {
         $this->view->add2Content('<script noCache="1">newDarkenPopup(\'error\',mText.error,\'' . $error . '\',500,250);</script>');
     }
     $this->view->add2Content(fmGetFiles());
 }
Ejemplo n.º 2
0
	public static function liveTests(){
		// Set Sandbox to be writable if possible
		@MFile::chmod(_FM_SANDBOX, 755);
		if( ! MFile::isWritable(_FM_SANDBOX)){
			self::$sandboxError = 1;
			return false;
		}
		
		$assets = _FM_SANDBOX .DS . "assets" ;
		$fileSample = _FM_SANDBOX .DS . "assets" . DS ."sample.txt";
		$fileValidate = _FM_SANDBOX .DS . "assets" . DS ."validate.txt";
		$destinationFolder = _FM_SANDBOX . DS . "dest";
		// 1. isDir
		self::$params["live_is_dir"] = (int) @MFile::isDir($assets);
		
		// 2. isFile
		self::$params["live_is_file"] = (int) @MFile::isFile($fileSample);
		
		// 3. Create Dir 
		MFile::createDir($destinationFolder, 0755);
		self::$params["live_create_dir"] = (int) ( @MFile::is($destinationFolder) && @MFile::isDir($destinationFolder));
		
		// 4. Read
		$valid = MFile::readData($fileValidate);
		self::$params["live_read_file"] = (int) $valid == "valid";
		
		// 5. Copy
		MFile::copy($fileValidate, $destinationFolder . DS . basename($fileValidate));
// 		MFile::copy($fileValidate, _FM_SANDBOX . DS . "reserved.txt");
		self::$params["live_copy"] = (int) MFile::is($destinationFolder . DS . basename($fileValidate));
		
		// 6. Rename
		$newValidate = $destinationFolder . DS .  "deleteme.txt";
		MFile::rename($destinationFolder . DS . basename($fileValidate), $newValidate);
		self::$params["live_rename"] = (int) MFile::is($newValidate);
		
		// 7. mode read
		@MFile::chmod($newValidate, 444);
		$mode = MFile::mode($newValidate);
		self::$params["live_mode"] = (int)  (!! $mode);
		
		// 8. CHMOD
		MFile::chmod($newValidate, 666);
		self::$params["live_chmod"] =  (int) ( $mode != MFile::mode($newValidate) );
		
		// 9. Write (Create / Add File)
		MFile::writeData($newValidate,"new",true);
		$validnew = MFile::readData($newValidate);
		self::$params["live_write_file"] = (int) $validnew == "validnew";
		
		// 10. Pack
		$archive = new PclZip(_FM_SANDBOX. DS . 'packed.zip');
		$archive->add($destinationFolder,PCLZIP_OPT_REMOVE_PATH, $destinationFolder);
		self::$params["live_zip"] = (int) MFile::is(_FM_SANDBOX. DS . 'packed.zip');
		
		// 11. Delete File
		MFile::remove($newValidate, 1);
		self::$params["live_delete_file"] = (int) ! MFile::is($newValidate);
		
		// 12. Delete Folder
		MFile::removeDir($destinationFolder);
		self::$params["live_delete_folder"] = (int) ! MFile::is($destinationFolder);
		
		// 13. UNZIP
		$archive = new PclZip(_FM_SANDBOX. DS . 'packed.zip');
		$archive->extract(PCLZIP_OPT_PATH, _FM_SANDBOX);
		self::$params["live_unzip"] = (int) MFile::is(_FM_SANDBOX. DS . 'deleteme.txt');
		
		// 14. Move
		MFile::createDir($destinationFolder, 0777);
		MFile::move(_FM_SANDBOX. DS . 'deleteme.txt', $destinationFolder);
		self::$params["live_move"] = (int) MFile::is($newValidate);
		
		
		// Purge
		MFile::remove(_FM_SANDBOX. DS . 'packed.zip', 1);
		MFile::removeDirAtAllCosts($destinationFolder);
		
		
		
	}
Ejemplo n.º 3
0
 public static function extract($archivename, $extractdir)
 {
     mimport('framework.filesystem.file');
     mimport('framework.filesystem.folder');
     $untar = false;
     $result = false;
     $ext = MFile::getExt(strtolower($archivename));
     // Check if a tar is embedded...gzip/bzip2 can just be plain files!
     if (MFile::getExt(MFile::stripExt(strtolower($archivename))) == 'tar') {
         $untar = true;
     }
     switch ($ext) {
         case 'zip':
             $adapter = MArchive::getAdapter('zip');
             if ($adapter) {
                 $result = $adapter->extract($archivename, $extractdir);
             }
             break;
         case 'tar':
             $adapter = MArchive::getAdapter('tar');
             if ($adapter) {
                 $result = $adapter->extract($archivename, $extractdir);
             }
             break;
         case 'tgz':
             // This format is a tarball gzip'd
             $untar = true;
         case 'gz':
         case 'gzip':
             // This may just be an individual file (e.g. sql script)
             $adapter = MArchive::getAdapter('gzip');
             if ($adapter) {
                 $config = MFactory::getConfig();
                 $tmpfname = $config->get('tmp_path') . '/' . uniqid('gzip');
                 $gzresult = $adapter->extract($archivename, $tmpfname);
                 if ($gzresult instanceof Exception) {
                     @unlink($tmpfname);
                     return false;
                 }
                 if ($untar) {
                     // Try to untar the file
                     $tadapter = MArchive::getAdapter('tar');
                     if ($tadapter) {
                         $result = $tadapter->extract($tmpfname, $extractdir);
                     }
                 } else {
                     $path = MPath::clean($extractdir);
                     MFolder::create($path);
                     $result = MFile::copy($tmpfname, $path . '/' . MFile::stripExt(MFile::getName(strtolower($archivename))), null, 1);
                 }
                 @unlink($tmpfname);
             }
             break;
         case 'tbz2':
             // This format is a tarball bzip2'd
             $untar = true;
         case 'bz2':
         case 'bzip2':
             // This may just be an individual file (e.g. sql script)
             $adapter = MArchive::getAdapter('bzip2');
             if ($adapter) {
                 $config = MFactory::getConfig();
                 $tmpfname = $config->get('tmp_path') . '/' . uniqid('bzip2');
                 $bzresult = $adapter->extract($archivename, $tmpfname);
                 if ($bzresult instanceof Exception) {
                     @unlink($tmpfname);
                     return false;
                 }
                 if ($untar) {
                     // Try to untar the file
                     $tadapter = MArchive::getAdapter('tar');
                     if ($tadapter) {
                         $result = $tadapter->extract($tmpfname, $extractdir);
                     }
                 } else {
                     $path = MPath::clean($extractdir);
                     MFolder::create($path);
                     $result = MFile::copy($tmpfname, $path . '/' . MFile::stripExt(MFile::getName(strtolower($archivename))), null, 1);
                 }
                 @unlink($tmpfname);
             }
             break;
         default:
             MError::raiseWarning(10, MText::_('MLIB_FILESYSTEM_UNKNOWNARCHIVETYPE'));
             return false;
             break;
     }
     if (!$result || $result instanceof Exception) {
         return false;
     }
     return true;
 }