mirror of
https://github.com/guezoloic/serverconfig.git
synced 2026-03-28 18:03:49 +00:00
feat: rework entire repo structure
This commit is contained in:
40
sshd-login.sh
Normal file
40
sshd-login.sh
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/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
|
||||
Reference in New Issue
Block a user