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 +)