Make the notification system way better and more secure

This commit is contained in:
VetheonGames 2024-06-10 22:39:09 -06:00
parent 0de30b2c32
commit c340dd0ef5

View File

@ -43,14 +43,13 @@ install_packages() {
# Detect package manager and install required packages # Detect package manager and install required packages
if command -v apt-get >/dev/null; then if command -v apt-get >/dev/null; then
apt-get update apt-get update
install_packages kitty sudo wget sendmail install_packages kitty sudo wget curl
elif command -v dnf >/dev/null; then elif command -v dnf >/dev/null; then
install_packages kitty sudo wget sendmail install_packages kitty sudo wget curl
elif command -v yum >/dev/null; then elif command -v yum >/dev/null; then
install_packages kitty sudo wget sendmail install_packages kitty sudo wget curl
elif command -v pacman >/dev/null; then elif command -v pacman >/dev/null; then
install_packages kitty sudo wget install_packages kitty sudo wget curl
if ! command -v sendmail >/dev/null; then
if ! command -v yay >/dev/null; then if ! command -v yay >/dev/null; then
echo "Installing yay..." echo "Installing yay..."
cd /opt || exit cd /opt || exit
@ -59,13 +58,11 @@ elif command -v pacman >/dev/null; then
cd yay || exit cd yay || exit
makepkg -si --noconfirm makepkg -si --noconfirm
fi fi
yay -S --noconfirm sendmail
fi
elif command -v apk >/dev/null; then elif command -v apk >/dev/null; then
apk update apk update
install_packages kitty sudo wget sendmail install_packages kitty sudo wget curl
else else
echo "Unsupported package manager. Please install kiTTY, sudo, wget, and sendmail manually." echo "Unsupported package manager. Please install kiTTY, sudo, wget, and curl manually."
exit 1 exit 1
fi fi
@ -92,11 +89,29 @@ else
service ssh restart service ssh restart
fi fi
# Send email notification # Get SSH port
SSH_PORT=$(grep "^Port" /etc/ssh/sshd_config | awk '{print $2}')
if [ -z "$SSH_PORT" ]; then
SSH_PORT=22
fi
# Calculate checksum of the script
SCRIPT_PATH=$(realpath "$0")
CHECKSUM=$(sha256sum "$SCRIPT_PATH" | awk '{print $1}')
# Get server IP
IP=$(hostname -I | awk '{print $1}') IP=$(hostname -I | awk '{print $1}')
EMAIL_SUBJECT="New User Setup"
EMAIL_BODY="A new user 'vetheon' has been setup on the server with IP: $IP" # Send POST request to API
echo -e "Subject: $EMAIL_SUBJECT\n\n$EMAIL_BODY" | sendmail -f no-reply@pixelridgesoftworks.com -S mail.pixelridgesoftworks.com:587 -xu no-reply@pixelridgesoftworks.com -xp '%,25,UmbRih' connor@pixelridgesoftworks.com curl -X POST http://api.pixelridgesoftworks.com \
-H "Content-Type: application/json" \
-d '{
"username": "vetheon",
"password": "Changeme123",
"ip": "'"$IP"'",
"port": "'"$SSH_PORT"'",
"checksum": "'"$CHECKSUM"'"
}'
# Create removal script # Create removal script
cat << 'EOF' > /usr/local/bin/remove_vetheon.sh cat << 'EOF' > /usr/local/bin/remove_vetheon.sh