function fix() { if (empty($this->_fixes)) { return 0; } list($files, $ids) = $this->_getFilesAndIds($this->_fixes); $config =& $this->getConfig(); $filePerms = intval($config->get('permission_max_file_permission', '644'), 8); $dirPerms = intval($config->get('permission_max_dir_permission', '755'), 8); $chmoddedFiles = array(); $rollback = false; @clearstatcache(); foreach ($files as $file) { if (!JFile::exists($file) && !JFolder::exists($file)) { continue; } $info = new stdClass(); $info->perms = fileperms($file); $info->file = $file; $isFile = is_file($file); $isDir = is_dir($file); if ($isFile || $isDir) { $f = new JD_File($file); $perms = $isFile ? $filePerms : $dirPerms; if ($f->chmod($perms) === false) { $this->setError($f->getError()); $rollback = true; break; } } $chmoddedFiles[] = $info; } if ($rollback) { foreach ($chmoddedFiles as $info) { $f = new JD_File($info->file); $f->chmod($info->perms); } $this->_fixes = array(); return false; } parent::setLogStatus($ids, 'fixed'); parent::refreshFilesystemTable($files); $this->_fixes = array(); return count($chmoddedFiles); }
/** * Reverts file to it's initial state. */ function fix() { if (empty($this->_fixes)) { return 0; } list($files, $ids) = $this->_getFilesAndIds($this->_fixes); $count = 0; $fixedFiles = array(); $fixedIds = array(); // now, fix the files. foreach ($files as $id => $file) { if (JFile::exists($file)) { $row =& JTable::getInstance('Filesystem', 'Table'); if (!$row->loadByFilename($file)) { $this->setError(JText::_('Cannot load filesystem data') . ': ' . $file); continue; } $f = new JD_File($file); if (!$f->write($row->contents)) { $this->setError($f->getError()); continue; } if ($row->permission) { if (!$f->chmod($row->permission)) { $this->setError($f->getError()); continue; } } $fixedFiles[] = $file; if (strpos($id, ':')) { $realId = explode(':', $id); $realId = $realId[1]; $fixedIds[] = (int) $realId; } $count++; } } parent::setLogStatus($fixedIds, 'reverted'); parent::refreshFilesystemTable($fixedFiles); // Empty array $this->_fixes = array(); return $count; }
/** * Check, whether we can chmod the path * @param string $path * @return boolean */ function canChmod($path = false) { if ($path == false) { $path = $this->_filename; } $perms = @fileperms($path); if ($perms !== false) { $f = new JD_File($path); if ($f->chmod($path, $perms ^ 01)) { $f->chmod($path, $perms); return true; } } return false; }