function save($data)
 {
     foreach ($data as $k => $v) {
         JD_Vars_Helper::setVar($k, 'configuration', $v);
     }
     return true;
 }
Exemple #2
0
 function getSpammer($ip)
 {
     require_once JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_jdefender' . DS . 'helpers' . DS . 'vars.php';
     $long = ip2long(trim($ip));
     if ($long == -1 || $long === false) {
         return false;
     }
     // Get Plugin info
     $params =& JD_Spam_Helper::getParams();
     // get API key
     $key = $params->get('spam_key');
     // without key this plugins has no use.
     if (empty($key)) {
         return false;
     }
     $response = JD_Vars_Helper::getVar($ip, 'spam_cache');
     if (!$response) {
         // Query
         $ip = implode('.', array_reverse(explode('.', $ip)));
         $query = $key . '.' . $ip . '.dnsbl.httpbl.org';
         $response = gethostbyname($query);
         // Did the lookup fail, if so either not listed or error
         if ($query == $response) {
             // rewrite responce so key isn't written to cache file and save precious space.
             $response = '0.0.0.0';
         }
         // store data
         JD_Vars_Helper::setVar($ip, 'spam_cache', $response);
     }
     // explode responce
     $response = explode('.', $response);
     // If the response is positive,
     if ($response[0] == 127) {
         // Get thresholds
         $age = $params->get('spam_age', 30);
         $threat = $params->get('spam_threat', 25);
         $whoToBlock = $params->get('spam_seek', array());
         settype($whoToBlock, 'array');
         // Who to block
         $seek_s = array_search(1, $whoToBlock) !== false ? 1 : 0;
         $seek_h = array_search(2, $whoToBlock) !== false ? 2 : 0;
         $seek_c = array_search(4, $whoToBlock) !== false ? 4 : 0;
         $seek = $seek_s | $seek_h | $seek_c;
         if ($response[1] < $age && $response[2] > $threat && $response[3] & $seek > 0) {
             $spammer = new stdClass();
             $spammer->suspicious = $response[3] & 1;
             $spammer->harvester = $response[3] & 2;
             $spammer->comment_spammer = $response[3] & 4;
             $spammer->age = $response[1];
             $spammer->threat = $response[2];
             $spammer->attacker = $response[3];
             return $spammer;
         }
     }
     return false;
 }
Exemple #3
0
 function purgeVars($type, $minutes = 60)
 {
     $minutes = (int) $minutes;
     $db =& JFactory::getDBO();
     $q = 'DELETE FROM #__jdefender_vars WHERE `type` = ' . $db->Quote($type);
     if ($minutes) {
         $q .= ' AND `ctime` + INTERVAL ' . $minutes . ' MINUTES < NOW()';
     }
     $db->setQuery($q);
     $db->query();
     $vars =& JD_Vars_Helper::_getVars();
     $vars[$type] = array();
 }
Exemple #4
0
 /**
  * 
  * @param $path
  * @param $doLog
  */
 function getScanData($path = '', $doLog = false)
 {
     $configModel =& JModel::getInstance('Configuration', 'JDefenderModel');
     $params = new JParameter($configModel->getIni());
     JD_Scanner::loadScanner();
     $fsScanner = false;
     if (!$this->getState('filesystem.scanned')) {
         $fsScanner =& JD_Filesystem_Scanner::getInstance();
         $fsScanner->loadValidator();
         // Set the "first scan" flag.
         if ($this->_isFirstScan()) {
             foreach ($fsScanner->listeners as $k => $v) {
                 if (method_exists($v, 'setFirstScan')) {
                     $fsScanner->listeners[$k]->setFirstScan(true);
                 }
             }
         }
         if ($doLog) {
             JD_Vars_Helper::setVar('status', 'jdefender_scan', JText::_('Scanning filesystem'));
         }
         // Run scanners
         if (empty($this->_filesystem_data)) {
             $this->_filesystem_data = $fsScanner->scan($path);
         }
     }
     $optScanner = false;
     if (!$this->getState('options.scanned')) {
         $optScanner =& JD_Options_Scanner::getInstance();
         $optScanner->loadValidator();
         if ($doLog) {
             JD_Vars_Helper::setVar('status', 'jdefender_scan', JText::_('Scanning system settings'));
         }
         // scan
         if (empty($this->_options_data)) {
             $this->_options_data = $optScanner->scan();
             $this->setState('options.scanned', true);
         }
     }
     // If filesystem scan ended
     if (!empty($this->_filesystem_data['EOF'])) {
         $this->setState('filesystem.scanned', true);
         unset($this->_filesystem_data['EOF']);
     }
     $result = array('filesystem' => &$this->_filesystem_data, 'options' => &$this->_options_data);
     return $result;
 }
