Fix checking for hostname duplicates
parent
6ed23a9d08
commit
6af817636a
|
@ -31,11 +31,11 @@ qs="$(<<<"${2}" tr '&' '\n' | sed 's/?//')"
|
||||||
# Check hostname
|
# Check hostname
|
||||||
hostname="$(<<<"${qs}" grep -oP 'name=(.*)' | sed 's/^name//' | xargs | tr -dc 'a-z0-9' | head -c10)"
|
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}"
|
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 'Rejecting hostname %s because it is too short.\n' "${hostname}" >>"${LOGFILE}"
|
||||||
printf 'Hostname too short\n' | "${LIB_DIR}/http_res" 400
|
printf 'Hostname too short\n' | "${LIB_DIR}/http_res" 400
|
||||||
exit 7
|
exit 7
|
||||||
)
|
fi
|
||||||
|
|
||||||
# Check token
|
# Check token
|
||||||
token_fail(){
|
token_fail(){
|
||||||
|
@ -58,17 +58,17 @@ printf '%s identified as %s\n' "${ip}" "${username}" >>"${LOGFILE}"
|
||||||
domain="${hostname}.${username}.${TLD}"
|
domain="${hostname}.${username}.${TLD}"
|
||||||
|
|
||||||
# Check if new peer already exists
|
# Check if new peer already exists
|
||||||
printf '%s' "${hostnames}" >>"${LOGFILE}"
|
|
||||||
printf "${hostname}" >>"${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 '%s.%s.%s already exists!\n' "${hostname}" "${username}" "${TLD}" >>"${LOGFILE}"
|
||||||
printf 'Hostname %s already exists!\n' "${hostname}" | "${LIB_DIR}/http_res" 409
|
printf 'Hostname %s already exists!\n' "${hostname}" | "${LIB_DIR}/http_res" 409
|
||||||
exit 6
|
exit 6
|
||||||
)
|
fi
|
||||||
|
|
||||||
|
# Create new domain
|
||||||
domain="${hostname:?}.${username:?}.${TLD:?}"
|
domain="${hostname:?}.${username:?}.${TLD:?}"
|
||||||
printf 'New domain will be %s\n' "${domain}" >>"${LOGFILE}"
|
printf 'New domain will be %s\n' "${domain}" >>"${LOGFILE}"
|
||||||
|
|
||||||
# Collect/parse existing peer data
|
|
||||||
# Create new IPs
|
# Create new IPs
|
||||||
peers="$("${LIB_DIR}/wg_peer_list" "${1}" tsv)" || exit 10
|
peers="$("${LIB_DIR}/wg_peer_list" "${1}" tsv)" || exit 10
|
||||||
hostnames="$(<<<"${peers}" awk '{print $1}' | cut -d'.' -f1)"
|
hostnames="$(<<<"${peers}" awk '{print $1}' | cut -d'.' -f1)"
|
||||||
|
|
Loading…
Reference in New Issue