mirror of
https://github.com/guezoloic/serverconfig.git
synced 2026-03-28 18:03:49 +00:00
41 lines
1.0 KiB
Bash
41 lines
1.0 KiB
Bash
#!/bin/bash
|
|
|
|
PROJECT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
readonly PROJECT_DIR 2>/dev/null
|
|
|
|
source $PROJECT_DIR/utils.sh
|
|
|
|
INSTALLED=$1
|
|
if [[ "--install" == $INSTALLED ]]; then
|
|
log_info "sshd-login Installation"
|
|
|
|
login="session optional pam_exec.so $PROJECT_DIR/sshd-login.sh"
|
|
file='/etc/pam.d/common-session'
|
|
|
|
if [[ ! -f "$file" ]]; then
|
|
log_error "$file doesn't found."
|
|
exit 1
|
|
fi
|
|
|
|
if ! grep -Fxq "$login" "$file"; then
|
|
echo "$login" >>"$file"
|
|
log_success "login command added to $file."
|
|
else
|
|
log_warn "login command already added to $file." $WARN_FLAG
|
|
fi
|
|
exit 0
|
|
fi
|
|
|
|
case "$PAM_TYPE" in
|
|
open_session)
|
|
PAYLOAD=$(printf "<b>🚨 Login Event 🚨</b>\nUser <code>%s</code> logged in from <code>%s</code> at <i>%s</i>." "$PAM_USER" "$PAM_RHOST" "$(date)")
|
|
;;
|
|
close_session)
|
|
PAYLOAD=$(printf "<b>🚨 Logout Event 🚨</b>\nUser <code>%s</code> logged out from <code>%s</code> at <i>%s</i>." "$PAM_USER" "$PAM_RHOST" "$(date)")
|
|
;;
|
|
esac
|
|
|
|
if [ -n "$PAYLOAD" ]; then
|
|
send_notification "$PAYLOAD"
|
|
fi
|