Skip to content

Commit 1f7fd4a

Browse files
CopilotPDowney
andauthored
fix(vhost-install): multi-part TLD extraction, secure credentials file, WP-CLI warning, WP admin validation
Agent-Logs-Url: https://github.com/EngineScript/EngineScript/sessions/aa21343b-51cd-44d3-9b93-e89cf3ac7846 Co-authored-by: PDowney <[email protected]>
1 parent 5556424 commit 1f7fd4a

2 files changed

Lines changed: 59 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ All notable changes to EngineScript will be documented in this file.
44

55
Changes are organized by date, with the most recent changes listed first.
66

7+
## 2026-04-11 (2)
8+
9+
### 🔒 VHOST INSTALL SECURITY & ROBUSTNESS IMPROVEMENTS
10+
11+
- Fixed `domain_without_tld` extraction in `scripts/functions/vhost/vhost-install.sh` to correctly handle multi-part TLDs (e.g., `co.uk`, `com.au`, `org.nz`). For a domain like `example.co.uk` the extracted base is now `example` instead of `example.co`, preventing unexpected database naming.
12+
- Added `chmod 600` on the MySQL credentials file immediately after writing it in `scripts/functions/vhost/vhost-install.sh`, ensuring sensitive database credentials are protected from unauthorised access by other system users.
13+
- Clarified the warning message when WP-CLI fails to delete the default `hello` plugin: the new message reads "It may already be deleted or another error occurred. Continuing installation." instead of the misleading "Continuing if plugin is already absent."
14+
- Added pre-install validation of WordPress admin credentials (`WP_ADMIN_USERNAME`, `WP_ADMIN_PASSWORD`, `WP_ADMIN_EMAIL`) in `scripts/functions/vhost/vhost-install.sh` before calling `wp core install`, enforcing non-empty values, a valid username format (3-60 alphanumeric/underscore/dot/hyphen characters), a valid email address format, and a minimum password complexity of 12+ characters with upper, lower, digit, and special-character requirements.
15+
716
## 2026-04-11
817

918
### 🔧 VHOST IMPORT BUG FIXES & IMPROVEMENTS

scripts/functions/vhost/vhost-install.sh

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,31 @@ if [[ "${INSTALL_WORDPRESS}" == "1" ]]; then
158158

