function unblockPHP($file) { $f = new JD_File($file); $blockString = '<?php /* ATTENTION!! DEFENDER GENERATED CODE. DO NOT DELETE!! */ return; ?>'; // Try to read file $contents = $f->read(); if ($contents === false) { return JText::_('Cannot unblock file') . ': ' . $f->getError(); } $toWrite = str_replace($blockString, '', $contents); // Try to write if (!$f->write($toWrite)) { return JText::_('Cannot unblock file') . ': ' . $f->getError(); } return true; }
/** * 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; }
function fix() { if (empty($this->_fixes)) { return 0; } list($files, $ids) = $this->_getFilesAndIds($this->_fixes); $newFiles = array(); $rollback = false; foreach ($files as $dir) { if (!is_dir($dir)) { continue; } $indexFile = JPath::clean($dir . DS . 'index.html'); if (JFile::exists($indexFile)) { continue; } $fixFile = new JD_File($indexFile); // Try to write the file if (!$fixFile->write($this->indexHTMLContents)) { $this->setError($fixFile->getError()); $rollback = true; break; } $newFiles[] = $indexFile; } if ($rollback) { foreach ($newFiles as $file) { if (JFile::exists($file)) { JFile::delete($file); } } $this->_fixes = array(); return false; } parent::refreshFilesystemTable($newFiles); parent::setLogStatus($ids, 'fixed'); $this->_fixes = array(); return count($newFiles); }
/** * Fix the missing _JEXEC issue * Note that processed items are removed from buffer * (non-PHPdoc) * @see components/com_jdefender/lib/actions/JD_Action#fix() */ 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. $error = false; foreach ($files as $k => $file) { if (JFile::exists($file)) { $dir = dirname($file); $f = new JD_File($file); $contents = $f->read(); if (!$f->write($this->fixString . $contents)) { $error = true; $this->setError(JText::_('Cannot write to file') . ': ' . $f->getError()); continue; } $fixedFiles[] = $file; if (strpos($k, ':')) { $id = explode(':', $k); $id = $id[1]; $fixedIds[] = $id; } $count++; } } parent::setLogStatus($fixedIds, 'fixed'); parent::refreshFilesystemTable($fixedFiles); // Empty array $this->_fixes = array(); return $error ? false : $count; }