Fix critical bugs found by QA tool: grep -F, integer comparisons, function exports

CRITICAL FIXES (8 → 0):
- Fix all 8 grep -F with regex anchors bugs
  - lib/reference-db.sh:420
  - lib/user-manager.sh:195, 254, 258, 317, 583, 590
  - modules/website/500-error-tracker.sh:313
  - Changed grep -F to grep for proper regex support

HIGH PRIORITY FIXES:
- Add 36 function exports for subshell availability
  - lib/system-detect.sh: 10 functions
  - lib/common-functions.sh: 26 functions

- Fix 27 integer comparisons with ${var:-0} validation
  - lib/common-functions.sh: 7 fixes
  - lib/ip-reputation.sh: 3 fixes
  - lib/user-manager.sh: 4 fixes
  - launcher.sh: 7 fixes
  - modules/website/500-error-tracker.sh: 1 fix
  - modules/performance/hardware-health-check.sh: 2 fixes
  - modules/performance/mysql-query-analyzer.sh: 1 fix
  - modules/security/bot-analyzer.sh: 11 fixes

- Change exit to return in library file
  - lib/common-functions.sh:246 (require_root function)

DOCUMENTATION:
- Add [DEVELOPMENT_WORKFLOW] section to REFDB_FORMAT.txt
  - Document QA script as "third option" for validation
  - Add recommended workflow for using QA tool
  - Document all 16 checks (11 bug + 5 performance)

IMPACT:
- Before: 41 issues (8 CRITICAL + 13 HIGH + 9 MEDIUM + 11 LOW)
- After: 30 issues (0 CRITICAL + 10 HIGH + 9 MEDIUM + 11 LOW)
- 27% reduction, all CRITICAL bugs eliminated

QA Tool: bash /tmp/toolkit-qa-check.sh /root/server-toolkit
This commit is contained in:
cschantz
2025-12-03 19:41:59 -05:00
parent 341df8e91d
commit cd38a457a4
10 changed files with 477 additions and 34 deletions
+33 -5
View File
@@ -207,7 +207,7 @@ format_bytes() {
local unit=0
local size=$bytes
while [ $size -gt 1024 ] && [ $unit -lt 4 ]; do
while [ "${size:-0}" -gt 1024 ] && [ "${unit:-0}" -lt 4 ]; do
size=$((size / 1024))
unit=$((unit + 1))
done
@@ -223,11 +223,11 @@ format_duration() {
local minutes=$(((seconds % 3600) / 60))
local secs=$((seconds % 60))
if [ $days -gt 0 ]; then
if [ "${days:-0}" -gt 0 ]; then
echo "${days}d ${hours}h ${minutes}m"
elif [ $hours -gt 0 ]; then
elif [ "${hours:-0}" -gt 0 ]; then
echo "${hours}h ${minutes}m ${secs}s"
elif [ $minutes -gt 0 ]; then
elif [ "${minutes:-0}" -gt 0 ]; then
echo "${minutes}m ${secs}s"
else
echo "${secs}s"
@@ -243,7 +243,7 @@ command_exists() {
require_root() {
if [ "$EUID" -ne 0 ]; then
print_error "This script must be run as root"
exit 1
return 1
fi
}
@@ -299,3 +299,31 @@ load_config() {
source "$config_file"
fi
}
# Export all functions for use in subshells and sourced scripts
export -f print_banner
export -f print_section
export -f print_info
export -f print_success
export -f print_warning
export -f print_error
export -f print_critical
export -f print_alert
export -f print_header
export -f cecho
export -f press_enter
export -f show_banner
export -f show_progress
export -f finish_progress
export -f show_terminal_info
export -f create_temp_session
export -f confirm
export -f format_bytes
export -f format_duration
export -f command_exists
export -f require_root
export -f safe_append
export -f log_message
export -f get_script_dir
export -f get_toolkit_dir
export -f load_config
+3 -3
View File
@@ -139,8 +139,8 @@ update_ip_reputation() {
rep_score=$((rep_score + score_delta))
# Cap reputation score at 0-100
[ $rep_score -lt 0 ] && rep_score=0
[ $rep_score -gt 100 ] && rep_score=100
[ "${rep_score:-0}" -lt 0 ] && rep_score=0
[ "${rep_score:-0}" -gt 100 ] && rep_score=100
# Merge attack flags (bitwise OR)
attack_flags=$((attack_flags | new_attack_flags))
@@ -602,7 +602,7 @@ record_ip_ban() {
# Increase reputation score for being banned
rep_score=$((rep_score + 10))
[ $rep_score -gt 100 ] && rep_score=100
[ "${rep_score:-0}" -gt 100 ] && rep_score=100
# Update notes
notes="Banned ${ban_count}x (${duration}h): $reason"
+1 -1
View File
@@ -417,7 +417,7 @@ build_wordpress_section() {
# Check for common domain folder patterns
if [[ "$path_after_home" == public_html ]]; then
# This is the primary domain - get it from user info
domain=$(grep -F "USER|${username}|" "$SYSREF_DB" 2>/dev/null | cut -d'|' -f3 || true)
domain=$(grep "USER|${username}|" "$SYSREF_DB" 2>/dev/null | cut -d'|' -f3 || true)
elif [[ "$path_after_home" =~ ^public_html/(.+) ]]; then
# Could be subdomain or subdirectory - extract folder name
local folder=$(echo "$path_after_home" | cut -d'/' -f2)
+12
View File
@@ -509,6 +509,18 @@ initialize_system_detection() {
export SYS_DETECTION_COMPLETE="yes"
}
# Export all functions for use in subshells and sourced scripts
export -f detect_control_panel
export -f detect_os
export -f detect_web_server
export -f detect_database
export -f detect_php_versions
export -f detect_cloudflare
export -f detect_firewall
export -f get_system_resources
export -f show_system_info
export -f initialize_system_detection
# Auto-initialize if not already done (when sourced)
if [ -z "${SYS_DETECTION_COMPLETE:-}" ]; then
# Just run initialization - output suppression was breaking variable assignment