159159
# Domain Creation Variables
160160
PREFIX="${RAND_CHAR2}"
161-
domain_input="${DOMAIN}" && domain_without_tld="${domain_input%.*}" && database_name="${domain_without_tld}_${RAND_CHAR4}"
161+
domain_input="${DOMAIN}"
162+
IFS='.' read -r -a domain_parts <<< "${domain_input}"
163+
domain_without_tld="${domain_input%.*}"
164+
if (( ${#domain_parts[@]} >= 3 )); then
165+
public_suffix="${domain_parts[${#domain_parts[@]}-2]}.${domain_parts[${#domain_parts[@]}-1]}"
166+
case "${public_suffix}" in
167+
co.uk|org.uk|gov.uk|ac.uk|com.au|net.au|org.au|co.nz|org.nz|com.br)
168+
domain_without_tld="${domain_parts[${#domain_parts[@]}-3]}"
169+
;;
170+
esac
171+
fi
172+
database_name="${domain_without_tld}_${RAND_CHAR4}"
162173
database_user="${RAND_CHAR16}"
163174
database_password="${RAND_CHAR32}"
164175

165176
# Domain Database Credentials
166-
echo "DB=\"${database_name}\"" >> "/home/EngineScript/mysql-credentials/${DOMAIN}.txt"
167-
echo "USR=\"${database_user}\"" >> "/home/EngineScript/mysql-credentials/${DOMAIN}.txt"
168-
echo "PSWD=\"${database_password}\"" >> "/home/EngineScript/mysql-credentials/${DOMAIN}.txt"
169-
echo "" >> "/home/EngineScript/mysql-credentials/${DOMAIN}.txt"
177+
credentials_file="/home/EngineScript/mysql-credentials/${DOMAIN}.txt"
178+
# Create the file with restrictive permissions before writing any sensitive data
179+
install -m 600 /dev/null "${credentials_file}"
180+
echo "DB=\"${database_name}\"" >> "${credentials_file}"
181+
echo "USR=\"${database_user}\"" >> "${credentials_file}"
182+
echo "PSWD=\"${database_password}\"" >> "${credentials_file}"
183+
echo "" >> "${credentials_file}"
170184

171-
source "/home/EngineScript/mysql-credentials/${DOMAIN}.txt"
185+
source "${credentials_file}"
172186

173187
echo "Randomly generated MySQL database credentials for ${DOMAIN}."
174188

@@ -190,7 +204,7 @@ if [[ "${INSTALL_WORDPRESS}" == "1" ]]; then
190204
# Download WordPress using WP-CLI
191205
wp core download --allow-root
192206
if ! wp plugin delete hello --allow-root; then
193-
echo "Warning: Failed to delete default 'hello' plugin via WP-CLI. Continuing if plugin is already absent."
207+
echo "Warning: Failed to delete default 'hello' plugin via WP-CLI. It may already be deleted or another error occurred. Continuing installation."
194208
fi
195209

196210
# Create Extra WordPress Directories
@@ -232,6 +246,35 @@ if [[ "${INSTALL_WORDPRESS}" == "1" ]]; then
232246

233247
# WP-CLI Install WordPress
234248
cd "/var/www/sites/${DOMAIN}/html"
249+
250+
# Validate WordPress admin credentials before install
251+
if [[ -z "${WP_ADMIN_USERNAME}" || -z "${WP_ADMIN_PASSWORD}" || -z "${WP_ADMIN_EMAIL}" ]]; then
252+
echo "Error: WP admin credentials must not be empty (WP_ADMIN_USERNAME, WP_ADMIN_PASSWORD, WP_ADMIN_EMAIL)." >&2
253+
exit 1
254+
fi
255+
256+
# Username: 3-60 chars, must start with alphanumeric, letters/numbers/underscore/dot/hyphen
257+
if [[ ! "${WP_ADMIN_USERNAME}" =~ ^[A-Za-z0-9][A-Za-z0-9_.-]{2,59}$ ]]; then
258+
echo "Error: WP_ADMIN_USERNAME is invalid. Use 3-60 characters: letters, numbers, underscore, dot, or hyphen." >&2
259+
exit 1
260+
fi
261+
262+
# Email: basic format validation
263+
if [[ ! "${WP_ADMIN_EMAIL}" =~ ^[A-Za-z0-9][A-Za-z0-9._%+-]*[A-Za-z0-9]@[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?)*\.[A-Za-z]{2,}$ ]]; then
264+
echo "Error: WP_ADMIN_EMAIL is not a valid email address format." >&2
265+
exit 1
266+
fi
267+
268+
# Password: minimum complexity requirements
269+
if [[ ${#WP_ADMIN_PASSWORD} -lt 12 ]] || \
270+
[[ ! "${WP_ADMIN_PASSWORD}" =~ [A-Z] ]] || \
271+
[[ ! "${WP_ADMIN_PASSWORD}" =~ [a-z] ]] || \
272+
[[ ! "${WP_ADMIN_PASSWORD}" =~ [0-9] ]] || \
273+
[[ ! "${WP_ADMIN_PASSWORD}" =~ [^A-Za-z0-9] ]]; then
274+
echo "Error: WP_ADMIN_PASSWORD must be at least 12 characters and include uppercase, lowercase, number, and special character." >&2
275+
exit 1
276+
fi
277+
235278
wp core install --admin_user="${WP_ADMIN_USERNAME}" --admin_password="${WP_ADMIN_PASSWORD}" --admin_email="${WP_ADMIN_EMAIL}" --url="https://${DOMAIN}" --title='New Site' --skip-email --allow-root
236279

237280
# Install and activate required WordPress plugins

0 commit comments

Comments
 (0)