From b7b35f1580f5098da9bb5bed8296facd339992b6 Mon Sep 17 00:00:00 2001 From: Darren 'Tadgy' Austin Date: Wed, 18 Nov 2020 21:20:18 +0000 Subject: Add syntax_check_v6 function to validate IPv6 addresses + more. Move temp directory code to start of main block. Update dialog text for some screens. --- netconfig | 63 ++++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 19 deletions(-) diff --git a/netconfig b/netconfig index e975fad..9362c37 100644 --- a/netconfig +++ b/netconfig @@ -356,15 +356,9 @@ fi rm -f $TMP/tempmsg /cardfound } # end write_config_files -TMP=/var/log/setup/tmp -if [ ! -d $TMP ]; then - mkdir -p $TMP - chmod 700 $TMP -fi - -# This checks IP address syntax. -# usage: syntax_check ADDRESS #-OF-EXPECTED-SEGMENTS (up to 4) -# example: syntax_check 123.22.43.1 4 +# This checks IPv4 address syntax. +# usage: syntax_check_v4 ADDRESS #-OF-EXPECTED-SEGMENTS (up to 4) +# example: syntax_check_v4 123.22.43.1 4 # returns: 0=found correct 1=too many fields 2=non numeric field found syntax_check_v4() { RET_CODE=0 @@ -387,13 +381,17 @@ syntax_check_v4() { fi if [ "$3" = "WARN" -a ! "$RET_CODE" = "0" ]; then cat << EOF > $TMP/tempmsg -The IP address you entered, $1, is not valid. +The IP address you entered: + $1 +is not valid. + There should be $2 groups of numbers seperated by dots, for example: 192.168.1.1 Please correct any mistakes in the IP. EOF - dialog --title "INVALID VALUE" --defaultno --msgbox "`cat $TMP/tempmsg`" 9 72 + dialog --title "INVALID IP" --ok-button "Back" --msgbox \ + "`cat $TMP/tempmsg`" 12 72 rm -r $TMP/tempmsg else if [ "$3" = "ECHO" ]; then @@ -403,6 +401,29 @@ EOF return $RET_CODE; } +# This does cursary checks to validate an IPv6 address. +syntax_check_v6() { + # We can only do a basic validation of the entered address + # as regexes for IPv6 addresses are very complex. + if [[ "$1" =~ ^[0-9a-fA-F:]+$ ]] && [[ "$1" =~ :[0-9a-fA-F]{1,4}$ ]]; then + return 0 + else + dialog --title "INVALID IP" --ok-button "Back" --msgbox \ +"The IP address you entered: + $1 +is not valid. + +Please enter a valid IPv6 address." 9 72 + fi + return 1 +} + +TMP=/var/log/setup/tmp +if [ ! -d $TMP ]; then + mkdir -p $TMP + chmod 700 $TMP +fi + # Figure out where we are... cheap hack. if [ ! -e etc/slackware-version -a ! -e /etc/installer -a ! -e bin/bash ]; then cd / @@ -621,10 +642,11 @@ if [ "$LOOPBACK" = "no" -a ! "$USE_DHCP" = "yes" -a ! "$USE_SLAAC" = "yes" ]; th if [ -r $TMP/SeTIPSv4 ]; then IPADDRS=($(cat $TMP/SeTIPSv4)) fi - dialog --title "ENTER IPv4 ADDRESSES" --cancel-label "Skip" --inputbox \ -"Enter the IPv4 addresses for this host. You may list one or more, + 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 For example: 111.112.113.114/24 If a net mask is not specified a default of 24 will be used. @@ -725,10 +747,11 @@ Enter IPv4 gateway address:" 14 68 "$GATEWAY" 2> $TMP/SeTgateway4 if [ -r $TMP/SeTIPSv6 ]; then IP6ADDRS=($(cat $TMP/SeTIPSv6)) fi - dialog --title "ENTER IPv6 ADDRESSES" --cancel-label "Skip" --inputbox \ -"Enter the IPv6 addresses for this host. You may list one or more, + dialog --title "ENTER IPv6 ADDRESSES" --cancel-label "Skip" \ + --colors --inputbox \ +"Enter the \Z1IPv6\Zn addresses for this host. You may list one or more, space delimited, IPv6 addresses with their prefixes in the format: - / + \Z1/\Zn For example: 11a:11b:11c:11d::abc/64 If a prefix is not specified a default of 64 will be used. @@ -751,7 +774,7 @@ know what to put, just leave it blank or select 'Skip'." \ rm -f $TMP/SeTIPSv6 break fi - for ((I=0; I < ${#IPADDRS[@]}; I++)); do + for ((I=0; I < ${#IP6ADDRS[@]}; I++)); do IP="${IP6ADDRS[$I]%%/*}" PREFIX="${IP6ADDRS[$I]#*/}" if [ "$IP" = "" ]; then @@ -763,11 +786,13 @@ know what to put, just leave it blank or select 'Skip'." \ fi continue fi - # syntax_check_v6 "$IP" || continue 2 + syntax_check_v6 "$IP" || continue 2 if [ "$PREFIX" = "" ]; then IP6ADDRS[$I]="$IP/64" PREFIX="64" fi + done + done # if [ "$IPADDR6" = "" ]; then # if [ "$IPADDR" = "" ]; then -- cgit v1.2.3