From 813c0beeacf986afeb220eabb313b5a242045eae Mon Sep 17 00:00:00 2001 From: Frogg Date: Thu, 7 May 2026 02:19:36 +0200 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20et=20Refactorisation=20du?= =?UTF-8?q?=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 777-welcome.sh | 82 +++++++--------- TODO.md | 45 +++++++++ config/config_cmd.sh | 33 +++++++ config/config_colors.sh | 24 +++++ config/config_conf.sh | 43 ++++++++ config/config_services.sh | 28 ++++++ func/common.sh | 24 +++++ func/mail.sh | 69 +++++++++++++ func/message.sh | 42 ++++++++ func/message_display.sh | 128 ++++++++++++++++++++++++ func/network.sh | 27 +++++ func/services_check.sh | 130 ++++++++++++++++++++++++ func/system_info.sh | 61 ++++++++++++ inc/alias.sh | 53 ++++++++++ inc/colors.sh | 18 ---- inc/infos.sh | 10 +- inc/mail_connect.sh | 85 +++------------- inc/ps1.sh | 106 +++++++++++++------- inc/services.sh | 190 +++++------------------------------- inc/vars.sh | 75 -------------- inc/warnings.sh | 78 +++++++++------ info/cmd | 49 +++++----- info/colors | 40 ++++++++ info/conf | 57 +++++------ inc/tool.sh => tool/ipv6.sh | 0 25 files changed, 986 insertions(+), 511 deletions(-) create mode 100644 TODO.md create mode 100644 config/config_cmd.sh create mode 100644 config/config_colors.sh create mode 100644 config/config_conf.sh create mode 100644 config/config_services.sh create mode 100644 func/common.sh create mode 100644 func/mail.sh create mode 100644 func/message.sh create mode 100644 func/message_display.sh create mode 100644 func/network.sh create mode 100644 func/services_check.sh create mode 100644 func/system_info.sh create mode 100644 inc/alias.sh delete mode 100644 inc/colors.sh delete mode 100644 inc/vars.sh create mode 100644 info/colors rename inc/tool.sh => tool/ipv6.sh (100%) diff --git a/777-welcome.sh b/777-welcome.sh index 28e58ba..5b70683 100755 --- a/777-welcome.sh +++ b/777-welcome.sh @@ -1,76 +1,62 @@ #!/bin/bash -# NETTOYAGE +WELCOME_SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" -clear -# INC -. /etc/profile.d/inc/colors.sh -. /etc/profile.d/inc/vars.sh +#region INCLUDES +. "${WELCOME_SCRIPT_PATH}/config/config_colors.sh" +. "${WELCOME_SCRIPT_PATH}/inc/vars.sh" +. "${WELCOME_SCRIPT_PATH}/func/common.sh" +. "${WELCOME_SCRIPT_PATH}/func/message_display.sh" +. "${WELCOME_SCRIPT_PATH}/func/system_info.sh" +#endregion -# LINUX TOOL -. /etc/profile.d/inc/tool.sh +################## +### DASHBOARD ### +################## -################ -### SHORTCUT ### -################ - -#F_DAT="${WHITE}$(date +"%A, %e %B %Y, %r")${NC}" -F_DAT="${WHITE}$(LC_TIME=fr_FR.UTF-8 date +"%A, %e %B %Y, %r")${NC}" -F_IPS="${YELLOW}IP Addresses.: ${WHITE}${IP}" -F_UPT="${YELLOW}Uptime.......: ${WHITE}${UPTIME}" -F_MEM="${YELLOW}Memory.......: ${WHITE}${MEMUSED} / ${MEMTOTAL} Go" -F_LOD="${YELLOW}Load Averages: ${WHITE}${ONE}, ${FIVE}, ${FIFTEEN} (1, 5, 15 min)" -F_VER="${WHITE} ${VERSION}" -F_BAR_MEM="${YELLOW}Memory.......: $(draw_bar $M_PCT ${V1})" -F_BAR_DSK="${YELLOW}Disk Usage...: $(draw_bar $D_PCT ${J1})" -F_USR="${YELLOW}Nb acc user..: ${WHITE}${NBUSERS}" - -###################### -### CUSTOM MESSAGE ### -###################### - -echo -e "${CYAN} ==[ You are connected to ${WHITE}$FULLNAME${CYAN} ]== -${GREEN} _ __ _ -${GREEN} ((-)).--.((-)) ${F_DAT} -${GREEN} / '' \\ ${F_VER} -${GREEN} ( \______/ ) -${GREEN} \ ( ) / ${F_IPS} -${GREEN} / /~~~~~~~~\ \ ${F_UPT} -${GREEN} /~~\/ / \ \/~~\ ${F_MEM} -${GREEN}( ( ( ) ) ) ${F_LOD} -${GREEN} \ \ \ \ / / / / ${F_BAR_MEM} -${GREEN} _\ \/ \.______./ \/ /_ ${F_BAR_DSK} -${GREEN} ___/ /\__________/\ \___ ${F_USR}" +display_dashboard ################# ### WARNINGS ### ################# -. /etc/profile.d/inc/warnings.sh - - echo -e "${GREEN}======================================================================${NONE}" +. "${WELCOME_SCRIPT_PATH}/inc/warnings.sh" ################# ### SERVICES ### ################# -. /etc/profile.d/inc/services.sh +. "${WELCOME_SCRIPT_PATH}/inc/services.sh" ############## ### INFOS ### ############## -. /etc/profile.d/inc/infos.sh +. "${WELCOME_SCRIPT_PATH}/inc/infos.sh" -##################### -### BASH DISPLAY ### -##################### +################### +### BASH ALIAS ### +################### -. /etc/profile.d/inc/ps1.sh +. "${WELCOME_SCRIPT_PATH}/inc/alias.sh" + +################# +### BASH PS1 ### +################# + +. "${WELCOME_SCRIPT_PATH}/inc/ps1.sh" ################## ### SEND MAIL ### ################## -. /etc/profile.d/inc/mail_connect.sh +. "${WELCOME_SCRIPT_PATH}/inc/mail_connect.sh" + +################ +### INSTALL ### +################ + +if [[ $HAS_WELCOME_CONF_ERROR -eq 1 ]];then + msg_error "TODO PROPOSER UNE INSTALL DE CE QUI MANQUE" +fi \ No newline at end of file diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..c227fad --- /dev/null +++ b/TODO.md @@ -0,0 +1,45 @@ +# ZABBIX +- config Proxmox (dl le template) +- config ndv +- config gita + + + + +# SCRIPT +- VARIABLE SUPER GLOBALE POUR EVITER LE MAIL A CHAQUE WELCOME +- verifier si git est installé +- verifier si Zabbix agent est installé +- n'afficher que les services présents +- ajouter le service de la base de gitea +- faire le redirect port 80 +- ajouter https sur gitea +- faire la connexion git sans faire pass a chaque fois +- faire un menu tool d install + - dont : + - confg mail + - conf ipv6 + - conf ip + - conf nom de machine + - menu qui propose des choix + +# SERVER +- mettre les scripts sur tous les linux + +ajouter ADMIN_MAIL dans /etc/environment +ADMIN_MAIL="admin@frogg.fr" + +# LIB A DIRE D INSTALLER : +jq pour les json en bash +ncdu + +# config de ADMIN_MAIL dans le ENV + +faire une page demo des couleurs + + + +>> rename la machine +hostnamectl set-hostname gitea +> /etc/hosts (changer le nom de la machine) +> > /etc/hostname (changer le nom de la machine) \ No newline at end of file diff --git a/config/config_cmd.sh b/config/config_cmd.sh new file mode 100644 index 0000000..b032229 --- /dev/null +++ b/config/config_cmd.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# shellcheck disable=SC2034 + +#region JSON +CMD_LIST_CONFIG_JSON=$(cat <= 1024 et qu'il reste des unités + while [[ $size -ge 1024 ]] && [[ $unit_idx -lt $((${#units[@]} - 1)) ]]; do + # On calcule le reste pour avoir une décimale (multiplication par 100) + # On simule scale=2 : (taille * 100 / 1024) + local total_centiemes=$(( size * 100 / 1024 )) + size=$(( total_centiemes / 100 )) + decimal=$(( total_centiemes % 100 )) + ((unit_idx++)) + done + + # Formatage de la sortie + if [[ $decimal -eq 0 ]]; then + echo "${size}${units[$unit_idx]}" + else + # On s'assure que le decimal a toujours 2 chiffres (ex: 05 au lieu de 5) + printf "%d.%02d%s\n" "$size" "$decimal" "${units[$unit_idx]}" | sed 's/\.00//; s/0$//' + fi +} \ No newline at end of file diff --git a/func/mail.sh b/func/mail.sh new file mode 100644 index 0000000..894eb2b --- /dev/null +++ b/func/mail.sh @@ -0,0 +1,69 @@ +send_mail() { + local to="$1" + local subject="$2" + local body="$3" + local mail_backend="none" + + # Détection du backend + if command -v mail >/dev/null 2>&1; then + mail_backend="mail" + elif command -v sendmail >/dev/null 2>&1; then + mail_backend="sendmail" + elif command -v msmtp >/dev/null 2>&1; then + mail_backend="msmtp" + fi + + case "$mail_backend" in + mail) + echo "$body" | mail -s "$subject" "$to" + ;; + sendmail|msmtp) + { + echo "To: $to" + echo "Subject: $subject" + echo "Content-Type: text/plain; charset=UTF-8" + echo "" + echo "$body" + } | "$mail_backend" -t + ;; + *) + msg_error "No mail system found (mail, sendmail or msmtp)" + return 1 + ;; + esac +} + +send_login_mail() { + + if [[ ${HAS_WELCOME_CONF_ERROR} -eq 1 ]]; then + return; + fi + + if [[ -z "${ADMIN_MAIL}" ]]; then + msg_error "ADMIN_MAIL is not defined in /etc/environment" + HAS_WELCOME_CONF_ERROR=1 + return 1 # ou exit 1 selon si c'est dans une fonction ou un script + fi + # Protection contre les appels multiples + if [[ ${CON_MAIL_DONE:-0} -eq 1 ]]; then + return + fi + export CON_MAIL_DONE=1 + + local user_ip="$1" + local user_name="$2" + local host_name="$3" + local loc_info subject body + + # Capture de la localisation + loc_info=$(getIpLocation "$user_ip") + + subject="[INFO] $user_name connected on $host_name" + body="User: $user_name +Host: $host_name +IP: $user_ip +Location: $loc_info +Date: $(date '+%Y-%m-%d %H:%M:%S')" + + send_mail "$ADMIN_MAIL" "$subject" "$body" +} \ No newline at end of file diff --git a/func/message.sh b/func/message.sh new file mode 100644 index 0000000..cdfd704 --- /dev/null +++ b/func/message.sh @@ -0,0 +1,42 @@ +msg_status_text() +{ + local type="$1" msg="$2" + + case "$type" in + ok|success) + echo -e "${COLOR_GREEN}✅ ${msg}${NONE}" + ;; + warn|warning) + echo -e "${COLOR_YELLOW}⚡ ${msg}${NONE}" + ;; + error|err) + echo -e "${COLOR_RED}❌ ${msg}${NONE}" + ;; + info|inf) + echo -e "${COLOR_BLUE}ℹ ${msg}${NONE}" + ;; + *) + echo -e "${msg}" + ;; + esac +} + + +msg_success() { + msg_status_text success "$1" +} + +# Fonction Erreur (Cross) +msg_error() { + msg_status_text error "$1" +} + +# Fonction Warning (Exclamation) +msg_warning() { + msg_status_text warning "$1" +} + +# Fonction Info (i) +msg_info() { + msg_status_text info "$1" +} diff --git a/func/message_display.sh b/func/message_display.sh new file mode 100644 index 0000000..a450e0d --- /dev/null +++ b/func/message_display.sh @@ -0,0 +1,128 @@ +display_line() +{ + local width=27 label_with_dots formatted_label + + # On calcule combien de points ajouter (Largeur - longueur du label) + # On utilise une astuce simple : on ajoute 27 points au label et on coupe à 27. + label_with_dots="${1}............................" + formatted_label="${label_with_dots:0:$width}" + + # 4. Affichage + printf "${COLOR_YELLOW}%s: ${COLOR_WHITE}%s${NONE}\n" "$formatted_label" "$2" +} + +display_conditional_list() +{ + clear + + # On boucle sur chaque section du JSON + echo "$1" | jq -c '.[]' | while read -r section; do + + local label cmd bin title items has_printed_title=false + + title=$(echo "$section" | jq -r '.section') + items=$(echo "$section" | jq -c '.items[]') + + # On boucle sur les items de la section + while read -r item; do + + label=$(echo "$item" | jq -r '.label') + cmd=$(echo "$item" | jq -r '.cmd') + bin=$(echo "$item" | jq -r '.bin // empty') + + # Vérification de la condition (binaire) + if [[ -n "$bin" ]] && ! command -v "$bin" &> /dev/null; then + continue + fi + + # Affichage du titre une seule fois si au moins un item est valide + if [ "$has_printed_title" = false ]; then + echo -e "\n${COLOR_CYAN}[ $title ]${NONE}" + has_printed_title=true + fi + + display_line "$label" "$cmd" + + done <<< "$items" + done +} + +draw_bar() { + local pct=$1 + # Nettoyage du point si présent (arrondi simple) + [[ "$pct" == *"."* ]] && pct=${pct%.*} + + # Sécurité pour ne pas dépasser 100 ou descendre sous 0 + ((pct > 100)) && pct=100 + ((pct < 0)) && pct=0 + + # Sélection automatique de la couleur + local color="${COLOR_BLUE}" + if (( pct >= 90 )); then color="${COLOR_RED}" + elif (( pct >= 70 )); then color="${COLOR_ORANGE}" + elif (( pct >= 50 )); then color="${COLOR_YELLOW}" + elif (( pct >= 30 )); then color="${COLOR_LIGHT_GREEN}" + elif (( pct >= 15 )); then color="${COLOR_GREEN}" + fi + + local size=20 + local filled=$((pct * size / 100)) + local empty=$((size - filled)) + + # Affichage de la barre + printf "[" + echo -ne "${color}" + for ((i=0; i/dev/null 2>&1; then + # Appel API ipinfo.io + geo=$(curl -s "https://ipinfo.io/${user_ip}/json") + + if command -v jq >/dev/null 2>&1; then + # Utilisation de JQ pour un parsing robuste + echo "$geo" | jq -r '"\(.city), \(.country) (ISP: \(.org))"' + else + # Fallback grep/cut si JQ absent + city=$(echo "$geo" | grep '"city"' | cut -d'"' -f4) + country=$(echo "$geo" | grep '"country"' | cut -d'"' -f4) + org=$(echo "$geo" | grep '"org"' | cut -d'"' -f4) + echo "$city, $country (ISP: $org)" + fi + else + echo "Unknown (curl missing)" + fi + fi +} \ No newline at end of file diff --git a/func/services_check.sh b/func/services_check.sh new file mode 100644 index 0000000..1946238 --- /dev/null +++ b/func/services_check.sh @@ -0,0 +1,130 @@ +check_service() +{ + local svc="$1" label="$2" status sudo_cmd="" + + # 1. On vérifie d'abord si le binaire existe + if ! command -v "$svc" &> /dev/null; then + return # Pas installé, on ne dit rien + fi + + # On vérifie si l'utilisateur est root ou s'il peut utiliser sudo sans mot de passe + if command -v sudo >/dev/null && sudo -n true 2>/dev/null; then + sudo_cmd="sudo -n" + fi + + # CAN systemctl ? + if ! command -v systemctl >/dev/null 2>&1; then + status=$(msg_status_text error "systemctl indisponible") + display_line "$label" "$status" + return + fi + + # Check availability + if $sudo_cmd systemctl is-active --quiet "$svc" 2>/dev/null; then + status=$(msg_status_text success "actif") + + elif $sudo_cmd systemctl status "$svc" >/dev/null 2>&1; then + status=$(msg_status_text error "arrêté") + + else + # If installed but not a services + status=$(msg_status_text success "installé") + fi + + display_line "$label" "$status" +} + + +get_systemd_status() +{ + local failed_output failed_count status + + # On capture la sortie ET on vérifie si la commande réussit + # 2>/dev/null est crucial ici pour ne pas polluer l'affichage + if failed_output=$(systemctl --failed --no-legend --no-pager 2>/dev/null); then + # La commande a fonctionné, on compte les lignes vides ou non + failed_count=$(echo "$failed_output" | grep -c '[^[:space:]]') + + if [ "$failed_count" -gt 0 ]; then + status=$(msg_status_text error "État critique (${failed_count} problème(s))") + else + status=$(msg_status_text success "système OK") + fi + else + # La commande a échoué (probablement un problème de sudo/permissions) + status=$(msg_status_text warning "Erreur accès (relancer avec sudo)") + fi + + display_line "Systemd" "$status" +} + + +get_fail2ban_status() +{ + local status jails count total=0 + + if ! command -v fail2ban-client >/dev/null 2>&1; then + status=$(msg_status_text error "non installé") + display_line "Fail2Ban" "$status" + return + fi + + if ! fail2ban-client ping >/dev/null 2>&1; then + status=$(msg_status_text error "service indisponible") + display_line "Fail2Ban" "$status" + return + fi + + jails=$(fail2ban-client status 2>/dev/null | sed -n 's/.*Jail list:\s*//p' | tr ',' ' ') + + for jail in $jails; do + count=$(fail2ban-client status "$jail" 2>/dev/null | awk '/Currently banned/ {print $NF}') + total=$((total + ${count:-0})) + done + + status=$(msg_status_text success "actif (${total} IPs bannies)") + display_line "Fail2Ban" "$status" +} + +get_apparmor_status() +{ + local enforce status + + if [ ! -d /sys/kernel/security/apparmor ]; then + status=$(msg_status_text error "non disponible") + display_line "AppArmor" "$status" + return + fi + + enforce=$(aa-status 2>/dev/null | awk '/profiles are in enforce mode/ {print $1}') + + if [ -z "$enforce" ] || [ "$enforce" -eq 0 ]; then + status=$(msg_status_text error "aucun profil renforcé") + else + status=$(msg_status_text success "${enforce} profils renforcés") + fi + + display_line "AppArmor" "$status" +} + +get_ufw_status() +{ + local status rules raw + + if ! command -v ufw >/dev/null 2>&1; then + status=$(msg_status_text error "non installé") + display_line "Firewall (UFW)" "$status" + return + fi + + raw=$(ufw status 2>/dev/null | head -n 1) + + if echo "$raw" | grep -q "active"; then + rules=$(ufw status 2>/dev/null | grep -cE "ALLOW|DENY") + status=$(msg_status_text success "actif (${rules} règles)") + else + status=$(msg_status_text error "inactif") + fi + + display_line "Firewall (UFW)" "$status" +} diff --git a/func/system_info.sh b/func/system_info.sh new file mode 100644 index 0000000..a16bf69 --- /dev/null +++ b/func/system_info.sh @@ -0,0 +1,61 @@ +# shellcheck disable=SC2034 + +get_os_info() { + local desc="" + if [ -f /etc/lsb-release ]; then source /etc/lsb-release; desc=$DISTRIB_DESCRIPTION; fi + [[ -z "$desc" && -x /usr/bin/lsb_release ]] && desc=$(lsb_release -s -d) + local re='(.*\()(.*)(\).*)' + if [[ $desc =~ $re ]]; then + F_VER=$(printf "%s%s%s%s%s" "${BASH_REMATCH[1]}" "${COLOR_YELLOW}" "${BASH_REMATCH[2]}" "${COLOR_WHITE}" "${BASH_REMATCH[3]}") + else + F_VER="${COLOR_WHITE}${desc}" + fi +} + +get_hardware_info() { + local mem_ko ram_pretty disk_ko disk_pretty + # RAM Totale (on la récupère en Ko dans /proc/meminfo) + mem_ko=$(awk '/MemTotal/ {print $2}' /proc/meminfo) + ram_pretty=$(format_size "$mem_ko") + + # DISQUE Total (on le récupère en Ko avec df -k) + disk_ko=$(df -k / | awk 'NR==2 {print $2}') + disk_pretty=$(format_size "$disk_ko") + + F_HARD="${COLOR_WHITE}Mem : ${ram_pretty} | Hdd : ${disk_pretty}" +} + +get_network_info() { + F_IPS="${COLOR_WHITE}$(hostname -I)" +} + +get_uptime_info() { + local s + s=$(cut -d. -f1 /proc/uptime) + F_UPT="${COLOR_WHITE}$(printf "%dj %02dh %02dm" $((s/86400)) $((s/3600%24)) $((s/60%60)))" +} + +get_memory_info() { + local m m_tot + m=($(free -m | awk '/Mem:/ {print $2, $3}')) + m_tot=${m[0]} m_use=${m[1]} + M_PCT=$((m_use * 100 / m_tot)) + F_BAR_MEM=$(draw_bar "${M_PCT}") +} + +get_load_info() { + read -r one rest < /proc/loadavg + local cpu_dec=${one#*.} + [[ "$one" == *"."* && "${cpu_dec//0/}" != "" ]] && local val=$((${one%.*} + 1)) || local val=${one%.*} + F_BAR_CPU="$(draw_bar "$val")" +} + +get_disk_info() { + local d + d=$(df / | awk 'NR==2 {print $5}' | sed 's/%//') + F_BAR_DSK="$(draw_bar "$d")" +} + +get_user_info() { + F_USR="${COLOR_WHITE}$(awk -F: '$3 >= 1000 && $7 !~ /(nologin|false)/ {count++} END {print count+1}' /etc/passwd)" +} diff --git a/inc/alias.sh b/inc/alias.sh new file mode 100644 index 0000000..0cf9487 --- /dev/null +++ b/inc/alias.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +#region Shortcut CUSTOM +alias cmd='bash /etc/profile.d/info/cmd' +alias conf='bash /etc/profile.d/info/conf' +alias colors='bash /etc/profile.d/info/colors' +alias welcome='bash /etc/profile.d/777-welcome.sh' +#endregion +#region Shortcut BASICS +alias cls='clear' +alias ll='ls -lah' +alias lh='ls -lisah' +alias ..='cd ..' +alias ...='cd ../..' +alias home='welcome && cd ~' +alias ffs='find / \( -path /proc -o -path /sys -o -path /dev -o -path /run \) -prune -o -type f -iname' +alias ff='sudo find / \( -path /proc -o -path /sys -o -path /dev -o -path /run \) -prune -o -type f -name' +#endregion +#region Shortcut APT +alias update='sudo apt update && sudo apt upgrade -y' +alias install='sudo apt install' +alias remove='sudo apt remove' +#endregion +#region Shortcut DEBUG +alias func='declare -F' +alias grep='grep --color=auto' +alias egrep='egrep --color=auto' +alias fgrep='fgrep --color=auto' +alias ports='netstat -tulanp' +alias psg='ps aux | grep -i' +alias top='htop' +alias cpu='top -o %CPU' +alias mem='top -o %MEM' +alias hdd='ncdu' +#endregion +#region Shortcut NETWORK +alias myip='curl ifconfig.me' +alias localip='ip a' +#endregion +#region Shortcut APACHE +alias wra='systemctl restart apache2' +alias werr='tail -fn 100 /var/log/apache2/error.log' +alias wlog='tail -fn 100 /var/log/apache2/access.log /var/log/apache2/error.log' +#endregion + + + +# Frogg version +#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;34m\][\[\033[01;91m\]\u\[\033[01;34m\]@\[\033[01;91m\]\h\[\033[01;34m\]]\[\033[01;34m\] \w\[\033[01;37m\] >' +# Github https://gist.github.com/justintv/168835 +#PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;36m\] @ \w\[\033[0;32m\]\n$(git branch 2>/dev/null | grep "^*" | colrm 1 2)\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\]\[\033[0m\] ' +# Mixed version +#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;34m\][\[\033[01;91m\]\u\[\033[01;34m\]@\[\033[01;91m\]\h\[\033[01;34m\]]\[\033[01;34m\] \w\[\033[01;37m\] \n$(git branch --show-current 2>/dev/null)\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\]\[\033[0m\] ' diff --git a/inc/colors.sh b/inc/colors.sh deleted file mode 100644 index 5a9ccc1..0000000 --- a/inc/colors.sh +++ /dev/null @@ -1,18 +0,0 @@ - -# SETTING CUSTOM COLOR -NONE="\e[0m" -WHITE="\e[1;37m" -GREEN="\e[1;32m" -RED="\e[0;32;31m" -YELLOW="\e[1;33m" -BLUE="\e[34m" -CYAN="\e[36m" -LIGHT_GREEN="\e[1;32m" -LIGHT_RED="\e[1;31m" - -R1="\e[38;5;196m" # Rouge alerte -G1="\e[38;5;240m" # Gris -V1="\e[38;5;82m" # Vert -J1="\e[38;5;220m" # Or -NC="\e[0m" # Reset - diff --git a/inc/infos.sh b/inc/infos.sh index f24f0f2..b392390 100644 --- a/inc/infos.sh +++ b/inc/infos.sh @@ -1,6 +1,14 @@ +#!/bin/bash + +if [[ -z "${WELCOME_SCRIPT_PATH}" ]]; then + WELCOME_SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &>/dev/null && pwd)" +fi + +. "${WELCOME_SCRIPT_PATH}/config/config_colors.sh" + # Infos echo "" -echo -e "${YELLOW}You can use the commands ${WHITE}cmd ${YELLOW}or ${WHITE}conf ${YELLOW}for more information...${NONE}" +echo -e "${COLOR_YELLOW}You can use the commands ${COLOR_WHITE}cmd ${COLOR_YELLOW}, ${COLOR_WHITE}conf ${COLOR_YELLOW}or ${COLOR_WHITE}colors ${COLOR_YELLOW}for more information...${NONE}" echo "" diff --git a/inc/mail_connect.sh b/inc/mail_connect.sh index 9c85bd4..4bbc903 100755 --- a/inc/mail_connect.sh +++ b/inc/mail_connect.sh @@ -1,79 +1,16 @@ #!/bin/bash -################ -### LOG MAIL ### -################ - -env > /tmp/env_login.txt - -USERIP=$(echo ${SSH_CONNECTION%% *}) - -# On ne check la géo que si l'IP n'est pas locale (RFC1918) -if [[ $USERIP =~ ^192\.168\. || $USERIP =~ ^10\. || $USERIP =~ ^172\. ]]; then - LOC_INFO="Local Network (LAN)" -else - # On récupère tout en un seul appel JSON pour économiser l'API et éviter les erreurs - GEO=$(curl -s ipinfo.io/$USERIP/json) - CITY=$(echo "$GEO" | grep '"city"' | cut -d'"' -f4) - COUNTRY=$(echo "$GEO" | grep '"country"' | cut -d'"' -f4) - ORG=$(echo "$GEO" | grep '"org"' | cut -d'"' -f4) - LOC_INFO="$CITY, $COUNTRY (ISP: $ORG)" +if [[ -z "${WELCOME_SCRIPT_PATH}" ]]; then + WELCOME_SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &>/dev/null && pwd)" + USERIP=$("${SSH_CONNECTION%% *}") + FULLNAME=$(hostname).$(hostname --domain) fi +#region INCLUDES +. "${WELCOME_SCRIPT_PATH}/config/config_colors.sh" +. "${WELCOME_SCRIPT_PATH}/func/message.sh" +. "${WELCOME_SCRIPT_PATH}/func/mail.sh" +. "${WELCOME_SCRIPT_PATH}/func/network.sh" +#endregion -# Détection du backend mail (une seule fois) -if command -v mail >/dev/null 2>&1; then - MAIL_BACKEND="mail" - -elif command -v sendmail >/dev/null 2>&1; then - MAIL_BACKEND="sendmail" - -elif command -v msmtp >/dev/null 2>&1; then - MAIL_BACKEND="msmtp" - -else - echo "ERROR: No mail system available" >&2 - MAIL_BACKEND="none" -fi - - -send_mail() { - local to="$1" - local subject="$2" - local body="$3" - - case "$MAIL_BACKEND" in - mail) - echo "$body" | mail -v -s "$subject" "$to" - ;; - - sendmail) - { - echo "To: $to" - echo "Subject: $subject" - echo "" - echo "$body" - } | sendmail -t - ;; - - msmtp) - { - echo "To: $to" - echo "Subject: $subject" - echo "" - echo "$body" - } | msmtp "$to" - ;; - - *) - echo "No mail backend available" >&2 - return 1 - ;; - esac -} - - -SUBJECT="[INFO] $USER connected on $FULLNAME" -BODY="$USER connected on $FULLNAME from $USERIP - $LOC_INFO" - -send_mail "$ADMIN_MAIL" "$SUBJECT" "$BODY" +send_login_mail "$USERIP" "$USER" "$FULLNAME" \ No newline at end of file diff --git a/inc/ps1.sh b/inc/ps1.sh index da7ae5a..043165f 100644 --- a/inc/ps1.sh +++ b/inc/ps1.sh @@ -1,39 +1,12 @@ -# Shortucts for server config info -alias cmd='bash /etc/profile.d/info/cmd' -alias conf='bash /etc/profile.d/info/conf' -alias welcome='bash /etc/profile.d/custom.sh' -# Shortcuts basics -alias cls='clear' -alias ll='ls -lah' -alias lh='ls -lisah' -alias ..='cd ..' -alias ...='cd ../..' -alias home='welcome && cd ~' -alias ffs='find / \( -path /proc -o -path /sys -o -path /dev -o -path /run \) -prune -o -type f -iname' -alias ff='sudo find / \( -path /proc -o -path /sys -o -path /dev -o -path /run \) -prune -o -type f -name' -#Shortcuts APT -update='sudo apt update && sudo apt upgrade -y' -install='sudo apt install' -remove='sudo apt remove' -#Shortcuts debug -alias func='declare -F' -alias grep='grep --color=auto' -alias egrep='egrep --color=auto' -alias fgrep='fgrep --color=auto' -alias ports='netstat -tulanp' -alias psg='ps aux | grep -i' -alias top='htop' -alias cpu='top -o %CPU' -alias mem='top -o %MEM' -alias hdd='ncdu' -#Shortcut network -alias myip='curl ifconfig.me' -alias localip='ip a' -#Shortcut Apache -alias web-restart='systemctl restart apache2' -alias web-err='tail -fn 100 /var/log/apache2/error.log' -alias web-log='tail -fn 100 /var/log/apache2/access.log /var/log/apache2/error.log' +#!/bin/bash +if [[ -z "${WELCOME_SCRIPT_PATH}" ]]; then + WELCOME_SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &>/dev/null && pwd)" +fi + +#region INCLUDES +. "${WELCOME_SCRIPT_PATH}/config/config_colors.sh" +#endregion # Frogg version #PS1='${debian_chroot:+($debian_chroot)}\[\033[01;34m\][\[\033[01;91m\]\u\[\033[01;34m\]@\[\033[01;91m\]\h\[\033[01;34m\]]\[\033[01;34m\] \w\[\033[01;37m\] >' @@ -41,4 +14,65 @@ alias web-log='tail -fn 100 /var/log/apache2/access.log /var/log/apache2/error.l #PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;36m\] @ \w\[\033[0;32m\]\n$(git branch 2>/dev/null | grep "^*" | colrm 1 2)\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\]\[\033[0m\] ' # Mixed version -PS1='${debian_chroot:+($debian_chroot)}\[\033[01;34m\][\[\033[01;91m\]\u\[\033[01;34m\]@\[\033[01;91m\]\h\[\033[01;34m\]]\[\033[01;34m\] \w\[\033[01;37m\] \n$(git branch --show-current 2>/dev/null)\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\]\[\033[0m\] ' +#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;34m\][\[\033[01;91m\]\u\[\033[01;34m\]@\[\033[01;91m\]\h\[\033[01;34m\]]\[\033[01;34m\] \w\[\033[01;37m\] \n$(git branch --show-current 2>/dev/null)\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\]\[\033[0m\] ' + +# ========================================== +# CONFIGURATION DES COULEURS (Modifie ici !) +# ========================================== + +# Séparateur +SEP="█►" + + +# ========================================== +# LOGIQUE DU PROMPT (Ne pas toucher) +# ========================================== + +get_git_status() { + local branch status current_bg current_color + + branch=$(git branch --show-current 2>/dev/null) + [[ -z "$branch" ]] && return + + current_bg=$COLOR_GREEN_BG + current_color=$COLOR_GREEN + status="✅" + + if [[ -n $(git status --porcelain 2>/dev/null) ]]; then + current_bg=$COLOR_LIGHT_RED_BG + current_color=$COLOR_LIGHT_RED + status="▼" + fi + + echo -ne "${COLOR_DARK_GRAY}${current_bg}${SEP}${COLOR_WHITE} ${status} git:[${branch}]${current_bg}${NONE}${current_color}${SEP}${NONE}" +} + +set_ps1() { + + local EXIT P1 P2 GIT_PART ARROW_C + + EXIT="$?" + + # Segment 1 : User (Bleu) + P1="${COLOR_LIGHT_BLUE_BG}${COLOR_WHITE} <\u@$(hostname -f)>${NONE}" + + # Segment 2 : Chemin (Gris) avec raccord Bleu + P2="${COLOR_LIGHT_BLUE}${COLOR_DARK_GRAY_BG}${SEP}${COLOR_WHITE} \w" + + # Segment 3 : Git + GIT_PART=$(get_git_status) + + if [[ -n "$GIT_PART" ]]; then + PS1="\n${P1}${P2} ${GIT_PART}" + else + PS1="\n${P1}${P2} ${NONE}${COLOR_DARK_GRAY}${SEP}${NONE}" + fi + + # Ligne 2 + ARROW_C=${COLOR_GREEN} + [[ $EXIT != 0 ]] && ARROW_C=${COLOR_LIGHT_RED} + + PS1+="\n${ARROW_C}└─${NONE} " +} + +PROMPT_COMMAND=set_ps1 diff --git a/inc/services.sh b/inc/services.sh index 236d222..8187709 100755 --- a/inc/services.sh +++ b/inc/services.sh @@ -1,173 +1,27 @@ #!/bin/bash -status_text() -{ - local type="$1" - local msg="$2" +if [[ -z "${WELCOME_SCRIPT_PATH}" ]]; then + WELCOME_SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &>/dev/null && pwd)" +fi - case "$type" in - ok|success) - echo "${GREEN}✅ ${msg}${NC}" - ;; - warn|warning) - echo "${YELLOW}⚡ ${msg}${NC}" - ;; - error|err) - echo "${RED}❌ ${msg}${NC}" - ;; - *) - echo "${msg}" - ;; - esac -} +#region INCLUDES +. "${WELCOME_SCRIPT_PATH}/config/config_colors.sh" +. "${WELCOME_SCRIPT_PATH}/config/config_services.sh" +. "${WELCOME_SCRIPT_PATH}/func/message.sh" +. "${WELCOME_SCRIPT_PATH}/func/message_display.sh" +. "${WELCOME_SCRIPT_PATH}/func/services_check.sh" +#endregion -format_line() -{ - local label="$1" - local status="$2" - local width=16 +#region COMMONS +get_systemd_status +get_fail2ban_status +get_apparmor_status +get_ufw_status +#endregion - local len=${#label} - local dots="" - local i - - while [ "$len" -lt "$width" ]; do - dots="${dots}." - len=$((len + 1)) - done - - printf "%s%s: %b\n" "$label" "$dots" "$status" -} - - -check_service() -{ - local svc="$1" - local label="$2" - local status - - if ! command -v systemctl >/dev/null 2>&1; then - status=$(status_text error "systemctl indisponible") - format_line "$label" "$status" - return - fi - - if sudo -n systemctl is-active --quiet "$svc" 2>/dev/null; then - status=$(status_text success "actif") - - elif sudo -n systemctl status "$svc" >/dev/null 2>&1; then - status=$(status_text error "arrêté") - - else - status=$(status_text error "non installé") - fi - - format_line "$label" "$status" -} - - -get_systemd_status() -{ - local failed_output failed_count status - - # On capture la sortie ET on vérifie si la commande réussit - # 2>/dev/null est crucial ici pour ne pas polluer l'affichage - if failed_output=$(systemctl --failed --no-legend --no-pager 2>/dev/null); then - # La commande a fonctionné, on compte les lignes vides ou non - failed_count=$(echo "$failed_output" | grep -c '[^[:space:]]') - - if [ "$failed_count" -gt 0 ]; then - status=$(status_text error "État critique (${failed_count} problème(s))") - else - status=$(status_text success "système OK") - fi - else - # La commande a échoué (probablement un problème de sudo/permissions) - status=$(status_text warning "Erreur accès (relancer avec sudo)") - fi - - format_line "Systemd" "$status" -} - - -get_fail2ban_status() -{ - local banned status jails count total=0 - - if ! command -v fail2ban-client >/dev/null 2>&1; then - status=$(status_text error "non installé") - format_line "Fail2Ban" "$status" - return - fi - - if ! fail2ban-client ping >/dev/null 2>&1; then - status=$(status_text error "service indisponible") - format_line "Fail2Ban" "$status" - return - fi - - jails=$(fail2ban-client status 2>/dev/null | sed -n 's/.*Jail list:\s*//p' | tr ',' ' ') - - for jail in $jails; do - count=$(fail2ban-client status "$jail" 2>/dev/null | awk '/Currently banned/ {print $NF}') - total=$((total + ${count:-0})) - done - - status=$(status_text success "actif (${total} IPs bannies)") - format_line "Fail2Ban" "$status" -} - -get_apparmor_status() -{ - local enforce status - - if [ ! -d /sys/kernel/security/apparmor ]; then - status=$(status_text error "non disponible") - format_line "AppArmor" "$status" - return - fi - - enforce=$(aa-status 2>/dev/null | awk '/profiles are in enforce mode/ {print $1}') - - if [ -z "$enforce" ] || [ "$enforce" -eq 0 ]; then - status=$(status_text error "aucun profil renforcé") - else - status=$(status_text success "${enforce} profils renforcés") - fi - - format_line "AppArmor" "$status" -} - -get_ufw_status() -{ - local status rules raw - - if ! command -v ufw >/dev/null 2>&1; then - status=$(status_text error "non installé") - format_line "Firewall (UFW)" "$status" - return - fi - - raw=$(ufw status 2>/dev/null | head -n 1) - - if echo "$raw" | grep -q "active"; then - rules=$(ufw status 2>/dev/null | grep -cE "ALLOW|DENY") - status=$(status_text success "actif (${rules} règles)") - else - status=$(status_text error "inactif") - fi - - format_line "Firewall (UFW)" "$status" -} - - -# ---- DISPLAY - -echo -e $(get_systemd_status) -echo -e $(get_fail2ban_status) -echo -e $(get_apparmor_status) -echo -e $(get_ufw_status) - -echo -e $(check_service "zabbix-server" "Zabbix Server") -echo -e $(check_service "mysql" "MySQL") -echo -e $(check_service "apache2" "Apache Web") +#region DYNAMICS +for entry in "${SERVICES_TO_CHECK[@]}"; do + IFS="|" read -r name bin <<< "$entry" + check_service "$bin" "$name" +done +#endregion diff --git a/inc/vars.sh b/inc/vars.sh deleted file mode 100644 index 96c2e53..0000000 --- a/inc/vars.sh +++ /dev/null @@ -1,75 +0,0 @@ -#################### -### PREPARE VARS ### -#################### - -FULLNAME=$(hostname).$(hostname --domain) -USERIP=$(echo ${SSH_CONNECTION%% *}) -LOC=$(curl -s ipinfo.io/$USERIP/city) -COUNTRY=$(curl -s ipinfo.io/$USERIP/country) -ISP=$(curl -s ipinfo.io/$USERIP/org) - -# --- RÉCUPÉRATION DES DATAS --- -# RAM -M_INFO=$(free -m | awk '/Mem:/ { printf "%d %d", $2, $3 }') -read -r M_TOT M_USE <<< "$M_INFO" -M_PCT=$((M_USE * 100 / M_TOT)) - -# DISQUE (Sur la partition racine /) -D_PCT=$(df / | awk 'NR==2 {print $5}' | sed 's/%//') - -# --- LA FONCTION DE DESSIN --- -# Usage: draw_bar -draw_bar() { - local pct=$1 - local color=$2 - local size=30 - local filled=$((pct * size / 100)) - local empty=$((size - filled)) - - printf "[" - echo -ne "${color}" - for i in $(seq 1 $filled); do echo -ne "■"; done - echo -ne "${G1}" - for i in $(seq 1 $empty); do echo -ne "·"; done - echo -ne "${NC}] ${pct}%" -} - - -# GET UPTIME -upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)" -secs=$((${upSeconds}%60)) -mins=$((${upSeconds}/60%60)) -hours=$((${upSeconds}/3600%24)) -days=$((${upSeconds}/86400)) -UPTIME=`printf "%d days, %02dhours %02dmin %02dsec" "$days" "$hours" "$mins" "$secs"` - -# GET IP -IP=`hostname -I` - -# GET MEMORY -MEMTOTAL=`awk '/MemTotal/ { printf "%.3f \n", $2/1024/1024 }' /proc/meminfo` -MEMFREE=`awk '/MemFree/ { printf "%.3f \n", $2/1024/1024 }' /proc/meminfo` -MEMUSED=`awk "BEGIN {print ${MEMTOTAL}-${MEMFREE}; exit}"` - -#GET LOAD -read ONE FIVE FIFTEEN REST < /proc/loadavg - -# GET LINUX VERSION -if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then - # Fall back to using the very slow lsb_release utility - DISTRIB_DESCRIPTION=$(lsb_release -s -d) -fi -re='(.*\()(.*)(\).*)' -if [[ $DISTRIB_DESCRIPTION =~ $re ]]; then - DISTRIB_DESCRIPTION=$(printf "%s%s%s%s%s" "${BASH_REMATCH[1]}" "${YELLOW}" "${BASH_REMATCH[2]}" "${NONE}" "${BASH_REMATCH[3]}") -fi -VERSION=`echo -e $DISTRIB_DESCRIPTION` - -#VERSION=`echo -e $DISTRIB_DESCRIPTION "(kernel "$(uname -r)")\n"` - -#SYSTEM NAME -SYSTEMNAME=$(cat /etc/os-release) - -# USERS -NBUSERS=$(awk -F: '$3 >= 1000 && $7 !~ /(nologin|false)/ {count++} END {print count+1}' /etc/passwd) -#NBCONN=$(who | wc -l) diff --git a/inc/warnings.sh b/inc/warnings.sh index a68cd1b..f91bcfc 100644 --- a/inc/warnings.sh +++ b/inc/warnings.sh @@ -1,41 +1,57 @@ -# Alertes de sécurité (Échec login) -FAILED=$(journalctl _SYSTEMD_UNIT=ssh.service --since "24 hours ago" | grep -c "Failed password") -if [ $FAILED -gt 0 ]; then - echo -e "${GREEN}======================================================================${NONE}" - echo -e " ${R1}⚡ ATTENTION : ${FAILED} tentatives de connexion SSH échouées ces dernières 24h !${NONE}" +#!/bin/bash + +if [[ -z "${WELCOME_SCRIPT_PATH}" ]]; then + WELCOME_SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &>/dev/null && pwd)" fi -OTHER_USERS=$(who | wc -l) -if [ "$OTHER_USERS" -gt 1 ]; then - echo -e "${GREEN}======================================================================${NONE}" - echo -e " ${R1}⚡ Attention :${NC} Il y a actuellement $(($OTHER_USERS - 1)) autre(s) session(s) active(s).${NC}" - echo -e "${R1} ╔════════════════════════════════════════════════╗" -printf " ║ %-10s %-10s %-8s %-15s ║\n" "USER" "DATE" "HEURE" "IP" - echo " ╠════════════════════════════════════════════════╣" +#region INCLUDES +. "${WELCOME_SCRIPT_PATH}/config/config_colors.sh" +#endregion -who | awk '{ - user=$1 +check_ssh_failed_logins() { + local failed_con + local sudo_cmd="" - # Cas avec IP (dernier champ contient des parenthèses) - if ($NF ~ /^\(.*\)$/) { - ip=$NF - gsub(/[()]/,"",ip) + # Détection sudo pour journalctl + [[ $EUID -ne 0 ]] && command -v sudo >/dev/null && sudo_cmd="sudo" - time=$(NF-1) - date=$(NF-2) - } else { - ip="console locale" + failed_con=$($sudo_cmd journalctl _SYSTEMD_UNIT=ssh.service --since "24 hours ago" 2>/dev/null | grep -c "Failed password") - time=$NF - date=$(NF-1) - } - - printf " ║ %-10s %-10s %-8s %-15s ║\n", user, date, time, ip -}' - - echo -e " ╚════════════════════════════════════════════════╝${NC}" -fi + if [[ ${failed_con:-0} -gt 0 ]]; then + echo -e " ${COLOR_RED}⚡ ATTENTION :${COLOR_GRAY} ${failed_con} tentatives de connexion échouées ces dernières 24h !${NONE}" + echo -e "${COLOR_GREEN}======================================================================${NONE}" + fi +} +check_active_sessions() { + local other_users + other_users=$(who | wc -l) + + if [[ ${other_users:-0} -gt 1 ]]; then + echo -e " ${COLOR_RED}⚡ ATTENTION :${COLOR_GRAY} Il y a actuellement $((other_users - 1)) autre(s) session(s) active(s).${NONE}" + echo -e "${COLOR_RED} ╔════════════════════════════════════════════════╗" + printf " ║ %-10s %-10s %-8s %-15s ║\n" "USER" "DATE" "HEURE" "IP" + echo " ╠════════════════════════════════════════════════╣" + + # Le flux 'who' est traité par awk pour le formatage des colonnes + who | awk '{ + u=$1; + # Si le dernier champ contient des parenthèses, c est une IP + if ($NF ~ /^\(.*\)$/) { + ip=$NF; gsub(/[()]/,"",ip); + t=$(NF-1); d=$(NF-2); + } else { + ip="console"; t=$NF; d=$(NF-1); + } + printf " ║ %-10s %-10s %-8s %-15s ║\n", u, d, t, ip + }' + + echo -e " ╚════════════════════════════════════════════════╝${NONE}" + echo -e "${COLOR_GREEN}======================================================================${NONE}" + fi +} +check_ssh_failed_logins +check_active_sessions \ No newline at end of file diff --git a/info/cmd b/info/cmd index 3b46f50..b38b786 100644 --- a/info/cmd +++ b/info/cmd @@ -1,31 +1,28 @@ -!/bin/sh +#!/bin/bash -# INCLUDE COLORS -. /etc/profile.d/inc/colors.sh +if [[ -z "${WELCOME_SCRIPT_PATH}" ]]; then + WELCOME_SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &>/dev/null && pwd)" +fi -clear +#region INCLUDES +. "${WELCOME_SCRIPT_PATH}/config/config_colors.sh" +. "${WELCOME_SCRIPT_PATH}/config/config_cmd.sh" +. "${WELCOME_SCRIPT_PATH}/func/message.sh" +. "${WELCOME_SCRIPT_PATH}/func/message_display.sh" +#endregion -echo -e " -${CYAN}[ APACHE ] -${YELLOW}Restart apache..........: ${WHITE}apache2ctl restart -${CYAN}[ MAIL ] -${YELLOW}Sending a mail..........: ${WHITE}echo "Subject: sendmail test" | sendmail -v admin@frogg.fr -${CYAN}[ CRON ] -${YELLOW}Edit main cron tab......: ${WHITE}crontab -e -${CYAN}[ LINUX ] -${YELLOW}Restart a service.......: ${WHITE}/etc/init.d/\${service name} restart${NONE} -${YELLOW}Add symbolic link.......: ${WHITE}ln -s \${path} \${symlink} -${YELLOW}Disk space tool.........: ${WHITE}ncdu -${YELLOW}Display journal.........: ${WHITE}journalctl -xe -${YELLOW}Display system erros....: ${WHITE}systemctl --failed +#region CHECKS +if ! command -v jq &> /dev/null; then + msg_error " 'jq' n'est pas installé." + msg_warning "Veuillez l'installer pour exécuter ce script : apt install jq" + exit 1 +fi +#endregion -liste des fonctions chargée dans la session ssh -declare -F +#region MAIN +display_conditional_list "$CMD_LIST_CONFIG_JSON" +#endregion -" - -############## -### INFOS ### -############## - -. /etc/profile.d/inc/infos.sh +#region INFOS +. "${WELCOME_SCRIPT_PATH}/inc/infos.sh" +#endregion \ No newline at end of file diff --git a/info/colors b/info/colors new file mode 100644 index 0000000..24bc403 --- /dev/null +++ b/info/colors @@ -0,0 +1,40 @@ +#!/bin/bash + +if [[ -z "${WELCOME_SCRIPT_PATH}" ]]; then + WELCOME_SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &>/dev/null && pwd)" +fi + +#region INCLUDES +. "${WELCOME_SCRIPT_PATH}/config/config_colors.sh" +. "${WELCOME_SCRIPT_PATH}/func/message.sh" +#endregion + +test_colors() { + + local vars val name + + # On vérifie la présence de compgen + [[ -z "$(command -v compgen)" ]] && return 1 + + # Liste triée des variables + vars=$(compgen -v | grep '^COLOR_' | sort) + + for var_name in $vars; do + [[ "$var_name" == "COLOR_NONE" ]] && continue + + val="${!var_name}" + name="${var_name#COLOR_}" + + # 1. On affiche le nom avec un alignement fixe (12 caractères) + printf "${val} %-12s : " "$name" + + # 2. On affiche le bloc de couleur + echo -ne "${val}█████████${COLOR_NONE} " + + # 3. On affiche le texte d'exemple avec la couleur appliquée + # On utilise echo -e pour être sûr que la couleur s'applique au texte + echo -e "${val}Texte d'exemple${COLOR_NONE}" + done +} + +test_colors diff --git a/info/conf b/info/conf index 21a5cd1..10577ec 100644 --- a/info/conf +++ b/info/conf @@ -1,39 +1,28 @@ -#!/bin/sh +#!/bin/bash -# INCLUDE COLORS -. /etc/profile.d/inc/colors.sh +if [[ -z "${WELCOME_SCRIPT_PATH}" ]]; then + WELCOME_SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &>/dev/null && pwd)" +fi -clear +#region INCLUDES +. "${WELCOME_SCRIPT_PATH}/config/config_colors.sh" +. "${WELCOME_SCRIPT_PATH}/config/config_conf.sh" +. "${WELCOME_SCRIPT_PATH}/func/message.sh" +. "${WELCOME_SCRIPT_PATH}/func/message_display.sh" +#endregion -echo -e " -${CYAN}[ WEBSITE ] -${YELLOW}Websites folder.........: ${WHITE}TODO -${CYAN}[ APACHE ] -${YELLOW}Vhost Websites includes.: ${WHITE}TODO -${CYAN}[ PHP ] -${YELLOW}Apache config...........: ${WHITE}TODO -${YELLOW}CLI config..............: ${WHITE}TODO -${CYAN}[ MYSQL ] -${YELLOW}Vhost Websites includes.: ${WHITE}TODO -${CYAN}[ MAIL ] -${YELLOW}graphical config........: ${WHITE}TODO -${CYAN}[ ZABBIX ] -${YELLOW}Zabbix agent config.....: ${WHITE}/etc/zabbix/zabbix-agent.conf -${CYAN}[ CUSTOM ] -${YELLOW}Login message...........: ${WHITE}/etc/profile.d/* -${YELLOW}SSH custom display......: ${WHITE}/root/.bashrc${NONE} -ajouter le path pour les mails -/etc/msmtprc -APP ARMOR -/etc/apparmor.d/local/ -log rotate conf -/etc/logrotate.d/ -Variable d environement -/etc/environment -" +#region CHECKS +if ! command -v jq &> /dev/null; then + msg_error " 'jq' n'est pas installé." + msg_warning "Veuillez l'installer pour exécuter ce script : apt install jq" + exit 1 +fi +#endregion -############## -### INFOS ### -############## +#region MAIN +display_conditional_list "$CONF_LIST_CONFIG_JSON" +#endregion -. /etc/profile.d/inc/infos.sh +#region INFOS +. "${WELCOME_SCRIPT_PATH}/inc/infos.sh" +#endregion \ No newline at end of file diff --git a/inc/tool.sh b/tool/ipv6.sh similarity index 100% rename from inc/tool.sh rename to tool/ipv6.sh