Improved logging

master
Keith Irwin 2022-09-07 18:52:52 -06:00
parent 80c08d5b19
commit 6bc2ceef24
Signed by: ki9
GPG Key ID: DF773B3F4A88DA86
1 changed files with 4 additions and 4 deletions

View File

@ -14,18 +14,18 @@ case "${REQUEST_METHOD}" in
# List peers
'GET')
printf "${REMOTE_ADDR} seeking peer listing..." >>${LOGFILE}
printf "${REMOTE_ADDR} seeking peer listing...\n" >>"${LOGFILE}"
token="$(grep ${REMOTE_ADDR} ${TOKENS_FILE} | cut -f2)"
if [ "${token}" == "" ]; then
printf "Creating token for ${REMOTE_ADDR}..." >>${LOGFILE}
printf "Creating token for ${REMOTE_ADDR}...\n" >>"${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 "Sent peers to user ${REMOTE_ADDR}" >>${LOGFILE}
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 "ERROR: Failed to lookup user: ${REMOTE_ADDR}\n" >>"${LOGFILE}"
printf 'Failed to lookup user' | "${LIB_DIR}/http_res" 500;;
esac
;;