function accept() { list($files, $ids) = $this->_getFilesAndIds($this->_accepts); parent::setLogStatus($ids, 'accepted'); parent::removeFromFilesystemTable($files); $this->_accepts = array(); return true; }
/** * @static * @param unknown_type $type * @return JD_Action instance :0 */ function &getInstance($type = null) { static $instances = array(); if (empty($type)) { return $instances; } $type = JFolder::makeSafe($type); if (empty($instances[$type])) { JD_Action::_loadActions(); $className = 'JD_' . $type . '_Action'; if (class_exists($className)) { $instances[$type] = new $className(); } else { JError::raiseWarning(0, JText::_('Cannot instanciate action class') . ': ' . 'jd_' . $type . '_action'); return null; } } return $instances[$type]; }
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); }
/** * Factory method: Get the action * @param string $type * @return JD_Action the action */ function &_getAction($type) { $action =& JD_Action::getInstance($type); return $action; }
/** * Assumes that log records 'issue' field contains key=value that can be used for creating rules. * @return int number of succesfully added exceptions */ function makeException() { $ids = array(); foreach ($this->_exceptions as $k => $item) { if (is_numeric($item)) { $ids[] = $item; } } $logModel =& JModel::getInstance('Log', 'JDefenderModel'); $logModel->setState('id', $ids); $records = $logModel->getData(); if (empty($records)) { $records = array(); } // Add exception rules $row =& JTable::getInstance('Rule', 'Table'); $fixedIds = array(); foreach ($records as $rec) { $vars = explode("=", $rec->issue); $extension = explode('::', $rec->extension); if (2 != count($vars)) { continue; } $row->id = null; $row->rule = $vars[0]; // The key $row->family = $log->type; $row->type = 'none'; $row->action = 'ignore'; $row->published = 1; $row->component = @$extension[0] == 'component' ? @$extension[2] : '*'; if ($row->check() && $row->store()) { $fixedIds[] = $rec->id; } else { $this->setError($row->getError()); } } parent::setLogStatus($fixedIds, 'added_to_exceptions'); $this->_exceptions = array(); return count($fixedIds); }
function __construct() { parent::__construct(); }
/** * This method can receive both single integer value, and an array */ function _getAction() { global $mainframe; JRequest::checkToken() or die('Invalid token'); $logId = JRequest::getInt('id'); $logIds = JRequest::getVar('cid', array(), 'default', 'array'); if (!empty($logIds)) { JArrayHelper::toInteger($logIds); $logId = reset($logIds); } else { $logIds = array($logId); } // Check the log $logRecord =& JTable::getInstance('Log', 'Table'); if (!$logRecord->load($logId)) { JError::raiseError(404, JText::_('Cannot find log')); return false; } $action =& JD_Action::getInstance($logRecord->type); if (empty($action)) { JError::raiseError(404, JText::_('Cannot find action for type') . ': ' . $logRecord->type); return array(false, false); } return array(&$action, $logIds); }