wagon/back/fed.cgi

32 lines
770 B
Plaintext
Raw Normal View History

2022-09-14 14:44:00 -06:00
#!/bin/bash
# FILE: wgapi:back/fed.cgi
# DESCRIPTION: Recieves incoming federated requests
# ERRORS:
# 3: Bad usage
# 4: Missing config file
CONFIG_FILE='/etc/wgapi/config'
if ! [ ${#} -eq 0 ]; then
printf 'ERROR! Bad input: %s %s\n' "${0}" "${*}" >&2
2022-09-14 14:44:00 -06:00
exit 3
2022-09-15 13:54:17 -06:00
fi & if ! [ -f "${CONFIG_FILE}" ]; then
printf 'ERROR! %s could not find %s!\n' "${0}" "${CONFIG_FILE}" >&2
2022-09-14 14:44:00 -06:00
exit 4
fi; source "${CONFIG_FILE}"
case "${REQUEST_METHOD}" in
# Add
2022-11-27 16:00:43 -07:00
'POST') "${LIB_DIR}/fed/peer/add" "${HTTP_X_REAL_IP}" "${QUERY_STRING}";;
2022-09-14 14:44:00 -06:00
# Delete
2022-11-27 16:00:43 -07:00
'DELETE') "${LIB_DIR}/fed/peer/del" "${HTTP_X_REAL_IP}" "${QUERY_STRING}";;
2022-09-14 14:44:00 -06:00
# Needed for CORS preflight
'OPTIONS') "${LIB_DIR}/http_res" 200;;
# Bad request
*) printf 'Invalid HTTP verb' | "${LIB_DIR}/http_res" 405;;
2022-11-27 16:00:43 -07:00
2022-09-14 14:44:00 -06:00
esac