Amélioration et Refactorisation du code
This commit is contained in:
parent
24fd610d3e
commit
813c0beeac
|
|
@ -1,76 +1,62 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# NETTOYAGE
|
WELCOME_SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
|
||||||
|
|
||||||
clear
|
|
||||||
|
|
||||||
# INC
|
#region INCLUDES
|
||||||
. /etc/profile.d/inc/colors.sh
|
. "${WELCOME_SCRIPT_PATH}/config/config_colors.sh"
|
||||||
. /etc/profile.d/inc/vars.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 ###
|
||||||
|
##################
|
||||||
|
|
||||||
################
|
display_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}"
|
|
||||||
|
|
||||||
#################
|
#################
|
||||||
### WARNINGS ###
|
### WARNINGS ###
|
||||||
#################
|
#################
|
||||||
|
|
||||||
. /etc/profile.d/inc/warnings.sh
|
. "${WELCOME_SCRIPT_PATH}/inc/warnings.sh"
|
||||||
|
|
||||||
echo -e "${GREEN}======================================================================${NONE}"
|
|
||||||
|
|
||||||
#################
|
#################
|
||||||
### SERVICES ###
|
### SERVICES ###
|
||||||
#################
|
#################
|
||||||
|
|
||||||
. /etc/profile.d/inc/services.sh
|
. "${WELCOME_SCRIPT_PATH}/inc/services.sh"
|
||||||
|
|
||||||
##############
|
##############
|
||||||
### INFOS ###
|
### 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 ###
|
### 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
|
||||||
|
|
@ -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)
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
|
||||||
|
#region JSON
|
||||||
|
CMD_LIST_CONFIG_JSON=$(cat <<EOF
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"section": "APACHE",
|
||||||
|
"items": [
|
||||||
|
{"label": "Restart apache", "cmd": "apache2ctl restart", "bin": "apache2ctl"},
|
||||||
|
{"label": "Status", "cmd": "service apache2 status", "bin": "apache2"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"section": "SYSTEM",
|
||||||
|
"items": [
|
||||||
|
{"label": "Edit main cron", "cmd": "crontab -e", "bin": "crontab"},
|
||||||
|
{"label": "Restart service", "cmd": "/etc/init.d/\${name} restart"},
|
||||||
|
{"label": "Display journal", "cmd": "journalctl -xe", "bin": "journalctl"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"section": "TOOLS",
|
||||||
|
"items": [
|
||||||
|
{"label": "Disk space", "cmd": "ncdu", "bin": "ncdu"},
|
||||||
|
{"label": "Network stats", "cmd": "htop", "bin": "htop"}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
#endregion
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
|
||||||
|
# SETTING CUSTOM COLOR
|
||||||
|
NONE="\e[0m"
|
||||||
|
COLOR_WHITE="\e[1;37m"
|
||||||
|
#COLOR_WHITE='\033[38;5;255m'
|
||||||
|
COLOR_GREEN="\e[1;32m"
|
||||||
|
COLOR_RED="\e[38;5;196m"
|
||||||
|
COLOR_ORANGE="\e[38;5;208m"
|
||||||
|
COLOR_YELLOW="\e[1;33m"
|
||||||
|
COLOR_BLUE="\e[1;94m"
|
||||||
|
COLOR_CYAN="\e[36m"
|
||||||
|
COLOR_GRAY="\e[38;5;250m"
|
||||||
|
COLOR_LIGHT_GREEN='\033[38;5;154m'
|
||||||
|
COLOR_LIGHT_BLUE="\033[38;5;31m"
|
||||||
|
COLOR_LIGHT_RED="\033[01;91m"
|
||||||
|
COLOR_DARK_GRAY="\033[38;5;239m"
|
||||||
|
|
||||||
|
COLOR_GREEN_BG='\033[48;5;28m' # Fond Git Propre (Vert)
|
||||||
|
COLOR_DARK_GRAY_BG='\033[48;5;239m' # Fond Gris
|
||||||
|
COLOR_LIGHT_BLUE_BG='\033[48;5;31m' # Fond Bleu
|
||||||
|
COLOR_LIGHT_RED_BG='\033[01;101m' # Fond Git Sale (Rouge Intense - 101 est le fond de 91)
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
|
||||||
|
#region JSON
|
||||||
|
CONF_LIST_CONFIG_JSON=$(cat <<EOF
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"section": "APACHE",
|
||||||
|
"items": [
|
||||||
|
{"label": "Websites folder", "cmd": "/var/www/", "bin": "apache2"},
|
||||||
|
{"label": "Apache config", "cmd": "/etc/apache2/", "bin": "apache2"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"section": "PHP",
|
||||||
|
"items": [
|
||||||
|
{"label": "CLI config", "cmd": "/etc/php/*/cli/php.ini", "bin": "php"},
|
||||||
|
{"label": "Apache config", "cmd": "/etc/php/*/apache2/php.ini", "bin": "php"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"section": "MYSQL",
|
||||||
|
"items": [
|
||||||
|
{"label": "Mysql config", "cmd": "/etc/mysql/my.cnf", "bin": "mysql"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"section": "TOOLS",
|
||||||
|
"items": [
|
||||||
|
{"label": "Zabbix agent", "cmd": "/etc/zabbix/zabbix-agent.conf", "bin": "zabbix-agent"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"section": "CUSTOM",
|
||||||
|
"items": [
|
||||||
|
{"label": "Login message", "cmd": "/etc/profile.d/777-welcome.sh"}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
#endregion
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
|
||||||
|
#region SERVICE_CHECKLIST
|
||||||
|
SERVICES_TO_CHECK=(
|
||||||
|
# MONITORING
|
||||||
|
"Zabbix Server|zabbix_server"
|
||||||
|
"Zabbix Agent|zabbix_agentd"
|
||||||
|
# DATABASE
|
||||||
|
"MySQL Server|mysql"
|
||||||
|
"PostgreSQL|psql"
|
||||||
|
"SQLite|sqlite3"
|
||||||
|
# WEB
|
||||||
|
"Apache Web|apache2"
|
||||||
|
"Nginx|nginx"
|
||||||
|
"Redis Server|redis-server"
|
||||||
|
# GIT
|
||||||
|
"Git Core|git"
|
||||||
|
"GitLab|gitlab-ctl"
|
||||||
|
"Gitea|gitea"
|
||||||
|
# VIRTUA
|
||||||
|
"VMware Tools|vmware-toolbox-cmd"
|
||||||
|
"Qemu Guest Agent|qemu-ga"
|
||||||
|
"Proxmox VE|pveversion" # ? fonctionne ?
|
||||||
|
"Docker Engine|docker"
|
||||||
|
)
|
||||||
|
#endregion
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
format_size() {
|
||||||
|
local size=$1 # En Ko
|
||||||
|
local units=("Ko" "Mo" "Go" "To" "Po")
|
||||||
|
local unit_idx=0
|
||||||
|
local decimal=0
|
||||||
|
|
||||||
|
# Tant que la taille est >= 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
|
||||||
|
}
|
||||||
|
|
@ -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"
|
||||||
|
}
|
||||||
|
|
@ -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"
|
||||||
|
}
|
||||||
|
|
@ -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<filled; i++)); do echo -ne "■"; done
|
||||||
|
echo -ne "${COLOR_GRAY}"
|
||||||
|
for ((i=0; i<empty; i++)); do echo -ne "·"; done
|
||||||
|
echo -ne "${NONE}] ${color}${pct}%${NONE}"
|
||||||
|
}
|
||||||
|
draw_ascii_art() {
|
||||||
|
|
||||||
|
local L_IPS L_UPT L_HRD L_CPU_BAR L_MEM_BAR L_HDD_BAR L_USR L_DAT
|
||||||
|
# Pré-formatage des étiquettes pour l'alignement
|
||||||
|
L_IPS="${COLOR_YELLOW}IP Addresses.: ${F_IPS}"
|
||||||
|
L_UPT="${COLOR_YELLOW}Uptime.......: ${F_UPT}"
|
||||||
|
L_HRD="${COLOR_YELLOW}Hardware.....: ${F_HARD}"
|
||||||
|
L_CPU_BAR="${COLOR_YELLOW}CPU Usage....: ${F_BAR_CPU}"
|
||||||
|
L_MEM_BAR="${COLOR_YELLOW}RAM Usage....: ${F_BAR_MEM}"
|
||||||
|
L_HDD_BAR="${COLOR_YELLOW}Disk Usage...: ${F_BAR_DSK}"
|
||||||
|
L_USR="${COLOR_YELLOW}Nb acc user..: ${F_USR}"
|
||||||
|
L_DAT="${COLOR_WHITE}$(LC_TIME=fr_FR.UTF-8 date +"%A, %e %B %Y, %r")"
|
||||||
|
|
||||||
|
clear
|
||||||
|
echo -e "${COLOR_CYAN} ==[ You are connected to ${COLOR_WHITE}$(hostname)${COLOR_CYAN} ]=="
|
||||||
|
echo -e "${COLOR_GREEN} _ __ _"
|
||||||
|
echo -e "${COLOR_GREEN} ((-)).--.((-)) ${L_DAT}"
|
||||||
|
echo -e "${COLOR_GREEN} / '' \\ ${F_VER}"
|
||||||
|
echo -e "${COLOR_GREEN} ( \______/ )"
|
||||||
|
echo -e "${COLOR_GREEN} \ ( ) / ${L_IPS}"
|
||||||
|
echo -e "${COLOR_GREEN} / /~~~~~~~~\ \ ${L_UPT}"
|
||||||
|
echo -e "${COLOR_GREEN} /~~\/ / \ \/~~\ ${L_HRD}"
|
||||||
|
echo -e "${COLOR_GREEN}( ( ( ) ) ) ${L_USR}"
|
||||||
|
echo -e "${COLOR_GREEN} \ \ \ \ / / / / ${L_CPU_BAR}"
|
||||||
|
echo -e "${COLOR_GREEN} _\ \/ \.______./ \/ /_ ${L_MEM_BAR}"
|
||||||
|
echo -e "${COLOR_GREEN} ___/ /\__________/\ \___ ${L_HDD_BAR}"
|
||||||
|
}
|
||||||
|
|
||||||
|
display_dashboard() {
|
||||||
|
# Déclaration de toutes les variables partagées en local
|
||||||
|
local F_VER F_IPS F_UPT F_BAR_CPU F_BAR_DSK F_USR F_HARD
|
||||||
|
|
||||||
|
# Exécution des sondes
|
||||||
|
get_os_info
|
||||||
|
get_hardware_info
|
||||||
|
get_network_info
|
||||||
|
get_uptime_info
|
||||||
|
get_memory_info
|
||||||
|
get_load_info
|
||||||
|
get_disk_info
|
||||||
|
get_disk_info
|
||||||
|
get_user_info
|
||||||
|
get_disk_info
|
||||||
|
|
||||||
|
# Affichage
|
||||||
|
draw_ascii_art
|
||||||
|
|
||||||
|
echo -e "${COLOR_GREEN}======================================================================${NONE}"
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
getIpLocation() {
|
||||||
|
local user_ip="$1"
|
||||||
|
local geo city country org
|
||||||
|
|
||||||
|
# Regex RFC1918 (LAN)
|
||||||
|
if [[ $user_ip =~ ^127\.|^10\.|^172\.(1[6-9]|2[0-9]|3[0-1])\.|^192\.168\. ]]; then
|
||||||
|
echo "Local Network (LAN)"
|
||||||
|
else
|
||||||
|
if command -v curl >/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
|
||||||
|
}
|
||||||
|
|
@ -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"
|
||||||
|
}
|
||||||
|
|
@ -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)"
|
||||||
|
}
|
||||||
|
|
@ -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\] '
|
||||||
|
|
@ -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
|
|
||||||
|
|
||||||
10
inc/infos.sh
10
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
|
# Infos
|
||||||
echo ""
|
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 ""
|
echo ""
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,79 +1,16 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
################
|
if [[ -z "${WELCOME_SCRIPT_PATH}" ]]; then
|
||||||
### LOG MAIL ###
|
WELCOME_SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &>/dev/null && pwd)"
|
||||||
################
|
USERIP=$("${SSH_CONNECTION%% *}")
|
||||||
|
FULLNAME=$(hostname).$(hostname --domain)
|
||||||
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)"
|
|
||||||
fi
|
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)
|
send_login_mail "$USERIP" "$USER" "$FULLNAME"
|
||||||
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"
|
|
||||||
106
inc/ps1.sh
106
inc/ps1.sh
|
|
@ -1,39 +1,12 @@
|
||||||
# Shortucts for server config info
|
#!/bin/bash
|
||||||
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'
|
|
||||||
|
|
||||||
|
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
|
# 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\] >'
|
#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\] '
|
#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
|
# 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
|
||||||
|
|
|
||||||
190
inc/services.sh
190
inc/services.sh
|
|
@ -1,173 +1,27 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
status_text()
|
if [[ -z "${WELCOME_SCRIPT_PATH}" ]]; then
|
||||||
{
|
WELCOME_SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &>/dev/null && pwd)"
|
||||||
local type="$1"
|
fi
|
||||||
local msg="$2"
|
|
||||||
|
|
||||||
case "$type" in
|
#region INCLUDES
|
||||||
ok|success)
|
. "${WELCOME_SCRIPT_PATH}/config/config_colors.sh"
|
||||||
echo "${GREEN}✅ ${msg}${NC}"
|
. "${WELCOME_SCRIPT_PATH}/config/config_services.sh"
|
||||||
;;
|
. "${WELCOME_SCRIPT_PATH}/func/message.sh"
|
||||||
warn|warning)
|
. "${WELCOME_SCRIPT_PATH}/func/message_display.sh"
|
||||||
echo "${YELLOW}⚡ ${msg}${NC}"
|
. "${WELCOME_SCRIPT_PATH}/func/services_check.sh"
|
||||||
;;
|
#endregion
|
||||||
error|err)
|
|
||||||
echo "${RED}❌ ${msg}${NC}"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "${msg}"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
format_line()
|
#region COMMONS
|
||||||
{
|
get_systemd_status
|
||||||
local label="$1"
|
get_fail2ban_status
|
||||||
local status="$2"
|
get_apparmor_status
|
||||||
local width=16
|
get_ufw_status
|
||||||
|
#endregion
|
||||||
|
|
||||||
local len=${#label}
|
#region DYNAMICS
|
||||||
local dots=""
|
for entry in "${SERVICES_TO_CHECK[@]}"; do
|
||||||
local i
|
IFS="|" read -r name bin <<< "$entry"
|
||||||
|
check_service "$bin" "$name"
|
||||||
while [ "$len" -lt "$width" ]; do
|
done
|
||||||
dots="${dots}."
|
#endregion
|
||||||
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")
|
|
||||||
|
|
|
||||||
75
inc/vars.sh
75
inc/vars.sh
|
|
@ -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 <pourcentage> <couleur>
|
|
||||||
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)
|
|
||||||
|
|
@ -1,41 +1,57 @@
|
||||||
# Alertes de sécurité (Échec login)
|
#!/bin/bash
|
||||||
FAILED=$(journalctl _SYSTEMD_UNIT=ssh.service --since "24 hours ago" | grep -c "Failed password")
|
|
||||||
if [ $FAILED -gt 0 ]; then
|
if [[ -z "${WELCOME_SCRIPT_PATH}" ]]; then
|
||||||
echo -e "${GREEN}======================================================================${NONE}"
|
WELCOME_SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &>/dev/null && pwd)"
|
||||||
echo -e " ${R1}⚡ ATTENTION : ${FAILED} tentatives de connexion SSH échouées ces dernières 24h !${NONE}"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
OTHER_USERS=$(who | wc -l)
|
#region INCLUDES
|
||||||
if [ "$OTHER_USERS" -gt 1 ]; then
|
. "${WELCOME_SCRIPT_PATH}/config/config_colors.sh"
|
||||||
echo -e "${GREEN}======================================================================${NONE}"
|
#endregion
|
||||||
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 " ╠════════════════════════════════════════════════╣"
|
|
||||||
|
|
||||||
who | awk '{
|
check_ssh_failed_logins() {
|
||||||
user=$1
|
local failed_con
|
||||||
|
local sudo_cmd=""
|
||||||
|
|
||||||
# Cas avec IP (dernier champ contient des parenthèses)
|
# Détection sudo pour journalctl
|
||||||
if ($NF ~ /^\(.*\)$/) {
|
[[ $EUID -ne 0 ]] && command -v sudo >/dev/null && sudo_cmd="sudo"
|
||||||
ip=$NF
|
|
||||||
gsub(/[()]/,"",ip)
|
|
||||||
|
|
||||||
time=$(NF-1)
|
failed_con=$($sudo_cmd journalctl _SYSTEMD_UNIT=ssh.service --since "24 hours ago" 2>/dev/null | grep -c "Failed password")
|
||||||
date=$(NF-2)
|
|
||||||
} else {
|
|
||||||
ip="console locale"
|
|
||||||
|
|
||||||
time=$NF
|
if [[ ${failed_con:-0} -gt 0 ]]; then
|
||||||
date=$(NF-1)
|
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
|
||||||
printf " ║ %-10s %-10s %-8s %-15s ║\n", user, date, time, ip
|
}
|
||||||
}'
|
|
||||||
|
|
||||||
echo -e " ╚════════════════════════════════════════════════╝${NC}"
|
|
||||||
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
|
||||||
49
info/cmd
49
info/cmd
|
|
@ -1,31 +1,28 @@
|
||||||
!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
# INCLUDE COLORS
|
if [[ -z "${WELCOME_SCRIPT_PATH}" ]]; then
|
||||||
. /etc/profile.d/inc/colors.sh
|
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 "
|
#region CHECKS
|
||||||
${CYAN}[ APACHE ]
|
if ! command -v jq &> /dev/null; then
|
||||||
${YELLOW}Restart apache..........: ${WHITE}apache2ctl restart
|
msg_error " 'jq' n'est pas installé."
|
||||||
${CYAN}[ MAIL ]
|
msg_warning "Veuillez l'installer pour exécuter ce script : apt install jq"
|
||||||
${YELLOW}Sending a mail..........: ${WHITE}echo "Subject: sendmail test" | sendmail -v admin@frogg.fr
|
exit 1
|
||||||
${CYAN}[ CRON ]
|
fi
|
||||||
${YELLOW}Edit main cron tab......: ${WHITE}crontab -e
|
#endregion
|
||||||
${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
|
|
||||||
|
|
||||||
liste des fonctions chargée dans la session ssh
|
#region MAIN
|
||||||
declare -F
|
display_conditional_list "$CMD_LIST_CONFIG_JSON"
|
||||||
|
#endregion
|
||||||
|
|
||||||
"
|
#region INFOS
|
||||||
|
. "${WELCOME_SCRIPT_PATH}/inc/infos.sh"
|
||||||
##############
|
#endregion
|
||||||
### INFOS ###
|
|
||||||
##############
|
|
||||||
|
|
||||||
. /etc/profile.d/inc/infos.sh
|
|
||||||
|
|
@ -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
|
||||||
57
info/conf
57
info/conf
|
|
@ -1,39 +1,28 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
# INCLUDE COLORS
|
if [[ -z "${WELCOME_SCRIPT_PATH}" ]]; then
|
||||||
. /etc/profile.d/inc/colors.sh
|
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 "
|
#region CHECKS
|
||||||
${CYAN}[ WEBSITE ]
|
if ! command -v jq &> /dev/null; then
|
||||||
${YELLOW}Websites folder.........: ${WHITE}TODO
|
msg_error " 'jq' n'est pas installé."
|
||||||
${CYAN}[ APACHE ]
|
msg_warning "Veuillez l'installer pour exécuter ce script : apt install jq"
|
||||||
${YELLOW}Vhost Websites includes.: ${WHITE}TODO
|
exit 1
|
||||||
${CYAN}[ PHP ]
|
fi
|
||||||
${YELLOW}Apache config...........: ${WHITE}TODO
|
#endregion
|
||||||
${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 MAIN
|
||||||
### INFOS ###
|
display_conditional_list "$CONF_LIST_CONFIG_JSON"
|
||||||
##############
|
#endregion
|
||||||
|
|
||||||
. /etc/profile.d/inc/infos.sh
|
#region INFOS
|
||||||
|
. "${WELCOME_SCRIPT_PATH}/inc/infos.sh"
|
||||||
|
#endregion
|
||||||
Loading…
Reference in New Issue