HEX
Server: nginx/1.29.3
System: Linux 11979.bigscoots-wpo.com 6.8.0-88-generic #89-Ubuntu SMP PREEMPT_DYNAMIC Sat Oct 11 01:02:46 UTC 2025 x86_64
User: nginx (1068)
PHP: 7.4.33
Disabled: exec,system,passthru,shell_exec,proc_open,proc_close,popen,show_source,cmd# Do not modify this line # 1684243876
Upload Files
File: //bigscoots/wpo/cloudflare/create_pkey.sh
#!/bin/bash

source /bigscoots/includes/common.sh

if [ -n "$5" ]
then
        echo "There are too many options ran with the command, exiting."
        exit
fi

DOMAIN=$1

site_id=$2
master_key=$3
p_key=$4

if [ -d /etc/cpanel ]
then
        DOCROOT=$(whmapi1 domainuserdata domain="$DOMAIN" |grep documentroot: | awk '{print $2}')
        HOMEDIR=$(whmapi1 domainuserdata domain="$DOMAIN" |grep homedir: | awk '{print $2}')
        wpconfig_path=$(wpcli config path --path="${DOCROOT}")
        mkdir -p "${HOMEDIR}"/.bigscoots/cf
else
        DOCROOT=/home/nginx/domains/"${DOMAIN}"/public
        HOMEDIR=/home/nginx
        wpconfig_path=$(wpcli config path --path="${DOCROOT}")
        mkdir -p ${HOMEDIR}/.bigscoots/cf
fi

mkdir -p "${HOMEDIR}"/.bigscoots/cf

if [ -f "${HOMEDIR}"/.bigscoots/cf/pkey_"${p_key}".php ]
then
        if ! grep -q "${site_id}" "${HOMEDIR}"/.bigscoots/cf/pkey_"${p_key}".php
        then
                sed -i '/BS_SITE_ID/d' ./infile
                echo "define('BS_SITE_ID', ${site_id});" >> "${HOMEDIR}"/.bigscoots/cf/pkey_"${p_key}".php
        fi
        if ! grep -q "${master_key}" "${HOMEDIR}"/.bigscoots/cf/pkey_"${p_key}".php
        then
                sed -i '/BS_MASTER_KEY/d' ./infile
                echo "define('BS_MASTER_KEY', ${master_key});" >> "${HOMEDIR}"/.bigscoots/cf/pkey_"${p_key}".php
        fi
else
        cat >"${HOMEDIR}"/.bigscoots/cf/pkey_"${p_key}".php <<EOL
<?php
define('BS_SITE_ID', '${site_id}');
define('BS_MASTER_KEY', '${master_key}');
?>
EOL
fi

if ! grep -q .bigscoots/cf/pkey "${wpconfig_path}" 
then
        if ! wpcli config set BIGSCOOTS_CFE on --quiet --path="${DOCROOT}"
        then
                bash /bigscoots/general/slack.sh "#cloudflare" ":warning: $(hostname) -  ${serverip} - Failed to add options in ${DOCROOT}/wp-config.php \n \n \
                Add the following lines into wp-config.php: \n \n \
                define( 'BIGSCOOTS_CFE', 'on' ); \n \
                include ( dirname(__DIR__) . '/../../.bigscoots/cf/pkey_""${p_key}"".php' );"
                exit 1
        fi
        if [ -d /etc/cpanel ]
        then
                sed -i "/BIGSCOOTS_CFE/a\\include ( '${HOMEDIR}/.bigscoots/cf/pkey_${p_key}.php' );\n\n" "${wpconfig_path}"
        else
                sed -i "/BIGSCOOTS_CFE/a\\include ( dirname(__DIR__) . '/../../.bigscoots/cf/pkey_${p_key}.php' );\n\n" "${wpconfig_path}"
        fi
fi 2>/dev/null