Ahoj,
potrebuji napsat jednoduchou CGI webovou stranku na routeru s OpenWrt.
Jsem si plne vedom nebezpecnosti pouziti shellu jako interpretu prikazu zadanych pres prohlizec, ale PHP se mi do 4MB flash spolu se systemem proste nevejde a cgi skript nebude dostupny z internetu.
Mam otestovane tyto dva skripty na Ubuntu s Apachem:
/usr/lib/cgi-bin/input :
#!/bin/bash
echo "Content-type: text/html"
echo ""
echo "<html><head><title>TEST</title>"
cat << EOF
<body>
<form action="output" method="GET">
MAC <input name="MAC" placeholder="0A:1B:2C:3D:4E:5F">
<input type="submit" name="odeslat" value="Odeslat" style="font-size: 150%">
<form>
EOF
echo "</body></html>"
/usr/lib/cgi-bin/output :
#!/bin/bash
# FORM GET:
saveIFS=$IFS
IFS='=&'
param=($QUERY_STRING)
IFS=$saveIFS
echo "Content-type: text/html"
echo ""
echo "<html><head><title>TEST</title></head>"
echo "<body>"
echo "<h1>abc<h1>"
if [ "${param[0]}" = "MAC" ]
then
echo "OK"
echo ${param[1]} >> /tmp/cgi-bin
else
echo "SPATNY VSTUP"
fi
echo "</body></html>"
S bashem to funguje krasne. Ale pokud pouziju (testuju na ubuntu)
busybox sh, nebo
dash - skript nefunguje.
Problem je s
IFS.
Muzete mi nekdo poradit, jak snadno pomoci busybox shellu naparsovat query string ve tvaru
http://localhost/cgi-bin/send?MAC=0A%3A1B%3A2C%3A3D%3A4E%3A5F&odeslat=OdeslatDekodovani URL neni problem:
$ alias urldecode='sed "s@+@ @g;s@%@\\\\x@g" | xargs -0 printf "%b"'
$ echo "http://localhost/cgi-bin/send?MAC=0A%3A1B%3A2C%3A3D%3A4E%3A5F&odeslat=Odeslat" | urldecode
http://localhost/cgi-bin/send?MAC=0A:1B:2C:3D:4E:5F&odeslat=Odeslat