Ejemplo n.º 1
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.º 2
0
 function zip()
 {
     global $dir;
     if (!MRights::can("zip")) {
         $this->view->authError("zip");
         return;
     }
     $zipName = MRequest::clean("zipname", null);
     $zipName = stripEnd(".zip", $zipName);
     $zipName = stripEnd(".ZIP", $zipName);
     if ($zipName) {
         $zipName .= ".zip";
     } else {
         $zipName = "archive_" . date("Y-m-d-H-i") . ".zip";
     }
     $archive = new PclZip(_FM_TMP_DIR . DS . $zipName);
     $selectedFiles = $_REQUEST["selectedFiles"];
     $error = null;
     $status = $archive->add($dir, PCLZIP_OPT_REMOVE_PATH, $dir);
     if (file_exists($dir . DS . $zipName)) {
         $error = MText::_("archive_exists");
         MFile::remove(_FM_TMP_DIR . DS . $zipName);
     } else {
         MFile::move(_FM_TMP_DIR . DS . $zipName, $dir);
     }
     foreach ($status as $item) {
         if ($item['status'] != "ok" && $item['status'] != "filtered") {
             $error .= ' - <b>' . $item['stored_filename'] . ":</b> " . MText::_($item['status']) . '<br>';
         }
     }
     if ($error) {
         $this->view->add2Content("_fmError" . $error);
     } else {
         $this->view->add2Content("ok");
     }
 }
Ejemplo n.º 3
0
 function remove()
 {
     if (!MRights::can("deletefile")) {
         $this->popupError("deletefile");
         return;
     }
     $this->view->add2Content('<div style="display:none;">' . md5(uniqid()) . '</div>');
     $selectedFiles = $_REQUEST["selectedFiles"];
     $error = null;
     foreach ($selectedFiles as $selectedFile) {
         $selectedFile = _START_FOLDER . urldecode($selectedFile);
         $selectedFile = MValidate::path($selectedFile);
         $info = MFile::info($selectedFile);
         if ($info->isWritable) {
             MFile::remove($selectedFile);
         } else {
             $error .= MText::_("file") . ": <b>" . $info->baseName . "</b> " . MText::_("is_wp") . "<br>";
         }
     }
     if ($error) {
         $this->view->add2Content('<script noCache="1">newDarkenPopup(\'error\',mText.error,\'' . $error . '\',500,250);</script>');
     }
     $this->view->add2Content(fmGetFiles());
 }
Ejemplo n.º 4
0
 function deleterootfolder()
 {
     $id = MRequest::int("id", -1);
     if ($id > -1) {
         $roots = MRoots::getInstance();
         $before = "ID: " . $id . "<br>" . $roots;
         if ($roots->get($id) !== false) {
             $roots->delete($id);
             if (!_FM_IS_DEMO) {
                 $roots->save();
             }
             if (MFile::is(_FM_HOME_DIR . DS . "data" . DS . "rights" . DS . "rf" . $id . ".php")) {
                 MFile::remove(_FM_HOME_DIR . DS . "data" . DS . "rights" . DS . "rf" . $id . ".php", 1);
             }
         }
     }
     $demoAdvice = _FM_IS_DEMO ? MSaved::url() : '';
     MPeer::redirect(MURL::_("rootsandrights", null, null) . $demoAdvice);
 }
Ejemplo n.º 5
0
 public function xhr()
 {
     if (!MRights::can("upload")) {
         return $this->view->authError("upload");
     }
     global $dir;
     $size = MRequest::int("size", null);
     if ($size === null) {
         return;
     }
     // 		print_r($_SERVER); die();
     $fn = isset($_SERVER['HTTP_X_FILENAME']) ? MRequest::filter($_SERVER['HTTP_X_FILENAME'], MREQUEST_STRING) : false;
     if (!$fn) {
         return null;
     }
     $fileName = $dir . DS . $fn;
     file_put_contents($fileName, file_get_contents('php://input'));
     // Delete on abbort
     if (MFile::getSize($fileName) != $size) {
         MFile::remove($fileName);
     }
     $this->view->add2Content("ok");
 }
Ejemplo n.º 6
0
 public static function remove($fileName, $atAllCosts = false, $secondAttempt = false)
 {
     if (self::isDir($fileName)) {
         return $atAllCosts ? self::removeDirAtAllCosts($fileName) : self::removeDir($fileName);
     }
     if (!($return = unlink($fileName))) {
         if ($atAllCosts && !$secondAttempt) {
             MFile::chmod($fileName, 0777);
             MFile::remove($fileName, true, true);
         }
     }
     return $return;
 }