Added logging to wg_peer_add
parent
4eb11ebfb5
commit
c4ff8ee734
|
@ -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
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue