ad_hoc.cgi 641 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/sh
  2. # https://mro.name/radio-privatkopie
  3. #
  4. # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
  5. set -eu
  6. [ "POST" = "${REQUEST_METHOD}" ] || {
  7. cat <<EOF
  8. Status: 405
  9. Content-Type: text/plain; charset=utf-8
  10. Method not allowed.
  11. https://mro.name/radio-privatkopie
  12. EOF
  13. exit 0
  14. }
  15. cd "$(dirname "${0}")" || exit 1
  16. readonly id="$(echo "${HTTP_REFERER}" | grep -hoE "/stations/[^/]+/[0-9]{4}/[0-9]{2}/[0-9]{2}/[0-9]{4}" | cut -d / -f 3-)"
  17. sudo -u radio-pi sh schedule.sh "${id}" \
  18. || exit 1
  19. cat <<EOF
  20. Status: 302
  21. Content-Type: text/plain; charset=utf-8
  22. Location: ../../stations/${id}.xml
  23. Das war aber einfach.
  24. EOF