Exemple #5
0
function jdGetScanStatus()
{
    require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'helpers' . DS . 'log.php';
    $objResponse = new xajaxResponse();
    $controller = new JDefenderControllerScan();
    $scanStatus = $controller->scan($doLog = JD_Scan_Helper::isLogging());
    $scanInfo = JD_Vars_Helper::getGroup('jdefender_scan');
    if (empty($scanInfo)) {
        $scanInfo = array();
    }
    unset($scanInfo['status']);
    $progress = 0;
    if (!empty($scanInfo['total'])) {
        $scanned = 0;
        $scanned += @$scanInfo['files'];
        $scanned += @$scanInfo['dirs'];
        $progress = (int) floor($scanned / $scanInfo['total'] * 100);
    }
    $objResponse->assign('scanstatus', 'innerHTML', JText::_('Progress') . ': ' . $progress . '%');
    $objResponse->script('setProgress(' . $progress . ');');
    $objResponse->script('blink("scanstatus", 2);');
    $js = array();
    foreach ($scanInfo as $k => $v) {
        if ($k == 'last_scan_date') {
            continue;
        }
        $titles = JD_Log_Helper::readableLogType($k);
        if ($titles) {
            $js[] = '"' . addslashes(JHTML::link('index.php?option=com_jdefender&controller=log&task=showLog&cid[]=' . $k, $titles->title, 'target="_blank"')) . '" : ' . (int) $v;
        } else {
            $js[] = $k . ': ' . (int) $v;
        }
    }
    $js = '{' . implode(', ', $js) . '}';
    $objResponse->script('onInfoUpdated("' . addslashes($js) . '")');
    // Check scan status.
    if ($scanStatus && is_array($scanStatus) && count($scanStatus) == 2) {
        list($filesystemScanComplete, $optionScanComplete) = $scanStatus;
        if ($filesystemScanComplete && $optionScanComplete) {
            $objResponse->script('onScanComplete()');
        }
    }
    return $objResponse;
}
Exemple #6
0
 /**
  * Cleanup session variables that are used in system scan. 
  */
 function cleanUpState()
 {
     $session =& JFactory::getSession();
     JD_Vars_Helper::purgeVars('jdefender_scan', 0);
     // Reset flags
     $session->clear('doLog', 'jdefender');
     // Unset counters
     $session->clear('filesystem.scanned', 'jdefender');
     $session->clear('options.scanned', 'jdefender');
     // Clean filelist data
     JD_Scan_Helper::setFilelist(false);
 }
{
	if (is_file(JPATH_ADMINISTRATOR.DS.'defined'.DS.'com_jslm'.DS.'jslm.php'))
	{
		$mainframe->redirect('index.php?option=com_jslm&cmt=com_jdefender');
	}
	else
	{
		JError::raiseWarning(403, JText::_('Please install Mighty Assistant.').' <a target="_blank" href="http://www.mightyextensions.com/download-mighty-assistant">'.JText::_('Download').'</a>');
		$mainframe->redirect('index.php');
	}
}*/
require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'lib' . DS . 'include.php';
jimport('joomla.application.component.model');
JModel::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'models');
JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
$config = JD_Vars_Helper::getGroup('configuration');
if (empty($config) && JRequest::getCmd('controller') != 'configuration') {
    JRequest::setVar('controller', 'configuration');
    JRequest::setVar('task', 'display');
    JRequest::setVar('view', 'configuration');
    JRequest::setVar('layout', 'default');
    JError::raiseNotice(123, JText::_('Please, save the configurations'));
}
if ($controller = JRequest::getWord('controller')) {
    $path = JPATH_COMPONENT . DS . 'controllers' . DS . $controller . '.php';
    if (file_exists($path)) {
        require_once $path;
        $classname = 'JDefenderController' . ucfirst($controller);
    }
} else {
    $path = JPATH_COMPONENT . DS . 'controllers' . DS . 'log.php';
Exemple #8
0
 function createScanFileList()
 {
     $doLog = JD_Scan_Helper::isLogging();
     // disable logging for now
     JD_Scan_Helper::setLogging(false);
     $fsScanner =& JD_Scanner::getInstance('filesystem');
     // Register a validator, to form a filelist.
     $fileListCreator = new JD_Filelist_Creator();
     $fsScanner->register($fileListCreator);
     // Make the file list
     $results = $fsScanner->scan(JPATH_ROOT, false);
     $filename = $this->_getFileListName();
     // Write the file list to a temporary file
     file_put_contents($filename, $results['filelist'][1]);
     // Set filelist filename for scan process
     JD_Scan_Helper::setFilelist($filename);
     JD_Scan_Helper::setLogging($doLog);
     // Store total file number
     JD_Vars_Helper::setVar('total', 'jdefender_scan', $fsScanner->_filesScanned + $fsScanner->_foldersScanned);
     return array($fsScanner->_filesScanned, $fsScanner->_foldersScanned);
 }
Exemple #9
0
 function formatDate($date)
 {
     $d =& JFactory::getDate($date);
     return $d->toFormat(JD_Vars_Helper::getVar('other_date_format', 'configuration', '%A, %d %B %Y'));
 }
 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);
     }
 }
