/** * Is allowed to view the site * * @return boolean */ public static function isAllowedViewSite() { if ((int) SettingService::getSetting('application_disable_site')) { $user = UserIdentityService::getCurrentUserIdentity(); if ($user['role'] != AclBaseModel::DEFAULT_ROLE_ADMIN) { // get a visitor IP $remote = new RemoteAddress(); $remote->setUseProxy(true); $userIp = $remote->getIpAddress(); // get list of allowed ACL roles if (null != ($allowedAclRoles = SettingService::getSetting('application_disable_site_acl'))) { if (!is_array($allowedAclRoles)) { $allowedAclRoles = [$allowedAclRoles]; } } // get list of allowed IPs if (null != ($allowedIps = SettingService::getSetting('application_disable_site_ip'))) { $allowedIps = explode(',', $allowedIps); } if ($allowedAclRoles || $allowedIps) { if ($allowedAclRoles && in_array($user['role'], $allowedAclRoles) || $allowedIps && in_array($userIp, $allowedIps)) { return true; } } return false; } } return true; }
/** * Configure instance * * @param array $options */ protected function configure(array $options) { if (isset($options['actionPluginManager'])) { $config = new Config($options['actionPluginManager']); $config->configureServiceManager($this->getActionPlugins()); unset($options['actionPluginManager']); } if (isset($options['storagePluginManager'])) { $config = new Config($options['storagePluginManager']); $config->configureServiceManager($this->getStoragePlugins()); unset($options['storagePluginManager']); } foreach ($options as $key => $value) { switch ($key) { case 'pluginName': $this->setPluginName($name); break; case 'limits': $this->setLimits($value); break; case 'storage': $this->setStorage($value); break; case 'useProxy': $this->remoteAddress->setUseProxy($value); break; case 'trustedProxies': $this->remoteAddress->setTrustedProxies($value); break; } } }
/** * Checks if a comment is spam using the akismet service. * * @param \RbComment\Model\Comment $comment * @param mixed $rbCommentConfig * @return boolean */ protected function isSpam($comment, $rbCommentConfig) { $remote = new RemoteAddress(); $remote->setUseProxy($rbCommentConfig->akismet['proxy']['use']); $remote->setTrustedProxies($rbCommentConfig->akismet['proxy']['trusted']); $remote->setProxyHeader($rbCommentConfig->akismet['proxy']['header']); return $this->getAkismetService()->isSpam(array('user_ip' => $remote->getIpAddress(), 'user_agent' => filter_input(INPUT_SERVER, 'HTTP_USER_AGENT'), 'comment_type' => 'comment', 'comment_author' => $comment->author, 'comment_author_email' => $comment->contact, 'comment_content' => $comment->content)); }
/** * {@inheritDoc} * * @return IpExclusion * @throws \InvalidArgumentException */ public function createService(ServiceLocatorInterface $serviceLocator) { $options = $serviceLocator->get('ZfMaintenanceOptions'); $exclusions = $options->getExclusions(); if (!isset($exclusions['ZfMaintenanceIpExclusion'])) { throw new \InvalidArgumentException('Config for "Jgut\\Zf\\Maintenance\\Exclusion\\IpExclusion" not set'); } $ipProvider = new RemoteAddress(); $ipProvider->setUseProxy(true); $ips = $exclusions['ZfMaintenanceIpExclusion']; return new IpExclusion($ips, $ipProvider); }
/** * Initialize proxy with config * * @param Config $config */ public function __construct(Config $config, ZendLogger $logger, Request $request) { $this->config = $config; $this->logger = $logger; $trustedProxies = explode(',', $this->config->get('TrustedProxy')->get('loadbalancer')); // Populate client info properties from request $RemoteAddress = new RemoteAddress(); $RemoteAddress->setUseProxy(); $RemoteAddress->setTrustedProxies($trustedProxies); $ipAddress = $RemoteAddress->getIpAddress(); $this->clientIp = array('IPv4' => $ipAddress); $Request = new Request(); $this->clientUri = $Request->getUri(); }
/** * Add answer vote * * @param integer $questionId * @param integer $answerId * @return string|boolean */ public function addAnswerVote($questionId, $answerId) { try { $this->adapter->getDriver()->getConnection()->beginTransaction(); $remote = new RemoteAddress(); $remote->setUseProxy(true); // add a track info $insert = $this->insert()->into('poll_answer_track')->values(['question_id' => $questionId, 'answer_id' => $answerId, 'ip' => inet_pton($remote->getIpAddress()), 'created' => time()]); $statement = $this->prepareStatementForSqlObject($insert); $statement->execute(); $this->adapter->getDriver()->getConnection()->commit(); } catch (Exception $e) { $this->adapter->getDriver()->getConnection()->rollback(); ApplicationErrorLogger::log($e); return $e->getMessage(); } return true; }
/** * Add page rating * * @param integer $pageId * @param integer $widgetConnectionId * @param float $ratingValue * @param string $slug * @return string|float */ public function addPageRating($pageId, $widgetConnectionId, $ratingValue, $slug = null) { try { $this->adapter->getDriver()->getConnection()->beginTransaction(); $pageRatingId = 0; $remote = new RemoteAddress(); $remote->setUseProxy(true); $visitorIp = inet_pton($remote->getIpAddress()); // check the page's rating existing if (null == ($pageRateInfo = $this->getPageRatingInfo($pageId, $slug))) { // create a new page rating $insert = $this->insert()->into('page_rating')->values(['page_id' => $pageId, 'widget_connection' => $widgetConnectionId, 'slug' => $slug, 'total_rating' => $ratingValue, 'total_count' => 1]); $statement = $this->prepareStatementForSqlObject($insert); $statement->execute(); $pageRatingId = $this->adapter->getDriver()->getLastGeneratedValue(); } else { // update the existing page's rating $update = $this->update()->table('page_rating')->set(['total_rating' => new Expression('total_rating + ?', [$ratingValue]), 'total_count' => new Expression('total_count + 1')])->where(['page_id' => $pageId, 'slug' => $slug]); $statement = $this->prepareStatementForSqlObject($update); $statement->execute(); } // add a track info $insert = $this->insert()->into('page_rating_track')->values(['rating_id' => !empty($pageRateInfo['id']) ? $pageRateInfo['id'] : $pageRatingId, 'ip' => $visitorIp, 'rating' => $ratingValue, 'created' => time()]); $statement = $this->prepareStatementForSqlObject($insert); $statement->execute(); $this->adapter->getDriver()->getConnection()->commit(); } catch (Exception $e) { $this->adapter->getDriver()->getConnection()->rollback(); ApplicationErrorLogger::log($e); return $e->getMessage(); } return !empty($pageRateInfo) ? ($pageRateInfo['total_rating'] + $ratingValue) / ($pageRateInfo['total_count'] + 1) : $ratingValue; }
/** * Returns client IP address. * * @return string IP address. */ protected function getIpAddress() { $remoteAddress = new RemoteAddress(); $remoteAddress->setUseProxy(static::$useProxy); $remoteAddress->setTrustedProxies(static::$trustedProxies); $remoteAddress->setProxyHeader(static::$proxyHeader); return $remoteAddress->getIpAddress(); }
/** * Add comment * * @param string $language * @param integer $maxNestedLevel * @param string $pageUrl * @param array $basicData * integer active * string comment * string name * string email * integer user_id * @param integer $pageId * @param string $slug * @param integer $replyId * @return array|string */ public function addComment($language, $maxNestedLevel, $pageUrl, array $basicData, $pageId, $slug = null, $replyId = null) { $replyComment = false; // get a reply comment info if ($replyId) { $replyComment = $this->getCommentInfo($replyId, $pageId, $slug); if ($replyComment['level'] > $maxNestedLevel) { return; } } // the reply comment doesn't exist or not active if ($replyId && !$replyComment) { return; } $filter = ['page_id' => $pageId, 'slug' => $slug]; $remote = new RemoteAddress(); $remote->setUseProxy(true); $commentHidden = $basicData['active'] == self::COMMENT_STATUS_NOT_ACTIVE || $replyComment && $replyComment['hidden'] == CommentNestedSet::COMMENT_STATUS_HIDDEN; $data = array_merge($basicData, ['hidden' => $commentHidden ? self::COMMENT_STATUS_HIDDEN : self::COMMENT_STATUS_NOT_HIDDEN, 'page_id' => $pageId, 'slug' => $slug, 'ip' => inet_pton($remote->getIpAddress()), 'guest_id' => empty($basicData['user_id']) ? $this->getGuestId() : null, 'created' => time(), 'language' => $language]); $parentLevel = $replyComment ? $replyComment['level'] : 0; $parentLeftKey = $replyComment ? $replyComment['left_key'] : 0; // add reply comments to the start if ($parentLevel) { $commentId = $this->insertNodeToStart($parentLevel, $parentLeftKey, $data, $filter); } else { $lastRightNode = $this->getLastNode($filter); // add a comment to the end $commentId = $lastRightNode ? $this->insertNode($parentLevel, $lastRightNode, $data, $filter) : $this->insertNodeToStart($parentLevel, $parentLeftKey, $data, $filter); } if (is_numeric($commentId)) { $commentInfo = $this->getCommentInfo($commentId, $pageId, $slug); // fire the add comment event CommentEvent::fireAddCommentEvent($pageUrl, $commentInfo, $replyComment); return $commentInfo; } return $commentId; }
/** * Validate spam IP * * @param $value * @param array $context * @return boolean */ public function validateSpamIp($value, array $context = []) { $remote = new RemoteAddress(); $remote->setUseProxy(true); return $this->model->isSpamIp($remote->getIpAddress()) ? false : true; }