Exemplo n.º 1
0
 /**
  * Sets last scan date
  * @param JDate $now
  */
 function setLastScanDate($now = false)
 {
     if (empty($now) || !@is_a($now, 'JDate')) {
         $now =& JFactory::getDate();
     }
     JD_Vars_Helper::setVar('last_scan_date', 'jdefender', $now->toMySQL());
 }
Exemplo n.º 2
0
 function save($data)
 {
     foreach ($data as $k => $v) {
         JD_Vars_Helper::setVar($k, 'configuration', $v);
     }
     return true;
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
0
 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);
     }
 }
Exemplo n.º 7
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;
 }