diff options
author | Darren 'Tadgy' Austin <darren@afterdark.org.uk> | 2020-11-17 23:26:45 +0000 |
---|---|---|
committer | Robby Workman <rworkman@slackware.com> | 2021-02-27 23:47:58 -0600 |
commit | 9510dbb57b8626a756d1b78ec763105c695460c3 (patch) | |
tree | 805e04dc727956d324f804945c0ac790a0a57f0a | |
parent | 856b3e0562dba2042aa1e375de15690197e0a75a (diff) | |
download | slacknetsetup-9510dbb57b8626a756d1b78ec763105c695460c3.tar.xz |
Clean up syntax of host+domain entry and add some basic validation.
-rw-r--r-- | netconfig | 70 |
1 files changed, 42 insertions, 28 deletions
@@ -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 |