2022-09-06 20:57:41 -06:00
|
|
|
#!/bin/bash
|
2022-09-14 14:44:00 -06:00
|
|
|
# FILE: wgapi:back/dashboard.cgi
|
2022-09-06 20:57:41 -06:00
|
|
|
# DESCRIPTION: Recieves incoming dashboard API requests
|
|
|
|
# ERRORS:
|
|
|
|
# 3: Bad usage
|
2022-09-14 14:44:00 -06:00
|
|
|
# 4: Missing config file
|
2022-09-06 20:57:41 -06:00
|
|
|
|
|
|
|
CONFIG_FILE='/etc/wgapi/config'
|
2022-09-15 13:54:17 -06:00
|
|
|
if ! [ -f "${CONFIG_FILE}" ]; then
|
2022-09-14 14:44:00 -06:00
|
|
|
printf 'ERROR! %s could not find %s!\n' "${0}" "${CONFIG_FILE}" >>"${LOGFILE}"
|
|
|
|
exit 4
|
|
|
|
fi; source "${CONFIG_FILE}"
|
2022-09-06 20:57:41 -06:00
|
|
|
|
|
|
|
case "${REQUEST_METHOD}" in
|
|
|
|
|
2022-09-14 14:44:00 -06:00
|
|
|
# List peers
|
2022-09-14 22:28:02 -06:00
|
|
|
'GET') "${LIB_DIR}/dashboard/peer/list" "${HTTP_X_REAL_IP}";;
|
2022-09-06 20:57:41 -06:00
|
|
|
|
|
|
|
# Add peer
|
2022-09-14 22:28:02 -06:00
|
|
|
'POST') "${LIB_DIR}/dashboard/peer/add" "${HTTP_X_REAL_IP}" "${QUERY_STRING}";;
|
2022-09-06 20:57:41 -06:00
|
|
|
|
|
|
|
# Delete peer
|
2022-09-14 22:28:02 -06:00
|
|
|
'DELETE') "${LIB_DIR}/dashboard/peer/del" "${HTTP_X_REAL_IP}" "${QUERY_STRING}";;
|
2022-09-06 20:57:41 -06:00
|
|
|
|
2022-09-13 11:33:13 -06:00
|
|
|
# Needed for CORS preflight
|
|
|
|
'OPTIONS') "${LIB_DIR}/http_res" 200;;
|
|
|
|
|
2022-09-06 20:57:41 -06:00
|
|
|
# Bad request
|
2022-09-08 14:39:59 -06:00
|
|
|
*) printf 'Invalid HTTP verb' | "${LIB_DIR}/http_res" 405;;
|
2022-09-06 20:57:41 -06:00
|
|
|
|
2022-09-14 14:44:00 -06:00
|
|
|
esac
|