ap.cgi (1876B)
1 #!/bin/sh 2 # Copyright 2023 Jacob R. Edwards <jacob@jacobedwards.org> 3 # The ap cgi script 4 # 5 # WARNING: The player command is dangerous, this script should be 6 # protected from malicious entities. 7 # 8 # Depends on /bin/sh(1), sed(1), echo(1) (unless built-in to sh(1)), 9 # and apc(1). If dynamically linked, you should only need libc. 10 # It also depends on urlencode and urldecode, but that's included 11 # in the project. 12 # 13 # If chrooted, you will need the programs and library listed above 14 # and the server socket must be accessable with the new root, such 15 # as at $CHROOT/tmp/aps 16 17 nam='Web Audio Player Client' 18 css=../ap.css 19 man=/man/aps.1.html 20 21 encode() { 22 echo -n "$1" | urlencode 23 } 24 25 # name, command 26 button() { 27 echo '<a href="'"?command=$(encode "$2")"'"><button>'"$1"'</button></a>' 28 } 29 30 # name, value, extra attributes 31 input() { 32 # put autofocus attribute in input to auto focus 33 # placeholder="'"${3:-list /jimi}"'"> 34 echo '<form action="'"$DOCUMENT_URI"'"> 35 <label for="command">'"$1"'</label> 36 <br> 37 <input type="search" name="command" value="'"$2"'" '${3:+"$3"}'> 38 <input type="submit" value="Execute"> 39 </form>' 40 } 41 42 echo -n 'Content-Type: text/html 43 44 ' 45 46 exec 2>&1 47 48 command="$(echo ${QUERY_STRING#command=} | sed 'y/+/ /' | urldecode)" 49 50 echo '<!DOCTYPE HTML><head> 51 <title>'"$nam"'</title> 52 <link rel="stylesheet" type="text/css" href="'"$css"'"> 53 </head>' 54 55 echo '<body><h1>'"$nam"'</h1> 56 <p>See the <a href="'"$man"'">manual</a> for available commands.</p>' 57 58 input Command '' autofocus 59 input 'Last Command' "$command" 'placeholder="'"$command"'"' 60 61 button Prev previous 62 button Toggle toggle 63 button Next next 64 65 echo '<br>' 66 button Status status 67 button Player player 68 button Playing name 69 70 echo '<br>' 71 button Next 'list 1' 72 button 'Next Ten' 'list ,10' 73 button 'List' list 74 75 echo -n '<hr><pre>' 76 77 echo "$command" | apc | 78 sed "s!.*!<a href='?command=play+\"&'>&</a>!" 79 80 echo '</pre></body>'