Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Aut 05 2016 CloudFlare Inc <[email protected]> - 2016.8.0
- Updated CloudFlare IPv6 ranges
- Support for installing on EasyApache4

* Jun 01 2016 CloudFlare Inc <[email protected]> - 2016.6.0
- Set HTTPS envrionment variable for Flexible SSL reqquests

Expand Down
122 changes: 106 additions & 16 deletions EasyApache/installer.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,111 @@
#!/bin/bash -e
# Location where to install on cPanel server
CPANEL_DIR="/var/cpanel/easy/apache/custom_opt_mods"
INSTALL_DIR="$CPANEL_DIR/Cpanel/Easy"

if [ ! -d "$CPANEL_DIR" ]; then
echo "$CPANEL_DIR not found. This script should only be used on servers that have cPanel installed."
exit 1
fi
#
# Install mod_cloudflare for EasyApache 3
#
function install_ea3 {

# Location where to install on cPanel server
CPANEL_DIR="/var/cpanel/easy/apache/custom_opt_mods"
INSTALL_DIR="$CPANEL_DIR/Cpanel/Easy"

if [ ! -d "$CPANEL_DIR" ]; then
echo "$CPANEL_DIR not found. This script should only be used on servers that have cPanel installed."
exit 1
fi

if [ ! -d "$INSTALL_DIR" ]; then
mkdir -p "$INSTALL_DIR"
fi

# Download & tar mod_cloudflare.c
mkdir mod_cloudflare && cd mod_cloudflare && wget "https://raw.githubusercontent.com/cloudflare/mod_cloudflare/master/mod_cloudflare.c" && cd ..
tar -cvzf $INSTALL_DIR/ModCloudflare.pm.tar.gz mod_cloudflare/mod_cloudflare.c

# Download ModCloudflare.pm into cPanel directory
wget -O $INSTALL_DIR/ModCloudflare.pm https://raw.githubusercontent.com/cloudflare/mod_cloudflare/master/EasyApache/ModCloudflare.pm

# Remove leftover files
rm -rf mod_cloudflare/
echo "Done. Please restart EasyApache 3"
exit

}

#
# Install mod_cloudflare for EasyApache 4
#
function install_ea4 {

#
# Reasonably reliable way to get OS distribution name and version
#
DISTRO_NAME=`cat /etc/os-release | grep "^NAME" | sed 's/NAME="//' | sed 's/"//'`
DISTRO_VERSION=`cat /etc/os-release | grep "^VERSION_ID" | sed 's/VERSION_ID="//' | sed 's/"//'`

# Remove trailing minor version
DISTRO_VERSION=`sed "s/\..*//" <<<"$DISTRO_VERSION"`

if [[ $DISTRO_VERSION == "6" || $DISTRO_VERSION == "7" ]]; then
echo
echo "Installing mod_cloudflare for EasyApache 4 on '$DISTRO_NAME $DISTRO_VERSION'"
else
echo "ERROR - Your distribution '$DISTRO_NAME $DISTRO_VERSION' is not supported"
exit
fi

#
# Location of the vanilla RPM packages. We'll have to extract certain files and
# put them where EasyApache 4 wants them.
#
DOWNLOAD_URL="https://www.cloudflare.com/static/misc/mod_cloudflare/centos/mod_cloudflare-el$DISTRO_VERSION-x86_64.latest.rpm"

# Make sure that the directories we want exist
if [ ! -d "/etc/apache2/conf.d" ]; then
echo "ERROR - missing /etc/apache2/conf.d, is EasyApache 4 installed?"
exit;
fi
if [ ! -d "/usr/lib64/apache2/modules" ]; then
echo "ERROR - missing /usr/lib64/apache2/modules, is EasyApache 4 installed?"
exit;
fi

# Download the correct RPM package
# echo "Fetching mod_cloudflare..."
# echo "curl -o /tmp/mod_cloudflare.rpm $DOWNLOAD_URL 2>/dev/null";
curl -o /tmp/mod_cloudflare.rpm $DOWNLOAD_URL 2>/dev/null;

# Extract the mod_cloudflare config file, fix up the path to where EasyApache 4
# installs modules, and write it out to the config dir
# echo "Installing /etc/apache2/conf.d/cloudflare.conf"
rpm2cpio /tmp/mod_cloudflare.rpm | cpio --to-stdout -iv ./etc/httpd/conf.d/cloudflare.conf 2>/dev/null | sed 's/httpd/apache2/' >/etc/apache2/conf.d/cloudflare.conf 2>/dev/null

# Extract the mod_cloudflare module binary file and put it where EasyApache 4 wants it
# echo "Installing /usr/lib64/apache2/modules/mod_cloudflare.so"
rpm2cpio /tmp/mod_cloudflare.rpm | cpio --to-stdout -iv ./usr/lib64/httpd/modules/mod_cloudflare.so >/usr/lib64/apache2/modules/mod_cloudflare.so 2>/dev/null

# Cleanup
rm /tmp/mod_cloudflare.rpm

echo
echo "Done. Please restart EasyApache 4"
echo
exit
}

#
# Main
#

#
# Check which version of cPanel we have
#
CPANEL_VERSION=`/usr/local/cpanel/cpanel -V | sed "s/\..*$//"`

if [ ! -d "$INSTALL_DIR" ]; then
mkdir -p "$INSTALL_DIR"
# Version 58 and up have Easy Apache 4
if [ "$CPANEL_VERSION" -gt "57" ]; then
install_ea4
else
install_ea3
fi

# Download & tar mod_cloudflare.c
mkdir mod_cloudflare && cd mod_cloudflare && wget "https://raw.githubusercontent.com/cloudflare/mod_cloudflare/master/mod_cloudflare.c" && cd ..
tar -cvzf $INSTALL_DIR/ModCloudflare.pm.tar.gz mod_cloudflare/mod_cloudflare.c
# Download ModCloudflare.pm into cPanel directory
wget -O $INSTALL_DIR/ModCloudflare.pm https://raw.githubusercontent.com/cloudflare/mod_cloudflare/master/EasyApache/ModCloudflare.pm
# Remove leftover files
rm -rf mod_cloudflare/
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
MAJOR=2016
MINOR=6
MINOR=8
BUILD=0
7 changes: 4 additions & 3 deletions mod_cloudflare.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* CloudFlareIPHeader CF-Connecting-IP
* CloudFlareIPTrustedProxy 204.93.173.0/24
*
* Version 1.0.3
*/

#include "ap_config.h"
Expand Down Expand Up @@ -60,10 +59,12 @@ static const char* CF_DEFAULT_TRUSTED_PROXY[] = {
"199.27.128.0/21",
/* IPv6 Address Ranges */
"2400:cb00::/32",
"2405:8100::/32",
"2405:b500::/32",
"2606:4700::/32",
"2803:f800::/32",
"2405:b500::/32",
"2405:8100::/32",
"2c0f:f248::/32",
"2a06:98c0::/29",
};
static const size_t CF_DEFAULT_TRUSTED_PROXY_COUNT =
sizeof(CF_DEFAULT_TRUSTED_PROXY)/sizeof(char *);
Expand Down