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 3330

User picture
  • Author: arunasmazeika
  • 2012-02-20 00:14 (about 2 years ago)

Added Check suffix on check methods.

Added referrer check method.

User agent check now makes use of KRequest instead of the server variable directly.

re #186

Files Affected

 
33293330
52
                'reverseHoneypot', 
52
                'reverseHoneypot', 
53
                'timestamp', 
53
                'timestamp', 
54
                'identicalValues', 
54
                'identicalValues', 
55
                'userAgent'), 
55
                'userAgent', 
 
 
56
                'referrer'), 
56
            'auto_mixin' => true));
57
            'auto_mixin' => true));
57
        parent::_initialize($config);
58
        parent::_initialize($config);
58
    }
59
    }
...
 
...
 
88
                }
89
                }
89
                // Append data.
90
                // Append data.
90
                $config['data'] = $data;
91
                $config['data'] = $data;
91
                $method = '_' . $check;
92
                $method = '_' . $check . 'Check';
92
                if(!method_exists($this, $method)) {
93
                if(!method_exists($this, $method)) {
93
                    throw new KControllerBehaviorException('Unknown spam check.');
94
                    throw new KControllerBehaviorException('Unknown spam check.');
94
                }
95
                }
...
 
...
 
122
     *           
123
     *           
123
     * @return boolean True if check is passed, false otherwise.
124
     * @return boolean True if check is passed, false otherwise.
124
     */
125
     */
125
    protected function _honeypot($config = array())
126
    protected function _honeypotCheck($config = array())
126
    {
127
    {
127
        $config = new KConfig($config);
128
        $config = new KConfig($config);
128
 
129
 
...
 
...
 
145
     *           
146
     *           
146
     * @return boolean True if check is passed, false otherwise.
147
     * @return boolean True if check is passed, false otherwise.
147
     */
148
     */
148
    protected function _reverseHoneypot($config = array())
149
    protected function _reverseHoneypotCheck($config = array())
149
    {
150
    {
150
        $config = new KConfig($config);
151
        $config = new KConfig($config);
151
 
152
 
...
 
...
 
161
    }
162
    }
162
 
163
 
163
    /**
164
    /**
164
     * Performs a timestamp check.
165
     * Timestamp check.
165
     * The current time is compared with the time at which the form was
166
     * The current time is compared with the time at which the form was
166
     * rendered. If only a few seconds have passed, the form is considered as
167
     * rendered. If only a few seconds have passed, the form is considered as
167
     * filled by a spam bot.
168
     * filled by a spam bot.
...
 
...
 
170
     *            array An optional configuration array.
171
     *            array An optional configuration array.
171
     * @return boolean True if check is passed, false otherwise.
172
     * @return boolean True if check is passed, false otherwise.
172
     */
173
     */
173
    protected function _timestamp($config = array())
174
    protected function _timestampCheck($config = array())
174
    {
175
    {
175
        $config = new KConfig($config);
176
        $config = new KConfig($config);
176
 
177
 
...
 
...
 
195
    }
196
    }
196
 
197
 
197
    /**
198
    /**
 
 
199
     * Identical field values check.
198
     * Performs a check over some selected fields and see if they have identical
200
     * Performs a check over some selected fields and see if they have identical
199
     * values.
201
     * values.
200
     * If they do, the form is considered as spammed.
202
     * If they do, the form is considered as spammed.
...
 
...
 
203
     *            array An optional configuration array.
205
     *            array An optional configuration array.
204
     * @return boolean True if check is passed, false otherwise.
206
     * @return boolean True if check is passed, false otherwise.
205
     */
207
     */
206
    protected function _identicalValues($config = array())
208
    protected function _identicalValuesCheck($config = array())
207
    {
209
    {
208
        $config = new KConfig($config);
210
        $config = new KConfig($config);
209
        if(!$config->fields) {
211
        if(!$config->fields) {
...
 
...
 
241
     *            array An optional configuration array.
243
     *            array An optional configuration array.
242
     * @return boolean True if check is passed, false otherwise.
244
     * @return boolean True if check is passed, false otherwise.
243
     */
245
     */
244
    protected function _userAgent($config = array())
246
    protected function _userAgentCheck($config = array())
245
    {
247
    {
246
        if(empty($_SERVER['HTTP_USER_AGENT'])) {
248
        $user_agent = KRequest::get('server.HTTP_USER_AGENT', 'raw');
 
 
249
        if(empty($user_agent)) {
247
            return false;
250
            return false;
248
        }
251
        }
249
        return true;
252
        return true;
250
    }
253
    }
 
 
254
 
 
 
255
    /**
 
 
256
     * Referrer check.
 
 
257
     * Checks for the existence of a referrer. If there isn't one, the form is
 
 
258
     * considered as sent by a bot.
 
 
259
     *
 
 
260
     * @param
 
 
261
     *            array An optional configuration array.
 
 
262
     * @return boolean True if check is passed, false otherwise.
 
 
263
     */
 
 
264
    protected function _referrerCheck($config = array())
 
 
265
    {
 
 
266
        $referrer = KRequest::get('server.HTTP_REFERER', 'raw');
 
 
267
        if(empty($referrer)) {
 
 
268
            return false;
 
 
269
        }
 
 
270
        return true;
 
 
271
    }
251
 
272
 
252
}
273
}