소스 검색

force redirect

Force redirect issue, not updating WP db when installed in subfolder, or is multisite.
Cristhian Martínez Ochoa 2 년 전
부모
커밋
cc3ec5317c
4개의 변경된 파일46개의 추가작업 그리고 37개의 파일을 삭제
  1. 36 15
      lib/general
  2. 6 18
      lib/site-ssl
  3. 3 3
      lib/sites
  4. 1 1
      usr/site

+ 36 - 15
lib/general

@@ -509,7 +509,8 @@ wp_conf_retrieve() {
 	
 	
 	# In case of parked sites with WP domain mapping
-	if [[ $3 != "false" && $(is_parked $1) == "true" ]]; then
+	#if [[ $3 != "false" && $(is_parked $1) == "true" ]]; then # Modified recently, not sure the impact!
+	if [[ $3 != "false" ]]; then
 		# If domain doesn't exist, check if it's a subsite of a subdomain Multisite network.
 		if [[ ! -f /etc/nginx/sites-available/$1 && -f /etc/nginx/sites-available/$(echo $1 | cut -d "." -f 2- -s) ]]; then
 			local maindom=$(echo $1 | cut -d "." -f 2- -s)
@@ -531,6 +532,8 @@ wp_conf_retrieve() {
 			if [[ $wp_blogid =~ ^[0-9]+$  && $wp_blogid -gt 1 ]]; then
 				wp_dbpref="${wp_dbpref}${wp_blogid}_"
 				echo "${blu}${dim}Site${end}${dim} ${1}${4} ${blu}is a subsite (${wp_dbpref}) in a WP Multisite Network!${end}" >&2
+			elif [[ $wp_blogid == 1 ]]; then
+				echo "${blu}${dim}Site${end}${dim} ${1}${4} ${blu}is the main site in a WP Multisite Network!${end}" >&2
 			else
 				[[ $wp_blogid != 1 ]] && wp_blogid=""
 			fi
@@ -1057,23 +1060,26 @@ email_update() {
 edit_wp_db_url_multisite() {
 	#Subfolder is not allowed here because is not needed, parked and force-www are not allowed in subfolders.
 	#Example: edit_wp_db_url_multisite olddomain.com newdomain.com 2
-	# $3 - WP BlogID to force
+	# $3 - WP BlogID to force (optional)
 	
-	if [[ -n $1 && -n $2 && -n $3 && $3 =~ ^[0-9]+$ && $(is_wp_multisite $1) =~ ^(subdomain|subdirectory)$ ]]; then
-		wp_conf_retrieve $1 true false $subfolder
+	if [[ -n $1 && -n $2 && $(is_wp_multisite $1) =~ ^(subdomain|subdirectory)$ ]]; then
+		wp_conf_retrieve $1 true true $subfolder
 		
 		# Force WP blogID
-		local wp_dbpref="${wp_dbpref}${3}_"
-		local wp_blogid=$3
-		local dbsetup="SELECT * FROM information_schema.tables WHERE table_schema = '$wp_dbname' AND table_name = '${wp_dbpref}options' LIMIT 1;"
-		if [[ $wp_dbhost == "localhost" && -n $(sudo mysql --connect-timeout=10 --user=admin -p$ADMIN_PASS -e "$dbsetup") ]]; then
-			echo "${blu}${dim}WordPress blog ID (${wp_dbpref}) found and validated in a WP Multisite Network!${end}" >&2
-		elif [[ $wp_dbhost != "localhost" && -n $(sudo mysql --connect-timeout=10 -h "$extdb_url" -P "$extdb_port" -u"$extdb_user" -p"$extdb_pass" -e "$dbsetup") ]]; then
-			echo "${blu}${dim}WordPress blog ID (${wp_dbpref}) found and validated in a WP Multisite Network!${end}" >&2
-		else
-			echo "${red}${dim}[ERROR] WordPress blog ID (${wp_dbpref}) not found!${end}" >&2
-			wp_dbpref=""
-			wp_blogid=""
+		if [[ -n $3 && $3 =~ ^[0-9]+$ ]]; then
+			local wp_dbpref="${wp_dbpref}${3}_"
+			local wp_blogid=$3		
+			local dbsetup="SELECT * FROM information_schema.tables WHERE table_schema = '$wp_dbname' AND table_name = '${wp_dbpref}options' LIMIT 1;"
+			
+			if [[ $wp_dbhost == "localhost" && -n $(sudo mysql --connect-timeout=10 --user=admin -p$ADMIN_PASS -e "$dbsetup") ]]; then
+				echo "${blu}${dim}WordPress blog ID (${wp_dbpref}) found and validated in a WP Multisite Network!${end}" >&2
+			elif [[ $wp_dbhost != "localhost" && -n $(sudo mysql --connect-timeout=10 -h "$extdb_url" -P "$extdb_port" -u"$extdb_user" -p"$extdb_pass" -e "$dbsetup") ]]; then
+				echo "${blu}${dim}WordPress blog ID (${wp_dbpref}) found and validated in a WP Multisite Network!${end}" >&2
+			else
+				echo "${red}${dim}[ERROR] WordPress blog ID (${wp_dbpref}) not found!${end}" >&2
+				wp_dbpref=""
+				wp_blogid=""
+			fi
 		fi
 		
 		if [[ -n $wp_dbhost && -n $wp_dbname && -n $wp_dbpref_main && -n $wp_blogid ]]; then
@@ -1139,6 +1145,21 @@ _EOF_
 }
 
 
+wp_db_update() {
+	# Same as edit_wp_db_url, but it also check and includes WP in subfolders.
+
+	# if main site is WP.
+	[[ $(is_wp $1) == "true" ]] && edit_wp_db_url $1 $2
+	
+	# Check if site contains WP in subfolders.
+	for site in "/etc/nginx/apps.d/${1}_"*-wpcommon.conf
+	do
+		local subwp="/$(echo $site | cut -f 2- -d "_" -s | cut -f -1 -d "-" -s | sed "s/_/\//g")"
+		[[ -n $subwp && -f /var/www/${1}/htdocs$subwp/wp-config.php ]] && edit_wp_db_url $1 ${2}${subwp} $subwp
+	done
+}
+
+
 db_role_check() {
 	if ! [[ $1 =~ ^(basic|limited|extra|complete|full|all|grant)$ ]]; then
 		echo "${red}[ERROR] Please, enter a valid database role!${end}"

+ 6 - 18
lib/site-ssl

@@ -4,18 +4,6 @@
 # Functions for SSL On/Off
 
 
-ssl_wp_db_update() {
-	# if main site is WP.
-	[[ $(is_wp $domain) == "true" ]] && edit_wp_db_url $domain $1
-	
-	# Check if site contains WP in subfolders.
-	for site in "/etc/nginx/apps.d/${domain}_"*-wpcommon.conf
-	do
-		local subwp="/$(echo $site | cut -f 2- -d "_" -s | cut -f -1 -d "-" -s | sed "s/_/\//g")"
-		[[ -n $subwp && -f /var/www/$domain/htdocs$subwp/wp-config.php ]] && edit_wp_db_url $domain ${1}${subwp} $subwp
-	done
-}
-
 ssl_nginx() {
 	sudo sed -i '/listen 80/c \	listen 443 ssl http2;' /etc/nginx/sites-available/$domain
 	sudo sed -i '/listen \[::\]:80/c \	listen [::]:443 ssl http2;' /etc/nginx/sites-available/$domain
@@ -48,9 +36,9 @@ ssl_nginx() {
 		# Not duplicate: Custom cert function does not run the same way as LE requests.
 		# For some unknown reason this condition doesn't work in oneline as we usually do!
 		if [[ $(is_force_redirect $domain) == "www" ]]; then
-			ssl_wp_db_update "https://www.${domain}"
+			wp_db_update $domain "https://www.${domain}"
 		else
-			ssl_wp_db_update "https://${domain}"
+			wp_db_update $domain "https://${domain}"
 		fi
 		
 		if [[ -n $ssl_ocsp && -f $ssl_ocsp ]]; then
@@ -190,9 +178,9 @@ site_ssl_on() {
 
 		# For some unknown reason this condition doesn't work in oneline as we usually do!
 		if [[ $(is_force_redirect $domain) == "www" ]]; then
-			ssl_wp_db_update "https://www.${domain}"
+			wp_db_update $domain "https://www.${domain}"
 		else
-			ssl_wp_db_update "https://${domain}"
+			wp_db_update $domain "https://${domain}"
 		fi
 		
 		echo "${gre}SSL have been successfully enabled for your site${blu} $domain${end}"
@@ -270,8 +258,8 @@ site_ssl_off() {
 		echo "${gre}${dim}Tools Site updated with SSL!${end}"
 	fi
 	
-	[[ -z $no_db_update && $(is_force_redirect $domain) != "www" ]] && ssl_wp_db_update "http://${domain}"
-	[[ -z $no_db_update && $(is_force_redirect $domain) == "www" ]] && ssl_wp_db_update "http://www.${domain}"
+	[[ -z $no_db_update && $(is_force_redirect $domain) != "www" ]] && wp_db_update $domain "http://${domain}"
+	[[ -z $no_db_update && $(is_force_redirect $domain) == "www" ]] && wp_db_update $domain "http://www.${domain}"
 	
 	# Check if exist to not try to revoke a cert that don't exist, for example a site with a cert added to a wildcard! (-add-to-wildcard)
 	if [[ -f /etc/letsencrypt/renewal/${domain}.conf ]]; then

+ 3 - 3
lib/sites

@@ -803,7 +803,7 @@ force_redirect() {
 	case $force_redirect in
 		"www")
 			[[ -n $rediron ]] && sudo sed -i '/WebinolyWWWredirectStart/,/WebinolyWWWredirectEnd/{/.*/d}' /etc/nginx/sites-available/$domain
-			edit_wp_db_url $domain "${scheme}://www.${domain}"
+			wp_db_update $domain "${scheme}://www.${domain}"
 			edit_wp_db_url_multisite $domain "www.${domain}"
 			
 			sudo sed -i "/#server_name;/c \	server_name $domain;" /tmp/template-site-wwwredirect
@@ -814,7 +814,7 @@ force_redirect() {
 		;;
 		"root")
 			[[ -n $rediron ]] && sudo sed -i '/WebinolyWWWredirectStart/,/WebinolyWWWredirectEnd/{/.*/d}' /etc/nginx/sites-available/$domain
-			edit_wp_db_url $domain "${scheme}://${domain}"
+			wp_db_update $domain "${scheme}://${domain}"
 			edit_wp_db_url_multisite $domain $domain
 			
 			sudo sed -i "/#server_name;/c \	server_name www.$domain;" /tmp/template-site-wwwredirect
@@ -824,7 +824,7 @@ force_redirect() {
 		;;
 		"off")
 			if [[ -n $rediron ]]; then
-				edit_wp_db_url $domain "${scheme}://${domain}"
+				wp_db_update $domain "${scheme}://${domain}"
 				edit_wp_db_url_multisite $domain $domain
 			
 				sudo sed -i '/WebinolyWWWredirectStart/,/WebinolyWWWredirectEnd/{/.*/d}' /etc/nginx/sites-available/$domain

+ 1 - 1
usr/site

@@ -324,7 +324,7 @@ elif [[ -n $ssl ]]; then
 				ssl_nginx
 				
 				# No need of force-redirect check because this site is always subdomain and subdomains are not supported in force-redirect.
-				[[ $(is_wp $domain) == "true" ]] && edit_wp_db_url $domain "https://${domain}"
+				[[ $(is_wp $domain) == "true" ]] && wp_db_update $domain "https://${domain}"
 				
 				echo "${gre}Your site${blu} $domain ${gre}have been successfully added to the${blu} $add_to_wildcard ${gre}wildcard cert.${end}"
 			else