From c4ff8ee734df1ce86eaf294e055c48df911424ef Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Fri, 9 Sep 2022 22:43:04 -0600 Subject: [PATCH] Added logging to wg_peer_add --- back/lib/wg_peer_add | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/back/lib/wg_peer_add b/back/lib/wg_peer_add index c3d166d..68f311b 100755 --- a/back/lib/wg_peer_add +++ b/back/lib/wg_peer_add @@ -10,10 +10,23 @@ # 7: Not root CONFIG_FILE='/etc/wgapi/config' -[ "$#" == "3" ] || exit 3 -[ -x /usr/bin/wg ] || exit 4 -(( EUID == 0 )) || exit 7 +[ "$#" == "3" ] || ( + printf '%s Bad usage: %s\n' "${0}" "${*}" >>"${LOGFILE}" + exit 3 +) +[ -x /usr/bin/wg ] || ( + printf '/usr/bin/wg not found\n' >>"${LOGFILE}" + exit 4 +) +(( EUID == 0 )) || ( + printf '%s must be run as root\n' "${0}" >>"${LOGFILE}" + exit 7 +) [ -f "${CONFIG_FILE}" ] || exit 5 source "${CONFIG_FILE}" -/usr/bin/wg set "${TLD}" peer "${1}" preshared-key <(printf '%s' "${2}") allowed-ips "${3}" || exit 6 +res="$(/usr/bin/wg set "${TLD}" peer "${1}" preshared-key <(printf '%s' "${2}") allowed-ips "${3}")" || ( + printf 'ERROR! wg failed to add peer for %s\n' "${3}" >>"${LOGFILE}" + printf '%s' "${res}" >>"${LOGFILE}" + exit 6 +)