Added logging, fixed broken loop

master
Keith Irwin 2022-09-09 22:19:57 -06:00
parent e5a1aa7a22
commit b9809e4c7a
Signed by: ki9
GPG Key ID: DF773B3F4A88DA86
1 changed files with 4 additions and 1 deletions

View File

@ -46,6 +46,7 @@ token_fail(){
saved_token="$(grep "${ip}" "${TOKENS_FILE}" | cut -f2)"
[ "${saved_token}" == "" ] && token_fail 'missing'
<<<"${qs}" grep -x "t=${saved_token}" || token_fail 'mismatched'
printf '%s token was valid\n' "${ip}" >>"${LOGFILE}"
# Check user
username="$("${LIB_DIR}/ns_lookup_rdns" "${REMOTE_ADDR}" | cut -d'.' -f2)" || (
@ -62,6 +63,8 @@ printf '%s' "${hostnames}" | grep -o "${hostname}" && (
printf 'Hostname %s already exists!\n' "${hostname}" | "${LIB_DIR}/http_res" 409
exit 6
)
domain="${hostname:?}.${username:?}.${TLD:?}"
printf 'New domain will be %s' "${domain}" >>"${LOGFILE}"
# Collect/parse existing peer data
# Create new IPs
@ -72,7 +75,7 @@ ipv6s="$(<<<"${peers}" awk '{print $3}')"
usernumber="$(<<<"${ipv4s}" head -n1 | cut -d'.' -f3)"
# Increment hostnumber from 1 until an unused one is found
used_hostnumbers="$(<<<"${ipv4s}" cut -d'.' -f4 | sort | uniq)"
hostnumber=1; while printf <<<"${used_hostnumbers}" grep "${hostnumber}"
hostnumber=1; while <<<"${used_hostnumbers}" grep "${hostnumber}"
do ((hostnumber++))
done
ipv4="${IPV4_NET%.*.*}.${usernumber}.${hostnumber}"