/** * testClientProperties method * * @return void */ public 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); }
/** * 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'); }
/** * 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; }
/** * undocumented function * * @return void * @access public */ function checkForIpSpam() { $ip = RequestHandlerComponent::getClientIP(); return $this->Tellfriend->isIpSpamming($ip) == 0; }
/** * 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; }
/** * 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); }
/** * Gets Remote Client IP * * Overridden to account for comma-delimited IP formats that proxies create. * Strips away everything but first address (the client IP) * * @since 1.0 * @author Anthony Putignano <*****@*****.**> * @param bool $safe * @return string */ public function getClientIP($safe = false) { $result = parent::getClientIP($safe); $clientIp = explode(',', $result); foreach ($clientIp as $ipAddress) { $cleanIpAddress = trim($ipAddress); if (false !== filter_var($cleanIpAddress, FILTER_VALIDATE_IP)) { return $cleanIpAddress; } } return ''; }