Skip to content

Commit

Permalink
Relax rules for detecting Apache
Browse files Browse the repository at this point in the history
When running under fcgi+Apache provide fallback function to detect Apache.
  • Loading branch information
dz0ny committed Dec 5, 2015
1 parent 74a3512 commit 346e035
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
/**
* Plugin Name: Spider Blocker
* Description: Spider Blocker will block most common bots that consume bandwidth and slow down your server.
* Version: 1.0.4
* Version: 1.0.5
* Runtime: 5.3
* Author: NiteoWeb Ltd.
* Author URI: www.niteoweb.com
*/

if (!function_exists('apache_get_version')) {
function apache_get_version()
{
if (stristr($_ENV["SERVER_SOFTWARE"], 'Apache')) {
return $_ENV["SERVER_SOFTWARE"];
}
return false;
}
}

if (version_compare(PHP_VERSION, '5.3.0', '<')) {
?>
<div id="error-page">
Expand Down Expand Up @@ -106,7 +116,7 @@ function activatePluginNotice()
*/
function activatePlugin()
{
if (!apache_get_version() || !SpiderBlocker::modRewriteEnabled()) {
if (!apache_get_version()) {
?>
<div id="error-page">
<p>This plugin requires Apache2 server with mod_rewrite support. Please contact your hosting provider
Expand Down Expand Up @@ -143,19 +153,12 @@ function generateBlockRules()
$htaccess_file = $home_path . '.htaccess';

if ((!file_exists($htaccess_file) && is_writable($home_path)) || is_writable($htaccess_file)) {
if ($this->modRewriteEnabled()) {
insert_with_markers($htaccess_file, 'NiteowebSpiderBlocker', $this->getRules());
}
insert_with_markers($htaccess_file, 'NiteowebSpiderBlocker', $this->getRules());
}

$wp_rewrite->flush_rules();
}

static function modRewriteEnabled()
{
return function_exists('apache_mod_loaded') ? apache_mod_loaded('mod_rewrite', false) : false;
}

/**
* Generate block rules based on enabled bots
*
Expand Down Expand Up @@ -206,9 +209,7 @@ function removeBlockRules()
$htaccess_file = $home_path . '.htaccess';
$empty = array();
if ((!file_exists($htaccess_file) && is_writable($home_path)) || is_writable($htaccess_file)) {
if ($this->modRewriteEnabled()) {
insert_with_markers($htaccess_file, 'NiteowebSpiderBlocker', $empty);
}
insert_with_markers($htaccess_file, 'NiteowebSpiderBlocker', $empty);
}

$wp_rewrite->flush_rules();
Expand Down

0 comments on commit 346e035

Please sign in to comment.