From 6af817636acf48e02122d5fd31e0ba40c50f2b46 Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Sat, 10 Sep 2022 14:44:10 -0600 Subject: [PATCH] Fix checking for hostname duplicates --- back/srv/dashboard/add | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/back/srv/dashboard/add b/back/srv/dashboard/add index ff3d683..3ff2db8 100755 --- a/back/srv/dashboard/add +++ b/back/srv/dashboard/add @@ -31,11 +31,11 @@ qs="$(<<<"${2}" tr '&' '\n' | sed 's/?//')" # Check hostname hostname="$(<<<"${qs}" grep -oP 'name=(.*)' | sed 's/^name//' | xargs | tr -dc 'a-z0-9' | head -c10)" printf '%s requested new peer with hostname %s\n' "${ip}" "${hostname}" >>"${LOGFILE}" -[[ ${#hostname} -ge 3 ]] || ( +if ! [[ ${#hostname} -ge 3 ]]; then printf 'Rejecting hostname %s because it is too short.\n' "${hostname}" >>"${LOGFILE}" printf 'Hostname too short\n' | "${LIB_DIR}/http_res" 400 exit 7 -) +fi # Check token token_fail(){ @@ -58,17 +58,17 @@ printf '%s identified as %s\n' "${ip}" "${username}" >>"${LOGFILE}" domain="${hostname}.${username}.${TLD}" # Check if new peer already exists -printf '%s' "${hostnames}" >>"${LOGFILE}" printf "${hostname}" >>"${LOGFILE}" -printf '%s' "${hostnames}" | grep -o "${hostname}" && ( +if "${LIB_DIR}/ns_lookup_send" "${domain}"; then printf '%s.%s.%s already exists!\n' "${hostname}" "${username}" "${TLD}" >>"${LOGFILE}" printf 'Hostname %s already exists!\n' "${hostname}" | "${LIB_DIR}/http_res" 409 exit 6 -) +fi + +# Create new domain domain="${hostname:?}.${username:?}.${TLD:?}" printf 'New domain will be %s\n' "${domain}" >>"${LOGFILE}" -# Collect/parse existing peer data # Create new IPs peers="$("${LIB_DIR}/wg_peer_list" "${1}" tsv)" || exit 10 hostnames="$(<<<"${peers}" awk '{print $1}' | cut -d'.' -f1)"