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
+12 -12
View File
@@ -974,13 +974,13 @@ calculate_threat_scores() {
# fi
# Cap at 100
[ $score -gt 100 ] && score=100
[ "${score:-0}" -gt 100 ] && score=100
# Only output IPs with score > 0
[ $score -gt 0 ] && echo "$score|$ip|$req_count"
[ "${score:-0}" -gt 0 ] && echo "$score|$ip|$req_count"
# Track in centralized IP reputation database (background process)
if [ $score -gt 0 ]; then
if [ "${score:-0}" -gt 0 ]; then
(
# Update IP with hit count
increment_ip_hits "$ip" "$req_count" >/dev/null 2>&1
@@ -1178,8 +1178,8 @@ generate_report() {
echo ""
alert_count=$((alert_count + 1))
fi
if [ $alert_count -eq 0 ]; then
if [ "${alert_count:-0}" -eq 0 ]; then
print_success "No critical threats detected"
fi
@@ -1256,7 +1256,7 @@ generate_report() {
hour=$(echo "$line" | awk '{print $2}')
# Create simple bar chart
bar_width=$((count * 10 / max_bot_traffic))
[ $bar_width -eq 0 ] && [ $count -gt 0 ] && bar_width=1
[ "${bar_width:-0}" -eq 0 ] && [ "${count:-0}" -gt 0 ] && bar_width=1
bar=$(printf '█%.0s' $(seq 1 $bar_width))
spaces=$(printf '░%.0s' $(seq 1 $((10 - bar_width))))
@@ -1314,7 +1314,7 @@ generate_report() {
echo "1. Highest Risk IPs (by threat score):"
if [ -s "$TEMP_DIR/threat_scores.txt" ]; then
counter=1
while read -r line && [ $counter -le 10 ]; do
while read -r line && [ "${counter:-0}" -le 10 ]; do
score=$(echo "$line" | cut -d'|' -f1)
ip=$(echo "$line" | cut -d'|' -f2)
count=$(echo "$line" | cut -d'|' -f3)
@@ -1362,10 +1362,10 @@ generate_report() {
echo " No significant threats detected "
fi
echo ""
echo "2. Top Aggressive Bots:"
counter=1
while read -r line && [ $counter -le 5 ]; do
while read -r line && [ "${counter:-0}" -le 5 ]; do
count=$(echo "$line" | awk '{print $1}')
bot=$(echo "$line" | awk '{$1=""; print $0}' | xargs)
@@ -1447,12 +1447,12 @@ generate_report() {
else
echo " None detected "
fi
# TOP 5 TARGETED SITES
print_header "TOP 5 TARGETED SITES (with risk breakdown)"
counter=1
while read -r line && [ $counter -le 5 ]; do
while read -r line && [ "${counter:-0}" -le 5 ]; do
count=$(echo "$line" | awk '{print $1}')
domain=$(echo "$line" | awk '{print $2}')