function perform()
 {
     // fetch the data
     $this->_ip1 = $this->_request->getValue("ip1");
     $this->_ip2 = $this->_request->getValue("ip2");
     $this->_ip3 = $this->_request->getValue("ip3");
     $this->_ip4 = $this->_request->getValue("ip4");
     $this->_hostIp = $this->_ip1 . "." . $this->_ip2 . "." . $this->_ip3 . "." . $this->_ip4;
     $this->_mask = $this->_request->getValue("mask");
     $this->_blockType = $this->_request->getValue("blockType");
     $this->_reason = $this->_request->getValue("reason");
     // create the dao object and add the info to the db
     $blockedHosts = new BlockedHosts();
     $t = new Timestamp();
     $blockedHost = new BlockedHost($this->_hostIp, $this->_mask, $this->_reason, $t->getTimestamp(), GLOBALLY_BLOCKED_HOST, $this->_blockType, BLOCK_BLACKLIST);
     $this->notifyEvent(EVENT_PRE_BLOCK_HOST_ADD, array("host" => &$blockedHost));
     $result = $blockedHosts->add($blockedHost);
     // and give some feedback to the user
     if (!$result) {
         $this->_view = new AdminNewBlockedHostView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_adding_blocked_host"));
         $this->setCommonData();
         return false;
     }
     $this->notifyEvent(EVENT_POST_BLOCK_HOST_ADD, array("host" => &$blockedHost));
     $this->_view = new AdminBlockedHostsView($this->_blogInfo);
     $this->_view->setSuccessMessage($this->_locale->tr("blocked_host_updated_ok"));
     $this->setCommonData();
     // clear the cache
     CacheControl::resetBlogCache($this->_blogInfo->getId());
     return true;
 }
 function render()
 {
     $blogSettings = $this->_blogInfo->getSettings();
     $pluginEnabled = $blogSettings->getValue("plugin_hostblock_enabled");
     // get the content that has been filtered by this blog
     $blockedHosts = new BlockedHosts();
     $hostsBlockedFromPosting = $blockedHosts->getBlogBlacklist($this->_blogInfo->getId(), BLOCK_COMMENT_POSTING);
     $hostsBlocked = $blockedHosts->getBlogBlacklist($this->_blogInfo->getId(), BLOCK_ACCESS);
     $blogBlockedHosts = array_merge($hostsBlockedFromPosting, $hostsBlocked);
     $this->setValue("pluginEnabled", $pluginEnabled);
     $this->setValue("blockedhosts", $blogBlockedHosts);
     if (!$pluginEnabled) {
         $locale = $this->_blogInfo->getLocale();
         $text = $locale->tr("error_hostblock_not_enabled");
         $this->setErrorMessage($text);
     }
     parent::render();
 }
 /**
  * Carries out the specified action
  */
 function perform()
 {
     // fetch the data
     $this->_hostId = $this->_request->getValue("hostId");
     $blockedHosts = new BlockedHosts();
     $blockedHost = $blockedHosts->getBlockedHost($this->_hostId);
     // check if the info about the blocked host is correct
     if (!$blockedHost) {
         $this->_view = new AdminBlockedHostsView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_fetching_blocked_host"));
         $this->setCommonData();
         return false;
     }
     // if so, continue
     $this->_view = new AdminEditBlockedHostView($this->_blogInfo, $this->_hostId);
     $this->setCommonData();
     // better to return true if everything fine
     return true;
 }
 function filter()
 {
     // get all the hosts that have been blacklisted
     // by this blog
     $blogInfo = $this->_pipelineRequest->getBlogInfo();
     $request = $this->_pipelineRequest->getHttpRequest();
     // check if this section has been enabled or disabled
     $blogSettings = $blogInfo->getSettings();
     $pluginEnabled = $blogSettings->getValue("plugin_hostblock_enabled");
     if (!$pluginEnabled) {
         // if not, nothing to do here...
         //_debug("ip address filter not enabled! quitting...<br/>");
         return new PipelineResult();
     }
     // get the list of blocked hosts for this blog
     $blockedHosts = new BlockedHosts();
     $hostsAccessBlocked = $blockedHosts->getBlogBlacklist($blogInfo->getId(), BLOCK_ACCESS, true);
     $hostsPostCommentBlocked = $blockedHosts->getBlogBlacklist($blogInfo->getId(), BLOCK_COMMENT_POSTING, true);
     // and now check one by one, comparing with the ip we just got
     $clientIp = Client::getIp();
     //
     // check the hosts that are not even allowed to access
     //
     $ipMatchValidator = new IpMatchValidator();
     foreach ($hostsAccessBlocked as $hostAccessBlocked) {
         if ($ipMatchValidator->validate($clientIp, $hostAccessBlocked->getCidrAddress())) {
             return new PipelineResult(false, HOST_BLACKLIST_BLOCKED_HOST_FOUND, $hostAccessBlocked->getReason());
         }
     }
     //
     // and now if we're posting a comment, check the ips
     //
     if ($request->getValue("op") == "AddComment") {
         foreach ($hostsPostCommentBlocked as $hostPostCommendBlocked) {
             if ($ipMatchValidator->validate($clientIp, $hostPostCommendBlocked->getCidrAddress())) {
                 return new PipelineResult(false, HOST_BLACKLIST_COMMENT_BLOCKED_HOST_FOUND, $hostPostCommendBlocked->getReason());
             }
         }
     }
     $result = new PipelineResult();
     return $result;
 }
 function render()
 {
     $blogSettings = $this->_blogInfo->getSettings();
     $pluginEnabled = $blogSettings->getValue("plugin_hostblock_enabled");
     $blockedHosts = new BlockedHosts();
     $blockedHost = $blockedHosts->getBlockedHost($this->_hostId, $this->_blogInfo->getId());
     $this->setValue("pluginEnabled", $pluginEnabled);
     $this->setValue("blockedhost", $blockedHost);
     // to make things easier in the template, let's do the following:
     $ipParts = explode(".", $blockedHost->getHost());
     $this->setValue("ip1", $ipParts[0]);
     $this->setValue("ip2", $ipParts[1]);
     $this->setValue("ip3", $ipParts[2]);
     $this->setValue("ip4", $ipParts[3]);
     if (!$pluginEnabled) {
         $locale = $this->_blogInfo->getLocale();
         $text = $locale->tr("error_hostblock_not_enabled");
         $this->setErrorMessage($text);
     }
     parent::render();
 }
 /**
  * Carries out the specified action
  */
 function perform()
 {
     // if we're blocking a single host, then the mask should be
     // as long as 32 bits
     $blockedHosts = new BlockedHosts();
     $t = new Timestamp();
     $blockedHost = new BlockedHost($this->_host, 32, "Host blocked from posting", $t->getTimestamp(), $this->_blogInfo->getId(), BLOCK_COMMENT_POSTING, BLOCK_BLACKLIST);
     $result = $blockedHosts->add($blockedHost);
     // if there was an error, let the user know about it...
     if (!$result) {
         $this->_view = new AdminErrorView($this->_blogInfo);
         $this->_view->setMessage("There was an error adding this host to the list of blocked hosts.");
         $this->setCommonData();
         return false;
     }
     $this->_view = new AdminMessageView($this->_blogInfo);
     $this->_view->setMessage("Host " . $this->_host . " blocked from posting comments successfully.");
     $this->setCommonData();
     // better to return true if everything fine
     return true;
 }
 /**
  * Carries out the specified action
  */
 function perform()
 {
     // fetch the data
     $this->_ip1 = $this->_request->getValue("ip1");
     $this->_ip2 = $this->_request->getValue("ip2");
     $this->_ip3 = $this->_request->getValue("ip3");
     $this->_ip4 = $this->_request->getValue("ip4");
     $this->_ip = $this->_ip1 . "." . $this->_ip2 . "." . $this->_ip3 . "." . $this->_ip4;
     $this->_mask = $this->_request->getValue("mask");
     $this->_type = $this->_request->getValue("blockType");
     $this->_reason = $this->_request->getValue("reason");
     $blockedHosts = new BlockedHosts();
     $blockedHost = $blockedHosts->getBlockedHost($this->_hostId, $this->_blogInfo->getId());
     // check if the info about the blocked host is correct
     if (!$blockedHost) {
         $this->_view = new AdminBlogBlockedHostsView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_fetching_blocked_host"));
         $this->setCommonData();
         return false;
     }
     // set the new information
     $blockedHost->setHost($this->_ip);
     $blockedHost->setReason($this->_reason);
     $blockedHost->setType($this->_type);
     $blockedHost->setMask($this->_mask);
     $this->notifyEvent(EVENT_PRE_BLOCK_HOST_UPDATE, array("host" => &$blockedHost));
     if (!$blockedHosts->update($blockedHost)) {
         $this->_view = new AdminBlogBlockedHostsView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_updating_blocked_host"));
         $this->setCommonData();
         return false;
     }
     $this->notifyEvent(EVENT_POST_BLOCK_HOST_UPDATE, array("host" => &$blockedHost));
     $this->_view = new AdminBlogBlockedHostsView($this->_blogInfo);
     $this->_view->setSuccessMessage($this->_locale->tr("blocked_host_updated_ok"));
     $this->setCommonData();
     // clear the cache
     CacheControl::resetBlogCache($this->_blogInfo->getId());
     return true;
 }
 function _deleteBlogBlockedHosts()
 {
     $blockedHosts = new BlockedHosts();
     // loop through the array of things to remove
     $errorMessage = "";
     $successMessage = "";
     $numOk = 0;
     foreach ($this->_blockedIds as $blockedId) {
         // get the post
         $blockedHost = $blockedHosts->getBlockedHost($blockedId, $this->_blogInfo->getId());
         $this->notifyEvent(EVENT_PRE_BLOCK_HOST_DELETE, array("host" => &$blockedHost));
         $result = $blockedHosts->remove($blockedId, $this->_blogInfo->getId());
         if (!$result) {
             $errorMessage .= $this->_locale->pr("error_deleting_blocked_host", $blockedHost->getHost()) . "<br/>";
         } else {
             $numOk++;
             if ($numOk > 1) {
                 $successMessage = $this->_locale->pr("blocked_hosts_deleted_ok", $numOk);
             } else {
                 $successMessage = $this->_locale->pr("blocked_host_deleted_ok", $blockedHost->getHost());
             }
             $this->notifyEvent(EVENT_POST_BLOCK_HOST_DELETE, array("host" => &$blockedHost));
         }
     }
     $this->_view = new AdminBlogBlockedHostsView($this->_blogInfo);
     if ($errorMessage != "") {
         $this->_view->setErrorMessage($errorMessage);
     }
     if ($successMessage != "") {
         $this->_view->setSuccessMessage($successMessage);
     }
     $this->setCommonData();
     // clear the cache
     CacheControl::resetBlogCache($this->_blogInfo->getId());
     // better to return true if everything fine
     return true;
 }