Test stderr logging

master
Keith Irwin 2022-12-03 16:19:23 -07:00
parent 09a4b2fcf9
commit 0177c4e9e8
Signed by: ki9
GPG Key ID: DF773B3F4A88DA86
4 changed files with 12 additions and 10 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}" "${*}"
printf 'ERROR! Bad input: %s %s\n' "${0}" "${*}" >&2
"${LIB_DIR}/http_res" 500; exit
fi & if ! [ -x '/usr/bin/wg' ]; then
printf 'ERROR! %s could not find /usr/bin/wg\n' "${0}"
printf 'ERROR! %s could not find /usr/bin/wg\n' "${0}" >&2
"${LIB_DIR}/http_res" 500; exit
fi & if ! [ -f "${CONFIG_FILE}" ]; then
printf 'ERROR! %s could not find %s!\n' "${0}" "${CONFIG_FILE}"
printf 'ERROR! %s could not find %s!\n' "${0}" "${CONFIG_FILE}" >&2
"${LIB_DIR}/http_res" 500; exit
fi
source "${CONFIG_FILE}"
@ -61,7 +61,7 @@ fi
# Create new domain
domain="${hostname:?}.${username:?}.${TLD:?}"
printf 'New domain will be %s\n' "${domain}" >>"${LOGFILE}"
printf 'New domain will be %s\n' "${domain}" >&2
# Get peer IP list
if ! wg_output="$(sudo /usr/bin/wg show "${TLD}" allowed-ips)"; then

View File

@ -6,13 +6,13 @@
CONFIG_FILE='/etc/wgapi/config'
if ! [ ${#} -eq 2 ]; then
printf 'ERROR! Bad input: %s %s\n' "${0}" "${*}" >>"${LOGFILE}"
printf 'ERROR! Bad input: %s %s\n' "${0}" "${*}" >&2
"${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}" >&2
"${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}" >&2
"${LIB_DIR}/http_res" 500; exit
fi; source "${CONFIG_FILE}"
ip="${1}"

View File

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

View File

@ -20,9 +20,11 @@
[X] Let this server route traffic for all hosts
[X] Prevent deleting user's only peer
[X] Remove bash errors
[ ] Move loging to STDERR
[ ] Federated servers
[ ] shellcheck
[ ] Deploy on GF4
[ ] Prepare for IPv4 exhaustion
[ ] Deduplicate code
[ ] shellcheck
[ ] Write tests