Renamed file
parent
f761459ee2
commit
f8c0415761
|
@ -87,7 +87,7 @@ if ! peers="$(sudo /usr/bin/wg show "${TLD}" allowed-ips)"; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get peer domains
|
# Get peer domains
|
||||||
if ! peers="$("${LIB_DIR}/wg_peer_list" tsv <<<"${peers}")"; then
|
if ! peers="$("${LIB_DIR}/ips_to_peers" tsv <<<"${peers}")"; then
|
||||||
printf 'ERROR! Failed to retrieve peers for %s!\n' "${ip}" >>"${LOGFILE}"
|
printf 'ERROR! Failed to retrieve peers for %s!\n' "${ip}" >>"${LOGFILE}"
|
||||||
exit 10
|
exit 10
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -60,7 +60,7 @@ if [ "${user_peers}" == "" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get peer domains
|
# Get peer domains
|
||||||
if ! peer="$("${LIB_DIR}/wg_peer_list" tsv <<<"${user_peers}" | grep "${pubkey}")"; then
|
if ! peer="$("${LIB_DIR}/ips_to_peers" tsv <<<"${user_peers}" | grep "${pubkey}")"; then
|
||||||
printf 'ERROR! Peer %s not found for user %s!\n' "${pubkey}" "${ip}" >>"${LOGFILE}" &
|
printf 'ERROR! Peer %s not found for user %s!\n' "${pubkey}" "${ip}" >>"${LOGFILE}" &
|
||||||
printf 'Peer not found\n' | "${LIB_DIR}/http_res" 404
|
printf 'Peer not found\n' | "${LIB_DIR}/http_res" 404
|
||||||
exit 6
|
exit 6
|
||||||
|
|
|
@ -61,7 +61,7 @@ if [ "${un}" != '' ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get domains for each peer
|
# Get domains for each peer
|
||||||
if peers="[$("${LIB_DIR}/wg_peer_list" json <<<"${peers}")]"; then
|
if peers="[$("${LIB_DIR}/ips_to_peers" json <<<"${peers}")]"; then
|
||||||
printf '{"token":"%s","peers":%s}' "${token}" "${peers}" | "${LIB_DIR}/http_res" 200 'application/json'
|
printf '{"token":"%s","peers":%s}' "${token}" "${peers}" | "${LIB_DIR}/http_res" 200 'application/json'
|
||||||
printf 'Sent peers to admin %s\n' "${ip}" >>"${LOGFILE}"
|
printf 'Sent peers to admin %s\n' "${ip}" >>"${LOGFILE}"
|
||||||
else
|
else
|
||||||
|
|
|
@ -94,7 +94,7 @@ if [ "${user_peers}" == "" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create new IPs
|
# Create new IPs
|
||||||
if ! peers="$("${LIB_DIR}/wg_peer_list" tsv <<<"${user_peers}")"; then
|
if ! peers="$("${LIB_DIR}/ips_to_peers" tsv <<<"${user_peers}")"; then
|
||||||
printf 'ERROR! Failed to parse peers for %s!\n' "${ip}" >>"${LOGFILE}"
|
printf 'ERROR! Failed to parse peers for %s!\n' "${ip}" >>"${LOGFILE}"
|
||||||
exit 10
|
exit 10
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -61,7 +61,7 @@ if [ "${user_peers}" == "" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get peer domains
|
# Get peer domains
|
||||||
if ! peer="$("${LIB_DIR}/wg_peer_list" tsv <<<"${user_peers}" | grep "${pubkey}")"; then
|
if ! peer="$("${LIB_DIR}/ips_to_peers" tsv <<<"${user_peers}" | grep "${pubkey}")"; then
|
||||||
printf 'ERROR! Peer %s not found for user %s!\n' "${pubkey}" "${ip}" >>"${LOGFILE}" &
|
printf 'ERROR! Peer %s not found for user %s!\n' "${pubkey}" "${ip}" >>"${LOGFILE}" &
|
||||||
printf 'Peer not found\n' | "${LIB_DIR}/http_res" 404
|
printf 'Peer not found\n' | "${LIB_DIR}/http_res" 404
|
||||||
exit 6
|
exit 6
|
||||||
|
|
|
@ -56,7 +56,7 @@ if [ "${user_peers}" == '' ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get domains for each one
|
# Get domains for each one
|
||||||
if peers="[$("${LIB_DIR}/wg_peer_list" json <<<"${user_peers}")]"; then
|
if peers="[$("${LIB_DIR}/ips_to_peers" json <<<"${user_peers}")]"; then
|
||||||
printf '{"token":"%s","peers":%s}' "${token}" "${peers}" | "${LIB_DIR}/http_res" 200 'application/json'
|
printf '{"token":"%s","peers":%s}' "${token}" "${peers}" | "${LIB_DIR}/http_res" 200 'application/json'
|
||||||
printf 'Sent peers to user %s\n' "${ip}" >>"${LOGFILE}"
|
printf 'Sent peers to user %s\n' "${ip}" >>"${LOGFILE}"
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# FILE: wg_peer_list
|
# FILE: ips_to_peers
|
||||||
# DESCRIPTION: Get peers in the same subnet as an ip
|
# DESCRIPTION: Takes a list of IPs from wg show allowed-ips
|
||||||
# USAGE: wg_peer_list json <<<"${user_peers}"
|
# and adds domains using rdns lookups
|
||||||
|
# USAGE: ips_to_peers json <<<"${user_peers}"
|
||||||
# ERRORS:
|
# ERRORS:
|
||||||
# 3: bad usage
|
# 3: bad usage
|
||||||
# 4: nslookup failed
|
# 4: nslookup failed
|
Loading…
Reference in New Issue