| Server IP : 172.67.149.12 / Your IP : 104.23.243.226 Web Server : Apache System : Linux vm3310.eosdns.net 4.18.0-553.132.1.el8_10.x86_64 #1 SMP Thu Jun 11 14:27:43 UTC 2026 x86_64 User : carnalmedia ( 1000) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /mojo/ |
Upload File : |
#!/bin/bash
#
# Script: add_wp_ftp
#
# Usage: add_wp_ftp
#
# Description: A tool for adding FTP accounts to wp-config.php configuration files to allow automatic updates
#
# Author: Adam Gomulka
#
# Changelog:
# * 07/31/2016: Jeremy Butler
# - Fixed script name in header
# - Issue #115 solution, script no longer prompts for ticket number and instead uses -z flag
# - Mjlogger lines added
# - Script updated to use current working directory instead of prompting
# * 08.04.2021: Nikita Shchetinin
# - CentOS 8 compatibility and refactoring
# * 30.07.2021: Nikita Shchetinin
# - Security fix
# * 20.01.2023: Nikita Shchetinin
# - Compatibility fix
if [ "$(whoami)" != 'root' ]
then
echo "You must execute this script as the root user!"
exit 1
fi
ADD () {
wp_dir=$(pwd)
local_user=$(stat -c '%U' $wp_dir)
if [ $local_user == 'root' ]
then
echo "The root directory of WordPress may not belong to the root user!"
exit 1
fi
ftp_user=$(</dev/urandom tr -dc A-Za-z | head -c5)
if [ -f $wp_dir/wp-config.php ]
then
if grep -q "FTP" $wp_dir/wp-config.php
then
echo "Existing FTP configuration is found in wp-config.php!"
exit 1
else
ftp_account=$(mjact_ftp -a add -n ${ftp_user}_wp -u $local_user -f $wp_dir)
ftp_hostname=$(echo $ftp_account | awk '{ print $2 }')
ftp_username=$(echo $ftp_account | awk '{ print $7 }')
ftp_password=$(echo $ftp_account | awk '{ print $10 }')
wp_config_fsmethod="define( 'FS_METHOD', 'ftpext' );"
wp_config_ssl="define( 'FTP_SSL', true );"
wp_config_hostname="define( 'FTP_HOST', '$ftp_hostname' );"
wp_config_username="define( 'FTP_USER', '$ftp_username' );"
wp_config_password="define( 'FTP_PASS', '$ftp_password' );"
sed -i "/That's all/i $wp_config_fsmethod" $wp_dir/wp-config.php
sed -i "/That's all/i $wp_config_ssl" $wp_dir/wp-config.php
sed -i "/That's all/i $wp_config_hostname" $wp_dir/wp-config.php
sed -i "/That's all/i $wp_config_username" $wp_dir/wp-config.php
sed -i "/That's all/i $wp_config_password" $wp_dir/wp-config.php
fi
else
echo "wp-config.php has not been found in this directory!"
exit 1
fi
}
HELP () {
echo "A tool for adding FTP accounts to wp-config.php configuration files to allow automatic updates"
echo "usage: add_wp_ftp"
}
if [[ "${1}" == "-h" ]] || [[ "${1}" == "--help" ]]
then
HELP
else
ADD
fi