diff --git a/back/lib/wg_peer_add b/back/lib/wg_peer_add index fb76cf8..af25132 100755 --- a/back/lib/wg_peer_add +++ b/back/lib/wg_peer_add @@ -1,12 +1,19 @@ #!/bin/bash -# FILE: wagon:back/lib/wg/peer/add +# FILE: wagon:back/lib/wg_peer_add # DESCRIPTION: Add a new peer to a wireguard interface -# USAGE: add pubkey psk allowedips +# USAGE: wg_peer_add pubkey psk allowedips source /etc/wagon/config -pubkey="${1}"; psk="${2}"; allowedips="${3}" +pubkey="${1}"; psk="${2}"; allowedips="${3}"; domain="${4}" -if ! res="$(printf '%s\n' "${psk}" | sudo /usr/bin/wg set "${TLD}" peer "${pubkey}" preshared-key /dev/stdin allowed-ips "${allowedips}")"; then - printf '%s %s\n' "${?}" "${res}" >&2 +# Add new peer to interface +if ! res_int="$(printf '%s\n' "${psk}" | sudo /usr/bin/wg set "${TLD}" peer "${pubkey}" preshared-key /dev/stdin allowed-ips "${allowedips}")"; then + printf '%s %s\n' "${?}" "${res_int}" >&2 exit 1 -fi \ No newline at end of file +fi + +# Save config +if ! res_conf="$(/usr/bin/wg-quick save ${TLD})"; then + printf '%s %s\n' "${?}" "${res_conf}" >&2 + exit 1 +fi diff --git a/back/lib/wg_peer_del b/back/lib/wg_peer_del index 72d22b6..ff168e9 100755 --- a/back/lib/wg_peer_del +++ b/back/lib/wg_peer_del @@ -1,11 +1,19 @@ #!/bin/bash -# FILE: wagon:back/lib/wg/peer/del +# FILE: wagon:back/lib/wg_peer_del # DESCRIPTION: Delete a peer from a wireguard interface -# USAGE: del pubkey +# USAGE: wg_peer_del pubkey source /etc/wagon/config +pubkey="${1}" -if ! res="$(sudo /usr/bin/wg set "${TLD}" peer "${1}" remove)"; then - printf 'ERROR! Wireguard failed: %s\n' "${res}" >&2 +# Delete peer from interface +if ! res_int="$(sudo /usr/bin/wg set "${TLD}" peer "${pubkey}" remove)"; then + printf 'ERROR! Wireguard failed: %s\n' "${res_int}" >&2 + exit 1 +fi & + +# Save config +if ! res_conf="$(/usr/bin/wg-quick save ${TLD})"; then + printf '%s %s\n' "${?}" "${res_conf}" >&2 exit 1 fi