From 9510dbb57b8626a756d1b78ec763105c695460c3 Mon Sep 17 00:00:00 2001 From: Darren 'Tadgy' Austin Date: Tue, 17 Nov 2020 23:26:45 +0000 Subject: Clean up syntax of host+domain entry and add some basic validation. --- netconfig | 70 ++++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 28 deletions(-) (limited to 'netconfig') diff --git a/netconfig b/netconfig index 210c8a4..bad070e 100644 --- a/netconfig +++ b/netconfig @@ -425,47 +425,61 @@ PREFIX6=64 # Main loop: while [ 0 ]; do -cat << EOF > $TMP/tempmsg + cat << EOF > $TMP/tempmsg First, we'll need the name you'd like to give your host. -Only the base hostname is needed right now. (not the domain) +Only the base hostname is needed right now - not the domain. +For example: darkstar Enter hostname: EOF - dialog --title "ENTER HOSTNAME" --inputbox "`cat $TMP/tempmsg`" 11 65 \ - $HOSTNM 2> $TMP/SeThost - if [ $? = 1 -o $? = 255 ]; then + dialog --title "ENTER HOSTNAME" --inputbox "`cat $TMP/tempmsg`" 12 64 \ + $HOSTNM 2> $TMP/SeThost + if [ $? = 1 -o $? = 255 ]; then + rm -f $TMP/SeThost $TMP/tempmsg + exit + fi + HOSTNM="`cat $TMP/SeThost`" rm -f $TMP/SeThost $TMP/tempmsg - exit - fi - HOSTNM="`cat $TMP/SeThost`" - rm -f $TMP/SeThost $TMP/tempmsg - if [ ! "$HOSTNM" = "" ]; then - break; - fi + if [ "$HOSTNM" = "" ] || [[ ! "$HOSTNM" =~ ^[[:alnum:]]+(-)*[[:alnum:]]+$ ]]; then + dialog --title "HOSTNAME" --ok-button "Back" --msgbox \ + "That doesn't appear to be a valid hostname.\n +Hostnames can only contain letters, numbers and hyphens." 6 60 + if [ $? = 1 -o $? = 255 ]; then + exit + fi + else + break + fi done while [ 0 ]; do -cat << EOF > $TMP/tempmsg + cat << EOF > $TMP/tempmsg Now, we need the domain name for this machine, such as: - -example.org - + example.org Do not supply a leading '.' Enter domain name for $HOSTNM: EOF - dialog --title "ENTER DOMAINNAME FOR '$HOSTNM'" --inputbox \ + dialog --title "ENTER DOMAINNAME FOR '$HOSTNM'" --inputbox \ "`cat $TMP/tempmsg`" \ -14 64 $DOMAIN 2> $TMP/SeTdom - if [ $? = 1 -o $? = 255 ]; then +12 59 $DOMAIN 2> $TMP/SeTdom + if [ $? = 1 -o $? = 255 ]; then + rm -f $TMP/SeTdom $TMP/tempmsg + exit + fi + DOMAIN="`cat $TMP/SeTdom`" rm -f $TMP/SeTdom $TMP/tempmsg - exit - fi - DOMAIN="`cat $TMP/SeTdom`" - rm -f $TMP/SeTdom $TMP/tempmsg - if [ ! "$DOMAIN" = "" ]; then - break; - fi + # This regex doesn't catch everything, just basic syntax mistakes. + if [ "$DOMAIN" = "" ] || [[ ! "$DOMAIN" =~ ^([[:alnum:]]+[-.]*[[:alnum:]]+)+$ ]]; then + dialog --title "DOMAINNAME" --ok-button "Back" --msgbox \ + "That doesn't appear to be a valid domain name.\n +Domain names can only contain letters, numbers hyphens and dots." 6 68 + if [ $? = 1 -o $? = 255 ]; then + exit + fi + else + break + fi done # Write the hostname with domain to /etc/HOSTNAME: @@ -478,8 +492,8 @@ echo $HOSTNM.$DOMAIN > etc/HOSTNAME dialog --title "CONNECT VIA VLAN" --defaultno --yesno \ "Some advanced networking set ups require a VLAN ID in order to \ -connect to the network. Do you wish to configure a VLAN now? \n\n\ -Unless you are sure you require a VLAN, select 'No'." 8 68 +connect to the network. Do you wish to configure a VLAN ID now?\n\n\ +Unless you are sure you require a VLAN ID, select 'No'." 8 68 ERRNO="$?" if [ "$ERRNO" = "255" ]; then exit -- cgit v1.2.3