From dc133053b34c54e7f550ba349b04149210a502b5 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 22 May 2022 17:34:51 +0200 Subject: [PATCH] fix: fix input validation Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/fluidd.sh | 12 ++++++++---- scripts/mainsail.sh | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index 2cdd11b..7e53485 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -384,14 +384,18 @@ function select_fluidd_port() { bottom_border local new_port re="^[0-9]+$" - while [[ ! ${new_port} =~ ${re} ]]; do + while true; do read -p "${cyan}Please enter a new Port:${white} " new_port - if [[ ${new_port} != "${MAINSAIL_PORT}" ]] && [[ ${new_port} != "${OCTOPRINT_PORT}" ]]; then - echo "Setting port ${new_port} for Fluidd!" + if [[ ${new_port} =~ ${re} && ${new_port} != "${MAINSAIL_PORT}" && ${new_port} != "${OCTOPRINT_PORT}" ]]; then + select_msg "Setting port ${new_port} for Fluidd!" SET_LISTEN_PORT=${new_port} break else - echo "That port is already taken! Select a different one!" + if [[ ! ${new_port} =~ ${re} ]]; then + error_msg "Invalid input!" + else + error_msg "Port already taken! Select a different one!" + fi fi done fi diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index 1941de8..e470ab0 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -506,14 +506,18 @@ function select_mainsail_port() { bottom_border local new_port re="^[0-9]+$" - while [[ ! ${new_port} =~ ${re} ]]; do + while true; do read -p "${cyan}Please enter a new Port:${white} " new_port - if [[ ${new_port} != "${FLUIDD_PORT}" ]] && [[ ${new_port} != "${OCTOPRINT_PORT}" ]]; then - echo "Setting port ${new_port} for Mainsail!" + if [[ ${new_port} =~ ${re} && ${new_port} != "${FLUIDD_PORT}" && ${new_port} != "${OCTOPRINT_PORT}" ]]; then + select_msg "Setting port ${new_port} for Mainsail!" SET_LISTEN_PORT=${new_port} break else - echo "That port is already taken! Select a different one!" + if [[ ! ${new_port} =~ ${re} ]]; then + error_msg "Invalid input!" + else + error_msg "Port already taken! Select a different one!" + fi fi done fi