Esempio n. 1
0
 /**
  * beforeSave method
  *
  * @param mixed $Model
  * @return bool true (always)
  * @access public
  */
 function beforeSave(&$Model)
 {
     if (!$Model->id) {
         App::import('Component', 'RequestHandler');
         if (!isset($Model->data[$Model->alias]['ip'])) {
             $Model->data[$Model->alias]['ip'] = ip2long(RequestHandlerComponent::getClientIp());
         }
         $Model->data[$Model->alias]['junk_score'] = $this->score($Model, $Model->data);
         $log = $this->suspectLog($Model);
         $matches = $log['matchingRules'];
         $string = array();
         foreach ($matches as $rule => $score) {
             $string[] = $rule . ':' . $score;
         }
         $string = implode($string, ';');
         $Model->data[$Model->alias]['rule_matches'] = $string;
         $this->_addToWhitelist($Model, array('ip', 'junk_score', 'rule_matches'));
         if ($this->settings[$Model->alias]['autoStatus']) {
             $this->_addToWhitelist($Model, array('status'));
             $score = $this->score($Model, $Model->data);
             if ($score >= $this->settings[$Model->alias]['scoreSpam']) {
                 $Model->data[$Model->alias]['status'] = $this->settings[$Model->alias]['statusSpam'];
             } elseif ($score >= $this->settings[$Model->alias]['scoreSuspect']) {
                 $Model->data[$Model->alias]['status'] = $this->settings[$Model->alias]['statusSuspect'];
             } else {
                 $Model->data[$Model->alias]['status'] = $this->settings[$Model->alias]['statusHam'];
             }
         }
         $Model->data[$Model->alias]['junk_score'] = (int) $Model->data[$Model->alias]['junk_score'];
     }
     return true;
 }
 /**
  * testClientProperties method
  *
  * @access public
  * @return void
  */
 function testClientProperties()
 {
     $_SERVER['HTTP_HOST'] = 'localhost:80';
     $this->assertEqual($this->RequestHandler->getReferer(), 'localhost');
     $_SERVER['HTTP_HOST'] = null;
     $_SERVER['HTTP_X_FORWARDED_HOST'] = 'cakephp.org';
     $this->assertEqual($this->RequestHandler->getReferer(), 'cakephp.org');
     $_SERVER['HTTP_X_FORWARDED_FOR'] = '192.168.1.5, 10.0.1.1, proxy.com';
     $_SERVER['HTTP_CLIENT_IP'] = '192.168.1.2';
     $_SERVER['REMOTE_ADDR'] = '192.168.1.3';
     $this->assertEqual($this->RequestHandler->getClientIP(false), '192.168.1.5');
     $this->assertEqual($this->RequestHandler->getClientIP(), '192.168.1.2');
     unset($_SERVER['HTTP_X_FORWARDED_FOR']);
     $this->assertEqual($this->RequestHandler->getClientIP(), '192.168.1.2');
     unset($_SERVER['HTTP_CLIENT_IP']);
     $this->assertEqual($this->RequestHandler->getClientIP(), '192.168.1.3');
     $_SERVER['HTTP_CLIENTADDRESS'] = '10.0.1.2, 10.0.1.1';
     $this->assertEqual($this->RequestHandler->getClientIP(), '10.0.1.2');
 }
 /**
  * @expectedException CakeException
  * @return void
  */
 public function testAddInputTypeException()
 {
     $this->RequestHandler->addInputType('csv', array('I am not callable'));
 }
Esempio n. 4
0
 /**
  * Wrapper for calling the remote API
  * 
  * @throws RuntimeException When an error is returned by Google
  * @return HttpSocket instance
  */
 protected function _doCall($uri, $query)
 {
     $result = false;
     if (!is_a($this->Http, 'HttpSocket')) {
         App::import('Core', 'HttpSocket');
         $this->Http = new HttpSocket();
     }
     $query['v'] = $this->__version;
     if ($this->useUserIp) {
         App::import('Component', 'RequestHandler');
         $RequestHandler = new RequestHandlerComponent();
         $query['userip'] = $RequestHandler->getClientIP();
     }
     if (!is_null($this->key)) {
         $query['key'] = $this->key;
     }
     $response = $this->Http->post($uri, $query);
     if ($this->Http->response['status']['code'] == 200) {
         $response = json_decode($response, true);
         if ($response['responseStatus'] != 200) {
             throw new RuntimeException($response['responseDetails']);
         }
         $result = $response['responseData'];
     }
     return $result;
 }
Esempio n. 5
0
 /**
  * undocumented function
  *
  * @return void
  * @access public
  */
 function checkForIpSpam()
 {
     $ip = RequestHandlerComponent::getClientIP();
     return $this->Tellfriend->isIpSpamming($ip) == 0;
 }
