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; }
/** * 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; }
/** * Load properties from a given file properties * * @param $file string The filename to scan * @param $contents boolean Load the contents * @param $loadId boolean Load id from database * @return boolean result */ function loadFromFile($file, $contents = false, $loadId = false) { if (!JFile::exists($file) && !JFolder::exists($file . DS)) { return false; } $info = @stat($file); $this->scandate = $this->_db->getNullDate(); $this->filename = basename($file); $this->fullpath = $file; $this->permission = fileperms($file) & 0777; $this->size = filesize($file); $ctime =& JFactory::getDate($info['ctime']); $mtime =& JFactory::getDate($info['mtime']); $this->ctime = $ctime->toMySQL(); $this->mtime = $mtime->toMySQL(); $this->uid = $info['uid']; $this->gid = $info['gid']; $this->type = ''; if (is_file($file)) { $this->type = 'file'; $this->hash_md = md5_file($file); if ($contents) { $f = new JD_File($file); $this->contents = $f->read(); } } elseif (is_dir($file)) { $this->type = 'dir'; } if ($loadId) { $this->_db->setQuery('SELECT id FROM #__jdefender_filesystem WHERE fullpath = ' . $this->fullpath . ' LIMIT 1'); $this->id = $this->_db->loadResult(); } return true; }
function scanFilesAndDirs($baseDir, $theFiles = false, $theDirs = false) { $session =& JFactory::getSession(); $doLog = $session->get('doLog', false, 'jdefender'); $baseDir = JPath::clean($baseDir); // Remove the trailing slash if (in_array(substr($baseDir, -1), array('/', '\\'))) { $baseDir = substr($baseDir, 0, -1); } $files = array(); $dirs = array(); if ($theFiles !== false) { $files = $theFiles; } else { $files = JFolder::files($baseDir, '.', true, true, array_keys($this->filter->excludedDirs)); } if ($theDirs !== false) { $dirs = $theDirs; } else { $dirs = $this->_listFolders($baseDir, $this->filter->getExcludedDirPregexp(), true, true, array_keys($this->filter->excludedDirs)); } foreach ($files as $file) { $contents = null; if (!$this->filter->isFileOK($file, true)) { continue; } if ($this->isReadFiles()) { $f = new JD_File($file); $contents = $f->read($file); if (false === $contents) { $contents = null; } } $this->trigger('onFile', array($file, &$contents)); $this->_filesScanned++; } if ($doLog) { JD_Vars_Helper::setVar('files', 'jdefender_scan', $this->_filesScanned); } foreach ($dirs as $dir) { if (!$this->filter->isDirOK($dir)) { continue; } $this->trigger('onDir', array(&$dir)); $this->_foldersScanned++; } if ($doLog) { JD_Vars_Helper::setVar('dirs', 'jdefender_scan', $this->_foldersScanned); } }