Fixed wg_peer_add, also LOGFILE not available before sourcing CONFIG
parent
72de903226
commit
ca0f07f03e
|
@ -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}"
|
||||
|
|
|
@ -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}"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue