code revision
Full code test and revision
This commit is contained in:
parent
70d535139a
commit
04b11c03be
11 changed files with 1415 additions and 1314 deletions
2
lib/bkp
2
lib/bkp
|
@ -122,7 +122,7 @@ bkp_s3_list() {
|
|||
for f in /root/.duply/*
|
||||
do
|
||||
[[ -d $f ]] && pro=$(echo $f | cut -f 4 -d "/" -s)
|
||||
[[ -a $f/conf ]] && fail="" || fail="${red}(fail)${end}"
|
||||
[[ -f $f/conf ]] && fail="" || fail="${red}(fail)${end}"
|
||||
[[ -n $raw || $list == "raw" ]] && outlist="$pro" || outlist=" ${gre}+ $pro ${end}${fail}"
|
||||
if [[ -n $outlist ]]; then
|
||||
echo "$outlist"
|
||||
|
|
28
lib/general
28
lib/general
|
@ -122,7 +122,7 @@ check_for_mysql() {
|
|||
|
||||
|
||||
conf_read() {
|
||||
if [[ ! -a /opt/webinoly/webinoly.conf ]]; then
|
||||
if [[ ! -f /opt/webinoly/webinoly.conf ]]; then
|
||||
echo "${red}[ERROR] Config file not found!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
@ -132,7 +132,7 @@ conf_read() {
|
|||
}
|
||||
|
||||
conf_delete() {
|
||||
if [[ ! -a /opt/webinoly/webinoly.conf ]]; then
|
||||
if [[ ! -f /opt/webinoly/webinoly.conf ]]; then
|
||||
echo "${red}[ERROR] Config file not found!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
@ -141,7 +141,7 @@ conf_delete() {
|
|||
}
|
||||
|
||||
conf_write() {
|
||||
[[ ! -a /opt/webinoly/webinoly.conf ]] && sudo touch /opt/webinoly/webinoly.conf
|
||||
[[ ! -f /opt/webinoly/webinoly.conf ]] && sudo touch /opt/webinoly/webinoly.conf
|
||||
conf_delete $1
|
||||
echo "$1:$2" >> /opt/webinoly/webinoly.conf
|
||||
}
|
||||
|
@ -157,9 +157,9 @@ wp_dbdata() {
|
|||
fi
|
||||
|
||||
# Get dbname and dbuser of a WP site
|
||||
if [[ -a /var/www/$domain/htdocs$subfolder/wp-config.php ]]; then
|
||||
if [[ -f /var/www/$domain/htdocs$subfolder/wp-config.php ]]; then
|
||||
wpconfpath="/var/www/$domain/htdocs$subfolder/wp-config.php"
|
||||
elif [[ -a /var/www/$domain/wp-config.php ]]; then
|
||||
elif [[ -f /var/www/$domain/wp-config.php ]]; then
|
||||
wpconfpath="/var/www/$domain/wp-config.php"
|
||||
else
|
||||
return
|
||||
|
@ -261,7 +261,7 @@ tools_port() {
|
|||
|
||||
api-events_update() {
|
||||
conf_write status-api $1
|
||||
if [[ -a /opt/webinoly/lib/api-events ]]; then
|
||||
if [[ -f /opt/webinoly/lib/api-events ]]; then
|
||||
source /opt/webinoly/lib/api-events
|
||||
api-events_catch_status $1
|
||||
fi
|
||||
|
@ -316,18 +316,18 @@ ip_check() {
|
|||
|
||||
|
||||
is_ssl() {
|
||||
[[ -a /etc/nginx/sites-available/$1 && -n $(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$1 | grep -F "ssl_certificate_key") ]] && echo "true" || echo "false"
|
||||
[[ -f /etc/nginx/sites-available/$1 && -n $(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$1 | grep -F "ssl_certificate_key") ]] && echo "true" || echo "false"
|
||||
}
|
||||
|
||||
is_php() {
|
||||
[[ -a /etc/nginx/sites-available/$1 && -n $(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$1 | grep -F "php.conf;") ]] && echo "true" || echo "false"
|
||||
[[ -f /etc/nginx/sites-available/$1 && -n $(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$1 | grep -F "php.conf;") ]] && echo "true" || echo "false"
|
||||
}
|
||||
|
||||
is_wp() {
|
||||
# $1 = domain, $2 = WP subfolder
|
||||
if [[ -z $2 && -a /etc/nginx/sites-available/$1 && -n $(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$1 | grep -F "wpcommon") ]]; then
|
||||
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 && -a /etc/nginx/sites-available/$1 && -a /etc/nginx/apps.d/$1$subname-wpcommon.conf && -a /var/www/$1/htdocs$2/wp-config.php ]]; then
|
||||
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
|
||||
echo "true"
|
||||
else
|
||||
echo "false"
|
||||
|
@ -336,9 +336,9 @@ is_wp() {
|
|||
|
||||
is_wp_cache() {
|
||||
# $1 = domain, $2 = WP subfolder
|
||||
if [[ -z $2 && -a /etc/nginx/sites-available/$1 && -n $(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$1 | grep -F "wpfc.conf;") ]]; then
|
||||
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 && -a /etc/nginx/sites-available/$1 && -n $(sed -n -e '/# WebinolyCustom/,$p' /etc/nginx/sites-available/$1 | grep -F "$1$subname-wpfc.conf;") ]]; then
|
||||
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
|
||||
echo "true"
|
||||
else
|
||||
echo "false"
|
||||
|
@ -369,9 +369,9 @@ is_wp_multisite() {
|
|||
}
|
||||
|
||||
is_proxy() {
|
||||
[[ -a /etc/nginx/sites-available/$1 && -n $(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$1 | grep -F "proxy_pass") ]] && echo "true" || echo "false"
|
||||
[[ -f /etc/nginx/sites-available/$1 && -n $(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$1 | grep -F "proxy_pass") ]] && echo "true" || echo "false"
|
||||
}
|
||||
|
||||
is_parked() {
|
||||
[[ -a /etc/nginx/sites-available/$1 && ! -d /var/www/$1 && $(is_proxy $1) == "false" ]] && echo "true" || echo "false"
|
||||
[[ -f /etc/nginx/sites-available/$1 && ! -d /var/www/$1 && $(is_proxy $1) == "false" ]] && echo "true" || echo "false"
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ linux_optim() {
|
|||
local cacheram=$(($nginxfd/1024))
|
||||
|
||||
[ -d /etc/systemd/system/nginx.service.d ] || sudo mkdir /etc/systemd/system/nginx.service.d
|
||||
[ -a /etc/systemd/system/nginx.service.d/nofile_limit.conf ] || sudo touch /etc/systemd/system/nginx.service.d/nofile_limit.conf
|
||||
[ -f /etc/systemd/system/nginx.service.d/nofile_limit.conf ] || sudo touch /etc/systemd/system/nginx.service.d/nofile_limit.conf
|
||||
sudo echo "[Service]
|
||||
LimitNOFILE=$nginxfd" | tee -a /etc/systemd/system/nginx.service.d/nofile_limit.conf
|
||||
|
||||
|
@ -270,7 +270,7 @@ nginx_optim() {
|
|||
# www-data sftp default uploads permissions 755 and 644, instead of 775 and 664.
|
||||
sudo sed -i '/USERGROUPS_ENAB/c \USERGROUPS_ENAB no' /etc/login.defs
|
||||
|
||||
if [[ ! -a /etc/ssl/dhparam.pem ]]; then
|
||||
if [[ ! -f /etc/ssl/dhparam.pem ]]; then
|
||||
sudo openssl dhparam -out /etc/ssl/dhparam.pem 2048
|
||||
sudo chmod 600 /etc/ssl/dhparam.pem
|
||||
fi
|
||||
|
@ -389,7 +389,7 @@ nginx_tool() {
|
|||
[[ -z $(conf_read tools-port) ]] && tools_port 22222
|
||||
[[ $(conf_read php) == "true" ]] && nginx_tool_site
|
||||
# in case php was installed before nginx
|
||||
[[ $(conf_read php-tool) == "true" && ! -a /var/www/$(conf_read tools-port)/htdocs/php/index.php ]] && php_tool_site
|
||||
[[ $(conf_read php-tool) == "true" && ! -f /var/www/$(conf_read tools-port)/htdocs/php/index.php ]] && php_tool_site
|
||||
|
||||
# Install LetsEncrypt
|
||||
echo | sudo add-apt-repository ppa:certbot/certbot
|
||||
|
@ -432,7 +432,7 @@ redis_optim() {
|
|||
php_tool() {
|
||||
api-events_update ip5
|
||||
# in case nginx was installed before php
|
||||
[[ $(conf_read nginx-tool) == "true" && ! -a /etc/nginx/sites-available/$(conf_read tools-port) ]] && nginx_tool_site
|
||||
[[ $(conf_read nginx-tool) == "true" && ! -f /etc/nginx/sites-available/$(conf_read tools-port) ]] && nginx_tool_site
|
||||
[[ $(conf_read nginx) == "true" ]] && php_tool_site
|
||||
|
||||
# Redis (Object Cache)
|
||||
|
|
24
lib/site-ssl
24
lib/site-ssl
|
@ -25,7 +25,7 @@ ssl_nginx() {
|
|||
sudo chmod 755 $(dirname -- $ssl_crt)
|
||||
sudo chmod 755 $(dirname -- $ssl_key)
|
||||
sudo chown -R root:root $(dirname -- $ssl_crt)
|
||||
if [[ -n $ssl_ocsp && -a $ssl_ocsp ]]; then
|
||||
if [[ -n $ssl_ocsp && -f $ssl_ocsp ]]; then
|
||||
sudo sed -i "/ssl_trusted_certificate/c \ ssl_trusted_certificate $ssl_ocsp;" /etc/nginx/sites-available/$domain
|
||||
sudo chmod 777 $ssl_ocsp
|
||||
sudo chmod 755 $(dirname -- $ssl_ocsp)
|
||||
|
@ -53,9 +53,9 @@ site_ssl_on() {
|
|||
|
||||
# Some validations to prevent errors when creating certs.
|
||||
check_for_nginx_tool
|
||||
if [[ -n $root && -a /etc/nginx/sites-available/$root ]]; then
|
||||
if [[ -n $root && -f /etc/nginx/sites-available/$root ]]; then
|
||||
path=$root
|
||||
elif [[ -n $root && ! -a /etc/nginx/sites-available/$root ]]; then
|
||||
elif [[ -n $root && ! -f /etc/nginx/sites-available/$root ]]; then
|
||||
echo "${red}[ERROR] Root path domain is not a valid domain or is not found/hosted in this server!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
@ -71,7 +71,7 @@ site_ssl_on() {
|
|||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -a /etc/letsencrypt/live/$domain/fullchain.pem && $ssl == "force-renewal" ]]; then
|
||||
if [[ ! -f /etc/letsencrypt/live/$domain/fullchain.pem && $ssl == "force-renewal" ]]; then
|
||||
echo "${red}[ERROR] Cert you're trying to renew not found!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
@ -111,30 +111,30 @@ site_ssl_on() {
|
|||
[[ $subdomflag == 1 ]] && local domset="-d $domain" || local domset="-d $domain -d www.$domain"
|
||||
|
||||
# Wildcard
|
||||
if [[ ( ! -a /etc/letsencrypt/live/$domain/fullchain.pem || $ssl == "force-renewal" ) && -n $wildcard ]]; then
|
||||
if [[ ( ! -f /etc/letsencrypt/live/$domain/fullchain.pem || $ssl == "force-renewal" ) && -n $wildcard ]]; then
|
||||
sudo certbot certonly --manual --preferred-challenges=dns --manual-public-ip-logging-ok -d $domain -d *.$domain $param
|
||||
|
||||
# Manual mode for Reverse Proxy sites
|
||||
elif [[ ( ! -a /etc/letsencrypt/live/$domain/fullchain.pem || $ssl == "force-renewal" ) && -n $root_path ]]; then
|
||||
elif [[ ( ! -f /etc/letsencrypt/live/$domain/fullchain.pem || $ssl == "force-renewal" ) && -n $root_path ]]; then
|
||||
conf_write temp-path $root_path
|
||||
sudo certbot certonly --manual --preferred-challenges=http --manual-auth-hook /opt/webinoly/lib/ex-ssl-authentication --manual-cleanup-hook /opt/webinoly/lib/ex-ssl-cleanup --manual-public-ip-logging-ok $domset $param
|
||||
conf_delete temp-path
|
||||
|
||||
# Single cert
|
||||
elif [[ ! -a /etc/letsencrypt/live/$domain/fullchain.pem || $ssl == "force-renewal" ]]; then
|
||||
elif [[ ! -f /etc/letsencrypt/live/$domain/fullchain.pem || $ssl == "force-renewal" ]]; then
|
||||
sudo certbot certonly --webroot -w /var/www/$path/htdocs/ $domset $param
|
||||
|
||||
elif [[ -a /etc/letsencrypt/live/$domain/fullchain.pem ]]; then
|
||||
elif [[ -f /etc/letsencrypt/live/$domain/fullchain.pem ]]; then
|
||||
echo "${blu}Certificate for${end} $domain ${blu}already exist and found, wait while we configure your server to use it!${end}"
|
||||
fi
|
||||
|
||||
|
||||
# SSL Nginx Conf
|
||||
if [[ -a /etc/letsencrypt/live/$domain/fullchain.pem && $ssl != "force-renewal" ]]; then
|
||||
if [[ -f /etc/letsencrypt/live/$domain/fullchain.pem && $ssl != "force-renewal" ]]; then
|
||||
ssl_nginx
|
||||
|
||||
# Auto-Renew Certificate
|
||||
if [[ ! -a /var/spool/cron/crontabs/root ]]; then
|
||||
if [[ ! -f /var/spool/cron/crontabs/root ]]; then
|
||||
sudo touch /var/spool/cron/crontabs/root
|
||||
sudo chmod 600 /var/spool/cron/crontabs/root
|
||||
sudo chown root:crontab /var/spool/cron/crontabs/root
|
||||
|
@ -146,9 +146,9 @@ site_ssl_on() {
|
|||
[[ -z $cronrene ]] && echo '15 3 * * 7 certbot renew --post-hook "service nginx restart"' | sudo tee -a /var/spool/cron/crontabs/root > /dev/null
|
||||
|
||||
echo "${gre}SSL have been successfully enabled for your site -${blu} $domain${end}"
|
||||
elif [[ -a /etc/letsencrypt/live/$domain/fullchain.pem && $ssl == "force-renewal" ]]; then
|
||||
elif [[ -f /etc/letsencrypt/live/$domain/fullchain.pem && $ssl == "force-renewal" ]]; then
|
||||
echo "${gre}SSL Cert ${blu}- $domain$ - ${gre}has been Forced to Renew!${end}"
|
||||
elif [[ ! -a /etc/letsencrypt/live/$domain/fullchain.pem ]]; then
|
||||
elif [[ ! -f /etc/letsencrypt/live/$domain/fullchain.pem ]]; then
|
||||
echo "${red}"
|
||||
echo "[ERROR] Unable to create the new certificate!"
|
||||
echo "${end}"
|
||||
|
|
489
lib/sites
489
lib/sites
|
@ -529,7 +529,7 @@ deletesite() {
|
|||
for site in "/etc/nginx/apps.d/$domain_"*-php.conf
|
||||
do
|
||||
subfolder="/$(echo $site | cut -f 2- -d "_" -s | cut -f -1 -d "-" -s | sed "s/_/\//g")"
|
||||
if [[ -n $subfolder && -a /var/www/$domain/htdocs$subfolder/wp-config.php ]]; then
|
||||
if [[ -n $subfolder && -f /var/www/$domain/htdocs$subfolder/wp-config.php ]]; then
|
||||
if ! [[ $delete =~ ^(force|keep-db)$ ]]; then
|
||||
echo "${blu}Delete Database ${end}'$domain$subfolder'${blu} [Y/n]?${end}"
|
||||
while read -r -n 1 -s dbsubdel; do
|
||||
|
@ -547,7 +547,7 @@ deletesite() {
|
|||
fi
|
||||
|
||||
# Determine if main site is WP, so you should delete the DB too.
|
||||
if [[ ( -z $dbdel || $dbdel = [Yy] ) && ( -a /var/www/$domain/wp-config.php || -a /var/www/$domain/htdocs/wp-config.php ) ]]; then
|
||||
if [[ ( -z $dbdel || $dbdel = [Yy] ) && ( -f /var/www/$domain/wp-config.php || -f /var/www/$domain/htdocs/wp-config.php ) ]]; then
|
||||
if ! [[ $delete =~ ^(force|keep-db)$ ]]; then
|
||||
echo "${blu}Delete Database ${end}'$domain$subfolder'${blu} [Y/n]?${end}"
|
||||
while read -r -n 1 -s dbdel; do
|
||||
|
@ -594,7 +594,7 @@ createsite() {
|
|||
fi
|
||||
|
||||
# Check for duplicate sites
|
||||
if [[ -a /etc/nginx/sites-available/$domain ]]; then
|
||||
if [[ -f /etc/nginx/sites-available/$domain ]]; then
|
||||
echo "${red}[ERROR] Can not create site${blu} $domain ${red}because already exists!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
@ -739,7 +739,7 @@ redirection_manager() {
|
|||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -a /etc/nginx/apps.d/$domain-nginx.conf ]]; then
|
||||
if [[ -f /etc/nginx/apps.d/$domain-nginx.conf ]]; then
|
||||
sudo sed -i "/^# RedirectFrom: $(echo $from | sed "s#/#\\\/#g")/,/^# RedirectEnd/{/.*/d}" /etc/nginx/apps.d/$domain-nginx.conf
|
||||
if [[ ! -s /etc/nginx/apps.d/$domain-nginx.conf ]]; then
|
||||
sudo rm /etc/nginx/apps.d/$domain-nginx.conf
|
||||
|
@ -770,7 +770,7 @@ redirection_manager() {
|
|||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -a /etc/nginx/apps.d/$domain-nginx.conf ]]; then
|
||||
if [[ ! -f /etc/nginx/apps.d/$domain-nginx.conf ]]; then
|
||||
sudo touch /etc/nginx/apps.d/$domain-nginx.conf
|
||||
sudo chmod 644 /etc/nginx/apps.d/$domain-nginx.conf
|
||||
sudo chown -R root:root /etc/nginx/apps.d/$domain-nginx.conf
|
||||
|
@ -812,4 +812,481 @@ location $sign$from {
|
|||
|
||||
fi
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
delete_all_sites() {
|
||||
echo "${red}"
|
||||
echo "All your sites files will be removed."
|
||||
echo "This action will only delete Databases attached to a WordPress site, any other Database will not be deleted."
|
||||
|
||||
if ! [[ $delete_all =~ ^(force|keep-db)$ ]]; then
|
||||
echo "${blu}"
|
||||
echo "Are you sure [y/N]? ${end}"
|
||||
while read -r -n 1 -s answer; do
|
||||
answer=${answer:-n}
|
||||
echo ""
|
||||
[[ $answer = [YyNn] ]] && break
|
||||
done
|
||||
|
||||
if [[ $answer == [Nn] ]]; then
|
||||
echo "${red}Action aborted!${end}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# List all remaining sites (parked and proxy)
|
||||
for site in "/etc/nginx/sites-available"/*
|
||||
do
|
||||
[[ $delete_all == "keep-db" ]] && delete="keep-db" || delete="force"
|
||||
domain=$(echo $site | cut -f 5 -d "/")
|
||||
[[ $domain != "default" && $domain != $(conf_read tools-port) ]] && deletesite
|
||||
done
|
||||
|
||||
# Delete all files - double check!
|
||||
# -rf is necessary to not generate an error when is empty.
|
||||
sudo rm -rf /etc/nginx/sites-available/!(default|$(conf_read tools-port))
|
||||
sudo rm -rf /etc/nginx/sites-enabled/!(default|$(conf_read tools-port))
|
||||
sudo rm -rf /var/www/!(html|$(conf_read tools-port))
|
||||
echo ""
|
||||
echo "${gre}All sites and data has been deleted successfully!${end}"
|
||||
}
|
||||
|
||||
|
||||
wp_subfolder() {
|
||||
sudo sed -i "/# WebinolyCustom$/a \ include apps.d/$domain$subname-php.conf;" /etc/nginx/sites-available/$domain
|
||||
|
||||
sudo cp /etc/nginx/common/php.conf /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo cp /etc/nginx/common/wpfc.conf /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
sudo cp /etc/nginx/common/wpcommon.conf /etc/nginx/apps.d/$domain$subname-wpcommon.conf
|
||||
sudo cp /etc/nginx/common/wpcommon-noauth.conf /etc/nginx/apps.d/$domain$subname-wpcommon-noauth.conf
|
||||
sudo cp /etc/nginx/common/locations.conf /etc/nginx/apps.d/$domain$subname-locations.conf
|
||||
sudo cp /etc/nginx/common/yoast-sitemap.conf /etc/nginx/apps.d/$domain$subname-yoast-sitemap.conf
|
||||
|
||||
sudo sed -i "/^location \/ {/,/^}$/{/.*/d}" /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo sed -i "/^location \/ {/,/^}$/{/.*/d}" /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
sudo sed -i '/DO NOT MODIFY,/r /opt/webinoly/templates/template-site-wpsubfolder' /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo cat /opt/webinoly/templates/template-site-wpsubfolder >> /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
sudo sed -i "s#subfolder#$subfolder#g" /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo sed -i "s#subfolder#$subfolder#g" /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
sudo sed -i "s/domain/$domain/g" /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo sed -i "s/domain/$domain/g" /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
sudo sed -i "s/subname/$subname/g" /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo sed -i "s/subname/$subname/g" /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
sudo sed -i "s#/index.php#$subfolder/index.php#g" /etc/nginx/apps.d/$domain$subname-yoast-sitemap.conf
|
||||
|
||||
sed -ri "s/^location(.*)\/([a-z].*)$/location\1subfolder\/\2/" /etc/nginx/apps.d/$domain$subname-locations.conf
|
||||
sed -ri "s/location(.*) \/(.*) \{$/location\1 subfolder\/\2 \{/" /etc/nginx/apps.d/$domain$subname-wpcommon.conf
|
||||
sed -ri "s/location(.*) \/(.*) \{$/location\1 subfolder\/\2 \{/" /etc/nginx/apps.d/$domain$subname-wpcommon-noauth.conf
|
||||
sudo sed -i "s#subfolder#$subfolder#g" /etc/nginx/apps.d/$domain$subname-locations.conf
|
||||
sudo sed -i "s#subfolder#$subfolder#g" /etc/nginx/apps.d/$domain$subname-wpcommon.conf
|
||||
sudo sed -i "s#subfolder#$subfolder#g" /etc/nginx/apps.d/$domain$subname-wpcommon-noauth.conf
|
||||
|
||||
[[ $(conf_read wp-admin-auth) == "purged" ]] && sudo httpauth $domain -wp-admin=off -subfolder=$subfolder > /dev/null 2>&1
|
||||
[[ $(conf_read yoast-sitemap) != "purged" ]] && sudo site $domain -yoast-sitemap=on -subfolder=$subfolder > /dev/null 2>&1
|
||||
|
||||
# Activate FastCgi cache
|
||||
if [[ $cache == "on" ]]; then
|
||||
sudo sed -i "/$domain$subname-php.conf;/c \ include apps.d/$domain$subname-wpfc.conf;" /etc/nginx/sites-available/$domain
|
||||
wp_cache_plugins
|
||||
fi
|
||||
|
||||
sudo chown -R www-data:www-data /var/www
|
||||
[[ $(conf_read login-www-data) == "true" ]] && sudo chown root:root /var/www
|
||||
echo "${gre}WordPress has been successfully installed in${blu} $domain$subfolder ${gre}subfolder!${end}"
|
||||
}
|
||||
|
||||
|
||||
wp_multisite_convertion() {
|
||||
[[ -z $subfolder ]] && wpcon="/var/www/$domain/wp-config.php" || wpcon="/var/www/$domain/htdocs$subfolder/wp-config.php"
|
||||
sudo sed -i "/stop editing/i \define('WP_ALLOW_MULTISITE', true);" $wpcon
|
||||
|
||||
echo "${blu}"
|
||||
echo "In your WordPress dashboard, go to ${end}“Tools -> Network Setup”${blu},"
|
||||
echo "select the type of WP Multisite installation you want (Subdomain or Subdirectory)"
|
||||
echo "and then press the ${end}“Install”${blu} button at the bottom."
|
||||
echo ""
|
||||
echo "After that, you don't need to add any code lines."
|
||||
echo "We will do it for you!"
|
||||
echo ""
|
||||
echo "${gre}Waiting... we will automatically finish the multisite configuration after you do the install in the WP dashboard!${blu}"
|
||||
echo "Write ${end}'quit'${blu} and press ${end}<Enter>${blu} to exit and abort this operation."
|
||||
echo "${end}"
|
||||
|
||||
while [[ -z $passed || $passed == "false" ]]; do
|
||||
if read -t0; then
|
||||
read pas
|
||||
[[ $pas == "quit" ]] && break
|
||||
fi
|
||||
sleep 2
|
||||
passed=$(is_wp_multisite $domain)
|
||||
done
|
||||
|
||||
if [[ $passed == "false" && $pas == "quit" ]]; then
|
||||
sudo sed -i "/WP_ALLOW_MULTISITE/d" $wpcon
|
||||
echo "${red}[ERROR] Action aborted!${end}"
|
||||
exit 1
|
||||
elif [[ $passed =~ ^(subdomain|subdirectory)$ ]]; then
|
||||
# Multisite wp-config
|
||||
sudo sed -i "/stop editing/i \define('MULTISITE', true);" $wpcon
|
||||
sudo sed -i "/stop editing/i \define('DOMAIN_CURRENT_SITE', '$domain');" $wpcon
|
||||
sudo sed -i "/stop editing/i \define('PATH_CURRENT_SITE', '$subfolder/');" $wpcon
|
||||
sudo sed -i "/stop editing/i \define('SITE_ID_CURRENT_SITE', 1);" $wpcon
|
||||
sudo sed -i "/stop editing/i \define('BLOG_ID_CURRENT_SITE', 1);" $wpcon
|
||||
|
||||
[[ $pas == "quit" ]] && echo "${red}Can not cancel because the installation was already done!${end}"
|
||||
|
||||
if [[ $passed == "subdomain" ]]; then
|
||||
sudo sed -i "/stop editing/i \define('SUBDOMAIN_INSTALL', true);" $wpcon
|
||||
sudo sed -i "/server_name /c \ server_name $domain *.$domain;" /etc/nginx/sites-available/$domain
|
||||
echo "${gre}Subdomain Multisite configuration has been successfully completed!${end}"
|
||||
elif [[ $passed == "subdirectory" ]]; then
|
||||
sudo sed -i "/stop editing/i \define('SUBDOMAIN_INSTALL', false);" $wpcon
|
||||
|
||||
if [[ -z $subfolder ]]; then
|
||||
sudo sed -i '/locations.conf/i \ include common/wpsubdir.conf;' /etc/nginx/sites-available/$domain
|
||||
else
|
||||
sudo cp /etc/nginx/common/wpsubdir.conf /etc/nginx/apps.d/$domain$subname-wpsubdir.conf
|
||||
sudo sed -i "/DO NOT MODIFY/a \include apps.d\/$domain$subname-wpsubdir.conf;" /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo sed -i "/DO NOT MODIFY/a \include apps.d\/$domain$subname-wpsubdir.conf;" /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
sed -i "s#\^(#\^$subfolder\(#" /etc/nginx/apps.d/$domain$subname-wpsubdir.conf
|
||||
sed -i "s#\$2#$subfolder\$2#" /etc/nginx/apps.d/$domain$subname-wpsubdir.conf
|
||||
fi
|
||||
|
||||
echo "${gre}Subdirectory Multisite configuration has been successfully completed!${end}"
|
||||
fi
|
||||
else
|
||||
sudo sed -i "/WP_ALLOW_MULTISITE/d" $wpcon
|
||||
echo "${red}[ERROR] Multisite installation incomplete or not detected!${end}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
parked_domain() {
|
||||
[[ $parked != true ]] && mapto=$parked || mapto="NeverMatchAtFirstDotCom"
|
||||
|
||||
while [[ ! -f /etc/nginx/sites-available/$mapto ]]
|
||||
do
|
||||
echo "${blu}"
|
||||
read -p "Main site domain: " mapto
|
||||
mapto=${mapto:-NeverMatchAtFirstDotCom}
|
||||
echo "${end}"
|
||||
[[ ! -f /etc/nginx/sites-available/$mapto ]] && echo "${red}Main site domain not found! ${end}"
|
||||
done
|
||||
|
||||
# Nginx conf file for the new parked domain
|
||||
sername=$(grep -w "server_name .*;" /etc/nginx/sites-available/$domain)
|
||||
sudo truncate -s 0 /etc/nginx/sites-available/$domain
|
||||
sudo cat /etc/nginx/sites-available/$mapto > /etc/nginx/sites-available/$domain
|
||||
|
||||
# Prevent if SSL is enabled in main site and ssl data is copied to parked site causing an error.
|
||||
sudo site $domain -ssl=off -revoke=off > /dev/null 2>&1
|
||||
|
||||
sudo sed -i "/server_name/c \ $sername" /etc/nginx/sites-available/$domain
|
||||
sudo sed -i "s/$mapto/$domain/g" /etc/nginx/sites-available/$domain
|
||||
sudo sed -i "/root/c \ root /var/www/$mapto/htdocs;" /etc/nginx/sites-available/$domain
|
||||
cusconl=$( grep -F "include /var/www/$domain/" /etc/nginx/sites-available/$domain | sed "s/$domain/$mapto/" )
|
||||
sed -i "/include \/var\/www\/$domain/c \ ${cusconl}" /etc/nginx/sites-available/$domain
|
||||
|
||||
echo "${gre}"
|
||||
echo "Parked domain was successfully configured! "
|
||||
echo "${end}"
|
||||
}
|
||||
|
||||
|
||||
reverse_proxy() {
|
||||
if [[ $proxy != true ]]; then
|
||||
firstchar=$(echo "${proxy}" | cut -c-1)
|
||||
lastchar=$(echo "${proxy}" | rev | cut -c-1)
|
||||
proxydata=${proxy:1:-1}
|
||||
|
||||
rpport=$(echo "${proxydata}" | rev | cut -d':' -f 1 -s | rev)
|
||||
if [[ $rpport =~ ^[0-9]+$ && $rpport -ge 0 && $rpport -le 65535 ]]; then
|
||||
rphost=$(echo "${proxydata}" | rev | cut -d':' -f 2- -s | rev)
|
||||
elif [[ $rpport =~ ^[0-9]+$ ]]; then
|
||||
echo "${red}[ERROR] Please, enter a valid port number!${end}"
|
||||
exit 1
|
||||
else
|
||||
rphost=$proxydata
|
||||
rpport=""
|
||||
fi
|
||||
|
||||
|
||||
if ! [[ -n $proxydata && $firstchar == "[" && $lastchar == "]" && -n $rphost ]]; then
|
||||
echo "${red}[ERROR] Please, enter a valid host and port!${end}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Support for custom nginx rules.
|
||||
sudo mkdir -p /var/www/.proxy
|
||||
|
||||
createsite
|
||||
sudo sed -i '/include /d' /etc/nginx/sites-available/$domain
|
||||
sudo sed -i '/root /d' /etc/nginx/sites-available/$domain
|
||||
sudo sed -i '/index /d' /etc/nginx/sites-available/$domain
|
||||
sudo sed -i '/error_log /r /opt/webinoly/templates/template-site-proxy' /etc/nginx/sites-available/$domain
|
||||
sudo sed -i "s/domain.com/$domain/g" /etc/nginx/sites-available/$domain
|
||||
|
||||
echo "${gre}"
|
||||
if [[ $(echo "${rphost}" | cut -d':' -f 1 -s ) =~ ^(http|https)$ ]]; then
|
||||
sudo sed -i "/proxy_set_header Host/d" /etc/nginx/sites-available/$domain
|
||||
sudo sed -i "/proxy_set_header X-/d" /etc/nginx/sites-available/$domain
|
||||
sudo sed -i "/proxy_redirect ws:/d" /etc/nginx/sites-available/$domain
|
||||
sudo sed -i '/proxy_read_timeout/a \ proxy_intercept_errors on;' /etc/nginx/sites-available/$domain
|
||||
sudo sed -i '/proxy_read_timeout/a \ proxy_ignore_headers Set-Cookie;' /etc/nginx/sites-available/$domain
|
||||
|
||||
sudo sed -i "s#http://localhost#$rphost#g" /etc/nginx/sites-available/$domain
|
||||
echo " Custom URL host: ${blu}$rphost${gre}"
|
||||
proxyurl="true"
|
||||
elif [[ -z $rphost ]]; then
|
||||
echo " Default host: ${blu}localhost${gre}"
|
||||
else
|
||||
sudo sed -i "s#localhost#$rphost#g" /etc/nginx/sites-available/$domain
|
||||
echo " Custom host: ${blu}$rphost${gre}"
|
||||
fi
|
||||
|
||||
if [[ -n $rpport ]]; then
|
||||
sudo sed -i "s/8080/$rpport/g" /etc/nginx/sites-available/$domain
|
||||
echo " Custom port: ${blu}$rpport${gre}"
|
||||
elif [[ -z $rpport && $proxyurl == "true" ]]; then
|
||||
sudo sed -i "s/:8080//g" /etc/nginx/sites-available/$domain
|
||||
else
|
||||
echo " Default port: ${blu}8080${gre}"
|
||||
fi
|
||||
|
||||
# Check host and port
|
||||
[[ -z $rphost ]] && rphost="localhost"
|
||||
[[ -z $rpport ]] && rpport="8080"
|
||||
code=$(wget -t 1 --timeout=5 --server-response --spider ${rphost}:${rpport} 2>&1 | awk '/^ HTTP/{print $2}')
|
||||
code="${code##*$'\n'}"
|
||||
echo "${red}"
|
||||
[[ $code != 200 ]] && echo "[WARNING] Seems like your host/port is not responding!"
|
||||
|
||||
echo "${end}"
|
||||
}
|
||||
|
||||
|
||||
wp_cache() {
|
||||
if [[ $cache == "off" && -f /etc/nginx/sites-available/$domain ]]; then
|
||||
api-events_update si9
|
||||
if [[ -n $subfolder && $(is_wp_cache $domain $subfolder) == "true" ]]; then
|
||||
sudo sed -i "/$domain$subname-wpfc.conf;/c \ include apps.d/$domain$subname-php.conf;" /etc/nginx/sites-available/$domain
|
||||
echo "${gre}FastCGI Cache in${blu} $domain$subfolder ${gre}has been disabled!${end}"
|
||||
elif [[ $(is_wp_cache $domain) == "true" ]]; then
|
||||
sudo sed -i '/wpfc.conf/c \ include common/php.conf;' /etc/nginx/sites-available/$domain
|
||||
echo "${gre}FastCGI Cache in${blu} $domain ${gre}has been disabled!${end}"
|
||||
else
|
||||
if [[ ( -z $subfolder && $(is_wp $domain) == "false" ) || ( -n $subfolder && $(is_wp $domain $subfolder) == "false" ) ]]; then
|
||||
echo "${red}[ERROR] Site${blu} $domain$subfolder ${red}is not a WP site!${end}"
|
||||
exit 1
|
||||
else
|
||||
echo "${gre}FastCGI Cache is already disabled on your site${blu} $domain${end}"
|
||||
fi
|
||||
fi
|
||||
elif [[ $cache == "on" && -f /etc/nginx/sites-available/$domain ]]; then
|
||||
api-events_update si8
|
||||
if [[ ( -z $subfolder && $(is_php $domain) == "true" && $(is_wp $domain) == "true" ) || ( -n $subfolder && $(is_wp $domain $subfolder) == "true" && $(is_wp_cache $domain $subfolder) == "false" ) ]]; then
|
||||
[[ -z $subfolder ]] && sudo sed -i '/php.conf/c \ include common/wpfc.conf;' /etc/nginx/sites-available/$domain
|
||||
[[ -n $subfolder ]] && sudo sed -i "/$domain$subname-php.conf;/c \ include apps.d/$domain$subname-wpfc.conf;" /etc/nginx/sites-available/$domain
|
||||
if [[ $(is_parked $domain) == "false" && ( ! -d /var/www/$domain/htdocs$subfolder/wp-content/plugins/nginx-helper || ! -d /var/www/$domain/htdocs$subfolder/wp-content/plugins/redis-cache ) ]]; then
|
||||
echo "${gre}"
|
||||
echo "We recommend Nginx Helper Plugin and Redis Object Cache Plugin as an easy way to manage FastCGI and Redis Cache on your WordPress site."
|
||||
echo "${blu}Do you want to install it now [Y/n]? ${end}"
|
||||
while read -r -n 1 -s answer; do
|
||||
answer=${answer:-y}
|
||||
if [[ $answer = [YyNn] ]]; then
|
||||
[[ $answer = [Yy] ]] && wp_cache_plugins
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
echo "${gre}"
|
||||
echo "FastCGI Cache in${blu} $domain$subfolder ${gre}has been successfully enabled! "
|
||||
echo "${end}"
|
||||
else
|
||||
if [[ ( -z $subfolder && $(is_wp $domain) == "false" ) || ( -n $subfolder && $(is_wp $domain $subfolder) == "false" ) ]]; then
|
||||
echo "${red}[ERROR] Site${blu} $domain$subfolder ${red}is not a WP site!${end}"
|
||||
exit 1
|
||||
else
|
||||
echo "${gre}FastCGI Cache is already enabled on your site${blu} $domain$subfolder${end}"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "${red}[ERROR] Invalid value for cache! ${end}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
yoast_sitemap() {
|
||||
if [[ ( -z $subfolder && $(is_wp $domain) == "false" ) || ( -n $subfolder && $(is_wp $domain $subfolder) == "false" ) ]]; then
|
||||
echo "${red}[ERROR] Site${blu} $domain$subfolder ${red}is not a WP site!${end}"
|
||||
exit 1
|
||||
elif [[ -n $subfolder && $(is_wp $domain $subfolder) == "true" ]]; then
|
||||
ystmap=$( grep -F "yoast-sitemap.conf;" /etc/nginx/apps.d/$domain$subname-php.conf )
|
||||
else
|
||||
ystmap=$( grep -F "yoast-sitemap.conf;" /etc/nginx/sites-available/$domain )
|
||||
fi
|
||||
|
||||
if [[ $yoast_sitemap == "on" ]]; then
|
||||
if [[ -z $ystmap ]]; then
|
||||
if [[ -z $subfolder ]]; then
|
||||
sudo sed -i "/# WebinolyCustom$/a \ include common/yoast-sitemap.conf;" /etc/nginx/sites-available/$domain
|
||||
else
|
||||
sudo sed -i "/\/index.php?q/a \ include apps.d\/$domain$subname-yoast-sitemap.conf;" /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo sed -i "/\/index.php?q/a \ include apps.d\/$domain$subname-yoast-sitemap.conf;" /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
fi
|
||||
echo "${gre}Yoast Sitemap Support was successfully enabled!${end}"
|
||||
else
|
||||
echo "${gre}Yoast Sitemap Support is already enabled!${end}"
|
||||
fi
|
||||
elif [[ $yoast_sitemap == "off" ]]; then
|
||||
if [[ -n $ystmap ]]; then
|
||||
if [[ -z $subfolder ]]; then
|
||||
sudo sed -i "/yoast-sitemap.conf;/d" /etc/nginx/sites-available/$domain
|
||||
else
|
||||
sudo sed -i "/yoast-sitemap.conf;/d" /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo sed -i "/yoast-sitemap.conf;/d" /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
fi
|
||||
echo "${gre}Yoast Sitemap Support was successfully disabled!${end}"
|
||||
else
|
||||
echo "${gre}Yoast Sitemap Support is already disabled!${end}"
|
||||
fi
|
||||
else
|
||||
echo "${red}[ERROR] Please, enter a valid option to enable/disable Yoast Sitemap Support!${end}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
clone_wp_site() {
|
||||
if [[ -n $subfolder ]]; then
|
||||
wpcon="/var/www/$domain/htdocs$subfolder/wp-config.php"
|
||||
arg=" -subfolder=$subfolder"
|
||||
|
||||
sudo cp /etc/nginx/apps.d/$clone_from$subname-php.conf /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo cp /etc/nginx/apps.d/$clone_from$subname-wpfc.conf /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
sudo cp /etc/nginx/apps.d/$clone_from$subname-wpcommon.conf /etc/nginx/apps.d/$domain$subname-wpcommon.conf
|
||||
sudo cp /etc/nginx/apps.d/$clone_from$subname-wpcommon-noauth.conf /etc/nginx/apps.d/$domain$subname-wpcommon-noauth.conf
|
||||
sudo cp /etc/nginx/apps.d/$clone_from$subname-locations.conf /etc/nginx/apps.d/$domain$subname-locations.conf
|
||||
sudo cp /etc/nginx/apps.d/$clone_from$subname-yoast-sitemap.conf /etc/nginx/apps.d/$domain$subname-yoast-sitemap.conf
|
||||
|
||||
sudo sed -i "s/$clone_from/$domain/g" /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo sed -i "s/$clone_from/$domain/g" /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
|
||||
dest=$( echo $subfolder | rev | cut -f 2- -d "/" -s | rev )
|
||||
sudo mkdir -p /var/www/$domain/htdocs$dest
|
||||
sudo cp -r /var/www/$clone_from/htdocs$subfolder /var/www/$domain/htdocs$dest
|
||||
else
|
||||
arg=""
|
||||
wpcon="/var/www/$domain/wp-config.php"
|
||||
sudo cp -r /var/www/$clone_from /var/www/$domain
|
||||
fi
|
||||
|
||||
if [[ -f /etc/nginx/sites-available/$domain ]]; then
|
||||
sudo sed -i "/# WebinolyCustom$/a \ include apps.d/$domain$subname-php.conf;" /etc/nginx/sites-available/$domain
|
||||
else
|
||||
sudo cp /etc/nginx/sites-available/$clone_from /etc/nginx/sites-available/$domain
|
||||
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
|
||||
fi
|
||||
|
||||
[[ $(is_ssl $clone_from) == "true" ]] && site $domain -ssl=off -revoke=off > /dev/null 2>&1
|
||||
dom=$(echo $domain$subfolder | sed "s/[^0-9A-Za-z]/_/g")
|
||||
AUTOGENPASS_WPDB=`pwgen -s -1 16`
|
||||
wp_dbdata $clone_from
|
||||
|
||||
if [[ $wp_dbhost == "localhost" ]]; then
|
||||
ROOT_PASS=$( echo $(conf_read mysql-root) | openssl enc -d -a -salt )
|
||||
site -mysql=[localhost,$dom,$dom,$AUTOGENPASS_WPDB] > /dev/null 2>&1
|
||||
mysqldump -u root -p$ROOT_PASS $wp_dbname | mysql -u root -p$ROOT_PASS $dom
|
||||
# Starting with MySQL 8 you no longer can (implicitly) create a user using the GRANT command.
|
||||
sudo mysql --connect-timeout=10 --user=root -p$ROOT_PASS <<_EOF_
|
||||
USE $dom;
|
||||
UPDATE ${wp_dbpref}options SET option_value='http://${domain}${subfolder}' WHERE option_name='home';
|
||||
UPDATE ${wp_dbpref}options SET option_value='http://${domain}${subfolder}' WHERE option_name='siteurl';
|
||||
FLUSH PRIVILEGES;
|
||||
_EOF_
|
||||
else
|
||||
echo "${red}[ERROR] Database host is not localhost!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sudo sed -i "/DB_NAME/c \define('DB_NAME', '$dom');" $wpcon
|
||||
sudo sed -i "/DB_USER/c \define('DB_USER', '$dom');" $wpcon
|
||||
sudo sed -i "/DB_PASSWORD/c \define('DB_PASSWORD', '$AUTOGENPASS_WPDB');" $wpcon
|
||||
|
||||
if [[ $replace_content != "off" ]]; then
|
||||
sudo site $domain -replace-content=[http://$clone_from,http://$domain]$arg > /dev/null 2>&1
|
||||
sudo site $domain -replace-content=[https://$clone_from,http://$domain]$arg > /dev/null 2>&1
|
||||
sudo site $domain -replace-content=[$clone_from,$domain]$arg > /dev/null 2>&1
|
||||
fi
|
||||
echo "${gre}Site ${blu}'$domain$subfolder'${gre} is now a successful clone of ${blu}'$clone_from$subfolder'${end}"
|
||||
}
|
||||
|
||||
|
||||
wp_replace_content() {
|
||||
if [[ $replace_content == true ]]; then
|
||||
echo ""
|
||||
read -p "${blu}Search: ${end}" search
|
||||
read -p "${blu}Replace with: ${end}" replace
|
||||
echo ""
|
||||
elif [[ $(echo "${replace_content}" | cut -c-1) == "[" && $(echo "${replace_content}" | rev | cut -c-1) == "]" ]]; then
|
||||
userdata=${replace_content:1:-1}
|
||||
search=$(echo "${userdata}" | cut -d',' -f 1 -s)
|
||||
replace=$(echo "${userdata}" | cut -d',' -f 2 -s)
|
||||
fi
|
||||
|
||||
if [[ -z $search || -z $replace ]]; then
|
||||
echo "${red}[ERROR] Please, enter a valid value for search and replace!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
wp_dbdata $domain
|
||||
query="USE $wp_dbname; UPDATE ${wp_dbpref}posts SET post_content = REPLACE (post_content,'$search','$replace'); FLUSH PRIVILEGES;"
|
||||
|
||||
if [[ $wp_dbhost == "localhost" ]]; then
|
||||
ROOT_PASS=$( echo $(conf_read mysql-root) | openssl enc -d -a -salt )
|
||||
sudo mysql --connect-timeout=10 --user=root -p$ROOT_PASS -e "$query"
|
||||
elif [[ -n $wp_dbhost ]]; then
|
||||
sudo mysql --connect-timeout=10 -h "$wp_dburl" -P "$wp_dbport" -u"$wp_uroot" -p"$wp_proot" -e "$query"
|
||||
else
|
||||
echo "${red}[ERROR] Invalid WP database host!${end}"
|
||||
exit 1
|
||||
fi
|
||||
echo "${gre}Content successfully replaced in your WP site!${end}"
|
||||
}
|
||||
|
||||
|
||||
list_sites() {
|
||||
echo ""
|
||||
for site in "/etc/nginx/sites-available"/*
|
||||
do
|
||||
domi=$(echo $site | cut -f 5 -d "/")
|
||||
if [[ $domi != "default" && $domi != $(conf_read tools-port) ]]; then
|
||||
[[ -f /var/www/$domi ]] && sign="${gre} +" || sign="${blu} *${gre}"
|
||||
[[ ! -L /etc/nginx/sites-enabled/$domi ]] && sign="${red} -"
|
||||
outlist="$sign $domi ${end}"
|
||||
|
||||
if [[ $list == "raw" || $raw =~ ^(all|parked|disabled|main|true)$ ]]; then
|
||||
outlist="$domi"
|
||||
[[ $raw == "parked" && -f /var/www/$domi ]] && outlist=""
|
||||
[[ $raw == "disabled" && -L /etc/nginx/sites-enabled/$domi ]] && outlist=""
|
||||
[[ $raw == "main" && ( ! -L /etc/nginx/sites-enabled/$domi || ! -f /var/www/$domi ) ]] && outlist=""
|
||||
elif [[ -n $raw ]]; then
|
||||
echo "${red}[ERROR] Please, enter a valid value for RAW!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n $outlist ]]; then
|
||||
echo "$outlist"
|
||||
nonemptylist=true
|
||||
fi
|
||||
fi
|
||||
done
|
||||
[[ -z $nonemptylist && -z $raw && $list != "raw" ]] && echo "${blu}[Empty] No sites were found!${end}"
|
||||
echo ""
|
||||
}
|
||||
|
||||
|
|
679
lib/webin
679
lib/webin
|
@ -11,156 +11,156 @@ webinoly_verify() {
|
|||
echo "${red}"
|
||||
|
||||
# Webinoly
|
||||
if [[ ! -a /opt/webinoly/lib/general ]]; then
|
||||
if [[ ! -f /opt/webinoly/lib/general ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/lib/general not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/lib/install ]]; then
|
||||
if [[ ! -f /opt/webinoly/lib/install ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/lib/install not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/lib/sites ]]; then
|
||||
if [[ ! -f /opt/webinoly/lib/sites ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/lib/install not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/lib/site-ssl ]]; then
|
||||
if [[ ! -f /opt/webinoly/lib/site-ssl ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/lib/install not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/lib/webin ]]; then
|
||||
if [[ ! -f /opt/webinoly/lib/webin ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/lib/install not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/lib/update ]]; then
|
||||
if [[ ! -f /opt/webinoly/lib/update ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/lib/install not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/lib/public_suffix_list.dat ]]; then
|
||||
if [[ ! -f /opt/webinoly/lib/public_suffix_list.dat ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/lib/install not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/lib/timezone.dat ]]; then
|
||||
if [[ ! -f /opt/webinoly/lib/timezone.dat ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/lib/install not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/lib/api-events_sample ]]; then
|
||||
if [[ ! -f /opt/webinoly/lib/api-events_sample ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/lib/install not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/templates/template-site-php ]]; then
|
||||
if [[ ! -f /opt/webinoly/templates/template-site-php ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/templates/template-site-php not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/templates/template-site-proxy ]]; then
|
||||
if [[ ! -f /opt/webinoly/templates/template-site-proxy ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/templates/template-site-php not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/templates/template-site-ssl ]]; then
|
||||
if [[ ! -f /opt/webinoly/templates/template-site-ssl ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/templates/template-site-php not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/templates/template-site-sslredirect ]]; then
|
||||
if [[ ! -f /opt/webinoly/templates/template-site-sslredirect ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/templates/template-site-php not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/templates/template-site-wwwredirect ]]; then
|
||||
if [[ ! -f /opt/webinoly/templates/template-site-wwwredirect ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/templates/template-site-php not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/templates/nginx/nginx.conf ]]; then
|
||||
if [[ ! -f /opt/webinoly/templates/nginx/nginx.conf ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/templates/nginx/nginx.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/templates/nginx/22222 ]]; then
|
||||
if [[ ! -f /opt/webinoly/templates/nginx/22222 ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/templates/nginx/22222 not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/templates/nginx/conf.d/fastcgi.conf ]]; then
|
||||
if [[ ! -f /opt/webinoly/templates/nginx/conf.d/fastcgi.conf ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/templates/nginx/conf.d/fastcgi.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/templates/nginx/conf.d/upstream.conf ]]; then
|
||||
if [[ ! -f /opt/webinoly/templates/nginx/conf.d/upstream.conf ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/templates/nginx/conf.d/upstream.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/templates/nginx/common/acl.conf ]]; then
|
||||
if [[ ! -f /opt/webinoly/templates/nginx/common/acl.conf ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/templates/nginx/common/acl.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/templates/nginx/common/locations.conf ]]; then
|
||||
if [[ ! -f /opt/webinoly/templates/nginx/common/locations.conf ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/templates/nginx/common/locations.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/templates/nginx/common/php.conf ]]; then
|
||||
if [[ ! -f /opt/webinoly/templates/nginx/common/php.conf ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/templates/nginx/common/php.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/templates/nginx/common/wpcommon.conf ]]; then
|
||||
if [[ ! -f /opt/webinoly/templates/nginx/common/wpcommon.conf ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/templates/nginx/common/wpcommon.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/templates/nginx/common/wpfc.conf ]]; then
|
||||
if [[ ! -f /opt/webinoly/templates/nginx/common/wpfc.conf ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/templates/nginx/common/wpfc.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/templates/nginx/common/wpsubdir.conf ]]; then
|
||||
if [[ ! -f /opt/webinoly/templates/nginx/common/wpsubdir.conf ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/templates/nginx/common/wpsubdir.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/templates/nginx/common/headers-html.conf ]]; then
|
||||
if [[ ! -f /opt/webinoly/templates/nginx/common/headers-html.conf ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/templates/nginx/common/headers-html.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/templates/nginx/common/headers-http.conf ]]; then
|
||||
if [[ ! -f /opt/webinoly/templates/nginx/common/headers-http.conf ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/templates/nginx/common/headers-http.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/templates/nginx/common/headers-https.conf ]]; then
|
||||
if [[ ! -f /opt/webinoly/templates/nginx/common/headers-https.conf ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/templates/nginx/common/headers-https.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/webinoly.conf ]]; then
|
||||
if [[ ! -f /opt/webinoly/webinoly.conf ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/webinoly.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /usr/bin/webinoly ]]; then
|
||||
if [[ ! -f /usr/bin/webinoly ]]; then
|
||||
echo "[ERROR] File: /usr/bin/webinoly not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /usr/bin/site ]]; then
|
||||
if [[ ! -f /usr/bin/site ]]; then
|
||||
echo "[ERROR] File: /usr/bin/site not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /usr/bin/httpauth ]]; then
|
||||
if [[ ! -f /usr/bin/httpauth ]]; then
|
||||
echo "[ERROR] File: /usr/bin/httpauth not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /usr/bin/log ]]; then
|
||||
if [[ ! -f /usr/bin/log ]]; then
|
||||
echo "[ERROR] File: /usr/bin/log not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /usr/bin/stack ]]; then
|
||||
if [[ ! -f /usr/bin/stack ]]; then
|
||||
echo "[ERROR] File: /usr/bin/stack not found!"
|
||||
error="1"
|
||||
fi
|
||||
|
||||
# NGINX
|
||||
if [[ $(conf_read nginx) == "true" ]]; then
|
||||
if [[ ! -a /etc/nginx/nginx.conf ]]; then
|
||||
if [[ ! -f /etc/nginx/nginx.conf ]]; then
|
||||
echo "[ERROR] File: /etc/nginx/nginx.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /etc/nginx/fastcgi.conf ]]; then
|
||||
if [[ ! -f /etc/nginx/fastcgi.conf ]]; then
|
||||
echo "[ERROR] File: /etc/nginx/fastcgi.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
fi
|
||||
if [[ $(conf_read nginx) != "true" ]]; then
|
||||
if [[ -a /etc/nginx/nginx.conf ]]; then
|
||||
if [[ -f /etc/nginx/nginx.conf ]]; then
|
||||
echo "[WARNING] Seems like NGINX is installed but Webinoly can not detect it!"
|
||||
warning="1"
|
||||
fi
|
||||
if [[ -a /etc/nginx/fastcgi.conf ]]; then
|
||||
if [[ -f /etc/nginx/fastcgi.conf ]]; then
|
||||
echo "[WARNING] Seems like NGINX is installed but Webinoly can not detect it!"
|
||||
warning="1"
|
||||
fi
|
||||
|
@ -168,55 +168,55 @@ webinoly_verify() {
|
|||
|
||||
# NGINX Optim
|
||||
if [[ $(conf_read nginx-optim) == "true" ]]; then
|
||||
if [[ ! -a /etc/nginx/fastcgi_params ]]; then
|
||||
if [[ ! -f /etc/nginx/fastcgi_params ]]; then
|
||||
echo "[ERROR] File: /etc/nginx/fastcgi_params not found!"
|
||||
error="1"
|
||||
fi
|
||||
if ! [[ -a /etc/nginx/.htpasswd && $(conf_read php) == "true" || ( -n $(conf_read tools-site) && -a /etc/nginx/apps.d/.htpasswd-$(conf_read tools-site) && $(conf_read php) == "true" ) ]]; then
|
||||
if ! [[ -f /etc/nginx/.htpasswd && $(conf_read php) == "true" || ( -n $(conf_read tools-site) && -f /etc/nginx/apps.d/.htpasswd-$(conf_read tools-site) && $(conf_read php) == "true" ) ]]; then
|
||||
echo "[INFO] HTTP Authentication Credentials not found!"
|
||||
info="1"
|
||||
fi
|
||||
if [[ ! -a /etc/nginx/conf.d/fastcgi.conf ]]; then
|
||||
if [[ ! -f /etc/nginx/conf.d/fastcgi.conf ]]; then
|
||||
echo "[ERROR] File: /etc/nginx/conf.d/fastcgi.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /etc/nginx/conf.d/upstream.conf ]]; then
|
||||
if [[ ! -f /etc/nginx/conf.d/upstream.conf ]]; then
|
||||
echo "[ERROR] File: /etc/nginx/conf.d/upstream.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /etc/nginx/common/acl.conf ]]; then
|
||||
if [[ ! -f /etc/nginx/common/acl.conf ]]; then
|
||||
echo "[ERROR] File: /etc/nginx/common/acl.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /etc/nginx/common/locations.conf ]]; then
|
||||
if [[ ! -f /etc/nginx/common/locations.conf ]]; then
|
||||
echo "[ERROR] File: /etc/nginx/common/locations.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /etc/nginx/common/php.conf ]]; then
|
||||
if [[ ! -f /etc/nginx/common/php.conf ]]; then
|
||||
echo "[ERROR] File: /etc/nginx/common/php.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /etc/nginx/common/wpcommon.conf ]]; then
|
||||
if [[ ! -f /etc/nginx/common/wpcommon.conf ]]; then
|
||||
echo "[ERROR] File: /etc/nginx/common/wpcommon.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /etc/nginx/common/wpfc.conf ]]; then
|
||||
if [[ ! -f /etc/nginx/common/wpfc.conf ]]; then
|
||||
echo "[ERROR] File: /etc/nginx/common/wpfc.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /etc/nginx/common/wpsubdir.conf ]]; then
|
||||
if [[ ! -f /etc/nginx/common/wpsubdir.conf ]]; then
|
||||
echo "[ERROR] File: /etc/nginx/common/wpsubdir.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /etc/nginx/common/headers-html.conf ]]; then
|
||||
if [[ ! -f /etc/nginx/common/headers-html.conf ]]; then
|
||||
echo "[ERROR] File: /etc/nginx/common/headers-html.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /etc/nginx/common/headers-http.conf ]]; then
|
||||
if [[ ! -f /etc/nginx/common/headers-http.conf ]]; then
|
||||
echo "[ERROR] File: /etc/nginx/common/headers-http.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /etc/nginx/common/headers-https.conf ]]; then
|
||||
if [[ ! -f /etc/nginx/common/headers-https.conf ]]; then
|
||||
echo "[ERROR] File: /etc/nginx/common/headers-https.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
|
@ -224,7 +224,7 @@ webinoly_verify() {
|
|||
|
||||
# NGINX Tools
|
||||
if [[ $(conf_read nginx-tool) == "true" ]]; then
|
||||
if [[ ! -a /etc/nginx/sites-available/$(conf_read tools-port) && $(conf_read php) == "true" ]]; then
|
||||
if [[ ! -f /etc/nginx/sites-available/$(conf_read tools-port) && $(conf_read php) == "true" ]]; then
|
||||
echo "[ERROR] File: /etc/nginx/sites-available/$(conf_read tools-port) not found!"
|
||||
error="1"
|
||||
fi
|
||||
|
@ -238,7 +238,7 @@ webinoly_verify() {
|
|||
fi
|
||||
fi
|
||||
if [[ $(conf_read nginx-tool) != "true" && -n $(conf_read tools-port) ]]; then
|
||||
if [[ -a /etc/nginx/sites-available/$(conf_read tools-port) || -d /var/www/$(conf_read tools-port) ]]; then
|
||||
if [[ -f /etc/nginx/sites-available/$(conf_read tools-port) || -d /var/www/$(conf_read tools-port) ]]; then
|
||||
echo "[WARNING] Seems like Nginx Tools are enabled but Webinoly can not detect it!"
|
||||
warning="1"
|
||||
fi
|
||||
|
@ -251,33 +251,33 @@ webinoly_verify() {
|
|||
fi
|
||||
|
||||
# PHP
|
||||
if [[ ! -a /etc/php/$(conf_read php-ver)/fpm/php.ini && $(conf_read php) == "true" ]]; then
|
||||
if [[ ! -f /etc/php/$(conf_read php-ver)/fpm/php.ini && $(conf_read php) == "true" ]]; then
|
||||
echo "[ERROR] File: /etc/php/$(conf_read php-ver)/fpm/php.ini not found!"
|
||||
error="1"
|
||||
elif [[ -a /etc/php/$(conf_read php-ver)/fpm/php.ini && $(conf_read php) != "true" ]]; then
|
||||
elif [[ -f /etc/php/$(conf_read php-ver)/fpm/php.ini && $(conf_read php) != "true" ]]; then
|
||||
echo "[WARNING] Seems like PHP is installed but Webinoly can not detect it!"
|
||||
warning="1"
|
||||
fi
|
||||
|
||||
# PHP Optim
|
||||
if [[ $(conf_read php-optim) == "true" ]]; then
|
||||
if [[ ! -a /etc/php/$(conf_read php-ver)/fpm/php-fpm.conf ]]; then
|
||||
if [[ ! -f /etc/php/$(conf_read php-ver)/fpm/php-fpm.conf ]]; then
|
||||
echo "[ERROR] File: /etc/php/$(conf_read php-ver)/fpm/php-fpm.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /etc/php/$(conf_read php-ver)/fpm/pool.d/debug.conf ]]; then
|
||||
if [[ ! -f /etc/php/$(conf_read php-ver)/fpm/pool.d/debug.conf ]]; then
|
||||
echo "[ERROR] File: /etc/php/$(conf_read php-ver)/fpm/pool.d/debug.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /etc/php/$(conf_read php-ver)/fpm/pool.d/www.conf ]]; then
|
||||
if [[ ! -f /etc/php/$(conf_read php-ver)/fpm/pool.d/www.conf ]]; then
|
||||
echo "[ERROR] File: /etc/php/$(conf_read php-ver)/fpm/pool.d/www.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/templates/source/www.conf ]]; then
|
||||
if [[ ! -f /opt/webinoly/templates/source/www.conf ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/templates/source/www.conf not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /opt/webinoly/templates/source/php.ini ]]; then
|
||||
if [[ ! -f /opt/webinoly/templates/source/php.ini ]]; then
|
||||
echo "[ERROR] File: /opt/webinoly/templates/source/php.ini not found!"
|
||||
error="1"
|
||||
fi
|
||||
|
@ -285,29 +285,29 @@ webinoly_verify() {
|
|||
|
||||
# PHP Tools
|
||||
if [[ $(conf_read php-tool) == "true" && $(conf_read nginx) == "true" ]]; then
|
||||
if [[ ! -a /var/www/$(conf_read tools-port)/htdocs/fpm/status/php ]]; then
|
||||
if [[ ! -f /var/www/$(conf_read tools-port)/htdocs/fpm/status/php ]]; then
|
||||
echo "[ERROR] File: /var/www/$(conf_read tools-port)/htdocs/fpm/status/php not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /var/www/$(conf_read tools-port)/htdocs/fpm/status/debug ]]; then
|
||||
if [[ ! -f /var/www/$(conf_read tools-port)/htdocs/fpm/status/debug ]]; then
|
||||
echo "[ERROR] File: /var/www/$(conf_read tools-port)/htdocs/fpm/status/debug not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /var/www/$(conf_read tools-port)/htdocs/php/index.php ]]; then
|
||||
if [[ ! -f /var/www/$(conf_read tools-port)/htdocs/php/index.php ]]; then
|
||||
echo "[ERROR] File: /var/www/$(conf_read tools-port)/htdocs/php/index.php not found!"
|
||||
error="1"
|
||||
fi
|
||||
fi
|
||||
if [[ $(conf_read php-tool) != "true" && $(conf_read nginx) == "true" ]]; then
|
||||
if [[ -a /var/www/$(conf_read tools-port)/htdocs/fpm/status/php ]]; then
|
||||
if [[ -f /var/www/$(conf_read tools-port)/htdocs/fpm/status/php ]]; then
|
||||
echo "[WARNING] Seems like PHP Tools are enabled but Webinoly can not detect it!"
|
||||
warning="1"
|
||||
fi
|
||||
if [[ -a /var/www/$(conf_read tools-port)/htdocs/fpm/status/debug ]]; then
|
||||
if [[ -f /var/www/$(conf_read tools-port)/htdocs/fpm/status/debug ]]; then
|
||||
echo "[WARNING] Seems like PHP Tools are enabled but Webinoly can not detect it!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ -a /var/www/$(conf_read tools-port)/htdocs/php/index.php ]]; then
|
||||
if [[ -f /var/www/$(conf_read tools-port)/htdocs/php/index.php ]]; then
|
||||
echo "[WARNING] Seems like PHP Tools are enabled but Webinoly can not detect it!"
|
||||
warning="1"
|
||||
fi
|
||||
|
@ -355,11 +355,11 @@ webinoly_verify() {
|
|||
fi
|
||||
fi
|
||||
if [[ $(conf_read nginx-tool) == "true" ]]; then
|
||||
if [[ ! -a /usr/bin/duplicity ]]; then
|
||||
if [[ ! -f /usr/bin/duplicity ]]; then
|
||||
echo "[ERROR] File: /usr/bin/duplicity not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /usr/bin/duply ]]; then
|
||||
if [[ ! -f /usr/bin/duply ]]; then
|
||||
echo "[ERROR] File: /usr/bin/duply not found!"
|
||||
error="1"
|
||||
fi
|
||||
|
@ -367,7 +367,7 @@ webinoly_verify() {
|
|||
echo "[ERROR] File: /usr/bin/letsencrypt not found!"
|
||||
error="1"
|
||||
fi
|
||||
if [[ ! -a /usr/bin/certbot ]]; then
|
||||
if [[ ! -f /usr/bin/certbot ]]; then
|
||||
echo "[ERROR] File: /usr/bin/certbot not found!"
|
||||
error="1"
|
||||
fi
|
||||
|
@ -429,8 +429,8 @@ webinoly_verify() {
|
|||
fi
|
||||
|
||||
# Check for PHP and MySQL version
|
||||
if [[ $(conf_read php) == "true" && $(php -v | grep -m1 "" | sed 's/PHP \([^\-]*\).*/\1/' | cut -f 1-2 -d'.') != "7.3" ]]; then
|
||||
echo "[INFO] PHP v7.3 is recommended to get an optimal perfomance!"
|
||||
if [[ $(conf_read php) == "true" && $(php -v | grep -m1 "" | sed 's/PHP \([^\-]*\).*/\1/' | cut -f 1-2 -d'.') != "7.4" ]]; then
|
||||
echo "[INFO] PHP v7.4 is recommended to get an optimal perfomance!"
|
||||
fi
|
||||
if [[ $(conf_read mysql) == "true" && $(sudo mysql --version | sed 's/.*Distrib \([^\-]*\).*/\1/' | cut -f 1-2 -d'.') != "10.4" ]]; then
|
||||
echo "[INFO] MariaDB (MySQL) v10.4 is recommended to get an optimal perfomance!"
|
||||
|
@ -456,7 +456,7 @@ webinoly_verify() {
|
|||
for cert in "/etc/letsencrypt/live"/*
|
||||
do
|
||||
domain=$(echo $cert | cut -f 5 -d "/")
|
||||
if [[ -d $cert && ! -a /etc/nginx/sites-available/$domain ]]; then
|
||||
if [[ -d $cert && ! -f /etc/nginx/sites-available/$domain ]]; then
|
||||
echo "[INFO] SSL Orphan-Cert found ($domain)!"
|
||||
info="1"
|
||||
fi
|
||||
|
@ -555,7 +555,7 @@ system_info() {
|
|||
fi
|
||||
|
||||
echo "[Raw Conf]"
|
||||
if [[ -a /opt/webinoly/webinoly.conf ]]; then
|
||||
if [[ -f /opt/webinoly/webinoly.conf ]]; then
|
||||
sudo cat /opt/webinoly/webinoly.conf
|
||||
else
|
||||
echo "${red} [ERROR] Configuration File not found! ${blu}"
|
||||
|
@ -566,7 +566,7 @@ system_info() {
|
|||
}
|
||||
|
||||
|
||||
smtp_setup() {
|
||||
smtp_setup() {
|
||||
if [[ $smtp == true ]]; then
|
||||
echo "${gre}"
|
||||
echo "**********************************"
|
||||
|
@ -591,12 +591,12 @@ smtp_setup() {
|
|||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z $user || -z $pass || -z $host || -z $mainhost || ! -a /etc/nginx/sites-available/$mainhost ]]; then
|
||||
if [[ -z $user || -z $pass || -z $host || -z $mainhost || ! -f /etc/nginx/sites-available/$mainhost ]]; then
|
||||
echo "${red}[ERROR] Invalid SMTP data!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
[[ ! -a /opt/webinoly/templates/source/main.cf ]] && sudo cp -p /etc/postfix/main.cf /opt/webinoly/templates/source/
|
||||
[[ ! -f /opt/webinoly/templates/source/main.cf ]] && sudo cp -p /etc/postfix/main.cf /opt/webinoly/templates/source/
|
||||
|
||||
sudo touch /etc/mailname
|
||||
echo "$mainhost" > /etc/mailname
|
||||
|
@ -672,9 +672,9 @@ mysql_change_password() {
|
|||
remove_domain_default_site() {
|
||||
# In case we have a domain as default before.
|
||||
if ! [[ $(conf_read default-site) =~ ^(default|blackhole)$ || -z $(conf_read default-site) ]]; then
|
||||
[[ ! -L /etc/nginx/sites-enabled/default && -a /etc/nginx/sites-available/default ]] && sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
|
||||
[[ ! -L /etc/nginx/sites-enabled/default && -f /etc/nginx/sites-available/default ]] && sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
|
||||
# Check in case site was deleted!
|
||||
if [[ -a /etc/nginx/sites-available/$(conf_read default-site) ]]; then
|
||||
if [[ -f /etc/nginx/sites-available/$(conf_read default-site) ]]; then
|
||||
sudo sed -i "s/listen 80 default_server;/listen 80;/" /etc/nginx/sites-available/$(conf_read default-site)
|
||||
sudo sed -i "s/listen \[::\]:80 default_server;/listen [::]:80;/" /etc/nginx/sites-available/$(conf_read default-site)
|
||||
sudo sed -i "s/listen 443 ssl http2 default_server;/listen 443 ssl http2;/" /etc/nginx/sites-available/$(conf_read default-site)
|
||||
|
@ -686,7 +686,7 @@ remove_domain_default_site() {
|
|||
|
||||
|
||||
create_blackhole_cert() {
|
||||
if [[ ! -a /etc/ssl/certs/webinoly-blackhole.crt.pem ]]; then
|
||||
if [[ ! -f /etc/ssl/certs/webinoly-blackhole.crt.pem ]]; then
|
||||
# REMOVE: Temporal fix affecting openssl 1.1.1 - https://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg1603717.html
|
||||
sudo touch /root/.rnd
|
||||
|
||||
|
@ -694,3 +694,526 @@ create_blackhole_cert() {
|
|||
fi
|
||||
}
|
||||
|
||||
|
||||
webinoly_update() {
|
||||
checkver=$(wget --timeout=10 -t 1 -qO- https://api.webinoly.com/check?text=true)
|
||||
currentver=$(conf_read app-version)
|
||||
|
||||
if [[ ( -n $checkver && ${checkver//.} -gt ${currentver//.} ) || ( -n $update && $update != true ) ]]; then
|
||||
echo ""
|
||||
[[ -n $update && $update != true ]] && branch="-ver=${update}" || branch=""
|
||||
sudo wget --timeout=15 -t 1 --referer="https://update.webinoly.com/?ver=${app_version}" -qrO weby https://qrok.es/wyupd && sudo bash weby upd $branch
|
||||
[[ $? == 0 ]] && echo "${gre}Webinoly App has been updated successfully!${end}"
|
||||
api-events_update wy1s
|
||||
else
|
||||
echo "${gre}You currently have the latest version!${end}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
server_reset() {
|
||||
# Regenerate NGINX conf files
|
||||
if [[ $(conf_read nginx-optim) == "true" && $server_reset =~ ^(nginx|all)$ ]]; then
|
||||
[[ -f /etc/nginx/conf.d/blockips.conf ]] && sudo cp -p /etc/nginx/conf.d/blockips.conf /tmp/webinoly_blockips_backup
|
||||
sudo rm -rf /etc/nginx/common
|
||||
sudo rm -rf /etc/nginx/conf.d/*
|
||||
linux_purge
|
||||
nginx_optim
|
||||
[[ -f /tmp/webinoly_blockips_backup ]] && sudo mv /tmp/webinoly_blockips_backup /etc/nginx/conf.d/blockips.conf
|
||||
echo "${gre}Nginx settings has been updated successfully!${end}"
|
||||
nginx_not="true" # Nginx-Reload not-needed.
|
||||
elif [[ $(conf_read nginx-optim) != "true" && $server_reset == "nginx" ]]; then
|
||||
echo "${red}[ERROR] Nginx settings couldn't been updated, seems like is not installed in your server!${end}"
|
||||
err_cont=true
|
||||
fi
|
||||
|
||||
# Regenerate PHP conf files
|
||||
if [[ $(conf_read php-optim) == "true" && $server_reset =~ ^(php|all)$ ]]; then
|
||||
if [[ -f /opt/webinoly/templates/source/php.ini && -f /opt/webinoly/templates/source/www.conf ]]; then
|
||||
sudo cat /opt/webinoly/templates/source/php.ini > /etc/php/$(conf_read php-ver)/fpm/php.ini
|
||||
sudo cat /opt/webinoly/templates/source/www.conf > /etc/php/$(conf_read php-ver)/fpm/pool.d/www.conf
|
||||
sudo rm -rf /etc/php/$(conf_read php-ver)/fpm/pool.d/debug.conf
|
||||
php_optim
|
||||
echo "${gre}PHP settings has been updated successfully!${end}"
|
||||
else
|
||||
echo "${red}[ERROR] PHP could not been updated, source files not found!${end}"
|
||||
exit 1
|
||||
fi
|
||||
elif [[ $(conf_read php-optim) != "true" && $server_reset == "php" ]]; then
|
||||
echo "${red}[ERROR] PHP settings couldn't been updated, seems like is not installed in your server!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Display message just to show we are alive.
|
||||
if [[ $server_reset == "all" && $(conf_read php-optim) != "true" && $(conf_read nginx-optim) != "true" ]]; then
|
||||
echo "${blu}Nothing to do, NGINX and PHP are not installed yet!${end}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
show_db_data() {
|
||||
if [[ -n $(conf_read mysql-root) || -n $(conf_read mysql-admin) ]]; then
|
||||
rpass=$( echo $(conf_read mysql-root) | openssl enc -d -a -salt )
|
||||
apass=$( echo $(conf_read mysql-admin) | openssl enc -d -a -salt )
|
||||
echo ""
|
||||
[[ $dbpass == "raw" || -n $raw ]] && echo "root:$rpass" || echo "${gre} root: $rpass"
|
||||
[[ $dbpass == "raw" || -n $raw ]] && echo "admin:$apass" || echo " admin: $apass ${end}"
|
||||
echo ""
|
||||
else
|
||||
echo "${red}"
|
||||
echo "[ERROR] DB Passwords not found!"
|
||||
echo "${end}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
change_tools_port() {
|
||||
[[ $tools_port != true ]] && tools_port $tools_port || tools_port
|
||||
newport="$(conf_read tools-port)"
|
||||
if [[ $oldport != $newport && $(conf_read nginx-tool) == "true" && $(conf_read nginx) == "true" ]]; then
|
||||
# MV in some edge cases fails to rename, specially when so much files are within the directories.
|
||||
sudo mkdir -p /var/www/$newport
|
||||
sudo cp -rp /var/www/$oldport/* /var/www/$newport
|
||||
sudo rm -rf /var/www/$oldport
|
||||
|
||||
sudo mv /etc/nginx/sites-available/$oldport /etc/nginx/sites-available/$newport
|
||||
sudo rm /etc/nginx/sites-enabled/$oldport
|
||||
sudo ln -s /etc/nginx/sites-available/$newport /etc/nginx/sites-enabled/$newport
|
||||
sudo sed -i "s/${oldport}/${newport}/g" /etc/nginx/sites-available/$newport
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
set_tools_site() {
|
||||
if [[ $tools_site == true ]]; then
|
||||
echo "${gre}Please, enter a valid domain to access the Tools Section! ${end}"
|
||||
read -p "${blu}Domain: ${end}" tools_site
|
||||
tools_site=${tools_site:-NeverMatchDotCom}
|
||||
fi
|
||||
|
||||
if [[ -f /etc/nginx/sites-available/$tools_site && -f /etc/nginx/sites-available/$(conf_read tools-port) && $tools_site != "default" ]]; then
|
||||
# Check for previous assigned domain and remove
|
||||
if [[ -n $(conf_read tools-site) ]]; then
|
||||
sudo sed -i '/server_name/d' /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
# In case SSL is enabled
|
||||
sudo sed -i "/listen $(conf_read tools-port)/c \ listen $(conf_read tools-port) default_server deferred;" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i "/listen \[::\]:$(conf_read tools-port)/c \ listen [::]:$(conf_read tools-port) default_server;" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i '/headers-https.conf/d' /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i '/WebinolySSLstart/,/WebinolySSLend/{/.*/d}' /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i '/WebinolyToolsStartBlackhole/,/WebinolyToolsEndBlackhole/{/.*/d}' /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
fi
|
||||
|
||||
# Assign new domain/site
|
||||
sername=$(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$tools_site | grep -F "server_name" | sed -e 's/^[ \t]*//')
|
||||
sudo sed -i "/error_log/a \ ${sername}" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i "/listen $(conf_read tools-port)/c \ listen $(conf_read tools-port) deferred;" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i "/listen \[::\]:$(conf_read tools-port)/c \ listen [::]:$(conf_read tools-port);" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
|
||||
# If SSL is enabled
|
||||
if [[ $(is_ssl $tools_site) == "true" ]]; then
|
||||
sudo sed -i "/listen $(conf_read tools-port)/c \ listen $(conf_read tools-port) ssl http2 deferred;" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i "/listen \[::\]:$(conf_read tools-port)/c \ listen [::]:$(conf_read tools-port) ssl http2;" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i '/server_name /r /opt/webinoly/templates/template-site-ssl' /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i "/WebinolySSLstart/,/WebinolySSLend/{s/domain.com/$tools_site/}" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i '/locations.conf/a \ include common/headers-https.conf;' /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i "/WebinolySSLend/i \ error_page 497 https:\/\/\$host:\$server_port\$request_uri;" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
create_blackhole_cert
|
||||
fi
|
||||
|
||||
# Default blackhole for requests different from our assigned Tools-Site
|
||||
sudo sed -i '/Webinoly Admin-Tools NGINX CONFIGURATION/r /opt/webinoly/templates/general/tools-site-blackhole' /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i "/WebinolyToolsStartBlackhole/,/WebinolyToolsEndBlackhole/{s/22222/$(conf_read tools-port)/}" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
if [[ $(is_ssl $tools_site) == "false" ]]; then
|
||||
sudo sed -i "/WebinolyToolsStartBlackhole/,/WebinolyToolsEndBlackhole/{/ssl_certificate/d}" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i "/WebinolyToolsStartBlackhole/,/WebinolyToolsEndBlackhole/{/error_page/d}" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i "/WebinolyToolsStartBlackhole/,/WebinolyToolsEndBlackhole/{s/ssl //}" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
echo "${red}It's highly recommended having an SSL Cert enabled on this site. ${end}"
|
||||
fi
|
||||
|
||||
conf_write tools-site $tools_site
|
||||
echo "${gre}Domain ${blu}- ${tools_site}:$(conf_read tools-port) -${gre} was successfully assigned to access your server tools!${end}"
|
||||
elif [[ $tools_site == "default" ]]; then
|
||||
sudo rm -rf /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo cp /opt/webinoly/templates/nginx/22222 /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i "s/22222/$(conf_read tools-port)/g" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
conf_delete tools-site
|
||||
echo "${gre}Tools Site settings has been reset successfully!${end}"
|
||||
elif [[ -f /etc/nginx/sites-available/$tools_site && ! -f /etc/nginx/sites-available/$(conf_read tools-port) ]]; then
|
||||
echo "${red}[ERROR] Tools Site is not enabled! ${end}"
|
||||
exit 1
|
||||
else
|
||||
echo "${red}[ERROR] Domain/site not found. ${end}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
www_data_sftp_access() {
|
||||
if [[ $login_www_data == "on" && $(conf_read login-www-data) == "true" ]]; then
|
||||
echo "${gre}SFTP access for www-data user is already enabled! ${end}"
|
||||
elif [[ $login_www_data == "off" && $(conf_read login-www-data) != "true" ]]; then
|
||||
echo "${gre}SFTP access for www-data user is already disabled! ${end}"
|
||||
elif [[ $login_www_data == "on" ]]; then
|
||||
# Allow access for www-data user
|
||||
if [[ -f $HOME/.ssh/authorized_keys ]]; then
|
||||
sudo mkdir -p /var/www/.ssh
|
||||
sudo chmod 700 /var/www/.ssh
|
||||
sudo cat $HOME/.ssh/authorized_keys > /var/www/.ssh/authorized_keys
|
||||
sudo chmod 600 /var/www/.ssh/*
|
||||
fi
|
||||
sudo chown -R www-data:www-data /var/www
|
||||
|
||||
# www-data sftp-only access jail - if fails usrlib must be listed in /etc/shells
|
||||
sudo usermod -s /usr/lib/openssh/sftp-server www-data
|
||||
sudo addgroup --system sftponly > /dev/null 2>&1
|
||||
sudo usermod -G sftponly www-data
|
||||
sudo chown root:root /var/www
|
||||
sudo sed -i "/Subsystem sftp/c\Subsystem sftp internal-sftp" /etc/ssh/sshd_config
|
||||
sudo echo '# WebinolySFTPstart
|
||||
Match Group sftponly
|
||||
ChrootDirectory /var/www
|
||||
X11Forwarding no
|
||||
AllowTcpForwarding no
|
||||
ForceCommand internal-sftp
|
||||
# WebinolySFTPend' >> /etc/ssh/sshd_config
|
||||
|
||||
falus=$( grep -Gi "^AllowUsers " /etc/ssh/sshd_config )
|
||||
[[ -n $falus ]] && sudo sed -i "s/$falus/$falus www-data/" /etc/ssh/sshd_config
|
||||
|
||||
conf_write login-www-data true
|
||||
sudo service ssh restart
|
||||
echo "${gre}SFTP access for www-data user has been successfuly enabled! ${end}"
|
||||
|
||||
elif [[ $login_www_data == "off" ]]; then
|
||||
sudo rm -rf /var/www/.ssh
|
||||
sudo sed -i '/www-data:/c\www-data:x:33:33:www-data:\/var\/www:\/usr\/sbin\/nologin' /etc/passwd
|
||||
sudo gpasswd -d www-data sftponly > /dev/null 2>&1
|
||||
sudo delgroup sftponly > /dev/null 2>&1
|
||||
sudo chown www-data:www-data /var/www
|
||||
sudo sed -i "/Subsystem sftp/c\Subsystem sftp \/usr\/lib\/openssh\/sftp-server" /etc/ssh/sshd_config
|
||||
sudo sed -i '/WebinolySFTPstart/,/WebinolySFTPend/{/.*/d}' /etc/ssh/sshd_config
|
||||
|
||||
falus=$( grep -Gi "^AllowUsers " /etc/ssh/sshd_config )
|
||||
if [[ -n $falus ]]; then
|
||||
suffix=" www-data"
|
||||
foo=${falus%$suffix}
|
||||
sudo sed -i "s/$falus/$foo/" /etc/ssh/sshd_config
|
||||
fi
|
||||
|
||||
conf_write login-www-data purged
|
||||
sudo service ssh restart
|
||||
echo "${gre}SFTP access for www-data user has been successfuly disabled! ${end}"
|
||||
else
|
||||
echo "${red}[ERROR] Invalid value for login-www-data! ${end}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
config_fastcgi_cache() {
|
||||
if [[ $(conf_read nginx) == "true" ]]; then
|
||||
hitline=$( grep -F "fastcgi_cache_valid 200" /etc/nginx/conf.d/fastcgi.conf )
|
||||
hitval=$(echo "${hitline//;}" | rev | cut -d' ' -f 1 | rev)
|
||||
inaline=$( grep -F "fastcgi_cache_path" /etc/nginx/conf.d/fastcgi.conf )
|
||||
inactive=$(echo "${inaline//;}" | rev | cut -d' ' -f 1 | rev)
|
||||
inaval=$(echo "${inactive}" | cut -d'=' -f 2)
|
||||
maxsize=$(echo "${inaline}" | rev | cut -d' ' -f 2 | rev)
|
||||
othline=$( grep -F "fastcgi_cache_valid 301 302 307 404 410" /etc/nginx/conf.d/fastcgi.conf )
|
||||
othval=$(echo "${othline//;}" | rev | cut -d' ' -f 1 | rev)
|
||||
else
|
||||
hitval="Not yet defined"
|
||||
inaval="Not yet defined"
|
||||
othval="Not yet defined"
|
||||
fi
|
||||
|
||||
|
||||
if [[ $config_cache == true ]]; then
|
||||
echo "${gre}"
|
||||
echo "**********************************************************************"
|
||||
echo "************* Set FastCGI Cache new time values **************"
|
||||
echo "***** Example: 30d = 30days | 3h = 3hours | 5m = 5minutes ******"
|
||||
echo "**********************************************************************"
|
||||
echo "${blu}"
|
||||
echo "FastCGI Cache Valid for Pages (HttpCode: 200) actual value is: $hitval"
|
||||
read -p " Set new value: " hit
|
||||
hit=${hit:-$hitval}
|
||||
echo ""
|
||||
echo "Purge Cache for inactive pages actual value is: $inaval"
|
||||
read -p " Set new value: " ina
|
||||
ina=${ina:-$inaval}
|
||||
echo ""
|
||||
echo "FastCGI Cache Valid for Errors and Redirections (HttpCode: 301, 302, 307, 404, 410) actual value is: $othval"
|
||||
read -p " Set new value: " oth
|
||||
oth=${oth:-$othval}
|
||||
echo ""
|
||||
elif [[ $(echo "${config_cache}" | cut -c-1) == "[" && $(echo "${config_cache}" | rev | cut -c-1) == "]" ]]; then
|
||||
custombegin=$(echo "${config_cache}" | cut -c-1)
|
||||
customlast=$(echo "${config_cache}" | rev | cut -c-1)
|
||||
cachedata=${config_cache:1:-1}
|
||||
|
||||
hit=$(echo "${cachedata}" | cut -d',' -f 1 )
|
||||
ina=$(echo "${cachedata}" | cut -d',' -f 2 )
|
||||
oth=$(echo "${cachedata}" | cut -d',' -f 3 )
|
||||
else
|
||||
echo "${red}[ERROR] Please enter a valid value!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$hit" =~ ^[0-9]+[smhdwMy]$ && "$ina" =~ ^[0-9]+[smhdwMy]$ && "$oth" =~ ^[0-9]+[smhdwMy]$ ]]; then
|
||||
if [[ $(conf_read nginx) == "true" ]]; then
|
||||
sudo sed -i "/fastcgi_cache_valid 200/c \fastcgi_cache_valid 200 ${hit};" /etc/nginx/conf.d/fastcgi.conf
|
||||
sudo sed -i "/fastcgi_cache_valid 301 302 307 404 410/c \fastcgi_cache_valid 301 302 307 404 410 ${oth};" /etc/nginx/conf.d/fastcgi.conf
|
||||
sudo sed -i "/fastcgi_cache_path/c \fastcgi_cache_path \/var\/run\/nginx-cache levels=1:2 keys_zone=WORDPRESS:50m ${maxsize} inactive=${ina};" /etc/nginx/conf.d/fastcgi.conf
|
||||
fi
|
||||
conf_write fastcgi-conf ${hit},${ina},${oth}
|
||||
echo "${gre}FastCGI Cache values has been successfully updated!${end}"
|
||||
else
|
||||
echo "${red}[ERROR] Invalid values!${end}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
webinoly_uninstall() {
|
||||
echo "${red}"
|
||||
echo "You are about to completely remove Webinoly App from your server!!"
|
||||
echo "${blu}Are you sure [y/N]? "
|
||||
while read -r -n 1 -s answer; do
|
||||
answer=${answer:-n}
|
||||
echo ""
|
||||
[[ $answer = [YyNn] ]] && break
|
||||
done
|
||||
|
||||
if [[ $answer == [Yy] ]]; then
|
||||
sudo tar -Pcf $HOME/.webinoly-conf-restore_dont-remove /opt/webinoly/webinoly.conf /opt/webinoly/templates/source
|
||||
sudo rm -rf /opt/webinoly
|
||||
sudo rm /usr/bin/webinoly
|
||||
sudo rm /usr/bin/stack
|
||||
sudo rm /usr/bin/site
|
||||
sudo rm /usr/bin/httpauth
|
||||
sudo rm /usr/bin/log
|
||||
echo "${gre}Webinoly App has been removed successfully from your server!${end}"
|
||||
exit 0 # Only allowed here because after this Webinoly does not exist in the server!
|
||||
else
|
||||
echo "${red}Action aborted!${end}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
external_sources_update() {
|
||||
echo "${blu}- Downloading Public Suffix List!${end}"
|
||||
sudo wget --timeout=15 -t 1 -qrO /tmp/temp-public_suffix_list.dat https://publicsuffix.org/list/public_suffix_list.dat
|
||||
if [[ -s /tmp/temp-public_suffix_list.dat ]]; then
|
||||
echo "${blu}- Processing file!${end}"
|
||||
sudo sed -i '/^\/\// d' /tmp/temp-public_suffix_list.dat
|
||||
sudo sed -i '/^$/d' /tmp/temp-public_suffix_list.dat
|
||||
sudo sed -i 's/[!]\+//g' /tmp/temp-public_suffix_list.dat
|
||||
sudo sed -i 's/^\*\.\+//g' /tmp/temp-public_suffix_list.dat
|
||||
sudo mv /tmp/temp-public_suffix_list.dat /opt/webinoly/lib/public_suffix_list.dat
|
||||
echo "${gre}Domain list has been successfully updated!${end}"
|
||||
else
|
||||
echo "${red}[ERROR] Domain list not updated!${end}"
|
||||
err_cont=true
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "${blu}- Downloading Timezone Database!${end}"
|
||||
sudo wget --timeout=15 -t 1 -qrO /tmp/timezonedb.tgz https://pecl.php.net/get/timezonedb
|
||||
if [[ -s /tmp/timezonedb.tgz ]]; then
|
||||
echo "${blu}- Processing file!${end}"
|
||||
sudo tar -xf /tmp/timezonedb.tgz -C /tmp/ --wildcards --no-anchored timezonedb-*/timezonedb.h --strip-components=1
|
||||
sudo sed -i '/^\t{.*},$/!d' /tmp/timezonedb.h
|
||||
sudo cut -d'"' -f2 /tmp/timezonedb.h > /opt/webinoly/lib/timezone.dat
|
||||
sudo rm /tmp/timezonedb.*
|
||||
echo "${gre}Timezone Database has been successfully updated!${end}"
|
||||
else
|
||||
echo "${red}[ERROR] Timezone Database not updated!${end}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
clear_caches() {
|
||||
if [[ $clear_cache =~ ^(redis|all)$ ]]; then
|
||||
if [[ $(conf_read php-tool) == "true" && -f /etc/redis/redis.conf ]]; then
|
||||
sudo redis-cli flushall
|
||||
echo "${gre}- Redis Cache has been successfully cleared!${end}"
|
||||
else
|
||||
echo "${red}[ERROR] We can not clear Redis Cache because is not installed!${end}"
|
||||
err_cont=true
|
||||
fi
|
||||
fi
|
||||
if [[ $clear_cache =~ ^(memcache|memcached|all)$ ]]; then
|
||||
if [[ $(conf_read php-tool) == "true" && -f /etc/memcached.conf ]]; then
|
||||
memhost=$(grep ^-l /etc/memcached.conf | cut -f 2 -d ' ')
|
||||
memport=$(grep ^-p /etc/memcached.conf | cut -f 2 -d ' ')
|
||||
echo flush_all > /dev/tcp/$memhost/$memport
|
||||
echo "${gre}- Memcached has been successfully cleared!${end}"
|
||||
else
|
||||
echo "${red}[ERROR] We can not clear Memcache because is not installed!${end}"
|
||||
err_cont=true
|
||||
fi
|
||||
fi
|
||||
if [[ $clear_cache =~ ^(opcache|all)$ ]]; then
|
||||
if [[ $(conf_read nginx-tool) == "true" && $(conf_read php-tool) == "true" ]]; then
|
||||
port=$(conf_read tools-port)
|
||||
if [[ ! -f /var/www/$port/htdocs/php/opcache/index.php ]]; then
|
||||
sudo mkdir /var/www/$port/htdocs/php/opcache
|
||||
sudo touch /var/www/$port/htdocs/php/opcache/index.php
|
||||
echo '<?php opcache_reset(); echo "OK\n";' > /var/www/$port/htdocs/php/opcache/index.php
|
||||
sudo chown -R www-data:www-data /var/www/$port/htdocs/php/opcache
|
||||
sudo chmod 644 /var/www/$port/htdocs/php/opcache/index.php
|
||||
fi
|
||||
wget --spider --no-check-certificate --timeout=15 -t 1 localhost:$port/php/opcache/ > /dev/null 2>&1 &
|
||||
echo "${gre}- OpCache has been successfully cleared!${end}"
|
||||
else
|
||||
echo "${red}[ERROR] We can not clear OpCache because PHP or NGINX are not installed!${end}"
|
||||
err_cont=true
|
||||
fi
|
||||
fi
|
||||
if [[ $clear_cache =~ ^(fastcgi|all)$ ]]; then
|
||||
if [[ $(conf_read nginx) == "true" ]]; then
|
||||
sudo rm -Rf /var/run/nginx-cache/*
|
||||
echo "${gre}- FastCgi Cache has been successfully cleared!${end}"
|
||||
else
|
||||
echo "${red}[ERROR] We can not clear FastCGI Cache because NGINX is not installed!${end}"
|
||||
err_cont=true
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
nginx_blockip() {
|
||||
if [[ -z $purge ]]; then
|
||||
if [[ -n $list ]]; then
|
||||
echo ""
|
||||
[[ -n $raw ]] && sign="" || sign="${blu}+ "
|
||||
if [[ -s /etc/nginx/conf.d/blockips.conf ]]; then
|
||||
sudo sed -n "s/^deny /${sign}/p;" /etc/nginx/conf.d/blockips.conf | sudo sed -n 's/;$//p'
|
||||
else
|
||||
echo "[Empty] No IP's were found!"
|
||||
fi
|
||||
[[ $list == "raw" || -n $raw ]] && echo "" || echo "${end}"
|
||||
else
|
||||
[[ $blockip == true ]] && read -p "${blu}IP address to block: ${end}" blockip
|
||||
if [[ $(ip_check $blockip) == "true" ]]; then
|
||||
if [[ ! -f /etc/nginx/conf.d/blockips.conf ]]; then
|
||||
sudo touch /etc/nginx/conf.d/blockips.conf
|
||||
sudo chmod 644 /etc/nginx/conf.d/blockips.conf
|
||||
sudo chown -R root:root /etc/nginx/conf.d/blockips.conf
|
||||
fi
|
||||
exist=$( grep -E "^deny $blockip;$" /etc/nginx/conf.d/blockips.conf )
|
||||
if [[ -z $exist ]]; then
|
||||
echo "deny $blockip;" >> /etc/nginx/conf.d/blockips.conf
|
||||
echo "${gre}The IP address ${blu}'$blockip'${gre} was successfully blocked!${end}"
|
||||
else
|
||||
echo "${gre}IP '$blockip' is already blocked!${end}"
|
||||
fi
|
||||
else
|
||||
echo "${red}[ERROR] Please, enter a valid IP value!${end}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
elif [[ -n $purge ]]; then
|
||||
[[ $blockip == true ]] && read -p "${blu}IP address to unblock: ${end}" blockip
|
||||
if [[ $(ip_check $blockip) == "true" ]]; then
|
||||
# https://stackoverflow.com/questions/1797906/delete-using-a-different-delimiter-with-sed
|
||||
[[ -f /etc/nginx/conf.d/blockips.conf ]] && sed -i "\#^deny ${blockip};#d" /etc/nginx/conf.d/blockips.conf
|
||||
|
||||
# Remove site-auth-file if empty.
|
||||
[[ ! -s /etc/nginx/conf.d/blockips.conf ]] && sudo rm /etc/nginx/conf.d/blockips.conf
|
||||
|
||||
echo "${gre}The IP address ${blu}'$blockip'${gre} was successfully unblocked!${end}"
|
||||
else
|
||||
echo "${red}[ERROR] Please, enter a valid IP value!${end}"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "${red}[ERROR] Nginx file not found!${end}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
set_default_nginx_response() {
|
||||
if [[ $default_site == true ]]; then
|
||||
echo "${gre}Please, enter a valid option to set the Default-Site server response! ${end}"
|
||||
read -p "${blu}default/blackhole or any existing domain: ${end}" default_site
|
||||
default_site=${default_site:-NeverMatchDotCom}
|
||||
fi
|
||||
|
||||
if [[ $default_site == "default" ]]; then
|
||||
if [[ -f /opt/webinoly/templates/source/default ]]; then
|
||||
sudo cat /opt/webinoly/templates/source/default >| /etc/nginx/sites-available/default
|
||||
remove_domain_default_site
|
||||
conf_write default-site default
|
||||
echo "${gre}Default Nginx was successfully assigned as default site!${end}"
|
||||
else
|
||||
echo "${red}[ERROR] Nginx Default file backup not found! ${end}"
|
||||
exit 1
|
||||
fi
|
||||
elif [[ $default_site == "blackhole" ]]; then
|
||||
sudo cat /opt/webinoly/templates/general/nginx-blackhole >| /etc/nginx/sites-available/default
|
||||
remove_domain_default_site
|
||||
create_blackhole_cert
|
||||
conf_write default-site blackhole
|
||||
echo "${gre}Blackhole Nginx site was successfully assigned as default site!${end}"
|
||||
else
|
||||
# Domain option
|
||||
if [[ -L /etc/nginx/sites-enabled/$default_site ]]; then
|
||||
remove_domain_default_site
|
||||
sudo sed -i "s/listen 80;/listen 80 default_server;/" /etc/nginx/sites-available/$default_site
|
||||
sudo sed -i "s/listen \[::\]:80;/listen [::]:80 default_server;/" /etc/nginx/sites-available/$default_site
|
||||
sudo sed -i '/WebinolyNginxServerStart/,/WebinolyNginxServerEnd/{s/listen 443 ssl http2;/listen 443 ssl http2 default_server;/}' /etc/nginx/sites-available/$default_site
|
||||
sudo sed -i '/WebinolyNginxServerStart/,/WebinolyNginxServerEnd/{s/listen \[::\]:443 ssl http2;/listen [::]:443 ssl http2 default_server;/}' /etc/nginx/sites-available/$default_site
|
||||
|
||||
# If default site is Non-SSL, we need add a blackhole for port 443.
|
||||
if [[ $(is_ssl $default_site) == "false" ]]; then
|
||||
create_blackhole_cert
|
||||
sudo sed -i '1r /opt/webinoly/templates/general/nginx-blackhole' /etc/nginx/sites-available/$default_site
|
||||
sudo sed -i '/NonSSL/,/NonSSLend/{/.*/d}' /etc/nginx/sites-available/$default_site
|
||||
fi
|
||||
|
||||
sudo rm -rf /etc/nginx/sites-enabled/default
|
||||
conf_write default-site $default_site
|
||||
echo "${gre}Site ${blu}- ${default_site} -${gre} was successfully assigned as default site!${end}"
|
||||
else
|
||||
[[ -f /etc/nginx/sites-available/$default_site ]] && echo "${red}Site found but is disabled.${end}"
|
||||
echo "${red}[ERROR] Please, enter a valid option (default, blackhole or domain.com). ${end}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
aws_s3_credentials() {
|
||||
if [[ $aws_s3_credentials == true ]]; then
|
||||
echo ""
|
||||
read -p "${blu}Access Key ID: ${end}" user
|
||||
read -p "${blu}Secret Access Key: ${end}" pass
|
||||
echo ""
|
||||
elif [[ $(echo "${aws_s3_credentials}" | cut -c-1) == "[" && $(echo "${aws_s3_credentials}" | rev | cut -c-1) == "]" ]]; then
|
||||
cred=${aws_s3_credentials:1:-1}
|
||||
user=$(echo "${cred}" | cut -d',' -f 1 -s)
|
||||
pass=$(echo "${cred}" | cut -d',' -f 2 -s)
|
||||
else
|
||||
echo "${red}[ERROR] Invalid AWS S3 Credentials!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! [[ -n $user && -n $pass ]]; then
|
||||
echo "${red}[ERROR] Please, enter a valid AWS S3 Access and Secret Key!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sudo rm -rf /root/.aws/credentials
|
||||
sudo mkdir -p /root/.aws
|
||||
sudo touch /root/.aws/credentials
|
||||
sudo echo "[default]
|
||||
aws_access_key_id = $user
|
||||
aws_secret_access_key = $pass" >> /root/.aws/credentials
|
||||
echo "${gre}AWS S3 Credentials successfully added!${end}"
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ api-events_update has
|
|||
[[ -n $wp_admin && -z $domain ]] || check_for_nginx -ask
|
||||
|
||||
# Check for domain.
|
||||
if [[ -n $domain && -a /etc/nginx/sites-available/$domain ]]; then
|
||||
if [[ -n $domain && -f /etc/nginx/sites-available/$domain ]]; then
|
||||
authfile="apps.d/.htpasswd-$domain"
|
||||
elif [[ -n $domain && ! -a /etc/nginx/sites-available/$domain ]]; then
|
||||
elif [[ -n $domain && ! -f /etc/nginx/sites-available/$domain ]]; then
|
||||
echo "${red}[ERROR] Domain not found!${end}"
|
||||
exit 1
|
||||
else
|
||||
|
@ -55,7 +55,7 @@ if [[ -n $add ]]; then
|
|||
fi
|
||||
|
||||
# Create pass-file if not-exist.
|
||||
if [[ ! -a /etc/nginx/$authfile ]]; then
|
||||
if [[ ! -f /etc/nginx/$authfile ]]; then
|
||||
sudo touch /etc/nginx/$authfile
|
||||
sudo chmod 644 /etc/nginx/$authfile
|
||||
sudo chown -R root:root /etc/nginx/$authfile
|
||||
|
@ -75,7 +75,7 @@ if [[ -n $add ]]; then
|
|||
elif [[ -n $delete ]]; then
|
||||
api-events_update ha2
|
||||
[[ $delete == true ]] && read -p "${blu}HTTP-Auth User: ${end}" userpurge || userpurge=$delete
|
||||
[[ -a /etc/nginx/$authfile ]] && exist=$( grep -F "${userpurge}:" /etc/nginx/$authfile )
|
||||
[[ -f /etc/nginx/$authfile ]] && exist=$( grep -F "${userpurge}:" /etc/nginx/$authfile )
|
||||
if [[ -z $exist ]]; then
|
||||
echo "${red}[ERROR] User '$userpurge' does not exist!${end}"
|
||||
exit 1
|
||||
|
@ -85,7 +85,7 @@ elif [[ -n $delete ]]; then
|
|||
# Remove site-auth-file if empty.
|
||||
[[ -n $domain && ! -s /etc/nginx/$authfile ]] && sudo rm /etc/nginx/$authfile
|
||||
|
||||
echo "${gre}User '$userpurge has been deleted successfully!${end}"
|
||||
echo "${gre}User '$userpurge' has been deleted successfully!${end}"
|
||||
|
||||
|
||||
elif [[ -n $wp_admin ]]; then
|
||||
|
@ -147,9 +147,9 @@ elif [[ -n $whitelist ]]; then
|
|||
if [[ -z $purge ]]; then
|
||||
if [[ -n $list ]]; then
|
||||
[[ -n $raw ]] && echo "" || echo "${blu}"
|
||||
if [[ -a /etc/nginx/apps.d/whitelist-acl.conf && -z $raw ]]; then
|
||||
if [[ -f /etc/nginx/apps.d/whitelist-acl.conf && -z $raw ]]; then
|
||||
sudo sed -n 's/^allow //p;' /etc/nginx/apps.d/whitelist-acl.conf | sudo sed -n 's/;$//p' | sed 's/^/+ /'
|
||||
elif [[ -a /etc/nginx/apps.d/whitelist-acl.conf && -n $raw ]]; then
|
||||
elif [[ -f /etc/nginx/apps.d/whitelist-acl.conf && -n $raw ]]; then
|
||||
sudo sed -n 's/^allow //p;' /etc/nginx/apps.d/whitelist-acl.conf | sudo sed -n 's/;$//p'
|
||||
else
|
||||
echo "[Empty] No IP's were found!"
|
||||
|
@ -158,7 +158,7 @@ elif [[ -n $whitelist ]]; then
|
|||
else
|
||||
[[ $whitelist == true ]] && read -p "${blu}IP address to whitelist: ${end}" whitelist
|
||||
if [[ $(ip_check $whitelist) == "true" ]]; then
|
||||
if [[ ! -a /etc/nginx/apps.d/whitelist-acl.conf ]]; then
|
||||
if [[ ! -f /etc/nginx/apps.d/whitelist-acl.conf ]]; then
|
||||
sudo touch /etc/nginx/apps.d/whitelist-acl.conf
|
||||
sudo chmod 644 /etc/nginx/apps.d/whitelist-acl.conf
|
||||
sudo chown -R root:root /etc/nginx/apps.d/whitelist-acl.conf
|
||||
|
@ -180,7 +180,7 @@ elif [[ -n $whitelist ]]; then
|
|||
[[ $whitelist == true ]] && read -p "${blu}IP address to remove from whitelist: ${end}" whitelist
|
||||
if [[ $(ip_check $whitelist) == "true" ]]; then
|
||||
# https://stackoverflow.com/questions/1797906/delete-using-a-different-delimiter-with-sed
|
||||
[[ -a /etc/nginx/apps.d/whitelist-acl.conf ]] && sudo sed -i "\#^allow ${whitelist};#d" /etc/nginx/apps.d/whitelist-acl.conf
|
||||
[[ -f /etc/nginx/apps.d/whitelist-acl.conf ]] && sudo sed -i "\#^allow ${whitelist};#d" /etc/nginx/apps.d/whitelist-acl.conf
|
||||
|
||||
# Remove site-auth-file if empty.
|
||||
[[ ! -s /etc/nginx/apps.d/whitelist-acl.conf ]] && sudo rm /etc/nginx/apps.d/whitelist-acl.conf
|
||||
|
@ -216,7 +216,7 @@ elif [[ -n $path && -n $domain ]]; then
|
|||
echo "${red}[ERROR] HTTP Authentication is not allowed in subfolders (only root '/' is allowed) for Reverse Proxy sites!${end}"
|
||||
exit 1
|
||||
elif [[ $path =~ ^\/([A-Za-z0-9_\/\.\-]+)?$ ]]; then
|
||||
if [[ ! -a /etc/nginx/apps.d/$domain-nginx.conf ]]; then
|
||||
if [[ ! -f /etc/nginx/apps.d/$domain-nginx.conf ]]; then
|
||||
sudo touch /etc/nginx/apps.d/$domain-nginx.conf
|
||||
sudo chmod 644 /etc/nginx/apps.d/$domain-nginx.conf
|
||||
sudo chown -R root:root /etc/nginx/apps.d/$domain-nginx.conf
|
||||
|
@ -267,7 +267,7 @@ location $sign$path {
|
|||
sudo rm -rf /etc/nginx/apps.d/$domain-nginx.conf
|
||||
echo "${gre}HTTP Authentication successfully removed from all your custom paths!${gre}${end}"
|
||||
elif [[ $path =~ ^\/([A-Za-z0-9_\/\.\-]+)?$ ]]; then
|
||||
if [[ -a /etc/nginx/apps.d/$domain-nginx.conf ]]; then
|
||||
if [[ -f /etc/nginx/apps.d/$domain-nginx.conf ]]; then
|
||||
sudo sed -i "/^# Path: $(echo $path | sed "s#/#\\\/#g")/,/^# PathEnd/{/.*/d}" /etc/nginx/apps.d/$domain-nginx.conf
|
||||
if [[ ! -s /etc/nginx/apps.d/$domain-nginx.conf ]]; then
|
||||
sudo rm /etc/nginx/apps.d/$domain-nginx.conf
|
||||
|
@ -289,9 +289,9 @@ elif [[ $list == "protected" && -n $domain ]]; then
|
|||
elif [[ -z $root ]]; then
|
||||
[[ -z $raw ]] && echo "${blu}" || echo ""
|
||||
fi
|
||||
if [[ -a /etc/nginx/apps.d/$domain-nginx.conf && -z $raw ]]; then
|
||||
if [[ -f /etc/nginx/apps.d/$domain-nginx.conf && -z $raw ]]; then
|
||||
sudo sed -n 's/^# Path: //p;' /etc/nginx/apps.d/$domain-nginx.conf | sed 's/^/+ /'
|
||||
elif [[ -a /etc/nginx/apps.d/$domain-nginx.conf && -n $raw ]]; then
|
||||
elif [[ -f /etc/nginx/apps.d/$domain-nginx.conf && -n $raw ]]; then
|
||||
sudo sed -n 's/^# Path: //p;' /etc/nginx/apps.d/$domain-nginx.conf
|
||||
elif [[ -z $root ]]; then
|
||||
echo "[Empty] No protected paths were found!"
|
||||
|
@ -302,7 +302,7 @@ elif [[ $list == "protected" && -n $domain ]]; then
|
|||
|
||||
elif [[ -n $list ]]; then
|
||||
echo ""
|
||||
if [[ -a /etc/nginx/$authfile ]]; then
|
||||
if [[ -f /etc/nginx/$authfile ]]; then
|
||||
cat /etc/nginx/$authfile |
|
||||
{
|
||||
while read line
|
||||
|
|
32
plugins/log
32
plugins/log
|
@ -22,30 +22,30 @@ error() {
|
|||
|
||||
|
||||
if [[ -n $mail || -n $email ]]; then
|
||||
if [[ -a /var/log/mail.log && -a /var/log/mail.err ]]; then
|
||||
if [[ -f /var/log/mail.log && -f /var/log/mail.err ]]; then
|
||||
sudo tail -f --lines=$clines /var/log/mail.log /var/log/mail.err
|
||||
elif [[ -a /var/log/mail.log ]]; then
|
||||
elif [[ -f /var/log/mail.log ]]; then
|
||||
sudo tail -f --lines=$clines /var/log/mail.log
|
||||
elif [[ -a /var/log/mail.err ]]; then
|
||||
elif [[ -f /var/log/mail.err ]]; then
|
||||
sudo tail -f --lines=$clines /var/log/mail.err
|
||||
else
|
||||
error
|
||||
fi
|
||||
elif [[ -n $fpm || -n $php ]]; then
|
||||
check_for_php
|
||||
if [[ -a /var/log/php/$(conf_read php-ver)/fpm.log ]]; then
|
||||
if [[ -f /var/log/php/$(conf_read php-ver)/fpm.log ]]; then
|
||||
sudo tail -f --lines=$clines /var/log/php/$(conf_read php-ver)/*.log
|
||||
else
|
||||
error
|
||||
fi
|
||||
elif [[ -n $le ]]; then
|
||||
if [[ -a /var/log/letsencrypt/letsencrypt.log ]]; then
|
||||
if [[ -f /var/log/letsencrypt/letsencrypt.log ]]; then
|
||||
sudo tail -f --lines=$clines /var/log/letsencrypt/letsencrypt.log
|
||||
else
|
||||
error
|
||||
fi
|
||||
elif [[ -n $ssh ]]; then
|
||||
if [[ -a /var/log/auth.log ]]; then
|
||||
if [[ -f /var/log/auth.log ]]; then
|
||||
sudo tail -f --lines=$clines /var/log/auth.log
|
||||
else
|
||||
error
|
||||
|
@ -176,7 +176,7 @@ elif [[ -n $only_error ]]; then
|
|||
fi
|
||||
|
||||
# Per site
|
||||
if [[ -n $domain && -a /etc/nginx/sites-available/$domain ]]; then
|
||||
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
|
||||
|
@ -203,14 +203,14 @@ elif [[ -n $only_error ]]; then
|
|||
echo "${gre}Access Log is already disabled for ${blu}${domain} ${gre}site!${end}"
|
||||
fi
|
||||
fi
|
||||
elif [[ -n $domain && ! -a /etc/nginx/sites-available/$domain ]]; then
|
||||
elif [[ -n $domain && ! -f /etc/nginx/sites-available/$domain ]]; then
|
||||
echo "${red}[ERROR] Domain not found!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Site log files
|
||||
elif [[ -n $domain && -a /etc/nginx/sites-available/$domain ]]; then
|
||||
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
|
||||
|
@ -220,7 +220,7 @@ elif [[ -n $domain && -a /etc/nginx/sites-available/$domain ]]; then
|
|||
|
||||
# WordPress Logs
|
||||
[[ -z $subfolder ]] && wpath="/var/www/$domain/wp-config.php" || wpath="/var/www/$domain/htdocs$subfolder/wp-config.php"
|
||||
if [[ -n $wp && -a $wpath ]]; then
|
||||
if [[ -n $wp && -f $wpath ]]; then
|
||||
iswpdeb=$( grep -F "'WP_DEBUG'" $wpath | cut -f 3 -d "'" -s | sed 's/[^a-zA-Z]*//g' )
|
||||
if [[ $wp == "on" ]]; then
|
||||
if [[ $iswpdeb == "false" ]]; then
|
||||
|
@ -241,7 +241,7 @@ elif [[ -n $domain && -a /etc/nginx/sites-available/$domain ]]; then
|
|||
else
|
||||
echo "${gre}WordPress Debug mode for${blu} $domain ${gre}is already disabled!${end}"
|
||||
fi
|
||||
elif [[ -a /var/www/$domain/htdocs$subfolder/wp-content/debug.log && $iswpdeb == "true" ]]; then
|
||||
elif [[ -f /var/www/$domain/htdocs$subfolder/wp-content/debug.log && $iswpdeb == "true" ]]; then
|
||||
sudo tail -f --lines=$clines /var/www/$domain/htdocs$subfolder/wp-content/debug.log
|
||||
elif [[ $iswpdeb != "true" ]]; then
|
||||
echo "${red}[ERROR] WordPress Debug Mode is not enabled!${end}"
|
||||
|
@ -255,16 +255,16 @@ elif [[ -n $domain && -a /etc/nginx/sites-available/$domain ]]; then
|
|||
exit 1
|
||||
|
||||
# Access and error logs
|
||||
elif [[ -n $error && -a /var/log/nginx/$domain.error.log ]]; then
|
||||
elif [[ -n $error && -f /var/log/nginx/$domain.error.log ]]; then
|
||||
sudo tail -f --lines=$clines /var/log/nginx/$domain.error.log
|
||||
elif [[ -a /var/log/nginx/$domain.access.log && -z $error && -z $wp ]]; then
|
||||
elif [[ -f /var/log/nginx/$domain.access.log && -z $error && -z $wp ]]; then
|
||||
sudo tail -f --lines=$clines /var/log/nginx/$domain.access.log
|
||||
else
|
||||
echo "${red}[ERROR] Log file not found!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
elif [[ -n $domain && ! -a /etc/nginx/sites-available/$domain ]]; then
|
||||
elif [[ -n $domain && ! -f /etc/nginx/sites-available/$domain ]]; then
|
||||
echo "${red}[ERROR] Domain not found!${end}"
|
||||
exit 1
|
||||
|
||||
|
@ -277,9 +277,9 @@ elif [[ -z $domain ]]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n $error && -a /var/log/nginx/error.log ]]; then
|
||||
if [[ -n $error && -f /var/log/nginx/error.log ]]; then
|
||||
sudo tail -f --lines=$clines /var/log/nginx/*error.log
|
||||
elif [[ -a /var/log/nginx/access.log && -z $1 ]]; then
|
||||
elif [[ -f /var/log/nginx/access.log && -z $1 ]]; then
|
||||
sudo tail -f --lines=$clines /var/log/nginx/*access.log
|
||||
else
|
||||
echo "${red}[ERROR] Please, enter a valid option! ${end}"
|
||||
|
|
477
plugins/site
477
plugins/site
|
@ -128,40 +128,7 @@ fi
|
|||
# Delete all sites
|
||||
if [[ -n $delete_all ]]; then
|
||||
api-events_update si7
|
||||
echo "${red}"
|
||||
echo "All your sites files will be removed."
|
||||
echo "This action will only delete Databases attached to a WordPress site, any other Database will not be deleted."
|
||||
|
||||
if ! [[ $delete_all =~ ^(force|keep-db)$ ]]; then
|
||||
echo "${blu}"
|
||||
echo "Are you sure [y/N]? ${end}"
|
||||
while read -r -n 1 -s answer; do
|
||||
answer=${answer:-n}
|
||||
echo ""
|
||||
[[ $answer = [YyNn] ]] && break
|
||||
done
|
||||
|
||||
if [[ $answer == [Nn] ]]; then
|
||||
echo "${red}Action aborted!${end}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# List all remaining sites (parked and proxy)
|
||||
for site in "/etc/nginx/sites-available"/*
|
||||
do
|
||||
[[ $delete_all == "keep-db" ]] && delete="keep-db" || delete="force"
|
||||
domain=$(echo $site | cut -f 5 -d "/")
|
||||
[[ $domain != "default" && $domain != $(conf_read tools-port) ]] && deletesite
|
||||
done
|
||||
|
||||
# Delete all files - double check!
|
||||
# -rf is necessary to not generate an error when is empty.
|
||||
sudo rm -rf /etc/nginx/sites-available/!(default|$(conf_read tools-port))
|
||||
sudo rm -rf /etc/nginx/sites-enabled/!(default|$(conf_read tools-port))
|
||||
sudo rm -rf /var/www/!(html|$(conf_read tools-port))
|
||||
echo ""
|
||||
echo "${gre}All sites and data has been deleted successfully!${end}"
|
||||
delete_all_sites
|
||||
|
||||
|
||||
# Create PHP site
|
||||
|
@ -195,60 +162,21 @@ elif [[ -n $wp && -n $domain ]]; then
|
|||
[[ $(conf_read wp-admin-auth) == "purged" ]] && sudo httpauth $domain -wp-admin=off > /dev/null 2>&1
|
||||
[[ $(conf_read yoast-sitemap) != "purged" ]] && sudo site $domain -yoast-sitemap=on > /dev/null 2>&1
|
||||
else
|
||||
if [[ -a /etc/nginx/sites-available/$domain && -n $subfolder && $type == [123] && -d /var/www/$domain/htdocs$subfolder ]]; then
|
||||
if [[ -f /etc/nginx/sites-available/$domain && -n $subfolder && $type == [123] && -d /var/www/$domain/htdocs$subfolder ]]; then
|
||||
echo "${red}[ERROR] Subfolder ${blu}'$subfolder'${red} already exists!${end}"
|
||||
exit 1
|
||||
elif [[ -a /etc/nginx/sites-available/$domain && -n $subfolder && $type == [123] && ! -d /var/www/$domain/htdocs$subfolder ]]; then
|
||||
elif [[ -f /etc/nginx/sites-available/$domain && -n $subfolder && $type == [123] && ! -d /var/www/$domain/htdocs$subfolder ]]; then
|
||||
wpinstall
|
||||
else
|
||||
createsite
|
||||
fi
|
||||
|
||||
sudo sed -i "/# WebinolyCustom$/a \ include apps.d/$domain$subname-php.conf;" /etc/nginx/sites-available/$domain
|
||||
|
||||
sudo cp /etc/nginx/common/php.conf /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo cp /etc/nginx/common/wpfc.conf /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
sudo cp /etc/nginx/common/wpcommon.conf /etc/nginx/apps.d/$domain$subname-wpcommon.conf
|
||||
sudo cp /etc/nginx/common/wpcommon-noauth.conf /etc/nginx/apps.d/$domain$subname-wpcommon-noauth.conf
|
||||
sudo cp /etc/nginx/common/locations.conf /etc/nginx/apps.d/$domain$subname-locations.conf
|
||||
sudo cp /etc/nginx/common/yoast-sitemap.conf /etc/nginx/apps.d/$domain$subname-yoast-sitemap.conf
|
||||
|
||||
sudo sed -i "/^location \/ {/,/^}$/{/.*/d}" /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo sed -i "/^location \/ {/,/^}$/{/.*/d}" /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
sudo sed -i '/DO NOT MODIFY,/r /opt/webinoly/templates/template-site-wpsubfolder' /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo cat /opt/webinoly/templates/template-site-wpsubfolder >> /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
sudo sed -i "s#subfolder#$subfolder#g" /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo sed -i "s#subfolder#$subfolder#g" /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
sudo sed -i "s/domain/$domain/g" /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo sed -i "s/domain/$domain/g" /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
sudo sed -i "s/subname/$subname/g" /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo sed -i "s/subname/$subname/g" /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
sudo sed -i "s#/index.php#$subfolder/index.php#g" /etc/nginx/apps.d/$domain$subname-yoast-sitemap.conf
|
||||
|
||||
sed -ri "s/^location(.*)\/([a-z].*)$/location\1subfolder\/\2/" /etc/nginx/apps.d/$domain$subname-locations.conf
|
||||
sed -ri "s/location(.*) \/(.*) \{$/location\1 subfolder\/\2 \{/" /etc/nginx/apps.d/$domain$subname-wpcommon.conf
|
||||
sed -ri "s/location(.*) \/(.*) \{$/location\1 subfolder\/\2 \{/" /etc/nginx/apps.d/$domain$subname-wpcommon-noauth.conf
|
||||
sudo sed -i "s#subfolder#$subfolder#g" /etc/nginx/apps.d/$domain$subname-locations.conf
|
||||
sudo sed -i "s#subfolder#$subfolder#g" /etc/nginx/apps.d/$domain$subname-wpcommon.conf
|
||||
sudo sed -i "s#subfolder#$subfolder#g" /etc/nginx/apps.d/$domain$subname-wpcommon-noauth.conf
|
||||
|
||||
[[ $(conf_read wp-admin-auth) == "purged" ]] && sudo httpauth $domain -wp-admin=off -subfolder=$subfolder > /dev/null 2>&1
|
||||
[[ $(conf_read yoast-sitemap) != "purged" ]] && sudo site $domain -yoast-sitemap=on -subfolder=$subfolder > /dev/null 2>&1
|
||||
|
||||
# Activate FastCgi cache
|
||||
if [[ $cache == "on" ]]; then
|
||||
sudo sed -i "/$domain$subname-php.conf;/c \ include apps.d/$domain$subname-wpfc.conf;" /etc/nginx/sites-available/$domain
|
||||
wp_cache_plugins
|
||||
fi
|
||||
|
||||
sudo chown -R www-data:www-data /var/www
|
||||
[[ $(conf_read login-www-data) == "true" ]] && sudo chown root:root /var/www
|
||||
echo "${gre}WordPress has been successfully installed in${blu} $domain$subfolder ${gre}subfolder!${end}"
|
||||
wp_subfolder
|
||||
fi
|
||||
|
||||
|
||||
# Convert WP single to Multisite
|
||||
elif [[ -n $multisite_convert && -a /etc/nginx/sites-available/$domain ]]; then
|
||||
elif [[ -n $multisite_convert && -f /etc/nginx/sites-available/$domain ]]; then
|
||||
if [[ ( -z $subfolder && $(is_wp $domain) == "false" ) || ( -n $subfolder && $(is_wp $domain $subfolder) == "false" ) ]]; then
|
||||
echo "${red}[ERROR] Site${blu} $domain$subfolder ${red}is not a WP site!${end}"
|
||||
exit 1
|
||||
|
@ -263,177 +191,22 @@ elif [[ -n $multisite_convert && -a /etc/nginx/sites-available/$domain ]]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
[[ -z $subfolder ]] && wpcon="/var/www/$domain/wp-config.php" || wpcon="/var/www/$domain/htdocs$subfolder/wp-config.php"
|
||||
sudo sed -i "/stop editing/i \define('WP_ALLOW_MULTISITE', true);" $wpcon
|
||||
|
||||
echo "${blu}"
|
||||
echo "In your WordPress dashboard, go to ${end}“Tools -> Network Setup”${blu},"
|
||||
echo "select the type of WP Multisite installation you want (Subdomain or Subdirectory)"
|
||||
echo "and then press the ${end}“Install”${blu} button at the bottom."
|
||||
echo ""
|
||||
echo "After that, you don't need to add any code lines."
|
||||
echo "We will do it for you!"
|
||||
echo ""
|
||||
echo "${gre}Waiting... we will automatically finish the multisite configuration after you do the install in the WP dashboard!${blu}"
|
||||
echo "Write ${end}'quit'${blu} and press ${end}<Enter>${blu} to exit and abort this operation."
|
||||
echo "${end}"
|
||||
|
||||
while [[ -z $passed || $passed == "false" ]]; do
|
||||
if read -t0; then
|
||||
read pas
|
||||
[[ $pas == "quit" ]] && break
|
||||
fi
|
||||
sleep 2
|
||||
passed=$(is_wp_multisite $domain)
|
||||
done
|
||||
|
||||
if [[ $passed == "false" && $pas == "quit" ]]; then
|
||||
sudo sed -i "/WP_ALLOW_MULTISITE/d" $wpcon
|
||||
echo "${red}[ERROR] Action aborted!${end}"
|
||||
exit 1
|
||||
elif [[ $passed =~ ^(subdomain|subdirectory)$ ]]; then
|
||||
# Multisite wp-config
|
||||
sudo sed -i "/stop editing/i \define('MULTISITE', true);" $wpcon
|
||||
sudo sed -i "/stop editing/i \define('DOMAIN_CURRENT_SITE', '$domain');" $wpcon
|
||||
sudo sed -i "/stop editing/i \define('PATH_CURRENT_SITE', '$subfolder/');" $wpcon
|
||||
sudo sed -i "/stop editing/i \define('SITE_ID_CURRENT_SITE', 1);" $wpcon
|
||||
sudo sed -i "/stop editing/i \define('BLOG_ID_CURRENT_SITE', 1);" $wpcon
|
||||
|
||||
[[ $pas == "quit" ]] && echo "${red}Can not cancel because the installation was already done!${end}"
|
||||
|
||||
if [[ $passed == "subdomain" ]]; then
|
||||
sudo sed -i "/stop editing/i \define('SUBDOMAIN_INSTALL', true);" $wpcon
|
||||
sudo sed -i "/server_name /c \ server_name $domain *.$domain;" /etc/nginx/sites-available/$domain
|
||||
echo "${gre}Subdomain Multisite configuration has been successfully completed!${end}"
|
||||
elif [[ $passed == "subdirectory" ]]; then
|
||||
sudo sed -i "/stop editing/i \define('SUBDOMAIN_INSTALL', false);" $wpcon
|
||||
|
||||
if [[ -z $subfolder ]]; then
|
||||
sudo sed -i '/locations.conf/i \ include common/wpsubdir.conf;' /etc/nginx/sites-available/$domain
|
||||
else
|
||||
sudo cp /etc/nginx/common/wpsubdir.conf /etc/nginx/apps.d/$domain$subname-wpsubdir.conf
|
||||
sudo sed -i "/DO NOT MODIFY/a \include apps.d\/$domain$subname-wpsubdir.conf;" /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo sed -i "/DO NOT MODIFY/a \include apps.d\/$domain$subname-wpsubdir.conf;" /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
sed -i "s#\^(#\^$subfolder\(#" /etc/nginx/apps.d/$domain$subname-wpsubdir.conf
|
||||
sed -i "s#\$2#$subfolder\$2#" /etc/nginx/apps.d/$domain$subname-wpsubdir.conf
|
||||
fi
|
||||
|
||||
echo "${gre}Subdirectory Multisite configuration has been successfully completed!${end}"
|
||||
fi
|
||||
else
|
||||
sudo sed -i "/WP_ALLOW_MULTISITE/d" $wpcon
|
||||
echo "${red}[ERROR] Multisite installation incomplete or not detected!${end}"
|
||||
exit 1
|
||||
fi
|
||||
wp_multisite_convertion
|
||||
|
||||
|
||||
# Parked Domain
|
||||
elif [[ -n $parked && -n $domain ]]; then
|
||||
createsite
|
||||
[[ $parked != true ]] && mapto=$parked || mapto="NeverMatchAtFirstDotCom"
|
||||
|
||||
while [[ ! -a /etc/nginx/sites-available/$mapto ]]
|
||||
do
|
||||
echo "${blu}"
|
||||
read -p "Main site domain: " mapto
|
||||
mapto=${mapto:-NeverMatchAtFirstDotCom}
|
||||
echo "${end}"
|
||||
[[ ! -a /etc/nginx/sites-available/$mapto ]] && echo "${red}Main site domain not found! ${end}"
|
||||
done
|
||||
|
||||
# Nginx conf file for the new parked domain
|
||||
sername=$(grep -w "server_name .*;" /etc/nginx/sites-available/$domain)
|
||||
sudo truncate -s 0 /etc/nginx/sites-available/$domain
|
||||
sudo cat /etc/nginx/sites-available/$mapto > /etc/nginx/sites-available/$domain
|
||||
|
||||
# Prevent if SSL is enabled in main site and ssl data is copied to parked site causing an error.
|
||||
sudo site $domain -ssl=off -revoke=off > /dev/null 2>&1
|
||||
|
||||
sudo sed -i "/server_name/c \ $sername" /etc/nginx/sites-available/$domain
|
||||
sudo sed -i "s/$mapto/$domain/g" /etc/nginx/sites-available/$domain
|
||||
sudo sed -i "/root/c \ root /var/www/$mapto/htdocs;" /etc/nginx/sites-available/$domain
|
||||
cusconl=$( grep -F "include /var/www/$domain/" /etc/nginx/sites-available/$domain | sed "s/$domain/$mapto/" )
|
||||
sed -i "/include \/var\/www\/$domain/c \ ${cusconl}" /etc/nginx/sites-available/$domain
|
||||
|
||||
echo "${gre}"
|
||||
echo "Parked domain was successfully configured! "
|
||||
echo "${end}"
|
||||
parked_domain
|
||||
|
||||
|
||||
# Reverse proxy
|
||||
elif [[ -n $proxy && -n $domain ]]; then
|
||||
if [[ $proxy != true ]]; then
|
||||
firstchar=$(echo "${proxy}" | cut -c-1)
|
||||
lastchar=$(echo "${proxy}" | rev | cut -c-1)
|
||||
proxydata=${proxy:1:-1}
|
||||
|
||||
rpport=$(echo "${proxydata}" | rev | cut -d':' -f 1 -s | rev)
|
||||
if [[ $rpport =~ ^[0-9]+$ && $rpport -ge 0 && $rpport -le 65535 ]]; then
|
||||
rphost=$(echo "${proxydata}" | rev | cut -d':' -f 2- -s | rev)
|
||||
elif [[ $rpport =~ ^[0-9]+$ ]]; then
|
||||
echo "${red}[ERROR] Please, enter a valid port number!${end}"
|
||||
exit 1
|
||||
else
|
||||
rphost=$proxydata
|
||||
rpport=""
|
||||
fi
|
||||
|
||||
|
||||
if ! [[ -n $proxydata && $firstchar == "[" && $lastchar == "]" && -n $rphost ]]; then
|
||||
echo "${red}[ERROR] Please, enter a valid host and port!${end}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Support for custom nginx rules.
|
||||
sudo mkdir -p /var/www/.proxy
|
||||
|
||||
createsite
|
||||
sudo sed -i '/include /d' /etc/nginx/sites-available/$domain
|
||||
sudo sed -i '/root /d' /etc/nginx/sites-available/$domain
|
||||
sudo sed -i '/index /d' /etc/nginx/sites-available/$domain
|
||||
sudo sed -i '/error_log /r /opt/webinoly/templates/template-site-proxy' /etc/nginx/sites-available/$domain
|
||||
sudo sed -i "s/domain.com/$domain/g" /etc/nginx/sites-available/$domain
|
||||
|
||||
echo "${gre}"
|
||||
if [[ $(echo "${rphost}" | cut -d':' -f 1 -s ) =~ ^(http|https)$ ]]; then
|
||||
sudo sed -i "/proxy_set_header Host/d" /etc/nginx/sites-available/$domain
|
||||
sudo sed -i "/proxy_set_header X-/d" /etc/nginx/sites-available/$domain
|
||||
sudo sed -i "/proxy_redirect ws:/d" /etc/nginx/sites-available/$domain
|
||||
sudo sed -i '/proxy_read_timeout/a \ proxy_intercept_errors on;' /etc/nginx/sites-available/$domain
|
||||
sudo sed -i '/proxy_read_timeout/a \ proxy_ignore_headers Set-Cookie;' /etc/nginx/sites-available/$domain
|
||||
|
||||
sudo sed -i "s#http://localhost#$rphost#g" /etc/nginx/sites-available/$domain
|
||||
echo " Custom URL host: ${blu}$rphost${gre}"
|
||||
proxyurl="true"
|
||||
elif [[ -z $rphost ]]; then
|
||||
echo " Default host: ${blu}localhost${gre}"
|
||||
else
|
||||
sudo sed -i "s#localhost#$rphost#g" /etc/nginx/sites-available/$domain
|
||||
echo " Custom host: ${blu}$rphost${gre}"
|
||||
fi
|
||||
|
||||
if [[ -n $rpport ]]; then
|
||||
sudo sed -i "s/8080/$rpport/g" /etc/nginx/sites-available/$domain
|
||||
echo " Custom port: ${blu}$rpport${gre}"
|
||||
elif [[ -z $rpport && $proxyurl == "true" ]]; then
|
||||
sudo sed -i "s/:8080//g" /etc/nginx/sites-available/$domain
|
||||
else
|
||||
echo " Default port: ${blu}8080${gre}"
|
||||
fi
|
||||
|
||||
# Check host and port
|
||||
[[ -z $rphost ]] && rphost="localhost"
|
||||
[[ -z $rpport ]] && rpport="8080"
|
||||
code=$(wget -t 1 --timeout=5 --server-response --spider ${rphost}:${rpport} 2>&1 | awk '/^ HTTP/{print $2}')
|
||||
code="${code##*$'\n'}"
|
||||
echo "${red}"
|
||||
[[ $code != 200 ]] && echo "[WARNING] Seems like your host/port is not responding!"
|
||||
|
||||
echo "${end}"
|
||||
reverse_proxy
|
||||
|
||||
|
||||
# Site disabled
|
||||
elif [[ -n $off && ! -L /etc/nginx/sites-enabled/$domain && -a /etc/nginx/sites-available/$domain ]]; then
|
||||
elif [[ -n $off && ! -L /etc/nginx/sites-enabled/$domain && -f /etc/nginx/sites-available/$domain ]]; then
|
||||
echo "${gre}Seems like your site${blu} $domain ${gre}is already disabled!${end}"
|
||||
elif [[ -n $off && -L /etc/nginx/sites-enabled/$domain ]]; then
|
||||
api-events_update si5
|
||||
|
@ -444,7 +217,7 @@ elif [[ -n $off && -L /etc/nginx/sites-enabled/$domain ]]; then
|
|||
# Site re-enabled
|
||||
elif [[ -n $on && -L /etc/nginx/sites-enabled/$domain ]]; then
|
||||
echo "${gre}Site${blu} $domain ${gre}is already enabled!${end}"
|
||||
elif [[ -n $on && ! -L /etc/nginx/sites-enabled/$domain && -a /etc/nginx/sites-available/$domain ]]; then
|
||||
elif [[ -n $on && ! -L /etc/nginx/sites-enabled/$domain && -f /etc/nginx/sites-available/$domain ]]; then
|
||||
api-events_update si4
|
||||
sudo ln -s /etc/nginx/sites-available/$domain /etc/nginx/sites-enabled/$domain
|
||||
echo "${gre}Site${blu} $domain ${gre}has been successfully enabled!${end}"
|
||||
|
@ -457,13 +230,13 @@ elif [[ -n $redirection && -f /etc/nginx/sites-available/$domain ]]; then
|
|||
|
||||
|
||||
# Delete site
|
||||
elif [[ -n $delete && -a /etc/nginx/sites-available/$domain ]]; then
|
||||
elif [[ -n $delete && -f /etc/nginx/sites-available/$domain ]]; then
|
||||
api-events_update si6
|
||||
if [[ $domain == "default" || $domain == $(conf_read tools-port) ]]; then
|
||||
echo "${red}[ERROR] System sites can not be removed!${end}"
|
||||
exit 1
|
||||
elif [[ -n $subfolder ]]; then
|
||||
if [[ ! -a /var/www/$domain/htdocs$subfolder/wp-config.php ]]; then
|
||||
if [[ ! -f /var/www/$domain/htdocs$subfolder/wp-config.php ]]; then
|
||||
echo "${red}[ERROR] Subfolder not found or is not a WP subsite!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
@ -488,7 +261,7 @@ elif [[ -n $ssl ]]; then
|
|||
if [[ $(is_ssl $domain) == "true" && $ssl != "force-renewal" ]]; then
|
||||
echo "${gre}SSL is already enabled for your site -${blu} $domain ${end}"
|
||||
elif [[ -n $ssl_crt || -n $ssl_key ]]; then
|
||||
if [[ -a $ssl_crt && -a $ssl_key ]]; then
|
||||
if [[ -f $ssl_crt && -f $ssl_key ]]; then
|
||||
ssl_nginx
|
||||
echo "${gre}Your Custom SSL Cert have been successfully enabled on your site -${blu} $domain${end}"
|
||||
else
|
||||
|
@ -535,111 +308,28 @@ elif [[ -n $ssl ]]; then
|
|||
|
||||
# FastCGI Cache
|
||||
elif [[ -n $cache ]]; then
|
||||
if [[ $cache == "off" && -a /etc/nginx/sites-available/$domain ]]; then
|
||||
api-events_update si9
|
||||
if [[ -n $subfolder && $(is_wp_cache $domain $subfolder) == "true" ]]; then
|
||||
sudo sed -i "/$domain$subname-wpfc.conf;/c \ include apps.d/$domain$subname-php.conf;" /etc/nginx/sites-available/$domain
|
||||
echo "${gre}FastCGI Cache in${blu} $domain$subfolder ${gre}has been disabled!${end}"
|
||||
elif [[ $(is_wp_cache $domain) == "true" ]]; then
|
||||
sudo sed -i '/wpfc.conf/c \ include common/php.conf;' /etc/nginx/sites-available/$domain
|
||||
echo "${gre}FastCGI Cache in${blu} $domain ${gre}has been disabled!${end}"
|
||||
else
|
||||
if [[ ( -z $subfolder && $(is_wp $domain) == "false" ) || ( -n $subfolder && $(is_wp $domain $subfolder) == "false" ) ]]; then
|
||||
echo "${red}[ERROR] Site${blu} $domain$subfolder ${red}is not a WP site!${end}"
|
||||
exit 1
|
||||
else
|
||||
echo "${gre}FastCGI Cache is already disabled on your site${blu} $domain${end}"
|
||||
fi
|
||||
fi
|
||||
elif [[ $cache == "on" && -a /etc/nginx/sites-available/$domain ]]; then
|
||||
api-events_update si8
|
||||
if [[ ( -z $subfolder && $(is_php $domain) == "true" && $(is_wp $domain) == "true" ) || ( -n $subfolder && $(is_wp $domain $subfolder) == "true" && $(is_wp_cache $domain $subfolder) == "false" ) ]]; then
|
||||
[[ -z $subfolder ]] && sudo sed -i '/php.conf/c \ include common/wpfc.conf;' /etc/nginx/sites-available/$domain
|
||||
[[ -n $subfolder ]] && sudo sed -i "/$domain$subname-php.conf;/c \ include apps.d/$domain$subname-wpfc.conf;" /etc/nginx/sites-available/$domain
|
||||
if [[ $(is_parked $domain) == "false" && ( ! -d /var/www/$domain/htdocs$subfolder/wp-content/plugins/nginx-helper || ! -d /var/www/$domain/htdocs$subfolder/wp-content/plugins/redis-cache ) ]]; then
|
||||
echo "${gre}"
|
||||
echo "We recommend Nginx Helper Plugin and Redis Object Cache Plugin as an easy way to manage FastCGI and Redis Cache on your WordPress site."
|
||||
echo "${blu}Do you want to install it now [Y/n]? ${end}"
|
||||
while read -r -n 1 -s answer; do
|
||||
answer=${answer:-y}
|
||||
if [[ $answer = [YyNn] ]]; then
|
||||
[[ $answer = [Yy] ]] && wp_cache_plugins
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
echo "${gre}"
|
||||
echo "FastCGI Cache in${blu} $domain$subfolder ${gre}has been successfully enabled! "
|
||||
echo "${end}"
|
||||
else
|
||||
if [[ ( -z $subfolder && $(is_wp $domain) == "false" ) || ( -n $subfolder && $(is_wp $domain $subfolder) == "false" ) ]]; then
|
||||
echo "${red}[ERROR] Site${blu} $domain$subfolder ${red}is not a WP site!${end}"
|
||||
exit 1
|
||||
else
|
||||
echo "${gre}FastCGI Cache is already enabled on your site${blu} $domain$subfolder${end}"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "${red}[ERROR] Invalid value for cache! ${end}"
|
||||
exit 1
|
||||
fi
|
||||
wp_cache
|
||||
|
||||
|
||||
# Force www or non-www redirect (www, root, off)
|
||||
elif [[ -n $force_redirect && -a /etc/nginx/sites-available/$domain ]]; then
|
||||
elif [[ -n $force_redirect && -f /etc/nginx/sites-available/$domain ]]; then
|
||||
force_redirect
|
||||
|
||||
|
||||
# Yoast Sitemap support, per site.
|
||||
elif [[ -n $yoast_sitemap && -a /etc/nginx/sites-available/$domain ]]; then
|
||||
if [[ ( -z $subfolder && $(is_wp $domain) == "false" ) || ( -n $subfolder && $(is_wp $domain $subfolder) == "false" ) ]]; then
|
||||
echo "${red}[ERROR] Site${blu} $domain$subfolder ${red}is not a WP site!${end}"
|
||||
exit 1
|
||||
elif [[ -n $subfolder && $(is_wp $domain $subfolder) == "true" ]]; then
|
||||
ystmap=$( grep -F "yoast-sitemap.conf;" /etc/nginx/apps.d/$domain$subname-php.conf )
|
||||
else
|
||||
ystmap=$( grep -F "yoast-sitemap.conf;" /etc/nginx/sites-available/$domain )
|
||||
fi
|
||||
|
||||
if [[ $yoast_sitemap == "on" ]]; then
|
||||
if [[ -z $ystmap ]]; then
|
||||
if [[ -z $subfolder ]]; then
|
||||
sudo sed -i "/# WebinolyCustom$/a \ include common/yoast-sitemap.conf;" /etc/nginx/sites-available/$domain
|
||||
else
|
||||
sudo sed -i "/\/index.php?q/a \ include apps.d\/$domain$subname-yoast-sitemap.conf;" /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo sed -i "/\/index.php?q/a \ include apps.d\/$domain$subname-yoast-sitemap.conf;" /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
fi
|
||||
echo "${gre}Yoast Sitemap Support was successfully enabled!${end}"
|
||||
else
|
||||
echo "${gre}Yoast Sitemap Support is already enabled!${end}"
|
||||
fi
|
||||
elif [[ $yoast_sitemap == "off" ]]; then
|
||||
if [[ -n $ystmap ]]; then
|
||||
if [[ -z $subfolder ]]; then
|
||||
sudo sed -i "/yoast-sitemap.conf;/d" /etc/nginx/sites-available/$domain
|
||||
else
|
||||
sudo sed -i "/yoast-sitemap.conf;/d" /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo sed -i "/yoast-sitemap.conf;/d" /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
fi
|
||||
echo "${gre}Yoast Sitemap Support was successfully disabled!${end}"
|
||||
else
|
||||
echo "${gre}Yoast Sitemap Support is already disabled!${end}"
|
||||
fi
|
||||
else
|
||||
echo "${red}[ERROR] Please, enter a valid option to enable/disable Yoast Sitemap Support!${end}"
|
||||
exit 1
|
||||
fi
|
||||
elif [[ -n $yoast_sitemap && -f /etc/nginx/sites-available/$domain ]]; then
|
||||
yoast_sitemap
|
||||
|
||||
|
||||
# Staging and Clone sites
|
||||
elif [[ -n $clone_from ]]; then
|
||||
if [[ ! -a /etc/nginx/sites-available/$clone_from ]]; then
|
||||
if [[ ! -f /etc/nginx/sites-available/$clone_from ]]; then
|
||||
echo "${red}[ERROR] Site/domain ${blu}'$clone_from'${red} not found!${end}"
|
||||
exit 1
|
||||
elif [[ -a /etc/nginx/sites-available/$domain && -z $subfolder ]]; then
|
||||
elif [[ -f /etc/nginx/sites-available/$domain && -z $subfolder ]]; then
|
||||
echo "${red}[ERROR] Can not create site${blu} $domain ${red}because already exists!${end}"
|
||||
exit 1
|
||||
elif [[ -a /etc/nginx/sites-available/$domain && -n $subfolder && -d /var/www/$domain/htdocs$subfolder ]]; then
|
||||
elif [[ -f /etc/nginx/sites-available/$domain && -n $subfolder && -d /var/www/$domain/htdocs$subfolder ]]; then
|
||||
echo "${red}[ERROR] Subfolder ${blu}'$subfolder'${red} already exists!${end}"
|
||||
exit 1
|
||||
elif [[ $(is_wp $clone_from $subfolder) != "true" ]]; then
|
||||
|
@ -649,144 +339,29 @@ elif [[ -n $clone_from ]]; then
|
|||
# Nginx fails due to duplicate default-server directives
|
||||
echo "${red}[ERROR] Cloning a site that is set as default-site is not allowed!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n $subfolder ]]; then
|
||||
wpcon="/var/www/$domain/htdocs$subfolder/wp-config.php"
|
||||
arg=" -subfolder=$subfolder"
|
||||
|
||||
sudo cp /etc/nginx/apps.d/$clone_from$subname-php.conf /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo cp /etc/nginx/apps.d/$clone_from$subname-wpfc.conf /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
sudo cp /etc/nginx/apps.d/$clone_from$subname-wpcommon.conf /etc/nginx/apps.d/$domain$subname-wpcommon.conf
|
||||
sudo cp /etc/nginx/apps.d/$clone_from$subname-wpcommon-noauth.conf /etc/nginx/apps.d/$domain$subname-wpcommon-noauth.conf
|
||||
sudo cp /etc/nginx/apps.d/$clone_from$subname-locations.conf /etc/nginx/apps.d/$domain$subname-locations.conf
|
||||
sudo cp /etc/nginx/apps.d/$clone_from$subname-yoast-sitemap.conf /etc/nginx/apps.d/$domain$subname-yoast-sitemap.conf
|
||||
|
||||
sudo sed -i "s/$clone_from/$domain/g" /etc/nginx/apps.d/$domain$subname-php.conf
|
||||
sudo sed -i "s/$clone_from/$domain/g" /etc/nginx/apps.d/$domain$subname-wpfc.conf
|
||||
|
||||
dest=$( echo $subfolder | rev | cut -f 2- -d "/" -s | rev )
|
||||
sudo mkdir -p /var/www/$domain/htdocs$dest
|
||||
sudo cp -r /var/www/$clone_from/htdocs$subfolder /var/www/$domain/htdocs$dest
|
||||
else
|
||||
arg=""
|
||||
wpcon="/var/www/$domain/wp-config.php"
|
||||
sudo cp -r /var/www/$clone_from /var/www/$domain
|
||||
clone_wp_site
|
||||
fi
|
||||
|
||||
if [[ -a /etc/nginx/sites-available/$domain ]]; then
|
||||
sudo sed -i "/# WebinolyCustom$/a \ include apps.d/$domain$subname-php.conf;" /etc/nginx/sites-available/$domain
|
||||
else
|
||||
sudo cp /etc/nginx/sites-available/$clone_from /etc/nginx/sites-available/$domain
|
||||
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
|
||||
fi
|
||||
|
||||
[[ $(is_ssl $clone_from) == "true" ]] && site $domain -ssl=off -revoke=off > /dev/null 2>&1
|
||||
dom=$(echo $domain$subfolder | sed "s/[^0-9A-Za-z]/_/g")
|
||||
AUTOGENPASS_WPDB=`pwgen -s -1 16`
|
||||
wp_dbdata $clone_from
|
||||
|
||||
if [[ $wp_dbhost == "localhost" ]]; then
|
||||
ROOT_PASS=$( echo $(conf_read mysql-root) | openssl enc -d -a -salt )
|
||||
site -mysql=[localhost,$dom,$dom,$AUTOGENPASS_WPDB] > /dev/null 2>&1
|
||||
mysqldump -u root -p$ROOT_PASS $wp_dbname | mysql -u root -p$ROOT_PASS $dom
|
||||
# Starting with MySQL 8 you no longer can (implicitly) create a user using the GRANT command.
|
||||
sudo mysql --connect-timeout=10 --user=root -p$ROOT_PASS <<_EOF_
|
||||
USE $dom;
|
||||
UPDATE ${wp_dbpref}options SET option_value='http://${domain}${subfolder}' WHERE option_name='home';
|
||||
UPDATE ${wp_dbpref}options SET option_value='http://${domain}${subfolder}' WHERE option_name='siteurl';
|
||||
FLUSH PRIVILEGES;
|
||||
_EOF_
|
||||
else
|
||||
echo "${red}[ERROR] Database host is not localhost!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sudo sed -i "/DB_NAME/c \define('DB_NAME', '$dom');" $wpcon
|
||||
sudo sed -i "/DB_USER/c \define('DB_USER', '$dom');" $wpcon
|
||||
sudo sed -i "/DB_PASSWORD/c \define('DB_PASSWORD', '$AUTOGENPASS_WPDB');" $wpcon
|
||||
|
||||
if [[ $replace_content != "off" ]]; then
|
||||
sudo site $domain -replace-content=[http://$clone_from,http://$domain]$arg > /dev/null 2>&1
|
||||
sudo site $domain -replace-content=[https://$clone_from,http://$domain]$arg > /dev/null 2>&1
|
||||
sudo site $domain -replace-content=[$clone_from,$domain]$arg > /dev/null 2>&1
|
||||
fi
|
||||
echo "${gre}Site ${blu}'$domain$subfolder'${gre} is now a successful clone of ${blu}'$clone_from$subfolder'${end}"
|
||||
|
||||
|
||||
# Replace Content
|
||||
elif [[ -n $replace_content && -a /etc/nginx/sites-available/$domain ]]; then
|
||||
elif [[ -n $replace_content && -f /etc/nginx/sites-available/$domain ]]; then
|
||||
if [[ $(is_wp $domain $subfolder) != "true" ]]; then
|
||||
echo "${red}[ERROR] Site${blu} $domain ${red}is not a WordPress site!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $replace_content == true ]]; then
|
||||
echo ""
|
||||
read -p "${blu}Search: ${end}" search
|
||||
read -p "${blu}Replace with: ${end}" replace
|
||||
echo ""
|
||||
elif [[ $(echo "${replace_content}" | cut -c-1) == "[" && $(echo "${replace_content}" | rev | cut -c-1) == "]" ]]; then
|
||||
userdata=${replace_content:1:-1}
|
||||
search=$(echo "${userdata}" | cut -d',' -f 1 -s)
|
||||
replace=$(echo "${userdata}" | cut -d',' -f 2 -s)
|
||||
fi
|
||||
|
||||
if [[ -z $search || -z $replace ]]; then
|
||||
echo "${red}[ERROR] Please, enter a valid value for search and replace!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
wp_dbdata $domain
|
||||
query="USE $wp_dbname; UPDATE ${wp_dbpref}posts SET post_content = REPLACE (post_content,'$search','$replace'); FLUSH PRIVILEGES;"
|
||||
|
||||
if [[ $wp_dbhost == "localhost" ]]; then
|
||||
ROOT_PASS=$( echo $(conf_read mysql-root) | openssl enc -d -a -salt )
|
||||
sudo mysql --connect-timeout=10 --user=root -p$ROOT_PASS -e "$query"
|
||||
elif [[ -n $wp_dbhost ]]; then
|
||||
sudo mysql --connect-timeout=10 -h "$wp_dburl" -P "$wp_dbport" -u"$wp_uroot" -p"$wp_proot" -e "$query"
|
||||
else
|
||||
echo "${red}[ERROR] Invalid WP database host!${end}"
|
||||
exit 1
|
||||
wp_replace_content
|
||||
fi
|
||||
echo "${gre}Content successfully replaced in your WP site!${end}"
|
||||
|
||||
|
||||
# List Sites
|
||||
elif [[ -n $list && -z $redirection ]]; then
|
||||
echo ""
|
||||
for site in "/etc/nginx/sites-available"/*
|
||||
do
|
||||
domi=$(echo $site | cut -f 5 -d "/")
|
||||
if [[ $domi != "default" && $domi != $(conf_read tools-port) ]]; then
|
||||
[[ -a /var/www/$domi ]] && sign="${gre} +" || sign="${blu} *${gre}"
|
||||
[[ ! -L /etc/nginx/sites-enabled/$domi ]] && sign="${red} -"
|
||||
outlist="$sign $domi ${end}"
|
||||
|
||||
if [[ $list == "raw" || $raw =~ ^(all|parked|disabled|main|true)$ ]]; then
|
||||
outlist="$domi"
|
||||
[[ $raw == "parked" && -a /var/www/$domi ]] && outlist=""
|
||||
[[ $raw == "disabled" && -L /etc/nginx/sites-enabled/$domi ]] && outlist=""
|
||||
[[ $raw == "main" && ( ! -L /etc/nginx/sites-enabled/$domi || ! -a /var/www/$domi ) ]] && outlist=""
|
||||
elif [[ -n $raw ]]; then
|
||||
echo "${red}[ERROR] Please, enter a valid value for RAW!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n $outlist ]]; then
|
||||
echo "$outlist"
|
||||
nonemptylist=true
|
||||
fi
|
||||
fi
|
||||
done
|
||||
[[ -z $nonemptylist && -z $raw && $list != "raw" ]] && echo "${blu}[Empty] No sites were found!${end}"
|
||||
echo ""
|
||||
list_sites
|
||||
nginx_not="true" # Nginx-Reload not-needed.
|
||||
|
||||
|
||||
# Catch ERROR
|
||||
elif [[ -n $domain && ! -a /etc/nginx/sites-available/$domain ]]; then
|
||||
elif [[ -n $domain && ! -f /etc/nginx/sites-available/$domain ]]; then
|
||||
echo "${red}[ERROR] Site${blu} $domain ${red}doesn't exists, please enter a valid domain name!${end}"
|
||||
exit 1
|
||||
else
|
||||
|
|
457
plugins/stack
457
plugins/stack
|
@ -5,7 +5,7 @@
|
|||
# Options: -html, -nginx, -php, -lemp, -mysql, -pma, -info, -purge-server-all, -php-ver
|
||||
# Arguments: -purge, -notools
|
||||
|
||||
source /opt/webinoly/lib/webin
|
||||
source /opt/webinoly/lib/install
|
||||
check_for_parameters $@
|
||||
api-events_update sts
|
||||
|
||||
|
@ -25,262 +25,260 @@ if [[ -n $purge && ( -n $html || -n $nginx ) ]]; then
|
|||
if [[ $(conf_read nginx) != "true" ]]; then
|
||||
echo "${gre}Nginx is not installed, hence can not be deleted! ${end}"
|
||||
clear_force_flag
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "${red}¡ C A U T I O N ! You are about to remove NGINX from your server!"
|
||||
[[ $(conf_read mysql-tool) == "true" ]] && echo "phpMyAdmin will be removed too because depends on Nginx."
|
||||
echo ""
|
||||
|
||||
if [[ $(conf_read force-flag) != "true" ]]; then
|
||||
echo " ${blu}Are you sure [y/N]? ${end}"
|
||||
while read -r -n 1 -s answer; do
|
||||
answer=${answer:-n}
|
||||
[[ $answer = [YyNn] ]] && break
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ $answer == [Yy] || $(conf_read force-flag) == "true" ]]; then
|
||||
if [[ $(conf_read force-flag) == "true" && $force == 1 ]]; then
|
||||
answer="Y"
|
||||
else
|
||||
echo ""
|
||||
echo "${blu}Do you want to delete your sites data directory (/var/www) [Y/n]? ${end}"
|
||||
else
|
||||
echo ""
|
||||
echo "${red}¡ C A U T I O N ! You are about to remove NGINX from your server!"
|
||||
[[ $(conf_read mysql-tool) == "true" ]] && echo "phpMyAdmin will be removed too because depends on Nginx."
|
||||
echo ""
|
||||
|
||||
if [[ $(conf_read force-flag) != "true" ]]; then
|
||||
echo " ${blu}Are you sure [y/N]? ${end}"
|
||||
while read -r -n 1 -s answer; do
|
||||
answer=${answer:-y}
|
||||
answer=${answer:-n}
|
||||
[[ $answer = [YyNn] ]] && break
|
||||
done
|
||||
fi
|
||||
if [[ $answer == [Yy] ]]; then
|
||||
[[ $(conf_read mysql-tool) == "true" ]] && stack -pma -purge=force
|
||||
api-events_update pn2
|
||||
site -delete-all=force
|
||||
sudo rm -rf /var/www/$(conf_read tools-port)
|
||||
sudo rm -rf /var/www/html
|
||||
api-events_update pn3
|
||||
|
||||
if [[ $answer == [Yy] || $(conf_read force-flag) == "true" ]]; then
|
||||
if [[ $(conf_read force-flag) == "true" && $force == 1 ]]; then
|
||||
answer="Y"
|
||||
else
|
||||
echo ""
|
||||
echo "${blu}Do you want to delete your sites data directory (/var/www) [Y/n]? ${end}"
|
||||
while read -r -n 1 -s answer; do
|
||||
answer=${answer:-y}
|
||||
[[ $answer = [YyNn] ]] && break
|
||||
done
|
||||
fi
|
||||
if [[ $answer == [Yy] ]]; then
|
||||
[[ $(conf_read mysql-tool) == "true" ]] && stack -pma -purge=force
|
||||
api-events_update pn2
|
||||
site -delete-all=force
|
||||
sudo rm -rf /var/www/$(conf_read tools-port)
|
||||
sudo rm -rf /var/www/html
|
||||
api-events_update pn3
|
||||
fi
|
||||
|
||||
sudo service nginx stop
|
||||
sudo apt -y purge nginx nginx-common
|
||||
[[ $(conf_read nginx-ppa) == "mainline" ]] && echo | sudo add-apt-repository --remove 'ppa:nginx/development' || echo | sudo add-apt-repository --remove 'ppa:nginx/stable'
|
||||
api-events_update pn4
|
||||
api-events_update pn5
|
||||
sudo apt -y purge certbot python-boto duplicity duply
|
||||
echo | sudo add-apt-repository --remove 'ppa:certbot/certbot'
|
||||
# Remove SSL Cron
|
||||
if [[ -f /var/spool/cron/crontabs/root ]]; then
|
||||
sudo sed -i '/MAILTO=/d' /var/spool/cron/crontabs/root
|
||||
sudo sed -i '/certbot renew/d' /var/spool/cron/crontabs/root
|
||||
fi
|
||||
sudo apt -y autoremove
|
||||
sudo rm $HOME/www
|
||||
sudo rm $HOME/sites-available
|
||||
|
||||
# Remove sources
|
||||
sudo rm -rf /opt/webinoly/templates/source/default
|
||||
|
||||
api-events_update pn6
|
||||
linux_purge
|
||||
|
||||
conf_write nginx purged
|
||||
conf_write nginx-optim purged
|
||||
conf_write nginx-tool purged
|
||||
conf_delete server-version
|
||||
echo ""
|
||||
echo "${gre}Nginx has been deleted successfully! ${end}"
|
||||
echo ""
|
||||
else
|
||||
echo ""
|
||||
echo " ${gre}Action aborted!!! ${end}"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
sudo service nginx stop
|
||||
sudo apt -y purge nginx nginx-common
|
||||
[[ $(conf_read nginx-ppa) == "mainline" ]] && echo | sudo add-apt-repository --remove 'ppa:nginx/development' || echo | sudo add-apt-repository --remove 'ppa:nginx/stable'
|
||||
api-events_update pn4
|
||||
api-events_update pn5
|
||||
sudo apt -y purge certbot python-boto duplicity duply
|
||||
echo | sudo add-apt-repository --remove 'ppa:certbot/certbot'
|
||||
# Remove SSL Cron
|
||||
if [[ -a /var/spool/cron/crontabs/root ]]; then
|
||||
sudo sed -i '/MAILTO=/d' /var/spool/cron/crontabs/root
|
||||
sudo sed -i '/certbot renew/d' /var/spool/cron/crontabs/root
|
||||
fi
|
||||
sudo apt -y autoremove
|
||||
sudo rm $HOME/www
|
||||
sudo rm $HOME/sites-available
|
||||
|
||||
# Remove sources
|
||||
sudo rm -rf /opt/webinoly/templates/source/default
|
||||
|
||||
api-events_update pn6
|
||||
linux_purge
|
||||
|
||||
conf_write nginx purged
|
||||
conf_write nginx-optim purged
|
||||
conf_write nginx-tool purged
|
||||
conf_delete server-version
|
||||
echo ""
|
||||
echo "${gre}Nginx has been deleted successfully! ${end}"
|
||||
echo ""
|
||||
else
|
||||
echo ""
|
||||
echo " ${gre}Action aborted!!! ${end}"
|
||||
echo ""
|
||||
fi
|
||||
echo ""
|
||||
|
||||
elif [[ -n $purge && -n $php ]]; then
|
||||
api-events_update pp1
|
||||
if [[ $(conf_read php) != "true" ]]; then
|
||||
echo "${gre}PHP is not installed, hence can not be deleted! ${end}"
|
||||
clear_force_flag
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "${red}¡ C A U T I O N ! You are about to remove PHP from your server!"
|
||||
echo "This action will also remove PhpMyAdmin if its installed because depends on PHP. ${end}"
|
||||
echo ""
|
||||
|
||||
if [[ $(conf_read force-flag) != "true" ]]; then
|
||||
echo " ${blu}Are you sure [y/N]? ${end}"
|
||||
while read -r -n 1 -s answer; do
|
||||
answer=${answer:-n}
|
||||
[[ $answer = [YyNn] ]] && break
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ $answer == [Yy] || $(conf_read force-flag) == "true" ]]; then
|
||||
[[ $(conf_read mysql-tool) == "true" ]] && stack -pma -purge=force
|
||||
sudo service php*-fpm stop
|
||||
sudo apt -y purge php*-fpm php*-curl php*-gd php*-imap php*-mcrypt php*-readline php*-common php*-recode php*-mysql php*-cli php*-mbstring php*-bcmath php*-mysql php*-opcache php*-zip php*-xml php*-soap php-imagick graphviz php-pear php-msgpack
|
||||
sudo apt -y purge php-memcached php-memcache memcached
|
||||
sudo apt -y purge redis-server php-redis postfix
|
||||
echo | sudo add-apt-repository --remove 'ppa:ondrej/php'
|
||||
echo | sudo add-apt-repository --remove 'ppa:chris-lea/redis-server'
|
||||
sudo apt -y autoremove
|
||||
sudo rm -rf /etc/php
|
||||
sudo rm /opt/webinoly/templates/source/*
|
||||
|
||||
# Remove sources
|
||||
sudo rm -rf /opt/webinoly/templates/source/php.ini
|
||||
sudo rm -rf /opt/webinoly/templates/source/www.conf
|
||||
sudo rm -rf /opt/webinoly/templates/source/main.cf
|
||||
|
||||
# Remove tools-site
|
||||
sudo rm -rf /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo rm -rf /etc/nginx/sites-enabled/$(conf_read tools-port)
|
||||
sudo rm -rf /var/www/$(conf_read tools-port)
|
||||
conf_delete tools-site
|
||||
|
||||
conf_write php purged
|
||||
conf_write php-optim purged
|
||||
[[ $(conf_read php-v7.4) == "true" ]] && conf_write php-v7.4 purged
|
||||
[[ $(conf_read php-v7.3) == "true" ]] && conf_write php-v7.3 purged
|
||||
[[ $(conf_read php-v7.2) == "true" ]] && conf_write php-v7.2 purged
|
||||
# We need it to support and update old deprecated stacks.
|
||||
[[ $(conf_read php-v7.1) == "true" ]] && conf_write php-v7.1 purged
|
||||
[[ $(conf_read php-v7.0) == "true" ]] && conf_write php-v7.0 purged
|
||||
[[ $(conf_read php-v5.6) == "true" ]] && conf_write php-v5.6 purged
|
||||
|
||||
if [[ $(conf_read php-tool) == "true" ]]; then
|
||||
rm -rf /var/www/$(conf_read tools-port)/htdocs/fpm
|
||||
rm -rf /var/www/$(conf_read tools-port)/htdocs/php
|
||||
conf_write php-tool purged
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "${gre}PHP has been deleted successfully! ${end}"
|
||||
echo ""
|
||||
else
|
||||
echo ""
|
||||
echo " ${gre}Action aborted!!! ${end}"
|
||||
echo "${red}¡ C A U T I O N ! You are about to remove PHP from your server!"
|
||||
echo "This action will also remove phpMyAdmin if its installed because depends on PHP. ${end}"
|
||||
echo ""
|
||||
fi
|
||||
echo ""
|
||||
api-events_update pp2
|
||||
|
||||
if [[ $(conf_read force-flag) != "true" ]]; then
|
||||
echo " ${blu}Are you sure [y/N]? ${end}"
|
||||
while read -r -n 1 -s answer; do
|
||||
answer=${answer:-n}
|
||||
[[ $answer = [YyNn] ]] && break
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ $answer == [Yy] || $(conf_read force-flag) == "true" ]]; then
|
||||
[[ $(conf_read mysql-tool) == "true" ]] && stack -pma -purge=force
|
||||
sudo service php*-fpm stop
|
||||
sudo apt -y purge php*-fpm php*-curl php*-gd php*-imap php*-mcrypt php*-readline php*-common php*-recode php*-mysql php*-cli php*-mbstring php*-bcmath php*-mysql php*-opcache php*-zip php*-xml php*-soap php-imagick graphviz php-pear php-msgpack
|
||||
sudo apt -y purge php-memcached php-memcache memcached
|
||||
sudo apt -y purge redis-server php-redis postfix
|
||||
echo | sudo add-apt-repository --remove 'ppa:ondrej/php'
|
||||
echo | sudo add-apt-repository --remove 'ppa:chris-lea/redis-server'
|
||||
sudo apt -y autoremove
|
||||
sudo rm -rf /etc/php
|
||||
sudo rm /opt/webinoly/templates/source/*
|
||||
|
||||
# Remove sources
|
||||
sudo rm -rf /opt/webinoly/templates/source/php.ini
|
||||
sudo rm -rf /opt/webinoly/templates/source/www.conf
|
||||
sudo rm -rf /opt/webinoly/templates/source/main.cf
|
||||
|
||||
# Remove tools-site
|
||||
sudo rm -rf /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo rm -rf /etc/nginx/sites-enabled/$(conf_read tools-port)
|
||||
sudo rm -rf /var/www/$(conf_read tools-port)
|
||||
conf_delete tools-site
|
||||
|
||||
conf_write php purged
|
||||
conf_write php-optim purged
|
||||
[[ $(conf_read php-v7.4) == "true" ]] && conf_write php-v7.4 purged
|
||||
[[ $(conf_read php-v7.3) == "true" ]] && conf_write php-v7.3 purged
|
||||
[[ $(conf_read php-v7.2) == "true" ]] && conf_write php-v7.2 purged
|
||||
# We need it to support and update old deprecated stacks.
|
||||
[[ $(conf_read php-v7.1) == "true" ]] && conf_write php-v7.1 purged
|
||||
[[ $(conf_read php-v7.0) == "true" ]] && conf_write php-v7.0 purged
|
||||
[[ $(conf_read php-v5.6) == "true" ]] && conf_write php-v5.6 purged
|
||||
|
||||
if [[ $(conf_read php-tool) == "true" ]]; then
|
||||
rm -rf /var/www/$(conf_read tools-port)/htdocs/fpm
|
||||
rm -rf /var/www/$(conf_read tools-port)/htdocs/php
|
||||
conf_write php-tool purged
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "${gre}PHP has been deleted successfully! ${end}"
|
||||
echo ""
|
||||
else
|
||||
echo ""
|
||||
echo " ${gre}Action aborted!!! ${end}"
|
||||
echo ""
|
||||
fi
|
||||
echo ""
|
||||
api-events_update pp2
|
||||
fi
|
||||
|
||||
|
||||
elif [[ -n $purge && -n $mysql ]]; then
|
||||
api-events_update pm1
|
||||
if [[ $(conf_read mysql) != "true" ]]; then
|
||||
echo "${gre}MySQL is not installed, hence can not be deleted! ${end}"
|
||||
clear_force_flag
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "${red}¡ C A U T I O N ! You are about to remove MySQL from your server! ${end}"
|
||||
echo ""
|
||||
|
||||
if [[ $(conf_read force-flag) != "true" ]]; then
|
||||
echo " ${blu}Are you sure [y/N]? ${end}"
|
||||
while read -r -n 1 -s answer; do
|
||||
answer=${answer:-n}
|
||||
[[ $answer = [YyNn] ]] && break
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ $answer == [Yy] || $(conf_read force-flag) == "true" ]]; then
|
||||
if [[ $(conf_read mysql-tool) == "true" ]]; then
|
||||
conf_write delautopma true
|
||||
stack -pma -purge
|
||||
conf_delete delautopma
|
||||
fi
|
||||
|
||||
# Determine MySQL version according to stack version.
|
||||
mysqlver=$(sudo mysql -V | cut -f 6 -d " " -s | cut -f -2 -d "." -s)
|
||||
sudo service mysql stop
|
||||
|
||||
if [[ $mysql == "keep-data" ]]; then
|
||||
echo "mariadb-server-${mysqlver} mariadb-server-${mysqlver}/postrm_remove_databases boolean false" | debconf-set-selections
|
||||
else
|
||||
echo "mariadb-server-${mysqlver} mariadb-server-${mysqlver}/postrm_remove_databases boolean true" | debconf-set-selections
|
||||
fi
|
||||
sudo apt -y purge mariadb-server mariadb-common mysql-common
|
||||
sudo apt -y purge mariadb-client
|
||||
sudo apt -y purge debconf-utils
|
||||
sudo apt -y autoremove
|
||||
|
||||
# Cases with MariaDB v10.4 support
|
||||
os_name=$(check_osname)
|
||||
sudo add-apt-repository --remove "http://mirrors.syringanetworks.net/mariadb/repo/${mysqlver}/ubuntu"
|
||||
case "$osname" in
|
||||
"trusty")
|
||||
sudo apt-key del 0xcbcb082a1bb943db
|
||||
;;
|
||||
"xenial"|"bionic"|"cosmic"|"disco")
|
||||
sudo apt-key del 0xF1656F24C74CD1D8
|
||||
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ $mysql != "keep-data" ]]; then
|
||||
sudo rm -rf /etc/mysql
|
||||
sudo rm -rf /var/lib/mysql
|
||||
conf_delete mysql-root
|
||||
conf_delete mysql-admin
|
||||
else
|
||||
echo "${blu}MySQL data was not removed.${end}"
|
||||
fi
|
||||
|
||||
conf_write mysql-client purged
|
||||
conf_write mysql purged
|
||||
echo ""
|
||||
echo "${gre}MySQL has been deleted successfully! ${end}"
|
||||
echo ""
|
||||
else
|
||||
echo ""
|
||||
echo " ${gre}Action aborted!!! ${end}"
|
||||
echo "${red}¡ C A U T I O N ! You are about to remove MySQL from your server! ${end}"
|
||||
echo ""
|
||||
|
||||
if [[ $(conf_read force-flag) != "true" ]]; then
|
||||
echo " ${blu}Are you sure [y/N]? ${end}"
|
||||
while read -r -n 1 -s answer; do
|
||||
answer=${answer:-n}
|
||||
[[ $answer = [YyNn] ]] && break
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ $answer == [Yy] || $(conf_read force-flag) == "true" ]]; then
|
||||
if [[ $(conf_read mysql-tool) == "true" ]]; then
|
||||
conf_write delautopma true
|
||||
stack -pma -purge
|
||||
conf_delete delautopma
|
||||
fi
|
||||
|
||||
# Determine MySQL version according to stack version.
|
||||
mysqlver=$(sudo mysql -V | cut -f 6 -d " " -s | cut -f -2 -d "." -s)
|
||||
sudo service mysql stop
|
||||
|
||||
if [[ $mysql == "keep-data" ]]; then
|
||||
echo "mariadb-server-${mysqlver} mariadb-server-${mysqlver}/postrm_remove_databases boolean false" | debconf-set-selections
|
||||
else
|
||||
echo "mariadb-server-${mysqlver} mariadb-server-${mysqlver}/postrm_remove_databases boolean true" | debconf-set-selections
|
||||
fi
|
||||
sudo apt -y purge mariadb-server mariadb-common mysql-common
|
||||
sudo apt -y purge mariadb-client
|
||||
sudo apt -y purge debconf-utils
|
||||
sudo apt -y autoremove
|
||||
|
||||
# Cases with MariaDB v10.4 support
|
||||
os_name=$(check_osname)
|
||||
sudo add-apt-repository --remove "http://mirrors.syringanetworks.net/mariadb/repo/${mysqlver}/ubuntu"
|
||||
case "$osname" in
|
||||
"trusty")
|
||||
sudo apt-key del 0xcbcb082a1bb943db
|
||||
;;
|
||||
"xenial"|"bionic"|"cosmic"|"disco")
|
||||
sudo apt-key del 0xF1656F24C74CD1D8
|
||||
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ $mysql != "keep-data" ]]; then
|
||||
sudo rm -rf /etc/mysql
|
||||
sudo rm -rf /var/lib/mysql
|
||||
conf_delete mysql-root
|
||||
conf_delete mysql-admin
|
||||
else
|
||||
echo "${blu}MySQL data was not removed.${end}"
|
||||
fi
|
||||
|
||||
conf_write mysql-client purged
|
||||
conf_write mysql purged
|
||||
echo ""
|
||||
echo "${gre}MySQL has been deleted successfully! ${end}"
|
||||
echo ""
|
||||
else
|
||||
echo ""
|
||||
echo " ${gre}Action aborted!!! ${end}"
|
||||
echo ""
|
||||
fi
|
||||
echo ""
|
||||
api-events_update pm4
|
||||
fi
|
||||
echo ""
|
||||
api-events_update pm4
|
||||
|
||||
|
||||
elif [[ -n $purge && -n $pma ]]; then
|
||||
api-events_update pm2
|
||||
if [[ $(conf_read mysql-tool) != "true" ]]; then
|
||||
echo "${gre}PhpMyAdmin is not installed, hence can not be deleted! ${end}"
|
||||
echo "${gre}phpMyAdmin is not installed, hence can not be deleted! ${end}"
|
||||
clear_force_flag
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "${red}¡ C A U T I O N ! You are about to remove PhpMyAdmin from your server! ${end}"
|
||||
echo ""
|
||||
|
||||
if [[ $(conf_read force-flag) != "true" && $(conf_read delautopma) != "true" ]]; then
|
||||
echo " ${blu}Are you sure [y/N]? ${end} "
|
||||
while read -r -n 1 -s answer; do
|
||||
answer=${answer:-n}
|
||||
if [[ $answer = [YyNn] ]]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ $answer == [Yy] || $(conf_read force-flag) == "true" || $(conf_read delautopma) == "true" ]]; then
|
||||
sudo rm -rf /var/www/$(conf_read tools-port)/htdocs/pma
|
||||
conf_write mysql-tool purged
|
||||
echo ""
|
||||
echo "${gre}PhpMyAdmin has been deleted successfully! ${end}"
|
||||
echo ""
|
||||
else
|
||||
echo ""
|
||||
echo " ${gre}Action aborted!!! ${end}"
|
||||
echo "${red}¡ C A U T I O N ! You are about to remove phpMyAdmin from your server! ${end}"
|
||||
echo ""
|
||||
|
||||
if [[ $(conf_read force-flag) != "true" && $(conf_read delautopma) != "true" ]]; then
|
||||
echo " ${blu}Are you sure [y/N]? ${end} "
|
||||
while read -r -n 1 -s answer; do
|
||||
answer=${answer:-n}
|
||||
if [[ $answer = [YyNn] ]]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ $answer == [Yy] || $(conf_read force-flag) == "true" || $(conf_read delautopma) == "true" ]]; then
|
||||
sudo rm -rf /var/www/$(conf_read tools-port)/htdocs/pma
|
||||
conf_write mysql-tool purged
|
||||
echo ""
|
||||
echo "${gre}phpMyAdmin has been deleted successfully! ${end}"
|
||||
echo ""
|
||||
else
|
||||
echo ""
|
||||
echo " ${gre}Action aborted!!! ${end}"
|
||||
echo ""
|
||||
fi
|
||||
echo ""
|
||||
api-events_update pm3
|
||||
fi
|
||||
echo ""
|
||||
api-events_update pm3
|
||||
|
||||
|
||||
|
||||
elif [[ -n $purge && -n $lemp ]]; then
|
||||
echo "${red}If you want to remove Webinoly Stack completely from your server use the '-purge-server-all' option or remove each package individually. ${end}"
|
||||
exit 1
|
||||
|
@ -357,7 +355,7 @@ elif [[ -n $php ]]; then
|
|||
elif [[ -n $mysql ]]; then
|
||||
if [[ $(conf_read mysql) != "true" ]]; then
|
||||
mysql_install
|
||||
[[ -z $notools && $(conf_read mysql) == "true" && $(conf_read php) == "true" && $(conf_read nginx) == "true" && $(conf_read nginx-tool) == "true" ]] && stack -pma || echo "${gre}PhpMyAdmin was NOT installed!${end}"
|
||||
[[ -z $notools && $(conf_read mysql) == "true" && $(conf_read php) == "true" && $(conf_read nginx) == "true" && $(conf_read nginx-tool) == "true" ]] && stack -pma || echo "${gre}phpMyAdmin was NOT installed!${end}"
|
||||
messagend_install
|
||||
else
|
||||
echo "${red}MySQL is already installed!${end}"
|
||||
|
@ -369,11 +367,11 @@ elif [[ -n $mysql ]]; then
|
|||
|
||||
elif [[ -n $pma ]]; then
|
||||
if [[ $(conf_read mysql) != "true" || $(conf_read php) != "true" || $(conf_read nginx) != "true" || $(conf_read nginx-tool) != "true" ]]; then
|
||||
echo "${red}[ERROR] You need to have MySQL, PHP and NGINX installed before you can install PhpMyAdmin! ${end}"
|
||||
echo "${red}[ERROR] You need to have MySQL, PHP and NGINX installed before you can install phpMyAdmin! ${end}"
|
||||
clear_force_flag
|
||||
exit 1
|
||||
fi
|
||||
[[ $(conf_read mysql-tool) != "true" ]] && mysql_tool || echo "${red}PhpMyAdmin is already installed!${end}"
|
||||
[[ $(conf_read mysql-tool) != "true" ]] && mysql_tool || echo "${red}phpMyAdmin is already installed!${end}"
|
||||
|
||||
elif [[ -n $lemp ]]; then
|
||||
api-events_update st1
|
||||
|
@ -395,7 +393,6 @@ elif [[ -n $php_ver ]]; then
|
|||
echo "${blu}New PHP version: '$php_ver' ${end}"
|
||||
if [[ $(conf_read php) == "true" && $(conf_read php-ver) == $php_ver ]]; then
|
||||
echo "${gre}PHP $php_ver is currently installed!${end}"
|
||||
exit 0
|
||||
elif [[ $(conf_read php) == "true" && $(conf_read mysql-tool) == "true" ]]; then
|
||||
sudo stack -php -purge=force
|
||||
conf_write php-ver $php_ver
|
||||
|
@ -419,9 +416,7 @@ elif [[ -n $php_ver ]]; then
|
|||
fi
|
||||
|
||||
|
||||
# Info & Purge-Server-All
|
||||
elif [[ -n $info ]]; then
|
||||
system_info
|
||||
# Purge-Server-All
|
||||
elif [[ -n $purge_server_all ]]; then
|
||||
api-events_update st2
|
||||
echo ""
|
||||
|
@ -448,9 +443,9 @@ elif [[ -n $purge_server_all ]]; then
|
|||
clear_force_flag
|
||||
|
||||
# Remove remanent packages and things!
|
||||
[[ -a /etc/ssl/certs/webinoly-blackhole.crt.pem ]] && sudo rm -rf /etc/ssl/certs/webinoly-blackhole.crt.pem
|
||||
[[ -a /etc/ssl/private/webinoly-blackhole.key.pem ]] && sudo rm -rf /etc/ssl/private/webinoly-blackhole.key.pem
|
||||
[[ -a /etc/ssl/dhparam.pem ]] && sudo rm -rf /etc/ssl/dhparam.pem
|
||||
[[ -f /etc/ssl/certs/webinoly-blackhole.crt.pem ]] && sudo rm -rf /etc/ssl/certs/webinoly-blackhole.crt.pem
|
||||
[[ -f /etc/ssl/private/webinoly-blackhole.key.pem ]] && sudo rm -rf /etc/ssl/private/webinoly-blackhole.key.pem
|
||||
[[ -f /etc/ssl/dhparam.pem ]] && sudo rm -rf /etc/ssl/dhparam.pem
|
||||
if [[ $(conf_read pre-packs) == true ]]; then
|
||||
sudo apt-get -y -qq purge pwgen unzip zip > /dev/null
|
||||
sudo apt-get -y -qq autoremove > /dev/null
|
||||
|
|
505
plugins/webinoly
505
plugins/webinoly
|
@ -13,18 +13,7 @@ api-events_update wys
|
|||
|
||||
if [[ -n $update ]]; then
|
||||
api-events_update wy1
|
||||
checkver=$(wget --timeout=10 -t 1 -qO- https://api.webinoly.com/check?text=true)
|
||||
currentver=$(conf_read app-version)
|
||||
|
||||
if [[ ( -n $checkver && ${checkver//.} -gt ${currentver//.} ) || ( -n $update && $update != true ) ]]; then
|
||||
echo ""
|
||||
[[ -n $update && $update != true ]] && branch="-ver=${update}" || branch=""
|
||||
sudo wget --timeout=15 -t 1 --referer="https://update.webinoly.com/?ver=${app_version}" -qrO weby https://qrok.es/wyupd && sudo bash weby upd $branch
|
||||
[[ $? == 0 ]] && echo "${gre}Webinoly App has been updated successfully!${end}"
|
||||
api-events_update wy1s
|
||||
else
|
||||
echo "${gre}You currently have the latest version!${end}"
|
||||
fi
|
||||
webinoly_update
|
||||
nginx_not="true" # Nginx-Reload not-needed.
|
||||
|
||||
|
||||
|
@ -36,43 +25,7 @@ elif [[ -n $server_reset ]]; then
|
|||
echo "${red}[ERROR] Please, enter a valid option to update/reset your server configuration!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Regenerate NGINX conf files
|
||||
if [[ $(conf_read nginx-optim) == "true" && $server_reset =~ ^(nginx|all)$ ]]; then
|
||||
[[ -a /etc/nginx/conf.d/blockips.conf ]] && sudo cp -p /etc/nginx/conf.d/blockips.conf /tmp/webinoly_blockips_backup
|
||||
sudo rm -rf /etc/nginx/common
|
||||
sudo rm -rf /etc/nginx/conf.d/*
|
||||
linux_purge
|
||||
nginx_optim
|
||||
[[ -a /tmp/webinoly_blockips_backup ]] && sudo mv /tmp/webinoly_blockips_backup /etc/nginx/conf.d/blockips.conf
|
||||
echo "${gre}Nginx settings has been updated successfully!${end}"
|
||||
nginx_not="true" # Nginx-Reload not-needed.
|
||||
elif [[ $(conf_read nginx-optim) != "true" && $server_reset == "nginx" ]]; then
|
||||
echo "${red}[ERROR] Nginx settings couldn't been updated, seems like is not installed in your server!${end}"
|
||||
err_cont=true
|
||||
fi
|
||||
|
||||
# Regenerate PHP conf files
|
||||
if [[ $(conf_read php-optim) == "true" && $server_reset =~ ^(php|all)$ ]]; then
|
||||
if [[ -a /opt/webinoly/templates/source/php.ini && -a /opt/webinoly/templates/source/www.conf ]]; then
|
||||
sudo cat /opt/webinoly/templates/source/php.ini > /etc/php/$(conf_read php-ver)/fpm/php.ini
|
||||
sudo cat /opt/webinoly/templates/source/www.conf > /etc/php/$(conf_read php-ver)/fpm/pool.d/www.conf
|
||||
sudo rm -rf /etc/php/$(conf_read php-ver)/fpm/pool.d/debug.conf
|
||||
php_optim
|
||||
echo "${gre}PHP settings has been updated successfully!${end}"
|
||||
else
|
||||
echo "${red}[ERROR] PHP could not been updated, source files not found!${end}"
|
||||
exit 1
|
||||
fi
|
||||
elif [[ $(conf_read php-optim) != "true" && $server_reset == "php" ]]; then
|
||||
echo "${red}[ERROR] PHP settings couldn't been updated, seems like is not installed in your server!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Display message just to show we are alive.
|
||||
if [[ $server_reset == "all" && $(conf_read php-optim) != "true" && $(conf_read nginx-optim) != "true" ]]; then
|
||||
echo "${blu}Nothing to do, NGINX and PHP are not installed yet!${end}"
|
||||
fi
|
||||
server_reset
|
||||
|
||||
|
||||
elif [[ -n $verify ]]; then
|
||||
|
@ -81,269 +34,42 @@ elif [[ -n $verify ]]; then
|
|||
|
||||
|
||||
elif [[ -n $dbpass ]]; then
|
||||
if [[ -n $(conf_read mysql-root) || -n $(conf_read mysql-admin) ]]; then
|
||||
rpass=$( echo $(conf_read mysql-root) | openssl enc -d -a -salt )
|
||||
apass=$( echo $(conf_read mysql-admin) | openssl enc -d -a -salt )
|
||||
echo ""
|
||||
[[ $dbpass == "raw" || -n $raw ]] && echo "root:$rpass" || echo "${gre} root: $rpass"
|
||||
[[ $dbpass == "raw" || -n $raw ]] && echo "admin:$apass" || echo " admin: $apass ${end}"
|
||||
echo ""
|
||||
else
|
||||
echo "${red}"
|
||||
echo "[ERROR] DB Passwords not found!"
|
||||
echo "${end}"
|
||||
exit 1
|
||||
fi
|
||||
show_db_data
|
||||
nginx_not="true" # Nginx-Reload not-needed.
|
||||
|
||||
|
||||
elif [[ -n $tools_port ]]; then
|
||||
check_for_php
|
||||
oldport="$(conf_read tools-port)"
|
||||
if [[ -a /etc/nginx/sites-available/$tools_port ]]; then
|
||||
if [[ -f /etc/nginx/sites-available/$tools_port ]]; then
|
||||
echo "${red}[ERROR] Port/site '$tools_port' is already in use!${end}"
|
||||
exit 1
|
||||
elif [[ ! -a /etc/nginx/sites-available/$oldport ]]; then
|
||||
elif [[ ! -f /etc/nginx/sites-available/$oldport ]]; then
|
||||
echo "${red}[ERROR] Site '$oldport' not found!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
[[ $tools_port != true ]] && tools_port $tools_port || tools_port
|
||||
newport="$(conf_read tools-port)"
|
||||
if [[ $oldport != $newport && $(conf_read nginx-tool) == "true" && $(conf_read nginx) == "true" ]]; then
|
||||
# MV in some edge cases fails to rename, specially when so much files are within the directories.
|
||||
sudo mkdir -p /var/www/$newport
|
||||
sudo cp -rp /var/www/$oldport/* /var/www/$newport
|
||||
sudo rm -rf /var/www/$oldport
|
||||
|
||||
sudo mv /etc/nginx/sites-available/$oldport /etc/nginx/sites-available/$newport
|
||||
sudo rm /etc/nginx/sites-enabled/$oldport
|
||||
sudo ln -s /etc/nginx/sites-available/$newport /etc/nginx/sites-enabled/$newport
|
||||
sudo sed -i "s/${oldport}/${newport}/g" /etc/nginx/sites-available/$newport
|
||||
else
|
||||
change_tools_port
|
||||
fi
|
||||
|
||||
|
||||
elif [[ -n $tools_site ]]; then
|
||||
check_for_nginx -ask
|
||||
if [[ $tools_site == true ]]; then
|
||||
echo "${gre}Please, enter a valid domain to access the Tools Section! ${end}"
|
||||
read -p "${blu}Domain: ${end}" tools_site
|
||||
tools_site=${tools_site:-NeverMatchDotCom}
|
||||
fi
|
||||
|
||||
if [[ -a /etc/nginx/sites-available/$tools_site && -a /etc/nginx/sites-available/$(conf_read tools-port) && $tools_site != "default" ]]; then
|
||||
# Check for previous assigned domain and remove
|
||||
if [[ -n $(conf_read tools-site) ]]; then
|
||||
sudo sed -i '/server_name/d' /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
# In case SSL is enabled
|
||||
sudo sed -i "/listen $(conf_read tools-port)/c \ listen $(conf_read tools-port) default_server deferred;" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i "/listen \[::\]:$(conf_read tools-port)/c \ listen [::]:$(conf_read tools-port) default_server;" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i '/headers-https.conf/d' /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i '/WebinolySSLstart/,/WebinolySSLend/{/.*/d}' /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i '/WebinolyToolsStartBlackhole/,/WebinolyToolsEndBlackhole/{/.*/d}' /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
fi
|
||||
|
||||
# Assign new domain/site
|
||||
sername=$(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$tools_site | grep -F "server_name" | sed -e 's/^[ \t]*//')
|
||||
sudo sed -i "/error_log/a \ ${sername}" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i "/listen $(conf_read tools-port)/c \ listen $(conf_read tools-port) deferred;" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i "/listen \[::\]:$(conf_read tools-port)/c \ listen [::]:$(conf_read tools-port);" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
|
||||
# If SSL is enabled
|
||||
if [[ $(is_ssl $tools_site) == "true" ]]; then
|
||||
sudo sed -i "/listen $(conf_read tools-port)/c \ listen $(conf_read tools-port) ssl http2 deferred;" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i "/listen \[::\]:$(conf_read tools-port)/c \ listen [::]:$(conf_read tools-port) ssl http2;" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i '/server_name /r /opt/webinoly/templates/template-site-ssl' /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i "/WebinolySSLstart/,/WebinolySSLend/{s/domain.com/$tools_site/}" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i '/locations.conf/a \ include common/headers-https.conf;' /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i "/WebinolySSLend/i \ error_page 497 https:\/\/\$host:\$server_port\$request_uri;" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
create_blackhole_cert
|
||||
fi
|
||||
|
||||
# Default blackhole for requests different from our assigned Tools-Site
|
||||
sudo sed -i '/Webinoly Admin-Tools NGINX CONFIGURATION/r /opt/webinoly/templates/general/tools-site-blackhole' /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i "/WebinolyToolsStartBlackhole/,/WebinolyToolsEndBlackhole/{s/22222/$(conf_read tools-port)/}" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
if [[ $(is_ssl $tools_site) == "false" ]]; then
|
||||
sudo sed -i "/WebinolyToolsStartBlackhole/,/WebinolyToolsEndBlackhole/{/ssl_certificate/d}" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i "/WebinolyToolsStartBlackhole/,/WebinolyToolsEndBlackhole/{/error_page/d}" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i "/WebinolyToolsStartBlackhole/,/WebinolyToolsEndBlackhole/{s/ssl //}" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
echo "${red}It's highly recommended having an SSL Cert enabled on this site. ${end}"
|
||||
fi
|
||||
|
||||
conf_write tools-site $tools_site
|
||||
echo "${gre}Domain ${blu}- ${tools_site}:$(conf_read tools-port) -${gre} was successfully assigned to access your server tools!${end}"
|
||||
elif [[ $tools_site == "default" ]]; then
|
||||
sudo rm -rf /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo cp /opt/webinoly/templates/nginx/22222 /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
sudo sed -i "s/22222/$(conf_read tools-port)/g" /etc/nginx/sites-available/$(conf_read tools-port)
|
||||
conf_delete tools-site
|
||||
echo "${gre}Tools Site settings has been reset successfully!${end}"
|
||||
elif [[ -a /etc/nginx/sites-available/$tools_site && ! -a /etc/nginx/sites-available/$(conf_read tools-port) ]]; then
|
||||
echo "${red}[ERROR] Tools Site is not enabled! ${end}"
|
||||
exit 1
|
||||
else
|
||||
echo "${red}[ERROR] Domain/site not found. ${end}"
|
||||
exit 1
|
||||
fi
|
||||
set_tools_site
|
||||
|
||||
|
||||
elif [[ -n $login_www_data ]]; then
|
||||
check_for_nginx -ask
|
||||
if [[ $login_www_data == "on" ]]; then
|
||||
if [[ $(conf_read login-www-data) == "true" ]]; then
|
||||
echo "${gre}SFTP access for www-data user is already enabled! ${end}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Allow access for www-data user
|
||||
if [[ -a $HOME/.ssh/authorized_keys ]]; then
|
||||
sudo mkdir -p /var/www/.ssh
|
||||
sudo chmod 700 /var/www/.ssh
|
||||
sudo cat $HOME/.ssh/authorized_keys > /var/www/.ssh/authorized_keys
|
||||
sudo chmod 600 /var/www/.ssh/*
|
||||
fi
|
||||
sudo chown -R www-data:www-data /var/www
|
||||
|
||||
# www-data sftp-only access jail - if fails usrlib must be listed in /etc/shells
|
||||
sudo usermod -s /usr/lib/openssh/sftp-server www-data
|
||||
sudo addgroup --system sftponly > /dev/null 2>&1
|
||||
sudo usermod -G sftponly www-data
|
||||
sudo chown root:root /var/www
|
||||
sudo sed -i "/Subsystem sftp/c\Subsystem sftp internal-sftp" /etc/ssh/sshd_config
|
||||
sudo echo '# WebinolySFTPstart
|
||||
Match Group sftponly
|
||||
ChrootDirectory /var/www
|
||||
X11Forwarding no
|
||||
AllowTcpForwarding no
|
||||
ForceCommand internal-sftp
|
||||
# WebinolySFTPend' >> /etc/ssh/sshd_config
|
||||
|
||||
falus=$( grep -Gi "^AllowUsers " /etc/ssh/sshd_config )
|
||||
[[ -n $falus ]] && sudo sed -i "s/$falus/$falus www-data/" /etc/ssh/sshd_config
|
||||
|
||||
conf_write login-www-data true
|
||||
sudo service ssh restart
|
||||
echo "${gre}SFTP access for www-data user has been successfuly enabled! ${end}"
|
||||
|
||||
elif [[ $login_www_data == "off" ]]; then
|
||||
if [[ $(conf_read login-www-data) != "true" ]]; then
|
||||
echo "${gre}SFTP access for www-data user is already disabled! ${end}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
sudo rm -rf /var/www/.ssh
|
||||
sudo sed -i '/www-data:/c\www-data:x:33:33:www-data:\/var\/www:\/usr\/sbin\/nologin' /etc/passwd
|
||||
sudo gpasswd -d www-data sftponly > /dev/null 2>&1
|
||||
sudo delgroup sftponly > /dev/null 2>&1
|
||||
sudo chown www-data:www-data /var/www
|
||||
sudo sed -i "/Subsystem sftp/c\Subsystem sftp \/usr\/lib\/openssh\/sftp-server" /etc/ssh/sshd_config
|
||||
sudo sed -i '/WebinolySFTPstart/,/WebinolySFTPend/{/.*/d}' /etc/ssh/sshd_config
|
||||
|
||||
falus=$( grep -Gi "^AllowUsers " /etc/ssh/sshd_config )
|
||||
if [[ -n $falus ]]; then
|
||||
suffix=" www-data"
|
||||
foo=${falus%$suffix}
|
||||
sudo sed -i "s/$falus/$foo/" /etc/ssh/sshd_config
|
||||
fi
|
||||
|
||||
conf_write login-www-data purged
|
||||
sudo service ssh restart
|
||||
echo "${gre}SFTP access for www-data user has been successfuly disabled! ${end}"
|
||||
else
|
||||
echo "${red}[ERROR] Invalid value for login-www-data! ${end}"
|
||||
exit 1
|
||||
fi
|
||||
www_data_sftp_access
|
||||
nginx_not="true" # Nginx-Reload not-needed.
|
||||
|
||||
|
||||
elif [[ -n $config_cache ]]; then
|
||||
if [[ $(conf_read nginx) == "true" ]]; then
|
||||
hitline=$( grep -F "fastcgi_cache_valid 200" /etc/nginx/conf.d/fastcgi.conf )
|
||||
hitval=$(echo "${hitline//;}" | rev | cut -d' ' -f 1 | rev)
|
||||
inaline=$( grep -F "fastcgi_cache_path" /etc/nginx/conf.d/fastcgi.conf )
|
||||
inactive=$(echo "${inaline//;}" | rev | cut -d' ' -f 1 | rev)
|
||||
inaval=$(echo "${inactive}" | cut -d'=' -f 2)
|
||||
maxsize=$(echo "${inaline}" | rev | cut -d' ' -f 2 | rev)
|
||||
othline=$( grep -F "fastcgi_cache_valid 301 302 307 404 410" /etc/nginx/conf.d/fastcgi.conf )
|
||||
othval=$(echo "${othline//;}" | rev | cut -d' ' -f 1 | rev)
|
||||
else
|
||||
hitval="Not yet defined"
|
||||
inaval="Not yet defined"
|
||||
othval="Not yet defined"
|
||||
fi
|
||||
|
||||
|
||||
if [[ $config_cache == true ]]; then
|
||||
echo "${gre}"
|
||||
echo "**********************************************************************"
|
||||
echo "************* Set FastCGI Cache new time values **************"
|
||||
echo "***** Example: 30d = 30days | 3h = 3hours | 5m = 5minutes ******"
|
||||
echo "**********************************************************************"
|
||||
echo "${blu}"
|
||||
echo "FastCGI Cache Valid for Pages (HttpCode: 200) actual value is: $hitval"
|
||||
read -p " Set new value: " hit
|
||||
hit=${hit:-$hitval}
|
||||
echo ""
|
||||
echo "Purge Cache for inactive pages actual value is: $inaval"
|
||||
read -p " Set new value: " ina
|
||||
ina=${ina:-$inaval}
|
||||
echo ""
|
||||
echo "FastCGI Cache Valid for Errors and Redirections (HttpCode: 301, 302, 307, 404, 410) actual value is: $othval"
|
||||
read -p " Set new value: " oth
|
||||
oth=${oth:-$othval}
|
||||
echo ""
|
||||
elif [[ $(echo "${config_cache}" | cut -c-1) == "[" && $(echo "${config_cache}" | rev | cut -c-1) == "]" ]]; then
|
||||
custombegin=$(echo "${config_cache}" | cut -c-1)
|
||||
customlast=$(echo "${config_cache}" | rev | cut -c-1)
|
||||
cachedata=${config_cache:1:-1}
|
||||
|
||||
hit=$(echo "${cachedata}" | cut -d',' -f 1 )
|
||||
ina=$(echo "${cachedata}" | cut -d',' -f 2 )
|
||||
oth=$(echo "${cachedata}" | cut -d',' -f 3 )
|
||||
else
|
||||
echo "${red}[ERROR] Please enter a valid value!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$hit" =~ ^[0-9]+[smhdwMy]$ && "$ina" =~ ^[0-9]+[smhdwMy]$ && "$oth" =~ ^[0-9]+[smhdwMy]$ ]]; then
|
||||
if [[ $(conf_read nginx) == "true" ]]; then
|
||||
sudo sed -i "/fastcgi_cache_valid 200/c \fastcgi_cache_valid 200 ${hit};" /etc/nginx/conf.d/fastcgi.conf
|
||||
sudo sed -i "/fastcgi_cache_valid 301 302 307 404 410/c \fastcgi_cache_valid 301 302 307 404 410 ${oth};" /etc/nginx/conf.d/fastcgi.conf
|
||||
sudo sed -i "/fastcgi_cache_path/c \fastcgi_cache_path \/var\/run\/nginx-cache levels=1:2 keys_zone=WORDPRESS:50m ${maxsize} inactive=${ina};" /etc/nginx/conf.d/fastcgi.conf
|
||||
fi
|
||||
conf_write fastcgi-conf ${hit},${ina},${oth}
|
||||
echo "${gre}FastCGI Cache values has been successfully updated!${end}"
|
||||
else
|
||||
echo "${red}[ERROR] Invalid values!${end}"
|
||||
exit 1
|
||||
fi
|
||||
config_fastcgi_cache
|
||||
|
||||
|
||||
elif [[ -n $uninstall ]]; then
|
||||
api-events_update wy4
|
||||
echo "${red}"
|
||||
echo "You are about to completely remove Webinoly App from your server!!"
|
||||
echo "${blu}Are you sure [y/N]? "
|
||||
while read -r -n 1 -s answer; do
|
||||
answer=${answer:-n}
|
||||
echo ""
|
||||
[[ $answer = [YyNn] ]] && break
|
||||
done
|
||||
|
||||
if [[ $answer == [Yy] ]]; then
|
||||
sudo tar -Pcf $HOME/.webinoly-conf-restore_dont-remove /opt/webinoly/webinoly.conf /opt/webinoly/templates/source
|
||||
sudo rm -rf /opt/webinoly
|
||||
sudo rm /usr/bin/webinoly
|
||||
sudo rm /usr/bin/stack
|
||||
sudo rm /usr/bin/site
|
||||
sudo rm /usr/bin/httpauth
|
||||
sudo rm /usr/bin/log
|
||||
echo "${gre}Webinoly App has been removed successfully from your server!${end}"
|
||||
exit 0
|
||||
else
|
||||
echo "${red}Action aborted!${end}"
|
||||
exit 1
|
||||
fi
|
||||
webinoly_uninstall
|
||||
nginx_not="true" # Nginx-Reload not-needed.
|
||||
|
||||
|
||||
|
@ -353,35 +79,7 @@ elif [[ -n $info ]]; then
|
|||
|
||||
|
||||
elif [[ -n $external_sources_update ]]; then
|
||||
echo "${blu}- Downloading Public Suffix List!${end}"
|
||||
sudo wget --timeout=15 -t 1 -qrO /tmp/temp-public_suffix_list.dat https://publicsuffix.org/list/public_suffix_list.dat
|
||||
if [[ -s /tmp/temp-public_suffix_list.dat ]]; then
|
||||
echo "${blu}- Processing file!${end}"
|
||||
sudo sed -i '/^\/\// d' /tmp/temp-public_suffix_list.dat
|
||||
sudo sed -i '/^$/d' /tmp/temp-public_suffix_list.dat
|
||||
sudo sed -i 's/[!]\+//g' /tmp/temp-public_suffix_list.dat
|
||||
sudo sed -i 's/^\*\.\+//g' /tmp/temp-public_suffix_list.dat
|
||||
sudo mv /tmp/temp-public_suffix_list.dat /opt/webinoly/lib/public_suffix_list.dat
|
||||
echo "${gre}Domain list has been successfully updated!${end}"
|
||||
else
|
||||
echo "${red}[ERROR] Domain list not updated!${end}"
|
||||
err_cont=true
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "${blu}- Downloading Timezone Database!${end}"
|
||||
sudo wget --timeout=15 -t 1 -qrO /tmp/timezonedb.tgz https://pecl.php.net/get/timezonedb
|
||||
if [[ -s /tmp/timezonedb.tgz ]]; then
|
||||
echo "${blu}- Processing file!${end}"
|
||||
sudo tar -xf /tmp/timezonedb.tgz -C /tmp/ --wildcards --no-anchored timezonedb-*/timezonedb.h --strip-components=1
|
||||
sudo sed -i '/^\t{.*},$/!d' /tmp/timezonedb.h
|
||||
sudo cut -d'"' -f2 /tmp/timezonedb.h > /opt/webinoly/lib/timezone.dat
|
||||
sudo rm /tmp/timezonedb.*
|
||||
echo "${gre}Timezone Database has been successfully updated!${end}"
|
||||
else
|
||||
echo "${red}[ERROR] Timezone Database not updated!${end}"
|
||||
exit 1
|
||||
fi
|
||||
external_sources_update
|
||||
nginx_not="true" # Nginx-Reload not-needed.
|
||||
|
||||
|
||||
|
@ -392,52 +90,7 @@ elif [[ -n $clear_cache ]]; then
|
|||
echo "${red}[ERROR] Please, enter a valid option!${end}"
|
||||
exit 1
|
||||
fi
|
||||
if [[ $clear_cache =~ ^(redis|all)$ ]]; then
|
||||
if [[ $(conf_read php-tool) == "true" && -a /etc/redis/redis.conf ]]; then
|
||||
sudo redis-cli flushall
|
||||
echo "${gre}- Redis Cache has been successfully cleared!${end}"
|
||||
else
|
||||
echo "${red}[ERROR] We can not clear Redis Cache because is not installed!${end}"
|
||||
err_cont=true
|
||||
fi
|
||||
fi
|
||||
if [[ $clear_cache =~ ^(memcache|memcached|all)$ ]]; then
|
||||
if [[ $(conf_read php-tool) == "true" && -a /etc/memcached.conf ]]; then
|
||||
memhost=$(grep ^-l /etc/memcached.conf | cut -f 2 -d ' ')
|
||||
memport=$(grep ^-p /etc/memcached.conf | cut -f 2 -d ' ')
|
||||
echo flush_all > /dev/tcp/$memhost/$memport
|
||||
echo "${gre}- Memcached has been successfully cleared!${end}"
|
||||
else
|
||||
echo "${red}[ERROR] We can not clear Memcache because is not installed!${end}"
|
||||
err_cont=true
|
||||
fi
|
||||
fi
|
||||
if [[ $clear_cache =~ ^(opcache|all)$ ]]; then
|
||||
if [[ $(conf_read nginx-tool) == "true" && $(conf_read php-tool) == "true" ]]; then
|
||||
port=$(conf_read tools-port)
|
||||
if [[ ! -a /var/www/$port/htdocs/php/opcache/index.php ]]; then
|
||||
sudo mkdir /var/www/$port/htdocs/php/opcache
|
||||
sudo touch /var/www/$port/htdocs/php/opcache/index.php
|
||||
echo '<?php opcache_reset(); echo "OK\n";' > /var/www/$port/htdocs/php/opcache/index.php
|
||||
sudo chown -R www-data:www-data /var/www/$port/htdocs/php/opcache
|
||||
sudo chmod 644 /var/www/$port/htdocs/php/opcache/index.php
|
||||
fi
|
||||
wget --spider --no-check-certificate --timeout=15 -t 1 localhost:$port/php/opcache/ > /dev/null 2>&1 &
|
||||
echo "${gre}- OpCache has been successfully cleared!${end}"
|
||||
else
|
||||
echo "${red}[ERROR] We can not clear OpCache because PHP or NGINX are not installed!${end}"
|
||||
err_cont=true
|
||||
fi
|
||||
fi
|
||||
if [[ $clear_cache =~ ^(fastcgi|all)$ ]]; then
|
||||
if [[ $(conf_read nginx) == "true" ]]; then
|
||||
sudo rm -Rf /var/run/nginx-cache/*
|
||||
echo "${gre}- FastCgi Cache has been successfully cleared!${end}"
|
||||
else
|
||||
echo "${red}[ERROR] We can not clear FastCGI Cache because NGINX is not installed!${end}"
|
||||
err_cont=true
|
||||
fi
|
||||
fi
|
||||
clear_caches
|
||||
nginx_not="true" # Nginx-Reload not-needed.
|
||||
|
||||
|
||||
|
@ -468,55 +121,7 @@ elif [[ -n $version || -n $v || -n $V ]]; then
|
|||
|
||||
elif [[ -n $blockip ]]; then
|
||||
check_for_nginx -ask
|
||||
if [[ -z $purge ]]; then
|
||||
if [[ -n $list ]]; then
|
||||
echo ""
|
||||
[[ -n $raw ]] && sign="" || sign="${blu}+ "
|
||||
if [[ -s /etc/nginx/conf.d/blockips.conf ]]; then
|
||||
sudo sed -n "s/^deny /${sign}/p;" /etc/nginx/conf.d/blockips.conf | sudo sed -n 's/;$//p'
|
||||
else
|
||||
echo "[Empty] No IP's were found!"
|
||||
fi
|
||||
[[ $list == "raw" || -n $raw ]] && echo "" || echo "${end}"
|
||||
else
|
||||
[[ $blockip == true ]] && read -p "${blu}IP address to block: ${end}" blockip
|
||||
if [[ $(ip_check $blockip) == "true" ]]; then
|
||||
if [[ ! -a /etc/nginx/conf.d/blockips.conf ]]; then
|
||||
sudo touch /etc/nginx/conf.d/blockips.conf
|
||||
sudo chmod 644 /etc/nginx/conf.d/blockips.conf
|
||||
sudo chown -R root:root /etc/nginx/conf.d/blockips.conf
|
||||
fi
|
||||
exist=$( grep -E "^deny $blockip;$" /etc/nginx/conf.d/blockips.conf )
|
||||
if [[ -z $exist ]]; then
|
||||
echo "deny $blockip;" >> /etc/nginx/conf.d/blockips.conf
|
||||
echo "${gre}The IP address ${blu}'$blockip'${gre} was successfully blocked!${end}"
|
||||
else
|
||||
echo "${gre}IP '$blockip' is already blocked!${end}"
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
echo "${red}[ERROR] Please, enter a valid IP value!${end}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
elif [[ -n $purge ]]; then
|
||||
[[ $blockip == true ]] && read -p "${blu}IP address to unblock: ${end}" blockip
|
||||
if [[ $(ip_check $blockip) == "true" ]]; then
|
||||
# https://stackoverflow.com/questions/1797906/delete-using-a-different-delimiter-with-sed
|
||||
[[ -a /etc/nginx/conf.d/blockips.conf ]] && sed -i "\#^deny ${blockip};#d" /etc/nginx/conf.d/blockips.conf
|
||||
|
||||
# Remove site-auth-file if empty.
|
||||
[[ ! -s /etc/nginx/conf.d/blockips.conf ]] && sudo rm /etc/nginx/conf.d/blockips.conf
|
||||
|
||||
echo "${gre}The IP address ${blu}'$blockip'${gre} was successfully unblocked!${end}"
|
||||
else
|
||||
echo "${red}[ERROR] Please, enter a valid IP value!${end}"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "${red}[ERROR] Nginx file not found!${end}"
|
||||
exit 1
|
||||
fi
|
||||
nginx_blockip
|
||||
|
||||
|
||||
elif [[ -n $conf_value ]]; then
|
||||
|
@ -551,53 +156,7 @@ elif [[ -n $yoast_sitemap ]]; then
|
|||
|
||||
elif [[ -n $default_site ]]; then
|
||||
check_for_nginx -ask
|
||||
if [[ $default_site == true ]]; then
|
||||
echo "${gre}Please, enter a valid option to set the Default-Site server response! ${end}"
|
||||
read -p "${blu}default/blackhole or any existing domain: ${end}" default_site
|
||||
default_site=${default_site:-NeverMatchDotCom}
|
||||
fi
|
||||
|
||||
if [[ $default_site == "default" ]]; then
|
||||
if [[ -a /opt/webinoly/templates/source/default ]]; then
|
||||
sudo cat /opt/webinoly/templates/source/default >| /etc/nginx/sites-available/default
|
||||
remove_domain_default_site
|
||||
conf_write default-site default
|
||||
echo "${gre}Default Nginx was successfully assigned as default site!${end}"
|
||||
else
|
||||
echo "${red}[ERROR] Nginx Default file backup not found! ${end}"
|
||||
exit 1
|
||||
fi
|
||||
elif [[ $default_site == "blackhole" ]]; then
|
||||
sudo cat /opt/webinoly/templates/general/nginx-blackhole >| /etc/nginx/sites-available/default
|
||||
remove_domain_default_site
|
||||
create_blackhole_cert
|
||||
conf_write default-site blackhole
|
||||
echo "${gre}Blackhole Nginx site was successfully assigned as default site!${end}"
|
||||
else
|
||||
# Domain option
|
||||
if [[ -L /etc/nginx/sites-enabled/$default_site ]]; then
|
||||
remove_domain_default_site
|
||||
sudo sed -i "s/listen 80;/listen 80 default_server;/" /etc/nginx/sites-available/$default_site
|
||||
sudo sed -i "s/listen \[::\]:80;/listen [::]:80 default_server;/" /etc/nginx/sites-available/$default_site
|
||||
sudo sed -i '/WebinolyNginxServerStart/,/WebinolyNginxServerEnd/{s/listen 443 ssl http2;/listen 443 ssl http2 default_server;/}' /etc/nginx/sites-available/$default_site
|
||||
sudo sed -i '/WebinolyNginxServerStart/,/WebinolyNginxServerEnd/{s/listen \[::\]:443 ssl http2;/listen [::]:443 ssl http2 default_server;/}' /etc/nginx/sites-available/$default_site
|
||||
|
||||
# If default site is Non-SSL, we need add a blackhole for port 443.
|
||||
if [[ $(is_ssl $default_site) == "false" ]]; then
|
||||
create_blackhole_cert
|
||||
sudo sed -i '1r /opt/webinoly/templates/general/nginx-blackhole' /etc/nginx/sites-available/$default_site
|
||||
sudo sed -i '/NonSSL/,/NonSSLend/{/.*/d}' /etc/nginx/sites-available/$default_site
|
||||
fi
|
||||
|
||||
sudo rm -rf /etc/nginx/sites-enabled/default
|
||||
conf_write default-site $default_site
|
||||
echo "${gre}Site ${blu}- ${default_site} -${gre} was successfully assigned as default site!${end}"
|
||||
else
|
||||
[[ -a /etc/nginx/sites-available/$default_site ]] && echo "${red}Site found but is disabled.${end}"
|
||||
echo "${red}[ERROR] Please, enter a valid option (default, blackhole or domain.com). ${end}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
set_default_nginx_response
|
||||
|
||||
|
||||
elif [[ -n $mysql_password ]]; then
|
||||
|
@ -630,11 +189,8 @@ elif [[ -n $smtp ]]; then
|
|||
echo "${red}[ERROR] Seems like PHP and Postfix are not installed!${end}"
|
||||
exit 1
|
||||
fi
|
||||
if [[ $(conf_read smtp) == "true" ]]; then
|
||||
echo "${gre}SMTP is already configured!${end}"
|
||||
exit 0
|
||||
fi
|
||||
smtp_setup
|
||||
|
||||
[[ $(conf_read smtp) == "true" ]] && echo "${gre}SMTP is already configured!${end}" || smtp_setup
|
||||
nginx_not="true" # Nginx-Reload not-needed.
|
||||
|
||||
|
||||
|
@ -652,32 +208,7 @@ elif [[ -n $backup ]]; then
|
|||
|
||||
|
||||
elif [[ -n $aws_s3_credentials ]]; then
|
||||
if [[ $aws_s3_credentials == true ]]; then
|
||||
echo ""
|
||||
read -p "${blu}Access Key ID: ${end}" user
|
||||
read -p "${blu}Secret Access Key: ${end}" pass
|
||||
echo ""
|
||||
elif [[ $(echo "${aws_s3_credentials}" | cut -c-1) == "[" && $(echo "${aws_s3_credentials}" | rev | cut -c-1) == "]" ]]; then
|
||||
cred=${aws_s3_credentials:1:-1}
|
||||
user=$(echo "${cred}" | cut -d',' -f 1 -s)
|
||||
pass=$(echo "${cred}" | cut -d',' -f 2 -s)
|
||||
else
|
||||
echo "${red}[ERROR] Invalid AWS S3 Credentials!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! [[ -n $user && -n $pass ]]; then
|
||||
echo "${red}[ERROR] Please, enter a valid AWS S3 Access and Secret Key!${end}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sudo rm -rf /root/.aws/credentials
|
||||
sudo mkdir -p /root/.aws
|
||||
sudo touch /root/.aws/credentials
|
||||
sudo echo "[default]
|
||||
aws_access_key_id = $user
|
||||
aws_secret_access_key = $pass" >> /root/.aws/credentials
|
||||
echo "${gre}AWS S3 Credentials successfully added!${end}"
|
||||
aws_s3_credentials
|
||||
|
||||
|
||||
else
|
||||
|
|
Loading…
Add table
Reference in a new issue