/** * Perform internal banning * * @param \Tollwerk\TwAntibot\Domain\Model\Submission $submission Submission * @return void */ protected function _ban(\Tollwerk\TwAntibot\Domain\Model\Submission $submission = null) { $persistence = $this->_setup('persistence.'); // If IP banning is enabled if ($this->_ipBanningEnabled()) { $ip = $this->_ipRepository->findExpiredOneByIp($this->_ip); if (!$ip instanceof \Tollwerk\TwAntibot\Domain\Model\Ip) { $ip = new \Tollwerk\TwAntibot\Domain\Model\Ip(); $ip->setPid(intval($persistence['storagePid'])); $ip->setIp($this->_ip); $ipUpdate = false; } else { $ipUpdate = true; } $ip->setSubmission($submission); // Set a period if configured $ipPeriod = intval($this->_settings['banning']['ip']['period']); if ($ipPeriod > 0) { $ip->setEndtime(time() + $ipPeriod); } if ($ipUpdate) { $this->_ipRepository->update($ip); } else { $this->_ipRepository->add($ip); } } // If email banning is enabled if ($this->_emailBanningEnabled()) { $emailField = trim($this->_settings['email']); $emailAddress = array_key_exists($emailField, $this->_fields) ? trim($this->_fields[$emailField]) : null; if (strlen($emailAddress)) { $email = $this->_emailRepository->findExpiredOneByEmail($emailAddress); if (!$email instanceof \Tollwerk\TwAntibot\Domain\Model\Email) { $email = new \Tollwerk\TwAntibot\Domain\Model\Email(); $email->setPid(intval($persistence['storagePid'])); $email->setEmail($emailAddress); $emailUpdate = false; } else { $emailUpdate = true; } $email->setSubmission($submission); // Set a period if configured $emailPeriod = intval($this->_settings['banning']['email']['period']); if ($emailPeriod > 0) { $email->setEndtime(time() + $emailPeriod); } if ($emailUpdate) { $this->_emailRepository->update($email); } else { $this->_emailRepository->add($email); } } } }
/** * Garbage collection * * @return \boolean Success */ public function gcCommand() { if ($this->_task === null) { foreach (debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT) as $frame) { if ($frame['class'] == 'TYPO3\\CMS\\Extbase\\Scheduler\\Task') { $this->_task =& $frame['object']; break; } } } $this->_outputStatistics(array(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('gc.ip', 'tw_antibot') => $this->ipRepository->collectGarbage(), \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('gc.email', 'tw_antibot') => $this->emailRepository->collectGarbage())); return true; }