Skip to content

Commit

Permalink
improvements and fixes
Browse files Browse the repository at this point in the history
- fixed S3 bucket name validation.
- fixed wp backup with subfolder
- fixed wrong server names in cloned sites.
- fixed mysql binaty logs not disabled by default
- fixed log viewer for admin site.
  • Loading branch information
QROkes committed May 8, 2020
1 parent fd24fcd commit d1109f5
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 22 deletions.
16 changes: 9 additions & 7 deletions lib/bkp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

bkp_local_db() {
check_for_mysql_client
wp_dbdata $wp

[[ -z $wp || $wp == "true" ]] && read -p "${gre}WordPress site: ${end}" wp
if [[ -z $wp || $(is_wp $wp) != "true" ]]; then

wp_dbdata $wp
if [[ -z $wp || $(is_wp $wp $subfolder) != "true" ]]; then
echo "${red}[ERROR] Please, enter a valid WP site!${end}"
exit 1
elif [[ $(is_wp_installed $wp) != "true" ]]; then
Expand Down Expand Up @@ -110,7 +111,7 @@ bkp_s3_profile() {

[[ $add_db_pre == "true" ]] && read -p "${gre}WordPress site: ${end}" add_db_pre
# we dont check is_wp_installed because at this point we are still not doing a backup, just setting it.
if [[ -z $add_db_pre || $(is_wp $add_db_pre) != "true" ]]; then
if [[ -z $add_db_pre || $(is_wp $add_db_pre $subfolder) != "true" ]]; then
echo "${red}[ERROR] Please, enter a valid WP site!${end}"
exit 1
fi
Expand All @@ -124,7 +125,8 @@ bkp_s3_profile() {
[[ -z $destination || $destination == "true" ]] && destination="default"
[[ -z $max && $destination == "default" ]] && max="5"
[[ -n $max && $max =~ ^[0-9]+$ ]] && local param="-max=$max "
[[ -n $bucket && $bucket != "true" ]] && local param="${param}-bucket=$bucket"
[[ -n $bucket && $bucket != "true" ]] && local param="${param}-bucket=$bucket "
[[ -n $subfolder ]] && local param="${param}-subfolder=$subfolder"

[[ ! -f $HOME/.duply/$profile/pre ]] && sudo touch $HOME/.duply/$profile/pre
echo "sudo webinoly -backup=local -wp=$add_db_pre -destination=$destination $param" >> $HOME/.duply/$profile/pre
Expand All @@ -138,8 +140,8 @@ bkp_s3_profile() {

[[ -z $bucket || $bucket == "true" ]] && read -p "${gre}S3 Bucket name: ${end}" bucket
# Only numerals 0-9, basic Latin letters (only lowercase) and underscore.
if ! [[ $bucket =~ ^[0-9a-z\/_]+$ ]] || [[ -z $bucket || $(echo "$bucket" | cut -c-1) =~ [_|\/] || ${#bucket} -gt 63 || ${#bucket} -lt 3 ]]; then
echo "${red}[ERROR] Bucket names can only contain lowercase letters, numbers or underscores; must start with a letter or number and must be at least 3 and no more than 63 characters long.${end}"
if ! [[ $bucket =~ ^[0-9a-z\/-]+$ ]] || [[ -z $bucket || $(echo "$bucket" | cut -c-1) =~ [-|\/] || ${#bucket} -gt 63 || ${#bucket} -lt 3 ]]; then
echo "${red}[ERROR] Bucket names can only contain lowercase letters, numbers or hyphens; must start with a letter or number and must be at least 3 and no more than 63 characters long.${end}"
exit 1
fi

Expand Down Expand Up @@ -202,7 +204,7 @@ s3_send() {

[[ -z $bucket || $bucket == "true" ]] && read -p "${gre}S3 Bucket name: ${end}" bucket
# Only numerals 0-9, basic Latin letters (only lowercase) and underscore.
if ! [[ $bucket =~ ^[0-9a-z\/_]+$ ]] || [[ -z $bucket || $(echo "$bucket" | cut -c-1) =~ [_|\/] || ${#bucket} -gt 63 || ${#bucket} -lt 3 ]]; then
if ! [[ $bucket =~ ^[0-9a-z\/-]+$ ]] || [[ -z $bucket || $(echo "$bucket" | cut -c-1) =~ [-|\/] || ${#bucket} -gt 63 || ${#bucket} -lt 3 ]]; then
echo "${red}[WARNING] Seems like you're still using the old (deprecated) bucket naming schema."
echo "https://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html#bucketnamingrules${end}"
#exit 1
Expand Down
7 changes: 7 additions & 0 deletions lib/general
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ is_php() {

is_wp() {
# $1 = domain, $2 = WP subfolder
[[ -n $2 ]] && local subname=$(echo $2 | sed "s/\//_/g")
if [[ -z $2 && -f /etc/nginx/sites-available/$1 && -n $(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$1 | grep -F "wpcommon") ]]; then
echo "true"
elif [[ -n $2 && -f /etc/nginx/sites-available/$1 && -f /etc/nginx/apps.d/$1$subname-wpcommon.conf && -f /var/www/$1/htdocs$2/wp-config.php ]]; then
Expand All @@ -420,6 +421,7 @@ is_wp() {

is_wp_cache() {
# $1 = domain, $2 = WP subfolder
[[ -n $2 ]] && local subname=$(echo $2 | sed "s/\//_/g")
if [[ -z $2 && -f /etc/nginx/sites-available/$1 && -n $(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$1 | grep -F "wpfc.conf;") ]]; then
echo "true"
elif [[ -n $2 && -f /etc/nginx/sites-available/$1 && -n $(sed -n -e '/# WebinolyCustom/,$p' /etc/nginx/sites-available/$1 | grep -F "$1$subname-wpfc.conf;") ]]; then
Expand Down Expand Up @@ -515,3 +517,8 @@ is_subdomain() {
fi
}


is_log() {
[[ -f /etc/nginx/sites-available/$1 && -n $(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$1 | grep -F "nginx/$1.access.log ") ]] && echo "true" || echo "false"
}

3 changes: 2 additions & 1 deletion lib/install
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ mysql_install() {
# Binaly logs disabled by default and Error logging not in syslog (syslog is default).
sudo sed -i "/Logging and Replication/a \log_error = \/var\/log\/mysql\/error.log" /etc/mysql/my.cnf
sudo rm -rf /etc/mysql/conf.d/mysqld_safe_syslog.cnf

conf_write mysql true
sudo log -mysql=binary -disable > /dev/null 2>&1

#Instead of mysql_secure_installation we do this: (same but manually, because not acept unattended)
Expand All @@ -250,7 +252,6 @@ GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
_EOF_

conf_write mysql true
echo "${gre}MySQL has been installed successfully! ${end}"
api-events_update im4
}
Expand Down
14 changes: 6 additions & 8 deletions lib/sites
Original file line number Diff line number Diff line change
Expand Up @@ -1306,12 +1306,14 @@ clone_wp_site() {
sudo ln -s /etc/nginx/sites-available/$domain /etc/nginx/sites-enabled/$domain
sudo sed -i "s/$clone_from/$domain/g" /etc/nginx/sites-available/$domain

# Remove custom settings from cloned site
sudo site $domain -subdomain=false -force-redirect=off > /dev/null 2>&1
[[ $(is_ssl $clone_from) == "true" ]] && revoke="off" && site_ssl_off > /dev/null 2>&1
[[ $(conf_read default-site) == $clone_from ]] && remove_nginx_default_server $domain

# Fix server_name according to new domain/site.
[[ $subdomflag == "true" ]] && local sername="server_name $domain;" || local sername="server_name $domain www.$domain;"
sudo sed -i "/server_name /c \ $sername" /etc/nginx/sites-available/$domain

# Prevent if main site is default.
[[ $(conf_read default-site) == $clone_from ]] && remove_nginx_default_server $domain
fi

local dom=$(echo $domain$subfolder | sed "s/[^0-9A-Za-z]/_/g")
Expand All @@ -1334,16 +1336,12 @@ clone_wp_site() {
sudo sed -i "/'WP_CACHE_KEY_SALT'/d" $wpcon
sudo sed -i "/stop editing/i \define('WP_CACHE_KEY_SALT', 'redis_object_cache_for_wp_$domain$(echo $subfolder | sed "s/\//_/g")');" $wpcon

# Remove custom settings from cloned site
sudo site $domain -subdomain=false -force-redirect=off > /dev/null 2>&1
[[ $(is_ssl $clone_from) == "true" ]] && revoke="off" && site_ssl_off > /dev/null 2>&1


if [[ $replace_content != "off" ]]; then
replace_content="[http://$clone_from,http://$domain]" && wp_replace_content > /dev/null 2>&1
replace_content="[https://$clone_from,http://$domain]" && wp_replace_content > /dev/null 2>&1
replace_content="[$clone_from,$domain]" && wp_replace_content > /dev/null 2>&1
fi

echo "${gre}Site ${blu}'$domain$subfolder'${gre} is now a successfull clone of ${blu}'$clone_from$subfolder'${end}"
}

Expand Down
8 changes: 3 additions & 5 deletions plugins/log
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,14 @@ elif [[ -n $only_error ]]; then
# Per site
if [[ -n $domain && -f /etc/nginx/sites-available/$domain ]]; then
check_for_nginx
islog=$( grep -F "access_log off;" /etc/nginx/sites-available/$domain )
if [[ $domain == "default" || $domain == $(conf_read tools-port) ]]; then
echo "${red}[ERROR] Only-Error is not allowed to be used in Tools-Port or Default Nginx site! ${end}"
exit 1
fi

if [[ $only_error == "on" ]]; then
api-events_update lg3
if [[ -z $islog ]]; then
if [[ $(is_log $domain) == "true" ]]; then
sudo sed -i '/access_log/c \ access_log off;' /etc/nginx/sites-available/$domain
sudo service nginx reload
echo "${gre}Only-Error Log was successfully enabled for ${blu}${domain} ${gre}site!${end}"
Expand All @@ -238,7 +237,7 @@ elif [[ -n $only_error ]]; then
fi
elif [[ $only_error == "off" ]]; then
api-events_update lg4
if [[ -n $islog ]]; then
if [[ $(is_log $domain) != "true" ]]; then
sudo sed -i "/access_log/c \ access_log \/var\/log\/nginx\/${domain}.access.log we_log;" /etc/nginx/sites-available/$domain
sudo service nginx reload
echo "${gre}Only-Error Log was successfully disabled for ${blu}${domain} ${gre}site!${end}"
Expand All @@ -255,8 +254,7 @@ elif [[ -n $only_error ]]; then
# Site log files
elif [[ -n $domain && -f /etc/nginx/sites-available/$domain ]]; then
# Check if Access Log is enabled
islog=$( grep -F "access_log off;" /etc/nginx/sites-available/$domain )
if [[ -z $error && -z $wp && -n $islog ]]; then
if [[ -z $error && -z $wp && $(is_log $domain) != "true" ]]; then
echo "${red}[ERROR] Access Log for${blu} $domain ${red}is disabled!${end}"
exit 1
fi
Expand Down
5 changes: 4 additions & 1 deletion plugins/site
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ if [[ -n $subfolder && ! ( $subfolder =~ ^\/([A-Za-z0-9_\/\-]+)?[^\/]$ ) ]]; the
elif [[ -n $subfolder && $type != [123] && -z $delete && -z $cache && -z $yoast_sitemap && -z $multisite_convert && -z $clone_from && -z $replace_content ]]; then
echo "${red}[ERROR] Subfolder option is only supported for WordPress sites!${end}"
exit 1
elif [[ -n $subfolder && ( -n $delete || -n $cache || -n $yoast_sitemap || -n $multisite_convert || -n $clone_from || -n $replace_content ) && ! -d /var/www/$domain/htdocs$subfolder ]]; then
elif [[ -n $subfolder && ( -n $delete || -n $cache || -n $yoast_sitemap || -n $multisite_convert || -n $replace_content ) && ! -d /var/www/$domain/htdocs$subfolder ]]; then
echo "${red}[ERROR] Subfolder not found!${end}"
exit 1
elif [[ -n $subfolder && -n $clone_from && ! -d /var/www/$clone_from/htdocs$subfolder ]]; then
echo "${red}[ERROR] Subfolder not found!${end}"
exit 1
else
Expand Down

0 comments on commit d1109f5

Please sign in to comment.