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); }
function chmod() { if (!MRights::can("chmod")) { $this->popupError("chmod"); return; } $mode = MRequest::int('chmod', null); if (!$mode) { $error = MText::_("no_mode_set"); $this->view->add2Content('<script noCache="1">newDarkenPopup(\'error\',mText.error,\'' . $error . '\',500,250);</script>'); $this->view->add2Content(fmGetFiles()); return false; } $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); $status = MFile::chmod($selectedFile, $mode); if (!$status) { $error .= "File: <b>" . $info->baseName . "</b> " . MText::_("mode_cannot_change") . "<br>"; } } if ($error) { $this->view->add2Content('<script noCache="1">newDarkenPopup(\'error\',mText.error,\'' . $error . '\',500,250);</script>'); } $this->view->add2Content(fmGetFiles()); }
function chmod() { global $dir; if ($dir == _START_FOLDER) { $this->view->add2Content("_fmError" . MText::_("notforroot")); return; } if (!MRights::can("chmod")) { $this->view->authError("chmod"); return; } $mode = MRequest::int('chmod', null); if (!$mode) { $this->view->add2Content("_fmError"); return null; } $status = MFile::chmod($dir, $mode); if (!$status) { $this->view->add2Content("_fmError"); } else { $this->view->add2Content(fmGetFinfo($dir)); } }
public static function action($name, $action, $arguments) { if (!file_exists($name)) { return null; } switch ($action) { case 'parseData': return MFile::parseData($name); break; case 'chmod': return MFile::chmod($name, $arguments); break; case 'mode': return MFile::mode($name); break; default: case 'info': return MFile::info($name); break; } }