0035_Bash: Strong-Wi-Fi

The script asks the user for the name of the Wi-Fi wireless network (SSID), generates a random 63-character WPA key, and displays all the data on the screen. After that, the user enters an email address to which the script sends two files: a QR code for connecting to the network and a text file indicating the network name (SSID) and the generated key.

#!/bin/bash

# Set a charset
CHARSET="utf-8"

# Clearing the screen
clear

# Getting the height of the terminal
rows=$(tput lines)

# Calculating the average row
middle_row=$((rows / 2))

# Move the cursor to the middle of the screen in height
tput cup $middle_row 0

# Requesting the name of the Wi-Fi wireless network
read -p "Enter the name of the wireless network. ((SSID-up to 32, without spaces and special characters): " SSID

# Length of the WPA key (maximum 63 characters)
KEY_LENGTH=63	# Up to
ENCRYPTION=WPA	# WPA /WEP / NONE

# Generate a random key from letters, numbers, and special characters
KEY=$(tr -dc 'A-Za-z0-9_!@#$%^&*()' </dev/urandom | head -c $KEY_LENGTH)

# QR code generation
echo -e "Wireless Network Name (SSID): $SSID\nType of encryption (NONE/WEP/WPA): $ENCRYPTION\nWireless Network key: $KEY" > email_body.txt
WIFI_STRING="WIFI:T:$ENCRYPTION;S:$SSID;P:$KEY;;"
            qrencode -o wifi_qr.png "$WIFI_STRING"
            GENERATED_FILES+=(wifi_qr.png email_body.txt)
echo
echo
echo
echo "Name of the wireless network (SSID):" $SSID
echo "Type of encryption (NONE/WEP/WPA):" $ENCRYPTION
echo "Wireless Network key:" $KEY


# Request for an email address to send the data to
echo
echo
echo
read -p "Enter the email address to send the data to:" EMAIL 

# Sending by еmail
set -x
sendemail -f <sender email> -t "$EMAIL" -u "YOUR QR Code" -m "Information about the Wi-Fi wireless network in the attachment" -s <your an email server> -a ${GENERATED_FILES[@]} -o message-charset=$CHARSET

# Deleting temporary files
rm -f  ${GENERATED_FILES[@]}

echo Done.


### hint ###
#sudo apt install sendemail libio-socket-ssl-perl libnet-ssleay-perl
#sendemail -f "Sender Name <sender@example.com>" \
#          -t recipient@example.com \
#          -u "Personalized Email" \
#          -m "This email has a custom sender name." \
#          -s smtp.example.com:587 \
#          -xu sender@example.com \
#          -xp "password"

#sendemail -f sender@example.com -t recipient@example.com \ -u "Log Test" -m "This email will be logged." \ -s smtp.yourserver.com:25 -l /path/to/logfile.log