Exemple #11
0
 /**
  * Flushes the log buffer.
  * @return boolean
  */
 function flushLogs()
 {
     if (!count($this->_logData)) {
         return true;
     }
     $session =& JFactory::getSession();
     $doLog = $session->get('doLog', false, 'jdefender');
     $db =& JFactory::getDBO();
     $keys = array('id', 'ip', 'ctime', 'type', 'user_id', 'url', 'post', 'cook', 'referer', 'status', 'issue', 'extension');
     $q = 'INSERT INTO #__jdefender_log ' . '(`id`, `ip`, `ctime`, `type`, `user_id`, `url`, `post`, `cook`, `referer`, `status`, `issue`, `extension`) ';
     $count = array();
     $values = array();
     foreach ($this->_logData as $entry) {
         if ($doLog) {
             if (empty($count[$entry->type])) {
                 $count[$entry->type] = 0;
             }
             $count[$entry->type]++;
         }
         $row = array();
         foreach ($keys as $key) {
             if (empty($entry->{$key})) {
                 if ($key == 'ctime') {
                     $row[] = 'NOW()';
                 } else {
                     $row[] = '""';
                 }
             } else {
                 $row[] = $db->Quote($entry->{$key});
             }
         }
         $values[] = '( ' . implode(', ', $row) . ' )';
     }
     $q = $q . ' VALUES ' . implode(', ', $values);
     $db->setQuery($q);
     if (!$db->query()) {
         $this->setError(JText::_('Cannot write log'));
         return false;
     }
     if ($doLog && count($count)) {
         foreach ($count as $type => $c) {
             $new = (int) JD_Vars_Helper::getVar($type, 'jdefender_scan', 0) + $c;
             JD_Vars_Helper::setVar($type, 'jdefender_scan', $new);
         }
     }
     // Empty the buffer
     $this->_logData = null;
     return true;
 }