Update autoremakessh

This commit is contained in:
2026-06-08 19:47:35 -04:00
parent 2671558823
commit e2bf7a6ab2

View File

@@ -4,7 +4,6 @@ FB="\e[1m"
CG="\e[38;5;40m" CG="\e[38;5;40m"
CR="\e[38;5;9m" CR="\e[38;5;9m"
CY="\033[38;5;226m" CY="\033[38;5;226m"
config="/opt/autoremakessh/client/defaultconfig"
### BEGIN FUNCTION BLOCK ### BEGIN FUNCTION BLOCK
@@ -24,38 +23,45 @@ return 1
fi fi
source $config source $config
if [ "$server" = "" ]; then if [ "$server" = "" ]; then
echo -e "${CR}'server' value cannot be empty! Exiting!" echo -e "${CR}[!] 'server' value cannot be empty! Exiting!"
return 1 return 1
fi fi
if [ "$privkey" = "" ]; then if [ "$privkey" = "" ]; then
echo -e "${CR}'privkey' value cannot be empty! Exiting!" echo -e "${CR}[!] 'privkey' value cannot be empty! Exiting!"
return 1 return 1
fi fi
if [ "$pubkey" = "" ]; then if [ "$pubkey" = "" ]; then
echo -e "${CR}'pubkey' value cannot be empty! Exiting!" echo -e "${CR}[!] 'pubkey' value cannot be empty! Exiting!"
return 1 return 1
fi fi
if [ "$checksumdir" = "" ]; then if [ "$checksumdir" = "" ]; then
echo -e "${CR}'checksumdir' value cannot be empty! Exiting!" echo -e "${CR}[!] 'checksumdir' value cannot be empty! Exiting!"
return 1 return 1
fi fi
if [[ "$disablechecksums" != "0" && "$disablechecksums" != "1" ]]; then if [[ "$disablechecksums" != "0" && "$disablechecksums" != "1" ]]; then
echo -e "${CR}Invalid value for option 'disablechecksums'. Exiting!" echo -e "${CR}[!] Invalid value for option 'disablechecksums'. Exiting!"
return 1 return 1
fi fi
if [[ "$insecure" != "0" && "$insecure" != "1" ]]; then if [[ "$insecure" != "0" && "$insecure" != "1" ]]; then
echo -e "${CR}Invalid value for option 'insecure'. Exiting!" echo -e "${CR}[!] Invalid value for option 'insecure'. Exiting!"
return 1 return 1
fi fi
} }
guardband() { guardband() {
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo ''
echo -e "${CR}Script Exited with an error.${NF}" echo -e "${CR}Script Exited with an error.${NF}"
exit 1 exit 1
fi fi
} }
ipguardband() {
if [ $? -ne 0 ]; then
securitywarning
fi
}
verifyserver(){ verifyserver(){
if ! wget --spider "$server" 2>/dev/null; then if ! wget --spider "$server" 2>/dev/null; then
echo -e "${CR}Error: Cannot reach provisioning server${NF}" echo -e "${CR}Error: Cannot reach provisioning server${NF}"
@@ -79,48 +85,60 @@ fi
} }
verifyconfigsecureIP(){ verifyconfigsecureIP(){
local config_file="$1" if [ "$insecure" = "1" ]; then
local server_line=$(grep "^server=" "$config_file") return 0
local url=$(echo "$server_line" | sed 's/^server=//') fi
local ip="" local host_part=$(echo "$server" | sed -E 's|^[a-zA-Z0-9]+://([^/]+).*|\1|')
local host_part=$(echo "$url" | sed -E 's|^[a-zA-Z0-9]+://([^/]+).*|\1|')
if [[ $host_part =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then if [[ $host_part =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
ip="$host_part" ip="$host_part"
else else
ip=""
if command -v host >/dev/null 2>&1; then if command -v host >/dev/null 2>&1; then
ip=$(host "$host_part" 2>/dev/null | grep "has address" | awk '{print $4}' | head -1) output=$(host "$host_part")
if [[ $output =~ has\ address ]]; then
ip=$(echo "$output" | awk '{print $4}')
fi
elif command -v nslookup >/dev/null 2>&1; then elif command -v nslookup >/dev/null 2>&1; then
ip=$(nslookup "$host_part" 2>/dev/null | grep "Name:" | awk '{print $2}' | head -1) output=$(nslookup "$host_part")
if [[ $output =~ Name: ]]; then
ip=$(echo "$output" | awk '{print $2}')
fi
elif command -v dig >/dev/null 2>&1; then elif command -v dig >/dev/null 2>&1; then
ip=$(dig +short "$host_part" 2>/dev/null | head -1) output=$(dig +short "$host_part")
ip="$output"
else else
ip=$(getent ahosts "$host_part" 2>/dev/null | awk '{print $1}' | head -1) output=$(getent ahosts "$host_part")
if [[ $output =~ [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ ]]; then
ip=$(echo "$output" | awk '{print $1}')
fi fi
fi fi
if [[ -z "$ip" ]]; then if [[ -z "$ip" ]]; then
echo -e ${CR}"[!] Unable to resolve IP address for host '$host_part'."${NF}
return 1 return 1
fi fi
fi
local oct1=$(echo "$ip" | cut -d. -f1) local oct1=$(echo "$ip" | cut -d. -f1)
local oct2=$(echo "$ip" | cut -d. -f2) local oct2=$(echo "$ip" | cut -d. -f2)
if [[ -n $oct1 && $oct1 =~ ^[0-9]+$ ]] && [[ -n $oct2 && $oct2 =~ ^[0-9]+$ ]]; then
if [[ $oct1 -eq 10 ]]; then if [[ $oct1 -eq 10 ]]; then
return 0 return 0
fi fi
if [[ $oct1 -eq 172 ]] && [[ $oct2 -ge 16 ]] && [[ $oct2 -le 31 ]]; then if [[ $oct1 -eq 172 ]] && [[ $oct2 -ge 16 ]] && [[ $oct2 -le 31 ]]; then
return 0 return 0
fi fi
if [[ $oct1 -eq 192 ]] && [[ $oct2 -eq 168 ]]; then if [[ $oct1 -eq 192 ]] && [[ $oct2 -eq 168 ]]; then
return 0 return 0
fi fi
fi
return 1 return 1
} }
securitywarning(){ securitywarning(){
echo ''
echo -e "${CR}${FB}@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@${NF}" echo -e "${CR}${FB}@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@${NF}"
echo -e "${CR}${FB}@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@${NF}" echo -e "${CR}${FB}@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@${NF}"
echo -e "${CR}${FB}@@@ @@@${NF}" echo -e "${CR}${FB}@@@ @@@${NF}"
@@ -159,29 +177,72 @@ sleep 30
exit 1 exit 1
} }
usage() {
echo ""
echo "Usage:"
echo "autoremakessh [MODE] [OPTIONS]"
echo ""
echo "Possible modes:"
echo "Default - Client mode"
echo "-s - Server mode"
echo ""
echo "Possible Options:"
echo "-c [FILE] - Configuration file to use (Default /opt/autoremakessh/client/defaultconfig)"
echo "-h - Display this message"
exit 0
}
### END FUNCTION BLOCK ### END FUNCTION BLOCK
config="/opt/autoremakessh/client/defaultconfig"
srvmode=0
echo "" echo ""
echo "AutoremakeSSH Version 20260410-0" echo "AutoremakeSSH Version 20260410-0"
echo "© 2026 Franscobec - AGPLv3 License" echo "© 2026 Franscobec - AGPLv3 License"
echo "https://git.franscorack.com/Franscobec/AutoremakeSSH/src/branch/main/" echo "https://git.franscorack.com/Franscobec/AutoremakeSSH/src/branch/main/"
echo "" echo ""
if [[ $1 = "--server" ]]; then while getopts ":c:sh" opt; do
echo -e "${CR}Feature not yet implemented in this release${NF}" case ${opt} in
elif [[ $1 = "-h" ]]; then c )
echo "" config=$OPTARG
echo "Usage:" ;;
echo "autoremakessh [MODE] [OPTIONS]" s )
echo "" srvmode=1
echo "Possible modes:" ;;
echo "Default (No Arg) - Client mode" h )
echo "--server - Server mode" usage
echo "" ;;
echo "Possible Options:" \? )
echo "-c [FILE] - Configuration file to use (Default /opt/autoremakessh/client/defaultconfig)" echo "Invalid option: -$OPTARG" 1>&2
echo "-h - Display this message" exit 1
else ;;
: )
echo "Invalid option: -$OPTARG requires an argument" 1>&2
exit 1
;;
esac
done
shift $((OPTIND -1))
if [ -z "$config" ]; then
echo "No custom config file specified. Using default: $config"
fi
if [ "$srvmode" -eq 1 ]; then
echo "Server mode is not yet implemented"
exit 1
fi
verifydefaultconfigpresence
guardband
verifyconfigvalidity
guardband
verifyserver
guardband
verifyconfigsecureIP
ipguardband
verifydefaultconfigpresence verifydefaultconfigpresence
guardband guardband
verifyconfigvalidity verifyconfigvalidity