| Server IP : 146.190.157.162 / Your IP : 216.73.217.6 Web Server : Apache System : Linux ubuntu-s-2vcpu-4gb-amd-sfo3-01-KIT-DIGITAL 6.5.0-44-generic #44-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 7 15:10:09 UTC 2024 x86_64 User : businessweek ( 639) PHP Version : 8.2.10-2ubuntu2.2 Disable Function : exec,passthru,shell_exec,system,proc_open,popen,pcntl_exec,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_signal,pcntl_signal_dispatch,pcntl_getpriority,pcntl_setpriority,dl,putenv,parse_ini_file,show_source MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/ |
Upload File : |
#!/usr/bin/env bash
set -euo pipefail
BASE_DIR="${BASE_DIR:-/var/www/html}"
EXCLUDE_DIR="${EXCLUDE_DIR:-wordpress-manager}"
DRY_RUN=0
if [[ "${1:-}" == "--dry-run" ]]; then
DRY_RUN=1
fi
is_wp_root() {
[[ -f "$1/wp-config.php" ]]
}
run() {
if [[ "$DRY_RUN" -eq 1 ]]; then
printf '[DRY] %q' "$1"
shift
for a in "$@"; do
printf ' %q' "$a"
done
printf '\n'
else
"$@"
fi
}
restore_latest_backup() {
local cfg="$1"
local dir
dir="$(dirname "$cfg")"
local latest
latest="$(ls -1t "$dir"/wp-config.php.bak.* 2>/dev/null | head -n 1 || true)"
if [[ -n "$latest" && -f "$latest" ]]; then
echo "Restore: $cfg <= $latest"
run cp -a "$latest" "$cfg"
return 0
fi
return 1
}
strip_defines() {
local cfg="$1"
echo "Strip defines in: $cfg"
if [[ "$DRY_RUN" -eq 1 ]]; then
echo "[DRY] remove DISALLOW_FILE_EDIT / DISALLOW_FILE_MODS from $cfg"
return 0
fi
local tmp
tmp="$(mktemp)"
awk '
{
if ($0 ~ /^[[:space:]]*define\([[:space:]]*["'\'']DISALLOW_FILE_EDIT["'\''][[:space:]]*,[[:space:]]*true[[:space:]]*\)[[:space:]]*;[[:space:]]*$/) next
if ($0 ~ /^[[:space:]]*define\([[:space:]]*["'\'']DISALLOW_FILE_MODS["'\''][[:space:]]*,[[:space:]]*true[[:space:]]*\)[[:space:]]*;[[:space:]]*$/) next
print
}
' "$cfg" > "$tmp"
cp -a "$cfg" "$cfg.pre-revert.$(date +%Y%m%dT%H%M%S)"
mv -f "$tmp" "$cfg"
}
for site_path in "$BASE_DIR"/*; do
[[ -d "$site_path" ]] || continue
site_name="$(basename "$site_path")"
[[ "$site_name" == "$EXCLUDE_DIR" ]] && continue
is_wp_root "$site_path" || continue
cfg="$site_path/wp-config.php"
echo "Revert: $site_name"
if ! restore_latest_backup "$cfg"; then
strip_defines "$cfg"
fi
done
echo "Done."