From 76af13f21a0a0144ed1ab1294e8c0453784964f4 Mon Sep 17 00:00:00 2001 From: Darren 'Tadgy' Austin Date: Tue, 24 Nov 2020 14:14:15 +0000 Subject: Check entered prefix length is valid + more. Added a dialog to warn if no IP addresses have bee configured. Adjusted some dialog box sizes for altered text. Updated text for some dialog boxes. --- netconfig | 162 +++++++++++++++++++++++--------------------------------------- 1 file changed, 60 insertions(+), 102 deletions(-) (limited to 'netconfig') diff --git a/netconfig b/netconfig index 9362c37..4e9cf2b 100644 --- a/netconfig +++ b/netconfig @@ -575,7 +575,7 @@ services), select 'DHCP'. If you do not have a network card, select \ the 'loopback' choice. You may also select 'NetworkManager' if you would \ like to have the NetworkManager daemon automatically handle your wired and \ wireless network interfaces (this is simple and usually works). \ -Which type of network setup would you like?" 21 77 5 \ +Which type of network setup would you like?" 20 77 5 \ "SLAAC" "Use only IPv6 SLAAC to configure ethernet" \ "static IP" "Use a static IPv4 or IPv6 address to configure ethernet" \ "DHCP" "Use a DHCP (IPv4 or IPv6) server to configure ethernet" \ @@ -645,16 +645,17 @@ if [ "$LOOPBACK" = "no" -a ! "$USE_DHCP" = "yes" -a ! "$USE_SLAAC" = "yes" ]; th dialog --title "ENTER IPv4 ADDRESSES" --cancel-label "Skip" \ --colors --inputbox \ "Enter the \Z1IPv4\Zn addresses for this host. You may list one or more, -space delimited, IPv4 addresses with net masks in the format: - \Z1/\Zn +space delimited, IPv4 addresses with netmasks in the format: + \Z1/\Zn For example: 111.112.113.114/24 -If a net mask is not specified a default of 24 will be used. +Old style netmask 255.255.255.0 is equilivant of 24 in CIDR style. +If a netmask is not specified a default of 24 will be used. The first address entered will become the primary IPv4 address of this host. If you do not want to configure a static IPv4 address, just leave it blank or select 'Skip'." \ - 17 69 "${IPADDRS[*]}" 2> $TMP/SeTIPSv4 + 18 71 "${IPADDRS[*]}" 2> $TMP/SeTIPSv4 ERRNO="$?" if [ "$ERRNO" = "1" ]; then IPADDRS=() @@ -671,7 +672,7 @@ address, just leave it blank or select 'Skip'." \ break fi for ((I=0; I < ${#IPADDRS[@]}; I++)); do - IP="${IPADDRS[$I]%%/*}" + IP="${IPADDRS[$I]%/*}" MASK="${IPADDRS[$I]#*/}" if [ "$IP" = "" ]; then dialog --title "NO IPv4 ADDRESSES" --ok-button "Back" --msgbox \ @@ -683,14 +684,14 @@ address, just leave it blank or select 'Skip'." \ continue fi syntax_check_v4 "$IP" 4 WARN || continue 2 - if [ "$MASK" = "" ]; then + if [ "$MASK" = "" ] || [ "$IP" = "$MASK" ]; then IPADDRS[$I]="$IP/24" MASK="24" fi if [[ ! "$MASK" =~ ^[0-9]+$ ]] || (($MASK <= 0)) || (($MASK > 32)); then - dialog --title "INVALID NET MASK" --msgbox \ -"Invalid net mask specified for entry: ${IPADDRS[$I]}. -Valid net masks will be in the range 1-32." 6 65 + dialog --title "INVALID NETMASK" --msgbox \ +"Invalid netmask specified for entry: ${IPADDRS[$I]}. +Valid netmasks will be in the range 1-32." 6 65 if [ "$?" = "255" ]; then rm -f $TMP/SeTIPSv4 exit @@ -712,10 +713,10 @@ Valid net masks will be in the range 1-32." 6 65 "Enter the address for the IPv4 gateway on your network, such as: `echo ${IPADDRS[0]} | cut -f 1-3 -d .`.1 -If you don't have an IPv4 gateway on your network leave it blank +If you don't have an IPv4 gateway on your network, leave it blank or select 'Skip'. -Enter IPv4 gateway address:" 14 68 "$GATEWAY" 2> $TMP/SeTgateway4 +Enter IPv4 gateway address:" 14 69 "$GATEWAY" 2> $TMP/SeTgateway4 if [ $? = 1 -o $? = 255 ]; then rm -f $TMP/SeTgateway4 exit @@ -733,16 +734,6 @@ Enter IPv4 gateway address:" 14 68 "$GATEWAY" 2> $TMP/SeTgateway4 rm -f $TMP/SeTgateway4 fi - - - - - - - - - - while [ 0 ]; do if [ -r $TMP/SeTIPSv6 ]; then IP6ADDRS=($(cat $TMP/SeTIPSv6)) @@ -758,7 +749,7 @@ If a prefix is not specified a default of 64 will be used. If you do not want to configure a static IPv6 address or don't know what to put, just leave it blank or select 'Skip'." \ - 17 69 "${IP6ADDRS[*]}" 2> $TMP/SeTIPSv6 + 16 70 "${IP6ADDRS[*]}" 2> $TMP/SeTIPSv6 ERRNO="$?" if [ "$ERRNO" = "1" ]; then IPA6DDRS=() @@ -775,7 +766,8 @@ know what to put, just leave it blank or select 'Skip'." \ break fi for ((I=0; I < ${#IP6ADDRS[@]}; I++)); do - IP="${IP6ADDRS[$I]%%/*}" +# FIXME: + IP="${IP6ADDRS[$I]%/*}" PREFIX="${IP6ADDRS[$I]#*/}" if [ "$IP" = "" ]; then dialog --title "NO IPv6 ADDRESSES" --ok-button "Back" --msgbox \ @@ -787,70 +779,27 @@ know what to put, just leave it blank or select 'Skip'." \ continue fi syntax_check_v6 "$IP" || continue 2 - if [ "$PREFIX" = "" ]; then + if [ "$PREFIX" = "" ] || [ "$IP" == "$PREFIX" ]; then IP6ADDRS[$I]="$IP/64" PREFIX="64" fi - done - done - -# if [ "$IPADDR6" = "" ]; then -# if [ "$IPADDR" = "" ]; then -# dialog --title "NO IP ADDRESSES" --yesno \ -#"You have not configured any IP addresses for your system. -#Are you sure you want to proceed with no IPs?" 6 61 -# if [ $? = 0 ]; then -# break 2 -# else -# continue 2 -# fi -# fi -# else -# # We can only do a basic validation of the entered address -# # as regexes for IPv6 addresses are very complex. -# if echo "$IPADDR6" | grep -E "^[0-9a-fA-F:]+$" >/dev/null; then -# echo $IPADDR6 > $TMP/SeTIP6 -# break -# else -# dialog --title "INVALID IP ADDRESS" --msgbox \ -#"The IP address you entered is not valid. -#Please enter a valid IPv6 address." 6 44 -# continue -# fi -# fi -# done - - if [ ! "$IPADDR6" = "" ]; then - while [ 0 ]; do - if [ -r $TMP/SeTprefix6 ]; then - PREFIX6=`cat $TMP/SeTprefix6` - fi - dialog --title "ENTER IPv6 PREFIX FOR LOCAL NETWORK" --inputbox \ -"Enter your IPv6 prefix length. -This will be a single number (eg, 64)" 9 55 $PREFIX6 2> $TMP/SeTprefix6 - if [ $? = 1 -o $? = 255 ]; then - rm -f $TMP/SeTprefix6 - exit - fi - PREFIX6="`cat $TMP/SeTprefix6`" - if [ "$PREFIX6" = "" ]; then - dialog --title "PREFIX REQUIRED" --msgbox \ -"You have configured this host with a v6 -IP address - a prefix is required." 6 43 - continue - elif (($PREFIX6 == 0)) 2>/dev/null || (($PREFIX6 > 128)) 2>/dev/null || \ - ! (($PREFIX6)) 2>/dev/null; then - dialog --title "PREFIX INVALID" --msgbox \ -"The prefix you entered is not valid. -Valid prefixes will be in the range 1-128." \ -6 46 - continue - else - echo $PREFIX6 >$TMP/SeTprefix6 - break + if [[ ! "$PREFIX" =~ ^[0-9]+$ ]] || (($PREFIX <= 0)) || (($PREFIX > 128)); then + dialog --title "INVALID PREFIX" --msgbox \ +"Invalid prefix specified for entry: ${IP6ADDRS[$I]}. +Valid prefixes will be in the range 1-128." 6 70 + if [ "$?" = "255" ]; then + rm -f $TMP/SeTIPSv6 + exit + fi + echo "${IP6ADDRS[@]}" >$TMP/SeTIPSv6 + continue 2 fi done + rm -f $TMP/SeTIPSv6 + break + done + if [ ! "${IP6ADDRS[*]}" = "" ]; then while [ 0 ]; do if [ -r $TMP/SeTgateway6 ]; then GATEWAY6=`cat $TMP/SeTgateway6` @@ -859,34 +808,43 @@ Valid prefixes will be in the range 1-128." \ "Enter the address for the IPv6 gateway on your network, such as: fe80:426c:ffff::1 -If you don't have an IPv6 gateway on your network just hit ENTER -without entering a gateway IP address. +If you don't have an IPv6 gateway on your network, leave it blank +or select 'Skip'. -Enter IPv6 gateway address:" 14 68 $GATEWAY6 2> $TMP/SeTgate6 - if [ $? = 1 -o $? = 255 ]; then - rm -f $TMP/SeTgate6 +Enter IPv6 gateway address:" 14 69 "$GATEWAY6" 2> $TMP/SeTgateway6 + ERRNO="$?" + if [ "$ERRNO" = "1" ]; then + rm -f $TMP/SeTgateway6 + break + elif [ "$ERRNO" = "255" ]; then + rm -f $TMP/SeTgateway6 exit fi - GATEWAY6="`cat $TMP/SeTgate6`" - rm -f $TMP/6SeTgate6 + GATEWAY6="`cat $TMP/SeTgateway6`" + # rm -f $TMP/SeTgateway6 if [ "$GATEWAY6" = "" ]; then - echo > $TMP/SeTgateway6 - break 2 + break fi - # We can only do a basic validation of the entered address - # as regexes for IPv6 addresses are very complex. - if echo "$GATEWAY6" | grep -E "^[0-9a-fA-F:]+$" >/dev/null; then - echo $GATEWAY6 > $TMP/SeTgateway6 - break 2 - else - dialog --title "INVALID IP ADDRESS" --msgbox \ -"The IP address you entered is not valid. -Please enter a valid IPv6 address." 6 44 - continue + syntax_check_v6 "$GATEWAY6" + if [ $? = 0 ]; then + break fi - echo $GATEWAY6 > $TMP/SeTgateway6 done + rm -f $TMP/SeTgateway6 + fi + + if [ "${IPADDRS[*]}" = "" ] && [ "${IP6ADDRS[*]}" = "" ]; then + dialog --title "NO IP ADDRESSES" --colors --defaultno --yesno \ +"\Z1You have not configured any IP addresses for this host. +Are you sure you want to proceed with no IPs?\Zn" 6 59 + ERRNO="$?" + if [ "$ERRNO" = "255" ]; then + exit + elif [ "$ERRNO" = "1" ]; then + continue + fi fi + break done fi -- cgit v1.2.3