moleflap/door/open.lua

52 lines
936 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-26 02:37:27 +01:00
require 'md5'
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()
2010-02-26 02:37:27 +01:00
con = env:connect(config.db)
2010-02-26 01:46:20 +01:00
2010-02-25 08:37:50 +01:00
if token == nil or token == "" then
2010-02-26 02:37:27 +01:00
fail("No token given")
else
if token:sub(1, 2) == "t=" then
token = token:sub(3)
end
2010-05-02 02:51:35 +02:00
token = token:gsub(" ",""):gsub("\n","")
2010-02-26 02:37:27 +01:00
if token:len() == config.key_len then
2010-02-26 03:31:22 +01:00
if not is_bruteforce(con) then
2010-02-26 02:37:27 +01:00
print ""
b = check_token(con, token)
token = set_prefix(token,generate_token())
if b ~= false then
add_token(con, token)
qspawn("./openseamless")
2010-02-26 02:37:27 +01:00
end
print(token)
else
fail("Stop bruteforcing, this box is too slow")
2010-02-25 08:37:50 +01:00
end
2010-02-26 02:37:27 +01:00
else
fail("Invalid token")
end
2010-02-25 08:37:50 +01:00
end
2010-02-26 01:46:20 +01:00
2010-02-26 02:37:27 +01:00
con:close()
env:close()