Added some logging

master
Keith Irwin 2022-09-07 18:50:32 -06:00
parent 7c2bb407be
commit 80c08d5b19
Signed by: ki9
GPG Key ID: DF773B3F4A88DA86
1 changed files with 6 additions and 2 deletions

View File

@ -14,15 +14,19 @@ case "${REQUEST_METHOD}" in
# List peers
'GET')
printf "${REMOTE_ADDR} seeking peer listing..." >>${LOGFILE}
token="$(grep ${REMOTE_ADDR} ${TOKENS_FILE} | cut -f2)"
if [ "${token}" == "" ]; then
printf "Creating token for ${REMOTE_ADDR}..." >>${LOGFILE}
token="$(</dev/urandom tr -dc '[:alnum:]' | fold -w 64 | head -n 1)"
printf "${REMOTE_ADDR}\t${token}\n" >>"${TOKENS_FILE}"
fi
peers="[$(sudo ${LIB_DIR}/wg_peer_list ${REMOTE_ADDR} json)]"
case ${?} in
0) printf "${peers}" | "${LIB_DIR}/http_res" 200 'application/json';;
*) printf 'Failed to lookup user' | "${LIB_DIR}/http_res" 500;;
0) printf "Sent peers to user ${REMOTE_ADDR}" >>${LOGFILE}
printf "${peers}" | "${LIB_DIR}/http_res" 200 'application/json';;
*) printf "ERROR: Failed to lookup user: ${REMOTE_ADDR}" >>${LOGFILE}
printf 'Failed to lookup user' | "${LIB_DIR}/http_res" 500;;
esac
;;