Nooku Server is an open source project powered by Assembla

Assembla offers free public and private SVN/Git repositories and project hosting with bug/issue tracking and collaboration tools.

nooku-server

Commit 3354

User picture
  • Author: arunasmazeika
  • 2012-02-24 04:18 (about 2 years ago)

Added some doc blocks.

Whitelisted IP checks is now performed in the spammed method. A variable can be set for bypassing the check, which is enabled by default.

Changed blacklistedhosts table name to blackhosts. blackListedHost check also renamed to blackHost.

re #186

Files Affected

 
33533354
19
 */
19
 */
20
class ComUsersControllerBehaviorSpammable extends KControllerBehaviorAbstract
20
class ComUsersControllerBehaviorSpammable extends KControllerBehaviorAbstract
21
{
21
{
22
 
22
    /**
 
 
23
     *
 
 
24
     * @var array An array of spam checks to be executed.
 
 
25
     */
23
    protected $_checks;
26
    protected $_checks;
24
 
27
 
 
 
28
    /**
 
 
29
     *
 
 
30
     * @var array An array containing the checks that failed.
 
 
31
     */
25
    protected $_failed_checks;
32
    protected $_failed_checks;
26
 
33
 
 
 
34
    /**
 
 
35
     *
 
 
36
     * @var boolean True is the form/data is spammed, false otherwise.
 
 
37
     */
27
    protected $_spammed;
38
    protected $_spammed;
28
 
39
 
 
 
40
    /**
 
 
41
     *
 
 
42
     * @var string A secret string for generating hashs.
 
 
43
     */
29
    protected $_secret;
44
    protected $_secret;
30
 
45
 
 
 
46
    /**
 
 
47
     *
 
 
48
     * @var string The client IP.
 
 
49
     */
31
    protected $_client_ip;
50
    protected $_client_ip;
32
 
51
 
 
 
52
    /**
 
 
53
     *
 
 
54
     * @var boolean True if the client IP is whitelisted, false otherwise.
 
 
55
     */
33
    protected $_white_ip;
56
    protected $_white_ip;
34
 
57
 
35
    public function __construct(KConfig $config = null)
58
    public function __construct(KConfig $config = null)
...
 
...
 
46
 
69
 
47
    protected function _beforeControllerAdd(KCommandContext $context)
70
    protected function _beforeControllerAdd(KCommandContext $context)
48
    {
71
    {
49
        // Check if IP is whitelisted.
72
        $result = (bool) !$this->spammed(array('data' => $context->data));
50
        if(!$this->whiteIp()) {
 
 
51
            // Perform a spam check.
 
 
52
            $result = (bool) !$this->spammed(array('data' => $context->data));
 
 
53
        } else {
 
 
54
            // Set as not spammed.
 
 
55
            $this->setSpammed(false);
 
 
56
            $result = true;
 
 
57
        }
 
 
58
        return $result;
 
 
59
    }
73
    }
60
 
74
 
61
    protected function _initialize(KConfig $config)
75
    protected function _initialize(KConfig $config)
...
 
...
 
69
                'identicalValues', 
83
                'identicalValues', 
70
                'userAgent', 
84
                'userAgent', 
71
                'referrer', 
85
                'referrer', 
72
                'blacklistedHost', 
86
                'blackHost', 
73
                'spamhaus', 
87
                'spamhaus', 
74
                'mxRecord', 
88
                'mxRecord', 
75
                'blacklist')));
89
                'blacklist')));
...
 
...
 
178
    public function spammed($config = array())
192
    public function spammed($config = array())
179
    {
193
    {
180
        if(!isset($this->_spammed)) {
194
        if(!isset($this->_spammed)) {
 
 
195
 
181
            $config = new KConfig($config);
196
            $config = new KConfig($config);
 
 
197
 
 
 
198
            $config->append(array('whitelist' => true));
 
 
199
 
 
 
200
            if($config->whitelist && $this->whiteIp()) {
 
 
201
                // Client is whitelisted.
 
 
202
                $this->_spammed = false;
 
 
203
                return $this->_spammed;
 
 
204
 
 
 
205
            }
 
 
206
 
182
            if(!$config->checks) {
207
            if(!$config->checks) {
183
                // Use behavior checks.
208
                // Use behavior checks.
184
                $config->checks = $this->_checks;
209
                $config->checks = $this->_checks;
185
            }
210
            }
 
 
211
 
186
            // Initialize the spammed status as false.
212
            // Initialize the spammed status as false.
187
            $this->_spammed = false;
213
            $this->_spammed = false;
188
            foreach($config->checks as $key => $val) {
214
            foreach($config->checks as $key => $val) {
...
 
...
 
379
    }
405
    }
380
 
406
 
381
    /**
407
    /**
382
     * Performs a check against the blacklisted hosts table.
408
     * Performs a check against the black hosts table.
383
     * If the provided email's domain is found on it, the check fails.
409
     * If the provided email's domain is found on it, the check fails.
384
     *
410
     *
385
     * @param
411
     * @param
...
 
...
 
386
     *            array An optional configuration array.
412
     *            array An optional configuration array.
387
     * @return boolean True if check is passed, false otherwise.
413
     * @return boolean True if check is passed, false otherwise.
388
     */
414
     */
389
    protected function _blacklistedHostCheck($config = array())
415
    protected function _blackHostCheck($config = array())
390
    {
416
    {
391
        $config = new KConfig($config);
417
        $config = new KConfig($config);
392
        $data = $config->data;
418
        $data = $config->data;
...
 
...
 
393
        $email = $data->email;
419
        $email = $data->email;
394
        $domain = $this->getEmailDomain($email);
420
        $domain = $this->getEmailDomain($email);
395
 
421
 
396
        if($this->getService('com://admin/users.database.row.blacklistedhost')
422
        if($this->getService('com://admin/users.database.row.blackhost')
397
            ->setData(array('name' => $domain))
423
            ->setData(array('name' => $domain))
398
            ->load()) {
424
            ->load()) {
399
            // Domain is blacklisted.
425
            // Domain is blacklisted.
...
 
...
 
525
    protected function _mxRecordCheck($config = array())
551
    protected function _mxRecordCheck($config = array())
526
    {
552
    {
527
        $config = new KConfig($config);
553
        $config = new KConfig($config);
528
 
554
        
529
        if(!function_exists('getmxrr')) {
555
        if(!function_exists('getmxrr')) {
530
            throw new KControllerBehaviorException('getmxrr function missing.');
556
            throw new KControllerBehaviorException('getmxrr function missing.');
531
        }
557
        }