Files
wevads-platform/scripts/sidebar_manager.sh
2026-02-26 04:53:11 +01:00

338 lines
8.5 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Sidebar Manager - Outil automatique de gestion sidebar WEVADS
SIDEBAR="/opt/wevads/public/includes/sidebar.php"
DOCS="/opt/wevads/docs/SIDEBAR_MANAGEMENT.md"
# Couleurs
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_header() {
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE}🎨 SIDEBAR MANAGER - WEVADS${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
}
cmd_info() {
print_header
echo -e "${GREEN}📊 INFORMATIONS SYSTÈME SIDEBAR${NC}"
echo ""
# Fichier sidebar
if [ -f "$SIDEBAR" ]; then
echo -e "✅ Sidebar existe: $SIDEBAR"
echo " Taille: $(du -h $SIDEBAR | cut -f1)"
echo " Modifié: $(stat -c %y $SIDEBAR | cut -d. -f1)"
else
echo -e "${RED}❌ Sidebar NON TROUVÉ: $SIDEBAR${NC}"
return 1
fi
echo ""
# Backups disponibles
BACKUPS=$(ls -1t ${SIDEBAR}.backup* 2>/dev/null | wc -l)
echo "💾 Backups disponibles: $BACKUPS"
if [ $BACKUPS -gt 0 ]; then
echo " Dernier: $(ls -1t ${SIDEBAR}.backup* 2>/dev/null | head -1)"
fi
echo ""
# Menus présents
echo "📋 Menus dans sidebar:"
grep -o '<span>[^<]*</span>' "$SIDEBAR" | sed 's/<span>//g' | sed 's/<\/span>//g' | sort -u | sed 's/^/ • /'
echo ""
# Pages qui incluent sidebar
echo "📄 Pages incluant sidebar:"
grep -l "sidebar.php" /opt/wevads/public/*.php 2>/dev/null | xargs basename | sed 's/^/ • /'
echo ""
# Permissions
PERMS=$(stat -c %a "$SIDEBAR")
OWNER=$(stat -c %U:%G "$SIDEBAR")
echo "🔐 Permissions: $PERMS ($OWNER)"
if [ "$PERMS" != "644" ]; then
echo -e " ${YELLOW}⚠️ Recommandé: 644${NC}"
fi
echo ""
}
cmd_add() {
print_header
if [ -z "$1" ]; then
echo -e "${RED}❌ Usage: sidebar add 'Nom|URL|Icon|Parent'${NC}"
echo ""
echo "Exemples:"
echo " sidebar add 'Test Menu|/test.php|fa-star|'"
echo " sidebar add 'Sub Menu|/sub.php|fa-circle|Brain'"
return 1
fi
IFS='|' read -r NAME URL ICON PARENT <<< "$1"
echo " Ajout nouveau menu:"
echo " Nom: $NAME"
echo " URL: $URL"
echo " Icône: $ICON"
echo " Parent: ${PARENT:-Menu principal}"
echo ""
# Backup
cp "$SIDEBAR" "${SIDEBAR}.backup_$(date +%s)"
echo "✅ Backup créé"
# Génération code
if [ -z "$PARENT" ]; then
# Menu principal
CODE=" <li class=\"nav-item\">\n <a class=\"nav-link\" href=\"$URL\">\n <i class=\"fas $ICON\"></i>\n <span>$NAME</span>\n </a>\n </li>"
else
# Sous-menu
CODE=" <li>\n <a href=\"$URL\">\n <i class=\"fas $ICON\"></i>\n $NAME\n </a>\n </li>"
fi
# Insertion
if [ -z "$PARENT" ]; then
sed -i "/Brain Menu/a\\$CODE" "$SIDEBAR"
else
sed -i "/$PARENT/,/\/ul/s|</ul>|$CODE\n </ul>|" "$SIDEBAR"
fi
echo "✅ Menu ajouté à sidebar.php"
# Restart Apache
systemctl restart apache2 2>/dev/null
echo "✅ Apache redémarré"
echo ""
echo -e "${GREEN}🎉 Menu '$NAME' ajouté avec succès !${NC}"
echo ""
}
cmd_fix() {
print_header
echo "🔧 FIX AUTOMATIQUE SIDEBAR"
echo ""
# 1. Vérifier sidebar existe
if [ ! -f "$SIDEBAR" ]; then
echo -e "${RED}❌ Sidebar n'existe pas !${NC}"
return 1
fi
# 2. Fixer permissions
echo "📝 Fix permissions..."
chown www-data:www-data "$SIDEBAR" 2>/dev/null
chmod 644 "$SIDEBAR"
echo "✅ Permissions: 644 www-data:www-data"
# 3. Ajouter inclusion dans pages principales
echo ""
echo "📄 Fix inclusion dans pages..."
for page in dashboard.php control-hub.php; do
PAGE_PATH="/opt/wevads/public/$page"
if [ -f "$PAGE_PATH" ]; then
if ! grep -q "sidebar.php" "$PAGE_PATH"; then
sed -i '1i <?php include("includes/sidebar.php"); ?>' "$PAGE_PATH"
echo "✅ Inclusion ajoutée: $page"
else
echo " Déjà inclus: $page"
fi
fi
done
# 4. Restart Apache
echo ""
echo "🔄 Restart Apache..."
systemctl restart apache2
echo "✅ Apache redémarré"
echo ""
echo -e "${GREEN}✅ Fix terminé !${NC}"
echo ""
}
cmd_verify() {
print_header
echo "🔍 VÉRIFICATION SIDEBAR"
echo ""
ERRORS=0
# Check 1: Sidebar existe
if [ -f "$SIDEBAR" ]; then
echo "✅ Sidebar existe"
else
echo -e "${RED}❌ Sidebar manquant${NC}"
((ERRORS++))
fi
# Check 2: Permissions
PERMS=$(stat -c %a "$SIDEBAR" 2>/dev/null)
if [ "$PERMS" = "644" ]; then
echo "✅ Permissions correctes (644)"
else
echo -e "${YELLOW}⚠️ Permissions: $PERMS (recommandé: 644)${NC}"
fi
# Check 3: Inclusions
INCLUDED=$(grep -l "sidebar.php" /opt/wevads/public/{dashboard,control-hub}.php 2>/dev/null | wc -l)
if [ $INCLUDED -ge 1 ]; then
echo "✅ Sidebar inclus dans $INCLUDED page(s)"
else
echo -e "${RED}❌ Sidebar non inclus dans les pages${NC}"
((ERRORS++))
fi
# Check 4: Syntaxe PHP
if php -l "$SIDEBAR" > /dev/null 2>&1; then
echo "✅ Syntaxe PHP valide"
else
echo -e "${RED}❌ Erreur syntaxe PHP${NC}"
((ERRORS++))
fi
# Check 5: Menu Brain existe
if grep -q "Brain" "$SIDEBAR"; then
echo "✅ Menu Brain présent"
else
echo -e "${YELLOW}⚠️ Menu Brain manquant${NC}"
fi
echo ""
if [ $ERRORS -eq 0 ]; then
echo -e "${GREEN}✅ Aucune erreur détectée !${NC}"
else
echo -e "${RED}$ERRORS erreur(s) détectée(s)${NC}"
echo ""
echo "💡 Lancez: sidebar fix"
fi
echo ""
}
cmd_backup() {
print_header
echo "💾 CRÉATION BACKUP"
echo ""
BACKUP="${SIDEBAR}.backup_$(date +%s)"
cp "$SIDEBAR" "$BACKUP"
echo "✅ Backup créé: $BACKUP"
echo ""
}
cmd_restore() {
print_header
echo "♻️ RESTAURATION BACKUP"
echo ""
# Lister backups
BACKUPS=($(ls -1t ${SIDEBAR}.backup* 2>/dev/null))
if [ ${#BACKUPS[@]} -eq 0 ]; then
echo -e "${RED}❌ Aucun backup trouvé${NC}"
return 1
fi
echo "Backups disponibles:"
for i in "${!BACKUPS[@]}"; do
DATE=$(stat -c %y "${BACKUPS[$i]}" | cut -d. -f1)
echo " [$i] ${BACKUPS[$i]} - $DATE"
done
echo ""
read -p "Numéro du backup à restaurer [0]: " NUM
NUM=${NUM:-0}
if [ -f "${BACKUPS[$NUM]}" ]; then
cp "${BACKUPS[$NUM]}" "$SIDEBAR"
echo "✅ Restauré depuis: ${BACKUPS[$NUM]}"
systemctl restart apache2
echo "✅ Apache redémarré"
else
echo -e "${RED}❌ Backup invalide${NC}"
return 1
fi
echo ""
}
cmd_help() {
print_header
cat << 'HELP'
sidebar info → Afficher infos système sidebar
sidebar add MENU → Ajouter un nouveau menu
sidebar fix → Fixer automatiquement la sidebar
sidebar verify → Vérifier configuration
sidebar backup → Créer un backup
sidebar restore → Restaurer un backup
sidebar help → Afficher cette aide
sidebar doc → Voir documentation complète
# Ajouter menu simple
sidebar add 'Mon Menu|/test.php|fa-star|'
# Ajouter sous-menu dans Brain
sidebar add 'Test|/test.php|fa-circle|Brain'
# Fix automatique
sidebar fix
# Vérifier tout
sidebar verify
HELP
}
cmd_doc() {
if [ -f "$DOCS" ]; then
less "$DOCS"
else
echo -e "${RED}❌ Documentation non trouvée: $DOCS${NC}"
fi
}
# Main
case "$1" in
info)
cmd_info
;;
add)
cmd_add "$2"
;;
fix)
cmd_fix
;;
verify)
cmd_verify
;;
backup)
cmd_backup
;;
restore)
cmd_restore
;;
doc)
cmd_doc
;;
help|*)
cmd_help
;;
esac