Esempio n. 6
0
 /**
  * testClientProperties method
  *
  * @access public
  * @return void
  */
 function testClientProperties()
 {
     $request = $this->getMock('CakeRequest');
     $request->expects($this->once())->method('referer');
     $request->expects($this->once())->method('clientIp')->will($this->returnValue(false));
     $this->RequestHandler->request = $request;
     $this->RequestHandler->getReferer();
     $this->RequestHandler->getClientIP(false);
 }
 /**
  * logs attempts
  * @param bool errorsOnly (only if error occured, otherwise always)
  * @returns null if not logged, true otherwise
  * 2009-12-18 ms
  */
 private function logAttempt($errorsOnly = true)
 {
     if ($errorsOnly === true && empty($this->error) && empty($this->internalError)) {
         return null;
     }
     App::import('Component', 'RequestHandler');
     $msg = 'Ip \'' . RequestHandlerComponent::getClientIP() . '\', Agent \'' . env('HTTP_USER_AGENT') . '\', Referer \'' . env('HTTP_REFERER') . '\', Host-Referer \'' . RequestHandlerComponent::getReferer() . '\'';
     if (!empty($this->error)) {
         $msg .= ', ' . $this->error;
     }
     if (!empty($this->internalError)) {
         $msg .= ' (' . $this->internalError . ')';
     }
     $this->log($msg, 'captcha');
     return true;
 }
Esempio n. 8
0
 /**
 * Used to perform comment related Api calls.
 *
 * @param array $comment
 * @param string $type
 * @return string
 */
 function __commentCall($comment, $type = 'comment-check')
 {
     if (empty($this->apiKey)) {
         // People will go crazy if they don't figure out they need an Api, so let's make there live
         // a little easier ; ).
         trigger_error('Akismet::checkComment() failed: No Akismet Api key has been set.', E_USER_WARNING);
         return false;
     }
     $vars = array();
     // We use the RequestHandlerComponent in order to figure out the Client-IP and Referrer
     //loadComponent('RequestHandler');
     if (!isset($comment['blog'])) {
         $vars['blog'] = FULL_BASE_URL;
     }
     if (!isset($comment['user_ip'])) {
         $vars['user_ip'] = RequestHandlerComponent::getClientIP();
     }
     if (!isset($comment['referrer '])) {
         $vars['referrer '] = RequestHandlerComponent::getReferrer();
     }
     if (!isset($comment['user_agent'])) {
         $vars['user_agent'] = env('HTTP_USER_AGENT');
     }
     $url = 'http://' . $this->apiKey . '.rest.akismet.com/1.1/' . $type;
     $vars = array_merge($vars, $comment);
     $headers = array();
     $headers[] = 'User-Agent: ' . $this->userAgent;
     return $this->httpPost($url, $vars, $headers);
 }
Esempio n. 9
0
 /**
  * setUser method
  *
  * There's no need to call this method explicitly unless for whatever reason the current user's data
  * Isn't what you want to use, or it isn't where it's set to look ($_SESSION['Auth']['User']). You
  * might call this method during a shell to set the user id to an admin (for example)
  *
  * If called with data, it will set the current user data.
  * If called with true, it will reset the current user data (to whatever's in the session)
  * If called with no data, it will read from the session (if set) or use a fallback of userid = 0
  *
  * Also sets the ip to the current request if it isn't in the passed data array.
  *
  * @param mixed $Model
  * @param array $data array()
  * @return array current user data
  * @access public
  */
 function setUser(&$Model, $data = array())
 {
     if (!$data) {
         if ($this->_currentUser) {
             return $this->_currentUser;
         }
         if (isset($_SESSION['Auth']['User'])) {
             $data = $_SESSION['Auth']['User'];
         } else {
             $data['id'] = 0;
         }
         if (empty($data['ip'])) {
             App::import('Component', 'RequestHandler');
             $data['ip'] = ip2long(str_replace('::ffff:', '', RequestHandlerComponent::getClientIp()));
         }
     } elseif ($data === true) {
         $this->_currentUser = array();
         return $this->setUser($Model);
     }
     $this->_currentUser = $data;
     return $this->_currentUser;
 }
 /**
  * Overload respondAs to Ignore Debug Status
  * 
  * @author	Wes DeMoney <*****@*****.**>
  * @since	1.0
  * @param	mixed	$type
  * @param	array	$options 
  * @return  array
  */
 public function respondAs($type, $options = array())
 {
     // Get Current Debug Level
     $debug = Configure::read();
     // Disable Debug Mode if Enabled
     if (!($debug < 2)) {
         Configure::write('debug', 0);
     }
     // Call RequestHandler respondAs
     $result = parent::respondAs($type, $options);
     // Re Enable Debug Mode if Previously Enabled
     if (!($debug < 2)) {
         Configure::write('debug', $debug);
     }
     return $result;
 }