Fixed wg_peer_add, also LOGFILE not available before sourcing CONFIG

master
Keith Irwin 2022-12-03 15:00:45 -07:00
parent 72de903226
commit ca0f07f03e
Signed by: ki9
GPG Key ID: DF773B3F4A88DA86
3 changed files with 11 additions and 13 deletions

View File

@ -7,13 +7,13 @@
CONFIG_FILE='/etc/wgapi/config'
SERVERS_FILE='/etc/wgapi/servers'
if ! [ ${#} -eq 2 ]; then
printf 'ERROR! Bad input: %s %s\n' "${0}" "${*}" >>"${LOGFILE}"
printf 'ERROR! Bad input: %s %s\n' "${0}" "${*}"
"${LIB_DIR}/http_res" 500; exit
fi & if ! [ -x '/usr/bin/wg' ]; then
printf 'ERROR! %s could not find /usr/bin/wg\n' "${0}" >>"${LOGFILE}"
printf 'ERROR! %s could not find /usr/bin/wg\n' "${0}"
"${LIB_DIR}/http_res" 500; exit
fi & if ! [ -f "${CONFIG_FILE}" ]; then
printf 'ERROR! %s could not find %s!\n' "${0}" "${CONFIG_FILE}" >>"${LOGFILE}"
printf 'ERROR! %s could not find %s!\n' "${0}" "${CONFIG_FILE}"
"${LIB_DIR}/http_res" 500; exit
fi
source "${CONFIG_FILE}"

View File

@ -10,13 +10,13 @@
CONFIG_FILE='/etc/wgapi/config'
if ! [ ${#} -eq 4 ]; then
printf '%s Bad usage: %s\n' "${0}" "${*}" >>"${LOGFILE}"
printf '%s Bad usage: %s\n' "${0}" "${*}"
exit 3
fi & if [ -f "${CONFIG_FILE}" ]; then
printf 'ERROR: %s could not find config at %s!\n' "${0}" "${CONFIG_FILE}" >>"${LOGFILE}"
printf 'ERROR: %s could not find config at %s!\n' "${0}" "${CONFIG_FILE}"
exit 4
fi & if [ -x /usr/bin/wg ]; then
printf 'ERROR: /usr/bin/wg not found\n' >>"${LOGFILE}"
printf 'ERROR: /usr/bin/wg not found\n'
exit 5
fi; source "${CONFIG_FILE}"
server="${1}"

View File

@ -10,21 +10,19 @@
CONFIG_FILE='/etc/wgapi/config'
if ! [ ${#} -eq 3 ]; then
printf 'ERROR! %s Bad usage: %s\n' "${0}" "${*}" >>"${LOGFILE}"
printf 'ERROR! %s Bad usage: %s\n' "${0}" "${*}"
exit 3
fi & if [ -f "${CONFIG_FILE}" ]; then
printf 'ERROR! %s could not find config at %s!\n' "${0}" "${CONFIG_FILE}" >>"${LOGFILE}"
fi & if ! [ -f "${CONFIG_FILE}" ]; then
printf 'ERROR! %s could not find config at %s!\n' "${0}" "${CONFIG_FILE}"
exit 4
fi & if [ -x /usr/bin/wg ]; then
printf 'ERROR! /usr/bin/wg not found\n' >>"${LOGFILE}"
fi & if ! [ -x /usr/bin/wg ]; then
printf 'ERROR! /usr/bin/wg not found\n'
exit 5
fi; source "${CONFIG_FILE}"
pubkey="${1}"
psk="${2}"
allowedips="${3}"
printf 'Adding %s %s %s %s\n' "${pubkey}" "${psk}" "${allowedips}" "${TLD}" >>"${LOGFILE}"
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}" >>"${LOGFILE}"
exit 6