Created
July 23, 2017 13:11
-
-
Save Egor-Skriptunoff/252060d0ddb744fe26791c7cd26f8bf1 to your computer and use it in GitHub Desktop.
bugfix for lua.org demo page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local write,D,L,select,tostring,ipairs,concat,execute,sub,gsub=io.write,{},8192,select,tostring,ipairs,table.concat,os.execute,string.sub,string.gsub | |
local T,E,I | |
T=io.read"*a" | |
T=string.match(T,"=(.-)$") or "" | |
T=gsub(T,"+"," ") | |
T=gsub(T,"%%(%x%x)",function (x) return string.char(tonumber(x,16)) end) | |
T=gsub(T,"^%s*=%s*","return ") | |
write(sub(T,1,L)) | |
write[[</TEXTAREA> | |
<P> | |
<INPUT TYPE="submit" VALUE="Run"> | |
<INPUT TYPE="button" VALUE="Clear" onclick="this.form.elements['input'].value=''"> | |
<INPUT TYPE="reset" VALUE="Original"> | |
</FORM> | |
<P> | |
<H2>Output</H2> | |
<TEXTAREA ROWS="8" COLS="80"> | |
]] | |
io.flush() | |
arg=nil | |
debug.debug=nil | |
debug.getfenv=getfenv | |
debug.getregistry=nil | |
dofile=nil | |
io={write=io.write} | |
loadfile=nil | |
os.execute=nil | |
os.getenv=nil | |
os.remove=nil | |
os.rename=nil | |
os.tmpname=nil | |
package.loaded.io=io | |
package.loaded.package=nil | |
package=nil | |
require=nil | |
function write(...) | |
for _,v in ipairs{...} do | |
v=sub(v,1,L) | |
D[#D+1]=v | |
L=L-#v | |
end | |
end | |
T,E=loadstring(T,"=input") | |
if not T then | |
write(E) E="failed to compile" I="alert" | |
else | |
T=(function (...) return {select('#',...),...} end)(pcall(T)) | |
if not T[2] then | |
write(T[3]) E="failed to run" I="alert" | |
else | |
E="ran successfully" I="ok" | |
for i=3,T[1]+1 do write(tostring(T[i]),"\t") end | |
end | |
end | |
write[[</TEXTAREA><P>]] | |
write('<IMG SRC="images/',I,'.png" ALIGN="absbottom">\n') | |
write("Your program ",E,".") | |
write("<!-- ") | |
execute("printf '%s\\n' '"..gsub(concat(D),"'","'\\''").."' >&3") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
LUA=/home/lhf/websites/lua.org/www/bin/lua | |
LOG=log | |
ECHO="/bin/echo -E" | |
cat <<EOF | |
Content-type: text/html | |
EOF | |
date "+%n@ %c $REMOTE_HOST $REQUEST_METHOD $HTTP_REFERER" >> $LOG | |
if [ "$REQUEST_METHOD" = "GET" ] | |
then | |
if [ "$QUERY_STRING" = "" ] | |
then | |
exec cat demo.html | |
else | |
$ECHO "$QUERY_STRING" >> $LOG | |
F=`basename -- "$QUERY_STRING"`.lua | |
sed '/TEXTAREA/q' demo.html | |
$ECHO "-- $F" | |
(cat -- "$F" 2>&1) | |
sed '1,/TEXTAREA/d' demo.html | |
fi | |
else | |
sed '/TEXTAREA/q' demo.html | |
tee -a $LOG | (ulimit -t 1 ; { res=$($LUA demo.lua 3>&1 >&4 2>&4 4>&-); } 4>&1 ; printf "%s\n" "$res") | |
cat <<EOF | |
</TEXTAREA><P><IMG SRC="images/alert.png" ALIGN="absbottom"> | |
Your program was aborted.<!-- --> | |
<P> | |
<HR> | |
<SMALL> | |
EOF | |
$LUA -v 2>&1 | |
cat <<EOF | |
</SMALL> | |
</BODY> | |
</HTML> | |
EOF | |
echo '' >> $LOG | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment