NOTICE: DO NOT INSTALL YET, there is an issue! Please wait for next version
This is a very fast, and easy way to one-click install Cloudflare apache module and also to remove it from the httpd.conf if you want. I'd like you to test and confirm it worked for you as it has for me.
I did write this, so it's bound to have something wrong, so please look over it and see what you think.
Features:
- One-Click install or Uninstall Cloudflare from Apache
- Checks to see if Cloudflare is already installed Apache
- You will need to restart apache after installing cloudflare, do this from the CWP Dashboard.
- Restores Original Visitor's IP address to your server logs
NOTICE: DO NOT INSTALL YET, there is an issue! Please wait for next versionI just tried doing it on a new server and it REALLY messed up the apache....
I'm not going to go deeper in this because I think I misunderstood how this works. Basicly what you need is to install cloudflare with the mod_cloudflare.so then add the
LoadModule cloudflare_module /usr/lib64/httpd/modules/mod_cloudflare.so
to your /usr/local/apache/conf/httpd.conf and restart apache. I was trying to install httpd-devel which I think messes it all up bad. You can read more here about installing cloudflare (
https://www.cloudflare.com/resources-downloads/).
Perhaps someone can branch this code I started and make it better or perfect.
Latest Version: 1.1
Screenshots
Installation
Add this line to:
/usr/local/cwpsrv/htdocs/resources/admin/include/3rdparty.php
<li><a href="index.php?module=cloudflare"><span class="icon16 icomoon-icon-arrow-right-3"></span>Cloudflare</a></li>
Then create a new file called "cloudflare.php" on:
/usr/local/cwpsrv/htdocs/resources/admin/modules
with this content:
<center><h2>Cloudflare Apache Module Installer</h2><h3>Version: 1.1</h3><a href="http://forum.centos-webpanel.com/new-modules/(module)-cloudflare-simple-1-click-install-or-uninstall/" target="_blank"><button type="button" class="btn btn-primary">Check for Update</button></a><hr></center>
<?php
$file = '/usr/local/apache/conf/httpd.conf';
$searchfor = 'LoadModule cloudflare_module /usr/lib64/httpd/modules/mod_cloudflare.so';
// get the file contents, assuming the file to be readable (and exist)
$contents = file_get_contents($file);
// escape special characters in the query
$pattern = preg_quote($searchfor, '/');
// finalise the regular expression, matching the whole line
$pattern = "/^.*$pattern.*\$/m";
// search, and store all matching occurences in $matches
if(preg_match_all($pattern, $contents, $matches)){
echo "<p class='text-success'>Cloudflare is installed already!</p>\n
<form action='' method='post'>
<button type='submit' name='uninstall' class='btn btn-danger'>Uninstall Cloudflare</button>
</form>
";
}
else{
echo "
<center><strong>Run these commands as root in SSH terminal</strong></center>
<pre>
mkdir /usr/local/cwpsrv/htdocs/resources/admin/modules/cloudflare
cd /usr/local/cwpsrv/htdocs/resources/admin/modules/cloudflare
wget https://www.cloudflare.com/static/misc/mod_cloudflare/mod_cloudflare.c
apxs -a -i -c mod_cloudflare.c
</pre>
Then click the green button below; then afterward go to the CWP Dashboard and Restart Apache
<p class='text-success'>Cloudflare is not installed!</p>\n
<form action='' method='post'>
<button type='submit' name='install' class='btn btn-success'>Install Cloudflare</button>
</form>";
}
?>
<?php
if(isset($_POST['install']))
{
//Add Cloudflare module to Apache
$path_to_file = '/usr/local/apache/conf/httpd.conf';
$file_contents = file_get_contents($path_to_file);
$file_contents = str_replace("# LoadModule foo_module modules/mod_foo.so","# LoadModule foo_module modules/mod_foo.so \nLoadModule cloudflare_module /usr/lib64/httpd/modules/mod_cloudflare.so",$file_contents);
file_put_contents($path_to_file,$file_contents);
echo "<center><h4>Go to CWP Dashboard and Restart Apache!</h4></center><br><br>
<h5>Refreshing page in 5 seconds to verify Cloudflare was installed.....</h5>
<meta http-equiv='refresh' content='5' />";
}
if(isset($_POST['uninstall']))
{
//Remove Cloudflare module to Apache
$path_to_file = '/usr/local/apache/conf/httpd.conf';
$file_contents = file_get_contents($path_to_file);
$file_contents = str_replace("LoadModule cloudflare_module /usr/lib64/httpd/modules/mod_cloudflare.so","",$file_contents);
file_put_contents($path_to_file,$file_contents);
echo "<center><h4>Go to CWP Dashboard and Restart Apache!</h4></center><br><br>
<h5>Refreshing page in 3 seconds to verify Cloudflare was uninstalled.....</h5>
<meta http-equiv='refresh' content='3' />";
}
?>