Author Topic: [module] Cloudflare - Simple 1-click install or uninstall  (Read 3429 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
[module] Cloudflare - Simple 1-click install or uninstall
« on: January 07, 2016, 03:46:39 PM »
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.  ;D 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 version
I 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
Quote
<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:
Quote
<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' />";

}
?>
« Last Edit: January 07, 2016, 05:17:40 PM by bentheman96 »

Offline
**
Re: [module] Cloudflare - Simple 1-click install or uninstall
« Reply #1 on: January 29, 2016, 11:19:54 PM »
Thanks buddy :)

Offline
*
Re: [module] Cloudflare - Simple 1-click install or uninstall
« Reply #2 on: July 12, 2016, 05:03:40 PM »
there is further ideas   ???

Offline
*
Re: [module] Cloudflare - Simple 1-click install or uninstall
« Reply #3 on: July 19, 2016, 02:23:50 PM »
I would love to use this module, is expected to be able to use it?

 :)

Offline
*
Re: [module] Cloudflare - Simple 1-click install or uninstall
« Reply #4 on: July 21, 2017, 06:29:24 PM »
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Fri 2017-07-21 14:27:14 EDT; 2s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 15689 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
  Process: 15687 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
 Main PID: 15687 (code=exited, status=1/FAILURE)

I have this error and it does not start me apache.can help me

Offline
*
Re: [module] Cloudflare - Simple 1-click install or uninstall
« Reply #5 on: July 22, 2017, 03:17:16 AM »
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Fri 2017-07-21 14:27:14 EDT; 2s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 15689 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
  Process: 15687 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
 Main PID: 15687 (code=exited, status=1/FAILURE)

I have this error and it does not start me apache.can help me

Well, he did say, do not Install it in a RED BIG FONT. Probably because the module break or something.