Added logging to wg_peer_add

master
Keith Irwin 2022-09-09 22:43:04 -06:00
parent 4eb11ebfb5
commit c4ff8ee734
Signed by: ki9
GPG Key ID: DF773B3F4A88DA86
1 changed files with 17 additions and 4 deletions

View File

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