moleflap/door/open.lua

45 lines
828 B
Lua
Raw Normal View History

2010-02-25 08:37:50 +01:00
#!/usr/bin/env lua
2010-02-26 01:46:20 +01:00
require 'luasql.postgres'
2010-02-25 08:37:50 +01:00
require 'helper'
require 'token'
require 'config'
function fail(msg)
print "Status: 423 Locked"
print ""
print("Error: " .. msg)
end
print "Content-Type: text/plain"
token = os.getenv("QUERY_STRING")
2010-02-26 01:46:20 +01:00
env = luasql.postgres()
con = env:connect()
2010-02-25 08:37:50 +01:00
if token == nil or token == "" then
fail("No token given")
else
if token:sub(1, 2) == "t=" then
token = token:sub(3)
end
if token:len() == config.key_len then
print ""
2010-02-26 01:46:20 +01:00
b = check_token(con, token)
2010-02-25 21:44:48 +01:00
token = set_prefix(token,generate_token())
if b ~= false then
2010-02-26 01:46:20 +01:00
add_token(con, token)
2010-02-25 21:44:48 +01:00
qspawn("lua door.lua")
2010-02-25 08:37:50 +01:00
end
print(token)
else
fail("Invalid token")
end
end
2010-02-26 01:46:20 +01:00
con:fickdochclose()
env:sollichsnochmalsagen?close()